@effect-app/vue 4.0.0-beta.4 → 4.0.0-beta.40
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 +262 -0
- package/dist/experimental/commander.d.ts +1 -1
- package/dist/experimental/commander.d.ts.map +1 -1
- package/dist/experimental/commander.js +4 -5
- package/dist/form.d.ts +9 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +24 -7
- package/dist/makeClient.d.ts +2 -2
- package/dist/makeClient.d.ts.map +1 -1
- package/dist/makeClient.js +5 -4
- package/dist/mutate.d.ts +1 -1
- package/dist/mutate.d.ts.map +1 -1
- package/dist/mutate.js +2 -2
- package/dist/query.d.ts +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +16 -7
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +8 -2
- package/package.json +9 -9
- package/src/experimental/commander.ts +4 -5
- package/src/form.ts +23 -6
- package/src/makeClient.ts +4 -3
- package/src/mutate.ts +1 -1
- package/src/query.ts +16 -9
- package/src/runtime.ts +13 -1
- package/test/dist/stubs.d.ts +30 -47
- package/test/dist/stubs.d.ts.map +1 -1
- package/test/dist/stubs.js +2 -2
- package/test/form-validation-errors.test.ts +23 -19
- package/test/stubs.ts +2 -2
- package/tsconfig.json +0 -1
- package/test/form.test.ts +0 -261
package/test/form.test.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { Effect, S } from "effect-app"
|
|
2
|
-
import { buildFieldInfoFromFieldsRoot, type DiscriminatedUnionFieldInfo, type FieldInfo, type NestedFieldInfo, type UnionFieldInfo } from "../src/form.js"
|
|
3
|
-
|
|
4
|
-
export class NestedSchema extends S.Class<NestedSchema>("NestedSchema")({
|
|
5
|
-
shallow: S.String,
|
|
6
|
-
nested: S.Struct({
|
|
7
|
-
deep: S.NonEmptyString,
|
|
8
|
-
nested: S.Struct({
|
|
9
|
-
deepest: S.Number
|
|
10
|
-
})
|
|
11
|
-
}),
|
|
12
|
-
age: S.Struct({ nfs: S.NumberFromString.pipe(S.decodeTo(S.PositiveInt)) })
|
|
13
|
-
}) {}
|
|
14
|
-
|
|
15
|
-
export class SchemaContainsClass extends S.Class<SchemaContainsClass>("SchemaContainsClass")({
|
|
16
|
-
inner: NestedSchema
|
|
17
|
-
}) {}
|
|
18
|
-
|
|
19
|
-
export class UnionSchema extends S.Class<UnionSchema>("UnionSchema")({
|
|
20
|
-
generalUnion: S.Union([S.String, S.Struct({ unionNested: NestedSchema })]),
|
|
21
|
-
structsUnion: S.Union([NestedSchema, SchemaContainsClass]),
|
|
22
|
-
optional: S.optional(S.String),
|
|
23
|
-
nullable: S.NullOr(S.String)
|
|
24
|
-
}) {}
|
|
25
|
-
|
|
26
|
-
class Circle extends S.TaggedClass<Circle>()("Circle", {
|
|
27
|
-
radius: S.PositiveInt
|
|
28
|
-
}) {}
|
|
29
|
-
|
|
30
|
-
class Square extends S.TaggedClass<Square>()("Square", {
|
|
31
|
-
sideLength: S.PositiveInt
|
|
32
|
-
}) {}
|
|
33
|
-
|
|
34
|
-
class Triangle extends S.TaggedClass<Triangle>()("Triangle", {
|
|
35
|
-
base: S.PositiveInt,
|
|
36
|
-
height: S.Number
|
|
37
|
-
}) {}
|
|
38
|
-
|
|
39
|
-
const CircleStruct = S.Struct({
|
|
40
|
-
_tag: S.Literal("CircleStruct"),
|
|
41
|
-
radius: S.PositiveInt
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const SquareStruct = S.Struct({
|
|
45
|
-
_tag: S.Literal("SquareStruct"),
|
|
46
|
-
sideLength: S.PositiveInt
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const TriangleStruct = S.Struct({
|
|
50
|
-
_tag: S.Literal("TriangleStruct"),
|
|
51
|
-
base: S.PositiveInt,
|
|
52
|
-
height: S.Number
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const ShapeWithStructs = S.Union([CircleStruct, SquareStruct, TriangleStruct])
|
|
56
|
-
const ShapeWithClasses = S.Union([Circle, Square, Triangle])
|
|
57
|
-
|
|
58
|
-
export class ShapeContainer extends S.Class<ShapeContainer>("ShapeContainer")({
|
|
59
|
-
shapeWithStruct: ShapeWithStructs,
|
|
60
|
-
shapeWithClasses: ShapeWithClasses
|
|
61
|
-
}) {}
|
|
62
|
-
|
|
63
|
-
function testFieldInfo<T>(fi: FieldInfo<T>) {
|
|
64
|
-
expect(fi).toBeInstanceOf(Object)
|
|
65
|
-
expect(fi._tag).toBe("FieldInfo")
|
|
66
|
-
expect(["text", "float", "int"]).toContain(fi.type)
|
|
67
|
-
expect(fi.rules).toBeInstanceOf(Array)
|
|
68
|
-
fi.rules.forEach((r) => {
|
|
69
|
-
expect(r).toBeInstanceOf(Function)
|
|
70
|
-
})
|
|
71
|
-
expect(fi.metadata).toBeInstanceOf(Object)
|
|
72
|
-
expect(fi.metadata.maxLength === void 0 || typeof fi.metadata.maxLength === "number").toBeTruthy()
|
|
73
|
-
expect(fi.metadata.minLength === void 0 || typeof fi.metadata.minLength === "number").toBeTruthy()
|
|
74
|
-
expect(typeof fi.metadata.required === "boolean").toBeTruthy()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function testUnionFieldInfo<T>(ufi: UnionFieldInfo<T[]>) {
|
|
78
|
-
expect(ufi).toBeInstanceOf(Object)
|
|
79
|
-
expect(ufi._tag).toBe("UnionFieldInfo")
|
|
80
|
-
expect(ufi.members).toBeInstanceOf(Array)
|
|
81
|
-
ufi.members.forEach(
|
|
82
|
-
(
|
|
83
|
-
i: any
|
|
84
|
-
) => {
|
|
85
|
-
switch (i._tag) {
|
|
86
|
-
case "FieldInfo":
|
|
87
|
-
testFieldInfo(i as FieldInfo<any>)
|
|
88
|
-
break
|
|
89
|
-
case "NestedFieldInfo":
|
|
90
|
-
testNestedFieldInfo(i as NestedFieldInfo<any>)
|
|
91
|
-
break
|
|
92
|
-
case "UnionFieldInfo":
|
|
93
|
-
testUnionFieldInfo(i as UnionFieldInfo<any>)
|
|
94
|
-
break
|
|
95
|
-
case "DiscriminatedUnionFieldInfo":
|
|
96
|
-
testDiscriminatedUnionFieldInfo(i as DiscriminatedUnionFieldInfo<any>)
|
|
97
|
-
break
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function testNestedFieldInfo<T extends Record<PropertyKey, any>>(nfi: NestedFieldInfo<T>) {
|
|
104
|
-
expect(nfi).toBeInstanceOf(Object)
|
|
105
|
-
expect(nfi._tag).toBe("NestedFieldInfo")
|
|
106
|
-
expect(nfi.fields).toBeInstanceOf(Object)
|
|
107
|
-
|
|
108
|
-
// remove the value of _infoTag from the object when it is undefined
|
|
109
|
-
// when it isn't undefined, the followin switch will ignore it
|
|
110
|
-
Object.values(nfi).filter(Boolean).forEach(
|
|
111
|
-
(
|
|
112
|
-
i: any
|
|
113
|
-
) => {
|
|
114
|
-
switch (i._tag) {
|
|
115
|
-
case "FieldInfo":
|
|
116
|
-
testFieldInfo(i as FieldInfo<any>)
|
|
117
|
-
break
|
|
118
|
-
case "NestedFieldInfo":
|
|
119
|
-
testNestedFieldInfo(i as NestedFieldInfo<any>)
|
|
120
|
-
break
|
|
121
|
-
case "UnionFieldInfo":
|
|
122
|
-
testUnionFieldInfo(i as UnionFieldInfo<any>)
|
|
123
|
-
break
|
|
124
|
-
case "DiscriminatedUnionFieldInfo":
|
|
125
|
-
testDiscriminatedUnionFieldInfo(i as DiscriminatedUnionFieldInfo<any>)
|
|
126
|
-
break
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function testDiscriminatedUnionFieldInfo<T extends Record<PropertyKey, any>>(dufi: DiscriminatedUnionFieldInfo<T>) {
|
|
133
|
-
expect(dufi).toBeInstanceOf(Object)
|
|
134
|
-
expect(dufi._tag).toBe("DiscriminatedUnionFieldInfo")
|
|
135
|
-
expect(dufi.members).toBeInstanceOf(Object)
|
|
136
|
-
|
|
137
|
-
Object.values(dufi.members).forEach(
|
|
138
|
-
(
|
|
139
|
-
i: any
|
|
140
|
-
) => {
|
|
141
|
-
switch (i._tag) {
|
|
142
|
-
case "FieldInfo":
|
|
143
|
-
testFieldInfo(i as FieldInfo<any>)
|
|
144
|
-
break
|
|
145
|
-
case "NestedFieldInfo":
|
|
146
|
-
testNestedFieldInfo(i as NestedFieldInfo<any>)
|
|
147
|
-
break
|
|
148
|
-
case "UnionFieldInfo":
|
|
149
|
-
testUnionFieldInfo(i as UnionFieldInfo<any>)
|
|
150
|
-
break
|
|
151
|
-
case "DiscriminatedUnionFieldInfo":
|
|
152
|
-
testDiscriminatedUnionFieldInfo(i as DiscriminatedUnionFieldInfo<any>)
|
|
153
|
-
break
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
it("buildFieldInfo", () =>
|
|
160
|
-
Effect
|
|
161
|
-
.gen(function*() {
|
|
162
|
-
const nestedFieldinfo = buildFieldInfoFromFieldsRoot(NestedSchema)
|
|
163
|
-
expectTypeOf(nestedFieldinfo).toEqualTypeOf<NestedFieldInfo<NestedSchema>>()
|
|
164
|
-
expectTypeOf(nestedFieldinfo.fields.shallow).toEqualTypeOf<FieldInfo<string>>()
|
|
165
|
-
expectTypeOf(nestedFieldinfo.fields.age).toEqualTypeOf<NestedFieldInfo<NestedSchema["age"]>>()
|
|
166
|
-
// TODO: v4 migration - type inference changed with S.decodeTo, investigate if this is correct
|
|
167
|
-
// expectTypeOf(nestedFieldinfo.fields.age.fields.nfs).toEqualTypeOf<FieldInfo<number & S.PositiveIntBrand>>()
|
|
168
|
-
expectTypeOf(nestedFieldinfo.fields.nested).toEqualTypeOf<NestedFieldInfo<NestedSchema["nested"]>>()
|
|
169
|
-
expectTypeOf(nestedFieldinfo.fields.nested.fields.deep).toEqualTypeOf<FieldInfo<string & S.NonEmptyStringBrand>>()
|
|
170
|
-
expectTypeOf(nestedFieldinfo.fields.nested.fields.nested).toEqualTypeOf<
|
|
171
|
-
NestedFieldInfo<NestedSchema["nested"]["nested"]>
|
|
172
|
-
>()
|
|
173
|
-
expectTypeOf(nestedFieldinfo.fields.nested.fields.nested.fields.deepest).toEqualTypeOf<FieldInfo<number>>()
|
|
174
|
-
|
|
175
|
-
// it's a recursive check on actual runtime structure
|
|
176
|
-
testNestedFieldInfo(nestedFieldinfo)
|
|
177
|
-
testNestedFieldInfo(nestedFieldinfo.fields.nested)
|
|
178
|
-
testNestedFieldInfo(nestedFieldinfo.fields.age)
|
|
179
|
-
})
|
|
180
|
-
.pipe(Effect.runPromise))
|
|
181
|
-
|
|
182
|
-
it("buildFieldInfo schema containing class", () =>
|
|
183
|
-
Effect
|
|
184
|
-
.gen(function*() {
|
|
185
|
-
const fieldinfo = buildFieldInfoFromFieldsRoot(SchemaContainsClass)
|
|
186
|
-
|
|
187
|
-
// the type system says that these are NestedFieldInfo<NestedSchema>s
|
|
188
|
-
// are they really? let's check
|
|
189
|
-
testNestedFieldInfo(fieldinfo.fields.inner)
|
|
190
|
-
testNestedFieldInfo(fieldinfo.fields.inner.fields.nested.fields.nested)
|
|
191
|
-
})
|
|
192
|
-
.pipe(Effect.runPromise))
|
|
193
|
-
|
|
194
|
-
it("buildFieldInfo with simple union", () =>
|
|
195
|
-
Effect
|
|
196
|
-
.gen(function*() {
|
|
197
|
-
const unionFieldinfo = buildFieldInfoFromFieldsRoot(UnionSchema)
|
|
198
|
-
expectTypeOf(unionFieldinfo).toEqualTypeOf<NestedFieldInfo<UnionSchema>>()
|
|
199
|
-
expectTypeOf(unionFieldinfo.fields.nullable).toEqualTypeOf<
|
|
200
|
-
FieldInfo<string | null>
|
|
201
|
-
>()
|
|
202
|
-
expectTypeOf(unionFieldinfo.fields.optional).toEqualTypeOf<
|
|
203
|
-
FieldInfo<string | undefined>
|
|
204
|
-
>()
|
|
205
|
-
expectTypeOf(unionFieldinfo.fields.structsUnion).toEqualTypeOf<
|
|
206
|
-
UnionFieldInfo<(NestedFieldInfo<NestedSchema> | NestedFieldInfo<SchemaContainsClass>)[]>
|
|
207
|
-
>()
|
|
208
|
-
expectTypeOf(unionFieldinfo.fields.generalUnion).toEqualTypeOf<
|
|
209
|
-
FieldInfo<
|
|
210
|
-
string | {
|
|
211
|
-
readonly unionNested: NestedSchema
|
|
212
|
-
}
|
|
213
|
-
>
|
|
214
|
-
>
|
|
215
|
-
|
|
216
|
-
// it's a recursive check on actual runtime structure
|
|
217
|
-
testNestedFieldInfo(unionFieldinfo)
|
|
218
|
-
testFieldInfo(unionFieldinfo.fields.nullable)
|
|
219
|
-
testFieldInfo(unionFieldinfo.fields.optional)
|
|
220
|
-
console.log({ asd: unionFieldinfo.fields.structsUnion })
|
|
221
|
-
testUnionFieldInfo(unionFieldinfo.fields.structsUnion)
|
|
222
|
-
testFieldInfo(unionFieldinfo.fields.generalUnion)
|
|
223
|
-
})
|
|
224
|
-
.pipe(Effect.runPromise))
|
|
225
|
-
|
|
226
|
-
it("buildFieldInfo with tagged unions", () =>
|
|
227
|
-
Effect
|
|
228
|
-
.gen(function*() {
|
|
229
|
-
const shapeFieldinfo = buildFieldInfoFromFieldsRoot(ShapeContainer)
|
|
230
|
-
|
|
231
|
-
// check at runtime if the structure is really an union
|
|
232
|
-
testDiscriminatedUnionFieldInfo(shapeFieldinfo.fields.shapeWithClasses)
|
|
233
|
-
testDiscriminatedUnionFieldInfo(shapeFieldinfo.fields.shapeWithStruct)
|
|
234
|
-
|
|
235
|
-
testNestedFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Square)
|
|
236
|
-
expect(shapeFieldinfo.fields.shapeWithClasses.members.Square._infoTag).toBe("Square")
|
|
237
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Square.fields.sideLength)
|
|
238
|
-
|
|
239
|
-
testNestedFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Triangle)
|
|
240
|
-
expect(shapeFieldinfo.fields.shapeWithClasses.members.Triangle._infoTag).toBe("Triangle")
|
|
241
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Triangle.fields.base)
|
|
242
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Triangle.fields.height)
|
|
243
|
-
|
|
244
|
-
testNestedFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Circle)
|
|
245
|
-
expect(shapeFieldinfo.fields.shapeWithClasses.members.Circle._infoTag).toBe("Circle")
|
|
246
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithClasses.members.Circle.fields.radius)
|
|
247
|
-
|
|
248
|
-
testNestedFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.SquareStruct)
|
|
249
|
-
expect(shapeFieldinfo.fields.shapeWithStruct.members.SquareStruct._infoTag).toBe("SquareStruct")
|
|
250
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.SquareStruct.fields.sideLength)
|
|
251
|
-
|
|
252
|
-
testNestedFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.TriangleStruct)
|
|
253
|
-
expect(shapeFieldinfo.fields.shapeWithStruct.members.TriangleStruct._infoTag).toBe("TriangleStruct")
|
|
254
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.TriangleStruct.fields.base)
|
|
255
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.TriangleStruct.fields.height)
|
|
256
|
-
|
|
257
|
-
testNestedFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.CircleStruct)
|
|
258
|
-
expect(shapeFieldinfo.fields.shapeWithStruct.members.CircleStruct._infoTag).toBe("CircleStruct")
|
|
259
|
-
testFieldInfo(shapeFieldinfo.fields.shapeWithStruct.members.CircleStruct.fields.radius)
|
|
260
|
-
})
|
|
261
|
-
.pipe(Effect.runPromise))
|