@effect-app/vue 4.0.0-beta.9 → 4.0.0-beta.90

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 (70) hide show
  1. package/CHANGELOG.md +576 -0
  2. package/dist/{experimental/commander.d.ts → commander.d.ts} +53 -53
  3. package/dist/commander.d.ts.map +1 -0
  4. package/dist/commander.js +556 -0
  5. package/dist/{experimental/confirm.d.ts → confirm.d.ts} +2 -2
  6. package/dist/confirm.d.ts.map +1 -0
  7. package/dist/confirm.js +28 -0
  8. package/dist/form.d.ts +9 -0
  9. package/dist/form.d.ts.map +1 -1
  10. package/dist/form.js +38 -9
  11. package/dist/intl.d.ts +15 -0
  12. package/dist/intl.d.ts.map +1 -0
  13. package/dist/intl.js +9 -0
  14. package/dist/makeClient.d.ts +18 -241
  15. package/dist/makeClient.d.ts.map +1 -1
  16. package/dist/makeClient.js +12 -335
  17. package/dist/{experimental/makeUseCommand.d.ts → makeUseCommand.d.ts} +1 -1
  18. package/dist/makeUseCommand.d.ts.map +1 -0
  19. package/dist/makeUseCommand.js +13 -0
  20. package/dist/mutate.d.ts +1 -1
  21. package/dist/mutate.d.ts.map +1 -1
  22. package/dist/mutate.js +2 -2
  23. package/dist/query.d.ts +10 -14
  24. package/dist/query.d.ts.map +1 -1
  25. package/dist/query.js +23 -23
  26. package/dist/runtime.d.ts +3 -0
  27. package/dist/runtime.d.ts.map +1 -1
  28. package/dist/runtime.js +15 -3
  29. package/dist/{experimental/toast.d.ts → toast.d.ts} +9 -10
  30. package/dist/toast.d.ts.map +1 -0
  31. package/dist/toast.js +32 -0
  32. package/dist/{experimental/withToast.d.ts → withToast.d.ts} +3 -3
  33. package/dist/withToast.d.ts.map +1 -0
  34. package/dist/withToast.js +45 -0
  35. package/package.json +43 -43
  36. package/src/{experimental/commander.ts → commander.ts} +826 -202
  37. package/src/{experimental/confirm.ts → confirm.ts} +2 -2
  38. package/src/form.ts +46 -8
  39. package/src/intl.ts +12 -0
  40. package/src/makeClient.ts +27 -924
  41. package/src/{experimental/makeUseCommand.ts → makeUseCommand.ts} +1 -1
  42. package/src/mutate.ts +1 -1
  43. package/src/query.ts +44 -45
  44. package/src/runtime.ts +25 -2
  45. package/src/{experimental/toast.ts → toast.ts} +11 -25
  46. package/src/{experimental/withToast.ts → withToast.ts} +3 -3
  47. package/test/Mutation.test.ts +77 -7
  48. package/test/dist/form.test.d.ts.map +1 -1
  49. package/test/dist/stubs.d.ts +273 -67
  50. package/test/dist/stubs.d.ts.map +1 -1
  51. package/test/dist/stubs.js +34 -15
  52. package/test/form-validation-errors.test.ts +23 -19
  53. package/test/form.test.ts +20 -2
  54. package/test/makeClient.test.ts +38 -23
  55. package/test/stubs.ts +45 -18
  56. package/tsconfig.json +0 -1
  57. package/dist/experimental/commander.d.ts.map +0 -1
  58. package/dist/experimental/commander.js +0 -558
  59. package/dist/experimental/confirm.d.ts.map +0 -1
  60. package/dist/experimental/confirm.js +0 -28
  61. package/dist/experimental/intl.d.ts +0 -16
  62. package/dist/experimental/intl.d.ts.map +0 -1
  63. package/dist/experimental/intl.js +0 -5
  64. package/dist/experimental/makeUseCommand.d.ts.map +0 -1
  65. package/dist/experimental/makeUseCommand.js +0 -13
  66. package/dist/experimental/toast.d.ts.map +0 -1
  67. package/dist/experimental/toast.js +0 -41
  68. package/dist/experimental/withToast.d.ts.map +0 -1
  69. package/dist/experimental/withToast.js +0 -45
  70. 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
 
package/src/form.ts CHANGED
@@ -22,6 +22,7 @@ function getObjectsAST(ast: S.AST.AST): S.AST.Objects | null {
22
22
  return null
23
23
  }
24
24
 
25
+ /** @deprecated Use OmegaForm instead */
25
26
  export function convertIn(v: string | null, type?: "text" | "float" | "int") {
26
27
  return v === null ? "" : type === "text" ? v : `${v}`
27
28
  }
@@ -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
  }
@@ -143,10 +147,18 @@ function handlePropertySignature(
143
147
  const typeLiteral = getObjectsAST(ps.type)
144
148
 
145
149
  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
150
+ // unwrap single-element Union to Literal (S.Struct({ _tag: S.Literal("x") }) wraps as Union([Literal("x")]))
151
+ const tagType = tagPropertySignature
152
+ ? S.AST.isUnion(tagPropertySignature.type)
153
+ && tagPropertySignature.type.types.length === 1
154
+ && S.AST.isLiteral(tagPropertySignature.type.types[0]!)
155
+ ? tagPropertySignature.type.types[0]
156
+ : tagPropertySignature.type
157
+ : undefined
158
+ const tagLiteral = tagType
159
+ && S.AST.isLiteral(tagType)
160
+ && typeof tagType.literal === "string"
161
+ ? tagType.literal
150
162
  : void 0
151
163
 
152
164
  const toRet = handlePropertySignature(ps)
@@ -189,6 +201,7 @@ function handlePropertySignature(
189
201
  }
190
202
  }
191
203
 
204
+ /** @deprecated Use OmegaForm instead */
192
205
  export function buildFieldInfoFromFields<
193
206
  From extends Record<PropertyKey, any>,
194
207
  To extends Record<PropertyKey, any>
@@ -198,6 +211,7 @@ export function buildFieldInfoFromFields<
198
211
  return buildFieldInfoFromFieldsRoot(schema).fields
199
212
  }
200
213
 
214
+ /** @deprecated Use OmegaForm instead */
201
215
  export function buildFieldInfoFromFieldsRoot<
202
216
  From extends Record<PropertyKey, any>,
203
217
  To extends Record<PropertyKey, any>,
@@ -235,7 +249,9 @@ abstract class PhantomTypeParameter<
235
249
 
236
250
  const defaultIntl = createIntl({ locale: "en" })
237
251
 
252
+ /** @deprecated Use OmegaForm instead */
238
253
  export const translate = ref<IntlFormatters["formatMessage"]>(defaultIntl.formatMessage)
254
+ /** @deprecated Use OmegaForm instead */
239
255
  export const customSchemaErrors = ref<Map<S.AST.AST | string, (message: string, e: unknown, v: unknown) => string>>(
240
256
  new Map()
241
257
  )
@@ -269,7 +285,7 @@ function buildFieldInfo(
269
285
  }
270
286
 
271
287
  // parse specific error types for better translation support
272
- const integerMatch = err.match(/Expected.*integer.*actual\s+(.+)/i)
288
+ const integerMatch = err.match(/Expected.*integer.*(?:actual|got)\s+([^)]+)/i)
273
289
  if (integerMatch) {
274
290
  return translate.value(
275
291
  { defaultMessage: "Expected an integer, actual {actualValue}", id: "validation.integer.expected" },
@@ -277,7 +293,7 @@ function buildFieldInfo(
277
293
  )
278
294
  }
279
295
 
280
- const numberMatch = err.match(/Expected.*number.*actual\s+(.+)/i)
296
+ const numberMatch = err.match(/Expected.*number.*(?:actual|got)\s+([^)]+)/i)
281
297
  if (numberMatch) {
282
298
  return translate.value(
283
299
  { defaultMessage: "Expected a number, actual {actualValue}", id: "validation.number.expected" },
@@ -398,6 +414,7 @@ function buildFieldInfo(
398
414
  return info as any
399
415
  }
400
416
 
417
+ /** @deprecated Use OmegaForm instead */
401
418
  export function getMetadataFromSchema(
402
419
  ast: S.AST.AST
403
420
  ): {
@@ -411,6 +428,27 @@ export function getMetadataFromSchema(
411
428
  required: boolean
412
429
  description?: string
413
430
  } {
431
+ const findJsonSchemaType = (
432
+ schema: any,
433
+ target: "number" | "integer"
434
+ ): boolean => {
435
+ if (!schema || typeof schema !== "object") {
436
+ return false
437
+ }
438
+
439
+ if (schema.type === target) {
440
+ return true
441
+ }
442
+
443
+ if (Array.isArray(schema.type) && schema.type.includes(target)) {
444
+ return true
445
+ }
446
+
447
+ return ["anyOf", "oneOf", "allOf"].some((key) =>
448
+ Array.isArray(schema[key]) && schema[key].some((member: any) => findJsonSchemaType(member, target))
449
+ )
450
+ }
451
+
414
452
  const nullable = S.AST.isUnion(ast) && ast.types.includes(S.Null.ast)
415
453
  const realSelf = nullable && S.AST.isUnion(ast)
416
454
  ? ast.types.filter((_) => _ !== S.Null.ast)[0]!
@@ -440,8 +478,8 @@ export function getMetadataFromSchema(
440
478
  // "title": "Int"
441
479
  // }
442
480
  // }
443
- const isNumber = jschema.type === "number" || jschema.type === "integer"
444
- const isInt = jschema.type === "integer"
481
+ const isInt = findJsonSchemaType(jschema, "integer")
482
+ const isNumber = isInt || findJsonSchemaType(jschema, "number")
445
483
  return {
446
484
  type: isInt ? "int" as const : isNumber ? "float" as const : "text" as const,
447
485
  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
+ }