@pulse-compute/provider-fastly 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,9 +6,10 @@
6
6
  > **Install directly:** Yes, for Fastly projects. Node-only projects do not need to import it directly.<br>
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
- > **Canonical documentation:** [Package guide](https://pulsecompute.io/v1.0.0-beta.1/packages/provider-fastly/)
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.2/packages/provider-fastly/)
10
11
  >
11
- > This release-status block is generated from the synchronized `Pulse 1.0.0-beta.1` package policy.
12
+ > This release-status block is generated from the synchronized `Pulse 1.0.0-beta.2` package policy.
12
13
  <!-- pulse-package-status:end -->
13
14
 
14
15
  Fastly provider configuration, canonical capability lowering, local conformance execution, Compute target generation, and explicit external-tool boundaries.
@@ -48,7 +49,7 @@ trusted wall-clock authority. It does not fall back to Node execution.
48
49
 
49
50
  ## Documentation
50
51
 
51
- - [Fastly package guide](https://pulsecompute.io/v1.0.0-beta.1/packages/provider-fastly/)
52
- - [Project configuration](https://pulsecompute.io/v1.0.0-beta.1/reference/project-config/#fastly-provider-options)
53
- - [Fastly capabilities guide](https://pulsecompute.io/v1.0.0-beta.1/guides/fastly-capabilities/)
54
- - [Environment variables](https://pulsecompute.io/v1.0.0-beta.1/reference/environment/#pulse-fastly-bin)
52
+ - [Fastly package guide](https://pulsecompute.io/v1.0.0-beta.2/packages/provider-fastly/)
53
+ - [Project configuration](https://pulsecompute.io/v1.0.0-beta.2/reference/project-config/#fastly-provider-options)
54
+ - [Fastly capabilities guide](https://pulsecompute.io/v1.0.0-beta.2/guides/fastly-capabilities/)
55
+ - [Environment variables](https://pulsecompute.io/v1.0.0-beta.2/reference/environment/#pulse-fastly-bin)
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "schemaVersion": "pulse.provider-fastly-config-schema.v1",
3
3
  "fields": {
4
+ "fastly.bindings.s3": {
5
+ "kind": "object",
6
+ "default": {}
7
+ },
4
8
  "fastly.configStore": {
5
9
  "kind": "string",
6
10
  "default": "pulse_config"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-compute/provider-fastly",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "license": "Apache-2.0",
5
5
  "engines": {
6
6
  "node": "^22.14.0 || ^24.0.0"
@@ -59,14 +59,15 @@
59
59
  }
60
60
  },
61
61
  "dependencies": {
62
- "@pulse-compute/crypto": "1.0.0-beta.1",
63
- "@pulse-compute/jwt": "1.0.0-beta.1",
64
- "@pulse-compute/runtime": "1.0.0-beta.1",
65
- "@pulse-compute/wasm-build-support": "1.0.0-beta.1",
66
- "@pulse-compute/wasm-contracts": "1.0.0-beta.1",
67
- "@pulse-compute/wasm-guest-link": "1.0.0-beta.1",
68
- "@pulse-compute/wasm-host-runtime": "1.0.0-beta.1",
69
- "@pulse-compute/wasm-runtime-core-as": "1.0.0-beta.1",
62
+ "@pulse-compute/crypto": "1.0.0-beta.2",
63
+ "@pulse-compute/jwt": "1.0.0-beta.2",
64
+ "@pulse-compute/runtime": "1.0.0-beta.2",
65
+ "@pulse-compute/s3": "1.0.0-beta.2",
66
+ "@pulse-compute/wasm-build-support": "1.0.0-beta.2",
67
+ "@pulse-compute/wasm-contracts": "1.0.0-beta.2",
68
+ "@pulse-compute/wasm-guest-link": "1.0.0-beta.2",
69
+ "@pulse-compute/wasm-host-runtime": "1.0.0-beta.2",
70
+ "@pulse-compute/wasm-runtime-core-as": "1.0.0-beta.2",
70
71
  "esbuild": "0.28.1"
71
72
  },
72
73
  "types": "./dist/index.d.ts",
@@ -86,7 +87,7 @@
86
87
  "url": "git+https://github.com/pulse-compute/pulse.git",
87
88
  "directory": "packages/provider-fastly"
88
89
  },
89
- "homepage": "https://pulsecompute.io/v1.0.0-beta.1/packages/provider-fastly/",
90
+ "homepage": "https://pulsecompute.io/v1.0.0-beta.2/packages/provider-fastly/",
90
91
  "bugs": {
91
92
  "url": "https://github.com/pulse-compute/pulse/issues"
92
93
  },
@@ -0,0 +1,229 @@
1
+ // Fastly Native realization of the runtime-owned K1/K2 conditional KV contract.
2
+ // Limits are generated from runtime/host. No SDK or unconditional CAS fallback.
3
+ @external('fastly_async_io', 'select') declare function __kv_select(handles: usize, count: i32, timeout: i32, ready: usize): i32
4
+ @external('fastly_http_body', 'close') declare function __kv_close(body: i32): i32
5
+
6
+ @lazy const __kv_deadline = new StaticArray<i64>(PULSE_FASTLY_EFFECT_COUNT)
7
+ @lazy const __kv_dispatched = new StaticArray<bool>(PULSE_FASTLY_EFFECT_COUNT)
8
+ let __kv_request_deadline: i64 = -1;
9
+ // Host embedding seam, in monotonic nanoseconds; never exposed through ctx.
10
+ export function pulse_fastly_kv_request_deadline(deadline: i64): void { __kv_request_deadline = deadline; }
11
+ function __kv_clock(): i64 {
12
+ const out = new StaticArray<i64>(1);
13
+ return wasi_snapshot_preview1_clock_time_get(1, 1, changetype<usize>(out)) == 0 ? out[0] : -1;
14
+ }
15
+ function __kv_remaining(index: i32): i32 {
16
+ const now = __kv_clock();
17
+ if (now < 0) return -1;
18
+ const remaining = __kv_deadline[index] - now;
19
+ return remaining <= 0 ? 0 : i32((remaining + 999999) / 1000000);
20
+ }
21
+ function __kv_set(result: i32, key: string, value: i32): void { host_value_object_set(result, __pulse_fastly_string_value(key), value); }
22
+ function __kv_result(status: string, reason: string = ''): i32 {
23
+ const result = host_value_object(); __kv_set(result, 'status', __pulse_fastly_string_value(status));
24
+ if (reason.length) __kv_set(result, 'reason', __pulse_fastly_string_value(reason));
25
+ return result;
26
+ }
27
+ function __kv_failure(index: i32, reason: string): i32 {
28
+ return __kv_result(__pulse_fastly_effect_kind(index) == 15 ? 'failed' : __kv_dispatched[index] ? 'unknown' : 'not-stored', reason);
29
+ }
30
+ function __kv_fail(index: i32, reason: string): void { __pulse_fastly_ready_effect(index, __kv_failure(index, reason)); }
31
+ function __kv_expired(index: i32): bool {
32
+ const remaining = __kv_remaining(index);
33
+ if (remaining > 0) return false;
34
+ __kv_fail(index, remaining == 0 ? 'timeout' : 'unavailable'); return true;
35
+ }
36
+ // select readiness guarantees the corresponding I/O action will not block.
37
+ // Zero timeout means infinity in this ABI, so it must never be passed.
38
+ function __kv_ready(index: i32, handle: i32): i32 {
39
+ const remaining = __kv_remaining(index); if (remaining <= 0) return remaining;
40
+ const handles = new StaticArray<i32>(1), out = new StaticArray<i32>(1);
41
+ handles[0] = handle; out[0] = -1;
42
+ if (__kv_select(changetype<usize>(handles), 1, remaining, changetype<usize>(out)) != 0) return -1;
43
+ const after = __kv_remaining(index); if (after <= 0) return after;
44
+ return out[0] == 0 ? 1 : out[0] == -1 ? 0 : -2;
45
+ }
46
+ function __kv_ready_failure(index: i32, ready: i32): i32 { return __kv_failure(index, ready == 0 ? 'timeout' : ready == -2 ? 'protocol' : 'transport'); }
47
+ function __kv_key(text: string): bool {
48
+ if (text == ' ' || text == '\ufffe' || text == '\uffff') return false;
49
+ if (!text.length || text.length > __KV_keyBytes || String.UTF8.byteLength(text) > __KV_keyBytes) return false;
50
+ for (let i = 0; i < text.length; i++) {
51
+ const c = text.charCodeAt(i);
52
+ if (c < 32 || (c >= 127 && c <= 159)) return false;
53
+ if (c >= 0xd800 && c <= 0xdbff) { if (++i >= text.length) return false; const next = text.charCodeAt(i); if (next < 0xdc00 || next > 0xdfff) return false; }
54
+ else if (c >= 0xdc00 && c <= 0xdfff) return false;
55
+ }
56
+ // Fastly's exact-key restrictions; never normalize an application key.
57
+ return text != '.' && text != '..' && !text.startsWith('.well-known/acme-challenge')
58
+ && text.indexOf('./') < 0 && !text.endsWith('/.') && !text.endsWith('/..')
59
+ && text.indexOf('#') < 0 && text.indexOf('?') < 0 && text.indexOf('^') < 0
60
+ && text.indexOf('|') < 0 && text.indexOf(';') < 0 && text.indexOf('\n') < 0 && text.indexOf('\r') < 0;
61
+ }
62
+ function __kv_token_valid(token: string): bool {
63
+ if (token.length != 29 || !token.startsWith('fastly-kv-v1:')) return false;
64
+ for (let i = 13; i < 29; i++) { const c = token.charCodeAt(i); if (!(c >= 48 && c <= 57) && !(c >= 97 && c <= 102)) return false; }
65
+ return true;
66
+ }
67
+ function __kv_generation(token: string): u64 {
68
+ let value: u64 = 0;
69
+ for (let i = 13; i < 29; i++) { const c = token.charCodeAt(i); value = (value << 4) | u64(c <= 57 ? c - 48 : c - 87); }
70
+ return value;
71
+ }
72
+ function __kv_token(value: u64): string {
73
+ let text = 'fastly-kv-v1:';
74
+ for (let i = 15; i >= 0; i--) text += '0123456789abcdef'.charAt(i32((value >> (i * 4)) & 15));
75
+ return text;
76
+ }
77
+ function __kv_number(value: f64): string {
78
+ const text = __pulse_fastly_number_string(value);
79
+ // AS prints a trailing .0 for large integral f64s; JSON.stringify does not.
80
+ // Count the portable serialized value budget, including this boundary case.
81
+ return text.endsWith('.0') ? text.substring(0, text.length - 2) : text;
82
+ }
83
+ function __kv_private(text: string): void {
84
+ __pulse_fastly_remember_secret(text);
85
+ const encoded = __pulse_fastly_quote(text);
86
+ __pulse_fastly_remember_secret(encoded.substring(1, encoded.length - 1));
87
+ }
88
+ class __KvEncoder {
89
+ 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); }
92
+ visit(handle: i32, depth: i32 = 0): void {
93
+ if (this.reason.length) return;
94
+ if (++this.entries > __KV_entries || depth > __KV_depth) { this.reason = 'too-large'; return; }
95
+ const value = __pulse_fastly_value(handle);
96
+ if (value.kind == PULSE_VALUE_NULL) this.add('null');
97
+ 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)); }
99
+ 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
+ else if (value.kind == PULSE_VALUE_ARRAY || value.kind == PULSE_VALUE_OBJECT) {
101
+ if (this.seen.has(handle)) { this.reason = 'invalid-value'; return; } this.seen.add(handle);
102
+ const object = value.kind == PULSE_VALUE_OBJECT; this.add(object ? '{' : '[');
103
+ for (let i = 0; i < value.values.length && !this.reason.length; i++) {
104
+ if (i) this.add(',');
105
+ if (object) { __kv_private(value.keys[i]); this.add(__pulse_fastly_quote(value.keys[i]) + ':'); }
106
+ this.visit(value.values[i], depth + 1);
107
+ }
108
+ this.add(object ? '}' : ']');
109
+ } else this.reason = 'invalid-value';
110
+ }
111
+ encode(handle: i32): string { this.visit(handle); return this.reason.length ? '' : this.parts.join(''); }
112
+ }
113
+ function __pulse_fastly_kv_conditional_begin(index: i32, payload: __PulseFastlyValue): void {
114
+ __kv_dispatched[index] = false;
115
+ const start = __kv_clock(); if (start < 0) { __kv_fail(index, 'unavailable'); return; }
116
+ __kv_deadline[index] = start + i64(__KV_timeoutMs) * 1000000;
117
+ if (__kv_request_deadline >= 0 && __kv_request_deadline < __kv_deadline[index]) __kv_deadline[index] = __kv_request_deadline;
118
+ const kind = __pulse_fastly_effect_kind(index), key = __pulse_fastly_value(__pulse_fastly_payload_field(payload, 'key'));
119
+ if (key.kind != PULSE_VALUE_STRING || !__kv_key(key.text)) { __kv_fail(index, 'invalid-key'); return; }
120
+ __kv_private(key.text);
121
+ let generation: u64 = 0;
122
+ if (kind == 17) {
123
+ const token = __pulse_fastly_value(__pulse_fastly_payload_field(payload, 'generation'));
124
+ if (token.kind != PULSE_VALUE_STRING || !__kv_token_valid(token.text)) { __kv_fail(index, 'invalid-generation'); return; }
125
+ __kv_private(token.text); generation = __kv_generation(token.text);
126
+ }
127
+ let wire = '';
128
+ if (kind != 15) {
129
+ const encoder = new __KvEncoder(); const json = encoder.encode(__pulse_fastly_payload_field(payload, 'value'));
130
+ if (encoder.reason.length) { __kv_fail(index, encoder.reason); return; }
131
+ // Immutable string snapshot exists before any binding/body/dispatch hostcall.
132
+ wire = '{"__pulseKv":1,"value":' + json + '}';
133
+ if (String.UTF8.byteLength(wire) > __KV_wireBytes) { __kv_fail(index, 'too-large'); return; }
134
+ }
135
+ if (__kv_expired(index)) return;
136
+ const name = __pulse_fastly_utf8(__pulse_fastly_kv_store(index)), storeHandle = new StaticArray<i32>(1);
137
+ if (fastly_kv_store_open(changetype<usize>(name), name.byteLength, changetype<usize>(storeHandle)) != 0) { __kv_fail(index, 'configuration'); return; }
138
+ if (__kv_expired(index)) return;
139
+ const keyBytes = __pulse_fastly_utf8(key.text), pending = new StaticArray<i32>(1); let status: i32;
140
+ if (kind == 15) {
141
+ const config = new StaticArray<i32>(1);
142
+ status = fastly_kv_store_lookup(storeHandle[0], changetype<usize>(keyBytes), keyBytes.byteLength, 0, changetype<usize>(config), changetype<usize>(pending));
143
+ } else {
144
+ const body = new StaticArray<i32>(1), written = new StaticArray<i32>(1);
145
+ if (fastly_http_body_new(changetype<usize>(body)) != 0) { __kv_fail(index, 'transport'); return; }
146
+ if (__kv_expired(index)) { __kv_close(body[0]); return; }
147
+ const bytes = __pulse_fastly_utf8(wire);
148
+ status = fastly_http_body_write(body[0], changetype<usize>(bytes), bytes.byteLength, 0, changetype<usize>(written));
149
+ if (status != 0 || written[0] != bytes.byteLength) { __kv_close(body[0]); __kv_fail(index, status != 0 ? 'transport' : 'protocol'); return; }
150
+ if (__kv_expired(index)) { __kv_close(body[0]); return; }
151
+ const config = new StaticArray<u64>(4); // 32 zeroed bytes, including padding.
152
+ if (kind == 16) store<u32>(changetype<usize>(config), 1);
153
+ else store<u64>(changetype<usize>(config) + 24, generation);
154
+ __kv_dispatched[index] = true; // Entry is the conservative mutation boundary.
155
+ status = fastly_kv_store_insert(storeHandle[0], changetype<usize>(keyBytes), keyBytes.byteLength, body[0], kind == 17 ? 32 : 0, changetype<usize>(config), changetype<usize>(pending));
156
+ // Insert takes ownership on success. On error the body may already be consumed;
157
+ // best-effort close cannot turn uncertain acceptance into rejection.
158
+ if (status != 0) __kv_close(body[0]);
159
+ }
160
+ if (status != 0) { __kv_fail(index, 'transport'); return; }
161
+ __pulse_fastly_pending[index] = pending[0]; __pulse_fastly_pending_mode[index] = PULSE_FASTLY_PENDING_ASYNC;
162
+ }
163
+ function __kv_utf8(data: Uint8Array, length: i32): bool {
164
+ for (let i = 0; i < length;) {
165
+ const c = data[i++]; if (c <= 127) continue;
166
+ const count = c >= 194 && c <= 223 ? 1 : c >= 224 && c <= 239 ? 2 : c >= 240 && c <= 244 ? 3 : -1;
167
+ if (count < 0 || i + count > length) return false;
168
+ const second = data[i];
169
+ if ((c == 224 && second < 160) || (c == 237 && second > 159) || (c == 240 && second < 144) || (c == 244 && second > 143)) return false;
170
+ for (let j = 0; j < count; j++) { const next = data[i++]; if (next < 128 || next > 191) return false; }
171
+ }
172
+ return true;
173
+ }
174
+ 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;
176
+ while (true) {
177
+ const ready = __kv_ready(index, body); if (ready <= 0) return __kv_ready_failure(index, ready);
178
+ written[0] = 0;
179
+ if (fastly_http_body_read(body, buffer.dataStart + count, buffer.length - count, changetype<usize>(written)) != 0) return __kv_failure(index, 'transport');
180
+ if (written[0] < 0 || written[0] > buffer.length - count) return __kv_failure(index, 'protocol');
181
+ if (!written[0]) break;
182
+ count += written[0]; if (count > __KV_wireBytes) return __kv_failure(index, 'too-large');
183
+ }
184
+ if (!__kv_utf8(buffer, count)) return __kv_failure(index, 'protocol');
185
+ const parser = new __PulseJsonParser(String.UTF8.decodeUnsafe(buffer.dataStart, count, false), true), parsed = parser.parse();
186
+ if (parser.failed || parsed <= 0) return __kv_failure(index, parser.tooLarge ? 'too-large' : 'protocol');
187
+ const outer = __pulse_fastly_value(parsed);
188
+ 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
+ const marker = __pulse_fastly_value(__pulse_fastly_payload_field(outer, '__pulseKv'));
190
+ 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);
192
+ if (encoder.reason.length) return __kv_failure(index, encoder.reason);
193
+ const remaining = __kv_remaining(index); if (remaining <= 0) return __kv_failure(index, remaining == 0 ? 'timeout' : 'unavailable');
194
+ const result = __kv_result('found'), token = __kv_token(generation); __kv_private(token);
195
+ __kv_set(result, 'generation', __pulse_fastly_string_value(token)); __kv_set(result, 'value', value);
196
+ __pulse_fastly_deep_freeze(result); return result;
197
+ }
198
+ function __kv_wait(index: i32): i32 {
199
+ if (__pulse_fastly_pending_mode[index] == PULSE_FASTLY_PENDING_READY) return __pulse_fastly_wait_ready(index);
200
+ const pending = __pulse_fastly_pending[index];
201
+ __pulse_fastly_pending_mode[index] = PULSE_FASTLY_PENDING_NONE; __pulse_fastly_pending[index] = 0; __pulse_fastly_payloads[index] = 0;
202
+ // No KV cancel hostcall exists. An expired pending handle is left to invocation
203
+ // teardown; never call an unready wait just to drain it, and never retry.
204
+ const ready = __kv_ready(index, pending); if (ready <= 0) return __kv_ready_failure(index, ready);
205
+ const error = new StaticArray<i32>(1), kind = __pulse_fastly_effect_kind(index);
206
+ if (kind != 15) {
207
+ const status = fastly_kv_store_insert_wait(pending, changetype<usize>(error));
208
+ if (status != 0) return __kv_failure(index, 'transport');
209
+ const remaining = __kv_remaining(index); if (remaining <= 0) return __kv_failure(index, remaining == 0 ? 'timeout' : 'unavailable');
210
+ if (error[0] == 1) return __kv_result('stored');
211
+ if (error[0] == 4 || (error[0] == 3 && kind == 17)) return __kv_result('conflict');
212
+ if (error[0] == 2 || error[0] == 5 || error[0] == 7) return __kv_result('not-stored', error[0] == 2 ? 'rejected' : error[0] == 5 ? 'too-large' : 'throttled');
213
+ return __kv_failure(index, error[0] == 6 ? 'unavailable' : 'protocol');
214
+ }
215
+ const body = new StaticArray<i32>(1), metadata = new Uint8Array(2000), written = new StaticArray<i32>(1), generation = new StaticArray<u64>(1);
216
+ const status = fastly_kv_store_lookup_wait_v2(pending, changetype<usize>(body), metadata.dataStart, metadata.length, changetype<usize>(written), changetype<usize>(generation), changetype<usize>(error));
217
+ if (status != 0) return __kv_failure(index, 'transport');
218
+ if (error[0] != 1) {
219
+ const remaining = __kv_remaining(index); if (remaining <= 0) return __kv_failure(index, remaining == 0 ? 'timeout' : 'unavailable');
220
+ if (error[0] == 3) return __kv_result('not-found');
221
+ return __kv_failure(index, error[0] == 5 ? 'too-large' : error[0] == 6 ? 'unavailable' : error[0] == 7 ? 'throttled' : 'protocol');
222
+ }
223
+ const result = written[0] < 0 || written[0] > metadata.length ? __kv_failure(index, 'protocol') : __kv_read(index, body[0], generation[0]);
224
+ __kv_close(body[0]); return result;
225
+ }
226
+
227
+ function __pulse_fastly_kv_conditional_wait(index: i32): i32 {
228
+ const result = __kv_wait(index); __pulse_fastly_deep_freeze(result); return result;
229
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const { KV_CONDITIONAL_KINDS, KV_CONDITIONAL_LIMITS } = require('@pulse-compute/runtime/host');
5
+
6
+ const KV_IMPORTS = Object.freeze([
7
+ 'fastly_async_io:select', 'fastly_http_body:close', 'wasi_snapshot_preview1:clock_time_get',
8
+ 'fastly_kv_store:open'
9
+ ]);
10
+ function kvImports(kind) {
11
+ return [...KV_IMPORTS, ...(kind === 'kv.getVersioned'
12
+ ? ['fastly_kv_store:lookup', 'fastly_kv_store:lookup_wait_v2', 'fastly_http_body:read']
13
+ : ['fastly_kv_store:insert', 'fastly_kv_store:insert_wait', 'fastly_http_body:new', 'fastly_http_body:write'])];
14
+ }
15
+ function kvNativeSource(plan) {
16
+ if (!plan.effects.some(effect => KV_CONDITIONAL_KINDS.includes(effect.kind))) return '';
17
+ const limits = Object.entries(KV_CONDITIONAL_LIMITS).map(([key, value]) => `const __KV_${key}: i32 = ${value};`).join('\n');
18
+ return limits + '\n' + fs.readFileSync(path.join(__dirname, 'kv-native.as.ts'), 'utf8');
19
+ }
20
+ module.exports = { KV_CONDITIONAL_KINDS, KV_CONDITIONAL_LIMITS, KV_IMPORTS, kvImports, kvNativeSource };