@dosgato/templating 0.0.33 → 0.0.36
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/apitemplate.d.ts +57 -20
- package/dist/component.d.ts +2 -2
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentData, DataData, PageData } from './component.js';
|
|
2
2
|
import { LinkDefinition } from './links.js';
|
|
3
3
|
export declare type APITemplateType = 'page' | 'component' | 'data';
|
|
4
4
|
export declare enum ValidationMessageType {
|
|
@@ -11,6 +11,49 @@ export interface ValidationFeedback {
|
|
|
11
11
|
path?: string;
|
|
12
12
|
message: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* This is information that the API will pass to the validation and migration
|
|
16
|
+
* functions provided by template implementations. It will help template developers
|
|
17
|
+
* do advanced logic when validating or migrating data, e.g. looking up a name in the
|
|
18
|
+
* API to make sure it hasn't been used already.
|
|
19
|
+
*/
|
|
20
|
+
export interface PageExtras {
|
|
21
|
+
/** A function for executing a graphql query to acquire more information than is already at hand. */
|
|
22
|
+
query: GraphQLQueryFn;
|
|
23
|
+
/** The site id in which the page lives or is being created. */
|
|
24
|
+
siteId: string;
|
|
25
|
+
/** The pagetree id in which the page lives or is being created. */
|
|
26
|
+
pagetreeId: string;
|
|
27
|
+
/** The page id of the page's parent or parent-to-be. Null if it is the root page of a pagetree. */
|
|
28
|
+
parentId?: string;
|
|
29
|
+
/** The page's id, presumably to be used in graphql queries. NOTE: will be null during page creation. */
|
|
30
|
+
pageId?: string;
|
|
31
|
+
/** The path in the pagetree to the page, or what the path will be. NOTE: looking the page up by path will not work during page creation. */
|
|
32
|
+
pagePath?: string;
|
|
33
|
+
/** The linkId the page has or will have. NOTE: looking the page up by linkId will not work during page creation. */
|
|
34
|
+
linkId: string;
|
|
35
|
+
/** The name the page has or will have. NOTE: looking the page up by name will not work during page creation. */
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ComponentExtras extends PageExtras {
|
|
39
|
+
/**
|
|
40
|
+
* The full page data in case validating or migrating a component depends on state
|
|
41
|
+
* elsewhere in the page.
|
|
42
|
+
*/
|
|
43
|
+
page: PageData;
|
|
44
|
+
/** The path within the page data to the component currently being evaluated. */
|
|
45
|
+
path: string;
|
|
46
|
+
}
|
|
47
|
+
export interface DataExtras {
|
|
48
|
+
/** A function for executing a graphql query to acquire more information than is already at hand. */
|
|
49
|
+
query: GraphQLQueryFn;
|
|
50
|
+
/** The id of the dataroot the entry lives in or will be placed in. */
|
|
51
|
+
dataRootId: string;
|
|
52
|
+
/** The id of the data folder the entry lives in or will be placed in. Null if directly in the dataroot. */
|
|
53
|
+
dataFolderId?: string;
|
|
54
|
+
/** The id of the data entry itself. NOTE: will be null during page creation. */
|
|
55
|
+
dataId?: string;
|
|
56
|
+
}
|
|
14
57
|
/**
|
|
15
58
|
* This interface lays out the structure the API needs for each template in the system.
|
|
16
59
|
*/
|
|
@@ -59,11 +102,12 @@ export interface APIComponentTemplate extends APITemplate {
|
|
|
59
102
|
* [{ type: 'error', path: 'name', message: 'A name is required.' }]
|
|
60
103
|
*
|
|
61
104
|
* This method is async so that you can do things like look in the database for conflicting
|
|
62
|
-
* names.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
105
|
+
* names. Keep in mind that the current editor MUST have access to any data you attempt to
|
|
106
|
+
* query in GraphQL.
|
|
107
|
+
*
|
|
108
|
+
* See the ComponentExtras type to see all the contextual information you'll have available.
|
|
65
109
|
*/
|
|
66
|
-
validate?: (data: ComponentData,
|
|
110
|
+
validate?: (data: ComponentData, extras: ComponentExtras) => Promise<ValidationFeedback[]>;
|
|
67
111
|
/**
|
|
68
112
|
* Each template must provide a list of migrations for upgrading the data schema over time.
|
|
69
113
|
* Typically this will start as an empty array and migrations will be added as the template
|
|
@@ -80,7 +124,7 @@ export interface APIPageTemplate extends APITemplate {
|
|
|
80
124
|
/**
|
|
81
125
|
* Page template implementations do not receive a path like component templates do.
|
|
82
126
|
*/
|
|
83
|
-
validate?: (data:
|
|
127
|
+
validate?: (data: PageData, extras: PageExtras) => Promise<ValidationFeedback[]>;
|
|
84
128
|
migrations: PageMigration[];
|
|
85
129
|
/**
|
|
86
130
|
* Hard-coded properties that may be set on page templates to influence the rendering of
|
|
@@ -100,7 +144,7 @@ export interface APIDataTemplate extends APITemplate {
|
|
|
100
144
|
* as well as the folder id (if applicable) and their own id. Keep in mind dataId will be
|
|
101
145
|
* null when it is a creation operation.
|
|
102
146
|
*/
|
|
103
|
-
validate?: (data: ComponentData,
|
|
147
|
+
validate?: (data: ComponentData, extras: DataExtras) => Promise<ValidationFeedback[]>;
|
|
104
148
|
migrations: DataMigration[];
|
|
105
149
|
}
|
|
106
150
|
export declare type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
|
|
@@ -132,21 +176,14 @@ export declare type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | AP
|
|
|
132
176
|
* If you're migrating a component template, you'll also get the page record and the
|
|
133
177
|
* path inside that page's data to the component being migrated.
|
|
134
178
|
*/
|
|
135
|
-
export interface Migration {
|
|
179
|
+
export interface Migration<DataType, ExtraType> {
|
|
136
180
|
createdAt: Date;
|
|
181
|
+
up: (data: DataType, extras: ExtraType) => DataType | Promise<DataType>;
|
|
182
|
+
down: (data: DataType, extras: ExtraType) => DataType | Promise<DataType>;
|
|
137
183
|
}
|
|
138
|
-
export
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
export interface PageMigration extends Migration {
|
|
143
|
-
up: (data: PageData, query: GraphQLQueryFn, page: PageRecord) => PageData | Promise<PageData>;
|
|
144
|
-
down: (data: PageData, query: GraphQLQueryFn, page: PageRecord) => PageData | Promise<PageData>;
|
|
145
|
-
}
|
|
146
|
-
export interface DataMigration extends Migration {
|
|
147
|
-
up: (data: DataData, query: GraphQLQueryFn, dataRootId: string, dataFolderId?: string, dataId?: string) => DataData | Promise<DataData>;
|
|
148
|
-
down: (data: DataData, query: GraphQLQueryFn, dataRootId: string, dataFolderId?: string, dataId?: string) => DataData | Promise<DataData>;
|
|
149
|
-
}
|
|
184
|
+
export declare type ComponentMigration = Migration<ComponentData, ComponentExtras>;
|
|
185
|
+
export declare type PageMigration = Migration<PageData, PageExtras>;
|
|
186
|
+
export declare type DataMigration = Migration<DataData, DataExtras>;
|
|
150
187
|
export declare type AnyMigration = ComponentMigration | PageMigration | DataMigration;
|
|
151
188
|
export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
|
|
152
189
|
export declare type FulltextGatheringFn = (data: any) => string[];
|
package/dist/component.d.ts
CHANGED
|
@@ -171,11 +171,11 @@ export interface ComponentData {
|
|
|
171
171
|
areas?: Record<string, ComponentData[]>;
|
|
172
172
|
}
|
|
173
173
|
export interface PageData extends ComponentData {
|
|
174
|
-
savedAtVersion:
|
|
174
|
+
savedAtVersion: string;
|
|
175
175
|
}
|
|
176
176
|
export interface DataData {
|
|
177
177
|
templateKey: string;
|
|
178
|
-
savedAtVersion:
|
|
178
|
+
savedAtVersion: string;
|
|
179
179
|
}
|
|
180
180
|
export interface ContextBase {
|
|
181
181
|
/**
|