@lafken/common 0.10.5 → 0.11.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.
@@ -29,7 +29,7 @@ const createLambdaDecorator = ({ getLambdaMetadata, descriptorValue, argumentPar
29
29
  ...argumentsByType,
30
30
  ...argumentParser,
31
31
  };
32
- descriptor.value = async (event, context) => {
32
+ descriptor.value = async function (event, context) {
33
33
  const methodArguments = (lambdaArguments?.[methodName] || []).map((argumentType) => mapArgumentMethod[argumentType]({ event, context, methodName, target }));
34
34
  const response = await originalValue.apply(this, methodArguments);
35
35
  return response;
@@ -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 ?? true,
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' | 'auth' | 'bucket' | 'dynamo' | 'event-bus';
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 AuthScopedNames = StackResourceName<AuthAvailable, 'auth'>;
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, AuthScopedNames, BucketScopedNames, DynamoTableScopedNames, EventBusScopedNames, QueueScopedNames, StateMachineScopedNames } from './override-resources.types';
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 | AuthScopedNames | BucketScopedNames | ApiRestScopedNames | EventBusScopedNames | StateMachineScopedNames | QueueScopedNames>;
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'>;
@@ -2,3 +2,4 @@ export * from './build-env.utils';
2
2
  export * from './path.utils';
3
3
  export * from './resource.utils';
4
4
  export * from './string.utils';
5
+ export * from './testing.utils';
@@ -18,3 +18,4 @@ __exportStar(require("./build-env.utils"), exports);
18
18
  __exportStar(require("./path.utils"), exports);
19
19
  __exportStar(require("./resource.utils"), exports);
20
20
  __exportStar(require("./string.utils"), exports);
21
+ __exportStar(require("./testing.utils"), exports);
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lafken/common",
3
- "version": "0.10.5",
3
+ "version": "0.11.0",
4
4
  "private": false,
5
5
  "description": "Lafken utilities - TypeScript decorator factories and metadata reflection for infrastructure-as-code decorators",
6
6
  "keywords": [