equipped 5.3.0-alpha.0 → 5.3.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/CHANGELOG.md +14 -0
- package/dist/cjs/server/adapters/express/index.cjs +312 -4
- package/dist/cjs/server/adapters/express/index.cjs.map +1 -1
- package/dist/cjs/server/adapters/express/index.min.cjs +7 -7
- package/dist/cjs/server/adapters/express/index.min.cjs.map +1 -1
- package/dist/cjs/server/adapters/fastify/index.cjs +315 -4
- package/dist/cjs/server/adapters/fastify/index.cjs.map +1 -1
- package/dist/cjs/server/adapters/fastify/index.min.cjs +7 -7
- package/dist/cjs/server/adapters/fastify/index.min.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +261 -4
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/cjs/server/index.min.cjs +7 -7
- package/dist/cjs/server/index.min.cjs.map +1 -1
- package/dist/esm/cache/adapters/in-memory/index.min.mjs +1 -1
- package/dist/esm/cache/adapters/in-memory/index.mjs +2 -2
- package/dist/esm/cache/adapters/redis/index.min.mjs +1 -1
- package/dist/esm/cache/adapters/redis/index.mjs +3 -3
- package/dist/esm/cache/index.min.mjs +1 -1
- package/dist/esm/cache/index.mjs +2 -2
- package/dist/esm/{chunk-AUKXL4EA.min.mjs → chunk-2GGMLKRP.min.mjs} +2 -2
- package/dist/esm/{chunk-TWKHVLLT.mjs → chunk-3TP7NINX.mjs} +2 -2
- package/dist/esm/{chunk-RIRBNBTC.mjs → chunk-5PZACGPI.mjs} +3 -3
- package/dist/esm/{chunk-OXI6IKAM.min.mjs → chunk-676VIABN.min.mjs} +2 -2
- package/dist/esm/{chunk-I4BB436E.mjs → chunk-7CP7ZE2O.mjs} +2 -2
- package/dist/esm/{chunk-YTM6ZURZ.min.mjs → chunk-7NF7PV6S.min.mjs} +2 -2
- package/dist/esm/{chunk-WHIWTP2Z.min.mjs → chunk-7SQ5JQYR.min.mjs} +2 -2
- package/dist/esm/{chunk-2TCFNKRZ.mjs → chunk-A4P7P6BU.mjs} +262 -5
- package/dist/esm/chunk-A4P7P6BU.mjs.map +1 -0
- package/dist/esm/{chunk-KW3PBDFD.mjs → chunk-BWUFPMVG.mjs} +2 -2
- package/dist/esm/{chunk-YTHRK2PO.mjs → chunk-HXFNN6RI.mjs} +3 -3
- package/dist/esm/chunk-IN5YKIJ7.min.mjs +32 -0
- package/dist/esm/chunk-IN5YKIJ7.min.mjs.map +1 -0
- package/dist/esm/{chunk-ECBJ3NT3.min.mjs → chunk-IRYCN6PI.min.mjs} +2 -2
- package/dist/esm/{chunk-IEBC3OWN.mjs → chunk-LKS5ZE45.mjs} +2 -2
- package/dist/esm/{chunk-6DW4GW3R.min.mjs → chunk-MQXTTWPS.min.mjs} +2 -2
- package/dist/esm/{chunk-MYGAF2AC.min.mjs → chunk-P4PRHHIY.min.mjs} +2 -2
- package/dist/esm/{chunk-6SB5M4XH.mjs → chunk-TSVHZZE4.mjs} +3 -3
- package/dist/esm/dbs/adapters/mongodb/index.min.mjs +1 -1
- package/dist/esm/dbs/adapters/mongodb/index.mjs +3 -3
- package/dist/esm/dbs/index.min.mjs +1 -1
- package/dist/esm/dbs/index.mjs +3 -3
- package/dist/esm/errors/index.min.mjs +1 -1
- package/dist/esm/errors/index.mjs +1 -1
- package/dist/esm/events/adapters/kafka/index.min.mjs +1 -1
- package/dist/esm/events/adapters/kafka/index.mjs +2 -2
- package/dist/esm/events/adapters/rabbitmq/index.min.mjs +1 -1
- package/dist/esm/events/adapters/rabbitmq/index.mjs +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/instance/index.min.mjs +1 -1
- package/dist/esm/instance/index.mjs +1 -1
- package/dist/esm/introspection-THKMXV5V.min.mjs +2 -0
- package/dist/esm/{introspection-Y7EXSYPD.mjs → introspection-YJF3QAUK.mjs} +3 -3
- package/dist/esm/jobs/adapters/redis/index.min.mjs +1 -1
- package/dist/esm/jobs/adapters/redis/index.mjs +3 -3
- package/dist/esm/orm/adapters/in-memory/index.min.mjs +1 -1
- package/dist/esm/orm/adapters/in-memory/index.mjs +3 -3
- package/dist/esm/orm/adapters/json/index.min.mjs +1 -1
- package/dist/esm/orm/adapters/json/index.mjs +3 -3
- package/dist/esm/orm/adapters/mongodb/index.min.mjs +1 -1
- package/dist/esm/orm/adapters/mongodb/index.mjs +2 -2
- package/dist/esm/orm/adapters/postgresql/index.min.mjs +2 -2
- package/dist/esm/orm/adapters/postgresql/index.mjs +3 -3
- package/dist/esm/orm/index.min.mjs +1 -1
- package/dist/esm/orm/index.mjs +3 -3
- package/dist/esm/server/adapters/express/index.min.mjs +1 -1
- package/dist/esm/server/adapters/express/index.min.mjs.map +1 -1
- package/dist/esm/server/adapters/express/index.mjs +52 -1
- package/dist/esm/server/adapters/express/index.mjs.map +1 -1
- package/dist/esm/server/adapters/fastify/index.min.mjs +1 -1
- package/dist/esm/server/adapters/fastify/index.min.mjs.map +1 -1
- package/dist/esm/server/adapters/fastify/index.mjs +55 -1
- package/dist/esm/server/adapters/fastify/index.mjs.map +1 -1
- package/dist/esm/server/index.min.mjs +1 -1
- package/dist/esm/server/index.mjs +1 -1
- package/dist/esm/utilities/index.min.mjs +1 -1
- package/dist/esm/utilities/index.mjs +1 -1
- package/dist/esm/validations/index.min.mjs +1 -1
- package/dist/esm/validations/index.mjs +1 -1
- package/dist/types/{base-3PpBAx1K.d.ts → base-BDTBLZ9a.d.ts} +26 -2
- package/dist/types/cache/adapters/in-memory/index.js +2 -2
- package/dist/types/cache/adapters/redis/index.js +3 -3
- package/dist/types/cache/index.js +2 -2
- package/dist/types/{chunk-H6JBLKX5.js → chunk-4DH3POYM.js} +2 -2
- package/dist/types/{chunk-XOU2A2Y6.js → chunk-55CTVK7R.js} +1 -1
- package/dist/types/{chunk-A2MRYMCA.js → chunk-5Z26ZURE.js} +1 -1
- package/dist/types/{chunk-JZ2JTENY.js → chunk-IZDJDGOV.js} +2 -2
- package/dist/types/{chunk-IAHTILKJ.js → chunk-J3TGB5YQ.js} +1 -1
- package/dist/types/{chunk-LWUMIHL4.js → chunk-LPB5LS7A.js} +1 -1
- package/dist/types/{chunk-32DMHN3G.js → chunk-TT5EORDK.js} +261 -4
- package/dist/types/{chunk-4LRJJSGG.js → chunk-YLJNBL6J.js} +2 -2
- package/dist/types/dbs/adapters/mongodb/index.js +3 -3
- package/dist/types/dbs/index.js +3 -3
- package/dist/types/errors/index.js +1 -1
- package/dist/types/events/adapters/kafka/index.js +2 -2
- package/dist/types/events/adapters/rabbitmq/index.js +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/instance/index.js +1 -1
- package/dist/types/{introspection-ZQCAW254.js → introspection-EHGM4RMO.js} +2 -2
- package/dist/types/jobs/adapters/redis/index.js +3 -3
- package/dist/types/orm/adapters/in-memory/index.js +3 -3
- package/dist/types/orm/adapters/json/index.js +3 -3
- package/dist/types/orm/adapters/mongodb/index.js +2 -2
- package/dist/types/orm/adapters/postgresql/index.js +3 -3
- package/dist/types/orm/index.js +3 -3
- package/dist/types/server/adapters/express/index.d.ts +3 -1
- package/dist/types/server/adapters/express/index.js +52 -1
- package/dist/types/server/adapters/fastify/index.d.ts +3 -1
- package/dist/types/server/adapters/fastify/index.js +55 -1
- package/dist/types/server/index.d.ts +2 -2
- package/dist/types/server/index.js +1 -1
- package/dist/types/utilities/index.js +1 -1
- package/dist/types/validations/index.js +1 -1
- package/package.json +2 -4
- package/dist/esm/chunk-2TCFNKRZ.mjs.map +0 -1
- package/dist/esm/chunk-LTDVZJYJ.min.mjs +0 -32
- package/dist/esm/chunk-LTDVZJYJ.min.mjs.map +0 -1
- package/dist/esm/introspection-GP3G26B6.min.mjs +0 -2
- /package/dist/esm/{chunk-AUKXL4EA.min.mjs.map → chunk-2GGMLKRP.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-TWKHVLLT.mjs.map → chunk-3TP7NINX.mjs.map} +0 -0
- /package/dist/esm/{chunk-RIRBNBTC.mjs.map → chunk-5PZACGPI.mjs.map} +0 -0
- /package/dist/esm/{chunk-OXI6IKAM.min.mjs.map → chunk-676VIABN.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-I4BB436E.mjs.map → chunk-7CP7ZE2O.mjs.map} +0 -0
- /package/dist/esm/{chunk-YTM6ZURZ.min.mjs.map → chunk-7NF7PV6S.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-WHIWTP2Z.min.mjs.map → chunk-7SQ5JQYR.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-KW3PBDFD.mjs.map → chunk-BWUFPMVG.mjs.map} +0 -0
- /package/dist/esm/{chunk-YTHRK2PO.mjs.map → chunk-HXFNN6RI.mjs.map} +0 -0
- /package/dist/esm/{chunk-ECBJ3NT3.min.mjs.map → chunk-IRYCN6PI.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-IEBC3OWN.mjs.map → chunk-LKS5ZE45.mjs.map} +0 -0
- /package/dist/esm/{chunk-6DW4GW3R.min.mjs.map → chunk-MQXTTWPS.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-MYGAF2AC.min.mjs.map → chunk-P4PRHHIY.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-6SB5M4XH.mjs.map → chunk-TSVHZZE4.mjs.map} +0 -0
- /package/dist/esm/{introspection-GP3G26B6.min.mjs.map → introspection-THKMXV5V.min.mjs.map} +0 -0
- /package/dist/esm/{introspection-Y7EXSYPD.mjs.map → introspection-YJF3QAUK.mjs.map} +0 -0
|
@@ -46,6 +46,7 @@ var RequestError = class extends EquippedError {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
// src/server/adapters/base.ts
|
|
49
|
+
import "http";
|
|
49
50
|
import "@fastify/cors";
|
|
50
51
|
import "cors";
|
|
51
52
|
import { Server as SocketServer } from "socket.io";
|
|
@@ -935,6 +936,22 @@ var serverConfigPipe = () => v3.object({
|
|
|
935
936
|
),
|
|
936
937
|
socketsAuthMethods: v3.defaults(v3.array(v3.instanceOf(BaseRequestAuthMethod)), [])
|
|
937
938
|
});
|
|
939
|
+
var rawResponseHandledSymbol = /* @__PURE__ */ Symbol("rawResponseHandled");
|
|
940
|
+
var rawResponseHandled = Object.freeze({ [rawResponseHandledSymbol]: true });
|
|
941
|
+
var rawResponseNotStartedMessage = "Raw not-found handler did not start or complete a response";
|
|
942
|
+
function isRawResponseHandled(input) {
|
|
943
|
+
return Boolean(input && typeof input === "object" && rawResponseHandledSymbol in input);
|
|
944
|
+
}
|
|
945
|
+
function hasRawResponseStarted(response) {
|
|
946
|
+
return response.headersSent || response.writableEnded;
|
|
947
|
+
}
|
|
948
|
+
function writeRawHandlerError(response, error) {
|
|
949
|
+
if (hasRawResponseStarted(response)) return;
|
|
950
|
+
response.statusCode = StatusCodes.BadRequest;
|
|
951
|
+
response.setHeader("Content-Type", "application/json");
|
|
952
|
+
const message = error instanceof Error ? error.message : `${error}`;
|
|
953
|
+
response.end(JSON.stringify([{ message }]));
|
|
954
|
+
}
|
|
938
955
|
var errorsSchemas = Object.entries(StatusCodes).filter(([, value]) => value > 399).map(([key, value]) => ({
|
|
939
956
|
status: value,
|
|
940
957
|
contentType: "application/json",
|
|
@@ -951,6 +968,9 @@ var Server = class {
|
|
|
951
968
|
#serverConfig;
|
|
952
969
|
#queue = [];
|
|
953
970
|
#routesByKey = /* @__PURE__ */ new Set();
|
|
971
|
+
#started = false;
|
|
972
|
+
#beforeListenHandlers = [];
|
|
973
|
+
#notFoundHandler = null;
|
|
954
974
|
setup(httpServer, config) {
|
|
955
975
|
this.#httpServer = httpServer;
|
|
956
976
|
this.#serverConfig = config;
|
|
@@ -1000,10 +1020,21 @@ var Server = class {
|
|
|
1000
1020
|
});
|
|
1001
1021
|
});
|
|
1002
1022
|
}
|
|
1023
|
+
setNotFoundHandler(handler) {
|
|
1024
|
+
if (this.#started) throw new EquippedError("Cannot set not-found handler after server has started", {});
|
|
1025
|
+
this.#notFoundHandler = handler;
|
|
1026
|
+
return this;
|
|
1027
|
+
}
|
|
1028
|
+
onBeforeListen(handler) {
|
|
1029
|
+
if (this.#started) throw new EquippedError("Cannot add before-listen handler after server has started", {});
|
|
1030
|
+
this.#beforeListenHandlers.push(handler);
|
|
1031
|
+
return this;
|
|
1032
|
+
}
|
|
1003
1033
|
test() {
|
|
1004
1034
|
return supertest(this.#httpServer);
|
|
1005
1035
|
}
|
|
1006
1036
|
async start() {
|
|
1037
|
+
this.#started = true;
|
|
1007
1038
|
const config = this.#serverConfig;
|
|
1008
1039
|
const instance = Instance.get();
|
|
1009
1040
|
const { app } = instance.settings;
|
|
@@ -1017,10 +1048,7 @@ var Server = class {
|
|
|
1017
1048
|
})
|
|
1018
1049
|
});
|
|
1019
1050
|
await Promise.all(this.#queue.map((cb) => cb()));
|
|
1020
|
-
this.registerNotFoundHandler(async (req) =>
|
|
1021
|
-
const request = await this.parseRequest(req);
|
|
1022
|
-
throw new NotFoundError(`Route ${request.path} not found`);
|
|
1023
|
-
});
|
|
1051
|
+
this.registerNotFoundHandler(async (req, res) => await this.#handleNotFound(req, res));
|
|
1024
1052
|
this.registerErrorHandler(async (error, _, res) => {
|
|
1025
1053
|
if (!(error instanceof EquippedError)) Instance.get().log.error({ error }, "Uncaught error in route handler");
|
|
1026
1054
|
const response = error instanceof RequestError ? new Response({
|
|
@@ -1035,10 +1063,36 @@ var Server = class {
|
|
|
1035
1063
|
});
|
|
1036
1064
|
return await this.handleResponse(res, response);
|
|
1037
1065
|
});
|
|
1066
|
+
for (const handler of this.#beforeListenHandlers) await handler({ httpServer: this.#httpServer, port: config.port });
|
|
1038
1067
|
const started = await this.startServer(config.port);
|
|
1039
1068
|
if (started) Instance.get().log.info(`${instance.id}(${app.name}) service listening on port ${config.port}`);
|
|
1040
1069
|
return started;
|
|
1041
1070
|
}
|
|
1071
|
+
createNodeRawResponder(input) {
|
|
1072
|
+
return async (handler) => {
|
|
1073
|
+
input.beforeHandle?.();
|
|
1074
|
+
try {
|
|
1075
|
+
await handler(input.request, input.response);
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
if (!hasRawResponseStarted(input.response)) {
|
|
1078
|
+
writeRawHandlerError(input.response, error);
|
|
1079
|
+
return rawResponseHandled;
|
|
1080
|
+
}
|
|
1081
|
+
throw error;
|
|
1082
|
+
}
|
|
1083
|
+
if (!hasRawResponseStarted(input.response))
|
|
1084
|
+
writeRawHandlerError(input.response, new EquippedError(rawResponseNotStartedMessage, {}));
|
|
1085
|
+
return rawResponseHandled;
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
async #handleNotFound(req, res) {
|
|
1089
|
+
const request = await this.parseRequest(req);
|
|
1090
|
+
if (!this.#notFoundHandler) throw new NotFoundError(`Route ${request.path} not found`);
|
|
1091
|
+
const result = await this.#notFoundHandler({ request, respondWithRaw: this.createRawResponder(req, res) });
|
|
1092
|
+
if (isRawResponseHandled(result)) return;
|
|
1093
|
+
if (result instanceof Response) return await this.handleResponse(res, result);
|
|
1094
|
+
throw new EquippedError("Not-found handler must return a Response or respondWithRaw(...)", {});
|
|
1095
|
+
}
|
|
1042
1096
|
#resolveSchema(method, schema) {
|
|
1043
1097
|
const defaultStatusCode = schema?.defaultStatusCode ?? StatusCodes.Ok;
|
|
1044
1098
|
const defaultContentType = schema?.defaultContentType ?? "application/json";
|
|
@@ -1129,6 +1183,209 @@ var Server = class {
|
|
|
1129
1183
|
};
|
|
1130
1184
|
}
|
|
1131
1185
|
};
|
|
1186
|
+
if (void 0) {
|
|
1187
|
+
let ensureTestInstance = function() {
|
|
1188
|
+
const instance = Instance.maybeGet() ?? Instance.create({ app: { name: "equipped-test" }, log: { level: "silent" } });
|
|
1189
|
+
if (!testInstanceState.__equippedTestInstanceAliased) {
|
|
1190
|
+
instance.alias("equipped-test");
|
|
1191
|
+
testInstanceState.__equippedTestInstanceAliased = true;
|
|
1192
|
+
}
|
|
1193
|
+
}, createRawResponse = function() {
|
|
1194
|
+
const chunks = [];
|
|
1195
|
+
return {
|
|
1196
|
+
statusCode: 200,
|
|
1197
|
+
headersSent: false,
|
|
1198
|
+
writableEnded: false,
|
|
1199
|
+
headers: {},
|
|
1200
|
+
setHeader(key, value) {
|
|
1201
|
+
this.headers[key] = value;
|
|
1202
|
+
},
|
|
1203
|
+
end(chunk) {
|
|
1204
|
+
if (chunk !== void 0) chunks.push(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
|
|
1205
|
+
this.headersSent = true;
|
|
1206
|
+
this.writableEnded = true;
|
|
1207
|
+
},
|
|
1208
|
+
body() {
|
|
1209
|
+
return chunks.join("");
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
};
|
|
1213
|
+
ensureTestInstance2 = ensureTestInstance, createRawResponse2 = createRawResponse;
|
|
1214
|
+
const { describe, expect, test } = void 0;
|
|
1215
|
+
const testInstanceState = globalThis;
|
|
1216
|
+
class TestServer extends Server {
|
|
1217
|
+
handledResponse = null;
|
|
1218
|
+
startedPorts = [];
|
|
1219
|
+
notFoundHandler = null;
|
|
1220
|
+
constructor() {
|
|
1221
|
+
super();
|
|
1222
|
+
this.setup(http.createServer(), {
|
|
1223
|
+
port: 0,
|
|
1224
|
+
cors: void 0,
|
|
1225
|
+
eventBus: void 0,
|
|
1226
|
+
publicPath: void 0,
|
|
1227
|
+
healthPath: void 0,
|
|
1228
|
+
openapi: { docsVersion: "1.0.0", docsBaseUrl: ["/"], docsPath: "/__docs" },
|
|
1229
|
+
requests: {
|
|
1230
|
+
log: false,
|
|
1231
|
+
rateLimit: { enabled: false, periodInMs: 1, limit: 1 },
|
|
1232
|
+
slowdown: { enabled: false, periodInMs: 1, delayAfter: 1, delayInMs: 1 }
|
|
1233
|
+
},
|
|
1234
|
+
socketsAuthMethods: []
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
async parseRequest(req) {
|
|
1238
|
+
return new Request2({
|
|
1239
|
+
ip: "127.0.0.1",
|
|
1240
|
+
body: {},
|
|
1241
|
+
cookies: {},
|
|
1242
|
+
params: {},
|
|
1243
|
+
query: {},
|
|
1244
|
+
method: Methods.get,
|
|
1245
|
+
path: req.path,
|
|
1246
|
+
headers: {},
|
|
1247
|
+
files: {}
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
async handleResponse(_, response) {
|
|
1251
|
+
this.handledResponse = response;
|
|
1252
|
+
}
|
|
1253
|
+
createRawResponder(req, res) {
|
|
1254
|
+
return this.createNodeRawResponder({ request: req.rawRequest, response: res.rawResponse });
|
|
1255
|
+
}
|
|
1256
|
+
registerRoute() {
|
|
1257
|
+
}
|
|
1258
|
+
registerErrorHandler() {
|
|
1259
|
+
}
|
|
1260
|
+
registerNotFoundHandler(cb) {
|
|
1261
|
+
this.notFoundHandler = cb;
|
|
1262
|
+
}
|
|
1263
|
+
async startServer(port) {
|
|
1264
|
+
this.startedPorts.push(port);
|
|
1265
|
+
return true;
|
|
1266
|
+
}
|
|
1267
|
+
async dispatchNotFound(path) {
|
|
1268
|
+
if (!this.notFoundHandler) throw new Error("not-found handler was not registered");
|
|
1269
|
+
this.handledResponse = null;
|
|
1270
|
+
const rawResponse = createRawResponse();
|
|
1271
|
+
await this.notFoundHandler({ path, rawRequest: {} }, { rawResponse });
|
|
1272
|
+
return { handledResponse: this.handledResponse, rawResponse };
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
describe("Server before-listen handlers", () => {
|
|
1276
|
+
test("runs before-listen handlers before adapter listen in registration order", async () => {
|
|
1277
|
+
ensureTestInstance();
|
|
1278
|
+
const server = new TestServer();
|
|
1279
|
+
const calls = [];
|
|
1280
|
+
let receivedServer = null;
|
|
1281
|
+
server.onBeforeListen(({ httpServer, port }) => {
|
|
1282
|
+
calls.push(`first:${port}`);
|
|
1283
|
+
receivedServer = httpServer;
|
|
1284
|
+
expect(server.startedPorts).toEqual([]);
|
|
1285
|
+
}).onBeforeListen(({ httpServer, port }) => {
|
|
1286
|
+
calls.push(`second:${port}`);
|
|
1287
|
+
expect(httpServer).toBe(receivedServer);
|
|
1288
|
+
expect(server.startedPorts).toEqual([]);
|
|
1289
|
+
});
|
|
1290
|
+
await server.start();
|
|
1291
|
+
expect(calls).toEqual(["first:0", "second:0"]);
|
|
1292
|
+
expect(receivedServer).toBeInstanceOf(http.Server);
|
|
1293
|
+
expect(server.startedPorts).toEqual([0]);
|
|
1294
|
+
});
|
|
1295
|
+
test("rejects startup when a before-listen handler fails before adapter listen", async () => {
|
|
1296
|
+
ensureTestInstance();
|
|
1297
|
+
const server = new TestServer();
|
|
1298
|
+
server.onBeforeListen(async () => {
|
|
1299
|
+
throw new Error("before-listen failed");
|
|
1300
|
+
});
|
|
1301
|
+
await expect(server.start()).rejects.toThrow("before-listen failed");
|
|
1302
|
+
expect(server.startedPorts).toEqual([]);
|
|
1303
|
+
});
|
|
1304
|
+
test("rejects adding before-listen handlers after server startup", async () => {
|
|
1305
|
+
ensureTestInstance();
|
|
1306
|
+
const server = new TestServer();
|
|
1307
|
+
await server.start();
|
|
1308
|
+
expect(() => server.onBeforeListen(() => {
|
|
1309
|
+
})).toThrow("Cannot add before-listen handler after server has started");
|
|
1310
|
+
});
|
|
1311
|
+
});
|
|
1312
|
+
describe("Server not-found handler", () => {
|
|
1313
|
+
test("throws the default Equipped not-found error when no custom handler is set", async () => {
|
|
1314
|
+
ensureTestInstance();
|
|
1315
|
+
const server = new TestServer();
|
|
1316
|
+
await server.start();
|
|
1317
|
+
await expect(server.dispatchNotFound("/missing")).rejects.toBeInstanceOf(NotFoundError);
|
|
1318
|
+
});
|
|
1319
|
+
test("allows a custom not-found handler to return an Equipped response", async () => {
|
|
1320
|
+
ensureTestInstance();
|
|
1321
|
+
const server = new TestServer();
|
|
1322
|
+
server.setNotFoundHandler(
|
|
1323
|
+
({ request }) => new Response({
|
|
1324
|
+
body: [{ message: `No route for ${request.path}` }],
|
|
1325
|
+
status: StatusCodes.NotFound,
|
|
1326
|
+
headers: {},
|
|
1327
|
+
cookies: {},
|
|
1328
|
+
contentType: "application/json"
|
|
1329
|
+
})
|
|
1330
|
+
);
|
|
1331
|
+
await server.start();
|
|
1332
|
+
const result = await server.dispatchNotFound("/custom");
|
|
1333
|
+
expect(result.handledResponse?.status).toBe(StatusCodes.NotFound);
|
|
1334
|
+
expect(result.handledResponse?.body).toEqual([{ message: "No route for /custom" }]);
|
|
1335
|
+
});
|
|
1336
|
+
test("allows a custom not-found handler to complete the response through a raw Node listener", async () => {
|
|
1337
|
+
ensureTestInstance();
|
|
1338
|
+
const server = new TestServer();
|
|
1339
|
+
server.setNotFoundHandler(
|
|
1340
|
+
({ respondWithRaw }) => respondWithRaw((_, response) => {
|
|
1341
|
+
response.statusCode = 203;
|
|
1342
|
+
response.end("raw fallback");
|
|
1343
|
+
})
|
|
1344
|
+
);
|
|
1345
|
+
await server.start();
|
|
1346
|
+
const result = await server.dispatchNotFound("/page");
|
|
1347
|
+
expect(result.handledResponse).toBeNull();
|
|
1348
|
+
expect(result.rawResponse.statusCode).toBe(203);
|
|
1349
|
+
expect(result.rawResponse.body()).toBe("raw fallback");
|
|
1350
|
+
});
|
|
1351
|
+
test("writes a clear raw error when a raw not-found handler does not start a response", async () => {
|
|
1352
|
+
ensureTestInstance();
|
|
1353
|
+
const server = new TestServer();
|
|
1354
|
+
server.setNotFoundHandler(({ respondWithRaw }) => respondWithRaw(() => {
|
|
1355
|
+
}));
|
|
1356
|
+
await server.start();
|
|
1357
|
+
const result = await server.dispatchNotFound("/page");
|
|
1358
|
+
expect(result.handledResponse).toBeNull();
|
|
1359
|
+
expect(result.rawResponse.statusCode).toBe(StatusCodes.BadRequest);
|
|
1360
|
+
expect(result.rawResponse.body()).toContain(rawResponseNotStartedMessage);
|
|
1361
|
+
});
|
|
1362
|
+
test("rejects a custom not-found handler result that is neither an Equipped response nor raw completion", async () => {
|
|
1363
|
+
ensureTestInstance();
|
|
1364
|
+
const server = new TestServer();
|
|
1365
|
+
server.setNotFoundHandler((() => void 0));
|
|
1366
|
+
await server.start();
|
|
1367
|
+
await expect(server.dispatchNotFound("/bad")).rejects.toThrow("Not-found handler must return a Response or respondWithRaw(...)");
|
|
1368
|
+
});
|
|
1369
|
+
test("rejects setting the custom not-found handler after server startup", async () => {
|
|
1370
|
+
ensureTestInstance();
|
|
1371
|
+
const server = new TestServer();
|
|
1372
|
+
await server.start();
|
|
1373
|
+
expect(
|
|
1374
|
+
() => server.setNotFoundHandler(
|
|
1375
|
+
() => new Response({
|
|
1376
|
+
body: null,
|
|
1377
|
+
status: StatusCodes.NotFound,
|
|
1378
|
+
headers: {},
|
|
1379
|
+
cookies: {},
|
|
1380
|
+
contentType: "application/json"
|
|
1381
|
+
})
|
|
1382
|
+
)
|
|
1383
|
+
).toThrow("Cannot set not-found handler after server has started");
|
|
1384
|
+
});
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
var ensureTestInstance2;
|
|
1388
|
+
var createRawResponse2;
|
|
1132
1389
|
|
|
1133
1390
|
// src/server/middlewares/requireAuthUser.ts
|
|
1134
1391
|
var requireAuthUser = (methods) => makeMiddleware(
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cache
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LPB5LS7A.js";
|
|
4
4
|
import {
|
|
5
5
|
EquippedError,
|
|
6
6
|
Instance,
|
|
7
7
|
configurable
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TT5EORDK.js";
|
|
9
9
|
|
|
10
10
|
// src/cache/adapters/redis/index.ts
|
|
11
11
|
import { Cluster, Redis } from "ioredis";
|
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
Db,
|
|
3
3
|
QueryKeys,
|
|
4
4
|
dbChangeConfigPipe
|
|
5
|
-
} from "../../../chunk-
|
|
6
|
-
import "../../../chunk-
|
|
5
|
+
} from "../../../chunk-IZDJDGOV.js";
|
|
6
|
+
import "../../../chunk-J3TGB5YQ.js";
|
|
7
7
|
import {
|
|
8
8
|
EquippedError,
|
|
9
9
|
Instance,
|
|
10
10
|
retry
|
|
11
|
-
} from "../../../chunk-
|
|
11
|
+
} from "../../../chunk-TT5EORDK.js";
|
|
12
12
|
import "../../../chunk-KZKFYO4V.js";
|
|
13
13
|
import "../../../chunk-MLKGABMK.js";
|
|
14
14
|
|
package/dist/types/dbs/index.js
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
queryParamsPipe,
|
|
7
7
|
queryResultsPipe,
|
|
8
8
|
wrapQueryParams
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-IZDJDGOV.js";
|
|
10
|
+
import "../chunk-J3TGB5YQ.js";
|
|
11
|
+
import "../chunk-TT5EORDK.js";
|
|
12
12
|
import "../chunk-KZKFYO4V.js";
|
|
13
13
|
import "../chunk-MLKGABMK.js";
|
|
14
14
|
export {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
KafkaEventBus,
|
|
3
3
|
kafkaConfigPipe
|
|
4
|
-
} from "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
4
|
+
} from "../../../chunk-J3TGB5YQ.js";
|
|
5
|
+
import "../../../chunk-TT5EORDK.js";
|
|
6
6
|
import "../../../chunk-KZKFYO4V.js";
|
|
7
7
|
import "../../../chunk-MLKGABMK.js";
|
|
8
8
|
export {
|
package/dist/types/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RedisCache,
|
|
3
3
|
redisConfigPipe
|
|
4
|
-
} from "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
4
|
+
} from "../../../chunk-YLJNBL6J.js";
|
|
5
|
+
import "../../../chunk-LPB5LS7A.js";
|
|
6
6
|
import {
|
|
7
7
|
Job
|
|
8
8
|
} from "../../../chunk-LN3A6R4Y.js";
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Instance,
|
|
11
11
|
configurable,
|
|
12
12
|
random_exports
|
|
13
|
-
} from "../../../chunk-
|
|
13
|
+
} from "../../../chunk-TT5EORDK.js";
|
|
14
14
|
import "../../../chunk-KZKFYO4V.js";
|
|
15
15
|
import "../../../chunk-MLKGABMK.js";
|
|
16
16
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InMemoryAdapter
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
3
|
+
} from "../../../chunk-4DH3POYM.js";
|
|
4
|
+
import "../../../chunk-5Z26ZURE.js";
|
|
5
|
+
import "../../../chunk-TT5EORDK.js";
|
|
6
6
|
import "../../../chunk-KZKFYO4V.js";
|
|
7
7
|
import "../../../chunk-MLKGABMK.js";
|
|
8
8
|
export {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InMemoryAdapter
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-4DH3POYM.js";
|
|
4
4
|
import {
|
|
5
5
|
OrmAdapter
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-5Z26ZURE.js";
|
|
7
7
|
import {
|
|
8
8
|
configurable
|
|
9
|
-
} from "../../../chunk-
|
|
9
|
+
} from "../../../chunk-TT5EORDK.js";
|
|
10
10
|
import "../../../chunk-KZKFYO4V.js";
|
|
11
11
|
import "../../../chunk-MLKGABMK.js";
|
|
12
12
|
|
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
PushOp,
|
|
12
12
|
UnsetOp,
|
|
13
13
|
flattenOps
|
|
14
|
-
} from "../../../chunk-
|
|
14
|
+
} from "../../../chunk-5Z26ZURE.js";
|
|
15
15
|
import {
|
|
16
16
|
EquippedError,
|
|
17
17
|
configurable
|
|
18
|
-
} from "../../../chunk-
|
|
18
|
+
} from "../../../chunk-TT5EORDK.js";
|
|
19
19
|
import "../../../chunk-KZKFYO4V.js";
|
|
20
20
|
import "../../../chunk-MLKGABMK.js";
|
|
21
21
|
|
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
PushOp,
|
|
13
13
|
UnsetOp,
|
|
14
14
|
flattenOps
|
|
15
|
-
} from "../../../chunk-
|
|
15
|
+
} from "../../../chunk-5Z26ZURE.js";
|
|
16
16
|
import {
|
|
17
17
|
EquippedError,
|
|
18
18
|
configurable
|
|
19
|
-
} from "../../../chunk-
|
|
19
|
+
} from "../../../chunk-TT5EORDK.js";
|
|
20
20
|
import "../../../chunk-KZKFYO4V.js";
|
|
21
21
|
import "../../../chunk-MLKGABMK.js";
|
|
22
22
|
|
|
@@ -1109,7 +1109,7 @@ var PostgresAdapter = class extends configurable(postgresqlConnectionPipe, OrmAd
|
|
|
1109
1109
|
await this.#getClient().query(`ALTER TABLE "${change.table}" DROP CONSTRAINT "${change.name}"`);
|
|
1110
1110
|
}
|
|
1111
1111
|
async introspect() {
|
|
1112
|
-
const { OrmIntrospectionError } = await import("../../../introspection-
|
|
1112
|
+
const { OrmIntrospectionError } = await import("../../../introspection-EHGM4RMO.js");
|
|
1113
1113
|
const client = this.#getClient();
|
|
1114
1114
|
const tablesResult = await client.query(`
|
|
1115
1115
|
SELECT table_name FROM information_schema.tables
|
package/dist/types/orm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OrmIntrospectionError
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-55CTVK7R.js";
|
|
4
4
|
import {
|
|
5
5
|
ComputedField,
|
|
6
6
|
Field,
|
|
@@ -33,11 +33,11 @@ import {
|
|
|
33
33
|
set,
|
|
34
34
|
toFieldName,
|
|
35
35
|
unset
|
|
36
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-5Z26ZURE.js";
|
|
37
37
|
import {
|
|
38
38
|
EquippedError,
|
|
39
39
|
Instance
|
|
40
|
-
} from "../chunk-
|
|
40
|
+
} from "../chunk-TT5EORDK.js";
|
|
41
41
|
import "../chunk-KZKFYO4V.js";
|
|
42
42
|
import "../chunk-MLKGABMK.js";
|
|
43
43
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { B as BaseRequestAuthMethod, S as Server } from '../../../base-
|
|
1
|
+
import { B as BaseRequestAuthMethod, S as Server, R as RawResponder } from '../../../base-BDTBLZ9a.js';
|
|
2
2
|
import { A as AuthUser } from '../../../overrides-6Hxg764S.js';
|
|
3
3
|
import { R as Request, a as Response, M as MethodsEnum } from '../../../requestError-DdaL8hc3.js';
|
|
4
4
|
import { EventBus } from '../../../events/index.js';
|
|
5
|
+
import express from 'express';
|
|
5
6
|
import 'node:http';
|
|
6
7
|
import '@fastify/cors';
|
|
7
8
|
import 'cors';
|
|
@@ -185,6 +186,7 @@ declare class ExpressServer extends ExpressServer_base {
|
|
|
185
186
|
protected constructor(config: typeof ExpressServer.Config);
|
|
186
187
|
protected parseRequest(req: any): Promise<Request<any>>;
|
|
187
188
|
protected handleResponse(res: any, response: Response<any>): Promise<void>;
|
|
189
|
+
protected createRawResponder(req: express.Request, res: express.Response): RawResponder;
|
|
188
190
|
protected registerRoute(method: MethodsEnum, path: string, cb: (req: any, res: any) => Promise<void>): void;
|
|
189
191
|
protected registerErrorHandler(cb: (error: Error, req: any, res: any) => Promise<void>): void;
|
|
190
192
|
protected registerNotFoundHandler(cb: (req: any, res: any) => Promise<void>): void;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
configurable,
|
|
7
7
|
getMediaDuration,
|
|
8
8
|
serverConfigPipe
|
|
9
|
-
} from "../../../chunk-
|
|
9
|
+
} from "../../../chunk-TT5EORDK.js";
|
|
10
10
|
import "../../../chunk-KZKFYO4V.js";
|
|
11
11
|
import "../../../chunk-MLKGABMK.js";
|
|
12
12
|
|
|
@@ -100,6 +100,9 @@ var ExpressServer = class extends configurable(serverConfigPipe, Server) {
|
|
|
100
100
|
response.body.pipe(res);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
createRawResponder(req, res) {
|
|
104
|
+
return this.createNodeRawResponder({ request: req, response: res });
|
|
105
|
+
}
|
|
103
106
|
registerRoute(method, path, cb) {
|
|
104
107
|
this.#app[method]?.(path, async (req, res) => cb(req, res));
|
|
105
108
|
}
|
|
@@ -120,6 +123,54 @@ var ExpressServer = class extends configurable(serverConfigPipe, Server) {
|
|
|
120
123
|
});
|
|
121
124
|
}
|
|
122
125
|
};
|
|
126
|
+
if (void 0) {
|
|
127
|
+
let ensureTestInstance = function() {
|
|
128
|
+
const instance = Instance.maybeGet() ?? Instance.create({ app: { name: "equipped-test" }, log: { level: "silent" } });
|
|
129
|
+
if (!testInstanceState.__equippedTestInstanceAliased) {
|
|
130
|
+
instance.alias("equipped-test");
|
|
131
|
+
testInstanceState.__equippedTestInstanceAliased = true;
|
|
132
|
+
}
|
|
133
|
+
}, createExpressResponse = function() {
|
|
134
|
+
return {
|
|
135
|
+
statusCode: 200,
|
|
136
|
+
headersSent: false,
|
|
137
|
+
writableEnded: false,
|
|
138
|
+
setHeader: vi.fn(),
|
|
139
|
+
end(chunk) {
|
|
140
|
+
void chunk;
|
|
141
|
+
this.headersSent = true;
|
|
142
|
+
this.writableEnded = true;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
ensureTestInstance2 = ensureTestInstance, createExpressResponse2 = createExpressResponse;
|
|
147
|
+
const { describe, expect, test, vi } = void 0;
|
|
148
|
+
const testInstanceState = globalThis;
|
|
149
|
+
class TestExpressServer extends ExpressServer {
|
|
150
|
+
exposeRawResponder(req, res) {
|
|
151
|
+
return this.createRawResponder(req, res);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
describe("ExpressServer raw responder", () => {
|
|
155
|
+
test("passes the Express request and response to the raw Node handler", async () => {
|
|
156
|
+
ensureTestInstance();
|
|
157
|
+
const server = TestExpressServer.create({ port: 0, requests: { log: false } });
|
|
158
|
+
const req = { marker: "request" };
|
|
159
|
+
const res = createExpressResponse();
|
|
160
|
+
let received = null;
|
|
161
|
+
await server.exposeRawResponder(
|
|
162
|
+
req,
|
|
163
|
+
res
|
|
164
|
+
)(async (request, response) => {
|
|
165
|
+
received = { request, response };
|
|
166
|
+
response.end("ok");
|
|
167
|
+
});
|
|
168
|
+
expect(received).toEqual({ request: req, response: res });
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
var ensureTestInstance2;
|
|
173
|
+
var createExpressResponse2;
|
|
123
174
|
export {
|
|
124
175
|
ExpressServer
|
|
125
176
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { B as BaseRequestAuthMethod, S as Server } from '../../../base-
|
|
1
|
+
import { B as BaseRequestAuthMethod, S as Server, R as RawResponder } from '../../../base-BDTBLZ9a.js';
|
|
2
2
|
import { A as AuthUser } from '../../../overrides-6Hxg764S.js';
|
|
3
3
|
import { R as Request, a as Response, M as MethodsEnum } from '../../../requestError-DdaL8hc3.js';
|
|
4
4
|
import { EventBus } from '../../../events/index.js';
|
|
5
|
+
import { FastifyRequest, FastifyReply } from 'fastify';
|
|
5
6
|
import 'node:http';
|
|
6
7
|
import '@fastify/cors';
|
|
7
8
|
import 'cors';
|
|
@@ -210,6 +211,7 @@ declare class FastifyServer extends FastifyServer_base {
|
|
|
210
211
|
contentType: string;
|
|
211
212
|
}>>;
|
|
212
213
|
protected handleResponse(res: any, response: Response<any>): Promise<void>;
|
|
214
|
+
protected createRawResponder(req: FastifyRequest, res: FastifyReply): RawResponder;
|
|
213
215
|
protected registerRoute(method: MethodsEnum, path: string, cb: (req: any, res: any) => Promise<void>): void;
|
|
214
216
|
protected registerErrorHandler(cb: (error: Error, req: any, res: any) => Promise<void>): void;
|
|
215
217
|
protected registerNotFoundHandler(cb: (req: any, res: any) => Promise<void>): void;
|