@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.
- package/README.md +5 -5
- package/bunfig.toml +1 -1
- package/dist/actions.js +197 -368
- package/dist/adminModelRouter.js +88 -173
- package/dist/api.js +598 -852
- package/dist/audit/auditApp.js +48 -89
- package/dist/audit/auditEventModel.js +15 -16
- package/dist/audit/cloudTasksEnqueue.js +56 -149
- package/dist/audit/diff.js +70 -160
- package/dist/audit/processQueue.js +25 -70
- package/dist/audit/rbacSink.js +25 -66
- package/dist/audit/record.js +129 -251
- package/dist/auth.js +432 -681
- package/dist/authRecovery.js +155 -269
- package/dist/authTokens.js +43 -118
- package/dist/betterAuthApp.js +25 -26
- package/dist/betterAuthSetup.js +258 -413
- package/dist/browserLogsRoute.d.ts +6 -0
- package/dist/browserLogsRoute.js +97 -0
- package/dist/collectionRegistry.js +32 -47
- package/dist/config.js +53 -122
- package/dist/configurationApp.js +180 -361
- package/dist/configurationPlugin.js +130 -302
- package/dist/consentApp.js +276 -421
- package/dist/docLoader.js +78 -126
- package/dist/envConfigurationPlugin.js +25 -147
- package/dist/errors.js +151 -247
- package/dist/example.js +28 -34
- package/dist/expressServer.d.ts +10 -0
- package/dist/expressServer.js +109 -255
- package/dist/frameworkModelNames.d.ts +24 -0
- package/dist/frameworkModelNames.js +31 -0
- package/dist/githubAuth.js +152 -216
- package/dist/httpClient.js +176 -264
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -2
- package/dist/logger.js +145 -278
- package/dist/mcp/auth.js +76 -128
- package/dist/mcp/createMCPRequest.js +4 -5
- package/dist/mcp/handlers.js +268 -480
- package/dist/mcp/query.js +56 -150
- package/dist/mcp/registry.js +17 -30
- package/dist/mcp/schemaGenerator.js +95 -181
- package/dist/mcp/server.js +28 -100
- package/dist/mcp/serviceTokens.js +102 -191
- package/dist/mcp/toolGenerator.js +78 -191
- package/dist/middleware.js +15 -27
- package/dist/migrations/fixtures/all-down/20260910120000-one.js +2 -42
- package/dist/migrations/fixtures/all-down/20260910120001-two.js +2 -42
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +1 -39
- package/dist/migrations/fixtures/bad-name/not-a-migration.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120000-alpha.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120001-beta.js +2 -42
- package/dist/migrations/generate.js +107 -229
- package/dist/migrations/load.js +75 -201
- package/dist/migrations/lock.js +54 -126
- package/dist/migrations/runner.js +192 -446
- package/dist/migrations/schemaCatalog.js +122 -263
- package/dist/models/consentForm.js +6 -6
- package/dist/models/consentResponse.js +5 -5
- package/dist/models/mcpServiceToken.js +66 -156
- package/dist/models/notification.js +6 -6
- package/dist/models/notificationPreference.js +6 -6
- package/dist/models/versionConfig.js +5 -5
- package/dist/notifications/notificationService.js +133 -273
- package/dist/notifications/notificationsApp.js +85 -179
- package/dist/notifications/notificationsBeforeSend.js +19 -64
- package/dist/notifiers/googleChatNotifier.js +36 -117
- package/dist/notifiers/slackNotifier.d.ts +31 -2
- package/dist/notifiers/slackNotifier.js +170 -119
- package/dist/notifiers/zoomNotifier.js +60 -111
- package/dist/openApi.js +107 -122
- package/dist/openApiBuilder.js +117 -159
- package/dist/openApiCompat.js +81 -148
- package/dist/openApiEtag.js +7 -7
- package/dist/openApiValidator.js +177 -286
- package/dist/orgs/orgContext.js +87 -157
- package/dist/orgs/orgPermissions.js +29 -68
- package/dist/orgs/orgPlugin.js +9 -27
- package/dist/orgs/organizationModel.js +65 -166
- package/dist/orgs/organizationSettings.js +29 -36
- package/dist/orgs/orgsApp.js +346 -608
- package/dist/permissions.js +88 -181
- package/dist/plugins.js +125 -218
- package/dist/populate.js +130 -240
- package/dist/rateLimit/applyTrustProxy.js +1 -1
- package/dist/rateLimit/createStore.js +7 -8
- package/dist/rateLimit/memoryStore.js +22 -100
- package/dist/rateLimit/middleware.js +48 -99
- package/dist/rateLimit/mongoStore.js +54 -112
- package/dist/rateLimit/policies.js +41 -75
- package/dist/rateLimit/redisStore.js +39 -133
- package/dist/rbac/access.js +119 -267
- package/dist/rbac/assertAllowed.js +95 -171
- package/dist/rbac/auditModel.js +14 -58
- package/dist/rbac/backfillAdmins.js +24 -130
- package/dist/rbac/fieldViews.js +46 -141
- package/dist/rbac/membershipOrgAdminSource.js +28 -99
- package/dist/rbac/middleware.js +30 -96
- package/dist/rbac/modelRouterAccess.js +130 -307
- package/dist/rbac/permissionUtils.js +40 -179
- package/dist/rbac/realtimeAccess.js +81 -147
- package/dist/rbac/resolve.d.ts +1 -1
- package/dist/rbac/resolve.js +148 -342
- package/dist/rbac/roleManager.js +318 -700
- package/dist/rbac/roleModel.js +44 -171
- package/dist/rbac/routes.js +93 -196
- package/dist/rbac/scopes.js +39 -133
- package/dist/rbac/statements.js +23 -91
- package/dist/rbac/userPlugin.js +3 -29
- package/dist/realtime/changeStreamWatcher.js +489 -800
- package/dist/realtime/deprecation.js +8 -10
- package/dist/realtime/queryMatcher.js +110 -191
- package/dist/realtime/queryStore.js +35 -118
- package/dist/realtime/realtimeApp.js +247 -401
- package/dist/realtime/registry.js +19 -30
- package/dist/realtime/sessionRevalidation.js +132 -358
- package/dist/realtime/socketAuth.js +89 -208
- package/dist/realtime/socketUser.js +10 -56
- package/dist/requestContext.js +93 -139
- package/dist/schemaMetadata.js +179 -274
- package/dist/scriptRunner.js +96 -266
- package/dist/scrubAdminFields.js +36 -108
- package/dist/secretProviders.js +130 -299
- package/dist/seedRunner.js +221 -514
- package/dist/sync/adminBroadcastScope.js +58 -170
- package/dist/sync/adminWindowAccess.js +15 -86
- package/dist/sync/adminWindowMutation.js +110 -181
- package/dist/sync/executors.js +425 -629
- package/dist/sync/loadHarness.js +392 -689
- package/dist/sync/models.js +181 -341
- package/dist/sync/mutationHandler.js +533 -801
- package/dist/sync/registrationSideEffects.js +41 -95
- package/dist/sync/registry.js +29 -49
- package/dist/sync/routes.js +484 -817
- package/dist/sync/scripts/compactTombstones.js +83 -228
- package/dist/sync/serialize.js +18 -58
- package/dist/sync/socketHandlers.js +253 -478
- package/dist/sync/streams.js +49 -117
- package/dist/sync/syncApp.js +12 -15
- package/dist/sync/syncBatch.js +63 -168
- package/dist/sync/syncSeqPlugin.js +430 -702
- package/dist/syncConsents.js +113 -253
- package/dist/terrenoApp.js +166 -276
- package/dist/tests/createTestData.js +146 -256
- package/dist/tests/models.js +14 -54
- package/dist/tests/mongoTestSetup.js +42 -103
- package/dist/tests/testHelper.js +31 -93
- package/dist/tests.js +12 -51
- package/dist/transformers.js +61 -164
- package/dist/utils.js +31 -93
- package/dist/vendor/wesleytodd-openapi/index.js +37 -51
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +32 -40
- package/dist/vendor/wesleytodd-openapi/lib/layer-schema.js +3 -3
- package/dist/vendor/wesleytodd-openapi/lib/ui.js +50 -19
- package/dist/vendor/wesleytodd-openapi/lib/validate.js +19 -47
- package/dist/versionCheckPlugin.js +52 -100
- package/dist/webhooks/headerValue.js +2 -2
- package/dist/webhooks/idempotency/memoryStore.js +16 -59
- package/dist/webhooks/idempotency/mongoStore.js +55 -130
- package/dist/webhooks/idempotency/webhookReceipt.js +9 -9
- package/dist/webhooks/rawBody.js +1 -1
- package/dist/webhooks/timingSafeEqual.js +4 -5
- package/dist/webhooks/verifiers/hmac.js +17 -18
- package/dist/webhooks/verifiers/sendgrid.js +20 -22
- package/dist/webhooks/verifiers/stripe.js +31 -65
- package/dist/webhooks/verifiers/twilio.js +23 -73
- package/dist/webhooks/webhooksApp.js +78 -177
- package/dist/zodOpenApi.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/browserLogsRoute.test.ts +165 -0
- package/src/audit/auditApp.test.ts +5 -5
- package/src/audit/auditEventModel.ts +7 -3
- package/src/audit/auditRouter.test.ts +5 -5
- package/src/audit/rbacSink.test.ts +2 -2
- package/src/audit/record.test.ts +2 -2
- package/src/audit/record.ts +3 -2
- package/src/auth.ts +1 -1
- package/src/authRecovery.test.ts +43 -0
- package/src/authRecovery.ts +16 -10
- package/src/authTokens.ts +6 -2
- package/src/authVerification.test.ts +22 -0
- package/src/browserLogsRoute.ts +110 -0
- package/src/configurationPlugin.test.ts +1 -11
- package/src/expressServer.ts +10 -0
- package/src/frameworkModelNames.test.ts +62 -0
- package/src/frameworkModelNames.ts +33 -0
- package/src/index.ts +7 -0
- package/src/isolated/migrateCliConnect.isolated.ts +51 -0
- package/src/mcp/auth.test.ts +34 -1
- package/src/migrations/cli.test.ts +0 -23
- package/src/models/mcpServiceToken.ts +4 -3
- package/src/models/notification.ts +3 -2
- package/src/models/notificationPreference.ts +1 -1
- package/src/notifications/notificationsApp.test.ts +24 -1
- package/src/notifiers/slackNotifier.test.ts +186 -1
- package/src/notifiers/slackNotifier.ts +167 -8
- package/src/orgs/orgPlugin.ts +1 -1
- package/src/orgs/organizationModel.ts +11 -6
- package/src/plugins.test.ts +5 -0
- package/src/plugins.ts +3 -0
- package/src/realtime/realtimeApp.ts +1 -1
- package/src/sync/integration.test.ts +2 -2
- package/src/terrenoApp.ts +3 -0
- package/src/types.d.ts +1 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
- package/tsconfig.json +13 -54
- package/tsconfig.typedoc.json +2 -0
package/dist/schemaMetadata.js
CHANGED
|
@@ -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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
83
|
-
var _a;
|
|
33
|
+
const getNestedValueSchemaPath = (schemaPath) => {
|
|
84
34
|
if (typeof schemaPath.getEmbeddedSchemaType === "function") {
|
|
85
|
-
|
|
35
|
+
const embedded = schemaPath.getEmbeddedSchemaType();
|
|
86
36
|
if (embedded) {
|
|
87
37
|
return embedded;
|
|
88
38
|
}
|
|
89
39
|
}
|
|
90
|
-
return
|
|
40
|
+
return schemaPath.$__schemaType ?? schemaPath.caster;
|
|
91
41
|
};
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
51
|
+
fields[path] = describeSchemaPath(path, rawSchemaPath);
|
|
113
52
|
}
|
|
114
53
|
return (0, exports.nestDottedFieldDescriptions)(fields);
|
|
115
54
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
:
|
|
59
|
+
: caster.options?.enum;
|
|
122
60
|
return {
|
|
123
|
-
description:
|
|
124
|
-
enum:
|
|
125
|
-
kind
|
|
126
|
-
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
|
-
|
|
131
|
-
|
|
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
|
-
:
|
|
135
|
-
|
|
136
|
-
default:
|
|
137
|
-
description:
|
|
138
|
-
enum:
|
|
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:
|
|
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
|
-
|
|
147
|
-
return
|
|
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
|
-
},
|
|
92
|
+
},
|
|
93
|
+
kind: "embedded",
|
|
94
|
+
};
|
|
152
95
|
}
|
|
153
|
-
|
|
96
|
+
const itemSchemaPath = getNestedValueSchemaPath(schemaPath);
|
|
154
97
|
if (itemSchemaPath) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return
|
|
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
|
|
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
|
-
|
|
163
|
-
return
|
|
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
|
-
|
|
167
|
-
return
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
182
|
-
|
|
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
|
|
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
|
-
|
|
155
|
+
current[parts[parts.length - 1]] = field;
|
|
206
156
|
}
|
|
207
157
|
return root;
|
|
208
158
|
};
|
|
209
159
|
exports.nestDottedFieldDescriptions = nestDottedFieldDescriptions;
|
|
210
|
-
|
|
160
|
+
const isWritePathAllowed = (path, write) => {
|
|
211
161
|
if (write === "*") {
|
|
212
162
|
return true;
|
|
213
163
|
}
|
|
214
|
-
return write.some(
|
|
164
|
+
return write.some((allowed) => path === allowed || path.startsWith(`${allowed}.`));
|
|
215
165
|
};
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
179
|
+
const writableOnUpdate = !field.system &&
|
|
232
180
|
!excludeFields.has(path) &&
|
|
233
181
|
!excludeFromUpdate.has(path) &&
|
|
234
182
|
(!fieldView || isWritePathAllowed(path, fieldView.write));
|
|
235
|
-
|
|
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(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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 (
|
|
246
|
-
next.item =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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(
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
283
|
-
|
|
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
|
|
221
|
+
fields,
|
|
298
222
|
modelName: model.modelName,
|
|
299
223
|
};
|
|
300
224
|
};
|
|
301
225
|
exports.describeModel = describeModel;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
234
|
+
const fieldDescriptionToOpenApiProperty = (field) => {
|
|
309
235
|
if (field.isArray) {
|
|
310
|
-
|
|
311
|
-
? (0, exports.fieldDescriptionToOpenApiProperty)(
|
|
236
|
+
const items = field.item
|
|
237
|
+
? (0, exports.fieldDescriptionToOpenApiProperty)({ ...field.item, isArray: false })
|
|
312
238
|
: { type: "string" };
|
|
313
|
-
|
|
239
|
+
const property = {
|
|
314
240
|
description: field.description,
|
|
315
|
-
items
|
|
241
|
+
items,
|
|
316
242
|
type: "array",
|
|
317
243
|
};
|
|
318
|
-
return
|
|
244
|
+
return property;
|
|
319
245
|
}
|
|
320
246
|
if (field.kind === "embedded" && field.fields) {
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
|
|
253
|
+
property.description = field.description;
|
|
328
254
|
}
|
|
329
255
|
if (nested.required.length > 0) {
|
|
330
|
-
|
|
256
|
+
property.required = nested.required;
|
|
331
257
|
}
|
|
332
|
-
return
|
|
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
|
-
|
|
264
|
+
const property = {
|
|
339
265
|
additionalProperties: field.item
|
|
340
|
-
? (0, exports.fieldDescriptionToOpenApiProperty)(
|
|
266
|
+
? (0, exports.fieldDescriptionToOpenApiProperty)({ ...field.item, isArray: false })
|
|
341
267
|
: { type: "string" },
|
|
342
268
|
type: "object",
|
|
343
269
|
};
|
|
344
270
|
if (field.description) {
|
|
345
|
-
|
|
271
|
+
property.description = field.description;
|
|
346
272
|
}
|
|
347
|
-
return
|
|
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
|
-
|
|
356
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
393
|
-
|
|
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
|
|
314
|
+
return { properties, required };
|
|
400
315
|
};
|
|
401
316
|
exports.modelDescriptionToOpenApiSpec = modelDescriptionToOpenApiSpec;
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
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(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
return Object.fromEntries(Object.entries(nestedFields).map(
|
|
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
|
-
|
|
470
|
-
|
|
471
|
-
var zodType;
|
|
375
|
+
const fieldDescriptionToZodType = (field, z) => {
|
|
376
|
+
let zodType;
|
|
472
377
|
if (field.isArray) {
|
|
473
|
-
|
|
474
|
-
? (0, exports.fieldDescriptionToZodType)(
|
|
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 (
|
|
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 ?
|
|
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());
|