@effect-app/vue 4.0.0-beta.17 → 4.0.0-beta.171

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 (96) hide show
  1. package/CHANGELOG.md +1098 -0
  2. package/dist/commander.d.ts +370 -0
  3. package/dist/commander.d.ts.map +1 -0
  4. package/dist/commander.js +591 -0
  5. package/dist/confirm.d.ts +19 -0
  6. package/dist/confirm.d.ts.map +1 -0
  7. package/dist/confirm.js +24 -0
  8. package/dist/errorReporter.d.ts +4 -4
  9. package/dist/errorReporter.d.ts.map +1 -1
  10. package/dist/errorReporter.js +12 -18
  11. package/dist/form.d.ts +13 -4
  12. package/dist/form.d.ts.map +1 -1
  13. package/dist/form.js +41 -12
  14. package/dist/index.d.ts +1 -1
  15. package/dist/intl.d.ts +15 -0
  16. package/dist/intl.d.ts.map +1 -0
  17. package/dist/intl.js +9 -0
  18. package/dist/lib.d.ts +8 -9
  19. package/dist/lib.d.ts.map +1 -1
  20. package/dist/lib.js +34 -7
  21. package/dist/makeClient.d.ts +120 -277
  22. package/dist/makeClient.d.ts.map +1 -1
  23. package/dist/makeClient.js +155 -359
  24. package/dist/makeContext.d.ts +1 -1
  25. package/dist/makeContext.d.ts.map +1 -1
  26. package/dist/makeIntl.d.ts +1 -1
  27. package/dist/makeIntl.d.ts.map +1 -1
  28. package/dist/makeUseCommand.d.ts +8 -0
  29. package/dist/makeUseCommand.d.ts.map +1 -0
  30. package/dist/makeUseCommand.js +13 -0
  31. package/dist/mutate.d.ts +4 -4
  32. package/dist/mutate.d.ts.map +1 -1
  33. package/dist/mutate.js +7 -7
  34. package/dist/query.d.ts +11 -15
  35. package/dist/query.d.ts.map +1 -1
  36. package/dist/query.js +19 -27
  37. package/dist/routeParams.d.ts +1 -1
  38. package/dist/runtime.d.ts +5 -2
  39. package/dist/runtime.d.ts.map +1 -1
  40. package/dist/runtime.js +27 -17
  41. package/dist/toast.d.ts +46 -0
  42. package/dist/toast.d.ts.map +1 -0
  43. package/dist/toast.js +32 -0
  44. package/dist/withToast.d.ts +26 -0
  45. package/dist/withToast.d.ts.map +1 -0
  46. package/dist/withToast.js +49 -0
  47. package/eslint.config.mjs +2 -2
  48. package/package.json +48 -48
  49. package/src/{experimental/commander.ts → commander.ts} +930 -255
  50. package/src/{experimental/confirm.ts → confirm.ts} +10 -14
  51. package/src/errorReporter.ts +60 -72
  52. package/src/form.ts +55 -16
  53. package/src/intl.ts +12 -0
  54. package/src/lib.ts +50 -13
  55. package/src/makeClient.ts +454 -1023
  56. package/src/{experimental/makeUseCommand.ts → makeUseCommand.ts} +3 -3
  57. package/src/mutate.ts +40 -32
  58. package/src/query.ts +39 -50
  59. package/src/runtime.ts +39 -18
  60. package/src/{experimental/toast.ts → toast.ts} +11 -25
  61. package/src/{experimental/withToast.ts → withToast.ts} +15 -6
  62. package/test/Mutation.test.ts +130 -10
  63. package/test/dist/form.test.d.ts.map +1 -1
  64. package/test/dist/lib.test.d.ts.map +1 -0
  65. package/test/dist/stubs.d.ts +2162 -118
  66. package/test/dist/stubs.d.ts.map +1 -1
  67. package/test/dist/stubs.js +80 -23
  68. package/test/form-validation-errors.test.ts +23 -19
  69. package/test/form.test.ts +20 -2
  70. package/test/lib.test.ts +240 -0
  71. package/test/makeClient.test.ts +217 -38
  72. package/test/stubs.ts +117 -40
  73. package/tsconfig.json +0 -1
  74. package/tsconfig.json.bak +2 -2
  75. package/tsconfig.src.json +34 -34
  76. package/tsconfig.test.json +2 -2
  77. package/vitest.config.ts +5 -5
  78. package/dist/experimental/commander.d.ts +0 -359
  79. package/dist/experimental/commander.d.ts.map +0 -1
  80. package/dist/experimental/commander.js +0 -557
  81. package/dist/experimental/confirm.d.ts +0 -19
  82. package/dist/experimental/confirm.d.ts.map +0 -1
  83. package/dist/experimental/confirm.js +0 -28
  84. package/dist/experimental/intl.d.ts +0 -16
  85. package/dist/experimental/intl.d.ts.map +0 -1
  86. package/dist/experimental/intl.js +0 -5
  87. package/dist/experimental/makeUseCommand.d.ts +0 -8
  88. package/dist/experimental/makeUseCommand.d.ts.map +0 -1
  89. package/dist/experimental/makeUseCommand.js +0 -13
  90. package/dist/experimental/toast.d.ts +0 -47
  91. package/dist/experimental/toast.d.ts.map +0 -1
  92. package/dist/experimental/toast.js +0 -41
  93. package/dist/experimental/withToast.d.ts +0 -25
  94. package/dist/experimental/withToast.d.ts.map +0 -1
  95. package/dist/experimental/withToast.js +0 -45
  96. package/src/experimental/intl.ts +0 -9
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { it } from "@effect/vitest"
3
3
  import { Cause, Effect, Exit, Fiber, Option } from "effect-app"
4
- import { CommandContext, DefaultIntl } from "../src/experimental/commander.js"
4
+ import { OperationFailure } from "effect-app/Operations"
5
+ import { CommandContext, DefaultIntl } from "../src/commander.js"
5
6
  import { AsyncResult } from "../src/lib.js"
6
7
  import { useExperimental } from "./stubs.js"
7
8
 
@@ -71,7 +72,10 @@ describe("alt2", () => {
71
72
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
72
73
  })),
73
74
  Effect.tap(() =>
74
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
75
+ Effect.currentSpan.pipe(
76
+ Effect.map((_) => _.name),
77
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
78
+ )
75
79
  ),
76
80
  Effect.tap(() => Effect.sync(() => executed = true))
77
81
  )
@@ -125,7 +129,10 @@ it.live("works", () =>
125
129
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
126
130
  })),
127
131
  Effect.tap(() =>
128
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
132
+ Effect.currentSpan.pipe(
133
+ Effect.map((_) => _.name),
134
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
135
+ )
129
136
  ),
130
137
  Effect.tap(() => Effect.sync(() => executed = true))
131
138
  )
@@ -175,7 +182,10 @@ it.live("works non-gen", () =>
175
182
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
176
183
  })),
177
184
  Effect.tap(() =>
178
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
185
+ Effect.currentSpan.pipe(
186
+ Effect.map((_) => _.name),
187
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
188
+ )
179
189
  ),
180
190
  Effect.tap(() => Effect.sync(() => executed = true))
181
191
  )
@@ -317,7 +327,10 @@ it.live("with toasts", () =>
317
327
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
318
328
  })),
319
329
  Effect.tap(() =>
320
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
330
+ Effect.currentSpan.pipe(
331
+ Effect.map((_) => _.name),
332
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
333
+ )
321
334
  ),
322
335
  // WithToast.handle({
323
336
  // onFailure: "failed",
@@ -388,9 +401,55 @@ it.live("fail", () =>
388
401
  expect(command.waiting).toBe(false)
389
402
  expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
390
403
  expect(toasts.length).toBe(1) // toast should show error
404
+ expect(toasts[0].type).toBe("warning")
405
+ expect(toasts[0].message).toContain("Test Action Failed:\nBoom!")
406
+ expect(toasts[0].message).toMatch(/Trace: [a-f0-9]{32}/)
407
+ expect(toasts[0].message).toMatch(/Span: [a-f0-9]{16}/)
408
+ }))
409
+
410
+ it.live("fail with showSpanInfo disabled", () =>
411
+ Effect
412
+ .gen(function*() {
413
+ const toasts: any[] = []
414
+ const Command = useExperimental({ toasts, messages: DefaultIntl.en })
415
+
416
+ const command = Command.fn("Test Action")(
417
+ function*() {
418
+ return yield* Effect.fail({ message: "Boom!" })
419
+ },
420
+ Command.withDefaultToast({ showSpanInfo: false })
421
+ )
422
+
423
+ yield* Fiber.join(command.handle())
424
+
425
+ expect(toasts.length).toBe(1)
391
426
  expect(toasts[0].message).toBe("Test Action Failed:\nBoom!")
392
427
  }))
393
428
 
429
+ it.live("fail with custom errorRenderer uses warning toast", () =>
430
+ Effect
431
+ .gen(function*() {
432
+ const toasts: any[] = []
433
+ const Command = useExperimental({ toasts, messages: DefaultIntl.en })
434
+
435
+ const command = Command.fn("Test Action")(
436
+ function*() {
437
+ return yield* Effect.fail(OperationFailure.make({ message: null }))
438
+ },
439
+ Command.withDefaultToast({
440
+ errorRenderer: () => "Rendered Boom!"
441
+ })
442
+ )
443
+
444
+ yield* Fiber.join(command.handle())
445
+
446
+ expect(toasts.length).toBe(1)
447
+ expect(toasts[0].type).toBe("warning")
448
+ expect(toasts[0].message).toContain("Test Action, with warnings\nRendered Boom!")
449
+ expect(toasts[0].message).toMatch(/Trace: [a-f0-9]{32}/)
450
+ expect(toasts[0].message).toMatch(/Span: [a-f0-9]{16}/)
451
+ }))
452
+
394
453
  it.live("fail and recover", () =>
395
454
  Effect
396
455
  .gen(function*() {
@@ -444,7 +503,8 @@ it.live("defect", () =>
444
503
  expect(command.waiting).toBe(false)
445
504
  expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
446
505
  expect(toasts.length).toBe(1) // toast should show error
447
- expect(toasts[0].message).toBe("Test Action unexpected error, please try again shortly.")
506
+ expect(toasts[0].type).toBe("error")
507
+ expect(toasts[0].message).toContain("Test Action unexpected error, please try again shortly.")
448
508
  }))
449
509
 
450
510
  it.live("works with alt", () =>
@@ -471,7 +531,10 @@ it.live("works with alt", () =>
471
531
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
472
532
  })),
473
533
  Effect.tap(() =>
474
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
534
+ Effect.currentSpan.pipe(
535
+ Effect.map((_) => _.name),
536
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
537
+ )
475
538
  ),
476
539
  Effect.tap(() => Effect.sync(() => executed = true))
477
540
  )
@@ -624,7 +687,10 @@ it.live("with toasts with alt", () =>
624
687
  expect(yield* Effect.currentSpan.pipe(Effect.map((_) => _.name))).toBe("Test Action")
625
688
  })),
626
689
  Effect.tap(() =>
627
- Effect.currentSpan.pipe(Effect.map((_) => _.name), Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action"))))
690
+ Effect.currentSpan.pipe(
691
+ Effect.map((_) => _.name),
692
+ Effect.tap((_) => Effect.sync(() => expect(_).toBe("Test Action")))
693
+ )
628
694
  ),
629
695
  Command.withDefaultToast(),
630
696
  Effect.tap(() => Effect.sync(() => executed = true))
@@ -696,7 +762,8 @@ it.live("fail with alt", () =>
696
762
  expect(command.waiting).toBe(false)
697
763
  expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
698
764
  expect(toasts.length).toBe(1) // toast should show error
699
- expect(toasts[0].message).toBe("Test Action Failed:\nBoom!")
765
+ expect(toasts[0].type).toBe("warning")
766
+ expect(toasts[0].message).toContain("Test Action Failed:\nBoom!")
700
767
  }))
701
768
 
702
769
  it.live("fail and recover with alt", () =>
@@ -756,5 +823,58 @@ it.live("defect with alt", () =>
756
823
  expect(command.waiting).toBe(false)
757
824
  expect(Exit.isFailure(AsyncResult.toExit(command.result))).toBe(true)
758
825
  expect(toasts.length).toBe(1) // toast should show error
759
- expect(toasts[0].message).toBe("Test Action unexpected error, please try again shortly.")
826
+ expect(toasts[0].type).toBe("error")
827
+ expect(toasts[0].message).toContain("Test Action unexpected error, please try again shortly.")
760
828
  }))
829
+
830
+ describe("state-in-toast", () => {
831
+ it("works", () => {
832
+ const toasts: any[] = []
833
+ const removeMutation = Object.assign(
834
+ Effect.fn(function*(_item: string) {
835
+ yield* Effect.sleep(1000)
836
+ }),
837
+ { id: "remove_thing" }
838
+ )
839
+
840
+ const item = "x"
841
+
842
+ const Command = useExperimental({ toasts, messages: DefaultIntl.en })
843
+
844
+ Command.fn(removeMutation, {
845
+ state: () => ({ item }),
846
+ waitKey: (id) => `${id}.${item}`,
847
+ blockKey: () => `modify_thing.${item}`
848
+ // allowed: () => role.value === "admin"
849
+ })(
850
+ function*() {
851
+ // yield* Command.confirmOrInterrupt(yield* I18n.formatMessage({ id: "confirm.remove_item" }, { item }))
852
+ yield* removeMutation(item)
853
+ },
854
+ Command.withDefaultToast({
855
+ onSuccess: (a, b, c, d) => {
856
+ console.log("Success", { a, b, c, d })
857
+ expectTypeOf(d.state).toEqualTypeOf<{ readonly item: "x" }>()
858
+ }
859
+ })
860
+ )
861
+
862
+ Command.fn(removeMutation, {
863
+ state: () => ({ item }),
864
+ waitKey: (id) => `${id}.${item}`,
865
+ blockKey: () => `modify_thing.${item}`
866
+ // allowed: () => role.value === "admin"
867
+ })(
868
+ function*() {
869
+ // yield* Command.confirmOrInterrupt(yield* I18n.formatMessage({ id: "confirm.remove_item" }, { item }))
870
+ yield* removeMutation(item)
871
+ },
872
+ Command.withDefaultToast({
873
+ onSuccess: (a, b, c) => {
874
+ console.log("Success", { a, b, c })
875
+ expectTypeOf(c).toEqualTypeOf<undefined>()
876
+ }
877
+ })
878
+ )
879
+ })
880
+ })
@@ -1 +1 @@
1
- {"version":3,"file":"form.test.d.ts","sourceRoot":"","sources":["../form.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,CAAC,EAAE,MAAM,YAAY,CAAA;;;;;;;;;;;;;;;;;AAGtC,qBAAa,YAAa,SAAQ,iBAShC;CAAG;;;;AAEL,qBAAa,mBAAoB,SAAQ,wBAEvC;CAAG;;;;;;;;;;;AAEL,qBAAa,WAAY,SAAQ,gBAK/B;CAAG;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;;;;AAEL,cAAM,QAAS,SAAQ,aAGrB;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBL,qBAAa,cAAe,SAAQ,mBAGlC;CAAG"}
1
+ {"version":3,"file":"form.test.d.ts","sourceRoot":"","sources":["../form.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,CAAC,EAAE,MAAM,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,qBAAa,YAAa,SAAQ,iBAahC;CAAG;;;;AAEL,qBAAa,mBAAoB,SAAQ,wBAEvC;CAAG;;;;;;;;;;;;AAEL,qBAAa,WAAY,SAAQ,gBAK/B;CAAG;;;;;;;;;;;;;;;;;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;;;;;;;;;;;;;;;;;AAEL,cAAM,MAAO,SAAQ,WAEnB;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEL,cAAM,QAAS,SAAQ,aAGrB;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBL,qBAAa,cAAe,SAAQ,mBAGlC;CAAG"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.test.d.ts","sourceRoot":"","sources":["../lib.test.ts"],"names":[],"mappings":""}