joist-core 2.3.0-next.95 → 2.3.0-next.97
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/EntityManager.cjs +36 -39
- package/build/EntityManager.cjs.map +1 -1
- package/build/EntityManager.d.cts +4 -4
- package/build/EntityManager.d.mts +4 -4
- package/build/EntityManager.js +29 -32
- package/build/EntityManager.js.map +1 -1
- package/build/EntityMetadata.cjs +3 -3
- package/build/EntityMetadata.js +3 -3
- package/build/IndexManager.cjs +1 -1
- package/build/IndexManager.js +1 -1
- package/build/InstanceData.cjs +1 -1
- package/build/InstanceData.js +1 -1
- package/build/JoinRows.cjs +1 -1
- package/build/JoinRows.js +1 -1
- package/build/PluginManager.cjs +0 -1
- package/build/PluginManager.cjs.map +1 -1
- package/build/PluginManager.d.cts +1 -1
- package/build/PluginManager.d.mts +1 -1
- package/build/PluginManager.js +0 -1
- package/build/PluginManager.js.map +1 -1
- package/build/ReactionsManager.cjs +2 -2
- package/build/ReactionsManager.js +2 -2
- package/build/Todo.cjs +1 -1
- package/build/Todo.js +1 -1
- package/build/batchloaders/enumCollectionBatchLoader.cjs +1 -1
- package/build/batchloaders/enumCollectionBatchLoader.js +1 -1
- package/build/batchloaders/loadBatchLoader.cjs +6 -5
- package/build/batchloaders/loadBatchLoader.cjs.map +1 -1
- package/build/batchloaders/loadBatchLoader.d.cts.map +1 -1
- package/build/batchloaders/loadBatchLoader.d.mts.map +1 -1
- package/build/batchloaders/loadBatchLoader.js +4 -3
- package/build/batchloaders/loadBatchLoader.js.map +1 -1
- package/build/batchloaders/manyToManyBatchLoader.cjs +1 -1
- package/build/batchloaders/manyToManyBatchLoader.js +1 -1
- package/build/batchloaders/oneToManyBatchLoader.cjs +3 -3
- package/build/batchloaders/oneToManyBatchLoader.cjs.map +1 -1
- package/build/batchloaders/oneToManyBatchLoader.js +2 -2
- package/build/batchloaders/oneToOneBatchLoader.cjs +4 -4
- package/build/batchloaders/oneToOneBatchLoader.cjs.map +1 -1
- package/build/batchloaders/oneToOneBatchLoader.js +3 -3
- package/build/batchloaders/populateBatchLoader.cjs +11 -11
- package/build/batchloaders/populateBatchLoader.cjs.map +1 -1
- package/build/batchloaders/populateBatchLoader.js +8 -8
- package/build/batchloaders/recursiveChildrenBatchLoader.cjs +8 -8
- package/build/batchloaders/recursiveChildrenBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveChildrenBatchLoader.js +5 -5
- package/build/batchloaders/recursiveM2mBatchLoader.cjs +5 -5
- package/build/batchloaders/recursiveM2mBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveM2mBatchLoader.js +2 -2
- package/build/batchloaders/recursiveParentsBatchLoader.cjs +8 -8
- package/build/batchloaders/recursiveParentsBatchLoader.cjs.map +1 -1
- package/build/batchloaders/recursiveParentsBatchLoader.js +5 -5
- package/build/changes.cjs +4 -4
- package/build/changes.js +4 -4
- package/build/config.cjs +3 -3
- package/build/config.js +3 -3
- package/build/configure.cjs +6 -6
- package/build/configure.js +6 -6
- package/build/dataloaders/fastWhereFilterHash.cjs +3 -3
- package/build/dataloaders/fastWhereFilterHash.cjs.map +1 -1
- package/build/dataloaders/fastWhereFilterHash.js +2 -2
- package/build/dataloaders/fastWhereFilterHash.js.map +1 -1
- package/build/dataloaders/findByUniqueDataLoader.cjs +5 -6
- package/build/dataloaders/findByUniqueDataLoader.cjs.map +1 -1
- package/build/dataloaders/findByUniqueDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findByUniqueDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findByUniqueDataLoader.js +3 -4
- package/build/dataloaders/findByUniqueDataLoader.js.map +1 -1
- package/build/dataloaders/findCountDataLoader.cjs +10 -13
- package/build/dataloaders/findCountDataLoader.cjs.map +1 -1
- package/build/dataloaders/findCountDataLoader.d.cts +2 -2
- package/build/dataloaders/findCountDataLoader.d.mts +2 -2
- package/build/dataloaders/findCountDataLoader.js +4 -7
- package/build/dataloaders/findCountDataLoader.js.map +1 -1
- package/build/dataloaders/findDataLoader.cjs +15 -19
- package/build/dataloaders/findDataLoader.cjs.map +1 -1
- package/build/dataloaders/findDataLoader.d.cts +2 -2
- package/build/dataloaders/findDataLoader.d.cts.map +1 -1
- package/build/dataloaders/findDataLoader.d.mts +2 -2
- package/build/dataloaders/findDataLoader.d.mts.map +1 -1
- package/build/dataloaders/findDataLoader.js +5 -9
- package/build/dataloaders/findDataLoader.js.map +1 -1
- package/build/dataloaders/findIdsDataLoader.cjs +6 -9
- package/build/dataloaders/findIdsDataLoader.cjs.map +1 -1
- package/build/dataloaders/findIdsDataLoader.d.cts +1 -1
- package/build/dataloaders/findIdsDataLoader.d.mts +1 -1
- package/build/dataloaders/findIdsDataLoader.js +3 -6
- package/build/dataloaders/findIdsDataLoader.js.map +1 -1
- package/build/dataloaders/findOrCreateDataLoader.cjs +1 -2
- package/build/dataloaders/findOrCreateDataLoader.cjs.map +1 -1
- package/build/dataloaders/findOrCreateDataLoader.js +1 -2
- package/build/dataloaders/findOrCreateDataLoader.js.map +1 -1
- package/build/dataloaders/findPaginatedDataLoader.cjs +3 -6
- package/build/dataloaders/findPaginatedDataLoader.cjs.map +1 -1
- package/build/dataloaders/findPaginatedDataLoader.d.cts +1 -1
- package/build/dataloaders/findPaginatedDataLoader.d.mts +1 -1
- package/build/dataloaders/findPaginatedDataLoader.js +2 -5
- package/build/dataloaders/findPaginatedDataLoader.js.map +1 -1
- package/build/dataloaders/lensDataLoader.cjs +4 -4
- package/build/dataloaders/lensDataLoader.cjs.map +1 -1
- package/build/dataloaders/lensDataLoader.js +2 -2
- package/build/dataloaders/lensDataLoader.js.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.cjs +1 -4
- package/build/dataloaders/manyToManyFindDataLoader.cjs.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.d.cts +0 -1
- package/build/dataloaders/manyToManyFindDataLoader.d.cts.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.d.mts +0 -1
- package/build/dataloaders/manyToManyFindDataLoader.d.mts.map +1 -1
- package/build/dataloaders/manyToManyFindDataLoader.js +1 -4
- package/build/dataloaders/manyToManyFindDataLoader.js.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.cjs +3 -6
- package/build/dataloaders/oneToManyFindDataLoader.cjs.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.d.cts +0 -1
- package/build/dataloaders/oneToManyFindDataLoader.d.cts.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.d.mts +0 -1
- package/build/dataloaders/oneToManyFindDataLoader.d.mts.map +1 -1
- package/build/dataloaders/oneToManyFindDataLoader.js +2 -5
- package/build/dataloaders/oneToManyFindDataLoader.js.map +1 -1
- package/build/defaults.cjs +4 -4
- package/build/defaults.js +4 -4
- package/build/driverApi.cjs +4 -5
- package/build/driverApi.cjs.map +1 -1
- package/build/driverApi.d.cts +1 -1
- package/build/driverApi.d.mts +1 -1
- package/build/driverApi.js +2 -2
- package/build/driverApi.js.map +1 -1
- package/build/drivers/Driver.cjs +0 -1
- package/build/drivers/Driver.d.cts +1 -1
- package/build/drivers/Driver.d.mts +1 -1
- package/build/drivers/Driver.js +0 -1
- package/build/drivers/EntityWriter.cjs +2 -2
- package/build/drivers/EntityWriter.js +2 -2
- package/build/drivers/index.cjs +0 -6
- package/build/drivers/index.d.cts +1 -3
- package/build/drivers/index.d.mts +1 -3
- package/build/drivers/index.js +1 -3
- package/build/fieldSerde.cjs +2 -2
- package/build/fieldSerde.js +2 -2
- package/build/fields.cjs +2 -2
- package/build/fields.js +2 -2
- package/build/getProperties.cjs +1 -1
- package/build/getProperties.js +1 -1
- package/build/index.cjs +109 -106
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +27 -24
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +27 -24
- package/build/index.d.mts.map +1 -1
- package/build/index.js +52 -50
- package/build/index.js.map +1 -1
- package/build/json.cjs +3 -3
- package/build/json.js +3 -3
- package/build/keys.cjs +1 -1
- package/build/keys.js +1 -1
- package/build/loadHints.cjs +1 -1
- package/build/loadHints.js +1 -1
- package/build/loadLens.cjs +1 -1
- package/build/loadLens.js +1 -1
- package/build/logging/FactoryLogger.cjs +1 -1
- package/build/logging/FactoryLogger.js +1 -1
- package/build/logging/FieldLogger.cjs +1 -1
- package/build/logging/FieldLogger.js +1 -1
- package/build/logging/ReactionLogger.cjs +1 -1
- package/build/logging/ReactionLogger.js +1 -1
- package/build/newEntity.cjs +1 -1
- package/build/newEntity.js +1 -1
- package/build/newTestInstance.cjs +3 -3
- package/build/newTestInstance.js +3 -3
- package/build/plugins/PreloadPlugin.cjs +1 -2
- package/build/plugins/PreloadPlugin.d.cts +1 -1
- package/build/plugins/PreloadPlugin.d.mts +1 -1
- package/build/plugins/PreloadPlugin.js +1 -2
- package/build/preloading/JsonAggregatePreloader.cjs +31 -31
- package/build/preloading/JsonAggregatePreloader.cjs.map +1 -1
- package/build/preloading/JsonAggregatePreloader.d.cts +1 -1
- package/build/preloading/JsonAggregatePreloader.d.mts +1 -1
- package/build/preloading/JsonAggregatePreloader.js +6 -6
- package/build/preloading/JsonAggregatePreloader.js.map +1 -1
- package/build/preloading/partitionHint.cjs +3 -3
- package/build/preloading/partitionHint.js +3 -3
- package/build/{ConditionBuilder.cjs → queries/ConditionBuilder.cjs} +7 -8
- package/build/queries/ConditionBuilder.cjs.map +1 -0
- package/build/{ConditionBuilder.d.cts → queries/ConditionBuilder.d.cts} +3 -3
- package/build/queries/ConditionBuilder.d.cts.map +1 -0
- package/build/{ConditionBuilder.d.mts → queries/ConditionBuilder.d.mts} +3 -3
- package/build/queries/ConditionBuilder.d.mts.map +1 -0
- package/build/{ConditionBuilder.js → queries/ConditionBuilder.js} +4 -5
- package/build/queries/ConditionBuilder.js.map +1 -0
- package/build/{conditions.cjs → queries/conditions.cjs} +1 -2
- package/build/queries/conditions.cjs.map +1 -0
- package/build/{conditions.d.cts → queries/conditions.d.cts} +2 -2
- package/build/queries/conditions.d.cts.map +1 -0
- package/build/{conditions.d.mts → queries/conditions.d.mts} +2 -2
- package/build/queries/conditions.d.mts.map +1 -0
- package/build/{conditions.js → queries/conditions.js} +1 -2
- package/build/queries/conditions.js.map +1 -0
- package/build/queries/entityQueryUtils.cjs +60 -0
- package/build/queries/entityQueryUtils.cjs.map +1 -0
- package/build/queries/entityQueryUtils.d.cts +19 -0
- package/build/queries/entityQueryUtils.d.cts.map +1 -0
- package/build/queries/entityQueryUtils.d.mts +19 -0
- package/build/queries/entityQueryUtils.d.mts.map +1 -0
- package/build/queries/entityQueryUtils.js +56 -0
- package/build/queries/entityQueryUtils.js.map +1 -0
- package/build/{Aliases.cjs → queries/find/Aliases.cjs} +23 -28
- package/build/queries/find/Aliases.cjs.map +1 -0
- package/build/{Aliases.d.cts → queries/find/Aliases.d.cts} +7 -7
- package/build/queries/find/Aliases.d.cts.map +1 -0
- package/build/{Aliases.d.mts → queries/find/Aliases.d.mts} +7 -7
- package/build/queries/find/Aliases.d.mts.map +1 -0
- package/build/{Aliases.js → queries/find/Aliases.js} +7 -12
- package/build/queries/find/Aliases.js.map +1 -0
- package/build/{DeferredAlias.cjs → queries/find/DeferredAlias.cjs} +3 -6
- package/build/queries/find/DeferredAlias.cjs.map +1 -0
- package/build/{DeferredAlias.d.cts → queries/find/DeferredAlias.d.cts} +4 -4
- package/build/queries/find/DeferredAlias.d.cts.map +1 -0
- package/build/{DeferredAlias.d.mts → queries/find/DeferredAlias.d.mts} +4 -4
- package/build/queries/find/DeferredAlias.d.mts.map +1 -0
- package/build/{DeferredAlias.js → queries/find/DeferredAlias.js} +2 -5
- package/build/queries/find/DeferredAlias.js.map +1 -0
- package/build/{EntityFilter.cjs → queries/find/EntityFilter.cjs} +4 -9
- package/build/queries/find/EntityFilter.cjs.map +1 -0
- package/build/{EntityFilter.d.cts → queries/find/EntityFilter.d.cts} +6 -6
- package/build/queries/find/EntityFilter.d.cts.map +1 -0
- package/build/{EntityFilter.d.mts → queries/find/EntityFilter.d.mts} +6 -6
- package/build/queries/find/EntityFilter.d.mts.map +1 -0
- package/build/{EntityFilter.js → queries/find/EntityFilter.js} +1 -6
- package/build/queries/find/EntityFilter.js.map +1 -0
- package/build/{EntityGraphQLFilter.cjs → queries/find/EntityGraphQLFilter.cjs} +1 -5
- package/build/queries/find/EntityGraphQLFilter.cjs.map +1 -0
- package/build/{EntityGraphQLFilter.d.cts → queries/find/EntityGraphQLFilter.d.cts} +3 -3
- package/build/queries/find/EntityGraphQLFilter.d.cts.map +1 -0
- package/build/{EntityGraphQLFilter.d.mts → queries/find/EntityGraphQLFilter.d.mts} +3 -3
- package/build/queries/find/EntityGraphQLFilter.d.mts.map +1 -0
- package/build/{EntityGraphQLFilter.js → queries/find/EntityGraphQLFilter.js} +1 -5
- package/build/queries/find/EntityGraphQLFilter.js.map +1 -0
- package/build/{QueryParser.cjs → queries/find/QueryParser.cjs} +68 -356
- package/build/queries/find/QueryParser.cjs.map +1 -0
- package/build/{QueryParser.collectionJoins.cjs → queries/find/QueryParser.collectionJoins.cjs} +8 -8
- package/build/queries/find/QueryParser.collectionJoins.cjs.map +1 -0
- package/build/{QueryParser.collectionJoins.d.cts → queries/find/QueryParser.collectionJoins.d.cts} +1 -1
- package/build/queries/find/QueryParser.collectionJoins.d.cts.map +1 -0
- package/build/{QueryParser.collectionJoins.d.mts → queries/find/QueryParser.collectionJoins.d.mts} +1 -1
- package/build/queries/find/QueryParser.collectionJoins.d.mts.map +1 -0
- package/build/{QueryParser.collectionJoins.js → queries/find/QueryParser.collectionJoins.js} +2 -2
- package/build/queries/find/QueryParser.collectionJoins.js.map +1 -0
- package/build/{QueryParser.d.cts → queries/find/QueryParser.d.cts} +5 -159
- package/build/queries/find/QueryParser.d.cts.map +1 -0
- package/build/{QueryParser.d.mts → queries/find/QueryParser.d.mts} +5 -159
- package/build/queries/find/QueryParser.d.mts.map +1 -0
- package/build/{QueryParser.js → queries/find/QueryParser.js} +15 -295
- package/build/queries/find/QueryParser.js.map +1 -0
- package/build/{QueryParser.pruning.cjs → queries/find/QueryParser.pruning.cjs} +6 -20
- package/build/queries/find/QueryParser.pruning.cjs.map +1 -0
- package/build/queries/find/QueryParser.pruning.d.cts +8 -0
- package/build/queries/find/QueryParser.pruning.d.cts.map +1 -0
- package/build/queries/find/QueryParser.pruning.d.mts +8 -0
- package/build/queries/find/QueryParser.pruning.d.mts.map +1 -0
- package/build/{QueryParser.pruning.js → queries/find/QueryParser.pruning.js} +4 -17
- package/build/queries/find/QueryParser.pruning.js.map +1 -0
- package/build/{QueryVisitor.cjs → queries/find/QueryVisitor.cjs} +2 -3
- package/build/queries/find/QueryVisitor.cjs.map +1 -0
- package/build/{QueryVisitor.d.cts → queries/find/QueryVisitor.d.cts} +3 -2
- package/build/queries/find/QueryVisitor.d.cts.map +1 -0
- package/build/{QueryVisitor.d.mts → queries/find/QueryVisitor.d.mts} +3 -2
- package/build/queries/find/QueryVisitor.d.mts.map +1 -0
- package/build/{QueryVisitor.js → queries/find/QueryVisitor.js} +2 -3
- package/build/queries/find/QueryVisitor.js.map +1 -0
- package/build/{drivers/buildRawQuery.cjs → queries/find/buildFindQuery.cjs} +14 -15
- package/build/queries/find/buildFindQuery.cjs.map +1 -0
- package/build/{drivers/buildRawQuery.d.cts → queries/find/buildFindQuery.d.cts} +3 -3
- package/build/queries/find/buildFindQuery.d.cts.map +1 -0
- package/build/{drivers/buildRawQuery.d.mts → queries/find/buildFindQuery.d.mts} +3 -3
- package/build/queries/find/buildFindQuery.d.mts.map +1 -0
- package/build/{drivers/buildRawQuery.js → queries/find/buildFindQuery.js} +5 -6
- package/build/queries/find/buildFindQuery.js.map +1 -0
- package/build/{scopes.cjs → queries/find/scopes.cjs} +2 -3
- package/build/queries/find/scopes.cjs.map +1 -0
- package/build/{scopes.d.cts → queries/find/scopes.d.cts} +6 -6
- package/build/queries/find/scopes.d.cts.map +1 -0
- package/build/{scopes.d.mts → queries/find/scopes.d.mts} +6 -6
- package/build/queries/find/scopes.d.mts.map +1 -0
- package/build/{scopes.js → queries/find/scopes.js} +2 -3
- package/build/queries/find/scopes.js.map +1 -0
- package/build/queries/parsedConditions.cjs +21 -0
- package/build/queries/parsedConditions.cjs.map +1 -0
- package/build/queries/parsedConditions.d.cts +127 -0
- package/build/queries/parsedConditions.d.cts.map +1 -0
- package/build/queries/parsedConditions.d.mts +127 -0
- package/build/queries/parsedConditions.d.mts.map +1 -0
- package/build/queries/parsedConditions.js +20 -0
- package/build/queries/parsedConditions.js.map +1 -0
- package/build/{drivers/buildUtils.cjs → queries/renderConditions.cjs} +7 -8
- package/build/queries/renderConditions.cjs.map +1 -0
- package/build/{drivers/buildUtils.d.mts → queries/renderConditions.d.cts} +5 -4
- package/build/queries/renderConditions.d.cts.map +1 -0
- package/build/{drivers/buildUtils.d.cts → queries/renderConditions.d.mts} +5 -4
- package/build/queries/renderConditions.d.mts.map +1 -0
- package/build/{drivers/buildUtils.js → queries/renderConditions.js} +4 -5
- package/build/queries/renderConditions.js.map +1 -0
- package/build/{skipCondition.cjs → queries/skipCondition.cjs} +1 -2
- package/build/queries/skipCondition.cjs.map +1 -0
- package/build/{skipCondition.d.cts → queries/skipCondition.d.cts} +2 -2
- package/build/{skipCondition.d.cts.map → queries/skipCondition.d.cts.map} +1 -1
- package/build/{skipCondition.d.mts → queries/skipCondition.d.mts} +2 -2
- package/build/{skipCondition.d.mts.map → queries/skipCondition.d.mts.map} +1 -1
- package/build/{skipCondition.js → queries/skipCondition.js} +1 -2
- package/build/queries/skipCondition.js.map +1 -0
- package/build/{AliasAssigner.cjs → queries/sql/AliasAssigner.cjs} +2 -3
- package/build/queries/sql/AliasAssigner.cjs.map +1 -0
- package/build/{AliasAssigner.d.cts → queries/sql/AliasAssigner.d.cts} +2 -2
- package/build/queries/sql/AliasAssigner.d.cts.map +1 -0
- package/build/{AliasAssigner.d.mts → queries/sql/AliasAssigner.d.mts} +2 -2
- package/build/queries/sql/AliasAssigner.d.mts.map +1 -0
- package/build/{AliasAssigner.js → queries/sql/AliasAssigner.js} +2 -3
- package/build/queries/sql/AliasAssigner.js.map +1 -0
- package/build/{Expr.cjs → queries/sql/Expr.cjs} +9 -9
- package/build/queries/sql/Expr.cjs.map +1 -0
- package/build/{Expr.d.cts → queries/sql/Expr.d.cts} +4 -4
- package/build/queries/sql/Expr.d.cts.map +1 -0
- package/build/{Expr.d.mts → queries/sql/Expr.d.mts} +4 -4
- package/build/queries/sql/Expr.d.mts.map +1 -0
- package/build/{Expr.js → queries/sql/Expr.js} +4 -4
- package/build/queries/sql/Expr.js.map +1 -0
- package/build/{Tables.cjs → queries/sql/Tables.cjs} +63 -67
- package/build/queries/sql/Tables.cjs.map +1 -0
- package/build/{Tables.d.cts → queries/sql/Tables.d.cts} +6 -7
- package/build/queries/sql/Tables.d.cts.map +1 -0
- package/build/{Tables.d.mts → queries/sql/Tables.d.mts} +6 -7
- package/build/queries/sql/Tables.d.mts.map +1 -0
- package/build/{Tables.js → queries/sql/Tables.js} +9 -13
- package/build/queries/sql/Tables.js.map +1 -0
- package/build/{execute.cjs → queries/sql/execute.cjs} +32 -37
- package/build/queries/sql/execute.cjs.map +1 -0
- package/build/{execute.d.cts → queries/sql/execute.d.cts} +6 -6
- package/build/queries/sql/execute.d.cts.map +1 -0
- package/build/{execute.d.mts → queries/sql/execute.d.mts} +6 -6
- package/build/queries/sql/execute.d.mts.map +1 -0
- package/build/{execute.js → queries/sql/execute.js} +5 -10
- package/build/queries/sql/execute.js.map +1 -0
- package/build/{expressions → queries/sql/expressions}/arrayAgg.cjs +12 -12
- package/build/queries/sql/expressions/arrayAgg.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/arrayAgg.d.cts +1 -1
- package/build/queries/sql/expressions/arrayAgg.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/arrayAgg.d.mts +1 -1
- package/build/queries/sql/expressions/arrayAgg.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/arrayAgg.js +1 -1
- package/build/queries/sql/expressions/arrayAgg.js.map +1 -0
- package/build/{expressions → queries/sql/expressions}/case.cjs +14 -14
- package/build/queries/sql/expressions/case.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/case.d.cts +1 -1
- package/build/queries/sql/expressions/case.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/case.d.mts +1 -1
- package/build/queries/sql/expressions/case.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/case.js +1 -1
- package/build/queries/sql/expressions/case.js.map +1 -0
- package/build/queries/sql/expressions/coalesce.cjs +25 -0
- package/build/queries/sql/expressions/coalesce.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/coalesce.d.cts +1 -1
- package/build/queries/sql/expressions/coalesce.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/coalesce.d.mts +1 -1
- package/build/queries/sql/expressions/coalesce.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/coalesce.js +1 -1
- package/build/queries/sql/expressions/coalesce.js.map +1 -0
- package/build/{expressions → queries/sql/expressions}/codecs.cjs +5 -5
- package/build/queries/sql/expressions/codecs.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/codecs.d.cts +1 -1
- package/build/queries/sql/expressions/codecs.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/codecs.d.mts +1 -1
- package/build/queries/sql/expressions/codecs.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/codecs.js +3 -3
- package/build/queries/sql/expressions/codecs.js.map +1 -0
- package/build/queries/sql/expressions/expression.cjs +102 -0
- package/build/queries/sql/expressions/expression.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/expression.d.cts +1 -1
- package/build/queries/sql/expressions/expression.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/expression.d.mts +1 -1
- package/build/queries/sql/expressions/expression.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/expression.js +2 -2
- package/build/queries/sql/expressions/expression.js.map +1 -0
- package/build/queries/sql/expressions/greatest.cjs +25 -0
- package/build/queries/sql/expressions/greatest.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/greatest.d.cts +1 -1
- package/build/queries/sql/expressions/greatest.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/greatest.d.mts +1 -1
- package/build/queries/sql/expressions/greatest.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/greatest.js +1 -1
- package/build/queries/sql/expressions/greatest.js.map +1 -0
- package/build/queries/sql/expressions/least.cjs +25 -0
- package/build/queries/sql/expressions/least.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/least.d.cts +1 -1
- package/build/queries/sql/expressions/least.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/least.d.mts +1 -1
- package/build/queries/sql/expressions/least.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/least.js +1 -1
- package/build/queries/sql/expressions/least.js.map +1 -0
- package/build/{expressions → queries/sql/expressions}/nullIf.cjs +6 -6
- package/build/queries/sql/expressions/nullIf.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/nullIf.d.cts +1 -1
- package/build/queries/sql/expressions/nullIf.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/nullIf.d.mts +1 -1
- package/build/queries/sql/expressions/nullIf.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/nullIf.js +1 -1
- package/build/queries/sql/expressions/nullIf.js.map +1 -0
- package/build/{expressions → queries/sql/expressions}/parseExpression.cjs +16 -16
- package/build/queries/sql/expressions/parseExpression.cjs.map +1 -0
- package/build/{expressions → queries/sql/expressions}/parseExpression.d.cts +1 -1
- package/build/queries/sql/expressions/parseExpression.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/parseExpression.d.mts +1 -1
- package/build/queries/sql/expressions/parseExpression.d.mts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/parseExpression.js +2 -2
- package/build/queries/sql/expressions/parseExpression.js.map +1 -0
- package/build/{expressions → queries/sql/expressions}/types.d.cts +1 -1
- package/build/queries/sql/expressions/types.d.cts.map +1 -0
- package/build/{expressions → queries/sql/expressions}/types.d.mts +1 -1
- package/build/queries/sql/expressions/types.d.mts.map +1 -0
- package/build/{keywords.cjs → queries/sql/keywords.cjs} +1 -1
- package/build/queries/sql/keywords.cjs.map +1 -0
- package/build/{keywords.d.cts → queries/sql/keywords.d.cts} +1 -1
- package/build/queries/sql/keywords.d.cts.map +1 -0
- package/build/{keywords.d.mts → queries/sql/keywords.d.mts} +1 -1
- package/build/queries/sql/keywords.d.mts.map +1 -0
- package/build/{keywords.js → queries/sql/keywords.js} +1 -1
- package/build/queries/sql/keywords.js.map +1 -0
- package/build/{query.cjs → queries/sql/query.cjs} +112 -83
- package/build/queries/sql/query.cjs.map +1 -0
- package/build/{query.d.cts → queries/sql/query.d.cts} +18 -8
- package/build/queries/sql/query.d.cts.map +1 -0
- package/build/{query.d.mts → queries/sql/query.d.mts} +18 -8
- package/build/queries/sql/query.d.mts.map +1 -0
- package/build/{query.js → queries/sql/query.js} +41 -13
- package/build/queries/sql/query.js.map +1 -0
- package/build/queries/valueFilters.cjs +248 -0
- package/build/queries/valueFilters.cjs.map +1 -0
- package/build/queries/valueFilters.d.cts +28 -0
- package/build/queries/valueFilters.d.cts.map +1 -0
- package/build/queries/valueFilters.d.mts +28 -0
- package/build/queries/valueFilters.d.mts.map +1 -0
- package/build/queries/valueFilters.js +243 -0
- package/build/queries/valueFilters.js.map +1 -0
- package/build/reactiveHints.cjs +5 -5
- package/build/reactiveHints.js +5 -5
- package/build/relations/AbstractRelationImpl.cjs +0 -5
- package/build/relations/AbstractRelationImpl.cjs.map +1 -1
- package/build/relations/AbstractRelationImpl.d.cts +1 -2
- package/build/relations/AbstractRelationImpl.d.cts.map +1 -1
- package/build/relations/AbstractRelationImpl.d.mts +1 -2
- package/build/relations/AbstractRelationImpl.d.mts.map +1 -1
- package/build/relations/AbstractRelationImpl.js +1 -5
- package/build/relations/AbstractRelationImpl.js.map +1 -1
- package/build/relations/AsyncProperty.cjs +1 -1
- package/build/relations/AsyncProperty.js +1 -1
- package/build/relations/AsyncReactiveField.cjs +3 -3
- package/build/relations/AsyncReactiveField.js +3 -3
- package/build/relations/Collection.cjs +1 -1
- package/build/relations/Collection.js +1 -1
- package/build/relations/CustomCollection.cjs +1 -1
- package/build/relations/CustomCollection.js +1 -1
- package/build/relations/CustomReference.cjs +3 -3
- package/build/relations/CustomReference.js +3 -3
- package/build/relations/EnumCollection.cjs +2 -2
- package/build/relations/EnumCollection.js +2 -2
- package/build/relations/LazyField.cjs +6 -7
- package/build/relations/LazyField.cjs.map +1 -1
- package/build/relations/LazyField.js +5 -6
- package/build/relations/LazyField.js.map +1 -1
- package/build/relations/ManyToManyCollection.cjs +4 -3
- package/build/relations/ManyToManyCollection.cjs.map +1 -1
- package/build/relations/ManyToManyCollection.d.cts.map +1 -1
- package/build/relations/ManyToManyCollection.d.mts.map +1 -1
- package/build/relations/ManyToManyCollection.js +4 -3
- package/build/relations/ManyToManyCollection.js.map +1 -1
- package/build/relations/ManyToManyLargeCollection.cjs +2 -2
- package/build/relations/ManyToManyLargeCollection.js +2 -2
- package/build/relations/ManyToOneReference.cjs +7 -6
- package/build/relations/ManyToOneReference.cjs.map +1 -1
- package/build/relations/ManyToOneReference.d.cts.map +1 -1
- package/build/relations/ManyToOneReference.d.mts.map +1 -1
- package/build/relations/ManyToOneReference.js +7 -6
- package/build/relations/ManyToOneReference.js.map +1 -1
- package/build/relations/OneToManyCollection.cjs +6 -5
- package/build/relations/OneToManyCollection.cjs.map +1 -1
- package/build/relations/OneToManyCollection.d.cts.map +1 -1
- package/build/relations/OneToManyCollection.d.mts.map +1 -1
- package/build/relations/OneToManyCollection.js +4 -3
- package/build/relations/OneToManyCollection.js.map +1 -1
- package/build/relations/OneToManyLargeCollection.cjs +3 -3
- package/build/relations/OneToManyLargeCollection.js +3 -3
- package/build/relations/OneToOneReference.cjs +6 -5
- package/build/relations/OneToOneReference.cjs.map +1 -1
- package/build/relations/OneToOneReference.d.cts.map +1 -1
- package/build/relations/OneToOneReference.d.mts.map +1 -1
- package/build/relations/OneToOneReference.js +6 -5
- package/build/relations/OneToOneReference.js.map +1 -1
- package/build/relations/PolymorphicReference.cjs +7 -6
- package/build/relations/PolymorphicReference.cjs.map +1 -1
- package/build/relations/PolymorphicReference.d.cts.map +1 -1
- package/build/relations/PolymorphicReference.d.mts.map +1 -1
- package/build/relations/PolymorphicReference.js +7 -6
- package/build/relations/PolymorphicReference.js.map +1 -1
- package/build/relations/ReactiveField.cjs +3 -3
- package/build/relations/ReactiveField.js +3 -3
- package/build/relations/ReactiveGetter.cjs +1 -1
- package/build/relations/ReactiveGetter.js +1 -1
- package/build/relations/ReactiveManyToMany.cjs +5 -4
- package/build/relations/ReactiveManyToMany.cjs.map +1 -1
- package/build/relations/ReactiveManyToMany.d.cts.map +1 -1
- package/build/relations/ReactiveManyToMany.d.mts.map +1 -1
- package/build/relations/ReactiveManyToMany.js +5 -4
- package/build/relations/ReactiveManyToMany.js.map +1 -1
- package/build/relations/ReactiveManyToManyOtherSide.cjs +3 -3
- package/build/relations/ReactiveManyToManyOtherSide.js +3 -3
- package/build/relations/ReactiveReference.cjs +8 -7
- package/build/relations/ReactiveReference.cjs.map +1 -1
- package/build/relations/ReactiveReference.d.cts.map +1 -1
- package/build/relations/ReactiveReference.d.mts.map +1 -1
- package/build/relations/ReactiveReference.js +8 -7
- package/build/relations/ReactiveReference.js.map +1 -1
- package/build/relations/RecursiveCollection.cjs +3 -3
- package/build/relations/RecursiveCollection.js +3 -3
- package/build/relations/Reference.cjs +1 -1
- package/build/relations/Reference.js +1 -1
- package/build/relations/hasAsyncMethod.cjs +1 -1
- package/build/relations/hasAsyncMethod.js +1 -1
- package/build/relations/hasManyDerived.cjs +1 -1
- package/build/relations/hasManyDerived.js +1 -1
- package/build/relations/hasOneDerived.cjs +2 -2
- package/build/relations/hasOneDerived.js +2 -2
- package/build/relations/hasProperty.cjs +2 -2
- package/build/relations/hasProperty.js +2 -2
- package/build/relations/index.cjs +13 -13
- package/build/relations/index.js +13 -13
- package/build/relations/isCascadeDelete.cjs +11 -0
- package/build/relations/isCascadeDelete.cjs.map +1 -0
- package/build/relations/isCascadeDelete.d.cts +7 -0
- package/build/relations/isCascadeDelete.d.cts.map +1 -0
- package/build/relations/isCascadeDelete.d.mts +7 -0
- package/build/relations/isCascadeDelete.d.mts.map +1 -0
- package/build/relations/isCascadeDelete.js +10 -0
- package/build/relations/isCascadeDelete.js.map +1 -0
- package/build/resurrection.cjs +1 -1
- package/build/resurrection.js +1 -1
- package/build/rules.cjs +4 -4
- package/build/rules.js +4 -4
- package/build/serde.cjs +1 -1
- package/build/serde.js +1 -1
- package/build/unnest.cjs +0 -1
- package/build/unnest.cjs.map +1 -1
- package/build/unnest.d.cts +1 -1
- package/build/unnest.d.mts +1 -1
- package/build/unnest.js +0 -1
- package/build/unnest.js.map +1 -1
- package/build/upsert.cjs +3 -3
- package/build/upsert.js +3 -3
- package/build/utils.cjs +1 -2
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +1 -1
- package/build/utils.d.mts +1 -1
- package/build/utils.js +1 -2
- package/build/utils.js.map +1 -1
- package/build/withLoaded.cjs +3 -3
- package/build/withLoaded.js +3 -3
- package/package.json +2 -2
- package/build/AliasAssigner.cjs.map +0 -1
- package/build/AliasAssigner.d.cts.map +0 -1
- package/build/AliasAssigner.d.mts.map +0 -1
- package/build/AliasAssigner.js.map +0 -1
- package/build/Aliases.cjs.map +0 -1
- package/build/Aliases.d.cts.map +0 -1
- package/build/Aliases.d.mts.map +0 -1
- package/build/Aliases.js.map +0 -1
- package/build/ConditionBuilder.cjs.map +0 -1
- package/build/ConditionBuilder.d.cts.map +0 -1
- package/build/ConditionBuilder.d.mts.map +0 -1
- package/build/ConditionBuilder.js.map +0 -1
- package/build/DeferredAlias.cjs.map +0 -1
- package/build/DeferredAlias.d.cts.map +0 -1
- package/build/DeferredAlias.d.mts.map +0 -1
- package/build/DeferredAlias.js.map +0 -1
- package/build/EntityFilter.cjs.map +0 -1
- package/build/EntityFilter.d.cts.map +0 -1
- package/build/EntityFilter.d.mts.map +0 -1
- package/build/EntityFilter.js.map +0 -1
- package/build/EntityGraphQLFilter.cjs.map +0 -1
- package/build/EntityGraphQLFilter.d.cts.map +0 -1
- package/build/EntityGraphQLFilter.d.mts.map +0 -1
- package/build/EntityGraphQLFilter.js.map +0 -1
- package/build/Expr.cjs.map +0 -1
- package/build/Expr.d.cts.map +0 -1
- package/build/Expr.d.mts.map +0 -1
- package/build/Expr.js.map +0 -1
- package/build/QueryParser.cjs.map +0 -1
- package/build/QueryParser.collectionJoins.cjs.map +0 -1
- package/build/QueryParser.collectionJoins.d.cts.map +0 -1
- package/build/QueryParser.collectionJoins.d.mts.map +0 -1
- package/build/QueryParser.collectionJoins.js.map +0 -1
- package/build/QueryParser.d.cts.map +0 -1
- package/build/QueryParser.d.mts.map +0 -1
- package/build/QueryParser.js.map +0 -1
- package/build/QueryParser.pruning.cjs.map +0 -1
- package/build/QueryParser.pruning.d.cts +0 -10
- package/build/QueryParser.pruning.d.cts.map +0 -1
- package/build/QueryParser.pruning.d.mts +0 -10
- package/build/QueryParser.pruning.d.mts.map +0 -1
- package/build/QueryParser.pruning.js.map +0 -1
- package/build/QueryVisitor.cjs.map +0 -1
- package/build/QueryVisitor.d.cts.map +0 -1
- package/build/QueryVisitor.d.mts.map +0 -1
- package/build/QueryVisitor.js.map +0 -1
- package/build/Tables.cjs.map +0 -1
- package/build/Tables.d.cts.map +0 -1
- package/build/Tables.d.mts.map +0 -1
- package/build/Tables.js.map +0 -1
- package/build/conditions.cjs.map +0 -1
- package/build/conditions.d.cts.map +0 -1
- package/build/conditions.d.mts.map +0 -1
- package/build/conditions.js.map +0 -1
- package/build/drivers/buildRawQuery.cjs.map +0 -1
- package/build/drivers/buildRawQuery.d.cts.map +0 -1
- package/build/drivers/buildRawQuery.d.mts.map +0 -1
- package/build/drivers/buildRawQuery.js.map +0 -1
- package/build/drivers/buildUtils.cjs.map +0 -1
- package/build/drivers/buildUtils.d.cts.map +0 -1
- package/build/drivers/buildUtils.d.mts.map +0 -1
- package/build/drivers/buildUtils.js.map +0 -1
- package/build/execute.cjs.map +0 -1
- package/build/execute.d.cts.map +0 -1
- package/build/execute.d.mts.map +0 -1
- package/build/execute.js.map +0 -1
- package/build/expressions/arrayAgg.cjs.map +0 -1
- package/build/expressions/arrayAgg.d.cts.map +0 -1
- package/build/expressions/arrayAgg.d.mts.map +0 -1
- package/build/expressions/arrayAgg.js.map +0 -1
- package/build/expressions/case.cjs.map +0 -1
- package/build/expressions/case.d.cts.map +0 -1
- package/build/expressions/case.d.mts.map +0 -1
- package/build/expressions/case.js.map +0 -1
- package/build/expressions/coalesce.cjs +0 -25
- package/build/expressions/coalesce.cjs.map +0 -1
- package/build/expressions/coalesce.d.cts.map +0 -1
- package/build/expressions/coalesce.d.mts.map +0 -1
- package/build/expressions/coalesce.js.map +0 -1
- package/build/expressions/codecs.cjs.map +0 -1
- package/build/expressions/codecs.d.cts.map +0 -1
- package/build/expressions/codecs.d.mts.map +0 -1
- package/build/expressions/codecs.js.map +0 -1
- package/build/expressions/expression.cjs +0 -102
- package/build/expressions/expression.cjs.map +0 -1
- package/build/expressions/expression.d.cts.map +0 -1
- package/build/expressions/expression.d.mts.map +0 -1
- package/build/expressions/expression.js.map +0 -1
- package/build/expressions/greatest.cjs +0 -25
- package/build/expressions/greatest.cjs.map +0 -1
- package/build/expressions/greatest.d.cts.map +0 -1
- package/build/expressions/greatest.d.mts.map +0 -1
- package/build/expressions/greatest.js.map +0 -1
- package/build/expressions/least.cjs +0 -25
- package/build/expressions/least.cjs.map +0 -1
- package/build/expressions/least.d.cts.map +0 -1
- package/build/expressions/least.d.mts.map +0 -1
- package/build/expressions/least.js.map +0 -1
- package/build/expressions/nullIf.cjs.map +0 -1
- package/build/expressions/nullIf.d.cts.map +0 -1
- package/build/expressions/nullIf.d.mts.map +0 -1
- package/build/expressions/nullIf.js.map +0 -1
- package/build/expressions/parseExpression.cjs.map +0 -1
- package/build/expressions/parseExpression.d.cts.map +0 -1
- package/build/expressions/parseExpression.d.mts.map +0 -1
- package/build/expressions/parseExpression.js.map +0 -1
- package/build/expressions/types.d.cts.map +0 -1
- package/build/expressions/types.d.mts.map +0 -1
- package/build/keywords.cjs.map +0 -1
- package/build/keywords.d.cts.map +0 -1
- package/build/keywords.d.mts.map +0 -1
- package/build/keywords.js.map +0 -1
- package/build/query.cjs.map +0 -1
- package/build/query.d.cts.map +0 -1
- package/build/query.d.mts.map +0 -1
- package/build/query.js.map +0 -1
- package/build/scopes.cjs.map +0 -1
- package/build/scopes.d.cts.map +0 -1
- package/build/scopes.d.mts.map +0 -1
- package/build/scopes.js.map +0 -1
- package/build/skipCondition.cjs.map +0 -1
- package/build/skipCondition.js.map +0 -1
- /package/build/{expressions → queries/sql/expressions}/types.cjs +0 -0
- /package/build/{expressions → queries/sql/expressions}/types.js +0 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractRelationImpl
|
|
1
|
+
import { getField, setField } from "../fields.js";
|
|
2
|
+
import { AbstractRelationImpl } from "./AbstractRelationImpl.js";
|
|
3
3
|
import { RelationT, RelationU } from "./RelationSymbols.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isCascadeDelete } from "./isCascadeDelete.js";
|
|
5
5
|
import { OneToManyCollection } from "./OneToManyCollection.js";
|
|
6
|
+
import { ReferenceN } from "./ReferenceSymbols.js";
|
|
6
7
|
import { failIfNewEntity, failNoId } from "./ManyToOneReference.js";
|
|
8
|
+
import { fail } from "../utils.js";
|
|
9
|
+
import { lazyField } from "../newEntity.js";
|
|
7
10
|
import { maybeResolveReferenceToId } from "../keys.js";
|
|
11
|
+
import { getConstructorFromTaggedId, maybeGetConstructorFromReference } from "../configure.js";
|
|
8
12
|
import { getMetadata } from "../EntityMetadata.js";
|
|
9
|
-
import { getField, setField } from "../fields.js";
|
|
10
|
-
import { fail } from "../utils.js";
|
|
11
13
|
import { ensureNotDeleted } from "../index.js";
|
|
12
14
|
import { sameEntity } from "../EntityManager.js";
|
|
13
15
|
import { isEntity } from "../Entity.js";
|
|
14
16
|
import { getInstanceData } from "../BaseEntity.js";
|
|
15
|
-
import { getConstructorFromTaggedId, maybeGetConstructorFromReference } from "../configure.js";
|
|
16
17
|
//#region src/relations/PolymorphicReference.ts
|
|
17
18
|
function hasOnePolymorphic() {
|
|
18
19
|
return lazyField((entity, fieldName) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolymorphicReference.js","names":["#hasBeenSet"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"../configure.ts\";\nimport { type Entity, isEntity } from \"../Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"../EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"../EntityMetadata.ts\";\nimport { getField, setField } from \"../fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\n} from \"../index.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { AbstractRelationImpl, isCascadeDelete } from \"./AbstractRelationImpl.ts\";\nimport { failIfNewEntity, failNoId } from \"./ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"./OneToManyCollection.ts\";\nimport { ReferenceN } from \"./ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"./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":";;;;;;;;;;;;;;;;AAsBA,SAAgB,oBAImB;CACjC,OAAO,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,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;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQ,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAO,iCAAiC,KAAK,QAAQ,CAAC;EAC5D,OAAO,KAAK,MAAM,WAAW,MAAM,MAAM,EAAE,cAAc,CAAC,CAAC,SAAS,IAAI;CAC1E;CAEA,IAAY,kBAA2B;EACrC,OAAO,gBAAgB,MAAM,KAAK,SAAS;CAC7C;CAEA,MAAM,KAAK,OAAyD,CAAC,GAAmB;EACtF,iBAAiB,KAAK,QAAQ,SAAS;EACvC,MAAM,UAAU,KAAK,QAAQ;EAE7B,IAAI,CAAC,KAAK,aAAa,KAAK,aAC1B,KAAK,SACH,SAAS,OAAO,KAAK,YAAY,KAAA,IAC5B,UAC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,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,CAAC,aAAgB;CACjB,CAAC,aAAgB;CACjB,CAAC,cAAiB;AACpB"}
|
|
1
|
+
{"version":3,"file":"PolymorphicReference.js","names":["#hasBeenSet"],"sources":["../../src/relations/PolymorphicReference.ts"],"sourcesContent":["import { maybeGetConstructorFromReference } from \"../configure.ts\";\nimport { type Entity, isEntity } from \"../Entity.ts\";\nimport { type IdOf, type TaggedId, sameEntity } from \"../EntityManager.ts\";\nimport { type PolymorphicFieldComponent, getMetadata } from \"../EntityMetadata.ts\";\nimport { getField, setField } from \"../fields.ts\";\nimport {\n type OneToOneReference,\n type PolymorphicField,\n type Reference,\n ensureNotDeleted,\n fail,\n getConstructorFromTaggedId,\n getInstanceData,\n maybeResolveReferenceToId,\n} from \"../index.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { AbstractRelationImpl } from \"./AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"./isCascadeDelete.ts\";\nimport { failIfNewEntity, failNoId } from \"./ManyToOneReference.ts\";\nimport { OneToManyCollection } from \"./OneToManyCollection.ts\";\nimport { ReferenceN } from \"./ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"./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,OAAO,WAAW,QAAW,cAAc;EACzC,OAAO,IAAI,yBAAkC,QAAQ,SAA6B;CACpF,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;EAFL,KAAA,YAAA;EAGP,KAAK,QAAQ,YAAY,MAAM,CAAC,CAAC,UAAU,KAAK;EAChD,IAAI,gBAAgB,MAAM,CAAC,CAAC,YAC1B,KAAK,YAAY;CAErB;CAEA,IAAY,mBAAkD;EAC5D,MAAM,OAAO,iCAAiC,KAAK,QAAQ,CAAC;EAC5D,OAAO,KAAK,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AAI,KAAA,CAAgB;EAErC;EACA,IAAI,UAAU,KAAA,KAAa,SAAS,KAAK,GAAG;GAC1C,MAAM,cAAc,KAAK,iBAAiB,KAAK;GAC/C,IAAI,uBAAuB,qBACzB,YAAY,IAAI,KAAK,MAAM;QAE3B,YAAY,IAAI,KAAK,MAAM;EAE/B;CACF;CAGA,QAAQ,MAAoD;EAC1D,MAAM,UAAU,SAAS,KAAK,QAAQ,KAAK,SAAS;EACpD,IAAI,YAAY,KAAA,KAAa,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,CAAC,aAAgB;CACjB,CAAC,aAAgB;CACjB,CAAC,cAAiB;AACpB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_fields = require("../fields.cjs");
|
|
3
3
|
const require_relations_AbstractPropertyImpl = require("./AbstractPropertyImpl.cjs");
|
|
4
4
|
const require_relations_PropertySymbols = require("./PropertySymbols.cjs");
|
|
5
5
|
require("../IsLoadedCache.cjs");
|
|
6
|
-
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
7
|
-
const require_fields = require("../fields.cjs");
|
|
8
6
|
const require_reactiveHints = require("../reactiveHints.cjs");
|
|
9
7
|
const require_loadHints = require("../loadHints.cjs");
|
|
8
|
+
const require_newEntity = require("../newEntity.cjs");
|
|
9
|
+
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
10
10
|
require("../index.cjs");
|
|
11
11
|
const require_EntityManager = require("../EntityManager.cjs");
|
|
12
12
|
require("../Entity.cjs");
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getField, isFieldSet, setField } from "../fields.js";
|
|
2
2
|
import { AbstractPropertyImpl } from "./AbstractPropertyImpl.js";
|
|
3
3
|
import { PropertyT } from "./PropertySymbols.js";
|
|
4
4
|
import "../IsLoadedCache.js";
|
|
5
|
-
import { getMetadata } from "../EntityMetadata.js";
|
|
6
|
-
import { getField, isFieldSet, setField } from "../fields.js";
|
|
7
5
|
import { convertToLoadHint } from "../reactiveHints.js";
|
|
8
6
|
import { isLoaded } from "../loadHints.js";
|
|
7
|
+
import { lazyField } from "../newEntity.js";
|
|
8
|
+
import { getMetadata } from "../EntityMetadata.js";
|
|
9
9
|
import "../index.js";
|
|
10
10
|
import { getEmInternalApi } from "../EntityManager.js";
|
|
11
11
|
import "../Entity.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_newEntity = require("../newEntity.cjs");
|
|
3
2
|
const require_relations_PropertySymbols = require("./PropertySymbols.cjs");
|
|
4
3
|
require("../reactiveHints.cjs");
|
|
4
|
+
const require_newEntity = require("../newEntity.cjs");
|
|
5
5
|
require("../Entity.cjs");
|
|
6
6
|
//#region src/relations/ReactiveGetter.ts
|
|
7
7
|
/** Creates a `ReactiveGetter`, for simple "getters" that still trackable for reactivity. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { lazyField } from "../newEntity.js";
|
|
2
1
|
import { PropertyT } from "./PropertySymbols.js";
|
|
3
2
|
import "../reactiveHints.js";
|
|
3
|
+
import { lazyField } from "../newEntity.js";
|
|
4
4
|
import "../Entity.js";
|
|
5
5
|
//#region src/relations/ReactiveGetter.ts
|
|
6
6
|
/** Creates a `ReactiveGetter`, for simple "getters" that still trackable for reactivity. */
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_newEntity = require("../newEntity.cjs");
|
|
3
2
|
const require_relations_AbstractRelationImpl = require("./AbstractRelationImpl.cjs");
|
|
4
3
|
const require_relations_RelationSymbols = require("./RelationSymbols.cjs");
|
|
5
|
-
const
|
|
4
|
+
const require_relations_isCascadeDelete = require("./isCascadeDelete.cjs");
|
|
6
5
|
require("../IsLoadedCache.cjs");
|
|
7
|
-
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
8
6
|
const require_reactiveHints = require("../reactiveHints.cjs");
|
|
9
7
|
const require_loadHints = require("../loadHints.cjs");
|
|
10
8
|
const require_utils = require("../utils.cjs");
|
|
9
|
+
const require_newEntity = require("../newEntity.cjs");
|
|
10
|
+
const require_batchloaders_manyToManyBatchLoader = require("../batchloaders/manyToManyBatchLoader.cjs");
|
|
11
|
+
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
11
12
|
const require_index = require("../index.cjs");
|
|
12
13
|
const require_EntityManager = require("../EntityManager.cjs");
|
|
13
14
|
const require_BaseEntity = require("../BaseEntity.cjs");
|
|
@@ -165,7 +166,7 @@ var ReactiveManyToManyImpl = class extends require_relations_AbstractRelationImp
|
|
|
165
166
|
return `ReactiveManyToMany(entity: ${this.entity}, fieldName: ${this.fieldName}, otherMeta: ${this.otherMeta.type})`;
|
|
166
167
|
}
|
|
167
168
|
get #isCascadeDelete() {
|
|
168
|
-
return
|
|
169
|
+
return require_relations_isCascadeDelete.isCascadeDelete(this, this.#field.fieldName);
|
|
169
170
|
}
|
|
170
171
|
async #loadFromJoinTable() {
|
|
171
172
|
const { em } = this.entity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveManyToMany.cjs","names":["lazyField","getMetadata","AbstractRelationImpl","#field","getEmInternalApi","#isCached","#loadPromise","#loadedMode","#isLoaded","#doGet","#loadFromJoinTable","#loaded","#filterDeleted","isLoaded","#syncJoinTableRows","convertToLoadHint","#isCascadeDelete","getMetadataForField","isCascadeDelete","manyToManyBatchLoader","RelationT","RelationU"],"sources":["../../src/relations/ReactiveManyToMany.ts"],"sourcesContent":["import { manyToManyBatchLoader } from \"../batchloaders/manyToManyBatchLoader.ts\";\nimport {\n type Entity,\n type EntityMetadata,\n type ManyToManyField,\n type ReadOnlyCollection,\n ensureNotDeleted,\n fail,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getMetadataForField,\n isLoaded,\n} from \"../index.ts\";\nimport { type IsLoadedCachable } from \"../IsLoadedCache.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { type MaybeReactedEntity, type Reacted, type ReactiveHint, convertToLoadHint } from \"../reactiveHints.ts\";\nimport { AbstractRelationImpl, isCascadeDelete } from \"./AbstractRelationImpl.ts\";\nimport { RelationT, RelationU } from \"./RelationSymbols.ts\";\n\n/**\n * A reactive, derived many-to-many collection.\n *\n * Similar to `ReactiveReference` but for collections--membership is calculated from a reactive\n * function and persisted to the underlying join table.\n */\nexport interface ReactiveManyToMany<T extends Entity, U extends Entity> extends ReadOnlyCollection<T, U> {\n load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<readonly U[]>;\n}\n\n/** Creates a `ReactiveManyToMany`. */\nexport function hasReactiveManyToMany<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n): ReactiveManyToMany<T, U> {\n return lazyField((entity: T, fieldName) => {\n const m2m = getMetadata(entity).allFields[fieldName] as ManyToManyField;\n return new ReactiveManyToManyImpl<T, U, H>(entity, m2m, hint, fn);\n });\n}\n\n/** Implements ReactiveManyToMany, initially a copy/paste of ReactiveReference but for m2m. */\nexport class ReactiveManyToManyImpl<T extends Entity, U extends Entity, H extends ReactiveHint<T>>\n extends AbstractRelationImpl<T, U[]>\n implements ReactiveManyToMany<T, U>, IsLoadedCachable\n{\n readonly #field: ManyToManyField;\n\n // Could be either the ref-loaded stored array, or full-loaded calculated array\n #loaded: U[] | undefined;\n // In ref-mode, we use our materialized FK value (which might be undefined)\n // If full-mode, we calculate the FK value from the subgraph\n #loadedMode: \"ref\" | \"full\" | undefined = undefined;\n // #isLoaded doesn't necessary care if we're ref-mode or full-mode, it's just\n // whether a caller can call `.get` and not have it blow up.\n #isLoaded: boolean | undefined = undefined;\n #isCached: boolean = false;\n #loadPromise: Promise<ReadonlyArray<U>> | undefined;\n\n constructor(\n entity: T,\n field: ManyToManyField,\n public reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n ) {\n super(entity);\n this.#field = field;\n (getInstanceData(entity).relations ??= {})[this.fieldName] = this;\n }\n\n async load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<ReadonlyArray<U>> {\n ensureNotDeleted(this.entity, \"pending\");\n const { loadHint } = this;\n\n if (!this.isLoaded || opts?.forceReload) {\n const { em } = this.entity;\n const maybeDirty = opts?.forceReload || getEmInternalApi(em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n\n if (maybeDirty) {\n this.#isCached = false;\n return (this.#loadPromise ??= em.populate(this.entity, { hint: loadHint, ...opts }).then(() => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"full\";\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#doGet(opts);\n }));\n } else {\n // Load from join table (existing materialized state)\n return (this.#loadPromise ??= this.#loadFromJoinTable().then((loaded) => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"ref\";\n this.#isLoaded = true;\n this.#loaded = loaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#filterDeleted(loaded, opts);\n }));\n }\n }\n return this.#doGet(opts);\n }\n\n get isLoaded(): boolean {\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // If a WIP mutation has marked our field as potentially dirty, we need to be \"full\" loaded\n const maybeDirty = getEmInternalApi(this.entity.em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n // If we're dirty, only being \"full\" loaded is good enough to recalc\n this.#loadedMode = \"full\";\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n this.#isCached = false;\n } else {\n // If we've had `.load` called before, assume we're still loaded\n this.#isLoaded = !!this.#loadedMode;\n }\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n this.#isLoaded = undefined;\n this.#isCached = false;\n }\n\n #doGet(opts?: { withDeleted?: boolean }): U[] {\n const { fn } = this;\n ensureNotDeleted(this.entity, \"pending\");\n // Fast pass if we've already calculated this (cache invalidation will happen on\n // any mutation via #resetIsLoaded)..\n if (this.#isCached) {\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n // Call isLoaded to probe the load hint, and get `#isLoaded` set, but still have\n // our `if` check the raw `#isLoaded` to know if we should eval-latest or return `loaded`.\n if (this.isLoaded && this.#loadedMode === \"full\") {\n const newValue = fn(this.entity as any) as unknown as U[];\n // Preserve deleted entities that were in the previous loaded value\n const previousDeleted = (this.#loaded ?? []).filter((e) => e.isDeletedEntity);\n for (const entity of previousDeleted) {\n if (!newValue.includes(entity)) newValue.push(entity);\n }\n if (!getEmInternalApi(this.entity.em).isValidating) {\n this.#syncJoinTableRows(newValue);\n }\n this.#loaded = newValue;\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else if (!!this.#loadedMode) {\n // We're either loadedMode=ref, or loadedMode=full (but not actually fully loaded),\n // but in theory loadedMode only gets set in `.load()`, so we should have #loaded\n // set to some value, even if it's not fully up-to-date.\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else {\n const noun = this.entity.isNewEntity ? \"derived\" : \"loaded\";\n throw new Error(`${this.entity}.${this.fieldName} has not been ${noun} yet`);\n }\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n\n get getWithDeleted(): U[] {\n return this.#doGet({ withDeleted: true });\n }\n\n get get(): U[] {\n return this.#doGet({ withDeleted: false });\n }\n\n set(): void {\n fail(`Cannot set ${this.entity}.${this.fieldName} ReactiveManyToMany directly.`);\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n setFromOpts(_others: U[]): void {\n throw new Error(`ReactiveManyToMany ${this.entity}.${this.fieldName} cannot be set via opts`);\n }\n\n maybeCascadeDelete(): void {\n if (this.#isCascadeDelete) {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n (jr.getOthers(this.columnName, this.entity) as U[]).forEach((e) => this.entity.em.delete(e));\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n const existing = await this.load({ withDeleted: true });\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n for (const entity of existing) jr.addRemove(this, this.entity, entity);\n this.#loaded = [];\n this.#isLoaded = false;\n }\n\n // Properties needed for JoinRows/ManyToManyCollection compatibility\n get meta(): EntityMetadata {\n return getMetadataForField(getMetadata(this.entity), this.fieldName);\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n get joinTableName(): string {\n return this.#field.joinTableName;\n }\n\n get columnName(): string {\n return this.#field.columnNames[0];\n }\n\n get otherColumnName(): string {\n return this.#field.columnNames[1];\n }\n\n get hasJoinTableId(): boolean {\n return this.#field.hasJoinTableId;\n }\n\n get otherFieldName(): string {\n return this.#field.otherFieldName;\n }\n\n get hasBeenSet(): boolean {\n return true;\n }\n\n get isPreloaded(): boolean {\n return false;\n }\n\n preload(): void {\n // No-op for now - could implement if needed\n }\n\n import(\n other: ReactiveManyToManyImpl<T, U, H>,\n _: unknown,\n mapEntities: (e: U[] | undefined) => U[] | undefined,\n ): void {\n this.#loaded = mapEntities(other.#loaded);\n this.#loadedMode = other.#loadedMode;\n this.#isLoaded = other.#isLoaded ?? false;\n // Don't set `#isCached b/c we're not registering ourselves with `isLoadedCache` yet; let\n // the first caller to `#doGet` do that if needed.\n }\n\n public toString(): string {\n return `ReactiveManyToMany(entity: ${this.entity}, fieldName: ${this.fieldName}, otherMeta: ${this.otherMeta.type})`;\n }\n\n get #isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.#field.fieldName);\n }\n\n async #loadFromJoinTable(): Promise<U[]> {\n const { em } = this.entity;\n const key = `${this.columnName}=${this.entity.id}`;\n // Use the existing m2m loader by creating a compatible collection-like object\n await manyToManyBatchLoader(em, this).load(key);\n return getEmInternalApi(em).joinRows(this).getOthers(this.columnName, this.entity) as U[];\n }\n\n // This is like calling `setField` but for a m2m relation...\n #syncJoinTableRows(newValue: U[]): void {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n const newSet = new Set(newValue);\n const oldSet = new Set(jr.getOthers(this.columnName, this.entity) as U[]);\n // Find entities to add (in new but not in old)\n for (const entity of newValue) {\n if (!oldSet.has(entity)) {\n jr.addNew(this, this.entity, entity);\n }\n }\n // Find entities to remove (in old but not in new)\n for (const entity of oldSet) {\n if (!newSet.has(entity)) {\n jr.addRemove(this, this.entity, entity);\n }\n }\n }\n\n #filterDeleted(entities: U[], opts?: { withDeleted?: boolean }): U[] {\n return opts?.withDeleted === true\n ? [...entities]\n : entities.filter((e) => !e.isDeletedEntity && !(e as any).isSoftDeletedEntity);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveManyToMany. */\nexport function isReactiveManyToMany(\n maybeReactiveMany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AE9C,MAAMS,2CAAAA,sBAAsB,IAAI,IAAI,CAAC,CAAC,KAAK,GAAG;EAC9C,OAAOf,sBAAAA,iBAAiB,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,UAAU,KAAK,YAAY,KAAK,MAAM;CACnF;CAGA,mBAAmB,UAAqB;EACtC,MAAM,KAAKA,sBAAAA,iBAAiB,KAAK,OAAO,EAAE,CAAC,CAAC,SAAS,IAAI;EACzD,MAAM,SAAS,IAAI,IAAI,QAAQ;EAC/B,MAAM,SAAS,IAAI,IAAI,GAAG,UAAU,KAAK,YAAY,KAAK,MAAM,CAAQ;EAExE,KAAK,MAAM,UAAU,UACnB,IAAI,CAAC,OAAO,IAAI,MAAM,GACpB,GAAG,OAAO,MAAM,KAAK,QAAQ,MAAM;EAIvC,KAAK,MAAM,UAAU,QACnB,IAAI,CAAC,OAAO,IAAI,MAAM,GACpB,GAAG,UAAU,MAAM,KAAK,QAAQ,MAAM;CAG5C;CAEA,eAAe,UAAe,MAAuC;EACnE,OAAO,MAAM,gBAAgB,OACzB,CAAC,GAAG,QAAQ,IACZ,SAAS,QAAQ,MAAM,CAAC,EAAE,mBAAmB,CAAE,EAAU,mBAAmB;CAClF;CAEA,CAACgB,kCAAAA,aAAgB;CACjB,CAACC,kCAAAA,aAAgB;AACnB;;AAGA,SAAgB,qBACd,yBACyD;CACzD,OAAO,mCAAmC;AAC5C"}
|
|
1
|
+
{"version":3,"file":"ReactiveManyToMany.cjs","names":["lazyField","getMetadata","AbstractRelationImpl","#field","getEmInternalApi","#isCached","#loadPromise","#loadedMode","#isLoaded","#doGet","#loadFromJoinTable","#loaded","#filterDeleted","isLoaded","#syncJoinTableRows","convertToLoadHint","#isCascadeDelete","getMetadataForField","isCascadeDelete","manyToManyBatchLoader","RelationT","RelationU"],"sources":["../../src/relations/ReactiveManyToMany.ts"],"sourcesContent":["import { manyToManyBatchLoader } from \"../batchloaders/manyToManyBatchLoader.ts\";\nimport {\n type Entity,\n type EntityMetadata,\n type ManyToManyField,\n type ReadOnlyCollection,\n ensureNotDeleted,\n fail,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getMetadataForField,\n isLoaded,\n} from \"../index.ts\";\nimport { type IsLoadedCachable } from \"../IsLoadedCache.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { type MaybeReactedEntity, type Reacted, type ReactiveHint, convertToLoadHint } from \"../reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"./AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"./isCascadeDelete.ts\";\nimport { RelationT, RelationU } from \"./RelationSymbols.ts\";\n\n/**\n * A reactive, derived many-to-many collection.\n *\n * Similar to `ReactiveReference` but for collections--membership is calculated from a reactive\n * function and persisted to the underlying join table.\n */\nexport interface ReactiveManyToMany<T extends Entity, U extends Entity> extends ReadOnlyCollection<T, U> {\n load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<readonly U[]>;\n}\n\n/** Creates a `ReactiveManyToMany`. */\nexport function hasReactiveManyToMany<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n): ReactiveManyToMany<T, U> {\n return lazyField((entity: T, fieldName) => {\n const m2m = getMetadata(entity).allFields[fieldName] as ManyToManyField;\n return new ReactiveManyToManyImpl<T, U, H>(entity, m2m, hint, fn);\n });\n}\n\n/** Implements ReactiveManyToMany, initially a copy/paste of ReactiveReference but for m2m. */\nexport class ReactiveManyToManyImpl<T extends Entity, U extends Entity, H extends ReactiveHint<T>>\n extends AbstractRelationImpl<T, U[]>\n implements ReactiveManyToMany<T, U>, IsLoadedCachable\n{\n readonly #field: ManyToManyField;\n\n // Could be either the ref-loaded stored array, or full-loaded calculated array\n #loaded: U[] | undefined;\n // In ref-mode, we use our materialized FK value (which might be undefined)\n // If full-mode, we calculate the FK value from the subgraph\n #loadedMode: \"ref\" | \"full\" | undefined = undefined;\n // #isLoaded doesn't necessary care if we're ref-mode or full-mode, it's just\n // whether a caller can call `.get` and not have it blow up.\n #isLoaded: boolean | undefined = undefined;\n #isCached: boolean = false;\n #loadPromise: Promise<ReadonlyArray<U>> | undefined;\n\n constructor(\n entity: T,\n field: ManyToManyField,\n public reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n ) {\n super(entity);\n this.#field = field;\n (getInstanceData(entity).relations ??= {})[this.fieldName] = this;\n }\n\n async load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<ReadonlyArray<U>> {\n ensureNotDeleted(this.entity, \"pending\");\n const { loadHint } = this;\n\n if (!this.isLoaded || opts?.forceReload) {\n const { em } = this.entity;\n const maybeDirty = opts?.forceReload || getEmInternalApi(em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n\n if (maybeDirty) {\n this.#isCached = false;\n return (this.#loadPromise ??= em.populate(this.entity, { hint: loadHint, ...opts }).then(() => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"full\";\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#doGet(opts);\n }));\n } else {\n // Load from join table (existing materialized state)\n return (this.#loadPromise ??= this.#loadFromJoinTable().then((loaded) => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"ref\";\n this.#isLoaded = true;\n this.#loaded = loaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#filterDeleted(loaded, opts);\n }));\n }\n }\n return this.#doGet(opts);\n }\n\n get isLoaded(): boolean {\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // If a WIP mutation has marked our field as potentially dirty, we need to be \"full\" loaded\n const maybeDirty = getEmInternalApi(this.entity.em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n // If we're dirty, only being \"full\" loaded is good enough to recalc\n this.#loadedMode = \"full\";\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n this.#isCached = false;\n } else {\n // If we've had `.load` called before, assume we're still loaded\n this.#isLoaded = !!this.#loadedMode;\n }\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n this.#isLoaded = undefined;\n this.#isCached = false;\n }\n\n #doGet(opts?: { withDeleted?: boolean }): U[] {\n const { fn } = this;\n ensureNotDeleted(this.entity, \"pending\");\n // Fast pass if we've already calculated this (cache invalidation will happen on\n // any mutation via #resetIsLoaded)..\n if (this.#isCached) {\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n // Call isLoaded to probe the load hint, and get `#isLoaded` set, but still have\n // our `if` check the raw `#isLoaded` to know if we should eval-latest or return `loaded`.\n if (this.isLoaded && this.#loadedMode === \"full\") {\n const newValue = fn(this.entity as any) as unknown as U[];\n // Preserve deleted entities that were in the previous loaded value\n const previousDeleted = (this.#loaded ?? []).filter((e) => e.isDeletedEntity);\n for (const entity of previousDeleted) {\n if (!newValue.includes(entity)) newValue.push(entity);\n }\n if (!getEmInternalApi(this.entity.em).isValidating) {\n this.#syncJoinTableRows(newValue);\n }\n this.#loaded = newValue;\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else if (!!this.#loadedMode) {\n // We're either loadedMode=ref, or loadedMode=full (but not actually fully loaded),\n // but in theory loadedMode only gets set in `.load()`, so we should have #loaded\n // set to some value, even if it's not fully up-to-date.\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else {\n const noun = this.entity.isNewEntity ? \"derived\" : \"loaded\";\n throw new Error(`${this.entity}.${this.fieldName} has not been ${noun} yet`);\n }\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n\n get getWithDeleted(): U[] {\n return this.#doGet({ withDeleted: true });\n }\n\n get get(): U[] {\n return this.#doGet({ withDeleted: false });\n }\n\n set(): void {\n fail(`Cannot set ${this.entity}.${this.fieldName} ReactiveManyToMany directly.`);\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n setFromOpts(_others: U[]): void {\n throw new Error(`ReactiveManyToMany ${this.entity}.${this.fieldName} cannot be set via opts`);\n }\n\n maybeCascadeDelete(): void {\n if (this.#isCascadeDelete) {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n (jr.getOthers(this.columnName, this.entity) as U[]).forEach((e) => this.entity.em.delete(e));\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n const existing = await this.load({ withDeleted: true });\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n for (const entity of existing) jr.addRemove(this, this.entity, entity);\n this.#loaded = [];\n this.#isLoaded = false;\n }\n\n // Properties needed for JoinRows/ManyToManyCollection compatibility\n get meta(): EntityMetadata {\n return getMetadataForField(getMetadata(this.entity), this.fieldName);\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n get joinTableName(): string {\n return this.#field.joinTableName;\n }\n\n get columnName(): string {\n return this.#field.columnNames[0];\n }\n\n get otherColumnName(): string {\n return this.#field.columnNames[1];\n }\n\n get hasJoinTableId(): boolean {\n return this.#field.hasJoinTableId;\n }\n\n get otherFieldName(): string {\n return this.#field.otherFieldName;\n }\n\n get hasBeenSet(): boolean {\n return true;\n }\n\n get isPreloaded(): boolean {\n return false;\n }\n\n preload(): void {\n // No-op for now - could implement if needed\n }\n\n import(\n other: ReactiveManyToManyImpl<T, U, H>,\n _: unknown,\n mapEntities: (e: U[] | undefined) => U[] | undefined,\n ): void {\n this.#loaded = mapEntities(other.#loaded);\n this.#loadedMode = other.#loadedMode;\n this.#isLoaded = other.#isLoaded ?? false;\n // Don't set `#isCached b/c we're not registering ourselves with `isLoadedCache` yet; let\n // the first caller to `#doGet` do that if needed.\n }\n\n public toString(): string {\n return `ReactiveManyToMany(entity: ${this.entity}, fieldName: ${this.fieldName}, otherMeta: ${this.otherMeta.type})`;\n }\n\n get #isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.#field.fieldName);\n }\n\n async #loadFromJoinTable(): Promise<U[]> {\n const { em } = this.entity;\n const key = `${this.columnName}=${this.entity.id}`;\n // Use the existing m2m loader by creating a compatible collection-like object\n await manyToManyBatchLoader(em, this).load(key);\n return getEmInternalApi(em).joinRows(this).getOthers(this.columnName, this.entity) as U[];\n }\n\n // This is like calling `setField` but for a m2m relation...\n #syncJoinTableRows(newValue: U[]): void {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n const newSet = new Set(newValue);\n const oldSet = new Set(jr.getOthers(this.columnName, this.entity) as U[]);\n // Find entities to add (in new but not in old)\n for (const entity of newValue) {\n if (!oldSet.has(entity)) {\n jr.addNew(this, this.entity, entity);\n }\n }\n // Find entities to remove (in old but not in new)\n for (const entity of oldSet) {\n if (!newSet.has(entity)) {\n jr.addRemove(this, this.entity, entity);\n }\n }\n }\n\n #filterDeleted(entities: U[], opts?: { withDeleted?: boolean }): U[] {\n return opts?.withDeleted === true\n ? [...entities]\n : entities.filter((e) => !e.isDeletedEntity && !(e as any).isSoftDeletedEntity);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveManyToMany. */\nexport function isReactiveManyToMany(\n maybeReactiveManyToMany: any,\n): maybeReactiveManyToMany is ReactiveManyToMany<any, any> {\n return maybeReactiveManyToMany instanceof ReactiveManyToManyImpl;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAgB,sBACd,MACA,IAC0B;CAC1B,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,MAAMC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,uBAAgC,QAAQ,KAAK,MAAM,EAAE;CAClE,CAAC;AACH;;AAGA,IAAa,yBAAb,cACUC,uCAAAA,qBAEV;CAiBW;CACC;CAjBV;CAGA;CAGA,cAA0C,KAAA;CAG1C,YA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B,IAAI,CAAC,OAAO,IAAI,MAAM,GACpB,GAAG,OAAO,MAAM,KAAK,QAAQ,MAAM;EAIvC,KAAK,MAAM,UAAU,QACnB,IAAI,CAAC,OAAO,IAAI,MAAM,GACpB,GAAG,UAAU,MAAM,KAAK,QAAQ,MAAM;CAG5C;CAEA,eAAe,UAAe,MAAuC;EACnE,OAAO,MAAM,gBAAgB,OACzB,CAAC,GAAG,QAAQ,IACZ,SAAS,QAAQ,MAAM,CAAC,EAAE,mBAAmB,CAAE,EAAU,mBAAmB;CAClF;CAEA,CAACgB,kCAAAA,aAAgB;CACjB,CAACC,kCAAAA,aAAgB;AACnB;;AAGA,SAAgB,qBACd,yBACyD;CACzD,OAAO,mCAAmC;AAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveManyToMany.d.cts","names":[],"sources":["../../src/relations/ReactiveManyToMany.ts"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ReactiveManyToMany.d.cts","names":[],"sources":["../../src/relations/ReactiveManyToMany.ts"],"mappings":";;;;;;;;;;;;;;;UA2BiB,mBAAmB,UAAU,QAAQ,UAAU,gBAAgB,mBAAmB,GAAG;EACpG,KAAK;IAAS;IAAuB;MAA0B,iBAAiB;;;iBAIlE,sBAAsB,UAAU,QAAQ,UAAU,cAAc,UAAU,aAAa,IACrG,MAAM,GACN,KAAK,QAAQ,QAAQ,GAAG,gBAAgB,mBAAmB,OAC1D,mBAAmB,GAAG;;cAQZ,uBAAuB,UAAU,QAAQ,UAAU,QAAQ,UAAU,aAAa,YACrF,qBAAqB,GAAG,gBACrB,mBAAmB,GAAG,IAAI;;EAkB5B,cAAc;UACb;EAJV,YACE,QAAQ,GACR,OAAO,iBACA,cAAc,GACb,KAAK,QAAQ,QAAQ,GAAG,gBAAgB,mBAAmB;EAO/D,KAAK;IAAS;IAAuB;MAA0B,QAAQ,cAAc;MAgCvF;EAiBJ;MAyCI,kBAAkB;MAIlB,OAAO;EAIX;MAII;EAKJ,YAAY,SAAS;EAIrB;EAOM,0BAA0B;MAS5B,QAAQ;MAIR;MAIA,aAAa;MAIb;MAIA;MAIA;MAIA;MAIA;MAIA;MAIA;EAIJ;EAIA,OACE,OAAO,uBAAuB,GAAG,GAAG,IACpC,YACA,cAAc,GAAG,oBAAoB;EAShC;GAyCN,YAAY;GACZ,YAAY;;;iBAIC,qBACd,+BACC,2BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveManyToMany.d.mts","names":[],"sources":["../../src/relations/ReactiveManyToMany.ts"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ReactiveManyToMany.d.mts","names":[],"sources":["../../src/relations/ReactiveManyToMany.ts"],"mappings":";;;;;;;;;;;;;;;UA2BiB,mBAAmB,UAAU,QAAQ,UAAU,gBAAgB,mBAAmB,GAAG;EACpG,KAAK;IAAS;IAAuB;MAA0B,iBAAiB;;;iBAIlE,sBAAsB,UAAU,QAAQ,UAAU,cAAc,UAAU,aAAa,IACrG,MAAM,GACN,KAAK,QAAQ,QAAQ,GAAG,gBAAgB,mBAAmB,OAC1D,mBAAmB,GAAG;;cAQZ,uBAAuB,UAAU,QAAQ,UAAU,QAAQ,UAAU,aAAa,YACrF,qBAAqB,GAAG,gBACrB,mBAAmB,GAAG,IAAI;;EAkB5B,cAAc;UACb;EAJV,YACE,QAAQ,GACR,OAAO,iBACA,cAAc,GACb,KAAK,QAAQ,QAAQ,GAAG,gBAAgB,mBAAmB;EAO/D,KAAK;IAAS;IAAuB;MAA0B,QAAQ,cAAc;MAgCvF;EAiBJ;MAyCI,kBAAkB;MAIlB,OAAO;EAIX;MAII;EAKJ,YAAY,SAAS;EAIrB;EAOM,0BAA0B;MAS5B,QAAQ;MAIR;MAIA,aAAa;MAIb;MAIA;MAIA;MAIA;MAIA;MAIA;MAIA;EAIJ;EAIA,OACE,OAAO,uBAAuB,GAAG,GAAG,IACpC,YACA,cAAc,GAAG,oBAAoB;EAShC;GAyCN,YAAY;GACZ,YAAY;;;iBAIC,qBACd,+BACC,2BAA2B"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractRelationImpl, isCascadeDelete } from "./AbstractRelationImpl.js";
|
|
1
|
+
import { AbstractRelationImpl } from "./AbstractRelationImpl.js";
|
|
3
2
|
import { RelationT, RelationU } from "./RelationSymbols.js";
|
|
4
|
-
import {
|
|
3
|
+
import { isCascadeDelete } from "./isCascadeDelete.js";
|
|
5
4
|
import "../IsLoadedCache.js";
|
|
6
|
-
import { getMetadata, getMetadataForField } from "../EntityMetadata.js";
|
|
7
5
|
import { convertToLoadHint } from "../reactiveHints.js";
|
|
8
6
|
import { isLoaded } from "../loadHints.js";
|
|
9
7
|
import { fail } from "../utils.js";
|
|
8
|
+
import { lazyField } from "../newEntity.js";
|
|
9
|
+
import { manyToManyBatchLoader } from "../batchloaders/manyToManyBatchLoader.js";
|
|
10
|
+
import { getMetadata, getMetadataForField } from "../EntityMetadata.js";
|
|
10
11
|
import { ensureNotDeleted } from "../index.js";
|
|
11
12
|
import { getEmInternalApi } from "../EntityManager.js";
|
|
12
13
|
import { getInstanceData } from "../BaseEntity.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveManyToMany.js","names":["#field","#isCached","#loadPromise","#loadedMode","#isLoaded","#doGet","#loadFromJoinTable","#loaded","#filterDeleted","#syncJoinTableRows","#isCascadeDelete"],"sources":["../../src/relations/ReactiveManyToMany.ts"],"sourcesContent":["import { manyToManyBatchLoader } from \"../batchloaders/manyToManyBatchLoader.ts\";\nimport {\n type Entity,\n type EntityMetadata,\n type ManyToManyField,\n type ReadOnlyCollection,\n ensureNotDeleted,\n fail,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getMetadataForField,\n isLoaded,\n} from \"../index.ts\";\nimport { type IsLoadedCachable } from \"../IsLoadedCache.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { type MaybeReactedEntity, type Reacted, type ReactiveHint, convertToLoadHint } from \"../reactiveHints.ts\";\nimport { AbstractRelationImpl, isCascadeDelete } from \"./AbstractRelationImpl.ts\";\nimport { RelationT, RelationU } from \"./RelationSymbols.ts\";\n\n/**\n * A reactive, derived many-to-many collection.\n *\n * Similar to `ReactiveReference` but for collections--membership is calculated from a reactive\n * function and persisted to the underlying join table.\n */\nexport interface ReactiveManyToMany<T extends Entity, U extends Entity> extends ReadOnlyCollection<T, U> {\n load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<readonly U[]>;\n}\n\n/** Creates a `ReactiveManyToMany`. */\nexport function hasReactiveManyToMany<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n): ReactiveManyToMany<T, U> {\n return lazyField((entity: T, fieldName) => {\n const m2m = getMetadata(entity).allFields[fieldName] as ManyToManyField;\n return new ReactiveManyToManyImpl<T, U, H>(entity, m2m, hint, fn);\n });\n}\n\n/** Implements ReactiveManyToMany, initially a copy/paste of ReactiveReference but for m2m. */\nexport class ReactiveManyToManyImpl<T extends Entity, U extends Entity, H extends ReactiveHint<T>>\n extends AbstractRelationImpl<T, U[]>\n implements ReactiveManyToMany<T, U>, IsLoadedCachable\n{\n readonly #field: ManyToManyField;\n\n // Could be either the ref-loaded stored array, or full-loaded calculated array\n #loaded: U[] | undefined;\n // In ref-mode, we use our materialized FK value (which might be undefined)\n // If full-mode, we calculate the FK value from the subgraph\n #loadedMode: \"ref\" | \"full\" | undefined = undefined;\n // #isLoaded doesn't necessary care if we're ref-mode or full-mode, it's just\n // whether a caller can call `.get` and not have it blow up.\n #isLoaded: boolean | undefined = undefined;\n #isCached: boolean = false;\n #loadPromise: Promise<ReadonlyArray<U>> | undefined;\n\n constructor(\n entity: T,\n field: ManyToManyField,\n public reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n ) {\n super(entity);\n this.#field = field;\n (getInstanceData(entity).relations ??= {})[this.fieldName] = this;\n }\n\n async load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<ReadonlyArray<U>> {\n ensureNotDeleted(this.entity, \"pending\");\n const { loadHint } = this;\n\n if (!this.isLoaded || opts?.forceReload) {\n const { em } = this.entity;\n const maybeDirty = opts?.forceReload || getEmInternalApi(em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n\n if (maybeDirty) {\n this.#isCached = false;\n return (this.#loadPromise ??= em.populate(this.entity, { hint: loadHint, ...opts }).then(() => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"full\";\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#doGet(opts);\n }));\n } else {\n // Load from join table (existing materialized state)\n return (this.#loadPromise ??= this.#loadFromJoinTable().then((loaded) => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"ref\";\n this.#isLoaded = true;\n this.#loaded = loaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#filterDeleted(loaded, opts);\n }));\n }\n }\n return this.#doGet(opts);\n }\n\n get isLoaded(): boolean {\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // If a WIP mutation has marked our field as potentially dirty, we need to be \"full\" loaded\n const maybeDirty = getEmInternalApi(this.entity.em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n // If we're dirty, only being \"full\" loaded is good enough to recalc\n this.#loadedMode = \"full\";\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n this.#isCached = false;\n } else {\n // If we've had `.load` called before, assume we're still loaded\n this.#isLoaded = !!this.#loadedMode;\n }\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n this.#isLoaded = undefined;\n this.#isCached = false;\n }\n\n #doGet(opts?: { withDeleted?: boolean }): U[] {\n const { fn } = this;\n ensureNotDeleted(this.entity, \"pending\");\n // Fast pass if we've already calculated this (cache invalidation will happen on\n // any mutation via #resetIsLoaded)..\n if (this.#isCached) {\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n // Call isLoaded to probe the load hint, and get `#isLoaded` set, but still have\n // our `if` check the raw `#isLoaded` to know if we should eval-latest or return `loaded`.\n if (this.isLoaded && this.#loadedMode === \"full\") {\n const newValue = fn(this.entity as any) as unknown as U[];\n // Preserve deleted entities that were in the previous loaded value\n const previousDeleted = (this.#loaded ?? []).filter((e) => e.isDeletedEntity);\n for (const entity of previousDeleted) {\n if (!newValue.includes(entity)) newValue.push(entity);\n }\n if (!getEmInternalApi(this.entity.em).isValidating) {\n this.#syncJoinTableRows(newValue);\n }\n this.#loaded = newValue;\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else if (!!this.#loadedMode) {\n // We're either loadedMode=ref, or loadedMode=full (but not actually fully loaded),\n // but in theory loadedMode only gets set in `.load()`, so we should have #loaded\n // set to some value, even if it's not fully up-to-date.\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else {\n const noun = this.entity.isNewEntity ? \"derived\" : \"loaded\";\n throw new Error(`${this.entity}.${this.fieldName} has not been ${noun} yet`);\n }\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n\n get getWithDeleted(): U[] {\n return this.#doGet({ withDeleted: true });\n }\n\n get get(): U[] {\n return this.#doGet({ withDeleted: false });\n }\n\n set(): void {\n fail(`Cannot set ${this.entity}.${this.fieldName} ReactiveManyToMany directly.`);\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n setFromOpts(_others: U[]): void {\n throw new Error(`ReactiveManyToMany ${this.entity}.${this.fieldName} cannot be set via opts`);\n }\n\n maybeCascadeDelete(): void {\n if (this.#isCascadeDelete) {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n (jr.getOthers(this.columnName, this.entity) as U[]).forEach((e) => this.entity.em.delete(e));\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n const existing = await this.load({ withDeleted: true });\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n for (const entity of existing) jr.addRemove(this, this.entity, entity);\n this.#loaded = [];\n this.#isLoaded = false;\n }\n\n // Properties needed for JoinRows/ManyToManyCollection compatibility\n get meta(): EntityMetadata {\n return getMetadataForField(getMetadata(this.entity), this.fieldName);\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n get joinTableName(): string {\n return this.#field.joinTableName;\n }\n\n get columnName(): string {\n return this.#field.columnNames[0];\n }\n\n get otherColumnName(): string {\n return this.#field.columnNames[1];\n }\n\n get hasJoinTableId(): boolean {\n return this.#field.hasJoinTableId;\n }\n\n get otherFieldName(): string {\n return this.#field.otherFieldName;\n }\n\n get hasBeenSet(): boolean {\n return true;\n }\n\n get isPreloaded(): boolean {\n return false;\n }\n\n preload(): void {\n // No-op for now - could implement if needed\n }\n\n import(\n other: ReactiveManyToManyImpl<T, U, H>,\n _: unknown,\n mapEntities: (e: U[] | undefined) => U[] | undefined,\n ): void {\n this.#loaded = mapEntities(other.#loaded);\n this.#loadedMode = other.#loadedMode;\n this.#isLoaded = other.#isLoaded ?? false;\n // Don't set `#isCached b/c we're not registering ourselves with `isLoadedCache` yet; let\n // the first caller to `#doGet` do that if needed.\n }\n\n public toString(): string {\n return `ReactiveManyToMany(entity: ${this.entity}, fieldName: ${this.fieldName}, otherMeta: ${this.otherMeta.type})`;\n }\n\n get #isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.#field.fieldName);\n }\n\n async #loadFromJoinTable(): Promise<U[]> {\n const { em } = this.entity;\n const key = `${this.columnName}=${this.entity.id}`;\n // Use the existing m2m loader by creating a compatible collection-like object\n await manyToManyBatchLoader(em, this).load(key);\n return getEmInternalApi(em).joinRows(this).getOthers(this.columnName, this.entity) as U[];\n }\n\n // This is like calling `setField` but for a m2m relation...\n #syncJoinTableRows(newValue: U[]): void {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n const newSet = new Set(newValue);\n const oldSet = new Set(jr.getOthers(this.columnName, this.entity) as U[]);\n // Find entities to add (in new but not in old)\n for (const entity of newValue) {\n if (!oldSet.has(entity)) {\n jr.addNew(this, this.entity, entity);\n }\n }\n // Find entities to remove (in old but not in new)\n for (const entity of oldSet) {\n if (!newSet.has(entity)) {\n jr.addRemove(this, this.entity, entity);\n }\n }\n }\n\n #filterDeleted(entities: U[], opts?: { withDeleted?: boolean }): U[] {\n return opts?.withDeleted === true\n ? [...entities]\n : entities.filter((e) => !e.isDeletedEntity && !(e as any).isSoftDeletedEntity);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveManyToMany. */\nexport function isReactiveManyToMany(\n maybeReactiveManyToMany: any,\n): maybeReactiveManyToMany is ReactiveManyToMany<any, any> {\n return maybeReactiveManyToMany instanceof ReactiveManyToManyImpl;\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAgB,sBACd,MACA,IAC0B;CAC1B,OAAO,WAAW,QAAW,cAAc;EACzC,MAAM,MAAM,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,uBAAgC,QAAQ,KAAK,MAAM,EAAE;CAClE,CAAC;AACH;;AAGA,IAAa,yBAAb,cACU,qBAEV;CAiBW;CACC;CAjBV;CAGA;CAGA,cAA0C,KAAA;CAG1C,YAAiC,KAAA;CACjC,YAAqB;CACrB;CAEA,YACE,QACA,OACA,cACA,IACA;EACA,MAAM,MAAM;EAHL,KAAA,eAAA;EACC,KAAA,KAAA;EAGR,KAAKA,SAAS;EACd,CAAC,gBAAgB,MAAM,CAAC,CAAC,cAAc,CAAC,EAAA,CAAG,KAAK,aAAa;CAC/D;CAEA,MAAM,KAAK,MAAoF;EAC7F,iBA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1
|
+
{"version":3,"file":"ReactiveManyToMany.js","names":["#field","#isCached","#loadPromise","#loadedMode","#isLoaded","#doGet","#loadFromJoinTable","#loaded","#filterDeleted","#syncJoinTableRows","#isCascadeDelete"],"sources":["../../src/relations/ReactiveManyToMany.ts"],"sourcesContent":["import { manyToManyBatchLoader } from \"../batchloaders/manyToManyBatchLoader.ts\";\nimport {\n type Entity,\n type EntityMetadata,\n type ManyToManyField,\n type ReadOnlyCollection,\n ensureNotDeleted,\n fail,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n getMetadataForField,\n isLoaded,\n} from \"../index.ts\";\nimport { type IsLoadedCachable } from \"../IsLoadedCache.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { type MaybeReactedEntity, type Reacted, type ReactiveHint, convertToLoadHint } from \"../reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"./AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"./isCascadeDelete.ts\";\nimport { RelationT, RelationU } from \"./RelationSymbols.ts\";\n\n/**\n * A reactive, derived many-to-many collection.\n *\n * Similar to `ReactiveReference` but for collections--membership is calculated from a reactive\n * function and persisted to the underlying join table.\n */\nexport interface ReactiveManyToMany<T extends Entity, U extends Entity> extends ReadOnlyCollection<T, U> {\n load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<readonly U[]>;\n}\n\n/** Creates a `ReactiveManyToMany`. */\nexport function hasReactiveManyToMany<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n): ReactiveManyToMany<T, U> {\n return lazyField((entity: T, fieldName) => {\n const m2m = getMetadata(entity).allFields[fieldName] as ManyToManyField;\n return new ReactiveManyToManyImpl<T, U, H>(entity, m2m, hint, fn);\n });\n}\n\n/** Implements ReactiveManyToMany, initially a copy/paste of ReactiveReference but for m2m. */\nexport class ReactiveManyToManyImpl<T extends Entity, U extends Entity, H extends ReactiveHint<T>>\n extends AbstractRelationImpl<T, U[]>\n implements ReactiveManyToMany<T, U>, IsLoadedCachable\n{\n readonly #field: ManyToManyField;\n\n // Could be either the ref-loaded stored array, or full-loaded calculated array\n #loaded: U[] | undefined;\n // In ref-mode, we use our materialized FK value (which might be undefined)\n // If full-mode, we calculate the FK value from the subgraph\n #loadedMode: \"ref\" | \"full\" | undefined = undefined;\n // #isLoaded doesn't necessary care if we're ref-mode or full-mode, it's just\n // whether a caller can call `.get` and not have it blow up.\n #isLoaded: boolean | undefined = undefined;\n #isCached: boolean = false;\n #loadPromise: Promise<ReadonlyArray<U>> | undefined;\n\n constructor(\n entity: T,\n field: ManyToManyField,\n public reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => readonly MaybeReactedEntity<U>[],\n ) {\n super(entity);\n this.#field = field;\n (getInstanceData(entity).relations ??= {})[this.fieldName] = this;\n }\n\n async load(opts?: { withDeleted?: boolean; forceReload?: boolean }): Promise<ReadonlyArray<U>> {\n ensureNotDeleted(this.entity, \"pending\");\n const { loadHint } = this;\n\n if (!this.isLoaded || opts?.forceReload) {\n const { em } = this.entity;\n const maybeDirty = opts?.forceReload || getEmInternalApi(em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n\n if (maybeDirty) {\n this.#isCached = false;\n return (this.#loadPromise ??= em.populate(this.entity, { hint: loadHint, ...opts }).then(() => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"full\";\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#doGet(opts);\n }));\n } else {\n // Load from join table (existing materialized state)\n return (this.#loadPromise ??= this.#loadFromJoinTable().then((loaded) => {\n this.#loadPromise = undefined;\n this.#loadedMode = \"ref\";\n this.#isLoaded = true;\n this.#loaded = loaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return this.#filterDeleted(loaded, opts);\n }));\n }\n }\n return this.#doGet(opts);\n }\n\n get isLoaded(): boolean {\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // If a WIP mutation has marked our field as potentially dirty, we need to be \"full\" loaded\n const maybeDirty = getEmInternalApi(this.entity.em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n // If we're dirty, only being \"full\" loaded is good enough to recalc\n this.#loadedMode = \"full\";\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n this.#isCached = false;\n } else {\n // If we've had `.load` called before, assume we're still loaded\n this.#isLoaded = !!this.#loadedMode;\n }\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n this.#isLoaded = undefined;\n this.#isCached = false;\n }\n\n #doGet(opts?: { withDeleted?: boolean }): U[] {\n const { fn } = this;\n ensureNotDeleted(this.entity, \"pending\");\n // Fast pass if we've already calculated this (cache invalidation will happen on\n // any mutation via #resetIsLoaded)..\n if (this.#isCached) {\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n // Call isLoaded to probe the load hint, and get `#isLoaded` set, but still have\n // our `if` check the raw `#isLoaded` to know if we should eval-latest or return `loaded`.\n if (this.isLoaded && this.#loadedMode === \"full\") {\n const newValue = fn(this.entity as any) as unknown as U[];\n // Preserve deleted entities that were in the previous loaded value\n const previousDeleted = (this.#loaded ?? []).filter((e) => e.isDeletedEntity);\n for (const entity of previousDeleted) {\n if (!newValue.includes(entity)) newValue.push(entity);\n }\n if (!getEmInternalApi(this.entity.em).isValidating) {\n this.#syncJoinTableRows(newValue);\n }\n this.#loaded = newValue;\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else if (!!this.#loadedMode) {\n // We're either loadedMode=ref, or loadedMode=full (but not actually fully loaded),\n // but in theory loadedMode only gets set in `.load()`, so we should have #loaded\n // set to some value, even if it's not fully up-to-date.\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else {\n const noun = this.entity.isNewEntity ? \"derived\" : \"loaded\";\n throw new Error(`${this.entity}.${this.fieldName} has not been ${noun} yet`);\n }\n return this.#filterDeleted(this.#loaded ?? [], opts) as U[];\n }\n\n get getWithDeleted(): U[] {\n return this.#doGet({ withDeleted: true });\n }\n\n get get(): U[] {\n return this.#doGet({ withDeleted: false });\n }\n\n set(): void {\n fail(`Cannot set ${this.entity}.${this.fieldName} ReactiveManyToMany directly.`);\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n setFromOpts(_others: U[]): void {\n throw new Error(`ReactiveManyToMany ${this.entity}.${this.fieldName} cannot be set via opts`);\n }\n\n maybeCascadeDelete(): void {\n if (this.#isCascadeDelete) {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n (jr.getOthers(this.columnName, this.entity) as U[]).forEach((e) => this.entity.em.delete(e));\n }\n }\n\n async cleanupOnEntityDeleted(): Promise<void> {\n const existing = await this.load({ withDeleted: true });\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n for (const entity of existing) jr.addRemove(this, this.entity, entity);\n this.#loaded = [];\n this.#isLoaded = false;\n }\n\n // Properties needed for JoinRows/ManyToManyCollection compatibility\n get meta(): EntityMetadata {\n return getMetadataForField(getMetadata(this.entity), this.fieldName);\n }\n\n get fieldName(): string {\n return this.#field.fieldName;\n }\n\n get otherMeta(): EntityMetadata {\n return this.#field.otherMetadata();\n }\n\n get joinTableName(): string {\n return this.#field.joinTableName;\n }\n\n get columnName(): string {\n return this.#field.columnNames[0];\n }\n\n get otherColumnName(): string {\n return this.#field.columnNames[1];\n }\n\n get hasJoinTableId(): boolean {\n return this.#field.hasJoinTableId;\n }\n\n get otherFieldName(): string {\n return this.#field.otherFieldName;\n }\n\n get hasBeenSet(): boolean {\n return true;\n }\n\n get isPreloaded(): boolean {\n return false;\n }\n\n preload(): void {\n // No-op for now - could implement if needed\n }\n\n import(\n other: ReactiveManyToManyImpl<T, U, H>,\n _: unknown,\n mapEntities: (e: U[] | undefined) => U[] | undefined,\n ): void {\n this.#loaded = mapEntities(other.#loaded);\n this.#loadedMode = other.#loadedMode;\n this.#isLoaded = other.#isLoaded ?? false;\n // Don't set `#isCached b/c we're not registering ourselves with `isLoadedCache` yet; let\n // the first caller to `#doGet` do that if needed.\n }\n\n public toString(): string {\n return `ReactiveManyToMany(entity: ${this.entity}, fieldName: ${this.fieldName}, otherMeta: ${this.otherMeta.type})`;\n }\n\n get #isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.#field.fieldName);\n }\n\n async #loadFromJoinTable(): Promise<U[]> {\n const { em } = this.entity;\n const key = `${this.columnName}=${this.entity.id}`;\n // Use the existing m2m loader by creating a compatible collection-like object\n await manyToManyBatchLoader(em, this).load(key);\n return getEmInternalApi(em).joinRows(this).getOthers(this.columnName, this.entity) as U[];\n }\n\n // This is like calling `setField` but for a m2m relation...\n #syncJoinTableRows(newValue: U[]): void {\n const jr = getEmInternalApi(this.entity.em).joinRows(this);\n const newSet = new Set(newValue);\n const oldSet = new Set(jr.getOthers(this.columnName, this.entity) as U[]);\n // Find entities to add (in new but not in old)\n for (const entity of newValue) {\n if (!oldSet.has(entity)) {\n jr.addNew(this, this.entity, entity);\n }\n }\n // Find entities to remove (in old but not in new)\n for (const entity of oldSet) {\n if (!newSet.has(entity)) {\n jr.addRemove(this, this.entity, entity);\n }\n }\n }\n\n #filterDeleted(entities: U[], opts?: { withDeleted?: boolean }): U[] {\n return opts?.withDeleted === true\n ? [...entities]\n : entities.filter((e) => !e.isDeletedEntity && !(e as any).isSoftDeletedEntity);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveManyToMany. */\nexport function isReactiveManyToMany(\n maybeReactiveManyToMany: any,\n): maybeReactiveManyToMany is ReactiveManyToMany<any, any> {\n return maybeReactiveManyToMany instanceof ReactiveManyToManyImpl;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,SAAgB,sBACd,MACA,IAC0B;CAC1B,OAAO,WA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E,KAAK,MAAM,UAAU,UACnB,IAAI,CAAC,OAAO,IAAI,MAAM,GACpB,GAAG,OAAO,MAAM,KAAK,QAAQ,MAAM;EAIvC,KAAK,MAAM,UAAU,QACnB,IAAI,CAAC,OAAO,IAAI,MAAM,GACpB,GAAG,UAAU,MAAM,KAAK,QAAQ,MAAM;CAG5C;CAEA,eAAe,UAAe,MAAuC;EACnE,OAAO,MAAM,gBAAgB,OACzB,CAAC,GAAG,QAAQ,IACZ,SAAS,QAAQ,MAAM,CAAC,EAAE,mBAAmB,CAAE,EAAU,mBAAmB;CAClF;CAEA,CAAC,aAAgB;CACjB,CAAC,aAAgB;AACnB;;AAGA,SAAgB,qBACd,yBACyD;CACzD,OAAO,mCAAmC;AAC5C"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
require("../JoinRows.cjs");
|
|
3
3
|
const require_relations_AbstractRelationImpl = require("./AbstractRelationImpl.cjs");
|
|
4
4
|
const require_relations_RelationSymbols = require("./RelationSymbols.cjs");
|
|
5
|
-
const require_batchloaders_manyToManyBatchLoader = require("../batchloaders/manyToManyBatchLoader.cjs");
|
|
6
5
|
require("../IsLoadedCache.cjs");
|
|
7
|
-
require("../
|
|
6
|
+
const require_newEntity = require("../newEntity.cjs");
|
|
7
|
+
const require_batchloaders_manyToManyBatchLoader = require("../batchloaders/manyToManyBatchLoader.cjs");
|
|
8
8
|
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
9
9
|
const require_index = require("../index.cjs");
|
|
10
10
|
const require_EntityManager = require("../EntityManager.cjs");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../JoinRows.js";
|
|
2
2
|
import { AbstractRelationImpl } from "./AbstractRelationImpl.js";
|
|
3
3
|
import { RelationT, RelationU } from "./RelationSymbols.js";
|
|
4
|
-
import { manyToManyBatchLoader } from "../batchloaders/manyToManyBatchLoader.js";
|
|
5
4
|
import "../IsLoadedCache.js";
|
|
6
|
-
import "../
|
|
5
|
+
import { lazyField } from "../newEntity.js";
|
|
6
|
+
import { manyToManyBatchLoader } from "../batchloaders/manyToManyBatchLoader.js";
|
|
7
7
|
import { getMetadata, getMetadataForField } from "../EntityMetadata.js";
|
|
8
8
|
import { ensureNotDeleted } from "../index.js";
|
|
9
9
|
import { getEmInternalApi } from "../EntityManager.js";
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_fields = require("../fields.cjs");
|
|
3
3
|
const require_relations_AbstractRelationImpl = require("./AbstractRelationImpl.cjs");
|
|
4
4
|
const require_relations_RelationSymbols = require("./RelationSymbols.cjs");
|
|
5
|
-
const
|
|
6
|
-
require("./Reference.cjs");
|
|
5
|
+
const require_relations_isCascadeDelete = require("./isCascadeDelete.cjs");
|
|
7
6
|
require("../IsLoadedCache.cjs");
|
|
7
|
+
const require_relations_ReferenceSymbols = require("./ReferenceSymbols.cjs");
|
|
8
8
|
const require_relations_ManyToOneReference = require("./ManyToOneReference.cjs");
|
|
9
|
-
|
|
10
|
-
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
11
|
-
const require_fields = require("../fields.cjs");
|
|
9
|
+
require("./Reference.cjs");
|
|
12
10
|
const require_reactiveHints = require("../reactiveHints.cjs");
|
|
13
11
|
const require_loadHints = require("../loadHints.cjs");
|
|
14
12
|
const require_utils = require("../utils.cjs");
|
|
13
|
+
const require_newEntity = require("../newEntity.cjs");
|
|
14
|
+
const require_keys = require("../keys.cjs");
|
|
15
|
+
const require_EntityMetadata = require("../EntityMetadata.cjs");
|
|
15
16
|
const require_index = require("../index.cjs");
|
|
16
17
|
const require_EntityManager = require("../EntityManager.cjs");
|
|
17
18
|
const require_Entity = require("../Entity.cjs");
|
|
@@ -252,7 +253,7 @@ var ReactiveReferenceImpl = class extends require_relations_AbstractRelationImpl
|
|
|
252
253
|
return entity;
|
|
253
254
|
}
|
|
254
255
|
get isCascadeDelete() {
|
|
255
|
-
return
|
|
256
|
+
return require_relations_isCascadeDelete.isCascadeDelete(this, this.#fieldName);
|
|
256
257
|
}
|
|
257
258
|
/**
|
|
258
259
|
* Looks for an entity in `EntityManager`, b/c we may have it in memory even if
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveReference.cjs","names":["lazyField","getMetadata","AbstractRelationImpl","#fieldName","#otherMeta","#state","getEmInternalApi","#loadPromise","#isLoaded","#isCached","isEntity","isLoaded","getField","sameEntity","maybeResolveReferenceToId","failNoId","failIfNewEntity","convertToLoadHint","toIdOf","deTagId","isCascadeDelete","RelationT","RelationU","ReferenceN","#rr","#loaded"],"sources":["../../src/relations/ReactiveReference.ts"],"sourcesContent":["import { type Entity } from \"../Entity.ts\";\nimport { type IdOf } from \"../EntityManager.ts\";\nimport { getField, setField } from \"../fields.ts\";\nimport {\n type EntityMetadata,\n type ManyToOneField,\n type TaggedId,\n deTagId,\n ensureNotDeleted,\n fail,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n isEntity,\n isLoaded,\n maybeResolveReferenceToId,\n sameEntity,\n toIdOf,\n} from \"../index.ts\";\nimport { type IsLoadedCachable } from \"../IsLoadedCache.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { type MaybeReactedEntity, type Reacted, type ReactiveHint, convertToLoadHint } from \"../reactiveHints.ts\";\nimport { AbstractRelationImpl, isCascadeDelete } from \"./AbstractRelationImpl.ts\";\nimport { failIfNewEntity, failNoId } from \"./ManyToOneReference.ts\";\nimport { type Reference } from \"./Reference.ts\";\nimport { ReferenceN } from \"./ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"./RelationSymbols.ts\";\n\nexport interface ReactiveReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<\n T,\n U,\n N\n> {\n isLoaded: boolean;\n isSet: boolean;\n\n load(opts?: { withDeleted?: boolean; forceReload?: true }): Promise<U | N>;\n\n /**\n * Returns the as-of-last-flush previously-calculated entity.\n *\n * This is useful if you have to purposefully avoid using the lambda to calc the latest entity,\n * i.e. if you're in a test and want to watch a calculated entity change from some dummy entity\n * to the new derived entity.\n * */\n fieldValue: U | N;\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 idUntagged: string;\n\n idUntaggedIfSet: string | undefined;\n}\n\nexport function hasReactiveReference<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U>,\n): ReactiveReference<T, U, never>;\nexport function hasReactiveReference<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U> | undefined,\n): ReactiveReference<T, U, undefined>;\n/** Creates a `ReactiveReference`. */\nexport function hasReactiveReference<\n T extends Entity,\n U extends Entity,\n const H extends ReactiveHint<T>,\n N extends never | undefined,\n>(hint: H, fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U> | N): ReactiveReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const m2o = getMetadata(entity).allFields[fieldName] as ManyToOneField;\n return new ReactiveReferenceImpl<T, U, H, N>(entity, m2o, hint, fn);\n });\n}\n\n/**\n * Implements ReactiveReferences.\n *\n * This is a bit trickier than ReactiveFields, because we have to differentiate our loaded\n * between:\n *\n * - our load hint is loaded, and we can directly calculate the referenced entity, or\n * - we've fetched the calculated/stored entity from the database, but not purposefully\n * not re-calculating it (which would require fetching the load hint, which might be\n * expensive, and defeat the point of having our field materialized in the database)\n *\n * Further, want to support all of:\n *\n * - When loaded & `.get` has been called, we cache the value\n *\n * - If a WIP mutation happens, we invalidate `.get` *but* if we check `.isLoaded`,\n * we can return the live/updated value, without an `await`.\n *\n * - If a WIP mutation happens, we invalidate `.isLoaded`, and if we're *no longer loaded*,\n * we want to keep returning the stale value (as asserted by the tests), but the next\n * `load` / `populate` should load the graph & recalculate the value.\n */\nexport class ReactiveReferenceImpl<\n T extends Entity,\n U extends Entity,\n H extends ReactiveHint<T>,\n N extends never | undefined,\n>\n extends AbstractRelationImpl<T, U>\n implements ReactiveReference<T, U, N>, IsLoadedCachable\n{\n readonly #fieldName: keyof T & string;\n readonly #otherMeta: EntityMetadata;\n #state: RRState<U, N>;\n // #isLoaded doesn't necessary care if we're ref-mode or full-mode, it's just\n // whether a caller can call `.get` and not have it blow up.\n #isLoaded: boolean | undefined = undefined;\n #isCached: boolean = false;\n #loadPromise: Promise<U | N> | undefined;\n\n constructor(\n entity: T,\n field: ManyToOneField,\n public reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U> | N,\n ) {\n super(entity);\n // Minimizing changes until the other PR lands...\n this.#fieldName = field.fieldName as keyof T & string;\n this.#otherMeta = field.otherMetadata();\n this.#state = new RRUnloadedState<U, N>(this);\n // We can be initialized with [entity | id | undefined], and if it's entity or id, then setImpl\n // will set loaded appropriately; but if we're initialized undefined, then mark loaded here\n if (entity.isNewEntity) {\n // const isLoaded = isEntity(this.current()) ? true : undefined;\n }\n // If the property transformer is not enabled, then the RR will not be in the relations map because they are\n // defined in the implementation file and not the codegen file. So we should insert ourselves regardless.\n (getInstanceData(entity).relations ??= {})[field.fieldName] = this;\n }\n\n async load(opts?: { withDeleted?: boolean; forceReload?: true }): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const { loadHint } = this;\n if (!this.isLoaded || opts?.forceReload) {\n const { em } = this.entity;\n // Just because we're not loaded, doesn't mean we necessarily need to load our full hint.\n // We prefer to load only our previously-calculated/materialized value, and only load the\n // full load hint if we need recalculated.\n const maybeDirty = opts?.forceReload || getEmInternalApi(em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n return (this.#loadPromise ??= em\n .populate(this.entity, { hint: loadHint, ...opts })\n .then(() => {\n this.#state = this.#state.enterRecalcMode(this);\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // Go through `this.get` so that `setField` is called to set our latest value\n this.#isCached = false;\n return this.doGet(opts);\n })\n .finally(() => {\n this.#loadPromise = undefined;\n }));\n } else {\n // If we don't need a full recalc, just make sure we have the entity in memory\n // ...ideally we would check `isSet` and whether the key was in the `instanceData`\n const current = this.current();\n if (isEntity(current) || current === undefined) {\n this.#state = new RRRefState<U, N>(this, current as U | N | undefined);\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return current as U | N;\n } else {\n return (this.#loadPromise ??= em\n .load(this.#otherMeta.cstr, current)\n .then((loaded) => {\n this.#state = new RRRefState<U, N>(this, loaded);\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return loaded;\n })\n .finally(() => {\n this.#loadPromise = undefined;\n }));\n }\n }\n }\n // The ReactiveField.load() always sets `#isCached = false`, but our assertion is that our\n // IsLoadedCache/resetIsLoaded infra is good enough to \"see all invalidating mutations\",\n // so we don't need this explicit reset.\n // this.#isCached = false;\n return this.doGet(opts);\n }\n\n get isLoaded(): boolean {\n // If we've cached an isLoaded value, just use that, see https://github.com/joist-orm/joist-orm/issues/1166\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // If a WIP mutation has marked our field as potentially dirty, we need to be \"full\" loaded\n const maybeDirty = getEmInternalApi(this.entity.em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n // If we're dirty, only being \"full\" loaded is good enough to recalc\n this.#state = this.#state.enterRecalcMode(this);\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n this.#isCached = false;\n } else {\n // If we've had `.load` called before, assume we're still loaded\n this.#isLoaded = this.#state.canReturnValue;\n }\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n this.#isLoaded = undefined;\n this.#isCached = false;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n const { fn } = this;\n ensureNotDeleted(this.entity, \"pending\");\n // Fast pass if we've already calculated this (cache invalidation will happen on\n // any mutation via #resetIsLoaded)..\n if (this.#isCached) {\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n // Call isLoaded to probe the load hint, and get `#isLoaded` set, but still have\n // our `if` check the raw `#isLoaded` to know if we should eval-latest or return `loaded`.\n if (this.isLoaded && this.#state.kind === \"full\") {\n const newValue = this.filterDeleted(fn(this.entity as any) as any, opts);\n // It's cheap to set this every time we're called, i.e. even if it's not the\n // official \"being called during em.flush\" update (...unless we're accessing it\n // during the validate phase of `em.flush`, then skip it to avoid tripping up\n // the \"cannot change entities during flush\" logic.)\n if (!getEmInternalApi(this.entity.em).isValidating) {\n this.setImpl(newValue);\n }\n this.#state = new RRFullState<U, N>(this, newValue);\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else if (this.#state.canReturnValue) {\n // We're either in ref mode, or in full mode but not actually fully loaded,\n // but in theory those states only get set after `.load()` / `.preload()` / import,\n // so we should have some stored value, even if it's not fully up-to-date.\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else {\n const noun = this.entity.isNewEntity ? \"derived\" : \"loaded\";\n throw new Error(`${this.entity}.${this.fieldName} has not been ${noun} yet`);\n }\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n get fieldValue(): U | N {\n return getField(this.entity, this.fieldName);\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 set(_: U | N): void {\n fail(`Cannot set ${this.entity}.${this.fieldName} ReactiveReference directly.`);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n // Internal method used by OneToManyCollection\n setImpl(entity: U | N): void {\n ensureNotDeleted(this.entity, \"pending\");\n if (sameEntity(entity, this.current({ withDeleted: true }))) {\n return;\n }\n // Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself\n setField(this.entity, this.fieldName, isEntity(entity) ? (entity.idTaggedMaybe ?? entity) : entity);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.#state = new RRRefState<U, N>(this, this.maybeFindEntity());\n this.#isLoaded = true;\n this.#isCached = true;\n }\n\n private unload(): void {\n this.#state = new RRUnloadedState<U, N>(this);\n this.#isLoaded = false;\n this.#isCached = false;\n this.#loadPromise = undefined;\n }\n\n import(other: ReactiveReferenceImpl<T, U, H, N>, findEntity: (e: U) => U): void {\n this.#state = other.#state.import(this, findEntity);\n this.#isLoaded = true;\n this.#isCached = true;\n }\n\n /** Returns the tagged id of the current value. */\n get idTaggedMaybe(): TaggedId | N {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as TaggedId | N;\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n // private impl\n\n /** Returns the id of the current value. */\n private get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return toIdOf(this.otherMeta, this.idTaggedMaybe);\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n setFromOpts(_: U | IdOf<U> | N): void {\n throw new Error(`ReactiveReference ${this.entity}.${this.fieldName} cannot be set via opts`);\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 setField(this.entity, this.fieldName, undefined);\n this.#state = new RRRefState<U, N>(this, undefined as N);\n this.#isLoaded = false;\n this.#isCached = false;\n this.#loadPromise = undefined;\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 | string | 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 get fieldName(): string {\n return this.#fieldName;\n }\n\n public get otherMeta(): EntityMetadata<U> {\n return (getMetadata(this.entity).allFields[this.#fieldName] as ManyToOneField).otherMetadata();\n }\n\n public get hasBeenSet(): boolean {\n return true;\n }\n\n public toString(): string {\n return `ReactiveReference(entity: ${this.entity}, hint: ${this.loadHint}, fieldName: ${this.fieldName}, otherMeta: {\n this.otherMeta.type\n }, id: ${this.id})`;\n }\n\n /**\n * Removes pending-hard-delete (but not soft-deleted), unless explicitly asked for.\n *\n * Note that we leave soft-deleted entities b/c the call signature of a `book.author.get`\n * very likely does not expect a soft-deleted entity to result in `undefined`.\n *\n * (Contrasted with `author.books.get` which is more intuitive to have soft-deleted\n * entities filtered out, i.e. it doesn't fundamentally change the return type.)\n */\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n if (entity && (!opts || !opts.withDeleted) && entity.isDeletedEntity) {\n return undefined!;\n }\n return entity;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.#fieldName);\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 | N {\n // Check this.loaded first b/c a new entity won't have an id yet\n if (this.#state.canReturnValue) {\n const loaded = this.#state.doGet();\n if (loaded !== undefined) {\n return loaded;\n }\n }\n const { idTaggedMaybe } = this;\n return idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U | N) : (undefined as N);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveReference. */\nexport function isReactiveReference(maybeReactiveRef: any): maybeReactiveRef is ReactiveReference<any, any, any> {\n return maybeReactiveRef instanceof ReactiveReferenceImpl;\n}\n\ninterface RRState<U extends Entity, N extends never | undefined> {\n readonly kind: \"unloaded\" | \"ref\" | \"full\";\n readonly canReturnValue: boolean;\n doGet(): U | N | undefined;\n /**\n * Switches from \"materialized ref value\" semantics to \"recalc from reactive graph when available\" semantics.\n *\n * This is synchronous because it does not mean the load hint is fully loaded yet. It only means this\n * reference should now behave as recalc-capable: if `isLoaded(loadHint)` later reports true, `doGet`\n * will recalculate from `fn(...)`; otherwise we keep returning the last known/stale value until `load()`\n * populates the graph.\n */\n enterRecalcMode(target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N>;\n import(target: ReactiveReferenceImpl<any, any, any, any>, findEntity: (e: U) => U): RRState<U, N>;\n}\n\nclass RRUnloadedState<U extends Entity, N extends never | undefined> implements RRState<U, N> {\n readonly kind = \"unloaded\";\n readonly canReturnValue = false;\n #rr: ReactiveReferenceImpl<any, any, any, any>;\n\n constructor(rr: ReactiveReferenceImpl<any, any, any, any>) {\n this.#rr = rr;\n }\n\n doGet(): U | N | undefined {\n throw new Error(`${this.#rr.entity}.${this.#rr.fieldName} was not loaded`);\n }\n\n enterRecalcMode(target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N> {\n return new RRFullState<U, N>(target, undefined);\n }\n\n import(target: ReactiveReferenceImpl<any, any, any, any>, _findEntity: (e: U) => U): RRState<U, N> {\n return new RRUnloadedState<U, N>(target);\n }\n}\n\nclass RRRefState<U extends Entity, N extends never | undefined> implements RRState<U, N> {\n readonly kind = \"ref\";\n readonly canReturnValue = true;\n #loaded: U | N | undefined;\n\n constructor(_rr: ReactiveReferenceImpl<any, any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n }\n\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n\n enterRecalcMode(target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N> {\n return new RRFullState<U, N>(target, this.#loaded);\n }\n\n import(target: ReactiveReferenceImpl<any, any, any, any>, findEntity: (e: U) => U): RRState<U, N> {\n return new RRRefState<U, N>(target, mapReactiveReferenceEntity(this.#loaded, findEntity));\n }\n}\n\nclass RRFullState<U extends Entity, N extends never | undefined> implements RRState<U, N> {\n readonly kind = \"full\";\n readonly canReturnValue = true;\n #loaded: U | N | undefined;\n\n constructor(_rr: ReactiveReferenceImpl<any, any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n }\n\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n\n enterRecalcMode(_target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N> {\n return this;\n }\n\n import(target: ReactiveReferenceImpl<any, any, any, any>, findEntity: (e: U) => U): RRState<U, N> {\n return new RRRefState<U, N>(target, mapReactiveReferenceEntity(this.#loaded, findEntity));\n }\n}\n\nfunction mapReactiveReferenceEntity<U extends Entity, N extends never | undefined>(\n entity: U | N | undefined,\n findEntity: (e: U) => U,\n): U | N | undefined {\n return isEntity(entity) ? findEntity(entity) : entity;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmEA,SAAgB,qBAKd,MAAS,IAAsF;CAC/F,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,MAAMC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,sBAAkC,QAAQ,KAAK,MAAM,EAAE;CACpE,CAAC;AACH;;;;;;;;;;;;;;;;;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uE;EACrF,OAAO;CACT;CAEA,OAAO,QAAmD,YAAwC;EAChG,OAAO,IAAI,WAAiB,QAAQ,2BAA2B,KAAKA,SAAS,UAAU,CAAC;CAC1F;AACF;AAEA,SAAS,2BACP,QACA,YACmB;CACnB,OAAOf,eAAAA,SAAS,MAAM,IAAI,WAAW,MAAM,IAAI;AACjD"}
|
|
1
|
+
{"version":3,"file":"ReactiveReference.cjs","names":["lazyField","getMetadata","AbstractRelationImpl","#fieldName","#otherMeta","#state","getEmInternalApi","#loadPromise","#isLoaded","#isCached","isEntity","isLoaded","getField","sameEntity","maybeResolveReferenceToId","failNoId","failIfNewEntity","convertToLoadHint","toIdOf","deTagId","isCascadeDelete","RelationT","RelationU","ReferenceN","#rr","#loaded"],"sources":["../../src/relations/ReactiveReference.ts"],"sourcesContent":["import { type Entity } from \"../Entity.ts\";\nimport { type IdOf } from \"../EntityManager.ts\";\nimport { getField, setField } from \"../fields.ts\";\nimport {\n type EntityMetadata,\n type ManyToOneField,\n type TaggedId,\n deTagId,\n ensureNotDeleted,\n fail,\n getEmInternalApi,\n getInstanceData,\n getMetadata,\n isEntity,\n isLoaded,\n maybeResolveReferenceToId,\n sameEntity,\n toIdOf,\n} from \"../index.ts\";\nimport { type IsLoadedCachable } from \"../IsLoadedCache.ts\";\nimport { lazyField } from \"../newEntity.ts\";\nimport { type MaybeReactedEntity, type Reacted, type ReactiveHint, convertToLoadHint } from \"../reactiveHints.ts\";\nimport { AbstractRelationImpl } from \"./AbstractRelationImpl.ts\";\nimport { isCascadeDelete } from \"./isCascadeDelete.ts\";\nimport { failIfNewEntity, failNoId } from \"./ManyToOneReference.ts\";\nimport { type Reference } from \"./Reference.ts\";\nimport { ReferenceN } from \"./ReferenceSymbols.ts\";\nimport { RelationT, RelationU } from \"./RelationSymbols.ts\";\n\nexport interface ReactiveReference<T extends Entity, U extends Entity, N extends never | undefined> extends Reference<\n T,\n U,\n N\n> {\n isLoaded: boolean;\n isSet: boolean;\n\n load(opts?: { withDeleted?: boolean; forceReload?: true }): Promise<U | N>;\n\n /**\n * Returns the as-of-last-flush previously-calculated entity.\n *\n * This is useful if you have to purposefully avoid using the lambda to calc the latest entity,\n * i.e. if you're in a test and want to watch a calculated entity change from some dummy entity\n * to the new derived entity.\n * */\n fieldValue: U | N;\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 idUntagged: string;\n\n idUntaggedIfSet: string | undefined;\n}\n\nexport function hasReactiveReference<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U>,\n): ReactiveReference<T, U, never>;\nexport function hasReactiveReference<T extends Entity, U extends Entity, const H extends ReactiveHint<T>>(\n hint: H,\n fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U> | undefined,\n): ReactiveReference<T, U, undefined>;\n/** Creates a `ReactiveReference`. */\nexport function hasReactiveReference<\n T extends Entity,\n U extends Entity,\n const H extends ReactiveHint<T>,\n N extends never | undefined,\n>(hint: H, fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U> | N): ReactiveReference<T, U, N> {\n return lazyField((entity: T, fieldName) => {\n const m2o = getMetadata(entity).allFields[fieldName] as ManyToOneField;\n return new ReactiveReferenceImpl<T, U, H, N>(entity, m2o, hint, fn);\n });\n}\n\n/**\n * Implements ReactiveReferences.\n *\n * This is a bit trickier than ReactiveFields, because we have to differentiate our loaded\n * between:\n *\n * - our load hint is loaded, and we can directly calculate the referenced entity, or\n * - we've fetched the calculated/stored entity from the database, but not purposefully\n * not re-calculating it (which would require fetching the load hint, which might be\n * expensive, and defeat the point of having our field materialized in the database)\n *\n * Further, want to support all of:\n *\n * - When loaded & `.get` has been called, we cache the value\n *\n * - If a WIP mutation happens, we invalidate `.get` *but* if we check `.isLoaded`,\n * we can return the live/updated value, without an `await`.\n *\n * - If a WIP mutation happens, we invalidate `.isLoaded`, and if we're *no longer loaded*,\n * we want to keep returning the stale value (as asserted by the tests), but the next\n * `load` / `populate` should load the graph & recalculate the value.\n */\nexport class ReactiveReferenceImpl<\n T extends Entity,\n U extends Entity,\n H extends ReactiveHint<T>,\n N extends never | undefined,\n>\n extends AbstractRelationImpl<T, U>\n implements ReactiveReference<T, U, N>, IsLoadedCachable\n{\n readonly #fieldName: keyof T & string;\n readonly #otherMeta: EntityMetadata;\n #state: RRState<U, N>;\n // #isLoaded doesn't necessary care if we're ref-mode or full-mode, it's just\n // whether a caller can call `.get` and not have it blow up.\n #isLoaded: boolean | undefined = undefined;\n #isCached: boolean = false;\n #loadPromise: Promise<U | N> | undefined;\n\n constructor(\n entity: T,\n field: ManyToOneField,\n public reactiveHint: H,\n private fn: (entity: Reacted<T, H>) => MaybeReactedEntity<U> | N,\n ) {\n super(entity);\n // Minimizing changes until the other PR lands...\n this.#fieldName = field.fieldName as keyof T & string;\n this.#otherMeta = field.otherMetadata();\n this.#state = new RRUnloadedState<U, N>(this);\n // We can be initialized with [entity | id | undefined], and if it's entity or id, then setImpl\n // will set loaded appropriately; but if we're initialized undefined, then mark loaded here\n if (entity.isNewEntity) {\n // const isLoaded = isEntity(this.current()) ? true : undefined;\n }\n // If the property transformer is not enabled, then the RR will not be in the relations map because they are\n // defined in the implementation file and not the codegen file. So we should insert ourselves regardless.\n (getInstanceData(entity).relations ??= {})[field.fieldName] = this;\n }\n\n async load(opts?: { withDeleted?: boolean; forceReload?: true }): Promise<U | N> {\n ensureNotDeleted(this.entity, \"pending\");\n const { loadHint } = this;\n if (!this.isLoaded || opts?.forceReload) {\n const { em } = this.entity;\n // Just because we're not loaded, doesn't mean we necessarily need to load our full hint.\n // We prefer to load only our previously-calculated/materialized value, and only load the\n // full load hint if we need recalculated.\n const maybeDirty = opts?.forceReload || getEmInternalApi(em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n return (this.#loadPromise ??= em\n .populate(this.entity, { hint: loadHint, ...opts })\n .then(() => {\n this.#state = this.#state.enterRecalcMode(this);\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // Go through `this.get` so that `setField` is called to set our latest value\n this.#isCached = false;\n return this.doGet(opts);\n })\n .finally(() => {\n this.#loadPromise = undefined;\n }));\n } else {\n // If we don't need a full recalc, just make sure we have the entity in memory\n // ...ideally we would check `isSet` and whether the key was in the `instanceData`\n const current = this.current();\n if (isEntity(current) || current === undefined) {\n this.#state = new RRRefState<U, N>(this, current as U | N | undefined);\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return current as U | N;\n } else {\n return (this.#loadPromise ??= em\n .load(this.#otherMeta.cstr, current)\n .then((loaded) => {\n this.#state = new RRRefState<U, N>(this, loaded);\n this.#isLoaded = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n return loaded;\n })\n .finally(() => {\n this.#loadPromise = undefined;\n }));\n }\n }\n }\n // The ReactiveField.load() always sets `#isCached = false`, but our assertion is that our\n // IsLoadedCache/resetIsLoaded infra is good enough to \"see all invalidating mutations\",\n // so we don't need this explicit reset.\n // this.#isCached = false;\n return this.doGet(opts);\n }\n\n get isLoaded(): boolean {\n // If we've cached an isLoaded value, just use that, see https://github.com/joist-orm/joist-orm/issues/1166\n if (this.#isLoaded !== undefined) return this.#isLoaded;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n // If a WIP mutation has marked our field as potentially dirty, we need to be \"full\" loaded\n const maybeDirty = getEmInternalApi(this.entity.em).rm.isMaybePendingRecalc(this.entity, this.fieldName);\n if (maybeDirty) {\n // If we're dirty, only being \"full\" loaded is good enough to recalc\n this.#state = this.#state.enterRecalcMode(this);\n this.#isLoaded = isLoaded(this.entity, this.loadHint);\n this.#isCached = false;\n } else {\n // If we've had `.load` called before, assume we're still loaded\n this.#isLoaded = this.#state.canReturnValue;\n }\n return this.#isLoaded;\n }\n\n resetIsLoaded(): void {\n this.#isLoaded = undefined;\n this.#isCached = false;\n }\n\n private doGet(opts?: { withDeleted?: boolean }): U | N {\n const { fn } = this;\n ensureNotDeleted(this.entity, \"pending\");\n // Fast pass if we've already calculated this (cache invalidation will happen on\n // any mutation via #resetIsLoaded)..\n if (this.#isCached) {\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n // Call isLoaded to probe the load hint, and get `#isLoaded` set, but still have\n // our `if` check the raw `#isLoaded` to know if we should eval-latest or return `loaded`.\n if (this.isLoaded && this.#state.kind === \"full\") {\n const newValue = this.filterDeleted(fn(this.entity as any) as any, opts);\n // It's cheap to set this every time we're called, i.e. even if it's not the\n // official \"being called during em.flush\" update (...unless we're accessing it\n // during the validate phase of `em.flush`, then skip it to avoid tripping up\n // the \"cannot change entities during flush\" logic.)\n if (!getEmInternalApi(this.entity.em).isValidating) {\n this.setImpl(newValue);\n }\n this.#state = new RRFullState<U, N>(this, newValue);\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else if (this.#state.canReturnValue) {\n // We're either in ref mode, or in full mode but not actually fully loaded,\n // but in theory those states only get set after `.load()` / `.preload()` / import,\n // so we should have some stored value, even if it's not fully up-to-date.\n this.#isCached = true;\n getEmInternalApi(this.entity.em).isLoadedCache.add(this);\n } else {\n const noun = this.entity.isNewEntity ? \"derived\" : \"loaded\";\n throw new Error(`${this.entity}.${this.fieldName} has not been ${noun} yet`);\n }\n return this.filterDeleted(this.#state.doGet() as U | N, opts);\n }\n\n get fieldValue(): U | N {\n return getField(this.entity, this.fieldName);\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 set(_: U | N): void {\n fail(`Cannot set ${this.entity}.${this.fieldName} ReactiveReference directly.`);\n }\n\n get isSet(): boolean {\n return this.current() !== undefined;\n }\n\n // Internal method used by OneToManyCollection\n setImpl(entity: U | N): void {\n ensureNotDeleted(this.entity, \"pending\");\n if (sameEntity(entity, this.current({ withDeleted: true }))) {\n return;\n }\n // Prefer to keep the id in our data hash, but if this is a new entity w/o an id, use the entity itself\n setField(this.entity, this.fieldName, isEntity(entity) ? (entity.idTaggedMaybe ?? entity) : entity);\n }\n\n get isPreloaded(): boolean {\n return !!this.maybeFindEntity();\n }\n\n preload(): void {\n this.#state = new RRRefState<U, N>(this, this.maybeFindEntity());\n this.#isLoaded = true;\n this.#isCached = true;\n }\n\n private unload(): void {\n this.#state = new RRUnloadedState<U, N>(this);\n this.#isLoaded = false;\n this.#isCached = false;\n this.#loadPromise = undefined;\n }\n\n import(other: ReactiveReferenceImpl<T, U, H, N>, findEntity: (e: U) => U): void {\n this.#state = other.#state.import(this, findEntity);\n this.#isLoaded = true;\n this.#isCached = true;\n }\n\n /** Returns the tagged id of the current value. */\n get idTaggedMaybe(): TaggedId | N {\n ensureNotDeleted(this.entity, \"pending\");\n return maybeResolveReferenceToId(this.current()) as TaggedId | N;\n }\n\n get id(): IdOf<U> {\n return this.idMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idUntagged(): string {\n return this.idUntaggedMaybe || failNoId(this.entity, this.fieldName, this.current());\n }\n\n get idIfSet(): IdOf<U> | N | undefined {\n return this.idMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get idUntaggedIfSet(): string | undefined {\n return this.idUntaggedMaybe || failIfNewEntity(this.entity, this.fieldName, this.current());\n }\n\n get loadHint(): any {\n const meta = getMetadata(this.entity);\n return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= convertToLoadHint(meta, this.reactiveHint));\n }\n\n // private impl\n\n /** Returns the id of the current value. */\n private get idMaybe(): IdOf<U> | undefined {\n ensureNotDeleted(this.entity, \"pending\");\n return toIdOf(this.otherMeta, this.idTaggedMaybe);\n }\n\n private get idUntaggedMaybe(): string | undefined {\n return deTagId(this.otherMeta, this.idMaybe);\n }\n\n setFromOpts(_: U | IdOf<U> | N): void {\n throw new Error(`ReactiveReference ${this.entity}.${this.fieldName} cannot be set via opts`);\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 setField(this.entity, this.fieldName, undefined);\n this.#state = new RRRefState<U, N>(this, undefined as N);\n this.#isLoaded = false;\n this.#isCached = false;\n this.#loadPromise = undefined;\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 | string | 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 get fieldName(): string {\n return this.#fieldName;\n }\n\n public get otherMeta(): EntityMetadata<U> {\n return (getMetadata(this.entity).allFields[this.#fieldName] as ManyToOneField).otherMetadata();\n }\n\n public get hasBeenSet(): boolean {\n return true;\n }\n\n public toString(): string {\n return `ReactiveReference(entity: ${this.entity}, hint: ${this.loadHint}, fieldName: ${this.fieldName}, otherMeta: {\n this.otherMeta.type\n }, id: ${this.id})`;\n }\n\n /**\n * Removes pending-hard-delete (but not soft-deleted), unless explicitly asked for.\n *\n * Note that we leave soft-deleted entities b/c the call signature of a `book.author.get`\n * very likely does not expect a soft-deleted entity to result in `undefined`.\n *\n * (Contrasted with `author.books.get` which is more intuitive to have soft-deleted\n * entities filtered out, i.e. it doesn't fundamentally change the return type.)\n */\n private filterDeleted(entity: U | N, opts?: { withDeleted?: boolean }): U | N {\n if (entity && (!opts || !opts.withDeleted) && entity.isDeletedEntity) {\n return undefined!;\n }\n return entity;\n }\n\n private get isCascadeDelete(): boolean {\n return isCascadeDelete(this, this.#fieldName);\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 | N {\n // Check this.loaded first b/c a new entity won't have an id yet\n if (this.#state.canReturnValue) {\n const loaded = this.#state.doGet();\n if (loaded !== undefined) {\n return loaded;\n }\n }\n const { idTaggedMaybe } = this;\n return idTaggedMaybe !== undefined ? (this.entity.em.getEntity(idTaggedMaybe) as U | N) : (undefined as N);\n }\n\n [RelationT]: T = null!;\n [RelationU]: U = null!;\n [ReferenceN]: N = null!;\n}\n\n/** Type guard utility for determining if an entity field is a ReactiveReference. */\nexport function isReactiveReference(maybeReactiveRef: any): maybeReactiveRef is ReactiveReference<any, any, any> {\n return maybeReactiveRef instanceof ReactiveReferenceImpl;\n}\n\ninterface RRState<U extends Entity, N extends never | undefined> {\n readonly kind: \"unloaded\" | \"ref\" | \"full\";\n readonly canReturnValue: boolean;\n doGet(): U | N | undefined;\n /**\n * Switches from \"materialized ref value\" semantics to \"recalc from reactive graph when available\" semantics.\n *\n * This is synchronous because it does not mean the load hint is fully loaded yet. It only means this\n * reference should now behave as recalc-capable: if `isLoaded(loadHint)` later reports true, `doGet`\n * will recalculate from `fn(...)`; otherwise we keep returning the last known/stale value until `load()`\n * populates the graph.\n */\n enterRecalcMode(target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N>;\n import(target: ReactiveReferenceImpl<any, any, any, any>, findEntity: (e: U) => U): RRState<U, N>;\n}\n\nclass RRUnloadedState<U extends Entity, N extends never | undefined> implements RRState<U, N> {\n readonly kind = \"unloaded\";\n readonly canReturnValue = false;\n #rr: ReactiveReferenceImpl<any, any, any, any>;\n\n constructor(rr: ReactiveReferenceImpl<any, any, any, any>) {\n this.#rr = rr;\n }\n\n doGet(): U | N | undefined {\n throw new Error(`${this.#rr.entity}.${this.#rr.fieldName} was not loaded`);\n }\n\n enterRecalcMode(target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N> {\n return new RRFullState<U, N>(target, undefined);\n }\n\n import(target: ReactiveReferenceImpl<any, any, any, any>, _findEntity: (e: U) => U): RRState<U, N> {\n return new RRUnloadedState<U, N>(target);\n }\n}\n\nclass RRRefState<U extends Entity, N extends never | undefined> implements RRState<U, N> {\n readonly kind = \"ref\";\n readonly canReturnValue = true;\n #loaded: U | N | undefined;\n\n constructor(_rr: ReactiveReferenceImpl<any, any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n }\n\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n\n enterRecalcMode(target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N> {\n return new RRFullState<U, N>(target, this.#loaded);\n }\n\n import(target: ReactiveReferenceImpl<any, any, any, any>, findEntity: (e: U) => U): RRState<U, N> {\n return new RRRefState<U, N>(target, mapReactiveReferenceEntity(this.#loaded, findEntity));\n }\n}\n\nclass RRFullState<U extends Entity, N extends never | undefined> implements RRState<U, N> {\n readonly kind = \"full\";\n readonly canReturnValue = true;\n #loaded: U | N | undefined;\n\n constructor(_rr: ReactiveReferenceImpl<any, any, any, any>, loaded: U | N | undefined) {\n this.#loaded = loaded;\n }\n\n doGet(): U | N | undefined {\n return this.#loaded;\n }\n\n enterRecalcMode(_target: ReactiveReferenceImpl<any, any, any, any>): RRFullState<U, N> {\n return this;\n }\n\n import(target: ReactiveReferenceImpl<any, any, any, any>, findEntity: (e: U) => U): RRState<U, N> {\n return new RRRefState<U, N>(target, mapReactiveReferenceEntity(this.#loaded, findEntity));\n }\n}\n\nfunction mapReactiveReferenceEntity<U extends Entity, N extends never | undefined>(\n entity: U | N | undefined,\n findEntity: (e: U) => U,\n): U | N | undefined {\n return isEntity(entity) ? findEntity(entity) : entity;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBAKd,MAAS,IAAsF;CAC/F,OAAOA,kBAAAA,WAAW,QAAW,cAAc;EACzC,MAAM,MAAMC,uBAAAA,YAAY,MAAM,CAAC,CAAC,UAAU;EAC1C,OAAO,IAAI,sBAAkC,QAAQ,KAAK,MAAM,EAAE;CACpE,CAAC;AACH;;;;;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