sst-http 1.3.2 → 1.3.3-beta.2

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/cli.cjs CHANGED
@@ -7,7 +7,7 @@ var import_node_path = require("path");
7
7
  var import_node_process = require("process");
8
8
  var import_ts_morph = require("ts-morph");
9
9
 
10
- // src/paths.ts
10
+ // src/http/paths.ts
11
11
  var API_GATEWAY_PARAM_RE = /(^|\/):([A-Za-z0-9_]+(?:[+*])?)(?=\/|$)/g;
12
12
  function normalizeApiGatewayPath(path) {
13
13
  return path.replace(API_GATEWAY_PARAM_RE, (_match, prefix, name) => `${prefix}{${name}}`);
@@ -49,7 +49,8 @@ async function runScan(args) {
49
49
  options.globs.push("src/**/*.ts");
50
50
  }
51
51
  project.addSourceFilesAtPaths(options.globs);
52
- const manifest = { routes: [] };
52
+ const routes = [];
53
+ const events = [];
53
54
  for (const sourceFile of project.getSourceFiles()) {
54
55
  for (const fn of sourceFile.getFunctions()) {
55
56
  if (!fn.isExported() && !fn.isDefaultExport()) {
@@ -57,7 +58,11 @@ async function runScan(args) {
57
58
  }
58
59
  const route = extractRoute(fn, options.inferName);
59
60
  if (route) {
60
- manifest.routes.push(route);
61
+ routes.push(route);
62
+ }
63
+ const foundEvents = extractEvents(fn);
64
+ if (foundEvents.length > 0) {
65
+ events.push(...foundEvents);
61
66
  }
62
67
  }
63
68
  for (const cls of sourceFile.getClasses()) {
@@ -70,17 +75,30 @@ async function runScan(args) {
70
75
  }
71
76
  const route = extractRoute(method, options.inferName);
72
77
  if (route) {
73
- manifest.routes.push(route);
78
+ routes.push(route);
79
+ }
80
+ const foundEvents = extractEvents(method);
81
+ if (foundEvents.length > 0) {
82
+ events.push(...foundEvents);
74
83
  }
75
84
  }
76
85
  }
77
86
  }
78
- manifest.routes.sort((a, b) => {
87
+ routes.sort((a, b) => {
79
88
  if (a.path === b.path) {
80
89
  return a.method.localeCompare(b.method);
81
90
  }
82
91
  return a.path.localeCompare(b.path);
83
92
  });
93
+ if (events.length > 0) {
94
+ events.sort((a, b) => {
95
+ return a.event.localeCompare(b.event);
96
+ });
97
+ }
98
+ const manifest = { routes };
99
+ if (events.length > 0) {
100
+ manifest.events = events;
101
+ }
84
102
  const outPath = (0, import_node_path.resolve)((0, import_node_process.cwd)(), options.outFile);
85
103
  (0, import_node_fs.writeFileSync)(outPath, JSON.stringify(manifest, null, 2));
86
104
  import_node_process.stdout.write(`Wrote ${manifest.routes.length} route(s) to ${outPath}
@@ -162,6 +180,14 @@ function extractRoute(fn, inferName) {
162
180
  auth
163
181
  };
164
182
  }
183
+ function extractEvents(fn) {
184
+ const decorators = collectDecorators(fn);
185
+ const onDecorators = decorators.filter((decorator) => decorator.getName() === "On");
186
+ if (onDecorators.length === 0) {
187
+ return [];
188
+ }
189
+ return onDecorators.map(readOnDecorator);
190
+ }
165
191
  function collectDecorators(fn) {
166
192
  if (import_ts_morph.Node.isMethodDeclaration(fn)) {
167
193
  return fn.getDecorators();
@@ -173,15 +199,25 @@ function readPath(decorator) {
173
199
  if (args.length === 0) {
174
200
  return void 0;
175
201
  }
176
- const first = args[0];
177
- if (import_ts_morph.Node.isStringLiteral(first) || import_ts_morph.Node.isNoSubstitutionTemplateLiteral(first)) {
178
- const value = first.getLiteralValue();
179
- if (!value) {
180
- return "/";
181
- }
182
- return value.startsWith("/") ? value : `/${value}`;
202
+ const value = readStringLiteral(args[0], "path");
203
+ if (!value) {
204
+ return "/";
205
+ }
206
+ return value.startsWith("/") ? value : `/${value}`;
207
+ }
208
+ function readOnDecorator(decorator) {
209
+ const args = decorator.getArguments();
210
+ if (args.length === 0) {
211
+ throw new Error("@On() requires an event name.");
212
+ }
213
+ const event = readStringLiteral(args[0], "event");
214
+ return { event };
215
+ }
216
+ function readStringLiteral(node, label) {
217
+ if (import_ts_morph.Node.isStringLiteral(node) || import_ts_morph.Node.isNoSubstitutionTemplateLiteral(node)) {
218
+ return node.getLiteralValue();
183
219
  }
184
- throw new Error(`Unsupported path expression: ${first.getText()}`);
220
+ throw new Error(`Unsupported ${label} expression: ${node.getText()}`);
185
221
  }
186
222
  function readFirebaseAuth(decorator) {
187
223
  const args = decorator.getArguments();
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  normalizeApiGatewayPath
4
- } from "./chunk-5MOJ3SW6.js";
4
+ } from "./chunk-5OUNKYO5.js";
5
5
 
6
6
  // src/cli.ts
7
7
  import { writeFileSync } from "fs";
@@ -47,7 +47,8 @@ async function runScan(args) {
47
47
  options.globs.push("src/**/*.ts");
48
48
  }
49
49
  project.addSourceFilesAtPaths(options.globs);
50
- const manifest = { routes: [] };
50
+ const routes = [];
51
+ const events = [];
51
52
  for (const sourceFile of project.getSourceFiles()) {
52
53
  for (const fn of sourceFile.getFunctions()) {
53
54
  if (!fn.isExported() && !fn.isDefaultExport()) {
@@ -55,7 +56,11 @@ async function runScan(args) {
55
56
  }
56
57
  const route = extractRoute(fn, options.inferName);
57
58
  if (route) {
58
- manifest.routes.push(route);
59
+ routes.push(route);
60
+ }
61
+ const foundEvents = extractEvents(fn);
62
+ if (foundEvents.length > 0) {
63
+ events.push(...foundEvents);
59
64
  }
60
65
  }
61
66
  for (const cls of sourceFile.getClasses()) {
@@ -68,17 +73,30 @@ async function runScan(args) {
68
73
  }
69
74
  const route = extractRoute(method, options.inferName);
70
75
  if (route) {
71
- manifest.routes.push(route);
76
+ routes.push(route);
77
+ }
78
+ const foundEvents = extractEvents(method);
79
+ if (foundEvents.length > 0) {
80
+ events.push(...foundEvents);
72
81
  }
73
82
  }
74
83
  }
75
84
  }
76
- manifest.routes.sort((a, b) => {
85
+ routes.sort((a, b) => {
77
86
  if (a.path === b.path) {
78
87
  return a.method.localeCompare(b.method);
79
88
  }
80
89
  return a.path.localeCompare(b.path);
81
90
  });
91
+ if (events.length > 0) {
92
+ events.sort((a, b) => {
93
+ return a.event.localeCompare(b.event);
94
+ });
95
+ }
96
+ const manifest = { routes };
97
+ if (events.length > 0) {
98
+ manifest.events = events;
99
+ }
82
100
  const outPath = resolve(cwd(), options.outFile);
83
101
  writeFileSync(outPath, JSON.stringify(manifest, null, 2));
84
102
  stdout.write(`Wrote ${manifest.routes.length} route(s) to ${outPath}
@@ -160,6 +178,14 @@ function extractRoute(fn, inferName) {
160
178
  auth
161
179
  };
162
180
  }
181
+ function extractEvents(fn) {
182
+ const decorators = collectDecorators(fn);
183
+ const onDecorators = decorators.filter((decorator) => decorator.getName() === "On");
184
+ if (onDecorators.length === 0) {
185
+ return [];
186
+ }
187
+ return onDecorators.map(readOnDecorator);
188
+ }
163
189
  function collectDecorators(fn) {
164
190
  if (Node.isMethodDeclaration(fn)) {
165
191
  return fn.getDecorators();
@@ -171,15 +197,25 @@ function readPath(decorator) {
171
197
  if (args.length === 0) {
172
198
  return void 0;
173
199
  }
174
- const first = args[0];
175
- if (Node.isStringLiteral(first) || Node.isNoSubstitutionTemplateLiteral(first)) {
176
- const value = first.getLiteralValue();
177
- if (!value) {
178
- return "/";
179
- }
180
- return value.startsWith("/") ? value : `/${value}`;
200
+ const value = readStringLiteral(args[0], "path");
201
+ if (!value) {
202
+ return "/";
203
+ }
204
+ return value.startsWith("/") ? value : `/${value}`;
205
+ }
206
+ function readOnDecorator(decorator) {
207
+ const args = decorator.getArguments();
208
+ if (args.length === 0) {
209
+ throw new Error("@On() requires an event name.");
210
+ }
211
+ const event = readStringLiteral(args[0], "event");
212
+ return { event };
213
+ }
214
+ function readStringLiteral(node, label) {
215
+ if (Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)) {
216
+ return node.getLiteralValue();
181
217
  }
182
- throw new Error(`Unsupported path expression: ${first.getText()}`);
218
+ throw new Error(`Unsupported ${label} expression: ${node.getText()}`);
183
219
  }
184
220
  function readFirebaseAuth(decorator) {
185
221
  const args = decorator.getArguments();
@@ -0,0 +1,4 @@
1
+ type LegacyDecorator = (target: unknown, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
2
+ type LegacyParameterDecorator = (target: unknown, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
3
+
4
+ export type { LegacyDecorator as L, LegacyParameterDecorator as a };
@@ -0,0 +1,4 @@
1
+ type LegacyDecorator = (target: unknown, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
2
+ type LegacyParameterDecorator = (target: unknown, propertyKey: string | symbol | undefined, parameterIndex: number) => void;
3
+
4
+ export type { LegacyDecorator as L, LegacyParameterDecorator as a };