@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.
Files changed (104) hide show
  1. package/README.md +53 -1
  2. package/bin/provider-proof-composition.js +34 -0
  3. package/bin/pulsewasm-extract.js +20 -0
  4. package/package.json +60 -5
  5. package/src/artifacts-dir.js +13 -0
  6. package/src/ast-json.js +52 -0
  7. package/src/build-manifest.js +354 -0
  8. package/src/canonical-api-compiler.js +269 -0
  9. package/src/canonical-native-compiler.js +411 -0
  10. package/src/canonical-native-plan.js +1478 -0
  11. package/src/canonical-project-compiler.js +1224 -0
  12. package/src/canonical-router-compiler.js +25 -0
  13. package/src/cli-intents.js +1235 -0
  14. package/src/cli.js +1927 -0
  15. package/src/codegen/assemblyscript-compile.js +3 -0
  16. package/src/codegen/assemblyscript-core.js +3 -0
  17. package/src/codegen/assemblyscript-shape.js +3 -0
  18. package/src/codegen/assemblyscript-wasm-smoke.js +3 -0
  19. package/src/codegen/backend-capabilities.js +3 -0
  20. package/src/codegen/channel-broadcaster.js +3 -0
  21. package/src/codegen/compiled-handlers.js +3 -0
  22. package/src/codegen/compiled-wasm-runtime.js +3 -0
  23. package/src/codegen/config-references.js +248 -0
  24. package/src/codegen/dispatch-ts.js +145 -0
  25. package/src/codegen/effect-composition.js +331 -0
  26. package/src/codegen/effect-runtime.js +418 -0
  27. package/src/codegen/execution-harness-ts.js +467 -0
  28. package/src/codegen/handler-bindings-ts.js +298 -0
  29. package/src/codegen/handler-library-contracts.js +3 -0
  30. package/src/codegen/host-capabilities.js +3 -0
  31. package/src/codegen/host-runtime-kernel.js +3 -0
  32. package/src/codegen/integrated-compiled-app.js +3 -0
  33. package/src/codegen/json-body.js +3 -0
  34. package/src/codegen/library-sidecars.js +3 -0
  35. package/src/codegen/local-harness-ts.js +453 -0
  36. package/src/codegen/pulse-wrapper.js +217 -0
  37. package/src/codegen/request-result-headers.js +3 -0
  38. package/src/codegen/schema-json-compile.js +3 -0
  39. package/src/codegen/schema-json-sidecar-v2.js +3 -0
  40. package/src/codegen/schema-json-sidecar.js +3 -0
  41. package/src/codegen/streaming-passthrough.js +3 -0
  42. package/src/codegen/wasm-host-abi.js +3 -0
  43. package/src/codegen/wasm-host-bridge.js +3 -0
  44. package/src/compiled-wasm-host-runtime-kv.js +3 -0
  45. package/src/config-resolver.js +813 -0
  46. package/src/crypto-requirement-planner.js +89 -0
  47. package/src/definitions/config-schema.js +14 -0
  48. package/src/definitions/handler-roles.js +14 -0
  49. package/src/definitions/path-grammar.js +14 -0
  50. package/src/definitions/router-api.js +14 -0
  51. package/src/diagnostics/codes.js +14 -0
  52. package/src/diagnostics/reporter.js +14 -0
  53. package/src/diagnostics.js +14 -0
  54. package/src/dispatch-table.js +400 -0
  55. package/src/events/event-emit.js +265 -0
  56. package/src/events/event-topology.js +127 -0
  57. package/src/execution-plan.js +463 -0
  58. package/src/extractor.js +2816 -0
  59. package/src/handler-eval.js +1154 -0
  60. package/src/handler-table.js +326 -0
  61. package/src/index.js +19 -0
  62. package/src/javascript-application-plan.js +181 -0
  63. package/src/kv-provider.js +3 -0
  64. package/src/path-table.js +60 -0
  65. package/src/path.js +14 -0
  66. package/src/patterns/config-define.js +30 -0
  67. package/src/patterns/dependency-call.js +18 -0
  68. package/src/patterns/env-lookup.js +13 -0
  69. package/src/patterns/handler-reference.js +29 -0
  70. package/src/patterns/path-literal.js +35 -0
  71. package/src/patterns/result.js +15 -0
  72. package/src/patterns/router-chain-call.js +50 -0
  73. package/src/patterns/router-construction.js +19 -0
  74. package/src/project/package-reachability.js +782 -0
  75. package/src/project/reachable-graph-builder.js +992 -0
  76. package/src/project/reachable-graph-contract.js +54 -0
  77. package/src/project/reachable-graph-implementation.js +36 -0
  78. package/src/project/router-module-linker.js +710 -0
  79. package/src/project-config-compiler.js +222 -0
  80. package/src/project-target-support.js +500 -0
  81. package/src/provider-toolchain.js +299 -0
  82. package/src/spine/async-surface-normalizer.js +328 -0
  83. package/src/spine/canonical-handler-ir.js +336 -0
  84. package/src/spine/canonical-native-module.js +87 -0
  85. package/src/spine/canonical-native-plan.js +89 -0
  86. package/src/spine/canonical-project.js +76 -0
  87. package/src/spine/canonical-router.js +155 -0
  88. package/src/spine/canonical-source.js +165 -0
  89. package/src/spine/diagnostic-authority.js +290 -0
  90. package/src/spine/equivalence.js +262 -0
  91. package/src/spine/guest-unit-stage.js +87 -0
  92. package/src/spine/handler-ir-emitter.js +455 -0
  93. package/src/spine/handler-ir-managed.js +1598 -0
  94. package/src/spine/handler-ir.js +797 -0
  95. package/src/spine/handler-surface-authority.js +588 -0
  96. package/src/spine/package-operation-seam.js +1015 -0
  97. package/src/spine/pipeline.js +202 -0
  98. package/src/spine/plain-handler-frontend.js +545 -0
  99. package/src/spine/provider-requirement-authority.js +208 -0
  100. package/src/spine/router-control-contract.js +17 -0
  101. package/src/spine/router-handler-frontend.js +514 -0
  102. package/src/spine/router-handler-ir.js +372 -0
  103. package/src/spine/router-topology-frontend.js +638 -0
  104. package/src/stable-id.js +14 -0
@@ -0,0 +1,208 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ PROVIDER_REQUIREMENT_RECORD_VERSION,
5
+ normalizeProviderRequirementRecord
6
+ } = require('@pulse-compute/wasm-contracts/package/package-contract');
7
+
8
+ const PROVIDER_REQUIREMENT_AUTHORITY_VERSION = 'pulse.provider-requirement-authority.v1';
9
+
10
+ class ProviderRequirementAuthorityError extends Error {
11
+ constructor(code, message, detail = {}) {
12
+ super(message);
13
+ this.name = 'ProviderRequirementAuthorityError';
14
+ this.code = code;
15
+ this.detail = Object.freeze({ ...detail });
16
+ }
17
+ }
18
+
19
+ function cloneJson(value) {
20
+ return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
21
+ }
22
+
23
+ function deepFreeze(value) {
24
+ if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
25
+ for (const child of Object.values(value)) deepFreeze(child);
26
+ return Object.freeze(value);
27
+ }
28
+
29
+ function sortedUnique(values) {
30
+ return Object.freeze([...new Set((values || []).filter((value) => typeof value === 'string' && value.length > 0))].sort());
31
+ }
32
+
33
+ function providerOperation(effect) {
34
+ const operation = {
35
+ order: effect.order,
36
+ id: effect.id,
37
+ kind: effect.kind,
38
+ providerKind: effect.providerKind,
39
+ operation: effect.operation,
40
+ capability: effect.capability,
41
+ package: effect.package,
42
+ contractId: effect.contractId,
43
+ result: cloneJson(effect.result),
44
+ continuationId: effect.continuationId,
45
+ resource: cloneJson(effect.resource),
46
+ source: cloneJson(effect.source),
47
+ routeStableId: effect.routeStableId,
48
+ routeRuntimeId: effect.routeRuntimeId,
49
+ routeMethod: effect.routeMethod,
50
+ routePath: effect.routePath,
51
+ routerEntryStableId: effect.routerEntryStableId,
52
+ routerEntryKind: effect.routerEntryKind,
53
+ routerEntryIndex: effect.routerEntryIndex,
54
+ routerEntryPath: effect.routerEntryPath
55
+ };
56
+ return deepFreeze(Object.fromEntries(Object.entries(operation).filter(([, value]) => value !== undefined)));
57
+ }
58
+
59
+ function packageIdentity(effect) {
60
+ return deepFreeze({
61
+ contractId: String(effect.contractId || ''),
62
+ package: String(effect.package || ''),
63
+ import: String(effect.import || '')
64
+ });
65
+ }
66
+
67
+ function packageEffectIdentity(effect) {
68
+ return [effect && effect.contractId, effect && effect.package, effect && effect.import, effect && effect.kind, effect && effect.operation, effect && effect.capability, effect && effect.placement, effect && effect.range && effect.range.start, effect && effect.range && effect.range.end].join('|');
69
+ }
70
+
71
+ function assertPackageLoweringMatchesPlan(plan, packageLowering) {
72
+ const declared = (plan && plan.packages && Array.isArray(plan.packages.effects)) ? plan.packages.effects : [];
73
+ const lowered = packageLowering && Array.isArray(packageLowering.effects) ? packageLowering.effects : [];
74
+ if (declared.length !== lowered.length) {
75
+ throw new ProviderRequirementAuthorityError(
76
+ 'PULSE_PROVIDER_REQUIREMENT_PACKAGE_MISMATCH',
77
+ 'Canonical package lowering and native-plan package effects differ.',
78
+ { declared: declared.length, lowered: lowered.length }
79
+ );
80
+ }
81
+ for (let index = 0; index < declared.length; index += 1) {
82
+ if (packageEffectIdentity(declared[index]) !== packageEffectIdentity(lowered[index])) {
83
+ throw new ProviderRequirementAuthorityError(
84
+ 'PULSE_PROVIDER_REQUIREMENT_PACKAGE_MISMATCH',
85
+ 'Canonical package lowering changed package-effect identity or order.',
86
+ { index, declared: cloneJson(declared[index]), lowered: cloneJson(lowered[index]) }
87
+ );
88
+ }
89
+ }
90
+ }
91
+
92
+ function collectProviderRequirements(plan, packageLowering) {
93
+ if (!plan || typeof plan !== 'object' || !Array.isArray(plan.effects) || !Array.isArray(plan.capabilities)) {
94
+ throw new ProviderRequirementAuthorityError('PULSE_PROVIDER_REQUIREMENT_PLAN_INVALID', 'Provider requirements require a canonical native plan.');
95
+ }
96
+ assertPackageLoweringMatchesPlan(plan, packageLowering);
97
+
98
+ const capabilities = sortedUnique(plan.capabilities.map(String));
99
+ const capabilitySet = new Set(capabilities);
100
+ for (const effect of plan.effects) {
101
+ if (effect.capability && !capabilitySet.has(String(effect.capability))) {
102
+ throw new ProviderRequirementAuthorityError(
103
+ 'PULSE_PROVIDER_REQUIREMENT_CAPABILITY_UNDECLARED',
104
+ `Canonical effect ${effect.id} requires undeclared capability ${effect.capability}.`,
105
+ { effectId: effect.id, capability: effect.capability }
106
+ );
107
+ }
108
+ }
109
+
110
+ const packageEffects = deepFreeze(cloneJson((plan.packages && plan.packages.effects) || []));
111
+ const packageMap = new Map();
112
+ for (const effect of packageEffects) {
113
+ const identity = packageIdentity(effect);
114
+ const key = `${identity.contractId}|${identity.package}|${identity.import}`;
115
+ if (!packageMap.has(key)) packageMap.set(key, identity);
116
+ }
117
+
118
+ return normalizeProviderRequirementRecord({
119
+ version: PROVIDER_REQUIREMENT_RECORD_VERSION,
120
+ authorityVersion: PROVIDER_REQUIREMENT_AUTHORITY_VERSION,
121
+ planVersion: String(plan.version || ''),
122
+ planHash: String(plan.planHash || ''),
123
+ providerNeutral: Boolean(plan.ownership && plan.ownership.providerNeutral),
124
+ capabilities,
125
+ providerKinds: sortedUnique(plan.effects.map((effect) => effect.providerKind)),
126
+ operations: Object.freeze(plan.effects.map(providerOperation)),
127
+ packageEffects,
128
+ packages: Object.freeze([...packageMap.values()]),
129
+ packageOperationIds: Object.freeze(packageLowering && packageLowering.operations
130
+ ? packageLowering.operations.map((operation) => String(operation.id))
131
+ : []),
132
+ hostCapabilities: sortedUnique(packageLowering && packageLowering.requiredHostCapabilities),
133
+ policy: Object.freeze({
134
+ providerSelected: false,
135
+ providerNeutralPlanRequired: true,
136
+ sourceAstAccepted: false,
137
+ sourceTextAccepted: false,
138
+ canonicalPlanOnly: true,
139
+ packageLoweringBundleOnly: true
140
+ })
141
+ });
142
+ }
143
+
144
+
145
+ function assertProviderRequirementsForPlan(requirements, plan) {
146
+ let normalized;
147
+ try {
148
+ normalized = normalizeProviderRequirementRecord(requirements);
149
+ } catch (error) {
150
+ throw new ProviderRequirementAuthorityError(
151
+ 'PULSE_PROVIDER_REQUIREMENT_RECORD_INVALID',
152
+ 'Expected a canonical provider requirement record.',
153
+ { version: requirements && requirements.version, cause: error && error.message }
154
+ );
155
+ }
156
+ const planHash = String(plan && plan.planHash || '');
157
+ if (!planHash || normalized.planHash !== planHash) {
158
+ throw new ProviderRequirementAuthorityError(
159
+ 'PULSE_PROVIDER_REQUIREMENT_PLAN_MISMATCH',
160
+ 'Provider requirements do not belong to the canonical native plan being realized.',
161
+ { planHash, requirementPlanHash: normalized.planHash }
162
+ );
163
+ }
164
+ if (normalized.planVersion !== String(plan && plan.version || '')) {
165
+ throw new ProviderRequirementAuthorityError(
166
+ 'PULSE_PROVIDER_REQUIREMENT_PLAN_VERSION_MISMATCH',
167
+ 'Provider requirements were produced for a different canonical native-plan version.',
168
+ { planVersion: plan && plan.version, requirementPlanVersion: normalized.planVersion }
169
+ );
170
+ }
171
+ if (normalized.providerNeutral !== true) {
172
+ throw new ProviderRequirementAuthorityError(
173
+ 'PULSE_PROVIDER_REQUIREMENT_PROVIDER_NEUTRAL_REQUIRED',
174
+ 'Canonical native realization requires provider-neutral requirements.',
175
+ { providerNeutral: normalized.providerNeutral }
176
+ );
177
+ }
178
+ return normalized;
179
+ }
180
+
181
+ function providerRequirementSnapshot(requirements) {
182
+ let normalized;
183
+ try {
184
+ normalized = normalizeProviderRequirementRecord(requirements);
185
+ } catch (error) {
186
+ throw new ProviderRequirementAuthorityError(
187
+ 'PULSE_PROVIDER_REQUIREMENT_RECORD_INVALID',
188
+ 'Expected a canonical provider requirement record.',
189
+ { cause: error && error.message }
190
+ );
191
+ }
192
+ return deepFreeze({
193
+ capabilities: cloneJson(normalized.capabilities),
194
+ providerKinds: cloneJson(normalized.providerKinds),
195
+ operations: cloneJson(normalized.operations),
196
+ packageEffects: cloneJson(normalized.packageEffects),
197
+ packages: cloneJson(normalized.packages)
198
+ });
199
+ }
200
+
201
+ module.exports = Object.freeze({
202
+ PROVIDER_REQUIREMENT_AUTHORITY_VERSION,
203
+ PROVIDER_REQUIREMENT_RECORD_VERSION,
204
+ ProviderRequirementAuthorityError,
205
+ collectProviderRequirements,
206
+ assertProviderRequirementsForPlan,
207
+ providerRequirementSnapshot
208
+ });
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const ROUTER_CONTROL_CONTRACT_VERSION = 'pulse.router-control-contract.v1';
4
+ const ROUTER_CURSOR_IDENTIFIER = '__pulse_router_cursor';
5
+ const ROUTER_MODE_IDENTIFIER = '__pulse_router_mode';
6
+ const ROUTER_ERROR_IDENTIFIER = '__pulse_router_error';
7
+ const ROUTER_NORMAL_MODE = 0;
8
+ const ROUTER_ERROR_MODE = 1;
9
+
10
+ module.exports = Object.freeze({
11
+ ROUTER_CONTROL_CONTRACT_VERSION,
12
+ ROUTER_CURSOR_IDENTIFIER,
13
+ ROUTER_MODE_IDENTIFIER,
14
+ ROUTER_ERROR_IDENTIFIER,
15
+ ROUTER_NORMAL_MODE,
16
+ ROUTER_ERROR_MODE
17
+ });