@rpcbase/server 0.481.0 → 0.482.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.
@@ -1,4 +1,4 @@
1
- import { loadModel, getTenantFilesystemDb } from "@rpcbase/db";
1
+ import { models, getTenantFilesystemDb } from "@rpcbase/db";
2
2
  import { GridFSBucket, ObjectId } from "mongodb";
3
3
  import { JSDOM } from "jsdom";
4
4
  import createDOMPurify from "dompurify";
@@ -124,8 +124,8 @@ const completeUpload = async (_payload, ctx) => {
124
124
  }
125
125
  const modelCtx = getModelCtx(ctx, tenantId);
126
126
  const [UploadSession, UploadChunk] = await Promise.all([
127
- loadModel("RBUploadSession", modelCtx),
128
- loadModel("RBUploadChunk", modelCtx)
127
+ models.get("RBUploadSession", modelCtx),
128
+ models.get("RBUploadChunk", modelCtx)
129
129
  ]);
130
130
  const ability = buildUploadsAbility(ctx, tenantId);
131
131
  if (!ability.can("update", "RBUploadSession")) {
@@ -352,8 +352,8 @@ const getStatus = async (_payload, ctx) => {
352
352
  }
353
353
  const modelCtx = getModelCtx(ctx, tenantId);
354
354
  const [UploadSession, UploadChunk] = await Promise.all([
355
- loadModel("RBUploadSession", modelCtx),
356
- loadModel("RBUploadChunk", modelCtx)
355
+ models.get("RBUploadSession", modelCtx),
356
+ models.get("RBUploadChunk", modelCtx)
357
357
  ]);
358
358
  const ability = buildUploadsAbility(ctx, tenantId);
359
359
  if (!ability.can("read", "RBUploadSession")) {
@@ -428,8 +428,8 @@ const initUpload = async (payload, ctx) => {
428
428
  const chunksTotal = Math.ceil(totalSize / chunkSize);
429
429
  const modelCtx = getModelCtx(ctx, tenantId);
430
430
  const [UploadSession, UploadChunk] = await Promise.all([
431
- loadModel("RBUploadSession", modelCtx),
432
- loadModel("RBUploadChunk", modelCtx)
431
+ models.get("RBUploadSession", modelCtx),
432
+ models.get("RBUploadChunk", modelCtx)
433
433
  ]);
434
434
  await ensureUploadIndexes(UploadSession, UploadChunk);
435
435
  const uploadId = new ObjectId().toString();
@@ -474,8 +474,8 @@ const uploadChunk = async (payload, ctx) => {
474
474
  }
475
475
  const modelCtx = getModelCtx(ctx, tenantId);
476
476
  const [UploadSession, UploadChunk] = await Promise.all([
477
- loadModel("RBUploadSession", modelCtx),
478
- loadModel("RBUploadChunk", modelCtx)
477
+ models.get("RBUploadSession", modelCtx),
478
+ models.get("RBUploadChunk", modelCtx)
479
479
  ]);
480
480
  const ability = buildUploadsAbility(ctx, tenantId);
481
481
  if (!ability.can("update", "RBUploadSession")) {
@@ -1,4 +1,4 @@
1
- import { loadModel } from "@rpcbase/db";
1
+ import { models } from "@rpcbase/db";
2
2
  import { buildAbilityFromSession, getAccessibleByQuery } from "@rpcbase/db/acl";
3
3
  import { createNotification, sendNotificationsDigestForUser } from "./notifications.js";
4
4
  import { o as object, b as boolean, n as number, a as array, s as string, r as record, u as unknown, _ as _enum } from "./schemas-D5T9tDtI.js";
@@ -139,10 +139,10 @@ const listNotifications = async (payload, ctx) => {
139
139
  const unreadOnly = parsed.data.unreadOnly === true;
140
140
  const limit = parsed.data.limit ?? 50;
141
141
  const markSeen = parsed.data.markSeen === true;
142
- const SettingsModel = await loadModel("RBNotificationSettings", ctx);
142
+ const SettingsModel = await models.get("RBNotificationSettings", ctx);
143
143
  const settings = await SettingsModel.findOne({ userId }).lean();
144
144
  const disabledTopics = buildDisabledTopics(settings, "inApp");
145
- const NotificationModel = await loadModel("RBNotification", ctx);
145
+ const NotificationModel = await models.get("RBNotification", ctx);
146
146
  const queryFilters = [
147
147
  { userId },
148
148
  getAccessibleByQuery(ability, "read", "RBNotification")
@@ -234,7 +234,7 @@ const markRead = async (_payload, ctx) => {
234
234
  ctx.res.status(400);
235
235
  return { ok: false, error: "missing_notification_id" };
236
236
  }
237
- const NotificationModel = await loadModel("RBNotification", ctx);
237
+ const NotificationModel = await models.get("RBNotification", ctx);
238
238
  const now = /* @__PURE__ */ new Date();
239
239
  try {
240
240
  await NotificationModel.updateOne(
@@ -257,10 +257,10 @@ const markAllRead = async (_payload, ctx) => {
257
257
  ctx.res.status(403);
258
258
  return { ok: false, error: "forbidden" };
259
259
  }
260
- const SettingsModel = await loadModel("RBNotificationSettings", ctx);
260
+ const SettingsModel = await models.get("RBNotificationSettings", ctx);
261
261
  const settings = await SettingsModel.findOne({ userId: session.userId }).lean();
262
262
  const disabledTopics = buildDisabledTopics(settings, "inApp");
263
- const NotificationModel = await loadModel("RBNotification", ctx);
263
+ const NotificationModel = await models.get("RBNotification", ctx);
264
264
  const queryFilters = [
265
265
  { userId: session.userId },
266
266
  { archivedAt: { $exists: false } },
@@ -288,7 +288,7 @@ const archiveNotification = async (_payload, ctx) => {
288
288
  ctx.res.status(400);
289
289
  return { ok: false, error: "missing_notification_id" };
290
290
  }
291
- const NotificationModel = await loadModel("RBNotification", ctx);
291
+ const NotificationModel = await models.get("RBNotification", ctx);
292
292
  try {
293
293
  await NotificationModel.updateOne(
294
294
  { $and: [{ _id: notificationId }, { archivedAt: { $exists: false } }, getAccessibleByQuery(ability, "update", "RBNotification")] },
@@ -310,7 +310,7 @@ const getSettings = async (_payload, ctx) => {
310
310
  ctx.res.status(403);
311
311
  return { ok: false, error: "forbidden" };
312
312
  }
313
- const SettingsModel = await loadModel("RBNotificationSettings", ctx);
313
+ const SettingsModel = await models.get("RBNotificationSettings", ctx);
314
314
  const settings = await SettingsModel.findOne(
315
315
  { $and: [{ userId: session.userId }, getAccessibleByQuery(ability, "read", "RBNotificationSettings")] }
316
316
  ).lean();
@@ -346,7 +346,7 @@ const updateSettings = async (payload, ctx) => {
346
346
  ctx.res.status(400);
347
347
  return { ok: false, error: "invalid_payload" };
348
348
  }
349
- const SettingsModel = await loadModel("RBNotificationSettings", ctx);
349
+ const SettingsModel = await models.get("RBNotificationSettings", ctx);
350
350
  const nextValues = {};
351
351
  if (parsed.data.digestFrequency) {
352
352
  nextValues.digestFrequency = parsed.data.digestFrequency;
@@ -1,4 +1,4 @@
1
- import { loadModel, ZRBRtsChangeOp } from "@rpcbase/db";
1
+ import { models, ZRBRtsChangeOp } from "@rpcbase/db";
2
2
  import { buildAbilityFromSession } from "@rpcbase/db/acl";
3
3
  import { o as object, a as array, s as string, n as number, b as boolean, _ as _enum } from "./schemas-D5T9tDtI.js";
4
4
  const Route = "/api/rb/rts/changes";
@@ -72,8 +72,8 @@ const changesHandler = async (payload, ctx) => {
72
72
  const ability = buildAbilityFromSession({ tenantId, session: ctx.req.session });
73
73
  const modelCtx = getModelCtx(ctx, tenantId);
74
74
  const [RtsChange, RtsCounter] = await Promise.all([
75
- loadModel("RBRtsChange", modelCtx),
76
- loadModel("RBRtsCounter", modelCtx)
75
+ models.get("RBRtsChange", modelCtx),
76
+ models.get("RBRtsCounter", modelCtx)
77
77
  ]);
78
78
  const counter = await RtsCounter.findOne({ _id: "rts" }, { seq: 1 }).lean();
79
79
  const latestSeq = Number(counter?.seq ?? 0) || 0;
@@ -1,7 +1,7 @@
1
- import { loadModel, loadRbModel } from "@rpcbase/db";
1
+ import { models } from "@rpcbase/db";
2
2
  import { s as sendEmail } from "./email-DEw8keax.js";
3
3
  const routes = Object.entries({
4
- .../* @__PURE__ */ Object.assign({ "./api/notifications/handler.ts": () => import("./handler-B_mMDLBO.js") })
4
+ .../* @__PURE__ */ Object.assign({ "./api/notifications/handler.ts": () => import("./handler-BvRk-c8E.js") })
5
5
  }).reduce((acc, [path, mod]) => {
6
6
  acc[path.replace("./api/", "@rpcbase/server/notifications/api/")] = mod;
7
7
  return acc;
@@ -18,7 +18,7 @@ const createNotification = async (ctx, input) => {
18
18
  const topic = typeof input.topic === "string" ? input.topic.trim() : "";
19
19
  const body = typeof input.body === "string" ? input.body.trim() : "";
20
20
  const url = typeof input.url === "string" ? input.url.trim() : "";
21
- const NotificationModel = await loadModel("RBNotification", ctx);
21
+ const NotificationModel = await models.get("RBNotification", ctx);
22
22
  const doc = await NotificationModel.create({
23
23
  userId,
24
24
  ...topic ? { topic } : {},
@@ -57,8 +57,8 @@ const sendNotificationsDigestForUser = async (ctx, {
57
57
  userId,
58
58
  force = false
59
59
  }) => {
60
- const SettingsModel = await loadModel("RBNotificationSettings", ctx);
61
- const NotificationModel = await loadModel("RBNotification", ctx);
60
+ const SettingsModel = await models.get("RBNotificationSettings", ctx);
61
+ const NotificationModel = await models.get("RBNotification", ctx);
62
62
  const settings = await SettingsModel.findOne({ userId }).lean();
63
63
  const digestFrequencyRaw = typeof settings?.digestFrequency === "string" ? settings.digestFrequency : "weekly";
64
64
  const digestFrequency = digestFrequencyRaw === "daily" || digestFrequencyRaw === "weekly" || digestFrequencyRaw === "off" ? digestFrequencyRaw : "weekly";
@@ -92,7 +92,7 @@ const sendNotificationsDigestForUser = async (ctx, {
92
92
  );
93
93
  return { ok: true, sent: false, skippedReason: "empty" };
94
94
  }
95
- const UserModel = await loadRbModel("RBUser", ctx);
95
+ const UserModel = await models.getGlobal("RBUser", ctx);
96
96
  const user = await UserModel.findById(userId, { email: 1 }).lean();
97
97
  const email = typeof user?.email === "string" ? user.email.trim() : "";
98
98
  if (!email) {
package/dist/rts/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { loadRbModel, loadModel } from "@rpcbase/db";
2
+ import { models } from "@rpcbase/db";
3
3
  import { buildAbilityFromSession, getTenantRolesFromSessionUser, buildAbility, getAccessibleByQuery } from "@rpcbase/db/acl";
4
4
  import { WebSocketServer } from "ws";
5
5
  const routes = Object.entries({
6
- .../* @__PURE__ */ Object.assign({ "./api/changes/handler.ts": () => import("../handler-Dd20DHyz.js") })
6
+ .../* @__PURE__ */ Object.assign({ "./api/changes/handler.ts": () => import("../handler-lOVgWqyF.js") })
7
7
  }).reduce((acc, [path, mod]) => {
8
8
  acc[path.replace("./api/", "@rpcbase/server/rts/api/")] = mod;
9
9
  return acc;
@@ -166,7 +166,7 @@ const parseUpgradeMeta = async ({
166
166
  throw new Error("Missing rb-user-id header (reverse-proxy) and no session middleware configured");
167
167
  }
168
168
  const rbCtx = { req: { session: null } };
169
- const User = await loadRbModel("RBUser", rbCtx);
169
+ const User = await models.getGlobal("RBUser", rbCtx);
170
170
  const user = await User.findById(headerUserId, { tenants: 1, tenantRoles: 1 }).lean();
171
171
  const tenantsRaw = user?.tenants;
172
172
  const tenants = Array.isArray(tenantsRaw) ? tenantsRaw.map((t) => String(t)) : [];
@@ -187,7 +187,7 @@ const getTenantModel = async (tenantId, modelName) => {
187
187
  }
188
188
  }
189
189
  };
190
- return loadModel(modelName, ctx);
190
+ return models.get(modelName, ctx);
191
191
  };
192
192
  const normalizeLimit = (limit) => {
193
193
  if (typeof limit !== "number") return QUERY_MAX_LIMIT;
package/dist/uploads.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const routes = Object.entries({
2
- .../* @__PURE__ */ Object.assign({ "./api/file-uploads/handler.ts": () => import("./handler-BA2YiqnG.js"), "./api/files/handler.ts": () => import("./handler-Cohj3cz3.js") })
2
+ .../* @__PURE__ */ Object.assign({ "./api/file-uploads/handler.ts": () => import("./handler-B45bHxic.js"), "./api/files/handler.ts": () => import("./handler-Cohj3cz3.js") })
3
3
  }).reduce((acc, [path, mod]) => {
4
4
  acc[path.replace("./api/", "@rpcbase/server/uploads/api/")] = mod;
5
5
  return acc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.481.0",
3
+ "version": "0.482.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"