document-model 6.2.3-dev.9 → 6.2.3-dev.91
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/README.md +0 -6
- package/dist/catalog-6zzASEUv.js +358 -0
- package/dist/catalog-6zzASEUv.js.map +1 -0
- package/dist/catalog-B3nJD57s.d.ts +85 -0
- package/dist/catalog-B3nJD57s.d.ts.map +1 -0
- package/dist/index.d.ts +588 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4439 -14
- package/dist/index.js.map +1 -1
- package/dist/mock.d.ts +2 -1
- package/dist/node.d.mts +10 -11
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +4 -2
- package/dist/node.mjs.map +1 -1
- package/dist/scalars.d.ts +39 -0
- package/dist/scalars.d.ts.map +1 -0
- package/dist/scalars.js +146 -0
- package/dist/scalars.js.map +1 -0
- package/dist/tooling.d.mts +121 -0
- package/dist/tooling.d.mts.map +1 -0
- package/dist/tooling.mjs +2655 -0
- package/dist/tooling.mjs.map +1 -0
- package/package.json +19 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as ScalarDefinition } from "./catalog-B3nJD57s.js";
|
|
2
|
+
import { Action, Actions, AssertIsDocumentOfType, AssertIsStateOfType, CreateState, DefinitionDiagnostic, DirectiveUseDefinition, DocumentAction, DocumentModelAction, DocumentModelDefinition, DocumentModelDocument, DocumentModelDocumentModelModule, DocumentModelModule, DocumentModelPHState, DocumentOperations, IsDocumentOfType, IsStateOfType, JsonValue, Operation, PHBaseState, PHDocument, PHDocumentHeader, SignalDispatch, UpgradeManifest, baseActions } from "@powerhousedao/shared/document-model";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { DispatchOutcome, DocumentDispatch, RejectedAction } from "@powerhousedao/shared/document-model/dispatch";
|
|
2
5
|
export * from "@powerhousedao/shared/document-model";
|
|
3
|
-
|
|
4
6
|
//#region src/controller.d.ts
|
|
5
7
|
type ScreamingSnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Lowercase<Head>}${Capitalize<ScreamingSnakeToCamel<Tail>>}` : Lowercase<S>;
|
|
6
|
-
type DocumentChangeEvent<TState extends PHBaseState = PHBaseState> = {
|
|
8
|
+
export type DocumentChangeEvent<TState extends PHBaseState = PHBaseState> = {
|
|
7
9
|
document: PHDocument<TState>;
|
|
8
10
|
};
|
|
9
|
-
type DocumentChangeListener<TState extends PHBaseState = PHBaseState> = (event: DocumentChangeEvent<TState>) => void;
|
|
10
|
-
type ActionMap<TAction extends Action, TReturn = void> = { [K in (TAction | DocumentAction)["type"] as ScreamingSnakeToCamel<K>]: (input: Extract<TAction | DocumentAction, {
|
|
11
|
+
export type DocumentChangeListener<TState extends PHBaseState = PHBaseState> = (event: DocumentChangeEvent<TState>) => void;
|
|
12
|
+
export type ActionMap<TAction extends Action, TReturn = void> = { [K in (TAction | DocumentAction)["type"] as ScreamingSnakeToCamel<K>]: (input: Extract<TAction | DocumentAction, {
|
|
11
13
|
type: K;
|
|
12
|
-
}>["input"]) => TReturn & ActionMap<TAction, TReturn
|
|
13
|
-
declare class PHDocumentController<TState extends PHBaseState> implements PHDocument<TState> {
|
|
14
|
+
}>["input"]) => TReturn & ActionMap<TAction, TReturn>; };
|
|
15
|
+
export declare class PHDocumentController<TState extends PHBaseState> implements PHDocument<TState> {
|
|
14
16
|
readonly module: DocumentModelModule<TState>;
|
|
15
17
|
protected _document: PHDocument<TState>;
|
|
16
18
|
private listeners;
|
|
@@ -25,11 +27,11 @@ declare class PHDocumentController<TState extends PHBaseState> implements PHDocu
|
|
|
25
27
|
private notifyListeners;
|
|
26
28
|
static forDocumentModel<TState extends PHBaseState, TAction extends Action>(module: DocumentModelModule<TState>): new (initialDocument?: PHDocument<TState>) => PHDocumentController<TState> & ActionMap<TAction, PHDocumentController<TState>>;
|
|
27
29
|
}
|
|
28
|
-
declare const DocumentModelController: new (initialDocument?: PHDocument<DocumentModelPHState> | undefined) => PHDocumentController<DocumentModelPHState> & ActionMap<DocumentModelAction, PHDocumentController<DocumentModelPHState>>;
|
|
30
|
+
export declare const DocumentModelController: new (initialDocument?: PHDocument<DocumentModelPHState> | undefined) => PHDocumentController<DocumentModelPHState> & ActionMap<DocumentModelAction, PHDocumentController<DocumentModelPHState>>;
|
|
29
31
|
//#endregion
|
|
30
32
|
//#region src/logger-types.d.ts
|
|
31
|
-
type LoggerErrorHandler = (...data: any[]) => void;
|
|
32
|
-
type ILogger = {
|
|
33
|
+
export type LoggerErrorHandler = (...data: any[]) => void;
|
|
34
|
+
export type ILogger = {
|
|
33
35
|
level: "verbose" | "debug" | "info" | "warn" | "error";
|
|
34
36
|
verbose: (message: string, ...replacements: any[]) => void;
|
|
35
37
|
debug: (message: string, ...replacements: any[]) => void;
|
|
@@ -48,7 +50,7 @@ declare const LOG_LEVELS: {
|
|
|
48
50
|
readonly warn: 3;
|
|
49
51
|
readonly error: 4;
|
|
50
52
|
};
|
|
51
|
-
declare class ConsoleLogger implements ILogger {
|
|
53
|
+
export declare class ConsoleLogger implements ILogger {
|
|
52
54
|
#private;
|
|
53
55
|
errorHandler: LoggerErrorHandler;
|
|
54
56
|
constructor(tags?: string[], handler?: LoggerErrorHandler);
|
|
@@ -61,21 +63,583 @@ declare class ConsoleLogger implements ILogger {
|
|
|
61
63
|
warn: (message: string, ...replacements: any[]) => void;
|
|
62
64
|
error: (message: string, ...replacements: any[]) => void;
|
|
63
65
|
}
|
|
64
|
-
declare const logger: ILogger;
|
|
65
|
-
declare const setLogLevel: (level: ILogger["level"]) => void;
|
|
66
|
-
declare const setErrorHandler: (handler: LoggerErrorHandler) => void;
|
|
67
|
-
declare const childLogger: (tags: string[]) => ILogger;
|
|
66
|
+
export declare const logger: ILogger;
|
|
67
|
+
export declare const setLogLevel: (level: ILogger["level"]) => void;
|
|
68
|
+
export declare const setErrorHandler: (handler: LoggerErrorHandler) => void;
|
|
69
|
+
export declare const childLogger: (tags: string[]) => ILogger;
|
|
68
70
|
//#endregion
|
|
69
71
|
//#region src/module.d.ts
|
|
70
|
-
declare const documentModelDocumentModelModule: DocumentModelDocumentModelModule;
|
|
72
|
+
export declare const documentModelDocumentModelModule: DocumentModelDocumentModelModule;
|
|
71
73
|
//#endregion
|
|
72
74
|
//#region src/state.d.ts
|
|
73
|
-
declare const isStateOfType: IsStateOfType<DocumentModelPHState>;
|
|
74
|
-
declare const assertIsStateOfType: AssertIsStateOfType<DocumentModelPHState>;
|
|
75
|
-
declare const isDocumentOfType: IsDocumentOfType<DocumentModelPHState>;
|
|
76
|
-
declare const assertIsDocumentOfType: AssertIsDocumentOfType<DocumentModelPHState>;
|
|
77
|
-
declare const documentModelCreateState: CreateState<DocumentModelPHState>;
|
|
78
|
-
declare function documentModelCreateDocument(state?: Partial<DocumentModelPHState>): DocumentModelDocument;
|
|
79
|
-
//#endregion
|
|
80
|
-
|
|
75
|
+
export declare const isStateOfType: IsStateOfType<DocumentModelPHState>;
|
|
76
|
+
export declare const assertIsStateOfType: AssertIsStateOfType<DocumentModelPHState>;
|
|
77
|
+
export declare const isDocumentOfType: IsDocumentOfType<DocumentModelPHState>;
|
|
78
|
+
export declare const assertIsDocumentOfType: AssertIsDocumentOfType<DocumentModelPHState>;
|
|
79
|
+
export declare const documentModelCreateState: CreateState<DocumentModelPHState>;
|
|
80
|
+
export declare function documentModelCreateDocument(state?: Partial<DocumentModelPHState>): DocumentModelDocument;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/definition/dsl/types.d.ts
|
|
83
|
+
type FieldValidationOptions<TRequired extends boolean = boolean> = {
|
|
84
|
+
readonly required?: TRequired;
|
|
85
|
+
};
|
|
86
|
+
type FieldTextOptions = {
|
|
87
|
+
readonly description?: string;
|
|
88
|
+
readonly deprecated?: string;
|
|
89
|
+
};
|
|
90
|
+
type EqualsOption = {
|
|
91
|
+
readonly equals?: string;
|
|
92
|
+
};
|
|
93
|
+
type JsonLiteral = string | number | boolean | null | readonly JsonLiteral[] | {
|
|
94
|
+
readonly [key: string]: JsonLiteral;
|
|
95
|
+
};
|
|
96
|
+
type FieldBuilderOptions<TRequired extends boolean = boolean, TDefault extends JsonLiteral | undefined = JsonLiteral | undefined> = FieldValidationOptions<TRequired> & FieldTextOptions & {
|
|
97
|
+
readonly defaultValue?: TDefault | (TDefault extends undefined ? JsonLiteral : never);
|
|
98
|
+
};
|
|
99
|
+
type ScalarBuilderOptions<TRequired extends boolean = boolean, TDefault extends JsonLiteral | undefined = JsonLiteral | undefined> = FieldBuilderOptions<TRequired, TDefault> & EqualsOption;
|
|
100
|
+
type IsLiteral<T> = T extends string ? string extends T ? false : true : T extends number ? number extends T ? false : true : T extends boolean ? boolean extends T ? false : true : T extends null ? true : T extends readonly unknown[] ? number extends T["length"] ? false : AllLiteral<T[number]> : T extends object ? string extends keyof T ? false : Partial<T> extends T ? [keyof T] extends [never] ? true : false : AllLiteral<T[keyof T]> : false;
|
|
101
|
+
type AllLiteral<T> = [T] extends [never] ? true : false extends IsLiteral<T> ? false : true;
|
|
102
|
+
type DefaultFlag<TDefault> = [TDefault] extends [undefined] ? false : undefined extends TDefault ? boolean : IsLiteral<TDefault> extends true ? true : boolean;
|
|
103
|
+
type ScalarBuilder<TBase, TInput = TBase> = <const TRequired extends boolean = false, const TDefault extends JsonLiteral | undefined = undefined>(options?: ScalarBuilderOptions<TRequired, TDefault>) => ScalarDescriptor<Nullable<TInput, TRequired>, Nullable<TBase, TRequired>, Nullable<TInput, TRequired>, TRequired, DefaultFlag<TDefault>>;
|
|
104
|
+
type FieldDefault = {
|
|
105
|
+
readonly present: false;
|
|
106
|
+
} | {
|
|
107
|
+
readonly present: true;
|
|
108
|
+
readonly value: JsonValue;
|
|
109
|
+
};
|
|
110
|
+
type FieldPresentation = {
|
|
111
|
+
readonly description: string | null;
|
|
112
|
+
readonly deprecated: string | null;
|
|
113
|
+
readonly default: FieldDefault;
|
|
114
|
+
readonly directives: readonly DirectiveUseDefinition[];
|
|
115
|
+
};
|
|
116
|
+
type NamedTypeKind = "enum" | "object" | "input" | "interface" | "union";
|
|
117
|
+
type FieldUseKind = "scalar" | "list" | "ref";
|
|
118
|
+
type DescriptorKind = NamedTypeKind | FieldUseKind;
|
|
119
|
+
type ScalarIdentity = {
|
|
120
|
+
readonly kind: "scalar";
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly required: boolean;
|
|
123
|
+
};
|
|
124
|
+
type ListIdentity = {
|
|
125
|
+
readonly kind: "list";
|
|
126
|
+
readonly required: boolean;
|
|
127
|
+
readonly item: GraphQLIdentity;
|
|
128
|
+
};
|
|
129
|
+
type ReferenceIdentity = {
|
|
130
|
+
readonly kind: "ref";
|
|
131
|
+
readonly required: boolean;
|
|
132
|
+
};
|
|
133
|
+
type NamedTypeIdentity = {
|
|
134
|
+
readonly kind: NamedTypeKind;
|
|
135
|
+
readonly name: string | null;
|
|
136
|
+
readonly description: string | null;
|
|
137
|
+
};
|
|
138
|
+
type GraphQLIdentity = ScalarIdentity | ListIdentity | ReferenceIdentity | NamedTypeIdentity;
|
|
139
|
+
type DescriptorNode<TInput, TOutput, TSource = TOutput> = {
|
|
140
|
+
readonly kind: DescriptorKind;
|
|
141
|
+
readonly identity: GraphQLIdentity;
|
|
142
|
+
readonly validator: z.ZodType;
|
|
143
|
+
readonly __types?: {
|
|
144
|
+
readonly input: TInput;
|
|
145
|
+
readonly output: TOutput;
|
|
146
|
+
readonly source: TSource;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
declare const FIELD_USE_ROLE: "field use";
|
|
150
|
+
declare const NAMED_TYPE_ROLE: "named type; wrap it with ph.ref(Type) to use it as a field";
|
|
151
|
+
type FieldDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = DescriptorNode<TInput, TOutput, TSource> & {
|
|
152
|
+
readonly role: typeof FIELD_USE_ROLE;
|
|
153
|
+
readonly kind: FieldUseKind;
|
|
154
|
+
readonly required: TRequired;
|
|
155
|
+
readonly presentation: FieldPresentation & {
|
|
156
|
+
readonly default: {
|
|
157
|
+
readonly present: TDefaulted;
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
type TypeDescriptor<TInput, TOutput, TSource = TOutput> = DescriptorNode<TInput, TOutput, TSource> & {
|
|
162
|
+
readonly role: typeof NAMED_TYPE_ROLE;
|
|
163
|
+
readonly kind: NamedTypeKind;
|
|
164
|
+
readonly name: string | null;
|
|
165
|
+
readonly description: string | null;
|
|
166
|
+
};
|
|
167
|
+
type AnyFieldDescriptor = FieldDescriptor<any, any, any>;
|
|
168
|
+
type AnyTypeDescriptor = TypeDescriptor<any, any, any>;
|
|
169
|
+
type Nullable<T, TRequired extends boolean> = TRequired extends true ? T : T | null | undefined;
|
|
170
|
+
type InputOf<T> = T extends DescriptorNode<infer TInput, any, any> ? TInput : never;
|
|
171
|
+
type OutputOf<T> = T extends DescriptorNode<any, infer TOutput, any> ? TOutput : never;
|
|
172
|
+
type SourceOf<T> = T extends DescriptorNode<any, any, infer TSource> ? TSource : never;
|
|
173
|
+
type RequiredOf<T> = T extends {
|
|
174
|
+
readonly required: infer TRequired;
|
|
175
|
+
} ? TRequired : never;
|
|
176
|
+
type DefaultedOf<T> = T extends {
|
|
177
|
+
readonly presentation: {
|
|
178
|
+
readonly default: {
|
|
179
|
+
readonly present: infer P;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
} ? P : never;
|
|
183
|
+
type ObjectFields = Readonly<Record<string, AnyFieldDescriptor>>;
|
|
184
|
+
type RequiredKeys<TFields extends ObjectFields> = { [K in keyof TFields]: RequiredOf<TFields[K]> extends true ? K : never; }[keyof TFields];
|
|
185
|
+
/** A caller may omit a required field that has a default. */
|
|
186
|
+
type CallerRequiredKeys<TFields extends ObjectFields> = { [K in RequiredKeys<TFields>]: DefaultedOf<TFields[K]> extends true ? never : K; }[RequiredKeys<TFields>];
|
|
187
|
+
/** @experimental */
|
|
188
|
+
type InputObjectOf<TFields extends ObjectFields> = { -readonly [K in CallerRequiredKeys<TFields>]: InputOf<TFields[K]>; } & { -readonly [K in Exclude<keyof TFields, CallerRequiredKeys<TFields>>]?: InputOf<TFields[K]>; };
|
|
189
|
+
type ResolvedInputObjectOf<TFields extends ObjectFields> = { -readonly [K in RequiredKeys<TFields>]: SourceOf<TFields[K]>; } & { -readonly [K in Exclude<keyof TFields, RequiredKeys<TFields>>]?: SourceOf<TFields[K]>; };
|
|
190
|
+
/** @experimental */
|
|
191
|
+
type OutputObjectOf<TFields extends ObjectFields> = { -readonly [K in keyof TFields]: OutputOf<TFields[K]>; };
|
|
192
|
+
type SourceObjectOf<TFields extends ObjectFields> = { -readonly [K in keyof TFields]: SourceOf<TFields[K]>; };
|
|
193
|
+
type EnumValueInput = string | {
|
|
194
|
+
readonly name: string;
|
|
195
|
+
readonly description?: string;
|
|
196
|
+
readonly deprecated?: string;
|
|
197
|
+
};
|
|
198
|
+
type EnumValueNameOf<TValue extends EnumValueInput> = TValue extends string ? TValue : TValue extends {
|
|
199
|
+
readonly name: infer TName extends string;
|
|
200
|
+
} ? TName : never;
|
|
201
|
+
type EnumValue = {
|
|
202
|
+
readonly name: string;
|
|
203
|
+
readonly description: string | null;
|
|
204
|
+
readonly deprecated: string | null;
|
|
205
|
+
};
|
|
206
|
+
/** @experimental */
|
|
207
|
+
type EnumDescriptor<TValues extends readonly EnumValueInput[] = readonly EnumValueInput[]> = TypeDescriptor<EnumValueNameOf<TValues[number]>, EnumValueNameOf<TValues[number]>, EnumValueNameOf<TValues[number]>> & {
|
|
208
|
+
readonly kind: "enum";
|
|
209
|
+
readonly name: string;
|
|
210
|
+
readonly values: readonly EnumValue[];
|
|
211
|
+
};
|
|
212
|
+
/** @experimental */
|
|
213
|
+
type InterfaceDescriptor<TFields extends ObjectFields = ObjectFields, TImplements extends readonly InterfaceDescriptor<ObjectFields, any>[] = readonly InterfaceDescriptor<ObjectFields, any>[]> = TypeDescriptor<InputObjectOf<TFields>, OutputObjectOf<TFields>, SourceObjectOf<TFields>> & {
|
|
214
|
+
readonly kind: "interface";
|
|
215
|
+
readonly name: string;
|
|
216
|
+
readonly fields: TFields;
|
|
217
|
+
readonly implements: TImplements;
|
|
218
|
+
};
|
|
219
|
+
/** @experimental */
|
|
220
|
+
type ObjectDescriptor<TFields extends ObjectFields = ObjectFields, TImplements extends readonly InterfaceDescriptor[] = readonly InterfaceDescriptor[]> = TypeDescriptor<InputObjectOf<TFields>, OutputObjectOf<TFields>, SourceObjectOf<TFields>> & {
|
|
221
|
+
readonly kind: "object";
|
|
222
|
+
readonly name: string;
|
|
223
|
+
readonly fields: TFields;
|
|
224
|
+
readonly implements: TImplements;
|
|
225
|
+
};
|
|
226
|
+
/** @experimental */
|
|
227
|
+
type InputDescriptor<TFields extends ObjectFields = ObjectFields> = TypeDescriptor<InputObjectOf<TFields>, InputObjectOf<TFields>, ResolvedInputObjectOf<TFields>> & {
|
|
228
|
+
readonly kind: "input";
|
|
229
|
+
readonly fields: TFields;
|
|
230
|
+
};
|
|
231
|
+
/** @experimental */
|
|
232
|
+
type UnionDescriptor<TMembers extends readonly ObjectDescriptor[] = readonly ObjectDescriptor[]> = TypeDescriptor<InputOf<TMembers[number]>, OutputOf<TMembers[number]>, SourceOf<TMembers[number]>> & {
|
|
233
|
+
readonly kind: "union";
|
|
234
|
+
readonly name: string;
|
|
235
|
+
readonly members: TMembers;
|
|
236
|
+
};
|
|
237
|
+
type RefTarget = AnyTypeDescriptor | (() => AnyTypeDescriptor);
|
|
238
|
+
/** @experimental */
|
|
239
|
+
type ReferenceDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = FieldDescriptor<TInput, TOutput, TSource, TRequired, TDefaulted> & {
|
|
240
|
+
readonly kind: "ref";
|
|
241
|
+
readonly target: RefTarget;
|
|
242
|
+
};
|
|
243
|
+
/** @experimental */
|
|
244
|
+
type ListDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = FieldDescriptor<TInput, TOutput, TSource, TRequired, TDefaulted> & {
|
|
245
|
+
readonly kind: "list";
|
|
246
|
+
readonly item: AnyFieldDescriptor;
|
|
247
|
+
};
|
|
248
|
+
/** @experimental */
|
|
249
|
+
type ScalarDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = FieldDescriptor<TInput, TOutput, TSource, TRequired, TDefaulted> & {
|
|
250
|
+
readonly kind: "scalar";
|
|
251
|
+
readonly scalarName: string;
|
|
252
|
+
readonly baseValidator: z.ZodType;
|
|
253
|
+
readonly definition?: ScalarDefinition;
|
|
254
|
+
};
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/definition/dsl/scalar-fields.d.ts
|
|
257
|
+
declare function scalarField<TName extends string, TValue, const TRequired extends boolean = false, const TDefault extends JsonLiteral | undefined = undefined>(definition: ScalarDefinition<TName, TValue>, options?: ScalarBuilderOptions<TRequired, TDefault>): ScalarDescriptor<Nullable<TValue, TRequired>, Nullable<TValue, TRequired>, Nullable<TValue, TRequired>, TRequired, DefaultFlag<TDefault>>;
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/definition/dsl/field.d.ts
|
|
260
|
+
type NamedOptions = {
|
|
261
|
+
readonly description?: string;
|
|
262
|
+
};
|
|
263
|
+
type EnumOptions<TValues extends readonly EnumValueInput[]> = NamedOptions & {
|
|
264
|
+
readonly values: TValues;
|
|
265
|
+
};
|
|
266
|
+
type FieldsOptions<TFields extends ObjectFields> = NamedOptions & {
|
|
267
|
+
readonly fields: TFields;
|
|
268
|
+
};
|
|
269
|
+
type ImplementsOptions<TImplements extends readonly InterfaceDescriptor[]> = {
|
|
270
|
+
readonly implements?: TImplements;
|
|
271
|
+
};
|
|
272
|
+
type ImplementingOptions<TFields extends ObjectFields, TImplements extends readonly InterfaceDescriptor[]> = FieldsOptions<TFields> & ImplementsOptions<TImplements>;
|
|
273
|
+
type UnionOptions<TMembers extends readonly ObjectDescriptor[]> = NamedOptions & {
|
|
274
|
+
readonly members: TMembers;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* The first signature types an object without `implements` as implementing
|
|
278
|
+
* nothing. A single generic signature would infer `TImplements` from the
|
|
279
|
+
* contextual type instead, as for a union member or an inline state root,
|
|
280
|
+
* and widen it to every interface.
|
|
281
|
+
*/
|
|
282
|
+
declare function objectType<const TFields extends ObjectFields>(name: string, options: ImplementingOptions<TFields, readonly []>): ObjectDescriptor<TFields, readonly []>;
|
|
283
|
+
declare function objectType<const TFields extends ObjectFields, const TImplements extends readonly InterfaceDescriptor[]>(name: string, options: ImplementingOptions<TFields, TImplements>): ObjectDescriptor<TFields, TImplements>;
|
|
284
|
+
/** Overloaded like `objectType`, for the same reason. */
|
|
285
|
+
declare function interfaceType<const TFields extends ObjectFields>(name: string, options: ImplementingOptions<TFields, readonly []>): InterfaceDescriptor<TFields, readonly []>;
|
|
286
|
+
declare function interfaceType<const TFields extends ObjectFields, const TImplements extends readonly InterfaceDescriptor[]>(name: string, options: ImplementingOptions<TFields, TImplements>): InterfaceDescriptor<TFields, TImplements>;
|
|
287
|
+
/**
|
|
288
|
+
* @experimental The field and type builders of a code-first document model:
|
|
289
|
+
* scalar factories such as `ph.String()` and `ph.PHID()`, `ph.scalar` for a
|
|
290
|
+
* project scalar, and `list`, `ref`, `enum`, `object`, `interface`, `input`,
|
|
291
|
+
* and `union`.
|
|
292
|
+
*/
|
|
293
|
+
export declare const ph: Readonly<{
|
|
294
|
+
ID: ScalarBuilder<string> & {
|
|
295
|
+
readonly role: "field-use factory; call it, as ph.ID({ required: true })";
|
|
296
|
+
readonly kind: "scalar-factory";
|
|
297
|
+
};
|
|
298
|
+
String: ScalarBuilder<string> & {
|
|
299
|
+
readonly role: "field-use factory; call it, as ph.String({ required: true })";
|
|
300
|
+
readonly kind: "scalar-factory";
|
|
301
|
+
};
|
|
302
|
+
Boolean: ScalarBuilder<boolean> & {
|
|
303
|
+
readonly role: "field-use factory; call it, as ph.Boolean({ required: true })";
|
|
304
|
+
readonly kind: "scalar-factory";
|
|
305
|
+
};
|
|
306
|
+
Int: ScalarBuilder<number> & {
|
|
307
|
+
readonly role: "field-use factory; call it, as ph.Int({ required: true })";
|
|
308
|
+
readonly kind: "scalar-factory";
|
|
309
|
+
};
|
|
310
|
+
Float: ScalarBuilder<number> & {
|
|
311
|
+
readonly role: "field-use factory; call it, as ph.Float({ required: true })";
|
|
312
|
+
readonly kind: "scalar-factory";
|
|
313
|
+
};
|
|
314
|
+
scalar: typeof scalarField;
|
|
315
|
+
list<const TItem extends AnyFieldDescriptor, const TRequired extends boolean = false, const TDefault extends JsonLiteral | undefined = undefined>(item: TItem, options?: FieldBuilderOptions<TRequired, TDefault>): ListDescriptor<Nullable<readonly InputOf<TItem>[], TRequired>, Nullable<readonly OutputOf<TItem>[], TRequired>, Nullable<readonly SourceOf<TItem>[], TRequired>, TRequired, DefaultFlag<TDefault>>;
|
|
316
|
+
ref<const TTarget extends AnyTypeDescriptor, const TRequired extends boolean = false, const TDefault extends JsonLiteral | undefined = undefined>(target: TTarget | (() => TTarget), options?: FieldBuilderOptions<TRequired, TDefault>): ReferenceDescriptor<Nullable<InputOf<TTarget>, TRequired>, Nullable<OutputOf<TTarget>, TRequired>, Nullable<SourceOf<TTarget>, TRequired>, TRequired, DefaultFlag<TDefault>>;
|
|
317
|
+
enum<const TValues extends readonly [EnumValueInput, ...EnumValueInput[]]>(name: string, options: EnumOptions<TValues>): EnumDescriptor<TValues>;
|
|
318
|
+
object: typeof objectType;
|
|
319
|
+
interface: typeof interfaceType;
|
|
320
|
+
input<const TFields extends ObjectFields>(...args: [name: string, options: FieldsOptions<TFields>] | [options: FieldsOptions<TFields>]): InputDescriptor<TFields>;
|
|
321
|
+
union<const TMembers extends readonly [ObjectDescriptor, ...ObjectDescriptor[]]>(name: string, options: UnionOptions<TMembers>): UnionDescriptor<TMembers>;
|
|
322
|
+
Address: ScalarBuilder<string> & {
|
|
323
|
+
readonly role: "field-use factory; call it, as ph.Address({ required: true })";
|
|
324
|
+
readonly kind: "scalar-factory";
|
|
325
|
+
};
|
|
326
|
+
Amount: ScalarBuilder<{
|
|
327
|
+
unit?: string | undefined;
|
|
328
|
+
value: number;
|
|
329
|
+
}> & {
|
|
330
|
+
readonly role: "field-use factory; call it, as ph.Amount({ required: true })";
|
|
331
|
+
readonly kind: "scalar-factory";
|
|
332
|
+
};
|
|
333
|
+
AmountCrypto: ScalarBuilder<{
|
|
334
|
+
unit: string;
|
|
335
|
+
value: string;
|
|
336
|
+
}> & {
|
|
337
|
+
readonly role: "field-use factory; call it, as ph.AmountCrypto({ required: true })";
|
|
338
|
+
readonly kind: "scalar-factory";
|
|
339
|
+
};
|
|
340
|
+
AmountCurrency: ScalarBuilder<{
|
|
341
|
+
unit: string;
|
|
342
|
+
value: string;
|
|
343
|
+
}> & {
|
|
344
|
+
readonly role: "field-use factory; call it, as ph.AmountCurrency({ required: true })";
|
|
345
|
+
readonly kind: "scalar-factory";
|
|
346
|
+
};
|
|
347
|
+
AmountFiat: ScalarBuilder<{
|
|
348
|
+
unit: string;
|
|
349
|
+
value: number;
|
|
350
|
+
}> & {
|
|
351
|
+
readonly role: "field-use factory; call it, as ph.AmountFiat({ required: true })";
|
|
352
|
+
readonly kind: "scalar-factory";
|
|
353
|
+
};
|
|
354
|
+
AttachmentRef: ScalarBuilder<string> & {
|
|
355
|
+
readonly role: "field-use factory; call it, as ph.AttachmentRef({ required: true })";
|
|
356
|
+
readonly kind: "scalar-factory";
|
|
357
|
+
};
|
|
358
|
+
Currency: ScalarBuilder<string> & {
|
|
359
|
+
readonly role: "field-use factory; call it, as ph.Currency({ required: true })";
|
|
360
|
+
readonly kind: "scalar-factory";
|
|
361
|
+
};
|
|
362
|
+
Date: ScalarBuilder<string> & {
|
|
363
|
+
readonly role: "field-use factory; call it, as ph.Date({ required: true })";
|
|
364
|
+
readonly kind: "scalar-factory";
|
|
365
|
+
};
|
|
366
|
+
DateTime: ScalarBuilder<string> & {
|
|
367
|
+
readonly role: "field-use factory; call it, as ph.DateTime({ required: true })";
|
|
368
|
+
readonly kind: "scalar-factory";
|
|
369
|
+
};
|
|
370
|
+
EmailAddress: ScalarBuilder<string> & {
|
|
371
|
+
readonly role: "field-use factory; call it, as ph.EmailAddress({ required: true })";
|
|
372
|
+
readonly kind: "scalar-factory";
|
|
373
|
+
};
|
|
374
|
+
EthereumAddress: ScalarBuilder<string> & {
|
|
375
|
+
readonly role: "field-use factory; call it, as ph.EthereumAddress({ required: true })";
|
|
376
|
+
readonly kind: "scalar-factory";
|
|
377
|
+
};
|
|
378
|
+
Money: ScalarBuilder<number> & {
|
|
379
|
+
readonly role: "field-use factory; call it, as ph.Money({ required: true })";
|
|
380
|
+
readonly kind: "scalar-factory";
|
|
381
|
+
};
|
|
382
|
+
OID: ScalarBuilder<string> & {
|
|
383
|
+
readonly role: "field-use factory; call it, as ph.OID({ required: true })";
|
|
384
|
+
readonly kind: "scalar-factory";
|
|
385
|
+
};
|
|
386
|
+
OLabel: ScalarBuilder<string> & {
|
|
387
|
+
readonly role: "field-use factory; call it, as ph.OLabel({ required: true })";
|
|
388
|
+
readonly kind: "scalar-factory";
|
|
389
|
+
};
|
|
390
|
+
PHID: ScalarBuilder<string> & {
|
|
391
|
+
readonly role: "field-use factory; call it, as ph.PHID({ required: true })";
|
|
392
|
+
readonly kind: "scalar-factory";
|
|
393
|
+
};
|
|
394
|
+
Percentage: ScalarBuilder<number> & {
|
|
395
|
+
readonly role: "field-use factory; call it, as ph.Percentage({ required: true })";
|
|
396
|
+
readonly kind: "scalar-factory";
|
|
397
|
+
};
|
|
398
|
+
Tokens: ScalarBuilder<number> & {
|
|
399
|
+
readonly role: "field-use factory; call it, as ph.Tokens({ required: true })";
|
|
400
|
+
readonly kind: "scalar-factory";
|
|
401
|
+
};
|
|
402
|
+
URL: ScalarBuilder<string> & {
|
|
403
|
+
readonly role: "field-use factory; call it, as ph.URL({ required: true })";
|
|
404
|
+
readonly kind: "scalar-factory";
|
|
405
|
+
};
|
|
406
|
+
Unknown: ScalarBuilder<unknown> & {
|
|
407
|
+
readonly role: "field-use factory; call it, as ph.Unknown({ required: true })";
|
|
408
|
+
readonly kind: "scalar-factory";
|
|
409
|
+
};
|
|
410
|
+
Upload: ScalarBuilder<any> & {
|
|
411
|
+
readonly role: "field-use factory; call it, as ph.Upload({ required: true })";
|
|
412
|
+
readonly kind: "scalar-factory";
|
|
413
|
+
};
|
|
414
|
+
}>;
|
|
415
|
+
/** @experimental The type of `ph`. */
|
|
416
|
+
type Ph = typeof ph;
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/definition/kernel/diagnostics.d.ts
|
|
419
|
+
/**
|
|
420
|
+
* @experimental Thrown when a code-first declaration is refused. `diagnostics`
|
|
421
|
+
* holds every problem found, sorted, each with its code, path and repair.
|
|
422
|
+
*/
|
|
423
|
+
export declare class DefinitionError extends Error {
|
|
424
|
+
readonly diagnostics: readonly DefinitionDiagnostic[];
|
|
425
|
+
constructor(diagnostics: readonly [DefinitionDiagnostic, ...DefinitionDiagnostic[]]);
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/definition/compiler/naming.d.ts
|
|
429
|
+
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
430
|
+
type ActionTypeWords<TKey extends string, TPrevious extends string = "", TResult extends string = "", TSeparator extends string = ""> = TKey extends `${infer TFirst}${infer TRest}` ? TFirst extends "_" ? ActionTypeWords<TRest, "", TResult, TResult extends "" ? "" : "_"> : ActionTypeWords<TRest, TFirst, `${TResult}${TSeparator extends "_" ? "_" : TFirst extends Lowercase<TFirst> ? "" : TPrevious extends "" ? "" : TPrevious extends Digit ? "_" : TPrevious extends Uppercase<TPrevious> ? TRest extends `${infer TNext}${string}` ? TNext extends Uppercase<TNext> ? "" : "_" : "" : "_"}${Uppercase<TFirst>}`> : TResult;
|
|
431
|
+
type DocumentModelActionType<TKey extends string> = string extends TKey ? string : ActionTypeWords<TKey>;
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/definition/compiler/compile.d.ts
|
|
434
|
+
type StateRootDescriptor = ObjectDescriptor;
|
|
435
|
+
type OperationErrorDeclaration = {
|
|
436
|
+
readonly code?: string | null;
|
|
437
|
+
readonly name?: string | null;
|
|
438
|
+
readonly description?: string | null;
|
|
439
|
+
readonly template?: string | null;
|
|
440
|
+
};
|
|
441
|
+
type DefinitionExampleDeclaration = {
|
|
442
|
+
readonly key: string;
|
|
443
|
+
readonly value: string;
|
|
444
|
+
};
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region src/definition/model/types.d.ts
|
|
447
|
+
type Mutable<T> = T extends readonly (infer TItem)[] ? Mutable<TItem>[] : T extends object ? { -readonly [K in keyof T]: Mutable<T[K]>; } : T;
|
|
448
|
+
type StateScopeDeclaration<TSchema extends StateRootDescriptor> = {
|
|
449
|
+
readonly schema: TSchema;
|
|
450
|
+
readonly initialValue: SourceOf<TSchema>;
|
|
451
|
+
readonly examples?: readonly DefinitionExampleDeclaration[];
|
|
452
|
+
};
|
|
453
|
+
type EmptyLocalScopeDeclaration = {
|
|
454
|
+
readonly schema: null;
|
|
455
|
+
readonly initialValue: Readonly<Record<string, never>>;
|
|
456
|
+
readonly examples?: readonly DefinitionExampleDeclaration[];
|
|
457
|
+
};
|
|
458
|
+
/** @experimental */
|
|
459
|
+
type DocumentModelConfig<TGlobal extends StateRootDescriptor, TLocal extends StateRootDescriptor | null, TVersion extends number> = {
|
|
460
|
+
readonly id: string;
|
|
461
|
+
readonly name: string;
|
|
462
|
+
readonly description: string;
|
|
463
|
+
readonly extension: string;
|
|
464
|
+
readonly version: TVersion;
|
|
465
|
+
readonly author: {
|
|
466
|
+
readonly name: string;
|
|
467
|
+
readonly website?: string | null;
|
|
468
|
+
};
|
|
469
|
+
readonly changeLog?: readonly string[];
|
|
470
|
+
readonly scopes: {
|
|
471
|
+
readonly auxiliaryTypes?: readonly AnyTypeDescriptor[];
|
|
472
|
+
readonly global: StateScopeDeclaration<TGlobal>;
|
|
473
|
+
readonly local: TLocal extends StateRootDescriptor ? StateScopeDeclaration<TLocal> : EmptyLocalScopeDeclaration;
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
type LocalStateOfDescriptor<TLocal extends StateRootDescriptor | null> = TLocal extends StateRootDescriptor ? Mutable<SourceOf<TLocal>> : Record<string, never>;
|
|
477
|
+
/** @experimental The document state a model's descriptors describe. */
|
|
478
|
+
type ModelState<TGlobal extends StateRootDescriptor, TLocal extends StateRootDescriptor | null> = PHBaseState & {
|
|
479
|
+
global: Mutable<SourceOf<TGlobal>>;
|
|
480
|
+
local: LocalStateOfDescriptor<TLocal>;
|
|
481
|
+
};
|
|
482
|
+
type ErrorDeclarations = Readonly<Record<string, OperationErrorDeclaration>>;
|
|
483
|
+
type ErrorCodeOf<TKey extends string, TError> = TError extends {
|
|
484
|
+
readonly code: infer TCode extends string;
|
|
485
|
+
} ? TCode extends "" ? TError extends {
|
|
486
|
+
readonly name: string;
|
|
487
|
+
} ? string : TKey : TCode : TKey;
|
|
488
|
+
type OperationErrorClasses<TErrors extends ErrorDeclarations> = { readonly [K in keyof TErrors & string]: new (message?: string) => Error & {
|
|
489
|
+
readonly errorCode: ErrorCodeOf<K, TErrors[K]>;
|
|
490
|
+
}; };
|
|
491
|
+
type ModelOperationContext<TInput extends InputDescriptor, TErrors extends ErrorDeclarations> = {
|
|
492
|
+
readonly errors: OperationErrorClasses<TErrors>;
|
|
493
|
+
readonly action: Action & {
|
|
494
|
+
readonly input: InputOf<TInput>;
|
|
495
|
+
};
|
|
496
|
+
readonly dispatch: SignalDispatch | undefined;
|
|
497
|
+
};
|
|
498
|
+
type ModelOperationConfig<TState, TInput extends InputDescriptor, TErrors extends ErrorDeclarations> = {
|
|
499
|
+
readonly description?: string;
|
|
500
|
+
readonly input: TInput;
|
|
501
|
+
readonly errors?: TErrors;
|
|
502
|
+
readonly examples?: readonly DefinitionExampleDeclaration[];
|
|
503
|
+
readonly template?: string | null;
|
|
504
|
+
readonly reducerTemplate?: string | null;
|
|
505
|
+
readonly reduce: (state: Mutable<TState>, input: Mutable<InputOf<TInput>>, context: ModelOperationContext<TInput, TErrors>) => void;
|
|
506
|
+
};
|
|
507
|
+
declare const operationTokenBrand: unique symbol;
|
|
508
|
+
/** @experimental An operation declared by a scope builder. */
|
|
509
|
+
interface ModelOperationToken<TInput extends InputDescriptor = InputDescriptor, TScope extends "global" | "local" = "global" | "local"> {
|
|
510
|
+
readonly kind: "powerhouse.document-model-operation";
|
|
511
|
+
readonly [operationTokenBrand]?: {
|
|
512
|
+
readonly input: TInput;
|
|
513
|
+
readonly scope: TScope;
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
interface ModelOperationBuilder<TState, TScope extends "global" | "local"> {
|
|
517
|
+
<const TInput extends InputDescriptor, const TErrors extends ErrorDeclarations = Record<never, never>>(config: ModelOperationConfig<TState, TInput, TErrors>): ModelOperationToken<TInput, TScope>;
|
|
518
|
+
}
|
|
519
|
+
type InputOfOperation<T> = T extends ModelOperationToken<infer TInput, any> ? InputOf<TInput> : never;
|
|
520
|
+
type ScopeOfOperation<T> = T extends ModelOperationToken<any, infer TScope> ? TScope : never;
|
|
521
|
+
type ActionForOperation<T, TType extends string = string> = Action & {
|
|
522
|
+
readonly type: TType;
|
|
523
|
+
readonly input: InputOfOperation<T>;
|
|
524
|
+
readonly scope: ScopeOfOperation<T>;
|
|
525
|
+
};
|
|
526
|
+
type CreatorParameters<T> = keyof InputOfOperation<T> extends never ? [input?: InputOfOperation<T>] : [input: InputOfOperation<T>];
|
|
527
|
+
/** @experimental */
|
|
528
|
+
type ActionsForOperationTokens<TOperations extends Readonly<Record<string, ModelOperationToken>>> = { readonly [K in keyof TOperations]: (...args: CreatorParameters<TOperations[K]>) => ActionForOperation<TOperations[K], DocumentModelActionType<K & string>>; };
|
|
529
|
+
declare const moduleTokenBrand: unique symbol;
|
|
530
|
+
/** @experimental A module declared by `context.module`. */
|
|
531
|
+
interface ModelModuleToken<TState extends PHBaseState = PHBaseState, TActions extends Actions = Actions, TKey extends string = string> {
|
|
532
|
+
readonly kind: "powerhouse.document-model-module";
|
|
533
|
+
readonly [moduleTokenBrand]?: {
|
|
534
|
+
readonly state: TState;
|
|
535
|
+
readonly actions: TActions;
|
|
536
|
+
readonly key: TKey;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
|
|
540
|
+
type ModelActionsOf<TModules extends readonly ModelModuleToken[]> = UnionToIntersection<TModules[number] extends ModelModuleToken<any, infer TActions, any> ? TActions : never>;
|
|
541
|
+
type ActionsOfModules<TModules extends readonly ModelModuleToken[], TModelActions = ModelActionsOf<TModules>> = TModelActions & Omit<typeof baseActions, keyof TModelActions>;
|
|
542
|
+
declare const versionTokenBrand: unique symbol;
|
|
543
|
+
/**
|
|
544
|
+
* @experimental A compiled model version. `materialize` turns it into a
|
|
545
|
+
* document model module; `defineDocumentModelFamily` composes several.
|
|
546
|
+
*/
|
|
547
|
+
interface DocumentModelVersionDefinition<TVersion extends number = number, TState extends PHBaseState = PHBaseState, TActions extends Actions = Actions> {
|
|
548
|
+
readonly kind: "powerhouse.document-model-version";
|
|
549
|
+
readonly version: TVersion;
|
|
550
|
+
readonly documentType: string;
|
|
551
|
+
readonly [versionTokenBrand]?: {
|
|
552
|
+
readonly state: TState;
|
|
553
|
+
readonly actions: TActions;
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
type DocumentModelVersionConfig<TModules extends readonly ModelModuleToken[]> = {
|
|
557
|
+
readonly modules: TModules;
|
|
558
|
+
};
|
|
559
|
+
/** @experimental The context `defineDocumentModel` returns. */
|
|
560
|
+
interface DocumentModelContext<TGlobal extends StateRootDescriptor, TLocal extends StateRootDescriptor | null, TVersion extends number> {
|
|
561
|
+
module<const TKey extends string, const TOperations extends Readonly<Record<string, ModelOperationToken>>>(key: TKey, config: {
|
|
562
|
+
readonly description?: string;
|
|
563
|
+
readonly operations: (builders: {
|
|
564
|
+
readonly global: ModelOperationBuilder<Mutable<SourceOf<TGlobal>>, "global">;
|
|
565
|
+
readonly local: ModelOperationBuilder<LocalStateOfDescriptor<TLocal>, "local">;
|
|
566
|
+
}) => TOperations;
|
|
567
|
+
}): ModelModuleToken<ModelState<TGlobal, TLocal>, ActionsForOperationTokens<TOperations>, TKey>;
|
|
568
|
+
version<const TModules extends readonly ModelModuleToken<ModelState<TGlobal, TLocal>, Actions>[]>(config: DocumentModelVersionConfig<TModules>): DocumentModelVersionDefinition<TVersion, ModelState<TGlobal, TLocal>, ActionsOfModules<TModules>>;
|
|
569
|
+
}
|
|
570
|
+
declare const familyTokenBrand: unique symbol;
|
|
571
|
+
/**
|
|
572
|
+
* @experimental The checked versions of one document type and their upgrade
|
|
573
|
+
* manifest. `materialize` turns it into one module per version.
|
|
574
|
+
*/
|
|
575
|
+
interface DocumentModelFamilyDefinition<TVersions extends readonly DocumentModelVersionDefinition[] = readonly DocumentModelVersionDefinition[]> {
|
|
576
|
+
readonly kind: "powerhouse.document-model-family";
|
|
577
|
+
readonly documentType: string;
|
|
578
|
+
readonly [familyTokenBrand]?: {
|
|
579
|
+
readonly versions: TVersions;
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region src/definition/model/define-document-model.d.ts
|
|
584
|
+
/**
|
|
585
|
+
* @experimental Declares a document model version from `ph` descriptors.
|
|
586
|
+
* The context's `module()` declares operations and `version()` compiles them
|
|
587
|
+
* into a token for `materialize` or `defineDocumentModelFamily`.
|
|
588
|
+
*/
|
|
589
|
+
export declare function defineDocumentModel<const TGlobal extends StateRootDescriptor, const TLocal extends StateRootDescriptor | null, const TVersion extends number>(config: DocumentModelConfig<TGlobal, TLocal, TVersion>): DocumentModelContext<TGlobal, TLocal, TVersion>;
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/definition/model/family.d.ts
|
|
592
|
+
/**
|
|
593
|
+
* @experimental Composes the versions of one document type with the upgrade
|
|
594
|
+
* manifest that moves a document between them. `materialize` turns the
|
|
595
|
+
* result into one module per version.
|
|
596
|
+
*/
|
|
597
|
+
export declare function defineDocumentModelFamily<const TVersions extends readonly DocumentModelVersionDefinition[]>(config: {
|
|
598
|
+
readonly versions: TVersions;
|
|
599
|
+
readonly upgradeManifest: UpgradeManifest<readonly number[]>;
|
|
600
|
+
}): DocumentModelFamilyDefinition<TVersions>;
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region src/definition/runtime/types.d.ts
|
|
603
|
+
/**
|
|
604
|
+
* @experimental An ordinary `DocumentModelModule` with typed actions and the
|
|
605
|
+
* stored definition it was compiled to. Hosts use `reducer`, `actions`,
|
|
606
|
+
* `utils`, and `documentModel` as they use a generated module's.
|
|
607
|
+
*/
|
|
608
|
+
type CodeFirstDocumentModelModule<TState extends PHBaseState = PHBaseState, TActions extends Actions = Actions> = Omit<DocumentModelModule<TState>, "actions" | "version"> & {
|
|
609
|
+
readonly version: number;
|
|
610
|
+
readonly actions: TActions;
|
|
611
|
+
readonly definition: DocumentModelDefinition;
|
|
612
|
+
};
|
|
613
|
+
type ModuleOfVersion<T> = T extends DocumentModelVersionDefinition<any, infer TState, infer TActions> ? CodeFirstDocumentModelModule<TState, TActions> : never;
|
|
614
|
+
type VersionNumbered<TMember, TVersion extends number> = TMember extends DocumentModelVersionDefinition<infer TNumber, any, any> ? TVersion extends TNumber ? TMember : never : never;
|
|
615
|
+
/** @experimental One module per version, and the family's upgrade manifest. */
|
|
616
|
+
type DocumentModelFamily<TVersions extends readonly DocumentModelVersionDefinition[] = readonly DocumentModelVersionDefinition[]> = {
|
|
617
|
+
readonly modules: { readonly [K in keyof TVersions]: ModuleOfVersion<TVersions[K]>; };
|
|
618
|
+
readonly upgradeManifest: UpgradeManifest<readonly number[]>;
|
|
619
|
+
at<const TVersion extends TVersions[number]["version"]>(version: TVersion): ModuleOfVersion<VersionNumbered<TVersions[number], TVersion>>;
|
|
620
|
+
};
|
|
621
|
+
/** @experimental The global state of a materialized module. */
|
|
622
|
+
type GlobalStateOf<T> = T extends CodeFirstDocumentModelModule<infer TState, any> ? TState extends {
|
|
623
|
+
global: infer TGlobal;
|
|
624
|
+
} ? TGlobal : never : never;
|
|
625
|
+
/** @experimental The local state of a materialized module. */
|
|
626
|
+
type LocalStateOf<T> = T extends CodeFirstDocumentModelModule<infer TState, any> ? TState extends {
|
|
627
|
+
local: infer TLocal;
|
|
628
|
+
} ? TLocal : never : never;
|
|
629
|
+
/** @experimental The document type of a materialized module. */
|
|
630
|
+
type DocumentOf<T> = T extends CodeFirstDocumentModelModule<infer TState, any> ? PHDocument<TState> : never;
|
|
631
|
+
/** @experimental Any action a materialized module's creators return. */
|
|
632
|
+
type ActionOf<T> = T extends CodeFirstDocumentModelModule<any, infer TActions> ? ReturnType<TActions[keyof TActions]> : never;
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region src/definition/runtime/materialize.d.ts
|
|
635
|
+
/**
|
|
636
|
+
* @experimental Builds the `DocumentModelModule` a host serves from a
|
|
637
|
+
* compiled version, or one module per version from a family. A single
|
|
638
|
+
* version is materialized as a one-version family.
|
|
639
|
+
*/
|
|
640
|
+
export declare function materialize<TState extends PHBaseState, TActions extends Actions>(definition: DocumentModelVersionDefinition<number, TState, TActions>): CodeFirstDocumentModelModule<TState, TActions>;
|
|
641
|
+
export declare function materialize<const TVersions extends readonly DocumentModelVersionDefinition[]>(definition: DocumentModelFamilyDefinition<TVersions>): DocumentModelFamily<TVersions>;
|
|
642
|
+
//#endregion
|
|
643
|
+
export type { ActionOf, ActionsForOperationTokens, CodeFirstDocumentModelModule, DispatchOutcome, DocumentDispatch, DocumentModelConfig, DocumentModelContext, DocumentModelFamily, DocumentModelFamilyDefinition, DocumentModelVersionDefinition, DocumentOf, EnumDescriptor, GlobalStateOf, InputDescriptor, InputObjectOf, InterfaceDescriptor, ListDescriptor, LocalStateOf, ModelModuleToken, ModelOperationToken, ModelState, ObjectDescriptor, OutputObjectOf, Ph, ReferenceDescriptor, RejectedAction, ScalarDescriptor, UnionDescriptor };
|
|
644
|
+
export {};
|
|
81
645
|
//# sourceMappingURL=index.d.ts.map
|