@effect-app/infra 4.0.0-beta.98 → 4.0.0
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/CHANGELOG.md +2891 -0
- package/_check.sh +1 -1
- package/dist/CUPS.d.ts +28 -9
- package/dist/CUPS.d.ts.map +1 -1
- package/dist/CUPS.js +35 -14
- package/dist/ClusterCosmos.d.ts +67 -0
- package/dist/ClusterCosmos.d.ts.map +1 -0
- package/dist/ClusterCosmos.js +588 -0
- package/dist/ClusterServiceBus.d.ts +67 -0
- package/dist/ClusterServiceBus.d.ts.map +1 -0
- package/dist/ClusterServiceBus.js +84 -0
- package/dist/{api/ContextProvider.d.ts → ContextProvider.d.ts} +7 -4
- package/dist/ContextProvider.d.ts.map +1 -0
- package/dist/ContextProvider.js +40 -0
- package/dist/Emailer/Sendgrid.d.ts +110 -146
- package/dist/Emailer/Sendgrid.d.ts.map +1 -1
- package/dist/Emailer/Sendgrid.js +24 -19
- package/dist/Emailer/fake.d.ts +1 -1
- package/dist/Emailer/fake.d.ts.map +1 -1
- package/dist/Emailer/fake.js +4 -4
- package/dist/MainFiberSet.d.ts +11 -7
- package/dist/MainFiberSet.d.ts.map +1 -1
- package/dist/MainFiberSet.js +22 -6
- package/dist/QueueMaker/errors.d.ts +3 -1
- package/dist/QueueMaker/errors.d.ts.map +1 -1
- package/dist/QueueMaker/errors.js +4 -2
- package/dist/{adapters/SQL → SQL}/Model.d.ts +34 -45
- package/dist/SQL/Model.d.ts.map +1 -0
- package/dist/SQL/Model.js +469 -0
- package/dist/SQL.d.ts.map +1 -0
- package/dist/{adapters/SQL.js → SQL.js} +1 -1
- package/dist/Store/Cosmos/query.d.ts +16 -4
- package/dist/Store/Cosmos/query.d.ts.map +1 -1
- package/dist/Store/Cosmos/query.js +238 -42
- package/dist/Store/Cosmos.d.ts +2 -2
- package/dist/Store/Cosmos.d.ts.map +1 -1
- package/dist/Store/Cosmos.js +394 -319
- package/dist/Store/Disk.d.ts +4 -4
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +91 -39
- package/dist/Store/Memory.d.ts +7 -10
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +348 -78
- package/dist/Store/SQL/Pg.d.ts +2 -2
- package/dist/Store/SQL/Pg.d.ts.map +1 -1
- package/dist/Store/SQL/Pg.js +229 -154
- package/dist/Store/SQL/query.d.ts +19 -3
- package/dist/Store/SQL/query.d.ts.map +1 -1
- package/dist/Store/SQL/query.js +306 -12
- package/dist/Store/SQL.d.ts +22 -5
- package/dist/Store/SQL.d.ts.map +1 -1
- package/dist/Store/SQL.js +369 -98
- package/dist/Store/codeFilter.d.ts +4 -4
- package/dist/Store/codeFilter.d.ts.map +1 -1
- package/dist/Store/codeFilter.js +71 -22
- package/dist/Store/index.d.ts +6 -4
- package/dist/Store/index.d.ts.map +1 -1
- package/dist/Store/index.js +9 -6
- package/dist/Store/jsonDocument.d.ts +67 -0
- package/dist/Store/jsonDocument.d.ts.map +1 -0
- package/dist/Store/jsonDocument.js +107 -0
- package/dist/Store/utils.d.ts +21 -2
- package/dist/Store/utils.d.ts.map +1 -1
- package/dist/Store/utils.js +253 -10
- package/dist/WorkflowEngineCosmos.d.ts +30 -0
- package/dist/WorkflowEngineCosmos.d.ts.map +1 -0
- package/dist/WorkflowEngineCosmos.js +542 -0
- package/dist/WorkflowEngineSqlite.d.ts +24 -0
- package/dist/WorkflowEngineSqlite.d.ts.map +1 -0
- package/dist/WorkflowEngineSqlite.js +550 -0
- package/dist/arbs.d.ts +6 -3
- package/dist/arbs.d.ts.map +1 -1
- package/dist/arbs.js +20 -4
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +5 -0
- package/dist/cosmos-client.d.ts +40 -0
- package/dist/cosmos-client.d.ts.map +1 -0
- package/dist/cosmos-client.js +41 -0
- package/dist/errorReporter.d.ts +6 -4
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +23 -27
- package/dist/fileUtil.d.ts +1 -1
- package/dist/fileUtil.d.ts.map +1 -1
- package/dist/fileUtil.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/internal/RequestContextMiddleware.d.ts +5 -0
- package/dist/internal/RequestContextMiddleware.d.ts.map +1 -0
- package/dist/internal/RequestContextMiddleware.js +45 -0
- package/dist/internal/auth.d.ts +53 -0
- package/dist/internal/auth.d.ts.map +1 -0
- package/dist/internal/auth.js +180 -0
- package/dist/internal/events.d.ts +11 -0
- package/dist/internal/events.d.ts.map +1 -0
- package/dist/internal/events.js +49 -0
- package/dist/{api/internal → internal}/health.d.ts +1 -1
- package/dist/internal/health.d.ts.map +1 -0
- package/dist/internal/health.js +5 -0
- package/dist/{api/layerUtils.d.ts → layerUtils.d.ts} +10 -2
- package/dist/layerUtils.d.ts.map +1 -0
- package/dist/layerUtils.js +17 -0
- package/dist/logger/jsonLogger.d.ts +1 -1
- package/dist/logger/jsonLogger.d.ts.map +1 -1
- package/dist/logger/jsonLogger.js +5 -3
- package/dist/logger/logFmtLogger.d.ts +1 -1
- package/dist/logger/logFmtLogger.d.ts.map +1 -1
- package/dist/logger/logFmtLogger.js +3 -3
- package/dist/logger/shared.d.ts +2 -2
- package/dist/logger/shared.d.ts.map +1 -1
- package/dist/logger/shared.js +6 -6
- package/dist/logger.d.ts.map +1 -1
- package/dist/middlewares.d.ts.map +1 -0
- package/dist/{api/middlewares.js → middlewares.js} +1 -1
- package/dist/{adapters/mongo-client.d.ts → mongo-client.d.ts} +2 -1
- package/dist/mongo-client.d.ts.map +1 -0
- package/dist/mongo-client.js +15 -0
- package/dist/otel.d.ts +75 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +84 -0
- package/dist/rateLimit.d.ts +11 -3
- package/dist/rateLimit.d.ts.map +1 -1
- package/dist/rateLimit.js +7 -12
- package/dist/{adapters/redis-client.d.ts → redis-client.d.ts} +4 -1
- package/dist/redis-client.d.ts.map +1 -0
- package/dist/redis-client.js +98 -0
- package/dist/{api/reportError.d.ts → reportError.d.ts} +1 -1
- package/dist/reportError.d.ts.map +1 -0
- package/dist/reportError.js +28 -0
- package/dist/{api/routing → routing}/middleware/RouterMiddleware.d.ts +2 -1
- package/dist/routing/middleware/RouterMiddleware.d.ts.map +1 -0
- package/dist/{api/routing → routing}/middleware/RouterMiddleware.js +1 -1
- package/dist/{api/routing → routing}/middleware/middleware.d.ts +11 -6
- package/dist/routing/middleware/middleware.d.ts.map +1 -0
- package/dist/routing/middleware/middleware.js +152 -0
- package/dist/{api/routing → routing}/middleware.d.ts +0 -1
- package/dist/routing/middleware.d.ts.map +1 -0
- package/dist/{api/routing → routing}/middleware.js +1 -2
- package/dist/routing/schema/jwt.d.ts.map +1 -0
- package/dist/routing/schema/jwt.js +12 -0
- package/dist/routing/tsort.d.ts.map +1 -0
- package/dist/routing/tsort.js +51 -0
- package/dist/{api/routing → routing}/utils.d.ts +3 -3
- package/dist/routing/utils.d.ts.map +1 -0
- package/dist/routing/utils.js +45 -0
- package/dist/routing.d.ts +182 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +256 -0
- package/dist/test.d.ts +2 -2
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +5 -5
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +14 -0
- package/docs/cluster-storage.md +26 -0
- package/docs/workflow-engine.md +262 -0
- package/examples/query.ts +23 -19
- package/package.json +36 -364
- package/src/CUPS.ts +53 -14
- package/src/ClusterCosmos.ts +1170 -0
- package/src/ClusterServiceBus.ts +244 -0
- package/src/{api/ContextProvider.ts → ContextProvider.ts} +10 -7
- package/src/Emailer/Sendgrid.ts +83 -60
- package/src/Emailer/fake.ts +4 -4
- package/src/MainFiberSet.ts +31 -12
- package/src/QueueMaker/errors.ts +3 -1
- package/src/{adapters/SQL → SQL}/Model.ts +48 -47
- package/src/SQL.ts +1 -0
- package/src/Store/Cosmos/query.ts +275 -55
- package/src/Store/Cosmos.ts +597 -515
- package/src/Store/Disk.ts +145 -71
- package/src/Store/Memory.ts +420 -115
- package/src/Store/SQL/Pg.ts +352 -268
- package/src/Store/SQL/query.ts +366 -20
- package/src/Store/SQL.ts +742 -293
- package/src/Store/codeFilter.ts +78 -28
- package/src/Store/index.ts +18 -13
- package/src/Store/jsonDocument.ts +143 -0
- package/src/Store/utils.ts +307 -30
- package/src/WorkflowEngineCosmos.ts +749 -0
- package/src/WorkflowEngineSqlite.ts +813 -0
- package/src/arbs.ts +25 -5
- package/src/cosmos-client.ts +72 -0
- package/src/errorReporter.ts +68 -78
- package/src/fileUtil.ts +1 -1
- package/src/index.ts +2 -1
- package/src/{api/internal → internal}/RequestContextMiddleware.ts +23 -6
- package/src/internal/auth.ts +272 -0
- package/src/{api/internal → internal}/events.ts +18 -9
- package/src/{api/layerUtils.ts → layerUtils.ts} +7 -3
- package/src/logger/jsonLogger.ts +5 -3
- package/src/logger/logFmtLogger.ts +3 -3
- package/src/logger/shared.ts +6 -5
- package/src/middlewares.ts +10 -0
- package/src/{adapters/mongo-client.ts → mongo-client.ts} +3 -1
- package/src/otel.ts +177 -0
- package/src/rateLimit.ts +35 -24
- package/src/{adapters/redis-client.ts → redis-client.ts} +6 -2
- package/src/{api/reportError.ts → reportError.ts} +3 -2
- package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +2 -1
- package/src/{api/routing → routing}/middleware/middleware.ts +75 -50
- package/src/routing/middleware.ts +4 -0
- package/src/{api/routing → routing}/schema/jwt.ts +2 -2
- package/src/{api/routing → routing}/utils.ts +2 -1
- package/src/routing.ts +823 -0
- package/src/test.ts +6 -6
- package/src/vitest.ts +1 -1
- package/test/arbs-magnitude.test.ts +33 -0
- package/test/arbs.test.ts +41 -0
- package/test/auth.test.ts +101 -0
- package/test/cluster-cosmos.test.ts +634 -0
- package/test/cluster-servicebus.test.ts +180 -0
- package/test/cluster-sqlite.test.ts +207 -0
- package/test/contextProvider.test.ts +11 -8
- package/test/controller.test.ts +23 -28
- package/test/cosmos-container-throughput.test.ts +80 -0
- package/test/cosmos-query.test.ts +368 -0
- package/test/dist/arbs-magnitude.test.d.ts.map +1 -0
- package/test/dist/arbs.test.d.ts.map +1 -0
- package/test/dist/auth.test.d.ts.map +1 -0
- package/test/dist/cluster-cosmos.test.d.ts.map +1 -0
- package/test/dist/cluster-servicebus.test.d.ts.map +1 -0
- package/test/dist/cluster-sqlite.test.d.ts.map +1 -0
- package/test/dist/contextProvider.test.d.ts.map +1 -1
- package/test/dist/controller.test.d.ts.map +1 -1
- package/test/dist/cosmos-container-throughput.test.d.ts.map +1 -0
- package/test/dist/cosmos-query.test.d.ts.map +1 -0
- package/test/dist/fixtures.d.ts +17 -9
- package/test/dist/fixtures.d.ts.map +1 -1
- package/test/dist/fixtures.js +8 -3
- package/test/dist/json-lower.test.d.ts.map +1 -0
- package/test/dist/query.test.d.ts.map +1 -1
- package/test/dist/rawQuery.test.d.ts.map +1 -1
- package/test/dist/repository-ext.test.d.ts.map +1 -0
- package/test/dist/repository-legacy-document.test.d.ts.map +1 -0
- package/test/dist/requires.test.d.ts.map +1 -1
- package/test/dist/router-generator.test.d.ts.map +1 -0
- package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
- package/test/dist/rpc-context-map-streaming.test.d.ts.map +1 -0
- package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
- package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
- package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
- package/test/dist/workflow-engine-cosmos.test.d.ts.map +1 -0
- package/test/dist/workflow-engine-sqlite.test.d.ts.map +1 -0
- package/test/fixtures.ts +7 -2
- package/test/json-lower.test.ts +129 -0
- package/test/layerUtils.test.ts +2 -2
- package/test/query.test.ts +1232 -42
- package/test/rawQuery.test.ts +432 -7
- package/test/repository-ext.test.ts +456 -0
- package/test/repository-legacy-document.test.ts +394 -0
- package/test/requires.test.ts +7 -3
- package/test/router-generator.test.ts +187 -0
- package/test/routing-interruptibility.test.ts +66 -0
- package/test/rpc-context-map-streaming.test.ts +265 -0
- package/test/rpc-e2e-invalidation.test.ts +421 -0
- package/test/rpc-multi-middleware.test.ts +17 -11
- package/test/rpc-stream-fullstack.test.ts +307 -0
- package/test/sql-store.test.ts +1202 -47
- package/test/validateSample.test.ts +70 -42
- package/test/workflow-engine-cosmos.test.ts +345 -0
- package/test/workflow-engine-sqlite.test.ts +297 -0
- package/tsconfig.examples.json +1 -1
- package/tsconfig.json +9 -1
- package/tsconfig.src.json +35 -35
- package/tsconfig.test.json +2 -2
- package/dist/Emailer/service.d.ts +0 -55
- package/dist/Emailer/service.d.ts.map +0 -1
- package/dist/Emailer/service.js +0 -6
- package/dist/Emailer.d.ts +0 -2
- package/dist/Emailer.d.ts.map +0 -1
- package/dist/Emailer.js +0 -2
- package/dist/Model/Repository/ext.d.ts +0 -41
- package/dist/Model/Repository/ext.d.ts.map +0 -1
- package/dist/Model/Repository/ext.js +0 -65
- package/dist/Model/Repository/internal/internal.d.ts +0 -59
- package/dist/Model/Repository/internal/internal.d.ts.map +0 -1
- package/dist/Model/Repository/internal/internal.js +0 -320
- package/dist/Model/Repository/legacy.d.ts +0 -19
- package/dist/Model/Repository/legacy.d.ts.map +0 -1
- package/dist/Model/Repository/legacy.js +0 -2
- package/dist/Model/Repository/makeRepo.d.ts +0 -49
- package/dist/Model/Repository/makeRepo.d.ts.map +0 -1
- package/dist/Model/Repository/makeRepo.js +0 -24
- package/dist/Model/Repository/service.d.ts +0 -89
- package/dist/Model/Repository/service.d.ts.map +0 -1
- package/dist/Model/Repository/service.js +0 -2
- package/dist/Model/Repository/validation.d.ts +0 -43
- package/dist/Model/Repository/validation.d.ts.map +0 -1
- package/dist/Model/Repository/validation.js +0 -32
- package/dist/Model/Repository.d.ts +0 -6
- package/dist/Model/Repository.d.ts.map +0 -1
- package/dist/Model/Repository.js +0 -6
- package/dist/Model/dsl.d.ts +0 -32
- package/dist/Model/dsl.d.ts.map +0 -1
- package/dist/Model/dsl.js +0 -44
- package/dist/Model/filter/filterApi.d.ts +0 -30
- package/dist/Model/filter/filterApi.d.ts.map +0 -1
- package/dist/Model/filter/filterApi.js +0 -2
- package/dist/Model/filter/types/errors.d.ts +0 -29
- package/dist/Model/filter/types/errors.d.ts.map +0 -1
- package/dist/Model/filter/types/errors.js +0 -2
- package/dist/Model/filter/types/fields.d.ts +0 -15
- package/dist/Model/filter/types/fields.d.ts.map +0 -1
- package/dist/Model/filter/types/fields.js +0 -2
- package/dist/Model/filter/types/path/common.d.ts +0 -316
- package/dist/Model/filter/types/path/common.d.ts.map +0 -1
- package/dist/Model/filter/types/path/common.js +0 -2
- package/dist/Model/filter/types/path/eager.d.ts +0 -95
- package/dist/Model/filter/types/path/eager.d.ts.map +0 -1
- package/dist/Model/filter/types/path/eager.js +0 -31
- package/dist/Model/filter/types/path/index.d.ts +0 -4
- package/dist/Model/filter/types/path/index.d.ts.map +0 -1
- package/dist/Model/filter/types/path/index.js +0 -3
- package/dist/Model/filter/types/utils.d.ts +0 -79
- package/dist/Model/filter/types/utils.d.ts.map +0 -1
- package/dist/Model/filter/types/utils.js +0 -2
- package/dist/Model/filter/types/validator.d.ts +0 -30
- package/dist/Model/filter/types/validator.d.ts.map +0 -1
- package/dist/Model/filter/types/validator.js +0 -2
- package/dist/Model/filter/types.d.ts +0 -5
- package/dist/Model/filter/types.d.ts.map +0 -1
- package/dist/Model/filter/types.js +0 -7
- package/dist/Model/query/dsl.d.ts +0 -248
- package/dist/Model/query/dsl.d.ts.map +0 -1
- package/dist/Model/query/dsl.js +0 -104
- package/dist/Model/query/new-kid-interpreter.d.ts +0 -28
- package/dist/Model/query/new-kid-interpreter.d.ts.map +0 -1
- package/dist/Model/query/new-kid-interpreter.js +0 -165
- package/dist/Model/query.d.ts +0 -15
- package/dist/Model/query.d.ts.map +0 -1
- package/dist/Model/query.js +0 -3
- package/dist/Model.d.ts +0 -4
- package/dist/Model.d.ts.map +0 -1
- package/dist/Model.js +0 -4
- package/dist/Operations.d.ts +0 -55
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -102
- package/dist/OperationsRepo.d.ts +0 -41
- package/dist/OperationsRepo.d.ts.map +0 -1
- package/dist/OperationsRepo.js +0 -14
- package/dist/QueueMaker/SQLQueue.d.ts +0 -14
- package/dist/QueueMaker/SQLQueue.d.ts.map +0 -1
- package/dist/QueueMaker/SQLQueue.js +0 -132
- package/dist/QueueMaker/memQueue.d.ts +0 -11
- package/dist/QueueMaker/memQueue.d.ts.map +0 -1
- package/dist/QueueMaker/memQueue.js +0 -76
- package/dist/QueueMaker/sbqueue.d.ts +0 -12
- package/dist/QueueMaker/sbqueue.d.ts.map +0 -1
- package/dist/QueueMaker/sbqueue.js +0 -91
- package/dist/QueueMaker/service.d.ts +0 -11
- package/dist/QueueMaker/service.d.ts.map +0 -1
- package/dist/QueueMaker/service.js +0 -4
- package/dist/RequestContext.d.ts +0 -68
- package/dist/RequestContext.d.ts.map +0 -1
- package/dist/RequestContext.js +0 -49
- package/dist/RequestFiberSet.d.ts +0 -36
- package/dist/RequestFiberSet.d.ts.map +0 -1
- package/dist/RequestFiberSet.js +0 -78
- package/dist/Store/ContextMapContainer.d.ts +0 -25
- package/dist/Store/ContextMapContainer.d.ts.map +0 -1
- package/dist/Store/ContextMapContainer.js +0 -77
- package/dist/Store/service.d.ts +0 -111
- package/dist/Store/service.d.ts.map +0 -1
- package/dist/Store/service.js +0 -79
- package/dist/Store.d.ts +0 -2
- package/dist/Store.d.ts.map +0 -1
- package/dist/Store.js +0 -2
- package/dist/adapters/SQL/Model.d.ts.map +0 -1
- package/dist/adapters/SQL/Model.js +0 -478
- package/dist/adapters/SQL.d.ts.map +0 -1
- package/dist/adapters/ServiceBus.d.ts +0 -58
- package/dist/adapters/ServiceBus.d.ts.map +0 -1
- package/dist/adapters/ServiceBus.js +0 -99
- package/dist/adapters/cosmos-client.d.ts +0 -14
- package/dist/adapters/cosmos-client.d.ts.map +0 -1
- package/dist/adapters/cosmos-client.js +0 -9
- package/dist/adapters/index.d.ts +0 -2
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -2
- package/dist/adapters/logger.d.ts +0 -9
- package/dist/adapters/logger.d.ts.map +0 -1
- package/dist/adapters/logger.js +0 -3
- package/dist/adapters/memQueue.d.ts +0 -13
- package/dist/adapters/memQueue.d.ts.map +0 -1
- package/dist/adapters/memQueue.js +0 -20
- package/dist/adapters/mongo-client.d.ts.map +0 -1
- package/dist/adapters/mongo-client.js +0 -13
- package/dist/adapters/redis-client.d.ts.map +0 -1
- package/dist/adapters/redis-client.js +0 -94
- package/dist/api/ContextProvider.d.ts.map +0 -1
- package/dist/api/ContextProvider.js +0 -38
- package/dist/api/codec.d.ts.map +0 -1
- package/dist/api/codec.js +0 -5
- package/dist/api/internal/RequestContextMiddleware.d.ts +0 -5
- package/dist/api/internal/RequestContextMiddleware.d.ts.map +0 -1
- package/dist/api/internal/RequestContextMiddleware.js +0 -35
- package/dist/api/internal/auth.d.ts +0 -15
- package/dist/api/internal/auth.d.ts.map +0 -1
- package/dist/api/internal/auth.js +0 -47
- package/dist/api/internal/events.d.ts +0 -9
- package/dist/api/internal/events.d.ts.map +0 -1
- package/dist/api/internal/events.js +0 -42
- package/dist/api/internal/health.d.ts.map +0 -1
- package/dist/api/internal/health.js +0 -5
- package/dist/api/layerUtils.d.ts.map +0 -1
- package/dist/api/layerUtils.js +0 -16
- package/dist/api/middlewares.d.ts.map +0 -1
- package/dist/api/reportError.d.ts.map +0 -1
- package/dist/api/reportError.js +0 -27
- package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
- package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
- package/dist/api/routing/middleware/middleware.js +0 -130
- package/dist/api/routing/middleware.d.ts.map +0 -1
- package/dist/api/routing/schema/jwt.d.ts.map +0 -1
- package/dist/api/routing/schema/jwt.js +0 -12
- package/dist/api/routing/tsort.d.ts.map +0 -1
- package/dist/api/routing/tsort.js +0 -51
- package/dist/api/routing/utils.d.ts.map +0 -1
- package/dist/api/routing/utils.js +0 -44
- package/dist/api/routing.d.ts +0 -134
- package/dist/api/routing.d.ts.map +0 -1
- package/dist/api/routing.js +0 -167
- package/dist/api/setupRequest.d.ts +0 -15
- package/dist/api/setupRequest.d.ts.map +0 -1
- package/dist/api/setupRequest.js +0 -49
- package/dist/api/util.d.ts.map +0 -1
- package/dist/api/util.js +0 -14
- package/eslint.config.mjs +0 -24
- package/src/Emailer/service.ts +0 -52
- package/src/Emailer.ts +0 -1
- package/src/Model/Repository/ext.ts +0 -283
- package/src/Model/Repository/internal/internal.ts +0 -580
- package/src/Model/Repository/legacy.ts +0 -27
- package/src/Model/Repository/makeRepo.ts +0 -139
- package/src/Model/Repository/service.ts +0 -627
- package/src/Model/Repository/validation.ts +0 -31
- package/src/Model/Repository.ts +0 -5
- package/src/Model/dsl.ts +0 -128
- package/src/Model/filter/filterApi.ts +0 -60
- package/src/Model/filter/types/errors.ts +0 -47
- package/src/Model/filter/types/fields.ts +0 -50
- package/src/Model/filter/types/path/common.ts +0 -404
- package/src/Model/filter/types/path/eager.ts +0 -298
- package/src/Model/filter/types/path/index.ts +0 -4
- package/src/Model/filter/types/utils.ts +0 -128
- package/src/Model/filter/types/validator.ts +0 -46
- package/src/Model/filter/types.ts +0 -6
- package/src/Model/query/dsl.ts +0 -2110
- package/src/Model/query/new-kid-interpreter.ts +0 -210
- package/src/Model/query.ts +0 -13
- package/src/Model.ts +0 -3
- package/src/Operations.ts +0 -235
- package/src/OperationsRepo.ts +0 -16
- package/src/QueueMaker/SQLQueue.ts +0 -190
- package/src/QueueMaker/memQueue.ts +0 -130
- package/src/QueueMaker/sbqueue.ts +0 -137
- package/src/QueueMaker/service.ts +0 -17
- package/src/RequestContext.ts +0 -63
- package/src/RequestFiberSet.ts +0 -105
- package/src/Store/ContextMapContainer.ts +0 -116
- package/src/Store/index.test.ts.bak +0 -112
- package/src/Store/service.ts +0 -193
- package/src/Store.ts +0 -1
- package/src/adapters/SQL.ts +0 -1
- package/src/adapters/ServiceBus.ts +0 -209
- package/src/adapters/cosmos-client.ts +0 -16
- package/src/adapters/index.ts +0 -0
- package/src/adapters/logger.ts +0 -3
- package/src/adapters/memQueue.ts +0 -21
- package/src/api/internal/auth.ts +0 -68
- package/src/api/middlewares.ts +0 -10
- package/src/api/routing/middleware.ts +0 -6
- package/src/api/routing.ts +0 -598
- package/src/api/setupRequest.ts +0 -104
- package/test/dist/date-query.test.d.ts.map +0 -1
- package/tsconfig.json.bak +0 -12
- /package/dist/{adapters/SQL.d.ts → SQL.d.ts} +0 -0
- /package/dist/{api/codec.d.ts → codec.d.ts} +0 -0
- /package/dist/{api/middlewares.d.ts → middlewares.d.ts} +0 -0
- /package/dist/{api/routing → routing}/schema/jwt.d.ts +0 -0
- /package/dist/{api/routing → routing}/tsort.d.ts +0 -0
- /package/dist/{api/util.d.ts → util.d.ts} +0 -0
- /package/src/{api/codec.ts → codec.ts} +0 -0
- /package/src/{api/internal → internal}/health.ts +0 -0
- /package/src/{api/routing → routing}/tsort.ts +0 -0
- /package/src/{api/util.ts → util.ts} +0 -0
|
@@ -17,13 +17,14 @@ import * as Option from "effect/Option"
|
|
|
17
17
|
import * as Predicate from "effect/Predicate"
|
|
18
18
|
import * as RequestResolver from "effect/RequestResolver"
|
|
19
19
|
import * as Schema from "effect/Schema"
|
|
20
|
+
import * as VariantSchema from "effect/schema/VariantSchema"
|
|
20
21
|
import * as Getter from "effect/SchemaGetter"
|
|
21
22
|
import * as Transformation from "effect/SchemaTransformation"
|
|
22
23
|
import type { Scope } from "effect/Scope"
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import * as
|
|
26
|
-
import
|
|
24
|
+
import { SqlClient } from "effect/sql/SqlClient"
|
|
25
|
+
import * as SqlResolver from "effect/sql/SqlResolver"
|
|
26
|
+
import * as SqlSchema from "effect/sql/SqlSchema"
|
|
27
|
+
import { type DbSystem, withDbSpan } from "../otel.ts"
|
|
27
28
|
|
|
28
29
|
const {
|
|
29
30
|
Class,
|
|
@@ -73,8 +74,8 @@ export {
|
|
|
73
74
|
* @since 1.0.0
|
|
74
75
|
* @category constructors
|
|
75
76
|
* @example
|
|
76
|
-
* import
|
|
77
|
-
* import { Model } from "effect/
|
|
77
|
+
* import * as Schema from "effect/Schema"
|
|
78
|
+
* import { Model } from "effect/schema"
|
|
78
79
|
*
|
|
79
80
|
* export const GroupId = Schema.Number.pipe(Schema.brand("GroupId"))
|
|
80
81
|
*
|
|
@@ -331,7 +332,7 @@ export interface Date extends Schema.decodeTo<Schema.instanceOf<DateTime.Utc>, S
|
|
|
331
332
|
*/
|
|
332
333
|
export const Date: Date = Schema.String.pipe(
|
|
333
334
|
Schema.decodeTo(Schema.DateTimeUtc, {
|
|
334
|
-
decode: Getter.dateTimeUtcFromInput()
|
|
335
|
+
decode: Getter.map(Getter.dateTimeUtcFromInput(), DateTime.removeTime),
|
|
335
336
|
encode: Getter.transform(DateTime.formatIsoDate)
|
|
336
337
|
})
|
|
337
338
|
)
|
|
@@ -545,9 +546,15 @@ export const DateTimeUpdateFromNumber: DateTimeUpdateFromNumber = Field({
|
|
|
545
546
|
*/
|
|
546
547
|
export interface JsonFromString<S extends Schema.Top> extends
|
|
547
548
|
VariantSchema.Field<{
|
|
548
|
-
readonly select: Schema.fromJsonString<
|
|
549
|
-
|
|
550
|
-
|
|
549
|
+
readonly select: Schema.fromJsonString<
|
|
550
|
+
Schema.Codec<S["Type"], Schema.Json, S["DecodingServices"], S["EncodingServices"]>
|
|
551
|
+
>
|
|
552
|
+
readonly insert: Schema.fromJsonString<
|
|
553
|
+
Schema.Codec<S["Type"], Schema.Json, S["DecodingServices"], S["EncodingServices"]>
|
|
554
|
+
>
|
|
555
|
+
readonly update: Schema.fromJsonString<
|
|
556
|
+
Schema.Codec<S["Type"], Schema.Json, S["DecodingServices"], S["EncodingServices"]>
|
|
557
|
+
>
|
|
551
558
|
readonly json: S
|
|
552
559
|
readonly jsonCreate: S
|
|
553
560
|
readonly jsonUpdate: S
|
|
@@ -565,7 +572,7 @@ export interface JsonFromString<S extends Schema.Top> extends
|
|
|
565
572
|
export const JsonFromString = <S extends Schema.Top>(
|
|
566
573
|
schema: S
|
|
567
574
|
): JsonFromString<S> => {
|
|
568
|
-
const parsed = Schema.fromJsonString(schema)
|
|
575
|
+
const parsed = Schema.fromJsonString(Schema.toCodecJson(schema))
|
|
569
576
|
return Field({
|
|
570
577
|
select: parsed,
|
|
571
578
|
insert: parsed,
|
|
@@ -590,6 +597,7 @@ export const makeRepository = <
|
|
|
590
597
|
readonly spanPrefix: string
|
|
591
598
|
readonly idColumn: Id
|
|
592
599
|
readonly versionColumn?: string | undefined
|
|
600
|
+
readonly dbSystem?: DbSystem | undefined
|
|
593
601
|
}): Effect.Effect<
|
|
594
602
|
{
|
|
595
603
|
readonly insert: (
|
|
@@ -623,6 +631,15 @@ export const makeRepository = <
|
|
|
623
631
|
const idSchema = Model.fields[options.idColumn] as Schema.Top
|
|
624
632
|
const idColumn = options.idColumn as string
|
|
625
633
|
const versionColumn = options.versionColumn
|
|
634
|
+
const system: DbSystem = options.dbSystem ?? "other_sql"
|
|
635
|
+
const opSpan = (operation: string, idValue?: unknown) =>
|
|
636
|
+
withDbSpan({
|
|
637
|
+
operation,
|
|
638
|
+
system,
|
|
639
|
+
collection: options.tableName,
|
|
640
|
+
entity: options.spanPrefix,
|
|
641
|
+
...(idValue !== undefined && { extra: { "app.entity.id": idValue } })
|
|
642
|
+
})
|
|
626
643
|
|
|
627
644
|
const insertSchema = SqlSchema.findOne({
|
|
628
645
|
Request: Model.insert,
|
|
@@ -644,9 +661,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID(
|
|
|
644
661
|
): Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"] | S["insert"]["EncodingServices"]> =>
|
|
645
662
|
insertSchema(insert).pipe(
|
|
646
663
|
Effect.catchTag("NoSuchElementError", Effect.die),
|
|
647
|
-
|
|
648
|
-
captureStackTrace: false
|
|
649
|
-
})
|
|
664
|
+
opSpan("insert")
|
|
650
665
|
) as any
|
|
651
666
|
|
|
652
667
|
const insertVoidSchema = SqlSchema.void({
|
|
@@ -657,9 +672,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID(
|
|
|
657
672
|
insert: S["insert"]["Type"]
|
|
658
673
|
): Effect.Effect<void, Schema.SchemaError, S["insert"]["EncodingServices"]> =>
|
|
659
674
|
insertVoidSchema(insert).pipe(
|
|
660
|
-
|
|
661
|
-
captureStackTrace: false
|
|
662
|
-
})
|
|
675
|
+
opSpan("insertVoid")
|
|
663
676
|
) as any
|
|
664
677
|
|
|
665
678
|
const updateSchema = SqlSchema.findOne({
|
|
@@ -706,11 +719,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = ${request[idCol
|
|
|
706
719
|
): Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"] | S["update"]["EncodingServices"]> =>
|
|
707
720
|
updateSchema(update).pipe(
|
|
708
721
|
Effect.catchTag("NoSuchElementError", Effect.die),
|
|
709
|
-
|
|
710
|
-
attributes: { id: (update as any)[idColumn] }
|
|
711
|
-
}, {
|
|
712
|
-
captureStackTrace: false
|
|
713
|
-
})
|
|
722
|
+
opSpan("update", (update as any)[idColumn])
|
|
714
723
|
) as any
|
|
715
724
|
|
|
716
725
|
const updateVoidSchema = SqlSchema.void({
|
|
@@ -729,11 +738,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = ${request[idCol
|
|
|
729
738
|
update: S["update"]["Type"]
|
|
730
739
|
): Effect.Effect<void, Schema.SchemaError, S["update"]["EncodingServices"]> =>
|
|
731
740
|
updateVoidSchema(update).pipe(
|
|
732
|
-
|
|
733
|
-
attributes: { id: (update as any)[idColumn] }
|
|
734
|
-
}, {
|
|
735
|
-
captureStackTrace: false
|
|
736
|
-
})
|
|
741
|
+
opSpan("updateVoid", (update as any)[idColumn])
|
|
737
742
|
) as any
|
|
738
743
|
|
|
739
744
|
const findByIdSchema = SqlSchema.findOneOption({
|
|
@@ -749,9 +754,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = ${request[idCol
|
|
|
749
754
|
S["DecodingServices"] | S["fields"][Id]["EncodingServices"]
|
|
750
755
|
> =>
|
|
751
756
|
findByIdSchema(id).pipe(
|
|
752
|
-
|
|
753
|
-
captureStackTrace: false
|
|
754
|
-
})
|
|
757
|
+
opSpan("findById", id)
|
|
755
758
|
) as any
|
|
756
759
|
|
|
757
760
|
const deleteSchema = SqlSchema.void({
|
|
@@ -762,11 +765,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = ${request[idCol
|
|
|
762
765
|
id: S["fields"][Id]["Type"]
|
|
763
766
|
): Effect.Effect<void, Schema.SchemaError, S["fields"][Id]["EncodingServices"]> =>
|
|
764
767
|
deleteSchema(id).pipe(
|
|
765
|
-
|
|
766
|
-
attributes: { id }
|
|
767
|
-
}, {
|
|
768
|
-
captureStackTrace: false
|
|
769
|
-
})
|
|
768
|
+
opSpan("delete", id)
|
|
770
769
|
) as any
|
|
771
770
|
|
|
772
771
|
return { insert, insertVoid, update, updateVoid, findById, delete: delete_ } as const
|
|
@@ -789,6 +788,7 @@ export const makeDataLoaders = <
|
|
|
789
788
|
readonly idColumn: Id
|
|
790
789
|
readonly window: Input
|
|
791
790
|
readonly maxBatchSize?: number | undefined
|
|
791
|
+
readonly dbSystem?: DbSystem | undefined
|
|
792
792
|
}
|
|
793
793
|
): Effect.Effect<
|
|
794
794
|
{
|
|
@@ -821,6 +821,15 @@ export const makeDataLoaders = <
|
|
|
821
821
|
const idSchema = Model.fields[options.idColumn] as Schema.Top
|
|
822
822
|
const idColumn = options.idColumn as string
|
|
823
823
|
const setMaxBatchSize = options.maxBatchSize ? RequestResolver.batchN(options.maxBatchSize) : identity
|
|
824
|
+
const system: DbSystem = options.dbSystem ?? "other_sql"
|
|
825
|
+
const opSpan = (operation: string, idValue?: unknown) =>
|
|
826
|
+
withDbSpan({
|
|
827
|
+
operation,
|
|
828
|
+
system,
|
|
829
|
+
collection: options.tableName,
|
|
830
|
+
entity: options.spanPrefix,
|
|
831
|
+
...(idValue !== undefined && { extra: { "app.entity.id": idValue } })
|
|
832
|
+
})
|
|
824
833
|
|
|
825
834
|
const insertResolver = SqlResolver
|
|
826
835
|
.ordered({
|
|
@@ -854,9 +863,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID(
|
|
|
854
863
|
> =>
|
|
855
864
|
insertExecute(insert).pipe(
|
|
856
865
|
Effect.catchTag("ResultLengthMismatch", Effect.die),
|
|
857
|
-
|
|
858
|
-
captureStackTrace: false
|
|
859
|
-
})
|
|
866
|
+
opSpan("insert")
|
|
860
867
|
) as any
|
|
861
868
|
|
|
862
869
|
const insertVoidResolver = SqlResolver
|
|
@@ -874,9 +881,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID(
|
|
|
874
881
|
insert: S["insert"]["Type"]
|
|
875
882
|
): Effect.Effect<void, Schema.SchemaError, S["insert"]["EncodingServices"]> =>
|
|
876
883
|
insertVoidExecute(insert).pipe(
|
|
877
|
-
|
|
878
|
-
captureStackTrace: false
|
|
879
|
-
})
|
|
884
|
+
opSpan("insertVoid")
|
|
880
885
|
) as any
|
|
881
886
|
|
|
882
887
|
const findByIdResolver = SqlResolver
|
|
@@ -902,9 +907,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID(
|
|
|
902
907
|
S["DecodingServices"] | S["fields"][Id]["EncodingServices"]
|
|
903
908
|
> =>
|
|
904
909
|
findByIdExecute(id).pipe(
|
|
905
|
-
|
|
906
|
-
captureStackTrace: false
|
|
907
|
-
})
|
|
910
|
+
opSpan("findById", id)
|
|
908
911
|
) as any
|
|
909
912
|
|
|
910
913
|
const deleteResolver = SqlResolver
|
|
@@ -922,9 +925,7 @@ select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID(
|
|
|
922
925
|
id: S["fields"][Id]["Type"]
|
|
923
926
|
): Effect.Effect<void, Schema.SchemaError, S["fields"][Id]["EncodingServices"]> =>
|
|
924
927
|
deleteExecute(id).pipe(
|
|
925
|
-
|
|
926
|
-
captureStackTrace: false
|
|
927
|
-
})
|
|
928
|
+
opSpan("delete", id)
|
|
928
929
|
) as any
|
|
929
930
|
|
|
930
931
|
return { insert, insertVoid, findById, delete: delete_ } as const
|
package/src/SQL.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as SQLModel from "./SQL/Model.ts"
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
|
-
import
|
|
3
|
+
import * as Array from "effect-app/Array"
|
|
4
|
+
import type { NonEmptyReadonlyArray } from "effect-app/Array"
|
|
5
|
+
import * as Effect from "effect-app/Effect"
|
|
6
|
+
import type { FilterR, FilterResult, Ops } from "effect-app/Model/filter/filterApi"
|
|
7
|
+
import type { AggregateIrExpression, ComputedProjectionIrExpression, ComputedProjectionMathIrExpression } from "effect-app/Model/query"
|
|
8
|
+
import type { SupportedValues } from "effect-app/Store"
|
|
4
9
|
import { assertUnreachable } from "effect-app/utils"
|
|
5
|
-
import { InfraLogger } from "../../logger.
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import type { SupportedValues } from "../service.js"
|
|
10
|
+
import { InfraLogger } from "../../logger.ts"
|
|
11
|
+
import { isRelationCheck } from "../codeFilter.ts"
|
|
12
|
+
import { jsonifyFilter, type JsonLower } from "../utils.ts"
|
|
9
13
|
|
|
10
14
|
export function logQuery(q: {
|
|
11
15
|
query: string
|
|
@@ -40,12 +44,30 @@ export function buildWhereCosmosQuery3(
|
|
|
40
44
|
filter: readonly FilterResult[],
|
|
41
45
|
name: string,
|
|
42
46
|
defaultValues: Record<string, unknown>,
|
|
43
|
-
select?: NonEmptyReadonlyArray<
|
|
47
|
+
select?: NonEmptyReadonlyArray<
|
|
48
|
+
string | {
|
|
49
|
+
key: string
|
|
50
|
+
subKeys: readonly string[]
|
|
51
|
+
} | {
|
|
52
|
+
key: string
|
|
53
|
+
computed: ComputedProjectionIrExpression
|
|
54
|
+
} | {
|
|
55
|
+
key: string
|
|
56
|
+
path: string
|
|
57
|
+
} | {
|
|
58
|
+
key: string
|
|
59
|
+
aggregate: AggregateIrExpression
|
|
60
|
+
}
|
|
61
|
+
>,
|
|
44
62
|
order?: NonEmptyReadonlyArray<{ key: string; direction: "ASC" | "DESC" }>,
|
|
45
63
|
skip?: number,
|
|
46
|
-
limit?: number
|
|
64
|
+
limit?: number,
|
|
65
|
+
json?: JsonLower
|
|
47
66
|
) {
|
|
48
|
-
|
|
67
|
+
// defaultValues are already JSON-lowered at store construction; a second
|
|
68
|
+
// schema encode of an ISO Date string throws "Expected a valid Date".
|
|
69
|
+
filter = (json?.jsonifyFilter ?? jsonifyFilter)(filter)
|
|
70
|
+
const statement = (x: FilterR, i: number) => {
|
|
49
71
|
if (x.path === idKey) {
|
|
50
72
|
x = { ...x, path: "id" }
|
|
51
73
|
}
|
|
@@ -60,8 +82,6 @@ export function buildWhereCosmosQuery3(
|
|
|
60
82
|
|
|
61
83
|
const v = "@v" + i
|
|
62
84
|
|
|
63
|
-
const realValue = values[i]
|
|
64
|
-
|
|
65
85
|
switch (x.op) {
|
|
66
86
|
case "in":
|
|
67
87
|
return `ARRAY_CONTAINS(${v}, ${k})`
|
|
@@ -74,14 +94,55 @@ export function buildWhereCosmosQuery3(
|
|
|
74
94
|
return `(NOT ARRAY_CONTAINS(${k}, ${v}))`
|
|
75
95
|
|
|
76
96
|
case "includes-any":
|
|
77
|
-
return `ARRAY_CONTAINS_ANY(${k}, ${(
|
|
97
|
+
return `ARRAY_CONTAINS_ANY(${k}, ${(x.value as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")})`
|
|
78
98
|
case "notIncludes-any":
|
|
79
|
-
return `(NOT ARRAY_CONTAINS_ANY(${k}, ${
|
|
99
|
+
return `(NOT ARRAY_CONTAINS_ANY(${k}, ${
|
|
100
|
+
(x.value as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")
|
|
101
|
+
}))`
|
|
80
102
|
|
|
81
103
|
case "includes-all":
|
|
82
|
-
return `ARRAY_CONTAINS_ALL(${k}, ${(
|
|
104
|
+
return `ARRAY_CONTAINS_ALL(${k}, ${(x.value as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")})`
|
|
83
105
|
case "notIncludes-all":
|
|
84
|
-
return `(NOT ARRAY_CONTAINS_ALL(${k}, ${
|
|
106
|
+
return `(NOT ARRAY_CONTAINS_ALL(${k}, ${
|
|
107
|
+
(x.value as readonly unknown[]).map((_, i) => `${v}__${i}`).join(", ")
|
|
108
|
+
}))`
|
|
109
|
+
|
|
110
|
+
case "hasKey":
|
|
111
|
+
return `EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[0] = ${v})`
|
|
112
|
+
case "notHasKey":
|
|
113
|
+
return `(NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[0] = ${v}))`
|
|
114
|
+
case "hasValue":
|
|
115
|
+
return `EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[1] = ${v})`
|
|
116
|
+
case "notHasValue":
|
|
117
|
+
return `(NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[1] = ${v}))`
|
|
118
|
+
case "hasKeyValue":
|
|
119
|
+
return `ARRAY_CONTAINS(${k}, ${v})`
|
|
120
|
+
case "notHasKeyValue":
|
|
121
|
+
return `(NOT ARRAY_CONTAINS(${k}, ${v}))`
|
|
122
|
+
case "hasKey-any":
|
|
123
|
+
return `EXISTS(SELECT VALUE p FROM p IN ${k} WHERE ARRAY_CONTAINS(${v}, p[0]))`
|
|
124
|
+
case "notHasKey-any":
|
|
125
|
+
return `(NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE ARRAY_CONTAINS(${v}, p[0])))`
|
|
126
|
+
case "hasKey-all":
|
|
127
|
+
return `(NOT EXISTS(SELECT VALUE key FROM key IN ${v} WHERE NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[0] = key)))`
|
|
128
|
+
case "notHasKey-all":
|
|
129
|
+
return `EXISTS(SELECT VALUE key FROM key IN ${v} WHERE NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[0] = key))`
|
|
130
|
+
case "hasValue-any":
|
|
131
|
+
return `EXISTS(SELECT VALUE p FROM p IN ${k} WHERE ARRAY_CONTAINS(${v}, p[1]))`
|
|
132
|
+
case "notHasValue-any":
|
|
133
|
+
return `(NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE ARRAY_CONTAINS(${v}, p[1])))`
|
|
134
|
+
case "hasValue-all":
|
|
135
|
+
return `(NOT EXISTS(SELECT VALUE val FROM val IN ${v} WHERE NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[1] = val)))`
|
|
136
|
+
case "notHasValue-all":
|
|
137
|
+
return `EXISTS(SELECT VALUE val FROM val IN ${v} WHERE NOT EXISTS(SELECT VALUE p FROM p IN ${k} WHERE p[1] = val))`
|
|
138
|
+
case "hasKeyValue-any":
|
|
139
|
+
return `EXISTS(SELECT VALUE pair FROM pair IN ${v} WHERE ARRAY_CONTAINS(${k}, pair))`
|
|
140
|
+
case "notHasKeyValue-any":
|
|
141
|
+
return `(NOT EXISTS(SELECT VALUE pair FROM pair IN ${v} WHERE ARRAY_CONTAINS(${k}, pair)))`
|
|
142
|
+
case "hasKeyValue-all":
|
|
143
|
+
return `(NOT EXISTS(SELECT VALUE pair FROM pair IN ${v} WHERE NOT ARRAY_CONTAINS(${k}, pair)))`
|
|
144
|
+
case "notHasKeyValue-all":
|
|
145
|
+
return `EXISTS(SELECT VALUE pair FROM pair IN ${v} WHERE NOT ARRAY_CONTAINS(${k}, pair))`
|
|
85
146
|
|
|
86
147
|
case "contains":
|
|
87
148
|
return `CONTAINS(${k}, ${v}, true)`
|
|
@@ -143,6 +204,24 @@ export function buildWhereCosmosQuery3(
|
|
|
143
204
|
"notIncludes-any": "includes-any",
|
|
144
205
|
"includes-all": "notIncludes-all",
|
|
145
206
|
"notIncludes-all": "includes-all",
|
|
207
|
+
hasKey: "notHasKey",
|
|
208
|
+
notHasKey: "hasKey",
|
|
209
|
+
hasValue: "notHasValue",
|
|
210
|
+
notHasValue: "hasValue",
|
|
211
|
+
hasKeyValue: "notHasKeyValue",
|
|
212
|
+
notHasKeyValue: "hasKeyValue",
|
|
213
|
+
"hasKey-any": "notHasKey-any",
|
|
214
|
+
"notHasKey-any": "hasKey-any",
|
|
215
|
+
"hasKey-all": "notHasKey-all",
|
|
216
|
+
"notHasKey-all": "hasKey-all",
|
|
217
|
+
"hasValue-any": "notHasValue-any",
|
|
218
|
+
"notHasValue-any": "hasValue-any",
|
|
219
|
+
"hasValue-all": "notHasValue-all",
|
|
220
|
+
"notHasValue-all": "hasValue-all",
|
|
221
|
+
"hasKeyValue-any": "notHasKeyValue-any",
|
|
222
|
+
"notHasKeyValue-any": "hasKeyValue-any",
|
|
223
|
+
"hasKeyValue-all": "notHasKeyValue-all",
|
|
224
|
+
"notHasKeyValue-all": "hasKeyValue-all",
|
|
146
225
|
in: "notIn",
|
|
147
226
|
notIn: "in"
|
|
148
227
|
} satisfies Record<Ops, Ops>
|
|
@@ -165,7 +244,7 @@ export function buildWhereCosmosQuery3(
|
|
|
165
244
|
: _
|
|
166
245
|
: _
|
|
167
246
|
|
|
168
|
-
const print = (state: readonly FilterResult[],
|
|
247
|
+
const print = (state: readonly FilterResult[], isRelation: string | null, every: boolean) => {
|
|
169
248
|
let s = ""
|
|
170
249
|
let l = 0
|
|
171
250
|
const printN = (n: number) => {
|
|
@@ -174,13 +253,13 @@ export function buildWhereCosmosQuery3(
|
|
|
174
253
|
for (const e of state) {
|
|
175
254
|
switch (e.t) {
|
|
176
255
|
case "where":
|
|
177
|
-
s += statement(e, i
|
|
256
|
+
s += statement(e, i++)
|
|
178
257
|
break
|
|
179
258
|
case "or":
|
|
180
|
-
s += ` OR ${statement(e, i
|
|
259
|
+
s += ` OR ${statement(e, i++)}`
|
|
181
260
|
break
|
|
182
261
|
case "and":
|
|
183
|
-
s += ` AND ${statement(e, i
|
|
262
|
+
s += ` AND ${statement(e, i++)}`
|
|
184
263
|
break
|
|
185
264
|
case "or-scope": {
|
|
186
265
|
++l
|
|
@@ -189,7 +268,7 @@ export function buildWhereCosmosQuery3(
|
|
|
189
268
|
if (rel) {
|
|
190
269
|
const rel = (e.result[0]! as { path: string }).path.split(".-1.")[0]
|
|
191
270
|
s += isRelation
|
|
192
|
-
? ` OR (\n${printN(l + 1)}${print(e.result,
|
|
271
|
+
? ` OR (\n${printN(l + 1)}${print(e.result, rel, every)}\n${printN(l)})`
|
|
193
272
|
: ` OR (\n${printN(l + 1)}${
|
|
194
273
|
every ? "NOT " : ""
|
|
195
274
|
}EXISTS(SELECT VALUE ${rel} FROM ${rel} IN f.${rel} WHERE ${
|
|
@@ -197,13 +276,12 @@ export function buildWhereCosmosQuery3(
|
|
|
197
276
|
e
|
|
198
277
|
.result
|
|
199
278
|
.map(flip(every)),
|
|
200
|
-
values,
|
|
201
279
|
rel,
|
|
202
280
|
every
|
|
203
281
|
)
|
|
204
282
|
}))`
|
|
205
283
|
} else {
|
|
206
|
-
s += ` OR (\n${printN(l + 1)}${print(e.result,
|
|
284
|
+
s += ` OR (\n${printN(l + 1)}${print(e.result, null, every)}\n${printN(l)})`
|
|
207
285
|
}
|
|
208
286
|
--l
|
|
209
287
|
break
|
|
@@ -215,14 +293,14 @@ export function buildWhereCosmosQuery3(
|
|
|
215
293
|
if (rel) {
|
|
216
294
|
const rel = (e.result[0]! as { path: string }).path.split(".-1.")[0]
|
|
217
295
|
s += isRelation
|
|
218
|
-
? ` AND (\n${printN(l + 1)}${print(e.result,
|
|
296
|
+
? ` AND (\n${printN(l + 1)}${print(e.result, rel, every)}\n${printN(l)})`
|
|
219
297
|
: ` AND (\n${printN(l + 1)}${
|
|
220
298
|
every ? "NOT " : ""
|
|
221
299
|
}EXISTS(SELECT VALUE ${rel} FROM ${rel} IN f.${rel} WHERE ${
|
|
222
|
-
print(e.result.map(flip(every)),
|
|
300
|
+
print(e.result.map(flip(every)), rel, every)
|
|
223
301
|
}))`
|
|
224
302
|
} else {
|
|
225
|
-
s += ` AND (\n${printN(l + 1)}${print(e.result,
|
|
303
|
+
s += ` AND (\n${printN(l + 1)}${print(e.result, null, every)}\n${printN(l)})`
|
|
226
304
|
}
|
|
227
305
|
--l
|
|
228
306
|
break
|
|
@@ -234,12 +312,12 @@ export function buildWhereCosmosQuery3(
|
|
|
234
312
|
if (rel) {
|
|
235
313
|
const rel = (e.result[0]! as { path: string }).path.split(".-1.")[0]
|
|
236
314
|
s += isRelation
|
|
237
|
-
? `(\n${printN(l + 1)}${print(e.result,
|
|
315
|
+
? `(\n${printN(l + 1)}${print(e.result, rel, every)}\n${printN(l)})`
|
|
238
316
|
: `(\n${printN(l + 1)}${every ? "NOT " : ""}EXISTS(SELECT VALUE ${rel} FROM ${rel} IN f.${rel} WHERE ${
|
|
239
|
-
print(e.result.map(flip(every)),
|
|
317
|
+
print(e.result.map(flip(every)), rel, every)
|
|
240
318
|
}))`
|
|
241
319
|
} else {
|
|
242
|
-
s += `(\n${printN(l + 1)}${print(e.result,
|
|
320
|
+
s += `(\n${printN(l + 1)}${print(e.result, null, every)}\n${printN(l)})`
|
|
243
321
|
}
|
|
244
322
|
// ;--l
|
|
245
323
|
break
|
|
@@ -272,40 +350,182 @@ export function buildWhereCosmosQuery3(
|
|
|
272
350
|
? getValues(_.result)
|
|
273
351
|
: [_]
|
|
274
352
|
)
|
|
275
|
-
const
|
|
353
|
+
const computedFilters = select
|
|
354
|
+
? select.flatMap((_) =>
|
|
355
|
+
typeof _ === "object" && "computed" in _ && "filter" in _.computed ? getValues(_.computed.filter) : []
|
|
356
|
+
)
|
|
357
|
+
: []
|
|
358
|
+
const aggregateFilters = select
|
|
359
|
+
? select.flatMap((_) =>
|
|
360
|
+
typeof _ === "object" && "aggregate" in _ && "filter" in _.aggregate ? getValues(_.aggregate.filter) : []
|
|
361
|
+
)
|
|
362
|
+
: []
|
|
363
|
+
const values = [...computedFilters, ...aggregateFilters, ...getValues(filter)]
|
|
364
|
+
|
|
365
|
+
const hasAggregates = select
|
|
366
|
+
? select.some((s) => typeof s === "object" && s !== null && "aggregate" in s)
|
|
367
|
+
: false
|
|
368
|
+
|
|
369
|
+
const aggregateSelectExpr = (key: string, agg: AggregateIrExpression): string => {
|
|
370
|
+
switch (agg._tag) {
|
|
371
|
+
case "agg-count":
|
|
372
|
+
return `COUNT(1) AS ${key}`
|
|
373
|
+
case "agg-count-when": {
|
|
374
|
+
if (agg.filter.length === 0) return `COUNT(1) AS ${key}`
|
|
375
|
+
const cond = print(agg.filter, null, false)
|
|
376
|
+
// Cosmos supports SUM(IIF(cond, 1, 0)) as a conditional count
|
|
377
|
+
return `SUM(IIF(${cond}, 1, 0)) AS ${key}`
|
|
378
|
+
}
|
|
379
|
+
case "agg-sum": {
|
|
380
|
+
const fieldRef = dottedToAccess(`f.${agg.field}`)
|
|
381
|
+
return `SUM(${fieldRef}) AS ${key}`
|
|
382
|
+
}
|
|
383
|
+
case "agg-min": {
|
|
384
|
+
const fieldRef = dottedToAccess(`f.${agg.field}`)
|
|
385
|
+
return `MIN(${fieldRef}) AS ${key}`
|
|
386
|
+
}
|
|
387
|
+
case "agg-max": {
|
|
388
|
+
const fieldRef = dottedToAccess(`f.${agg.field}`)
|
|
389
|
+
return `MAX(${fieldRef}) AS ${key}`
|
|
390
|
+
}
|
|
391
|
+
default:
|
|
392
|
+
return assertUnreachable(agg)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const computedSelectExpr = (key: string, computed: ComputedProjectionIrExpression) => {
|
|
397
|
+
const relationPath = computed.path
|
|
398
|
+
const relationAlias = relationPath
|
|
399
|
+
const relationSource = dottedToAccess(`f.${relationPath}`)
|
|
400
|
+
const compileExpr = (expression: ComputedProjectionMathIrExpression): string => {
|
|
401
|
+
switch (expression._tag) {
|
|
402
|
+
case "field":
|
|
403
|
+
return dottedToAccess(`${relationAlias}.${expression.field}`)
|
|
404
|
+
case "mul":
|
|
405
|
+
return `(${compileExpr(expression.left)} * ${compileExpr(expression.right)})`
|
|
406
|
+
default:
|
|
407
|
+
return assertUnreachable(expression)
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const factorExpr = (unitExpr: string, toBase: string, factors: Readonly<Record<string, number>>) => {
|
|
411
|
+
const entries = Object.entries(factors).filter(([, factor]) => Number.isFinite(factor))
|
|
412
|
+
return entries.reduceRight<string>(
|
|
413
|
+
(acc, [unit, factor]) => `IIF(${unitExpr} = ${JSON.stringify(unit)}, ${factor}, ${acc})`,
|
|
414
|
+
`IIF(${unitExpr} = ${JSON.stringify(toBase)}, 1, 0)`
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
const filter = "filter" in computed ? computed.filter : []
|
|
418
|
+
// Print filter once — `print` mutates the outer `i` parameter counter, so
|
|
419
|
+
// re-walking the same filter would double-bump it and desync @v indices.
|
|
420
|
+
const filterSql = filter.length > 0 ? print(filter, relationPath, false) : ""
|
|
421
|
+
const where = filterSql ? ` WHERE ${filterSql}` : ""
|
|
422
|
+
switch (computed._tag) {
|
|
423
|
+
case "relation-count":
|
|
424
|
+
return `(SELECT VALUE COUNT(1) FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
425
|
+
case "relation-any":
|
|
426
|
+
return `EXISTS(SELECT VALUE ${relationAlias} FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
427
|
+
case "relation-every": {
|
|
428
|
+
// ∀x.P(x) ≡ ¬∃x.¬P(x). Cosmos has no NOT(...) on EXISTS subqueries directly,
|
|
429
|
+
// but we can flip via NOT EXISTS(... WHERE NOT (filter)).
|
|
430
|
+
if (filter.length === 0) return `true AS ${key}`
|
|
431
|
+
return `NOT EXISTS(SELECT VALUE ${relationAlias} FROM ${relationAlias} IN ${relationSource} WHERE NOT (${filterSql})) AS ${key}`
|
|
432
|
+
}
|
|
433
|
+
case "relation-distinct-count": {
|
|
434
|
+
const fieldRef = dottedToAccess(`${relationAlias}.${computed.field}`)
|
|
435
|
+
return `(SELECT VALUE COUNT(1) FROM (SELECT DISTINCT VALUE ${fieldRef} FROM ${relationAlias} IN ${relationSource}${where})) AS ${key}`
|
|
436
|
+
}
|
|
437
|
+
case "relation-sum": {
|
|
438
|
+
const fieldRef = dottedToAccess(`${relationAlias}.${computed.field}`)
|
|
439
|
+
return `(SELECT VALUE SUM(${fieldRef}) FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
440
|
+
}
|
|
441
|
+
case "relation-sum-expr": {
|
|
442
|
+
const expression = compileExpr(computed.expression)
|
|
443
|
+
return `(SELECT VALUE SUM(${expression}) FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
444
|
+
}
|
|
445
|
+
case "relation-sum-expr-by": {
|
|
446
|
+
const unitRef = dottedToAccess(`${relationAlias}.${computed.unit}`)
|
|
447
|
+
const expression = compileExpr(computed.expression)
|
|
448
|
+
return `ARRAY(SELECT VALUE { "unit": ${unitRef}, "total": SUM(${expression}) } FROM ${relationAlias} IN ${relationSource}${where} GROUP BY ${unitRef}) AS ${key}`
|
|
449
|
+
}
|
|
450
|
+
case "relation-sum-expr-normalized": {
|
|
451
|
+
const unitRef = dottedToAccess(`${relationAlias}.${computed.unit}`)
|
|
452
|
+
const expression = compileExpr(computed.expression)
|
|
453
|
+
const factor = factorExpr(unitRef, computed.toBase, computed.factors)
|
|
454
|
+
return `(SELECT VALUE SUM((${expression}) * (${factor})) FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
455
|
+
}
|
|
456
|
+
case "relation-collect": {
|
|
457
|
+
const fieldRef = dottedToAccess(`${relationAlias}.${computed.field}`)
|
|
458
|
+
if (computed.distinct) {
|
|
459
|
+
return `ARRAY(SELECT DISTINCT VALUE ${fieldRef} FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
460
|
+
}
|
|
461
|
+
return `ARRAY(SELECT VALUE ${fieldRef} FROM ${relationAlias} IN ${relationSource}${where}) AS ${key}`
|
|
462
|
+
}
|
|
463
|
+
case "relation-length":
|
|
464
|
+
return `ARRAY_LENGTH(${relationSource}) AS ${key}`
|
|
465
|
+
case "relation-collect-fields": {
|
|
466
|
+
const subqueries = computed.fields.map((field) => {
|
|
467
|
+
const fieldRef = dottedToAccess(`${relationAlias}.${field}`)
|
|
468
|
+
return computed.distinct
|
|
469
|
+
? `ARRAY(SELECT DISTINCT VALUE ${fieldRef} FROM ${relationAlias} IN ${relationSource}${where})`
|
|
470
|
+
: `ARRAY(SELECT VALUE ${fieldRef} FROM ${relationAlias} IN ${relationSource}${where})`
|
|
471
|
+
})
|
|
472
|
+
const combined = computed.distinct
|
|
473
|
+
? subqueries.reduce((acc, sq) => `SetUnion(${acc}, ${sq})`)
|
|
474
|
+
: subqueries.reduce((acc, sq) => `ARRAY_CONCAT(${acc}, ${sq})`)
|
|
475
|
+
return `${combined} AS ${key}`
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const buildSelectList = (): string => {
|
|
481
|
+
if (!select) return "f"
|
|
482
|
+
return select
|
|
483
|
+
.map((s) => {
|
|
484
|
+
if (typeof s === "string") {
|
|
485
|
+
return dottedToAccess(s === idKey ? "f.id" : `f.${s}`)
|
|
486
|
+
}
|
|
487
|
+
if ("computed" in s) return computedSelectExpr(s.key, s.computed)
|
|
488
|
+
if ("aggregate" in s) return aggregateSelectExpr(s.key, s.aggregate)
|
|
489
|
+
if ("path" in s) return `${dottedToAccess(`f.${s.path}`)} AS ${s.key}`
|
|
490
|
+
// subKeys
|
|
491
|
+
return `ARRAY (SELECT ${s.subKeys.map((_) => dottedToAccess(`t.${_}`)).join(",")}
|
|
492
|
+
FROM t in ${dottedToAccess(`f.${s.key}`)}) AS ${s.key}`
|
|
493
|
+
})
|
|
494
|
+
.join(", ")
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const groupByClause = hasAggregates && select
|
|
498
|
+
? (() => {
|
|
499
|
+
const groupByExprs = select
|
|
500
|
+
.filter((s): s is { key: string; path: string } =>
|
|
501
|
+
typeof s === "object" && s !== null && "path" in s && !("aggregate" in s)
|
|
502
|
+
)
|
|
503
|
+
.map((s) => dottedToAccess(`f.${s.path}`))
|
|
504
|
+
return groupByExprs.length > 0 ? `GROUP BY ${groupByExprs.join(", ")}` : ""
|
|
505
|
+
})()
|
|
506
|
+
: ""
|
|
507
|
+
|
|
508
|
+
const orderExpr = (key: string) => hasAggregates ? key : dottedToAccess(`f.${key}`)
|
|
509
|
+
|
|
276
510
|
// with joins, you should use DISTINCT
|
|
277
511
|
// or you can end up with duplicates
|
|
278
512
|
return {
|
|
279
513
|
query: `
|
|
280
|
-
SELECT ${
|
|
281
|
-
select
|
|
282
|
-
? `${
|
|
283
|
-
select
|
|
284
|
-
.map((s) =>
|
|
285
|
-
typeof s === "string"
|
|
286
|
-
? dottedToAccess(s === idKey ? "f.id" : `f.${s}`) // x["y"} vs x.y, helps with reserved keywords like "value"
|
|
287
|
-
: `ARRAY (SELECT ${s.subKeys.map((_) => dottedToAccess(`t.${_}`)).join(",")}
|
|
288
|
-
FROM t in ${dottedToAccess(`f.${s.key}`)}) AS ${s.key}`
|
|
289
|
-
)
|
|
290
|
-
.join(", ")
|
|
291
|
-
}`
|
|
292
|
-
: "f"
|
|
293
|
-
}
|
|
514
|
+
SELECT ${buildSelectList()}
|
|
294
515
|
FROM ${name} f
|
|
295
516
|
|
|
296
|
-
${filter.length ? `WHERE (${print(filter,
|
|
297
|
-
${
|
|
517
|
+
${filter.length ? `WHERE (${print(filter, null, false)})` : ""}
|
|
518
|
+
${groupByClause}
|
|
519
|
+
${order ? `ORDER BY ${order.map((_) => `${orderExpr(_.key)} ${_.direction}`).join(", ")}` : ""}
|
|
298
520
|
${skip !== undefined || limit !== undefined ? `OFFSET ${skip ?? 0} LIMIT ${limit ?? 999999}` : ""}`,
|
|
299
|
-
parameters:
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
)
|
|
309
|
-
]
|
|
521
|
+
parameters: values
|
|
522
|
+
.flatMap((x, i) =>
|
|
523
|
+
[{
|
|
524
|
+
name: `@v${i}`,
|
|
525
|
+
value: x.value as any
|
|
526
|
+
}]
|
|
527
|
+
// TODO: only for arrays that are used with _ANY or _ALL
|
|
528
|
+
.concat(Array.isArray(x.value) ? x.value.map((_, i2) => ({ name: `@v${i}__${i2}`, value: _ as any })) : [])
|
|
529
|
+
)
|
|
310
530
|
}
|
|
311
531
|
}
|