@dosgato/templating 0.0.52 → 0.0.55

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.
@@ -57,7 +57,7 @@ export interface DataExtras {
57
57
  /**
58
58
  * This interface lays out the structure the API needs for each template in the system.
59
59
  */
60
- export interface APITemplate {
60
+ export interface APITemplate<DataType> {
61
61
  type: APITemplateType;
62
62
  /**
63
63
  * A unique string to globally identify this template across installations. Namespacing like
@@ -73,15 +73,15 @@ export interface APITemplate {
73
73
  * can be indexed. Only fields that are links need to be returned. Links inside rich editor
74
74
  * text will be extracted automatically from any text returned by getFulltext (see below)
75
75
  */
76
- getLinks?: LinkGatheringFn;
76
+ getLinks?: LinkGatheringFn<DataType>;
77
77
  /**
78
78
  * Each template must provide the text from any text or rich editor data it possesses, so that
79
79
  * the text can be decomposed into words and indexed for fulltext searches. Any text returned
80
80
  * by this function will also be scanned for links.
81
81
  */
82
- getFulltext?: FulltextGatheringFn;
82
+ getFulltext?: FulltextGatheringFn<DataType>;
83
83
  }
84
- export interface APIComponentTemplate extends APITemplate {
84
+ export interface APIComponentTemplate<DataType extends ComponentData = any> extends APITemplate<DataType> {
85
85
  type: 'component';
86
86
  /**
87
87
  * Each template must declare its areas and the template keys of components that will be
@@ -107,15 +107,15 @@ export interface APIComponentTemplate extends APITemplate {
107
107
  *
108
108
  * See the ComponentExtras type to see all the contextual information you'll have available.
109
109
  */
110
- validate?: <T extends ComponentData>(data: T, extras: ComponentExtras) => Promise<ValidationFeedback[]>;
110
+ validate?: (data: DataType, extras: ComponentExtras) => Promise<ValidationFeedback[]>;
111
111
  /**
112
112
  * Each template must provide a list of migrations for upgrading the data schema over time.
113
113
  * Typically this will start as an empty array and migrations will be added as the template
114
114
  * gets refactored.
115
115
  */
116
- migrations?: ComponentMigration[];
116
+ migrations?: ComponentMigration<DataType>[];
117
117
  }
118
- export interface APIPageTemplate extends APITemplate {
118
+ export interface APIPageTemplate<DataType extends PageData = any> extends APITemplate<DataType> {
119
119
  type: 'page';
120
120
  /**
121
121
  * Page areas are the same as components but are required.
@@ -124,8 +124,8 @@ export interface APIPageTemplate extends APITemplate {
124
124
  /**
125
125
  * Page template implementations do not receive a path like component templates do.
126
126
  */
127
- validate?: <T extends PageData>(data: T, extras: PageExtras) => Promise<ValidationFeedback[]>;
128
- migrations?: PageMigration[];
127
+ validate?: (data: DataType, extras: PageExtras) => Promise<ValidationFeedback[]>;
128
+ migrations?: PageMigration<DataType>[];
129
129
  /**
130
130
  * Hard-coded properties that may be set on page templates to influence the rendering of
131
131
  * components on the page. For instance, a set of color choices that are customized for
@@ -137,15 +137,15 @@ export interface APIPageTemplate extends APITemplate {
137
137
  */
138
138
  templateProperties?: any;
139
139
  }
140
- export interface APIDataTemplate extends APITemplate {
140
+ export interface APIDataTemplate<DataType extends DataData = any> extends APITemplate<DataType> {
141
141
  type: 'data';
142
142
  /**
143
143
  * Data template implementations receive the id of the dataroot the data is/will be inside,
144
144
  * as well as the folder id (if applicable) and their own id. Keep in mind dataId will be
145
145
  * null when it is a creation operation.
146
146
  */
147
- validate?: <T extends DataData>(data: T, extras: DataExtras) => Promise<ValidationFeedback[]>;
148
- migrations?: DataMigration[];
147
+ validate?: (data: DataType, extras: DataExtras) => Promise<ValidationFeedback[]>;
148
+ migrations?: DataMigration<DataType>[];
149
149
  }
150
150
  export declare type APIAnyTemplate = APIComponentTemplate | APIPageTemplate | APIDataTemplate;
151
151
  /**
@@ -181,12 +181,12 @@ export interface Migration<DataType, ExtraType> {
181
181
  up: (data: DataType, extras: ExtraType) => DataType | Promise<DataType>;
182
182
  down: (data: DataType, extras: ExtraType) => DataType | Promise<DataType>;
183
183
  }
184
- export declare type ComponentMigration = Migration<ComponentData, ComponentExtras>;
185
- export declare type PageMigration = Migration<PageData, PageExtras>;
186
- export declare type DataMigration = Migration<DataData, DataExtras>;
184
+ export declare type ComponentMigration<DataType extends ComponentData = ComponentData> = Migration<DataType, ComponentExtras>;
185
+ export declare type PageMigration<DataType extends PageData = PageData> = Migration<DataType, PageExtras>;
186
+ export declare type DataMigration<DataType extends DataData = DataData> = Migration<DataType, DataExtras>;
187
187
  export declare type AnyMigration = ComponentMigration | PageMigration | DataMigration;
188
- export declare type LinkGatheringFn = (data: any) => LinkDefinition[];
189
- export declare type FulltextGatheringFn = (data: any) => string[];
188
+ export declare type LinkGatheringFn<DataType> = (data: DataType) => LinkDefinition[];
189
+ export declare type FulltextGatheringFn<DataType> = (data: DataType) => string[];
190
190
  export declare type GraphQLQueryFn = <T>(query: string, variables?: any) => Promise<T>;
191
191
  /**
192
192
  * This function is used by API template definitions to help them identify all the searchable
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingHttpHeaders } from 'http';
1
3
  import { ResourceProvider } from './provider.js';
2
4
  import { APIClient } from './render.js';
3
5
  /**
@@ -179,6 +181,8 @@ export declare abstract class Component<DataType extends ComponentData = any, Fe
179
181
  renderedAreas: Map<string, RenderedComponent[]>;
180
182
  hadError: boolean;
181
183
  autoLabel: string;
184
+ reqHeaders: IncomingHttpHeaders;
185
+ reqUrl: URL;
182
186
  /**
183
187
  * For logging errors during rendering without crashing the render. If your fetch, setContext,
184
188
  * render, or renderVariation functions throw, the error will be logged but the page render will
@@ -243,6 +247,11 @@ export declare abstract class Page<DataType extends PageData = any, FetchedType
243
247
  * should place include it in the <head> element
244
248
  */
245
249
  headContent: string;
250
+ /**
251
+ * This method will be provided to page templates by the render server. You may call it
252
+ * at any time during fetch, context, or render, to set an HTTP header on the response
253
+ */
254
+ addHeader: (key: string, value: string | undefined) => void;
246
255
  protected passError(e: Error, path: string): void;
247
256
  constructor(page: PageRecord<DataType>, editMode: boolean);
248
257
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dosgato/templating",
3
- "version": "0.0.52",
3
+ "version": "0.0.55",
4
4
  "description": "A library to support building templates for dosgato CMS.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,6 +18,7 @@
18
18
  "txstate-utils": "^1.7.4"
19
19
  },
20
20
  "devDependencies": {
21
+ "@types/node": "^18.7.11",
21
22
  "eslint-config-standard-with-typescript": "^22.0.0",
22
23
  "typescript": "^4.4.2"
23
24
  },