effortless-aws 0.16.2 → 0.18.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/README.md +21 -15
- package/dist/index.d.ts +177 -29
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/wrap-api.js +145 -0
- package/package.json +11 -45
- package/dist/cli/index.js +0 -75949
- package/dist/cli/index.js.map +0 -1
- package/dist/runtime/wrap-app.js +0 -128
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# effortless-aws
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/effortless-aws)
|
|
4
|
-
[](https://www.npmjs.com/package/effortless-aws)
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Code-first AWS Lambda framework. Export handlers, deploy with one command. No YAML, no CloudFormation, no state files.
|
|
7
6
|
|
|
8
7
|
```bash
|
|
9
8
|
npm install effortless-aws
|
|
@@ -23,26 +22,33 @@ export const hello = defineHttp({
|
|
|
23
22
|
});
|
|
24
23
|
```
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
npx eff deploy
|
|
28
|
-
```
|
|
25
|
+
## Handlers
|
|
29
26
|
|
|
30
|
-
|
|
27
|
+
| Handler | Description |
|
|
28
|
+
|---------|-------------|
|
|
29
|
+
| `defineHttp` | HTTP endpoint via API Gateway |
|
|
30
|
+
| `defineApi` | REST API with typed GET/POST routes |
|
|
31
|
+
| `defineApp` | Generic Lambda (cron, custom events) |
|
|
32
|
+
| `defineTable` | DynamoDB table with stream processing |
|
|
33
|
+
| `defineFifoQueue` | SQS FIFO queue consumer |
|
|
34
|
+
| `defineBucket` | S3 bucket with event triggers |
|
|
35
|
+
| `defineMailer` | SES email sending |
|
|
36
|
+
| `defineStaticSite` | CloudFront + S3 static site with optional middleware |
|
|
31
37
|
|
|
32
38
|
## Features
|
|
33
39
|
|
|
34
|
-
- **Infrastructure from code** — export a handler, get the AWS resources
|
|
35
|
-
- **Typed everything** — `defineTable<Order>` gives you typed `put()`, typed `deps.orders.get()`, typed `record.new
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
- **Infrastructure from code** — export a handler, get the AWS resources
|
|
41
|
+
- **Typed everything** — `defineTable<Order>` gives you typed `put()`, typed `deps.orders.get()`, typed `record.new`
|
|
42
|
+
- **Cross-handler deps** — `deps: { orders }` auto-wires IAM and injects a typed `TableClient`
|
|
43
|
+
- **SSM params** — `param("stripe-key")` fetches from Parameter Store at cold start
|
|
44
|
+
- **Static files** — `static: ["templates/*.ejs"]` bundles files into the Lambda ZIP
|
|
45
|
+
- **Cold start caching** — `setup` factory runs once per cold start, cached across invocations
|
|
46
|
+
|
|
47
|
+
Deploy with [`@effortless-aws/cli`](https://www.npmjs.com/package/@effortless-aws/cli).
|
|
42
48
|
|
|
43
49
|
## Documentation
|
|
44
50
|
|
|
45
|
-
Full docs, examples, and API reference: **[effortless-aws
|
|
51
|
+
Full docs, examples, and API reference: **[effortless-aws.website](https://effortless-aws.website)**
|
|
46
52
|
|
|
47
53
|
## License
|
|
48
54
|
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,13 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
type EffortlessConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* Project root directory. All relative paths (handlers, server, assets, etc.)
|
|
19
|
+
* are resolved from this directory.
|
|
20
|
+
* Resolved relative to where the CLI runs (process.cwd()).
|
|
21
|
+
* @default "." (current working directory)
|
|
22
|
+
*/
|
|
23
|
+
root?: string;
|
|
17
24
|
/**
|
|
18
25
|
* Project name used for resource naming and tagging.
|
|
19
26
|
* This becomes part of Lambda function names, IAM roles, etc.
|
|
@@ -415,7 +422,7 @@ type FailedRecord<T = Record<string, unknown>> = {
|
|
|
415
422
|
* Always receives `table: TableClient<T>` (self-client for the handler's own table).
|
|
416
423
|
* Also receives `deps` and/or `config` when declared.
|
|
417
424
|
*/
|
|
418
|
-
type SetupFactory$
|
|
425
|
+
type SetupFactory$4<C, T, D, P, S extends string[] | undefined = undefined> = (args: {
|
|
419
426
|
table: TableClient<T>;
|
|
420
427
|
} & ([D] extends [undefined] ? {} : {
|
|
421
428
|
deps: ResolveDeps<D>;
|
|
@@ -491,7 +498,7 @@ type DefineTableBase<T = Record<string, unknown>, C = undefined, D = undefined,
|
|
|
491
498
|
* When deps/params are declared, receives them as argument.
|
|
492
499
|
* Supports both sync and async return values.
|
|
493
500
|
*/
|
|
494
|
-
setup?: SetupFactory$
|
|
501
|
+
setup?: SetupFactory$4<C, T, D, P, S>;
|
|
495
502
|
/**
|
|
496
503
|
* Dependencies on other handlers (tables, queues, etc.).
|
|
497
504
|
* Typed clients are injected into the handler via the `deps` argument.
|
|
@@ -661,7 +668,7 @@ type BucketObjectRemovedFn<C = undefined, D = undefined, P = undefined, S extend
|
|
|
661
668
|
* Always receives `bucket: BucketClient` (self-client for the handler's own bucket).
|
|
662
669
|
* Also receives `deps` and/or `config` when declared.
|
|
663
670
|
*/
|
|
664
|
-
type SetupFactory$
|
|
671
|
+
type SetupFactory$3<C, D, P, S extends string[] | undefined = undefined> = (args: {
|
|
665
672
|
bucket: BucketClient;
|
|
666
673
|
} & ([D] extends [undefined] ? {} : {
|
|
667
674
|
deps: ResolveDeps<D>;
|
|
@@ -683,7 +690,7 @@ type DefineBucketBase<C = undefined, D = undefined, P = undefined, S extends str
|
|
|
683
690
|
* Always receives `bucket: BucketClient` (self-client). When deps/config
|
|
684
691
|
* are declared, receives them as well.
|
|
685
692
|
*/
|
|
686
|
-
setup?: SetupFactory$
|
|
693
|
+
setup?: SetupFactory$3<C, D, P, S>;
|
|
687
694
|
/**
|
|
688
695
|
* Dependencies on other handlers (tables, buckets, etc.).
|
|
689
696
|
* Typed clients are injected into the handler via the `deps` argument.
|
|
@@ -853,7 +860,7 @@ type ResolveDeps<D> = {
|
|
|
853
860
|
};
|
|
854
861
|
|
|
855
862
|
/** HTTP methods supported by API Gateway */
|
|
856
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
863
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "ANY";
|
|
857
864
|
/** Short content-type aliases for common response formats */
|
|
858
865
|
type ContentType = "json" | "html" | "text" | "css" | "js" | "xml" | "csv" | "svg";
|
|
859
866
|
/**
|
|
@@ -932,7 +939,7 @@ type HttpHandlerFn<T = undefined, C = undefined, D = undefined, P = undefined, S
|
|
|
932
939
|
* Setup factory type — always receives an args object.
|
|
933
940
|
* Args include `deps` and/or `config` when declared (empty `{}` otherwise).
|
|
934
941
|
*/
|
|
935
|
-
type SetupFactory$
|
|
942
|
+
type SetupFactory$2<C, D, P, S extends string[] | undefined = undefined> = (args: ([D] extends [undefined] ? {} : {
|
|
936
943
|
deps: ResolveDeps<D>;
|
|
937
944
|
}) & ([P] extends [undefined] ? {} : {
|
|
938
945
|
config: ResolveConfig<P & {}>;
|
|
@@ -970,7 +977,7 @@ type DefineHttpOptions<T = undefined, C = undefined, D extends Record<string, An
|
|
|
970
977
|
* When deps/params are declared, receives them as argument.
|
|
971
978
|
* Supports both sync and async return values.
|
|
972
979
|
*/
|
|
973
|
-
setup?: SetupFactory$
|
|
980
|
+
setup?: SetupFactory$2<C, D, P, S>;
|
|
974
981
|
/**
|
|
975
982
|
* Dependencies on other handlers (tables, queues, etc.).
|
|
976
983
|
* Typed clients are injected into the handler via the `deps` argument.
|
|
@@ -1046,23 +1053,33 @@ type HttpHandler<T = undefined, C = undefined, D = undefined, P = undefined, S e
|
|
|
1046
1053
|
* })
|
|
1047
1054
|
* });
|
|
1048
1055
|
* ```
|
|
1056
|
+
*
|
|
1057
|
+
* @see {@link defineApi} for multi-route endpoints with typed GET routes and POST command handling (CQRS pattern)
|
|
1049
1058
|
*/
|
|
1050
1059
|
declare const defineHttp: <T = undefined, C = undefined, D extends Record<string, AnyDepHandler> | 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>;
|
|
1051
1060
|
|
|
1052
1061
|
/**
|
|
1053
|
-
* Configuration for
|
|
1062
|
+
* Configuration for deploying an SSR framework (Nuxt, Astro, etc.)
|
|
1063
|
+
* via CloudFront + S3 (static assets) + Lambda Function URL (server-side rendering).
|
|
1054
1064
|
*/
|
|
1055
|
-
type AppConfig =
|
|
1056
|
-
/**
|
|
1065
|
+
type AppConfig = LambdaWithPermissions & {
|
|
1066
|
+
/** Directory containing the Lambda server handler (e.g., ".output/server").
|
|
1067
|
+
* Must contain an `index.mjs` (or `index.js`) that exports a `handler` function. */
|
|
1068
|
+
server: string;
|
|
1069
|
+
/** Directory containing static assets for S3 (e.g., ".output/public") */
|
|
1070
|
+
assets: string;
|
|
1071
|
+
/** Base URL path (default: "/") */
|
|
1057
1072
|
path?: string;
|
|
1058
|
-
/**
|
|
1059
|
-
dir: string;
|
|
1060
|
-
/** Default file for directory requests (default: "index.html") */
|
|
1061
|
-
index?: string;
|
|
1062
|
-
/** SPA mode: serve index.html for all paths that don't match a file (default: false) */
|
|
1063
|
-
spa?: boolean;
|
|
1064
|
-
/** Shell command to run before deploy to generate site content (e.g., "npx astro build") */
|
|
1073
|
+
/** Shell command to build the framework output (e.g., "nuxt build") */
|
|
1065
1074
|
build?: string;
|
|
1075
|
+
/** Custom domain name. String or stage-keyed record (e.g., { prod: "app.example.com" }). */
|
|
1076
|
+
domain?: string | Record<string, string>;
|
|
1077
|
+
/** CloudFront route overrides: path patterns forwarded to API Gateway instead of the SSR Lambda.
|
|
1078
|
+
* Keys are CloudFront path patterns (e.g., "/api/*"), values are handler references.
|
|
1079
|
+
* Example: `routes: { "/api/*": api }` */
|
|
1080
|
+
routes?: Record<string, {
|
|
1081
|
+
readonly __brand: string;
|
|
1082
|
+
}>;
|
|
1066
1083
|
};
|
|
1067
1084
|
/**
|
|
1068
1085
|
* Internal handler object created by defineApp
|
|
@@ -1073,25 +1090,33 @@ type AppHandler = {
|
|
|
1073
1090
|
readonly __spec: AppConfig;
|
|
1074
1091
|
};
|
|
1075
1092
|
/**
|
|
1076
|
-
* Deploy
|
|
1077
|
-
* Files are bundled into the Lambda ZIP and served with auto-detected content types.
|
|
1093
|
+
* Deploy an SSR framework application via CloudFront + Lambda Function URL.
|
|
1078
1094
|
*
|
|
1079
|
-
*
|
|
1095
|
+
* Static assets from the `assets` directory are served via S3 + CloudFront CDN.
|
|
1096
|
+
* Server-rendered pages are handled by a Lambda function using the framework's
|
|
1097
|
+
* built output from the `server` directory.
|
|
1080
1098
|
*
|
|
1081
|
-
*
|
|
1099
|
+
* For static-only sites (no SSR), use {@link defineStaticSite} instead.
|
|
1100
|
+
*
|
|
1101
|
+
* @param options - App configuration: server directory, assets directory, optional build command
|
|
1082
1102
|
* @returns Handler object used by the deployment system
|
|
1083
1103
|
*
|
|
1084
|
-
* @example
|
|
1104
|
+
* @example Nuxt SSR
|
|
1085
1105
|
* ```typescript
|
|
1086
1106
|
* export const app = defineApp({
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
1107
|
+
* build: "nuxt build",
|
|
1108
|
+
* server: ".output/server",
|
|
1109
|
+
* assets: ".output/public",
|
|
1110
|
+
* memory: 1024,
|
|
1089
1111
|
* });
|
|
1090
1112
|
* ```
|
|
1091
1113
|
*/
|
|
1092
1114
|
declare const defineApp: (options: AppConfig) => AppHandler;
|
|
1093
1115
|
|
|
1094
|
-
|
|
1116
|
+
/** Any branded handler that deploys to API Gateway (HttpHandler, ApiHandler, etc.) */
|
|
1117
|
+
type AnyRoutableHandler = {
|
|
1118
|
+
readonly __brand: string;
|
|
1119
|
+
};
|
|
1095
1120
|
/** Simplified request object passed to middleware */
|
|
1096
1121
|
type MiddlewareRequest = {
|
|
1097
1122
|
uri: string;
|
|
@@ -1133,7 +1158,7 @@ type StaticSiteConfig = {
|
|
|
1133
1158
|
/** CloudFront route overrides: path patterns forwarded to API Gateway instead of S3.
|
|
1134
1159
|
* Keys are CloudFront path patterns (e.g., "/api/*"), values are HTTP handlers.
|
|
1135
1160
|
* Example: `routes: { "/api/*": api }` */
|
|
1136
|
-
routes?: Record<string,
|
|
1161
|
+
routes?: Record<string, AnyRoutableHandler>;
|
|
1137
1162
|
/** Custom 404 error page path relative to `dir` (e.g. "404.html").
|
|
1138
1163
|
* For non-SPA sites only. If not set, a default page is generated automatically. */
|
|
1139
1164
|
errorPage?: string;
|
|
@@ -1234,7 +1259,7 @@ type FifoQueueConfig = LambdaWithPermissions & {
|
|
|
1234
1259
|
* Setup factory type — always receives an args object.
|
|
1235
1260
|
* Args include `deps` and/or `config` when declared (empty `{}` otherwise).
|
|
1236
1261
|
*/
|
|
1237
|
-
type SetupFactory<C, D, P, S extends string[] | undefined = undefined> = (args: ([D] extends [undefined] ? {} : {
|
|
1262
|
+
type SetupFactory$1<C, D, P, S extends string[] | undefined = undefined> = (args: ([D] extends [undefined] ? {} : {
|
|
1238
1263
|
deps: ResolveDeps<D>;
|
|
1239
1264
|
}) & ([P] extends [undefined] ? {} : {
|
|
1240
1265
|
config: ResolveConfig<P & {}>;
|
|
@@ -1288,7 +1313,7 @@ type DefineFifoQueueBase<T = unknown, C = undefined, D = undefined, P = undefine
|
|
|
1288
1313
|
* Called once on cold start, result is cached and reused across invocations.
|
|
1289
1314
|
* When deps/params are declared, receives them as argument.
|
|
1290
1315
|
*/
|
|
1291
|
-
setup?: SetupFactory<C, D, P, S>;
|
|
1316
|
+
setup?: SetupFactory$1<C, D, P, S>;
|
|
1292
1317
|
/**
|
|
1293
1318
|
* Dependencies on other handlers (tables, queues, etc.).
|
|
1294
1319
|
* Typed clients are injected into the handler via the `deps` argument.
|
|
@@ -1364,4 +1389,127 @@ type FifoQueueHandler<T = unknown, C = undefined, D = undefined, P = undefined,
|
|
|
1364
1389
|
*/
|
|
1365
1390
|
declare const defineFifoQueue: <T = unknown, C = undefined, D extends Record<string, AnyDepHandler> | 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>;
|
|
1366
1391
|
|
|
1367
|
-
|
|
1392
|
+
/** GET route handler — no schema, no data */
|
|
1393
|
+
type ApiGetHandlerFn<C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = (args: {
|
|
1394
|
+
req: HttpRequest;
|
|
1395
|
+
} & ([C] extends [undefined] ? {} : {
|
|
1396
|
+
ctx: C;
|
|
1397
|
+
}) & ([D] extends [undefined] ? {} : {
|
|
1398
|
+
deps: ResolveDeps<D>;
|
|
1399
|
+
}) & ([P] extends [undefined] ? {} : {
|
|
1400
|
+
config: ResolveConfig<P>;
|
|
1401
|
+
}) & ([S] extends [undefined] ? {} : {
|
|
1402
|
+
files: StaticFiles;
|
|
1403
|
+
})) => Promise<HttpResponse> | HttpResponse;
|
|
1404
|
+
/** POST handler — with typed data from schema */
|
|
1405
|
+
type ApiPostHandlerFn<T = undefined, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = (args: {
|
|
1406
|
+
req: HttpRequest;
|
|
1407
|
+
} & ([T] extends [undefined] ? {} : {
|
|
1408
|
+
data: T;
|
|
1409
|
+
}) & ([C] extends [undefined] ? {} : {
|
|
1410
|
+
ctx: C;
|
|
1411
|
+
}) & ([D] extends [undefined] ? {} : {
|
|
1412
|
+
deps: ResolveDeps<D>;
|
|
1413
|
+
}) & ([P] extends [undefined] ? {} : {
|
|
1414
|
+
config: ResolveConfig<P>;
|
|
1415
|
+
}) & ([S] extends [undefined] ? {} : {
|
|
1416
|
+
files: StaticFiles;
|
|
1417
|
+
})) => Promise<HttpResponse> | HttpResponse;
|
|
1418
|
+
/** Setup factory — receives deps/config/files when declared */
|
|
1419
|
+
type SetupFactory<C, D, P, S extends string[] | undefined = undefined> = (args: ([D] extends [undefined] ? {} : {
|
|
1420
|
+
deps: ResolveDeps<D>;
|
|
1421
|
+
}) & ([P] extends [undefined] ? {} : {
|
|
1422
|
+
config: ResolveConfig<P & {}>;
|
|
1423
|
+
}) & ([S] extends [undefined] ? {} : {
|
|
1424
|
+
files: StaticFiles;
|
|
1425
|
+
})) => C | Promise<C>;
|
|
1426
|
+
/** Static config extracted by AST (no runtime callbacks) */
|
|
1427
|
+
type ApiConfig = LambdaWithPermissions & {
|
|
1428
|
+
/** Base path prefix for all routes (e.g., "/api") */
|
|
1429
|
+
basePath: string;
|
|
1430
|
+
};
|
|
1431
|
+
/**
|
|
1432
|
+
* Options for defining a CQRS-style API endpoint.
|
|
1433
|
+
*
|
|
1434
|
+
* - `get` routes handle queries (path-based routing, no body)
|
|
1435
|
+
* - `post` handles commands (single entry point, discriminated union via `schema`)
|
|
1436
|
+
*/
|
|
1437
|
+
type DefineApiOptions<T = undefined, C = undefined, D extends Record<string, AnyDepHandler> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined> = LambdaWithPermissions & {
|
|
1438
|
+
/** Base path prefix for all routes (e.g., "/api") */
|
|
1439
|
+
basePath: string;
|
|
1440
|
+
/**
|
|
1441
|
+
* Factory function to initialize shared state.
|
|
1442
|
+
* Called once on cold start, result is cached and reused across invocations.
|
|
1443
|
+
*/
|
|
1444
|
+
setup?: SetupFactory<C, D, P, S>;
|
|
1445
|
+
/** Dependencies on other handlers (tables, queues, etc.) */
|
|
1446
|
+
deps?: D;
|
|
1447
|
+
/** SSM Parameter Store parameters */
|
|
1448
|
+
config?: P;
|
|
1449
|
+
/** Static file glob patterns to bundle into the Lambda ZIP */
|
|
1450
|
+
static?: S;
|
|
1451
|
+
/** Error handler called when schema validation or handler throws */
|
|
1452
|
+
onError?: (error: unknown, req: HttpRequest) => HttpResponse;
|
|
1453
|
+
/** GET routes — query handlers keyed by relative path (e.g., "/users/{id}") */
|
|
1454
|
+
get?: Record<string, ApiGetHandlerFn<C, D, P, S>>;
|
|
1455
|
+
/**
|
|
1456
|
+
* Schema for POST body validation. Use with discriminated unions:
|
|
1457
|
+
* ```typescript
|
|
1458
|
+
* schema: Action.parse,
|
|
1459
|
+
* post: async ({ data }) => { switch (data.action) { ... } }
|
|
1460
|
+
* ```
|
|
1461
|
+
*/
|
|
1462
|
+
schema?: (input: unknown) => T;
|
|
1463
|
+
/** POST handler — single entry point for commands */
|
|
1464
|
+
post?: ApiPostHandlerFn<T, C, D, P, S>;
|
|
1465
|
+
};
|
|
1466
|
+
/** Internal handler object created by defineApi */
|
|
1467
|
+
type ApiHandler<T = undefined, C = undefined, D = undefined, P = undefined, S extends string[] | undefined = undefined> = {
|
|
1468
|
+
readonly __brand: "effortless-api";
|
|
1469
|
+
readonly __spec: ApiConfig;
|
|
1470
|
+
readonly schema?: (input: unknown) => T;
|
|
1471
|
+
readonly onError?: (error: unknown, req: HttpRequest) => HttpResponse;
|
|
1472
|
+
readonly setup?: (...args: any[]) => C | Promise<C>;
|
|
1473
|
+
readonly deps?: D;
|
|
1474
|
+
readonly config?: P;
|
|
1475
|
+
readonly static?: string[];
|
|
1476
|
+
readonly get?: Record<string, ApiGetHandlerFn<C, D, P, S>>;
|
|
1477
|
+
readonly post?: ApiPostHandlerFn<T, C, D, P, S>;
|
|
1478
|
+
};
|
|
1479
|
+
/**
|
|
1480
|
+
* Define a CQRS-style API with typed GET routes and POST commands.
|
|
1481
|
+
*
|
|
1482
|
+
* GET routes handle queries — path-based routing, no request body.
|
|
1483
|
+
* POST handles commands — single entry point with discriminated union schema.
|
|
1484
|
+
* Deploys as a single Lambda (fat Lambda) with one API Gateway catch-all route.
|
|
1485
|
+
*
|
|
1486
|
+
* @example
|
|
1487
|
+
* ```typescript
|
|
1488
|
+
* export default defineApi({
|
|
1489
|
+
* basePath: "/api",
|
|
1490
|
+
* deps: { users },
|
|
1491
|
+
*
|
|
1492
|
+
* get: {
|
|
1493
|
+
* "/users": async ({ req, deps }) => ({
|
|
1494
|
+
* status: 200,
|
|
1495
|
+
* body: await deps.users.scan()
|
|
1496
|
+
* }),
|
|
1497
|
+
* "/users/{id}": async ({ req, deps }) => ({
|
|
1498
|
+
* status: 200,
|
|
1499
|
+
* body: await deps.users.get(req.params.id)
|
|
1500
|
+
* }),
|
|
1501
|
+
* },
|
|
1502
|
+
*
|
|
1503
|
+
* schema: Action.parse,
|
|
1504
|
+
* post: async ({ data, deps }) => {
|
|
1505
|
+
* switch (data.action) {
|
|
1506
|
+
* case "create": return { status: 201, body: await deps.users.put(data) }
|
|
1507
|
+
* case "delete": return { status: 200, body: await deps.users.delete(data.id) }
|
|
1508
|
+
* }
|
|
1509
|
+
* },
|
|
1510
|
+
* })
|
|
1511
|
+
* ```
|
|
1512
|
+
*/
|
|
1513
|
+
declare const defineApi: <T = undefined, C = undefined, D extends Record<string, AnyDepHandler> | undefined = undefined, P extends Record<string, AnyParamRef> | undefined = undefined, S extends string[] | undefined = undefined>(options: DefineApiOptions<T, C, D, P, S>) => ApiHandler<T, C, D, P, S>;
|
|
1514
|
+
|
|
1515
|
+
export { type AnyParamRef, type ApiConfig, type ApiGetHandlerFn, type ApiHandler, type ApiPostHandlerFn, type AppConfig, type AppHandler, type BucketClient, type BucketConfig, type BucketEvent, type BucketHandler, type BucketObjectCreatedFn, type BucketObjectRemovedFn, type ContentType, type DefineApiOptions, type DefineBucketOptions, type DefineFifoQueueOptions, type DefineHttpOptions, type DefineTableOptions, type EffortlessConfig, type EmailClient, 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 LambdaConfig, type LambdaWithPermissions, type LogLevel, type MailerConfig, type MailerHandler, type MiddlewareDeny, type MiddlewareHandler, type MiddlewareRedirect, type MiddlewareRequest, type MiddlewareResult, type ParamRef, type Permission, type PutInput, type PutOptions, type QueryByTagParams, type QueryParams, type ResolveConfig, type ResolveDeps, type SendEmailOptions, type SkCondition, type StaticFiles, type StaticSiteConfig, type StaticSiteHandler, type StreamView, type TableBatchCompleteFn, type TableBatchFn, type TableClient, type TableConfig, type TableHandler, type TableItem, type TableKey, type TableRecord, type TableRecordFn, type UpdateActions, defineApi, defineApp, defineBucket, defineConfig, defineFifoQueue, defineHttp, defineMailer, defineStaticSite, defineTable, param, typed };
|
package/dist/index.js
CHANGED
|
@@ -86,6 +86,23 @@ var defineMailer = (options) => ({
|
|
|
86
86
|
__spec: options
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
+
// src/handlers/define-api.ts
|
|
90
|
+
var defineApi = (options) => {
|
|
91
|
+
const { get, post, schema, onError, setup, deps, config, static: staticFiles, ...__spec } = options;
|
|
92
|
+
return {
|
|
93
|
+
__brand: "effortless-api",
|
|
94
|
+
__spec,
|
|
95
|
+
...get ? { get } : {},
|
|
96
|
+
...post ? { post } : {},
|
|
97
|
+
...schema ? { schema } : {},
|
|
98
|
+
...onError ? { onError } : {},
|
|
99
|
+
...setup ? { setup } : {},
|
|
100
|
+
...deps ? { deps } : {},
|
|
101
|
+
...config ? { config } : {},
|
|
102
|
+
...staticFiles ? { static: staticFiles } : {}
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
89
106
|
// src/handlers/handler-options.ts
|
|
90
107
|
function param(key, transform) {
|
|
91
108
|
return {
|
|
@@ -98,6 +115,7 @@ function typed() {
|
|
|
98
115
|
return (input) => input;
|
|
99
116
|
}
|
|
100
117
|
export {
|
|
118
|
+
defineApi,
|
|
101
119
|
defineApp,
|
|
102
120
|
defineBucket,
|
|
103
121
|
defineConfig,
|