@pulse-compute/provider-node 0.0.0 → 1.0.0-beta.1
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 +60 -1
- package/package.json +61 -6
- package/src/capabilities.js +56 -0
- package/src/compiler/assets-provider-proof.js +434 -0
- package/src/compiler/backend-json-request-body-proof.js +90 -0
- package/src/compiler/index.js +38 -0
- package/src/compiler/node-adapter.js +452 -0
- package/src/compiler/node-compiled-wasm-assets-lifecycle-proof.js +435 -0
- package/src/compiler/request-json-body-proof.js +181 -0
- package/src/compiler/route-handler-compiled-wasm-bridge.js +323 -0
- package/src/compiler/route-handler-effect-proof.js +215 -0
- package/src/compiler/route-handler-live-origin-proof.js +372 -0
- package/src/compiler/schema-decode-result-proof.js +180 -0
- package/src/compiler/schema-response-codec-proof.js +149 -0
- package/src/events/reference-adapter.js +145 -0
- package/src/index.js +57 -0
- package/src/javascript/assets-adapter.js +68 -0
- package/src/javascript/bindings-adapter.js +120 -0
- package/src/javascript/fetch-adapter.js +187 -0
- package/src/javascript/grip-broadcast.js +243 -0
- package/src/javascript/jwt-verifier.js +137 -0
- package/src/javascript/lifecycle.js +69 -0
- package/src/javascript/node-adapter.js +281 -0
- package/src/javascript/package-effects.js +78 -0
- package/src/javascript/runtime-host.js +165 -0
- package/src/javascript/source-package.js +439 -0
- package/src/javascript/support.js +205 -0
- package/src/javascript/target-support-policy.js +134 -0
- package/src/javascript/target.js +37 -0
- package/src/javascript/test-runtime.js +111 -0
- package/src/native/target.js +78 -0
- package/src/runtime/assets-provider.js +776 -0
- package/src/runtime/canonical-api-runtime.js +632 -0
- package/src/runtime/compiled-wasm-node-adapter-kv.js +15 -0
- package/src/runtime/index.js +17 -0
- package/src/runtime/jwt-verifier.js +264 -0
- package/src/runtime/route-handler-effects.js +757 -0
- package/src/toolchain.js +258 -0
package/src/toolchain.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const {
|
|
5
|
+
PROVIDER_DRIVER_VERSION,
|
|
6
|
+
PROVIDER_TARGET_RESULT_VERSION,
|
|
7
|
+
PROVIDER_PACKAGING_AUDIT_VERSION,
|
|
8
|
+
defineProviderToolchain,
|
|
9
|
+
defineProviderDriver,
|
|
10
|
+
normalizeProviderTargetResult,
|
|
11
|
+
normalizeProviderJavascriptPackageResult
|
|
12
|
+
} = require('@pulse-compute/wasm-contracts/provider/toolchain');
|
|
13
|
+
const canonicalProvider = require('@pulse-compute/wasm-contracts/provider/canonical-provider');
|
|
14
|
+
const nodeRuntime = require('./runtime/canonical-api-runtime.js');
|
|
15
|
+
const { NODE_NATIVE_TARGET_DESCRIPTOR } = require('./native/target.js');
|
|
16
|
+
const { NODE_JAVASCRIPT_TARGET_DESCRIPTOR } = require('./javascript/target.js');
|
|
17
|
+
const { NODE_JAVASCRIPT_TARGET_SUPPORT_DECLARATION } = require('./javascript/support.js');
|
|
18
|
+
const {
|
|
19
|
+
classifyNodeJavascriptCapability,
|
|
20
|
+
classifyNodeJavascriptProviderRequirement
|
|
21
|
+
} = require('./javascript/target-support-policy.js');
|
|
22
|
+
const nodeJavascriptHost = require('./javascript/runtime-host.js');
|
|
23
|
+
const nodeJavascriptLifecycle = require('./javascript/lifecycle.js');
|
|
24
|
+
const nodeJavascriptTestRuntime = require('./javascript/test-runtime.js');
|
|
25
|
+
const { createNodeEventReferenceAdapter } = require('./events/reference-adapter.js');
|
|
26
|
+
const { writeNodeJavascriptSourcePackage } = require('./javascript/source-package.js');
|
|
27
|
+
const packageManifest = require('../package.json');
|
|
28
|
+
|
|
29
|
+
const reportingTargetCapability = Object.freeze({
|
|
30
|
+
supported: true,
|
|
31
|
+
default: 'info',
|
|
32
|
+
levels: Object.freeze(['off', 'error', 'warn', 'info', 'debug'])
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function genericProviderConfig() {
|
|
36
|
+
return Object.freeze({ kind: 'node', bindings: Object.freeze({}), local: Object.freeze({}) });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function nodeRealization(nativeArtifact) {
|
|
40
|
+
return Object.freeze({
|
|
41
|
+
target: 'node-native-host',
|
|
42
|
+
provider: 'node',
|
|
43
|
+
providerNeutralWasm: true,
|
|
44
|
+
nativeWasm: true,
|
|
45
|
+
compiledWasmPresent: true,
|
|
46
|
+
sourceOnly: false,
|
|
47
|
+
sourceOnlySupported: false,
|
|
48
|
+
javascriptRuntime: false,
|
|
49
|
+
jsComputeRuntime: false,
|
|
50
|
+
wasm: nativeArtifact.manifest.wasm,
|
|
51
|
+
wat: nativeArtifact.manifest.wat,
|
|
52
|
+
importModules: nativeArtifact.manifest.importModules,
|
|
53
|
+
imports: nativeArtifact.manifest.imports,
|
|
54
|
+
exports: nativeArtifact.manifest.exports,
|
|
55
|
+
packageRealizationArtifacts: nativeArtifact.manifest.packageRealizationArtifacts,
|
|
56
|
+
compiler: Object.freeze({
|
|
57
|
+
package: nativeArtifact.manifest.assemblyScript.package,
|
|
58
|
+
version: nativeArtifact.manifest.assemblyScript.version,
|
|
59
|
+
targetCompilerVersion: nativeArtifact.compilerVersion
|
|
60
|
+
}),
|
|
61
|
+
optimization: nativeArtifact.manifest.optimization
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function targetSupportContext(_compiled, _project, declaration) {
|
|
66
|
+
const gates = declaration.availability && declaration.availability.gates || [];
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
bindingsRedaction: gates.some((entry) => entry.id === 'bindings-redaction' && entry.status === 'satisfied'),
|
|
69
|
+
gripRealized: gates.some((entry) => entry.id === 'grip-readiness' && entry.evidence && entry.evidence.status === 'passed')
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function executeNodeEventTestCase(invocation = {}) {
|
|
74
|
+
const target = String(invocation.target || '');
|
|
75
|
+
if (!['javascript', 'native'].includes(target)) {
|
|
76
|
+
throw new TypeError(`Node event test execution does not support target ${JSON.stringify(target)}.`);
|
|
77
|
+
}
|
|
78
|
+
const testCase = invocation.testCase || {};
|
|
79
|
+
const options = invocation.options || {};
|
|
80
|
+
const adapter = createNodeEventReferenceAdapter({
|
|
81
|
+
id: `pulse-test-${target}`,
|
|
82
|
+
maxQueueDepth: 1024
|
|
83
|
+
});
|
|
84
|
+
let executionEvidence = null;
|
|
85
|
+
const common = {
|
|
86
|
+
application: options.application,
|
|
87
|
+
config: testCase.config || {},
|
|
88
|
+
secrets: testCase.secrets || {},
|
|
89
|
+
kv: testCase.kv || {},
|
|
90
|
+
grip: testCase.grip || {},
|
|
91
|
+
fetches: testCase.fetches || {},
|
|
92
|
+
eventAdapter: adapter,
|
|
93
|
+
schemaCodecs: options.schemaCodecs,
|
|
94
|
+
reporting: options.reporting,
|
|
95
|
+
maxEffects: options.maxEffects,
|
|
96
|
+
maxBindingNameBytes: options.maxBindingNameBytes,
|
|
97
|
+
maxBindingValueBytes: options.maxBindingValueBytes,
|
|
98
|
+
maxKvNamespaceBytes: options.maxKvNamespaceBytes,
|
|
99
|
+
maxKvKeyBytes: options.maxKvKeyBytes,
|
|
100
|
+
maxKvValueBytes: options.maxKvValueBytes,
|
|
101
|
+
maxKvValueDepth: options.maxKvValueDepth,
|
|
102
|
+
maxKvValueEntries: options.maxKvValueEntries
|
|
103
|
+
};
|
|
104
|
+
const result = target === 'javascript'
|
|
105
|
+
? await nodeJavascriptHost.executeNodeJavascriptEvent(invocation.application, testCase.event, {
|
|
106
|
+
...common,
|
|
107
|
+
fetchImplementation: nodeJavascriptHost.createNodeJavascriptFixtureFetch(
|
|
108
|
+
testCase.fetches || {},
|
|
109
|
+
options.networkFetch === true ? globalThis.fetch : undefined
|
|
110
|
+
),
|
|
111
|
+
onEffectSummary(value) { executionEvidence = value; }
|
|
112
|
+
})
|
|
113
|
+
: await nodeRuntime.executeNodeNativeEvent(invocation.application, testCase.event, {
|
|
114
|
+
...common,
|
|
115
|
+
onEventExecutionEvidence(value) { executionEvidence = value; }
|
|
116
|
+
});
|
|
117
|
+
return Object.freeze({
|
|
118
|
+
version: 'pulse.provider-event-test-result.v1',
|
|
119
|
+
target,
|
|
120
|
+
result,
|
|
121
|
+
emittedFrames: adapter.acceptedFrames(),
|
|
122
|
+
adapter: adapter.summary(),
|
|
123
|
+
executionEvidence
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function createDriver() {
|
|
128
|
+
return defineProviderDriver({
|
|
129
|
+
version: PROVIDER_DRIVER_VERSION,
|
|
130
|
+
id: 'node',
|
|
131
|
+
descriptor: nodeRuntime.NODE_PROVIDER_DESCRIPTOR,
|
|
132
|
+
executable: true,
|
|
133
|
+
localExecution: true,
|
|
134
|
+
deployable: true,
|
|
135
|
+
deploymentValidated: false,
|
|
136
|
+
sourcePackage: false,
|
|
137
|
+
compiledWasm: true,
|
|
138
|
+
defaultBuildMode: 'native-provider',
|
|
139
|
+
sourceOnlySupported: false,
|
|
140
|
+
targetSupport: Object.freeze({ javascript: NODE_JAVASCRIPT_TARGET_SUPPORT_DECLARATION }),
|
|
141
|
+
normalizeConfig: genericProviderConfig,
|
|
142
|
+
defaultLocalNetworkFetch: true,
|
|
143
|
+
projectConfigDocument() { return undefined; },
|
|
144
|
+
initTemplate() {
|
|
145
|
+
return Object.freeze({ profileFragment: '', dependencies: Object.freeze({}) });
|
|
146
|
+
},
|
|
147
|
+
executionOptions(_config, values) {
|
|
148
|
+
return Object.freeze({
|
|
149
|
+
...values,
|
|
150
|
+
providerAdapter: nodeRuntime.createNodeProviderAdapter()
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
javascript: Object.freeze({
|
|
154
|
+
kind: 'reference-node',
|
|
155
|
+
localEmulation: false,
|
|
156
|
+
buildTimeLoader: false,
|
|
157
|
+
validateApplication: nodeJavascriptHost.assertNodeJavascriptApplication,
|
|
158
|
+
targetSupportPolicy: Object.freeze({
|
|
159
|
+
providerId: 'node',
|
|
160
|
+
declaration: NODE_JAVASCRIPT_TARGET_SUPPORT_DECLARATION,
|
|
161
|
+
context: targetSupportContext,
|
|
162
|
+
classifyCapability: classifyNodeJavascriptCapability,
|
|
163
|
+
classifyProviderRequirement: classifyNodeJavascriptProviderRequirement
|
|
164
|
+
}),
|
|
165
|
+
writeSourcePackage(invocation) {
|
|
166
|
+
return normalizeProviderJavascriptPackageResult(writeNodeJavascriptSourcePackage({
|
|
167
|
+
plan: invocation.applicationPlan,
|
|
168
|
+
projectRoot: invocation.project.root,
|
|
169
|
+
outDir: invocation.project.outDir,
|
|
170
|
+
schemaBundle: invocation.javascript.schemaBundle
|
|
171
|
+
}), { provider: 'node' });
|
|
172
|
+
},
|
|
173
|
+
describeSourcePackage(sourcePackage) {
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
deploymentCandidate: false,
|
|
176
|
+
downstreamJavascriptRuntimeWasm: false,
|
|
177
|
+
application: Object.freeze({
|
|
178
|
+
entry: path.basename(sourcePackage.paths.entry),
|
|
179
|
+
modules: sourcePackage.manifest.summary.modules
|
|
180
|
+
}),
|
|
181
|
+
files: Object.freeze({})
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
executeTestCase(application, testCase, options) {
|
|
185
|
+
return nodeJavascriptTestRuntime.executeNodeJavascriptTestCase(application, testCase, options);
|
|
186
|
+
},
|
|
187
|
+
createServer: nodeJavascriptLifecycle.createNodeJavascriptServer,
|
|
188
|
+
createFixtureFetch: nodeJavascriptHost.createNodeJavascriptFixtureFetch
|
|
189
|
+
}),
|
|
190
|
+
events: Object.freeze({
|
|
191
|
+
targets: Object.freeze(['javascript', 'native']),
|
|
192
|
+
executeTestCase: executeNodeEventTestCase
|
|
193
|
+
}),
|
|
194
|
+
targets: Object.freeze({
|
|
195
|
+
native: Object.freeze({
|
|
196
|
+
...NODE_NATIVE_TARGET_DESCRIPTOR,
|
|
197
|
+
target: 'native',
|
|
198
|
+
targetId: 'node-native-host',
|
|
199
|
+
runtimeClass: 'native',
|
|
200
|
+
status: 'supported',
|
|
201
|
+
automaticFallback: false,
|
|
202
|
+
reporting: reportingTargetCapability,
|
|
203
|
+
commands: Object.freeze({ compile: true, inspect: true, doctor: true, build: true, test: true, dev: true })
|
|
204
|
+
}),
|
|
205
|
+
javascript: NODE_JAVASCRIPT_TARGET_DESCRIPTOR
|
|
206
|
+
}),
|
|
207
|
+
execute: nodeRuntime.executeCanonicalProgram,
|
|
208
|
+
createLoweringPlan(metadata) {
|
|
209
|
+
return canonicalProvider.createProviderLoweringPlan(metadata, nodeRuntime.NODE_PROVIDER_DESCRIPTOR, {
|
|
210
|
+
grip: 'node-reference-broadcaster'
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
inspectRealization(invocation) {
|
|
214
|
+
const realization = nodeRealization(invocation.nativeArtifact);
|
|
215
|
+
return normalizeProviderTargetResult({
|
|
216
|
+
version: PROVIDER_TARGET_RESULT_VERSION,
|
|
217
|
+
action: 'inspect-native',
|
|
218
|
+
provider: 'node',
|
|
219
|
+
target: 'native',
|
|
220
|
+
status: 'inspected',
|
|
221
|
+
automaticFallback: false,
|
|
222
|
+
files: Object.freeze({}),
|
|
223
|
+
build: null,
|
|
224
|
+
realization,
|
|
225
|
+
packaging: null
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
writeTarget(invocation) {
|
|
229
|
+
const realization = nodeRealization(invocation.nativeArtifact);
|
|
230
|
+
const audit = invocation.nativeArtifact.guestAudit;
|
|
231
|
+
return normalizeProviderTargetResult({
|
|
232
|
+
version: PROVIDER_TARGET_RESULT_VERSION,
|
|
233
|
+
action: 'write-native',
|
|
234
|
+
provider: 'node',
|
|
235
|
+
target: 'native',
|
|
236
|
+
status: 'built',
|
|
237
|
+
automaticFallback: false,
|
|
238
|
+
files: Object.freeze({}),
|
|
239
|
+
build: realization,
|
|
240
|
+
realization,
|
|
241
|
+
packaging: audit ? Object.freeze({
|
|
242
|
+
version: PROVIDER_PACKAGING_AUDIT_VERSION,
|
|
243
|
+
artifactSha256: invocation.nativeArtifact.finalArtifact.sha256,
|
|
244
|
+
auditedSha256: audit.finalArtifact.sha256,
|
|
245
|
+
authorized: audit.providerPackaging.authorized === true
|
|
246
|
+
}) : null
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = defineProviderToolchain({
|
|
253
|
+
version: 'pulse.provider-toolchain.v1',
|
|
254
|
+
id: 'node',
|
|
255
|
+
packageName: packageManifest.name,
|
|
256
|
+
packageVersion: packageManifest.version,
|
|
257
|
+
createDriver
|
|
258
|
+
});
|