@dosgato/templating 0.0.23 → 0.0.26

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.
@@ -1,6 +1,16 @@
1
- import { PageWithAncestors, ComponentData } from './component.js';
1
+ import { PageRecord, ComponentData, PageData } from './component.js';
2
2
  import { LinkDefinition } from './links.js';
3
3
  export declare type APITemplateType = 'page' | 'component' | 'data';
4
+ export declare enum ValidationMessageType {
5
+ ERROR = "error",
6
+ WARNING = "warning",
7
+ SUCCESS = "success"
8
+ }
9
+ export interface ValidationFeedback {
10
+ type: `${ValidationMessageType}`;
11
+ path?: string;
12
+ message: string;
13
+ }
4
14
  /**
5
15
  * This interface lays out the structure the API needs for each template in the system.
6
16
  */
@@ -41,17 +51,22 @@ export interface APITemplate {
41
51
  getFulltext: FulltextGatheringFn;
42
52
  /**
43
53
  * Each template must provide a validation function so that the API can enforce its data is
44
- * shaped properly. If there are no issues, it should return an empty object {}, otherwise it
45
- * should return an object with keys that reference the path to the error and values that
46
- * are an array of error messages pertaining to that path.
54
+ * shaped properly.
55
+ *
56
+ * Each entry in the return array can have a type of error, warning, or success. Errors
57
+ * represent a validation failure and mean that saving will not succeed. Warnings are shown
58
+ * to the editor but do not prevent saving. Success messages postively affirm valid input - for
59
+ * instance, a name they chose is available.
47
60
  *
48
- * For instance, if name is required and the user didn't provide one, you would return:
49
- * { name: ['A name is required.'] }
61
+ * As an example, if name is required and the user didn't provide one, you would return:
62
+ * [{ type: 'error', path: 'name', message: 'A name is required.' }]
50
63
  *
51
64
  * This method is async so that you can do things like look in the database for conflicting
52
- * names.
65
+ * names. The full page data, the path to this component, and a GraphQL query executor are
66
+ * available as parameters in case you need them. Keep in mind that the current editor MUST
67
+ * have access to any data you attempt to query in GraphQL.
53
68
  */
54
- validate: (data: any) => Promise<Record<string, string[]>>;
69
+ validate: (data: ComponentData, query: <T>(query: string, variables?: any) => Promise<T>, page: PageData, path: string) => Promise<ValidationFeedback[]>;
55
70
  /**
56
71
  * Hard-coded properties that may be set on page templates to influence the rendering of
57
72
  * components on the page. For instance, a set of color choices that are customized for
@@ -85,8 +100,8 @@ export interface APITemplate {
85
100
  */
86
101
  export interface Migration {
87
102
  createdAt: Date;
88
- up: (data: ComponentData, page: PageWithAncestors) => ComponentData | Promise<ComponentData>;
89
- down: (data: ComponentData, page: PageWithAncestors) => ComponentData | Promise<ComponentData>;
103
+ up: (data: ComponentData, page: PageRecord) => ComponentData | Promise<ComponentData>;
104
+ down: (data: ComponentData, page: PageRecord) => ComponentData | Promise<ComponentData>;
90
105
  }
91
106
  export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
92
107
  export declare type FulltextGatheringFn = (data: any) => string[];
@@ -1,4 +1,10 @@
1
1
  import { stopwords } from './stopwords.js';
2
+ export var ValidationMessageType;
3
+ (function (ValidationMessageType) {
4
+ ValidationMessageType["ERROR"] = "error";
5
+ ValidationMessageType["WARNING"] = "warning";
6
+ ValidationMessageType["SUCCESS"] = "success";
7
+ })(ValidationMessageType || (ValidationMessageType = {}));
2
8
  /**
3
9
  * This function is used by API template definitions to help them identify links inside large blocks
4
10
  * of text and return them for indexing.
@@ -166,9 +166,6 @@ export interface PageRecord<DataType extends PageData = PageData> {
166
166
  path: string;
167
167
  data: DataType;
168
168
  }
169
- export interface PageWithAncestors<DataType extends PageData = PageData> extends PageRecord<DataType> {
170
- ancestors: PageRecord<PageData>[];
171
- }
172
169
  export interface ComponentData {
173
170
  templateKey: string;
174
171
  areas?: Record<string, ComponentData[]>;
@@ -194,7 +191,6 @@ export interface ContextBase {
194
191
  }
195
192
  export declare abstract class Page<DataType extends PageData = any, FetchedType = any, RenderContextType extends ContextBase = any> extends Component<DataType, FetchedType, RenderContextType> {
196
193
  pagePath: string;
197
- ancestors: PageRecord[];
198
194
  /**
199
195
  * we will fill this before rendering, stuff that dosgato knows needs to be added to
200
196
  * the <head> element
@@ -202,5 +198,5 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
202
198
  */
203
199
  headContent: string;
204
200
  protected passError(e: Error, path: string): void;
205
- constructor(page: PageWithAncestors<DataType>);
201
+ constructor(page: PageRecord<DataType>);
206
202
  }
package/dist/component.js CHANGED
@@ -167,7 +167,6 @@ export class Page extends Component {
167
167
  constructor(page) {
168
168
  super(page.data, '/', undefined);
169
169
  this.pagePath = page.path;
170
- this.ancestors = page.ancestors;
171
170
  }
172
171
  passError(e, path) {
173
172
  console.warn(`Recoverable issue occured during render of ${this.pagePath}. Component at ${path} threw the following error:`, e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.23",
3
+ "version": "0.0.26",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {