joist-core 2.5.0-next.2 → 2.5.0-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/BaseEntity.cjs +33 -3
- package/build/BaseEntity.cjs.map +1 -1
- package/build/BaseEntity.d.cts +6 -4
- package/build/BaseEntity.d.cts.map +1 -1
- package/build/BaseEntity.d.mts +6 -4
- package/build/BaseEntity.d.mts.map +1 -1
- package/build/BaseEntity.js +33 -4
- package/build/BaseEntity.js.map +1 -1
- package/build/Entity.cjs +2 -3
- package/build/Entity.d.cts +0 -2
- package/build/Entity.d.cts.map +1 -1
- package/build/Entity.d.mts +0 -2
- package/build/Entity.d.mts.map +1 -1
- package/build/Entity.js +2 -3
- package/build/EntityFields.d.cts +0 -2
- package/build/EntityFields.d.cts.map +1 -1
- package/build/EntityFields.d.mts +0 -2
- package/build/EntityFields.d.mts.map +1 -1
- package/build/EntityManager.cjs +185 -103
- package/build/EntityManager.cjs.map +1 -1
- package/build/EntityManager.d.cts +50 -37
- package/build/EntityManager.d.cts.map +1 -1
- package/build/EntityManager.d.mts +50 -37
- package/build/EntityManager.d.mts.map +1 -1
- package/build/EntityManager.js +185 -104
- package/build/EntityManager.js.map +1 -1
- package/build/EntityMetadata.cjs +3 -4
- package/build/EntityMetadata.cjs.map +1 -1
- package/build/EntityMetadata.d.cts +8 -6
- package/build/EntityMetadata.d.cts.map +1 -1
- package/build/EntityMetadata.d.mts +8 -6
- package/build/EntityMetadata.d.mts.map +1 -1
- package/build/EntityMetadata.js +3 -4
- package/build/EntityMetadata.js.map +1 -1
- package/build/EnumMetadata.d.cts +0 -2
- package/build/EnumMetadata.d.cts.map +1 -1
- package/build/EnumMetadata.d.mts +0 -2
- package/build/EnumMetadata.d.mts.map +1 -1
- package/build/IndexManager.cjs +4 -5
- package/build/IndexManager.d.cts +1 -3
- package/build/IndexManager.d.cts.map +1 -1
- package/build/IndexManager.d.mts +1 -3
- package/build/IndexManager.d.mts.map +1 -1
- package/build/IndexManager.js +4 -5
- package/build/InstanceData.cjs +12 -6
- package/build/InstanceData.cjs.map +1 -1
- package/build/InstanceData.d.cts +9 -5
- package/build/InstanceData.d.cts.map +1 -1
- package/build/InstanceData.d.mts +9 -5
- package/build/InstanceData.d.mts.map +1 -1
- package/build/InstanceData.js +12 -6
- package/build/InstanceData.js.map +1 -1
- package/build/PluginManager.cjs +21 -8
- package/build/PluginManager.cjs.map +1 -1
- package/build/PluginManager.d.cts +19 -7
- package/build/PluginManager.d.cts.map +1 -1
- package/build/PluginManager.d.mts +19 -7
- package/build/PluginManager.d.mts.map +1 -1
- package/build/PluginManager.js +21 -8
- package/build/PluginManager.js.map +1 -1
- package/build/RowData.cjs +1 -2
- package/build/RowData.d.cts +0 -2
- package/build/RowData.d.cts.map +1 -1
- package/build/RowData.d.mts +0 -2
- package/build/RowData.d.mts.map +1 -1
- package/build/RowData.js +1 -2
- package/build/_virtual/_rolldown/runtime.cjs +1 -2
- package/build/batchloaders/BatchLoader.cjs +1 -2
- package/build/batchloaders/BatchLoader.d.cts +0 -2
- package/build/batchloaders/BatchLoader.d.cts.map +1 -1
- package/build/batchloaders/BatchLoader.d.mts +0 -2
- package/build/batchloaders/BatchLoader.d.mts.map +1 -1
- package/build/batchloaders/BatchLoader.js +1 -2
- package/build/batchloaders/enumCollectionBatchLoader.cjs +4 -5
- package/build/batchloaders/enumCollectionBatchLoader.cjs.map +1 -1
- package/build/batchloaders/enumCollectionBatchLoader.d.cts +1 -3
- package/build/batchloaders/enumCollectionBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/enumCollectionBatchLoader.d.mts +1 -3
- package/build/batchloaders/enumCollectionBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/enumCollectionBatchLoader.js +4 -5
- package/build/batchloaders/enumCollectionBatchLoader.js.map +1 -1
- package/build/batchloaders/loadBatchLoader.cjs +9 -9
- package/build/batchloaders/loadBatchLoader.cjs.map +1 -1
- package/build/batchloaders/loadBatchLoader.d.cts +3 -5
- package/build/batchloaders/loadBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/loadBatchLoader.d.mts +3 -5
- package/build/batchloaders/loadBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/loadBatchLoader.js +9 -9
- package/build/batchloaders/loadBatchLoader.js.map +1 -1
- package/build/batchloaders/manyToManyBatchLoader.cjs +5 -6
- package/build/batchloaders/manyToManyBatchLoader.cjs.map +1 -1
- package/build/batchloaders/manyToManyBatchLoader.d.cts +1 -3
- package/build/batchloaders/manyToManyBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/manyToManyBatchLoader.d.mts +1 -3
- package/build/batchloaders/manyToManyBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/manyToManyBatchLoader.js +5 -6
- package/build/batchloaders/manyToManyBatchLoader.js.map +1 -1
- package/build/batchloaders/oneToManyBatchLoader.cjs +5 -6
- package/build/batchloaders/oneToManyBatchLoader.cjs.map +1 -1
- package/build/batchloaders/oneToManyBatchLoader.d.cts +2 -4
- package/build/batchloaders/oneToManyBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/oneToManyBatchLoader.d.mts +2 -4
- package/build/batchloaders/oneToManyBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/oneToManyBatchLoader.js +6 -7
- package/build/batchloaders/oneToManyBatchLoader.js.map +1 -1
- package/build/batchloaders/oneToOneBatchLoader.cjs +7 -8
- package/build/batchloaders/oneToOneBatchLoader.cjs.map +1 -1
- package/build/batchloaders/oneToOneBatchLoader.d.cts +2 -4
- package/build/batchloaders/oneToOneBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/oneToOneBatchLoader.d.mts +2 -4
- package/build/batchloaders/oneToOneBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/oneToOneBatchLoader.js +7 -8
- package/build/batchloaders/oneToOneBatchLoader.js.map +1 -1
- package/build/batchloaders/populateBatchLoader.cjs +14 -18
- package/build/batchloaders/populateBatchLoader.cjs.map +1 -1
- package/build/batchloaders/populateBatchLoader.d.cts +2 -4
- package/build/batchloaders/populateBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/populateBatchLoader.d.mts +2 -4
- package/build/batchloaders/populateBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/populateBatchLoader.js +14 -18
- package/build/batchloaders/populateBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.cjs +11 -11
- package/build/batchloaders/recursiveChildrenBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.d.cts +2 -4
- package/build/batchloaders/recursiveChildrenBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.d.mts +2 -4
- package/build/batchloaders/recursiveChildrenBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.js +11 -11
- package/build/batchloaders/recursiveChildrenBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.cjs +7 -8
- package/build/batchloaders/recursiveM2mBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.d.cts +2 -4
- package/build/batchloaders/recursiveM2mBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.d.mts +2 -4
- package/build/batchloaders/recursiveM2mBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.js +7 -8
- package/build/batchloaders/recursiveM2mBatchLoader.js.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.cjs +7 -8
- package/build/batchloaders/recursiveParentsBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.d.cts +2 -4
- package/build/batchloaders/recursiveParentsBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.d.mts +2 -4
- package/build/batchloaders/recursiveParentsBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.js +7 -8
- package/build/batchloaders/recursiveParentsBatchLoader.js.map +1 -1
- package/build/changes.cjs +7 -8
- package/build/changes.d.cts +3 -5
- package/build/changes.d.cts.map +1 -1
- package/build/changes.d.mts +3 -5
- package/build/changes.d.mts.map +1 -1
- package/build/changes.js +7 -8
- package/build/config.cjs +9 -10
- package/build/config.d.cts +6 -8
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +6 -8
- package/build/config.d.mts.map +1 -1
- package/build/config.js +9 -10
- package/build/configure.cjs +11 -12
- package/build/configure.d.cts +3 -5
- package/build/configure.d.cts.map +1 -1
- package/build/configure.d.mts +3 -5
- package/build/configure.d.mts.map +1 -1
- package/build/configure.js +11 -12
- package/build/dataloaders/buildCandidateBatchQuery.cjs +499 -0
- package/build/dataloaders/buildCandidateBatchQuery.cjs.map +1 -0
- package/build/dataloaders/buildCandidateBatchQuery.d.cts +57 -0
- package/build/dataloaders/buildCandidateBatchQuery.d.cts.map +1 -0
- package/build/dataloaders/buildCandidateBatchQuery.d.mts +57 -0
- package/build/dataloaders/buildCandidateBatchQuery.d.mts.map +1 -0
- package/build/dataloaders/buildCandidateBatchQuery.js +498 -0
- package/build/dataloaders/buildCandidateBatchQuery.js.map +1 -0
- package/build/dataloaders/collectFindArguments.cjs +48 -0
- package/build/dataloaders/collectFindArguments.cjs.map +1 -0
- package/build/dataloaders/collectFindArguments.d.cts +31 -0
- package/build/dataloaders/collectFindArguments.d.cts.map +1 -0
- package/build/dataloaders/collectFindArguments.d.mts +31 -0
- package/build/dataloaders/collectFindArguments.d.mts.map +1 -0
- package/build/dataloaders/collectFindArguments.js +47 -0
- package/build/dataloaders/collectFindArguments.js.map +1 -0
- package/build/dataloaders/fastWhereFilterHash.cjs +3 -4
- package/build/dataloaders/fastWhereFilterHash.d.cts +0 -2
- package/build/dataloaders/fastWhereFilterHash.d.cts.map +1 -1
- package/build/dataloaders/fastWhereFilterHash.d.mts +0 -2
- package/build/dataloaders/fastWhereFilterHash.d.mts.map +1 -1
- package/build/dataloaders/fastWhereFilterHash.js +3 -4
- package/build/dataloaders/findByUniqueDataLoader.cjs +2 -3
- package/build/dataloaders/findByUniqueDataLoader.d.cts +2 -4
- package/build/dataloaders/findByUniqueDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findByUniqueDataLoader.d.mts +2 -4
- package/build/dataloaders/findByUniqueDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findByUniqueDataLoader.js +2 -3
- package/build/dataloaders/findCountDataLoader.cjs +8 -9
- package/build/dataloaders/findCountDataLoader.d.cts +3 -5
- package/build/dataloaders/findCountDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findCountDataLoader.d.mts +3 -5
- package/build/dataloaders/findCountDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findCountDataLoader.js +8 -9
- package/build/dataloaders/findDataLoader.cjs +48 -77
- package/build/dataloaders/findDataLoader.cjs.map +1 -1
- package/build/dataloaders/findDataLoader.d.cts +5 -7
- package/build/dataloaders/findDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findDataLoader.d.mts +5 -7
- package/build/dataloaders/findDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findDataLoader.js +48 -77
- package/build/dataloaders/findDataLoader.js.map +1 -1
- package/build/dataloaders/findIdsDataLoader.cjs +6 -7
- package/build/dataloaders/findIdsDataLoader.d.cts +2 -4
- package/build/dataloaders/findIdsDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findIdsDataLoader.d.mts +2 -4
- package/build/dataloaders/findIdsDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findIdsDataLoader.js +6 -7
- package/build/dataloaders/findOrCreateDataLoader.cjs +7 -8
- package/build/dataloaders/findOrCreateDataLoader.d.cts +2 -4
- package/build/dataloaders/findOrCreateDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findOrCreateDataLoader.d.mts +2 -4
- package/build/dataloaders/findOrCreateDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findOrCreateDataLoader.js +7 -8
- package/build/dataloaders/findPaginatedDataLoader.cjs +6 -7
- package/build/dataloaders/findPaginatedDataLoader.d.cts +3 -5
- package/build/dataloaders/findPaginatedDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findPaginatedDataLoader.d.mts +3 -5
- package/build/dataloaders/findPaginatedDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findPaginatedDataLoader.js +6 -7
- package/build/dataloaders/lensDataLoader.cjs +5 -6
- package/build/dataloaders/lensDataLoader.d.cts +1 -3
- package/build/dataloaders/lensDataLoader.d.cts.map +1 -1
- package/build/dataloaders/lensDataLoader.d.mts +1 -3
- package/build/dataloaders/lensDataLoader.d.mts.map +1 -1
- package/build/dataloaders/lensDataLoader.js +5 -6
- package/build/dataloaders/manyToManyFindDataLoader.cjs +1 -2
- package/build/dataloaders/manyToManyFindDataLoader.d.cts +2 -4
- package/build/dataloaders/manyToManyFindDataLoader.d.cts.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.d.mts +2 -4
- package/build/dataloaders/manyToManyFindDataLoader.d.mts.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.js +1 -2
- package/build/dataloaders/oneToManyFindDataLoader.cjs +7 -5
- package/build/dataloaders/oneToManyFindDataLoader.cjs.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.d.cts +2 -4
- package/build/dataloaders/oneToManyFindDataLoader.d.cts.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.d.mts +2 -4
- package/build/dataloaders/oneToManyFindDataLoader.d.mts.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.js +8 -6
- package/build/dataloaders/oneToManyFindDataLoader.js.map +1 -1
- package/build/defaults.cjs +7 -8
- package/build/defaults.d.cts +2 -4
- package/build/defaults.d.cts.map +1 -1
- package/build/defaults.d.mts +2 -4
- package/build/defaults.d.mts.map +1 -1
- package/build/defaults.js +7 -8
- package/build/drivers/Driver.cjs +1 -1
- package/build/drivers/Driver.d.cts +2 -4
- package/build/drivers/Driver.d.cts.map +1 -1
- package/build/drivers/Driver.d.mts +2 -4
- package/build/drivers/Driver.d.mts.map +1 -1
- package/build/drivers/Driver.js +1 -1
- package/build/drivers/EntityWriter.cjs +6 -7
- package/build/drivers/EntityWriter.d.cts +1 -3
- package/build/drivers/EntityWriter.d.cts.map +1 -1
- package/build/drivers/EntityWriter.d.mts +1 -3
- package/build/drivers/EntityWriter.d.mts.map +1 -1
- package/build/drivers/EntityWriter.js +6 -7
- package/build/drivers/IdAssigner.cjs +7 -4
- package/build/drivers/IdAssigner.cjs.map +1 -1
- package/build/drivers/IdAssigner.d.cts +1 -2
- package/build/drivers/IdAssigner.d.cts.map +1 -1
- package/build/drivers/IdAssigner.d.mts +1 -2
- package/build/drivers/IdAssigner.d.mts.map +1 -1
- package/build/drivers/IdAssigner.js +7 -4
- package/build/drivers/IdAssigner.js.map +1 -1
- package/build/drivers/driverApi.cjs +4 -5
- package/build/drivers/driverApi.d.cts +2 -4
- package/build/drivers/driverApi.d.cts.map +1 -1
- package/build/drivers/driverApi.d.mts +2 -4
- package/build/drivers/driverApi.d.mts.map +1 -1
- package/build/drivers/driverApi.js +4 -5
- package/build/drivers/index.d.cts +1 -1
- package/build/drivers/index.d.mts +1 -1
- package/build/fields.cjs +87 -17
- package/build/fields.cjs.map +1 -1
- package/build/fields.d.cts +8 -2
- package/build/fields.d.cts.map +1 -1
- package/build/fields.d.mts +8 -2
- package/build/fields.d.mts.map +1 -1
- package/build/fields.js +87 -19
- package/build/fields.js.map +1 -1
- package/build/flush/FlushLock.cjs +1 -2
- package/build/flush/FlushLock.cjs.map +1 -1
- package/build/flush/FlushLock.d.cts +0 -2
- package/build/flush/FlushLock.d.cts.map +1 -1
- package/build/flush/FlushLock.d.mts +0 -2
- package/build/flush/FlushLock.d.mts.map +1 -1
- package/build/flush/FlushLock.js +1 -2
- package/build/flush/JoinRows.cjs +10 -10
- package/build/flush/JoinRows.cjs.map +1 -1
- package/build/flush/JoinRows.d.cts +2 -4
- package/build/flush/JoinRows.d.cts.map +1 -1
- package/build/flush/JoinRows.d.mts +2 -4
- package/build/flush/JoinRows.d.mts.map +1 -1
- package/build/flush/JoinRows.js +10 -10
- package/build/flush/JoinRows.js.map +1 -1
- package/build/flush/PendingChanges.d.cts +0 -2
- package/build/flush/PendingChanges.d.cts.map +1 -1
- package/build/flush/PendingChanges.d.mts +0 -2
- package/build/flush/PendingChanges.d.mts.map +1 -1
- package/build/flush/ReadDrift.cjs +7 -8
- package/build/flush/ReadDrift.cjs.map +1 -1
- package/build/flush/ReadDrift.d.cts +2 -4
- package/build/flush/ReadDrift.d.cts.map +1 -1
- package/build/flush/ReadDrift.d.mts +2 -4
- package/build/flush/ReadDrift.d.mts.map +1 -1
- package/build/flush/ReadDrift.js +7 -8
- package/build/flush/ReadDrift.js.map +1 -1
- package/build/flush/Todo.cjs +3 -4
- package/build/flush/Todo.d.cts +2 -4
- package/build/flush/Todo.d.cts.map +1 -1
- package/build/flush/Todo.d.mts +2 -4
- package/build/flush/Todo.d.mts.map +1 -1
- package/build/flush/Todo.js +3 -4
- package/build/getProperties.cjs +3 -4
- package/build/getProperties.d.cts +0 -2
- package/build/getProperties.d.cts.map +1 -1
- package/build/getProperties.d.mts +0 -2
- package/build/getProperties.d.mts.map +1 -1
- package/build/getProperties.js +3 -4
- package/build/index.cjs +59 -57
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +51 -53
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +51 -53
- package/build/index.d.mts.map +1 -1
- package/build/index.js +59 -58
- package/build/index.js.map +1 -1
- package/build/json.cjs +12 -13
- package/build/json.cjs.map +1 -1
- package/build/json.d.cts +5 -7
- package/build/json.d.cts.map +1 -1
- package/build/json.d.mts +5 -7
- package/build/json.d.mts.map +1 -1
- package/build/json.js +12 -13
- package/build/json.js.map +1 -1
- package/build/k.cjs +1 -2
- package/build/k.js +1 -2
- package/build/keys.cjs +5 -6
- package/build/keys.d.cts +3 -5
- package/build/keys.d.cts.map +1 -1
- package/build/keys.d.mts +3 -5
- package/build/keys.d.mts.map +1 -1
- package/build/keys.js +5 -6
- package/build/loading/HintTree.cjs +1 -2
- package/build/loading/HintTree.d.cts +2 -4
- package/build/loading/HintTree.d.cts.map +1 -1
- package/build/loading/HintTree.d.mts +2 -4
- package/build/loading/HintTree.d.mts.map +1 -1
- package/build/loading/HintTree.js +1 -2
- package/build/loading/IsLoadedCache.cjs +1 -2
- package/build/loading/IsLoadedCache.d.cts +0 -2
- package/build/loading/IsLoadedCache.d.cts.map +1 -1
- package/build/loading/IsLoadedCache.d.mts +0 -2
- package/build/loading/IsLoadedCache.d.mts.map +1 -1
- package/build/loading/IsLoadedCache.js +1 -2
- package/build/loading/loadHints.cjs +1 -2
- package/build/loading/loadHints.d.cts +4 -6
- package/build/loading/loadHints.d.cts.map +1 -1
- package/build/loading/loadHints.d.mts +4 -6
- package/build/loading/loadHints.d.mts.map +1 -1
- package/build/loading/loadHints.js +1 -2
- package/build/loading/loadLens.cjs +11 -8
- package/build/loading/loadLens.cjs.map +1 -1
- package/build/loading/loadLens.d.cts +2 -4
- package/build/loading/loadLens.d.cts.map +1 -1
- package/build/loading/loadLens.d.mts +2 -4
- package/build/loading/loadLens.d.mts.map +1 -1
- package/build/loading/loadLens.js +11 -8
- package/build/loading/loadLens.js.map +1 -1
- package/build/loading/withLoaded.cjs +1 -2
- package/build/loading/withLoaded.d.cts +2 -4
- package/build/loading/withLoaded.d.cts.map +1 -1
- package/build/loading/withLoaded.d.mts +2 -4
- package/build/loading/withLoaded.d.mts.map +1 -1
- package/build/loading/withLoaded.js +1 -2
- package/build/logging/FactoryLogger.cjs +2 -3
- package/build/logging/FactoryLogger.d.cts +1 -3
- package/build/logging/FactoryLogger.d.cts.map +1 -1
- package/build/logging/FactoryLogger.d.mts +1 -3
- package/build/logging/FactoryLogger.d.mts.map +1 -1
- package/build/logging/FactoryLogger.js +2 -3
- package/build/logging/FieldLogger.cjs +1 -2
- package/build/logging/FieldLogger.d.cts +0 -2
- package/build/logging/FieldLogger.d.cts.map +1 -1
- package/build/logging/FieldLogger.d.mts +0 -2
- package/build/logging/FieldLogger.d.mts.map +1 -1
- package/build/logging/FieldLogger.js +1 -2
- package/build/logging/ReactionLogger.cjs +3 -4
- package/build/logging/ReactionLogger.d.cts +3 -5
- package/build/logging/ReactionLogger.d.cts.map +1 -1
- package/build/logging/ReactionLogger.d.mts +3 -5
- package/build/logging/ReactionLogger.d.mts.map +1 -1
- package/build/logging/ReactionLogger.js +3 -4
- package/build/metrics/EntityMetrics.cjs +1 -2
- package/build/metrics/EntityMetrics.d.cts +0 -2
- package/build/metrics/EntityMetrics.d.cts.map +1 -1
- package/build/metrics/EntityMetrics.d.mts +0 -2
- package/build/metrics/EntityMetrics.d.mts.map +1 -1
- package/build/metrics/EntityMetrics.js +1 -2
- package/build/newEntity.cjs +5 -6
- package/build/newEntity.cjs.map +1 -1
- package/build/newEntity.d.cts +2 -4
- package/build/newEntity.d.cts.map +1 -1
- package/build/newEntity.d.mts +2 -4
- package/build/newEntity.d.mts.map +1 -1
- package/build/newEntity.js +5 -6
- package/build/newEntity.js.map +1 -1
- package/build/newTestInstance.cjs +9 -10
- package/build/newTestInstance.d.cts +3 -5
- package/build/newTestInstance.d.cts.map +1 -1
- package/build/newTestInstance.d.mts +3 -5
- package/build/newTestInstance.d.mts.map +1 -1
- package/build/newTestInstance.js +9 -10
- package/build/normalizeHints.cjs +1 -2
- package/build/normalizeHints.d.cts +1 -3
- package/build/normalizeHints.d.cts.map +1 -1
- package/build/normalizeHints.d.mts +1 -3
- package/build/normalizeHints.d.mts.map +1 -1
- package/build/normalizeHints.js +1 -2
- package/build/nowUTC.cjs +1 -2
- package/build/nowUTC.d.cts +0 -2
- package/build/nowUTC.d.cts.map +1 -1
- package/build/nowUTC.d.mts +0 -2
- package/build/nowUTC.d.mts.map +1 -1
- package/build/nowUTC.js +1 -2
- package/build/plugins/ImmutableEntitiesPlugin.cjs +3 -4
- package/build/plugins/ImmutableEntitiesPlugin.d.cts +1 -3
- package/build/plugins/ImmutableEntitiesPlugin.d.cts.map +1 -1
- package/build/plugins/ImmutableEntitiesPlugin.d.mts +1 -3
- package/build/plugins/ImmutableEntitiesPlugin.d.mts.map +1 -1
- package/build/plugins/ImmutableEntitiesPlugin.js +3 -4
- package/build/plugins/PreloadPlugin.cjs +1 -1
- package/build/plugins/PreloadPlugin.d.cts +4 -6
- package/build/plugins/PreloadPlugin.d.cts.map +1 -1
- package/build/plugins/PreloadPlugin.d.mts +4 -6
- package/build/plugins/PreloadPlugin.d.mts.map +1 -1
- package/build/plugins/PreloadPlugin.js +1 -1
- package/build/preloading/JsonAggregatePreloader.cjs +13 -13
- package/build/preloading/JsonAggregatePreloader.cjs.map +1 -1
- package/build/preloading/JsonAggregatePreloader.d.cts +3 -5
- package/build/preloading/JsonAggregatePreloader.d.cts.map +1 -1
- package/build/preloading/JsonAggregatePreloader.d.mts +3 -5
- package/build/preloading/JsonAggregatePreloader.d.mts.map +1 -1
- package/build/preloading/JsonAggregatePreloader.js +13 -13
- package/build/preloading/JsonAggregatePreloader.js.map +1 -1
- package/build/preloading/canPreload.cjs +1 -2
- package/build/preloading/canPreload.d.cts +0 -2
- package/build/preloading/canPreload.d.cts.map +1 -1
- package/build/preloading/canPreload.d.mts +0 -2
- package/build/preloading/canPreload.d.mts.map +1 -1
- package/build/preloading/canPreload.js +1 -2
- package/build/preloading/partitionHint.cjs +4 -5
- package/build/preloading/partitionHint.d.cts +1 -3
- package/build/preloading/partitionHint.d.cts.map +1 -1
- package/build/preloading/partitionHint.d.mts +1 -3
- package/build/preloading/partitionHint.d.mts.map +1 -1
- package/build/preloading/partitionHint.js +4 -5
- package/build/queries/ConditionBuilder.cjs +2 -3
- package/build/queries/ConditionBuilder.d.cts +1 -3
- package/build/queries/ConditionBuilder.d.cts.map +1 -1
- package/build/queries/ConditionBuilder.d.mts +1 -3
- package/build/queries/ConditionBuilder.d.mts.map +1 -1
- package/build/queries/ConditionBuilder.js +2 -3
- package/build/queries/conditions.cjs +1 -2
- package/build/queries/conditions.d.cts +0 -2
- package/build/queries/conditions.d.cts.map +1 -1
- package/build/queries/conditions.d.mts +0 -2
- package/build/queries/conditions.d.mts.map +1 -1
- package/build/queries/conditions.js +1 -2
- package/build/queries/entityQueryUtils.cjs +2 -3
- package/build/queries/entityQueryUtils.d.cts +1 -3
- package/build/queries/entityQueryUtils.d.cts.map +1 -1
- package/build/queries/entityQueryUtils.d.mts +1 -3
- package/build/queries/entityQueryUtils.d.mts.map +1 -1
- package/build/queries/entityQueryUtils.js +2 -3
- package/build/queries/find/Aliases.cjs +4 -5
- package/build/queries/find/Aliases.d.cts +5 -7
- package/build/queries/find/Aliases.d.cts.map +1 -1
- package/build/queries/find/Aliases.d.mts +5 -7
- package/build/queries/find/Aliases.d.mts.map +1 -1
- package/build/queries/find/Aliases.js +4 -5
- package/build/queries/find/DeferredAlias.cjs +1 -2
- package/build/queries/find/DeferredAlias.d.cts +2 -4
- package/build/queries/find/DeferredAlias.d.cts.map +1 -1
- package/build/queries/find/DeferredAlias.d.mts +2 -4
- package/build/queries/find/DeferredAlias.d.mts.map +1 -1
- package/build/queries/find/DeferredAlias.js +1 -2
- package/build/queries/find/EntityFilter.cjs +1 -2
- package/build/queries/find/EntityFilter.d.cts +3 -5
- package/build/queries/find/EntityFilter.d.cts.map +1 -1
- package/build/queries/find/EntityFilter.d.mts +3 -5
- package/build/queries/find/EntityFilter.d.mts.map +1 -1
- package/build/queries/find/EntityFilter.js +1 -2
- package/build/queries/find/EntityGraphQLFilter.cjs +1 -2
- package/build/queries/find/EntityGraphQLFilter.d.cts +2 -4
- package/build/queries/find/EntityGraphQLFilter.d.cts.map +1 -1
- package/build/queries/find/EntityGraphQLFilter.d.mts +2 -4
- package/build/queries/find/EntityGraphQLFilter.d.mts.map +1 -1
- package/build/queries/find/EntityGraphQLFilter.js +1 -2
- package/build/queries/find/QueryParser.cjs +9 -10
- package/build/queries/find/QueryParser.cjs.map +1 -1
- package/build/queries/find/QueryParser.collectionJoins.cjs +1 -2
- package/build/queries/find/QueryParser.collectionJoins.d.cts +0 -2
- package/build/queries/find/QueryParser.collectionJoins.d.cts.map +1 -1
- package/build/queries/find/QueryParser.collectionJoins.d.mts +0 -2
- package/build/queries/find/QueryParser.collectionJoins.d.mts.map +1 -1
- package/build/queries/find/QueryParser.collectionJoins.js +1 -2
- package/build/queries/find/QueryParser.d.cts +4 -4
- package/build/queries/find/QueryParser.d.cts.map +1 -1
- package/build/queries/find/QueryParser.d.mts +4 -4
- package/build/queries/find/QueryParser.d.mts.map +1 -1
- package/build/queries/find/QueryParser.js +9 -10
- package/build/queries/find/QueryParser.js.map +1 -1
- package/build/queries/find/QueryParser.pruning.cjs +2 -3
- package/build/queries/find/QueryParser.pruning.d.cts +0 -2
- package/build/queries/find/QueryParser.pruning.d.cts.map +1 -1
- package/build/queries/find/QueryParser.pruning.d.mts +0 -2
- package/build/queries/find/QueryParser.pruning.d.mts.map +1 -1
- package/build/queries/find/QueryParser.pruning.js +2 -3
- package/build/queries/find/QueryVisitor.cjs +1 -2
- package/build/queries/find/QueryVisitor.d.cts +0 -2
- package/build/queries/find/QueryVisitor.d.cts.map +1 -1
- package/build/queries/find/QueryVisitor.d.mts +0 -2
- package/build/queries/find/QueryVisitor.d.mts.map +1 -1
- package/build/queries/find/QueryVisitor.js +1 -2
- package/build/queries/find/buildFindQuery.cjs +5 -6
- package/build/queries/find/buildFindQuery.cjs.map +1 -1
- package/build/queries/find/buildFindQuery.d.cts +0 -2
- package/build/queries/find/buildFindQuery.d.cts.map +1 -1
- package/build/queries/find/buildFindQuery.d.mts +0 -2
- package/build/queries/find/buildFindQuery.d.mts.map +1 -1
- package/build/queries/find/buildFindQuery.js +5 -6
- package/build/queries/find/buildFindQuery.js.map +1 -1
- package/build/queries/find/scopes.cjs +1 -2
- package/build/queries/find/scopes.d.cts +5 -7
- package/build/queries/find/scopes.d.cts.map +1 -1
- package/build/queries/find/scopes.d.mts +5 -7
- package/build/queries/find/scopes.d.mts.map +1 -1
- package/build/queries/find/scopes.js +1 -2
- package/build/queries/parsedConditions.cjs +1 -2
- package/build/queries/parsedConditions.d.cts +0 -2
- package/build/queries/parsedConditions.d.cts.map +1 -1
- package/build/queries/parsedConditions.d.mts +0 -2
- package/build/queries/parsedConditions.d.mts.map +1 -1
- package/build/queries/parsedConditions.js +1 -2
- package/build/queries/renderConditions.cjs +3 -4
- package/build/queries/renderConditions.d.cts +0 -2
- package/build/queries/renderConditions.d.cts.map +1 -1
- package/build/queries/renderConditions.d.mts +0 -2
- package/build/queries/renderConditions.d.mts.map +1 -1
- package/build/queries/renderConditions.js +3 -4
- package/build/queries/skipCondition.cjs +1 -2
- package/build/queries/skipCondition.d.cts +0 -2
- package/build/queries/skipCondition.d.cts.map +1 -1
- package/build/queries/skipCondition.d.mts +0 -2
- package/build/queries/skipCondition.d.mts.map +1 -1
- package/build/queries/skipCondition.js +1 -2
- package/build/queries/sql/AliasAssigner.cjs +1 -2
- package/build/queries/sql/AliasAssigner.d.cts +0 -2
- package/build/queries/sql/AliasAssigner.d.cts.map +1 -1
- package/build/queries/sql/AliasAssigner.d.mts +0 -2
- package/build/queries/sql/AliasAssigner.d.mts.map +1 -1
- package/build/queries/sql/AliasAssigner.js +1 -2
- package/build/queries/sql/Expr.cjs +3 -4
- package/build/queries/sql/Expr.d.cts +2 -4
- package/build/queries/sql/Expr.d.cts.map +1 -1
- package/build/queries/sql/Expr.d.mts +2 -4
- package/build/queries/sql/Expr.d.mts.map +1 -1
- package/build/queries/sql/Expr.js +3 -4
- package/build/queries/sql/JoinTree.cjs +3 -4
- package/build/queries/sql/JoinTree.d.cts +5 -7
- package/build/queries/sql/JoinTree.d.cts.map +1 -1
- package/build/queries/sql/JoinTree.d.mts +5 -7
- package/build/queries/sql/JoinTree.d.mts.map +1 -1
- package/build/queries/sql/JoinTree.js +3 -4
- package/build/queries/sql/Tables.cjs +8 -9
- package/build/queries/sql/Tables.d.cts +5 -7
- package/build/queries/sql/Tables.d.cts.map +1 -1
- package/build/queries/sql/Tables.d.mts +5 -7
- package/build/queries/sql/Tables.d.mts.map +1 -1
- package/build/queries/sql/Tables.js +8 -9
- package/build/queries/sql/custom.cjs +1 -2
- package/build/queries/sql/custom.d.cts +2 -4
- package/build/queries/sql/custom.d.cts.map +1 -1
- package/build/queries/sql/custom.d.mts +2 -4
- package/build/queries/sql/custom.d.mts.map +1 -1
- package/build/queries/sql/custom.js +1 -2
- package/build/queries/sql/execute.cjs +6 -7
- package/build/queries/sql/execute.d.cts +6 -8
- package/build/queries/sql/execute.d.cts.map +1 -1
- package/build/queries/sql/execute.d.mts +6 -8
- package/build/queries/sql/execute.d.mts.map +1 -1
- package/build/queries/sql/execute.js +6 -7
- package/build/queries/sql/expressions/arrayAgg.cjs +2 -3
- package/build/queries/sql/expressions/arrayAgg.d.cts +1 -3
- package/build/queries/sql/expressions/arrayAgg.d.cts.map +1 -1
- package/build/queries/sql/expressions/arrayAgg.d.mts +1 -3
- package/build/queries/sql/expressions/arrayAgg.d.mts.map +1 -1
- package/build/queries/sql/expressions/arrayAgg.js +2 -3
- package/build/queries/sql/expressions/case.cjs +2 -3
- package/build/queries/sql/expressions/case.d.cts +1 -3
- package/build/queries/sql/expressions/case.d.cts.map +1 -1
- package/build/queries/sql/expressions/case.d.mts +1 -3
- package/build/queries/sql/expressions/case.d.mts.map +1 -1
- package/build/queries/sql/expressions/case.js +2 -3
- package/build/queries/sql/expressions/coalesce.cjs +2 -3
- package/build/queries/sql/expressions/coalesce.d.cts +1 -3
- package/build/queries/sql/expressions/coalesce.d.cts.map +1 -1
- package/build/queries/sql/expressions/coalesce.d.mts +1 -3
- package/build/queries/sql/expressions/coalesce.d.mts.map +1 -1
- package/build/queries/sql/expressions/coalesce.js +2 -3
- package/build/queries/sql/expressions/codecs.cjs +2 -3
- package/build/queries/sql/expressions/codecs.d.cts +0 -2
- package/build/queries/sql/expressions/codecs.d.cts.map +1 -1
- package/build/queries/sql/expressions/codecs.d.mts +0 -2
- package/build/queries/sql/expressions/codecs.d.mts.map +1 -1
- package/build/queries/sql/expressions/codecs.js +2 -3
- package/build/queries/sql/expressions/expression.cjs +4 -5
- package/build/queries/sql/expressions/expression.d.cts +2 -4
- package/build/queries/sql/expressions/expression.d.cts.map +1 -1
- package/build/queries/sql/expressions/expression.d.mts +2 -4
- package/build/queries/sql/expressions/expression.d.mts.map +1 -1
- package/build/queries/sql/expressions/expression.js +4 -5
- package/build/queries/sql/expressions/greatest.cjs +2 -3
- package/build/queries/sql/expressions/greatest.d.cts +1 -3
- package/build/queries/sql/expressions/greatest.d.cts.map +1 -1
- package/build/queries/sql/expressions/greatest.d.mts +1 -3
- package/build/queries/sql/expressions/greatest.d.mts.map +1 -1
- package/build/queries/sql/expressions/greatest.js +2 -3
- package/build/queries/sql/expressions/least.cjs +2 -3
- package/build/queries/sql/expressions/least.d.cts +1 -3
- package/build/queries/sql/expressions/least.d.cts.map +1 -1
- package/build/queries/sql/expressions/least.d.mts +1 -3
- package/build/queries/sql/expressions/least.d.mts.map +1 -1
- package/build/queries/sql/expressions/least.js +2 -3
- package/build/queries/sql/expressions/nullIf.cjs +2 -3
- package/build/queries/sql/expressions/nullIf.d.cts +1 -3
- package/build/queries/sql/expressions/nullIf.d.cts.map +1 -1
- package/build/queries/sql/expressions/nullIf.d.mts +1 -3
- package/build/queries/sql/expressions/nullIf.d.mts.map +1 -1
- package/build/queries/sql/expressions/nullIf.js +2 -3
- package/build/queries/sql/expressions/parseExpression.cjs +3 -4
- package/build/queries/sql/expressions/parseExpression.d.cts +0 -2
- package/build/queries/sql/expressions/parseExpression.d.cts.map +1 -1
- package/build/queries/sql/expressions/parseExpression.d.mts +0 -2
- package/build/queries/sql/expressions/parseExpression.d.mts.map +1 -1
- package/build/queries/sql/expressions/parseExpression.js +3 -4
- package/build/queries/sql/expressions/types.d.cts +1 -3
- package/build/queries/sql/expressions/types.d.cts.map +1 -1
- package/build/queries/sql/expressions/types.d.mts +1 -3
- package/build/queries/sql/expressions/types.d.mts.map +1 -1
- package/build/queries/sql/keywords.cjs +1 -2
- package/build/queries/sql/keywords.d.cts +0 -2
- package/build/queries/sql/keywords.d.cts.map +1 -1
- package/build/queries/sql/keywords.d.mts +0 -2
- package/build/queries/sql/keywords.d.mts.map +1 -1
- package/build/queries/sql/keywords.js +1 -2
- package/build/queries/sql/query.cjs +9 -10
- package/build/queries/sql/query.d.cts +6 -8
- package/build/queries/sql/query.d.cts.map +1 -1
- package/build/queries/sql/query.d.mts +6 -8
- package/build/queries/sql/query.d.mts.map +1 -1
- package/build/queries/sql/query.js +9 -10
- package/build/queries/unnest.cjs +1 -2
- package/build/queries/unnest.d.cts +1 -3
- package/build/queries/unnest.d.cts.map +1 -1
- package/build/queries/unnest.d.mts +1 -3
- package/build/queries/unnest.d.mts.map +1 -1
- package/build/queries/unnest.js +1 -2
- package/build/queries/valueFilters.cjs +3 -4
- package/build/queries/valueFilters.d.cts +2 -4
- package/build/queries/valueFilters.d.cts.map +1 -1
- package/build/queries/valueFilters.d.mts +2 -4
- package/build/queries/valueFilters.d.mts.map +1 -1
- package/build/queries/valueFilters.js +3 -4
- package/build/reactivity/ReactionsManager.cjs +6 -7
- package/build/reactivity/ReactionsManager.d.cts +2 -4
- package/build/reactivity/ReactionsManager.d.cts.map +1 -1
- package/build/reactivity/ReactionsManager.d.mts +2 -4
- package/build/reactivity/ReactionsManager.d.mts.map +1 -1
- package/build/reactivity/ReactionsManager.js +6 -7
- package/build/reactivity/reactiveHints.cjs +8 -9
- package/build/reactivity/reactiveHints.d.cts +8 -10
- package/build/reactivity/reactiveHints.d.cts.map +1 -1
- package/build/reactivity/reactiveHints.d.mts +8 -10
- package/build/reactivity/reactiveHints.d.mts.map +1 -1
- package/build/reactivity/reactiveHints.js +8 -9
- package/build/relations/AbstractPropertyImpl.cjs +1 -2
- package/build/relations/AbstractPropertyImpl.d.cts +0 -2
- package/build/relations/AbstractPropertyImpl.d.cts.map +1 -1
- package/build/relations/AbstractPropertyImpl.d.mts +0 -2
- package/build/relations/AbstractPropertyImpl.d.mts.map +1 -1
- package/build/relations/AbstractPropertyImpl.js +1 -2
- package/build/relations/AbstractRelationImpl.cjs +1 -2
- package/build/relations/AbstractRelationImpl.d.cts +0 -2
- package/build/relations/AbstractRelationImpl.d.cts.map +1 -1
- package/build/relations/AbstractRelationImpl.d.mts +0 -2
- package/build/relations/AbstractRelationImpl.d.mts.map +1 -1
- package/build/relations/AbstractRelationImpl.js +1 -2
- package/build/relations/AsyncProperty.cjs +3 -4
- package/build/relations/AsyncProperty.d.cts +2 -4
- package/build/relations/AsyncProperty.d.cts.map +1 -1
- package/build/relations/AsyncProperty.d.mts +2 -4
- package/build/relations/AsyncProperty.d.mts.map +1 -1
- package/build/relations/AsyncProperty.js +3 -4
- package/build/relations/AsyncReactiveField.cjs +10 -11
- package/build/relations/AsyncReactiveField.d.cts +4 -6
- package/build/relations/AsyncReactiveField.d.cts.map +1 -1
- package/build/relations/AsyncReactiveField.d.mts +4 -6
- package/build/relations/AsyncReactiveField.d.mts.map +1 -1
- package/build/relations/AsyncReactiveField.js +10 -11
- package/build/relations/Collection.cjs +3 -4
- package/build/relations/Collection.d.cts +2 -4
- package/build/relations/Collection.d.cts.map +1 -1
- package/build/relations/Collection.d.mts +2 -4
- package/build/relations/Collection.d.mts.map +1 -1
- package/build/relations/Collection.js +3 -4
- package/build/relations/CustomCollection.cjs +40 -8
- package/build/relations/CustomCollection.cjs.map +1 -1
- package/build/relations/CustomCollection.d.cts +6 -6
- package/build/relations/CustomCollection.d.cts.map +1 -1
- package/build/relations/CustomCollection.d.mts +6 -6
- package/build/relations/CustomCollection.d.mts.map +1 -1
- package/build/relations/CustomCollection.js +40 -8
- package/build/relations/CustomCollection.js.map +1 -1
- package/build/relations/CustomReference.cjs +36 -8
- package/build/relations/CustomReference.cjs.map +1 -1
- package/build/relations/CustomReference.d.cts +8 -8
- package/build/relations/CustomReference.d.cts.map +1 -1
- package/build/relations/CustomReference.d.mts +8 -8
- package/build/relations/CustomReference.d.mts.map +1 -1
- package/build/relations/CustomReference.js +36 -8
- package/build/relations/CustomReference.js.map +1 -1
- package/build/relations/EnumCollection.cjs +4 -5
- package/build/relations/EnumCollection.d.cts +3 -5
- package/build/relations/EnumCollection.d.cts.map +1 -1
- package/build/relations/EnumCollection.d.mts +3 -5
- package/build/relations/EnumCollection.d.mts.map +1 -1
- package/build/relations/EnumCollection.js +4 -5
- package/build/relations/LargeCollection.cjs +2 -2
- package/build/relations/LargeCollection.d.cts +2 -4
- package/build/relations/LargeCollection.d.cts.map +1 -1
- package/build/relations/LargeCollection.d.mts +2 -4
- package/build/relations/LargeCollection.d.mts.map +1 -1
- package/build/relations/LargeCollection.js +2 -2
- package/build/relations/LazyField.cjs +14 -15
- package/build/relations/LazyField.cjs.map +1 -1
- package/build/relations/LazyField.d.cts +2 -4
- package/build/relations/LazyField.d.cts.map +1 -1
- package/build/relations/LazyField.d.mts +2 -4
- package/build/relations/LazyField.d.mts.map +1 -1
- package/build/relations/LazyField.js +14 -15
- package/build/relations/LazyField.js.map +1 -1
- package/build/relations/ManyToManyCollection.cjs +68 -13
- package/build/relations/ManyToManyCollection.cjs.map +1 -1
- package/build/relations/ManyToManyCollection.d.cts +2 -4
- package/build/relations/ManyToManyCollection.d.cts.map +1 -1
- package/build/relations/ManyToManyCollection.d.mts +2 -4
- package/build/relations/ManyToManyCollection.d.mts.map +1 -1
- package/build/relations/ManyToManyCollection.js +68 -13
- package/build/relations/ManyToManyCollection.js.map +1 -1
- package/build/relations/ManyToManyLargeCollection.cjs +35 -13
- package/build/relations/ManyToManyLargeCollection.cjs.map +1 -1
- package/build/relations/ManyToManyLargeCollection.d.cts +6 -8
- package/build/relations/ManyToManyLargeCollection.d.cts.map +1 -1
- package/build/relations/ManyToManyLargeCollection.d.mts +6 -8
- package/build/relations/ManyToManyLargeCollection.d.mts.map +1 -1
- package/build/relations/ManyToManyLargeCollection.js +35 -13
- package/build/relations/ManyToManyLargeCollection.js.map +1 -1
- package/build/relations/ManyToOneReference.cjs +35 -19
- package/build/relations/ManyToOneReference.cjs.map +1 -1
- package/build/relations/ManyToOneReference.d.cts +6 -8
- package/build/relations/ManyToOneReference.d.cts.map +1 -1
- package/build/relations/ManyToOneReference.d.mts +6 -8
- package/build/relations/ManyToOneReference.d.mts.map +1 -1
- package/build/relations/ManyToOneReference.js +35 -19
- package/build/relations/ManyToOneReference.js.map +1 -1
- package/build/relations/OneToManyCollection.cjs +71 -15
- package/build/relations/OneToManyCollection.cjs.map +1 -1
- package/build/relations/OneToManyCollection.d.cts +3 -5
- package/build/relations/OneToManyCollection.d.cts.map +1 -1
- package/build/relations/OneToManyCollection.d.mts +3 -5
- package/build/relations/OneToManyCollection.d.mts.map +1 -1
- package/build/relations/OneToManyCollection.js +71 -15
- package/build/relations/OneToManyCollection.js.map +1 -1
- package/build/relations/OneToManyLargeCollection.cjs +25 -10
- package/build/relations/OneToManyLargeCollection.cjs.map +1 -1
- package/build/relations/OneToManyLargeCollection.d.cts +4 -6
- package/build/relations/OneToManyLargeCollection.d.cts.map +1 -1
- package/build/relations/OneToManyLargeCollection.d.mts +4 -6
- package/build/relations/OneToManyLargeCollection.d.mts.map +1 -1
- package/build/relations/OneToManyLargeCollection.js +25 -10
- package/build/relations/OneToManyLargeCollection.js.map +1 -1
- package/build/relations/OneToOneReference.cjs +41 -13
- package/build/relations/OneToOneReference.cjs.map +1 -1
- package/build/relations/OneToOneReference.d.cts +6 -8
- package/build/relations/OneToOneReference.d.cts.map +1 -1
- package/build/relations/OneToOneReference.d.mts +6 -8
- package/build/relations/OneToOneReference.d.mts.map +1 -1
- package/build/relations/OneToOneReference.js +41 -13
- package/build/relations/OneToOneReference.js.map +1 -1
- package/build/relations/PolymorphicReference.cjs +33 -17
- package/build/relations/PolymorphicReference.cjs.map +1 -1
- package/build/relations/PolymorphicReference.d.cts +5 -7
- package/build/relations/PolymorphicReference.d.cts.map +1 -1
- package/build/relations/PolymorphicReference.d.mts +5 -7
- package/build/relations/PolymorphicReference.d.mts.map +1 -1
- package/build/relations/PolymorphicReference.js +33 -17
- package/build/relations/PolymorphicReference.js.map +1 -1
- package/build/relations/PropertySymbols.cjs +1 -2
- package/build/relations/PropertySymbols.d.cts +0 -2
- package/build/relations/PropertySymbols.d.cts.map +1 -1
- package/build/relations/PropertySymbols.d.mts +0 -2
- package/build/relations/PropertySymbols.d.mts.map +1 -1
- package/build/relations/PropertySymbols.js +1 -2
- package/build/relations/ReactiveField.cjs +9 -10
- package/build/relations/ReactiveField.d.cts +4 -6
- package/build/relations/ReactiveField.d.cts.map +1 -1
- package/build/relations/ReactiveField.d.mts +4 -6
- package/build/relations/ReactiveField.d.mts.map +1 -1
- package/build/relations/ReactiveField.js +9 -10
- package/build/relations/ReactiveGetter.cjs +2 -3
- package/build/relations/ReactiveGetter.d.cts +2 -4
- package/build/relations/ReactiveGetter.d.cts.map +1 -1
- package/build/relations/ReactiveGetter.d.mts +2 -4
- package/build/relations/ReactiveGetter.d.mts.map +1 -1
- package/build/relations/ReactiveGetter.js +2 -3
- package/build/relations/ReactiveManyToMany.cjs +59 -17
- package/build/relations/ReactiveManyToMany.cjs.map +1 -1
- package/build/relations/ReactiveManyToMany.d.cts +7 -6
- package/build/relations/ReactiveManyToMany.d.cts.map +1 -1
- package/build/relations/ReactiveManyToMany.d.mts +7 -6
- package/build/relations/ReactiveManyToMany.d.mts.map +1 -1
- package/build/relations/ReactiveManyToMany.js +59 -17
- package/build/relations/ReactiveManyToMany.js.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.cjs +41 -10
- package/build/relations/ReactiveManyToManyOtherSide.cjs.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.d.cts +4 -6
- package/build/relations/ReactiveManyToManyOtherSide.d.cts.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.d.mts +4 -6
- package/build/relations/ReactiveManyToManyOtherSide.d.mts.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.js +41 -10
- package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
- package/build/relations/ReactiveReference.cjs +29 -12
- package/build/relations/ReactiveReference.cjs.map +1 -1
- package/build/relations/ReactiveReference.d.cts +7 -9
- package/build/relations/ReactiveReference.d.cts.map +1 -1
- package/build/relations/ReactiveReference.d.mts +7 -9
- package/build/relations/ReactiveReference.d.mts.map +1 -1
- package/build/relations/ReactiveReference.js +29 -12
- package/build/relations/ReactiveReference.js.map +1 -1
- package/build/relations/ReadOnlyCollection.cjs +3 -4
- package/build/relations/ReadOnlyCollection.d.cts +1 -3
- package/build/relations/ReadOnlyCollection.d.cts.map +1 -1
- package/build/relations/ReadOnlyCollection.d.mts +1 -3
- package/build/relations/ReadOnlyCollection.d.mts.map +1 -1
- package/build/relations/ReadOnlyCollection.js +3 -4
- package/build/relations/RecursiveCollection.cjs +60 -11
- package/build/relations/RecursiveCollection.cjs.map +1 -1
- package/build/relations/RecursiveCollection.d.cts +3 -5
- package/build/relations/RecursiveCollection.d.cts.map +1 -1
- package/build/relations/RecursiveCollection.d.mts +3 -5
- package/build/relations/RecursiveCollection.d.mts.map +1 -1
- package/build/relations/RecursiveCollection.js +60 -11
- package/build/relations/RecursiveCollection.js.map +1 -1
- package/build/relations/RecursiveCycleError.cjs +1 -2
- package/build/relations/RecursiveCycleError.d.cts +0 -2
- package/build/relations/RecursiveCycleError.d.cts.map +1 -1
- package/build/relations/RecursiveCycleError.d.mts +0 -2
- package/build/relations/RecursiveCycleError.d.mts.map +1 -1
- package/build/relations/RecursiveCycleError.js +1 -2
- package/build/relations/Reference.cjs +4 -5
- package/build/relations/Reference.d.cts +3 -5
- package/build/relations/Reference.d.cts.map +1 -1
- package/build/relations/Reference.d.mts +3 -5
- package/build/relations/Reference.d.mts.map +1 -1
- package/build/relations/Reference.js +4 -5
- package/build/relations/ReferenceSymbols.cjs +1 -2
- package/build/relations/ReferenceSymbols.d.cts +0 -2
- package/build/relations/ReferenceSymbols.d.cts.map +1 -1
- package/build/relations/ReferenceSymbols.d.mts +0 -2
- package/build/relations/ReferenceSymbols.d.mts.map +1 -1
- package/build/relations/ReferenceSymbols.js +1 -2
- package/build/relations/Relation.cjs +3 -4
- package/build/relations/Relation.d.cts +1 -3
- package/build/relations/Relation.d.cts.map +1 -1
- package/build/relations/Relation.d.mts +1 -3
- package/build/relations/Relation.d.mts.map +1 -1
- package/build/relations/Relation.js +3 -4
- package/build/relations/RelationSymbols.cjs +1 -2
- package/build/relations/RelationSymbols.d.cts +0 -2
- package/build/relations/RelationSymbols.d.cts.map +1 -1
- package/build/relations/RelationSymbols.d.mts +0 -2
- package/build/relations/RelationSymbols.d.mts.map +1 -1
- package/build/relations/RelationSymbols.js +1 -2
- package/build/relations/hasAsyncMethod.cjs +6 -7
- package/build/relations/hasAsyncMethod.d.cts +2 -4
- package/build/relations/hasAsyncMethod.d.cts.map +1 -1
- package/build/relations/hasAsyncMethod.d.mts +2 -4
- package/build/relations/hasAsyncMethod.d.mts.map +1 -1
- package/build/relations/hasAsyncMethod.js +6 -7
- package/build/relations/hasManyDerived.cjs +5 -6
- package/build/relations/hasManyDerived.cjs.map +1 -1
- package/build/relations/hasManyDerived.d.cts +2 -4
- package/build/relations/hasManyDerived.d.cts.map +1 -1
- package/build/relations/hasManyDerived.d.mts +2 -4
- package/build/relations/hasManyDerived.d.mts.map +1 -1
- package/build/relations/hasManyDerived.js +5 -6
- package/build/relations/hasManyDerived.js.map +1 -1
- package/build/relations/hasManyThrough.cjs +4 -5
- package/build/relations/hasManyThrough.cjs.map +1 -1
- package/build/relations/hasManyThrough.d.cts +0 -2
- package/build/relations/hasManyThrough.d.cts.map +1 -1
- package/build/relations/hasManyThrough.d.mts +0 -2
- package/build/relations/hasManyThrough.d.mts.map +1 -1
- package/build/relations/hasManyThrough.js +4 -5
- package/build/relations/hasManyThrough.js.map +1 -1
- package/build/relations/hasOneDerived.cjs +5 -6
- package/build/relations/hasOneDerived.cjs.map +1 -1
- package/build/relations/hasOneDerived.d.cts +2 -4
- package/build/relations/hasOneDerived.d.cts.map +1 -1
- package/build/relations/hasOneDerived.d.mts +2 -4
- package/build/relations/hasOneDerived.d.mts.map +1 -1
- package/build/relations/hasOneDerived.js +5 -6
- package/build/relations/hasOneDerived.js.map +1 -1
- package/build/relations/hasOneThrough.cjs +4 -5
- package/build/relations/hasOneThrough.cjs.map +1 -1
- package/build/relations/hasOneThrough.d.cts +0 -2
- package/build/relations/hasOneThrough.d.cts.map +1 -1
- package/build/relations/hasOneThrough.d.mts +0 -2
- package/build/relations/hasOneThrough.d.mts.map +1 -1
- package/build/relations/hasOneThrough.js +4 -5
- package/build/relations/hasOneThrough.js.map +1 -1
- package/build/relations/hasProperty.cjs +5 -6
- package/build/relations/hasProperty.d.cts +2 -4
- package/build/relations/hasProperty.d.cts.map +1 -1
- package/build/relations/hasProperty.d.mts +2 -4
- package/build/relations/hasProperty.d.mts.map +1 -1
- package/build/relations/hasProperty.js +5 -6
- package/build/relations/hasReactiveAsyncMethod.cjs +5 -6
- package/build/relations/hasReactiveAsyncMethod.d.cts +3 -5
- package/build/relations/hasReactiveAsyncMethod.d.cts.map +1 -1
- package/build/relations/hasReactiveAsyncMethod.d.mts +3 -5
- package/build/relations/hasReactiveAsyncMethod.d.mts.map +1 -1
- package/build/relations/hasReactiveAsyncMethod.js +5 -6
- package/build/relations/index.cjs +9 -9
- package/build/relations/index.d.cts +3 -3
- package/build/relations/index.d.mts +3 -3
- package/build/relations/index.js +9 -9
- package/build/relations/isCascadeDelete.cjs +1 -2
- package/build/relations/isCascadeDelete.d.cts +0 -2
- package/build/relations/isCascadeDelete.d.cts.map +1 -1
- package/build/relations/isCascadeDelete.d.mts +0 -2
- package/build/relations/isCascadeDelete.d.mts.map +1 -1
- package/build/relations/isCascadeDelete.js +1 -2
- package/build/relations/relationVisibility.cjs +51 -0
- package/build/relations/relationVisibility.cjs.map +1 -0
- package/build/relations/relationVisibility.d.cts +10 -0
- package/build/relations/relationVisibility.d.cts.map +1 -0
- package/build/relations/relationVisibility.d.mts +10 -0
- package/build/relations/relationVisibility.d.mts.map +1 -0
- package/build/relations/relationVisibility.js +47 -0
- package/build/relations/relationVisibility.js.map +1 -0
- package/build/resurrection.cjs +4 -5
- package/build/resurrection.d.cts +2 -4
- package/build/resurrection.d.cts.map +1 -1
- package/build/resurrection.d.mts +2 -4
- package/build/resurrection.d.mts.map +1 -1
- package/build/resurrection.js +4 -5
- package/build/rules.cjs +6 -7
- package/build/rules.d.cts +3 -5
- package/build/rules.d.cts.map +1 -1
- package/build/rules.d.mts +3 -5
- package/build/rules.d.mts.map +1 -1
- package/build/rules.js +6 -7
- package/build/runtimeConfig.cjs +1 -2
- package/build/runtimeConfig.d.cts +0 -2
- package/build/runtimeConfig.d.cts.map +1 -1
- package/build/runtimeConfig.d.mts +0 -2
- package/build/runtimeConfig.d.mts.map +1 -1
- package/build/runtimeConfig.js +1 -2
- package/build/serde/TypeInfo.cjs +1 -2
- package/build/serde/TypeInfo.d.cts +0 -2
- package/build/serde/TypeInfo.d.cts.map +1 -1
- package/build/serde/TypeInfo.d.mts +0 -2
- package/build/serde/TypeInfo.d.mts.map +1 -1
- package/build/serde/TypeInfo.js +1 -2
- package/build/serde/columns.cjs +1 -2
- package/build/serde/columns.d.cts +2 -4
- package/build/serde/columns.d.cts.map +1 -1
- package/build/serde/columns.d.mts +2 -4
- package/build/serde/columns.d.mts.map +1 -1
- package/build/serde/columns.js +1 -2
- package/build/serde/fieldSerde.cjs +4 -5
- package/build/serde/fieldSerde.d.cts +4 -6
- package/build/serde/fieldSerde.d.cts.map +1 -1
- package/build/serde/fieldSerde.d.mts +4 -6
- package/build/serde/fieldSerde.d.mts.map +1 -1
- package/build/serde/fieldSerde.js +4 -5
- package/build/serde/serde.cjs +4 -5
- package/build/serde/serde.cjs.map +1 -1
- package/build/serde/serde.d.cts +0 -2
- package/build/serde/serde.d.cts.map +1 -1
- package/build/serde/serde.d.mts +0 -2
- package/build/serde/serde.d.mts.map +1 -1
- package/build/serde/serde.js +4 -5
- package/build/serde/temporal.cjs +1 -2
- package/build/serde/temporal.cjs.map +1 -1
- package/build/serde/temporal.d.cts +0 -2
- package/build/serde/temporal.d.cts.map +1 -1
- package/build/serde/temporal.d.mts +0 -2
- package/build/serde/temporal.d.mts.map +1 -1
- package/build/serde/temporal.js +1 -2
- package/build/serde/temporalMappers.cjs +1 -2
- package/build/serde/temporalMappers.d.cts +1 -3
- package/build/serde/temporalMappers.d.cts.map +1 -1
- package/build/serde/temporalMappers.d.mts +1 -3
- package/build/serde/temporalMappers.d.mts.map +1 -1
- package/build/serde/temporalMappers.js +1 -2
- package/build/transitions.cjs +2 -3
- package/build/transitions.d.cts +3 -5
- package/build/transitions.d.cts.map +1 -1
- package/build/transitions.d.mts +3 -5
- package/build/transitions.d.mts.map +1 -1
- package/build/transitions.js +2 -3
- package/build/trusted.cjs +1 -2
- package/build/trusted.cjs.map +1 -1
- package/build/trusted.d.cts +0 -2
- package/build/trusted.d.cts.map +1 -1
- package/build/trusted.d.mts +0 -2
- package/build/trusted.d.mts.map +1 -1
- package/build/trusted.js +1 -2
- package/build/typeMap.cjs +1 -1
- package/build/typeMap.d.cts +1 -3
- package/build/typeMap.d.cts.map +1 -1
- package/build/typeMap.d.mts +1 -3
- package/build/typeMap.d.mts.map +1 -1
- package/build/typeMap.js +1 -1
- package/build/upsert.cjs +7 -8
- package/build/upsert.d.cts +3 -5
- package/build/upsert.d.cts.map +1 -1
- package/build/upsert.d.mts +3 -5
- package/build/upsert.d.mts.map +1 -1
- package/build/upsert.js +7 -8
- package/build/utils.cjs +3 -4
- package/build/utils.d.cts +2 -4
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +2 -4
- package/build/utils.d.mts.map +1 -1
- package/build/utils.js +3 -4
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneToOneReference.js","names":[],"sources":["../../src/relations/OneToOneReference.ts"],"sourcesContent":["import { oneToOneBatchLoader } from \"src/batchloaders/oneToOneBatchLoader.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityMetadata } from \"src/EntityMetadata.ts\";\nimport { setField } from \"src/fields.ts\";\nimport {\n type IdOf,\n type LoadedReference,\n type OneToOneField,\n type TaggedId,\n appendStack,\n deTagId,\n ensureNotDeleted,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { type ManyToOneReference, failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { isReactiveReference } from \"src/relations/ReactiveReference.ts\";\nimport { type Reference } from \"src/relations/Reference.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nconst OneToOne = Symbol();\n\n/** An alias for creating `OneToOneReference`s. */\nexport function hasOneToOne<T extends Entity, U extends Entity>(): OneToOneReference<T, U> {\n return lazyField((entity: T, fieldName) => {\n const o2o = getMetadata(entity).allFields[fieldName] as OneToOneField;\n return new OneToOneReferenceImpl<T, U>(entity, o2o);\n });\n}\n\n/** The lazy-loaded/lookup side of a one-to-one, i.e. the side w/o the unique foreign key column. */\nexport interface OneToOneReference<T extends Entity, U extends Entity> extends Reference<T, U, undefined> {\n // Need to differentiate OneToOneReference from Reference\n [OneToOne]: T;\n}\n\n/** Adds a known-safe `get` accessor. */\nexport interface LoadedOneToOneReference<T extends Entity, U extends Entity> extends LoadedReference<T, U, undefined> {\n get: U | undefined;\n\n getWithDeleted: U | undefined;\n\n // Once OneToOneReference is loaded, it can get a lot of the ManyToOneReference methods that\n // are available even in an unloaded state; below is mostly a copy/paste of those.\n\n /** Returns the id of the current assigned entity or a runtime error if it's either a) unset or b) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n idIfSet: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedMaybe: string | undefined;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/** Type guard utility for determining if an entity field is a Reference. */\nexport function isOneToOneReference(maybeReference: any): maybeReference is OneToOneReference<any, any> {\n return maybeReference instanceof OneToOneReferenceImpl;\n}\n\n/** Type guard utility for determining if an entity field is a loaded Reference. */\nexport function isLoadedOneToOneReference(\n maybeReference: any,\n): maybeReference is Reference<any, any, any> & LoadedOneToOneReference<any, any> {\n return isOneToOneReference(maybeReference) && maybeReference.isLoaded;\n}\n\n/**\n * Represents the \"many\" side of a one-to-one relationship.\n *\n * I.e. in a one-to-many from Book -> Reviews, there is a review.book_id that can have many books.\n *\n * This class is for when that `review.book_id` column is itself unique, i.e. like `image.book_id`, and\n * so instead of `Book.images: OneToManyCollection` we have a `Book.image: OneToOneReference`.\n *\n * This class implements `Reference` because it is essentially like \"one entity pointing/refereing to another\",\n * however because we require a `.load` call to lazily know the value of other side (unlike ManyToOneReference\n * which has it's `book_id` column immediately available in the entity `data` hash), there is some wonkiness\n * around methods like `Reference.id` that are usually callable without `load`/`populate`, that for this\n * class can actually only be called post `load`/`populate`.\n *\n * Currently we enforce this with a runtime check, which is not great, but the trade-off of implementing\n * `Reference` seemed worth the downside of a un-type-safe `.id` property.\n */\nexport class OneToOneReferenceImpl<T extends Entity, U extends Entity>\n extends AbstractRelationImpl<T, U>\n implements OneToOneReference<T, U>\n{\n #field: OneToOneField;\n private loaded: U | undefined;\n private _isLoaded: boolean = false;\n #hasBeenSet = false;\n\n constructor(entity: T, field: OneToOneField) {\n super(entity);\n this.#field = field;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n // These are public to our internal implementation but not exposed in the Collection API\n get fieldName(): keyof T & string {\n return this.#field.fieldName as keyof T & string;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idIfSet(): IdOf<U> | undefined {\n if (this._isLoaded) {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n\n private get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idMaybe as IdOf<U> | undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idTaggedMaybe(): TaggedId | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idTaggedMaybe;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n get isSet(): boolean {\n if (this._isLoaded) {\n return this.loaded !== undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n // opts is an internal parameter\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | undefined> {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded || opts.forceReload) {\n if (!this.entity.isNewEntity) {\n const joinLoaded = this.getPreloaded();\n if (joinLoaded) {\n this.loaded = joinLoaded[0];\n } else {\n try {\n await oneToOneBatchLoader(this.entity.em, this).load(this.entity.idTagged);\n } catch (err) {\n throw appendStack(err as Error, new Error());\n }\n this.preload();\n }\n }\n this._isLoaded = true;\n }\n return this.filterDeleted(this.loaded, opts);\n }\n\n set(other: U, opts: { percolating?: boolean } = {}): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n if (other === this.loaded) {\n this._isLoaded = true;\n return;\n }\n if (this._isLoaded) {\n if (this.loaded && !opts.percolating) {\n this.getOtherRelation(this.loaded).set(undefined);\n }\n }\n const { fieldLogger } = getEmInternalApi(this.entity.em);\n fieldLogger.logSet(this.entity, this.fieldName, other);\n this.loaded = other;\n this._isLoaded = true;\n // This will no-op and mark other dirty if necessary\n if (other && !opts.percolating) {\n this.getOtherRelation(other).set(this.entity);\n }\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.getPreloaded();\n }\n\n preload(): void {\n this.loaded = this.getPreloaded()?.[0];\n this._isLoaded = true;\n }\n\n import(other: OneToOneReferenceImpl<T, U>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n get getWithDeleted(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: true });\n }\n\n get get(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: false });\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n private doGet(): U | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded) {\n // This should only be callable in the type system if we've already resolved this to an instance\n throw new Error(\"get was called when not loaded\");\n }\n return this.loaded;\n }\n\n // internal impl\n\n setFromOpts(other: U): void {\n this.set(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete && this.loaded) {\n this.entity.em.delete(this.loaded);\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const otherSide = this.getOtherRelation(current);\n // Don't call `ReactiveReference.set` because it'll blow up\n if (!isReactiveReference(otherSide)) {\n otherSide.set(undefined as any);\n }\n setField(current, this.otherFieldName, undefined);\n }\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `OneToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;\n }\n\n private filterDeleted(entity: U | undefined, opts?: { withDeleted?: boolean }): U | undefined {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : undefined;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */\n private getOtherRelation(other: U): ManyToOneReference<U, T, any> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private getPreloaded(): U[] | undefined {\n if (this.entity.isNewEntity) return undefined;\n return getEmInternalApi(this.entity.em).getPreloadedRelation(this.entity.idTagged, this.fieldName);\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n [RelationT] = null!;\n [RelationU] = null!;\n [ReferenceN] = null!;\n [OneToOne] = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAM,WAAW,OAAO;;AAGxB,SAAgB,cAA2E;CACzF,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,sBAA4B,QAAQ,GAAG;CACpD,CAAC;AACH;;AA+BA,SAAgB,oBAAoB,gBAAoE;CACtG,OAAO,0BAA0B;AACnC;;AAGA,SAAgB,0BACd,gBACgF;CAChF,OAAO,oBAAoB,cAAc,KAAK,eAAe;AAC/D;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAb,cACU,qBAEV;CACE;CACA;CACA,YAA6B;CAC7B,cAAc;CAEd,YAAY,QAAW,OAAsB;EAC3C,MAAM,MAAM;EACZ,KAAK,SAAS;EACd,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAGA,IAAI,YAA8B;EAChC,OAAO,KAAK,OAAO;CACrB;CAEA,IAAI,iBAAmC;EACrC,OAAO,KAAK,OAAO;CACrB;CAEA,IAAI,KAAc;EAChB,OAAO,KAAK,WAAW,SAAS,KAAK,QAAQ,KA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ACf,CAAC,YAAY;AACf"}
|
|
1
|
+
{"version":3,"file":"OneToOneReference.js","names":[],"sources":["../../src/relations/OneToOneReference.ts"],"sourcesContent":["import { oneToOneBatchLoader } from \"src/batchloaders/oneToOneBatchLoader.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { hasVisibilityHook } from \"src/EntityManager.ts\";\nimport { type EntityMetadata } from \"src/EntityMetadata.ts\";\nimport { setField } from \"src/fields.ts\";\nimport {\n type IdOf,\n type LoadedReference,\n type OneToOneField,\n type TaggedId,\n appendStack,\n deTagId,\n ensureNotDeleted,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { type ManyToOneReference, failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { isReactiveReference } from \"src/relations/ReactiveReference.ts\";\nimport { type Reference } from \"src/relations/Reference.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { checkVisibleReference } from \"src/relations/relationVisibility.ts\";\n\nconst OneToOne = Symbol();\n\n/** An alias for creating `OneToOneReference`s. */\nexport function hasOneToOne<T extends Entity, U extends Entity>(): OneToOneReference<T, U> {\n return lazyField((entity: T, fieldName) => {\n const o2o = getMetadata(entity).allFields[fieldName] as OneToOneField;\n const Relation = hasVisibilityHook(entity) ? PluginOneToOneReference : OneToOneReferenceImpl;\n return new Relation<T, U>(entity, o2o);\n });\n}\n\n/** The lazy-loaded/lookup side of a one-to-one, i.e. the side w/o the unique foreign key column. */\nexport interface OneToOneReference<T extends Entity, U extends Entity> extends Reference<T, U, undefined> {\n // Need to differentiate OneToOneReference from Reference\n [OneToOne]: T;\n}\n\n/** Adds a known-safe `get` accessor. */\nexport interface LoadedOneToOneReference<T extends Entity, U extends Entity> extends LoadedReference<T, U, undefined> {\n get: U | undefined;\n\n getWithDeleted: U | undefined;\n\n // Once OneToOneReference is loaded, it can get a lot of the ManyToOneReference methods that\n // are available even in an unloaded state; below is mostly a copy/paste of those.\n\n /** Returns the id of the current assigned entity or a runtime error if it's either a) unset or b) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n idIfSet: IdOf<U> | undefined;\n\n idUntagged: string;\n\n idUntaggedMaybe: string | undefined;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/** Type guard utility for determining if an entity field is a Reference. */\nexport function isOneToOneReference(maybeReference: any): maybeReference is OneToOneReference<any, any> {\n return maybeReference instanceof OneToOneReferenceImpl;\n}\n\n/** Type guard utility for determining if an entity field is a loaded Reference. */\nexport function isLoadedOneToOneReference(\n maybeReference: any,\n): maybeReference is Reference<any, any, any> & LoadedOneToOneReference<any, any> {\n return isOneToOneReference(maybeReference) && maybeReference.isLoaded;\n}\n\n/**\n * Represents the \"many\" side of a one-to-one relationship.\n *\n * I.e. in a one-to-many from Book -> Reviews, there is a review.book_id that can have many books.\n *\n * This class is for when that `review.book_id` column is itself unique, i.e. like `image.book_id`, and\n * so instead of `Book.images: OneToManyCollection` we have a `Book.image: OneToOneReference`.\n *\n * This class implements `Reference` because it is essentially like \"one entity pointing/refereing to another\",\n * however because we require a `.load` call to lazily know the value of other side (unlike ManyToOneReference\n * which has it's `book_id` column immediately available in the entity `data` hash), there is some wonkiness\n * around methods like `Reference.id` that are usually callable without `load`/`populate`, that for this\n * class can actually only be called post `load`/`populate`.\n *\n * Currently we enforce this with a runtime check, which is not great, but the trade-off of implementing\n * `Reference` seemed worth the downside of a un-type-safe `.id` property.\n */\nexport class OneToOneReferenceImpl<T extends Entity, U extends Entity>\n extends AbstractRelationImpl<T, U>\n implements OneToOneReference<T, U>\n{\n #field: OneToOneField;\n private loaded: U | undefined;\n private _isLoaded: boolean = false;\n #hasBeenSet = false;\n\n constructor(entity: T, field: OneToOneField) {\n super(entity);\n this.#field = field;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n // These are public to our internal implementation but not exposed in the Collection API\n get fieldName(): keyof T & string {\n return this.#field.fieldName as keyof T & string;\n }\n\n get otherFieldName(): keyof U & string {\n return this.#field.otherFieldName as keyof U & string;\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idIfSet(): IdOf<U> | undefined {\n if (this._isLoaded) {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.loaded);\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.loaded);\n }\n\n protected get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idMaybe as IdOf<U> | undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n get idTaggedMaybe(): TaggedId | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (this._isLoaded) {\n return this.loaded?.idTaggedMaybe;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n get isSet(): boolean {\n if (this._isLoaded) {\n return this.loaded !== undefined;\n }\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n\n // opts is an internal parameter\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | undefined> {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded || opts.forceReload) {\n if (!this.entity.isNewEntity) {\n const joinLoaded = this.getPreloaded();\n if (joinLoaded) {\n this.loaded = joinLoaded[0];\n } else {\n try {\n await oneToOneBatchLoader(this.entity.em, this).load(this.entity.idTagged);\n } catch (err) {\n throw appendStack(err as Error, new Error());\n }\n this.preload();\n }\n }\n this._isLoaded = true;\n }\n return this.filterDeleted(this.loaded, opts);\n }\n\n set(other: U, opts: { percolating?: boolean } = {}): void {\n ensureNotDeleted(this.entity, \"pending\");\n this.#hasBeenSet = true;\n if (other === this.loaded) {\n this._isLoaded = true;\n return;\n }\n if (this._isLoaded) {\n if (this.loaded && !opts.percolating) {\n this.getOtherRelation(this.loaded).set(undefined);\n }\n }\n const { fieldLogger } = getEmInternalApi(this.entity.em);\n fieldLogger.logSet(this.entity, this.fieldName, other);\n this.loaded = other;\n this._isLoaded = true;\n // This will no-op and mark other dirty if necessary\n if (other && !opts.percolating) {\n this.getOtherRelation(other).set(this.entity);\n }\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n get isPreloaded(): boolean {\n return !!this.getPreloaded();\n }\n\n preload(): void {\n this.loaded = this.getPreloaded()?.[0];\n this._isLoaded = true;\n }\n\n import(other: OneToOneReferenceImpl<T, U>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n get getWithDeleted(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: true });\n }\n\n get get(): U | undefined {\n return this.filterDeleted(this.doGet(), { withDeleted: false });\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n private doGet(): U | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n if (!this._isLoaded) {\n // This should only be callable in the type system if we've already resolved this to an instance\n throw new Error(\"get was called when not loaded\");\n }\n return this.loaded;\n }\n\n // internal impl\n\n setFromOpts(other: U): void {\n this.set(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete && this.loaded) {\n this.entity.em.delete(this.loaded);\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const otherSide = this.getOtherRelation(current);\n // Don't call `ReactiveReference.set` because it'll blow up\n if (!isReactiveReference(otherSide)) {\n otherSide.set(undefined as any);\n }\n setField(current, this.otherFieldName, undefined);\n }\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n public toString(): string {\n return `OneToOneReference(entity: ${this.entity}, fieldName: ${this.fieldName}, otherType: ${this.otherMeta.type}, otherFieldName: ${this.otherFieldName})`;\n }\n\n private filterDeleted(entity: U | undefined, opts?: { withDeleted?: boolean }): U | undefined {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : undefined;\n }\n\n /** Returns the other relation that points back at us, i.e. we're `Author.image` and this is `Image.author_id`. */\n private getOtherRelation(other: U): ManyToOneReference<U, T, any> {\n return (other as U)[this.otherFieldName] as any;\n }\n\n private getPreloaded(): U[] | undefined {\n if (this.entity.isNewEntity) return undefined;\n return getEmInternalApi(this.entity.em).getPreloadedRelation(this.entity.idTagged, this.fieldName);\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n [RelationT] = null!;\n [RelationU] = null!;\n [ReferenceN] = null!;\n [OneToOne] = null!;\n}\n\n/** Applies policy to public reads of inverse references, including loaded ids. */\nclass PluginOneToOneReference<T extends Entity, U extends Entity> extends OneToOneReferenceImpl<T, U> {\n override get get(): U | undefined {\n return this.check(super.get);\n }\n\n override get getWithDeleted(): U | undefined {\n return this.check(super.getWithDeleted);\n }\n\n override async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | undefined> {\n return this.check(await super.load(opts));\n }\n\n override get isSet(): boolean {\n checkVisibleReference(this.entity, this.fieldName, undefined);\n return super.isSet;\n }\n\n protected override get idMaybe(): IdOf<U> | undefined {\n checkVisibleReference(this.entity, this.fieldName, undefined);\n return super.idMaybe;\n }\n\n override get idTaggedMaybe(): TaggedId | undefined {\n checkVisibleReference(this.entity, this.fieldName, undefined);\n return super.idTaggedMaybe;\n }\n\n /** Checks the target without making required references nullable. */\n private check(value: U | undefined): U | undefined {\n return checkVisibleReference(this.entity, this.fieldName, value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,MAAM,WAAW,OAAO;;AAGxB,SAAgB,cAA2E;CACzF,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAE1C,OAAO,KADU,kBAAkB,MAAM,IAAI,0BAA0B,uBAC7C,QAAQ,GAAG;CACvC,CAAC;AACH;;AA+BA,SAAgB,oBAAoB,gBAAoE;CACtG,OAAO,0BAA0B;AACnC;;AAGA,SAAgB,0BACd,gBACgF;CAChF,OAAO,oBAAoB,cAAc,KAAK,eAAe;AAC/D;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAb,cACU,qBAEV;CACE;CACA;CACA,YAA6B;CAC7B,cAAc;CAEd,YAAY,QAAW,OAAsB;EAC3C,MAAM,MAAM;EACZ,KAAK,SAAS;EACd,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAGA,IAAI,YAA8B;EAChC,OAAO,KAAK,OAAO;CACrB;CAEA,IAAI,iBAAmC;EACrC,OAAO,KAAK,OAAO;CACrB;CAEA,IAAI,KAAc;EAChB,OAAO,KAAK,WAAW,SAAS,KAAK,QAAQ,KAAK,WAAW,KAAK,MAAM;CAC1E;CAEA,IAAI,UAA+B;EACjC,IAAI,KAAK,WACP,OAAO,KAAK,WAAW,gBAAgB,KAAK,QAAQ,KAAK,WAAW,KAAK,MAAM;EAEjF,MAAM,IAAI,MAAM,GAAG,KAAK,OAAO,GAAG,KAAK,UAAU,gBAAgB;CACnE;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAK,mBAAmB,SAAS,KAAK,QAAQ,K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CAC1C;CAEA,IAAa,QAAiB;EAC5B,sBAAsB,KAAK,QAAQ,KAAK,WAAW,KAAA,CAAS;EAC5D,OAAO,MAAM;CACf;CAEA,IAAuB,UAA+B;EACpD,sBAAsB,KAAK,QAAQ,KAAK,WAAW,KAAA,CAAS;EAC5D,OAAO,MAAM;CACf;CAEA,IAAa,gBAAsC;EACjD,sBAAsB,KAAK,QAAQ,KAAK,WAAW,KAAA,CAAS;EAC5D,OAAO,MAAM;CACf;;CAGA,MAAc,OAAqC;EACjD,OAAO,sBAAsB,KAAK,QAAQ,KAAK,WAAW,KAAK;CACjE;AACF"}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_configure = require("../configure.cjs");
|
|
3
|
+
const require_Entity = require("../Entity.cjs");
|
|
4
|
+
const require_EntityManager = require("../EntityManager.cjs");
|
|
5
|
+
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
6
|
+
const require_fields = require("../fields.cjs");
|
|
7
|
+
const require_keys = require("../keys.cjs");
|
|
8
|
+
const require_index = require("../index.cjs");
|
|
2
9
|
const require_newEntity = require("../newEntity.cjs");
|
|
3
10
|
const require_relations_AbstractRelationImpl = require("./AbstractRelationImpl.cjs");
|
|
4
|
-
const
|
|
5
|
-
const require_relations_ReferenceSymbols = require("./ReferenceSymbols.cjs");
|
|
6
|
-
const require_keys = require("../keys.cjs");
|
|
11
|
+
const require_utils = require("../utils.cjs");
|
|
7
12
|
const require_relations_isCascadeDelete = require("./isCascadeDelete.cjs");
|
|
8
|
-
const require_relations_OneToManyCollection = require("./OneToManyCollection.cjs");
|
|
9
13
|
const require_relations_ManyToOneReference = require("./ManyToOneReference.cjs");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const require_index = require("../index.cjs");
|
|
15
|
-
const require_EntityManager = require("../EntityManager.cjs");
|
|
16
|
-
const require_Entity = require("../Entity.cjs");
|
|
14
|
+
const require_relations_OneToManyCollection = require("./OneToManyCollection.cjs");
|
|
15
|
+
const require_relations_ReferenceSymbols = require("./ReferenceSymbols.cjs");
|
|
16
|
+
const require_relations_RelationSymbols = require("./RelationSymbols.cjs");
|
|
17
|
+
const require_relations_relationVisibility = require("./relationVisibility.cjs");
|
|
17
18
|
const require_BaseEntity = require("../BaseEntity.cjs");
|
|
18
|
-
|
|
19
|
+
// src/relations/PolymorphicReference.ts
|
|
19
20
|
function hasOnePolymorphic() {
|
|
20
21
|
return require_newEntity.lazyField((entity, fieldName) => {
|
|
21
|
-
return new PolymorphicReferenceImpl(entity, fieldName);
|
|
22
|
+
return new (require_EntityManager.hasVisibilityHook(entity) ? PluginPolymorphicReference : PolymorphicReferenceImpl)(entity, fieldName);
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
25
|
/** Type guard utility for determining if an entity field is a PolymorphicReference. */
|
|
@@ -58,7 +59,7 @@ var PolymorphicReferenceImpl = class extends require_relations_AbstractRelationI
|
|
|
58
59
|
async load(opts = {}) {
|
|
59
60
|
require_index.ensureNotDeleted(this.entity, "pending");
|
|
60
61
|
const current = this.current();
|
|
61
|
-
if (!this._isLoaded || opts.forceReload) this.loaded = require_Entity.isEntity(current) || current === void 0 ? current : await this.entity.em.load(require_configure.getConstructorFromTaggedId(current), current);
|
|
62
|
+
if (!this._isLoaded || opts.forceReload) this.loaded = require_Entity.isEntity(current) || current === void 0 ? current : await require_EntityManager.getEmInternalApi(this.entity.em).load(require_configure.getConstructorFromTaggedId(current), current);
|
|
62
63
|
this._isLoaded = true;
|
|
63
64
|
return this.filterDeleted(this.loaded, opts);
|
|
64
65
|
}
|
|
@@ -77,7 +78,7 @@ var PolymorphicReferenceImpl = class extends require_relations_AbstractRelationI
|
|
|
77
78
|
*/
|
|
78
79
|
maybeFindEntity() {
|
|
79
80
|
const { idTaggedMaybe } = this;
|
|
80
|
-
return this.loaded ?? (idTaggedMaybe !== void 0 ? this.entity.em.getEntity(idTaggedMaybe) : void 0);
|
|
81
|
+
return this.loaded ?? (idTaggedMaybe !== void 0 ? require_EntityManager.getEmInternalApi(this.entity.em).getEntity(idTaggedMaybe) : void 0);
|
|
81
82
|
}
|
|
82
83
|
get isPreloaded() {
|
|
83
84
|
return !!this.maybeFindEntity();
|
|
@@ -196,13 +197,28 @@ var PolymorphicReferenceImpl = class extends require_relations_AbstractRelationI
|
|
|
196
197
|
return other[this.field.components.find((c) => other instanceof c.otherMetadata().cstr)?.otherFieldName];
|
|
197
198
|
}
|
|
198
199
|
maybeFindExisting() {
|
|
199
|
-
return this.idTaggedMaybe !== void 0 ? this.entity.em.getEntity(this.idTagged) : void 0;
|
|
200
|
+
return this.idTaggedMaybe !== void 0 ? require_EntityManager.getEmInternalApi(this.entity.em).getEntity(this.idTagged) : void 0;
|
|
200
201
|
}
|
|
201
202
|
[require_relations_RelationSymbols.RelationT] = null;
|
|
202
203
|
[require_relations_RelationSymbols.RelationU] = null;
|
|
203
204
|
[require_relations_ReferenceSymbols.ReferenceN] = null;
|
|
204
205
|
};
|
|
205
|
-
|
|
206
|
+
/** Checks polymorphic targets at public entity-returning boundaries. */
|
|
207
|
+
var PluginPolymorphicReference = class extends PolymorphicReferenceImpl {
|
|
208
|
+
get get() {
|
|
209
|
+
return this.check(super.get);
|
|
210
|
+
}
|
|
211
|
+
get getWithDeleted() {
|
|
212
|
+
return this.check(super.getWithDeleted);
|
|
213
|
+
}
|
|
214
|
+
async load(opts = {}) {
|
|
215
|
+
return this.check(await super.load(opts));
|
|
216
|
+
}
|
|
217
|
+
/** Checks visibility when returning the target entity. */
|
|
218
|
+
check(value) {
|
|
219
|
+
return require_relations_relationVisibility.checkVisibleReference(this.entity, this.fieldName, value);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
206
222
|
exports.PolymorphicReferenceImpl = PolymorphicReferenceImpl;
|
|
207
223
|
exports.hasOnePolymorphic = hasOnePolymorphic;
|
|
208
224
|
exports.isPolymorphicReference = isPolymorphicReference;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolymorphicReference.cjs","names":["lazyField","AbstractRelationImpl","getMetadata","getInstanceData","maybeGetConstructorFromReference","isCascadeDelete","isEntity","getConstructorFromTaggedId","failNoId","maybeResolveReferenceToId","failIfNewEntity","OneToManyCollection","sameEntity","getField","RelationT","RelationU","ReferenceN"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n return new PolymorphicReferenceImpl<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, N> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idTagged: string;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await this.entity.em.load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, opts);\n }\n\n set(other: U | N): void {\n this.setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return this.loaded ?? (idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): void {\n this.setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? (this.entity.em.getEntity(this.idTagged) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,SAAgB,oBAImB;CACjC,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,CAAC;AACH;;AAGA,SAAgB,uBAAuB,gBAA4E;CACjH,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAwCA,IAAa,2BAAb,cACUC,uCAAAA,qBAEV;CASW;CART;CAEA,YAAoB;CACpB;CACA,cAAc;CAEd,YACE,QACA,WACA;EACA,MAAM,MAAM;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAIC,mBAAAA,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAOC,kBAAAA,iCAAiC,KAAK,QAAQ,CAAC;EAC5D,OAAO,KAAK,MAAM,WAAW,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC,SAAS,IAAI;CAC1E;CAEA,IAAY,kBAA2B;EACrC,OAAOC,kCAAAA,gBAAgB,MAAM,KAAK,SAAS;CAC7C;CAEA,MAAM,KAAK,OAAyD,CAAC,GAAmB;EACtF,cAAA,iBAAiB,KAAK,QAAQ,SAAS;EACvC,MAAM,UAAU,KAAK,QAAQ;EAE7B,IAAI,CAAC,KAAK,aAAa,KAAK,aAC1B,KAAK,SACHC,eAAAA,SAAS,OAAO,KAAK,YAAY,KAAA,IAC5B,UACC,MAAM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QAE3B,YAAY,IAAI,KAAK,MAAM;EAE/B;CACF;CAGA,QAAQ,MAAoD;EAC1D,MAAM,UAAUE,eAAAA,SAAS,KAAK,QAAQ,KAAK,SAAS;EACpD,IAAI,YAAY,KAAA,KAAaP,eAAAA,SAAS,OAAO,GAC3C,OAAO,KAAK,cAAc,SAAc,IAAI;EAE9C,OAAO;CACT;CAEA,WAA0B;EACxB,OAAO,gCAAgC,KAAK,OAAO,eACjD,KAAK,UACN,eAAe,KAAK,kBAAkB,cAAc,CAAC,CAAC,KAAK,oBAC1D,KAAK,kBAAkB,eACxB,QAAQ,KAAK,GAAG;CACnB;CAEA,cAAsB,QAAe,MAAyC;EAC5E,OAAO,MAAM,gBAAgB,QAAQ,WAAW,KAAA,KAAa,CAAC,OAAO,kBAAkB,SAAU,KAAA;CACnG;;CAGA,iBAAyB,OAA+D;EAEtF,OAAQ,MADU,KAAK,MAAM,WAAW,MAAM,MAAM,iBAAiB,EAAE,cAAc,CAAC,CAAC,IAC3D,CAAC,EAAE;CACjC;CAEA,oBAA2C;EACzC,OAAO,KAAK,kBAAkB,KAAA,IAAa,KAAK,OAAO,GAAG,UAAU,KAAK,QAAQ,IAAU,KAAA;CAC7F;CAEA,CAACQ,kCAAAA,aAAgB;CACjB,CAACC,kCAAAA,aAAgB;CACjB,CAACC,mCAAAA,cAAiB;AACpB"}
|
|
1
|
+
{"version":3,"file":"PolymorphicReference.cjs","names":["lazyField","hasVisibilityHook","AbstractRelationImpl","getMetadata","getInstanceData","maybeGetConstructorFromReference","isCascadeDelete","isEntity","getEmInternalApi","getConstructorFromTaggedId","failNoId","maybeResolveReferenceToId","failIfNewEntity","OneToManyCollection","sameEntity","getField","RelationT","RelationU","ReferenceN","checkVisibleReference"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, getEmInternalApi, hasVisibilityHook, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { checkVisibleReference } from \"src/relations/relationVisibility.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const Relation = hasVisibilityHook(entity) ? PluginPolymorphicReference : PolymorphicReferenceImpl;\n return new Relation<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, N> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idTagged: string;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await getEmInternalApi(this.entity.em).load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, opts);\n }\n\n set(other: U | N): void {\n this.setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return (\n this.loaded ??\n (idTaggedMaybe !== undefined ? getEmInternalApi(this.entity.em).getEntity<U>(idTaggedMaybe) : undefined)\n );\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): void {\n this.setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? getEmInternalApi(this.entity.em).getEntity<U>(this.idTagged) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/** Checks polymorphic targets at public entity-returning boundaries. */\nclass PluginPolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends PolymorphicReferenceImpl<T, U, N> {\n override get get(): U | N {\n return this.check(super.get);\n }\n\n override get getWithDeleted(): U | N {\n return this.check(super.getWithDeleted);\n }\n\n override async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n return this.check(await super.load(opts));\n }\n\n /** Checks visibility when returning the target entity. */\n private check<V extends Entity | undefined>(value: V): V {\n return checkVisibleReference(this.entity, this.fieldName, value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,oBAImB;CACjC,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EAEzC,OAAO,KADUC,sBAAAA,kBAAkB,MAAM,IAAI,6BAA6B,0BAC7C,QAAQ,SAA6B;CACpE,CAAC;AACH;;AAGA,SAAgB,uBAAuB,gBAA4E;CACjH,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAwCA,IAAa,2BAAb,cACUC,uCAAAA,qBAEV;CASW;CART;CAEA,YAAoB;CACpB;CACA,cAAc;CAEd,YACE,QACA,WACA;EACA,MAAM,MAAM;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAIC,mBAAAA,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAOC,kBAAAA,iCAAiC,KAAK,QAAQ,CAAC;EAC5D,OAAO,KAAK,MAAM,WAAW,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC,SAAS,IAAI;CAC1E;CAEA,IAAY,kBAA2B;EACrC,OAAOC,kCAAAA,gBAAgB,MAAM,KAAK,SAAS;CAC7C;CAEA,MAAM,KAAK,OAAyD,CAAC,GAAmB;EACtF,cAAA,iBAA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,MAAM,cAAc;CACxC;CAEA,MAAe,KAAK,OAAyD,CAAC,GAAmB;EAC/F,OAAO,KAAK,MAAM,MAAM,MAAM,KAAK,IAAI,CAAC;CAC1C;;CAGA,MAA4C,OAAa;EACvD,OAAOC,qCAAAA,sBAAsB,KAAK,QAAQ,KAAK,WAAW,KAAK;CACjE;AACF"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { Entity } from "../Entity.cjs";
|
|
2
|
+
import { IdOf, TaggedId } from "../EntityManager.cjs";
|
|
3
|
+
import "../index.cjs";
|
|
4
|
+
import { Reference } from "./Reference.cjs";
|
|
1
5
|
import { AbstractRelationImpl } from "./AbstractRelationImpl.cjs";
|
|
2
|
-
import { RelationT, RelationU } from "./RelationSymbols.cjs";
|
|
3
6
|
import { ReferenceN } from "./ReferenceSymbols.cjs";
|
|
4
|
-
import {
|
|
5
|
-
import "../index.cjs";
|
|
6
|
-
import { IdOf, TaggedId } from "../EntityManager.cjs";
|
|
7
|
-
import { Entity } from "../Entity.cjs";
|
|
8
|
-
//#region src/relations/PolymorphicReference.d.ts
|
|
7
|
+
import { RelationT, RelationU } from "./RelationSymbols.cjs";
|
|
9
8
|
export declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(): PolymorphicReference<T, U, N>;
|
|
10
9
|
/** Type guard utility for determining if an entity field is a PolymorphicReference. */
|
|
11
10
|
export declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
|
|
@@ -88,5 +87,4 @@ export declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity
|
|
|
88
87
|
[RelationU]: U;
|
|
89
88
|
[ReferenceN]: N;
|
|
90
89
|
}
|
|
91
|
-
//#endregion
|
|
92
90
|
//# sourceMappingURL=PolymorphicReference.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolymorphicReference.d.cts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PolymorphicReference.d.cts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":";;;;;;;wBAwBgB,kBACd,UAAU,QACV,UAAU,QACV,gCACG,qBAAqB,GAAG,GAAG;;wBAQhB,uBAAuB,sBAAsB,kBAAkB;;;;;;;;iBAW9D,qBACf,UAAU,QACV,UAAU,QACV,qCACQ,UAAU,GAAG,GAAG;;EAExB,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;;WAGS;;;;;;;;;;;;;qBAcE,yBAAyB,UAAU,QAAQ,UAAU,QAAQ,qCAChE,qBAAqB,GAAG,cACrB,qBAAqB,GAAG,GAAG;;EAU7B,iBAAiB;UARlB;UAEA;UACA;EAGR,YACE,QAAQ,GACD,iBAAiB;cASd;cAKA;EAIN,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAcrF,IAAI,OAAO,IAAI;MAIX;MAIA;;;;;EAQJ,mBAAmB;MASf;EAIJ;UAKQ;EAKR,OAAO,OAAO,yBAAyB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAK/D;MAgBJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;MAIX,MAAM,KAAK;MAIX,WAAW,KAAK;MAKhB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAKA;EAMJ,YAAY,OAAO;EAInB;EASM,0BAA0B;EAkBhC,QAAQ,OAAO,IAAI;EAsEnB,QAAQ;IAAS;MAA0B,IAAI,WAAW;EAQnD;UAQC;;UAKA;UAKA;GAIP,YAAY;GACZ,YAAY;GACZ,aAAa"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { Entity } from "../Entity.mjs";
|
|
2
|
+
import { IdOf, TaggedId } from "../EntityManager.mjs";
|
|
3
|
+
import "../index.mjs";
|
|
4
|
+
import { Reference } from "./Reference.mjs";
|
|
1
5
|
import { AbstractRelationImpl } from "./AbstractRelationImpl.mjs";
|
|
2
|
-
import { RelationT, RelationU } from "./RelationSymbols.mjs";
|
|
3
6
|
import { ReferenceN } from "./ReferenceSymbols.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import "../index.mjs";
|
|
6
|
-
import { IdOf, TaggedId } from "../EntityManager.mjs";
|
|
7
|
-
import { Entity } from "../Entity.mjs";
|
|
8
|
-
//#region src/relations/PolymorphicReference.d.ts
|
|
7
|
+
import { RelationT, RelationU } from "./RelationSymbols.mjs";
|
|
9
8
|
export declare function hasOnePolymorphic<T extends Entity, U extends Entity, N extends never | undefined>(): PolymorphicReference<T, U, N>;
|
|
10
9
|
/** Type guard utility for determining if an entity field is a PolymorphicReference. */
|
|
11
10
|
export declare function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any>;
|
|
@@ -88,5 +87,4 @@ export declare class PolymorphicReferenceImpl<T extends Entity, U extends Entity
|
|
|
88
87
|
[RelationU]: U;
|
|
89
88
|
[ReferenceN]: N;
|
|
90
89
|
}
|
|
91
|
-
//#endregion
|
|
92
90
|
//# sourceMappingURL=PolymorphicReference.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolymorphicReference.d.mts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PolymorphicReference.d.mts","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"mappings":";;;;;;;wBAwBgB,kBACd,UAAU,QACV,UAAU,QACV,gCACG,qBAAqB,GAAG,GAAG;;wBAQhB,uBAAuB,sBAAsB,kBAAkB;;;;;;;;iBAW9D,qBACf,UAAU,QACV,UAAU,QACV,qCACQ,UAAU,GAAG,GAAG;;EAExB,IAAI,KAAK;;EAGT,SAAS,KAAK;;EAGd,SAAS,KAAK;EAEd;;WAGS;;;;;;;;;;;;;qBAcE,yBAAyB,UAAU,QAAQ,UAAU,QAAQ,qCAChE,qBAAqB,GAAG,cACrB,qBAAqB,GAAG,GAAG;;EAU7B,iBAAiB;UARlB;UAEA;UACA;EAGR,YACE,QAAQ,GACD,iBAAiB;cASd;cAKA;EAIN,KAAK;IAAQ;IAAuB;MAA+B,QAAQ,IAAI;EAcrF,IAAI,OAAO,IAAI;MAIX;MAIA;;;;;EAQJ,mBAAmB;MASf;EAIJ;UAKQ;EAKR,OAAO,OAAO,yBAAyB,GAAG,GAAG,IAAI,aAAa,GAAG,MAAM;UAK/D;MAgBJ,kBAAkB,IAAI;MAItB,OAAO,IAAI;MAIX,MAAM,KAAK;MAIX,WAAW,KAAK;MAKhB,WAAW,KAAK,KAAK;MAIrB;MAIA;MAKA;EAMJ,YAAY,OAAO;EAInB;EASM,0BAA0B;EAkBhC,QAAQ,OAAO,IAAI;EAsEnB,QAAQ;IAAS;MAA0B,IAAI,WAAW;EAQnD;UAQC;;UAKA;UAKA;GAIP,YAAY;GACZ,YAAY;GACZ,aAAa"}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
+
import { getConstructorFromTaggedId, maybeGetConstructorFromReference } from "../configure.js";
|
|
2
|
+
import { isEntity } from "../Entity.js";
|
|
3
|
+
import { getEmInternalApi, hasVisibilityHook, sameEntity } from "../EntityManager.js";
|
|
4
|
+
import { getMetadata } from "../EntityMetadata.js";
|
|
5
|
+
import { getField, setField } from "../fields.js";
|
|
6
|
+
import { maybeResolveReferenceToId } from "../keys.js";
|
|
7
|
+
import { ensureNotDeleted } from "../index.js";
|
|
1
8
|
import { lazyField } from "../newEntity.js";
|
|
2
9
|
import { AbstractRelationImpl } from "./AbstractRelationImpl.js";
|
|
3
|
-
import {
|
|
4
|
-
import { ReferenceN } from "./ReferenceSymbols.js";
|
|
5
|
-
import { maybeResolveReferenceToId } from "../keys.js";
|
|
10
|
+
import { fail } from "../utils.js";
|
|
6
11
|
import { isCascadeDelete } from "./isCascadeDelete.js";
|
|
7
|
-
import { OneToManyCollection } from "./OneToManyCollection.js";
|
|
8
12
|
import { failIfNewEntity, failNoId } from "./ManyToOneReference.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { ensureNotDeleted } from "../index.js";
|
|
14
|
-
import { sameEntity } from "../EntityManager.js";
|
|
15
|
-
import { isEntity } from "../Entity.js";
|
|
13
|
+
import { OneToManyCollection } from "./OneToManyCollection.js";
|
|
14
|
+
import { ReferenceN } from "./ReferenceSymbols.js";
|
|
15
|
+
import { RelationT, RelationU } from "./RelationSymbols.js";
|
|
16
|
+
import { checkVisibleReference } from "./relationVisibility.js";
|
|
16
17
|
import { getInstanceData } from "../BaseEntity.js";
|
|
17
|
-
|
|
18
|
+
// src/relations/PolymorphicReference.ts
|
|
18
19
|
function hasOnePolymorphic() {
|
|
19
20
|
return lazyField((entity, fieldName) => {
|
|
20
|
-
return new PolymorphicReferenceImpl(entity, fieldName);
|
|
21
|
+
return new (hasVisibilityHook(entity) ? PluginPolymorphicReference : PolymorphicReferenceImpl)(entity, fieldName);
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
/** Type guard utility for determining if an entity field is a PolymorphicReference. */
|
|
@@ -57,7 +58,7 @@ var PolymorphicReferenceImpl = class extends AbstractRelationImpl {
|
|
|
57
58
|
async load(opts = {}) {
|
|
58
59
|
ensureNotDeleted(this.entity, "pending");
|
|
59
60
|
const current = this.current();
|
|
60
|
-
if (!this._isLoaded || opts.forceReload) this.loaded = isEntity(current) || current === void 0 ? current : await this.entity.em.load(getConstructorFromTaggedId(current), current);
|
|
61
|
+
if (!this._isLoaded || opts.forceReload) this.loaded = isEntity(current) || current === void 0 ? current : await getEmInternalApi(this.entity.em).load(getConstructorFromTaggedId(current), current);
|
|
61
62
|
this._isLoaded = true;
|
|
62
63
|
return this.filterDeleted(this.loaded, opts);
|
|
63
64
|
}
|
|
@@ -76,7 +77,7 @@ var PolymorphicReferenceImpl = class extends AbstractRelationImpl {
|
|
|
76
77
|
*/
|
|
77
78
|
maybeFindEntity() {
|
|
78
79
|
const { idTaggedMaybe } = this;
|
|
79
|
-
return this.loaded ?? (idTaggedMaybe !== void 0 ? this.entity.em.getEntity(idTaggedMaybe) : void 0);
|
|
80
|
+
return this.loaded ?? (idTaggedMaybe !== void 0 ? getEmInternalApi(this.entity.em).getEntity(idTaggedMaybe) : void 0);
|
|
80
81
|
}
|
|
81
82
|
get isPreloaded() {
|
|
82
83
|
return !!this.maybeFindEntity();
|
|
@@ -195,13 +196,28 @@ var PolymorphicReferenceImpl = class extends AbstractRelationImpl {
|
|
|
195
196
|
return other[this.field.components.find((c) => other instanceof c.otherMetadata().cstr)?.otherFieldName];
|
|
196
197
|
}
|
|
197
198
|
maybeFindExisting() {
|
|
198
|
-
return this.idTaggedMaybe !== void 0 ? this.entity.em.getEntity(this.idTagged) : void 0;
|
|
199
|
+
return this.idTaggedMaybe !== void 0 ? getEmInternalApi(this.entity.em).getEntity(this.idTagged) : void 0;
|
|
199
200
|
}
|
|
200
201
|
[RelationT] = null;
|
|
201
202
|
[RelationU] = null;
|
|
202
203
|
[ReferenceN] = null;
|
|
203
204
|
};
|
|
204
|
-
|
|
205
|
+
/** Checks polymorphic targets at public entity-returning boundaries. */
|
|
206
|
+
var PluginPolymorphicReference = class extends PolymorphicReferenceImpl {
|
|
207
|
+
get get() {
|
|
208
|
+
return this.check(super.get);
|
|
209
|
+
}
|
|
210
|
+
get getWithDeleted() {
|
|
211
|
+
return this.check(super.getWithDeleted);
|
|
212
|
+
}
|
|
213
|
+
async load(opts = {}) {
|
|
214
|
+
return this.check(await super.load(opts));
|
|
215
|
+
}
|
|
216
|
+
/** Checks visibility when returning the target entity. */
|
|
217
|
+
check(value) {
|
|
218
|
+
return checkVisibleReference(this.entity, this.fieldName, value);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
205
221
|
export { PolymorphicReferenceImpl, hasOnePolymorphic, isPolymorphicReference };
|
|
206
222
|
|
|
207
223
|
//# sourceMappingURL=PolymorphicReference.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolymorphicReference.js","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n return new PolymorphicReferenceImpl<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, N> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idTagged: string;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await this.entity.em.load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, opts);\n }\n\n set(other: U | N): void {\n this.setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return this.loaded ?? (idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U) : undefined);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): void {\n this.setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? (this.entity.em.getEntity(this.idTagged) as U) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [Referen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;EAEtF,OAAQ,MADU,KAAK,MAAM,WAAW,MAAM,MAAM,iBAAiB,EAAE,cAAc,CAAC,CAAC,IAC3D,CAAC,EAAE;CACjC;CAEA,oBAA2C;EACzC,OAAO,KAAK,kBAAkB,KAAA,IAAa,KAAK,OAAO,GAAG,UAAU,KAAK,QAAQ,IAAU,KAAA;CAC7F;CAEA,CAAC,aAAgB;CACjB,CAAC,aAAgB;CACjB,CAAC,cAAiB;AACpB"}
|
|
1
|
+
{"version":3,"file":"PolymorphicReference.js","names":[],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"src/configure.ts\";\nimport { type Entity, isEntity } from \"src/Entity.ts\";\nimport { type IdOf, type TaggedId, getEmInternalApi, hasVisibilityHook, sameEntity } from \"src/EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"src/EntityMetadata.ts\";\nimport { getField, setField } from \"src/fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\n} from \"src/index.ts\";\nimport { lazyField } from \"src/newEntity.ts\";\nimport { AbstractRelationImpl } from \"src/relations/AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"src/relations/isCascadeDelete.ts\";\nimport { failIfNewEntity, failNoId } from \"src/relations/ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"src/relations/OneToManyCollection.ts\";\nimport { ReferenceN } from \"src/relations/ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"src/relations/RelationSymbols.ts\";\nimport { checkVisibleReference } from \"src/relations/relationVisibility.ts\";\n\nexport function hasOnePolymorphic<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n>(): PolymorphicReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const Relation = hasVisibilityHook(entity) ? PluginPolymorphicReference : PolymorphicReferenceImpl;\n return new Relation<T, U, N>(entity, fieldName as keyof T & string);\n });\n}\n\n/** Type guard utility for determining if an entity field is a PolymorphicReference. */\nexport function isPolymorphicReference(maybeReference: any): maybeReference is PolymorphicReference<any, any, any> {\n return maybeReference instanceof PolymorphicReferenceImpl;\n}\n\n/**\n * A reference that can be assigned to multiple different entity types.\n *\n * I.e. a `Comment.parent` reference that can be an `Author` or `Book`.\n *\n * The `U` generic will be the type union of `Author | Book`.\n */\nexport interface PolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends Reference<T, U, N> {\n /** Returns the id of the current assigned entity, or a runtime error if either 1) unset or 2) set to a new entity that doesn't have an `id` yet. */\n id: IdOf<U>;\n\n /** Returns the id of the current assigned entity, undefined if unset, or a runtime error if set to a new entity. */\n idIfSet: IdOf<U> | undefined;\n\n /** Returns the id of the current assigned entity, undefined if unset, or undefined if set to a new entity. */\n idMaybe: IdOf<U> | undefined;\n\n idTagged: string;\n\n /** Returns `true` if this relation is currently set (i.e. regardless of whether it's loaded, or if it is set but the assigned entity doesn't have an id saved. */\n readonly isSet: boolean;\n}\n\n/**\n * Manages a set of foreign keys from one entity to another, i.e. `Comment.parent --> Book | BookReview`.\n *\n * We keep the current `parent` / `parent.id` value in the `__orm.data` hash, where the\n * current value could be either the `comments.parent_book_id` / `comments.parent_book_review_id` id (as a tagged string)\n * from the database, or an entity `Book` / `BookReview` that the user has set.\n *\n * Note that if any of our columns (eg `comments.parent_book_review_id`) is unique, this `PolymorphicReference` will\n * essentially be half of a one-to-one relationship, but we'll keep using this reference on the \"owning\" side; the other\n * side, i.e. `BookReview.comment` will use a `OneToOneReference` to point back to us.\n */\nexport class PolymorphicReferenceImpl<T extends Entity, U extends Entity, N extends never | undefined>\n extends AbstractRelationImpl<T, U>\n implements PolymorphicReference<T, U, N>\n{\n private loaded: U | N | undefined;\n // We need a separate boolean to b/c loaded == undefined can still mean \"_isLoaded\" for nullable fks.\n private _isLoaded = false;\n private field: PolymorphicField;\n #hasBeenSet = false;\n\n constructor(\n entity: T,\n public fieldName: keyof T & string,\n ) {\n super(entity);\n this.field = getMetadata(entity).allFields[this.fieldName] as PolymorphicField;\n if (getInstanceData(entity).isOrWasNew) {\n this._isLoaded = true;\n }\n }\n\n private get currentComponent(): PolymorphicFieldComponent | N {\n const cstr = maybeGetConstructorFromReference(this.current());\n return this.field.components.find((c) => c.otherMetadata().cstr === cstr) as any;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.fieldName);\n }\n\n async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const current = this.current();\n // Resolve the id to an entity\n if (!this._isLoaded || opts.forceReload) {\n this.loaded =\n isEntity(current) || current === undefined\n ? (current as U | undefined)\n : ((await getEmInternalApi(this.entity.em).load(getConstructorFromTaggedId(current), current)) as U);\n }\n this._isLoaded = true;\n return this.filterDeleted(this.loaded!, opts);\n }\n\n set(other: U | N): void {\n this.setImpl(other);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n /**\n * Looks for an entity in `EntityManager`, b/c we may have it in memory even if\n * our reference is not specifically loaded.\n */\n maybeFindEntity(): U | undefined {\n // Check this.loaded first b/c a new entity won't have an id yet\n const { idTaggedMaybe } = this;\n return (\n this.loaded ??\n (idTaggedMaybe !== undefined ? getEmInternalApi(this.entity.em).getEntity<U>(idTaggedMaybe) : undefined)\n );\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.loaded = this.maybeFindEntity();\n this._isLoaded = true;\n }\n\n private unload(): void {\n this.loaded = undefined;\n this._isLoaded = false;\n }\n\n import(other: PolymorphicReferenceImpl<T, U, N>, findEntity: (e: U) => U): void {\n this.loaded = other.loaded ? findEntity(other.loaded) : undefined;\n this._isLoaded = true;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n ensureNotDeleted(this.entity, \"pending\");\n // This should only be callable in the type system if we've already resolved this to an instance,\n // but, just in case we somehow got here in an unloaded state, check to see if we're already in the UoW\n if (!this._isLoaded) {\n const existing = this.maybeFindExisting();\n if (existing === undefined) {\n throw new Error(`${this.entity}.${this.fieldName} was not loaded`);\n }\n this.loaded = existing;\n this._isLoaded = true;\n }\n\n return this.filterDeleted(this.loaded!, opts);\n }\n\n get getWithDeleted(): U | N {\n return this.doGet({ withDeleted: true });\n }\n\n get get(): U | N {\n return this.doGet({ withDeleted: false });\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as IdOf<U> | undefined;\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idTagged(): string {\n return this.idTaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idTaggedMaybe(): string | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current());\n }\n\n get hasBeenSet() {\n return this.#hasBeenSet;\n }\n\n // private impl\n\n setFromOpts(other: U): void {\n this.setImpl(other);\n }\n\n maybeCascadeDelete(): void {\n if (this.isCascadeDelete) {\n const current = this.current({ withDeleted: true });\n if (current !== undefined && typeof current !== \"string\") {\n this.entity.em.delete(current as U);\n }\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n // if we are going to delete this relation as well, then we don't need to clean it up\n if (this.isCascadeDelete) return;\n const current = await this.load({ withDeleted: true });\n if (current !== undefined) {\n const o2m = this.getOtherRelation(current);\n if (o2m instanceof OneToManyCollection) {\n o2m.remove(this.entity, { requireLoaded: false });\n } else {\n o2m.set(undefined as any);\n }\n }\n setField(this.entity, this.fieldName, undefined);\n this.loaded = undefined as any;\n this._isLoaded = true;\n }\n\n // Internal method used by PolymorphicReference\n setImpl(other: U | N): void {\n this.#hasBeenSet = true;\n\n if (sameEntity(other, this.current({ withDeleted: true }))) {\n return;\n }\n\n if (\n other !== undefined &&\n !this.field.components.some(\n (c) =>\n other instanceof c.otherMetadata().cstr ||\n (typeof other === \"string\" && getConstructorFromTaggedId(other) === c.otherMetadata().cstr),\n )\n ) {\n fail(`${other} cannot be set as '${this.field.fieldName}' on ${this.entity}`);\n }\n\n // we may not be loaded yet, but our previous entity might already be in the UoW\n const previousLoaded = this.loaded ?? this.maybeFindExisting();\n\n ensureNotDeleted(this.entity, \"pending\");\n\n // Keep the entity when its tagged id cannot distinguish between sibling subtypes.\n if (isEntity(other)) {\n const otherMeta = getMetadata(other);\n const hasComponentsWithSameBaseType =\n otherMeta.baseType &&\n this.field.components.some(\n (component) =>\n component.otherMetadata().baseType === otherMeta.baseType &&\n !(other instanceof component.otherMetadata().cstr),\n );\n setField(\n this.entity,\n this.fieldName,\n other.isNewEntity || hasComponentsWithSameBaseType ? other : other.idTagged,\n );\n } else {\n setField(this.entity, this.fieldName, other);\n }\n\n if (typeof other === \"string\") {\n this.loaded = undefined;\n this._isLoaded = false;\n } else {\n this.loaded = other;\n this._isLoaded = true;\n }\n\n // If had an existing value, remove us from its collection\n if (previousLoaded) {\n const prevRelation = this.getOtherRelation(previousLoaded);\n if (prevRelation instanceof OneToManyCollection) {\n prevRelation.removeIfLoaded(this.entity);\n } else {\n prevRelation.set(undefined as any);\n }\n }\n if (other !== undefined && isEntity(other)) {\n const newRelation = this.getOtherRelation(other);\n if (newRelation instanceof OneToManyCollection) {\n newRelation.add(this.entity);\n } else {\n newRelation.set(this.entity);\n }\n }\n }\n\n // We need to keep U in data[fieldName] to handle entities without an id assigned yet.\n current(opts?: { withDeleted?: boolean }): U | TaggedId | N {\n const current = getField(this.entity, this.fieldName);\n if (current !== undefined && isEntity(current)) {\n return this.filterDeleted(current as U, opts);\n }\n return current;\n }\n\n public toString(): string {\n return `PolymorphicReference(entity: ${this.entity}, fieldName: ${\n this.fieldName\n }, otherType: ${this.currentComponent?.otherMetadata().type}, otherFieldName: ${\n this.currentComponent?.otherFieldName\n }, id: ${this.id})`;\n }\n\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n return opts?.withDeleted === true || entity === undefined || !entity.isDeletedEntity ? entity : (undefined as N);\n }\n\n /** Returns the other relation that points back at us, i.e. we're `comment.parent_book_id` and this is `Book.comments`. */\n private getOtherRelation(other: U): OneToManyCollection<U, T> | OneToOneReference<U, T> {\n const component = this.field.components.find((c) => other instanceof c.otherMetadata().cstr) as any;\n return (other as U)[component?.otherFieldName as keyof U] as any;\n }\n\n private maybeFindExisting(): U | undefined {\n return this.idTaggedMaybe !== undefined ? getEmInternalApi(this.entity.em).getEntity<U>(this.idTagged) : undefined;\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/** Checks polymorphic targets at public entity-returning boundaries. */\nclass PluginPolymorphicReference<\n T extends Entity,\n U extends Entity,\n N extends never | undefined,\n> extends PolymorphicReferenceImpl<T, U, N> {\n override get get(): U | N {\n return this.check(super.get);\n }\n\n override get getWithDeleted(): U | N {\n return this.check(super.getWithDeleted);\n }\n\n override async load(opts: { withDeleted?: boolean; forceReload?: boolean } = {}): Promise<U | N> {\n return this.check(await super.load(opts));\n }\n\n /** Checks visibility when returning the target entity. */\n private check<V extends Entity | undefined>(value: V): V {\n return checkVisibleReference(this.entity, this.fieldName, value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAgB,oBAImB;CACjC,OAAO,WAAW,QAAW,cAAc;EAEzC,OAAO,KADU,kBAAkB,MAAM,IAAI,6BAA6B,0BAC7C,QAAQ,SAA6B;CACpE,CAAC;AACH;;AAGA,SAAgB,uBAAuB,gBAA4E;CACjH,OAAO,0BAA0B;AACnC;;;;;;;;;;;;AAwCA,IAAa,2BAAb,cACU,qBAEV;CASW;CART;CAEA,YAAoB;CACpB;CACA,cAAc;CAEd,YACE,QACA,WACA;EACA,MAAM,MAAM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;AACpB;;AAGA,IAAM,6BAAN,cAIU,yBAAkC;CAC1C,IAAa,MAAa;EACxB,OAAO,KAAK,MAAM,MAAM,GAAG;CAC7B;CAEA,IAAa,iBAAwB;EACnC,OAAO,KAAK,MAAM,MAAM,cAAc;CACxC;CAEA,MAAe,KAAK,OAAyD,CAAC,GAAmB;EAC/F,OAAO,KAAK,MAAM,MAAM,MAAM,KAAK,IAAI,CAAC;CAC1C;;CAGA,MAA4C,OAAa;EACvD,OAAO,sBAAsB,KAAK,QAAQ,KAAK,WAAW,KAAK;CACjE;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/relations/PropertySymbols.ts
|
|
3
3
|
const PropertyT = Symbol();
|
|
4
|
-
//#endregion
|
|
5
4
|
exports.PropertyT = PropertyT;
|
|
6
5
|
|
|
7
6
|
//# sourceMappingURL=PropertySymbols.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertySymbols.d.cts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PropertySymbols.d.cts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":"A,qBAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertySymbols.d.mts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PropertySymbols.d.mts","names":[],"sources":["../../src/relations/PropertySymbols.ts"],"mappings":"A,qBAAa"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../Entity.cjs");
|
|
3
|
+
const require_EntityManager = require("../EntityManager.cjs");
|
|
4
|
+
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
5
|
+
const require_fields = require("../fields.cjs");
|
|
6
|
+
require("../index.cjs");
|
|
7
|
+
const require_loading_loadHints = require("../loading/loadHints.cjs");
|
|
8
|
+
const require_metrics_EntityMetrics = require("../metrics/EntityMetrics.cjs");
|
|
2
9
|
const require_newEntity = require("../newEntity.cjs");
|
|
10
|
+
const require_reactivity_reactiveHints = require("../reactivity/reactiveHints.cjs");
|
|
3
11
|
const require_relations_AbstractPropertyImpl = require("./AbstractPropertyImpl.cjs");
|
|
4
|
-
const require_metrics_EntityMetrics = require("../metrics/EntityMetrics.cjs");
|
|
5
12
|
const require_relations_PropertySymbols = require("./PropertySymbols.cjs");
|
|
6
|
-
|
|
7
|
-
const require_loading_loadHints = require("../loading/loadHints.cjs");
|
|
8
|
-
const require_fields = require("../fields.cjs");
|
|
9
|
-
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
10
|
-
require("../index.cjs");
|
|
11
|
-
const require_EntityManager = require("../EntityManager.cjs");
|
|
12
|
-
require("../Entity.cjs");
|
|
13
|
-
//#region src/relations/ReactiveField.ts
|
|
13
|
+
// src/relations/ReactiveField.ts
|
|
14
14
|
/**
|
|
15
15
|
* Creates a calculated derived value from a load hint + lambda.
|
|
16
16
|
*
|
|
@@ -127,7 +127,6 @@ var ReactiveFieldImpl = class extends require_relations_AbstractPropertyImpl.Abs
|
|
|
127
127
|
function isReactiveField(maybeReactiveField) {
|
|
128
128
|
return maybeReactiveField instanceof ReactiveFieldImpl;
|
|
129
129
|
}
|
|
130
|
-
//#endregion
|
|
131
130
|
exports.ReactiveFieldImpl = ReactiveFieldImpl;
|
|
132
131
|
exports.hasReactiveField = hasReactiveField;
|
|
133
132
|
exports.isReactiveField = isReactiveField;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { Entity } from "../Entity.cjs";
|
|
2
|
+
import { PrimitiveField } from "../EntityMetadata.cjs";
|
|
3
|
+
import { IsLoadedCachable } from "../loading/IsLoadedCache.cjs";
|
|
1
4
|
import { EvaluationSlot } from "../metrics/EntityMetrics.cjs";
|
|
5
|
+
import { Reacted, ReactiveHint } from "../reactivity/reactiveHints.cjs";
|
|
2
6
|
import { AbstractPropertyImpl } from "./AbstractPropertyImpl.cjs";
|
|
3
|
-
import { IsLoadedCachable } from "../loading/IsLoadedCache.cjs";
|
|
4
7
|
import { PropertyT } from "./PropertySymbols.cjs";
|
|
5
|
-
import { Reacted, ReactiveHint } from "../reactivity/reactiveHints.cjs";
|
|
6
|
-
import { PrimitiveField } from "../EntityMetadata.cjs";
|
|
7
|
-
import { Entity } from "../Entity.cjs";
|
|
8
|
-
//#region src/relations/ReactiveField.d.ts
|
|
9
8
|
/**
|
|
10
9
|
* A `ReactiveField` is a value that is derived from other entities/values,
|
|
11
10
|
* similar to a `Property`, but it is also persisted in the database.
|
|
@@ -88,5 +87,4 @@ export declare class ReactiveFieldImpl<T extends Entity, H extends ReactiveHint<
|
|
|
88
87
|
}
|
|
89
88
|
/** Type guard utility for determining if an entity field is a ReactiveField. */
|
|
90
89
|
export declare function isReactiveField(maybeReactiveField: any): maybeReactiveField is ReactiveField<any, any>;
|
|
91
|
-
//#endregion
|
|
92
90
|
//# sourceMappingURL=ReactiveField.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveField.d.cts","names":[],"sources":["../../src/relations/ReactiveField.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ReactiveField.d.cts","names":[],"sources":["../../src/relations/ReactiveField.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAyBiB,cAAc,UAAU,QAAQ;GAC9C,YAAY;EACb;EACA;;;;;;;;;;;;;;;;;EAkBA,KAAK;IAAS;MAA0B,QAAQ;;EAGhD,KAAK;;;;;;;;EASL,YAAY;;;;;;;;;;wBAWE,iBAAiB,UAAU,cAAc,UAAU,aAAa,IAAI,GAClF,MAAM,GACN,KAAK,QAAQ,QAAQ,GAAG,OAAO,GAC/B;EAAS,gBAAgB,QAAQ;IAChC,cAAc,GAAG;qBAWP,kBAAkB,UAAU,QAAQ,UAAU,aAAa,IAAI,WAClE,qBAAqB,cAClB,cAAc,GAAG,IAAI;;UAatB;mBACS;UACT;EANV,YACE,QAAQ,GACR,OAAO,gBACP,cAAc,GACN,KAAK,QAAQ,QAAQ,GAAG,OAAO,GACtB,YAAY,gBACrB,iBAAgB,QAAQ;EAO5B,KAAK;IAAS;MAA0B,QAAQ;;MA4BlD,OAAO;MAwCP,mBAAmB;MAInB,gBAAgB;MAIhB,cAAc;MAId;MAIA;EAQJ;MAQI;EAKJ,gBAAgB;GAKf,YAAiC;UAE1B;;;wBAQM,gBAAgB,0BAA0B,sBAAsB"}
|