effortless-aws 0.5.0 → 0.6.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/cli/index.js +455 -158
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +250 -20
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/wrap-fifo-queue.js +84 -0
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -191,9 +191,9 @@ type ResolveParams<P> = {
|
|
|
191
191
|
declare function param(key: string): ParamRef<string>;
|
|
192
192
|
declare function param<T>(key: string, transform: (raw: string) => T): ParamRef<T>;
|
|
193
193
|
|
|
194
|
-
type AnyTableHandler$
|
|
194
|
+
type AnyTableHandler$2 = TableHandler<any, any, any, any, any, any>;
|
|
195
195
|
/** Maps a deps declaration to resolved runtime client types */
|
|
196
|
-
type ResolveDeps$
|
|
196
|
+
type ResolveDeps$2<D> = {
|
|
197
197
|
[K in keyof D]: D[K] extends TableHandler<infer T, any, any, any, any> ? TableClient<T> : never;
|
|
198
198
|
};
|
|
199
199
|
/** DynamoDB attribute types for keys */
|
|
@@ -275,7 +275,7 @@ type FailedRecord<T = Record<string, unknown>> = {
|
|
|
275
275
|
* Without params: `() => C | Promise<C>`
|
|
276
276
|
* With params: `(args: { params: ResolveParams<P> }) => C | Promise<C>`
|
|
277
277
|
*/
|
|
278
|
-
type ContextFactory$
|
|
278
|
+
type ContextFactory$2<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
|
|
279
279
|
params: ResolveParams<P & {}>;
|
|
280
280
|
}) => C | Promise<C>;
|
|
281
281
|
/**
|
|
@@ -287,7 +287,7 @@ type TableRecordFn<T = Record<string, unknown>, C = undefined, R = void, D = und
|
|
|
287
287
|
} & ([C] extends [undefined] ? {} : {
|
|
288
288
|
ctx: C;
|
|
289
289
|
}) & ([D] extends [undefined] ? {} : {
|
|
290
|
-
deps: ResolveDeps$
|
|
290
|
+
deps: ResolveDeps$2<D>;
|
|
291
291
|
}) & ([P] extends [undefined] ? {} : {
|
|
292
292
|
params: ResolveParams<P>;
|
|
293
293
|
}) & ([S] extends [undefined] ? {} : {
|
|
@@ -303,7 +303,7 @@ type TableBatchCompleteFn<T = Record<string, unknown>, C = undefined, R = void,
|
|
|
303
303
|
} & ([C] extends [undefined] ? {} : {
|
|
304
304
|
ctx: C;
|
|
305
305
|
}) & ([D] extends [undefined] ? {} : {
|
|
306
|
-
deps: ResolveDeps$
|
|
306
|
+
deps: ResolveDeps$2<D>;
|
|
307
307
|
}) & ([P] extends [undefined] ? {} : {
|
|
308
308
|
params: ResolveParams<P>;
|
|
309
309
|
}) & ([S] extends [undefined] ? {} : {
|
|
@@ -318,7 +318,7 @@ type TableBatchFn<T = Record<string, unknown>, C = undefined, D = undefined, P =
|
|
|
318
318
|
} & ([C] extends [undefined] ? {} : {
|
|
319
319
|
ctx: C;
|
|
320
320
|
}) & ([D] extends [undefined] ? {} : {
|
|
321
|
-
deps: ResolveDeps$
|
|
321
|
+
deps: ResolveDeps$2<D>;
|
|
322
322
|
}) & ([P] extends [undefined] ? {} : {
|
|
323
323
|
params: ResolveParams<P>;
|
|
324
324
|
}) & ([S] extends [undefined] ? {} : {
|
|
@@ -343,7 +343,7 @@ type DefineTableBase<T = Record<string, unknown>, C = undefined, D = undefined,
|
|
|
343
343
|
* When params are declared, receives resolved params as argument.
|
|
344
344
|
* Supports both sync and async return values.
|
|
345
345
|
*/
|
|
346
|
-
context?: ContextFactory$
|
|
346
|
+
context?: ContextFactory$2<C, P>;
|
|
347
347
|
/**
|
|
348
348
|
* Dependencies on other handlers (tables, queues, etc.).
|
|
349
349
|
* Typed clients are injected into the handler via the `deps` argument.
|
|
@@ -379,7 +379,7 @@ type DefineTableResourceOnly<T = Record<string, unknown>, C = undefined, D = und
|
|
|
379
379
|
onBatch?: never;
|
|
380
380
|
onBatchComplete?: never;
|
|
381
381
|
};
|
|
382
|
-
type DefineTableOptions<T = Record<string, unknown>, C = undefined, R = void, D extends Record<string, AnyTableHandler$
|
|
382
|
+
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
383
|
/**
|
|
384
384
|
* Internal handler object created by defineTable
|
|
385
385
|
* @internal
|
|
@@ -428,11 +428,11 @@ type TableHandler<T = Record<string, unknown>, C = undefined, R = void, D = unde
|
|
|
428
428
|
* });
|
|
429
429
|
* ```
|
|
430
430
|
*/
|
|
431
|
-
declare const defineTable: <T = Record<string, unknown>, C = undefined, R = void, D extends Record<string, AnyTableHandler$
|
|
431
|
+
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>;
|
|
432
432
|
|
|
433
|
-
type AnyTableHandler = TableHandler<any, any, any, any, any, any>;
|
|
433
|
+
type AnyTableHandler$1 = TableHandler<any, any, any, any, any, any>;
|
|
434
434
|
/** Maps a deps declaration to resolved runtime client types */
|
|
435
|
-
type ResolveDeps<D> = {
|
|
435
|
+
type ResolveDeps$1<D> = {
|
|
436
436
|
[K in keyof D]: D[K] extends TableHandler<infer T, any, any, any, any> ? TableClient<T> : never;
|
|
437
437
|
};
|
|
438
438
|
/** HTTP methods supported by API Gateway */
|
|
@@ -515,7 +515,7 @@ type HttpHandlerFn<T = undefined, C = undefined, D = undefined, P = undefined, S
|
|
|
515
515
|
}) & ([C] extends [undefined] ? {} : {
|
|
516
516
|
ctx: C;
|
|
517
517
|
}) & ([D] extends [undefined] ? {} : {
|
|
518
|
-
deps: ResolveDeps<D>;
|
|
518
|
+
deps: ResolveDeps$1<D>;
|
|
519
519
|
}) & ([P] extends [undefined] ? {} : {
|
|
520
520
|
params: ResolveParams<P>;
|
|
521
521
|
}) & ([S] extends [undefined] ? {} : {
|
|
@@ -526,7 +526,7 @@ type HttpHandlerFn<T = undefined, C = undefined, D = undefined, P = undefined, S
|
|
|
526
526
|
* Without params: `() => C | Promise<C>`
|
|
527
527
|
* With params: `(args: { params: ResolveParams<P> }) => C | Promise<C>`
|
|
528
528
|
*/
|
|
529
|
-
type ContextFactory<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
|
|
529
|
+
type ContextFactory$1<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
|
|
530
530
|
params: ResolveParams<P & {}>;
|
|
531
531
|
}) => C | Promise<C>;
|
|
532
532
|
/**
|
|
@@ -537,7 +537,7 @@ type ContextFactory<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (ar
|
|
|
537
537
|
* @typeParam D - Type of the deps (from deps declaration)
|
|
538
538
|
* @typeParam P - Type of the params (from params declaration)
|
|
539
539
|
*/
|
|
540
|
-
type DefineHttpOptions<T = undefined, C = undefined, D extends Record<string, AnyTableHandler> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined> = HttpConfig & {
|
|
540
|
+
type DefineHttpOptions<T = undefined, C = undefined, D extends Record<string, AnyTableHandler$1> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined> = HttpConfig & {
|
|
541
541
|
/**
|
|
542
542
|
* Decode/validate function for the request body.
|
|
543
543
|
* Called with the parsed body; should return typed data or throw on validation failure.
|
|
@@ -560,7 +560,7 @@ type DefineHttpOptions<T = undefined, C = undefined, D extends Record<string, An
|
|
|
560
560
|
* When params are declared, receives resolved params as argument.
|
|
561
561
|
* Supports both sync and async return values.
|
|
562
562
|
*/
|
|
563
|
-
context?: ContextFactory<C, P>;
|
|
563
|
+
context?: ContextFactory$1<C, P>;
|
|
564
564
|
/**
|
|
565
565
|
* Dependencies on other handlers (tables, queues, etc.).
|
|
566
566
|
* Typed clients are injected into the handler via the `deps` argument.
|
|
@@ -637,7 +637,7 @@ type HttpHandler<T = undefined, C = undefined, D = undefined, P = undefined, S e
|
|
|
637
637
|
* });
|
|
638
638
|
* ```
|
|
639
639
|
*/
|
|
640
|
-
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>;
|
|
640
|
+
declare const defineHttp: <T = undefined, C = undefined, D extends Record<string, AnyTableHandler$1> | 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
641
|
|
|
642
642
|
/**
|
|
643
643
|
* Configuration for a Lambda-served static site (API Gateway + Lambda)
|
|
@@ -737,6 +737,236 @@ type StaticSiteHandler = {
|
|
|
737
737
|
*/
|
|
738
738
|
declare const defineStaticSite: (options: StaticSiteConfig) => StaticSiteHandler;
|
|
739
739
|
|
|
740
|
+
type AnyTableHandler = TableHandler<any, any, any, any, any, any>;
|
|
741
|
+
/** Maps a deps declaration to resolved runtime client types */
|
|
742
|
+
type ResolveDeps<D> = {
|
|
743
|
+
[K in keyof D]: D[K] extends TableHandler<infer T, any, any, any, any> ? TableClient<T> : never;
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* Parsed SQS FIFO message passed to the handler callbacks.
|
|
747
|
+
*
|
|
748
|
+
* @typeParam T - Type of the decoded message body (from schema function)
|
|
749
|
+
*/
|
|
750
|
+
type FifoQueueMessage<T = unknown> = {
|
|
751
|
+
/** Unique message identifier */
|
|
752
|
+
messageId: string;
|
|
753
|
+
/** Receipt handle for acknowledgement */
|
|
754
|
+
receiptHandle: string;
|
|
755
|
+
/** Parsed message body (JSON-decoded, then optionally schema-validated) */
|
|
756
|
+
body: T;
|
|
757
|
+
/** Raw unparsed message body string */
|
|
758
|
+
rawBody: string;
|
|
759
|
+
/** Message group ID (FIFO ordering key) */
|
|
760
|
+
messageGroupId: string;
|
|
761
|
+
/** Message deduplication ID */
|
|
762
|
+
messageDeduplicationId?: string;
|
|
763
|
+
/** SQS message attributes */
|
|
764
|
+
messageAttributes: Record<string, {
|
|
765
|
+
dataType?: string;
|
|
766
|
+
stringValue?: string;
|
|
767
|
+
}>;
|
|
768
|
+
/** Approximate first receive timestamp */
|
|
769
|
+
approximateFirstReceiveTimestamp?: string;
|
|
770
|
+
/** Approximate receive count */
|
|
771
|
+
approximateReceiveCount?: string;
|
|
772
|
+
/** Sent timestamp */
|
|
773
|
+
sentTimestamp?: string;
|
|
774
|
+
};
|
|
775
|
+
/**
|
|
776
|
+
* Configuration options for a FIFO queue handler
|
|
777
|
+
*/
|
|
778
|
+
type FifoQueueConfig = {
|
|
779
|
+
/** Handler name. Defaults to export name if not specified */
|
|
780
|
+
name?: string;
|
|
781
|
+
/** Number of messages per Lambda invocation (1-10 for FIFO, default: 10) */
|
|
782
|
+
batchSize?: number;
|
|
783
|
+
/** Maximum time in seconds to gather messages before invoking (0-300, default: 0) */
|
|
784
|
+
batchWindow?: number;
|
|
785
|
+
/** Visibility timeout in seconds (default: max of timeout or 30) */
|
|
786
|
+
visibilityTimeout?: number;
|
|
787
|
+
/** Message retention period in seconds (60-1209600, default: 345600 = 4 days) */
|
|
788
|
+
retentionPeriod?: number;
|
|
789
|
+
/** Enable content-based deduplication (default: true) */
|
|
790
|
+
contentBasedDeduplication?: boolean;
|
|
791
|
+
/** Lambda memory in MB (default: 256) */
|
|
792
|
+
memory?: number;
|
|
793
|
+
/** Lambda timeout in seconds (default: 30) */
|
|
794
|
+
timeout?: number;
|
|
795
|
+
/** Additional IAM permissions for the Lambda */
|
|
796
|
+
permissions?: Permission[];
|
|
797
|
+
/** Enable observability logging to platform table (default: true) */
|
|
798
|
+
observe?: boolean;
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* Context factory type — conditional on whether params are declared.
|
|
802
|
+
* Without params: `() => C | Promise<C>`
|
|
803
|
+
* With params: `(args: { params: ResolveParams<P> }) => C | Promise<C>`
|
|
804
|
+
*/
|
|
805
|
+
type ContextFactory<C, P> = [P] extends [undefined] ? () => C | Promise<C> : (args: {
|
|
806
|
+
params: ResolveParams<P & {}>;
|
|
807
|
+
}) => C | Promise<C>;
|
|
808
|
+
/**
|
|
809
|
+
* Per-message handler function.
|
|
810
|
+
* Called once per message in the batch. Failures are reported individually.
|
|
811
|
+
*/
|
|
812
|
+
type FifoQueueMessageFn<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = (args: {
|
|
813
|
+
message: FifoQueueMessage<T>;
|
|
814
|
+
} & ([C] extends [undefined] ? {} : {
|
|
815
|
+
ctx: C;
|
|
816
|
+
}) & ([D] extends [undefined] ? {} : {
|
|
817
|
+
deps: ResolveDeps<D>;
|
|
818
|
+
}) & ([P] extends [undefined] ? {} : {
|
|
819
|
+
params: ResolveParams<P>;
|
|
820
|
+
}) & ([S] extends [undefined] ? {} : {
|
|
821
|
+
readStatic: (path: string) => string;
|
|
822
|
+
})) => Promise<void>;
|
|
823
|
+
/**
|
|
824
|
+
* Batch handler function.
|
|
825
|
+
* Called once with all messages in the batch.
|
|
826
|
+
*/
|
|
827
|
+
type FifoQueueBatchFn<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = (args: {
|
|
828
|
+
messages: FifoQueueMessage<T>[];
|
|
829
|
+
} & ([C] extends [undefined] ? {} : {
|
|
830
|
+
ctx: C;
|
|
831
|
+
}) & ([D] extends [undefined] ? {} : {
|
|
832
|
+
deps: ResolveDeps<D>;
|
|
833
|
+
}) & ([P] extends [undefined] ? {} : {
|
|
834
|
+
params: ResolveParams<P>;
|
|
835
|
+
}) & ([S] extends [undefined] ? {} : {
|
|
836
|
+
readStatic: (path: string) => string;
|
|
837
|
+
})) => Promise<void>;
|
|
838
|
+
/** Base options shared by all defineFifoQueue variants */
|
|
839
|
+
type DefineFifoQueueBase<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = FifoQueueConfig & {
|
|
840
|
+
/**
|
|
841
|
+
* Decode/validate function for the message body.
|
|
842
|
+
* Called with the JSON-parsed body; should return typed data or throw on validation failure.
|
|
843
|
+
*/
|
|
844
|
+
schema?: (input: unknown) => T;
|
|
845
|
+
/**
|
|
846
|
+
* Error handler called when onMessage or onBatch throws.
|
|
847
|
+
* If not provided, defaults to `console.error`.
|
|
848
|
+
*/
|
|
849
|
+
onError?: (error: unknown) => void;
|
|
850
|
+
/**
|
|
851
|
+
* Factory function to create context/dependencies for the handler.
|
|
852
|
+
* Called once on cold start, result is cached and reused across invocations.
|
|
853
|
+
* When params are declared, receives resolved params as argument.
|
|
854
|
+
*/
|
|
855
|
+
context?: ContextFactory<C, P>;
|
|
856
|
+
/**
|
|
857
|
+
* Dependencies on other handlers (tables, queues, etc.).
|
|
858
|
+
* Typed clients are injected into the handler via the `deps` argument.
|
|
859
|
+
*/
|
|
860
|
+
deps?: D;
|
|
861
|
+
/**
|
|
862
|
+
* SSM Parameter Store parameters.
|
|
863
|
+
* Declare with `param()` helper. Values are fetched and cached at cold start.
|
|
864
|
+
*/
|
|
865
|
+
params?: P;
|
|
866
|
+
/**
|
|
867
|
+
* Static file glob patterns to bundle into the Lambda ZIP.
|
|
868
|
+
* Files are accessible at runtime via the `readStatic` callback argument.
|
|
869
|
+
*/
|
|
870
|
+
static?: S;
|
|
871
|
+
};
|
|
872
|
+
/** Per-message processing */
|
|
873
|
+
type DefineFifoQueueWithOnMessage<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = DefineFifoQueueBase<T, C, D, P, S> & {
|
|
874
|
+
onMessage: FifoQueueMessageFn<T, C, D, P, S>;
|
|
875
|
+
onBatch?: never;
|
|
876
|
+
};
|
|
877
|
+
/** Batch processing: all messages at once */
|
|
878
|
+
type DefineFifoQueueWithOnBatch<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = DefineFifoQueueBase<T, C, D, P, S> & {
|
|
879
|
+
onBatch: FifoQueueBatchFn<T, C, D, P, S>;
|
|
880
|
+
onMessage?: never;
|
|
881
|
+
};
|
|
882
|
+
type DefineFifoQueueOptions<T = unknown, C = undefined, D extends Record<string, AnyTableHandler> | 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>;
|
|
883
|
+
/**
|
|
884
|
+
* Internal handler object created by defineFifoQueue
|
|
885
|
+
* @internal
|
|
886
|
+
*/
|
|
887
|
+
type FifoQueueHandler<T = unknown, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = {
|
|
888
|
+
readonly __brand: "effortless-fifo-queue";
|
|
889
|
+
readonly config: FifoQueueConfig;
|
|
890
|
+
readonly schema?: (input: unknown) => T;
|
|
891
|
+
readonly onError?: (error: unknown) => void;
|
|
892
|
+
readonly context?: (...args: any[]) => C | Promise<C>;
|
|
893
|
+
readonly deps?: D;
|
|
894
|
+
readonly params?: P;
|
|
895
|
+
readonly static?: string[];
|
|
896
|
+
readonly onMessage?: FifoQueueMessageFn<T, C, D, P, S>;
|
|
897
|
+
readonly onBatch?: FifoQueueBatchFn<T, C, D, P, S>;
|
|
898
|
+
};
|
|
899
|
+
/**
|
|
900
|
+
* Define a FIFO SQS queue with a Lambda message handler
|
|
901
|
+
*
|
|
902
|
+
* Creates:
|
|
903
|
+
* - SQS FIFO queue (with `.fifo` suffix)
|
|
904
|
+
* - Lambda function triggered by the queue
|
|
905
|
+
* - Event source mapping with partial batch failure support
|
|
906
|
+
*
|
|
907
|
+
* @example Per-message processing
|
|
908
|
+
* ```typescript
|
|
909
|
+
* type OrderEvent = { orderId: string; action: string };
|
|
910
|
+
*
|
|
911
|
+
* export const orderQueue = defineFifoQueue<OrderEvent>({
|
|
912
|
+
* onMessage: async ({ message }) => {
|
|
913
|
+
* console.log("Processing order:", message.body.orderId);
|
|
914
|
+
* }
|
|
915
|
+
* });
|
|
916
|
+
* ```
|
|
917
|
+
*
|
|
918
|
+
* @example Batch processing with schema
|
|
919
|
+
* ```typescript
|
|
920
|
+
* export const notifications = defineFifoQueue({
|
|
921
|
+
* schema: (input) => NotificationSchema.parse(input),
|
|
922
|
+
* batchSize: 5,
|
|
923
|
+
* onBatch: async ({ messages }) => {
|
|
924
|
+
* await sendAll(messages.map(m => m.body));
|
|
925
|
+
* }
|
|
926
|
+
* });
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
declare const defineFifoQueue: <T = unknown, C = undefined, D extends Record<string, AnyTableHandler> | 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>;
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* Type-only schema helper for handlers.
|
|
933
|
+
*
|
|
934
|
+
* Use this instead of explicit generic parameters like `defineTable<Order>(...)`.
|
|
935
|
+
* It enables TypeScript to infer all generic types from the options object,
|
|
936
|
+
* avoiding the partial-inference problem where specifying one generic
|
|
937
|
+
* forces all others to their defaults.
|
|
938
|
+
*
|
|
939
|
+
* At runtime this is a no-op identity function — it simply returns the input unchanged.
|
|
940
|
+
* The type narrowing happens entirely at the TypeScript level.
|
|
941
|
+
*
|
|
942
|
+
* @example Resource-only table
|
|
943
|
+
* ```typescript
|
|
944
|
+
* type User = { id: string; email: string };
|
|
945
|
+
*
|
|
946
|
+
* // Before (breaks inference for context, deps, params):
|
|
947
|
+
* export const users = defineTable<User>({ pk: { name: "id", type: "string" } });
|
|
948
|
+
*
|
|
949
|
+
* // After (all generics inferred correctly):
|
|
950
|
+
* export const users = defineTable({
|
|
951
|
+
* pk: { name: "id", type: "string" },
|
|
952
|
+
* schema: typed<User>(),
|
|
953
|
+
* });
|
|
954
|
+
* ```
|
|
955
|
+
*
|
|
956
|
+
* @example Table with stream handler
|
|
957
|
+
* ```typescript
|
|
958
|
+
* export const orders = defineTable({
|
|
959
|
+
* pk: { name: "id", type: "string" },
|
|
960
|
+
* schema: typed<Order>(),
|
|
961
|
+
* context: async () => ({ db: createClient() }),
|
|
962
|
+
* onRecord: async ({ record, ctx }) => {
|
|
963
|
+
* // record.new is Order, ctx is { db: Client } — all inferred
|
|
964
|
+
* },
|
|
965
|
+
* });
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
declare function typed<T>(): (input: unknown) => T;
|
|
969
|
+
|
|
740
970
|
type BasePlatformEntity = {
|
|
741
971
|
pk: string;
|
|
742
972
|
sk: string;
|
|
@@ -760,15 +990,15 @@ type ErrorEntry = {
|
|
|
760
990
|
type ExecutionLogEntity = BasePlatformEntity & {
|
|
761
991
|
type: "execution-log";
|
|
762
992
|
handlerName: string;
|
|
763
|
-
handlerType: "http" | "table";
|
|
993
|
+
handlerType: "http" | "table" | "app" | "fifo-queue";
|
|
764
994
|
executions: ExecutionEntry[];
|
|
765
995
|
errors: ErrorEntry[];
|
|
766
996
|
};
|
|
767
997
|
type PlatformEntity = ExecutionLogEntity;
|
|
768
998
|
|
|
769
999
|
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>;
|
|
1000
|
+
appendExecution(handlerName: string, handlerType: "http" | "table" | "app" | "fifo-queue", entry: ExecutionEntry): Promise<void>;
|
|
1001
|
+
appendError(handlerName: string, handlerType: "http" | "table" | "app" | "fifo-queue", entry: ErrorEntry): Promise<void>;
|
|
772
1002
|
get<T extends PlatformEntity>(pk: string, sk: string): Promise<T | undefined>;
|
|
773
1003
|
query<T extends PlatformEntity>(pk: string, skPrefix?: string): Promise<T[]>;
|
|
774
1004
|
put(entity: PlatformEntity): Promise<void>;
|
|
@@ -776,4 +1006,4 @@ type PlatformClient = {
|
|
|
776
1006
|
};
|
|
777
1007
|
declare const createPlatformClient: () => PlatformClient | undefined;
|
|
778
1008
|
|
|
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 };
|
|
1009
|
+
export { type AppConfig, type AppHandler, type BasePlatformEntity, type ContentType, type DefineFifoQueueOptions, type DefineHttpOptions, type DefineTableOptions, type EffortlessConfig, type ErrorEntry, type ExecutionEntry, type ExecutionLogEntity, 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 ParamRef, type PlatformClient, type PlatformEntity, type QueryParams, type ResolveDeps$1 as 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, defineFifoQueue, defineHttp, defineStaticSite, defineTable, param, typed };
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,23 @@ var defineStaticSite = (options) => ({
|
|
|
47
47
|
config: options
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
// src/handlers/define-fifo-queue.ts
|
|
51
|
+
var defineFifoQueue = (options) => {
|
|
52
|
+
const { onMessage, onBatch, onError, schema, context, deps, params, static: staticFiles, ...config } = options;
|
|
53
|
+
return {
|
|
54
|
+
__brand: "effortless-fifo-queue",
|
|
55
|
+
config,
|
|
56
|
+
...schema ? { schema } : {},
|
|
57
|
+
...onError ? { onError } : {},
|
|
58
|
+
...context ? { context } : {},
|
|
59
|
+
...deps ? { deps } : {},
|
|
60
|
+
...params ? { params } : {},
|
|
61
|
+
...staticFiles ? { static: staticFiles } : {},
|
|
62
|
+
...onMessage ? { onMessage } : {},
|
|
63
|
+
...onBatch ? { onBatch } : {}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
50
67
|
// src/handlers/param.ts
|
|
51
68
|
function param(key, transform) {
|
|
52
69
|
return {
|
|
@@ -56,6 +73,11 @@ function param(key, transform) {
|
|
|
56
73
|
};
|
|
57
74
|
}
|
|
58
75
|
|
|
76
|
+
// src/handlers/typed.ts
|
|
77
|
+
function typed() {
|
|
78
|
+
return (input) => input;
|
|
79
|
+
}
|
|
80
|
+
|
|
59
81
|
// src/runtime/platform-client.ts
|
|
60
82
|
import { DynamoDB } from "@aws-sdk/client-dynamodb";
|
|
61
83
|
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
|
|
@@ -150,9 +172,11 @@ export {
|
|
|
150
172
|
createPlatformClient,
|
|
151
173
|
defineApp,
|
|
152
174
|
defineConfig,
|
|
175
|
+
defineFifoQueue,
|
|
153
176
|
defineHttp,
|
|
154
177
|
defineStaticSite,
|
|
155
178
|
defineTable,
|
|
156
|
-
param
|
|
179
|
+
param,
|
|
180
|
+
typed
|
|
157
181
|
};
|
|
158
182
|
//# sourceMappingURL=index.js.map
|