effortless-aws 0.29.0 → 0.30.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/index.js CHANGED
@@ -39,23 +39,74 @@ function unsafeAs() {
39
39
  }
40
40
 
41
41
  // src/handlers/define-table.ts
42
- var defineTable = () => (options) => {
43
- const { onRecord, onRecordBatch, onError, onAfterInvoke, schema, setup, deps, config: configFactory, static: staticFiles, ...__spec } = options;
44
- const config = configFactory ? resolveConfigFactory(configFactory) : void 0;
45
- return {
46
- __brand: "effortless-table",
47
- __spec,
42
+ function defineTable(options) {
43
+ const {
44
+ memory,
45
+ timeout,
46
+ permissions,
47
+ logLevel,
48
+ schema,
49
+ static: staticFiles,
50
+ ...tableConfig
51
+ } = options ?? {};
52
+ const hasLambda = memory != null || timeout != null || permissions != null || logLevel != null;
53
+ const spec = {
54
+ ...tableConfig,
55
+ ...hasLambda ? { lambda: { ...memory != null ? { memory } : {}, ...timeout != null ? { timeout } : {}, ...permissions ? { permissions } : {}, ...logLevel ? { logLevel } : {} } } : {}
56
+ };
57
+ const state = {
58
+ spec,
48
59
  ...schema ? { schema } : {},
49
- ...onError ? { onError } : {},
50
- ...onAfterInvoke ? { onAfterInvoke } : {},
51
- ...setup ? { setup } : {},
52
- ...deps ? { deps } : {},
53
- ...config ? { config } : {},
54
- ...staticFiles ? { static: staticFiles } : {},
55
- ...onRecord ? { onRecord } : {},
56
- ...onRecordBatch ? { onRecordBatch } : {}
60
+ ...staticFiles ? { static: staticFiles } : {}
57
61
  };
58
- };
62
+ const finalize = () => ({
63
+ __brand: "effortless-table",
64
+ __spec: state.spec,
65
+ ...state.schema ? { schema: state.schema } : {},
66
+ ...state.onError ? { onError: state.onError } : {},
67
+ ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
68
+ ...state.setup ? { setup: state.setup } : {},
69
+ ...state.deps ? { deps: state.deps } : {},
70
+ ...state.config ? { config: state.config } : {},
71
+ ...state.static ? { static: state.static } : {},
72
+ ...state.onRecord ? { onRecord: state.onRecord } : {},
73
+ ...state.onRecordBatch ? { onRecordBatch: state.onRecordBatch } : {}
74
+ });
75
+ const builder = {
76
+ deps(fn) {
77
+ state.deps = fn;
78
+ return builder;
79
+ },
80
+ config(fn) {
81
+ state.config = resolveConfigFactory(fn);
82
+ return builder;
83
+ },
84
+ setup(fn) {
85
+ state.setup = fn;
86
+ return builder;
87
+ },
88
+ onRecord(fn) {
89
+ state.onRecord = fn;
90
+ return finalize();
91
+ },
92
+ onRecordBatch(fn) {
93
+ state.onRecordBatch = fn;
94
+ return finalize();
95
+ },
96
+ onError(fn) {
97
+ state.onError = fn;
98
+ return builder;
99
+ },
100
+ onCleanup(fn) {
101
+ state.onCleanup = fn;
102
+ return builder;
103
+ },
104
+ build() {
105
+ return finalize();
106
+ }
107
+ };
108
+ return builder;
109
+ }
59
110
 
60
111
  // src/handlers/define-app.ts
61
112
  var defineApp = () => (options) => ({
@@ -70,41 +121,138 @@ var defineStaticSite = () => (options) => ({
70
121
  });
71
122
 
72
123
  // src/handlers/define-fifo-queue.ts
73
- var defineFifoQueue = () => (options) => {
74
- const { onMessage, onMessageBatch, onError, onAfterInvoke, schema, setup, deps, config: configFactory, static: staticFiles, ...__spec } = options;
75
- const config = configFactory ? resolveConfigFactory(configFactory) : void 0;
76
- return {
77
- __brand: "effortless-fifo-queue",
78
- __spec,
124
+ function defineFifoQueue(options) {
125
+ const {
126
+ memory,
127
+ timeout,
128
+ permissions,
129
+ logLevel,
130
+ schema,
131
+ static: staticFiles,
132
+ ...queueConfig
133
+ } = options ?? {};
134
+ const hasLambda = memory != null || timeout != null || permissions != null || logLevel != null;
135
+ const spec = {
136
+ ...queueConfig,
137
+ ...hasLambda ? { lambda: { ...memory != null ? { memory } : {}, ...timeout != null ? { timeout } : {}, ...permissions ? { permissions } : {}, ...logLevel ? { logLevel } : {} } } : {}
138
+ };
139
+ const state = {
140
+ spec,
79
141
  ...schema ? { schema } : {},
80
- ...onError ? { onError } : {},
81
- ...onAfterInvoke ? { onAfterInvoke } : {},
82
- ...setup ? { setup } : {},
83
- ...deps ? { deps } : {},
84
- ...config ? { config } : {},
85
- ...staticFiles ? { static: staticFiles } : {},
86
- ...onMessage ? { onMessage } : {},
87
- ...onMessageBatch ? { onMessageBatch } : {}
142
+ ...staticFiles ? { static: staticFiles } : {}
88
143
  };
89
- };
144
+ const finalize = () => ({
145
+ __brand: "effortless-fifo-queue",
146
+ __spec: state.spec,
147
+ ...state.schema ? { schema: state.schema } : {},
148
+ ...state.onError ? { onError: state.onError } : {},
149
+ ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
150
+ ...state.setup ? { setup: state.setup } : {},
151
+ ...state.deps ? { deps: state.deps } : {},
152
+ ...state.config ? { config: state.config } : {},
153
+ ...state.static ? { static: state.static } : {},
154
+ ...state.onMessage ? { onMessage: state.onMessage } : {},
155
+ ...state.onMessageBatch ? { onMessageBatch: state.onMessageBatch } : {}
156
+ });
157
+ const builder = {
158
+ deps(fn) {
159
+ state.deps = fn;
160
+ return builder;
161
+ },
162
+ config(fn) {
163
+ state.config = resolveConfigFactory(fn);
164
+ return builder;
165
+ },
166
+ setup(fn) {
167
+ state.setup = fn;
168
+ return builder;
169
+ },
170
+ onMessage(fn) {
171
+ state.onMessage = fn;
172
+ return finalize();
173
+ },
174
+ onMessageBatch(fn) {
175
+ state.onMessageBatch = fn;
176
+ return finalize();
177
+ },
178
+ onError(fn) {
179
+ state.onError = fn;
180
+ return builder;
181
+ },
182
+ onCleanup(fn) {
183
+ state.onCleanup = fn;
184
+ return builder;
185
+ }
186
+ };
187
+ return builder;
188
+ }
90
189
 
91
190
  // src/handlers/define-bucket.ts
92
- var defineBucket = () => (options) => {
93
- const { onObjectCreated, onObjectRemoved, onError, onAfterInvoke, setup, deps, config: configFactory, static: staticFiles, ...__spec } = options;
94
- const config = configFactory ? resolveConfigFactory(configFactory) : void 0;
95
- return {
191
+ function defineBucket(options) {
192
+ const {
193
+ memory,
194
+ timeout,
195
+ permissions,
196
+ logLevel,
197
+ static: staticFiles,
198
+ ...bucketConfig
199
+ } = options ?? {};
200
+ const hasLambda = memory != null || timeout != null || permissions != null || logLevel != null;
201
+ const spec = {
202
+ ...bucketConfig,
203
+ ...hasLambda ? { lambda: { ...memory != null ? { memory } : {}, ...timeout != null ? { timeout } : {}, ...permissions ? { permissions } : {}, ...logLevel ? { logLevel } : {} } } : {}
204
+ };
205
+ const state = {
206
+ spec,
207
+ ...staticFiles ? { static: staticFiles } : {}
208
+ };
209
+ const finalize = () => ({
96
210
  __brand: "effortless-bucket",
97
- __spec,
98
- ...onError ? { onError } : {},
99
- ...onAfterInvoke ? { onAfterInvoke } : {},
100
- ...setup ? { setup } : {},
101
- ...deps ? { deps } : {},
102
- ...config ? { config } : {},
103
- ...staticFiles ? { static: staticFiles } : {},
104
- ...onObjectCreated ? { onObjectCreated } : {},
105
- ...onObjectRemoved ? { onObjectRemoved } : {}
211
+ __spec: state.spec,
212
+ ...state.onError ? { onError: state.onError } : {},
213
+ ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
214
+ ...state.setup ? { setup: state.setup } : {},
215
+ ...state.deps ? { deps: state.deps } : {},
216
+ ...state.config ? { config: state.config } : {},
217
+ ...state.static ? { static: state.static } : {},
218
+ ...state.onObjectCreated ? { onObjectCreated: state.onObjectCreated } : {},
219
+ ...state.onObjectRemoved ? { onObjectRemoved: state.onObjectRemoved } : {}
220
+ });
221
+ const builder = {
222
+ deps(fn) {
223
+ state.deps = fn;
224
+ return builder;
225
+ },
226
+ config(fn) {
227
+ state.config = resolveConfigFactory(fn);
228
+ return builder;
229
+ },
230
+ setup(fn) {
231
+ state.setup = fn;
232
+ return builder;
233
+ },
234
+ onObjectCreated(fn) {
235
+ state.onObjectCreated = fn;
236
+ return finalize();
237
+ },
238
+ onObjectRemoved(fn) {
239
+ state.onObjectRemoved = fn;
240
+ return finalize();
241
+ },
242
+ onError(fn) {
243
+ state.onError = fn;
244
+ return builder;
245
+ },
246
+ onCleanup(fn) {
247
+ state.onCleanup = fn;
248
+ return builder;
249
+ },
250
+ build() {
251
+ return finalize();
252
+ }
106
253
  };
107
- };
254
+ return builder;
255
+ }
108
256
 
109
257
  // src/handlers/define-mailer.ts
110
258
  var defineMailer = () => (options) => ({
@@ -113,46 +261,91 @@ var defineMailer = () => (options) => ({
113
261
  });
114
262
 
115
263
  // src/handlers/define-api.ts
116
- var defineApi = () => (options) => {
117
- const { routes, onError, onAfterInvoke, setup, deps, config: configFactory, static: staticFiles, ...__spec } = options;
118
- const config = configFactory ? resolveConfigFactory(configFactory) : void 0;
119
- const parsed = routes ? routes.map(parseRoute) : void 0;
120
- return {
121
- __brand: "effortless-api",
122
- __spec,
123
- ...parsed ? { routes: parsed } : {},
124
- ...onError ? { onError } : {},
125
- ...onAfterInvoke ? { onAfterInvoke } : {},
126
- ...setup ? { setup } : {},
127
- ...deps ? { deps } : {},
128
- ...config ? { config } : {},
129
- ...staticFiles ? { static: staticFiles } : {}
264
+ function defineApi(options) {
265
+ const { basePath, stream, static: staticFiles, ...lambdaConfig } = options;
266
+ const hasLambda = Object.keys(lambdaConfig).length > 0;
267
+ const state = {
268
+ spec: {
269
+ basePath,
270
+ ...hasLambda ? { lambda: lambdaConfig } : {},
271
+ ...stream ? { stream } : {}
272
+ },
273
+ ...staticFiles ? { static: staticFiles } : {},
274
+ routes: []
130
275
  };
131
- };
132
- var parseRoute = (route) => {
133
- const spaceIdx = route.path.indexOf(" ");
134
- const method = route.path.slice(0, spaceIdx);
135
- const path = route.path.slice(spaceIdx + 1);
136
- return {
137
- method,
138
- path,
139
- onRequest: route.onRequest,
140
- ...route.public ? { public: true } : {}
276
+ const addRoute = (method, path, handler, opts) => {
277
+ state.routes.push({
278
+ method,
279
+ path,
280
+ onRequest: handler,
281
+ ...opts?.public ? { public: true } : {}
282
+ });
141
283
  };
142
- };
143
-
144
- // src/handlers/shared.ts
145
- var result = {
146
- /** Return a JSON response */
147
- json: (body, status = 200) => ({ status, body }),
148
- /** Return a binary response. Accepts a Buffer and converts to base64 automatically. */
149
- binary: (body, contentType, headers) => ({
150
- status: 200,
151
- body: body.toString("base64"),
152
- binary: true,
153
- headers: { "content-type": contentType, ...headers }
154
- })
155
- };
284
+ const finalize = () => {
285
+ const handler = {
286
+ __brand: "effortless-api",
287
+ __spec: state.spec,
288
+ routes: state.routes,
289
+ ...state.onError ? { onError: state.onError } : {},
290
+ ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
291
+ ...state.setup ? { setup: state.setup } : {},
292
+ ...state.deps ? { deps: state.deps } : {},
293
+ ...state.config ? { config: state.config } : {},
294
+ ...state.static ? { static: state.static } : {}
295
+ };
296
+ for (const m of ["get", "post", "put", "patch", "delete"]) {
297
+ handler[m] = (path, fn, opts) => {
298
+ addRoute(m.toUpperCase(), path, fn, opts);
299
+ handler.routes = state.routes;
300
+ return handler;
301
+ };
302
+ }
303
+ return handler;
304
+ };
305
+ const builder = {
306
+ deps(fn) {
307
+ state.deps = fn;
308
+ return builder;
309
+ },
310
+ config(fn) {
311
+ state.config = resolveConfigFactory(fn);
312
+ return builder;
313
+ },
314
+ setup(fn) {
315
+ state.setup = fn;
316
+ return builder;
317
+ },
318
+ onError(fn) {
319
+ state.onError = fn;
320
+ return builder;
321
+ },
322
+ onCleanup(fn) {
323
+ state.onCleanup = fn;
324
+ return builder;
325
+ },
326
+ get(path, handler, opts) {
327
+ addRoute("GET", path, handler, opts);
328
+ return finalize();
329
+ },
330
+ post(path, handler, opts) {
331
+ addRoute("POST", path, handler, opts);
332
+ return finalize();
333
+ },
334
+ put(path, handler, opts) {
335
+ addRoute("PUT", path, handler, opts);
336
+ return finalize();
337
+ },
338
+ patch(path, handler, opts) {
339
+ addRoute("PATCH", path, handler, opts);
340
+ return finalize();
341
+ },
342
+ delete(path, handler, opts) {
343
+ addRoute("DELETE", path, handler, opts);
344
+ return finalize();
345
+ }
346
+ };
347
+ return builder;
348
+ }
156
349
  export {
157
350
  defineApi,
158
351
  defineApp,
@@ -167,7 +360,6 @@ export {
167
360
  generateHex,
168
361
  generateUuid,
169
362
  param,
170
- result,
171
363
  secret,
172
364
  toSeconds,
173
365
  unsafeAs