effect 4.0.0-beta.97 → 4.0.0-beta.98

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 (166) hide show
  1. package/dist/LayerRef.d.ts +4 -6
  2. package/dist/LayerRef.d.ts.map +1 -1
  3. package/dist/LayerRef.js +4 -6
  4. package/dist/LayerRef.js.map +1 -1
  5. package/dist/Number.d.ts.map +1 -1
  6. package/dist/Number.js +28 -10
  7. package/dist/Number.js.map +1 -1
  8. package/dist/Schema.d.ts +22 -22
  9. package/dist/Schema.d.ts.map +1 -1
  10. package/dist/Schema.js +36 -33
  11. package/dist/Schema.js.map +1 -1
  12. package/dist/SchemaAST.d.ts.map +1 -1
  13. package/dist/SchemaAST.js +25 -10
  14. package/dist/SchemaAST.js.map +1 -1
  15. package/dist/SchemaError.d.ts +53 -0
  16. package/dist/SchemaError.d.ts.map +1 -0
  17. package/dist/SchemaError.js +61 -0
  18. package/dist/SchemaError.js.map +1 -0
  19. package/dist/SchemaGetter.d.ts.map +1 -1
  20. package/dist/SchemaGetter.js +17 -12
  21. package/dist/SchemaGetter.js.map +1 -1
  22. package/dist/SchemaRepresentation.d.ts.map +1 -1
  23. package/dist/SchemaRepresentation.js +186 -224
  24. package/dist/SchemaRepresentation.js.map +1 -1
  25. package/dist/index.d.ts +8 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +8 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/internal/effect.js +26 -8
  30. package/dist/internal/effect.js.map +1 -1
  31. package/dist/internal/schema/equivalence.js +1 -2
  32. package/dist/internal/schema/equivalence.js.map +1 -1
  33. package/dist/internal/schema/representation.js +1 -3
  34. package/dist/internal/schema/representation.js.map +1 -1
  35. package/dist/internal/schema/schema.d.ts +0 -13
  36. package/dist/internal/schema/schema.d.ts.map +1 -1
  37. package/dist/internal/schema/schema.js +4 -29
  38. package/dist/internal/schema/schema.js.map +1 -1
  39. package/dist/unstable/ai/McpSchema.d.ts +128 -128
  40. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  41. package/dist/unstable/cli/CliError.d.ts +8 -16
  42. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  43. package/dist/unstable/cli/CliError.js +8 -16
  44. package/dist/unstable/cli/CliError.js.map +1 -1
  45. package/dist/unstable/cli/Command.d.ts +4 -3
  46. package/dist/unstable/cli/Command.d.ts.map +1 -1
  47. package/dist/unstable/cli/Command.js +3 -3
  48. package/dist/unstable/cli/Command.js.map +1 -1
  49. package/dist/unstable/cli/GlobalFlag.d.ts +6 -8
  50. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  51. package/dist/unstable/cli/GlobalFlag.js +6 -6
  52. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  53. package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
  54. package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
  55. package/dist/unstable/cluster/EntityProxyServer.js +2 -4
  56. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  57. package/dist/unstable/cluster/internal/entityManager.js +15 -12
  58. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  59. package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
  60. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  61. package/dist/unstable/httpapi/HttpApi.js +19 -20
  62. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  63. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
  64. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  65. package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
  66. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  67. package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
  68. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiClient.js +40 -30
  70. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
  72. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  73. package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
  74. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  75. package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
  76. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  77. package/dist/unstable/httpapi/HttpApiError.js +31 -0
  78. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  79. package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
  80. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  81. package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
  82. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  83. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
  84. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  85. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  86. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  87. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  88. package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
  89. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  90. package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
  91. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  92. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  93. package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
  94. package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
  95. package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
  96. package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
  97. package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
  98. package/dist/unstable/httpapi/HttpApiTest.js +9 -8
  99. package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
  100. package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
  101. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  102. package/dist/unstable/httpapi/OpenApi.js +77 -37
  103. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  104. package/dist/unstable/httpapi/internal/html.js +6 -2
  105. package/dist/unstable/httpapi/internal/html.js.map +1 -1
  106. package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
  107. package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
  108. package/dist/unstable/httpapi/internal/mediaType.js +7 -0
  109. package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
  110. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  111. package/dist/unstable/persistence/PersistedQueue.js +16 -12
  112. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  113. package/dist/unstable/reactivity/Atom.js +1 -1
  114. package/dist/unstable/reactivity/Atom.js.map +1 -1
  115. package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
  116. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  117. package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
  118. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  119. package/dist/unstable/rpc/RpcServer.d.ts +3 -1
  120. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  121. package/dist/unstable/rpc/RpcServer.js +6 -3
  122. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  123. package/dist/unstable/workflow/DurableDeferred.js +1 -1
  124. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  125. package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
  126. package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
  127. package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
  128. package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
  129. package/package.json +1 -1
  130. package/src/LayerRef.ts +4 -6
  131. package/src/Number.ts +29 -10
  132. package/src/Schema.ts +42 -34
  133. package/src/SchemaAST.ts +25 -13
  134. package/src/SchemaError.ts +64 -0
  135. package/src/SchemaGetter.ts +22 -16
  136. package/src/SchemaRepresentation.ts +165 -202
  137. package/src/index.ts +10 -0
  138. package/src/internal/effect.ts +39 -22
  139. package/src/internal/schema/equivalence.ts +1 -2
  140. package/src/internal/schema/representation.ts +4 -4
  141. package/src/internal/schema/schema.ts +4 -37
  142. package/src/unstable/cli/CliError.ts +24 -16
  143. package/src/unstable/cli/Command.ts +8 -8
  144. package/src/unstable/cli/GlobalFlag.ts +22 -33
  145. package/src/unstable/cluster/EntityProxyServer.ts +15 -17
  146. package/src/unstable/cluster/internal/entityManager.ts +48 -34
  147. package/src/unstable/httpapi/HttpApi.ts +72 -47
  148. package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
  149. package/src/unstable/httpapi/HttpApiClient.ts +196 -151
  150. package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
  151. package/src/unstable/httpapi/HttpApiError.ts +33 -0
  152. package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
  153. package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
  154. package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
  155. package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
  156. package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
  157. package/src/unstable/httpapi/HttpApiTest.ts +15 -14
  158. package/src/unstable/httpapi/OpenApi.ts +74 -36
  159. package/src/unstable/httpapi/internal/html.ts +9 -2
  160. package/src/unstable/httpapi/internal/mediaType.ts +6 -0
  161. package/src/unstable/persistence/PersistedQueue.ts +16 -14
  162. package/src/unstable/reactivity/Atom.ts +1 -1
  163. package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
  164. package/src/unstable/rpc/RpcServer.ts +10 -4
  165. package/src/unstable/workflow/DurableDeferred.ts +1 -1
  166. package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
@@ -1,10 +1,9 @@
1
1
  import * as Cause from "../../Cause.ts"
2
- import * as Data from "../../Data.ts"
3
2
  import * as Effect from "../../Effect.ts"
4
- import * as Exit from "../../Exit.ts"
5
3
  import * as Pipeable from "../../Pipeable.ts"
6
4
  import type * as Schema from "../../Schema.ts"
7
5
  import * as SchemaAST from "../../SchemaAST.ts"
6
+ import { SchemaError } from "../../SchemaError.ts"
8
7
  import type { Issue } from "../../SchemaIssue.ts"
9
8
  import * as SchemaParser from "../../SchemaParser.ts"
10
9
 
@@ -35,34 +34,16 @@ export function make<S extends Schema.Constraint>(ast: S["ast"], options?: objec
35
34
  }
36
35
  self.ast = ast
37
36
  self.rebuild = (ast: SchemaAST.AST) => make(ast, options)
37
+ const makeEffect = SchemaParser.makeEffect(self)
38
38
  self.makeEffect = (input: S["~type.make.in"], options?: Schema.MakeOptions) =>
39
- mapSchemaIssueEffect(SchemaParser.makeEffect(self)(input, options))
39
+ fromIssueEffect(makeEffect(input, options))
40
40
  self.make = SchemaParser.make(self)
41
41
  self.makeOption = SchemaParser.makeOption(self)
42
42
  return self
43
43
  }
44
44
 
45
45
  /** @internal */
46
- export const SchemaErrorTypeId = "~effect/Schema/SchemaError"
47
-
48
- // purposefully not internal
49
- export class SchemaError extends Data.TaggedError("SchemaError")<{
50
- readonly issue: Issue
51
- }> {
52
- readonly [SchemaErrorTypeId]: typeof SchemaErrorTypeId = SchemaErrorTypeId
53
- constructor(issue: Issue) {
54
- super({ issue })
55
- }
56
- override get message() {
57
- return this.issue.toString()
58
- }
59
- override toString() {
60
- return `SchemaError(${this.message})`
61
- }
62
- }
63
-
64
- /** @internal */
65
- export function mapSchemaIssueEffect<A, R>(
46
+ export function fromIssueEffect<A, R>(
66
47
  self: Effect.Effect<A, Issue, R>
67
48
  ): Effect.Effect<A, SchemaError, R> {
68
49
  return Effect.catchCause(
@@ -71,20 +52,6 @@ export function mapSchemaIssueEffect<A, R>(
71
52
  )
72
53
  }
73
54
 
74
- /** @internal */
75
- export function mapSchemaErrorEffect<A, R>(
76
- self: Effect.Effect<A, SchemaError, R>
77
- ): Effect.Effect<A, Issue, R> {
78
- return Effect.catchCause(self, (cause) => Effect.failCauseSync(() => Cause.map(cause, (error) => error.issue)))
79
- }
80
-
81
- /** @internal */
82
- export function mapSchemaIssueExit<A>(exit: Exit.Exit<A, Issue>): Exit.Exit<A, SchemaError> {
83
- return Exit.isSuccess(exit)
84
- ? Exit.succeed(exit.value)
85
- : Exit.failCause(Cause.map(exit.cause, (issue) => new SchemaError(issue)))
86
- }
87
-
88
55
  /** @internal */
89
56
  export const jsonReorder = makeReorder(getJsonPriority)
90
57
 
@@ -127,8 +127,9 @@ export type CliError =
127
127
  * @category models
128
128
  * @since 4.0.0
129
129
  */
130
- export class UnrecognizedOption extends Schema.ErrorClass<UnrecognizedOption>(`${TypeId}/UnrecognizedOption`)({
131
- _tag: Schema.tag("UnrecognizedOption"),
130
+ export class UnrecognizedOption extends Schema.TaggedErrorClass<UnrecognizedOption>(
131
+ `${TypeId}/UnrecognizedOption`
132
+ )("UnrecognizedOption", {
132
133
  option: Schema.String,
133
134
  command: Schema.optional(Schema.Array(Schema.String)),
134
135
  suggestions: Schema.Array(Schema.String)
@@ -178,8 +179,9 @@ export class UnrecognizedOption extends Schema.ErrorClass<UnrecognizedOption>(`$
178
179
  * @category models
179
180
  * @since 4.0.0
180
181
  */
181
- export class DuplicateOption extends Schema.ErrorClass<DuplicateOption>(`${TypeId}/DuplicateOption`)({
182
- _tag: Schema.tag("DuplicateOption"),
182
+ export class DuplicateOption extends Schema.TaggedErrorClass<DuplicateOption>(
183
+ `${TypeId}/DuplicateOption`
184
+ )("DuplicateOption", {
183
185
  option: Schema.String,
184
186
  parentCommand: Schema.String,
185
187
  childCommand: Schema.String
@@ -232,8 +234,9 @@ export class DuplicateOption extends Schema.ErrorClass<DuplicateOption>(`${TypeI
232
234
  * @category models
233
235
  * @since 4.0.0
234
236
  */
235
- export class MissingOption extends Schema.ErrorClass<MissingOption>(`${TypeId}/MissingOption`)({
236
- _tag: Schema.tag("MissingOption"),
237
+ export class MissingOption extends Schema.TaggedErrorClass<MissingOption>(
238
+ `${TypeId}/MissingOption`
239
+ )("MissingOption", {
237
240
  option: Schema.String
238
241
  }) {
239
242
  /**
@@ -282,8 +285,9 @@ export class MissingOption extends Schema.ErrorClass<MissingOption>(`${TypeId}/M
282
285
  * @category models
283
286
  * @since 4.0.0
284
287
  */
285
- export class MissingArgument extends Schema.ErrorClass<MissingArgument>(`${TypeId}/MissingArgument`)({
286
- _tag: Schema.tag("MissingArgument"),
288
+ export class MissingArgument extends Schema.TaggedErrorClass<MissingArgument>(
289
+ `${TypeId}/MissingArgument`
290
+ )("MissingArgument", {
287
291
  argument: Schema.String
288
292
  }) {
289
293
  /**
@@ -337,8 +341,9 @@ export class MissingArgument extends Schema.ErrorClass<MissingArgument>(`${TypeI
337
341
  * @category models
338
342
  * @since 4.0.0
339
343
  */
340
- export class InvalidValue extends Schema.ErrorClass<InvalidValue>(`${TypeId}/InvalidValue`)({
341
- _tag: Schema.tag("InvalidValue"),
344
+ export class InvalidValue extends Schema.TaggedErrorClass<InvalidValue>(
345
+ `${TypeId}/InvalidValue`
346
+ )("InvalidValue", {
342
347
  option: Schema.String,
343
348
  value: Schema.String,
344
349
  expected: Schema.String,
@@ -400,8 +405,9 @@ export class InvalidValue extends Schema.ErrorClass<InvalidValue>(`${TypeId}/Inv
400
405
  * @category models
401
406
  * @since 4.0.0
402
407
  */
403
- export class UnknownSubcommand extends Schema.ErrorClass<UnknownSubcommand>(`${TypeId}/UnknownSubcommand`)({
404
- _tag: Schema.tag("UnknownSubcommand"),
408
+ export class UnknownSubcommand extends Schema.TaggedErrorClass<UnknownSubcommand>(
409
+ `${TypeId}/UnknownSubcommand`
410
+ )("UnknownSubcomand", {
405
411
  subcommand: Schema.String,
406
412
  parent: Schema.optional(Schema.Array(Schema.String)),
407
413
  suggestions: Schema.Array(Schema.String)
@@ -464,8 +470,9 @@ export class UnknownSubcommand extends Schema.ErrorClass<UnknownSubcommand>(`${T
464
470
  * @category models
465
471
  * @since 4.0.0
466
472
  */
467
- export class UserError extends Schema.ErrorClass<UserError>(`${TypeId}/UserError`)({
468
- _tag: Schema.tag("UserError"),
473
+ export class UserError extends Schema.TaggedErrorClass<UserError>(
474
+ `${TypeId}/UserError`
475
+ )("UserError", {
469
476
  cause: Schema.Defect()
470
477
  }) {
471
478
  /**
@@ -533,8 +540,9 @@ export type NonShowHelpErrors = typeof NonShowHelpErrors.Type
533
540
  * @category models
534
541
  * @since 4.0.0
535
542
  */
536
- export class ShowHelp extends Schema.ErrorClass<ShowHelp>(`${TypeId}/ShowHelp`)({
537
- _tag: Schema.tag("ShowHelp"),
543
+ export class ShowHelp extends Schema.TaggedErrorClass<ShowHelp>(
544
+ `${TypeId}/ShowHelp`
545
+ )("ShowHelp", {
538
546
  commandPath: Schema.Array(Schema.String),
539
547
  errors: Schema.Array(NonShowHelpErrors)
540
548
  }) {
@@ -697,7 +697,7 @@ export const make: {
697
697
  name: Name,
698
698
  config: Config,
699
699
  handler: (config: Command.Config.Infer<Config>) => Effect.Effect<void, E, R>
700
- ): Command<Name, Command.Config.Infer<Config>, {}, E, Exclude<R, GlobalFlag.BuiltInSettingContext>>
700
+ ): Command<Name, Command.Config.Infer<Config>, {}, E, Exclude<R, BuiltInSettingContext>>
701
701
  } = ((
702
702
  name: string,
703
703
  config?: Command.Config,
@@ -772,7 +772,7 @@ export const withHandler: {
772
772
  */
773
773
  <A, R, E>(handler: (value: A) => Effect.Effect<void, E, R>): <Name extends string, XR, XE, ContextInput>(
774
774
  self: Command<Name, A, ContextInput, XE, XR>
775
- ) => Command<Name, A, ContextInput, E, Exclude<R, GlobalFlag.BuiltInSettingContext>>
775
+ ) => Command<Name, A, ContextInput, E, Exclude<R, BuiltInSettingContext>>
776
776
  /* ========================================================================== */
777
777
  /* Combinators */
778
778
  /* ========================================================================== */
@@ -805,11 +805,11 @@ export const withHandler: {
805
805
  <Name extends string, A, XR, XE, R, E, ContextInput>(
806
806
  self: Command<Name, A, ContextInput, XE, XR>,
807
807
  handler: (value: A) => Effect.Effect<void, E, R>
808
- ): Command<Name, A, ContextInput, E, Exclude<R, GlobalFlag.BuiltInSettingContext>>
808
+ ): Command<Name, A, ContextInput, E, Exclude<R, BuiltInSettingContext>>
809
809
  } = dual(2, <Name extends string, A, XR, XE, R, E, ContextInput>(
810
810
  self: Command<Name, A, ContextInput, XE, XR>,
811
811
  handler: (value: A) => Effect.Effect<void, E, R>
812
- ): Command<Name, A, ContextInput, E, Exclude<R, GlobalFlag.BuiltInSettingContext>> =>
812
+ ): Command<Name, A, ContextInput, E, Exclude<R, BuiltInSettingContext>> =>
813
813
  makeCommand({ ...toImpl(self), handle: handler } as any))
814
814
 
815
815
  interface SubcommandGroupInternal {
@@ -1272,6 +1272,7 @@ type ExtractGlobalFlagContext<T extends ReadonlyArray<GlobalFlag.GlobalFlag<any>
1272
1272
  ? F extends GlobalFlag.Setting<infer Id, infer _A> ? GlobalFlag.Setting.Identifier<Id>
1273
1273
  : never
1274
1274
  : never
1275
+ type BuiltInSettingContext = ExtractGlobalFlagContext<typeof GlobalFlag.BuiltIns>
1275
1276
  type ExtractSubcommand<T> = T extends Command<infer _Name, infer _Input, infer _CI, infer _E, infer _R> ? T
1276
1277
  : T extends Command.SubcommandGroup<infer Commands> ? Commands[number]
1277
1278
  : never
@@ -2352,15 +2353,14 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
2352
2353
 
2353
2354
  // 7. Provide setting values
2354
2355
  let program = commandImpl.handle(parseResult.success, [command.name])
2356
+ const [, logLevel] = yield* GlobalFlag.LogLevel.flag.parse(emptyArgs)
2357
+ program = Effect.provideService(program, GlobalFlag.LogLevel, logLevel)
2355
2358
  for (const flag of activeFlags) {
2356
- if (flag._tag !== "Setting") continue
2359
+ if (flag._tag !== "Setting" || flag === GlobalFlag.LogLevel) continue
2357
2360
  const [, value] = yield* flag.flag.parse(emptyArgs)
2358
2361
  program = Effect.provideService(program, flag, value)
2359
2362
  }
2360
2363
 
2361
- const [, logLevel] = yield* GlobalFlag.LogLevel.flag.parse(emptyArgs)
2362
- program = Effect.provideService(program, GlobalFlag.LogLevel, logLevel)
2363
-
2364
2364
  // 8. Apply built-in setting behavior
2365
2365
  const services = Option.match(logLevel, {
2366
2366
  onNone: () => Context.empty(),
@@ -156,12 +156,11 @@ export const Help: Action<boolean> = action({
156
156
  Flag.withAlias("h"),
157
157
  Flag.withDescription("Show help information")
158
158
  ),
159
- run: (_, { command, commandPath }) =>
160
- Effect.gen(function*() {
161
- const formatter = yield* CliOutput.Formatter
162
- const helpDoc = yield* HelpInternal.getHelpForCommandPath(command, commandPath, BuiltIns)
163
- yield* Console.log(formatter.formatHelpDoc(helpDoc))
164
- })
159
+ run: Effect.fnUntraced(function*(_, { command, commandPath }) {
160
+ const formatter = yield* CliOutput.Formatter
161
+ const helpDoc = yield* HelpInternal.getHelpForCommandPath(command, commandPath, BuiltIns)
162
+ yield* Console.log(formatter.formatHelpDoc(helpDoc))
163
+ })
165
164
  })
166
165
 
167
166
  /**
@@ -179,11 +178,10 @@ export const Version: Action<boolean> = action({
179
178
  Flag.withAlias("v"),
180
179
  Flag.withDescription("Show version information")
181
180
  ),
182
- run: (_, { command, version }) =>
183
- Effect.gen(function*() {
184
- const formatter = yield* CliOutput.Formatter
185
- yield* Console.log(formatter.formatVersion(command.name, version))
186
- })
181
+ run: Effect.fnUntraced(function*(_, { command, version }) {
182
+ const formatter = yield* CliOutput.Formatter
183
+ yield* Console.log(formatter.formatVersion(command.name, version))
184
+ })
187
185
  })
188
186
 
189
187
  /**
@@ -206,14 +204,13 @@ export const Completions: Action<Option.Option<"bash" | "zsh" | "fish">> = actio
206
204
  Flag.withMetavar("<bash|zsh|fish|sh>"),
207
205
  Flag.withDescription("Print shell completion script")
208
206
  ),
209
- run: (shell, { command }) =>
210
- Effect.gen(function*() {
211
- if (Option.isNone(shell)) return
212
- const descriptor = CommandDescriptor.fromCommand(command)
213
- yield* Console.log(
214
- Completions_.generate(command.name, shell.value, descriptor)
215
- )
216
- })
207
+ run: Effect.fnUntraced(function*(shell, { command }) {
208
+ if (Option.isNone(shell)) return
209
+ const descriptor = CommandDescriptor.fromCommand(command)
210
+ yield* Console.log(
211
+ Completions_.generate(command.name, shell.value, descriptor)
212
+ )
213
+ })
217
214
  })
218
215
 
219
216
  /**
@@ -279,17 +276,9 @@ export const LogLevel: Setting<"log-level", Option.Option<LogLevelType>> = setti
279
276
  * @category references
280
277
  * @since 4.0.0
281
278
  */
282
- export const BuiltIns: ReadonlyArray<GlobalFlag<any>> = [
283
- Help,
284
- Version,
285
- Completions,
286
- LogLevel
287
- ]
288
-
289
- /**
290
- * Built-in setting context identifiers.
291
- *
292
- * @category models
293
- * @since 4.0.0
294
- */
295
- export type BuiltInSettingContext = Setting.Identifier<"log-level">
279
+ export const BuiltIns: readonly [
280
+ Action<boolean>,
281
+ Action<boolean>,
282
+ Action<Option.Option<"bash" | "zsh" | "fish">>,
283
+ Setting<"log-level", Option.Option<LogLevelType>>
284
+ ] = [Help, Version, Completions, LogLevel]
@@ -34,27 +34,25 @@ import type { Sharding } from "./Sharding.ts"
34
34
  */
35
35
  export const layerHttpApi = <
36
36
  ApiId extends string,
37
- Groups extends HttpApiGroup.Any,
38
- Name extends HttpApiGroup.Name<Groups>,
37
+ Groups extends HttpApiGroup.Constraint,
38
+ Identifier extends HttpApiGroup.Identifier<Groups>,
39
39
  Type extends string,
40
40
  Rpcs extends Rpc.Any
41
41
  >(
42
42
  api: HttpApi.HttpApi<ApiId, Groups>,
43
- name: Name,
43
+ identifier: Identifier,
44
44
  entity: Entity.Entity<Type, Rpcs>
45
- ): Layer.Layer<HttpApiGroup.ApiGroup<ApiId, Name>, never, Sharding | Rpc.ServicesServer<Rpcs>> =>
45
+ ): Layer.Layer<HttpApiGroup.Service<ApiId, Identifier>, never, Sharding | Rpc.ServicesServer<Rpcs>> =>
46
46
  HttpApiBuilder.group(
47
47
  api,
48
- name,
49
- Effect.fnUntraced(function*(handlers_) {
48
+ identifier,
49
+ Effect.fnUntraced(function*(handlers: any) {
50
50
  const client = yield* entity.client
51
- let handlers = handlers_
52
- for (const parentRpc_ of entity.protocol.requests.values()) {
53
- const parentRpc = parentRpc_ as any as Rpc.AnyWithProps
51
+ for (const parentRpc of entity.protocol.requests.values()) {
54
52
  handlers = handlers
55
53
  .handle(
56
- parentRpc._tag as any,
57
- (({ params, payload }: { params: { entityId: string }; payload: any }) =>
54
+ parentRpc._tag,
55
+ ({ params, payload }: { params: { entityId: string }; payload: any }) =>
58
56
  (client(params.entityId) as any as Record<string, (p: any) => Effect.Effect<any>>)[parentRpc._tag](
59
57
  payload
60
58
  ).pipe(
@@ -65,11 +63,11 @@ export const layerHttpApi = <
65
63
  entityId: params.entityId,
66
64
  method: parentRpc._tag
67
65
  })
68
- )) as any
66
+ )
69
67
  )
70
68
  .handle(
71
- `${parentRpc._tag}Discard` as any,
72
- (({ params, payload }: { params: { entityId: string }; payload: any }) =>
69
+ `${parentRpc._tag}Discard`,
70
+ ({ params, payload }: { params: { entityId: string }; payload: any }) =>
73
71
  (client(params.entityId) as any as Record<string, (p: any, o: {}) => Effect.Effect<any>>)[parentRpc._tag](
74
72
  payload,
75
73
  { discard: true }
@@ -81,10 +79,10 @@ export const layerHttpApi = <
81
79
  entityId: params.entityId,
82
80
  method: `${parentRpc._tag}Discard`
83
81
  })
84
- )) as any
85
- ) as any
82
+ )
83
+ )
86
84
  }
87
- return handlers as HttpApiBuilder.Handlers<never, never>
85
+ return handlers as HttpApiBuilder.Handlers<never>
88
86
  })
89
87
  )
90
88
 
@@ -207,15 +207,21 @@ export const make = Effect.fnUntraced(function*<
207
207
  (isShuttingDown || isUninterruptibleForServer(request.message.annotations))
208
208
  ) {
209
209
  if (!isShuttingDown) {
210
- return server.write(0, {
211
- ...request.message.envelope,
212
- id: request.message.envelope.requestId as any,
213
- tag: request.message.envelope.tag as any,
214
- payload: new Request({
210
+ return server.write(
211
+ 0,
212
+ {
215
213
  ...request.message.envelope,
216
- lastSentChunk: request.lastSentChunk
217
- } as any) as any
218
- }).pipe(
214
+ id: request.message.envelope.requestId as any,
215
+ tag: request.message.envelope.tag as any,
216
+ payload: new Request({
217
+ ...request.message.envelope,
218
+ lastSentChunk: request.lastSentChunk
219
+ } as any) as any
220
+ },
221
+ Context.get(request.rpc.annotations, WithTransaction)
222
+ ? { onRequest: options.storage.withTransaction }
223
+ : undefined
224
+ ).pipe(
219
225
  Effect.forkIn(scope)
220
226
  )
221
227
  }
@@ -295,16 +301,22 @@ export const make = Effect.fnUntraced(function*<
295
301
  for (const id of defectRequestIds) {
296
302
  const request = activeRequests.get(id)
297
303
  if (!request) continue
298
- const { lastSentChunk, message } = request
299
- yield* server.write(0, {
300
- ...message.envelope,
301
- id: message.envelope.requestId as any,
302
- tag: message.envelope.tag as any,
303
- payload: new Request({
304
+ const { lastSentChunk, message, rpc } = request
305
+ yield* server.write(
306
+ 0,
307
+ {
304
308
  ...message.envelope,
305
- lastSentChunk
306
- } as any) as any
307
- })
309
+ id: message.envelope.requestId as any,
310
+ tag: message.envelope.tag as any,
311
+ payload: new Request({
312
+ ...message.envelope,
313
+ lastSentChunk
314
+ } as any) as any
315
+ },
316
+ Context.get(rpc.annotations, WithTransaction)
317
+ ? { onRequest: options.storage.withTransaction }
318
+ : undefined
319
+ )
308
320
  }
309
321
  defectRequestIds.clear()
310
322
  }
@@ -341,11 +353,11 @@ export const make = Effect.fnUntraced(function*<
341
353
  const state: EntityState = {
342
354
  scope,
343
355
  address,
344
- write(clientId, message) {
356
+ write(clientId, message, writeOptions) {
345
357
  if (writeRef.state.current._tag !== "Acquired") {
346
- return Effect.flatMap(writeRef.await, (write) => write(clientId, message))
358
+ return Effect.flatMap(writeRef.await, (write) => write(clientId, message, writeOptions))
347
359
  }
348
- return writeRef.state.current.value(clientId, message)
360
+ return writeRef.state.current.value(clientId, message, writeOptions)
349
361
  },
350
362
  activeRequests,
351
363
  lastActiveCheck: clock.currentTimeMillisUnsafe(),
@@ -472,21 +484,23 @@ export const make = Effect.fnUntraced(function*<
472
484
  })
473
485
  }
474
486
  server.activeRequests.set(message.envelope.requestId, entry)
475
- let write = server.write(0, {
476
- ...message.envelope,
477
- id: message.envelope.requestId as any,
478
- payload: new Request({
487
+ return server.write(
488
+ 0,
489
+ {
479
490
  ...message.envelope,
480
- lastSentChunk: Option.filter(
481
- message.lastSentReply,
482
- (reply): reply is Reply.Chunk<R> => reply._tag === "Chunk"
483
- )
484
- })
485
- })
486
- if (Context.get(message.annotations, WithTransaction)) {
487
- write = options.storage.withTransaction(write)
488
- }
489
- return write
491
+ id: message.envelope.requestId as any,
492
+ payload: new Request({
493
+ ...message.envelope,
494
+ lastSentChunk: Option.filter(
495
+ message.lastSentReply,
496
+ (reply): reply is Reply.Chunk<R> => reply._tag === "Chunk"
497
+ )
498
+ })
499
+ },
500
+ Context.get(message.annotations, WithTransaction)
501
+ ? { onRequest: options.storage.withTransaction }
502
+ : undefined
503
+ )
490
504
  }
491
505
  case "IncomingEnvelope": {
492
506
  const entry = server.activeRequests.get(message.envelope.requestId)