@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/drizzle.js CHANGED
@@ -2,79 +2,24 @@
2
2
  import { Node as N } from "ts-morph";
3
3
  import { resolveAliasedSymbol } from "@suss/adapter-typescript";
4
4
  import { storageBinding } from "@suss/behavioral-ir";
5
- import { readSqlAccess, sqlFromParts } from "@suss/sql";
5
+ import {
6
+ compile,
7
+ constructedFrom,
8
+ declarationsIn,
9
+ declaredBy,
10
+ sqlStatements
11
+ } from "@suss/recognize";
6
12
  var QUERY_API_METHODS = /* @__PURE__ */ new Set(["findMany", "findFirst"]);
7
13
  var TABLE_FACTORIES = /* @__PURE__ */ new Set(["pgTable", "mysqlTable", "sqliteTable"]);
8
14
  var CHAIN_WALK_LIMIT = 12;
9
- var RAW_METHOD = "execute";
10
- function makeRawRecognizer(opts) {
15
+ function rawStatements(opts) {
11
16
  const storageSystem = opts.storageSystem ?? "postgresql";
12
- const scope = opts.scope ?? "default";
13
- return ((call) => {
14
- const callNode = call;
15
- const callee = callNode.getExpression();
16
- if (!N.isPropertyAccessExpression(callee)) {
17
- return null;
18
- }
19
- if (callee.getName() !== RAW_METHOD) {
20
- return null;
21
- }
22
- const statement = sqlTextOf(callNode.getArguments()[0]);
23
- if (statement === null) {
24
- return null;
25
- }
26
- const accesses = readSqlAccess(statement, { dialect: storageSystem });
27
- if (accesses.length === 0) {
28
- return null;
29
- }
30
- return accesses.map((access) => ({
31
- type: "interaction",
32
- binding: storageBinding({
33
- recognition: "@suss/framework-drizzle",
34
- storageSystem,
35
- scope,
36
- container: access.table
37
- }),
38
- callee: callee.getText(),
39
- interaction: {
40
- class: "storage-access",
41
- kind: access.kind,
42
- fields: access.fields,
43
- ...access.selector.length > 0 ? { selector: access.selector } : {},
44
- operation: callee.getName()
45
- }
46
- }));
47
- });
48
- }
49
- function sqlTextOf(argument) {
50
- if (argument === void 0) {
51
- return null;
52
- }
53
- if (N.isNoSubstitutionTemplateLiteral(argument)) {
54
- return argument.getLiteralValue();
55
- }
56
- if (N.isTaggedTemplateExpression(argument)) {
57
- const template = argument.getTemplate();
58
- if (N.isNoSubstitutionTemplateLiteral(template)) {
59
- return template.getLiteralValue();
60
- }
61
- const spans = template.getTemplateSpans();
62
- return sqlFromParts(
63
- [
64
- template.getHead().getLiteralText(),
65
- ...spans.map((span) => span.getLiteral().getLiteralText())
66
- ],
67
- // A statement that interpolates a table interpolates the schema
68
- // object, so the name it declares is what belongs in the text.
69
- // Everything else is a value, and a parameter is what a value
70
- // would have been.
71
- spans.map((span) => resolveTableName(span.getExpression()))
72
- );
73
- }
74
- if (N.isStringLiteral(argument)) {
75
- return argument.getLiteralValue();
76
- }
77
- return null;
17
+ return sqlStatements({
18
+ system: storageSystem,
19
+ dialect: storageSystem,
20
+ scope: opts.scope ?? "default",
21
+ client: declaredBy("drizzle-orm")
22
+ }).methods({ execute: { statement: { at: 0 } } }).interpolating({ from: constructedFrom("drizzle-orm"), named: { at: 0 } }).example("db.execute(sql`SELECT id, email FROM users`)");
78
23
  }
79
24
  function makeRecognizer(opts) {
80
25
  const storageSystem = opts.storageSystem ?? "postgresql";
@@ -360,6 +305,7 @@ function selectorFromWhere(whereCall, tableExprText) {
360
305
  return columns.size > 0 ? [...columns] : null;
361
306
  }
362
307
  function drizzleFramework(options = {}) {
308
+ const raw = rawStatements(options);
363
309
  return {
364
310
  name: "drizzle",
365
311
  protocol: "in-process",
@@ -371,10 +317,11 @@ function drizzleFramework(options = {}) {
371
317
  // drizzle-orm/pg-core and driver entry points): files without
372
318
  // them can't type-check as Drizzle receivers anyway.
373
319
  requiresImport: ["drizzle-orm"],
374
- invocationRecognizers: [
375
- makeRecognizer(options),
376
- makeRawRecognizer(options)
377
- ]
320
+ invocationRecognizers: [makeRecognizer(options)],
321
+ // A statement can be written as a tagged template, which the
322
+ // invocation walk never reaches.
323
+ accessRecognizers: [compile(raw.declared, "@suss/framework-drizzle")],
324
+ declarations: declarationsIn([raw])
378
325
  };
379
326
  }
380
327
  var index_default = drizzleFramework;
package/dist/fastapi.js CHANGED
@@ -30,6 +30,7 @@ function fastapiFramework(options = {}) {
30
30
  routerComposition: {
31
31
  routerConstructorName: "APIRouter",
32
32
  includeMethodName: "include_router",
33
+ routerKeyword: "router",
33
34
  prefixKeyword: "prefix"
34
35
  }
35
36
  }
package/dist/fetch.js CHANGED
@@ -19,7 +19,7 @@ function webFetchPack() {
19
19
  property: "method",
20
20
  default: "GET"
21
21
  },
22
- path: { type: "fromArgumentLiteral", position: 0 }
22
+ path: { type: "fromArgument", position: 0 }
23
23
  },
24
24
  // No import gate: `fetch` is a global. Walk every file,
25
25
  // the discovery dispatch is itself cheap (just looks for
package/dist/gcs.js CHANGED
@@ -1,132 +1,53 @@
1
1
  // ../framework/gcs/dist/index.js
2
- import { Node as N } from "ts-morph";
3
- import { methodDeclaredIn, readName } from "@suss/adapter-typescript";
4
- import { storageBinding } from "@suss/behavioral-ir";
5
- var RECOGNITION = "@suss/framework-gcs";
2
+ import { declaredBy, pack, storageCalls } from "@suss/recognize";
6
3
  var CLIENT_MODULE = "@google-cloud/storage";
7
- var OPERATIONS = {
8
- download: "read",
9
- createReadStream: "read",
10
- getMetadata: "read",
11
- exists: "read",
12
- isPublic: "read",
13
- getFiles: "read",
14
- save: "write",
15
- upload: "write",
16
- createWriteStream: "write",
17
- delete: "write",
18
- copy: "write",
19
- move: "write",
20
- rename: "write",
21
- setMetadata: "write",
22
- makePublic: "write",
23
- makePrivate: "write"
4
+ var BUCKET_STEP = { to: "receiver", method: "bucket" };
5
+ var FILE_STEP = { to: "receiver", method: "file" };
6
+ var OBJECT = { of: [FILE_STEP], at: 0 };
7
+ var BUCKET = { of: [BUCKET_STEP], at: 0 };
8
+ var READ = { kind: "read", selector: OBJECT };
9
+ var WRITE = { kind: "write", selector: OBJECT };
10
+ var SIGNED_URL = {
11
+ kind: {
12
+ asks: { at: 0, property: ["action"] },
13
+ means: {
14
+ read: "read",
15
+ write: "write",
16
+ delete: "write",
17
+ resumable: "write"
18
+ },
19
+ otherwise: "read"
20
+ },
21
+ selector: OBJECT
24
22
  };
25
- var SIGNED_URL = "getSignedUrl";
26
- var SIGNED_ACTIONS = {
27
- read: "read",
28
- write: "write",
29
- delete: "write",
30
- resumable: "write"
23
+ var OPERATIONS = {
24
+ download: READ,
25
+ createReadStream: READ,
26
+ getMetadata: READ,
27
+ exists: READ,
28
+ isPublic: READ,
29
+ getFiles: READ,
30
+ save: WRITE,
31
+ upload: WRITE,
32
+ createWriteStream: WRITE,
33
+ delete: WRITE,
34
+ copy: WRITE,
35
+ move: WRITE,
36
+ rename: WRITE,
37
+ setMetadata: WRITE,
38
+ makePublic: WRITE,
39
+ makePrivate: WRITE,
40
+ getSignedUrl: SIGNED_URL
31
41
  };
32
- var BUCKET_STEP = "bucket";
33
- var FILE_STEP = "file";
34
- function gcsRecognizer(call, ctx) {
35
- const callNode = call;
36
- const resolve = ctx.resolveWrittenValue ?? (() => null);
37
- const callee = callNode.getExpression();
38
- if (!N.isPropertyAccessExpression(callee)) {
39
- return null;
40
- }
41
- const operation = callee.getName();
42
- const kind = kindOf(operation, callNode, resolve);
43
- if (kind === null || !methodDeclaredIn(callee, CLIENT_MODULE)) {
44
- return null;
45
- }
46
- const chain = walkChain(callee.getExpression(), resolve);
47
- return [
48
- {
49
- type: "interaction",
50
- binding: storageBinding({
51
- recognition: RECOGNITION,
52
- storageSystem: "gcs",
53
- scope: "default",
54
- container: chain.bucket,
55
- accessPath: null
56
- }),
57
- callee: callee.getText(),
58
- interaction: {
59
- class: "storage-access",
60
- kind,
61
- // An object has no fields, so a call says nothing about any.
62
- fields: [],
63
- operation,
64
- ...chain.object !== null ? { selector: [chain.object] } : {}
65
- }
66
- }
67
- ];
68
- }
69
- function kindOf(operation, call, resolve) {
70
- if (operation !== SIGNED_URL) {
71
- return OPERATIONS[operation] ?? null;
72
- }
73
- const config = call.getArguments()[0];
74
- const asked = config === void 0 ? null : property(config, "action");
75
- const action = asked === null ? null : readName(asked, { resolve });
76
- return action === null ? "read" : SIGNED_ACTIONS[action] ?? "read";
77
- }
78
- function walkChain(subject, resolve) {
79
- let step = subject;
80
- const found = { bucket: null, object: null };
81
- for (let hops = 0; step !== null && hops < MAX_CHAIN_STEPS; hops++) {
82
- if (N.isIdentifier(step) || N.isPropertyAccessExpression(step)) {
83
- const written = resolve(step);
84
- step = written === step ? null : written;
85
- continue;
86
- }
87
- if (!N.isCallExpression(step)) {
88
- return found;
89
- }
90
- const callee = step.getExpression();
91
- if (!N.isPropertyAccessExpression(callee)) {
92
- return found;
93
- }
94
- const named = callee.getName();
95
- const argument = step.getArguments()[0];
96
- if (named === FILE_STEP && found.object === null) {
97
- found.object = argument === void 0 ? null : readName(argument, { resolve, unsettled: "reference" });
98
- }
99
- if (named === BUCKET_STEP && found.bucket === null) {
100
- found.bucket = argument === void 0 ? null : readName(argument, { resolve, unsettled: "reference" });
101
- return found;
102
- }
103
- step = callee.getExpression();
104
- }
105
- return found;
106
- }
107
- var MAX_CHAIN_STEPS = 8;
108
- function property(input, name) {
109
- if (!N.isObjectLiteralExpression(input)) {
110
- return null;
111
- }
112
- for (const prop of input.getProperties()) {
113
- if (N.isPropertyAssignment(prop) && prop.getName() === name) {
114
- return prop.getInitializer() ?? null;
115
- }
116
- }
117
- return null;
118
- }
42
+ var CHAIN_CALLS = storageCalls({
43
+ system: "gcs",
44
+ client: declaredBy(CLIENT_MODULE)
45
+ }).methods(OPERATIONS).container(BUCKET).example('storage.bucket("uploads").file("reports/a.pdf").download()');
119
46
  function gcsFramework() {
120
- return {
121
- name: "gcs",
122
- protocol: "gcs",
47
+ return pack("gcs", [CHAIN_CALLS], {
123
48
  languages: ["typescript", "javascript"],
124
- discovery: [],
125
- terminals: [],
126
- inputMapping: { type: "positionalParams", params: [] },
127
- requiresImport: [CLIENT_MODULE],
128
- invocationRecognizers: [gcsRecognizer]
129
- };
49
+ recognizedAs: "@suss/framework-gcs"
50
+ });
130
51
  }
131
52
  var index_default = gcsFramework;
132
53
  export {