@cedarjs/api-server 9.0.0-canary.1784 → 9.0.0-canary.3124
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 +0 -1
- package/dist/apiCLIConfig.d.ts.map +1 -1
- package/dist/apiCLIConfig.js +1 -1
- package/dist/apiCLIConfigHandler.d.ts.map +1 -1
- package/dist/apiCLIConfigHandler.js +5 -0
- package/dist/bin.js +316 -98
- package/dist/bothCLIConfig.d.ts.map +1 -1
- package/dist/bothCLIConfig.js +2 -2
- package/dist/bothCLIConfigHandler.d.ts.map +1 -1
- package/dist/bothCLIConfigHandler.js +8 -2
- package/dist/cliHelpers.d.ts +22 -4
- package/dist/cliHelpers.d.ts.map +1 -1
- package/dist/cliHelpers.js +43 -11
- package/dist/createServer.d.ts +19 -3
- package/dist/createServer.d.ts.map +1 -1
- package/dist/createServer.js +18 -11
- package/dist/createServerHelpers.d.ts +15 -2
- package/dist/createServerHelpers.d.ts.map +1 -1
- package/dist/createServerHelpers.js +14 -4
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +5 -0
- package/dist/logFormatter/formatters.d.ts +1 -1
- package/dist/logFormatter/formatters.d.ts.map +1 -1
- package/dist/logFormatter/index.d.ts.map +1 -1
- package/dist/plugins/api.d.ts +4 -5
- package/dist/plugins/api.d.ts.map +1 -1
- package/dist/plugins/api.js +15 -15
- package/dist/plugins/graphql.d.ts +20 -3
- package/dist/plugins/graphql.d.ts.map +1 -1
- package/dist/plugins/graphql.js +69 -28
- package/dist/plugins/lambdaLoader.d.ts +16 -6
- package/dist/plugins/lambdaLoader.d.ts.map +1 -1
- package/dist/plugins/lambdaLoader.js +73 -10
- package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -1
- package/dist/requestHandlers/awsLambdaFastify.js +16 -4
- package/dist/serverFile.d.ts +23 -0
- package/dist/serverFile.d.ts.map +1 -0
- package/dist/serverFile.js +35 -0
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -20
- package/package.json +56 -72
- package/LICENSE +0 -21
- package/dist/buildManager.d.ts +0 -15
- package/dist/buildManager.d.ts.map +0 -1
- package/dist/buildManager.js +0 -50
- package/dist/cjs/apiCLIConfig.d.ts +0 -6
- package/dist/cjs/apiCLIConfig.d.ts.map +0 -1
- package/dist/cjs/apiCLIConfig.js +0 -71
- package/dist/cjs/apiCLIConfigHandler.d.ts +0 -3
- package/dist/cjs/apiCLIConfigHandler.d.ts.map +0 -1
- package/dist/cjs/apiCLIConfigHandler.js +0 -67
- package/dist/cjs/bin.d.ts +0 -2
- package/dist/cjs/bin.d.ts.map +0 -1
- package/dist/cjs/bin.js +0 -896
- package/dist/cjs/bothCLIConfig.d.ts +0 -6
- package/dist/cjs/bothCLIConfig.d.ts.map +0 -1
- package/dist/cjs/bothCLIConfig.js +0 -76
- package/dist/cjs/bothCLIConfigHandler.d.ts +0 -3
- package/dist/cjs/bothCLIConfigHandler.d.ts.map +0 -1
- package/dist/cjs/bothCLIConfigHandler.js +0 -107
- package/dist/cjs/buildManager.d.ts +0 -15
- package/dist/cjs/buildManager.d.ts.map +0 -1
- package/dist/cjs/buildManager.js +0 -74
- package/dist/cjs/cliHelpers.d.ts +0 -5
- package/dist/cjs/cliHelpers.d.ts.map +0 -1
- package/dist/cjs/cliHelpers.js +0 -52
- package/dist/cjs/createServer.d.ts +0 -30
- package/dist/cjs/createServer.d.ts.map +0 -1
- package/dist/cjs/createServer.js +0 -144
- package/dist/cjs/createServerHelpers.d.ts +0 -38
- package/dist/cjs/createServerHelpers.d.ts.map +0 -1
- package/dist/cjs/createServerHelpers.js +0 -112
- package/dist/cjs/fastify.d.ts +0 -13
- package/dist/cjs/fastify.d.ts.map +0 -1
- package/dist/cjs/fastify.js +0 -91
- package/dist/cjs/logFormatter/ambient.d.js +0 -1
- package/dist/cjs/logFormatter/bin.d.ts +0 -2
- package/dist/cjs/logFormatter/bin.d.ts.map +0 -1
- package/dist/cjs/logFormatter/bin.js +0 -369
- package/dist/cjs/logFormatter/formatters.d.ts +0 -30
- package/dist/cjs/logFormatter/formatters.d.ts.map +0 -1
- package/dist/cjs/logFormatter/formatters.js +0 -275
- package/dist/cjs/logFormatter/index.d.ts +0 -2
- package/dist/cjs/logFormatter/index.d.ts.map +0 -1
- package/dist/cjs/logFormatter/index.js +0 -184
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/plugins/api.d.ts +0 -14
- package/dist/cjs/plugins/api.d.ts.map +0 -1
- package/dist/cjs/plugins/api.js +0 -78
- package/dist/cjs/plugins/graphql.d.ts +0 -10
- package/dist/cjs/plugins/graphql.d.ts.map +0 -1
- package/dist/cjs/plugins/graphql.js +0 -109
- package/dist/cjs/plugins/lambdaLoader.d.ts +0 -24
- package/dist/cjs/plugins/lambdaLoader.d.ts.map +0 -1
- package/dist/cjs/plugins/lambdaLoader.js +0 -134
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +0 -5
- package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +0 -1
- package/dist/cjs/requestHandlers/awsLambdaFastify.js +0 -103
- package/dist/cjs/requestHandlers/utils.d.ts +0 -26
- package/dist/cjs/requestHandlers/utils.d.ts.map +0 -1
- package/dist/cjs/requestHandlers/utils.js +0 -55
- package/dist/cjs/serverManager.d.ts +0 -8
- package/dist/cjs/serverManager.d.ts.map +0 -1
- package/dist/cjs/serverManager.js +0 -137
- package/dist/cjs/types.d.ts +0 -19
- package/dist/cjs/types.d.ts.map +0 -1
- package/dist/cjs/utils.d.ts +0 -6
- package/dist/cjs/utils.d.ts.map +0 -1
- package/dist/cjs/utils.js +0 -58
- package/dist/cjs/watch.d.ts +0 -10
- package/dist/cjs/watch.d.ts.map +0 -1
- package/dist/cjs/watch.js +0 -394
- package/dist/cjs/watchPaths.d.ts +0 -3
- package/dist/cjs/watchPaths.d.ts.map +0 -1
- package/dist/cjs/watchPaths.js +0 -140
- package/dist/serverManager.d.ts +0 -8
- package/dist/serverManager.d.ts.map +0 -1
- package/dist/serverManager.js +0 -102
- package/dist/watch.d.ts +0 -10
- package/dist/watch.d.ts.map +0 -1
- package/dist/watch.js +0 -370
- package/dist/watchPaths.d.ts +0 -3
- package/dist/watchPaths.d.ts.map +0 -1
- package/dist/watchPaths.js +0 -109
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var createServerHelpers_exports = {};
|
|
20
|
-
__export(createServerHelpers_exports, {
|
|
21
|
-
getDefaultCreateServerOptions: () => getDefaultCreateServerOptions,
|
|
22
|
-
resolveOptions: () => resolveOptions
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(createServerHelpers_exports);
|
|
25
|
-
var import_util = require("util");
|
|
26
|
-
var import_helpers = require("@cedarjs/fastify-web/dist/helpers.js");
|
|
27
|
-
var import_cliHelpers = require("./cliHelpers.js");
|
|
28
|
-
const getDefaultCreateServerOptions = () => ({
|
|
29
|
-
apiRootPath: "/",
|
|
30
|
-
logger: {
|
|
31
|
-
level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === "development" ? "debug" : "warn")
|
|
32
|
-
},
|
|
33
|
-
fastifyServerOptions: {
|
|
34
|
-
requestTimeout: 15e3,
|
|
35
|
-
bodyLimit: 1024 * 1024 * 100
|
|
36
|
-
// 100MB
|
|
37
|
-
},
|
|
38
|
-
discoverFunctionsGlob: "dist/functions/**/*.{ts,js}",
|
|
39
|
-
configureApiServer: () => {
|
|
40
|
-
},
|
|
41
|
-
parseArgs: true,
|
|
42
|
-
apiHost: (0, import_cliHelpers.getAPIHost)(),
|
|
43
|
-
apiPort: (0, import_cliHelpers.getAPIPort)()
|
|
44
|
-
});
|
|
45
|
-
function isCustomLoggerInstance(logger) {
|
|
46
|
-
return !!logger && typeof logger === "object" && "info" in logger;
|
|
47
|
-
}
|
|
48
|
-
function resolveOptions(options = {}, args) {
|
|
49
|
-
options.parseArgs ??= true;
|
|
50
|
-
const defaults = getDefaultCreateServerOptions();
|
|
51
|
-
const logger = options.logger ?? defaults.logger;
|
|
52
|
-
const resolvedOptions = {
|
|
53
|
-
apiRootPath: options.apiRootPath ?? defaults.apiRootPath,
|
|
54
|
-
fastifyServerOptions: options.fastifyServerOptions ?? {
|
|
55
|
-
requestTimeout: defaults.fastifyServerOptions.requestTimeout,
|
|
56
|
-
bodyLimit: defaults.fastifyServerOptions.bodyLimit
|
|
57
|
-
},
|
|
58
|
-
discoverFunctionsGlob: options.discoverFunctionsGlob ?? defaults.discoverFunctionsGlob,
|
|
59
|
-
configureApiServer: options.configureApiServer ?? defaults.configureApiServer,
|
|
60
|
-
apiHost: options.apiHost ?? defaults.apiHost,
|
|
61
|
-
apiPort: options.apiPort ?? defaults.apiPort
|
|
62
|
-
};
|
|
63
|
-
resolvedOptions.fastifyServerOptions.requestTimeout ??= defaults.fastifyServerOptions.requestTimeout;
|
|
64
|
-
if (isCustomLoggerInstance(logger)) {
|
|
65
|
-
resolvedOptions.fastifyServerOptions.loggerInstance = logger;
|
|
66
|
-
} else {
|
|
67
|
-
resolvedOptions.fastifyServerOptions.logger = logger;
|
|
68
|
-
}
|
|
69
|
-
if (options.parseArgs) {
|
|
70
|
-
const { values } = (0, import_util.parseArgs)({
|
|
71
|
-
options: {
|
|
72
|
-
apiHost: {
|
|
73
|
-
type: "string"
|
|
74
|
-
},
|
|
75
|
-
apiPort: {
|
|
76
|
-
type: "string",
|
|
77
|
-
short: "p"
|
|
78
|
-
},
|
|
79
|
-
apiRootPath: {
|
|
80
|
-
type: "string"
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
strict: false,
|
|
84
|
-
...args && { args }
|
|
85
|
-
});
|
|
86
|
-
if (values.apiHost && typeof values.apiHost !== "string") {
|
|
87
|
-
throw new Error("`apiHost` must be a string");
|
|
88
|
-
}
|
|
89
|
-
if (values.apiHost) {
|
|
90
|
-
resolvedOptions.apiHost = values.apiHost;
|
|
91
|
-
}
|
|
92
|
-
if (values.apiPort) {
|
|
93
|
-
resolvedOptions.apiPort = +values.apiPort;
|
|
94
|
-
if (isNaN(resolvedOptions.apiPort)) {
|
|
95
|
-
throw new Error("`apiPort` must be an integer");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (values.apiRootPath && typeof values.apiRootPath !== "string") {
|
|
99
|
-
throw new Error("`apiRootPath` must be a string");
|
|
100
|
-
}
|
|
101
|
-
if (values.apiRootPath) {
|
|
102
|
-
resolvedOptions.apiRootPath = values.apiRootPath;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
resolvedOptions.apiRootPath = (0, import_helpers.coerceRootPath)(resolvedOptions.apiRootPath);
|
|
106
|
-
return resolvedOptions;
|
|
107
|
-
}
|
|
108
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
-
0 && (module.exports = {
|
|
110
|
-
getDefaultCreateServerOptions,
|
|
111
|
-
resolveOptions
|
|
112
|
-
});
|
package/dist/cjs/fastify.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FastifyInstance, FastifyServerOptions } from 'fastify';
|
|
2
|
-
import type { FastifySideConfigFn } from './types.js';
|
|
3
|
-
export declare const DEFAULT_OPTIONS: {
|
|
4
|
-
logger: {
|
|
5
|
-
level: string;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export declare function loadFastifyConfig(): Promise<{
|
|
9
|
-
config: FastifyServerOptions;
|
|
10
|
-
configureFastify: FastifySideConfigFn;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const createFastifyInstance: (options?: FastifyServerOptions) => Promise<FastifyInstance>;
|
|
13
|
-
//# sourceMappingURL=fastify.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../../src/fastify.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAOpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrD,eAAO,MAAM,eAAe;;;;CAI3B,CAAA;AAiBD,wBAAsB,iBAAiB;YAb7B,oBAAoB;sBACV,mBAAmB;GAsCtC;AAED,eAAO,MAAM,qBAAqB,GAChC,UAAU,oBAAoB,KAC7B,OAAO,CAAC,eAAe,CAWzB,CAAA"}
|
package/dist/cjs/fastify.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var fastify_exports = {};
|
|
30
|
-
__export(fastify_exports, {
|
|
31
|
-
DEFAULT_OPTIONS: () => DEFAULT_OPTIONS,
|
|
32
|
-
createFastifyInstance: () => createFastifyInstance,
|
|
33
|
-
loadFastifyConfig: () => loadFastifyConfig
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(fastify_exports);
|
|
36
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
37
|
-
var import_path = __toESM(require("path"), 1);
|
|
38
|
-
var import_url = require("url");
|
|
39
|
-
var import_fastify = __toESM(require("fastify"), 1);
|
|
40
|
-
var import_store = require("@cedarjs/context/dist/store");
|
|
41
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
42
|
-
const DEFAULT_OPTIONS = {
|
|
43
|
-
logger: {
|
|
44
|
-
level: process.env.NODE_ENV === "development" ? "debug" : "info"
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
let isServerConfigLoaded = false;
|
|
48
|
-
let serverConfigFile = {
|
|
49
|
-
config: DEFAULT_OPTIONS,
|
|
50
|
-
configureFastify: async (fastify, options) => {
|
|
51
|
-
fastify.log.trace(
|
|
52
|
-
options,
|
|
53
|
-
`In configureFastify hook for side: ${options?.side}`
|
|
54
|
-
);
|
|
55
|
-
return fastify;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
async function loadFastifyConfig() {
|
|
59
|
-
const serverConfigPath = import_path.default.join(
|
|
60
|
-
(0, import_project_config.getPaths)().base,
|
|
61
|
-
(0, import_project_config.getConfig)().api.serverConfig
|
|
62
|
-
);
|
|
63
|
-
if (!import_node_fs.default.existsSync(serverConfigPath)) {
|
|
64
|
-
return serverConfigFile;
|
|
65
|
-
}
|
|
66
|
-
if (!isServerConfigLoaded) {
|
|
67
|
-
console.log(`Loading server config from ${serverConfigPath}`);
|
|
68
|
-
console.log(`Loading server config from URL file://${serverConfigPath}`);
|
|
69
|
-
console.log(
|
|
70
|
-
`Loading server config from URL ${(0, import_url.pathToFileURL)(serverConfigPath).href}`
|
|
71
|
-
);
|
|
72
|
-
const config = await import((0, import_url.pathToFileURL)(serverConfigPath).href);
|
|
73
|
-
serverConfigFile = { ...config.default };
|
|
74
|
-
isServerConfigLoaded = true;
|
|
75
|
-
}
|
|
76
|
-
return serverConfigFile;
|
|
77
|
-
}
|
|
78
|
-
const createFastifyInstance = async (options) => {
|
|
79
|
-
const { config } = await loadFastifyConfig();
|
|
80
|
-
const fastify = (0, import_fastify.default)(options || config || DEFAULT_OPTIONS);
|
|
81
|
-
fastify.addHook("onRequest", (_req, _reply, done) => {
|
|
82
|
-
(0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
|
|
83
|
-
});
|
|
84
|
-
return fastify;
|
|
85
|
-
};
|
|
86
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
-
0 && (module.exports = {
|
|
88
|
-
DEFAULT_OPTIONS,
|
|
89
|
-
createFastifyInstance,
|
|
90
|
-
loadFastifyConfig
|
|
91
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../../src/logFormatter/bin.ts"],"names":[],"mappings":""}
|
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
-
mod
|
|
24
|
-
));
|
|
25
|
-
|
|
26
|
-
// src/logFormatter/bin.ts
|
|
27
|
-
var import_split2 = __toESM(require("split2"), 1);
|
|
28
|
-
|
|
29
|
-
// src/logFormatter/index.ts
|
|
30
|
-
var import_fast_json_parse = __toESM(require("fast-json-parse"), 1);
|
|
31
|
-
|
|
32
|
-
// src/logFormatter/formatters.ts
|
|
33
|
-
var import_ansis = __toESM(require("ansis"), 1);
|
|
34
|
-
var import_pretty_bytes = __toESM(require("pretty-bytes"), 1);
|
|
35
|
-
var import_pretty_ms = __toESM(require("pretty-ms"), 1);
|
|
36
|
-
var NEWLINE = "\n";
|
|
37
|
-
var emojiLog = {
|
|
38
|
-
warn: "\u{1F6A6}",
|
|
39
|
-
info: "\u{1F332}",
|
|
40
|
-
error: "\u{1F6A8}",
|
|
41
|
-
debug: "\u{1F41B}",
|
|
42
|
-
fatal: "\u{1F480}",
|
|
43
|
-
trace: "\u{1F9F5}"
|
|
44
|
-
};
|
|
45
|
-
var ignoredCustomData = [
|
|
46
|
-
"time",
|
|
47
|
-
"pid",
|
|
48
|
-
"hostname",
|
|
49
|
-
"msg",
|
|
50
|
-
"res",
|
|
51
|
-
"req",
|
|
52
|
-
"reqId",
|
|
53
|
-
"responseTime"
|
|
54
|
-
];
|
|
55
|
-
var isObject = (object) => {
|
|
56
|
-
return object && Object.prototype.toString.apply(object) === "[object Object]";
|
|
57
|
-
};
|
|
58
|
-
var isEmptyObject = (object) => {
|
|
59
|
-
return object && !Object.keys(object).length;
|
|
60
|
-
};
|
|
61
|
-
var isPinoLog = (log) => {
|
|
62
|
-
return log && Object.prototype.hasOwnProperty.call(log, "level");
|
|
63
|
-
};
|
|
64
|
-
var isWideEmoji = (character) => {
|
|
65
|
-
return character !== "\u{1F6A6}";
|
|
66
|
-
};
|
|
67
|
-
var formatBundleSize = (bundle) => {
|
|
68
|
-
const bytes = parseInt(bundle, 10);
|
|
69
|
-
const size = (0, import_pretty_bytes.default)(bytes).replace(/ /, "");
|
|
70
|
-
return import_ansis.default.gray(size);
|
|
71
|
-
};
|
|
72
|
-
var formatCustom = (query) => {
|
|
73
|
-
if (!query) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
ignoredCustomData.forEach((key) => {
|
|
77
|
-
delete query[key];
|
|
78
|
-
});
|
|
79
|
-
if (!isEmptyObject(query)) {
|
|
80
|
-
return import_ansis.default.white(
|
|
81
|
-
NEWLINE + "\u{1F5D2} Custom" + NEWLINE + JSON.stringify(query, null, 2)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
};
|
|
86
|
-
var formatData = (data) => {
|
|
87
|
-
if (!isEmptyObject(data)) {
|
|
88
|
-
return import_ansis.default.white(
|
|
89
|
-
NEWLINE + "\u{1F4E6} Result Data" + NEWLINE + JSON.stringify(data, null, 2)
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return;
|
|
93
|
-
};
|
|
94
|
-
var formatDate = (instant) => {
|
|
95
|
-
const date = new Date(instant);
|
|
96
|
-
const hours = date.getHours().toString().padStart(2, "0");
|
|
97
|
-
const minutes = date.getMinutes().toString().padStart(2, "0");
|
|
98
|
-
const seconds = date.getSeconds().toString().padStart(2, "0");
|
|
99
|
-
const prettyDate = hours + ":" + minutes + ":" + seconds;
|
|
100
|
-
return import_ansis.default.gray(prettyDate);
|
|
101
|
-
};
|
|
102
|
-
var formatErrorProp = (errorPropValue) => {
|
|
103
|
-
const errorType = errorPropValue["type"] || "Error";
|
|
104
|
-
delete errorPropValue["message"];
|
|
105
|
-
delete errorPropValue["stack"];
|
|
106
|
-
delete errorPropValue["type"];
|
|
107
|
-
return import_ansis.default.redBright(
|
|
108
|
-
NEWLINE + NEWLINE + `\u{1F6A8} ${errorType} Info` + NEWLINE + NEWLINE + JSON.stringify(errorPropValue, null, 2) + NEWLINE
|
|
109
|
-
);
|
|
110
|
-
};
|
|
111
|
-
var formatLevel = (level) => {
|
|
112
|
-
const emoji = emojiLog[level];
|
|
113
|
-
const padding = isWideEmoji(emoji) ? "" : " ";
|
|
114
|
-
return emoji + padding;
|
|
115
|
-
};
|
|
116
|
-
var formatLoadTime = (elapsedTime) => {
|
|
117
|
-
const elapsed = parseInt(elapsedTime, 10);
|
|
118
|
-
const time = (0, import_pretty_ms.default)(elapsed);
|
|
119
|
-
return import_ansis.default.gray(time);
|
|
120
|
-
};
|
|
121
|
-
var formatMessage = (logData) => {
|
|
122
|
-
const { level, message } = logData;
|
|
123
|
-
const msg = formatMessageName(message);
|
|
124
|
-
let pretty;
|
|
125
|
-
if (level === "error") {
|
|
126
|
-
pretty = import_ansis.default.red(msg);
|
|
127
|
-
}
|
|
128
|
-
if (level === "trace") {
|
|
129
|
-
pretty = import_ansis.default.white(msg);
|
|
130
|
-
}
|
|
131
|
-
if (level === "warn") {
|
|
132
|
-
const orange = "#ffa500";
|
|
133
|
-
pretty = import_ansis.default.hex(orange)(msg);
|
|
134
|
-
}
|
|
135
|
-
if (level === "debug") {
|
|
136
|
-
pretty = import_ansis.default.yellow(msg);
|
|
137
|
-
}
|
|
138
|
-
if (level === "info" || level === "customlevel") {
|
|
139
|
-
pretty = import_ansis.default.green(msg);
|
|
140
|
-
}
|
|
141
|
-
if (level === "fatal") {
|
|
142
|
-
pretty = import_ansis.default.white.bgRed(msg);
|
|
143
|
-
}
|
|
144
|
-
return pretty;
|
|
145
|
-
};
|
|
146
|
-
var formatMethod = (method) => {
|
|
147
|
-
return method && import_ansis.default.white(method);
|
|
148
|
-
};
|
|
149
|
-
var formatRequestId = (requestId) => {
|
|
150
|
-
return requestId && import_ansis.default.cyan(requestId);
|
|
151
|
-
};
|
|
152
|
-
var formatNs = (ns) => {
|
|
153
|
-
return ns && import_ansis.default.cyan(ns);
|
|
154
|
-
};
|
|
155
|
-
var formatName = (name) => {
|
|
156
|
-
return name && import_ansis.default.blue(name);
|
|
157
|
-
};
|
|
158
|
-
var formatMessageName = (message) => {
|
|
159
|
-
if (message === void 0) {
|
|
160
|
-
return "";
|
|
161
|
-
}
|
|
162
|
-
if (message === "request") {
|
|
163
|
-
return "<--";
|
|
164
|
-
}
|
|
165
|
-
if (message === "response") {
|
|
166
|
-
return "-->";
|
|
167
|
-
}
|
|
168
|
-
return message;
|
|
169
|
-
};
|
|
170
|
-
var formatOperationName = (operationName) => {
|
|
171
|
-
return import_ansis.default.white(NEWLINE + "\u{1F3F7} " + operationName);
|
|
172
|
-
};
|
|
173
|
-
var formatQuery = (query) => {
|
|
174
|
-
if (!isEmptyObject(query)) {
|
|
175
|
-
return import_ansis.default.white(
|
|
176
|
-
NEWLINE + "\u{1F52D} Query" + NEWLINE + JSON.stringify(query, null, 2)
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
return;
|
|
180
|
-
};
|
|
181
|
-
var formatResponseCache = (responseCache) => {
|
|
182
|
-
if (!isEmptyObject(responseCache)) {
|
|
183
|
-
return import_ansis.default.white(
|
|
184
|
-
NEWLINE + "\u{1F4BE} Response Cache" + NEWLINE + JSON.stringify(responseCache, null, 2)
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
return;
|
|
188
|
-
};
|
|
189
|
-
var formatStatusCode = (statusCode) => {
|
|
190
|
-
statusCode = statusCode || "xxx";
|
|
191
|
-
return import_ansis.default.white(statusCode);
|
|
192
|
-
};
|
|
193
|
-
var formatStack = (stack) => {
|
|
194
|
-
return import_ansis.default.redBright(
|
|
195
|
-
stack ? NEWLINE + "\u{1F95E} Error Stack" + NEWLINE + NEWLINE + stack + NEWLINE : ""
|
|
196
|
-
);
|
|
197
|
-
};
|
|
198
|
-
var formatTracing = (data) => {
|
|
199
|
-
if (!isEmptyObject(data)) {
|
|
200
|
-
return import_ansis.default.white(
|
|
201
|
-
NEWLINE + "\u23F0 Timing" + NEWLINE + JSON.stringify(data, null, 2)
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
return;
|
|
205
|
-
};
|
|
206
|
-
var formatUrl = (url) => {
|
|
207
|
-
return import_ansis.default.white(url);
|
|
208
|
-
};
|
|
209
|
-
var formatUserAgent = (userAgent) => {
|
|
210
|
-
return import_ansis.default.gray(NEWLINE + "\u{1F575}\uFE0F\u200D\u2640\uFE0F " + userAgent);
|
|
211
|
-
};
|
|
212
|
-
var noEmpty = (value) => {
|
|
213
|
-
return !!value;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// src/logFormatter/index.ts
|
|
217
|
-
var LogFormatter = () => {
|
|
218
|
-
const parse = (inputData) => {
|
|
219
|
-
let logData;
|
|
220
|
-
if (typeof inputData === "string") {
|
|
221
|
-
const parsedData = (0, import_fast_json_parse.default)(inputData);
|
|
222
|
-
if (!parsedData.value || parsedData.err || !isPinoLog(parsedData.value)) {
|
|
223
|
-
return inputData + NEWLINE;
|
|
224
|
-
}
|
|
225
|
-
logData = parsedData.value;
|
|
226
|
-
} else if (isObject(inputData) && isPinoLog(inputData)) {
|
|
227
|
-
logData = inputData;
|
|
228
|
-
} else {
|
|
229
|
-
return inputData + NEWLINE;
|
|
230
|
-
}
|
|
231
|
-
if (!logData.level) {
|
|
232
|
-
return inputData + NEWLINE;
|
|
233
|
-
}
|
|
234
|
-
if (!logData.message) {
|
|
235
|
-
logData.message = logData.msg;
|
|
236
|
-
}
|
|
237
|
-
if (typeof logData.level === "number") {
|
|
238
|
-
convertLogNumber(logData);
|
|
239
|
-
}
|
|
240
|
-
return output2(logData) + NEWLINE;
|
|
241
|
-
};
|
|
242
|
-
const convertLogNumber = (logData) => {
|
|
243
|
-
if (logData.level === 10) {
|
|
244
|
-
logData.level = "trace";
|
|
245
|
-
}
|
|
246
|
-
if (logData.level === 20) {
|
|
247
|
-
logData.level = "debug";
|
|
248
|
-
}
|
|
249
|
-
if (logData.level === 30) {
|
|
250
|
-
logData.level = "info";
|
|
251
|
-
}
|
|
252
|
-
if (logData.level === 40) {
|
|
253
|
-
logData.level = "warn";
|
|
254
|
-
}
|
|
255
|
-
if (logData.level === 50) {
|
|
256
|
-
logData.level = "error";
|
|
257
|
-
}
|
|
258
|
-
if (logData.level === 60) {
|
|
259
|
-
logData.level = "fatal";
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
const output2 = (logData) => {
|
|
263
|
-
const output3 = [];
|
|
264
|
-
output3.push(formatDate(logData.time || Date.now()));
|
|
265
|
-
output3.push(formatLevel(logData.level));
|
|
266
|
-
output3.push(formatNs(logData.ns));
|
|
267
|
-
output3.push(formatName(logData.name));
|
|
268
|
-
output3.push(formatRequestId(logData.requestId));
|
|
269
|
-
output3.push(formatMessage(logData));
|
|
270
|
-
const req = logData.req;
|
|
271
|
-
const res = logData.res;
|
|
272
|
-
const { statusCode: responseStatusCode } = res || {};
|
|
273
|
-
const { method: requestMethod, url: requestUrl } = req || {};
|
|
274
|
-
const {
|
|
275
|
-
level,
|
|
276
|
-
message,
|
|
277
|
-
name,
|
|
278
|
-
ns,
|
|
279
|
-
err: logDataErr,
|
|
280
|
-
stack: logDataStack,
|
|
281
|
-
statusCode: logDataStatusCode,
|
|
282
|
-
elapsed,
|
|
283
|
-
responseTime: logDataResponseTime,
|
|
284
|
-
method: logDataMethod,
|
|
285
|
-
custom,
|
|
286
|
-
contentLength,
|
|
287
|
-
operationName,
|
|
288
|
-
query,
|
|
289
|
-
data: graphQLData,
|
|
290
|
-
responseCache,
|
|
291
|
-
tracing,
|
|
292
|
-
url: logDataUrl,
|
|
293
|
-
userAgent,
|
|
294
|
-
...rest
|
|
295
|
-
} = logData;
|
|
296
|
-
const statusCode = responseStatusCode || logDataStatusCode;
|
|
297
|
-
const responseTime = logDataResponseTime || elapsed;
|
|
298
|
-
const method = requestMethod || logDataMethod;
|
|
299
|
-
const url = requestUrl || logDataUrl;
|
|
300
|
-
const logDataErrStack = logDataErr && logDataErr.stack;
|
|
301
|
-
const stack = level === "fatal" || level === "error" ? logDataStack || logDataErr && logDataErrStack : null;
|
|
302
|
-
const err = (level === "fatal" || level === "error") && logDataErr && Object.keys(logDataErr).find((key) => key !== "stack") ? logDataErr : null;
|
|
303
|
-
if (!message) {
|
|
304
|
-
logData.message = "";
|
|
305
|
-
}
|
|
306
|
-
if (!level) {
|
|
307
|
-
logData.level = "customlevel";
|
|
308
|
-
}
|
|
309
|
-
if (!name) {
|
|
310
|
-
logData.name = "";
|
|
311
|
-
}
|
|
312
|
-
if (!ns) {
|
|
313
|
-
logData.ns = "";
|
|
314
|
-
}
|
|
315
|
-
if (method != null) {
|
|
316
|
-
output3.push(formatMethod(method));
|
|
317
|
-
output3.push(formatStatusCode(statusCode));
|
|
318
|
-
}
|
|
319
|
-
if (url != null) {
|
|
320
|
-
output3.push(formatUrl(url));
|
|
321
|
-
}
|
|
322
|
-
if (contentLength != null) {
|
|
323
|
-
output3.push(formatBundleSize(contentLength));
|
|
324
|
-
}
|
|
325
|
-
if (custom) {
|
|
326
|
-
output3.push(formatCustom(custom));
|
|
327
|
-
}
|
|
328
|
-
if (responseTime != null) {
|
|
329
|
-
output3.push(formatLoadTime(responseTime));
|
|
330
|
-
}
|
|
331
|
-
if (userAgent != null) {
|
|
332
|
-
output3.push(formatUserAgent(userAgent));
|
|
333
|
-
}
|
|
334
|
-
if (operationName != null) {
|
|
335
|
-
output3.push(formatOperationName(operationName));
|
|
336
|
-
}
|
|
337
|
-
if (query != null) {
|
|
338
|
-
output3.push(formatQuery(query));
|
|
339
|
-
}
|
|
340
|
-
if (graphQLData != null) {
|
|
341
|
-
output3.push(formatData(graphQLData));
|
|
342
|
-
}
|
|
343
|
-
if (responseCache != null) {
|
|
344
|
-
output3.push(formatResponseCache(responseCache));
|
|
345
|
-
}
|
|
346
|
-
if (tracing != null) {
|
|
347
|
-
output3.push(formatTracing(tracing));
|
|
348
|
-
}
|
|
349
|
-
if (err != null) {
|
|
350
|
-
output3.push(formatErrorProp(err));
|
|
351
|
-
}
|
|
352
|
-
if (stack != null) {
|
|
353
|
-
output3.push(formatStack(stack));
|
|
354
|
-
}
|
|
355
|
-
if (rest) {
|
|
356
|
-
output3.push(formatCustom(rest));
|
|
357
|
-
}
|
|
358
|
-
return output3.filter(noEmpty).join(" ");
|
|
359
|
-
};
|
|
360
|
-
return parse;
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// src/logFormatter/bin.ts
|
|
364
|
-
var input = process.stdin;
|
|
365
|
-
var output = process.stdout;
|
|
366
|
-
input.pipe((0, import_split2.default)(LogFormatter())).pipe(output);
|
|
367
|
-
process.on("SIGINT", () => {
|
|
368
|
-
process.exit(0);
|
|
369
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare const NEWLINE = "\n";
|
|
2
|
-
export declare const emojiLog: Record<string, string>;
|
|
3
|
-
export declare const ignoredCustomData: string[];
|
|
4
|
-
export declare const isObject: (object?: Record<string, unknown>) => boolean | undefined;
|
|
5
|
-
export declare const isEmptyObject: (object?: Record<string, unknown>) => boolean | undefined;
|
|
6
|
-
export declare const isPinoLog: (log?: Record<string, unknown>) => boolean | undefined;
|
|
7
|
-
export declare const isWideEmoji: (character: string) => boolean;
|
|
8
|
-
export declare const formatBundleSize: (bundle: string) => string;
|
|
9
|
-
export declare const formatCustom: (query?: Record<string, unknown>) => string | undefined;
|
|
10
|
-
export declare const formatData: (data?: Record<string, unknown>) => string | undefined;
|
|
11
|
-
export declare const formatDate: (instant: Date) => string;
|
|
12
|
-
export declare const formatErrorProp: (errorPropValue: Record<string, unknown>) => string;
|
|
13
|
-
export declare const formatLevel: (level: any) => string;
|
|
14
|
-
export declare const formatLoadTime: (elapsedTime: any) => string;
|
|
15
|
-
export declare const formatMessage: (logData: any) => string | undefined;
|
|
16
|
-
export declare const formatMethod: (method: string) => string;
|
|
17
|
-
export declare const formatRequestId: (requestId: string) => string;
|
|
18
|
-
export declare const formatNs: (ns: string) => string;
|
|
19
|
-
export declare const formatName: (name: string) => string;
|
|
20
|
-
export declare const formatMessageName: (message: string) => string;
|
|
21
|
-
export declare const formatOperationName: (operationName: string) => string;
|
|
22
|
-
export declare const formatQuery: (query?: Record<string, unknown>) => string | undefined;
|
|
23
|
-
export declare const formatResponseCache: (responseCache?: Record<string, unknown>) => string | undefined;
|
|
24
|
-
export declare const formatStatusCode: (statusCode: string) => string;
|
|
25
|
-
export declare const formatStack: (stack?: string | Record<string, unknown>) => string;
|
|
26
|
-
export declare const formatTracing: (data?: Record<string, unknown>) => string | undefined;
|
|
27
|
-
export declare const formatUrl: (url: string) => string;
|
|
28
|
-
export declare const formatUserAgent: (userAgent: string) => string;
|
|
29
|
-
export declare const noEmpty: (value: any) => boolean;
|
|
30
|
-
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../src/logFormatter/formatters.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,OAAO,CAAA;AAE3B,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAO3C,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,EASrC,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAExD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAE7D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,wBAEtD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,YAE5C,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,WAI9C,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAgB3D,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQxD,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,SAAS,IAAI,WAOvC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAgBtE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,GAAG,WAIrC,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,aAAa,GAAG,WAI9C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,GAAG,uBAyBzC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,WAE1C,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,WAEhD,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,IAAI,MAAM,WAElC,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,MAAM,WAYhD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,eAAe,MAAM,WAExD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQ1D,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAYxC,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,WAGlD,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAMnE,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAQ3D,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAEpC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,WAEhD,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,OAAO,GAAG,YAEjC,CAAA"}
|