@suss/packs 0.11.0
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/LICENSE +205 -0
- package/README.md +29 -0
- package/dist/activerecord.d.ts +30 -0
- package/dist/activerecord.js +45 -0
- package/dist/apollo-client.d.ts +1 -0
- package/dist/apollo-client.js +137 -0
- package/dist/apollo.d.ts +1 -0
- package/dist/apollo.js +90 -0
- package/dist/aws-dynamodb.d.ts +1 -0
- package/dist/aws-dynamodb.js +386 -0
- package/dist/aws-eventbridge.d.ts +1 -0
- package/dist/aws-eventbridge.js +240 -0
- package/dist/aws-lambda.d.ts +1 -0
- package/dist/aws-lambda.js +382 -0
- package/dist/aws-s3.d.ts +1 -0
- package/dist/aws-s3.js +120 -0
- package/dist/aws-sqs.d.ts +1 -0
- package/dist/aws-sqs.js +296 -0
- package/dist/axios.d.ts +1 -0
- package/dist/axios.js +107 -0
- package/dist/cloudflare-workers.d.ts +1 -0
- package/dist/cloudflare-workers.js +562 -0
- package/dist/drizzle.d.ts +1 -0
- package/dist/drizzle.js +383 -0
- package/dist/express.d.ts +1 -0
- package/dist/express.js +124 -0
- package/dist/fastapi.d.ts +1 -0
- package/dist/fastapi.js +42 -0
- package/dist/fastify.d.ts +1 -0
- package/dist/fastify.js +116 -0
- package/dist/fetch.d.ts +1 -0
- package/dist/fetch.js +64 -0
- package/dist/flask-restx.d.ts +1 -0
- package/dist/flask-restx.js +59 -0
- package/dist/gcs.d.ts +1 -0
- package/dist/gcs.js +134 -0
- package/dist/graphql-ruby.d.ts +1 -0
- package/dist/graphql-ruby.js +84 -0
- package/dist/hono.d.ts +1 -0
- package/dist/hono.js +184 -0
- package/dist/mongoose.d.ts +1 -0
- package/dist/mongoose.js +379 -0
- package/dist/nestjs-graphql.d.ts +1 -0
- package/dist/nestjs-graphql.js +77 -0
- package/dist/nestjs-rest.d.ts +1 -0
- package/dist/nestjs-rest.js +89 -0
- package/dist/nextjs.d.ts +1 -0
- package/dist/nextjs.js +154 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +667 -0
- package/dist/prisma.d.ts +1 -0
- package/dist/prisma.js +448 -0
- package/dist/react-router.d.ts +1 -0
- package/dist/react-router.js +197 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +221 -0
- package/dist/redis.d.ts +1 -0
- package/dist/redis.js +93 -0
- package/dist/sqlalchemy.d.ts +1 -0
- package/dist/sqlalchemy.js +48 -0
- package/dist/ts-rest.d.ts +1 -0
- package/dist/ts-rest.js +89 -0
- package/package.json +208 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
// ../framework/cloudflare-workers/dist/index.js
|
|
2
|
+
import { Node as N } from "ts-morph";
|
|
3
|
+
import { Node as N2 } from "ts-morph";
|
|
4
|
+
import { runtimeConfigBinding } from "@suss/behavioral-ir";
|
|
5
|
+
import { Node as N3 } from "ts-morph";
|
|
6
|
+
import { readName as readName2 } from "@suss/adapter-typescript";
|
|
7
|
+
import { storageBinding } from "@suss/behavioral-ir";
|
|
8
|
+
import { readSqlAccess } from "@suss/sql";
|
|
9
|
+
var TRIGGERS = {
|
|
10
|
+
fetch: {
|
|
11
|
+
kind: "handler",
|
|
12
|
+
// A Worker serves whatever method reaches it, and the route it is
|
|
13
|
+
// bound to is declared outside the code, so the path is null.
|
|
14
|
+
routeInfo: { method: "*", path: null }
|
|
15
|
+
},
|
|
16
|
+
scheduled: {
|
|
17
|
+
kind: "worker",
|
|
18
|
+
channelInfo: { messageBus: "cloudflare-cron", channel: null }
|
|
19
|
+
},
|
|
20
|
+
queue: {
|
|
21
|
+
kind: "consumer",
|
|
22
|
+
channelInfo: { messageBus: "cloudflare-queues", channel: null }
|
|
23
|
+
},
|
|
24
|
+
tail: {
|
|
25
|
+
kind: "consumer",
|
|
26
|
+
channelInfo: { messageBus: "cloudflare-tail", channel: null }
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var METADATA_NAMESPACE = "cloudflareWorkers";
|
|
30
|
+
function cloudflareWorkersDiscovery(options = {}) {
|
|
31
|
+
return (sourceFile) => {
|
|
32
|
+
const sf = sourceFile;
|
|
33
|
+
const triggers = [...defaultExportTriggers(sf), ...listenerTriggers(sf)];
|
|
34
|
+
const units = [];
|
|
35
|
+
const taken = /* @__PURE__ */ new Set();
|
|
36
|
+
for (const trigger of triggers) {
|
|
37
|
+
if (taken.has(trigger.name)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
taken.add(trigger.name);
|
|
41
|
+
units.push(unitFor(trigger, options.scriptName));
|
|
42
|
+
}
|
|
43
|
+
return units;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function unitFor(trigger, scriptName) {
|
|
47
|
+
const shape = TRIGGERS[trigger.name];
|
|
48
|
+
return {
|
|
49
|
+
func: trigger.func,
|
|
50
|
+
kind: shape.kind,
|
|
51
|
+
name: trigger.name,
|
|
52
|
+
...shape.routeInfo !== void 0 ? { routeInfo: shape.routeInfo } : {},
|
|
53
|
+
...shape.channelInfo !== void 0 ? { channelInfo: shape.channelInfo } : {},
|
|
54
|
+
...scriptName !== void 0 ? {
|
|
55
|
+
deployableUnit: {
|
|
56
|
+
deploymentTarget: "worker",
|
|
57
|
+
instanceName: scriptName
|
|
58
|
+
}
|
|
59
|
+
} : {},
|
|
60
|
+
metadata: {
|
|
61
|
+
[METADATA_NAMESPACE]: {
|
|
62
|
+
trigger: trigger.name,
|
|
63
|
+
registration: trigger.registration
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function defaultExportTriggers(sf) {
|
|
69
|
+
const literal = defaultExportObject(sf);
|
|
70
|
+
if (literal === null) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const triggers = [];
|
|
74
|
+
for (const property of literal.getProperties()) {
|
|
75
|
+
const found = triggerOfProperty(property, sf);
|
|
76
|
+
if (found !== null) {
|
|
77
|
+
triggers.push(found);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return triggers;
|
|
81
|
+
}
|
|
82
|
+
function triggerOfProperty(property, sf) {
|
|
83
|
+
const named = propertyName(property);
|
|
84
|
+
if (named === null || TRIGGERS[named] === void 0) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const func = functionOfProperty(property, sf);
|
|
88
|
+
return func === null ? null : { name: named, func, registration: "default-export" };
|
|
89
|
+
}
|
|
90
|
+
function propertyName(property) {
|
|
91
|
+
if (N.isMethodDeclaration(property) || N.isPropertyAssignment(property)) {
|
|
92
|
+
const name = property.getNameNode();
|
|
93
|
+
if (N.isIdentifier(name)) {
|
|
94
|
+
return name.getText();
|
|
95
|
+
}
|
|
96
|
+
return N.isStringLiteral(name) ? name.getLiteralValue() : null;
|
|
97
|
+
}
|
|
98
|
+
return N.isShorthandPropertyAssignment(property) ? property.getName() : null;
|
|
99
|
+
}
|
|
100
|
+
function functionOfProperty(property, sf) {
|
|
101
|
+
if (N.isMethodDeclaration(property)) {
|
|
102
|
+
return property;
|
|
103
|
+
}
|
|
104
|
+
if (N.isPropertyAssignment(property)) {
|
|
105
|
+
const written = property.getInitializer();
|
|
106
|
+
return written === void 0 ? null : functionBehind(written, sf);
|
|
107
|
+
}
|
|
108
|
+
if (N.isShorthandPropertyAssignment(property)) {
|
|
109
|
+
return functionBehind(property.getNameNode(), sf);
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
function functionBehind(expression, sf) {
|
|
114
|
+
if (N.isArrowFunction(expression) || N.isFunctionExpression(expression)) {
|
|
115
|
+
return expression;
|
|
116
|
+
}
|
|
117
|
+
if (!N.isIdentifier(expression)) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
for (const definition of expression.getDefinitionNodes()) {
|
|
121
|
+
const declared = declaredFunction(definition);
|
|
122
|
+
if (declared !== null) {
|
|
123
|
+
return declared;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return localFunction(sf, expression.getText());
|
|
127
|
+
}
|
|
128
|
+
function declaredFunction(definition) {
|
|
129
|
+
if (N.isFunctionDeclaration(definition)) {
|
|
130
|
+
return definition;
|
|
131
|
+
}
|
|
132
|
+
if (!N.isVariableDeclaration(definition)) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const written = definition.getInitializer();
|
|
136
|
+
if (written === void 0) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return N.isArrowFunction(written) || N.isFunctionExpression(written) ? written : null;
|
|
140
|
+
}
|
|
141
|
+
function localFunction(sf, name) {
|
|
142
|
+
const declaration = sf.getFunction(name);
|
|
143
|
+
if (declaration !== void 0) {
|
|
144
|
+
return declaration;
|
|
145
|
+
}
|
|
146
|
+
const variable = sf.getVariableDeclaration(name);
|
|
147
|
+
return variable === void 0 ? null : declaredFunction(variable);
|
|
148
|
+
}
|
|
149
|
+
function defaultExportObject(sf) {
|
|
150
|
+
const assignment = sf.getExportAssignment((a) => !a.isExportEquals());
|
|
151
|
+
if (assignment === void 0) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
return objectBehind(unwrap(assignment.getExpression()), sf);
|
|
155
|
+
}
|
|
156
|
+
function unwrap(expression) {
|
|
157
|
+
let inner = expression;
|
|
158
|
+
while (N.isSatisfiesExpression(inner) || N.isAsExpression(inner) || N.isParenthesizedExpression(inner)) {
|
|
159
|
+
inner = inner.getExpression();
|
|
160
|
+
}
|
|
161
|
+
return inner;
|
|
162
|
+
}
|
|
163
|
+
function objectBehind(expression, sf) {
|
|
164
|
+
if (N.isObjectLiteralExpression(expression)) {
|
|
165
|
+
return expression;
|
|
166
|
+
}
|
|
167
|
+
if (!N.isIdentifier(expression)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
const declaration = sf.getVariableDeclaration(expression.getText());
|
|
171
|
+
const written = declaration?.getInitializer();
|
|
172
|
+
if (written === void 0) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const inner = unwrap(written);
|
|
176
|
+
return N.isObjectLiteralExpression(inner) ? inner : null;
|
|
177
|
+
}
|
|
178
|
+
function listenerTriggers(sf) {
|
|
179
|
+
const triggers = [];
|
|
180
|
+
sf.forEachDescendant((node) => {
|
|
181
|
+
const registered = listenerAt(node);
|
|
182
|
+
if (registered === null) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const func = functionBehind(registered.handler, sf);
|
|
186
|
+
if (func !== null) {
|
|
187
|
+
triggers.push({
|
|
188
|
+
name: registered.event,
|
|
189
|
+
func,
|
|
190
|
+
registration: "addEventListener"
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return triggers;
|
|
195
|
+
}
|
|
196
|
+
function listenerAt(node) {
|
|
197
|
+
if (!N.isCallExpression(node)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const callee = node.getExpression();
|
|
201
|
+
if (!N.isIdentifier(callee) || callee.getText() !== "addEventListener") {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const [event, handler] = node.getArguments();
|
|
205
|
+
if (event === void 0 || handler === void 0) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
if (!N.isStringLiteral(event) || TRIGGERS[event.getLiteralValue()] === void 0) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return { event: event.getLiteralValue(), handler };
|
|
212
|
+
}
|
|
213
|
+
var ENV_PARAMETER_POSITION = 1;
|
|
214
|
+
var readName = (name) => `env.${name}`;
|
|
215
|
+
function envBindingRecognizer(options = {}) {
|
|
216
|
+
const instanceName = options.scriptName ?? "<unknown>";
|
|
217
|
+
return (access) => {
|
|
218
|
+
const read = envReadAt(access);
|
|
219
|
+
return read === null ? null : [configReadEffect(read, instanceName)];
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function envReadAt(node) {
|
|
223
|
+
if (!N2.isPropertyAccessExpression(node)) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const subject = node.getExpression();
|
|
227
|
+
if (!N2.isIdentifier(subject) || !isTriggerEnvArgument(subject)) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const name = node.getName();
|
|
231
|
+
return name.length === 0 ? null : { name, defaulted: isDefaultedAt(node) };
|
|
232
|
+
}
|
|
233
|
+
function isTriggerEnvArgument(subject) {
|
|
234
|
+
for (const definition of subject.getSymbol()?.getDeclarations() ?? []) {
|
|
235
|
+
if (N2.isParameterDeclaration(definition) && isTriggerEnvParameter(definition)) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
function isTriggerEnvParameter(parameter) {
|
|
242
|
+
const owner = parameter.getParent();
|
|
243
|
+
const parameters = owner.getParameters?.() ?? [];
|
|
244
|
+
if (parameters[ENV_PARAMETER_POSITION] !== parameter) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return isTriggerBody(owner);
|
|
248
|
+
}
|
|
249
|
+
function isTriggerBody(owner) {
|
|
250
|
+
const named = triggerNameOf(owner);
|
|
251
|
+
if (named !== null) {
|
|
252
|
+
return TRIGGERS[named] !== void 0;
|
|
253
|
+
}
|
|
254
|
+
return referredToByEntrypoint(owner);
|
|
255
|
+
}
|
|
256
|
+
function triggerNameOf(owner) {
|
|
257
|
+
if (N2.isMethodDeclaration(owner)) {
|
|
258
|
+
const name = owner.getNameNode();
|
|
259
|
+
return N2.isIdentifier(name) ? name.getText() : null;
|
|
260
|
+
}
|
|
261
|
+
const parent = owner.getParent();
|
|
262
|
+
if (parent !== void 0 && N2.isPropertyAssignment(parent)) {
|
|
263
|
+
const name = parent.getNameNode();
|
|
264
|
+
return N2.isIdentifier(name) ? name.getText() : null;
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
function referredToByEntrypoint(owner) {
|
|
269
|
+
const name = declaredName(owner);
|
|
270
|
+
if (name === null) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
const assignment = owner.getSourceFile().getExportAssignment((a) => !a.isExportEquals());
|
|
274
|
+
if (assignment === void 0) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return triggerReferences(assignment.getExpression()).has(name);
|
|
278
|
+
}
|
|
279
|
+
function declaredName(owner) {
|
|
280
|
+
if (N2.isFunctionDeclaration(owner)) {
|
|
281
|
+
return owner.getName() ?? null;
|
|
282
|
+
}
|
|
283
|
+
const parent = owner.getParent();
|
|
284
|
+
return parent !== void 0 && N2.isVariableDeclaration(parent) ? parent.getName() : null;
|
|
285
|
+
}
|
|
286
|
+
function triggerReferences(expression) {
|
|
287
|
+
const names = /* @__PURE__ */ new Set();
|
|
288
|
+
if (!N2.isObjectLiteralExpression(expression)) {
|
|
289
|
+
return names;
|
|
290
|
+
}
|
|
291
|
+
for (const property of expression.getProperties()) {
|
|
292
|
+
if (!N2.isPropertyAssignment(property)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const key = property.getNameNode();
|
|
296
|
+
if (!N2.isIdentifier(key) || TRIGGERS[key.getText()] === void 0) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const written = property.getInitializer();
|
|
300
|
+
if (written !== void 0 && N2.isIdentifier(written)) {
|
|
301
|
+
names.add(written.getText());
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return names;
|
|
305
|
+
}
|
|
306
|
+
function isDefaultedAt(node) {
|
|
307
|
+
let child = node;
|
|
308
|
+
let parent = child.getParent();
|
|
309
|
+
while (parent !== void 0) {
|
|
310
|
+
if (N2.isParenthesizedExpression(parent)) {
|
|
311
|
+
child = parent;
|
|
312
|
+
parent = parent.getParent();
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (!N2.isBinaryExpression(parent)) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
const operator = parent.getOperatorToken().getText();
|
|
319
|
+
if (operator !== "??" && operator !== "||") {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
if (parent.getLeft() === child) {
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
child = parent;
|
|
326
|
+
parent = parent.getParent();
|
|
327
|
+
}
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
function configReadEffect(read, instanceName) {
|
|
331
|
+
return {
|
|
332
|
+
type: "interaction",
|
|
333
|
+
binding: runtimeConfigBinding({
|
|
334
|
+
recognition: "@suss/framework-cloudflare-workers",
|
|
335
|
+
deploymentTarget: "worker",
|
|
336
|
+
instanceName
|
|
337
|
+
}),
|
|
338
|
+
callee: readName(read.name),
|
|
339
|
+
interaction: {
|
|
340
|
+
class: "config-read",
|
|
341
|
+
name: read.name,
|
|
342
|
+
defaulted: read.defaulted
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
var RECOGNITION = "@suss/framework-cloudflare-workers";
|
|
347
|
+
var OBJECT_OPERATIONS = {
|
|
348
|
+
get: "read",
|
|
349
|
+
getWithMetadata: "read",
|
|
350
|
+
head: "read",
|
|
351
|
+
list: "read",
|
|
352
|
+
put: "write",
|
|
353
|
+
delete: "write"
|
|
354
|
+
};
|
|
355
|
+
var KEYED_OPERATIONS = /* @__PURE__ */ new Set([
|
|
356
|
+
"get",
|
|
357
|
+
"getWithMetadata",
|
|
358
|
+
"head",
|
|
359
|
+
"put",
|
|
360
|
+
"delete"
|
|
361
|
+
]);
|
|
362
|
+
var objectStoreAccess = (method, call, resolve) => {
|
|
363
|
+
const kind = OBJECT_OPERATIONS[method];
|
|
364
|
+
if (kind === void 0) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const argument = call.getArguments()[0];
|
|
368
|
+
const selector = argument !== void 0 && KEYED_OPERATIONS.has(method) ? readName2(argument, { resolve, unsettled: "reference" }) : null;
|
|
369
|
+
return { kind, ...selector !== null ? { selector } : {} };
|
|
370
|
+
};
|
|
371
|
+
var D1_STATEMENT_METHODS = /* @__PURE__ */ new Set(["prepare", "exec"]);
|
|
372
|
+
var d1Access = (method, call, resolve) => {
|
|
373
|
+
if (!D1_STATEMENT_METHODS.has(method)) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
const sql = literalText(call.getArguments()[0], resolve);
|
|
377
|
+
if (sql === null) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
const accesses = readSqlAccess(sql, { dialect: "sqlite" });
|
|
381
|
+
if (accesses.length === 0) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
const kind = accesses.some((access) => access.kind === "write") ? "write" : "read";
|
|
385
|
+
return { kind };
|
|
386
|
+
};
|
|
387
|
+
var STORES = {
|
|
388
|
+
KVNamespace: { storageSystem: "cloudflare-kv", read: objectStoreAccess },
|
|
389
|
+
R2Bucket: { storageSystem: "r2", read: objectStoreAccess },
|
|
390
|
+
D1Database: { storageSystem: "d1", read: d1Access }
|
|
391
|
+
};
|
|
392
|
+
function storeBindingRecognizer(call, ctx) {
|
|
393
|
+
const callNode = call;
|
|
394
|
+
const resolve = ctx.resolveWrittenValue ?? (() => null);
|
|
395
|
+
const callee = callNode.getExpression();
|
|
396
|
+
if (!N3.isPropertyAccessExpression(callee)) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
const binding = boundReceiver(callee.getExpression(), resolve);
|
|
400
|
+
if (binding === null) {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
const store = STORES[binding.typeName];
|
|
404
|
+
if (store === void 0) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
const method = callee.getName();
|
|
408
|
+
const access = store.read(method, callNode, resolve);
|
|
409
|
+
if (access === null) {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
return [
|
|
413
|
+
{
|
|
414
|
+
type: "interaction",
|
|
415
|
+
binding: storageBinding({
|
|
416
|
+
recognition: RECOGNITION,
|
|
417
|
+
storageSystem: store.storageSystem,
|
|
418
|
+
scope: "default",
|
|
419
|
+
container: binding.name,
|
|
420
|
+
accessPath: null
|
|
421
|
+
}),
|
|
422
|
+
callee: callee.getText(),
|
|
423
|
+
interaction: {
|
|
424
|
+
class: "storage-access",
|
|
425
|
+
kind: access.kind,
|
|
426
|
+
// KV and R2 keep opaque values and a D1 statement is judged at
|
|
427
|
+
// database level, so no call states a field.
|
|
428
|
+
fields: [],
|
|
429
|
+
operation: method,
|
|
430
|
+
...access.selector !== void 0 ? { selector: [access.selector] } : {}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
function boundReceiver(subject, resolve) {
|
|
436
|
+
let receiver = subject;
|
|
437
|
+
if (N3.isIdentifier(receiver)) {
|
|
438
|
+
const written = declaredInitializer(receiver) ?? resolve(receiver);
|
|
439
|
+
if (written !== null && written !== receiver) {
|
|
440
|
+
receiver = written;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (!N3.isPropertyAccessExpression(receiver)) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
const env = receiver.getExpression();
|
|
447
|
+
if (!N3.isIdentifier(env) || !isTriggerEnvArgument(env)) {
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
const typeName = declaredTypeName(receiver);
|
|
451
|
+
if (typeName === null) {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
return { name: receiver.getName(), typeName };
|
|
455
|
+
}
|
|
456
|
+
function declaredInitializer(identifier) {
|
|
457
|
+
for (const declaration of identifier.getSymbol()?.getDeclarations() ?? []) {
|
|
458
|
+
if (N3.isVariableDeclaration(declaration)) {
|
|
459
|
+
return declaration.getInitializer() ?? null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
function declaredTypeName(receiver) {
|
|
465
|
+
const declarations = receiver.getNameNode().getSymbol()?.getDeclarations() ?? [];
|
|
466
|
+
for (const declaration of declarations) {
|
|
467
|
+
if (!N3.isPropertySignature(declaration)) {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const typeNode = declaration.getTypeNode();
|
|
471
|
+
if (typeNode !== void 0) {
|
|
472
|
+
return typeNode.getText();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
function literalText(argument, resolve) {
|
|
478
|
+
if (argument === void 0) {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
const written = resolve(argument) ?? argument;
|
|
482
|
+
if (N3.isStringLiteral(written) || N3.isNoSubstitutionTemplateLiteral(written)) {
|
|
483
|
+
return written.getLiteralValue();
|
|
484
|
+
}
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
function cloudflareWorkersFramework(options = {}) {
|
|
488
|
+
return {
|
|
489
|
+
name: "cloudflare-workers",
|
|
490
|
+
protocol: "http",
|
|
491
|
+
languages: ["typescript", "javascript"],
|
|
492
|
+
// Nothing is registered in code, so there is no data-driven
|
|
493
|
+
// discovery to declare.
|
|
494
|
+
discovery: [],
|
|
495
|
+
discoverUnits: cloudflareWorkersDiscovery(options),
|
|
496
|
+
terminals: [
|
|
497
|
+
{
|
|
498
|
+
// new Response(body, { status }), which is what a Worker returns
|
|
499
|
+
// for everything: JSON, a redirect, a stream, plain text.
|
|
500
|
+
kind: "response",
|
|
501
|
+
match: { type: "functionCall", functionName: "Response" },
|
|
502
|
+
extraction: {
|
|
503
|
+
body: { from: "argument", position: 0 },
|
|
504
|
+
statusCode: { from: "argumentProperty", position: 1, name: "status" },
|
|
505
|
+
defaultStatusCode: 200
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
// Response.json(body, { status }), the platform's own helper.
|
|
510
|
+
kind: "response",
|
|
511
|
+
match: { type: "functionCall", functionName: "Response.json" },
|
|
512
|
+
extraction: {
|
|
513
|
+
body: { from: "argument", position: 0 },
|
|
514
|
+
statusCode: { from: "argumentProperty", position: 1, name: "status" },
|
|
515
|
+
defaultStatusCode: 200
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
// Response.redirect(url, status). The platform sends 302 when
|
|
520
|
+
// the caller leaves the status off.
|
|
521
|
+
kind: "response",
|
|
522
|
+
match: { type: "functionCall", functionName: "Response.redirect" },
|
|
523
|
+
extraction: {
|
|
524
|
+
statusCode: { from: "argument", position: 1 },
|
|
525
|
+
defaultStatusCode: 302
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
// A returned value that is none of the above: a Response the
|
|
530
|
+
// handler got back from `fetch`, or from a helper of its own.
|
|
531
|
+
kind: "return",
|
|
532
|
+
match: { type: "returnStatement", excludeCallReturns: true },
|
|
533
|
+
extraction: {}
|
|
534
|
+
},
|
|
535
|
+
{ kind: "throw", match: { type: "throwExpression" }, extraction: {} },
|
|
536
|
+
{
|
|
537
|
+
// scheduled, queue and tail return nothing, so their bodies end
|
|
538
|
+
// by running off the end.
|
|
539
|
+
kind: "return",
|
|
540
|
+
match: { type: "functionFallthrough" },
|
|
541
|
+
extraction: {}
|
|
542
|
+
}
|
|
543
|
+
],
|
|
544
|
+
// Every trigger takes its event first, its bindings second and its
|
|
545
|
+
// execution context third.
|
|
546
|
+
inputMapping: {
|
|
547
|
+
type: "positionalParams",
|
|
548
|
+
params: [
|
|
549
|
+
{ position: 0, role: "event" },
|
|
550
|
+
{ position: 1, role: "config" },
|
|
551
|
+
{ position: 2, role: "context" }
|
|
552
|
+
]
|
|
553
|
+
},
|
|
554
|
+
accessRecognizers: [envBindingRecognizer(options)],
|
|
555
|
+
// A store call on an env binding: `env.SESSIONS.get(key)`.
|
|
556
|
+
invocationRecognizers: [storeBindingRecognizer]
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
var index_default = cloudflareWorkersFramework;
|
|
560
|
+
export {
|
|
561
|
+
index_default as default
|
|
562
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@suss/framework-drizzle';
|