effortless-aws 0.5.0 → 0.7.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.d.ts CHANGED
@@ -47,21 +47,26 @@ type EffortlessConfig = {
47
47
  handlers?: string | string[];
48
48
  /**
49
49
  * Default settings applied to all handlers unless overridden.
50
+ *
51
+ * All Lambdas run on ARM64 (Graviton2) architecture — ~20% cheaper than x86_64
52
+ * with better price-performance for most workloads.
50
53
  */
51
54
  defaults?: {
52
55
  /**
53
- * Lambda memory in MB.
56
+ * Lambda memory in MB. AWS allocates proportional CPU —
57
+ * 1769 MB gives one full vCPU.
54
58
  * @default 256
55
59
  */
56
60
  memory?: number;
57
61
  /**
58
62
  * Lambda timeout as a human-readable string.
63
+ * AWS maximum is 15 minutes.
59
64
  * @example "30 seconds", "5 minutes"
60
65
  */
61
66
  timeout?: string;
62
67
  /**
63
- * Lambda runtime.
64
- * @default "nodejs22.x"
68
+ * Node.js Lambda runtime version.
69
+ * @default "nodejs24.x"
65
70
  */
66
71
  runtime?: string;
67
72
  };
@@ -83,9 +88,6 @@ type EffortlessConfig = {
83
88
  */
84
89
  declare const defineConfig: (config: EffortlessConfig) => EffortlessConfig;
85
90
 
86
- type AwsService = "dynamodb" | "s3" | "sqs" | "sns" | "ses" | "ssm" | "lambda" | "events" | "secretsmanager" | "cognito-idp" | "logs";
87
- type Permission = `${AwsService}:${string}` | (string & {});
88
-
89
91
  /**
90
92
  * Query parameters for TableClient.query()
91
93
  */
@@ -143,57 +145,9 @@ type TableClient<T = Record<string, unknown>> = {
143
145
  tableName: string;
144
146
  };
145
147
 
146
- type AnyParamRef = ParamRef<any>;
147
- /**
148
- * Reference to an SSM Parameter Store parameter.
149
- *
150
- * @typeParam T - The resolved type after optional transform (default: string)
151
- */
152
- type ParamRef<T = string> = {
153
- readonly __brand: "effortless-param";
154
- readonly key: string;
155
- readonly transform?: (raw: string) => T;
156
- };
157
- /**
158
- * Maps a params declaration to resolved value types.
159
- *
160
- * @typeParam P - Record of param names to ParamRef instances
161
- */
162
- type ResolveParams<P> = {
163
- [K in keyof P]: P[K] extends ParamRef<infer T> ? T : never;
164
- };
165
- /**
166
- * Declare an SSM Parameter Store parameter.
167
- *
168
- * The key is combined with project and stage at deploy time to form the full
169
- * SSM path: `/${project}/${stage}/${key}`.
170
- *
171
- * @param key - Parameter key (e.g., "database-url")
172
- * @param transform - Optional function to transform the raw string value
173
- * @returns A ParamRef used by the deployment and runtime systems
174
- *
175
- * @example Simple string parameter
176
- * ```typescript
177
- * params: {
178
- * dbUrl: param("database-url"),
179
- * }
180
- * ```
181
- *
182
- * @example With transform (e.g., TOML parsing)
183
- * ```typescript
184
- * import TOML from "smol-toml";
185
- *
186
- * params: {
187
- * config: param("app-config", TOML.parse),
188
- * }
189
- * ```
190
- */
191
- declare function param(key: string): ParamRef<string>;
192
- declare function param<T>(key: string, transform: (raw: string) => T): ParamRef<T>;
193
-
194
- type AnyTableHandler$1 = TableHandler<any, any, any, any, any, any>;
148
+ type AnyTableHandler$2 = TableHandler<any, any, any, any, any, any>;
195
149
  /** Maps a deps declaration to resolved runtime client types */
196
- type ResolveDeps$1<D> = {
150
+ type ResolveDeps$2<D> = {
197
151
  [K in keyof D]: D[K] extends TableHandler<infer T, any, any, any, any> ? TableClient<T> : never;
198
152
  };
199
153
  /** DynamoDB attribute types for keys */
@@ -212,9 +166,7 @@ type StreamView = "NEW_AND_OLD_IMAGES" | "NEW_IMAGE" | "OLD_IMAGE" | "KEYS_ONLY"
212
166
  /**
213
167
  * Configuration options extracted from DefineTableOptions (without onRecord/context)
214
168
  */
215
- type TableConfig = {
216
- /** Table/handler name. Defaults to export name if not specified */
217
- name?: string;
169
+ type TableConfig = LambdaWithPermissions & {
218
170
  /** Partition key definition */
219
171
  pk: TableKey;
220
172
  /** Sort key definition (optional) */
@@ -231,14 +183,6 @@ type TableConfig = {
231
183
  batchWindow?: number;
232
184
  /** Where to start reading the stream (default: "LATEST") */
233
185
  startingPosition?: "LATEST" | "TRIM_HORIZON";
234
- /** Lambda memory in MB (default: 256) */
235
- memory?: number;
236
- /** Lambda timeout in seconds (default: 30) */
237
- timeout?: number;
238
- /** Additional IAM permissions for the Lambda */
239
- permissions?: Permission[];
240
- /** Enable observability logging to platform table (default: true) */
241
- observe?: boolean;
242
186
  };
243
187
  /**
244
188
  * DynamoDB stream record passed to onRecord callback
@@ -275,7 +219,7 @@ type FailedRecord<T = Record<string, unknown>> = {
275
219
  * Without params: `() => C | Promise<C>`
276
220
  * With params: `(args: { params: ResolveParams<P> }) => C | Promise<C>`
277
221
  */
278
- type ContextFactory$1<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
222
+ type ContextFactory$2<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
279
223
  params: ResolveParams<P & {}>;
280
224
  }) => C | Promise<C>;
281
225
  /**
@@ -287,7 +231,7 @@ type TableRecordFn<T = Record<string, unknown>, C = undefined, R = void, D = und
287
231
  } & ([C] extends [undefined] ? {} : {
288
232
  ctx: C;
289
233
  }) & ([D] extends [undefined] ? {} : {
290
- deps: ResolveDeps$1<D>;
234
+ deps: ResolveDeps$2<D>;
291
235
  }) & ([P] extends [undefined] ? {} : {
292
236
  params: ResolveParams<P>;
293
237
  }) & ([S] extends [undefined] ? {} : {
@@ -303,7 +247,7 @@ type TableBatchCompleteFn<T = Record<string, unknown>, C = undefined, R = void,
303
247
  } & ([C] extends [undefined] ? {} : {
304
248
  ctx: C;
305
249
  }) & ([D] extends [undefined] ? {} : {
306
- deps: ResolveDeps$1<D>;
250
+ deps: ResolveDeps$2<D>;
307
251
  }) & ([P] extends [undefined] ? {} : {
308
252
  params: ResolveParams<P>;
309
253
  }) & ([S] extends [undefined] ? {} : {
@@ -318,7 +262,7 @@ type TableBatchFn<T = Record<string, unknown>, C = undefined, D = undefined, P =
318
262
  } & ([C] extends [undefined] ? {} : {
319
263
  ctx: C;
320
264
  }) & ([D] extends [undefined] ? {} : {
321
- deps: ResolveDeps$1<D>;
265
+ deps: ResolveDeps$2<D>;
322
266
  }) & ([P] extends [undefined] ? {} : {
323
267
  params: ResolveParams<P>;
324
268
  }) & ([S] extends [undefined] ? {} : {
@@ -343,7 +287,7 @@ type DefineTableBase<T = Record<string, unknown>, C = undefined, D = undefined,
343
287
  * When params are declared, receives resolved params as argument.
344
288
  * Supports both sync and async return values.
345
289
  */
346
- context?: ContextFactory$1<C, P>;
290
+ context?: ContextFactory$2<C, P>;
347
291
  /**
348
292
  * Dependencies on other handlers (tables, queues, etc.).
349
293
  * Typed clients are injected into the handler via the `deps` argument.
@@ -379,7 +323,7 @@ type DefineTableResourceOnly<T = Record<string, unknown>, C = undefined, D = und
379
323
  onBatch?: never;
380
324
  onBatchComplete?: never;
381
325
  };
382
- type DefineTableOptions<T = Record<string, unknown>, C = undefined, R = void, D extends Record<string, AnyTableHandler$1> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined> = DefineTableWithOnRecord<T, C, R, D, P, S> | DefineTableWithOnBatch<T, C, D, P, S> | DefineTableResourceOnly<T, C, D, P, S>;
326
+ type DefineTableOptions<T = Record<string, unknown>, C = undefined, R = void, D extends Record<string, AnyTableHandler$2> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined> = DefineTableWithOnRecord<T, C, R, D, P, S> | DefineTableWithOnBatch<T, C, D, P, S> | DefineTableResourceOnly<T, C, D, P, S>;
383
327
  /**
384
328
  * Internal handler object created by defineTable
385
329
  * @internal
@@ -428,7 +372,389 @@ type TableHandler<T = Record<string, unknown>, C = undefined, R = void, D = unde
428
372
  * });
429
373
  * ```
430
374
  */
431
- declare const defineTable: <T = Record<string, unknown>, C = undefined, R = void, D extends Record<string, AnyTableHandler$1> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined>(options: DefineTableOptions<T, C, R, D, P, S>) => TableHandler<T, C, R, D, P, S>;
375
+ declare const defineTable: <T = Record<string, unknown>, C = undefined, R = void, D extends Record<string, AnyTableHandler$2> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined>(options: DefineTableOptions<T, C, R, D, P, S>) => TableHandler<T, C, R, D, P, S>;
376
+
377
+ /**
378
+ * Configuration for a Lambda-served static site (API Gateway + Lambda)
379
+ */
380
+ type AppConfig = LambdaConfig & {
381
+ /** Base URL path the site is served under (e.g., "/app") */
382
+ path?: string;
383
+ /** Directory containing the static site files, relative to project root */
384
+ dir: string;
385
+ /** Default file for directory requests (default: "index.html") */
386
+ index?: string;
387
+ /** SPA mode: serve index.html for all paths that don't match a file (default: false) */
388
+ spa?: boolean;
389
+ /** Shell command to run before deploy to generate site content (e.g., "npx astro build") */
390
+ build?: string;
391
+ };
392
+ /**
393
+ * Internal handler object created by defineApp
394
+ * @internal
395
+ */
396
+ type AppHandler = {
397
+ readonly __brand: "effortless-app";
398
+ readonly config: AppConfig;
399
+ };
400
+ /**
401
+ * Deploy a static site via Lambda + API Gateway.
402
+ * Files are bundled into the Lambda ZIP and served with auto-detected content types.
403
+ *
404
+ * For CDN-backed sites (S3 + CloudFront), use {@link defineStaticSite} instead.
405
+ *
406
+ * @param options - Site configuration: path, directory, optional SPA mode
407
+ * @returns Handler object used by the deployment system
408
+ *
409
+ * @example Basic static site
410
+ * ```typescript
411
+ * export const app = defineApp({
412
+ * path: "/app",
413
+ * dir: "src/webapp",
414
+ * });
415
+ * ```
416
+ */
417
+ declare const defineApp: (options: AppConfig) => AppHandler;
418
+
419
+ /**
420
+ * Configuration for a static site handler (S3 + CloudFront)
421
+ */
422
+ type StaticSiteConfig = {
423
+ /** Handler name. Defaults to export name if not specified */
424
+ name?: string;
425
+ /** Directory containing the static site files, relative to project root */
426
+ dir: string;
427
+ /** Default file for directory requests (default: "index.html") */
428
+ index?: string;
429
+ /** SPA mode: serve index.html for all paths that don't match a file (default: false) */
430
+ spa?: boolean;
431
+ /** Shell command to run before deploy to generate site content (e.g., "npx astro build") */
432
+ build?: string;
433
+ };
434
+ /**
435
+ * Internal handler object created by defineStaticSite
436
+ * @internal
437
+ */
438
+ type StaticSiteHandler = {
439
+ readonly __brand: "effortless-static-site";
440
+ readonly config: StaticSiteConfig;
441
+ };
442
+ /**
443
+ * Deploy a static site via S3 + CloudFront CDN.
444
+ *
445
+ * @param options - Static site configuration: directory, optional SPA mode, build command
446
+ * @returns Handler object used by the deployment system
447
+ *
448
+ * @example Documentation site
449
+ * ```typescript
450
+ * export const docs = defineStaticSite({
451
+ * dir: "dist",
452
+ * build: "npx astro build",
453
+ * });
454
+ * ```
455
+ *
456
+ * @example SPA with client-side routing
457
+ * ```typescript
458
+ * export const app = defineStaticSite({
459
+ * dir: "dist",
460
+ * spa: true,
461
+ * build: "npm run build",
462
+ * });
463
+ * ```
464
+ */
465
+ declare const defineStaticSite: (options: StaticSiteConfig) => StaticSiteHandler;
466
+
467
+ type AnyTableHandler$1 = TableHandler<any, any, any, any, any, any>;
468
+ /** Maps a deps declaration to resolved runtime client types */
469
+ type ResolveDeps$1<D> = {
470
+ [K in keyof D]: D[K] extends TableHandler<infer T, any, any, any, any> ? TableClient<T> : never;
471
+ };
472
+ /**
473
+ * Parsed SQS FIFO message passed to the handler callbacks.
474
+ *
475
+ * @typeParam T - Type of the decoded message body (from schema function)
476
+ */
477
+ type FifoQueueMessage<T = unknown> = {
478
+ /** Unique message identifier */
479
+ messageId: string;
480
+ /** Receipt handle for acknowledgement */
481
+ receiptHandle: string;
482
+ /** Parsed message body (JSON-decoded, then optionally schema-validated) */
483
+ body: T;
484
+ /** Raw unparsed message body string */
485
+ rawBody: string;
486
+ /** Message group ID (FIFO ordering key) */
487
+ messageGroupId: string;
488
+ /** Message deduplication ID */
489
+ messageDeduplicationId?: string;
490
+ /** SQS message attributes */
491
+ messageAttributes: Record<string, {
492
+ dataType?: string;
493
+ stringValue?: string;
494
+ }>;
495
+ /** Approximate first receive timestamp */
496
+ approximateFirstReceiveTimestamp?: string;
497
+ /** Approximate receive count */
498
+ approximateReceiveCount?: string;
499
+ /** Sent timestamp */
500
+ sentTimestamp?: string;
501
+ };
502
+ /**
503
+ * Configuration options for a FIFO queue handler
504
+ */
505
+ type FifoQueueConfig = LambdaWithPermissions & {
506
+ /** Number of messages per Lambda invocation (1-10 for FIFO, default: 10) */
507
+ batchSize?: number;
508
+ /** Maximum time in seconds to gather messages before invoking (0-300, default: 0) */
509
+ batchWindow?: number;
510
+ /** Visibility timeout in seconds (default: max of timeout or 30) */
511
+ visibilityTimeout?: number;
512
+ /** Message retention period in seconds (60-1209600, default: 345600 = 4 days) */
513
+ retentionPeriod?: number;
514
+ /** Enable content-based deduplication (default: true) */
515
+ contentBasedDeduplication?: boolean;
516
+ };
517
+ /**
518
+ * Context factory type — conditional on whether params are declared.
519
+ * Without params: `() => C | Promise<C>`
520
+ * With params: `(args: { params: ResolveParams<P> }) => C | Promise<C>`
521
+ */
522
+ type ContextFactory$1<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
523
+ params: ResolveParams<P & {}>;
524
+ }) => C | Promise<C>;
525
+ /**
526
+ * Per-message handler function.
527
+ * Called once per message in the batch. Failures are reported individually.
528
+ */
529
+ type FifoQueueMessageFn<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = (args: {
530
+ message: FifoQueueMessage<T>;
531
+ } & ([C] extends [undefined] ? {} : {
532
+ ctx: C;
533
+ }) & ([D] extends [undefined] ? {} : {
534
+ deps: ResolveDeps$1<D>;
535
+ }) & ([P] extends [undefined] ? {} : {
536
+ params: ResolveParams<P>;
537
+ }) & ([S] extends [undefined] ? {} : {
538
+ readStatic: (path: string) => string;
539
+ })) => Promise<void>;
540
+ /**
541
+ * Batch handler function.
542
+ * Called once with all messages in the batch.
543
+ */
544
+ type FifoQueueBatchFn<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = (args: {
545
+ messages: FifoQueueMessage<T>[];
546
+ } & ([C] extends [undefined] ? {} : {
547
+ ctx: C;
548
+ }) & ([D] extends [undefined] ? {} : {
549
+ deps: ResolveDeps$1<D>;
550
+ }) & ([P] extends [undefined] ? {} : {
551
+ params: ResolveParams<P>;
552
+ }) & ([S] extends [undefined] ? {} : {
553
+ readStatic: (path: string) => string;
554
+ })) => Promise<void>;
555
+ /** Base options shared by all defineFifoQueue variants */
556
+ type DefineFifoQueueBase<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = FifoQueueConfig & {
557
+ /**
558
+ * Decode/validate function for the message body.
559
+ * Called with the JSON-parsed body; should return typed data or throw on validation failure.
560
+ */
561
+ schema?: (input: unknown) => T;
562
+ /**
563
+ * Error handler called when onMessage or onBatch throws.
564
+ * If not provided, defaults to `console.error`.
565
+ */
566
+ onError?: (error: unknown) => void;
567
+ /**
568
+ * Factory function to create context/dependencies for the handler.
569
+ * Called once on cold start, result is cached and reused across invocations.
570
+ * When params are declared, receives resolved params as argument.
571
+ */
572
+ context?: ContextFactory$1<C, P>;
573
+ /**
574
+ * Dependencies on other handlers (tables, queues, etc.).
575
+ * Typed clients are injected into the handler via the `deps` argument.
576
+ */
577
+ deps?: D;
578
+ /**
579
+ * SSM Parameter Store parameters.
580
+ * Declare with `param()` helper. Values are fetched and cached at cold start.
581
+ */
582
+ params?: P;
583
+ /**
584
+ * Static file glob patterns to bundle into the Lambda ZIP.
585
+ * Files are accessible at runtime via the `readStatic` callback argument.
586
+ */
587
+ static?: S;
588
+ };
589
+ /** Per-message processing */
590
+ type DefineFifoQueueWithOnMessage<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = DefineFifoQueueBase<T, C, D, P, S> & {
591
+ onMessage: FifoQueueMessageFn<T, C, D, P, S>;
592
+ onBatch?: never;
593
+ };
594
+ /** Batch processing: all messages at once */
595
+ type DefineFifoQueueWithOnBatch<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = DefineFifoQueueBase<T, C, D, P, S> & {
596
+ onBatch: FifoQueueBatchFn<T, C, D, P, S>;
597
+ onMessage?: never;
598
+ };
599
+ type DefineFifoQueueOptions<T = unknown, C = undefined, D extends Record<string, AnyTableHandler$1> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined> = DefineFifoQueueWithOnMessage<T, C, D, P, S> | DefineFifoQueueWithOnBatch<T, C, D, P, S>;
600
+ /**
601
+ * Internal handler object created by defineFifoQueue
602
+ * @internal
603
+ */
604
+ type FifoQueueHandler<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = {
605
+ readonly __brand: "effortless-fifo-queue";
606
+ readonly config: FifoQueueConfig;
607
+ readonly schema?: (input: unknown) => T;
608
+ readonly onError?: (error: unknown) => void;
609
+ readonly context?: (...args: any[]) => C | Promise<C>;
610
+ readonly deps?: D;
611
+ readonly params?: P;
612
+ readonly static?: string[];
613
+ readonly onMessage?: FifoQueueMessageFn<T, C, D, P, S>;
614
+ readonly onBatch?: FifoQueueBatchFn<T, C, D, P, S>;
615
+ };
616
+ /**
617
+ * Define a FIFO SQS queue with a Lambda message handler
618
+ *
619
+ * Creates:
620
+ * - SQS FIFO queue (with `.fifo` suffix)
621
+ * - Lambda function triggered by the queue
622
+ * - Event source mapping with partial batch failure support
623
+ *
624
+ * @example Per-message processing
625
+ * ```typescript
626
+ * type OrderEvent = { orderId: string; action: string };
627
+ *
628
+ * export const orderQueue = defineFifoQueue<OrderEvent>({
629
+ * onMessage: async ({ message }) => {
630
+ * console.log("Processing order:", message.body.orderId);
631
+ * }
632
+ * });
633
+ * ```
634
+ *
635
+ * @example Batch processing with schema
636
+ * ```typescript
637
+ * export const notifications = defineFifoQueue({
638
+ * schema: (input) => NotificationSchema.parse(input),
639
+ * batchSize: 5,
640
+ * onBatch: async ({ messages }) => {
641
+ * await sendAll(messages.map(m => m.body));
642
+ * }
643
+ * });
644
+ * ```
645
+ */
646
+ declare const defineFifoQueue: <T = unknown, C = undefined, D extends Record<string, AnyTableHandler$1> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined>(options: DefineFifoQueueOptions<T, C, D, P, S>) => FifoQueueHandler<T, C, D, P, S>;
647
+
648
+ type AwsService = "dynamodb" | "s3" | "sqs" | "sns" | "ses" | "ssm" | "lambda" | "events" | "secretsmanager" | "cognito-idp" | "logs";
649
+ type Permission = `${AwsService}:${string}` | (string & {});
650
+ /** Logging verbosity level for Lambda handlers */
651
+ type LogLevel = "error" | "info" | "debug";
652
+ /**
653
+ * Common Lambda configuration shared by all handler types.
654
+ */
655
+ type LambdaConfig = {
656
+ /** Handler name. Defaults to export name if not specified */
657
+ name?: string;
658
+ /** Lambda memory in MB (default: 256) */
659
+ memory?: number;
660
+ /** Lambda timeout in seconds (default: 30) */
661
+ timeout?: number;
662
+ /** Logging verbosity: "error" (errors only), "info" (+ execution summary), "debug" (+ input/output). Default: "info" */
663
+ logLevel?: LogLevel;
664
+ };
665
+ /**
666
+ * Lambda configuration with additional IAM permissions.
667
+ * Used by handler types that support custom permissions (http, table, fifo-queue).
668
+ */
669
+ type LambdaWithPermissions = LambdaConfig & {
670
+ /** Additional IAM permissions for the Lambda */
671
+ permissions?: Permission[];
672
+ };
673
+ type AnyParamRef = ParamRef<any>;
674
+ /**
675
+ * Reference to an SSM Parameter Store parameter.
676
+ *
677
+ * @typeParam T - The resolved type after optional transform (default: string)
678
+ */
679
+ type ParamRef<T = string> = {
680
+ readonly __brand: "effortless-param";
681
+ readonly key: string;
682
+ readonly transform?: (raw: string) => T;
683
+ };
684
+ /**
685
+ * Maps a params declaration to resolved value types.
686
+ *
687
+ * @typeParam P - Record of param names to ParamRef instances
688
+ */
689
+ type ResolveParams<P> = {
690
+ [K in keyof P]: P[K] extends ParamRef<infer T> ? T : never;
691
+ };
692
+ /**
693
+ * Declare an SSM Parameter Store parameter.
694
+ *
695
+ * The key is combined with project and stage at deploy time to form the full
696
+ * SSM path: `/${project}/${stage}/${key}`.
697
+ *
698
+ * @param key - Parameter key (e.g., "database-url")
699
+ * @param transform - Optional function to transform the raw string value
700
+ * @returns A ParamRef used by the deployment and runtime systems
701
+ *
702
+ * @example Simple string parameter
703
+ * ```typescript
704
+ * params: {
705
+ * dbUrl: param("database-url"),
706
+ * }
707
+ * ```
708
+ *
709
+ * @example With transform (e.g., TOML parsing)
710
+ * ```typescript
711
+ * import TOML from "smol-toml";
712
+ *
713
+ * params: {
714
+ * config: param("app-config", TOML.parse),
715
+ * }
716
+ * ```
717
+ */
718
+ declare function param(key: string): ParamRef<string>;
719
+ declare function param<T>(key: string, transform: (raw: string) => T): ParamRef<T>;
720
+ /**
721
+ * Type-only schema helper for handlers.
722
+ *
723
+ * Use this instead of explicit generic parameters like `defineTable<Order>(...)`.
724
+ * It enables TypeScript to infer all generic types from the options object,
725
+ * avoiding the partial-inference problem where specifying one generic
726
+ * forces all others to their defaults.
727
+ *
728
+ * At runtime this is a no-op identity function — it simply returns the input unchanged.
729
+ * The type narrowing happens entirely at the TypeScript level.
730
+ *
731
+ * @example Resource-only table
732
+ * ```typescript
733
+ * type User = { id: string; email: string };
734
+ *
735
+ * // Before (breaks inference for context, deps, params):
736
+ * export const users = defineTable<User>({ pk: { name: "id", type: "string" } });
737
+ *
738
+ * // After (all generics inferred correctly):
739
+ * export const users = defineTable({
740
+ * pk: { name: "id", type: "string" },
741
+ * schema: typed<User>(),
742
+ * });
743
+ * ```
744
+ *
745
+ * @example Table with stream handler
746
+ * ```typescript
747
+ * export const orders = defineTable({
748
+ * pk: { name: "id", type: "string" },
749
+ * schema: typed<Order>(),
750
+ * context: async () => ({ db: createClient() }),
751
+ * onRecord: async ({ record, ctx }) => {
752
+ * // record.new is Order, ctx is { db: Client } — all inferred
753
+ * },
754
+ * });
755
+ * ```
756
+ */
757
+ declare function typed<T>(): (input: unknown) => T;
432
758
 
433
759
  type AnyTableHandler = TableHandler<any, any, any, any, any, any>;
434
760
  /** Maps a deps declaration to resolved runtime client types */
@@ -484,21 +810,11 @@ type HttpResponse = {
484
810
  /**
485
811
  * Configuration options extracted from DefineHttpOptions (without onRequest callback)
486
812
  */
487
- type HttpConfig = {
488
- /** Handler name. Defaults to export name if not specified */
489
- name?: string;
813
+ type HttpConfig = LambdaWithPermissions & {
490
814
  /** HTTP method for the route */
491
815
  method: HttpMethod;
492
816
  /** Route path (e.g., "/api/users", "/api/users/{id}") */
493
817
  path: string;
494
- /** Lambda memory in MB (default: 256) */
495
- memory?: number;
496
- /** Lambda timeout in seconds (default: 30) */
497
- timeout?: number;
498
- /** Additional IAM permissions for the Lambda */
499
- permissions?: Permission[];
500
- /** Enable observability logging to platform table (default: true) */
501
- observe?: boolean;
502
818
  };
503
819
  /**
504
820
  * Handler function type for HTTP endpoints
@@ -639,141 +955,4 @@ type HttpHandler<T = undefined, C = undefined, D = undefined, P = undefined, S e
639
955
  */
640
956
  declare const defineHttp: <T = undefined, C = undefined, D extends Record<string, AnyTableHandler> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined>(options: DefineHttpOptions<T, C, D, P, S>) => HttpHandler<T, C, D, P, S>;
641
957
 
642
- /**
643
- * Configuration for a Lambda-served static site (API Gateway + Lambda)
644
- */
645
- type AppConfig = {
646
- /** Handler name. Defaults to export name if not specified */
647
- name?: string;
648
- /** Base URL path the site is served under (e.g., "/app") */
649
- path?: string;
650
- /** Directory containing the static site files, relative to project root */
651
- dir: string;
652
- /** Default file for directory requests (default: "index.html") */
653
- index?: string;
654
- /** SPA mode: serve index.html for all paths that don't match a file (default: false) */
655
- spa?: boolean;
656
- /** Shell command to run before deploy to generate site content (e.g., "npx astro build") */
657
- build?: string;
658
- /** Lambda memory in MB (default: 256) */
659
- memory?: number;
660
- /** Lambda timeout in seconds (default: 5) */
661
- timeout?: number;
662
- /** Enable observability logging to platform table (default: false) */
663
- observe?: boolean;
664
- };
665
- /**
666
- * Internal handler object created by defineApp
667
- * @internal
668
- */
669
- type AppHandler = {
670
- readonly __brand: "effortless-app";
671
- readonly config: AppConfig;
672
- };
673
- /**
674
- * Deploy a static site via Lambda + API Gateway.
675
- * Files are bundled into the Lambda ZIP and served with auto-detected content types.
676
- *
677
- * For CDN-backed sites (S3 + CloudFront), use {@link defineStaticSite} instead.
678
- *
679
- * @param options - Site configuration: path, directory, optional SPA mode
680
- * @returns Handler object used by the deployment system
681
- *
682
- * @example Basic static site
683
- * ```typescript
684
- * export const app = defineApp({
685
- * path: "/app",
686
- * dir: "src/webapp",
687
- * });
688
- * ```
689
- */
690
- declare const defineApp: (options: AppConfig) => AppHandler;
691
-
692
- /**
693
- * Configuration for a static site handler (S3 + CloudFront)
694
- */
695
- type StaticSiteConfig = {
696
- /** Handler name. Defaults to export name if not specified */
697
- name?: string;
698
- /** Directory containing the static site files, relative to project root */
699
- dir: string;
700
- /** Default file for directory requests (default: "index.html") */
701
- index?: string;
702
- /** SPA mode: serve index.html for all paths that don't match a file (default: false) */
703
- spa?: boolean;
704
- /** Shell command to run before deploy to generate site content (e.g., "npx astro build") */
705
- build?: string;
706
- };
707
- /**
708
- * Internal handler object created by defineStaticSite
709
- * @internal
710
- */
711
- type StaticSiteHandler = {
712
- readonly __brand: "effortless-static-site";
713
- readonly config: StaticSiteConfig;
714
- };
715
- /**
716
- * Deploy a static site via S3 + CloudFront CDN.
717
- *
718
- * @param options - Static site configuration: directory, optional SPA mode, build command
719
- * @returns Handler object used by the deployment system
720
- *
721
- * @example Documentation site
722
- * ```typescript
723
- * export const docs = defineStaticSite({
724
- * dir: "dist",
725
- * build: "npx astro build",
726
- * });
727
- * ```
728
- *
729
- * @example SPA with client-side routing
730
- * ```typescript
731
- * export const app = defineStaticSite({
732
- * dir: "dist",
733
- * spa: true,
734
- * build: "npm run build",
735
- * });
736
- * ```
737
- */
738
- declare const defineStaticSite: (options: StaticSiteConfig) => StaticSiteHandler;
739
-
740
- type BasePlatformEntity = {
741
- pk: string;
742
- sk: string;
743
- type: string;
744
- ttl?: number;
745
- };
746
- type ExecutionEntry = {
747
- id: string;
748
- ts: string;
749
- ms: number;
750
- in: unknown;
751
- out?: unknown;
752
- };
753
- type ErrorEntry = {
754
- id: string;
755
- ts: string;
756
- ms: number;
757
- in: unknown;
758
- err: string;
759
- };
760
- type ExecutionLogEntity = BasePlatformEntity & {
761
- type: "execution-log";
762
- handlerName: string;
763
- handlerType: "http" | "table";
764
- executions: ExecutionEntry[];
765
- errors: ErrorEntry[];
766
- };
767
- type PlatformEntity = ExecutionLogEntity;
768
-
769
- type PlatformClient = {
770
- appendExecution(handlerName: string, handlerType: "http" | "table" | "app", entry: ExecutionEntry): Promise<void>;
771
- appendError(handlerName: string, handlerType: "http" | "table" | "app", entry: ErrorEntry): Promise<void>;
772
- get<T extends PlatformEntity>(pk: string, sk: string): Promise<T | undefined>;
773
- query<T extends PlatformEntity>(pk: string, skPrefix?: string): Promise<T[]>;
774
- put(entity: PlatformEntity): Promise<void>;
775
- tableName: string;
776
- };
777
- declare const createPlatformClient: () => PlatformClient | undefined;
778
-
779
- export { type AppConfig, type AppHandler, type BasePlatformEntity, type ContentType, type DefineHttpOptions, type DefineTableOptions, type EffortlessConfig, type ErrorEntry, type ExecutionEntry, type ExecutionLogEntity, type FailedRecord, type HttpConfig, type HttpHandler, type HttpHandlerFn, type HttpMethod, type HttpRequest, type HttpResponse, type KeyType, type ParamRef, type PlatformClient, type PlatformEntity, type QueryParams, type ResolveDeps, type ResolveParams, type StaticSiteConfig, type StaticSiteHandler, type StreamView, type TableBatchCompleteFn, type TableBatchFn, type TableClient, type TableConfig, type TableHandler, type TableKey, type TableRecord, type TableRecordFn, createPlatformClient, defineApp, defineConfig, defineHttp, defineStaticSite, defineTable, param };
958
+ export { type AppConfig, type AppHandler, type ContentType, type DefineFifoQueueOptions, type DefineHttpOptions, type DefineTableOptions, type EffortlessConfig, type FailedRecord, type FifoQueueBatchFn, type FifoQueueConfig, type FifoQueueHandler, type FifoQueueMessage, type FifoQueueMessageFn, type HttpConfig, type HttpHandler, type HttpHandlerFn, type HttpMethod, type HttpRequest, type HttpResponse, type KeyType, type LambdaConfig, type LambdaWithPermissions, type LogLevel, type ParamRef, type QueryParams, type ResolveDeps, type ResolveParams, type StaticSiteConfig, type StaticSiteHandler, type StreamView, type TableBatchCompleteFn, type TableBatchFn, type TableClient, type TableConfig, type TableHandler, type TableKey, type TableRecord, type TableRecordFn, defineApp, defineConfig, defineFifoQueue, defineHttp, defineStaticSite, defineTable, param, typed };