@telorun/sdk 0.72.0 → 0.74.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/dist/bigint-json.d.ts +21 -0
- package/dist/bigint-json.d.ts.map +1 -1
- package/dist/bigint-json.js +28 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/resource-context.d.ts +6 -0
- package/dist/resource-context.d.ts.map +1 -1
- package/dist/type-schema-ref.d.ts +11 -0
- package/dist/type-schema-ref.d.ts.map +1 -1
- package/dist/type-schema-ref.js +15 -0
- package/dist/value-type.d.ts +166 -0
- package/dist/value-type.d.ts.map +1 -0
- package/dist/value-type.js +317 -0
- package/dist/value-types/entries/index.d.ts +3 -0
- package/dist/value-types/entries/index.d.ts.map +1 -0
- package/dist/value-types/entries/index.js +13 -0
- package/dist/value-types/entries/telo-bytes.json +7 -0
- package/dist/value-types/entries/telo-stream.json +15 -0
- package/dist/value-types/entries/telo-tcp-port.json +7 -0
- package/dist/value-types/entries/telo-udp-port.json +6 -0
- package/package.json +1 -1
- package/src/bigint-json.ts +27 -0
- package/src/index.ts +1 -0
- package/src/resource-context.ts +6 -0
- package/src/type-schema-ref.ts +16 -0
- package/src/value-type.ts +417 -0
- package/src/value-types/entries/index.ts +14 -0
- package/src/value-types/entries/telo-bytes.json +7 -0
- package/src/value-types/entries/telo-stream.json +15 -0
- package/src/value-types/entries/telo-tcp-port.json +7 -0
- package/src/value-types/entries/telo-udp-port.json +6 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `x-telo-type` — the one annotation that says what the value at a slot IS,
|
|
3
|
+
* beyond what JSON Schema's `type` vocabulary can express, and the single
|
|
4
|
+
* accessor every surface reads it through (the `ref-slot.ts` precedent).
|
|
5
|
+
*
|
|
6
|
+
* It replaced three keywords that answered one question differently: a nominal
|
|
7
|
+
* brand from a closed kernel table (`x-telo-type: TcpPort`), raw bytes
|
|
8
|
+
* (`x-telo-binary: true`), and a live handle (`x-telo-stream: true`). They
|
|
9
|
+
* differed in POSTURE toward the JSON Schema layer — refine, replace, exempt —
|
|
10
|
+
* not in kind, so each spelled as its own keyword meant a fourth cost eleven
|
|
11
|
+
* files across four packages, and left three defects: a typo'd brand degraded
|
|
12
|
+
* silently, bytes had no CEL identity, and a module string-matched the keyword
|
|
13
|
+
* because there was nothing on its surface to read.
|
|
14
|
+
*
|
|
15
|
+
* THE VOCABULARY IS DATA; THE BINDING TO A LANGUAGE IS NOT. Entries live at
|
|
16
|
+
* `sdk/value-types/*.json` (see the README there) and are copied in by the SDK's
|
|
17
|
+
* `prepare`. Every runtime that hosts Telo reads the same files — the Rust half
|
|
18
|
+
* types an `!include-bytes` slot from them in a kernel with no CEL engine — so
|
|
19
|
+
* an entry declares a symbolic `binding`, never a constructor name, and each
|
|
20
|
+
* runtime carries its own table mapping that key to its own identity.
|
|
21
|
+
*
|
|
22
|
+
* THE REGISTRY IS IN THE SDK because it is dependency-free and Node-built-in-free
|
|
23
|
+
* (so a browser-side analyzer can read it), because `Stream` already lives here,
|
|
24
|
+
* and because it is the only placement a module controller can reach: a module
|
|
25
|
+
* may import `@telorun/sdk` and nothing else.
|
|
26
|
+
*/
|
|
27
|
+
import { Stream } from "./stream.js";
|
|
28
|
+
import { VALUE_TYPE_ENTRY_FILES } from "./value-types/entries/index.js";
|
|
29
|
+
export const X_TELO_TYPE = "x-telo-type";
|
|
30
|
+
/**
|
|
31
|
+
* Node's binding table — the ONLY per-language artifact in the whole mechanism.
|
|
32
|
+
*
|
|
33
|
+
* Keyed by an entry's symbolic `binding`, never by its name, so a runtime that
|
|
34
|
+
* represents two entries the same way says so once and a rename of a type does
|
|
35
|
+
* not touch any table.
|
|
36
|
+
*/
|
|
37
|
+
export const VALUE_TYPE_BINDINGS = {
|
|
38
|
+
bytes: { constructor: Uint8Array, celType: "bytes", placeholder: () => new Uint8Array() },
|
|
39
|
+
stream: { constructor: Stream, celType: "Stream" },
|
|
40
|
+
};
|
|
41
|
+
/** The CEL type a `json` representation's declared base carries. A brand's own
|
|
42
|
+
* name is the CEL type; this is what it degrades to when the consuming slot
|
|
43
|
+
* declares no brand of its own (gradual typing). */
|
|
44
|
+
const CEL_TYPE_FOR_BASE = {
|
|
45
|
+
integer: "int",
|
|
46
|
+
number: "double",
|
|
47
|
+
string: "string",
|
|
48
|
+
boolean: "bool",
|
|
49
|
+
array: "list",
|
|
50
|
+
object: "map",
|
|
51
|
+
};
|
|
52
|
+
class ValueTypeEntryError extends Error {
|
|
53
|
+
constructor(file, detail) {
|
|
54
|
+
super(`Invalid value-type entry '${file}': ${detail}`);
|
|
55
|
+
this.name = "ValueTypeEntryError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const ENTRY_KEYS = [
|
|
59
|
+
"name",
|
|
60
|
+
"representation",
|
|
61
|
+
"base",
|
|
62
|
+
"binding",
|
|
63
|
+
"live",
|
|
64
|
+
"parameters",
|
|
65
|
+
"description",
|
|
66
|
+
"$comment",
|
|
67
|
+
];
|
|
68
|
+
function isPlainObject(value) {
|
|
69
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
70
|
+
}
|
|
71
|
+
function requireString(file, node, key) {
|
|
72
|
+
const value = node[key];
|
|
73
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
74
|
+
throw new ValueTypeEntryError(file, `'${key}' must be a non-empty string`);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function readParameters(file, raw) {
|
|
79
|
+
if (raw === undefined)
|
|
80
|
+
return [];
|
|
81
|
+
if (!Array.isArray(raw))
|
|
82
|
+
throw new ValueTypeEntryError(file, "'parameters' must be a sequence");
|
|
83
|
+
const params = raw.map((entry, i) => {
|
|
84
|
+
if (!isPlainObject(entry)) {
|
|
85
|
+
throw new ValueTypeEntryError(file, `parameters[${i}] must be a mapping`);
|
|
86
|
+
}
|
|
87
|
+
for (const key of Object.keys(entry)) {
|
|
88
|
+
if (key !== "name" && key !== "description" && key !== "element") {
|
|
89
|
+
throw new ValueTypeEntryError(file, `parameters[${i}] has no key '${key}'`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (entry.element !== undefined && typeof entry.element !== "boolean") {
|
|
93
|
+
throw new ValueTypeEntryError(file, `parameters[${i}].element must be a boolean when present`);
|
|
94
|
+
}
|
|
95
|
+
const name = requireString(file, entry, "name");
|
|
96
|
+
return {
|
|
97
|
+
name,
|
|
98
|
+
...(entry.element === true ? { element: true } : {}),
|
|
99
|
+
...(entry.description === undefined
|
|
100
|
+
? {}
|
|
101
|
+
: { description: requireString(file, entry, "description") }),
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
// Two element parameters would make "the element of this value" ambiguous, and
|
|
105
|
+
// the reader is the only place that can refuse it — every consumer takes the
|
|
106
|
+
// first match and would silently pick one.
|
|
107
|
+
if (params.filter((p) => p.element).length > 1) {
|
|
108
|
+
throw new ValueTypeEntryError(file, "at most one parameter may declare 'element'");
|
|
109
|
+
}
|
|
110
|
+
return params;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Read one entry file's parsed data.
|
|
114
|
+
*
|
|
115
|
+
* Reading is STRICT and the vocabulary is closed at every level. A malformed or
|
|
116
|
+
* typo'd entry is an authoring mistake whose only other outcome is a type that
|
|
117
|
+
* quietly is not in the vocabulary — which reads to an author as "unknown name",
|
|
118
|
+
* pointing at their manifest instead of at the entry.
|
|
119
|
+
*/
|
|
120
|
+
export function parseValueTypeEntry(file, data) {
|
|
121
|
+
if (!isPlainObject(data))
|
|
122
|
+
throw new ValueTypeEntryError(file, "an entry must be a mapping");
|
|
123
|
+
for (const key of Object.keys(data)) {
|
|
124
|
+
if (!ENTRY_KEYS.includes(key)) {
|
|
125
|
+
throw new ValueTypeEntryError(file, `an entry has no key '${key}'. Known keys: ${ENTRY_KEYS.join(", ")}.`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const name = requireString(file, data, "name");
|
|
129
|
+
if (!name.startsWith("Telo.")) {
|
|
130
|
+
throw new ValueTypeEntryError(file, `'name' must be Telo.-qualified — a representation is kernel-owned and cannot be module-defined`);
|
|
131
|
+
}
|
|
132
|
+
const representation = requireString(file, data, "representation");
|
|
133
|
+
if (representation !== "json" && representation !== "instance") {
|
|
134
|
+
throw new ValueTypeEntryError(file, `'representation' must be 'json' or 'instance'`);
|
|
135
|
+
}
|
|
136
|
+
if (data.live !== undefined && typeof data.live !== "boolean") {
|
|
137
|
+
throw new ValueTypeEntryError(file, "'live' must be a boolean when present");
|
|
138
|
+
}
|
|
139
|
+
// The two representations take disjoint parameters, and mixing them is a
|
|
140
|
+
// statement with no meaning: a `json` value has no constructor to assert, and
|
|
141
|
+
// an `instance` has no JSON base to refine.
|
|
142
|
+
if (representation === "json") {
|
|
143
|
+
if (data.binding !== undefined) {
|
|
144
|
+
throw new ValueTypeEntryError(file, "a 'json' representation takes no 'binding'");
|
|
145
|
+
}
|
|
146
|
+
const base = requireString(file, data, "base");
|
|
147
|
+
if (!(base in CEL_TYPE_FOR_BASE)) {
|
|
148
|
+
throw new ValueTypeEntryError(file, `'base' '${base}' is not a JSON Schema type (${Object.keys(CEL_TYPE_FOR_BASE).join(", ")})`);
|
|
149
|
+
}
|
|
150
|
+
if (data.live === true) {
|
|
151
|
+
throw new ValueTypeEntryError(file, "a 'json' representation cannot be 'live' — it is data");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (data.base !== undefined) {
|
|
156
|
+
throw new ValueTypeEntryError(file, "an 'instance' representation takes no 'base'");
|
|
157
|
+
}
|
|
158
|
+
requireString(file, data, "binding");
|
|
159
|
+
}
|
|
160
|
+
const entry = {
|
|
161
|
+
name,
|
|
162
|
+
representation,
|
|
163
|
+
...(representation === "json" ? { base: data.base } : { binding: data.binding }),
|
|
164
|
+
live: data.live === true,
|
|
165
|
+
parameters: readParameters(file, data.parameters),
|
|
166
|
+
description: requireString(file, data, "description"),
|
|
167
|
+
};
|
|
168
|
+
return entry;
|
|
169
|
+
}
|
|
170
|
+
function buildRegistry() {
|
|
171
|
+
const registry = new Map();
|
|
172
|
+
for (const [file, data] of VALUE_TYPE_ENTRY_FILES) {
|
|
173
|
+
const entry = parseValueTypeEntry(file, data);
|
|
174
|
+
if (registry.has(entry.name)) {
|
|
175
|
+
throw new ValueTypeEntryError(file, `'${entry.name}' is already declared by another entry`);
|
|
176
|
+
}
|
|
177
|
+
// A binding with no row in THIS host's table is a hard error, never a
|
|
178
|
+
// skipped assertion: a type that cannot be asserted would silently exempt
|
|
179
|
+
// every slot declaring it, converting a contract into a hole. The same class
|
|
180
|
+
// of failure as an unrecognized `use` token degrading to the legacy reading.
|
|
181
|
+
if (entry.binding !== undefined && !(entry.binding in VALUE_TYPE_BINDINGS)) {
|
|
182
|
+
throw new ValueTypeEntryError(file, `binding '${entry.binding}' has no row in this runtime's table — a value type ` +
|
|
183
|
+
`whose assertion cannot be produced would silently exempt every slot that declares it`);
|
|
184
|
+
}
|
|
185
|
+
registry.set(entry.name, entry);
|
|
186
|
+
}
|
|
187
|
+
// Defence in depth against the packaging mistake, because the failure it
|
|
188
|
+
// produces is indistinguishable from an author's typo: every `x-telo-type`
|
|
189
|
+
// becomes an unknown name, reported against manifests that are correct. The
|
|
190
|
+
// build script refuses a missing source directory; this refuses the state that
|
|
191
|
+
// would reach a user if some other path ever produced it.
|
|
192
|
+
if (registry.size === 0) {
|
|
193
|
+
throw new Error("The value-type vocabulary is empty. `sdk/value-types/*.json` did not reach this " +
|
|
194
|
+
"build — check the file allowlist of whatever packaged it. Continuing would report " +
|
|
195
|
+
"every declared value type as an unknown name.");
|
|
196
|
+
}
|
|
197
|
+
return registry;
|
|
198
|
+
}
|
|
199
|
+
/** Every declared value type, keyed by its `Telo.`-qualified name. */
|
|
200
|
+
export const VALUE_TYPES = buildRegistry();
|
|
201
|
+
/** The declared names, in entry order — what `telo cel types` and the generated
|
|
202
|
+
* docs section enumerate. */
|
|
203
|
+
export function valueTypeNames() {
|
|
204
|
+
return [...VALUE_TYPES.keys()];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Read the annotation off a schema node.
|
|
208
|
+
*
|
|
209
|
+
* Two spellings, one meaning: a bare name (`x-telo-type: Telo.Bytes`) and the
|
|
210
|
+
* object form carrying arguments (`{ name: Telo.Stream, of: … }`). Returns
|
|
211
|
+
* undefined when the node carries no annotation at all — an unknown NAME still
|
|
212
|
+
* returns a slot, with `entry` undefined, because silently reading it as "no
|
|
213
|
+
* value type" is the degrade this annotation replaced.
|
|
214
|
+
*/
|
|
215
|
+
export function readValueTypeSlot(schema) {
|
|
216
|
+
if (!isPlainObject(schema))
|
|
217
|
+
return undefined;
|
|
218
|
+
const raw = schema[X_TELO_TYPE];
|
|
219
|
+
if (raw === undefined)
|
|
220
|
+
return undefined;
|
|
221
|
+
if (typeof raw === "string") {
|
|
222
|
+
return { name: raw, entry: VALUE_TYPES.get(raw), args: {} };
|
|
223
|
+
}
|
|
224
|
+
if (isPlainObject(raw)) {
|
|
225
|
+
const name = typeof raw.name === "string" ? raw.name : "";
|
|
226
|
+
const args = {};
|
|
227
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
228
|
+
if (key === "name")
|
|
229
|
+
continue;
|
|
230
|
+
// A bare NAME as an argument is sugar for a schema node carrying only that
|
|
231
|
+
// annotation, so `of: Telo.Bytes` and `of: { x-telo-type: Telo.Bytes }`
|
|
232
|
+
// are one thing. Normalized HERE, in the single reader, so no consumer
|
|
233
|
+
// re-derives it — a comparator that saw the string form would compare a
|
|
234
|
+
// string against a schema and quietly conclude nothing.
|
|
235
|
+
args[key] = typeof value === "string" ? { [X_TELO_TYPE]: value } : value;
|
|
236
|
+
}
|
|
237
|
+
return { name, entry: VALUE_TYPES.get(name), args };
|
|
238
|
+
}
|
|
239
|
+
return { name: "", entry: undefined, args: {} };
|
|
240
|
+
}
|
|
241
|
+
/** The entry a schema node declares, or undefined. The common read. */
|
|
242
|
+
export function valueTypeOf(schema) {
|
|
243
|
+
return readValueTypeSlot(schema)?.entry;
|
|
244
|
+
}
|
|
245
|
+
/** True when this node declares a value type at all (known or not). */
|
|
246
|
+
export function isValueTypeSlot(schema) {
|
|
247
|
+
return readValueTypeSlot(schema) !== undefined;
|
|
248
|
+
}
|
|
249
|
+
/** True when the node declares a `live` type, so its value is exempt from
|
|
250
|
+
* validation — never traversed, never asserted. Typing is unaffected. */
|
|
251
|
+
export function isLiveSlot(schema) {
|
|
252
|
+
return valueTypeOf(schema)?.live === true;
|
|
253
|
+
}
|
|
254
|
+
/** True when the node declares a type represented as a runtime instance —
|
|
255
|
+
* the values no manifest literal can ever be. */
|
|
256
|
+
export function isInstanceSlot(schema) {
|
|
257
|
+
return valueTypeOf(schema)?.representation === "instance";
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The schema of what iterating a value at this slot yields, or undefined when
|
|
261
|
+
* the slot declares no value type, or one with no element parameter.
|
|
262
|
+
*
|
|
263
|
+
* The whole point of reading it from the entry is that no consumer names a type:
|
|
264
|
+
* a future iterable value type is covered by declaring `element` on its own
|
|
265
|
+
* parameter, with nothing to change here or in the analyzer. An element
|
|
266
|
+
* parameter left unsupplied means *any*, exactly as every other omitted argument
|
|
267
|
+
* does, so an unparameterized use degrades to permissive rather than to nothing.
|
|
268
|
+
*/
|
|
269
|
+
export function elementSchemaOf(schema) {
|
|
270
|
+
const slot = readValueTypeSlot(schema);
|
|
271
|
+
const parameter = slot?.entry?.parameters.find((p) => p.element);
|
|
272
|
+
if (!parameter)
|
|
273
|
+
return undefined;
|
|
274
|
+
return slot.args[parameter.name] ?? {};
|
|
275
|
+
}
|
|
276
|
+
/** The binding row for a schema node's declared type, or undefined when it
|
|
277
|
+
* declares none / declares a `json` one. */
|
|
278
|
+
export function bindingOf(schema) {
|
|
279
|
+
const binding = valueTypeOf(schema)?.binding;
|
|
280
|
+
return binding === undefined ? undefined : VALUE_TYPE_BINDINGS[binding];
|
|
281
|
+
}
|
|
282
|
+
/** The stand-in for a CEL leaf at this slot, or undefined when the slot declares
|
|
283
|
+
* no instance type (ordinary JSON, so the schema's own shape decides) or a live
|
|
284
|
+
* one (nothing validates it, so nothing has to satisfy anything). */
|
|
285
|
+
export function valueTypePlaceholder(schema) {
|
|
286
|
+
return bindingOf(schema)?.placeholder?.();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The CEL type a value at this slot carries.
|
|
290
|
+
*
|
|
291
|
+
* A `json` representation carries its own NAME as a nominal brand — which is the
|
|
292
|
+
* whole point of one, since a `Telo.TcpPort` and a `Telo.UdpPort` are structurally
|
|
293
|
+
* identical. An `instance` carries whatever its binding says.
|
|
294
|
+
*/
|
|
295
|
+
export function celTypeOfValueType(entry) {
|
|
296
|
+
if (entry.representation === "json")
|
|
297
|
+
return entry.name;
|
|
298
|
+
const binding = VALUE_TYPE_BINDINGS[entry.binding];
|
|
299
|
+
return binding.celType;
|
|
300
|
+
}
|
|
301
|
+
/** The CEL type a brand degrades to where the consuming slot declares none —
|
|
302
|
+
* gradual typing, so a `Telo.TcpPort` flows freely into a plain integer field.
|
|
303
|
+
* Undefined for an `instance`, which has no base to fall back to. */
|
|
304
|
+
export function celBaseOfValueType(entry) {
|
|
305
|
+
return entry.representation === "json" ? CEL_TYPE_FOR_BASE[entry.base] : undefined;
|
|
306
|
+
}
|
|
307
|
+
/** Every `json` representation's CEL brand → the base type it refines. The
|
|
308
|
+
* gradual-typing table, derived rather than hand-written. */
|
|
309
|
+
export function valueBrandBases() {
|
|
310
|
+
const out = {};
|
|
311
|
+
for (const entry of VALUE_TYPES.values()) {
|
|
312
|
+
const base = celBaseOfValueType(entry);
|
|
313
|
+
if (base !== undefined)
|
|
314
|
+
out[entry.name] = base;
|
|
315
|
+
}
|
|
316
|
+
return out;
|
|
317
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/value-types/entries/index.ts"],"names":[],"mappings":"AAOA,yEAAyE;AACzE,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAKxF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// GENERATED by scripts/copy-value-type-entries.mjs — do not edit, and do not commit.
|
|
2
|
+
// Source: sdk/value-types/*.json (lexically ordered).
|
|
3
|
+
import e0 from "./telo-bytes.json" with { type: "json" };
|
|
4
|
+
import e1 from "./telo-stream.json" with { type: "json" };
|
|
5
|
+
import e2 from "./telo-tcp-port.json" with { type: "json" };
|
|
6
|
+
import e3 from "./telo-udp-port.json" with { type: "json" };
|
|
7
|
+
/** Every value-type entry file, in the order the registry reads them. */
|
|
8
|
+
export const VALUE_TYPE_ENTRY_FILES = [
|
|
9
|
+
["telo-bytes.json", e0],
|
|
10
|
+
["telo-stream.json", e1],
|
|
11
|
+
["telo-tcp-port.json", e2],
|
|
12
|
+
["telo-udp-port.json", e3],
|
|
13
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Bytes are not expressible in JSON Schema's type vocabulary. `type: object` is satisfied by every object, so a mistyped literal reached the controller instead of failing check; `type: binary` is not an option, since a validator refuses to COMPILE an unknown type and a published telo.yaml would stop being JSON Schema for the hub, the editor and every third-party reader. Declaring the representation instead is what makes the check fall out: no YAML literal is ever a byte buffer, so a literal at a byte slot is rejected statically and a value arriving by reference passes.",
|
|
3
|
+
"name": "Telo.Bytes",
|
|
4
|
+
"representation": "instance",
|
|
5
|
+
"binding": "bytes",
|
|
6
|
+
"description": "Raw bytes. Never authorable inline — a byte slot is filled by reference (an `!include-bytes` embed, a resource output, a CEL expression), and the runtime asserts the value really is a byte buffer."
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "`live` is what separates a stream from bytes: consuming it has effects, so it is EXEMPT from validation rather than asserted — iterating a stream to check its elements is precisely what the exemption forbids. The exemption is from VALIDATION, never from TYPING: `of` still travels through every schema-typing walk, because that is where the argument check reads it.",
|
|
3
|
+
"name": "Telo.Stream",
|
|
4
|
+
"representation": "instance",
|
|
5
|
+
"binding": "stream",
|
|
6
|
+
"live": true,
|
|
7
|
+
"parameters": [
|
|
8
|
+
{
|
|
9
|
+
"name": "of",
|
|
10
|
+
"element": true,
|
|
11
|
+
"description": "The element the stream yields. Any schema node — an inline shape, a value type, a `!ref` to a named shape, or another parameterized type. Omitted means any element."
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"description": "A live handle over a sequence of values, consumed by reading. Its elements are never buffered or validated, and member access past it is rejected — a consumer iterates it instead."
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "A `json` representation adds nominal identity to a value the declared schema already validates. A TcpPort and a UdpPort are both integers, so nothing structural tells them apart — the name is the whole difference, and it is what makes wiring one into the other's slot a static error.",
|
|
3
|
+
"name": "Telo.TcpPort",
|
|
4
|
+
"representation": "json",
|
|
5
|
+
"base": "integer",
|
|
6
|
+
"description": "A TCP port number. Distinct from a UDP port even though both are integers, so wiring one into the other's slot is a static error."
|
|
7
|
+
}
|
package/package.json
CHANGED
package/src/bigint-json.ts
CHANGED
|
@@ -49,3 +49,30 @@ export function bigIntAt(holder: unknown, key: string): bigint | undefined {
|
|
|
49
49
|
const source = (holder as Record<string, unknown> | null | undefined)?.[key];
|
|
50
50
|
return typeof source === "bigint" ? source : undefined;
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A declared-integer input read as a JS number, whichever representation the
|
|
55
|
+
* call site produced.
|
|
56
|
+
*
|
|
57
|
+
* A CEL integer is an int64 — a BigInt — and the kernel normalizes a declared
|
|
58
|
+
* `type: integer` OUTPUT to that form, so one resource's result reaching another
|
|
59
|
+
* resource's input arrives as a BigInt while a YAML literal at the same slot
|
|
60
|
+
* arrives as a plain number. A controller that reads such an input with
|
|
61
|
+
* `Number.isInteger(...)` or plain arithmetic therefore works for one call site
|
|
62
|
+
* and throws `Cannot mix BigInt and other types` for the other. Inputs are
|
|
63
|
+
* deliberately NOT normalized (that would change the authoring surface of every
|
|
64
|
+
* module rather than repair a false declaration), so this is how a controller
|
|
65
|
+
* reads one.
|
|
66
|
+
*
|
|
67
|
+
* Returns `undefined` for anything that is not an integer in either
|
|
68
|
+
* representation — including a BigInt too large for a double, since silently
|
|
69
|
+
* rounding it would be the precision loss int64 support exists to remove — so a
|
|
70
|
+
* caller's own "must be a non-negative integer" check still rejects what it
|
|
71
|
+
* should.
|
|
72
|
+
*/
|
|
73
|
+
export function integerInput(value: unknown): number | undefined {
|
|
74
|
+
if (typeof value === "number") return Number.isInteger(value) ? value : undefined;
|
|
75
|
+
if (typeof value !== "bigint") return undefined;
|
|
76
|
+
const asNumber = Number(value);
|
|
77
|
+
return Number.isSafeInteger(asNumber) ? asNumber : undefined;
|
|
78
|
+
}
|
package/src/index.ts
CHANGED
package/src/resource-context.ts
CHANGED
|
@@ -27,6 +27,12 @@ export interface LoadOptions {
|
|
|
27
27
|
* inline imports resolve and execute identically to authored `Telo.Import`
|
|
28
28
|
* documents. Mirrors the analyzer loader's option of the same name. */
|
|
29
29
|
desugarImports?: boolean;
|
|
30
|
+
/** When true, legacy manifest spellings are rewritten to the current ones
|
|
31
|
+
* before the manifests are returned, so a module published years ago loads
|
|
32
|
+
* against today's vocabulary. On for every runtime load; off only for a
|
|
33
|
+
* round-trip view that must show the author's own text. Mirrors the analyzer
|
|
34
|
+
* loader's option of the same name. */
|
|
35
|
+
migrate?: boolean;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
export interface DataValidator {
|
package/src/type-schema-ref.ts
CHANGED
|
@@ -33,6 +33,22 @@ export function canonicalTypeSchemaId(moduleName: string, typeName: string): str
|
|
|
33
33
|
return `telo:${moduleName}/${typeName}`;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** The inverse of {@link canonicalTypeSchemaId}. Returns null for any other
|
|
37
|
+
* string, including the authoring authority form and fragment-bearing built-ins.
|
|
38
|
+
*
|
|
39
|
+
* A resolver reads a named shape through this rather than by bare name: the
|
|
40
|
+
* canonical id carries the OWNING MODULE, so two libraries declaring a shape of
|
|
41
|
+
* the same name stay distinct. Resolving by name alone was how an alias got
|
|
42
|
+
* silently dropped. */
|
|
43
|
+
export function parseCanonicalTypeSchemaId(
|
|
44
|
+
ref: unknown,
|
|
45
|
+
): { moduleName: string; typeName: string } | null {
|
|
46
|
+
if (typeof ref !== "string") return null;
|
|
47
|
+
const match = /^telo:([^/#:]+)\/([^#/]+)$/.exec(ref);
|
|
48
|
+
if (!match) return null;
|
|
49
|
+
return { moduleName: match[1]!, typeName: match[2]! };
|
|
50
|
+
}
|
|
51
|
+
|
|
36
52
|
/** Top-level keywords merged structurally rather than copied wholesale when
|
|
37
53
|
* resolving `extends`: object shape (`properties` / `required` /
|
|
38
54
|
* `additionalProperties`) is deep-merged, and composition keywords (`allOf` /
|