@voidhash/mimic 0.0.1-alpha.4 → 0.0.1-alpha.6
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/.turbo/turbo-build.log +13 -13
- package/dist/index.cjs +35 -9
- package/dist/index.d.cts +45 -16
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +45 -16
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +35 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/client/ClientDocument.ts +1 -1
- package/src/client/errors.ts +10 -10
- package/src/primitives/Boolean.ts +1 -1
- package/src/primitives/Literal.ts +1 -1
- package/src/primitives/Number.ts +1 -1
- package/src/primitives/String.ts +1 -1
- package/src/primitives/Struct.ts +2 -2
- package/src/primitives/Tree.ts +2 -2
- package/src/primitives/TreeNode.ts +69 -28
- package/src/primitives/Union.ts +1 -1
- package/src/server/errors.ts +6 -6
package/dist/index.mjs
CHANGED
|
@@ -309,7 +309,7 @@ var StringPrimitive = class StringPrimitive {
|
|
|
309
309
|
}
|
|
310
310
|
};
|
|
311
311
|
},
|
|
312
|
-
applyOperation: (
|
|
312
|
+
applyOperation: (_state, operation) => {
|
|
313
313
|
if (!isCompatibleOperation(operation, this._opDefinitions)) throw new ValidationError(`StringPrimitive cannot apply operation of kind: ${operation.kind}`);
|
|
314
314
|
const payload = operation.payload;
|
|
315
315
|
if (typeof payload !== "string") throw new ValidationError(`StringPrimitive.set requires a string payload, got: ${typeof payload}`);
|
|
@@ -431,7 +431,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
431
431
|
return buildSnapshot();
|
|
432
432
|
}
|
|
433
433
|
}, {
|
|
434
|
-
get: (target, prop,
|
|
434
|
+
get: (target, prop, _receiver) => {
|
|
435
435
|
if (prop === "get") return target.get;
|
|
436
436
|
if (prop === "set") return target.set;
|
|
437
437
|
if (prop === "toSnapshot") return target.toSnapshot;
|
|
@@ -442,7 +442,7 @@ var StructPrimitive = class StructPrimitive {
|
|
|
442
442
|
return fieldPrimitive._internal.createProxy(env, fieldPath);
|
|
443
443
|
}
|
|
444
444
|
},
|
|
445
|
-
has: (
|
|
445
|
+
has: (_target, prop) => {
|
|
446
446
|
if (prop === "get" || prop === "set" || prop === "toSnapshot") return true;
|
|
447
447
|
if (typeof prop === "string" && prop in fields) return true;
|
|
448
448
|
return false;
|
|
@@ -594,7 +594,7 @@ var BooleanPrimitive = class BooleanPrimitive {
|
|
|
594
594
|
}
|
|
595
595
|
};
|
|
596
596
|
},
|
|
597
|
-
applyOperation: (
|
|
597
|
+
applyOperation: (_state, operation) => {
|
|
598
598
|
if (operation.kind !== "boolean.set") throw new ValidationError(`BooleanPrimitive cannot apply operation of kind: ${operation.kind}`);
|
|
599
599
|
const payload = operation.payload;
|
|
600
600
|
if (typeof payload !== "boolean") throw new ValidationError(`BooleanPrimitive.set requires a boolean payload, got: ${typeof payload}`);
|
|
@@ -671,7 +671,7 @@ var NumberPrimitive = class NumberPrimitive {
|
|
|
671
671
|
}
|
|
672
672
|
};
|
|
673
673
|
},
|
|
674
|
-
applyOperation: (
|
|
674
|
+
applyOperation: (_state, operation) => {
|
|
675
675
|
if (operation.kind !== "number.set") throw new ValidationError(`NumberPrimitive cannot apply operation of kind: ${operation.kind}`);
|
|
676
676
|
const payload = operation.payload;
|
|
677
677
|
if (typeof payload !== "number") throw new ValidationError(`NumberPrimitive.set requires a number payload, got: ${typeof payload}`);
|
|
@@ -768,7 +768,7 @@ var LiteralPrimitive = class LiteralPrimitive {
|
|
|
768
768
|
}
|
|
769
769
|
};
|
|
770
770
|
},
|
|
771
|
-
applyOperation: (
|
|
771
|
+
applyOperation: (_state, operation) => {
|
|
772
772
|
if (operation.kind !== "literal.set") throw new ValidationError(`LiteralPrimitive cannot apply operation of kind: ${operation.kind}`);
|
|
773
773
|
const payload = operation.payload;
|
|
774
774
|
if (payload !== this._schema.literal) throw new ValidationError(`LiteralPrimitive.set requires the exact literal value "${globalThis.String(this._schema.literal)}", got: "${globalThis.String(payload)}"`);
|
|
@@ -1817,6 +1817,32 @@ function Either(...variants) {
|
|
|
1817
1817
|
//#endregion
|
|
1818
1818
|
//#region src/primitives/TreeNode.ts
|
|
1819
1819
|
/**
|
|
1820
|
+
* Symbol used to identify the Self placeholder
|
|
1821
|
+
*/
|
|
1822
|
+
const TreeNodeSelfSymbol = Symbol.for("TreeNode.Self");
|
|
1823
|
+
/**
|
|
1824
|
+
* Special placeholder for self-referential tree nodes.
|
|
1825
|
+
* Use this in the children array when a node type can contain itself.
|
|
1826
|
+
*
|
|
1827
|
+
* @example
|
|
1828
|
+
* ```typescript
|
|
1829
|
+
* const FolderNode = TreeNode("folder", {
|
|
1830
|
+
* data: Struct({ name: String() }),
|
|
1831
|
+
* children: [TreeNodeSelf], // Folder can contain other folders
|
|
1832
|
+
* });
|
|
1833
|
+
* ```
|
|
1834
|
+
*/
|
|
1835
|
+
const TreeNodeSelf = {
|
|
1836
|
+
_tag: "TreeNodeSelf",
|
|
1837
|
+
_symbol: TreeNodeSelfSymbol
|
|
1838
|
+
};
|
|
1839
|
+
/**
|
|
1840
|
+
* Check if a value is the Self placeholder
|
|
1841
|
+
*/
|
|
1842
|
+
const isSelf = (value) => {
|
|
1843
|
+
return typeof value === "object" && value !== null && "_symbol" in value && value._symbol === TreeNodeSelfSymbol;
|
|
1844
|
+
};
|
|
1845
|
+
/**
|
|
1820
1846
|
* TreeNodePrimitive - defines a node type with its data schema and allowed children
|
|
1821
1847
|
*/
|
|
1822
1848
|
var TreeNodePrimitive = class {
|
|
@@ -1841,10 +1867,9 @@ var TreeNodePrimitive = class {
|
|
|
1841
1867
|
get data() {
|
|
1842
1868
|
return this._data;
|
|
1843
1869
|
}
|
|
1844
|
-
/** Get resolved children (resolves lazy thunk if needed) */
|
|
1870
|
+
/** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */
|
|
1845
1871
|
get children() {
|
|
1846
|
-
if (this._resolvedChildren === void 0)
|
|
1847
|
-
else this._resolvedChildren = this._children;
|
|
1872
|
+
if (this._resolvedChildren === void 0) this._resolvedChildren = (typeof this._children === "function" ? this._children() : this._children).map((child) => isSelf(child) ? this : child);
|
|
1848
1873
|
return this._resolvedChildren;
|
|
1849
1874
|
}
|
|
1850
1875
|
/** Check if a child type is allowed */
|
|
@@ -2420,6 +2445,7 @@ var Primitive_exports = /* @__PURE__ */ __export({
|
|
|
2420
2445
|
Tree: () => Tree,
|
|
2421
2446
|
TreeNode: () => TreeNode,
|
|
2422
2447
|
TreeNodePrimitive: () => TreeNodePrimitive,
|
|
2448
|
+
TreeNodeSelf: () => TreeNodeSelf,
|
|
2423
2449
|
TreePrimitive: () => TreePrimitive,
|
|
2424
2450
|
Union: () => Union,
|
|
2425
2451
|
UnionPrimitive: () => UnionPrimitive,
|