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