@voidhash/mimic 0.0.1-alpha.1 → 0.0.1-alpha.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.
- package/.turbo/turbo-build.log +23 -0
- package/LICENSE.md +663 -0
- package/dist/chunk-C6wwvPpM.mjs +18 -0
- package/dist/index.cjs +2820 -0
- package/dist/index.d.cts +1086 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +1086 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2734 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -10
- package/src/Primitive.ts +3 -0
- package/src/primitives/Either.ts +364 -0
- package/tests/primitives/Either.test.ts +707 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1086 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import * as Schema$1 from "effect/Schema";
|
|
3
|
+
|
|
4
|
+
//#region src/OperationPath.d.ts
|
|
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
|
+
interface Primitive<TState, TProxy> {
|
|
146
|
+
readonly _tag: string;
|
|
147
|
+
readonly _State: TState;
|
|
148
|
+
readonly _Proxy: TProxy;
|
|
149
|
+
readonly _internal: PrimitiveInternal<TState, TProxy>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Internal operations that each primitive must provide.
|
|
153
|
+
*/
|
|
154
|
+
interface PrimitiveInternal<TState, TProxy> {
|
|
155
|
+
/** Creates a proxy for generating operations */
|
|
156
|
+
readonly createProxy: (env: ProxyEnvironment, path: OperationPath) => TProxy;
|
|
157
|
+
/** Applies an operation to the current state, returning the new state */
|
|
158
|
+
readonly applyOperation: (state: TState | undefined, operation: Operation<any, any, any>) => TState;
|
|
159
|
+
/** Returns the initial/default state for this primitive */
|
|
160
|
+
readonly getInitialState: () => TState | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Transforms a client operation against a server operation.
|
|
163
|
+
* Used for operational transformation (OT) conflict resolution.
|
|
164
|
+
*
|
|
165
|
+
* @param clientOp - The client's operation to transform
|
|
166
|
+
* @param serverOp - The server's operation that has already been applied
|
|
167
|
+
* @returns TransformResult indicating how the client operation should be handled
|
|
168
|
+
*/
|
|
169
|
+
readonly transformOperation: (clientOp: Operation<any, any, any>, serverOp: Operation<any, any, any>) => TransformResult;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Any primitive type - used for generic constraints.
|
|
173
|
+
*/
|
|
174
|
+
type AnyPrimitive = Primitive<any, any>;
|
|
175
|
+
/**
|
|
176
|
+
* Infer the state type from a primitive.
|
|
177
|
+
*/
|
|
178
|
+
type InferState<T> = T extends Primitive<infer S, any> ? S : never;
|
|
179
|
+
/**
|
|
180
|
+
* Infer the proxy type from a primitive.
|
|
181
|
+
*/
|
|
182
|
+
type InferProxy<T> = T extends Primitive<any, infer P> ? P : never;
|
|
183
|
+
/**
|
|
184
|
+
* Helper type to conditionally add undefined based on TDefined.
|
|
185
|
+
* When TDefined is true, the value is guaranteed to be defined (via required() or default()).
|
|
186
|
+
* When TDefined is false, the value may be undefined.
|
|
187
|
+
*/
|
|
188
|
+
type MaybeUndefined<T, TDefined extends boolean> = TDefined extends true ? T : T | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* Infer the snapshot type from a primitive.
|
|
191
|
+
* The snapshot is a readonly, type-safe structure suitable for rendering.
|
|
192
|
+
*/
|
|
193
|
+
type InferSnapshot<T> = T extends Primitive<any, infer P> ? P extends {
|
|
194
|
+
toSnapshot(): infer S;
|
|
195
|
+
} ? S : never : never;
|
|
196
|
+
declare class ValidationError extends Error {
|
|
197
|
+
readonly _tag = "ValidationError";
|
|
198
|
+
constructor(message: string);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* A validator that checks a value and returns whether it's valid.
|
|
202
|
+
*/
|
|
203
|
+
interface Validator<T> {
|
|
204
|
+
readonly validate: (value: T) => boolean;
|
|
205
|
+
readonly message: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Runs all validators against a value, throwing ValidationError if any fail.
|
|
209
|
+
*/
|
|
210
|
+
declare function runValidators<T>(value: T, validators: readonly {
|
|
211
|
+
validate: (value: T) => boolean;
|
|
212
|
+
message: string;
|
|
213
|
+
}[]): void;
|
|
214
|
+
/**
|
|
215
|
+
* Checks if an operation is compatible with the given operation definitions.
|
|
216
|
+
* @param operation - The operation to check.
|
|
217
|
+
* @param operationDefinitions - The operation definitions to check against.
|
|
218
|
+
* @returns True if the operation is compatible, false otherwise.
|
|
219
|
+
*/
|
|
220
|
+
declare function isCompatibleOperation(operation: Operation<any, any, any>, operationDefinitions: Record<string, OperationDefinition<any, any, any>>): boolean;
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/primitives/String.d.ts
|
|
223
|
+
interface StringProxy<TDefined extends boolean = false> {
|
|
224
|
+
/** Gets the current string value */
|
|
225
|
+
get(): MaybeUndefined<string, TDefined>;
|
|
226
|
+
/** Sets the string value, generating a string.set operation */
|
|
227
|
+
set(value: string): void;
|
|
228
|
+
/** Returns a readonly snapshot of the string value for rendering */
|
|
229
|
+
toSnapshot(): MaybeUndefined<string, TDefined>;
|
|
230
|
+
}
|
|
231
|
+
interface StringPrimitiveSchema {
|
|
232
|
+
readonly required: boolean;
|
|
233
|
+
readonly defaultValue: string | undefined;
|
|
234
|
+
readonly validators: readonly Validator<string>[];
|
|
235
|
+
}
|
|
236
|
+
declare class StringPrimitive<TDefined extends boolean = false> implements Primitive<string, StringProxy<TDefined>> {
|
|
237
|
+
readonly _tag: "StringPrimitive";
|
|
238
|
+
readonly _State: string;
|
|
239
|
+
readonly _Proxy: StringProxy<TDefined>;
|
|
240
|
+
private readonly _schema;
|
|
241
|
+
private readonly _opDefinitions;
|
|
242
|
+
constructor(schema: StringPrimitiveSchema);
|
|
243
|
+
/** Mark this string as required */
|
|
244
|
+
required(): StringPrimitive<true>;
|
|
245
|
+
/** Set a default value for this string */
|
|
246
|
+
default(defaultValue: string): StringPrimitive<true>;
|
|
247
|
+
/** Add a custom validation rule */
|
|
248
|
+
refine(fn: (value: string) => boolean, message: string): StringPrimitive<TDefined>;
|
|
249
|
+
/** Minimum string length */
|
|
250
|
+
min(length: number): StringPrimitive<TDefined>;
|
|
251
|
+
/** Maximum string length */
|
|
252
|
+
max(length: number): StringPrimitive<TDefined>;
|
|
253
|
+
/** Exact string length */
|
|
254
|
+
length(exact: number): StringPrimitive<TDefined>;
|
|
255
|
+
/** Match a regex pattern */
|
|
256
|
+
regex(pattern: RegExp, message?: string): StringPrimitive<TDefined>;
|
|
257
|
+
/** Validate as email format */
|
|
258
|
+
email(): StringPrimitive<TDefined>;
|
|
259
|
+
/** Validate as URL format */
|
|
260
|
+
url(): StringPrimitive<TDefined>;
|
|
261
|
+
readonly _internal: PrimitiveInternal<string, StringProxy<TDefined>>;
|
|
262
|
+
}
|
|
263
|
+
/** Creates a new StringPrimitive */
|
|
264
|
+
declare const String: () => StringPrimitive<false>;
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/primitives/Struct.d.ts
|
|
267
|
+
/**
|
|
268
|
+
* Maps a schema definition to its state type.
|
|
269
|
+
* { name: StringPrimitive, age: NumberPrimitive } -> { name: string, age: number }
|
|
270
|
+
*/
|
|
271
|
+
type InferStructState<TFields extends Record<string, AnyPrimitive>> = { readonly [K in keyof TFields]: InferState<TFields[K]> };
|
|
272
|
+
/**
|
|
273
|
+
* Maps a schema definition to its snapshot type.
|
|
274
|
+
* Each field's snapshot type is inferred from the field primitive.
|
|
275
|
+
*/
|
|
276
|
+
type InferStructSnapshot<TFields extends Record<string, AnyPrimitive>> = { readonly [K in keyof TFields]: InferSnapshot<TFields[K]> };
|
|
277
|
+
/**
|
|
278
|
+
* Maps a schema definition to its proxy type.
|
|
279
|
+
* Provides nested field access + get()/set()/toSnapshot() methods for the whole struct.
|
|
280
|
+
*/
|
|
281
|
+
type StructProxy<TFields extends Record<string, AnyPrimitive>, TDefined extends boolean = false> = { readonly [K in keyof TFields]: InferProxy<TFields[K]> } & {
|
|
282
|
+
/** Gets the entire struct value */
|
|
283
|
+
get(): MaybeUndefined<InferStructState<TFields>, TDefined>;
|
|
284
|
+
/** Sets the entire struct value */
|
|
285
|
+
set(value: InferStructState<TFields>): void;
|
|
286
|
+
/** Returns a readonly snapshot of the struct for rendering */
|
|
287
|
+
toSnapshot(): MaybeUndefined<InferStructSnapshot<TFields>, TDefined>;
|
|
288
|
+
};
|
|
289
|
+
interface StructPrimitiveSchema<TFields extends Record<string, AnyPrimitive>> {
|
|
290
|
+
readonly required: boolean;
|
|
291
|
+
readonly defaultValue: InferStructState<TFields> | undefined;
|
|
292
|
+
readonly fields: TFields;
|
|
293
|
+
readonly validators: readonly Validator<InferStructState<TFields>>[];
|
|
294
|
+
}
|
|
295
|
+
declare class StructPrimitive<TFields extends Record<string, AnyPrimitive>, TDefined extends boolean = false> implements Primitive<InferStructState<TFields>, StructProxy<TFields, TDefined>> {
|
|
296
|
+
readonly _tag: "StructPrimitive";
|
|
297
|
+
readonly _State: InferStructState<TFields>;
|
|
298
|
+
readonly _Proxy: StructProxy<TFields, TDefined>;
|
|
299
|
+
private readonly _schema;
|
|
300
|
+
private readonly _opDefinitions;
|
|
301
|
+
constructor(schema: StructPrimitiveSchema<TFields>);
|
|
302
|
+
/** Mark this struct as required */
|
|
303
|
+
required(): StructPrimitive<TFields, true>;
|
|
304
|
+
/** Set a default value for this struct */
|
|
305
|
+
default(defaultValue: InferStructState<TFields>): StructPrimitive<TFields, true>;
|
|
306
|
+
/** Get the fields schema */
|
|
307
|
+
get fields(): TFields;
|
|
308
|
+
/** Add a custom validation rule (useful for cross-field validation) */
|
|
309
|
+
refine(fn: (value: InferStructState<TFields>) => boolean, message: string): StructPrimitive<TFields, TDefined>;
|
|
310
|
+
readonly _internal: PrimitiveInternal<InferStructState<TFields>, StructProxy<TFields, TDefined>>;
|
|
311
|
+
}
|
|
312
|
+
/** Creates a new StructPrimitive with the given fields */
|
|
313
|
+
declare const Struct: <TFields extends Record<string, AnyPrimitive>>(fields: TFields) => StructPrimitive<TFields, false>;
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/primitives/Boolean.d.ts
|
|
316
|
+
interface BooleanProxy<TDefined extends boolean = false> {
|
|
317
|
+
/** Gets the current boolean value */
|
|
318
|
+
get(): MaybeUndefined<boolean, TDefined>;
|
|
319
|
+
/** Sets the boolean value, generating a boolean.set operation */
|
|
320
|
+
set(value: boolean): void;
|
|
321
|
+
/** Returns a readonly snapshot of the boolean value for rendering */
|
|
322
|
+
toSnapshot(): MaybeUndefined<boolean, TDefined>;
|
|
323
|
+
}
|
|
324
|
+
interface BooleanPrimitiveSchema {
|
|
325
|
+
readonly required: boolean;
|
|
326
|
+
readonly defaultValue: boolean | undefined;
|
|
327
|
+
readonly validators: readonly Validator<boolean>[];
|
|
328
|
+
}
|
|
329
|
+
declare class BooleanPrimitive<TDefined extends boolean = false> implements Primitive<boolean, BooleanProxy<TDefined>> {
|
|
330
|
+
readonly _tag: "BooleanPrimitive";
|
|
331
|
+
readonly _State: boolean;
|
|
332
|
+
readonly _Proxy: BooleanProxy<TDefined>;
|
|
333
|
+
private readonly _schema;
|
|
334
|
+
private readonly _opDefinitions;
|
|
335
|
+
constructor(schema: BooleanPrimitiveSchema);
|
|
336
|
+
/** Mark this boolean as required */
|
|
337
|
+
required(): BooleanPrimitive<true>;
|
|
338
|
+
/** Set a default value for this boolean */
|
|
339
|
+
default(defaultValue: boolean): BooleanPrimitive<true>;
|
|
340
|
+
/** Add a custom validation rule */
|
|
341
|
+
refine(fn: (value: boolean) => boolean, message: string): BooleanPrimitive<TDefined>;
|
|
342
|
+
readonly _internal: PrimitiveInternal<boolean, BooleanProxy<TDefined>>;
|
|
343
|
+
}
|
|
344
|
+
/** Creates a new BooleanPrimitive */
|
|
345
|
+
declare const Boolean: () => BooleanPrimitive<false>;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/primitives/Number.d.ts
|
|
348
|
+
interface NumberProxy<TDefined extends boolean = false> {
|
|
349
|
+
/** Gets the current number value */
|
|
350
|
+
get(): MaybeUndefined<number, TDefined>;
|
|
351
|
+
/** Sets the number value, generating a number.set operation */
|
|
352
|
+
set(value: number): void;
|
|
353
|
+
/** Returns a readonly snapshot of the number value for rendering */
|
|
354
|
+
toSnapshot(): MaybeUndefined<number, TDefined>;
|
|
355
|
+
}
|
|
356
|
+
interface NumberPrimitiveSchema {
|
|
357
|
+
readonly required: boolean;
|
|
358
|
+
readonly defaultValue: number | undefined;
|
|
359
|
+
readonly validators: readonly Validator<number>[];
|
|
360
|
+
}
|
|
361
|
+
declare class NumberPrimitive<TDefined extends boolean = false> implements Primitive<number, NumberProxy<TDefined>> {
|
|
362
|
+
readonly _tag: "NumberPrimitive";
|
|
363
|
+
readonly _State: number;
|
|
364
|
+
readonly _Proxy: NumberProxy<TDefined>;
|
|
365
|
+
private readonly _schema;
|
|
366
|
+
private readonly _opDefinitions;
|
|
367
|
+
constructor(schema: NumberPrimitiveSchema);
|
|
368
|
+
/** Mark this number as required */
|
|
369
|
+
required(): NumberPrimitive<true>;
|
|
370
|
+
/** Set a default value for this number */
|
|
371
|
+
default(defaultValue: number): NumberPrimitive<true>;
|
|
372
|
+
/** Add a custom validation rule */
|
|
373
|
+
refine(fn: (value: number) => boolean, message: string): NumberPrimitive<TDefined>;
|
|
374
|
+
/** Minimum value (inclusive) */
|
|
375
|
+
min(value: number): NumberPrimitive<TDefined>;
|
|
376
|
+
/** Maximum value (inclusive) */
|
|
377
|
+
max(value: number): NumberPrimitive<TDefined>;
|
|
378
|
+
/** Must be positive (> 0) */
|
|
379
|
+
positive(): NumberPrimitive<TDefined>;
|
|
380
|
+
/** Must be negative (< 0) */
|
|
381
|
+
negative(): NumberPrimitive<TDefined>;
|
|
382
|
+
/** Must be an integer */
|
|
383
|
+
int(): NumberPrimitive<TDefined>;
|
|
384
|
+
readonly _internal: PrimitiveInternal<number, NumberProxy<TDefined>>;
|
|
385
|
+
}
|
|
386
|
+
/** Creates a new NumberPrimitive */
|
|
387
|
+
declare const Number: () => NumberPrimitive<false>;
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/primitives/Literal.d.ts
|
|
390
|
+
/** Valid literal types */
|
|
391
|
+
type LiteralValue = string | number | boolean | null;
|
|
392
|
+
interface LiteralProxy<T extends LiteralValue, TDefined extends boolean = false> {
|
|
393
|
+
/** Gets the current literal value */
|
|
394
|
+
get(): MaybeUndefined<T, TDefined>;
|
|
395
|
+
/** Sets the literal value (must match the exact literal type) */
|
|
396
|
+
set(value: T): void;
|
|
397
|
+
/** Returns a readonly snapshot of the literal value for rendering */
|
|
398
|
+
toSnapshot(): MaybeUndefined<T, TDefined>;
|
|
399
|
+
}
|
|
400
|
+
interface LiteralPrimitiveSchema<T extends LiteralValue> {
|
|
401
|
+
readonly required: boolean;
|
|
402
|
+
readonly defaultValue: T | undefined;
|
|
403
|
+
readonly literal: T;
|
|
404
|
+
}
|
|
405
|
+
declare class LiteralPrimitive<T extends LiteralValue, TDefined extends boolean = false> implements Primitive<T, LiteralProxy<T, TDefined>> {
|
|
406
|
+
readonly _tag: "LiteralPrimitive";
|
|
407
|
+
readonly _State: T;
|
|
408
|
+
readonly _Proxy: LiteralProxy<T, TDefined>;
|
|
409
|
+
private readonly _schema;
|
|
410
|
+
private readonly _opDefinitions;
|
|
411
|
+
constructor(schema: LiteralPrimitiveSchema<T>);
|
|
412
|
+
/** Mark this literal as required */
|
|
413
|
+
required(): LiteralPrimitive<T, true>;
|
|
414
|
+
/** Set a default value for this literal */
|
|
415
|
+
default(defaultValue: T): LiteralPrimitive<T, true>;
|
|
416
|
+
/** Get the literal value this primitive represents */
|
|
417
|
+
get literal(): T;
|
|
418
|
+
readonly _internal: PrimitiveInternal<T, LiteralProxy<T, TDefined>>;
|
|
419
|
+
}
|
|
420
|
+
/** Creates a new LiteralPrimitive with the given literal value */
|
|
421
|
+
declare const Literal: <T extends LiteralValue>(literal: T) => LiteralPrimitive<T, false>;
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/primitives/Array.d.ts
|
|
424
|
+
/**
|
|
425
|
+
* Entry in an ordered array with ID and fractional position
|
|
426
|
+
*/
|
|
427
|
+
interface ArrayEntry<T> {
|
|
428
|
+
readonly id: string;
|
|
429
|
+
readonly pos: string;
|
|
430
|
+
readonly value: T;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Entry in an array snapshot with ID and value snapshot
|
|
434
|
+
*/
|
|
435
|
+
interface ArrayEntrySnapshot<TElement extends AnyPrimitive> {
|
|
436
|
+
readonly id: string;
|
|
437
|
+
readonly value: InferSnapshot<TElement>;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Snapshot type for arrays - always an array (never undefined)
|
|
441
|
+
*/
|
|
442
|
+
type ArraySnapshot<TElement extends AnyPrimitive> = readonly ArrayEntrySnapshot<TElement>[];
|
|
443
|
+
interface ArrayProxy<TElement extends AnyPrimitive> {
|
|
444
|
+
/** Gets the current array entries (sorted by position) */
|
|
445
|
+
get(): ArrayState<TElement>;
|
|
446
|
+
/** Replaces the entire array with new values (generates new IDs and positions) */
|
|
447
|
+
set(values: readonly InferState<TElement>[]): void;
|
|
448
|
+
/** Appends a value to the end of the array */
|
|
449
|
+
push(value: InferState<TElement>): void;
|
|
450
|
+
/** Inserts a value at the specified visual index */
|
|
451
|
+
insertAt(index: number, value: InferState<TElement>): void;
|
|
452
|
+
/** Removes the element with the specified ID */
|
|
453
|
+
remove(id: string): void;
|
|
454
|
+
/** Moves an element to a new visual index */
|
|
455
|
+
move(id: string, toIndex: number): void;
|
|
456
|
+
/** Returns a proxy for the element with the specified ID */
|
|
457
|
+
at(id: string): InferProxy<TElement>;
|
|
458
|
+
/** Finds an element by predicate and returns its proxy */
|
|
459
|
+
find(predicate: (value: InferState<TElement>, id: string) => boolean): InferProxy<TElement> | undefined;
|
|
460
|
+
/** Returns a readonly snapshot of the array for rendering (always returns an array, never undefined) */
|
|
461
|
+
toSnapshot(): ArraySnapshot<TElement>;
|
|
462
|
+
}
|
|
463
|
+
/** The state type for arrays - an array of entries */
|
|
464
|
+
type ArrayState<TElement extends AnyPrimitive> = readonly ArrayEntry<InferState<TElement>>[];
|
|
465
|
+
interface ArrayPrimitiveSchema<TElement extends AnyPrimitive> {
|
|
466
|
+
readonly required: boolean;
|
|
467
|
+
readonly defaultValue: ArrayState<TElement> | undefined;
|
|
468
|
+
readonly element: TElement;
|
|
469
|
+
readonly validators: readonly Validator<ArrayState<TElement>>[];
|
|
470
|
+
}
|
|
471
|
+
declare class ArrayPrimitive<TElement extends AnyPrimitive> implements Primitive<ArrayState<TElement>, ArrayProxy<TElement>> {
|
|
472
|
+
readonly _tag: "ArrayPrimitive";
|
|
473
|
+
readonly _State: ArrayState<TElement>;
|
|
474
|
+
readonly _Proxy: ArrayProxy<TElement>;
|
|
475
|
+
private readonly _schema;
|
|
476
|
+
private readonly _opDefinitions;
|
|
477
|
+
constructor(schema: ArrayPrimitiveSchema<TElement>);
|
|
478
|
+
/** Mark this array as required */
|
|
479
|
+
required(): ArrayPrimitive<TElement>;
|
|
480
|
+
/** Set a default value for this array */
|
|
481
|
+
default(defaultValue: ArrayState<TElement>): ArrayPrimitive<TElement>;
|
|
482
|
+
/** Get the element primitive */
|
|
483
|
+
get element(): TElement;
|
|
484
|
+
/** Add a custom validation rule */
|
|
485
|
+
refine(fn: (value: ArrayState<TElement>) => boolean, message: string): ArrayPrimitive<TElement>;
|
|
486
|
+
/** Minimum array length */
|
|
487
|
+
minLength(length: number): ArrayPrimitive<TElement>;
|
|
488
|
+
/** Maximum array length */
|
|
489
|
+
maxLength(length: number): ArrayPrimitive<TElement>;
|
|
490
|
+
readonly _internal: PrimitiveInternal<ArrayState<TElement>, ArrayProxy<TElement>>;
|
|
491
|
+
}
|
|
492
|
+
/** Creates a new ArrayPrimitive with the given element type */
|
|
493
|
+
declare const Array$1: <TElement extends AnyPrimitive>(element: TElement) => ArrayPrimitive<TElement>;
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/primitives/Lazy.d.ts
|
|
496
|
+
/**
|
|
497
|
+
* Type to infer state from a lazy thunk
|
|
498
|
+
*/
|
|
499
|
+
type InferLazyState<T extends () => AnyPrimitive> = InferState<ReturnType<T>>;
|
|
500
|
+
/**
|
|
501
|
+
* Type to infer proxy from a lazy thunk
|
|
502
|
+
*/
|
|
503
|
+
type InferLazyProxy<T extends () => AnyPrimitive> = InferProxy<ReturnType<T>>;
|
|
504
|
+
/**
|
|
505
|
+
* Type to infer snapshot from a lazy thunk
|
|
506
|
+
*/
|
|
507
|
+
type InferLazySnapshot<T extends () => AnyPrimitive> = InferSnapshot<ReturnType<T>>;
|
|
508
|
+
declare class LazyPrimitive<TThunk extends () => AnyPrimitive> implements Primitive<InferLazyState<TThunk>, InferLazyProxy<TThunk>> {
|
|
509
|
+
readonly _tag: "LazyPrimitive";
|
|
510
|
+
readonly _State: InferLazyState<TThunk>;
|
|
511
|
+
readonly _Proxy: InferLazyProxy<TThunk>;
|
|
512
|
+
private readonly _thunk;
|
|
513
|
+
private _resolved;
|
|
514
|
+
constructor(thunk: TThunk);
|
|
515
|
+
/** Resolve and cache the lazy primitive */
|
|
516
|
+
private _resolve;
|
|
517
|
+
/** Mark this lazy primitive as required (delegates to resolved) */
|
|
518
|
+
required(): LazyPrimitive<TThunk>;
|
|
519
|
+
readonly _internal: PrimitiveInternal<InferLazyState<TThunk>, InferLazyProxy<TThunk>>;
|
|
520
|
+
}
|
|
521
|
+
/** Creates a new LazyPrimitive with the given thunk */
|
|
522
|
+
declare const Lazy: <TThunk extends () => AnyPrimitive>(thunk: TThunk) => LazyPrimitive<TThunk>;
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/primitives/Union.d.ts
|
|
525
|
+
/**
|
|
526
|
+
* Type constraint for union variants - must be struct primitives
|
|
527
|
+
*/
|
|
528
|
+
type UnionVariants = Record<string, StructPrimitive<any, any>>;
|
|
529
|
+
/**
|
|
530
|
+
* Infer the union state type from variants
|
|
531
|
+
*/
|
|
532
|
+
type InferUnionState<TVariants extends UnionVariants> = { [K in keyof TVariants]: InferState<TVariants[K]> }[keyof TVariants];
|
|
533
|
+
/**
|
|
534
|
+
* Infer the union snapshot type from variants
|
|
535
|
+
*/
|
|
536
|
+
type InferUnionSnapshot<TVariants extends UnionVariants> = { [K in keyof TVariants]: InferSnapshot<TVariants[K]> }[keyof TVariants];
|
|
537
|
+
/**
|
|
538
|
+
* Proxy for accessing union variants
|
|
539
|
+
*/
|
|
540
|
+
interface UnionProxy<TVariants extends UnionVariants, TDiscriminator extends string, TDefined extends boolean = false> {
|
|
541
|
+
/** Gets the current union value */
|
|
542
|
+
get(): MaybeUndefined<InferUnionState<TVariants>, TDefined>;
|
|
543
|
+
/** Sets the entire union value */
|
|
544
|
+
set(value: InferUnionState<TVariants>): void;
|
|
545
|
+
/** Access a specific variant's proxy (assumes the variant is active) */
|
|
546
|
+
as<K$1 extends keyof TVariants>(variant: K$1): InferProxy<TVariants[K$1]>;
|
|
547
|
+
/** Pattern match on the variant type */
|
|
548
|
+
match<R>(handlers: { [K in keyof TVariants]: (proxy: InferProxy<TVariants[K$1]>) => R }): R | undefined;
|
|
549
|
+
/** Returns a readonly snapshot of the union for rendering */
|
|
550
|
+
toSnapshot(): MaybeUndefined<InferUnionSnapshot<TVariants>, TDefined>;
|
|
551
|
+
}
|
|
552
|
+
interface UnionPrimitiveSchema<TVariants extends UnionVariants, TDiscriminator extends string> {
|
|
553
|
+
readonly required: boolean;
|
|
554
|
+
readonly defaultValue: InferUnionState<TVariants> | undefined;
|
|
555
|
+
readonly discriminator: TDiscriminator;
|
|
556
|
+
readonly variants: TVariants;
|
|
557
|
+
}
|
|
558
|
+
declare class UnionPrimitive<TVariants extends UnionVariants, TDiscriminator extends string = "type", TDefined extends boolean = false> implements Primitive<InferUnionState<TVariants>, UnionProxy<TVariants, TDiscriminator, TDefined>> {
|
|
559
|
+
readonly _tag: "UnionPrimitive";
|
|
560
|
+
readonly _State: InferUnionState<TVariants>;
|
|
561
|
+
readonly _Proxy: UnionProxy<TVariants, TDiscriminator, TDefined>;
|
|
562
|
+
private readonly _schema;
|
|
563
|
+
private readonly _opDefinitions;
|
|
564
|
+
constructor(schema: UnionPrimitiveSchema<TVariants, TDiscriminator>);
|
|
565
|
+
/** Mark this union as required */
|
|
566
|
+
required(): UnionPrimitive<TVariants, TDiscriminator, true>;
|
|
567
|
+
/** Set a default value for this union */
|
|
568
|
+
default(defaultValue: InferUnionState<TVariants>): UnionPrimitive<TVariants, TDiscriminator, true>;
|
|
569
|
+
/** Get the discriminator field name */
|
|
570
|
+
get discriminator(): TDiscriminator;
|
|
571
|
+
/** Get the variants */
|
|
572
|
+
get variants(): TVariants;
|
|
573
|
+
/** Find the variant key from a state value */
|
|
574
|
+
private _findVariantKey;
|
|
575
|
+
readonly _internal: PrimitiveInternal<InferUnionState<TVariants>, UnionProxy<TVariants, TDiscriminator, TDefined>>;
|
|
576
|
+
}
|
|
577
|
+
/** Options for creating a Union primitive */
|
|
578
|
+
interface UnionOptions<TVariants extends UnionVariants, TDiscriminator extends string> {
|
|
579
|
+
/** The field name used to discriminate between variants (defaults to "type") */
|
|
580
|
+
readonly discriminator?: TDiscriminator;
|
|
581
|
+
/** The variant struct primitives */
|
|
582
|
+
readonly variants: TVariants;
|
|
583
|
+
}
|
|
584
|
+
/** Creates a new UnionPrimitive with the given variants */
|
|
585
|
+
declare function Union<TVariants extends UnionVariants>(options: UnionOptions<TVariants, "type">): UnionPrimitive<TVariants, "type", false>;
|
|
586
|
+
declare function Union<TVariants extends UnionVariants, TDiscriminator extends string>(options: UnionOptions<TVariants, TDiscriminator>): UnionPrimitive<TVariants, TDiscriminator, false>;
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/primitives/Either.d.ts
|
|
589
|
+
/**
|
|
590
|
+
* Scalar primitives that can be used as variants in Either
|
|
591
|
+
*/
|
|
592
|
+
type ScalarPrimitive = StringPrimitive<any> | NumberPrimitive<any> | BooleanPrimitive<any> | LiteralPrimitive<any, any>;
|
|
593
|
+
/**
|
|
594
|
+
* Infer the union state type from a tuple of scalar primitives
|
|
595
|
+
*/
|
|
596
|
+
type InferEitherState<TVariants extends readonly ScalarPrimitive[]> = InferState<TVariants[number]>;
|
|
597
|
+
/**
|
|
598
|
+
* Infer the union snapshot type from a tuple of scalar primitives
|
|
599
|
+
*/
|
|
600
|
+
type InferEitherSnapshot<TVariants extends readonly ScalarPrimitive[]> = InferState<TVariants[number]>;
|
|
601
|
+
/**
|
|
602
|
+
* Match handlers for Either - optional handlers for each scalar type
|
|
603
|
+
*/
|
|
604
|
+
interface EitherMatchHandlers<R> {
|
|
605
|
+
string?: (value: string) => R;
|
|
606
|
+
number?: (value: number) => R;
|
|
607
|
+
boolean?: (value: boolean) => R;
|
|
608
|
+
literal?: (value: LiteralValue) => R;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Proxy for accessing Either values
|
|
612
|
+
*/
|
|
613
|
+
interface EitherProxy<TVariants extends readonly ScalarPrimitive[], TDefined extends boolean = false> {
|
|
614
|
+
/** Gets the current value */
|
|
615
|
+
get(): MaybeUndefined<InferEitherState<TVariants>, TDefined>;
|
|
616
|
+
/** Sets the value to any of the allowed variant types */
|
|
617
|
+
set(value: InferEitherState<TVariants>): void;
|
|
618
|
+
/** Pattern match on the value type */
|
|
619
|
+
match<R>(handlers: EitherMatchHandlers<R>): R | undefined;
|
|
620
|
+
/** Returns a readonly snapshot of the value for rendering */
|
|
621
|
+
toSnapshot(): MaybeUndefined<InferEitherSnapshot<TVariants>, TDefined>;
|
|
622
|
+
}
|
|
623
|
+
interface EitherPrimitiveSchema<TVariants extends readonly ScalarPrimitive[]> {
|
|
624
|
+
readonly required: boolean;
|
|
625
|
+
readonly defaultValue: InferEitherState<TVariants> | undefined;
|
|
626
|
+
readonly variants: TVariants;
|
|
627
|
+
}
|
|
628
|
+
declare class EitherPrimitive<TVariants extends readonly ScalarPrimitive[], TDefined extends boolean = false> implements Primitive<InferEitherState<TVariants>, EitherProxy<TVariants, TDefined>> {
|
|
629
|
+
readonly _tag: "EitherPrimitive";
|
|
630
|
+
readonly _State: InferEitherState<TVariants>;
|
|
631
|
+
readonly _Proxy: EitherProxy<TVariants, TDefined>;
|
|
632
|
+
private readonly _schema;
|
|
633
|
+
private readonly _opDefinitions;
|
|
634
|
+
constructor(schema: EitherPrimitiveSchema<TVariants>);
|
|
635
|
+
/** Mark this either as required */
|
|
636
|
+
required(): EitherPrimitive<TVariants, true>;
|
|
637
|
+
/** Set a default value for this either */
|
|
638
|
+
default(defaultValue: InferEitherState<TVariants>): EitherPrimitive<TVariants, true>;
|
|
639
|
+
/** Get the variants */
|
|
640
|
+
get variants(): TVariants;
|
|
641
|
+
/**
|
|
642
|
+
* Determine the type category of a value based on the variants
|
|
643
|
+
*/
|
|
644
|
+
private _getValueType;
|
|
645
|
+
/**
|
|
646
|
+
* Find the matching variant for a value.
|
|
647
|
+
* For literals, matches exact value. For other types, matches by typeof.
|
|
648
|
+
*/
|
|
649
|
+
private _findMatchingVariant;
|
|
650
|
+
/**
|
|
651
|
+
* Get the operation kind for a variant
|
|
652
|
+
*/
|
|
653
|
+
private _getVariantOperationKind;
|
|
654
|
+
/**
|
|
655
|
+
* Validate a value against the matching variant, including running its validators.
|
|
656
|
+
* Throws ValidationError if the value doesn't match any variant or fails validation.
|
|
657
|
+
*/
|
|
658
|
+
private _validateAndApplyToVariant;
|
|
659
|
+
readonly _internal: PrimitiveInternal<InferEitherState<TVariants>, EitherProxy<TVariants, TDefined>>;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Creates a new EitherPrimitive with the given scalar variant types.
|
|
663
|
+
* Validators defined on the variants are applied when validating values.
|
|
664
|
+
*
|
|
665
|
+
* @example
|
|
666
|
+
* ```typescript
|
|
667
|
+
* // String or number
|
|
668
|
+
* const value = Either(String(), Number());
|
|
669
|
+
*
|
|
670
|
+
* // String, number, or boolean
|
|
671
|
+
* const status = Either(String(), Number(), Boolean()).default("pending");
|
|
672
|
+
*
|
|
673
|
+
* // With literal types
|
|
674
|
+
* const mode = Either(Literal("auto"), Literal("manual"), Number());
|
|
675
|
+
*
|
|
676
|
+
* // With validators - validates string length and number range
|
|
677
|
+
* const constrained = Either(
|
|
678
|
+
* String().min(2).max(50),
|
|
679
|
+
* Number().max(255)
|
|
680
|
+
* );
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
declare function Either<TVariants extends readonly ScalarPrimitive[]>(...variants: TVariants): EitherPrimitive<TVariants, false>;
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/primitives/TreeNode.d.ts
|
|
686
|
+
/**
|
|
687
|
+
* Any TreeNodePrimitive type - used for generic constraints.
|
|
688
|
+
*/
|
|
689
|
+
type AnyTreeNodePrimitive = TreeNodePrimitive<string, StructPrimitive<any>, readonly AnyTreeNodePrimitive[] | (() => readonly AnyTreeNodePrimitive[])>;
|
|
690
|
+
/**
|
|
691
|
+
* Resolves children type - handles both array and lazy thunk
|
|
692
|
+
*/
|
|
693
|
+
type ResolveChildren<TChildren$1 extends readonly AnyTreeNodePrimitive[] | (() => readonly AnyTreeNodePrimitive[])> = TChildren$1 extends (() => readonly AnyTreeNodePrimitive[]) ? ReturnType<TChildren$1> : TChildren$1;
|
|
694
|
+
/**
|
|
695
|
+
* Infer the data state type from a TreeNodePrimitive
|
|
696
|
+
*/
|
|
697
|
+
type InferTreeNodeDataState<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<any, infer TData, any> ? InferState<TData> : never;
|
|
698
|
+
/**
|
|
699
|
+
* Infer the type literal from a TreeNodePrimitive
|
|
700
|
+
*/
|
|
701
|
+
type InferTreeNodeType<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<infer TType, any, any> ? TType : never;
|
|
702
|
+
/**
|
|
703
|
+
* Infer the allowed children from a TreeNodePrimitive
|
|
704
|
+
*/
|
|
705
|
+
type InferTreeNodeChildren<T extends AnyTreeNodePrimitive> = T extends TreeNodePrimitive<any, any, infer TChildren> ? ResolveChildren<TChildren>[number] : never;
|
|
706
|
+
/**
|
|
707
|
+
* Configuration for a TreeNode primitive
|
|
708
|
+
*/
|
|
709
|
+
interface TreeNodeConfig<TData$1 extends StructPrimitive<any>, TChildren$1 extends readonly AnyTreeNodePrimitive[] | (() => readonly AnyTreeNodePrimitive[])> {
|
|
710
|
+
readonly data: TData$1;
|
|
711
|
+
readonly children: TChildren$1;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* TreeNodePrimitive - defines a node type with its data schema and allowed children
|
|
715
|
+
*/
|
|
716
|
+
declare class TreeNodePrimitive<TType extends string, TData$1 extends StructPrimitive<any>, TChildren$1 extends readonly AnyTreeNodePrimitive[] | (() => readonly AnyTreeNodePrimitive[])> {
|
|
717
|
+
readonly _tag: "TreeNodePrimitive";
|
|
718
|
+
readonly _Type: TType;
|
|
719
|
+
readonly _Data: TData$1;
|
|
720
|
+
readonly _Children: TChildren$1;
|
|
721
|
+
private readonly _type;
|
|
722
|
+
private readonly _data;
|
|
723
|
+
private readonly _children;
|
|
724
|
+
private _resolvedChildren;
|
|
725
|
+
constructor(type: TType, config: TreeNodeConfig<TData$1, TChildren$1>);
|
|
726
|
+
/** Get the node type identifier */
|
|
727
|
+
get type(): TType;
|
|
728
|
+
/** Get the data primitive */
|
|
729
|
+
get data(): TData$1;
|
|
730
|
+
/** Get resolved children (resolves lazy thunk if needed) */
|
|
731
|
+
get children(): ResolveChildren<TChildren$1>;
|
|
732
|
+
/** Check if a child type is allowed */
|
|
733
|
+
isChildAllowed(childType: string): boolean;
|
|
734
|
+
}
|
|
735
|
+
/** Creates a new TreeNodePrimitive with the given type and config */
|
|
736
|
+
declare const TreeNode: <TType extends string, TData$1 extends StructPrimitive<any>, TChildren$1 extends readonly AnyTreeNodePrimitive[] | (() => readonly AnyTreeNodePrimitive[])>(type: TType, config: TreeNodeConfig<TData$1, TChildren$1>) => TreeNodePrimitive<TType, TData$1, TChildren$1>;
|
|
737
|
+
//#endregion
|
|
738
|
+
//#region src/primitives/Tree.d.ts
|
|
739
|
+
/**
|
|
740
|
+
* A node in the tree state (flat storage format)
|
|
741
|
+
*/
|
|
742
|
+
interface TreeNodeState {
|
|
743
|
+
readonly id: string;
|
|
744
|
+
readonly type: string;
|
|
745
|
+
readonly parentId: string | null;
|
|
746
|
+
readonly pos: string;
|
|
747
|
+
readonly data: unknown;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Typed node state for a specific node type
|
|
751
|
+
*/
|
|
752
|
+
interface TypedTreeNodeState<TNode extends AnyTreeNodePrimitive> {
|
|
753
|
+
readonly id: string;
|
|
754
|
+
readonly type: InferTreeNodeType<TNode>;
|
|
755
|
+
readonly parentId: string | null;
|
|
756
|
+
readonly pos: string;
|
|
757
|
+
readonly data: InferTreeNodeDataState<TNode>;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* The state type for trees - a flat array of nodes
|
|
761
|
+
*/
|
|
762
|
+
type TreeState<TRoot$1 extends AnyTreeNodePrimitive> = readonly TreeNodeState[];
|
|
763
|
+
/**
|
|
764
|
+
* Snapshot of a single node for UI rendering (data properties spread at node level)
|
|
765
|
+
*/
|
|
766
|
+
type TreeNodeSnapshot<TNode extends AnyTreeNodePrimitive> = {
|
|
767
|
+
readonly id: string;
|
|
768
|
+
readonly type: InferTreeNodeType<TNode>;
|
|
769
|
+
readonly children: TreeNodeSnapshot<InferTreeNodeChildren<TNode>>[];
|
|
770
|
+
} & InferTreeNodeDataState<TNode>;
|
|
771
|
+
/**
|
|
772
|
+
* Infer the snapshot type for a tree (recursive tree structure for UI)
|
|
773
|
+
*/
|
|
774
|
+
type InferTreeSnapshot<T extends TreePrimitive<any>> = T extends TreePrimitive<infer TRoot> ? TreeNodeSnapshot<TRoot> : never;
|
|
775
|
+
/**
|
|
776
|
+
* Typed proxy for a specific node type - provides type-safe data access
|
|
777
|
+
*/
|
|
778
|
+
interface TypedNodeProxy<TNode extends AnyTreeNodePrimitive> {
|
|
779
|
+
/** The node ID */
|
|
780
|
+
readonly id: string;
|
|
781
|
+
/** The node type */
|
|
782
|
+
readonly type: InferTreeNodeType<TNode>;
|
|
783
|
+
/** Access the node's data proxy */
|
|
784
|
+
readonly data: InferProxy<TNode["data"]>;
|
|
785
|
+
/** Get the raw node state */
|
|
786
|
+
get(): TypedTreeNodeState<TNode>;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Node proxy with type narrowing capabilities
|
|
790
|
+
*/
|
|
791
|
+
interface TreeNodeProxyBase<TRoot$1 extends AnyTreeNodePrimitive> {
|
|
792
|
+
/** The node ID */
|
|
793
|
+
readonly id: string;
|
|
794
|
+
/** The node type (string) */
|
|
795
|
+
readonly type: string;
|
|
796
|
+
/** Type guard - narrows the proxy to a specific node type */
|
|
797
|
+
is<TNode extends AnyTreeNodePrimitive>(nodeType: TNode): this is TypedNodeProxy<TNode>;
|
|
798
|
+
/** Type assertion - returns typed proxy (throws if wrong type) */
|
|
799
|
+
as<TNode extends AnyTreeNodePrimitive>(nodeType: TNode): TypedNodeProxy<TNode>;
|
|
800
|
+
/** Get the raw node state */
|
|
801
|
+
get(): TreeNodeState;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Proxy for accessing and modifying tree nodes
|
|
805
|
+
*/
|
|
806
|
+
interface TreeProxy<TRoot$1 extends AnyTreeNodePrimitive> {
|
|
807
|
+
/** Gets the entire tree state (flat array of nodes) */
|
|
808
|
+
get(): TreeState<TRoot$1>;
|
|
809
|
+
/** Replaces the entire tree */
|
|
810
|
+
set(nodes: TreeState<TRoot$1>): void;
|
|
811
|
+
/** Gets the root node state */
|
|
812
|
+
root(): TypedTreeNodeState<TRoot$1> | undefined;
|
|
813
|
+
/** Gets ordered children states of a parent (null for root's children) */
|
|
814
|
+
children(parentId: string | null): TreeNodeState[];
|
|
815
|
+
/** Gets a node proxy by ID with type narrowing capabilities */
|
|
816
|
+
node(id: string): TreeNodeProxyBase<TRoot$1> | undefined;
|
|
817
|
+
/** Insert a new node as the first child */
|
|
818
|
+
insertFirst<TNode extends AnyTreeNodePrimitive>(parentId: string | null, nodeType: TNode, data: InferTreeNodeDataState<TNode>): string;
|
|
819
|
+
/** Insert a new node as the last child */
|
|
820
|
+
insertLast<TNode extends AnyTreeNodePrimitive>(parentId: string | null, nodeType: TNode, data: InferTreeNodeDataState<TNode>): string;
|
|
821
|
+
/** Insert a new node at a specific index among siblings */
|
|
822
|
+
insertAt<TNode extends AnyTreeNodePrimitive>(parentId: string | null, index: number, nodeType: TNode, data: InferTreeNodeDataState<TNode>): string;
|
|
823
|
+
/** Insert a new node after a sibling */
|
|
824
|
+
insertAfter<TNode extends AnyTreeNodePrimitive>(siblingId: string, nodeType: TNode, data: InferTreeNodeDataState<TNode>): string;
|
|
825
|
+
/** Insert a new node before a sibling */
|
|
826
|
+
insertBefore<TNode extends AnyTreeNodePrimitive>(siblingId: string, nodeType: TNode, data: InferTreeNodeDataState<TNode>): string;
|
|
827
|
+
/** Remove a node and all its descendants */
|
|
828
|
+
remove(id: string): void;
|
|
829
|
+
/** Move a node to a new parent at a specific index */
|
|
830
|
+
move(nodeId: string, newParentId: string | null, toIndex: number): void;
|
|
831
|
+
/** Move a node after a sibling */
|
|
832
|
+
moveAfter(nodeId: string, siblingId: string): void;
|
|
833
|
+
/** Move a node before a sibling */
|
|
834
|
+
moveBefore(nodeId: string, siblingId: string): void;
|
|
835
|
+
/** Move a node to be the first child of a parent */
|
|
836
|
+
moveToFirst(nodeId: string, newParentId: string | null): void;
|
|
837
|
+
/** Move a node to be the last child of a parent */
|
|
838
|
+
moveToLast(nodeId: string, newParentId: string | null): void;
|
|
839
|
+
/** Returns a typed proxy for a specific node's data */
|
|
840
|
+
at<TNode extends AnyTreeNodePrimitive>(id: string, nodeType: TNode): InferProxy<TNode["data"]>;
|
|
841
|
+
/** Convert tree to a nested snapshot for UI rendering */
|
|
842
|
+
toSnapshot(): TreeNodeSnapshot<TRoot$1> | undefined;
|
|
843
|
+
}
|
|
844
|
+
interface TreePrimitiveSchema<TRoot$1 extends AnyTreeNodePrimitive> {
|
|
845
|
+
readonly required: boolean;
|
|
846
|
+
readonly defaultValue: TreeState<TRoot$1> | undefined;
|
|
847
|
+
readonly root: TRoot$1;
|
|
848
|
+
readonly validators: readonly Validator<TreeState<TRoot$1>>[];
|
|
849
|
+
}
|
|
850
|
+
declare class TreePrimitive<TRoot$1 extends AnyTreeNodePrimitive> implements Primitive<TreeState<TRoot$1>, TreeProxy<TRoot$1>> {
|
|
851
|
+
readonly _tag: "TreePrimitive";
|
|
852
|
+
readonly _State: TreeState<TRoot$1>;
|
|
853
|
+
readonly _Proxy: TreeProxy<TRoot$1>;
|
|
854
|
+
private readonly _schema;
|
|
855
|
+
private _nodeTypeRegistry;
|
|
856
|
+
private readonly _opDefinitions;
|
|
857
|
+
constructor(schema: TreePrimitiveSchema<TRoot$1>);
|
|
858
|
+
/** Mark this tree as required */
|
|
859
|
+
required(): TreePrimitive<TRoot$1>;
|
|
860
|
+
/** Set a default value for this tree */
|
|
861
|
+
default(defaultValue: TreeState<TRoot$1>): TreePrimitive<TRoot$1>;
|
|
862
|
+
/** Get the root node type */
|
|
863
|
+
get root(): TRoot$1;
|
|
864
|
+
/** Add a custom validation rule */
|
|
865
|
+
refine(fn: (value: TreeState<TRoot$1>) => boolean, message: string): TreePrimitive<TRoot$1>;
|
|
866
|
+
/**
|
|
867
|
+
* Build a registry of all node types reachable from root
|
|
868
|
+
*/
|
|
869
|
+
private _buildNodeTypeRegistry;
|
|
870
|
+
/**
|
|
871
|
+
* Get a node type primitive by its type string
|
|
872
|
+
*/
|
|
873
|
+
private _getNodeTypePrimitive;
|
|
874
|
+
/**
|
|
875
|
+
* Validate that a node type can be a child of a parent node type
|
|
876
|
+
*/
|
|
877
|
+
private _validateChildType;
|
|
878
|
+
readonly _internal: PrimitiveInternal<TreeState<TRoot$1>, TreeProxy<TRoot$1>>;
|
|
879
|
+
}
|
|
880
|
+
/** Options for creating a Tree primitive */
|
|
881
|
+
interface TreeOptions<TRoot$1 extends AnyTreeNodePrimitive> {
|
|
882
|
+
/** The root node type */
|
|
883
|
+
readonly root: TRoot$1;
|
|
884
|
+
}
|
|
885
|
+
/** Creates a new TreePrimitive with the given root node type */
|
|
886
|
+
declare const Tree: <TRoot$1 extends AnyTreeNodePrimitive>(options: TreeOptions<TRoot$1>) => TreePrimitive<TRoot$1>;
|
|
887
|
+
declare namespace Primitive_d_exports {
|
|
888
|
+
export { AnyPrimitive, AnyTreeNodePrimitive, Array$1 as Array, ArrayEntry, ArrayEntrySnapshot, ArrayPrimitive, ArrayProxy, ArraySnapshot, ArrayState, Boolean, BooleanPrimitive, BooleanProxy, Either, EitherMatchHandlers, EitherPrimitive, EitherProxy, InferEitherSnapshot, InferEitherState, InferLazyProxy, InferLazySnapshot, InferLazyState, InferProxy, InferSnapshot, InferState, InferStructSnapshot, InferStructState, InferTreeNodeChildren, InferTreeNodeDataState, InferTreeNodeType, InferTreeSnapshot, InferUnionSnapshot, InferUnionState, Lazy, LazyPrimitive, Literal, LiteralPrimitive, LiteralProxy, LiteralValue, MaybeUndefined, Number, NumberPrimitive, NumberProxy, Primitive, PrimitiveInternal, ResolveChildren, ScalarPrimitive, String, StringPrimitive, StringProxy, Struct, StructPrimitive, StructProxy, Tree, TreeNode, TreeNodeConfig, TreeNodePrimitive, TreeNodeProxyBase, TreeNodeSnapshot, TreeNodeState, TreeOptions, TreePrimitive, TreeProxy, TreeState, TypedNodeProxy, TypedTreeNodeState, Union, UnionOptions, UnionPrimitive, UnionProxy, UnionVariants, ValidationError, Validator, isCompatibleOperation, runValidators };
|
|
889
|
+
}
|
|
890
|
+
declare namespace Transaction_d_exports {
|
|
891
|
+
export { EncodedTransaction, Transaction, decode, empty, encode, isEmpty, make$2 as make, merge };
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* A Transaction represents a group of operations that were applied atomically.
|
|
895
|
+
*/
|
|
896
|
+
interface Transaction {
|
|
897
|
+
/** Unique identifier for this transaction */
|
|
898
|
+
readonly id: string;
|
|
899
|
+
/** Operations contained in this transaction */
|
|
900
|
+
readonly ops: ReadonlyArray<Operation<any, any, any>>;
|
|
901
|
+
/** Timestamp when the transaction was created */
|
|
902
|
+
readonly timestamp: number;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Creates a new Transaction with the given operations.
|
|
906
|
+
*/
|
|
907
|
+
declare const make$2: (ops: ReadonlyArray<Operation<any, any, any>>) => Transaction;
|
|
908
|
+
/**
|
|
909
|
+
* Creates an empty Transaction.
|
|
910
|
+
*/
|
|
911
|
+
declare const empty: () => Transaction;
|
|
912
|
+
/**
|
|
913
|
+
* Checks if a transaction is empty (has no operations).
|
|
914
|
+
*/
|
|
915
|
+
declare const isEmpty: (tx: Transaction) => boolean;
|
|
916
|
+
/**
|
|
917
|
+
* Merges multiple transactions into one.
|
|
918
|
+
*/
|
|
919
|
+
declare const merge: (txs: ReadonlyArray<Transaction>) => Transaction;
|
|
920
|
+
/**
|
|
921
|
+
* Encoded representation of a Transaction for network transport.
|
|
922
|
+
*/
|
|
923
|
+
interface EncodedTransaction {
|
|
924
|
+
readonly id: string;
|
|
925
|
+
readonly ops: ReadonlyArray<EncodedOperation>;
|
|
926
|
+
readonly timestamp: number;
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Encodes a Transaction to a JSON-serializable format for network transport.
|
|
930
|
+
* @param transaction - The transaction to encode.
|
|
931
|
+
* @returns The encoded representation.
|
|
932
|
+
*/
|
|
933
|
+
declare const encode: (transaction: Transaction) => EncodedTransaction;
|
|
934
|
+
/**
|
|
935
|
+
* Decodes an encoded transaction back to a Transaction.
|
|
936
|
+
* @param encoded - The encoded representation.
|
|
937
|
+
* @returns The decoded Transaction.
|
|
938
|
+
*/
|
|
939
|
+
declare const decode: (encoded: EncodedTransaction) => Transaction;
|
|
940
|
+
declare namespace Document_d_exports {
|
|
941
|
+
export { Document, DocumentOptions, NestedTransactionError, OperationError, make$1 as make };
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Error thrown when attempting to start a nested transaction.
|
|
945
|
+
*/
|
|
946
|
+
declare class NestedTransactionError extends Error {
|
|
947
|
+
readonly _tag = "NestedTransactionError";
|
|
948
|
+
constructor();
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Error thrown when an operation fails to apply.
|
|
952
|
+
*/
|
|
953
|
+
declare class OperationError extends Error {
|
|
954
|
+
readonly _tag = "OperationError";
|
|
955
|
+
constructor(message: string);
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* A Document manages state for a primitive-based schema with transaction support.
|
|
959
|
+
*/
|
|
960
|
+
interface Document<TSchema extends AnyPrimitive> {
|
|
961
|
+
/** The schema defining this document's structure */
|
|
962
|
+
readonly schema: TSchema;
|
|
963
|
+
/** Root proxy for accessing and modifying document data */
|
|
964
|
+
readonly root: InferProxy<TSchema>;
|
|
965
|
+
/** Returns the current document state */
|
|
966
|
+
get(): InferState<TSchema> | undefined;
|
|
967
|
+
/**
|
|
968
|
+
* Returns a readonly snapshot of the entire document state for rendering.
|
|
969
|
+
* The snapshot is a type-safe, readonly structure where:
|
|
970
|
+
* - Required fields and fields with defaults are guaranteed to be defined
|
|
971
|
+
* - Optional fields may be undefined
|
|
972
|
+
*/
|
|
973
|
+
toSnapshot(): InferSnapshot<TSchema>;
|
|
974
|
+
/**
|
|
975
|
+
* Runs a function within a transaction.
|
|
976
|
+
* All operations are collected and applied atomically.
|
|
977
|
+
* If the function throws, all changes are rolled back.
|
|
978
|
+
* @returns The return value of the function
|
|
979
|
+
*/
|
|
980
|
+
transaction<R>(fn: (root: InferProxy<TSchema>) => R): R;
|
|
981
|
+
/**
|
|
982
|
+
* Applies external operations (e.g., from server/peers) to the document.
|
|
983
|
+
* These operations are NOT added to pending operations.
|
|
984
|
+
*/
|
|
985
|
+
apply(ops: ReadonlyArray<Operation<any, any, any>>): void;
|
|
986
|
+
/**
|
|
987
|
+
* Returns pending local operations as a Transaction and clears the buffer.
|
|
988
|
+
*/
|
|
989
|
+
flush(): Transaction;
|
|
990
|
+
}
|
|
991
|
+
interface DocumentOptions<TSchema extends AnyPrimitive> {
|
|
992
|
+
/** Initial state for the document */
|
|
993
|
+
readonly initial?: InferState<TSchema>;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Creates a new Document for the given schema.
|
|
997
|
+
*/
|
|
998
|
+
declare const make$1: <TSchema extends AnyPrimitive>(schema: TSchema, options?: DocumentOptions<TSchema>) => Document<TSchema>;
|
|
999
|
+
declare namespace Presence_d_exports {
|
|
1000
|
+
export { AnyPresence, Infer, Presence, PresenceEntry, PresenceOptions, isValid, make, validate, validateSafe };
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* A Presence schema wrapper that holds an Effect Schema for validation.
|
|
1004
|
+
* This is used by both client and server to validate presence data.
|
|
1005
|
+
*/
|
|
1006
|
+
interface Presence<TData$1> {
|
|
1007
|
+
readonly _tag: "Presence";
|
|
1008
|
+
/** The Effect Schema used for validation */
|
|
1009
|
+
readonly schema: Schema$1.Schema<TData$1>;
|
|
1010
|
+
/** Branded type marker for inference */
|
|
1011
|
+
readonly _Data: TData$1;
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Options for creating a Presence instance.
|
|
1015
|
+
*/
|
|
1016
|
+
interface PresenceOptions<TData$1> {
|
|
1017
|
+
/** The Effect Schema defining the presence data structure */
|
|
1018
|
+
readonly schema: Schema$1.Schema<TData$1>;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Infer the data type from a Presence instance.
|
|
1022
|
+
*/
|
|
1023
|
+
type Infer<P extends Presence<any>> = P["_Data"];
|
|
1024
|
+
/**
|
|
1025
|
+
* Any Presence type (for generic constraints).
|
|
1026
|
+
*/
|
|
1027
|
+
type AnyPresence = Presence<any>;
|
|
1028
|
+
/**
|
|
1029
|
+
* A presence entry as stored/transmitted.
|
|
1030
|
+
*/
|
|
1031
|
+
interface PresenceEntry<TData$1 = unknown> {
|
|
1032
|
+
/** The presence data */
|
|
1033
|
+
readonly data: TData$1;
|
|
1034
|
+
/** Optional user ID from authentication */
|
|
1035
|
+
readonly userId?: string;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Creates a new Presence schema wrapper.
|
|
1039
|
+
*
|
|
1040
|
+
* @example
|
|
1041
|
+
* ```typescript
|
|
1042
|
+
* import { Presence } from "@voidhash/mimic";
|
|
1043
|
+
* import { Schema } from "effect";
|
|
1044
|
+
*
|
|
1045
|
+
* const CursorPresence = Presence.make({
|
|
1046
|
+
* schema: Schema.Struct({
|
|
1047
|
+
* name: Schema.String,
|
|
1048
|
+
* cursor: Schema.Struct({
|
|
1049
|
+
* x: Schema.Number,
|
|
1050
|
+
* y: Schema.Number,
|
|
1051
|
+
* }),
|
|
1052
|
+
* }),
|
|
1053
|
+
* });
|
|
1054
|
+
* ```
|
|
1055
|
+
*/
|
|
1056
|
+
declare const make: <TData$1>(options: PresenceOptions<TData$1>) => Presence<TData$1>;
|
|
1057
|
+
/**
|
|
1058
|
+
* Validates unknown data against a Presence schema.
|
|
1059
|
+
* Throws a ParseError if validation fails.
|
|
1060
|
+
*
|
|
1061
|
+
* @param presence - The Presence instance with the schema
|
|
1062
|
+
* @param data - Unknown data to validate
|
|
1063
|
+
* @returns The validated and typed data
|
|
1064
|
+
* @throws ParseError if validation fails
|
|
1065
|
+
*/
|
|
1066
|
+
declare const validate: <TData$1>(presence: Presence<TData$1>, data: unknown) => TData$1;
|
|
1067
|
+
/**
|
|
1068
|
+
* Safely validates unknown data against a Presence schema.
|
|
1069
|
+
* Returns undefined if validation fails instead of throwing.
|
|
1070
|
+
*
|
|
1071
|
+
* @param presence - The Presence instance with the schema
|
|
1072
|
+
* @param data - Unknown data to validate
|
|
1073
|
+
* @returns The validated data or undefined if invalid
|
|
1074
|
+
*/
|
|
1075
|
+
declare const validateSafe: <TData$1>(presence: Presence<TData$1>, data: unknown) => TData$1 | undefined;
|
|
1076
|
+
/**
|
|
1077
|
+
* Checks if unknown data is valid according to a Presence schema.
|
|
1078
|
+
*
|
|
1079
|
+
* @param presence - The Presence instance with the schema
|
|
1080
|
+
* @param data - Unknown data to check
|
|
1081
|
+
* @returns true if valid, false otherwise
|
|
1082
|
+
*/
|
|
1083
|
+
declare const isValid: <TData$1>(presence: Presence<TData$1>, data: unknown) => data is TData$1;
|
|
1084
|
+
//#endregion
|
|
1085
|
+
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 };
|
|
1086
|
+
//# sourceMappingURL=index.d.mts.map
|