@effect-app/vue-components 2.9.2 → 2.10.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/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +2 -0
- package/dist/types/components/OmegaForm/useOmegaForm.d.ts +1 -0
- package/dist/vue-components.es.js +17 -15
- package/dist/vue-components.es10.js +91 -93
- package/dist/vue-components.es12.js +282 -204
- package/dist/vue-components.es16.js +4 -10
- package/dist/vue-components.es17.js +10 -97
- package/dist/vue-components.es2.js +29 -27
- package/dist/vue-components.es20.js +2 -2
- package/dist/vue-components.es21.js +2 -2
- package/dist/vue-components.es22.js +1 -1
- package/dist/vue-components.es23.js +1 -1
- package/dist/vue-components.es30.js +191 -41
- package/dist/vue-components.es32.js +42 -2
- package/dist/vue-components.es33.js +1 -1
- package/dist/vue-components.es34.js +2 -111
- package/dist/vue-components.es35.js +113 -0
- package/dist/vue-components.es37.js +7 -32
- package/dist/vue-components.es38.js +34 -0
- package/dist/vue-components.es40.js +6 -0
- package/dist/vue-components.es41.js +23 -4
- package/dist/vue-components.es42.js +5 -23
- package/dist/vue-components.es43.js +21 -5
- package/dist/vue-components.es44.js +25 -16
- package/dist/vue-components.es45.js +15 -23
- package/dist/vue-components.es46.js +7 -17
- package/dist/vue-components.es47.js +5 -12
- package/dist/vue-components.es48.js +19 -5
- package/dist/vue-components.es49.js +9 -19
- package/dist/vue-components.es50.js +31 -9
- package/dist/vue-components.es51.js +42 -25
- package/dist/vue-components.es52.js +16 -38
- package/dist/vue-components.es53.js +11 -26
- package/dist/vue-components.es54.js +65 -11
- package/dist/vue-components.es55.js +45 -54
- package/dist/vue-components.es56.js +15 -54
- package/dist/vue-components.es57.js +31 -15
- package/dist/vue-components.es58.js +26 -30
- package/dist/vue-components.es59.js +42 -29
- package/dist/vue-components.es60.js +2 -42
- package/dist/vue-components.es61.js +44 -2
- package/dist/vue-components.es62.js +2 -44
- package/dist/vue-components.es7.js +1 -1
- package/dist/vue-components.es9.js +10 -33
- package/package.json +1 -1
- package/src/components/OmegaForm/OmegaFormStuff.ts +174 -11
- package/src/components/OmegaForm/OmegaTaggedUnionInternal.vue +0 -48
- package/src/components/OmegaForm/useOmegaForm.ts +16 -8
- package/dist/types/components/OmegaForm/defaultAST.d.ts +0 -4
- package/dist/vue-components.es31.js +0 -6
- package/dist/vue-components.es36.js +0 -9
- package/dist/vue-components.es39.js +0 -194
- package/dist/vue-components.es63.js +0 -4
- package/src/components/OmegaForm/defaultAST.ts +0 -191
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { defineComponent as k, resolveComponent as b, createElementBlock as v, openBlock as a, createBlock as n, createCommentVNode as u, resolveDynamicComponent as g, mergeProps as o, createSlots as d, withCtx as r, renderSlot as m, normalizeProps as s, guardReactiveProps as P, unref as C, Fragment as V, renderList as U } from "vue";
|
|
2
|
-
import { getInputType as c } from "./vue-components.es12.js";
|
|
3
|
-
const w = /* @__PURE__ */ k({
|
|
4
|
-
inheritAttrs: !1,
|
|
5
|
-
__name: "OmegaInputVuetify",
|
|
6
|
-
props: {
|
|
7
|
-
inputProps: {},
|
|
8
|
-
field: {},
|
|
9
|
-
state: {}
|
|
10
|
-
},
|
|
11
|
-
emits: ["focus", "blur"],
|
|
12
|
-
setup(e) {
|
|
13
|
-
return (l, i) => {
|
|
14
|
-
const y = b("v-text-field"), p = b("v-textarea"), f = b("v-radio"), h = b("v-radio-group"), q = b("v-select"), $ = b("v-autocomplete");
|
|
15
|
-
return a(), v("div", {
|
|
16
|
-
class: "omega-input",
|
|
17
|
-
onFocusout: i[4] || (i[4] = (t) => l.$emit("blur", t)),
|
|
18
|
-
onFocusin: i[5] || (i[5] = (t) => l.$emit("focus", t))
|
|
19
|
-
}, [
|
|
20
|
-
e.inputProps.type === "boolean" || e.inputProps.type === "switch" ? (a(), n(g(e.inputProps.type === "boolean" ? "v-checkbox" : "v-switch"), o({
|
|
21
|
-
key: 0,
|
|
22
|
-
id: e.inputProps.id,
|
|
23
|
-
name: e.field.name,
|
|
24
|
-
label: e.inputProps.label,
|
|
25
|
-
"error-messages": e.inputProps.errorMessages,
|
|
26
|
-
error: e.inputProps.error,
|
|
27
|
-
ripple: ""
|
|
28
|
-
}, l.$attrs, {
|
|
29
|
-
"model-value": e.state.value,
|
|
30
|
-
onChange: i[0] || (i[0] = (t) => e.field.handleChange(t.target.checked))
|
|
31
|
-
}), d({ _: 2 }, [
|
|
32
|
-
l.$slots.label ? {
|
|
33
|
-
name: "label",
|
|
34
|
-
fn: r(() => [
|
|
35
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
36
|
-
]),
|
|
37
|
-
key: "0"
|
|
38
|
-
} : void 0
|
|
39
|
-
]), 1040, ["id", "name", "label", "error-messages", "error", "model-value"])) : u("", !0),
|
|
40
|
-
e.inputProps.type === "email" || e.inputProps.type === "string" || e.inputProps.type === "password" || e.inputProps.type === "date" ? (a(), n(y, o({
|
|
41
|
-
key: 1,
|
|
42
|
-
id: e.inputProps.id,
|
|
43
|
-
required: e.inputProps.required,
|
|
44
|
-
"min-length": e.inputProps.minLength,
|
|
45
|
-
"max-length": e.inputProps.maxLength,
|
|
46
|
-
type: C(c)(e.inputProps.type),
|
|
47
|
-
name: e.field.name,
|
|
48
|
-
label: e.inputProps.label,
|
|
49
|
-
"error-messages": e.inputProps.errorMessages,
|
|
50
|
-
error: e.inputProps.error
|
|
51
|
-
}, l.$attrs, {
|
|
52
|
-
"model-value": e.state.value,
|
|
53
|
-
"onUpdate:modelValue": e.field.handleChange
|
|
54
|
-
}), d({ _: 2 }, [
|
|
55
|
-
l.$slots.label ? {
|
|
56
|
-
name: "label",
|
|
57
|
-
fn: r(() => [
|
|
58
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
59
|
-
]),
|
|
60
|
-
key: "0"
|
|
61
|
-
} : void 0
|
|
62
|
-
]), 1040, ["id", "required", "min-length", "max-length", "type", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : u("", !0),
|
|
63
|
-
e.inputProps.type === "text" ? (a(), n(p, o({
|
|
64
|
-
key: 2,
|
|
65
|
-
id: e.inputProps.id,
|
|
66
|
-
required: e.inputProps.required,
|
|
67
|
-
"min-length": e.inputProps.minLength,
|
|
68
|
-
"max-length": e.inputProps.maxLength,
|
|
69
|
-
name: e.field.name,
|
|
70
|
-
label: e.inputProps.label,
|
|
71
|
-
"error-messages": e.inputProps.errorMessages,
|
|
72
|
-
error: e.inputProps.error
|
|
73
|
-
}, l.$attrs, {
|
|
74
|
-
"model-value": e.state.value,
|
|
75
|
-
"onUpdate:modelValue": e.field.handleChange
|
|
76
|
-
}), d({ _: 2 }, [
|
|
77
|
-
l.$slots.label ? {
|
|
78
|
-
name: "label",
|
|
79
|
-
fn: r(() => [
|
|
80
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
81
|
-
]),
|
|
82
|
-
key: "0"
|
|
83
|
-
} : void 0
|
|
84
|
-
]), 1040, ["id", "required", "min-length", "max-length", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : u("", !0),
|
|
85
|
-
e.inputProps.type === "number" || e.inputProps.type === "range" ? (a(), n(g(e.inputProps.type === "range" ? "v-slider" : "v-text-field"), o({
|
|
86
|
-
key: 3,
|
|
87
|
-
id: e.inputProps.id,
|
|
88
|
-
required: e.inputProps.required,
|
|
89
|
-
min: e.inputProps.min,
|
|
90
|
-
max: e.inputProps.max,
|
|
91
|
-
type: e.inputProps.type,
|
|
92
|
-
name: e.field.name,
|
|
93
|
-
label: e.inputProps.label,
|
|
94
|
-
"error-messages": e.inputProps.errorMessages,
|
|
95
|
-
error: e.inputProps.error
|
|
96
|
-
}, l.$attrs, {
|
|
97
|
-
"model-value": e.state.value,
|
|
98
|
-
"onUpdate:modelValue": i[1] || (i[1] = (t) => {
|
|
99
|
-
t || t === 0 ? e.field.handleChange(Number(t)) : e.field.handleChange(void 0);
|
|
100
|
-
})
|
|
101
|
-
}), d({ _: 2 }, [
|
|
102
|
-
l.$slots.label ? {
|
|
103
|
-
name: "label",
|
|
104
|
-
fn: r(() => [
|
|
105
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
106
|
-
]),
|
|
107
|
-
key: "0"
|
|
108
|
-
} : void 0
|
|
109
|
-
]), 1040, ["id", "required", "min", "max", "type", "name", "label", "error-messages", "error", "model-value"])) : u("", !0),
|
|
110
|
-
e.inputProps.type === "radio" ? (a(), n(h, o({
|
|
111
|
-
key: 4,
|
|
112
|
-
id: e.inputProps.id,
|
|
113
|
-
name: e.field.name,
|
|
114
|
-
label: e.inputProps.label,
|
|
115
|
-
"error-messages": e.inputProps.errorMessages,
|
|
116
|
-
error: e.inputProps.error
|
|
117
|
-
}, l.$attrs, {
|
|
118
|
-
"model-value": e.state.value,
|
|
119
|
-
"onUpdate:modelValue": e.field.handleChange
|
|
120
|
-
}), d({
|
|
121
|
-
default: r(() => [
|
|
122
|
-
(a(!0), v(V, null, U(e.inputProps.options, (t) => (a(), n(f, {
|
|
123
|
-
key: t.value,
|
|
124
|
-
label: t.title,
|
|
125
|
-
value: t.value
|
|
126
|
-
}, null, 8, ["label", "value"]))), 128))
|
|
127
|
-
]),
|
|
128
|
-
_: 2
|
|
129
|
-
}, [
|
|
130
|
-
l.$slots.label ? {
|
|
131
|
-
name: "label",
|
|
132
|
-
fn: r(() => [
|
|
133
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
134
|
-
]),
|
|
135
|
-
key: "0"
|
|
136
|
-
} : void 0
|
|
137
|
-
]), 1040, ["id", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : u("", !0),
|
|
138
|
-
e.inputProps.type === "select" || e.inputProps.type === "multiple" ? (a(), n(q, o({
|
|
139
|
-
key: 5,
|
|
140
|
-
id: e.inputProps.id,
|
|
141
|
-
clearable: e.inputProps.type === "select",
|
|
142
|
-
required: e.inputProps.required,
|
|
143
|
-
multiple: e.inputProps.type === "multiple",
|
|
144
|
-
chips: e.inputProps.type === "multiple",
|
|
145
|
-
name: e.field.name,
|
|
146
|
-
label: e.inputProps.label,
|
|
147
|
-
items: e.inputProps.options,
|
|
148
|
-
"error-messages": e.inputProps.errorMessages,
|
|
149
|
-
error: e.inputProps.error
|
|
150
|
-
}, l.$attrs, {
|
|
151
|
-
"model-value": e.state.value,
|
|
152
|
-
onClear: i[2] || (i[2] = (t) => e.field.handleChange(void 0)),
|
|
153
|
-
"onUpdate:modelValue": e.field.handleChange
|
|
154
|
-
}), d({ _: 2 }, [
|
|
155
|
-
l.$slots.label ? {
|
|
156
|
-
name: "label",
|
|
157
|
-
fn: r(() => [
|
|
158
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
159
|
-
]),
|
|
160
|
-
key: "0"
|
|
161
|
-
} : void 0
|
|
162
|
-
]), 1040, ["id", "clearable", "required", "multiple", "chips", "name", "label", "items", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : u("", !0),
|
|
163
|
-
e.inputProps.type === "autocomplete" || e.inputProps.type === "autocompletemultiple" ? (a(), n($, o({
|
|
164
|
-
key: 6,
|
|
165
|
-
id: e.inputProps.id,
|
|
166
|
-
clearable: e.inputProps.type === "autocomplete",
|
|
167
|
-
multiple: e.inputProps.type === "autocompletemultiple",
|
|
168
|
-
required: e.inputProps.required,
|
|
169
|
-
name: e.field.name,
|
|
170
|
-
label: e.inputProps.label,
|
|
171
|
-
items: e.inputProps.options,
|
|
172
|
-
"error-messages": e.inputProps.errorMessages,
|
|
173
|
-
error: e.inputProps.error,
|
|
174
|
-
chips: e.inputProps.type === "autocompletemultiple"
|
|
175
|
-
}, l.$attrs, {
|
|
176
|
-
"model-value": e.state.value,
|
|
177
|
-
onClear: i[3] || (i[3] = (t) => e.field.handleChange(void 0)),
|
|
178
|
-
"onUpdate:modelValue": e.field.handleChange
|
|
179
|
-
}), d({ _: 2 }, [
|
|
180
|
-
l.$slots.label ? {
|
|
181
|
-
name: "label",
|
|
182
|
-
fn: r(() => [
|
|
183
|
-
m(l.$slots, "label", s(P({ required: e.inputProps.required, id: e.inputProps.id, label: e.inputProps.label })))
|
|
184
|
-
]),
|
|
185
|
-
key: "0"
|
|
186
|
-
} : void 0
|
|
187
|
-
]), 1040, ["id", "clearable", "multiple", "required", "name", "label", "items", "error-messages", "error", "chips", "model-value", "onUpdate:modelValue"])) : u("", !0)
|
|
188
|
-
], 32);
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
export {
|
|
193
|
-
w as default
|
|
194
|
-
};
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { isObject } from "@vueuse/core"
|
|
2
|
-
import { S } from "effect-app"
|
|
3
|
-
import { isNullableOrUndefined } from "./OmegaFormStuff"
|
|
4
|
-
|
|
5
|
-
export function deepMerge(target: any, source: any) {
|
|
6
|
-
for (const key in source) {
|
|
7
|
-
if (Array.isArray(source[key])) {
|
|
8
|
-
// Arrays should be copied directly, not deep merged
|
|
9
|
-
target[key] = source[key]
|
|
10
|
-
} else if (source[key] && isObject(source[key])) {
|
|
11
|
-
if (!target[key]) {
|
|
12
|
-
target[key] = {}
|
|
13
|
-
}
|
|
14
|
-
deepMerge(target[key], source[key])
|
|
15
|
-
} else {
|
|
16
|
-
target[key] = source[key]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return target
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Recursively makes all properties in a schema optional, including nested objects.
|
|
24
|
-
* Unlike S.partial which only makes top-level properties optional, this utility
|
|
25
|
-
* traverses the schema tree and applies partial transformation at every level.
|
|
26
|
-
*
|
|
27
|
-
* Handles:
|
|
28
|
-
* - TypeLiteral (structs): Makes all properties optional and recursively processes nested types
|
|
29
|
-
* - Union types: Recursively applies partial to each union member
|
|
30
|
-
* - Transformation types: Applies partial to both 'from' and 'to' sides
|
|
31
|
-
*/
|
|
32
|
-
const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<A>, Partial<I>, R> => {
|
|
33
|
-
const ast = schema.ast
|
|
34
|
-
|
|
35
|
-
// Handle Refinement types (e.g., NonEmptyArray, filters on ExtendedClass)
|
|
36
|
-
if (ast._tag === "Refinement") {
|
|
37
|
-
const refinementAst = ast as any
|
|
38
|
-
// For refinements, bypass the filter and recursively apply partial to the underlying type
|
|
39
|
-
const fromSchema = S.make(refinementAst.from)
|
|
40
|
-
return partialRecursive(fromSchema as any)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Handle Union types - recursively apply partial to each member
|
|
44
|
-
if (ast._tag === "Union") {
|
|
45
|
-
const partialMembers = (ast as any).types.map((memberAst: any) => {
|
|
46
|
-
const memberSchema = S.make(memberAst)
|
|
47
|
-
const partialMember = partialRecursive(memberSchema as any)
|
|
48
|
-
return partialMember.ast
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
const newAst = {
|
|
52
|
-
...ast,
|
|
53
|
-
types: partialMembers
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return S.make(newAst as any)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Handle Transformation types (e.g., withDefaultConstructor, ExtendedClass)
|
|
60
|
-
if (ast._tag === "Transformation") {
|
|
61
|
-
const transformAst = ast as any
|
|
62
|
-
|
|
63
|
-
// Special handling for ExtendedClass (Declaration in 'to' side)
|
|
64
|
-
if (transformAst.to._tag === "Declaration") {
|
|
65
|
-
// For ExtendedClass, extract the TypeLiteral from the 'from' side
|
|
66
|
-
// and make that partial, bypassing the Declaration entirely
|
|
67
|
-
const fromSchema = S.make(transformAst.from)
|
|
68
|
-
return partialRecursive(fromSchema as any)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// For other transformations, apply partial to both sides
|
|
72
|
-
const fromSchema = S.make(transformAst.from)
|
|
73
|
-
const toSchema = S.make(transformAst.to)
|
|
74
|
-
const partialFrom = partialRecursive(fromSchema as any)
|
|
75
|
-
const partialTo = partialRecursive(toSchema as any)
|
|
76
|
-
|
|
77
|
-
const newAst = {
|
|
78
|
-
...ast,
|
|
79
|
-
from: partialFrom.ast,
|
|
80
|
-
to: partialTo.ast
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return S.make(newAst as any)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// If this is a TypeLiteral (struct), recursively apply partial to nested fields
|
|
87
|
-
if (ast._tag === "TypeLiteral") {
|
|
88
|
-
const fields = ast.propertySignatures.map((prop: any) => {
|
|
89
|
-
const propType = prop.type
|
|
90
|
-
let newType = propType
|
|
91
|
-
|
|
92
|
-
// Recursively handle nested complex types (structs, unions, transformations, refinements)
|
|
93
|
-
if (
|
|
94
|
-
propType._tag === "TypeLiteral" || propType._tag === "Union" || propType
|
|
95
|
-
._tag === "Transformation" || propType
|
|
96
|
-
._tag === "Refinement"
|
|
97
|
-
) {
|
|
98
|
-
const nestedSchema = S.make(propType)
|
|
99
|
-
const recursivePartial = partialRecursive(nestedSchema as any)
|
|
100
|
-
newType = recursivePartial.ast
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Create a new property signature with isOptional: true
|
|
104
|
-
return {
|
|
105
|
-
...prop,
|
|
106
|
-
type: newType,
|
|
107
|
-
isOptional: true
|
|
108
|
-
}
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
const newAst = {
|
|
112
|
-
...ast,
|
|
113
|
-
propertySignatures: fields
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return S.make(newAst as any)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// For other schema types (primitives, refinements, etc.), return as-is
|
|
120
|
-
// These types don't need to be made partial, and S.partial doesn't support them anyway
|
|
121
|
-
return schema as any
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Helper function to recursively extract default values from schema AST swag ast
|
|
125
|
-
export const extractDefaultsFromAST = (schemaObj: any): any => {
|
|
126
|
-
const result: Record<string, any> = {}
|
|
127
|
-
|
|
128
|
-
// Check if this schema has fields (struct)
|
|
129
|
-
if (schemaObj?.fields && typeof schemaObj.fields === "object") {
|
|
130
|
-
for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
|
|
131
|
-
// Check if this field has a default value in its AST
|
|
132
|
-
if ((fieldSchema as any)?.ast?.defaultValue) {
|
|
133
|
-
try {
|
|
134
|
-
const defaultValue = (fieldSchema as any).ast.defaultValue()
|
|
135
|
-
result[key] = defaultValue
|
|
136
|
-
} catch {
|
|
137
|
-
// Silently ignore if defaultValue() throws
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
// TODO Should we put to null/undefined only leaves?
|
|
141
|
-
const ast = (fieldSchema as any)?.ast
|
|
142
|
-
const nullableOrUndefined = isNullableOrUndefined(ast)
|
|
143
|
-
switch (nullableOrUndefined) {
|
|
144
|
-
case "null":
|
|
145
|
-
result[key] = null
|
|
146
|
-
break
|
|
147
|
-
case "undefined":
|
|
148
|
-
result[key] = undefined
|
|
149
|
-
break
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Recursively check nested fields for structs and unions
|
|
154
|
-
const nestedDefaults = extractDefaultsFromAST(fieldSchema as any)
|
|
155
|
-
if (Object.keys(nestedDefaults).length > 0) {
|
|
156
|
-
// If we already have a default value for this key, merge with nested
|
|
157
|
-
if (result[key] && typeof result[key] === "object") {
|
|
158
|
-
Object.assign(result[key], nestedDefaults)
|
|
159
|
-
} else if (!result[key]) {
|
|
160
|
-
// Only set nested defaults if we don't have a default value
|
|
161
|
-
result[key] = nestedDefaults
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
if (schemaObj?.from?.fields && typeof schemaObj?.from?.fields === "object") {
|
|
167
|
-
return extractDefaultsFromAST(schemaObj.from)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return result
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Extract default values from schema constructors (e.g., withDefaultConstructor) swag schema defaults
|
|
175
|
-
export const extractSchemaDefaults = <From, To>(
|
|
176
|
-
schema: S.Schema<To, From, never>,
|
|
177
|
-
defaultValues: Partial<From> = {}
|
|
178
|
-
) => {
|
|
179
|
-
let result: Partial<From> = {}
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
const astDefaults = extractDefaultsFromAST(schema)
|
|
183
|
-
result = S.encodeSync(partialRecursive(schema))(astDefaults)
|
|
184
|
-
} catch (astError) {
|
|
185
|
-
if (window.location.hostname === "localhost") {
|
|
186
|
-
console.warn("Could not extract defaults from AST:", astError)
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return deepMerge(result, defaultValues)
|
|
191
|
-
}
|