@pulse-compute/wasm-compiler 0.0.0 → 1.0.0-beta.2
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 +53 -1
- package/bin/provider-proof-composition.js +34 -0
- package/bin/pulsewasm-extract.js +20 -0
- package/package.json +60 -5
- package/src/artifacts-dir.js +13 -0
- package/src/ast-json.js +52 -0
- package/src/build-manifest.js +354 -0
- package/src/canonical-api-compiler.js +269 -0
- package/src/canonical-native-compiler.js +411 -0
- package/src/canonical-native-plan.js +1478 -0
- package/src/canonical-project-compiler.js +1224 -0
- package/src/canonical-router-compiler.js +25 -0
- package/src/cli-intents.js +1235 -0
- package/src/cli.js +1927 -0
- package/src/codegen/assemblyscript-compile.js +3 -0
- package/src/codegen/assemblyscript-core.js +3 -0
- package/src/codegen/assemblyscript-shape.js +3 -0
- package/src/codegen/assemblyscript-wasm-smoke.js +3 -0
- package/src/codegen/backend-capabilities.js +3 -0
- package/src/codegen/channel-broadcaster.js +3 -0
- package/src/codegen/compiled-handlers.js +3 -0
- package/src/codegen/compiled-wasm-runtime.js +3 -0
- package/src/codegen/config-references.js +248 -0
- package/src/codegen/dispatch-ts.js +145 -0
- package/src/codegen/effect-composition.js +331 -0
- package/src/codegen/effect-runtime.js +418 -0
- package/src/codegen/execution-harness-ts.js +467 -0
- package/src/codegen/handler-bindings-ts.js +298 -0
- package/src/codegen/handler-library-contracts.js +3 -0
- package/src/codegen/host-capabilities.js +3 -0
- package/src/codegen/host-runtime-kernel.js +3 -0
- package/src/codegen/integrated-compiled-app.js +3 -0
- package/src/codegen/json-body.js +3 -0
- package/src/codegen/library-sidecars.js +3 -0
- package/src/codegen/local-harness-ts.js +453 -0
- package/src/codegen/pulse-wrapper.js +217 -0
- package/src/codegen/request-result-headers.js +3 -0
- package/src/codegen/schema-json-compile.js +3 -0
- package/src/codegen/schema-json-sidecar-v2.js +3 -0
- package/src/codegen/schema-json-sidecar.js +3 -0
- package/src/codegen/streaming-passthrough.js +3 -0
- package/src/codegen/wasm-host-abi.js +3 -0
- package/src/codegen/wasm-host-bridge.js +3 -0
- package/src/compiled-wasm-host-runtime-kv.js +3 -0
- package/src/config-resolver.js +813 -0
- package/src/crypto-requirement-planner.js +89 -0
- package/src/definitions/config-schema.js +14 -0
- package/src/definitions/handler-roles.js +14 -0
- package/src/definitions/path-grammar.js +14 -0
- package/src/definitions/router-api.js +14 -0
- package/src/diagnostics/codes.js +14 -0
- package/src/diagnostics/reporter.js +14 -0
- package/src/diagnostics.js +14 -0
- package/src/dispatch-table.js +400 -0
- package/src/events/event-emit.js +265 -0
- package/src/events/event-topology.js +127 -0
- package/src/execution-plan.js +463 -0
- package/src/extractor.js +2816 -0
- package/src/handler-eval.js +1154 -0
- package/src/handler-table.js +326 -0
- package/src/index.js +19 -0
- package/src/javascript-application-plan.js +181 -0
- package/src/kv-provider.js +3 -0
- package/src/path-table.js +60 -0
- package/src/path.js +14 -0
- package/src/patterns/config-define.js +30 -0
- package/src/patterns/dependency-call.js +18 -0
- package/src/patterns/env-lookup.js +13 -0
- package/src/patterns/handler-reference.js +29 -0
- package/src/patterns/path-literal.js +35 -0
- package/src/patterns/result.js +15 -0
- package/src/patterns/router-chain-call.js +50 -0
- package/src/patterns/router-construction.js +19 -0
- package/src/project/package-reachability.js +782 -0
- package/src/project/reachable-graph-builder.js +992 -0
- package/src/project/reachable-graph-contract.js +54 -0
- package/src/project/reachable-graph-implementation.js +36 -0
- package/src/project/router-module-linker.js +710 -0
- package/src/project-config-compiler.js +222 -0
- package/src/project-target-support.js +500 -0
- package/src/provider-toolchain.js +299 -0
- package/src/spine/async-surface-normalizer.js +328 -0
- package/src/spine/canonical-handler-ir.js +336 -0
- package/src/spine/canonical-native-module.js +87 -0
- package/src/spine/canonical-native-plan.js +89 -0
- package/src/spine/canonical-project.js +76 -0
- package/src/spine/canonical-router.js +155 -0
- package/src/spine/canonical-source.js +165 -0
- package/src/spine/diagnostic-authority.js +290 -0
- package/src/spine/equivalence.js +262 -0
- package/src/spine/guest-unit-stage.js +87 -0
- package/src/spine/handler-ir-emitter.js +455 -0
- package/src/spine/handler-ir-managed.js +1598 -0
- package/src/spine/handler-ir.js +797 -0
- package/src/spine/handler-surface-authority.js +588 -0
- package/src/spine/package-operation-seam.js +1015 -0
- package/src/spine/pipeline.js +202 -0
- package/src/spine/plain-handler-frontend.js +545 -0
- package/src/spine/provider-requirement-authority.js +208 -0
- package/src/spine/router-control-contract.js +17 -0
- package/src/spine/router-handler-frontend.js +514 -0
- package/src/spine/router-handler-ir.js +372 -0
- package/src/spine/router-topology-frontend.js +638 -0
- package/src/stable-id.js +14 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function loadCompilerSpineContract() {
|
|
4
|
+
try {
|
|
5
|
+
return require('@pulse-compute/wasm-contracts/compiler-spine');
|
|
6
|
+
} catch (error) {
|
|
7
|
+
if (error && ['MODULE_NOT_FOUND', 'ERR_PACKAGE_PATH_NOT_EXPORTED'].includes(error.code)) {
|
|
8
|
+
return require('../../../contracts/src/spine.js');
|
|
9
|
+
}
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const compilerSpineContract = loadCompilerSpineContract();
|
|
15
|
+
const registry = compilerSpineContract.DEFAULT_COMPILER_SPINE_REGISTRY;
|
|
16
|
+
|
|
17
|
+
const compilerSpineRuntimeVersion = 'pulse.compiler-spine-runtime.v1';
|
|
18
|
+
const compilerSpineTraceVersion = 'pulse.compiler-spine-trace.v1';
|
|
19
|
+
|
|
20
|
+
class CompilerSpineRuntimeError extends Error {
|
|
21
|
+
constructor(code, message, detail = {}) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'CompilerSpineRuntimeError';
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.detail = Object.freeze({ ...detail });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function nonEmptyString(value, field) {
|
|
30
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
31
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_DEFINITION_INVALID', `${field} must be a non-empty string.`, { field, value });
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function phaseById(id) {
|
|
37
|
+
const phase = registry.phases.find((entry) => entry.id === id);
|
|
38
|
+
if (!phase) {
|
|
39
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_PHASE_UNKNOWN', `Unknown compiler spine phase ${id}.`, { phase: id });
|
|
40
|
+
}
|
|
41
|
+
return phase;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function orderedPhases(ids) {
|
|
45
|
+
if (!Array.isArray(ids) || ids.length === 0) {
|
|
46
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_DEFINITION_INVALID', 'Compiler spine segment requires at least one phase.');
|
|
47
|
+
}
|
|
48
|
+
const phases = ids.map((id) => phaseById(nonEmptyString(id, 'phase')));
|
|
49
|
+
for (let index = 1; index < phases.length; index += 1) {
|
|
50
|
+
if (phases[index - 1].order >= phases[index].order) {
|
|
51
|
+
throw new CompilerSpineRuntimeError(
|
|
52
|
+
'PULSE_COMPILER_SPINE_PHASE_ORDER_INVALID',
|
|
53
|
+
`Compiler spine segment phases must follow contract order: ${phases[index - 1].id} before ${phases[index].id}.`,
|
|
54
|
+
{ phases: ids }
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return Object.freeze(phases);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function definePhaseAdapter(definition) {
|
|
62
|
+
if (!definition || typeof definition !== 'object') {
|
|
63
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_DEFINITION_INVALID', 'Compiler spine adapter must be an object.');
|
|
64
|
+
}
|
|
65
|
+
const adapter = {
|
|
66
|
+
id: nonEmptyString(definition.id, 'adapter.id'),
|
|
67
|
+
phase: nonEmptyString(definition.phase, 'adapter.phase'),
|
|
68
|
+
mode: nonEmptyString(definition.mode, 'adapter.mode'),
|
|
69
|
+
inputKind: nonEmptyString(definition.inputKind, 'adapter.inputKind'),
|
|
70
|
+
outputKind: nonEmptyString(definition.outputKind, 'adapter.outputKind'),
|
|
71
|
+
run: definition.run
|
|
72
|
+
};
|
|
73
|
+
phaseById(adapter.phase);
|
|
74
|
+
if (typeof adapter.run !== 'function') {
|
|
75
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_DEFINITION_INVALID', `Compiler spine adapter ${adapter.id} requires a run function.`, { adapter: adapter.id });
|
|
76
|
+
}
|
|
77
|
+
return Object.freeze(adapter);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function definePassThroughAdapter(definition) {
|
|
81
|
+
return definePhaseAdapter({
|
|
82
|
+
...definition,
|
|
83
|
+
mode: definition.mode || 'legacy-pass-through',
|
|
84
|
+
run({ value }) {
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function defineCompilerSpineSegment(definition) {
|
|
91
|
+
if (!definition || typeof definition !== 'object') {
|
|
92
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_DEFINITION_INVALID', 'Compiler spine segment must be an object.');
|
|
93
|
+
}
|
|
94
|
+
const id = nonEmptyString(definition.id, 'segment.id');
|
|
95
|
+
const phases = orderedPhases(definition.phases);
|
|
96
|
+
if (!Array.isArray(definition.adapters)) {
|
|
97
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_DEFINITION_INVALID', `Compiler spine segment ${id} requires an adapters array.`);
|
|
98
|
+
}
|
|
99
|
+
const adaptersByPhase = new Map();
|
|
100
|
+
for (const raw of definition.adapters) {
|
|
101
|
+
const adapter = definePhaseAdapter(raw);
|
|
102
|
+
if (adaptersByPhase.has(adapter.phase)) {
|
|
103
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_ADAPTER_DUPLICATE', `Compiler spine segment ${id} has more than one adapter for ${adapter.phase}.`, { segment: id, phase: adapter.phase });
|
|
104
|
+
}
|
|
105
|
+
adaptersByPhase.set(adapter.phase, adapter);
|
|
106
|
+
}
|
|
107
|
+
for (const adapter of adaptersByPhase.values()) {
|
|
108
|
+
if (!phases.some((phase) => phase.id === adapter.phase)) {
|
|
109
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_ADAPTER_OUTSIDE_SEGMENT', `Compiler spine adapter ${adapter.id} targets phase ${adapter.phase} outside segment ${id}.`, { segment: id, adapter: adapter.id, phase: adapter.phase });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const phase of phases) {
|
|
113
|
+
if (!adaptersByPhase.has(phase.id)) {
|
|
114
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_ADAPTER_MISSING', `Compiler spine segment ${id} has no adapter for ${phase.id}.`, { segment: id, phase: phase.id });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const adapters = Object.freeze(phases.map((phase) => adaptersByPhase.get(phase.id)));
|
|
119
|
+
for (let index = 1; index < adapters.length; index += 1) {
|
|
120
|
+
const previous = adapters[index - 1];
|
|
121
|
+
const current = adapters[index];
|
|
122
|
+
if (previous.outputKind !== current.inputKind) {
|
|
123
|
+
throw new CompilerSpineRuntimeError(
|
|
124
|
+
'PULSE_COMPILER_SPINE_ADAPTER_SHAPE_MISMATCH',
|
|
125
|
+
`Compiler spine segment ${id} cannot pass ${previous.outputKind} from ${previous.id} into ${current.inputKind} for ${current.id}.`,
|
|
126
|
+
{
|
|
127
|
+
segment: id,
|
|
128
|
+
previousAdapter: previous.id,
|
|
129
|
+
previousOutputKind: previous.outputKind,
|
|
130
|
+
adapter: current.id,
|
|
131
|
+
inputKind: current.inputKind
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const descriptor = Object.freeze({
|
|
137
|
+
version: compilerSpineRuntimeVersion,
|
|
138
|
+
id,
|
|
139
|
+
contractVersion: registry.version,
|
|
140
|
+
contractId: registry.contractId,
|
|
141
|
+
phases: Object.freeze(phases.map((phase) => Object.freeze({
|
|
142
|
+
id: phase.id,
|
|
143
|
+
order: phase.order,
|
|
144
|
+
input: phase.input,
|
|
145
|
+
output: phase.output,
|
|
146
|
+
ruleIds: Object.freeze(registry.rulesForPhase(phase.id).map((rule) => rule.id))
|
|
147
|
+
}))),
|
|
148
|
+
adapters: Object.freeze(adapters.map((adapter) => Object.freeze({
|
|
149
|
+
id: adapter.id,
|
|
150
|
+
phase: adapter.phase,
|
|
151
|
+
mode: adapter.mode,
|
|
152
|
+
inputKind: adapter.inputKind,
|
|
153
|
+
outputKind: adapter.outputKind
|
|
154
|
+
})))
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
function run(input, context = {}) {
|
|
158
|
+
if (!context || typeof context !== 'object') {
|
|
159
|
+
throw new CompilerSpineRuntimeError('PULSE_COMPILER_SPINE_CONTEXT_INVALID', `Compiler spine segment ${id} context must be an object.`, { segment: id });
|
|
160
|
+
}
|
|
161
|
+
const readonlyContext = Object.freeze({ ...context });
|
|
162
|
+
const trace = [];
|
|
163
|
+
let value = input;
|
|
164
|
+
for (let index = 0; index < phases.length; index += 1) {
|
|
165
|
+
const phase = phases[index];
|
|
166
|
+
const adapter = adapters[index];
|
|
167
|
+
const rules = registry.rulesForPhase(phase.id);
|
|
168
|
+
value = adapter.run(Object.freeze({ value, context: readonlyContext, phase, rules }));
|
|
169
|
+
trace.push(Object.freeze({
|
|
170
|
+
phase: phase.id,
|
|
171
|
+
order: phase.order,
|
|
172
|
+
adapter: adapter.id,
|
|
173
|
+
mode: adapter.mode,
|
|
174
|
+
inputKind: adapter.inputKind,
|
|
175
|
+
outputKind: adapter.outputKind,
|
|
176
|
+
ruleIds: Object.freeze(rules.map((rule) => rule.id))
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
return Object.freeze({
|
|
180
|
+
output: value,
|
|
181
|
+
trace: Object.freeze({
|
|
182
|
+
version: compilerSpineTraceVersion,
|
|
183
|
+
runtimeVersion: compilerSpineRuntimeVersion,
|
|
184
|
+
contractVersion: registry.version,
|
|
185
|
+
contractId: registry.contractId,
|
|
186
|
+
segment: id,
|
|
187
|
+
phases: Object.freeze(trace)
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return Object.freeze({ ...descriptor, run });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
module.exports = Object.freeze({
|
|
196
|
+
runtimeVersion: compilerSpineRuntimeVersion,
|
|
197
|
+
traceVersion: compilerSpineTraceVersion,
|
|
198
|
+
CompilerSpineRuntimeError,
|
|
199
|
+
definePhaseAdapter,
|
|
200
|
+
definePassThroughAdapter,
|
|
201
|
+
defineCompilerSpineSegment
|
|
202
|
+
});
|