@redmix/api-server 0.0.1
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/apiCLIConfig.d.ts +6 -0
- package/dist/apiCLIConfig.d.ts.map +1 -0
- package/dist/apiCLIConfig.js +71 -0
- package/dist/apiCLIConfigHandler.d.ts +3 -0
- package/dist/apiCLIConfigHandler.d.ts.map +1 -0
- package/dist/apiCLIConfigHandler.js +68 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +850 -0
- package/dist/bothCLIConfig.d.ts +6 -0
- package/dist/bothCLIConfig.d.ts.map +1 -0
- package/dist/bothCLIConfig.js +76 -0
- package/dist/bothCLIConfigHandler.d.ts +3 -0
- package/dist/bothCLIConfigHandler.d.ts.map +1 -0
- package/dist/bothCLIConfigHandler.js +107 -0
- package/dist/buildManager.d.ts +15 -0
- package/dist/buildManager.d.ts.map +1 -0
- package/dist/buildManager.js +74 -0
- package/dist/cliHelpers.d.ts +5 -0
- package/dist/cliHelpers.d.ts.map +1 -0
- package/dist/cliHelpers.js +52 -0
- package/dist/createServer.d.ts +30 -0
- package/dist/createServer.d.ts.map +1 -0
- package/dist/createServer.js +142 -0
- package/dist/createServerHelpers.d.ts +39 -0
- package/dist/createServerHelpers.d.ts.map +1 -0
- package/dist/createServerHelpers.js +101 -0
- package/dist/fastify.d.ts +14 -0
- package/dist/fastify.d.ts.map +1 -0
- package/dist/fastify.js +88 -0
- package/dist/logFormatter/ambient.d.js +1 -0
- package/dist/logFormatter/bin.d.ts +2 -0
- package/dist/logFormatter/bin.d.ts.map +1 -0
- package/dist/logFormatter/bin.js +369 -0
- package/dist/logFormatter/formatters.d.ts +30 -0
- package/dist/logFormatter/formatters.d.ts.map +1 -0
- package/dist/logFormatter/formatters.js +275 -0
- package/dist/logFormatter/index.d.ts +2 -0
- package/dist/logFormatter/index.d.ts.map +1 -0
- package/dist/logFormatter/index.js +184 -0
- package/dist/plugins/api.d.ts +13 -0
- package/dist/plugins/api.d.ts.map +1 -0
- package/dist/plugins/api.js +77 -0
- package/dist/plugins/graphql.d.ts +10 -0
- package/dist/plugins/graphql.d.ts.map +1 -0
- package/dist/plugins/graphql.js +115 -0
- package/dist/plugins/lambdaLoader.d.ts +23 -0
- package/dist/plugins/lambdaLoader.d.ts.map +1 -0
- package/dist/plugins/lambdaLoader.js +116 -0
- package/dist/requestHandlers/awsLambdaFastify.d.ts +5 -0
- package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -0
- package/dist/requestHandlers/awsLambdaFastify.js +103 -0
- package/dist/requestHandlers/utils.d.ts +26 -0
- package/dist/requestHandlers/utils.d.ts.map +1 -0
- package/dist/requestHandlers/utils.js +55 -0
- package/dist/serverManager.d.ts +8 -0
- package/dist/serverManager.d.ts.map +1 -0
- package/dist/serverManager.js +138 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/watch.d.ts +2 -0
- package/dist/watch.d.ts.map +1 -0
- package/dist/watch.js +274 -0
- package/package.json +77 -0
@@ -0,0 +1,275 @@
|
|
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 formatters_exports = {};
|
30
|
+
__export(formatters_exports, {
|
31
|
+
NEWLINE: () => NEWLINE,
|
32
|
+
emojiLog: () => emojiLog,
|
33
|
+
formatBundleSize: () => formatBundleSize,
|
34
|
+
formatCustom: () => formatCustom,
|
35
|
+
formatData: () => formatData,
|
36
|
+
formatDate: () => formatDate,
|
37
|
+
formatErrorProp: () => formatErrorProp,
|
38
|
+
formatLevel: () => formatLevel,
|
39
|
+
formatLoadTime: () => formatLoadTime,
|
40
|
+
formatMessage: () => formatMessage,
|
41
|
+
formatMessageName: () => formatMessageName,
|
42
|
+
formatMethod: () => formatMethod,
|
43
|
+
formatName: () => formatName,
|
44
|
+
formatNs: () => formatNs,
|
45
|
+
formatOperationName: () => formatOperationName,
|
46
|
+
formatQuery: () => formatQuery,
|
47
|
+
formatRequestId: () => formatRequestId,
|
48
|
+
formatResponseCache: () => formatResponseCache,
|
49
|
+
formatStack: () => formatStack,
|
50
|
+
formatStatusCode: () => formatStatusCode,
|
51
|
+
formatTracing: () => formatTracing,
|
52
|
+
formatUrl: () => formatUrl,
|
53
|
+
formatUserAgent: () => formatUserAgent,
|
54
|
+
ignoredCustomData: () => ignoredCustomData,
|
55
|
+
isEmptyObject: () => isEmptyObject,
|
56
|
+
isObject: () => isObject,
|
57
|
+
isPinoLog: () => isPinoLog,
|
58
|
+
isWideEmoji: () => isWideEmoji,
|
59
|
+
noEmpty: () => noEmpty
|
60
|
+
});
|
61
|
+
module.exports = __toCommonJS(formatters_exports);
|
62
|
+
var import_chalk = __toESM(require("chalk"));
|
63
|
+
var import_pretty_bytes = __toESM(require("pretty-bytes"));
|
64
|
+
var import_pretty_ms = __toESM(require("pretty-ms"));
|
65
|
+
const NEWLINE = "\n";
|
66
|
+
const emojiLog = {
|
67
|
+
warn: "\u{1F6A6}",
|
68
|
+
info: "\u{1F332}",
|
69
|
+
error: "\u{1F6A8}",
|
70
|
+
debug: "\u{1F41B}",
|
71
|
+
fatal: "\u{1F480}",
|
72
|
+
trace: "\u{1F9F5}"
|
73
|
+
};
|
74
|
+
const ignoredCustomData = [
|
75
|
+
"time",
|
76
|
+
"pid",
|
77
|
+
"hostname",
|
78
|
+
"msg",
|
79
|
+
"res",
|
80
|
+
"req",
|
81
|
+
"reqId",
|
82
|
+
"responseTime"
|
83
|
+
];
|
84
|
+
const isObject = (object) => {
|
85
|
+
return object && Object.prototype.toString.apply(object) === "[object Object]";
|
86
|
+
};
|
87
|
+
const isEmptyObject = (object) => {
|
88
|
+
return object && !Object.keys(object).length;
|
89
|
+
};
|
90
|
+
const isPinoLog = (log) => {
|
91
|
+
return log && Object.prototype.hasOwnProperty.call(log, "level");
|
92
|
+
};
|
93
|
+
const isWideEmoji = (character) => {
|
94
|
+
return character !== "\u{1F6A6}";
|
95
|
+
};
|
96
|
+
const formatBundleSize = (bundle) => {
|
97
|
+
const bytes = parseInt(bundle, 10);
|
98
|
+
const size = (0, import_pretty_bytes.default)(bytes).replace(/ /, "");
|
99
|
+
return import_chalk.default.gray(size);
|
100
|
+
};
|
101
|
+
const formatCustom = (query) => {
|
102
|
+
if (!query) {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
ignoredCustomData.forEach((key) => {
|
106
|
+
delete query[key];
|
107
|
+
});
|
108
|
+
if (!isEmptyObject(query)) {
|
109
|
+
return import_chalk.default.white(
|
110
|
+
NEWLINE + "\u{1F5D2} Custom" + NEWLINE + JSON.stringify(query, null, 2)
|
111
|
+
);
|
112
|
+
}
|
113
|
+
return;
|
114
|
+
};
|
115
|
+
const formatData = (data) => {
|
116
|
+
if (!isEmptyObject(data)) {
|
117
|
+
return import_chalk.default.white(
|
118
|
+
NEWLINE + "\u{1F4E6} Result Data" + NEWLINE + JSON.stringify(data, null, 2)
|
119
|
+
);
|
120
|
+
}
|
121
|
+
return;
|
122
|
+
};
|
123
|
+
const formatDate = (instant) => {
|
124
|
+
const date = new Date(instant);
|
125
|
+
const hours = date.getHours().toString().padStart(2, "0");
|
126
|
+
const minutes = date.getMinutes().toString().padStart(2, "0");
|
127
|
+
const seconds = date.getSeconds().toString().padStart(2, "0");
|
128
|
+
const prettyDate = hours + ":" + minutes + ":" + seconds;
|
129
|
+
return import_chalk.default.gray(prettyDate);
|
130
|
+
};
|
131
|
+
const formatErrorProp = (errorPropValue) => {
|
132
|
+
const errorType = errorPropValue["type"] || "Error";
|
133
|
+
delete errorPropValue["message"];
|
134
|
+
delete errorPropValue["stack"];
|
135
|
+
delete errorPropValue["type"];
|
136
|
+
return import_chalk.default.redBright(
|
137
|
+
NEWLINE + NEWLINE + `\u{1F6A8} ${errorType} Info` + NEWLINE + NEWLINE + JSON.stringify(errorPropValue, null, 2) + NEWLINE
|
138
|
+
);
|
139
|
+
};
|
140
|
+
const formatLevel = (level) => {
|
141
|
+
const emoji = emojiLog[level];
|
142
|
+
const padding = isWideEmoji(emoji) ? "" : " ";
|
143
|
+
return emoji + padding;
|
144
|
+
};
|
145
|
+
const formatLoadTime = (elapsedTime) => {
|
146
|
+
const elapsed = parseInt(elapsedTime, 10);
|
147
|
+
const time = (0, import_pretty_ms.default)(elapsed);
|
148
|
+
return import_chalk.default.gray(time);
|
149
|
+
};
|
150
|
+
const formatMessage = (logData) => {
|
151
|
+
const { level, message } = logData;
|
152
|
+
const msg = formatMessageName(message);
|
153
|
+
let pretty;
|
154
|
+
if (level === "error") {
|
155
|
+
pretty = import_chalk.default.red(msg);
|
156
|
+
}
|
157
|
+
if (level === "trace") {
|
158
|
+
pretty = import_chalk.default.white(msg);
|
159
|
+
}
|
160
|
+
if (level === "warn") {
|
161
|
+
const orange = "#ffa500";
|
162
|
+
pretty = import_chalk.default.hex(orange)(msg);
|
163
|
+
}
|
164
|
+
if (level === "debug") {
|
165
|
+
pretty = import_chalk.default.yellow(msg);
|
166
|
+
}
|
167
|
+
if (level === "info" || level === "customlevel") {
|
168
|
+
pretty = import_chalk.default.green(msg);
|
169
|
+
}
|
170
|
+
if (level === "fatal") {
|
171
|
+
pretty = import_chalk.default.white.bgRed(msg);
|
172
|
+
}
|
173
|
+
return pretty;
|
174
|
+
};
|
175
|
+
const formatMethod = (method) => {
|
176
|
+
return method && import_chalk.default.white(method);
|
177
|
+
};
|
178
|
+
const formatRequestId = (requestId) => {
|
179
|
+
return requestId && import_chalk.default.cyan(requestId);
|
180
|
+
};
|
181
|
+
const formatNs = (ns) => {
|
182
|
+
return ns && import_chalk.default.cyan(ns);
|
183
|
+
};
|
184
|
+
const formatName = (name) => {
|
185
|
+
return name && import_chalk.default.blue(name);
|
186
|
+
};
|
187
|
+
const formatMessageName = (message) => {
|
188
|
+
if (message === void 0) {
|
189
|
+
return "";
|
190
|
+
}
|
191
|
+
if (message === "request") {
|
192
|
+
return "<--";
|
193
|
+
}
|
194
|
+
if (message === "response") {
|
195
|
+
return "-->";
|
196
|
+
}
|
197
|
+
return message;
|
198
|
+
};
|
199
|
+
const formatOperationName = (operationName) => {
|
200
|
+
return import_chalk.default.white(NEWLINE + "\u{1F3F7} " + operationName);
|
201
|
+
};
|
202
|
+
const formatQuery = (query) => {
|
203
|
+
if (!isEmptyObject(query)) {
|
204
|
+
return import_chalk.default.white(
|
205
|
+
NEWLINE + "\u{1F52D} Query" + NEWLINE + JSON.stringify(query, null, 2)
|
206
|
+
);
|
207
|
+
}
|
208
|
+
return;
|
209
|
+
};
|
210
|
+
const formatResponseCache = (responseCache) => {
|
211
|
+
if (!isEmptyObject(responseCache)) {
|
212
|
+
return import_chalk.default.white(
|
213
|
+
NEWLINE + "\u{1F4BE} Response Cache" + NEWLINE + JSON.stringify(responseCache, null, 2)
|
214
|
+
);
|
215
|
+
}
|
216
|
+
return;
|
217
|
+
};
|
218
|
+
const formatStatusCode = (statusCode) => {
|
219
|
+
statusCode = statusCode || "xxx";
|
220
|
+
return import_chalk.default.white(statusCode);
|
221
|
+
};
|
222
|
+
const formatStack = (stack) => {
|
223
|
+
return import_chalk.default.redBright(
|
224
|
+
stack ? NEWLINE + "\u{1F95E} Error Stack" + NEWLINE + NEWLINE + stack + NEWLINE : ""
|
225
|
+
);
|
226
|
+
};
|
227
|
+
const formatTracing = (data) => {
|
228
|
+
if (!isEmptyObject(data)) {
|
229
|
+
return import_chalk.default.white(
|
230
|
+
NEWLINE + "\u23F0 Timing" + NEWLINE + JSON.stringify(data, null, 2)
|
231
|
+
);
|
232
|
+
}
|
233
|
+
return;
|
234
|
+
};
|
235
|
+
const formatUrl = (url) => {
|
236
|
+
return import_chalk.default.white(url);
|
237
|
+
};
|
238
|
+
const formatUserAgent = (userAgent) => {
|
239
|
+
return import_chalk.default.grey(NEWLINE + "\u{1F575}\uFE0F\u200D\u2640\uFE0F " + userAgent);
|
240
|
+
};
|
241
|
+
const noEmpty = (value) => {
|
242
|
+
return !!value;
|
243
|
+
};
|
244
|
+
// Annotate the CommonJS export names for ESM import in node:
|
245
|
+
0 && (module.exports = {
|
246
|
+
NEWLINE,
|
247
|
+
emojiLog,
|
248
|
+
formatBundleSize,
|
249
|
+
formatCustom,
|
250
|
+
formatData,
|
251
|
+
formatDate,
|
252
|
+
formatErrorProp,
|
253
|
+
formatLevel,
|
254
|
+
formatLoadTime,
|
255
|
+
formatMessage,
|
256
|
+
formatMessageName,
|
257
|
+
formatMethod,
|
258
|
+
formatName,
|
259
|
+
formatNs,
|
260
|
+
formatOperationName,
|
261
|
+
formatQuery,
|
262
|
+
formatRequestId,
|
263
|
+
formatResponseCache,
|
264
|
+
formatStack,
|
265
|
+
formatStatusCode,
|
266
|
+
formatTracing,
|
267
|
+
formatUrl,
|
268
|
+
formatUserAgent,
|
269
|
+
ignoredCustomData,
|
270
|
+
isEmptyObject,
|
271
|
+
isObject,
|
272
|
+
isPinoLog,
|
273
|
+
isWideEmoji,
|
274
|
+
noEmpty
|
275
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logFormatter/index.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,YAAY,oBACG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WA0L3D,CAAA"}
|
@@ -0,0 +1,184 @@
|
|
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 logFormatter_exports = {};
|
30
|
+
__export(logFormatter_exports, {
|
31
|
+
LogFormatter: () => LogFormatter
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(logFormatter_exports);
|
34
|
+
var import_fast_json_parse = __toESM(require("fast-json-parse"));
|
35
|
+
var import_formatters = require("./formatters");
|
36
|
+
const LogFormatter = () => {
|
37
|
+
const parse = (inputData) => {
|
38
|
+
let logData;
|
39
|
+
if (typeof inputData === "string") {
|
40
|
+
const parsedData = (0, import_fast_json_parse.default)(inputData);
|
41
|
+
if (!parsedData.value || parsedData.err || !(0, import_formatters.isPinoLog)(parsedData.value)) {
|
42
|
+
return inputData + import_formatters.NEWLINE;
|
43
|
+
}
|
44
|
+
logData = parsedData.value;
|
45
|
+
} else if ((0, import_formatters.isObject)(inputData) && (0, import_formatters.isPinoLog)(inputData)) {
|
46
|
+
logData = inputData;
|
47
|
+
} else {
|
48
|
+
return inputData + import_formatters.NEWLINE;
|
49
|
+
}
|
50
|
+
if (!logData.level) {
|
51
|
+
return inputData + import_formatters.NEWLINE;
|
52
|
+
}
|
53
|
+
if (!logData.message) {
|
54
|
+
logData.message = logData.msg;
|
55
|
+
}
|
56
|
+
if (typeof logData.level === "number") {
|
57
|
+
convertLogNumber(logData);
|
58
|
+
}
|
59
|
+
return output(logData) + import_formatters.NEWLINE;
|
60
|
+
};
|
61
|
+
const convertLogNumber = (logData) => {
|
62
|
+
if (logData.level === 10) {
|
63
|
+
logData.level = "trace";
|
64
|
+
}
|
65
|
+
if (logData.level === 20) {
|
66
|
+
logData.level = "debug";
|
67
|
+
}
|
68
|
+
if (logData.level === 30) {
|
69
|
+
logData.level = "info";
|
70
|
+
}
|
71
|
+
if (logData.level === 40) {
|
72
|
+
logData.level = "warn";
|
73
|
+
}
|
74
|
+
if (logData.level === 50) {
|
75
|
+
logData.level = "error";
|
76
|
+
}
|
77
|
+
if (logData.level === 60) {
|
78
|
+
logData.level = "fatal";
|
79
|
+
}
|
80
|
+
};
|
81
|
+
const output = (logData) => {
|
82
|
+
const output2 = [];
|
83
|
+
output2.push((0, import_formatters.formatDate)(logData.time || Date.now()));
|
84
|
+
output2.push((0, import_formatters.formatLevel)(logData.level));
|
85
|
+
output2.push((0, import_formatters.formatNs)(logData.ns));
|
86
|
+
output2.push((0, import_formatters.formatName)(logData.name));
|
87
|
+
output2.push((0, import_formatters.formatRequestId)(logData.requestId));
|
88
|
+
output2.push((0, import_formatters.formatMessage)(logData));
|
89
|
+
const req = logData.req;
|
90
|
+
const res = logData.res;
|
91
|
+
const { statusCode: responseStatusCode } = res || {};
|
92
|
+
const { method: requestMethod, url: requestUrl } = req || {};
|
93
|
+
const {
|
94
|
+
level,
|
95
|
+
message,
|
96
|
+
name,
|
97
|
+
ns,
|
98
|
+
err: logDataErr,
|
99
|
+
stack: logDataStack,
|
100
|
+
statusCode: logDataStatusCode,
|
101
|
+
elapsed,
|
102
|
+
responseTime: logDataResponseTime,
|
103
|
+
method: logDataMethod,
|
104
|
+
custom,
|
105
|
+
contentLength,
|
106
|
+
operationName,
|
107
|
+
query,
|
108
|
+
data: graphQLData,
|
109
|
+
responseCache,
|
110
|
+
tracing,
|
111
|
+
url: logDataUrl,
|
112
|
+
userAgent,
|
113
|
+
...rest
|
114
|
+
} = logData;
|
115
|
+
const statusCode = responseStatusCode || logDataStatusCode;
|
116
|
+
const responseTime = logDataResponseTime || elapsed;
|
117
|
+
const method = requestMethod || logDataMethod;
|
118
|
+
const url = requestUrl || logDataUrl;
|
119
|
+
const logDataErrStack = logDataErr && logDataErr.stack;
|
120
|
+
const stack = level === "fatal" || level === "error" ? logDataStack || logDataErr && logDataErrStack : null;
|
121
|
+
const err = (level === "fatal" || level === "error") && logDataErr && Object.keys(logDataErr).find((key) => key !== "stack") ? logDataErr : null;
|
122
|
+
if (!message) {
|
123
|
+
logData.message = "";
|
124
|
+
}
|
125
|
+
if (!level) {
|
126
|
+
logData.level = "customlevel";
|
127
|
+
}
|
128
|
+
if (!name) {
|
129
|
+
logData.name = "";
|
130
|
+
}
|
131
|
+
if (!ns) {
|
132
|
+
logData.ns = "";
|
133
|
+
}
|
134
|
+
if (method != null) {
|
135
|
+
output2.push((0, import_formatters.formatMethod)(method));
|
136
|
+
output2.push((0, import_formatters.formatStatusCode)(statusCode));
|
137
|
+
}
|
138
|
+
if (url != null) {
|
139
|
+
output2.push((0, import_formatters.formatUrl)(url));
|
140
|
+
}
|
141
|
+
if (contentLength != null) {
|
142
|
+
output2.push((0, import_formatters.formatBundleSize)(contentLength));
|
143
|
+
}
|
144
|
+
if (custom) {
|
145
|
+
output2.push((0, import_formatters.formatCustom)(custom));
|
146
|
+
}
|
147
|
+
if (responseTime != null) {
|
148
|
+
output2.push((0, import_formatters.formatLoadTime)(responseTime));
|
149
|
+
}
|
150
|
+
if (userAgent != null) {
|
151
|
+
output2.push((0, import_formatters.formatUserAgent)(userAgent));
|
152
|
+
}
|
153
|
+
if (operationName != null) {
|
154
|
+
output2.push((0, import_formatters.formatOperationName)(operationName));
|
155
|
+
}
|
156
|
+
if (query != null) {
|
157
|
+
output2.push((0, import_formatters.formatQuery)(query));
|
158
|
+
}
|
159
|
+
if (graphQLData != null) {
|
160
|
+
output2.push((0, import_formatters.formatData)(graphQLData));
|
161
|
+
}
|
162
|
+
if (responseCache != null) {
|
163
|
+
output2.push((0, import_formatters.formatResponseCache)(responseCache));
|
164
|
+
}
|
165
|
+
if (tracing != null) {
|
166
|
+
output2.push((0, import_formatters.formatTracing)(tracing));
|
167
|
+
}
|
168
|
+
if (err != null) {
|
169
|
+
output2.push((0, import_formatters.formatErrorProp)(err));
|
170
|
+
}
|
171
|
+
if (stack != null) {
|
172
|
+
output2.push((0, import_formatters.formatStack)(stack));
|
173
|
+
}
|
174
|
+
if (rest) {
|
175
|
+
output2.push((0, import_formatters.formatCustom)(rest));
|
176
|
+
}
|
177
|
+
return output2.filter(import_formatters.noEmpty).join(" ");
|
178
|
+
};
|
179
|
+
return parse;
|
180
|
+
};
|
181
|
+
// Annotate the CommonJS export names for ESM import in node:
|
182
|
+
0 && (module.exports = {
|
183
|
+
LogFormatter
|
184
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { Options as FastGlobOptions } from 'fast-glob';
|
2
|
+
import type { FastifyInstance } from 'fastify';
|
3
|
+
import type { Server } from '../createServerHelpers';
|
4
|
+
export interface RedwoodFastifyAPIOptions {
|
5
|
+
redwood: {
|
6
|
+
apiRootPath?: string;
|
7
|
+
fastGlobOptions?: FastGlobOptions;
|
8
|
+
loadUserConfig?: boolean;
|
9
|
+
configureServer?: (server: Server) => void | Promise<void>;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
export declare function redwoodFastifyAPI(fastify: FastifyInstance, opts: RedwoodFastifyAPIOptions): Promise<void>;
|
13
|
+
//# sourceMappingURL=api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/plugins/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAC3D,CAAA;CACF;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,wBAAwB,iBA2C/B"}
|
@@ -0,0 +1,77 @@
|
|
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 api_exports = {};
|
30
|
+
__export(api_exports, {
|
31
|
+
redwoodFastifyAPI: () => redwoodFastifyAPI
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(api_exports);
|
34
|
+
var import_url_data = __toESM(require("@fastify/url-data"));
|
35
|
+
var import_fastify_raw_body = __toESM(require("fastify-raw-body"));
|
36
|
+
var import_store = require("@redmix/context/dist/store");
|
37
|
+
var import_helpers = require("@redmix/fastify-web/dist/helpers");
|
38
|
+
var import_fastify = require("../fastify");
|
39
|
+
var import_lambdaLoader = require("./lambdaLoader");
|
40
|
+
async function redwoodFastifyAPI(fastify, opts) {
|
41
|
+
const redwoodOptions = opts.redwood ?? {};
|
42
|
+
redwoodOptions.apiRootPath ??= "/";
|
43
|
+
redwoodOptions.apiRootPath = (0, import_helpers.coerceRootPath)(redwoodOptions.apiRootPath);
|
44
|
+
redwoodOptions.fastGlobOptions ??= {};
|
45
|
+
redwoodOptions.loadUserConfig ??= false;
|
46
|
+
fastify.register(import_url_data.default);
|
47
|
+
await fastify.register(import_fastify_raw_body.default);
|
48
|
+
fastify.addHook("onRequest", (_req, _reply, done) => {
|
49
|
+
(0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
|
50
|
+
});
|
51
|
+
fastify.addContentTypeParser(
|
52
|
+
["application/x-www-form-urlencoded", "multipart/form-data"],
|
53
|
+
{ parseAs: "string" },
|
54
|
+
fastify.defaultTextParser
|
55
|
+
);
|
56
|
+
if (redwoodOptions.loadUserConfig) {
|
57
|
+
const { configureFastify } = await (0, import_fastify.loadFastifyConfig)();
|
58
|
+
if (configureFastify) {
|
59
|
+
await configureFastify(fastify, {
|
60
|
+
side: "api",
|
61
|
+
apiRootPath: redwoodOptions.apiRootPath
|
62
|
+
});
|
63
|
+
}
|
64
|
+
}
|
65
|
+
if (redwoodOptions.configureServer) {
|
66
|
+
await redwoodOptions.configureServer(fastify);
|
67
|
+
}
|
68
|
+
fastify.all(`${redwoodOptions.apiRootPath}:routeName`, import_lambdaLoader.lambdaRequestHandler);
|
69
|
+
fastify.all(`${redwoodOptions.apiRootPath}:routeName/*`, import_lambdaLoader.lambdaRequestHandler);
|
70
|
+
await (0, import_lambdaLoader.loadFunctionsFromDist)({
|
71
|
+
fastGlobOptions: redwoodOptions.fastGlobOptions
|
72
|
+
});
|
73
|
+
}
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
75
|
+
0 && (module.exports = {
|
76
|
+
redwoodFastifyAPI
|
77
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
2
|
+
import type { GraphQLYogaOptions } from '@redmix/graphql-server';
|
3
|
+
export interface RedwoodFastifyGraphQLOptions {
|
4
|
+
redwood: {
|
5
|
+
apiRootPath?: string;
|
6
|
+
graphql?: GraphQLYogaOptions;
|
7
|
+
};
|
8
|
+
}
|
9
|
+
export declare function redwoodFastifyGraphQLServer(fastify: FastifyInstance, options: RedwoodFastifyGraphQLOptions): Promise<void>;
|
10
|
+
//# sourceMappingURL=graphql.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,SAAS,CAAA;AAMhB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAKhE,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,kBAAkB,CAAA;KAC7B,CAAA;CACF;AAED,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,4BAA4B,iBAoGtC"}
|
@@ -0,0 +1,115 @@
|
|
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 graphql_exports = {};
|
30
|
+
__export(graphql_exports, {
|
31
|
+
redwoodFastifyGraphQLServer: () => redwoodFastifyGraphQLServer
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(graphql_exports);
|
34
|
+
var import_multipart = __toESM(require("@fastify/multipart"));
|
35
|
+
var import_url_data = __toESM(require("@fastify/url-data"));
|
36
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
37
|
+
var import_store = require("@redmix/context/dist/store");
|
38
|
+
var import_helpers = require("@redmix/fastify-web/dist/helpers");
|
39
|
+
var import_graphql_server = require("@redmix/graphql-server");
|
40
|
+
var import_project_config = require("@redmix/project-config");
|
41
|
+
var import_awsLambdaFastify = require("../requestHandlers/awsLambdaFastify");
|
42
|
+
async function redwoodFastifyGraphQLServer(fastify, options) {
|
43
|
+
const redwoodOptions = options.redwood ?? {};
|
44
|
+
redwoodOptions.apiRootPath ??= "/";
|
45
|
+
redwoodOptions.apiRootPath = (0, import_helpers.coerceRootPath)(redwoodOptions.apiRootPath);
|
46
|
+
fastify.register(import_url_data.default);
|
47
|
+
fastify.register(import_multipart.default);
|
48
|
+
const method = ["GET", "POST", "OPTIONS"];
|
49
|
+
fastify.addHook("onRequest", (_req, _reply, done) => {
|
50
|
+
(0, import_store.getAsyncStoreInstance)().run(/* @__PURE__ */ new Map(), done);
|
51
|
+
});
|
52
|
+
try {
|
53
|
+
if (!redwoodOptions.graphql) {
|
54
|
+
const [graphqlFunctionPath] = await (0, import_fast_glob.default)("dist/functions/graphql.{ts,js}", {
|
55
|
+
cwd: (0, import_project_config.getPaths)().api.base,
|
56
|
+
absolute: true
|
57
|
+
});
|
58
|
+
const { __rw_graphqlOptions } = await import(`file://${graphqlFunctionPath}`);
|
59
|
+
redwoodOptions.graphql = __rw_graphqlOptions;
|
60
|
+
}
|
61
|
+
const graphqlOptions = redwoodOptions.graphql;
|
62
|
+
if (graphqlOptions?.realtime) {
|
63
|
+
const { useRedwoodRealtime } = await import("@redmix/realtime");
|
64
|
+
const originalExtraPlugins = graphqlOptions.extraPlugins ?? [];
|
65
|
+
originalExtraPlugins.push(useRedwoodRealtime(graphqlOptions.realtime));
|
66
|
+
graphqlOptions.extraPlugins = originalExtraPlugins;
|
67
|
+
if (graphqlOptions.realtime.subscriptions) {
|
68
|
+
method.push("PUT");
|
69
|
+
}
|
70
|
+
}
|
71
|
+
const { yoga } = (0, import_graphql_server.createGraphQLYoga)(graphqlOptions);
|
72
|
+
const graphQLYogaHandler = async (req, reply) => {
|
73
|
+
const response = await yoga.handleNodeRequest(req, {
|
74
|
+
req,
|
75
|
+
reply,
|
76
|
+
event: (0, import_awsLambdaFastify.lambdaEventForFastifyRequest)(req),
|
77
|
+
requestContext: {}
|
78
|
+
});
|
79
|
+
for (const [name, value] of response.headers) {
|
80
|
+
reply.header(name, value);
|
81
|
+
}
|
82
|
+
reply.status(response.status);
|
83
|
+
reply.send(response.body);
|
84
|
+
return reply;
|
85
|
+
};
|
86
|
+
const graphqlEndpoint = trimSlashes(yoga.graphqlEndpoint);
|
87
|
+
const routePaths = ["", "/health", "/readiness", "/stream"];
|
88
|
+
for (const routePath of routePaths) {
|
89
|
+
fastify.route({
|
90
|
+
url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
|
91
|
+
method,
|
92
|
+
handler: (req, reply) => graphQLYogaHandler(req, reply)
|
93
|
+
});
|
94
|
+
}
|
95
|
+
fastify.addHook("onReady", (done) => {
|
96
|
+
console.info(`GraphQL Yoga Server endpoint at ${graphqlEndpoint}`);
|
97
|
+
console.info(
|
98
|
+
`GraphQL Yoga Server Health Check endpoint at ${graphqlEndpoint}/health`
|
99
|
+
);
|
100
|
+
console.info(
|
101
|
+
`GraphQL Yoga Server Readiness endpoint at ${graphqlEndpoint}/readiness`
|
102
|
+
);
|
103
|
+
done();
|
104
|
+
});
|
105
|
+
} catch (e) {
|
106
|
+
console.log(e);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
function trimSlashes(path) {
|
110
|
+
return path.replace(/^\/|\/$/g, "");
|
111
|
+
}
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
113
|
+
0 && (module.exports = {
|
114
|
+
redwoodFastifyGraphQLServer
|
115
|
+
});
|