@effect-app/infra 4.0.0-beta.25 → 4.0.0-beta.250
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 +1892 -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/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 +345 -246
- package/dist/Store/Disk.d.ts +5 -5
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +77 -37
- package/dist/Store/Memory.d.ts +9 -6
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +328 -63
- 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 +233 -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 +450 -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/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 +46 -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 +4 -4
- 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/setupRequest.d.ts +19 -0
- package/dist/setupRequest.d.ts.map +1 -0
- package/dist/setupRequest.js +70 -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/examples/query.ts +47 -39
- package/package.json +123 -234
- package/src/CUPS.ts +52 -13
- 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 +494 -353
- package/src/Store/Disk.ts +108 -68
- package/src/Store/Memory.ts +367 -93
- package/src/Store/SQL/Pg.ts +364 -0
- package/src/Store/SQL/query.ts +603 -0
- package/src/Store/SQL.ts +736 -0
- package/src/Store/codeFilter.ts +8 -5
- package/src/Store/index.ts +21 -6
- package/src/Store/utils.ts +26 -24
- 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/internal/RequestContextMiddleware.ts +60 -0
- 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 +4 -3
- 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/setupRequest.ts +135 -0
- package/src/test.ts +2 -2
- package/test/auth.test.ts +101 -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/auth.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/fixtures.ts +16 -9
- package/test/layerUtils.test.ts +2 -2
- package/test/query.test.ts +903 -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 +19 -14
- 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/RequestContextMiddleware.ts +0 -42
- 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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { type MakeContext, type MakeErrors, makeRouter } from "@effect-app/infra/routing"
|
|
2
|
+
import { expectTypeOf, it } from "@effect/vitest"
|
|
3
|
+
import { InvalidStateError, makeRpcClient, UnauthorizedError } from "effect-app/client"
|
|
4
|
+
import * as Context from "effect-app/Context"
|
|
5
|
+
import * as Effect from "effect-app/Effect"
|
|
6
|
+
import * as Layer from "effect-app/Layer"
|
|
7
|
+
import { DefaultGenericMiddlewares } from "effect-app/middleware"
|
|
8
|
+
import { makeAllDSL, makeOneDSL } from "effect-app/Model"
|
|
9
|
+
import { type FixEnv } from "effect-app/Pure"
|
|
10
|
+
import * as RpcX from "effect-app/rpc"
|
|
11
|
+
import { MiddlewareMaker } from "effect-app/rpc"
|
|
12
|
+
import * as S from "effect-app/Schema"
|
|
13
|
+
import { type TypeTestId } from "effect-app/TypeTest"
|
|
14
|
+
import { type ConfigError } from "effect/Config"
|
|
15
|
+
import { type RpcSerialization } from "effect/unstable/rpc/RpcSerialization"
|
|
16
|
+
import { DefaultGenericMiddlewaresLive, DevModeMiddlewareLive } from "../src/routing/middleware.js"
|
|
17
|
+
import { AllowAnonymous, AllowAnonymousLive, RequestContextMap, RequireRoles, RequireRolesLive, Some, SomeElse, SomeService, Test, TestLive } from "./fixtures.js"
|
|
18
|
+
|
|
19
|
+
// Inline minimal context provider (provides `Some`)
|
|
20
|
+
class CtxProvider extends RpcX.RpcMiddleware.Tag<CtxProvider, { provides: Some }>()("CtxProvider") {
|
|
21
|
+
static Default = Layer.make(this, {
|
|
22
|
+
*make() {
|
|
23
|
+
return Effect.fnUntraced(function*(effect) {
|
|
24
|
+
return yield* Effect.provideService(effect, Some, Some.of({ a: 1 }))
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Provides `SomeElse` so AllowAnonymous's requirement is met.
|
|
31
|
+
class SomeElseProvider extends RpcX.RpcMiddleware.Tag<SomeElseProvider, { provides: SomeElse }>()("SomeElseProvider") {
|
|
32
|
+
static Default = Layer.make(this, {
|
|
33
|
+
*make() {
|
|
34
|
+
return Effect.fnUntraced(function*(effect) {
|
|
35
|
+
return yield* Effect.provideService(effect, SomeElse, SomeElse.of({ b: 2 }))
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class mw extends MiddlewareMaker
|
|
42
|
+
.Tag<mw>()("mw", RequestContextMap)
|
|
43
|
+
.middleware(RequireRoles, Test)
|
|
44
|
+
.middleware(AllowAnonymous)
|
|
45
|
+
.middleware(CtxProvider)
|
|
46
|
+
.middleware(...DefaultGenericMiddlewares, SomeElseProvider)
|
|
47
|
+
{
|
|
48
|
+
static Default = this.layer.pipe(
|
|
49
|
+
Layer.provide([
|
|
50
|
+
RequireRolesLive,
|
|
51
|
+
TestLive,
|
|
52
|
+
AllowAnonymousLive,
|
|
53
|
+
CtxProvider.Default,
|
|
54
|
+
SomeElseProvider.Default,
|
|
55
|
+
DefaultGenericMiddlewaresLive,
|
|
56
|
+
DevModeMiddlewareLive,
|
|
57
|
+
SomeService.Default
|
|
58
|
+
])
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { TaggedRequestFor } = makeRpcClient(mw)
|
|
63
|
+
const Req = TaggedRequestFor("GenRouter")
|
|
64
|
+
|
|
65
|
+
class GetThing extends Req.Query<GetThing>()("GetThing", { id: S.String }, {
|
|
66
|
+
success: S.String,
|
|
67
|
+
error: UnauthorizedError
|
|
68
|
+
}) {}
|
|
69
|
+
class DoThing extends Req.Command<DoThing>()("DoThing", { id: S.String }, { success: S.Void }) {}
|
|
70
|
+
|
|
71
|
+
const Resource = { GetThing, DoThing }
|
|
72
|
+
|
|
73
|
+
const { Router, matchAll } = makeRouter(mw.Default)
|
|
74
|
+
|
|
75
|
+
class ThingRepo extends Context.Service<ThingRepo>()("ThingRepo", {
|
|
76
|
+
make: Effect.succeed({ get: (id: string) => Effect.succeed(id + "!") })
|
|
77
|
+
}) {
|
|
78
|
+
static Default = Layer.effect(this, this.make)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Case under test:
|
|
82
|
+
// `match({})` is given handlers as **shorthand generator methods** (`*GetThing(req) { ... }`).
|
|
83
|
+
// tsgo (>= 7 dev) infers `TNext = unknown` for these shorthand generators while TS6 infers `never`.
|
|
84
|
+
// `HandlerWithInputGen` in routing.ts must accept both — see the structural fix.
|
|
85
|
+
const router = Router(Resource)({
|
|
86
|
+
dependencies: [ThingRepo.Default],
|
|
87
|
+
*effect(match) {
|
|
88
|
+
const repo = yield* ThingRepo
|
|
89
|
+
|
|
90
|
+
if (Math.random() > 0.5) return yield* new InvalidStateError("nope")
|
|
91
|
+
|
|
92
|
+
return match({
|
|
93
|
+
*GetThing(req) {
|
|
94
|
+
const some = yield* Some
|
|
95
|
+
if (req.id === "boom") {
|
|
96
|
+
return yield* Effect.fail(new UnauthorizedError())
|
|
97
|
+
}
|
|
98
|
+
return yield* repo.get(req.id + String(some.a))
|
|
99
|
+
},
|
|
100
|
+
*DoThing(_req) {
|
|
101
|
+
yield* Effect.succeed(1)
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
// Same scenario but using the `raw:` variant — exercises the `raw` path of `HandlerWithInputGen`.
|
|
108
|
+
const routerRaw = Router({ GetThing })({
|
|
109
|
+
*effect(match) {
|
|
110
|
+
return match({
|
|
111
|
+
GetThing: {
|
|
112
|
+
*raw(req) {
|
|
113
|
+
const some = yield* Some
|
|
114
|
+
return yield* Effect.succeed(req.id + String(some.a))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("router with generator-method handlers compiles", () => {
|
|
122
|
+
expectTypeOf(router).toMatchTypeOf<
|
|
123
|
+
Layer.Layer<never, ConfigError | InvalidStateError, SomeService | RpcSerialization>
|
|
124
|
+
>()
|
|
125
|
+
expectTypeOf(routerRaw).toMatchTypeOf<Layer.Layer<never, ConfigError, SomeService | RpcSerialization>>()
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// Type-level assertions: verify generator yields propagate to MakeErrors / MakeContext
|
|
129
|
+
type Errors = MakeErrors<typeof router[TypeTestId]>
|
|
130
|
+
type Ctx = MakeContext<typeof router[TypeTestId]>
|
|
131
|
+
expectTypeOf<Errors>().toEqualTypeOf<InvalidStateError>()
|
|
132
|
+
expectTypeOf<Ctx>().toEqualTypeOf<ThingRepo>()
|
|
133
|
+
|
|
134
|
+
const matched = matchAll({ router })
|
|
135
|
+
expectTypeOf(matched).toMatchTypeOf<
|
|
136
|
+
Layer.Layer<never, ConfigError | InvalidStateError, SomeService | RpcSerialization>
|
|
137
|
+
>()
|
|
138
|
+
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// DSL R-inference regression
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// `OneDSL`/`OneDSLExt.update`/`.modify` previously annotated the callback's
|
|
143
|
+
// effect R as `FixEnv<R, Evt, S1, S2>`. That deadlocked inference of `R`
|
|
144
|
+
// (TS6 → `never`, tsgo → `unknown`), causing yielded effects to leak
|
|
145
|
+
// `unknown` in the R slot when consumed by generator handlers.
|
|
146
|
+
// The fix uses bare `R` in the callback and `FixEnv<R, …>` only on the return.
|
|
147
|
+
class Item extends S.Class<Item>("Item")({ id: S.String, label: S.String }) {}
|
|
148
|
+
class Dep extends Context.Service<Dep>()("Dep", { make: Effect.succeed({ tag: "dep" as const }) }) {}
|
|
149
|
+
|
|
150
|
+
type Evt = { _tag: "Updated"; id: string }
|
|
151
|
+
|
|
152
|
+
const Items$ = makeAllDSL<Item, Evt>()
|
|
153
|
+
const Item$ = makeOneDSL<Item, Evt>()
|
|
154
|
+
|
|
155
|
+
// Callback body uses generator syntax (TNext = unknown under tsgo) and yields
|
|
156
|
+
// a service-dependent effect — R must be inferred as `Dep` (plus the
|
|
157
|
+
// canonical PureEnvEnv contributed by FixEnv on the return).
|
|
158
|
+
const oneUpdate = Item$.update((item) =>
|
|
159
|
+
Effect.gen(function*() {
|
|
160
|
+
const dep = yield* Dep
|
|
161
|
+
return new Item({ id: item.id, label: item.label + dep.tag })
|
|
162
|
+
})
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
const allUpdate = Items$.update((items) =>
|
|
166
|
+
Effect.gen(function*() {
|
|
167
|
+
const dep = yield* Dep
|
|
168
|
+
return items.map((_) => new Item({ id: _.id, label: _.label + dep.tag }))
|
|
169
|
+
})
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
const oneModify = Item$.modify((item, _dsl) =>
|
|
173
|
+
Effect.gen(function*() {
|
|
174
|
+
const dep = yield* Dep
|
|
175
|
+
return { ...item, tag: dep.tag }
|
|
176
|
+
})
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
// `R` should be `FixEnv<Dep, Evt, …>` — never collapsed to `unknown`/`never`.
|
|
180
|
+
// The regression manifested as `unknown` here, breaking `Dep` assignability.
|
|
181
|
+
expectTypeOf(oneUpdate).toMatchTypeOf<Effect.Effect<Item, never, FixEnv<Dep, Evt, Item, Item>>>()
|
|
182
|
+
expectTypeOf(allUpdate).toMatchTypeOf<
|
|
183
|
+
Effect.Effect<readonly Item[], never, FixEnv<Dep, Evt, readonly Item[], readonly Item[]>>
|
|
184
|
+
>()
|
|
185
|
+
expectTypeOf(oneModify).toMatchTypeOf<
|
|
186
|
+
Effect.Effect<{ tag: "dep"; id: string; label: string }, never, FixEnv<Dep, Evt, Item, Item>>
|
|
187
|
+
>()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
+
import { ConfigureInterruptibilityMiddleware } from "effect-app/middleware"
|
|
3
|
+
import * as S from "effect-app/Schema"
|
|
4
|
+
import * as Effect from "effect/Effect"
|
|
5
|
+
import * as Fiber from "effect/Fiber"
|
|
6
|
+
import * as Layer from "effect/Layer"
|
|
7
|
+
import * as Ref from "effect/Ref"
|
|
8
|
+
import { Rpc, RpcGroup, RpcTest } from "effect/unstable/rpc"
|
|
9
|
+
import { applyRequestTypeInterruptibility } from "../src/routing.js"
|
|
10
|
+
import { ConfigureInterruptibilityMiddlewareLive, RequestType } from "../src/routing/middleware.js"
|
|
11
|
+
|
|
12
|
+
const InterruptibilityRpcs = RpcGroup.make(
|
|
13
|
+
Rpc
|
|
14
|
+
.make("doCommand", { success: S.Void })
|
|
15
|
+
.annotate(RequestType, "command")
|
|
16
|
+
.middleware(ConfigureInterruptibilityMiddleware),
|
|
17
|
+
Rpc
|
|
18
|
+
.make("doQuery", { success: S.Void })
|
|
19
|
+
.annotate(RequestType, "query")
|
|
20
|
+
.middleware(ConfigureInterruptibilityMiddleware)
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const makeImplLayer = (commandDone: Ref.Ref<boolean>, queryDone: Ref.Ref<boolean>) =>
|
|
24
|
+
InterruptibilityRpcs.toLayer({
|
|
25
|
+
doCommand: () =>
|
|
26
|
+
applyRequestTypeInterruptibility(
|
|
27
|
+
"command",
|
|
28
|
+
Effect.sleep("120 millis").pipe(Effect.andThen(Ref.set(commandDone, true)))
|
|
29
|
+
),
|
|
30
|
+
doQuery: () =>
|
|
31
|
+
applyRequestTypeInterruptibility(
|
|
32
|
+
"query",
|
|
33
|
+
Effect.sleep("120 millis").pipe(Effect.andThen(Ref.set(queryDone, true)))
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe("routing interruptibility", () => {
|
|
38
|
+
it.live(
|
|
39
|
+
"e2e: command continues after client interrupt, query does not",
|
|
40
|
+
() =>
|
|
41
|
+
Effect.gen(function*() {
|
|
42
|
+
const commandDone = yield* Ref.make(false)
|
|
43
|
+
const queryDone = yield* Ref.make(false)
|
|
44
|
+
|
|
45
|
+
const client = yield* RpcTest
|
|
46
|
+
.makeClient(InterruptibilityRpcs)
|
|
47
|
+
.pipe(
|
|
48
|
+
Effect.provide(
|
|
49
|
+
Layer.mergeAll(makeImplLayer(commandDone, queryDone), ConfigureInterruptibilityMiddlewareLive)
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const commandFiber = yield* Effect.forkDetach(client.doCommand())
|
|
54
|
+
yield* Effect.sleep("20 millis")
|
|
55
|
+
yield* Fiber.interrupt(commandFiber)
|
|
56
|
+
yield* Effect.sleep("180 millis")
|
|
57
|
+
expect(yield* Ref.get(commandDone)).toBe(true)
|
|
58
|
+
|
|
59
|
+
const queryFiber = yield* Effect.forkDetach(client.doQuery())
|
|
60
|
+
yield* Effect.sleep("20 millis")
|
|
61
|
+
yield* Fiber.interrupt(queryFiber)
|
|
62
|
+
yield* Effect.sleep("180 millis")
|
|
63
|
+
expect(yield* Ref.get(queryDone)).toBe(false)
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
})
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2E test for commit bb3f51d03 — `fix(infra): bind ContextMap to request scope
|
|
3
|
+
* for SSE streams`.
|
|
4
|
+
*
|
|
5
|
+
* Background
|
|
6
|
+
* ----------
|
|
7
|
+
* The RpcServer returns `HttpServerResponse.stream(...)` for streaming RPC
|
|
8
|
+
* resources. The body of that response keeps producing chunks AFTER the
|
|
9
|
+
* outer Effect that built the response has returned. `RequestContextMiddleware`
|
|
10
|
+
* provisions `ContextMapContainer` for the request. The acquireRelease
|
|
11
|
+
* inside `ContextMapContainer.layer` calls `clear()` on finalize, wiping
|
|
12
|
+
* the etag map and the per-request resolver/store cache.
|
|
13
|
+
*
|
|
14
|
+
* If that layer is built against a sub-scope of the outer Effect (the
|
|
15
|
+
* pre-fix behaviour: `Effect.provide(layer)`), the finalizer fires as soon
|
|
16
|
+
* as the middleware Effect returns the HttpServerResponse — i.e. between
|
|
17
|
+
* "handler done" and "first chunk written" — wiping ContextMap state that
|
|
18
|
+
* later chunks still need. In production this surfaces as spurious
|
|
19
|
+
* OptimisticConcurrencyException on writes that follow a streaming read.
|
|
20
|
+
*
|
|
21
|
+
* The fix binds the layer to the ambient request scope via
|
|
22
|
+
* `provideOnRequestScope`, so `clear()` only runs once the response body
|
|
23
|
+
* has fully drained.
|
|
24
|
+
*
|
|
25
|
+
* Reproduction strategy
|
|
26
|
+
* ---------------------
|
|
27
|
+
* - Mirror the production wiring: apply `RequestContextMiddleware` to the
|
|
28
|
+
* RPC router (see `boilerplate/api/src/router.ts`).
|
|
29
|
+
* - The stream handler sets an etag on the ContextMap BEFORE returning the
|
|
30
|
+
* Stream value.
|
|
31
|
+
* - The Stream emits three values 100ms apart; each emission reads back the
|
|
32
|
+
* etag via `getContextMap` and yields 1 if the value is still present,
|
|
33
|
+
* 0 otherwise.
|
|
34
|
+
* - Expectation: [1, 1, 1]. If the layer's `clear()` runs mid-stream the
|
|
35
|
+
* later chunks observe an empty map and the assertion fails (typically
|
|
36
|
+
* with [1, 0, 0] or [0, 0, 0]).
|
|
37
|
+
*/
|
|
38
|
+
import { NodeHttpServer } from "@effect/platform-node"
|
|
39
|
+
import { expect, it } from "@effect/vitest"
|
|
40
|
+
import { ApiClientFactory, makeRpcClient } from "effect-app/client"
|
|
41
|
+
import { HttpRouter, HttpServer } from "effect-app/http"
|
|
42
|
+
import { DefaultGenericMiddlewares } from "effect-app/middleware"
|
|
43
|
+
import { MiddlewareMaker } from "effect-app/rpc"
|
|
44
|
+
import * as S from "effect-app/Schema"
|
|
45
|
+
import { getContextMap } from "effect-app/Store"
|
|
46
|
+
import * as Effect from "effect/Effect"
|
|
47
|
+
import * as Layer from "effect/Layer"
|
|
48
|
+
import * as Option from "effect/Option"
|
|
49
|
+
import * as Stream from "effect/Stream"
|
|
50
|
+
import { FetchHttpClient } from "effect/unstable/http"
|
|
51
|
+
import { RpcSerialization } from "effect/unstable/rpc"
|
|
52
|
+
import { createServer } from "http"
|
|
53
|
+
import { RequestContextMiddleware } from "../src/internal/RequestContextMiddleware.js"
|
|
54
|
+
import { makeRouter } from "../src/routing.js"
|
|
55
|
+
import { DefaultGenericMiddlewaresLive } from "../src/routing/middleware.js"
|
|
56
|
+
import { AllowAnonymous, AllowAnonymousLive, RequestContextMap, RequireRoles, RequireRolesLive, SomeElseMiddleware, SomeElseMiddlewareLive, SomeService, Test, TestLive } from "./fixtures.js"
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Middleware — mirrors AppMiddleware shape used by the other rpc e2e tests.
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
class AppMiddleware extends MiddlewareMaker
|
|
63
|
+
.Tag<AppMiddleware>()("AppMiddleware", RequestContextMap)
|
|
64
|
+
.middleware(RequireRoles, Test)
|
|
65
|
+
.middleware(AllowAnonymous)
|
|
66
|
+
.middleware(SomeElseMiddleware)
|
|
67
|
+
.middleware(...DefaultGenericMiddlewares)
|
|
68
|
+
{
|
|
69
|
+
static Default = this.layer.pipe(
|
|
70
|
+
Layer.provide(
|
|
71
|
+
[
|
|
72
|
+
RequireRolesLive.pipe(Layer.provide(SomeService.Default)),
|
|
73
|
+
AllowAnonymousLive,
|
|
74
|
+
TestLive,
|
|
75
|
+
SomeElseMiddlewareLive,
|
|
76
|
+
DefaultGenericMiddlewaresLive
|
|
77
|
+
] as const
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { Router, matchAll } = makeRouter(AppMiddleware.Default)
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Resource — single streaming command that exercises ContextMap mid-stream.
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
const { TaggedRequestFor } = makeRpcClient(AppMiddleware)
|
|
89
|
+
const Req = TaggedRequestFor("CtxMap")
|
|
90
|
+
|
|
91
|
+
class StreamEtag extends Req.Command<StreamEtag>()("StreamEtag", {}, {
|
|
92
|
+
stream: true,
|
|
93
|
+
allowAnonymous: true,
|
|
94
|
+
success: S.Number
|
|
95
|
+
}) {}
|
|
96
|
+
|
|
97
|
+
// Per-request isolation probes: each handler writes a caller-supplied value to
|
|
98
|
+
// the SHARED key, then emits 3 chunks each re-reading the SHARED key. If two
|
|
99
|
+
// concurrent requests share a ContextMap, the second writer overwrites the
|
|
100
|
+
// first and the first request observes the wrong value mid-stream.
|
|
101
|
+
class StreamWithEtag extends Req.Command<StreamWithEtag>()("StreamWithEtag", {
|
|
102
|
+
value: S.String
|
|
103
|
+
}, {
|
|
104
|
+
stream: true,
|
|
105
|
+
allowAnonymous: true,
|
|
106
|
+
success: S.String
|
|
107
|
+
}) {}
|
|
108
|
+
|
|
109
|
+
class ReadEtagOnce extends Req.Query<ReadEtagOnce>()("ReadEtagOnce", {}, {
|
|
110
|
+
allowAnonymous: true,
|
|
111
|
+
success: S.String
|
|
112
|
+
}) {}
|
|
113
|
+
|
|
114
|
+
const Rsc = { StreamEtag, StreamWithEtag, ReadEtagOnce }
|
|
115
|
+
|
|
116
|
+
// Distinct constants so an assertion failure points squarely at "the etag
|
|
117
|
+
// the handler wrote was no longer there when later chunks ran".
|
|
118
|
+
const ETAG_ID = "ctxmap-test-id"
|
|
119
|
+
const ETAG_VALUE = "v1"
|
|
120
|
+
const SHARED_KEY = "ctxmap-shared-key"
|
|
121
|
+
const MISSING = "<missing>"
|
|
122
|
+
|
|
123
|
+
const router = Router(Rsc)({
|
|
124
|
+
*effect(match) {
|
|
125
|
+
return match({
|
|
126
|
+
StreamEtag: () =>
|
|
127
|
+
Effect
|
|
128
|
+
.gen(function*() {
|
|
129
|
+
// 1) Acquire the request-scoped ContextMap. Fails (dies) if the
|
|
130
|
+
// container is still the default "root" — which would mean
|
|
131
|
+
// RequestContextMiddleware did not run for this request.
|
|
132
|
+
const ctxMap = yield* getContextMap.pipe(Effect.orDie)
|
|
133
|
+
// 2) Seed an etag BEFORE handing back the Stream. This write is
|
|
134
|
+
// what the per-chunk readers below verify.
|
|
135
|
+
ctxMap.set(ETAG_ID, ETAG_VALUE)
|
|
136
|
+
// 3) Emit three values 100ms apart so chunks are produced AFTER
|
|
137
|
+
// the outer Effect that built the response has returned. Each
|
|
138
|
+
// emission re-reads the etag from the request-scoped ContextMap.
|
|
139
|
+
return Stream.fromIterable([0, 1, 2]).pipe(
|
|
140
|
+
Stream.mapEffect(() =>
|
|
141
|
+
Effect.sleep("100 millis").pipe(
|
|
142
|
+
Effect.flatMap(() => getContextMap.pipe(Effect.orDie)),
|
|
143
|
+
Effect.map((m) => m.get(ETAG_ID) === ETAG_VALUE ? 1 : 0)
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
})
|
|
148
|
+
.pipe(Stream.unwrap),
|
|
149
|
+
StreamWithEtag: ({ value }: { readonly value: string }) =>
|
|
150
|
+
Effect
|
|
151
|
+
.gen(function*() {
|
|
152
|
+
const ctxMap = yield* getContextMap.pipe(Effect.orDie)
|
|
153
|
+
ctxMap.set(SHARED_KEY, value)
|
|
154
|
+
return Stream.fromIterable([0, 1, 2]).pipe(
|
|
155
|
+
Stream.mapEffect(() =>
|
|
156
|
+
Effect.sleep("100 millis").pipe(
|
|
157
|
+
Effect.flatMap(() => getContextMap.pipe(Effect.orDie)),
|
|
158
|
+
Effect.map((m) => m.get(SHARED_KEY) ?? MISSING)
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
})
|
|
163
|
+
.pipe(Stream.unwrap),
|
|
164
|
+
ReadEtagOnce: () => getContextMap.pipe(Effect.orDie, Effect.map((m) => m.get(SHARED_KEY) ?? MISSING))
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const RpcRouterLayer = matchAll({ router })
|
|
170
|
+
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// HTTP wiring — fresh server on a loopback port per `it.live`. The critical
|
|
173
|
+
// difference vs. rpc-stream-fullstack: we apply `RequestContextMiddleware`
|
|
174
|
+
// here, exactly as the production boilerplate does, so the fix code path
|
|
175
|
+
// is what runs.
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
const NodeServerLayer = NodeHttpServer.layer(() => createServer(), { port: 0 })
|
|
179
|
+
|
|
180
|
+
const RequestContextMiddlewareLayer = HttpRouter.middleware(RequestContextMiddleware()).layer
|
|
181
|
+
|
|
182
|
+
const ServerLayer = HttpRouter
|
|
183
|
+
.serve(
|
|
184
|
+
RpcRouterLayer.pipe(Layer.provide(RequestContextMiddlewareLayer))
|
|
185
|
+
)
|
|
186
|
+
.pipe(
|
|
187
|
+
Layer.provide(NodeServerLayer),
|
|
188
|
+
Layer.provide(RpcSerialization.layerNdjson)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
const ClientLayer = Layer
|
|
192
|
+
.unwrap(
|
|
193
|
+
Effect.gen(function*() {
|
|
194
|
+
const server = yield* HttpServer.HttpServer
|
|
195
|
+
const addr = server.address
|
|
196
|
+
if (addr._tag !== "TcpAddress") return yield* Effect.die(new Error("expected TcpAddress"))
|
|
197
|
+
const host = addr.hostname === "0.0.0.0" ? "127.0.0.1" : addr.hostname
|
|
198
|
+
const url = `http://${host}:${addr.port}`
|
|
199
|
+
return ApiClientFactory
|
|
200
|
+
.layer({ url, headers: Option.none() })
|
|
201
|
+
.pipe(Layer.provide(FetchHttpClient.layer))
|
|
202
|
+
})
|
|
203
|
+
)
|
|
204
|
+
.pipe(Layer.provide(NodeServerLayer))
|
|
205
|
+
|
|
206
|
+
const TestLayer = Layer.mergeAll(ServerLayer, ClientLayer)
|
|
207
|
+
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// Test
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
it.live(
|
|
213
|
+
"ContextMap survives mid-stream: etag set in handler is readable by every chunk",
|
|
214
|
+
Effect.fnUntraced(function*() {
|
|
215
|
+
const client = yield* ApiClientFactory.makeFor(Layer.empty)(Rsc)
|
|
216
|
+
const values = yield* Stream.runCollect(client.StreamEtag.handler())
|
|
217
|
+
// All three chunks emit 1 → the etag was still readable when each chunk
|
|
218
|
+
// executed. If the layer-bound ContextMap's `clear()` finalizer fired
|
|
219
|
+
// mid-stream (the pre-fix behaviour), later chunks would emit 0.
|
|
220
|
+
expect(values).toStrictEqual([1, 1, 1])
|
|
221
|
+
}, Effect.provide(TestLayer)),
|
|
222
|
+
{ timeout: 10_000 }
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
it.live(
|
|
226
|
+
"succeeding requests get a fresh ContextMap: request N+1 cannot see request N's writes",
|
|
227
|
+
Effect.fnUntraced(function*() {
|
|
228
|
+
const client = yield* ApiClientFactory.makeFor(Layer.empty)(Rsc)
|
|
229
|
+
// 1st request writes SHARED_KEY = "first" and drains its stream so its
|
|
230
|
+
// request scope (and ContextMap) is closed before request 2 starts.
|
|
231
|
+
const first = yield* Stream.runCollect(client.StreamWithEtag.handler({ value: "first" }))
|
|
232
|
+
expect(first).toStrictEqual(["first", "first", "first"])
|
|
233
|
+
// 2nd request must NOT observe the previous request's value at any point.
|
|
234
|
+
const peek = yield* client.ReadEtagOnce.handler()
|
|
235
|
+
expect(peek).toBe(MISSING)
|
|
236
|
+
// 3rd request writes a different value and drains; must not be polluted by request 1.
|
|
237
|
+
const third = yield* Stream.runCollect(client.StreamWithEtag.handler({ value: "third" }))
|
|
238
|
+
expect(third).toStrictEqual(["third", "third", "third"])
|
|
239
|
+
}, Effect.provide(TestLayer)),
|
|
240
|
+
{ timeout: 10_000 }
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
it.live(
|
|
244
|
+
"overlapping requests get isolated ContextMaps: concurrent streams see only their own writes",
|
|
245
|
+
Effect.fnUntraced(function*() {
|
|
246
|
+
const client = yield* ApiClientFactory.makeFor(Layer.empty)(Rsc)
|
|
247
|
+
// Two streams in flight at the same time, each writing the SAME key with a
|
|
248
|
+
// different value. With per-request maps each stream reads back only its
|
|
249
|
+
// own value across all chunks. With a shared map the later writer's value
|
|
250
|
+
// would leak into the earlier stream's later chunks.
|
|
251
|
+
const [a, b] = yield* Effect.all(
|
|
252
|
+
[
|
|
253
|
+
Stream.runCollect(client.StreamWithEtag.handler({ value: "alpha" })),
|
|
254
|
+
Stream.runCollect(client.StreamWithEtag.handler({ value: "beta" }))
|
|
255
|
+
],
|
|
256
|
+
{ concurrency: "unbounded" }
|
|
257
|
+
)
|
|
258
|
+
expect(a).toStrictEqual(["alpha", "alpha", "alpha"])
|
|
259
|
+
expect(b).toStrictEqual(["beta", "beta", "beta"])
|
|
260
|
+
}, Effect.provide(TestLayer)),
|
|
261
|
+
{ timeout: 10_000 }
|
|
262
|
+
)
|