document-model 6.2.3-staging.0 → 6.3.0-dev.1
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/dist/catalog-B3nJD57s.d.ts +85 -0
- package/dist/catalog-B3nJD57s.d.ts.map +1 -0
- package/dist/index.d.ts +844 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6284 -14
- package/dist/index.js.map +1 -1
- package/dist/model-scalars-BzEq3l83.js +399 -0
- package/dist/model-scalars-BzEq3l83.js.map +1 -0
- package/dist/scalars.d.ts +53 -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 +668 -0
- package/dist/tooling.d.mts.map +1 -0
- package/dist/tooling.mjs +7993 -0
- package/dist/tooling.mjs.map +1 -0
- package/package.json +24 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
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, DocumentModelSpecificationDefinition, DocumentOperations, IsDocumentOfType, IsStateOfType, JsonValue, LocationFreeGraphQLDocumentNode, Operation, PHBaseState, PHDocument, PHDocumentHeader, PackageScalarReferenceDefinition, SignalDispatch, SubgraphDefinition, 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
6
|
//#region src/controller.d.ts
|
|
4
7
|
type ScreamingSnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Lowercase<Head>}${Capitalize<ScreamingSnakeToCamel<Tail>>}` : Lowercase<S>;
|
|
@@ -76,5 +79,845 @@ export declare const assertIsDocumentOfType: AssertIsDocumentOfType<DocumentMode
|
|
|
76
79
|
export declare const documentModelCreateState: CreateState<DocumentModelPHState>;
|
|
77
80
|
export declare function documentModelCreateDocument(state?: Partial<DocumentModelPHState>): DocumentModelDocument;
|
|
78
81
|
//#endregion
|
|
82
|
+
//#region src/definition/compiler/graphql-projection.d.ts
|
|
83
|
+
type GraphQLSegment = {
|
|
84
|
+
readonly root: string;
|
|
85
|
+
readonly document: LocationFreeGraphQLDocumentNode;
|
|
86
|
+
};
|
|
87
|
+
type DocumentModelGraphQLProjection = {
|
|
88
|
+
readonly graphQLName: string;
|
|
89
|
+
readonly global: GraphQLSegment;
|
|
90
|
+
readonly local: GraphQLSegment | null;
|
|
91
|
+
readonly modules: readonly {
|
|
92
|
+
readonly key: string;
|
|
93
|
+
readonly name: string;
|
|
94
|
+
readonly operations: readonly {
|
|
95
|
+
readonly key: string;
|
|
96
|
+
readonly name: string;
|
|
97
|
+
readonly actionType: string;
|
|
98
|
+
readonly creatorKey: string;
|
|
99
|
+
readonly scope: "global" | "local";
|
|
100
|
+
readonly input: LocationFreeGraphQLDocumentNode | null;
|
|
101
|
+
}[];
|
|
102
|
+
}[];
|
|
103
|
+
readonly packageScalars: readonly PackageScalarReferenceDefinition[];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Projects a specification into the GraphQL documents its stored SDL
|
|
107
|
+
* segments parse to: `print(segment.document)` equals
|
|
108
|
+
* `print(parse(storedSegment))` for the state schemas and each operation's
|
|
109
|
+
* `schema` that `materialize` stores.
|
|
110
|
+
*/
|
|
111
|
+
export declare function projectDocumentModelGraphQL(definition: DocumentModelDefinition, specification: DocumentModelSpecificationDefinition): DocumentModelGraphQLProjection;
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/definition/dsl/types.d.ts
|
|
114
|
+
type FieldValidationOptions<TRequired extends boolean = boolean> = {
|
|
115
|
+
readonly required?: TRequired;
|
|
116
|
+
};
|
|
117
|
+
type FieldTextOptions = {
|
|
118
|
+
readonly description?: string;
|
|
119
|
+
readonly deprecated?: string;
|
|
120
|
+
};
|
|
121
|
+
type EqualsOption = {
|
|
122
|
+
readonly equals?: string;
|
|
123
|
+
};
|
|
124
|
+
type JsonLiteral = string | number | boolean | null | readonly JsonLiteral[] | {
|
|
125
|
+
readonly [key: string]: JsonLiteral;
|
|
126
|
+
};
|
|
127
|
+
type FieldBuilderOptions<TRequired extends boolean = boolean, TDefault extends JsonLiteral | undefined = JsonLiteral | undefined> = FieldValidationOptions<TRequired> & FieldTextOptions & {
|
|
128
|
+
readonly defaultValue?: TDefault | (TDefault extends undefined ? JsonLiteral : never);
|
|
129
|
+
};
|
|
130
|
+
type ScalarBuilderOptions<TRequired extends boolean = boolean, TDefault extends JsonLiteral | undefined = JsonLiteral | undefined> = FieldBuilderOptions<TRequired, TDefault> & EqualsOption;
|
|
131
|
+
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;
|
|
132
|
+
type AllLiteral<T> = [T] extends [never] ? true : false extends IsLiteral<T> ? false : true;
|
|
133
|
+
type DefaultFlag<TDefault> = [TDefault] extends [undefined] ? false : undefined extends TDefault ? boolean : IsLiteral<TDefault> extends true ? true : boolean;
|
|
134
|
+
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>>;
|
|
135
|
+
type FieldDefault = {
|
|
136
|
+
readonly present: false;
|
|
137
|
+
} | {
|
|
138
|
+
readonly present: true;
|
|
139
|
+
readonly value: JsonValue;
|
|
140
|
+
};
|
|
141
|
+
type FieldPresentation = {
|
|
142
|
+
readonly description: string | null;
|
|
143
|
+
readonly deprecated: string | null;
|
|
144
|
+
readonly default: FieldDefault;
|
|
145
|
+
readonly directives: readonly DirectiveUseDefinition[];
|
|
146
|
+
};
|
|
147
|
+
type NamedTypeKind = "enum" | "object" | "input" | "interface" | "union";
|
|
148
|
+
type FieldUseKind = "scalar" | "list" | "ref";
|
|
149
|
+
type DescriptorKind = NamedTypeKind | FieldUseKind;
|
|
150
|
+
type ScalarIdentity = {
|
|
151
|
+
readonly kind: "scalar";
|
|
152
|
+
readonly name: string;
|
|
153
|
+
readonly required: boolean;
|
|
154
|
+
};
|
|
155
|
+
type ListIdentity = {
|
|
156
|
+
readonly kind: "list";
|
|
157
|
+
readonly required: boolean;
|
|
158
|
+
readonly item: GraphQLIdentity;
|
|
159
|
+
};
|
|
160
|
+
type ReferenceIdentity = {
|
|
161
|
+
readonly kind: "ref";
|
|
162
|
+
readonly required: boolean;
|
|
163
|
+
};
|
|
164
|
+
type NamedTypeIdentity = {
|
|
165
|
+
readonly kind: NamedTypeKind;
|
|
166
|
+
readonly name: string | null;
|
|
167
|
+
readonly description: string | null;
|
|
168
|
+
};
|
|
169
|
+
type GraphQLIdentity = ScalarIdentity | ListIdentity | ReferenceIdentity | NamedTypeIdentity;
|
|
170
|
+
type DescriptorNode<TInput, TOutput, TSource = TOutput> = {
|
|
171
|
+
readonly kind: DescriptorKind;
|
|
172
|
+
readonly identity: GraphQLIdentity;
|
|
173
|
+
readonly validator: z.ZodType;
|
|
174
|
+
readonly __types?: {
|
|
175
|
+
readonly input: TInput;
|
|
176
|
+
readonly output: TOutput;
|
|
177
|
+
readonly source: TSource;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
declare const FIELD_USE_ROLE: "field use";
|
|
181
|
+
declare const NAMED_TYPE_ROLE: "named type; wrap it with ph.ref(Type) to use it as a field";
|
|
182
|
+
type FieldDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = DescriptorNode<TInput, TOutput, TSource> & {
|
|
183
|
+
readonly role: typeof FIELD_USE_ROLE;
|
|
184
|
+
readonly kind: FieldUseKind;
|
|
185
|
+
readonly required: TRequired;
|
|
186
|
+
readonly presentation: FieldPresentation & {
|
|
187
|
+
readonly default: {
|
|
188
|
+
readonly present: TDefaulted;
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
type TypeDescriptor<TInput, TOutput, TSource = TOutput> = DescriptorNode<TInput, TOutput, TSource> & {
|
|
193
|
+
readonly role: typeof NAMED_TYPE_ROLE;
|
|
194
|
+
readonly kind: NamedTypeKind;
|
|
195
|
+
readonly name: string | null;
|
|
196
|
+
readonly description: string | null;
|
|
197
|
+
};
|
|
198
|
+
type AnyFieldDescriptor = FieldDescriptor<any, any, any>;
|
|
199
|
+
type AnyTypeDescriptor = TypeDescriptor<any, any, any>;
|
|
200
|
+
type Nullable<T, TRequired extends boolean> = TRequired extends true ? T : T | null | undefined;
|
|
201
|
+
type InputOf<T> = T extends DescriptorNode<infer TInput, any, any> ? TInput : never;
|
|
202
|
+
type OutputOf<T> = T extends DescriptorNode<any, infer TOutput, any> ? TOutput : never;
|
|
203
|
+
type SourceOf<T> = T extends DescriptorNode<any, any, infer TSource> ? TSource : never;
|
|
204
|
+
type RequiredOf<T> = T extends {
|
|
205
|
+
readonly required: infer TRequired;
|
|
206
|
+
} ? TRequired : never;
|
|
207
|
+
type DefaultedOf<T> = T extends {
|
|
208
|
+
readonly presentation: {
|
|
209
|
+
readonly default: {
|
|
210
|
+
readonly present: infer P;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
} ? P : never;
|
|
214
|
+
type ObjectFields = Readonly<Record<string, AnyFieldDescriptor>>;
|
|
215
|
+
type RequiredKeys<TFields extends ObjectFields> = { [K in keyof TFields]: RequiredOf<TFields[K]> extends true ? K : never; }[keyof TFields];
|
|
216
|
+
/** A caller may omit a required field that has a default. */
|
|
217
|
+
type CallerRequiredKeys<TFields extends ObjectFields> = { [K in RequiredKeys<TFields>]: DefaultedOf<TFields[K]> extends true ? never : K; }[RequiredKeys<TFields>];
|
|
218
|
+
/** @experimental */
|
|
219
|
+
type InputObjectOf<TFields extends ObjectFields> = { -readonly [K in CallerRequiredKeys<TFields>]: InputOf<TFields[K]>; } & { -readonly [K in Exclude<keyof TFields, CallerRequiredKeys<TFields>>]?: InputOf<TFields[K]>; };
|
|
220
|
+
type ResolvedInputObjectOf<TFields extends ObjectFields> = { -readonly [K in RequiredKeys<TFields>]: SourceOf<TFields[K]>; } & { -readonly [K in Exclude<keyof TFields, RequiredKeys<TFields>>]?: SourceOf<TFields[K]>; };
|
|
221
|
+
/** @experimental */
|
|
222
|
+
type OutputObjectOf<TFields extends ObjectFields> = { -readonly [K in keyof TFields]: OutputOf<TFields[K]>; };
|
|
223
|
+
type SourceObjectOf<TFields extends ObjectFields> = { -readonly [K in keyof TFields]: SourceOf<TFields[K]>; };
|
|
224
|
+
type EnumValueInput = string | {
|
|
225
|
+
readonly name: string;
|
|
226
|
+
readonly description?: string;
|
|
227
|
+
readonly deprecated?: string;
|
|
228
|
+
};
|
|
229
|
+
type EnumValueNameOf<TValue extends EnumValueInput> = TValue extends string ? TValue : TValue extends {
|
|
230
|
+
readonly name: infer TName extends string;
|
|
231
|
+
} ? TName : never;
|
|
232
|
+
type EnumValue = {
|
|
233
|
+
readonly name: string;
|
|
234
|
+
readonly description: string | null;
|
|
235
|
+
readonly deprecated: string | null;
|
|
236
|
+
};
|
|
237
|
+
/** @experimental */
|
|
238
|
+
type EnumDescriptor<TValues extends readonly EnumValueInput[] = readonly EnumValueInput[]> = TypeDescriptor<EnumValueNameOf<TValues[number]>, EnumValueNameOf<TValues[number]>, EnumValueNameOf<TValues[number]>> & {
|
|
239
|
+
readonly kind: "enum";
|
|
240
|
+
readonly name: string;
|
|
241
|
+
readonly values: readonly EnumValue[];
|
|
242
|
+
};
|
|
243
|
+
/** @experimental */
|
|
244
|
+
type InterfaceDescriptor<TFields extends ObjectFields = ObjectFields, TImplements extends readonly InterfaceDescriptor<ObjectFields, any>[] = readonly InterfaceDescriptor<ObjectFields, any>[]> = TypeDescriptor<InputObjectOf<TFields>, OutputObjectOf<TFields>, SourceObjectOf<TFields>> & {
|
|
245
|
+
readonly kind: "interface";
|
|
246
|
+
readonly name: string;
|
|
247
|
+
readonly fields: TFields;
|
|
248
|
+
readonly implements: TImplements;
|
|
249
|
+
};
|
|
250
|
+
/** @experimental */
|
|
251
|
+
type ObjectDescriptor<TFields extends ObjectFields = ObjectFields, TImplements extends readonly InterfaceDescriptor[] = readonly InterfaceDescriptor[]> = TypeDescriptor<InputObjectOf<TFields>, OutputObjectOf<TFields>, SourceObjectOf<TFields>> & {
|
|
252
|
+
readonly kind: "object";
|
|
253
|
+
readonly name: string;
|
|
254
|
+
readonly fields: TFields;
|
|
255
|
+
readonly implements: TImplements;
|
|
256
|
+
};
|
|
257
|
+
/** @experimental */
|
|
258
|
+
type InputDescriptor<TFields extends ObjectFields = ObjectFields> = TypeDescriptor<InputObjectOf<TFields>, InputObjectOf<TFields>, ResolvedInputObjectOf<TFields>> & {
|
|
259
|
+
readonly kind: "input";
|
|
260
|
+
readonly fields: TFields;
|
|
261
|
+
};
|
|
262
|
+
/** @experimental */
|
|
263
|
+
type UnionDescriptor<TMembers extends readonly ObjectDescriptor[] = readonly ObjectDescriptor[]> = TypeDescriptor<InputOf<TMembers[number]>, OutputOf<TMembers[number]>, SourceOf<TMembers[number]>> & {
|
|
264
|
+
readonly kind: "union";
|
|
265
|
+
readonly name: string;
|
|
266
|
+
readonly members: TMembers;
|
|
267
|
+
};
|
|
268
|
+
type RefTarget = AnyTypeDescriptor | (() => AnyTypeDescriptor);
|
|
269
|
+
/** @experimental */
|
|
270
|
+
type ReferenceDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = FieldDescriptor<TInput, TOutput, TSource, TRequired, TDefaulted> & {
|
|
271
|
+
readonly kind: "ref";
|
|
272
|
+
readonly target: RefTarget;
|
|
273
|
+
};
|
|
274
|
+
/** @experimental */
|
|
275
|
+
type ListDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = FieldDescriptor<TInput, TOutput, TSource, TRequired, TDefaulted> & {
|
|
276
|
+
readonly kind: "list";
|
|
277
|
+
readonly item: AnyFieldDescriptor;
|
|
278
|
+
};
|
|
279
|
+
/** @experimental */
|
|
280
|
+
type ScalarDescriptor<TInput, TOutput, TSource = TOutput, TRequired extends boolean = boolean, TDefaulted extends boolean = boolean> = FieldDescriptor<TInput, TOutput, TSource, TRequired, TDefaulted> & {
|
|
281
|
+
readonly kind: "scalar";
|
|
282
|
+
readonly scalarName: string;
|
|
283
|
+
readonly baseValidator: z.ZodType;
|
|
284
|
+
readonly definition?: ScalarDefinition;
|
|
285
|
+
};
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/definition/dsl/scalar-fields.d.ts
|
|
288
|
+
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>>;
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/definition/dsl/field.d.ts
|
|
291
|
+
type NamedOptions = {
|
|
292
|
+
readonly description?: string;
|
|
293
|
+
};
|
|
294
|
+
type EnumOptions<TValues extends readonly EnumValueInput[]> = NamedOptions & {
|
|
295
|
+
readonly values: TValues;
|
|
296
|
+
};
|
|
297
|
+
type FieldsOptions<TFields extends ObjectFields> = NamedOptions & {
|
|
298
|
+
readonly fields: TFields;
|
|
299
|
+
};
|
|
300
|
+
type ImplementsOptions<TImplements extends readonly InterfaceDescriptor[]> = {
|
|
301
|
+
readonly implements?: TImplements;
|
|
302
|
+
};
|
|
303
|
+
type ImplementingOptions<TFields extends ObjectFields, TImplements extends readonly InterfaceDescriptor[]> = FieldsOptions<TFields> & ImplementsOptions<TImplements>;
|
|
304
|
+
type UnionOptions<TMembers extends readonly ObjectDescriptor[]> = NamedOptions & {
|
|
305
|
+
readonly members: TMembers;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* The first signature types an object without `implements` as implementing
|
|
309
|
+
* nothing. A single generic signature would infer `TImplements` from the
|
|
310
|
+
* contextual type instead, as for a union member or an inline state root,
|
|
311
|
+
* and widen it to every interface.
|
|
312
|
+
*/
|
|
313
|
+
declare function objectType<const TFields extends ObjectFields>(name: string, options: ImplementingOptions<TFields, readonly []>): ObjectDescriptor<TFields, readonly []>;
|
|
314
|
+
declare function objectType<const TFields extends ObjectFields, const TImplements extends readonly InterfaceDescriptor[]>(name: string, options: ImplementingOptions<TFields, TImplements>): ObjectDescriptor<TFields, TImplements>;
|
|
315
|
+
/** Overloaded like `objectType`, for the same reason. */
|
|
316
|
+
declare function interfaceType<const TFields extends ObjectFields>(name: string, options: ImplementingOptions<TFields, readonly []>): InterfaceDescriptor<TFields, readonly []>;
|
|
317
|
+
declare function interfaceType<const TFields extends ObjectFields, const TImplements extends readonly InterfaceDescriptor[]>(name: string, options: ImplementingOptions<TFields, TImplements>): InterfaceDescriptor<TFields, TImplements>;
|
|
318
|
+
/**
|
|
319
|
+
* @experimental The field and type builders of a code-first document model:
|
|
320
|
+
* scalar factories such as `ph.String()` and `ph.PHID()`, `ph.scalar` for a
|
|
321
|
+
* project scalar, and `list`, `ref`, `enum`, `object`, `interface`, `input`,
|
|
322
|
+
* and `union`.
|
|
323
|
+
*/
|
|
324
|
+
export declare const ph: Readonly<{
|
|
325
|
+
ID: ScalarBuilder<string> & {
|
|
326
|
+
readonly role: "field-use factory; call it, as ph.ID({ required: true })";
|
|
327
|
+
readonly kind: "scalar-factory";
|
|
328
|
+
};
|
|
329
|
+
String: ScalarBuilder<string> & {
|
|
330
|
+
readonly role: "field-use factory; call it, as ph.String({ required: true })";
|
|
331
|
+
readonly kind: "scalar-factory";
|
|
332
|
+
};
|
|
333
|
+
Boolean: ScalarBuilder<boolean> & {
|
|
334
|
+
readonly role: "field-use factory; call it, as ph.Boolean({ required: true })";
|
|
335
|
+
readonly kind: "scalar-factory";
|
|
336
|
+
};
|
|
337
|
+
Int: ScalarBuilder<number> & {
|
|
338
|
+
readonly role: "field-use factory; call it, as ph.Int({ required: true })";
|
|
339
|
+
readonly kind: "scalar-factory";
|
|
340
|
+
};
|
|
341
|
+
Float: ScalarBuilder<number> & {
|
|
342
|
+
readonly role: "field-use factory; call it, as ph.Float({ required: true })";
|
|
343
|
+
readonly kind: "scalar-factory";
|
|
344
|
+
};
|
|
345
|
+
scalar: typeof scalarField;
|
|
346
|
+
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>>;
|
|
347
|
+
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>>;
|
|
348
|
+
enum<const TValues extends readonly [EnumValueInput, ...EnumValueInput[]]>(name: string, options: EnumOptions<TValues>): EnumDescriptor<TValues>;
|
|
349
|
+
object: typeof objectType;
|
|
350
|
+
interface: typeof interfaceType;
|
|
351
|
+
input<const TFields extends ObjectFields>(...args: [name: string, options: FieldsOptions<TFields>] | [options: FieldsOptions<TFields>]): InputDescriptor<TFields>;
|
|
352
|
+
union<const TMembers extends readonly [ObjectDescriptor, ...ObjectDescriptor[]]>(name: string, options: UnionOptions<TMembers>): UnionDescriptor<TMembers>;
|
|
353
|
+
Address: ScalarBuilder<string> & {
|
|
354
|
+
readonly role: "field-use factory; call it, as ph.Address({ required: true })";
|
|
355
|
+
readonly kind: "scalar-factory";
|
|
356
|
+
};
|
|
357
|
+
Amount: ScalarBuilder<{
|
|
358
|
+
unit?: string | undefined;
|
|
359
|
+
value: number;
|
|
360
|
+
}> & {
|
|
361
|
+
readonly role: "field-use factory; call it, as ph.Amount({ required: true })";
|
|
362
|
+
readonly kind: "scalar-factory";
|
|
363
|
+
};
|
|
364
|
+
AmountCrypto: ScalarBuilder<{
|
|
365
|
+
unit: string;
|
|
366
|
+
value: string;
|
|
367
|
+
}> & {
|
|
368
|
+
readonly role: "field-use factory; call it, as ph.AmountCrypto({ required: true })";
|
|
369
|
+
readonly kind: "scalar-factory";
|
|
370
|
+
};
|
|
371
|
+
AmountCurrency: ScalarBuilder<{
|
|
372
|
+
unit: string;
|
|
373
|
+
value: string;
|
|
374
|
+
}> & {
|
|
375
|
+
readonly role: "field-use factory; call it, as ph.AmountCurrency({ required: true })";
|
|
376
|
+
readonly kind: "scalar-factory";
|
|
377
|
+
};
|
|
378
|
+
AmountFiat: ScalarBuilder<{
|
|
379
|
+
unit: string;
|
|
380
|
+
value: number;
|
|
381
|
+
}> & {
|
|
382
|
+
readonly role: "field-use factory; call it, as ph.AmountFiat({ required: true })";
|
|
383
|
+
readonly kind: "scalar-factory";
|
|
384
|
+
};
|
|
385
|
+
AttachmentRef: ScalarBuilder<string> & {
|
|
386
|
+
readonly role: "field-use factory; call it, as ph.AttachmentRef({ required: true })";
|
|
387
|
+
readonly kind: "scalar-factory";
|
|
388
|
+
};
|
|
389
|
+
Currency: ScalarBuilder<string> & {
|
|
390
|
+
readonly role: "field-use factory; call it, as ph.Currency({ required: true })";
|
|
391
|
+
readonly kind: "scalar-factory";
|
|
392
|
+
};
|
|
393
|
+
Date: ScalarBuilder<string> & {
|
|
394
|
+
readonly role: "field-use factory; call it, as ph.Date({ required: true })";
|
|
395
|
+
readonly kind: "scalar-factory";
|
|
396
|
+
};
|
|
397
|
+
DateTime: ScalarBuilder<string> & {
|
|
398
|
+
readonly role: "field-use factory; call it, as ph.DateTime({ required: true })";
|
|
399
|
+
readonly kind: "scalar-factory";
|
|
400
|
+
};
|
|
401
|
+
EmailAddress: ScalarBuilder<string> & {
|
|
402
|
+
readonly role: "field-use factory; call it, as ph.EmailAddress({ required: true })";
|
|
403
|
+
readonly kind: "scalar-factory";
|
|
404
|
+
};
|
|
405
|
+
EthereumAddress: ScalarBuilder<string> & {
|
|
406
|
+
readonly role: "field-use factory; call it, as ph.EthereumAddress({ required: true })";
|
|
407
|
+
readonly kind: "scalar-factory";
|
|
408
|
+
};
|
|
409
|
+
Money: ScalarBuilder<number> & {
|
|
410
|
+
readonly role: "field-use factory; call it, as ph.Money({ required: true })";
|
|
411
|
+
readonly kind: "scalar-factory";
|
|
412
|
+
};
|
|
413
|
+
OID: ScalarBuilder<string> & {
|
|
414
|
+
readonly role: "field-use factory; call it, as ph.OID({ required: true })";
|
|
415
|
+
readonly kind: "scalar-factory";
|
|
416
|
+
};
|
|
417
|
+
OLabel: ScalarBuilder<string> & {
|
|
418
|
+
readonly role: "field-use factory; call it, as ph.OLabel({ required: true })";
|
|
419
|
+
readonly kind: "scalar-factory";
|
|
420
|
+
};
|
|
421
|
+
PHID: ScalarBuilder<string> & {
|
|
422
|
+
readonly role: "field-use factory; call it, as ph.PHID({ required: true })";
|
|
423
|
+
readonly kind: "scalar-factory";
|
|
424
|
+
};
|
|
425
|
+
Percentage: ScalarBuilder<number> & {
|
|
426
|
+
readonly role: "field-use factory; call it, as ph.Percentage({ required: true })";
|
|
427
|
+
readonly kind: "scalar-factory";
|
|
428
|
+
};
|
|
429
|
+
Tokens: ScalarBuilder<number> & {
|
|
430
|
+
readonly role: "field-use factory; call it, as ph.Tokens({ required: true })";
|
|
431
|
+
readonly kind: "scalar-factory";
|
|
432
|
+
};
|
|
433
|
+
URL: ScalarBuilder<string> & {
|
|
434
|
+
readonly role: "field-use factory; call it, as ph.URL({ required: true })";
|
|
435
|
+
readonly kind: "scalar-factory";
|
|
436
|
+
};
|
|
437
|
+
Unknown: ScalarBuilder<unknown> & {
|
|
438
|
+
readonly role: "field-use factory; call it, as ph.Unknown({ required: true })";
|
|
439
|
+
readonly kind: "scalar-factory";
|
|
440
|
+
};
|
|
441
|
+
Upload: ScalarBuilder<any> & {
|
|
442
|
+
readonly role: "field-use factory; call it, as ph.Upload({ required: true })";
|
|
443
|
+
readonly kind: "scalar-factory";
|
|
444
|
+
};
|
|
445
|
+
}>;
|
|
446
|
+
/** @experimental The type of `ph`. */
|
|
447
|
+
type Ph = typeof ph;
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/definition/kernel/diagnostics.d.ts
|
|
450
|
+
/**
|
|
451
|
+
* @experimental Thrown when a code-first declaration is refused. `diagnostics`
|
|
452
|
+
* holds every problem found, sorted, each with its code, path and repair.
|
|
453
|
+
*/
|
|
454
|
+
export declare class DefinitionError extends Error {
|
|
455
|
+
readonly diagnostics: readonly DefinitionDiagnostic[];
|
|
456
|
+
constructor(diagnostics: readonly [DefinitionDiagnostic, ...DefinitionDiagnostic[]]);
|
|
457
|
+
}
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/definition/compiler/naming.d.ts
|
|
460
|
+
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
461
|
+
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;
|
|
462
|
+
type DocumentModelActionType<TKey extends string> = string extends TKey ? string : ActionTypeWords<TKey>;
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/definition/compiler/compile.d.ts
|
|
465
|
+
type StateRootDescriptor = ObjectDescriptor;
|
|
466
|
+
type OperationErrorDeclaration = {
|
|
467
|
+
readonly code?: string | null;
|
|
468
|
+
readonly name?: string | null;
|
|
469
|
+
readonly description?: string | null;
|
|
470
|
+
readonly template?: string | null;
|
|
471
|
+
};
|
|
472
|
+
type DefinitionExampleDeclaration = {
|
|
473
|
+
readonly key: string;
|
|
474
|
+
readonly value: string;
|
|
475
|
+
};
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/definition/model/types.d.ts
|
|
478
|
+
type Mutable<T> = T extends readonly (infer TItem)[] ? Mutable<TItem>[] : T extends object ? { -readonly [K in keyof T]: Mutable<T[K]>; } : T;
|
|
479
|
+
type StateScopeDeclaration<TSchema extends StateRootDescriptor> = {
|
|
480
|
+
readonly schema: TSchema;
|
|
481
|
+
readonly initialValue: SourceOf<TSchema>;
|
|
482
|
+
readonly examples?: readonly DefinitionExampleDeclaration[];
|
|
483
|
+
};
|
|
484
|
+
type EmptyLocalScopeDeclaration = {
|
|
485
|
+
readonly schema: null;
|
|
486
|
+
readonly initialValue: Readonly<Record<string, never>>;
|
|
487
|
+
readonly examples?: readonly DefinitionExampleDeclaration[];
|
|
488
|
+
};
|
|
489
|
+
type LocalScopeDeclaration<TLocal extends StateRootDescriptor | null> = TLocal extends StateRootDescriptor ? StateScopeDeclaration<TLocal> : EmptyLocalScopeDeclaration;
|
|
490
|
+
type LocalScopeEntry<TLocal extends StateRootDescriptor | null> = [TLocal] extends [null] ? {
|
|
491
|
+
readonly local?: EmptyLocalScopeDeclaration;
|
|
492
|
+
} : {
|
|
493
|
+
readonly local: LocalScopeDeclaration<TLocal>;
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* @experimental A model without local state can omit `scopes.local`, which
|
|
497
|
+
* means `local: { schema: null, initialValue: {} }`.
|
|
498
|
+
*/
|
|
499
|
+
type DocumentModelConfig<TGlobal extends StateRootDescriptor, TLocal extends StateRootDescriptor | null, TVersion extends number> = {
|
|
500
|
+
readonly id: string;
|
|
501
|
+
readonly name: string;
|
|
502
|
+
readonly description: string;
|
|
503
|
+
readonly extension: string;
|
|
504
|
+
readonly version: TVersion;
|
|
505
|
+
readonly author: {
|
|
506
|
+
readonly name: string;
|
|
507
|
+
readonly website?: string | null;
|
|
508
|
+
};
|
|
509
|
+
readonly changeLog?: readonly string[];
|
|
510
|
+
readonly scopes: {
|
|
511
|
+
readonly auxiliaryTypes?: readonly AnyTypeDescriptor[];
|
|
512
|
+
readonly global: StateScopeDeclaration<TGlobal>;
|
|
513
|
+
} & LocalScopeEntry<TLocal>;
|
|
514
|
+
};
|
|
515
|
+
type LocalStateOfDescriptor<TLocal extends StateRootDescriptor | null> = TLocal extends StateRootDescriptor ? Mutable<SourceOf<TLocal>> : Record<string, never>;
|
|
516
|
+
/** @experimental The document state a model's descriptors describe. */
|
|
517
|
+
type ModelState<TGlobal extends StateRootDescriptor, TLocal extends StateRootDescriptor | null> = PHBaseState & {
|
|
518
|
+
global: Mutable<SourceOf<TGlobal>>;
|
|
519
|
+
local: LocalStateOfDescriptor<TLocal>;
|
|
520
|
+
};
|
|
521
|
+
type ErrorDeclarations = Readonly<Record<string, OperationErrorDeclaration>>;
|
|
522
|
+
type ErrorCodeOf<TKey extends string, TError> = TError extends {
|
|
523
|
+
readonly code: infer TCode extends string;
|
|
524
|
+
} ? TCode extends "" ? TError extends {
|
|
525
|
+
readonly name: string;
|
|
526
|
+
} ? string : TKey : TCode : TKey;
|
|
527
|
+
type OperationErrorClasses<TErrors extends ErrorDeclarations> = { readonly [K in keyof TErrors & string]: new (message?: string) => Error & {
|
|
528
|
+
readonly errorCode: ErrorCodeOf<K, TErrors[K]>;
|
|
529
|
+
}; };
|
|
530
|
+
type ModelOperationContext<TInput extends InputDescriptor, TErrors extends ErrorDeclarations> = {
|
|
531
|
+
readonly errors: OperationErrorClasses<TErrors>;
|
|
532
|
+
readonly action: Action & {
|
|
533
|
+
readonly input: InputOf<TInput>;
|
|
534
|
+
};
|
|
535
|
+
readonly dispatch: SignalDispatch | undefined;
|
|
536
|
+
};
|
|
537
|
+
type ModelOperationConfig<TState, TInput extends InputDescriptor, TErrors extends ErrorDeclarations> = {
|
|
538
|
+
readonly description?: string;
|
|
539
|
+
readonly input: TInput;
|
|
540
|
+
readonly errors?: TErrors;
|
|
541
|
+
readonly examples?: readonly DefinitionExampleDeclaration[];
|
|
542
|
+
readonly template?: string | null;
|
|
543
|
+
readonly reducerTemplate?: string | null;
|
|
544
|
+
readonly reduce: (state: Mutable<TState>, input: Mutable<InputOf<TInput>>, context: ModelOperationContext<TInput, TErrors>) => void;
|
|
545
|
+
};
|
|
546
|
+
declare const operationTokenBrand: unique symbol;
|
|
547
|
+
/** @experimental An operation declared by a scope builder. */
|
|
548
|
+
interface ModelOperationToken<TInput extends InputDescriptor = InputDescriptor, TScope extends "global" | "local" = "global" | "local"> {
|
|
549
|
+
readonly kind: "powerhouse.document-model-operation";
|
|
550
|
+
readonly [operationTokenBrand]?: {
|
|
551
|
+
readonly input: TInput;
|
|
552
|
+
readonly scope: TScope;
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
interface ModelOperationBuilder<TState, TScope extends "global" | "local"> {
|
|
556
|
+
<const TInput extends InputDescriptor, const TErrors extends ErrorDeclarations = Record<never, never>>(config: ModelOperationConfig<TState, TInput, TErrors>): ModelOperationToken<TInput, TScope>;
|
|
557
|
+
}
|
|
558
|
+
type InputOfOperation<T> = T extends ModelOperationToken<infer TInput, any> ? InputOf<TInput> : never;
|
|
559
|
+
type ScopeOfOperation<T> = T extends ModelOperationToken<any, infer TScope> ? TScope : never;
|
|
560
|
+
type ActionForOperation<T, TType extends string = string> = Action & {
|
|
561
|
+
readonly type: TType;
|
|
562
|
+
readonly input: InputOfOperation<T>;
|
|
563
|
+
readonly scope: ScopeOfOperation<T>;
|
|
564
|
+
};
|
|
565
|
+
type CreatorParameters<T> = keyof InputOfOperation<T> extends never ? [input?: InputOfOperation<T>] : [input: InputOfOperation<T>];
|
|
566
|
+
/** @experimental */
|
|
567
|
+
type ActionsForOperationTokens<TOperations extends Readonly<Record<string, ModelOperationToken>>> = { readonly [K in keyof TOperations]: (...args: CreatorParameters<TOperations[K]>) => ActionForOperation<TOperations[K], DocumentModelActionType<K & string>>; };
|
|
568
|
+
declare const moduleTokenBrand: unique symbol;
|
|
569
|
+
/** @experimental A module declared by `context.module`. */
|
|
570
|
+
interface ModelModuleToken<TState extends PHBaseState = PHBaseState, TActions extends Actions = Actions, TKey extends string = string> {
|
|
571
|
+
readonly kind: "powerhouse.document-model-module";
|
|
572
|
+
readonly [moduleTokenBrand]?: {
|
|
573
|
+
readonly state: TState;
|
|
574
|
+
readonly actions: TActions;
|
|
575
|
+
readonly key: TKey;
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
|
|
579
|
+
type ModelActionsOf<TModules extends readonly ModelModuleToken[]> = UnionToIntersection<TModules[number] extends ModelModuleToken<any, infer TActions, any> ? TActions : never>;
|
|
580
|
+
type ActionsOfModules<TModules extends readonly ModelModuleToken[], TModelActions = ModelActionsOf<TModules>> = TModelActions & Omit<typeof baseActions, keyof TModelActions>;
|
|
581
|
+
declare const versionTokenBrand: unique symbol;
|
|
582
|
+
/**
|
|
583
|
+
* @experimental A compiled model version. `materialize` turns it into a
|
|
584
|
+
* document model module; `defineDocumentModelFamily` composes several.
|
|
585
|
+
*/
|
|
586
|
+
interface DocumentModelVersionDefinition<TVersion extends number = number, TState extends PHBaseState = PHBaseState, TActions extends Actions = Actions> {
|
|
587
|
+
readonly kind: "powerhouse.document-model-version";
|
|
588
|
+
readonly version: TVersion;
|
|
589
|
+
readonly documentType: string;
|
|
590
|
+
readonly [versionTokenBrand]?: {
|
|
591
|
+
readonly state: TState;
|
|
592
|
+
readonly actions: TActions;
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
type DocumentModelVersionConfig<TModules extends readonly ModelModuleToken[]> = {
|
|
596
|
+
readonly modules: TModules;
|
|
597
|
+
};
|
|
598
|
+
/** @experimental The context `defineDocumentModel` returns. */
|
|
599
|
+
interface DocumentModelContext<TGlobal extends StateRootDescriptor, TLocal extends StateRootDescriptor | null, TVersion extends number> {
|
|
600
|
+
module<const TKey extends string, const TOperations extends Readonly<Record<string, ModelOperationToken>>>(key: TKey, config: {
|
|
601
|
+
readonly description?: string;
|
|
602
|
+
readonly operations: (builders: {
|
|
603
|
+
readonly global: ModelOperationBuilder<Mutable<SourceOf<TGlobal>>, "global">;
|
|
604
|
+
readonly local: ModelOperationBuilder<LocalStateOfDescriptor<TLocal>, "local">;
|
|
605
|
+
}) => TOperations;
|
|
606
|
+
}): ModelModuleToken<ModelState<TGlobal, TLocal>, ActionsForOperationTokens<TOperations>, TKey>;
|
|
607
|
+
version<const TModules extends readonly ModelModuleToken<ModelState<TGlobal, TLocal>, Actions>[]>(config: DocumentModelVersionConfig<TModules>): DocumentModelVersionDefinition<TVersion, ModelState<TGlobal, TLocal>, ActionsOfModules<TModules>>;
|
|
608
|
+
}
|
|
609
|
+
declare const familyTokenBrand: unique symbol;
|
|
610
|
+
/**
|
|
611
|
+
* @experimental The checked versions of one document type and their upgrade
|
|
612
|
+
* manifest. `materialize` turns it into one module per version.
|
|
613
|
+
*/
|
|
614
|
+
interface DocumentModelFamilyDefinition<TVersions extends readonly DocumentModelVersionDefinition[] = readonly DocumentModelVersionDefinition[]> {
|
|
615
|
+
readonly kind: "powerhouse.document-model-family";
|
|
616
|
+
readonly documentType: string;
|
|
617
|
+
readonly [familyTokenBrand]?: {
|
|
618
|
+
readonly versions: TVersions;
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/definition/model/define-document-model.d.ts
|
|
623
|
+
/**
|
|
624
|
+
* @experimental Declares a document model version from `ph` descriptors.
|
|
625
|
+
* The context's `module()` declares operations and `version()` compiles them
|
|
626
|
+
* into a token for `materialize` or `defineDocumentModelFamily`.
|
|
627
|
+
*/
|
|
628
|
+
export declare function defineDocumentModel<const TGlobal extends StateRootDescriptor, const TLocal extends StateRootDescriptor | null = null, const TVersion extends number = number>(config: DocumentModelConfig<TGlobal, TLocal, TVersion>): DocumentModelContext<TGlobal, TLocal, TVersion>;
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/definition/model/family.d.ts
|
|
631
|
+
/**
|
|
632
|
+
* @experimental Composes the versions of one document type with the upgrade
|
|
633
|
+
* manifest that moves a document between them. `materialize` turns the
|
|
634
|
+
* result into one module per version.
|
|
635
|
+
*/
|
|
636
|
+
export declare function defineDocumentModelFamily<const TVersions extends readonly DocumentModelVersionDefinition[]>(config: {
|
|
637
|
+
readonly versions: TVersions;
|
|
638
|
+
readonly upgradeManifest: UpgradeManifest<readonly number[]>;
|
|
639
|
+
}): DocumentModelFamilyDefinition<TVersions>;
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/definition/runtime/inspection.d.ts
|
|
642
|
+
type DocumentModelDefinitionInspection = {
|
|
643
|
+
readonly kind: "structured";
|
|
644
|
+
readonly definition: DocumentModelDefinition;
|
|
645
|
+
readonly specification: DocumentModelSpecificationDefinition;
|
|
646
|
+
} | {
|
|
647
|
+
readonly kind: "stored";
|
|
648
|
+
readonly reason: "absent" | "retained";
|
|
649
|
+
} | {
|
|
650
|
+
readonly kind: "stored";
|
|
651
|
+
readonly reason: "invalid" | "mismatch";
|
|
652
|
+
readonly diagnostics: readonly DefinitionDiagnostic[];
|
|
653
|
+
};
|
|
654
|
+
type InspectableDocumentModelModule = {
|
|
655
|
+
readonly documentModel: {
|
|
656
|
+
readonly global: {
|
|
657
|
+
readonly id: string;
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
readonly version?: unknown;
|
|
661
|
+
readonly definition?: unknown;
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Reads the structured definition a module carries. `structured` holds the
|
|
665
|
+
* specification the stored path serves, `specifications.at(-1)`. A module
|
|
666
|
+
* without a valid, matching, canonically serialized definition is served from
|
|
667
|
+
* its stored model.
|
|
668
|
+
*/
|
|
669
|
+
export declare function inspectDocumentModelDefinition(module: InspectableDocumentModelModule): DocumentModelDefinitionInspection;
|
|
670
|
+
/**
|
|
671
|
+
* An operation of a model authored in code: the name it is stored under and
|
|
672
|
+
* the key of its action creator.
|
|
673
|
+
*
|
|
674
|
+
* @experimental
|
|
675
|
+
*/
|
|
676
|
+
type StructuredOperation = {
|
|
677
|
+
readonly storedName: string;
|
|
678
|
+
readonly creatorKey: string;
|
|
679
|
+
};
|
|
680
|
+
/**
|
|
681
|
+
* The operations of a model authored in code, keyed by action type. Empty for
|
|
682
|
+
* a model served from its stored specification, whose operations are stored
|
|
683
|
+
* under their action types.
|
|
684
|
+
*
|
|
685
|
+
* @experimental
|
|
686
|
+
*/
|
|
687
|
+
export declare function operationsByActionType(module: InspectableDocumentModelModule): ReadonlyMap<string, StructuredOperation>;
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/definition/runtime/types.d.ts
|
|
690
|
+
/**
|
|
691
|
+
* @experimental An ordinary `DocumentModelModule` with typed actions and the
|
|
692
|
+
* stored definition it was compiled to. Hosts use `reducer`, `actions`,
|
|
693
|
+
* `utils`, and `documentModel` as they use a generated module's.
|
|
694
|
+
*/
|
|
695
|
+
type CodeFirstDocumentModelModule<TState extends PHBaseState = PHBaseState, TActions extends Actions = Actions> = Omit<DocumentModelModule<TState>, "actions" | "version"> & {
|
|
696
|
+
readonly version: number;
|
|
697
|
+
readonly actions: TActions;
|
|
698
|
+
readonly definition: DocumentModelDefinition;
|
|
699
|
+
};
|
|
700
|
+
type ModuleOfVersion<T> = T extends DocumentModelVersionDefinition<any, infer TState, infer TActions> ? CodeFirstDocumentModelModule<TState, TActions> : never;
|
|
701
|
+
type VersionNumbered<TMember, TVersion extends number> = TMember extends DocumentModelVersionDefinition<infer TNumber, any, any> ? TVersion extends TNumber ? TMember : never : never;
|
|
702
|
+
/** @experimental One module per version, and the family's upgrade manifest. */
|
|
703
|
+
type DocumentModelFamily<TVersions extends readonly DocumentModelVersionDefinition[] = readonly DocumentModelVersionDefinition[]> = {
|
|
704
|
+
readonly modules: { readonly [K in keyof TVersions]: ModuleOfVersion<TVersions[K]>; };
|
|
705
|
+
readonly upgradeManifest: UpgradeManifest<readonly number[]>;
|
|
706
|
+
at<const TVersion extends TVersions[number]["version"]>(version: TVersion): ModuleOfVersion<VersionNumbered<TVersions[number], TVersion>>;
|
|
707
|
+
};
|
|
708
|
+
/** @experimental The global state of a materialized module. */
|
|
709
|
+
type GlobalStateOf<T> = T extends CodeFirstDocumentModelModule<infer TState, any> ? TState extends {
|
|
710
|
+
global: infer TGlobal;
|
|
711
|
+
} ? TGlobal : never : never;
|
|
712
|
+
/** @experimental The local state of a materialized module. */
|
|
713
|
+
type LocalStateOf<T> = T extends CodeFirstDocumentModelModule<infer TState, any> ? TState extends {
|
|
714
|
+
local: infer TLocal;
|
|
715
|
+
} ? TLocal : never : never;
|
|
716
|
+
/** @experimental The document type of a materialized module. */
|
|
717
|
+
type DocumentOf<T> = T extends CodeFirstDocumentModelModule<infer TState, any> ? PHDocument<TState> : never;
|
|
718
|
+
/** @experimental Any action a materialized module's creators return. */
|
|
719
|
+
type ActionOf<T> = T extends CodeFirstDocumentModelModule<any, infer TActions> ? ReturnType<TActions[keyof TActions]> : never;
|
|
720
|
+
//#endregion
|
|
721
|
+
//#region src/definition/runtime/materialize.d.ts
|
|
722
|
+
/**
|
|
723
|
+
* @experimental Builds the `DocumentModelModule` a host serves from a
|
|
724
|
+
* compiled version, or one module per version from a family. A single
|
|
725
|
+
* version is materialized as a one-version family.
|
|
726
|
+
*/
|
|
727
|
+
export declare function materialize<TState extends PHBaseState, TActions extends Actions>(definition: DocumentModelVersionDefinition<number, TState, TActions>): CodeFirstDocumentModelModule<TState, TActions>;
|
|
728
|
+
export declare function materialize<const TVersions extends readonly DocumentModelVersionDefinition[]>(definition: DocumentModelFamilyDefinition<TVersions>): DocumentModelFamily<TVersions>;
|
|
729
|
+
//#endregion
|
|
730
|
+
//#region src/definition/subgraph/types.d.ts
|
|
731
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
732
|
+
type NoArgs = Readonly<Record<never, AnyFieldDescriptor>>;
|
|
733
|
+
/**
|
|
734
|
+
* @experimental What a resolver receives. `subgraph` is the instance the
|
|
735
|
+
* host serves, so a resolver reaches its services and helpers through it.
|
|
736
|
+
*/
|
|
737
|
+
type SubgraphResolverCall<TParent, TArgs, TSubgraph, TRequest, TInfo> = {
|
|
738
|
+
readonly parent: TParent;
|
|
739
|
+
readonly args: TArgs;
|
|
740
|
+
readonly request: TRequest;
|
|
741
|
+
readonly info: TInfo;
|
|
742
|
+
readonly subgraph: TSubgraph;
|
|
743
|
+
};
|
|
744
|
+
/** @experimental What a `resolveType` function receives. */
|
|
745
|
+
type SubgraphResolveTypeCall<TValue, TSubgraph, TRequest, TInfo> = {
|
|
746
|
+
readonly value: TValue;
|
|
747
|
+
readonly request: TRequest;
|
|
748
|
+
readonly info: TInfo;
|
|
749
|
+
readonly subgraph: TSubgraph;
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* @experimental The arguments a resolver receives: the resolved input form,
|
|
753
|
+
* with defaults applied, as a reducer receives an operation input.
|
|
754
|
+
*/
|
|
755
|
+
type SubgraphArgsOf<TArgs extends ObjectFields> = SourceOf<InputDescriptor<TArgs>>;
|
|
756
|
+
type FieldSpec<TArgs extends ObjectFields, TType extends AnyFieldDescriptor> = {
|
|
757
|
+
readonly args?: TArgs;
|
|
758
|
+
readonly type: TType;
|
|
759
|
+
readonly description?: string;
|
|
760
|
+
readonly deprecated?: string;
|
|
761
|
+
};
|
|
762
|
+
type Resolver<TParent, TArgs extends ObjectFields, TResult, TSubgraph, TRequest, TInfo> = (call: SubgraphResolverCall<TParent, SubgraphArgsOf<TArgs>, TSubgraph, TRequest, TInfo>) => MaybePromise<TResult>;
|
|
763
|
+
/**
|
|
764
|
+
* @experimental An entry of a code-first subgraph: a root field, a computed
|
|
765
|
+
* field, an abstract type's `resolveType`, or a type no field reaches. Only
|
|
766
|
+
* the entry builders create one, and it is frozen.
|
|
767
|
+
*/
|
|
768
|
+
type SubgraphEntry<TSubgraph = unknown, TRequest = unknown, TInfo = unknown> = {
|
|
769
|
+
readonly kind: "query" | "mutation" | "subscription" | "computed-field" | "resolve-type" | "type";
|
|
770
|
+
/** Type-only; it makes an entry accept a narrower subgraph, request and info. */
|
|
771
|
+
readonly __types?: (subgraph: TSubgraph, request: TRequest, info: TInfo) => void;
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* @experimental The entry builders, bound to a subgraph, request and info
|
|
775
|
+
* type. A missing `resolve`, `subscribe` or `resolveType` is reported by
|
|
776
|
+
* `compileSubgraph`, not thrown here.
|
|
777
|
+
*/
|
|
778
|
+
type SubgraphEntryBuilders<TSubgraph, TRequest, TInfo> = {
|
|
779
|
+
query<TType extends AnyFieldDescriptor, TArgs extends ObjectFields = NoArgs>(name: string, spec: FieldSpec<TArgs, TType> & {
|
|
780
|
+
readonly resolve: Resolver<undefined, TArgs, OutputOf<TType>, TSubgraph, TRequest, TInfo>;
|
|
781
|
+
}): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
782
|
+
mutation<TType extends AnyFieldDescriptor, TArgs extends ObjectFields = NoArgs>(name: string, spec: FieldSpec<TArgs, TType> & {
|
|
783
|
+
readonly resolve: Resolver<undefined, TArgs, OutputOf<TType>, TSubgraph, TRequest, TInfo>;
|
|
784
|
+
}): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
785
|
+
/** With `resolve`, each event is mapped to the field's value. */
|
|
786
|
+
subscription<TType extends AnyFieldDescriptor, TEvent, TArgs extends ObjectFields = NoArgs>(name: string, spec: FieldSpec<TArgs, TType> & {
|
|
787
|
+
readonly subscribe: Resolver<undefined, TArgs, AsyncIterable<TEvent>, TSubgraph, TRequest, TInfo>;
|
|
788
|
+
readonly resolve: Resolver<TEvent, TArgs, OutputOf<TType>, TSubgraph, TRequest, TInfo>;
|
|
789
|
+
}): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
790
|
+
/** Without `resolve`, each event carries the field's value under its name. */
|
|
791
|
+
subscription<TName extends string, TType extends AnyFieldDescriptor, TArgs extends ObjectFields = NoArgs>(name: TName, spec: FieldSpec<TArgs, TType> & {
|
|
792
|
+
readonly subscribe: Resolver<undefined, TArgs, AsyncIterable<{ readonly [K in TName]: OutputOf<TType>; }>, TSubgraph, TRequest, TInfo>;
|
|
793
|
+
}): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
794
|
+
/** A field that `resolve` computes, added to an object type. */
|
|
795
|
+
field<TParent extends ObjectDescriptor, TType extends AnyFieldDescriptor, TArgs extends ObjectFields = NoArgs>(parent: TParent, name: string, spec: FieldSpec<TArgs, TType> & {
|
|
796
|
+
readonly resolve: Resolver<OutputOf<TParent>, TArgs, OutputOf<TType>, TSubgraph, TRequest, TInfo>;
|
|
797
|
+
}): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
798
|
+
/** Names the object type of a value of an interface or union. */
|
|
799
|
+
resolveType<TAbstract extends InterfaceDescriptor | UnionDescriptor>(type: TAbstract, resolveType: (call: SubgraphResolveTypeCall<OutputOf<TAbstract>, TSubgraph, TRequest, TInfo>) => MaybePromise<string | undefined>): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
800
|
+
/**
|
|
801
|
+
* Serves a named type, and every type it reaches, that no field reaches:
|
|
802
|
+
* typically an object type that only an interface leads to. It binds no
|
|
803
|
+
* resolver.
|
|
804
|
+
*/
|
|
805
|
+
type(type: AnyTypeDescriptor): SubgraphEntry<TSubgraph, TRequest, TInfo>;
|
|
806
|
+
};
|
|
807
|
+
type BoundResolver<TSubgraph, TRequest, TInfo> = (call: SubgraphResolverCall<unknown, unknown, TSubgraph, TRequest, TInfo>) => unknown;
|
|
808
|
+
/**
|
|
809
|
+
* @experimental The functions bound to one schema coordinate. A host builds
|
|
810
|
+
* its resolver map from these without calling `getSchema` again.
|
|
811
|
+
*/
|
|
812
|
+
type SubgraphBinding<TSubgraph, TRequest, TInfo> = {
|
|
813
|
+
readonly kind: "query" | "mutation" | "computed-field";
|
|
814
|
+
readonly typeName: string;
|
|
815
|
+
readonly fieldName: string;
|
|
816
|
+
readonly resolve: BoundResolver<TSubgraph, TRequest, TInfo>;
|
|
817
|
+
} | {
|
|
818
|
+
readonly kind: "subscription";
|
|
819
|
+
readonly typeName: "Subscription";
|
|
820
|
+
readonly fieldName: string;
|
|
821
|
+
readonly subscribe: BoundResolver<TSubgraph, TRequest, TInfo>;
|
|
822
|
+
readonly resolve?: BoundResolver<TSubgraph, TRequest, TInfo>;
|
|
823
|
+
} | {
|
|
824
|
+
readonly kind: "resolve-type";
|
|
825
|
+
readonly typeName: string;
|
|
826
|
+
readonly fieldName: null;
|
|
827
|
+
readonly resolveType: (call: SubgraphResolveTypeCall<unknown, TSubgraph, TRequest, TInfo>) => unknown;
|
|
828
|
+
};
|
|
829
|
+
/**
|
|
830
|
+
* @experimental The result of `compileSubgraph`. `definition` is present
|
|
831
|
+
* exactly when `diagnostics` holds no error; `bindings` is then keyed by
|
|
832
|
+
* coordinate (`Type.field`, or the type name for `resolveType`) and is empty
|
|
833
|
+
* otherwise.
|
|
834
|
+
*/
|
|
835
|
+
type SubgraphCompilation<TSubgraph, TRequest, TInfo> = {
|
|
836
|
+
readonly definition?: SubgraphDefinition & {
|
|
837
|
+
readonly schemaKind: "typed";
|
|
838
|
+
};
|
|
839
|
+
readonly bindings: ReadonlyMap<string, SubgraphBinding<TSubgraph, TRequest, TInfo>>;
|
|
840
|
+
readonly diagnostics: readonly DefinitionDiagnostic[];
|
|
841
|
+
};
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region src/definition/subgraph/compile.d.ts
|
|
844
|
+
/**
|
|
845
|
+
* @experimental Compiles a code-first subgraph's entries into its stored
|
|
846
|
+
* definition, plus the functions a host binds to each schema coordinate.
|
|
847
|
+
* It never throws for an invalid declaration; it reports diagnostics.
|
|
848
|
+
*/
|
|
849
|
+
export declare function compileSubgraph<TSubgraph, TRequest, TInfo>(input: {
|
|
850
|
+
readonly name: string;
|
|
851
|
+
readonly entries: readonly SubgraphEntry<TSubgraph, TRequest, TInfo>[];
|
|
852
|
+
}): SubgraphCompilation<TSubgraph, TRequest, TInfo>;
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region src/definition/subgraph/entries.d.ts
|
|
855
|
+
/**
|
|
856
|
+
* @experimental The builders a code-first subgraph declares its entries
|
|
857
|
+
* with. Each call returns a frozen entry; `compileSubgraph` reports what is
|
|
858
|
+
* wrong with it instead of the builder throwing.
|
|
859
|
+
*/
|
|
860
|
+
export declare function createSubgraphEntryBuilders<TSubgraph, TRequest, TInfo>(): SubgraphEntryBuilders<TSubgraph, TRequest, TInfo>;
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/definition/subgraph/projection.d.ts
|
|
863
|
+
/**
|
|
864
|
+
* @experimental The GraphQL document a subgraph definition serves, without
|
|
865
|
+
* locations, in the definition's print order. A typed definition declares
|
|
866
|
+
* the catalog and project scalars it uses as `scalar` definitions.
|
|
867
|
+
*/
|
|
868
|
+
export declare function projectSubgraphGraphQL(definition: SubgraphDefinition): LocationFreeGraphQLDocumentNode;
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region src/definition/subgraph/protocol.d.ts
|
|
871
|
+
/**
|
|
872
|
+
* @experimental The static member that marks a code-first subgraph class.
|
|
873
|
+
* `Symbol.for` makes it the same key in every copy of the package; the
|
|
874
|
+
* protocol's `version` says which contract the class speaks.
|
|
875
|
+
*/
|
|
876
|
+
export declare const SUBGRAPH_PROTOCOL: unique symbol;
|
|
877
|
+
/**
|
|
878
|
+
* @experimental A code-first class's description. `name` is absent on a
|
|
879
|
+
* base class that declares no `subgraphName`.
|
|
880
|
+
*/
|
|
881
|
+
type SubgraphDescription = {
|
|
882
|
+
readonly name?: string;
|
|
883
|
+
readonly definition?: SubgraphDefinition;
|
|
884
|
+
readonly diagnostics: readonly DefinitionDiagnostic[];
|
|
885
|
+
};
|
|
886
|
+
/**
|
|
887
|
+
* @experimental The contract a code-first subgraph class exposes under
|
|
888
|
+
* `SUBGRAPH_PROTOCOL`. Both methods run in the copy that defined the class.
|
|
889
|
+
*/
|
|
890
|
+
type SubgraphProtocol = {
|
|
891
|
+
readonly version: 1;
|
|
892
|
+
describe(): SubgraphDescription;
|
|
893
|
+
validate(instance: unknown): {
|
|
894
|
+
readonly ok: true;
|
|
895
|
+
} | {
|
|
896
|
+
readonly ok: false;
|
|
897
|
+
readonly message: string;
|
|
898
|
+
};
|
|
899
|
+
};
|
|
900
|
+
/**
|
|
901
|
+
* @experimental How a host treats a subgraph export. `unsupported` covers a
|
|
902
|
+
* protocol of another version and a malformed one, and carries the version
|
|
903
|
+
* it read.
|
|
904
|
+
*/
|
|
905
|
+
type SubgraphProtocolRead = {
|
|
906
|
+
readonly kind: "schema-first";
|
|
907
|
+
} | {
|
|
908
|
+
readonly kind: "code-first";
|
|
909
|
+
readonly protocol: SubgraphProtocol;
|
|
910
|
+
} | {
|
|
911
|
+
readonly kind: "unsupported";
|
|
912
|
+
readonly version: unknown;
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* @experimental Reads the protocol of a subgraph export. It reads only the
|
|
916
|
+
* static `SUBGRAPH_PROTOCOL` member of a function: it never constructs the
|
|
917
|
+
* class or calls the protocol.
|
|
918
|
+
*/
|
|
919
|
+
export declare function readSubgraphProtocol(value: unknown): SubgraphProtocolRead;
|
|
920
|
+
//#endregion
|
|
921
|
+
export type { ActionOf, ActionsForOperationTokens, CodeFirstDocumentModelModule, DispatchOutcome, DocumentDispatch, DocumentModelConfig, DocumentModelContext, DocumentModelDefinitionInspection, DocumentModelFamily, DocumentModelFamilyDefinition, DocumentModelGraphQLProjection, DocumentModelVersionDefinition, DocumentOf, EnumDescriptor, GlobalStateOf, InputDescriptor, InputObjectOf, InspectableDocumentModelModule, InterfaceDescriptor, ListDescriptor, LocalStateOf, ModelModuleToken, ModelOperationToken, ModelState, ObjectDescriptor, OutputObjectOf, Ph, ReferenceDescriptor, RejectedAction, ScalarDescriptor, StructuredOperation, SubgraphArgsOf, SubgraphBinding, SubgraphCompilation, SubgraphDescription, SubgraphEntry, SubgraphEntryBuilders, SubgraphProtocol, SubgraphProtocolRead, SubgraphResolveTypeCall, SubgraphResolverCall, UnionDescriptor };
|
|
79
922
|
export {};
|
|
80
923
|
//# sourceMappingURL=index.d.ts.map
|