@effect-app/vue 2.94.0 → 4.0.0-beta.1

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 (64) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/errorReporter.d.ts +2 -2
  3. package/dist/errorReporter.d.ts.map +1 -1
  4. package/dist/errorReporter.js +9 -9
  5. package/dist/experimental/commander.d.ts +49 -69
  6. package/dist/experimental/commander.d.ts.map +1 -1
  7. package/dist/experimental/commander.js +27 -29
  8. package/dist/experimental/confirm.d.ts +11 -5
  9. package/dist/experimental/confirm.d.ts.map +1 -1
  10. package/dist/experimental/confirm.js +19 -6
  11. package/dist/experimental/intl.d.ts +2 -21
  12. package/dist/experimental/intl.d.ts.map +1 -1
  13. package/dist/experimental/intl.js +4 -4
  14. package/dist/experimental/makeUseCommand.js +2 -2
  15. package/dist/experimental/toast.d.ts +3 -35
  16. package/dist/experimental/toast.d.ts.map +1 -1
  17. package/dist/experimental/toast.js +19 -5
  18. package/dist/experimental/withToast.d.ts +6 -4
  19. package/dist/experimental/withToast.d.ts.map +1 -1
  20. package/dist/experimental/withToast.js +10 -8
  21. package/dist/form.d.ts +2 -2
  22. package/dist/form.d.ts.map +1 -1
  23. package/dist/form.js +47 -47
  24. package/dist/lib.d.ts +1 -1
  25. package/dist/lib.d.ts.map +1 -1
  26. package/dist/lib.js +12 -10
  27. package/dist/makeClient.d.ts +31 -28
  28. package/dist/makeClient.d.ts.map +1 -1
  29. package/dist/makeClient.js +31 -32
  30. package/dist/mutate.d.ts +5 -5
  31. package/dist/mutate.d.ts.map +1 -1
  32. package/dist/mutate.js +14 -14
  33. package/dist/query.d.ts +16 -14
  34. package/dist/query.d.ts.map +1 -1
  35. package/dist/query.js +37 -28
  36. package/dist/routeParams.d.ts +2 -4
  37. package/dist/routeParams.d.ts.map +1 -1
  38. package/dist/routeParams.js +3 -15
  39. package/dist/runtime.d.ts +1 -1
  40. package/dist/runtime.d.ts.map +1 -1
  41. package/dist/runtime.js +4 -4
  42. package/package.json +19 -20
  43. package/src/errorReporter.ts +11 -11
  44. package/src/experimental/commander.ts +83 -86
  45. package/src/experimental/confirm.ts +21 -6
  46. package/src/experimental/intl.ts +3 -3
  47. package/src/experimental/makeUseCommand.ts +1 -1
  48. package/src/experimental/toast.ts +23 -4
  49. package/src/experimental/withToast.ts +10 -7
  50. package/src/form.ts +56 -64
  51. package/src/lib.ts +11 -9
  52. package/src/makeClient.ts +70 -63
  53. package/src/mutate.ts +18 -19
  54. package/src/query.ts +56 -49
  55. package/src/routeParams.ts +9 -23
  56. package/src/runtime.ts +6 -6
  57. package/test/Mutation.test.ts +52 -53
  58. package/test/dist/form.test.d.ts.map +1 -1
  59. package/test/dist/stubs.d.ts +103 -45
  60. package/test/dist/stubs.d.ts.map +1 -1
  61. package/test/dist/stubs.js +8 -8
  62. package/test/form.test.ts +7 -6
  63. package/test/stubs.ts +43 -41
  64. package/tsconfig.json +1 -27
@@ -1,14 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { asResult, type MissingDependencies, reportRuntimeError } from "@effect-app/vue"
3
3
  import { reportMessage } from "@effect-app/vue/errorReporter"
4
- import { type Result } from "@effect-atom/atom/Result"
5
- import { Cause, Context, Effect, type Exit, flow, type Layer, Match, MutableHashMap, Option, Runtime, S, Utils } from "effect-app"
4
+ import { type AsyncResult } from "effect/unstable/reactivity/AsyncResult"
5
+ import { Cause, Effect, type Exit, type Fiber, flow, Layer, Match, MutableHashMap, Option, S, ServiceMap } from "effect-app"
6
6
  import { SupportedErrors } from "effect-app/client"
7
7
  import { OperationFailure, OperationSuccess } from "effect-app/Operations"
8
8
  import { wrapEffect } from "effect-app/utils"
9
- import { id, type RuntimeFiber } from "effect/Fiber"
10
- import { type NoInfer } from "effect/Types"
11
- import { isGeneratorFunction, type YieldWrap } from "effect/Utils"
9
+ import { isGeneratorFunction } from "effect/Utils"
12
10
  import { type FormatXMLElementFn, type PrimitiveType } from "intl-messageformat"
13
11
  import { computed, type ComputedRef, reactive, ref } from "vue"
14
12
  import { Confirm } from "./confirm.js"
@@ -69,18 +67,17 @@ export const DefaultIntl = {
69
67
  }
70
68
  }
71
69
 
72
- export class CommandContext extends Effect.Tag("CommandContext")<
73
- CommandContext,
74
- {
75
- id: string
76
- i18nKey: string
77
- action: string
78
- label: string
79
- namespace: string
80
- namespaced: (key: string) => string
81
- state?: IntlRecord | undefined
82
- }
83
- >() {}
70
+ export class CommandContext extends ServiceMap.Service<CommandContext, {
71
+ id: string
72
+ i18nKey: string
73
+ action: string
74
+ label: string
75
+ namespace: string
76
+ namespaced: (key: string) => string
77
+ state?: IntlRecord | undefined
78
+ }>()(
79
+ "CommandContext"
80
+ ) {}
84
81
 
85
82
  export type EmitWithCallback<A, Event extends string> = (event: Event, value: A, onDone: () => void) => void
86
83
 
@@ -100,7 +97,7 @@ export declare namespace Commander {
100
97
  & NonGen<RT, Id, I18nKey, State>
101
98
  & CommandContextLocal<Id, I18nKey>
102
99
  & {
103
- state: Context.Tag<`Commander.Command.${Id}.state`, State>
100
+ state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>
104
101
  }
105
102
 
106
103
  export type CommanderFn<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> =
@@ -120,7 +117,7 @@ export declare namespace Commander {
120
117
  & GenWrap<RT, Id, I18nCustomKey, I, A, E, R, State>
121
118
  & NonGenWrap<RT, Id, I18nCustomKey, I, A, E, R, State>
122
119
  & {
123
- state: Context.Tag<`Commander.Command.${Id}.state`, State>
120
+ state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>
124
121
  }
125
122
 
126
123
  export interface CommandContextLocal<Id extends string, I18nKey extends string> {
@@ -142,7 +139,7 @@ export declare namespace Commander {
142
139
  /** reactive */
143
140
  label: string
144
141
  /** reactive */
145
- result: Result<A, E>
142
+ result: AsyncResult<A, E>
146
143
  /** reactive */
147
144
  waiting: boolean
148
145
  /** reactive */
@@ -165,7 +162,7 @@ export declare namespace Commander {
165
162
  new(): {}
166
163
 
167
164
  /** click handlers */
168
- handle: ((arg: Arg) => RuntimeFiber<Exit.Exit<A, E>, never>) & {
165
+ handle: ((arg: Arg) => Fiber.Fiber<Exit.Exit<A, E>, never>) & {
169
166
  /** @deprecated don't exist */
170
167
  effect: (arg: Arg) => Effect.Effect<A, E, R>
171
168
  }
@@ -179,7 +176,7 @@ export declare namespace Commander {
179
176
  // * @experimental
180
177
  // * captures the current span and returns an Effect that when run will execute the command
181
178
  // */
182
- // handleEffect: (arg: Arg) => Effect.Effect<RuntimeFiber<Exit.Exit<A, E>, never>>
179
+ // handleEffect: (arg: Arg) => Effect.Effect<Fiber.Fiber<Exit.Exit<A, E>, never>>
183
180
  // /**
184
181
  // * @experimental
185
182
  // */
@@ -200,9 +197,9 @@ export declare namespace Commander {
200
197
  State extends IntlRecord | undefined
201
198
  > = CommandOut<
202
199
  Arg,
203
- Effect.Effect.Success<Eff>,
204
- Effect.Effect.Error<Eff>,
205
- Effect.Effect.Context<Eff>,
200
+ Effect.Success<Eff>,
201
+ Effect.Error<Eff>,
202
+ Effect.Services<Eff>,
206
203
  Id,
207
204
  I18nKey,
208
205
  State
@@ -210,7 +207,7 @@ export declare namespace Commander {
210
207
 
211
208
  export type Gen<RT, Id extends string, I18nKey extends string, State extends IntlRecord | undefined> = {
212
209
  <
213
- Eff extends YieldWrap<Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>>,
210
+ Eff extends Effect.Yieldable<any, any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
214
211
  AEff,
215
212
  Arg = void
216
213
  >(
@@ -219,17 +216,17 @@ export declare namespace Commander {
219
216
  Arg,
220
217
  AEff,
221
218
  [Eff] extends [never] ? never
222
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
219
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
223
220
  : never,
224
221
  [Eff] extends [never] ? never
225
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
222
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
226
223
  : never,
227
224
  Id,
228
225
  I18nKey,
229
226
  State
230
227
  >
231
228
  <
232
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
229
+ Eff extends Effect.Yieldable<any, any, any, any>,
233
230
  AEff,
234
231
  A extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
235
232
  Arg = void
@@ -239,10 +236,10 @@ export declare namespace Commander {
239
236
  _: Effect.Effect<
240
237
  AEff,
241
238
  [Eff] extends [never] ? never
242
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
239
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
243
240
  : never,
244
241
  [Eff] extends [never] ? never
245
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
242
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
246
243
  : never
247
244
  >,
248
245
  arg: NoInfer<Arg>,
@@ -250,7 +247,7 @@ export declare namespace Commander {
250
247
  ) => A
251
248
  ): CommandOutHelper<Arg, A, Id, I18nKey, State>
252
249
  <
253
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
250
+ Eff extends Effect.Yieldable<any, any, any, any>,
254
251
  AEff,
255
252
  A,
256
253
  B extends Effect.Effect<any, any, RT | CommandContext | `Commander.Command.${Id}.state`>,
@@ -261,10 +258,10 @@ export declare namespace Commander {
261
258
  _: Effect.Effect<
262
259
  AEff,
263
260
  [Eff] extends [never] ? never
264
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
261
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
265
262
  : never,
266
263
  [Eff] extends [never] ? never
267
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
264
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
268
265
  : never
269
266
  >,
270
267
  arg: NoInfer<Arg>,
@@ -273,7 +270,7 @@ export declare namespace Commander {
273
270
  b: (_: A, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => B
274
271
  ): CommandOutHelper<Arg, B, Id, I18nKey, State>
275
272
  <
276
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
273
+ Eff extends Effect.Yieldable<any, any, any, any>,
277
274
  AEff,
278
275
  A,
279
276
  B,
@@ -285,10 +282,10 @@ export declare namespace Commander {
285
282
  _: Effect.Effect<
286
283
  AEff,
287
284
  [Eff] extends [never] ? never
288
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
285
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
289
286
  : never,
290
287
  [Eff] extends [never] ? never
291
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
288
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
292
289
  : never
293
290
  >,
294
291
  arg: NoInfer<Arg>,
@@ -298,7 +295,7 @@ export declare namespace Commander {
298
295
  c: (_: B, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => C
299
296
  ): CommandOutHelper<Arg, C, Id, I18nKey, State>
300
297
  <
301
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
298
+ Eff extends Effect.Yieldable<any, any, any, any>,
302
299
  AEff,
303
300
  A,
304
301
  B,
@@ -311,10 +308,10 @@ export declare namespace Commander {
311
308
  _: Effect.Effect<
312
309
  AEff,
313
310
  [Eff] extends [never] ? never
314
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
311
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
315
312
  : never,
316
313
  [Eff] extends [never] ? never
317
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
314
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
318
315
  : never
319
316
  >,
320
317
  arg: NoInfer<Arg>,
@@ -325,7 +322,7 @@ export declare namespace Commander {
325
322
  d: (_: C, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => D
326
323
  ): CommandOutHelper<Arg, D, Id, I18nKey, State>
327
324
  <
328
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
325
+ Eff extends Effect.Yieldable<any, any, any, any>,
329
326
  AEff,
330
327
  A,
331
328
  B,
@@ -339,10 +336,10 @@ export declare namespace Commander {
339
336
  _: Effect.Effect<
340
337
  AEff,
341
338
  [Eff] extends [never] ? never
342
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
339
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
343
340
  : never,
344
341
  [Eff] extends [never] ? never
345
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
342
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
346
343
  : never
347
344
  >,
348
345
  arg: NoInfer<Arg>,
@@ -354,7 +351,7 @@ export declare namespace Commander {
354
351
  e: (_: D, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => E
355
352
  ): CommandOutHelper<Arg, E, Id, I18nKey, State>
356
353
  <
357
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
354
+ Eff extends Effect.Yieldable<any, any, any, any>,
358
355
  AEff,
359
356
  A,
360
357
  B,
@@ -369,10 +366,10 @@ export declare namespace Commander {
369
366
  _: Effect.Effect<
370
367
  AEff,
371
368
  [Eff] extends [never] ? never
372
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
369
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
373
370
  : never,
374
371
  [Eff] extends [never] ? never
375
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
372
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
376
373
  : never
377
374
  >,
378
375
  arg: NoInfer<Arg>,
@@ -385,7 +382,7 @@ export declare namespace Commander {
385
382
  f: (_: E, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => F
386
383
  ): CommandOutHelper<Arg, F, Id, I18nKey, State>
387
384
  <
388
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
385
+ Eff extends Effect.Yieldable<any, any, any, any>,
389
386
  AEff,
390
387
  A,
391
388
  B,
@@ -401,10 +398,10 @@ export declare namespace Commander {
401
398
  _: Effect.Effect<
402
399
  AEff,
403
400
  [Eff] extends [never] ? never
404
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
401
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
405
402
  : never,
406
403
  [Eff] extends [never] ? never
407
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
404
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
408
405
  : never
409
406
  >,
410
407
  arg: NoInfer<Arg>,
@@ -418,7 +415,7 @@ export declare namespace Commander {
418
415
  g: (_: F, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => G
419
416
  ): CommandOutHelper<Arg, G, Id, I18nKey, State>
420
417
  <
421
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
418
+ Eff extends Effect.Yieldable<any, any, any, any>,
422
419
  AEff,
423
420
  A,
424
421
  B,
@@ -435,10 +432,10 @@ export declare namespace Commander {
435
432
  _: Effect.Effect<
436
433
  AEff,
437
434
  [Eff] extends [never] ? never
438
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
435
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
439
436
  : never,
440
437
  [Eff] extends [never] ? never
441
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
438
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
442
439
  : never
443
440
  >,
444
441
  arg: NoInfer<Arg>,
@@ -453,7 +450,7 @@ export declare namespace Commander {
453
450
  h: (_: G, arg: NoInfer<Arg>, ctx: CommandContextLocal2<NoInfer<Id>, NoInfer<I18nKey>, NoInfer<State>>) => H
454
451
  ): CommandOutHelper<Arg, H, Id, I18nKey, State>
455
452
  <
456
- Eff extends YieldWrap<Effect.Effect<any, any, any>>,
453
+ Eff extends Effect.Yieldable<any, any, any, any>,
457
454
  AEff,
458
455
  A,
459
456
  B,
@@ -471,10 +468,10 @@ export declare namespace Commander {
471
468
  _: Effect.Effect<
472
469
  AEff,
473
470
  [Eff] extends [never] ? never
474
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E
471
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer E, infer _R>] ? E
475
472
  : never,
476
473
  [Eff] extends [never] ? never
477
- : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R
474
+ : [Eff] extends [Effect.Yieldable<any, infer _A, infer _E, infer R>] ? R
478
475
  : never
479
476
  >,
480
477
  arg: NoInfer<Arg>,
@@ -1051,7 +1048,7 @@ export declare namespace Commander {
1051
1048
 
1052
1049
  type ErrorRenderer<E, Args extends readonly any[]> = (e: E, action: string, ...args: Args) => string | undefined
1053
1050
 
1054
- const renderErrorMaker = I18n.use(
1051
+ const renderErrorMaker = I18n.useSync(
1055
1052
  ({ intl }) =>
1056
1053
  <E, Args extends readonly any[]>(action: string, errorRenderer?: ErrorRenderer<E, Args>) =>
1057
1054
  (e: E, ...args: Args): string => {
@@ -1061,7 +1058,7 @@ const renderErrorMaker = I18n.use(
1061
1058
  return m
1062
1059
  }
1063
1060
  }
1064
- if (!S.is(SupportedErrors)(e) && !S.ParseResult.isParseError(e)) {
1061
+ if (!S.is(SupportedErrors)(e) && !S.isSchemaError(e)) {
1065
1062
  if (typeof e === "object" && e !== null) {
1066
1063
  if ("message" in e) {
1067
1064
  return `${e.message}`
@@ -1072,13 +1069,13 @@ const renderErrorMaker = I18n.use(
1072
1069
  }
1073
1070
  return ""
1074
1071
  }
1075
- const e2: SupportedErrors | S.ParseResult.ParseError = e
1072
+ const e2: SupportedErrors | S.SchemaError = e
1076
1073
  return Match.value(e2).pipe(
1077
1074
  Match.tags({
1078
1075
  NotFoundError: (e) => {
1079
1076
  return intl.formatMessage({ id: "handle.not_found" }, { type: e.type, id: e.id })
1080
1077
  },
1081
- ParseError: (e) => {
1078
+ SchemaError: (e) => {
1082
1079
  console.warn(e.toString())
1083
1080
  return intl.formatMessage({ id: "validation.failed" })
1084
1081
  }
@@ -1217,7 +1214,7 @@ export const CommanderStatic = {
1217
1214
  ? cc.id
1218
1215
  : typeof options.stableToastId === "function"
1219
1216
  ? (...args: Args) => {
1220
- const r = (options.stableToastId as any)(id, ...args)
1217
+ const r = (options.stableToastId as any)(cc.id, ...args)
1221
1218
  if (typeof r === "string") return r
1222
1219
  if (r === true) return cc.id
1223
1220
  return undefined
@@ -1267,17 +1264,15 @@ export const CommanderStatic = {
1267
1264
  return (_k: ArgIn) => {
1268
1265
  const k = keyMaker ? keyMaker(_k) : _k as unknown as Arg
1269
1266
  // we want to compare structurally, unless custom equal/hash has been implemented
1270
- return Utils.structuralRegion(() => {
1271
- const item = MutableHashMap.get(commands, k).pipe(Option.flatMap((r) => Option.fromNullable(r.deref())))
1272
- if (item.value) {
1273
- return item.value
1274
- }
1275
- const v = maker(k)
1276
- MutableHashMap.set(commands, k, new WeakRef(v))
1267
+ const item = MutableHashMap.get(commands, k).pipe(Option.flatMap((r) => Option.fromNullishOr(r.deref())))
1268
+ if (item.value) {
1269
+ return item.value
1270
+ }
1271
+ const v = maker(k)
1272
+ MutableHashMap.set(commands, k, new WeakRef(v))
1277
1273
 
1278
- registry.register(v, k)
1279
- return v
1280
- })
1274
+ registry.register(v, k)
1275
+ return v
1281
1276
  }
1282
1277
  }
1283
1278
  }
@@ -1329,7 +1324,7 @@ const getStateValues = <const Id extends string, const I18nKey extends string, S
1329
1324
  // class preserves JSDoc throughout..
1330
1325
  export class CommanderImpl<RT, RTHooks> {
1331
1326
  constructor(
1332
- private readonly rt: Runtime.Runtime<RT>,
1327
+ private readonly rt: ServiceMap.ServiceMap<RT>,
1333
1328
  private readonly intl: I18n,
1334
1329
  private readonly hooks: Layer.Layer<RTHooks, never, RT>
1335
1330
  ) {
@@ -1391,7 +1386,7 @@ export class CommanderImpl<RT, RTHooks> {
1391
1386
  }
1392
1387
 
1393
1388
  const key = `Commander.Command.${id}.state` as const
1394
- const stateTag = Context.GenericTag<typeof key, State>(key)
1389
+ const stateTag = ServiceMap.Service<typeof key, State>(key)
1395
1390
 
1396
1391
  const makeContext_ = () => this.makeContext(id, { ...options, state: state?.value })
1397
1392
  const initialContext = makeContext_()
@@ -1401,14 +1396,14 @@ export class CommanderImpl<RT, RTHooks> {
1401
1396
 
1402
1397
  const errorReporter = <A, E, R>(self: Effect.Effect<A, E, R>) =>
1403
1398
  self.pipe(
1404
- Effect.tapErrorCause(
1399
+ Effect.tapCause(
1405
1400
  Effect.fnUntraced(function*(cause) {
1406
- if (Cause.isInterruptedOnly(cause)) {
1401
+ if (Cause.hasInterruptsOnly(cause)) {
1407
1402
  console.info(`Interrupted while trying to ${id}`)
1408
1403
  return
1409
1404
  }
1410
1405
 
1411
- const fail = Cause.failureOption(cause)
1406
+ const fail = Cause.findErrorOption(cause)
1412
1407
  if (Option.isSome(fail)) {
1413
1408
  // if (fail.value._tag === "SuppressErrors") {
1414
1409
  // console.info(
@@ -1485,8 +1480,8 @@ export class CommanderImpl<RT, RTHooks> {
1485
1480
  const computeAllowed = options?.allowed
1486
1481
  const allowed = computeAllowed ? computed(() => computeAllowed(id, state)) : true
1487
1482
 
1488
- const rt = Effect.runtime<RT | RTHooks>().pipe(Effect.provide(this.hooks)).pipe(Runtime.runSync(this.rt))
1489
- const runFork = Runtime.runFork(rt)
1483
+ const rt = Effect.services<RT | RTHooks>().pipe(Effect.provide(this.hooks)).pipe(Effect.runSyncWith(this.rt))
1484
+ const runFork = Effect.runForkWith(rt)
1490
1485
 
1491
1486
  const handle = Object.assign((arg: Arg) => {
1492
1487
  // we capture the call site stack here
@@ -1660,7 +1655,7 @@ export class CommanderImpl<RT, RTHooks> {
1660
1655
  id: Id | { id: Id },
1661
1656
  options?: FnOptions<Id, I18nKey, State>
1662
1657
  ): Commander.Gen<RT | RTHooks, Id, I18nKey, State> & Commander.NonGen<RT | RTHooks, Id, I18nKey, State> & {
1663
- state: Context.Tag<`Commander.Command.${Id}.state`, State>
1658
+ state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>
1664
1659
  } =>
1665
1660
  Object.assign(
1666
1661
  (
@@ -1685,7 +1680,7 @@ export class CommanderImpl<RT, RTHooks> {
1685
1680
  },
1686
1681
  makeBaseInfo(typeof id === "string" ? id : id.id, options),
1687
1682
  {
1688
- state: Context.GenericTag<`Commander.Command.${Id}.state`, State>(
1683
+ state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>(
1689
1684
  `Commander.Command.${typeof id === "string" ? id : id.id}.state`
1690
1685
  )
1691
1686
  }
@@ -1710,7 +1705,7 @@ export class CommanderImpl<RT, RTHooks> {
1710
1705
  & Commander.CommandContextLocal<Id, I18nKey>
1711
1706
  & (<A, E, R extends RT | RTHooks | CommandContext | `Commander.Command.${Id}.state`, Arg = void>(
1712
1707
  handler: (
1713
- ctx: Effect.fn.Gen & Effect.fn.NonGen & Commander.CommandContextLocal<Id, I18nKey> & {
1708
+ ctx: Effect.fn.Traced & Effect.fn.Untraced & Commander.CommandContextLocal<Id, I18nKey> & {
1714
1709
  // todo: only if we passed in one
1715
1710
  mutate: (arg: Arg) => Effect.Effect<MutA, MutE, MutR>
1716
1711
  }
@@ -1821,7 +1816,7 @@ export class CommanderImpl<RT, RTHooks> {
1821
1816
  },
1822
1817
  makeBaseInfo(mutation.id, options),
1823
1818
  {
1824
- state: Context.GenericTag<`Commander.Command.${Id}.state`, State>(
1819
+ state: ServiceMap.Service<`Commander.Command.${Id}.state`, State>(
1825
1820
  `Commander.Command.${mutation.id}.state`
1826
1821
  )
1827
1822
  }
@@ -1829,11 +1824,13 @@ export class CommanderImpl<RT, RTHooks> {
1829
1824
  }
1830
1825
 
1831
1826
  // @effect-diagnostics-next-line missingEffectServiceDependency:off
1832
- export class Commander extends Effect.Service<Commander>()("Commander", {
1833
- dependencies: [WithToast.Default],
1834
- effect: Effect.gen(function*() {
1827
+ export class Commander extends ServiceMap.Service<Commander>()("Commander", {
1828
+ make: Effect.gen(function*() {
1835
1829
  const i18n = yield* I18n
1836
- return <RT, RTHooks>(rt: Runtime.Runtime<RT>, rtHooks: Layer.Layer<RTHooks, never, RT>) =>
1830
+ return <RT, RTHooks>(rt: ServiceMap.ServiceMap<RT>, rtHooks: Layer.Layer<RTHooks, never, RT>) =>
1837
1831
  new CommanderImpl(rt, i18n, rtHooks)
1838
1832
  })
1839
- }) {}
1833
+ }) {
1834
+ static readonly DefaultWithoutDependencies = Layer.effect(this, this.make)
1835
+ static readonly Default = this.DefaultWithoutDependencies
1836
+ }
@@ -1,9 +1,9 @@
1
- import { Effect } from "effect-app"
1
+ import { Effect, Layer, ServiceMap } from "effect-app"
2
2
  import { I18n } from "./intl.js"
3
3
 
4
4
  // @effect-diagnostics-next-line missingEffectServiceDependency:off
5
- export class Confirm extends Effect.Service<Confirm>()("Confirm", {
6
- effect: Effect.gen(function*() {
5
+ export class Confirm extends ServiceMap.Service<Confirm>()("Confirm", {
6
+ make: Effect.gen(function*() {
7
7
  const { intl } = yield* I18n
8
8
 
9
9
  const getDefaultMessage = () => intl.formatMessage({ id: "confirm.default", defaultMessage: "Sind sie Sicher?" })
@@ -16,6 +16,21 @@ export class Confirm extends Effect.Service<Confirm>()("Confirm", {
16
16
  )
17
17
 
18
18
  return { confirm, confirmOrInterrupt }
19
- }),
20
- accessors: true
21
- }) {}
19
+ })
20
+ }) {
21
+ static readonly DefaultWithoutDependencies = Layer.effect(this, this.make)
22
+ static readonly Default = this.DefaultWithoutDependencies
23
+
24
+ static confirm(message?: string) {
25
+ return Effect.gen(function*() {
26
+ const c = yield* Confirm
27
+ return yield* c.confirm(message)
28
+ })
29
+ }
30
+ static confirmOrInterrupt(message?: string) {
31
+ return Effect.gen(function*() {
32
+ const c = yield* Confirm
33
+ return yield* c.confirmOrInterrupt(message)
34
+ })
35
+ }
36
+ }
@@ -1,8 +1,8 @@
1
- import { Context } from "effect-app"
2
- import { proxify } from "effect-app/Context"
1
+ import { ServiceMap } from "effect-app"
2
+ import { proxify } from "effect-app/ServiceMap"
3
3
  import { type MakeIntlReturn } from "../makeIntl.js"
4
4
 
5
- export class I18n extends proxify(Context.TagId("I18n")<I18n, ReturnType<MakeIntlReturn<string>["useIntl"]>>())<
5
+ export class I18n extends proxify(ServiceMap.Opaque<I18n, ReturnType<MakeIntlReturn<string>["useIntl"]>>()("I18n"))<
6
6
  I18n,
7
7
  ReturnType<MakeIntlReturn<string>["useIntl"]>
8
8
  >() {
@@ -12,7 +12,7 @@ export interface CommanderResolved<RT, RTHooks>
12
12
  export const makeUseCommand = Effect.fnUntraced(
13
13
  function*<R = never, RTHooks = never>(rtHooks: Layer.Layer<RTHooks, never, R>) {
14
14
  const cmndr = yield* Commander
15
- const runtime = yield* Effect.runtime<R>()
15
+ const runtime = yield* Effect.services<R>()
16
16
 
17
17
  const comm = cmndr(runtime, rtHooks)
18
18
 
@@ -1,5 +1,5 @@
1
- import { Context, Effect, Option } from "effect-app"
2
- import { proxify } from "effect-app/Context"
1
+ import { Effect, Option, ServiceMap } from "effect-app"
2
+ import { proxify } from "effect-app/ServiceMap"
3
3
 
4
4
  export type ToastId = string | number
5
5
  export type ToastOpts = { id?: ToastId; timeout?: number }
@@ -13,7 +13,7 @@ export type UseToast = () => {
13
13
  dismiss: (this: void, id: ToastId) => void
14
14
  }
15
15
 
16
- export class CurrentToastId extends Context.TagId("CurrentToastId")<CurrentToastId, { toastId: ToastId }>() {}
16
+ export class CurrentToastId extends ServiceMap.Opaque<CurrentToastId, { toastId: ToastId }>()("CurrentToastId") {}
17
17
 
18
18
  /** fallback to CurrentToastId when available unless id is explicitly set to a value or null */
19
19
  export const wrap = (toast: ReturnType<UseToast>) => {
@@ -42,6 +42,25 @@ export const wrap = (toast: ReturnType<UseToast>) => {
42
42
  }
43
43
 
44
44
  export class Toast
45
- extends proxify(Context.TagId("Toast")<Toast, ReturnType<typeof wrap>>())<Toast, ReturnType<typeof wrap>>()
45
+ extends proxify(ServiceMap.Opaque<Toast, ReturnType<typeof wrap>>()("Toast"))<Toast, ReturnType<typeof wrap>>()
46
46
  {
47
47
  }
48
+
49
+ // const a = Layer.effect(Toast, Effect.sync(() => Toast.of(null as any)))
50
+
51
+ // const A = Toast.of({
52
+ // error: () => Effect.succeed(null as any),
53
+ // info: () => Effect.succeed(null as any),
54
+ // success: () => Effect.succeed(null as any),
55
+ // warning: () => Effect.succeed(null as any),
56
+ // dismiss: () => Effect.succeed(null as any)
57
+ // })
58
+
59
+ // const b = Toast.info("test")
60
+
61
+ // const a2 = Toast.use((_) => _.error("test"))
62
+
63
+ // const b2 = Effect.gen(function*() {
64
+ // const toast = yield* Toast
65
+ // toast.error("test")
66
+ // })
@@ -1,4 +1,4 @@
1
- import { Cause, Effect, type Option } from "effect-app"
1
+ import { Cause, Effect, Layer, type Option, ServiceMap } from "effect-app"
2
2
  import { wrapEffect } from "effect-app/utils"
3
3
  import { CurrentToastId, Toast } from "./toast.js"
4
4
 
@@ -33,8 +33,8 @@ export interface ToastOptions<A, E, Args extends ReadonlyArray<unknown>, WaiR, S
33
33
  }
34
34
 
35
35
  // @effect-diagnostics-next-line missingEffectServiceDependency:off
36
- export class WithToast extends Effect.Service<WithToast>()("WithToast", {
37
- effect: Effect.gen(function*() {
36
+ export class WithToast extends ServiceMap.Service<WithToast>()("WithToast", {
37
+ make: Effect.gen(function*() {
38
38
  const toast = yield* Toast
39
39
  return <A, E, Args extends Array<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
40
40
  options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
@@ -62,19 +62,19 @@ export class WithToast extends Effect.Service<WithToast>()("WithToast", {
62
62
  toastId !== undefined ? { id: toastId, timeout: baseTimeout } : { timeout: baseTimeout }
63
63
  )
64
64
  })),
65
- Effect.tapErrorCause(Effect.fnUntraced(function*(cause) {
65
+ Effect.tapCause(Effect.fnUntraced(function*(cause) {
66
66
  yield* Effect.logDebug(
67
67
  "WithToast - caught error cause: " + Cause.squash(cause),
68
- Cause.isInterruptedOnly(cause),
68
+ Cause.hasInterruptsOnly(cause),
69
69
  cause
70
70
  )
71
71
 
72
- if (Cause.isInterruptedOnly(cause)) {
72
+ if (Cause.hasInterruptsOnly(cause)) {
73
73
  if (toastId) yield* toast.dismiss(toastId)
74
74
  return
75
75
  }
76
76
 
77
- const t = yield* wrapEffect(options.onFailure)(Cause.failureOption(cause), ...args)
77
+ const t = yield* wrapEffect(options.onFailure)(Cause.findErrorOption(cause), ...args)
78
78
  const opts = { timeout: baseTimeout * 2 }
79
79
 
80
80
  if (typeof t === "object") {
@@ -89,6 +89,9 @@ export class WithToast extends Effect.Service<WithToast>()("WithToast", {
89
89
  })
90
90
  })
91
91
  }) {
92
+ static readonly DefaultWithoutDependencies = Layer.effect(this, this.make)
93
+ static readonly Default = this.DefaultWithoutDependencies
94
+
92
95
  static readonly handle = <A, E, Args extends Array<unknown>, R, WaiR = never, SucR = never, ErrR = never>(
93
96
  options: ToastOptions<A, E, Args, WaiR, SucR, ErrR>
94
97
  ): (self: Effect.Effect<A, E, R>, ...args: Args) => Effect.Effect<A, E, R | WaiR | SucR | ErrR | WithToast> =>