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,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
2
|
+
const require_queries_parsedConditions = require("../parsedConditions.cjs");
|
|
3
|
+
const require_queries_find_QueryParser = require("./QueryParser.cjs");
|
|
4
|
+
const require_utils = require("../../utils.cjs");
|
|
5
|
+
//#region src/queries/find/QueryParser.pruning.ts
|
|
5
6
|
function pruneUnusedJoins(parsed, keepAliases) {
|
|
6
7
|
const dt = new DependencyTracker();
|
|
7
8
|
const todo = [...parsed.tables];
|
|
@@ -36,7 +37,7 @@ function pruneUnusedJoins(parsed, keepAliases) {
|
|
|
36
37
|
}];
|
|
37
38
|
while (todo2.length > 0) {
|
|
38
39
|
const { query, filterPruneable } = todo2.pop();
|
|
39
|
-
deepFindConditions(query.condition, filterPruneable).forEach((c) => {
|
|
40
|
+
require_queries_parsedConditions.deepFindConditions(query.condition, filterPruneable).forEach((c) => {
|
|
40
41
|
if (c.kind === "column") dt.markRequired(c.alias);
|
|
41
42
|
else if (c.kind === "raw") for (const alias of c.aliases) dt.markRequired(alias);
|
|
42
43
|
else if (c.kind === "exists") for (const alias of c.outerAliases) dt.markRequired(alias);
|
|
@@ -56,7 +57,7 @@ function pruneUnusedJoins(parsed, keepAliases) {
|
|
|
56
57
|
}
|
|
57
58
|
/** Returns the aliases needed to evaluate a join's ON clause, excluding the joined alias itself. */
|
|
58
59
|
function joinDependencies(t) {
|
|
59
|
-
return [
|
|
60
|
+
return [require_queries_find_QueryParser.parseAlias(t.col1), require_queries_find_QueryParser.parseAlias(t.col2)].filter((alias) => alias !== t.alias);
|
|
60
61
|
}
|
|
61
62
|
/** Marks aliases used by select strings, including generated CTI expressions like `COALESCE(st0.col, st1.col)`. */
|
|
62
63
|
function markSelectAliases(dt, parsed, select) {
|
|
@@ -87,20 +88,6 @@ function selectReferencesCandidate(select, candidate) {
|
|
|
87
88
|
function isSqlIdentifierChar(char) {
|
|
88
89
|
return char !== void 0 && /[A-Za-z0-9_]/.test(char);
|
|
89
90
|
}
|
|
90
|
-
/** Pulls out a flat list of all `ColumnCondition`s from a `ParsedExpressionFilter` tree. */
|
|
91
|
-
function deepFindConditions(condition, filterPruneable) {
|
|
92
|
-
const todo = condition ? [condition] : [];
|
|
93
|
-
const result = [];
|
|
94
|
-
while (todo.length !== 0) {
|
|
95
|
-
const cc = todo.pop();
|
|
96
|
-
for (const c of cc.conditions) if (c.kind === "exp") todo.push(c);
|
|
97
|
-
else if (c.kind === "column" || c.kind === "raw") {
|
|
98
|
-
if (!filterPruneable || !c.pruneable) result.push(c);
|
|
99
|
-
} else if (c.kind === "exists") result.push(c);
|
|
100
|
-
else require_utils.assertNever(c);
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
91
|
/** Track join dependencies for `pruneUnusedJoins`. */
|
|
105
92
|
var DependencyTracker = class {
|
|
106
93
|
nodes = /* @__PURE__ */ new Map();
|
|
@@ -122,7 +109,6 @@ var DependencyTracker = class {
|
|
|
122
109
|
}
|
|
123
110
|
};
|
|
124
111
|
//#endregion
|
|
125
|
-
exports.deepFindConditions = deepFindConditions;
|
|
126
112
|
exports.pruneUnusedJoins = pruneUnusedJoins;
|
|
127
113
|
exports.selectReferencesAlias = selectReferencesAlias;
|
|
128
114
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryParser.pruning.cjs","names":["parseAlias"],"sources":["../../../src/queries/find/QueryParser.pruning.ts"],"sourcesContent":["import { assertNever } from \"../../utils.ts\";\nimport { deepFindConditions } from \"../parsedConditions.ts\";\nimport { type JoinTable, type ParsedFindQuery, parseAlias } from \"./QueryParser.ts\";\n\n// Remove any joins that are not used in the select or conditions\nexport function pruneUnusedJoins(parsed: ParsedFindQuery, keepAliases: string[]): void {\n const dt = new DependencyTracker();\n\n // First setup the alias -> alias dependencies...\n const todo = [...parsed.tables];\n while (todo.length > 0) {\n const t = todo.pop()!;\n if (t.join === \"lateral\") {\n dt.addAlias(t.alias, [t.fromAlias]);\n // Recurse into lateral joins...\n todo.push(...t.query.tables);\n } else if (t.join === \"cross\") {\n dt.markRequired(t.alias);\n } else if (t.join === \"primary\") {\n dt.markRequired(t.alias);\n } else if (parsed.ctes?.some((cte) => cte.alias === t.table)) {\n dt.addAlias(t.alias, joinDependencies(t));\n dt.markRequired(t.alias);\n } else {\n dt.addAlias(t.alias, joinDependencies(t));\n }\n }\n\n // Mark all terminal usages\n parsed.selects.forEach((s) => {\n if (typeof s === \"string\") {\n markSelectAliases(dt, parsed, s);\n } else if (\"aliases\" in s) {\n for (const a of s.aliases) dt.markRequired(a);\n markSelectAliases(dt, parsed, s.sql);\n }\n });\n parsed.orderBys.forEach((o) => dt.markRequired(o.alias));\n parsed.groupBys?.forEach((g) => {\n if (\"expression\" in g) {\n markSelectAliases(dt, parsed, g.expression);\n } else {\n dt.markRequired(g.alias);\n }\n });\n keepAliases.forEach((a) => dt.markRequired(a));\n // Look recursively into CTE & lateral join conditions\n const todo2 = [{ query: parsed, filterPruneable: true }];\n while (todo2.length > 0) {\n const { query, filterPruneable } = todo2.pop()!;\n deepFindConditions(query.condition, filterPruneable).forEach((c) => {\n if (c.kind === \"column\") {\n dt.markRequired(c.alias);\n } else if (c.kind === \"raw\") {\n for (const alias of c.aliases) dt.markRequired(alias);\n } else if (c.kind === \"exists\") {\n for (const alias of c.outerAliases) dt.markRequired(alias);\n } else {\n assertNever(c);\n }\n });\n todo2.push(\n ...query.tables.filter((t) => t.join === \"lateral\").map((t) => ({ query: t.query, filterPruneable: false })),\n );\n }\n\n // Now remove any unused joins\n parsed.tables = parsed.tables.filter((t) => dt.required.has(t.alias));\n\n // And then remove any inline soft-delete conditions we don't need anymore\n if (parsed.condition && parsed.condition.op === \"and\") {\n parsed.condition.conditions = parsed.condition.conditions.filter((c) => {\n if (c.kind === \"column\") {\n const prune = c.pruneable && !dt.required.has(c.alias);\n // if (prune) console.log(`DROPPING`, c);\n return !prune;\n } else {\n return c;\n }\n });\n }\n\n // Remove any `{ and: [...] }`s that are empty; we should probably do this deeply?\n if (parsed.condition && parsed.condition.conditions.length === 0) {\n parsed.condition = undefined;\n }\n}\n\n/** Returns the aliases needed to evaluate a join's ON clause, excluding the joined alias itself. */\nfunction joinDependencies(t: JoinTable): string[] {\n return [parseAlias(t.col1), parseAlias(t.col2)].filter((alias) => alias !== t.alias);\n}\n\n/** Marks aliases used by select strings, including generated CTI expressions like `COALESCE(st0.col, st1.col)`. */\nfunction markSelectAliases(dt: DependencyTracker, parsed: ParsedFindQuery, select: string): void {\n for (const table of parsed.tables) {\n if (selectReferencesAlias(select, table.alias)) {\n dt.markRequired(table.alias);\n }\n }\n}\n\n/** Returns true if a raw select expression references `alias.column` or the whole-row `alias`. */\nexport function selectReferencesAlias(select: string, alias: string): boolean {\n // Most selects are simple `a.*`, but CTI adds expressions like\n // `COALESCE(p_s0.shared_column, p_s1.shared_column) as shared_column`.\n // Those expressions must keep the subtype joins, but `parseAlias` only sees\n // the leading function name. Instead of parsing SQL, scan for the only alias\n // forms Joist generates in selects: `alias.column`, `\"alias\".column`, and whole-row aliases.\n return (\n selectReferencesCandidate(select, `${alias}.`) ||\n selectReferencesCandidate(select, `\"${alias}\".`) ||\n selectReferencesCandidate(select, alias) ||\n selectReferencesCandidate(select, `\"${alias}\"`)\n );\n}\n\n/**\n * Returns true when `candidate` is present at a SQL identifier boundary.\n *\n * Scans the select string for literal candidate matches, then verifies the characters before/after the match are not\n * part of a larger identifier or dotted path. I.e. `row_to_json(\"ap\")` matches, but `foo_\"ap\"` and `foo.ap` do not.\n */\nfunction selectReferencesCandidate(select: string, candidate: string): boolean {\n let index = select.indexOf(candidate);\n const quoted = candidate.startsWith('\"');\n while (index !== -1) {\n // Each loop inspects one literal occurrence of `candidate`, then either accepts it as a real alias reference or\n // advances to the next occurrence if the surrounding characters show it is part of a larger token.\n // Avoid treating `foo.a.id` as a reference to `a`; Joist-generated aliases\n // appear at the start of an expression or after punctuation/whitespace.\n const previous = select[index - 1];\n const next = select[index + candidate.length];\n if (\n (index === 0 || (previous !== \".\" && !isSqlIdentifierChar(previous))) &&\n !isSqlIdentifierChar(next) &&\n (quoted || (previous !== '\"' && next !== '\"'))\n ) {\n return true;\n }\n // Continue scanning after the current occurrence; `indexOf` returns -1 once there are no more candidates.\n index = select.indexOf(candidate, index + candidate.length);\n }\n return false;\n}\n\n/** Returns true for characters that can be part of an unquoted SQL identifier. */\nfunction isSqlIdentifierChar(char: string | undefined): boolean {\n return char !== undefined && /[A-Za-z0-9_]/.test(char);\n}\n\n/** Track join dependencies for `pruneUnusedJoins`. */\nclass DependencyTracker {\n private nodes: Map<string, string[]> = new Map();\n required: Set<string> = new Set();\n\n addAlias(alias: string, dependencies: string[] = []): void {\n this.nodes.set(alias, dependencies);\n }\n\n markRequired(alias: string): void {\n const marked = new Set<string>();\n const todo = [alias];\n while (todo.length > 0) {\n const alias = todo.pop()!;\n if (!marked.has(alias)) {\n marked.add(alias);\n todo.push(...(this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@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParsedFindQuery } from "./QueryParser.cjs";
|
|
2
|
+
//#region src/queries/find/QueryParser.pruning.d.ts
|
|
3
|
+
declare function pruneUnusedJoins(parsed: ParsedFindQuery, keepAliases: string[]): void;
|
|
4
|
+
/** Returns true if a raw select expression references `alias.column` or the whole-row `alias`. */
|
|
5
|
+
declare function selectReferencesAlias(select: string, alias: string): boolean;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { pruneUnusedJoins, selectReferencesAlias };
|
|
8
|
+
//# sourceMappingURL=QueryParser.pruning.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryParser.pruning.d.cts","names":[],"sources":["../../../src/queries/find/QueryParser.pruning.ts"],"mappings":";;iBAKgB,iBAAiB,QAAQ,iBAAiB;;iBAkG1C,sBAAsB,gBAAgB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParsedFindQuery } from "./QueryParser.mjs";
|
|
2
|
+
//#region src/queries/find/QueryParser.pruning.d.ts
|
|
3
|
+
declare function pruneUnusedJoins(parsed: ParsedFindQuery, keepAliases: string[]): void;
|
|
4
|
+
/** Returns true if a raw select expression references `alias.column` or the whole-row `alias`. */
|
|
5
|
+
declare function selectReferencesAlias(select: string, alias: string): boolean;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { pruneUnusedJoins, selectReferencesAlias };
|
|
8
|
+
//# sourceMappingURL=QueryParser.pruning.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryParser.pruning.d.mts","names":[],"sources":["../../../src/queries/find/QueryParser.pruning.ts"],"mappings":";;iBAKgB,iBAAiB,QAAQ,iBAAiB;;iBAkG1C,sBAAsB,gBAAgB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { deepFindConditions } from "../parsedConditions.js";
|
|
2
2
|
import { parseAlias } from "./QueryParser.js";
|
|
3
|
-
|
|
3
|
+
import { assertNever } from "../../utils.js";
|
|
4
|
+
//#region src/queries/find/QueryParser.pruning.ts
|
|
4
5
|
function pruneUnusedJoins(parsed, keepAliases) {
|
|
5
6
|
const dt = new DependencyTracker();
|
|
6
7
|
const todo = [...parsed.tables];
|
|
@@ -86,20 +87,6 @@ function selectReferencesCandidate(select, candidate) {
|
|
|
86
87
|
function isSqlIdentifierChar(char) {
|
|
87
88
|
return char !== void 0 && /[A-Za-z0-9_]/.test(char);
|
|
88
89
|
}
|
|
89
|
-
/** Pulls out a flat list of all `ColumnCondition`s from a `ParsedExpressionFilter` tree. */
|
|
90
|
-
function deepFindConditions(condition, filterPruneable) {
|
|
91
|
-
const todo = condition ? [condition] : [];
|
|
92
|
-
const result = [];
|
|
93
|
-
while (todo.length !== 0) {
|
|
94
|
-
const cc = todo.pop();
|
|
95
|
-
for (const c of cc.conditions) if (c.kind === "exp") todo.push(c);
|
|
96
|
-
else if (c.kind === "column" || c.kind === "raw") {
|
|
97
|
-
if (!filterPruneable || !c.pruneable) result.push(c);
|
|
98
|
-
} else if (c.kind === "exists") result.push(c);
|
|
99
|
-
else assertNever(c);
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
90
|
/** Track join dependencies for `pruneUnusedJoins`. */
|
|
104
91
|
var DependencyTracker = class {
|
|
105
92
|
nodes = /* @__PURE__ */ new Map();
|
|
@@ -121,6 +108,6 @@ var DependencyTracker = class {
|
|
|
121
108
|
}
|
|
122
109
|
};
|
|
123
110
|
//#endregion
|
|
124
|
-
export {
|
|
111
|
+
export { pruneUnusedJoins, selectReferencesAlias };
|
|
125
112
|
|
|
126
113
|
//# sourceMappingURL=QueryParser.pruning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryParser.pruning.js","names":[],"sources":["../../../src/queries/find/QueryParser.pruning.ts"],"sourcesContent":["import { assertNever } from \"../../utils.ts\";\nimport { deepFindConditions } from \"../parsedConditions.ts\";\nimport { type JoinTable, type ParsedFindQuery, parseAlias } from \"./QueryParser.ts\";\n\n// Remove any joins that are not used in the select or conditions\nexport function pruneUnusedJoins(parsed: ParsedFindQuery, keepAliases: string[]): void {\n const dt = new DependencyTracker();\n\n // First setup the alias -> alias dependencies...\n const todo = [...parsed.tables];\n while (todo.length > 0) {\n const t = todo.pop()!;\n if (t.join === \"lateral\") {\n dt.addAlias(t.alias, [t.fromAlias]);\n // Recurse into lateral joins...\n todo.push(...t.query.tables);\n } else if (t.join === \"cross\") {\n dt.markRequired(t.alias);\n } else if (t.join === \"primary\") {\n dt.markRequired(t.alias);\n } else if (parsed.ctes?.some((cte) => cte.alias === t.table)) {\n dt.addAlias(t.alias, joinDependencies(t));\n dt.markRequired(t.alias);\n } else {\n dt.addAlias(t.alias, joinDependencies(t));\n }\n }\n\n // Mark all terminal usages\n parsed.selects.forEach((s) => {\n if (typeof s === \"string\") {\n markSelectAliases(dt, parsed, s);\n } else if (\"aliases\" in s) {\n for (const a of s.aliases) dt.markRequired(a);\n markSelectAliases(dt, parsed, s.sql);\n }\n });\n parsed.orderBys.forEach((o) => dt.markRequired(o.alias));\n parsed.groupBys?.forEach((g) => {\n if (\"expression\" in g) {\n markSelectAliases(dt, parsed, g.expression);\n } else {\n dt.markRequired(g.alias);\n }\n });\n keepAliases.forEach((a) => dt.markRequired(a));\n // Look recursively into CTE & lateral join conditions\n const todo2 = [{ query: parsed, filterPruneable: true }];\n while (todo2.length > 0) {\n const { query, filterPruneable } = todo2.pop()!;\n deepFindConditions(query.condition, filterPruneable).forEach((c) => {\n if (c.kind === \"column\") {\n dt.markRequired(c.alias);\n } else if (c.kind === \"raw\") {\n for (const alias of c.aliases) dt.markRequired(alias);\n } else if (c.kind === \"exists\") {\n for (const alias of c.outerAliases) dt.markRequired(alias);\n } else {\n assertNever(c);\n }\n });\n todo2.push(\n ...query.tables.filter((t) => t.join === \"lateral\").map((t) => ({ query: t.query, filterPruneable: false })),\n );\n }\n\n // Now remove any unused joins\n parsed.tables = parsed.tables.filter((t) => dt.required.has(t.alias));\n\n // And then remove any inline soft-delete conditions we don't need anymore\n if (parsed.condition && parsed.condition.op === \"and\") {\n parsed.condition.conditions = parsed.condition.conditions.filter((c) => {\n if (c.kind === \"column\") {\n const prune = c.pruneable && !dt.required.has(c.alias);\n // if (prune) console.log(`DROPPING`, c);\n return !prune;\n } else {\n return c;\n }\n });\n }\n\n // Remove any `{ and: [...] }`s that are empty; we should probably do this deeply?\n if (parsed.condition && parsed.condition.conditions.length === 0) {\n parsed.condition = undefined;\n }\n}\n\n/** Returns the aliases needed to evaluate a join's ON clause, excluding the joined alias itself. */\nfunction joinDependencies(t: JoinTable): string[] {\n return [parseAlias(t.col1), parseAlias(t.col2)].filter((alias) => alias !== t.alias);\n}\n\n/** Marks aliases used by select strings, including generated CTI expressions like `COALESCE(st0.col, st1.col)`. */\nfunction markSelectAliases(dt: DependencyTracker, parsed: ParsedFindQuery, select: string): void {\n for (const table of parsed.tables) {\n if (selectReferencesAlias(select, table.alias)) {\n dt.markRequired(table.alias);\n }\n }\n}\n\n/** Returns true if a raw select expression references `alias.column` or the whole-row `alias`. */\nexport function selectReferencesAlias(select: string, alias: string): boolean {\n // Most selects are simple `a.*`, but CTI adds expressions like\n // `COALESCE(p_s0.shared_column, p_s1.shared_column) as shared_column`.\n // Those expressions must keep the subtype joins, but `parseAlias` only sees\n // the leading function name. Instead of parsing SQL, scan for the only alias\n // forms Joist generates in selects: `alias.column`, `\"alias\".column`, and whole-row aliases.\n return (\n selectReferencesCandidate(select, `${alias}.`) ||\n selectReferencesCandidate(select, `\"${alias}\".`) ||\n selectReferencesCandidate(select, alias) ||\n selectReferencesCandidate(select, `\"${alias}\"`)\n );\n}\n\n/**\n * Returns true when `candidate` is present at a SQL identifier boundary.\n *\n * Scans the select string for literal candidate matches, then verifies the characters before/after the match are not\n * part of a larger identifier or dotted path. I.e. `row_to_json(\"ap\")` matches, but `foo_\"ap\"` and `foo.ap` do not.\n */\nfunction selectReferencesCandidate(select: string, candidate: string): boolean {\n let index = select.indexOf(candidate);\n const quoted = candidate.startsWith('\"');\n while (index !== -1) {\n // Each loop inspects one literal occurrence of `candidate`, then either accepts it as a real alias reference or\n // advances to the next occurrence if the surrounding characters show it is part of a larger token.\n // Avoid treating `foo.a.id` as a reference to `a`; Joist-generated aliases\n // appear at the start of an expression or after punctuation/whitespace.\n const previous = select[index - 1];\n const next = select[index + candidate.length];\n if (\n (index === 0 || (previous !== \".\" && !isSqlIdentifierChar(previous))) &&\n !isSqlIdentifierChar(next) &&\n (quoted || (previous !== '\"' && next !== '\"'))\n ) {\n return true;\n }\n // Continue scanning after the current occurrence; `indexOf` returns -1 once there are no more candidates.\n index = select.indexOf(candidate, index + candidate.length);\n }\n return false;\n}\n\n/** Returns true for characters that can be part of an unquoted SQL identifier. */\nfunction isSqlIdentifierChar(char: string | undefined): boolean {\n return char !== undefined && /[A-Za-z0-9_]/.test(char);\n}\n\n/** Track join dependencies for `pruneUnusedJoins`. */\nclass DependencyTracker {\n private nodes: Map<string, string[]> = new Map();\n required: Set<string> = new Set();\n\n addAlias(alias: string, dependencies: string[] = []): void {\n this.nodes.set(alias, dependencies);\n }\n\n markRequired(alias: string): void {\n const marked = new Set<string>();\n const todo = [alias];\n while (todo.length > 0) {\n const alias = todo.pop()!;\n if (!marked.has(alias)) {\n marked.add(alias);\n todo.push(...(this.nodes.get(alias) || []));\n }\n }\n this.required = new Set([...this.required, ...marked]);\n }\n}\n"],"mappings":";;;;AAKA,SAAgB,iBAAiB,QAAyB,aAA6B;CACrF,MAAM,KAAK,IAAI,kBAAkB;CAGjC,MAAM,OAAO,CAAC,GAAG,OAAO,MAAM;CAC9B,OAAO,KAAK,SAAS,GAAG;EACtB,MAAM,IAAI,KAAK,IAAI;EACnB,IAAI,EAAE,SAAS,WAAW;GACxB,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC;GAElC,KAAK,KAAK,GAAG,EAAE,MAAM,MAAM;EAC7B,OAAO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,UAAU,KAAM,aAAa,OAAO,CAAC,oBAAoB,QAAQ,MAClE,CAAC,oBAAoB,IAAI,MACxB,UAAW,aAAa,QAAO,SAAS,OAEzC,OAAO;EAGT,QAAQ,OAAO,QAAQ,WAAW,QAAQ,UAAU,MAAM;CAC5D;CACA,OAAO;AACT;;AAGA,SAAS,oBAAoB,MAAmC;CAC9D,OAAO,SAAS,KAAA,KAAa,eAAe,KAAK,IAAI;AACvD;;AAGA,IAAM,oBAAN,MAAwB;CACtB,wBAAuC,IAAI,IAAI;CAC/C,2BAAwB,IAAI,IAAI;CAEhC,SAAS,OAAe,eAAyB,CAAC,GAAS;EACzD,KAAK,MAAM,IAAI,OAAO,YAAY;CACpC;CAEA,aAAa,OAAqB;EAChC,MAAM,yBAAS,IAAI,IAAY;EAC/B,MAAM,OAAO,CAAC,KAAK;EACnB,OAAO,KAAK,SAAS,GAAG;GACtB,MAAM,QAAQ,KAAK,IAAI;GACvB,IAAI,CAAC,OAAO,IAAI,KAAK,GAAG;IACtB,OAAO,IAAI,KAAK;IAChB,KAAK,KAAK,GAAI,KAAK,MAAM,IAAI,KAAK,KAAK,CAAC,CAAE;GAC5C;EACF;EACA,KAAK,2BAAW,IAAI,IAAI,CAAC,GAAG,KAAK,UAAU,GAAG,MAAM,CAAC;CACvD;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_utils = require("
|
|
3
|
-
|
|
4
|
-
//#region src/QueryVisitor.ts
|
|
2
|
+
const require_utils = require("../../utils.cjs");
|
|
3
|
+
//#region src/queries/find/QueryVisitor.ts
|
|
5
4
|
/**
|
|
6
5
|
* Visits the nested conditions within `query`.
|
|
7
6
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryVisitor.cjs","names":[],"sources":["../../../src/queries/find/QueryVisitor.ts"],"sourcesContent":["import { assertNever } from \"../../utils.ts\";\nimport type {\n ColumnCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n RawCondition,\n} from \"../parsedConditions.ts\";\nimport type { ParsedFindQuery } from \"./QueryParser.ts\";\n\n/** A generic visitor over the simple & complex conditions of a query. */\ninterface Visitor {\n visitExp?(c: ParsedExpressionFilter): ParsedExpressionFilter | void;\n visitRaw?(c: RawCondition): RawCondition | ParsedExpressionFilter | void;\n visitCond(c: ColumnCondition): ColumnCondition | ParsedExpressionFilter | RawCondition | null | void;\n}\n\n/**\n * Visits the nested conditions within `query`.\n *\n * If the visitors return a new condition or expression, the returned expression\n * will replace the original one at that location in the expression.\n *\n * If the visitor returns null, the condition or expression will be removed from the tree.\n */\nexport function visitConditions(query: ParsedFindQuery, visitor: Visitor): void {\n const todo = [query];\n while (todo.length > 0) {\n const query = todo.pop()!;\n if (query.condition) visitFilter(query.condition, visitor);\n // Recurse into lateral subqueries (used by batching/preloading, not EXISTS rewrite)\n for (const table of query.tables) {\n if (table.join === \"lateral\") {\n todo.push(table.query);\n }\n }\n // Recurse into EXISTS subqueries so batching visitors can rewrite conditions inside them\n if (query.condition) {\n visitExistsSubqueries(query.condition, todo);\n }\n }\n}\n\n/** Finds ExistsCondition nodes in a condition tree and pushes their subqueries onto the todo list. */\nfunction visitExistsSubqueries(condition: ParsedExpressionCondition, todo: ParsedFindQuery[]): void {\n if (condition.kind === \"exp\") {\n for (const c of condition.conditions) {\n visitExistsSubqueries(c, todo);\n }\n } else if (condition.kind === \"exists\") {\n todo.push(condition.subquery);\n }\n}\n\nexport function visitFilter(pc: ParsedExpressionCondition, visitor: Visitor) {\n if (pc.kind === \"exp\") {\n const toRemove = new Set<number>();\n pc.conditions.forEach((c, i) => {\n if (c.kind === \"column\") {\n const result = visitor.visitCond(c);\n if (result === null) {\n toRemove.add(i);\n } else if (result) {\n pc.conditions[i] = result;\n }\n } else if (c.kind === \"exp\") {\n const result = visitor.visitExp?.(c);\n if (result === null) {\n toRemove.add(i);\n return;\n } else if (result) {\n pc.conditions[i] = result;\n }\n visitFilter(result ?? c, visitor);\n } else if (c.kind === \"raw\") {\n const result = visitor.visitRaw?.(c);\n if (result === null) {\n toRemove.add(i);\n } else if (result) {\n pc.conditions[i] = result;\n }\n } else if (c.kind === \"exists\") {\n // EXISTS conditions are visited via visitExistsSubqueries, not inline\n } else {\n assertNever(c);\n }\n });\n // do this after visiting the children, so we can do it in one pass and don't mess up the indices\n if (toRemove.size > 0) pc.conditions = pc.conditions.filter((_, i) => !toRemove.has(i));\n } else if (pc.kind === \"column\") {\n const result = visitor.visitCond(pc);\n if (result || result === null) {\n throw new Error(\"ParsedExpressionCondition overload not support mutating the condition\");\n }\n } else if (pc.kind === \"raw\") {\n const result = visitor.visitRaw?.(pc);\n if (result || result === null) {\n throw new Error(\"ParsedExpressionCondition overload not support mutating the condition\");\n }\n } else if (pc.kind === \"exists\") {\n // EXISTS conditions are handled at the query level\n } else {\n assertNever(pc);\n }\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,gBAAgB,OAAwB,SAAwB;CAC9E,MAAM,OAAO,CAAC,KAAK;CACnB,OAAO,KAAK,SAAS,GAAG;EACtB,MAAM,QAAQ,KAAK,IAAI;EACvB,IAAI,MAAM,WAAW,YAAY,MAAM,WAAW,OAAO;EAEzD,KAAK,MAAM,SAAS,MAAM,QACxB,IAAI,MAAM,SAAS,WACjB,KAAK,KAAK,MAAM,KAAK;EAIzB,IAAI,MAAM,WACR,sBAAsB,MAAM,WAAW,IAAI;CAE/C;AACF;;AAGA,SAAS,sBAAsB,WAAsC,MAA+B;CAClG,IAAI,UAAU,SAAS,OACrB,KAAK,MAAM,KAAK,UAAU,YACxB,sBAAsB,GAAG,IAAI;MAE1B,IAAI,UAAU,SAAS,UAC5B,KAAK,KAAK,UAAU,QAAQ;AAEhC;AAEA,SAAgB,YAAY,IAA+B,SAAkB;CAC3E,IAAI,GAAG,SAAS,OAAO;EACrB,MAAM,2BAAW,IAAI,IAAY;EACjC,GAAG,WAAW,SAAS,GAAG,MAAM;GAC9B,IAAI,EAAE,SAAS,UAAU;IACvB,MAAM,SAAS,QAAQ,UAAU,CAAC;IAClC,IAAI,WAAW,MACb,SAAS,IAAI,CAAC;SACT,IAAI,QACT,GAAG,WAAW,KAAK;GAEvB,OAAO,IAAI,EAAE,SAAS,OAAO;IAC3B,MAAM,SAAS,QAAQ,WAAW,CAAC;IACnC,IAAI,WAAW,MAAM;KACnB,SAAS,IAAI,CAAC;KACd;IACF,OAAO,IAAI,QACT,GAAG,WAAW,KAAK;IAErB,YAAY,UAAU,GAAG,OAAO;GAClC,OAAO,IAAI,EAAE,SAAS,OAAO;IAC3B,MAAM,SAAS,QAAQ,WAAW,CAAC;IACnC,IAAI,WAAW,MACb,SAAS,IAAI,CAAC;SACT,IAAI,QACT,GAAG,WAAW,KAAK;GAEvB,OAAO,IAAI,EAAE,SAAS,UAAU,CAEhC,OACE,cAAA,YAAY,CAAC;EAEjB,CAAC;EAED,IAAI,SAAS,OAAO,GAAG,GAAG,aAAa,GAAG,WAAW,QAAQ,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;CACxF,OAAO,IAAI,GAAG,SAAS,UAAU;EAC/B,MAAM,SAAS,QAAQ,UAAU,EAAE;EACnC,IAAI,UAAU,WAAW,MACvB,MAAM,IAAI,MAAM,uEAAuE;CAE3F,OAAO,IAAI,GAAG,SAAS,OAAO;EAC5B,MAAM,SAAS,QAAQ,WAAW,EAAE;EACpC,IAAI,UAAU,WAAW,MACvB,MAAM,IAAI,MAAM,uEAAuE;CAE3F,OAAO,IAAI,GAAG,SAAS,UAAU,CAEjC,OACE,cAAA,YAAY,EAAE;AAElB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ParsedFindQuery } from "./QueryParser.cjs";
|
|
2
|
+
import { ColumnCondition, ParsedExpressionCondition, ParsedExpressionFilter, RawCondition } from "../parsedConditions.cjs";
|
|
3
|
+
//#region src/queries/find/QueryVisitor.d.ts
|
|
3
4
|
/** A generic visitor over the simple & complex conditions of a query. */
|
|
4
5
|
interface Visitor {
|
|
5
6
|
visitExp?(c: ParsedExpressionFilter): ParsedExpressionFilter | void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryVisitor.d.cts","names":[],"sources":["../../../src/queries/find/QueryVisitor.ts"],"mappings":";;;;UAUU;EACR,UAAU,GAAG,yBAAyB;EACtC,UAAU,GAAG,eAAe,eAAe;EAC3C,UAAU,GAAG,kBAAkB,kBAAkB,yBAAyB;;;;;;;;;;iBAW5D,gBAAgB,OAAO,iBAAiB,SAAS;iBA6BjD,YAAY,IAAI,2BAA2B,SAAS"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ParsedFindQuery } from "./QueryParser.mjs";
|
|
2
|
+
import { ColumnCondition, ParsedExpressionCondition, ParsedExpressionFilter, RawCondition } from "../parsedConditions.mjs";
|
|
3
|
+
//#region src/queries/find/QueryVisitor.d.ts
|
|
3
4
|
/** A generic visitor over the simple & complex conditions of a query. */
|
|
4
5
|
interface Visitor {
|
|
5
6
|
visitExp?(c: ParsedExpressionFilter): ParsedExpressionFilter | void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryVisitor.d.mts","names":[],"sources":["../../../src/queries/find/QueryVisitor.ts"],"mappings":";;;;UAUU;EACR,UAAU,GAAG,yBAAyB;EACtC,UAAU,GAAG,eAAe,eAAe;EAC3C,UAAU,GAAG,kBAAkB,kBAAkB,yBAAyB;;;;;;;;;;iBAW5D,gBAAgB,OAAO,iBAAiB,SAAS;iBA6BjD,YAAY,IAAI,2BAA2B,SAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryVisitor.js","names":[],"sources":["../../../src/queries/find/QueryVisitor.ts"],"sourcesContent":["import { assertNever } from \"../../utils.ts\";\nimport type {\n ColumnCondition,\n ParsedExpressionCondition,\n ParsedExpressionFilter,\n RawCondition,\n} from \"../parsedConditions.ts\";\nimport type { ParsedFindQuery } from \"./QueryParser.ts\";\n\n/** A generic visitor over the simple & complex conditions of a query. */\ninterface Visitor {\n visitExp?(c: ParsedExpressionFilter): ParsedExpressionFilter | void;\n visitRaw?(c: RawCondition): RawCondition | ParsedExpressionFilter | void;\n visitCond(c: ColumnCondition): ColumnCondition | ParsedExpressionFilter | RawCondition | null | void;\n}\n\n/**\n * Visits the nested conditions within `query`.\n *\n * If the visitors return a new condition or expression, the returned expression\n * will replace the original one at that location in the expression.\n *\n * If the visitor returns null, the condition or expression will be removed from the tree.\n */\nexport function visitConditions(query: ParsedFindQuery, visitor: Visitor): void {\n const todo = [query];\n while (todo.length > 0) {\n const query = todo.pop()!;\n if (query.condition) visitFilter(query.condition, visitor);\n // Recurse into lateral subqueries (used by batching/preloading, not EXISTS rewrite)\n for (const table of query.tables) {\n if (table.join === \"lateral\") {\n todo.push(table.query);\n }\n }\n // Recurse into EXISTS subqueries so batching visitors can rewrite conditions inside them\n if (query.condition) {\n visitExistsSubqueries(query.condition, todo);\n }\n }\n}\n\n/** Finds ExistsCondition nodes in a condition tree and pushes their subqueries onto the todo list. */\nfunction visitExistsSubqueries(condition: ParsedExpressionCondition, todo: ParsedFindQuery[]): void {\n if (condition.kind === \"exp\") {\n for (const c of condition.conditions) {\n visitExistsSubqueries(c, todo);\n }\n } else if (condition.kind === \"exists\") {\n todo.push(condition.subquery);\n }\n}\n\nexport function visitFilter(pc: ParsedExpressionCondition, visitor: Visitor) {\n if (pc.kind === \"exp\") {\n const toRemove = new Set<number>();\n pc.conditions.forEach((c, i) => {\n if (c.kind === \"column\") {\n const result = visitor.visitCond(c);\n if (result === null) {\n toRemove.add(i);\n } else if (result) {\n pc.conditions[i] = result;\n }\n } else if (c.kind === \"exp\") {\n const result = visitor.visitExp?.(c);\n if (result === null) {\n toRemove.add(i);\n return;\n } else if (result) {\n pc.conditions[i] = result;\n }\n visitFilter(result ?? c, visitor);\n } else if (c.kind === \"raw\") {\n const result = visitor.visitRaw?.(c);\n if (result === null) {\n toRemove.add(i);\n } else if (result) {\n pc.conditions[i] = result;\n }\n } else if (c.kind === \"exists\") {\n // EXISTS conditions are visited via visitExistsSubqueries, not inline\n } else {\n assertNever(c);\n }\n });\n // do this after visiting the children, so we can do it in one pass and don't mess up the indices\n if (toRemove.size > 0) pc.conditions = pc.conditions.filter((_, i) => !toRemove.has(i));\n } else if (pc.kind === \"column\") {\n const result = visitor.visitCond(pc);\n if (result || result === null) {\n throw new Error(\"ParsedExpressionCondition overload not support mutating the condition\");\n }\n } else if (pc.kind === \"raw\") {\n const result = visitor.visitRaw?.(pc);\n if (result || result === null) {\n throw new Error(\"ParsedExpressionCondition overload not support mutating the condition\");\n }\n } else if (pc.kind === \"exists\") {\n // EXISTS conditions are handled at the query level\n } else {\n assertNever(pc);\n }\n}\n"],"mappings":";;;;;;;;;;AAwBA,SAAgB,gBAAgB,OAAwB,SAAwB;CAC9E,MAAM,OAAO,CAAC,KAAK;CACnB,OAAO,KAAK,SAAS,GAAG;EACtB,MAAM,QAAQ,KAAK,IAAI;EACvB,IAAI,MAAM,WAAW,YAAY,MAAM,WAAW,OAAO;EAEzD,KAAK,MAAM,SAAS,MAAM,QACxB,IAAI,MAAM,SAAS,WACjB,KAAK,KAAK,MAAM,KAAK;EAIzB,IAAI,MAAM,WACR,sBAAsB,MAAM,WAAW,IAAI;CAE/C;AACF;;AAGA,SAAS,sBAAsB,WAAsC,MAA+B;CAClG,IAAI,UAAU,SAAS,OACrB,KAAK,MAAM,KAAK,UAAU,YACxB,sBAAsB,GAAG,IAAI;MAE1B,IAAI,UAAU,SAAS,UAC5B,KAAK,KAAK,UAAU,QAAQ;AAEhC;AAEA,SAAgB,YAAY,IAA+B,SAAkB;CAC3E,IAAI,GAAG,SAAS,OAAO;EACrB,MAAM,2BAAW,IAAI,IAAY;EACjC,GAAG,WAAW,SAAS,GAAG,MAAM;GAC9B,IAAI,EAAE,SAAS,UAAU;IACvB,MAAM,SAAS,QAAQ,UAAU,CAAC;IAClC,IAAI,WAAW,MACb,SAAS,IAAI,CAAC;SACT,IAAI,QACT,GAAG,WAAW,KAAK;GAEvB,OAAO,IAAI,EAAE,SAAS,OAAO;IAC3B,MAAM,SAAS,QAAQ,WAAW,CAAC;IACnC,IAAI,WAAW,MAAM;KACnB,SAAS,IAAI,CAAC;KACd;IACF,OAAO,IAAI,QACT,GAAG,WAAW,KAAK;IAErB,YAAY,UAAU,GAAG,OAAO;GAClC,OAAO,IAAI,EAAE,SAAS,OAAO;IAC3B,MAAM,SAAS,QAAQ,WAAW,CAAC;IACnC,IAAI,WAAW,MACb,SAAS,IAAI,CAAC;SACT,IAAI,QACT,GAAG,WAAW,KAAK;GAEvB,OAAO,IAAI,EAAE,SAAS,UAAU,CAEhC,OACE,YAAY,CAAC;EAEjB,CAAC;EAED,IAAI,SAAS,OAAO,GAAG,GAAG,aAAa,GAAG,WAAW,QAAQ,GAAG,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;CACxF,OAAO,IAAI,GAAG,SAAS,UAAU;EAC/B,MAAM,SAAS,QAAQ,UAAU,EAAE;EACnC,IAAI,UAAU,WAAW,MACvB,MAAM,IAAI,MAAM,uEAAuE;CAE3F,OAAO,IAAI,GAAG,SAAS,OAAO;EAC5B,MAAM,SAAS,QAAQ,WAAW,EAAE;EACpC,IAAI,UAAU,WAAW,MACvB,MAAM,IAAI,MAAM,uEAAuE;CAE3F,OAAO,IAAI,GAAG,SAAS,UAAU,CAEjC,OACE,YAAY,EAAE;AAElB"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_utils = require("
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
//#region src/drivers/buildRawQuery.ts
|
|
2
|
+
const require_queries_sql_keywords = require("../sql/keywords.cjs");
|
|
3
|
+
const require_utils = require("../../utils.cjs");
|
|
4
|
+
const require_queries_renderConditions = require("../renderConditions.cjs");
|
|
5
|
+
//#region src/queries/find/buildFindQuery.ts
|
|
7
6
|
/**
|
|
8
7
|
* Transforms `ParsedFindQuery` into a raw SQL string.
|
|
9
8
|
*
|
|
@@ -27,7 +26,7 @@ function buildRawQuery(parsed, settings) {
|
|
|
27
26
|
sql += " (";
|
|
28
27
|
for (let j = 0; j < cte.columns.length; j++) {
|
|
29
28
|
sql += j > 0 ? ", " : "";
|
|
30
|
-
sql +=
|
|
29
|
+
sql += require_queries_sql_keywords.kq(cte.columns[j].columnName);
|
|
31
30
|
}
|
|
32
31
|
sql += ")";
|
|
33
32
|
}
|
|
@@ -53,25 +52,25 @@ function buildRawQuery(parsed, settings) {
|
|
|
53
52
|
bindings.push(...s.bindings);
|
|
54
53
|
}
|
|
55
54
|
});
|
|
56
|
-
if (needsDistinct && parsed.orderBys.length > 0) for (const { alias, column } of parsed.orderBys) sql += `, ${
|
|
55
|
+
if (needsDistinct && parsed.orderBys.length > 0) for (const { alias, column } of parsed.orderBys) sql += `, ${require_queries_sql_keywords.kqDot(alias, column)}`;
|
|
57
56
|
sql += ` FROM ${as(primary)}`;
|
|
58
57
|
for (const t of parsed.tables) if (t.join === "inner") sql += ` JOIN ${as(t)} ON ${t.col1} = ${t.col2}`;
|
|
59
58
|
else if (t.join === "outer") sql += ` LEFT OUTER JOIN ${as(t)} ON ${t.col1} = ${t.col2}`;
|
|
60
59
|
else if (t.join === "primary") {} else if (t.join === "lateral") {
|
|
61
60
|
const { sql: subQ, bindings: subB } = buildRawQuery(t.query, t.settings ?? {});
|
|
62
|
-
sql += ` CROSS JOIN LATERAL (${subQ}) AS ${
|
|
61
|
+
sql += ` CROSS JOIN LATERAL (${subQ}) AS ${require_queries_sql_keywords.kq(t.alias)}`;
|
|
63
62
|
bindings.push(...subB);
|
|
64
63
|
} else if (t.join === "cross") sql += ` CROSS JOIN ${as(t)}`;
|
|
65
64
|
else require_utils.assertNever(t.join);
|
|
66
65
|
if (parsed.condition) {
|
|
67
|
-
const where =
|
|
66
|
+
const where = require_queries_renderConditions.buildWhereClause(parsed.condition, true, subqueryRenderer);
|
|
68
67
|
if (where) {
|
|
69
68
|
sql += " WHERE " + where[0];
|
|
70
69
|
bindings.push(...where[1]);
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
|
-
if (parsed.groupBys && parsed.groupBys.length > 0) sql += " GROUP BY " + parsed.groupBys.map((gb) => "expression" in gb ? gb.expression :
|
|
74
|
-
if (parsed.orderBys.length > 0) sql += " ORDER BY " + parsed.orderBys.map((ob) =>
|
|
72
|
+
if (parsed.groupBys && parsed.groupBys.length > 0) sql += " GROUP BY " + parsed.groupBys.map((gb) => "expression" in gb ? gb.expression : require_queries_sql_keywords.kqDot(gb.alias, gb.column)).join(", ");
|
|
73
|
+
if (parsed.orderBys.length > 0) sql += " ORDER BY " + parsed.orderBys.map((ob) => require_queries_sql_keywords.kqDot(ob.alias, ob.column) + " " + ob.order).join(", ");
|
|
75
74
|
if (limit !== void 0) {
|
|
76
75
|
sql += ` LIMIT ?`;
|
|
77
76
|
bindings.push(limit);
|
|
@@ -86,12 +85,12 @@ function buildRawQuery(parsed, settings) {
|
|
|
86
85
|
};
|
|
87
86
|
}
|
|
88
87
|
function buildDistinctOn(parsed, primary) {
|
|
89
|
-
return `DISTINCT ON (${[...parsed.orderBys.map((ob) =>
|
|
88
|
+
return `DISTINCT ON (${[...parsed.orderBys.map((ob) => require_queries_sql_keywords.kqDot(ob.alias, ob.column)), require_queries_sql_keywords.kqDot(primary.alias, "id")].join(", ")}) `;
|
|
90
89
|
}
|
|
91
90
|
/** Creates the `WITH alias (...)` SQL for the given `cte`. */
|
|
92
91
|
function buildCteSql(cte) {
|
|
93
92
|
const maybeRecursive = cte.recursive ? "RECURSIVE " : "";
|
|
94
|
-
const maybeColumns = cte.columns ? ` (${cte.columns.map((c) =>
|
|
93
|
+
const maybeColumns = cte.columns ? ` (${cte.columns.map((c) => require_queries_sql_keywords.kq(c.columnName)).join(", ")})` : "";
|
|
95
94
|
const prefix = `WITH ${maybeRecursive}${cte.alias}${maybeColumns} AS`;
|
|
96
95
|
if (cte.query.kind === "raw") return {
|
|
97
96
|
sql: `${prefix} (${require_utils.cleanSql(cte.query.sql)} )`,
|
|
@@ -105,9 +104,9 @@ function buildCteSql(cte) {
|
|
|
105
104
|
};
|
|
106
105
|
} else require_utils.assertNever(cte.query);
|
|
107
106
|
}
|
|
108
|
-
const as = (t) => `${
|
|
107
|
+
const as = (t) => `${require_queries_sql_keywords.kq(t.table)} AS ${require_queries_sql_keywords.kq(t.alias)}`;
|
|
109
108
|
//#endregion
|
|
110
109
|
exports.buildCteSql = buildCteSql;
|
|
111
110
|
exports.buildRawQuery = buildRawQuery;
|
|
112
111
|
|
|
113
|
-
//# sourceMappingURL=
|
|
112
|
+
//# sourceMappingURL=buildFindQuery.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFindQuery.cjs","names":["kq","cleanSql","kqDot","buildWhereClause"],"sources":["../../../src/queries/find/buildFindQuery.ts"],"sourcesContent":["import { assertNever, cleanSql } from \"../../utils.ts\";\nimport { buildWhereClause } from \"../renderConditions.ts\";\nimport { kq, kqDot } from \"../sql/keywords.ts\";\nimport type { ParsedCteClause, ParsedFindQuery, ParsedTable } from \"./QueryParser.ts\";\n\ntype QuerySettings = { limit?: number; offset?: number };\n\n/**\n * Transforms `ParsedFindQuery` into a raw SQL string.\n *\n * In theory this should be implemented within each Driver, but the logic will be largely\n * the same for different dbs.\n */\nexport function buildRawQuery(\n parsed: ParsedFindQuery,\n settings: QuerySettings,\n): { sql: string; bindings: readonly any[] } {\n const { limit, offset } = settings;\n\n const primary = parsed.tables.find((t) => t.join === \"primary\")!;\n\n // If we're doing o2m joins, add a `DISTINCT` clause to avoid duplicates\n const needsDistinct =\n parsed.tables.some((t) => t.join === \"outer\" && t.distinct !== false) &&\n // If this is a `findCount`, it will rewrite the `select` to have its own distinct\n !parsed.selects.find((s) => typeof s === \"string\" && s.startsWith(\"count(\"));\n\n let sql = \"\";\n const bindings: any[] = [];\n\n if (parsed.ctes && parsed.ctes.length > 0) {\n const hasRecursive = parsed.ctes.some((cte) => cte.recursive);\n const maybeRecursive = hasRecursive ? \" RECURSIVE\" : \"\";\n sql += `WITH${maybeRecursive}`;\n for (let i = 0; i < parsed.ctes.length; i++) {\n const cte = parsed.ctes[i];\n sql += i > 0 ? \", \" : \"\";\n sql += ` ${cte.alias}`;\n if (cte.columns) {\n sql += \" (\";\n for (let j = 0; j < cte.columns.length; j++) {\n sql += j > 0 ? \", \" : \"\";\n sql += kq(cte.columns[j].columnName);\n }\n sql += \")\";\n }\n if (cte.query.kind === \"raw\") {\n sql += ` AS (${cleanSql(cte.query.sql)})`;\n bindings.push(...cte.query.bindings);\n } else if (cte.query.kind === \"ast\") {\n const nested = buildRawQuery(cte.query.query, {});\n sql += ` AS (${nested.sql})`;\n bindings.push(...nested.bindings);\n } else {\n assertNever(cte.query);\n }\n }\n sql += \" \";\n }\n\n sql += \"SELECT \";\n const subqueryRenderer = (q: ParsedFindQuery) => buildRawQuery(q, {});\n\n parsed.selects.forEach((s, i) => {\n const maybeDistinct = i === 0 && needsDistinct ? buildDistinctOn(parsed, primary) : \"\";\n const maybeComma = i === parsed.selects.length - 1 ? \"\" : \", \";\n if (typeof s === \"string\") {\n sql += maybeDistinct + s + maybeComma;\n } else if (\"sql\" in s) {\n sql += maybeDistinct + s.sql + maybeComma;\n bindings.push(...s.bindings);\n }\n });\n\n // If we're doing \"select distinct\" for o2m joins, then all order bys must be selects\n if (needsDistinct && parsed.orderBys.length > 0) {\n for (const { alias, column } of parsed.orderBys) {\n sql += `, ${kqDot(alias, column)}`;\n }\n }\n\n // Make sure the primary is first\n sql += ` FROM ${as(primary)}`;\n\n // Then the joins\n for (const t of parsed.tables) {\n if (t.join === \"inner\") {\n sql += ` JOIN ${as(t)} ON ${t.col1} = ${t.col2}`;\n } else if (t.join === \"outer\") {\n sql += ` LEFT OUTER JOIN ${as(t)} ON ${t.col1} = ${t.col2}`;\n } else if (t.join === \"primary\") {\n // handled above\n } else if (t.join === \"lateral\") {\n const { sql: subQ, bindings: subB } = buildRawQuery(t.query, t.settings ?? {});\n sql += ` CROSS JOIN LATERAL (${subQ}) AS ${kq(t.alias)}`;\n bindings.push(...subB);\n } else if (t.join === \"cross\") {\n sql += ` CROSS JOIN ${as(t)}`;\n } else {\n assertNever(t.join);\n }\n }\n\n if (parsed.condition) {\n const where = buildWhereClause(parsed.condition, true, subqueryRenderer);\n if (where) {\n sql += \" WHERE \" + where[0];\n bindings.push(...where[1]);\n }\n }\n\n if (parsed.groupBys && parsed.groupBys.length > 0) {\n sql +=\n \" GROUP BY \" +\n parsed.groupBys.map((gb) => (\"expression\" in gb ? gb.expression : kqDot(gb.alias, gb.column))).join(\", \");\n }\n\n if (parsed.orderBys.length > 0) {\n sql += \" ORDER BY \" + parsed.orderBys.map((ob) => kqDot(ob.alias, ob.column) + \" \" + ob.order).join(\", \");\n }\n\n if (limit !== undefined) {\n sql += ` LIMIT ?`;\n bindings.push(limit);\n }\n if (offset !== undefined) {\n sql += ` OFFSET ?`;\n bindings.push(offset);\n }\n\n return { sql, bindings };\n}\n\nfunction buildDistinctOn(parsed: ParsedFindQuery, primary: ParsedTable): string {\n const columns = [\n // If we have an order by, it needs to be included in the DISTINCT ON\n ...parsed.orderBys.map((ob) => kqDot(ob.alias, ob.column)),\n kqDot(primary.alias, \"id\"),\n ];\n return `DISTINCT ON (${columns.join(\", \")}) `;\n}\n\n/** Creates the `WITH alias (...)` SQL for the given `cte`. */\nexport function buildCteSql(cte: ParsedCteClause): { sql: string; bindings: readonly any[] } {\n const maybeRecursive = cte.recursive ? \"RECURSIVE \" : \"\";\n const maybeColumns = cte.columns ? ` (${cte.columns.map((c) => kq(c.columnName)).join(\", \")})` : \"\";\n const prefix = `WITH ${maybeRecursive}${cte.alias}${maybeColumns} AS`;\n if (cte.query.kind === \"raw\") {\n return {\n sql: `${prefix} (${cleanSql(cte.query.sql)} )`,\n bindings: cte.query.bindings,\n };\n } else if (cte.query.kind === \"ast\") {\n const { sql, bindings } = buildRawQuery(cte.query.query, {});\n return { sql: `${prefix} (${sql})`, bindings };\n } else {\n assertNever(cte.query);\n }\n}\n\nconst as = (t: ParsedTable) => `${kq(t.table)} AS ${kq(t.alias)}`;\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,cACd,QACA,UAC2C;CAC3C,MAAM,EAAE,OAAO,WAAW;CAE1B,MAAM,UAAU,OAAO,OAAO,MAAM,MAAM,EAAE,SAAS,SAAS;CAG9D,MAAM,gBACJ,OAAO,OAAO,MAAM,MAAM,EAAE,SAAS,WAAW,EAAE,aAAa,KAAK,KAEpE,CAAC,OAAO,QAAQ,MAAM,MAAM,OAAO,MAAM,YAAY,EAAE,WAAW,QAAQ,CAAC;CAE7E,IAAI,MAAM;CACV,MAAM,WAAkB,CAAC;CAEzB,IAAI,OAAO,QAAQ,OAAO,KAAK,SAAS,GAAG;EAEzC,MAAM,iBADe,OAAO,KAAK,MAAM,QAAQ,IAAI,SACjB,IAAI,eAAe;EACrD,OAAO,OAAO;EACd,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK,QAAQ,KAAK;GAC3C,MAAM,MAAM,OAAO,KAAK;GACxB,OAAO,IAAI,IAAI,OAAO;GACtB,OAAO,IAAI,IAAI;GACf,IAAI,IAAI,SAAS;IACf,OAAO;IACP,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KAAK;KAC3C,OAAO,IAAI,IAAI,OAAO;KACtB,OAAOA,6BAAAA,GAAG,IAAI,QAAQ,EAAE,CAAC,UAAU;IACrC;IACA,OAAO;GACT;GACA,IAAI,IAAI,MAAM,SAAS,OAAO;IAC5B,OAAO,QAAQC,cAAAA,SAAS,IAAI,MAAM,GAAG,EAAE;IACvC,SAAS,KAAK,GAAG,IAAI,MAAM,QAAQ;GACrC,OAAO,IAAI,IAAI,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AAa;CACjE,IAAI,IAAI,MAAM,SAAS,OACrB,OAAO;EACL,KAAK,GAAG,OAAO,IAAIC,cAAAA,SAAS,IAAI,MAAM,GAAG,EAAE;EAC3C,UAAU,IAAI,MAAM;CACtB;MACK,IAAI,IAAI,MAAM,SAAS,OAAO;EACnC,MAAM,EAAE,KAAK,aAAa,cAAc,IAAI,MAAM,OAAO,CAAC,CAAC;EAC3D,OAAO;GAAE,KAAK,GAAG,OAAO,IAAI,IAAI;GAAI;EAAS;CAC/C,OACE,cAAA,YAAY,IAAI,KAAK;AAEzB;AAEA,MAAM,MAAM,MAAmB,GAAGD,6BAAAA,GAAG,EAAE,KAAK,EAAE,MAAMA,6BAAAA,GAAG,EAAE,KAAK"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParsedCteClause, ParsedFindQuery } from "
|
|
2
|
-
//#region src/
|
|
1
|
+
import { ParsedCteClause, ParsedFindQuery } from "./QueryParser.cjs";
|
|
2
|
+
//#region src/queries/find/buildFindQuery.d.ts
|
|
3
3
|
type QuerySettings = {
|
|
4
4
|
limit?: number;
|
|
5
5
|
offset?: number;
|
|
@@ -21,4 +21,4 @@ declare function buildCteSql(cte: ParsedCteClause): {
|
|
|
21
21
|
};
|
|
22
22
|
//#endregion
|
|
23
23
|
export { buildCteSql, buildRawQuery };
|
|
24
|
-
//# sourceMappingURL=
|
|
24
|
+
//# sourceMappingURL=buildFindQuery.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFindQuery.d.cts","names":[],"sources":["../../../src/queries/find/buildFindQuery.ts"],"mappings":";;KAKK;EAAkB;EAAgB;;;;;;;;iBAQvB,cACd,QAAQ,iBACR,UAAU;EACP;EAAa;;;iBA+HF,YAAY,KAAK;EAAoB;EAAa"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParsedCteClause, ParsedFindQuery } from "
|
|
2
|
-
//#region src/
|
|
1
|
+
import { ParsedCteClause, ParsedFindQuery } from "./QueryParser.mjs";
|
|
2
|
+
//#region src/queries/find/buildFindQuery.d.ts
|
|
3
3
|
type QuerySettings = {
|
|
4
4
|
limit?: number;
|
|
5
5
|
offset?: number;
|
|
@@ -21,4 +21,4 @@ declare function buildCteSql(cte: ParsedCteClause): {
|
|
|
21
21
|
};
|
|
22
22
|
//#endregion
|
|
23
23
|
export { buildCteSql, buildRawQuery };
|
|
24
|
-
//# sourceMappingURL=
|
|
24
|
+
//# sourceMappingURL=buildFindQuery.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFindQuery.d.mts","names":[],"sources":["../../../src/queries/find/buildFindQuery.ts"],"mappings":";;KAKK;EAAkB;EAAgB;;;;;;;;iBAQvB,cACd,QAAQ,iBACR,UAAU;EACP;EAAa;;;iBA+HF,YAAY,KAAK;EAAoB;EAAa"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { kq, kqDot } from "../keywords.js";
|
|
2
|
-
import { assertNever, cleanSql } from "
|
|
3
|
-
import { buildWhereClause } from "
|
|
4
|
-
|
|
5
|
-
//#region src/drivers/buildRawQuery.ts
|
|
1
|
+
import { kq, kqDot } from "../sql/keywords.js";
|
|
2
|
+
import { assertNever, cleanSql } from "../../utils.js";
|
|
3
|
+
import { buildWhereClause } from "../renderConditions.js";
|
|
4
|
+
//#region src/queries/find/buildFindQuery.ts
|
|
6
5
|
/**
|
|
7
6
|
* Transforms `ParsedFindQuery` into a raw SQL string.
|
|
8
7
|
*
|
|
@@ -108,4 +107,4 @@ const as = (t) => `${kq(t.table)} AS ${kq(t.alias)}`;
|
|
|
108
107
|
//#endregion
|
|
109
108
|
export { buildCteSql, buildRawQuery };
|
|
110
109
|
|
|
111
|
-
//# sourceMappingURL=
|
|
110
|
+
//# sourceMappingURL=buildFindQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFindQuery.js","names":[],"sources":["../../../src/queries/find/buildFindQuery.ts"],"sourcesContent":["import { assertNever, cleanSql } from \"../../utils.ts\";\nimport { buildWhereClause } from \"../renderConditions.ts\";\nimport { kq, kqDot } from \"../sql/keywords.ts\";\nimport type { ParsedCteClause, ParsedFindQuery, ParsedTable } from \"./QueryParser.ts\";\n\ntype QuerySettings = { limit?: number; offset?: number };\n\n/**\n * Transforms `ParsedFindQuery` into a raw SQL string.\n *\n * In theory this should be implemented within each Driver, but the logic will be largely\n * the same for different dbs.\n */\nexport function buildRawQuery(\n parsed: ParsedFindQuery,\n settings: QuerySettings,\n): { sql: string; bindings: readonly any[] } {\n const { limit, offset } = settings;\n\n const primary = parsed.tables.find((t) => t.join === \"primary\")!;\n\n // If we're doing o2m joins, add a `DISTINCT` clause to avoid duplicates\n const needsDistinct =\n parsed.tables.some((t) => t.join === \"outer\" && t.distinct !== false) &&\n // If this is a `findCount`, it will rewrite the `select` to have its own distinct\n !parsed.selects.find((s) => typeof s === \"string\" && s.startsWith(\"count(\"));\n\n let sql = \"\";\n const bindings: any[] = [];\n\n if (parsed.ctes && parsed.ctes.length > 0) {\n const hasRecursive = parsed.ctes.some((cte) => cte.recursive);\n const maybeRecursive = hasRecursive ? \" RECURSIVE\" : \"\";\n sql += `WITH${maybeRecursive}`;\n for (let i = 0; i < parsed.ctes.length; i++) {\n const cte = parsed.ctes[i];\n sql += i > 0 ? \", \" : \"\";\n sql += ` ${cte.alias}`;\n if (cte.columns) {\n sql += \" (\";\n for (let j = 0; j < cte.columns.length; j++) {\n sql += j > 0 ? \", \" : \"\";\n sql += kq(cte.columns[j].columnName);\n }\n sql += \")\";\n }\n if (cte.query.kind === \"raw\") {\n sql += ` AS (${cleanSql(cte.query.sql)})`;\n bindings.push(...cte.query.bindings);\n } else if (cte.query.kind === \"ast\") {\n const nested = buildRawQuery(cte.query.query, {});\n sql += ` AS (${nested.sql})`;\n bindings.push(...nested.bindings);\n } else {\n assertNever(cte.query);\n }\n }\n sql += \" \";\n }\n\n sql += \"SELECT \";\n const subqueryRenderer = (q: ParsedFindQuery) => buildRawQuery(q, {});\n\n parsed.selects.forEach((s, i) => {\n const maybeDistinct = i === 0 && needsDistinct ? buildDistinctOn(parsed, primary) : \"\";\n const maybeComma = i === parsed.selects.length - 1 ? \"\" : \", \";\n if (typeof s === \"string\") {\n sql += maybeDistinct + s + maybeComma;\n } else if (\"sql\" in s) {\n sql += maybeDistinct + s.sql + maybeComma;\n bindings.push(...s.bindings);\n }\n });\n\n // If we're doing \"select distinct\" for o2m joins, then all order bys must be selects\n if (needsDistinct && parsed.orderBys.length > 0) {\n for (const { alias, column } of parsed.orderBys) {\n sql += `, ${kqDot(alias, column)}`;\n }\n }\n\n // Make sure the primary is first\n sql += ` FROM ${as(primary)}`;\n\n // Then the joins\n for (const t of parsed.tables) {\n if (t.join === \"inner\") {\n sql += ` JOIN ${as(t)} ON ${t.col1} = ${t.col2}`;\n } else if (t.join === \"outer\") {\n sql += ` LEFT OUTER JOIN ${as(t)} ON ${t.col1} = ${t.col2}`;\n } else if (t.join === \"primary\") {\n // handled above\n } else if (t.join === \"lateral\") {\n const { sql: subQ, bindings: subB } = buildRawQuery(t.query, t.settings ?? {});\n sql += ` CROSS JOIN LATERAL (${subQ}) AS ${kq(t.alias)}`;\n bindings.push(...subB);\n } else if (t.join === \"cross\") {\n sql += ` CROSS JOIN ${as(t)}`;\n } else {\n assertNever(t.join);\n }\n }\n\n if (parsed.condition) {\n const where = buildWhereClause(parsed.condition, true, subqueryRenderer);\n if (where) {\n sql += \" WHERE \" + where[0];\n bindings.push(...where[1]);\n }\n }\n\n if (parsed.groupBys && parsed.groupBys.length > 0) {\n sql +=\n \" GROUP BY \" +\n parsed.groupBys.map((gb) => (\"expression\" in gb ? gb.expression : kqDot(gb.alias, gb.column))).join(\", \");\n }\n\n if (parsed.orderBys.length > 0) {\n sql += \" ORDER BY \" + parsed.orderBys.map((ob) => kqDot(ob.alias, ob.column) + \" \" + ob.order).join(\", \");\n }\n\n if (limit !== undefined) {\n sql += ` LIMIT ?`;\n bindings.push(limit);\n }\n if (offset !== undefined) {\n sql += ` OFFSET ?`;\n bindings.push(offset);\n }\n\n return { sql, bindings };\n}\n\nfunction buildDistinctOn(parsed: ParsedFindQuery, primary: ParsedTable): string {\n const columns = [\n // If we have an order by, it needs to be included in the DISTINCT ON\n ...parsed.orderBys.map((ob) => kqDot(ob.alias, ob.column)),\n kqDot(primary.alias, \"id\"),\n ];\n return `DISTINCT ON (${columns.join(\", \")}) `;\n}\n\n/** Creates the `WITH alias (...)` SQL for the given `cte`. */\nexport function buildCteSql(cte: ParsedCteClause): { sql: string; bindings: readonly any[] } {\n const maybeRecursive = cte.recursive ? \"RECURSIVE \" : \"\";\n const maybeColumns = cte.columns ? ` (${cte.columns.map((c) => kq(c.columnName)).join(\", \")})` : \"\";\n const prefix = `WITH ${maybeRecursive}${cte.alias}${maybeColumns} AS`;\n if (cte.query.kind === \"raw\") {\n return {\n sql: `${prefix} (${cleanSql(cte.query.sql)} )`,\n bindings: cte.query.bindings,\n };\n } else if (cte.query.kind === \"ast\") {\n const { sql, bindings } = buildRawQuery(cte.query.query, {});\n return { sql: `${prefix} (${sql})`, bindings };\n } else {\n assertNever(cte.query);\n }\n}\n\nconst as = (t: ParsedTable) => `${kq(t.table)} AS ${kq(t.alias)}`;\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,cACd,QACA,UAC2C;CAC3C,MAAM,EAAE,OAAO,WAAW;CAE1B,MAAM,UAAU,OAAO,OAAO,MAAM,MAAM,EAAE,SAAS,SAAS;CAG9D,MAAM,gBACJ,OAAO,OAAO,MAAM,MAAM,EAAE,SAAS,WAAW,EAAE,aAAa,KAAK,KAEpE,CAAC,OAAO,QAAQ,MAAM,MAAM,OAAO,MAAM,YAAY,EAAE,WAAW,QAAQ,CAAC;CAE7E,IAAI,MAAM;CACV,MAAM,WAAkB,CAAC;CAEzB,IAAI,OAAO,QAAQ,OAAO,KAAK,SAAS,GAAG;EAEzC,MAAM,iBADe,OAAO,KAAK,MAAM,QAAQ,IA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AACzB;AAEA,SAAS,gBAAgB,QAAyB,SAA8B;CAM9E,OAAO,gBAAgB,CAHrB,GAAG,OAAO,SAAS,KAAK,OAAO,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,GACzD,MAAM,QAAQ,OAAO,IAAI,CAEE,CAAC,CAAC,KAAK,IAAI,EAAE;AAC5C;;AAGA,SAAgB,YAAY,KAAiE;CAC3F,MAAM,iBAAiB,IAAI,YAAY,eAAe;CACtD,MAAM,eAAe,IAAI,UAAU,KAAK,IAAI,QAAQ,KAAK,MAAM,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,KAAK;CACjG,MAAM,SAAS,QAAQ,iBAAiB,IAAI,QAAQ,aAAa;CACjE,IAAI,IAAI,MAAM,SAAS,OACrB,OAAO;EACL,KAAK,GAAG,OAAO,IAAI,SAAS,IAAI,MAAM,GAAG,EAAE;EAC3C,UAAU,IAAI,MAAM;CACtB;MACK,IAAI,IAAI,MAAM,SAAS,OAAO;EACnC,MAAM,EAAE,KAAK,aAAa,cAAc,IAAI,MAAM,OAAO,CAAC,CAAC;EAC3D,OAAO;GAAE,KAAK,GAAG,OAAO,IAAI,IAAI;GAAI;EAAS;CAC/C,OACE,YAAY,IAAI,KAAK;AAEzB;AAEA,MAAM,MAAM,MAAmB,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,KAAK"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_configure = require("
|
|
3
|
-
|
|
4
|
-
//#region src/scopes.ts
|
|
2
|
+
const require_configure = require("../../configure.cjs");
|
|
3
|
+
//#region src/queries/find/scopes.ts
|
|
5
4
|
/**
|
|
6
5
|
* Discriminates an {@link AliasFn} result that is a {@link ScopeJoinFilter} from a bare
|
|
7
6
|
* condition / condition array.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.cjs","names":["maybeGetMetadataForType","#ops","#resolver"],"sources":["../../../src/queries/find/scopes.ts"],"sourcesContent":["import { maybeGetMetadataForType } from \"../../configure.ts\";\nimport type { Entity } from \"../../Entity.ts\";\nimport type { EntityManager, FindFilterOptions, MaybeAbstractEntityConstructor } from \"../../EntityManager.ts\";\nimport type { LoadHint, Loaded } from \"../../loadHints.ts\";\nimport type { OrderOf } from \"../../typeMap.ts\";\nimport type { Alias } from \"./Aliases.ts\";\nimport type {\n ExpressionCondition,\n ExpressionFilter,\n FilterAndSettings,\n FilterWithAlias,\n FindFilter,\n} from \"./EntityFilter.ts\";\nimport type { GraphQLFilterWithAlias } from \"./EntityGraphQLFilter.ts\";\n\n/**\n * A scope fragment that introduces its own join aliases: a join tree plus conditions\n * that reference the aliases it binds.\n *\n * Lets a scope express predicates a plain nested filter can't, e.g. a top-level `OR`\n * spanning two different joined tables. Both halves are required — the `where` tree binds\n * the aliases (via `as:`) that `conditions` reference, so neither is meaningful alone.\n */\nexport interface ScopeJoinFilter<T extends Entity> {\n where: FilterWithAlias<T>;\n conditions: ExpressionFilter;\n}\n\n/** A predicate expressed against a bound alias, i.e. `(a) => a.age.gte(18)`. */\nexport type AliasFn<T extends Entity> = (\n a: Alias<T>,\n) => ExpressionCondition | ExpressionCondition[] | ScopeJoinFilter<T>;\n\n/**\n * Discriminates an {@link AliasFn} result that is a {@link ScopeJoinFilter} from a bare\n * condition / condition array.\n *\n * A `ScopeJoinFilter` is the only `AliasFn` return that carries both `where` and `conditions`\n * keys; `ExpressionFilter` (`and`/`or`), `ColumnCondition`/`RawCondition` (`kind`), and arrays\n * have neither, so the two-key check is unambiguous.\n */\nexport function isScopeJoinFilter<T extends Entity>(\n result: ExpressionCondition | ExpressionCondition[] | ScopeJoinFilter<T>,\n): result is ScopeJoinFilter<T> {\n return (\n typeof result === \"object\" &&\n result !== null &&\n !Array.isArray(result) &&\n \"where\" in result &&\n \"conditions\" in result\n );\n}\n\n/**\n * The fluent builder to either a) terminate/invoke or b) chain scope methods.\n *\n * I.e. `Author.adult` is a ScopeQuery that can either do `.find` or `.popular`.\n *\n * This `ScopeQuery` is just the terminal/invocation methods, the `.popular` methods\n * are chained on via the `Scope` mapped type below.\n */\nexport interface ScopeQuery<T extends Entity> {\n /**\n * ANDs an ad-hoc filter onto the scope, i.e. `Author.adult.where({ firstName: \"a1\" })`.\n *\n * Accepts either a plain find filter (`{ field: value }`) or an alias callback\n * (`(a) => a.field.eq(value)`) and appends it to the recorded ops — multiple\n * `.where(...)` calls on the same field AND together rather than override.\n */\n where(where: FilterWithAlias<T>): this;\n where(fn: AliasFn<T>): this;\n\n /**\n * Appends an `orderBy` to the scope, i.e. `Author.adult.orderBy({ age: \"DESC\" })`.\n *\n * Chained `.orderBy(...)` calls **accumulate** (the resulting query has every recorded\n * orderBy in declaration order), unlike `.limit`/`.offset`/`.softDeletes` which are\n * last-wins. To replace an existing scope's ordering, pass `orderBy` to the terminal\n * `.find(em, { orderBy: ... })` instead — terminal options override the scope's.\n */\n orderBy(orderBy: OrderOf<T> | OrderOf<T>[]): this;\n\n /**\n * Sets the row limit on the scope, i.e. `Author.adult.limit(10)`.\n *\n * Chained `.limit(...)` calls are last-wins — only the most recent value survives compile.\n */\n limit(limit: number): this;\n\n /**\n * Sets the row offset on the scope, i.e. `Author.adult.offset(10)`.\n *\n * Chained `.offset(...)` calls are last-wins — only the most recent value survives compile.\n */\n offset(offset: number): this;\n\n /**\n * Overrides Joist's default soft-delete handling for this query, i.e.\n * `Author.adult.softDeletes(\"include\")` to see soft-deleted rows.\n *\n * Chained `.softDeletes(...)` calls are last-wins. The effective value also gates\n * how `.where({ relation: ... })` filters that touch soft-delete-aware entities are\n * composed at compile time.\n */\n softDeletes(softDeletes: \"include\" | \"exclude\"): this;\n\n /**\n * Runs the scope against `em`, returning all matching rows.\n *\n * Terminal options (`orderBy`, `limit`, `offset`, `softDeletes`) passed here\n * **override** anything the scope recorded via `.orderBy(...)`, `.limit(...)`, etc.;\n * `conditions` passed here are ANDed with the scope's compiled conditions rather than\n * replacing them. To extend the scope's ordering instead of replacing it, chain\n * `.orderBy(...)` before `.find(em)`.\n */\n find(em: EntityManager): Promise<T[]>;\n find<const H extends LoadHint<T>>(\n em: EntityManager,\n opts?: FindFilterOptions<T> & { populate?: H },\n ): Promise<Loaded<T, H>[]>;\n\n /** Like {@link find} but returns a single match or `undefined`. Same options precedence as `find`. */\n findOne(em: EntityManager): Promise<T | undefined>;\n findOne<const H extends LoadHint<T>>(\n em: EntityManager,\n opts?: FindFilterOptions<T> & { populate?: H },\n ): Promise<Loaded<T, H> | undefined>;\n\n /** Like {@link findOne} but throws if no row matches. Same options precedence as `find`. */\n findOneOrFail(em: EntityManager): Promise<T>;\n findOneOrFail<const H extends LoadHint<T>>(\n em: EntityManager,\n opts?: FindFilterOptions<T> & { populate?: H },\n ): Promise<Loaded<T, H>>;\n\n /**\n * Returns the count of rows matching the scope.\n *\n * Recorded `orderBy`/`limit`/`offset` ops are dropped (they're meaningless for a count);\n * `softDeletes` and conditions still apply.\n */\n findCount(em: EntityManager): Promise<number>;\n\n /**\n * Returns the tagged ids of rows matching the scope.\n *\n * Like {@link findCount}, recorded `orderBy`/`limit`/`offset` ops are dropped.\n */\n findIds(em: EntityManager): Promise<string[]>;\n\n /**\n * Compiles the scope into Joist's `FilterAndSettings` shape for passing to other APIs\n * or for inspection in tests.\n *\n * Useful primarily for debugging — the returned shape captures whatever the terminal\n * `find` methods would have sent to `em.find`, before terminal-options precedence is\n * applied.\n */\n toFindArgs(): FilterAndSettings<T>;\n}\n\n/** A scope for entity `T`, with chainable named accessors supplied by `S`. */\nexport type Scope<T extends Entity, S = {}> = ScopeQuery<T> & S;\n\n/**\n * A per-entity, pre-typed function for declaring scopes.\n *\n * I.e. this is the type of the `import { authorScope as scope }` that entity files\n * use to declare their scopes.\n *\n * Because of the `authorScope as scope` rename, we can bake into the API that this\n * is the Author entity, and so simplify its usage.\n */\nexport interface ScopeFn<T extends Entity, R extends Scope<T>> {\n /** Defines a scope based on a filter condition, i.e. `scope({ name: \"John\" })` or `scope(a => a.name.eq(\"John\")`. */\n (arg: FilterWithAlias<T> | AliasFn<T>): R;\n /** Defines a parametrized filter, i.e. `scope(name => ({ name: { startsWith: name } }))`. */\n fn<A extends unknown[]>(fn: (...args: A) => FilterWithAlias<T> | AliasFn<T>): (...args: A) => R;\n}\n\n/** A scope fragment that can be expanded against any current query alias. */\nexport type ScopeFilterFragment<T extends Entity> =\n | { kind: \"alias\"; fn: AliasFn<T> }\n | { kind: \"filter\"; filter: FilterWithAlias<T> };\n\n/**\n * Fully-expanded scope contents, with named refs resolved and settings collapsed.\n *\n * Deliberately *not* a `ParsedFindQuery`, even though they look adjacent: this is the pre-parse,\n * alias-free *input* we feed into `parseFindQuery`, not its alias-committed AST output. Two reasons\n * the distinction matters:\n * - `fragments` are un-parsed DSL — filter objects plus un-invoked `AliasFn` closures — so the same\n * scope can be re-rooted onto the query's primary alias (`Author.adult.find(em)`) or onto a joined\n * relation alias (`em.find(Book, { author: Author.adult })`). A `ParsedFindQuery` has already baked\n * in concrete aliases like `a`/`b1` and could only be reused via alias-rewrite surgery.\n * - keeping `fragments` as a *list* (rather than one merged condition tree) preserves independent-EXISTS\n * semantics: `.where({ books: ... }).where({ books: ... })` must stay two predicates — one EXISTS each —\n * which a collapsed `ParsedFindQuery.condition` can no longer be split back into.\n */\nexport interface ResolvedScope<T extends Entity> {\n fragments: ScopeFilterFragment<T>[];\n orderBys: OrderOf<T>[];\n limit: number | undefined;\n offset: number | undefined;\n softDeletes: \"include\" | \"exclude\" | undefined;\n}\n\ninterface EntityCstrResolver<T extends Entity> {\n entityType: string;\n /** Returns undefined while entity static fields run, before `configureMetadata` has populated the type map. */\n maybeGet(): MaybeAbstractEntityConstructor<T> | undefined;\n}\ntype FindOptionsWithPopulate<T extends Entity> = FindFilterOptions<T> & { populate?: LoadHint<T> };\n\ntype ScopeOp<T extends Entity> =\n | ScopeFilterFragment<T>\n | { kind: \"orderBy\"; orderBy: OrderOf<T> | OrderOf<T>[] }\n | { kind: \"limit\"; limit: number }\n | { kind: \"offset\"; offset: number }\n | { kind: \"softDeletes\"; value: \"include\" | \"exclude\" }\n | { kind: \"ref\"; name: string; args?: unknown[] };\n\n/** A named-scope reference captured during chaining, i.e. `.popular` in `Author.adult.popular`. */\ntype ScopeRefOp<T extends Entity> = Extract<ScopeOp<T>, { kind: \"ref\" }>;\n\n// Use a symbol so stored scope fragments cannot collide with user-defined scope names.\nconst kOps = Symbol(\"scopeOps\");\nconst kResolver = Symbol(\"scopeResolver\");\nconst kWithScopeOp = Symbol(\"scopeWithOp\");\n// Symbol-keyed so it can't collide with a user's named scope (e.g. `Author.resolve`), which the\n// proxy would otherwise treat as a chained ref.\nconst kResolve = Symbol(\"scopeResolve\");\n\n/** The internal-only view of a scope proxy: its symbol-keyed members, hidden from the public `Scope<T>`. */\ntype ScopeInternalApi<T extends Entity> = Scope<T> & {\n readonly [kOps]: ScopeOp<T>[];\n readonly [kResolver]: EntityCstrResolver<T>;\n [kResolve](): ResolvedScope<T>;\n};\n\n/** Creates a per-entity, pre-typed scope function. */\nexport function newScopeFn<T extends Entity, R extends Scope<T>>(entityType: string): ScopeFn<T, R> {\n // We won't immediately have access to the EntityMetadata during static field assignment, so provide a lazy handle\n const resolver: EntityCstrResolver<T> = {\n entityType,\n maybeGet: () => maybeGetMetadataForType<T>(entityType)?.cstr,\n };\n // Create the scopeFn\n function scopeFn(arg: FilterWithAlias<T> | AliasFn<T>): R {\n return newScope(resolver, [toOp(arg)]) as R;\n }\n // But then also add the `.fn(...)` for parameterized scopes\n scopeFn.fn = function scopeFn<A extends unknown[]>(\n fn: (...args: A) => FilterWithAlias<T> | AliasFn<T>,\n ): (...args: A) => R {\n return (...args) => newScope(resolver, [toOp(fn(...args))]) as R;\n };\n return scopeFn;\n}\n\n/** Returns true if `value` is one of our scope proxies. */\nexport function isScope<T extends Entity>(value: unknown): value is Scope<T> {\n // A scope is a callable Proxy (so parameterized refs like `Author.adult.named(\"a\")` work), so it's\n // always `typeof === \"function\"`; that guard also keeps the `in` checks from throwing on primitives.\n return typeof value === \"function\" && kOps in value && kResolver in value;\n}\n\n/** Resolves a scope proxy into ordered filter fragments plus collapsed settings. */\nexport function resolveScope<T extends Entity>(scope: Scope<T>): ResolvedScope<T> {\n return asScopeInternalApi(scope)[kResolve]();\n}\n\n/**\n * Returns true for find filters that select every row of the entity type, i.e. an empty `{}` filter\n * or a scope that resolved to no fragments.\n *\n * Used by `em.findCount` and the count dataloader to short-circuit in-memory delete adjustments, which\n * are only safe when the query has no `where`/`conditions` to evaluate created/deleted entities against.\n */\nexport function isSelectAllFilter<T extends Entity>(\n where: FindFilter<T> | GraphQLFilterWithAlias<T>,\n conditions: ExpressionFilter | undefined,\n): boolean {\n if (conditions !== undefined) return false;\n if (isScope<T>(where)) return resolveScope(where).fragments.length === 0;\n return Object.keys(where).length === 0;\n}\n\n/**\n * Creates an immutable scope proxy with `ops` as its current scope fragments.\n *\n * The proxy target is a function so the proxy is callable (for parameterized refs\n * like `Author.adult.named(\"a\")`); unknown property accesses always record a `ref`\n * op, with validation against the entity constructor deferred until `compile` runs.\n */\nfunction newScope<T extends Entity>(resolver: EntityCstrResolver<T>, ops: ScopeOp<T>[]): Scope<T> {\n const terminals = new ScopeTerminals(resolver, ops);\n function callable() {}\n Object.defineProperty(callable, kOps, { value: ops });\n Object.defineProperty(callable, kResolver, { value: resolver });\n return new Proxy(callable, {\n get(target, prop) {\n if (prop === kOps || prop === kResolver) return Reflect.get(target, prop);\n if (typeof prop === \"symbol\" || prop in terminals) {\n const value = Reflect.get(terminals, prop, terminals);\n return typeof value === \"function\" ? value.bind(terminals) : value;\n }\n // `await scope` probes `.then`; returning undefined lets await resolve to the scope itself\n // instead of treating the proxy as a thenable.\n if (prop === \"then\") return undefined;\n return newScope(resolver, [...ops, { kind: \"ref\", name: prop }]);\n },\n apply(_target, _thisArg, args: unknown[]) {\n // Invoked for chained parameterized refs, i.e. the `(\"a\")` in `Author.adult.named(\"a\")`.\n const lastOp = ops[ops.length - 1];\n if (lastOp?.kind !== \"ref\") throw new Error(`Scope is not parameterized`);\n return newScope(resolver, [...ops.slice(0, -1), { ...lastOp, args }]);\n },\n }) as unknown as Scope<T>;\n}\n\n/**\n * Concrete builder/terminal methods for a scope proxy.\n *\n * The outer proxy handles dynamic named-scope access like `.popular`; this class handles\n * fixed methods like `.where`, `.find`, and `.toFindArgs`.\n */\nclass ScopeTerminals<T extends Entity> {\n readonly #ops: ScopeOp<T>[];\n readonly #resolver: EntityCstrResolver<T>;\n\n constructor(resolver: EntityCstrResolver<T>, ops: ScopeOp<T>[]) {\n this.#resolver = resolver;\n this.#ops = ops;\n }\n\n get [kOps](): ScopeOp<T>[] {\n return this.#ops;\n }\n\n /** Flattens our recorded ops (resolving named refs, collapsing settings) into a {@link ResolvedScope}. */\n [kResolve](): ResolvedScope<T> {\n return resolveScopeOps(this.#resolver, this.#ops);\n }\n\n where(arg: FilterWithAlias<T> | AliasFn<T>): Scope<T> {\n return this[kWithScopeOp](toOp(arg));\n }\n\n orderBy(orderBy: OrderOf<T> | OrderOf<T>[]): Scope<T> {\n return this[kWithScopeOp]({ kind: \"orderBy\", orderBy });\n }\n\n limit(limit: number): Scope<T> {\n return this[kWithScopeOp]({ kind: \"limit\", limit });\n }\n\n offset(offset: number): Scope<T> {\n return this[kWithScopeOp]({ kind: \"offset\", offset });\n }\n\n softDeletes(value: \"include\" | \"exclude\"): Scope<T> {\n return this[kWithScopeOp]({ kind: \"softDeletes\", value });\n }\n\n toFindArgs(): FilterAndSettings<T> {\n return compile(this.#resolver, this.#ops);\n }\n\n find(em: EntityManager): Promise<T[]>;\n find<const H extends LoadHint<T>>(\n em: EntityManager,\n opts?: FindOptionsWithPopulate<T> & { populate?: H },\n ): Promise<Loaded<T, H>[]>;\n find(em: EntityManager, opts?: FindOptionsWithPopulate<T>): Promise<T[]> {\n const args = compile(this.#resolver, this.#ops);\n return em.find(resolveCstr(this.#resolver), args.where, toFindOptions(args, opts));\n }\n\n findOne(em: EntityManager): Promise<T | undefined>;\n findOne<const H extends LoadHint<T>>(\n em: EntityManager,\n opts?: FindOptionsWithPopulate<T> & { populate?: H },\n ): Promise<Loaded<T, H> | undefined>;\n findOne(em: EntityManager, opts?: FindOptionsWithPopulate<T>): Promise<T | undefined> {\n const args = compile(this.#resolver, this.#ops);\n return em.findOne(resolveCstr(this.#resolver), args.where, toFindOptions(args, opts));\n }\n\n findOneOrFail(em: EntityManager): Promise<T>;\n findOneOrFail<const H extends LoadHint<T>>(\n em: EntityManager,\n opts?: FindOptionsWithPopulate<T> & { populate?: H },\n ): Promise<Loaded<T, H>>;\n findOneOrFail(em: EntityManager, opts?: FindOptionsWithPopulate<T>): Promise<T> {\n const args = compile(this.#resolver, this.#ops);\n return em.findOneOrFail(resolveCstr(this.#resolver), args.where, toFindOptions(args, opts));\n }\n\n findCount(em: EntityManager): Promise<number> {\n const args = compile(this.#resolver, this.#ops);\n return em.findCount(resolveCstr(this.#resolver), args.where, toCountOptions(args));\n }\n\n findIds(em: EntityManager): Promise<string[]> {\n const args = compile(this.#resolver, this.#ops);\n return em.findIds(resolveCstr(this.#resolver), args.where, toCountOptions(args));\n }\n\n /** Returns a new scope with one more recorded operation. */\n [kWithScopeOp](op: ScopeOp<T>): Scope<T> {\n return newScope(this.#resolver, [...this.#ops, op]);\n }\n}\n\n/** Compiles the ordered scope ops into Joist's existing find args shape. */\nfunction compile<T extends Entity>(resolver: EntityCstrResolver<T>, ops: ScopeOp<T>[]): FilterAndSettings<T> {\n const resolved = resolveScopeOps(resolver, ops);\n\n return {\n // A scope is a valid `FindFilter` `where`, so `em.find` re-parses & expands its fragments.\n where: newScope(resolver, resolved.fragments),\n orderBy: resolved.orderBys.length ? resolved.orderBys : undefined,\n limit: resolved.limit,\n offset: resolved.offset,\n softDeletes: resolved.softDeletes,\n };\n}\n\n/** Resolves ordered scope ops into filter fragments and root-only settings. */\nfunction resolveScopeOps<T extends Entity>(resolver: EntityCstrResolver<T>, ops: ScopeOp<T>[]): ResolvedScope<T> {\n const fragments: ScopeFilterFragment<T>[] = [];\n const orderBys: OrderOf<T>[] = [];\n const refArgKeys = new WeakMap<object, number>();\n const nextRefArgKey = { value: 0 };\n let limit: number | undefined;\n let offset: number | undefined;\n let softDeletes: \"include\" | \"exclude\" | undefined;\n\n function expand(currentOps: ScopeOp<T>[], seen: Set<string>): void {\n for (const op of currentOps) {\n switch (op.kind) {\n case \"alias\":\n case \"filter\":\n fragments.push(op);\n break;\n case \"orderBy\":\n if (Array.isArray(op.orderBy)) orderBys.push(...op.orderBy);\n else orderBys.push(op.orderBy);\n break;\n case \"limit\":\n limit = op.limit;\n break;\n case \"offset\":\n offset = op.offset;\n break;\n case \"softDeletes\":\n softDeletes = op.value;\n break;\n case \"ref\": {\n const key = scopeRefKey(op, refArgKeys, nextRefArgKey);\n if (seen.has(key)) break;\n seen.add(key);\n expand(scopeOpsForRef(resolver, op), seen);\n break;\n }\n }\n }\n }\n\n expand(ops, new Set());\n return { fragments, orderBys, limit, offset, softDeletes };\n}\n\n/** Resolves a recorded named-scope ref to its underlying ops. */\nfunction scopeOpsForRef<T extends Entity>(resolver: EntityCstrResolver<T>, op: ScopeRefOp<T>): ScopeOp<T>[] {\n const cstr = resolveCstr(resolver) as MaybeAbstractEntityConstructor<T> & Record<string, unknown>;\n const sibling = cstr[op.name];\n if (op.args) {\n // Scope proxies are also `typeof === \"function\"`, so explicitly reject them via `isScope`.\n if (typeof sibling !== \"function\" || isScope(sibling)) {\n throw new Error(`Scope ${resolver.entityType}.${op.name} is not parameterized`);\n }\n return scopeOpsFromValue(resolver, op.name, (sibling as (...args: unknown[]) => unknown)(...op.args));\n }\n return scopeOpsFromValue(resolver, op.name, sibling);\n}\n\n/** Extracts recorded scope ops from a resolved static field. */\nfunction scopeOpsFromValue<T extends Entity>(\n resolver: EntityCstrResolver<T>,\n name: string,\n value: unknown,\n): ScopeOp<T>[] {\n if (isScope<T>(value)) return asScopeInternalApi(value)[kOps];\n if (value === undefined) throw new Error(`Invalid scope ${resolver.entityType}.${name}`);\n if (typeof value === \"function\") throw new Error(`Scope ${resolver.entityType}.${name} requires arguments`);\n throw new Error(`${resolver.entityType}.${name} is not a scope`);\n}\n\n/** Creates a cycle key for named-scope refs without serializing arbitrary entities/functions. */\nfunction scopeRefKey<T extends Entity>(\n op: ScopeRefOp<T>,\n refArgKeys: WeakMap<object, number>,\n nextRefArgKey: { value: number },\n): string {\n return op.args\n ? `${op.name}(${op.args.map((arg) => scopeRefArgKey(arg, refArgKeys, nextRefArgKey)).join(\",\")})`\n : op.name;\n}\n\n/** Creates a stable per-resolution key for one named-scope argument. */\nfunction scopeRefArgKey(arg: unknown, refArgKeys: WeakMap<object, number>, nextRefArgKey: { value: number }): string {\n if ((typeof arg === \"object\" && arg !== null) || typeof arg === \"function\") {\n let key = refArgKeys.get(arg);\n if (key === undefined) {\n key = nextRefArgKey.value;\n nextRefArgKey.value += 1;\n refArgKeys.set(arg, key);\n }\n return `${typeof arg}:${key}`;\n }\n return `${typeof arg}:${JSON.stringify(String(arg))}`;\n}\n\n/** Narrows a known scope proxy to its internal-only (symbol-keyed) API. */\nfunction asScopeInternalApi<T extends Entity>(scope: Scope<T>): ScopeInternalApi<T> {\n if (!isScope(scope)) throw new Error(\"Invalid scope\");\n return scope as ScopeInternalApi<T>;\n}\n\n/** Resolves the lazy entity constructor. */\nfunction resolveCstr<T extends Entity>(resolver: EntityCstrResolver<T>): MaybeAbstractEntityConstructor<T> {\n const cstr = resolver.maybeGet();\n if (cstr === undefined) throw new Error(`Unknown type ${resolver.entityType}`);\n return cstr;\n}\n\n/** Converts a scope declaration argument into a recorded op. */\nfunction toOp<T extends Entity>(arg: FilterWithAlias<T> | AliasFn<T>): ScopeOp<T> {\n return typeof arg === \"function\"\n ? { kind: \"alias\", fn: arg as AliasFn<T> }\n : { kind: \"filter\", filter: arg as FilterWithAlias<T> };\n}\n\n/**\n * Pulls the option half of `FilterAndSettings` back out for `em.find`.\n *\n * The scope's recorded settings are the defaults; terminal `opts` (orderBy/limit/offset/conditions/\n * populate) override. The scope itself carries no `conditions` — it compiles to a `where` scope that\n * `em.find` expands — so the only conditions are the caller's, which flow through the `...opts` spread.\n */\nfunction toFindOptions<T extends Entity>(\n args: FilterAndSettings<T>,\n opts?: FindOptionsWithPopulate<T>,\n): FindOptionsWithPopulate<T> {\n return { orderBy: args.orderBy, limit: args.limit, offset: args.offset, softDeletes: args.softDeletes, ...opts };\n}\n\n/** Like `toFindOptions`, but drops the `orderBy`/`limit`/`offset` that `findCount`/`findIds` ignore. */\nfunction toCountOptions<T extends Entity>(args: FilterAndSettings<T>): FindFilterOptions<T> {\n return { softDeletes: args.softDeletes };\n}\n"],"mappings":";;;;;;;;;;;AAyCA,SAAgB,kBACd,QAC8B;CAC9B,OACE,OAAO,WAAW,YAClB,WAAW,QACX,CAAC,MAAM,QAAQ,MAAM,KACrB,WAAW,UACX,gBAAgB;AAEpB;AA+KA,MAAM,OAAO,OAAO,UAAU;AAC9B,MAAM,YAAY,OAAO,eAAe;AACxC,MAAM,eAAe,OAAO,aAAa;AAGzC,MAAM,WAAW,OAAO,cAAc;;AAUtC,SAAgB,WAAiD,YAAmC;CAElG,MAAM,WAAkC;EACtC;EACA,gBAAgBA,kBAAAA,wBAA2B,UAAU,CAAC,EAAE;CAC1D;CAEA,SAAS,QAAQ,KAAyC;EACxD,OAAO,SAAS,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC;CACvC;CAEA,QAAQ,KAAK,SAAS,QACpB,IACmB;EACnB,QAAQ,GAAG,SAAS,SAAS,UAAU,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5D;CACA,OAAO;AACT;;AAGA,SAAgB,QAA0B,OAAmC;CAG3E,OAAO,OAAO,UAAU,cAAc,QAAQ,SAAS,aAAa;AACtE;;AAGA,SAAgB,aAA+B,OAAmC;CAChF,OAAO,mBAAmB,KAAK,CAAC,CAAC,SAAS,CAAC;A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G,OAAO,IAAI,GAAG;CAC1B;CACA,OAAO,GAAG,OAAO,IAAI,GAAG,KAAK,UAAU,OAAO,GAAG,CAAC;AACpD;;AAGA,SAAS,mBAAqC,OAAsC;CAClF,IAAI,CAAC,QAAQ,KAAK,GAAG,MAAM,IAAI,MAAM,eAAe;CACpD,OAAO;AACT;;AAGA,SAAS,YAA8B,UAAoE;CACzG,MAAM,OAAO,SAAS,SAAS;CAC/B,IAAI,SAAS,KAAA,GAAW,MAAM,IAAI,MAAM,gBAAgB,SAAS,YAAY;CAC7E,OAAO;AACT;;AAGA,SAAS,KAAuB,KAAkD;CAChF,OAAO,OAAO,QAAQ,aAClB;EAAE,MAAM;EAAS,IAAI;CAAkB,IACvC;EAAE,MAAM;EAAU,QAAQ;CAA0B;AAC1D;;;;;;;;AASA,SAAS,cACP,MACA,MAC4B;CAC5B,OAAO;EAAE,SAAS,KAAK;EAAS,OAAO,KAAK;EAAO,QAAQ,KAAK;EAAQ,aAAa,KAAK;EAAa,GAAG;CAAK;AACjH;;AAGA,SAAS,eAAiC,MAAkD;CAC1F,OAAO,EAAE,aAAa,KAAK,YAAY;AACzC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OrderOf } from "
|
|
2
|
-
import { LoadHint, Loaded } from "./loadHints.cjs";
|
|
3
|
-
import { GraphQLFilterWithAlias } from "./EntityGraphQLFilter.cjs";
|
|
4
|
-
import { EntityManager, FindFilterOptions } from "./EntityManager.cjs";
|
|
5
|
-
import { Entity } from "./Entity.cjs";
|
|
1
|
+
import { OrderOf } from "../../typeMap.cjs";
|
|
6
2
|
import { Alias } from "./Aliases.cjs";
|
|
3
|
+
import { GraphQLFilterWithAlias } from "./EntityGraphQLFilter.cjs";
|
|
7
4
|
import { ExpressionCondition, ExpressionFilter, FilterAndSettings, FilterWithAlias, FindFilter } from "./EntityFilter.cjs";
|
|
8
|
-
|
|
5
|
+
import { LoadHint, Loaded } from "../../loadHints.cjs";
|
|
6
|
+
import { EntityManager, FindFilterOptions } from "../../EntityManager.cjs";
|
|
7
|
+
import { Entity } from "../../Entity.cjs";
|
|
8
|
+
//#region src/queries/find/scopes.d.ts
|
|
9
9
|
/**
|
|
10
10
|
* A scope fragment that introduces its own join aliases: a join tree plus conditions
|
|
11
11
|
* that reference the aliases it binds.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.d.cts","names":[],"sources":["../../../src/queries/find/scopes.ts"],"mappings":";;;;;;;;;;;;;;;;UAuBiB,gBAAgB,UAAU;EACzC,OAAO,gBAAgB;EACvB,YAAY;;;KAIF,QAAQ,UAAU,WAC5B,GAAG,MAAM,OACN,sBAAsB,wBAAwB,gBAAgB;;;;;;;;;iBAUnD,kBAAkB,UAAU,QAC1C,QAAQ,sBAAsB,wBAAwB,gBAAgB,KACrE,UAAU,gBAAgB;;;;;;;;;UAkBZ,WAAW,UAAU;;;;;;;;EAQpC,MAAM,OAAO,gBAAgB;EAC7B,MAAM,IAAI,QAAQ;;;;;;;;;EAUlB,QAAQ,SAAS,QAAQ,KAAK,QAAQ;;;;;;EAOtC,MAAM;;;;;;EAON,OAAO;;;;;;;;;EAUP,YAAY;;;;;;;;;;EAWZ,KAAK,IAAI,gBAAgB,QAAQ;EACjC,WAAW,UAAU,SAAS,IAC5B,IAAI,eACJ,OAAO,kBAAkB;IAAO,WAAW;MAC1C,QAAQ,OAAO,GAAG;;EAGrB,QAAQ,IAAI,gBAAgB,QAAQ;EACpC,cAAc,UAAU,SAAS,IAC/B,IAAI,eACJ,OAAO,kBAAkB;IAAO,WAAW;MAC1C,QAAQ,OAAO,GAAG;;EAGrB,cAAc,IAAI,gBAAgB,QAAQ;EAC1C,oBAAoB,UAAU,SAAS,IACrC,IAAI,eACJ,OAAO,kBAAkB;IAAO,WAAW;MAC1C,QAAQ,OAAO,GAAG;;;;;;;EAQrB,UAAU,IAAI,gBAAgB;;;;;;EAO9B,QAAQ,IAAI,gBAAgB;;;;;;;;;EAU5B,cAAc,kBAAkB;;;KAItB,MAAM,UAAU,QAAQ,UAAU,WAAW,KAAK;;;;;;;;;;UAW7C,QAAQ,UAAU,QAAQ,UAAU,MAAM;;GAExD,KAAK,gBAAgB,KAAK,QAAQ,KAAK;;EAExC,GAAG,qBAAqB,QAAQ,MAAM,MAAM,gBAAgB,KAAK,QAAQ,SAAS,MAAM,MAAM;;;KAIpF,oBAAoB,UAAU;EACpC;EAAe,IAAI,QAAQ;;EAC3B;EAAgB,QAAQ,gBAAgB;;;;;;;;;;;;;;;;UAgB7B,cAAc,UAAU;EACvC,WAAW,oBAAoB;EAC/B,UAAU,QAAQ;EAClB;EACA;EACA;;;iBAqCc,WAAW,UAAU,QAAQ,UAAU,MAAM,IAAI,qBAAqB,QAAQ,GAAG;;iBAoBjF,QAAQ,UAAU,QAAQ,iBAAiB,SAAS,MAAM;;iBAO1D,aAAa,UAAU,QAAQ,OAAO,MAAM,KAAK,cAAc;;;;;;;;iBAW/D,kBAAkB,UAAU,QAC1C,OAAO,WAAW,KAAK,uBAAuB,IAC9C,YAAY"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OrderOf } from "
|
|
2
|
-
import { LoadHint, Loaded } from "./loadHints.mjs";
|
|
3
|
-
import { GraphQLFilterWithAlias } from "./EntityGraphQLFilter.mjs";
|
|
4
|
-
import { EntityManager, FindFilterOptions } from "./EntityManager.mjs";
|
|
5
|
-
import { Entity } from "./Entity.mjs";
|
|
1
|
+
import { OrderOf } from "../../typeMap.mjs";
|
|
6
2
|
import { Alias } from "./Aliases.mjs";
|
|
3
|
+
import { GraphQLFilterWithAlias } from "./EntityGraphQLFilter.mjs";
|
|
7
4
|
import { ExpressionCondition, ExpressionFilter, FilterAndSettings, FilterWithAlias, FindFilter } from "./EntityFilter.mjs";
|
|
8
|
-
|
|
5
|
+
import { LoadHint, Loaded } from "../../loadHints.mjs";
|
|
6
|
+
import { EntityManager, FindFilterOptions } from "../../EntityManager.mjs";
|
|
7
|
+
import { Entity } from "../../Entity.mjs";
|
|
8
|
+
//#region src/queries/find/scopes.d.ts
|
|
9
9
|
/**
|
|
10
10
|
* A scope fragment that introduces its own join aliases: a join tree plus conditions
|
|
11
11
|
* that reference the aliases it binds.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.d.mts","names":[],"sources":["../../../src/queries/find/scopes.ts"],"mappings":";;;;;;;;;;;;;;;;UAuBiB,gBAAgB,UAAU;EACzC,OAAO,gBAAgB;EACvB,YAAY;;;KAIF,QAAQ,UAAU,WAC5B,GAAG,MAAM,OACN,sBAAsB,wBAAwB,gBAAgB;;;;;;;;;iBAUnD,kBAAkB,UAAU,QAC1C,QAAQ,sBAAsB,wBAAwB,gBAAgB,KACrE,UAAU,gBAAgB;;;;;;;;;UAkBZ,WAAW,UAAU;;;;;;;;EAQpC,MAAM,OAAO,gBAAgB;EAC7B,MAAM,IAAI,QAAQ;;;;;;;;;EAUlB,QAAQ,SAAS,QAAQ,KAAK,QAAQ;;;;;;EAOtC,MAAM;;;;;;EAON,OAAO;;;;;;;;;EAUP,YAAY;;;;;;;;;;EAWZ,KAAK,IAAI,gBAAgB,QAAQ;EACjC,WAAW,UAAU,SAAS,IAC5B,IAAI,eACJ,OAAO,kBAAkB;IAAO,WAAW;MAC1C,QAAQ,OAAO,GAAG;;EAGrB,QAAQ,IAAI,gBAAgB,QAAQ;EACpC,cAAc,UAAU,SAAS,IAC/B,IAAI,eACJ,OAAO,kBAAkB;IAAO,WAAW;MAC1C,QAAQ,OAAO,GAAG;;EAGrB,cAAc,IAAI,gBAAgB,QAAQ;EAC1C,oBAAoB,UAAU,SAAS,IACrC,IAAI,eACJ,OAAO,kBAAkB;IAAO,WAAW;MAC1C,QAAQ,OAAO,GAAG;;;;;;;EAQrB,UAAU,IAAI,gBAAgB;;;;;;EAO9B,QAAQ,IAAI,gBAAgB;;;;;;;;;EAU5B,cAAc,kBAAkB;;;KAItB,MAAM,UAAU,QAAQ,UAAU,WAAW,KAAK;;;;;;;;;;UAW7C,QAAQ,UAAU,QAAQ,UAAU,MAAM;;GAExD,KAAK,gBAAgB,KAAK,QAAQ,KAAK;;EAExC,GAAG,qBAAqB,QAAQ,MAAM,MAAM,gBAAgB,KAAK,QAAQ,SAAS,MAAM,MAAM;;;KAIpF,oBAAoB,UAAU;EACpC;EAAe,IAAI,QAAQ;;EAC3B;EAAgB,QAAQ,gBAAgB;;;;;;;;;;;;;;;;UAgB7B,cAAc,UAAU;EACvC,WAAW,oBAAoB;EAC/B,UAAU,QAAQ;EAClB;EACA;EACA;;;iBAqCc,WAAW,UAAU,QAAQ,UAAU,MAAM,IAAI,qBAAqB,QAAQ,GAAG;;iBAoBjF,QAAQ,UAAU,QAAQ,iBAAiB,SAAS,MAAM;;iBAO1D,aAAa,UAAU,QAAQ,OAAO,MAAM,KAAK,cAAc;;;;;;;;iBAW/D,kBAAkB,UAAU,QAC1C,OAAO,WAAW,KAAK,uBAAuB,IAC9C,YAAY"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { maybeGetMetadataForType } from "
|
|
2
|
-
|
|
3
|
-
//#region src/scopes.ts
|
|
1
|
+
import { maybeGetMetadataForType } from "../../configure.js";
|
|
2
|
+
//#region src/queries/find/scopes.ts
|
|
4
3
|
/**
|
|
5
4
|
* Discriminates an {@link AliasFn} result that is a {@link ScopeJoinFilter} from a bare
|
|
6
5
|
* condition / condition array.
|