@memberjunction/templates-base-types 6.2.0-edge.3 → 6.2.0-edge.5
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/TemplateEngineBase.d.ts +8 -0
- package/dist/TemplateEngineBase.d.ts.map +1 -1
- package/dist/TemplateEngineBase.js +72 -7
- package/dist/TemplateEngineBase.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
|
@@ -16,6 +16,14 @@ export declare class TemplateEngineBase extends BaseEngine<TemplateEngineBase> {
|
|
|
16
16
|
get TemplateCategories(): MJTemplateCategoryEntity[];
|
|
17
17
|
get TemplateContents(): MJTemplateContentEntity[];
|
|
18
18
|
get TemplateParams(): MJTemplateParamEntity[];
|
|
19
|
+
private _indexedTemplatesRef?;
|
|
20
|
+
private _templatesById;
|
|
21
|
+
private _templatesByName;
|
|
22
|
+
private ensureTemplateIndexes;
|
|
23
|
+
/**
|
|
24
|
+
* Convenience method to find a template by ID, case-insensitive.
|
|
25
|
+
*/
|
|
26
|
+
FindTemplateByID(templateId: string): MJTemplateEntityExtended | undefined;
|
|
19
27
|
/**
|
|
20
28
|
* Convenience method to find a template by name, case-insensitive
|
|
21
29
|
* @param templateName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngineBase.d.ts","sourceRoot":"","sources":["../src/TemplateEngineBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"TemplateEngineBase.d.ts","sourceRoot":"","sources":["../src/TemplateEngineBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzG,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAkBhL;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU,CAAC,kBAAkB,CAAC;IAClE;;OAEG;IACH,WAAkB,QAAQ,IAAI,kBAAkB,CAE/C;IAGD,OAAO,CAAC,SAAS,CAMf;IAEW,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,iBAAiB;cAYhF,iBAAiB,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAexE,IAAW,SAAS,IAAI,wBAAwB,EAAE,CAEjD;IAED,IAAW,oBAAoB,IAAI,2BAA2B,EAAE,CAE/D;IACD,IAAW,kBAAkB,IAAI,wBAAwB,EAAE,CAE1D;IACD,IAAW,gBAAgB,IAAI,uBAAuB,EAAE,CAEvD;IACD,IAAW,cAAc,IAAI,qBAAqB,EAAE,CAEnD;IAED,OAAO,CAAC,oBAAoB,CAAC,CAA6B;IAC1D,OAAO,CAAC,cAAc,CAA+C;IACrE,OAAO,CAAC,gBAAgB,CAA+C;IAEvE,OAAO,CAAC,qBAAqB;IAyB7B;;OAEG;IACI,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS;IAQjF;;;;OAIG;IACI,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,wBAAwB;CAOtE"}
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { BaseEngine } from "@memberjunction/core";
|
|
2
|
-
import {
|
|
2
|
+
import { NormalizeUUID } from "@memberjunction/global";
|
|
3
|
+
/** Rows grouped by their normalized TemplateID. */
|
|
4
|
+
function groupByTemplate(rows) {
|
|
5
|
+
const groups = new Map();
|
|
6
|
+
for (const row of rows) {
|
|
7
|
+
const key = NormalizeUUID(row.TemplateID);
|
|
8
|
+
const bucket = groups.get(key);
|
|
9
|
+
if (bucket) {
|
|
10
|
+
bucket.push(row);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
groups.set(key, [row]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return groups;
|
|
17
|
+
}
|
|
3
18
|
/**
|
|
4
19
|
* TemplateEngine is used for accessing template metadata/caching it, and rendering templates
|
|
5
20
|
*/
|
|
6
21
|
export class TemplateEngineBase extends BaseEngine {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this._templatesById = new Map();
|
|
25
|
+
this._templatesByName = new Map();
|
|
26
|
+
}
|
|
7
27
|
/**
|
|
8
28
|
* Returns the global instance of the class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of it, always use this method to get the instance.
|
|
9
29
|
*/
|
|
@@ -22,11 +42,18 @@ export class TemplateEngineBase extends BaseEngine {
|
|
|
22
42
|
await this.Load(c, provider, forceRefresh, contextUser);
|
|
23
43
|
}
|
|
24
44
|
async AdditionalLoading(contextUser) {
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
// Associate content and params with their templates. Each template gets a new array on
|
|
46
|
+
// every run, so repeated rebuilds converge. Grouping first keeps this linear; filtering
|
|
47
|
+
// both child arrays once per template was O(templates x children).
|
|
48
|
+
// (The templates load as a dataset, which a cache-sourced related-record collection cannot
|
|
49
|
+
// read from, so these stay hand-associated.)
|
|
50
|
+
const contentByTemplate = groupByTemplate(this.TemplateContents);
|
|
51
|
+
const paramsByTemplate = groupByTemplate(this.TemplateParams);
|
|
52
|
+
for (const template of this.Templates) {
|
|
53
|
+
const key = NormalizeUUID(template.ID);
|
|
54
|
+
template.Content = contentByTemplate.get(key) ?? [];
|
|
55
|
+
template.Params = paramsByTemplate.get(key) ?? [];
|
|
56
|
+
}
|
|
30
57
|
}
|
|
31
58
|
get Templates() {
|
|
32
59
|
return this._metadata.Templates;
|
|
@@ -43,13 +70,51 @@ export class TemplateEngineBase extends BaseEngine {
|
|
|
43
70
|
get TemplateParams() {
|
|
44
71
|
return this._metadata.TemplateParams;
|
|
45
72
|
}
|
|
73
|
+
ensureTemplateIndexes() {
|
|
74
|
+
const templates = this._metadata?.Templates;
|
|
75
|
+
if (!templates) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (this._indexedTemplatesRef === templates && this._templatesById.size === templates.length) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
this._templatesById.clear();
|
|
82
|
+
this._templatesByName.clear();
|
|
83
|
+
for (let i = 0; i < templates.length; i++) {
|
|
84
|
+
const t = templates[i];
|
|
85
|
+
if (t.ID) {
|
|
86
|
+
this._templatesById.set(NormalizeUUID(t.ID), t);
|
|
87
|
+
}
|
|
88
|
+
if (t.Name) {
|
|
89
|
+
const nameKey = t.Name.trim().toLowerCase();
|
|
90
|
+
if (!this._templatesByName.has(nameKey)) {
|
|
91
|
+
this._templatesByName.set(nameKey, t);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this._indexedTemplatesRef = templates;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Convenience method to find a template by ID, case-insensitive.
|
|
99
|
+
*/
|
|
100
|
+
FindTemplateByID(templateId) {
|
|
101
|
+
if (!templateId) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
this.ensureTemplateIndexes();
|
|
105
|
+
return this._templatesById.get(NormalizeUUID(templateId));
|
|
106
|
+
}
|
|
46
107
|
/**
|
|
47
108
|
* Convenience method to find a template by name, case-insensitive
|
|
48
109
|
* @param templateName
|
|
49
110
|
* @returns
|
|
50
111
|
*/
|
|
51
112
|
FindTemplate(templateName) {
|
|
52
|
-
|
|
113
|
+
if (!templateName) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
this.ensureTemplateIndexes();
|
|
117
|
+
return this._templatesByName.get(templateName.trim().toLowerCase());
|
|
53
118
|
}
|
|
54
119
|
}
|
|
55
120
|
//# sourceMappingURL=TemplateEngineBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngineBase.js","sourceRoot":"","sources":["../src/TemplateEngineBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyD,MAAM,sBAAsB,CAAC;AAEzG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"TemplateEngineBase.js","sourceRoot":"","sources":["../src/TemplateEngineBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyD,MAAM,sBAAsB,CAAC;AAEzG,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,mDAAmD;AACnD,SAAS,eAAe,CAAmC,IAAS;IAChE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAe,CAAC;IACtC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3B,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,UAA8B;IAAtE;;QA8DY,mBAAc,GAAG,IAAI,GAAG,EAAoC,CAAC;QAC7D,qBAAgB,GAAG,IAAI,GAAG,EAAoC,CAAC;IAkD3E,CAAC;IAhHG;;OAEG;IACI,MAAM,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gB,CAAC,UAAkB;QACtC,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,YAAoB;QACpC,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,OAAO,SAAU,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAE,CAAC;IACzE,CAAC;CACJ"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options of one template render (`RenderTemplate` / `RenderTemplateSimple`, and the prompt runner that asks for a
|
|
3
|
+
* raw render on a prompt's behalf).
|
|
4
|
+
*/
|
|
5
|
+
export interface TemplateRenderOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Whether rendered output is HTML-entity escaped (default `true`). Pass `false` when the output is plain text for a
|
|
8
|
+
* model or an email subject line, where `Acme & Co` must not become `Acme & Co`.
|
|
9
|
+
*/
|
|
10
|
+
autoescape?: boolean;
|
|
11
|
+
}
|
|
1
12
|
/**
|
|
2
13
|
* Contains the results of a call to render a template
|
|
3
14
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,oBAAoB;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,OAAO,oBAAoB;CAOhC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/templates-base-types",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.0-edge.
|
|
4
|
+
"version": "6.2.0-edge.5",
|
|
5
5
|
"description": "MemberJunction Templating Base Types for Client/Server Use",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"typescript": "^5.9.3"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@memberjunction/core": "6.2.0-edge.
|
|
18
|
-
"@memberjunction/core-entities": "6.2.0-edge.
|
|
19
|
-
"@memberjunction/global": "6.2.0-edge.
|
|
17
|
+
"@memberjunction/core": "6.2.0-edge.5",
|
|
18
|
+
"@memberjunction/core-entities": "6.2.0-edge.5",
|
|
19
|
+
"@memberjunction/global": "6.2.0-edge.5"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|