@effect-app/infra 4.0.0-beta.26 → 4.0.0-beta.260
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 +1966 -0
- package/_check.sh +1 -1
- package/dist/CUPS.d.ts +30 -11
- package/dist/CUPS.d.ts.map +1 -1
- package/dist/CUPS.js +35 -14
- package/dist/ClusterCosmos.d.ts +64 -0
- package/dist/ClusterCosmos.d.ts.map +1 -0
- package/dist/ClusterCosmos.js +487 -0
- package/dist/ClusterServiceBus.d.ts +67 -0
- package/dist/ClusterServiceBus.d.ts.map +1 -0
- package/dist/ClusterServiceBus.js +82 -0
- package/dist/ContextProvider.d.ts +34 -0
- package/dist/ContextProvider.d.ts.map +1 -0
- package/dist/ContextProvider.js +40 -0
- package/dist/Emailer/Sendgrid.d.ts +111 -147
- package/dist/Emailer/Sendgrid.d.ts.map +1 -1
- package/dist/Emailer/Sendgrid.js +24 -19
- package/dist/Emailer/fake.d.ts +2 -2
- package/dist/Emailer/fake.d.ts.map +1 -1
- package/dist/Emailer/fake.js +4 -4
- package/dist/MainFiberSet.d.ts +12 -9
- package/dist/MainFiberSet.d.ts.map +1 -1
- package/dist/MainFiberSet.js +10 -6
- package/dist/QueueMaker/SQLQueue.d.ts +8 -9
- package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
- package/dist/QueueMaker/SQLQueue.js +138 -120
- package/dist/QueueMaker/errors.d.ts +5 -3
- package/dist/QueueMaker/errors.d.ts.map +1 -1
- package/dist/QueueMaker/errors.js +4 -2
- package/dist/QueueMaker/memQueue.d.ts +10 -6
- package/dist/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.js +84 -68
- package/dist/QueueMaker/sbqueue.d.ts +9 -5
- package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/QueueMaker/sbqueue.js +60 -58
- package/dist/RequestFiberSet.d.ts +10 -7
- package/dist/RequestFiberSet.d.ts.map +1 -1
- package/dist/RequestFiberSet.js +13 -8
- package/dist/SQL/Model.d.ts +468 -0
- package/dist/SQL/Model.d.ts.map +1 -0
- package/dist/SQL/Model.js +469 -0
- package/dist/SQL.d.ts +2 -0
- package/dist/SQL.d.ts.map +1 -0
- package/dist/{adapters/SQL.js → SQL.js} +1 -1
- package/dist/ServiceBus.d.ts +61 -0
- package/dist/ServiceBus.d.ts.map +1 -0
- package/dist/ServiceBus.js +108 -0
- package/dist/Store/Cosmos/query.d.ts +15 -4
- package/dist/Store/Cosmos/query.d.ts.map +1 -1
- package/dist/Store/Cosmos/query.js +179 -41
- package/dist/Store/Cosmos.d.ts +3 -3
- package/dist/Store/Cosmos.d.ts.map +1 -1
- package/dist/Store/Cosmos.js +344 -246
- package/dist/Store/Disk.d.ts +5 -5
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +78 -38
- package/dist/Store/Memory.d.ts +7 -10
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +326 -66
- package/dist/Store/SQL/Pg.d.ts +4 -0
- package/dist/Store/SQL/Pg.d.ts.map +1 -0
- package/dist/Store/SQL/Pg.js +232 -0
- package/dist/Store/SQL/query.d.ts +49 -0
- package/dist/Store/SQL/query.d.ts.map +1 -0
- package/dist/Store/SQL/query.js +527 -0
- package/dist/Store/SQL.d.ts +21 -0
- package/dist/Store/SQL.d.ts.map +1 -0
- package/dist/Store/SQL.js +449 -0
- package/dist/Store/codeFilter.d.ts +5 -5
- package/dist/Store/codeFilter.d.ts.map +1 -1
- package/dist/Store/codeFilter.js +6 -3
- package/dist/Store/index.d.ts +7 -5
- package/dist/Store/index.d.ts.map +1 -1
- package/dist/Store/index.js +18 -5
- package/dist/Store/utils.d.ts +4 -3
- package/dist/Store/utils.d.ts.map +1 -1
- package/dist/Store/utils.js +5 -5
- package/dist/WorkflowEngineCosmos.d.ts +29 -0
- package/dist/WorkflowEngineCosmos.d.ts.map +1 -0
- package/dist/WorkflowEngineCosmos.js +521 -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 +2 -2
- package/dist/arbs.d.ts.map +1 -1
- package/dist/arbs.js +5 -3
- package/dist/codec.d.ts +5 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +5 -0
- package/dist/cosmos-client.d.ts +16 -0
- package/dist/cosmos-client.d.ts.map +1 -0
- package/dist/cosmos-client.js +11 -0
- package/dist/errorReporter.d.ts +7 -5
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +23 -27
- package/dist/errors.d.ts +1 -1
- package/dist/fileUtil.d.ts +2 -2
- package/dist/fileUtil.d.ts.map +1 -1
- package/dist/fileUtil.js +2 -2
- package/dist/index.d.ts +3 -2
- 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/internal/health.d.ts +3 -0
- package/dist/internal/health.d.ts.map +1 -0
- package/dist/internal/health.js +5 -0
- package/dist/layerUtils.d.ts +32 -0
- package/dist/layerUtils.d.ts.map +1 -0
- package/dist/layerUtils.js +17 -0
- package/dist/logger/jsonLogger.d.ts +2 -2
- package/dist/logger/jsonLogger.d.ts.map +1 -1
- package/dist/logger/jsonLogger.js +5 -3
- package/dist/logger/logFmtLogger.d.ts +2 -2
- package/dist/logger/logFmtLogger.d.ts.map +1 -1
- package/dist/logger/logFmtLogger.js +3 -3
- package/dist/logger/shared.d.ts +3 -3
- package/dist/logger/shared.d.ts.map +1 -1
- package/dist/logger/shared.js +5 -5
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/memQueue.d.ts +15 -0
- package/dist/memQueue.d.ts.map +1 -0
- package/dist/memQueue.js +21 -0
- package/dist/middlewares.d.ts +10 -0
- package/dist/middlewares.d.ts.map +1 -0
- package/dist/{api/middlewares.js → middlewares.js} +1 -1
- package/dist/mongo-client.d.ts +11 -0
- 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 +65 -0
- package/dist/rateLimit.d.ts +12 -4
- package/dist/rateLimit.d.ts.map +1 -1
- package/dist/rateLimit.js +7 -12
- package/dist/redis-client.d.ts +42 -0
- package/dist/redis-client.d.ts.map +1 -0
- package/dist/redis-client.js +98 -0
- package/dist/reportError.d.ts +4 -0
- package/dist/reportError.d.ts.map +1 -0
- package/dist/reportError.js +28 -0
- package/dist/routing/middleware/RouterMiddleware.d.ts +16 -0
- package/dist/routing/middleware/RouterMiddleware.d.ts.map +1 -0
- package/dist/{api/routing → routing}/middleware/RouterMiddleware.js +1 -1
- package/dist/routing/middleware/middleware.d.ts +48 -0
- package/dist/routing/middleware/middleware.d.ts.map +1 -0
- package/dist/routing/middleware/middleware.js +128 -0
- package/dist/routing/middleware.d.ts +3 -0
- 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 +4 -0
- package/dist/routing/schema/jwt.d.ts.map +1 -0
- package/dist/routing/schema/jwt.js +13 -0
- package/dist/routing/tsort.d.ts +8 -0
- package/dist/routing/tsort.d.ts.map +1 -0
- package/dist/routing/tsort.js +51 -0
- package/dist/routing/utils.d.ts +19 -0
- package/dist/routing/utils.d.ts.map +1 -0
- package/dist/routing/utils.js +45 -0
- package/dist/routing.d.ts +184 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +236 -0
- package/dist/test.d.ts +3 -3
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +2 -2
- package/dist/util.d.ts +3 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +14 -0
- package/dist/vitest.d.ts +1 -1
- package/docs/cluster-storage.md +26 -0
- package/docs/workflow-engine.md +262 -0
- package/examples/query.ts +47 -39
- package/package.json +31 -345
- package/run.sh +1 -0
- package/src/CUPS.ts +52 -13
- package/src/ClusterCosmos.ts +954 -0
- package/src/ClusterServiceBus.ts +242 -0
- package/src/{api/ContextProvider.ts → ContextProvider.ts} +19 -16
- package/src/Emailer/Sendgrid.ts +82 -59
- package/src/Emailer/fake.ts +3 -3
- package/src/MainFiberSet.ts +12 -10
- package/src/QueueMaker/SQLQueue.ts +153 -156
- package/src/QueueMaker/errors.ts +3 -1
- package/src/QueueMaker/memQueue.ts +113 -107
- package/src/QueueMaker/sbqueue.ts +78 -90
- package/src/RequestFiberSet.ts +13 -8
- package/src/{adapters/SQL → SQL}/Model.ts +42 -41
- package/src/ServiceBus.ts +219 -0
- package/src/Store/Cosmos/query.ts +216 -52
- package/src/Store/Cosmos.ts +493 -353
- package/src/Store/Disk.ts +109 -69
- package/src/Store/Memory.ts +365 -96
- package/src/Store/SQL/Pg.ts +363 -0
- package/src/Store/SQL/query.ts +603 -0
- package/src/Store/SQL.ts +735 -0
- package/src/Store/codeFilter.ts +8 -5
- package/src/Store/index.ts +21 -6
- package/src/Store/utils.ts +26 -24
- package/src/WorkflowEngineCosmos.ts +719 -0
- package/src/WorkflowEngineSqlite.ts +813 -0
- package/src/arbs.ts +5 -3
- package/src/{adapters/cosmos-client.ts → cosmos-client.ts} +5 -3
- package/src/errorReporter.ts +66 -76
- 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 +22 -13
- package/src/{api/layerUtils.ts → layerUtils.ts} +14 -10
- package/src/logger/jsonLogger.ts +4 -2
- package/src/logger/logFmtLogger.ts +2 -2
- package/src/logger/shared.ts +5 -4
- package/src/{adapters/memQueue.ts → memQueue.ts} +5 -4
- package/src/{adapters/mongo-client.ts → mongo-client.ts} +4 -2
- package/src/otel.ts +152 -0
- package/src/rateLimit.ts +34 -23
- package/src/{adapters/redis-client.ts → redis-client.ts} +7 -3
- package/src/{api/reportError.ts → reportError.ts} +3 -2
- package/src/{api/routing → routing}/middleware/RouterMiddleware.ts +5 -4
- package/src/{api/routing → routing}/middleware/middleware.ts +62 -17
- package/src/routing/middleware.ts +4 -0
- package/src/{api/routing → routing}/schema/jwt.ts +2 -1
- package/src/{api/routing → routing}/utils.ts +2 -1
- package/src/routing.ts +768 -0
- package/src/test.ts +2 -2
- package/test/auth.test.ts +101 -0
- package/test/cluster-cosmos.test.ts +503 -0
- package/test/cluster-servicebus.test.ts +180 -0
- package/test/contextProvider.test.ts +15 -12
- package/test/controller.test.ts +28 -32
- package/test/cosmos-query.test.ts +159 -0
- package/test/dist/_check-agg-infer.test-d.d.ts +2 -0
- package/test/dist/_check-agg-infer.test-d.d.ts.map +1 -0
- package/test/dist/_check-agg-infer.test-d.js +19 -0
- package/test/dist/_check-proj-infer.test-d.d.ts +2 -0
- package/test/dist/_check-proj-infer.test-d.d.ts.map +1 -0
- package/test/dist/_check-proj-infer.test-d.js +16 -0
- package/test/dist/_check-tighten.test-d.d.ts +2 -0
- package/test/dist/_check-tighten.test-d.d.ts.map +1 -0
- package/test/dist/_check-tighten.test-d.js +21 -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/contextProvider.test.d.ts.map +1 -1
- package/test/dist/controller.test.d.ts.map +1 -1
- package/test/dist/cosmos-query.test.d.ts.map +1 -0
- package/test/dist/date-query.test.d.ts.map +1 -0
- package/test/dist/fixtures.d.ts +30 -12
- package/test/dist/fixtures.d.ts.map +1 -1
- package/test/dist/fixtures.js +17 -10
- 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/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/sql-store.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 +16 -9
- package/test/layerUtils.test.ts +2 -2
- package/test/query.test.ts +905 -40
- package/test/rawQuery.test.ts +340 -22
- package/test/repository-ext.test.ts +62 -0
- package/test/requires.test.ts +10 -5
- package/test/router-generator.test.ts +187 -0
- package/test/routing-interruptibility.test.ts +66 -0
- package/test/rpc-context-map-streaming.test.ts +262 -0
- package/test/rpc-e2e-invalidation.test.ts +256 -0
- package/test/rpc-multi-middleware.test.ts +85 -10
- package/test/rpc-stream-fullstack.test.ts +304 -0
- package/test/sql-store.test.ts +1711 -0
- package/test/validateSample.test.ts +26 -14
- package/test/workflow-engine-cosmos.test.ts +354 -0
- package/test/workflow-engine-sqlite.test.ts +299 -0
- package/tsconfig.examples.json +1 -1
- package/tsconfig.json +2 -1
- package/tsconfig.json.bak +2 -2
- 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 -316
- 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 -42
- 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/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 -63
- package/dist/RequestContext.d.ts.map +0 -1
- package/dist/RequestContext.js +0 -49
- package/dist/Store/ContextMapContainer.d.ts +0 -14
- package/dist/Store/ContextMapContainer.d.ts.map +0 -1
- package/dist/Store/ContextMapContainer.js +0 -16
- package/dist/Store/service.d.ts +0 -108
- package/dist/Store/service.d.ts.map +0 -1
- package/dist/Store/service.js +0 -71
- 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 +0 -479
- package/dist/adapters/SQL/Model.d.ts.map +0 -1
- package/dist/adapters/SQL/Model.js +0 -478
- package/dist/adapters/SQL.d.ts +0 -2
- 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 +0 -10
- 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 +0 -39
- package/dist/adapters/redis-client.d.ts.map +0 -1
- package/dist/adapters/redis-client.js +0 -94
- package/dist/api/ContextProvider.d.ts +0 -31
- package/dist/api/ContextProvider.d.ts.map +0 -1
- package/dist/api/ContextProvider.js +0 -38
- package/dist/api/codec.d.ts +0 -5
- 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 +0 -3
- package/dist/api/internal/health.d.ts.map +0 -1
- package/dist/api/internal/health.js +0 -5
- package/dist/api/layerUtils.d.ts +0 -24
- package/dist/api/layerUtils.d.ts.map +0 -1
- package/dist/api/layerUtils.js +0 -16
- package/dist/api/middlewares.d.ts +0 -10
- package/dist/api/middlewares.d.ts.map +0 -1
- package/dist/api/reportError.d.ts +0 -4
- package/dist/api/reportError.d.ts.map +0 -1
- package/dist/api/reportError.js +0 -27
- package/dist/api/routing/middleware/RouterMiddleware.d.ts +0 -15
- package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +0 -1
- package/dist/api/routing/middleware/middleware.d.ts +0 -9
- package/dist/api/routing/middleware/middleware.d.ts.map +0 -1
- package/dist/api/routing/middleware/middleware.js +0 -92
- package/dist/api/routing/middleware.d.ts +0 -4
- package/dist/api/routing/middleware.d.ts.map +0 -1
- package/dist/api/routing/schema/jwt.d.ts +0 -4
- 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 +0 -8
- 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 +0 -19
- 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 -138
- package/dist/api/routing.d.ts.map +0 -1
- package/dist/api/routing.js +0 -166
- package/dist/api/setupRequest.d.ts +0 -12
- package/dist/api/setupRequest.d.ts.map +0 -1
- package/dist/api/setupRequest.js +0 -44
- package/dist/api/util.d.ts +0 -3
- 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 -577
- 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/service.ts +0 -17
- package/src/RequestContext.ts +0 -63
- package/src/Store/ContextMapContainer.ts +0 -20
- package/src/Store/service.ts +0 -184
- package/src/Store.ts +0 -1
- package/src/adapters/ServiceBus.ts +0 -209
- package/src/adapters/index.ts +0 -0
- package/src/adapters/logger.ts +0 -3
- package/src/api/internal/auth.ts +0 -68
- package/src/api/routing/middleware.ts +0 -6
- package/src/api/routing.ts +0 -598
- package/src/api/setupRequest.ts +0 -84
- /package/src/{adapters/SQL.ts → SQL.ts} +0 -0
- /package/src/{api/codec.ts → codec.ts} +0 -0
- /package/src/{api/internal → internal}/health.ts +0 -0
- /package/src/{api/middlewares.ts → middlewares.ts} +0 -0
- /package/src/{api/routing → routing}/tsort.ts +0 -0
- /package/src/{api/util.ts → util.ts} +0 -0
|
@@ -1,577 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import type {} from "effect/Equal"
|
|
3
|
-
import type {} from "effect/Hash"
|
|
4
|
-
import { Array, Chunk, Effect, Equivalence, flow, type NonEmptyReadonlyArray, Option, pipe, Pipeable, PubSub, Result, S, SchemaAST, ServiceMap, Unify } from "effect-app"
|
|
5
|
-
import { toNonEmptyArray } from "effect-app/Array"
|
|
6
|
-
import { NotFoundError } from "effect-app/client/errors"
|
|
7
|
-
import { flatMapOption } from "effect-app/Effect"
|
|
8
|
-
import { type Codec, NonNegativeInt } from "effect-app/Schema"
|
|
9
|
-
import { setupRequestContextFromCurrent } from "../../../api/setupRequest.js"
|
|
10
|
-
import { type FilterArgs, type PersistenceModelType, type StoreConfig, StoreMaker } from "../../../Store.js"
|
|
11
|
-
import { getContextMap } from "../../../Store/ContextMapContainer.js"
|
|
12
|
-
import type { FieldValues } from "../../filter/types.js"
|
|
13
|
-
import * as Q from "../../query.js"
|
|
14
|
-
import type { Repository } from "../service.js"
|
|
15
|
-
import { ValidationError, ValidationResult } from "../validation.js"
|
|
16
|
-
|
|
17
|
-
const dedupe = Array.dedupeWith(Equivalence.String)
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A base implementation to create a repository.
|
|
21
|
-
*/
|
|
22
|
-
export function makeRepoInternal<
|
|
23
|
-
Evt = never
|
|
24
|
-
>() {
|
|
25
|
-
return <
|
|
26
|
-
ItemType extends string,
|
|
27
|
-
R,
|
|
28
|
-
Encoded extends FieldValues,
|
|
29
|
-
T,
|
|
30
|
-
IdKey extends keyof T & keyof Encoded
|
|
31
|
-
>(
|
|
32
|
-
name: ItemType,
|
|
33
|
-
schema: S.Codec<T, Encoded, R>,
|
|
34
|
-
mapFrom: (pm: Encoded) => Encoded,
|
|
35
|
-
mapTo: (e: Encoded, etag: string | undefined) => PersistenceModelType<Encoded>,
|
|
36
|
-
idKey: IdKey
|
|
37
|
-
) => {
|
|
38
|
-
type PM = PersistenceModelType<Encoded>
|
|
39
|
-
function mapToPersistenceModel(
|
|
40
|
-
e: Encoded,
|
|
41
|
-
getEtag: (id: string) => string | undefined
|
|
42
|
-
): PM {
|
|
43
|
-
return mapTo(e, getEtag(e[idKey]))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function mapReverse(
|
|
47
|
-
{ _etag, ...e }: PM,
|
|
48
|
-
setEtag: (id: string, eTag: string | undefined) => void
|
|
49
|
-
): Encoded {
|
|
50
|
-
setEtag((e as any)[idKey], _etag)
|
|
51
|
-
return mapFrom(e as unknown as Encoded)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const mkStore = makeStore<Encoded>()(name, schema, mapTo, idKey)
|
|
55
|
-
|
|
56
|
-
function make<RInitial = never, E = never, RPublish = never, RCtx = never>(
|
|
57
|
-
args: [Evt] extends [never] ? {
|
|
58
|
-
schemaContext?: ServiceMap.ServiceMap<RCtx>
|
|
59
|
-
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
60
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
61
|
-
partitionValue?: (e?: Encoded) => string
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
: {
|
|
65
|
-
schemaContext?: ServiceMap.ServiceMap<RCtx>
|
|
66
|
-
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
|
|
67
|
-
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
68
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
69
|
-
partitionValue?: (e?: Encoded) => string
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
) {
|
|
73
|
-
return Effect
|
|
74
|
-
.gen(function*() {
|
|
75
|
-
const rctx: ServiceMap.ServiceMap<RCtx> = args.schemaContext ?? ServiceMap.empty() as any
|
|
76
|
-
const provideRctx = Effect.provide(rctx)
|
|
77
|
-
const encodeMany = flow(
|
|
78
|
-
S.encodeEffect(S.Array(schema)),
|
|
79
|
-
provideRctx,
|
|
80
|
-
Effect.withSpan("encodeMany", {}, { captureStackTrace: false })
|
|
81
|
-
)
|
|
82
|
-
const decode = flow(S.decodeEffect(schema), provideRctx)
|
|
83
|
-
const decodeMany = flow(
|
|
84
|
-
S.decodeEffect(S.Array(schema)),
|
|
85
|
-
provideRctx
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
const store = yield* mkStore(args.makeInitial, args.config)
|
|
89
|
-
const cms = Effect.map(getContextMap.pipe(Effect.orDie), (_) => ({
|
|
90
|
-
get: (id: string) => _.get(`${name}.${id}`),
|
|
91
|
-
set: (id: string, etag: string | undefined) => _.set(`${name}.${id}`, etag)
|
|
92
|
-
}))
|
|
93
|
-
|
|
94
|
-
const pub = "publishEvents" in args
|
|
95
|
-
? args.publishEvents
|
|
96
|
-
: () => Effect.void
|
|
97
|
-
const changeFeed = yield* PubSub.unbounded<[T[], "save" | "remove"]>()
|
|
98
|
-
|
|
99
|
-
const allE = cms
|
|
100
|
-
.pipe(Effect.flatMap((cm) => Effect.map(store.all, (_) => _.map((_) => mapReverse(_, cm.set)))))
|
|
101
|
-
|
|
102
|
-
const all = Effect
|
|
103
|
-
.flatMap(
|
|
104
|
-
allE,
|
|
105
|
-
(_) => decodeMany(_).pipe(Effect.orDie)
|
|
106
|
-
)
|
|
107
|
-
.pipe(Effect.map((_) => _ as T[]))
|
|
108
|
-
|
|
109
|
-
const fieldsSchema = schema as unknown as { fields: any }
|
|
110
|
-
// assumes the id field never needs a service...
|
|
111
|
-
const i = ("fields" in fieldsSchema ? S.Struct(fieldsSchema["fields"]) as unknown as typeof schema : schema)
|
|
112
|
-
.pipe((_) => {
|
|
113
|
-
let ast = _.ast
|
|
114
|
-
if (ast._tag === "Declaration") ast = ast.typeParameters[0]!
|
|
115
|
-
|
|
116
|
-
// In v4, to get the encoded (from) side of a schema, use SchemaAST.toEncoded
|
|
117
|
-
const pickIdFromAst = (a: SchemaAST.AST) => {
|
|
118
|
-
const encoded = SchemaAST.toEncoded(a)
|
|
119
|
-
if (SchemaAST.isObjects(encoded)) {
|
|
120
|
-
const field = encoded.propertySignatures.find((_) => _.name === idKey)
|
|
121
|
-
if (field) {
|
|
122
|
-
return S.Struct({ [idKey]: S.make(field.type) }) as unknown as Codec<T, Encoded>
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return S.make(a) as unknown as Codec<T, Encoded>
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return ast._tag === "Union"
|
|
129
|
-
// we need to get the Objects (TypeLiteral), in case of class it has encoding chain...
|
|
130
|
-
? S.Union(
|
|
131
|
-
ast.types.map((_) => pickIdFromAst(_))
|
|
132
|
-
)
|
|
133
|
-
: pickIdFromAst(ast)
|
|
134
|
-
})
|
|
135
|
-
const encodeId = flow(S.encodeEffect(i), provideRctx)
|
|
136
|
-
const encodeIdOnly = (id: string) =>
|
|
137
|
-
encodeId({ [idKey]: id } as any).pipe(
|
|
138
|
-
Effect.map((_: Record<string, unknown>) => _[idKey as string] as Encoded[IdKey])
|
|
139
|
-
)
|
|
140
|
-
const findEId = Effect.fnUntraced(function*(id: Encoded[IdKey]) {
|
|
141
|
-
yield* Effect.annotateCurrentSpan({ itemId: id })
|
|
142
|
-
|
|
143
|
-
return yield* Effect.flatMap(
|
|
144
|
-
store.find(id),
|
|
145
|
-
(item) =>
|
|
146
|
-
Effect.gen(function*() {
|
|
147
|
-
const { set } = yield* cms
|
|
148
|
-
return item.pipe(Option.map((_) => mapReverse(_, set)))
|
|
149
|
-
})
|
|
150
|
-
)
|
|
151
|
-
})
|
|
152
|
-
// TODO: select the particular field, instead of as struct
|
|
153
|
-
const findE = Effect.fnUntraced(function*(id: T[IdKey]) {
|
|
154
|
-
yield* Effect.annotateCurrentSpan({ itemId: id })
|
|
155
|
-
|
|
156
|
-
return yield* pipe(
|
|
157
|
-
encodeId({ [idKey]: id } as any),
|
|
158
|
-
Effect.orDie,
|
|
159
|
-
Effect.map((_) => (_ as any)[idKey]),
|
|
160
|
-
Effect.flatMap(findEId)
|
|
161
|
-
)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
const find = Effect.fn("find")(function*(id: T[IdKey]) {
|
|
165
|
-
yield* Effect.annotateCurrentSpan({ itemId: id })
|
|
166
|
-
|
|
167
|
-
return yield* flatMapOption(findE(id), (_) => Effect.orDie(decode(_)))
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
const saveAllE = (a: Iterable<Encoded>) =>
|
|
171
|
-
flatMapOption(
|
|
172
|
-
Effect
|
|
173
|
-
.sync(() => toNonEmptyArray([...a])),
|
|
174
|
-
(a) =>
|
|
175
|
-
Effect.gen(function*() {
|
|
176
|
-
const { get, set } = yield* cms
|
|
177
|
-
const items = a.map((_) => mapToPersistenceModel(_, get))
|
|
178
|
-
const ret = yield* store.batchSet(items)
|
|
179
|
-
ret.forEach((_) => set(_[idKey], _._etag))
|
|
180
|
-
})
|
|
181
|
-
)
|
|
182
|
-
.pipe(Effect.asVoid)
|
|
183
|
-
|
|
184
|
-
const saveAll = (a: Iterable<T>) =>
|
|
185
|
-
encodeMany(Array.fromIterable(a))
|
|
186
|
-
.pipe(
|
|
187
|
-
Effect.orDie,
|
|
188
|
-
Effect.andThen(saveAllE)
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
const saveAndPublish = Effect.fn("saveAndPublish")(function*(items: Iterable<T>, events: Iterable<Evt> = []) {
|
|
192
|
-
const it = Chunk.fromIterable(items)
|
|
193
|
-
const evts = [...events]
|
|
194
|
-
yield* Effect.annotateCurrentSpan({ itemIds: [...Chunk.map(it, (_) => _[idKey])], events: evts.length })
|
|
195
|
-
return yield* saveAll(it)
|
|
196
|
-
.pipe(
|
|
197
|
-
Effect.andThen(Effect.sync(() => toNonEmptyArray(evts))),
|
|
198
|
-
// TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
|
|
199
|
-
(_) => flatMapOption(_, pub),
|
|
200
|
-
Effect.andThen(PubSub.publish(changeFeed, [Chunk.toArray(it), "save"] as [T[], "save" | "remove"])),
|
|
201
|
-
Effect.asVoid
|
|
202
|
-
)
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
const removeAndPublish = Effect.fn("removeAndPublish")(function*(a: Iterable<T>, events: Iterable<Evt> = []) {
|
|
206
|
-
const { set } = yield* cms
|
|
207
|
-
const it = [...a]
|
|
208
|
-
const evts = [...events]
|
|
209
|
-
yield* Effect.annotateCurrentSpan({ itemIds: it.map((_) => _[idKey]), eventCount: evts.length })
|
|
210
|
-
const items = yield* encodeMany(it).pipe(Effect.orDie)
|
|
211
|
-
if (Array.isReadonlyArrayNonEmpty(items)) {
|
|
212
|
-
yield* store.batchRemove(
|
|
213
|
-
items.map((_) => (_[idKey])),
|
|
214
|
-
args.config?.partitionValue?.(items[0])
|
|
215
|
-
)
|
|
216
|
-
for (const e of items) {
|
|
217
|
-
set(e[idKey], undefined)
|
|
218
|
-
}
|
|
219
|
-
yield* Effect
|
|
220
|
-
.sync(() => toNonEmptyArray(evts))
|
|
221
|
-
// TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
|
|
222
|
-
.pipe((_) => flatMapOption(_, pub))
|
|
223
|
-
|
|
224
|
-
yield* PubSub.publish(changeFeed, [it, "remove"] as [T[], "save" | "remove"])
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
const removeById = Effect.fn("removeById")(function*(...ids: readonly T[IdKey][]) {
|
|
229
|
-
if (!Array.isReadonlyArrayNonEmpty(ids)) {
|
|
230
|
-
return
|
|
231
|
-
}
|
|
232
|
-
const { set } = yield* cms
|
|
233
|
-
const eids = yield* Effect.forEach(ids, (_) => encodeIdOnly(_ as any)).pipe(Effect.orDie)
|
|
234
|
-
yield* Effect.annotateCurrentSpan({ itemIds: eids })
|
|
235
|
-
yield* store.batchRemove(eids)
|
|
236
|
-
for (const id of eids) {
|
|
237
|
-
set(id, undefined)
|
|
238
|
-
}
|
|
239
|
-
yield* PubSub.publish(changeFeed, [[], "remove"] as [T[], "save" | "remove"])
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
const parseMany = (items: readonly PM[]) =>
|
|
243
|
-
Effect
|
|
244
|
-
.flatMap(cms, (cm) =>
|
|
245
|
-
decodeMany(items.map((_) => mapReverse(_, cm.set)))
|
|
246
|
-
.pipe(Effect.orDie, Effect.withSpan("parseMany", {}, { captureStackTrace: false })))
|
|
247
|
-
const parseMany2 = <A, R>(
|
|
248
|
-
items: readonly PM[],
|
|
249
|
-
schema: S.Codec<A, Encoded, R>
|
|
250
|
-
) =>
|
|
251
|
-
Effect
|
|
252
|
-
.flatMap(cms, (cm) =>
|
|
253
|
-
S
|
|
254
|
-
.decodeEffect(S.Array(schema))(
|
|
255
|
-
items.map((_) => mapReverse(_, cm.set))
|
|
256
|
-
)
|
|
257
|
-
.pipe(Effect.orDie, Effect.withSpan("parseMany2", {}, { captureStackTrace: false })))
|
|
258
|
-
const filter = <U extends keyof Encoded = keyof Encoded>(args: FilterArgs<Encoded, U>) =>
|
|
259
|
-
store
|
|
260
|
-
.filter(
|
|
261
|
-
// always enforce id and _etag because they are system fields, required for etag tracking etc
|
|
262
|
-
{
|
|
263
|
-
...args,
|
|
264
|
-
select: args.select
|
|
265
|
-
? dedupe([...args.select, idKey, "_etag" as any])
|
|
266
|
-
: undefined
|
|
267
|
-
} as typeof args
|
|
268
|
-
)
|
|
269
|
-
.pipe(
|
|
270
|
-
Effect.tap((items) =>
|
|
271
|
-
Effect.map(cms, ({ set }) => items.forEach((_) => set((_ as Encoded)[idKey], (_ as PM)._etag)))
|
|
272
|
-
)
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
// TODO: For raw we should use S.from, and drop the R...
|
|
276
|
-
const query: {
|
|
277
|
-
<A, R, From extends FieldValues>(
|
|
278
|
-
q: Q.QueryProjection<Encoded extends From ? From : never, A, R>
|
|
279
|
-
): Effect.Effect<readonly A[], S.SchemaError, R>
|
|
280
|
-
<A, R, EncodedRefined extends Encoded = Encoded>(
|
|
281
|
-
q: Q.QAll<NoInfer<Encoded>, NoInfer<EncodedRefined>, A, R>
|
|
282
|
-
): Effect.Effect<readonly A[], never, R>
|
|
283
|
-
} = (<A, R, EncodedRefined extends Encoded = Encoded>(q: Q.QAll<Encoded, EncodedRefined, A, R>) => {
|
|
284
|
-
const a = Q.toFilter(q)
|
|
285
|
-
const eff = a.mode === "project"
|
|
286
|
-
? filter(a)
|
|
287
|
-
// TODO: mapFrom but need to support per field and dependencies
|
|
288
|
-
.pipe(
|
|
289
|
-
Effect.andThen(flow(S.decodeEffect(S.Array(a.schema ?? schema)), provideRctx))
|
|
290
|
-
)
|
|
291
|
-
: a.mode === "collect"
|
|
292
|
-
? filter(a)
|
|
293
|
-
// TODO: mapFrom but need to support per field and dependencies
|
|
294
|
-
.pipe(
|
|
295
|
-
Effect.flatMap(flow(
|
|
296
|
-
S.decodeEffect(S.Array(a.schema)),
|
|
297
|
-
Effect.map(Array.getSomes),
|
|
298
|
-
provideRctx
|
|
299
|
-
))
|
|
300
|
-
)
|
|
301
|
-
: Effect.flatMap(
|
|
302
|
-
filter(a),
|
|
303
|
-
(_) =>
|
|
304
|
-
Unify.unify(
|
|
305
|
-
a.schema
|
|
306
|
-
// TODO: partial may not match?
|
|
307
|
-
? parseMany2(_ as any, a.schema as any)
|
|
308
|
-
: parseMany(_ as any)
|
|
309
|
-
)
|
|
310
|
-
)
|
|
311
|
-
return pipe(
|
|
312
|
-
a.ttype === "one"
|
|
313
|
-
? Effect.flatMap(
|
|
314
|
-
eff,
|
|
315
|
-
flow(
|
|
316
|
-
Array.head,
|
|
317
|
-
Option.match({
|
|
318
|
-
onNone: () => Effect.fail(new NotFoundError({ id: "query", /* TODO */ type: name })),
|
|
319
|
-
onSome: Effect.succeed
|
|
320
|
-
})
|
|
321
|
-
)
|
|
322
|
-
)
|
|
323
|
-
: a.ttype === "count"
|
|
324
|
-
? Effect
|
|
325
|
-
.map(eff, (_) => NonNegativeInt(_.length))
|
|
326
|
-
.pipe(Effect.catchTag("SchemaError", (e) => Effect.die(e)))
|
|
327
|
-
: eff,
|
|
328
|
-
Effect.withSpan("Repository.query [effect-app/infra]", {
|
|
329
|
-
attributes: {
|
|
330
|
-
"repository.model_name": name,
|
|
331
|
-
query: { ...a, schema: a.schema ? "__SCHEMA__" : a.schema, filter: a.filter }
|
|
332
|
-
}
|
|
333
|
-
}, { captureStackTrace: false })
|
|
334
|
-
)
|
|
335
|
-
}) as any
|
|
336
|
-
|
|
337
|
-
const validateSample = Effect.fn("validateSample")(function*(options?: {
|
|
338
|
-
percentage?: number
|
|
339
|
-
maxItems?: number
|
|
340
|
-
}) {
|
|
341
|
-
const percentage = options?.percentage ?? 0.1 // default 10%
|
|
342
|
-
const maxItems = options?.maxItems
|
|
343
|
-
|
|
344
|
-
// 1. get all IDs with projection (bypasses main schema decode)
|
|
345
|
-
const allIds = yield* store.filter({
|
|
346
|
-
t: null as unknown as Encoded,
|
|
347
|
-
select: [idKey as keyof Encoded]
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
// 2. random subset
|
|
351
|
-
const shuffled = [...allIds].sort(() => Math.random() - 0.5)
|
|
352
|
-
const sampleSize = Math.min(
|
|
353
|
-
maxItems ?? Infinity,
|
|
354
|
-
Math.ceil(allIds.length * percentage)
|
|
355
|
-
)
|
|
356
|
-
const sample = shuffled.slice(0, sampleSize)
|
|
357
|
-
|
|
358
|
-
// 3. validate each item
|
|
359
|
-
const errors: ValidationError[] = []
|
|
360
|
-
|
|
361
|
-
for (const item of sample) {
|
|
362
|
-
const id = item[idKey]
|
|
363
|
-
const rawResult = yield* store.find(id)
|
|
364
|
-
|
|
365
|
-
if (Option.isNone(rawResult)) continue
|
|
366
|
-
|
|
367
|
-
const rawData = rawResult.value as Encoded
|
|
368
|
-
const jitMResult = mapFrom(rawData) // apply jitM
|
|
369
|
-
|
|
370
|
-
const decodeResult = yield* S.decodeEffect(schema)(jitMResult).pipe(
|
|
371
|
-
Effect.result,
|
|
372
|
-
provideRctx
|
|
373
|
-
)
|
|
374
|
-
|
|
375
|
-
if (Result.isFailure(decodeResult)) {
|
|
376
|
-
errors.push(
|
|
377
|
-
new ValidationError({
|
|
378
|
-
id,
|
|
379
|
-
rawData,
|
|
380
|
-
jitMResult,
|
|
381
|
-
error: decodeResult.failure
|
|
382
|
-
})
|
|
383
|
-
)
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return new ValidationResult({
|
|
388
|
-
total: NonNegativeInt(allIds.length),
|
|
389
|
-
sampled: NonNegativeInt(sample.length),
|
|
390
|
-
valid: NonNegativeInt(sample.length - errors.length),
|
|
391
|
-
errors
|
|
392
|
-
})
|
|
393
|
-
})
|
|
394
|
-
|
|
395
|
-
const r = {
|
|
396
|
-
changeFeed,
|
|
397
|
-
itemType: name,
|
|
398
|
-
idKey,
|
|
399
|
-
find,
|
|
400
|
-
all,
|
|
401
|
-
saveAndPublish,
|
|
402
|
-
removeAndPublish,
|
|
403
|
-
removeById,
|
|
404
|
-
validateSample,
|
|
405
|
-
queryRaw<A, Out, QR>(schema: S.Codec<A, Out, QR>, q: Q.RawQuery<Encoded, Out>) {
|
|
406
|
-
const dec = S.decodeEffect(S.Array(schema))
|
|
407
|
-
return store.queryRaw(q).pipe(Effect.flatMap(dec))
|
|
408
|
-
},
|
|
409
|
-
query(q: any) {
|
|
410
|
-
// eslint-disable-next-line prefer-rest-params
|
|
411
|
-
return query(typeof q === "function" ? Pipeable.pipeArguments(Q.make(), arguments) : q) as any
|
|
412
|
-
},
|
|
413
|
-
/**
|
|
414
|
-
* @internal
|
|
415
|
-
*/
|
|
416
|
-
mapped: <A, R>(schema: S.Codec<A, any, R>) => {
|
|
417
|
-
const dec = S.decodeEffect(schema)
|
|
418
|
-
const encMany = S.encodeEffect(S.Array(schema))
|
|
419
|
-
const decMany = S.decodeEffect(S.Array(schema))
|
|
420
|
-
return {
|
|
421
|
-
all: allE.pipe(
|
|
422
|
-
Effect.flatMap(decMany),
|
|
423
|
-
Effect.map((_) => _ as any[])
|
|
424
|
-
),
|
|
425
|
-
find: (id: T[IdKey]) => flatMapOption(findE(id), dec),
|
|
426
|
-
// query: (q: any) => {
|
|
427
|
-
// const a = Q.toFilter(q)
|
|
428
|
-
|
|
429
|
-
// return filter(a)
|
|
430
|
-
// .pipe(
|
|
431
|
-
// Effect.flatMap(decMany),
|
|
432
|
-
// Effect.map((_) => _ as any[]),
|
|
433
|
-
// Effect.withSpan("Repository.mapped.query [effect-app/infra]", {
|
|
434
|
-
// captureStackTrace: false,
|
|
435
|
-
// attributes: {
|
|
436
|
-
// "repository.model_name": name,
|
|
437
|
-
// query: { ...a, schema: a.schema ? "__SCHEMA__" : a.schema, filter: a.filter.build() }
|
|
438
|
-
// }
|
|
439
|
-
// })
|
|
440
|
-
// )
|
|
441
|
-
// },
|
|
442
|
-
save: (...xes: any[]) =>
|
|
443
|
-
Effect.flatMap(encMany(xes), (_) => saveAllE(_)).pipe(
|
|
444
|
-
Effect.withSpan("mapped.save", {}, { captureStackTrace: false })
|
|
445
|
-
)
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return r as Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<R, RCtx>, RPublish>
|
|
450
|
-
})
|
|
451
|
-
.pipe(Effect
|
|
452
|
-
// .withSpan("Repository.make [effect-app/infra]", { attributes: { "repository.model_name": name } })
|
|
453
|
-
.withLogSpan("Repository.make: " + name))
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return {
|
|
457
|
-
make,
|
|
458
|
-
Q: Q.make<Encoded>()
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
const pluralize = (s: string) =>
|
|
464
|
-
s.endsWith("s")
|
|
465
|
-
? s + "es"
|
|
466
|
-
: s.endsWith("y")
|
|
467
|
-
? s.substring(0, s.length - 1) + "ies"
|
|
468
|
-
: s + "s"
|
|
469
|
-
|
|
470
|
-
export function makeStore<Encoded extends FieldValues>() {
|
|
471
|
-
return <
|
|
472
|
-
ItemType extends string,
|
|
473
|
-
R,
|
|
474
|
-
E,
|
|
475
|
-
T,
|
|
476
|
-
IdKey extends keyof Encoded
|
|
477
|
-
>(
|
|
478
|
-
name: ItemType,
|
|
479
|
-
schema: S.Codec<T, E, R>,
|
|
480
|
-
mapTo: (e: E, etag: string | undefined) => Encoded,
|
|
481
|
-
idKey: IdKey
|
|
482
|
-
) => {
|
|
483
|
-
function makeStore<RInitial = never, EInitial = never>(
|
|
484
|
-
makeInitial?: Effect.Effect<readonly T[], EInitial, RInitial>,
|
|
485
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
486
|
-
partitionValue?: (e?: Encoded) => string
|
|
487
|
-
}
|
|
488
|
-
) {
|
|
489
|
-
function encodeToEncoded() {
|
|
490
|
-
const getEtag = () => undefined
|
|
491
|
-
return (t: T) =>
|
|
492
|
-
S.encodeEffect(schema)(t).pipe(
|
|
493
|
-
Effect.orDie,
|
|
494
|
-
Effect.map((_) => mapToPersistenceModel(_, getEtag))
|
|
495
|
-
)
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
function mapToPersistenceModel(
|
|
499
|
-
e: E,
|
|
500
|
-
getEtag: (id: string) => string | undefined
|
|
501
|
-
): Encoded {
|
|
502
|
-
return mapTo(e, getEtag((e as any)[idKey] as string))
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
return Effect.gen(function*() {
|
|
506
|
-
const { make } = yield* StoreMaker
|
|
507
|
-
|
|
508
|
-
const store = yield* make<IdKey, Encoded, RInitial | R, EInitial>(
|
|
509
|
-
pluralize(name),
|
|
510
|
-
idKey,
|
|
511
|
-
makeInitial
|
|
512
|
-
? makeInitial
|
|
513
|
-
.pipe(
|
|
514
|
-
Effect.flatMap(Effect.forEach(encodeToEncoded())),
|
|
515
|
-
setupRequestContextFromCurrent("Repository.makeInitial [effect-app/infra]", {
|
|
516
|
-
attributes: { "repository.model_name": name }
|
|
517
|
-
})
|
|
518
|
-
)
|
|
519
|
-
: undefined,
|
|
520
|
-
{
|
|
521
|
-
...config,
|
|
522
|
-
partitionValue: config?.partitionValue
|
|
523
|
-
?? ((_) => "primary") /*(isIntegrationEvent(r) ? r.companyId : r.id*/
|
|
524
|
-
}
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
return store
|
|
528
|
-
})
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
return makeStore
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
export interface Repos<
|
|
536
|
-
T,
|
|
537
|
-
Encoded extends { id: string },
|
|
538
|
-
RSchema,
|
|
539
|
-
Evt,
|
|
540
|
-
ItemType extends string,
|
|
541
|
-
IdKey extends keyof T,
|
|
542
|
-
RPublish
|
|
543
|
-
> {
|
|
544
|
-
make<RInitial = never, E = never, R2 = never>(
|
|
545
|
-
args: [Evt] extends [never] ? {
|
|
546
|
-
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
547
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
548
|
-
partitionValue?: (e?: Encoded) => string
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
: {
|
|
552
|
-
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, R2>
|
|
553
|
-
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
554
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
555
|
-
partitionValue?: (e?: Encoded) => string
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
): Effect.Effect<Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish>, E, StoreMaker | RInitial | R2>
|
|
559
|
-
makeWith<Out, RInitial = never, E = never, R2 = never>(
|
|
560
|
-
args: [Evt] extends [never] ? {
|
|
561
|
-
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
562
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
563
|
-
partitionValue?: (e?: Encoded) => string
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
: {
|
|
567
|
-
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, R2>
|
|
568
|
-
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
569
|
-
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
570
|
-
partitionValue?: (e?: Encoded) => string
|
|
571
|
-
}
|
|
572
|
-
},
|
|
573
|
-
f: (r: Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish>) => Out
|
|
574
|
-
): Effect.Effect<Out, E, StoreMaker | RInitial | R2>
|
|
575
|
-
readonly Q: ReturnType<typeof Q.make<Encoded>>
|
|
576
|
-
readonly type: Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish>
|
|
577
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
import type { Effect, Option, S } from "effect-app"
|
|
4
|
-
import type { OptimisticConcurrencyException } from "effect-app/client/errors"
|
|
5
|
-
|
|
6
|
-
export interface Mapped1<A, IdKey extends keyof A, R> {
|
|
7
|
-
all: Effect.Effect<A[], S.SchemaError, R>
|
|
8
|
-
save: (...xes: readonly A[]) => Effect.Effect<void, OptimisticConcurrencyException | S.SchemaError, R>
|
|
9
|
-
find: (id: A[IdKey]) => Effect.Effect<Option.Option<A>, S.SchemaError, R>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// TODO: auto use project, and select fields from the From side of schema only
|
|
13
|
-
export interface Mapped2<A, R> {
|
|
14
|
-
all: Effect.Effect<A[], S.SchemaError, R>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface Mapped<Encoded> {
|
|
18
|
-
<A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Mapped1<A, IdKey, R>
|
|
19
|
-
// TODO: constrain on Encoded2 having to contain only fields that fit Encoded
|
|
20
|
-
<A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Mapped2<A, R>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface MM<Repo, Encoded> {
|
|
24
|
-
<A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Effect.Effect<Mapped1<A, IdKey, R>, never, Repo>
|
|
25
|
-
// TODO: constrain on Encoded2 having to contain only fields that fit Encoded
|
|
26
|
-
<A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Effect.Effect<Mapped2<A, R>, never, Repo>
|
|
27
|
-
}
|