@pulse-compute/provider-fastly 1.0.0-beta.4 → 1.0.0-beta.6

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 (46) hide show
  1. package/README.md +6 -6
  2. package/dist/config-schema.json +10 -0
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +1 -1
  7. package/package.json +11 -11
  8. package/src/build/canonical-target.js +15 -2
  9. package/src/build/digest-native.js +25 -0
  10. package/src/build/effect-invocations.js +49 -0
  11. package/src/build/embedded-assets.as.ts +32 -0
  12. package/src/build/kv-native.as.ts +18 -8
  13. package/src/build/native-application-errors.js +140 -0
  14. package/src/build/native-http-effects.js +87 -22
  15. package/src/build/native-platform-capabilities.js +480 -151
  16. package/src/build/native-request-body.js +44 -0
  17. package/src/build/native-request-headers.js +93 -0
  18. package/src/build/native-string-values.js +113 -0
  19. package/src/build/native-value-budget.js +58 -0
  20. package/src/build/package-native-application.js +94 -0
  21. package/src/build/request-budget.as.ts +49 -0
  22. package/src/build/request-budget.js +45 -0
  23. package/src/build/s3-body.as.ts +97 -0
  24. package/src/build/s3-native.as.ts +12 -4
  25. package/src/build/s3-native.js +2 -2
  26. package/src/build/schema-admission.js +83 -0
  27. package/src/build/schema-nested-json.js +93 -0
  28. package/src/build/schema-scalar-record.js +41 -0
  29. package/src/build/time-native.js +49 -0
  30. package/src/build/wasm-budget.js +28 -0
  31. package/src/config-api.js +3 -0
  32. package/src/config-schema.json +10 -0
  33. package/src/index.ts +9 -0
  34. package/src/javascript/jwt-verifier.js +14 -4
  35. package/src/javascript/package-effects.js +5 -2
  36. package/src/javascript/runtime-host.js +5 -2
  37. package/src/javascript/target-support-policy.js +18 -5
  38. package/src/javascript/target.js +16 -1
  39. package/src/provider-contract.js +7 -3
  40. package/src/runtime/canonical-api-runtime.js +2 -0
  41. package/src/testing/native-http-effects-host.js +5 -1
  42. package/src/testing/native-platform-capabilities-host.js +78 -6
  43. package/src/toolchain/config.js +8 -1
  44. package/src/toolchain/index.js +31 -2
  45. package/src/toolchain/native-execution.js +1 -0
  46. package/src/toolchain/s3.js +2 -2
package/README.md CHANGED
@@ -7,9 +7,9 @@
7
7
  > **Supported entry points:** `@pulse-compute/provider-fastly`, `@pulse-compute/provider-fastly/contract`, `@pulse-compute/provider-fastly/toolchain`, `@pulse-compute/provider-fastly/config-schema`, `@pulse-compute/provider-fastly/runtime/canonical-api-runtime`, `@pulse-compute/provider-fastly/build/canonical-target`, `@pulse-compute/provider-fastly/testing/fastly-cli`<br>
8
8
  > **Stability:** The listed entry points are supported for the Beta; all other exported subpaths are implementation-only.<br>
9
9
  > **npm:** [`@pulse-compute/provider-fastly`](https://www.npmjs.com/package/@pulse-compute/provider-fastly)<br>
10
- > **Canonical documentation:** [Package guide](https://pulsecompute.io/v1.0.0-beta.4/packages/provider-fastly/)
10
+ > **Canonical documentation:** [Package guide](https://pulsecompute.io/v1.0.0-beta.6/packages/provider-fastly/)
11
11
  >
12
- > This release-status block is generated from the synchronized `Pulse 1.0.0-beta.4` package policy.
12
+ > This release-status block is generated from the synchronized `Pulse 1.0.0-beta.6` package policy.
13
13
  <!-- pulse-package-status:end -->
14
14
 
15
15
  Fastly provider configuration, canonical capability lowering, local conformance execution, Compute target generation, and explicit external-tool boundaries.
@@ -49,7 +49,7 @@ trusted wall-clock authority. It does not fall back to Node execution.
49
49
 
50
50
  ## Documentation
51
51
 
52
- - [Fastly package guide](https://pulsecompute.io/v1.0.0-beta.4/packages/provider-fastly/)
53
- - [Project configuration](https://pulsecompute.io/v1.0.0-beta.4/reference/project-config/#fastly-provider-options)
54
- - [Fastly capabilities guide](https://pulsecompute.io/v1.0.0-beta.4/guides/fastly-capabilities/)
55
- - [Environment variables](https://pulsecompute.io/v1.0.0-beta.4/reference/environment/#pulse-fastly-bin)
52
+ - [Fastly package guide](https://pulsecompute.io/v1.0.0-beta.6/packages/provider-fastly/)
53
+ - [Project configuration](https://pulsecompute.io/v1.0.0-beta.6/reference/project-config/#fastly-provider-options)
54
+ - [Fastly capabilities guide](https://pulsecompute.io/v1.0.0-beta.6/guides/fastly-capabilities/)
55
+ - [Environment variables](https://pulsecompute.io/v1.0.0-beta.6/reference/environment/#pulse-fastly-bin)
@@ -72,6 +72,16 @@
72
72
  "fastly.local.networkFetch": {
73
73
  "kind": "boolean",
74
74
  "default": false
75
+ },
76
+ "fastly.maxDurationMs": {
77
+ "kind": "optional-number"
78
+ },
79
+ "fastly.build.maxWasmBytes": {
80
+ "kind": "positive-safe-integer",
81
+ "default": 4194304
82
+ },
83
+ "fastly.maxWasmBytes": {
84
+ "kind": "positive-safe-integer"
75
85
  }
76
86
  }
77
87
  }
package/dist/index.d.ts CHANGED
@@ -14,6 +14,9 @@ export interface PulseFastlyLocalOptions {
14
14
  readonly networkFetch?: boolean;
15
15
  }
16
16
  export interface PulseFastlyProviderOptions {
17
+ /** Inclusive final Native Wasm byte budget; default 4 MiB. */
18
+ readonly maxWasmBytes?: number;
19
+ readonly maxDurationMs?: number;
17
20
  readonly configStore?: string;
18
21
  readonly secretStore?: string;
19
22
  readonly kv?: Readonly<Record<string, string>>;
@@ -26,6 +29,7 @@ export interface PulseFastlyProviderOptions {
26
29
  readonly local?: PulseFastlyLocalOptions;
27
30
  }
28
31
  export interface PulseFastlyProviderConfig {
32
+ readonly maxDurationMs?: number;
29
33
  readonly kind: 'fastly';
30
34
  readonly version: typeof FASTLY_PROVIDER_API_VERSION;
31
35
  readonly bindings: {
@@ -47,6 +51,7 @@ export interface PulseFastlyProviderConfig {
47
51
  readonly dynamicBackends: boolean;
48
52
  };
49
53
  readonly build: {
54
+ readonly maxWasmBytes: number;
50
55
  readonly name: string;
51
56
  readonly description: string;
52
57
  readonly authors: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,2BAA2B,EAAG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,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;QACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;KAC5B,CAAC;IACF,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;KAChC,CAAC;IACF,QAAQ,CAAC,wBAAwB,EAAE,KAAK,CAAC;CAC1C;AA2BD,wBAAgB,MAAM,CAAC,OAAO,GAAE,0BAA+B,GAAG,yBAAyB,CAwB1F"}
package/dist/index.js CHANGED
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FASTLY_PROVIDER_API_VERSION = void 0;
7
7
  exports.fastly = fastly;
8
+ const { normalizeFastlyMaxWasmBytes } = require('../src/build/wasm-budget.js');
9
+ const { normalizeRequestDuration } = require('@pulse-compute/runtime/host');
8
10
  const config_schema_json_1 = __importDefault(require("./config-schema.json"));
9
11
  const fastlySchemaFields = config_schema_json_1.default.fields;
10
12
  const fastlyDefaults = Object.freeze(Object.fromEntries(Object.entries(fastlySchemaFields).filter(([, rule]) => Object.prototype.hasOwnProperty.call(rule, 'default')).map(([key, rule]) => [key, rule.default])));
@@ -37,6 +39,7 @@ function fastly(options = {}) {
37
39
  const normalizedGrip = options.grip === undefined ? undefined : gripBindings(options.grip);
38
40
  return Object.freeze({
39
41
  kind: 'fastly',
42
+ maxDurationMs: normalizeRequestDuration(options.maxDurationMs),
40
43
  version: exports.FASTLY_PROVIDER_API_VERSION,
41
44
  bindings: Object.freeze({
42
45
  configStore: String(options.configStore ?? fastlyDefaults['fastly.configStore']),
@@ -47,6 +50,7 @@ function fastly(options = {}) {
47
50
  dynamicBackends: options.dynamicBackends === undefined ? Boolean(fastlyDefaults['fastly.dynamicBackends']) : options.dynamicBackends === true
48
51
  }),
49
52
  build: Object.freeze({
53
+ maxWasmBytes: normalizeFastlyMaxWasmBytes(options.maxWasmBytes),
50
54
  name: String(options.name ?? fastlyDefaults['fastly.name']),
51
55
  description: String(options.description ?? fastlyDefaults['fastly.description']),
52
56
  authors: Object.freeze((options.authors ?? (Array.isArray(fastlyDefaults['fastly.authors']) ? fastlyDefaults['fastly.authors'] : [])).map(String)),
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AA+FA,wBAsBC;AArHD,8EAAwD;AAGxD,MAAM,kBAAkB,GAAG,4BAAoB,CAAC,MAAoD,CAAC;AACrG,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAsC,CAAC;AAE3O,QAAA,2BAA2B,GAAG,8BAAuC,CAAC;AAgEnF,SAAS,SAAS,CAAC,KAAmD;IACpE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5H,CAAC;AAED,SAAS,k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IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;YAC3D,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,IAAI,cAAc,CAAC,oBAAoB,CAAC,CAAC;YAChF,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAClJ,QAAQ,EAAE,OAAO;SAClB,CAAC;QACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,IAAI,cAAc,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC;QAC3H,wBAAwB,EAAE,KAAK;KAChC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-compute/provider-fastly",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "license": "Apache-2.0",
5
5
  "engines": {
6
6
  "node": "^22.14.0 || ^24.0.0"
@@ -59,15 +59,15 @@
59
59
  }
60
60
  },
61
61
  "dependencies": {
62
- "@pulse-compute/crypto": "1.0.0-beta.4",
63
- "@pulse-compute/jwt": "1.0.0-beta.4",
64
- "@pulse-compute/runtime": "1.0.0-beta.4",
65
- "@pulse-compute/s3": "1.0.0-beta.4",
66
- "@pulse-compute/wasm-build-support": "1.0.0-beta.4",
67
- "@pulse-compute/wasm-contracts": "1.0.0-beta.4",
68
- "@pulse-compute/wasm-guest-link": "1.0.0-beta.4",
69
- "@pulse-compute/wasm-host-runtime": "1.0.0-beta.4",
70
- "@pulse-compute/wasm-runtime-core-as": "1.0.0-beta.4",
62
+ "@pulse-compute/crypto": "1.0.0-beta.6",
63
+ "@pulse-compute/jwt": "1.0.0-beta.6",
64
+ "@pulse-compute/runtime": "1.0.0-beta.6",
65
+ "@pulse-compute/s3": "1.0.0-beta.6",
66
+ "@pulse-compute/wasm-build-support": "1.0.0-beta.6",
67
+ "@pulse-compute/wasm-contracts": "1.0.0-beta.6",
68
+ "@pulse-compute/wasm-guest-link": "1.0.0-beta.6",
69
+ "@pulse-compute/wasm-host-runtime": "1.0.0-beta.6",
70
+ "@pulse-compute/wasm-runtime-core-as": "1.0.0-beta.6",
71
71
  "esbuild": "0.28.1"
72
72
  },
73
73
  "types": "./dist/index.d.ts",
@@ -87,7 +87,7 @@
87
87
  "url": "git+https://github.com/pulse-compute/pulse.git",
88
88
  "directory": "packages/provider-fastly"
89
89
  },
90
- "homepage": "https://pulsecompute.io/v1.0.0-beta.4/packages/provider-fastly/",
90
+ "homepage": "https://pulsecompute.io/v1.0.0-beta.6/packages/provider-fastly/",
91
91
  "bugs": {
92
92
  "url": "https://github.com/pulse-compute/pulse/issues"
93
93
  },
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const crypto = require('node:crypto');
4
+ const { normalizeFastlyMaxWasmBytes, assertFastlyWasmBudget } = require('./wasm-budget.js');
4
5
  const fs = require('node:fs');
5
6
  const path = require('node:path');
6
7
  const { CANONICAL_NATIVE_PLAN_VERSION } = require('@pulse-compute/wasm-contracts/handler/canonical-native-plan');
@@ -222,6 +223,8 @@ function inspectFastlyCanonicalTarget(options = {}) {
222
223
  }
223
224
  const providerConfig = options.providerConfig || {};
224
225
  const bindings = options.bindings || providerConfig.bindings || {};
226
+ const maxWasmBytes = normalizeFastlyMaxWasmBytes(providerConfig.build?.maxWasmBytes);
227
+ if (isFastlyNativeArtifact(options.native)) assertFastlyWasmBudget(options.native.wasm.length, maxWasmBytes);
225
228
  const native = isFastlyNativeArtifact(options.native)
226
229
  ? assertExactProviderNative(options.native)
227
230
  : compileFastlyNativePlatformCapabilitiesPlan(plan, {
@@ -229,6 +232,8 @@ function inspectFastlyCanonicalTarget(options = {}) {
229
232
  projectRoot: options.projectRoot,
230
233
  profile: options.profile,
231
234
  bindings,
235
+ maxDurationMs: providerConfig.maxDurationMs,
236
+ maxWasmBytes,
232
237
  requirePlatformCapability: false,
233
238
  canonicalBuild: true,
234
239
  targetDescriptor: options.targetDescriptor,
@@ -239,8 +244,13 @@ function inspectFastlyCanonicalTarget(options = {}) {
239
244
  || (options.native && options.native.guestUnits),
240
245
  nativeOptimization: options.nativeOptimization
241
246
  || (options.experimentalNativeSize === true ? 'experimental-native-size' : undefined),
247
+ emitWat: options.emitWat,
242
248
  timeoutMs: options.compileTimeoutMs
243
249
  });
250
+ const duration = require('@pulse-compute/runtime/host').normalizeRequestDuration(providerConfig.maxDurationMs);
251
+ if (native.manifest.bindings?.maxDurationMs !== duration) {
252
+ throw providerBuildError('PULSE_REQUEST_DURATION_ARTIFACT_MISMATCH', 'Fastly artifact request deadline does not match the selected provider profile.');
253
+ }
244
254
  return Object.freeze({
245
255
  target: FASTLY_CANONICAL_TARGET,
246
256
  provider: 'fastly',
@@ -287,6 +297,8 @@ function writeFastlyCanonicalTarget(options = {}) {
287
297
  fs.mkdirSync(binDir, { recursive: true });
288
298
 
289
299
  let native;
300
+ const maxWasmBytes = normalizeFastlyMaxWasmBytes(providerConfig.build?.maxWasmBytes);
301
+ if (isFastlyNativeArtifact(options.native)) assertFastlyWasmBudget(options.native.wasm.length, maxWasmBytes);
290
302
  const auditedNative = isFastlyNativeArtifact(options.native)
291
303
  ? assertExactProviderNative(options.native)
292
304
  : null;
@@ -308,6 +320,7 @@ function writeFastlyCanonicalTarget(options = {}) {
308
320
  || (options.native && options.native.guestUnits),
309
321
  nativeOptimization: options.nativeOptimization
310
322
  || (options.experimentalNativeSize === true ? 'experimental-native-size' : undefined),
323
+ emitWat: options.emitWat,
311
324
  compileTimeoutMs: options.compileTimeoutMs
312
325
  });
313
326
  native = realization.native;
@@ -373,7 +386,7 @@ function writeFastlyCanonicalTarget(options = {}) {
373
386
  }),
374
387
  optimization: native.manifest.optimization,
375
388
  wasm: Object.freeze({ file: 'bin/main.wasm', ...native.manifest.wasm }),
376
- wat: Object.freeze({ file: 'bin/main.wat', ...native.manifest.wat }),
389
+ wat: Object.freeze({ file: written.watFile ? 'bin/main.wat' : null, ...native.manifest.wat }),
377
390
  imports: native.manifest.imports,
378
391
  importModules: native.manifest.importModules,
379
392
  exports: native.manifest.exports,
@@ -402,7 +415,7 @@ function writeFastlyCanonicalTarget(options = {}) {
402
415
  localEntry: 'fastly-entry.cjs',
403
416
  sourceEntry: 'src/main.as.ts',
404
417
  wasm: 'bin/main.wasm',
405
- wat: 'bin/main.wat',
418
+ wat: written.watFile ? 'bin/main.wat' : null,
406
419
  nativePlan: 'fastly-native-plan.json',
407
420
  nativeManifest: 'fastly-native-manifest.json',
408
421
  fastlyToml: 'fastly.toml',
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ function digestNativeSource(plan) {
5
+ if (!plan.effects.some(effect => effect.kind === 'crypto.digestText')) return '';
6
+ const selected = plan.crypto?.algorithms.find(entry => entry.algorithm === 'SHA-256');
7
+ if (!selected || selected.realization !== 'guest-source:pulse-hmac-as' || selected.automaticFallback !== false) throw new TypeError('Digest requires the selected Crypto SHA-256 guest source.');
8
+ const root = path.dirname(require.resolve('@pulse-compute/crypto/pulsewasm-native'));
9
+ return fs.readFileSync(path.join(root, 'as/digest-text.as.ts'), 'utf8') + `
10
+ function __pulse_fastly_digest_begin(index: i32, outer: __PulseFastlyValue): void {
11
+ const payload = __pulse_fastly_value(__pulse_fastly_payload_field(outer, 'invocation'))
12
+ const text = __pulse_fastly_value(__pulse_fastly_payload_field(payload, 'text'))
13
+ const digest = __pulse_crypto_digest_text(text.kind == PULSE_VALUE_STRING ? text.text : null)
14
+ if (text.kind == PULSE_VALUE_STRING) __pulse_fastly_remember_secret(text.text)
15
+ const result = host_value_object()
16
+ host_value_object_set(result, __pulse_fastly_string_value('status'), __pulse_fastly_string_value(digest.status))
17
+ if (digest.status == 'ok') {
18
+ host_value_object_set(result, __pulse_fastly_string_value('sha256'), __pulse_fastly_string_value(digest.sha256))
19
+ host_value_object_set(result, __pulse_fastly_string_value('byteLength'), host_value_number(f64(digest.byteLength)))
20
+ } else host_value_object_set(result, __pulse_fastly_string_value('reason'), __pulse_fastly_string_value(digest.reason))
21
+ __pulse_fastly_ready_effect(index, result)
22
+ }
23
+ `;
24
+ }
25
+ module.exports = { digestNativeSource };
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const { CANONICAL_EFFECT_INVOCATION_POLICY } = require('@pulse-compute/wasm-contracts/handler/canonical-runtime');
4
+
5
+ function runtimeSource(options = {}) {
6
+ return `
7
+ const PULSE_FASTLY_MAX_EFFECT_INVOCATIONS: i32 = ${CANONICAL_EFFECT_INVOCATION_POLICY.defaultMaxEffects}
8
+ let __pulse_invocation_count: i32 = 0
9
+ let __pulse_invocation_started: bool = false
10
+ let __pulse_invocation_closed: bool = false
11
+ let __pulse_invocation_failure: i32 = 171
12
+ const __pulse_invocation_tickets = new StaticArray<i32>(PULSE_FASTLY_EFFECT_COUNT)
13
+ function __pulse_invocation_begin(index: i32): bool {
14
+ if (__pulse_invocation_closed || index < 0 || index >= PULSE_FASTLY_EFFECT_COUNT
15
+ || unchecked(__pulse_invocation_tickets[index]) != 0) {
16
+ __pulse_fastly_fail(PULSE_ERROR_STATE, __pulse_invocation_failure, index); return false
17
+ }
18
+ if (__pulse_invocation_count >= PULSE_FASTLY_MAX_EFFECT_INVOCATIONS) {
19
+ __pulse_invocation_closed = true
20
+ __pulse_invocation_failure = 170
21
+ __pulse_fastly_fail(PULSE_ERROR_STATE, 170, index); return false
22
+ }
23
+ unchecked(__pulse_invocation_tickets[index] = ++__pulse_invocation_count)
24
+ return true
25
+ }
26
+ function __pulse_invocation_settle(index: i32, ticket: i32, result: i32): i32 {
27
+ if (__pulse_invocation_closed || index < 0 || index >= PULSE_FASTLY_EFFECT_COUNT
28
+ || ticket <= 0 || unchecked(__pulse_invocation_tickets[index]) != ticket) {
29
+ __pulse_fastly_fail(PULSE_ERROR_STATE, __pulse_invocation_failure, index); return 0
30
+ }
31
+ unchecked(__pulse_invocation_tickets[index] = 0)
32
+ return ${options.packageCompletion ? "result == 0 ? pulse_package_set_effect_failure(index) : pulse_set_effect_result(index, result)" : "pulse_set_effect_result(index, result)"}
33
+ }
34
+ function __pulse_invocation_close(): void {
35
+ __pulse_invocation_closed = true
36
+ for (let i = 0; i < PULSE_FASTLY_EFFECT_COUNT; i += 1) unchecked(__pulse_invocation_tickets[i] = 0)
37
+ }
38
+ `;
39
+ }
40
+
41
+ function instrument(source) {
42
+ const signature = 'function host_effect_begin(effectIndex: i32, payload: i32): void {';
43
+ if (!source.includes(signature)) throw new Error('Fastly invocation admission boundary drift.');
44
+ // Every guest-requested slot gets a ticket, including a group member suppressed
45
+ // by an earlier application error. Its undefined result can then be drained.
46
+ return source.replace(signature, signature + '\n if (!__pulse_invocation_begin(effectIndex)) return;');
47
+ }
48
+
49
+ module.exports = { runtimeSource, instrument, policy: CANONICAL_EFFECT_INVOCATION_POLICY };
@@ -0,0 +1,32 @@
1
+ function __pulse_embedded_request_header(name: string): string | null {
2
+ const values = __pulse_request_header_list(name, false);
3
+ return values.length ? values.join(', ') : null;
4
+ }
5
+ function __pulse_embedded_field(payload: __PulseFastlyValue, name: string): string { return __pulse_fastly_string(__pulse_fastly_payload_field(payload, name)); }
6
+ function __pulse_fastly_embedded_asset(payload: __PulseFastlyValue): i32 {
7
+ // Avoid exposing provider buffers as canonical application values.
8
+ const length = __pulse_fastly_value(__pulse_fastly_payload_field(payload, 'embeddedFound')).boolean != 0 ? i32(__pulse_fastly_number(__pulse_fastly_payload_field(payload, 'embeddedLength'))) : -1;
9
+ const etag = __pulse_embedded_field(payload, 'embeddedEtag'), method = __pulse_embedded_field(payload, 'method');
10
+ const selected = __pulse_embedded_selection(length, method, etag,
11
+ __pulse_embedded_request_header('if-none-match'), __pulse_embedded_request_header('range'), __pulse_embedded_request_header('if-range'));
12
+ if (__pulse_request_headers_failed) return 0;
13
+ const output = new __PulseFastlyValue(); output.kind = PULSE_VALUE_RESPONSE; output.status = selected.status;
14
+ if (selected.status != 400 && selected.status != 404) {
15
+ output.headers.push(new __PulseFastlyHeader('content-type', __pulse_embedded_field(payload, 'embeddedType')));
16
+ output.headers.push(new __PulseFastlyHeader('etag', etag)); output.headers.push(new __PulseFastlyHeader('accept-ranges', 'bytes'));
17
+ if (selected.contentRange.length) output.headers.push(new __PulseFastlyHeader('content-range', selected.contentRange));
18
+ if (selected.status == 200 || selected.status == 206) {
19
+ output.headers.push(new __PulseFastlyHeader('content-length', max<i32>(0, selected.end - selected.start + 1).toString()));
20
+ if (method != 'HEAD') output.binaryBody = __pulse_embedded_bytes(__pulse_embedded_field(payload, 'embeddedData'), selected.start, selected.end);
21
+ }
22
+ }
23
+ return __pulse_fastly_put(output);
24
+ }
25
+ function __pulse_fastly_write_binary(handle: i32, data: Uint8Array): i32 {
26
+ const written = new StaticArray<i32>(1); let offset = 0;
27
+ while (offset < data.length) {
28
+ if (fastly_http_body_write(handle, data.dataStart + offset, data.length - offset, 0, changetype<usize>(written)) != 0 || written[0] <= 0 || written[0] > data.length - offset) return 1;
29
+ offset += written[0];
30
+ }
31
+ return 0;
32
+ }
@@ -80,35 +80,40 @@ function __kv_number(value: f64): string {
80
80
  // Count the portable serialized value budget, including this boundary case.
81
81
  return text.endsWith('.0') ? text.substring(0, text.length - 2) : text;
82
82
  }
83
- function __kv_private(text: string): void {
83
+ // Return the same quoted form registered for redaction so validation and writes
84
+ // do not allocate and scan a second representation of each string or key.
85
+ function __kv_private(text: string): string {
84
86
  __pulse_fastly_remember_secret(text);
85
87
  const encoded = __pulse_fastly_quote(text);
86
88
  __pulse_fastly_remember_secret(encoded.substring(1, encoded.length - 1));
89
+ return encoded;
87
90
  }
88
91
  class __KvEncoder {
89
92
  reason: string = ''; entries: i32 = 0; bytes: i32 = 0;
90
- seen: Set<i32> = new Set<i32>(); parts: Array<string> = new Array<string>();
91
- add(text: string): void { this.bytes += String.UTF8.byteLength(text); if (this.bytes > __KV_valueBytes) this.reason = 'too-large'; else this.parts.push(text); }
93
+ seen: Set<i32> = new Set<i32>(); parts: Array<string> | null;
94
+ // Reads need the same validation and redaction walk, but no serialized output.
95
+ constructor(materialize: bool = true) { this.parts = materialize ? new Array<string>() : null; }
96
+ add(text: string): void { this.bytes += String.UTF8.byteLength(text); if (this.bytes > __KV_valueBytes) this.reason = 'too-large'; else if (this.parts !== null) this.parts!.push(text); }
92
97
  visit(handle: i32, depth: i32 = 0): void {
93
98
  if (this.reason.length) return;
94
99
  if (++this.entries > __KV_entries || depth > __KV_depth) { this.reason = 'too-large'; return; }
95
100
  const value = __pulse_fastly_value(handle);
96
101
  if (value.kind == PULSE_VALUE_NULL) this.add('null');
97
102
  else if (value.kind == PULSE_VALUE_BOOLEAN) this.add(value.boolean ? 'true' : 'false');
98
- else if (value.kind == PULSE_VALUE_STRING) { __kv_private(value.text); this.add(__pulse_fastly_quote(value.text)); }
103
+ else if (value.kind == PULSE_VALUE_STRING) this.add(__kv_private(value.text));
99
104
  else if (value.kind == PULSE_VALUE_NUMBER) { if (!isFinite(value.number)) this.reason = 'invalid-value'; else this.add(value.number == 0 ? '0' : __kv_number(value.number)); }
100
105
  else if (value.kind == PULSE_VALUE_ARRAY || value.kind == PULSE_VALUE_OBJECT) {
101
106
  if (this.seen.has(handle)) { this.reason = 'invalid-value'; return; } this.seen.add(handle);
102
107
  const object = value.kind == PULSE_VALUE_OBJECT; this.add(object ? '{' : '[');
103
108
  for (let i = 0; i < value.values.length && !this.reason.length; i++) {
104
109
  if (i) this.add(',');
105
- if (object) { __kv_private(value.keys[i]); this.add(__pulse_fastly_quote(value.keys[i]) + ':'); }
110
+ if (object) this.add(__kv_private(value.keys[i]) + ':');
106
111
  this.visit(value.values[i], depth + 1);
107
112
  }
108
113
  this.add(object ? '}' : ']');
109
114
  } else this.reason = 'invalid-value';
110
115
  }
111
- encode(handle: i32): string { this.visit(handle); return this.reason.length ? '' : this.parts.join(''); }
116
+ encode(handle: i32): string { this.visit(handle); return this.reason.length ? '' : this.parts!.join(''); }
112
117
  }
113
118
  function __pulse_fastly_kv_conditional_begin(index: i32, payload: __PulseFastlyValue): void {
114
119
  __kv_dispatched[index] = false;
@@ -171,8 +176,13 @@ function __kv_utf8(data: Uint8Array, length: i32): bool {
171
176
  }
172
177
  return true;
173
178
  }
179
+ // Each read is synchronous through owned-string decoding and parsing. Parallel
180
+ // effects enter their waits serially; no result or pending hostcall owns this
181
+ // scratch buffer. Only the written prefix is inspected, including after errors.
182
+ @lazy let __kv_read_buffer: Uint8Array | null = null;
174
183
  function __kv_read(index: i32, body: i32, generation: u64): i32 {
175
- const buffer = new Uint8Array(__KV_wireBytes + 1), written = new StaticArray<i32>(1); let count = 0;
184
+ if (__kv_read_buffer === null) __kv_read_buffer = new Uint8Array(__KV_wireBytes + 1);
185
+ const buffer = __kv_read_buffer!, written = new StaticArray<i32>(1); let count = 0;
176
186
  while (true) {
177
187
  const ready = __kv_ready(index, body); if (ready <= 0) return __kv_ready_failure(index, ready);
178
188
  written[0] = 0;
@@ -188,7 +198,7 @@ function __kv_read(index: i32, body: i32, generation: u64): i32 {
188
198
  if (outer.kind != PULSE_VALUE_OBJECT || outer.keys.length != 2 || __pulse_fastly_find(outer, '__pulseKv') < 0 || __pulse_fastly_find(outer, 'value') < 0) return __kv_failure(index, 'protocol');
189
199
  const marker = __pulse_fastly_value(__pulse_fastly_payload_field(outer, '__pulseKv'));
190
200
  if (marker.kind != PULSE_VALUE_NUMBER || marker.number != 1) return __kv_failure(index, 'protocol');
191
- const value = __pulse_fastly_payload_field(outer, 'value'), encoder = new __KvEncoder(); encoder.encode(value);
201
+ const value = __pulse_fastly_payload_field(outer, 'value'), encoder = new __KvEncoder(false); encoder.visit(value);
192
202
  if (encoder.reason.length) return __kv_failure(index, encoder.reason);
193
203
  const remaining = __kv_remaining(index); if (remaining <= 0) return __kv_failure(index, remaining == 0 ? 'timeout' : 'unavailable');
194
204
  const result = __kv_result('found'), token = __kv_token(generation); __kv_private(token);
@@ -0,0 +1,140 @@
1
+ 'use strict';
2
+
3
+ function enabled(plan) {
4
+ return (plan.routing?.entries || []).some(entry => entry.kind === 'error');
5
+ }
6
+
7
+ // Capture provider diagnostics before clearing them. A failed continuation is
8
+ // drained once; only its application data error can enter the next Router lane.
9
+ function runtimeSource(plan) {
10
+ const jwt = ['TOKEN_REQUIRED', 'BEARER_INVALID', 'MALFORMED', 'LIMIT_EXCEEDED',
11
+ 'ALGORITHM_NOT_ALLOWED', 'KEY_INVALID', 'SIGNATURE_INVALID', 'CLOCK_INVALID',
12
+ 'CLAIMS_INVALID', 'CLAIMS_SCHEMA_INVALID'];
13
+ return `
14
+ let __pulse_application_schema: i32 = 0
15
+ let __pulse_application_failed_schema: i32 = 0
16
+ function __pulse_application_code(): string {
17
+ if (__pulse_fastly_last_error == PULSE_ERROR_REQUEST_BODY)
18
+ return __pulse_fastly_error_stage == 21 ? "PULSE_BODY_TOO_LARGE" : "PULSE_REQUEST_BODY_INVALID_UTF8"
19
+ if (__pulse_fastly_jwt_error > 0) {
20
+ if (__pulse_fastly_last_error != PULSE_ERROR_JWT
21
+ && !(__pulse_fastly_last_error == PULSE_ERROR_SCHEMA && __pulse_fastly_jwt_error == 10)) return ""
22
+ switch (__pulse_fastly_jwt_error) {
23
+ ${jwt.map((code, i) => ` case ${i + 1}: return "PULSE_JWT_${code}"`).join('\n')}
24
+ default: return ""
25
+ }
26
+ }
27
+ if (__pulse_application_failed_schema == 0) return ""
28
+ if (__pulse_fastly_last_error == PULSE_ERROR_JSON) return "PULSE_SCHEMA_JSON_MALFORMED"
29
+ if (__pulse_fastly_last_error != PULSE_ERROR_SCHEMA) return ""
30
+ if (__pulse_fastly_error_stage == 21) return "PULSE_BODY_TOO_LARGE"
31
+ if (__pulse_fastly_error_stage == 44) return "PULSE_SCHEMA_CONTENT_TYPE"
32
+ // Stages 56/57 reject ScalarRecord and bounded nested JSON data.
33
+ // Stage 55 remains a fatal schema-ID/configuration error.
34
+ if ((__pulse_fastly_error_stage >= 50 && __pulse_fastly_error_stage <= 54)
35
+ || __pulse_fastly_error_stage == 56 || __pulse_fastly_error_stage == 57)
36
+ return __pulse_application_failed_schema == 2 ? "PULSE_SCHEMA_ENCODE" : "PULSE_SCHEMA_DECODE"
37
+ return ""
38
+ }
39
+ function __pulse_application_clear(): void {
40
+ __pulse_fastly_last_error = 0; __pulse_fastly_error_stage = 0; __pulse_fastly_error_effect = -1
41
+ __pulse_fastly_jwt_error = 0; __pulse_application_failed_schema = 0
42
+ }
43
+ ${(plan?.effects || []).length > 0 ? settlementSource() : ''}
44
+ function host_router_error_take(): i32 {
45
+ if (__pulse_fastly_last_error == 0) return 0
46
+ const code = __pulse_application_code()
47
+ if (code.length == 0) return -1
48
+ // Never abandon a dispatched sibling to run application recovery.
49
+ for (let i = 0; i < PULSE_FASTLY_EFFECT_COUNT; i += 1)
50
+ if (unchecked(__pulse_fastly_pending_mode[i]) != PULSE_FASTLY_PENDING_NONE) return 0
51
+ __pulse_application_clear()
52
+ const error = host_value_object()
53
+ host_value_object_set(error, __pulse_fastly_string_value("code"), __pulse_fastly_string_value(code))
54
+ host_value_object_set(error, __pulse_fastly_string_value("name"), __pulse_fastly_string_value("PulseApplicationError"))
55
+ host_value_object_set(error, __pulse_fastly_string_value("message"), __pulse_fastly_string_value("Pulse application data validation failed."))
56
+ return error
57
+ }
58
+ `;
59
+ }
60
+
61
+ // The caller retains the static pending-slot guards. The shared body owns one
62
+ // site's resolution and authenticated settlement; diagnostics carry the saved
63
+ // failure between calls without allocating an accumulator or merging slot state.
64
+ function settlementSource() {
65
+ return `
66
+ // Returns 0 for recoverable/no failure, 1 for fatal, -1 for rejected settlement.
67
+ function __pulse_application_settle_effect(index: i32, fatal: bool): i32 {
68
+ let failure = __pulse_fastly_last_error
69
+ let stage = __pulse_fastly_error_stage
70
+ let effect = __pulse_fastly_error_effect
71
+ let jwt = __pulse_fastly_jwt_error
72
+ let schema = __pulse_application_failed_schema
73
+ const invocation = unchecked(__pulse_invocation_tickets[index])
74
+ __pulse_application_clear()
75
+ let result = host_value_undefined()
76
+ if (unchecked(__pulse_fastly_pending_mode[index]) != PULSE_FASTLY_PENDING_NONE) {
77
+ result = __pulse_fastly_resolve_effect(index)
78
+ if (result <= 0 && __pulse_fastly_last_error == 0) __pulse_fastly_fail(PULSE_ERROR_STATE, 101, index)
79
+ } else if (failure == 0) __pulse_fastly_fail(PULSE_ERROR_STATE, 101, index)
80
+ if (__pulse_fastly_last_error != 0) {
81
+ const terminal = __pulse_application_code().length == 0
82
+ if (failure == 0 || (!fatal && terminal)) {
83
+ failure = __pulse_fastly_last_error; stage = __pulse_fastly_error_stage; effect = __pulse_fastly_error_effect
84
+ jwt = __pulse_fastly_jwt_error; schema = __pulse_application_failed_schema; fatal = terminal
85
+ }
86
+ __pulse_application_clear()
87
+ result = host_value_undefined()
88
+ }
89
+ if (__pulse_invocation_settle(index, invocation, result) != 1) {
90
+ __pulse_fastly_fail(PULSE_ERROR_STATE, 101, index); __pulse_fastly_jwt_send_error(); return -1
91
+ }
92
+ __pulse_fastly_last_error = failure; __pulse_fastly_error_stage = stage; __pulse_fastly_error_effect = effect
93
+ __pulse_fastly_jwt_error = jwt; __pulse_application_failed_schema = schema
94
+ return fatal ? 1 : 0
95
+ }
96
+ `;
97
+ }
98
+
99
+ // Preserve the fatal-return boundary consumed by request-budget instrumentation.
100
+ function driverLoop(plan) {
101
+ return ` while (runStatus == 1) {
102
+ let fatal = __pulse_fastly_last_error != 0 && __pulse_application_code().length == 0
103
+ ${(plan.effects || []).map((_, index) => ` if (__pulse_effect_pending_${index} != 0) {
104
+ const settled = __pulse_application_settle_effect(${index}, fatal)
105
+ if (settled < 0) return
106
+ fatal = settled != 0
107
+ }`).join('\n')}
108
+ if (fatal) return
109
+ runStatus = pulse_resume()
110
+ }`;
111
+ }
112
+
113
+ function instrument(source) {
114
+ // The input is compiler-owned AS with simple, typed host signatures. Keep
115
+ // failure suppression on all imports so a failed expression has no effects.
116
+ source = source.replace(/function (host_\w+)\(([^)]*)\): (i32|void) \{/g,
117
+ (declaration, name, _args, result) => name === 'host_router_error_take' ? declaration
118
+ : `${declaration} if (__pulse_fastly_last_error != 0) return${result === 'void' ? '' : ' 0'};`);
119
+ const wrappers = [
120
+ ['host_request_json', 'schema: i32', 'schema', '1'],
121
+ ['host_schema_decode', 'text: i32, schema: i32', 'text, schema', '1'],
122
+ ['host_schema_encode', 'value: i32, schema: i32', 'value, schema', '2'],
123
+ ['host_fetch_json', 'responseHandle: i32, schemaHandle: i32', 'responseHandle, schemaHandle', '1'],
124
+ ['host_response_json', 'value: i32, options: i32', 'value, options', '2'],
125
+ ['__pulse_fastly_schema_apply', 'schemaId: string, valueHandle: i32, encode: bool', 'schemaId, valueHandle, encode', 'encode ? 2 : 1']
126
+ ];
127
+ for (const [name, params, args, mode] of wrappers) {
128
+ source = source.replace(`function ${name}(`, `function __pulse_application_impl_${name}(`);
129
+ source += `\nfunction ${name}(${params}): i32 {
130
+ const previous = __pulse_application_schema; __pulse_application_schema = ${mode}
131
+ const result = __pulse_application_impl_${name}(${args})
132
+ __pulse_application_schema = previous
133
+ return result
134
+ }\n`;
135
+ }
136
+ source = source.replace('__pulse_fastly_last_error = code;', '__pulse_application_failed_schema = __pulse_application_schema; __pulse_fastly_last_error = code;');
137
+ return source;
138
+ }
139
+
140
+ module.exports = Object.freeze({ enabled, runtimeSource, driverLoop, instrument });