@effect-app/vue-components 4.0.0-beta.46 → 4.0.0-beta.48

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.
@@ -395,58 +395,46 @@ function A(t, n) {
395
395
  return r;
396
396
  }
397
397
  function j(e) {
398
- return e && "fields" in e && typeof e.fields == "object";
399
- }
400
- function M(e) {
401
398
  return e && "members" in e && Array.isArray(e.members);
402
399
  }
403
- var N = (e, t = {}) => {
400
+ var M = (e, t = {}) => {
404
401
  let n = e.ast, r = _(n);
405
402
  if (r !== void 0) return r;
406
403
  if (f(e.ast) === "null") return null;
407
- if (f(e.ast) !== "undefined") {
408
- if (j(e)) {
409
- let n = {};
410
- for (let [r, i] of Object.entries(e.fields)) {
411
- let e = _(i?.ast);
412
- if (e !== void 0) {
413
- n[r] = e;
414
- continue;
415
- }
416
- let a = N(i, t[r] || {});
417
- a === void 0 ? f(i.ast) === "undefined" && (n[r] = void 0) : n[r] = a;
404
+ if (f(e.ast) === "undefined") return;
405
+ let i = a.AST.isObjects(n) ? n : a.AST.isDeclaration(n) ? c(n) : void 0;
406
+ if (i && a.AST.isObjects(i)) {
407
+ let e = {};
408
+ for (let n of i.propertySignatures) {
409
+ let r = n.name.toString(), i = n.type, o = _(i);
410
+ if (o !== void 0) {
411
+ e[r] = o;
412
+ continue;
418
413
  }
419
- return {
420
- ...n,
421
- ...t
422
- };
414
+ let s = M(a.make(i), t[r] || {});
415
+ s === void 0 ? f(i) === "undefined" && (e[r] = void 0) : e[r] = s;
423
416
  }
424
- if (e?.from && j(e.from)) return N(e.from, t);
425
- if (M(e)) {
426
- let n = e.members.reduce((e, t) => (j(t) && Object.entries(t.fields).forEach(([t, n]) => {
427
- let r = _(n.ast), i = e[t] ? _(e[t].ast) : void 0;
428
- (!e[t] || r !== void 0 && i === void 0) && (e[t] = n);
429
- }), e), {});
430
- return Object.keys(n).length === 0 ? Object.keys(t).length > 0 ? t : void 0 : Object.entries(n).reduce((e, [n, r]) => (e[n] = N(r, t[n] || {}), e), t);
431
- }
432
- if (Object.keys(t).length === 0) {
433
- if (a.AST.isObjects(n)) {
434
- let e = { ...t };
435
- for (let r of n.propertySignatures) {
436
- let n = r.name.toString(), i = r.type, o = _(i);
437
- if (o !== void 0) {
438
- e[n] = o;
439
- continue;
440
- }
441
- let s = N(a.make(i), t[n] || {});
442
- s === void 0 ? f(i) === "undefined" && (e[n] = void 0) : e[n] = s;
443
- }
444
- return e;
417
+ return {
418
+ ...e,
419
+ ...t
420
+ };
421
+ }
422
+ let o = a.AST.isUnion(n) ? n.types : j(e) ? e.members.map((e) => e.ast) : void 0;
423
+ if (o) {
424
+ let e = {};
425
+ for (let t of o) {
426
+ let n = c(t);
427
+ if (a.AST.isObjects(n)) for (let t of n.propertySignatures) {
428
+ let n = t.name.toString(), r = _(t.type), i = e[n] ? _(e[n].ast) : void 0;
429
+ (!e[n] || r !== void 0 && i === void 0) && (e[n] = { ast: t.type });
445
430
  }
446
- if (a.AST.isString(n)) return "";
447
- if (a.AST.isBoolean(n)) return !1;
448
431
  }
432
+ return Object.keys(e).length === 0 ? Object.keys(t).length > 0 ? t : void 0 : Object.entries(e).reduce((e, [n, { ast: r }]) => (e[n] = M(a.make(r), t[n] || {}), e), t);
433
+ }
434
+ if (Object.keys(t).length === 0) {
435
+ if (a.AST.isString(n)) return "";
436
+ if (a.AST.isBoolean(n)) return !1;
449
437
  }
450
438
  };
451
439
  //#endregion
452
- export { b as createMeta, A as deepMerge, N as defaultsValueFromSchema, T as duplicateSchema, D as generateInputStandardSchemaFromFieldMeta, E as generateMetaFromSchema, k as getInputType, f as isNullableOrUndefined, w as toFormSchema };
440
+ export { b as createMeta, A as deepMerge, M as defaultsValueFromSchema, T as duplicateSchema, D as generateInputStandardSchemaFromFieldMeta, E as generateMetaFromSchema, k as getInputType, f as isNullableOrUndefined, w as toFormSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "4.0.0-beta.46",
3
+ "version": "4.0.0-beta.48",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^4.0.0-beta.43",
@@ -33,7 +33,7 @@
33
33
  "vue-toastification": "^2.0.0-rc.5",
34
34
  "vue-tsc": "^3.2.6",
35
35
  "vuetify": "^4.0.4",
36
- "@effect-app/eslint-shared-config": "0.5.7-beta.4"
36
+ "@effect-app/eslint-shared-config": "0.5.7-beta.6"
37
37
  },
38
38
  "files": [
39
39
  "src",
@@ -57,8 +57,8 @@
57
57
  "highlight.js": "^11.11.1",
58
58
  "mitt": "^3.0.1",
59
59
  "vue3-highlightjs": "^1.0.5",
60
- "@effect-app/vue": "4.0.0-beta.46",
61
- "effect-app": "4.0.0-beta.46"
60
+ "@effect-app/vue": "4.0.0-beta.48",
61
+ "effect-app": "4.0.0-beta.48"
62
62
  },
63
63
  "scripts": {
64
64
  "check": "vue-tsc",
@@ -1207,20 +1207,10 @@ export function deepMerge(target: any, source: any) {
1207
1207
  return result
1208
1208
  }
1209
1209
 
1210
- // Type definitions for schemas with fields and members
1211
- type SchemaWithFields = {
1212
- fields: Record<string, S.Schema<any>>
1213
- }
1214
-
1215
1210
  type SchemaWithMembers = {
1216
1211
  members: readonly S.Schema<any>[]
1217
1212
  }
1218
1213
 
1219
- // Type guards to check schema types
1220
- function hasFields(schema: any): schema is SchemaWithFields {
1221
- return schema && "fields" in schema && typeof schema.fields === "object"
1222
- }
1223
-
1224
1214
  function hasMembers(schema: any): schema is SchemaWithMembers {
1225
1215
  return schema && "members" in schema && Array.isArray(schema.members)
1226
1216
  }
@@ -1244,23 +1234,31 @@ export const defaultsValueFromSchema = (
1244
1234
  return undefined
1245
1235
  }
1246
1236
 
1247
- // Check if schema has fields directly
1248
- if (hasFields(schema)) {
1249
- // Process fields and extract default values
1237
+ // Handle structs via AST (covers plain structs, transformed schemas like decodeTo, ExtendedClass, etc.)
1238
+ const objectsAst = S.AST.isObjects(ast)
1239
+ ? ast
1240
+ : S.AST.isDeclaration(ast)
1241
+ ? unwrapDeclaration(ast)
1242
+ : undefined
1243
+ if (objectsAst && S.AST.isObjects(objectsAst)) {
1250
1244
  const result: Record<string, any> = {}
1251
1245
 
1252
- for (const [key, fieldSchema] of Object.entries(schema.fields)) {
1253
- const fieldDefault = getDefaultFromAst((fieldSchema as any)?.ast)
1254
- if (fieldDefault !== undefined) {
1255
- result[key] = fieldDefault
1246
+ for (const prop of objectsAst.propertySignatures) {
1247
+ const key = prop.name.toString()
1248
+ const propType = prop.type
1249
+
1250
+ const propDefault = getDefaultFromAst(propType)
1251
+ if (propDefault !== undefined) {
1252
+ result[key] = propDefault
1256
1253
  continue
1257
1254
  }
1258
1255
 
1259
- // Recursively process the field
1260
- const fieldValue = defaultsValueFromSchema(fieldSchema as any, record[key] || {})
1261
- if (fieldValue !== undefined) {
1262
- result[key] = fieldValue
1263
- } else if (isNullableOrUndefined((fieldSchema as any).ast) === "undefined") {
1256
+ const propSchema = S.make(propType)
1257
+ const propValue = defaultsValueFromSchema(propSchema, record[key] || {})
1258
+
1259
+ if (propValue !== undefined) {
1260
+ result[key] = propValue
1261
+ } else if (isNullableOrUndefined(propType) === "undefined") {
1264
1262
  result[key] = undefined
1265
1263
  }
1266
1264
  }
@@ -1268,74 +1266,41 @@ export const defaultsValueFromSchema = (
1268
1266
  return { ...result, ...record }
1269
1267
  }
1270
1268
 
1271
- // Check if schema has fields in from (for ExtendedClass and similar transformations)
1272
- if ((schema as any)?.from && hasFields((schema as any).from)) {
1273
- return defaultsValueFromSchema((schema as any).from, record)
1274
- }
1269
+ // Handle unions via AST or schema-level .members
1270
+ const unionTypes = S.AST.isUnion(ast)
1271
+ ? ast.types
1272
+ : hasMembers(schema)
1273
+ ? schema.members.map((m) => m.ast)
1274
+ : undefined
1275
+ if (unionTypes) {
1276
+ const mergedFields: Record<string, { ast: S.AST.AST }> = {}
1275
1277
 
1276
- if (hasMembers(schema)) {
1277
- // Merge all member fields, giving precedence to fields with default values
1278
- const mergedMembers = schema.members.reduce((acc, member) => {
1279
- if (hasFields(member)) {
1280
- // Check each field and give precedence to ones with default values
1281
- Object.entries(member.fields).forEach(([key, fieldSchema]) => {
1282
- const fieldDefault = getDefaultFromAst(fieldSchema.ast)
1283
- const existingDefault = acc[key] ? getDefaultFromAst(acc[key].ast) : undefined
1284
-
1285
- // If field doesn't exist yet, or new field has default and existing doesn't, use new field
1286
- if (!acc[key] || (fieldDefault !== undefined && existingDefault === undefined)) {
1287
- acc[key] = fieldSchema
1288
- }
1289
- // If both have defaults or neither have defaults, keep the first one (existing)
1290
- })
1291
- return acc
1278
+ for (const memberAstRaw of unionTypes) {
1279
+ const memberAst = unwrapDeclaration(memberAstRaw)
1280
+ if (!S.AST.isObjects(memberAst)) continue
1281
+
1282
+ for (const prop of memberAst.propertySignatures) {
1283
+ const key = prop.name.toString()
1284
+ const fieldDefault = getDefaultFromAst(prop.type)
1285
+ const existingDefault = mergedFields[key] ? getDefaultFromAst(mergedFields[key]!.ast) : undefined
1286
+
1287
+ if (!mergedFields[key] || (fieldDefault !== undefined && existingDefault === undefined)) {
1288
+ mergedFields[key] = { ast: prop.type }
1289
+ }
1292
1290
  }
1293
- return acc
1294
- }, {} as Record<string, any>)
1291
+ }
1295
1292
 
1296
- if (Object.keys(mergedMembers).length === 0) {
1293
+ if (Object.keys(mergedFields).length === 0) {
1297
1294
  return Object.keys(record).length > 0 ? record : undefined
1298
1295
  }
1299
1296
 
1300
- // Use reduce to properly accumulate the merged fields
1301
- return Object.entries(mergedMembers).reduce((acc, [key, value]) => {
1302
- acc[key] = defaultsValueFromSchema(value, record[key] || {})
1297
+ return Object.entries(mergedFields).reduce((acc, [key, { ast: propAst }]) => {
1298
+ acc[key] = defaultsValueFromSchema(S.make(propAst), record[key] || {})
1303
1299
  return acc
1304
1300
  }, record)
1305
1301
  }
1306
1302
 
1307
1303
  if (Object.keys(record).length === 0) {
1308
- if (S.AST.isObjects(ast)) {
1309
- // Process TypeLiteral fields directly to build the result object
1310
- const result: Record<string, any> = { ...record }
1311
-
1312
- for (const prop of ast.propertySignatures) {
1313
- const key = prop.name.toString()
1314
- const propType = prop.type
1315
-
1316
- const propDefault = getDefaultFromAst(propType)
1317
- if (propDefault !== undefined) {
1318
- result[key] = propDefault
1319
- continue
1320
- }
1321
-
1322
- // Create a schema from the property type and get its defaults
1323
- const propSchema = S.make(propType)
1324
-
1325
- // Recursively process the property - don't pas for prop processing
1326
- // to allow proper unwrapping of nested structures
1327
- const propValue = defaultsValueFromSchema(propSchema, record[key] || {})
1328
-
1329
- if (propValue !== undefined) {
1330
- result[key] = propValue
1331
- } else if (isNullableOrUndefined(propType) === "undefined") {
1332
- result[key] = undefined
1333
- }
1334
- }
1335
-
1336
- return result
1337
- }
1338
-
1339
1304
  if (S.AST.isString(ast)) {
1340
1305
  return ""
1341
1306
  }