@suss/packs 0.12.0 → 0.13.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/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/mongoose.js
CHANGED
|
@@ -1,377 +1,156 @@
|
|
|
1
1
|
// ../framework/mongoose/dist/index.js
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
updateMany: { kind: "write", filterArg: 0, updateArg: 1 },
|
|
20
|
-
replaceOne: { kind: "write", filterArg: 0, payloadArg: 1 },
|
|
21
|
-
deleteOne: { kind: "write", filterArg: 0 },
|
|
22
|
-
deleteMany: { kind: "write", filterArg: 0 },
|
|
23
|
-
findOneAndUpdate: { kind: "write", filterArg: 0, updateArg: 1 },
|
|
24
|
-
findByIdAndUpdate: { kind: "write", idArg: 0, updateArg: 1 },
|
|
25
|
-
findOneAndDelete: { kind: "write", filterArg: 0 },
|
|
26
|
-
findByIdAndDelete: { kind: "write", idArg: 0 },
|
|
27
|
-
findOneAndReplace: { kind: "write", filterArg: 0, payloadArg: 1 }
|
|
3
|
+
constructedFrom,
|
|
4
|
+
declaredBy,
|
|
5
|
+
pack,
|
|
6
|
+
storageCalls
|
|
7
|
+
} from "@suss/recognize";
|
|
8
|
+
var CLIENT_MODULE = "mongoose";
|
|
9
|
+
var WHOLE_DOCUMENT = ["*"];
|
|
10
|
+
var BY_ID = ["_id"];
|
|
11
|
+
var FILTER_KEYS = ({ input }) => keysOf(input);
|
|
12
|
+
var PROJECTED = ({ input }) => {
|
|
13
|
+
const written = input.text();
|
|
14
|
+
if (written !== null) {
|
|
15
|
+
return namedInProjection(written);
|
|
16
|
+
}
|
|
17
|
+
const asked = keysOf(input, asksForIt);
|
|
18
|
+
return asked.length > 0 ? asked : WHOLE_DOCUMENT;
|
|
28
19
|
};
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
if (/(s|x|z|ch|sh)$/.test(lower)) {
|
|
35
|
-
return `${lower}es`;
|
|
36
|
-
}
|
|
37
|
-
return `${lower}s`;
|
|
38
|
-
}
|
|
39
|
-
function resolveModelIdentity(node, resolve) {
|
|
40
|
-
if (N.isCallExpression(node)) {
|
|
41
|
-
return modelIdentityFromModelCall(node, resolve);
|
|
42
|
-
}
|
|
43
|
-
if (!N.isIdentifier(node)) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const symbol = node.getSymbol();
|
|
47
|
-
if (symbol === void 0) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
for (const decl of symbol.getDeclarations()) {
|
|
51
|
-
const identity = modelIdentityFromDeclaration(decl, resolve);
|
|
52
|
-
if (identity !== null) {
|
|
53
|
-
return identity;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
function modelIdentityFromDeclaration(decl, resolve) {
|
|
59
|
-
if (N.isImportSpecifier(decl)) {
|
|
60
|
-
const symbol = decl.getNameNode().getSymbol();
|
|
61
|
-
for (const target of symbol?.getAliasedSymbol()?.getDeclarations() ?? []) {
|
|
62
|
-
const identity = modelIdentityFromDeclaration(target, resolve);
|
|
63
|
-
if (identity !== null) {
|
|
64
|
-
return identity;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
if (!N.isVariableDeclaration(decl)) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const init = decl.getInitializer();
|
|
73
|
-
if (init === void 0 || !N.isCallExpression(init)) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
return modelIdentityFromModelCall(init, resolve);
|
|
77
|
-
}
|
|
78
|
-
function modelIdentityFromModelCall(call, resolve) {
|
|
79
|
-
const callee = call.getExpression();
|
|
80
|
-
if (!isModelFactoryCall(callee, resolve)) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
const args = call.getArguments();
|
|
84
|
-
const modelName = literalString(args[0]);
|
|
85
|
-
if (modelName === null) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
const explicitCollection = literalString(args[2]);
|
|
89
|
-
const schemaCollection = explicitCollection === null ? collectionFromSchemaArg(args[1]) : null;
|
|
90
|
-
const collection = explicitCollection ?? schemaCollection ?? defaultCollectionName(modelName);
|
|
91
|
-
return { modelName, collection };
|
|
92
|
-
}
|
|
93
|
-
function isModelFactoryCall(callee, resolve) {
|
|
94
|
-
if (N.isPropertyAccessExpression(callee)) {
|
|
95
|
-
return callee.getName() === "model" && methodDeclaredIn(callee, "mongoose", resolve);
|
|
96
|
-
}
|
|
97
|
-
return N.isIdentifier(callee) && isImportedAs(callee, "mongoose", "model");
|
|
98
|
-
}
|
|
99
|
-
function isImportedAs(identifier, module, exportName) {
|
|
100
|
-
const symbol = identifier.getSymbol();
|
|
101
|
-
if (symbol === void 0) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
for (const decl of symbol.getDeclarations()) {
|
|
105
|
-
if (N.isImportSpecifier(decl) && decl.getName() === exportName && decl.getImportDeclaration().getModuleSpecifierValue() === module) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
function collectionFromSchemaArg(schemaArg) {
|
|
112
|
-
if (schemaArg === void 0) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
const ctor = schemaConstructorOf(schemaArg);
|
|
116
|
-
const optionsArg = ctor?.getArguments()[1];
|
|
117
|
-
if (optionsArg === void 0 || !N.isObjectLiteralExpression(optionsArg)) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
for (const prop of optionsArg.getProperties()) {
|
|
121
|
-
if (N.isPropertyAssignment(prop) && prop.getName() === "collection") {
|
|
122
|
-
return literalString(prop.getInitializer());
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
function schemaConstructorOf(node) {
|
|
128
|
-
if (N.isNewExpression(node)) {
|
|
129
|
-
return node;
|
|
130
|
-
}
|
|
131
|
-
if (!N.isIdentifier(node)) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
const symbol = node.getSymbol();
|
|
135
|
-
for (const decl of symbol?.getDeclarations() ?? []) {
|
|
136
|
-
if (!N.isVariableDeclaration(decl)) {
|
|
20
|
+
var UPDATED = ({ input }) => {
|
|
21
|
+
const touched = /* @__PURE__ */ new Set();
|
|
22
|
+
for (const entry of input.entries("nothing")) {
|
|
23
|
+
if (entry.key === null) {
|
|
137
24
|
continue;
|
|
138
25
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return init;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
function resolveDocumentModelIdentity(node, resolve) {
|
|
147
|
-
if (N.isNewExpression(node)) {
|
|
148
|
-
return resolveModelIdentity(node.getExpression(), resolve);
|
|
149
|
-
}
|
|
150
|
-
if (N.isAwaitExpression(node) || N.isParenthesizedExpression(node)) {
|
|
151
|
-
return resolveDocumentModelIdentity(node.getExpression(), resolve);
|
|
152
|
-
}
|
|
153
|
-
if (N.isCallExpression(node)) {
|
|
154
|
-
const callee = node.getExpression();
|
|
155
|
-
if (!N.isPropertyAccessExpression(callee) || !(callee.getName() in METHODS)) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
return resolveModelIdentity(callee.getExpression(), resolve);
|
|
159
|
-
}
|
|
160
|
-
if (!N.isIdentifier(node)) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
const symbol = node.getSymbol();
|
|
164
|
-
for (const decl of symbol?.getDeclarations() ?? []) {
|
|
165
|
-
if (!N.isVariableDeclaration(decl)) {
|
|
26
|
+
if (!entry.key.startsWith(OPERATOR_PREFIX)) {
|
|
27
|
+
touched.add(entry.key);
|
|
166
28
|
continue;
|
|
167
29
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
if (identity !== null) {
|
|
171
|
-
return identity;
|
|
30
|
+
for (const name of keysOf(entry.value)) {
|
|
31
|
+
touched.add(name);
|
|
172
32
|
}
|
|
173
33
|
}
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
function readObjectArg(arg) {
|
|
183
|
-
if (arg === null || arg === void 0 || typeof arg !== "object") {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
return arg.kind === "object" ? arg : null;
|
|
187
|
-
}
|
|
188
|
-
function isTruthyLiteral(value) {
|
|
189
|
-
if (value === null || typeof value !== "object") {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
if (value.kind === "number") {
|
|
193
|
-
return value.value !== 0;
|
|
194
|
-
}
|
|
195
|
-
return value.kind === "boolean" && value.value;
|
|
196
|
-
}
|
|
197
|
-
function projectionFromString(text) {
|
|
198
|
-
const included = text.trim().split(/\s+/).filter((term) => term.length > 0 && !term.startsWith("-")).map((term) => term.replace(/^\+/, ""));
|
|
199
|
-
return included.length > 0 ? included : ["*"];
|
|
200
|
-
}
|
|
201
|
-
function projectionFields(arg) {
|
|
202
|
-
if (arg !== null && typeof arg === "object" && arg.kind === "string") {
|
|
203
|
-
return projectionFromString(arg.value);
|
|
204
|
-
}
|
|
205
|
-
const object = readObjectArg(arg);
|
|
206
|
-
if (object === null) {
|
|
207
|
-
return ["*"];
|
|
208
|
-
}
|
|
209
|
-
const included = Object.entries(object.fields).filter(([, value]) => isTruthyLiteral(value)).map(([key]) => key);
|
|
210
|
-
return included.length > 0 ? included : ["*"];
|
|
211
|
-
}
|
|
212
|
-
function updateFields(arg) {
|
|
213
|
-
const object = readObjectArg(arg);
|
|
214
|
-
if (object === null) {
|
|
215
|
-
return ["*"];
|
|
34
|
+
return touched.size > 0 ? [...touched] : WHOLE_DOCUMENT;
|
|
35
|
+
};
|
|
36
|
+
var PAYLOAD = ({ input }) => {
|
|
37
|
+
const documents = input.items();
|
|
38
|
+
if (documents.length === 0) {
|
|
39
|
+
const written = keysOf(input);
|
|
40
|
+
return written.length > 0 ? written : WHOLE_DOCUMENT;
|
|
216
41
|
}
|
|
217
|
-
const
|
|
218
|
-
for (const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
42
|
+
const union = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const document of documents) {
|
|
44
|
+
const written = keysOf(document);
|
|
45
|
+
if (written.length === 0) {
|
|
46
|
+
return WHOLE_DOCUMENT;
|
|
222
47
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
fields.add(inner);
|
|
48
|
+
for (const name of written) {
|
|
49
|
+
union.add(name);
|
|
226
50
|
}
|
|
227
51
|
}
|
|
228
|
-
return
|
|
52
|
+
return [...union];
|
|
53
|
+
};
|
|
54
|
+
var OPERATOR_PREFIX = "$";
|
|
55
|
+
function asksForIt(value) {
|
|
56
|
+
return value.flag() === true;
|
|
229
57
|
}
|
|
230
|
-
function
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
if (arg === null || arg === void 0 || typeof arg !== "object" || arg.kind !== "array") {
|
|
237
|
-
return ["*"];
|
|
238
|
-
}
|
|
239
|
-
const union = /* @__PURE__ */ new Set();
|
|
240
|
-
for (const item of arg.items) {
|
|
241
|
-
const row = readObjectArg(item);
|
|
242
|
-
if (row === null) {
|
|
243
|
-
return ["*"];
|
|
244
|
-
}
|
|
245
|
-
for (const key of Object.keys(row.fields)) {
|
|
246
|
-
union.add(key);
|
|
58
|
+
function keysOf(value, keep = () => true) {
|
|
59
|
+
const found = [];
|
|
60
|
+
for (const entry of value.entries("nothing")) {
|
|
61
|
+
if (entry.key !== null && keep(entry.value)) {
|
|
62
|
+
found.push(entry.key);
|
|
247
63
|
}
|
|
248
64
|
}
|
|
249
|
-
return
|
|
65
|
+
return found;
|
|
250
66
|
}
|
|
251
|
-
function
|
|
252
|
-
|
|
67
|
+
function namedInProjection(written) {
|
|
68
|
+
const asked = written.trim().split(/\s+/).filter((term) => term.length > 0 && !term.startsWith("-")).map((term) => term.replace(/^\+/, ""));
|
|
69
|
+
return asked.length > 0 ? asked : WHOLE_DOCUMENT;
|
|
253
70
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
71
|
+
var filter = (at) => ({ of: { at }, by: FILTER_KEYS });
|
|
72
|
+
var projection = (at) => ({ of: { at }, by: PROJECTED });
|
|
73
|
+
var update = (at) => ({ of: { at }, by: UPDATED });
|
|
74
|
+
var payload = (at) => ({ of: { at }, by: PAYLOAD });
|
|
75
|
+
var METHODS = {
|
|
76
|
+
find: { kind: "read", selector: filter(0), fields: projection(1) },
|
|
77
|
+
findOne: { kind: "read", selector: filter(0), fields: projection(1) },
|
|
78
|
+
findById: { kind: "read", selector: BY_ID, fields: projection(1) },
|
|
79
|
+
countDocuments: { kind: "read", selector: filter(0) },
|
|
80
|
+
exists: { kind: "read", selector: filter(0) },
|
|
81
|
+
distinct: { kind: "read", selector: filter(1), fields: { at: 0 } },
|
|
82
|
+
create: { kind: "write", fields: payload(0) },
|
|
83
|
+
insertMany: { kind: "write", fields: payload(0) },
|
|
84
|
+
updateOne: { kind: "write", selector: filter(0), fields: update(1) },
|
|
85
|
+
updateMany: { kind: "write", selector: filter(0), fields: update(1) },
|
|
86
|
+
replaceOne: { kind: "write", selector: filter(0), fields: payload(1) },
|
|
87
|
+
deleteOne: { kind: "write", selector: filter(0), fields: WHOLE_DOCUMENT },
|
|
88
|
+
deleteMany: { kind: "write", selector: filter(0), fields: WHOLE_DOCUMENT },
|
|
89
|
+
findOneAndUpdate: { kind: "write", selector: filter(0), fields: update(1) },
|
|
90
|
+
findByIdAndUpdate: { kind: "write", selector: BY_ID, fields: update(1) },
|
|
91
|
+
findOneAndDelete: {
|
|
92
|
+
kind: "write",
|
|
93
|
+
selector: filter(0),
|
|
94
|
+
fields: WHOLE_DOCUMENT
|
|
95
|
+
},
|
|
96
|
+
findByIdAndDelete: { kind: "write", selector: BY_ID, fields: WHOLE_DOCUMENT },
|
|
97
|
+
findOneAndReplace: { kind: "write", selector: filter(0), fields: payload(1) },
|
|
98
|
+
// A document can be changed after it was built, which this does not
|
|
99
|
+
// track, so a save is not reported as touching the fields the
|
|
100
|
+
// constructor happened to state.
|
|
101
|
+
save: { kind: "write", fields: WHOLE_DOCUMENT }
|
|
102
|
+
};
|
|
103
|
+
var MODEL_FACTORY = "model";
|
|
104
|
+
function collectionOf(_selector, call) {
|
|
105
|
+
const model = modelCallIn(call);
|
|
106
|
+
const modelName = model?.nameAt(0, "nothing") ?? null;
|
|
107
|
+
if (model === null || modelName === null) {
|
|
108
|
+
return null;
|
|
266
109
|
}
|
|
267
|
-
return
|
|
110
|
+
return model.nameAt(2, "nothing") ?? schemaCollectionOf(model) ?? pluralized(modelName);
|
|
268
111
|
}
|
|
269
|
-
function
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
if (spec.filterArg === void 0) {
|
|
112
|
+
function modelCallIn(call) {
|
|
113
|
+
const receiver = call.receiver();
|
|
114
|
+
if (receiver === null) {
|
|
274
115
|
return null;
|
|
275
116
|
}
|
|
276
|
-
|
|
277
|
-
|
|
117
|
+
return modelFactoryCall(receiver) ?? modelFactoryCall(receiver.callee()) ?? modelFactoryCall(receiver.receiver());
|
|
118
|
+
}
|
|
119
|
+
function modelFactoryCall(call) {
|
|
120
|
+
if (call === null) {
|
|
278
121
|
return null;
|
|
279
122
|
}
|
|
280
|
-
const
|
|
281
|
-
|
|
123
|
+
const named = call.method() ?? call.calleeText();
|
|
124
|
+
const fromLibrary = call.isFrom(constructedFrom(CLIENT_MODULE));
|
|
125
|
+
return named === MODEL_FACTORY && fromLibrary ? call : null;
|
|
282
126
|
}
|
|
283
|
-
function
|
|
284
|
-
return
|
|
285
|
-
type: "interaction",
|
|
286
|
-
binding: storageBinding({
|
|
287
|
-
recognition: RECOGNITION,
|
|
288
|
-
storageSystem: STORAGE_SYSTEM,
|
|
289
|
-
scope: opts.scope,
|
|
290
|
-
container: opts.collection
|
|
291
|
-
}),
|
|
292
|
-
callee: opts.calleeText,
|
|
293
|
-
interaction: {
|
|
294
|
-
class: "storage-access",
|
|
295
|
-
kind: opts.kind,
|
|
296
|
-
fields: opts.fields,
|
|
297
|
-
...opts.selector !== null ? { selector: opts.selector } : {},
|
|
298
|
-
operation: opts.operation
|
|
299
|
-
}
|
|
300
|
-
};
|
|
127
|
+
function schemaCollectionOf(model) {
|
|
128
|
+
return model.argument(1)?.propertyAt(1, "collection", "nothing") ?? null;
|
|
301
129
|
}
|
|
302
|
-
function
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const method = callee.getName();
|
|
312
|
-
const spec = METHODS[method];
|
|
313
|
-
if (spec === void 0 || !methodDeclaredIn(callee, "mongoose", resolve)) {
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
const identity = resolveModelIdentity(callee.getExpression(), resolve);
|
|
317
|
-
const args = recognizerCtx.extractArgs?.() ?? [];
|
|
318
|
-
return [
|
|
319
|
-
buildAccess({
|
|
320
|
-
scope,
|
|
321
|
-
collection: identity?.collection ?? null,
|
|
322
|
-
calleeText: callee.getText(),
|
|
323
|
-
operation: method,
|
|
324
|
-
kind: spec.kind,
|
|
325
|
-
fields: fieldsOf(spec, args),
|
|
326
|
-
selector: selectorOf(spec, args)
|
|
327
|
-
})
|
|
328
|
-
];
|
|
329
|
-
};
|
|
130
|
+
function pluralized(modelName) {
|
|
131
|
+
const lower = modelName.toLowerCase();
|
|
132
|
+
if (/[^aeiou]y$/.test(lower)) {
|
|
133
|
+
return `${lower.slice(0, -1)}ies`;
|
|
134
|
+
}
|
|
135
|
+
if (/(s|x|z|ch|sh)$/.test(lower)) {
|
|
136
|
+
return `${lower}es`;
|
|
137
|
+
}
|
|
138
|
+
return `${lower}s`;
|
|
330
139
|
}
|
|
331
|
-
function
|
|
332
|
-
return (
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return null;
|
|
339
|
-
}
|
|
340
|
-
if (!methodDeclaredIn(callee, "mongoose", resolve)) {
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
const identity = resolveDocumentModelIdentity(
|
|
344
|
-
callee.getExpression(),
|
|
345
|
-
resolve
|
|
346
|
-
);
|
|
347
|
-
return [
|
|
348
|
-
buildAccess({
|
|
349
|
-
scope,
|
|
350
|
-
collection: identity?.collection ?? null,
|
|
351
|
-
calleeText: callee.getText(),
|
|
352
|
-
operation: "save",
|
|
353
|
-
kind: "write",
|
|
354
|
-
fields: ["*"],
|
|
355
|
-
selector: null
|
|
356
|
-
})
|
|
357
|
-
];
|
|
358
|
-
};
|
|
140
|
+
function modelCalls(scope) {
|
|
141
|
+
return storageCalls({
|
|
142
|
+
system: "mongodb",
|
|
143
|
+
scope,
|
|
144
|
+
client: declaredBy(CLIENT_MODULE),
|
|
145
|
+
unsettledName: "nothing"
|
|
146
|
+
}).methods(METHODS).container(collectionOf).example('User.find({ email: "a@b.c" }, { name: 1 })');
|
|
359
147
|
}
|
|
360
148
|
function mongooseFramework(options = {}) {
|
|
361
|
-
|
|
362
|
-
return {
|
|
363
|
-
name: "mongoose",
|
|
364
|
-
protocol: "in-process",
|
|
149
|
+
return pack("mongoose", [modelCalls(options.scope ?? "default")], {
|
|
365
150
|
languages: ["typescript", "javascript"],
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
requiresImport: ["mongoose"],
|
|
370
|
-
invocationRecognizers: [
|
|
371
|
-
makeStaticRecognizer(scope),
|
|
372
|
-
makeSaveRecognizer(scope)
|
|
373
|
-
]
|
|
374
|
-
};
|
|
151
|
+
recognizedAs: "@suss/framework-mongoose",
|
|
152
|
+
protocol: "in-process"
|
|
153
|
+
});
|
|
375
154
|
}
|
|
376
155
|
var index_default = mongooseFramework;
|
|
377
156
|
export {
|
package/dist/prisma.js
CHANGED
|
@@ -3,13 +3,12 @@ import {
|
|
|
3
3
|
Node as N
|
|
4
4
|
} from "ts-morph";
|
|
5
5
|
import { storageBinding } from "@suss/behavioral-ir";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
]);
|
|
6
|
+
import {
|
|
7
|
+
compile,
|
|
8
|
+
declarationsIn,
|
|
9
|
+
declaredBy,
|
|
10
|
+
sqlStatements
|
|
11
|
+
} from "@suss/recognize";
|
|
13
12
|
var PRISMA_READ_METHODS = /* @__PURE__ */ new Set([
|
|
14
13
|
"findUnique",
|
|
15
14
|
"findFirst",
|
|
@@ -360,74 +359,23 @@ function extractSelector(optionsArg) {
|
|
|
360
359
|
const keys = Object.keys(where.fields);
|
|
361
360
|
return keys.length > 0 ? keys : null;
|
|
362
361
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
return (
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
binding: storageBinding({
|
|
378
|
-
recognition: "@suss/framework-prisma",
|
|
379
|
-
storageSystem,
|
|
380
|
-
scope,
|
|
381
|
-
container: access.table
|
|
382
|
-
}),
|
|
383
|
-
callee: statement.callee,
|
|
384
|
-
interaction: {
|
|
385
|
-
class: "storage-access",
|
|
386
|
-
kind: access.kind,
|
|
387
|
-
fields: access.fields,
|
|
388
|
-
...access.selector.length > 0 ? { selector: access.selector } : {},
|
|
389
|
-
operation: statement.method
|
|
390
|
-
}
|
|
391
|
-
}));
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
function rawStatementAt(node) {
|
|
395
|
-
const tag = N.isTaggedTemplateExpression(node) ? node.getTag() : N.isCallExpression(node) ? node.getExpression() : null;
|
|
396
|
-
if (tag === null || !N.isPropertyAccessExpression(tag)) {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
const method = tag.getName();
|
|
400
|
-
if (!RAW_METHODS.has(method)) {
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
if (!isPrismaClientReceiver(tag.getExpression())) {
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
const sql = N.isTaggedTemplateExpression(node) ? templateSql(node.getTemplate()) : N.isCallExpression(node) ? literalSql(node.getArguments()[0]) : null;
|
|
407
|
-
return sql === null ? null : { sql, method, callee: tag.getText() };
|
|
408
|
-
}
|
|
409
|
-
function templateSql(template) {
|
|
410
|
-
if (N.isNoSubstitutionTemplateLiteral(template)) {
|
|
411
|
-
return template.getLiteralValue();
|
|
412
|
-
}
|
|
413
|
-
if (!N.isTemplateExpression(template)) {
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
return sqlFromParts([
|
|
417
|
-
template.getHead().getLiteralText(),
|
|
418
|
-
...template.getTemplateSpans().map((span) => span.getLiteral().getLiteralText())
|
|
419
|
-
]);
|
|
420
|
-
}
|
|
421
|
-
function literalSql(argument) {
|
|
422
|
-
if (argument === void 0) {
|
|
423
|
-
return null;
|
|
424
|
-
}
|
|
425
|
-
if (N.isStringLiteral(argument) || N.isNoSubstitutionTemplateLiteral(argument)) {
|
|
426
|
-
return argument.getLiteralValue();
|
|
427
|
-
}
|
|
428
|
-
return N.isTemplateExpression(argument) ? templateSql(argument) : null;
|
|
362
|
+
var STATEMENT = { statement: { at: 0 } };
|
|
363
|
+
function rawStatements(options) {
|
|
364
|
+
const provider = options.storageSystem ?? "postgresql";
|
|
365
|
+
return sqlStatements({
|
|
366
|
+
system: provider,
|
|
367
|
+
dialect: provider,
|
|
368
|
+
scope: options.scope ?? "default",
|
|
369
|
+
client: declaredBy("@prisma/client", ".prisma/client")
|
|
370
|
+
}).methods({
|
|
371
|
+
$queryRaw: STATEMENT,
|
|
372
|
+
$executeRaw: STATEMENT,
|
|
373
|
+
$queryRawUnsafe: STATEMENT,
|
|
374
|
+
$executeRawUnsafe: STATEMENT
|
|
375
|
+
}).example('prisma.$queryRawUnsafe("SELECT id, email FROM users")');
|
|
429
376
|
}
|
|
430
377
|
function prismaFramework(options = {}) {
|
|
378
|
+
const raw = rawStatements(options);
|
|
431
379
|
return {
|
|
432
380
|
name: "prisma",
|
|
433
381
|
protocol: "in-process",
|
|
@@ -439,7 +387,10 @@ function prismaFramework(options = {}) {
|
|
|
439
387
|
// recognizer's type-resolution check would reject them anyway.
|
|
440
388
|
requiresImport: ["@prisma/client"],
|
|
441
389
|
invocationRecognizers: [makeRecognizer(options)],
|
|
442
|
-
|
|
390
|
+
// A tagged template is not an invocation, so the raw chain runs on
|
|
391
|
+
// the access walk, which visits calls as well.
|
|
392
|
+
accessRecognizers: [compile(raw.declared, "@suss/framework-prisma")],
|
|
393
|
+
declarations: declarationsIn([raw])
|
|
443
394
|
};
|
|
444
395
|
}
|
|
445
396
|
var index_default = prismaFramework;
|
package/dist/react-router.js
CHANGED