@terreno/api 57.4.0 → 57.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) 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 +617 -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/api.arrayOperations.test.ts +44 -0
  173. package/src/api.ts +64 -39
  174. package/src/audit/auditApp.test.ts +5 -5
  175. package/src/audit/auditEventModel.ts +7 -3
  176. package/src/audit/auditRouter.test.ts +5 -5
  177. package/src/audit/rbacSink.test.ts +2 -2
  178. package/src/audit/record.test.ts +2 -2
  179. package/src/audit/record.ts +3 -2
  180. package/src/auth.ts +1 -1
  181. package/src/authRecovery.test.ts +43 -0
  182. package/src/authRecovery.ts +16 -10
  183. package/src/authTokens.ts +6 -2
  184. package/src/authVerification.test.ts +22 -0
  185. package/src/browserLogsRoute.ts +110 -0
  186. package/src/configurationPlugin.test.ts +1 -11
  187. package/src/expressServer.ts +10 -0
  188. package/src/frameworkModelNames.test.ts +62 -0
  189. package/src/frameworkModelNames.ts +33 -0
  190. package/src/index.ts +7 -0
  191. package/src/isolated/migrateCliConnect.isolated.ts +51 -0
  192. package/src/mcp/auth.test.ts +34 -1
  193. package/src/migrations/cli.test.ts +0 -23
  194. package/src/models/mcpServiceToken.ts +4 -3
  195. package/src/models/notification.ts +3 -2
  196. package/src/models/notificationPreference.ts +1 -1
  197. package/src/notifications/notificationsApp.test.ts +24 -1
  198. package/src/notifiers/slackNotifier.test.ts +186 -1
  199. package/src/notifiers/slackNotifier.ts +167 -8
  200. package/src/orgs/orgPlugin.ts +1 -1
  201. package/src/orgs/organizationModel.ts +11 -6
  202. package/src/plugins.test.ts +5 -0
  203. package/src/plugins.ts +3 -0
  204. package/src/realtime/realtimeApp.ts +1 -1
  205. package/src/sync/integration.test.ts +2 -2
  206. package/src/terrenoApp.ts +3 -0
  207. package/src/types.d.ts +1 -0
  208. package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
  209. package/tsconfig.json +13 -54
  210. package/tsconfig.typedoc.json +2 -0
@@ -1,59 +1,10 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __values = (this && this.__values) || function(o) {
25
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
26
- if (m) return m.call(o);
27
- if (o && typeof o.length === "number") return {
28
- next: function () {
29
- if (o && i >= o.length) o = void 0;
30
- return { value: o && o[i++], done: !o };
31
- }
32
- };
33
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
34
- };
35
- var __read = (this && this.__read) || function (o, n) {
36
- var m = typeof Symbol === "function" && o[Symbol.iterator];
37
- if (!m) return o;
38
- var i = m.call(o), r, ar = [], e;
39
- try {
40
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
41
- }
42
- catch (error) { e = { error: error }; }
43
- finally {
44
- try {
45
- if (r && !r.done && (m = i["return"])) m.call(i);
46
- }
47
- finally { if (e) throw e.error; }
48
- }
49
- return ar;
50
- };
51
2
  Object.defineProperty(exports, "__esModule", { value: true });
52
3
  exports.fieldDescriptionToZodType = exports.modelDescriptionToAdminFields = exports.fieldDescriptionToAdminMeta = exports.modelDescriptionToOpenApiSpec = exports.fieldDescriptionToOpenApiProperty = exports.describeModelForRouter = exports.describeModel = exports.nestDottedFieldDescriptions = exports.SYSTEM_FIELD_PATHS = void 0;
53
4
  exports.SYSTEM_FIELD_PATHS = new Set(["_id", "id", "__v", "created", "updated", "deleted"]);
54
- var isSystemField = function (path) { return exports.SYSTEM_FIELD_PATHS.has(path); };
55
- var isMapWildcardPath = function (path) { return path === "$*" || path.endsWith(".$*"); };
56
- var normalizeKind = function (instance) {
5
+ const isSystemField = (path) => exports.SYSTEM_FIELD_PATHS.has(path);
6
+ const isMapWildcardPath = (path) => path === "$*" || path.endsWith(".$*");
7
+ const normalizeKind = (instance) => {
57
8
  switch (instance) {
58
9
  case "String":
59
10
  return "string";
@@ -79,272 +30,247 @@ var normalizeKind = function (instance) {
79
30
  return "mixed";
80
31
  }
81
32
  };
82
- var getNestedValueSchemaPath = function (schemaPath) {
83
- var _a;
33
+ const getNestedValueSchemaPath = (schemaPath) => {
84
34
  if (typeof schemaPath.getEmbeddedSchemaType === "function") {
85
- var embedded = schemaPath.getEmbeddedSchemaType();
35
+ const embedded = schemaPath.getEmbeddedSchemaType();
86
36
  if (embedded) {
87
37
  return embedded;
88
38
  }
89
39
  }
90
- return (_a = schemaPath.$__schemaType) !== null && _a !== void 0 ? _a : schemaPath.caster;
40
+ return schemaPath.$__schemaType ?? schemaPath.caster;
91
41
  };
92
- var describeEmbeddedSchema = function (embeddedSchema) {
93
- var e_1, _a;
94
- if (!(embeddedSchema === null || embeddedSchema === void 0 ? void 0 : embeddedSchema.paths)) {
42
+ const describeEmbeddedSchema = (embeddedSchema) => {
43
+ if (!embeddedSchema?.paths) {
95
44
  return undefined;
96
45
  }
97
- var fields = {};
98
- try {
99
- for (var _b = __values(Object.entries(embeddedSchema.paths)), _c = _b.next(); !_c.done; _c = _b.next()) {
100
- var _d = __read(_c.value, 2), path = _d[0], rawSchemaPath = _d[1];
101
- if (isMapWildcardPath(path)) {
102
- continue;
103
- }
104
- fields[path] = describeSchemaPath(path, rawSchemaPath);
105
- }
106
- }
107
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
108
- finally {
109
- try {
110
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
46
+ const fields = {};
47
+ for (const [path, rawSchemaPath] of Object.entries(embeddedSchema.paths)) {
48
+ if (isMapWildcardPath(path)) {
49
+ continue;
111
50
  }
112
- finally { if (e_1) throw e_1.error; }
51
+ fields[path] = describeSchemaPath(path, rawSchemaPath);
113
52
  }
114
53
  return (0, exports.nestDottedFieldDescriptions)(fields);
115
54
  };
116
- var describeCaster = function (caster) {
117
- var _a, _b, _c, _d;
118
- var kind = normalizeKind(caster.instance);
119
- var enumValues = ((_a = caster.enumValues) === null || _a === void 0 ? void 0 : _a.length)
55
+ const describeCaster = (caster) => {
56
+ const kind = normalizeKind(caster.instance);
57
+ const enumValues = caster.enumValues?.length
120
58
  ? caster.enumValues
121
- : (_b = caster.options) === null || _b === void 0 ? void 0 : _b.enum;
59
+ : caster.options?.enum;
122
60
  return {
123
- description: (_c = caster.options) === null || _c === void 0 ? void 0 : _c.description,
124
- enum: (enumValues === null || enumValues === void 0 ? void 0 : enumValues.length) ? enumValues : undefined,
125
- kind: kind,
126
- ref: (_d = caster.options) === null || _d === void 0 ? void 0 : _d.ref,
61
+ description: caster.options?.description,
62
+ enum: enumValues?.length ? enumValues : undefined,
63
+ kind,
64
+ ref: caster.options?.ref,
127
65
  required: false,
128
66
  };
129
67
  };
130
- var describeSchemaPath = function (path, schemaPath) {
131
- var _a, _b, _c, _d, _e;
132
- var enumValues = ((_a = schemaPath.enumValues) === null || _a === void 0 ? void 0 : _a.length)
68
+ const describeSchemaPath = (path, schemaPath) => {
69
+ const enumValues = schemaPath.enumValues?.length
133
70
  ? schemaPath.enumValues
134
- : (_b = schemaPath.options) === null || _b === void 0 ? void 0 : _b.enum;
135
- var base = {
136
- default: (_c = schemaPath.options) === null || _c === void 0 ? void 0 : _c.default,
137
- description: (_d = schemaPath.options) === null || _d === void 0 ? void 0 : _d.description,
138
- enum: (enumValues === null || enumValues === void 0 ? void 0 : enumValues.length) ? enumValues : undefined,
71
+ : schemaPath.options?.enum;
72
+ const base = {
73
+ default: schemaPath.options?.default,
74
+ description: schemaPath.options?.description,
75
+ enum: enumValues?.length ? enumValues : undefined,
139
76
  kind: normalizeKind(schemaPath.instance),
140
- ref: (_e = schemaPath.options) === null || _e === void 0 ? void 0 : _e.ref,
77
+ ref: schemaPath.options?.ref,
141
78
  required: Boolean(schemaPath.isRequired),
142
79
  system: isSystemField(path),
143
80
  };
144
81
  if (schemaPath.instance === "Array") {
145
82
  if (schemaPath.schema) {
146
- var nestedFields = describeEmbeddedSchema(schemaPath.schema);
147
- return __assign(__assign({}, base), { fields: nestedFields, isArray: true, item: {
83
+ const nestedFields = describeEmbeddedSchema(schemaPath.schema);
84
+ return {
85
+ ...base,
86
+ fields: nestedFields,
87
+ isArray: true,
88
+ item: {
148
89
  fields: nestedFields,
149
90
  kind: "embedded",
150
91
  required: false,
151
- }, kind: "embedded" });
92
+ },
93
+ kind: "embedded",
94
+ };
152
95
  }
153
- var itemSchemaPath = getNestedValueSchemaPath(schemaPath);
96
+ const itemSchemaPath = getNestedValueSchemaPath(schemaPath);
154
97
  if (itemSchemaPath) {
155
- var item = describeCaster(itemSchemaPath);
156
- var _arrayEnum = base.enum, arrayBase = __rest(base, ["enum"]);
157
- return __assign(__assign({}, arrayBase), { isArray: true, item: item, kind: item.kind });
98
+ const item = describeCaster(itemSchemaPath);
99
+ const { enum: _arrayEnum, ...arrayBase } = base;
100
+ return {
101
+ ...arrayBase,
102
+ isArray: true,
103
+ item,
104
+ kind: item.kind,
105
+ };
158
106
  }
159
- return __assign(__assign({}, base), { isArray: true, item: { kind: "mixed", required: false }, kind: "mixed" });
107
+ return {
108
+ ...base,
109
+ isArray: true,
110
+ item: { kind: "mixed", required: false },
111
+ kind: "mixed",
112
+ };
160
113
  }
161
114
  if (schemaPath.instance === "Embedded" && schemaPath.schema) {
162
- var fields = describeEmbeddedSchema(schemaPath.schema);
163
- return __assign(__assign({}, base), { fields: fields, kind: "embedded" });
115
+ const fields = describeEmbeddedSchema(schemaPath.schema);
116
+ return {
117
+ ...base,
118
+ fields,
119
+ kind: "embedded",
120
+ };
164
121
  }
165
122
  if (schemaPath.instance === "Map") {
166
- var valueSchemaPath = getNestedValueSchemaPath(schemaPath);
167
- return __assign(__assign({}, base), { item: valueSchemaPath ? describeCaster(valueSchemaPath) : { kind: "mixed", required: false }, kind: "map" });
123
+ const valueSchemaPath = getNestedValueSchemaPath(schemaPath);
124
+ return {
125
+ ...base,
126
+ item: valueSchemaPath ? describeCaster(valueSchemaPath) : { kind: "mixed", required: false },
127
+ kind: "map",
128
+ };
168
129
  }
169
130
  return base;
170
131
  };
171
- var nestDottedFieldDescriptions = function (fields) {
172
- var e_2, _a;
173
- var root = {};
174
- try {
175
- for (var _b = __values(Object.entries(fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
176
- var _d = __read(_c.value, 2), path = _d[0], field = _d[1];
177
- if (!path.includes(".")) {
178
- root[path] = field;
179
- continue;
132
+ const nestDottedFieldDescriptions = (fields) => {
133
+ const root = {};
134
+ for (const [path, field] of Object.entries(fields)) {
135
+ if (!path.includes(".")) {
136
+ root[path] = field;
137
+ continue;
138
+ }
139
+ const parts = path.split(".");
140
+ let current = root;
141
+ for (let index = 0; index < parts.length - 1; index++) {
142
+ const part = parts[index];
143
+ if (!current[part]) {
144
+ current[part] = {
145
+ fields: {},
146
+ kind: "embedded",
147
+ required: false,
148
+ };
180
149
  }
181
- var parts = path.split(".");
182
- var current = root;
183
- for (var index = 0; index < parts.length - 1; index++) {
184
- var part = parts[index];
185
- if (!current[part]) {
186
- current[part] = {
187
- fields: {},
188
- kind: "embedded",
189
- required: false,
190
- };
191
- }
192
- if (!current[part].fields) {
193
- current[part].fields = {};
194
- }
195
- current = current[part].fields;
150
+ if (!current[part].fields) {
151
+ current[part].fields = {};
196
152
  }
197
- current[parts[parts.length - 1]] = field;
198
- }
199
- }
200
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
201
- finally {
202
- try {
203
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
153
+ current = current[part].fields;
204
154
  }
205
- finally { if (e_2) throw e_2.error; }
155
+ current[parts[parts.length - 1]] = field;
206
156
  }
207
157
  return root;
208
158
  };
209
159
  exports.nestDottedFieldDescriptions = nestDottedFieldDescriptions;
210
- var isWritePathAllowed = function (path, write) {
160
+ const isWritePathAllowed = (path, write) => {
211
161
  if (write === "*") {
212
162
  return true;
213
163
  }
214
- return write.some(function (allowed) { return path === allowed || path.startsWith("".concat(allowed, ".")); });
164
+ return write.some((allowed) => path === allowed || path.startsWith(`${allowed}.`));
215
165
  };
216
- var applyWriteMasks = function (fields, options) {
217
- var _a, _b, _c;
218
- var validation = typeof options.validation === "object" && options.validation !== null
166
+ const applyWriteMasks = (fields, options) => {
167
+ const validation = typeof options.validation === "object" && options.validation !== null
219
168
  ? options.validation
220
169
  : undefined;
221
- var excludeFromCreate = new Set((_a = validation === null || validation === void 0 ? void 0 : validation.excludeFromCreate) !== null && _a !== void 0 ? _a : []);
222
- var excludeFromUpdate = new Set((_b = validation === null || validation === void 0 ? void 0 : validation.excludeFromUpdate) !== null && _b !== void 0 ? _b : []);
223
- var excludeFields = new Set((_c = options.excludeFields) !== null && _c !== void 0 ? _c : []);
224
- var fieldView = options.fieldView;
225
- var withMasks = function (path, field) {
226
- var _a;
227
- var writableOnCreate = !field.system &&
170
+ const excludeFromCreate = new Set(validation?.excludeFromCreate ?? []);
171
+ const excludeFromUpdate = new Set(validation?.excludeFromUpdate ?? []);
172
+ const excludeFields = new Set(options.excludeFields ?? []);
173
+ const fieldView = options.fieldView;
174
+ const withMasks = (path, field) => {
175
+ const writableOnCreate = !field.system &&
228
176
  !excludeFields.has(path) &&
229
177
  !excludeFromCreate.has(path) &&
230
178
  (!fieldView || isWritePathAllowed(path, fieldView.write));
231
- var writableOnUpdate = !field.system &&
179
+ const writableOnUpdate = !field.system &&
232
180
  !excludeFields.has(path) &&
233
181
  !excludeFromUpdate.has(path) &&
234
182
  (!fieldView || isWritePathAllowed(path, fieldView.write));
235
- var next = __assign(__assign({}, field), { writableOnCreate: writableOnCreate, writableOnUpdate: writableOnUpdate });
183
+ const next = {
184
+ ...field,
185
+ writableOnCreate,
186
+ writableOnUpdate,
187
+ };
236
188
  if (field.fields) {
237
- next.fields = Object.fromEntries(Object.entries(field.fields).map(function (_a) {
238
- var _b = __read(_a, 2), nestedPath = _b[0], nestedField = _b[1];
239
- return [
240
- nestedPath,
241
- withMasks("".concat(path, ".").concat(nestedPath), nestedField),
242
- ];
243
- }));
189
+ next.fields = Object.fromEntries(Object.entries(field.fields).map(([nestedPath, nestedField]) => [
190
+ nestedPath,
191
+ withMasks(`${path}.${nestedPath}`, nestedField),
192
+ ]));
244
193
  }
245
- if ((_a = field.item) === null || _a === void 0 ? void 0 : _a.fields) {
246
- next.item = __assign(__assign({}, field.item), { fields: Object.fromEntries(Object.entries(field.item.fields).map(function (_a) {
247
- var _b = __read(_a, 2), nestedPath = _b[0], nestedField = _b[1];
248
- return [
249
- nestedPath,
250
- withMasks("".concat(path, ".").concat(nestedPath), nestedField),
251
- ];
252
- })) });
194
+ if (field.item?.fields) {
195
+ next.item = {
196
+ ...field.item,
197
+ fields: Object.fromEntries(Object.entries(field.item.fields).map(([nestedPath, nestedField]) => [
198
+ nestedPath,
199
+ withMasks(`${path}.${nestedPath}`, nestedField),
200
+ ])),
201
+ };
253
202
  }
254
203
  return next;
255
204
  };
256
- return Object.fromEntries(Object.entries(fields).map(function (_a) {
257
- var _b = __read(_a, 2), path = _b[0], field = _b[1];
258
- return [path, withMasks(path, field)];
259
- }));
205
+ return Object.fromEntries(Object.entries(fields).map(([path, field]) => [path, withMasks(path, field)]));
260
206
  };
261
- var describeModel = function (model, options) {
262
- var e_3, _a, e_4, _b;
263
- if (options === void 0) { options = {}; }
264
- var fields = {};
265
- try {
266
- for (var _c = __values(Object.entries(model.schema.paths)), _d = _c.next(); !_d.done; _d = _c.next()) {
267
- var _e = __read(_d.value, 2), path = _e[0], rawSchemaPath = _e[1];
268
- if (isMapWildcardPath(path)) {
269
- continue;
270
- }
271
- fields[path] = describeSchemaPath(path, rawSchemaPath);
207
+ const describeModel = (model, options = {}) => {
208
+ const fields = {};
209
+ for (const [path, rawSchemaPath] of Object.entries(model.schema.paths)) {
210
+ if (isMapWildcardPath(path)) {
211
+ continue;
272
212
  }
273
- }
274
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
275
- finally {
276
- try {
277
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
278
- }
279
- finally { if (e_3) throw e_3.error; }
213
+ fields[path] = describeSchemaPath(path, rawSchemaPath);
280
214
  }
281
215
  if (options.extraProperties) {
282
- try {
283
- for (var _f = __values(Object.entries(options.extraProperties)), _g = _f.next(); !_g.done; _g = _f.next()) {
284
- var _h = __read(_g.value, 2), path = _h[0], field = _h[1];
285
- fields[path] = field;
286
- }
287
- }
288
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
289
- finally {
290
- try {
291
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
292
- }
293
- finally { if (e_4) throw e_4.error; }
216
+ for (const [path, field] of Object.entries(options.extraProperties)) {
217
+ fields[path] = field;
294
218
  }
295
219
  }
296
220
  return {
297
- fields: fields,
221
+ fields,
298
222
  modelName: model.modelName,
299
223
  };
300
224
  };
301
225
  exports.describeModel = describeModel;
302
- var describeModelForRouter = function (model, options) {
303
- if (options === void 0) { options = {}; }
304
- var description = (0, exports.describeModel)(model, options);
305
- return __assign(__assign({}, description), { fields: applyWriteMasks(description.fields, options) });
226
+ const describeModelForRouter = (model, options = {}) => {
227
+ const description = (0, exports.describeModel)(model, options);
228
+ return {
229
+ ...description,
230
+ fields: applyWriteMasks(description.fields, options),
231
+ };
306
232
  };
307
233
  exports.describeModelForRouter = describeModelForRouter;
308
- var fieldDescriptionToOpenApiProperty = function (field) {
234
+ const fieldDescriptionToOpenApiProperty = (field) => {
309
235
  if (field.isArray) {
310
- var items = field.item
311
- ? (0, exports.fieldDescriptionToOpenApiProperty)(__assign(__assign({}, field.item), { isArray: false }))
236
+ const items = field.item
237
+ ? (0, exports.fieldDescriptionToOpenApiProperty)({ ...field.item, isArray: false })
312
238
  : { type: "string" };
313
- var property_1 = {
239
+ const property = {
314
240
  description: field.description,
315
- items: items,
241
+ items,
316
242
  type: "array",
317
243
  };
318
- return property_1;
244
+ return property;
319
245
  }
320
246
  if (field.kind === "embedded" && field.fields) {
321
- var nested = (0, exports.modelDescriptionToOpenApiSpec)({ fields: field.fields, modelName: "" });
322
- var property_2 = {
247
+ const nested = (0, exports.modelDescriptionToOpenApiSpec)({ fields: field.fields, modelName: "" });
248
+ const property = {
323
249
  properties: nested.properties,
324
250
  type: "object",
325
251
  };
326
252
  if (field.description) {
327
- property_2.description = field.description;
253
+ property.description = field.description;
328
254
  }
329
255
  if (nested.required.length > 0) {
330
- property_2.required = nested.required;
256
+ property.required = nested.required;
331
257
  }
332
- return property_2;
258
+ return property;
333
259
  }
334
260
  if (field.kind === "mixed") {
335
261
  return { description: field.description };
336
262
  }
337
263
  if (field.kind === "map") {
338
- var property_3 = {
264
+ const property = {
339
265
  additionalProperties: field.item
340
- ? (0, exports.fieldDescriptionToOpenApiProperty)(__assign(__assign({}, field.item), { isArray: false }))
266
+ ? (0, exports.fieldDescriptionToOpenApiProperty)({ ...field.item, isArray: false })
341
267
  : { type: "string" },
342
268
  type: "object",
343
269
  };
344
270
  if (field.description) {
345
- property_3.description = field.description;
271
+ property.description = field.description;
346
272
  }
347
- return property_3;
273
+ return property;
348
274
  }
349
275
  if (field.kind === "dateOnly") {
350
276
  return {
@@ -352,8 +278,8 @@ var fieldDescriptionToOpenApiProperty = function (field) {
352
278
  type: "dateonly",
353
279
  };
354
280
  }
355
- var openApiType = field.kind === "objectId" ? "string" : field.kind === "date" ? "string" : field.kind;
356
- var property = {
281
+ const openApiType = field.kind === "objectId" ? "string" : field.kind === "date" ? "string" : field.kind;
282
+ const property = {
357
283
  type: openApiType,
358
284
  };
359
285
  if (field.description) {
@@ -371,36 +297,25 @@ var fieldDescriptionToOpenApiProperty = function (field) {
371
297
  return property;
372
298
  };
373
299
  exports.fieldDescriptionToOpenApiProperty = fieldDescriptionToOpenApiProperty;
374
- var modelDescriptionToOpenApiSpec = function (description) {
375
- var e_5, _a;
376
- var nestedFields = (0, exports.nestDottedFieldDescriptions)(description.fields);
377
- var properties = {};
378
- var required = [];
379
- try {
380
- for (var _b = __values(Object.entries(nestedFields)), _c = _b.next(); !_c.done; _c = _b.next()) {
381
- var _d = __read(_c.value, 2), path = _d[0], field = _d[1];
382
- // mongoose-to-swagger omits __v from OpenAPI components; keep parity for HTTP bodies.
383
- if (path === "__v") {
384
- continue;
385
- }
386
- properties[path] = (0, exports.fieldDescriptionToOpenApiProperty)(field);
387
- if (field.required) {
388
- required.push(path);
389
- }
300
+ const modelDescriptionToOpenApiSpec = (description) => {
301
+ const nestedFields = (0, exports.nestDottedFieldDescriptions)(description.fields);
302
+ const properties = {};
303
+ const required = [];
304
+ for (const [path, field] of Object.entries(nestedFields)) {
305
+ // mongoose-to-swagger omits __v from OpenAPI components; keep parity for HTTP bodies.
306
+ if (path === "__v") {
307
+ continue;
390
308
  }
391
- }
392
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
393
- finally {
394
- try {
395
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
309
+ properties[path] = (0, exports.fieldDescriptionToOpenApiProperty)(field);
310
+ if (field.required) {
311
+ required.push(path);
396
312
  }
397
- finally { if (e_5) throw e_5.error; }
398
313
  }
399
- return { properties: properties, required: required };
314
+ return { properties, required };
400
315
  };
401
316
  exports.modelDescriptionToOpenApiSpec = modelDescriptionToOpenApiSpec;
402
- var fieldDescriptionToAdminMeta = function (field) {
403
- var adminType = field.isArray
317
+ const fieldDescriptionToAdminMeta = (field) => {
318
+ const adminType = field.isArray
404
319
  ? "array"
405
320
  : field.kind === "objectId"
406
321
  ? "objectid"
@@ -413,7 +328,7 @@ var fieldDescriptionToAdminMeta = function (field) {
413
328
  : field.kind === "dateOnly"
414
329
  ? "dateonly"
415
330
  : field.kind;
416
- var meta = {
331
+ const meta = {
417
332
  default: field.default,
418
333
  description: field.description,
419
334
  enum: field.enum,
@@ -427,13 +342,10 @@ var fieldDescriptionToAdminMeta = function (field) {
427
342
  meta.ref = field.item.ref;
428
343
  }
429
344
  if (field.item.fields) {
430
- meta.items = Object.fromEntries(Object.entries(field.item.fields).map(function (_a) {
431
- var _b = __read(_a, 2), key = _b[0], nestedField = _b[1];
432
- return [
433
- key,
434
- (0, exports.fieldDescriptionToAdminMeta)(nestedField),
435
- ];
436
- }));
345
+ meta.items = Object.fromEntries(Object.entries(field.item.fields).map(([key, nestedField]) => [
346
+ key,
347
+ (0, exports.fieldDescriptionToAdminMeta)(nestedField),
348
+ ]));
437
349
  }
438
350
  else {
439
351
  meta.itemType =
@@ -447,34 +359,27 @@ var fieldDescriptionToAdminMeta = function (field) {
447
359
  }
448
360
  }
449
361
  if (field.kind === "embedded" && field.fields && !field.isArray) {
450
- meta.items = Object.fromEntries(Object.entries(field.fields).map(function (_a) {
451
- var _b = __read(_a, 2), key = _b[0], nestedField = _b[1];
452
- return [
453
- key,
454
- (0, exports.fieldDescriptionToAdminMeta)(nestedField),
455
- ];
456
- }));
362
+ meta.items = Object.fromEntries(Object.entries(field.fields).map(([key, nestedField]) => [
363
+ key,
364
+ (0, exports.fieldDescriptionToAdminMeta)(nestedField),
365
+ ]));
457
366
  }
458
367
  return meta;
459
368
  };
460
369
  exports.fieldDescriptionToAdminMeta = fieldDescriptionToAdminMeta;
461
- var modelDescriptionToAdminFields = function (description) {
462
- var nestedFields = (0, exports.nestDottedFieldDescriptions)(description.fields);
463
- return Object.fromEntries(Object.entries(nestedFields).map(function (_a) {
464
- var _b = __read(_a, 2), path = _b[0], field = _b[1];
465
- return [path, (0, exports.fieldDescriptionToAdminMeta)(field)];
466
- }));
370
+ const modelDescriptionToAdminFields = (description) => {
371
+ const nestedFields = (0, exports.nestDottedFieldDescriptions)(description.fields);
372
+ return Object.fromEntries(Object.entries(nestedFields).map(([path, field]) => [path, (0, exports.fieldDescriptionToAdminMeta)(field)]));
467
373
  };
468
374
  exports.modelDescriptionToAdminFields = modelDescriptionToAdminFields;
469
- var fieldDescriptionToZodType = function (field, z) {
470
- var _a;
471
- var zodType;
375
+ const fieldDescriptionToZodType = (field, z) => {
376
+ let zodType;
472
377
  if (field.isArray) {
473
- var itemType = field.item
474
- ? (0, exports.fieldDescriptionToZodType)(__assign(__assign({}, field.item), { isArray: false }), z)
378
+ const itemType = field.item
379
+ ? (0, exports.fieldDescriptionToZodType)({ ...field.item, isArray: false }, z)
475
380
  : z.any();
476
381
  zodType = z.array(itemType);
477
- if (((_a = field.item) === null || _a === void 0 ? void 0 : _a.kind) === "embedded") {
382
+ if (field.item?.kind === "embedded") {
478
383
  zodType = zodType.describe("Array of subdocuments");
479
384
  }
480
385
  if (field.description) {
@@ -507,7 +412,7 @@ var fieldDescriptionToZodType = function (field, z) {
507
412
  zodType = z.string().describe("ISO 8601 date string");
508
413
  break;
509
414
  case "objectId":
510
- zodType = z.string().describe(field.ref ? "ObjectId reference to ".concat(field.ref) : "ObjectId");
415
+ zodType = z.string().describe(field.ref ? `ObjectId reference to ${field.ref}` : "ObjectId");
511
416
  break;
512
417
  case "map":
513
418
  zodType = z.record(z.string(), z.any());