@lafken/common 0.10.6 → 0.11.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/lib/decorators/resource/resource.js +1 -1
- package/lib/decorators/resource/resource.types.d.ts +2 -1
- package/lib/types/override-resources.types.d.ts +3 -2
- package/lib/types/resource.types.d.ts +3 -2
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/testing.utils.d.ts +8 -0
- package/lib/utils/testing.utils.js +28 -0
- package/package.json +1 -1
|
@@ -19,7 +19,7 @@ const createResourceDecorator = (decoratorProps) => (props) => (constructor) =>
|
|
|
19
19
|
foldername: (0, node_path_1.dirname)(callerFile),
|
|
20
20
|
filename: (0, node_path_1.basename)(callerFile).replace('.js', ''),
|
|
21
21
|
originalName: constructor.name,
|
|
22
|
-
minify: props?.minify
|
|
22
|
+
minify: props?.minify,
|
|
23
23
|
}, constructor);
|
|
24
24
|
};
|
|
25
25
|
exports.createResourceDecorator = createResourceDecorator;
|
|
@@ -18,11 +18,12 @@ export interface ResourceProps {
|
|
|
18
18
|
*/
|
|
19
19
|
minify?: boolean;
|
|
20
20
|
}
|
|
21
|
-
export interface ResourceMetadata extends Required<ResourceProps
|
|
21
|
+
export interface ResourceMetadata extends Required<Omit<ResourceProps, 'minify'>> {
|
|
22
22
|
type: string;
|
|
23
23
|
filename: string;
|
|
24
24
|
foldername: string;
|
|
25
25
|
originalName: string;
|
|
26
|
+
minify?: boolean;
|
|
26
27
|
}
|
|
27
28
|
export interface ResourceDecoratorProps<T> {
|
|
28
29
|
type: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResourceIdentifiers, ScopedResourceNames } from './utilities.types';
|
|
2
|
-
export type ModuleGlobalReferenceNames = 'api' | '
|
|
2
|
+
export type ModuleGlobalReferenceNames = 'api' | 'user-pool' | 'user-pool-client' | 'bucket' | 'dynamo' | 'event-bus';
|
|
3
3
|
export interface ModulesAvailable {
|
|
4
4
|
}
|
|
5
5
|
export interface AuthAvailable {
|
|
@@ -18,7 +18,8 @@ type ResourceNames<T> = keyof T | (string & {});
|
|
|
18
18
|
type StackResourceName<T, S extends ModuleGlobalReferenceNames> = `${S}::${Extract<keyof T, string | number>}` | (string & {});
|
|
19
19
|
export type ModuleNames = ResourceNames<ModulesAvailable>;
|
|
20
20
|
export type AuthNames = ResourceNames<AuthAvailable>;
|
|
21
|
-
export type
|
|
21
|
+
export type UserPoolScopedNames = StackResourceName<AuthAvailable, 'user-pool'>;
|
|
22
|
+
export type UserPoolClientScopedNames = StackResourceName<AuthAvailable, 'user-pool-client'>;
|
|
22
23
|
export type BucketNames = ResourceNames<BucketAvailable>;
|
|
23
24
|
export type BucketScopedNames = StackResourceName<BucketAvailable, 'bucket'>;
|
|
24
25
|
export type ApiRestNames = ResourceNames<ApiRestAvailable>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GetResourceValue } from './output.types';
|
|
2
|
-
import type { ApiRestScopedNames,
|
|
2
|
+
import type { ApiRestScopedNames, BucketScopedNames, DynamoTableScopedNames, EventBusScopedNames, QueueScopedNames, StateMachineScopedNames, UserPoolClientScopedNames, UserPoolScopedNames } from './override-resources.types';
|
|
3
3
|
export interface ClassResource {
|
|
4
4
|
new (...args: any[]): {};
|
|
5
5
|
}
|
|
@@ -272,7 +272,7 @@ export interface GetResourceProps {
|
|
|
272
272
|
* // Get a bucket ARN
|
|
273
273
|
* getResourceValue('bucket::uploads', 'arn')
|
|
274
274
|
*/
|
|
275
|
-
getResourceValue: GetResourceValue<DynamoTableScopedNames |
|
|
275
|
+
getResourceValue: GetResourceValue<DynamoTableScopedNames | UserPoolScopedNames | UserPoolClientScopedNames | BucketScopedNames | ApiRestScopedNames | EventBusScopedNames | StateMachineScopedNames | QueueScopedNames>;
|
|
276
276
|
/**
|
|
277
277
|
* Retrieves a value from AWS Systems Manager Parameter Store.
|
|
278
278
|
*
|
|
@@ -302,3 +302,4 @@ export interface GetResourceProps {
|
|
|
302
302
|
*/
|
|
303
303
|
token: TerraformToken;
|
|
304
304
|
}
|
|
305
|
+
export type GetExternalValues = Omit<GetResourceProps, 'getResourceValue'>;
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClassResource } from '../types';
|
|
2
|
+
type InstanceMethod<T extends ClassResource, M extends keyof InstanceType<T>> = InstanceType<T>[M] extends (...args: any[]) => any ? InstanceType<T>[M] : never;
|
|
3
|
+
interface ExecuteLambdaProps<T extends ClassResource, M extends keyof InstanceType<T>> {
|
|
4
|
+
method: M;
|
|
5
|
+
params?: Parameters<InstanceMethod<T, M>>;
|
|
6
|
+
}
|
|
7
|
+
export declare const executeLambda: <T extends ClassResource, M extends keyof InstanceType<T>>(classResource: T, props: ExecuteLambdaProps<T, M>) => Promise<Awaited<ReturnType<InstanceMethod<T, M>>>>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeLambda = void 0;
|
|
4
|
+
const decorators_1 = require("../decorators");
|
|
5
|
+
const build_env_utils_1 = require("./build-env.utils");
|
|
6
|
+
const executeLambda = async (classResource, props) => {
|
|
7
|
+
if (!(0, build_env_utils_1.isBuildEnvironment)()) {
|
|
8
|
+
throw new Error('executeLambda: Build environment is not enabled. ' +
|
|
9
|
+
'Call enableBuildEnvVariable() before defining decorated classes.');
|
|
10
|
+
}
|
|
11
|
+
const instance = new classResource();
|
|
12
|
+
const methodName = props.method;
|
|
13
|
+
const lambdaArguments = Reflect.getMetadata(decorators_1.LambdaReflectKeys.arguments, classResource.prototype) || {};
|
|
14
|
+
const argumentTypes = lambdaArguments[methodName] || [];
|
|
15
|
+
const params = props.params || [];
|
|
16
|
+
let event = {};
|
|
17
|
+
let context = {};
|
|
18
|
+
argumentTypes.forEach((type, index) => {
|
|
19
|
+
if (type === decorators_1.LambdaArgumentTypes.event) {
|
|
20
|
+
event = params[index] ?? {};
|
|
21
|
+
}
|
|
22
|
+
else if (type === decorators_1.LambdaArgumentTypes.context) {
|
|
23
|
+
context = params[index] ?? {};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return instance[methodName](event, context);
|
|
27
|
+
};
|
|
28
|
+
exports.executeLambda = executeLambda;
|
package/package.json
CHANGED