equipped 5.3.0-alpha.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/server/adapters/express/index.cjs +266 -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 +269 -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 +215 -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-WHIWTP2Z.min.mjs → chunk-4JLDXF7T.min.mjs} +2 -2
- package/dist/esm/{chunk-I4BB436E.mjs → chunk-4MXYZS5R.mjs} +2 -2
- package/dist/esm/{chunk-YTM6ZURZ.min.mjs → chunk-5VW3JAFR.min.mjs} +2 -2
- package/dist/esm/{chunk-YTHRK2PO.mjs → chunk-AKQBDYUO.mjs} +3 -3
- package/dist/esm/{chunk-MYGAF2AC.min.mjs → chunk-B5QQ32YY.min.mjs} +2 -2
- package/dist/esm/chunk-FLAPYQUT.min.mjs +32 -0
- package/dist/esm/chunk-FLAPYQUT.min.mjs.map +1 -0
- package/dist/esm/{chunk-KW3PBDFD.mjs → chunk-JH6EBXY4.mjs} +2 -2
- package/dist/esm/{chunk-2TCFNKRZ.mjs → chunk-MDQKODYQ.mjs} +216 -5
- package/dist/esm/chunk-MDQKODYQ.mjs.map +1 -0
- package/dist/esm/{chunk-ECBJ3NT3.min.mjs → chunk-PCAUXBAG.min.mjs} +2 -2
- package/dist/esm/{chunk-RIRBNBTC.mjs → chunk-PNZNNUMN.mjs} +3 -3
- package/dist/esm/{chunk-TWKHVLLT.mjs → chunk-PQCBVQL6.mjs} +2 -2
- package/dist/esm/{chunk-AUKXL4EA.min.mjs → chunk-QHLKB47N.min.mjs} +2 -2
- package/dist/esm/{chunk-6DW4GW3R.min.mjs → chunk-SGZNOYC3.min.mjs} +2 -2
- package/dist/esm/{chunk-6SB5M4XH.mjs → chunk-TVTYDU2D.mjs} +3 -3
- package/dist/esm/{chunk-IEBC3OWN.mjs → chunk-Z2TZ3KR7.mjs} +2 -2
- package/dist/esm/{chunk-OXI6IKAM.min.mjs → chunk-ZGMFFK6Y.min.mjs} +2 -2
- 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-Y7EXSYPD.mjs → introspection-32BRYKYY.mjs} +3 -3
- package/dist/esm/introspection-A72WMWE3.min.mjs +2 -0
- 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-DVr0fHil.d.ts} +20 -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-JZ2JTENY.js → chunk-3M4PBZAQ.js} +2 -2
- package/dist/types/{chunk-LWUMIHL4.js → chunk-3TKJGSCZ.js} +1 -1
- package/dist/types/{chunk-4LRJJSGG.js → chunk-65EHKCDZ.js} +2 -2
- package/dist/types/{chunk-A2MRYMCA.js → chunk-JQ2FWX4W.js} +1 -1
- package/dist/types/{chunk-H6JBLKX5.js → chunk-NJ2FHI3U.js} +2 -2
- package/dist/types/{chunk-XOU2A2Y6.js → chunk-OHFTQGQG.js} +1 -1
- package/dist/types/{chunk-IAHTILKJ.js → chunk-XGGGAEET.js} +1 -1
- package/dist/types/{chunk-32DMHN3G.js → chunk-YTY3EFNB.js} +215 -4
- 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-VOIU3XE6.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-WHIWTP2Z.min.mjs.map → chunk-4JLDXF7T.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-I4BB436E.mjs.map → chunk-4MXYZS5R.mjs.map} +0 -0
- /package/dist/esm/{chunk-YTM6ZURZ.min.mjs.map → chunk-5VW3JAFR.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-YTHRK2PO.mjs.map → chunk-AKQBDYUO.mjs.map} +0 -0
- /package/dist/esm/{chunk-MYGAF2AC.min.mjs.map → chunk-B5QQ32YY.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-KW3PBDFD.mjs.map → chunk-JH6EBXY4.mjs.map} +0 -0
- /package/dist/esm/{chunk-ECBJ3NT3.min.mjs.map → chunk-PCAUXBAG.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-RIRBNBTC.mjs.map → chunk-PNZNNUMN.mjs.map} +0 -0
- /package/dist/esm/{chunk-TWKHVLLT.mjs.map → chunk-PQCBVQL6.mjs.map} +0 -0
- /package/dist/esm/{chunk-AUKXL4EA.min.mjs.map → chunk-QHLKB47N.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-6DW4GW3R.min.mjs.map → chunk-SGZNOYC3.min.mjs.map} +0 -0
- /package/dist/esm/{chunk-6SB5M4XH.mjs.map → chunk-TVTYDU2D.mjs.map} +0 -0
- /package/dist/esm/{chunk-IEBC3OWN.mjs.map → chunk-Z2TZ3KR7.mjs.map} +0 -0
- /package/dist/esm/{chunk-OXI6IKAM.min.mjs.map → chunk-ZGMFFK6Y.min.mjs.map} +0 -0
- /package/dist/esm/{introspection-GP3G26B6.min.mjs.map → introspection-32BRYKYY.mjs.map} +0 -0
- /package/dist/esm/{introspection-Y7EXSYPD.mjs.map → introspection-A72WMWE3.min.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,8 @@ var Server = class {
|
|
|
951
968
|
#serverConfig;
|
|
952
969
|
#queue = [];
|
|
953
970
|
#routesByKey = /* @__PURE__ */ new Set();
|
|
971
|
+
#started = false;
|
|
972
|
+
#notFoundHandler = null;
|
|
954
973
|
setup(httpServer, config) {
|
|
955
974
|
this.#httpServer = httpServer;
|
|
956
975
|
this.#serverConfig = config;
|
|
@@ -1000,10 +1019,16 @@ var Server = class {
|
|
|
1000
1019
|
});
|
|
1001
1020
|
});
|
|
1002
1021
|
}
|
|
1022
|
+
setNotFoundHandler(handler) {
|
|
1023
|
+
if (this.#started) throw new EquippedError("Cannot set not-found handler after server has started", {});
|
|
1024
|
+
this.#notFoundHandler = handler;
|
|
1025
|
+
return this;
|
|
1026
|
+
}
|
|
1003
1027
|
test() {
|
|
1004
1028
|
return supertest(this.#httpServer);
|
|
1005
1029
|
}
|
|
1006
1030
|
async start() {
|
|
1031
|
+
this.#started = true;
|
|
1007
1032
|
const config = this.#serverConfig;
|
|
1008
1033
|
const instance = Instance.get();
|
|
1009
1034
|
const { app } = instance.settings;
|
|
@@ -1017,10 +1042,7 @@ var Server = class {
|
|
|
1017
1042
|
})
|
|
1018
1043
|
});
|
|
1019
1044
|
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
|
-
});
|
|
1045
|
+
this.registerNotFoundHandler(async (req, res) => await this.#handleNotFound(req, res));
|
|
1024
1046
|
this.registerErrorHandler(async (error, _, res) => {
|
|
1025
1047
|
if (!(error instanceof EquippedError)) Instance.get().log.error({ error }, "Uncaught error in route handler");
|
|
1026
1048
|
const response = error instanceof RequestError ? new Response({
|
|
@@ -1039,6 +1061,31 @@ var Server = class {
|
|
|
1039
1061
|
if (started) Instance.get().log.info(`${instance.id}(${app.name}) service listening on port ${config.port}`);
|
|
1040
1062
|
return started;
|
|
1041
1063
|
}
|
|
1064
|
+
createNodeRawResponder(input) {
|
|
1065
|
+
return async (handler) => {
|
|
1066
|
+
input.beforeHandle?.();
|
|
1067
|
+
try {
|
|
1068
|
+
await handler(input.request, input.response);
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
if (!hasRawResponseStarted(input.response)) {
|
|
1071
|
+
writeRawHandlerError(input.response, error);
|
|
1072
|
+
return rawResponseHandled;
|
|
1073
|
+
}
|
|
1074
|
+
throw error;
|
|
1075
|
+
}
|
|
1076
|
+
if (!hasRawResponseStarted(input.response))
|
|
1077
|
+
writeRawHandlerError(input.response, new EquippedError(rawResponseNotStartedMessage, {}));
|
|
1078
|
+
return rawResponseHandled;
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
async #handleNotFound(req, res) {
|
|
1082
|
+
const request = await this.parseRequest(req);
|
|
1083
|
+
if (!this.#notFoundHandler) throw new NotFoundError(`Route ${request.path} not found`);
|
|
1084
|
+
const result = await this.#notFoundHandler({ request, respondWithRaw: this.createRawResponder(req, res) });
|
|
1085
|
+
if (isRawResponseHandled(result)) return;
|
|
1086
|
+
if (result instanceof Response) return await this.handleResponse(res, result);
|
|
1087
|
+
throw new EquippedError("Not-found handler must return a Response or respondWithRaw(...)", {});
|
|
1088
|
+
}
|
|
1042
1089
|
#resolveSchema(method, schema) {
|
|
1043
1090
|
const defaultStatusCode = schema?.defaultStatusCode ?? StatusCodes.Ok;
|
|
1044
1091
|
const defaultContentType = schema?.defaultContentType ?? "application/json";
|
|
@@ -1129,6 +1176,170 @@ var Server = class {
|
|
|
1129
1176
|
};
|
|
1130
1177
|
}
|
|
1131
1178
|
};
|
|
1179
|
+
if (void 0) {
|
|
1180
|
+
let ensureTestInstance = function() {
|
|
1181
|
+
const instance = Instance.maybeGet() ?? Instance.create({ app: { name: "equipped-test" }, log: { level: "silent" } });
|
|
1182
|
+
if (!testInstanceState.__equippedTestInstanceAliased) {
|
|
1183
|
+
instance.alias("equipped-test");
|
|
1184
|
+
testInstanceState.__equippedTestInstanceAliased = true;
|
|
1185
|
+
}
|
|
1186
|
+
}, createRawResponse = function() {
|
|
1187
|
+
const chunks = [];
|
|
1188
|
+
return {
|
|
1189
|
+
statusCode: 200,
|
|
1190
|
+
headersSent: false,
|
|
1191
|
+
writableEnded: false,
|
|
1192
|
+
headers: {},
|
|
1193
|
+
setHeader(key, value) {
|
|
1194
|
+
this.headers[key] = value;
|
|
1195
|
+
},
|
|
1196
|
+
end(chunk) {
|
|
1197
|
+
if (chunk !== void 0) chunks.push(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk));
|
|
1198
|
+
this.headersSent = true;
|
|
1199
|
+
this.writableEnded = true;
|
|
1200
|
+
},
|
|
1201
|
+
body() {
|
|
1202
|
+
return chunks.join("");
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
};
|
|
1206
|
+
ensureTestInstance2 = ensureTestInstance, createRawResponse2 = createRawResponse;
|
|
1207
|
+
const { describe, expect, test } = void 0;
|
|
1208
|
+
const testInstanceState = globalThis;
|
|
1209
|
+
class TestServer extends Server {
|
|
1210
|
+
handledResponse = null;
|
|
1211
|
+
notFoundHandler = null;
|
|
1212
|
+
constructor() {
|
|
1213
|
+
super();
|
|
1214
|
+
this.setup(http.createServer(), {
|
|
1215
|
+
port: 0,
|
|
1216
|
+
cors: void 0,
|
|
1217
|
+
eventBus: void 0,
|
|
1218
|
+
publicPath: void 0,
|
|
1219
|
+
healthPath: void 0,
|
|
1220
|
+
openapi: { docsVersion: "1.0.0", docsBaseUrl: ["/"], docsPath: "/__docs" },
|
|
1221
|
+
requests: {
|
|
1222
|
+
log: false,
|
|
1223
|
+
rateLimit: { enabled: false, periodInMs: 1, limit: 1 },
|
|
1224
|
+
slowdown: { enabled: false, periodInMs: 1, delayAfter: 1, delayInMs: 1 }
|
|
1225
|
+
},
|
|
1226
|
+
socketsAuthMethods: []
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
async parseRequest(req) {
|
|
1230
|
+
return new Request2({
|
|
1231
|
+
ip: "127.0.0.1",
|
|
1232
|
+
body: {},
|
|
1233
|
+
cookies: {},
|
|
1234
|
+
params: {},
|
|
1235
|
+
query: {},
|
|
1236
|
+
method: Methods.get,
|
|
1237
|
+
path: req.path,
|
|
1238
|
+
headers: {},
|
|
1239
|
+
files: {}
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
async handleResponse(_, response) {
|
|
1243
|
+
this.handledResponse = response;
|
|
1244
|
+
}
|
|
1245
|
+
createRawResponder(req, res) {
|
|
1246
|
+
return this.createNodeRawResponder({ request: req.rawRequest, response: res.rawResponse });
|
|
1247
|
+
}
|
|
1248
|
+
registerRoute() {
|
|
1249
|
+
}
|
|
1250
|
+
registerErrorHandler() {
|
|
1251
|
+
}
|
|
1252
|
+
registerNotFoundHandler(cb) {
|
|
1253
|
+
this.notFoundHandler = cb;
|
|
1254
|
+
}
|
|
1255
|
+
async startServer() {
|
|
1256
|
+
return true;
|
|
1257
|
+
}
|
|
1258
|
+
async dispatchNotFound(path) {
|
|
1259
|
+
if (!this.notFoundHandler) throw new Error("not-found handler was not registered");
|
|
1260
|
+
this.handledResponse = null;
|
|
1261
|
+
const rawResponse = createRawResponse();
|
|
1262
|
+
await this.notFoundHandler({ path, rawRequest: {} }, { rawResponse });
|
|
1263
|
+
return { handledResponse: this.handledResponse, rawResponse };
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
describe("Server not-found handler", () => {
|
|
1267
|
+
test("throws the default Equipped not-found error when no custom handler is set", async () => {
|
|
1268
|
+
ensureTestInstance();
|
|
1269
|
+
const server = new TestServer();
|
|
1270
|
+
await server.start();
|
|
1271
|
+
await expect(server.dispatchNotFound("/missing")).rejects.toBeInstanceOf(NotFoundError);
|
|
1272
|
+
});
|
|
1273
|
+
test("allows a custom not-found handler to return an Equipped response", async () => {
|
|
1274
|
+
ensureTestInstance();
|
|
1275
|
+
const server = new TestServer();
|
|
1276
|
+
server.setNotFoundHandler(
|
|
1277
|
+
({ request }) => new Response({
|
|
1278
|
+
body: [{ message: `No route for ${request.path}` }],
|
|
1279
|
+
status: StatusCodes.NotFound,
|
|
1280
|
+
headers: {},
|
|
1281
|
+
cookies: {},
|
|
1282
|
+
contentType: "application/json"
|
|
1283
|
+
})
|
|
1284
|
+
);
|
|
1285
|
+
await server.start();
|
|
1286
|
+
const result = await server.dispatchNotFound("/custom");
|
|
1287
|
+
expect(result.handledResponse?.status).toBe(StatusCodes.NotFound);
|
|
1288
|
+
expect(result.handledResponse?.body).toEqual([{ message: "No route for /custom" }]);
|
|
1289
|
+
});
|
|
1290
|
+
test("allows a custom not-found handler to complete the response through a raw Node listener", async () => {
|
|
1291
|
+
ensureTestInstance();
|
|
1292
|
+
const server = new TestServer();
|
|
1293
|
+
server.setNotFoundHandler(
|
|
1294
|
+
({ respondWithRaw }) => respondWithRaw((_, response) => {
|
|
1295
|
+
response.statusCode = 203;
|
|
1296
|
+
response.end("raw fallback");
|
|
1297
|
+
})
|
|
1298
|
+
);
|
|
1299
|
+
await server.start();
|
|
1300
|
+
const result = await server.dispatchNotFound("/page");
|
|
1301
|
+
expect(result.handledResponse).toBeNull();
|
|
1302
|
+
expect(result.rawResponse.statusCode).toBe(203);
|
|
1303
|
+
expect(result.rawResponse.body()).toBe("raw fallback");
|
|
1304
|
+
});
|
|
1305
|
+
test("writes a clear raw error when a raw not-found handler does not start a response", async () => {
|
|
1306
|
+
ensureTestInstance();
|
|
1307
|
+
const server = new TestServer();
|
|
1308
|
+
server.setNotFoundHandler(({ respondWithRaw }) => respondWithRaw(() => {
|
|
1309
|
+
}));
|
|
1310
|
+
await server.start();
|
|
1311
|
+
const result = await server.dispatchNotFound("/page");
|
|
1312
|
+
expect(result.handledResponse).toBeNull();
|
|
1313
|
+
expect(result.rawResponse.statusCode).toBe(StatusCodes.BadRequest);
|
|
1314
|
+
expect(result.rawResponse.body()).toContain(rawResponseNotStartedMessage);
|
|
1315
|
+
});
|
|
1316
|
+
test("rejects a custom not-found handler result that is neither an Equipped response nor raw completion", async () => {
|
|
1317
|
+
ensureTestInstance();
|
|
1318
|
+
const server = new TestServer();
|
|
1319
|
+
server.setNotFoundHandler((() => void 0));
|
|
1320
|
+
await server.start();
|
|
1321
|
+
await expect(server.dispatchNotFound("/bad")).rejects.toThrow("Not-found handler must return a Response or respondWithRaw(...)");
|
|
1322
|
+
});
|
|
1323
|
+
test("rejects setting the custom not-found handler after server startup", async () => {
|
|
1324
|
+
ensureTestInstance();
|
|
1325
|
+
const server = new TestServer();
|
|
1326
|
+
await server.start();
|
|
1327
|
+
expect(
|
|
1328
|
+
() => server.setNotFoundHandler(
|
|
1329
|
+
() => new Response({
|
|
1330
|
+
body: null,
|
|
1331
|
+
status: StatusCodes.NotFound,
|
|
1332
|
+
headers: {},
|
|
1333
|
+
cookies: {},
|
|
1334
|
+
contentType: "application/json"
|
|
1335
|
+
})
|
|
1336
|
+
)
|
|
1337
|
+
).toThrow("Cannot set not-found handler after server has started");
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
var ensureTestInstance2;
|
|
1342
|
+
var createRawResponse2;
|
|
1132
1343
|
|
|
1133
1344
|
// src/server/middlewares/requireAuthUser.ts
|
|
1134
1345
|
var requireAuthUser = (methods) => makeMiddleware(
|
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
Db,
|
|
3
3
|
QueryKeys,
|
|
4
4
|
dbChangeConfigPipe
|
|
5
|
-
} from "../../../chunk-
|
|
6
|
-
import "../../../chunk-
|
|
5
|
+
} from "../../../chunk-3M4PBZAQ.js";
|
|
6
|
+
import "../../../chunk-XGGGAEET.js";
|
|
7
7
|
import {
|
|
8
8
|
EquippedError,
|
|
9
9
|
Instance,
|
|
10
10
|
retry
|
|
11
|
-
} from "../../../chunk-
|
|
11
|
+
} from "../../../chunk-YTY3EFNB.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-3M4PBZAQ.js";
|
|
10
|
+
import "../chunk-XGGGAEET.js";
|
|
11
|
+
import "../chunk-YTY3EFNB.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-XGGGAEET.js";
|
|
5
|
+
import "../../../chunk-YTY3EFNB.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-65EHKCDZ.js";
|
|
5
|
+
import "../../../chunk-3TKJGSCZ.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-YTY3EFNB.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-NJ2FHI3U.js";
|
|
4
|
+
import "../../../chunk-JQ2FWX4W.js";
|
|
5
|
+
import "../../../chunk-YTY3EFNB.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-NJ2FHI3U.js";
|
|
4
4
|
import {
|
|
5
5
|
OrmAdapter
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-JQ2FWX4W.js";
|
|
7
7
|
import {
|
|
8
8
|
configurable
|
|
9
|
-
} from "../../../chunk-
|
|
9
|
+
} from "../../../chunk-YTY3EFNB.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-JQ2FWX4W.js";
|
|
15
15
|
import {
|
|
16
16
|
EquippedError,
|
|
17
17
|
configurable
|
|
18
|
-
} from "../../../chunk-
|
|
18
|
+
} from "../../../chunk-YTY3EFNB.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-JQ2FWX4W.js";
|
|
16
16
|
import {
|
|
17
17
|
EquippedError,
|
|
18
18
|
configurable
|
|
19
|
-
} from "../../../chunk-
|
|
19
|
+
} from "../../../chunk-YTY3EFNB.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-VOIU3XE6.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-OHFTQGQG.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-JQ2FWX4W.js";
|
|
37
37
|
import {
|
|
38
38
|
EquippedError,
|
|
39
39
|
Instance
|
|
40
|
-
} from "../chunk-
|
|
40
|
+
} from "../chunk-YTY3EFNB.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-DVr0fHil.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-YTY3EFNB.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-DVr0fHil.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;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
configurable,
|
|
8
8
|
getMediaDuration,
|
|
9
9
|
serverConfigPipe
|
|
10
|
-
} from "../../../chunk-
|
|
10
|
+
} from "../../../chunk-YTY3EFNB.js";
|
|
11
11
|
import "../../../chunk-KZKFYO4V.js";
|
|
12
12
|
import "../../../chunk-MLKGABMK.js";
|
|
13
13
|
|
|
@@ -96,6 +96,9 @@ var FastifyServer = class extends configurable(serverConfigPipe, Server) {
|
|
|
96
96
|
for (const [key, { value, ...opts }] of Object.entries(response.cookies)) res = res.setCookie(key, value, opts);
|
|
97
97
|
await res.status(response.status).headers(response.headers).send(response.body);
|
|
98
98
|
}
|
|
99
|
+
createRawResponder(req, res) {
|
|
100
|
+
return this.createNodeRawResponder({ request: req.raw, response: res.raw, beforeHandle: () => res.hijack() });
|
|
101
|
+
}
|
|
99
102
|
registerRoute(method, path, cb) {
|
|
100
103
|
this.#app.register(async (inst) => {
|
|
101
104
|
inst.route({ url: path, method, handler: cb });
|
|
@@ -125,6 +128,57 @@ function excludeBufferKeys(body) {
|
|
|
125
128
|
files: Object.fromEntries(fileEntries)
|
|
126
129
|
};
|
|
127
130
|
}
|
|
131
|
+
if (void 0) {
|
|
132
|
+
let ensureTestInstance = function() {
|
|
133
|
+
const instance = Instance.maybeGet() ?? Instance.create({ app: { name: "equipped-test" }, log: { level: "silent" } });
|
|
134
|
+
if (!testInstanceState.__equippedTestInstanceAliased) {
|
|
135
|
+
instance.alias("equipped-test");
|
|
136
|
+
testInstanceState.__equippedTestInstanceAliased = true;
|
|
137
|
+
}
|
|
138
|
+
}, createRawResponse = function() {
|
|
139
|
+
return {
|
|
140
|
+
statusCode: 200,
|
|
141
|
+
headersSent: false,
|
|
142
|
+
writableEnded: false,
|
|
143
|
+
setHeader: vi.fn(),
|
|
144
|
+
end(chunk) {
|
|
145
|
+
void chunk;
|
|
146
|
+
this.headersSent = true;
|
|
147
|
+
this.writableEnded = true;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
ensureTestInstance2 = ensureTestInstance, createRawResponse2 = createRawResponse;
|
|
152
|
+
const { describe, expect, test, vi } = void 0;
|
|
153
|
+
const testInstanceState = globalThis;
|
|
154
|
+
class TestFastifyServer extends FastifyServer {
|
|
155
|
+
exposeRawResponder(req, res) {
|
|
156
|
+
return this.createRawResponder(req, res);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
describe("FastifyServer raw responder", () => {
|
|
160
|
+
test("hijacks the Fastify reply before passing Node raw request and response to the handler", async () => {
|
|
161
|
+
ensureTestInstance();
|
|
162
|
+
const server = TestFastifyServer.create({ port: 0, requests: { log: false } });
|
|
163
|
+
const rawRequest = { marker: "request" };
|
|
164
|
+
const rawResponse = createRawResponse();
|
|
165
|
+
const reply = { raw: rawResponse, hijack: vi.fn() };
|
|
166
|
+
const request = { raw: rawRequest };
|
|
167
|
+
let received = null;
|
|
168
|
+
await server.exposeRawResponder(
|
|
169
|
+
request,
|
|
170
|
+
reply
|
|
171
|
+
)(async (req, res) => {
|
|
172
|
+
received = { request: req, response: res };
|
|
173
|
+
res.end("ok");
|
|
174
|
+
});
|
|
175
|
+
expect(reply.hijack).toHaveBeenCalledOnce();
|
|
176
|
+
expect(received).toEqual({ request: rawRequest, response: rawResponse });
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
var ensureTestInstance2;
|
|
181
|
+
var createRawResponse2;
|
|
128
182
|
export {
|
|
129
183
|
FastifyServer
|
|
130
184
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BaseRequestAuthMethod } from '../base-
|
|
2
|
-
export { O as OnJoinFn, R as Router, S as Server, a as ServerConfig,
|
|
1
|
+
import { B as BaseRequestAuthMethod } from '../base-DVr0fHil.js';
|
|
2
|
+
export { O as OnJoinFn, R as RawResponder, b as RawResponseHandled, c as RawResponseHandler, f as Router, S as Server, a as ServerConfig, d as ServerNotFoundContext, e as ServerNotFoundHandler, g as SocketCallbacks, h as SocketEmitter, s as serverConfigPipe } from '../base-DVr0fHil.js';
|
|
3
3
|
import { A as AuthUser } from '../overrides-6Hxg764S.js';
|
|
4
4
|
import { R as Request, c as RouteDefToReqRes, d as RouteDef, e as Route } from '../requestError-DdaL8hc3.js';
|
|
5
5
|
export { C as CookieVal, h as DefaultCookies, D as DefaultHeaders, I as IncomingFile, k as MergeRouteDefs, f as Methods, M as MethodsEnum, a as Response, i as RouteConfig, l as RouteDefHandler, j as RouterConfig, S as StatusCodes, g as StatusCodesEnum, o as makeErrorMiddleware, m as makeMiddleware, n as makeResponseMiddleware } from '../requestError-DdaL8hc3.js';
|