@whook/gcp-functions 9.0.1 → 10.0.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/README.md +8 -9
- package/dist/commands/testHTTPFunction.d.ts +1 -1
- package/dist/commands/testHTTPFunction.js +119 -150
- package/dist/commands/testHTTPFunction.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +182 -269
- package/dist/index.js.map +1 -1
- package/dist/libs/utils.js +16 -35
- package/dist/libs/utils.js.map +1 -1
- package/dist/services/_autoload.d.ts +3 -3
- package/dist/services/_autoload.js +83 -109
- package/dist/services/_autoload.js.map +1 -1
- package/dist/services/log.js +2 -12
- package/dist/services/log.js.map +1 -1
- package/dist/services/log.test.js +4 -9
- package/dist/services/log.test.js.map +1 -1
- package/dist/wrappers/googleHTTPFunction.js +246 -294
- package/dist/wrappers/googleHTTPFunction.js.map +1 -1
- package/package.json +47 -89
- package/src/commands/testHTTPFunction.ts +6 -13
- package/src/index.ts +36 -54
- package/src/libs/utils.ts +3 -4
- package/src/services/_autoload.ts +4 -3
- package/src/services/log.test.ts +1 -1
- package/src/wrappers/googleHTTPFunction.ts +6 -6
- package/dist/commands/testHTTPFunction.mjs +0 -136
- package/dist/commands/testHTTPFunction.mjs.map +0 -1
- package/dist/index.mjs +0 -265
- package/dist/index.mjs.map +0 -1
- package/dist/libs/utils.mjs +0 -27
- package/dist/libs/utils.mjs.map +0 -1
- package/dist/services/_autoload.mjs +0 -113
- package/dist/services/_autoload.mjs.map +0 -1
- package/dist/services/log.mjs +0 -4
- package/dist/services/log.mjs.map +0 -1
- package/dist/services/log.test.mjs +0 -7
- package/dist/services/log.test.mjs.map +0 -1
- package/dist/wrappers/googleHTTPFunction.mjs +0 -290
- package/dist/wrappers/googleHTTPFunction.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whook/gcp-functions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Build and deploy to GCP Cloud Functions with Whook.",
|
|
5
|
-
"main": "dist/index",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
5
|
+
"main": "dist/index.js",
|
|
7
6
|
"types": "dist/index.d.ts",
|
|
8
7
|
"metapak": {
|
|
9
8
|
"configs": [
|
|
10
9
|
"main",
|
|
11
10
|
"readme",
|
|
11
|
+
"tsesm",
|
|
12
12
|
"eslint",
|
|
13
|
-
"babel",
|
|
14
13
|
"jest",
|
|
15
|
-
"jsdocs"
|
|
16
|
-
"typescript"
|
|
14
|
+
"jsdocs"
|
|
17
15
|
],
|
|
18
16
|
"data": {
|
|
19
17
|
"childPackage": true,
|
|
@@ -50,50 +48,42 @@
|
|
|
50
48
|
},
|
|
51
49
|
"homepage": "https://github.com/nfroidure/whook",
|
|
52
50
|
"dependencies": {
|
|
53
|
-
"@whook/cli": "^
|
|
54
|
-
"@whook/cors": "^
|
|
55
|
-
"@whook/http-router": "^
|
|
56
|
-
"@whook/whook": "^
|
|
51
|
+
"@whook/cli": "^10.0.0",
|
|
52
|
+
"@whook/cors": "^10.0.0",
|
|
53
|
+
"@whook/http-router": "^10.0.0",
|
|
54
|
+
"@whook/whook": "^10.0.0",
|
|
57
55
|
"ajv": "^8.11.0",
|
|
58
56
|
"ajv-formats": "^2.1.1",
|
|
59
|
-
"camelcase": "^
|
|
60
|
-
"common-services": "^
|
|
57
|
+
"camelcase": "^7.0.0",
|
|
58
|
+
"common-services": "^11.0.1",
|
|
61
59
|
"cpr": "3.0.1",
|
|
62
|
-
"knifecycle": "^
|
|
60
|
+
"knifecycle": "^14.0.0",
|
|
63
61
|
"mkdirp": "^1.0.4",
|
|
64
|
-
"openapi-types": "^
|
|
62
|
+
"openapi-types": "^12.0.0",
|
|
65
63
|
"qs": "^6.10.3",
|
|
66
|
-
"strict-qs": "^
|
|
67
|
-
"yerror": "^6.
|
|
64
|
+
"strict-qs": "^7.0.0",
|
|
65
|
+
"yerror": "^6.1.1"
|
|
68
66
|
},
|
|
69
67
|
"devDependencies": {
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"@babel/preset-env": "^7.18.2",
|
|
78
|
-
"@babel/preset-typescript": "^7.17.12",
|
|
79
|
-
"@babel/register": "^7.17.7",
|
|
80
|
-
"@types/jest": "^27.0.2",
|
|
81
|
-
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
82
|
-
"@typescript-eslint/parser": "^5.26.0",
|
|
83
|
-
"babel-plugin-knifecycle": "^5.0.3",
|
|
84
|
-
"eslint": "^8.16.0",
|
|
68
|
+
"@types/jest": "^28.1.1",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
|
70
|
+
"@typescript-eslint/parser": "^5.27.0",
|
|
71
|
+
"esbuild": "^0.14.46",
|
|
72
|
+
"esbuild-jest": "^0.5.0",
|
|
73
|
+
"eslint": "^8.17.0",
|
|
74
|
+
"eslint-config-prettier": "^8.5.0",
|
|
85
75
|
"eslint-plugin-prettier": "^4.0.0",
|
|
86
76
|
"jest": "^28.1.0",
|
|
87
77
|
"jsdoc-to-markdown": "^7.1.1",
|
|
88
78
|
"metapak": "^4.0.4",
|
|
89
|
-
"metapak-nfroidure": "
|
|
79
|
+
"metapak-nfroidure": "12.1.0",
|
|
90
80
|
"prettier": "^2.6.2",
|
|
91
81
|
"rimraf": "^3.0.2",
|
|
92
|
-
"typescript": "^4.7.
|
|
82
|
+
"typescript": "^4.7.3"
|
|
93
83
|
},
|
|
94
84
|
"contributors": [],
|
|
95
85
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
86
|
+
"node": ">=16.15.0"
|
|
97
87
|
},
|
|
98
88
|
"files": [
|
|
99
89
|
"dist",
|
|
@@ -105,12 +95,13 @@
|
|
|
105
95
|
"eslintConfig": {
|
|
106
96
|
"extends": [
|
|
107
97
|
"eslint:recommended",
|
|
98
|
+
"plugin:prettier/recommended",
|
|
108
99
|
"plugin:@typescript-eslint/eslint-recommended",
|
|
109
100
|
"plugin:@typescript-eslint/recommended"
|
|
110
101
|
],
|
|
111
102
|
"parserOptions": {
|
|
112
103
|
"ecmaVersion": 2018,
|
|
113
|
-
"sourceType": "
|
|
104
|
+
"sourceType": "script",
|
|
114
105
|
"modules": true
|
|
115
106
|
},
|
|
116
107
|
"env": {
|
|
@@ -137,53 +128,6 @@
|
|
|
137
128
|
"trailingComma": "all",
|
|
138
129
|
"proseWrap": "always"
|
|
139
130
|
},
|
|
140
|
-
"babel": {
|
|
141
|
-
"presets": [
|
|
142
|
-
"@babel/typescript",
|
|
143
|
-
[
|
|
144
|
-
"@babel/env",
|
|
145
|
-
{
|
|
146
|
-
"targets": {
|
|
147
|
-
"node": "12.19.0"
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
],
|
|
152
|
-
"plugins": [
|
|
153
|
-
"@babel/proposal-class-properties",
|
|
154
|
-
"@babel/plugin-proposal-object-rest-spread",
|
|
155
|
-
"babel-plugin-knifecycle"
|
|
156
|
-
],
|
|
157
|
-
"env": {
|
|
158
|
-
"cjs": {
|
|
159
|
-
"presets": [
|
|
160
|
-
[
|
|
161
|
-
"@babel/env",
|
|
162
|
-
{
|
|
163
|
-
"targets": {
|
|
164
|
-
"node": "10"
|
|
165
|
-
},
|
|
166
|
-
"modules": "commonjs"
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
]
|
|
170
|
-
},
|
|
171
|
-
"mjs": {
|
|
172
|
-
"presets": [
|
|
173
|
-
[
|
|
174
|
-
"@babel/env",
|
|
175
|
-
{
|
|
176
|
-
"targets": {
|
|
177
|
-
"node": "12"
|
|
178
|
-
},
|
|
179
|
-
"modules": false
|
|
180
|
-
}
|
|
181
|
-
]
|
|
182
|
-
]
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
"sourceMaps": true
|
|
186
|
-
},
|
|
187
131
|
"jest": {
|
|
188
132
|
"coverageReporters": [
|
|
189
133
|
"lcov",
|
|
@@ -194,22 +138,36 @@
|
|
|
194
138
|
],
|
|
195
139
|
"roots": [
|
|
196
140
|
"<rootDir>/src"
|
|
141
|
+
],
|
|
142
|
+
"testEnvironment": "node",
|
|
143
|
+
"transform": {
|
|
144
|
+
"^.+\\.tsx?$": [
|
|
145
|
+
"esbuild-jest",
|
|
146
|
+
{
|
|
147
|
+
"sourcemap": true,
|
|
148
|
+
"format": "esm"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
"moduleNameMapper": {
|
|
153
|
+
"(.+)\\.js": "$1"
|
|
154
|
+
},
|
|
155
|
+
"extensionsToTreatAsEsm": [
|
|
156
|
+
".ts"
|
|
197
157
|
]
|
|
198
158
|
},
|
|
199
159
|
"scripts": {
|
|
160
|
+
"build": "rimraf -f 'dist' && tsc --outDir dist",
|
|
200
161
|
"cli": "env NODE_ENV=${NODE_ENV:-cli}",
|
|
201
|
-
"compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
|
|
202
|
-
"compile:cjs": "babel --env-name=cjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
|
|
203
|
-
"compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --extensions '.ts,.js' --source-maps=true src",
|
|
204
162
|
"cover": "npm run jest -- --coverage",
|
|
205
163
|
"doc": "echo \"# API\" > API.md; jsdoc2md 'dist/**/*.js' >> API.md && git add API.md",
|
|
206
164
|
"genPackagelock": "npm i --package-lock-only",
|
|
207
|
-
"jest": "NODE_ENV=test jest",
|
|
165
|
+
"jest": "NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest",
|
|
208
166
|
"lint": "eslint 'src/**/*.ts'",
|
|
209
167
|
"metapak": "metapak",
|
|
210
168
|
"prettier": "prettier --write 'src/**/*.ts'",
|
|
211
|
-
"test": "npm run jest"
|
|
212
|
-
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist"
|
|
169
|
+
"test": "npm run jest"
|
|
213
170
|
},
|
|
214
|
-
"
|
|
171
|
+
"type": "module",
|
|
172
|
+
"gitHead": "5f8f3fc82c4a95176a5ce730b416bcee59316678"
|
|
215
173
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { loadLambda } from '../libs/utils';
|
|
1
|
+
import { loadLambda } from '../libs/utils.js';
|
|
2
2
|
import { extra, autoService } from 'knifecycle';
|
|
3
3
|
import { readArgs } from '@whook/cli';
|
|
4
|
-
import YError from 'yerror';
|
|
4
|
+
import { YError } from 'yerror';
|
|
5
5
|
import {
|
|
6
6
|
dereferenceOpenAPIOperations,
|
|
7
7
|
getOpenAPIOperations,
|
|
8
8
|
} from '@whook/http-router';
|
|
9
9
|
import stream from 'stream';
|
|
10
10
|
import camelCase from 'camelcase';
|
|
11
|
-
import type {
|
|
12
|
-
WhookCommandArgs,
|
|
13
|
-
WhookCommandDefinition,
|
|
14
|
-
WhookCommandNamedArgs,
|
|
15
|
-
} from '@whook/cli';
|
|
11
|
+
import type { WhookCommandArgs, WhookCommandDefinition } from '@whook/cli';
|
|
16
12
|
import type { LogService } from 'common-services';
|
|
17
13
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
18
14
|
|
|
@@ -68,16 +64,13 @@ async function initTestHTTPLambdaCommand({
|
|
|
68
64
|
}) {
|
|
69
65
|
return async () => {
|
|
70
66
|
const {
|
|
71
|
-
name,
|
|
72
|
-
|
|
73
|
-
contentType,
|
|
74
|
-
parameters: rawParameters,
|
|
75
|
-
}: WhookCommandNamedArgs = readArgs(definition.arguments, args) as {
|
|
67
|
+
namedArguments: { name, type, contentType, parameters: rawParameters },
|
|
68
|
+
} = readArgs<{
|
|
76
69
|
name: string;
|
|
77
70
|
type: string;
|
|
78
71
|
contentType: string;
|
|
79
72
|
parameters: string;
|
|
80
|
-
};
|
|
73
|
+
}>(definition.arguments, args);
|
|
81
74
|
const handler = await loadLambda(
|
|
82
75
|
{ PROJECT_DIR, log },
|
|
83
76
|
NODE_ENV,
|
package/src/index.ts
CHANGED
|
@@ -4,14 +4,16 @@ import util from 'util';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import mkdirp from 'mkdirp';
|
|
6
6
|
import cpr from 'cpr';
|
|
7
|
-
import YError from 'yerror';
|
|
8
|
-
import
|
|
7
|
+
import { YError } from 'yerror';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
import {
|
|
10
|
+
Knifecycle,
|
|
9
11
|
SPECIAL_PROPS,
|
|
10
12
|
constant,
|
|
11
13
|
initInitializerBuilder,
|
|
12
14
|
} from 'knifecycle';
|
|
13
|
-
import {
|
|
14
|
-
import initBuildAutoloader from './services/_autoload';
|
|
15
|
+
import { initCompiler } from '@whook/whook';
|
|
16
|
+
import initBuildAutoloader from './services/_autoload.js';
|
|
15
17
|
import {
|
|
16
18
|
dereferenceOpenAPIOperations,
|
|
17
19
|
getOpenAPIOperations,
|
|
@@ -25,7 +27,6 @@ import type {
|
|
|
25
27
|
} from 'knifecycle';
|
|
26
28
|
import type {
|
|
27
29
|
WhookOperation,
|
|
28
|
-
WhookCompilerConfig,
|
|
29
30
|
WhookCompilerOptions,
|
|
30
31
|
WhookCompilerService,
|
|
31
32
|
} from '@whook/whook';
|
|
@@ -61,6 +62,9 @@ const cprAsync = util.promisify(cpr) as (
|
|
|
61
62
|
options: CprOptions,
|
|
62
63
|
) => Promise<string[]>;
|
|
63
64
|
|
|
65
|
+
// TODO: Use import.meta when Jest will support it
|
|
66
|
+
const require = createRequire(path.join(process.cwd(), 'src', 'index.ts'));
|
|
67
|
+
|
|
64
68
|
const BUILD_DEFINITIONS: Record<
|
|
65
69
|
NonNullable<WhookAPIOperationGCPFunctionConfig['type']>,
|
|
66
70
|
{
|
|
@@ -73,7 +77,10 @@ const BUILD_DEFINITIONS: Record<
|
|
|
73
77
|
type: 'HTTP',
|
|
74
78
|
wrapper: {
|
|
75
79
|
name: 'wrapHandlerForGoogleHTTPFunction',
|
|
76
|
-
path: path.join(
|
|
80
|
+
path: path.join(
|
|
81
|
+
path.dirname(require.resolve('@whook/gcp-function')),
|
|
82
|
+
'wrappers/googleHTTPFunction.js',
|
|
83
|
+
),
|
|
77
84
|
},
|
|
78
85
|
suffix: 'Wrapped',
|
|
79
86
|
},
|
|
@@ -85,7 +92,7 @@ export async function prepareBuildEnvironment<T extends Knifecycle>(
|
|
|
85
92
|
$.register(
|
|
86
93
|
constant('INITIALIZER_PATH_MAP', {
|
|
87
94
|
ENV: '@whook/whook/dist/services/ProxyedENV',
|
|
88
|
-
log:
|
|
95
|
+
log: '@whook/gcp-functions/dist/services/log',
|
|
89
96
|
time: 'common-services/dist/time',
|
|
90
97
|
delay: 'common-services/dist/delay',
|
|
91
98
|
}),
|
|
@@ -108,26 +115,23 @@ export async function runBuild(
|
|
|
108
115
|
const {
|
|
109
116
|
NODE_ENV,
|
|
110
117
|
BUILD_PARALLELISM,
|
|
111
|
-
BUILD_OPTIONS,
|
|
112
118
|
PROJECT_DIR,
|
|
113
119
|
compiler,
|
|
114
120
|
log,
|
|
115
121
|
$autoload,
|
|
116
122
|
API,
|
|
117
123
|
buildInitializer,
|
|
118
|
-
}: WhookGCPBuildConfig &
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
} = await $.run([
|
|
124
|
+
}: WhookGCPBuildConfig & {
|
|
125
|
+
NODE_ENV: string;
|
|
126
|
+
PROJECT_DIR: string;
|
|
127
|
+
compiler: WhookCompilerService;
|
|
128
|
+
log: LogService;
|
|
129
|
+
$autoload: Autoloader<Initializer<Dependencies, Service>>;
|
|
130
|
+
API: OpenAPIV3.Document;
|
|
131
|
+
buildInitializer: BuildInitializer;
|
|
132
|
+
} = await $.run([
|
|
128
133
|
'NODE_ENV',
|
|
129
134
|
'?BUILD_PARALLELISM',
|
|
130
|
-
'?BUILD_OPTIONS',
|
|
131
135
|
'PROJECT_DIR',
|
|
132
136
|
'process',
|
|
133
137
|
'compiler',
|
|
@@ -161,7 +165,6 @@ export async function runBuild(
|
|
|
161
165
|
await processOperations(
|
|
162
166
|
{
|
|
163
167
|
NODE_ENV,
|
|
164
|
-
BUILD_OPTIONS: BUILD_OPTIONS || DEFAULT_BUILD_OPTIONS,
|
|
165
168
|
BUILD_PARALLELISM: BUILD_PARALLELISM || DEFAULT_BUILD_PARALLELISM,
|
|
166
169
|
PROJECT_DIR,
|
|
167
170
|
compiler,
|
|
@@ -187,15 +190,13 @@ async function processOperations(
|
|
|
187
190
|
{
|
|
188
191
|
NODE_ENV,
|
|
189
192
|
BUILD_PARALLELISM,
|
|
190
|
-
BUILD_OPTIONS,
|
|
191
193
|
PROJECT_DIR,
|
|
192
194
|
compiler,
|
|
193
195
|
log,
|
|
194
196
|
$autoload,
|
|
195
197
|
buildInitializer,
|
|
196
|
-
}:
|
|
198
|
+
}: WhookGCPBuildConfig & {
|
|
197
199
|
NODE_ENV: string;
|
|
198
|
-
BUILD_PARALLELISM: number;
|
|
199
200
|
PROJECT_DIR: string;
|
|
200
201
|
compiler: WhookCompilerService;
|
|
201
202
|
log: LogService;
|
|
@@ -212,7 +213,6 @@ async function processOperations(
|
|
|
212
213
|
{
|
|
213
214
|
NODE_ENV,
|
|
214
215
|
PROJECT_DIR,
|
|
215
|
-
BUILD_OPTIONS,
|
|
216
216
|
compiler,
|
|
217
217
|
log,
|
|
218
218
|
$autoload,
|
|
@@ -229,7 +229,6 @@ async function processOperations(
|
|
|
229
229
|
{
|
|
230
230
|
NODE_ENV,
|
|
231
231
|
BUILD_PARALLELISM,
|
|
232
|
-
BUILD_OPTIONS,
|
|
233
232
|
PROJECT_DIR,
|
|
234
233
|
compiler,
|
|
235
234
|
log,
|
|
@@ -246,12 +245,11 @@ async function buildAnyLambda(
|
|
|
246
245
|
{
|
|
247
246
|
NODE_ENV,
|
|
248
247
|
PROJECT_DIR,
|
|
249
|
-
BUILD_OPTIONS,
|
|
250
248
|
compiler,
|
|
251
249
|
log,
|
|
252
250
|
$autoload,
|
|
253
251
|
buildInitializer,
|
|
254
|
-
}:
|
|
252
|
+
}: {
|
|
255
253
|
NODE_ENV: string;
|
|
256
254
|
PROJECT_DIR: string;
|
|
257
255
|
compiler: WhookCompilerService;
|
|
@@ -264,8 +262,9 @@ async function buildAnyLambda(
|
|
|
264
262
|
const { operationId } = operation;
|
|
265
263
|
|
|
266
264
|
try {
|
|
267
|
-
const whookConfig: WhookAPIOperationGCPFunctionConfig =
|
|
268
|
-
|
|
265
|
+
const whookConfig: WhookAPIOperationGCPFunctionConfig = operation[
|
|
266
|
+
'x-whook'
|
|
267
|
+
] || { type: 'http' };
|
|
269
268
|
const operationType = whookConfig.type || 'http';
|
|
270
269
|
const sourceOperationId = whookConfig.sourceOperationId;
|
|
271
270
|
const entryPoint = operationId;
|
|
@@ -275,7 +274,7 @@ async function buildAnyLambda(
|
|
|
275
274
|
log('warning', `Building ${operationType} "${finalEntryPoint}"...`);
|
|
276
275
|
const buildDefinition = BUILD_DEFINITIONS[operationType];
|
|
277
276
|
// eslint-disable-next-line
|
|
278
|
-
const applyWrapper =
|
|
277
|
+
const applyWrapper = (await import(buildDefinition.wrapper.path)).default;
|
|
279
278
|
const rootNode = await $autoload(
|
|
280
279
|
entryPoint + (buildDefinition.suffix || ''),
|
|
281
280
|
);
|
|
@@ -293,16 +292,11 @@ async function buildAnyLambda(
|
|
|
293
292
|
? `OPERATION_API>OPERATION_API_${finalEntryPoint}`
|
|
294
293
|
: name,
|
|
295
294
|
),
|
|
296
|
-
BUILD_OPTIONS,
|
|
297
|
-
);
|
|
298
|
-
const indexContent = await buildLambdaIndex(
|
|
299
|
-
rootNode,
|
|
300
|
-
{
|
|
301
|
-
name: buildDefinition.wrapper.name,
|
|
302
|
-
path: buildDefinition.wrapper.path,
|
|
303
|
-
},
|
|
304
|
-
BUILD_OPTIONS,
|
|
305
295
|
);
|
|
296
|
+
const indexContent = await buildLambdaIndex(rootNode, {
|
|
297
|
+
name: buildDefinition.wrapper.name,
|
|
298
|
+
path: buildDefinition.wrapper.path,
|
|
299
|
+
});
|
|
306
300
|
|
|
307
301
|
await mkdirp(lambdaPath);
|
|
308
302
|
await Promise.all([
|
|
@@ -330,18 +324,10 @@ async function buildAnyLambda(
|
|
|
330
324
|
async function buildLambdaIndex(
|
|
331
325
|
rootNode: { path: string },
|
|
332
326
|
buildWrapper: { name: string; path: string },
|
|
333
|
-
options: NonNullable<WhookCompilerConfig['BUILD_OPTIONS']>,
|
|
334
327
|
): Promise<string> {
|
|
335
|
-
return
|
|
336
|
-
options.modules === 'commonjs'
|
|
337
|
-
? `const pickModule = (m) => { return m && m.default || m; }
|
|
338
|
-
const initHandler = pickModule(require('${rootNode.path}'));
|
|
339
|
-
const ${buildWrapper.name} = pickModule(require('${buildWrapper.path}'));
|
|
340
|
-
const { initialize } = require('./initialize');`
|
|
341
|
-
: `import initHandler from '${rootNode.path}';
|
|
328
|
+
return `import initHandler from '${rootNode.path}';
|
|
342
329
|
import ${buildWrapper.name} from '${buildWrapper.path}';
|
|
343
|
-
import { initialize } from './initialize'
|
|
344
|
-
}
|
|
330
|
+
import { initialize } from './initialize.js';
|
|
345
331
|
|
|
346
332
|
const handlerInitializer = ${buildWrapper.name}(
|
|
347
333
|
initHandler
|
|
@@ -350,11 +336,7 @@ const handlerInitializer = ${buildWrapper.name}(
|
|
|
350
336
|
const handlerPromise = initialize()
|
|
351
337
|
.then(handlerInitializer);
|
|
352
338
|
|
|
353
|
-
|
|
354
|
-
options.modules === 'commonjs'
|
|
355
|
-
? 'module.exports = {}; module.exports.default = '
|
|
356
|
-
: 'export default '
|
|
357
|
-
}function handler (req, res) {
|
|
339
|
+
export default function handler (req, res) {
|
|
358
340
|
return handlerPromise
|
|
359
341
|
.then(handler => handler(req, res));
|
|
360
342
|
};
|
package/src/libs/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import YError from 'yerror';
|
|
1
|
+
import { YError } from 'yerror';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import type { LogService } from 'common-services';
|
|
4
4
|
|
|
@@ -19,14 +19,13 @@ export async function loadLambda(
|
|
|
19
19
|
'builds',
|
|
20
20
|
target,
|
|
21
21
|
operationId,
|
|
22
|
-
type,
|
|
22
|
+
type + '.js',
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
log('debug', `⛏️ - Loading lambda module at path "${modulePath}".`);
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
|
-
|
|
29
|
-
const module = require(modulePath);
|
|
28
|
+
const module = await import(modulePath);
|
|
30
29
|
|
|
31
30
|
if (!module) {
|
|
32
31
|
throw new YError('E_MODULE_NOT_FOUND', module);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { initAutoload, noop, cleanupOpenAPI } from '@whook/whook';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
Knifecycle,
|
|
3
4
|
SPECIAL_PROPS,
|
|
4
5
|
wrapInitializer,
|
|
5
6
|
constant,
|
|
6
7
|
alsoInject,
|
|
7
8
|
} from 'knifecycle';
|
|
8
|
-
import YError from 'yerror';
|
|
9
|
+
import { YError } from 'yerror';
|
|
9
10
|
import {
|
|
10
11
|
dereferenceOpenAPIOperations,
|
|
11
12
|
getOpenAPIOperations,
|
|
@@ -22,7 +23,7 @@ import type { WhookBuildConstantsService } from '@whook/whook';
|
|
|
22
23
|
import type { WhookRawOperation } from '@whook/http-router';
|
|
23
24
|
import type { LogService } from 'common-services';
|
|
24
25
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
25
|
-
import type { WhookAPIOperationGCPFunctionConfig } from '
|
|
26
|
+
import type { WhookAPIOperationGCPFunctionConfig } from '../index.js';
|
|
26
27
|
|
|
27
28
|
const initializerWrapper: ServiceInitializerWrapper<
|
|
28
29
|
Autoloader<Initializer<Dependencies, Service>>,
|
package/src/services/log.test.ts
CHANGED
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
castParameters,
|
|
10
10
|
} from '@whook/http-router';
|
|
11
11
|
import { reuseSpecialProps, alsoInject } from 'knifecycle';
|
|
12
|
-
import Ajv from 'ajv';
|
|
13
|
-
import addAJVFormats from 'ajv-formats';
|
|
12
|
+
import { default as Ajv } from 'ajv';
|
|
13
|
+
import { default as addAJVFormats } from 'ajv-formats';
|
|
14
14
|
import bytes from 'bytes';
|
|
15
|
-
import
|
|
15
|
+
import { YHTTPError } from 'yhttperror';
|
|
16
16
|
import {
|
|
17
17
|
prepareParametersValidators,
|
|
18
18
|
prepareBodyValidator,
|
|
@@ -328,7 +328,7 @@ async function handleForAWSHTTPFunction(
|
|
|
328
328
|
...('undefined' !== typeof body ? { body } : {}),
|
|
329
329
|
};
|
|
330
330
|
} catch (err) {
|
|
331
|
-
throw
|
|
331
|
+
throw YHTTPError.cast(err as Error, 400);
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
response = await executeHandler(operation, handler, parameters);
|
|
@@ -354,7 +354,7 @@ async function handleForAWSHTTPFunction(
|
|
|
354
354
|
(responseSchema.type !== 'string' || responseSchema.format !== 'binary');
|
|
355
355
|
|
|
356
356
|
if (responseHasSchema && !STRINGIFYERS[response.headers['content-type']]) {
|
|
357
|
-
throw new
|
|
357
|
+
throw new YHTTPError(
|
|
358
358
|
500,
|
|
359
359
|
'E_STRINGIFYER_LACK',
|
|
360
360
|
response.headers['content-type'],
|
|
@@ -370,7 +370,7 @@ async function handleForAWSHTTPFunction(
|
|
|
370
370
|
};
|
|
371
371
|
log?.('debug', JSON.stringify(responseLog));
|
|
372
372
|
} catch (err) {
|
|
373
|
-
const castedError =
|
|
373
|
+
const castedError = YHTTPError.cast(err as Error);
|
|
374
374
|
|
|
375
375
|
responseLog = {
|
|
376
376
|
type: 'error',
|