@serene-pub/sdk 0.6.0-pr-1
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/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one template checker (typed templates P4): does this Handlebars or
|
|
3
|
+
* Liquid source parse, and does every name it reads exist in the scope it will
|
|
4
|
+
* be rendered against?
|
|
5
|
+
*
|
|
6
|
+
* ## Why a separate entry point
|
|
7
|
+
*
|
|
8
|
+
* `@serene-pub/sdk/template-check`, not the barrel. The checker parses with
|
|
9
|
+
* the real engines — `handlebars` and `liquidjs`, parse only (Q5) — and the
|
|
10
|
+
* barrel is what every node author and plugin bundle imports; it has no
|
|
11
|
+
* dependencies and stays that way. A host (the editor lint, a save, a
|
|
12
|
+
* packager) imports this on purpose. Nothing here renders: the host keeps its
|
|
13
|
+
* own engines with its own helpers, and hands this module their NAMES.
|
|
14
|
+
*
|
|
15
|
+
* ## What it reports, and what it leaves alone
|
|
16
|
+
*
|
|
17
|
+
* - **syntax** — the engine's own words and position. Always an error: a
|
|
18
|
+
* template that does not parse breaks every pipeline that selects it.
|
|
19
|
+
* - **unknown-name** — a root the scope does not have. Renders as nothing.
|
|
20
|
+
* - **unknown-path** — a field the declared type positively contradicts
|
|
21
|
+
* (`characters.nmae`, a field read straight off a list).
|
|
22
|
+
* - **unknown-helper** — a Handlebars helper nobody registered.
|
|
23
|
+
*
|
|
24
|
+
* Conservative by construction: an `'any'` root, a record's author-chosen
|
|
25
|
+
* key, a dynamic lookup (`lookup`, `a[k]`) and a subexpression's result are
|
|
26
|
+
* unchecked, never guessed. Loop items, `{% assign %}`/`{% capture %}`
|
|
27
|
+
* locals, `@data` and `forloop` are never scope names.
|
|
28
|
+
*
|
|
29
|
+
* **Untyped sources.** When `templateScopeReport().untyped` is non-empty some
|
|
30
|
+
* producer supplies keys nobody declared, so a name missing from the scope may
|
|
31
|
+
* still arrive: name and path findings are then WARNINGS, never errors, and
|
|
32
|
+
* say which producer might supply them.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
import Handlebars from 'handlebars';
|
|
36
|
+
import { Liquid, Tag, Hash, analyzeSync } from 'liquidjs';
|
|
37
|
+
import { handlebars as handlebarsEngine, liquid as liquidEngine } from './engines.js';
|
|
38
|
+
import { enterHandlebarsBlock, nearestName, resolveHandlebarsPath, rootHandlebarsReach, typeOfHandlebarsPath, } from './handlebarsReach.js';
|
|
39
|
+
import { resolvePath } from './template.js';
|
|
40
|
+
/**
|
|
41
|
+
* Helpers Handlebars itself registers. A host's own (`json`, `isSet`, …) are
|
|
42
|
+
* an input — {@link TemplateCheckOptions.helpers} — never hard-coded here.
|
|
43
|
+
* @experimental
|
|
44
|
+
*/
|
|
45
|
+
export const HANDLEBARS_BUILTIN_HELPERS = [
|
|
46
|
+
'if',
|
|
47
|
+
'unless',
|
|
48
|
+
'each',
|
|
49
|
+
'with',
|
|
50
|
+
'lookup',
|
|
51
|
+
'log',
|
|
52
|
+
'blockHelperMissing',
|
|
53
|
+
'helperMissing',
|
|
54
|
+
];
|
|
55
|
+
/** Whether {@link checkTemplateSource} can say anything about this engine. @experimental */
|
|
56
|
+
export const canCheckTemplateEngine = (engine) => engine === handlebarsEngine.id || engine === liquidEngine.id;
|
|
57
|
+
/**
|
|
58
|
+
* Check `src` in `engine` against `scope`. The findings only — see
|
|
59
|
+
* {@link checkTemplateSourceReport} for whether anything was checked at all.
|
|
60
|
+
* @experimental
|
|
61
|
+
*/
|
|
62
|
+
export function checkTemplateSource(engine, src, scope, options = {}) {
|
|
63
|
+
return checkTemplateSourceReport(engine, src, scope, options).findings;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check `src` in `engine` against `scope`, and say whether it was checked.
|
|
67
|
+
*
|
|
68
|
+
* A syntax finding short-circuits: nothing useful can be said about the names
|
|
69
|
+
* in a template that does not parse, and saying it anyway buries the one
|
|
70
|
+
* message that matters. Each finding is reported once per place it appears.
|
|
71
|
+
* @experimental
|
|
72
|
+
*/
|
|
73
|
+
export function checkTemplateSourceReport(engine, src, scope, options = {}) {
|
|
74
|
+
if (!canCheckTemplateEngine(engine))
|
|
75
|
+
return { checked: false, findings: [] };
|
|
76
|
+
const lines = lineStarts(src);
|
|
77
|
+
const isHandlebars = engine === handlebarsEngine.id;
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = isHandlebars ? Handlebars.parse(src) : liquidFor(options).parse(src);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
return { checked: true, findings: [syntaxFinding(err, lines)] };
|
|
84
|
+
}
|
|
85
|
+
const sink = new FindingSink(scope, options.untyped ?? [], lines);
|
|
86
|
+
try {
|
|
87
|
+
if (isHandlebars)
|
|
88
|
+
walkHandlebars(parsed, scope, helperSet(options), sink);
|
|
89
|
+
else
|
|
90
|
+
walkLiquid(parsed, src, scope, sink);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// The source parsed a moment ago, so this is the analyser failing on
|
|
94
|
+
// something it did not expect rather than the template being wrong.
|
|
95
|
+
// Reporting nothing is right; claiming it was checked is not.
|
|
96
|
+
return { checked: false, findings: [] };
|
|
97
|
+
}
|
|
98
|
+
return { checked: true, findings: sink.findings };
|
|
99
|
+
}
|
|
100
|
+
// ── Positions ───────────────────────────────────────────────────────────────
|
|
101
|
+
function lineStarts(src) {
|
|
102
|
+
const out = [0];
|
|
103
|
+
for (let i = 0; i < src.length; i++)
|
|
104
|
+
if (src[i] === '\n')
|
|
105
|
+
out.push(i + 1);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
/** 1-based line, 1-based column → 0-based offset. */
|
|
109
|
+
const offsetOf = (lines, line, column) => (lines[line - 1] ?? 0) + column - 1;
|
|
110
|
+
/**
|
|
111
|
+
* Read a line and column off whatever the engine threw — the engine's own
|
|
112
|
+
* report, never a guess. Handlebars sets `lineNumber` when a block does not
|
|
113
|
+
* match its closer and otherwise states the line in its message; LiquidJS puts
|
|
114
|
+
* the position on the token it failed at. None is guaranteed.
|
|
115
|
+
*/
|
|
116
|
+
function positionOf(err) {
|
|
117
|
+
const e = err;
|
|
118
|
+
if (typeof e?.lineNumber === 'number')
|
|
119
|
+
return { line: e.lineNumber, column: (typeof e.column === 'number' ? e.column : 0) + 1 };
|
|
120
|
+
const stated = /^Parse error on line (\d+)/.exec(String(e?.message ?? ''));
|
|
121
|
+
if (stated)
|
|
122
|
+
return { line: Number(stated[1]) };
|
|
123
|
+
if (e?.token && typeof e.token.getPosition === 'function') {
|
|
124
|
+
const [line, column] = e.token.getPosition();
|
|
125
|
+
if (typeof line === 'number')
|
|
126
|
+
return { line, column };
|
|
127
|
+
}
|
|
128
|
+
return {};
|
|
129
|
+
}
|
|
130
|
+
function syntaxFinding(err, lines) {
|
|
131
|
+
const at = positionOf(err);
|
|
132
|
+
const message = String(err?.message ?? err);
|
|
133
|
+
return {
|
|
134
|
+
kind: 'syntax',
|
|
135
|
+
severity: 'error',
|
|
136
|
+
message,
|
|
137
|
+
fix: at.line
|
|
138
|
+
? `fix line ${at.line} so the template parses — the engine names the construct it stopped at`
|
|
139
|
+
: 'fix the template so it parses — the engine names the construct it stopped at',
|
|
140
|
+
...at,
|
|
141
|
+
...(at.line ? { start: offsetOf(lines, at.line, at.column ?? 1) } : {}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
class FindingSink {
|
|
145
|
+
scope;
|
|
146
|
+
untyped;
|
|
147
|
+
lines;
|
|
148
|
+
findings = [];
|
|
149
|
+
seen = new Set();
|
|
150
|
+
constructor(scope, untyped, lines) {
|
|
151
|
+
this.scope = scope;
|
|
152
|
+
this.untyped = untyped;
|
|
153
|
+
this.lines = lines;
|
|
154
|
+
}
|
|
155
|
+
get nameSeverity() {
|
|
156
|
+
return this.untyped.length ? 'warning' : 'error';
|
|
157
|
+
}
|
|
158
|
+
/** The sentence an untyped source earns a warning, or nothing. */
|
|
159
|
+
get untypedNote() {
|
|
160
|
+
if (!this.untyped.length)
|
|
161
|
+
return '';
|
|
162
|
+
const who = this.untyped.join(', ');
|
|
163
|
+
return ` It may still come from ${who}, which ${this.untyped.length === 1 ? 'declares' : 'declare'} no types.`;
|
|
164
|
+
}
|
|
165
|
+
push(f) {
|
|
166
|
+
const key = `${f.kind}:${f.path ?? f.name}:${f.start}`;
|
|
167
|
+
if (this.seen.has(key))
|
|
168
|
+
return;
|
|
169
|
+
this.seen.add(key);
|
|
170
|
+
this.findings.push(f);
|
|
171
|
+
}
|
|
172
|
+
where(line, column, length, tag) {
|
|
173
|
+
const start = offsetOf(this.lines, line, column);
|
|
174
|
+
return { line, column, start, end: start + length, ...(tag ? { tag } : {}) };
|
|
175
|
+
}
|
|
176
|
+
unknownRoot(root, path, available, line, column, tag) {
|
|
177
|
+
const suggestion = nearestName(root, available);
|
|
178
|
+
this.push({
|
|
179
|
+
kind: 'unknown-name',
|
|
180
|
+
severity: this.nameSeverity,
|
|
181
|
+
name: root,
|
|
182
|
+
path,
|
|
183
|
+
message: `"${root}" isn't a recognized field at this scope, so it renders as nothing.` +
|
|
184
|
+
(suggestion ? ` Did you mean "${suggestion}"?` : '') +
|
|
185
|
+
this.untypedNote,
|
|
186
|
+
fix: suggestion
|
|
187
|
+
? `use "${suggestion}"`
|
|
188
|
+
: available.length
|
|
189
|
+
? `available here: ${available.join(', ')}`
|
|
190
|
+
: 'nothing is declared here — check the node this template belongs to',
|
|
191
|
+
available,
|
|
192
|
+
...(suggestion ? { suggestion } : {}),
|
|
193
|
+
...this.where(line, column, path.length, tag),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
badPath(r, root, path, line, column, tag) {
|
|
197
|
+
const suggestion = r.at && r.available?.length ? nearestName(r.at, r.available) : undefined;
|
|
198
|
+
this.push({
|
|
199
|
+
kind: 'unknown-path',
|
|
200
|
+
severity: this.nameSeverity,
|
|
201
|
+
name: root,
|
|
202
|
+
path,
|
|
203
|
+
message:
|
|
204
|
+
// A sentence, so the did-you-mean after it reads as one too.
|
|
205
|
+
(r.message ?? 'that path does not exist.').replace(/([^.?!])$/, '$1.') +
|
|
206
|
+
(suggestion ? ` Did you mean "${suggestion}"?` : '') +
|
|
207
|
+
this.untypedNote,
|
|
208
|
+
fix: suggestion
|
|
209
|
+
? `use "${suggestion}"`
|
|
210
|
+
: r.available?.length
|
|
211
|
+
? `'${r.at}' is not one of: ${r.available.join(', ')}`
|
|
212
|
+
: 'check the shape this template declares — the path does not exist on it',
|
|
213
|
+
...(r.available ? { available: r.available } : {}),
|
|
214
|
+
...(suggestion ? { suggestion } : {}),
|
|
215
|
+
...this.where(line, column, path.length, tag),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
unknownHelper(name, known, line, column, tag) {
|
|
219
|
+
const suggestion = nearestName(name, known);
|
|
220
|
+
this.push({
|
|
221
|
+
kind: 'unknown-helper',
|
|
222
|
+
severity: 'error',
|
|
223
|
+
name,
|
|
224
|
+
message: `"${name}" isn't a recognized helper.` +
|
|
225
|
+
(suggestion ? ` Did you mean "${suggestion}"?` : ''),
|
|
226
|
+
fix: suggestion ? `use "${suggestion}"` : `helpers here: ${known.join(', ')}`,
|
|
227
|
+
available: [...known],
|
|
228
|
+
...(suggestion ? { suggestion } : {}),
|
|
229
|
+
...this.where(line, column, name.length, tag),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** Report whatever a resolution says is wrong. */
|
|
233
|
+
resolution(r, path, line, column, tag) {
|
|
234
|
+
if (r.kind === 'unknown-root')
|
|
235
|
+
this.unknownRoot(r.root, path, r.available, line, column, tag);
|
|
236
|
+
else if (r.kind === 'resolved' && !r.resolution.ok)
|
|
237
|
+
this.badPath(r.resolution, r.label, path, line, column, tag);
|
|
238
|
+
}
|
|
239
|
+
get scopeNames() {
|
|
240
|
+
return Object.keys(this.scope);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function helperSet(options) {
|
|
244
|
+
return new Set([...HANDLEBARS_BUILTIN_HELPERS, ...(options.helpers ?? [])]);
|
|
245
|
+
}
|
|
246
|
+
const isPath = (n) => n?.type === 'PathExpression';
|
|
247
|
+
/** `this.x`, `./x` — Handlebars' own `scopedId` test. */
|
|
248
|
+
const scopedOf = (p) => /^\.|this\b/.test(p.original);
|
|
249
|
+
const readPath = (p) => ({
|
|
250
|
+
depth: p.depth ?? 0,
|
|
251
|
+
scoped: scopedOf(p),
|
|
252
|
+
data: !!p.data,
|
|
253
|
+
parts: p.parts ?? [],
|
|
254
|
+
});
|
|
255
|
+
/** A one-segment, unclimbed, unscoped name — what a helper call is spelled with. */
|
|
256
|
+
const simpleName = (p) => isPath(p) && !p.data && !p.depth && p.parts?.length === 1 && !scopedOf(p)
|
|
257
|
+
? p.parts[0]
|
|
258
|
+
: undefined;
|
|
259
|
+
function walkHandlebars(ast, scope, helpers, sink) {
|
|
260
|
+
const knownHelpers = [...helpers].sort();
|
|
261
|
+
const lines = sink.lines;
|
|
262
|
+
const spanOf = (loc) => loc
|
|
263
|
+
? {
|
|
264
|
+
start: offsetOf(lines, loc.start.line, loc.start.column + 1),
|
|
265
|
+
end: offsetOf(lines, loc.end.line, loc.end.column + 1),
|
|
266
|
+
}
|
|
267
|
+
: undefined;
|
|
268
|
+
const ref = (node, reach, tag) => {
|
|
269
|
+
if (!node)
|
|
270
|
+
return;
|
|
271
|
+
if (node.type === 'SubExpression')
|
|
272
|
+
return call(node, reach, tag);
|
|
273
|
+
if (!isPath(node))
|
|
274
|
+
return;
|
|
275
|
+
const path = readPath(node);
|
|
276
|
+
if (path.data || !path.parts.length)
|
|
277
|
+
return;
|
|
278
|
+
const r = resolveHandlebarsPath(path, reach, scope);
|
|
279
|
+
const written = node.original || path.parts.join('.');
|
|
280
|
+
sink.resolution(r, written, node.loc?.start.line ?? 1, (node.loc?.start.column ?? 0) + 1, tag);
|
|
281
|
+
};
|
|
282
|
+
const args = (node, reach, tag) => {
|
|
283
|
+
for (const p of node.params ?? [])
|
|
284
|
+
ref(p, reach, tag);
|
|
285
|
+
for (const pair of node.hash?.pairs ?? [])
|
|
286
|
+
ref(pair.value, reach, tag);
|
|
287
|
+
};
|
|
288
|
+
/** A helper invocation — `(eq a b)`, `{{pad x 2}}`: the name is a helper, the rest are values. */
|
|
289
|
+
const call = (node, reach, tag) => {
|
|
290
|
+
const name = simpleName(node.path);
|
|
291
|
+
if (name !== undefined && !helpers.has(name))
|
|
292
|
+
sink.unknownHelper(name, knownHelpers, node.path.loc?.start.line ?? 1, (node.path.loc?.start.column ?? 0) + 1, tag);
|
|
293
|
+
else if (name === undefined)
|
|
294
|
+
ref(node.path, reach, tag);
|
|
295
|
+
args(node, reach, tag);
|
|
296
|
+
};
|
|
297
|
+
const program = (p, reach) => {
|
|
298
|
+
for (const stmt of p?.body ?? [])
|
|
299
|
+
statement(stmt, reach);
|
|
300
|
+
};
|
|
301
|
+
const statement = (node, reach) => {
|
|
302
|
+
const tag = spanOf(node.loc);
|
|
303
|
+
switch (node.type) {
|
|
304
|
+
case 'MustacheStatement': {
|
|
305
|
+
const m = node;
|
|
306
|
+
if (m.params?.length || m.hash?.pairs?.length)
|
|
307
|
+
return call(m, reach, tag);
|
|
308
|
+
// `{{log}}`-style: a bare name that IS a helper is a call, not a read.
|
|
309
|
+
const name = simpleName(m.path);
|
|
310
|
+
if (name !== undefined && helpers.has(name))
|
|
311
|
+
return;
|
|
312
|
+
return ref(m.path, reach, tag);
|
|
313
|
+
}
|
|
314
|
+
case 'BlockStatement': {
|
|
315
|
+
const b = node;
|
|
316
|
+
// `{{#foo}}` is always an invocation, never a variable.
|
|
317
|
+
const name = simpleName(b.path);
|
|
318
|
+
if (name !== undefined && !helpers.has(name))
|
|
319
|
+
sink.unknownHelper(name, knownHelpers, b.path.loc?.start.line ?? 1, (b.path.loc?.start.column ?? 0) + 1, tag);
|
|
320
|
+
args(b, reach, tag);
|
|
321
|
+
const helper = name ?? '';
|
|
322
|
+
const first = b.params?.[0];
|
|
323
|
+
const target = (helper === 'each' || helper === 'with') && isPath(first)
|
|
324
|
+
? typeOfHandlebarsPath(readPath(first), reach, scope)
|
|
325
|
+
: undefined;
|
|
326
|
+
program(b.program, enterHandlebarsBlock(reach, helper, target, b.program?.blockParams ?? []));
|
|
327
|
+
// An `{{else}}` runs in the reach the block was opened in: an
|
|
328
|
+
// `each` over nothing, a `with` of nothing — never the element.
|
|
329
|
+
program(b.inverse, enterHandlebarsBlock(reach, 'if', undefined, b.inverse?.blockParams ?? []));
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
case 'PartialStatement':
|
|
333
|
+
case 'PartialBlockStatement': {
|
|
334
|
+
const p = node;
|
|
335
|
+
for (const x of p.params ?? [])
|
|
336
|
+
ref(x, reach, tag);
|
|
337
|
+
for (const pair of p.hash?.pairs ?? [])
|
|
338
|
+
ref(pair.value, reach, tag);
|
|
339
|
+
program(p.program, reach);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
default:
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
program(ast, rootHandlebarsReach());
|
|
347
|
+
}
|
|
348
|
+
// ── Liquid ──────────────────────────────────────────────────────────────────
|
|
349
|
+
/**
|
|
350
|
+
* The filesystem the checker's Liquid gets: none. It parses; nothing it does
|
|
351
|
+
* should ever read a file, and a re-registered `include` finds no loader.
|
|
352
|
+
*/
|
|
353
|
+
const NO_FILESYSTEM = {
|
|
354
|
+
exists: async () => false,
|
|
355
|
+
existsSync: () => false,
|
|
356
|
+
readFile: async () => {
|
|
357
|
+
throw new Error('templates are rows, not files');
|
|
358
|
+
},
|
|
359
|
+
readFileSync: () => {
|
|
360
|
+
throw new Error('templates are rows, not files');
|
|
361
|
+
},
|
|
362
|
+
resolve: () => {
|
|
363
|
+
throw new Error('templates are rows, not files');
|
|
364
|
+
},
|
|
365
|
+
contains: async () => false,
|
|
366
|
+
containsSync: () => false,
|
|
367
|
+
};
|
|
368
|
+
/** A tag refused at parse time, with the host's sentence. */
|
|
369
|
+
function refusedTag(message) {
|
|
370
|
+
return class extends Tag {
|
|
371
|
+
constructor(token, remainTokens, liquid) {
|
|
372
|
+
super(token, remainTokens, liquid);
|
|
373
|
+
throw new Error(message);
|
|
374
|
+
}
|
|
375
|
+
*render() { }
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* A `{% name %}…{% endname %}` tag the host registers, parsed the way the
|
|
380
|
+
* host's is: the body up to the closer, `key: value` arguments as a hash. It
|
|
381
|
+
* exposes both to the analyser, so a name inside the body — or in `id: m.id` —
|
|
382
|
+
* is seen.
|
|
383
|
+
*/
|
|
384
|
+
function blockTag() {
|
|
385
|
+
return class extends Tag {
|
|
386
|
+
args;
|
|
387
|
+
body = [];
|
|
388
|
+
constructor(token, remainTokens, liquid, parser) {
|
|
389
|
+
super(token, remainTokens, liquid);
|
|
390
|
+
this.args = new Hash(this.tokenizer, liquid.options.keyValueSeparator);
|
|
391
|
+
const body = this.body;
|
|
392
|
+
parser
|
|
393
|
+
.parseStream(remainTokens)
|
|
394
|
+
.on('template', (tpl) => body.push(tpl))
|
|
395
|
+
.on(`tag:end${token.name}`, function () {
|
|
396
|
+
this.stop();
|
|
397
|
+
})
|
|
398
|
+
.on('end', () => {
|
|
399
|
+
throw new Error(`tag ${token.getText()} not closed`);
|
|
400
|
+
})
|
|
401
|
+
.start();
|
|
402
|
+
}
|
|
403
|
+
*render(_ctx, _emitter) { }
|
|
404
|
+
*children() {
|
|
405
|
+
return this.body;
|
|
406
|
+
}
|
|
407
|
+
*arguments() {
|
|
408
|
+
for (const v of Object.values(this.args.hash))
|
|
409
|
+
if (v)
|
|
410
|
+
yield v;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
const liquidCache = new WeakMap();
|
|
415
|
+
let defaultLiquid;
|
|
416
|
+
function liquidFor(options) {
|
|
417
|
+
const o = options.liquid;
|
|
418
|
+
if (!o)
|
|
419
|
+
return (defaultLiquid ??= makeLiquid({}));
|
|
420
|
+
let l = liquidCache.get(o);
|
|
421
|
+
if (!l)
|
|
422
|
+
liquidCache.set(o, (l = makeLiquid(o)));
|
|
423
|
+
return l;
|
|
424
|
+
}
|
|
425
|
+
function makeLiquid(o) {
|
|
426
|
+
const liquid = new Liquid({
|
|
427
|
+
strictFilters: true,
|
|
428
|
+
strictVariables: false,
|
|
429
|
+
ownPropertyOnly: true,
|
|
430
|
+
cache: false,
|
|
431
|
+
root: [],
|
|
432
|
+
partials: [],
|
|
433
|
+
layouts: [],
|
|
434
|
+
relativeReference: false,
|
|
435
|
+
fs: NO_FILESYSTEM,
|
|
436
|
+
...(o.parseLimit ? { parseLimit: o.parseLimit } : {}),
|
|
437
|
+
});
|
|
438
|
+
for (const [name, message] of Object.entries(o.refusedTags ?? {}))
|
|
439
|
+
liquid.registerTag(name, refusedTag(message));
|
|
440
|
+
for (const name of o.blockTags ?? [])
|
|
441
|
+
liquid.registerTag(name, blockTag());
|
|
442
|
+
// Parse only: a filter need exist, not work.
|
|
443
|
+
for (const name of o.filters ?? [])
|
|
444
|
+
liquid.registerFilter(name, (v) => v);
|
|
445
|
+
return liquid;
|
|
446
|
+
}
|
|
447
|
+
/** Liquid answers these on a list (and `size` on a string) without a declaration. */
|
|
448
|
+
const LIQUID_LIST_INTRINSICS = new Set(['size', 'first', 'last']);
|
|
449
|
+
/**
|
|
450
|
+
* Walk Liquid segments against a declaration, one at a time so `first`/`last`
|
|
451
|
+
* step into the element and `size` ends the walk — the three reads Liquid
|
|
452
|
+
* answers on a list that the schema never declares.
|
|
453
|
+
*/
|
|
454
|
+
function resolveLiquidPath(decl, segs, base) {
|
|
455
|
+
let cur = decl;
|
|
456
|
+
let label = base;
|
|
457
|
+
for (const seg of segs) {
|
|
458
|
+
const field = cur && cur !== 'any' && !Array.isArray(cur) ? cur : undefined;
|
|
459
|
+
if (field &&
|
|
460
|
+
LIQUID_LIST_INTRINSICS.has(seg) &&
|
|
461
|
+
(field.type === 'list' || (field.type === 'string' && seg === 'size'))) {
|
|
462
|
+
if (seg === 'size')
|
|
463
|
+
return { ok: true, checked: true, field: { type: 'number' } };
|
|
464
|
+
if (!field.of)
|
|
465
|
+
return { ok: true, checked: false };
|
|
466
|
+
cur = field.of;
|
|
467
|
+
label = `${label}.${seg}`;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const r = resolvePath(cur, [seg], label);
|
|
471
|
+
if (!r.ok)
|
|
472
|
+
return r;
|
|
473
|
+
if (!r.field)
|
|
474
|
+
return { ok: true, checked: false };
|
|
475
|
+
cur = r.field;
|
|
476
|
+
label = `${label}.${seg}`;
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
ok: true,
|
|
480
|
+
checked: true,
|
|
481
|
+
...(cur && cur !== 'any' && !Array.isArray(cur) ? { field: cur } : {}),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
/** `a.b['c d']` as written at `start` — a span for the finding, not a parse. */
|
|
485
|
+
const WRITTEN_PATH = /^[A-Za-z_][\w-]*(?:\s*(?:\.[\w-]+|\[[^\]]*\]))*/;
|
|
486
|
+
function walkLiquid(templates, src, scope, sink) {
|
|
487
|
+
// `globals` is Liquid's own answer to "which names come from outside": loop
|
|
488
|
+
// bindings, assigns, captures and `forloop` are already excluded, which is
|
|
489
|
+
// the conservative line. Loop items are therefore unchecked.
|
|
490
|
+
const analysis = analyzeSync(templates, { partials: false });
|
|
491
|
+
const lines = sink.lines;
|
|
492
|
+
for (const [root, uses] of Object.entries(analysis.globals))
|
|
493
|
+
for (const use of uses) {
|
|
494
|
+
const { row, col } = use.location;
|
|
495
|
+
const start = offsetOf(lines, row, col);
|
|
496
|
+
const written = WRITTEN_PATH.exec(src.slice(start))?.[0] ?? root;
|
|
497
|
+
// A dynamic segment (`a[k]`) ends what can be checked; `k` is
|
|
498
|
+
// reported on its own, as the analyser lists it separately.
|
|
499
|
+
const segs = [];
|
|
500
|
+
for (const s of use.segments.slice(1)) {
|
|
501
|
+
if (typeof s === 'string' || typeof s === 'number')
|
|
502
|
+
segs.push(String(s));
|
|
503
|
+
else
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
const decl = scope[root];
|
|
507
|
+
if (decl === undefined) {
|
|
508
|
+
sink.unknownRoot(root, written, sink.scopeNames, row, col);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
const r = resolveLiquidPath(decl, segs, root);
|
|
512
|
+
if (!r.ok)
|
|
513
|
+
sink.badPath(r, root, written, row, col);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
//# sourceMappingURL=templateCheck.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does this template fit this node? (typed templates P5, 2026-09-27)
|
|
3
|
+
*
|
|
4
|
+
* The refusals of design §4, in one place: a template is checked against the
|
|
5
|
+
* typed scope of the node that renders it (`templateScopeReport`), and a name
|
|
6
|
+
* or path nothing there supplies is REFUSED — at selection (the host), at a
|
|
7
|
+
* spec's save and publish (law T1, `validate()`), and at packaging (a plugin's
|
|
8
|
+
* shipped template seeds). Warnings never refuse, and nor does anything while
|
|
9
|
+
* a producer upstream declares no types (`untyped`): its keys may still
|
|
10
|
+
* arrive, so the checker only warns (owner Q6: refuse new selections and new
|
|
11
|
+
* saves; a stored row becomes a notice, never a retroactive refusal).
|
|
12
|
+
*
|
|
13
|
+
* ## The checker is a value
|
|
14
|
+
*
|
|
15
|
+
* The checker parses with the real engines (`@serene-pub/sdk/template-check`,
|
|
16
|
+
* which carries `handlebars` and `liquidjs`); this module is on the barrel,
|
|
17
|
+
* which stays dependency-free. So every door here takes the checker as an
|
|
18
|
+
* argument — `{ check: checkTemplateSourceReport }` — and a caller without one
|
|
19
|
+
* gets the checker-free half of T1 (scope collisions, forbidden kinds, a band
|
|
20
|
+
* with no variable) and no name check. One way to check; the engines stay
|
|
21
|
+
* where they were imported on purpose.
|
|
22
|
+
*
|
|
23
|
+
* ## What refuses
|
|
24
|
+
*
|
|
25
|
+
* `SCOPE_FINDING_KINDS` — `unknown-name` and `unknown-path` at error
|
|
26
|
+
* severity. A syntax finding and an unknown helper depend on the host's
|
|
27
|
+
* vocabulary (its helpers, its Liquid tags), which a spec document and a
|
|
28
|
+
* package do not carry; a host that passes its own vocabulary may widen
|
|
29
|
+
* `refuse`.
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
32
|
+
import { type BandSource } from './bands.js';
|
|
33
|
+
import type { DocEdge, DocNode } from './document.js';
|
|
34
|
+
import type { TemplateValue } from './engines.js';
|
|
35
|
+
import type { TemplateCheckOptions, TemplateFinding, TemplateFindingKind, TemplateScope, TemplateSourceCheck } from './template.js';
|
|
36
|
+
import type { TemplateSeed } from './templateIds.js';
|
|
37
|
+
import { type ScopeSource, type TemplateScopeEnv } from './templateScopeAt.js';
|
|
38
|
+
/** `checkTemplateSourceReport` from `@serene-pub/sdk/template-check`, as a value. @experimental */
|
|
39
|
+
export type TemplateSourceChecker = (engine: string, source: string, scope: TemplateScope, options?: TemplateCheckOptions) => TemplateSourceCheck;
|
|
40
|
+
/** How to check a template's names: the checker, the host's vocabulary, what refuses. @experimental */
|
|
41
|
+
export interface TemplateChecking {
|
|
42
|
+
check: TemplateSourceChecker;
|
|
43
|
+
/** The host's helpers and Liquid vocabulary. `untyped` is filled in per node. */
|
|
44
|
+
options?: TemplateCheckOptions;
|
|
45
|
+
/** Error findings of these kinds refuse. Default: {@link SCOPE_FINDING_KINDS}. */
|
|
46
|
+
refuse?: readonly TemplateFindingKind[];
|
|
47
|
+
}
|
|
48
|
+
/** What a scope decides — a name or a path nothing supplies. @experimental */
|
|
49
|
+
export declare const SCOPE_FINDING_KINDS: readonly TemplateFindingKind[];
|
|
50
|
+
/** @experimental */
|
|
51
|
+
export interface TemplateFit {
|
|
52
|
+
/** False when the checker could not read the engine — nothing was judged. */
|
|
53
|
+
checked: boolean;
|
|
54
|
+
/** Producers whose keys reach the template undeclared; non-empty means nothing refuses. */
|
|
55
|
+
untyped: string[];
|
|
56
|
+
/** Error findings of a refusing kind. Non-empty: refuse, with {@link templateFitSentence}. */
|
|
57
|
+
refusals: TemplateFinding[];
|
|
58
|
+
/** Everything else the checker said. Shown, never refused. */
|
|
59
|
+
warnings: TemplateFinding[];
|
|
60
|
+
}
|
|
61
|
+
type Doc = {
|
|
62
|
+
nodes: readonly DocNode[];
|
|
63
|
+
edges: readonly DocEdge[];
|
|
64
|
+
input?: {
|
|
65
|
+
genre?: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Check `template` against the typed scope of its template slot at `nodeKey`.
|
|
70
|
+
* Throws what `templateScopeReport` throws — a root two declarers claim, a
|
|
71
|
+
* forbidden kind — because then the document is wrong, not the template.
|
|
72
|
+
* @experimental
|
|
73
|
+
*/
|
|
74
|
+
export declare function templateFit(doc: Doc, nodeKey: string, template: TemplateValue, checking: TemplateChecking, env?: TemplateScopeEnv): TemplateFit;
|
|
75
|
+
/**
|
|
76
|
+
* The refusal, in the design's words:
|
|
77
|
+
*
|
|
78
|
+
* > 'speakPrompt' can't render 'Riddle layout': it uses `secretEntri`, which
|
|
79
|
+
* > nothing supplies here. Did you mean `secretEntry`? Available: …
|
|
80
|
+
*
|
|
81
|
+
* `where` names the step (a node key); `what` names the template (its name, or
|
|
82
|
+
* "the 'x' preset's template").
|
|
83
|
+
* @experimental
|
|
84
|
+
*/
|
|
85
|
+
export declare function templateFitSentence(where: string, what: string, refusals: readonly TemplateFinding[]): string;
|
|
86
|
+
/** The finding shape `validate()` returns — structural, so this module does not import it. */
|
|
87
|
+
interface LawFinding {
|
|
88
|
+
law: string;
|
|
89
|
+
severity: 'error' | 'warning';
|
|
90
|
+
nodeKey?: string;
|
|
91
|
+
message: string;
|
|
92
|
+
fix: string;
|
|
93
|
+
}
|
|
94
|
+
type Describe = (node: DocNode) => (ScopeSource & BandSource) | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Law T1 over one document (design §4.2):
|
|
97
|
+
*
|
|
98
|
+
* - a root two declarers claim at a template node, or a forbidden kind in its
|
|
99
|
+
* scope — refused, naming both declarers (`templateScopeReport`);
|
|
100
|
+
* - a band reaching a `rendersBands` slot whose variable is not registered —
|
|
101
|
+
* refused (a band with no variable renders under a name nothing declares);
|
|
102
|
+
* - with `checking`: every template source the document carries (a node's
|
|
103
|
+
* configured value, each preset's) is checked against the typed scope of
|
|
104
|
+
* the slot it fills, and a name or path nothing supplies is refused.
|
|
105
|
+
*
|
|
106
|
+
* Also law T2 (P6, `annexPortFindings`): the annex in-port.
|
|
107
|
+
*
|
|
108
|
+
* Errors only: a warning is the editor's and the receipt's to say.
|
|
109
|
+
* @experimental
|
|
110
|
+
*/
|
|
111
|
+
export declare function templateLawFindings(doc: Doc & {
|
|
112
|
+
presets?: ReadonlyArray<{
|
|
113
|
+
slug: string;
|
|
114
|
+
values: ReadonlyArray<{
|
|
115
|
+
nodeKey: string;
|
|
116
|
+
slot: string;
|
|
117
|
+
value: unknown;
|
|
118
|
+
}>;
|
|
119
|
+
}>;
|
|
120
|
+
}, checking?: TemplateChecking, env?: Omit<TemplateScopeEnv, 'slot'>): LawFinding[];
|
|
121
|
+
/** The one query that may feed a template's annex in-port, and the view it must read. @experimental */
|
|
122
|
+
export declare const TEMPLATE_ANNEX_QUERY = "core:query/session-annex";
|
|
123
|
+
/** @experimental */
|
|
124
|
+
export declare const TEMPLATE_ANNEX_VIEW = "template";
|
|
125
|
+
/**
|
|
126
|
+
* Law T2 (typed templates P6, owner ruling Q1): a template node's `annex`
|
|
127
|
+
* in-port is fed only by `core:query/session-annex@1` reading `view:
|
|
128
|
+
* 'template'` — every declared key of every owner in scope, and nothing a
|
|
129
|
+
* declaration does not cover — and a template-view read feeds nothing but
|
|
130
|
+
* such a port. Either half broken would put undeclared data into a prompt, or
|
|
131
|
+
* the prompt's data somewhere a prompt is not. Errors only.
|
|
132
|
+
* @experimental
|
|
133
|
+
*/
|
|
134
|
+
export declare function annexPortFindings(doc: Doc, describe?: Describe): LawFinding[];
|
|
135
|
+
/** One refused seed: which, where, and the sentence. @experimental */
|
|
136
|
+
export interface TemplateSeedFinding {
|
|
137
|
+
/** The seed's template id. */
|
|
138
|
+
template: string;
|
|
139
|
+
/** The spec and node it was checked at. */
|
|
140
|
+
specId: string;
|
|
141
|
+
nodeKey: string;
|
|
142
|
+
message: string;
|
|
143
|
+
fix: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Check a package's `context template` seeds (`TemplateSeed` kind
|
|
147
|
+
* `template`) against every node of its own specs that renders them — the
|
|
148
|
+
* seed's pool is the node definition, so each such node is a place it can be
|
|
149
|
+
* selected. A seed no spec of the package places is left to the host, whose
|
|
150
|
+
* selection check sees the spec that selects it.
|
|
151
|
+
* @experimental
|
|
152
|
+
*/
|
|
153
|
+
export declare function templateSeedFindings(seeds: readonly TemplateSeed[], documents: ReadonlyArray<Doc & {
|
|
154
|
+
id: string;
|
|
155
|
+
}>, checking: TemplateChecking, env?: Omit<TemplateScopeEnv, 'slot'>): TemplateSeedFinding[];
|
|
156
|
+
export {};
|
|
157
|
+
//# sourceMappingURL=templateFit.d.ts.map
|