@effect-app/vue 4.0.0-beta.22 → 4.0.0-beta.220

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 (103) hide show
  1. package/CHANGELOG.md +1605 -0
  2. package/dist/commander.d.ts +628 -0
  3. package/dist/commander.d.ts.map +1 -0
  4. package/dist/commander.js +1060 -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 +14 -5
  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 +6 -9
  19. package/dist/lib.d.ts.map +1 -1
  20. package/dist/lib.js +35 -10
  21. package/dist/makeClient.d.ts +152 -339
  22. package/dist/makeClient.d.ts.map +1 -1
  23. package/dist/makeClient.js +221 -376
  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 +52 -34
  32. package/dist/mutate.d.ts.map +1 -1
  33. package/dist/mutate.js +137 -46
  34. package/dist/query.d.ts +19 -39
  35. package/dist/query.d.ts.map +1 -1
  36. package/dist/query.js +128 -72
  37. package/dist/routeParams.d.ts +1 -1
  38. package/dist/runtime.d.ts +7 -4
  39. package/dist/runtime.d.ts.map +1 -1
  40. package/dist/runtime.js +27 -17
  41. package/dist/toast.d.ts +50 -0
  42. package/dist/toast.d.ts.map +1 -0
  43. package/dist/toast.js +32 -0
  44. package/dist/withToast.d.ts +27 -0
  45. package/dist/withToast.d.ts.map +1 -0
  46. package/dist/withToast.js +59 -0
  47. package/examples/streamMutation.ts +70 -0
  48. package/package.json +48 -50
  49. package/src/commander.ts +3393 -0
  50. package/src/{experimental/confirm.ts → confirm.ts} +10 -14
  51. package/src/errorReporter.ts +62 -74
  52. package/src/form.ts +56 -17
  53. package/src/intl.ts +12 -0
  54. package/src/lib.ts +47 -20
  55. package/src/makeClient.ts +568 -1134
  56. package/src/{experimental/makeUseCommand.ts → makeUseCommand.ts} +6 -4
  57. package/src/mutate.ts +265 -127
  58. package/src/query.ts +197 -183
  59. package/src/runtime.ts +41 -20
  60. package/src/{experimental/toast.ts → toast.ts} +13 -27
  61. package/src/{experimental/withToast.ts → withToast.ts} +40 -12
  62. package/test/Mutation.test.ts +176 -23
  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/streamFinal.test.d.ts.map +1 -0
  66. package/test/dist/streamFn.test.d.ts.map +1 -0
  67. package/test/dist/stubs.d.ts +3529 -122
  68. package/test/dist/stubs.d.ts.map +1 -1
  69. package/test/dist/stubs.js +182 -31
  70. package/test/form-validation-errors.test.ts +23 -19
  71. package/test/form.test.ts +20 -2
  72. package/test/lib.test.ts +240 -0
  73. package/test/makeClient.test.ts +292 -38
  74. package/test/streamFinal.test.ts +63 -0
  75. package/test/streamFn.test.ts +455 -0
  76. package/test/stubs.ts +218 -42
  77. package/tsconfig.examples.json +20 -0
  78. package/tsconfig.json +0 -1
  79. package/tsconfig.json.bak +5 -2
  80. package/tsconfig.src.json +34 -34
  81. package/tsconfig.test.json +2 -2
  82. package/vitest.config.ts +5 -5
  83. package/dist/experimental/commander.d.ts +0 -359
  84. package/dist/experimental/commander.d.ts.map +0 -1
  85. package/dist/experimental/commander.js +0 -557
  86. package/dist/experimental/confirm.d.ts +0 -19
  87. package/dist/experimental/confirm.d.ts.map +0 -1
  88. package/dist/experimental/confirm.js +0 -28
  89. package/dist/experimental/intl.d.ts +0 -16
  90. package/dist/experimental/intl.d.ts.map +0 -1
  91. package/dist/experimental/intl.js +0 -5
  92. package/dist/experimental/makeUseCommand.d.ts +0 -8
  93. package/dist/experimental/makeUseCommand.d.ts.map +0 -1
  94. package/dist/experimental/makeUseCommand.js +0 -13
  95. package/dist/experimental/toast.d.ts +0 -47
  96. package/dist/experimental/toast.d.ts.map +0 -1
  97. package/dist/experimental/toast.js +0 -41
  98. package/dist/experimental/withToast.d.ts +0 -25
  99. package/dist/experimental/withToast.d.ts.map +0 -1
  100. package/dist/experimental/withToast.js +0 -45
  101. package/eslint.config.mjs +0 -24
  102. package/src/experimental/commander.ts +0 -1835
  103. package/src/experimental/intl.ts +0 -9
@@ -1,8 +1,8 @@
1
- import { Effect, Layer, ServiceMap } from "effect-app"
1
+ import { Context, Effect, Layer } 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 ServiceMap.Service<Confirm>()("Confirm", {
5
+ export class Confirm extends Context.Service<Confirm>()("Confirm", {
6
6
  make: Effect.gen(function*() {
7
7
  const { intl } = yield* I18n
8
8
 
@@ -21,16 +21,12 @@ export class Confirm extends ServiceMap.Service<Confirm>()("Confirm", {
21
21
  static readonly DefaultWithoutDependencies = Layer.effect(this, this.make)
22
22
  static readonly Default = this.DefaultWithoutDependencies
23
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
- }
24
+ static readonly confirm = Effect.fnUntraced(function*(message?: string) {
25
+ const c = yield* Confirm
26
+ return yield* c.confirm(message)
27
+ })
28
+ static readonly confirmOrInterrupt = Effect.fnUntraced(function*(message?: string) {
29
+ const c = yield* Confirm
30
+ return yield* c.confirmOrInterrupt(message)
31
+ })
36
32
  }
@@ -13,45 +13,41 @@ export const tryCauseException = <E>(cause: Cause.Cause<E>, name: string): Cause
13
13
  }
14
14
  }
15
15
 
16
- export function reportError(
17
- name: string
18
- ) {
19
- return (
20
- cause: Cause.Cause<unknown>,
21
- extras?: Record<string, unknown>,
22
- level: LogLevel.Severity = "Error"
23
- ): Effect.Effect<unknown, never, never> =>
24
- Effect
25
- .gen(function*() {
26
- if (Cause.hasInterruptsOnly(cause)) {
27
- yield* Effect.logDebug("Interrupted").pipe(Effect.annotateLogs("extras", JSON.stringify(extras ?? {})))
28
- return Cause.squash(cause)
29
- }
30
-
31
- const error = tryCauseException(cause, name)
32
- yield* reportSentry(error, extras, LogLevelToSentry(level))
33
- yield* Effect
34
- .logWithLevel(level)("Reporting error", cause)
35
- .pipe(
36
- Effect.annotateLogs(dropUndefined({
37
- extras,
38
- error: tryToReport(error),
39
- cause: tryToJson(cause),
40
- __error_name__: name
41
- })),
42
- Effect.catchCause((cause) => Effect.logWarning("Failed to log error", cause)),
43
- Effect.catchCause(() => Effect.logFatal("Failed to log error cause"))
44
- )
16
+ export function reportError(name: string) {
17
+ return Effect.fnUntraced(
18
+ function*(
19
+ cause: Cause.Cause<unknown>,
20
+ extras?: Record<string, unknown>,
21
+ level: LogLevel.Severity = "Error"
22
+ ) {
23
+ if (Cause.hasInterruptsOnly(cause)) {
24
+ yield* Effect.logDebug("Interrupted").pipe(Effect.annotateLogs("extras", JSON.stringify(extras ?? {})))
25
+ return Cause.squash(cause)
26
+ }
45
27
 
46
- return error
47
- })
48
- .pipe(
49
- Effect.tapCause((cause) =>
50
- Effect.logError("Failed to report error", cause).pipe(
51
- Effect.tapCause(() => Effect.logFatal("Failed to log error cause"))
52
- )
28
+ const error = tryCauseException(cause, name)
29
+ yield* reportSentry(error, extras, LogLevelToSentry(level))
30
+ yield* Effect
31
+ .logWithLevel(level)("Reporting error", cause)
32
+ .pipe(
33
+ Effect.annotateLogs(dropUndefined({
34
+ extras,
35
+ error: tryToReport(error),
36
+ cause: tryToJson(cause),
37
+ __error_name__: name
38
+ })),
39
+ Effect.catchCause((cause) => Effect.logWarning("Failed to log error", cause)),
40
+ Effect.catchCause(() => Effect.logFatal("Failed to log error cause"))
53
41
  )
54
- )
42
+
43
+ return error
44
+ },
45
+ (effect) =>
46
+ Effect.tapCause(effect, (cause) =>
47
+ Effect.logError("Failed to report error", cause).pipe(
48
+ Effect.tapCause(() => Effect.logFatal("Failed to log error cause"))
49
+ ))
50
+ )
55
51
  }
56
52
 
57
53
  function reportSentry(
@@ -63,39 +59,33 @@ function reportSentry(
63
59
  const scope = new Sentry.Scope()
64
60
  scope.setLevel(level)
65
61
  if (extras) scope.setContext("extras", extras)
66
- scope.setContext("error", tryToReport(error) as any)
67
- scope.setContext("cause", tryToJson(error.originalCause) as any)
62
+ scope.setContext("error", tryToReport(error))
63
+ scope.setContext("cause", tryToJson(error.originalCause))
68
64
  Sentry.captureException(error, scope)
69
65
  })
70
66
  }
71
67
 
72
- export function logError<E>(
73
- name: string
74
- ) {
75
- return (cause: Cause.Cause<E>, extras?: Record<string, unknown>) =>
76
- Effect
77
- .gen(function*() {
78
- if (Cause.hasInterruptsOnly(cause)) {
79
- yield* Effect.logDebug("Interrupted").pipe(Effect.annotateLogs(dropUndefined({ extras })))
80
- return
81
- }
82
- yield* Effect
83
- .logWarning("Logging error", cause)
84
- .pipe(
85
- Effect.annotateLogs(dropUndefined({
86
- extras,
87
- cause: tryToJson(cause),
88
- __error_name__: name
89
- }))
90
- )
91
- })
92
- .pipe(
93
- Effect.tapCause((cause) =>
94
- Effect.logError("Failed to log error", cause).pipe(
95
- Effect.tapCause(() => Effect.logFatal("Failed to log error cause"))
96
- )
97
- )
98
- )
68
+ export function logError<E>(name: string) {
69
+ return Effect.fnUntraced(
70
+ function*(cause: Cause.Cause<E>, extras?: Record<string, unknown>) {
71
+ if (Cause.hasInterruptsOnly(cause)) {
72
+ yield* Effect.logDebug("Interrupted").pipe(Effect.annotateLogs(dropUndefined({ extras })))
73
+ return
74
+ }
75
+ yield* Effect
76
+ .logWarning("Logging error", cause)
77
+ .pipe(Effect.annotateLogs(dropUndefined({
78
+ extras,
79
+ cause: tryToJson(cause),
80
+ __error_name__: name
81
+ })))
82
+ },
83
+ (effect) =>
84
+ Effect.tapCause(effect, (cause) =>
85
+ Effect.logError("Failed to log error", cause).pipe(
86
+ Effect.tapCause(() => Effect.logFatal("Failed to log error cause"))
87
+ ))
88
+ )
99
89
  }
100
90
 
101
91
  export function captureException(error: unknown, extras?: Record<string, unknown>) {
@@ -105,12 +95,10 @@ export function captureException(error: unknown, extras?: Record<string, unknown
105
95
  console.error(error, extras)
106
96
  }
107
97
 
108
- export function reportMessage(message: string, extras?: Record<string, unknown>) {
109
- return Effect.gen(function*() {
110
- const scope = new Sentry.Scope()
111
- if (extras) scope.setContext("extras", extras)
112
- Sentry.captureMessage(message, scope)
98
+ export const reportMessage = Effect.fnUntraced(function*(message: string, extras?: Record<string, unknown>) {
99
+ const scope = new Sentry.Scope()
100
+ if (extras) scope.setContext("extras", extras)
101
+ Sentry.captureMessage(message, scope)
113
102
 
114
- console.warn(message, extras)
115
- })
116
- }
103
+ console.warn(message, extras)
104
+ })
package/src/form.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createIntl, type IntlFormatters } from "@formatjs/intl"
2
- import type {} from "intl-messageformat"
2
+
3
3
  import { Cause, Exit, Option, pipe, S } from "effect-app"
4
4
  import type { Unbranded } from "effect-app/Schema/brand"
5
5
  import type { IsUnion } from "effect-app/utils"
@@ -22,7 +22,8 @@ function getObjectsAST(ast: S.AST.AST): S.AST.Objects | null {
22
22
  return null
23
23
  }
24
24
 
25
- export function convertIn(v: string | null, type?: "text" | "float" | "int") {
25
+ /** @deprecated Use OmegaForm instead */
26
+ export function convertIn(v: number | string | null, type?: "text" | "float" | "int") {
26
27
  return v === null ? "" : type === "text" ? v : `${v}`
27
28
  }
28
29
 
@@ -30,8 +31,10 @@ export function convertIn(v: string | null, type?: "text" | "float" | "int") {
30
31
  * Makes sure our international number format is converted to js int/float format.
31
32
  * Right now assumes . for thousands and , for decimal.
32
33
  */
34
+ /** @deprecated Use OmegaForm instead */
33
35
  export const prepareNumberForLocale = (v: string) => v.replace(/\./g, "").replace(/,/g, ".")
34
36
 
37
+ /** @deprecated Use OmegaForm instead */
35
38
  export function convertOutInt(v: string, type?: "text" | "float" | "int") {
36
39
  v = v == null ? v : v.trim()
37
40
  const c = v === ""
@@ -49,6 +52,7 @@ export function convertOutInt(v: string, type?: "text" | "float" | "int") {
49
52
  return c
50
53
  }
51
54
 
55
+ /** @deprecated Use OmegaForm instead */
52
56
  export function convertOut(v: string, set: (v: {} | null) => void, type?: "text" | "float" | "int") {
53
57
  return set(convertOutInt(v, type))
54
58
  }
@@ -72,7 +76,8 @@ export interface DiscriminatedUnionFieldInfo<T> {
72
76
  }
73
77
 
74
78
  export type NestedFieldInfoKey<Key> = [Key] extends [Record<PropertyKey, any>]
75
- ? Unbranded<Key> extends Record<PropertyKey, any> ? NestedFieldInfo<Key>
79
+ ? Unbranded<Key> extends (string | number | boolean | bigint | symbol) ? FieldInfo<Key>
80
+ : Unbranded<Key> extends Record<PropertyKey, any> ? NestedFieldInfo<Key>
76
81
  : FieldInfo<Key>
77
82
  : FieldInfo<Key>
78
83
 
@@ -143,10 +148,18 @@ function handlePropertySignature(
143
148
  const typeLiteral = getObjectsAST(ps.type)
144
149
 
145
150
  const tagPropertySignature = typeLiteral?.propertySignatures.find((_) => _.name === "_tag")
146
- const tagLiteral = tagPropertySignature
147
- && S.AST.isLiteral(tagPropertySignature.type)
148
- && typeof tagPropertySignature.type.literal === "string"
149
- ? tagPropertySignature.type.literal
151
+ // unwrap single-element Union to Literal (S.Struct({ _tag: S.Literal("x") }) wraps as Union([Literal("x")]))
152
+ const tagType = tagPropertySignature
153
+ ? S.AST.isUnion(tagPropertySignature.type)
154
+ && tagPropertySignature.type.types.length === 1
155
+ && S.AST.isLiteral(tagPropertySignature.type.types[0]!)
156
+ ? tagPropertySignature.type.types[0]
157
+ : tagPropertySignature.type
158
+ : undefined
159
+ const tagLiteral = tagType
160
+ && S.AST.isLiteral(tagType)
161
+ && typeof tagType.literal === "string"
162
+ ? tagType.literal
150
163
  : void 0
151
164
 
152
165
  const toRet = handlePropertySignature(ps)
@@ -189,6 +202,7 @@ function handlePropertySignature(
189
202
  }
190
203
  }
191
204
 
205
+ /** @deprecated Use OmegaForm instead */
192
206
  export function buildFieldInfoFromFields<
193
207
  From extends Record<PropertyKey, any>,
194
208
  To extends Record<PropertyKey, any>
@@ -198,6 +212,7 @@ export function buildFieldInfoFromFields<
198
212
  return buildFieldInfoFromFieldsRoot(schema).fields
199
213
  }
200
214
 
215
+ /** @deprecated Use OmegaForm instead */
201
216
  export function buildFieldInfoFromFieldsRoot<
202
217
  From extends Record<PropertyKey, any>,
203
218
  To extends Record<PropertyKey, any>,
@@ -235,7 +250,9 @@ abstract class PhantomTypeParameter<
235
250
 
236
251
  const defaultIntl = createIntl({ locale: "en" })
237
252
 
253
+ /** @deprecated Use OmegaForm instead */
238
254
  export const translate = ref<IntlFormatters["formatMessage"]>(defaultIntl.formatMessage)
255
+ /** @deprecated Use OmegaForm instead */
239
256
  export const customSchemaErrors = ref<Map<S.AST.AST | string, (message: string, e: unknown, v: unknown) => string>>(
240
257
  new Map()
241
258
  )
@@ -246,12 +263,12 @@ function buildFieldInfo(
246
263
  const propertyKey = property.name
247
264
  const schema = S.make<S.Codec<unknown>>(property.type)
248
265
  const metadata = getMetadataFromSchema(property.type)
249
- const parse = S.decodeUnknownExit(schema as S.Codec<unknown> & { readonly DecodingServices: never })
266
+ const parse = S.decodeUnknownExit(schema)
250
267
 
251
268
  const nullableOrUndefined = S.AST.isUnion(property.type)
252
269
  && (property.type.types.includes(S.Null.ast) || property.type.types.some((_) => _._tag === "Undefined"))
253
270
  const realSelf = nullableOrUndefined && S.AST.isUnion(property.type)
254
- ? property.type.types.filter((_) => _ !== S.Null.ast && _._tag !== "Undefined")[0]!
271
+ ? property.type.types.find((_) => _ !== S.Null.ast && _._tag !== "Undefined")!
255
272
  : property.type
256
273
  const id = S.AST.resolveIdentifier(property.type)
257
274
  const id2 = S.AST.resolveIdentifier(realSelf)
@@ -269,7 +286,7 @@ function buildFieldInfo(
269
286
  }
270
287
 
271
288
  // parse specific error types for better translation support
272
- const integerMatch = err.match(/Expected.*integer.*actual\s+(.+)/i)
289
+ const integerMatch = err.match(/Expected.*integer.*(?:actual|got)\s+([^)]+)/i)
273
290
  if (integerMatch) {
274
291
  return translate.value(
275
292
  { defaultMessage: "Expected an integer, actual {actualValue}", id: "validation.integer.expected" },
@@ -277,7 +294,7 @@ function buildFieldInfo(
277
294
  )
278
295
  }
279
296
 
280
- const numberMatch = err.match(/Expected.*number.*actual\s+(.+)/i)
297
+ const numberMatch = err.match(/Expected.*number.*(?:actual|got)\s+([^)]+)/i)
281
298
  if (numberMatch) {
282
299
  return translate.value(
283
300
  { defaultMessage: "Expected a number, actual {actualValue}", id: "validation.number.expected" },
@@ -368,7 +385,7 @@ function buildFieldInfo(
368
385
  : metadata.type === "float" || metadata.type === "int"
369
386
  ? numberRules
370
387
  : []) as UnknownRule[],
371
- parseRule as UnknownRule
388
+ parseRule
372
389
  ]
373
390
 
374
391
  const info = {
@@ -398,6 +415,7 @@ function buildFieldInfo(
398
415
  return info as any
399
416
  }
400
417
 
418
+ /** @deprecated Use OmegaForm instead */
401
419
  export function getMetadataFromSchema(
402
420
  ast: S.AST.AST
403
421
  ): {
@@ -411,22 +429,43 @@ export function getMetadataFromSchema(
411
429
  required: boolean
412
430
  description?: string
413
431
  } {
432
+ const findJsonSchemaType = (
433
+ schema: any,
434
+ target: "number" | "integer"
435
+ ): boolean => {
436
+ if (!schema || typeof schema !== "object") {
437
+ return false
438
+ }
439
+
440
+ if (schema.type === target) {
441
+ return true
442
+ }
443
+
444
+ if (Array.isArray(schema.type) && schema.type.includes(target)) {
445
+ return true
446
+ }
447
+
448
+ return ["anyOf", "oneOf", "allOf"].some((key) =>
449
+ Array.isArray(schema[key]) && schema[key].some((member: any) => findJsonSchemaType(member, target))
450
+ )
451
+ }
452
+
414
453
  const nullable = S.AST.isUnion(ast) && ast.types.includes(S.Null.ast)
415
454
  const realSelf = nullable && S.AST.isUnion(ast)
416
- ? ast.types.filter((_) => _ !== S.Null.ast)[0]!
455
+ ? ast.types.find((_) => _ !== S.Null.ast)!
417
456
  : ast
418
457
 
419
458
  let jschema: any
420
459
  try {
421
460
  const doc = S.toJsonSchemaDocument(S.make<S.Codec<unknown>>(realSelf))
422
461
  jschema = doc.schema as any
423
- const defs = doc.definitions as Record<string, any>
462
+ const defs = doc.definitions
424
463
  // resolve $ref against definitions
425
464
  while (jschema["$ref"] && jschema["$ref"].startsWith("#/$defs/")) {
426
465
  const { $ref: _, ...rest } = jschema
427
466
  jschema = { ...defs[jschema["$ref"].replace("#/$defs/", "")], ...rest }
428
467
  }
429
- } catch (_err) {
468
+ } catch {
430
469
  jschema = {}
431
470
  }
432
471
  // or we need to add these info directly in the refinement like the minimum
@@ -440,8 +479,8 @@ export function getMetadataFromSchema(
440
479
  // "title": "Int"
441
480
  // }
442
481
  // }
443
- const isNumber = jschema.type === "number" || jschema.type === "integer"
444
- const isInt = jschema.type === "integer"
482
+ const isInt = findJsonSchemaType(jschema, "integer")
483
+ const isNumber = isInt || findJsonSchemaType(jschema, "number")
445
484
  return {
446
485
  type: isInt ? "int" as const : isNumber ? "float" as const : "text" as const,
447
486
  minimum: jschema.minimum,
package/src/intl.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Context } from "effect-app"
2
+ import { accessCn, accessFn } from "effect-app/Context"
3
+ import { type MakeIntlReturn } from "./makeIntl.js"
4
+
5
+ type I18nShape = ReturnType<MakeIntlReturn<string>["useIntl"]>
6
+
7
+ export class I18n extends Context.Opaque<I18n, I18nShape>()("I18n") {
8
+ static readonly locale = accessCn(this, "locale")
9
+ static readonly trans = accessFn(this, "trans")
10
+ static readonly formatMessage = accessFn(this, "formatMessage")
11
+ static readonly intl = accessCn(this, "intl")
12
+ }
package/src/lib.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { type Pausable, useIntervalFn, type UseIntervalFnOptions } from "@vueuse/core"
2
- import { Cause, type Effect, pipe } from "effect-app"
3
- import { type Req } from "effect-app/client"
4
- import type { ClientForOptions, RequestHandler, RequestHandlerWithInput } from "effect-app/client/clientFor"
2
+ import { Cause, type Effect } from "effect-app"
3
+ import type { Req } from "effect-app/client"
4
+ import type { RequestHandlerWithInput } from "effect-app/client/clientFor"
5
5
  import { isHttpClientError } from "effect/unstable/http/HttpClientError"
6
- import type { MaybeRefOrGetter } from "vue"
6
+ import { isProxy, isReactive, isRef, type MaybeRefOrGetter, toRaw } from "vue"
7
7
  import { reportError } from "./errorReporter.js"
8
8
 
9
9
  export * as AsyncResult from "effect/unstable/reactivity/AsyncResult"
@@ -31,15 +31,7 @@ const determineLevel = (cause: Cause.Cause<unknown>) => {
31
31
  export const reportRuntimeError = (cause: Cause.Cause<unknown>, extras?: Record<string, unknown>) =>
32
32
  reportRuntimeError_(cause, extras, determineLevel(cause))
33
33
 
34
- // $Project/$Configuration.Index
35
- // -> "$Project", "$Configuration", "Index"
36
- export const makeQueryKey = ({ id, options }: { id: string; options?: ClientForOptions }) =>
37
- pipe(
38
- id.split("/"),
39
- (split) => split.filter((_) => !options || !options?.skipQueryKey?.includes(_)).map((_) => "$" + _)
40
- )
41
- .join(".")
42
- .split(".")
34
+ export { makeQueryKey } from "effect-app/client"
43
35
 
44
36
  export function pauseWhileProcessing(
45
37
  iv: Pausable,
@@ -75,13 +67,48 @@ export const mapHandler: {
75
67
  self: RequestHandlerWithInput<I, A, E, R, Request, Name>,
76
68
  map: (handler: (i: I) => Effect.Effect<A, E, R>) => (i: I) => Effect.Effect<A2, E2, R2>
77
69
  ): RequestHandlerWithInput<I, A2, E2, R2, Request, Name>
78
- <E, A, R, E2, A2, R2, Request extends Req, Name extends string>(
79
- self: RequestHandler<A, E, R, Request, Name>,
80
- map: (handler: Effect.Effect<A, E, R>) => Effect.Effect<A2, E2, R2>
81
- ): RequestHandler<A2, E2, R2, Request, Name>
82
70
  } = (self: any, map: any): any => ({
83
71
  ...self,
84
- handler: typeof self.handler === "function"
85
- ? (i: any) => map(self.handler as (i: any) => Effect.Effect<any, any, any>)(i)
86
- : map(self.handler)
72
+ handler: (i: any) => map(self.handler as (i: any) => Effect.Effect<any, any, any>)(i)
87
73
  })
74
+
75
+ export function deepToRaw<T>(sourceObj: T): T {
76
+ const objectIterator = (input: any): any => {
77
+ if (isRef(input)) {
78
+ return objectIterator(input.value)
79
+ }
80
+
81
+ const rawInput = isReactive(input) || isProxy(input)
82
+ ? toRaw(input)
83
+ : input
84
+
85
+ if (Array.isArray(rawInput)) {
86
+ return rawInput.map((item) => objectIterator(item))
87
+ }
88
+
89
+ if (rawInput instanceof Map) {
90
+ return new Map(
91
+ Array.from(rawInput.entries(), ([key, value]) => [objectIterator(key), objectIterator(value)])
92
+ )
93
+ }
94
+
95
+ if (rawInput instanceof Set) {
96
+ return new Set(Array.from(rawInput.values(), (value) => objectIterator(value)))
97
+ }
98
+
99
+ if (rawInput instanceof Date) {
100
+ return new Date(rawInput)
101
+ }
102
+
103
+ if (rawInput && typeof rawInput === "object") {
104
+ return Object.keys(rawInput).reduce((acc, key) => {
105
+ acc[key] = objectIterator(rawInput[key])
106
+ return acc
107
+ }, {} as Record<string, unknown>)
108
+ }
109
+
110
+ return rawInput
111
+ }
112
+
113
+ return objectIterator(sourceObj)
114
+ }