@effect-app/vue 0.87.0-next.8 → 0.87.0
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 +492 -0
- package/_cjs/form.cjs +149 -1
- package/_cjs/form.cjs.map +1 -1
- package/_cjs/hooks.cjs +9 -3
- package/_cjs/hooks.cjs.map +1 -1
- package/_src/form.ts +231 -174
- package/_src/hooks.ts +18 -8
- package/dist/form.d.ts +26 -4
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +164 -2
- package/dist/hooks.d.ts +8 -7
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +12 -4
- package/package.json +15 -14
package/_cjs/hooks.cjs
CHANGED
|
@@ -73,10 +73,16 @@ function useSafeQueryWithArg(self, arg, config) {
|
|
|
73
73
|
return useSafeQueryWithArg_(self, self.mapPath, arg, config);
|
|
74
74
|
}
|
|
75
75
|
function useSafeQuery(self, config) {
|
|
76
|
-
return useSafeQuery_(self.mapPath, self, config);
|
|
76
|
+
return useSafeQuery_(self.mapPath, () => self, config);
|
|
77
77
|
}
|
|
78
78
|
function useSafeQueryWithArg_(self, mapPath, arg, config) {
|
|
79
|
-
|
|
79
|
+
const arr = arg;
|
|
80
|
+
const r = typeof arr === "function" ? {
|
|
81
|
+
get value() {
|
|
82
|
+
return arr();
|
|
83
|
+
}
|
|
84
|
+
} : (0, _vue.ref)(arg);
|
|
85
|
+
return useSafeQuery_((0, _vue.computed)(() => mapPath(r.value)), () => self(r.value), config);
|
|
80
86
|
}
|
|
81
87
|
function useSafeQuery_(key, self, config) {
|
|
82
88
|
// const [result, latestSuccess, execute] = make(self)
|
|
@@ -107,7 +113,7 @@ function useSafeQuery_(key, self, config) {
|
|
|
107
113
|
// })
|
|
108
114
|
// }
|
|
109
115
|
// const swr = useSWRV<A, E>(key, () => execWithInterruption().then(_ => _?.body as any)) // Effect.runPromise(self.provide(Layers))
|
|
110
|
-
const swr = useSWRV(key, () => _internal.run.value(self).then(_ => _.body), config);
|
|
116
|
+
const swr = useSWRV(key, () => _internal.run.value(self()).then(_ => _.body), config);
|
|
111
117
|
const result = (0, _vue.computed)(() => swrToQuery({
|
|
112
118
|
data: swr.data.value,
|
|
113
119
|
error: swr.error.value,
|
package/_cjs/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":["swrv","_interopRequireWildcard","require","_vue","_internal","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","useSWRV","mutate","exports","swrToQuery","error","isValidating","tsplus_module_1","Refreshing","fail","data","Done","undefined","succeed","Loading","Initial","useMutate","self","fn","run","value","then","_","body","mapPath","useMutateWithArg","arg","useSafeQueryWithArg","config","useSafeQueryWithArg_","useSafeQuery","useSafeQuery_","key","swr","result","
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":["swrv","_interopRequireWildcard","require","_vue","_internal","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","useSWRV","mutate","exports","swrToQuery","error","isValidating","tsplus_module_1","Refreshing","fail","data","Done","undefined","succeed","Loading","Initial","useMutate","self","fn","run","value","then","_","body","mapPath","useMutateWithArg","arg","useSafeQueryWithArg","config","useSafeQueryWithArg_","useSafeQuery","useSafeQuery_","arr","ref","computed","key","swr","result","latestSuccess","tsplus_module_2","isSuccess","tsplus_module_3","isRight","current","right","tsplus_module_4","isSome","previous","tsplus_module_5","tuple","useSafeQueryLegacy","execute","make","sem","tsplus_module_6","unsafeMakeSemaphore","withPermit","withPermits","fib","runNew","tap","fork","newFiber","sync","ex","flatMap","suspend","zipRight","tsplus_module_7","interrupt","pipe","await","exec","catch","err","JSON","stringify","includes","shallowRef","isInitializing","queryResult","map","hasValue","useMutation","state","_tag","handleExit","exit","tsplus_module_8","tsplus_module_9","failureOption","cause","left","died","dieOption","tsplus_module_10","getOrUndefined","interrupted","interruptOption","InterruptedException","Error","fst","snd","effect","abortSignal","f","cancel","addEventListener","console","join"],"sources":["../_src/hooks.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,IAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAAmC,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA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kC,eAAA,CAAAW,OAAA,CAAAX,eAAA,CAAAO,IAAA,CAAAP,eAAA,CAAAW,OAAA,CAAAX,eAAA,CAAAiC,IAAA,CAAAjC,eAAA,CAAAa,QAAA,CAAAb,eAAA,CAAAS,IAAA,CACQ,MAAK;MACTqB,KAAK,CAAChE,KAAK,GAAG;QAAEiE,IAAI,EAAE;MAAS,CAAE;IACnC,CAAC,CAAC,EACQkB,MAAM,CAAC,GAERjB,UAAU,CAAC,GAEVmB,CAAC,IAAI;MACb,MAAMC,MAAM,GAAGA,CAAA,KAAMvF,aAAG,CAACC,KAAK,CAAAgD,eAAA,CAAAC,SAAA,CAACoC,CAAC,EAAW;MAC3CD,WAAW,EAAEG,gBAAgB,CAAC,OAAO,EAAE,MAAM,KAAKD,MAAM,EAAE,CAACjC,KAAK,CAACmC,OAAO,CAACvG,KAAK,CAAC,CAAC;MAChF,OAAA+D,eAAA,CAAAyC,IAAA,CAAOJ,CAAC;IACV,CAAC,CAAC,CACL;EACH,CAAC;EAED,OAAOzD,eAAA,CAAAC,KAAK,CACVmC,KAAK,EACLZ,IAAI,CACL;AACH,CAAC;AAAArE,OAAA,CAAAgF,WAAA,GAAAA,WAAA"}
|
package/_src/form.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { AST, S } from "@effect-app/schema"
|
|
1
2
|
import type { Schema } from "@effect-app/schema"
|
|
2
3
|
import { createIntl, type IntlFormatters } from "@formatjs/intl"
|
|
3
|
-
import {
|
|
4
|
+
import type { Ref } from "vue"
|
|
5
|
+
import { capitalize, ref, watch } from "vue"
|
|
6
|
+
|
|
7
|
+
import * as JSONSchema from "@effect/schema/JSONSchema"
|
|
8
|
+
import type { ParseError } from "@effect/schema/ParseResult"
|
|
4
9
|
|
|
5
10
|
export function convertIn(v: string | null, type?: "text" | "float" | "int") {
|
|
6
11
|
return v === null ? "" : type === "text" ? v : `${v}`
|
|
@@ -16,22 +21,27 @@ export function convertOut(v: string, set: (v: unknown | null) => void, type?: "
|
|
|
16
21
|
return set(convertOutInt(v, type))
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
export function buildFieldInfoFromFields<From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>>(
|
|
25
|
+
fields: Schema<From, To>
|
|
26
|
+
) {
|
|
27
|
+
let ast = fields.ast
|
|
28
|
+
// todo: or look at from?
|
|
29
|
+
if (AST.isTransform(ast)) {
|
|
30
|
+
if (AST.isDeclaration(ast.to)) {
|
|
31
|
+
ast = ast.to.type
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!AST.isTypeLiteral(ast)) throw new Error("not a struct type")
|
|
35
|
+
return ast.propertySignatures.reduce(
|
|
36
|
+
(prev, cur) => {
|
|
37
|
+
;(prev as any)[cur.name] = buildFieldInfo(cur)
|
|
38
|
+
return prev
|
|
39
|
+
},
|
|
40
|
+
{} as {
|
|
41
|
+
[K in keyof To]: FieldInfo<To[K]>
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
}
|
|
35
45
|
|
|
36
46
|
export interface FieldMetadata {
|
|
37
47
|
minLength: number | undefined
|
|
@@ -48,7 +58,7 @@ abstract class PhantomTypeParameter<
|
|
|
48
58
|
readonly [NameP in Identifier]: (_: InstantiatedType) => InstantiatedType
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
|
-
export interface FieldInfo<
|
|
61
|
+
export interface FieldInfo<Tout> extends PhantomTypeParameter<typeof f, { out: Tout }> {
|
|
52
62
|
rules: ((v: string) => boolean | string)[]
|
|
53
63
|
metadata: FieldMetadata
|
|
54
64
|
type: "text" | "float" | "int" // todo; multi-line vs single line text
|
|
@@ -59,162 +69,209 @@ export interface FieldInfo<Tin, Tout> extends PhantomTypeParameter<typeof f, { i
|
|
|
59
69
|
|
|
60
70
|
const defaultIntl = createIntl({ locale: "en" })
|
|
61
71
|
export const translate = ref<IntlFormatters["formatMessage"]>(defaultIntl.formatMessage.bind(defaultIntl))
|
|
62
|
-
export const customSchemaErrors = ref<Map<
|
|
72
|
+
export const customSchemaErrors = ref<Map<AST.AST, (message: string, e: unknown, v: unknown) => string>>(
|
|
63
73
|
new Map()
|
|
64
74
|
)
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
76
|
+
function buildFieldInfo(
|
|
77
|
+
property: AST.PropertySignature
|
|
78
|
+
): FieldInfo<any> {
|
|
79
|
+
const propertyKey = property.name
|
|
80
|
+
const schema = S.make(property.type)
|
|
81
|
+
const metadata = getMetadataFromSchema(property.type) // TODO
|
|
82
|
+
const parse = schema.parseEither
|
|
83
|
+
|
|
84
|
+
const nullable = AST.isUnion(property.type) && property.type.types.includes(S.null.ast)
|
|
85
|
+
const realSelf = nullable && AST.isUnion(property.type)
|
|
86
|
+
? property.type.types.filter((_) => _ !== S.null.ast)[0]!
|
|
87
|
+
: property.type
|
|
88
|
+
|
|
89
|
+
function renderError(e: ParseError, v: unknown) {
|
|
90
|
+
const err = e.toString()
|
|
91
|
+
const custom = customSchemaErrors.value.get(realSelf)
|
|
92
|
+
return custom ? custom(err, e, v) : translate.value(
|
|
93
|
+
{ defaultMessage: "The entered value is not a valid {type}: {message}", id: "validation.not_a_valid" },
|
|
94
|
+
{
|
|
95
|
+
type: translate.value({
|
|
96
|
+
defaultMessage: capitalize(propertyKey.toString()),
|
|
97
|
+
id: `fieldNames.${String(propertyKey)}`
|
|
98
|
+
}),
|
|
99
|
+
message: metadata.description ? "expected " + metadata.description : err.slice(err.indexOf("Expected")) // TODO: this is not translated.
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const stringRules = [
|
|
105
|
+
(v: string | null) =>
|
|
106
|
+
v === null
|
|
107
|
+
|| metadata.minLength === undefined
|
|
108
|
+
|| v.length >= metadata.minLength
|
|
109
|
+
|| translate.value({
|
|
110
|
+
defaultMessage: "The field requires at least {minLength} characters",
|
|
111
|
+
id: "validation.string.minLength"
|
|
112
|
+
}, {
|
|
113
|
+
minLength: metadata.minLength
|
|
114
|
+
}),
|
|
115
|
+
(v: string | null) =>
|
|
116
|
+
v === null
|
|
117
|
+
|| metadata.maxLength === undefined
|
|
118
|
+
|| v.length <= metadata.maxLength
|
|
119
|
+
|| translate.value({
|
|
120
|
+
defaultMessage: "The field cannot have more than {maxLength} characters",
|
|
121
|
+
id: "validation.string.maxLength"
|
|
122
|
+
}, {
|
|
123
|
+
maxLength: metadata.maxLength
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
const numberRules = [
|
|
128
|
+
(v: number | null) =>
|
|
129
|
+
v === null
|
|
130
|
+
|| (metadata.minimum === undefined && metadata.exclusiveMinimum === undefined)
|
|
131
|
+
|| metadata.exclusiveMinimum !== undefined && v > metadata.exclusiveMinimum
|
|
132
|
+
|| metadata.minimum !== undefined && v >= metadata.minimum
|
|
133
|
+
|| translate.value({
|
|
134
|
+
defaultMessage: "The value should be {isExclusive, select, true {larger than} other {at least}} {minimum}",
|
|
135
|
+
id: "validation.number.min"
|
|
136
|
+
}, {
|
|
137
|
+
isExclusive: metadata.exclusiveMinimum !== undefined,
|
|
138
|
+
minimum: metadata.exclusiveMinimum ?? metadata.minimum
|
|
139
|
+
}),
|
|
140
|
+
(v: number | null) =>
|
|
141
|
+
v === null
|
|
142
|
+
|| (metadata.maximum === undefined && metadata.exclusiveMaximum === undefined)
|
|
143
|
+
|| metadata.exclusiveMaximum !== undefined && v < metadata.exclusiveMaximum
|
|
144
|
+
|| metadata.maximum !== undefined && v <= metadata.maximum
|
|
145
|
+
|| translate.value({
|
|
146
|
+
defaultMessage: "The value should be {isExclusive, select, true {smaller than} other {at most}} {maximum}",
|
|
147
|
+
id: "validation.number.max"
|
|
148
|
+
}, {
|
|
149
|
+
isExclusive: metadata.exclusiveMaximum !== undefined,
|
|
150
|
+
maximum: metadata.exclusiveMaximum ?? metadata.maximum
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
|
|
154
|
+
const parseRule = (v: unknown) =>
|
|
155
|
+
pipe(
|
|
156
|
+
parse(v),
|
|
157
|
+
(_) =>
|
|
158
|
+
_.match(
|
|
159
|
+
{
|
|
160
|
+
onLeft: (_) => renderError(_, v),
|
|
161
|
+
onRight: () => true
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
type UnknownRule = (v: unknown) => boolean | string
|
|
167
|
+
const rules: UnknownRule[] = [
|
|
168
|
+
...(metadata.type === "text"
|
|
169
|
+
? stringRules
|
|
170
|
+
: numberRules) as UnknownRule[],
|
|
171
|
+
parseRule as UnknownRule
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
const info = {
|
|
175
|
+
type: metadata.type,
|
|
176
|
+
rules: [
|
|
177
|
+
(v: string) =>
|
|
178
|
+
!metadata.required
|
|
179
|
+
|| v !== ""
|
|
180
|
+
|| translate.value({ defaultMessage: "The field cannot be empty", id: "validation.empty" }),
|
|
181
|
+
(v: string) => {
|
|
182
|
+
const converted = convertOutInt(v, metadata.type)
|
|
183
|
+
|
|
184
|
+
for (const r of rules) {
|
|
185
|
+
const res = r(converted)
|
|
186
|
+
if (res !== true) {
|
|
187
|
+
return res
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return true
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
metadata
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return info as any
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const buildFormFromSchema = <
|
|
201
|
+
From extends Record<PropertyKey, any>,
|
|
202
|
+
To extends Record<PropertyKey, any>,
|
|
203
|
+
OnSubmitA
|
|
204
|
+
>(
|
|
205
|
+
s: Schema<
|
|
206
|
+
From,
|
|
207
|
+
To
|
|
208
|
+
>,
|
|
209
|
+
state: Ref<From>,
|
|
210
|
+
onSubmit: (a: To) => Promise<OnSubmitA>
|
|
211
|
+
) => {
|
|
212
|
+
const fields = buildFieldInfoFromFields(s)
|
|
213
|
+
const parse = s.decodeSync
|
|
214
|
+
const isDirty = ref(false)
|
|
215
|
+
const isValid = ref(true)
|
|
216
|
+
|
|
217
|
+
const submit1 = <A>(onSubmit: (a: To) => Promise<A>) => async <T extends Promise<{ valid: boolean }>>(e: T) => {
|
|
218
|
+
const r = await e
|
|
219
|
+
if (!r.valid) return
|
|
220
|
+
return onSubmit(parse(state.value))
|
|
221
|
+
}
|
|
222
|
+
const submit = submit1(onSubmit)
|
|
223
|
+
|
|
224
|
+
watch(
|
|
225
|
+
state,
|
|
226
|
+
(v) => {
|
|
227
|
+
// TODO: do better
|
|
228
|
+
isDirty.value = JSON.stringify(v) !== JSON.stringify(state.value)
|
|
229
|
+
},
|
|
230
|
+
{ deep: true }
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
const submitFromState = () => submit(Promise.resolve({ valid: isValid.value }))
|
|
234
|
+
|
|
235
|
+
return { fields, submit, submitFromState, isDirty, isValid }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function getMetadataFromSchema(
|
|
239
|
+
ast: AST.AST
|
|
240
|
+
): {
|
|
241
|
+
type: "int" | "float" | "text"
|
|
242
|
+
minimum?: number
|
|
243
|
+
maximum?: number
|
|
244
|
+
exclusiveMinimum?: number
|
|
245
|
+
exclusiveMaximum?: number
|
|
246
|
+
minLength?: number
|
|
247
|
+
maxLength?: number
|
|
248
|
+
required: boolean
|
|
249
|
+
description?: string
|
|
250
|
+
} {
|
|
251
|
+
const nullable = AST.isUnion(ast) && ast.types.includes(S.null.ast)
|
|
252
|
+
const realSelf = nullable && AST.isUnion(ast)
|
|
253
|
+
? ast.types.filter((_) => _ !== S.null.ast)[0]!
|
|
254
|
+
: ast
|
|
255
|
+
|
|
256
|
+
let jschema: any
|
|
257
|
+
try {
|
|
258
|
+
jschema = JSONSchema.to(S.make(realSelf)) as any
|
|
259
|
+
} catch (err) {
|
|
260
|
+
jschema = {}
|
|
261
|
+
console.warn("error getting jsonschema from ", err, ast)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const isNumber = jschema.type === "number" || jschema.type === "integer"
|
|
265
|
+
const isInt = jschema.type === "integer"
|
|
266
|
+
return {
|
|
267
|
+
type: isInt ? "int" as const : isNumber ? "float" as const : "text" as const,
|
|
268
|
+
minimum: jschema.minimum,
|
|
269
|
+
exclusiveMinimum: jschema.exclusiveMinimum,
|
|
270
|
+
maximum: jschema.maximum,
|
|
271
|
+
exclusiveMaximum: jschema.exclusiveMaximum,
|
|
272
|
+
minLength: jschema.minLength,
|
|
273
|
+
maxLength: jschema.maxLength,
|
|
274
|
+
description: jschema.description,
|
|
275
|
+
required: !nullable
|
|
276
|
+
}
|
|
277
|
+
}
|
package/_src/hooks.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ApiConfig, FetchResponse } from "@effect-app/prelude/client"
|
|
|
3
3
|
import { InterruptedException } from "effect/Cause"
|
|
4
4
|
import * as swrv from "swrv"
|
|
5
5
|
import type { fetcherFn, IKey, IResponse } from "swrv/dist/types.js"
|
|
6
|
-
import type { Ref } from "vue"
|
|
6
|
+
import type { ComputedRef, Ref } from "vue"
|
|
7
7
|
import { computed, ref, shallowRef } from "vue"
|
|
8
8
|
import { run } from "./internal.js"
|
|
9
9
|
|
|
@@ -64,10 +64,12 @@ export function useMutateWithArg<Arg, E, A>(
|
|
|
64
64
|
return (arg: Arg) => mutate(self.mapPath(arg), fn(arg))
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
|
|
68
|
+
|
|
67
69
|
// TODO: same trick with mutations/actions
|
|
68
70
|
export function useSafeQueryWithArg<Arg, E, A>(
|
|
69
71
|
self: ((arg: Arg) => Effect<ApiConfig | HttpClient.Default, E, FetchResponse<A>>) & { mapPath: (arg: Arg) => string },
|
|
70
|
-
arg: Arg
|
|
72
|
+
arg: Arg | WatchSource<Arg>,
|
|
71
73
|
config?: swrv.IConfig<A, fetcherFn<A>> | undefined
|
|
72
74
|
) {
|
|
73
75
|
return useSafeQueryWithArg_(self, self.mapPath, arg, config)
|
|
@@ -77,21 +79,29 @@ export function useSafeQuery<E, A>(
|
|
|
77
79
|
self: Effect<ApiConfig | HttpClient.Default, E, FetchResponse<A>> & { mapPath: string },
|
|
78
80
|
config?: swrv.IConfig<A, fetcherFn<A>> | undefined
|
|
79
81
|
) {
|
|
80
|
-
return useSafeQuery_(self.mapPath, self, config)
|
|
82
|
+
return useSafeQuery_(self.mapPath, () => self, config)
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
export function useSafeQueryWithArg_<Arg, E, A>(
|
|
84
86
|
self: (arg: Arg) => Effect<ApiConfig | HttpClient.Default, E, FetchResponse<A>>,
|
|
85
87
|
mapPath: (arg: Arg) => string,
|
|
86
|
-
arg: Arg
|
|
88
|
+
arg: Arg | WatchSource<Arg>,
|
|
87
89
|
config?: swrv.IConfig<A, fetcherFn<A>> | undefined
|
|
88
90
|
) {
|
|
89
|
-
|
|
91
|
+
const arr = arg
|
|
92
|
+
const r: { value: Arg } = typeof arr === "function"
|
|
93
|
+
? {
|
|
94
|
+
get value() {
|
|
95
|
+
return (arr as any)()
|
|
96
|
+
}
|
|
97
|
+
} as any
|
|
98
|
+
: ref(arg)
|
|
99
|
+
return useSafeQuery_(computed(() => mapPath(r.value)), () => self(r.value), config)
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
export function useSafeQuery_<E, A>(
|
|
93
|
-
key: string
|
|
94
|
-
self: Effect<ApiConfig | HttpClient.Default, E, FetchResponse<A>>,
|
|
103
|
+
key: string | WatchSource<string>,
|
|
104
|
+
self: () => Effect<ApiConfig | HttpClient.Default, E, FetchResponse<A>>,
|
|
95
105
|
config?: swrv.IConfig<A, fetcherFn<A>> | undefined
|
|
96
106
|
) {
|
|
97
107
|
// const [result, latestSuccess, execute] = make(self)
|
|
@@ -125,7 +135,7 @@ export function useSafeQuery_<E, A>(
|
|
|
125
135
|
// }
|
|
126
136
|
|
|
127
137
|
// const swr = useSWRV<A, E>(key, () => execWithInterruption().then(_ => _?.body as any)) // Effect.runPromise(self.provide(Layers))
|
|
128
|
-
const swr = useSWRV<A, E>(key, () => run.value(self).then((_) => _.body), config)
|
|
138
|
+
const swr = useSWRV<A, E>(key, () => run.value(self()).then((_) => _.body), config)
|
|
129
139
|
const result = computed(() =>
|
|
130
140
|
swrToQuery({ data: swr.data.value, error: swr.error.value, isValidating: swr.isValidating.value })
|
|
131
141
|
) // ref<QueryResult<E, A>>()
|
package/dist/form.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { AST } from "@effect-app/schema";
|
|
1
2
|
import type { Schema } from "@effect-app/schema";
|
|
3
|
+
import type { Ref } from "vue";
|
|
2
4
|
export declare function convertIn(v: string | null, type?: "text" | "float" | "int"): string;
|
|
3
5
|
export declare function convertOutInt(v: string, type?: "text" | "float" | "int"): string | number | null;
|
|
4
6
|
export declare function convertOut(v: string, set: (v: unknown | null) => void, type?: "text" | "float" | "int"): void;
|
|
7
|
+
export declare function buildFieldInfoFromFields<From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>>(fields: Schema<From, To>): { [K in keyof To]: FieldInfo<To[K]>; };
|
|
5
8
|
export interface FieldMetadata {
|
|
6
9
|
minLength: number | undefined;
|
|
7
10
|
maxLength: number | undefined;
|
|
@@ -13,18 +16,37 @@ declare abstract class PhantomTypeParameter<Identifier extends keyof any, Instan
|
|
|
13
16
|
readonly [NameP in Identifier]: (_: InstantiatedType) => InstantiatedType;
|
|
14
17
|
};
|
|
15
18
|
}
|
|
16
|
-
export interface FieldInfo<
|
|
17
|
-
in: Tin;
|
|
19
|
+
export interface FieldInfo<Tout> extends PhantomTypeParameter<typeof f, {
|
|
18
20
|
out: Tout;
|
|
19
21
|
}> {
|
|
20
22
|
rules: ((v: string) => boolean | string)[];
|
|
21
23
|
metadata: FieldMetadata;
|
|
22
24
|
type: "text" | "float" | "int";
|
|
23
25
|
}
|
|
24
|
-
export declare const translate:
|
|
26
|
+
export declare const translate: Ref<{
|
|
25
27
|
(descriptor: import("@formatjs/intl").MessageDescriptor, values?: Record<string, import("intl-messageformat").PrimitiveType | import("intl-messageformat").FormatXMLElementFn<string, string>> | undefined, opts?: import("intl-messageformat").Options | undefined): string;
|
|
26
28
|
<T extends unknown>(descriptor: import("@formatjs/intl").MessageDescriptor, values?: Record<string, import("intl-messageformat").PrimitiveType | T | import("intl-messageformat").FormatXMLElementFn<T>> | undefined, opts?: import("intl-messageformat").Options | undefined): string | T | (string | T)[];
|
|
27
29
|
}>;
|
|
28
|
-
export declare const customSchemaErrors:
|
|
30
|
+
export declare const customSchemaErrors: Ref<Map<AST.AST, (message: string, e: unknown, v: unknown) => string>>;
|
|
31
|
+
export declare const buildFormFromSchema: <From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>, OnSubmitA>(s: Schema<From, To>, state: Ref<From>, onSubmit: (a: To) => Promise<OnSubmitA>) => {
|
|
32
|
+
fields: { [K in keyof To]: FieldInfo<To[K]>; };
|
|
33
|
+
submit: <T extends Promise<{
|
|
34
|
+
valid: boolean;
|
|
35
|
+
}>>(e: T) => Promise<OnSubmitA | undefined>;
|
|
36
|
+
submitFromState: () => Promise<OnSubmitA | undefined>;
|
|
37
|
+
isDirty: Ref<boolean>;
|
|
38
|
+
isValid: Ref<boolean>;
|
|
39
|
+
};
|
|
40
|
+
export declare function getMetadataFromSchema(ast: AST.AST): {
|
|
41
|
+
type: "int" | "float" | "text";
|
|
42
|
+
minimum?: number;
|
|
43
|
+
maximum?: number;
|
|
44
|
+
exclusiveMinimum?: number;
|
|
45
|
+
exclusiveMaximum?: number;
|
|
46
|
+
minLength?: number;
|
|
47
|
+
maxLength?: number;
|
|
48
|
+
required: boolean;
|
|
49
|
+
description?: string;
|
|
50
|
+
};
|
|
29
51
|
export {};
|
|
30
52
|
//# sourceMappingURL=form.d.ts.map
|