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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +52 -1
  2. package/dist/config-schema.json +73 -0
  3. package/dist/index.d.ts +61 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +59 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +87 -5
  8. package/src/build/canonical-target.js +436 -0
  9. package/src/build/entities-native.js +564 -0
  10. package/src/build/fixed-memory-runtime.as.ts +148 -0
  11. package/src/build/native-http-effects.js +871 -0
  12. package/src/build/native-http-shell.js +703 -0
  13. package/src/build/native-platform-capabilities.js +2109 -0
  14. package/src/compiler/assets-package-out-parity-proof.js +338 -0
  15. package/src/compiler/assets-provider-proof.js +499 -0
  16. package/src/compiler/config-provider-resolution.js +573 -0
  17. package/src/compiler/fastly-adapter.js +564 -0
  18. package/src/compiler/fastly-command-entry.js +390 -0
  19. package/src/compiler/fastly-config-secret-serve.js +323 -0
  20. package/src/compiler/fastly-hostcall-binding.js +598 -0
  21. package/src/compiler/fastly-readiness.js +477 -0
  22. package/src/compiler/index.js +40 -0
  23. package/src/compiler/lifecycle-parity-contract.js +70 -0
  24. package/src/compiler/lifecycle-parity-proof.js +260 -0
  25. package/src/compiler/route-handler-effect-proof.js +255 -0
  26. package/src/compiler/runtime-provider-kv.js +237 -0
  27. package/src/compiler/runtime-provider-shape.js +109 -0
  28. package/src/config-api.js +63 -0
  29. package/src/config-schema.d.ts +13 -0
  30. package/src/config-schema.js +27 -0
  31. package/src/config-schema.json +73 -0
  32. package/src/index.js +3 -0
  33. package/src/index.ts +118 -0
  34. package/src/javascript/assets-adapter.js +122 -0
  35. package/src/javascript/bindings-adapter.js +237 -0
  36. package/src/javascript/errors.js +26 -0
  37. package/src/javascript/fetch-adapter.js +93 -0
  38. package/src/javascript/grip-broadcast.js +261 -0
  39. package/src/javascript/jwt-verifier.js +137 -0
  40. package/src/javascript/lifecycle.js +55 -0
  41. package/src/javascript/local-loader.js +138 -0
  42. package/src/javascript/logging.js +26 -0
  43. package/src/javascript/package-effects.js +68 -0
  44. package/src/javascript/runtime-host.js +108 -0
  45. package/src/javascript/sha256.js +128 -0
  46. package/src/javascript/source-package.js +776 -0
  47. package/src/javascript/support.js +142 -0
  48. package/src/javascript/target-support-policy.js +260 -0
  49. package/src/javascript/target.js +73 -0
  50. package/src/javascript/test-runtime.js +407 -0
  51. package/src/provider-contract.js +72 -0
  52. package/src/runtime/assets-provider.js +464 -0
  53. package/src/runtime/canonical-api-runtime.js +597 -0
  54. package/src/runtime/index.js +28 -0
  55. package/src/runtime/provider-primitives-contract.js +272 -0
  56. package/src/runtime/provider-primitives.js +82 -0
  57. package/src/runtime/route-handler-effects.js +507 -0
  58. package/src/testing/fastly-cli.js +538 -0
  59. package/src/testing/native-http-effects-host.js +390 -0
  60. package/src/testing/native-http-shell-host.js +190 -0
  61. package/src/testing/native-platform-capabilities-host.js +599 -0
  62. package/src/toolchain/config.js +128 -0
  63. package/src/toolchain/index.js +343 -0
@@ -0,0 +1,148 @@
1
+ /*
2
+ * Fixed-memory AssemblyScript runtime for guest-linked Fastly Native modules.
3
+ *
4
+ * The ES256 guest contract reserves [0, 262144) for Rust, [262144, 524288)
5
+ * for primary static data, and [524288, 540928) for the private invocation
6
+ * frame. Dynamic primary allocations use [540928, 2097152). The allocator
7
+ * reclaims and coalesces blocks and asks the mark/sweep runtime to collect
8
+ * before reporting exhaustion. It contains no memory.grow instruction.
9
+ */
10
+
11
+ import {
12
+ AL_MASK,
13
+ BLOCK_MAXSIZE,
14
+ BLOCK_OVERHEAD,
15
+ } from "~lib/rt/common"
16
+ import "~lib/rt/itcms"
17
+
18
+ const PRIMARY_HEAP_START: usize = 540928
19
+ const PRIMARY_HEAP_END: usize = 2097152
20
+ const FREE: usize = 1
21
+ const MIN_PAYLOAD: usize =
22
+ ((1 + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD
23
+
24
+ @lazy let startOffset: usize =
25
+ ((PRIMARY_HEAP_START + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD
26
+ @lazy let endOffset: usize = startOffset
27
+ @lazy let collecting: bool = false
28
+
29
+ @inline function computeSize(size: usize): usize {
30
+ return ((size + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD
31
+ }
32
+
33
+ @inline function blockSize(block: usize): usize {
34
+ return load<usize>(block) & ~FREE
35
+ }
36
+
37
+ @inline function blockIsFree(block: usize): bool {
38
+ return (load<usize>(block) & FREE) != 0
39
+ }
40
+
41
+ function allocateFromFree(block: usize, actualSize: usize, size: usize): usize {
42
+ const remaining = actualSize - size
43
+ if (remaining >= BLOCK_OVERHEAD + MIN_PAYLOAD) {
44
+ const next = block + BLOCK_OVERHEAD + size
45
+ store<usize>(next, (remaining - BLOCK_OVERHEAD) | FREE)
46
+ store<usize>(block, size)
47
+ } else {
48
+ store<usize>(block, actualSize)
49
+ }
50
+ return block + BLOCK_OVERHEAD
51
+ }
52
+
53
+ function tryAllocate(size: usize): usize {
54
+ let cursor = startOffset
55
+ while (cursor < endOffset) {
56
+ const actualSize = blockSize(cursor)
57
+ if (blockIsFree(cursor) && actualSize >= size) {
58
+ return allocateFromFree(cursor, actualSize, size)
59
+ }
60
+ cursor += BLOCK_OVERHEAD + actualSize
61
+ }
62
+ const nextEnd = endOffset + BLOCK_OVERHEAD + size
63
+ if (nextEnd > PRIMARY_HEAP_END) return 0
64
+ const block = endOffset
65
+ endOffset = nextEnd
66
+ store<usize>(block, size)
67
+ return block + BLOCK_OVERHEAD
68
+ }
69
+
70
+ function coalesce(): void {
71
+ let cursor = startOffset
72
+ while (cursor < endOffset) {
73
+ let actualSize = blockSize(cursor)
74
+ let next = cursor + BLOCK_OVERHEAD + actualSize
75
+ if (blockIsFree(cursor)) {
76
+ while (next < endOffset && blockIsFree(next)) {
77
+ actualSize += BLOCK_OVERHEAD + blockSize(next)
78
+ store<usize>(cursor, actualSize | FREE)
79
+ next = cursor + BLOCK_OVERHEAD + actualSize
80
+ }
81
+ if (next == endOffset) {
82
+ endOffset = cursor
83
+ return
84
+ }
85
+ }
86
+ cursor = next
87
+ }
88
+ }
89
+
90
+ @unsafe @global
91
+ export function __alloc(size: usize): usize {
92
+ if (size > BLOCK_MAXSIZE) unreachable()
93
+ const payloadSize = computeSize(size)
94
+ let pointer = tryAllocate(payloadSize)
95
+ if (pointer == 0 && !collecting) {
96
+ collecting = true
97
+ __collect()
98
+ collecting = false
99
+ coalesce()
100
+ pointer = tryAllocate(payloadSize)
101
+ }
102
+ if (pointer == 0) unreachable()
103
+ return pointer
104
+ }
105
+
106
+ @unsafe @global
107
+ export function __realloc(pointer: usize, size: usize): usize {
108
+ if (pointer == 0 || (pointer & AL_MASK) != 0) unreachable()
109
+ const block = pointer - BLOCK_OVERHEAD
110
+ const actualSize = blockSize(block)
111
+ const payloadSize = computeSize(size)
112
+ if (payloadSize <= actualSize) {
113
+ const remaining = actualSize - payloadSize
114
+ if (remaining >= BLOCK_OVERHEAD + MIN_PAYLOAD) {
115
+ const next = block + BLOCK_OVERHEAD + payloadSize
116
+ store<usize>(block, payloadSize)
117
+ store<usize>(next, (remaining - BLOCK_OVERHEAD) | FREE)
118
+ coalesce()
119
+ }
120
+ return pointer
121
+ }
122
+ const right = block + BLOCK_OVERHEAD + actualSize
123
+ if (right < endOffset && blockIsFree(right)) {
124
+ const combined = actualSize + BLOCK_OVERHEAD + blockSize(right)
125
+ if (combined >= payloadSize) {
126
+ return allocateFromFree(block, combined, payloadSize)
127
+ }
128
+ }
129
+ const newPointer = __alloc(max<usize>(payloadSize, actualSize << 1))
130
+ for (let index: usize = 0; index < actualSize; index += 1) {
131
+ store<u8>(newPointer + index, load<u8>(pointer + index))
132
+ }
133
+ __free(pointer)
134
+ return newPointer
135
+ }
136
+
137
+ @unsafe @global
138
+ export function __free(pointer: usize): void {
139
+ if (pointer == 0 || (pointer & AL_MASK) != 0) unreachable()
140
+ const block = pointer - BLOCK_OVERHEAD
141
+ store<usize>(block, blockSize(block) | FREE)
142
+ coalesce()
143
+ }
144
+
145
+ @unsafe @global
146
+ export function __reset(): void {
147
+ endOffset = startOffset
148
+ }