@effect-app/infra 0.142.1 → 0.143.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/_cjs/api/defaultErrorHandler.cjs.map +1 -1
  3. package/_cjs/api/routing/base.cjs.map +1 -1
  4. package/_cjs/api/routing/defaultErrorHandler.cjs.map +1 -1
  5. package/_cjs/api/routing/makeRequestHandler.cjs.map +1 -1
  6. package/_cjs/errorReporter.cjs.map +1 -1
  7. package/_cjs/services/Emailer/Sendgrid.cjs.map +1 -1
  8. package/_cjs/services/Operations/live.cjs.map +1 -1
  9. package/_cjs/services/QueueMaker/errors.cjs.map +1 -1
  10. package/_cjs/services/QueueMaker/memQueue.cjs.map +1 -1
  11. package/_cjs/services/QueueMaker/sbqueue.cjs.map +1 -1
  12. package/_cjs/services/Repository.cjs.map +1 -1
  13. package/_cjs/services/RepositoryBase.cjs.map +1 -1
  14. package/_cjs/services/RequestContextContainer.cjs.map +1 -1
  15. package/_cjs/services/Store/ContextMapContainer.cjs.map +1 -1
  16. package/_cjs/services/Store/Cosmos.cjs +1 -1
  17. package/_cjs/services/Store/Cosmos.cjs.map +1 -1
  18. package/_cjs/services/Store/Disk.cjs.map +1 -1
  19. package/_cjs/services/Store/Memory.cjs.map +1 -1
  20. package/_cjs/services/Store/Redis.cjs.map +1 -1
  21. package/_cjs/services/Store/codeFilter.cjs +2 -2
  22. package/_cjs/services/Store/utils.cjs.map +1 -1
  23. package/_cjs/services/simpledb/diskdb.cjs.map +1 -1
  24. package/_cjs/services/simpledb/redisdb.cjs.map +1 -1
  25. package/_cjs/services/simpledb/shared.cjs.map +1 -1
  26. package/_cjs/services/simpledb/simpledb.cjs.map +1 -1
  27. package/_src/api/defaultErrorHandler.ts +2 -2
  28. package/_src/api/express/schema/routing.ts +11 -11
  29. package/_src/api/routing/base.ts +12 -12
  30. package/_src/api/routing/defaultErrorHandler.ts +2 -2
  31. package/_src/api/routing/makeRequestHandler.ts +1 -1
  32. package/_src/errorReporter.ts +1 -1
  33. package/_src/services/Emailer/Sendgrid.ts +1 -1
  34. package/_src/services/Operations/live.ts +3 -3
  35. package/_src/services/QueueMaker/errors.ts +1 -1
  36. package/_src/services/QueueMaker/memQueue.ts +2 -2
  37. package/_src/services/QueueMaker/sbqueue.ts +1 -1
  38. package/_src/services/Repository.ts +11 -11
  39. package/_src/services/RepositoryBase.ts +3 -3
  40. package/_src/services/RequestContextContainer.ts +1 -1
  41. package/_src/services/Store/ContextMapContainer.ts +1 -1
  42. package/_src/services/Store/Cosmos.ts +27 -19
  43. package/_src/services/Store/Disk.ts +2 -2
  44. package/_src/services/Store/Memory.ts +3 -3
  45. package/_src/services/Store/Redis.ts +1 -1
  46. package/_src/services/Store/codeFilter.ts +2 -2
  47. package/_src/services/Store/index.test.ts.bak +5 -5
  48. package/_src/services/Store/utils.ts +9 -9
  49. package/_src/services/simpledb/diskdb.ts +1 -1
  50. package/_src/services/simpledb/redisdb.ts +1 -1
  51. package/_src/services/simpledb/shared.ts +1 -1
  52. package/_src/services/simpledb/simpledb.ts +2 -2
  53. package/dist/api/defaultErrorHandler.js +1 -1
  54. package/dist/api/routing/base.js +1 -1
  55. package/dist/api/routing/defaultErrorHandler.js +1 -1
  56. package/dist/api/routing/makeRequestHandler.js +1 -1
  57. package/dist/errorReporter.js +1 -1
  58. package/dist/services/Emailer/Sendgrid.js +1 -1
  59. package/dist/services/Operations/live.js +1 -1
  60. package/dist/services/Operations/service.d.ts +4 -4
  61. package/dist/services/Operations/service.d.ts.map +1 -1
  62. package/dist/services/QueueMaker/errors.js +1 -1
  63. package/dist/services/QueueMaker/memQueue.js +1 -1
  64. package/dist/services/QueueMaker/sbqueue.js +1 -1
  65. package/dist/services/Repository.js +1 -1
  66. package/dist/services/RepositoryBase.d.ts +5 -17
  67. package/dist/services/RepositoryBase.d.ts.map +1 -1
  68. package/dist/services/RepositoryBase.js +1 -1
  69. package/dist/services/RequestContextContainer.d.ts +1 -1
  70. package/dist/services/RequestContextContainer.js +1 -1
  71. package/dist/services/Store/ContextMapContainer.js +1 -1
  72. package/dist/services/Store/Cosmos.d.ts.map +1 -1
  73. package/dist/services/Store/Cosmos.js +2 -2
  74. package/dist/services/Store/Disk.js +1 -1
  75. package/dist/services/Store/Memory.js +1 -1
  76. package/dist/services/Store/Redis.js +1 -1
  77. package/dist/services/Store/codeFilter.js +3 -3
  78. package/dist/services/Store/utils.js +1 -1
  79. package/dist/services/simpledb/diskdb.d.ts +1 -1
  80. package/dist/services/simpledb/diskdb.js +1 -1
  81. package/dist/services/simpledb/redisdb.js +1 -1
  82. package/dist/services/simpledb/shared.js +1 -1
  83. package/dist/services/simpledb/simpledb.d.ts.map +1 -1
  84. package/dist/services/simpledb/simpledb.js +1 -1
  85. package/package.json +8 -8
@@ -152,7 +152,7 @@ export function parseRequestParams<
152
152
  .flatMap((_) =>
153
153
  _.isFailure() && !_.cause.isFailure()
154
154
  ? (Effect.failCauseSync(() => _.cause) as Effect<never, ValidationError, never>)
155
- : Effect(
155
+ : Effect.sync(() =>
156
156
  _.isSuccess()
157
157
  ? { _tag: "Success" as const, value: _.value }
158
158
  : { _tag: "Failure", errors: _.cause.failures }
@@ -164,7 +164,7 @@ export function parseRequestParams<
164
164
  .flatMap((_) =>
165
165
  _.isFailure() && !_.cause.isFailure()
166
166
  ? (Effect.failCauseSync(() => _.cause) as Effect<never, ValidationError, never>)
167
- : Effect(
167
+ : Effect.sync(() =>
168
168
  _.isSuccess()
169
169
  ? { _tag: "Success" as const, value: _.value }
170
170
  : { _tag: "Failure", errors: _.cause.failures }
@@ -176,7 +176,7 @@ export function parseRequestParams<
176
176
  .flatMap((_) =>
177
177
  _.isFailure() && !_.cause.isFailure()
178
178
  ? (Effect.failCauseSync(() => _.cause) as Effect<never, ValidationError, never>)
179
- : Effect(
179
+ : Effect.sync(() =>
180
180
  _.isSuccess()
181
181
  ? { _tag: "Success" as const, value: _.value }
182
182
  : { _tag: "Failure", errors: _.cause.failures }
@@ -188,7 +188,7 @@ export function parseRequestParams<
188
188
  .flatMap((_) =>
189
189
  _.isFailure() && !_.cause.isFailure()
190
190
  ? (Effect.failCauseSync(() => _.cause) as Effect<never, ValidationError, never>)
191
- : Effect(
191
+ : Effect.sync(() =>
192
192
  _.isSuccess()
193
193
  ? { _tag: "Success" as const, value: _.value }
194
194
  : { _tag: "Failure", errors: _.cause.failures }
@@ -200,7 +200,7 @@ export function parseRequestParams<
200
200
  .flatMap((_) =>
201
201
  _.isFailure() && !_.cause.isFailure()
202
202
  ? (Effect.failCauseSync(() => _.cause) as Effect<never, ValidationError, never>)
203
- : Effect(
203
+ : Effect.sync(() =>
204
204
  _.isSuccess()
205
205
  ? { _tag: "Success" as const, value: _.value }
206
206
  : { _tag: "Failure", errors: _.cause.failures }
@@ -227,13 +227,13 @@ export function parseRequestParams<
227
227
  if (errors.length) {
228
228
  return new ValidationError({ errors })
229
229
  }
230
- return Effect({
230
+ return Effect.sync(() => ({
231
231
  body: body.value!,
232
232
  cookie: cookie.value!,
233
233
  headers: headers.value!,
234
234
  path: path.value!,
235
235
  query: query.value!
236
- })
236
+ }))
237
237
  })
238
238
  }
239
239
 
@@ -319,7 +319,7 @@ export function makeRequestParsers<
319
319
  Config
320
320
  >["Request"]
321
321
  ): RequestParsers<PathA, CookieA, QueryA, BodyA, HeaderA> {
322
- const ph = Effect(
322
+ const ph = Effect.sync(() =>
323
323
  Option
324
324
  .fromNullable(Request.Headers)
325
325
  .map((s) => s as unknown as Schema<any, any>)
@@ -327,7 +327,7 @@ export function makeRequestParsers<
327
327
  )
328
328
  const parseHeaders = (u: unknown) => ph.flatMapOpt((d) => d(u))
329
329
 
330
- const pq = Effect(
330
+ const pq = Effect.sync(() =>
331
331
  Option
332
332
  .fromNullable(Request.Query)
333
333
  .map((s) => s as unknown as Schema<any, any>)
@@ -335,7 +335,7 @@ export function makeRequestParsers<
335
335
  )
336
336
  const parseQuery = (u: unknown) => pq.flatMapOpt((d) => d(u))
337
337
 
338
- const pb = Effect(
338
+ const pb = Effect.sync(() =>
339
339
  Option
340
340
  .fromNullable(Request.Body)
341
341
  .map((s) => s as unknown as Schema<any, any>)
@@ -343,7 +343,7 @@ export function makeRequestParsers<
343
343
  )
344
344
  const parseBody = (u: unknown) => pb.flatMapOpt((d) => d(u))
345
345
 
346
- const pp = Effect(
346
+ const pp = Effect.sync(() =>
347
347
  Option
348
348
  .fromNullable(Request.Path)
349
349
  .map((s) => s as unknown as Schema<any, any>)
@@ -351,7 +351,7 @@ export function makeRequestParsers<
351
351
  )
352
352
  const parsePath = (u: unknown) => pp.flatMapOpt((d) => d(u))
353
353
 
354
- const pc = Effect(
354
+ const pc = Effect.sync(() =>
355
355
  Option
356
356
  .fromNullable(Request.Cookie)
357
357
  .map((s) => s as unknown as Schema<any, any>)
@@ -24,7 +24,7 @@ export function defaultBasicErrorHandler<R>(
24
24
  res: HttpServerResponse,
25
25
  r2: Effect<R, ValidationError, HttpServerResponse>
26
26
  ) {
27
- const sendError = (code: number) => (body: unknown) => Effect(res.setBody(HttpBody.unsafeJson(body)).setStatus(code))
27
+ const sendError = (code: number) => (body: unknown) => Effect.sync(() => res.setBody(HttpBody.unsafeJson(body)).setStatus(code))
28
28
  return r2
29
29
  .tapErrorCause((cause) => cause.isFailure() ? logRequestError(cause) : Effect.unit)
30
30
  .catchTag("ValidationError", (err) => sendError(400)(err.errors))
@@ -50,7 +50,7 @@ export function defaultErrorHandler<R>(
50
50
  const r3 = req.method === "PATCH"
51
51
  ? r2.retry(optimisticConcurrencySchedule)
52
52
  : r2
53
- const sendError = (code: number) => (body: unknown) => Effect(res.setStatus(code).setBody(HttpBody.unsafeJson(body)))
53
+ const sendError = (code: number) => (body: unknown) => Effect.sync(() => res.setStatus(code).setBody(HttpBody.unsafeJson(body)))
54
54
  return r3
55
55
  .tapErrorCause((cause) => cause.isFailure() ? logRequestError(cause) : Effect.unit)
56
56
  .catchTags({
@@ -248,7 +248,7 @@ export function makeRequestHandler<
248
248
  })
249
249
  ], { concurrency: "inherit" })
250
250
  )
251
- .tapErrorCause((cause) => Effect(console.error("Error occurred while reporting error", cause)))
251
+ .tapErrorCause((cause) => Effect.sync(() => console.error("Error occurred while reporting error", cause)))
252
252
  )
253
253
  .tap((res) =>
254
254
  Effect
@@ -76,5 +76,5 @@ export function reportMessage(message: string) {
76
76
  }
77
77
 
78
78
  export function reportMessageM(message: string) {
79
- return Effect(reportMessage(message))
79
+ return Effect.sync(() => reportMessage(message))
80
80
  }
@@ -33,7 +33,7 @@ const makeSendgrid = ({ apiKey, defaultFrom, defaultReplyTo, realMail, subjectPr
33
33
  void sgMail.send(renderedMsg, false, (err, result) =>
34
34
  err
35
35
  ? cb(Effect.fail(err))
36
- : cb(Effect(result)))
36
+ : cb(Effect.sync(() => result)))
37
37
  )
38
38
  )
39
39
 
@@ -7,7 +7,7 @@ const reportAppError = reportError("Operations.Cleanup")
7
7
 
8
8
  const make = Effect.sync((): Operations => {
9
9
  const ops = new Map<OperationId, Operation>()
10
- const makeOp = Effect(OperationId.make())
10
+ const makeOp = Effect.sync(() => OperationId.make())
11
11
 
12
12
  const cleanup = Effect
13
13
  .sync(() => {
@@ -30,7 +30,7 @@ const make = Effect.sync((): Operations => {
30
30
  })
31
31
  }
32
32
  function findOp(id: OperationId) {
33
- return Effect(Option.fromNullable(ops.get(id)))
33
+ return Effect.sync(() => Option.fromNullable(ops.get(id)))
34
34
  }
35
35
  function finishOp(id: OperationId, exit: Exit<unknown, unknown>) {
36
36
  return findOp(id).flatMap((_) =>
@@ -53,7 +53,7 @@ const make = Effect.sync((): Operations => {
53
53
  .failureOption
54
54
  .flatMap((_) =>
55
55
  typeof _ === "object" && _ !== null && "message" in _ && NonEmptyString2k.is(_.message)
56
- ? Option(_.message)
56
+ ? Option.some(_.message)
57
57
  : Option.none
58
58
  )
59
59
  .value ?? null
@@ -28,7 +28,7 @@ export function reportNonInterruptedFailure(context?: Record<string, unknown>) {
28
28
  inp
29
29
  .exit
30
30
  .flatMap((result) =>
31
- result.match({ onFailure: (cause) => report(cause).map(() => result), onSuccess: () => Effect(result) })
31
+ result.match({ onFailure: (cause) => report(cause).map(() => result), onSuccess: () => Effect.sync(() => result) })
32
32
  )
33
33
  }
34
34
 
@@ -41,7 +41,7 @@ export function makeMemQueue<
41
41
  messages
42
42
  .forEachEffect((m) =>
43
43
  // we JSON encode, because that is what the wire also does, and it reveals holes in e.g unknown encoders (Date->String)
44
- Effect(
44
+ Effect.sync(() =>
45
45
  JSON.stringify(
46
46
  wireSchema.encodeSync({ body: m, meta: { requestContext, span } })
47
47
  )
@@ -60,7 +60,7 @@ export function makeMemQueue<
60
60
  const silenceAndReportError = reportNonInterruptedFailure({ name: "MemQueue.drain." + queueDrainName })
61
61
  const processMessage = (msg: string) =>
62
62
  // we JSON parse, because that is what the wire also does, and it reveals holes in e.g unknown encoders (Date->String)
63
- Effect(JSON.parse(msg))
63
+ Effect.sync(() => JSON.parse(msg))
64
64
  .flatMap(parseDrain)
65
65
  .orDie
66
66
  .flatMap(({ body, meta }) =>
@@ -84,7 +84,7 @@ export function makeServiceBusQueue<
84
84
  return yield* $(
85
85
  subscribe({
86
86
  processMessage: (x) => processMessage(x.body).uninterruptible,
87
- processError: (err) => Effect(captureException(err.error))
87
+ processError: (err) => Effect.sync(() => captureException(err.error))
88
88
  })
89
89
  .provide(receiverLayer)
90
90
  )
@@ -190,7 +190,7 @@ export function project<
190
190
  skip?: number
191
191
  }
192
192
  ): Effect<never, never, S[]> {
193
- return self.projectEffect(Effect(map))
193
+ return self.projectEffect(Effect.sync(() => map))
194
194
  }
195
195
 
196
196
  /**
@@ -207,7 +207,7 @@ export function count<
207
207
  filter?: Filter<PM>
208
208
  ) {
209
209
  return self
210
- .projectEffect(Effect({ filter }))
210
+ .projectEffect(Effect.sync(() => ({ filter })))
211
211
  .map((_) => NonNegativeInt(_.length))
212
212
  }
213
213
 
@@ -301,7 +301,7 @@ export function query<
301
301
  // TODO: think about collectPM, collectE, and collect(Parsed)
302
302
  map: { filter?: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }
303
303
  ) {
304
- return self.queryEffect(Effect(map))
304
+ return self.queryEffect(Effect.sync(() => map))
305
305
  }
306
306
 
307
307
  /**
@@ -336,7 +336,7 @@ export function queryOne<
336
336
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
337
337
  map: { filter?: Filter<PM>; collect?: (t: T) => Option<S> }
338
338
  ) {
339
- return self.queryOneEffect(Effect(map))
339
+ return self.queryOneEffect(Effect.sync(() => map))
340
340
  }
341
341
 
342
342
  /**
@@ -426,7 +426,7 @@ export function queryAndSaveOnePure(
426
426
  self: any,
427
427
  map: { filter: Filter<any>; collect?: any }
428
428
  ) {
429
- return queryAndSaveOnePureEffect(self, Effect(map))
429
+ return queryAndSaveOnePureEffect(self, Effect.sync(() => map))
430
430
  }
431
431
 
432
432
  /**
@@ -462,7 +462,7 @@ export function queryAndSavePure<
462
462
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
463
463
  map: { filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }
464
464
  ) {
465
- return self.queryAndSavePureEffect(Effect(map))
465
+ return self.queryAndSavePureEffect(Effect.sync(() => map))
466
466
  }
467
467
 
468
468
  /**
@@ -613,7 +613,7 @@ export function queryAndSavePureBatched<
613
613
  map: { filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number },
614
614
  batchSize = 100
615
615
  ) {
616
- return self.queryAndSavePureEffectBatched(Effect(map), batchSize)
616
+ return self.queryAndSavePureEffectBatched(Effect.sync(() => map), batchSize)
617
617
  }
618
618
 
619
619
  /**
@@ -705,7 +705,7 @@ export interface OneDSLExt<T, Evt> {
705
705
  * @tsplus fluent DSLExt updateWith
706
706
  */
707
707
  export function updateWithOne<T, Evt, S1 extends T, S2 extends T>(self: OneDSL<T, Evt>, upd: (item: S1) => S2) {
708
- return self.update((_: S1) => Effect(upd(_)))
708
+ return self.update((_: S1) => Effect.sync(() => upd(_)))
709
709
  }
710
710
 
711
711
  /**
@@ -715,7 +715,7 @@ export function updateWith<T, Evt, S1 extends T, S2 extends T>(
715
715
  self: AllDSL<T, Evt>,
716
716
  upd: (item: S1[]) => S2[]
717
717
  ) {
718
- return self.update((_: S1[]) => Effect(upd(_)))
718
+ return self.update((_: S1[]) => Effect.sync(() => upd(_)))
719
719
  }
720
720
 
721
721
  export function makeOneDSL<T, Evt>(): OneDSL<T, Evt> {
@@ -772,14 +772,14 @@ export function makeDSL<S1, S2, Evt>() {
772
772
  export interface DSLExt<S1, S2, Evt> extends ReturnType<typeof makeDSL<S1, S2, Evt>> {}
773
773
 
774
774
  export function ifAny<T, R, E, A>(fn: (items: NonEmptyReadonlyArray<T>) => Effect<R, E, A>) {
775
- return (items: Iterable<T>) => Effect(items.toNonEmptyArray).flatMapOpt(fn)
775
+ return (items: Iterable<T>) => Effect.sync(() => items.toNonEmptyArray).flatMapOpt(fn)
776
776
  }
777
777
 
778
778
  /**
779
779
  * @tsplus fluent Iterable ifAny
780
780
  */
781
781
  export function ifAny_<T, R, E, A>(items: Iterable<T>, fn: (items: NonEmptyReadonlyArray<T>) => Effect<R, E, A>) {
782
- return Effect(items.toNonEmptyArray).flatMapOpt(fn)
782
+ return Effect.sync(() => items.toNonEmptyArray).flatMapOpt(fn)
783
783
  }
784
784
 
785
785
  /**
@@ -180,7 +180,7 @@ export function makeRepo<
180
180
  }
181
181
 
182
182
  const saveAllE = (a: Iterable<From>) =>
183
- Effect(a.toNonEmptyArray)
183
+ Effect.sync(() => a.toNonEmptyArray)
184
184
  .flatMapOpt((a) =>
185
185
  Do(($) => {
186
186
  const { get, set } = $(cms)
@@ -197,7 +197,7 @@ export function makeRepo<
197
197
  const saveAndPublish = (items: Iterable<T>, events: Iterable<Evt> = []) => {
198
198
  const it = items.toChunk
199
199
  return saveAll(it)
200
- .andThen(Effect(events.toNonEmptyArray))
200
+ .andThen(Effect.sync(() => events.toNonEmptyArray))
201
201
  // TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
202
202
  .flatMapOpt(pub)
203
203
  .andThen(changeFeed
@@ -216,7 +216,7 @@ export function makeRepo<
216
216
  set(e.id, undefined)
217
217
  }
218
218
  yield* $(
219
- Effect(events.toNonEmptyArray)
219
+ Effect.sync(() => events.toNonEmptyArray)
220
220
  // TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
221
221
  .flatMapOpt(pub)
222
222
  )
@@ -19,7 +19,7 @@ export class RequestContextContainer extends TagClass<RequestContextContainer, {
19
19
  .flatMap((requestContext) =>
20
20
  requestContext.isSome()
21
21
  ? requestContext.value.requestContext.map(Option.some)
22
- : Effect(Option.none)
22
+ : Effect.sync(() => Option.none)
23
23
  )
24
24
  }
25
25
  }
@@ -22,7 +22,7 @@ export class ContextMapContainer extends TagClass<ContextMapContainer, {
22
22
  .flatMap((ctx) =>
23
23
  ctx.isSome()
24
24
  ? ctx.value.get.map(Option.some)
25
- : Effect(Option.none)
25
+ : Effect.sync(() => Option.none)
26
26
  )
27
27
  }
28
28
  }
@@ -199,10 +199,11 @@ function makeCosmosStore({ prefix }: StorageConfig) {
199
199
  }
200
200
 
201
201
  const s: Store<PM, Id> = {
202
- all: Effect({
203
- query: `SELECT * FROM ${name} f WHERE f.id != @id`,
204
- parameters: [{ name: "@id", value: importedMarkerId }]
205
- })
202
+ all: Effect
203
+ .sync(() => ({
204
+ query: `SELECT * FROM ${name} f WHERE f.id != @id`,
205
+ parameters: [{ name: "@id", value: importedMarkerId }]
206
+ }))
206
207
  .tap((q) => logQuery(q))
207
208
  .flatMap((q) =>
208
209
  Effect.promise(() =>
@@ -223,7 +224,8 @@ function makeCosmosStore({ prefix }: StorageConfig) {
223
224
  filter
224
225
  .keys
225
226
  .forEachEffect((k) =>
226
- Effect(buildFilterJoinSelectCosmosQuery(filter, k, name, cursor?.skip, cursor?.limit))
227
+ Effect
228
+ .sync(() => buildFilterJoinSelectCosmosQuery(filter, k, name, cursor?.skip, cursor?.limit))
227
229
  .tap((q) => logQuery(q))
228
230
  .flatMap((q) =>
229
231
  Effect.promise(() =>
@@ -266,7 +268,8 @@ function makeCosmosStore({ prefix }: StorageConfig) {
266
268
  ? filter
267
269
  .keys
268
270
  .forEachEffect((k) =>
269
- Effect(buildFindJoinCosmosQuery(filter, k, name, skip, limit))
271
+ Effect
272
+ .sync(() => buildFindJoinCosmosQuery(filter, k, name, skip, limit))
270
273
  .tap((q) => logQuery(q))
271
274
  .flatMap((q) =>
272
275
  Effect.promise(() =>
@@ -280,15 +283,18 @@ function makeCosmosStore({ prefix }: StorageConfig) {
280
283
  )
281
284
  .map((_) => _.flatMap((_) => _))
282
285
  : (filter.type === "new-kid"
283
- ? Effect(buildWhereCosmosQuery3(
284
- filter.build(),
285
- name,
286
- importedMarkerId,
287
- defaultValues,
288
- f.select as NonEmptyReadonlyArray<string> | undefined,
289
- skip,
290
- limit
291
- ))
286
+ ? Effect
287
+ .sync(() =>
288
+ buildWhereCosmosQuery3(
289
+ filter.build(),
290
+ name,
291
+ importedMarkerId,
292
+ defaultValues,
293
+ f.select as NonEmptyReadonlyArray<string> | undefined,
294
+ skip,
295
+ limit
296
+ )
297
+ )
292
298
  .tap((q) => logQuery(q))
293
299
  .flatMap((q) =>
294
300
  Effect.promise(() =>
@@ -307,7 +313,8 @@ function makeCosmosStore({ prefix }: StorageConfig) {
307
313
  .then(({ resources }) => resources.map((_) => ({ ...defaultValues, ..._.f })))
308
314
  )
309
315
  )
310
- : Effect(buildCosmosQuery(filter, name, importedMarkerId, defaultValues, skip, limit))
316
+ : Effect
317
+ .sync(() => buildCosmosQuery(filter, name, importedMarkerId, defaultValues, skip, limit))
311
318
  .tap((q) => logQuery(q))
312
319
  .flatMap((q) =>
313
320
  Effect.promise(() =>
@@ -370,10 +377,10 @@ function makeCosmosStore({ prefix }: StorageConfig) {
370
377
  )
371
378
  )
372
379
  }
373
- return Effect({
380
+ return Effect.sync(() => ({
374
381
  ...e,
375
382
  _etag: x.etag
376
- })
383
+ }))
377
384
  })
378
385
  .withSpan("Cosmos.set [effect-app/infra/Store]", {
379
386
  attributes: { "repository.container_id": containerId, "repository.model_name": name }
@@ -403,7 +410,8 @@ function makeCosmosStore({ prefix }: StorageConfig) {
403
410
  if (seed) {
404
411
  const m = yield* $(seed)
405
412
  yield* $(
406
- Effect(m.toNonEmptyArray)
413
+ Effect
414
+ .succeed(m.toNonEmptyArray)
407
415
  .flatMapOpt((a) =>
408
416
  s
409
417
  .bulkSet(a)
@@ -64,7 +64,7 @@ function makeDiskStoreInt<Id extends string, PM extends PersistenceModelType<Id>
64
64
  const withPermit = sem.withPermits(1)
65
65
  const flushToDisk = store.all.flatMap(fsStore.setRaw).pipe(withPermit)
66
66
  const flushToDiskInBackground = flushToDisk
67
- .tapErrorCause((err) => Effect(console.error(err)))
67
+ .tapErrorCause((err) => Effect.sync(() => console.error(err)))
68
68
  .uninterruptible
69
69
  .forkDaemon
70
70
 
@@ -121,7 +121,7 @@ export function makeDiskStore({ prefix }: StorageConfig, dir: string) {
121
121
  return storesSem.withPermits(1)(
122
122
  Effect.suspend(() => {
123
123
  const existing = stores.get(namespace)
124
- if (existing) return Effect(existing)
124
+ if (existing) return Effect.sync(() => existing)
125
125
  return makeDiskStoreInt<Id, PM, R, E>(prefix, namespace, dir, name, seed, config?.defaultValues)
126
126
  .orDie
127
127
  .provide(ctx)
@@ -62,7 +62,7 @@ export function makeMemoryStoreInt<Id extends string, PM extends PersistenceMode
62
62
  ) {
63
63
  return Effect.gen(function*($) {
64
64
  const updateETag = makeUpdateETag(modelName)
65
- const items_ = yield* $(seed ?? Effect([]))
65
+ const items_ = yield* $(seed ?? Effect.sync(() => []))
66
66
  const defaultValues = _defaultValues ?? {}
67
67
 
68
68
  const items = new Map(items_.toChunk.map((_) => [_.id, { ...defaultValues, ..._ }] as const))
@@ -134,7 +134,7 @@ export function makeMemoryStoreInt<Id extends string, PM extends PersistenceMode
134
134
  }),
135
135
  batchSet: (items: readonly [PM, ...PM[]]) =>
136
136
  pipe(
137
- Effect(items)
137
+ Effect.sync(() => items)
138
138
  // align with CosmosDB
139
139
  .filterOrDieMessage((_) => _.length <= 100, "BatchSet: a batch may not exceed 100 items")
140
140
  .andThen(batchSet)
@@ -184,7 +184,7 @@ export const makeMemoryStore = () => ({
184
184
  }
185
185
  return storesSem.withPermits(1)(Effect.suspend(() => {
186
186
  const store = stores.get(namespace)
187
- if (store) return Effect(store)
187
+ if (store) return Effect.sync(() => store)
188
188
  return makeMemoryStoreInt(modelName, namespace, seed, config?.defaultValues)
189
189
  .orDie
190
190
  .provide(ctx)
@@ -21,7 +21,7 @@ function makeRedisStore({ prefix }: StorageConfig) {
21
21
  const key = `${prefix}${name}`
22
22
  const current = yield* $(redis.get(key).orDie)
23
23
  if (!current.isSome()) {
24
- const m = yield* $(seed ?? Effect([]))
24
+ const m = yield* $(seed ?? Effect.sync(() => []))
25
25
  yield* $(
26
26
  redis
27
27
  .set(key, JSON.stringify({ data: [...m].map((e) => makeETag(e)) }))
@@ -66,7 +66,7 @@ export const codeFilterStatement = <E>(p: FilterR, x: E) => {
66
66
  // }
67
67
  // return codeFilterStatement(p, x)
68
68
  // })
69
- // ? Option(x as unknown as NE)
69
+ // ? Option.some(x as unknown as NE)
70
70
  // : Option.none
71
71
 
72
72
  // export const and = <E extends { id: string }, NE extends E>(filters: readonly FilterResult[], x: E): Option<NE> =>
@@ -83,7 +83,7 @@ export const codeFilterStatement = <E>(p: FilterR, x: E) => {
83
83
  // }
84
84
  // return codeFilterStatement(p, x)
85
85
  // })
86
- // ? Option(x as unknown as NE)
86
+ // ? Option.some(x as unknown as NE)
87
87
  // : Option.none
88
88
 
89
89
  // // TODO: how to handle and/or outside scopes.
@@ -17,7 +17,7 @@ describe("Optimistic Concurrency", () => {
17
17
  { _etag: string | undefined; id: string; a: string }
18
18
  >()
19
19
  const { make } = makeMemoryStore()
20
- const store = yield* $(make("test", Effect(existing)))
20
+ const store = yield* $(make("test", Effect.sync(() => existing)))
21
21
 
22
22
  const result1 = yield* $(store.set({ id: "1", a: "string", _etag: undefined }))
23
23
  const result2_1 = yield* $(
@@ -51,7 +51,7 @@ describe("Optimistic Concurrency", () => {
51
51
  { _etag: string | undefined; id: string; a: string }
52
52
  >()
53
53
  const { make } = makeMemoryStore()
54
- const store = yield* $(make("test", Effect(existing)))
54
+ const store = yield* $(make("test", Effect.sync(() => existing)))
55
55
 
56
56
  const [result1] = yield* $(
57
57
  store.bulkSet([{ id: "1", a: "string", _etag: undefined }])
@@ -89,7 +89,7 @@ describe("Optimistic Concurrency", () => {
89
89
  { _etag: string | undefined; id: string; a: string }
90
90
  >()
91
91
  const { make } = makeMemoryStore()
92
- const store = yield* $(make("test", Effect(existing)))
92
+ const store = yield* $(make("test", Effect.sync(() => existing)))
93
93
 
94
94
  const item1 = { id: "1", a: "string", _etag: undefined }
95
95
  const item2 = { id: "2", a: "string", _etag: undefined }
@@ -102,8 +102,8 @@ describe("Optimistic Concurrency", () => {
102
102
  const failResult = yield* $(
103
103
  store.batchSet([{ id: "1", a: "another-string3", _etag: "abc" }]).result
104
104
  )
105
- expect(result1).toEqual(Option({ ...item1, _etag: expect.any(String) }))
106
- expect(result2).toEqual(Option({ ...item2, _etag: expect.any(String) }))
105
+ expect(result1).toEqual(Option.some({ ...item1, _etag: expect.any(String) }))
106
+ expect(result2).toEqual(Option.some({ ...item2, _etag: expect.any(String) }))
107
107
  expect(Exit.untraced(failResult)).toEqual(
108
108
  Exit.fail(new OptimisticConcurrencyException("test", "1"))
109
109
  )
@@ -40,22 +40,22 @@ export const makeUpdateETag =
40
40
  export function codeFilter<E extends { id: string }, NE extends E>(filter: Filter<NE>) {
41
41
  return (x: E) =>
42
42
  filter.type === "new-kid"
43
- ? codeFilter3_(filter.build(), x) ? Option(x as unknown as NE) : Option.none
43
+ ? codeFilter3_(filter.build(), x) ? Option.some(x as unknown as NE) : Option.none
44
44
  : filter.type === "startsWith"
45
45
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
46
  ? lowercaseIfString((x as any)[filter.by]).startsWith(filter.value.toLowerCase())
47
- ? Option(x as unknown as NE)
47
+ ? Option.some(x as unknown as NE)
48
48
  : Option.none
49
49
  : filter.type === "endsWith"
50
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
51
  ? lowercaseIfString((x as any)[filter.by]).endsWith(filter.value.toLowerCase())
52
- ? Option(x as unknown as NE)
52
+ ? Option.some(x as unknown as NE)
53
53
  : Option.none
54
54
  : filter.type === "contains"
55
55
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
56
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
57
57
  ? lowercaseIfString((x as any)[filter.by]).includes(filter.value.toLowerCase())
58
- ? Option(x as unknown as NE)
58
+ ? Option.some(x as unknown as NE)
59
59
  : Option.none
60
60
  : filter.type === "join_find"
61
61
  ? filter.keys.some((k) => {
@@ -66,7 +66,7 @@ export function codeFilter<E extends { id: string }, NE extends E>(filter: Filte
66
66
  && value.some((v) => compare(v[filter.valueKey], filter.value))
67
67
  )
68
68
  })
69
- ? Option(x as unknown as NE)
69
+ ? Option.some(x as unknown as NE)
70
70
  : Option.none
71
71
  // TODO: support mixed or/and
72
72
  : filter.mode === "or"
@@ -110,7 +110,7 @@ export function codeFilter<E extends { id: string }, NE extends E>(filter: Filte
110
110
  return compare(k, p.value)
111
111
  }
112
112
  })
113
- ? Option(x as unknown as NE)
113
+ ? Option.some(x as unknown as NE)
114
114
  : Option.none
115
115
  : filter
116
116
  .where
@@ -160,7 +160,7 @@ export function codeFilter<E extends { id: string }, NE extends E>(filter: Filte
160
160
  : compare(k, p.value)
161
161
  }
162
162
  })
163
- ? Option(x as unknown as NE)
163
+ ? Option.some(x as unknown as NE)
164
164
  : Option.none
165
165
  }
166
166
 
@@ -174,11 +174,11 @@ export function codeFilterJoinSelect<E extends { id: string }, NE>(
174
174
  const value = get(x, k)
175
175
  // we mimic the behavior of cosmosdb; if the shape in db does not match what we're looking for, we imagine false hit
176
176
  return value
177
- ? Option(
177
+ ? Option.some(
178
178
  (value as readonly NE[]).filterMap((v) =>
179
179
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
180
  compare((v as any)[filter.valueKey], filter.value)
181
- ? Option({ ...v, _rootId: x.id })
181
+ ? Option.some({ ...v, _rootId: x.id })
182
182
  : Option.none
183
183
  )
184
184
  )
@@ -133,7 +133,7 @@ export function createContext<TKey extends string, EA, A extends DBRecord<TKey>>
133
133
  function tryRead(filePath: string) {
134
134
  return fu
135
135
  .fileExists(filePath)
136
- .flatMap((exists) => !exists ? Effect(Option.none) : readFile(filePath).map(Option.some))
136
+ .flatMap((exists) => !exists ? Effect.sync(() => Option.none) : readFile(filePath).map(Option.some))
137
137
  }
138
138
 
139
139
  function getFilename(type: string, id: string) {
@@ -184,7 +184,7 @@ export function createContext<TKey extends string, EA, A extends DBRecord<TKey>>
184
184
  (err) =>
185
185
  err
186
186
  ? res(new ConnectionException(err))
187
- : res(Effect(void 0))
187
+ : res(Effect.sync(() => void 0))
188
188
  )
189
189
  })
190
190
  .uninterruptible