@voidhash/mimic 0.0.1-alpha.7 → 0.0.1-alpha.8

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 (53) hide show
  1. package/.turbo/turbo-build.log +43 -15
  2. package/dist/Document-ChuFrTk1.cjs +571 -0
  3. package/dist/Document-CwiAFTIq.mjs +438 -0
  4. package/dist/Document-CwiAFTIq.mjs.map +1 -0
  5. package/dist/Presence-DKKP4v5X.d.cts +91 -0
  6. package/dist/Presence-DKKP4v5X.d.cts.map +1 -0
  7. package/dist/Presence-DdMVKcOv.mjs +110 -0
  8. package/dist/Presence-DdMVKcOv.mjs.map +1 -0
  9. package/dist/Presence-N8u7Eppr.d.mts +91 -0
  10. package/dist/Presence-N8u7Eppr.d.mts.map +1 -0
  11. package/dist/Presence-gWrmGBeu.cjs +126 -0
  12. package/dist/Primitive-BK7kfHJZ.d.cts +1165 -0
  13. package/dist/Primitive-BK7kfHJZ.d.cts.map +1 -0
  14. package/dist/Primitive-D1kdB6za.d.mts +1165 -0
  15. package/dist/Primitive-D1kdB6za.d.mts.map +1 -0
  16. package/dist/client/index.cjs +1456 -0
  17. package/dist/client/index.d.cts +692 -0
  18. package/dist/client/index.d.cts.map +1 -0
  19. package/dist/client/index.d.mts +692 -0
  20. package/dist/client/index.d.mts.map +1 -0
  21. package/dist/client/index.mjs +1413 -0
  22. package/dist/client/index.mjs.map +1 -0
  23. package/dist/index.cjs +224 -765
  24. package/dist/index.d.cts +5 -1152
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts +5 -1152
  27. package/dist/index.d.mts.map +1 -1
  28. package/dist/index.mjs +69 -569
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/server/index.cjs +191 -0
  31. package/dist/server/index.d.cts +148 -0
  32. package/dist/server/index.d.cts.map +1 -0
  33. package/dist/server/index.d.mts +148 -0
  34. package/dist/server/index.d.mts.map +1 -0
  35. package/dist/server/index.mjs +182 -0
  36. package/dist/server/index.mjs.map +1 -0
  37. package/package.json +16 -4
  38. package/src/primitives/Array.ts +25 -14
  39. package/src/primitives/Boolean.ts +29 -17
  40. package/src/primitives/Either.ts +30 -17
  41. package/src/primitives/Lazy.ts +16 -2
  42. package/src/primitives/Literal.ts +29 -18
  43. package/src/primitives/Number.ts +35 -24
  44. package/src/primitives/String.ts +36 -23
  45. package/src/primitives/Struct.ts +74 -26
  46. package/src/primitives/Tree.ts +30 -14
  47. package/src/primitives/Union.ts +21 -21
  48. package/src/primitives/shared.ts +27 -34
  49. package/tests/primitives/Array.test.ts +108 -0
  50. package/tests/primitives/Struct.test.ts +2 -2
  51. package/tests/primitives/Tree.test.ts +128 -0
  52. package/tsdown.config.ts +1 -1
  53. /package/dist/{chunk-C6wwvPpM.mjs → chunk-CLMFDpHK.mjs} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,1071 +1,9 @@
1
- import { Schema } from "effect";
2
- import * as Schema$1 from "effect/Schema";
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-BK7kfHJZ.cjs";
2
+ import { i as Presence_d_exports } from "./Presence-DKKP4v5X.cjs";
3
3
 
4
- //#region rolldown:runtime
5
- declare namespace OperationPath_d_exports {
6
- export { EncodedOperationPath, OperationPath, OperationPathToken, decode$2 as decode, encode$2 as encode, fromTokens, getRelativePath, isPrefix, make$4 as make, pathsEqual, pathsOverlap };
7
- }
8
- type OperationPathToken = string;
9
- interface OperationPath {
10
- readonly _tag: "OperationPath";
11
- readonly toTokens: () => ReadonlyArray<OperationPathToken>;
12
- readonly concat: (other: OperationPath) => OperationPath;
13
- readonly append: (token: OperationPathToken) => OperationPath;
14
- readonly pop: () => OperationPath;
15
- readonly shift: () => OperationPath;
16
- }
17
- /**
18
- * Creates a new operation path.
19
- * @param stringPath - The string path to create the path from.
20
- * @returns The new operation path.
21
- */
22
- declare function make$4(stringPath?: string): OperationPath;
23
- /**
24
- * Creates a new operation path from tokens.
25
- * @param tokens - The tokens to create the path from.
26
- * @returns The new operation path.
27
- */
28
- declare function fromTokens(tokens: ReadonlyArray<OperationPathToken>): OperationPath;
29
- /**
30
- * Checks if two operation paths overlap (one is prefix of the other or equal).
31
- */
32
- declare const pathsOverlap: (pathA: OperationPath, pathB: OperationPath) => boolean;
33
- /**
34
- * Checks if pathA is a prefix of pathB (pathA is ancestor of pathB).
35
- */
36
- declare const isPrefix: (pathA: OperationPath, pathB: OperationPath) => boolean;
37
- /**
38
- * Checks if two paths are exactly equal.
39
- */
40
- declare const pathsEqual: (pathA: OperationPath, pathB: OperationPath) => boolean;
41
- /**
42
- * Gets the relative path of pathB with respect to pathA.
43
- * Assumes pathA is a prefix of pathB.
44
- */
45
- declare const getRelativePath: (basePath: OperationPath, fullPath: OperationPath) => string[];
46
- /**
47
- * Encoded representation of an OperationPath for network transport.
48
- */
49
- type EncodedOperationPath = string;
50
- /**
51
- * Encodes an OperationPath to a string for network transport.
52
- * @param path - The operation path to encode.
53
- * @returns The encoded string representation.
54
- */
55
- declare const encode$2: (path: OperationPath) => EncodedOperationPath;
56
- /**
57
- * Decodes an encoded string back to an OperationPath.
58
- * @param encoded - The encoded string representation.
59
- * @returns The decoded OperationPath.
60
- */
61
- declare const decode$2: (encoded: EncodedOperationPath) => OperationPath;
62
- //#endregion
63
- //#region src/OperationDefinition.d.ts
64
- interface OperationDefinition<TKind, TPayload extends Schema.Schema.Any, TTarget extends Schema.Schema.Any> {
65
- readonly kind: TKind;
66
- readonly payload: TPayload;
67
- readonly target: TTarget;
68
- }
69
- declare namespace Operation_d_exports {
70
- export { EncodedOperation, Operation, decode$1 as decode, encode$1 as encode, fromDefinition };
71
- }
72
- type Operation<TKind, TPayload extends Schema.Schema.Any, TDef extends OperationDefinition<TKind, TPayload, any>> = {
73
- readonly kind: TKind;
74
- readonly path: OperationPath;
75
- readonly payload: Schema.Schema.Type<TPayload>;
76
- } & TDef;
77
- declare const fromDefinition: <TKind, TPayload extends Schema.Schema.Any, TDef extends OperationDefinition<TKind, TPayload, any>>(operationPath: OperationPath, definition: TDef, payload: Schema.Schema.Type<TPayload>) => Operation<TKind, TPayload, TDef>;
78
- /**
79
- * Encoded representation of an Operation for network transport.
80
- */
81
- interface EncodedOperation {
82
- readonly kind: unknown;
83
- readonly path: EncodedOperationPath;
84
- readonly payload: unknown;
85
- }
86
- /**
87
- * Encodes an Operation to a JSON-serializable format for network transport.
88
- * @param operation - The operation to encode.
89
- * @returns The encoded representation.
90
- */
91
- declare const encode$1: <TKind, TPayload extends Schema.Schema.Any, TDef extends OperationDefinition<TKind, TPayload, any>>(operation: Operation<TKind, TPayload, TDef>) => EncodedOperation;
92
- /**
93
- * Decodes an encoded operation back to an Operation.
94
- * Note: This returns a partial operation without the definition methods.
95
- * The caller must have the operation definitions to fully reconstruct if needed.
96
- * @param encoded - The encoded representation.
97
- * @returns The decoded Operation (without definition-specific methods).
98
- */
99
- declare const decode$1: (encoded: EncodedOperation) => Operation<unknown, Schema.Schema.Any, any>;
100
- declare namespace ProxyEnvironment_d_exports {
101
- export { ProxyEnvironment, ProxyEnvironmentOptions, make$3 as make };
102
- }
103
- type ProxyEnvironment = {
104
- /** Adds an operation to be collected/applied */
105
- readonly addOperation: (operation: Operation<any, any, any>) => void;
106
- /** Gets the current state at the given path */
107
- readonly getState: (path: OperationPath) => unknown;
108
- /** Generates a unique ID (UUID) for array elements */
109
- readonly generateId: () => string;
110
- };
111
- interface ProxyEnvironmentOptions {
112
- /** Callback when an operation is added */
113
- readonly onOperation: (operation: Operation<any, any, any>) => void;
114
- /** Function to retrieve current state at a path (defaults to returning undefined) */
115
- readonly getState?: (path: OperationPath) => unknown;
116
- /** Optional: Custom ID generator (defaults to crypto.randomUUID) */
117
- readonly generateId?: () => string;
118
- }
119
- /**
120
- * Creates a ProxyEnvironment.
121
- * @param optionsOrCallback - Either an options object or a simple callback for operations
122
- */
123
- declare const make$3: (optionsOrCallback: ProxyEnvironmentOptions | ((operation: Operation<any, any, any>) => void)) => ProxyEnvironment;
124
- declare namespace Transform_d_exports {
125
- export { TransformResult };
126
- }
127
- /**
128
- * Result of transforming an operation against another operation.
129
- */
130
- type TransformResult = {
131
- type: "transformed";
132
- operation: Operation<any, any, any>;
133
- } | {
134
- type: "noop";
135
- } | {
136
- type: "conflict";
137
- reason: string;
138
- };
139
- //#endregion
140
- //#region src/primitives/shared.d.ts
141
- /**
142
- * Base interface that all primitives must implement.
143
- * Provides type inference helpers and internal operations.
144
- *
145
- * @typeParam TState - The state type this primitive holds
146
- * @typeParam TProxy - The proxy type for interacting with this primitive
147
- * @typeParam TDefined - Whether the value is guaranteed to be defined (via required() or default())
148
- * @typeParam THasDefault - Whether this primitive has a default value
149
- */
150
- interface Primitive<TState, TProxy, TDefined extends boolean = false, THasDefault extends boolean = false> {
151
- readonly _tag: string;
152
- readonly _State: TState;
153
- readonly _Proxy: TProxy;
154
- readonly _TDefined: TDefined;
155
- readonly _THasDefault: THasDefault;
156
- readonly _internal: PrimitiveInternal<TState, TProxy>;
157
- }
158
- /**
159
- * Internal operations that each primitive must provide.
160
- */
161
- interface PrimitiveInternal<TState, TProxy> {
162
- /** Creates a proxy for generating operations */
163
- readonly createProxy: (env: ProxyEnvironment, path: OperationPath) => TProxy;
164
- /** Applies an operation to the current state, returning the new state */
165
- readonly applyOperation: (state: TState | undefined, operation: Operation<any, any, any>) => TState;
166
- /** Returns the initial/default state for this primitive */
167
- readonly getInitialState: () => TState | undefined;
168
- /**
169
- * Transforms a client operation against a server operation.
170
- * Used for operational transformation (OT) conflict resolution.
171
- *
172
- * @param clientOp - The client's operation to transform
173
- * @param serverOp - The server's operation that has already been applied
174
- * @returns TransformResult indicating how the client operation should be handled
175
- */
176
- readonly transformOperation: (clientOp: Operation<any, any, any>, serverOp: Operation<any, any, any>) => TransformResult;
177
- }
178
- /**
179
- * Any primitive type - used for generic constraints.
180
- */
181
- type AnyPrimitive = Primitive<any, any, any, any>;
182
- /**
183
- * Infer the state type from a primitive.
184
- */
185
- type InferState<T> = T extends Primitive<infer S, any, any, any> ? S : never;
186
- /**
187
- * Infer the proxy type from a primitive.
188
- */
189
- type InferProxy<T> = T extends Primitive<any, infer P, any, any> ? P : never;
190
- /**
191
- * Helper type to conditionally add undefined based on TDefined.
192
- * When TDefined is true, the value is guaranteed to be defined (via required() or default()).
193
- * When TDefined is false, the value may be undefined.
194
- */
195
- type MaybeUndefined<T, TDefined extends boolean> = TDefined extends true ? T : T | undefined;
196
- /**
197
- * Infer the snapshot type from a primitive.
198
- * The snapshot is a readonly, type-safe structure suitable for rendering.
199
- */
200
- type InferSnapshot<T> = T extends Primitive<any, infer P, any, any> ? P extends {
201
- toSnapshot(): infer S;
202
- } ? S : never : never;
203
- /**
204
- * Extract THasDefault from a primitive.
205
- */
206
- type HasDefault<T> = T extends Primitive<any, any, any, infer H> ? H : false;
207
- /**
208
- * Extract TDefined from a primitive.
209
- */
210
- type IsDefined<T> = T extends Primitive<any, any, infer D, any> ? D : false;
211
- /**
212
- * Determines if a field is required for set() operations.
213
- * A field is required if: TDefined is true AND THasDefault is false
214
- */
215
- type IsRequiredForSet<T> = T extends Primitive<any, any, true, false> ? true : false;
216
- /**
217
- * Extract keys of fields that are required for set() (required without default).
218
- */
219
- type RequiredSetKeys<TFields$1 extends Record<string, AnyPrimitive>> = { [K in keyof TFields$1]: IsRequiredForSet<TFields$1[K]> extends true ? K : never }[keyof TFields$1];
220
- /**
221
- * Extract keys of fields that are optional for set() (has default OR not required).
222
- */
223
- type OptionalSetKeys<TFields$1 extends Record<string, AnyPrimitive>> = { [K in keyof TFields$1]: IsRequiredForSet<TFields$1[K]> extends true ? never : K }[keyof TFields$1];
224
- /**
225
- * Compute the input type for set() operations on a struct.
226
- * Required fields (required without default) must be provided.
227
- * Optional fields (has default or not required) can be omitted.
228
- */
229
- type StructSetInput<TFields$1 extends Record<string, AnyPrimitive>> = { readonly [K in RequiredSetKeys<TFields$1>]: InferState<TFields$1[K]> } & { readonly [K in OptionalSetKeys<TFields$1>]?: InferState<TFields$1[K]> };
230
- declare class ValidationError extends Error {
231
- readonly _tag = "ValidationError";
232
- constructor(message: string);
233
- }
234
- /**
235
- * A validator that checks a value and returns whether it's valid.
236
- */
237
- interface Validator<T> {
238
- readonly validate: (value: T) => boolean;
239
- readonly message: string;
240
- }
241
- /**
242
- * Runs all validators against a value, throwing ValidationError if any fail.
243
- */
244
- declare function runValidators<T>(value: T, validators: readonly {
245
- validate: (value: T) => boolean;
246
- message: string;
247
- }[]): void;
248
- /**
249
- * Checks if an operation is compatible with the given operation definitions.
250
- * @param operation - The operation to check.
251
- * @param operationDefinitions - The operation definitions to check against.
252
- * @returns True if the operation is compatible, false otherwise.
253
- */
254
- declare function isCompatibleOperation(operation: Operation<any, any, any>, operationDefinitions: Record<string, OperationDefinition<any, any, any>>): boolean;
255
- /**
256
- * Applies default values to a partial input, recursively handling nested structs.
257
- *
258
- * Uses a two-layer approach:
259
- * 1. First, get the struct's initial state (which includes struct-level defaults)
260
- * 2. Then, layer the provided values on top
261
- * 3. Finally, ensure nested structs are recursively processed
262
- *
263
- * @param primitive - The primitive definition containing field information
264
- * @param value - The partial value provided by the user
265
- * @returns The value with defaults applied for missing fields
266
- */
267
- declare function applyDefaults<T extends AnyPrimitive>(primitive: T, value: Partial<InferState<T>>): InferState<T>;
268
- //#endregion
269
- //#region src/primitives/String.d.ts
270
- interface StringProxy<TDefined extends boolean = false> {
271
- /** Gets the current string value */
272
- get(): MaybeUndefined<string, TDefined>;
273
- /** Sets the string value, generating a string.set operation */
274
- set(value: string): void;
275
- /** Returns a readonly snapshot of the string value for rendering */
276
- toSnapshot(): MaybeUndefined<string, TDefined>;
277
- }
278
- interface StringPrimitiveSchema {
279
- readonly required: boolean;
280
- readonly defaultValue: string | undefined;
281
- readonly validators: readonly Validator<string>[];
282
- }
283
- declare class StringPrimitive<TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<string, StringProxy<TDefined>, TDefined, THasDefault> {
284
- readonly _tag: "StringPrimitive";
285
- readonly _State: string;
286
- readonly _Proxy: StringProxy<TDefined>;
287
- readonly _TDefined: TDefined;
288
- readonly _THasDefault: THasDefault;
289
- private readonly _schema;
290
- private readonly _opDefinitions;
291
- constructor(schema: StringPrimitiveSchema);
292
- /** Mark this string as required */
293
- required(): StringPrimitive<true, THasDefault>;
294
- /** Set a default value for this string */
295
- default(defaultValue: string): StringPrimitive<true, true>;
296
- /** Add a custom validation rule */
297
- refine(fn: (value: string) => boolean, message: string): StringPrimitive<TDefined, THasDefault>;
298
- /** Minimum string length */
299
- min(length: number): StringPrimitive<TDefined, THasDefault>;
300
- /** Maximum string length */
301
- max(length: number): StringPrimitive<TDefined, THasDefault>;
302
- /** Exact string length */
303
- length(exact: number): StringPrimitive<TDefined, THasDefault>;
304
- /** Match a regex pattern */
305
- regex(pattern: RegExp, message?: string): StringPrimitive<TDefined, THasDefault>;
306
- /** Validate as email format */
307
- email(): StringPrimitive<TDefined, THasDefault>;
308
- /** Validate as URL format */
309
- url(): StringPrimitive<TDefined, THasDefault>;
310
- readonly _internal: PrimitiveInternal<string, StringProxy<TDefined>>;
311
- }
312
- /** Creates a new StringPrimitive */
313
- declare const String: () => StringPrimitive<false, false>;
314
- //#endregion
315
- //#region src/primitives/Struct.d.ts
316
- /**
317
- * Maps a schema definition to its state type.
318
- * { name: StringPrimitive, age: NumberPrimitive } -> { name: string, age: number }
319
- */
320
- type InferStructState<TFields$1 extends Record<string, AnyPrimitive>> = { readonly [K in keyof TFields$1]: InferState<TFields$1[K]> };
321
- /**
322
- * Maps a schema definition to its snapshot type.
323
- * Each field's snapshot type is inferred from the field primitive.
324
- */
325
- type InferStructSnapshot<TFields$1 extends Record<string, AnyPrimitive>> = { readonly [K in keyof TFields$1]: InferSnapshot<TFields$1[K]> };
326
- /**
327
- * Maps a schema definition to a partial update type.
328
- * For nested structs, allows recursive partial updates.
329
- */
330
- type StructUpdateValue<TFields$1 extends Record<string, AnyPrimitive>> = { readonly [K in keyof TFields$1]?: TFields$1[K] extends StructPrimitive<infer F, any> ? StructUpdateValue<F> | InferState<TFields$1[K]> : InferState<TFields$1[K]> };
331
- /**
332
- * Maps a schema definition to its proxy type.
333
- * Provides nested field access + get()/set()/toSnapshot() methods for the whole struct.
334
- */
335
- type StructProxy<TFields$1 extends Record<string, AnyPrimitive>, TDefined extends boolean = false> = { readonly [K in keyof TFields$1]: InferProxy<TFields$1[K]> } & {
336
- /** Gets the entire struct value */
337
- get(): MaybeUndefined<InferStructState<TFields$1>, TDefined>;
338
- /** Sets the entire struct value (only fields that are required without defaults must be provided) */
339
- set(value: StructSetInput<TFields$1>): void;
340
- /** Updates only the specified fields (partial update, handles nested structs recursively) */
341
- update(value: StructUpdateValue<TFields$1>): void;
342
- /** Returns a readonly snapshot of the struct for rendering */
343
- toSnapshot(): MaybeUndefined<InferStructSnapshot<TFields$1>, TDefined>;
344
- };
345
- interface StructPrimitiveSchema<TFields$1 extends Record<string, AnyPrimitive>> {
346
- readonly required: boolean;
347
- readonly defaultValue: InferStructState<TFields$1> | undefined;
348
- readonly fields: TFields$1;
349
- readonly validators: readonly Validator<InferStructState<TFields$1>>[];
350
- }
351
- declare class StructPrimitive<TFields$1 extends Record<string, AnyPrimitive>, TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<InferStructState<TFields$1>, StructProxy<TFields$1, TDefined>, TDefined, THasDefault> {
352
- readonly _tag: "StructPrimitive";
353
- readonly _State: InferStructState<TFields$1>;
354
- readonly _Proxy: StructProxy<TFields$1, TDefined>;
355
- readonly _TDefined: TDefined;
356
- readonly _THasDefault: THasDefault;
357
- private readonly _schema;
358
- private readonly _opDefinitions;
359
- constructor(schema: StructPrimitiveSchema<TFields$1>);
360
- /** Mark this struct as required */
361
- required(): StructPrimitive<TFields$1, true, THasDefault>;
362
- /** Set a default value for this struct */
363
- default(defaultValue: StructSetInput<TFields$1>): StructPrimitive<TFields$1, true, true>;
364
- /** Get the fields schema */
365
- get fields(): TFields$1;
366
- /** Add a custom validation rule (useful for cross-field validation) */
367
- refine(fn: (value: InferStructState<TFields$1>) => boolean, message: string): StructPrimitive<TFields$1, TDefined, THasDefault>;
368
- readonly _internal: PrimitiveInternal<InferStructState<TFields$1>, StructProxy<TFields$1, TDefined>>;
369
- }
370
- /** Creates a new StructPrimitive with the given fields */
371
- declare const Struct: <TFields$1 extends Record<string, AnyPrimitive>>(fields: TFields$1) => StructPrimitive<TFields$1, false, false>;
372
- //#endregion
373
- //#region src/primitives/Boolean.d.ts
374
- interface BooleanProxy<TDefined extends boolean = false> {
375
- /** Gets the current boolean value */
376
- get(): MaybeUndefined<boolean, TDefined>;
377
- /** Sets the boolean value, generating a boolean.set operation */
378
- set(value: boolean): void;
379
- /** Returns a readonly snapshot of the boolean value for rendering */
380
- toSnapshot(): MaybeUndefined<boolean, TDefined>;
381
- }
382
- interface BooleanPrimitiveSchema {
383
- readonly required: boolean;
384
- readonly defaultValue: boolean | undefined;
385
- readonly validators: readonly Validator<boolean>[];
386
- }
387
- declare class BooleanPrimitive<TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<boolean, BooleanProxy<TDefined>, TDefined, THasDefault> {
388
- readonly _tag: "BooleanPrimitive";
389
- readonly _State: boolean;
390
- readonly _Proxy: BooleanProxy<TDefined>;
391
- readonly _TDefined: TDefined;
392
- readonly _THasDefault: THasDefault;
393
- private readonly _schema;
394
- private readonly _opDefinitions;
395
- constructor(schema: BooleanPrimitiveSchema);
396
- /** Mark this boolean as required */
397
- required(): BooleanPrimitive<true, THasDefault>;
398
- /** Set a default value for this boolean */
399
- default(defaultValue: boolean): BooleanPrimitive<true, true>;
400
- /** Add a custom validation rule */
401
- refine(fn: (value: boolean) => boolean, message: string): BooleanPrimitive<TDefined, THasDefault>;
402
- readonly _internal: PrimitiveInternal<boolean, BooleanProxy<TDefined>>;
403
- }
404
- /** Creates a new BooleanPrimitive */
405
- declare const Boolean: () => BooleanPrimitive<false, false>;
406
- //#endregion
407
- //#region src/primitives/Number.d.ts
408
- interface NumberProxy<TDefined extends boolean = false> {
409
- /** Gets the current number value */
410
- get(): MaybeUndefined<number, TDefined>;
411
- /** Sets the number value, generating a number.set operation */
412
- set(value: number): void;
413
- /** Returns a readonly snapshot of the number value for rendering */
414
- toSnapshot(): MaybeUndefined<number, TDefined>;
415
- }
416
- interface NumberPrimitiveSchema {
417
- readonly required: boolean;
418
- readonly defaultValue: number | undefined;
419
- readonly validators: readonly Validator<number>[];
420
- }
421
- declare class NumberPrimitive<TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<number, NumberProxy<TDefined>, TDefined, THasDefault> {
422
- readonly _tag: "NumberPrimitive";
423
- readonly _State: number;
424
- readonly _Proxy: NumberProxy<TDefined>;
425
- readonly _TDefined: TDefined;
426
- readonly _THasDefault: THasDefault;
427
- private readonly _schema;
428
- private readonly _opDefinitions;
429
- constructor(schema: NumberPrimitiveSchema);
430
- /** Mark this number as required */
431
- required(): NumberPrimitive<true, THasDefault>;
432
- /** Set a default value for this number */
433
- default(defaultValue: number): NumberPrimitive<true, true>;
434
- /** Add a custom validation rule */
435
- refine(fn: (value: number) => boolean, message: string): NumberPrimitive<TDefined, THasDefault>;
436
- /** Minimum value (inclusive) */
437
- min(value: number): NumberPrimitive<TDefined, THasDefault>;
438
- /** Maximum value (inclusive) */
439
- max(value: number): NumberPrimitive<TDefined, THasDefault>;
440
- /** Must be positive (> 0) */
441
- positive(): NumberPrimitive<TDefined, THasDefault>;
442
- /** Must be negative (< 0) */
443
- negative(): NumberPrimitive<TDefined, THasDefault>;
444
- /** Must be an integer */
445
- int(): NumberPrimitive<TDefined, THasDefault>;
446
- readonly _internal: PrimitiveInternal<number, NumberProxy<TDefined>>;
447
- }
448
- /** Creates a new NumberPrimitive */
449
- declare const Number: () => NumberPrimitive<false, false>;
450
- //#endregion
451
- //#region src/primitives/Literal.d.ts
452
- /** Valid literal types */
453
- type LiteralValue = string | number | boolean | null;
454
- interface LiteralProxy<T extends LiteralValue, TDefined extends boolean = false> {
455
- /** Gets the current literal value */
456
- get(): MaybeUndefined<T, TDefined>;
457
- /** Sets the literal value (must match the exact literal type) */
458
- set(value: T): void;
459
- /** Returns a readonly snapshot of the literal value for rendering */
460
- toSnapshot(): MaybeUndefined<T, TDefined>;
461
- }
462
- interface LiteralPrimitiveSchema<T extends LiteralValue> {
463
- readonly required: boolean;
464
- readonly defaultValue: T | undefined;
465
- readonly literal: T;
466
- }
467
- declare class LiteralPrimitive<T extends LiteralValue, TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<T, LiteralProxy<T, TDefined>, TDefined, THasDefault> {
468
- readonly _tag: "LiteralPrimitive";
469
- readonly _State: T;
470
- readonly _Proxy: LiteralProxy<T, TDefined>;
471
- readonly _TDefined: TDefined;
472
- readonly _THasDefault: THasDefault;
473
- private readonly _schema;
474
- private readonly _opDefinitions;
475
- constructor(schema: LiteralPrimitiveSchema<T>);
476
- /** Mark this literal as required */
477
- required(): LiteralPrimitive<T, true, THasDefault>;
478
- /** Set a default value for this literal */
479
- default(defaultValue: T): LiteralPrimitive<T, true, true>;
480
- /** Get the literal value this primitive represents */
481
- get literal(): T;
482
- readonly _internal: PrimitiveInternal<T, LiteralProxy<T, TDefined>>;
483
- }
484
- /** Creates a new LiteralPrimitive with the given literal value */
485
- declare const Literal: <T extends LiteralValue>(literal: T) => LiteralPrimitive<T, false, false>;
486
- //#endregion
487
- //#region src/primitives/Array.d.ts
488
- /**
489
- * Entry in an ordered array with ID and fractional position
490
- */
491
- interface ArrayEntry<T> {
492
- readonly id: string;
493
- readonly pos: string;
494
- readonly value: T;
495
- }
496
- /**
497
- * Entry in an array snapshot with ID and value snapshot
498
- */
499
- interface ArrayEntrySnapshot<TElement extends AnyPrimitive> {
500
- readonly id: string;
501
- readonly value: InferSnapshot<TElement>;
502
- }
503
- /**
504
- * Snapshot type for arrays - always an array (never undefined)
505
- */
506
- type ArraySnapshot<TElement extends AnyPrimitive> = readonly ArrayEntrySnapshot<TElement>[];
507
- /**
508
- * Compute the input type for array element values.
509
- * If the element is a struct, uses StructSetInput (partial with defaults).
510
- * Otherwise uses the full state type.
511
- */
512
- type ArrayElementSetInput<TElement extends AnyPrimitive> = TElement extends StructPrimitive<infer TFields, any, any> ? StructSetInput<TFields> : InferState<TElement>;
513
- interface ArrayProxy<TElement extends AnyPrimitive> {
514
- /** Gets the current array entries (sorted by position) */
515
- get(): ArrayState<TElement>;
516
- /** Replaces the entire array with new values (generates new IDs and positions, applies defaults) */
517
- set(values: readonly ArrayElementSetInput<TElement>[]): void;
518
- /** Appends a value to the end of the array (applies defaults for struct elements) */
519
- push(value: ArrayElementSetInput<TElement>): void;
520
- /** Inserts a value at the specified visual index (applies defaults for struct elements) */
521
- insertAt(index: number, value: ArrayElementSetInput<TElement>): void;
522
- /** Removes the element with the specified ID */
523
- remove(id: string): void;
524
- /** Moves an element to a new visual index */
525
- move(id: string, toIndex: number): void;
526
- /** Returns a proxy for the element with the specified ID */
527
- at(id: string): InferProxy<TElement>;
528
- /** Finds an element by predicate and returns its proxy */
529
- find(predicate: (value: InferState<TElement>, id: string) => boolean): InferProxy<TElement> | undefined;
530
- /** Returns a readonly snapshot of the array for rendering (always returns an array, never undefined) */
531
- toSnapshot(): ArraySnapshot<TElement>;
532
- }
533
- /** The state type for arrays - an array of entries */
534
- type ArrayState<TElement extends AnyPrimitive> = readonly ArrayEntry<InferState<TElement>>[];
535
- interface ArrayPrimitiveSchema<TElement extends AnyPrimitive> {
536
- readonly required: boolean;
537
- readonly defaultValue: ArrayState<TElement> | undefined;
538
- readonly element: TElement;
539
- readonly validators: readonly Validator<ArrayState<TElement>>[];
540
- }
541
- declare class ArrayPrimitive<TElement extends AnyPrimitive, TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<ArrayState<TElement>, ArrayProxy<TElement>, TDefined, THasDefault> {
542
- readonly _tag: "ArrayPrimitive";
543
- readonly _State: ArrayState<TElement>;
544
- readonly _Proxy: ArrayProxy<TElement>;
545
- readonly _TDefined: TDefined;
546
- readonly _THasDefault: THasDefault;
547
- private readonly _schema;
548
- private readonly _opDefinitions;
549
- constructor(schema: ArrayPrimitiveSchema<TElement>);
550
- /** Mark this array as required */
551
- required(): ArrayPrimitive<TElement, true, THasDefault>;
552
- /** Set a default value for this array */
553
- default(defaultValue: ArrayState<TElement>): ArrayPrimitive<TElement, true, true>;
554
- /** Get the element primitive */
555
- get element(): TElement;
556
- /** Add a custom validation rule */
557
- refine(fn: (value: ArrayState<TElement>) => boolean, message: string): ArrayPrimitive<TElement, TDefined, THasDefault>;
558
- /** Minimum array length */
559
- minLength(length: number): ArrayPrimitive<TElement, TDefined, THasDefault>;
560
- /** Maximum array length */
561
- maxLength(length: number): ArrayPrimitive<TElement, TDefined, THasDefault>;
562
- readonly _internal: PrimitiveInternal<ArrayState<TElement>, ArrayProxy<TElement>>;
563
- }
564
- /** Creates a new ArrayPrimitive with the given element type */
565
- declare const Array$1: <TElement extends AnyPrimitive>(element: TElement) => ArrayPrimitive<TElement, false, false>;
566
- //#endregion
567
- //#region src/primitives/Lazy.d.ts
568
- /**
569
- * Type to infer state from a lazy thunk
570
- */
571
- type InferLazyState<T extends () => AnyPrimitive> = InferState<ReturnType<T>>;
572
- /**
573
- * Type to infer proxy from a lazy thunk
574
- */
575
- type InferLazyProxy<T extends () => AnyPrimitive> = InferProxy<ReturnType<T>>;
576
- /**
577
- * Type to infer snapshot from a lazy thunk
578
- */
579
- type InferLazySnapshot<T extends () => AnyPrimitive> = InferSnapshot<ReturnType<T>>;
580
- declare class LazyPrimitive<TThunk extends () => AnyPrimitive> implements Primitive<InferLazyState<TThunk>, InferLazyProxy<TThunk>> {
581
- readonly _tag: "LazyPrimitive";
582
- readonly _State: InferLazyState<TThunk>;
583
- readonly _Proxy: InferLazyProxy<TThunk>;
584
- private readonly _thunk;
585
- private _resolved;
586
- constructor(thunk: TThunk);
587
- /** Resolve and cache the lazy primitive */
588
- private _resolve;
589
- /** Mark this lazy primitive as required (delegates to resolved) */
590
- required(): LazyPrimitive<TThunk>;
591
- readonly _internal: PrimitiveInternal<InferLazyState<TThunk>, InferLazyProxy<TThunk>>;
592
- }
593
- /** Creates a new LazyPrimitive with the given thunk */
594
- declare const Lazy: <TThunk extends () => AnyPrimitive>(thunk: TThunk) => LazyPrimitive<TThunk>;
595
- //#endregion
596
- //#region src/primitives/Union.d.ts
597
- /**
598
- * Type constraint for union variants - must be struct primitives
599
- */
600
- type UnionVariants = Record<string, StructPrimitive<any, any, any>>;
601
- /**
602
- * Infer the union state type from variants
603
- */
604
- type InferUnionState<TVariants extends UnionVariants> = { [K in keyof TVariants]: InferState<TVariants[K]> }[keyof TVariants];
605
- /**
606
- * Infer the union snapshot type from variants
607
- */
608
- type InferUnionSnapshot<TVariants extends UnionVariants> = { [K in keyof TVariants]: InferSnapshot<TVariants[K]> }[keyof TVariants];
609
- /**
610
- * Compute the input type for union.set() operations.
611
- * For each variant, uses StructSetInput to make fields with defaults optional.
612
- */
613
- type UnionSetInput<TVariants extends UnionVariants> = { [K in keyof TVariants]: TVariants[K] extends StructPrimitive<infer TFields, any, any> ? StructSetInput<TFields> : InferState<TVariants[K]> }[keyof TVariants];
614
- /**
615
- * Proxy for accessing union variants
616
- */
617
- interface UnionProxy<TVariants extends UnionVariants, _TDiscriminator extends string, TDefined extends boolean = false> {
618
- /** Gets the current union value */
619
- get(): MaybeUndefined<InferUnionState<TVariants>, TDefined>;
620
- /** Sets the entire union value (applies defaults for variant fields) */
621
- set(value: UnionSetInput<TVariants>): void;
622
- /** Access a specific variant's proxy (assumes the variant is active) */
623
- as<K$1 extends keyof TVariants>(variant: K$1): InferProxy<TVariants[K$1]>;
624
- /** Pattern match on the variant type */
625
- match<R>(handlers: { [K in keyof TVariants]: (proxy: InferProxy<TVariants[K$1]>) => R }): R | undefined;
626
- /** Returns a readonly snapshot of the union for rendering */
627
- toSnapshot(): MaybeUndefined<InferUnionSnapshot<TVariants>, TDefined>;
628
- }
629
- interface UnionPrimitiveSchema<TVariants extends UnionVariants, TDiscriminator extends string> {
630
- readonly required: boolean;
631
- readonly defaultValue: InferUnionState<TVariants> | undefined;
632
- readonly discriminator: TDiscriminator;
633
- readonly variants: TVariants;
634
- }
635
- declare class UnionPrimitive<TVariants extends UnionVariants, TDiscriminator extends string = "type", TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<InferUnionState<TVariants>, UnionProxy<TVariants, TDiscriminator, TDefined>, TDefined, THasDefault> {
636
- readonly _tag: "UnionPrimitive";
637
- readonly _State: InferUnionState<TVariants>;
638
- readonly _Proxy: UnionProxy<TVariants, TDiscriminator, TDefined>;
639
- readonly _TDefined: TDefined;
640
- readonly _THasDefault: THasDefault;
641
- private readonly _schema;
642
- private readonly _opDefinitions;
643
- constructor(schema: UnionPrimitiveSchema<TVariants, TDiscriminator>);
644
- /** Mark this union as required */
645
- required(): UnionPrimitive<TVariants, TDiscriminator, true, THasDefault>;
646
- /** Set a default value for this union */
647
- default(defaultValue: UnionSetInput<TVariants>): UnionPrimitive<TVariants, TDiscriminator, true, true>;
648
- /** Get the discriminator field name */
649
- get discriminator(): TDiscriminator;
650
- /** Get the variants */
651
- get variants(): TVariants;
652
- /** Find the variant key from a state value */
653
- private _findVariantKey;
654
- /** Apply defaults to a variant value based on the discriminator */
655
- private _applyVariantDefaults;
656
- readonly _internal: PrimitiveInternal<InferUnionState<TVariants>, UnionProxy<TVariants, TDiscriminator, TDefined>>;
657
- }
658
- /** Options for creating a Union primitive */
659
- interface UnionOptions<TVariants extends UnionVariants, TDiscriminator extends string> {
660
- /** The field name used to discriminate between variants (defaults to "type") */
661
- readonly discriminator?: TDiscriminator;
662
- /** The variant struct primitives */
663
- readonly variants: TVariants;
664
- }
665
- /** Creates a new UnionPrimitive with the given variants */
666
- declare function Union<TVariants extends UnionVariants>(options: UnionOptions<TVariants, "type">): UnionPrimitive<TVariants, "type", false, false>;
667
- declare function Union<TVariants extends UnionVariants, TDiscriminator extends string>(options: UnionOptions<TVariants, TDiscriminator>): UnionPrimitive<TVariants, TDiscriminator, false, false>;
668
- //#endregion
669
- //#region src/primitives/Either.d.ts
670
- /**
671
- * Scalar primitives that can be used as variants in Either
672
- */
673
- type ScalarPrimitive = StringPrimitive<any, any> | NumberPrimitive<any, any> | BooleanPrimitive<any, any> | LiteralPrimitive<any, any, any>;
674
- /**
675
- * Infer the union state type from a tuple of scalar primitives
676
- */
677
- type InferEitherState<TVariants extends readonly ScalarPrimitive[]> = InferState<TVariants[number]>;
678
- /**
679
- * Infer the union snapshot type from a tuple of scalar primitives
680
- */
681
- type InferEitherSnapshot<TVariants extends readonly ScalarPrimitive[]> = InferState<TVariants[number]>;
682
- /**
683
- * Match handlers for Either - optional handlers for each scalar type
684
- */
685
- interface EitherMatchHandlers<R> {
686
- string?: (value: string) => R;
687
- number?: (value: number) => R;
688
- boolean?: (value: boolean) => R;
689
- literal?: (value: LiteralValue) => R;
690
- }
691
- /**
692
- * Proxy for accessing Either values
693
- */
694
- interface EitherProxy<TVariants extends readonly ScalarPrimitive[], TDefined extends boolean = false> {
695
- /** Gets the current value */
696
- get(): MaybeUndefined<InferEitherState<TVariants>, TDefined>;
697
- /** Sets the value to any of the allowed variant types */
698
- set(value: InferEitherState<TVariants>): void;
699
- /** Pattern match on the value type */
700
- match<R>(handlers: EitherMatchHandlers<R>): R | undefined;
701
- /** Returns a readonly snapshot of the value for rendering */
702
- toSnapshot(): MaybeUndefined<InferEitherSnapshot<TVariants>, TDefined>;
703
- }
704
- interface EitherPrimitiveSchema<TVariants extends readonly ScalarPrimitive[]> {
705
- readonly required: boolean;
706
- readonly defaultValue: InferEitherState<TVariants> | undefined;
707
- readonly variants: TVariants;
708
- }
709
- declare class EitherPrimitive<TVariants extends readonly ScalarPrimitive[], TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<InferEitherState<TVariants>, EitherProxy<TVariants, TDefined>, TDefined, THasDefault> {
710
- readonly _tag: "EitherPrimitive";
711
- readonly _State: InferEitherState<TVariants>;
712
- readonly _Proxy: EitherProxy<TVariants, TDefined>;
713
- readonly _TDefined: TDefined;
714
- readonly _THasDefault: THasDefault;
715
- private readonly _schema;
716
- private readonly _opDefinitions;
717
- constructor(schema: EitherPrimitiveSchema<TVariants>);
718
- /** Mark this either as required */
719
- required(): EitherPrimitive<TVariants, true, THasDefault>;
720
- /** Set a default value for this either */
721
- default(defaultValue: InferEitherState<TVariants>): EitherPrimitive<TVariants, true, true>;
722
- /** Get the variants */
723
- get variants(): TVariants;
724
- /**
725
- * Determine the type category of a value based on the variants
726
- */
727
- private _getValueType;
728
- /**
729
- * Find the matching variant for a value.
730
- * For literals, matches exact value. For other types, matches by typeof.
731
- */
732
- private _findMatchingVariant;
733
- /**
734
- * Get the operation kind for a variant
735
- */
736
- private _getVariantOperationKind;
737
- /**
738
- * Validate a value against the matching variant, including running its validators.
739
- * Throws ValidationError if the value doesn't match any variant or fails validation.
740
- */
741
- private _validateAndApplyToVariant;
742
- readonly _internal: PrimitiveInternal<InferEitherState<TVariants>, EitherProxy<TVariants, TDefined>>;
743
- }
744
- /**
745
- * Creates a new EitherPrimitive with the given scalar variant types.
746
- * Validators defined on the variants are applied when validating values.
747
- *
748
- * @example
749
- * ```typescript
750
- * // String or number
751
- * const value = Either(String(), Number());
752
- *
753
- * // String, number, or boolean
754
- * const status = Either(String(), Number(), Boolean()).default("pending");
755
- *
756
- * // With literal types
757
- * const mode = Either(Literal("auto"), Literal("manual"), Number());
758
- *
759
- * // With validators - validates string length and number range
760
- * const constrained = Either(
761
- * String().min(2).max(50),
762
- * Number().max(255)
763
- * );
764
- * ```
765
- */
766
- declare function Either<TVariants extends readonly ScalarPrimitive[]>(...variants: TVariants): EitherPrimitive<TVariants, false, false>;
767
- //#endregion
768
- //#region src/primitives/TreeNode.d.ts
769
- /**
770
- * Branded type for TreeNodeSelf - distinguishable at compile time
771
- */
772
- declare const SelfBrand: unique symbol;
773
- interface TreeNodeSelfType {
774
- readonly _tag: "TreeNodeSelf";
775
- readonly _brand: typeof SelfBrand;
776
- }
777
- /**
778
- * Special placeholder for self-referential tree nodes.
779
- * Use this in the children array when a node type can contain itself.
780
- *
781
- * @example
782
- * ```typescript
783
- * const FolderNode = TreeNode("folder", {
784
- * data: Struct({ name: String() }),
785
- * children: [TreeNodeSelf], // Folder can contain other folders
786
- * });
787
- * ```
788
- */
789
- declare const TreeNodeSelf: TreeNodeSelfType;
790
- /**
791
- * Type utility to resolve Self placeholders to the actual node type
792
- */
793
- type ResolveSelf<T, TSelf extends AnyTreeNodePrimitive> = T extends TreeNodeSelfType ? TSelf : T;
794
- /**
795
- * Type utility to resolve all children in a tuple, replacing Self with the node type
796
- */
797
- type ResolveChildrenUnion<TChildren, TSelf extends AnyTreeNodePrimitive> = TChildren extends readonly (infer U)[] ? ResolveSelf<U, TSelf> : never;
798
- /**
799
- * The type for children - either a direct array or a lazy function (for self-referential nodes).
800
- */
801
- type TreeNodeChildrenInput = readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[] | (() => readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]);
802
- /**
803
- * Any TreeNodePrimitive type - used for generic constraints.
804
- */
805
- type AnyTreeNodePrimitive = TreeNodePrimitive<string, StructPrimitive<any>, any>;
806
- /**
807
- * Infer the data state type from a TreeNodePrimitive
808
- */
809
- type InferTreeNodeDataState<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<any, infer TData, any> ? InferState<TData> : never;
810
- /**
811
- * Infer the type literal from a TreeNodePrimitive
812
- */
813
- type InferTreeNodeType<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<infer TType, any, any> ? TType : never;
814
- /**
815
- * Infer the allowed children from a TreeNodePrimitive
816
- */
817
- type InferTreeNodeChildren<T> = T extends TreeNodePrimitive<any, any, infer TChildren> ? TChildren : never;
818
- /**
819
- * Configuration for a TreeNode primitive
820
- */
821
- interface TreeNodeConfig<TData$1 extends StructPrimitive<any>, TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]> {
822
- readonly data: TData$1;
823
- readonly children: TChildren | (() => TChildren);
824
- }
825
- /**
826
- * TreeNodePrimitive - defines a node type with its data schema and allowed children
827
- */
828
- declare class TreeNodePrimitive<TType extends string, TData$1 extends StructPrimitive<any>, TChildren extends AnyTreeNodePrimitive = AnyTreeNodePrimitive> {
829
- readonly _tag: "TreeNodePrimitive";
830
- readonly _Type: TType;
831
- readonly _Data: TData$1;
832
- readonly _Children: TChildren;
833
- private readonly _type;
834
- private readonly _data;
835
- private readonly _children;
836
- private _resolvedChildren;
837
- constructor(type: TType, config: TreeNodeConfig<TData$1, readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>);
838
- /** Get the node type identifier */
839
- get type(): TType;
840
- /** Get the data primitive */
841
- get data(): TData$1;
842
- /** Get resolved children (resolves lazy thunk if needed, replaces Self with this node) */
843
- get children(): readonly AnyTreeNodePrimitive[];
844
- /** Check if a child type is allowed */
845
- isChildAllowed(childType: string): boolean;
846
- }
847
- /** Creates a new TreeNodePrimitive with the given type and config */
848
- declare const TreeNode: <TType extends string, TData$1 extends StructPrimitive<any>, const TChildren extends readonly (AnyTreeNodePrimitive | TreeNodeSelfType)[]>(type: TType, config: TreeNodeConfig<TData$1, TChildren>) => TreeNodePrimitive<TType, TData$1, ResolveChildrenUnion<TChildren, TreeNodePrimitive<TType, TData$1, any>>>;
849
- //#endregion
850
- //#region src/primitives/Tree.d.ts
851
- /**
852
- * A node in the tree state (flat storage format)
853
- */
854
- interface TreeNodeState {
855
- readonly id: string;
856
- readonly type: string;
857
- readonly parentId: string | null;
858
- readonly pos: string;
859
- readonly data: unknown;
860
- }
861
- /**
862
- * Typed node state for a specific node type
863
- */
864
- interface TypedTreeNodeState<TNode extends AnyTreeNodePrimitive> {
865
- readonly id: string;
866
- readonly type: InferTreeNodeType<TNode>;
867
- readonly parentId: string | null;
868
- readonly pos: string;
869
- readonly data: InferTreeNodeDataState<TNode>;
870
- }
871
- /**
872
- * The state type for trees - a flat array of nodes
873
- */
874
- type TreeState<_TRoot extends AnyTreeNodePrimitive> = readonly TreeNodeState[];
875
- /**
876
- * Snapshot of a single node for UI rendering (data properties spread at node level)
877
- */
878
- type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {
879
- readonly id: string;
880
- readonly type: InferTreeNodeType<TNode>;
881
- readonly children: TreeNodeSnapshot<InferTreeNodeChildren<TNode>>[];
882
- } & InferTreeNodeDataState<TNode>;
883
- /**
884
- * Infer the snapshot type for a tree (recursive tree structure for UI)
885
- */
886
- type InferTreeSnapshot<T extends TreePrimitive<any>> = T extends TreePrimitive<infer TRoot> ? TreeNodeSnapshot<TRoot> : never;
887
- /**
888
- * Helper type to infer the update value type from a TreeNode's data
889
- */
890
- type TreeNodeUpdateValue<TNode extends AnyTreeNodePrimitive> = TNode["data"] extends StructPrimitive<infer TFields, any, any> ? StructUpdateValue<TFields> : never;
891
- /**
892
- * Helper type to infer the input type for node data (with defaults applied).
893
- * Uses StructSetInput for struct data, making fields with defaults optional.
894
- */
895
- type TreeNodeDataSetInput<TNode extends AnyTreeNodePrimitive> = TNode["data"] extends StructPrimitive<infer TFields, any, any> ? StructSetInput<TFields> : InferTreeNodeDataState<TNode>;
896
- /**
897
- * Typed proxy for a specific node type - provides type-safe data access
898
- */
899
- interface TypedNodeProxy<TNode extends AnyTreeNodePrimitive> {
900
- /** The node ID */
901
- readonly id: string;
902
- /** The node type */
903
- readonly type: InferTreeNodeType<TNode>;
904
- /** Access the node's data proxy */
905
- readonly data: InferProxy<TNode["data"]>;
906
- /** Get the raw node state */
907
- get(): TypedTreeNodeState<TNode>;
908
- /** Updates only the specified data fields (partial update, handles nested structs recursively) */
909
- update(value: TreeNodeUpdateValue<TNode>): void;
910
- }
911
- /**
912
- * Node proxy with type narrowing capabilities
913
- */
914
- interface TreeNodeProxyBase<_TRoot extends AnyTreeNodePrimitive> {
915
- /** The node ID */
916
- readonly id: string;
917
- /** The node type (string) */
918
- readonly type: string;
919
- /** Type guard - narrows the proxy to a specific node type */
920
- is<TNode extends AnyTreeNodePrimitive>(nodeType: TNode): this is TypedNodeProxy<TNode>;
921
- /** Type assertion - returns typed proxy (throws if wrong type) */
922
- as<TNode extends AnyTreeNodePrimitive>(nodeType: TNode): TypedNodeProxy<TNode>;
923
- /** Get the raw node state */
924
- get(): TreeNodeState;
925
- }
926
- /**
927
- * Proxy for accessing and modifying tree nodes
928
- */
929
- interface TreeProxy<TRoot$1 extends AnyTreeNodePrimitive> {
930
- /** Gets the entire tree state (flat array of nodes) */
931
- get(): TreeState<TRoot$1>;
932
- /** Replaces the entire tree */
933
- set(nodes: TreeState<TRoot$1>): void;
934
- /** Gets the root node state */
935
- root(): TypedTreeNodeState<TRoot$1> | undefined;
936
- /** Gets ordered children states of a parent (null for root's children) */
937
- children(parentId: string | null): TreeNodeState[];
938
- /** Gets a node proxy by ID with type narrowing capabilities */
939
- node(id: string): TreeNodeProxyBase<TRoot$1> | undefined;
940
- /** Insert a new node as the first child (applies defaults for node data) */
941
- insertFirst<TNode extends AnyTreeNodePrimitive>(parentId: string | null, nodeType: TNode, data: TreeNodeDataSetInput<TNode>): string;
942
- /** Insert a new node as the last child (applies defaults for node data) */
943
- insertLast<TNode extends AnyTreeNodePrimitive>(parentId: string | null, nodeType: TNode, data: TreeNodeDataSetInput<TNode>): string;
944
- /** Insert a new node at a specific index among siblings (applies defaults for node data) */
945
- insertAt<TNode extends AnyTreeNodePrimitive>(parentId: string | null, index: number, nodeType: TNode, data: TreeNodeDataSetInput<TNode>): string;
946
- /** Insert a new node after a sibling (applies defaults for node data) */
947
- insertAfter<TNode extends AnyTreeNodePrimitive>(siblingId: string, nodeType: TNode, data: TreeNodeDataSetInput<TNode>): string;
948
- /** Insert a new node before a sibling (applies defaults for node data) */
949
- insertBefore<TNode extends AnyTreeNodePrimitive>(siblingId: string, nodeType: TNode, data: TreeNodeDataSetInput<TNode>): string;
950
- /** Remove a node and all its descendants */
951
- remove(id: string): void;
952
- /** Move a node to a new parent at a specific index */
953
- move(nodeId: string, newParentId: string | null, toIndex: number): void;
954
- /** Move a node after a sibling */
955
- moveAfter(nodeId: string, siblingId: string): void;
956
- /** Move a node before a sibling */
957
- moveBefore(nodeId: string, siblingId: string): void;
958
- /** Move a node to be the first child of a parent */
959
- moveToFirst(nodeId: string, newParentId: string | null): void;
960
- /** Move a node to be the last child of a parent */
961
- moveToLast(nodeId: string, newParentId: string | null): void;
962
- /** Returns a typed proxy for a specific node's data */
963
- at<TNode extends AnyTreeNodePrimitive>(id: string, nodeType: TNode): InferProxy<TNode["data"]>;
964
- /** Updates only the specified data fields of a node (partial update) */
965
- updateAt<TNode extends AnyTreeNodePrimitive>(id: string, nodeType: TNode, value: TreeNodeUpdateValue<TNode>): void;
966
- /** Convert tree to a nested snapshot for UI rendering */
967
- toSnapshot(): TreeNodeSnapshot<TRoot$1> | undefined;
968
- }
969
- interface TreePrimitiveSchema<TRoot$1 extends AnyTreeNodePrimitive> {
970
- readonly required: boolean;
971
- readonly defaultValue: TreeState<TRoot$1> | undefined;
972
- readonly root: TRoot$1;
973
- readonly validators: readonly Validator<TreeState<TRoot$1>>[];
974
- }
975
- declare class TreePrimitive<TRoot$1 extends AnyTreeNodePrimitive, TDefined extends boolean = false, THasDefault extends boolean = false> implements Primitive<TreeState<TRoot$1>, TreeProxy<TRoot$1>, TDefined, THasDefault> {
976
- readonly _tag: "TreePrimitive";
977
- readonly _State: TreeState<TRoot$1>;
978
- readonly _Proxy: TreeProxy<TRoot$1>;
979
- readonly _TDefined: TDefined;
980
- readonly _THasDefault: THasDefault;
981
- private readonly _schema;
982
- private _nodeTypeRegistry;
983
- private readonly _opDefinitions;
984
- constructor(schema: TreePrimitiveSchema<TRoot$1>);
985
- /** Mark this tree as required */
986
- required(): TreePrimitive<TRoot$1, true, THasDefault>;
987
- /** Set a default value for this tree */
988
- default(defaultValue: TreeState<TRoot$1>): TreePrimitive<TRoot$1, true, true>;
989
- /** Get the root node type */
990
- get root(): TRoot$1;
991
- /** Add a custom validation rule */
992
- refine(fn: (value: TreeState<TRoot$1>) => boolean, message: string): TreePrimitive<TRoot$1, TDefined, THasDefault>;
993
- /**
994
- * Build a registry of all node types reachable from root
995
- */
996
- private _buildNodeTypeRegistry;
997
- /**
998
- * Get a node type primitive by its type string
999
- */
1000
- private _getNodeTypePrimitive;
1001
- /**
1002
- * Validate that a node type can be a child of a parent node type
1003
- */
1004
- private _validateChildType;
1005
- readonly _internal: PrimitiveInternal<TreeState<TRoot$1>, TreeProxy<TRoot$1>>;
1006
- }
1007
- /** Options for creating a Tree primitive */
1008
- interface TreeOptions<TRoot$1 extends AnyTreeNodePrimitive> {
1009
- /** The root node type */
1010
- readonly root: TRoot$1;
1011
- }
1012
- /** Creates a new TreePrimitive with the given root node type */
1013
- declare const Tree: <TRoot$1 extends AnyTreeNodePrimitive>(options: TreeOptions<TRoot$1>) => TreePrimitive<TRoot$1, false, false>;
1014
- declare namespace Primitive_d_exports {
1015
- export { AnyPrimitive, AnyTreeNodePrimitive, Array$1 as Array, ArrayElementSetInput, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySnapshot, ArrayState, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, HasDefault, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySnapshot, InferLazyState, InferProxy, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, IsDefined, IsRequiredForSet, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MaybeUndefined, Number, NumberPrimitive, NumberProxy, OptionalSetKeys, Primitive, PrimitiveInternal, RequiredSetKeys, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, StructSetInput, StructUpdateValue, Tree, TreeNode, TreeNodeChildrenInput, TreeNodeConfig, TreeNodeDataSetInput, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSelf, TreeNodeSelfType, TreeNodeSnapshot, TreeNodeState, TreeNodeUpdateValue, TreeOptions, TreePrimitive, TreeProxy, TreeState, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionSetInput, UnionVariants, ValidationError, Validator, applyDefaults, isCompatibleOperation, runValidators };
1016
- }
1017
- declare namespace Transaction_d_exports {
1018
- export { EncodedTransaction, Transaction, decode, empty, encode, isEmpty, make$2 as make, merge };
1019
- }
1020
- /**
1021
- * A Transaction represents a group of operations that were applied atomically.
1022
- */
1023
- interface Transaction {
1024
- /** Unique identifier for this transaction */
1025
- readonly id: string;
1026
- /** Operations contained in this transaction */
1027
- readonly ops: ReadonlyArray<Operation<any, any, any>>;
1028
- /** Timestamp when the transaction was created */
1029
- readonly timestamp: number;
1030
- }
1031
- /**
1032
- * Creates a new Transaction with the given operations.
1033
- */
1034
- declare const make$2: (ops: ReadonlyArray<Operation<any, any, any>>) => Transaction;
1035
- /**
1036
- * Creates an empty Transaction.
1037
- */
1038
- declare const empty: () => Transaction;
1039
- /**
1040
- * Checks if a transaction is empty (has no operations).
1041
- */
1042
- declare const isEmpty: (tx: Transaction) => boolean;
1043
- /**
1044
- * Merges multiple transactions into one.
1045
- */
1046
- declare const merge: (txs: ReadonlyArray<Transaction>) => Transaction;
1047
- /**
1048
- * Encoded representation of a Transaction for network transport.
1049
- */
1050
- interface EncodedTransaction {
1051
- readonly id: string;
1052
- readonly ops: ReadonlyArray<EncodedOperation>;
1053
- readonly timestamp: number;
1054
- }
1055
- /**
1056
- * Encodes a Transaction to a JSON-serializable format for network transport.
1057
- * @param transaction - The transaction to encode.
1058
- * @returns The encoded representation.
1059
- */
1060
- declare const encode: (transaction: Transaction) => EncodedTransaction;
1061
- /**
1062
- * Decodes an encoded transaction back to a Transaction.
1063
- * @param encoded - The encoded representation.
1064
- * @returns The decoded Transaction.
1065
- */
1066
- declare const decode: (encoded: EncodedTransaction) => Transaction;
4
+ //#region src/Document.d.ts
1067
5
  declare namespace Document_d_exports {
1068
- export { Document, DocumentOptions, NestedTransactionError, OperationError, make$1 as make };
6
+ export { Document, DocumentOptions, NestedTransactionError, OperationError, make };
1069
7
  }
1070
8
  /**
1071
9
  * Error thrown when attempting to start a nested transaction.
@@ -1122,92 +60,7 @@ interface DocumentOptions<TSchema extends AnyPrimitive> {
1122
60
  /**
1123
61
  * Creates a new Document for the given schema.
1124
62
  */
1125
- declare const make$1: <TSchema extends AnyPrimitive>(schema: TSchema, options?: DocumentOptions<TSchema>) => Document<TSchema>;
1126
- declare namespace Presence_d_exports {
1127
- export { AnyPresence, Infer, Presence, PresenceEntry, PresenceOptions, isValid, make, validate, validateSafe };
1128
- }
1129
- /**
1130
- * A Presence schema wrapper that holds an Effect Schema for validation.
1131
- * This is used by both client and server to validate presence data.
1132
- */
1133
- interface Presence<TData$1> {
1134
- readonly _tag: "Presence";
1135
- /** The Effect Schema used for validation */
1136
- readonly schema: Schema$1.Schema<TData$1>;
1137
- /** Branded type marker for inference */
1138
- readonly _Data: TData$1;
1139
- }
1140
- /**
1141
- * Options for creating a Presence instance.
1142
- */
1143
- interface PresenceOptions<TData$1> {
1144
- /** The Effect Schema defining the presence data structure */
1145
- readonly schema: Schema$1.Schema<TData$1>;
1146
- }
1147
- /**
1148
- * Infer the data type from a Presence instance.
1149
- */
1150
- type Infer<P extends Presence<any>> = P["_Data"];
1151
- /**
1152
- * Any Presence type (for generic constraints).
1153
- */
1154
- type AnyPresence = Presence<any>;
1155
- /**
1156
- * A presence entry as stored/transmitted.
1157
- */
1158
- interface PresenceEntry<TData$1 = unknown> {
1159
- /** The presence data */
1160
- readonly data: TData$1;
1161
- /** Optional user ID from authentication */
1162
- readonly userId?: string;
1163
- }
1164
- /**
1165
- * Creates a new Presence schema wrapper.
1166
- *
1167
- * @example
1168
- * ```typescript
1169
- * import { Presence } from "@voidhash/mimic";
1170
- * import { Schema } from "effect";
1171
- *
1172
- * const CursorPresence = Presence.make({
1173
- * schema: Schema.Struct({
1174
- * name: Schema.String,
1175
- * cursor: Schema.Struct({
1176
- * x: Schema.Number,
1177
- * y: Schema.Number,
1178
- * }),
1179
- * }),
1180
- * });
1181
- * ```
1182
- */
1183
- declare const make: <TData$1>(options: PresenceOptions<TData$1>) => Presence<TData$1>;
1184
- /**
1185
- * Validates unknown data against a Presence schema.
1186
- * Throws a ParseError if validation fails.
1187
- *
1188
- * @param presence - The Presence instance with the schema
1189
- * @param data - Unknown data to validate
1190
- * @returns The validated and typed data
1191
- * @throws ParseError if validation fails
1192
- */
1193
- declare const validate: <TData$1>(presence: Presence<TData$1>, data: unknown) => TData$1;
1194
- /**
1195
- * Safely validates unknown data against a Presence schema.
1196
- * Returns undefined if validation fails instead of throwing.
1197
- *
1198
- * @param presence - The Presence instance with the schema
1199
- * @param data - Unknown data to validate
1200
- * @returns The validated data or undefined if invalid
1201
- */
1202
- declare const validateSafe: <TData$1>(presence: Presence<TData$1>, data: unknown) => TData$1 | undefined;
1203
- /**
1204
- * Checks if unknown data is valid according to a Presence schema.
1205
- *
1206
- * @param presence - The Presence instance with the schema
1207
- * @param data - Unknown data to check
1208
- * @returns true if valid, false otherwise
1209
- */
1210
- declare const isValid: <TData$1>(presence: Presence<TData$1>, data: unknown) => data is TData$1;
63
+ declare const make: <TSchema extends AnyPrimitive>(schema: TSchema, options?: DocumentOptions<TSchema>) => Document<TSchema>;
1211
64
  //#endregion
1212
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 };
1213
66
  //# sourceMappingURL=index.d.cts.map