@effect-app/infra 4.0.0-beta.8 → 4.0.0-beta.81

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +527 -0
  2. package/dist/CUPS.d.ts +3 -3
  3. package/dist/CUPS.d.ts.map +1 -1
  4. package/dist/CUPS.js +3 -3
  5. package/dist/Emailer/Sendgrid.js +1 -1
  6. package/dist/Emailer/service.d.ts +3 -3
  7. package/dist/Emailer/service.d.ts.map +1 -1
  8. package/dist/Emailer/service.js +3 -3
  9. package/dist/MainFiberSet.d.ts +2 -2
  10. package/dist/MainFiberSet.d.ts.map +1 -1
  11. package/dist/MainFiberSet.js +3 -3
  12. package/dist/Model/Repository/internal/internal.d.ts +3 -3
  13. package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
  14. package/dist/Model/Repository/internal/internal.js +11 -7
  15. package/dist/Model/Repository/makeRepo.d.ts +2 -2
  16. package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
  17. package/dist/Model/Repository/makeRepo.js +1 -1
  18. package/dist/Model/Repository/validation.d.ts +5 -4
  19. package/dist/Model/Repository/validation.d.ts.map +1 -1
  20. package/dist/Model/query/dsl.d.ts +9 -9
  21. package/dist/Operations.d.ts +2 -2
  22. package/dist/Operations.d.ts.map +1 -1
  23. package/dist/Operations.js +3 -3
  24. package/dist/OperationsRepo.d.ts +2 -2
  25. package/dist/OperationsRepo.d.ts.map +1 -1
  26. package/dist/OperationsRepo.js +3 -3
  27. package/dist/QueueMaker/SQLQueue.d.ts +3 -5
  28. package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
  29. package/dist/QueueMaker/SQLQueue.js +9 -7
  30. package/dist/QueueMaker/errors.d.ts +1 -1
  31. package/dist/QueueMaker/errors.d.ts.map +1 -1
  32. package/dist/QueueMaker/memQueue.d.ts.map +1 -1
  33. package/dist/QueueMaker/memQueue.js +10 -9
  34. package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
  35. package/dist/QueueMaker/sbqueue.js +11 -9
  36. package/dist/RequestContext.d.ts +19 -14
  37. package/dist/RequestContext.d.ts.map +1 -1
  38. package/dist/RequestContext.js +5 -5
  39. package/dist/RequestFiberSet.d.ts +2 -2
  40. package/dist/RequestFiberSet.d.ts.map +1 -1
  41. package/dist/RequestFiberSet.js +5 -5
  42. package/dist/Store/ContextMapContainer.d.ts +14 -3
  43. package/dist/Store/ContextMapContainer.d.ts.map +1 -1
  44. package/dist/Store/ContextMapContainer.js +64 -3
  45. package/dist/Store/Cosmos.js +1 -1
  46. package/dist/Store/Disk.d.ts.map +1 -1
  47. package/dist/Store/Disk.js +3 -4
  48. package/dist/Store/Memory.d.ts +2 -2
  49. package/dist/Store/Memory.d.ts.map +1 -1
  50. package/dist/Store/Memory.js +4 -4
  51. package/dist/Store/service.d.ts +6 -3
  52. package/dist/Store/service.d.ts.map +1 -1
  53. package/dist/Store/service.js +14 -6
  54. package/dist/adapters/SQL/Model.d.ts +2 -5
  55. package/dist/adapters/SQL/Model.d.ts.map +1 -1
  56. package/dist/adapters/SQL/Model.js +21 -13
  57. package/dist/adapters/ServiceBus.d.ts +6 -6
  58. package/dist/adapters/ServiceBus.d.ts.map +1 -1
  59. package/dist/adapters/ServiceBus.js +9 -9
  60. package/dist/adapters/cosmos-client.d.ts +2 -2
  61. package/dist/adapters/cosmos-client.d.ts.map +1 -1
  62. package/dist/adapters/cosmos-client.js +3 -3
  63. package/dist/adapters/logger.d.ts.map +1 -1
  64. package/dist/adapters/memQueue.d.ts +2 -2
  65. package/dist/adapters/memQueue.d.ts.map +1 -1
  66. package/dist/adapters/memQueue.js +3 -3
  67. package/dist/adapters/mongo-client.d.ts +2 -2
  68. package/dist/adapters/mongo-client.d.ts.map +1 -1
  69. package/dist/adapters/mongo-client.js +3 -3
  70. package/dist/adapters/redis-client.d.ts +3 -3
  71. package/dist/adapters/redis-client.d.ts.map +1 -1
  72. package/dist/adapters/redis-client.js +3 -3
  73. package/dist/api/ContextProvider.d.ts +6 -6
  74. package/dist/api/ContextProvider.d.ts.map +1 -1
  75. package/dist/api/ContextProvider.js +6 -6
  76. package/dist/api/internal/RequestContextMiddleware.d.ts +1 -1
  77. package/dist/api/internal/auth.d.ts +1 -1
  78. package/dist/api/internal/events.d.ts +2 -2
  79. package/dist/api/internal/events.d.ts.map +1 -1
  80. package/dist/api/internal/events.js +7 -5
  81. package/dist/api/layerUtils.d.ts +5 -5
  82. package/dist/api/layerUtils.d.ts.map +1 -1
  83. package/dist/api/layerUtils.js +5 -5
  84. package/dist/api/routing/middleware/RouterMiddleware.d.ts +3 -3
  85. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +1 -1
  86. package/dist/api/routing/schema/jwt.d.ts +1 -1
  87. package/dist/api/routing/schema/jwt.d.ts.map +1 -1
  88. package/dist/api/routing/schema/jwt.js +1 -1
  89. package/dist/api/routing.d.ts +1 -5
  90. package/dist/api/routing.d.ts.map +1 -1
  91. package/dist/api/routing.js +3 -2
  92. package/dist/api/setupRequest.js +4 -4
  93. package/dist/errorReporter.d.ts +1 -1
  94. package/dist/errorReporter.d.ts.map +1 -1
  95. package/dist/errorReporter.js +1 -1
  96. package/dist/fileUtil.js +1 -1
  97. package/dist/logger.d.ts.map +1 -1
  98. package/dist/rateLimit.js +1 -1
  99. package/examples/query.ts +29 -25
  100. package/package.json +16 -16
  101. package/src/CUPS.ts +2 -2
  102. package/src/Emailer/Sendgrid.ts +1 -1
  103. package/src/Emailer/service.ts +2 -2
  104. package/src/MainFiberSet.ts +2 -2
  105. package/src/Model/Repository/internal/internal.ts +11 -8
  106. package/src/Model/Repository/makeRepo.ts +2 -2
  107. package/src/Operations.ts +2 -2
  108. package/src/OperationsRepo.ts +2 -2
  109. package/src/QueueMaker/SQLQueue.ts +10 -10
  110. package/src/QueueMaker/memQueue.ts +41 -42
  111. package/src/QueueMaker/sbqueue.ts +65 -62
  112. package/src/RequestContext.ts +4 -4
  113. package/src/RequestFiberSet.ts +4 -4
  114. package/src/Store/ContextMapContainer.ts +98 -2
  115. package/src/Store/Cosmos.ts +10 -10
  116. package/src/Store/Disk.ts +2 -3
  117. package/src/Store/Memory.ts +4 -6
  118. package/src/Store/service.ts +14 -5
  119. package/src/adapters/SQL/Model.ts +76 -71
  120. package/src/adapters/ServiceBus.ts +8 -8
  121. package/src/adapters/cosmos-client.ts +2 -2
  122. package/src/adapters/memQueue.ts +2 -2
  123. package/src/adapters/mongo-client.ts +2 -2
  124. package/src/adapters/redis-client.ts +2 -2
  125. package/src/api/ContextProvider.ts +11 -11
  126. package/src/api/internal/events.ts +7 -6
  127. package/src/api/layerUtils.ts +8 -8
  128. package/src/api/routing/middleware/RouterMiddleware.ts +4 -4
  129. package/src/api/routing/schema/jwt.ts +2 -3
  130. package/src/api/routing.ts +7 -6
  131. package/src/api/setupRequest.ts +3 -3
  132. package/src/errorReporter.ts +1 -1
  133. package/src/fileUtil.ts +1 -1
  134. package/src/rateLimit.ts +2 -2
  135. package/test/contextProvider.test.ts +5 -5
  136. package/test/controller.test.ts +12 -9
  137. package/test/dist/contextProvider.test.d.ts.map +1 -1
  138. package/test/dist/controller.test.d.ts.map +1 -1
  139. package/test/dist/fixtures.d.ts +18 -8
  140. package/test/dist/fixtures.d.ts.map +1 -1
  141. package/test/dist/fixtures.js +11 -9
  142. package/test/dist/query.test.d.ts.map +1 -1
  143. package/test/dist/rawQuery.test.d.ts.map +1 -1
  144. package/test/dist/requires.test.d.ts.map +1 -1
  145. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  146. package/test/fixtures.ts +10 -8
  147. package/test/query.test.ts +160 -14
  148. package/test/rawQuery.test.ts +19 -17
  149. package/test/requires.test.ts +6 -5
  150. package/test/rpc-multi-middleware.test.ts +73 -4
  151. package/test/validateSample.test.ts +1 -1
  152. package/tsconfig.json +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/infra",
3
- "version": "4.0.0-beta.8",
3
+ "version": "4.0.0-beta.81",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -8,46 +8,46 @@
8
8
  "change-case": "^5.4.4",
9
9
  "cross-fetch": "^4.1.0",
10
10
  "express-oauth2-jwt-bearer": "^1.7.4",
11
- "fast-check": "~4.5.3",
11
+ "fast-check": "~4.6.0",
12
12
  "path-parser": "^6.1.0",
13
13
  "proper-lockfile": "^4.1.2",
14
14
  "pure-rand": "7.0.1",
15
15
  "query-string": "^9.3.1",
16
- "effect-app": "4.0.0-beta.7"
16
+ "effect-app": "4.0.0-beta.81"
17
17
  },
18
18
  "devDependencies": {
19
- "@azure/cosmos": "^4.9.1",
19
+ "@azure/cosmos": "^4.9.2",
20
20
  "@azure/service-bus": "^7.9.5",
21
- "@sentry/node": "10.40.0",
22
- "@sentry/opentelemetry": "10.40.0",
21
+ "@sentry/node": "10.47.0",
22
+ "@sentry/opentelemetry": "10.47.0",
23
23
  "@types/express": "^5.0.6",
24
- "@types/node": "25.3.3",
24
+ "@types/node": "25.5.2",
25
25
  "@types/proper-lockfile": "^4.1.4",
26
26
  "@types/redis": "^2.8.32",
27
27
  "@types/redlock": "^4.0.8",
28
28
  "express": "^5.2.1",
29
29
  "jwks-rsa": "2.1.4",
30
30
  "jwt-decode": "^4.0.0",
31
- "mongodb": "7.1.0",
31
+ "mongodb": "7.1.1",
32
32
  "redis": "^3.1.2",
33
33
  "redlock": "^4.2.0",
34
34
  "strip-ansi": "^7.2.0",
35
- "typescript": "~5.9.3",
36
- "vitest": "^4.0.18",
37
- "@effect-app/eslint-shared-config": "0.5.7-beta.1"
35
+ "typescript": "~6.0.2",
36
+ "vitest": "^4.1.3",
37
+ "@effect-app/eslint-shared-config": "0.5.7-beta.9"
38
38
  },
39
39
  "peerDependencies": {
40
- "@azure/cosmos": "^4.9.1",
40
+ "@azure/cosmos": "^4.9.2",
41
41
  "@azure/service-bus": "^7.9.5",
42
- "@effect/vitest": "^4.0.0-beta.25",
42
+ "@effect/vitest": "^4.0.0-beta.47",
43
43
  "@sendgrid/helpers": "^8.0.0",
44
44
  "@sendgrid/mail": "^8.1.6",
45
- "@sentry/node": "10.40.0",
46
- "@sentry/opentelemetry": "10.40.0",
45
+ "@sentry/node": "10.47.0",
46
+ "@sentry/opentelemetry": "10.47.0",
47
47
  "jwt-decode": "^4.0.0",
48
48
  "redis": "^3.1.2",
49
49
  "redlock": "^4.2.0",
50
- "effect": "^4.0.0-beta.25",
50
+ "effect": "^4.0.0-beta.47",
51
51
  "express": "^5.2.1"
52
52
  },
53
53
  "typesVersions": {
package/src/CUPS.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type FileOptions, tempFile } from "@effect-app/infra/fileUtil"
2
2
  import cp from "child_process"
3
- import { Config, Effect, Layer, Option, Predicate, S, ServiceMap } from "effect-app"
3
+ import { Config, Context, Effect, Layer, Option, Predicate, S } from "effect-app"
4
4
  import { pretty } from "effect-app/utils"
5
5
  import fs from "fs"
6
6
  import os from "os"
@@ -100,7 +100,7 @@ export const CUPSConfig = Config.all({
100
100
  )
101
101
  })
102
102
 
103
- export class CUPS extends ServiceMap.Service<CUPS>()("effect-app/CUPS", {
103
+ export class CUPS extends Context.Service<CUPS>()("effect-app/CUPS", {
104
104
  make: Effect.gen(function*() {
105
105
  const config = yield* CUPSConfig
106
106
  const serverUrl = Option.getOrUndefined(config.server)
@@ -42,7 +42,7 @@ const makeSendgrid = ({ apiKey, defaultFrom, defaultReplyTo, realMail, subjectPr
42
42
  (err, result) =>
43
43
  err
44
44
  ? resume(Effect.fail(err))
45
- : resume(Effect.sync(() => result!))
45
+ : resume(Effect.sync(() => result))
46
46
  )
47
47
  )
48
48
  .pipe(Effect.mapError((raw) => new SendMailError({ raw })))
@@ -1,13 +1,13 @@
1
1
  import type { MailContent, MailData } from "@sendgrid/helpers/classes/mail.js"
2
2
  import type { ResponseError } from "@sendgrid/mail"
3
- import { Data, type Effect, type NonEmptyReadonlyArray, type Redacted, ServiceMap } from "effect-app"
3
+ import { Context, Data, type Effect, type NonEmptyReadonlyArray, type Redacted } from "effect-app"
4
4
  import type { Email } from "effect-app/Schema"
5
5
 
6
6
  export class SendMailError extends Data.TaggedError("SendMailError")<{
7
7
  readonly raw: Error | ResponseError
8
8
  }> {}
9
9
 
10
- export class Emailer extends ServiceMap.Opaque<Emailer, {
10
+ export class Emailer extends Context.Opaque<Emailer, {
11
11
  sendMail: (msg: EmailMsgOptionalFrom) => Effect.Effect<void, SendMailError>
12
12
  }>()("effect-app/Emailer") {}
13
13
 
@@ -1,4 +1,4 @@
1
- import { Effect, Fiber, FiberSet, Layer, ServiceMap } from "effect-app"
1
+ import { Context, Effect, Fiber, FiberSet, Layer } from "effect-app"
2
2
  import type {} from "effect/Scope"
3
3
  import { InfraLogger } from "./logger.js"
4
4
  import { reportNonInterruptedFailureCause } from "./QueueMaker/errors.js"
@@ -62,7 +62,7 @@ const make = Effect.gen(function*() {
62
62
  * you should register these long running fibers in a FiberSet, and join them at the end of your main program.
63
63
  * This way any errors will blow up the main program instead of fibers dying unknowingly.
64
64
  */
65
- export class MainFiberSet extends ServiceMap.Service<MainFiberSet>()("MainFiberSet", { make }) {
65
+ export class MainFiberSet extends Context.Service<MainFiberSet>()("MainFiberSet", { make }) {
66
66
  static readonly Live = Layer.effect(this, this.make)
67
67
  static readonly JoinLive = this.asEffect().pipe(
68
68
  Effect.andThen((_) => _.join),
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import type {} from "effect/Equal"
3
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"
4
+ import { Array, Chunk, Context, Effect, Equivalence, flow, type NonEmptyReadonlyArray, Option, pipe, Pipeable, PubSub, Result, S, SchemaAST, Unify } from "effect-app"
5
5
  import { toNonEmptyArray } from "effect-app/Array"
6
6
  import { NotFoundError } from "effect-app/client/errors"
7
7
  import { flatMapOption } from "effect-app/Effect"
@@ -55,14 +55,14 @@ export function makeRepoInternal<
55
55
 
56
56
  function make<RInitial = never, E = never, RPublish = never, RCtx = never>(
57
57
  args: [Evt] extends [never] ? {
58
- schemaContext?: ServiceMap.ServiceMap<RCtx>
58
+ schemaContext?: Context.Context<RCtx>
59
59
  makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
60
60
  config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
61
61
  partitionValue?: (e?: Encoded) => string
62
62
  }
63
63
  }
64
64
  : {
65
- schemaContext?: ServiceMap.ServiceMap<RCtx>
65
+ schemaContext?: Context.Context<RCtx>
66
66
  publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
67
67
  makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
68
68
  config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
@@ -72,7 +72,7 @@ export function makeRepoInternal<
72
72
  ) {
73
73
  return Effect
74
74
  .gen(function*() {
75
- const rctx: ServiceMap.ServiceMap<RCtx> = args.schemaContext ?? ServiceMap.empty() as any
75
+ const rctx: Context.Context<RCtx> = args.schemaContext ?? Context.empty() as any
76
76
  const provideRctx = Effect.provide(rctx)
77
77
  const encodeMany = flow(
78
78
  S.encodeEffect(S.Array(schema)),
@@ -113,11 +113,14 @@ export function makeRepoInternal<
113
113
  let ast = _.ast
114
114
  if (ast._tag === "Declaration") ast = ast.typeParameters[0]!
115
115
 
116
- // In v4, to get the encoded (from) side of a schema, use SchemaAST.toEncoded
117
116
  const pickIdFromAst = (a: SchemaAST.AST) => {
118
- const encoded = SchemaAST.toEncoded(a)
119
- if (SchemaAST.isObjects(encoded)) {
120
- const field = encoded.propertySignatures.find((_) => _.name === idKey)
117
+ // Unwrap Declaration (e.g. TaggedClass) to get the underlying Objects AST
118
+ let inner = a
119
+ if (inner._tag === "Declaration") inner = inner.typeParameters[0]!
120
+ // Pick from the original AST to preserve the full encoding chain (e.g. decodeTo transformations).
121
+ // Using toEncoded would lose transformation info needed to encode Type -> Encoded.
122
+ if (SchemaAST.isObjects(inner)) {
123
+ const field = inner.propertySignatures.find((_) => _.name === idKey)
121
124
  if (field) {
122
125
  return S.Struct({ [idKey]: S.make(field.type) }) as unknown as Codec<T, Encoded>
123
126
  }
@@ -7,7 +7,7 @@
7
7
  // import type { ParserEnv } from "effect-app/Schema/custom/Parser"
8
8
  import type {} from "effect/Equal"
9
9
  import type {} from "effect/Hash"
10
- import { Effect, type NonEmptyReadonlyArray, type S, type ServiceMap } from "effect-app"
10
+ import { type Context, Effect, type NonEmptyReadonlyArray, type S } from "effect-app"
11
11
  import type { StoreConfig, StoreMaker } from "../../Store.js"
12
12
  import type { FieldValues } from "../filter/types.js"
13
13
  import { type ExtendedRepository, extendRepo } from "./ext.js"
@@ -52,7 +52,7 @@ export interface RepositoryOptions<
52
52
  * Optional context to be provided to Schema decode/encode.
53
53
  * Useful for effectful transformations like XWithItems, where items is a transformation retrieving elements from another database table or other source.
54
54
  */
55
- schemaContext?: ServiceMap.ServiceMap<RCtx>
55
+ schemaContext?: Context.Context<RCtx>
56
56
 
57
57
  overrides?: (
58
58
  repo: Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish>
package/src/Operations.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reportError } from "@effect-app/infra/errorReporter"
2
2
  import { subHours } from "date-fns"
3
- import { Cause, copy, Duration, Effect, Exit, type Fiber, Layer, Option, S, Schedule, ServiceMap } from "effect-app"
3
+ import { Cause, Context, copy, Duration, Effect, Exit, type Fiber, Layer, Option, S, Schedule } from "effect-app"
4
4
  import { annotateLogscoped } from "effect-app/Effect"
5
5
  import { dual, pipe } from "effect-app/Function"
6
6
  import { Operation, OperationFailure, OperationId, type OperationProgress, OperationSuccess } from "effect-app/Operations"
@@ -189,7 +189,7 @@ const make = Effect.gen(function*() {
189
189
  }
190
190
  })
191
191
 
192
- export class Operations extends ServiceMap.Opaque<Operations>()("effect-app/Operations", { make }) {
192
+ export class Operations extends Context.Opaque<Operations>()("effect-app/Operations", { make }) {
193
193
  private static readonly CleanupLive = this
194
194
  .use((_) =>
195
195
  _.cleanup.pipe(
@@ -1,8 +1,8 @@
1
- import { Effect, ServiceMap } from "effect-app"
1
+ import { Context, Effect } from "effect-app"
2
2
  import { Operation } from "effect-app/Operations"
3
3
  import { makeRepo } from "./Model.js"
4
4
 
5
- export class OperationsRepo extends ServiceMap.Service<OperationsRepo>()(
5
+ export class OperationsRepo extends Context.Service<OperationsRepo>()(
6
6
  "OperationRepo",
7
7
  {
8
8
  make: Effect.gen(function*() {
@@ -1,16 +1,15 @@
1
1
  import { getRequestContext, setupRequestContextWithCustomSpan } from "@effect-app/infra/api/setupRequest"
2
2
  import { reportNonInterruptedFailure } from "@effect-app/infra/QueueMaker/errors"
3
3
  import { type QueueBase, QueueMeta } from "@effect-app/infra/QueueMaker/service"
4
- import { SqlClient } from "effect/unstable/sql"
5
4
  import { subMinutes } from "date-fns"
6
- import { Effect, Fiber, Option, S, Tracer } from "effect-app"
7
- import type { NonEmptyString255 } from "effect-app/Schema"
5
+ import { Effect, Fiber, type NonEmptyReadonlyArray, Option, S, Tracer } from "effect-app"
6
+ import { type NonEmptyString255 } from "effect-app/Schema"
8
7
  import { pretty } from "effect-app/utils"
9
- import type { NonEmptyReadonlyArray } from "effect-app"
8
+ import { SqlClient } from "effect/unstable/sql"
10
9
  import { SQLModel } from "../adapters/SQL.js"
11
10
  import { InfraLogger } from "../logger.js"
12
11
 
13
- export const QueueId = S.Number.pipe(S.brand("QueueId"))
12
+ export const QueueId = S.Finite.pipe(S.brand("QueueId"))
14
13
  export type QueueId = typeof QueueId.Type
15
14
 
16
15
  // TODO: let the model track and Auto Generate versionColumn on every update instead
@@ -79,14 +78,14 @@ export function makeSQLQueue<
79
78
 
80
79
  const q = {
81
80
  offer: Effect.fnUntraced(function*(body: Evt, meta: typeof QueueMeta.Type) {
82
- yield* queueRepo.insertVoid({
81
+ yield* queueRepo.insertVoid(Queue.insert.make({
83
82
  body,
84
83
  meta,
85
84
  name: queueName,
86
85
  processingAt: Option.none(),
87
86
  finishedAt: Option.none(),
88
87
  etag: crypto.randomUUID()
89
- })
88
+ }))
90
89
  }),
91
90
  take: Effect.gen(function*() {
92
91
  while (true) {
@@ -95,15 +94,16 @@ export function makeSQLQueue<
95
94
  const dec = yield* decodeDrain(first)
96
95
  const { createdAt, updatedAt, ...rest } = dec
97
96
  return yield* drainRepo.update(
98
- { ...rest, processingAt: Option.some(new Date()) } // auto in lib , etag: crypto.randomUUID()
97
+ Drain.update.make({ ...rest, processingAt: Option.some(new Date()) }) // auto in lib , etag: crypto.randomUUID()
99
98
  )
100
99
  }
101
100
  if (first) return first
102
101
  yield* Effect.sleep(250)
103
102
  }
104
103
  }),
105
- finish: ({ createdAt, updatedAt, ...q }: Drain) =>
106
- drainRepo.updateVoid({ ...q, finishedAt: Option.some(new Date()) }) // auto in lib , etag: crypto.randomUUID()
104
+ finish: Effect.fn(function*({ createdAt, updatedAt, ...q }: Drain) {
105
+ return yield* drainRepo.updateVoid(Drain.update.make({ ...q, finishedAt: Option.some(new Date()) })) // auto in lib , etag: crypto.randomUUID()
106
+ })
107
107
  }
108
108
  const queue = {
109
109
  publish: (...messages: NonEmptyReadonlyArray<Evt>) =>
@@ -1,12 +1,11 @@
1
1
  import { Cause, Tracer } from "effect"
2
- import { Effect, Fiber, flow, S } from "effect-app"
3
- import * as Q from "effect/Queue"
2
+ import { Effect, Fiber, flow, type NonEmptyReadonlyArray, S } from "effect-app"
4
3
  import { pretty } from "effect-app/utils"
4
+ import * as Q from "effect/Queue"
5
5
  import { MemQueue } from "../adapters/memQueue.js"
6
6
  import { getRequestContext, setupRequestContextWithCustomSpan } from "../api/setupRequest.js"
7
7
  import { InfraLogger } from "../logger.js"
8
8
  import { reportNonInterruptedFailure, reportNonInterruptedFailureCause } from "./errors.js"
9
- import type { NonEmptyReadonlyArray } from "effect-app"
10
9
  import { type QueueBase, QueueMeta } from "./service.js"
11
10
 
12
11
  export function makeMemQueue<
@@ -26,8 +25,12 @@ export function makeMemQueue<
26
25
  const qDrain = yield* mem.getOrCreateQueue(queueDrainName)
27
26
 
28
27
  const wireSchema = S.Struct({ body: schema, meta: QueueMeta })
28
+ const wireSchemaJson = S.fromJsonString(S.toCodecJson(wireSchema))
29
+ const encodePublish = S.encodeEffect(wireSchemaJson)
29
30
  const drainW = S.Struct({ body: drainSchema, meta: QueueMeta })
30
- const parseDrain = flow(S.decodeUnknownEffect(drainW), Effect.orDie)
31
+ const drainWJson = S.fromJsonString(S.toCodecJson(drainW))
32
+
33
+ const parseDrain = flow(S.decodeUnknownEffect(drainWJson), Effect.orDie)
31
34
 
32
35
  const queue = {
33
36
  publish: (...messages: NonEmptyReadonlyArray<Evt>) =>
@@ -37,10 +40,8 @@ export function makeMemQueue<
37
40
  Effect
38
41
  .forEach(messages, (m) =>
39
42
  // we JSON encode, because that is what the wire also does, and it reveals holes in e.g unknown encoders (Date->String)
40
- S.encodeEffect(wireSchema)({ body: m, meta: requestContext }).pipe(
43
+ encodePublish({ body: m, meta: requestContext }).pipe(
41
44
  Effect.orDie,
42
- Effect
43
- .map(JSON.stringify),
44
45
  // .tap((msg) => info("Publishing Mem Message: " + utils.inspect(msg)))
45
46
  Effect.flatMap((_) => Q.offer(q, _))
46
47
  ), { discard: true })
@@ -58,42 +59,40 @@ export function makeMemQueue<
58
59
  const reportError = reportNonInterruptedFailureCause({ name: "MemQueue.drain." + queueDrainName })
59
60
  const processMessage = (msg: string) =>
60
61
  // we JSON parse, because that is what the wire also does, and it reveals holes in e.g unknown encoders (Date->String)
61
- Effect
62
- .sync(() => JSON.parse(msg))
63
- .pipe(
64
- Effect.flatMap(parseDrain),
65
- Effect.orDie,
66
- Effect
67
- .flatMap(({ body, meta }) => {
68
- let effect = InfraLogger
69
- .logDebug(`[${queueDrainName}] Processing incoming message`)
70
- .pipe(
71
- Effect.annotateLogs({ body: pretty(body), meta: pretty(meta) }),
72
- Effect.andThen(handleEvent(body)),
73
- silenceAndReportError,
74
- (_) =>
75
- setupRequestContextWithCustomSpan(
76
- _,
77
- meta,
78
- `queue.drain: ${queueDrainName}.${body._tag}`,
79
- {
80
- captureStackTrace: false,
81
- kind: "consumer",
82
- attributes: {
83
- "queue.name": queueDrainName,
84
- "queue.sessionId": sessionId,
85
- "queue.input": body
86
- }
62
+ parseDrain(msg).pipe(
63
+ Effect.orDie,
64
+ Effect
65
+ .flatMap(({ body, meta }) => {
66
+ let effect = InfraLogger
67
+ .logDebug(`[${queueDrainName}] Processing incoming message`)
68
+ .pipe(
69
+ Effect.annotateLogs({ body: pretty(body), meta: pretty(meta) }),
70
+ Effect.andThen(handleEvent(body)),
71
+ silenceAndReportError,
72
+ (_) =>
73
+ setupRequestContextWithCustomSpan(
74
+ _,
75
+ meta,
76
+ `queue.drain: ${queueDrainName}.${body._tag}`,
77
+ {
78
+ captureStackTrace: false,
79
+ kind: "consumer",
80
+ attributes: {
81
+ "queue.name": queueDrainName,
82
+ "queue.sessionId": sessionId,
83
+ "queue.input": body
87
84
  }
88
- )
89
- )
90
- if (meta.span) {
91
- effect = Effect.withParentSpan(effect, Tracer.externalSpan(meta.span))
92
- }
93
- return effect
94
- })
95
- )
96
- return Q.take(qDrain)
85
+ }
86
+ )
87
+ )
88
+ if (meta.span) {
89
+ effect = Effect.withParentSpan(effect, Tracer.externalSpan(meta.span))
90
+ }
91
+ return effect
92
+ })
93
+ )
94
+ return Q
95
+ .take(qDrain)
97
96
  .pipe(
98
97
  Effect
99
98
  .flatMap((x) =>
@@ -1,12 +1,11 @@
1
1
  import { Tracer } from "effect"
2
- import { Cause, Effect, flow, S } from "effect-app"
2
+ import { Cause, Effect, flow, type NonEmptyReadonlyArray, S } from "effect-app"
3
3
  import type { StringId } from "effect-app/Schema"
4
4
  import { pretty } from "effect-app/utils"
5
5
  import { Receiver, Sender } from "../adapters/ServiceBus.js"
6
6
  import { getRequestContext, setupRequestContextWithCustomSpan } from "../api/setupRequest.js"
7
7
  import { InfraLogger } from "../logger.js"
8
8
  import { reportNonInterruptedFailure, reportNonInterruptedFailureCause, reportQueueError } from "./errors.js"
9
- import type { NonEmptyReadonlyArray } from "effect-app"
10
9
  import { type QueueBase, QueueMeta } from "./service.js"
11
10
 
12
11
  export function makeServiceBusQueue<
@@ -22,8 +21,11 @@ export function makeServiceBusQueue<
22
21
  body: schema,
23
22
  meta: QueueMeta
24
23
  })
24
+ const wireSchemaJson = S.fromJsonString(S.toCodecJson(wireSchema))
25
+ const encodePublish = S.encodeEffect(wireSchemaJson)
25
26
  const drainW = S.Struct({ body: drainSchema, meta: QueueMeta })
26
- const parseDrain = flow(S.decodeUnknownEffect(drainW), Effect.orDie)
27
+ const drainWJson = S.fromJsonString(S.toCodecJson(drainW))
28
+ const parseDrain = flow(S.decodeUnknownEffect(drainWJson), Effect.orDie)
27
29
 
28
30
  return Effect.gen(function*() {
29
31
  const sender = yield* Sender
@@ -40,55 +42,51 @@ export function makeServiceBusQueue<
40
42
  handleEvent: (ks: DrainEvt) => Effect.Effect<void, DrainE, DrainR>,
41
43
  sessionId?: string
42
44
  ) => {
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- function processMessage(messageBody: any) {
45
- return Effect
46
- .sync(() => JSON.parse(messageBody))
47
- .pipe(
48
- Effect.flatMap((x) => parseDrain(x)),
49
- Effect.orDie,
50
- Effect
51
- .flatMap(({ body, meta }) => {
52
- let effect = InfraLogger
53
- .logDebug(`[${receiver.name}] Processing incoming message`)
54
- .pipe(
55
- Effect.annotateLogs({
56
- body: pretty(body),
57
- meta: pretty(meta)
58
- }),
59
- Effect.andThen(handleEvent(body)),
60
- Effect.orDie
61
- )
62
- // we silenceAndReportError here, so that the error is reported, and moves into the Exit.
63
- .pipe(
64
- silenceAndReportError,
65
- (_) =>
66
- setupRequestContextWithCustomSpan(
67
- _,
68
- meta,
69
- `queue.drain: ${receiver.name}${sessionId ? `#${sessionId}` : ""}.${body._tag}`,
70
- {
71
- captureStackTrace: false,
72
- kind: "consumer",
73
- attributes: {
74
- "queue.name": receiver.name,
75
- "queue.sessionId": sessionId,
76
- "queue.input": body
77
- }
45
+ function processMessage(messageBody: unknown) {
46
+ return parseDrain(messageBody).pipe(
47
+ Effect.orDie,
48
+ Effect
49
+ .flatMap(({ body, meta }) => {
50
+ let effect = InfraLogger
51
+ .logDebug(`[${receiver.name}] Processing incoming message`)
52
+ .pipe(
53
+ Effect.annotateLogs({
54
+ body: pretty(body),
55
+ meta: pretty(meta)
56
+ }),
57
+ Effect.andThen(handleEvent(body)),
58
+ Effect.orDie
59
+ )
60
+ // we silenceAndReportError here, so that the error is reported, and moves into the Exit.
61
+ .pipe(
62
+ silenceAndReportError,
63
+ (_) =>
64
+ setupRequestContextWithCustomSpan(
65
+ _,
66
+ meta,
67
+ `queue.drain: ${receiver.name}${sessionId ? `#${sessionId}` : ""}.${body._tag}`,
68
+ {
69
+ captureStackTrace: false,
70
+ kind: "consumer",
71
+ attributes: {
72
+ "queue.name": receiver.name,
73
+ "queue.sessionId": sessionId,
74
+ "queue.input": body
78
75
  }
79
- )
80
- )
81
- if (meta.span) {
82
- effect = Effect.withParentSpan(effect, Tracer.externalSpan(meta.span))
83
- }
84
- return effect
85
- }),
86
- Effect
87
- // we reportError here, so that we report the error only, and keep flowing
88
- .tapCause(reportError),
89
- // we still need to flatten the Exit.
90
- Effect.flatMap((_) => _)
91
- )
76
+ }
77
+ )
78
+ )
79
+ if (meta.span) {
80
+ effect = Effect.withParentSpan(effect, Tracer.externalSpan(meta.span))
81
+ }
82
+ return effect
83
+ }),
84
+ Effect
85
+ // we reportError here, so that we report the error only, and keep flowing
86
+ .tapCause(reportError),
87
+ // we still need to flatten the Exit.
88
+ Effect.flatMap((_) => _)
89
+ )
92
90
  }
93
91
 
94
92
  return receiver
@@ -111,17 +109,22 @@ export function makeServiceBusQueue<
111
109
  getRequestContext
112
110
  .pipe(
113
111
  Effect.flatMap((requestContext) =>
114
- Effect.forEach(messages, (m) =>
115
- S.encodeEffect(wireSchema)({
116
- body: m,
117
- meta: requestContext
118
- }).pipe(Effect.orDie, Effect.map((encoded) => ({
119
- body: JSON.stringify(encoded),
120
- messageId: m.id, /* correllationid: requestId */
121
- contentType: "application/json",
122
- sessionId: "sessionId" in m ? m.sessionId as string : undefined as unknown as string // TODO: optional
123
- }))))
124
- .pipe(Effect.flatMap((msgs) => sender.sendMessages(msgs)))
112
+ Effect
113
+ .forEach(messages, (m) =>
114
+ encodePublish({
115
+ body: m,
116
+ meta: requestContext
117
+ })
118
+ .pipe(
119
+ Effect.orDie,
120
+ Effect.map((body) => ({
121
+ body,
122
+ messageId: m.id, /* correllationid: requestId */
123
+ contentType: "application/json",
124
+ sessionId: "sessionId" in m ? m.sessionId as string : undefined as unknown as string // TODO: optional
125
+ }))
126
+ ))
127
+ .pipe(Effect.flatMap((msgs) => sender.sendMessages(msgs)))
125
128
  ),
126
129
  Effect.withSpan("queue.publish: " + sender.name, {
127
130
  kind: "producer",
@@ -1,11 +1,11 @@
1
- import { S, ServiceMap } from "effect-app"
1
+ import { Context, S } from "effect-app"
2
2
  import { UserProfileId } from "effect-app/ids"
3
3
  import { NonEmptyString255 } from "effect-app/Schema"
4
4
 
5
- export const Locale = S.Literal("en", "de")
5
+ export const Locale = S.Literals(["en", "de"])
6
6
  export type Locale = typeof Locale.Type
7
7
 
8
- export class LocaleRef extends ServiceMap.Reference("Locale", { defaultValue: (): Locale => "en" }) {}
8
+ export class LocaleRef extends Context.Reference("Locale", { defaultValue: (): Locale => "en" }) {}
9
9
 
10
10
  export class RequestContext extends S.ExtendedClass<
11
11
  RequestContext,
@@ -23,7 +23,7 @@ export class RequestContext extends S.ExtendedClass<
23
23
  /** @deprecated */
24
24
  userProfile: S.optional(S.Struct({ sub: UserProfileId })) //
25
25
  }) {
26
- // static Tag = ServiceMap.Tag<RequestContext>()
26
+ // static Tag = Context.Tag<RequestContext>()
27
27
 
28
28
  static toMonitoring(this: void, self: RequestContext) {
29
29
  return {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Effect, Fiber, FiberSet, Layer, ServiceMap, type Tracer } from "effect-app"
2
+ import { Context, Effect, Fiber, FiberSet, Layer, Option, type Tracer } from "effect-app"
3
3
  import { reportRequestError, reportUnknownRequestError } from "./api/reportError.js"
4
4
  import { InfraLogger } from "./logger.js"
5
5
 
@@ -8,8 +8,8 @@ const getRootParentSpan = Effect.gen(function*() {
8
8
  Effect.catchTag("NoSuchElementError", () => Effect.succeed(null))
9
9
  )
10
10
  if (!span) return span
11
- while (span._tag === "Span" && span.parent !== undefined) {
12
- span = span.parent
11
+ while (span._tag === "Span" && Option.isSome(span.parent)) {
12
+ span = span.parent.value
13
13
  }
14
14
  return span
15
15
  })
@@ -92,7 +92,7 @@ const make = Effect.gen(function*() {
92
92
  * Whenever you fork a fiber for a Request, and you want to prevent dependent services to close prematurely on interruption,
93
93
  * like the ServiceBus Sender, you should register these fibers in this FiberSet.
94
94
  */
95
- export class RequestFiberSet extends ServiceMap.Service<RequestFiberSet>()("RequestFiberSet", { make }) {
95
+ export class RequestFiberSet extends Context.Service<RequestFiberSet>()("RequestFiberSet", { make }) {
96
96
  static readonly Live = Layer.effect(this, this.make)
97
97
  static readonly register = <A, E, R>(self: Effect.Effect<A, E, R>) =>
98
98
  this.asEffect().pipe(Effect.andThen((_) => _.register(self)))