@terreno/api 57.4.0 → 57.6.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 (208) hide show
  1. package/README.md +5 -5
  2. package/bunfig.toml +1 -1
  3. package/dist/actions.js +197 -368
  4. package/dist/adminModelRouter.js +88 -173
  5. package/dist/api.js +598 -852
  6. package/dist/audit/auditApp.js +48 -89
  7. package/dist/audit/auditEventModel.js +15 -16
  8. package/dist/audit/cloudTasksEnqueue.js +56 -149
  9. package/dist/audit/diff.js +70 -160
  10. package/dist/audit/processQueue.js +25 -70
  11. package/dist/audit/rbacSink.js +25 -66
  12. package/dist/audit/record.js +129 -251
  13. package/dist/auth.js +432 -681
  14. package/dist/authRecovery.js +155 -269
  15. package/dist/authTokens.js +43 -118
  16. package/dist/betterAuthApp.js +25 -26
  17. package/dist/betterAuthSetup.js +258 -413
  18. package/dist/browserLogsRoute.d.ts +6 -0
  19. package/dist/browserLogsRoute.js +97 -0
  20. package/dist/collectionRegistry.js +32 -47
  21. package/dist/config.js +53 -122
  22. package/dist/configurationApp.js +180 -361
  23. package/dist/configurationPlugin.js +130 -302
  24. package/dist/consentApp.js +276 -421
  25. package/dist/docLoader.js +78 -126
  26. package/dist/envConfigurationPlugin.js +25 -147
  27. package/dist/errors.js +151 -247
  28. package/dist/example.js +28 -34
  29. package/dist/expressServer.d.ts +10 -0
  30. package/dist/expressServer.js +109 -255
  31. package/dist/frameworkModelNames.d.ts +24 -0
  32. package/dist/frameworkModelNames.js +31 -0
  33. package/dist/githubAuth.js +152 -216
  34. package/dist/httpClient.js +176 -264
  35. package/dist/index.d.ts +2 -0
  36. package/dist/index.js +7 -2
  37. package/dist/logger.js +145 -278
  38. package/dist/mcp/auth.js +76 -128
  39. package/dist/mcp/createMCPRequest.js +4 -5
  40. package/dist/mcp/handlers.js +268 -480
  41. package/dist/mcp/query.js +56 -150
  42. package/dist/mcp/registry.js +17 -30
  43. package/dist/mcp/schemaGenerator.js +95 -181
  44. package/dist/mcp/server.js +28 -100
  45. package/dist/mcp/serviceTokens.js +102 -191
  46. package/dist/mcp/toolGenerator.js +78 -191
  47. package/dist/middleware.js +15 -27
  48. package/dist/migrations/fixtures/all-down/20260910120000-one.js +2 -42
  49. package/dist/migrations/fixtures/all-down/20260910120001-two.js +2 -42
  50. package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +1 -39
  51. package/dist/migrations/fixtures/bad-name/not-a-migration.js +1 -39
  52. package/dist/migrations/fixtures/valid/20260910120000-alpha.js +1 -39
  53. package/dist/migrations/fixtures/valid/20260910120001-beta.js +2 -42
  54. package/dist/migrations/generate.js +107 -229
  55. package/dist/migrations/load.js +75 -201
  56. package/dist/migrations/lock.js +54 -126
  57. package/dist/migrations/runner.js +192 -446
  58. package/dist/migrations/schemaCatalog.js +122 -263
  59. package/dist/models/consentForm.js +6 -6
  60. package/dist/models/consentResponse.js +5 -5
  61. package/dist/models/mcpServiceToken.js +66 -156
  62. package/dist/models/notification.js +6 -6
  63. package/dist/models/notificationPreference.js +6 -6
  64. package/dist/models/versionConfig.js +5 -5
  65. package/dist/notifications/notificationService.js +133 -273
  66. package/dist/notifications/notificationsApp.js +85 -179
  67. package/dist/notifications/notificationsBeforeSend.js +19 -64
  68. package/dist/notifiers/googleChatNotifier.js +36 -117
  69. package/dist/notifiers/slackNotifier.d.ts +31 -2
  70. package/dist/notifiers/slackNotifier.js +170 -119
  71. package/dist/notifiers/zoomNotifier.js +60 -111
  72. package/dist/openApi.js +107 -122
  73. package/dist/openApiBuilder.js +117 -159
  74. package/dist/openApiCompat.js +81 -148
  75. package/dist/openApiEtag.js +7 -7
  76. package/dist/openApiValidator.js +177 -286
  77. package/dist/orgs/orgContext.js +87 -157
  78. package/dist/orgs/orgPermissions.js +29 -68
  79. package/dist/orgs/orgPlugin.js +9 -27
  80. package/dist/orgs/organizationModel.js +65 -166
  81. package/dist/orgs/organizationSettings.js +29 -36
  82. package/dist/orgs/orgsApp.js +346 -608
  83. package/dist/permissions.js +88 -181
  84. package/dist/plugins.js +125 -218
  85. package/dist/populate.js +130 -240
  86. package/dist/rateLimit/applyTrustProxy.js +1 -1
  87. package/dist/rateLimit/createStore.js +7 -8
  88. package/dist/rateLimit/memoryStore.js +22 -100
  89. package/dist/rateLimit/middleware.js +48 -99
  90. package/dist/rateLimit/mongoStore.js +54 -112
  91. package/dist/rateLimit/policies.js +41 -75
  92. package/dist/rateLimit/redisStore.js +39 -133
  93. package/dist/rbac/access.js +119 -267
  94. package/dist/rbac/assertAllowed.js +95 -171
  95. package/dist/rbac/auditModel.js +14 -58
  96. package/dist/rbac/backfillAdmins.js +24 -130
  97. package/dist/rbac/fieldViews.js +46 -141
  98. package/dist/rbac/membershipOrgAdminSource.js +28 -99
  99. package/dist/rbac/middleware.js +30 -96
  100. package/dist/rbac/modelRouterAccess.js +130 -307
  101. package/dist/rbac/permissionUtils.js +40 -179
  102. package/dist/rbac/realtimeAccess.js +81 -147
  103. package/dist/rbac/resolve.d.ts +1 -1
  104. package/dist/rbac/resolve.js +148 -342
  105. package/dist/rbac/roleManager.js +318 -700
  106. package/dist/rbac/roleModel.js +44 -171
  107. package/dist/rbac/routes.js +93 -196
  108. package/dist/rbac/scopes.js +39 -133
  109. package/dist/rbac/statements.js +23 -91
  110. package/dist/rbac/userPlugin.js +3 -29
  111. package/dist/realtime/changeStreamWatcher.js +489 -800
  112. package/dist/realtime/deprecation.js +8 -10
  113. package/dist/realtime/queryMatcher.js +110 -191
  114. package/dist/realtime/queryStore.js +35 -118
  115. package/dist/realtime/realtimeApp.js +247 -401
  116. package/dist/realtime/registry.js +19 -30
  117. package/dist/realtime/sessionRevalidation.js +132 -358
  118. package/dist/realtime/socketAuth.js +89 -208
  119. package/dist/realtime/socketUser.js +10 -56
  120. package/dist/requestContext.js +93 -139
  121. package/dist/schemaMetadata.js +179 -274
  122. package/dist/scriptRunner.js +96 -266
  123. package/dist/scrubAdminFields.js +36 -108
  124. package/dist/secretProviders.js +130 -299
  125. package/dist/seedRunner.js +221 -514
  126. package/dist/sync/adminBroadcastScope.js +58 -170
  127. package/dist/sync/adminWindowAccess.js +15 -86
  128. package/dist/sync/adminWindowMutation.js +110 -181
  129. package/dist/sync/executors.js +425 -629
  130. package/dist/sync/loadHarness.js +392 -689
  131. package/dist/sync/models.js +181 -341
  132. package/dist/sync/mutationHandler.js +533 -801
  133. package/dist/sync/registrationSideEffects.js +41 -95
  134. package/dist/sync/registry.js +29 -49
  135. package/dist/sync/routes.js +484 -817
  136. package/dist/sync/scripts/compactTombstones.js +83 -228
  137. package/dist/sync/serialize.js +18 -58
  138. package/dist/sync/socketHandlers.js +253 -478
  139. package/dist/sync/streams.js +49 -117
  140. package/dist/sync/syncApp.js +12 -15
  141. package/dist/sync/syncBatch.js +63 -168
  142. package/dist/sync/syncSeqPlugin.js +430 -702
  143. package/dist/syncConsents.js +113 -253
  144. package/dist/terrenoApp.js +166 -276
  145. package/dist/tests/createTestData.js +146 -256
  146. package/dist/tests/models.js +14 -54
  147. package/dist/tests/mongoTestSetup.js +42 -103
  148. package/dist/tests/testHelper.js +31 -93
  149. package/dist/tests.js +12 -51
  150. package/dist/transformers.js +61 -164
  151. package/dist/utils.js +31 -93
  152. package/dist/vendor/wesleytodd-openapi/index.js +37 -51
  153. package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +32 -40
  154. package/dist/vendor/wesleytodd-openapi/lib/layer-schema.js +3 -3
  155. package/dist/vendor/wesleytodd-openapi/lib/ui.js +50 -19
  156. package/dist/vendor/wesleytodd-openapi/lib/validate.js +19 -47
  157. package/dist/versionCheckPlugin.js +52 -100
  158. package/dist/webhooks/headerValue.js +2 -2
  159. package/dist/webhooks/idempotency/memoryStore.js +16 -59
  160. package/dist/webhooks/idempotency/mongoStore.js +55 -130
  161. package/dist/webhooks/idempotency/webhookReceipt.js +9 -9
  162. package/dist/webhooks/rawBody.js +1 -1
  163. package/dist/webhooks/timingSafeEqual.js +4 -5
  164. package/dist/webhooks/verifiers/hmac.js +17 -18
  165. package/dist/webhooks/verifiers/sendgrid.js +20 -22
  166. package/dist/webhooks/verifiers/stripe.js +31 -65
  167. package/dist/webhooks/verifiers/twilio.js +23 -73
  168. package/dist/webhooks/webhooksApp.js +78 -177
  169. package/dist/zodOpenApi.js +2 -2
  170. package/package.json +6 -6
  171. package/src/__tests__/browserLogsRoute.test.ts +165 -0
  172. package/src/audit/auditApp.test.ts +5 -5
  173. package/src/audit/auditEventModel.ts +7 -3
  174. package/src/audit/auditRouter.test.ts +5 -5
  175. package/src/audit/rbacSink.test.ts +2 -2
  176. package/src/audit/record.test.ts +2 -2
  177. package/src/audit/record.ts +3 -2
  178. package/src/auth.ts +1 -1
  179. package/src/authRecovery.test.ts +43 -0
  180. package/src/authRecovery.ts +16 -10
  181. package/src/authTokens.ts +6 -2
  182. package/src/authVerification.test.ts +22 -0
  183. package/src/browserLogsRoute.ts +110 -0
  184. package/src/configurationPlugin.test.ts +1 -11
  185. package/src/expressServer.ts +10 -0
  186. package/src/frameworkModelNames.test.ts +62 -0
  187. package/src/frameworkModelNames.ts +33 -0
  188. package/src/index.ts +7 -0
  189. package/src/isolated/migrateCliConnect.isolated.ts +51 -0
  190. package/src/mcp/auth.test.ts +34 -1
  191. package/src/migrations/cli.test.ts +0 -23
  192. package/src/models/mcpServiceToken.ts +4 -3
  193. package/src/models/notification.ts +3 -2
  194. package/src/models/notificationPreference.ts +1 -1
  195. package/src/notifications/notificationsApp.test.ts +24 -1
  196. package/src/notifiers/slackNotifier.test.ts +186 -1
  197. package/src/notifiers/slackNotifier.ts +167 -8
  198. package/src/orgs/orgPlugin.ts +1 -1
  199. package/src/orgs/organizationModel.ts +11 -6
  200. package/src/plugins.test.ts +5 -0
  201. package/src/plugins.ts +3 -0
  202. package/src/realtime/realtimeApp.ts +1 -1
  203. package/src/sync/integration.test.ts +2 -2
  204. package/src/terrenoApp.ts +3 -0
  205. package/src/types.d.ts +1 -0
  206. package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
  207. package/tsconfig.json +13 -54
  208. package/tsconfig.typedoc.json +2 -0
@@ -35,79 +35,21 @@
35
35
  * });
36
36
  * ```
37
37
  */
38
- var __assign = (this && this.__assign) || function () {
39
- __assign = Object.assign || function(t) {
40
- for (var s, i = 1, n = arguments.length; i < n; i++) {
41
- s = arguments[i];
42
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
43
- t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
- var __rest = (this && this.__rest) || function (s, e) {
50
- var t = {};
51
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
- t[p] = s[p];
53
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
- t[p[i]] = s[p[i]];
57
- }
58
- return t;
59
- };
60
- var __values = (this && this.__values) || function(o) {
61
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
62
- if (m) return m.call(o);
63
- if (o && typeof o.length === "number") return {
64
- next: function () {
65
- if (o && i >= o.length) o = void 0;
66
- return { value: o && o[i++], done: !o };
67
- }
68
- };
69
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
70
- };
71
- var __read = (this && this.__read) || function (o, n) {
72
- var m = typeof Symbol === "function" && o[Symbol.iterator];
73
- if (!m) return o;
74
- var i = m.call(o), r, ar = [], e;
75
- try {
76
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
77
- }
78
- catch (error) { e = { error: error }; }
79
- finally {
80
- try {
81
- if (r && !r.done && (m = i["return"])) m.call(i);
82
- }
83
- finally { if (e) throw e.error; }
84
- }
85
- return ar;
86
- };
87
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
88
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
89
- if (ar || !(i in from)) {
90
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
91
- ar[i] = from[i];
92
- }
93
- }
94
- return to.concat(ar || Array.prototype.slice.call(from));
95
- };
96
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
97
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
98
40
  };
99
41
  Object.defineProperty(exports, "__esModule", { value: true });
100
42
  exports.buildQuerySchemaFromFields = exports.buildNumericListQueryFieldSchema = exports.buildStringListQueryFieldSchema = exports.createModelValidators = exports.validateModelRequestBody = exports.getSchemaFromModel = exports.validateResponseData = exports.createValidator = exports.validateQueryParams = exports.validateRequestBody = exports.isEscapedRegexLiteral = exports.resetOpenApiValidatorConfig = exports.getOpenApiValidatorConfig = exports.configureOpenApiValidator = exports.isOpenApiValidatorConfigured = void 0;
101
- var ajv_1 = __importDefault(require("ajv"));
102
- var ajv_formats_1 = __importDefault(require("ajv-formats"));
103
- var adminTypes_1 = require("./adminTypes");
104
- var errors_1 = require("./errors");
105
- var logger_1 = require("./logger");
106
- var populate_1 = require("./populate");
43
+ const ajv_1 = __importDefault(require("ajv"));
44
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
45
+ const adminTypes_1 = require("./adminTypes");
46
+ const errors_1 = require("./errors");
47
+ const logger_1 = require("./logger");
48
+ const populate_1 = require("./populate");
107
49
  // Whether configureOpenApiValidator() has been called
108
- var isConfigured = false;
50
+ let isConfigured = false;
109
51
  // Global validator configuration - can be modified at runtime
110
- var globalConfig = {
52
+ let globalConfig = {
111
53
  coerceTypes: true,
112
54
  logValidationErrors: true,
113
55
  removeAdditional: true,
@@ -118,7 +60,7 @@ var globalConfig = {
118
60
  * Check whether `configureOpenApiValidator()` has been called.
119
61
  * Validation middleware is a no-op when this returns false.
120
62
  */
121
- var isOpenApiValidatorConfigured = function () {
63
+ const isOpenApiValidatorConfigured = () => {
122
64
  return isConfigured;
123
65
  };
124
66
  exports.isOpenApiValidatorConfigured = isOpenApiValidatorConfigured;
@@ -139,21 +81,20 @@ exports.isOpenApiValidatorConfigured = isOpenApiValidatorConfigured;
139
81
  * });
140
82
  * ```
141
83
  */
142
- var configureOpenApiValidator = function (config) {
143
- if (config === void 0) { config = {}; }
84
+ const configureOpenApiValidator = (config = {}) => {
144
85
  isConfigured = true;
145
- globalConfig = __assign(__assign({}, globalConfig), config);
86
+ globalConfig = { ...globalConfig, ...config };
146
87
  // Clear cached AJV instances so new config takes effect
147
88
  ajvCache.clear();
148
89
  validatorCache.clear();
149
- logger_1.logger.debug("OpenAPI validator configured: ".concat(JSON.stringify(globalConfig)));
90
+ logger_1.logger.debug(`OpenAPI validator configured: ${JSON.stringify(globalConfig)}`);
150
91
  };
151
92
  exports.configureOpenApiValidator = configureOpenApiValidator;
152
93
  /**
153
94
  * Get the current global validator configuration.
154
95
  */
155
- var getOpenApiValidatorConfig = function () {
156
- return __assign({}, globalConfig);
96
+ const getOpenApiValidatorConfig = () => {
97
+ return { ...globalConfig };
157
98
  };
158
99
  exports.getOpenApiValidatorConfig = getOpenApiValidatorConfig;
159
100
  /**
@@ -161,7 +102,7 @@ exports.getOpenApiValidatorConfig = getOpenApiValidatorConfig;
161
102
  * Also resets `isConfigured` to false.
162
103
  * Useful for testing.
163
104
  */
164
- var resetOpenApiValidatorConfig = function () {
105
+ const resetOpenApiValidatorConfig = () => {
165
106
  isConfigured = false;
166
107
  globalConfig = {
167
108
  coerceTypes: true,
@@ -175,19 +116,18 @@ var resetOpenApiValidatorConfig = function () {
175
116
  };
176
117
  exports.resetOpenApiValidatorConfig = resetOpenApiValidatorConfig;
177
118
  // Lazy AJV instance cache keyed by coerceTypes + removeAdditional
178
- var ajvCache = new Map();
119
+ const ajvCache = new Map();
179
120
  /**
180
121
  * Get or create an AJV instance with the current config settings.
181
122
  */
182
- var getAjvInstance = function () {
183
- var _a, _b, _c, _d;
184
- var key = "coerce:".concat((_a = globalConfig.coerceTypes) !== null && _a !== void 0 ? _a : true, ",remove:").concat((_b = globalConfig.removeAdditional) !== null && _b !== void 0 ? _b : true);
185
- var instance = ajvCache.get(key);
123
+ const getAjvInstance = () => {
124
+ const key = `coerce:${globalConfig.coerceTypes ?? true},remove:${globalConfig.removeAdditional ?? true}`;
125
+ let instance = ajvCache.get(key);
186
126
  if (!instance) {
187
127
  instance = new ajv_1.default({
188
128
  allErrors: true,
189
- coerceTypes: (_c = globalConfig.coerceTypes) !== null && _c !== void 0 ? _c : true,
190
- removeAdditional: (_d = globalConfig.removeAdditional) !== null && _d !== void 0 ? _d : true,
129
+ coerceTypes: globalConfig.coerceTypes ?? true,
130
+ removeAdditional: globalConfig.removeAdditional ?? true,
191
131
  strict: false,
192
132
  useDefaults: true,
193
133
  validateSchema: false,
@@ -196,21 +136,21 @@ var getAjvInstance = function () {
196
136
  instance.addKeyword({
197
137
  keyword: ESCAPED_REGEX_LITERAL_KEYWORD,
198
138
  type: "string",
199
- validate: function (_enabled, data) { return (0, exports.isEscapedRegexLiteral)(data); },
139
+ validate: (_enabled, data) => (0, exports.isEscapedRegexLiteral)(data),
200
140
  });
201
141
  ajvCache.set(key, instance);
202
142
  }
203
143
  return instance;
204
144
  };
205
145
  // Cache compiled validators by schema hash + config key
206
- var validatorCache = new Map();
146
+ const validatorCache = new Map();
207
147
  /**
208
148
  * Generate a simple hash for a schema to use as a cache key.
209
149
  */
210
- var hashSchema = function (schema) {
150
+ const hashSchema = (schema) => {
211
151
  return JSON.stringify(schema);
212
152
  };
213
- var VALID_JSON_SCHEMA_TYPES = new Set([
153
+ const VALID_JSON_SCHEMA_TYPES = new Set([
214
154
  "string",
215
155
  "number",
216
156
  "integer",
@@ -219,7 +159,7 @@ var VALID_JSON_SCHEMA_TYPES = new Set([
219
159
  "object",
220
160
  "null",
221
161
  ]);
222
- var REGEX_META_CHARACTERS = new Set([
162
+ const REGEX_META_CHARACTERS = new Set([
223
163
  "\\",
224
164
  ".",
225
165
  "*",
@@ -236,11 +176,11 @@ var REGEX_META_CHARACTERS = new Set([
236
176
  "]",
237
177
  ]);
238
178
  /** Accepts literal text and escaped metacharacters (e.g. `\\.`), rejects executable patterns. */
239
- var isEscapedRegexLiteral = function (value) {
240
- for (var index = 0; index < value.length; index += 1) {
241
- var character = value[index];
179
+ const isEscapedRegexLiteral = (value) => {
180
+ for (let index = 0; index < value.length; index += 1) {
181
+ const character = value[index];
242
182
  if (character === "\\") {
243
- var escapedCharacter = value[index + 1];
183
+ const escapedCharacter = value[index + 1];
244
184
  if (!escapedCharacter || !REGEX_META_CHARACTERS.has(escapedCharacter)) {
245
185
  return false;
246
186
  }
@@ -254,9 +194,9 @@ var isEscapedRegexLiteral = function (value) {
254
194
  return true;
255
195
  };
256
196
  exports.isEscapedRegexLiteral = isEscapedRegexLiteral;
257
- var ESCAPED_REGEX_LITERAL_KEYWORD = "escapedRegexLiteral";
197
+ const ESCAPED_REGEX_LITERAL_KEYWORD = "escapedRegexLiteral";
258
198
  // mongoose-to-swagger emits non-standard type strings for some Mongoose types
259
- var MONGOOSE_TYPE_MAP = {
199
+ const MONGOOSE_TYPE_MAP = {
260
200
  dateonly: { format: "date", type: "string" },
261
201
  schemaobjectid: { type: "string" },
262
202
  };
@@ -264,14 +204,13 @@ var MONGOOSE_TYPE_MAP = {
264
204
  * Recursively replace non-standard mongoose-to-swagger types with valid JSON Schema types
265
205
  * so AJV can compile the schema.
266
206
  */
267
- var sanitizeSchemaForAjv = function (schema) {
268
- var e_1, _a;
207
+ const sanitizeSchemaForAjv = (schema) => {
269
208
  if (!schema || typeof schema !== "object") {
270
209
  return schema;
271
210
  }
272
- var result = __assign({}, schema);
211
+ const result = { ...schema };
273
212
  if (typeof result.type === "string" && !VALID_JSON_SCHEMA_TYPES.has(result.type)) {
274
- var mapped = MONGOOSE_TYPE_MAP[result.type];
213
+ const mapped = MONGOOSE_TYPE_MAP[result.type];
275
214
  if (mapped) {
276
215
  result.type = mapped.type;
277
216
  if (mapped.format && !result.format) {
@@ -286,22 +225,12 @@ var sanitizeSchemaForAjv = function (schema) {
286
225
  result.items = sanitizeSchemaForAjv(result.items);
287
226
  }
288
227
  if (result.properties && typeof result.properties === "object") {
289
- var sanitizedProps = {};
290
- try {
291
- for (var _b = __values(Object.entries(result.properties)), _c = _b.next(); !_c.done; _c = _b.next()) {
292
- var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
293
- sanitizedProps[key] =
294
- typeof value === "object" && value !== null
295
- ? sanitizeSchemaForAjv(value)
296
- : value;
297
- }
298
- }
299
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
300
- finally {
301
- try {
302
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
303
- }
304
- finally { if (e_1) throw e_1.error; }
228
+ const sanitizedProps = {};
229
+ for (const [key, value] of Object.entries(result.properties)) {
230
+ sanitizedProps[key] =
231
+ typeof value === "object" && value !== null
232
+ ? sanitizeSchemaForAjv(value)
233
+ : value;
305
234
  }
306
235
  result.properties = sanitizedProps;
307
236
  }
@@ -309,52 +238,47 @@ var sanitizeSchemaForAjv = function (schema) {
309
238
  result.additionalProperties = sanitizeSchemaForAjv(result.additionalProperties);
310
239
  }
311
240
  if (Array.isArray(result.oneOf)) {
312
- result.oneOf = result.oneOf.map(function (entry) {
313
- return typeof entry === "object" && entry !== null
314
- ? sanitizeSchemaForAjv(entry)
315
- : entry;
316
- });
241
+ result.oneOf = result.oneOf.map((entry) => typeof entry === "object" && entry !== null
242
+ ? sanitizeSchemaForAjv(entry)
243
+ : entry);
317
244
  }
318
245
  if (typeof result.required === "boolean") {
319
246
  delete result.required;
320
247
  }
321
248
  return result;
322
249
  };
323
- var stripBooleanRequiredFlag = function (schema) {
250
+ const stripBooleanRequiredFlag = (schema) => {
324
251
  if (schema.required === true || schema.required === false) {
325
- var _1 = schema.required, rest = __rest(schema, ["required"]);
326
- var cleaned = __assign({}, rest);
252
+ const { required: _, ...rest } = schema;
253
+ const cleaned = { ...rest };
327
254
  if (cleaned.properties) {
328
- cleaned.properties = Object.fromEntries(Object.entries(cleaned.properties).map(function (_a) {
329
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
330
- return [
331
- key,
332
- stripBooleanRequiredFlag(value),
333
- ];
334
- }));
255
+ cleaned.properties = Object.fromEntries(Object.entries(cleaned.properties).map(([key, value]) => [
256
+ key,
257
+ stripBooleanRequiredFlag(value),
258
+ ]));
335
259
  }
336
260
  if (cleaned.items) {
337
261
  cleaned.items = stripBooleanRequiredFlag(cleaned.items);
338
262
  }
339
263
  if (cleaned.oneOf) {
340
- cleaned.oneOf = cleaned.oneOf.map(function (entry) { return stripBooleanRequiredFlag(entry); });
264
+ cleaned.oneOf = cleaned.oneOf.map((entry) => stripBooleanRequiredFlag(entry));
341
265
  }
342
266
  return cleaned;
343
267
  }
344
268
  if (schema.properties) {
345
- return __assign(__assign({}, schema), { properties: Object.fromEntries(Object.entries(schema.properties).map(function (_a) {
346
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
347
- return [
348
- key,
349
- stripBooleanRequiredFlag(value),
350
- ];
351
- })) });
269
+ return {
270
+ ...schema,
271
+ properties: Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => [
272
+ key,
273
+ stripBooleanRequiredFlag(value),
274
+ ])),
275
+ };
352
276
  }
353
277
  if (schema.items) {
354
- return __assign(__assign({}, schema), { items: stripBooleanRequiredFlag(schema.items) });
278
+ return { ...schema, items: stripBooleanRequiredFlag(schema.items) };
355
279
  }
356
280
  if (schema.oneOf) {
357
- return __assign(__assign({}, schema), { oneOf: schema.oneOf.map(function (entry) { return stripBooleanRequiredFlag(entry); }) });
281
+ return { ...schema, oneOf: schema.oneOf.map((entry) => stripBooleanRequiredFlag(entry)) };
358
282
  }
359
283
  return schema;
360
284
  };
@@ -364,23 +288,22 @@ var stripBooleanRequiredFlag = function (schema) {
364
288
  * Sanitizes non-standard mongoose-to-swagger types before compilation.
365
289
  * Returns null if the schema still cannot be compiled after sanitization.
366
290
  */
367
- var getValidator = function (schema) {
368
- var _a, _b;
369
- var ajv = getAjvInstance();
370
- var configKey = "coerce:".concat((_a = globalConfig.coerceTypes) !== null && _a !== void 0 ? _a : true, ",remove:").concat((_b = globalConfig.removeAdditional) !== null && _b !== void 0 ? _b : true);
371
- var hash = "".concat(configKey, ":").concat(hashSchema(schema));
372
- var cached = validatorCache.get(hash);
291
+ const getValidator = (schema) => {
292
+ const ajv = getAjvInstance();
293
+ const configKey = `coerce:${globalConfig.coerceTypes ?? true},remove:${globalConfig.removeAdditional ?? true}`;
294
+ const hash = `${configKey}:${hashSchema(schema)}`;
295
+ const cached = validatorCache.get(hash);
373
296
  if (cached !== undefined) {
374
297
  return cached;
375
298
  }
376
- var sanitized = sanitizeSchemaForAjv(schema);
299
+ const sanitized = sanitizeSchemaForAjv(schema);
377
300
  try {
378
- var validator = ajv.compile(sanitized);
301
+ const validator = ajv.compile(sanitized);
379
302
  validatorCache.set(hash, validator);
380
303
  return validator;
381
304
  }
382
305
  catch (err) {
383
- logger_1.logger.debug("Could not compile validation schema after sanitization: ".concat(err.message));
306
+ logger_1.logger.debug(`Could not compile validation schema after sanitization: ${err.message}`);
384
307
  validatorCache.set(hash, null);
385
308
  return null;
386
309
  }
@@ -388,12 +311,12 @@ var getValidator = function (schema) {
388
311
  /**
389
312
  * Format AJV errors into a human-readable string.
390
313
  */
391
- var formatValidationErrors = function (errors) {
314
+ const formatValidationErrors = (errors) => {
392
315
  return errors
393
- .map(function (err) {
394
- var path = err.instancePath || "/";
395
- var message = err.message || "validation failed";
396
- return "".concat(path, ": ").concat(message);
316
+ .map((err) => {
317
+ const path = err.instancePath || "/";
318
+ const message = err.message || "validation failed";
319
+ return `${path}: ${message}`;
397
320
  })
398
321
  .join("; ");
399
322
  };
@@ -402,40 +325,23 @@ var formatValidationErrors = function (errors) {
402
325
  * Strips `required` from individual properties (OpenAPI-style) and moves it
403
326
  * to the schema-level `required` array (JSON Schema-style) for AJV compatibility.
404
327
  */
405
- var propertiesToSchema = function (properties, requiredFields, options) {
406
- var e_2, _a;
328
+ const propertiesToSchema = (properties, requiredFields, options) => {
407
329
  // Extract required fields from properties marked required: true (OpenAPI builder style).
408
330
  // PATCH bodies are partial: omit mongoose/OpenAPI required so one field can be sent.
409
- var autoRequired = (options === null || options === void 0 ? void 0 : options.partial)
331
+ const autoRequired = options?.partial
410
332
  ? []
411
333
  : Object.entries(properties)
412
- .filter(function (_a) {
413
- var _b = __read(_a, 2), _ = _b[0], prop = _b[1];
414
- return prop.required === true;
415
- })
416
- .map(function (_a) {
417
- var _b = __read(_a, 1), key = _b[0];
418
- return key;
419
- });
420
- var allRequired = (options === null || options === void 0 ? void 0 : options.partial)
334
+ .filter(([_, prop]) => prop.required === true)
335
+ .map(([key]) => key);
336
+ const allRequired = options?.partial
421
337
  ? []
422
- : __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read((requiredFields !== null && requiredFields !== void 0 ? requiredFields : [])), false), __read(autoRequired), false))), false);
338
+ : [...new Set([...(requiredFields ?? []), ...autoRequired])];
423
339
  // Strip boolean `required` from individual properties — AJV only accepts `required` arrays on objects
424
- var cleanedProperties = {};
425
- try {
426
- for (var _b = __values(Object.entries(properties)), _c = _b.next(); !_c.done; _c = _b.next()) {
427
- var _d = __read(_c.value, 2), key = _d[0], prop = _d[1];
428
- cleanedProperties[key] = stripBooleanRequiredFlag(prop);
429
- }
340
+ const cleanedProperties = {};
341
+ for (const [key, prop] of Object.entries(properties)) {
342
+ cleanedProperties[key] = stripBooleanRequiredFlag(prop);
430
343
  }
431
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
432
- finally {
433
- try {
434
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
435
- }
436
- finally { if (e_2) throw e_2.error; }
437
- }
438
- var schema = {
344
+ const schema = {
439
345
  properties: cleanedProperties,
440
346
  required: allRequired.length > 0 ? allRequired : undefined,
441
347
  type: "object",
@@ -457,42 +363,41 @@ var propertiesToSchema = function (properties, requiredFields, options) {
457
363
  * @param options - Optional configuration for this validator
458
364
  * @returns Express middleware function
459
365
  */
460
- var validateRequestBody = function (schema, options) {
461
- var fullSchema = propertiesToSchema(schema, options === null || options === void 0 ? void 0 : options.required, {
462
- partial: options === null || options === void 0 ? void 0 : options.partial,
366
+ const validateRequestBody = (schema, options) => {
367
+ const fullSchema = propertiesToSchema(schema, options?.required, {
368
+ partial: options?.partial,
463
369
  });
464
- return function (req, _res, next) {
465
- var _a, _b, _c;
370
+ return (req, _res, next) => {
466
371
  // No-op if not configured
467
372
  if (!isConfigured) {
468
373
  next();
469
374
  return;
470
375
  }
471
376
  // Check if validation is enabled (route override takes precedence)
472
- var isEnabled = (_a = options === null || options === void 0 ? void 0 : options.enabled) !== null && _a !== void 0 ? _a : globalConfig.validateRequests;
377
+ const isEnabled = options?.enabled ?? globalConfig.validateRequests;
473
378
  if (!isEnabled) {
474
379
  next();
475
380
  return;
476
381
  }
477
382
  // Capture keys before validation for removeAdditional detection
478
- var keysBefore = req.body && typeof req.body === "object" ? Object.keys(req.body) : [];
383
+ const keysBefore = req.body && typeof req.body === "object" ? Object.keys(req.body) : [];
479
384
  // Get validator at request time so config changes take effect
480
- var validator = getValidator(fullSchema);
385
+ const validator = getValidator(fullSchema);
481
386
  // If schema couldn't be compiled (e.g., non-standard types), skip validation
482
387
  if (!validator) {
483
388
  next();
484
389
  return;
485
390
  }
486
391
  // Clone body if we might modify it (coercion or removeAdditional)
487
- var bodyToValidate = __assign({}, req.body);
488
- var valid = validator(bodyToValidate);
392
+ const bodyToValidate = { ...req.body };
393
+ const valid = validator(bodyToValidate);
489
394
  if (!valid && validator.errors) {
490
- var errors = validator.errors;
395
+ const errors = validator.errors;
491
396
  if (globalConfig.logValidationErrors) {
492
- logger_1.logger.warn("Request body validation failed for ".concat(req.method, " ").concat(req.path, ": ").concat(formatValidationErrors(errors)));
397
+ logger_1.logger.warn(`Request body validation failed for ${req.method} ${req.path}: ${formatValidationErrors(errors)}`);
493
398
  }
494
399
  // Use custom error handler if provided
495
- var errorHandler = (_b = options === null || options === void 0 ? void 0 : options.onError) !== null && _b !== void 0 ? _b : globalConfig.onValidationError;
400
+ const errorHandler = options?.onError ?? globalConfig.onValidationError;
496
401
  if (errorHandler) {
497
402
  errorHandler(errors, req);
498
403
  next();
@@ -503,11 +408,11 @@ var validateRequestBody = function (schema, options) {
503
408
  detail: formatValidationErrors(errors),
504
409
  disableExternalErrorTracking: true,
505
410
  meta: {
506
- validationErrors: JSON.stringify(errors.map(function (e) { return ({
411
+ validationErrors: JSON.stringify(errors.map((e) => ({
507
412
  message: e.message,
508
413
  params: e.params,
509
414
  path: e.instancePath,
510
- }); })),
415
+ }))),
511
416
  },
512
417
  source: {
513
418
  pointer: "/body",
@@ -520,15 +425,15 @@ var validateRequestBody = function (schema, options) {
520
425
  if (valid) {
521
426
  // Detect removed properties (top-level only)
522
427
  if (globalConfig.removeAdditional) {
523
- var keysAfter_1 = Object.keys(bodyToValidate);
524
- var removedProperties = keysBefore.filter(function (k) { return !keysAfter_1.includes(k); });
428
+ const keysAfter = Object.keys(bodyToValidate);
429
+ const removedProperties = keysBefore.filter((k) => !keysAfter.includes(k));
525
430
  if (removedProperties.length > 0) {
526
- var hook = (_c = options === null || options === void 0 ? void 0 : options.onAdditionalPropertiesRemoved) !== null && _c !== void 0 ? _c : globalConfig.onAdditionalPropertiesRemoved;
431
+ const hook = options?.onAdditionalPropertiesRemoved ?? globalConfig.onAdditionalPropertiesRemoved;
527
432
  if (hook) {
528
433
  hook(removedProperties, req);
529
434
  }
530
435
  if (globalConfig.logValidationErrors) {
531
- logger_1.logger.debug("Stripped additional properties from ".concat(req.method, " ").concat(req.path, ": ").concat(removedProperties.join(", ")));
436
+ logger_1.logger.debug(`Stripped additional properties from ${req.method} ${req.path}: ${removedProperties.join(", ")}`);
532
437
  }
533
438
  }
534
439
  }
@@ -545,35 +450,34 @@ exports.validateRequestBody = validateRequestBody;
545
450
  * @param options - Optional configuration for this validator
546
451
  * @returns Express middleware function
547
452
  */
548
- var validateQueryParams = function (schema, options) {
549
- var fullSchema = propertiesToSchema(schema);
550
- return function (req, _res, next) {
551
- var _a, _b, _c, _d;
453
+ const validateQueryParams = (schema, options) => {
454
+ const fullSchema = propertiesToSchema(schema);
455
+ return (req, _res, next) => {
552
456
  // No-op if not configured
553
457
  if (!isConfigured) {
554
458
  next();
555
459
  return;
556
460
  }
557
- var isEnabled = (_a = options === null || options === void 0 ? void 0 : options.enabled) !== null && _a !== void 0 ? _a : globalConfig.validateRequests;
461
+ const isEnabled = options?.enabled ?? globalConfig.validateRequests;
558
462
  if (!isEnabled) {
559
463
  next();
560
464
  return;
561
465
  }
562
466
  // Get validator at request time
563
- var validator = getValidator(fullSchema);
467
+ const validator = getValidator(fullSchema);
564
468
  // If schema couldn't be compiled, skip validation
565
469
  if (!validator) {
566
470
  next();
567
471
  return;
568
472
  }
569
- var queryToValidate = globalConfig.coerceTypes ? __assign({}, req.query) : req.query;
570
- var valid = validator(queryToValidate);
473
+ const queryToValidate = globalConfig.coerceTypes ? { ...req.query } : req.query;
474
+ const valid = validator(queryToValidate);
571
475
  if (!valid && validator.errors) {
572
- var errors = validator.errors;
476
+ const errors = validator.errors;
573
477
  if (globalConfig.logValidationErrors) {
574
- logger_1.logger.warn("Query parameter validation failed for ".concat(req.method, " ").concat(req.path, ": ").concat(formatValidationErrors(errors)));
478
+ logger_1.logger.warn(`Query parameter validation failed for ${req.method} ${req.path}: ${formatValidationErrors(errors)}`);
575
479
  }
576
- var errorHandler = (_b = options === null || options === void 0 ? void 0 : options.onError) !== null && _b !== void 0 ? _b : globalConfig.onValidationError;
480
+ const errorHandler = options?.onError ?? globalConfig.onValidationError;
577
481
  if (errorHandler) {
578
482
  errorHandler(errors, req);
579
483
  next();
@@ -583,14 +487,14 @@ var validateQueryParams = function (schema, options) {
583
487
  detail: formatValidationErrors(errors),
584
488
  disableExternalErrorTracking: true,
585
489
  meta: {
586
- validationErrors: JSON.stringify(errors.map(function (e) { return ({
490
+ validationErrors: JSON.stringify(errors.map((e) => ({
587
491
  message: e.message,
588
492
  params: e.params,
589
493
  path: e.instancePath,
590
- }); })),
494
+ }))),
591
495
  },
592
496
  source: {
593
- parameter: ((_d = (_c = errors[0]) === null || _c === void 0 ? void 0 : _c.instancePath) === null || _d === void 0 ? void 0 : _d.replace("/", "")) || "unknown",
497
+ parameter: errors[0]?.instancePath?.replace("/", "") || "unknown",
594
498
  },
595
499
  status: 400,
596
500
  title: "Query parameter validation failed",
@@ -622,17 +526,17 @@ exports.validateQueryParams = validateQueryParams;
622
526
  * ], handler);
623
527
  * ```
624
528
  */
625
- var createValidator = function (options) {
626
- var bodyValidator = options.body
529
+ const createValidator = (options) => {
530
+ const bodyValidator = options.body
627
531
  ? (0, exports.validateRequestBody)(options.body, { enabled: options.enabled })
628
532
  : null;
629
- var queryValidator = options.query
533
+ const queryValidator = options.query
630
534
  ? (0, exports.validateQueryParams)(options.query, { enabled: options.enabled })
631
535
  : null;
632
- return function (req, res, next) {
536
+ return (req, res, next) => {
633
537
  // Run body validation first
634
538
  if (bodyValidator) {
635
- bodyValidator(req, res, (function (err) {
539
+ bodyValidator(req, res, ((err) => {
636
540
  if (err) {
637
541
  next(err);
638
542
  return;
@@ -663,19 +567,19 @@ exports.createValidator = createValidator;
663
567
  * @param schema - The expected schema
664
568
  * @returns Object with valid flag and any errors
665
569
  */
666
- var validateResponseData = function (data, schema) {
570
+ const validateResponseData = (data, schema) => {
667
571
  if (!globalConfig.validateResponses) {
668
572
  return { valid: true };
669
573
  }
670
- var fullSchema = propertiesToSchema(schema);
671
- var validator = getValidator(fullSchema);
574
+ const fullSchema = propertiesToSchema(schema);
575
+ const validator = getValidator(fullSchema);
672
576
  if (!validator) {
673
577
  return { valid: true };
674
578
  }
675
- var valid = validator(data);
579
+ const valid = validator(data);
676
580
  if (!valid && validator.errors) {
677
581
  if (globalConfig.logValidationErrors) {
678
- logger_1.logger.warn("Response validation failed: ".concat(formatValidationErrors(validator.errors)));
582
+ logger_1.logger.warn(`Response validation failed: ${formatValidationErrors(validator.errors)}`);
679
583
  }
680
584
  return { errors: validator.errors, valid: false };
681
585
  }
@@ -690,16 +594,16 @@ exports.validateResponseData = validateResponseData;
690
594
  * @param model - A Mongoose model
691
595
  * @returns Schema properties suitable for validation
692
596
  */
693
- var getSchemaFromModel = function (model) {
694
- var properties = (0, populate_1.getOpenApiSpecForModel)(model).properties;
597
+ const getSchemaFromModel = (model) => {
598
+ const { properties } = (0, populate_1.getOpenApiSpecForModel)(model);
695
599
  return properties;
696
600
  };
697
601
  exports.getSchemaFromModel = getSchemaFromModel;
698
602
  /**
699
603
  * Extract required field names from a Mongoose model's swagger schema.
700
604
  */
701
- var getRequiredFieldsFromModel = function (model) {
702
- var required = (0, populate_1.getOpenApiSpecForModel)(model).required;
605
+ const getRequiredFieldsFromModel = (model) => {
606
+ const { required } = (0, populate_1.getOpenApiSpecForModel)(model);
703
607
  return required;
704
608
  };
705
609
  /**
@@ -710,19 +614,18 @@ var getRequiredFieldsFromModel = function (model) {
710
614
  * @param options - Optional configuration for the validator
711
615
  * @returns Express middleware function
712
616
  */
713
- var validateModelRequestBody = function (model, options) {
714
- var _a, _b;
715
- var schema = (0, exports.getSchemaFromModel)(model);
716
- var requiredFields = (options === null || options === void 0 ? void 0 : options.partial) ? [] : getRequiredFieldsFromModel(model);
717
- if ((_a = options === null || options === void 0 ? void 0 : options.excludeFields) === null || _a === void 0 ? void 0 : _a.length) {
718
- var excluded_1 = new Set(options.excludeFields);
719
- schema = Object.fromEntries(Object.entries(schema).filter(function (_a) {
720
- var _b = __read(_a, 1), key = _b[0];
721
- return !excluded_1.has(key);
722
- }));
723
- requiredFields = requiredFields.filter(function (f) { return !excluded_1.has(f); });
617
+ const validateModelRequestBody = (model, options) => {
618
+ let schema = (0, exports.getSchemaFromModel)(model);
619
+ let requiredFields = options?.partial ? [] : getRequiredFieldsFromModel(model);
620
+ if (options?.excludeFields?.length) {
621
+ const excluded = new Set(options.excludeFields);
622
+ schema = Object.fromEntries(Object.entries(schema).filter(([key]) => !excluded.has(key)));
623
+ requiredFields = requiredFields.filter((f) => !excluded.has(f));
724
624
  }
725
- return (0, exports.validateRequestBody)(schema, __assign(__assign({}, options), { required: (options === null || options === void 0 ? void 0 : options.partial) ? [] : __spreadArray(__spreadArray([], __read(((_b = options === null || options === void 0 ? void 0 : options.required) !== null && _b !== void 0 ? _b : [])), false), __read(requiredFields), false) }));
625
+ return (0, exports.validateRequestBody)(schema, {
626
+ ...options,
627
+ required: options?.partial ? [] : [...(options?.required ?? []), ...requiredFields],
628
+ });
726
629
  };
727
630
  exports.validateModelRequestBody = validateModelRequestBody;
728
631
  /**
@@ -733,24 +636,24 @@ exports.validateModelRequestBody = validateModelRequestBody;
733
636
  * @param options - Configuration options
734
637
  * @returns Object with create and update validation middleware
735
638
  */
736
- var createModelValidators = function (model, options) {
737
- var schema = (0, exports.getSchemaFromModel)(model);
639
+ const createModelValidators = (model, options) => {
640
+ const schema = (0, exports.getSchemaFromModel)(model);
738
641
  return {
739
642
  create: (0, exports.validateRequestBody)(schema, {
740
- enabled: options === null || options === void 0 ? void 0 : options.validateCreate,
741
- onAdditionalPropertiesRemoved: options === null || options === void 0 ? void 0 : options.onAdditionalPropertiesRemoved,
742
- onError: options === null || options === void 0 ? void 0 : options.onError,
643
+ enabled: options?.validateCreate,
644
+ onAdditionalPropertiesRemoved: options?.onAdditionalPropertiesRemoved,
645
+ onError: options?.onError,
743
646
  }),
744
647
  update: (0, exports.validateRequestBody)(schema, {
745
- enabled: options === null || options === void 0 ? void 0 : options.validateUpdate,
746
- onAdditionalPropertiesRemoved: options === null || options === void 0 ? void 0 : options.onAdditionalPropertiesRemoved,
747
- onError: options === null || options === void 0 ? void 0 : options.onError,
648
+ enabled: options?.validateUpdate,
649
+ onAdditionalPropertiesRemoved: options?.onAdditionalPropertiesRemoved,
650
+ onError: options?.onError,
748
651
  partial: true,
749
652
  }),
750
653
  };
751
654
  };
752
655
  exports.createModelValidators = createModelValidators;
753
- var choiceEmptyInItemSchema = function (baseItem) {
656
+ const choiceEmptyInItemSchema = (baseItem) => {
754
657
  if (baseItem.enum) {
755
658
  return {
756
659
  oneOf: [
@@ -766,7 +669,7 @@ var choiceEmptyInItemSchema = function (baseItem) {
766
669
  ],
767
670
  };
768
671
  };
769
- var buildInOperatorSchema = function (itemSchema) { return ({
672
+ const buildInOperatorSchema = (itemSchema) => ({
770
673
  additionalProperties: false,
771
674
  properties: {
772
675
  $in: {
@@ -777,8 +680,8 @@ var buildInOperatorSchema = function (itemSchema) { return ({
777
680
  },
778
681
  required: ["$in"],
779
682
  type: "object",
780
- }); };
781
- var buildRegexOperatorSchema = function () { return ({
683
+ });
684
+ const buildRegexOperatorSchema = () => ({
782
685
  additionalProperties: false,
783
686
  properties: {
784
687
  $options: { enum: ["i"], type: "string" },
@@ -786,8 +689,8 @@ var buildRegexOperatorSchema = function () { return ({
786
689
  },
787
690
  required: ["$regex", "$options"],
788
691
  type: "object",
789
- }); };
790
- var buildRangeOperatorSchema = function (valueSchema) { return ({
692
+ });
693
+ const buildRangeOperatorSchema = (valueSchema) => ({
791
694
  additionalProperties: false,
792
695
  properties: {
793
696
  $gt: valueSchema,
@@ -796,11 +699,11 @@ var buildRangeOperatorSchema = function (valueSchema) { return ({
796
699
  $lte: valueSchema,
797
700
  },
798
701
  type: "object",
799
- }); };
702
+ });
800
703
  /** Query schema for string/enum fields: scalar, `$in`, or escaped `$regex`. */
801
- var buildStringListQueryFieldSchema = function (fieldSchema) {
802
- var scalar = stripBooleanRequiredFlag(fieldSchema);
803
- var inItems = fieldSchema.enum
704
+ const buildStringListQueryFieldSchema = (fieldSchema) => {
705
+ const scalar = stripBooleanRequiredFlag(fieldSchema);
706
+ const inItems = fieldSchema.enum
804
707
  ? choiceEmptyInItemSchema(fieldSchema)
805
708
  : stripBooleanRequiredFlag(fieldSchema);
806
709
  return {
@@ -809,9 +712,9 @@ var buildStringListQueryFieldSchema = function (fieldSchema) {
809
712
  };
810
713
  exports.buildStringListQueryFieldSchema = buildStringListQueryFieldSchema;
811
714
  /** Query schema for number/date fields: scalar or comparison operators. */
812
- var buildNumericListQueryFieldSchema = function (fieldSchema) {
813
- var scalar = stripBooleanRequiredFlag(fieldSchema);
814
- var valueSchema = stripBooleanRequiredFlag(fieldSchema);
715
+ const buildNumericListQueryFieldSchema = (fieldSchema) => {
716
+ const scalar = stripBooleanRequiredFlag(fieldSchema);
717
+ const valueSchema = stripBooleanRequiredFlag(fieldSchema);
815
718
  return {
816
719
  oneOf: [scalar, buildRangeOperatorSchema(valueSchema)],
817
720
  };
@@ -825,40 +728,28 @@ exports.buildNumericListQueryFieldSchema = buildNumericListQueryFieldSchema;
825
728
  * @param queryFields - Array of field names allowed for querying
826
729
  * @returns Schema properties suitable for query validation
827
730
  */
828
- var buildQuerySchemaFromFields = function (model, queryFields) {
829
- var e_3, _a;
830
- if (queryFields === void 0) { queryFields = []; }
831
- var modelSchema = (0, exports.getSchemaFromModel)(model);
832
- var querySchema = {
731
+ const buildQuerySchemaFromFields = (model, queryFields = []) => {
732
+ const modelSchema = (0, exports.getSchemaFromModel)(model);
733
+ const querySchema = {
833
734
  limit: { type: "number" },
834
735
  page: { type: "number" },
835
736
  sort: { type: "string" },
836
737
  };
837
- try {
838
- for (var queryFields_1 = __values(queryFields), queryFields_1_1 = queryFields_1.next(); !queryFields_1_1.done; queryFields_1_1 = queryFields_1.next()) {
839
- var field = queryFields_1_1.value;
840
- var modelField = modelSchema[field];
841
- if (!modelField) {
842
- querySchema[field] = (0, exports.buildStringListQueryFieldSchema)({ type: "string" });
843
- continue;
844
- }
845
- if (modelField.type === "boolean") {
846
- querySchema[field] = stripBooleanRequiredFlag(modelField);
847
- continue;
848
- }
849
- if (modelField.type === "number" || modelField.format === "date-time") {
850
- querySchema[field] = (0, exports.buildNumericListQueryFieldSchema)(modelField);
851
- continue;
852
- }
853
- querySchema[field] = (0, exports.buildStringListQueryFieldSchema)(modelField);
738
+ for (const field of queryFields) {
739
+ const modelField = modelSchema[field];
740
+ if (!modelField) {
741
+ querySchema[field] = (0, exports.buildStringListQueryFieldSchema)({ type: "string" });
742
+ continue;
854
743
  }
855
- }
856
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
857
- finally {
858
- try {
859
- if (queryFields_1_1 && !queryFields_1_1.done && (_a = queryFields_1.return)) _a.call(queryFields_1);
744
+ if (modelField.type === "boolean") {
745
+ querySchema[field] = stripBooleanRequiredFlag(modelField);
746
+ continue;
747
+ }
748
+ if (modelField.type === "number" || modelField.format === "date-time") {
749
+ querySchema[field] = (0, exports.buildNumericListQueryFieldSchema)(modelField);
750
+ continue;
860
751
  }
861
- finally { if (e_3) throw e_3.error; }
752
+ querySchema[field] = (0, exports.buildStringListQueryFieldSchema)(modelField);
862
753
  }
863
754
  return querySchema;
864
755
  };