@voidhash/mimic 0.0.1-alpha.9 → 0.0.1

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/index.cjs CHANGED
@@ -2349,6 +2349,177 @@ var Primitive_exports = /* @__PURE__ */ require_Document.__export({
2349
2349
  //#region src/Transform.ts
2350
2350
  var Transform_exports = {};
2351
2351
 
2352
+ //#endregion
2353
+ //#region src/EffectSchema.ts
2354
+ /**
2355
+ * Effect.Schema utilities for converting Mimic primitives to Effect.Schema schemas.
2356
+ *
2357
+ * @since 0.0.1
2358
+ */
2359
+ var EffectSchema_exports = /* @__PURE__ */ require_Document.__export({
2360
+ TreeNodeStateSchema: () => TreeNodeStateSchema,
2361
+ toSetSchema: () => toSetSchema,
2362
+ toUpdateSchema: () => toUpdateSchema
2363
+ });
2364
+ /**
2365
+ * Schema for a tree node state (flat storage format).
2366
+ */
2367
+ const TreeNodeStateSchema = effect.Schema.Struct({
2368
+ id: effect.Schema.String,
2369
+ type: effect.Schema.String,
2370
+ parentId: effect.Schema.NullOr(effect.Schema.String),
2371
+ pos: effect.Schema.String,
2372
+ data: effect.Schema.Unknown
2373
+ });
2374
+ /**
2375
+ * Check if a field is required for set operations.
2376
+ * A field is required if: TRequired is true AND THasDefault is false.
2377
+ *
2378
+ * We determine this by checking the primitive's schema properties.
2379
+ */
2380
+ function isRequiredForSet(primitive) {
2381
+ const schema = primitive._schema;
2382
+ if (!schema) return false;
2383
+ return schema.required === true && schema.defaultValue === void 0;
2384
+ }
2385
+ /**
2386
+ * Get the base Effect.Schema for a primitive type (without optional wrapper).
2387
+ */
2388
+ function getBaseSchema(primitive) {
2389
+ switch (primitive._tag) {
2390
+ case "StringPrimitive": return effect.Schema.String;
2391
+ case "NumberPrimitive": return effect.Schema.Number;
2392
+ case "BooleanPrimitive": return effect.Schema.Boolean;
2393
+ case "LiteralPrimitive": {
2394
+ var _schema$literal, _schema;
2395
+ const literalPrimitive = primitive;
2396
+ const literalValue = (_schema$literal = (_schema = literalPrimitive._schema) === null || _schema === void 0 ? void 0 : _schema.literal) !== null && _schema$literal !== void 0 ? _schema$literal : literalPrimitive.literal;
2397
+ return effect.Schema.Literal(literalValue);
2398
+ }
2399
+ case "StructPrimitive": return buildStructSetSchema(primitive);
2400
+ case "ArrayPrimitive": {
2401
+ const elementSchema = buildElementSetSchema(primitive.element);
2402
+ return effect.Schema.Array(elementSchema);
2403
+ }
2404
+ case "UnionPrimitive": return buildUnionSetSchema(primitive);
2405
+ case "EitherPrimitive": return buildEitherSchema(primitive);
2406
+ case "LazyPrimitive": {
2407
+ var _resolve, _resolve2;
2408
+ const lazyPrimitive = primitive;
2409
+ return getBaseSchema((_resolve = (_resolve2 = lazyPrimitive._resolve) === null || _resolve2 === void 0 ? void 0 : _resolve2.call(lazyPrimitive)) !== null && _resolve !== void 0 ? _resolve : lazyPrimitive._thunk());
2410
+ }
2411
+ case "TreeNodePrimitive": return buildStructSetSchema(primitive.data);
2412
+ case "TreePrimitive": return effect.Schema.Array(TreeNodeStateSchema);
2413
+ default: return effect.Schema.Unknown;
2414
+ }
2415
+ }
2416
+ /**
2417
+ * Build the set schema for a struct primitive.
2418
+ * Required fields (required=true, no default) are non-optional.
2419
+ * Other fields are wrapped with Schema.optional.
2420
+ */
2421
+ function buildStructSetSchema(structPrimitive) {
2422
+ const fields = structPrimitive.fields;
2423
+ const schemaFields = {};
2424
+ for (const key in fields) {
2425
+ const fieldPrimitive = fields[key];
2426
+ const baseSchema = getBaseSchema(fieldPrimitive);
2427
+ if (isRequiredForSet(fieldPrimitive)) schemaFields[key] = baseSchema;
2428
+ else schemaFields[key] = effect.Schema.optional(baseSchema);
2429
+ }
2430
+ return effect.Schema.Struct(schemaFields);
2431
+ }
2432
+ /**
2433
+ * Build the update schema for a struct primitive.
2434
+ * All fields are optional for partial updates.
2435
+ */
2436
+ function buildStructUpdateSchema(structPrimitive) {
2437
+ const fields = structPrimitive.fields;
2438
+ const schemaFields = {};
2439
+ for (const key in fields) {
2440
+ const fieldPrimitive = fields[key];
2441
+ let fieldSchema;
2442
+ if (fieldPrimitive._tag === "StructPrimitive") fieldSchema = buildStructUpdateSchema(fieldPrimitive);
2443
+ else fieldSchema = getBaseSchema(fieldPrimitive);
2444
+ schemaFields[key] = effect.Schema.optional(fieldSchema);
2445
+ }
2446
+ return effect.Schema.Struct(schemaFields);
2447
+ }
2448
+ /**
2449
+ * Build the set schema for an array element.
2450
+ * For struct elements, uses the struct's set input schema.
2451
+ */
2452
+ function buildElementSetSchema(elementPrimitive) {
2453
+ if (elementPrimitive._tag === "StructPrimitive") return buildStructSetSchema(elementPrimitive);
2454
+ return getBaseSchema(elementPrimitive);
2455
+ }
2456
+ /**
2457
+ * Build the set schema for a union primitive.
2458
+ * Creates a Schema.Union of all variant schemas.
2459
+ */
2460
+ function buildUnionSetSchema(unionPrimitive) {
2461
+ const variants = unionPrimitive.variants;
2462
+ const variantSchemas = [];
2463
+ for (const key in variants) {
2464
+ const variantPrimitive = variants[key];
2465
+ variantSchemas.push(buildStructSetSchema(variantPrimitive));
2466
+ }
2467
+ if (variantSchemas.length === 0) return effect.Schema.Unknown;
2468
+ if (variantSchemas.length === 1) return variantSchemas[0];
2469
+ return effect.Schema.Union(...variantSchemas);
2470
+ }
2471
+ /**
2472
+ * Build the schema for an either primitive.
2473
+ * Creates a Schema.Union of all scalar variant types.
2474
+ */
2475
+ function buildEitherSchema(eitherPrimitive) {
2476
+ const variants = eitherPrimitive.variants;
2477
+ const variantSchemas = [];
2478
+ for (const variant of variants) variantSchemas.push(getBaseSchema(variant));
2479
+ if (variantSchemas.length === 0) return effect.Schema.Unknown;
2480
+ if (variantSchemas.length === 1) return variantSchemas[0];
2481
+ return effect.Schema.Union(...variantSchemas);
2482
+ }
2483
+ /**
2484
+ * Build the update schema for a union primitive.
2485
+ * Creates a Schema.Union of all variant update schemas.
2486
+ */
2487
+ function buildUnionUpdateSchema(unionPrimitive) {
2488
+ const variants = unionPrimitive.variants;
2489
+ const variantSchemas = [];
2490
+ for (const key in variants) {
2491
+ const variantPrimitive = variants[key];
2492
+ variantSchemas.push(buildStructUpdateSchema(variantPrimitive));
2493
+ }
2494
+ if (variantSchemas.length === 0) return effect.Schema.Unknown;
2495
+ if (variantSchemas.length === 1) return variantSchemas[0];
2496
+ return effect.Schema.Union(...variantSchemas);
2497
+ }
2498
+ /**
2499
+ * Get the update schema for a primitive.
2500
+ * For structs, all fields are optional (partial updates).
2501
+ * For simple primitives, same as set schema.
2502
+ */
2503
+ function getUpdateSchema(primitive) {
2504
+ switch (primitive._tag) {
2505
+ case "StructPrimitive": return buildStructUpdateSchema(primitive);
2506
+ case "UnionPrimitive": return buildUnionUpdateSchema(primitive);
2507
+ case "TreeNodePrimitive": return buildStructUpdateSchema(primitive.data);
2508
+ case "LazyPrimitive": {
2509
+ var _resolve3, _resolve4;
2510
+ const lazyPrimitive = primitive;
2511
+ return getUpdateSchema((_resolve3 = (_resolve4 = lazyPrimitive._resolve) === null || _resolve4 === void 0 ? void 0 : _resolve4.call(lazyPrimitive)) !== null && _resolve3 !== void 0 ? _resolve3 : lazyPrimitive._thunk());
2512
+ }
2513
+ default: return getBaseSchema(primitive);
2514
+ }
2515
+ }
2516
+ function toSetSchema(primitive) {
2517
+ return getBaseSchema(primitive);
2518
+ }
2519
+ function toUpdateSchema(primitive) {
2520
+ return getUpdateSchema(primitive);
2521
+ }
2522
+
2352
2523
  //#endregion
2353
2524
  Object.defineProperty(exports, 'Document', {
2354
2525
  enumerable: true,
@@ -2356,6 +2527,12 @@ Object.defineProperty(exports, 'Document', {
2356
2527
  return require_Document.Document_exports;
2357
2528
  }
2358
2529
  });
2530
+ Object.defineProperty(exports, 'EffectSchema', {
2531
+ enumerable: true,
2532
+ get: function () {
2533
+ return EffectSchema_exports;
2534
+ }
2535
+ });
2359
2536
  Object.defineProperty(exports, 'Operation', {
2360
2537
  enumerable: true,
2361
2538
  get: function () {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { a as InferState, c as ProxyEnvironment_d_exports, d as Transaction_d_exports, f as Operation, h as __export, i as InferSnapshot, m as OperationPath_d_exports, n as AnyPrimitive, p as Operation_d_exports, r as InferProxy, s as Transform_d_exports, t as Primitive_d_exports, u as Transaction } from "./Primitive-Cyvy7zvF.cjs";
1
+ import { _ as OperationPath_d_exports, a as InferSetInput, c as InferUpdateInput, d as ProxyEnvironment_d_exports, g as Operation_d_exports, h as Operation, i as InferProxy, m as Transaction_d_exports, n as AnyTreeNodePrimitive, o as InferSnapshot, p as Transaction, r as AnyPrimitive, s as InferState, t as Primitive_d_exports, u as Transform_d_exports, v as __export } from "./Primitive-CvFVxR8_.cjs";
2
2
  import { i as Presence_d_exports } from "./Presence-DKKP4v5X.cjs";
3
+ import { Schema } from "effect";
3
4
 
4
5
  //#region src/Document.d.ts
5
6
  declare namespace Document_d_exports {
@@ -61,6 +62,82 @@ interface DocumentOptions<TSchema extends AnyPrimitive> {
61
62
  * Creates a new Document for the given schema.
62
63
  */
63
64
  declare const make: <TSchema extends AnyPrimitive>(schema: TSchema, options?: DocumentOptions<TSchema>) => Document<TSchema>;
65
+ declare namespace EffectSchema_d_exports {
66
+ export { ToSetSchema, ToTreeNodeSetSchema, ToTreeNodeUpdateSchema, ToUpdateSchema, TreeNodeStateSchema, toSetSchema, toUpdateSchema };
67
+ }
68
+ /**
69
+ * Infer the Effect.Schema type for a primitive's set input.
70
+ */
71
+ type ToSetSchema<T extends AnyPrimitive> = Schema.Schema<InferSetInput<T>>;
72
+ /**
73
+ * Infer the Effect.Schema type for a primitive's update input.
74
+ */
75
+ type ToUpdateSchema<T extends AnyPrimitive> = Schema.Schema<InferUpdateInput<T>>;
76
+ /**
77
+ * Type for TreeNode set schema - uses the node's data set input type
78
+ */
79
+ type ToTreeNodeSetSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferSetInput<T["data"]>>;
80
+ /**
81
+ * Type for TreeNode update schema - uses the node's data update input type
82
+ */
83
+ type ToTreeNodeUpdateSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferUpdateInput<T["data"]>>;
84
+ /**
85
+ * Schema for a tree node state (flat storage format).
86
+ */
87
+ declare const TreeNodeStateSchema: Schema.Struct<{
88
+ id: typeof Schema.String;
89
+ type: typeof Schema.String;
90
+ parentId: Schema.NullOr<typeof Schema.String>;
91
+ pos: typeof Schema.String;
92
+ data: typeof Schema.Unknown;
93
+ }>;
94
+ /**
95
+ * Convert a Mimic primitive to an Effect.Schema for set operations.
96
+ *
97
+ * The resulting schema:
98
+ * - For structs: required fields (required=true, no default) are non-optional, others are optional
99
+ * - For arrays: uses the element's set schema
100
+ * - For unions: creates a Schema.Union of variant schemas
101
+ * - For TreeNode: delegates to the node's data struct schema
102
+ * - For Tree: returns Schema.Array of TreeNodeState
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const UserSchema = Primitive.Struct({
107
+ * name: Primitive.String().required(),
108
+ * age: Primitive.Number().default(0),
109
+ * email: Primitive.String(),
110
+ * });
111
+ *
112
+ * const SetSchema = toSetSchema(UserSchema);
113
+ * // { name: string, age?: number, email?: string }
114
+ * ```
115
+ */
116
+ declare function toSetSchema<T extends AnyPrimitive>(primitive: T): ToSetSchema<T>;
117
+ declare function toSetSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeSetSchema<T>;
118
+ /**
119
+ * Convert a Mimic primitive to an Effect.Schema for update operations.
120
+ *
121
+ * The resulting schema:
122
+ * - For structs: all fields are optional (partial updates)
123
+ * - For unions: all variant fields are optional
124
+ * - For TreeNode: delegates to the node's data struct update schema
125
+ * - For simple primitives: same as set schema
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const UserSchema = Primitive.Struct({
130
+ * name: Primitive.String().required(),
131
+ * age: Primitive.Number().default(0),
132
+ * email: Primitive.String(),
133
+ * });
134
+ *
135
+ * const UpdateSchema = toUpdateSchema(UserSchema);
136
+ * // { name?: string, age?: string, email?: string }
137
+ * ```
138
+ */
139
+ declare function toUpdateSchema<T extends AnyPrimitive>(primitive: T): ToUpdateSchema<T>;
140
+ declare function toUpdateSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeUpdateSchema<T>;
64
141
  //#endregion
65
- export { Document_d_exports as Document, Operation_d_exports as Operation, OperationPath_d_exports as OperationPath, Presence_d_exports as Presence, Primitive_d_exports as Primitive, ProxyEnvironment_d_exports as ProxyEnvironment, Transaction_d_exports as Transaction, Transform_d_exports as Transform };
142
+ export { Document_d_exports as Document, EffectSchema_d_exports as EffectSchema, Operation_d_exports as Operation, OperationPath_d_exports as OperationPath, Presence_d_exports as Presence, Primitive_d_exports as Primitive, ProxyEnvironment_d_exports as ProxyEnvironment, Transaction_d_exports as Transaction, Transform_d_exports as Transform };
66
143
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;AAA5C;AAWA;AAeiB,cAfJ,cAAA,SAAuB,KAAA,CAeX;EAAiB,SAAA,IAAA,GAAA,gBAAA;EAEvB,WAAA,CAAA,OAAA,EAAA,MAAA;;;;;AAcqB,UAhBvB,QAgBuB,CAAA,gBAhBE,YAgBF,CAAA,CAAA;EAAxB;EAQiC,SAAA,MAAA,EAtB9B,OAsB8B;EAArB;EAAkC,SAAA,IAAA,EAnB7C,UAmB6C,CAnBxB,OAmBwB,CAAA;EAAI;EAMvC,GAAA,EAAA,EAtBlB,UAsBkB,CAtBG,OAsBH,CAAA,GAAA,SAAA;EAAd;;;AAYb;;;EAEqB,UAAA,EAAA,EA5BL,aA4BK,CA5BmB,OA4BnB,CAAA;EAAoB;AAUzC;;;;;EAGY,WAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EAjCgB,UAiChB,CAjCqC,OAiCrC,CAAA,EAAA,GAjCkD,CAiClD,CAAA,EAjCsD,CAiCtD;EAAT;;;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InferState, c as ProxyEnvironment_d_exports, d as Transaction_d_exports, f as Operation, i as InferSnapshot, m as OperationPath_d_exports, n as AnyPrimitive, p as Operation_d_exports, r as InferProxy, s as Transform_d_exports, t as Primitive_d_exports, u as Transaction } from "./Primitive-CasheIbX.mjs";
2
+ import { _ as OperationPath_d_exports, a as InferSetInput, c as InferUpdateInput, d as ProxyEnvironment_d_exports, g as Operation_d_exports, h as Operation, i as InferProxy, m as Transaction_d_exports, n as AnyTreeNodePrimitive, o as InferSnapshot, p as Transaction, r as AnyPrimitive, s as InferState, t as Primitive_d_exports, u as Transform_d_exports } from "./Primitive-lEhQyGVL.mjs";
3
+ import { Schema } from "effect";
3
4
 
4
5
  //#region src/Document.d.ts
5
6
  declare namespace Document_d_exports {
@@ -61,6 +62,82 @@ interface DocumentOptions<TSchema extends AnyPrimitive> {
61
62
  * Creates a new Document for the given schema.
62
63
  */
63
64
  declare const make: <TSchema extends AnyPrimitive>(schema: TSchema, options?: DocumentOptions<TSchema>) => Document<TSchema>;
65
+ declare namespace EffectSchema_d_exports {
66
+ export { ToSetSchema, ToTreeNodeSetSchema, ToTreeNodeUpdateSchema, ToUpdateSchema, TreeNodeStateSchema, toSetSchema, toUpdateSchema };
67
+ }
68
+ /**
69
+ * Infer the Effect.Schema type for a primitive's set input.
70
+ */
71
+ type ToSetSchema<T extends AnyPrimitive> = Schema.Schema<InferSetInput<T>>;
72
+ /**
73
+ * Infer the Effect.Schema type for a primitive's update input.
74
+ */
75
+ type ToUpdateSchema<T extends AnyPrimitive> = Schema.Schema<InferUpdateInput<T>>;
76
+ /**
77
+ * Type for TreeNode set schema - uses the node's data set input type
78
+ */
79
+ type ToTreeNodeSetSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferSetInput<T["data"]>>;
80
+ /**
81
+ * Type for TreeNode update schema - uses the node's data update input type
82
+ */
83
+ type ToTreeNodeUpdateSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferUpdateInput<T["data"]>>;
84
+ /**
85
+ * Schema for a tree node state (flat storage format).
86
+ */
87
+ declare const TreeNodeStateSchema: Schema.Struct<{
88
+ id: typeof Schema.String;
89
+ type: typeof Schema.String;
90
+ parentId: Schema.NullOr<typeof Schema.String>;
91
+ pos: typeof Schema.String;
92
+ data: typeof Schema.Unknown;
93
+ }>;
94
+ /**
95
+ * Convert a Mimic primitive to an Effect.Schema for set operations.
96
+ *
97
+ * The resulting schema:
98
+ * - For structs: required fields (required=true, no default) are non-optional, others are optional
99
+ * - For arrays: uses the element's set schema
100
+ * - For unions: creates a Schema.Union of variant schemas
101
+ * - For TreeNode: delegates to the node's data struct schema
102
+ * - For Tree: returns Schema.Array of TreeNodeState
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const UserSchema = Primitive.Struct({
107
+ * name: Primitive.String().required(),
108
+ * age: Primitive.Number().default(0),
109
+ * email: Primitive.String(),
110
+ * });
111
+ *
112
+ * const SetSchema = toSetSchema(UserSchema);
113
+ * // { name: string, age?: number, email?: string }
114
+ * ```
115
+ */
116
+ declare function toSetSchema<T extends AnyPrimitive>(primitive: T): ToSetSchema<T>;
117
+ declare function toSetSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeSetSchema<T>;
118
+ /**
119
+ * Convert a Mimic primitive to an Effect.Schema for update operations.
120
+ *
121
+ * The resulting schema:
122
+ * - For structs: all fields are optional (partial updates)
123
+ * - For unions: all variant fields are optional
124
+ * - For TreeNode: delegates to the node's data struct update schema
125
+ * - For simple primitives: same as set schema
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const UserSchema = Primitive.Struct({
130
+ * name: Primitive.String().required(),
131
+ * age: Primitive.Number().default(0),
132
+ * email: Primitive.String(),
133
+ * });
134
+ *
135
+ * const UpdateSchema = toUpdateSchema(UserSchema);
136
+ * // { name?: string, age?: string, email?: string }
137
+ * ```
138
+ */
139
+ declare function toUpdateSchema<T extends AnyPrimitive>(primitive: T): ToUpdateSchema<T>;
140
+ declare function toUpdateSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeUpdateSchema<T>;
64
141
  //#endregion
65
- export { Document_d_exports as Document, Operation_d_exports as Operation, OperationPath_d_exports as OperationPath, Presence_d_exports as Presence, Primitive_d_exports as Primitive, ProxyEnvironment_d_exports as ProxyEnvironment, Transaction_d_exports as Transaction, Transform_d_exports as Transform };
142
+ export { Document_d_exports as Document, EffectSchema_d_exports as EffectSchema, Operation_d_exports as Operation, OperationPath_d_exports as OperationPath, Presence_d_exports as Presence, Primitive_d_exports as Primitive, ProxyEnvironment_d_exports as ProxyEnvironment, Transaction_d_exports as Transaction, Transform_d_exports as Transform };
66
143
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;AAA5C;AAWa,cAAA,cAAA,SAAuB,KAAA,CAAK;EAexB,SAAA,IAAQ,GAAA,gBAAA;EAAiB,WAAA,CAAA,OAAA,EAAA,MAAA;;;;;AAQjC,UARQ,QAQR,CAAA,gBARiC,YAQjC,CAAA,CAAA;EAQ+B;EAAxB,SAAA,MAAA,EAdG,OAcH;EAQiC;EAArB,SAAA,IAAA,EAnBX,UAmBW,CAnBU,OAmBV,CAAA;EAAkC;EAAI,GAAA,EAAA,EAhBzD,UAgByD,CAhBpC,OAgBoC,CAAA,GAAA,SAAA;EAMvC;;;;AAY3B;;EAE0C,UAAA,EAAA,EA5B1B,aA4B0B,CA5BF,OA4BE,CAAA;EAArB;;AAUrB;;;;EAEY,WAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EAhCgB,UAgChB,CAhCqC,OAgCrC,CAAA,EAAA,GAhCkD,CAgClD,CAAA,EAhCsD,CAgCtD;EACA;;;;aA3BC,cAAc;;;;WAKhB;;UAOM,gCAAgC;;qBAE5B,WAAqB;;;;;cAU7B,uBAAwB,sBAC3B,mBACE,gBAA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A,GCZiD,MAAA,CAAO,MDYxD,CCZ+D,aDY/D,CCZ6E,CDY7E,CAAA,MAAA,CAAA,CAAA,CAAA;;;;AAWD,KClBJ,sBDkBI,CAAA,UClB6B,oBDkB7B,CAAA,GClBqD,MAAA,CAAO,MDkB5D,CClBmE,gBDkBnE,CClBoF,CDkBpF,CAAA,MAAA,CAAA,CAAA,CAAA;;;;AAQkD,cCjBrD,mBDiBqD,ECjBlC,MAAA,CAAA,MDiBkC,CAAA;EAMvC,EAAA,EAAA,oBAAA;EAAd,IAAA,EAAA,oBAAA;EAKF,QAAA,eAAA,CAAA,oBAAA,CAAA;EAAuB,GAAA,EAAA,oBAAA;EAOjB,IAAA,EAAA,qBAAe;CAAiB,CAAA;;;;AAYjD;;;;;;;;;;;;;;;;;;;iBCyPgB,sBAAsB,yBAAyB,IAAI,YAAY;AAhUnE,iBAiUI,WAjUO,CAAA,UAiUe,oBAjUf,CAAA,CAAA,SAAA,EAiUgD,CAjUhD,CAAA,EAiUoD,mBAjUpD,CAiUwE,CAjUxE,CAAA;;;;;;AAKvB;;;;;;AAKA;;;;;;AAKA;;;;AAAqE,iBA4UrD,cA5U4D,CAAA,UA4UnC,YA5UmC,CAAA,CAAA,SAAA,EA4UV,CA5UU,CAAA,EA4UN,cA5UM,CA4US,CA5UT,CAAA;AAAM,iBA6UlE,cA7UkE,CAAA,UA6UzC,oBA7UyC,CAAA,CAAA,SAAA,EA6UR,CA7UQ,CAAA,EA6UJ,sBA7UI,CA6UmB,CA7UnB,CAAA"}
package/dist/index.mjs CHANGED
@@ -2351,5 +2351,176 @@ var Primitive_exports = /* @__PURE__ */ __export({
2351
2351
  var Transform_exports = {};
2352
2352
 
2353
2353
  //#endregion
2354
- export { Document_exports as Document, Operation_exports as Operation, OperationPath_exports as OperationPath, Presence_exports as Presence, Primitive_exports as Primitive, ProxyEnvironment_exports as ProxyEnvironment, Transaction_exports as Transaction, Transform_exports as Transform };
2354
+ //#region src/EffectSchema.ts
2355
+ /**
2356
+ * Effect.Schema utilities for converting Mimic primitives to Effect.Schema schemas.
2357
+ *
2358
+ * @since 0.0.1
2359
+ */
2360
+ var EffectSchema_exports = /* @__PURE__ */ __export({
2361
+ TreeNodeStateSchema: () => TreeNodeStateSchema,
2362
+ toSetSchema: () => toSetSchema,
2363
+ toUpdateSchema: () => toUpdateSchema
2364
+ });
2365
+ /**
2366
+ * Schema for a tree node state (flat storage format).
2367
+ */
2368
+ const TreeNodeStateSchema = Schema.Struct({
2369
+ id: Schema.String,
2370
+ type: Schema.String,
2371
+ parentId: Schema.NullOr(Schema.String),
2372
+ pos: Schema.String,
2373
+ data: Schema.Unknown
2374
+ });
2375
+ /**
2376
+ * Check if a field is required for set operations.
2377
+ * A field is required if: TRequired is true AND THasDefault is false.
2378
+ *
2379
+ * We determine this by checking the primitive's schema properties.
2380
+ */
2381
+ function isRequiredForSet(primitive) {
2382
+ const schema = primitive._schema;
2383
+ if (!schema) return false;
2384
+ return schema.required === true && schema.defaultValue === void 0;
2385
+ }
2386
+ /**
2387
+ * Get the base Effect.Schema for a primitive type (without optional wrapper).
2388
+ */
2389
+ function getBaseSchema(primitive) {
2390
+ switch (primitive._tag) {
2391
+ case "StringPrimitive": return Schema.String;
2392
+ case "NumberPrimitive": return Schema.Number;
2393
+ case "BooleanPrimitive": return Schema.Boolean;
2394
+ case "LiteralPrimitive": {
2395
+ var _schema$literal, _schema;
2396
+ const literalPrimitive = primitive;
2397
+ const literalValue = (_schema$literal = (_schema = literalPrimitive._schema) === null || _schema === void 0 ? void 0 : _schema.literal) !== null && _schema$literal !== void 0 ? _schema$literal : literalPrimitive.literal;
2398
+ return Schema.Literal(literalValue);
2399
+ }
2400
+ case "StructPrimitive": return buildStructSetSchema(primitive);
2401
+ case "ArrayPrimitive": {
2402
+ const elementSchema = buildElementSetSchema(primitive.element);
2403
+ return Schema.Array(elementSchema);
2404
+ }
2405
+ case "UnionPrimitive": return buildUnionSetSchema(primitive);
2406
+ case "EitherPrimitive": return buildEitherSchema(primitive);
2407
+ case "LazyPrimitive": {
2408
+ var _resolve, _resolve2;
2409
+ const lazyPrimitive = primitive;
2410
+ return getBaseSchema((_resolve = (_resolve2 = lazyPrimitive._resolve) === null || _resolve2 === void 0 ? void 0 : _resolve2.call(lazyPrimitive)) !== null && _resolve !== void 0 ? _resolve : lazyPrimitive._thunk());
2411
+ }
2412
+ case "TreeNodePrimitive": return buildStructSetSchema(primitive.data);
2413
+ case "TreePrimitive": return Schema.Array(TreeNodeStateSchema);
2414
+ default: return Schema.Unknown;
2415
+ }
2416
+ }
2417
+ /**
2418
+ * Build the set schema for a struct primitive.
2419
+ * Required fields (required=true, no default) are non-optional.
2420
+ * Other fields are wrapped with Schema.optional.
2421
+ */
2422
+ function buildStructSetSchema(structPrimitive) {
2423
+ const fields = structPrimitive.fields;
2424
+ const schemaFields = {};
2425
+ for (const key in fields) {
2426
+ const fieldPrimitive = fields[key];
2427
+ const baseSchema = getBaseSchema(fieldPrimitive);
2428
+ if (isRequiredForSet(fieldPrimitive)) schemaFields[key] = baseSchema;
2429
+ else schemaFields[key] = Schema.optional(baseSchema);
2430
+ }
2431
+ return Schema.Struct(schemaFields);
2432
+ }
2433
+ /**
2434
+ * Build the update schema for a struct primitive.
2435
+ * All fields are optional for partial updates.
2436
+ */
2437
+ function buildStructUpdateSchema(structPrimitive) {
2438
+ const fields = structPrimitive.fields;
2439
+ const schemaFields = {};
2440
+ for (const key in fields) {
2441
+ const fieldPrimitive = fields[key];
2442
+ let fieldSchema;
2443
+ if (fieldPrimitive._tag === "StructPrimitive") fieldSchema = buildStructUpdateSchema(fieldPrimitive);
2444
+ else fieldSchema = getBaseSchema(fieldPrimitive);
2445
+ schemaFields[key] = Schema.optional(fieldSchema);
2446
+ }
2447
+ return Schema.Struct(schemaFields);
2448
+ }
2449
+ /**
2450
+ * Build the set schema for an array element.
2451
+ * For struct elements, uses the struct's set input schema.
2452
+ */
2453
+ function buildElementSetSchema(elementPrimitive) {
2454
+ if (elementPrimitive._tag === "StructPrimitive") return buildStructSetSchema(elementPrimitive);
2455
+ return getBaseSchema(elementPrimitive);
2456
+ }
2457
+ /**
2458
+ * Build the set schema for a union primitive.
2459
+ * Creates a Schema.Union of all variant schemas.
2460
+ */
2461
+ function buildUnionSetSchema(unionPrimitive) {
2462
+ const variants = unionPrimitive.variants;
2463
+ const variantSchemas = [];
2464
+ for (const key in variants) {
2465
+ const variantPrimitive = variants[key];
2466
+ variantSchemas.push(buildStructSetSchema(variantPrimitive));
2467
+ }
2468
+ if (variantSchemas.length === 0) return Schema.Unknown;
2469
+ if (variantSchemas.length === 1) return variantSchemas[0];
2470
+ return Schema.Union(...variantSchemas);
2471
+ }
2472
+ /**
2473
+ * Build the schema for an either primitive.
2474
+ * Creates a Schema.Union of all scalar variant types.
2475
+ */
2476
+ function buildEitherSchema(eitherPrimitive) {
2477
+ const variants = eitherPrimitive.variants;
2478
+ const variantSchemas = [];
2479
+ for (const variant of variants) variantSchemas.push(getBaseSchema(variant));
2480
+ if (variantSchemas.length === 0) return Schema.Unknown;
2481
+ if (variantSchemas.length === 1) return variantSchemas[0];
2482
+ return Schema.Union(...variantSchemas);
2483
+ }
2484
+ /**
2485
+ * Build the update schema for a union primitive.
2486
+ * Creates a Schema.Union of all variant update schemas.
2487
+ */
2488
+ function buildUnionUpdateSchema(unionPrimitive) {
2489
+ const variants = unionPrimitive.variants;
2490
+ const variantSchemas = [];
2491
+ for (const key in variants) {
2492
+ const variantPrimitive = variants[key];
2493
+ variantSchemas.push(buildStructUpdateSchema(variantPrimitive));
2494
+ }
2495
+ if (variantSchemas.length === 0) return Schema.Unknown;
2496
+ if (variantSchemas.length === 1) return variantSchemas[0];
2497
+ return Schema.Union(...variantSchemas);
2498
+ }
2499
+ /**
2500
+ * Get the update schema for a primitive.
2501
+ * For structs, all fields are optional (partial updates).
2502
+ * For simple primitives, same as set schema.
2503
+ */
2504
+ function getUpdateSchema(primitive) {
2505
+ switch (primitive._tag) {
2506
+ case "StructPrimitive": return buildStructUpdateSchema(primitive);
2507
+ case "UnionPrimitive": return buildUnionUpdateSchema(primitive);
2508
+ case "TreeNodePrimitive": return buildStructUpdateSchema(primitive.data);
2509
+ case "LazyPrimitive": {
2510
+ var _resolve3, _resolve4;
2511
+ const lazyPrimitive = primitive;
2512
+ return getUpdateSchema((_resolve3 = (_resolve4 = lazyPrimitive._resolve) === null || _resolve4 === void 0 ? void 0 : _resolve4.call(lazyPrimitive)) !== null && _resolve3 !== void 0 ? _resolve3 : lazyPrimitive._thunk());
2513
+ }
2514
+ default: return getBaseSchema(primitive);
2515
+ }
2516
+ }
2517
+ function toSetSchema(primitive) {
2518
+ return getBaseSchema(primitive);
2519
+ }
2520
+ function toUpdateSchema(primitive) {
2521
+ return getUpdateSchema(primitive);
2522
+ }
2523
+
2524
+ //#endregion
2525
+ export { Document_exports as Document, EffectSchema_exports as EffectSchema, Operation_exports as Operation, OperationPath_exports as OperationPath, Presence_exports as Presence, Primitive_exports as Primitive, ProxyEnvironment_exports as ProxyEnvironment, Transaction_exports as Transaction, Transform_exports as Transform };
2355
2526
  //# sourceMappingURL=index.mjs.map