doxum 0.1.25 → 0.1.26

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.
@@ -85,23 +85,65 @@ type TreeNode<TValue, ValueOptional extends boolean = false> = BaseNode<'tree'>
85
85
  };
86
86
  type DocumentNode = FieldNode<unknown, false> | FieldNode<unknown, true> | ObjectNode<ObjectShape> | VariantNode<string, VariantShape> | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
87
87
  declare const schemaType: unique symbol;
88
- declare const schemaNode: unique symbol;
89
88
  declare const objectSchema: unique symbol;
90
- type Schema<T = unknown> = {
91
- readonly [schemaType]: T;
89
+ /** Portable public schema handle. The definition parameter carries compile-time shape only. */
90
+ type Schema<T = unknown, Definition = unknown> = {
91
+ readonly [schemaType]: {
92
+ readonly value: T;
93
+ readonly definition: Definition;
94
+ };
95
+ };
96
+ type PublicSchemaShape = {
97
+ readonly [key: string]: Schema<unknown, unknown>;
92
98
  };
93
- type ObjectSchema<T extends object = object> = Schema<T> & {
99
+ type ObjectSchema<T extends object = object, Shape extends PublicSchemaShape = PublicSchemaShape> = Schema<T, {
100
+ readonly kind: 'object';
101
+ readonly shape: Shape;
102
+ }> & {
94
103
  readonly [objectSchema]: true;
95
104
  };
96
- type SchemaNodeOf<S extends Schema<unknown>> = S extends {
97
- readonly [schemaNode]: infer N extends DocumentNode;
98
- } ? N : S extends ObjectSchema<object> ? ObjectNode : DocumentNode;
105
+ type SchemaDefinitionOf<S extends Schema<unknown, unknown>> = S extends Schema<unknown, infer Definition> ? Definition : unknown;
106
+ type Optionalized<N extends DocumentNode, Optional extends boolean> = Optional extends true ? OptionalNode<N> : N;
107
+ type FieldNodeFor<TValue, Optional extends boolean> = Optional extends true ? FieldNode<TValue, true> : FieldNode<TValue, false>;
108
+ type TreeNodeFor<TValue, ValueOptional extends boolean> = ValueOptional extends true ? TreeNode<TValue, true> : TreeNode<TValue, false>;
109
+ type SchemaNodeFromDefinition<Definition> = Definition extends {
110
+ readonly kind: 'field';
111
+ readonly value: infer TValue;
112
+ readonly optional: infer Optional extends boolean;
113
+ } ? FieldNodeFor<TValue, Optional> : Definition extends {
114
+ readonly kind: 'object';
115
+ readonly shape: infer Shape extends PublicSchemaShape;
116
+ } ? ObjectNode<NodeShapeOf<Shape>> : Definition extends {
117
+ readonly kind: 'variant';
118
+ readonly tag: infer Tag extends string;
119
+ readonly variants: infer Variants extends PublicVariantShape;
120
+ readonly optional: infer Optional extends boolean;
121
+ } ? Optionalized<VariantNode<Tag, VariantNodeShapeOf<Variants>>, Optional> : Definition extends {
122
+ readonly kind: 'table';
123
+ readonly value: infer Value extends Schema<unknown, unknown>;
124
+ readonly key: infer Key extends string;
125
+ } ? TableNode<Extract<SchemaNodeOf<Value>, EntitySchemaNode>, Key> : Definition extends {
126
+ readonly kind: 'map';
127
+ readonly value: infer Value extends Schema<unknown, unknown>;
128
+ readonly key: infer Key extends string;
129
+ readonly optional: infer Optional extends boolean;
130
+ } ? Optionalized<MapNode<Extract<SchemaNodeOf<Value>, ValueSchemaNode>, Key>, Optional> : Definition extends {
131
+ readonly kind: 'list';
132
+ readonly value: infer TValue;
133
+ readonly optional: infer Optional extends boolean;
134
+ } ? Optionalized<ListNode<TValue>, Optional> : Definition extends {
135
+ readonly kind: 'tree';
136
+ readonly value: infer TValue;
137
+ readonly valueOptional: infer ValueOptional extends boolean;
138
+ readonly optional: infer Optional extends boolean;
139
+ } ? Optionalized<TreeNodeFor<TValue, ValueOptional>, Optional> : DocumentNode;
140
+ type SchemaNodeOf<S extends Schema<unknown, unknown>> = SchemaNodeFromDefinition<SchemaDefinitionOf<S>>;
99
141
  type SchemaObject<T> = { [K in keyof T]: T[K] } & {};
100
142
  /** Infer a document or node value, including optional node presence. */
101
143
  type InferNode<T extends DocumentNode> = T extends {
102
144
  readonly optional: true;
103
145
  } ? NodeValue<T> | undefined : NodeValue<T>;
104
- type Infer<T extends Schema<unknown> | DocumentNode> = T extends Schema<infer TValue> ? TValue : T extends DocumentNode ? InferNode<T> : never;
146
+ type Infer<T extends Schema<unknown, unknown> | DocumentNode> = T extends Schema<infer TValue, unknown> ? TValue : T extends DocumentNode ? InferNode<T> : never;
105
147
  type NodeValue<N> = N extends FieldNode<infer T, infer O> ? O extends true ? ReadonlyValue<T> | undefined : ReadonlyValue<T> : N extends ObjectNode<infer S> ? ShapeValue<S> : N extends VariantNode<infer T, infer V> ? { [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & NodeValue<V[K]>> }[keyof V & string] : N extends TableNode<infer V, infer K> ? {
106
148
  readonly ids: readonly K[];
107
149
  readonly byId: Readonly<Record<K, NodeValue<V>>>;
@@ -121,56 +163,141 @@ type DocumentAnchor<K extends string = string> = {
121
163
  } | {
122
164
  readonly after: K;
123
165
  };
124
- type SchemaHandle<N extends DocumentNode> = Schema<InferNode<N>> & {
125
- readonly [schemaNode]: N;
126
- };
127
- type PublicSchemaShape = {
128
- readonly [key: string]: Schema<unknown>;
129
- };
130
166
  type NodeShapeOf<S extends PublicSchemaShape> = { readonly [K in keyof S]: SchemaNodeOf<S[K]> };
131
167
  type PublicOptionalKeys<S extends PublicSchemaShape> = { [K in keyof S]: SchemaNodeOf<S[K]> extends {
132
168
  readonly optional: true;
133
169
  } ? K : never }[keyof S];
134
170
  type PublicRequiredKeys<S extends PublicSchemaShape> = Exclude<keyof S, PublicOptionalKeys<S>>;
135
171
  type PublicShapeValue<S extends PublicSchemaShape> = SchemaObject<{ readonly [K in PublicRequiredKeys<S>]: Infer<S[K]> } & { readonly [K in PublicOptionalKeys<S>]?: Infer<S[K]> }>;
136
- type ObjectSchemaHandle<S extends PublicSchemaShape> = ObjectSchema<PublicShapeValue<S>> & {
137
- readonly [schemaNode]: ObjectNode<NodeShapeOf<S>>;
138
- };
139
- type FieldSchemaHandle<T> = SchemaHandle<FieldNode<T, false>>;
140
- type OptionalFieldSchemaHandle<T> = SchemaHandle<FieldNode<T, true>>;
141
- type OptionalSchemaHandle = Schema<unknown> & {
142
- readonly [schemaNode]: OptionalLeaf;
143
- };
144
- type EntitySchemaHandle = Schema<unknown> & {
145
- readonly [schemaNode]: EntitySchemaNode;
146
- };
147
- type ValueSchemaHandle = Schema<unknown> & {
148
- readonly [schemaNode]: ValueSchemaNode;
149
- };
150
172
  type PublicVariantShape = {
151
173
  readonly [key: string]: ObjectSchema<object>;
152
174
  };
153
175
  type VariantNodeShapeOf<V extends PublicVariantShape> = { readonly [K in keyof V]: Extract<SchemaNodeOf<V[K]>, ObjectNode> };
154
- type VariantSchemaHandle<T extends string, V extends PublicVariantShape> = Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string]> & {
155
- readonly [schemaNode]: VariantNode<T, VariantNodeShapeOf<V>>;
156
- };
157
- type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
158
- type OptionalResult<T extends OptionalSchemaHandle> = SchemaHandle<OptionalNode<Extract<SchemaNodeOf<T>, OptionalLeaf>>>;
159
- type EntityNodeOf<V extends EntitySchemaHandle> = Extract<SchemaNodeOf<V>, EntitySchemaNode>;
160
- type ValueNodeOf<V extends ValueSchemaHandle> = Extract<SchemaNodeOf<V>, ValueSchemaNode>;
161
- declare const field: <T>(validator?: Validator<T>) => FieldSchemaHandle<T>;
162
- declare const optional: <T extends OptionalSchemaHandle>(value: T) => OptionalResult<T>;
163
- declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchemaHandle<S>;
164
- declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => VariantSchemaHandle<T, V>;
165
- declare const table: <V extends EntitySchemaHandle, K extends string = string>(value: V, options?: {
176
+ type FieldSchema<T, Optional extends boolean = boolean> = Schema<ReadonlyValue<T> | (Optional extends true ? undefined : never), {
177
+ readonly kind: 'field';
178
+ readonly value: T;
179
+ readonly optional: Optional;
180
+ }>;
181
+ type VariantSchema = Schema<unknown, {
182
+ readonly kind: 'variant';
183
+ readonly tag: string;
184
+ readonly variants: PublicVariantShape;
185
+ readonly optional: boolean;
186
+ }>;
187
+ type EntitySchema = ObjectSchema<object> | VariantSchema;
188
+ type ValueSchema = EntitySchema | FieldSchema<unknown>;
189
+ declare const field: <T>(validator?: Validator<T>) => Schema<ReadonlyValue<T>, {
190
+ readonly kind: "field";
191
+ readonly value: T;
192
+ readonly optional: false;
193
+ }>;
194
+ declare function optional<T, Optional extends boolean>(value: Schema<ReadonlyValue<T> | (Optional extends true ? undefined : never), {
195
+ readonly kind: 'field';
196
+ readonly value: T;
197
+ readonly optional: Optional;
198
+ }>): Schema<ReadonlyValue<T> | undefined, {
199
+ readonly kind: 'field';
200
+ readonly value: T;
201
+ readonly optional: true;
202
+ }>;
203
+ declare function optional<TValue, Tag extends string, Variants extends PublicVariantShape, Optional extends boolean>(value: Schema<TValue, {
204
+ readonly kind: 'variant';
205
+ readonly tag: Tag;
206
+ readonly variants: Variants;
207
+ readonly optional: Optional;
208
+ }>): Schema<TValue | undefined, {
209
+ readonly kind: 'variant';
210
+ readonly tag: Tag;
211
+ readonly variants: Variants;
212
+ readonly optional: true;
213
+ }>;
214
+ declare function optional<TValue, Value extends Schema<unknown, unknown>, Key extends string, Optional extends boolean>(value: Schema<TValue, {
215
+ readonly kind: 'map';
216
+ readonly value: Value;
217
+ readonly key: Key;
218
+ readonly optional: Optional;
219
+ }>): Schema<TValue | undefined, {
220
+ readonly kind: 'map';
221
+ readonly value: Value;
222
+ readonly key: Key;
223
+ readonly optional: true;
224
+ }>;
225
+ declare function optional<TValue, TItem, Optional extends boolean>(value: Schema<TValue, {
226
+ readonly kind: 'list';
227
+ readonly value: TItem;
228
+ readonly optional: Optional;
229
+ }>): Schema<TValue | undefined, {
230
+ readonly kind: 'list';
231
+ readonly value: TItem;
232
+ readonly optional: true;
233
+ }>;
234
+ declare function optional<TValue, TNodeValue, ValueOptional extends boolean, Optional extends boolean>(value: Schema<TValue, {
235
+ readonly kind: 'tree';
236
+ readonly value: TNodeValue;
237
+ readonly valueOptional: ValueOptional;
238
+ readonly optional: Optional;
239
+ }>): Schema<TValue | undefined, {
240
+ readonly kind: 'tree';
241
+ readonly value: TNodeValue;
242
+ readonly valueOptional: ValueOptional;
243
+ readonly optional: true;
244
+ }>;
245
+ declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchema<PublicShapeValue<S>, S>;
246
+ declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string], {
247
+ readonly kind: "variant";
248
+ readonly tag: T;
249
+ readonly variants: V;
250
+ readonly optional: false;
251
+ }>;
252
+ declare const table: <V extends EntitySchema, K extends string = string>(value: V, options?: {
166
253
  readonly key: Validator<K>;
167
- }) => SchemaHandle<TableNode<EntityNodeOf<V>, K>>;
168
- declare const map: <V extends ValueSchemaHandle, K extends string = string>(value: V, options?: {
254
+ }) => Schema<{
255
+ readonly ids: readonly K[];
256
+ readonly byId: Readonly<Record<K, Exclude<Infer<V>, undefined>>>;
257
+ }, {
258
+ readonly kind: "table";
259
+ readonly value: V;
260
+ readonly key: K;
261
+ }>;
262
+ declare const map: <V extends ValueSchema, K extends string = string>(value: V, options?: {
169
263
  readonly key: Validator<K>;
170
- }) => SchemaHandle<MapNode<ValueNodeOf<V>, K>>;
171
- declare const list: <TItem>(value: FieldSchemaHandle<TItem>, config: DocumentListConfig<TItem>) => SchemaHandle<ListNode<TItem>>;
172
- declare function tree<TValue>(value: FieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, false>>;
173
- declare function tree<TValue>(value: OptionalFieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, true>>;
264
+ }) => Schema<Readonly<Record<K, V extends Schema<infer TValue, infer Definition> ? Definition extends {
265
+ readonly kind: "field";
266
+ } ? TValue : Exclude<TValue, undefined> : never>>, {
267
+ readonly kind: "map";
268
+ readonly value: V;
269
+ readonly key: K;
270
+ readonly optional: false;
271
+ }>;
272
+ declare const list: <TItem>(value: Schema<ReadonlyValue<TItem>, {
273
+ readonly kind: "field";
274
+ readonly value: TItem;
275
+ readonly optional: false;
276
+ }>, config: DocumentListConfig<TItem>) => Schema<readonly ReadonlyValue<TItem>[], {
277
+ readonly kind: "list";
278
+ readonly value: TItem;
279
+ readonly optional: false;
280
+ }>;
281
+ declare function tree<TValue>(value: Schema<ReadonlyValue<TValue>, {
282
+ readonly kind: 'field';
283
+ readonly value: TValue;
284
+ readonly optional: false;
285
+ }>): Schema<DocumentTreeValue<TValue, false>, {
286
+ readonly kind: 'tree';
287
+ readonly value: TValue;
288
+ readonly valueOptional: false;
289
+ readonly optional: false;
290
+ }>;
291
+ declare function tree<TValue>(value: Schema<ReadonlyValue<TValue> | undefined, {
292
+ readonly kind: 'field';
293
+ readonly value: TValue;
294
+ readonly optional: true;
295
+ }>): Schema<DocumentTreeValue<TValue, true>, {
296
+ readonly kind: 'tree';
297
+ readonly value: TValue;
298
+ readonly valueOptional: true;
299
+ readonly optional: false;
300
+ }>;
174
301
  //#endregion
175
302
  //#region core/src/schema/path.d.ts
176
303
  declare const pathValue: unique symbol;
@@ -491,4 +618,4 @@ type DocumentRuntime<S extends ObjectSchema<object>> = ReadonlyDocument<S> & {
491
618
  };
492
619
  //#endregion
493
620
  export { table as $, ParseError as A, DocumentListConfig as B, Read as C, ChangeSet as D, Change as E, CollectionPath as F, ReadonlyValue as G, DocumentTreeValue as H, PathValueOf as I, field as J, Schema as K, SchemaPath as L, parse as M, CollectionEntry as N, MemberChange as O, CollectionId as P, optional as Q, DocumentAddress as R, Draft as S, snapshot as T, Infer as U, DocumentTreeNode as V, ObjectSchema as W, map as X, list as Y, object as Z, Unsubscribe as _, DocumentProblem as a, CollectionImpact as b, HistoryState as c, OperationResult as d, tree as et, ReadonlyDocument as f, Readable as g, TransactionResult as h, DocumentDisposedError as i, ParseIssue as j, ValueTransition as k, LocalHistory as l, TransactionRejected as m, DocumentCommit as n, DocumentReentrancyError as o, Synchronous as p, Validator as q, DocumentDiagnostic as r, DocumentRuntime as s, CommitSource as t, variant as tt, ObserverError as u, MutationIssue as v, replace as w, DocumentImpact as x, MutationIssueCode as y, DocumentAnchor as z };
494
- //# sourceMappingURL=contract-Dawq6LKS.d.ts.map
621
+ //# sourceMappingURL=contract-CNR6BS75.d.cts.map
@@ -85,23 +85,65 @@ type TreeNode<TValue, ValueOptional extends boolean = false> = BaseNode<'tree'>
85
85
  };
86
86
  type DocumentNode = FieldNode<unknown, false> | FieldNode<unknown, true> | ObjectNode<ObjectShape> | VariantNode<string, VariantShape> | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
87
87
  declare const schemaType: unique symbol;
88
- declare const schemaNode: unique symbol;
89
88
  declare const objectSchema: unique symbol;
90
- type Schema<T = unknown> = {
91
- readonly [schemaType]: T;
89
+ /** Portable public schema handle. The definition parameter carries compile-time shape only. */
90
+ type Schema<T = unknown, Definition = unknown> = {
91
+ readonly [schemaType]: {
92
+ readonly value: T;
93
+ readonly definition: Definition;
94
+ };
95
+ };
96
+ type PublicSchemaShape = {
97
+ readonly [key: string]: Schema<unknown, unknown>;
92
98
  };
93
- type ObjectSchema<T extends object = object> = Schema<T> & {
99
+ type ObjectSchema<T extends object = object, Shape extends PublicSchemaShape = PublicSchemaShape> = Schema<T, {
100
+ readonly kind: 'object';
101
+ readonly shape: Shape;
102
+ }> & {
94
103
  readonly [objectSchema]: true;
95
104
  };
96
- type SchemaNodeOf<S extends Schema<unknown>> = S extends {
97
- readonly [schemaNode]: infer N extends DocumentNode;
98
- } ? N : S extends ObjectSchema<object> ? ObjectNode : DocumentNode;
105
+ type SchemaDefinitionOf<S extends Schema<unknown, unknown>> = S extends Schema<unknown, infer Definition> ? Definition : unknown;
106
+ type Optionalized<N extends DocumentNode, Optional extends boolean> = Optional extends true ? OptionalNode<N> : N;
107
+ type FieldNodeFor<TValue, Optional extends boolean> = Optional extends true ? FieldNode<TValue, true> : FieldNode<TValue, false>;
108
+ type TreeNodeFor<TValue, ValueOptional extends boolean> = ValueOptional extends true ? TreeNode<TValue, true> : TreeNode<TValue, false>;
109
+ type SchemaNodeFromDefinition<Definition> = Definition extends {
110
+ readonly kind: 'field';
111
+ readonly value: infer TValue;
112
+ readonly optional: infer Optional extends boolean;
113
+ } ? FieldNodeFor<TValue, Optional> : Definition extends {
114
+ readonly kind: 'object';
115
+ readonly shape: infer Shape extends PublicSchemaShape;
116
+ } ? ObjectNode<NodeShapeOf<Shape>> : Definition extends {
117
+ readonly kind: 'variant';
118
+ readonly tag: infer Tag extends string;
119
+ readonly variants: infer Variants extends PublicVariantShape;
120
+ readonly optional: infer Optional extends boolean;
121
+ } ? Optionalized<VariantNode<Tag, VariantNodeShapeOf<Variants>>, Optional> : Definition extends {
122
+ readonly kind: 'table';
123
+ readonly value: infer Value extends Schema<unknown, unknown>;
124
+ readonly key: infer Key extends string;
125
+ } ? TableNode<Extract<SchemaNodeOf<Value>, EntitySchemaNode>, Key> : Definition extends {
126
+ readonly kind: 'map';
127
+ readonly value: infer Value extends Schema<unknown, unknown>;
128
+ readonly key: infer Key extends string;
129
+ readonly optional: infer Optional extends boolean;
130
+ } ? Optionalized<MapNode<Extract<SchemaNodeOf<Value>, ValueSchemaNode>, Key>, Optional> : Definition extends {
131
+ readonly kind: 'list';
132
+ readonly value: infer TValue;
133
+ readonly optional: infer Optional extends boolean;
134
+ } ? Optionalized<ListNode<TValue>, Optional> : Definition extends {
135
+ readonly kind: 'tree';
136
+ readonly value: infer TValue;
137
+ readonly valueOptional: infer ValueOptional extends boolean;
138
+ readonly optional: infer Optional extends boolean;
139
+ } ? Optionalized<TreeNodeFor<TValue, ValueOptional>, Optional> : DocumentNode;
140
+ type SchemaNodeOf<S extends Schema<unknown, unknown>> = SchemaNodeFromDefinition<SchemaDefinitionOf<S>>;
99
141
  type SchemaObject<T> = { [K in keyof T]: T[K] } & {};
100
142
  /** Infer a document or node value, including optional node presence. */
101
143
  type InferNode<T extends DocumentNode> = T extends {
102
144
  readonly optional: true;
103
145
  } ? NodeValue<T> | undefined : NodeValue<T>;
104
- type Infer<T extends Schema<unknown> | DocumentNode> = T extends Schema<infer TValue> ? TValue : T extends DocumentNode ? InferNode<T> : never;
146
+ type Infer<T extends Schema<unknown, unknown> | DocumentNode> = T extends Schema<infer TValue, unknown> ? TValue : T extends DocumentNode ? InferNode<T> : never;
105
147
  type NodeValue<N> = N extends FieldNode<infer T, infer O> ? O extends true ? ReadonlyValue<T> | undefined : ReadonlyValue<T> : N extends ObjectNode<infer S> ? ShapeValue<S> : N extends VariantNode<infer T, infer V> ? { [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & NodeValue<V[K]>> }[keyof V & string] : N extends TableNode<infer V, infer K> ? {
106
148
  readonly ids: readonly K[];
107
149
  readonly byId: Readonly<Record<K, NodeValue<V>>>;
@@ -121,56 +163,141 @@ type DocumentAnchor<K extends string = string> = {
121
163
  } | {
122
164
  readonly after: K;
123
165
  };
124
- type SchemaHandle<N extends DocumentNode> = Schema<InferNode<N>> & {
125
- readonly [schemaNode]: N;
126
- };
127
- type PublicSchemaShape = {
128
- readonly [key: string]: Schema<unknown>;
129
- };
130
166
  type NodeShapeOf<S extends PublicSchemaShape> = { readonly [K in keyof S]: SchemaNodeOf<S[K]> };
131
167
  type PublicOptionalKeys<S extends PublicSchemaShape> = { [K in keyof S]: SchemaNodeOf<S[K]> extends {
132
168
  readonly optional: true;
133
169
  } ? K : never }[keyof S];
134
170
  type PublicRequiredKeys<S extends PublicSchemaShape> = Exclude<keyof S, PublicOptionalKeys<S>>;
135
171
  type PublicShapeValue<S extends PublicSchemaShape> = SchemaObject<{ readonly [K in PublicRequiredKeys<S>]: Infer<S[K]> } & { readonly [K in PublicOptionalKeys<S>]?: Infer<S[K]> }>;
136
- type ObjectSchemaHandle<S extends PublicSchemaShape> = ObjectSchema<PublicShapeValue<S>> & {
137
- readonly [schemaNode]: ObjectNode<NodeShapeOf<S>>;
138
- };
139
- type FieldSchemaHandle<T> = SchemaHandle<FieldNode<T, false>>;
140
- type OptionalFieldSchemaHandle<T> = SchemaHandle<FieldNode<T, true>>;
141
- type OptionalSchemaHandle = Schema<unknown> & {
142
- readonly [schemaNode]: OptionalLeaf;
143
- };
144
- type EntitySchemaHandle = Schema<unknown> & {
145
- readonly [schemaNode]: EntitySchemaNode;
146
- };
147
- type ValueSchemaHandle = Schema<unknown> & {
148
- readonly [schemaNode]: ValueSchemaNode;
149
- };
150
172
  type PublicVariantShape = {
151
173
  readonly [key: string]: ObjectSchema<object>;
152
174
  };
153
175
  type VariantNodeShapeOf<V extends PublicVariantShape> = { readonly [K in keyof V]: Extract<SchemaNodeOf<V[K]>, ObjectNode> };
154
- type VariantSchemaHandle<T extends string, V extends PublicVariantShape> = Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string]> & {
155
- readonly [schemaNode]: VariantNode<T, VariantNodeShapeOf<V>>;
156
- };
157
- type OptionalLeaf = FieldNode<unknown, boolean> | VariantNode<string, VariantShape> | MapNode<ValueSchemaNode> | ListNode<unknown> | TreeNode<unknown, false> | TreeNode<unknown, true>;
158
- type OptionalResult<T extends OptionalSchemaHandle> = SchemaHandle<OptionalNode<Extract<SchemaNodeOf<T>, OptionalLeaf>>>;
159
- type EntityNodeOf<V extends EntitySchemaHandle> = Extract<SchemaNodeOf<V>, EntitySchemaNode>;
160
- type ValueNodeOf<V extends ValueSchemaHandle> = Extract<SchemaNodeOf<V>, ValueSchemaNode>;
161
- declare const field: <T>(validator?: Validator<T>) => FieldSchemaHandle<T>;
162
- declare const optional: <T extends OptionalSchemaHandle>(value: T) => OptionalResult<T>;
163
- declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchemaHandle<S>;
164
- declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => VariantSchemaHandle<T, V>;
165
- declare const table: <V extends EntitySchemaHandle, K extends string = string>(value: V, options?: {
176
+ type FieldSchema<T, Optional extends boolean = boolean> = Schema<ReadonlyValue<T> | (Optional extends true ? undefined : never), {
177
+ readonly kind: 'field';
178
+ readonly value: T;
179
+ readonly optional: Optional;
180
+ }>;
181
+ type VariantSchema = Schema<unknown, {
182
+ readonly kind: 'variant';
183
+ readonly tag: string;
184
+ readonly variants: PublicVariantShape;
185
+ readonly optional: boolean;
186
+ }>;
187
+ type EntitySchema = ObjectSchema<object> | VariantSchema;
188
+ type ValueSchema = EntitySchema | FieldSchema<unknown>;
189
+ declare const field: <T>(validator?: Validator<T>) => Schema<ReadonlyValue<T>, {
190
+ readonly kind: "field";
191
+ readonly value: T;
192
+ readonly optional: false;
193
+ }>;
194
+ declare function optional<T, Optional extends boolean>(value: Schema<ReadonlyValue<T> | (Optional extends true ? undefined : never), {
195
+ readonly kind: 'field';
196
+ readonly value: T;
197
+ readonly optional: Optional;
198
+ }>): Schema<ReadonlyValue<T> | undefined, {
199
+ readonly kind: 'field';
200
+ readonly value: T;
201
+ readonly optional: true;
202
+ }>;
203
+ declare function optional<TValue, Tag extends string, Variants extends PublicVariantShape, Optional extends boolean>(value: Schema<TValue, {
204
+ readonly kind: 'variant';
205
+ readonly tag: Tag;
206
+ readonly variants: Variants;
207
+ readonly optional: Optional;
208
+ }>): Schema<TValue | undefined, {
209
+ readonly kind: 'variant';
210
+ readonly tag: Tag;
211
+ readonly variants: Variants;
212
+ readonly optional: true;
213
+ }>;
214
+ declare function optional<TValue, Value extends Schema<unknown, unknown>, Key extends string, Optional extends boolean>(value: Schema<TValue, {
215
+ readonly kind: 'map';
216
+ readonly value: Value;
217
+ readonly key: Key;
218
+ readonly optional: Optional;
219
+ }>): Schema<TValue | undefined, {
220
+ readonly kind: 'map';
221
+ readonly value: Value;
222
+ readonly key: Key;
223
+ readonly optional: true;
224
+ }>;
225
+ declare function optional<TValue, TItem, Optional extends boolean>(value: Schema<TValue, {
226
+ readonly kind: 'list';
227
+ readonly value: TItem;
228
+ readonly optional: Optional;
229
+ }>): Schema<TValue | undefined, {
230
+ readonly kind: 'list';
231
+ readonly value: TItem;
232
+ readonly optional: true;
233
+ }>;
234
+ declare function optional<TValue, TNodeValue, ValueOptional extends boolean, Optional extends boolean>(value: Schema<TValue, {
235
+ readonly kind: 'tree';
236
+ readonly value: TNodeValue;
237
+ readonly valueOptional: ValueOptional;
238
+ readonly optional: Optional;
239
+ }>): Schema<TValue | undefined, {
240
+ readonly kind: 'tree';
241
+ readonly value: TNodeValue;
242
+ readonly valueOptional: ValueOptional;
243
+ readonly optional: true;
244
+ }>;
245
+ declare const object: <S extends PublicSchemaShape>(shape: S) => ObjectSchema<PublicShapeValue<S>, S>;
246
+ declare const variant: <T extends string, V extends PublicVariantShape>(tag: T, variants: V) => Schema<{ [K in keyof V & string]: SchemaObject<{ readonly [P in T]: K } & Infer<V[K]>> }[keyof V & string], {
247
+ readonly kind: "variant";
248
+ readonly tag: T;
249
+ readonly variants: V;
250
+ readonly optional: false;
251
+ }>;
252
+ declare const table: <V extends EntitySchema, K extends string = string>(value: V, options?: {
166
253
  readonly key: Validator<K>;
167
- }) => SchemaHandle<TableNode<EntityNodeOf<V>, K>>;
168
- declare const map: <V extends ValueSchemaHandle, K extends string = string>(value: V, options?: {
254
+ }) => Schema<{
255
+ readonly ids: readonly K[];
256
+ readonly byId: Readonly<Record<K, Exclude<Infer<V>, undefined>>>;
257
+ }, {
258
+ readonly kind: "table";
259
+ readonly value: V;
260
+ readonly key: K;
261
+ }>;
262
+ declare const map: <V extends ValueSchema, K extends string = string>(value: V, options?: {
169
263
  readonly key: Validator<K>;
170
- }) => SchemaHandle<MapNode<ValueNodeOf<V>, K>>;
171
- declare const list: <TItem>(value: FieldSchemaHandle<TItem>, config: DocumentListConfig<TItem>) => SchemaHandle<ListNode<TItem>>;
172
- declare function tree<TValue>(value: FieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, false>>;
173
- declare function tree<TValue>(value: OptionalFieldSchemaHandle<TValue>): SchemaHandle<TreeNode<TValue, true>>;
264
+ }) => Schema<Readonly<Record<K, V extends Schema<infer TValue, infer Definition> ? Definition extends {
265
+ readonly kind: "field";
266
+ } ? TValue : Exclude<TValue, undefined> : never>>, {
267
+ readonly kind: "map";
268
+ readonly value: V;
269
+ readonly key: K;
270
+ readonly optional: false;
271
+ }>;
272
+ declare const list: <TItem>(value: Schema<ReadonlyValue<TItem>, {
273
+ readonly kind: "field";
274
+ readonly value: TItem;
275
+ readonly optional: false;
276
+ }>, config: DocumentListConfig<TItem>) => Schema<readonly ReadonlyValue<TItem>[], {
277
+ readonly kind: "list";
278
+ readonly value: TItem;
279
+ readonly optional: false;
280
+ }>;
281
+ declare function tree<TValue>(value: Schema<ReadonlyValue<TValue>, {
282
+ readonly kind: 'field';
283
+ readonly value: TValue;
284
+ readonly optional: false;
285
+ }>): Schema<DocumentTreeValue<TValue, false>, {
286
+ readonly kind: 'tree';
287
+ readonly value: TValue;
288
+ readonly valueOptional: false;
289
+ readonly optional: false;
290
+ }>;
291
+ declare function tree<TValue>(value: Schema<ReadonlyValue<TValue> | undefined, {
292
+ readonly kind: 'field';
293
+ readonly value: TValue;
294
+ readonly optional: true;
295
+ }>): Schema<DocumentTreeValue<TValue, true>, {
296
+ readonly kind: 'tree';
297
+ readonly value: TValue;
298
+ readonly valueOptional: true;
299
+ readonly optional: false;
300
+ }>;
174
301
  //#endregion
175
302
  //#region core/src/schema/path.d.ts
176
303
  declare const pathValue: unique symbol;
@@ -491,4 +618,4 @@ type DocumentRuntime<S extends ObjectSchema<object>> = ReadonlyDocument<S> & {
491
618
  };
492
619
  //#endregion
493
620
  export { table as $, ParseError as A, DocumentListConfig as B, Read as C, ChangeSet as D, Change as E, CollectionPath as F, ReadonlyValue as G, DocumentTreeValue as H, PathValueOf as I, field as J, Schema as K, SchemaPath as L, parse as M, CollectionEntry as N, MemberChange as O, CollectionId as P, optional as Q, DocumentAddress as R, Draft as S, snapshot as T, Infer as U, DocumentTreeNode as V, ObjectSchema as W, map as X, list as Y, object as Z, Unsubscribe as _, DocumentProblem as a, CollectionImpact as b, HistoryState as c, OperationResult as d, tree as et, ReadonlyDocument as f, Readable as g, TransactionResult as h, DocumentDisposedError as i, ParseIssue as j, ValueTransition as k, LocalHistory as l, TransactionRejected as m, DocumentCommit as n, DocumentReentrancyError as o, Synchronous as p, Validator as q, DocumentDiagnostic as r, DocumentRuntime as s, CommitSource as t, variant as tt, ObserverError as u, MutationIssue as v, replace as w, DocumentImpact as x, MutationIssueCode as y, DocumentAnchor as z };
494
- //# sourceMappingURL=contract-DB8XvNt0.d.cts.map
621
+ //# sourceMappingURL=contract-COgxO5sv.d.ts.map
@@ -1,4 +1,4 @@
1
- import { _ as Unsubscribe, b as CollectionImpact } from "./contract-Dawq6LKS.js";
1
+ import { _ as Unsubscribe, b as CollectionImpact } from "./contract-CNR6BS75.cjs";
2
2
 
3
3
  //#region core/src/projection/contract.d.ts
4
4
  /** The one processor-facing collection transition protocol. */
@@ -74,24 +74,30 @@ declare class ProjectionDisposedError extends Error {
74
74
  //#endregion
75
75
  //#region core/src/projection/definition.d.ts
76
76
  declare const projectionDefinition: unique symbol;
77
- declare const projectionChanges: unique symbol;
77
+ declare const keyedProjection: unique symbol;
78
78
  declare const writableInput: unique symbol;
79
79
  declare const writableCollectionInput: unique symbol;
80
80
  /** A lazy output reference with no materialized Runtime state. */
81
81
  type Projection<T> = {
82
82
  readonly [projectionDefinition]: T;
83
83
  };
84
+ /** A projection whose output is a keyed collection with per-key change semantics. */
85
+ type KeyedProjection<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
86
+ readonly [keyedProjection]: {
87
+ readonly key: K;
88
+ readonly value: V;
89
+ };
90
+ };
84
91
  /** A writable source projection. */
85
92
  type Input<T> = Projection<T> & {
86
93
  readonly [writableInput]: true;
87
94
  };
88
95
  /** A writable keyed collection source projection. */
89
- type CollectionInput<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
96
+ type CollectionInput<K extends string, V> = KeyedProjection<K, V> & {
90
97
  readonly [writableCollectionInput]: {
91
98
  readonly key: K;
92
99
  readonly value: V;
93
100
  };
94
- readonly [projectionChanges]: CollectionChange<K, V>;
95
101
  };
96
102
  type CollectionInputDraft<K extends string, V> = {
97
103
  get(key: K): V | undefined;
@@ -99,12 +105,7 @@ type CollectionInputDraft<K extends string, V> = {
99
105
  set(key: K, value: V): void;
100
106
  remove(key: K): void;
101
107
  };
102
- type ProjectionWithChange<T, C> = Projection<T> & {
103
- readonly [projectionChanges]: C;
104
- };
105
- type ProjectionChange<P> = P extends {
106
- readonly [projectionChanges]: infer C;
107
- } ? C : undefined;
108
+ type ProjectionChange<P> = P extends KeyedProjection<infer K, infer V> ? CollectionChange<K, V> : undefined;
108
109
  //#endregion
109
- export { ProjectionChange as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, Projection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionWithChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
110
- //# sourceMappingURL=definition-DT1NpMul.d.ts.map
110
+ export { Projection as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, KeyedProjection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
111
+ //# sourceMappingURL=definition-CDOuvb5C.d.cts.map
@@ -1,4 +1,4 @@
1
- import { _ as Unsubscribe, b as CollectionImpact } from "./contract-DB8XvNt0.cjs";
1
+ import { _ as Unsubscribe, b as CollectionImpact } from "./contract-COgxO5sv.js";
2
2
 
3
3
  //#region core/src/projection/contract.d.ts
4
4
  /** The one processor-facing collection transition protocol. */
@@ -74,24 +74,30 @@ declare class ProjectionDisposedError extends Error {
74
74
  //#endregion
75
75
  //#region core/src/projection/definition.d.ts
76
76
  declare const projectionDefinition: unique symbol;
77
- declare const projectionChanges: unique symbol;
77
+ declare const keyedProjection: unique symbol;
78
78
  declare const writableInput: unique symbol;
79
79
  declare const writableCollectionInput: unique symbol;
80
80
  /** A lazy output reference with no materialized Runtime state. */
81
81
  type Projection<T> = {
82
82
  readonly [projectionDefinition]: T;
83
83
  };
84
+ /** A projection whose output is a keyed collection with per-key change semantics. */
85
+ type KeyedProjection<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
86
+ readonly [keyedProjection]: {
87
+ readonly key: K;
88
+ readonly value: V;
89
+ };
90
+ };
84
91
  /** A writable source projection. */
85
92
  type Input<T> = Projection<T> & {
86
93
  readonly [writableInput]: true;
87
94
  };
88
95
  /** A writable keyed collection source projection. */
89
- type CollectionInput<K extends string, V> = Projection<ReadonlyMap<K, V>> & {
96
+ type CollectionInput<K extends string, V> = KeyedProjection<K, V> & {
90
97
  readonly [writableCollectionInput]: {
91
98
  readonly key: K;
92
99
  readonly value: V;
93
100
  };
94
- readonly [projectionChanges]: CollectionChange<K, V>;
95
101
  };
96
102
  type CollectionInputDraft<K extends string, V> = {
97
103
  get(key: K): V | undefined;
@@ -99,12 +105,7 @@ type CollectionInputDraft<K extends string, V> = {
99
105
  set(key: K, value: V): void;
100
106
  remove(key: K): void;
101
107
  };
102
- type ProjectionWithChange<T, C> = Projection<T> & {
103
- readonly [projectionChanges]: C;
104
- };
105
- type ProjectionChange<P> = P extends {
106
- readonly [projectionChanges]: infer C;
107
- } ? C : undefined;
108
+ type ProjectionChange<P> = P extends KeyedProjection<infer K, infer V> ? CollectionChange<K, V> : undefined;
108
109
  //#endregion
109
- export { ProjectionChange as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, Projection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionWithChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
110
- //# sourceMappingURL=definition-CHVS-RDY.d.cts.map
110
+ export { Projection as a, CollectionDraft as c, ExternalCollectionRead as d, ExternalCollectionSource as f, ProjectionError as g, ProjectionDisposedError as h, KeyedProjection as i, CollectionRead as l, ExternalValueSource as m, CollectionInputDraft as n, ProjectionChange as o, ExternalValueEvent as p, Input as r, CollectionChange as s, CollectionInput as t, ExternalCollectionEvent as u };
111
+ //# sourceMappingURL=definition-xgk3YNBp.d.ts.map