@lafken/common 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.
Files changed (61) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +66 -0
  3. package/lib/constants/env.constants.d.ts +2 -0
  4. package/lib/constants/env.constants.js +5 -0
  5. package/lib/constants/index.d.ts +1 -0
  6. package/lib/constants/index.js +17 -0
  7. package/lib/decorators/field/field.d.ts +9 -0
  8. package/lib/decorators/field/field.js +132 -0
  9. package/lib/decorators/field/field.types.d.ts +69 -0
  10. package/lib/decorators/field/field.types.js +8 -0
  11. package/lib/decorators/field/index.d.ts +2 -0
  12. package/lib/decorators/field/index.js +18 -0
  13. package/lib/decorators/index.d.ts +4 -0
  14. package/lib/decorators/index.js +20 -0
  15. package/lib/decorators/lambda/index.d.ts +2 -0
  16. package/lib/decorators/lambda/index.js +18 -0
  17. package/lib/decorators/lambda/lambda.d.ts +8 -0
  18. package/lib/decorators/lambda/lambda.js +63 -0
  19. package/lib/decorators/lambda/lambda.types.d.ts +126 -0
  20. package/lib/decorators/lambda/lambda.types.js +15 -0
  21. package/lib/decorators/payload/index.d.ts +2 -0
  22. package/lib/decorators/payload/index.js +18 -0
  23. package/lib/decorators/payload/payload.d.ts +2 -0
  24. package/lib/decorators/payload/payload.js +32 -0
  25. package/lib/decorators/payload/payload.types.d.ts +18 -0
  26. package/lib/decorators/payload/payload.types.js +2 -0
  27. package/lib/decorators/resource/index.d.ts +2 -0
  28. package/lib/decorators/resource/index.js +18 -0
  29. package/lib/decorators/resource/resource.d.ts +2 -0
  30. package/lib/decorators/resource/resource.js +25 -0
  31. package/lib/decorators/resource/resource.types.d.ts +31 -0
  32. package/lib/decorators/resource/resource.types.js +7 -0
  33. package/lib/index.d.ts +4 -0
  34. package/lib/index.js +20 -0
  35. package/lib/types/env.types.d.ts +4 -0
  36. package/lib/types/env.types.js +2 -0
  37. package/lib/types/index.d.ts +7 -0
  38. package/lib/types/index.js +23 -0
  39. package/lib/types/output.types.d.ts +2 -0
  40. package/lib/types/output.types.js +2 -0
  41. package/lib/types/override-resources.types.d.ts +35 -0
  42. package/lib/types/override-resources.types.js +2 -0
  43. package/lib/types/resource.types.d.ts +8 -0
  44. package/lib/types/resource.types.js +2 -0
  45. package/lib/types/services.types.d.ts +22 -0
  46. package/lib/types/services.types.js +2 -0
  47. package/lib/types/time.types.d.ts +8 -0
  48. package/lib/types/time.types.js +2 -0
  49. package/lib/types/utilities.types.d.ts +33 -0
  50. package/lib/types/utilities.types.js +2 -0
  51. package/lib/utils/build-env.utils.d.ts +2 -0
  52. package/lib/utils/build-env.utils.js +12 -0
  53. package/lib/utils/index.d.ts +4 -0
  54. package/lib/utils/index.js +20 -0
  55. package/lib/utils/path.utils.d.ts +1 -0
  56. package/lib/utils/path.utils.js +16 -0
  57. package/lib/utils/resource.utils.d.ts +6 -0
  58. package/lib/utils/resource.utils.js +20 -0
  59. package/lib/utils/string.utils.d.ts +4 -0
  60. package/lib/utils/string.utils.js +29 -0
  61. package/package.json +30 -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,66 @@
1
+ # @lafken/common
2
+
3
+ `@lafken/common` is the core utility package for the Lafken framework. It provides the essential factory functions and utilities used to create the decorators that define infrastructure resources and Lambda handlers throughout the ecosystem.
4
+
5
+ ## Features
6
+
7
+ ### Decorator Factories
8
+
9
+ The package exports powerful factories to create custom decorators that integrate with the framework's metadata system.
10
+
11
+ #### `createResourceDecorator`
12
+
13
+ Use this factory to create class-level decorators that mark a class as a deployable resource (e.g., a State Machine, a Queue, or a custom Event).
14
+
15
+ It automatically captures:
16
+ - The resource name.
17
+ - The file path and folder name (for bundling).
18
+ - Custom metadata defined in your props.
19
+
20
+ ```typescript
21
+ import { createResourceDecorator } from '@lafken/common';
22
+
23
+ export const MyCustomResource = createResourceDecorator({
24
+ type: 'MY_CUSTOM_RESOURCE',
25
+ callerFileIndex: 5, // Adjusts stack trace to find the caller file
26
+ });
27
+
28
+ // Usage
29
+ @MyCustomResource({ ... })
30
+ export class MyService { ... }
31
+ ```
32
+
33
+ #### `createLambdaDecorator`
34
+
35
+ Use this factory to create method-level decorators that mark methods as Lambda function handlers. It handles:
36
+ - Method metadata reflection.
37
+ - Argument injection (Event, Context, Callback).
38
+
39
+ ```typescript
40
+ import { createLambdaDecorator } from '@lafken/common';
41
+
42
+ export const MyLambdaTrigger = <T>(props: T) =>
43
+ createLambdaDecorator({
44
+ getLambdaMetadata: (props, methodName) => ({
45
+ ...props,
46
+ name: methodName,
47
+ }),
48
+ })(props);
49
+
50
+ // Usage
51
+ class MyService {
52
+ @MyLambdaTrigger({ ... })
53
+ handleRequest(@Event() event: any) { ... }
54
+ }
55
+ ```
56
+
57
+ ### Metadata Utilities
58
+
59
+ `@lafken/common` provides utilities to read the metadata stored by these decorators, which resolvers use to build the actual infrastructure.
60
+
61
+ - `getResourceMetadata(target)`: Retrieves metadata from a resource class.
62
+ - `getResourceHandlerMetadata(target)`: Retrieves metadata for all lambda handlers in a class.
63
+
64
+ ## Usage
65
+
66
+ This package is intended for internal use within the Lafken framework or for advanced users extending the framework with custom resource types. It ensures consistent metadata handling across all `@lafken/*` packages.
@@ -0,0 +1,2 @@
1
+ export declare const LAFKEN_CONTEXT = "LAFKEN_CONTEXT";
2
+ export declare const LAFKEN_CONTEXT_VALUE = "BUILD";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LAFKEN_CONTEXT_VALUE = exports.LAFKEN_CONTEXT = void 0;
4
+ exports.LAFKEN_CONTEXT = 'LAFKEN_CONTEXT';
5
+ exports.LAFKEN_CONTEXT_VALUE = 'BUILD';
@@ -0,0 +1 @@
1
+ export * from './env.constants';
@@ -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("./env.constants"), exports);
@@ -0,0 +1,9 @@
1
+ import 'reflect-metadata';
2
+ import { type AllowedTypes, type BaseFieldMetadata, type CreateFieldDecoratorProps, FieldProperties, type FieldProps, type PrimitiveTypes } from './field.types';
3
+ export declare const primitiveTypeValues: Set<PrimitiveTypes>;
4
+ export declare const primitiveTypeofValues: Set<string>;
5
+ export declare const mapTypeofValueToPrimitiveType: Record<string, PrimitiveTypes>;
6
+ export declare const getPrimitiveType: (type: AllowedTypes) => PrimitiveTypes | undefined;
7
+ export declare const getEventFields: (prefix: string, target?: AllowedTypes, name?: string) => BaseFieldMetadata | undefined;
8
+ export declare const createFieldDecorator: <T extends FieldProps, M>({ prefix, enableInLambdaInvocation, getMetadata, }: CreateFieldDecoratorProps<T, M>) => (props?: T) => (target: any, destinationName: string) => void;
9
+ export declare const createFieldName: (prefix: string, type: FieldProperties) => string;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFieldName = exports.createFieldDecorator = exports.getEventFields = exports.getPrimitiveType = exports.mapTypeofValueToPrimitiveType = exports.primitiveTypeofValues = exports.primitiveTypeValues = void 0;
4
+ require("reflect-metadata");
5
+ const utils_1 = require("../../utils");
6
+ const build_env_utils_1 = require("../../utils/build-env.utils");
7
+ const field_types_1 = require("./field.types");
8
+ exports.primitiveTypeValues = new Set([
9
+ 'Boolean',
10
+ 'Number',
11
+ 'String',
12
+ ]);
13
+ exports.primitiveTypeofValues = new Set(['boolean', 'number', 'string']);
14
+ exports.mapTypeofValueToPrimitiveType = {
15
+ boolean: 'Boolean',
16
+ number: 'Number',
17
+ string: 'String',
18
+ };
19
+ const getPrimitiveType = (type) => {
20
+ if (type === String)
21
+ return 'String';
22
+ if (type === Number)
23
+ return 'Number';
24
+ if (type === Boolean)
25
+ return 'Boolean';
26
+ };
27
+ exports.getPrimitiveType = getPrimitiveType;
28
+ const getEventFields = (prefix, target, name = 'event') => {
29
+ if (!target) {
30
+ return undefined;
31
+ }
32
+ return getFieldMetadata({
33
+ destinationName: name,
34
+ type: `${name}_type`,
35
+ fieldProps: {
36
+ type: target,
37
+ },
38
+ prefix,
39
+ });
40
+ };
41
+ exports.getEventFields = getEventFields;
42
+ const getObjectMetadata = (metadata, payloadClass, prefix) => {
43
+ const payloadMetadata = (0, utils_1.getMetadataByKey)(payloadClass, (0, exports.createFieldName)(prefix, field_types_1.FieldProperties.payload)) || {
44
+ name: payloadClass.name,
45
+ id: payloadClass.name,
46
+ };
47
+ const properties = (0, utils_1.getMetadataPrototypeByKey)(payloadClass, (0, exports.createFieldName)(prefix, field_types_1.FieldProperties.field));
48
+ if (!properties?.length) {
49
+ throw new Error(`should include Field properties in ${payloadClass.name} class`);
50
+ }
51
+ return {
52
+ ...metadata,
53
+ properties,
54
+ type: 'Object',
55
+ payload: payloadMetadata,
56
+ };
57
+ };
58
+ const getFieldMetadata = (props) => {
59
+ const { fieldProps, destinationName, type, prefix } = props;
60
+ const metadata = {
61
+ destinationName,
62
+ name: fieldProps?.name || destinationName,
63
+ };
64
+ const primitiveType = (0, exports.getPrimitiveType)(type);
65
+ const typeHasValue = exports.mapTypeofValueToPrimitiveType[typeof fieldProps?.type];
66
+ if (fieldProps?.type !== undefined) {
67
+ if (typeof fieldProps.type === 'function') {
68
+ return getObjectMetadata(metadata, fieldProps.type, prefix);
69
+ }
70
+ if (Array.isArray(fieldProps.type)) {
71
+ const arrayPrimitiveType = (0, exports.getPrimitiveType)(fieldProps.type[0]);
72
+ let items;
73
+ if (arrayPrimitiveType) {
74
+ items = {
75
+ type: arrayPrimitiveType,
76
+ name: arrayPrimitiveType,
77
+ destinationName: arrayPrimitiveType,
78
+ };
79
+ }
80
+ else {
81
+ if (typeof fieldProps.type[0] === 'function') {
82
+ items = getObjectMetadata({
83
+ name: 'Object',
84
+ destinationName: 'Object',
85
+ }, fieldProps.type[0], prefix);
86
+ }
87
+ }
88
+ return {
89
+ ...metadata,
90
+ type: 'Array',
91
+ items,
92
+ };
93
+ }
94
+ }
95
+ if (exports.primitiveTypeValues.has(type) ||
96
+ exports.primitiveTypeValues.has(primitiveType) ||
97
+ typeHasValue) {
98
+ return {
99
+ type: primitiveType || typeHasValue || type,
100
+ initialValue: typeHasValue ? fieldProps?.type : undefined,
101
+ ...metadata,
102
+ };
103
+ }
104
+ throw new Error(`unidentified type ${type} in ${destinationName} field`);
105
+ };
106
+ const createFieldDecorator = ({ prefix, enableInLambdaInvocation, getMetadata, }) => (props) => (target, destinationName) => {
107
+ if (!(0, build_env_utils_1.isBuildEnvironment)() && !enableInLambdaInvocation) {
108
+ return;
109
+ }
110
+ const filedKey = (0, exports.createFieldName)(prefix, field_types_1.FieldProperties.field);
111
+ const fields = (0, utils_1.getMetadataByKey)(target, filedKey) || [];
112
+ const propertyType = Reflect.getMetadata('design:type', target, destinationName).name;
113
+ const parentMetadata = getMetadata(props);
114
+ const metadata = [
115
+ ...fields,
116
+ {
117
+ ...parentMetadata,
118
+ ...getFieldMetadata({
119
+ destinationName,
120
+ type: propertyType,
121
+ fieldProps: props,
122
+ prefix,
123
+ }),
124
+ },
125
+ ];
126
+ Reflect.defineMetadata(filedKey, metadata, target);
127
+ };
128
+ exports.createFieldDecorator = createFieldDecorator;
129
+ const createFieldName = (prefix, type) => {
130
+ return `${prefix}:${type}`;
131
+ };
132
+ exports.createFieldName = createFieldName;
@@ -0,0 +1,69 @@
1
+ import type { PayloadMetadata } from '../payload';
2
+ export type BasicTypes = StringConstructor | NumberConstructor | BooleanConstructor;
3
+ export type AllowedTypes = String | Number | Boolean | Function | [String | Number | Boolean | Function];
4
+ export type AllowedTypesWithoutFunction = BasicTypes | [BasicTypes];
5
+ export type EnumValue = (string | number)[];
6
+ export interface FieldProps {
7
+ /**
8
+ * Original field name.
9
+ *
10
+ * Specifies the original name of the field as it is expected
11
+ * in the input or payload. This is used to map incoming data
12
+ * to the corresponding property in the system.
13
+ */
14
+ name?: string;
15
+ /**
16
+ * Field data type.
17
+ *
18
+ * Specifies the type of the field. By default, the type is inferred
19
+ * from the property that decorates the field. However, it can be
20
+ * explicitly set to a primitive type such as `String`, `Number`,
21
+ * `Boolean`, or to another payload type.
22
+ *
23
+ * This ensures correct parsing, validation, and serialization of the field's value.
24
+ */
25
+ type?: AllowedTypes;
26
+ }
27
+ export interface BaseFieldMetadata {
28
+ name: string;
29
+ destinationName: string;
30
+ }
31
+ export interface StringField extends BaseFieldMetadata {
32
+ type: 'String';
33
+ initialValue?: string;
34
+ }
35
+ export interface NumberField extends BaseFieldMetadata {
36
+ type: 'Number';
37
+ initialValue?: number;
38
+ }
39
+ export interface BooleanField extends BaseFieldMetadata {
40
+ type: 'Boolean';
41
+ initialValue?: boolean;
42
+ }
43
+ export interface ObjectField extends BaseFieldMetadata {
44
+ type: 'Object';
45
+ properties: FieldMetadata[];
46
+ payload: PayloadMetadata;
47
+ }
48
+ export interface ArrayField extends BaseFieldMetadata {
49
+ type: 'Array';
50
+ items: FieldMetadata;
51
+ }
52
+ export type FieldMetadata = StringField | NumberField | BooleanField | ObjectField | ArrayField;
53
+ export type FieldTypes = FieldMetadata['type'];
54
+ export type PrimitiveTypes = Extract<FieldTypes, 'String' | 'Number' | 'Boolean'>;
55
+ export declare enum FieldProperties {
56
+ field = "lafken:field",
57
+ payload = "lafken:payload"
58
+ }
59
+ export interface CreateFieldDecoratorProps<P extends FieldProps, M> {
60
+ prefix: string;
61
+ enableInLambdaInvocation?: boolean;
62
+ getMetadata: (props?: P) => Omit<M, keyof FieldMetadata>;
63
+ }
64
+ export interface GetFieldMetadataProps {
65
+ type: string;
66
+ prefix: string;
67
+ destinationName: string;
68
+ fieldProps?: FieldProps;
69
+ }
@@ -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,2 @@
1
+ export * from './field';
2
+ export * from './field.types';
@@ -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,4 @@
1
+ export * from './field';
2
+ export * from './lambda';
3
+ export * from './payload';
4
+ export * from './resource';
@@ -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,2 @@
1
+ export * from './lambda';
2
+ export * from './lambda.types';
@@ -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,8 @@
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 Callback: () => (target: any, methodName: string, _number: number) => void;
8
+ export declare const Context: () => (target: any, methodName: string, _number: number) => void;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Context = exports.Callback = 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.callback]: ({ callback }) => callback,
11
+ [lambda_types_1.LambdaArgumentTypes.context]: ({ context }) => context,
12
+ };
13
+ const reflectArgumentMethod = (target, methodName, type) => {
14
+ const properties = Reflect.getMetadata(lambda_types_1.LambdaReflectKeys.arguments, target) || {};
15
+ properties[methodName] = [type, ...(properties[methodName] || [])];
16
+ Reflect.defineMetadata(lambda_types_1.LambdaReflectKeys.arguments, properties, target);
17
+ };
18
+ exports.reflectArgumentMethod = reflectArgumentMethod;
19
+ const createLambdaDecorator = ({ getLambdaMetadata, descriptorValue, argumentParser, }) => (props) => (target, methodName, descriptor) => {
20
+ if ((0, utils_1.isBuildEnvironment)()) {
21
+ const handlersMetadata = Reflect.getMetadata(lambda_types_1.LambdaReflectKeys.handlers, target) || [];
22
+ Reflect.defineMetadata(lambda_types_1.LambdaReflectKeys.handlers, [...handlersMetadata, getLambdaMetadata(props || {}, methodName)], target);
23
+ }
24
+ const lambdaArguments = Reflect.getMetadata(lambda_types_1.LambdaReflectKeys.arguments, target);
25
+ if (descriptorValue) {
26
+ return descriptorValue(descriptor);
27
+ }
28
+ const { value: originalValue } = descriptor;
29
+ const mapArgumentMethod = {
30
+ ...argumentsByType,
31
+ ...argumentParser,
32
+ };
33
+ descriptor.value = async (event, context, callback) => {
34
+ const methodArguments = (lambdaArguments?.[methodName] || []).map((argumentType) => mapArgumentMethod[argumentType]({ event, context, methodName, target, callback }));
35
+ const response = await originalValue.apply(this, methodArguments);
36
+ return response;
37
+ };
38
+ };
39
+ exports.createLambdaDecorator = createLambdaDecorator;
40
+ const reflectEventMetadata = (target, methodName, key, data) => {
41
+ const argumentsByMethod = Reflect.getMetadata(key, target) || {};
42
+ Reflect.defineMetadata(key, {
43
+ ...argumentsByMethod,
44
+ ...(data ? { [methodName]: data } : {}),
45
+ }, target);
46
+ };
47
+ const createEventDecorator = ({ enableInLambdaInvocation = false, prefix }) => (eventField) => (target, methodName, _number) => {
48
+ (0, exports.reflectArgumentMethod)(target, methodName, lambda_types_1.LambdaArgumentTypes.event);
49
+ if (!eventField || (!enableInLambdaInvocation && !(0, utils_1.isBuildEnvironment)())) {
50
+ return;
51
+ }
52
+ const field = (0, field_1.getEventFields)(prefix, eventField);
53
+ reflectEventMetadata(target, methodName, lambda_types_1.LambdaReflectKeys.event_param, field);
54
+ };
55
+ exports.createEventDecorator = createEventDecorator;
56
+ const Callback = () => (target, methodName, _number) => {
57
+ (0, exports.reflectArgumentMethod)(target, methodName, lambda_types_1.LambdaArgumentTypes.callback);
58
+ };
59
+ exports.Callback = Callback;
60
+ const Context = () => (target, methodName, _number) => {
61
+ (0, exports.reflectArgumentMethod)(target, methodName, lambda_types_1.LambdaArgumentTypes.context);
62
+ };
63
+ exports.Context = Context;
@@ -0,0 +1,126 @@
1
+ import type { EnvironmentValue } from '../../types';
2
+ import type { ServicesValues } from '../../types/services.types';
3
+ export interface LambdaProps {
4
+ /**
5
+ * Lambda execution timeout.
6
+ *
7
+ * Specifies the maximum amount of time (in seconds) that the Lambda
8
+ * function is allowed to run before being terminated. If the execution
9
+ * exceeds this limit, the function will be stopped and an error will be raised.
10
+ */
11
+ timeout?: number;
12
+ /**
13
+ * Lambda memory allocation.
14
+ *
15
+ * Specifies the amount of memory (in MB) allocated to the Lambda function.
16
+ * Increasing memory also increases the CPU and network resources proportionally.
17
+ */
18
+ memory?: number;
19
+ /**
20
+ * Lambda NodeJS runtime
21
+ *
22
+ * Defines the Node.js runtime environment that the Lambda will use
23
+ * during execution. Only supported LTS versions are allowed to ensure
24
+ * long-term stability and AWS compatibility.
25
+ *
26
+ * Supported values:
27
+ * - `24` → Node.js 24
28
+ * - `22` → Node.js 22
29
+ * - `20` → Node.js 20
30
+ */
31
+ runtime?: 24 | 22 | 20;
32
+ /**
33
+ * Lambda services.
34
+ *
35
+ * Defines which AWS services the Lambda function is allowed to access.
36
+ * Internally, a role is created with the specified service permissions,
37
+ * granting the Lambda the ability to interact with those resources.
38
+ */
39
+ services?: ServicesValues;
40
+ /**
41
+ * Lambda environments.
42
+ *
43
+ * Defines environment values that will be applied specifically to
44
+ * this Lambda. These values override any global or stack-level
45
+ * environment configuration.
46
+ *
47
+ * Values can be provided in three formats:
48
+ * 1. `string` - The value will be taken from the `.env` file if present.
49
+ * 2. `Record<string, string | number | boolean | EnvFunction>` - Directly provides the value as a string.
50
+ * 3. `Record<string, EnvFunction>` - Functions can compute dynamic values based on resources
51
+ * created in the project, using the `getResourceValue` helper.
52
+ *
53
+ * @example
54
+ * // Load value from .env
55
+ * ["ENV_VALUE"]
56
+ *
57
+ * @example
58
+ * // Provide static values
59
+ * [
60
+ * { "ENV_VALUE": "static_string" },
61
+ * { "ENV_NUMBER": 123 }
62
+ * ]
63
+ *
64
+ * @example
65
+ * // Provide dynamic values from resources
66
+ * [
67
+ * {
68
+ * "ENV_VALUE": {
69
+ * name: "any",
70
+ * other: ({ getResourceValue }) => getResourceValue("s3_bucket", "arn")
71
+ * }
72
+ * }
73
+ * ]
74
+ */
75
+ env?: EnvironmentValue;
76
+ /**
77
+ * Lambda tags.
78
+ *
79
+ * Specifies a set of tags that will be applied to lambda function.
80
+ */
81
+ tags?: Record<string, string>;
82
+ /**
83
+ * Enables AWS X-Ray tracing for Lambda function.
84
+ *
85
+ * When set to `true`, X-Ray tracing is activated, allowing you to
86
+ * collect detailed information about requests, performance, and
87
+ * interactions with other AWS services.
88
+ *
89
+ * This is useful for debugging, monitoring, and gaining visibility
90
+ * into the execution flow of your Lambda.
91
+ */
92
+ enableTrace?: boolean;
93
+ }
94
+ export interface LambdaMetadata {
95
+ name: string;
96
+ lambda?: LambdaProps;
97
+ description?: string;
98
+ }
99
+ export declare enum LambdaReflectKeys {
100
+ handlers = "lambda:handlers",
101
+ arguments = "lambda:arguments",
102
+ event_param = "lambda:event_params"
103
+ }
104
+ export declare enum LambdaArgumentTypes {
105
+ event = "event",
106
+ callback = "callback",
107
+ context = "context"
108
+ }
109
+ export type CallbackParam = (error: boolean | null, response?: any) => void;
110
+ export type LambdaArguments = Record<string, LambdaArgumentTypes[]>;
111
+ export type LambdaArgumentsType = Record<LambdaArgumentTypes, ({ event, context, callback, }: {
112
+ event: any;
113
+ context: any;
114
+ methodName: string;
115
+ target: any;
116
+ callback: CallbackParam;
117
+ }) => any>;
118
+ export interface CreateLambdaDecoratorProps<T, M> {
119
+ getLambdaMetadata: (params: T, methodName: string) => M;
120
+ descriptorValue?: (descriptor: PropertyDescriptor) => any;
121
+ argumentParser?: Partial<LambdaArgumentsType | (string & {})>;
122
+ }
123
+ export interface CreateEventDecoratorProps {
124
+ prefix: string;
125
+ enableInLambdaInvocation?: boolean;
126
+ }
@@ -0,0 +1,15 @@
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["callback"] = "callback";
14
+ LambdaArgumentTypes["context"] = "context";
15
+ })(LambdaArgumentTypes || (exports.LambdaArgumentTypes = LambdaArgumentTypes = {}));
@@ -0,0 +1,2 @@
1
+ export * from './payload';
2
+ export * from './payload.types';
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './resource';
2
+ export * from './resource.types';
@@ -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,2 @@
1
+ import { type ResourceDecoratorProps, type ResourceProps } from './resource.types';
2
+ export declare const createResourceDecorator: <T extends ResourceProps>(decoratorProps: ResourceDecoratorProps<T>) => (props?: T) => (constructor: Function) => void;
@@ -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
@@ -0,0 +1,4 @@
1
+ export * from './constants/env.constants';
2
+ export * from './decorators';
3
+ export * from './types';
4
+ export * from './utils';
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,4 @@
1
+ import type { GetResourceProps } from './resource.types';
2
+ type EvnFunction = (props: GetResourceProps) => Record<string, string>;
3
+ export type EnvironmentValue = Record<string, string> | EvnFunction;
4
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export * from './env.types';
2
+ export * from './output.types';
3
+ export * from './override-resources.types';
4
+ export * from './resource.types';
5
+ export * from './services.types';
6
+ export * from './time.types';
7
+ export * from './utilities.types';
@@ -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);
@@ -0,0 +1,2 @@
1
+ export type OutputType = 'arn' | 'id';
2
+ export type GetResourceValue<T = string, V = OutputType> = (value: T, type: V) => any;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,35 @@
1
+ import type { ResourceIdentifiers, ScopedResourceNames } from './utilities.types';
2
+ export type ModuleGlobalReferenceNames = 'api' | 'auth' | 'bucket' | 'dynamo' | 'event-bus';
3
+ export interface ModulesAvailable {
4
+ }
5
+ export interface AuthAvailable {
6
+ }
7
+ export interface BucketAvailable {
8
+ }
9
+ export interface ApiRestAvailable {
10
+ }
11
+ export interface ApiAuthorizerAvailable {
12
+ }
13
+ export interface EventBusAvailable {
14
+ }
15
+ export interface DynamoTableAvailable {
16
+ }
17
+ type ResourceNames<T> = keyof T | (string & {});
18
+ type StackResourceName<T, S extends ModuleGlobalReferenceNames> = `${S}::${Extract<keyof T, string | number>}` | (string & {});
19
+ export type ModuleNames = ResourceNames<ModulesAvailable>;
20
+ export type AuthNames = ResourceNames<AuthAvailable>;
21
+ export type AuthScopedNames = StackResourceName<AuthAvailable, 'auth'>;
22
+ export type BucketNames = ResourceNames<BucketAvailable>;
23
+ export type BucketScopedNames = StackResourceName<ApiRestAvailable, 'bucket'>;
24
+ export type ApiRestNames = ResourceNames<ApiRestAvailable>;
25
+ export type ApiRestScopedNames = StackResourceName<ApiRestAvailable, 'api'>;
26
+ export type ApiAuthorizerNames = ResourceNames<ApiAuthorizerAvailable>;
27
+ export type EventBusNames = ResourceNames<EventBusAvailable>;
28
+ export type EventBusScopedNames = StackResourceName<ApiRestAvailable, 'event-bus'>;
29
+ export type DynamoTableNames = ResourceNames<DynamoTableAvailable>;
30
+ export type DynamoTableScopedNames = StackResourceName<DynamoTableAvailable, 'dynamo'>;
31
+ export type StateMachineNames = ResourceIdentifiers<ModulesAvailable, 'StateMachine'> | (string & {});
32
+ export type StateMachineScopedNames = ScopedResourceNames<ModulesAvailable, 'StateMachine'> | (string & {});
33
+ export type QueueNames = ResourceIdentifiers<ModulesAvailable, 'Queue'> | (string & {});
34
+ export type QueueScopedNames = ScopedResourceNames<ModulesAvailable, 'Queue'> | (string & {});
35
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import type { GetResourceValue } from './output.types';
2
+ import type { ApiRestScopedNames, AuthScopedNames, BucketScopedNames, DynamoTableScopedNames, EventBusScopedNames, QueueScopedNames, StateMachineScopedNames } from './override-resources.types';
3
+ export interface ClassResource {
4
+ new (...args: any[]): {};
5
+ }
6
+ export interface GetResourceProps {
7
+ getResourceValue: GetResourceValue<DynamoTableScopedNames | AuthScopedNames | BucketScopedNames | ApiRestScopedNames | EventBusScopedNames | StateMachineScopedNames | QueueScopedNames>;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ import type { GetResourceProps } from './resource.types';
2
+ export type ServicesName = 'dynamodb' | 's3' | 'lambda' | 'cloudwatch' | 'sqs' | 'state_machine' | 'kms' | 'ssm' | 'event';
3
+ interface PermissionService<T extends ServicesName | 'custom', P extends string> {
4
+ type: T;
5
+ permissions?: P[];
6
+ resources?: string[];
7
+ }
8
+ export type DynamoPermissions = 'Query' | 'Scan' | 'GetItem' | 'BatchGetItem' | 'PutItem' | 'DeleteItem' | 'UpdateItem' | 'ConditionCheckItem' | 'DescribeStream' | 'GetRecords' | 'GetShardIterator' | 'ListStreams';
9
+ export type S3Permissions = 'AbortMultipartUpload' | 'CreateBucket' | 'DeleteBucket' | 'DeleteObject' | 'DeleteObjectTagging' | 'DeleteObjectVersion' | 'DeleteObjectVersionTagging' | 'GetBucketTagging' | 'GetBucketVersioning' | 'GetObject' | 'GetObjectAttributes' | 'GetObjectTagging' | 'GetObjectVersion' | 'GetObjectVersionAttributes' | 'GetObjectVersionTagging' | 'ListAllMyBuckets' | 'ListBucket' | 'ListBucketMultipartUploads' | 'ListBucketVersions' | 'ListMultipartUploadParts' | 'PutObject' | 'PutObjectTagging' | 'PutObjectVersionTagging' | 'ReplicateDelete' | 'ReplicateObject' | 'ReplicateTags' | 'RestoreObject';
10
+ export type LambdaPermissions = 'InvokeFunction';
11
+ export type LogsPermission = 'CreateLogGroup' | 'CreateLogStream' | 'PutLogEvents';
12
+ export type SQSPermissions = 'DeleteMessage' | 'GetQueueUrl' | 'ReceiveMessage' | 'ReceiveMessage' | 'SendMessage' | 'GetQueueAttributes';
13
+ export type StateMachinePermissions = 'InvokeHTTPEndpoint' | 'DescribeExecution' | 'StartExecution' | 'StopExecution' | 'DescribeExecution' | 'GetExecutionHistory';
14
+ export type KMSPermissions = 'Decrypt' | 'DescribeKey' | 'Encrypt' | 'GenerateDataKey' | 'GenerateRandom' | 'GetPublicKey' | 'Sign' | 'Verify';
15
+ export type SSMPermissions = 'DescribeParameters' | 'GetDocument' | 'GetParameter' | 'GetParameters' | 'GetParametersByPath' | 'ListDocuments' | 'PutParameter';
16
+ export type EventPermissions = 'DescribeEventRule' | 'DescribeEventBus' | 'DescribeRule' | 'PutEvents' | 'PutRule';
17
+ export type Services = ServicesName | PermissionService<'dynamodb', DynamoPermissions> | PermissionService<'s3', S3Permissions> | PermissionService<'lambda', LambdaPermissions> | PermissionService<'cloudwatch', LogsPermission> | PermissionService<'sqs', SQSPermissions> | PermissionService<'state_machine', StateMachinePermissions> | PermissionService<'kms', KMSPermissions> | PermissionService<'ssm', SSMPermissions> | PermissionService<'event', EventPermissions> | (PermissionService<'custom', string> & {
18
+ serviceName: string;
19
+ });
20
+ export type ServiceFunction = (props: GetResourceProps) => Services[];
21
+ export type ServicesValues = Services[] | ServiceFunction;
22
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface Time {
2
+ type: 'days' | 'minutes' | 'seconds';
3
+ duration: number;
4
+ }
5
+ /**
6
+ * Time in seconds or Time object
7
+ */
8
+ export type Duration = number | Time;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,33 @@
1
+ export type KeyOfClass<E extends Function> = keyof E['prototype'];
2
+ export type DeepPartial<T> = T extends object ? {
3
+ [P in keyof T]?: DeepPartial<T[P]>;
4
+ } : T;
5
+ export type OnlyNumberString<T> = {
6
+ [key in keyof T as T[key] extends string | number ? key : never]: T[key];
7
+ };
8
+ export type OnlyNumber<T> = {
9
+ [key in keyof T as T[key] extends number ? key : never]: T[key];
10
+ };
11
+ export type Join<K, P> = K extends string ? P extends string ? `${K}::${P}` : never : never;
12
+ export type FlattenStacksByResource<TStacks, TResource extends string> = {
13
+ [StackName in keyof TStacks]: TResource extends keyof TStacks[StackName] ? Join<TResource, Join<StackName & string, keyof TStacks[StackName][TResource] & string>> : never;
14
+ }[keyof TStacks];
15
+ export type ResourceIdentifiers<TStacks, TResource extends string> = {
16
+ [K in keyof TStacks]: TResource extends keyof TStacks[K] ? keyof TStacks[K][TResource] : never;
17
+ }[keyof TStacks] & string;
18
+ export type ScopedResourceNames<TStacks, TResource extends string> = {
19
+ [StackName in keyof TStacks]: TResource extends keyof TStacks[StackName] ? Join<StackName & string, keyof TStacks[StackName][TResource] & string> : never;
20
+ }[keyof TStacks];
21
+ export type OnlyOne<T> = {
22
+ [K in keyof T]: Required<Pick<T, K>> & Partial<Record<Exclude<keyof T, K>, never>>;
23
+ }[keyof T];
24
+ export type OnlyOneKey<T> = {
25
+ [K in keyof T]: {
26
+ [P in K]: T[P];
27
+ } & {
28
+ [P in Exclude<keyof T, K>]?: never;
29
+ };
30
+ }[keyof T];
31
+ export type StripReadonly<T> = {
32
+ -readonly [P in keyof T]: StripReadonly<T[P]>;
33
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare const enableBuildEnvVariable: () => void;
2
+ export declare const isBuildEnvironment: () => boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBuildEnvironment = exports.enableBuildEnvVariable = void 0;
4
+ const env_constants_1 = require("../constants/env.constants");
5
+ const enableBuildEnvVariable = () => {
6
+ process.env[env_constants_1.LAFKEN_CONTEXT] = env_constants_1.LAFKEN_CONTEXT_VALUE;
7
+ };
8
+ exports.enableBuildEnvVariable = enableBuildEnvVariable;
9
+ const isBuildEnvironment = () => {
10
+ return process.env[env_constants_1.LAFKEN_CONTEXT] === env_constants_1.LAFKEN_CONTEXT_VALUE;
11
+ };
12
+ exports.isBuildEnvironment = isBuildEnvironment;
@@ -0,0 +1,4 @@
1
+ export * from './build-env.utils';
2
+ export * from './path.utils';
3
+ export * from './resource.utils';
4
+ export * from './string.utils';
@@ -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("./build-env.utils"), exports);
18
+ __exportStar(require("./path.utils"), exports);
19
+ __exportStar(require("./resource.utils"), exports);
20
+ __exportStar(require("./string.utils"), exports);
@@ -0,0 +1 @@
1
+ export declare const getCallerFileName: (fileIndex?: number) => string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCallerFileName = void 0;
4
+ const getStacks = () => {
5
+ const originalPrepareStackTrace = Error.prepareStackTrace;
6
+ Error.prepareStackTrace = (_, stack) => stack;
7
+ const err = new Error();
8
+ const stacks = err.stack;
9
+ Error.prepareStackTrace = originalPrepareStackTrace;
10
+ return stacks;
11
+ };
12
+ const getCallerFileName = (fileIndex = 5) => {
13
+ const stacks = getStacks();
14
+ return stacks[fileIndex].getFileName();
15
+ };
16
+ exports.getCallerFileName = getCallerFileName;
@@ -0,0 +1,6 @@
1
+ import { type LambdaMetadata, type ResourceMetadata } from '../decorators';
2
+ import type { ClassResource } from '../types';
3
+ export declare const getResourceMetadata: <T = ResourceMetadata>(classResource: ClassResource) => T;
4
+ export declare const getResourceHandlerMetadata: <T = LambdaMetadata>(classResource: ClassResource) => T[];
5
+ export declare const getMetadataByKey: <T>(classResource: ClassResource, key: string) => T;
6
+ export declare const getMetadataPrototypeByKey: <T>(classResource: ClassResource, key: string) => T;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMetadataPrototypeByKey = exports.getMetadataByKey = exports.getResourceHandlerMetadata = exports.getResourceMetadata = void 0;
4
+ const decorators_1 = require("../decorators");
5
+ const getResourceMetadata = (classResource) => {
6
+ return Reflect.getMetadata(decorators_1.ResourceReflectKeys.resource, classResource);
7
+ };
8
+ exports.getResourceMetadata = getResourceMetadata;
9
+ const getResourceHandlerMetadata = (classResource) => {
10
+ return Reflect.getMetadata(decorators_1.LambdaReflectKeys.handlers, classResource.prototype) || [];
11
+ };
12
+ exports.getResourceHandlerMetadata = getResourceHandlerMetadata;
13
+ const getMetadataByKey = (classResource, key) => {
14
+ return Reflect.getMetadata(key, classResource);
15
+ };
16
+ exports.getMetadataByKey = getMetadataByKey;
17
+ const getMetadataPrototypeByKey = (classResource, key) => {
18
+ return Reflect.getMetadata(key, classResource.prototype);
19
+ };
20
+ exports.getMetadataPrototypeByKey = getMetadataPrototypeByKey;
@@ -0,0 +1,4 @@
1
+ export declare const capitalize: (str: string) => string;
2
+ export declare const kebabCase: (str: string) => string;
3
+ export declare const cleanString: (str: string) => string;
4
+ export declare const cleanTemplateString: (str: string) => string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanTemplateString = exports.cleanString = exports.kebabCase = exports.capitalize = void 0;
4
+ const capitalize = (str) => {
5
+ return str.charAt(0).toUpperCase() + str.slice(1);
6
+ };
7
+ exports.capitalize = capitalize;
8
+ const kebabCase = (str) => {
9
+ if (str === str.toUpperCase()) {
10
+ return str.toLocaleLowerCase();
11
+ }
12
+ return str
13
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
14
+ .replace(/[\s_]+/g, '-')
15
+ .toLowerCase();
16
+ };
17
+ exports.kebabCase = kebabCase;
18
+ const cleanString = (str) => {
19
+ return str.replace(/[^a-zA-Z0-9]/g, '');
20
+ };
21
+ exports.cleanString = cleanString;
22
+ const cleanTemplateString = (str) => {
23
+ return str
24
+ .split('\n')
25
+ .map((s) => s.trim())
26
+ .filter(Boolean)
27
+ .join(' ');
28
+ };
29
+ exports.cleanTemplateString = cleanTemplateString;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@lafken/common",
3
+ "version": "0.6.0",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "files": [
9
+ "lib"
10
+ ],
11
+ "dependencies": {
12
+ "reflect-metadata": "0.2.2"
13
+ },
14
+ "devDependencies": {
15
+ "@types/jest": "30.0.0",
16
+ "jest": "30.2.0",
17
+ "ts-jest": "29.4.6",
18
+ "ts-node": "10.9.2"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "pnpm clean && tsc -p ./tsconfig.build.json",
25
+ "clean": "rm -rf ./lib",
26
+ "dev": "tsc -w",
27
+ "test": "jest",
28
+ "test:coverage": "jest --coverage"
29
+ }
30
+ }