@renderify/runtime 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.
@@ -0,0 +1,226 @@
1
+ import { RuntimeExecutionResult, RuntimeEvent, RuntimeNode, RuntimeSourceLanguage, RuntimeSourceModule, RuntimePlan, RuntimeDiagnostic, RuntimeExecutionContext, RuntimeStateSnapshot, RuntimeExecutionProfile, JsonValue } from '@renderify/ir';
2
+ import { SecurityChecker, SecurityInitializationInput, SecurityCheckResult } from '@renderify/security';
3
+
4
+ type RuntimeDependencyUsage = "import" | "component" | "source-import";
5
+ interface RuntimeDependencyProbeStatus {
6
+ usage: RuntimeDependencyUsage;
7
+ specifier: string;
8
+ resolvedSpecifier?: string;
9
+ ok: boolean;
10
+ message?: string;
11
+ }
12
+
13
+ type RuntimeSourceSandboxMode$1 = "none" | "worker" | "iframe";
14
+
15
+ interface RuntimeEventDispatchRequest {
16
+ planId: string;
17
+ event: RuntimeEvent;
18
+ }
19
+ interface InteractiveRenderTarget {
20
+ element: string | HTMLElement;
21
+ onRuntimeEvent?: (request: RuntimeEventDispatchRequest) => void | Promise<void>;
22
+ }
23
+ type RenderTarget = string | HTMLElement | InteractiveRenderTarget;
24
+ interface UIRenderer {
25
+ render(result: RuntimeExecutionResult, target?: RenderTarget): Promise<string>;
26
+ renderNode(node: RuntimeNode): string;
27
+ }
28
+ declare class DefaultUIRenderer implements UIRenderer {
29
+ private readonly mountSessions;
30
+ render(result: RuntimeExecutionResult, target?: RenderTarget): Promise<string>;
31
+ private renderPreactArtifact;
32
+ renderNode(node: RuntimeNode): string;
33
+ private renderNodeWithBindings;
34
+ private renderNodeInternal;
35
+ private resolveRenderTarget;
36
+ private resolveTargetElement;
37
+ private patchMountPoint;
38
+ private sanitizeHtmlForMount;
39
+ private reconcileChildren;
40
+ private shouldUseKeyedReconcile;
41
+ private reconcileKeyedChildren;
42
+ private applyDesiredChildren;
43
+ private getNodeKey;
44
+ private areNodesCompatible;
45
+ private reconcileNode;
46
+ private reconcileAttributes;
47
+ private shouldSkipInteractivePropertySync;
48
+ private syncMountSession;
49
+ private syncDelegatedListeners;
50
+ private handleDelegatedRuntimeEvent;
51
+ private loadPreactRenderer;
52
+ private loadPreactRenderToString;
53
+ private stringifyTarget;
54
+ }
55
+
56
+ interface CompileOptions {
57
+ pretty?: boolean;
58
+ }
59
+ interface RuntimeModuleLoader {
60
+ load(specifier: string): Promise<unknown>;
61
+ unload?(specifier: string): Promise<void>;
62
+ }
63
+ interface RuntimeExecutionInput {
64
+ plan: RuntimePlan;
65
+ context?: RuntimeExecutionContext;
66
+ event?: RuntimeEvent;
67
+ stateOverride?: RuntimeStateSnapshot;
68
+ signal?: AbortSignal;
69
+ }
70
+
71
+ interface RuntimePlanProbeResult {
72
+ planId: string;
73
+ diagnostics: RuntimeDiagnostic[];
74
+ dependencies: RuntimeDependencyProbeStatus[];
75
+ }
76
+ interface RuntimeManager {
77
+ initialize(): Promise<void>;
78
+ terminate(): Promise<void>;
79
+ probePlan(plan: RuntimePlan): Promise<RuntimePlanProbeResult>;
80
+ executePlan(plan: RuntimePlan, context?: RuntimeExecutionContext, event?: RuntimeEvent, stateOverride?: RuntimeStateSnapshot, signal?: AbortSignal): Promise<RuntimeExecutionResult>;
81
+ execute(input: RuntimeExecutionInput): Promise<RuntimeExecutionResult>;
82
+ compile(plan: RuntimePlan, options?: CompileOptions): Promise<string>;
83
+ getPlanState(planId: string): RuntimeStateSnapshot | undefined;
84
+ setPlanState(planId: string, snapshot: RuntimeStateSnapshot): void;
85
+ clearPlanState(planId: string): void;
86
+ }
87
+ interface RuntimeManagerOptions {
88
+ moduleLoader?: RuntimeModuleLoader;
89
+ sourceTranspiler?: RuntimeSourceTranspiler;
90
+ defaultMaxImports?: number;
91
+ defaultMaxComponentInvocations?: number;
92
+ defaultMaxExecutionMs?: number;
93
+ defaultExecutionProfile?: RuntimeExecutionProfile;
94
+ supportedPlanSpecVersions?: string[];
95
+ enforceModuleManifest?: boolean;
96
+ allowIsolationFallback?: boolean;
97
+ browserSourceSandboxMode?: RuntimeSourceSandboxMode;
98
+ browserSourceSandboxTimeoutMs?: number;
99
+ browserSourceSandboxFailClosed?: boolean;
100
+ enableDependencyPreflight?: boolean;
101
+ failOnDependencyPreflightError?: boolean;
102
+ remoteFetchTimeoutMs?: number;
103
+ remoteFetchRetries?: number;
104
+ remoteFetchBackoffMs?: number;
105
+ remoteFallbackCdnBases?: string[];
106
+ }
107
+ interface RuntimeSourceTranspileInput {
108
+ code: string;
109
+ language: RuntimeSourceLanguage;
110
+ filename?: string;
111
+ runtime?: RuntimeSourceModule["runtime"];
112
+ }
113
+ interface RuntimeSourceTranspiler {
114
+ transpile(input: RuntimeSourceTranspileInput): Promise<string>;
115
+ }
116
+ interface RuntimeEmbedRenderOptions {
117
+ target?: RenderTarget;
118
+ context?: RuntimeExecutionContext;
119
+ signal?: AbortSignal;
120
+ runtime?: RuntimeManager;
121
+ runtimeOptions?: RuntimeManagerOptions;
122
+ security?: SecurityChecker;
123
+ securityInitialization?: SecurityInitializationInput;
124
+ ui?: UIRenderer;
125
+ autoInitializeRuntime?: boolean;
126
+ autoTerminateRuntime?: boolean;
127
+ serializeTargetRenders?: boolean;
128
+ }
129
+ interface RuntimeEmbedRenderResult {
130
+ html: string;
131
+ execution: RuntimeExecutionResult;
132
+ security: SecurityCheckResult;
133
+ runtime: RuntimeManager;
134
+ }
135
+ declare class RuntimeSecurityViolationError extends Error {
136
+ readonly result: SecurityCheckResult;
137
+ constructor(result: SecurityCheckResult);
138
+ }
139
+ type RuntimeSourceSandboxMode = RuntimeSourceSandboxMode$1;
140
+
141
+ declare function renderPlanInBrowser(plan: RuntimePlan, options?: RuntimeEmbedRenderOptions): Promise<RuntimeEmbedRenderResult>;
142
+
143
+ interface JspmModuleLoaderOptions {
144
+ cdnBaseUrl?: string;
145
+ importMap?: Record<string, string>;
146
+ }
147
+ declare class JspmModuleLoader implements RuntimeModuleLoader {
148
+ private readonly cdnBaseUrl;
149
+ private readonly importMap;
150
+ private readonly cache;
151
+ constructor(options?: JspmModuleLoaderOptions);
152
+ load(specifier: string): Promise<unknown>;
153
+ unload(specifier: string): Promise<void>;
154
+ resolveSpecifier(specifier: string): string;
155
+ private importWithBestEffort;
156
+ private isUrl;
157
+ private hasUnsupportedScheme;
158
+ private isBareNpmSpecifier;
159
+ private isNodeBuiltinSpecifier;
160
+ private extractTopLevelPackageName;
161
+ private resolveNpmSpecifier;
162
+ private normalizeCdnBaseUrl;
163
+ }
164
+
165
+ type RuntimeComponentFactory = (props: Record<string, JsonValue>, context: RuntimeExecutionContext, children: RuntimeNode[]) => Promise<RuntimeNode | string> | RuntimeNode | string;
166
+
167
+ declare class DefaultRuntimeManager implements RuntimeManager {
168
+ private readonly moduleLoader?;
169
+ private readonly sourceTranspiler;
170
+ private readonly states;
171
+ private readonly defaultMaxImports;
172
+ private readonly defaultMaxComponentInvocations;
173
+ private readonly defaultMaxExecutionMs;
174
+ private readonly defaultExecutionProfile;
175
+ private readonly supportedPlanSpecVersions;
176
+ private readonly enforceModuleManifest;
177
+ private readonly allowIsolationFallback;
178
+ private readonly browserSourceSandboxMode;
179
+ private readonly browserSourceSandboxTimeoutMs;
180
+ private readonly browserSourceSandboxFailClosed;
181
+ private readonly enableDependencyPreflight;
182
+ private readonly failOnDependencyPreflightError;
183
+ private readonly remoteFetchTimeoutMs;
184
+ private readonly remoteFetchRetries;
185
+ private readonly remoteFetchBackoffMs;
186
+ private readonly remoteFallbackCdnBases;
187
+ private readonly browserModuleUrlCache;
188
+ private readonly browserModuleInflight;
189
+ private readonly browserBlobUrls;
190
+ private initialized;
191
+ constructor(options?: RuntimeManagerOptions);
192
+ initialize(): Promise<void>;
193
+ terminate(): Promise<void>;
194
+ execute(input: RuntimeExecutionInput): Promise<RuntimeExecutionResult>;
195
+ probePlan(plan: RuntimePlan): Promise<RuntimePlanProbeResult>;
196
+ executePlan(plan: RuntimePlan, context?: RuntimeExecutionContext, event?: RuntimeEvent, stateOverride?: RuntimeStateSnapshot, signal?: AbortSignal): Promise<RuntimeExecutionResult>;
197
+ compile(plan: RuntimePlan, options?: CompileOptions): Promise<string>;
198
+ getPlanState(planId: string): RuntimeStateSnapshot | undefined;
199
+ setPlanState(planId: string, snapshot: RuntimeStateSnapshot): void;
200
+ clearPlanState(planId: string): void;
201
+ private resolveState;
202
+ private preflightPlanDependencies;
203
+ private resolveSourceRoot;
204
+ private resolveRuntimeSourceSpecifier;
205
+ private resolveSourceImportLoaderCandidate;
206
+ private resolveRuntimeSpecifier;
207
+ private createSourceModuleLoader;
208
+ private materializeFetchedModuleSource;
209
+ private toConfiguredFallbackUrl;
210
+ private toEsmFallbackUrl;
211
+ private rewriteImportsAsync;
212
+ private createBrowserBlobModuleUrl;
213
+ private revokeBrowserBlobUrls;
214
+ private normalizeSourceOutput;
215
+ private resolveNode;
216
+ private ensureInitialized;
217
+ private errorToMessage;
218
+ }
219
+
220
+ declare class BabelRuntimeSourceTranspiler implements RuntimeSourceTranspiler {
221
+ transpile(input: RuntimeSourceTranspileInput): Promise<string>;
222
+ private resolveBabel;
223
+ static mergeRuntimeHelpers(source: RuntimeSourceTranspileInput["code"], runtime: RuntimeSourceTranspileInput["runtime"]): string;
224
+ }
225
+
226
+ export { BabelRuntimeSourceTranspiler, type CompileOptions, DefaultRuntimeManager, DefaultUIRenderer, type InteractiveRenderTarget, JspmModuleLoader, type JspmModuleLoaderOptions, type RenderTarget, type RuntimeComponentFactory, type RuntimeDependencyProbeStatus, type RuntimeDependencyUsage, type RuntimeEmbedRenderOptions, type RuntimeEmbedRenderResult, type RuntimeEventDispatchRequest, type RuntimeExecutionInput, type RuntimeManager, type RuntimeManagerOptions, type RuntimeModuleLoader, type RuntimePlanProbeResult, RuntimeSecurityViolationError, type RuntimeSourceSandboxMode, type RuntimeSourceTranspileInput, type RuntimeSourceTranspiler, type UIRenderer, renderPlanInBrowser };
@@ -0,0 +1,226 @@
1
+ import { RuntimeExecutionResult, RuntimeEvent, RuntimeNode, RuntimeSourceLanguage, RuntimeSourceModule, RuntimePlan, RuntimeDiagnostic, RuntimeExecutionContext, RuntimeStateSnapshot, RuntimeExecutionProfile, JsonValue } from '@renderify/ir';
2
+ import { SecurityChecker, SecurityInitializationInput, SecurityCheckResult } from '@renderify/security';
3
+
4
+ type RuntimeDependencyUsage = "import" | "component" | "source-import";
5
+ interface RuntimeDependencyProbeStatus {
6
+ usage: RuntimeDependencyUsage;
7
+ specifier: string;
8
+ resolvedSpecifier?: string;
9
+ ok: boolean;
10
+ message?: string;
11
+ }
12
+
13
+ type RuntimeSourceSandboxMode$1 = "none" | "worker" | "iframe";
14
+
15
+ interface RuntimeEventDispatchRequest {
16
+ planId: string;
17
+ event: RuntimeEvent;
18
+ }
19
+ interface InteractiveRenderTarget {
20
+ element: string | HTMLElement;
21
+ onRuntimeEvent?: (request: RuntimeEventDispatchRequest) => void | Promise<void>;
22
+ }
23
+ type RenderTarget = string | HTMLElement | InteractiveRenderTarget;
24
+ interface UIRenderer {
25
+ render(result: RuntimeExecutionResult, target?: RenderTarget): Promise<string>;
26
+ renderNode(node: RuntimeNode): string;
27
+ }
28
+ declare class DefaultUIRenderer implements UIRenderer {
29
+ private readonly mountSessions;
30
+ render(result: RuntimeExecutionResult, target?: RenderTarget): Promise<string>;
31
+ private renderPreactArtifact;
32
+ renderNode(node: RuntimeNode): string;
33
+ private renderNodeWithBindings;
34
+ private renderNodeInternal;
35
+ private resolveRenderTarget;
36
+ private resolveTargetElement;
37
+ private patchMountPoint;
38
+ private sanitizeHtmlForMount;
39
+ private reconcileChildren;
40
+ private shouldUseKeyedReconcile;
41
+ private reconcileKeyedChildren;
42
+ private applyDesiredChildren;
43
+ private getNodeKey;
44
+ private areNodesCompatible;
45
+ private reconcileNode;
46
+ private reconcileAttributes;
47
+ private shouldSkipInteractivePropertySync;
48
+ private syncMountSession;
49
+ private syncDelegatedListeners;
50
+ private handleDelegatedRuntimeEvent;
51
+ private loadPreactRenderer;
52
+ private loadPreactRenderToString;
53
+ private stringifyTarget;
54
+ }
55
+
56
+ interface CompileOptions {
57
+ pretty?: boolean;
58
+ }
59
+ interface RuntimeModuleLoader {
60
+ load(specifier: string): Promise<unknown>;
61
+ unload?(specifier: string): Promise<void>;
62
+ }
63
+ interface RuntimeExecutionInput {
64
+ plan: RuntimePlan;
65
+ context?: RuntimeExecutionContext;
66
+ event?: RuntimeEvent;
67
+ stateOverride?: RuntimeStateSnapshot;
68
+ signal?: AbortSignal;
69
+ }
70
+
71
+ interface RuntimePlanProbeResult {
72
+ planId: string;
73
+ diagnostics: RuntimeDiagnostic[];
74
+ dependencies: RuntimeDependencyProbeStatus[];
75
+ }
76
+ interface RuntimeManager {
77
+ initialize(): Promise<void>;
78
+ terminate(): Promise<void>;
79
+ probePlan(plan: RuntimePlan): Promise<RuntimePlanProbeResult>;
80
+ executePlan(plan: RuntimePlan, context?: RuntimeExecutionContext, event?: RuntimeEvent, stateOverride?: RuntimeStateSnapshot, signal?: AbortSignal): Promise<RuntimeExecutionResult>;
81
+ execute(input: RuntimeExecutionInput): Promise<RuntimeExecutionResult>;
82
+ compile(plan: RuntimePlan, options?: CompileOptions): Promise<string>;
83
+ getPlanState(planId: string): RuntimeStateSnapshot | undefined;
84
+ setPlanState(planId: string, snapshot: RuntimeStateSnapshot): void;
85
+ clearPlanState(planId: string): void;
86
+ }
87
+ interface RuntimeManagerOptions {
88
+ moduleLoader?: RuntimeModuleLoader;
89
+ sourceTranspiler?: RuntimeSourceTranspiler;
90
+ defaultMaxImports?: number;
91
+ defaultMaxComponentInvocations?: number;
92
+ defaultMaxExecutionMs?: number;
93
+ defaultExecutionProfile?: RuntimeExecutionProfile;
94
+ supportedPlanSpecVersions?: string[];
95
+ enforceModuleManifest?: boolean;
96
+ allowIsolationFallback?: boolean;
97
+ browserSourceSandboxMode?: RuntimeSourceSandboxMode;
98
+ browserSourceSandboxTimeoutMs?: number;
99
+ browserSourceSandboxFailClosed?: boolean;
100
+ enableDependencyPreflight?: boolean;
101
+ failOnDependencyPreflightError?: boolean;
102
+ remoteFetchTimeoutMs?: number;
103
+ remoteFetchRetries?: number;
104
+ remoteFetchBackoffMs?: number;
105
+ remoteFallbackCdnBases?: string[];
106
+ }
107
+ interface RuntimeSourceTranspileInput {
108
+ code: string;
109
+ language: RuntimeSourceLanguage;
110
+ filename?: string;
111
+ runtime?: RuntimeSourceModule["runtime"];
112
+ }
113
+ interface RuntimeSourceTranspiler {
114
+ transpile(input: RuntimeSourceTranspileInput): Promise<string>;
115
+ }
116
+ interface RuntimeEmbedRenderOptions {
117
+ target?: RenderTarget;
118
+ context?: RuntimeExecutionContext;
119
+ signal?: AbortSignal;
120
+ runtime?: RuntimeManager;
121
+ runtimeOptions?: RuntimeManagerOptions;
122
+ security?: SecurityChecker;
123
+ securityInitialization?: SecurityInitializationInput;
124
+ ui?: UIRenderer;
125
+ autoInitializeRuntime?: boolean;
126
+ autoTerminateRuntime?: boolean;
127
+ serializeTargetRenders?: boolean;
128
+ }
129
+ interface RuntimeEmbedRenderResult {
130
+ html: string;
131
+ execution: RuntimeExecutionResult;
132
+ security: SecurityCheckResult;
133
+ runtime: RuntimeManager;
134
+ }
135
+ declare class RuntimeSecurityViolationError extends Error {
136
+ readonly result: SecurityCheckResult;
137
+ constructor(result: SecurityCheckResult);
138
+ }
139
+ type RuntimeSourceSandboxMode = RuntimeSourceSandboxMode$1;
140
+
141
+ declare function renderPlanInBrowser(plan: RuntimePlan, options?: RuntimeEmbedRenderOptions): Promise<RuntimeEmbedRenderResult>;
142
+
143
+ interface JspmModuleLoaderOptions {
144
+ cdnBaseUrl?: string;
145
+ importMap?: Record<string, string>;
146
+ }
147
+ declare class JspmModuleLoader implements RuntimeModuleLoader {
148
+ private readonly cdnBaseUrl;
149
+ private readonly importMap;
150
+ private readonly cache;
151
+ constructor(options?: JspmModuleLoaderOptions);
152
+ load(specifier: string): Promise<unknown>;
153
+ unload(specifier: string): Promise<void>;
154
+ resolveSpecifier(specifier: string): string;
155
+ private importWithBestEffort;
156
+ private isUrl;
157
+ private hasUnsupportedScheme;
158
+ private isBareNpmSpecifier;
159
+ private isNodeBuiltinSpecifier;
160
+ private extractTopLevelPackageName;
161
+ private resolveNpmSpecifier;
162
+ private normalizeCdnBaseUrl;
163
+ }
164
+
165
+ type RuntimeComponentFactory = (props: Record<string, JsonValue>, context: RuntimeExecutionContext, children: RuntimeNode[]) => Promise<RuntimeNode | string> | RuntimeNode | string;
166
+
167
+ declare class DefaultRuntimeManager implements RuntimeManager {
168
+ private readonly moduleLoader?;
169
+ private readonly sourceTranspiler;
170
+ private readonly states;
171
+ private readonly defaultMaxImports;
172
+ private readonly defaultMaxComponentInvocations;
173
+ private readonly defaultMaxExecutionMs;
174
+ private readonly defaultExecutionProfile;
175
+ private readonly supportedPlanSpecVersions;
176
+ private readonly enforceModuleManifest;
177
+ private readonly allowIsolationFallback;
178
+ private readonly browserSourceSandboxMode;
179
+ private readonly browserSourceSandboxTimeoutMs;
180
+ private readonly browserSourceSandboxFailClosed;
181
+ private readonly enableDependencyPreflight;
182
+ private readonly failOnDependencyPreflightError;
183
+ private readonly remoteFetchTimeoutMs;
184
+ private readonly remoteFetchRetries;
185
+ private readonly remoteFetchBackoffMs;
186
+ private readonly remoteFallbackCdnBases;
187
+ private readonly browserModuleUrlCache;
188
+ private readonly browserModuleInflight;
189
+ private readonly browserBlobUrls;
190
+ private initialized;
191
+ constructor(options?: RuntimeManagerOptions);
192
+ initialize(): Promise<void>;
193
+ terminate(): Promise<void>;
194
+ execute(input: RuntimeExecutionInput): Promise<RuntimeExecutionResult>;
195
+ probePlan(plan: RuntimePlan): Promise<RuntimePlanProbeResult>;
196
+ executePlan(plan: RuntimePlan, context?: RuntimeExecutionContext, event?: RuntimeEvent, stateOverride?: RuntimeStateSnapshot, signal?: AbortSignal): Promise<RuntimeExecutionResult>;
197
+ compile(plan: RuntimePlan, options?: CompileOptions): Promise<string>;
198
+ getPlanState(planId: string): RuntimeStateSnapshot | undefined;
199
+ setPlanState(planId: string, snapshot: RuntimeStateSnapshot): void;
200
+ clearPlanState(planId: string): void;
201
+ private resolveState;
202
+ private preflightPlanDependencies;
203
+ private resolveSourceRoot;
204
+ private resolveRuntimeSourceSpecifier;
205
+ private resolveSourceImportLoaderCandidate;
206
+ private resolveRuntimeSpecifier;
207
+ private createSourceModuleLoader;
208
+ private materializeFetchedModuleSource;
209
+ private toConfiguredFallbackUrl;
210
+ private toEsmFallbackUrl;
211
+ private rewriteImportsAsync;
212
+ private createBrowserBlobModuleUrl;
213
+ private revokeBrowserBlobUrls;
214
+ private normalizeSourceOutput;
215
+ private resolveNode;
216
+ private ensureInitialized;
217
+ private errorToMessage;
218
+ }
219
+
220
+ declare class BabelRuntimeSourceTranspiler implements RuntimeSourceTranspiler {
221
+ transpile(input: RuntimeSourceTranspileInput): Promise<string>;
222
+ private resolveBabel;
223
+ static mergeRuntimeHelpers(source: RuntimeSourceTranspileInput["code"], runtime: RuntimeSourceTranspileInput["runtime"]): string;
224
+ }
225
+
226
+ export { BabelRuntimeSourceTranspiler, type CompileOptions, DefaultRuntimeManager, DefaultUIRenderer, type InteractiveRenderTarget, JspmModuleLoader, type JspmModuleLoaderOptions, type RenderTarget, type RuntimeComponentFactory, type RuntimeDependencyProbeStatus, type RuntimeDependencyUsage, type RuntimeEmbedRenderOptions, type RuntimeEmbedRenderResult, type RuntimeEventDispatchRequest, type RuntimeExecutionInput, type RuntimeManager, type RuntimeManagerOptions, type RuntimeModuleLoader, type RuntimePlanProbeResult, RuntimeSecurityViolationError, type RuntimeSourceSandboxMode, type RuntimeSourceTranspileInput, type RuntimeSourceTranspiler, type UIRenderer, renderPlanInBrowser };