@bifravst/aws-cdk-lambda-helpers 1.2.4 → 1.2.6
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/README.md +9 -1
- package/dist/src/module-folder-named-like-handler-bug.spec.js +6 -2
- package/dist/src/packLambda.js +10 -3
- package/dist/src/test-data/module-folder-named-like-handler-bug/different-level/lambda/acme.js +2 -0
- package/dist/src/test-data/module-folder-named-like-handler-bug/same-level/acme/lib.d.ts +1 -0
- package/dist/src/test-data/module-folder-named-like-handler-bug/same-level/acme/lib.js +1 -0
- package/dist/src/test-data/module-folder-named-like-handler-bug/same-level/acme.d.ts +1 -0
- package/package.json +2 -2
- package/dist/cdk/TestApp.d.ts +0 -5
- package/dist/cdk/TestApp.js +0 -12
- package/dist/cdk/TestStack.d.ts +0 -12
- package/dist/cdk/TestStack.js +0 -39
- package/dist/cdk/baseLayer.d.ts +0 -2
- package/dist/cdk/baseLayer.js +0 -5
- package/dist/cdk/e2e.d.ts +0 -1
- package/dist/cdk/e2e.js +0 -11
- package/dist/cdk/lambda.d.ts +0 -2
- package/dist/cdk/lambda.js +0 -5
- package/dist/cdk/packTestLambdas.d.ts +0 -5
- package/dist/cdk/packTestLambdas.js +0 -4
- package/dist/e2e.spec.d.ts +0 -1
- package/dist/e2e.spec.js +0 -17
- package/dist/lambdas/test.zip +0 -0
- package/dist/layers/baseLayer/nodejs/node_modules/.package-lock.json +0 -16
- package/dist/layers/baseLayer/nodejs/node_modules/id128/CHANGES +0 -20
- package/dist/layers/baseLayer/nodejs/node_modules/id128/LICENSE +0 -18
- package/dist/layers/baseLayer/nodejs/node_modules/id128/README.md +0 -853
- package/dist/layers/baseLayer/nodejs/node_modules/id128/index.d.ts +0 -167
- package/dist/layers/baseLayer/nodejs/node_modules/id128/index.js +0 -49
- package/dist/layers/baseLayer/nodejs/node_modules/id128/package.json +0 -68
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/base.js +0 -53
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/crockford32.js +0 -114
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/hex.js +0 -63
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/coder/uuid.js +0 -77
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/byte-array.js +0 -26
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/epoch-converter.js +0 -32
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/exception.js +0 -18
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/fake-machine.js +0 -26
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/machine.js +0 -37
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/random-bytes-browser.js +0 -9
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/common/random-bytes.js +0 -17
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/factory/id.js +0 -96
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/factory/versioned-id.js +0 -72
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/base.js +0 -39
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/ulid-monotonic.js +0 -71
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/ulid.js +0 -64
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-1.js +0 -149
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-4.js +0 -24
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-6.js +0 -146
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid-nil.js +0 -33
- package/dist/layers/baseLayer/nodejs/node_modules/id128/src/id/uuid.js +0 -58
- package/dist/layers/baseLayer/nodejs/node_modules/id128/utils.js +0 -35
- package/dist/layers/baseLayer/nodejs/package-lock.json +0 -6671
- package/dist/layers/baseLayer/nodejs/package.json +0 -1
- package/dist/layers/baseLayer.zip +0 -0
- /package/dist/src/test-data/module-folder-named-like-handler-bug/{acme → different-level/acme}/lib.d.ts +0 -0
- /package/dist/src/test-data/module-folder-named-like-handler-bug/{acme → different-level/acme}/lib.js +0 -0
- /package/dist/src/test-data/module-folder-named-like-handler-bug/{acme.d.ts → different-level/lambda/acme.d.ts} +0 -0
- /package/dist/src/test-data/module-folder-named-like-handler-bug/{acme.js → same-level/acme.js} +0 -0
package/README.md
CHANGED
@@ -11,4 +11,12 @@ Helper functions which simplify working with TypeScript lambdas for AWS CDK.
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
npm i --save --save-exact @bifravst/aws-cdk-lambda-helpers
|
14
|
+
npm i --save-dev --save-exact @bifravst/aws-cdk-lambda-helpers
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
See [the end-to-end test stack](./cdk/e2e.ts).
|
19
|
+
|
20
|
+
## Example migrations to `@bifravst/aws-cdk-lambda-helpers`
|
21
|
+
|
22
|
+
- [world.thingy.rocks backend](https://github.com/NordicPlayground/thingy-rocks-cloud-aws-js/commit/3ca6e267917db4d8cb09ca63ed54384c0e23f163)
|
@@ -8,8 +8,12 @@ import os from 'node:os';
|
|
8
8
|
const tmpDir = os.tmpdir();
|
9
9
|
void describe('packLambda()', () => {
|
10
10
|
// See https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93#issuecomment-2042201321
|
11
|
-
void it('should fail if it imports from a folder that has the same name as the handler module', async () => assert.rejects(async () => packLambda({
|
12
|
-
sourceFile: path.join(dirname(fileURLToPath(import.meta.url)), 'test-data', 'module-folder-named-like-handler-bug', 'acme.ts'),
|
11
|
+
void it('should fail if it imports from a folder on the same level that has the same name as the handler module', async () => assert.rejects(async () => packLambda({
|
12
|
+
sourceFile: path.join(dirname(fileURLToPath(import.meta.url)), 'test-data', 'module-folder-named-like-handler-bug', 'same-level', 'acme.ts'),
|
13
13
|
zipFile: path.join(await fs.mkdtemp(`${tmpDir}${path.sep}`), 'acme.zip'),
|
14
14
|
}), ImportFromFolderNameError));
|
15
|
+
void it('should not fail if it a folder with the same name is on a different level', async () => assert.doesNotReject(async () => packLambda({
|
16
|
+
sourceFile: path.join(dirname(fileURLToPath(import.meta.url)), 'test-data', 'module-folder-named-like-handler-bug', 'different-level', 'lambda', 'acme.ts'),
|
17
|
+
zipFile: path.join(await fs.mkdtemp(`${tmpDir}${path.sep}`), 'acme.zip'),
|
18
|
+
})));
|
15
19
|
});
|
package/dist/src/packLambda.js
CHANGED
@@ -27,11 +27,18 @@ export const packLambda = async ({ sourceFile, zipFile, debug, progress, }) => {
|
|
27
27
|
const zipfile = new yazl.ZipFile();
|
28
28
|
const stripCommon = removeCommonAncestor(commonParent(lambdaFiles));
|
29
29
|
const handler = stripCommon(sourceFile);
|
30
|
-
|
31
|
-
const
|
32
|
-
|
30
|
+
// Make sure that the handler does not import from a folder with the same name in the folder
|
31
|
+
const handlerInfo = path.parse(handler);
|
32
|
+
const handlerName = handlerInfo.name;
|
33
|
+
const handlerDir = handlerInfo.dir;
|
34
|
+
const handlerDepsFromSameDirectory = deps
|
35
|
+
.map(stripCommon)
|
36
|
+
.filter((d) => handlerDir === '' ? true : d.startsWith(`${handlerDir}${path.sep}`));
|
37
|
+
const handlerDepsFolderNames = new Set(handlerDepsFromSameDirectory.map((s) => s.split('/')[0]));
|
38
|
+
if (handlerDepsFolderNames.has(handlerName)) {
|
33
39
|
throw new ImportFromFolderNameError(handlerName);
|
34
40
|
}
|
41
|
+
// Compile files
|
35
42
|
for (const file of lambdaFiles) {
|
36
43
|
const compiled = (await swc.transformFile(file, {
|
37
44
|
jsc: {
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const hello: () => string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export const hello = () => 'Hello World!';
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const handler: () => string;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bifravst/aws-cdk-lambda-helpers",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.6",
|
4
4
|
"description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
@@ -105,7 +105,7 @@
|
|
105
105
|
},
|
106
106
|
"files": [
|
107
107
|
"package-lock.json",
|
108
|
-
"dist",
|
108
|
+
"dist/src",
|
109
109
|
"LICENSE",
|
110
110
|
"README.md"
|
111
111
|
],
|
package/dist/cdk/TestApp.d.ts
DELETED
package/dist/cdk/TestApp.js
DELETED
package/dist/cdk/TestStack.d.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { App, Stack } from 'aws-cdk-lib';
|
2
|
-
import type { PackedLayer } from '../src/layer.js';
|
3
|
-
import type { TestLambdas } from './packTestLambdas.js';
|
4
|
-
export declare class TestStack extends Stack {
|
5
|
-
constructor(parent: App, id: string, { lambdaSources, layer, }: {
|
6
|
-
lambdaSources: TestLambdas;
|
7
|
-
layer: PackedLayer;
|
8
|
-
});
|
9
|
-
}
|
10
|
-
export type StackOutputs = {
|
11
|
-
lambdaURL: string;
|
12
|
-
};
|
package/dist/cdk/TestStack.js
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
import { App, CfnOutput, Duration, aws_lambda as Lambda, Stack, } from 'aws-cdk-lib';
|
2
|
-
import { LambdaLogGroup, LambdaSource } from '../src/cdk.js';
|
3
|
-
export class TestStack extends Stack {
|
4
|
-
constructor(parent, id, { lambdaSources, layer, }) {
|
5
|
-
super(parent, id, {});
|
6
|
-
const baseLayer = new Lambda.LayerVersion(this, 'baseLayer', {
|
7
|
-
layerVersionName: `${Stack.of(this).stackName}-baseLayer`,
|
8
|
-
code: new LambdaSource(this, {
|
9
|
-
id: 'baseLayer',
|
10
|
-
zipFile: layer.layerZipFile,
|
11
|
-
hash: layer.hash,
|
12
|
-
}).code,
|
13
|
-
compatibleArchitectures: [Lambda.Architecture.ARM_64],
|
14
|
-
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
|
15
|
-
});
|
16
|
-
const fn = new Lambda.Function(this, 'fn', {
|
17
|
-
handler: lambdaSources.test.handler,
|
18
|
-
architecture: Lambda.Architecture.ARM_64,
|
19
|
-
runtime: Lambda.Runtime.NODEJS_20_X,
|
20
|
-
timeout: Duration.seconds(1),
|
21
|
-
memorySize: 1792,
|
22
|
-
code: new LambdaSource(this, lambdaSources.test).code,
|
23
|
-
description: 'Returns a ULID',
|
24
|
-
environment: {
|
25
|
-
NODE_NO_WARNINGS: '1',
|
26
|
-
},
|
27
|
-
layers: [baseLayer],
|
28
|
-
...new LambdaLogGroup(this, 'fnLogs'),
|
29
|
-
});
|
30
|
-
const url = fn.addFunctionUrl({
|
31
|
-
authType: Lambda.FunctionUrlAuthType.NONE,
|
32
|
-
});
|
33
|
-
new CfnOutput(this, 'lambdaURL', {
|
34
|
-
exportName: `${this.stackName}:lambdaURL`,
|
35
|
-
description: 'API endpoint',
|
36
|
-
value: url.url,
|
37
|
-
});
|
38
|
-
}
|
39
|
-
}
|
package/dist/cdk/baseLayer.d.ts
DELETED
package/dist/cdk/baseLayer.js
DELETED
package/dist/cdk/e2e.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/cdk/e2e.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import { TestApp } from './TestApp.js';
|
2
|
-
import { pack as packBaseLayer } from './baseLayer.js';
|
3
|
-
import { packTestLambdas } from './packTestLambdas.js';
|
4
|
-
import { fromEnv } from '@nordicsemiconductor/from-env';
|
5
|
-
const { stackName } = fromEnv({
|
6
|
-
stackName: 'STACK_NAME',
|
7
|
-
})(process.env);
|
8
|
-
new TestApp(stackName, {
|
9
|
-
lambdaSources: await packTestLambdas(),
|
10
|
-
layer: await packBaseLayer(),
|
11
|
-
});
|
package/dist/cdk/lambda.d.ts
DELETED
package/dist/cdk/lambda.js
DELETED
package/dist/e2e.spec.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/e2e.spec.js
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
import { describe, it } from 'node:test';
|
2
|
-
import assert from 'node:assert/strict';
|
3
|
-
import { stackOutput } from '@nordicsemiconductor/cloudformation-helpers';
|
4
|
-
import { CloudFormationClient } from '@aws-sdk/client-cloudformation';
|
5
|
-
import { fromEnv } from '@nordicsemiconductor/from-env';
|
6
|
-
void describe('end-to-end tests', () => {
|
7
|
-
void it('should return an ULID', async () => {
|
8
|
-
const { stackName } = fromEnv({
|
9
|
-
stackName: 'STACK_NAME',
|
10
|
-
})(process.env);
|
11
|
-
const { lambdaURL } = await stackOutput(new CloudFormationClient({}))(stackName);
|
12
|
-
const res = await fetch(new URL(lambdaURL));
|
13
|
-
assert.equal(res.ok, true);
|
14
|
-
assert.equal(res.status, 201);
|
15
|
-
assert.match(await res.text(), /^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/);
|
16
|
-
});
|
17
|
-
});
|
package/dist/lambdas/test.zip
DELETED
Binary file
|
@@ -1,16 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "@bifravst/aws-cdk-lambda-helpers",
|
3
|
-
"version": "0.0.0-development",
|
4
|
-
"lockfileVersion": 3,
|
5
|
-
"requires": true,
|
6
|
-
"packages": {
|
7
|
-
"node_modules/id128": {
|
8
|
-
"version": "1.6.6",
|
9
|
-
"resolved": "https://registry.npmjs.org/id128/-/id128-1.6.6.tgz",
|
10
|
-
"integrity": "sha512-ExSXL9qcyQ7X/AfyO4ouARLnztm7Nmry1rwGi1nbrtSM90tjjqKzeMKqJfkw5bDdDX7XqdXIRzYYkVj5PU28Hg==",
|
11
|
-
"engines": {
|
12
|
-
"node": ">=v6.9.0"
|
13
|
-
}
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
- 0.1.0 : Move extraneous exports from index.js into utils.js.
|
2
|
-
- 0.2.0 : Add browser support for Browserify/Webpack.
|
3
|
-
- 0.3.0 : Pass named arguments to .generate instead of positional.
|
4
|
-
- 1.0.0 : Added support for Uuid V1 and extracted competitive benchmarks.
|
5
|
-
- 1.0.1 : Remove lockfile from release.
|
6
|
-
- 1.0.2 : Fix bad version push.
|
7
|
-
- 1.0.3 : Delete the extra benchmarks for real.
|
8
|
-
- 1.1.0 : Performance improvements and renamed resetClockSequence to reset.
|
9
|
-
- 1.1.1 : Fixed repo link.
|
10
|
-
- 1.2.0 : Added generic UUID factory.
|
11
|
-
- 1.3.0 : Added UUID V6 support.
|
12
|
-
- 1.4.0 : Exposed encoding verifiers.
|
13
|
-
- 1.5.0 : Fixed benchmarks and added support for node +12.5.
|
14
|
-
- 1.6.0 : Added Typescript support and top-level id comparators.
|
15
|
-
- 1.6.1 : Tweaked random memory allocation and updated benchmarks.
|
16
|
-
- 1.6.2 : Fixed docs
|
17
|
-
- 1.6.3 : Fixed memory profile by reusing the buffer of random.
|
18
|
-
- 1.6.4 : Fixed worker support
|
19
|
-
- 1.6.5 : Removed erroneous packaged files
|
20
|
-
- 1.6.6 : Fix CHANGES and add credit for worker support
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Copyright 2018 Aaron Cohen <aarondcohen@gmail.com>
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
-
this software and associated documentation files (the "Software"), to deal in
|
5
|
-
the Software without restriction, including without limitation the rights to
|
6
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
-
subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
11
|
-
copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|