@terreno/api 0.26.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.
Files changed (96) hide show
  1. package/dist/__tests__/openApiCompat.test.js +8 -2
  2. package/dist/actions.openApi.test.js +1 -0
  3. package/dist/actions.test.js +1 -0
  4. package/dist/api.arrayOperations.test.js +1 -0
  5. package/dist/api.coverage.test.d.ts +1 -0
  6. package/dist/api.coverage.test.js +191 -0
  7. package/dist/api.errorPaths.test.d.ts +1 -0
  8. package/dist/api.errorPaths.test.js +278 -0
  9. package/dist/api.errors.test.js +1 -0
  10. package/dist/api.hooks.test.js +1 -0
  11. package/dist/api.js +160 -167
  12. package/dist/api.query.test.js +1 -0
  13. package/dist/api.test.js +1 -0
  14. package/dist/auth.js +1 -0
  15. package/dist/auth.test.js +122 -0
  16. package/dist/betterAuthSetup.js +1 -0
  17. package/dist/betterAuthSetup.test.js +1 -0
  18. package/dist/configuration.test.js +1 -0
  19. package/dist/configurationApp.js +1 -0
  20. package/dist/configurationPlugin.test.js +80 -0
  21. package/dist/consentApp.test.js +1 -0
  22. package/dist/docLoader.js +1 -3
  23. package/dist/envConfigurationPlugin.js +1 -0
  24. package/dist/example.js +3 -2
  25. package/dist/expressServer.test.js +1 -0
  26. package/dist/githubAuth.js +2 -0
  27. package/dist/githubAuth.test.js +1 -0
  28. package/dist/logger.test.js +107 -0
  29. package/dist/openApi.test.js +1 -0
  30. package/dist/openApiBuilder.js +2 -1
  31. package/dist/openApiBuilder.test.js +3 -2
  32. package/dist/openApiValidator.js +1 -0
  33. package/dist/openApiValidator.test.js +41 -0
  34. package/dist/permissions.middleware.test.js +1 -0
  35. package/dist/permissions.test.js +1 -0
  36. package/dist/plugins.js +8 -0
  37. package/dist/plugins.test.js +1 -0
  38. package/dist/populate.js +4 -2
  39. package/dist/populate.test.js +1 -0
  40. package/dist/realtime/realtime.test.js +13 -3
  41. package/dist/realtime/types.d.ts +1 -1
  42. package/dist/requestContext.test.js +28 -0
  43. package/dist/terrenoApp.js +1 -0
  44. package/dist/tests/createTestData.js +11 -6
  45. package/dist/tests/models.js +1 -0
  46. package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +3 -1
  47. package/package.json +7 -7
  48. package/src/__tests__/openApiCompat.test.ts +8 -2
  49. package/src/actions.openApi.test.ts +1 -0
  50. package/src/actions.test.ts +1 -0
  51. package/src/api.arrayOperations.test.ts +1 -0
  52. package/src/api.coverage.test.ts +121 -0
  53. package/src/api.errorPaths.test.ts +171 -0
  54. package/src/api.errors.test.ts +1 -0
  55. package/src/api.hooks.test.ts +1 -0
  56. package/src/api.query.test.ts +1 -0
  57. package/src/api.test.ts +1 -0
  58. package/src/api.ts +13 -9
  59. package/src/auth.test.ts +91 -2
  60. package/src/auth.ts +6 -0
  61. package/src/betterAuthSetup.test.ts +1 -0
  62. package/src/betterAuthSetup.ts +3 -0
  63. package/src/configuration.test.ts +1 -0
  64. package/src/configurationApp.ts +2 -0
  65. package/src/configurationPlugin.test.ts +46 -1
  66. package/src/consentApp.test.ts +1 -0
  67. package/src/docLoader.ts +1 -2
  68. package/src/envConfigurationPlugin.ts +2 -0
  69. package/src/example.ts +3 -2
  70. package/src/expressServer.test.ts +1 -0
  71. package/src/expressServer.ts +4 -2
  72. package/src/githubAuth.test.ts +1 -0
  73. package/src/githubAuth.ts +2 -0
  74. package/src/logger.test.ts +78 -0
  75. package/src/openApi.test.ts +1 -0
  76. package/src/openApiBuilder.test.ts +7 -6
  77. package/src/openApiBuilder.ts +2 -1
  78. package/src/openApiValidator.test.ts +64 -0
  79. package/src/openApiValidator.ts +1 -0
  80. package/src/permissions.middleware.test.ts +1 -0
  81. package/src/permissions.test.ts +1 -0
  82. package/src/plugins.test.ts +1 -0
  83. package/src/plugins.ts +9 -0
  84. package/src/populate.test.ts +1 -0
  85. package/src/populate.ts +4 -2
  86. package/src/realtime/realtime.test.ts +13 -3
  87. package/src/realtime/realtimeApp.ts +1 -0
  88. package/src/realtime/registry.ts +1 -0
  89. package/src/realtime/types.ts +1 -2
  90. package/src/requestContext.test.ts +32 -0
  91. package/src/terrenoApp.ts +1 -0
  92. package/src/tests/createTestData.ts +11 -6
  93. package/src/tests/models.ts +1 -0
  94. package/src/vendor/wesleytodd-openapi/lib/generate-doc.js +4 -1
  95. package/tsconfig.json +3 -3
  96. /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) {
@@ -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
- // biome-ignore lint/suspicious/noExplicitAny: passport-local-mongoose's plugin type is incompatible with mongoose Schema generics
72
- userSchema.plugin(passport_local_mongoose_1.default, { usernameField: "email" });
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);
@@ -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");
@@ -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,
@@ -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"));
@@ -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
  });
@@ -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"));
@@ -459,7 +459,8 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
459
459
  * router.get("/users/:id", middleware, getUserHandler);
460
460
  * ```
461
461
  */
462
- // biome-ignore lint/suspicious/noExplicitAny: returns either a single RequestHandler or an array depending on validation config — callers spread or invoke
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 with validators when validation is enabled", function () {
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.length).toBeGreaterThan(1);
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)({})
@@ -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"));
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ // noExplicitAny: test mock typing
42
43
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
43
44
  var bun_test_1 = require("bun:test");
44
45
  var supertest_1 = __importDefault(require("supertest"));
package/dist/plugins.js CHANGED
@@ -99,6 +99,7 @@ exports.DateOnly = exports.upsertPlugin = exports.findExactlyOne = exports.findO
99
99
  var luxon_1 = require("luxon");
100
100
  var mongoose_1 = __importStar(require("mongoose"));
101
101
  var errors_1 = require("./errors");
102
+ // noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
102
103
  // biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
103
104
  var baseUserPlugin = function (schema) {
104
105
  schema.add({
@@ -107,6 +108,7 @@ var baseUserPlugin = function (schema) {
107
108
  schema.add({ email: { description: "The user's email address", index: true, type: String } });
108
109
  };
109
110
  exports.baseUserPlugin = baseUserPlugin;
111
+ // noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
110
112
  // biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
111
113
  var isDeletedPlugin = function (schema, defaultValue) {
112
114
  if (defaultValue === void 0) { defaultValue = false; }
@@ -119,6 +121,7 @@ var isDeletedPlugin = function (schema, defaultValue) {
119
121
  type: Boolean,
120
122
  },
121
123
  });
124
+ // noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
122
125
  // biome-ignore lint/suspicious/noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
123
126
  var applyDeleteFilter = function (q) {
124
127
  var query = q.getQuery();
@@ -135,6 +138,7 @@ var isDeletedPlugin = function (schema, defaultValue) {
135
138
  };
136
139
  exports.isDeletedPlugin = isDeletedPlugin;
137
140
  var isDisabledPlugin = function (
141
+ // noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
138
142
  // biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
139
143
  schema, defaultValue) {
140
144
  if (defaultValue === void 0) { defaultValue = false; }
@@ -148,6 +152,7 @@ schema, defaultValue) {
148
152
  });
149
153
  };
150
154
  exports.isDisabledPlugin = isDisabledPlugin;
155
+ // noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
151
156
  // biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
152
157
  var createdUpdatedPlugin = function (schema) {
153
158
  schema.add({
@@ -274,6 +279,7 @@ exports.findExactlyOne = findExactlyOne;
274
279
  * match the conditions to prevent ambiguous updates.
275
280
  * @param schema Mongoose Schema
276
281
  */
282
+ // noExplicitAny: Schema generics with unknown collide with mongoose's loose this-binding on schema.statics
277
283
  // biome-ignore lint/suspicious/noExplicitAny: Schema generics with unknown collide with mongoose's loose this-binding on schema.statics
278
284
  var upsertPlugin = function (schema) {
279
285
  schema.statics.upsert = function (conditions, update) {
@@ -322,6 +328,7 @@ var DateOnly = /** @class */ (function (_super) {
322
328
  // When using $gt, $gte, $lt, $lte, etc, we need to cast the value to a Date
323
329
  DateOnly.prototype.castForQuery = function ($conditional, val, context) {
324
330
  if ($conditional == null) {
331
+ // noExplicitAny: applySetters is an internal Mongoose SchemaType method not in public type definitions
325
332
  // biome-ignore lint/suspicious/noExplicitAny: applySetters is an internal Mongoose SchemaType method not in public type definitions
326
333
  return this.applySetters(val, context);
327
334
  }
@@ -363,5 +370,6 @@ var DateOnly = /** @class */ (function (_super) {
363
370
  }(mongoose_1.SchemaType));
364
371
  exports.DateOnly = DateOnly;
365
372
  // Register DateOnly with Mongoose's Schema.Types
373
+ // noExplicitAny: DateOnly is a custom SchemaType not declared in Mongoose's Schema.Types interface
366
374
  // biome-ignore lint/suspicious/noExplicitAny: DateOnly is a custom SchemaType not declared in Mongoose's Schema.Types interface
367
375
  mongoose_1.default.Schema.Types.DateOnly = DateOnly;
@@ -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 mongoose_1 = require("mongoose");
package/dist/populate.js CHANGED
@@ -158,7 +158,8 @@ var fixMixedFields = function (schema, properties) {
158
158
  };
159
159
  exports.fixMixedFields = fixMixedFields;
160
160
  var getOpenApiSpecForModel = function (
161
- // biome-ignore lint/suspicious/noExplicitAny: noExplicitAny: Mongoose Model param uses deep internal APIs (schema.path().options.ref, schema.virtuals, schema.childSchemas, db.model) that are not exposed in public type definitions
161
+ // noExplicitAny: Mongoose Model param uses deep internal APIs (schema.path().options.ref, schema.virtuals, schema.childSchemas, db.model) that are not exposed in public type definitions
162
+ // biome-ignore lint/suspicious/noExplicitAny: Mongoose Model param uses deep internal APIs (schema.path().options.ref, schema.virtuals, schema.childSchemas, db.model) that are not exposed in public type definitions
162
163
  model, _a) {
163
164
  var e_2, _b, _c, e_3, _d, e_4, _e, e_5, _f;
164
165
  var _g, _h, _j, _k;
@@ -304,7 +305,8 @@ var unpopulate = function (doc, path) {
304
305
  }
305
306
  var pathParts = path.split(".");
306
307
  // Recursive because we need to support nested paths.
307
- // biome-ignore lint/suspicious/noExplicitAny: noExplicitAny: recursive document traversal uses bracket-notation indexing on arbitrary nested document shapes that Mongoose Document types do not expose
308
+ // noExplicitAny: recursive document traversal uses bracket-notation indexing on arbitrary nested document shapes that Mongoose Document types do not expose
309
+ // biome-ignore lint/suspicious/noExplicitAny: recursive document traversal uses bracket-notation indexing on arbitrary nested document shapes that Mongoose Document types do not expose
308
310
  var recursiveUnpopulate = function (current, parts) {
309
311
  var e_6, _a;
310
312
  var _b;
@@ -69,6 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  }
70
70
  };
71
71
  Object.defineProperty(exports, "__esModule", { value: true });
72
+ // noExplicitAny: test mock typing
72
73
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
73
74
  var bun_test_1 = require("bun:test");
74
75
  var mongoose_1 = __importStar(require("mongoose"));
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // noExplicitAny: test mocks use dynamic shapes for registry entries and documents
2
3
  // biome-ignore-all lint/suspicious/noExplicitAny: test mocks use dynamic shapes for registry entries and documents
3
4
  /**
4
5
  * Tests for the realtime module's pure functions and classes:
@@ -1114,7 +1115,10 @@ var createMockSocket = function (decodedToken) {
1114
1115
  _a.sent();
1115
1116
  subscribed = socket.emitted.find(function (e) { return e.event === "query:subscribed"; });
1116
1117
  (0, bun_test_1.expect)(subscribed).toBeDefined();
1117
- (0, bun_test_1.expect)((subscribed === null || subscribed === void 0 ? void 0 : subscribed.payload).queryId).toContain("user1");
1118
+ if (!subscribed) {
1119
+ throw new Error("Expected a query subscription event");
1120
+ }
1121
+ (0, bun_test_1.expect)(subscribed.payload.queryId).toContain("user1");
1118
1122
  return [2 /*return*/];
1119
1123
  }
1120
1124
  });
@@ -1135,7 +1139,10 @@ var createMockSocket = function (decodedToken) {
1135
1139
  _a.sent();
1136
1140
  subscribed = socket.emitted.find(function (e) { return e.event === "query:subscribed"; });
1137
1141
  (0, bun_test_1.expect)(subscribed).toBeDefined();
1138
- (0, bun_test_1.expect)((subscribed === null || subscribed === void 0 ? void 0 : subscribed.payload).queryId).not.toContain("admin1");
1142
+ if (!subscribed) {
1143
+ throw new Error("Expected a query subscription event");
1144
+ }
1145
+ (0, bun_test_1.expect)(subscribed.payload.queryId).not.toContain("admin1");
1139
1146
  return [2 /*return*/];
1140
1147
  }
1141
1148
  });
@@ -1438,7 +1445,10 @@ var createMockSocket = function (decodedToken) {
1438
1445
  _a.sent();
1439
1446
  subscribed = socket.emitted.find(function (e) { return e.event === "query:subscribed"; });
1440
1447
  (0, bun_test_1.expect)(subscribed).toBeDefined();
1441
- queryId = (subscribed === null || subscribed === void 0 ? void 0 : subscribed.payload).queryId;
1448
+ if (!subscribed) {
1449
+ throw new Error("Expected a query subscription event");
1450
+ }
1451
+ queryId = subscribed.payload.queryId;
1442
1452
  (0, bun_test_1.expect)(socket.rooms.has("query:".concat(queryId))).toBe(true);
1443
1453
  (0, bun_test_1.expect)((0, queryStore_1.getQuerySubscriptionsForCollection)("broadcasts").length).toBe(1);
1444
1454
  return [4 /*yield*/, socket.trigger("unsubscribe:query", { queryId: queryId })];
@@ -30,7 +30,7 @@ export interface RealtimeEvent {
30
30
  /** Document ID */
31
31
  id: string;
32
32
  /** Serialized document data (omitted for hard deletes) */
33
- data?: any;
33
+ data?: unknown;
34
34
  /** Fields that were updated (for update events from change streams) */
35
35
  updatedFields?: string[];
36
36
  /** Epoch milliseconds when the event was generated */
@@ -355,6 +355,34 @@ var requestContext_1 = require("./requestContext");
355
355
  });
356
356
  (0, bun_test_1.expect)(ctx.traceId).toBeUndefined();
357
357
  });
358
+ (0, bun_test_1.it)("returns undefined trace when google cloud trace context has empty trace id", function () {
359
+ var ctx = (0, requestContext_1.getRequestContextFromAttributes)({
360
+ "x-cloud-trace-context": "/1;o=1",
361
+ "x-request-id": "r7",
362
+ });
363
+ (0, bun_test_1.expect)(ctx.traceId).toBeUndefined();
364
+ (0, bun_test_1.expect)(ctx.spanId).toBeUndefined();
365
+ (0, bun_test_1.expect)(ctx.requestId).toBe("r7");
366
+ });
367
+ (0, bun_test_1.it)("reads the first value when a request header arrives as an array", function () {
368
+ var headers = {
369
+ "x-cloud-trace-context": ["arrtrace/7;o=1", "ignored/9;o=0"],
370
+ };
371
+ var req = {
372
+ header: function (name) { return headers[name.toLowerCase()]; },
373
+ user: undefined,
374
+ };
375
+ var res = {
376
+ setHeader: function () { },
377
+ };
378
+ var captured;
379
+ (0, requestContext_1.requestContextMiddleware)(req, res, function () {
380
+ var ctx = (0, requestContext_1.getCurrentRequestContext)();
381
+ captured = { spanId: ctx === null || ctx === void 0 ? void 0 : ctx.spanId, traceId: ctx === null || ctx === void 0 ? void 0 : ctx.traceId };
382
+ });
383
+ (0, bun_test_1.expect)(captured === null || captured === void 0 ? void 0 : captured.traceId).toBe("arrtrace");
384
+ (0, bun_test_1.expect)(captured === null || captured === void 0 ? void 0 : captured.spanId).toBe("7");
385
+ });
358
386
  (0, bun_test_1.it)("adds job id to logger context", function () {
359
387
  var output = "";
360
388
  var stream = new node_stream_1.Writable({
@@ -218,6 +218,7 @@ var TerrenoApp = /** @class */ (function () {
218
218
  * ```
219
219
  */
220
220
  TerrenoApp.prototype.configure = function (
221
+ // noExplicitAny: Model<any> required for invariance — consumers pass arbitrary configuration models
221
222
  // biome-ignore lint/suspicious/noExplicitAny: Model<any> required for invariance — consumers pass arbitrary configuration models
222
223
  model, options) {
223
224
  this.configurationApp = new configurationApp_1.ConfigurationApp(__assign({ model: model }, options));