@dosgato/templating 0.0.24 → 0.0.27

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 { PageRecord, 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
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.24",
3
+ "version": "0.0.27",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {