@effect-app/vue-components 2.7.8 → 2.7.9

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.
@@ -1,128 +1,137 @@
1
- import { useForm as z } from "@tanstack/vue-form";
2
- import { Data as Q, S, Effect as b, Array as g, Fiber as O, Option as D } from "effect-app";
3
- import { runtimeFiberAsPromise as X } from "./vue-components.es16.js";
4
- import { isObject as Y } from "./vue-components.es17.js";
5
- import { computed as V, onUnmounted as W, onMounted as Z, onBeforeUnmount as C, watch as H, ref as ee, h as B } from "vue";
6
- import te from "./vue-components.es18.js";
7
- import re from "./vue-components.es19.js";
8
- import ne from "./vue-components.es20.js";
9
- import { generateMetaFromSchema as se, isNullableOrUndefined as J } from "./vue-components.es12.js";
10
- import oe from "./vue-components.es6.js";
11
- import ie from "./vue-components.es8.js";
12
- import ae from "./vue-components.es21.js";
13
- import { trace as q } from "./vue-components.es22.js";
14
- import { context as T } from "./vue-components.es23.js";
15
- const A = (c) => {
1
+ import { useForm as K } from "@tanstack/vue-form";
2
+ import { Data as G, S as p, Effect as b, Array as A, Fiber as x, Option as O } from "effect-app";
3
+ import { runtimeFiberAsPromise as z } from "./vue-components.es16.js";
4
+ import { isObject as Q } from "./vue-components.es17.js";
5
+ import { computed as V, onUnmounted as N, onMounted as X, onBeforeUnmount as Y, watch as W, ref as Z, h as J } from "vue";
6
+ import C from "./vue-components.es18.js";
7
+ import ee from "./vue-components.es19.js";
8
+ import te from "./vue-components.es20.js";
9
+ import { generateMetaFromSchema as re, isNullableOrUndefined as ne } from "./vue-components.es12.js";
10
+ import se from "./vue-components.es6.js";
11
+ import oe from "./vue-components.es8.js";
12
+ import ie from "./vue-components.es21.js";
13
+ import { trace as H } from "./vue-components.es22.js";
14
+ import { context as L } from "./vue-components.es23.js";
15
+ const g = (c) => {
16
16
  const i = c.ast;
17
+ if (i._tag === "Refinement") {
18
+ const n = i, u = p.make(n.from);
19
+ return g(u);
20
+ }
17
21
  if (i._tag === "Union") {
18
- const o = i.types.map((f) => {
19
- const l = S.make(f);
20
- return A(l).ast;
21
- }), p = {
22
+ const n = i.types.map((f) => {
23
+ const l = p.make(f);
24
+ return g(l).ast;
25
+ }), u = {
22
26
  ...i,
23
- types: o
27
+ types: n
24
28
  };
25
- return S.make(p);
29
+ return p.make(u);
26
30
  }
27
31
  if (i._tag === "Transformation") {
28
- const o = S.make(i.from), p = S.make(i.to), f = A(o), l = A(p), d = {
32
+ const n = i;
33
+ if (n.to._tag === "Declaration") {
34
+ const h = p.make(n.from);
35
+ return g(h);
36
+ }
37
+ const u = p.make(n.from), f = p.make(n.to), l = g(u), d = g(f), w = {
29
38
  ...i,
30
- from: f.ast,
31
- to: l.ast
39
+ from: l.ast,
40
+ to: d.ast
32
41
  };
33
- return S.make(d);
42
+ return p.make(w);
34
43
  }
35
44
  if (i._tag === "TypeLiteral") {
36
- const o = i.propertySignatures.map((f) => {
45
+ const n = i.propertySignatures.map((f) => {
37
46
  const l = f.type;
38
47
  let d = l;
39
- if (l._tag === "TypeLiteral" || l._tag === "Union" || l._tag === "Transformation") {
40
- const k = S.make(l);
41
- d = A(k).ast;
48
+ if (l._tag === "TypeLiteral" || l._tag === "Union" || l._tag === "Transformation" || l._tag === "Refinement") {
49
+ const w = p.make(l);
50
+ d = g(w).ast;
42
51
  }
43
52
  return {
44
53
  ...f,
45
54
  type: d,
46
55
  isOptional: !0
47
56
  };
48
- }), p = {
57
+ }), u = {
49
58
  ...i,
50
- propertySignatures: o
59
+ propertySignatures: n
51
60
  };
52
- return S.make(p);
61
+ return p.make(u);
53
62
  }
54
63
  return c;
55
64
  };
56
- class le extends Q.TaggedError("FormErrors") {
65
+ class ae extends G.TaggedError("FormErrors") {
57
66
  }
58
- const M = (c) => function(o) {
67
+ const k = (c) => function(n) {
59
68
  return {
60
69
  render() {
61
- return B(o, {
70
+ return J(n, {
62
71
  form: c,
63
72
  ...this.$attrs
64
73
  }, this.$slots);
65
74
  }
66
75
  };
67
- }, ce = (c) => function(o) {
76
+ }, le = (c) => function(n) {
68
77
  return {
69
78
  setup() {
70
- const { fieldMap: p, form: f } = c, l = f.useStore((v) => v.errors), d = f.useStore((v) => v.fieldMeta), k = f.useStore((v) => v.errorMap), h = V(() => {
71
- const v = g.filterMap(
79
+ const { fieldMap: u, form: f } = c, l = f.useStore((S) => S.errors), d = f.useStore((S) => S.fieldMeta), w = f.useStore((S) => S.errorMap), h = V(() => {
80
+ const S = A.filterMap(
72
81
  Object.entries(d.value),
73
- ([x, w]) => {
74
- const a = w.errors ?? [];
75
- if (!a.length) return D.none();
76
- const y = p.value.get(x);
77
- return y ? D.some({
78
- label: y.label,
79
- inputId: y.id,
82
+ ([M, y]) => {
83
+ const a = y.errors ?? [];
84
+ if (!a.length) return O.none();
85
+ const v = u.value.get(M);
86
+ return v ? O.some({
87
+ label: v.label,
88
+ inputId: v.id,
80
89
  // Only show the first error
81
90
  errors: [a[0]?.message].filter(Boolean)
82
- }) : D.none();
91
+ }) : O.none();
83
92
  }
84
93
  ), F = [];
85
- if (k.value.onSubmit) {
86
- for (const [x, w] of Object.entries(k.value.onSubmit))
87
- if (g.isArray(w) && w.length)
88
- for (const a of w) {
89
- const y = a;
90
- if (y?.path && g.isArray(y.path) && y.path.length) {
91
- const _ = y.path.join(".");
92
- if (!p.value.has(_)) {
94
+ if (w.value.onSubmit) {
95
+ for (const [M, y] of Object.entries(w.value.onSubmit))
96
+ if (A.isArray(y) && y.length)
97
+ for (const a of y) {
98
+ const v = a;
99
+ if (v?.path && A.isArray(v.path) && v.path.length) {
100
+ const _ = v.path.join(".");
101
+ if (!u.value.has(_)) {
93
102
  F.push({
94
103
  label: _,
95
104
  inputId: _,
96
- errors: [y.message].filter(Boolean)
105
+ errors: [v.message].filter(Boolean)
97
106
  });
98
107
  break;
99
108
  }
100
109
  }
101
110
  }
102
111
  }
103
- return [...v, ...F];
112
+ return [...S, ...F];
104
113
  });
105
114
  return {
106
115
  generalErrors: l,
107
116
  errors: h
108
117
  };
109
118
  },
110
- render({ errors: p, generalErrors: f }) {
111
- return B(o, {
112
- errors: p,
119
+ render({ errors: u, generalErrors: f }) {
120
+ return J(n, {
121
+ errors: u,
113
122
  generalErrors: f,
114
123
  ...this.$attrs
115
124
  }, this.$slots);
116
125
  }
117
126
  };
118
- }, _e = (c, i, o) => {
127
+ }, _e = (c, i, n) => {
119
128
  if (!c) throw new Error("Schema is required");
120
- const p = S.standardSchemaV1(c), f = S.decode(c), { meta: l } = se(c), d = V(() => {
121
- if (o?.persistency?.id)
122
- return o.persistency.id;
129
+ const u = p.standardSchemaV1(c), f = p.decode(c), { meta: l } = re(c), d = V(() => {
130
+ if (n?.persistency?.id)
131
+ return n.persistency.id;
123
132
  const e = window.location.pathname, t = Object.keys(l);
124
133
  return `${e}-${t.join("-")}`;
125
- }), k = () => {
134
+ }), w = () => {
126
135
  const e = new URLSearchParams(window.location.search);
127
136
  e.delete(d.value);
128
137
  const t = new URL(window.location.href);
@@ -130,78 +139,48 @@ const M = (c) => function(o) {
130
139
  };
131
140
  function h(e, t) {
132
141
  for (const r in t)
133
- g.isArray(t[r]) ? e[r] = t[r] : t[r] && Y(t[r]) ? (e[r] || (e[r] = {}), h(e[r], t[r])) : e[r] = t[r];
142
+ A.isArray(t[r]) ? e[r] = t[r] : t[r] && Q(t[r]) ? (e[r] || (e[r] = {}), h(e[r], t[r])) : e[r] = t[r];
134
143
  return e;
135
144
  }
136
- const v = (e) => {
145
+ const S = (e) => {
137
146
  const t = {};
138
- if (typeof e?.make == "function")
139
- try {
140
- const n = e.make({});
141
- if (e?.fields && typeof e.fields == "object") {
142
- for (const [s, u] of Object.entries(e.fields))
143
- if (n[s] === void 0) {
144
- const m = u?.ast, U = J(m);
145
- U === "null" ? n[s] = null : U === "undefined" && (n[s] = void 0);
146
- }
147
- }
148
- return n;
149
- } catch {
150
- }
151
- const r = e?.members || (e?.ast?._tag === "Union" && e.ast.types ? e.ast.types.map((n) => S.make(n)) : null);
152
- if (r && g.isArray(r)) {
153
- for (const n of r) {
154
- const s = v(n);
155
- if (Object.keys(s).length > 0 && n?.fields && Object.entries(n.fields).some(
156
- ([m, U]) => m === "_tag" || m === "type" || m === "kind" ? U?.ast?.defaultValue !== void 0 : !1
157
- ))
158
- return s;
159
- }
160
- return {};
161
- }
162
147
  if (e?.fields && typeof e.fields == "object")
163
- for (const [n, s] of Object.entries(e.fields)) {
164
- if (s?.ast?.defaultValue)
148
+ for (const [r, o] of Object.entries(e.fields)) {
149
+ if (o?.ast?.defaultValue)
165
150
  try {
166
- const m = s.ast.defaultValue();
167
- t[n] = m;
151
+ const m = o.ast.defaultValue();
152
+ t[r] = m;
168
153
  } catch {
169
154
  }
170
155
  else {
171
- const m = s?.ast;
172
- switch (J(m)) {
156
+ const m = o?.ast;
157
+ switch (ne(m)) {
173
158
  case "null":
174
- t[n] = null;
159
+ t[r] = null;
175
160
  break;
176
161
  case "undefined":
177
- t[n] = void 0;
162
+ t[r] = void 0;
178
163
  break;
179
164
  }
180
165
  }
181
- const u = v(s);
182
- Object.keys(u).length > 0 && (t[n] && typeof t[n] == "object" ? Object.assign(t[n], u) : t[n] || (t[n] = u));
166
+ const s = S(o);
167
+ Object.keys(s).length > 0 && (t[r] && typeof t[r] == "object" ? Object.assign(t[r], s) : t[r] || (t[r] = s));
183
168
  }
169
+ else if (e?.from?.fields && typeof e?.from?.fields == "object")
170
+ return S(e.from);
184
171
  return t;
185
172
  }, F = (e = {}) => {
186
173
  let t = {};
187
174
  try {
188
- let r = c;
189
- r?.ast?._tag === "Refinement" && r?.from && (r = r.from);
190
- const n = r.make(e);
191
- t = S.encodeSync(A(r))(n);
175
+ const r = S(c);
176
+ t = p.encodeSync(g(c))(r);
192
177
  } catch (r) {
193
- window.location.hostname === "localhost" && console.warn("schema.make() failed, extracting defaults from AST:", r);
194
- try {
195
- const n = v(c);
196
- t = S.encodeSync(A(c))(n);
197
- } catch (n) {
198
- window.location.hostname === "localhost" && console.warn("Could not extract defaults from AST:", n);
199
- }
178
+ window.location.hostname === "localhost" && console.warn("Could not extract defaults from AST:", r);
200
179
  }
201
180
  return h(t, e);
202
- }, x = V(() => {
181
+ }, M = V(() => {
203
182
  let e;
204
- const t = o?.persistency;
183
+ const t = n?.persistency;
205
184
  if (
206
185
  // query string has higher priority than local/session storage
207
186
  t?.policies && !e && (t.policies.includes("local") || t.policies.includes("session"))
@@ -209,131 +188,131 @@ const M = (c) => function(o) {
209
188
  const r = t.policies.includes("local") ? localStorage : sessionStorage;
210
189
  if (r)
211
190
  try {
212
- const n = JSON.parse(
191
+ const o = JSON.parse(
213
192
  r.getItem(d.value) || "{}"
214
193
  );
215
- r.removeItem(d.value), e = n;
216
- } catch (n) {
217
- console.error(n);
194
+ r.removeItem(d.value), e = o;
195
+ } catch (o) {
196
+ console.error(o);
218
197
  }
219
198
  }
220
199
  if (t?.policies && t.policies.includes("querystring"))
221
200
  try {
222
- const n = new URLSearchParams(window.location.search).get(d.value);
223
- k(), n && (e = h(e || {}, JSON.parse(n)));
201
+ const o = new URLSearchParams(window.location.search).get(d.value);
202
+ w(), o && (e = h(e || {}, JSON.parse(o)));
224
203
  } catch (r) {
225
204
  console.error(r);
226
205
  }
227
206
  return e ??= {}, F(
228
- o?.persistency?.overrideDefaultValues ? h(i?.defaultValues || {}, e) : h(e, i?.defaultValues || {})
207
+ n?.persistency?.overrideDefaultValues ? h(i?.defaultValues || {}, e) : h(e, i?.defaultValues || {})
229
208
  );
230
- }), w = (e, t) => e ? T.with(q.setSpan(T.active(), e), t) : t(), a = z({
209
+ }), y = (e, t) => e ? L.with(H.setSpan(L.active(), e), t) : t(), a = K({
231
210
  ...i,
232
211
  validators: {
233
- onSubmit: p,
212
+ onSubmit: u,
234
213
  ...i?.validators || {}
235
214
  },
236
- onSubmit: i?.onSubmit ? ({ formApi: e, meta: t, value: r }) => w(t?.currentSpan, async () => {
237
- const n = await b.runPromise(f(r)), s = i.onSubmit({
215
+ onSubmit: i?.onSubmit ? ({ formApi: e, meta: t, value: r }) => y(t?.currentSpan, async () => {
216
+ const o = await b.runPromise(f(r)), s = i.onSubmit({
238
217
  formApi: e,
239
218
  meta: t,
240
- value: n
219
+ value: o
241
220
  });
242
- return O.isFiber(s) && O.isRuntimeFiber(s) ? await X(s) : b.isEffect(s) ? await b.runPromise(
221
+ return x.isFiber(s) && x.isRuntimeFiber(s) ? await z(s) : b.isEffect(s) ? await b.runPromise(
243
222
  s.pipe(
244
223
  // meta?.currentSpan
245
224
  // ? Effect.withParentSpan(meta.currentSpan)
246
225
  // : (_) => _,
247
- b.flatMap((u) => O.join(u))
226
+ b.flatMap((m) => x.join(m))
248
227
  )
249
228
  ) : s;
250
229
  }) : void 0,
251
- defaultValues: x.value
252
- }), y = () => {
230
+ defaultValues: M.value
231
+ }), v = () => {
253
232
  Object.keys(l).forEach((e) => {
254
233
  a.setFieldValue(e, void 0);
255
234
  });
256
235
  }, _ = (e) => e.reduce((t, r) => {
257
- const n = r.split(".");
258
- return n.reduce((s, u, m) => (m === n.length - 1 ? s[u] = a.getFieldValue(r) : s[u] = s[u] ?? {}, s[u]), t), t;
259
- }, {}), j = (e) => {
236
+ const o = r.split(".");
237
+ return o.reduce((s, m, U) => (U === o.length - 1 ? s[m] = a.getFieldValue(r) : s[m] = s[m] ?? {}, s[m]), t), t;
238
+ }, {}), D = (e) => {
260
239
  if (e) {
261
- if (g.isArray(e.keys))
240
+ if (A.isArray(e.keys))
262
241
  return _(e.keys);
263
- if (g.isArray(e.banKeys)) {
242
+ if (A.isArray(e.banKeys)) {
264
243
  const t = Object.keys(l).filter((r) => e.banKeys?.includes(r));
265
244
  return _(t);
266
245
  }
267
246
  return a.store.state.values;
268
247
  }
269
248
  }, P = () => {
270
- const e = o?.persistency;
249
+ const e = n?.persistency;
271
250
  if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
272
251
  const t = e.policies.includes("local") ? localStorage : sessionStorage;
273
252
  if (!t) return;
274
- const r = j(e);
253
+ const r = D(e);
275
254
  return t.setItem(d.value, JSON.stringify(r));
276
255
  }
277
- }, I = () => {
278
- const e = o?.persistency;
256
+ }, T = () => {
257
+ const e = n?.persistency;
279
258
  if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
280
- const t = j(e), r = new URLSearchParams(window.location.search);
259
+ const t = D(e), r = new URLSearchParams(window.location.search);
281
260
  r.set(d.value, JSON.stringify(t));
282
- const n = new URL(window.location.href);
283
- n.search = r.toString(), window.history.replaceState({}, "", n.toString());
261
+ const o = new URL(window.location.href);
262
+ o.search = r.toString(), window.history.replaceState({}, "", o.toString());
284
263
  }
285
- }, $ = (e) => {
264
+ }, I = (e) => {
286
265
  a.store.state.isDirty && e.preventDefault();
287
266
  };
288
- if (W(P), Z(() => {
289
- window.addEventListener("beforeunload", P), window.addEventListener("blur", I), o?.preventWindowExit && o.preventWindowExit !== "nope" && window.addEventListener("beforeunload", $);
290
- }), C(() => {
291
- window.removeEventListener("beforeunload", P), window.removeEventListener("blur", I), o?.preventWindowExit && o.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", $);
292
- }), o?.preventWindowExit === "prevent-and-reset") {
293
- const e = a.useStore((s) => s.isSubmitting), t = a.useStore((s) => s.submissionAttempts), r = a.useStore((s) => s.canSubmit), n = a.useStore((s) => s.values);
294
- H([e, t], ([s, u], [m]) => {
295
- m && !s && u > 0 && r.value && a.reset(n.value);
267
+ if (N(P), X(() => {
268
+ window.addEventListener("beforeunload", P), window.addEventListener("blur", T), n?.preventWindowExit && n.preventWindowExit !== "nope" && window.addEventListener("beforeunload", I);
269
+ }), Y(() => {
270
+ window.removeEventListener("beforeunload", P), window.removeEventListener("blur", T), n?.preventWindowExit && n.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", I);
271
+ }), n?.preventWindowExit === "prevent-and-reset") {
272
+ const e = a.useStore((s) => s.isSubmitting), t = a.useStore((s) => s.submissionAttempts), r = a.useStore((s) => s.canSubmit), o = a.useStore((s) => s.values);
273
+ W([e, t], ([s, m], [U]) => {
274
+ U && !s && m > 0 && r.value && a.reset(o.value);
296
275
  });
297
276
  }
298
- const N = (e) => b.currentSpan.pipe(
277
+ const R = (e) => b.currentSpan.pipe(
299
278
  b.option,
300
279
  b.flatMap(
301
- (t) => b.promise(() => a.handleSubmit(D.isSome(t) ? { currentSpan: t.value, ...e } : e))
280
+ (t) => b.promise(() => a.handleSubmit(O.isSome(t) ? { currentSpan: t.value, ...e } : e))
302
281
  )
303
- ), K = (e) => e?.checkErrors ? N(e?.meta).pipe(b.flatMap(b.fnUntraced(function* () {
282
+ ), q = (e) => e?.checkErrors ? R(e?.meta).pipe(b.flatMap(b.fnUntraced(function* () {
304
283
  const t = a.getAllErrors();
305
284
  if (Object.keys(t.fields).length || t.form.errors.length)
306
- return yield* new le({ form: t.form, fields: t.fields });
307
- }))) : N(e?.meta), G = a.handleSubmit, L = ee(/* @__PURE__ */ new Map()), E = Object.assign(a, {
308
- i18nNamespace: o?.i18nNamespace,
309
- ignorePreventCloseEvents: o?.ignorePreventCloseEvents,
285
+ return yield* new ae({ form: t.form, fields: t.fields });
286
+ }))) : R(e?.meta), B = a.handleSubmit, j = Z(/* @__PURE__ */ new Map()), E = Object.assign(a, {
287
+ i18nNamespace: n?.i18nNamespace,
288
+ ignorePreventCloseEvents: n?.ignorePreventCloseEvents,
310
289
  meta: l,
311
- clear: y,
290
+ clear: v,
312
291
  handleSubmit: (e) => {
313
- const t = q.getSpan(T.active());
314
- return G({ currentSpan: t, ...e });
292
+ const t = H.getSpan(L.active());
293
+ return B({ currentSpan: t, ...e });
315
294
  },
316
295
  // /** @experimental */
317
- handleSubmitEffect: K,
296
+ handleSubmitEffect: q,
318
297
  registerField: (e) => {
319
- H(e, (t) => L.value.set(t.name, { label: t.label, id: t.id }), { immediate: !0 }), W(() => L.value.delete(e.value.name));
298
+ W(e, (t) => j.value.set(t.name, { label: t.label, id: t.id }), { immediate: !0 }), N(() => j.value.delete(e.value.name));
320
299
  }
321
- }), R = { form: E, fieldMap: L };
300
+ }), $ = { form: E, fieldMap: j };
322
301
  return Object.assign(E, {
323
302
  // Type-level properties for performance optimization (not used at runtime)
324
303
  _paths: void 0,
325
304
  _keys: void 0,
326
- errorContext: R,
327
- Form: M(E)(ae),
328
- Input: M(E)(o?.input ?? oe),
329
- TaggedUnion: M(E)(ie),
305
+ errorContext: $,
306
+ Form: k(E)(ie),
307
+ Input: k(E)(n?.input ?? se),
308
+ TaggedUnion: k(E)(oe),
330
309
  Field: a.Field,
331
- Errors: ce(R)(ne),
332
- Array: M(E)(te),
333
- AutoGen: M(E)(re)
310
+ Errors: le($)(te),
311
+ Array: k(E)(C),
312
+ AutoGen: k(E)(ee)
334
313
  });
335
314
  };
336
315
  export {
337
- le as FormErrors,
316
+ ae as FormErrors,
338
317
  _e as useOmegaForm
339
318
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "2.7.8",
3
+ "version": "2.7.9",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^3.18.0",
@@ -53,8 +53,8 @@
53
53
  "highlight.js": "^11.11.1",
54
54
  "mitt": "^3.0.1",
55
55
  "vue3-highlightjs": "^1.0.5",
56
- "@effect-app/vue": "2.92.2",
57
- "effect-app": "3.12.0"
56
+ "effect-app": "3.12.0",
57
+ "@effect-app/vue": "2.92.2"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "pnpm build:run",
@@ -29,6 +29,14 @@ import OmegaForm from "./OmegaWrapper.vue"
29
29
  const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<A>, Partial<I>, R> => {
30
30
  const ast = schema.ast
31
31
 
32
+ // Handle Refinement types (e.g., NonEmptyArray, filters on ExtendedClass)
33
+ if (ast._tag === "Refinement") {
34
+ const refinementAst = ast as any
35
+ // For refinements, bypass the filter and recursively apply partial to the underlying type
36
+ const fromSchema = S.make(refinementAst.from)
37
+ return partialRecursive(fromSchema as any)
38
+ }
39
+
32
40
  // Handle Union types - recursively apply partial to each member
33
41
  if (ast._tag === "Union") {
34
42
  const partialMembers = (ast as any).types.map((memberAst: any) => {
@@ -45,11 +53,21 @@ const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<
45
53
  return S.make(newAst as any)
46
54
  }
47
55
 
48
- // Handle Transformation types (e.g., withDefaultConstructor)
56
+ // Handle Transformation types (e.g., withDefaultConstructor, ExtendedClass)
49
57
  if (ast._tag === "Transformation") {
50
- // For transformations, apply partial to both the 'from' and 'to' sides
51
- const fromSchema = S.make((ast as any).from)
52
- const toSchema = S.make((ast as any).to)
58
+ const transformAst = ast as any
59
+
60
+ // Special handling for ExtendedClass (Declaration in 'to' side)
61
+ if (transformAst.to._tag === "Declaration") {
62
+ // For ExtendedClass, extract the TypeLiteral from the 'from' side
63
+ // and make that partial, bypassing the Declaration entirely
64
+ const fromSchema = S.make(transformAst.from)
65
+ return partialRecursive(fromSchema as any)
66
+ }
67
+
68
+ // For other transformations, apply partial to both sides
69
+ const fromSchema = S.make(transformAst.from)
70
+ const toSchema = S.make(transformAst.to)
53
71
  const partialFrom = partialRecursive(fromSchema as any)
54
72
  const partialTo = partialRecursive(toSchema as any)
55
73
 
@@ -68,8 +86,12 @@ const partialRecursive = <A, I, R>(schema: S.Schema<A, I, R>): S.Schema<Partial<
68
86
  const propType = prop.type
69
87
  let newType = propType
70
88
 
71
- // Recursively handle nested complex types (structs, unions, transformations)
72
- if (propType._tag === "TypeLiteral" || propType._tag === "Union" || propType._tag === "Transformation") {
89
+ // Recursively handle nested complex types (structs, unions, transformations, refinements)
90
+ if (
91
+ propType._tag === "TypeLiteral" || propType._tag === "Union" || propType
92
+ ._tag === "Transformation" || propType
93
+ ._tag === "Refinement"
94
+ ) {
73
95
  const nestedSchema = S.make(propType)
74
96
  const recursivePartial = partialRecursive(nestedSchema as any)
75
97
  newType = recursivePartial.ast
@@ -762,66 +784,6 @@ export const useOmegaForm = <
762
784
  const extractDefaultsFromAST = (schemaObj: any): any => {
763
785
  const result: Record<string, any> = {}
764
786
 
765
- // If this schema has a .make() method (like ExtendedClass), use it to get complete defaults
766
- // This is more reliable than manually extracting fields, especially for classes
767
- if (typeof schemaObj?.make === "function") {
768
- try {
769
- const instance = schemaObj.make({})
770
- // For ExtendedClass, the instance is already in the correct encoded format
771
- // But we need to check for nullable fields that may have been set to undefined
772
- // instead of null, and fix them
773
- if (schemaObj?.fields && typeof schemaObj.fields === "object") {
774
- for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
775
- // Only fix fields that are undefined in the instance
776
- if (instance[key] === undefined) {
777
- const ast = (fieldSchema as any)?.ast
778
- const nullableOrUndefined = isNullableOrUndefined(ast)
779
- if (nullableOrUndefined === "null") {
780
- instance[key] = null
781
- } else if (nullableOrUndefined === "undefined") {
782
- instance[key] = undefined
783
- }
784
- }
785
- }
786
- }
787
- return instance
788
- } catch {
789
- // If make() fails, fall through to manual extraction
790
- }
791
- }
792
-
793
- // Check if this schema is a union - check both direct property and AST
794
- const unionMembers = schemaObj?.members
795
- || (schemaObj?.ast?._tag === "Union" && schemaObj.ast.types
796
- ? schemaObj.ast.types.map((t: any) => S.make(t))
797
- : null)
798
- if (unionMembers && Array.isArray(unionMembers)) {
799
- // For unions, we try to find the first member that has a complete set of defaults
800
- // Priority is given to members with default values for discriminator fields
801
- for (const member of unionMembers as any[]) {
802
- const memberDefaults = extractDefaultsFromAST(member)
803
- if (Object.keys(memberDefaults).length > 0) {
804
- // Check if this member has a default value for a discriminator field (like _tag)
805
- // If it does, use this member's defaults
806
- const hasDiscriminatorDefault = member?.fields && Object.entries(member.fields).some(
807
- ([key, fieldSchema]: [string, any]) => {
808
- // Common discriminator field names
809
- if (key === "_tag" || key === "type" || key === "kind") {
810
- return fieldSchema?.ast?.defaultValue !== undefined
811
- }
812
- return false
813
- }
814
- )
815
-
816
- if (hasDiscriminatorDefault) {
817
- return memberDefaults
818
- }
819
- }
820
- }
821
- // If no member has a discriminator default, return empty
822
- return {}
823
- }
824
-
825
787
  // Check if this schema has fields (struct)
826
788
  if (schemaObj?.fields && typeof schemaObj.fields === "object") {
827
789
  for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
@@ -859,6 +821,10 @@ export const useOmegaForm = <
859
821
  }
860
822
  }
861
823
  }
824
+ } else {
825
+ if (schemaObj?.from?.fields && typeof schemaObj?.from?.fields === "object") {
826
+ return extractDefaultsFromAST(schemaObj.from)
827
+ }
862
828
  }
863
829
 
864
830
  return result
@@ -869,30 +835,14 @@ export const useOmegaForm = <
869
835
  let result: Partial<From> = {}
870
836
 
871
837
  try {
872
- // For filtered schemas (created with S.filter), use the original unfiltered schema's make method
873
- let schemaToUse = schema as any
874
- if (schemaToUse?.ast?._tag === "Refinement" && schemaToUse?.from) {
875
- schemaToUse = schemaToUse.from
876
- }
877
-
878
- // First try to use schema.make() if available
879
- // Note: Partial schemas don't have .make() method yet (https://github.com/Effect-TS/effect/issues/4222)
880
- const decoded = schemaToUse.make(defaultValues)
881
- result = S.encodeSync(partialRecursive(schemaToUse))(decoded)
882
- } catch (error) {
883
- // If make() fails, try to extract defaults from AST
838
+ const astDefaults = extractDefaultsFromAST(schema)
839
+ result = S.encodeSync(partialRecursive(schema))(astDefaults)
840
+ } catch (astError) {
884
841
  if (window.location.hostname === "localhost") {
885
- console.warn("schema.make() failed, extracting defaults from AST:", error)
886
- }
887
- try {
888
- const astDefaults = extractDefaultsFromAST(schema)
889
- result = S.encodeSync(partialRecursive(schema))(astDefaults)
890
- } catch (astError) {
891
- if (window.location.hostname === "localhost") {
892
- console.warn("Could not extract defaults from AST:", astError)
893
- }
842
+ console.warn("Could not extract defaults from AST:", astError)
894
843
  }
895
844
  }
845
+
896
846
  return deepMerge(result, defaultValues)
897
847
  }
898
848