The reference check both headless backends need, written once.
packages/export/src/effective-index.ts is the authority on the same
question for the exporter, and answering it twice is a real hazard: it is not
called here because it is not exported from @ifc-lite/export, and because
it answers about express ids only, with no notion of a model id, which is
half of what a reference has to be checked for. If it is ever exported, this
is the call site to move onto it.
Neither question it answers has an obvious source to read, which is why this
is shared rather than re-derived per backend:
The express id is resolved against the EFFECTIVE model, not
store.entityIndex.byId. StoreEditor.addEntity deliberately keeps
created ids out of that index (it may be a CompactEntityIndex over
immutable typed arrays), so an id bim.store.addEntity just handed back is
real while the base index has never heard of it; a tombstoned entity is in
the base index while being exported nowhere. Both would be answered wrong.
The model id is checked because the write methods do not pass it on — they
forward ref.expressId into the one overlay the backend holds. A reference
carrying another model's id, left unchecked, is not a dropped write but a
write to the wrong entity. It is reported as its own reason, naming the ids
the backend does answer for, because it is not a missing entity.
overlay is a thunk and is consulted only once it exists: no overlay means
nothing was created or deleted this session, so hasSourceEntity is the
whole truth and a read-only session still never builds one.
The reference check both headless backends need, written once.
packages/export/src/effective-index.tsis the authority on the same question for the exporter, and answering it twice is a real hazard: it is not called here because it is not exported from@ifc-lite/export, and because it answers about express ids only, with no notion of a model id, which is half of what a reference has to be checked for. If it is ever exported, this is the call site to move onto it.Neither question it answers has an obvious source to read, which is why this is shared rather than re-derived per backend:
store.entityIndex.byId.StoreEditor.addEntitydeliberately keeps created ids out of that index (it may be aCompactEntityIndexover immutable typed arrays), so an idbim.store.addEntityjust handed back is real while the base index has never heard of it; a tombstoned entity is in the base index while being exported nowhere. Both would be answered wrong.ref.expressIdinto the one overlay the backend holds. A reference carrying another model's id, left unchecked, is not a dropped write but a write to the wrong entity. It is reported as its own reason, naming the ids the backend does answer for, because it is not a missing entity.overlayis a thunk and is consulted only once it exists: no overlay means nothing was created or deleted this session, sohasSourceEntityis the whole truth and a read-only session still never builds one.