@terreno/api 0.25.0 → 0.27.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/.ai/guidelines/core.md +1 -0
- package/README.md +4 -3
- package/dist/__tests__/openApiCompat.test.js +8 -2
- package/dist/__tests__/versionCheckPlugin.test.js +15 -0
- package/dist/actions.openApi.test.js +1 -0
- package/dist/actions.test.js +1 -0
- package/dist/api.arrayOperations.test.js +1 -0
- package/dist/api.coverage.test.d.ts +1 -0
- package/dist/api.coverage.test.js +191 -0
- package/dist/api.errorPaths.test.d.ts +1 -0
- package/dist/api.errorPaths.test.js +278 -0
- package/dist/api.errors.test.js +1 -0
- package/dist/api.hooks.test.js +1 -0
- package/dist/api.js +160 -167
- package/dist/api.query.test.js +1 -0
- package/dist/api.test.js +1 -0
- package/dist/auth.js +1 -0
- package/dist/auth.test.js +122 -0
- package/dist/betterAuthApp.test.js +1 -2
- package/dist/betterAuthSetup.js +1 -0
- package/dist/betterAuthSetup.test.js +1 -0
- package/dist/configuration.test.js +1 -0
- package/dist/configurationApp.js +1 -0
- package/dist/configurationPlugin.test.js +80 -0
- package/dist/consentApp.test.js +1 -0
- package/dist/docLoader.js +1 -3
- package/dist/envConfigurationPlugin.js +1 -0
- package/dist/example.js +3 -2
- package/dist/expressServer.js +6 -6
- package/dist/expressServer.test.js +23 -0
- package/dist/githubAuth.js +2 -0
- package/dist/githubAuth.test.js +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +28 -3
- package/dist/logger.test.js +107 -0
- package/dist/openApi.test.js +52 -0
- package/dist/openApiBuilder.js +2 -1
- package/dist/openApiBuilder.test.js +3 -2
- package/dist/openApiValidator.js +1 -0
- package/dist/openApiValidator.test.js +41 -0
- package/dist/permissions.middleware.test.js +1 -0
- package/dist/permissions.test.js +1 -0
- package/dist/plugins.js +8 -0
- package/dist/plugins.test.js +1 -0
- package/dist/populate.js +4 -2
- package/dist/populate.test.js +1 -0
- package/dist/realtime/realtime.test.js +13 -3
- package/dist/realtime/types.d.ts +1 -1
- package/dist/requestContext.test.js +28 -0
- package/dist/terrenoApp.js +1 -0
- package/dist/tests/createTestData.js +11 -6
- package/dist/tests/fixtures/compileAuthEntry.js +1 -1
- package/dist/tests/models.js +1 -0
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +3 -1
- package/package.json +7 -7
- package/src/__tests__/openApiCompat.test.ts +8 -2
- package/src/__tests__/versionCheckPlugin.test.ts +9 -0
- package/src/actions.openApi.test.ts +1 -0
- package/src/actions.test.ts +1 -0
- package/src/api.arrayOperations.test.ts +1 -0
- package/src/api.coverage.test.ts +121 -0
- package/src/api.errorPaths.test.ts +171 -0
- package/src/api.errors.test.ts +1 -0
- package/src/api.hooks.test.ts +1 -0
- package/src/api.query.test.ts +1 -0
- package/src/api.test.ts +1 -0
- package/src/api.ts +13 -9
- package/src/auth.test.ts +91 -2
- package/src/auth.ts +6 -0
- package/src/betterAuthApp.test.ts +3 -3
- package/src/betterAuthSetup.test.ts +1 -0
- package/src/betterAuthSetup.ts +3 -0
- package/src/configuration.test.ts +1 -0
- package/src/configurationApp.ts +2 -0
- package/src/configurationPlugin.test.ts +46 -1
- package/src/consentApp.test.ts +1 -0
- package/src/docLoader.ts +1 -2
- package/src/envConfigurationPlugin.ts +2 -0
- package/src/example.ts +3 -2
- package/src/expressServer.test.ts +13 -0
- package/src/expressServer.ts +5 -3
- package/src/githubAuth.test.ts +1 -0
- package/src/githubAuth.ts +2 -0
- package/src/index.ts +40 -2
- package/src/logger.test.ts +78 -0
- package/src/openApi.test.ts +54 -0
- package/src/openApiBuilder.test.ts +7 -6
- package/src/openApiBuilder.ts +2 -1
- package/src/openApiValidator.test.ts +64 -0
- package/src/openApiValidator.ts +1 -0
- package/src/permissions.middleware.test.ts +1 -0
- package/src/permissions.test.ts +1 -0
- package/src/plugins.test.ts +1 -0
- package/src/plugins.ts +9 -0
- package/src/populate.test.ts +1 -0
- package/src/populate.ts +4 -2
- package/src/realtime/realtime.test.ts +13 -3
- package/src/realtime/realtimeApp.ts +1 -0
- package/src/realtime/registry.ts +1 -0
- package/src/realtime/types.ts +1 -2
- package/src/requestContext.test.ts +32 -0
- package/src/terrenoApp.ts +1 -0
- package/src/tests/createTestData.ts +11 -6
- package/src/tests/fixtures/compileAuthEntry.ts +1 -1
- package/src/tests/models.ts +1 -0
- package/src/vendor/wesleytodd-openapi/lib/generate-doc.js +4 -1
- package/tsconfig.json +3 -3
- package/dist/notifiers/index.d.ts +0 -3
- package/dist/notifiers/index.js +0 -19
- package/dist/realtime/index.d.ts +0 -6
- package/dist/realtime/index.js +0 -27
- package/src/notifiers/index.ts +0 -3
- package/src/realtime/index.ts +0 -34
- /package/{types.d.ts → src/types.d.ts} +0 -0
|
@@ -85,6 +85,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
85
85
|
return ar;
|
|
86
86
|
};
|
|
87
87
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
88
|
+
// noExplicitAny: test mock typing
|
|
88
89
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
89
90
|
var bun_test_1 = require("bun:test");
|
|
90
91
|
var mongoose_1 = __importStar(require("mongoose"));
|
|
@@ -469,6 +470,85 @@ var ValidatedConfigModel = (0, mongoose_1.model)("ValidatedConfiguration", valid
|
|
|
469
470
|
}
|
|
470
471
|
});
|
|
471
472
|
}); });
|
|
473
|
+
(0, bun_test_1.it)("re-fetches the existing singleton when a concurrent create hits a 409", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
474
|
+
var existing, spy, config;
|
|
475
|
+
return __generator(this, function (_a) {
|
|
476
|
+
switch (_a.label) {
|
|
477
|
+
case 0:
|
|
478
|
+
if (!dbConnected) {
|
|
479
|
+
return [2 /*return*/];
|
|
480
|
+
}
|
|
481
|
+
return [4 /*yield*/, SimpleConfigModel.getConfig()];
|
|
482
|
+
case 1:
|
|
483
|
+
existing = (_a.sent());
|
|
484
|
+
spy = (0, bun_test_1.spyOn)(SimpleConfigModel, "findOneOrNone").mockResolvedValueOnce(null);
|
|
485
|
+
_a.label = 2;
|
|
486
|
+
case 2:
|
|
487
|
+
_a.trys.push([2, , 4, 5]);
|
|
488
|
+
return [4 /*yield*/, SimpleConfigModel.getConfig()];
|
|
489
|
+
case 3:
|
|
490
|
+
config = (_a.sent());
|
|
491
|
+
(0, bun_test_1.expect)(config._id.toString()).toBe(existing._id.toString());
|
|
492
|
+
return [3 /*break*/, 5];
|
|
493
|
+
case 4:
|
|
494
|
+
spy.mockRestore();
|
|
495
|
+
return [7 /*endfinally*/];
|
|
496
|
+
case 5: return [2 /*return*/];
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}); });
|
|
500
|
+
(0, bun_test_1.it)("rethrows non-409 errors raised while creating the singleton", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
501
|
+
var findSpy, saveSpy;
|
|
502
|
+
return __generator(this, function (_a) {
|
|
503
|
+
switch (_a.label) {
|
|
504
|
+
case 0:
|
|
505
|
+
if (!dbConnected) {
|
|
506
|
+
return [2 /*return*/];
|
|
507
|
+
}
|
|
508
|
+
findSpy = (0, bun_test_1.spyOn)(SimpleConfigModel, "findOneOrNone").mockResolvedValueOnce(null);
|
|
509
|
+
saveSpy = (0, bun_test_1.spyOn)(SimpleConfigModel.prototype, "save").mockRejectedValueOnce(new Error("unexpected save failure"));
|
|
510
|
+
_a.label = 1;
|
|
511
|
+
case 1:
|
|
512
|
+
_a.trys.push([1, , 3, 4]);
|
|
513
|
+
return [4 /*yield*/, (0, bun_test_1.expect)(SimpleConfigModel.getConfig()).rejects.toThrow("unexpected save failure")];
|
|
514
|
+
case 2:
|
|
515
|
+
_a.sent();
|
|
516
|
+
return [3 /*break*/, 4];
|
|
517
|
+
case 3:
|
|
518
|
+
findSpy.mockRestore();
|
|
519
|
+
saveSpy.mockRestore();
|
|
520
|
+
return [7 /*endfinally*/];
|
|
521
|
+
case 4: return [2 /*return*/];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}); });
|
|
525
|
+
(0, bun_test_1.it)("returns undefined for a dotted key that traverses a non-object value", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
526
|
+
var _a, _b;
|
|
527
|
+
return __generator(this, function (_c) {
|
|
528
|
+
switch (_c.label) {
|
|
529
|
+
case 0:
|
|
530
|
+
if (!dbConnected) {
|
|
531
|
+
return [2 /*return*/];
|
|
532
|
+
}
|
|
533
|
+
return [4 /*yield*/, SimpleConfigModel.getConfig()];
|
|
534
|
+
case 1:
|
|
535
|
+
_c.sent();
|
|
536
|
+
// `value` is a string, so descending into `value.missing` bails out.
|
|
537
|
+
_a = bun_test_1.expect;
|
|
538
|
+
return [4 /*yield*/, SimpleConfigModel.getConfig("value.missing")];
|
|
539
|
+
case 2:
|
|
540
|
+
// `value` is a string, so descending into `value.missing` bails out.
|
|
541
|
+
_a.apply(void 0, [_c.sent()]).toBeUndefined();
|
|
542
|
+
// A missing top-level segment also resolves to undefined.
|
|
543
|
+
_b = bun_test_1.expect;
|
|
544
|
+
return [4 /*yield*/, SimpleConfigModel.getConfig("nope.deeper")];
|
|
545
|
+
case 3:
|
|
546
|
+
// A missing top-level segment also resolves to undefined.
|
|
547
|
+
_b.apply(void 0, [_c.sent()]).toBeUndefined();
|
|
548
|
+
return [2 /*return*/];
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
}); });
|
|
472
552
|
(0, bun_test_1.it)("updates an existing document via updateConfig", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
473
553
|
var updated, count;
|
|
474
554
|
return __generator(this, function (_a) {
|
package/dist/consentApp.test.js
CHANGED
|
@@ -55,6 +55,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
56
56
|
};
|
|
57
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
// noExplicitAny: test mock typing
|
|
58
59
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
59
60
|
var bun_test_1 = require("bun:test");
|
|
60
61
|
var supertest_1 = __importDefault(require("supertest"));
|
package/dist/docLoader.js
CHANGED
|
@@ -87,9 +87,7 @@ var loadDocOr404 = function (model, id, populatePaths) { return __awaiter(void 0
|
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
89
|
builtQuery = model.findById(id);
|
|
90
|
-
populatedQuery = (0, api_1.addPopulateToQuery)(
|
|
91
|
-
// biome-ignore lint/suspicious/noExplicitAny: Query types vary based on populate paths
|
|
92
|
-
builtQuery, populatePaths);
|
|
90
|
+
populatedQuery = (0, api_1.addPopulateToQuery)(builtQuery, populatePaths);
|
|
93
91
|
_a.label = 1;
|
|
94
92
|
case 1:
|
|
95
93
|
_a.trys.push([1, 3, , 4]);
|
|
@@ -121,6 +121,7 @@ var refreshFromDoc = function (Model) { return __awaiter(void 0, void 0, void 0,
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
}); };
|
|
124
|
+
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
124
125
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
125
126
|
var envConfigurationPlugin = function (schema) {
|
|
126
127
|
schema.add({
|
package/dist/example.js
CHANGED
|
@@ -68,8 +68,9 @@ var userSchema = new mongoose_1.Schema({
|
|
|
68
68
|
admin: { default: false, description: "Whether the user has admin privileges", type: Boolean },
|
|
69
69
|
username: { description: "The user's username", type: String },
|
|
70
70
|
}, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
userSchema.plugin(passport_local_mongoose_1.default, {
|
|
72
|
+
usernameField: "email",
|
|
73
|
+
});
|
|
73
74
|
userSchema.plugin(plugins_1.createdUpdatedPlugin);
|
|
74
75
|
userSchema.plugin(plugins_1.isDeletedPlugin);
|
|
75
76
|
userSchema.plugin(plugins_1.findOneOrNone);
|
package/dist/expressServer.js
CHANGED
|
@@ -105,7 +105,7 @@ var cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
|
105
105
|
var on_finished_1 = __importDefault(require("on-finished"));
|
|
106
106
|
var passport_1 = __importDefault(require("passport"));
|
|
107
107
|
var logger_1 = require("./logger");
|
|
108
|
-
var
|
|
108
|
+
var slackNotifier_1 = require("./notifiers/slackNotifier");
|
|
109
109
|
var SLOW_READ_MAX = 200;
|
|
110
110
|
var SLOW_WRITE_MAX = 500;
|
|
111
111
|
var IS_JEST = process.env.JEST_WORKER_ID !== undefined;
|
|
@@ -246,7 +246,7 @@ var wrapScript = function (func_1) {
|
|
|
246
246
|
case 0:
|
|
247
247
|
name = (_a = require.main) === null || _a === void 0 ? void 0 : _a.filename.split("/").slice(-1)[0].replace(".ts", "");
|
|
248
248
|
logger_1.logger.info("Running script ".concat(name));
|
|
249
|
-
return [4 /*yield*/, (0,
|
|
249
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("Running script ".concat(name), {
|
|
250
250
|
slackChannel: options.slackChannel,
|
|
251
251
|
})];
|
|
252
252
|
case 1:
|
|
@@ -260,7 +260,7 @@ var wrapScript = function (func_1) {
|
|
|
260
260
|
switch (_a.label) {
|
|
261
261
|
case 0:
|
|
262
262
|
msg = "Script ".concat(name, " is taking a while, currently ").concat(warnTime_1 / 1000, " seconds");
|
|
263
|
-
return [4 /*yield*/, (0,
|
|
263
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)(msg)];
|
|
264
264
|
case 1:
|
|
265
265
|
_a.sent();
|
|
266
266
|
logger_1.logger.warn(msg);
|
|
@@ -274,7 +274,7 @@ var wrapScript = function (func_1) {
|
|
|
274
274
|
switch (_a.label) {
|
|
275
275
|
case 0:
|
|
276
276
|
msg = "Script ".concat(name, " took too long, exiting");
|
|
277
|
-
return [4 /*yield*/, (0,
|
|
277
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)(msg)];
|
|
278
278
|
case 1:
|
|
279
279
|
_a.sent();
|
|
280
280
|
logger_1.logger.error(msg);
|
|
@@ -304,7 +304,7 @@ var wrapScript = function (func_1) {
|
|
|
304
304
|
error_1 = _d.sent();
|
|
305
305
|
Sentry.captureException(error_1);
|
|
306
306
|
logger_1.logger.error("Error running script ".concat(name, ": ").concat(error_1, "\n").concat(error_1.stack));
|
|
307
|
-
return [4 /*yield*/, (0,
|
|
307
|
+
return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("Error running script ".concat(name, ": ").concat(error_1, "\n").concat(error_1.stack))];
|
|
308
308
|
case 7:
|
|
309
309
|
_d.sent();
|
|
310
310
|
return [4 /*yield*/, Sentry.flush()];
|
|
@@ -312,7 +312,7 @@ var wrapScript = function (func_1) {
|
|
|
312
312
|
_d.sent();
|
|
313
313
|
process.exit(1);
|
|
314
314
|
return [3 /*break*/, 9];
|
|
315
|
-
case 9: return [4 /*yield*/, (0,
|
|
315
|
+
case 9: return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("Success running script ".concat(name, ": ").concat(result))];
|
|
316
316
|
case 10:
|
|
317
317
|
_d.sent();
|
|
318
318
|
process.exit(0);
|
|
@@ -119,6 +119,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
119
119
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
120
120
|
};
|
|
121
121
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
122
|
+
// noExplicitAny: test mock typing
|
|
122
123
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
123
124
|
var bun_test_1 = require("bun:test");
|
|
124
125
|
var node_stream_1 = require("node:stream");
|
|
@@ -1201,6 +1202,28 @@ var typedUserModel = tests_1.UserModel;
|
|
|
1201
1202
|
}
|
|
1202
1203
|
});
|
|
1203
1204
|
}); });
|
|
1205
|
+
(0, bun_test_1.it)("terminate timeout callback reports the timeout and exits with code 2", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1206
|
+
var func, closeTimer, runCloseTimer;
|
|
1207
|
+
return __generator(this, function (_a) {
|
|
1208
|
+
switch (_a.label) {
|
|
1209
|
+
case 0:
|
|
1210
|
+
func = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1211
|
+
return [2 /*return*/, "ok"];
|
|
1212
|
+
}); }); };
|
|
1213
|
+
return [4 /*yield*/, (0, bun_test_1.expect)((0, expressServer_1.wrapScript)(func, { terminateTimeout: 100 })).rejects.toThrow("__EXIT__")];
|
|
1214
|
+
case 1:
|
|
1215
|
+
_a.sent();
|
|
1216
|
+
closeTimer = timerCallbacks.find(function (t) { return t.delay === 100000; });
|
|
1217
|
+
(0, bun_test_1.expect)(closeTimer).toBeDefined();
|
|
1218
|
+
runCloseTimer = closeTimer === null || closeTimer === void 0 ? void 0 : closeTimer.callback;
|
|
1219
|
+
return [4 /*yield*/, (0, bun_test_1.expect)(runCloseTimer()).rejects.toThrow("__EXIT__")];
|
|
1220
|
+
case 2:
|
|
1221
|
+
_a.sent();
|
|
1222
|
+
(0, bun_test_1.expect)(process.exit).toHaveBeenCalledWith(2);
|
|
1223
|
+
return [2 /*return*/];
|
|
1224
|
+
}
|
|
1225
|
+
});
|
|
1226
|
+
}); });
|
|
1204
1227
|
});
|
|
1205
1228
|
(0, bun_test_1.describe)("TerrenoApp error handling", function () {
|
|
1206
1229
|
var originalEnv = process.env;
|
package/dist/githubAuth.js
CHANGED
|
@@ -58,6 +58,7 @@ var plugins_1 = require("./plugins");
|
|
|
58
58
|
* userSchema.plugin(githubUserPlugin);
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
+
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
61
62
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
62
63
|
var githubUserPlugin = function (schema) {
|
|
63
64
|
schema.add({
|
|
@@ -82,6 +83,7 @@ var setupGitHubAuth = function (_app, userModel, githubOptions) {
|
|
|
82
83
|
var _a;
|
|
83
84
|
var scope = (_a = githubOptions.scope) !== null && _a !== void 0 ? _a : ["user:email"];
|
|
84
85
|
passport_1.default.use("github",
|
|
86
|
+
// noExplicitAny: passport-github2's typed constructor overloads don't match passReqToCallback variant
|
|
85
87
|
// biome-ignore lint/suspicious/noExplicitAny: passport-github2's typed constructor overloads don't match passReqToCallback variant
|
|
86
88
|
new passport_github2_1.Strategy({
|
|
87
89
|
callbackURL: githubOptions.callbackURL,
|
package/dist/githubAuth.test.js
CHANGED
|
@@ -72,6 +72,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
72
72
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
73
|
};
|
|
74
74
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
+
// noExplicitAny: test mock typing
|
|
75
76
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
76
77
|
var bun_test_1 = require("bun:test");
|
|
77
78
|
var mongoose_1 = __importStar(require("mongoose"));
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export * from "./middleware";
|
|
|
18
18
|
export * from "./models/consentForm";
|
|
19
19
|
export * from "./models/consentResponse";
|
|
20
20
|
export * from "./models/versionConfig";
|
|
21
|
-
export * from "./notifiers";
|
|
21
|
+
export * from "./notifiers/googleChatNotifier";
|
|
22
|
+
export * from "./notifiers/slackNotifier";
|
|
23
|
+
export * from "./notifiers/zoomNotifier";
|
|
22
24
|
export * from "./openApiBuilder";
|
|
23
25
|
export * from "./openApiCompat";
|
|
24
26
|
export * from "./openApiEtag";
|
|
@@ -26,7 +28,12 @@ export * from "./openApiValidator";
|
|
|
26
28
|
export * from "./permissions";
|
|
27
29
|
export * from "./plugins";
|
|
28
30
|
export * from "./populate";
|
|
29
|
-
export
|
|
31
|
+
export { startChangeStreamWatcher, stopChangeStreamWatcher, } from "./realtime/changeStreamWatcher";
|
|
32
|
+
export { matchesQuery } from "./realtime/queryMatcher";
|
|
33
|
+
export { addQuerySubscription, clearQueryStore, computeQueryId, getQuerySubscriptionsForCollection, removeAllSocketQueries, removeQuerySubscription, } from "./realtime/queryStore";
|
|
34
|
+
export { installRealtimeSocketHandlers, MAX_DOCUMENT_SUBSCRIPTIONS, MAX_MODEL_SUBSCRIPTIONS, MAX_QUERY_SUBSCRIPTIONS, RealtimeApp, type RealtimeSocketLike, } from "./realtime/realtimeApp";
|
|
35
|
+
export { clearRealtimeRegistry, findRegistryEntryByCollection, findRegistryEntryByRoutePath, getRealtimeRegistry, type RealtimeRegistryEntry, registerRealtime, } from "./realtime/registry";
|
|
36
|
+
export type { ChangeStreamConfig, DocumentSubscription, QuerySubscription, RealtimeAppOptions, RealtimeConfig, RealtimeEvent, } from "./realtime/types";
|
|
30
37
|
export * from "./requestContext";
|
|
31
38
|
export * from "./scriptRunner";
|
|
32
39
|
export * from "./secretProviders";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.z = void 0;
|
|
17
|
+
exports.z = exports.registerRealtime = exports.getRealtimeRegistry = exports.findRegistryEntryByRoutePath = exports.findRegistryEntryByCollection = exports.clearRealtimeRegistry = exports.RealtimeApp = exports.MAX_QUERY_SUBSCRIPTIONS = exports.MAX_MODEL_SUBSCRIPTIONS = exports.MAX_DOCUMENT_SUBSCRIPTIONS = exports.installRealtimeSocketHandlers = exports.removeQuerySubscription = exports.removeAllSocketQueries = exports.getQuerySubscriptionsForCollection = exports.computeQueryId = exports.clearQueryStore = exports.addQuerySubscription = exports.matchesQuery = exports.stopChangeStreamWatcher = exports.startChangeStreamWatcher = void 0;
|
|
18
18
|
__exportStar(require("./actions"), exports);
|
|
19
19
|
__exportStar(require("./api"), exports);
|
|
20
20
|
__exportStar(require("./auth"), exports);
|
|
@@ -35,7 +35,9 @@ __exportStar(require("./middleware"), exports);
|
|
|
35
35
|
__exportStar(require("./models/consentForm"), exports);
|
|
36
36
|
__exportStar(require("./models/consentResponse"), exports);
|
|
37
37
|
__exportStar(require("./models/versionConfig"), exports);
|
|
38
|
-
__exportStar(require("./notifiers"), exports);
|
|
38
|
+
__exportStar(require("./notifiers/googleChatNotifier"), exports);
|
|
39
|
+
__exportStar(require("./notifiers/slackNotifier"), exports);
|
|
40
|
+
__exportStar(require("./notifiers/zoomNotifier"), exports);
|
|
39
41
|
__exportStar(require("./openApiBuilder"), exports);
|
|
40
42
|
__exportStar(require("./openApiCompat"), exports);
|
|
41
43
|
__exportStar(require("./openApiEtag"), exports);
|
|
@@ -43,7 +45,30 @@ __exportStar(require("./openApiValidator"), exports);
|
|
|
43
45
|
__exportStar(require("./permissions"), exports);
|
|
44
46
|
__exportStar(require("./plugins"), exports);
|
|
45
47
|
__exportStar(require("./populate"), exports);
|
|
46
|
-
|
|
48
|
+
var changeStreamWatcher_1 = require("./realtime/changeStreamWatcher");
|
|
49
|
+
Object.defineProperty(exports, "startChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.startChangeStreamWatcher; } });
|
|
50
|
+
Object.defineProperty(exports, "stopChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.stopChangeStreamWatcher; } });
|
|
51
|
+
var queryMatcher_1 = require("./realtime/queryMatcher");
|
|
52
|
+
Object.defineProperty(exports, "matchesQuery", { enumerable: true, get: function () { return queryMatcher_1.matchesQuery; } });
|
|
53
|
+
var queryStore_1 = require("./realtime/queryStore");
|
|
54
|
+
Object.defineProperty(exports, "addQuerySubscription", { enumerable: true, get: function () { return queryStore_1.addQuerySubscription; } });
|
|
55
|
+
Object.defineProperty(exports, "clearQueryStore", { enumerable: true, get: function () { return queryStore_1.clearQueryStore; } });
|
|
56
|
+
Object.defineProperty(exports, "computeQueryId", { enumerable: true, get: function () { return queryStore_1.computeQueryId; } });
|
|
57
|
+
Object.defineProperty(exports, "getQuerySubscriptionsForCollection", { enumerable: true, get: function () { return queryStore_1.getQuerySubscriptionsForCollection; } });
|
|
58
|
+
Object.defineProperty(exports, "removeAllSocketQueries", { enumerable: true, get: function () { return queryStore_1.removeAllSocketQueries; } });
|
|
59
|
+
Object.defineProperty(exports, "removeQuerySubscription", { enumerable: true, get: function () { return queryStore_1.removeQuerySubscription; } });
|
|
60
|
+
var realtimeApp_1 = require("./realtime/realtimeApp");
|
|
61
|
+
Object.defineProperty(exports, "installRealtimeSocketHandlers", { enumerable: true, get: function () { return realtimeApp_1.installRealtimeSocketHandlers; } });
|
|
62
|
+
Object.defineProperty(exports, "MAX_DOCUMENT_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_DOCUMENT_SUBSCRIPTIONS; } });
|
|
63
|
+
Object.defineProperty(exports, "MAX_MODEL_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_MODEL_SUBSCRIPTIONS; } });
|
|
64
|
+
Object.defineProperty(exports, "MAX_QUERY_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_QUERY_SUBSCRIPTIONS; } });
|
|
65
|
+
Object.defineProperty(exports, "RealtimeApp", { enumerable: true, get: function () { return realtimeApp_1.RealtimeApp; } });
|
|
66
|
+
var registry_1 = require("./realtime/registry");
|
|
67
|
+
Object.defineProperty(exports, "clearRealtimeRegistry", { enumerable: true, get: function () { return registry_1.clearRealtimeRegistry; } });
|
|
68
|
+
Object.defineProperty(exports, "findRegistryEntryByCollection", { enumerable: true, get: function () { return registry_1.findRegistryEntryByCollection; } });
|
|
69
|
+
Object.defineProperty(exports, "findRegistryEntryByRoutePath", { enumerable: true, get: function () { return registry_1.findRegistryEntryByRoutePath; } });
|
|
70
|
+
Object.defineProperty(exports, "getRealtimeRegistry", { enumerable: true, get: function () { return registry_1.getRealtimeRegistry; } });
|
|
71
|
+
Object.defineProperty(exports, "registerRealtime", { enumerable: true, get: function () { return registry_1.registerRealtime; } });
|
|
47
72
|
__exportStar(require("./requestContext"), exports);
|
|
48
73
|
__exportStar(require("./scriptRunner"), exports);
|
|
49
74
|
__exportStar(require("./secretProviders"), exports);
|
package/dist/logger.test.js
CHANGED
|
@@ -10,6 +10,39 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
13
46
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
47
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
48
|
};
|
|
@@ -19,6 +52,7 @@ var node_fs_1 = __importDefault(require("node:fs"));
|
|
|
19
52
|
var node_os_1 = __importDefault(require("node:os"));
|
|
20
53
|
var node_path_1 = __importDefault(require("node:path"));
|
|
21
54
|
var node_stream_1 = require("node:stream");
|
|
55
|
+
var Sentry = __importStar(require("@sentry/bun"));
|
|
22
56
|
var winston_1 = __importDefault(require("winston"));
|
|
23
57
|
var logger_1 = require("./logger");
|
|
24
58
|
var requestContext_1 = require("./requestContext");
|
|
@@ -53,6 +87,55 @@ var requestContext_1 = require("./requestContext");
|
|
|
53
87
|
(0, bun_test_1.expect)(function () { return logger_1.logger.catch(new Error("captured")); }).not.toThrow();
|
|
54
88
|
});
|
|
55
89
|
});
|
|
90
|
+
(0, bun_test_1.describe)("logger Sentry structured logging", function () {
|
|
91
|
+
(0, bun_test_1.afterEach)(function () {
|
|
92
|
+
Reflect.deleteProperty(process.env, "USE_SENTRY_LOGGING");
|
|
93
|
+
});
|
|
94
|
+
(0, bun_test_1.it)("forwards every level to Sentry.logger when USE_SENTRY_LOGGING is true", function () {
|
|
95
|
+
var _a, _b, _c, _d;
|
|
96
|
+
process.env.USE_SENTRY_LOGGING = "true";
|
|
97
|
+
logger_1.logger.debug("sentry-debug-message");
|
|
98
|
+
logger_1.logger.info("sentry-info-message");
|
|
99
|
+
logger_1.logger.warn("sentry-warn-message");
|
|
100
|
+
logger_1.logger.error("sentry-error-message");
|
|
101
|
+
(0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.debug).toHaveBeenCalledWith("sentry-debug-message", bun_test_1.expect.anything());
|
|
102
|
+
(0, bun_test_1.expect)((_b = Sentry.logger) === null || _b === void 0 ? void 0 : _b.info).toHaveBeenCalledWith("sentry-info-message", bun_test_1.expect.anything());
|
|
103
|
+
(0, bun_test_1.expect)((_c = Sentry.logger) === null || _c === void 0 ? void 0 : _c.warn).toHaveBeenCalledWith("sentry-warn-message", bun_test_1.expect.anything());
|
|
104
|
+
(0, bun_test_1.expect)((_d = Sentry.logger) === null || _d === void 0 ? void 0 : _d.error).toHaveBeenCalledWith("sentry-error-message", bun_test_1.expect.anything());
|
|
105
|
+
});
|
|
106
|
+
(0, bun_test_1.it)("does not forward to Sentry.logger when USE_SENTRY_LOGGING is unset", function () {
|
|
107
|
+
var _a;
|
|
108
|
+
Reflect.deleteProperty(process.env, "USE_SENTRY_LOGGING");
|
|
109
|
+
(0, bun_test_1.expect)(function () { return logger_1.logger.info("no-sentry-message"); }).not.toThrow();
|
|
110
|
+
(0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.info).not.toHaveBeenCalledWith("no-sentry-message", bun_test_1.expect.anything());
|
|
111
|
+
});
|
|
112
|
+
(0, bun_test_1.it)("attaches terrenoRequestLog to Sentry attributes inside a request scope", function () {
|
|
113
|
+
var _a;
|
|
114
|
+
process.env.USE_SENTRY_LOGGING = "true";
|
|
115
|
+
(0, requestContext_1.runWithRequestContext)({ requestId: "sentry-req-1", userId: "sentry-user-1" }, function () {
|
|
116
|
+
logger_1.logger.info("sentry-request-scoped-message");
|
|
117
|
+
});
|
|
118
|
+
(0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.info).toHaveBeenCalledWith("sentry-request-scoped-message", bun_test_1.expect.objectContaining({
|
|
119
|
+
terrenoRequestLog: bun_test_1.expect.objectContaining({
|
|
120
|
+
requestId: "sentry-req-1",
|
|
121
|
+
userId: "sentry-user-1",
|
|
122
|
+
}),
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
(0, bun_test_1.it)("logs a caught non-Error value via Sentry.logger.error when enabled", function () {
|
|
126
|
+
var _a;
|
|
127
|
+
process.env.USE_SENTRY_LOGGING = "true";
|
|
128
|
+
(0, bun_test_1.expect)(function () { return logger_1.logger.catch("plain-string-failure"); }).not.toThrow();
|
|
129
|
+
(0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.error).toHaveBeenCalled();
|
|
130
|
+
});
|
|
131
|
+
(0, bun_test_1.it)("scoped logger catch logs a non-Error value via Sentry.logger.error when enabled", function () {
|
|
132
|
+
var _a;
|
|
133
|
+
process.env.USE_SENTRY_LOGGING = "true";
|
|
134
|
+
var scoped = (0, logger_1.createScopedLogger)({ labels: { jobId: "j1" }, prefix: "[SentryScoped]" });
|
|
135
|
+
(0, bun_test_1.expect)(function () { return scoped.catch("scoped-plain-failure"); }).not.toThrow();
|
|
136
|
+
(0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.error).toHaveBeenCalled();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
56
139
|
(0, bun_test_1.describe)("formatLogContextSuffix", function () {
|
|
57
140
|
(0, bun_test_1.it)("includes request ids and sorts terrenoLabels for stable output", function () {
|
|
58
141
|
var suffix = (0, logger_1.formatLogContextSuffix)({
|
|
@@ -575,4 +658,28 @@ var requestContext_1 = require("./requestContext");
|
|
|
575
658
|
});
|
|
576
659
|
}).not.toThrow();
|
|
577
660
|
});
|
|
661
|
+
(0, bun_test_1.it)("attaches the dev JSONL transport when TERRENO_LOG_FILE forces it on", function () {
|
|
662
|
+
var originalCwd = process.cwd();
|
|
663
|
+
process.env.TERRENO_LOG_FILE = "true";
|
|
664
|
+
try {
|
|
665
|
+
process.chdir(tempDir);
|
|
666
|
+
(0, logger_1.setupLogging)({ disableConsoleLogging: true, disableFileLogging: true });
|
|
667
|
+
(0, bun_test_1.expect)(node_fs_1.default.existsSync(node_path_1.default.join(tempDir, ".terreno", "logs"))).toBe(true);
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
process.chdir(originalCwd);
|
|
671
|
+
Reflect.deleteProperty(process.env, "TERRENO_LOG_FILE");
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
(0, bun_test_1.it)("skips the dev JSONL transport when TERRENO_LOG_FILE forces it off", function () {
|
|
675
|
+
process.env.TERRENO_LOG_FILE = "false";
|
|
676
|
+
try {
|
|
677
|
+
(0, bun_test_1.expect)(function () {
|
|
678
|
+
return (0, logger_1.setupLogging)({ disableConsoleLogging: true, disableFileLogging: true });
|
|
679
|
+
}).not.toThrow();
|
|
680
|
+
}
|
|
681
|
+
finally {
|
|
682
|
+
Reflect.deleteProperty(process.env, "TERRENO_LOG_FILE");
|
|
683
|
+
}
|
|
684
|
+
});
|
|
578
685
|
});
|
package/dist/openApi.test.js
CHANGED
|
@@ -66,6 +66,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
66
66
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
67
67
|
};
|
|
68
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
// noExplicitAny: test mock typing
|
|
69
70
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
70
71
|
var bun_test_1 = require("bun:test");
|
|
71
72
|
var supertest_1 = __importDefault(require("supertest"));
|
|
@@ -293,6 +294,57 @@ function addRoutes(router, options) {
|
|
|
293
294
|
});
|
|
294
295
|
}); });
|
|
295
296
|
});
|
|
297
|
+
function addRoutesStringQuery(router, options) {
|
|
298
|
+
router.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, __assign(__assign({}, options), { allowAnonymous: true, permissions: {
|
|
299
|
+
create: [permissions_1.Permissions.IsAny],
|
|
300
|
+
delete: [permissions_1.Permissions.IsAny],
|
|
301
|
+
list: [permissions_1.Permissions.IsAny],
|
|
302
|
+
read: [permissions_1.Permissions.IsAny],
|
|
303
|
+
update: [permissions_1.Permissions.IsAny],
|
|
304
|
+
}, queryFields: ["name"] })));
|
|
305
|
+
}
|
|
306
|
+
(0, bun_test_1.describe)("openApi string query fields", function () {
|
|
307
|
+
var server;
|
|
308
|
+
var app;
|
|
309
|
+
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
310
|
+
return __generator(this, function (_a) {
|
|
311
|
+
process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
|
|
312
|
+
process.env.ENABLE_SWAGGER = "true";
|
|
313
|
+
app = new terrenoApp_1.TerrenoApp({
|
|
314
|
+
configureApp: addRoutesStringQuery,
|
|
315
|
+
skipListen: true,
|
|
316
|
+
userModel: tests_1.UserModel,
|
|
317
|
+
}).build();
|
|
318
|
+
return [2 /*return*/];
|
|
319
|
+
});
|
|
320
|
+
}); });
|
|
321
|
+
(0, bun_test_1.it)("builds an $in array query param for non-numeric query fields", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
322
|
+
var res, nameQuery;
|
|
323
|
+
return __generator(this, function (_a) {
|
|
324
|
+
switch (_a.label) {
|
|
325
|
+
case 0:
|
|
326
|
+
server = (0, supertest_1.default)(app);
|
|
327
|
+
return [4 /*yield*/, server.get("/openapi.json").expect(200)];
|
|
328
|
+
case 1:
|
|
329
|
+
res = _a.sent();
|
|
330
|
+
nameQuery = res.body.paths["/food/"].get.parameters.find(function (p) { return p.name === "name"; });
|
|
331
|
+
// Non-number/non-datetime fields support equality and $in array matching.
|
|
332
|
+
(0, bun_test_1.expect)(nameQuery.schema).toEqual({
|
|
333
|
+
oneOf: [
|
|
334
|
+
{ description: "The name of the food", type: "string" },
|
|
335
|
+
{
|
|
336
|
+
properties: {
|
|
337
|
+
$in: { items: { type: "string" }, type: "array" },
|
|
338
|
+
},
|
|
339
|
+
type: "object",
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
});
|
|
343
|
+
return [2 /*return*/];
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}); });
|
|
347
|
+
});
|
|
296
348
|
function addRoutesPopulate(router, options) {
|
|
297
349
|
var _a;
|
|
298
350
|
(_a = options === null || options === void 0 ? void 0 : options.openApi) === null || _a === void 0 ? void 0 : _a.component("schemas", "LimitedUser", {
|
package/dist/openApiBuilder.js
CHANGED
|
@@ -459,7 +459,8 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
459
459
|
* router.get("/users/:id", middleware, getUserHandler);
|
|
460
460
|
* ```
|
|
461
461
|
*/
|
|
462
|
-
//
|
|
462
|
+
// noExplicitAny: returns either a single RequestHandler or an array depending on validation config — callers spread or invoke
|
|
463
|
+
// biome-ignore lint/suspicious/noExplicitAny: returns either a single RequestHandler or an array depending on validation config
|
|
463
464
|
OpenApiMiddlewareBuilder.prototype.build = function () {
|
|
464
465
|
var _c, _d, _e, _f, _g;
|
|
465
466
|
var noop = function (_a, _b, next) { return next(); };
|
|
@@ -50,6 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
// noExplicitAny: test mock typing
|
|
53
54
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
54
55
|
var bun_test_1 = require("bun:test");
|
|
55
56
|
var supertest_1 = __importDefault(require("supertest"));
|
|
@@ -569,14 +570,14 @@ function addRoutesWithBuilder(router, options) {
|
|
|
569
570
|
.buildWithSchemas();
|
|
570
571
|
(0, bun_test_1.expect)(result.validationEnabled).toBe(false);
|
|
571
572
|
});
|
|
572
|
-
(0, bun_test_1.it)("build() returns an array
|
|
573
|
+
(0, bun_test_1.it)("build() returns an array when validation is enabled with body and query", function () {
|
|
573
574
|
var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
|
|
574
575
|
.withRequestBody({ name: { required: true, type: "string" } })
|
|
575
576
|
.withQueryParameter("page", { type: "number" })
|
|
576
577
|
.withValidation()
|
|
577
578
|
.build();
|
|
578
579
|
(0, bun_test_1.expect)(Array.isArray(result)).toBe(true);
|
|
579
|
-
(0, bun_test_1.expect)(result
|
|
580
|
+
(0, bun_test_1.expect)(result).toHaveLength(3);
|
|
580
581
|
});
|
|
581
582
|
(0, bun_test_1.it)("build() returns a single middleware when validation is disabled", function () {
|
|
582
583
|
var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
|
package/dist/openApiValidator.js
CHANGED
|
@@ -191,6 +191,7 @@ var getAjvInstance = function () {
|
|
|
191
191
|
useDefaults: true,
|
|
192
192
|
validateSchema: false,
|
|
193
193
|
});
|
|
194
|
+
// noExplicitAny: ajv-formats has a known type compat issue with AJV instances
|
|
194
195
|
// biome-ignore lint/suspicious/noExplicitAny: ajv-formats has a known type compat issue with AJV instances
|
|
195
196
|
(0, ajv_formats_1.default)(instance);
|
|
196
197
|
ajvCache.set(key, instance);
|
|
@@ -72,6 +72,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
72
72
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
73
|
};
|
|
74
74
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
+
// noExplicitAny: test mock typing
|
|
75
76
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
76
77
|
var bun_test_1 = require("bun:test");
|
|
77
78
|
var api_1 = require("./api");
|
|
@@ -717,4 +718,44 @@ var setupFreshApp = function () { return __awaiter(void 0, void 0, void 0, funct
|
|
|
717
718
|
(0, bun_test_1.expect)((0, openApiValidator_1.getOpenApiValidatorConfig)().removeAdditional).toBe(false);
|
|
718
719
|
});
|
|
719
720
|
});
|
|
721
|
+
(0, bun_test_1.describe)("schema sanitization and validator caching", function () {
|
|
722
|
+
var runMiddleware = function (middleware, req) {
|
|
723
|
+
var nextCalled = false;
|
|
724
|
+
middleware(req, {}, function () {
|
|
725
|
+
nextCalled = true;
|
|
726
|
+
});
|
|
727
|
+
return nextCalled;
|
|
728
|
+
};
|
|
729
|
+
// An unresolvable $ref makes ajv.compile throw, so getValidator catches the error
|
|
730
|
+
// and returns null. Built via `unknown` to keep the non-standard keyword out of the
|
|
731
|
+
// typed surface (and out of the explicit-any baseline).
|
|
732
|
+
var uncompilableSchema = {
|
|
733
|
+
broken: { $ref: "#/components/schemas/DoesNotExist" },
|
|
734
|
+
};
|
|
735
|
+
(0, bun_test_1.it)("maps an unrecognized mongoose type to string so the schema still compiles", function () {
|
|
736
|
+
(0, openApiValidator_1.configureOpenApiValidator)();
|
|
737
|
+
// "buffer" is neither a valid JSON Schema type nor present in MONGOOSE_TYPE_MAP,
|
|
738
|
+
// so sanitizeSchemaForAjv falls through to the `type = "string"` branch.
|
|
739
|
+
var middleware = (0, openApiValidator_1.validateRequestBody)({ raw: { type: "buffer" } });
|
|
740
|
+
(0, bun_test_1.expect)(runMiddleware(middleware, { body: { raw: "some-string" }, method: "POST", path: "/t" })).toBe(true);
|
|
741
|
+
});
|
|
742
|
+
(0, bun_test_1.it)("reuses the cached validator on subsequent requests with the same schema", function () {
|
|
743
|
+
(0, openApiValidator_1.configureOpenApiValidator)();
|
|
744
|
+
var middleware = (0, openApiValidator_1.validateRequestBody)({ name: { type: "string" } });
|
|
745
|
+
var req = { body: { name: "ok" }, method: "POST", path: "/t" };
|
|
746
|
+
// First request compiles and caches the validator; the second must hit the cache.
|
|
747
|
+
(0, bun_test_1.expect)(runMiddleware(middleware, req)).toBe(true);
|
|
748
|
+
(0, bun_test_1.expect)(runMiddleware(middleware, req)).toBe(true);
|
|
749
|
+
});
|
|
750
|
+
(0, bun_test_1.it)("skips query validation when the schema cannot be compiled", function () {
|
|
751
|
+
(0, openApiValidator_1.configureOpenApiValidator)();
|
|
752
|
+
var middleware = (0, openApiValidator_1.validateQueryParams)(uncompilableSchema);
|
|
753
|
+
(0, bun_test_1.expect)(runMiddleware(middleware, { method: "GET", path: "/t", query: { broken: "x" } })).toBe(true);
|
|
754
|
+
});
|
|
755
|
+
(0, bun_test_1.it)("skips response validation when the schema cannot be compiled", function () {
|
|
756
|
+
(0, openApiValidator_1.configureOpenApiValidator)({ validateResponses: true });
|
|
757
|
+
var result = (0, openApiValidator_1.validateResponseData)({ broken: "x" }, uncompilableSchema);
|
|
758
|
+
(0, bun_test_1.expect)(result.valid).toBe(true);
|
|
759
|
+
});
|
|
760
|
+
});
|
|
720
761
|
});
|
|
@@ -96,6 +96,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
96
96
|
return ar;
|
|
97
97
|
};
|
|
98
98
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
99
|
+
// noExplicitAny: test mock typing
|
|
99
100
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
100
101
|
var bun_test_1 = require("bun:test");
|
|
101
102
|
var Sentry = __importStar(require("@sentry/bun"));
|