lift-extensions 0.1.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.
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "lift-extensions",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "files": [
6
+ "src"
7
+ ],
8
+ "exports": {
9
+ ".": "./src/plugin.mjs"
10
+ },
11
+ "dependencies": {
12
+ "defu": "^6.1.7",
13
+ "jiti": "^2.7.0",
14
+ "yaml": "^2.9.0"
15
+ },
16
+ "peerDependencies": {
17
+ "osls": "^3",
18
+ "serverless": "^3 || ^4",
19
+ "serverless-lift": "^1.36.0"
20
+ },
21
+ "peerDependenciesMeta": {
22
+ "osls": {
23
+ "optional": true
24
+ },
25
+ "serverless": {
26
+ "optional": true
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,66 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { createDefu } from 'defu';
3
+ import { parse } from 'yaml';
4
+ import type { Serverless } from '../types/serverless';
5
+
6
+ const MODULE_DEFINITION = {
7
+ type: 'object',
8
+ properties: {
9
+ type: { const: 'module' },
10
+ path: { type: 'string' },
11
+ overrides: { type: 'object' },
12
+ },
13
+ required: ['path'],
14
+ additionalProperties: false,
15
+ } as const;
16
+
17
+ const isRecord = (value: unknown): value is Record<string, unknown> => {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ };
20
+
21
+ const defu = createDefu((obj, key, value) => {
22
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
23
+ obj[key] = value;
24
+
25
+ return true;
26
+ }
27
+ });
28
+
29
+ export class Module {
30
+ public static type = 'module';
31
+ public static schema = MODULE_DEFINITION;
32
+
33
+ static initialize({ configurationInput: config }: Serverless) {
34
+ const constructs = config.constructs;
35
+
36
+ if (!isRecord(constructs)) {
37
+ return;
38
+ }
39
+
40
+ for (const [id, construct] of Object.entries(constructs)) {
41
+ if (!isRecord(construct) || construct.type !== this.type) {
42
+ continue;
43
+ }
44
+
45
+ const moduleConfig = parse(
46
+ readFileSync(String(construct.path), 'utf-8'),
47
+ );
48
+
49
+ if (!isRecord(moduleConfig)) {
50
+ continue;
51
+ }
52
+
53
+ const overrides = isRecord(construct.overrides)
54
+ ? construct.overrides
55
+ : {};
56
+
57
+ Object.assign(config, defu(overrides, config, moduleConfig));
58
+
59
+ delete constructs[id];
60
+ }
61
+ }
62
+
63
+ static create() {
64
+ return {};
65
+ }
66
+ }
@@ -0,0 +1 @@
1
+ export { Module } from './Module';
package/src/plugin.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { createJiti } from 'jiti';
2
+
3
+ const jiti = createJiti(import.meta.url);
4
+
5
+ export default jiti.import('./plugin.ts', { default: true });
package/src/plugin.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { AwsProvider } from 'serverless-lift/dist/src/providers/AwsProvider.js';
2
+ import { Module } from './constructs';
3
+ import type { Serverless } from './types/serverless';
4
+
5
+ export default class LiftExtensionsPlugin {
6
+ constructor(serverless: Serverless) {
7
+ AwsProvider.registerConstructs(Module);
8
+
9
+ for (const providerClass of AwsProvider.getAllConstructClasses()) {
10
+ providerClass.initialize?.(serverless);
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ export type Serverless = {
2
+ configurationInput: Record<string, unknown>;
3
+ };