@suss/packs 0.29.0 → 0.31.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/dist/activerecord.js +55 -2
- package/dist/aiohttp.js +4 -1
- package/dist/aws-sqs.js +2 -5
- package/dist/{chunk-CZY5QLMS.js → chunk-NYWZHQBJ.js} +2 -1
- package/dist/cloudflare-workers.js +90 -204
- package/dist/drizzle.js +56 -88
- package/dist/httpx.js +5 -0
- package/dist/node.js +90 -141
- package/dist/rails.js +67 -10
- package/dist/requests.js +4 -1
- package/dist/sqlalchemy.js +1 -1
- package/dist/sqlmodel.js +5 -1
- package/package.json +10 -10
package/dist/drizzle.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// ../framework/drizzle/dist/index.js
|
|
2
2
|
import { Node as N } from "ts-morph";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
arrayLiteralOf,
|
|
6
|
+
objectLiteralOf,
|
|
7
|
+
propertiesOf,
|
|
8
|
+
propertyNameOf,
|
|
9
|
+
propertyOf,
|
|
10
|
+
stringValueOf,
|
|
11
|
+
writtenNodeOf
|
|
12
|
+
} from "@suss/adapter-typescript";
|
|
5
13
|
import { storageBinding } from "@suss/behavioral-ir";
|
|
6
14
|
import { scopeOption, storageSystemOption } from "@suss/extractor";
|
|
7
15
|
import {
|
|
@@ -13,6 +21,7 @@ import {
|
|
|
13
21
|
} from "@suss/recognize";
|
|
14
22
|
var QUERY_API_METHODS = /* @__PURE__ */ new Set(["findMany", "findFirst"]);
|
|
15
23
|
var TABLE_FACTORIES = /* @__PURE__ */ new Set(["pgTable", "mysqlTable", "sqliteTable"]);
|
|
24
|
+
var DRIZZLE_PACKAGE = "drizzle-orm";
|
|
16
25
|
var CHAIN_WALK_LIMIT = 12;
|
|
17
26
|
var optionsSchema = z.object({
|
|
18
27
|
/**
|
|
@@ -36,8 +45,9 @@ function rawStatements(opts) {
|
|
|
36
45
|
function makeRecognizer(opts) {
|
|
37
46
|
const storageSystem = opts.storageSystem ?? "postgresql";
|
|
38
47
|
const scope = opts.scope ?? "default";
|
|
39
|
-
return (call) => {
|
|
40
|
-
const
|
|
48
|
+
return (call, ctx) => {
|
|
49
|
+
const { resolution } = ctx;
|
|
50
|
+
const query = recognizeAnchor(call, resolution);
|
|
41
51
|
if (query === null) {
|
|
42
52
|
return null;
|
|
43
53
|
}
|
|
@@ -62,24 +72,24 @@ function makeRecognizer(opts) {
|
|
|
62
72
|
];
|
|
63
73
|
};
|
|
64
74
|
}
|
|
65
|
-
function recognizeAnchor(call) {
|
|
75
|
+
function recognizeAnchor(call, resolution) {
|
|
66
76
|
const callee = call.getExpression();
|
|
67
77
|
if (!N.isPropertyAccessExpression(callee)) {
|
|
68
78
|
return null;
|
|
69
79
|
}
|
|
70
80
|
const method = callee.getName();
|
|
71
81
|
if (method === "from") {
|
|
72
|
-
return recognizeSelect(call, callee.getExpression());
|
|
82
|
+
return recognizeSelect(call, callee.getExpression(), resolution);
|
|
73
83
|
}
|
|
74
84
|
if (method === "insert" || method === "update" || method === "delete") {
|
|
75
|
-
return recognizeMutation(call, callee.getExpression(), method);
|
|
85
|
+
return recognizeMutation(call, callee.getExpression(), method, resolution);
|
|
76
86
|
}
|
|
77
87
|
if (QUERY_API_METHODS.has(method)) {
|
|
78
|
-
return recognizeQueryApi(call, callee.getExpression(), method);
|
|
88
|
+
return recognizeQueryApi(call, callee.getExpression(), method, resolution);
|
|
79
89
|
}
|
|
80
90
|
return null;
|
|
81
91
|
}
|
|
82
|
-
function recognizeSelect(fromCall, receiver) {
|
|
92
|
+
function recognizeSelect(fromCall, receiver, resolution) {
|
|
83
93
|
if (!N.isCallExpression(receiver)) {
|
|
84
94
|
return null;
|
|
85
95
|
}
|
|
@@ -98,10 +108,11 @@ function recognizeSelect(fromCall, receiver) {
|
|
|
98
108
|
if (tableArg === void 0) {
|
|
99
109
|
return null;
|
|
100
110
|
}
|
|
101
|
-
const table = resolveTableName(tableArg);
|
|
111
|
+
const table = resolveTableName(tableArg, resolution);
|
|
102
112
|
const tableExprText = tableArg.getText();
|
|
103
113
|
const selectArg = receiver.getArguments()[0];
|
|
104
|
-
const
|
|
114
|
+
const projected = selectArg === void 0 ? [] : objectKeys(selectArg, resolution);
|
|
115
|
+
const fields = projected.length > 0 ? projected : ["*"];
|
|
105
116
|
const chain = collectChainCalls(fromCall);
|
|
106
117
|
const selector = selectorFromWhere(chain.get("where"), tableExprText);
|
|
107
118
|
return {
|
|
@@ -114,7 +125,7 @@ function recognizeSelect(fromCall, receiver) {
|
|
|
114
125
|
calleeText: fromCall.getExpression().getText()
|
|
115
126
|
};
|
|
116
127
|
}
|
|
117
|
-
function recognizeMutation(call, receiver, operation) {
|
|
128
|
+
function recognizeMutation(call, receiver, operation, resolution) {
|
|
118
129
|
if (!isDrizzleReceiver(receiver)) {
|
|
119
130
|
return null;
|
|
120
131
|
}
|
|
@@ -122,10 +133,10 @@ function recognizeMutation(call, receiver, operation) {
|
|
|
122
133
|
if (tableArg === void 0) {
|
|
123
134
|
return null;
|
|
124
135
|
}
|
|
125
|
-
const table = resolveTableName(tableArg);
|
|
136
|
+
const table = resolveTableName(tableArg, resolution);
|
|
126
137
|
const tableExprText = tableArg.getText();
|
|
127
138
|
const chain = collectChainCalls(call);
|
|
128
|
-
const fields = operation === "insert" ? valuesKeys(chain.get("values")) : operation === "update" ? setKeys(chain.get("set")) : ["*"];
|
|
139
|
+
const fields = operation === "insert" ? valuesKeys(chain.get("values"), resolution) : operation === "update" ? setKeys(chain.get("set"), resolution) : ["*"];
|
|
129
140
|
const selector = selectorFromWhere(chain.get("where"), tableExprText);
|
|
130
141
|
return {
|
|
131
142
|
kind: "write",
|
|
@@ -137,7 +148,7 @@ function recognizeMutation(call, receiver, operation) {
|
|
|
137
148
|
calleeText: call.getExpression().getText()
|
|
138
149
|
};
|
|
139
150
|
}
|
|
140
|
-
function recognizeQueryApi(call, receiver, operation) {
|
|
151
|
+
function recognizeQueryApi(call, receiver, operation, resolution) {
|
|
141
152
|
if (!N.isPropertyAccessExpression(receiver)) {
|
|
142
153
|
return null;
|
|
143
154
|
}
|
|
@@ -148,17 +159,14 @@ function recognizeQueryApi(call, receiver, operation) {
|
|
|
148
159
|
if (!isDrizzleReceiver(queryAccess.getExpression())) {
|
|
149
160
|
return null;
|
|
150
161
|
}
|
|
151
|
-
const table = resolveTableName(receiver) ?? receiver.getName();
|
|
162
|
+
const table = resolveTableName(receiver, resolution) ?? receiver.getName();
|
|
152
163
|
const optionsArg = call.getArguments()[0];
|
|
164
|
+
const options = optionsArg === void 0 ? null : objectLiteralOf(optionsArg, resolution);
|
|
153
165
|
const fields = [];
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
fields.push(...objectKeys(
|
|
158
|
-
}
|
|
159
|
-
const withProp = objectProperty(optionsArg, "with");
|
|
160
|
-
if (withProp !== null && N.isObjectLiteralExpression(withProp)) {
|
|
161
|
-
fields.push(...objectKeys(withProp));
|
|
166
|
+
for (const key of ["columns", "with"]) {
|
|
167
|
+
const written = options === null ? null : propertyOf(options, key, resolution);
|
|
168
|
+
if (written !== null) {
|
|
169
|
+
fields.push(...objectKeys(written, resolution));
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
172
|
return {
|
|
@@ -204,98 +212,58 @@ function isDrizzleReceiver(node) {
|
|
|
204
212
|
}
|
|
205
213
|
return false;
|
|
206
214
|
}
|
|
207
|
-
function resolveTableName(tableExpr) {
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
215
|
+
function resolveTableName(tableExpr, resolution) {
|
|
216
|
+
const written = writtenNodeOf(tableExpr, resolution);
|
|
217
|
+
if (written === null || !N.isCallExpression(written) || !isTableFactory(written.getExpression(), resolution)) {
|
|
210
218
|
return null;
|
|
211
219
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (declared !== null) {
|
|
215
|
-
return declared;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
220
|
+
const first = written.getArguments()[0];
|
|
221
|
+
return first === void 0 ? null : stringValueOf(first, resolution);
|
|
219
222
|
}
|
|
220
|
-
function
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
const aliased = symbol === void 0 ? void 0 : resolveAliasedSymbol(symbol);
|
|
224
|
-
for (const target of aliased?.getDeclarations() ?? []) {
|
|
225
|
-
const name = tableNameFromDeclaration(target);
|
|
226
|
-
if (name !== null) {
|
|
227
|
-
return name;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
if (!N.isVariableDeclaration(decl)) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
const init = decl.getInitializer();
|
|
236
|
-
if (init === void 0 || !N.isCallExpression(init)) {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
const calleeText = init.getExpression().getText();
|
|
240
|
-
const calleeName = calleeText.split(".").pop() ?? calleeText;
|
|
241
|
-
if (!TABLE_FACTORIES.has(calleeName)) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
const first = init.getArguments()[0];
|
|
245
|
-
if (first !== void 0 && N.isStringLiteral(first)) {
|
|
246
|
-
return first.getLiteralValue();
|
|
223
|
+
function isTableFactory(callee, resolution) {
|
|
224
|
+
if (resolution === void 0) {
|
|
225
|
+
return false;
|
|
247
226
|
}
|
|
248
|
-
return
|
|
227
|
+
return resolution.importedNamesOf(callee, [DRIZZLE_PACKAGE]).some((name) => TABLE_FACTORIES.has(name));
|
|
249
228
|
}
|
|
250
|
-
function objectKeys(
|
|
251
|
-
|
|
229
|
+
function objectKeys(value, resolution) {
|
|
230
|
+
const object = objectLiteralOf(value, resolution);
|
|
231
|
+
if (object === null) {
|
|
252
232
|
return [];
|
|
253
233
|
}
|
|
254
234
|
const keys = [];
|
|
255
|
-
for (const
|
|
256
|
-
|
|
257
|
-
|
|
235
|
+
for (const property of propertiesOf(object, resolution)) {
|
|
236
|
+
const name = propertyNameOf(property);
|
|
237
|
+
if (name !== null) {
|
|
238
|
+
keys.push(name);
|
|
258
239
|
}
|
|
259
240
|
}
|
|
260
241
|
return keys;
|
|
261
242
|
}
|
|
262
|
-
function
|
|
263
|
-
if (!N.isObjectLiteralExpression(obj)) {
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
for (const prop of obj.getProperties()) {
|
|
267
|
-
if (N.isPropertyAssignment(prop) && prop.getName() === name) {
|
|
268
|
-
return prop.getInitializer() ?? null;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
function valuesKeys(valuesCall) {
|
|
243
|
+
function valuesKeys(valuesCall, resolution) {
|
|
274
244
|
const arg = valuesCall?.getArguments()[0];
|
|
275
245
|
if (arg === void 0) {
|
|
276
246
|
return ["*"];
|
|
277
247
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return keys.length > 0 ? keys : ["*"];
|
|
281
|
-
}
|
|
282
|
-
if (N.isArrayLiteralExpression(arg)) {
|
|
248
|
+
const rows = arrayLiteralOf(arg, resolution);
|
|
249
|
+
if (rows !== null) {
|
|
283
250
|
const union = /* @__PURE__ */ new Set();
|
|
284
|
-
for (const element of
|
|
285
|
-
for (const key of objectKeys(element)) {
|
|
251
|
+
for (const element of rows.getElements()) {
|
|
252
|
+
for (const key of objectKeys(element, resolution)) {
|
|
286
253
|
union.add(key);
|
|
287
254
|
}
|
|
288
255
|
}
|
|
289
256
|
return union.size > 0 ? [...union] : ["*"];
|
|
290
257
|
}
|
|
291
|
-
|
|
258
|
+
const keys = objectKeys(arg, resolution);
|
|
259
|
+
return keys.length > 0 ? keys : ["*"];
|
|
292
260
|
}
|
|
293
|
-
function setKeys(setCall) {
|
|
261
|
+
function setKeys(setCall, resolution) {
|
|
294
262
|
const arg = setCall?.getArguments()[0];
|
|
295
263
|
if (arg === void 0) {
|
|
296
264
|
return ["*"];
|
|
297
265
|
}
|
|
298
|
-
const keys = objectKeys(arg);
|
|
266
|
+
const keys = objectKeys(arg, resolution);
|
|
299
267
|
return keys.length > 0 ? keys : ["*"];
|
|
300
268
|
}
|
|
301
269
|
function selectorFromWhere(whereCall, tableExprText) {
|
package/dist/httpx.js
CHANGED
|
@@ -37,6 +37,11 @@ function httpxClient() {
|
|
|
37
37
|
failureDelivery: "response"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
],
|
|
41
|
+
// Both classes document `__enter__` as giving back the client, so
|
|
42
|
+
// `with httpx.Client() as c` puts the constructed client in c.
|
|
43
|
+
contextManagers: [
|
|
44
|
+
{ module: "httpx", returnsSelf: ["Client", "AsyncClient"] }
|
|
40
45
|
]
|
|
41
46
|
};
|
|
42
47
|
}
|
package/dist/node.js
CHANGED
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import {
|
|
4
4
|
Node as N,
|
|
5
|
-
|
|
5
|
+
SyntaxKind
|
|
6
6
|
} from "ts-morph";
|
|
7
|
+
import {
|
|
8
|
+
findEnclosingFunction,
|
|
9
|
+
functionTargetOf,
|
|
10
|
+
isDefaultedAt,
|
|
11
|
+
stringValueOf,
|
|
12
|
+
symbolBehind
|
|
13
|
+
} from "@suss/adapter-typescript";
|
|
7
14
|
import { runtimeConfigBinding } from "@suss/behavioral-ir";
|
|
8
15
|
import { Node } from "ts-morph";
|
|
9
16
|
import { runtimeConfigBinding as runtimeConfigBinding2 } from "@suss/behavioral-ir";
|
|
@@ -29,7 +36,7 @@ function dottedRead(node) {
|
|
|
29
36
|
}
|
|
30
37
|
return [{ name: node.getName(), defaulted: isDefaultedAt(node), node }];
|
|
31
38
|
}
|
|
32
|
-
function bracketRead(access) {
|
|
39
|
+
function bracketRead(access, resolution) {
|
|
33
40
|
const argument = access.getArgumentExpression();
|
|
34
41
|
if (argument === void 0) {
|
|
35
42
|
return [];
|
|
@@ -42,51 +49,49 @@ function bracketRead(access) {
|
|
|
42
49
|
return [{ name, defaulted: isDefaultedAt(access), node: access }];
|
|
43
50
|
}
|
|
44
51
|
if (N.isIdentifier(argument)) {
|
|
45
|
-
return readsThroughParameter(access, argument);
|
|
52
|
+
return readsThroughParameter(access, argument, resolution);
|
|
46
53
|
}
|
|
47
54
|
return [];
|
|
48
55
|
}
|
|
49
56
|
var CALLER_LOOKUPS = /* @__PURE__ */ new WeakMap();
|
|
50
|
-
function readsThroughParameter(access, index) {
|
|
57
|
+
function readsThroughParameter(access, index, resolution) {
|
|
51
58
|
const remembered = CALLER_LOOKUPS.get(access);
|
|
52
59
|
if (remembered !== void 0) {
|
|
53
60
|
return remembered;
|
|
54
61
|
}
|
|
55
|
-
const found = callerLiteralReads(access, index);
|
|
62
|
+
const found = callerLiteralReads(access, index, resolution);
|
|
56
63
|
CALLER_LOOKUPS.set(access, found);
|
|
57
64
|
return found;
|
|
58
65
|
}
|
|
59
|
-
function callerLiteralReads(access, index) {
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
function callerLiteralReads(access, index, resolution) {
|
|
67
|
+
if (resolution === void 0) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
const enclosing = findEnclosingFunction(access);
|
|
71
|
+
if (enclosing === null) {
|
|
62
72
|
return [];
|
|
63
73
|
}
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
74
|
+
const start = enclosing.getParameters().find((parameter) => parameter.getName() === index.getText());
|
|
75
|
+
if (start === void 0) {
|
|
66
76
|
return [];
|
|
67
77
|
}
|
|
68
78
|
const defaulted = isDefaultedAt(access);
|
|
69
79
|
const reads = [];
|
|
70
|
-
const pending = [
|
|
80
|
+
const pending = [start];
|
|
71
81
|
const taken = /* @__PURE__ */ new Set();
|
|
72
82
|
while (pending.length > 0) {
|
|
73
83
|
const wanted = pending.pop();
|
|
74
|
-
|
|
75
|
-
if (taken.has(key)) {
|
|
84
|
+
if (taken.has(wanted)) {
|
|
76
85
|
continue;
|
|
77
86
|
}
|
|
78
|
-
taken.add(
|
|
79
|
-
for (const
|
|
80
|
-
const
|
|
81
|
-
if (passed === void 0) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const literal = literalBehind(passed);
|
|
87
|
+
taken.add(wanted);
|
|
88
|
+
for (const passed of resolution.argumentsPassedTo(wanted)) {
|
|
89
|
+
const literal = stringValueOf(passed.argument, resolution);
|
|
85
90
|
if (literal !== null && literal.length > 0) {
|
|
86
|
-
reads.push({ name: literal, defaulted, node: call });
|
|
91
|
+
reads.push({ name: literal, defaulted, node: passed.call });
|
|
87
92
|
continue;
|
|
88
93
|
}
|
|
89
|
-
const forwarded = forwardedParameter(passed, call);
|
|
94
|
+
const forwarded = forwardedParameter(passed.argument, passed.call);
|
|
90
95
|
if (forwarded !== null) {
|
|
91
96
|
pending.push(forwarded);
|
|
92
97
|
}
|
|
@@ -94,63 +99,19 @@ function callerLiteralReads(access, index) {
|
|
|
94
99
|
}
|
|
95
100
|
return reads;
|
|
96
101
|
}
|
|
97
|
-
function enclosingFunction(node) {
|
|
98
|
-
return node.getFirstAncestor(
|
|
99
|
-
(candidate) => N.isFunctionDeclaration(candidate) || N.isArrowFunction(candidate) || N.isFunctionExpression(candidate) || N.isMethodDeclaration(candidate)
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
function literalBehind(passed) {
|
|
103
|
-
if (N.isStringLiteral(passed) || N.isNoSubstitutionTemplateLiteral(passed)) {
|
|
104
|
-
return passed.getLiteralValue();
|
|
105
|
-
}
|
|
106
|
-
if (!N.isIdentifier(passed)) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
for (const definition of passed.getDefinitionNodes()) {
|
|
110
|
-
if (!N.isVariableDeclaration(definition)) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
const initializer = definition.getInitializer();
|
|
114
|
-
if (initializer !== void 0 && definition.getVariableStatement()?.getDeclarationKind() === VariableDeclarationKind.Const && (N.isStringLiteral(initializer) || N.isNoSubstitutionTemplateLiteral(initializer))) {
|
|
115
|
-
return initializer.getLiteralValue();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
102
|
function forwardedParameter(passed, call) {
|
|
121
103
|
if (!N.isIdentifier(passed)) {
|
|
122
104
|
return null;
|
|
123
105
|
}
|
|
124
|
-
const caller =
|
|
125
|
-
if (caller ===
|
|
106
|
+
const caller = findEnclosingFunction(call);
|
|
107
|
+
if (caller === null) {
|
|
126
108
|
return null;
|
|
127
109
|
}
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
function callSitesOf(fn) {
|
|
132
|
-
const named = N.isVariableDeclaration(fn.getParent()) ? fn.getParent().getNameNode() : fn.getNameNode?.();
|
|
133
|
-
if (named === void 0 || !N.isIdentifier(named)) {
|
|
134
|
-
return [];
|
|
135
|
-
}
|
|
136
|
-
const calls = [];
|
|
137
|
-
for (const reference of named.findReferencesAsNodes()) {
|
|
138
|
-
const parent = reference.getParent();
|
|
139
|
-
if (parent === void 0) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (N.isCallExpression(parent) && parent.getExpression() === reference) {
|
|
143
|
-
calls.push(parent);
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
if (N.isPropertyAccessExpression(parent) && parent.getNameNode() === reference) {
|
|
147
|
-
const grandparent = parent.getParent();
|
|
148
|
-
if (grandparent !== void 0 && N.isCallExpression(grandparent) && grandparent.getExpression() === parent) {
|
|
149
|
-
calls.push(grandparent);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
110
|
+
const behind = symbolBehind(passed)?.getValueDeclaration();
|
|
111
|
+
if (behind === void 0 || !N.isParameterDeclaration(behind)) {
|
|
112
|
+
return null;
|
|
152
113
|
}
|
|
153
|
-
return
|
|
114
|
+
return behind.getParent() === caller ? behind : null;
|
|
154
115
|
}
|
|
155
116
|
function bindingRead(element) {
|
|
156
117
|
if (element.getDotDotDotToken() !== void 0) {
|
|
@@ -181,37 +142,37 @@ function destructuredReads(declaration) {
|
|
|
181
142
|
}
|
|
182
143
|
return pattern.getElements().flatMap(bindingRead);
|
|
183
144
|
}
|
|
184
|
-
function readsThroughEnvObject(envNode) {
|
|
145
|
+
function readsThroughEnvObject(envNode, resolution) {
|
|
185
146
|
const parent = envNode.getParent();
|
|
186
147
|
if (N.isElementAccessExpression(parent)) {
|
|
187
|
-
return bracketRead(parent);
|
|
148
|
+
return bracketRead(parent, resolution);
|
|
188
149
|
}
|
|
189
150
|
if (N.isVariableDeclaration(parent)) {
|
|
190
151
|
return destructuredReads(parent);
|
|
191
152
|
}
|
|
192
153
|
return [];
|
|
193
154
|
}
|
|
194
|
-
function envReadsAt(node) {
|
|
155
|
+
function envReadsAt(node, resolution) {
|
|
195
156
|
if (N.isCallExpression(node)) {
|
|
196
|
-
return readsThroughHelperCall(node);
|
|
157
|
+
return readsThroughHelperCall(node, resolution);
|
|
197
158
|
}
|
|
198
159
|
if (!N.isPropertyAccessExpression(node)) {
|
|
199
160
|
return [];
|
|
200
161
|
}
|
|
201
|
-
return isProcessEnv(node) ? readsThroughEnvObject(node) : dottedRead(node);
|
|
162
|
+
return isProcessEnv(node) ? readsThroughEnvObject(node, resolution) : dottedRead(node);
|
|
202
163
|
}
|
|
203
|
-
function readsThroughHelperCall(call) {
|
|
164
|
+
function readsThroughHelperCall(call, resolution) {
|
|
204
165
|
const reads = [];
|
|
205
166
|
const callee = functionBehindCallee(call.getExpression());
|
|
206
167
|
if (callee === null) {
|
|
207
168
|
return reads;
|
|
208
169
|
}
|
|
209
170
|
call.getArguments().forEach((passed, at) => {
|
|
210
|
-
const literal =
|
|
171
|
+
const literal = stringValueOf(passed, resolution);
|
|
211
172
|
if (literal === null || literal.length === 0) {
|
|
212
173
|
return;
|
|
213
174
|
}
|
|
214
|
-
const read = parameterReachesEnvRead(callee, at);
|
|
175
|
+
const read = parameterReachesEnvRead(callee, at, resolution);
|
|
215
176
|
if (read !== null) {
|
|
216
177
|
reads.push({ name: literal, defaulted: read.defaulted, node: call });
|
|
217
178
|
}
|
|
@@ -223,31 +184,24 @@ function functionBehindCallee(callee) {
|
|
|
223
184
|
if (!N.isIdentifier(nameNode)) {
|
|
224
185
|
return null;
|
|
225
186
|
}
|
|
226
|
-
|
|
227
|
-
if (N.isFunctionDeclaration(definition) || N.isMethodDeclaration(definition)) {
|
|
228
|
-
return definition;
|
|
229
|
-
}
|
|
230
|
-
if (N.isVariableDeclaration(definition)) {
|
|
231
|
-
const initializer = definition.getInitializer();
|
|
232
|
-
if (initializer !== void 0 && (N.isArrowFunction(initializer) || N.isFunctionExpression(initializer))) {
|
|
233
|
-
return initializer;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return null;
|
|
187
|
+
return functionTargetOf(nameNode)?.func ?? null;
|
|
238
188
|
}
|
|
239
189
|
var PARAM_ENV_READS = /* @__PURE__ */ new WeakMap();
|
|
240
|
-
function parameterReachesEnvRead(fn, at) {
|
|
190
|
+
function parameterReachesEnvRead(fn, at, resolution) {
|
|
241
191
|
const byParameter = PARAM_ENV_READS.get(fn.compilerNode) ?? /* @__PURE__ */ new Map();
|
|
242
192
|
PARAM_ENV_READS.set(fn.compilerNode, byParameter);
|
|
243
193
|
const remembered = byParameter.get(at);
|
|
244
194
|
if (remembered !== void 0) {
|
|
245
195
|
return remembered;
|
|
246
196
|
}
|
|
247
|
-
|
|
197
|
+
const found = reachesEnvRead(fn, at, resolution);
|
|
198
|
+
byParameter.set(at, found);
|
|
199
|
+
return found;
|
|
200
|
+
}
|
|
201
|
+
function reachesEnvRead(fn, at, resolution) {
|
|
248
202
|
const pending = [{ fn, at }];
|
|
249
203
|
const taken = /* @__PURE__ */ new Set();
|
|
250
|
-
while (pending.length > 0
|
|
204
|
+
while (pending.length > 0) {
|
|
251
205
|
const wanted = pending.pop();
|
|
252
206
|
const key = `${wanted.fn.getPos()}:${wanted.at}`;
|
|
253
207
|
if (taken.has(key)) {
|
|
@@ -258,57 +212,47 @@ function parameterReachesEnvRead(fn, at) {
|
|
|
258
212
|
if (parameter === void 0) {
|
|
259
213
|
continue;
|
|
260
214
|
}
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return;
|
|
215
|
+
const direct = directEnvRead(wanted.fn, parameter);
|
|
216
|
+
if (direct !== null) {
|
|
217
|
+
return direct;
|
|
218
|
+
}
|
|
219
|
+
if (resolution === void 0) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
for (const passed of resolution.callsPassing(parameter)) {
|
|
223
|
+
if (!N.isCallExpression(passed.call)) {
|
|
224
|
+
continue;
|
|
272
225
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (next !== null && next !== wanted.fn) {
|
|
280
|
-
pending.push({ fn: next, at: position });
|
|
281
|
-
}
|
|
282
|
-
});
|
|
226
|
+
const position = passed.call.getArguments().indexOf(passed.argument);
|
|
227
|
+
const next = functionLikeOf(
|
|
228
|
+
resolution.resolveCallable(passed.call.getExpression())
|
|
229
|
+
);
|
|
230
|
+
if (position >= 0 && next !== null && next !== wanted.fn) {
|
|
231
|
+
pending.push({ fn: next, at: position });
|
|
283
232
|
}
|
|
284
|
-
}
|
|
233
|
+
}
|
|
285
234
|
}
|
|
286
|
-
|
|
287
|
-
return found;
|
|
235
|
+
return null;
|
|
288
236
|
}
|
|
289
|
-
function
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
294
|
-
child = parent;
|
|
295
|
-
parent = parent.getParent();
|
|
237
|
+
function directEnvRead(fn, parameter) {
|
|
238
|
+
for (const access of fn.getDescendantsOfKind(
|
|
239
|
+
SyntaxKind.ElementAccessExpression
|
|
240
|
+
)) {
|
|
241
|
+
if (!isProcessEnv(access.getExpression())) {
|
|
296
242
|
continue;
|
|
297
243
|
}
|
|
298
|
-
|
|
299
|
-
|
|
244
|
+
const argument = access.getArgumentExpression();
|
|
245
|
+
if (argument !== void 0 && N.isIdentifier(argument) && symbolBehind(argument)?.getValueDeclaration() === parameter) {
|
|
246
|
+
return { defaulted: isDefaultedAt(access) };
|
|
300
247
|
}
|
|
301
|
-
const op = parent.getOperatorToken().getText();
|
|
302
|
-
if (op !== "??" && op !== "||") {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
if (parent.getLeft() === child) {
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
child = parent;
|
|
309
|
-
parent = parent.getParent();
|
|
310
248
|
}
|
|
311
|
-
return
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
function functionLikeOf(node) {
|
|
252
|
+
if (node === null) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
return N.isFunctionDeclaration(node) || N.isArrowFunction(node) || N.isFunctionExpression(node) || N.isMethodDeclaration(node) ? node : null;
|
|
312
256
|
}
|
|
313
257
|
function configReadEffect(read, deploymentTarget, instanceName) {
|
|
314
258
|
return {
|
|
@@ -326,8 +270,8 @@ function configReadEffect(read, deploymentTarget, instanceName) {
|
|
|
326
270
|
}
|
|
327
271
|
};
|
|
328
272
|
}
|
|
329
|
-
function recognizeProcessEnvRead(access, deploymentTarget, instanceName) {
|
|
330
|
-
const reads = envReadsAt(access);
|
|
273
|
+
function recognizeProcessEnvRead(access, deploymentTarget, instanceName, resolution) {
|
|
274
|
+
const reads = envReadsAt(access, resolution);
|
|
331
275
|
if (reads.length === 0) {
|
|
332
276
|
return null;
|
|
333
277
|
}
|
|
@@ -338,7 +282,12 @@ function recognizeProcessEnvRead(access, deploymentTarget, instanceName) {
|
|
|
338
282
|
function envVarRecognizer(opts = {}) {
|
|
339
283
|
const deploymentTarget = opts.deploymentTarget ?? "lambda";
|
|
340
284
|
const instanceName = opts.instanceName ?? "<unknown>";
|
|
341
|
-
return (access,
|
|
285
|
+
return (access, ctx) => recognizeProcessEnvRead(
|
|
286
|
+
access,
|
|
287
|
+
deploymentTarget,
|
|
288
|
+
instanceName,
|
|
289
|
+
ctx.resolution
|
|
290
|
+
);
|
|
342
291
|
}
|
|
343
292
|
var FILE_LOCATION_GLOBALS = /* @__PURE__ */ new Set(["__dirname", "__filename"]);
|
|
344
293
|
function moduleMetaRead(callee) {
|