@renderify/ir 0.1.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/ir.cjs.js +576 -0
- package/dist/ir.cjs.js.map +1 -0
- package/dist/ir.d.mts +175 -0
- package/dist/ir.d.ts +175 -0
- package/dist/ir.esm.js +556 -0
- package/dist/ir.esm.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Web LLM
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @renderify/ir
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Runtime IR contracts and utilities for Renderify.
|
|
8
|
+
|
|
9
|
+
`@renderify/ir` defines the RuntimePlan schema, node/state/action types, guards, path helpers, import parsing, and shared constants used across all other packages.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @renderify/ir
|
|
15
|
+
# or
|
|
16
|
+
npm i @renderify/ir
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Main Exports
|
|
20
|
+
|
|
21
|
+
- Types: `RuntimePlan`, `RuntimeNode`, `RuntimeCapabilities`, `RuntimeExecutionResult`, `RuntimeSourceModule`
|
|
22
|
+
- Guards: `isRuntimePlan`, `isRuntimeNode`, `isJsonValue`
|
|
23
|
+
- Builders: `createTextNode`, `createElementNode`, `createComponentNode`
|
|
24
|
+
- Path utils: `getValueByPath`, `setValueByPath`, `isSafePath`
|
|
25
|
+
- Import parsing: `collectRuntimeSourceImports`, `parseRuntimeSourceImportRanges`
|
|
26
|
+
- Hash utils: `hashStringFNV1a32`, `createFnv1a64Hasher`
|
|
27
|
+
- Shared constants: `DEFAULT_RUNTIME_PLAN_SPEC_VERSION`, `DEFAULT_JSPM_SPECIFIER_OVERRIDES`
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {
|
|
33
|
+
createElementNode,
|
|
34
|
+
createTextNode,
|
|
35
|
+
isRuntimePlan,
|
|
36
|
+
type RuntimePlan,
|
|
37
|
+
} from "@renderify/ir";
|
|
38
|
+
|
|
39
|
+
const plan: RuntimePlan = {
|
|
40
|
+
specVersion: "runtime-plan/v1",
|
|
41
|
+
id: "demo",
|
|
42
|
+
version: 1,
|
|
43
|
+
capabilities: { domWrite: true },
|
|
44
|
+
root: createElementNode("div", {}, [createTextNode("Hello Renderify")]),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (!isRuntimePlan(plan)) {
|
|
48
|
+
throw new Error("Invalid RuntimePlan");
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Notes
|
|
53
|
+
|
|
54
|
+
- This package is framework-agnostic.
|
|
55
|
+
- All other Renderify packages depend on these contracts.
|
package/dist/ir.cjs.js
ADDED
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
DEFAULT_JSPM_SPECIFIER_OVERRIDES: () => DEFAULT_JSPM_SPECIFIER_OVERRIDES,
|
|
24
|
+
DEFAULT_RUNTIME_PLAN_SPEC_VERSION: () => DEFAULT_RUNTIME_PLAN_SPEC_VERSION,
|
|
25
|
+
RUNTIME_PLAN_SPEC_VERSION_V1: () => RUNTIME_PLAN_SPEC_VERSION_V1,
|
|
26
|
+
asJsonValue: () => asJsonValue,
|
|
27
|
+
cloneJsonValue: () => cloneJsonValue,
|
|
28
|
+
collectComponentModules: () => collectComponentModules,
|
|
29
|
+
collectRuntimeSourceImports: () => collectRuntimeSourceImports,
|
|
30
|
+
createComponentNode: () => createComponentNode,
|
|
31
|
+
createElementNode: () => createElementNode,
|
|
32
|
+
createFnv1a64Hasher: () => createFnv1a64Hasher,
|
|
33
|
+
createTextNode: () => createTextNode,
|
|
34
|
+
getValueByPath: () => getValueByPath,
|
|
35
|
+
hashStringFNV1a32: () => hashStringFNV1a32,
|
|
36
|
+
hashStringFNV1a32Base36: () => hashStringFNV1a32Base36,
|
|
37
|
+
hashStringFNV1a64Hex: () => hashStringFNV1a64Hex,
|
|
38
|
+
isJsonValue: () => isJsonValue,
|
|
39
|
+
isRuntimeAction: () => isRuntimeAction,
|
|
40
|
+
isRuntimeCapabilities: () => isRuntimeCapabilities,
|
|
41
|
+
isRuntimeEvent: () => isRuntimeEvent,
|
|
42
|
+
isRuntimeModuleDescriptor: () => isRuntimeModuleDescriptor,
|
|
43
|
+
isRuntimeModuleManifest: () => isRuntimeModuleManifest,
|
|
44
|
+
isRuntimeNode: () => isRuntimeNode,
|
|
45
|
+
isRuntimePlan: () => isRuntimePlan,
|
|
46
|
+
isRuntimePlanMetadata: () => isRuntimePlanMetadata,
|
|
47
|
+
isRuntimeSourceLanguage: () => isRuntimeSourceLanguage,
|
|
48
|
+
isRuntimeSourceModule: () => isRuntimeSourceModule,
|
|
49
|
+
isRuntimeSourceRuntime: () => isRuntimeSourceRuntime,
|
|
50
|
+
isRuntimeStateModel: () => isRuntimeStateModel,
|
|
51
|
+
isRuntimeStateSnapshot: () => isRuntimeStateSnapshot,
|
|
52
|
+
isRuntimeValueFromPath: () => isRuntimeValueFromPath,
|
|
53
|
+
isSafePath: () => isSafePath,
|
|
54
|
+
parseRuntimeSourceImportRanges: () => parseRuntimeSourceImportRanges,
|
|
55
|
+
resolveRuntimePlanSpecVersion: () => resolveRuntimePlanSpecVersion,
|
|
56
|
+
setValueByPath: () => setValueByPath,
|
|
57
|
+
splitPath: () => splitPath,
|
|
58
|
+
walkRuntimeNode: () => walkRuntimeNode
|
|
59
|
+
});
|
|
60
|
+
module.exports = __toCommonJS(src_exports);
|
|
61
|
+
|
|
62
|
+
// src/hash.ts
|
|
63
|
+
var FNV1A_64_OFFSET_BASIS = 0xcbf29ce484222325n;
|
|
64
|
+
var FNV1A_64_PRIME = 0x100000001b3n;
|
|
65
|
+
var UINT64_MASK = 0xffffffffffffffffn;
|
|
66
|
+
function createFnv1a64Hasher() {
|
|
67
|
+
let hash = FNV1A_64_OFFSET_BASIS;
|
|
68
|
+
return {
|
|
69
|
+
update: (chunk) => {
|
|
70
|
+
for (let index = 0; index < chunk.length; index += 1) {
|
|
71
|
+
hash ^= BigInt(chunk.charCodeAt(index));
|
|
72
|
+
hash = hash * FNV1A_64_PRIME & UINT64_MASK;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
digestHex: () => hash.toString(16)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function hashStringFNV1a64Hex(value) {
|
|
79
|
+
const hasher = createFnv1a64Hasher();
|
|
80
|
+
hasher.update(value);
|
|
81
|
+
return hasher.digestHex();
|
|
82
|
+
}
|
|
83
|
+
function hashStringFNV1a32(value) {
|
|
84
|
+
let hash = 2166136261;
|
|
85
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
86
|
+
hash ^= value.charCodeAt(index);
|
|
87
|
+
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
88
|
+
}
|
|
89
|
+
return hash >>> 0;
|
|
90
|
+
}
|
|
91
|
+
function hashStringFNV1a32Base36(value) {
|
|
92
|
+
return hashStringFNV1a32(value).toString(36);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/source-imports.ts
|
|
96
|
+
var import_es_module_lexer = require("es-module-lexer");
|
|
97
|
+
var SOURCE_IMPORT_REWRITE_PATTERNS = [
|
|
98
|
+
/\bfrom\s+["']([^"']+)["']/g,
|
|
99
|
+
/\bimport\s+["']([^"']+)["']/g,
|
|
100
|
+
/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g
|
|
101
|
+
];
|
|
102
|
+
async function parseRuntimeSourceImportRanges(source) {
|
|
103
|
+
if (source.trim().length === 0) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
await import_es_module_lexer.init;
|
|
108
|
+
const [imports] = (0, import_es_module_lexer.parse)(source);
|
|
109
|
+
const parsed = [];
|
|
110
|
+
for (const entry of imports) {
|
|
111
|
+
const specifier = entry.n?.trim();
|
|
112
|
+
if (!specifier) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (entry.s < 0 || entry.e <= entry.s) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
parsed.push({
|
|
119
|
+
start: entry.s,
|
|
120
|
+
end: entry.e,
|
|
121
|
+
specifier
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return parsed.sort((left, right) => left.start - right.start);
|
|
125
|
+
} catch {
|
|
126
|
+
return parseRuntimeSourceImportRangesFromRegex(source);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function collectRuntimeSourceImports(source) {
|
|
130
|
+
const ranges = await parseRuntimeSourceImportRanges(source);
|
|
131
|
+
const imports = /* @__PURE__ */ new Set();
|
|
132
|
+
for (const entry of ranges) {
|
|
133
|
+
imports.add(entry.specifier);
|
|
134
|
+
}
|
|
135
|
+
return [...imports];
|
|
136
|
+
}
|
|
137
|
+
function parseRuntimeSourceImportRangesFromRegex(source) {
|
|
138
|
+
const parsed = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const pattern of SOURCE_IMPORT_REWRITE_PATTERNS) {
|
|
140
|
+
const regex = new RegExp(
|
|
141
|
+
pattern.source,
|
|
142
|
+
pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`
|
|
143
|
+
);
|
|
144
|
+
let match = regex.exec(source);
|
|
145
|
+
while (match) {
|
|
146
|
+
const fullMatch = String(match[0] ?? "");
|
|
147
|
+
const capturedSpecifier = String(match[1] ?? "").trim();
|
|
148
|
+
if (capturedSpecifier.length === 0) {
|
|
149
|
+
match = regex.exec(source);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const relativeIndex = fullMatch.indexOf(capturedSpecifier);
|
|
153
|
+
if (relativeIndex < 0) {
|
|
154
|
+
match = regex.exec(source);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const start = match.index + relativeIndex;
|
|
158
|
+
const end = start + capturedSpecifier.length;
|
|
159
|
+
parsed.set(`${start}:${end}`, {
|
|
160
|
+
start,
|
|
161
|
+
end,
|
|
162
|
+
specifier: capturedSpecifier
|
|
163
|
+
});
|
|
164
|
+
match = regex.exec(source);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return [...parsed.values()].sort((left, right) => left.start - right.start);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/index.ts
|
|
171
|
+
var DEFAULT_JSPM_SPECIFIER_OVERRIDES = Object.freeze({
|
|
172
|
+
preact: "https://ga.jspm.io/npm:preact@10.28.3/dist/preact.module.js",
|
|
173
|
+
"preact/hooks": "https://ga.jspm.io/npm:preact@10.28.3/hooks/dist/hooks.module.js",
|
|
174
|
+
"preact/compat": "https://ga.jspm.io/npm:preact@10.28.3/compat/dist/compat.module.js",
|
|
175
|
+
"preact/jsx-runtime": "https://ga.jspm.io/npm:preact@10.28.3/jsx-runtime/dist/jsxRuntime.module.js",
|
|
176
|
+
react: "https://ga.jspm.io/npm:preact@10.28.3/compat/dist/compat.module.js",
|
|
177
|
+
"react-dom": "https://ga.jspm.io/npm:preact@10.28.3/compat/dist/compat.module.js",
|
|
178
|
+
"react-dom/client": "https://ga.jspm.io/npm:preact@10.28.3/compat/dist/compat.module.js",
|
|
179
|
+
"react/jsx-runtime": "https://ga.jspm.io/npm:preact@10.28.3/jsx-runtime/dist/jsxRuntime.module.js",
|
|
180
|
+
"react/jsx-dev-runtime": "https://ga.jspm.io/npm:preact@10.28.3/jsx-runtime/dist/jsxRuntime.module.js",
|
|
181
|
+
recharts: "https://ga.jspm.io/npm:recharts@3.3.0/es6/index.js"
|
|
182
|
+
});
|
|
183
|
+
var RUNTIME_PLAN_SPEC_VERSION_V1 = "runtime-plan/v1";
|
|
184
|
+
var DEFAULT_RUNTIME_PLAN_SPEC_VERSION = RUNTIME_PLAN_SPEC_VERSION_V1;
|
|
185
|
+
function createTextNode(value) {
|
|
186
|
+
return { type: "text", value };
|
|
187
|
+
}
|
|
188
|
+
function createElementNode(tag, props, children) {
|
|
189
|
+
return { type: "element", tag, props, children };
|
|
190
|
+
}
|
|
191
|
+
function createComponentNode(module2, exportName = "default", props, children) {
|
|
192
|
+
return { type: "component", module: module2, exportName, props, children };
|
|
193
|
+
}
|
|
194
|
+
function isRuntimeNode(value) {
|
|
195
|
+
if (typeof value !== "object" || value === null) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
const candidate = value;
|
|
199
|
+
if (candidate.type === "text") {
|
|
200
|
+
return typeof candidate.value === "string";
|
|
201
|
+
}
|
|
202
|
+
if (candidate.type === "element") {
|
|
203
|
+
return typeof candidate.tag === "string";
|
|
204
|
+
}
|
|
205
|
+
if (candidate.type === "component") {
|
|
206
|
+
return typeof candidate.module === "string";
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
function isJsonValue(value) {
|
|
211
|
+
return isJsonValueInternal(value, /* @__PURE__ */ new Set());
|
|
212
|
+
}
|
|
213
|
+
function isRuntimeValueFromPath(value) {
|
|
214
|
+
if (typeof value !== "object" || value === null) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
const candidate = value;
|
|
218
|
+
return typeof candidate.$from === "string";
|
|
219
|
+
}
|
|
220
|
+
function isRuntimeAction(value) {
|
|
221
|
+
if (!isRecord(value)) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (typeof value.path !== "string" || value.path.trim().length === 0) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
if (value.type === "set" || value.type === "push") {
|
|
228
|
+
return "value" in value && (isJsonValue(value.value) || isRuntimeValueFromPath(value.value));
|
|
229
|
+
}
|
|
230
|
+
if (value.type === "increment") {
|
|
231
|
+
return value.by === void 0 || typeof value.by === "number" && Number.isFinite(value.by);
|
|
232
|
+
}
|
|
233
|
+
if (value.type === "toggle") {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
function isRuntimeStateSnapshot(value) {
|
|
239
|
+
if (!isRecord(value)) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
for (const entry of Object.values(value)) {
|
|
243
|
+
if (!isJsonValue(entry)) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
function isRuntimeStateModel(value) {
|
|
250
|
+
if (!isRecord(value)) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (!isRuntimeStateSnapshot(value.initial)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
if (value.transitions === void 0) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (!isRecord(value.transitions)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
for (const [eventType, actions] of Object.entries(value.transitions)) {
|
|
263
|
+
if (eventType.trim().length === 0) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
if (!Array.isArray(actions)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
for (const action of actions) {
|
|
270
|
+
if (!isRuntimeAction(action)) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
function isRuntimeCapabilities(value) {
|
|
278
|
+
if (!isRecord(value)) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
if (value.domWrite !== void 0 && typeof value.domWrite !== "boolean") {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
if (value.networkHosts !== void 0 && (!Array.isArray(value.networkHosts) || value.networkHosts.some((entry) => typeof entry !== "string"))) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
if (value.allowedModules !== void 0 && (!Array.isArray(value.allowedModules) || value.allowedModules.some((entry) => typeof entry !== "string"))) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
if (value.timers !== void 0 && typeof value.timers !== "boolean") {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
if (value.executionProfile !== void 0 && value.executionProfile !== "standard" && value.executionProfile !== "isolated-vm" && value.executionProfile !== "sandbox-worker" && value.executionProfile !== "sandbox-iframe") {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
if (value.storage !== void 0 && (!Array.isArray(value.storage) || value.storage.some(
|
|
297
|
+
(entry) => entry !== "localStorage" && entry !== "sessionStorage"
|
|
298
|
+
))) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
if (!isFiniteNonNegativeNumber(value.maxImports)) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
if (!isFiniteNonNegativeNumber(value.maxComponentInvocations)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
if (value.maxExecutionMs !== void 0 && (typeof value.maxExecutionMs !== "number" || !Number.isFinite(value.maxExecutionMs) || value.maxExecutionMs < 1)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
function isRuntimeSourceLanguage(value) {
|
|
313
|
+
return value === "js" || value === "jsx" || value === "ts" || value === "tsx";
|
|
314
|
+
}
|
|
315
|
+
function isRuntimeSourceRuntime(value) {
|
|
316
|
+
return value === "renderify" || value === "preact";
|
|
317
|
+
}
|
|
318
|
+
function isRuntimeSourceModule(value) {
|
|
319
|
+
if (!isRecord(value)) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
if (typeof value.code !== "string" || value.code.trim().length === 0) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
if (!isRuntimeSourceLanguage(value.language)) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if (value.exportName !== void 0 && (typeof value.exportName !== "string" || value.exportName.trim().length === 0)) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (value.runtime !== void 0 && !isRuntimeSourceRuntime(value.runtime)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
function isRuntimePlanMetadata(value) {
|
|
337
|
+
if (!isRecord(value)) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
if (value.sourcePrompt !== void 0 && typeof value.sourcePrompt !== "string") {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
if (value.sourceModel !== void 0 && typeof value.sourceModel !== "string") {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (value.tags !== void 0 && (!Array.isArray(value.tags) || value.tags.some((entry) => typeof entry !== "string"))) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
350
|
+
if (key === "sourcePrompt" || key === "sourceModel" || key === "tags") {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (entry !== void 0 && !isJsonValue(entry)) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
function isRuntimeEvent(value) {
|
|
360
|
+
if (!isRecord(value)) {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
if (typeof value.type !== "string" || value.type.trim().length === 0) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (value.payload !== void 0 && !isRuntimeStateSnapshot(value.payload)) {
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
function isRuntimePlan(value) {
|
|
372
|
+
if (!isRecord(value)) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
if (typeof value.id !== "string" || value.id.trim().length === 0) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
if (typeof value.version !== "number" || !Number.isInteger(value.version) || value.version <= 0) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
if (!isRuntimeNode(value.root)) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
if (!isRuntimeCapabilities(value.capabilities)) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
if (value.specVersion !== void 0 && (typeof value.specVersion !== "string" || value.specVersion.trim().length === 0)) {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
if (value.imports !== void 0 && (!Array.isArray(value.imports) || value.imports.some((entry) => typeof entry !== "string"))) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
if (value.moduleManifest !== void 0 && !isRuntimeModuleManifest(value.moduleManifest)) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
if (value.state !== void 0 && !isRuntimeStateModel(value.state)) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
if (value.source !== void 0 && !isRuntimeSourceModule(value.source)) {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
if (value.metadata !== void 0 && !isRuntimePlanMetadata(value.metadata)) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
function isRuntimeModuleDescriptor(value) {
|
|
408
|
+
if (!isRecord(value)) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
if (typeof value.resolvedUrl !== "string" || value.resolvedUrl.trim().length === 0) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
if (value.integrity !== void 0 && (typeof value.integrity !== "string" || value.integrity.trim().length === 0)) {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
if (value.version !== void 0 && (typeof value.version !== "string" || value.version.trim().length === 0)) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
if (value.signer !== void 0 && (typeof value.signer !== "string" || value.signer.trim().length === 0)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
function isRuntimeModuleManifest(value) {
|
|
426
|
+
if (!isRecord(value)) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
for (const [specifier, descriptor] of Object.entries(value)) {
|
|
430
|
+
if (specifier.trim().length === 0) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
if (!isRuntimeModuleDescriptor(descriptor)) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
function resolveRuntimePlanSpecVersion(specVersion) {
|
|
440
|
+
if (typeof specVersion === "string" && specVersion.trim().length > 0) {
|
|
441
|
+
return specVersion.trim();
|
|
442
|
+
}
|
|
443
|
+
return DEFAULT_RUNTIME_PLAN_SPEC_VERSION;
|
|
444
|
+
}
|
|
445
|
+
function walkRuntimeNode(node, visitor, depth = 0) {
|
|
446
|
+
visitor(node, depth);
|
|
447
|
+
const children = node.type === "text" ? void 0 : node.children;
|
|
448
|
+
if (!children || children.length === 0) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
for (const child of children) {
|
|
452
|
+
walkRuntimeNode(child, visitor, depth + 1);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function collectComponentModules(root) {
|
|
456
|
+
const modules = /* @__PURE__ */ new Set();
|
|
457
|
+
walkRuntimeNode(root, (node) => {
|
|
458
|
+
if (node.type === "component") {
|
|
459
|
+
modules.add(node.module);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
return [...modules];
|
|
463
|
+
}
|
|
464
|
+
function splitPath(path) {
|
|
465
|
+
return path.split(".").map((segment) => segment.trim()).filter((segment) => segment.length > 0);
|
|
466
|
+
}
|
|
467
|
+
function isSafePath(path) {
|
|
468
|
+
const segments = splitPath(path);
|
|
469
|
+
if (segments.length === 0) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
for (const segment of segments) {
|
|
473
|
+
if (segment === "__proto__" || segment === "prototype" || segment === "constructor") {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
function getValueByPath(source, path) {
|
|
480
|
+
const segments = splitPath(path);
|
|
481
|
+
if (segments.length === 0) {
|
|
482
|
+
return void 0;
|
|
483
|
+
}
|
|
484
|
+
let cursor = source;
|
|
485
|
+
for (const segment of segments) {
|
|
486
|
+
if (typeof cursor !== "object" || cursor === null) {
|
|
487
|
+
return void 0;
|
|
488
|
+
}
|
|
489
|
+
cursor = cursor[segment];
|
|
490
|
+
}
|
|
491
|
+
return cursor;
|
|
492
|
+
}
|
|
493
|
+
function setValueByPath(target, path, value) {
|
|
494
|
+
const segments = splitPath(path);
|
|
495
|
+
if (segments.length === 0) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
let cursor = target;
|
|
499
|
+
for (let i = 0; i < segments.length; i += 1) {
|
|
500
|
+
const segment = segments[i];
|
|
501
|
+
const isLast = i === segments.length - 1;
|
|
502
|
+
if (isLast) {
|
|
503
|
+
cursor[segment] = value;
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const next = cursor[segment];
|
|
507
|
+
if (typeof next !== "object" || next === null || Array.isArray(next)) {
|
|
508
|
+
cursor[segment] = {};
|
|
509
|
+
}
|
|
510
|
+
cursor = cursor[segment];
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function cloneJsonValue(value) {
|
|
514
|
+
if (typeof globalThis.structuredClone === "function") {
|
|
515
|
+
return globalThis.structuredClone(value);
|
|
516
|
+
}
|
|
517
|
+
return JSON.parse(JSON.stringify(value));
|
|
518
|
+
}
|
|
519
|
+
function asJsonValue(value) {
|
|
520
|
+
if (value === void 0) {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
524
|
+
return value;
|
|
525
|
+
}
|
|
526
|
+
if (typeof value === "number") {
|
|
527
|
+
return Number.isFinite(value) ? value : null;
|
|
528
|
+
}
|
|
529
|
+
if (Array.isArray(value)) {
|
|
530
|
+
return value.map((item) => asJsonValue(item));
|
|
531
|
+
}
|
|
532
|
+
if (typeof value === "object" && value !== null) {
|
|
533
|
+
const result = {};
|
|
534
|
+
for (const [key, item] of Object.entries(value)) {
|
|
535
|
+
result[key] = asJsonValue(item);
|
|
536
|
+
}
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
return String(value);
|
|
540
|
+
}
|
|
541
|
+
function isRecord(value) {
|
|
542
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
543
|
+
}
|
|
544
|
+
function isFiniteNonNegativeNumber(value) {
|
|
545
|
+
return value === void 0 || typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
546
|
+
}
|
|
547
|
+
function isJsonValueInternal(value, seen) {
|
|
548
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
if (typeof value === "number") {
|
|
552
|
+
return Number.isFinite(value);
|
|
553
|
+
}
|
|
554
|
+
if (Array.isArray(value)) {
|
|
555
|
+
if (seen.has(value)) {
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
seen.add(value);
|
|
559
|
+
const valid = value.every((entry) => isJsonValueInternal(entry, seen));
|
|
560
|
+
seen.delete(value);
|
|
561
|
+
return valid;
|
|
562
|
+
}
|
|
563
|
+
if (isRecord(value)) {
|
|
564
|
+
if (seen.has(value)) {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
seen.add(value);
|
|
568
|
+
const valid = Object.values(value).every(
|
|
569
|
+
(entry) => isJsonValueInternal(entry, seen)
|
|
570
|
+
);
|
|
571
|
+
seen.delete(value);
|
|
572
|
+
return valid;
|
|
573
|
+
}
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
//# sourceMappingURL=ir.cjs.js.map
|