@lafken/common 0.10.1
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 +414 -0
- package/lib/constants/env.constants.d.ts +2 -0
- package/lib/constants/env.constants.js +5 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +17 -0
- package/lib/decorators/field/field.d.ts +9 -0
- package/lib/decorators/field/field.js +138 -0
- package/lib/decorators/field/field.types.d.ts +71 -0
- package/lib/decorators/field/field.types.js +8 -0
- package/lib/decorators/field/index.d.ts +2 -0
- package/lib/decorators/field/index.js +18 -0
- package/lib/decorators/index.d.ts +4 -0
- package/lib/decorators/index.js +20 -0
- package/lib/decorators/lambda/index.d.ts +2 -0
- package/lib/decorators/lambda/index.js +18 -0
- package/lib/decorators/lambda/lambda.d.ts +7 -0
- package/lib/decorators/lambda/lambda.js +58 -0
- package/lib/decorators/lambda/lambda.types.d.ts +204 -0
- package/lib/decorators/lambda/lambda.types.js +14 -0
- package/lib/decorators/payload/index.d.ts +2 -0
- package/lib/decorators/payload/index.js +18 -0
- package/lib/decorators/payload/payload.d.ts +2 -0
- package/lib/decorators/payload/payload.js +32 -0
- package/lib/decorators/payload/payload.types.d.ts +18 -0
- package/lib/decorators/payload/payload.types.js +2 -0
- package/lib/decorators/resource/index.d.ts +2 -0
- package/lib/decorators/resource/index.js +18 -0
- package/lib/decorators/resource/resource.d.ts +2 -0
- package/lib/decorators/resource/resource.js +25 -0
- package/lib/decorators/resource/resource.types.d.ts +31 -0
- package/lib/decorators/resource/resource.types.js +7 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +20 -0
- package/lib/types/env.types.d.ts +4 -0
- package/lib/types/env.types.js +2 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/index.js +23 -0
- package/lib/types/output.types.d.ts +55 -0
- package/lib/types/output.types.js +2 -0
- package/lib/types/override-resources.types.d.ts +35 -0
- package/lib/types/override-resources.types.js +2 -0
- package/lib/types/resource.types.d.ts +52 -0
- package/lib/types/resource.types.js +2 -0
- package/lib/types/services.types.d.ts +22 -0
- package/lib/types/services.types.js +2 -0
- package/lib/types/time.types.d.ts +8 -0
- package/lib/types/time.types.js +2 -0
- package/lib/types/utilities.types.d.ts +37 -0
- package/lib/types/utilities.types.js +2 -0
- package/lib/utils/build-env.utils.d.ts +2 -0
- package/lib/utils/build-env.utils.js +12 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +20 -0
- package/lib/utils/path.utils.d.ts +1 -0
- package/lib/utils/path.utils.js +16 -0
- package/lib/utils/resource.utils.d.ts +6 -0
- package/lib/utils/resource.utils.js +20 -0
- package/lib/utils/string.utils.d.ts +5 -0
- package/lib/utils/string.utils.js +36 -0
- package/package.json +55 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FieldProperties = void 0;
|
|
4
|
+
var FieldProperties;
|
|
5
|
+
(function (FieldProperties) {
|
|
6
|
+
FieldProperties["field"] = "lafken:field";
|
|
7
|
+
FieldProperties["payload"] = "lafken:payload";
|
|
8
|
+
})(FieldProperties || (exports.FieldProperties = FieldProperties = {}));
|
|
@@ -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("./field"), exports);
|
|
18
|
+
__exportStar(require("./field.types"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./field"), exports);
|
|
18
|
+
__exportStar(require("./lambda"), exports);
|
|
19
|
+
__exportStar(require("./payload"), exports);
|
|
20
|
+
__exportStar(require("./resource"), 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("./lambda"), exports);
|
|
18
|
+
__exportStar(require("./lambda.types"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { type AllowedTypes } from '../field';
|
|
3
|
+
import { type CreateEventDecoratorProps, type CreateLambdaDecoratorProps, LambdaArgumentTypes } from './lambda.types';
|
|
4
|
+
export declare const reflectArgumentMethod: (target: Function, methodName: string, type: LambdaArgumentTypes) => void;
|
|
5
|
+
export declare const createLambdaDecorator: <T, M>({ getLambdaMetadata, descriptorValue, argumentParser, }: CreateLambdaDecoratorProps<T, M>) => (props?: T) => (target: any, methodName: string, descriptor: PropertyDescriptor) => any;
|
|
6
|
+
export declare const createEventDecorator: ({ enableInLambdaInvocation, prefix }: CreateEventDecoratorProps) => (eventField: AllowedTypes) => (target: any, methodName: string, _number: number) => void;
|
|
7
|
+
export declare const Context: () => (target: any, methodName: string, _number: number) => void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = exports.createEventDecorator = exports.createLambdaDecorator = exports.reflectArgumentMethod = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const field_1 = require("../field");
|
|
7
|
+
const lambda_types_1 = require("./lambda.types");
|
|
8
|
+
const argumentsByType = {
|
|
9
|
+
[lambda_types_1.LambdaArgumentTypes.event]: ({ event }) => event,
|
|
10
|
+
[lambda_types_1.LambdaArgumentTypes.context]: ({ context }) => context,
|
|
11
|
+
};
|
|
12
|
+
const reflectArgumentMethod = (target, methodName, type) => {
|
|
13
|
+
const properties = Reflect.getMetadata(lambda_types_1.LambdaReflectKeys.arguments, target) || {};
|
|
14
|
+
properties[methodName] = [type, ...(properties[methodName] || [])];
|
|
15
|
+
Reflect.defineMetadata(lambda_types_1.LambdaReflectKeys.arguments, properties, target);
|
|
16
|
+
};
|
|
17
|
+
exports.reflectArgumentMethod = reflectArgumentMethod;
|
|
18
|
+
const createLambdaDecorator = ({ getLambdaMetadata, descriptorValue, argumentParser, }) => (props) => (target, methodName, descriptor) => {
|
|
19
|
+
if ((0, utils_1.isBuildEnvironment)()) {
|
|
20
|
+
const handlersMetadata = Reflect.getMetadata(lambda_types_1.LambdaReflectKeys.handlers, target) || [];
|
|
21
|
+
Reflect.defineMetadata(lambda_types_1.LambdaReflectKeys.handlers, [...handlersMetadata, getLambdaMetadata(props || {}, methodName)], target);
|
|
22
|
+
}
|
|
23
|
+
const lambdaArguments = Reflect.getMetadata(lambda_types_1.LambdaReflectKeys.arguments, target);
|
|
24
|
+
if (descriptorValue) {
|
|
25
|
+
return descriptorValue(descriptor);
|
|
26
|
+
}
|
|
27
|
+
const { value: originalValue } = descriptor;
|
|
28
|
+
const mapArgumentMethod = {
|
|
29
|
+
...argumentsByType,
|
|
30
|
+
...argumentParser,
|
|
31
|
+
};
|
|
32
|
+
descriptor.value = async (event, context) => {
|
|
33
|
+
const methodArguments = (lambdaArguments?.[methodName] || []).map((argumentType) => mapArgumentMethod[argumentType]({ event, context, methodName, target }));
|
|
34
|
+
const response = await originalValue.apply(this, methodArguments);
|
|
35
|
+
return response;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.createLambdaDecorator = createLambdaDecorator;
|
|
39
|
+
const reflectEventMetadata = (target, methodName, key, data) => {
|
|
40
|
+
const argumentsByMethod = Reflect.getMetadata(key, target) || {};
|
|
41
|
+
Reflect.defineMetadata(key, {
|
|
42
|
+
...argumentsByMethod,
|
|
43
|
+
...(data ? { [methodName]: data } : {}),
|
|
44
|
+
}, target);
|
|
45
|
+
};
|
|
46
|
+
const createEventDecorator = ({ enableInLambdaInvocation = false, prefix }) => (eventField) => (target, methodName, _number) => {
|
|
47
|
+
(0, exports.reflectArgumentMethod)(target, methodName, lambda_types_1.LambdaArgumentTypes.event);
|
|
48
|
+
if (!eventField || (!enableInLambdaInvocation && !(0, utils_1.isBuildEnvironment)())) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const field = (0, field_1.getEventFields)(prefix, eventField);
|
|
52
|
+
reflectEventMetadata(target, methodName, lambda_types_1.LambdaReflectKeys.event_param, field);
|
|
53
|
+
};
|
|
54
|
+
exports.createEventDecorator = createEventDecorator;
|
|
55
|
+
const Context = () => (target, methodName, _number) => {
|
|
56
|
+
(0, exports.reflectArgumentMethod)(target, methodName, lambda_types_1.LambdaArgumentTypes.context);
|
|
57
|
+
};
|
|
58
|
+
exports.Context = Context;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { EnvironmentValue, GetResourceProps } from '../../types';
|
|
2
|
+
import type { ServicesValues } from '../../types/services.types';
|
|
3
|
+
export interface VpcConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Enables IPv6 for dual-stack networking.
|
|
6
|
+
*
|
|
7
|
+
* When set to `true`, the Lambda function will support both IPv4 and IPv6
|
|
8
|
+
* traffic within the VPC. This is useful when the VPC subnets are configured
|
|
9
|
+
* with dual-stack addressing.
|
|
10
|
+
*
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
ipv6AllowedForDualStack?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Security group IDs to associate with the Lambda function.
|
|
16
|
+
*
|
|
17
|
+
* Specifies one or more VPC security groups that control inbound and outbound
|
|
18
|
+
* network traffic for the Lambda function. These security groups determine
|
|
19
|
+
* which resources the Lambda can communicate with inside and outside the VPC.
|
|
20
|
+
*/
|
|
21
|
+
securityGroupIds: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Subnet IDs where the Lambda function will be deployed.
|
|
24
|
+
*
|
|
25
|
+
* Specifies one or more VPC subnets in which the Lambda function will run.
|
|
26
|
+
* To ensure high availability, it is recommended to provide subnets across
|
|
27
|
+
* multiple Availability Zones.
|
|
28
|
+
*/
|
|
29
|
+
subnetIds: string[];
|
|
30
|
+
}
|
|
31
|
+
export type VpcConfigValue = VpcConfig | ((props: Pick<GetResourceProps, 'getSSMValue'>) => VpcConfig);
|
|
32
|
+
export interface AliasConfig {
|
|
33
|
+
/**
|
|
34
|
+
* The name of the Lambda alias.
|
|
35
|
+
*
|
|
36
|
+
* This name will be used to create an AWS Lambda alias pointing to the
|
|
37
|
+
* latest published version of the function. The alias acts as a stable
|
|
38
|
+
* reference to a specific function version.
|
|
39
|
+
*/
|
|
40
|
+
name: string;
|
|
41
|
+
/**
|
|
42
|
+
* Number of provisioned concurrent executions for this alias.
|
|
43
|
+
*
|
|
44
|
+
* When set to a value greater than 0, a `LambdaProvisionedConcurrencyConfig`
|
|
45
|
+
* will be created, ensuring that the specified number of execution environments
|
|
46
|
+
* are initialized and ready to respond immediately to invocations.
|
|
47
|
+
*
|
|
48
|
+
* This helps reduce cold start latency for latency-sensitive workloads.
|
|
49
|
+
*
|
|
50
|
+
* @default undefined (no provisioned concurrency)
|
|
51
|
+
*/
|
|
52
|
+
provisionedExecutions?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface LambdaProps {
|
|
55
|
+
/**
|
|
56
|
+
* Lambda execution timeout.
|
|
57
|
+
*
|
|
58
|
+
* Specifies the maximum amount of time (in seconds) that the Lambda
|
|
59
|
+
* function is allowed to run before being terminated. If the execution
|
|
60
|
+
* exceeds this limit, the function will be stopped and an error will be raised.
|
|
61
|
+
*/
|
|
62
|
+
timeout?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Lambda memory allocation.
|
|
65
|
+
*
|
|
66
|
+
* Specifies the amount of memory (in MB) allocated to the Lambda function.
|
|
67
|
+
* Increasing memory also increases the CPU and network resources proportionally.
|
|
68
|
+
*/
|
|
69
|
+
memory?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Lambda NodeJS runtime
|
|
72
|
+
*
|
|
73
|
+
* Defines the Node.js runtime environment that the Lambda will use
|
|
74
|
+
* during execution. Only supported LTS versions are allowed to ensure
|
|
75
|
+
* long-term stability and AWS compatibility.
|
|
76
|
+
*
|
|
77
|
+
* Supported values:
|
|
78
|
+
* - `24` → Node.js 24
|
|
79
|
+
* - `22` → Node.js 22
|
|
80
|
+
* - `20` → Node.js 20
|
|
81
|
+
*/
|
|
82
|
+
runtime?: 24 | 22 | 20;
|
|
83
|
+
/**
|
|
84
|
+
* Lambda services.
|
|
85
|
+
*
|
|
86
|
+
* Defines which AWS services the Lambda function is allowed to access.
|
|
87
|
+
* Internally, a role is created with the specified service permissions,
|
|
88
|
+
* granting the Lambda the ability to interact with those resources.
|
|
89
|
+
*/
|
|
90
|
+
services?: ServicesValues;
|
|
91
|
+
/**
|
|
92
|
+
* Lambda environments.
|
|
93
|
+
*
|
|
94
|
+
* Defines environment values that will be applied specifically to
|
|
95
|
+
* this Lambda. These values override any global or stack-level
|
|
96
|
+
* environment configuration.
|
|
97
|
+
*
|
|
98
|
+
* Values can be provided in three formats:
|
|
99
|
+
* 1. `string` - The value will be taken from the `.env` file if present.
|
|
100
|
+
* 2. `Record<string, string | number | boolean | EnvFunction>` - Directly provides the value as a string.
|
|
101
|
+
* 3. `Record<string, EnvFunction>` - Functions can compute dynamic values based on resources
|
|
102
|
+
* created in the project, using the `getResourceValue` helper.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Load value from .env
|
|
106
|
+
* ["ENV_VALUE"]
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Provide static values
|
|
110
|
+
* [
|
|
111
|
+
* { "ENV_VALUE": "static_string" },
|
|
112
|
+
* { "ENV_NUMBER": 123 }
|
|
113
|
+
* ]
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // Provide dynamic values from resources
|
|
117
|
+
* [
|
|
118
|
+
* {
|
|
119
|
+
* "ENV_VALUE": {
|
|
120
|
+
* name: "any",
|
|
121
|
+
* other: ({ getResourceValue }) => getResourceValue("s3_bucket", "arn")
|
|
122
|
+
* }
|
|
123
|
+
* }
|
|
124
|
+
* ]
|
|
125
|
+
*/
|
|
126
|
+
env?: EnvironmentValue;
|
|
127
|
+
/**
|
|
128
|
+
* Lambda tags.
|
|
129
|
+
*
|
|
130
|
+
* Specifies a set of tags that will be applied to lambda function.
|
|
131
|
+
*/
|
|
132
|
+
tags?: Record<string, string>;
|
|
133
|
+
/**
|
|
134
|
+
* Enables AWS X-Ray tracing for Lambda function.
|
|
135
|
+
*
|
|
136
|
+
* When set to `true`, X-Ray tracing is activated, allowing you to
|
|
137
|
+
* collect detailed information about requests, performance, and
|
|
138
|
+
* interactions with other AWS services.
|
|
139
|
+
*
|
|
140
|
+
* This is useful for debugging, monitoring, and gaining visibility
|
|
141
|
+
* into the execution flow of your Lambda.
|
|
142
|
+
*/
|
|
143
|
+
enableTrace?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* VPC configuration for the Lambda function.
|
|
146
|
+
*
|
|
147
|
+
* When provided, the Lambda function will be deployed inside the specified
|
|
148
|
+
* VPC, allowing it to access private resources such as RDS databases,
|
|
149
|
+
* ElastiCache clusters, or internal services that are not publicly accessible.
|
|
150
|
+
*
|
|
151
|
+
* Requires specifying at least one subnet and one security group.
|
|
152
|
+
*/
|
|
153
|
+
vpcConfig?: VpcConfigValue;
|
|
154
|
+
/**
|
|
155
|
+
* Alias configuration for the Lambda function.
|
|
156
|
+
*
|
|
157
|
+
* When provided, the Lambda function will be published (creating a new version)
|
|
158
|
+
* and a Lambda alias will be created pointing to the latest published version.
|
|
159
|
+
*
|
|
160
|
+
* If `provisionedExecutions` is set to a value greater than 0, a provisioned
|
|
161
|
+
* concurrency configuration will also be created for the alias to reduce
|
|
162
|
+
* cold start latency.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* // Create an alias without provisioned concurrency
|
|
166
|
+
* { name: 'live' }
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* // Create an alias with provisioned concurrency
|
|
170
|
+
* { name: 'live', provisionedExecutions: 5 }
|
|
171
|
+
*/
|
|
172
|
+
alias?: AliasConfig;
|
|
173
|
+
}
|
|
174
|
+
export interface LambdaMetadata {
|
|
175
|
+
name: string;
|
|
176
|
+
lambda?: LambdaProps;
|
|
177
|
+
description?: string;
|
|
178
|
+
}
|
|
179
|
+
export declare enum LambdaReflectKeys {
|
|
180
|
+
handlers = "lambda:handlers",
|
|
181
|
+
arguments = "lambda:arguments",
|
|
182
|
+
event_param = "lambda:event_params"
|
|
183
|
+
}
|
|
184
|
+
export declare enum LambdaArgumentTypes {
|
|
185
|
+
event = "event",
|
|
186
|
+
context = "context"
|
|
187
|
+
}
|
|
188
|
+
export type CallbackParam = (error: boolean | null, response?: any) => void;
|
|
189
|
+
export type LambdaArguments = Record<string, LambdaArgumentTypes[]>;
|
|
190
|
+
export type LambdaArgumentsType = Record<LambdaArgumentTypes, ({ event, context, }: {
|
|
191
|
+
event: any;
|
|
192
|
+
context: any;
|
|
193
|
+
methodName: string;
|
|
194
|
+
target: any;
|
|
195
|
+
}) => any>;
|
|
196
|
+
export interface CreateLambdaDecoratorProps<T, M> {
|
|
197
|
+
getLambdaMetadata: (params: T, methodName: string) => M;
|
|
198
|
+
descriptorValue?: (descriptor: PropertyDescriptor) => any;
|
|
199
|
+
argumentParser?: Partial<LambdaArgumentsType | (string & {})>;
|
|
200
|
+
}
|
|
201
|
+
export interface CreateEventDecoratorProps {
|
|
202
|
+
prefix: string;
|
|
203
|
+
enableInLambdaInvocation?: boolean;
|
|
204
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LambdaArgumentTypes = exports.LambdaReflectKeys = void 0;
|
|
4
|
+
var LambdaReflectKeys;
|
|
5
|
+
(function (LambdaReflectKeys) {
|
|
6
|
+
LambdaReflectKeys["handlers"] = "lambda:handlers";
|
|
7
|
+
LambdaReflectKeys["arguments"] = "lambda:arguments";
|
|
8
|
+
LambdaReflectKeys["event_param"] = "lambda:event_params";
|
|
9
|
+
})(LambdaReflectKeys || (exports.LambdaReflectKeys = LambdaReflectKeys = {}));
|
|
10
|
+
var LambdaArgumentTypes;
|
|
11
|
+
(function (LambdaArgumentTypes) {
|
|
12
|
+
LambdaArgumentTypes["event"] = "event";
|
|
13
|
+
LambdaArgumentTypes["context"] = "context";
|
|
14
|
+
})(LambdaArgumentTypes || (exports.LambdaArgumentTypes = LambdaArgumentTypes = {}));
|
|
@@ -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("./payload"), exports);
|
|
18
|
+
__exportStar(require("./payload.types"), exports);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { CreatePayloadDecoratorProps, PayloadProps } from './payload.types';
|
|
2
|
+
export declare const createPayloadDecorator: <T extends PayloadProps, M>({ prefix, getMetadata, createUniqueId, enableInLambdaInvocation, }: CreatePayloadDecoratorProps<T, M>) => (props?: T) => (target: Function) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPayloadDecorator = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const field_1 = require("../field");
|
|
6
|
+
const payloadIds = {};
|
|
7
|
+
const createPayloadDecorator = ({ prefix, getMetadata, createUniqueId = false, enableInLambdaInvocation = false, }) => (props) => (target) => {
|
|
8
|
+
if (!(0, utils_1.isBuildEnvironment)() && !enableInLambdaInvocation) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const { name = target.name } = props || {};
|
|
12
|
+
let id = name;
|
|
13
|
+
if (createUniqueId) {
|
|
14
|
+
payloadIds[name] ??= 0;
|
|
15
|
+
if (payloadIds[name] > 0) {
|
|
16
|
+
id = `${name}_${payloadIds[name]}`;
|
|
17
|
+
}
|
|
18
|
+
payloadIds[name]++;
|
|
19
|
+
}
|
|
20
|
+
let payloadMetadata = {
|
|
21
|
+
id,
|
|
22
|
+
name,
|
|
23
|
+
};
|
|
24
|
+
if (getMetadata) {
|
|
25
|
+
payloadMetadata = {
|
|
26
|
+
...payloadMetadata,
|
|
27
|
+
...getMetadata(props),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
Reflect.defineMetadata(`${prefix}:${field_1.FieldProperties.payload}`, payloadMetadata, target);
|
|
31
|
+
};
|
|
32
|
+
exports.createPayloadDecorator = createPayloadDecorator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface PayloadProps {
|
|
2
|
+
/**
|
|
3
|
+
* Payload name.
|
|
4
|
+
*
|
|
5
|
+
* Specifies the name of the payload, which is used to identify
|
|
6
|
+
* it within the application or during data processing.
|
|
7
|
+
*/
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PayloadMetadata extends Required<PayloadProps> {
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CreatePayloadDecoratorProps<P extends PayloadProps, M> {
|
|
14
|
+
prefix: string;
|
|
15
|
+
enableInLambdaInvocation?: boolean;
|
|
16
|
+
createUniqueId?: boolean;
|
|
17
|
+
getMetadata?: (props?: P) => Omit<M, keyof PayloadMetadata>;
|
|
18
|
+
}
|
|
@@ -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("./resource"), exports);
|
|
18
|
+
__exportStar(require("./resource.types"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createResourceDecorator = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const path_utils_1 = require("../../utils/path.utils");
|
|
7
|
+
const resource_types_1 = require("./resource.types");
|
|
8
|
+
const createResourceDecorator = (decoratorProps) => (props) => (constructor) => {
|
|
9
|
+
if (!(0, utils_1.isBuildEnvironment)()) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { type, callerFileIndex, getMetadata = () => props } = decoratorProps;
|
|
13
|
+
const additionalMetadata = getMetadata(props || {});
|
|
14
|
+
const callerFile = (0, path_utils_1.getCallerFileName)(callerFileIndex);
|
|
15
|
+
Reflect.defineMetadata(resource_types_1.ResourceReflectKeys.resource, {
|
|
16
|
+
...additionalMetadata,
|
|
17
|
+
type,
|
|
18
|
+
name: props?.name || constructor.name,
|
|
19
|
+
foldername: (0, node_path_1.dirname)(callerFile),
|
|
20
|
+
filename: (0, node_path_1.basename)(callerFile).replace('.js', ''),
|
|
21
|
+
originalName: constructor.name,
|
|
22
|
+
minify: props?.minify ?? true,
|
|
23
|
+
}, constructor);
|
|
24
|
+
};
|
|
25
|
+
exports.createResourceDecorator = createResourceDecorator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare enum ResourceReflectKeys {
|
|
2
|
+
resource = "resource"
|
|
3
|
+
}
|
|
4
|
+
export interface ResourceProps {
|
|
5
|
+
/**
|
|
6
|
+
* Resource name.
|
|
7
|
+
*
|
|
8
|
+
* Specifies the name of the resource. This name is used to identify
|
|
9
|
+
* the resource within the application, stack, or deployment.
|
|
10
|
+
*/
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Resource minify
|
|
14
|
+
*
|
|
15
|
+
* Specifies whether the code should be minified when the resource is processed
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
minify?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ResourceMetadata extends Required<ResourceProps> {
|
|
22
|
+
type: string;
|
|
23
|
+
filename: string;
|
|
24
|
+
foldername: string;
|
|
25
|
+
originalName: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ResourceDecoratorProps<T> {
|
|
28
|
+
type: string;
|
|
29
|
+
callerFileIndex?: number;
|
|
30
|
+
getMetadata?: (props: T) => T;
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceReflectKeys = void 0;
|
|
4
|
+
var ResourceReflectKeys;
|
|
5
|
+
(function (ResourceReflectKeys) {
|
|
6
|
+
ResourceReflectKeys["resource"] = "resource";
|
|
7
|
+
})(ResourceReflectKeys || (exports.ResourceReflectKeys = ResourceReflectKeys = {}));
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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("./constants/env.constants"), exports);
|
|
18
|
+
__exportStar(require("./decorators"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./env.types"), exports);
|
|
18
|
+
__exportStar(require("./output.types"), exports);
|
|
19
|
+
__exportStar(require("./override-resources.types"), exports);
|
|
20
|
+
__exportStar(require("./resource.types"), exports);
|
|
21
|
+
__exportStar(require("./services.types"), exports);
|
|
22
|
+
__exportStar(require("./time.types"), exports);
|
|
23
|
+
__exportStar(require("./utilities.types"), exports);
|