@terreno/api 57.2.0 → 57.3.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 +17 -7
- package/dist/actions.js +19 -7
- package/dist/api.d.ts +4 -0
- package/dist/api.js +12 -24
- package/dist/auth.d.ts +23 -10
- package/dist/auth.js +97 -32
- package/dist/authRecovery.d.ts +5 -0
- package/dist/authRecovery.js +350 -0
- package/dist/authTokens.d.ts +8 -0
- package/dist/authTokens.js +162 -0
- package/dist/betterAuth.d.ts +33 -0
- package/dist/betterAuthApp.d.ts +4 -0
- package/dist/betterAuthApp.js +26 -8
- package/dist/betterAuthSetup.d.ts +44 -2
- package/dist/betterAuthSetup.js +288 -18
- package/dist/collectionRegistry.d.ts +38 -0
- package/dist/collectionRegistry.js +72 -0
- package/dist/configurationApp.d.ts +11 -2
- package/dist/configurationApp.js +2 -4
- package/dist/docLoader.js +35 -6
- package/dist/expressServer.d.ts +26 -3
- package/dist/expressServer.js +79 -11
- package/dist/index.d.ts +16 -0
- package/dist/index.js +38 -2
- package/dist/mcp/auth.d.ts +1 -0
- package/dist/mcp/auth.js +47 -25
- package/dist/mcp/handlers.d.ts +1 -1
- package/dist/mcp/handlers.js +67 -233
- package/dist/mcp/query.d.ts +2 -2
- package/dist/mcp/registry.d.ts +1 -5
- package/dist/mcp/registry.js +31 -20
- package/dist/mcp/schemaGenerator.d.ts +2 -7
- package/dist/mcp/schemaGenerator.js +41 -116
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +1 -0
- package/dist/mcp/serviceTokens.d.ts +16 -0
- package/dist/mcp/serviceTokens.js +345 -0
- package/dist/mcp/types.d.ts +2 -2
- package/dist/models/mcpServiceToken.d.ts +3 -0
- package/dist/models/mcpServiceToken.js +208 -0
- package/dist/openApiBuilder.d.ts +5 -4
- package/dist/openApiBuilder.js +61 -8
- package/dist/openApiCompat.js +1 -1
- package/dist/openApiValidator.js +0 -2
- package/dist/plugins.d.ts +14 -1
- package/dist/plugins.js +17 -6
- package/dist/populate.d.ts +2 -2
- package/dist/populate.js +47 -42
- package/dist/rateLimit/applyTrustProxy.d.ts +3 -0
- package/dist/rateLimit/applyTrustProxy.js +17 -0
- package/dist/rateLimit/createStore.d.ts +2 -0
- package/dist/rateLimit/createStore.js +28 -0
- package/dist/rateLimit/memoryStore.d.ts +2 -0
- package/dist/rateLimit/memoryStore.js +108 -0
- package/dist/rateLimit/middleware.d.ts +11 -0
- package/dist/rateLimit/middleware.js +110 -0
- package/dist/rateLimit/mongoStore.d.ts +3 -0
- package/dist/rateLimit/mongoStore.js +122 -0
- package/dist/rateLimit/policies.d.ts +14 -0
- package/dist/rateLimit/policies.js +151 -0
- package/dist/rateLimit/redisStore.d.ts +3 -0
- package/dist/rateLimit/redisStore.js +155 -0
- package/dist/rateLimit/types.d.ts +54 -0
- package/dist/rateLimit/types.js +9 -0
- package/dist/rbac/access.js +5 -1
- package/dist/rbac/assertAllowed.d.ts +9 -0
- package/dist/rbac/assertAllowed.js +182 -0
- package/dist/rbac/modelRouterAccess.d.ts +1 -0
- package/dist/rbac/modelRouterAccess.js +8 -4
- package/dist/rbac/permissionUtils.js +3 -2
- package/dist/rbac/resolve.js +5 -4
- package/dist/rbac/routes.js +15 -6
- package/dist/realtime/deprecation.d.ts +12 -0
- package/dist/realtime/deprecation.js +32 -0
- package/dist/realtime/realtimeApp.d.ts +1 -1
- package/dist/realtime/realtimeApp.js +10 -11
- package/dist/realtime/registry.d.ts +0 -31
- package/dist/realtime/registry.js +44 -31
- package/dist/realtime/socketAuth.d.ts +5 -5
- package/dist/realtime/socketAuth.js +11 -1
- package/dist/realtime/socketUser.d.ts +5 -1
- package/dist/realtime/types.d.ts +14 -4
- package/dist/schemaMetadata.d.ts +56 -0
- package/dist/schemaMetadata.js +513 -0
- package/dist/seedRunner.d.ts +88 -0
- package/dist/seedRunner.js +627 -0
- package/dist/sync/executors.d.ts +12 -2
- package/dist/sync/executors.js +8 -10
- package/dist/sync/loadHarness.js +28 -19
- package/dist/sync/models.js +26 -24
- package/dist/sync/mutationHandler.d.ts +9 -0
- package/dist/sync/mutationHandler.js +11 -6
- package/dist/sync/registrationSideEffects.d.ts +35 -0
- package/dist/sync/registrationSideEffects.js +151 -0
- package/dist/sync/registry.d.ts +2 -52
- package/dist/sync/registry.js +38 -187
- package/dist/sync/routes.js +3 -2
- package/dist/sync/scripts/compactTombstones.js +0 -2
- package/dist/sync/syncApp.d.ts +3 -3
- package/dist/sync/syncApp.js +4 -4
- package/dist/sync/syncBatch.js +3 -2
- package/dist/sync/syncSeqPlugin.d.ts +1 -1
- package/dist/sync/syncSeqPlugin.js +20 -16
- package/dist/terrenoApp.d.ts +19 -5
- package/dist/terrenoApp.js +66 -18
- package/dist/tests/models.d.ts +2 -0
- package/dist/tests/models.js +6 -0
- package/dist/types/authToken.d.ts +33 -0
- package/dist/types/authToken.js +2 -0
- package/dist/types/mcpServiceToken.d.ts +41 -0
- package/dist/types/mcpServiceToken.js +2 -0
- package/dist/webhooks/headerValue.d.ts +2 -0
- package/dist/webhooks/headerValue.js +14 -0
- package/dist/webhooks/idempotency/memoryStore.d.ts +10 -0
- package/dist/webhooks/idempotency/memoryStore.js +65 -0
- package/dist/webhooks/idempotency/mongoStore.d.ts +4 -0
- package/dist/webhooks/idempotency/mongoStore.js +150 -0
- package/dist/webhooks/idempotency/webhookReceipt.d.ts +62 -0
- package/dist/webhooks/idempotency/webhookReceipt.js +39 -0
- package/dist/webhooks/rawBody.d.ts +14 -0
- package/dist/webhooks/rawBody.js +22 -0
- package/dist/webhooks/timingSafeEqual.d.ts +4 -0
- package/dist/webhooks/timingSafeEqual.js +17 -0
- package/dist/webhooks/verifiers/hmac.d.ts +15 -0
- package/dist/webhooks/verifiers/hmac.js +49 -0
- package/dist/webhooks/verifiers/sendgrid.d.ts +10 -0
- package/dist/webhooks/verifiers/sendgrid.js +56 -0
- package/dist/webhooks/verifiers/stripe.d.ts +9 -0
- package/dist/webhooks/verifiers/stripe.js +99 -0
- package/dist/webhooks/verifiers/twilio.d.ts +9 -0
- package/dist/webhooks/verifiers/twilio.js +112 -0
- package/dist/webhooks/webhooksApp.d.ts +33 -0
- package/dist/webhooks/webhooksApp.js +195 -0
- package/package.json +4 -5
- package/src/__snapshots__/openApi.test.ts.snap +270 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +30 -12
- package/src/__snapshots__/schemaMetadata.test.ts.snap +197 -0
- package/src/actions.ts +20 -13
- package/src/adminModelRouter.test.ts +133 -0
- package/src/api.arrayOperations.test.ts +43 -31
- package/src/api.hooks.test.ts +38 -29
- package/src/api.query.test.ts +31 -31
- package/src/api.test.ts +95 -96
- package/src/api.ts +16 -27
- package/src/auth.test.ts +107 -51
- package/src/auth.ts +98 -29
- package/src/authRecovery.test.ts +281 -0
- package/src/authRecovery.ts +279 -0
- package/src/authTokens.test.ts +94 -0
- package/src/authTokens.ts +118 -0
- package/src/authVerification.test.ts +293 -0
- package/src/betterAuth.ts +24 -0
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthApp.ts +27 -9
- package/src/betterAuthSetup.test.ts +568 -38
- package/src/betterAuthSetup.ts +260 -5
- package/src/collectionRegistry.test.ts +165 -0
- package/src/collectionRegistry.ts +115 -0
- package/src/configurationApp.ts +13 -7
- package/src/docLoader.test.ts +45 -1
- package/src/docLoader.ts +37 -6
- package/src/express.d.ts +1 -0
- package/src/expressServer.test.ts +130 -66
- package/src/expressServer.ts +75 -19
- package/src/githubAuth.test.ts +60 -55
- package/src/index.ts +58 -0
- package/src/mcp/auth.test.ts +47 -0
- package/src/mcp/auth.ts +32 -11
- package/src/mcp/handlers.ts +45 -172
- package/src/mcp/integration.test.ts +59 -9
- package/src/mcp/query.ts +2 -4
- package/src/mcp/registry.ts +29 -20
- package/src/mcp/schemaGenerator.test.ts +8 -0
- package/src/mcp/schemaGenerator.ts +49 -131
- package/src/mcp/server.ts +2 -0
- package/src/mcp/serviceTokens.test.ts +330 -0
- package/src/mcp/serviceTokens.ts +307 -0
- package/src/mcp/toolGenerator.test.ts +1 -1
- package/src/mcp/types.ts +2 -6
- package/src/models/mcpServiceToken.test.ts +129 -0
- package/src/models/mcpServiceToken.ts +158 -0
- package/src/openApi.test.ts +80 -64
- package/src/openApiBuilder.test.ts +95 -7
- package/src/openApiBuilder.ts +46 -9
- package/src/openApiCompat.ts +1 -1
- package/src/openApiValidator.test.ts +49 -54
- package/src/openApiValidator.ts +1 -3
- package/src/plugins.test.ts +14 -0
- package/src/plugins.ts +34 -9
- package/src/populate.test.ts +34 -0
- package/src/populate.ts +40 -29
- package/src/rateLimit/applyTrustProxy.ts +17 -0
- package/src/rateLimit/createStore.ts +25 -0
- package/src/rateLimit/memoryStore.ts +40 -0
- package/src/rateLimit/middleware.ts +79 -0
- package/src/rateLimit/mongoStore.test.ts +80 -0
- package/src/rateLimit/mongoStore.ts +76 -0
- package/src/rateLimit/policies.ts +130 -0
- package/src/rateLimit/rateLimit.test.ts +328 -0
- package/src/rateLimit/redisStore.ioredis.test.ts +29 -0
- package/src/rateLimit/redisStore.test.ts +114 -0
- package/src/rateLimit/redisStore.ts +85 -0
- package/src/rateLimit/types.ts +64 -0
- package/src/rbac/access.ts +5 -1
- package/src/rbac/assertAllowed.test.ts +325 -0
- package/src/rbac/assertAllowed.ts +157 -0
- package/src/rbac/backfillAdmins.test.ts +124 -0
- package/src/rbac/fieldViews.test.ts +89 -0
- package/src/rbac/modelRouterAccess.test.ts +126 -0
- package/src/rbac/modelRouterAccess.ts +5 -2
- package/src/rbac/permissionUtils.ts +3 -2
- package/src/rbac/realtimeAccess.test.ts +109 -1
- package/src/rbac/resolve.ts +5 -4
- package/src/rbac/roleManager.test.ts +169 -0
- package/src/rbac/routes.test.ts +233 -0
- package/src/rbac/routes.ts +16 -6
- package/src/realtime/deprecation.test.ts +60 -0
- package/src/realtime/deprecation.ts +32 -0
- package/src/realtime/realtime.test.ts +8 -4
- package/src/realtime/realtimeApp.ts +10 -11
- package/src/realtime/realtimeAppSetup.test.ts +32 -5
- package/src/realtime/registry.ts +48 -42
- package/src/realtime/sessionRevalidation.test.ts +57 -44
- package/src/realtime/socketAuth.test.ts +75 -23
- package/src/realtime/socketAuth.ts +17 -6
- package/src/realtime/socketUser.ts +5 -3
- package/src/realtime/types.ts +14 -4
- package/src/schemaMetadata.test.ts +405 -0
- package/src/schemaMetadata.ts +593 -0
- package/src/scrubAdminFields.test.ts +105 -0
- package/src/seedRunner.test.ts +591 -0
- package/src/seedRunner.ts +464 -0
- package/src/sync/docMatchesMutationData.test.ts +16 -0
- package/src/sync/ensureSyncIndexes.test.ts +54 -15
- package/src/sync/executors.test.ts +40 -0
- package/src/sync/executors.ts +24 -12
- package/src/sync/integration.test.ts +15 -7
- package/src/sync/loadHarness.ts +28 -19
- package/src/sync/models.ts +32 -18
- package/src/sync/mutationHandler.test.ts +16 -16
- package/src/sync/mutationHandler.ts +9 -7
- package/src/sync/registrationSideEffects.test.ts +126 -0
- package/src/sync/registrationSideEffects.ts +131 -0
- package/src/sync/registry.ts +45 -171
- package/src/sync/routes.ts +3 -2
- package/src/sync/scripts/compactTombstones.ts +0 -2
- package/src/sync/sessionRevalidationIntegration.test.ts +12 -11
- package/src/sync/sync.test.ts +25 -23
- package/src/sync/syncApp.ts +4 -4
- package/src/sync/syncBatch.ts +3 -2
- package/src/sync/syncFrontier.test.ts +17 -15
- package/src/sync/syncPhaseC.test.ts +54 -43
- package/src/sync/syncRoutes.test.ts +51 -36
- package/src/sync/syncSeqPlugin.ts +66 -44
- package/src/sync/syncSocket.test.ts +112 -81
- package/src/terrenoApp.mcpServiceTokens.test.ts +173 -0
- package/src/terrenoApp.ts +87 -15
- package/src/tests/models.ts +14 -1
- package/src/types/authToken.ts +43 -0
- package/src/types/mcpServiceToken.ts +54 -0
- package/src/webhooks/headerValue.test.ts +22 -0
- package/src/webhooks/headerValue.ts +12 -0
- package/src/webhooks/idempotency/memoryStore.ts +34 -0
- package/src/webhooks/idempotency/mongoStore.test.ts +274 -0
- package/src/webhooks/idempotency/mongoStore.ts +83 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +70 -0
- package/src/webhooks/rawBody.test.ts +74 -0
- package/src/webhooks/rawBody.ts +23 -0
- package/src/webhooks/timingSafeEqual.ts +16 -0
- package/src/webhooks/verifiers/hmac.test.ts +110 -0
- package/src/webhooks/verifiers/hmac.ts +54 -0
- package/src/webhooks/verifiers/providerVerifiers.test.ts +388 -0
- package/src/webhooks/verifiers/sendgrid.ts +59 -0
- package/src/webhooks/verifiers/stripe.ts +67 -0
- package/src/webhooks/verifiers/twilio.ts +69 -0
- package/src/webhooks/webhooksApp.test.ts +221 -0
- package/src/webhooks/webhooksApp.ts +144 -0
package/src/api.test.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
|
-
// biome-ignore-all lint/suspicious/noImplicitAnyLet: test mock typing
|
|
4
1
|
import {beforeEach, describe, expect, it} from "bun:test";
|
|
5
2
|
import type express from "express";
|
|
6
3
|
import {DateTime} from "luxon";
|
|
7
4
|
import type mongoose from "mongoose";
|
|
5
|
+
import type {Model} from "mongoose";
|
|
8
6
|
import supertest from "supertest";
|
|
9
7
|
import type TestAgent from "supertest/lib/agent";
|
|
10
8
|
|
|
11
9
|
import {addPopulateToQuery, modelRouter} from "./api";
|
|
12
|
-
import {addAuthRoutes, setupAuth} from "./auth";
|
|
10
|
+
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "./auth";
|
|
13
11
|
import {APIError} from "./errors";
|
|
14
12
|
import {clearMCPRegistry, getMCPRegistry} from "./mcp/registry";
|
|
15
13
|
import {Permissions} from "./permissions";
|
|
@@ -25,13 +23,20 @@ import {
|
|
|
25
23
|
} from "./tests";
|
|
26
24
|
import {AdminOwnerTransformer} from "./transformers";
|
|
27
25
|
|
|
26
|
+
interface SoftDeleteDoc {
|
|
27
|
+
deleted: boolean;
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type TestUser = Awaited<ReturnType<typeof setupDb>>[number];
|
|
32
|
+
|
|
28
33
|
describe("@terreno/api", () => {
|
|
29
34
|
let server: TestAgent;
|
|
30
35
|
let app: express.Application;
|
|
31
36
|
|
|
32
37
|
describe("populate", () => {
|
|
33
|
-
let admin:
|
|
34
|
-
let notAdmin:
|
|
38
|
+
let admin: TestUser;
|
|
39
|
+
let notAdmin: TestUser;
|
|
35
40
|
let agent: TestAgent;
|
|
36
41
|
let spinach: Food;
|
|
37
42
|
|
|
@@ -61,8 +66,8 @@ describe("@terreno/api", () => {
|
|
|
61
66
|
}),
|
|
62
67
|
]);
|
|
63
68
|
app = getBaseServer();
|
|
64
|
-
setupAuth(app, UserModel as
|
|
65
|
-
addAuthRoutes(app, UserModel as
|
|
69
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
70
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
66
71
|
app.use(
|
|
67
72
|
"/food",
|
|
68
73
|
modelRouter(FoodModel, {
|
|
@@ -129,7 +134,7 @@ describe("@terreno/api", () => {
|
|
|
129
134
|
});
|
|
130
135
|
|
|
131
136
|
describe("responseHandler", () => {
|
|
132
|
-
let admin:
|
|
137
|
+
let admin: TestUser;
|
|
133
138
|
let agent: TestAgent;
|
|
134
139
|
let spinach: Food;
|
|
135
140
|
|
|
@@ -156,8 +161,8 @@ describe("@terreno/api", () => {
|
|
|
156
161
|
}),
|
|
157
162
|
]);
|
|
158
163
|
app = getBaseServer();
|
|
159
|
-
setupAuth(app, UserModel as
|
|
160
|
-
addAuthRoutes(app, UserModel as
|
|
164
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
165
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
161
166
|
app.use(
|
|
162
167
|
"/food",
|
|
163
168
|
modelRouter(FoodModel, {
|
|
@@ -169,16 +174,16 @@ describe("@terreno/api", () => {
|
|
|
169
174
|
read: [Permissions.IsAny],
|
|
170
175
|
update: [Permissions.IsAny],
|
|
171
176
|
},
|
|
172
|
-
responseHandler: (data, method) => {
|
|
173
|
-
if (method === "list") {
|
|
174
|
-
return
|
|
177
|
+
responseHandler: async (data, method) => {
|
|
178
|
+
if (method === "list" && Array.isArray(data)) {
|
|
179
|
+
return data.map((d) => ({
|
|
175
180
|
foo: "bar",
|
|
176
|
-
id: (d
|
|
181
|
+
id: String(d._id),
|
|
177
182
|
}));
|
|
178
183
|
}
|
|
179
184
|
return {
|
|
180
185
|
foo: "bar",
|
|
181
|
-
id: (data as
|
|
186
|
+
id: String((data as Food)._id),
|
|
182
187
|
};
|
|
183
188
|
},
|
|
184
189
|
})
|
|
@@ -212,8 +217,8 @@ describe("@terreno/api", () => {
|
|
|
212
217
|
beforeEach(async () => {
|
|
213
218
|
await setupDb();
|
|
214
219
|
app = getBaseServer();
|
|
215
|
-
setupAuth(app, UserModel as
|
|
216
|
-
addAuthRoutes(app, UserModel as
|
|
220
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
221
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
217
222
|
app.use(
|
|
218
223
|
"/users",
|
|
219
224
|
modelRouter(UserModel, {
|
|
@@ -241,7 +246,7 @@ describe("@terreno/api", () => {
|
|
|
241
246
|
});
|
|
242
247
|
|
|
243
248
|
describe("error handling", () => {
|
|
244
|
-
let admin:
|
|
249
|
+
let admin: TestUser;
|
|
245
250
|
let spinach: Food;
|
|
246
251
|
|
|
247
252
|
beforeEach(async () => {
|
|
@@ -259,8 +264,8 @@ describe("@terreno/api", () => {
|
|
|
259
264
|
});
|
|
260
265
|
|
|
261
266
|
app = getBaseServer();
|
|
262
|
-
setupAuth(app, UserModel as
|
|
263
|
-
addAuthRoutes(app, UserModel as
|
|
267
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
268
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
264
269
|
});
|
|
265
270
|
|
|
266
271
|
it("PUT returns 500 not supported", async () => {
|
|
@@ -295,11 +300,11 @@ describe("@terreno/api", () => {
|
|
|
295
300
|
read: [Permissions.IsAny],
|
|
296
301
|
update: [Permissions.IsAny],
|
|
297
302
|
},
|
|
298
|
-
responseHandler: (_data, method) => {
|
|
303
|
+
responseHandler: async (_data, method) => {
|
|
299
304
|
if (method === "read") {
|
|
300
305
|
throw new Error("responseHandler read failed");
|
|
301
306
|
}
|
|
302
|
-
return {}
|
|
307
|
+
return {};
|
|
303
308
|
},
|
|
304
309
|
})
|
|
305
310
|
);
|
|
@@ -321,11 +326,11 @@ describe("@terreno/api", () => {
|
|
|
321
326
|
read: [Permissions.IsAny],
|
|
322
327
|
update: [Permissions.IsAny],
|
|
323
328
|
},
|
|
324
|
-
responseHandler: (_data, method) => {
|
|
329
|
+
responseHandler: async (_data, method) => {
|
|
325
330
|
if (method === "create") {
|
|
326
331
|
throw new Error("responseHandler create failed");
|
|
327
332
|
}
|
|
328
|
-
return {}
|
|
333
|
+
return {};
|
|
329
334
|
},
|
|
330
335
|
})
|
|
331
336
|
);
|
|
@@ -347,11 +352,11 @@ describe("@terreno/api", () => {
|
|
|
347
352
|
read: [Permissions.IsAny],
|
|
348
353
|
update: [Permissions.IsAny],
|
|
349
354
|
},
|
|
350
|
-
responseHandler: (_data, method) => {
|
|
355
|
+
responseHandler: async (_data, method) => {
|
|
351
356
|
if (method === "update") {
|
|
352
357
|
throw new Error("responseHandler update failed");
|
|
353
358
|
}
|
|
354
|
-
return {}
|
|
359
|
+
return {};
|
|
355
360
|
},
|
|
356
361
|
})
|
|
357
362
|
);
|
|
@@ -373,11 +378,11 @@ describe("@terreno/api", () => {
|
|
|
373
378
|
read: [Permissions.IsAny],
|
|
374
379
|
update: [Permissions.IsAny],
|
|
375
380
|
},
|
|
376
|
-
responseHandler: (_data, method) => {
|
|
381
|
+
responseHandler: async (_data, method) => {
|
|
377
382
|
if (method === "list") {
|
|
378
383
|
throw new Error("responseHandler list failed");
|
|
379
384
|
}
|
|
380
|
-
return {}
|
|
385
|
+
return {};
|
|
381
386
|
},
|
|
382
387
|
})
|
|
383
388
|
);
|
|
@@ -399,11 +404,11 @@ describe("@terreno/api", () => {
|
|
|
399
404
|
read: [Permissions.IsAny],
|
|
400
405
|
update: [Permissions.IsAny],
|
|
401
406
|
},
|
|
402
|
-
responseHandler: (_data, method) => {
|
|
407
|
+
responseHandler: async (_data, method) => {
|
|
403
408
|
if (method === "list") {
|
|
404
|
-
return {custom: "response"}
|
|
409
|
+
return {custom: "response"};
|
|
405
410
|
}
|
|
406
|
-
return {}
|
|
411
|
+
return {};
|
|
407
412
|
},
|
|
408
413
|
})
|
|
409
414
|
);
|
|
@@ -477,8 +482,8 @@ describe("@terreno/api", () => {
|
|
|
477
482
|
"/food",
|
|
478
483
|
modelRouter(FoodModel, {
|
|
479
484
|
allowAnonymous: true,
|
|
480
|
-
endpoints: (router
|
|
481
|
-
router.get("/custom", (_req
|
|
485
|
+
endpoints: (router) => {
|
|
486
|
+
router.get("/custom", (_req, res) => {
|
|
482
487
|
res.json({custom: true});
|
|
483
488
|
});
|
|
484
489
|
},
|
|
@@ -542,7 +547,7 @@ describe("@terreno/api", () => {
|
|
|
542
547
|
});
|
|
543
548
|
|
|
544
549
|
describe("transformer errors", () => {
|
|
545
|
-
let admin:
|
|
550
|
+
let admin: TestUser;
|
|
546
551
|
let spinach: Food;
|
|
547
552
|
let agent: TestAgent;
|
|
548
553
|
|
|
@@ -561,8 +566,8 @@ describe("@terreno/api", () => {
|
|
|
561
566
|
});
|
|
562
567
|
|
|
563
568
|
app = getBaseServer();
|
|
564
|
-
setupAuth(app, UserModel as
|
|
565
|
-
addAuthRoutes(app, UserModel as
|
|
569
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
570
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
566
571
|
});
|
|
567
572
|
|
|
568
573
|
it("transform error in create is handled", async () => {
|
|
@@ -691,15 +696,15 @@ describe("@terreno/api", () => {
|
|
|
691
696
|
});
|
|
692
697
|
|
|
693
698
|
describe("soft delete with isDeleted plugin", () => {
|
|
694
|
-
let admin:
|
|
699
|
+
let admin: TestUser;
|
|
695
700
|
let agent: TestAgent;
|
|
696
701
|
|
|
697
702
|
beforeEach(async () => {
|
|
698
703
|
[admin] = await setupDb();
|
|
699
704
|
|
|
700
705
|
app = getBaseServer();
|
|
701
|
-
setupAuth(app, UserModel as
|
|
702
|
-
addAuthRoutes(app, UserModel as
|
|
706
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
707
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
703
708
|
});
|
|
704
709
|
|
|
705
710
|
it("soft deletes user with deleted field", async () => {
|
|
@@ -728,7 +733,7 @@ describe("@terreno/api", () => {
|
|
|
728
733
|
});
|
|
729
734
|
|
|
730
735
|
describe("populate in create", () => {
|
|
731
|
-
let admin:
|
|
736
|
+
let admin: TestUser;
|
|
732
737
|
|
|
733
738
|
beforeEach(async () => {
|
|
734
739
|
[admin] = await setupDb();
|
|
@@ -742,8 +747,8 @@ describe("@terreno/api", () => {
|
|
|
742
747
|
});
|
|
743
748
|
|
|
744
749
|
app = getBaseServer();
|
|
745
|
-
setupAuth(app, UserModel as
|
|
746
|
-
addAuthRoutes(app, UserModel as
|
|
750
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
751
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
747
752
|
});
|
|
748
753
|
|
|
749
754
|
it("handles populate with valid path in create", async () => {
|
|
@@ -773,7 +778,7 @@ describe("@terreno/api", () => {
|
|
|
773
778
|
});
|
|
774
779
|
|
|
775
780
|
describe("save error handling", () => {
|
|
776
|
-
let admin:
|
|
781
|
+
let admin: TestUser;
|
|
777
782
|
let spinach: Food;
|
|
778
783
|
|
|
779
784
|
beforeEach(async () => {
|
|
@@ -791,8 +796,8 @@ describe("@terreno/api", () => {
|
|
|
791
796
|
});
|
|
792
797
|
|
|
793
798
|
app = getBaseServer();
|
|
794
|
-
setupAuth(app, UserModel as
|
|
795
|
-
addAuthRoutes(app, UserModel as
|
|
799
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
800
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
796
801
|
});
|
|
797
802
|
|
|
798
803
|
it("handles patch save error with validation failure", async () => {
|
|
@@ -824,8 +829,8 @@ describe("@terreno/api", () => {
|
|
|
824
829
|
await setupDb();
|
|
825
830
|
|
|
826
831
|
app = getBaseServer();
|
|
827
|
-
setupAuth(app, UserModel as
|
|
828
|
-
addAuthRoutes(app, UserModel as
|
|
832
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
833
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
829
834
|
});
|
|
830
835
|
|
|
831
836
|
it("handles undefined body after transform when no preCreate", async () => {
|
|
@@ -854,15 +859,15 @@ describe("@terreno/api", () => {
|
|
|
854
859
|
});
|
|
855
860
|
|
|
856
861
|
describe("soft delete with deleted field", () => {
|
|
857
|
-
let _admin:
|
|
862
|
+
let _admin: TestUser;
|
|
858
863
|
let agent: TestAgent;
|
|
859
864
|
|
|
860
865
|
beforeEach(async () => {
|
|
861
866
|
[_admin] = await setupDb();
|
|
862
867
|
|
|
863
868
|
app = getBaseServer();
|
|
864
|
-
setupAuth(app, UserModel as
|
|
865
|
-
addAuthRoutes(app, UserModel as
|
|
869
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
870
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
866
871
|
});
|
|
867
872
|
|
|
868
873
|
it("soft deletes document with deleted field using isDeletedPlugin", async () => {
|
|
@@ -877,12 +882,9 @@ describe("@terreno/api", () => {
|
|
|
877
882
|
name: {description: "The name of the item", type: String},
|
|
878
883
|
});
|
|
879
884
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
} catch {
|
|
884
|
-
SoftDeleteModel = mongoose.model("SoftDeleteTest", softDeleteSchema);
|
|
885
|
-
}
|
|
885
|
+
const SoftDeleteModel =
|
|
886
|
+
(mongoose.models.SoftDeleteTest as Model<SoftDeleteDoc> | undefined) ??
|
|
887
|
+
mongoose.model<SoftDeleteDoc>("SoftDeleteTest", softDeleteSchema);
|
|
886
888
|
|
|
887
889
|
await SoftDeleteModel.deleteMany({});
|
|
888
890
|
|
|
@@ -948,7 +950,7 @@ describe("@terreno/api", () => {
|
|
|
948
950
|
});
|
|
949
951
|
|
|
950
952
|
describe("special query params", () => {
|
|
951
|
-
let admin:
|
|
953
|
+
let admin: TestUser;
|
|
952
954
|
|
|
953
955
|
beforeEach(async () => {
|
|
954
956
|
[admin] = await setupDb();
|
|
@@ -962,8 +964,8 @@ describe("@terreno/api", () => {
|
|
|
962
964
|
});
|
|
963
965
|
|
|
964
966
|
app = getBaseServer();
|
|
965
|
-
setupAuth(app, UserModel as
|
|
966
|
-
addAuthRoutes(app, UserModel as
|
|
967
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
968
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
967
969
|
});
|
|
968
970
|
|
|
969
971
|
it("period query param is stripped from query", async () => {
|
|
@@ -1024,7 +1026,7 @@ describe("@terreno/api", () => {
|
|
|
1024
1026
|
|
|
1025
1027
|
// Query for non-hidden foods using ?hidden=false
|
|
1026
1028
|
const res = await server.get("/food?hidden=false").expect(200);
|
|
1027
|
-
expect(res.body.data.every((f:
|
|
1029
|
+
expect(res.body.data.every((f: {hidden: boolean}) => f.hidden === false)).toBe(true);
|
|
1028
1030
|
});
|
|
1029
1031
|
|
|
1030
1032
|
it("$search query triggers special handling code path", async () => {
|
|
@@ -1078,7 +1080,7 @@ describe("@terreno/api", () => {
|
|
|
1078
1080
|
});
|
|
1079
1081
|
|
|
1080
1082
|
describe("array operation with undefined preUpdate return", () => {
|
|
1081
|
-
let admin:
|
|
1083
|
+
let admin: TestUser;
|
|
1082
1084
|
let apple: Food;
|
|
1083
1085
|
let agent: TestAgent;
|
|
1084
1086
|
|
|
@@ -1099,8 +1101,8 @@ describe("@terreno/api", () => {
|
|
|
1099
1101
|
});
|
|
1100
1102
|
|
|
1101
1103
|
app = getBaseServer();
|
|
1102
|
-
setupAuth(app, UserModel as
|
|
1103
|
-
addAuthRoutes(app, UserModel as
|
|
1104
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1105
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1104
1106
|
});
|
|
1105
1107
|
|
|
1106
1108
|
it("array operation preUpdate returning undefined for array POST throws error", async () => {
|
|
@@ -1115,7 +1117,7 @@ describe("@terreno/api", () => {
|
|
|
1115
1117
|
read: [Permissions.IsAdmin],
|
|
1116
1118
|
update: [Permissions.IsAdmin],
|
|
1117
1119
|
},
|
|
1118
|
-
preUpdate: () => undefined as
|
|
1120
|
+
preUpdate: () => undefined as unknown as Food,
|
|
1119
1121
|
})
|
|
1120
1122
|
);
|
|
1121
1123
|
server = supertest(app);
|
|
@@ -1295,7 +1297,7 @@ describe("@terreno/api", () => {
|
|
|
1295
1297
|
});
|
|
1296
1298
|
|
|
1297
1299
|
describe("transformer errors", () => {
|
|
1298
|
-
let admin:
|
|
1300
|
+
let admin: TestUser;
|
|
1299
1301
|
let spinach: Food;
|
|
1300
1302
|
let agent: TestAgent;
|
|
1301
1303
|
|
|
@@ -1314,8 +1316,8 @@ describe("@terreno/api", () => {
|
|
|
1314
1316
|
});
|
|
1315
1317
|
|
|
1316
1318
|
app = getBaseServer();
|
|
1317
|
-
setupAuth(app, UserModel as
|
|
1318
|
-
addAuthRoutes(app, UserModel as
|
|
1319
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1320
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1319
1321
|
});
|
|
1320
1322
|
|
|
1321
1323
|
it("transform error in create is handled", async () => {
|
|
@@ -1424,7 +1426,7 @@ describe("@terreno/api", () => {
|
|
|
1424
1426
|
});
|
|
1425
1427
|
|
|
1426
1428
|
describe("special query params", () => {
|
|
1427
|
-
let admin:
|
|
1429
|
+
let admin: TestUser;
|
|
1428
1430
|
|
|
1429
1431
|
beforeEach(async () => {
|
|
1430
1432
|
[admin] = await setupDb();
|
|
@@ -1438,8 +1440,8 @@ describe("@terreno/api", () => {
|
|
|
1438
1440
|
});
|
|
1439
1441
|
|
|
1440
1442
|
app = getBaseServer();
|
|
1441
|
-
setupAuth(app, UserModel as
|
|
1442
|
-
addAuthRoutes(app, UserModel as
|
|
1443
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1444
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1443
1445
|
});
|
|
1444
1446
|
|
|
1445
1447
|
it("period query param is stripped from query", async () => {
|
|
@@ -1500,7 +1502,7 @@ describe("@terreno/api", () => {
|
|
|
1500
1502
|
|
|
1501
1503
|
// Query for non-hidden foods using ?hidden=false
|
|
1502
1504
|
const res = await server.get("/food?hidden=false").expect(200);
|
|
1503
|
-
expect(res.body.data.every((f:
|
|
1505
|
+
expect(res.body.data.every((f: {hidden: boolean}) => f.hidden === false)).toBe(true);
|
|
1504
1506
|
});
|
|
1505
1507
|
|
|
1506
1508
|
it("$search query triggers special handling code path", async () => {
|
|
@@ -1581,15 +1583,15 @@ describe("@terreno/api", () => {
|
|
|
1581
1583
|
});
|
|
1582
1584
|
|
|
1583
1585
|
describe("soft delete with isDeleted plugin", () => {
|
|
1584
|
-
let admin:
|
|
1586
|
+
let admin: TestUser;
|
|
1585
1587
|
let agent: TestAgent;
|
|
1586
1588
|
|
|
1587
1589
|
beforeEach(async () => {
|
|
1588
1590
|
[admin] = await setupDb();
|
|
1589
1591
|
|
|
1590
1592
|
app = getBaseServer();
|
|
1591
|
-
setupAuth(app, UserModel as
|
|
1592
|
-
addAuthRoutes(app, UserModel as
|
|
1593
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1594
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1593
1595
|
});
|
|
1594
1596
|
|
|
1595
1597
|
it("soft deletes user with deleted field", async () => {
|
|
@@ -1623,7 +1625,7 @@ describe("@terreno/api", () => {
|
|
|
1623
1625
|
});
|
|
1624
1626
|
|
|
1625
1627
|
describe("populate in create", () => {
|
|
1626
|
-
let admin:
|
|
1628
|
+
let admin: TestUser;
|
|
1627
1629
|
|
|
1628
1630
|
beforeEach(async () => {
|
|
1629
1631
|
[admin] = await setupDb();
|
|
@@ -1637,8 +1639,8 @@ describe("@terreno/api", () => {
|
|
|
1637
1639
|
});
|
|
1638
1640
|
|
|
1639
1641
|
app = getBaseServer();
|
|
1640
|
-
setupAuth(app, UserModel as
|
|
1641
|
-
addAuthRoutes(app, UserModel as
|
|
1642
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1643
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1642
1644
|
});
|
|
1643
1645
|
|
|
1644
1646
|
it("handles populate with valid path in create", async () => {
|
|
@@ -1670,7 +1672,7 @@ describe("@terreno/api", () => {
|
|
|
1670
1672
|
});
|
|
1671
1673
|
|
|
1672
1674
|
describe("save error handling", () => {
|
|
1673
|
-
let admin:
|
|
1675
|
+
let admin: TestUser;
|
|
1674
1676
|
let spinach: Food;
|
|
1675
1677
|
|
|
1676
1678
|
beforeEach(async () => {
|
|
@@ -1688,8 +1690,8 @@ describe("@terreno/api", () => {
|
|
|
1688
1690
|
});
|
|
1689
1691
|
|
|
1690
1692
|
app = getBaseServer();
|
|
1691
|
-
setupAuth(app, UserModel as
|
|
1692
|
-
addAuthRoutes(app, UserModel as
|
|
1693
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1694
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1693
1695
|
});
|
|
1694
1696
|
|
|
1695
1697
|
it("handles patch save error with validation failure", async () => {
|
|
@@ -1723,8 +1725,8 @@ describe("@terreno/api", () => {
|
|
|
1723
1725
|
await setupDb();
|
|
1724
1726
|
|
|
1725
1727
|
app = getBaseServer();
|
|
1726
|
-
setupAuth(app, UserModel as
|
|
1727
|
-
addAuthRoutes(app, UserModel as
|
|
1728
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1729
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1728
1730
|
});
|
|
1729
1731
|
|
|
1730
1732
|
it("handles undefined body after transform when no preCreate", async () => {
|
|
@@ -1754,15 +1756,15 @@ describe("@terreno/api", () => {
|
|
|
1754
1756
|
});
|
|
1755
1757
|
|
|
1756
1758
|
describe("soft delete with deleted field", () => {
|
|
1757
|
-
let _admin:
|
|
1759
|
+
let _admin: TestUser;
|
|
1758
1760
|
let agent: TestAgent;
|
|
1759
1761
|
|
|
1760
1762
|
beforeEach(async () => {
|
|
1761
1763
|
[_admin] = await setupDb();
|
|
1762
1764
|
|
|
1763
1765
|
app = getBaseServer();
|
|
1764
|
-
setupAuth(app, UserModel as
|
|
1765
|
-
addAuthRoutes(app, UserModel as
|
|
1766
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1767
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1766
1768
|
});
|
|
1767
1769
|
|
|
1768
1770
|
it("soft deletes document with deleted field using isDeletedPlugin", async () => {
|
|
@@ -1778,12 +1780,9 @@ describe("@terreno/api", () => {
|
|
|
1778
1780
|
// The schema already has the deleted field, so it should use soft delete
|
|
1779
1781
|
|
|
1780
1782
|
// Check if the model already exists to avoid OverwriteModelError
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
} catch {
|
|
1785
|
-
SoftDeleteModel = mongoose.model("SoftDeleteTest", softDeleteSchema);
|
|
1786
|
-
}
|
|
1783
|
+
const SoftDeleteModel =
|
|
1784
|
+
(mongoose.models.SoftDeleteTest as Model<SoftDeleteDoc> | undefined) ??
|
|
1785
|
+
mongoose.model<SoftDeleteDoc>("SoftDeleteTest", softDeleteSchema);
|
|
1787
1786
|
|
|
1788
1787
|
// Clean up any existing documents
|
|
1789
1788
|
await SoftDeleteModel.deleteMany({});
|
|
@@ -1821,7 +1820,7 @@ describe("@terreno/api", () => {
|
|
|
1821
1820
|
});
|
|
1822
1821
|
|
|
1823
1822
|
describe("array operation with undefined preUpdate return", () => {
|
|
1824
|
-
let admin:
|
|
1823
|
+
let admin: TestUser;
|
|
1825
1824
|
let apple: Food;
|
|
1826
1825
|
let agent: TestAgent;
|
|
1827
1826
|
|
|
@@ -1842,8 +1841,8 @@ describe("@terreno/api", () => {
|
|
|
1842
1841
|
});
|
|
1843
1842
|
|
|
1844
1843
|
app = getBaseServer();
|
|
1845
|
-
setupAuth(app, UserModel as
|
|
1846
|
-
addAuthRoutes(app, UserModel as
|
|
1844
|
+
setupAuth(app, UserModel as unknown as AuthUserModel);
|
|
1845
|
+
addAuthRoutes(app, UserModel as unknown as AuthUserModel);
|
|
1847
1846
|
});
|
|
1848
1847
|
|
|
1849
1848
|
it("array operation preUpdate returning undefined for array POST throws error", async () => {
|
|
@@ -1858,7 +1857,7 @@ describe("@terreno/api", () => {
|
|
|
1858
1857
|
read: [Permissions.IsAdmin],
|
|
1859
1858
|
update: [Permissions.IsAdmin],
|
|
1860
1859
|
},
|
|
1861
|
-
preUpdate: () => undefined as
|
|
1860
|
+
preUpdate: () => undefined as unknown as Food,
|
|
1862
1861
|
})
|
|
1863
1862
|
);
|
|
1864
1863
|
server = supertest(app);
|
package/src/api.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import {enrichModelRouterOptions, type ModelRouterBuildContext} from "./adminModelRouter";
|
|
19
19
|
import type {AdminConfig} from "./adminTypes";
|
|
20
20
|
import {authenticateMiddleware, omitUserRolesFromWriteBody, type User} from "./auth";
|
|
21
|
+
import {registerCollection, replaceCollectionOptions} from "./collectionRegistry";
|
|
21
22
|
import {
|
|
22
23
|
APIError,
|
|
23
24
|
apiErrorMiddleware,
|
|
@@ -48,7 +49,7 @@ import {checkPermissions, permissionMiddleware, type RESTPermissions} from "./pe
|
|
|
48
49
|
import type {PopulatePath} from "./populate";
|
|
49
50
|
import {resolveModelRouterAccess, validateAccessWriteBody} from "./rbac/modelRouterAccess";
|
|
50
51
|
import type {AnyTerrenoAccess, ModelRouterAccessOptions} from "./rbac/types";
|
|
51
|
-
import {
|
|
52
|
+
import {warnRealtimeDeprecated} from "./realtime/deprecation";
|
|
52
53
|
import type {RealtimeConfig} from "./realtime/types";
|
|
53
54
|
import {
|
|
54
55
|
type ExecutorConcurrencyCheck,
|
|
@@ -57,7 +58,6 @@ import {
|
|
|
57
58
|
executeUpdate,
|
|
58
59
|
isExecutorConflictError,
|
|
59
60
|
} from "./sync/executors";
|
|
60
|
-
import {registerSync, updateSyncRegistryOptions} from "./sync/registry";
|
|
61
61
|
import type {SyncConfig} from "./sync/types";
|
|
62
62
|
import {
|
|
63
63
|
defaultResponseHandler,
|
|
@@ -388,6 +388,10 @@ export interface ModelRouterOptions<T> {
|
|
|
388
388
|
* through the RealtimeApp plugin's change stream watcher.
|
|
389
389
|
*
|
|
390
390
|
* Requires the RealtimeApp plugin to be registered with TerrenoApp.
|
|
391
|
+
*
|
|
392
|
+
* @deprecated Removed in Terreno 58. Use `sync` with
|
|
393
|
+
* `@terreno/syncdb` instead. `RealtimeApp` remains required for sync sockets.
|
|
394
|
+
* See docs/how-to/migrate-rtk-to-syncdb.md.
|
|
391
395
|
*/
|
|
392
396
|
realtime?: RealtimeConfig;
|
|
393
397
|
/**
|
|
@@ -663,29 +667,19 @@ export function modelRouter<T>(
|
|
|
663
667
|
options = modelOrOptions as ModelRouterOptions<T>;
|
|
664
668
|
}
|
|
665
669
|
|
|
666
|
-
//
|
|
667
|
-
//
|
|
668
|
-
if (options.mcp) {
|
|
670
|
+
// Pathless MCP only — when a route path is present, registerCollection below
|
|
671
|
+
// owns the catalog entry and MCP shares that routePath key.
|
|
672
|
+
if (options.mcp && path === undefined) {
|
|
669
673
|
registerMCPModel(model, options.mcp, options);
|
|
670
674
|
}
|
|
671
675
|
|
|
672
676
|
const shouldDeferBuild = path !== undefined && Boolean(options.access) && !options.accessControl;
|
|
673
677
|
|
|
674
678
|
if (path !== undefined) {
|
|
675
|
-
// Register before building so _buildModelRouter can replace options with
|
|
676
|
-
// RBAC-resolved permissions (same contract as MCP).
|
|
677
679
|
if (options.realtime) {
|
|
678
|
-
|
|
679
|
-
collectionName: model.collection.collectionName,
|
|
680
|
-
config: options.realtime,
|
|
681
|
-
modelName: model.modelName,
|
|
682
|
-
options: options as unknown as ModelRouterOptions<unknown>,
|
|
683
|
-
routePath: path,
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
if (options.sync) {
|
|
687
|
-
registerSync({config: options.sync, model, options, routePath: path});
|
|
680
|
+
warnRealtimeDeprecated(model.modelName, path);
|
|
688
681
|
}
|
|
682
|
+
registerCollection({model, options, routePath: path});
|
|
689
683
|
}
|
|
690
684
|
|
|
691
685
|
const router = shouldDeferBuild ? express.Router() : _buildModelRouter(model, options, path);
|
|
@@ -703,12 +697,7 @@ export function modelRouter<T>(
|
|
|
703
697
|
...enrichedOptions,
|
|
704
698
|
accessControl: enrichedOptions.accessControl ?? context.accessControl,
|
|
705
699
|
};
|
|
706
|
-
|
|
707
|
-
updateRealtimeRegistryOptions(
|
|
708
|
-
path,
|
|
709
|
-
runtimeOptions as unknown as ModelRouterOptions<unknown>
|
|
710
|
-
);
|
|
711
|
-
}
|
|
700
|
+
replaceCollectionOptions(path, runtimeOptions as unknown as ModelRouterOptions<unknown>);
|
|
712
701
|
return _buildModelRouter(model, runtimeOptions, path);
|
|
713
702
|
},
|
|
714
703
|
model,
|
|
@@ -719,6 +708,7 @@ export function modelRouter<T>(
|
|
|
719
708
|
}
|
|
720
709
|
|
|
721
710
|
if (options.realtime) {
|
|
711
|
+
warnRealtimeDeprecated(model.modelName);
|
|
722
712
|
logger.warn(
|
|
723
713
|
`modelRouter for ${model.modelName} has realtime config but was called without a path. ` +
|
|
724
714
|
"Realtime sync only works with the three-argument form: modelRouter('/path', Model, options)"
|
|
@@ -757,12 +747,12 @@ const _buildModelRouter = <T>(
|
|
|
757
747
|
options.responseHandler ??
|
|
758
748
|
defaultResponseHandler) as ModelRouterOptions<T>["responseHandler"],
|
|
759
749
|
};
|
|
750
|
+
if (routePath) {
|
|
751
|
+
replaceCollectionOptions(routePath, options as unknown as ModelRouterOptions<unknown>);
|
|
752
|
+
}
|
|
760
753
|
if (options.mcp) {
|
|
761
754
|
updateMCPRegistryOptions(model.modelName, options as unknown as ModelRouterOptions<unknown>);
|
|
762
755
|
}
|
|
763
|
-
if (options.sync && routePath) {
|
|
764
|
-
updateSyncRegistryOptions(routePath, options as unknown as ModelRouterOptions<unknown>);
|
|
765
|
-
}
|
|
766
756
|
|
|
767
757
|
assertNoActionCollisions(model, options);
|
|
768
758
|
registerActionRoutes(router, model, options);
|
|
@@ -807,7 +797,6 @@ const _buildModelRouter = <T>(
|
|
|
807
797
|
})
|
|
808
798
|
);
|
|
809
799
|
|
|
810
|
-
// TODO add rate limit
|
|
811
800
|
router.get(
|
|
812
801
|
"/",
|
|
813
802
|
[
|