Skip to content

Commit

Permalink
feat(@whook/example): add Google Cloud Functions build
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Feb 27, 2024
1 parent 140c13d commit 4382e77
Show file tree
Hide file tree
Showing 13 changed files with 2,186 additions and 4,462 deletions.
6,365 changes: 1,905 additions & 4,460 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -151,6 +152,7 @@ DEV_MODE=1
"openapi-schema-validator": "^12.1.3",
"openapi-types": "^12.1.3",
"pkg-dir": "^8.0.0",
"js-yaml": "^4.1.0",
"strict-qs": "^8.0.2",
"type-fest": "^4.10.3",
"yerror": "^8.0.0",
Expand Down Expand Up @@ -478,6 +480,7 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -491,6 +494,7 @@ DEV_MODE=1
"openapi-schema-validator": "^12.1.3",
"openapi-types": "^12.1.3",
"pkg-dir": "^8.0.0",
"js-yaml": "^4.1.0",
"strict-qs": "^8.0.2",
"type-fest": "^4.10.3",
"yerror": "^8.0.0",
Expand Down Expand Up @@ -850,6 +854,7 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -863,6 +868,7 @@ DEV_MODE=1
"openapi-schema-validator": "^12.1.3",
"openapi-types": "^12.1.3",
"pkg-dir": "^8.0.0",
"js-yaml": "^4.1.0",
"strict-qs": "^8.0.2",
"type-fest": "^4.10.3",
"yerror": "^8.0.0",
Expand Down Expand Up @@ -1205,6 +1211,7 @@ DEV_MODE=1
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -1218,6 +1225,7 @@ DEV_MODE=1
"openapi-schema-validator": "^12.1.3",
"openapi-types": "^12.1.3",
"pkg-dir": "^8.0.0",
"js-yaml": "^4.1.0",
"strict-qs": "^8.0.2",
"type-fest": "^4.10.3",
"yerror": "^8.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe('initCreateWhook', () => {
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -168,6 +169,7 @@ describe('initCreateWhook', () => {
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"http-auth-utils": "^6.0.0",
"js-yaml": "^4.1.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
"openapi-schema-validator": "^12.1.3",
Expand Down Expand Up @@ -382,6 +384,7 @@ describe('initCreateWhook', () => {
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -390,6 +393,7 @@ describe('initCreateWhook', () => {
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"http-auth-utils": "^6.0.0",
"js-yaml": "^4.1.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
"openapi-schema-validator": "^12.1.3",
Expand Down Expand Up @@ -589,6 +593,7 @@ describe('initCreateWhook', () => {
"dependencies": {
"@whook/authorization": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "<current_version>",
"@whook/http-server": "<current_version>",
"@whook/http-transaction": "<current_version>",
Expand All @@ -597,6 +602,7 @@ describe('initCreateWhook', () => {
"application-services": "^6.0.0",
"common-services": "^16.0.1",
"http-auth-utils": "^6.0.0",
"js-yaml": "^4.1.0",
"jwt-service": "^10.0.4",
"knifecycle": "^17.0.1",
"openapi-schema-validator": "^12.1.3",
Expand Down
7 changes: 7 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ Debug `knifecycle` internals (dependency injection issues):
DEBUG=knifecycle npm run dev
```

## Testing the GCP Functions

```sh
JWT_SECRET=lol APP_ENV=local npx whook testHTTPFunction --name putEcho \
--parameters '{ "body": { "echo": "Hey!" } }'
```

[//]: # (::contents:end)

# Authors
Expand Down
2 changes: 2 additions & 0 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"dependencies": {
"@whook/authorization": "^15.0.0",
"@whook/cors": "^15.0.0",
"@whook/gcp-functions": "^15.0.0",
"@whook/http-router": "^15.0.0",
"@whook/http-server": "^15.0.0",
"@whook/http-transaction": "^15.0.0",
Expand All @@ -95,6 +96,7 @@
"openapi-schema-validator": "^12.1.3",
"openapi-types": "^12.1.3",
"pkg-dir": "^8.0.0",
"js-yaml": "^4.1.0",
"strict-qs": "^8.0.2",
"type-fest": "^4.10.3",
"yerror": "^8.0.0",
Expand Down
36 changes: 36 additions & 0 deletions packages/whook-example/src/build.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, test } from '@jest/globals';
import { exec } from 'child_process';

describe('build should work', () => {
[
['getPing', '{}'],
['getOpenAPI', '{}'],
[
'getParameters',
'{ "aHeader": "true", "pathParam1":"4", "pathParam2":"a,b,c,d" }',
],
['getTime', '{}'],
['getDelay', '{ "duration": 1 }'],
['putEcho', '{"body": { "echo": "YOLO!" }}'],
].forEach(([operationId, parameters]) => {
test(`with ${operationId} http lambdas`, async () => {
await execCommand(
`JWT_SECRET=test npx whook testHTTPFunction --name ${operationId} --parameters '${parameters}'`,
);
});
});
});

async function execCommand(
command,
): Promise<{ stdout: string; stderr: string }> {
return new Promise((resolve, reject) => {
exec(command, (err, stdout, stderr) => {
if (err) {
reject(err);
return;
}
resolve({ stdout, stderr });
});
});
}
4 changes: 3 additions & 1 deletion packages/whook-example/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { prepareEnvironment } from './index.js';
import {
DEFAULT_BUILD_INITIALIZER_PATH_MAP,
initBuildConstants,
} from '@whook/whook';
import {
runBuild as runBaseBuild,
prepareBuildEnvironment as prepareBaseBuildEnvironment,
} from '@whook/whook';
} from '@whook/gcp-functions';

/* Architecture Note #1.2: The build file
Expand Down
4 changes: 4 additions & 0 deletions packages/whook-example/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ describe('commands should work', () => {
- ls: Print available commands
# Provided by "@whook/gcp-functions": 1 commands
- testHTTPFunction: A command for testing GCP HTTP function
# Provided by "@whook/cors": none
Expand Down
8 changes: 8 additions & 0 deletions packages/whook-example/src/config/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ const CONFIG: Omit<AppConfig, 'HOST'> = {
CONFIG: {
name: _packageJSON.name,
description: _packageJSON.description || '',
baseURL: 'https://api.example.com',
},
DEBUG_NODE_ENVS: process.env.DEBUG ? Object.keys(NodeEnv) : DEBUG_NODE_ENVS,
COMPILER_OPTIONS: {
externalModules: ['portfinder', 'internal-ip'],
ignoredModules: ['ecstatic', 'swagger-ui-dist'],
excludeNodeModules: true,
},
BUILD_PARALLELISM: 10,
PROXYED_ENV_VARS: ['APP_ENV', 'NODE_ENV', 'JWT_SECRET'],
SERVICE_NAME_MAP: {},
ERRORS_DESCRIPTORS: {
...DEFAULT_ERRORS_DESCRIPTORS,
Expand Down
4 changes: 4 additions & 0 deletions packages/whook-example/src/config/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import COMMON_CONFIG from '../common/config.js';
import type { AppConfig } from 'application-services';

const CONFIG: AppConfig = {
BASE_ENV: {
...COMMON_CONFIG.BASE_ENV,
JWT_SECRET: 'yop',
},
...COMMON_CONFIG,
HOST: 'localhost',
};
Expand Down
Loading

0 comments on commit 4382e77

Please sign in to comment.