@suss/packs 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aws-dynamodb.js +140 -301
- package/dist/aws-s3.js +27 -107
- package/dist/axios.js +2 -2
- package/dist/drizzle.js +20 -73
- package/dist/fastapi.js +1 -0
- package/dist/fetch.js +1 -1
- package/dist/gcs.js +44 -123
- package/dist/mongoose.js +123 -344
- package/dist/prisma.js +25 -74
- package/dist/react-router.js +1 -2
- package/dist/ts-rest.js +1 -1
- package/package.json +10 -10
package/dist/aws-dynamodb.js
CHANGED
|
@@ -1,237 +1,127 @@
|
|
|
1
1
|
// ../framework/aws-dynamodb/dist/index.js
|
|
2
|
-
import {
|
|
3
|
-
import { readName, rootIdentifier } from "@suss/adapter-typescript";
|
|
4
|
-
import { storageBinding } from "@suss/behavioral-ir";
|
|
2
|
+
import { constructedFrom, pack, storageCalls } from "@suss/recognize";
|
|
5
3
|
var COMMAND_MODULES = [
|
|
6
4
|
"@aws-sdk/lib-dynamodb",
|
|
7
5
|
"@aws-sdk/client-dynamodb"
|
|
8
6
|
];
|
|
9
7
|
var RECOGNITION = "@suss/framework-aws-dynamodb";
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ScanCommand: "read",
|
|
15
|
-
BatchGetCommand: "read",
|
|
16
|
-
BatchGetItemCommand: "read",
|
|
17
|
-
PutCommand: "write",
|
|
18
|
-
PutItemCommand: "write",
|
|
19
|
-
UpdateCommand: "write",
|
|
20
|
-
UpdateItemCommand: "write",
|
|
21
|
-
DeleteCommand: "write",
|
|
22
|
-
DeleteItemCommand: "write",
|
|
23
|
-
BatchWriteCommand: "write",
|
|
24
|
-
BatchWriteItemCommand: "write"
|
|
8
|
+
var COMMAND = {
|
|
9
|
+
to: "argument",
|
|
10
|
+
at: { from: 0 },
|
|
11
|
+
origin: constructedFrom(...COMMAND_MODULES)
|
|
25
12
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const kind = COMMANDS[commandName];
|
|
45
|
-
if (kind === void 0) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
if (!fromDynamoModule(ctorExpr, recognizerCtx)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const input = built.getArguments()[0];
|
|
52
|
-
if (input === void 0 || !N.isObjectLiteralExpression(input)) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return requestEffects({
|
|
56
|
-
input,
|
|
57
|
-
kind,
|
|
58
|
-
operation: commandName,
|
|
59
|
-
callee: callee.getText(),
|
|
60
|
-
transport: "aws-sdk",
|
|
61
|
-
resolve
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function requestEffects(read) {
|
|
65
|
-
const { input, kind, operation, callee, resolve } = read;
|
|
66
|
-
const requestItems = property(input, "RequestItems");
|
|
67
|
-
if (requestItems !== null) {
|
|
68
|
-
return batchEffects(requestItems, read);
|
|
69
|
-
}
|
|
70
|
-
const picked = selector(input);
|
|
71
|
-
return [
|
|
72
|
-
{
|
|
73
|
-
type: "interaction",
|
|
74
|
-
binding: dynamoBinding(read, {
|
|
75
|
-
container: nameOfProperty(input, "TableName", resolve),
|
|
76
|
-
accessPath: nameOfProperty(input, "IndexName", resolve)
|
|
77
|
-
}),
|
|
78
|
-
callee,
|
|
79
|
-
interaction: {
|
|
80
|
-
class: "storage-access",
|
|
81
|
-
kind,
|
|
82
|
-
fields: fieldsOf(input, kind),
|
|
83
|
-
operation,
|
|
84
|
-
...picked.length > 0 ? { selector: picked } : {}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
|
-
function dynamoBinding(read, addressed) {
|
|
90
|
-
return storageBinding({
|
|
91
|
-
recognition: RECOGNITION,
|
|
92
|
-
storageSystem: "aws.dynamodb",
|
|
93
|
-
...read.transport === void 0 ? {} : { transport: read.transport },
|
|
94
|
-
scope: "default",
|
|
95
|
-
container: addressed.container,
|
|
96
|
-
accessPath: addressed.accessPath
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function batchEffects(requestItems, read) {
|
|
100
|
-
const { kind, operation, callee, resolve } = read;
|
|
101
|
-
if (!N.isObjectLiteralExpression(requestItems)) {
|
|
13
|
+
var COMMAND_INPUT = { at: 0 };
|
|
14
|
+
var TABLE = { at: 0, property: ["TableName"] };
|
|
15
|
+
var INDEX = { at: 0, property: ["IndexName"] };
|
|
16
|
+
var TABLES = { at: 0, property: ["RequestItems"] };
|
|
17
|
+
var ATTRIBUTES = ({ input, entry, kind }) => {
|
|
18
|
+
if (entry !== null) {
|
|
19
|
+
const requested = requestedAttributes(entry);
|
|
20
|
+
return requested.length > 0 ? requested : everything(kind);
|
|
21
|
+
}
|
|
22
|
+
const projected = projectedAttributes(input);
|
|
23
|
+
if (projected !== null) {
|
|
24
|
+
return projected;
|
|
25
|
+
}
|
|
26
|
+
const written = namesIn(input.property("Item"));
|
|
27
|
+
return kind === "write" && written.length > 0 ? written : everything(kind);
|
|
28
|
+
};
|
|
29
|
+
var KEY_ATTRIBUTES = ({ input, entry }) => {
|
|
30
|
+
if (entry !== null) {
|
|
102
31
|
return [];
|
|
103
32
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
const requests = entry.getInitializer();
|
|
110
|
-
effects.push({
|
|
111
|
-
type: "interaction",
|
|
112
|
-
binding: dynamoBinding(read, {
|
|
113
|
-
container: entryName(entry, resolve),
|
|
114
|
-
accessPath: null
|
|
115
|
-
}),
|
|
116
|
-
callee,
|
|
117
|
-
interaction: {
|
|
118
|
-
class: "storage-access",
|
|
119
|
-
kind,
|
|
120
|
-
fields: requests === void 0 ? [] : requestedFields(requests, kind),
|
|
121
|
-
operation
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return effects;
|
|
126
|
-
}
|
|
127
|
-
function entryName(entry, resolve) {
|
|
128
|
-
if (!N.isPropertyAssignment(entry)) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
const nameNode = entry.getNameNode();
|
|
132
|
-
if (N.isComputedPropertyName(nameNode)) {
|
|
133
|
-
return readName(nameNode.getExpression(), { resolve });
|
|
33
|
+
const key = namesIn(input.property("Key"));
|
|
34
|
+
if (key.length > 0) {
|
|
35
|
+
return key;
|
|
134
36
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
37
|
+
const condition = input.property("KeyConditionExpression")?.text() ?? null;
|
|
38
|
+
return condition === null ? [] : keyConditionAttributes(condition, aliasesIn(input));
|
|
39
|
+
};
|
|
40
|
+
function everything(kind) {
|
|
41
|
+
return kind === "read" ? ["*"] : [];
|
|
139
42
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
43
|
+
var READ = {
|
|
44
|
+
kind: "read",
|
|
45
|
+
fields: ATTRIBUTES,
|
|
46
|
+
selector: KEY_ATTRIBUTES
|
|
47
|
+
};
|
|
48
|
+
var WRITE = {
|
|
49
|
+
kind: "write",
|
|
50
|
+
fields: ATTRIBUTES,
|
|
51
|
+
selector: KEY_ATTRIBUTES
|
|
52
|
+
};
|
|
53
|
+
var COMMANDS = {
|
|
54
|
+
GetCommand: READ,
|
|
55
|
+
GetItemCommand: READ,
|
|
56
|
+
QueryCommand: READ,
|
|
57
|
+
ScanCommand: READ,
|
|
58
|
+
BatchGetCommand: READ,
|
|
59
|
+
BatchGetItemCommand: READ,
|
|
60
|
+
PutCommand: WRITE,
|
|
61
|
+
PutItemCommand: WRITE,
|
|
62
|
+
UpdateCommand: WRITE,
|
|
63
|
+
UpdateItemCommand: WRITE,
|
|
64
|
+
DeleteCommand: WRITE,
|
|
65
|
+
DeleteItemCommand: WRITE,
|
|
66
|
+
BatchWriteCommand: WRITE,
|
|
67
|
+
BatchWriteItemCommand: WRITE
|
|
68
|
+
};
|
|
69
|
+
var COMMAND_CALLS = storageCalls({
|
|
70
|
+
system: "aws.dynamodb",
|
|
71
|
+
transport: "aws-sdk"
|
|
72
|
+
}).about(COMMAND).methods(COMMANDS).input(COMMAND_INPUT).container(TABLE).accessPath(INDEX).containersIn(TABLES).example(
|
|
73
|
+
'client.send(new GetCommand({ TableName: "orders-v1", Key: { orderId: "a" } }))'
|
|
74
|
+
);
|
|
75
|
+
function namesIn(value) {
|
|
76
|
+
const found = [];
|
|
77
|
+
for (const entry of value?.entries("nothing") ?? []) {
|
|
78
|
+
if (entry.key !== null) {
|
|
79
|
+
found.push(entry.key);
|
|
156
80
|
}
|
|
157
|
-
});
|
|
158
|
-
return found.size > 0 ? [...found] : kind === "read" ? ["*"] : [];
|
|
159
|
-
}
|
|
160
|
-
function asNewExpression(resolved) {
|
|
161
|
-
return resolved !== null && N.isNewExpression(resolved) ? resolved : null;
|
|
162
|
-
}
|
|
163
|
-
function fromDynamoModule(ctorExpr, ctx) {
|
|
164
|
-
const target = N.isPropertyAccessExpression(ctorExpr) ? rootIdentifier(ctorExpr) : ctorExpr;
|
|
165
|
-
if (target === null) {
|
|
166
|
-
return false;
|
|
167
81
|
}
|
|
168
|
-
return
|
|
82
|
+
return found;
|
|
169
83
|
}
|
|
170
|
-
function
|
|
171
|
-
|
|
84
|
+
function projectedAttributes(input) {
|
|
85
|
+
const projection = input.property("ProjectionExpression")?.text() ?? null;
|
|
86
|
+
if (projection === null) {
|
|
172
87
|
return null;
|
|
173
88
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return prop.getInitializer() ?? null;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
function nameOfProperty(input, name, resolve) {
|
|
182
|
-
const written = property(input, name);
|
|
183
|
-
return written === null ? null : readName(written, { resolve, unsettled: "reference" });
|
|
184
|
-
}
|
|
185
|
-
function fieldsOf(input, kind) {
|
|
186
|
-
const projection = property(input, "ProjectionExpression");
|
|
187
|
-
if (projection !== null) {
|
|
188
|
-
const text = literalText(projection);
|
|
189
|
-
if (text !== null) {
|
|
190
|
-
const aliases = expressionNames(input);
|
|
191
|
-
return text.split(",").map((field) => field.trim()).filter((field) => field !== "").map((field) => aliases.get(field) ?? field);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (kind === "write") {
|
|
195
|
-
const item = property(input, "Item");
|
|
196
|
-
if (item !== null && N.isObjectLiteralExpression(item)) {
|
|
197
|
-
return objectKeys(item);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return kind === "read" ? ["*"] : [];
|
|
89
|
+
const aliases = aliasesIn(input);
|
|
90
|
+
return projection.split(",").map((field) => field.trim()).filter((field) => field !== "").map((field) => aliases.get(field) ?? field);
|
|
201
91
|
}
|
|
202
|
-
function
|
|
203
|
-
const key = property(input, "Key");
|
|
204
|
-
if (key !== null && N.isObjectLiteralExpression(key)) {
|
|
205
|
-
return objectKeys(key);
|
|
206
|
-
}
|
|
207
|
-
const condition = property(input, "KeyConditionExpression");
|
|
208
|
-
const text = condition === null ? null : literalText(condition);
|
|
209
|
-
if (text === null) {
|
|
210
|
-
return [];
|
|
211
|
-
}
|
|
212
|
-
return keyConditionAttributes(text, expressionNames(input));
|
|
213
|
-
}
|
|
214
|
-
function expressionNames(input) {
|
|
92
|
+
function aliasesIn(input) {
|
|
215
93
|
const names = /* @__PURE__ */ new Map();
|
|
216
|
-
const declared = property(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (!N.isPropertyAssignment(prop)) {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
const value = prop.getInitializer();
|
|
225
|
-
const written = value === void 0 ? null : literalText(value);
|
|
226
|
-
if (written === null) {
|
|
227
|
-
continue;
|
|
94
|
+
const declared = input.property("ExpressionAttributeNames");
|
|
95
|
+
for (const entry of declared?.entries("nothing") ?? []) {
|
|
96
|
+
const written = entry.value.text();
|
|
97
|
+
if (entry.key !== null && written !== null) {
|
|
98
|
+
names.set(entry.key, written);
|
|
228
99
|
}
|
|
229
|
-
names.set(prop.getName().replace(/^["']|["']$/g, ""), written);
|
|
230
100
|
}
|
|
231
101
|
return names;
|
|
232
102
|
}
|
|
233
|
-
|
|
234
|
-
|
|
103
|
+
var REQUESTED = ["Item", "Key", "Keys"];
|
|
104
|
+
function requestedAttributes(requests) {
|
|
105
|
+
const found = /* @__PURE__ */ new Set();
|
|
106
|
+
const walk = (value) => {
|
|
107
|
+
for (const item of value.items()) {
|
|
108
|
+
walk(item);
|
|
109
|
+
}
|
|
110
|
+
for (const entry of value.entries("nothing")) {
|
|
111
|
+
if (entry.key !== null && REQUESTED.includes(entry.key)) {
|
|
112
|
+
for (const name of attributeNames(entry.value)) {
|
|
113
|
+
found.add(name);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
walk(entry.value);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
walk(requests);
|
|
120
|
+
return [...found];
|
|
121
|
+
}
|
|
122
|
+
function attributeNames(value) {
|
|
123
|
+
const items = value.items();
|
|
124
|
+
return items.length > 0 ? items.flatMap(namesIn) : namesIn(value);
|
|
235
125
|
}
|
|
236
126
|
var ATTRIBUTE_POSITIONS = [
|
|
237
127
|
/([#\w.]+)\s*(?:<>|<=|>=|=|<|>)/g,
|
|
@@ -256,82 +146,40 @@ function keyConditionAttributes(expression, names) {
|
|
|
256
146
|
}
|
|
257
147
|
return found;
|
|
258
148
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
for (const prop of literal.getProperties()) {
|
|
265
|
-
if (N.isPropertyAssignment(prop) || N.isShorthandPropertyAssignment(prop)) {
|
|
266
|
-
keys.push(prop.getName().replace(/^["']|["']$/g, ""));
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return keys;
|
|
270
|
-
}
|
|
271
|
-
function requestFunctionRecognizer(spec) {
|
|
272
|
-
return ((call, ctx) => {
|
|
273
|
-
const callNode = call;
|
|
274
|
-
const recognizerCtx = ctx;
|
|
275
|
-
const resolve = recognizerCtx.resolveWrittenValue ?? (() => null);
|
|
276
|
-
const callee = callNode.getExpression();
|
|
277
|
-
if (calledName(callee) !== spec.name) {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
if (spec.module !== void 0 && !declaredIn(callee, spec.module, recognizerCtx)) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
const args = callNode.getArguments();
|
|
284
|
-
const operation = argumentText(args[spec.operationArg], resolve);
|
|
285
|
-
if (operation === null) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
const kind = spec.operations[operation];
|
|
289
|
-
if (kind === void 0) {
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
const input = objectArgument(args[spec.requestArg], resolve);
|
|
293
|
-
if (input === null) {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
return requestEffects({
|
|
297
|
-
input,
|
|
298
|
-
kind,
|
|
299
|
-
operation,
|
|
300
|
-
callee: callee.getText(),
|
|
301
|
-
resolve
|
|
302
|
-
});
|
|
149
|
+
function requestFunctionCalls(spec) {
|
|
150
|
+
const operation = { at: spec.operationArg };
|
|
151
|
+
const request = (property) => ({
|
|
152
|
+
at: spec.requestArg,
|
|
153
|
+
property: [property]
|
|
303
154
|
});
|
|
155
|
+
return storageCalls({
|
|
156
|
+
system: "aws.dynamodb",
|
|
157
|
+
...spec.module === void 0 ? {} : { client: constructedFrom(spec.module) }
|
|
158
|
+
}).methods({
|
|
159
|
+
[spec.name]: {
|
|
160
|
+
operation,
|
|
161
|
+
kind: { asks: operation, means: spec.operations },
|
|
162
|
+
fields: ATTRIBUTES,
|
|
163
|
+
selector: KEY_ATTRIBUTES
|
|
164
|
+
}
|
|
165
|
+
}).input({ at: spec.requestArg }).container(request("TableName")).accessPath(request("IndexName")).containersIn(request("RequestItems")).example(exampleCall(spec));
|
|
304
166
|
}
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
167
|
+
function exampleCall(spec) {
|
|
168
|
+
const [operation] = Object.keys(spec.operations);
|
|
169
|
+
const written = [];
|
|
170
|
+
for (let at = 0; at <= Math.max(spec.operationArg, spec.requestArg); at++) {
|
|
171
|
+
written.push(argumentText(spec, at, operation ?? ""));
|
|
308
172
|
}
|
|
309
|
-
return
|
|
310
|
-
}
|
|
311
|
-
function declaredIn(callee, module, ctx) {
|
|
312
|
-
const target = N.isPropertyAccessExpression(callee) ? rootIdentifier(callee) : callee;
|
|
313
|
-
return target !== null && ctx.isImportedFrom(target, module);
|
|
173
|
+
return `${spec.name}(${written.join(", ")})`;
|
|
314
174
|
}
|
|
315
|
-
function argumentText(
|
|
316
|
-
if (
|
|
317
|
-
return
|
|
175
|
+
function argumentText(spec, at, operation) {
|
|
176
|
+
if (at === spec.operationArg) {
|
|
177
|
+
return JSON.stringify(operation);
|
|
318
178
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return direct;
|
|
179
|
+
if (at === spec.requestArg) {
|
|
180
|
+
return '{ TableName: "orders-v1", Key: { orderId: "a" } }';
|
|
322
181
|
}
|
|
323
|
-
|
|
324
|
-
return written === null ? null : literalText(written);
|
|
325
|
-
}
|
|
326
|
-
function objectArgument(arg, resolve) {
|
|
327
|
-
if (arg === void 0) {
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
if (N.isObjectLiteralExpression(arg)) {
|
|
331
|
-
return arg;
|
|
332
|
-
}
|
|
333
|
-
const written = resolve(arg);
|
|
334
|
-
return written !== null && N.isObjectLiteralExpression(written) ? written : null;
|
|
182
|
+
return "undefined";
|
|
335
183
|
}
|
|
336
184
|
var isArgumentPosition = (index) => Number.isInteger(index) && index >= 0;
|
|
337
185
|
function checkRequestFunction(spec, at) {
|
|
@@ -360,25 +208,16 @@ function checkRequestFunction(spec, at) {
|
|
|
360
208
|
function dynamoFramework(options = {}) {
|
|
361
209
|
const requestFunctions = options.requestFunctions ?? [];
|
|
362
210
|
requestFunctions.forEach(checkRequestFunction);
|
|
363
|
-
return
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
...options.requiresImport ?? [],
|
|
374
|
-
...requestFunctions.map((spec) => spec.module).filter((module) => module !== void 0)
|
|
375
|
-
])
|
|
376
|
-
],
|
|
377
|
-
invocationRecognizers: [
|
|
378
|
-
dynamoRecognizer,
|
|
379
|
-
...requestFunctions.map(requestFunctionRecognizer)
|
|
380
|
-
]
|
|
381
|
-
};
|
|
211
|
+
return pack(
|
|
212
|
+
"aws-dynamodb",
|
|
213
|
+
[COMMAND_CALLS, ...requestFunctions.map(requestFunctionCalls)],
|
|
214
|
+
{
|
|
215
|
+
languages: ["typescript", "javascript"],
|
|
216
|
+
recognizedAs: RECOGNITION,
|
|
217
|
+
protocol: "dynamodb",
|
|
218
|
+
...options.requiresImport === void 0 ? {} : { requiresImport: options.requiresImport }
|
|
219
|
+
}
|
|
220
|
+
);
|
|
382
221
|
}
|
|
383
222
|
var index_default = dynamoFramework;
|
|
384
223
|
export {
|
package/dist/aws-s3.js
CHANGED
|
@@ -1,118 +1,38 @@
|
|
|
1
1
|
// ../framework/aws-s3/dist/index.js
|
|
2
|
-
import {
|
|
3
|
-
import { readName, rootIdentifier } from "@suss/adapter-typescript";
|
|
4
|
-
import { storageBinding } from "@suss/behavioral-ir";
|
|
5
|
-
var RECOGNITION = "@suss/framework-aws-s3";
|
|
2
|
+
import { constructedFrom, pack, storageCalls } from "@suss/recognize";
|
|
6
3
|
var COMMAND_MODULE = "@aws-sdk/client-s3";
|
|
4
|
+
var COMMAND = { to: "argument", at: { from: 0 } };
|
|
5
|
+
var ADDRESSED = { at: 0, property: ["Key", "Prefix"] };
|
|
6
|
+
var BUCKET = { at: 0, property: ["Bucket"] };
|
|
7
|
+
var READ_OBJECT = { kind: "read", selector: ADDRESSED };
|
|
8
|
+
var WRITE_OBJECT = { kind: "write", selector: ADDRESSED };
|
|
7
9
|
var COMMANDS = {
|
|
8
|
-
GetObjectCommand:
|
|
9
|
-
HeadObjectCommand:
|
|
10
|
-
ListObjectsV2Command:
|
|
11
|
-
ListObjectsCommand:
|
|
12
|
-
PutObjectCommand:
|
|
13
|
-
DeleteObjectCommand:
|
|
14
|
-
DeleteObjectsCommand:
|
|
15
|
-
CopyObjectCommand:
|
|
10
|
+
GetObjectCommand: READ_OBJECT,
|
|
11
|
+
HeadObjectCommand: READ_OBJECT,
|
|
12
|
+
ListObjectsV2Command: READ_OBJECT,
|
|
13
|
+
ListObjectsCommand: READ_OBJECT,
|
|
14
|
+
PutObjectCommand: WRITE_OBJECT,
|
|
15
|
+
DeleteObjectCommand: WRITE_OBJECT,
|
|
16
|
+
DeleteObjectsCommand: WRITE_OBJECT,
|
|
17
|
+
CopyObjectCommand: WRITE_OBJECT,
|
|
16
18
|
// A large object goes up in parts, and each command in that sequence
|
|
17
19
|
// writes the same object.
|
|
18
|
-
CreateMultipartUploadCommand:
|
|
19
|
-
UploadPartCommand:
|
|
20
|
-
CompleteMultipartUploadCommand:
|
|
21
|
-
AbortMultipartUploadCommand:
|
|
20
|
+
CreateMultipartUploadCommand: WRITE_OBJECT,
|
|
21
|
+
UploadPartCommand: WRITE_OBJECT,
|
|
22
|
+
CompleteMultipartUploadCommand: WRITE_OBJECT,
|
|
23
|
+
AbortMultipartUploadCommand: WRITE_OBJECT
|
|
22
24
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (built === null) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const ctorExpr = built.getExpression();
|
|
32
|
-
const commandName = N.isPropertyAccessExpression(ctorExpr) ? ctorExpr.getName() : ctorExpr.getText();
|
|
33
|
-
const kind = COMMANDS[commandName];
|
|
34
|
-
if (kind === void 0 || !fromS3Module(ctorExpr, recognizerCtx)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const input = built.getArguments()[0];
|
|
38
|
-
if (input === void 0 || !N.isObjectLiteralExpression(input)) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const key = nameOfProperty(input, "Key", resolve);
|
|
42
|
-
const prefix = nameOfProperty(input, "Prefix", resolve);
|
|
43
|
-
const addressed = key ?? prefix;
|
|
44
|
-
return [
|
|
45
|
-
{
|
|
46
|
-
type: "interaction",
|
|
47
|
-
binding: storageBinding({
|
|
48
|
-
recognition: RECOGNITION,
|
|
49
|
-
storageSystem: "s3",
|
|
50
|
-
transport: "aws-sdk",
|
|
51
|
-
scope: "default",
|
|
52
|
-
container: nameOfProperty(input, "Bucket", resolve),
|
|
53
|
-
accessPath: null
|
|
54
|
-
}),
|
|
55
|
-
callee: callNode.getExpression().getText(),
|
|
56
|
-
interaction: {
|
|
57
|
-
class: "storage-access",
|
|
58
|
-
kind,
|
|
59
|
-
// An object has no fields, so a call says nothing about any.
|
|
60
|
-
fields: [],
|
|
61
|
-
operation: commandName,
|
|
62
|
-
...addressed !== null ? { selector: [addressed] } : {}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
];
|
|
66
|
-
}
|
|
67
|
-
function commandArgument(call, resolve) {
|
|
68
|
-
for (const arg of call.getArguments()) {
|
|
69
|
-
if (N.isNewExpression(arg)) {
|
|
70
|
-
return arg;
|
|
71
|
-
}
|
|
72
|
-
if (!N.isIdentifier(arg) || !typedAsCommand(arg)) {
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const written = resolve(arg);
|
|
76
|
-
if (written !== null && N.isNewExpression(written)) {
|
|
77
|
-
return written;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
function typedAsCommand(value) {
|
|
83
|
-
const declared = value.getType().getSymbol();
|
|
84
|
-
return declared !== void 0 && COMMANDS[declared.getName()] !== void 0;
|
|
85
|
-
}
|
|
86
|
-
function fromS3Module(ctorExpr, ctx) {
|
|
87
|
-
const target = N.isPropertyAccessExpression(ctorExpr) ? rootIdentifier(ctorExpr) : ctorExpr;
|
|
88
|
-
return target !== null && ctx.isImportedFrom(target, COMMAND_MODULE);
|
|
89
|
-
}
|
|
90
|
-
function nameOfProperty(input, name, resolve) {
|
|
91
|
-
const written = property(input, name);
|
|
92
|
-
return written === null ? null : readName(written, { resolve, unsettled: "reference" });
|
|
93
|
-
}
|
|
94
|
-
function property(input, name) {
|
|
95
|
-
if (!N.isObjectLiteralExpression(input)) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
for (const prop of input.getProperties()) {
|
|
99
|
-
if (N.isPropertyAssignment(prop) && prop.getName() === name) {
|
|
100
|
-
return prop.getInitializer() ?? null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
25
|
+
var OBJECT_CALLS = storageCalls({
|
|
26
|
+
system: "s3",
|
|
27
|
+
transport: "aws-sdk",
|
|
28
|
+
client: constructedFrom(COMMAND_MODULE)
|
|
29
|
+
}).about(COMMAND).methods(COMMANDS).container(BUCKET).example('s3.send(new GetObjectCommand({ Bucket: "photos", Key: "a.jpg" }))');
|
|
105
30
|
function s3Framework() {
|
|
106
|
-
return {
|
|
107
|
-
name: "aws-s3",
|
|
108
|
-
protocol: "s3",
|
|
31
|
+
return pack("aws-s3", [OBJECT_CALLS], {
|
|
109
32
|
languages: ["typescript", "javascript"],
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
requiresImport: [COMMAND_MODULE],
|
|
114
|
-
invocationRecognizers: [s3Recognizer]
|
|
115
|
-
};
|
|
33
|
+
recognizedAs: "@suss/framework-aws-s3",
|
|
34
|
+
protocol: "s3"
|
|
35
|
+
});
|
|
116
36
|
}
|
|
117
37
|
var index_default = s3Framework;
|
|
118
38
|
export {
|
package/dist/axios.js
CHANGED
|
@@ -27,7 +27,7 @@ function discoveryForVerb(verb, factories) {
|
|
|
27
27
|
},
|
|
28
28
|
bindingExtraction: {
|
|
29
29
|
method: { type: "literal", value: verb.toUpperCase() },
|
|
30
|
-
path: { type: "
|
|
30
|
+
path: { type: "fromArgument", position: 0 }
|
|
31
31
|
},
|
|
32
32
|
requiresImport: ["axios"]
|
|
33
33
|
}
|
|
@@ -43,7 +43,7 @@ function discoveryForVerb(verb, factories) {
|
|
|
43
43
|
},
|
|
44
44
|
bindingExtraction: {
|
|
45
45
|
method: { type: "literal", value: verb.toUpperCase() },
|
|
46
|
-
path: { type: "
|
|
46
|
+
path: { type: "fromArgument", position: 0 }
|
|
47
47
|
},
|
|
48
48
|
// A bare specifier gates the way "axios" above does: cheap and
|
|
49
49
|
// exact, since two files spelling a package name the same way
|