@promptctl/go-template-js 0.9.0 → 0.12.0
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/README.md +131 -10
- package/dist/index.d.ts +284 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1306 -519
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -16,9 +16,11 @@ interface Pos {
|
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/errors.d.ts
|
|
19
|
-
type ErrorKind = "ParseError" | "EvalError" | "FuncNotFoundError" | "TypeMismatchError" | "MissingFieldError" | "FailError";
|
|
19
|
+
type ErrorKind = "ParseError" | "EvalError" | "FuncNotFoundError" | "ArgCountError" | "TypeMismatchError" | "MissingFieldError" | "FailError";
|
|
20
20
|
interface TemplateErrorContext {
|
|
21
21
|
readonly source?: string | undefined;
|
|
22
|
+
/** The error a function body threw, when this one reports it at the call site. */
|
|
23
|
+
readonly cause?: unknown;
|
|
22
24
|
}
|
|
23
25
|
declare class TemplateError extends Error {
|
|
24
26
|
readonly name: string;
|
|
@@ -59,6 +61,37 @@ declare class FuncNotFoundError extends EvalError {
|
|
|
59
61
|
available?: readonly string[];
|
|
60
62
|
});
|
|
61
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The argument counts a func accepts — a closed interval, with
|
|
66
|
+
* `maximum: Infinity` for the variadic and alternating kinds.
|
|
67
|
+
*
|
|
68
|
+
* [LAW:one-source-of-truth] Nothing declares these numbers. They are
|
|
69
|
+
* derived from `TemplateFunc.arity` and `argTypes.length` by
|
|
70
|
+
* `acceptedArgCount` in the evaluator, which is the only producer; a
|
|
71
|
+
* registration that stored its own minimum would be a second copy of a
|
|
72
|
+
* number the declaration already carries.
|
|
73
|
+
*/
|
|
74
|
+
interface ArgCount {
|
|
75
|
+
readonly minimum: number;
|
|
76
|
+
readonly maximum: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Thrown when a func is called with a number of arguments its declared
|
|
80
|
+
* arity does not accept — `{{ upper "a" "b" }}`, `{{ min }}`.
|
|
81
|
+
*
|
|
82
|
+
* The message mirrors Go's `text/template`, which reports a fixed-arity
|
|
83
|
+
* signature as `want N` and a variadic one as `want at least N`. That
|
|
84
|
+
* distinction is read off `accepted`, not passed in, so the two phrasings
|
|
85
|
+
* cannot disagree about which one a given func gets.
|
|
86
|
+
*/
|
|
87
|
+
declare class ArgCountError extends EvalError {
|
|
88
|
+
readonly name = "ArgCountError";
|
|
89
|
+
readonly kind: ErrorKind;
|
|
90
|
+
readonly funcName: string;
|
|
91
|
+
readonly accepted: ArgCount;
|
|
92
|
+
readonly got: number;
|
|
93
|
+
constructor(funcName: string, accepted: ArgCount, got: number, pos: Pos, ctx?: TemplateErrorContext);
|
|
94
|
+
}
|
|
62
95
|
declare class TypeMismatchError extends EvalError {
|
|
63
96
|
readonly name = "TypeMismatchError";
|
|
64
97
|
readonly kind: ErrorKind;
|
|
@@ -69,6 +102,18 @@ declare class TypeMismatchError extends EvalError {
|
|
|
69
102
|
readonly receivedSummary: string;
|
|
70
103
|
constructor(funcName: string, argIndex: number, expected: string, receivedSummary: string, pos: Pos, ctx?: TemplateErrorContext);
|
|
71
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* An integer slot refused a number that is not a safe integer. Still a
|
|
107
|
+
* `TypeMismatchError` (the slot's type refused the value), but worded
|
|
108
|
+
* with the value and the reason: a fractional is Go's own refusal,
|
|
109
|
+
* `expected integer; found 2.7`, and an integer past 2^53 is
|
|
110
|
+
* `integer out of range: <n>`, since JS cannot carry it exactly. The
|
|
111
|
+
* generic wording would say a number was expected and a number arrived,
|
|
112
|
+
* and suggest flattening a styled value that was never there.
|
|
113
|
+
*/
|
|
114
|
+
declare class NotIntegerError extends TypeMismatchError {
|
|
115
|
+
constructor(funcName: string, argIndex: number, value: number | bigint, pos: Pos, ctx?: TemplateErrorContext);
|
|
116
|
+
}
|
|
72
117
|
declare class MissingFieldError extends EvalError {
|
|
73
118
|
readonly name = "MissingFieldError";
|
|
74
119
|
readonly kind: ErrorKind;
|
|
@@ -113,9 +158,31 @@ declare class Defines {
|
|
|
113
158
|
static readonly EMPTY: Defines;
|
|
114
159
|
private constructor();
|
|
115
160
|
has(name: string): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Every name this set can render, own and inherited, sorted — what a
|
|
163
|
+
* consumer reads after `evaluateDefine` reports a name as not defined.
|
|
164
|
+
* The parser forbids redeclaring an inherited name, so the chain repeats
|
|
165
|
+
* none; the Set keeps the listing duplicate-free without leaning on that.
|
|
166
|
+
*/
|
|
167
|
+
names(): string[];
|
|
116
168
|
}
|
|
117
169
|
//#endregion
|
|
118
170
|
//#region src/evaluator/evaluator.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* Every kind a slot may declare.
|
|
173
|
+
*
|
|
174
|
+
* [LAW:one-source-of-truth] The kinds are a *list* first and a type
|
|
175
|
+
* second. `validateArgSpecs` must reject a declaration naming a kind
|
|
176
|
+
* that does not exist, and a runtime check needs a runtime list; writing
|
|
177
|
+
* that list out beside a hand-maintained union would be the second
|
|
178
|
+
* clock. So the array is authoritative and `ArgType` is derived from it
|
|
179
|
+
* — one edit adds a kind to the type, to the construct-time check, and
|
|
180
|
+
* to the two exhaustive switches that must then grow an arm.
|
|
181
|
+
*
|
|
182
|
+
* The per-kind semantics live on `ArgType` below, where a consumer
|
|
183
|
+
* hovering the exported name finds them.
|
|
184
|
+
*/
|
|
185
|
+
declare const ARG_TYPES: readonly ["string", "int", "truncating-int", "float", "bool", "T", "ordered", "list", "dict", "sized", "comparable", "stringifiable", "liftable", "callable", "collection", "index-key", "sliceable", "truthy", "reflective", "value", "serializable"];
|
|
119
186
|
/**
|
|
120
187
|
* Declared parameter type for a registered template function. Used by
|
|
121
188
|
* the no-silent-flatten guard to detect unsafe T-into-string flows.
|
|
@@ -123,13 +190,20 @@ declare class Defines {
|
|
|
123
190
|
* - "string" — must be a JS string. Non-string values raise
|
|
124
191
|
* TypeMismatchError. This is the **architectural commitment**: T
|
|
125
192
|
* never silently flattens into a string parameter.
|
|
126
|
-
* - "int" — validate-AND-parse integer carrier
|
|
127
|
-
* `number` and any `bigint`
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* `
|
|
132
|
-
* `
|
|
193
|
+
* - "int" — validate-AND-parse integer carrier: a Go `int`
|
|
194
|
+
* parameter. Accepts any safe-integer `number` and any `bigint`
|
|
195
|
+
* whose `Number()` is safe-integer-representable; rejects
|
|
196
|
+
* fractionals, `NaN`, `±Infinity`, and integers past 2^53, as
|
|
197
|
+
* Go refuses `repeat 2.7 "x"`. The gate normalizes `values[i]` to
|
|
198
|
+
* `Number(v)` so bodies see `number`. Used by every slot Go declares
|
|
199
|
+
* `int`: the built-in `slice`'s indices, `repeat`, `substr`, `trunc`,
|
|
200
|
+
* `until`, `seq`, `chunk`, `splitn`, `round`'s precision ….
|
|
201
|
+
* - "truncating-int" — the numeric half of sprig's `cast.ToInt64` read
|
|
202
|
+
* of an `interface{}` parameter. Accepts what "int" accepts plus any
|
|
203
|
+
* finite fractional `number`, which the gate truncates toward zero
|
|
204
|
+
* (`max 1.5 2.5` is `2` in Go); refuses the strings, bools and nil
|
|
205
|
+
* the cast would convert. Used by `add`, `add1`, `sub`, `mul`, `div`, `mod`,
|
|
206
|
+
* `max`, `min`, `biggest`, and sprig's list `slice`.
|
|
133
207
|
* - "float" — validate-AND-parse float carrier. Accepts any `number`
|
|
134
208
|
* (including `NaN`/`±Infinity` — legitimate IEEE-754 floats) and any
|
|
135
209
|
* `bigint` whose `Number()` is finite (overflow-to-Infinity rejected
|
|
@@ -155,9 +229,11 @@ declare class Defines {
|
|
|
155
229
|
* slots appear in the same call, all of them must share a kind, with
|
|
156
230
|
* `number`↔`bigint` bridged and `nil` acting as a wildcard. Object
|
|
157
231
|
* equality routes through `deepEqual` in `eq`/`ne` bodies.
|
|
158
|
-
* - "stringifiable" —
|
|
159
|
-
* `toString`
|
|
160
|
-
*
|
|
232
|
+
* - "stringifiable" — a value Go's `%v` can print: a string, nil, a
|
|
233
|
+
* scalar, a T the engine's `toString` flattens, an object with its own
|
|
234
|
+
* toString, a class instance (Go's struct), or a list/map of those; a
|
|
235
|
+
* Set, function or symbol has no text form. The matcher *probes* `formatV`;
|
|
236
|
+
* downstream func bodies call it again to actually print.
|
|
161
237
|
* - "callable" — `typeof v === "function"`.
|
|
162
238
|
* - "collection" — string | array | Map | plain object. The receiver
|
|
163
239
|
* shape `index` accepts. Sets and primitives are rejected. Nil is
|
|
@@ -187,7 +263,75 @@ declare class Defines {
|
|
|
187
263
|
* `"callable"`). The history for this decision lives in epic
|
|
188
264
|
* template-laws-3gt.
|
|
189
265
|
*/
|
|
190
|
-
type ArgType =
|
|
266
|
+
type ArgType = (typeof ARG_TYPES)[number];
|
|
267
|
+
/**
|
|
268
|
+
* How many arguments a func accepts, and how `argTypes` covers them.
|
|
269
|
+
*
|
|
270
|
+
* [LAW:types-are-the-program] Argument *count* used to live only in the
|
|
271
|
+
* JS signature, where the gate could not see it: `enforceArgTypes`
|
|
272
|
+
* iterated the supplied values, so a missing or surplus argument was
|
|
273
|
+
* not a state it could represent, let alone reject. Declaring arity
|
|
274
|
+
* alongside `argTypes` makes the count a fact the gate reads —
|
|
275
|
+
* `acceptedArgCount` projects this union into the counts a declaration
|
|
276
|
+
* admits and rejects the rest before the slot loop.
|
|
277
|
+
*
|
|
278
|
+
* [LAW:one-source-of-truth] No kind carries a count that `argTypes`
|
|
279
|
+
* already holds. `"exact"` means exactly `argTypes.length`, and
|
|
280
|
+
* `"variadic"` means at least `argTypes.length - 1` — which is Go's
|
|
281
|
+
* gate for a variadic signature, always, since its fixed parameters are
|
|
282
|
+
* every one but the last. A `minimum` field on either would be a second
|
|
283
|
+
* copy of a number the array carries, and the copy is what drifts:
|
|
284
|
+
* `minimum` survives here only on `"alternating"`, where `argTypes` is
|
|
285
|
+
* a cycle length rather than a parameter count and the two are
|
|
286
|
+
* genuinely unrelated.
|
|
287
|
+
*
|
|
288
|
+
* [LAW:one-type-per-behavior] The three kinds are exactly the three
|
|
289
|
+
* slot-lookup rules, so `makeSlotLookup` switches on this union and
|
|
290
|
+
* nothing else. Folding the former `argTypePattern` field in here is
|
|
291
|
+
* what makes "exact yet alternating" unrepresentable rather than merely
|
|
292
|
+
* unused.
|
|
293
|
+
*
|
|
294
|
+
* There is deliberately no `between`/optional-trailing kind: Go's own
|
|
295
|
+
* `text/template` and `sprig` have no notion of an optional parameter,
|
|
296
|
+
* so every signature is fixed-arity or variadic. That every declaration
|
|
297
|
+
* here matches the Go function it mirrors is not a claim — it is
|
|
298
|
+
* checked by `go-arity.test.ts` against `go-arity.fixture.json`, which
|
|
299
|
+
* `conformance/gen/arity` extracts from Go. Do not add a fourth kind
|
|
300
|
+
* without a Go signature that demands it.
|
|
301
|
+
*/
|
|
302
|
+
type Arity = /** Exactly `argTypes.length` arguments; each slot is declared once. */{
|
|
303
|
+
readonly kind: "exact";
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* At least `argTypes.length - 1` arguments — Go's own gate for a
|
|
307
|
+
* variadic signature, whose fixed parameters are every one but the
|
|
308
|
+
* last. The trailing `argTypes` entry is that last, repeating
|
|
309
|
+
* parameter, so every argument past the declared ones validates
|
|
310
|
+
* against `argTypes[argTypes.length - 1]`.
|
|
311
|
+
*
|
|
312
|
+
* Declare one slot per Go parameter, the repeating one last: `eq` is
|
|
313
|
+
* `func(reflect.Value, ...reflect.Value)`, so it declares two
|
|
314
|
+
* `"comparable"` slots and requires one. Collapsing those to a single
|
|
315
|
+
* slot would render the same verdicts today and quietly lose the
|
|
316
|
+
* minimum.
|
|
317
|
+
*/
|
|
318
|
+
| {
|
|
319
|
+
readonly kind: "variadic";
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* At least `minimum` arguments — the one kind that needs the number,
|
|
323
|
+
* because `argTypes` below is a cycle length, not a parameter count.
|
|
324
|
+
* With `argTypes` read as a *cycle*:
|
|
325
|
+
* the slot for argument `i` is `argTypes[i % argTypes.length]`. Used
|
|
326
|
+
* by `dict`'s `string, value, string, value, …` kv pairing — without
|
|
327
|
+
* it the gate cannot distinguish even-index keys (must be string)
|
|
328
|
+
* from odd-index values (anything), and the body would re-validate
|
|
329
|
+
* per key, splitting `[LAW:single-enforcer]` across two layers.
|
|
330
|
+
*/
|
|
331
|
+
| {
|
|
332
|
+
readonly kind: "alternating";
|
|
333
|
+
readonly minimum: number;
|
|
334
|
+
};
|
|
191
335
|
interface TemplateFunc {
|
|
192
336
|
/**
|
|
193
337
|
* The function body. Parameter types are *contravariant-bottom*
|
|
@@ -199,38 +343,57 @@ interface TemplateFunc {
|
|
|
199
343
|
* site (`enforceArgTypes`). The compile-time signature does not
|
|
200
344
|
* duplicate that gate — it stays out of the way so consumer
|
|
201
345
|
* implementations can declare the precise types they expect.
|
|
346
|
+
*
|
|
347
|
+
* The signature is *not* a source of arity: `fn.length` stops at the
|
|
348
|
+
* first rest parameter and lies about several registrations (`min`,
|
|
349
|
+
* `max`, `mul` and friends report 0 while Go requires 1). Arity comes
|
|
350
|
+
* from `arity`, never from here.
|
|
351
|
+
*
|
|
352
|
+
* Return `marked(value, ...tokens)` to mark the call; the template sees
|
|
353
|
+
* `value`, and the tokens reach `EngineConfig.emitted` / `decided`
|
|
354
|
+
* wherever the output depends on it.
|
|
202
355
|
*/
|
|
203
356
|
readonly fn: (...args: never[]) => unknown;
|
|
204
357
|
/**
|
|
205
358
|
* Declared positional parameter types. Required.
|
|
206
359
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* `Variadic`.
|
|
360
|
+
* How the slots cover the supplied arguments is `arity`'s job: an
|
|
361
|
+
* `"exact"` func declares one entry per parameter, a `"variadic"` one
|
|
362
|
+
* declares the repeating slot last, and an `"alternating"` one
|
|
363
|
+
* declares the cycle.
|
|
212
364
|
*
|
|
213
365
|
* The pipe-fed last argument is appended to the positional list
|
|
214
|
-
* before validation, so it is checked against the
|
|
366
|
+
* before validation, so it is checked against the slot its final
|
|
367
|
+
* position selects.
|
|
215
368
|
*/
|
|
216
369
|
readonly argTypes: readonly ArgType[];
|
|
217
370
|
readonly returnType?: ArgType;
|
|
218
371
|
/**
|
|
219
|
-
*
|
|
372
|
+
* Argument count. Required — a func whose arity is undeclared is a
|
|
373
|
+
* func the gate cannot check, and defaulting to a permissive value
|
|
374
|
+
* would hide exactly the registrations that most need the
|
|
375
|
+
* declaration.
|
|
220
376
|
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
* `
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
377
|
+
* Minimums mirror Go's *arity gate*, which is not always the same as
|
|
378
|
+
* the function body's own requirement; see `eq` and `dig`.
|
|
379
|
+
*/
|
|
380
|
+
readonly arity: Arity;
|
|
381
|
+
/**
|
|
382
|
+
* `true` when the body stores anything it was handed — in place in an
|
|
383
|
+
* argument, as sprig `set` and `unset` do, or in a closure or module
|
|
384
|
+
* variable a later call returns — or runs code it was handed, which may
|
|
385
|
+
* store (`call`). Omitted: it does neither, which is true of nearly
|
|
386
|
+
* every func.
|
|
230
387
|
*
|
|
231
|
-
*
|
|
388
|
+
* [LAW:types-are-the-program] Whether a call writes is a fact about the
|
|
389
|
+
* func, so it is declared rather than assumed of every call. Where a
|
|
390
|
+
* write lands is beyond what the engine can follow (an object read
|
|
391
|
+
* later, a fragment already emitted, the host's data for the next
|
|
392
|
+
* evaluation), so each call of a writing func reports its inputs'
|
|
393
|
+
* marks through `EngineConfig.decided` as it runs. A body that writes
|
|
394
|
+
* without declaring it reports late.
|
|
232
395
|
*/
|
|
233
|
-
readonly
|
|
396
|
+
readonly writes?: true;
|
|
234
397
|
}
|
|
235
398
|
type FuncMap = Record<string, TemplateFunc>;
|
|
236
399
|
/**
|
|
@@ -251,7 +414,10 @@ type FuncMap = Record<string, TemplateFunc>;
|
|
|
251
414
|
* indicates a scope-construction bug that should fail loud.
|
|
252
415
|
*/
|
|
253
416
|
type MissingKeyOption = "default" | "zero" | "error";
|
|
254
|
-
|
|
417
|
+
type EngineConfig<T> = EngineConfigFields<T> & ([T] extends [string] ? unknown : {
|
|
418
|
+
readonly isT: (value: unknown) => value is T;
|
|
419
|
+
});
|
|
420
|
+
interface EngineConfigFields<T> {
|
|
255
421
|
/** Convert a text literal (or string-returning function result) into T. */
|
|
256
422
|
readonly fromString: (s: string) => T;
|
|
257
423
|
/**
|
|
@@ -259,9 +425,9 @@ interface EngineConfig<T> {
|
|
|
259
425
|
*
|
|
260
426
|
* [LAW:single-enforcer] Dual of `fromString`: one place owns the
|
|
261
427
|
* string→T direction, this owns the T→string direction. Built-ins
|
|
262
|
-
* registered against the `"stringifiable"` ArgType call this
|
|
263
|
-
* they
|
|
264
|
-
* `
|
|
428
|
+
* registered against the `"stringifiable"` ArgType call this for each
|
|
429
|
+
* T they print, nested ones included; every non-T value prints as Go's
|
|
430
|
+
* `%v` and never reaches it.
|
|
265
431
|
*
|
|
266
432
|
* Default behaviour: passes through any value that is already a
|
|
267
433
|
* `typeof "string"` and throws `TypeMismatchError` for everything
|
|
@@ -277,12 +443,13 @@ interface EngineConfig<T> {
|
|
|
277
443
|
* Date's own String); at a call, a `"T"` ArgType slot accepts exactly
|
|
278
444
|
* what this says.
|
|
279
445
|
*
|
|
280
|
-
* [LAW:single-enforcer] The one predicate
|
|
281
|
-
*
|
|
282
|
-
* it
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
446
|
+
* [LAW:single-enforcer] The one predicate for what is a T. At the output
|
|
447
|
+
* stream a string, number, boolean or nil is lifted through `fromString`
|
|
448
|
+
* before it is asked, so it decides only for structured values.
|
|
449
|
+
* Default: a string — the T the default `fromString`/`toString` pair
|
|
450
|
+
* supports — so a plain object prints `map[k:v …]` as Go's `%v` does.
|
|
451
|
+
* Required by the type whenever T is not a string, e.g.
|
|
452
|
+
* `isT: (v) => v instanceof RichText`.
|
|
286
453
|
*/
|
|
287
454
|
readonly isT?: (value: unknown) => value is T;
|
|
288
455
|
/**
|
|
@@ -330,6 +497,27 @@ interface EngineConfig<T> {
|
|
|
330
497
|
readonly delims?: Delims;
|
|
331
498
|
/** Optional registry of named functions usable in pipelines. */
|
|
332
499
|
readonly funcs?: FuncMap;
|
|
500
|
+
/**
|
|
501
|
+
* Every `T` the template emits passes through here with the marks it
|
|
502
|
+
* depends on (see `marked`), and the return is what reaches the output.
|
|
503
|
+
* The marks are those of every value the emitting action read and of
|
|
504
|
+
* every `if`/`with`/`range` arm it sits in; a mark is reported early,
|
|
505
|
+
* never late, and a mark bound somewhere nobody reads is not reported.
|
|
506
|
+
* Called for every emission, an empty set included. Default: returns
|
|
507
|
+
* `value` unchanged.
|
|
508
|
+
*/
|
|
509
|
+
readonly emitted?: (value: T, marks: ReadonlySet<unknown>) => T;
|
|
510
|
+
/**
|
|
511
|
+
* Called once each time an `if`/`with`/`range` pipe is evaluated,
|
|
512
|
+
* before either arm runs — so a decision whose taken arm emits nothing
|
|
513
|
+
* (or which has no arm to take) still says what it depended on. Also
|
|
514
|
+
* called for each call of a func that declares `writes` (the output may
|
|
515
|
+
* show that write later with no cell to say it on), and for each action
|
|
516
|
+
* or control pipe that throws. Every call carries the marks of the
|
|
517
|
+
* values read and of every `if`/`with`/`range` arm it sits in.
|
|
518
|
+
* Default: does nothing.
|
|
519
|
+
*/
|
|
520
|
+
readonly decided?: (marks: ReadonlySet<unknown>) => void;
|
|
333
521
|
}
|
|
334
522
|
interface ReferencedCall {
|
|
335
523
|
/** The function name at the head of the command. */
|
|
@@ -372,6 +560,7 @@ type ReferencedArg = {
|
|
|
372
560
|
declare class Template<T> {
|
|
373
561
|
readonly source: string;
|
|
374
562
|
private readonly _evaluate;
|
|
563
|
+
private readonly _evaluateDefine;
|
|
375
564
|
private readonly _defines;
|
|
376
565
|
private readonly _referencedFunctions;
|
|
377
566
|
private readonly _referencedCalls;
|
|
@@ -387,6 +576,13 @@ declare class Template<T> {
|
|
|
387
576
|
*/
|
|
388
577
|
defines(): Defines;
|
|
389
578
|
evaluate(scope: unknown): T[];
|
|
579
|
+
/**
|
|
580
|
+
* Render one named sub-template — any `{{ define }}` in {@link defines}, its
|
|
581
|
+
* own or inherited — with `scope` as its dot and `$`, as Go's
|
|
582
|
+
* `ExecuteTemplate` does. The output is the same `T[]` a whole-template
|
|
583
|
+
* {@link evaluate} produces, through the same `emitted` / `decided` hooks.
|
|
584
|
+
*/
|
|
585
|
+
evaluateDefine(name: string, scope: unknown): T[];
|
|
390
586
|
/**
|
|
391
587
|
* The FuncMap function names this template references — every identifier that
|
|
392
588
|
* names a function in this parse: the template body and its own `{{ define }}`
|
|
@@ -432,6 +628,8 @@ declare class Engine<T> {
|
|
|
432
628
|
private readonly funcs;
|
|
433
629
|
private readonly missingKey;
|
|
434
630
|
private readonly delims;
|
|
631
|
+
private readonly emitted;
|
|
632
|
+
private readonly decided;
|
|
435
633
|
constructor(config: EngineConfig<T>);
|
|
436
634
|
/**
|
|
437
635
|
* Parse a template source into a reusable Template handle.
|
|
@@ -462,18 +660,60 @@ declare class Engine<T> {
|
|
|
462
660
|
private evalWith;
|
|
463
661
|
private evalRange;
|
|
464
662
|
private evalTemplateInvoke;
|
|
663
|
+
private definedEntry;
|
|
664
|
+
private renderDefine;
|
|
665
|
+
private include;
|
|
465
666
|
private evalBlock;
|
|
466
|
-
private
|
|
667
|
+
private decide;
|
|
668
|
+
private readonly assigned;
|
|
669
|
+
private assignedIn;
|
|
670
|
+
private invocationDot;
|
|
671
|
+
private read;
|
|
467
672
|
private evalPipe;
|
|
468
|
-
private
|
|
673
|
+
private bind;
|
|
469
674
|
private evalCommand;
|
|
675
|
+
private invoke;
|
|
470
676
|
private evalPrimary;
|
|
677
|
+
private evalOperand;
|
|
471
678
|
private resolveFieldChain;
|
|
472
679
|
private resolveVariable;
|
|
473
|
-
private
|
|
680
|
+
private readDot;
|
|
681
|
+
private lift;
|
|
474
682
|
}
|
|
475
683
|
declare function createEngine<T>(config: EngineConfig<T>): Engine<T>;
|
|
476
684
|
//#endregion
|
|
685
|
+
//#region src/evaluator/include.d.ts
|
|
686
|
+
/** Helm's `include(name string, data interface{}) (string, error)`. */
|
|
687
|
+
declare const include: TemplateFunc;
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/evaluator/marks.d.ts
|
|
690
|
+
/**
|
|
691
|
+
* A func's return value together with the marks of the call that
|
|
692
|
+
* produced it. Opaque: build one with {@link marked}; only the engine
|
|
693
|
+
* reads it.
|
|
694
|
+
*/
|
|
695
|
+
declare class Marked {
|
|
696
|
+
#private;
|
|
697
|
+
private constructor();
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Return this from a registered func to mark the call: every emission
|
|
701
|
+
* and control decision that depends on the call's result reports
|
|
702
|
+
* `marks`. The template sees `value`, exactly as if it had been returned
|
|
703
|
+
* directly.
|
|
704
|
+
*/
|
|
705
|
+
declare function marked(value: unknown, ...marks: unknown[]): Marked;
|
|
706
|
+
/**
|
|
707
|
+
* A func's return read apart: its value and the marks it carries (none
|
|
708
|
+
* for a plain value). For JS code that builds on a marking func outside a
|
|
709
|
+
* template — `const { value, marks } = unmarked(tween.fn(...))`, then
|
|
710
|
+
* `return marked(Math.min(1, value as number), ...marks)`.
|
|
711
|
+
*/
|
|
712
|
+
declare function unmarked(result: unknown): {
|
|
713
|
+
readonly value: unknown;
|
|
714
|
+
readonly marks: readonly unknown[];
|
|
715
|
+
};
|
|
716
|
+
//#endregion
|
|
477
717
|
//#region src/sprig/conversions/index.d.ts
|
|
478
718
|
declare function sprigConversions(): FuncMap;
|
|
479
719
|
//#endregion
|
|
@@ -556,5 +796,5 @@ declare function sprigStrings(): FuncMap;
|
|
|
556
796
|
//#region src/sprig/types/index.d.ts
|
|
557
797
|
declare function sprigTypes(): FuncMap;
|
|
558
798
|
//#endregion
|
|
559
|
-
export { type ArgType, Defines, type Delims, Engine, type EngineConfig, type ErrorKind, EvalError, FailError, type FuncMap, FuncNotFoundError, MissingFieldError, type MissingKeyOption, ParseError, type ReferencedArg, type ReferencedCall, type ReferencedLiteral, Template, TemplateError, type TemplateFunc, TypeMismatchError, createEngine, sprigConversions, sprigDatetime, sprigDefaults, sprigDicts, sprigFlow, sprigHash, sprigLists, sprigMath, sprigRandom, sprigRegex, sprigSemver, sprigStrings, sprigTypes, staticDictEntries };
|
|
799
|
+
export { type ArgCount, ArgCountError, type ArgType, type Arity, Defines, type Delims, Engine, type EngineConfig, type ErrorKind, EvalError, FailError, type FuncMap, FuncNotFoundError, type Marked, MissingFieldError, type MissingKeyOption, NotIntegerError, ParseError, type ReferencedArg, type ReferencedCall, type ReferencedLiteral, Template, TemplateError, type TemplateFunc, TypeMismatchError, createEngine, include, marked, sprigConversions, sprigDatetime, sprigDefaults, sprigDicts, sprigFlow, sprigHash, sprigLists, sprigMath, sprigRandom, sprigRegex, sprigSemver, sprigStrings, sprigTypes, staticDictEntries, unmarked };
|
|
560
800
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/parser/pos.ts","../src/errors.ts","../src/parser/lexer.ts","../src/parser/parser.ts","../src/evaluator/evaluator.ts","../src/sprig/conversions/index.ts","../src/sprig/datetime/_clock.ts","../src/sprig/datetime/index.ts","../src/sprig/defaults/index.ts","../src/sprig/dicts/dict.ts","../src/sprig/dicts/index.ts","../src/sprig/flow/index.ts","../src/sprig/hash/index.ts","../src/sprig/lists/index.ts","../src/sprig/math/index.ts","../src/sprig/random/index.ts","../src/sprig/regex/index.ts","../src/sprig/semver/index.ts","../src/sprig/strings/index.ts","../src/sprig/types/index.ts"],"mappings":";;AAUA;;;;;;;;;UAAiB,GAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/parser/pos.ts","../src/errors.ts","../src/parser/lexer.ts","../src/parser/parser.ts","../src/evaluator/evaluator.ts","../src/evaluator/include.ts","../src/evaluator/marks.ts","../src/sprig/conversions/index.ts","../src/sprig/datetime/_clock.ts","../src/sprig/datetime/index.ts","../src/sprig/defaults/index.ts","../src/sprig/dicts/dict.ts","../src/sprig/dicts/index.ts","../src/sprig/flow/index.ts","../src/sprig/hash/index.ts","../src/sprig/lists/index.ts","../src/sprig/math/index.ts","../src/sprig/random/index.ts","../src/sprig/regex/index.ts","../src/sprig/semver/index.ts","../src/sprig/strings/index.ts","../src/sprig/types/index.ts"],"mappings":";;AAUA;;;;;;;;;UAAiB,GAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;AAAA;;;KCUC,SAAA;AAAA,UASK,oBAAA;EAAA,SACN,MAAA;EASgB;EAAA,SAPhB,KAAA;AAAA;AAAA,cAOE,aAAA,SAAsB,KAAA;EAAA,SACf,IAAA;EAAA,SACT,IAAA,EAAM,SAAA;EAAA,SACN,GAAA,EAAK,GAAA;EAAA,SACL,MAAA;cAEG,OAAA,UAAiB,GAAA,EAAK,GAAA,EAAK,GAAA,GAAK,oBAAA;EANX;EAAA,IAa7B,aAAA,CAAA;EAIK,QAAA,CAAA;AAAA;AAAA,UAWM,iBAAA,SAA0B,oBAAA;EAAA,SAChC,QAAA;EAAA,SACA,KAAA;AAAA;AAAA,cAGE,UAAA,SAAmB,aAAA;EAAA,SACZ,IAAA;EAAA,SACA,IAAA,EAAM,SAAA;EAAA,SACf,QAAA;EAAA,SACA,KAAA;cAEG,OAAA,UAAiB,GAAA,EAAK,GAAA,EAAK,GAAA,GAAK,iBAAA;AAAA;AAAA,cAWjC,SAAA,SAAkB,aAAA;EAAA,SACX,IAAA;EAAA,SACA,IAAA,EAAM,SAAA;AAAA;;;;;;cAQb,iBAAA,SAA0B,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