@terreno/api 57.21.0 → 58.0.0-beta.2

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 (121) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +1 -1
  3. package/dist/api.d.ts +0 -13
  4. package/dist/api.js +0 -9
  5. package/dist/auth.d.ts +3 -2
  6. package/dist/auth.js +95 -5
  7. package/dist/authRecovery.d.ts +2 -1
  8. package/dist/authRecovery.js +35 -17
  9. package/dist/collectionRegistry.d.ts +3 -4
  10. package/dist/collectionRegistry.js +0 -1
  11. package/dist/consentApp.d.ts +1 -1
  12. package/dist/consentApp.js +58 -2
  13. package/dist/index.d.ts +4 -5
  14. package/dist/index.js +8 -20
  15. package/dist/mcp/adminTracking.js +1 -1
  16. package/dist/mcp/serviceTokens.d.ts +21 -1
  17. package/dist/mcp/serviceTokens.js +159 -183
  18. package/dist/migrations/builtin/mcpServiceTokenStringIds.d.ts +18 -0
  19. package/dist/migrations/builtin/mcpServiceTokenStringIds.js +67 -0
  20. package/dist/models/mcpRequestLog.js +1 -1
  21. package/dist/models/mcpServiceToken.js +36 -4
  22. package/dist/openApiBuilder.d.ts +4 -0
  23. package/dist/openApiBuilder.js +2 -0
  24. package/dist/rbac/realtimeAccess.d.ts +5 -4
  25. package/dist/rbac/realtimeAccess.js +17 -64
  26. package/dist/realtime/changeStreamWatcher.d.ts +8 -63
  27. package/dist/realtime/changeStreamWatcher.js +32 -391
  28. package/dist/realtime/realtimeApp.d.ts +14 -27
  29. package/dist/realtime/realtimeApp.js +14 -220
  30. package/dist/realtime/types.d.ts +0 -64
  31. package/dist/sync/entityIds.d.ts +14 -0
  32. package/dist/sync/entityIds.js +17 -0
  33. package/dist/sync/executors.js +14 -2
  34. package/dist/sync/models.d.ts +1 -0
  35. package/dist/sync/models.js +4 -0
  36. package/dist/sync/mutationHandler.js +51 -2
  37. package/dist/sync/routes.js +12 -17
  38. package/dist/sync/socketHandlers.d.ts +1 -1
  39. package/dist/sync/socketHandlers.js +1 -1
  40. package/dist/sync/types.d.ts +8 -0
  41. package/dist/terrenoApp.d.ts +7 -5
  42. package/dist/terrenoApp.js +18 -14
  43. package/dist/tests/openApiResponseSchema.d.ts +39 -0
  44. package/dist/tests/openApiResponseSchema.js +56 -0
  45. package/dist/tests.d.ts +1 -0
  46. package/dist/tests.js +4 -1
  47. package/dist/types/mcpAdmin.d.ts +1 -1
  48. package/dist/types/mcpServiceToken.d.ts +7 -4
  49. package/dist/versionCheckPlugin.d.ts +1 -1
  50. package/dist/versionCheckPlugin.js +25 -2
  51. package/package.json +17 -6
  52. package/src/__snapshots__/openApi.test.ts.snap +4986 -2478
  53. package/src/__snapshots__/openApiBuilder.test.ts.snap +836 -0
  54. package/src/__tests__/openApiResponseSchema.test.ts +148 -0
  55. package/src/__tests__/versionCheckPlugin.test.ts +72 -0
  56. package/src/api.test.ts +9 -7
  57. package/src/api.ts +0 -24
  58. package/src/auth.ts +116 -5
  59. package/src/authOpenApi.test.ts +316 -0
  60. package/src/authRecovery.ts +47 -19
  61. package/src/betterAuthOAuthHandoff.test.ts +13 -5
  62. package/src/collectionRegistry.ts +3 -5
  63. package/src/consentApp.test.ts +98 -0
  64. package/src/consentApp.ts +67 -2
  65. package/src/index.ts +6 -28
  66. package/src/mcp/actionTools.test.ts +2 -2
  67. package/src/mcp/adminTracking.ts +1 -1
  68. package/src/mcp/auth.test.ts +7 -3
  69. package/src/mcp/oauth.test.ts +12 -12
  70. package/src/mcp/serviceTokens.sync.test.ts +230 -0
  71. package/src/mcp/serviceTokens.test.ts +112 -61
  72. package/src/mcp/serviceTokens.ts +193 -212
  73. package/src/migrations/builtin/mcpServiceTokenStringIds.test.ts +194 -0
  74. package/src/migrations/builtin/mcpServiceTokenStringIds.ts +121 -0
  75. package/src/models/mcpRequestLog.ts +1 -1
  76. package/src/models/mcpServiceToken.test.ts +52 -5
  77. package/src/models/mcpServiceToken.ts +51 -14
  78. package/src/openApiBuilder.test.ts +34 -1
  79. package/src/openApiBuilder.ts +5 -0
  80. package/src/rateLimit/rateLimit.test.ts +25 -10
  81. package/src/rbac/realtimeAccess.test.ts +20 -172
  82. package/src/rbac/realtimeAccess.ts +17 -82
  83. package/src/realtime/changeStreamWatcher.ts +43 -506
  84. package/src/realtime/realtime.test.ts +205 -2545
  85. package/src/realtime/realtimeApp.ts +16 -295
  86. package/src/realtime/types.ts +0 -72
  87. package/src/sync/entityIds.ts +18 -0
  88. package/src/sync/executors.test.ts +28 -0
  89. package/src/sync/executors.ts +23 -2
  90. package/src/sync/models.ts +6 -0
  91. package/src/sync/mutationHandler.test.ts +84 -0
  92. package/src/sync/mutationHandler.ts +57 -2
  93. package/src/sync/routes.ts +12 -17
  94. package/src/sync/socketHandlers.ts +1 -1
  95. package/src/sync/syncRoutes.test.ts +8 -4
  96. package/src/sync/syncSocket.test.ts +77 -113
  97. package/src/sync/types.ts +9 -0
  98. package/src/terrenoApp.mcpServiceTokens.test.ts +14 -6
  99. package/src/terrenoApp.ts +24 -18
  100. package/src/tests/openApiResponseSchema.ts +104 -0
  101. package/src/tests.ts +7 -0
  102. package/src/types/mcpAdmin.ts +1 -1
  103. package/src/types/mcpServiceToken.ts +7 -4
  104. package/src/versionCheckPlugin.ts +41 -2
  105. package/biome.jsonc +0 -22
  106. package/bunfig.toml +0 -10
  107. package/bunfig.unit.toml +0 -3
  108. package/dist/realtime/deprecation.d.ts +0 -13
  109. package/dist/realtime/deprecation.js +0 -31
  110. package/dist/realtime/queryStore.d.ts +0 -37
  111. package/dist/realtime/queryStore.js +0 -103
  112. package/dist/realtime/registry.d.ts +0 -15
  113. package/dist/realtime/registry.js +0 -52
  114. package/e2e/smoke.ts +0 -193
  115. package/src/realtime/deprecation.test.ts +0 -60
  116. package/src/realtime/deprecation.ts +0 -33
  117. package/src/realtime/queryStore.ts +0 -122
  118. package/src/realtime/registry.ts +0 -84
  119. package/tsconfig.json +0 -19
  120. package/tsconfig.typecheck.json +0 -14
  121. package/tsconfig.typedoc.json +0 -13
package/e2e/smoke.ts DELETED
@@ -1,193 +0,0 @@
1
- /**
2
- * Real-process smoke for @terreno/api. Run `bun e2e/smoke.ts` after `bun run compile`.
3
- *
4
- * The smoke re-runs this file with `serve` as a child process: a minimal TerrenoApp built from
5
- * the compiled package with one modelRouter model, on a free port, against `smokeMongoUri()`.
6
- * The parent then checks over real HTTP that `/health` answers, a user can sign up, and that
7
- * user can create and list a document. Exits non-zero on the first failed check.
8
- */
9
- import {
10
- freePort,
11
- type SpawnedProcess,
12
- smokeMongoUri,
13
- spawnUntilReady,
14
- stopSmokeMongo,
15
- } from "@terreno/test";
16
- import type express from "express";
17
- import {DateTime} from "luxon";
18
- import type {Schema} from "mongoose";
19
-
20
- const SERVE_ARG = "serve";
21
-
22
- interface SmokeWidget {
23
- _id: string;
24
- name: string;
25
- ownerId: string;
26
- }
27
-
28
- /**
29
- * Child: the compiled API with auth, one owner-scoped model, and a health plugin. The API is
30
- * imported here, not at the top, so the parent process never loads it.
31
- */
32
- const serve = async (): Promise<void> => {
33
- const {createdUpdatedPlugin, logger, modelRouter, OwnerQueryFilter, Permissions, TerrenoApp} =
34
- await import("@terreno/api");
35
- const {default: mongoose} = await import("mongoose");
36
- const {default: passportLocalMongoose} = await import("passport-local-mongoose");
37
-
38
- const userSchema = new mongoose.Schema({
39
- admin: {default: false, description: "Whether the user is an admin", type: Boolean},
40
- email: {description: "Sign-in email", type: String},
41
- name: {description: "Display name", type: String},
42
- });
43
- userSchema.plugin(passportLocalMongoose as unknown as (schema: Schema, options: object) => void, {
44
- usernameCaseInsensitive: true,
45
- usernameField: "email",
46
- });
47
- userSchema.plugin(createdUpdatedPlugin);
48
- const User = mongoose.model("User", userSchema);
49
-
50
- const widgetSchema = new mongoose.Schema({
51
- name: {description: "Widget name", required: true, type: String},
52
- ownerId: {description: "User who owns the widget", ref: "User", type: String},
53
- });
54
- widgetSchema.plugin(createdUpdatedPlugin);
55
- const Widget = mongoose.model("Widget", widgetSchema);
56
-
57
- const widgetRouter = modelRouter("/widgets", Widget, {
58
- permissions: {
59
- create: [Permissions.IsAuthenticated],
60
- delete: [],
61
- list: [Permissions.IsAuthenticated],
62
- read: [Permissions.IsOwner],
63
- update: [],
64
- },
65
- preCreate: (body, req) => {
66
- const user = req.user as unknown as {_id: string};
67
- return {...(body as {name: string}), ownerId: String(user._id)};
68
- },
69
- queryFilter: OwnerQueryFilter,
70
- });
71
-
72
- const healthPlugin = {
73
- register: (app: express.Application): void => {
74
- app.get("/health", (_req, res) => {
75
- res.json({healthy: mongoose.connection.readyState === 1});
76
- });
77
- },
78
- };
79
-
80
- await mongoose.connect(process.env.MONGO_URI as string);
81
- const app = new TerrenoApp({
82
- loggingOptions: {logRequests: false},
83
- userModel: User as unknown as ConstructorParameters<typeof TerrenoApp>[0]["userModel"],
84
- })
85
- .register(widgetRouter)
86
- .register(healthPlugin);
87
- app.start();
88
- await app.whenReady();
89
- logger.info(`[apiSmoke] serving on port ${process.env.PORT}`);
90
- };
91
-
92
- const expectStatus = async (res: Response, status: number, step: string): Promise<unknown> => {
93
- const body = await res.text();
94
- if (res.status !== status) {
95
- throw new Error(`${step}: expected ${status}, got ${res.status}: ${body}`);
96
- }
97
- return body ? JSON.parse(body) : undefined;
98
- };
99
-
100
- /** Parent: boots the child and walks the happy path over HTTP. */
101
- const run = async (): Promise<void> => {
102
- const startedAt = DateTime.now();
103
- const port = await freePort();
104
- const baseUrl = `http://127.0.0.1:${port}`;
105
- let server: SpawnedProcess | undefined;
106
-
107
- try {
108
- server = await spawnUntilReady({
109
- cmd: [process.execPath, __filename, SERVE_ARG],
110
- env: {
111
- MONGO_URI: await smokeMongoUri({databaseName: "apiSmoke"}),
112
- PORT: String(port),
113
- REFRESH_TOKEN_SECRET: "api-smoke-refresh-secret",
114
- SESSION_SECRET: "api-smoke-session-secret",
115
- TOKEN_ISSUER: "api-smoke",
116
- TOKEN_SECRET: "api-smoke-token-secret",
117
- },
118
- timeoutMs: 20000,
119
- url: `${baseUrl}/health`,
120
- });
121
-
122
- const health = (await expectStatus(await fetch(`${baseUrl}/health`), 200, "GET /health")) as {
123
- healthy: boolean;
124
- };
125
- if (!health.healthy) {
126
- throw new Error("GET /health: server reports unhealthy");
127
- }
128
- console.info("✅ GET /health is healthy");
129
-
130
- const email = `api-smoke-${startedAt.toMillis()}@example.com`;
131
- const signup = (await expectStatus(
132
- await fetch(`${baseUrl}/auth/signup`, {
133
- body: JSON.stringify({email, password: "api-smoke-password-1"}),
134
- headers: {"Content-Type": "application/json"},
135
- method: "POST",
136
- }),
137
- 200,
138
- "POST /auth/signup"
139
- )) as {data: {token: string; userId: string}};
140
- const headers = {
141
- Authorization: `Bearer ${signup.data.token}`,
142
- "Content-Type": "application/json",
143
- };
144
- console.info("✅ POST /auth/signup returns a token");
145
-
146
- const created = (await expectStatus(
147
- await fetch(`${baseUrl}/widgets`, {
148
- body: JSON.stringify({name: "Smoke widget"}),
149
- headers,
150
- method: "POST",
151
- }),
152
- 201,
153
- "POST /widgets"
154
- )) as {data: SmokeWidget};
155
- if (created.data.ownerId !== String(signup.data.userId)) {
156
- throw new Error(`POST /widgets: ownerId ${created.data.ownerId} is not the new user`);
157
- }
158
- console.info("✅ POST /widgets creates an owned widget");
159
-
160
- const listed = (await expectStatus(
161
- await fetch(`${baseUrl}/widgets`, {headers}),
162
- 200,
163
- "GET /widgets"
164
- )) as {data: SmokeWidget[]};
165
- if (!listed.data.some((widget) => widget._id === created.data._id)) {
166
- throw new Error("GET /widgets: the created widget is missing from the list");
167
- }
168
- console.info("✅ GET /widgets lists it");
169
- } catch (error: unknown) {
170
- if (server) {
171
- console.error(`--- server output ---\n${server.output()}`);
172
- }
173
- throw error;
174
- } finally {
175
- await server?.stop();
176
- await stopSmokeMongo();
177
- }
178
-
179
- console.info(`api smoke passed in ${DateTime.now().diff(startedAt).toMillis()} ms`);
180
- };
181
-
182
- const main = process.argv[2] === SERVE_ARG ? serve : run;
183
- main().then(
184
- () => {
185
- if (main === run) {
186
- process.exit(0);
187
- }
188
- },
189
- (error: unknown) => {
190
- console.error(`❌ ${error instanceof Error ? error.message : String(error)}`);
191
- process.exit(1);
192
- }
193
- );
@@ -1,60 +0,0 @@
1
- import {afterEach, describe, expect, it, spyOn} from "bun:test";
2
-
3
- import {modelRouter} from "../api";
4
- import {logger} from "../logger";
5
- import {Permissions} from "../permissions";
6
- import {FoodModel} from "../tests";
7
- import {
8
- REALTIME_DEPRECATION_MESSAGE,
9
- resetRealtimeDeprecationWarningsForTests,
10
- } from "./deprecation";
11
- import {clearRealtimeRegistry} from "./registry";
12
-
13
- const realtimeConfig = {
14
- methods: ["create", "update", "delete"] as Array<"create" | "update" | "delete">,
15
- roomStrategy: "model" as const,
16
- };
17
-
18
- const permissions = {
19
- create: [Permissions.IsAny],
20
- delete: [Permissions.IsAny],
21
- list: [Permissions.IsAny],
22
- read: [Permissions.IsAny],
23
- update: [Permissions.IsAny],
24
- };
25
-
26
- describe("modelRouter realtime deprecation", () => {
27
- afterEach(() => {
28
- resetRealtimeDeprecationWarningsForTests();
29
- clearRealtimeRegistry();
30
- });
31
-
32
- it("warns once per model and path when realtime is configured", () => {
33
- const warnSpy = spyOn(logger, "warn").mockImplementation(() => logger);
34
-
35
- modelRouter("/foods", FoodModel, {permissions, realtime: realtimeConfig});
36
- modelRouter("/foods", FoodModel, {permissions, realtime: realtimeConfig});
37
-
38
- const deprecationCalls = warnSpy.mock.calls.filter((args) =>
39
- String(args[0]).includes(REALTIME_DEPRECATION_MESSAGE)
40
- );
41
- expect(deprecationCalls).toHaveLength(1);
42
- expect(String(deprecationCalls[0]?.[0])).toContain("Food at /foods");
43
-
44
- warnSpy.mockRestore();
45
- });
46
-
47
- it("warns when realtime is used without the path form", () => {
48
- const warnSpy = spyOn(logger, "warn").mockImplementation(() => logger);
49
-
50
- modelRouter(FoodModel, {permissions, realtime: realtimeConfig});
51
-
52
- const deprecationCalls = warnSpy.mock.calls.filter((args) =>
53
- String(args[0]).includes(REALTIME_DEPRECATION_MESSAGE)
54
- );
55
- expect(deprecationCalls).toHaveLength(1);
56
- expect(String(deprecationCalls[0]?.[0])).toContain("(Food)");
57
-
58
- warnSpy.mockRestore();
59
- });
60
- });
@@ -1,33 +0,0 @@
1
- import {logger} from "../logger";
2
-
3
- /**
4
- * One-line warning for modelRouter `realtime`. Keep in sync with the
5
- * `@terreno/rtk` helpers and `docs/implementationPlans/remove-legacy-realtime.md`.
6
- */
7
- /** @internal */
8
- export const REALTIME_DEPRECATION_MESSAGE =
9
- "modelRouter `realtime` is deprecated and will be removed in Terreno 58. Use `sync` with `@terreno/syncdb` instead. See docs/how-to/migrate-rtk-to-syncdb.md. RealtimeApp remains required for sync sockets.";
10
-
11
- const warnedKeys = new Set<string>();
12
-
13
- const warningKey = (modelName: string, routePath?: string): string =>
14
- `${modelName}:${routePath ?? ""}`;
15
-
16
- /**
17
- * Emits a one-time deprecation warning per model/routePath per process when a
18
- * consumer enables the legacy RTK cache-patching `realtime` option.
19
- */
20
- export const warnRealtimeDeprecated = (modelName: string, routePath?: string): void => {
21
- const key = warningKey(modelName, routePath);
22
- if (warnedKeys.has(key)) {
23
- return;
24
- }
25
- warnedKeys.add(key);
26
- const location = routePath ? `${modelName} at ${routePath}` : modelName;
27
- logger.warn(`[realtime] ${REALTIME_DEPRECATION_MESSAGE} (${location})`);
28
- };
29
-
30
- /** @internal Test helper — clears one-time realtime deprecation warnings. */
31
- export const resetRealtimeDeprecationWarningsForTests = (): void => {
32
- warnedKeys.clear();
33
- };
@@ -1,122 +0,0 @@
1
- /**
2
- * Manages query subscriptions for Socket.io clients.
3
- *
4
- * When a client subscribes to a query (e.g., `{completed: false}` on the "todos" collection),
5
- * the query is stored here. The change stream watcher consults this store to determine
6
- * which query rooms should receive a given change event.
7
- */
8
-
9
- interface QuerySubscription {
10
- collection: string;
11
- query: Record<string, unknown>;
12
- queryId: string;
13
- }
14
-
15
- /**
16
- * Compute a deterministic queryId from collection and query on the server side.
17
- * This prevents clients from hijacking other subscriptions by providing a colliding queryId.
18
- */
19
- export const computeQueryId = (collection: string, query: Record<string, unknown>): string => {
20
- const sortedKeys = Object.keys(query).sort();
21
- const normalized: Record<string, unknown> = {};
22
- for (const key of sortedKeys) {
23
- normalized[key] = query[key];
24
- }
25
- return `${collection}:${JSON.stringify(normalized)}`;
26
- };
27
-
28
- /** queryId → query subscription details (shared across all sockets in that room) */
29
- const querySubscriptions = new Map<string, QuerySubscription>();
30
-
31
- /** socketId → set of queryIds that socket is subscribed to */
32
- const socketQueries = new Map<string, Set<string>>();
33
-
34
- /**
35
- * Register a query subscription for a socket.
36
- * The socket joins the `query:{queryId}` room (handled by the caller).
37
- */
38
- export const addQuerySubscription = (
39
- socketId: string,
40
- collection: string,
41
- query: Record<string, unknown>,
42
- queryId: string
43
- ): void => {
44
- querySubscriptions.set(queryId, {collection, query, queryId});
45
-
46
- if (!socketQueries.has(socketId)) {
47
- socketQueries.set(socketId, new Set());
48
- }
49
- socketQueries.get(socketId)?.add(queryId);
50
- };
51
-
52
- /**
53
- * Remove a single query subscription for a socket.
54
- */
55
- export const removeQuerySubscription = (socketId: string, queryId: string): void => {
56
- socketQueries.get(socketId)?.delete(queryId);
57
-
58
- // Check if any other socket still has this query
59
- let stillUsed = false;
60
- for (const [, queryIds] of socketQueries) {
61
- if (queryIds.has(queryId)) {
62
- stillUsed = true;
63
- break;
64
- }
65
- }
66
-
67
- if (!stillUsed) {
68
- querySubscriptions.delete(queryId);
69
- }
70
- };
71
-
72
- /**
73
- * Remove all query subscriptions for a disconnected socket.
74
- */
75
- export const removeAllSocketQueries = (socketId: string): void => {
76
- const queryIds = socketQueries.get(socketId);
77
- if (!queryIds) {
78
- return;
79
- }
80
-
81
- socketQueries.delete(socketId);
82
-
83
- // Clean up any queries that no longer have subscribers
84
- for (const queryId of queryIds) {
85
- let stillUsed = false;
86
- for (const [, otherQueryIds] of socketQueries) {
87
- if (otherQueryIds.has(queryId)) {
88
- stillUsed = true;
89
- break;
90
- }
91
- }
92
- if (!stillUsed) {
93
- querySubscriptions.delete(queryId);
94
- }
95
- }
96
- };
97
-
98
- /**
99
- * Get all unique query subscriptions for a given collection.
100
- * Used by the change stream watcher to evaluate which query rooms to emit to.
101
- */
102
- export const getQuerySubscriptionsForCollection = (
103
- collection: string
104
- ): {queryId: string; query: Record<string, unknown>}[] => {
105
- const result: {queryId: string; query: Record<string, unknown>}[] = [];
106
-
107
- for (const [queryId, sub] of querySubscriptions) {
108
- if (sub.collection === collection) {
109
- result.push({query: sub.query, queryId});
110
- }
111
- }
112
-
113
- return result;
114
- };
115
-
116
- /**
117
- * Clear all subscriptions (for testing).
118
- */
119
- export const clearQueryStore = (): void => {
120
- querySubscriptions.clear();
121
- socketQueries.clear();
122
- };
@@ -1,84 +0,0 @@
1
- import type {Model} from "mongoose";
2
-
3
- import type {ModelRouterOptions} from "../api";
4
- import {
5
- clearCollectionRegistry,
6
- listCollections,
7
- registerCollection,
8
- replaceCollectionOptions,
9
- } from "../collectionRegistry";
10
- import type {RealtimeConfig} from "./types";
11
-
12
- export interface RealtimeRegistryEntry {
13
- modelName: string;
14
- routePath: string;
15
- collectionName: string;
16
- config: RealtimeConfig;
17
- options: ModelRouterOptions<unknown>;
18
- }
19
-
20
- const toRealtimeEntry = (record: {
21
- model: Model<unknown>;
22
- options: ModelRouterOptions<unknown>;
23
- routePath: string;
24
- }): RealtimeRegistryEntry => ({
25
- collectionName: record.model.collection.collectionName,
26
- config: record.options.realtime as RealtimeConfig,
27
- modelName: record.model.modelName,
28
- options: record.options,
29
- routePath: record.routePath,
30
- });
31
-
32
- const realtimeModelForEntry = (entry: RealtimeRegistryEntry): Model<unknown> => {
33
- const registered = listCollections().find(
34
- (record) => record.routePath === entry.routePath
35
- )?.model;
36
- if (registered) {
37
- return registered;
38
- }
39
- return {
40
- collection: {collectionName: entry.collectionName},
41
- modelName: entry.modelName,
42
- } as Model<unknown>;
43
- };
44
-
45
- export const registerRealtime = (entry: RealtimeRegistryEntry): void => {
46
- registerCollection({
47
- model: realtimeModelForEntry(entry),
48
- options: {
49
- ...entry.options,
50
- realtime: entry.config,
51
- } as ModelRouterOptions<unknown>,
52
- routePath: entry.routePath,
53
- });
54
- };
55
-
56
- export const updateRealtimeRegistryOptions = (
57
- routePath: string,
58
- options: ModelRouterOptions<unknown>
59
- ): void => {
60
- replaceCollectionOptions(routePath, options);
61
- };
62
-
63
- export const getRealtimeRegistry = (): RealtimeRegistryEntry[] =>
64
- listCollections()
65
- .filter((record) => record.surfaces.realtime)
66
- .map(toRealtimeEntry);
67
-
68
- export const findRegistryEntryByCollection = (
69
- collectionName: string
70
- ): RealtimeRegistryEntry | undefined => {
71
- return getRealtimeRegistry().find((entry) => entry.collectionName === collectionName);
72
- };
73
-
74
- export const findRegistryEntryByRoutePath = (
75
- collection: string
76
- ): RealtimeRegistryEntry | undefined => {
77
- return getRealtimeRegistry().find(
78
- (entry) => entry.routePath === `/${collection}` || entry.routePath === collection
79
- );
80
- };
81
-
82
- export const clearRealtimeRegistry = (): void => {
83
- clearCollectionRegistry();
84
- };
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "declaration": true,
5
- "isolatedModules": true,
6
- "lib": ["es2023"],
7
- "module": "nodenext",
8
- "noImplicitAny": false,
9
- "noImplicitReturns": true,
10
- "outDir": "./dist",
11
- "rootDir": "./src",
12
- "skipLibCheck": true,
13
- "strict": true,
14
- "target": "es2023",
15
- "types": ["bun", "node"]
16
- },
17
- "exclude": ["node_modules", "**/*.test.ts", "**/*.isolated.ts", "src/isolated", "src/tests", "src/migrations/cli.ts"],
18
- "include": ["src"]
19
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": true,
5
- "composite": false,
6
- "incremental": false,
7
- "declaration": false,
8
- "declarationMap": false
9
- },
10
- "exclude": [
11
- "node_modules",
12
- "dist"
13
- ]
14
- }
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "exclude": [
4
- "node_modules",
5
- "src/tests.ts",
6
- "src/tests/**",
7
- "**/*.test.ts",
8
- "**/*.isolated.ts",
9
- "src/isolated",
10
- "src/sync/loadHarness.ts",
11
- "src/migrations/cli.ts"
12
- ]
13
- }