@lafken/standalone 0.12.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/LICENCE +21 -0
- package/README.md +177 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/main/index.d.ts +1 -0
- package/lib/main/index.js +17 -0
- package/lib/main/standalone/index.d.ts +2 -0
- package/lib/main/standalone/index.js +18 -0
- package/lib/main/standalone/standalone.d.ts +38 -0
- package/lib/main/standalone/standalone.js +49 -0
- package/lib/main/standalone/standalone.types.d.ts +47 -0
- package/lib/main/standalone/standalone.types.js +4 -0
- package/lib/resolver/handler/handler.d.ts +16 -0
- package/lib/resolver/handler/handler.js +53 -0
- package/lib/resolver/handler/handler.types.d.ts +6 -0
- package/lib/resolver/handler/handler.types.js +2 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/resolver.d.ts +6 -0
- package/lib/resolver/resolver.js +29 -0
- package/package.json +84 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aníbal Emilio Jorquera Cornejo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# @lafken/standalone
|
|
2
|
+
|
|
3
|
+
Define standalone AWS Lambda functions using TypeScript decorators. `@lafken/standalone` lets you declare independent Lambda handlers that can be invoked by other services, and automatically wires them up with optional IAM invoke roles and global references.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lafken/standalone
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
Define a standalone class with `@Standalone`, add `@Handler` methods, and register everything through `StandaloneResolver`:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createApp, createModule } from '@lafken/main';
|
|
17
|
+
import { StandaloneResolver } from '@lafken/standalone/resolver';
|
|
18
|
+
import { Standalone, Handler } from '@lafken/standalone/main';
|
|
19
|
+
|
|
20
|
+
// 1. Define standalone handlers
|
|
21
|
+
@Standalone()
|
|
22
|
+
export class OrderFunctions {
|
|
23
|
+
@Handler()
|
|
24
|
+
processOrder() {
|
|
25
|
+
console.log('Processing order...');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 2. Register in a module
|
|
30
|
+
const orderModule = createModule({
|
|
31
|
+
name: 'order',
|
|
32
|
+
resources: [OrderFunctions],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// 3. Add the resolver to the app
|
|
36
|
+
createApp({
|
|
37
|
+
name: 'my-app',
|
|
38
|
+
resolvers: [new StandaloneResolver()],
|
|
39
|
+
modules: [orderModule],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Each `@Handler` method becomes an independent Lambda function ready to be invoked by other services.
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
### Standalone Class
|
|
48
|
+
|
|
49
|
+
Use the `@Standalone` decorator to group related Lambda handlers in a single class:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Standalone, Handler } from '@lafken/standalone/main';
|
|
53
|
+
|
|
54
|
+
@Standalone()
|
|
55
|
+
export class NotificationFunctions {
|
|
56
|
+
@Handler()
|
|
57
|
+
sendEmail() { }
|
|
58
|
+
|
|
59
|
+
@Handler()
|
|
60
|
+
sendSms() { }
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Custom Handler Name
|
|
65
|
+
|
|
66
|
+
By default the method name is used as the Lambda handler identifier. Override it with the `name` option:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
@Handler({ name: 'process-payment' })
|
|
70
|
+
handlePayment() { }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Invoke Role
|
|
74
|
+
|
|
75
|
+
Configure an IAM role that grants another principal permission to invoke the Lambda. When `invocator` is provided, a dedicated invoke role is created and attached to the function:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
@Handler({
|
|
79
|
+
invocator: {
|
|
80
|
+
principalRole: 'apigateway.amazonaws.com',
|
|
81
|
+
services: [
|
|
82
|
+
{
|
|
83
|
+
type: 'execute-api',
|
|
84
|
+
permissions: ['Invoke'],
|
|
85
|
+
resources: ['*'],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
roleRef: 'processOrderInvokeRole',
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
processOrder() { }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### Invocator Options
|
|
95
|
+
|
|
96
|
+
| Option | Type | Description |
|
|
97
|
+
| -------------------- | ---------------- | --------------------------------------------------------------------------- |
|
|
98
|
+
| `principalRole` | `string` | AWS service or account ARN allowed to assume the role |
|
|
99
|
+
| `principalPermission`| `string` | Permission level for the principal |
|
|
100
|
+
| `services` | `ServicesValues` | Additional IAM policy statements to include in the role |
|
|
101
|
+
| `roleRef` | `string` | Name to register the created role as a global reference |
|
|
102
|
+
|
|
103
|
+
### Global References
|
|
104
|
+
|
|
105
|
+
Use `ref` to register the Lambda function as a named global reference so other resources can access its attributes (e.g. ARN, function name):
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
@Handler({
|
|
109
|
+
ref: 'processOrderLambda',
|
|
110
|
+
})
|
|
111
|
+
processOrder() { }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Lambda Configuration
|
|
115
|
+
|
|
116
|
+
Pass any Lambda-specific settings through the `lambda` option:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
@Handler({
|
|
120
|
+
lambda: {
|
|
121
|
+
timeout: 30,
|
|
122
|
+
memorySize: 512,
|
|
123
|
+
environment: {
|
|
124
|
+
QUEUE_URL: 'https://sqs.us-east-1.amazonaws.com/...',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
processOrder() { }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Full Example
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { createApp, createModule } from '@lafken/main';
|
|
135
|
+
import { StandaloneResolver } from '@lafken/standalone/resolver';
|
|
136
|
+
import { Standalone, Handler } from '@lafken/standalone/main';
|
|
137
|
+
|
|
138
|
+
@Standalone()
|
|
139
|
+
export class PaymentFunctions {
|
|
140
|
+
@Handler({
|
|
141
|
+
name: 'process-payment',
|
|
142
|
+
ref: 'processPaymentLambda',
|
|
143
|
+
invocator: {
|
|
144
|
+
principalRole: 'apigateway.amazonaws.com',
|
|
145
|
+
services: [
|
|
146
|
+
{
|
|
147
|
+
type: 'execute-api',
|
|
148
|
+
permissions: ['Invoke'],
|
|
149
|
+
resources: ['*'],
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
roleRef: 'processPaymentInvokeRole',
|
|
153
|
+
},
|
|
154
|
+
lambda: {
|
|
155
|
+
timeout: 30,
|
|
156
|
+
memorySize: 256,
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
processPayment() { }
|
|
160
|
+
|
|
161
|
+
@Handler({
|
|
162
|
+
ref: 'refundPaymentLambda',
|
|
163
|
+
})
|
|
164
|
+
refundPayment() { }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const paymentModule = createModule({
|
|
168
|
+
name: 'payment',
|
|
169
|
+
resources: [PaymentFunctions],
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
createApp({
|
|
173
|
+
name: 'my-app',
|
|
174
|
+
resolvers: [new StandaloneResolver()],
|
|
175
|
+
modules: [paymentModule],
|
|
176
|
+
});
|
|
177
|
+
```
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./main"), exports);
|
|
18
|
+
__exportStar(require("./resolver"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './standalone';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./standalone"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./standalone"), exports);
|
|
18
|
+
__exportStar(require("./standalone.types"), exports);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type HandlerProps } from './standalone.types';
|
|
2
|
+
/**
|
|
3
|
+
* Class decorator that marks a class as a standalone Lambda resource module.
|
|
4
|
+
* The resolver uses the metadata stored by this decorator to discover and wire
|
|
5
|
+
* up all `@Handler`-decorated methods within the class.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* @Standalone()
|
|
9
|
+
* export class MyFunctions {
|
|
10
|
+
* @Handler()
|
|
11
|
+
* myHandler() {}
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
export declare const Standalone: (props?: import("@lafken/common").ResourceProps | undefined) => (constructor: Function) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Method decorator that registers a class method as a Lambda handler.
|
|
17
|
+
* The decorated method becomes the entry point of a Lambda function; its name
|
|
18
|
+
* (or the explicit `name` prop) is used as the logical function identifier.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Minimal — uses the method name as the handler name
|
|
22
|
+
* @Handler()
|
|
23
|
+
* myHandler() {}
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Custom name + invoke role for API Gateway
|
|
27
|
+
* @Handler({
|
|
28
|
+
* name: 'my-handler',
|
|
29
|
+
* invocator: {
|
|
30
|
+
* principal: 'apigateway.amazonaws.com',
|
|
31
|
+
* services: (props) => [{ type: 'execute-api', permissions: ['Invoke'], resources: [props.arn] }],
|
|
32
|
+
* roleRef: 'myHandlerInvokeRole',
|
|
33
|
+
* },
|
|
34
|
+
* ref: 'myHandler',
|
|
35
|
+
* })
|
|
36
|
+
* myHandler() {}
|
|
37
|
+
*/
|
|
38
|
+
export declare const Handler: (props?: HandlerProps | undefined) => (target: any, methodName: string, descriptor: PropertyDescriptor) => any;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Handler = exports.Standalone = void 0;
|
|
4
|
+
const common_1 = require("@lafken/common");
|
|
5
|
+
const standalone_types_1 = require("./standalone.types");
|
|
6
|
+
/**
|
|
7
|
+
* Class decorator that marks a class as a standalone Lambda resource module.
|
|
8
|
+
* The resolver uses the metadata stored by this decorator to discover and wire
|
|
9
|
+
* up all `@Handler`-decorated methods within the class.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* @Standalone()
|
|
13
|
+
* export class MyFunctions {
|
|
14
|
+
* @Handler()
|
|
15
|
+
* myHandler() {}
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
exports.Standalone = (0, common_1.createResourceDecorator)({
|
|
19
|
+
type: standalone_types_1.RESOURCE_TYPE,
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Method decorator that registers a class method as a Lambda handler.
|
|
23
|
+
* The decorated method becomes the entry point of a Lambda function; its name
|
|
24
|
+
* (or the explicit `name` prop) is used as the logical function identifier.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Minimal — uses the method name as the handler name
|
|
28
|
+
* @Handler()
|
|
29
|
+
* myHandler() {}
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Custom name + invoke role for API Gateway
|
|
33
|
+
* @Handler({
|
|
34
|
+
* name: 'my-handler',
|
|
35
|
+
* invocator: {
|
|
36
|
+
* principal: 'apigateway.amazonaws.com',
|
|
37
|
+
* services: (props) => [{ type: 'execute-api', permissions: ['Invoke'], resources: [props.arn] }],
|
|
38
|
+
* roleRef: 'myHandlerInvokeRole',
|
|
39
|
+
* },
|
|
40
|
+
* ref: 'myHandler',
|
|
41
|
+
* })
|
|
42
|
+
* myHandler() {}
|
|
43
|
+
*/
|
|
44
|
+
exports.Handler = (0, common_1.createLambdaDecorator)({
|
|
45
|
+
getLambdaMetadata: (props, methodName) => ({
|
|
46
|
+
...props,
|
|
47
|
+
name: props.name || methodName,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { LambdaMetadata, LambdaProps, ServicesValues } from '@lafken/common';
|
|
2
|
+
export declare const RESOURCE_TYPE = "standalone";
|
|
3
|
+
export interface HandlerProps {
|
|
4
|
+
/**
|
|
5
|
+
* The logical name used to identify this Lambda handler within the stack.
|
|
6
|
+
* Defaults to the function's file or export name if not provided.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* name: 'myHandler'
|
|
10
|
+
*/
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Configures an IAM role that grants another principal permission to invoke
|
|
14
|
+
* this Lambda function. When provided, a dedicated invoke role is created and
|
|
15
|
+
* attached to the function.
|
|
16
|
+
*
|
|
17
|
+
* - `principal` — the AWS service or account ARN allowed to assume the role
|
|
18
|
+
* (e.g. `'apigateway.amazonaws.com'`).
|
|
19
|
+
* - `services` — additional IAM policy statements to include in the role.
|
|
20
|
+
* - `roleRef` — registers the created role as a named global reference so
|
|
21
|
+
* other resources can look it up by name.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* invocator: {
|
|
25
|
+
* principal: 'apigateway.amazonaws.com',
|
|
26
|
+
* services: [{ type: 'lambda', permissions: ['InvokeFunction'], resources: ['*'] }],
|
|
27
|
+
* roleRef: 'myHandlerInvokeRole',
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
invocator?: {
|
|
31
|
+
principalRole?: string;
|
|
32
|
+
principalPermission?: string;
|
|
33
|
+
services?: ServicesValues;
|
|
34
|
+
roleRef?: string;
|
|
35
|
+
};
|
|
36
|
+
lambda?: LambdaProps;
|
|
37
|
+
/**
|
|
38
|
+
* Registers this Lambda function as a named global reference, allowing other
|
|
39
|
+
* resources to access its attributes (e.g. ARN, function name) by reference name.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ref: 'myHandler'
|
|
43
|
+
*/
|
|
44
|
+
ref?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface HandlerMetadata extends Omit<HandlerProps, 'name'>, LambdaMetadata {
|
|
47
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AppModule, LambdaHandler } from '@lafken/resolver';
|
|
2
|
+
import type { HandlerProps } from './handler.types';
|
|
3
|
+
declare const GlobalLambdaHandler: (new (...args: any[]) => {
|
|
4
|
+
register(namespaces: import("@lafken/common").RegisterNamespaces | (string & {}), id: string): void;
|
|
5
|
+
onResolve(callback: () => void): void;
|
|
6
|
+
readonly node: import("constructs").Node;
|
|
7
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
8
|
+
toString(): string;
|
|
9
|
+
}) & typeof LambdaHandler;
|
|
10
|
+
export declare class Handler extends GlobalLambdaHandler {
|
|
11
|
+
protected scope: AppModule;
|
|
12
|
+
protected props: HandlerProps;
|
|
13
|
+
constructor(scope: AppModule, id: string, props: HandlerProps);
|
|
14
|
+
private createInvokeRole;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Handler = void 0;
|
|
4
|
+
const resolver_1 = require("@lafken/resolver");
|
|
5
|
+
const GlobalLambdaHandler = resolver_1.lafkenResource.make(resolver_1.LambdaHandler);
|
|
6
|
+
class Handler extends GlobalLambdaHandler {
|
|
7
|
+
scope;
|
|
8
|
+
props;
|
|
9
|
+
constructor(scope, id, props) {
|
|
10
|
+
const { handlerMetadata, resourceMetadata } = props;
|
|
11
|
+
super(scope, id, {
|
|
12
|
+
filename: resourceMetadata.filename,
|
|
13
|
+
foldername: resourceMetadata.foldername,
|
|
14
|
+
name: handlerMetadata.name,
|
|
15
|
+
originalName: resourceMetadata.originalName,
|
|
16
|
+
lambda: handlerMetadata.lambda,
|
|
17
|
+
principal: handlerMetadata?.invocator?.principalPermission,
|
|
18
|
+
});
|
|
19
|
+
this.scope = scope;
|
|
20
|
+
this.props = props;
|
|
21
|
+
this.createInvokeRole(id);
|
|
22
|
+
if (props.handlerMetadata.ref) {
|
|
23
|
+
this.register('lambda', props.handlerMetadata.ref);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
createInvokeRole(id) {
|
|
27
|
+
const { invocator = {} } = this.props.handlerMetadata;
|
|
28
|
+
const { principalPermission: _exclude, ...rolePermissions } = invocator;
|
|
29
|
+
if (Object.values(rolePermissions).length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const appContext = (0, resolver_1.getAppContext)(this);
|
|
33
|
+
const role = new resolver_1.Role(this, 'handler-role', {
|
|
34
|
+
name: `${appContext.contextCreator}-${id.toLocaleLowerCase()}-invoke-role`,
|
|
35
|
+
principal: rolePermissions.principalRole,
|
|
36
|
+
services: (props) => [
|
|
37
|
+
...(Array.isArray(rolePermissions.services) ||
|
|
38
|
+
rolePermissions.services === undefined
|
|
39
|
+
? rolePermissions.services || []
|
|
40
|
+
: rolePermissions.services(props)),
|
|
41
|
+
{
|
|
42
|
+
type: 'lambda',
|
|
43
|
+
permissions: ['InvokeFunction'],
|
|
44
|
+
resources: [this.arn],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
if (this.props.handlerMetadata.ref) {
|
|
49
|
+
role.register('lambda', this.props.handlerMetadata.ref);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.Handler = Handler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resolver';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolver"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ClassResource } from '@lafken/common';
|
|
2
|
+
import { type AppModule, type ResolverType } from '@lafken/resolver';
|
|
3
|
+
export declare class StandaloneResolver implements ResolverType {
|
|
4
|
+
type: string;
|
|
5
|
+
create(module: AppModule, resource: ClassResource): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StandaloneResolver = void 0;
|
|
4
|
+
const common_1 = require("@lafken/common");
|
|
5
|
+
const resolver_1 = require("@lafken/resolver");
|
|
6
|
+
const main_1 = require("../main");
|
|
7
|
+
const handler_1 = require("./handler/handler");
|
|
8
|
+
class StandaloneResolver {
|
|
9
|
+
type = main_1.RESOURCE_TYPE;
|
|
10
|
+
create(module, resource) {
|
|
11
|
+
const minify = (0, resolver_1.getContextValueByScope)(module, 'minify');
|
|
12
|
+
const metadata = (0, common_1.getResourceMetadata)(resource);
|
|
13
|
+
const handlers = (0, common_1.getResourceHandlerMetadata)(resource);
|
|
14
|
+
resolver_1.lambdaAssets.initializeMetadata({
|
|
15
|
+
foldername: metadata.foldername,
|
|
16
|
+
filename: metadata.filename,
|
|
17
|
+
minify: metadata.minify ?? minify,
|
|
18
|
+
className: metadata.originalName,
|
|
19
|
+
methods: handlers.map((handler) => handler.name),
|
|
20
|
+
});
|
|
21
|
+
for (const handler of handlers) {
|
|
22
|
+
new handler_1.Handler(module, `${handler.name}-${metadata.name}`, {
|
|
23
|
+
handlerMetadata: handler,
|
|
24
|
+
resourceMetadata: metadata,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.StandaloneResolver = StandaloneResolver;
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lafken/standalone",
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Define Lambdas using TypeScript decorators - serverless event-driven infrastructure",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"aws",
|
|
8
|
+
"lambda",
|
|
9
|
+
"serverless",
|
|
10
|
+
"typescript",
|
|
11
|
+
"decorators",
|
|
12
|
+
"lafken"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/Hero64/lafken#readme",
|
|
15
|
+
"bugs": "https://github.com/Hero64/lafken/issues",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/Hero64/lafken",
|
|
19
|
+
"directory": "packages/event"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Aníbal Jorquera",
|
|
23
|
+
"exports": {
|
|
24
|
+
"./main": {
|
|
25
|
+
"import": "./lib/main/index.js",
|
|
26
|
+
"types": "./lib/main/index.d.ts",
|
|
27
|
+
"require": "./lib/main/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./resolver": {
|
|
30
|
+
"import": "./lib/resolver/index.js",
|
|
31
|
+
"types": "./lib/resolver/index.d.ts",
|
|
32
|
+
"require": "./lib/resolver/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"typesVersions": {
|
|
36
|
+
"*": {
|
|
37
|
+
"main": [
|
|
38
|
+
"./lib/main/index.d.ts"
|
|
39
|
+
],
|
|
40
|
+
"resolver": [
|
|
41
|
+
"./lib/resolver/index.d.ts"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"lib"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"reflect-metadata": "^0.2.2",
|
|
50
|
+
"@lafken/resolver": "0.12.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@cdktn/provider-aws": "^24.0.0",
|
|
54
|
+
"@swc/core": "^1.15.33",
|
|
55
|
+
"@swc/helpers": "^0.5.21",
|
|
56
|
+
"@vitest/runner": "^4.1.5",
|
|
57
|
+
"cdktn": "^0.23.0",
|
|
58
|
+
"cdktn-vitest": "^1.0.0",
|
|
59
|
+
"constructs": "^10.6.0",
|
|
60
|
+
"typescript": "6.0.3",
|
|
61
|
+
"unplugin-swc": "^1.5.9",
|
|
62
|
+
"vitest": "^4.1.5",
|
|
63
|
+
"@lafken/common": "0.12.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@cdktn/provider-aws": ">=23.0.0",
|
|
67
|
+
"cdktn": ">=0.22.0",
|
|
68
|
+
"constructs": "^10.4.5",
|
|
69
|
+
"@lafken/common": "0.12.0"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=20.19"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "pnpm clean && tsc -p ./tsconfig.build.json",
|
|
79
|
+
"check-types": "tsc --noEmit -p ./tsconfig.build.json",
|
|
80
|
+
"clean": "rm -rf ./lib",
|
|
81
|
+
"dev": "tsc -w",
|
|
82
|
+
"test": "vitest"
|
|
83
|
+
}
|
|
84
|
+
}
|