@voidhash/mimic 0.0.2 → 0.0.3

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.
Files changed (273) hide show
  1. package/.turbo/turbo-build.log +257 -42
  2. package/dist/Document.cjs +152 -0
  3. package/dist/Document.d.cts +67 -0
  4. package/dist/Document.d.cts.map +1 -0
  5. package/dist/Document.d.mts +68 -0
  6. package/dist/Document.d.mts.map +1 -0
  7. package/dist/Document.mjs +147 -0
  8. package/dist/Document.mjs.map +1 -0
  9. package/dist/EffectSchema.cjs +180 -0
  10. package/dist/EffectSchema.d.cts +84 -0
  11. package/dist/EffectSchema.d.cts.map +1 -0
  12. package/dist/EffectSchema.d.mts +84 -0
  13. package/dist/EffectSchema.d.mts.map +1 -0
  14. package/dist/EffectSchema.mjs +176 -0
  15. package/dist/EffectSchema.mjs.map +1 -0
  16. package/dist/FractionalIndex.cjs +365 -0
  17. package/dist/FractionalIndex.mjs +364 -0
  18. package/dist/FractionalIndex.mjs.map +1 -0
  19. package/dist/Operation.cjs +53 -0
  20. package/dist/Operation.d.cts +39 -0
  21. package/dist/Operation.d.cts.map +1 -0
  22. package/dist/Operation.d.mts +39 -0
  23. package/dist/Operation.d.mts.map +1 -0
  24. package/dist/Operation.mjs +46 -0
  25. package/dist/Operation.mjs.map +1 -0
  26. package/dist/OperationDefinition.cjs +13 -0
  27. package/dist/OperationDefinition.d.cts +12 -0
  28. package/dist/OperationDefinition.d.cts.map +1 -0
  29. package/dist/OperationDefinition.d.mts +12 -0
  30. package/dist/OperationDefinition.d.mts.map +1 -0
  31. package/dist/OperationDefinition.mjs +13 -0
  32. package/dist/OperationDefinition.mjs.map +1 -0
  33. package/dist/OperationPath.cjs +148 -0
  34. package/dist/OperationPath.d.cts +60 -0
  35. package/dist/OperationPath.d.cts.map +1 -0
  36. package/dist/OperationPath.d.mts +60 -0
  37. package/dist/OperationPath.d.mts.map +1 -0
  38. package/dist/OperationPath.mjs +138 -0
  39. package/dist/OperationPath.mjs.map +1 -0
  40. package/dist/{Presence-gWrmGBeu.cjs → Presence.cjs} +4 -39
  41. package/dist/{Presence-N8u7Eppr.d.mts → Presence.d.cts} +2 -2
  42. package/dist/Presence.d.cts.map +1 -0
  43. package/dist/{Presence-DKKP4v5X.d.cts → Presence.d.mts} +2 -2
  44. package/dist/Presence.d.mts.map +1 -0
  45. package/dist/{Presence-DdMVKcOv.mjs → Presence.mjs} +3 -28
  46. package/dist/Presence.mjs.map +1 -0
  47. package/dist/Primitive.cjs +52 -0
  48. package/dist/Primitive.d.cts +20 -0
  49. package/dist/Primitive.d.cts.map +1 -0
  50. package/dist/Primitive.d.mts +20 -0
  51. package/dist/Primitive.d.mts.map +1 -0
  52. package/dist/Primitive.mjs +48 -0
  53. package/dist/Primitive.mjs.map +1 -0
  54. package/dist/ProxyEnvironment.cjs +34 -0
  55. package/dist/ProxyEnvironment.d.cts +31 -0
  56. package/dist/ProxyEnvironment.d.cts.map +1 -0
  57. package/dist/ProxyEnvironment.d.mts +31 -0
  58. package/dist/ProxyEnvironment.d.mts.map +1 -0
  59. package/dist/ProxyEnvironment.mjs +29 -0
  60. package/dist/ProxyEnvironment.mjs.map +1 -0
  61. package/dist/Transaction.cjs +66 -0
  62. package/dist/Transaction.d.cts +56 -0
  63. package/dist/Transaction.d.cts.map +1 -0
  64. package/dist/Transaction.d.mts +56 -0
  65. package/dist/Transaction.d.mts.map +1 -0
  66. package/dist/Transaction.mjs +58 -0
  67. package/dist/Transaction.mjs.map +1 -0
  68. package/dist/Transform.cjs +11 -0
  69. package/dist/Transform.d.cts +21 -0
  70. package/dist/Transform.d.cts.map +1 -0
  71. package/dist/Transform.d.mts +21 -0
  72. package/dist/Transform.d.mts.map +1 -0
  73. package/dist/Transform.mjs +6 -0
  74. package/dist/Transform.mjs.map +1 -0
  75. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
  76. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
  77. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
  78. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
  79. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
  80. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
  81. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
  82. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
  83. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
  84. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
  85. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  86. package/dist/{chunk-CLMFDpHK.mjs → _virtual/rolldown_runtime.mjs} +1 -1
  87. package/dist/client/ClientDocument.cjs +590 -0
  88. package/dist/client/ClientDocument.d.cts +161 -0
  89. package/dist/client/ClientDocument.d.cts.map +1 -0
  90. package/dist/client/ClientDocument.d.mts +162 -0
  91. package/dist/client/ClientDocument.d.mts.map +1 -0
  92. package/dist/client/ClientDocument.mjs +586 -0
  93. package/dist/client/ClientDocument.mjs.map +1 -0
  94. package/dist/client/Rebase.cjs +204 -0
  95. package/dist/client/Rebase.d.cts +87 -0
  96. package/dist/client/Rebase.d.cts.map +1 -0
  97. package/dist/client/Rebase.d.mts +88 -0
  98. package/dist/client/Rebase.d.mts.map +1 -0
  99. package/dist/client/Rebase.mjs +198 -0
  100. package/dist/client/Rebase.mjs.map +1 -0
  101. package/dist/client/StateMonitor.cjs +133 -0
  102. package/dist/client/StateMonitor.d.cts +122 -0
  103. package/dist/client/StateMonitor.d.cts.map +1 -0
  104. package/dist/client/StateMonitor.d.mts +122 -0
  105. package/dist/client/StateMonitor.d.mts.map +1 -0
  106. package/dist/client/StateMonitor.mjs +129 -0
  107. package/dist/client/StateMonitor.mjs.map +1 -0
  108. package/dist/client/Transport.cjs +11 -0
  109. package/dist/client/Transport.d.cts +237 -0
  110. package/dist/client/Transport.d.cts.map +1 -0
  111. package/dist/client/Transport.d.mts +237 -0
  112. package/dist/client/Transport.d.mts.map +1 -0
  113. package/dist/client/Transport.mjs +6 -0
  114. package/dist/client/Transport.mjs.map +1 -0
  115. package/dist/client/WebSocketTransport.cjs +396 -0
  116. package/dist/client/WebSocketTransport.d.cts +29 -0
  117. package/dist/client/WebSocketTransport.d.cts.map +1 -0
  118. package/dist/client/WebSocketTransport.d.mts +29 -0
  119. package/dist/client/WebSocketTransport.d.mts.map +1 -0
  120. package/dist/client/WebSocketTransport.mjs +392 -0
  121. package/dist/client/WebSocketTransport.mjs.map +1 -0
  122. package/dist/client/errors.cjs +135 -0
  123. package/dist/client/errors.d.cts +87 -0
  124. package/dist/client/errors.d.cts.map +1 -0
  125. package/dist/client/errors.d.mts +87 -0
  126. package/dist/client/errors.d.mts.map +1 -0
  127. package/dist/client/errors.mjs +127 -0
  128. package/dist/client/errors.mjs.map +1 -0
  129. package/dist/client/index.cjs +22 -1424
  130. package/dist/client/index.d.cts +8 -692
  131. package/dist/client/index.d.mts +8 -692
  132. package/dist/client/index.mjs +9 -1413
  133. package/dist/index.cjs +20 -2973
  134. package/dist/index.d.cts +12 -419
  135. package/dist/index.d.mts +12 -419
  136. package/dist/index.mjs +13 -2968
  137. package/dist/primitives/Array.cjs +302 -0
  138. package/dist/primitives/Array.d.cts +95 -0
  139. package/dist/primitives/Array.d.cts.map +1 -0
  140. package/dist/primitives/Array.d.mts +95 -0
  141. package/dist/primitives/Array.d.mts.map +1 -0
  142. package/dist/primitives/Array.mjs +301 -0
  143. package/dist/primitives/Array.mjs.map +1 -0
  144. package/dist/primitives/Boolean.cjs +95 -0
  145. package/dist/primitives/Boolean.d.cts +44 -0
  146. package/dist/primitives/Boolean.d.cts.map +1 -0
  147. package/dist/primitives/Boolean.d.mts +44 -0
  148. package/dist/primitives/Boolean.d.mts.map +1 -0
  149. package/dist/primitives/Boolean.mjs +94 -0
  150. package/dist/primitives/Boolean.mjs.map +1 -0
  151. package/dist/primitives/Either.cjs +200 -0
  152. package/dist/primitives/Either.d.cts +113 -0
  153. package/dist/primitives/Either.d.cts.map +1 -0
  154. package/dist/primitives/Either.d.mts +113 -0
  155. package/dist/primitives/Either.d.mts.map +1 -0
  156. package/dist/primitives/Either.mjs +199 -0
  157. package/dist/primitives/Either.mjs.map +1 -0
  158. package/dist/primitives/Lazy.cjs +46 -0
  159. package/dist/primitives/Lazy.d.cts +46 -0
  160. package/dist/primitives/Lazy.d.cts.map +1 -0
  161. package/dist/primitives/Lazy.d.mts +46 -0
  162. package/dist/primitives/Lazy.d.mts.map +1 -0
  163. package/dist/primitives/Lazy.mjs +46 -0
  164. package/dist/primitives/Lazy.mjs.map +1 -0
  165. package/dist/primitives/Literal.cjs +91 -0
  166. package/dist/primitives/Literal.d.cts +46 -0
  167. package/dist/primitives/Literal.d.cts.map +1 -0
  168. package/dist/primitives/Literal.d.mts +46 -0
  169. package/dist/primitives/Literal.d.mts.map +1 -0
  170. package/dist/primitives/Literal.mjs +90 -0
  171. package/dist/primitives/Literal.mjs.map +1 -0
  172. package/dist/primitives/Number.cjs +115 -0
  173. package/dist/primitives/Number.d.cts +54 -0
  174. package/dist/primitives/Number.d.cts.map +1 -0
  175. package/dist/primitives/Number.d.mts +54 -0
  176. package/dist/primitives/Number.d.mts.map +1 -0
  177. package/dist/primitives/Number.mjs +114 -0
  178. package/dist/primitives/Number.mjs.map +1 -0
  179. package/dist/primitives/String.cjs +127 -0
  180. package/dist/primitives/String.d.cts +56 -0
  181. package/dist/primitives/String.d.cts.map +1 -0
  182. package/dist/primitives/String.d.mts +56 -0
  183. package/dist/primitives/String.d.mts.map +1 -0
  184. package/dist/primitives/String.mjs +126 -0
  185. package/dist/primitives/String.mjs.map +1 -0
  186. package/dist/primitives/Struct.cjs +207 -0
  187. package/dist/primitives/Struct.d.cts +96 -0
  188. package/dist/primitives/Struct.d.cts.map +1 -0
  189. package/dist/primitives/Struct.d.mts +97 -0
  190. package/dist/primitives/Struct.d.mts.map +1 -0
  191. package/dist/primitives/Struct.mjs +206 -0
  192. package/dist/primitives/Struct.mjs.map +1 -0
  193. package/dist/primitives/Tree.cjs +575 -0
  194. package/dist/primitives/Tree.d.cts +185 -0
  195. package/dist/primitives/Tree.d.cts.map +1 -0
  196. package/dist/primitives/Tree.d.mts +185 -0
  197. package/dist/primitives/Tree.d.mts.map +1 -0
  198. package/dist/primitives/Tree.mjs +574 -0
  199. package/dist/primitives/Tree.mjs.map +1 -0
  200. package/dist/primitives/TreeNode.cjs +73 -0
  201. package/dist/primitives/TreeNode.d.cts +92 -0
  202. package/dist/primitives/TreeNode.d.cts.map +1 -0
  203. package/dist/primitives/TreeNode.d.mts +93 -0
  204. package/dist/primitives/TreeNode.d.mts.map +1 -0
  205. package/dist/primitives/TreeNode.mjs +72 -0
  206. package/dist/primitives/TreeNode.mjs.map +1 -0
  207. package/dist/primitives/Union.cjs +170 -0
  208. package/dist/primitives/Union.d.cts +81 -0
  209. package/dist/primitives/Union.d.cts.map +1 -0
  210. package/dist/primitives/Union.d.mts +81 -0
  211. package/dist/primitives/Union.d.mts.map +1 -0
  212. package/dist/primitives/Union.mjs +169 -0
  213. package/dist/primitives/Union.mjs.map +1 -0
  214. package/dist/primitives/shared.cjs +60 -0
  215. package/dist/primitives/shared.d.cts +147 -0
  216. package/dist/primitives/shared.d.cts.map +1 -0
  217. package/dist/primitives/shared.d.mts +147 -0
  218. package/dist/primitives/shared.d.mts.map +1 -0
  219. package/dist/primitives/shared.mjs +58 -0
  220. package/dist/primitives/shared.mjs.map +1 -0
  221. package/dist/server/ServerDocument.cjs +110 -0
  222. package/dist/server/ServerDocument.d.cts +98 -0
  223. package/dist/server/ServerDocument.d.cts.map +1 -0
  224. package/dist/server/ServerDocument.d.mts +99 -0
  225. package/dist/server/ServerDocument.d.mts.map +1 -0
  226. package/dist/server/ServerDocument.mjs +106 -0
  227. package/dist/server/ServerDocument.mjs.map +1 -0
  228. package/dist/server/errors.cjs +85 -0
  229. package/dist/server/errors.d.cts +53 -0
  230. package/dist/server/errors.d.cts.map +1 -0
  231. package/dist/server/errors.d.mts +53 -0
  232. package/dist/server/errors.d.mts.map +1 -0
  233. package/dist/server/errors.mjs +81 -0
  234. package/dist/server/errors.mjs.map +1 -0
  235. package/dist/server/index.cjs +9 -185
  236. package/dist/server/index.d.cts +3 -148
  237. package/dist/server/index.d.mts +3 -148
  238. package/dist/server/index.mjs +3 -181
  239. package/dist/types/index.cjs +16 -0
  240. package/dist/types/index.d.cts +16 -0
  241. package/dist/types/index.d.cts.map +1 -0
  242. package/dist/types/index.d.mts +16 -0
  243. package/dist/types/index.d.mts.map +1 -0
  244. package/dist/types/index.mjs +12 -0
  245. package/dist/types/index.mjs.map +1 -0
  246. package/dist/utils/tree-helpers.cjs +443 -0
  247. package/dist/utils/tree-helpers.d.cts +280 -0
  248. package/dist/utils/tree-helpers.d.cts.map +1 -0
  249. package/dist/utils/tree-helpers.d.mts +280 -0
  250. package/dist/utils/tree-helpers.d.mts.map +1 -0
  251. package/dist/utils/tree-helpers.mjs +439 -0
  252. package/dist/utils/tree-helpers.mjs.map +1 -0
  253. package/package.json +2 -2
  254. package/tsdown.config.ts +1 -1
  255. package/dist/Document-ChuFrTk1.cjs +0 -571
  256. package/dist/Document-CwiAFTIq.mjs +0 -438
  257. package/dist/Document-CwiAFTIq.mjs.map +0 -1
  258. package/dist/Presence-DKKP4v5X.d.cts.map +0 -1
  259. package/dist/Presence-DdMVKcOv.mjs.map +0 -1
  260. package/dist/Presence-N8u7Eppr.d.mts.map +0 -1
  261. package/dist/Primitive-DqQFc3Gu.d.mts +0 -1180
  262. package/dist/Primitive-DqQFc3Gu.d.mts.map +0 -1
  263. package/dist/Primitive-awpEjnKL.d.cts +0 -1180
  264. package/dist/Primitive-awpEjnKL.d.cts.map +0 -1
  265. package/dist/client/index.d.cts.map +0 -1
  266. package/dist/client/index.d.mts.map +0 -1
  267. package/dist/client/index.mjs.map +0 -1
  268. package/dist/index.d.cts.map +0 -1
  269. package/dist/index.d.mts.map +0 -1
  270. package/dist/index.mjs.map +0 -1
  271. package/dist/server/index.d.cts.map +0 -1
  272. package/dist/server/index.d.mts.map +0 -1
  273. package/dist/server/index.mjs.map +0 -1
@@ -0,0 +1,68 @@
1
+ import { Operation } from "./Operation.mjs";
2
+ import { Transaction } from "./Transaction.mjs";
3
+ import { AnyPrimitive, InferProxy, InferSnapshot, InferState } from "./primitives/shared.mjs";
4
+ import "./Primitive.mjs";
5
+
6
+ //#region src/Document.d.ts
7
+ declare namespace Document_d_exports {
8
+ export { Document, DocumentOptions, NestedTransactionError, OperationError, make };
9
+ }
10
+ /**
11
+ * Error thrown when attempting to start a nested transaction.
12
+ */
13
+ declare class NestedTransactionError extends Error {
14
+ readonly _tag = "NestedTransactionError";
15
+ constructor();
16
+ }
17
+ /**
18
+ * Error thrown when an operation fails to apply.
19
+ */
20
+ declare class OperationError extends Error {
21
+ readonly _tag = "OperationError";
22
+ constructor(message: string);
23
+ }
24
+ /**
25
+ * A Document manages state for a primitive-based schema with transaction support.
26
+ */
27
+ interface Document<TSchema extends AnyPrimitive> {
28
+ /** The schema defining this document's structure */
29
+ readonly schema: TSchema;
30
+ /** Root proxy for accessing and modifying document data */
31
+ readonly root: InferProxy<TSchema>;
32
+ /** Returns the current document state */
33
+ get(): InferState<TSchema> | undefined;
34
+ /**
35
+ * Returns a readonly snapshot of the entire document state for rendering.
36
+ * The snapshot is a type-safe, readonly structure where:
37
+ * - Required fields and fields with defaults are guaranteed to be defined
38
+ * - Optional fields may be undefined
39
+ */
40
+ toSnapshot(): InferSnapshot<TSchema>;
41
+ /**
42
+ * Runs a function within a transaction.
43
+ * All operations are collected and applied atomically.
44
+ * If the function throws, all changes are rolled back.
45
+ * @returns The return value of the function
46
+ */
47
+ transaction<R>(fn: (root: InferProxy<TSchema>) => R): R;
48
+ /**
49
+ * Applies external operations (e.g., from server/peers) to the document.
50
+ * These operations are NOT added to pending operations.
51
+ */
52
+ apply(ops: ReadonlyArray<Operation<any, any, any>>): void;
53
+ /**
54
+ * Returns pending local operations as a Transaction and clears the buffer.
55
+ */
56
+ flush(): Transaction;
57
+ }
58
+ interface DocumentOptions<TSchema extends AnyPrimitive> {
59
+ /** Initial state for the document */
60
+ readonly initial?: InferState<TSchema>;
61
+ }
62
+ /**
63
+ * Creates a new Document for the given schema.
64
+ */
65
+ declare const make: <TSchema extends AnyPrimitive>(schema: TSchema, options?: DocumentOptions<TSchema>) => Document<TSchema>;
66
+ //#endregion
67
+ export { Document_d_exports };
68
+ //# sourceMappingURL=Document.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Document.d.mts","names":[],"sources":["../src/Document.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;cAaa,sBAAA,SAA+B,KAAA;;;;;;;cAW/B,cAAA,SAAuB,KAAA;EAXvB,SAAA,IAAA,GAAA,gBAAuB;EAWvB,WAAA,CAAA,OAAe,EAAA,MAAA;AAe5B;;;;AAKiB,UALA,QAKA,CAAA,gBALyB,YAKzB,CAAA,CAAA;EAGa;EAArB,SAAA,MAAA,EANU,OAMV;EAQ+B;EAAxB,SAAA,IAAA,EAXC,UAWD,CAXsB,OAWtB,CAAA;EAQiC;EAArB,GAAA,EAAA,EAhBnB,UAgBmB,CAhBE,OAgBF,CAAA,GAAA,SAAA;EAAkC;;;;;;EAkB7C,UAAA,EAAA,EA1BD,aA0BgB,CA1BQ,OA0BR,CAAA;EAAiB;;;;AAYjD;;EACU,WAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EA/BkB,UA+BlB,CA/BuC,OA+BvC,CAAA,EAAA,GA/BoD,CA+BpD,CAAA,EA/BwD,CA+BxD;EACkB;;;;EACjB,KAAA,CAAA,GAAA,EA3BE,aA2BF,CA3BgB,SA2BhB,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAAA,EAAA,IAAA;;;;WAtBA;;UAOM,gCAAgC;;qBAE5B,WAAqB;;;;;cAU7B,uBAAwB,sBAC3B,mBACE,gBAAgB,aACzB,SAAS"}
@@ -0,0 +1,147 @@
1
+ import { __export } from "./_virtual/rolldown_runtime.mjs";
2
+ import { _defineProperty } from "./_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs";
3
+ import { make as make$1 } from "./OperationPath.mjs";
4
+ import { make as make$2 } from "./ProxyEnvironment.mjs";
5
+ import { make as make$3 } from "./Transaction.mjs";
6
+
7
+ //#region src/Document.ts
8
+ var Document_exports = /* @__PURE__ */ __export({
9
+ NestedTransactionError: () => NestedTransactionError,
10
+ OperationError: () => OperationError,
11
+ make: () => make
12
+ });
13
+ /**
14
+ * Error thrown when attempting to start a nested transaction.
15
+ */
16
+ var NestedTransactionError = class extends Error {
17
+ constructor() {
18
+ super("Nested transactions are not supported");
19
+ _defineProperty(this, "_tag", "NestedTransactionError");
20
+ this.name = "NestedTransactionError";
21
+ }
22
+ };
23
+ /**
24
+ * Error thrown when an operation fails to apply.
25
+ */
26
+ var OperationError = class extends Error {
27
+ constructor(message) {
28
+ super(message);
29
+ _defineProperty(this, "_tag", "OperationError");
30
+ this.name = "OperationError";
31
+ }
32
+ };
33
+ /**
34
+ * Creates a new Document for the given schema.
35
+ */
36
+ const make = (schema, options) => {
37
+ var _options$initial;
38
+ let _state = (_options$initial = options === null || options === void 0 ? void 0 : options.initial) !== null && _options$initial !== void 0 ? _options$initial : schema._internal.getInitialState();
39
+ let _pending = [];
40
+ let _inTransaction = false;
41
+ let _txOps = [];
42
+ let _txBaseState = void 0;
43
+ /**
44
+ * Gets state at the given path.
45
+ */
46
+ const getStateAtPath = (path) => {
47
+ const tokens = path.toTokens().filter((t) => t !== "");
48
+ if (tokens.length === 0) return _state;
49
+ let current = _state;
50
+ for (const token of tokens) {
51
+ if (current === null || current === void 0) return;
52
+ if (typeof current === "object") {
53
+ if (Array.isArray(current)) {
54
+ const entry = current.find((e) => e.id === token);
55
+ if (entry) {
56
+ current = entry.value;
57
+ continue;
58
+ }
59
+ }
60
+ current = current[token];
61
+ } else return;
62
+ }
63
+ return current;
64
+ };
65
+ /**
66
+ * Applies a single operation to the current state.
67
+ */
68
+ const applyOperation = (op) => {
69
+ try {
70
+ _state = schema._internal.applyOperation(_state, op);
71
+ } catch (error) {
72
+ if (error instanceof Error) throw new OperationError(error.message);
73
+ throw new OperationError(String(error));
74
+ }
75
+ };
76
+ /**
77
+ * Handles an operation from a proxy.
78
+ * In transaction mode: collects operations, applies to state immediately for subsequent reads.
79
+ * Outside transaction mode: auto-wraps in a single-operation transaction.
80
+ */
81
+ const handleOperation = (op) => {
82
+ if (_inTransaction) {
83
+ _txOps.push(op);
84
+ applyOperation(op);
85
+ } else {
86
+ const baseState = _state;
87
+ try {
88
+ applyOperation(op);
89
+ _pending.push(op);
90
+ } catch (error) {
91
+ _state = baseState;
92
+ throw error;
93
+ }
94
+ }
95
+ };
96
+ /**
97
+ * Creates a ProxyEnvironment for the document.
98
+ */
99
+ const createEnv = () => {
100
+ return make$2({
101
+ onOperation: handleOperation,
102
+ getState: getStateAtPath
103
+ });
104
+ };
105
+ const env = createEnv();
106
+ const rootProxy = schema._internal.createProxy(env, make$1(""));
107
+ return {
108
+ schema,
109
+ root: rootProxy,
110
+ get: () => {
111
+ return _state;
112
+ },
113
+ toSnapshot: () => {
114
+ return rootProxy.toSnapshot();
115
+ },
116
+ transaction: (fn) => {
117
+ if (_inTransaction) throw new NestedTransactionError();
118
+ _inTransaction = true;
119
+ _txOps = [];
120
+ _txBaseState = _state;
121
+ try {
122
+ const result = fn(rootProxy);
123
+ _pending.push(..._txOps);
124
+ return result;
125
+ } catch (error) {
126
+ _state = _txBaseState;
127
+ throw error;
128
+ } finally {
129
+ _inTransaction = false;
130
+ _txOps = [];
131
+ _txBaseState = void 0;
132
+ }
133
+ },
134
+ apply: (ops) => {
135
+ for (const op of ops) applyOperation(op);
136
+ },
137
+ flush: () => {
138
+ const tx = make$3(_pending);
139
+ _pending = [];
140
+ return tx;
141
+ }
142
+ };
143
+ };
144
+
145
+ //#endregion
146
+ export { Document_exports, make };
147
+ //# sourceMappingURL=Document.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Document.mjs","names":["_state: Primitive.InferState<TSchema> | undefined","_pending: Operation.Operation<any, any, any>[]","_txOps: Operation.Operation<any, any, any>[]","_txBaseState: Primitive.InferState<TSchema> | undefined","current: unknown","ProxyEnvironment.make","OperationPath.make","Transaction.make"],"sources":["../src/Document.ts"],"sourcesContent":["import * as Operation from \"./Operation\";\nimport * as OperationPath from \"./OperationPath\";\nimport * as ProxyEnvironment from \"./ProxyEnvironment\";\nimport * as Transaction from \"./Transaction\";\nimport type * as Primitive from \"./Primitive\";\n\n// =============================================================================\n// Document Errors\n// =============================================================================\n\n/**\n * Error thrown when attempting to start a nested transaction.\n */\nexport class NestedTransactionError extends Error {\n readonly _tag = \"NestedTransactionError\";\n constructor() {\n super(\"Nested transactions are not supported\");\n this.name = \"NestedTransactionError\";\n }\n}\n\n/**\n * Error thrown when an operation fails to apply.\n */\nexport class OperationError extends Error {\n readonly _tag = \"OperationError\";\n constructor(message: string) {\n super(message);\n this.name = \"OperationError\";\n }\n}\n\n// =============================================================================\n// Document Interface\n// =============================================================================\n\n/**\n * A Document manages state for a primitive-based schema with transaction support.\n */\nexport interface Document<TSchema extends Primitive.AnyPrimitive> {\n /** The schema defining this document's structure */\n readonly schema: TSchema;\n \n /** Root proxy for accessing and modifying document data */\n readonly root: Primitive.InferProxy<TSchema>;\n \n /** Returns the current document state */\n get(): Primitive.InferState<TSchema> | undefined;\n \n /**\n * Returns a readonly snapshot of the entire document state for rendering.\n * The snapshot is a type-safe, readonly structure where:\n * - Required fields and fields with defaults are guaranteed to be defined\n * - Optional fields may be undefined\n */\n toSnapshot(): Primitive.InferSnapshot<TSchema>;\n \n /**\n * Runs a function within a transaction.\n * All operations are collected and applied atomically.\n * If the function throws, all changes are rolled back.\n * @returns The return value of the function\n */\n transaction<R>(fn: (root: Primitive.InferProxy<TSchema>) => R): R;\n \n /**\n * Applies external operations (e.g., from server/peers) to the document.\n * These operations are NOT added to pending operations.\n */\n apply(ops: ReadonlyArray<Operation.Operation<any, any, any>>): void;\n \n /**\n * Returns pending local operations as a Transaction and clears the buffer.\n */\n flush(): Transaction.Transaction;\n}\n\n// =============================================================================\n// Document Options\n// =============================================================================\n\nexport interface DocumentOptions<TSchema extends Primitive.AnyPrimitive> {\n /** Initial state for the document */\n readonly initial?: Primitive.InferState<TSchema>;\n}\n\n// =============================================================================\n// Document Implementation\n// =============================================================================\n\n/**\n * Creates a new Document for the given schema.\n */\nexport const make = <TSchema extends Primitive.AnyPrimitive>(\n schema: TSchema,\n options?: DocumentOptions<TSchema>\n): Document<TSchema> => {\n // Internal state\n let _state: Primitive.InferState<TSchema> | undefined = \n options?.initial ?? schema._internal.getInitialState();\n \n // Pending operations buffer (local changes not yet flushed)\n let _pending: Operation.Operation<any, any, any>[] = [];\n \n // Transaction state\n let _inTransaction = false;\n let _txOps: Operation.Operation<any, any, any>[] = [];\n let _txBaseState: Primitive.InferState<TSchema> | undefined = undefined;\n\n /**\n * Gets state at the given path.\n */\n const getStateAtPath = (path: OperationPath.OperationPath): unknown => {\n const tokens = path.toTokens().filter(t => t !== \"\");\n \n if (tokens.length === 0) {\n return _state;\n }\n \n let current: unknown = _state;\n for (const token of tokens) {\n if (current === null || current === undefined) {\n return undefined;\n }\n \n if (typeof current === \"object\") {\n // Handle array entries (which have { id, pos, value } structure)\n if (Array.isArray(current)) {\n // Try to find by ID in array entries\n const entry = current.find((e: any) => e.id === token);\n if (entry) {\n current = entry.value;\n continue;\n }\n }\n \n // Handle regular object property access\n current = (current as Record<string, unknown>)[token];\n } else {\n return undefined;\n }\n }\n \n return current;\n };\n\n /**\n * Applies a single operation to the current state.\n */\n const applyOperation = (op: Operation.Operation<any, any, any>): void => {\n try {\n _state = schema._internal.applyOperation(_state, op);\n } catch (error) {\n if (error instanceof Error) {\n throw new OperationError(error.message);\n }\n throw new OperationError(String(error));\n }\n };\n\n /**\n * Handles an operation from a proxy.\n * In transaction mode: collects operations, applies to state immediately for subsequent reads.\n * Outside transaction mode: auto-wraps in a single-operation transaction.\n */\n const handleOperation = (op: Operation.Operation<any, any, any>): void => {\n if (_inTransaction) {\n // In transaction: collect op and apply immediately for subsequent reads\n _txOps.push(op);\n applyOperation(op);\n } else {\n // Not in transaction: auto-wrap in single-operation transaction\n const baseState = _state;\n try {\n applyOperation(op);\n _pending.push(op);\n } catch (error) {\n // Rollback on error\n _state = baseState;\n throw error;\n }\n }\n };\n\n /**\n * Creates a ProxyEnvironment for the document.\n */\n const createEnv = (): ProxyEnvironment.ProxyEnvironment => {\n return ProxyEnvironment.make({\n onOperation: handleOperation,\n getState: getStateAtPath,\n });\n };\n\n // Create the root proxy\n const env = createEnv();\n const rootProxy = schema._internal.createProxy(env, OperationPath.make(\"\")) as Primitive.InferProxy<TSchema>;\n\n // Document implementation\n const document: Document<TSchema> = {\n schema,\n root: rootProxy,\n \n get: (): Primitive.InferState<TSchema> | undefined => {\n return _state;\n },\n \n toSnapshot: (): Primitive.InferSnapshot<TSchema> => {\n return (rootProxy as { toSnapshot(): Primitive.InferSnapshot<TSchema> }).toSnapshot();\n },\n \n transaction: <R,>(fn: (root: Primitive.InferProxy<TSchema>) => R): R => {\n if (_inTransaction) {\n throw new NestedTransactionError();\n }\n \n // Start transaction\n _inTransaction = true;\n _txOps = [];\n _txBaseState = _state;\n \n try {\n // Execute the transaction function\n const result = fn(rootProxy);\n \n // Commit: add transaction ops to pending\n _pending.push(..._txOps);\n \n return result;\n } catch (error) {\n // Rollback: restore base state\n _state = _txBaseState;\n throw error;\n } finally {\n // Clean up transaction state\n _inTransaction = false;\n _txOps = [];\n _txBaseState = undefined;\n }\n },\n \n apply: (ops: ReadonlyArray<Operation.Operation<any, any, any>>): void => {\n for (const op of ops) {\n applyOperation(op);\n }\n },\n \n flush: (): Transaction.Transaction => {\n const tx = Transaction.make(_pending);\n _pending = [];\n return tx;\n },\n };\n\n return document;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,yBAAb,cAA4C,MAAM;CAEhD,cAAc;AACZ,QAAM,wCAAwC;wBAFvC,QAAO;AAGd,OAAK,OAAO;;;;;;AAOhB,IAAa,iBAAb,cAAoC,MAAM;CAExC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;wBAFP,QAAO;AAGd,OAAK,OAAO;;;;;;AAiEhB,MAAa,QACX,QACA,YACsB;;CAEtB,IAAIA,+EACF,QAAS,sEAAW,OAAO,UAAU,iBAAiB;CAGxD,IAAIC,WAAiD,EAAE;CAGvD,IAAI,iBAAiB;CACrB,IAAIC,SAA+C,EAAE;CACrD,IAAIC,eAA0D;;;;CAK9D,MAAM,kBAAkB,SAA+C;EACrE,MAAM,SAAS,KAAK,UAAU,CAAC,QAAO,MAAK,MAAM,GAAG;AAEpD,MAAI,OAAO,WAAW,EACpB,QAAO;EAGT,IAAIC,UAAmB;AACvB,OAAK,MAAM,SAAS,QAAQ;AAC1B,OAAI,YAAY,QAAQ,YAAY,OAClC;AAGF,OAAI,OAAO,YAAY,UAAU;AAE/B,QAAI,MAAM,QAAQ,QAAQ,EAAE;KAE1B,MAAM,QAAQ,QAAQ,MAAM,MAAW,EAAE,OAAO,MAAM;AACtD,SAAI,OAAO;AACT,gBAAU,MAAM;AAChB;;;AAKJ,cAAW,QAAoC;SAE/C;;AAIJ,SAAO;;;;;CAMT,MAAM,kBAAkB,OAAiD;AACvE,MAAI;AACF,YAAS,OAAO,UAAU,eAAe,QAAQ,GAAG;WAC7C,OAAO;AACd,OAAI,iBAAiB,MACnB,OAAM,IAAI,eAAe,MAAM,QAAQ;AAEzC,SAAM,IAAI,eAAe,OAAO,MAAM,CAAC;;;;;;;;CAS3C,MAAM,mBAAmB,OAAiD;AACxE,MAAI,gBAAgB;AAElB,UAAO,KAAK,GAAG;AACf,kBAAe,GAAG;SACb;GAEL,MAAM,YAAY;AAClB,OAAI;AACF,mBAAe,GAAG;AAClB,aAAS,KAAK,GAAG;YACV,OAAO;AAEd,aAAS;AACT,UAAM;;;;;;;CAQZ,MAAM,kBAAqD;AACzD,SAAOC,OAAsB;GAC3B,aAAa;GACb,UAAU;GACX,CAAC;;CAIJ,MAAM,MAAM,WAAW;CACvB,MAAM,YAAY,OAAO,UAAU,YAAY,KAAKC,OAAmB,GAAG,CAAC;AA0D3E,QAvDoC;EAClC;EACA,MAAM;EAEN,WAAsD;AACpD,UAAO;;EAGT,kBAAoD;AAClD,UAAQ,UAAiE,YAAY;;EAGvF,cAAkB,OAAsD;AACtE,OAAI,eACF,OAAM,IAAI,wBAAwB;AAIpC,oBAAiB;AACjB,YAAS,EAAE;AACX,kBAAe;AAEf,OAAI;IAEF,MAAM,SAAS,GAAG,UAAU;AAG5B,aAAS,KAAK,GAAG,OAAO;AAExB,WAAO;YACA,OAAO;AAEd,aAAS;AACT,UAAM;aACE;AAER,qBAAiB;AACjB,aAAS,EAAE;AACX,mBAAe;;;EAInB,QAAQ,QAAiE;AACvE,QAAK,MAAM,MAAM,IACf,gBAAe,GAAG;;EAItB,aAAsC;GACpC,MAAM,KAAKC,OAAiB,SAAS;AACrC,cAAW,EAAE;AACb,UAAO;;EAEV"}
@@ -0,0 +1,180 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let effect = require("effect");
3
+
4
+ //#region src/EffectSchema.ts
5
+ /**
6
+ * Effect.Schema utilities for converting Mimic primitives to Effect.Schema schemas.
7
+ *
8
+ * @since 0.0.1
9
+ */
10
+ var EffectSchema_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
11
+ TreeNodeStateSchema: () => TreeNodeStateSchema,
12
+ toSetSchema: () => toSetSchema,
13
+ toUpdateSchema: () => toUpdateSchema
14
+ });
15
+ /**
16
+ * Schema for a tree node state (flat storage format).
17
+ */
18
+ const TreeNodeStateSchema = effect.Schema.Struct({
19
+ id: effect.Schema.String,
20
+ type: effect.Schema.String,
21
+ parentId: effect.Schema.NullOr(effect.Schema.String),
22
+ pos: effect.Schema.String,
23
+ data: effect.Schema.Unknown
24
+ });
25
+ /**
26
+ * Check if a field is required for set operations.
27
+ * A field is required if: TRequired is true AND THasDefault is false.
28
+ *
29
+ * We determine this by checking the primitive's schema properties.
30
+ */
31
+ function isRequiredForSet(primitive) {
32
+ const schema = primitive._schema;
33
+ if (!schema) return false;
34
+ return schema.required === true && schema.defaultValue === void 0;
35
+ }
36
+ /**
37
+ * Get the base Effect.Schema for a primitive type (without optional wrapper).
38
+ */
39
+ function getBaseSchema(primitive) {
40
+ switch (primitive._tag) {
41
+ case "StringPrimitive": return effect.Schema.String;
42
+ case "NumberPrimitive": return effect.Schema.Number;
43
+ case "BooleanPrimitive": return effect.Schema.Boolean;
44
+ case "LiteralPrimitive": {
45
+ var _schema$literal, _schema;
46
+ const literalPrimitive = primitive;
47
+ const literalValue = (_schema$literal = (_schema = literalPrimitive._schema) === null || _schema === void 0 ? void 0 : _schema.literal) !== null && _schema$literal !== void 0 ? _schema$literal : literalPrimitive.literal;
48
+ return effect.Schema.Literal(literalValue);
49
+ }
50
+ case "StructPrimitive": return buildStructSetSchema(primitive);
51
+ case "ArrayPrimitive": {
52
+ const elementSchema = buildElementSetSchema(primitive.element);
53
+ return effect.Schema.Array(elementSchema);
54
+ }
55
+ case "UnionPrimitive": return buildUnionSetSchema(primitive);
56
+ case "EitherPrimitive": return buildEitherSchema(primitive);
57
+ case "LazyPrimitive": {
58
+ var _resolve, _resolve2;
59
+ const lazyPrimitive = primitive;
60
+ return getBaseSchema((_resolve = (_resolve2 = lazyPrimitive._resolve) === null || _resolve2 === void 0 ? void 0 : _resolve2.call(lazyPrimitive)) !== null && _resolve !== void 0 ? _resolve : lazyPrimitive._thunk());
61
+ }
62
+ case "TreeNodePrimitive": return buildStructSetSchema(primitive.data);
63
+ case "TreePrimitive": return effect.Schema.Array(TreeNodeStateSchema);
64
+ default: return effect.Schema.Unknown;
65
+ }
66
+ }
67
+ /**
68
+ * Build the set schema for a struct primitive.
69
+ * Required fields (required=true, no default) are non-optional.
70
+ * Other fields are wrapped with Schema.optional.
71
+ */
72
+ function buildStructSetSchema(structPrimitive) {
73
+ const fields = structPrimitive.fields;
74
+ const schemaFields = {};
75
+ for (const key in fields) {
76
+ const fieldPrimitive = fields[key];
77
+ const baseSchema = getBaseSchema(fieldPrimitive);
78
+ if (isRequiredForSet(fieldPrimitive)) schemaFields[key] = baseSchema;
79
+ else schemaFields[key] = effect.Schema.optional(baseSchema);
80
+ }
81
+ return effect.Schema.Struct(schemaFields);
82
+ }
83
+ /**
84
+ * Build the update schema for a struct primitive.
85
+ * All fields are optional for partial updates.
86
+ */
87
+ function buildStructUpdateSchema(structPrimitive) {
88
+ const fields = structPrimitive.fields;
89
+ const schemaFields = {};
90
+ for (const key in fields) {
91
+ const fieldPrimitive = fields[key];
92
+ let fieldSchema;
93
+ if (fieldPrimitive._tag === "StructPrimitive") fieldSchema = buildStructUpdateSchema(fieldPrimitive);
94
+ else fieldSchema = getBaseSchema(fieldPrimitive);
95
+ schemaFields[key] = effect.Schema.optional(fieldSchema);
96
+ }
97
+ return effect.Schema.Struct(schemaFields);
98
+ }
99
+ /**
100
+ * Build the set schema for an array element.
101
+ * For struct elements, uses the struct's set input schema.
102
+ */
103
+ function buildElementSetSchema(elementPrimitive) {
104
+ if (elementPrimitive._tag === "StructPrimitive") return buildStructSetSchema(elementPrimitive);
105
+ return getBaseSchema(elementPrimitive);
106
+ }
107
+ /**
108
+ * Build the set schema for a union primitive.
109
+ * Creates a Schema.Union of all variant schemas.
110
+ */
111
+ function buildUnionSetSchema(unionPrimitive) {
112
+ const variants = unionPrimitive.variants;
113
+ const variantSchemas = [];
114
+ for (const key in variants) {
115
+ const variantPrimitive = variants[key];
116
+ variantSchemas.push(buildStructSetSchema(variantPrimitive));
117
+ }
118
+ if (variantSchemas.length === 0) return effect.Schema.Unknown;
119
+ if (variantSchemas.length === 1) return variantSchemas[0];
120
+ return effect.Schema.Union(...variantSchemas);
121
+ }
122
+ /**
123
+ * Build the schema for an either primitive.
124
+ * Creates a Schema.Union of all scalar variant types.
125
+ */
126
+ function buildEitherSchema(eitherPrimitive) {
127
+ const variants = eitherPrimitive.variants;
128
+ const variantSchemas = [];
129
+ for (const variant of variants) variantSchemas.push(getBaseSchema(variant));
130
+ if (variantSchemas.length === 0) return effect.Schema.Unknown;
131
+ if (variantSchemas.length === 1) return variantSchemas[0];
132
+ return effect.Schema.Union(...variantSchemas);
133
+ }
134
+ /**
135
+ * Build the update schema for a union primitive.
136
+ * Creates a Schema.Union of all variant update schemas.
137
+ */
138
+ function buildUnionUpdateSchema(unionPrimitive) {
139
+ const variants = unionPrimitive.variants;
140
+ const variantSchemas = [];
141
+ for (const key in variants) {
142
+ const variantPrimitive = variants[key];
143
+ variantSchemas.push(buildStructUpdateSchema(variantPrimitive));
144
+ }
145
+ if (variantSchemas.length === 0) return effect.Schema.Unknown;
146
+ if (variantSchemas.length === 1) return variantSchemas[0];
147
+ return effect.Schema.Union(...variantSchemas);
148
+ }
149
+ /**
150
+ * Get the update schema for a primitive.
151
+ * For structs, all fields are optional (partial updates).
152
+ * For simple primitives, same as set schema.
153
+ */
154
+ function getUpdateSchema(primitive) {
155
+ switch (primitive._tag) {
156
+ case "StructPrimitive": return buildStructUpdateSchema(primitive);
157
+ case "UnionPrimitive": return buildUnionUpdateSchema(primitive);
158
+ case "TreeNodePrimitive": return buildStructUpdateSchema(primitive.data);
159
+ case "LazyPrimitive": {
160
+ var _resolve3, _resolve4;
161
+ const lazyPrimitive = primitive;
162
+ return getUpdateSchema((_resolve3 = (_resolve4 = lazyPrimitive._resolve) === null || _resolve4 === void 0 ? void 0 : _resolve4.call(lazyPrimitive)) !== null && _resolve3 !== void 0 ? _resolve3 : lazyPrimitive._thunk());
163
+ }
164
+ default: return getBaseSchema(primitive);
165
+ }
166
+ }
167
+ function toSetSchema(primitive) {
168
+ return getBaseSchema(primitive);
169
+ }
170
+ function toUpdateSchema(primitive) {
171
+ return getUpdateSchema(primitive);
172
+ }
173
+
174
+ //#endregion
175
+ Object.defineProperty(exports, 'EffectSchema_exports', {
176
+ enumerable: true,
177
+ get: function () {
178
+ return EffectSchema_exports;
179
+ }
180
+ });
@@ -0,0 +1,84 @@
1
+ import { AnyPrimitive, InferSetInput, InferUpdateInput } from "./primitives/shared.cjs";
2
+ import { AnyTreeNodePrimitive } from "./primitives/TreeNode.cjs";
3
+ import { Schema } from "effect";
4
+
5
+ //#region src/EffectSchema.d.ts
6
+ declare namespace EffectSchema_d_exports {
7
+ export { ToSetSchema, ToTreeNodeSetSchema, ToTreeNodeUpdateSchema, ToUpdateSchema, TreeNodeStateSchema, toSetSchema, toUpdateSchema };
8
+ }
9
+ /**
10
+ * Infer the Effect.Schema type for a primitive's set input.
11
+ */
12
+ type ToSetSchema<T extends AnyPrimitive> = Schema.Schema<InferSetInput<T>>;
13
+ /**
14
+ * Infer the Effect.Schema type for a primitive's update input.
15
+ */
16
+ type ToUpdateSchema<T extends AnyPrimitive> = Schema.Schema<InferUpdateInput<T>>;
17
+ /**
18
+ * Type for TreeNode set schema - uses the node's data set input type
19
+ */
20
+ type ToTreeNodeSetSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferSetInput<T["data"]>>;
21
+ /**
22
+ * Type for TreeNode update schema - uses the node's data update input type
23
+ */
24
+ type ToTreeNodeUpdateSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferUpdateInput<T["data"]>>;
25
+ /**
26
+ * Schema for a tree node state (flat storage format).
27
+ */
28
+ declare const TreeNodeStateSchema: Schema.Struct<{
29
+ id: typeof Schema.String;
30
+ type: typeof Schema.String;
31
+ parentId: Schema.NullOr<typeof Schema.String>;
32
+ pos: typeof Schema.String;
33
+ data: typeof Schema.Unknown;
34
+ }>;
35
+ /**
36
+ * Convert a Mimic primitive to an Effect.Schema for set operations.
37
+ *
38
+ * The resulting schema:
39
+ * - For structs: required fields (required=true, no default) are non-optional, others are optional
40
+ * - For arrays: uses the element's set schema
41
+ * - For unions: creates a Schema.Union of variant schemas
42
+ * - For TreeNode: delegates to the node's data struct schema
43
+ * - For Tree: returns Schema.Array of TreeNodeState
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const UserSchema = Primitive.Struct({
48
+ * name: Primitive.String().required(),
49
+ * age: Primitive.Number().default(0),
50
+ * email: Primitive.String(),
51
+ * });
52
+ *
53
+ * const SetSchema = toSetSchema(UserSchema);
54
+ * // { name: string, age?: number, email?: string }
55
+ * ```
56
+ */
57
+ declare function toSetSchema<T extends AnyPrimitive>(primitive: T): ToSetSchema<T>;
58
+ declare function toSetSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeSetSchema<T>;
59
+ /**
60
+ * Convert a Mimic primitive to an Effect.Schema for update operations.
61
+ *
62
+ * The resulting schema:
63
+ * - For structs: all fields are optional (partial updates)
64
+ * - For unions: all variant fields are optional
65
+ * - For TreeNode: delegates to the node's data struct update schema
66
+ * - For simple primitives: same as set schema
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const UserSchema = Primitive.Struct({
71
+ * name: Primitive.String().required(),
72
+ * age: Primitive.Number().default(0),
73
+ * email: Primitive.String(),
74
+ * });
75
+ *
76
+ * const UpdateSchema = toUpdateSchema(UserSchema);
77
+ * // { name?: string, age?: string, email?: string }
78
+ * ```
79
+ */
80
+ declare function toUpdateSchema<T extends AnyPrimitive>(primitive: T): ToUpdateSchema<T>;
81
+ declare function toUpdateSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeUpdateSchema<T>;
82
+ //#endregion
83
+ export { EffectSchema_d_exports };
84
+ //# sourceMappingURL=EffectSchema.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EffectSchema.d.cts","names":[],"sources":["../src/EffectSchema.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;KAsBY,sBAAsB,gBAAgB,MAAA,CAAO,OAAO,cAAc;;;;AAAlE,KAKA,cALW,CAAA,UAKc,YALd,CAAA,GAK8B,MAAA,CAAO,MALrC,CAK4C,gBAL5C,CAK6D,CAL7D,CAAA,CAAA;;;;AAA2B,KAUtC,mBAV6C,CAAA,UAUf,oBAVe,CAAA,GAUS,MAAA,CAAO,MAVhB,CAUuB,aAVvB,CAUqC,CAVrC,CAAA,MAAA,CAAA,CAAA,CAAA;;AAKzD;;AAAoF,KAUxE,sBAVwE,CAAA,UAUvC,oBAVuC,CAAA,GAUf,MAAA,CAAO,MAVQ,CAUD,gBAVC,CAUgB,CAVhB,CAAA,MAAA,CAAA,CAAA,CAAA;;;;AAKxE,cAcC,mBAdkB,EAcC,MAAA,CAAA,MAdD,CAAA;EAAW,EAAA,EAAA,oBAAA;EAAoD,IAAA,EAAA,oBAAA;EAAd,QAAA,eAAA,CAAA,oBAAA,CAAA;EAAd,GAAA,EAAO,oBAAA;EAAM,IAAA,EAAA,qBAAA;AAK/E,CAAA,CAAA;;;;;;AASA;;;;;;;;;AAwSA;;;;;;AACA;;AAAuE,iBADvD,WACuD,CAAA,UADjC,YACiC,CAAA,CAAA,SAAA,EADR,CACQ,CAAA,EADJ,WACI,CADQ,CACR,CAAA;AAAwB,iBAA/E,WAA+E,CAAA,UAAzD,oBAAyD,CAAA,CAAA,SAAA,EAAxB,CAAwB,CAAA,EAApB,mBAAoB,CAAA,CAAA,CAAA;;;AA0B/F;;;;;;AACA;;;;;;;;;;;;;iBADgB,yBAAyB,yBAAyB,IAAI,eAAe;iBACrE,yBAAyB,iCAAiC,IAAI,uBAAuB"}
@@ -0,0 +1,84 @@
1
+ import { AnyPrimitive, InferSetInput, InferUpdateInput } from "./primitives/shared.mjs";
2
+ import { AnyTreeNodePrimitive } from "./primitives/TreeNode.mjs";
3
+ import { Schema } from "effect";
4
+
5
+ //#region src/EffectSchema.d.ts
6
+ declare namespace EffectSchema_d_exports {
7
+ export { ToSetSchema, ToTreeNodeSetSchema, ToTreeNodeUpdateSchema, ToUpdateSchema, TreeNodeStateSchema, toSetSchema, toUpdateSchema };
8
+ }
9
+ /**
10
+ * Infer the Effect.Schema type for a primitive's set input.
11
+ */
12
+ type ToSetSchema<T extends AnyPrimitive> = Schema.Schema<InferSetInput<T>>;
13
+ /**
14
+ * Infer the Effect.Schema type for a primitive's update input.
15
+ */
16
+ type ToUpdateSchema<T extends AnyPrimitive> = Schema.Schema<InferUpdateInput<T>>;
17
+ /**
18
+ * Type for TreeNode set schema - uses the node's data set input type
19
+ */
20
+ type ToTreeNodeSetSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferSetInput<T["data"]>>;
21
+ /**
22
+ * Type for TreeNode update schema - uses the node's data update input type
23
+ */
24
+ type ToTreeNodeUpdateSchema<T extends AnyTreeNodePrimitive> = Schema.Schema<InferUpdateInput<T["data"]>>;
25
+ /**
26
+ * Schema for a tree node state (flat storage format).
27
+ */
28
+ declare const TreeNodeStateSchema: Schema.Struct<{
29
+ id: typeof Schema.String;
30
+ type: typeof Schema.String;
31
+ parentId: Schema.NullOr<typeof Schema.String>;
32
+ pos: typeof Schema.String;
33
+ data: typeof Schema.Unknown;
34
+ }>;
35
+ /**
36
+ * Convert a Mimic primitive to an Effect.Schema for set operations.
37
+ *
38
+ * The resulting schema:
39
+ * - For structs: required fields (required=true, no default) are non-optional, others are optional
40
+ * - For arrays: uses the element's set schema
41
+ * - For unions: creates a Schema.Union of variant schemas
42
+ * - For TreeNode: delegates to the node's data struct schema
43
+ * - For Tree: returns Schema.Array of TreeNodeState
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const UserSchema = Primitive.Struct({
48
+ * name: Primitive.String().required(),
49
+ * age: Primitive.Number().default(0),
50
+ * email: Primitive.String(),
51
+ * });
52
+ *
53
+ * const SetSchema = toSetSchema(UserSchema);
54
+ * // { name: string, age?: number, email?: string }
55
+ * ```
56
+ */
57
+ declare function toSetSchema<T extends AnyPrimitive>(primitive: T): ToSetSchema<T>;
58
+ declare function toSetSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeSetSchema<T>;
59
+ /**
60
+ * Convert a Mimic primitive to an Effect.Schema for update operations.
61
+ *
62
+ * The resulting schema:
63
+ * - For structs: all fields are optional (partial updates)
64
+ * - For unions: all variant fields are optional
65
+ * - For TreeNode: delegates to the node's data struct update schema
66
+ * - For simple primitives: same as set schema
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const UserSchema = Primitive.Struct({
71
+ * name: Primitive.String().required(),
72
+ * age: Primitive.Number().default(0),
73
+ * email: Primitive.String(),
74
+ * });
75
+ *
76
+ * const UpdateSchema = toUpdateSchema(UserSchema);
77
+ * // { name?: string, age?: string, email?: string }
78
+ * ```
79
+ */
80
+ declare function toUpdateSchema<T extends AnyPrimitive>(primitive: T): ToUpdateSchema<T>;
81
+ declare function toUpdateSchema<T extends AnyTreeNodePrimitive>(primitive: T): ToTreeNodeUpdateSchema<T>;
82
+ //#endregion
83
+ export { EffectSchema_d_exports };
84
+ //# sourceMappingURL=EffectSchema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EffectSchema.d.mts","names":[],"sources":["../src/EffectSchema.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;KAsBY,sBAAsB,gBAAgB,MAAA,CAAO,OAAO,cAAc;;;;AAAlE,KAKA,cALW,CAAA,UAKc,YALd,CAAA,GAK8B,MAAA,CAAO,MALrC,CAK4C,gBAL5C,CAK6D,CAL7D,CAAA,CAAA;;;;AAA2B,KAUtC,mBAV6C,CAAA,UAUf,oBAVe,CAAA,GAUS,MAAA,CAAO,MAVhB,CAUuB,aAVvB,CAUqC,CAVrC,CAAA,MAAA,CAAA,CAAA,CAAA;;AAKzD;;AAAoF,KAUxE,sBAVwE,CAAA,UAUvC,oBAVuC,CAAA,GAUf,MAAA,CAAO,MAVQ,CAUD,gBAVC,CAUgB,CAVhB,CAAA,MAAA,CAAA,CAAA,CAAA;;;;AAKxE,cAcC,mBAdkB,EAcC,MAAA,CAAA,MAdD,CAAA;EAAW,EAAA,EAAA,oBAAA;EAAoD,IAAA,EAAA,oBAAA;EAAd,QAAA,eAAA,CAAA,oBAAA,CAAA;EAAd,GAAA,EAAO,oBAAA;EAAM,IAAA,EAAA,qBAAA;AAK/E,CAAA,CAAA;;;;;;AASA;;;;;;;;;AAwSA;;;;;;AACA;;AAAuE,iBADvD,WACuD,CAAA,UADjC,YACiC,CAAA,CAAA,SAAA,EADR,CACQ,CAAA,EADJ,WACI,CADQ,CACR,CAAA;AAAwB,iBAA/E,WAA+E,CAAA,UAAzD,oBAAyD,CAAA,CAAA,SAAA,EAAxB,CAAwB,CAAA,EAApB,mBAAoB,CAAA,CAAA,CAAA;;;AA0B/F;;;;;;AACA;;;;;;;;;;;;;iBADgB,yBAAyB,yBAAyB,IAAI,eAAe;iBACrE,yBAAyB,iCAAiC,IAAI,uBAAuB"}