effortless-aws 0.30.0 → 0.31.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
@@ -34,30 +34,22 @@ var param = (key, transform) => {
34
34
  var generateHex = (bytes) => `hex:${bytes}`;
35
35
  var generateBase64 = (bytes) => `base64:${bytes}`;
36
36
  var generateUuid = () => "uuid";
37
- function unsafeAs() {
38
- return (input) => input;
39
- }
40
37
 
41
38
  // src/handlers/define-table.ts
42
39
  function defineTable(options) {
43
40
  const {
44
- memory,
45
- timeout,
46
- permissions,
47
- logLevel,
48
41
  schema,
49
- static: staticFiles,
50
42
  ...tableConfig
51
43
  } = 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
- };
44
+ const spec = { ...tableConfig };
57
45
  const state = {
58
46
  spec,
59
- ...schema ? { schema } : {},
60
- ...staticFiles ? { static: staticFiles } : {}
47
+ ...schema ? { schema } : {}
48
+ };
49
+ const applyLambdaOptions = (lambda) => {
50
+ if (Object.keys(lambda).length > 0) {
51
+ state.spec = { ...state.spec, lambda: { ...state.spec.lambda, ...lambda } };
52
+ }
61
53
  };
62
54
  const finalize = () => ({
63
55
  __brand: "effortless-table",
@@ -81,8 +73,17 @@ function defineTable(options) {
81
73
  state.config = resolveConfigFactory(fn);
82
74
  return builder;
83
75
  },
84
- setup(fn) {
85
- state.setup = fn;
76
+ include(glob) {
77
+ state.static = [...state.static ?? [], glob];
78
+ return builder;
79
+ },
80
+ setup(fnOrLambda, maybeLambda) {
81
+ if (typeof fnOrLambda === "function") {
82
+ state.setup = fnOrLambda;
83
+ if (maybeLambda) applyLambdaOptions(maybeLambda);
84
+ } else {
85
+ applyLambdaOptions(fnOrLambda);
86
+ }
86
87
  return builder;
87
88
  },
88
89
  onRecord(fn) {
@@ -123,23 +124,18 @@ var defineStaticSite = () => (options) => ({
123
124
  // src/handlers/define-fifo-queue.ts
124
125
  function defineFifoQueue(options) {
125
126
  const {
126
- memory,
127
- timeout,
128
- permissions,
129
- logLevel,
130
127
  schema,
131
- static: staticFiles,
132
128
  ...queueConfig
133
129
  } = 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
- };
130
+ const spec = { ...queueConfig };
139
131
  const state = {
140
132
  spec,
141
- ...schema ? { schema } : {},
142
- ...staticFiles ? { static: staticFiles } : {}
133
+ ...schema ? { schema } : {}
134
+ };
135
+ const applyLambdaOptions = (lambda) => {
136
+ if (Object.keys(lambda).length > 0) {
137
+ state.spec = { ...state.spec, lambda: { ...state.spec.lambda, ...lambda } };
138
+ }
143
139
  };
144
140
  const finalize = () => ({
145
141
  __brand: "effortless-fifo-queue",
@@ -163,8 +159,17 @@ function defineFifoQueue(options) {
163
159
  state.config = resolveConfigFactory(fn);
164
160
  return builder;
165
161
  },
166
- setup(fn) {
167
- state.setup = fn;
162
+ include(glob) {
163
+ state.static = [...state.static ?? [], glob];
164
+ return builder;
165
+ },
166
+ setup(fnOrLambda, maybeLambda) {
167
+ if (typeof fnOrLambda === "function") {
168
+ state.setup = fnOrLambda;
169
+ if (maybeLambda) applyLambdaOptions(maybeLambda);
170
+ } else {
171
+ applyLambdaOptions(fnOrLambda);
172
+ }
168
173
  return builder;
169
174
  },
170
175
  onMessage(fn) {
@@ -189,22 +194,17 @@ function defineFifoQueue(options) {
189
194
 
190
195
  // src/handlers/define-bucket.ts
191
196
  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;
197
+ const bucketConfig = options ?? {};
201
198
  const spec = {
202
- ...bucketConfig,
203
- ...hasLambda ? { lambda: { ...memory != null ? { memory } : {}, ...timeout != null ? { timeout } : {}, ...permissions ? { permissions } : {}, ...logLevel ? { logLevel } : {} } } : {}
199
+ ...bucketConfig
204
200
  };
205
201
  const state = {
206
- spec,
207
- ...staticFiles ? { static: staticFiles } : {}
202
+ spec
203
+ };
204
+ const applyLambdaOptions = (lambda) => {
205
+ if (Object.keys(lambda).length > 0) {
206
+ state.spec = { ...state.spec, lambda: { ...state.spec.lambda, ...lambda } };
207
+ }
208
208
  };
209
209
  const finalize = () => ({
210
210
  __brand: "effortless-bucket",
@@ -227,8 +227,17 @@ function defineBucket(options) {
227
227
  state.config = resolveConfigFactory(fn);
228
228
  return builder;
229
229
  },
230
- setup(fn) {
231
- state.setup = fn;
230
+ include(glob) {
231
+ state.static = [...state.static ?? [], glob];
232
+ return builder;
233
+ },
234
+ setup(fnOrLambda, maybeLambda) {
235
+ if (typeof fnOrLambda === "function") {
236
+ state.setup = fnOrLambda;
237
+ if (maybeLambda) applyLambdaOptions(maybeLambda);
238
+ } else {
239
+ applyLambdaOptions(fnOrLambda);
240
+ }
232
241
  return builder;
233
242
  },
234
243
  onObjectCreated(fn) {
@@ -262,15 +271,12 @@ var defineMailer = () => (options) => ({
262
271
 
263
272
  // src/handlers/define-api.ts
264
273
  function defineApi(options) {
265
- const { basePath, stream, static: staticFiles, ...lambdaConfig } = options;
266
- const hasLambda = Object.keys(lambdaConfig).length > 0;
274
+ const { basePath, stream } = options;
267
275
  const state = {
268
276
  spec: {
269
277
  basePath,
270
- ...hasLambda ? { lambda: lambdaConfig } : {},
271
278
  ...stream ? { stream } : {}
272
279
  },
273
- ...staticFiles ? { static: staticFiles } : {},
274
280
  routes: []
275
281
  };
276
282
  const addRoute = (method, path, handler, opts) => {
@@ -281,6 +287,11 @@ function defineApi(options) {
281
287
  ...opts?.public ? { public: true } : {}
282
288
  });
283
289
  };
290
+ const applyLambdaOptions = (lambda) => {
291
+ if (Object.keys(lambda).length > 0) {
292
+ state.spec = { ...state.spec, lambda: { ...state.spec.lambda, ...lambda } };
293
+ }
294
+ };
284
295
  const finalize = () => {
285
296
  const handler = {
286
297
  __brand: "effortless-api",
@@ -311,8 +322,17 @@ function defineApi(options) {
311
322
  state.config = resolveConfigFactory(fn);
312
323
  return builder;
313
324
  },
314
- setup(fn) {
315
- state.setup = fn;
325
+ include(glob) {
326
+ state.static = [...state.static ?? [], glob];
327
+ return builder;
328
+ },
329
+ setup(fnOrLambda, maybeLambda) {
330
+ if (typeof fnOrLambda === "function") {
331
+ state.setup = fnOrLambda;
332
+ if (maybeLambda) applyLambdaOptions(maybeLambda);
333
+ } else {
334
+ applyLambdaOptions(fnOrLambda);
335
+ }
316
336
  return builder;
317
337
  },
318
338
  onError(fn) {
@@ -346,11 +366,74 @@ function defineApi(options) {
346
366
  };
347
367
  return builder;
348
368
  }
369
+
370
+ // src/handlers/define-cron.ts
371
+ function defineCron(options) {
372
+ const { schedule, timezone } = options;
373
+ const spec = {
374
+ schedule,
375
+ ...timezone ? { timezone } : {}
376
+ };
377
+ const state = { spec };
378
+ const applyLambdaOptions = (lambda) => {
379
+ if (Object.keys(lambda).length > 0) {
380
+ state.spec = { ...state.spec, lambda: { ...state.spec.lambda, ...lambda } };
381
+ }
382
+ };
383
+ const finalize = () => ({
384
+ __brand: "effortless-cron",
385
+ __spec: state.spec,
386
+ ...state.onError ? { onError: state.onError } : {},
387
+ ...state.onCleanup ? { onCleanup: state.onCleanup } : {},
388
+ ...state.setup ? { setup: state.setup } : {},
389
+ ...state.deps ? { deps: state.deps } : {},
390
+ ...state.config ? { config: state.config } : {},
391
+ ...state.static ? { static: state.static } : {},
392
+ ...state.onTick ? { onTick: state.onTick } : {}
393
+ });
394
+ const builder = {
395
+ deps(fn) {
396
+ state.deps = fn;
397
+ return builder;
398
+ },
399
+ config(fn) {
400
+ state.config = resolveConfigFactory(fn);
401
+ return builder;
402
+ },
403
+ include(glob) {
404
+ state.static = [...state.static ?? [], glob];
405
+ return builder;
406
+ },
407
+ setup(fnOrLambda, maybeLambda) {
408
+ if (typeof fnOrLambda === "function") {
409
+ state.setup = fnOrLambda;
410
+ if (maybeLambda) applyLambdaOptions(maybeLambda);
411
+ } else {
412
+ applyLambdaOptions(fnOrLambda);
413
+ }
414
+ return builder;
415
+ },
416
+ onError(fn) {
417
+ state.onError = fn;
418
+ return builder;
419
+ },
420
+ onCleanup(fn) {
421
+ state.onCleanup = fn;
422
+ return builder;
423
+ },
424
+ onTick(fn) {
425
+ state.onTick = fn;
426
+ return finalize();
427
+ }
428
+ };
429
+ return builder;
430
+ }
349
431
  export {
350
432
  defineApi,
351
433
  defineApp,
352
434
  defineBucket,
353
435
  defineConfig,
436
+ defineCron,
354
437
  defineFifoQueue,
355
438
  defineMailer,
356
439
  defineSecret,
@@ -361,7 +444,6 @@ export {
361
444
  generateUuid,
362
445
  param,
363
446
  secret,
364
- toSeconds,
365
- unsafeAs
447
+ toSeconds
366
448
  };
367
449
  //# sourceMappingURL=index.js.map