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

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 +700 -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 +11 -3
  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} +827 -203
  37. package/src/{experimental/confirm.ts → confirm.ts} +2 -2
  38. package/src/form.ts +52 -15
  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 +287 -77
  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
@@ -1,7 +1,6 @@
1
1
  import { createIntl, type IntlFormatters } from "@formatjs/intl"
2
2
  import type {} from "intl-messageformat"
3
3
  import { Cause, Exit, Option, pipe, S } from "effect-app"
4
- import type { Schema } from "effect-app/Schema"
5
4
  import type { Unbranded } from "effect-app/Schema/brand"
6
5
  import type { IsUnion } from "effect-app/utils"
7
6
  import { capitalize, ref } from "vue"
@@ -23,6 +22,7 @@ function getObjectsAST(ast: S.AST.AST): S.AST.Objects | null {
23
22
  return null
24
23
  }
25
24
 
25
+ /** @deprecated Use OmegaForm instead */
26
26
  export function convertIn(v: string | null, type?: "text" | "float" | "int") {
27
27
  return v === null ? "" : type === "text" ? v : `${v}`
28
28
  }
@@ -31,8 +31,10 @@ export function convertIn(v: string | null, type?: "text" | "float" | "int") {
31
31
  * Makes sure our international number format is converted to js int/float format.
32
32
  * Right now assumes . for thousands and , for decimal.
33
33
  */
34
+ /** @deprecated Use OmegaForm instead */
34
35
  export const prepareNumberForLocale = (v: string) => v.replace(/\./g, "").replace(/,/g, ".")
35
36
 
37
+ /** @deprecated Use OmegaForm instead */
36
38
  export function convertOutInt(v: string, type?: "text" | "float" | "int") {
37
39
  v = v == null ? v : v.trim()
38
40
  const c = v === ""
@@ -50,6 +52,7 @@ export function convertOutInt(v: string, type?: "text" | "float" | "int") {
50
52
  return c
51
53
  }
52
54
 
55
+ /** @deprecated Use OmegaForm instead */
53
56
  export function convertOut(v: string, set: (v: {} | null) => void, type?: "text" | "float" | "int") {
54
57
  return set(convertOutInt(v, type))
55
58
  }
@@ -122,7 +125,7 @@ function handlePropertySignature(
122
125
  switch (schema.ast._tag) {
123
126
  case "Objects": {
124
127
  return buildFieldInfoFromFieldsRoot(
125
- schema as S.Schema<Record<PropertyKey, any>>
128
+ schema as S.Codec<Record<PropertyKey, any>>
126
129
  )
127
130
  }
128
131
  case "Union": {
@@ -144,10 +147,18 @@ function handlePropertySignature(
144
147
  const typeLiteral = getObjectsAST(ps.type)
145
148
 
146
149
  const tagPropertySignature = typeLiteral?.propertySignatures.find((_) => _.name === "_tag")
147
- const tagLiteral = tagPropertySignature
148
- && S.AST.isLiteral(tagPropertySignature.type)
149
- && typeof tagPropertySignature.type.literal === "string"
150
- ? 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
151
162
  : void 0
152
163
 
153
164
  const toRet = handlePropertySignature(ps)
@@ -190,21 +201,23 @@ function handlePropertySignature(
190
201
  }
191
202
  }
192
203
 
204
+ /** @deprecated Use OmegaForm instead */
193
205
  export function buildFieldInfoFromFields<
194
206
  From extends Record<PropertyKey, any>,
195
207
  To extends Record<PropertyKey, any>
196
208
  >(
197
- schema: (Schema<To> | S.Codec<To, From>) & { fields?: S.Struct.Fields }
209
+ schema: (S.Codec<To, From>) & { fields?: S.Struct.Fields }
198
210
  ) {
199
211
  return buildFieldInfoFromFieldsRoot(schema).fields
200
212
  }
201
213
 
214
+ /** @deprecated Use OmegaForm instead */
202
215
  export function buildFieldInfoFromFieldsRoot<
203
216
  From extends Record<PropertyKey, any>,
204
217
  To extends Record<PropertyKey, any>,
205
218
  R
206
219
  >(
207
- schema: (Schema<To> | S.Codec<To, From, R>) & { fields?: S.Struct.Fields }
220
+ schema: (S.Codec<To, From, R>) & { fields?: S.Struct.Fields }
208
221
  ): NestedFieldInfo<To> {
209
222
  const ast = getObjectsAST(schema.ast)
210
223
 
@@ -236,7 +249,9 @@ abstract class PhantomTypeParameter<
236
249
 
237
250
  const defaultIntl = createIntl({ locale: "en" })
238
251
 
252
+ /** @deprecated Use OmegaForm instead */
239
253
  export const translate = ref<IntlFormatters["formatMessage"]>(defaultIntl.formatMessage)
254
+ /** @deprecated Use OmegaForm instead */
240
255
  export const customSchemaErrors = ref<Map<S.AST.AST | string, (message: string, e: unknown, v: unknown) => string>>(
241
256
  new Map()
242
257
  )
@@ -245,9 +260,9 @@ function buildFieldInfo(
245
260
  property: S.AST.PropertySignature
246
261
  ): FieldInfo<any> {
247
262
  const propertyKey = property.name
248
- const schema = S.make<S.Schema<unknown>>(property.type)
263
+ const schema = S.make<S.Codec<unknown>>(property.type)
249
264
  const metadata = getMetadataFromSchema(property.type)
250
- const parse = S.decodeUnknownExit(schema as S.Schema<unknown> & { readonly DecodingServices: never })
265
+ const parse = S.decodeUnknownExit(schema as S.Codec<unknown> & { readonly DecodingServices: never })
251
266
 
252
267
  const nullableOrUndefined = S.AST.isUnion(property.type)
253
268
  && (property.type.types.includes(S.Null.ast) || property.type.types.some((_) => _._tag === "Undefined"))
@@ -270,7 +285,7 @@ function buildFieldInfo(
270
285
  }
271
286
 
272
287
  // parse specific error types for better translation support
273
- const integerMatch = err.match(/Expected.*integer.*actual\s+(.+)/i)
288
+ const integerMatch = err.match(/Expected.*integer.*(?:actual|got)\s+([^)]+)/i)
274
289
  if (integerMatch) {
275
290
  return translate.value(
276
291
  { defaultMessage: "Expected an integer, actual {actualValue}", id: "validation.integer.expected" },
@@ -278,7 +293,7 @@ function buildFieldInfo(
278
293
  )
279
294
  }
280
295
 
281
- const numberMatch = err.match(/Expected.*number.*actual\s+(.+)/i)
296
+ const numberMatch = err.match(/Expected.*number.*(?:actual|got)\s+([^)]+)/i)
282
297
  if (numberMatch) {
283
298
  return translate.value(
284
299
  { defaultMessage: "Expected a number, actual {actualValue}", id: "validation.number.expected" },
@@ -399,6 +414,7 @@ function buildFieldInfo(
399
414
  return info as any
400
415
  }
401
416
 
417
+ /** @deprecated Use OmegaForm instead */
402
418
  export function getMetadataFromSchema(
403
419
  ast: S.AST.AST
404
420
  ): {
@@ -412,6 +428,27 @@ export function getMetadataFromSchema(
412
428
  required: boolean
413
429
  description?: string
414
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
+
415
452
  const nullable = S.AST.isUnion(ast) && ast.types.includes(S.Null.ast)
416
453
  const realSelf = nullable && S.AST.isUnion(ast)
417
454
  ? ast.types.filter((_) => _ !== S.Null.ast)[0]!
@@ -419,7 +456,7 @@ export function getMetadataFromSchema(
419
456
 
420
457
  let jschema: any
421
458
  try {
422
- const doc = S.toJsonSchemaDocument(S.make<S.Schema<unknown>>(realSelf))
459
+ const doc = S.toJsonSchemaDocument(S.make<S.Codec<unknown>>(realSelf))
423
460
  jschema = doc.schema as any
424
461
  const defs = doc.definitions as Record<string, any>
425
462
  // resolve $ref against definitions
@@ -441,8 +478,8 @@ export function getMetadataFromSchema(
441
478
  // "title": "Int"
442
479
  // }
443
480
  // }
444
- const isNumber = jschema.type === "number" || jschema.type === "integer"
445
- const isInt = jschema.type === "integer"
481
+ const isInt = findJsonSchemaType(jschema, "integer")
482
+ const isNumber = isInt || findJsonSchemaType(jschema, "number")
446
483
  return {
447
484
  type: isInt ? "int" as const : isNumber ? "float" as const : "text" as const,
448
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
+ }