@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.
- package/CHANGELOG.md +1605 -0
- package/dist/commander.d.ts +628 -0
- package/dist/commander.d.ts.map +1 -0
- package/dist/commander.js +1060 -0
- package/dist/confirm.d.ts +19 -0
- package/dist/confirm.d.ts.map +1 -0
- package/dist/confirm.js +24 -0
- package/dist/errorReporter.d.ts +4 -4
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +12 -18
- package/dist/form.d.ts +14 -5
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +41 -12
- 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 +6 -9
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +35 -10
- package/dist/makeClient.d.ts +152 -339
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +221 -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 +8 -0
- package/dist/makeUseCommand.d.ts.map +1 -0
- package/dist/makeUseCommand.js +13 -0
- package/dist/mutate.d.ts +52 -34
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +137 -46
- package/dist/query.d.ts +19 -39
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +128 -72
- package/dist/routeParams.d.ts +1 -1
- package/dist/runtime.d.ts +7 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +27 -17
- package/dist/toast.d.ts +50 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +32 -0
- package/dist/withToast.d.ts +27 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +59 -0
- package/examples/streamMutation.ts +70 -0
- package/package.json +48 -50
- package/src/commander.ts +3393 -0
- package/src/{experimental/confirm.ts → confirm.ts} +10 -14
- package/src/errorReporter.ts +62 -74
- package/src/form.ts +56 -17
- package/src/intl.ts +12 -0
- package/src/lib.ts +47 -20
- package/src/makeClient.ts +568 -1134
- package/src/{experimental/makeUseCommand.ts → makeUseCommand.ts} +6 -4
- package/src/mutate.ts +265 -127
- package/src/query.ts +197 -183
- package/src/runtime.ts +41 -20
- package/src/{experimental/toast.ts → toast.ts} +13 -27
- package/src/{experimental/withToast.ts → withToast.ts} +40 -12
- package/test/Mutation.test.ts +176 -23
- 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 +3529 -122
- package/test/dist/stubs.d.ts.map +1 -1
- package/test/dist/stubs.js +182 -31
- package/test/form-validation-errors.test.ts +23 -19
- package/test/form.test.ts +20 -2
- package/test/lib.test.ts +240 -0
- package/test/makeClient.test.ts +292 -38
- package/test/streamFinal.test.ts +63 -0
- package/test/streamFn.test.ts +455 -0
- package/test/stubs.ts +218 -42
- 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,8 @@
|
|
|
1
|
-
import { Effect, Layer
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
}
|
package/src/errorReporter.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
)
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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)
|
|
67
|
-
scope.setContext("cause", tryToJson(error.originalCause)
|
|
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
|
-
|
|
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
|
-
)
|
|
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
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
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.
|
|
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+(
|
|
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+(
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
444
|
-
const
|
|
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
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
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
|
|
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
|
-
|
|
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:
|
|
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
|
+
}
|