@timber-js/app 0.2.0-alpha.166 → 0.2.0-alpha.168
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/dist/_chunks/{actions-CDPfMp_I.js → actions-O_LsyCE4.js} +3 -3
- package/dist/_chunks/{actions-CDPfMp_I.js.map → actions-O_LsyCE4.js.map} +1 -1
- package/dist/_chunks/{cache-api-DygSeKCB.js → cache-api-B-lhk9p4.js} +107 -58
- package/dist/_chunks/cache-api-B-lhk9p4.js.map +1 -0
- package/dist/_chunks/{cli-schema-sync-EXGYPhI2.js → cli-schema-sync-B73L6pMq.js} +5 -3
- package/dist/_chunks/cli-schema-sync-B73L6pMq.js.map +1 -0
- package/dist/_chunks/cloudflare-AHoWYTYr.js +1188 -0
- package/dist/_chunks/cloudflare-AHoWYTYr.js.map +1 -0
- package/dist/_chunks/json-lossy-check-ClNvBM_3.js +63 -0
- package/dist/_chunks/json-lossy-check-ClNvBM_3.js.map +1 -0
- package/dist/_chunks/{logger-t3uxAmbX.js → logger-AWfuX-KJ.js} +2 -19
- package/dist/_chunks/logger-AWfuX-KJ.js.map +1 -0
- package/dist/_chunks/{walkers-DBVzXuWc.js → walkers-CoOC8Hga.js} +2 -2
- package/dist/_chunks/{walkers-DBVzXuWc.js.map → walkers-CoOC8Hga.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +10 -3
- package/dist/adapters/cloudflare-kv-cache.js.map +1 -1
- package/dist/adapters/cloudflare.d.ts +12 -1
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +2 -461
- package/dist/adapters/types.d.ts +2 -0
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/cache/cache-api.d.ts +33 -11
- package/dist/cache/cache-api.d.ts.map +1 -1
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cache/json-lossy-check.d.ts +11 -0
- package/dist/cache/json-lossy-check.d.ts.map +1 -0
- package/dist/cache/redis-handler.d.ts +42 -0
- package/dist/cache/redis-handler.d.ts.map +1 -1
- package/dist/cache/singleflight.d.ts.map +1 -1
- package/dist/cache/stores/cloudflare-kv.d.ts +1 -1
- package/dist/cache/stores/cloudflare-kv.d.ts.map +1 -1
- package/dist/cache/stores/memory.d.ts +1 -1
- package/dist/cache/stores/memory.d.ts.map +1 -1
- package/dist/cache/stores/redis.d.ts +1 -1
- package/dist/cache/stores/redis.d.ts.map +1 -1
- package/dist/cache/stores/vercel.d.ts +1 -1
- package/dist/cache/stores/vercel.d.ts.map +1 -1
- package/dist/cache/tag-aware-handler.d.ts.map +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cdn/cloudflare-purge.d.ts.map +1 -1
- package/dist/cdn/fastly-purge.d.ts.map +1 -1
- package/dist/cdn/workers-cache-purge.d.ts.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/client/browser-entry/post-hydration.d.ts.map +1 -1
- package/dist/client/browser-entry/router-init.d.ts +1 -0
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/child-segment-context.d.ts +2 -2
- package/dist/client/child-segment-context.d.ts.map +1 -1
- package/dist/client/error-boundary.d.ts.map +1 -1
- package/dist/client/history.d.ts +10 -0
- package/dist/client/history.d.ts.map +1 -1
- package/dist/client/internal.js +141 -116
- package/dist/client/internal.js.map +1 -1
- package/dist/client/router.d.ts +6 -0
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/rsc-fetch.d.ts.map +1 -1
- package/dist/client/segment-cache.d.ts.map +1 -1
- package/dist/client/segment-update-context.d.ts +3 -3
- package/dist/client/segment-update-context.d.ts.map +1 -1
- package/dist/client/slot-outlet.d.ts +1 -1
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +2 -1
- package/dist/codec.js.map +1 -1
- package/dist/config-types.d.ts +16 -37
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/dev-tools/instrumentation.d.ts.map +1 -1
- package/dist/fonts/pipeline.d.ts +19 -0
- package/dist/fonts/pipeline.d.ts.map +1 -1
- package/dist/fonts/transform.d.ts.map +1 -1
- package/dist/fonts/virtual-modules.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -109
- package/dist/index.js.map +1 -1
- package/dist/plugin-context.d.ts.map +1 -1
- package/dist/plugins/adapter-build.d.ts +1 -0
- package/dist/plugins/adapter-build.d.ts.map +1 -1
- package/dist/plugins/cache.d.ts +8 -8
- package/dist/plugins/cache.d.ts.map +1 -1
- package/dist/plugins/entries.d.ts +27 -3
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/fonts.d.ts.map +1 -1
- package/dist/plugins/server-bundle.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/action-client.d.ts +1 -1
- package/dist/server/action-client.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +7 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/body-limits.d.ts.map +1 -1
- package/dist/server/deny-boundary.d.ts +3 -1
- package/dist/server/deny-boundary.d.ts.map +1 -1
- package/dist/server/form-data.d.ts.map +1 -1
- package/dist/server/html-injector-core.d.ts.map +1 -1
- package/dist/server/index.js +20 -3
- package/dist/server/index.js.map +1 -1
- package/dist/server/internal.js +28 -41
- package/dist/server/internal.js.map +1 -1
- package/dist/server/middleware-runner.d.ts +0 -17
- package/dist/server/middleware-runner.d.ts.map +1 -1
- package/dist/server/param-coercion.d.ts.map +1 -1
- package/dist/server/pipeline-phases.d.ts +6 -3
- package/dist/server/pipeline-phases.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts +18 -0
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt/capture-state.d.ts.map +1 -1
- package/dist/server/prebuilt/synthetic-store.d.ts.map +1 -1
- package/dist/server/primitives.d.ts.map +1 -1
- package/dist/server/render-timeout.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts +9 -0
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-middleware-runner.d.ts +14 -14
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +1 -0
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +8 -0
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/rsc-entry/wrap-action-dispatch.d.ts +44 -74
- package/dist/server/rsc-entry/wrap-action-dispatch.d.ts.map +1 -1
- package/dist/server/safe-load.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/shared/redirect-type.d.ts +2 -2
- package/dist/shared/redirect-type.d.ts.map +1 -1
- package/dist/shims/font-google.d.ts.map +1 -1
- package/dist/shims/image.d.ts +120 -120
- package/dist/shims/image.d.ts.map +1 -1
- package/docs/api/32-api-cache.mdx +116 -4
- package/docs/api/34-api-config.mdx +0 -26
- package/docs/learn/09-caching.mdx +126 -10
- package/docs/learn/12-client-navigation.mdx +9 -1
- package/docs/learn/13-configuration.mdx +6 -8
- package/docs/learn/14-deploying.mdx +18 -18
- package/docs/more/03-coming-from-nextjs.mdx +2 -2
- package/docs/more/04-metadata-and-fonts.mdx +1 -1
- package/docs/more/50-ai-agent-instructions.mdx +5 -5
- package/package.json +6 -5
- package/src/adapters/cloudflare-kv-cache.ts +27 -6
- package/src/adapters/cloudflare.ts +63 -25
- package/src/adapters/types.ts +2 -0
- package/src/cache/cache-api.ts +84 -84
- package/src/cache/index.ts +1 -1
- package/src/cache/json-lossy-check.ts +75 -0
- package/src/cache/redis-handler.ts +65 -14
- package/src/cache/timber-cache.ts +10 -2
- package/src/client/browser-entry/index.ts +2 -0
- package/src/client/browser-entry/post-hydration.ts +16 -9
- package/src/client/browser-entry/router-init.ts +2 -0
- package/src/client/history.ts +11 -0
- package/src/client/router.ts +224 -208
- package/src/codec.ts +3 -1
- package/src/config-types.ts +16 -37
- package/src/config-validation.ts +7 -5
- package/src/fonts/pipeline.ts +32 -0
- package/src/fonts/transform.ts +30 -24
- package/src/plugins/adapter-build.ts +132 -13
- package/src/plugins/cache.ts +45 -30
- package/src/plugins/entries.ts +40 -43
- package/src/plugins/fonts.ts +30 -0
- package/src/plugins/server-bundle.ts +7 -15
- package/src/routing/scanner.ts +7 -0
- package/src/server/action-client.ts +1 -1
- package/src/server/als-registry.ts +7 -0
- package/src/server/deny-boundary.ts +6 -3
- package/src/server/middleware-runner.ts +0 -44
- package/src/server/param-coercion.ts +1 -0
- package/src/server/pipeline-phases.ts +11 -13
- package/src/server/pipeline.ts +51 -3
- package/src/server/route-element-builder.ts +59 -9
- package/src/server/rsc-entry/action-middleware-runner.ts +14 -14
- package/src/server/rsc-entry/index.ts +30 -40
- package/src/server/rsc-entry/render-route.ts +6 -2
- package/src/server/rsc-entry/rsc-payload.ts +21 -4
- package/src/server/rsc-entry/rsc-stream.ts +8 -0
- package/src/server/rsc-entry/wrap-action-dispatch.ts +109 -372
- package/dist/_chunks/cache-api-DygSeKCB.js.map +0 -1
- package/dist/_chunks/cli-schema-sync-EXGYPhI2.js.map +0 -1
- package/dist/_chunks/logger-t3uxAmbX.js.map +0 -1
- package/dist/_chunks/tree-match-D2l830j2.js +0 -102
- package/dist/_chunks/tree-match-D2l830j2.js.map +0 -1
- package/dist/adapters/cloudflare.js.map +0 -1
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
import { t as runSharedBuildSteps } from "./build-output-helper-DF5uScqS.js";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { access, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
7
|
+
/**
|
|
8
|
+
* Creates a JSON scanner on the given text.
|
|
9
|
+
* If ignoreTrivia is set, whitespaces or comments are ignored.
|
|
10
|
+
*/
|
|
11
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
12
|
+
const len = text.length;
|
|
13
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
14
|
+
function scanHexDigits(count, exact) {
|
|
15
|
+
let digits = 0;
|
|
16
|
+
let value = 0;
|
|
17
|
+
while (digits < count || !exact) {
|
|
18
|
+
let ch = text.charCodeAt(pos);
|
|
19
|
+
if (ch >= 48 && ch <= 57) value = value * 16 + ch - 48;
|
|
20
|
+
else if (ch >= 65 && ch <= 70) value = value * 16 + ch - 65 + 10;
|
|
21
|
+
else if (ch >= 97 && ch <= 102) value = value * 16 + ch - 97 + 10;
|
|
22
|
+
else break;
|
|
23
|
+
pos++;
|
|
24
|
+
digits++;
|
|
25
|
+
}
|
|
26
|
+
if (digits < count) value = -1;
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function setPosition(newPosition) {
|
|
30
|
+
pos = newPosition;
|
|
31
|
+
value = "";
|
|
32
|
+
tokenOffset = 0;
|
|
33
|
+
token = 16;
|
|
34
|
+
scanError = 0;
|
|
35
|
+
}
|
|
36
|
+
function scanNumber() {
|
|
37
|
+
let start = pos;
|
|
38
|
+
if (text.charCodeAt(pos) === 48) pos++;
|
|
39
|
+
else {
|
|
40
|
+
pos++;
|
|
41
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
42
|
+
}
|
|
43
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
44
|
+
pos++;
|
|
45
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
46
|
+
pos++;
|
|
47
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
48
|
+
} else {
|
|
49
|
+
scanError = 3;
|
|
50
|
+
return text.substring(start, pos);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let end = pos;
|
|
54
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
55
|
+
pos++;
|
|
56
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) pos++;
|
|
57
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
58
|
+
pos++;
|
|
59
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) pos++;
|
|
60
|
+
end = pos;
|
|
61
|
+
} else scanError = 3;
|
|
62
|
+
}
|
|
63
|
+
return text.substring(start, end);
|
|
64
|
+
}
|
|
65
|
+
function scanString() {
|
|
66
|
+
let result = "", start = pos;
|
|
67
|
+
while (true) {
|
|
68
|
+
if (pos >= len) {
|
|
69
|
+
result += text.substring(start, pos);
|
|
70
|
+
scanError = 2;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
const ch = text.charCodeAt(pos);
|
|
74
|
+
if (ch === 34) {
|
|
75
|
+
result += text.substring(start, pos);
|
|
76
|
+
pos++;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (ch === 92) {
|
|
80
|
+
result += text.substring(start, pos);
|
|
81
|
+
pos++;
|
|
82
|
+
if (pos >= len) {
|
|
83
|
+
scanError = 2;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
switch (text.charCodeAt(pos++)) {
|
|
87
|
+
case 34:
|
|
88
|
+
result += "\"";
|
|
89
|
+
break;
|
|
90
|
+
case 92:
|
|
91
|
+
result += "\\";
|
|
92
|
+
break;
|
|
93
|
+
case 47:
|
|
94
|
+
result += "/";
|
|
95
|
+
break;
|
|
96
|
+
case 98:
|
|
97
|
+
result += "\b";
|
|
98
|
+
break;
|
|
99
|
+
case 102:
|
|
100
|
+
result += "\f";
|
|
101
|
+
break;
|
|
102
|
+
case 110:
|
|
103
|
+
result += "\n";
|
|
104
|
+
break;
|
|
105
|
+
case 114:
|
|
106
|
+
result += "\r";
|
|
107
|
+
break;
|
|
108
|
+
case 116:
|
|
109
|
+
result += " ";
|
|
110
|
+
break;
|
|
111
|
+
case 117:
|
|
112
|
+
const ch3 = scanHexDigits(4, true);
|
|
113
|
+
if (ch3 >= 0) result += String.fromCharCode(ch3);
|
|
114
|
+
else scanError = 4;
|
|
115
|
+
break;
|
|
116
|
+
default: scanError = 5;
|
|
117
|
+
}
|
|
118
|
+
start = pos;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (ch >= 0 && ch <= 31) if (isLineBreak(ch)) {
|
|
122
|
+
result += text.substring(start, pos);
|
|
123
|
+
scanError = 2;
|
|
124
|
+
break;
|
|
125
|
+
} else scanError = 6;
|
|
126
|
+
pos++;
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function scanNext() {
|
|
131
|
+
value = "";
|
|
132
|
+
scanError = 0;
|
|
133
|
+
tokenOffset = pos;
|
|
134
|
+
lineStartOffset = lineNumber;
|
|
135
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
136
|
+
if (pos >= len) {
|
|
137
|
+
tokenOffset = len;
|
|
138
|
+
return token = 17;
|
|
139
|
+
}
|
|
140
|
+
let code = text.charCodeAt(pos);
|
|
141
|
+
if (isWhiteSpace(code)) {
|
|
142
|
+
do {
|
|
143
|
+
pos++;
|
|
144
|
+
value += String.fromCharCode(code);
|
|
145
|
+
code = text.charCodeAt(pos);
|
|
146
|
+
} while (isWhiteSpace(code));
|
|
147
|
+
return token = 15;
|
|
148
|
+
}
|
|
149
|
+
if (isLineBreak(code)) {
|
|
150
|
+
pos++;
|
|
151
|
+
value += String.fromCharCode(code);
|
|
152
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
153
|
+
pos++;
|
|
154
|
+
value += "\n";
|
|
155
|
+
}
|
|
156
|
+
lineNumber++;
|
|
157
|
+
tokenLineStartOffset = pos;
|
|
158
|
+
return token = 14;
|
|
159
|
+
}
|
|
160
|
+
switch (code) {
|
|
161
|
+
case 123:
|
|
162
|
+
pos++;
|
|
163
|
+
return token = 1;
|
|
164
|
+
case 125:
|
|
165
|
+
pos++;
|
|
166
|
+
return token = 2;
|
|
167
|
+
case 91:
|
|
168
|
+
pos++;
|
|
169
|
+
return token = 3;
|
|
170
|
+
case 93:
|
|
171
|
+
pos++;
|
|
172
|
+
return token = 4;
|
|
173
|
+
case 58:
|
|
174
|
+
pos++;
|
|
175
|
+
return token = 6;
|
|
176
|
+
case 44:
|
|
177
|
+
pos++;
|
|
178
|
+
return token = 5;
|
|
179
|
+
case 34:
|
|
180
|
+
pos++;
|
|
181
|
+
value = scanString();
|
|
182
|
+
return token = 10;
|
|
183
|
+
case 47:
|
|
184
|
+
const start = pos - 1;
|
|
185
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
186
|
+
pos += 2;
|
|
187
|
+
while (pos < len) {
|
|
188
|
+
if (isLineBreak(text.charCodeAt(pos))) break;
|
|
189
|
+
pos++;
|
|
190
|
+
}
|
|
191
|
+
value = text.substring(start, pos);
|
|
192
|
+
return token = 12;
|
|
193
|
+
}
|
|
194
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
195
|
+
pos += 2;
|
|
196
|
+
const safeLength = len - 1;
|
|
197
|
+
let commentClosed = false;
|
|
198
|
+
while (pos < safeLength) {
|
|
199
|
+
const ch = text.charCodeAt(pos);
|
|
200
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
201
|
+
pos += 2;
|
|
202
|
+
commentClosed = true;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
pos++;
|
|
206
|
+
if (isLineBreak(ch)) {
|
|
207
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) pos++;
|
|
208
|
+
lineNumber++;
|
|
209
|
+
tokenLineStartOffset = pos;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!commentClosed) {
|
|
213
|
+
pos++;
|
|
214
|
+
scanError = 1;
|
|
215
|
+
}
|
|
216
|
+
value = text.substring(start, pos);
|
|
217
|
+
return token = 13;
|
|
218
|
+
}
|
|
219
|
+
value += String.fromCharCode(code);
|
|
220
|
+
pos++;
|
|
221
|
+
return token = 16;
|
|
222
|
+
case 45:
|
|
223
|
+
value += String.fromCharCode(code);
|
|
224
|
+
pos++;
|
|
225
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) return token = 16;
|
|
226
|
+
case 48:
|
|
227
|
+
case 49:
|
|
228
|
+
case 50:
|
|
229
|
+
case 51:
|
|
230
|
+
case 52:
|
|
231
|
+
case 53:
|
|
232
|
+
case 54:
|
|
233
|
+
case 55:
|
|
234
|
+
case 56:
|
|
235
|
+
case 57:
|
|
236
|
+
value += scanNumber();
|
|
237
|
+
return token = 11;
|
|
238
|
+
default:
|
|
239
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
240
|
+
pos++;
|
|
241
|
+
code = text.charCodeAt(pos);
|
|
242
|
+
}
|
|
243
|
+
if (tokenOffset !== pos) {
|
|
244
|
+
value = text.substring(tokenOffset, pos);
|
|
245
|
+
switch (value) {
|
|
246
|
+
case "true": return token = 8;
|
|
247
|
+
case "false": return token = 9;
|
|
248
|
+
case "null": return token = 7;
|
|
249
|
+
}
|
|
250
|
+
return token = 16;
|
|
251
|
+
}
|
|
252
|
+
value += String.fromCharCode(code);
|
|
253
|
+
pos++;
|
|
254
|
+
return token = 16;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function isUnknownContentCharacter(code) {
|
|
258
|
+
if (isWhiteSpace(code) || isLineBreak(code)) return false;
|
|
259
|
+
switch (code) {
|
|
260
|
+
case 125:
|
|
261
|
+
case 93:
|
|
262
|
+
case 123:
|
|
263
|
+
case 91:
|
|
264
|
+
case 34:
|
|
265
|
+
case 58:
|
|
266
|
+
case 44:
|
|
267
|
+
case 47: return false;
|
|
268
|
+
}
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
function scanNextNonTrivia() {
|
|
272
|
+
let result;
|
|
273
|
+
do
|
|
274
|
+
result = scanNext();
|
|
275
|
+
while (result >= 12 && result <= 15);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
setPosition,
|
|
280
|
+
getPosition: () => pos,
|
|
281
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
282
|
+
getToken: () => token,
|
|
283
|
+
getTokenValue: () => value,
|
|
284
|
+
getTokenOffset: () => tokenOffset,
|
|
285
|
+
getTokenLength: () => pos - tokenOffset,
|
|
286
|
+
getTokenStartLine: () => lineStartOffset,
|
|
287
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
288
|
+
getTokenError: () => scanError
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function isWhiteSpace(ch) {
|
|
292
|
+
return ch === 32 || ch === 9;
|
|
293
|
+
}
|
|
294
|
+
function isLineBreak(ch) {
|
|
295
|
+
return ch === 10 || ch === 13;
|
|
296
|
+
}
|
|
297
|
+
function isDigit(ch) {
|
|
298
|
+
return ch >= 48 && ch <= 57;
|
|
299
|
+
}
|
|
300
|
+
var CharacterCodes;
|
|
301
|
+
(function(CharacterCodes) {
|
|
302
|
+
CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
|
|
303
|
+
CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
|
|
304
|
+
CharacterCodes[CharacterCodes["space"] = 32] = "space";
|
|
305
|
+
CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
|
|
306
|
+
CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
|
|
307
|
+
CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
|
|
308
|
+
CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
|
|
309
|
+
CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
|
|
310
|
+
CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
|
|
311
|
+
CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
|
|
312
|
+
CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
|
|
313
|
+
CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
|
|
314
|
+
CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
|
|
315
|
+
CharacterCodes[CharacterCodes["a"] = 97] = "a";
|
|
316
|
+
CharacterCodes[CharacterCodes["b"] = 98] = "b";
|
|
317
|
+
CharacterCodes[CharacterCodes["c"] = 99] = "c";
|
|
318
|
+
CharacterCodes[CharacterCodes["d"] = 100] = "d";
|
|
319
|
+
CharacterCodes[CharacterCodes["e"] = 101] = "e";
|
|
320
|
+
CharacterCodes[CharacterCodes["f"] = 102] = "f";
|
|
321
|
+
CharacterCodes[CharacterCodes["g"] = 103] = "g";
|
|
322
|
+
CharacterCodes[CharacterCodes["h"] = 104] = "h";
|
|
323
|
+
CharacterCodes[CharacterCodes["i"] = 105] = "i";
|
|
324
|
+
CharacterCodes[CharacterCodes["j"] = 106] = "j";
|
|
325
|
+
CharacterCodes[CharacterCodes["k"] = 107] = "k";
|
|
326
|
+
CharacterCodes[CharacterCodes["l"] = 108] = "l";
|
|
327
|
+
CharacterCodes[CharacterCodes["m"] = 109] = "m";
|
|
328
|
+
CharacterCodes[CharacterCodes["n"] = 110] = "n";
|
|
329
|
+
CharacterCodes[CharacterCodes["o"] = 111] = "o";
|
|
330
|
+
CharacterCodes[CharacterCodes["p"] = 112] = "p";
|
|
331
|
+
CharacterCodes[CharacterCodes["q"] = 113] = "q";
|
|
332
|
+
CharacterCodes[CharacterCodes["r"] = 114] = "r";
|
|
333
|
+
CharacterCodes[CharacterCodes["s"] = 115] = "s";
|
|
334
|
+
CharacterCodes[CharacterCodes["t"] = 116] = "t";
|
|
335
|
+
CharacterCodes[CharacterCodes["u"] = 117] = "u";
|
|
336
|
+
CharacterCodes[CharacterCodes["v"] = 118] = "v";
|
|
337
|
+
CharacterCodes[CharacterCodes["w"] = 119] = "w";
|
|
338
|
+
CharacterCodes[CharacterCodes["x"] = 120] = "x";
|
|
339
|
+
CharacterCodes[CharacterCodes["y"] = 121] = "y";
|
|
340
|
+
CharacterCodes[CharacterCodes["z"] = 122] = "z";
|
|
341
|
+
CharacterCodes[CharacterCodes["A"] = 65] = "A";
|
|
342
|
+
CharacterCodes[CharacterCodes["B"] = 66] = "B";
|
|
343
|
+
CharacterCodes[CharacterCodes["C"] = 67] = "C";
|
|
344
|
+
CharacterCodes[CharacterCodes["D"] = 68] = "D";
|
|
345
|
+
CharacterCodes[CharacterCodes["E"] = 69] = "E";
|
|
346
|
+
CharacterCodes[CharacterCodes["F"] = 70] = "F";
|
|
347
|
+
CharacterCodes[CharacterCodes["G"] = 71] = "G";
|
|
348
|
+
CharacterCodes[CharacterCodes["H"] = 72] = "H";
|
|
349
|
+
CharacterCodes[CharacterCodes["I"] = 73] = "I";
|
|
350
|
+
CharacterCodes[CharacterCodes["J"] = 74] = "J";
|
|
351
|
+
CharacterCodes[CharacterCodes["K"] = 75] = "K";
|
|
352
|
+
CharacterCodes[CharacterCodes["L"] = 76] = "L";
|
|
353
|
+
CharacterCodes[CharacterCodes["M"] = 77] = "M";
|
|
354
|
+
CharacterCodes[CharacterCodes["N"] = 78] = "N";
|
|
355
|
+
CharacterCodes[CharacterCodes["O"] = 79] = "O";
|
|
356
|
+
CharacterCodes[CharacterCodes["P"] = 80] = "P";
|
|
357
|
+
CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
|
|
358
|
+
CharacterCodes[CharacterCodes["R"] = 82] = "R";
|
|
359
|
+
CharacterCodes[CharacterCodes["S"] = 83] = "S";
|
|
360
|
+
CharacterCodes[CharacterCodes["T"] = 84] = "T";
|
|
361
|
+
CharacterCodes[CharacterCodes["U"] = 85] = "U";
|
|
362
|
+
CharacterCodes[CharacterCodes["V"] = 86] = "V";
|
|
363
|
+
CharacterCodes[CharacterCodes["W"] = 87] = "W";
|
|
364
|
+
CharacterCodes[CharacterCodes["X"] = 88] = "X";
|
|
365
|
+
CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
|
|
366
|
+
CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
|
|
367
|
+
CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
|
|
368
|
+
CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
|
|
369
|
+
CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
|
|
370
|
+
CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
|
|
371
|
+
CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
|
|
372
|
+
CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
|
|
373
|
+
CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
|
|
374
|
+
CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
|
|
375
|
+
CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
|
|
376
|
+
CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
|
|
377
|
+
CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
|
|
378
|
+
CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
|
|
379
|
+
CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
|
|
380
|
+
CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
|
|
381
|
+
CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
|
|
382
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
383
|
+
new Array(20).fill(0).map((_, index) => {
|
|
384
|
+
return " ".repeat(index);
|
|
385
|
+
});
|
|
386
|
+
var maxCachedValues = 200;
|
|
387
|
+
new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
388
|
+
return "\n" + " ".repeat(index);
|
|
389
|
+
}), new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
390
|
+
return "\r" + " ".repeat(index);
|
|
391
|
+
}), new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
392
|
+
return "\r\n" + " ".repeat(index);
|
|
393
|
+
}), new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
394
|
+
return "\n" + " ".repeat(index);
|
|
395
|
+
}), new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
396
|
+
return "\r" + " ".repeat(index);
|
|
397
|
+
}), new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
398
|
+
return "\r\n" + " ".repeat(index);
|
|
399
|
+
});
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
402
|
+
var ParseOptions;
|
|
403
|
+
(function(ParseOptions) {
|
|
404
|
+
ParseOptions.DEFAULT = { allowTrailingComma: false };
|
|
405
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
406
|
+
/**
|
|
407
|
+
* Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
408
|
+
* Therefore always check the errors list to find out if the input was valid.
|
|
409
|
+
*/
|
|
410
|
+
function parse$1(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
411
|
+
let currentProperty = null;
|
|
412
|
+
let currentParent = [];
|
|
413
|
+
const previousParents = [];
|
|
414
|
+
function onValue(value) {
|
|
415
|
+
if (Array.isArray(currentParent)) currentParent.push(value);
|
|
416
|
+
else if (currentProperty !== null) currentParent[currentProperty] = value;
|
|
417
|
+
}
|
|
418
|
+
visit(text, {
|
|
419
|
+
onObjectBegin: () => {
|
|
420
|
+
const object = {};
|
|
421
|
+
onValue(object);
|
|
422
|
+
previousParents.push(currentParent);
|
|
423
|
+
currentParent = object;
|
|
424
|
+
currentProperty = null;
|
|
425
|
+
},
|
|
426
|
+
onObjectProperty: (name) => {
|
|
427
|
+
currentProperty = name;
|
|
428
|
+
},
|
|
429
|
+
onObjectEnd: () => {
|
|
430
|
+
currentParent = previousParents.pop();
|
|
431
|
+
},
|
|
432
|
+
onArrayBegin: () => {
|
|
433
|
+
const array = [];
|
|
434
|
+
onValue(array);
|
|
435
|
+
previousParents.push(currentParent);
|
|
436
|
+
currentParent = array;
|
|
437
|
+
currentProperty = null;
|
|
438
|
+
},
|
|
439
|
+
onArrayEnd: () => {
|
|
440
|
+
currentParent = previousParents.pop();
|
|
441
|
+
},
|
|
442
|
+
onLiteralValue: onValue,
|
|
443
|
+
onError: (error, offset, length) => {
|
|
444
|
+
errors.push({
|
|
445
|
+
error,
|
|
446
|
+
offset,
|
|
447
|
+
length
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}, options);
|
|
451
|
+
return currentParent[0];
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Parses the given text and invokes the visitor functions for each object, array and literal reached.
|
|
455
|
+
*/
|
|
456
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
457
|
+
const _scanner = createScanner(text, false);
|
|
458
|
+
const _jsonPath = [];
|
|
459
|
+
let suppressedCallbacks = 0;
|
|
460
|
+
function toNoArgVisit(visitFunction) {
|
|
461
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
462
|
+
}
|
|
463
|
+
function toOneArgVisit(visitFunction) {
|
|
464
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
465
|
+
}
|
|
466
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
467
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
468
|
+
}
|
|
469
|
+
function toBeginVisit(visitFunction) {
|
|
470
|
+
return visitFunction ? () => {
|
|
471
|
+
if (suppressedCallbacks > 0) suppressedCallbacks++;
|
|
472
|
+
else if (visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) === false) suppressedCallbacks = 1;
|
|
473
|
+
} : () => true;
|
|
474
|
+
}
|
|
475
|
+
function toEndVisit(visitFunction) {
|
|
476
|
+
return visitFunction ? () => {
|
|
477
|
+
if (suppressedCallbacks > 0) suppressedCallbacks--;
|
|
478
|
+
if (suppressedCallbacks === 0) visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
479
|
+
} : () => true;
|
|
480
|
+
}
|
|
481
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
482
|
+
const disallowComments = options && options.disallowComments;
|
|
483
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
484
|
+
function scanNext() {
|
|
485
|
+
while (true) {
|
|
486
|
+
const token = _scanner.scan();
|
|
487
|
+
switch (_scanner.getTokenError()) {
|
|
488
|
+
case 4:
|
|
489
|
+
handleError(14);
|
|
490
|
+
break;
|
|
491
|
+
case 5:
|
|
492
|
+
handleError(15);
|
|
493
|
+
break;
|
|
494
|
+
case 3:
|
|
495
|
+
handleError(13);
|
|
496
|
+
break;
|
|
497
|
+
case 1:
|
|
498
|
+
if (!disallowComments) handleError(11);
|
|
499
|
+
break;
|
|
500
|
+
case 2:
|
|
501
|
+
handleError(12);
|
|
502
|
+
break;
|
|
503
|
+
case 6:
|
|
504
|
+
handleError(16);
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
switch (token) {
|
|
508
|
+
case 12:
|
|
509
|
+
case 13:
|
|
510
|
+
if (disallowComments) handleError(10);
|
|
511
|
+
else onComment();
|
|
512
|
+
break;
|
|
513
|
+
case 16:
|
|
514
|
+
handleError(1);
|
|
515
|
+
break;
|
|
516
|
+
case 15:
|
|
517
|
+
case 14: break;
|
|
518
|
+
default: return token;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
523
|
+
onError(error);
|
|
524
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
525
|
+
let token = _scanner.getToken();
|
|
526
|
+
while (token !== 17) {
|
|
527
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
528
|
+
scanNext();
|
|
529
|
+
break;
|
|
530
|
+
} else if (skipUntil.indexOf(token) !== -1) break;
|
|
531
|
+
token = scanNext();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function parseString(isValue) {
|
|
536
|
+
const value = _scanner.getTokenValue();
|
|
537
|
+
if (isValue) onLiteralValue(value);
|
|
538
|
+
else {
|
|
539
|
+
onObjectProperty(value);
|
|
540
|
+
_jsonPath.push(value);
|
|
541
|
+
}
|
|
542
|
+
scanNext();
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
function parseLiteral() {
|
|
546
|
+
switch (_scanner.getToken()) {
|
|
547
|
+
case 11:
|
|
548
|
+
const tokenValue = _scanner.getTokenValue();
|
|
549
|
+
let value = Number(tokenValue);
|
|
550
|
+
if (isNaN(value)) {
|
|
551
|
+
handleError(2);
|
|
552
|
+
value = 0;
|
|
553
|
+
}
|
|
554
|
+
onLiteralValue(value);
|
|
555
|
+
break;
|
|
556
|
+
case 7:
|
|
557
|
+
onLiteralValue(null);
|
|
558
|
+
break;
|
|
559
|
+
case 8:
|
|
560
|
+
onLiteralValue(true);
|
|
561
|
+
break;
|
|
562
|
+
case 9:
|
|
563
|
+
onLiteralValue(false);
|
|
564
|
+
break;
|
|
565
|
+
default: return false;
|
|
566
|
+
}
|
|
567
|
+
scanNext();
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
function parseProperty() {
|
|
571
|
+
if (_scanner.getToken() !== 10) {
|
|
572
|
+
handleError(3, [], [2, 5]);
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
parseString(false);
|
|
576
|
+
if (_scanner.getToken() === 6) {
|
|
577
|
+
onSeparator(":");
|
|
578
|
+
scanNext();
|
|
579
|
+
if (!parseValue()) handleError(4, [], [2, 5]);
|
|
580
|
+
} else handleError(5, [], [2, 5]);
|
|
581
|
+
_jsonPath.pop();
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
function parseObject() {
|
|
585
|
+
onObjectBegin();
|
|
586
|
+
scanNext();
|
|
587
|
+
let needsComma = false;
|
|
588
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
589
|
+
if (_scanner.getToken() === 5) {
|
|
590
|
+
if (!needsComma) handleError(4, [], []);
|
|
591
|
+
onSeparator(",");
|
|
592
|
+
scanNext();
|
|
593
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) break;
|
|
594
|
+
} else if (needsComma) handleError(6, [], []);
|
|
595
|
+
if (!parseProperty()) handleError(4, [], [2, 5]);
|
|
596
|
+
needsComma = true;
|
|
597
|
+
}
|
|
598
|
+
onObjectEnd();
|
|
599
|
+
if (_scanner.getToken() !== 2) handleError(7, [2], []);
|
|
600
|
+
else scanNext();
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
function parseArray() {
|
|
604
|
+
onArrayBegin();
|
|
605
|
+
scanNext();
|
|
606
|
+
let isFirstElement = true;
|
|
607
|
+
let needsComma = false;
|
|
608
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
609
|
+
if (_scanner.getToken() === 5) {
|
|
610
|
+
if (!needsComma) handleError(4, [], []);
|
|
611
|
+
onSeparator(",");
|
|
612
|
+
scanNext();
|
|
613
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) break;
|
|
614
|
+
} else if (needsComma) handleError(6, [], []);
|
|
615
|
+
if (isFirstElement) {
|
|
616
|
+
_jsonPath.push(0);
|
|
617
|
+
isFirstElement = false;
|
|
618
|
+
} else _jsonPath[_jsonPath.length - 1]++;
|
|
619
|
+
if (!parseValue()) handleError(4, [], [4, 5]);
|
|
620
|
+
needsComma = true;
|
|
621
|
+
}
|
|
622
|
+
onArrayEnd();
|
|
623
|
+
if (!isFirstElement) _jsonPath.pop();
|
|
624
|
+
if (_scanner.getToken() !== 4) handleError(8, [4], []);
|
|
625
|
+
else scanNext();
|
|
626
|
+
return true;
|
|
627
|
+
}
|
|
628
|
+
function parseValue() {
|
|
629
|
+
switch (_scanner.getToken()) {
|
|
630
|
+
case 3: return parseArray();
|
|
631
|
+
case 1: return parseObject();
|
|
632
|
+
case 10: return parseString(true);
|
|
633
|
+
default: return parseLiteral();
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
scanNext();
|
|
637
|
+
if (_scanner.getToken() === 17) {
|
|
638
|
+
if (options.allowEmptyContent) return true;
|
|
639
|
+
handleError(4, [], []);
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
if (!parseValue()) {
|
|
643
|
+
handleError(4, [], []);
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
if (_scanner.getToken() !== 17) handleError(9, [], []);
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
651
|
+
var ScanError;
|
|
652
|
+
(function(ScanError) {
|
|
653
|
+
ScanError[ScanError["None"] = 0] = "None";
|
|
654
|
+
ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
655
|
+
ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
656
|
+
ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
657
|
+
ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
658
|
+
ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
659
|
+
ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
660
|
+
})(ScanError || (ScanError = {}));
|
|
661
|
+
var SyntaxKind;
|
|
662
|
+
(function(SyntaxKind) {
|
|
663
|
+
SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
664
|
+
SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
665
|
+
SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
666
|
+
SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
667
|
+
SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
|
|
668
|
+
SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
|
|
669
|
+
SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
|
|
670
|
+
SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
|
|
671
|
+
SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
|
|
672
|
+
SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
|
|
673
|
+
SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
|
|
674
|
+
SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
675
|
+
SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
676
|
+
SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
677
|
+
SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
|
|
678
|
+
SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
|
|
679
|
+
SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
|
|
680
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
681
|
+
/**
|
|
682
|
+
* Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
683
|
+
* Therefore, always check the errors list to find out if the input was valid.
|
|
684
|
+
*/
|
|
685
|
+
var parse = parse$1;
|
|
686
|
+
var ParseErrorCode;
|
|
687
|
+
(function(ParseErrorCode) {
|
|
688
|
+
ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
689
|
+
ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
690
|
+
ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
691
|
+
ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
|
|
692
|
+
ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
|
|
693
|
+
ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
|
|
694
|
+
ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
695
|
+
ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
696
|
+
ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
697
|
+
ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
698
|
+
ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
699
|
+
ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
700
|
+
ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
701
|
+
ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
702
|
+
ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
703
|
+
ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
704
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/adapters/cloudflare.ts
|
|
707
|
+
var BINDINGS_ALS_KEY = Symbol.for("timber:cf-bindings-als");
|
|
708
|
+
function getBindingsAls() {
|
|
709
|
+
let als = globalThis[BINDINGS_ALS_KEY];
|
|
710
|
+
if (!als) {
|
|
711
|
+
als = new AsyncLocalStorage();
|
|
712
|
+
globalThis[BINDINGS_ALS_KEY] = als;
|
|
713
|
+
}
|
|
714
|
+
return als;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Get Cloudflare Worker bindings for the current request.
|
|
718
|
+
*
|
|
719
|
+
* Returns the `env` object passed to the Worker's `fetch` handler,
|
|
720
|
+
* giving direct access to KV, D1, Durable Objects, R2, Queues, and
|
|
721
|
+
* any other bindings configured in `wrangler.jsonc`.
|
|
722
|
+
*
|
|
723
|
+
* Must be called within a request context (server component, middleware,
|
|
724
|
+
* server action). Throws outside a request.
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* ```ts
|
|
728
|
+
* import { getCloudflareBindings } from '@timber-js/app/adapters/cloudflare'
|
|
729
|
+
*
|
|
730
|
+
* export default async function Page() {
|
|
731
|
+
* const { MY_KV, MY_DB } = getCloudflareBindings()
|
|
732
|
+
* const data = await MY_KV.get('key')
|
|
733
|
+
* return <div>{data}</div>
|
|
734
|
+
* }
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
function getCloudflareBindings() {
|
|
738
|
+
const env = getBindingsAls().getStore();
|
|
739
|
+
if (!env) throw new Error("getCloudflareBindings() called outside a Cloudflare Workers request context. It can only be called from server components, middleware, or server actions when running on the Cloudflare adapter.");
|
|
740
|
+
return env;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Run a function with Cloudflare bindings available via getCloudflareBindings().
|
|
744
|
+
* @internal Used by cloudflareDevBindings() to wrap dev-server requests.
|
|
745
|
+
*/
|
|
746
|
+
function runWithBindings(env, fn) {
|
|
747
|
+
return getBindingsAls().run(env, fn);
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Create a Cloudflare Workers adapter.
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
* ```ts
|
|
754
|
+
* import { cloudflare } from '@timber-js/app/adapters/cloudflare'
|
|
755
|
+
*
|
|
756
|
+
* export default {
|
|
757
|
+
* output: 'server',
|
|
758
|
+
* adapter: cloudflare(),
|
|
759
|
+
* }
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
762
|
+
function cloudflare(options = {}) {
|
|
763
|
+
return {
|
|
764
|
+
name: "cloudflare",
|
|
765
|
+
async buildOutput(config, buildDir) {
|
|
766
|
+
const outDir = join(buildDir, "cloudflare");
|
|
767
|
+
await rm(join(outDir, "prebuilt"), {
|
|
768
|
+
recursive: true,
|
|
769
|
+
force: true
|
|
770
|
+
}).catch(() => {});
|
|
771
|
+
await rm(join(outDir, "static", "prebuilt"), {
|
|
772
|
+
recursive: true,
|
|
773
|
+
force: true
|
|
774
|
+
}).catch(() => {});
|
|
775
|
+
await runSharedBuildSteps({
|
|
776
|
+
config,
|
|
777
|
+
buildDir,
|
|
778
|
+
outDir,
|
|
779
|
+
publicDirName: "static"
|
|
780
|
+
});
|
|
781
|
+
let hasWorkerHandlers = false;
|
|
782
|
+
if (options.workerHandlers) {
|
|
783
|
+
const handlersEntry = join(process.cwd(), options.workerHandlers);
|
|
784
|
+
const { build: viteBuild } = await import("vite");
|
|
785
|
+
await viteBuild({
|
|
786
|
+
configFile: false,
|
|
787
|
+
logLevel: "info",
|
|
788
|
+
build: {
|
|
789
|
+
lib: {
|
|
790
|
+
entry: handlersEntry,
|
|
791
|
+
formats: ["es"],
|
|
792
|
+
fileName: () => "_worker-handlers.js"
|
|
793
|
+
},
|
|
794
|
+
outDir,
|
|
795
|
+
emptyOutDir: false,
|
|
796
|
+
minify: false,
|
|
797
|
+
rollupOptions: { external: [/^node:/, /^cloudflare:/] }
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
hasWorkerHandlers = true;
|
|
801
|
+
}
|
|
802
|
+
const prebuiltData = await readPrebuiltData(buildDir);
|
|
803
|
+
await writeFile(join(outDir, "_timber-prebuilt-source.js"), generatePrebuiltSourceModule(prebuiltData));
|
|
804
|
+
await rm(join(outDir, "prebuilt"), {
|
|
805
|
+
recursive: true,
|
|
806
|
+
force: true
|
|
807
|
+
}).catch(() => {});
|
|
808
|
+
await writeFile(join(outDir, "_timber-runtime-init.js"), generateRuntimeInitModule());
|
|
809
|
+
const workerEntry = generateWorkerEntry(outDir, outDir, !!config.manifestInit, hasWorkerHandlers);
|
|
810
|
+
await writeFile(join(outDir, "_worker.js"), workerEntry);
|
|
811
|
+
const wranglerConfig = generateWranglerConfig(config, options, await readUserWranglerConfig(config.root ?? process.cwd()));
|
|
812
|
+
await writeFile(join(outDir, "wrangler.jsonc"), JSON.stringify(wranglerConfig, null, 2));
|
|
813
|
+
},
|
|
814
|
+
async preview(_config, buildDir) {
|
|
815
|
+
const cmd = generatePreviewCommand(buildDir);
|
|
816
|
+
await spawnPreviewProcess(cmd.command, cmd.args, cmd.cwd);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
/** @internal Exported for testing. */
|
|
821
|
+
function generateWorkerEntry(buildDir, outDir, hasManifestInit = false, hasWorkerHandlers = false) {
|
|
822
|
+
let rscEntryRelative = relative(outDir, join(buildDir, "rsc", "index.js"));
|
|
823
|
+
if (!rscEntryRelative.startsWith(".")) rscEntryRelative = "./" + rscEntryRelative;
|
|
824
|
+
return `// Generated by @timber-js/app/adapters/cloudflare
|
|
825
|
+
// Do not edit — this file is regenerated on each build.
|
|
826
|
+
|
|
827
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
828
|
+
// Side-effect imports: evaluated IN ORDER before the _worker.js body runs.
|
|
829
|
+
// _timber-runtime-init.js sets TIMBER_RUNTIME before createRequestHandler()
|
|
830
|
+
// runs (during the RSC entry's top-level await) so the auto-wire for
|
|
831
|
+
// WorkersCachePurge can detect the Cloudflare runtime (TIM-1170).
|
|
832
|
+
// _timber-prebuilt-source.js sets globalThis.__TIMBER_PREBUILT_SOURCE__
|
|
833
|
+
// for cache.component payloads.
|
|
834
|
+
import './_timber-runtime-init.js'
|
|
835
|
+
import './_timber-prebuilt-source.js'
|
|
836
|
+
${hasManifestInit ? "import './_timber-manifest-init.js'\n" : ""}import handler, { runWithWaitUntil, runWithWorkersCachePurge } from '${rscEntryRelative}'
|
|
837
|
+
${hasWorkerHandlers ? "import * as workerHandlers from './_worker-handlers.js'\n" : ""}
|
|
838
|
+
|
|
839
|
+
// Bind Cloudflare env to ALS so getCloudflareBindings() works at runtime.
|
|
840
|
+
// Uses the same Symbol.for key as getCloudflareBindings() reads from.
|
|
841
|
+
const ALS_KEY = Symbol.for('timber:cf-bindings-als')
|
|
842
|
+
let bindingsAls = globalThis[ALS_KEY]
|
|
843
|
+
if (!bindingsAls) {
|
|
844
|
+
bindingsAls = new AsyncLocalStorage()
|
|
845
|
+
globalThis[ALS_KEY] = bindingsAls
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// Register timber's platform tracer so pipeline phase spans (timber.proxy,
|
|
849
|
+
// timber.middleware, timber.render, timber.access, timber.action, …) appear
|
|
850
|
+
// as native Cloudflare spans in the Observability dashboard, nested under
|
|
851
|
+
// the auto-instrumented fetch/KV/D1 spans. Requires observability.traces
|
|
852
|
+
// enabled in wrangler.jsonc (generated by default).
|
|
853
|
+
//
|
|
854
|
+
// Lazily imported and guarded: runtimes without the custom spans API
|
|
855
|
+
// (older compatibility dates, older local workerd) fall back to OTEL-only
|
|
856
|
+
// emission. withSpan() in the framework composes both channels.
|
|
857
|
+
const TRACER_KEY = Symbol.for('timber:platform-tracer')
|
|
858
|
+
let tracerInit
|
|
859
|
+
function initPlatformTracer() {
|
|
860
|
+
tracerInit ??= import('cloudflare:workers')
|
|
861
|
+
.then(({ tracing }) => {
|
|
862
|
+
if (tracing && typeof tracing.enterSpan === 'function') {
|
|
863
|
+
globalThis[TRACER_KEY] ??= {
|
|
864
|
+
enterSpan: (name, fn) => tracing.enterSpan(name, fn),
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
})
|
|
868
|
+
.catch(() => {})
|
|
869
|
+
return tracerInit
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
export default {
|
|
873
|
+
${hasWorkerHandlers ? " ...workerHandlers,\n" : ""} async fetch(request, env, ctx) {
|
|
874
|
+
// One-time on first request; resolved-promise await thereafter.
|
|
875
|
+
await initPlatformTracer()
|
|
876
|
+
|
|
877
|
+
// Edge-cache GET/HEAD responses via the Cache API. RSC navigation
|
|
878
|
+
// requests (Accept: text/x-component) are excluded — they vary by
|
|
879
|
+
// X-Timber-State-Tree which the cache key doesn't capture.
|
|
880
|
+
const isRsc = request.headers.get('Accept')?.includes('text/x-component')
|
|
881
|
+
const reqCc = request.headers.get('Cache-Control') || ''
|
|
882
|
+
const bypassCache = reqCc.includes('no-cache') || reqCc.includes('max-age=0')
|
|
883
|
+
|| request.headers.has('Pragma')
|
|
884
|
+
const cacheable = !isRsc && !bypassCache
|
|
885
|
+
&& (request.method === 'GET' || request.method === 'HEAD')
|
|
886
|
+
const cache = cacheable && typeof caches !== 'undefined' ? caches.default : null
|
|
887
|
+
if (cache) {
|
|
888
|
+
const cached = await cache.match(request)
|
|
889
|
+
if (cached) return cached
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// Bridge ctx.cache into the per-request ALS so WorkersCachePurge can
|
|
893
|
+
// call ctx.cache.purge({ tags }) during cache.invalidate/revalidateTag.
|
|
894
|
+
// Workers Cache is available on all Cloudflare plans — no API token needed.
|
|
895
|
+
const workersCacheCtx = ctx.cache && typeof ctx.cache.purge === 'function' ? ctx.cache : null
|
|
896
|
+
const runHandler = () =>
|
|
897
|
+
runWithWaitUntil((promise) => ctx.waitUntil(promise), () => handler(request))
|
|
898
|
+
const response = await bindingsAls.run(env, () =>
|
|
899
|
+
workersCacheCtx
|
|
900
|
+
? runWithWorkersCachePurge(workersCacheCtx, runHandler)
|
|
901
|
+
: runHandler()
|
|
902
|
+
)
|
|
903
|
+
|
|
904
|
+
// Cache public responses at the edge. A response is edge-cacheable if
|
|
905
|
+
// it has 'public' or 's-maxage' (a shared-cache TTL directive) and no
|
|
906
|
+
// 'no-store' or 'private'. Cloudflare's cache.put() only accepts GET
|
|
907
|
+
// requests and rejects 206, so only store GET 200s. HEAD requests
|
|
908
|
+
// benefit from cache.match() which handles HEAD→GET matching automatically.
|
|
909
|
+
// See design/25-production-deployments.md §"CDN / Edge Cache".
|
|
910
|
+
if (cache && request.method === 'GET' && response.status === 200) {
|
|
911
|
+
const cc = response.headers.get('Cache-Control')
|
|
912
|
+
const vary = response.headers.get('Vary')
|
|
913
|
+
if (cc && !cc.includes('no-store') && !cc.includes('private')
|
|
914
|
+
&& (cc.includes('public') || cc.includes('s-maxage'))
|
|
915
|
+
&& vary !== '*' && !response.headers.has('Set-Cookie')) {
|
|
916
|
+
ctx.waitUntil(cache.put(request, response.clone()))
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
return response
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
`;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Discover and read prebuilt flight payload files from the build directory.
|
|
927
|
+
* Returns null when no prebuilt artifacts exist (no cache.component usage).
|
|
928
|
+
*
|
|
929
|
+
* @internal Exported for testing.
|
|
930
|
+
*/
|
|
931
|
+
async function readPrebuiltData(buildDir) {
|
|
932
|
+
const prebuiltDir = join(buildDir, "prebuilt");
|
|
933
|
+
let manifestJson;
|
|
934
|
+
try {
|
|
935
|
+
manifestJson = await readFile(join(prebuiltDir, "manifest.json"), "utf-8");
|
|
936
|
+
} catch {
|
|
937
|
+
return null;
|
|
938
|
+
}
|
|
939
|
+
const payloads = [];
|
|
940
|
+
try {
|
|
941
|
+
const componentDirs = await readdir(prebuiltDir, { withFileTypes: true });
|
|
942
|
+
for (const dir of componentDirs) {
|
|
943
|
+
if (!dir.isDirectory()) continue;
|
|
944
|
+
const files = await readdir(join(prebuiltDir, dir.name));
|
|
945
|
+
for (const file of files) if (file.endsWith(".flight")) {
|
|
946
|
+
const filePath = `${dir.name}/${file}`;
|
|
947
|
+
const bytes = await readFile(join(prebuiltDir, filePath));
|
|
948
|
+
payloads.push({
|
|
949
|
+
file: filePath,
|
|
950
|
+
bytes
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
} catch {}
|
|
955
|
+
return {
|
|
956
|
+
manifestJson,
|
|
957
|
+
payloads
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Generate the prebuilt payload source module for Cloudflare Workers.
|
|
962
|
+
*
|
|
963
|
+
* Inlines manifest JSON and flight payload bytes directly into the module
|
|
964
|
+
* so they're part of the worker's JS bundle — no external Text/Data module
|
|
965
|
+
* imports needed. This avoids depending on wrangler's find_additional_modules
|
|
966
|
+
* to discover non-JS files, which doesn't reliably resolve Text/Data imports.
|
|
967
|
+
*
|
|
968
|
+
* @internal Exported for testing.
|
|
969
|
+
*/
|
|
970
|
+
function generatePrebuiltSourceModule(data) {
|
|
971
|
+
if (!data) return `// Generated by @timber-js/app/adapters/cloudflare
|
|
972
|
+
// No prebuilt artifacts — all cache.component wrappers render dynamically.
|
|
973
|
+
globalThis.__TIMBER_PREBUILT_SOURCE__ = {
|
|
974
|
+
async loadManifest() { return null },
|
|
975
|
+
async readPayload() { return null },
|
|
976
|
+
}
|
|
977
|
+
`;
|
|
978
|
+
const entries = [];
|
|
979
|
+
for (const { file, bytes } of data.payloads) {
|
|
980
|
+
const b64 = bytes.toString("base64");
|
|
981
|
+
entries.push(` ${JSON.stringify(file)}: ${JSON.stringify(b64)}`);
|
|
982
|
+
}
|
|
983
|
+
return `// Generated by @timber-js/app/adapters/cloudflare
|
|
984
|
+
// Prebuilt payload source — inlines cache.component flight payloads
|
|
985
|
+
// directly into the worker bundle (TIM-1162).
|
|
986
|
+
const _manifest = ${data.manifestJson.trim()}
|
|
987
|
+
|
|
988
|
+
function _decode(b64) {
|
|
989
|
+
const bin = atob(b64)
|
|
990
|
+
const buf = new Uint8Array(bin.length)
|
|
991
|
+
for (let i = 0; i < bin.length; i++) buf[i] = bin.charCodeAt(i)
|
|
992
|
+
return buf
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
const _payloads = {
|
|
996
|
+
${entries.join(",\n")}
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
globalThis.__TIMBER_PREBUILT_SOURCE__ = {
|
|
1000
|
+
async loadManifest() { return _manifest },
|
|
1001
|
+
async readPayload(file) {
|
|
1002
|
+
const b64 = _payloads[file]
|
|
1003
|
+
return b64 ? _decode(b64) : null
|
|
1004
|
+
},
|
|
1005
|
+
}
|
|
1006
|
+
`;
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Generate the runtime init module that sets TIMBER_RUNTIME before the
|
|
1010
|
+
* RSC entry evaluates. Imported as a side-effect module in _worker.js.
|
|
1011
|
+
*
|
|
1012
|
+
* @internal Exported for testing.
|
|
1013
|
+
*/
|
|
1014
|
+
function generateRuntimeInitModule() {
|
|
1015
|
+
return `// Generated by @timber-js/app/adapters/cloudflare
|
|
1016
|
+
// Sets TIMBER_RUNTIME before the RSC handler evaluates (TIM-1170).
|
|
1017
|
+
// Must be a separate module imported before rsc/index.js so that ESM
|
|
1018
|
+
// evaluation order guarantees the env var is set when
|
|
1019
|
+
// createRequestHandler() runs its auto-wire logic.
|
|
1020
|
+
globalThis.process ??= { env: {} }
|
|
1021
|
+
process.env.TIMBER_RUNTIME = 'cloudflare'
|
|
1022
|
+
`;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Convert declarative `CloudflareBindings` into wrangler.jsonc binding sections.
|
|
1026
|
+
*
|
|
1027
|
+
* Maps:
|
|
1028
|
+
* - `kv` → `kv_namespaces`
|
|
1029
|
+
* - `d1` → `d1_databases`
|
|
1030
|
+
* - `r2` → `r2_buckets`
|
|
1031
|
+
* - `queues` → `queues` (producers + consumers)
|
|
1032
|
+
* - `durableObjects` → `durable_objects`
|
|
1033
|
+
*
|
|
1034
|
+
* Empty arrays are omitted from the output.
|
|
1035
|
+
*
|
|
1036
|
+
* @internal Exported for testing.
|
|
1037
|
+
*/
|
|
1038
|
+
function generateBindingsConfig(bindings) {
|
|
1039
|
+
if (!bindings) return {};
|
|
1040
|
+
const result = {};
|
|
1041
|
+
if (bindings.kv && bindings.kv.length > 0) result.kv_namespaces = bindings.kv.map((kv) => ({
|
|
1042
|
+
binding: kv.name,
|
|
1043
|
+
id: kv.id ?? ""
|
|
1044
|
+
}));
|
|
1045
|
+
if (bindings.d1 && bindings.d1.length > 0) result.d1_databases = bindings.d1.map((d1) => ({
|
|
1046
|
+
binding: d1.name,
|
|
1047
|
+
database_id: d1.database_id
|
|
1048
|
+
}));
|
|
1049
|
+
if (bindings.r2 && bindings.r2.length > 0) result.r2_buckets = bindings.r2.map((r2) => ({
|
|
1050
|
+
binding: r2.name,
|
|
1051
|
+
bucket_name: r2.bucket_name
|
|
1052
|
+
}));
|
|
1053
|
+
if (bindings.queues) {
|
|
1054
|
+
const queues = {};
|
|
1055
|
+
if (bindings.queues.producers && bindings.queues.producers.length > 0) queues.producers = bindings.queues.producers.map((p) => ({
|
|
1056
|
+
binding: p.name,
|
|
1057
|
+
queue: p.queue
|
|
1058
|
+
}));
|
|
1059
|
+
if (bindings.queues.consumers && bindings.queues.consumers.length > 0) queues.consumers = bindings.queues.consumers.map((c) => {
|
|
1060
|
+
const consumer = { queue: c.queue };
|
|
1061
|
+
if (c.max_batch_size !== void 0) consumer.max_batch_size = c.max_batch_size;
|
|
1062
|
+
if (c.max_retries !== void 0) consumer.max_retries = c.max_retries;
|
|
1063
|
+
if (c.dead_letter_queue !== void 0) consumer.dead_letter_queue = c.dead_letter_queue;
|
|
1064
|
+
return consumer;
|
|
1065
|
+
});
|
|
1066
|
+
if (Object.keys(queues).length > 0) result.queues = queues;
|
|
1067
|
+
}
|
|
1068
|
+
if (bindings.durableObjects && bindings.durableObjects.length > 0) result.durable_objects = { bindings: bindings.durableObjects.map((dobj) => {
|
|
1069
|
+
const entry = {
|
|
1070
|
+
name: dobj.name,
|
|
1071
|
+
class_name: dobj.class_name
|
|
1072
|
+
};
|
|
1073
|
+
if (dobj.script_name) entry.script_name = dobj.script_name;
|
|
1074
|
+
return entry;
|
|
1075
|
+
}) };
|
|
1076
|
+
return result;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* One-level deep merge: for each key in `override`, if both the base and
|
|
1080
|
+
* override values are plain objects (not arrays, not null), merge their
|
|
1081
|
+
* keys with override winning on conflicts. Everything else (primitives,
|
|
1082
|
+
* arrays, null) is replaced outright — matching the intuitive behavior
|
|
1083
|
+
* where `kv_namespaces: [...]` replaces fully but
|
|
1084
|
+
* `durable_objects: { migrations }` merges with generated `bindings`.
|
|
1085
|
+
*/
|
|
1086
|
+
function shallowDeepMerge(base, override) {
|
|
1087
|
+
const result = { ...base };
|
|
1088
|
+
for (const key of Object.keys(override)) {
|
|
1089
|
+
const baseVal = result[key];
|
|
1090
|
+
const overVal = override[key];
|
|
1091
|
+
if (isPlainObject(baseVal) && isPlainObject(overVal)) result[key] = {
|
|
1092
|
+
...baseVal,
|
|
1093
|
+
...overVal
|
|
1094
|
+
};
|
|
1095
|
+
else result[key] = overVal;
|
|
1096
|
+
}
|
|
1097
|
+
return result;
|
|
1098
|
+
}
|
|
1099
|
+
/** True for `{}` literals — false for arrays, null, Date, etc. */
|
|
1100
|
+
function isPlainObject(val) {
|
|
1101
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
1102
|
+
}
|
|
1103
|
+
var WRANGLER_CONFIG_FILES = ["wrangler.jsonc", "wrangler.json"];
|
|
1104
|
+
/**
|
|
1105
|
+
* Read the user's wrangler config from the project root, if one exists.
|
|
1106
|
+
* Checks wrangler.jsonc first, then wrangler.json.
|
|
1107
|
+
* @internal Exported for testing.
|
|
1108
|
+
*/
|
|
1109
|
+
async function readUserWranglerConfig(root) {
|
|
1110
|
+
for (const filename of WRANGLER_CONFIG_FILES) {
|
|
1111
|
+
const filepath = join(root, filename);
|
|
1112
|
+
try {
|
|
1113
|
+
await access(filepath);
|
|
1114
|
+
} catch {
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
return parse(await readFile(filepath, "utf-8"));
|
|
1118
|
+
}
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
/** @internal Exported for testing. */
|
|
1122
|
+
function generateWranglerConfig(config, options, userConfig) {
|
|
1123
|
+
const base = {
|
|
1124
|
+
name: "timber-app",
|
|
1125
|
+
main: "_worker.js",
|
|
1126
|
+
compatibility_date: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
1127
|
+
compatibility_flags: ["nodejs_compat"],
|
|
1128
|
+
no_bundle: true,
|
|
1129
|
+
find_additional_modules: true,
|
|
1130
|
+
rules: [{
|
|
1131
|
+
type: "ESModule",
|
|
1132
|
+
globs: ["**/*.js"]
|
|
1133
|
+
}],
|
|
1134
|
+
assets: {
|
|
1135
|
+
directory: "./static",
|
|
1136
|
+
binding: "ASSETS"
|
|
1137
|
+
},
|
|
1138
|
+
observability: { traces: { enabled: true } }
|
|
1139
|
+
};
|
|
1140
|
+
let merged = userConfig ? shallowDeepMerge(base, userConfig) : base;
|
|
1141
|
+
const explicit = {};
|
|
1142
|
+
if (options.name != null) explicit.name = options.name;
|
|
1143
|
+
if (options.compatibilityDate != null) explicit.compatibility_date = options.compatibilityDate;
|
|
1144
|
+
if (options.compatibilityFlags != null) explicit.compatibility_flags = options.compatibilityFlags;
|
|
1145
|
+
if (Object.keys(explicit).length > 0) merged = {
|
|
1146
|
+
...merged,
|
|
1147
|
+
...explicit
|
|
1148
|
+
};
|
|
1149
|
+
const bindingsConfig = generateBindingsConfig(options.bindings);
|
|
1150
|
+
merged = shallowDeepMerge(merged, bindingsConfig);
|
|
1151
|
+
if (options.wrangler) merged = shallowDeepMerge(merged, options.wrangler);
|
|
1152
|
+
delete merged.env;
|
|
1153
|
+
merged.main = "_worker.js";
|
|
1154
|
+
merged.find_additional_modules = true;
|
|
1155
|
+
return merged;
|
|
1156
|
+
}
|
|
1157
|
+
/** @internal Exported for testing. */
|
|
1158
|
+
function generatePreviewCommand(buildDir) {
|
|
1159
|
+
const cfDir = join(buildDir, "cloudflare");
|
|
1160
|
+
return {
|
|
1161
|
+
command: "wrangler",
|
|
1162
|
+
args: [
|
|
1163
|
+
"dev",
|
|
1164
|
+
"--local",
|
|
1165
|
+
"--config",
|
|
1166
|
+
join(cfDir, "wrangler.jsonc")
|
|
1167
|
+
],
|
|
1168
|
+
cwd: cfDir
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Spawn a long-running preview process and pipe stdio to the parent.
|
|
1173
|
+
* Resolves when the process exits.
|
|
1174
|
+
*/
|
|
1175
|
+
function spawnPreviewProcess(command, args, cwd) {
|
|
1176
|
+
return new Promise((resolve, reject) => {
|
|
1177
|
+
const child = execFile(command, args, { cwd }, (err) => {
|
|
1178
|
+
if (err) reject(err);
|
|
1179
|
+
else resolve();
|
|
1180
|
+
});
|
|
1181
|
+
child.stdout?.pipe(process.stdout);
|
|
1182
|
+
child.stderr?.pipe(process.stderr);
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
//#endregion
|
|
1186
|
+
export { generateRuntimeInitModule as a, getCloudflareBindings as c, runWithBindings as d, generatePreviewCommand as i, readPrebuiltData as l, generateBindingsConfig as n, generateWorkerEntry as o, generatePrebuiltSourceModule as r, generateWranglerConfig as s, cloudflare as t, readUserWranglerConfig as u };
|
|
1187
|
+
|
|
1188
|
+
//# sourceMappingURL=cloudflare-AHoWYTYr.js.map
|