@dosgato/templating 0.0.30 → 0.0.33
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 +50 -13
- package/package.json +1 -1
package/dist/apitemplate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageRecord, ComponentData } 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.
|
|
@@ -67,6 +64,24 @@ export interface APITemplate {
|
|
|
67
64
|
* have access to any data you attempt to query in GraphQL.
|
|
68
65
|
*/
|
|
69
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,17 @@ 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 id of the dataroot the data is/will be inside,
|
|
100
|
+
* as well as the folder id (if applicable) and their own id. Keep in mind dataId will be
|
|
101
|
+
* null when it is a creation operation.
|
|
102
|
+
*/
|
|
103
|
+
validate?: (data: ComponentData, query: GraphQLQueryFn, dataRootId: string, dataFolderId?: string, dataId?: string) => Promise<ValidationFeedback[]>;
|
|
104
|
+
migrations: DataMigration[];
|
|
105
|
+
}
|
|
106
|
+
export declare type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
|
|
81
107
|
/**
|
|
82
108
|
* In dosgato CMS, the data in the database is not altered except during user activity. This
|
|
83
109
|
* means that older records could have been saved when the schema expected by component
|
|
@@ -108,9 +134,20 @@ export interface APITemplate {
|
|
|
108
134
|
*/
|
|
109
135
|
export interface Migration {
|
|
110
136
|
createdAt: Date;
|
|
137
|
+
}
|
|
138
|
+
export interface ComponentMigration extends Migration {
|
|
111
139
|
up: (data: ComponentData, query: GraphQLQueryFn, page: PageRecord, path: string) => ComponentData | Promise<ComponentData>;
|
|
112
140
|
down: (data: ComponentData, query: GraphQLQueryFn, page: PageRecord, path: string) => ComponentData | Promise<ComponentData>;
|
|
113
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
|
+
}
|
|
150
|
+
export declare type AnyMigration = ComponentMigration | PageMigration | DataMigration;
|
|
114
151
|
export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
|
|
115
152
|
export declare type FulltextGatheringFn = (data: any) => string[];
|
|
116
153
|
export declare type GraphQLQueryFn = <T>(query: string, variables?: any) => Promise<T>;
|