@dosgato/templating 0.0.28 → 0.0.31
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 +60 -16
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageRecord, ComponentData, PageData } from './component.js';
|
|
1
|
+
import { PageRecord, 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 {
|
|
@@ -25,18 +25,6 @@ export interface APITemplate {
|
|
|
25
25
|
* A uniquey human-readable name describing this template
|
|
26
26
|
*/
|
|
27
27
|
name: string;
|
|
28
|
-
/**
|
|
29
|
-
* Each template must declare its areas and the template keys of components that will be
|
|
30
|
-
* permitted inside each area. The list of allowed component templates can be updated beyond
|
|
31
|
-
* the list provided here. See templateRegistry.addAvailableComponent's comment for info on why.
|
|
32
|
-
*/
|
|
33
|
-
areas: Record<string, string[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Each template must provide a list of migrations for upgrading the data schema over time.
|
|
36
|
-
* Typically this will start as an empty array and migrations will be added as the template
|
|
37
|
-
* gets refactored.
|
|
38
|
-
*/
|
|
39
|
-
migrations: Migration[];
|
|
40
28
|
/**
|
|
41
29
|
* Each template must provide a function that returns links from its data so that they
|
|
42
30
|
* can be indexed. Only fields that are links need to be returned. Links inside rich editor
|
|
@@ -49,6 +37,15 @@ export interface APITemplate {
|
|
|
49
37
|
* by this function will also be scanned for links.
|
|
50
38
|
*/
|
|
51
39
|
getFulltext: FulltextGatheringFn;
|
|
40
|
+
}
|
|
41
|
+
export interface APIComponentTemplate extends APITemplate {
|
|
42
|
+
type: 'component';
|
|
43
|
+
/**
|
|
44
|
+
* Each template must declare its areas and the template keys of components that will be
|
|
45
|
+
* permitted inside each area. The list of allowed component templates can be updated beyond
|
|
46
|
+
* the list provided here. See templateRegistry.addAvailableComponent's comment for info on why.
|
|
47
|
+
*/
|
|
48
|
+
areas?: Record<string, string[]>;
|
|
52
49
|
/**
|
|
53
50
|
* Each template must provide a validation function so that the API can enforce its data is
|
|
54
51
|
* shaped properly.
|
|
@@ -66,7 +63,25 @@ export interface APITemplate {
|
|
|
66
63
|
* available as parameters in case you need them. Keep in mind that the current editor MUST
|
|
67
64
|
* have access to any data you attempt to query in GraphQL.
|
|
68
65
|
*/
|
|
69
|
-
validate?: (data: ComponentData, query:
|
|
66
|
+
validate?: (data: ComponentData, query: GraphQLQueryFn, page: PageRecord, path: string) => Promise<ValidationFeedback[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Each template must provide a list of migrations for upgrading the data schema over time.
|
|
69
|
+
* Typically this will start as an empty array and migrations will be added as the template
|
|
70
|
+
* gets refactored.
|
|
71
|
+
*/
|
|
72
|
+
migrations: ComponentMigration[];
|
|
73
|
+
}
|
|
74
|
+
export interface APIPageTemplate extends APITemplate {
|
|
75
|
+
type: 'page';
|
|
76
|
+
/**
|
|
77
|
+
* Page areas are the same as components but are required.
|
|
78
|
+
*/
|
|
79
|
+
areas: Record<string, string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Page template implementations do not receive a path like component templates do.
|
|
82
|
+
*/
|
|
83
|
+
validate?: (data: ComponentData, query: GraphQLQueryFn, page: PageRecord) => Promise<ValidationFeedback[]>;
|
|
84
|
+
migrations: PageMigration[];
|
|
70
85
|
/**
|
|
71
86
|
* Hard-coded properties that may be set on page templates to influence the rendering of
|
|
72
87
|
* components on the page. For instance, a set of color choices that are customized for
|
|
@@ -78,6 +93,15 @@ export interface APITemplate {
|
|
|
78
93
|
*/
|
|
79
94
|
templateProperties?: any;
|
|
80
95
|
}
|
|
96
|
+
export interface APIDataTemplate extends APITemplate {
|
|
97
|
+
type: 'data';
|
|
98
|
+
/**
|
|
99
|
+
* Data template implementations receive the dataId so they can self-reference in queries.
|
|
100
|
+
*/
|
|
101
|
+
validate?: (data: ComponentData, query: GraphQLQueryFn, dataId: string) => Promise<ValidationFeedback[]>;
|
|
102
|
+
migrations: DataMigration[];
|
|
103
|
+
}
|
|
104
|
+
export declare type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
|
|
81
105
|
/**
|
|
82
106
|
* In dosgato CMS, the data in the database is not altered except during user activity. This
|
|
83
107
|
* means that older records could have been saved when the schema expected by component
|
|
@@ -97,14 +121,34 @@ export interface APITemplate {
|
|
|
97
121
|
*
|
|
98
122
|
* Your `up` and `down` methods will be applied to components in bottom-up fashion, so you
|
|
99
123
|
* can assume that any components inside one of your areas has already been processed.
|
|
124
|
+
*
|
|
125
|
+
* All migration functions receive a `query` function for making a graphql query, in case the
|
|
126
|
+
* migration depends on the state of a parent page or something. Be careful not
|
|
127
|
+
* to create an infinite loop - querying a page will trigger that page to be migrated, which
|
|
128
|
+
* could end up calling your code again on that page.
|
|
129
|
+
*
|
|
130
|
+
* If you're migrating a component template, you'll also get the page record and the
|
|
131
|
+
* path inside that page's data to the component being migrated.
|
|
100
132
|
*/
|
|
101
133
|
export interface Migration {
|
|
102
134
|
createdAt: Date;
|
|
103
|
-
up: (data: ComponentData, page: PageRecord) => ComponentData | Promise<ComponentData>;
|
|
104
|
-
down: (data: ComponentData, page: PageRecord) => ComponentData | Promise<ComponentData>;
|
|
105
135
|
}
|
|
136
|
+
export interface ComponentMigration extends Migration {
|
|
137
|
+
up: (data: ComponentData, query: GraphQLQueryFn, page: PageRecord, path: string) => ComponentData | Promise<ComponentData>;
|
|
138
|
+
down: (data: ComponentData, query: GraphQLQueryFn, page: PageRecord, path: string) => ComponentData | Promise<ComponentData>;
|
|
139
|
+
}
|
|
140
|
+
export interface PageMigration extends Migration {
|
|
141
|
+
up: (data: PageData, query: GraphQLQueryFn, page: PageRecord) => PageData | Promise<PageData>;
|
|
142
|
+
down: (data: PageData, query: GraphQLQueryFn, page: PageRecord) => PageData | Promise<PageData>;
|
|
143
|
+
}
|
|
144
|
+
export interface DataMigration extends Migration {
|
|
145
|
+
up: (data: DataData, query: GraphQLQueryFn, dataId: string) => DataData | Promise<DataData>;
|
|
146
|
+
down: (data: DataData, query: GraphQLQueryFn, dataId: string) => DataData | Promise<DataData>;
|
|
147
|
+
}
|
|
148
|
+
export declare type AnyMigration = ComponentMigration | PageMigration | DataMigration;
|
|
106
149
|
export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
|
|
107
150
|
export declare type FulltextGatheringFn = (data: any) => string[];
|
|
151
|
+
export declare type GraphQLQueryFn = <T>(query: string, variables?: any) => Promise<T>;
|
|
108
152
|
/**
|
|
109
153
|
* This function is used by API template definitions to help them identify links inside large blocks
|
|
110
154
|
* of text and return them for indexing.
|