@terreno/api 56.0.0-beta.0 → 57.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +2 -122
  2. package/LICENSE +21 -202
  3. package/dist/api.d.ts +3 -2
  4. package/dist/auth.js +21 -25
  5. package/dist/betterAuthSetup.d.ts +15 -1
  6. package/dist/betterAuthSetup.js +4 -6
  7. package/dist/configurationPlugin.js +2 -2
  8. package/dist/expressServer.js +11 -5
  9. package/dist/githubAuth.js +1 -4
  10. package/dist/plugins.d.ts +7 -6
  11. package/dist/plugins.js +24 -8
  12. package/dist/realtime/changeStreamWatcher.d.ts +1 -1
  13. package/dist/realtime/changeStreamWatcher.js +0 -2
  14. package/dist/realtime/realtimeApp.d.ts +1 -1
  15. package/dist/realtime/realtimeApp.js +16 -8
  16. package/dist/realtime/types.d.ts +14 -0
  17. package/dist/sync/executors.js +14 -14
  18. package/dist/sync/models.js +1 -1
  19. package/dist/sync/registry.d.ts +4 -4
  20. package/dist/sync/registry.js +1 -1
  21. package/dist/sync/socketHandlers.d.ts +1 -1
  22. package/dist/sync/syncSeqPlugin.js +25 -29
  23. package/dist/tests/models.d.ts +27 -11
  24. package/dist/tests/models.js +5 -3
  25. package/dist/tests/testHelper.d.ts +9 -3
  26. package/package.json +5 -6
  27. package/src/actions.test.ts +19 -12
  28. package/src/actions.ts +2 -2
  29. package/src/api.coverage.test.ts +7 -9
  30. package/src/api.errorPaths.test.ts +47 -1
  31. package/src/api.errors.test.ts +32 -23
  32. package/src/api.ts +22 -12
  33. package/src/auth.test.ts +251 -1
  34. package/src/auth.ts +25 -23
  35. package/src/betterAuthSetup.ts +7 -7
  36. package/src/configuration.test.ts +59 -38
  37. package/src/configurationPlugin.test.ts +72 -42
  38. package/src/configurationPlugin.ts +2 -2
  39. package/src/consentApp.test.ts +12 -12
  40. package/src/expressServer.ts +11 -5
  41. package/src/githubAuth.ts +1 -3
  42. package/src/middleware.test.ts +16 -0
  43. package/src/models/versionConfig.ts +1 -1
  44. package/src/openApiBuilder.test.ts +24 -9
  45. package/src/openApiValidator.test.ts +41 -0
  46. package/src/permissions.middleware.test.ts +73 -81
  47. package/src/permissions.test.ts +35 -25
  48. package/src/plugins.test.ts +74 -29
  49. package/src/plugins.ts +29 -11
  50. package/src/populate.test.ts +25 -16
  51. package/src/realtime/changeStreamWatcher.ts +1 -4
  52. package/src/realtime/realtime.test.ts +239 -0
  53. package/src/realtime/realtimeApp.ts +15 -8
  54. package/src/realtime/realtimeAppSetup.test.ts +159 -0
  55. package/src/realtime/types.ts +14 -0
  56. package/src/secretProvidersGcpClient.test.ts +66 -0
  57. package/src/sync/executors.ts +16 -14
  58. package/src/sync/models.ts +2 -1
  59. package/src/sync/registry.ts +6 -8
  60. package/src/sync/socketHandlers.ts +1 -3
  61. package/src/sync/syncFrontier.test.ts +2 -2
  62. package/src/sync/syncSeqPlugin.test.ts +446 -0
  63. package/src/sync/syncSeqPlugin.ts +43 -51
  64. package/src/tests/models.ts +8 -6
package/dist/plugins.js CHANGED
@@ -355,10 +355,10 @@ var upsertPlugin = function (schema) {
355
355
  };
356
356
  exports.upsertPlugin = upsertPlugin;
357
357
  /**
358
- * Adds an `archived` boolean field and excludes archived documents from `find()` queries by
359
- * default. Pass `{archived: true}` explicitly to include them. This is a soft-archive analog to
360
- * {@link isDeletedPlugin}: use it when documents should be hidden from normal listings but kept
361
- * (and still directly queryable) rather than treated as deleted.
358
+ * Adds an `archived` boolean field and excludes archived documents from `find()` / `findOne()`
359
+ * queries by default. Pass `{archived: true}` explicitly to include them. This is a soft-archive
360
+ * analog to {@link isDeletedPlugin}: use it when documents should be hidden from normal listings
361
+ * but kept (and still directly queryable) rather than treated as deleted.
362
362
  * @param schema Mongoose Schema
363
363
  * @param defaultValue Default value for the `archived` field (defaults to `false`)
364
364
  */
@@ -376,15 +376,27 @@ schema, defaultValue) {
376
376
  type: Boolean,
377
377
  },
378
378
  });
379
+ // Mirror isDeletedPlugin: filter both find and findOne so findExactlyOne / findOneOrNone
380
+ // also exclude archived documents unless the query sets `archived` explicitly.
379
381
  // noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
380
382
  // biome-ignore lint/suspicious/noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
381
- schema.pre("find", function () {
382
- var conditions = this.getFilter();
383
+ var applyArchiveFilter = function (query) {
384
+ var conditions = query.getFilter();
383
385
  // Only apply the default filter when the query does not mention `archived` at all, so an
384
386
  // explicit `{archived: true}` (or `false`) is always respected.
385
387
  if (conditions.archived === undefined) {
386
- this.setQuery(__assign(__assign({}, conditions), { archived: { $ne: true } }));
388
+ query.setQuery(__assign(__assign({}, conditions), { archived: { $ne: true } }));
387
389
  }
390
+ };
391
+ // noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
392
+ // biome-ignore lint/suspicious/noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
393
+ schema.pre("find", function () {
394
+ applyArchiveFilter(this);
395
+ });
396
+ // noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
397
+ // biome-ignore lint/suspicious/noExplicitAny: Query<any, any> must be loose to accept arbitrary consumer queries
398
+ schema.pre("findOne", function () {
399
+ applyArchiveFilter(this);
388
400
  });
389
401
  };
390
402
  exports.excludeArchivedPlugin = excludeArchivedPlugin;
@@ -408,7 +420,11 @@ var DateOnly = /** @class */ (function (_super) {
408
420
  }
409
421
  var handler = this.$conditionalHandlers[$conditional];
410
422
  if (!handler) {
411
- throw new Error("Can't use ".concat($conditional, " with DateOnly."));
423
+ throw new errors_1.APIError({
424
+ detail: "Can't use ".concat($conditional, " with DateOnly."),
425
+ status: 400,
426
+ title: "Unsupported query conditional for DateOnly",
427
+ });
412
428
  }
413
429
  return handler.call(this, val);
414
430
  };
@@ -51,7 +51,7 @@ export interface AuthorizedEmitEntry {
51
51
  modelName: string;
52
52
  options: {
53
53
  permissions: {
54
- read: PermissionMethod<any>[];
54
+ read: PermissionMethod<unknown>[];
55
55
  };
56
56
  };
57
57
  }
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- // noExplicitAny: change stream and socket handlers use dynamic document shapes
3
- // biome-ignore-all lint/suspicious/noExplicitAny: change stream and socket handlers use dynamic document shapes
4
2
  var __assign = (this && this.__assign) || function () {
5
3
  __assign = Object.assign || function(t) {
6
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -28,7 +28,7 @@ export interface RealtimeSocketLike extends SocketWithDecodedToken {
28
28
  join: (room: string) => Promise<void> | void;
29
29
  leave: (room: string) => Promise<void> | void;
30
30
  emit: (event: string, payload: unknown) => void;
31
- on: (event: string, handler: (...args: any[]) => any) => void;
31
+ on: (event: string, handler: (...args: never[]) => void | Promise<void>) => void;
32
32
  }
33
33
  /**
34
34
  * Install the realtime subscription handlers on a single socket. Extracted from the
@@ -83,6 +83,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
83
83
  exports.RealtimeApp = exports.installRealtimeSocketHandlers = exports.redactCredentials = exports.MAX_QUERY_SUBSCRIPTIONS = exports.MAX_DOCUMENT_SUBSCRIPTIONS = exports.MAX_MODEL_SUBSCRIPTIONS = void 0;
84
84
  var Sentry = __importStar(require("@sentry/bun"));
85
85
  var socket_io_1 = require("socket.io");
86
+ var errors_1 = require("../errors");
86
87
  var logger_1 = require("../logger");
87
88
  var permissions_1 = require("../permissions");
88
89
  var registry_1 = require("../sync/registry");
@@ -454,7 +455,7 @@ var RealtimeApp = /** @class */ (function () {
454
455
  */
455
456
  RealtimeApp.prototype.onServerCreated = function (server) {
456
457
  var _this = this;
457
- var _a, _b, _c;
458
+ var _a, _b, _c, _d, _e;
458
459
  var debug = (_a = this.config.debug) !== null && _a !== void 0 ? _a : false;
459
460
  var logInfo = function (message) {
460
461
  if (debug) {
@@ -463,17 +464,23 @@ var RealtimeApp = /** @class */ (function () {
463
464
  };
464
465
  try {
465
466
  logInfo("[realtime] Setting up Socket.io server...");
466
- this.io = new socket_io_1.Server(server, {
467
- cors: (_b = this.config.cors) !== null && _b !== void 0 ? _b : {
467
+ // Prefer an injected Server constructor in tests so callers never need
468
+ // process-wide `mock.module("socket.io")` (which poisons later files).
469
+ var SocketServerCtor = (_b = this.config.SocketServer) !== null && _b !== void 0 ? _b : socket_io_1.Server;
470
+ this.io = new SocketServerCtor(server, {
471
+ cors: (_c = this.config.cors) !== null && _c !== void 0 ? _c : {
468
472
  methods: ["GET", "POST"],
469
473
  origin: "*",
470
474
  },
471
475
  });
472
476
  // Authentication middleware: legacy JWT first, optionally Better Auth sessions.
473
- var tokenSecret = (_c = this.config.tokenSecret) !== null && _c !== void 0 ? _c : process.env.TOKEN_SECRET;
477
+ var tokenSecret = (_d = this.config.tokenSecret) !== null && _d !== void 0 ? _d : process.env.TOKEN_SECRET;
474
478
  if (!tokenSecret) {
475
- throw new Error("[realtime] TOKEN_SECRET is required for socket authentication. " +
476
- "Set process.env.TOKEN_SECRET or pass tokenSecret in RealtimeAppOptions.");
479
+ throw new errors_1.APIError({
480
+ status: 500,
481
+ title: "[realtime] TOKEN_SECRET is required for socket authentication. " +
482
+ "Set process.env.TOKEN_SECRET or pass tokenSecret in RealtimeAppOptions.",
483
+ });
477
484
  }
478
485
  // D1: pass the issuer through for parity with the HTTP JWT path
479
486
  // (jwt.verify(token, secret, {issuer})) — without it a validly-signed token
@@ -521,8 +528,9 @@ var RealtimeApp = /** @class */ (function () {
521
528
  logger_1.logger.error("[realtime] Connection error: ".concat(error.message));
522
529
  Sentry.captureException(error);
523
530
  });
524
- // Start the change stream watcher
525
- (0, changeStreamWatcher_1.startChangeStreamWatcher)(this.io, this.config.changeStream, debug);
531
+ // Start the change stream watcher (injectable for unit tests — see SocketServer).
532
+ var startWatcher = (_e = this.config.startChangeStreamWatcher) !== null && _e !== void 0 ? _e : changeStreamWatcher_1.startChangeStreamWatcher;
533
+ startWatcher(this.io, this.config.changeStream, debug);
526
534
  // D1: periodic session re-validation sweep — disconnects sockets whose JWT has
527
535
  // expired, whose Better Auth session is no longer valid, or whose user has
528
536
  // since been disabled; also refreshes socket.data.fullUser (D2) and
@@ -1,6 +1,8 @@
1
1
  import type express from "express";
2
+ import type { Server as SocketIoServer } from "socket.io";
2
3
  import type { UserModel } from "../auth";
3
4
  import type { SyncAppOptions } from "../sync/routes";
5
+ import type { startChangeStreamWatcher } from "./changeStreamWatcher";
4
6
  import type { BetterAuthSocketOptions } from "./socketAuth";
5
7
  /**
6
8
  * Configuration for real-time sync on a modelRouter.
@@ -117,6 +119,18 @@ export interface RealtimeAppOptions {
117
119
  sessionRevalidationIntervalMs?: number;
118
120
  /** Enable debug logging */
119
121
  debug?: boolean;
122
+ /**
123
+ * Test seam: Socket.IO server constructor. Defaults to `socket.io`'s `Server`.
124
+ * Prefer this over `mock.module("socket.io")` — bun's module mocks are process-wide
125
+ * and break later files that need a real Socket.IO server (sync integration, etc.).
126
+ */
127
+ SocketServer?: typeof SocketIoServer;
128
+ /**
129
+ * Test seam: change-stream watcher starter. Defaults to the real
130
+ * `startChangeStreamWatcher`. Same rationale as {@link SocketServer} — avoid
131
+ * process-wide `mock.module` of `./changeStreamWatcher`.
132
+ */
133
+ startChangeStreamWatcher?: typeof startChangeStreamWatcher;
120
134
  }
121
135
  /**
122
136
  * Payload sent by the client to subscribe to a single document's changes.
@@ -197,25 +197,25 @@ var executeCreate = function (_a) { return __awaiter(void 0, [_a], void 0, funct
197
197
  });
198
198
  case 5:
199
199
  if (cleanedBody === undefined) {
200
- throw new errors_1.APIError({
200
+ throw new errors_1.ForbiddenError({
201
+ code: "create-not-allowed",
201
202
  detail: "A body must be returned from preCreate",
202
- status: 403,
203
203
  title: "Create not allowed",
204
204
  });
205
205
  }
206
206
  if (cleanedBody === null) {
207
- throw new errors_1.APIError({
207
+ throw new errors_1.ForbiddenError({
208
+ code: "create-not-allowed",
208
209
  detail: "preCreate hook returned null",
209
- status: 403,
210
210
  title: "Create not allowed",
211
211
  });
212
212
  }
213
213
  _c.label = 6;
214
214
  case 6:
215
215
  if (cleanedBody === undefined) {
216
- throw new errors_1.APIError({
216
+ throw new errors_1.BadRequestError({
217
+ code: "invalid-request-body",
217
218
  detail: "Body is undefined",
218
- status: 400,
219
219
  title: "Invalid request body",
220
220
  });
221
221
  }
@@ -371,16 +371,16 @@ var executeUpdate = function (_a) { return __awaiter(void 0, [_a], void 0, funct
371
371
  });
372
372
  case 9:
373
373
  if (cleanedBody === undefined) {
374
- throw new errors_1.APIError({
374
+ throw new errors_1.ForbiddenError({
375
+ code: "update-not-allowed",
375
376
  detail: "A body must be returned from preUpdate",
376
- status: 403,
377
377
  title: "Update not allowed",
378
378
  });
379
379
  }
380
380
  if (cleanedBody === null) {
381
- throw new errors_1.APIError({
381
+ throw new errors_1.ForbiddenError({
382
+ code: "update-not-allowed",
382
383
  detail: "preUpdate hook on ".concat(id, " returned null"),
383
- status: 403,
384
384
  title: "Update not allowed",
385
385
  });
386
386
  }
@@ -596,16 +596,16 @@ var executeDelete = function (_a) { return __awaiter(void 0, [_a], void 0, funct
596
596
  });
597
597
  case 13:
598
598
  if (body === undefined) {
599
- throw new errors_1.APIError({
599
+ throw new errors_1.ForbiddenError({
600
+ code: "delete-not-allowed",
600
601
  detail: "A body must be returned from preDelete",
601
- status: 403,
602
602
  title: "Delete not allowed",
603
603
  });
604
604
  }
605
605
  if (body === null) {
606
- throw new errors_1.APIError({
606
+ throw new errors_1.ForbiddenError({
607
+ code: "delete-not-allowed",
607
608
  detail: "preDelete hook for ".concat(id, " returned null"),
608
- status: 403,
609
609
  title: "Delete not allowed",
610
610
  });
611
611
  }
@@ -196,7 +196,7 @@ var claimSyncSeqs = function (_a) { return __awaiter(void 0, [_a], void 0, funct
196
196
  },
197
197
  },
198
198
  { $unset: "_syncOldSeq" },
199
- ], { new: true, upsert: true })];
199
+ ], { returnDocument: "after", updatePipeline: true, upsert: true })];
200
200
  case 1:
201
201
  doc = _a.sent();
202
202
  return [2 /*return*/, { lastSeq: doc.seq, registered: true, seqs: materialize(doc.seq) }];
@@ -16,7 +16,7 @@ export interface SyncRegistryEntry {
16
16
  /** Sync configuration from modelRouter options */
17
17
  config: SyncConfig;
18
18
  /** Full modelRouter options (for responseHandler, permissions, etc.) */
19
- options: ModelRouterOptions<any>;
19
+ options: ModelRouterOptions<unknown>;
20
20
  }
21
21
  /**
22
22
  * Enqueue an index-creation promise for `ensureSyncIndexes()` to await at startup. Used by
@@ -33,11 +33,11 @@ export declare const trackSyncIndexCreation: (promise: Promise<void>) => void;
33
33
  * - `syncPlugin` is required so every write stamps a per-stream `_syncSeq`;
34
34
  * - owner/tenant scope fields must exist on the schema.
35
35
  */
36
- export declare const registerSync: ({ model, routePath, config, options, }: {
37
- model: Model<any>;
36
+ export declare const registerSync: <T>({ model, routePath, config, options, }: {
37
+ model: Model<T>;
38
38
  routePath: string;
39
39
  config: SyncConfig;
40
- options: ModelRouterOptions<any>;
40
+ options: ModelRouterOptions<T>;
41
41
  }) => void;
42
42
  /**
43
43
  * C8: await every enqueued sync index creation — per-model snapshot indexes from
@@ -75,7 +75,7 @@ var registerSync = function (_a) {
75
75
  var model = _a.model, routePath = _a.routePath, config = _a.config, options = _a.options;
76
76
  var name = model.modelName;
77
77
  var deletedPath = model.schema.path("deleted");
78
- if (!deletedPath || deletedPath.instance !== "Boolean") {
78
+ if ((deletedPath === null || deletedPath === void 0 ? void 0 : deletedPath.instance) !== "Boolean") {
79
79
  throw new Error("Model ".concat(name, " has a sync config but no soft delete support. ") +
80
80
  "Apply isDeletedPlugin to the schema — sync catch-up requires delete tombstones.");
81
81
  }
@@ -40,7 +40,7 @@ export interface SyncSocketLike extends SocketWithDecodedToken {
40
40
  join: (room: string) => Promise<void> | void;
41
41
  leave: (room: string) => Promise<void> | void;
42
42
  emit: (event: string, payload: unknown) => void;
43
- on: (event: string, handler: (...args: any[]) => any) => void;
43
+ on: (event: string, handler: (...args: never[]) => void | Promise<void>) => void;
44
44
  }
45
45
  /**
46
46
  * Install the sync socket handlers on a single socket. Wired into RealtimeApp's
@@ -76,7 +76,6 @@ var __read = (this && this.__read) || function (o, n) {
76
76
  Object.defineProperty(exports, "__esModule", { value: true });
77
77
  exports.syncPlugin = exports.SCOPE_MOVE_MARKER_ATTEMPTS = void 0;
78
78
  var logger_1 = require("../logger");
79
- var executors_1 = require("./executors");
80
79
  var models_1 = require("./models");
81
80
  var registry_1 = require("./registry");
82
81
  var streams_1 = require("./streams");
@@ -496,12 +495,16 @@ var syncPlugin = function (schema) {
496
495
  });
497
496
  });
498
497
  });
499
- // Task 9.13: an optimistic-concurrency loss (`VersionError`) matched no document, so the
500
- // seq claimed in pre('save') will never be stamped on anything. Cancel it instead of
501
- // letting it hold the stable frontier down for the full pending-claim lease — a lost
502
- // update race is now an EXPECTED outcome, not a crash, and must not stall catch-up for
503
- // every other client on the stream.
504
- schema.post("save", function (error, doc, next) {
498
+ // Any save that claimed a seq in pre('save') but then failed (VersionError, E11000,
499
+ // simulated/hook failure, etc.) never stamped that seq. Release it so the stable
500
+ // frontier is not held for the full pending-claim lease.
501
+ //
502
+ // Mongoose 9 / Kareem 3: async error middleware must `throw error` (or return a
503
+ // rejected promise). Calling `next(error)` after an async hook returns a Promise
504
+ // leaves an orphaned rejection that Bun reports as an unhandled error between tests,
505
+ // even when the caller correctly awaited `save().catch(...)`.
506
+ // Keep arity ≥ 3 so Kareem still classifies this as error middleware.
507
+ schema.post("save", function (error, doc, _next) {
505
508
  return __awaiter(this, void 0, void 0, function () {
506
509
  var locals, pending;
507
510
  var _a;
@@ -513,9 +516,9 @@ var syncPlugin = function (schema) {
513
516
  if (locals) {
514
517
  locals[PENDING_COMMIT_KEY] = undefined;
515
518
  }
516
- if (!((pending === null || pending === void 0 ? void 0 : pending.claim.registered) && (0, executors_1.isVersionError)(error))) return [3 /*break*/, 2];
519
+ if (!(pending === null || pending === void 0 ? void 0 : pending.claim.registered)) return [3 /*break*/, 2];
517
520
  return [4 /*yield*/, (0, models_1.releaseSyncSeqs)({ seqs: pending.claim.seqs, stream: pending.currentStream }).catch(function (releaseError) {
518
- logger_1.logger.error("[sync] Failed to release the seq claim of a version-conflicted save", {
521
+ logger_1.logger.error("[sync] Failed to release seq claim after failed save", {
519
522
  error: String(releaseError),
520
523
  stream: pending.currentStream,
521
524
  });
@@ -523,32 +526,33 @@ var syncPlugin = function (schema) {
523
526
  case 1:
524
527
  _b.sent();
525
528
  _b.label = 2;
526
- case 2:
527
- next(error);
528
- return [2 /*return*/];
529
+ case 2: throw error;
529
530
  }
530
531
  });
531
532
  });
532
533
  });
533
- schema.pre("insertMany", function (next, docs, options) {
534
+ // Mongoose 9 insertMany pre hooks are async (no `next` callback) and receive docs + options.
535
+ schema.pre("insertMany", function (docs, options) {
534
536
  return __awaiter(this, void 0, void 0, function () {
535
- var model, entry, session, byStream, docs_1, docs_1_1, doc, stream, group, _loop_1, byStream_1, byStream_1_1, _a, stream, group, e_1_1, error_4;
537
+ var docsArray, model, entry, session, byStream, docsArray_1, docsArray_1_1, doc, stream, group, _loop_1, byStream_1, byStream_1_1, _a, stream, group, e_1_1;
536
538
  var e_2, _b, e_1, _c;
537
539
  var _d, _e;
538
540
  return __generator(this, function (_f) {
539
541
  switch (_f.label) {
540
542
  case 0:
541
- _f.trys.push([0, 9, , 10]);
543
+ docsArray = Array.isArray(docs)
544
+ ? docs
545
+ : [docs];
542
546
  model = this;
543
547
  entry = (0, registry_1.findSyncEntryByModelName)(model.modelName);
544
- if (!entry || !Array.isArray(docs) || docs.length === 0) {
545
- return [2 /*return*/, next()];
548
+ if (!entry || docsArray.length === 0) {
549
+ return [2 /*return*/];
546
550
  }
547
551
  session = (_d = options === null || options === void 0 ? void 0 : options.session) !== null && _d !== void 0 ? _d : null;
548
552
  byStream = new Map();
549
553
  try {
550
- for (docs_1 = __values(docs), docs_1_1 = docs_1.next(); !docs_1_1.done; docs_1_1 = docs_1.next()) {
551
- doc = docs_1_1.value;
554
+ for (docsArray_1 = __values(docsArray), docsArray_1_1 = docsArray_1.next(); !docsArray_1_1.done; docsArray_1_1 = docsArray_1.next()) {
555
+ doc = docsArray_1_1.value;
552
556
  stream = writableStreamForObject(entry, doc);
553
557
  group = (_e = byStream.get(stream)) !== null && _e !== void 0 ? _e : [];
554
558
  group.push(doc);
@@ -558,7 +562,7 @@ var syncPlugin = function (schema) {
558
562
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
559
563
  finally {
560
564
  try {
561
- if (docs_1_1 && !docs_1_1.done && (_b = docs_1.return)) _b.call(docs_1);
565
+ if (docsArray_1_1 && !docsArray_1_1.done && (_b = docsArray_1.return)) _b.call(docsArray_1);
562
566
  }
563
567
  finally { if (e_2) throw e_2.error; }
564
568
  }
@@ -603,15 +607,7 @@ var syncPlugin = function (schema) {
603
607
  }
604
608
  finally { if (e_1) throw e_1.error; }
605
609
  return [7 /*endfinally*/];
606
- case 8:
607
- // C1: the confirm belongs in post('insertMany') — confirming here would let the
608
- // stable frontier (and therefore a snapshot cursor) advance past seqs whose
609
- // documents have not committed yet, stranding them below every catch-up cursor.
610
- return [2 /*return*/, next()];
611
- case 9:
612
- error_4 = _f.sent();
613
- return [2 /*return*/, next(error_4)];
614
- case 10: return [2 /*return*/];
610
+ case 8: return [2 /*return*/];
615
611
  }
616
612
  });
617
613
  });
@@ -1,4 +1,4 @@
1
- import mongoose, { type Model, Schema } from "mongoose";
1
+ import mongoose, { type Model } from "mongoose";
2
2
  export interface User {
3
3
  admin: boolean;
4
4
  name?: string;
@@ -33,14 +33,14 @@ export interface Food {
33
33
  dateAdded?: string;
34
34
  };
35
35
  tags: string[];
36
- eatenBy: [Schema.Types.ObjectId | User];
36
+ eatenBy: Array<mongoose.Types.ObjectId | User>;
37
37
  lastEatenWith: {
38
38
  [name: string]: Date;
39
39
  };
40
40
  categories: FoodCategory[];
41
41
  expiration: string;
42
42
  likesIds: {
43
- userId: string;
43
+ userId: mongoose.Types.ObjectId | string;
44
44
  likes: boolean;
45
45
  }[];
46
46
  }
@@ -48,24 +48,40 @@ export interface RequiredField {
48
48
  name: string;
49
49
  about?: string;
50
50
  }
51
- export declare const UserModel: mongoose.Model<User, {}, {}, {}, mongoose.Document<unknown, {}, User, {}, {}> & User & {
51
+ export declare const UserModel: mongoose.Model<User, {}, {}, {}, mongoose.Document<unknown, {}, User, {}, mongoose.DefaultSchemaOptions> & User & {
52
52
  _id: mongoose.Types.ObjectId;
53
53
  } & {
54
54
  __v: number;
55
- }, any>;
56
- export declare const SuperUserModel: mongoose.Model<User & SuperUser, {}, {}, {}, mongoose.Document<unknown, {}, User & SuperUser, {}, {}> & User & SuperUser & {
55
+ } & {
56
+ id: string;
57
+ }, any, User>;
58
+ export declare const SuperUserModel: mongoose.Model<User & SuperUser, {}, {}, {
59
+ id: string;
60
+ }, mongoose.Document<unknown, {}, User & SuperUser, {
61
+ id: string;
62
+ }, mongoose.DefaultSchemaOptions> & Omit<User & SuperUser & {
57
63
  _id: mongoose.Types.ObjectId;
58
64
  } & {
59
65
  __v: number;
60
- }, any>;
61
- export declare const StaffUserModel: mongoose.Model<User & StaffUser, {}, {}, {}, mongoose.Document<unknown, {}, User & StaffUser, {}, {}> & User & StaffUser & {
66
+ }, "id"> & mongoose.HydratedDocumentOverrides<{
67
+ id: string;
68
+ }>, any, User & SuperUser>;
69
+ export declare const StaffUserModel: mongoose.Model<User & StaffUser, {}, {}, {
70
+ id: string;
71
+ }, mongoose.Document<unknown, {}, User & StaffUser, {
72
+ id: string;
73
+ }, mongoose.DefaultSchemaOptions> & Omit<User & StaffUser & {
62
74
  _id: mongoose.Types.ObjectId;
63
75
  } & {
64
76
  __v: number;
65
- }, any>;
77
+ }, "id"> & mongoose.HydratedDocumentOverrides<{
78
+ id: string;
79
+ }>, any, User & StaffUser>;
66
80
  export declare const FoodModel: Model<Food>;
67
- export declare const RequiredModel: mongoose.Model<RequiredField, {}, {}, {}, mongoose.Document<unknown, {}, RequiredField, {}, {}> & RequiredField & {
81
+ export declare const RequiredModel: mongoose.Model<RequiredField, {}, {}, {}, mongoose.Document<unknown, {}, RequiredField, {}, mongoose.DefaultSchemaOptions> & RequiredField & {
68
82
  _id: mongoose.Types.ObjectId;
69
83
  } & {
70
84
  __v: number;
71
- }, any>;
85
+ } & {
86
+ id: string;
87
+ }, any, RequiredField>;
@@ -101,9 +101,11 @@ var foodSchema = new mongoose_1.Schema({
101
101
  type: mongoose_1.Schema.Types.ObjectId,
102
102
  },
103
103
  ],
104
- // noExplicitAny: DateOnly is a custom SchemaType not recognized by Mongoose's built-in type definitions
105
- // biome-ignore lint/suspicious/noExplicitAny: DateOnly is a custom SchemaType not recognized by Mongoose's built-in type definitions
106
- expiration: { description: "Expiration date of the food", type: plugins_1.DateOnly },
104
+ expiration: {
105
+ description: "Expiration date of the food",
106
+ // DateOnly is a custom SchemaType registered on Schema.Types; it stores an ISO date string.
107
+ type: plugins_1.DateOnly,
108
+ },
107
109
  hidden: {
108
110
  default: false,
109
111
  description: "Whether this food is hidden from listings",
@@ -1,18 +1,24 @@
1
1
  import type { TestData } from "./types";
2
2
  export declare const applyTestAuthEnv: () => void;
3
3
  /** Seeds only the standard users (legacy helper). */
4
- export declare const setupDb: () => Promise<readonly [import("mongoose").Document<unknown, {}, import("./models").User, {}, {}> & import("./models").User & {
4
+ export declare const setupDb: () => Promise<readonly [import("mongoose").Document<unknown, {}, import("./models").User, {}, import("mongoose").DefaultSchemaOptions> & import("./models").User & {
5
5
  _id: import("mongoose").Types.ObjectId;
6
6
  } & {
7
7
  __v: number;
8
- }, import("mongoose").Document<unknown, {}, import("./models").User, {}, {}> & import("./models").User & {
8
+ } & {
9
+ id: string;
10
+ }, import("mongoose").Document<unknown, {}, import("./models").User, {}, import("mongoose").DefaultSchemaOptions> & import("./models").User & {
9
11
  _id: import("mongoose").Types.ObjectId;
10
12
  } & {
11
13
  __v: number;
12
- }, import("mongoose").Document<unknown, {}, import("./models").User, {}, {}> & import("./models").User & {
14
+ } & {
15
+ id: string;
16
+ }, import("mongoose").Document<unknown, {}, import("./models").User, {}, import("mongoose").DefaultSchemaOptions> & import("./models").User & {
13
17
  _id: import("mongoose").Types.ObjectId;
14
18
  } & {
15
19
  __v: number;
20
+ } & {
21
+ id: string;
16
22
  }]>;
17
23
  /** Seeds users, foods, and required docs — the recommended API test baseline. */
18
24
  export declare const setupTestData: () => Promise<TestData>;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "@asteasolutions/zod-to-openapi": "^8.5.0",
8
8
  "@sentry/bun": "^10.39.0",
9
9
  "@sentry/profiling-node": "^10.25.0",
10
- "@terreno/test": "56.0.0-beta.0",
10
+ "@terreno/test": "57.0.0-beta.1",
11
11
  "@types/qs": "^6.14.0",
12
12
  "ajv": "8.20.0",
13
13
  "ajv-formats": "^3.0.1",
@@ -47,7 +47,7 @@
47
47
  "description": "Styled after the Django & Django REST Framework, a batteries-include framework for building REST APIs with Node/Express/Mongoose.",
48
48
  "devDependencies": {
49
49
  "@biomejs/biome": "^2.3.6",
50
- "@terreno/syncdb": "56.0.0-beta.0",
50
+ "@terreno/syncdb": "57.0.0-beta.1",
51
51
  "@types/bcrypt": "^6.0.0",
52
52
  "@types/bun": "^1.3.8",
53
53
  "@types/cors": "^2.8.17",
@@ -55,7 +55,6 @@
55
55
  "@types/express": "^5.0.6",
56
56
  "@types/jsonwebtoken": "^9.0.9",
57
57
  "@types/lodash": "^4.17.17",
58
- "@types/mongodb": "^4.0.7",
59
58
  "@types/node": "^25.3.0",
60
59
  "@types/on-finished": "^2.3.4",
61
60
  "@types/passport": "^1.0.17",
@@ -66,7 +65,7 @@
66
65
  "@types/sinon": "^21.0.0",
67
66
  "@types/supertest": "^7.2.0",
68
67
  "mongodb-memory-server": "^11.0.1",
69
- "mongoose": "8.23.0",
68
+ "mongoose": "9.7.4",
70
69
  "sinon": "^22.0.0",
71
70
  "supertest": "^7.2.2",
72
71
  "typescript": "~6.0.3",
@@ -79,7 +78,7 @@
79
78
  "mongoose",
80
79
  "express"
81
80
  ],
82
- "license": "Apache-2.0",
81
+ "license": "MIT",
83
82
  "main": "dist/index.js",
84
83
  "exports": {
85
84
  ".": {
@@ -124,5 +123,5 @@
124
123
  "updateSnapshot": "bun test --update-snapshots"
125
124
  },
126
125
  "types": "dist/index.d.ts",
127
- "version": "56.0.0-beta.0"
126
+ "version": "57.0.0-beta.1"
128
127
  }