@pulse-compute/provider-fastly 1.0.0-beta.4 → 1.0.0-beta.5
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 +6 -6
- package/dist/config-schema.json +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/build/canonical-target.js +5 -0
- package/src/build/digest-native.js +25 -0
- package/src/build/native-application-errors.js +117 -0
- package/src/build/native-http-effects.js +48 -12
- package/src/build/native-platform-capabilities.js +142 -39
- package/src/build/native-request-body.js +44 -0
- package/src/build/native-request-headers.js +93 -0
- package/src/build/native-string-values.js +113 -0
- package/src/build/request-budget.as.ts +49 -0
- package/src/build/request-budget.js +43 -0
- package/src/build/s3-native.as.ts +3 -1
- package/src/build/time-native.js +49 -0
- package/src/config-api.js +1 -0
- package/src/config-schema.json +3 -0
- package/src/index.ts +4 -0
- package/src/javascript/package-effects.js +4 -1
- package/src/javascript/runtime-host.js +5 -2
- package/src/javascript/target-support-policy.js +7 -0
- package/src/javascript/target.js +6 -1
- package/src/provider-contract.js +3 -1
- package/src/runtime/canonical-api-runtime.js +2 -0
- package/src/testing/native-platform-capabilities-host.js +54 -3
- package/src/toolchain/config.js +4 -1
- package/src/toolchain/index.js +1 -1
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.
|
|
10
|
+
> **Canonical documentation:** [Package guide](https://pulsecompute.io/v1.0.0-beta.5/packages/provider-fastly/)
|
|
11
11
|
>
|
|
12
|
-
> This release-status block is generated from the synchronized `Pulse 1.0.0-beta.
|
|
12
|
+
> This release-status block is generated from the synchronized `Pulse 1.0.0-beta.5` 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.
|
|
53
|
-
- [Project configuration](https://pulsecompute.io/v1.0.0-beta.
|
|
54
|
-
- [Fastly capabilities guide](https://pulsecompute.io/v1.0.0-beta.
|
|
55
|
-
- [Environment variables](https://pulsecompute.io/v1.0.0-beta.
|
|
52
|
+
- [Fastly package guide](https://pulsecompute.io/v1.0.0-beta.5/packages/provider-fastly/)
|
|
53
|
+
- [Project configuration](https://pulsecompute.io/v1.0.0-beta.5/reference/project-config/#fastly-provider-options)
|
|
54
|
+
- [Fastly capabilities guide](https://pulsecompute.io/v1.0.0-beta.5/guides/fastly-capabilities/)
|
|
55
|
+
- [Environment variables](https://pulsecompute.io/v1.0.0-beta.5/reference/environment/#pulse-fastly-bin)
|
package/dist/config-schema.json
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface PulseFastlyLocalOptions {
|
|
|
14
14
|
readonly networkFetch?: boolean;
|
|
15
15
|
}
|
|
16
16
|
export interface PulseFastlyProviderOptions {
|
|
17
|
+
readonly maxDurationMs?: number;
|
|
17
18
|
readonly configStore?: string;
|
|
18
19
|
readonly secretStore?: string;
|
|
19
20
|
readonly kv?: Readonly<Record<string, string>>;
|
|
@@ -26,6 +27,7 @@ export interface PulseFastlyProviderOptions {
|
|
|
26
27
|
readonly local?: PulseFastlyLocalOptions;
|
|
27
28
|
}
|
|
28
29
|
export interface PulseFastlyProviderConfig {
|
|
30
|
+
readonly maxDurationMs?: number;
|
|
29
31
|
readonly kind: 'fastly';
|
|
30
32
|
readonly version: typeof FASTLY_PROVIDER_API_VERSION;
|
|
31
33
|
readonly bindings: {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,2BAA2B,EAAG,8BAAuC,CAAC;AAEnF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE;QACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;QAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,E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C,cAAc,CAAC,EAAE;gBACxB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;gBAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;aAC5B,CAAC;YACF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;SAC9B,CAAC;QACF,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;KACnC,CAAC;IACF,QAAQ,CAAC,KAAK,EAAE;QACd,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,CAuB1F"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ 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 { normalizeRequestDuration } = require('@pulse-compute/runtime/host');
|
|
8
9
|
const config_schema_json_1 = __importDefault(require("./config-schema.json"));
|
|
9
10
|
const fastlySchemaFields = config_schema_json_1.default.fields;
|
|
10
11
|
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 +38,7 @@ function fastly(options = {}) {
|
|
|
37
38
|
const normalizedGrip = options.grip === undefined ? undefined : gripBindings(options.grip);
|
|
38
39
|
return Object.freeze({
|
|
39
40
|
kind: 'fastly',
|
|
41
|
+
maxDurationMs: normalizeRequestDuration(options.maxDurationMs),
|
|
40
42
|
version: exports.FASTLY_PROVIDER_API_VERSION,
|
|
41
43
|
bindings: Object.freeze({
|
|
42
44
|
configStore: String(options.configStore ?? fastlyDefaults['fastly.configStore']),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAkGA,wBAuBC;AAzHD,MAAM,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC,6BAA6B,CAAqE,CAAC;AAChJ,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;AAkEnF,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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AAO,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.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
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.
|
|
63
|
-
"@pulse-compute/jwt": "1.0.0-beta.
|
|
64
|
-
"@pulse-compute/runtime": "1.0.0-beta.
|
|
65
|
-
"@pulse-compute/s3": "1.0.0-beta.
|
|
66
|
-
"@pulse-compute/wasm-build-support": "1.0.0-beta.
|
|
67
|
-
"@pulse-compute/wasm-contracts": "1.0.0-beta.
|
|
68
|
-
"@pulse-compute/wasm-guest-link": "1.0.0-beta.
|
|
69
|
-
"@pulse-compute/wasm-host-runtime": "1.0.0-beta.
|
|
70
|
-
"@pulse-compute/wasm-runtime-core-as": "1.0.0-beta.
|
|
62
|
+
"@pulse-compute/crypto": "1.0.0-beta.5",
|
|
63
|
+
"@pulse-compute/jwt": "1.0.0-beta.5",
|
|
64
|
+
"@pulse-compute/runtime": "1.0.0-beta.5",
|
|
65
|
+
"@pulse-compute/s3": "1.0.0-beta.5",
|
|
66
|
+
"@pulse-compute/wasm-build-support": "1.0.0-beta.5",
|
|
67
|
+
"@pulse-compute/wasm-contracts": "1.0.0-beta.5",
|
|
68
|
+
"@pulse-compute/wasm-guest-link": "1.0.0-beta.5",
|
|
69
|
+
"@pulse-compute/wasm-host-runtime": "1.0.0-beta.5",
|
|
70
|
+
"@pulse-compute/wasm-runtime-core-as": "1.0.0-beta.5",
|
|
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.
|
|
90
|
+
"homepage": "https://pulsecompute.io/v1.0.0-beta.5/packages/provider-fastly/",
|
|
91
91
|
"bugs": {
|
|
92
92
|
"url": "https://github.com/pulse-compute/pulse/issues"
|
|
93
93
|
},
|
|
@@ -229,6 +229,7 @@ function inspectFastlyCanonicalTarget(options = {}) {
|
|
|
229
229
|
projectRoot: options.projectRoot,
|
|
230
230
|
profile: options.profile,
|
|
231
231
|
bindings,
|
|
232
|
+
maxDurationMs: providerConfig.maxDurationMs,
|
|
232
233
|
requirePlatformCapability: false,
|
|
233
234
|
canonicalBuild: true,
|
|
234
235
|
targetDescriptor: options.targetDescriptor,
|
|
@@ -241,6 +242,10 @@ function inspectFastlyCanonicalTarget(options = {}) {
|
|
|
241
242
|
|| (options.experimentalNativeSize === true ? 'experimental-native-size' : undefined),
|
|
242
243
|
timeoutMs: options.compileTimeoutMs
|
|
243
244
|
});
|
|
245
|
+
const duration = require('@pulse-compute/runtime/host').normalizeRequestDuration(providerConfig.maxDurationMs);
|
|
246
|
+
if (native.manifest.bindings?.maxDurationMs !== duration) {
|
|
247
|
+
throw providerBuildError('PULSE_REQUEST_DURATION_ARTIFACT_MISMATCH', 'Fastly artifact request deadline does not match the selected provider profile.');
|
|
248
|
+
}
|
|
244
249
|
return Object.freeze({
|
|
245
250
|
target: FASTLY_CANONICAL_TARGET,
|
|
246
251
|
provider: 'fastly',
|
|
@@ -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,117 @@
|
|
|
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() {
|
|
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
|
+
if (__pulse_fastly_error_stage >= 50 && __pulse_fastly_error_stage <= 54)
|
|
33
|
+
return __pulse_application_failed_schema == 2 ? "PULSE_SCHEMA_ENCODE" : "PULSE_SCHEMA_DECODE"
|
|
34
|
+
return ""
|
|
35
|
+
}
|
|
36
|
+
function __pulse_application_clear(): void {
|
|
37
|
+
__pulse_fastly_last_error = 0; __pulse_fastly_error_stage = 0; __pulse_fastly_error_effect = -1
|
|
38
|
+
__pulse_fastly_jwt_error = 0; __pulse_application_failed_schema = 0
|
|
39
|
+
}
|
|
40
|
+
function host_router_error_take(): i32 {
|
|
41
|
+
if (__pulse_fastly_last_error == 0) return 0
|
|
42
|
+
const code = __pulse_application_code()
|
|
43
|
+
if (code.length == 0) return -1
|
|
44
|
+
// Never abandon a dispatched sibling to run application recovery.
|
|
45
|
+
for (let i = 0; i < PULSE_FASTLY_EFFECT_COUNT; i += 1)
|
|
46
|
+
if (unchecked(__pulse_fastly_pending_mode[i]) != PULSE_FASTLY_PENDING_NONE) return 0
|
|
47
|
+
__pulse_application_clear()
|
|
48
|
+
const error = host_value_object()
|
|
49
|
+
host_value_object_set(error, __pulse_fastly_string_value("code"), __pulse_fastly_string_value(code))
|
|
50
|
+
host_value_object_set(error, __pulse_fastly_string_value("name"), __pulse_fastly_string_value("PulseApplicationError"))
|
|
51
|
+
host_value_object_set(error, __pulse_fastly_string_value("message"), __pulse_fastly_string_value("Pulse application data validation failed."))
|
|
52
|
+
return error
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function driverLoop(plan) {
|
|
58
|
+
return ` while (runStatus == 1) {
|
|
59
|
+
let failure = __pulse_fastly_last_error
|
|
60
|
+
let stage = __pulse_fastly_error_stage
|
|
61
|
+
let effect = __pulse_fastly_error_effect
|
|
62
|
+
let jwt = __pulse_fastly_jwt_error
|
|
63
|
+
let schema = __pulse_application_failed_schema
|
|
64
|
+
let fatal = failure != 0 && __pulse_application_code().length == 0
|
|
65
|
+
${(plan.effects || []).map((_, index) => ` if (__pulse_effect_pending_${index} != 0) {
|
|
66
|
+
__pulse_application_clear()
|
|
67
|
+
let result = host_value_undefined()
|
|
68
|
+
if (unchecked(__pulse_fastly_pending_mode[${index}]) != PULSE_FASTLY_PENDING_NONE) {
|
|
69
|
+
result = __pulse_fastly_resolve_effect(${index})
|
|
70
|
+
if (result <= 0 && __pulse_fastly_last_error == 0) __pulse_fastly_fail(PULSE_ERROR_STATE, 101, ${index})
|
|
71
|
+
} else if (failure == 0) __pulse_fastly_fail(PULSE_ERROR_STATE, 101, ${index})
|
|
72
|
+
if (__pulse_fastly_last_error != 0) {
|
|
73
|
+
const terminal = __pulse_application_code().length == 0
|
|
74
|
+
if (failure == 0 || (!fatal && terminal)) {
|
|
75
|
+
failure = __pulse_fastly_last_error; stage = __pulse_fastly_error_stage; effect = __pulse_fastly_error_effect
|
|
76
|
+
jwt = __pulse_fastly_jwt_error; schema = __pulse_application_failed_schema; fatal = terminal
|
|
77
|
+
}
|
|
78
|
+
__pulse_application_clear()
|
|
79
|
+
result = host_value_undefined()
|
|
80
|
+
}
|
|
81
|
+
if (pulse_set_effect_result(${index}, result) != 1) { __pulse_fastly_fail(PULSE_ERROR_STATE, 101, ${index}); return }
|
|
82
|
+
}`).join('\n')}
|
|
83
|
+
__pulse_fastly_last_error = failure; __pulse_fastly_error_stage = stage; __pulse_fastly_error_effect = effect
|
|
84
|
+
__pulse_fastly_jwt_error = jwt; __pulse_application_failed_schema = schema
|
|
85
|
+
if (fatal) return
|
|
86
|
+
runStatus = pulse_resume()
|
|
87
|
+
}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function instrument(source) {
|
|
91
|
+
// The input is compiler-owned AS with simple, typed host signatures. Keep
|
|
92
|
+
// failure suppression on all imports so a failed expression has no effects.
|
|
93
|
+
source = source.replace(/function (host_\w+)\(([^)]*)\): (i32|void) \{/g,
|
|
94
|
+
(declaration, name, _args, result) => name === 'host_router_error_take' ? declaration
|
|
95
|
+
: `${declaration} if (__pulse_fastly_last_error != 0) return${result === 'void' ? '' : ' 0'};`);
|
|
96
|
+
const wrappers = [
|
|
97
|
+
['host_request_json', 'schema: i32', 'schema', '1'],
|
|
98
|
+
['host_schema_decode', 'text: i32, schema: i32', 'text, schema', '1'],
|
|
99
|
+
['host_schema_encode', 'value: i32, schema: i32', 'value, schema', '2'],
|
|
100
|
+
['host_fetch_json', 'responseHandle: i32, schemaHandle: i32', 'responseHandle, schemaHandle', '1'],
|
|
101
|
+
['host_response_json', 'value: i32, options: i32', 'value, options', '2'],
|
|
102
|
+
['__pulse_fastly_schema_apply', 'schemaId: string, valueHandle: i32, encode: bool', 'schemaId, valueHandle, encode', 'encode ? 2 : 1']
|
|
103
|
+
];
|
|
104
|
+
for (const [name, params, args, mode] of wrappers) {
|
|
105
|
+
source = source.replace(`function ${name}(`, `function __pulse_application_impl_${name}(`);
|
|
106
|
+
source += `\nfunction ${name}(${params}): i32 {
|
|
107
|
+
const previous = __pulse_application_schema; __pulse_application_schema = ${mode}
|
|
108
|
+
const result = __pulse_application_impl_${name}(${args})
|
|
109
|
+
__pulse_application_schema = previous
|
|
110
|
+
return result
|
|
111
|
+
}\n`;
|
|
112
|
+
}
|
|
113
|
+
source = source.replace('__pulse_fastly_last_error = code;', '__pulse_application_failed_schema = __pulse_application_schema; __pulse_fastly_last_error = code;');
|
|
114
|
+
return source;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = Object.freeze({ enabled, runtimeSource, driverLoop, instrument });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const crypto = require('node:crypto');
|
|
4
|
+
const { nativeStringFields, nativeStringConcat, nativeStringTrim, nativeStringIndex, needsNativeValueFailureGuard } = require('./native-string-values.js');
|
|
4
5
|
const fs = require('node:fs');
|
|
5
6
|
const os = require('node:os');
|
|
6
7
|
const path = require('node:path');
|
|
@@ -216,11 +217,13 @@ function generateSchemaRuntime(plan) {
|
|
|
216
217
|
body.push(' const output = host_value_object()');
|
|
217
218
|
fields.forEach(({ field, apply }, fieldIndex) => {
|
|
218
219
|
body.push(` const key_${currentIndex}_${fieldIndex} = __pulse_fastly_string_value(${quote(field.name)})`);
|
|
220
|
+
if (!field.required) body.push(` if (__pulse_fastly_find(input, ${quote(field.name)}) >= 0) {`);
|
|
219
221
|
body.push(` const field_${currentIndex}_${fieldIndex} = host_value_property(valueHandle, key_${currentIndex}_${fieldIndex})`);
|
|
220
222
|
body.push(` if (__pulse_fastly_value(field_${currentIndex}_${fieldIndex}).kind == PULSE_VALUE_UNDEFINED) { __pulse_fastly_fail(PULSE_ERROR_SCHEMA, 51, -1); return 0 }`);
|
|
221
223
|
body.push(` const projected_${currentIndex}_${fieldIndex} = ${apply}(field_${currentIndex}_${fieldIndex})`);
|
|
222
224
|
body.push(` if (projected_${currentIndex}_${fieldIndex} <= 0) return 0`);
|
|
223
225
|
body.push(` host_value_object_set(output, key_${currentIndex}_${fieldIndex}, projected_${currentIndex}_${fieldIndex})`);
|
|
226
|
+
if (!field.required) body.push(' }');
|
|
224
227
|
});
|
|
225
228
|
body.push(' return output');
|
|
226
229
|
} else if (node.kind === 'string') {
|
|
@@ -354,17 +357,33 @@ const PULSE_ERROR_TRANSPORT: i32 = 1006
|
|
|
354
357
|
const PULSE_ERROR_STATE: i32 = 1007
|
|
355
358
|
|
|
356
359
|
class __PulseFastlyValue {
|
|
360
|
+
immutable: bool = false
|
|
357
361
|
kind: i32 = PULSE_VALUE_UNDEFINED
|
|
358
362
|
boolean: i32 = 0
|
|
359
363
|
number: f64 = 0.0
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
364
|
+
${nativeStringFields}
|
|
365
|
+
// Scalar handles do not need collection backing stores.
|
|
366
|
+
private keysStorage: Array<string> | null = null
|
|
367
|
+
get keys(): Array<string> {
|
|
368
|
+
if (this.keysStorage === null) this.keysStorage = new Array<string>()
|
|
369
|
+
return this.keysStorage!
|
|
370
|
+
}
|
|
371
|
+
// Scalar handles do not need collection backing stores.
|
|
372
|
+
private valuesStorage: Array<i32> | null = null
|
|
373
|
+
get values(): Array<i32> {
|
|
374
|
+
if (this.valuesStorage === null) this.valuesStorage = new Array<i32>()
|
|
375
|
+
return this.valuesStorage!
|
|
376
|
+
}
|
|
363
377
|
responseHandle: i32 = 0
|
|
364
378
|
bodyHandle: i32 = 0
|
|
365
379
|
bodyLoaded: i32 = 0
|
|
366
380
|
status: i32 = 200
|
|
367
|
-
|
|
381
|
+
// Scalar handles do not need collection backing stores.
|
|
382
|
+
private headersStorage: Array<__PulseFastlyHeader> | null = null
|
|
383
|
+
get headers(): Array<__PulseFastlyHeader> {
|
|
384
|
+
if (this.headersStorage === null) this.headersStorage = new Array<__PulseFastlyHeader>()
|
|
385
|
+
return this.headersStorage!
|
|
386
|
+
}
|
|
368
387
|
}
|
|
369
388
|
class __PulseFastlyHeader {
|
|
370
389
|
constructor(public name: string, public value: string) {}
|
|
@@ -547,6 +566,10 @@ function __pulse_fastly_json(handle: i32, depth: i32): string {
|
|
|
547
566
|
if (value.kind == PULSE_VALUE_OBJECT) { let out = "{"; for (let i = 0; i < value.keys.length; i += 1) { if (i > 0) out += ","; out += __pulse_fastly_quote(unchecked(value.keys[i])) + ":" + __pulse_fastly_json(unchecked(value.values[i]), depth + 1) } return out + "}" }
|
|
548
567
|
return "null"
|
|
549
568
|
}
|
|
569
|
+
${nativeStringConcat}
|
|
570
|
+
${nativeStringTrim}
|
|
571
|
+
${nativeStringIndex}
|
|
572
|
+
function __pulse_fastly_deep_freeze(handle: i32): void { const value = __pulse_fastly_value(handle); if (value.immutable) return; value.immutable = true; if (value.kind == PULSE_VALUE_ARRAY || value.kind == PULSE_VALUE_OBJECT) for (let index = 0; index < value.values.length; index += 1) __pulse_fastly_deep_freeze(unchecked(value.values[index])) }
|
|
550
573
|
function __pulse_fastly_parse_json(text: string): i32 { const parser = new __PulseJsonParser(text); const value = parser.parse(); if (parser.failed || value <= 0) { __pulse_fastly_fail(PULSE_ERROR_JSON, 3, -1); return 0 } return value }
|
|
551
574
|
function __pulse_fastly_path(uri: string): string { let start = 0; const scheme = uri.indexOf("://"); if (scheme >= 0) { const slash = uri.indexOf("/", scheme + 3); start = slash >= 0 ? slash : uri.length } let end = uri.length; const query = uri.indexOf("?", start); if (query >= 0 && query < end) end = query; const fragment = uri.indexOf("#", start); if (fragment >= 0 && fragment < end) end = fragment; return start >= end ? "/" : uri.substring(start, end) }
|
|
552
575
|
function __pulse_fastly_read_req_string(kind: i32): string { const buffer = new Uint8Array(PULSE_FASTLY_BUFFER_BYTES); const written = __pulse_fastly_out_i32(); const status = kind == 0 ? fastly_http_req_method_get(__pulse_fastly_request_handle, buffer.dataStart, PULSE_FASTLY_BUFFER_BYTES, changetype<usize>(written)) : fastly_http_req_uri_get(__pulse_fastly_request_handle, buffer.dataStart, PULSE_FASTLY_BUFFER_BYTES, changetype<usize>(written)); if (status != FASTLY_STATUS_OK) { __pulse_fastly_fail(PULSE_ERROR_HOSTCALL, 10 + kind, -1); return "" } return __pulse_fastly_decode(buffer, __pulse_fastly_out_value(written)) }
|
|
@@ -561,18 +584,18 @@ function host_value_boolean(value: i32): i32 { const item = new __PulseFastlyVal
|
|
|
561
584
|
function host_value_number(value: f64): i32 { const item = new __PulseFastlyValue(); item.kind = PULSE_VALUE_NUMBER; item.number = value; return __pulse_fastly_put(item) }
|
|
562
585
|
function host_value_string(pointer: i32, length: i32): i32 { return __pulse_fastly_string_value(changetype<string>(pointer)) }
|
|
563
586
|
function host_value_array(): i32 { const item = new __PulseFastlyValue(); item.kind = PULSE_VALUE_ARRAY; return __pulse_fastly_put(item) }
|
|
564
|
-
function host_value_array_push(target: i32, value: i32): void { const item = __pulse_fastly_value(target); if (item.kind != PULSE_VALUE_ARRAY) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 30, -1); return } item.values.push(value) }
|
|
587
|
+
function host_value_array_push(target: i32, value: i32): void { const item = __pulse_fastly_value(target); if (item.kind != PULSE_VALUE_ARRAY || item.immutable) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 30, -1); return } item.values.push(value) }
|
|
565
588
|
function host_value_array_spread(target: i32, source: i32): void { const from = __pulse_fastly_value(source); if (from.kind != PULSE_VALUE_ARRAY) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 31, -1); return } for (let i = 0; i < from.values.length; i += 1) host_value_array_push(target, unchecked(from.values[i])) }
|
|
566
589
|
function host_value_object(): i32 { const item = new __PulseFastlyValue(); item.kind = PULSE_VALUE_OBJECT; return __pulse_fastly_put(item) }
|
|
567
|
-
function host_value_object_set(target: i32, keyHandle: i32, value: i32): void { const item = __pulse_fastly_value(target); if (item.kind != PULSE_VALUE_OBJECT) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 32, -1); return } const key = __pulse_fastly_string(keyHandle); const index = __pulse_fastly_find(item, key); if (index >= 0) unchecked(item.values[index] = value); else { item.keys.push(key); item.values.push(value) } }
|
|
590
|
+
function host_value_object_set(target: i32, keyHandle: i32, value: i32): void { const item = __pulse_fastly_value(target); if (item.kind != PULSE_VALUE_OBJECT || item.immutable) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 32, -1); return } const key = __pulse_fastly_string(keyHandle); const index = __pulse_fastly_find(item, key); if (index >= 0) unchecked(item.values[index] = value); else { item.keys.push(key); item.values.push(value) } }
|
|
568
591
|
function host_value_object_spread(target: i32, source: i32): void { const from = __pulse_fastly_value(source); if (from.kind != PULSE_VALUE_OBJECT) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 33, -1); return } for (let i = 0; i < from.keys.length; i += 1) host_value_object_set(target, __pulse_fastly_string_value(unchecked(from.keys[i])), unchecked(from.values[i])) }
|
|
569
|
-
function host_value_property(target: i32, keyHandle: i32): i32 { const item = __pulse_fastly_value(target); const key = __pulse_fastly_string(keyHandle); if (item.kind == PULSE_VALUE_OBJECT) { const index = __pulse_fastly_find(item, key); return index >= 0 ? unchecked(item.values[index]) : host_value_undefined() } if (item.kind == PULSE_VALUE_FETCH && key == "status") { const out = __pulse_fastly_out_i32(); const status = fastly_http_resp_status_get(item.responseHandle, changetype<usize>(out)); if (status != FASTLY_STATUS_OK) { __pulse_fastly_fail(PULSE_ERROR_HOSTCALL, 34, -1); return 0 } return host_value_number(__pulse_fastly_out_value(out)) } if ((item.kind == PULSE_VALUE_STRING || item.kind == PULSE_VALUE_ARRAY) && key == "length") return host_value_number(item.kind == PULSE_VALUE_STRING ? item.
|
|
592
|
+
function host_value_property(target: i32, keyHandle: i32): i32 { const item = __pulse_fastly_value(target); const key = __pulse_fastly_string(keyHandle); if (item.kind == PULSE_VALUE_OBJECT) { const index = __pulse_fastly_find(item, key); return index >= 0 ? unchecked(item.values[index]) : host_value_undefined() } if (item.kind == PULSE_VALUE_FETCH && key == "status") { const out = __pulse_fastly_out_i32(); const status = fastly_http_resp_status_get(item.responseHandle, changetype<usize>(out)); if (status != FASTLY_STATUS_OK) { __pulse_fastly_fail(PULSE_ERROR_HOSTCALL, 34, -1); return 0 } return host_value_number(__pulse_fastly_out_value(out)) } if ((item.kind == PULSE_VALUE_STRING || item.kind == PULSE_VALUE_ARRAY) && key == "length") return host_value_number(item.kind == PULSE_VALUE_STRING ? item.textLength : item.values.length); return host_value_undefined() }
|
|
570
593
|
function host_value_property_set(target: i32, key: i32, value: i32): i32 { host_value_object_set(target, key, value); return value }
|
|
571
|
-
function host_value_element(target: i32, keyHandle: i32): i32 { const item = __pulse_fastly_value(target); if (item.kind == PULSE_VALUE_ARRAY) { const index = i32(__pulse_fastly_number(keyHandle)); return index >= 0 && index < item.values.length ? unchecked(item.values[index]) : host_value_undefined() } return host_value_property(target, keyHandle) }
|
|
572
|
-
function host_value_element_set(target: i32, keyHandle: i32, value: i32): i32 { const item = __pulse_fastly_value(target); if (item.kind == PULSE_VALUE_ARRAY) { const index = i32(__pulse_fastly_number(keyHandle)); if (index < 0) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 35, -1); return 0 } while (item.values.length <= index) item.values.push(host_value_undefined()); unchecked(item.values[index] = value); return value } return host_value_property_set(target, keyHandle, value) }
|
|
573
|
-
function host_value_truthy(handle: i32): i32 { const value = __pulse_fastly_value(handle); if (value.kind == PULSE_VALUE_UNDEFINED || value.kind == PULSE_VALUE_NULL) return 0; if (value.kind == PULSE_VALUE_BOOLEAN) return value.boolean; if (value.kind == PULSE_VALUE_NUMBER) return value.number != 0.0 && !isNaN(value.number) ? 1 : 0; if (value.kind == PULSE_VALUE_STRING) return value.
|
|
594
|
+
function host_value_element(target: i32, keyHandle: i32): i32 { const item = __pulse_fastly_value(target); if (item.kind == PULSE_VALUE_STRING) return __pulse_fastly_string_index(item, keyHandle); if (item.kind == PULSE_VALUE_ARRAY) { const index = i32(__pulse_fastly_number(keyHandle)); return index >= 0 && index < item.values.length ? unchecked(item.values[index]) : host_value_undefined() } return host_value_property(target, keyHandle) }
|
|
595
|
+
function host_value_element_set(target: i32, keyHandle: i32, value: i32): i32 { const item = __pulse_fastly_value(target); if (item.immutable) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 35, -1); return 0 } if (item.kind == PULSE_VALUE_ARRAY) { const index = i32(__pulse_fastly_number(keyHandle)); if (index < 0) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 35, -1); return 0 } while (item.values.length <= index) item.values.push(host_value_undefined()); unchecked(item.values[index] = value); return value } return host_value_property_set(target, keyHandle, value) }
|
|
596
|
+
function host_value_truthy(handle: i32): i32 { const value = __pulse_fastly_value(handle); if (value.kind == PULSE_VALUE_UNDEFINED || value.kind == PULSE_VALUE_NULL) return 0; if (value.kind == PULSE_VALUE_BOOLEAN) return value.boolean; if (value.kind == PULSE_VALUE_NUMBER) return value.number != 0.0 && !isNaN(value.number) ? 1 : 0; if (value.kind == PULSE_VALUE_STRING) return value.textLength > 0 ? 1 : 0; return 1 }
|
|
574
597
|
function host_value_nullish(handle: i32): i32 { const kind = __pulse_fastly_value(handle).kind; return kind == PULSE_VALUE_UNDEFINED || kind == PULSE_VALUE_NULL ? 1 : 0 }
|
|
575
|
-
function host_value_binary(operator: i32, leftHandle: i32, rightHandle: i32): i32 { const left = __pulse_fastly_value(leftHandle); const right = __pulse_fastly_value(rightHandle); if (operator == 0 || operator == 2) { let equal = false; if (left.kind == right.kind) { if (left.kind == PULSE_VALUE_UNDEFINED || left.kind == PULSE_VALUE_NULL) equal = true; else if (left.kind == PULSE_VALUE_BOOLEAN) equal = left.boolean == right.boolean; else if (left.kind == PULSE_VALUE_NUMBER) equal = left.number == right.number; else if (left.kind == PULSE_VALUE_STRING) equal = left.text == right.text; else equal = leftHandle == rightHandle } return host_value_boolean(equal ? 1 : 0) } if (operator == 1 || operator == 3) { const result = host_value_binary(operator == 1 ? 0 : 2, leftHandle, rightHandle); return host_value_boolean(host_value_truthy(result) == 0 ? 1 : 0) } if (operator == 8) { if (left.kind == PULSE_VALUE_STRING || right.kind == PULSE_VALUE_STRING) return
|
|
598
|
+
function host_value_binary(operator: i32, leftHandle: i32, rightHandle: i32): i32 { const left = __pulse_fastly_value(leftHandle); const right = __pulse_fastly_value(rightHandle); if (operator == 0 || operator == 2) { let equal = false; if (left.kind == right.kind) { if (left.kind == PULSE_VALUE_UNDEFINED || left.kind == PULSE_VALUE_NULL) equal = true; else if (left.kind == PULSE_VALUE_BOOLEAN) equal = left.boolean == right.boolean; else if (left.kind == PULSE_VALUE_NUMBER) equal = left.number == right.number; else if (left.kind == PULSE_VALUE_STRING) equal = left.text == right.text; else equal = leftHandle == rightHandle } return host_value_boolean(equal ? 1 : 0) } if (operator == 1 || operator == 3) { const result = host_value_binary(operator == 1 ? 0 : 2, leftHandle, rightHandle); return host_value_boolean(host_value_truthy(result) == 0 ? 1 : 0) } if (operator == 8) { if (left.kind == PULSE_VALUE_STRING || right.kind == PULSE_VALUE_STRING) return __pulse_fastly_concat(leftHandle, rightHandle); return host_value_number(__pulse_fastly_number(leftHandle) + __pulse_fastly_number(rightHandle)) } if (left.kind == PULSE_VALUE_STRING && right.kind == PULSE_VALUE_STRING) { if (operator == 4) return host_value_boolean(left.text < right.text ? 1 : 0); if (operator == 5) return host_value_boolean(left.text <= right.text ? 1 : 0); if (operator == 6) return host_value_boolean(left.text > right.text ? 1 : 0); if (operator == 7) return host_value_boolean(left.text >= right.text ? 1 : 0); } if (operator == 4) return host_value_boolean(__pulse_fastly_number(leftHandle) < __pulse_fastly_number(rightHandle) ? 1 : 0); if (operator == 5) return host_value_boolean(__pulse_fastly_number(leftHandle) <= __pulse_fastly_number(rightHandle) ? 1 : 0); if (operator == 6) return host_value_boolean(__pulse_fastly_number(leftHandle) > __pulse_fastly_number(rightHandle) ? 1 : 0); if (operator == 7) return host_value_boolean(__pulse_fastly_number(leftHandle) >= __pulse_fastly_number(rightHandle) ? 1 : 0); if (operator == 9) return host_value_number(__pulse_fastly_number(leftHandle) - __pulse_fastly_number(rightHandle)); if (operator == 10) return host_value_number(__pulse_fastly_number(leftHandle) * __pulse_fastly_number(rightHandle)); if (operator == 11) return host_value_number(__pulse_fastly_number(leftHandle) / __pulse_fastly_number(rightHandle)); if (operator == 12) return host_value_number(__pulse_fastly_number(leftHandle) % __pulse_fastly_number(rightHandle)); if (operator == 14) return host_value_truthy(leftHandle) != 0 ? rightHandle : leftHandle; if (operator == 15) return host_value_truthy(leftHandle) != 0 ? leftHandle : rightHandle; if (operator == 16) return host_value_nullish(leftHandle) == 0 ? leftHandle : rightHandle; __pulse_fastly_fail(PULSE_ERROR_UNSUPPORTED, 36, -1); return 0 }
|
|
576
599
|
function host_value_unary(operator: i32, handle: i32): i32 { if (operator == 0) return host_value_boolean(host_value_truthy(handle) == 0 ? 1 : 0); if (operator == 1) return host_value_number(__pulse_fastly_number(handle)); if (operator == 2) return host_value_number(-__pulse_fastly_number(handle)); if (operator == 5) return host_value_undefined(); __pulse_fastly_fail(PULSE_ERROR_UNSUPPORTED, 37, -1); return 0 }
|
|
577
600
|
|
|
578
601
|
function host_request_method(): i32 { return __pulse_fastly_string_value(__pulse_fastly_request_method) }
|
|
@@ -590,6 +613,19 @@ function host_request_json(schema: i32): i32 { const parsed = __pulse_fastly_par
|
|
|
590
613
|
function __pulse_fastly_headers_from_options(options: __PulseFastlyValue, output: __PulseFastlyValue): void { const index = __pulse_fastly_find(options, "headers"); if (index < 0) return; const headers = __pulse_fastly_value(unchecked(options.values[index])); if (headers.kind == PULSE_VALUE_OBJECT) { for (let i = 0; i < headers.keys.length; i += 1) { const name = unchecked(headers.keys[i]); const value = __pulse_fastly_value(unchecked(headers.values[i])); if (value.kind == PULSE_VALUE_ARRAY) { for (let j = 0; j < value.values.length; j += 1) output.headers.push(new __PulseFastlyHeader(name, __pulse_fastly_string(unchecked(value.values[j])))) } else output.headers.push(new __PulseFastlyHeader(name, __pulse_fastly_string(unchecked(headers.values[i])))) } return } if (headers.kind == PULSE_VALUE_ARRAY) { for (let i = 0; i < headers.values.length; i += 1) { const pair = __pulse_fastly_value(unchecked(headers.values[i])); if (pair.kind != PULSE_VALUE_ARRAY || pair.values.length < 2) continue; output.headers.push(new __PulseFastlyHeader(__pulse_fastly_string(unchecked(pair.values[0])), __pulse_fastly_string(unchecked(pair.values[1])))) } } }
|
|
591
614
|
function __pulse_fastly_response(value: i32, optionsHandle: i32, json: bool): i32 { const output = new __PulseFastlyValue(); output.kind = PULSE_VALUE_RESPONSE; output.status = 200; const options = __pulse_fastly_value(optionsHandle); let bodyValue = value; if (options.kind == PULSE_VALUE_OBJECT) { const statusIndex = __pulse_fastly_find(options, "status"); if (statusIndex >= 0) output.status = i32(__pulse_fastly_number(unchecked(options.values[statusIndex]))); const schemaIndex = __pulse_fastly_find(options, "schema"); if (json && schemaIndex >= 0) { bodyValue = __pulse_fastly_schema_apply(__pulse_fastly_string(unchecked(options.values[schemaIndex])), value, true); if (bodyValue <= 0) return 0 } __pulse_fastly_headers_from_options(options, output) } output.text = json ? __pulse_fastly_json(bodyValue, 0) : __pulse_fastly_string(value); let hasContentType = false; for (let i = 0; i < output.headers.length; i += 1) if (unchecked(output.headers[i]).name.toLowerCase() == "content-type") hasContentType = true; if (!hasContentType) output.headers.push(new __PulseFastlyHeader("content-type", json ? "application/json; charset=utf-8" : "text/plain; charset=utf-8")); return __pulse_fastly_put(output) }
|
|
592
615
|
function host_response_json(value: i32, options: i32): i32 { return __pulse_fastly_response(value, options, true) }
|
|
616
|
+
function host_schema_decode(text: i32, schema: i32): i32 {
|
|
617
|
+
const id = __pulse_fastly_value(schema)
|
|
618
|
+
if (id.kind != PULSE_VALUE_STRING || id.text.length == 0) { __pulse_fastly_fail(PULSE_ERROR_SCHEMA, 55, -1); return 0 }
|
|
619
|
+
const input = __pulse_fastly_value(text)
|
|
620
|
+
if (input.kind != PULSE_VALUE_STRING) { __pulse_fastly_fail(PULSE_ERROR_SCHEMA, 52, -1); return 0 }
|
|
621
|
+
if (String.UTF8.byteLength(input.text) > __PULSE_SCHEMA_MAX_BYTES) { __pulse_fastly_fail(PULSE_ERROR_SCHEMA, 21, -1); return 0 }
|
|
622
|
+
const parsed = __pulse_fastly_parse_json(input.text)
|
|
623
|
+
if (parsed <= 0) return 0
|
|
624
|
+
const decoded = __pulse_fastly_schema_apply(id.text, parsed, false)
|
|
625
|
+
if (decoded <= 0) return 0
|
|
626
|
+
__pulse_fastly_deep_freeze(decoded)
|
|
627
|
+
return decoded
|
|
628
|
+
}
|
|
593
629
|
function host_schema_encode(value: i32, schema: i32): i32 {
|
|
594
630
|
const id = __pulse_fastly_value(schema)
|
|
595
631
|
if (id.kind != PULSE_VALUE_STRING || id.text.length == 0) { __pulse_fastly_fail(PULSE_ERROR_SCHEMA, 55, -1); return 0 }
|
|
@@ -610,7 +646,7 @@ function host_kv_namespace(name: i32): i32 { __pulse_fastly_fail(PULSE_ERROR_UNS
|
|
|
610
646
|
function host_fetch_text(responseHandle: i32): i32 { const response = __pulse_fastly_value(responseHandle); if (response.kind != PULSE_VALUE_FETCH) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 42, -1); return 0 } return __pulse_fastly_string_value(__pulse_fastly_fetch_body(response)) }
|
|
611
647
|
function host_fetch_json(responseHandle: i32, schemaHandle: i32): i32 { const response = __pulse_fastly_value(responseHandle); if (response.kind != PULSE_VALUE_FETCH) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 43, -1); return 0 } if (__PULSE_SCHEMA_REQUIRE_JSON) { const contentType = __pulse_fastly_fetch_header_text(response.responseHandle, "content-type"); if (contentType.length == 0 || contentType.toLowerCase().indexOf("json") < 0) { __pulse_fastly_fail(PULSE_ERROR_SCHEMA, 44, -1); return 0 } } const parsed = __pulse_fastly_parse_json(__pulse_fastly_fetch_body(response)); if (parsed <= 0) return 0; const schema = __pulse_fastly_value(schemaHandle); return schema.kind == PULSE_VALUE_STRING ? __pulse_fastly_schema_apply(schema.text, parsed, false) : parsed }
|
|
612
648
|
function host_fetch_header(responseHandle: i32, nameHandle: i32): i32 { const response = __pulse_fastly_value(responseHandle); if (response.kind != PULSE_VALUE_FETCH) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 45, -1); return 0 } const value = __pulse_fastly_fetch_header_text(response.responseHandle, __pulse_fastly_string(nameHandle)); return value.length == 0 ? host_value_undefined() : __pulse_fastly_string_value(value) }
|
|
613
|
-
function host_effect_begin(effectIndex: i32, payload: i32): void { ${(plan
|
|
649
|
+
function host_effect_begin(effectIndex: i32, payload: i32): void { ${needsNativeValueFailureGuard(plan) ? 'if (__pulse_fastly_last_error != PULSE_ERROR_NONE) return; ' : ''}if (effectIndex < 0 || effectIndex >= PULSE_FASTLY_EFFECT_COUNT || unchecked(__pulse_fastly_pending_active[effectIndex]) != 0) { __pulse_fastly_fail(PULSE_ERROR_STATE, 46, effectIndex); return } const payloadValue = __pulse_fastly_value(payload); if (payloadValue.kind != PULSE_VALUE_OBJECT) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 47, effectIndex); return } const urlIndex = __pulse_fastly_find(payloadValue, "url"); if (urlIndex < 0) { __pulse_fastly_fail(PULSE_ERROR_VALUE, 48, effectIndex); return } const url = __pulse_fastly_string(unchecked(payloadValue.values[urlIndex])); const initIndex = __pulse_fastly_find(payloadValue, "init"); const init = initIndex >= 0 ? __pulse_fastly_value(unchecked(payloadValue.values[initIndex])) : new __PulseFastlyValue(); let method = "GET"; let body = ""; let headers = new __PulseFastlyValue(); headers.kind = PULSE_VALUE_OBJECT; if (init.kind == PULSE_VALUE_OBJECT) { const methodIndex = __pulse_fastly_find(init, "method"); if (methodIndex >= 0) method = __pulse_fastly_string(unchecked(init.values[methodIndex])).toUpperCase(); const headersIndex = __pulse_fastly_find(init, "headers"); if (headersIndex >= 0) headers = __pulse_fastly_value(unchecked(init.values[headersIndex])); const bodyIndex = __pulse_fastly_find(init, "body"); if (bodyIndex >= 0) { const bodyValue = unchecked(init.values[bodyIndex]); const bodyObject = __pulse_fastly_value(bodyValue); body = bodyObject.kind == PULSE_VALUE_STRING ? bodyObject.text : __pulse_fastly_json(bodyValue, 0) } }
|
|
614
650
|
const requestOut = __pulse_fastly_out_i32(); let status = fastly_http_req_new(changetype<usize>(requestOut)); if (status != FASTLY_STATUS_OK) { __pulse_fastly_fail(PULSE_ERROR_HOSTCALL, 70, effectIndex); return } const requestHandle = __pulse_fastly_out_value(requestOut)
|
|
615
651
|
const bodyOut = __pulse_fastly_out_i32(); status = fastly_http_body_new(changetype<usize>(bodyOut)); if (status != FASTLY_STATUS_OK) { __pulse_fastly_fail(PULSE_ERROR_HOSTCALL, 71, effectIndex); return } const bodyHandle = __pulse_fastly_out_value(bodyOut)
|
|
616
652
|
const methodBytes = __pulse_fastly_utf8(method); status = fastly_http_req_method_set(requestHandle, changetype<usize>(methodBytes), methodBytes.byteLength); if (status != FASTLY_STATUS_OK) { __pulse_fastly_fail(PULSE_ERROR_HOSTCALL, 72, effectIndex); return }
|