@terreno/api 0.31.0 → 56.0.0-beta.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.
Files changed (250) hide show
  1. package/CHANGELOG.md +122 -2
  2. package/LICENSE +202 -21
  3. package/dist/api.d.ts +12 -3
  4. package/dist/api.js +110 -361
  5. package/dist/auth.d.ts +26 -0
  6. package/dist/auth.js +100 -1
  7. package/dist/betterAuth.d.ts +5 -0
  8. package/dist/betterAuthSetup.d.ts +1 -15
  9. package/dist/betterAuthSetup.js +29 -8
  10. package/dist/configurationPlugin.js +2 -2
  11. package/dist/docLoader.js +12 -9
  12. package/dist/errors.d.ts +13 -0
  13. package/dist/errors.js +29 -1
  14. package/dist/expressServer.js +5 -11
  15. package/dist/githubAuth.js +4 -1
  16. package/dist/index.d.ts +17 -1
  17. package/dist/index.js +29 -1
  18. package/dist/middleware.d.ts +7 -0
  19. package/dist/middleware.js +16 -1
  20. package/dist/openApiCompat.d.ts +10 -1
  21. package/dist/openApiCompat.js +115 -47
  22. package/dist/permissions.d.ts +27 -0
  23. package/dist/permissions.js +42 -1
  24. package/dist/plugins.d.ts +15 -3
  25. package/dist/plugins.js +36 -6
  26. package/dist/realtime/changeStreamWatcher.d.ts +100 -3
  27. package/dist/realtime/changeStreamWatcher.js +542 -137
  28. package/dist/realtime/realtimeApp.d.ts +3 -1
  29. package/dist/realtime/realtimeApp.js +75 -27
  30. package/dist/realtime/sessionRevalidation.d.ts +90 -0
  31. package/dist/realtime/sessionRevalidation.js +438 -0
  32. package/dist/realtime/socketAuth.d.ts +97 -0
  33. package/dist/realtime/socketAuth.js +272 -0
  34. package/dist/realtime/socketUser.d.ts +54 -0
  35. package/dist/realtime/socketUser.js +75 -5
  36. package/dist/realtime/types.d.ts +40 -0
  37. package/dist/secretProviders.d.ts +23 -0
  38. package/dist/secretProviders.js +9 -3
  39. package/dist/sync/executors.d.ts +198 -0
  40. package/dist/sync/executors.js +670 -0
  41. package/dist/sync/loadHarness.js +807 -0
  42. package/dist/sync/models.d.ts +216 -0
  43. package/dist/sync/models.js +644 -0
  44. package/dist/sync/mutationHandler.d.ts +97 -0
  45. package/dist/sync/mutationHandler.js +886 -0
  46. package/dist/sync/registry.d.ts +73 -0
  47. package/dist/sync/registry.js +223 -0
  48. package/dist/sync/routes.d.ts +62 -0
  49. package/dist/sync/routes.js +936 -0
  50. package/dist/sync/scripts/compactTombstones.d.ts +47 -0
  51. package/dist/sync/scripts/compactTombstones.js +270 -0
  52. package/dist/sync/serialize.d.ts +20 -0
  53. package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
  54. package/dist/sync/socketHandlers.d.ts +54 -0
  55. package/dist/sync/socketHandlers.js +470 -0
  56. package/dist/sync/streams.d.ts +85 -0
  57. package/dist/sync/streams.js +221 -0
  58. package/dist/sync/syncApp.d.ts +29 -0
  59. package/dist/sync/syncApp.js +44 -0
  60. package/dist/sync/syncBatch.d.ts +71 -0
  61. package/dist/sync/syncBatch.js +252 -0
  62. package/dist/sync/syncSeqPlugin.d.ts +8 -0
  63. package/dist/sync/syncSeqPlugin.js +903 -0
  64. package/dist/sync/types.d.ts +254 -0
  65. package/dist/sync/types.js +9 -0
  66. package/dist/terrenoApp.js +90 -27
  67. package/dist/tests/models.d.ts +11 -27
  68. package/dist/tests/models.js +3 -5
  69. package/dist/tests/testHelper.d.ts +3 -9
  70. package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
  71. package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
  72. package/package.json +10 -8
  73. package/src/__tests__/openApiCompat.test.ts +20 -0
  74. package/src/actions.test.ts +12 -19
  75. package/src/actions.ts +2 -2
  76. package/src/api.coverage.test.ts +9 -7
  77. package/src/api.errorPaths.test.ts +1 -47
  78. package/src/api.test.ts +12 -0
  79. package/src/api.ts +98 -317
  80. package/src/auth.test.ts +128 -176
  81. package/src/auth.ts +109 -0
  82. package/src/betterAuth.ts +6 -0
  83. package/src/betterAuthSetup.test.ts +34 -0
  84. package/src/betterAuthSetup.ts +27 -8
  85. package/src/configurationPlugin.ts +2 -2
  86. package/src/consentApp.test.ts +12 -12
  87. package/src/docLoader.ts +3 -1
  88. package/src/errors.ts +33 -0
  89. package/src/expressServer.test.ts +7 -1
  90. package/src/expressServer.ts +5 -11
  91. package/src/githubAuth.ts +3 -1
  92. package/src/index.ts +42 -0
  93. package/src/middleware.test.ts +40 -1
  94. package/src/middleware.ts +15 -0
  95. package/src/models/versionConfig.ts +1 -1
  96. package/src/openApiBuilder.test.ts +9 -24
  97. package/src/openApiCompat.ts +99 -45
  98. package/src/openApiValidator.test.ts +0 -41
  99. package/src/permissions.test.ts +75 -1
  100. package/src/permissions.ts +49 -0
  101. package/src/plugins.test.ts +54 -14
  102. package/src/plugins.ts +47 -9
  103. package/src/populate.test.ts +16 -25
  104. package/src/realtime/changeStreamWatcher.ts +552 -114
  105. package/src/realtime/realtime.test.ts +157 -239
  106. package/src/realtime/realtimeApp.ts +80 -19
  107. package/src/realtime/sessionRevalidation.test.ts +423 -0
  108. package/src/realtime/sessionRevalidation.ts +273 -0
  109. package/src/realtime/socketAuth.test.ts +355 -0
  110. package/src/realtime/socketAuth.ts +228 -0
  111. package/src/realtime/socketUser.ts +69 -0
  112. package/src/realtime/types.ts +40 -0
  113. package/src/secretProviders.test.ts +7 -1
  114. package/src/secretProviders.ts +15 -3
  115. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  116. package/src/sync/executors.test.ts +882 -0
  117. package/src/sync/executors.ts +703 -0
  118. package/src/sync/integration.test.ts +1160 -0
  119. package/src/sync/loadHarness.ts +618 -0
  120. package/src/sync/models.ts +640 -0
  121. package/src/sync/mutationHandler.test.ts +1252 -0
  122. package/src/sync/mutationHandler.ts +850 -0
  123. package/src/sync/registry.ts +232 -0
  124. package/src/sync/routes.ts +812 -0
  125. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  126. package/src/sync/scripts/compactTombstones.ts +145 -0
  127. package/src/sync/serialize.ts +48 -0
  128. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  129. package/src/sync/socketHandlers.ts +320 -0
  130. package/src/sync/streams.ts +188 -0
  131. package/src/sync/sync.test.ts +582 -0
  132. package/src/sync/syncApp.ts +44 -0
  133. package/src/sync/syncBatch.ts +219 -0
  134. package/src/sync/syncFrontier.test.ts +494 -0
  135. package/src/sync/syncPhaseC.test.ts +718 -0
  136. package/src/sync/syncRoutes.test.ts +865 -0
  137. package/src/sync/syncSeqPlugin.ts +738 -0
  138. package/src/sync/syncSocket.test.ts +1440 -0
  139. package/src/sync/types.ts +270 -0
  140. package/src/terrenoApp.ts +37 -17
  141. package/src/tests/bunSetup.ts +8 -0
  142. package/src/tests/models.ts +6 -8
  143. package/tsconfig.json +4 -4
  144. package/tsconfig.typedoc.json +7 -1
  145. package/dist/__tests__/openApiCompat.test.js +0 -317
  146. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  147. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  148. package/dist/actions.openApi.test.d.ts +0 -1
  149. package/dist/actions.openApi.test.js +0 -253
  150. package/dist/actions.test.d.ts +0 -1
  151. package/dist/actions.test.js +0 -1087
  152. package/dist/api.arrayOperations.test.d.ts +0 -1
  153. package/dist/api.arrayOperations.test.js +0 -878
  154. package/dist/api.asyncHandler.test.d.ts +0 -1
  155. package/dist/api.asyncHandler.test.js +0 -236
  156. package/dist/api.coverage.test.d.ts +0 -1
  157. package/dist/api.coverage.test.js +0 -192
  158. package/dist/api.errorPaths.test.d.ts +0 -1
  159. package/dist/api.errorPaths.test.js +0 -887
  160. package/dist/api.errors.test.d.ts +0 -1
  161. package/dist/api.errors.test.js +0 -185
  162. package/dist/api.hooks.test.d.ts +0 -1
  163. package/dist/api.hooks.test.js +0 -950
  164. package/dist/api.query.test.d.ts +0 -1
  165. package/dist/api.query.test.js +0 -948
  166. package/dist/api.test.d.ts +0 -1
  167. package/dist/api.test.js +0 -2820
  168. package/dist/auth.compile.test.d.ts +0 -1
  169. package/dist/auth.compile.test.js +0 -201
  170. package/dist/auth.coverage.test.d.ts +0 -1
  171. package/dist/auth.coverage.test.js +0 -202
  172. package/dist/auth.test.d.ts +0 -1
  173. package/dist/auth.test.js +0 -2286
  174. package/dist/betterAuth.test.d.ts +0 -1
  175. package/dist/betterAuth.test.js +0 -181
  176. package/dist/betterAuthApp.test.d.ts +0 -1
  177. package/dist/betterAuthApp.test.js +0 -242
  178. package/dist/betterAuthSetup.test.d.ts +0 -1
  179. package/dist/betterAuthSetup.test.js +0 -762
  180. package/dist/config.test.d.ts +0 -1
  181. package/dist/config.test.js +0 -353
  182. package/dist/configuration.test.d.ts +0 -1
  183. package/dist/configuration.test.js +0 -980
  184. package/dist/configurationPlugin.test.d.ts +0 -1
  185. package/dist/configurationPlugin.test.js +0 -827
  186. package/dist/consentApp.test.d.ts +0 -1
  187. package/dist/consentApp.test.js +0 -1411
  188. package/dist/docLoader.test.d.ts +0 -1
  189. package/dist/docLoader.test.js +0 -137
  190. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  191. package/dist/envConfigurationPlugin.test.js +0 -369
  192. package/dist/errors.test.d.ts +0 -1
  193. package/dist/errors.test.js +0 -607
  194. package/dist/expressServer.test.d.ts +0 -1
  195. package/dist/expressServer.test.js +0 -1249
  196. package/dist/githubAuth.test.d.ts +0 -1
  197. package/dist/githubAuth.test.js +0 -1142
  198. package/dist/httpClient.test.d.ts +0 -1
  199. package/dist/httpClient.test.js +0 -1471
  200. package/dist/logger.test.d.ts +0 -1
  201. package/dist/logger.test.js +0 -685
  202. package/dist/middleware.test.d.ts +0 -1
  203. package/dist/middleware.test.js +0 -241
  204. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  205. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  206. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  207. package/dist/notifiers/slackNotifier.test.js +0 -297
  208. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  209. package/dist/notifiers/zoomNotifier.test.js +0 -373
  210. package/dist/openApi.test.d.ts +0 -1
  211. package/dist/openApi.test.js +0 -620
  212. package/dist/openApiBuilder.test.d.ts +0 -1
  213. package/dist/openApiBuilder.test.js +0 -599
  214. package/dist/openApiEtag.test.d.ts +0 -1
  215. package/dist/openApiEtag.test.js +0 -86
  216. package/dist/openApiValidator.test.d.ts +0 -1
  217. package/dist/openApiValidator.test.js +0 -795
  218. package/dist/permissions.middleware.test.d.ts +0 -1
  219. package/dist/permissions.middleware.test.js +0 -308
  220. package/dist/permissions.test.d.ts +0 -1
  221. package/dist/permissions.test.js +0 -439
  222. package/dist/plugins.test.d.ts +0 -1
  223. package/dist/plugins.test.js +0 -902
  224. package/dist/populate.test.d.ts +0 -1
  225. package/dist/populate.test.js +0 -370
  226. package/dist/realtime/realtime.test.d.ts +0 -10
  227. package/dist/realtime/realtime.test.js +0 -4213
  228. package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
  229. package/dist/realtime/realtimeAppSetup.test.js +0 -213
  230. package/dist/requestContext.test.d.ts +0 -1
  231. package/dist/requestContext.test.js +0 -412
  232. package/dist/scriptRunner.test.d.ts +0 -1
  233. package/dist/scriptRunner.test.js +0 -386
  234. package/dist/secretProviders.test.d.ts +0 -1
  235. package/dist/secretProviders.test.js +0 -726
  236. package/dist/syncConsents.test.d.ts +0 -1
  237. package/dist/syncConsents.test.js +0 -522
  238. package/dist/terrenoApp.test.d.ts +0 -1
  239. package/dist/terrenoApp.test.js +0 -489
  240. package/dist/tests/bunSetup.d.ts +0 -1
  241. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  242. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  243. package/dist/tests/testEnv.d.ts +0 -0
  244. package/dist/tests/testEnv.js +0 -6
  245. package/dist/transformers.test.d.ts +0 -1
  246. package/dist/transformers.test.js +0 -423
  247. package/dist/utils.test.d.ts +0 -1
  248. package/dist/utils.test.js +0 -242
  249. package/src/realtime/realtimeAppSetup.test.ts +0 -161
  250. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1,423 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var bun_test_1 = require("bun:test");
54
- var supertest_1 = __importDefault(require("supertest"));
55
- var api_1 = require("./api");
56
- var auth_1 = require("./auth");
57
- var errors_1 = require("./errors");
58
- var permissions_1 = require("./permissions");
59
- var tests_1 = require("./tests");
60
- var transformers_1 = require("./transformers");
61
- (0, bun_test_1.describe)("query and transform", function () {
62
- var notAdmin;
63
- var admin;
64
- var server;
65
- var app;
66
- (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
67
- var testData;
68
- return __generator(this, function (_a) {
69
- switch (_a.label) {
70
- case 0:
71
- process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
72
- return [4 /*yield*/, (0, tests_1.setupTestData)()];
73
- case 1:
74
- testData = _a.sent();
75
- admin = testData.users.admin;
76
- notAdmin = testData.users.notAdmin;
77
- app = (0, tests_1.getBaseServer)();
78
- (0, auth_1.setupAuth)(app, tests_1.UserModel);
79
- (0, auth_1.addAuthRoutes)(app, tests_1.UserModel);
80
- app.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, {
81
- allowAnonymous: true,
82
- permissions: {
83
- create: [permissions_1.Permissions.IsAny],
84
- delete: [permissions_1.Permissions.IsAny],
85
- list: [permissions_1.Permissions.IsAny],
86
- read: [permissions_1.Permissions.IsAny],
87
- update: [permissions_1.Permissions.IsAny],
88
- },
89
- queryFilter: function (user) {
90
- if (!(user === null || user === void 0 ? void 0 : user.admin)) {
91
- return { hidden: { $ne: true } };
92
- }
93
- return {};
94
- },
95
- transformer: (0, transformers_1.AdminOwnerTransformer)({
96
- adminReadFields: ["name", "calories", "created", "ownerId"],
97
- adminWriteFields: ["name", "calories", "created", "ownerId"],
98
- anonReadFields: ["name"],
99
- anonWriteFields: [],
100
- authReadFields: ["name", "calories", "created"],
101
- authWriteFields: ["name", "calories"],
102
- ownerReadFields: ["name", "calories", "created", "ownerId"],
103
- ownerWriteFields: ["name", "calories", "created"],
104
- }),
105
- }));
106
- server = (0, supertest_1.default)(app);
107
- return [2 /*return*/];
108
- }
109
- });
110
- }); });
111
- (0, bun_test_1.it)("filters list for non-admin", function () { return __awaiter(void 0, void 0, void 0, function () {
112
- var agent, foodRes;
113
- return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
116
- case 1:
117
- agent = _a.sent();
118
- return [4 /*yield*/, agent.get("/food").expect(200)];
119
- case 2:
120
- foodRes = _a.sent();
121
- (0, bun_test_1.expect)(foodRes.body.data).toHaveLength(3);
122
- return [2 /*return*/];
123
- }
124
- });
125
- }); });
126
- (0, bun_test_1.it)("does not filter list for admin", function () { return __awaiter(void 0, void 0, void 0, function () {
127
- var agent, foodRes;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "admin")];
131
- case 1:
132
- agent = _a.sent();
133
- return [4 /*yield*/, agent.get("/food").expect(200)];
134
- case 2:
135
- foodRes = _a.sent();
136
- (0, bun_test_1.expect)(foodRes.body.data).toHaveLength(4);
137
- return [2 /*return*/];
138
- }
139
- });
140
- }); });
141
- (0, bun_test_1.it)("admin read transform", function () { return __awaiter(void 0, void 0, void 0, function () {
142
- var agent, foodRes, spinach;
143
- return __generator(this, function (_a) {
144
- switch (_a.label) {
145
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "admin")];
146
- case 1:
147
- agent = _a.sent();
148
- return [4 /*yield*/, agent.get("/food").expect(200)];
149
- case 2:
150
- foodRes = _a.sent();
151
- (0, bun_test_1.expect)(foodRes.body.data).toHaveLength(4);
152
- spinach = foodRes.body.data.find(function (food) { return food.name === "Spinach"; });
153
- (0, bun_test_1.expect)(spinach.created).toBeDefined();
154
- (0, bun_test_1.expect)(spinach.id).toBeDefined();
155
- (0, bun_test_1.expect)(spinach.ownerId).toBeDefined();
156
- (0, bun_test_1.expect)(spinach.name).toBe("Spinach");
157
- (0, bun_test_1.expect)(spinach.calories).toBe(1);
158
- (0, bun_test_1.expect)(spinach.hidden).toBeUndefined();
159
- return [2 /*return*/];
160
- }
161
- });
162
- }); });
163
- (0, bun_test_1.it)("admin write transform", function () { return __awaiter(void 0, void 0, void 0, function () {
164
- var agent, foodRes, spinach, spinachRes;
165
- return __generator(this, function (_a) {
166
- switch (_a.label) {
167
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "admin")];
168
- case 1:
169
- agent = _a.sent();
170
- return [4 /*yield*/, agent.get("/food").expect(200)];
171
- case 2:
172
- foodRes = _a.sent();
173
- spinach = foodRes.body.data.find(function (food) { return food.name === "Spinach"; });
174
- return [4 /*yield*/, agent.patch("/food/".concat(spinach.id)).send({ name: "Lettuce" }).expect(200)];
175
- case 3:
176
- spinachRes = _a.sent();
177
- (0, bun_test_1.expect)(spinachRes.body.data.name).toBe("Lettuce");
178
- return [2 /*return*/];
179
- }
180
- });
181
- }); });
182
- (0, bun_test_1.it)("owner read transform", function () { return __awaiter(void 0, void 0, void 0, function () {
183
- var agent, foodRes, spinach;
184
- return __generator(this, function (_a) {
185
- switch (_a.label) {
186
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
187
- case 1:
188
- agent = _a.sent();
189
- return [4 /*yield*/, agent.get("/food").expect(200)];
190
- case 2:
191
- foodRes = _a.sent();
192
- (0, bun_test_1.expect)(foodRes.body.data).toHaveLength(3);
193
- spinach = foodRes.body.data.find(function (food) { return food.name === "Spinach"; });
194
- (0, bun_test_1.expect)(spinach.id).toBeDefined();
195
- (0, bun_test_1.expect)(spinach.name).toBe("Spinach");
196
- (0, bun_test_1.expect)(spinach.calories).toBe(1);
197
- (0, bun_test_1.expect)(spinach.created).toBeDefined();
198
- (0, bun_test_1.expect)(spinach.ownerId).toBeDefined();
199
- (0, bun_test_1.expect)(spinach.hidden).toBeUndefined();
200
- return [2 /*return*/];
201
- }
202
- });
203
- }); });
204
- (0, bun_test_1.it)("owner write transform", function () { return __awaiter(void 0, void 0, void 0, function () {
205
- var agent, foodRes, spinach;
206
- return __generator(this, function (_a) {
207
- switch (_a.label) {
208
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
209
- case 1:
210
- agent = _a.sent();
211
- return [4 /*yield*/, agent.get("/food").expect(200)];
212
- case 2:
213
- foodRes = _a.sent();
214
- spinach = foodRes.body.data.find(function (food) { return food.name === "Spinach"; });
215
- return [4 /*yield*/, agent.patch("/food/".concat(spinach.id)).send({ ownerId: admin.id }).expect(403)];
216
- case 3:
217
- _a.sent();
218
- return [2 /*return*/];
219
- }
220
- });
221
- }); });
222
- (0, bun_test_1.it)("owner write transform fails", function () { return __awaiter(void 0, void 0, void 0, function () {
223
- var agent, foodRes, spinach, spinachRes;
224
- return __generator(this, function (_a) {
225
- switch (_a.label) {
226
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
227
- case 1:
228
- agent = _a.sent();
229
- return [4 /*yield*/, agent.get("/food").expect(200)];
230
- case 2:
231
- foodRes = _a.sent();
232
- spinach = foodRes.body.data.find(function (food) { return food.name === "Spinach"; });
233
- return [4 /*yield*/, agent
234
- .patch("/food/".concat(spinach.id))
235
- .send({ ownerId: notAdmin.id })
236
- .expect(403)];
237
- case 3:
238
- spinachRes = _a.sent();
239
- (0, bun_test_1.expect)(spinachRes.body.title.includes("User of type owner cannot write fields: ownerId")).toBe(true);
240
- return [2 /*return*/];
241
- }
242
- });
243
- }); });
244
- (0, bun_test_1.it)("auth read transform", function () { return __awaiter(void 0, void 0, void 0, function () {
245
- var agent, foodRes, spinach, carrots;
246
- return __generator(this, function (_a) {
247
- switch (_a.label) {
248
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
249
- case 1:
250
- agent = _a.sent();
251
- return [4 /*yield*/, agent.get("/food").expect(200)];
252
- case 2:
253
- foodRes = _a.sent();
254
- (0, bun_test_1.expect)(foodRes.body.data).toHaveLength(3);
255
- spinach = foodRes.body.data.find(function (food) { return food.name === "Spinach"; });
256
- (0, bun_test_1.expect)(spinach.id).toBeDefined();
257
- (0, bun_test_1.expect)(spinach.name).toBe("Spinach");
258
- (0, bun_test_1.expect)(spinach.calories).toBe(1);
259
- (0, bun_test_1.expect)(spinach.created).toBeDefined();
260
- // Owner, so this is defined.
261
- (0, bun_test_1.expect)(spinach.ownerId).toBeDefined();
262
- (0, bun_test_1.expect)(spinach.hidden).toBeUndefined();
263
- carrots = foodRes.body.data.find(function (food) { return food.name === "Carrots"; });
264
- (0, bun_test_1.expect)(carrots.id).toBeDefined();
265
- (0, bun_test_1.expect)(carrots.name).toBe("Carrots");
266
- (0, bun_test_1.expect)(carrots.calories).toBe(100);
267
- (0, bun_test_1.expect)(carrots.created).toBeDefined();
268
- // Not owner, so undefined.
269
- (0, bun_test_1.expect)(carrots.ownerId).toBeUndefined();
270
- (0, bun_test_1.expect)(spinach.hidden).toBeUndefined();
271
- return [2 /*return*/];
272
- }
273
- });
274
- }); });
275
- (0, bun_test_1.it)("auth write transform", function () { return __awaiter(void 0, void 0, void 0, function () {
276
- var agent, foodRes, carrots, carrotRes;
277
- return __generator(this, function (_a) {
278
- switch (_a.label) {
279
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
280
- case 1:
281
- agent = _a.sent();
282
- return [4 /*yield*/, agent.get("/food")];
283
- case 2:
284
- foodRes = _a.sent();
285
- carrots = foodRes.body.data.find(function (food) { return food.name === "Carrots"; });
286
- return [4 /*yield*/, agent.patch("/food/".concat(carrots.id)).send({ calories: 2000 }).expect(200)];
287
- case 3:
288
- carrotRes = _a.sent();
289
- (0, bun_test_1.expect)(carrotRes.body.data.calories).toBe(2000);
290
- return [2 /*return*/];
291
- }
292
- });
293
- }); });
294
- (0, bun_test_1.it)("auth write transform fail", function () { return __awaiter(void 0, void 0, void 0, function () {
295
- var agent, foodRes, carrots, writeRes;
296
- return __generator(this, function (_a) {
297
- switch (_a.label) {
298
- case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
299
- case 1:
300
- agent = _a.sent();
301
- return [4 /*yield*/, agent.get("/food")];
302
- case 2:
303
- foodRes = _a.sent();
304
- carrots = foodRes.body.data.find(function (food) { return food.name === "Carrots"; });
305
- return [4 /*yield*/, agent
306
- .patch("/food/".concat(carrots.id))
307
- .send({ created: "2020-01-01T00:00:00Z" })
308
- .expect(403)];
309
- case 3:
310
- writeRes = _a.sent();
311
- (0, bun_test_1.expect)(writeRes.body.title.includes("User of type auth cannot write fields: created")).toBe(true);
312
- return [2 /*return*/];
313
- }
314
- });
315
- }); });
316
- (0, bun_test_1.it)("anon read transform", function () { return __awaiter(void 0, void 0, void 0, function () {
317
- var res;
318
- return __generator(this, function (_a) {
319
- switch (_a.label) {
320
- case 0: return [4 /*yield*/, server.get("/food")];
321
- case 1:
322
- res = _a.sent();
323
- (0, bun_test_1.expect)(res.body.data).toHaveLength(3);
324
- (0, bun_test_1.expect)(res.body.data.find(function (f) { return f.name === "Spinach"; })).toBeDefined();
325
- (0, bun_test_1.expect)(res.body.data.find(function (f) { return f.name === "Carrots"; })).toBeDefined();
326
- (0, bun_test_1.expect)(res.body.data.find(function (f) { return f.name === "Pizza"; })).toBeDefined();
327
- return [2 /*return*/];
328
- }
329
- });
330
- }); });
331
- (0, bun_test_1.it)("anon write transform fails", function () { return __awaiter(void 0, void 0, void 0, function () {
332
- var foodRes, carrots;
333
- return __generator(this, function (_a) {
334
- switch (_a.label) {
335
- case 0: return [4 /*yield*/, server.get("/food")];
336
- case 1:
337
- foodRes = _a.sent();
338
- carrots = foodRes.body.data.find(function (food) { return food.name === "Carrots"; });
339
- return [4 /*yield*/, server.patch("/food/".concat(carrots.id)).send({ calories: 10 }).expect(403)];
340
- case 2:
341
- _a.sent();
342
- return [2 /*return*/];
343
- }
344
- });
345
- }); });
346
- });
347
- (0, bun_test_1.describe)("transform (deprecated helper)", function () {
348
- var mockTransformFn = function (obj, _method) { return (__assign(__assign({}, obj), { name: "".concat(obj.name, "_transformed") })); };
349
- (0, bun_test_1.it)("returns data unchanged when no transformer is configured", function () {
350
- var options = { permissions: {} };
351
- var data = { name: "Apple" };
352
- (0, bun_test_1.expect)((0, transformers_1.transform)(options, data, "create")).toEqual(data);
353
- });
354
- (0, bun_test_1.it)("transforms a single object", function () {
355
- var options = {
356
- transformer: { transform: mockTransformFn },
357
- };
358
- var result = (0, transformers_1.transform)(options, { name: "Apple" }, "create");
359
- (0, bun_test_1.expect)(result.name).toBe("Apple_transformed");
360
- });
361
- (0, bun_test_1.it)("transforms an array of objects", function () {
362
- var options = {
363
- transformer: { transform: mockTransformFn },
364
- };
365
- var data = [{ name: "Apple" }, { name: "Banana" }];
366
- var result = (0, transformers_1.transform)(options, data, "update");
367
- (0, bun_test_1.expect)(result).toHaveLength(2);
368
- (0, bun_test_1.expect)(result[0].name).toBe("Apple_transformed");
369
- (0, bun_test_1.expect)(result[1].name).toBe("Banana_transformed");
370
- });
371
- });
372
- (0, bun_test_1.describe)("defaultResponseHandler", function () {
373
- (0, bun_test_1.it)("returns null when doc is null", function () { return __awaiter(void 0, void 0, void 0, function () {
374
- var options, req, result;
375
- return __generator(this, function (_a) {
376
- switch (_a.label) {
377
- case 0:
378
- options = { permissions: {} };
379
- req = {};
380
- return [4 /*yield*/, (0, transformers_1.defaultResponseHandler)(null, "read", req, options)];
381
- case 1:
382
- result = _a.sent();
383
- (0, bun_test_1.expect)(result).toBeNull();
384
- return [2 /*return*/];
385
- }
386
- });
387
- }); });
388
- (0, bun_test_1.it)("throws APIError when serialize throws", function () { return __awaiter(void 0, void 0, void 0, function () {
389
- var options, fakeDoc, req, err_1;
390
- return __generator(this, function (_a) {
391
- switch (_a.label) {
392
- case 0:
393
- options = {
394
- transformer: {
395
- serialize: function () {
396
- throw new Error("serialize boom");
397
- },
398
- },
399
- };
400
- fakeDoc = {
401
- _id: "abc",
402
- toObject: function () { return ({ name: "Apple" }); },
403
- };
404
- req = {};
405
- _a.label = 1;
406
- case 1:
407
- _a.trys.push([1, 3, , 4]);
408
- return [4 /*yield*/, (0, transformers_1.defaultResponseHandler)(fakeDoc, "read", req, options)];
409
- case 2:
410
- _a.sent();
411
- (0, bun_test_1.expect)(true).toBe(false);
412
- return [3 /*break*/, 4];
413
- case 3:
414
- err_1 = _a.sent();
415
- (0, bun_test_1.expect)(err_1).toBeInstanceOf(errors_1.APIError);
416
- (0, bun_test_1.expect)(err_1.status).toBe(400);
417
- (0, bun_test_1.expect)(err_1.title).toContain("Error serializing read response");
418
- return [3 /*break*/, 4];
419
- case 4: return [2 /*return*/];
420
- }
421
- });
422
- }); });
423
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,242 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- var bun_test_1 = require("bun:test");
43
- var mongoose_1 = __importDefault(require("mongoose"));
44
- var utils_1 = require("./utils");
45
- (0, bun_test_1.describe)("utils", function () {
46
- (0, bun_test_1.describe)("isValidObjectId", function () {
47
- (0, bun_test_1.it)("checks valid ObjectIds", function () {
48
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("62c44da0003d9f8ee8cc925c")).toBe(true);
49
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("620000000000000000000000")).toBe(true);
50
- // Mongoose's builtin "ObjectId.isValid" will falsely say this is an ObjectId.
51
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("1234567890ab")).toBe(false);
52
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("microsoft123")).toBe(false);
53
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("62c44da0003d9f8ee8cc925x")).toBe(false);
54
- });
55
- });
56
- (0, bun_test_1.describe)("checkModelsStrict", function () {
57
- (0, bun_test_1.it)("throws error when toObject.virtuals is not true", function () {
58
- // Create a schema without toObject.virtuals
59
- var testSchema = new mongoose_1.default.Schema({ name: String });
60
- testSchema.set("strict", "throw");
61
- // Not setting toObject.virtuals
62
- if (mongoose_1.default.models.ToObjectTestModel) {
63
- delete mongoose_1.default.models.ToObjectTestModel;
64
- }
65
- mongoose_1.default.model("ToObjectTestModel", testSchema);
66
- try {
67
- // This should throw because ToObjectTestModel doesn't have toObject.virtuals
68
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).toThrow("toObject.virtuals not set to true");
69
- }
70
- finally {
71
- delete mongoose_1.default.models.ToObjectTestModel;
72
- }
73
- });
74
- (0, bun_test_1.it)("throws error when toJSON.virtuals is not true", function () {
75
- // Create a schema with toObject.virtuals but without toJSON.virtuals
76
- var testSchema = new mongoose_1.default.Schema({ name: String });
77
- testSchema.set("toObject", { virtuals: true });
78
- testSchema.set("strict", "throw");
79
- // Not setting toJSON.virtuals
80
- if (mongoose_1.default.models.ToJsonTestModel) {
81
- delete mongoose_1.default.models.ToJsonTestModel;
82
- }
83
- mongoose_1.default.model("ToJsonTestModel", testSchema);
84
- // Use spyOn to intercept modelNames and return only our test model
85
- var spy = (0, bun_test_1.spyOn)(mongoose_1.default, "modelNames").mockReturnValue(["ToJsonTestModel"]);
86
- try {
87
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).toThrow("toJSON.virtuals not set to true");
88
- }
89
- finally {
90
- spy.mockRestore();
91
- delete mongoose_1.default.models.ToJsonTestModel;
92
- }
93
- });
94
- (0, bun_test_1.it)("throws error when strict mode is not set to throw", function () {
95
- // Create a schema with virtuals but without strict mode
96
- var testSchema = new mongoose_1.default.Schema({ name: String });
97
- testSchema.set("toObject", { virtuals: true });
98
- testSchema.set("toJSON", { virtuals: true });
99
- // Not setting strict to "throw"
100
- if (mongoose_1.default.models.StrictTestModel) {
101
- delete mongoose_1.default.models.StrictTestModel;
102
- }
103
- mongoose_1.default.model("StrictTestModel", testSchema);
104
- var spy = (0, bun_test_1.spyOn)(mongoose_1.default, "modelNames").mockReturnValue(["StrictTestModel"]);
105
- try {
106
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).toThrow("is not set to strict mode");
107
- }
108
- finally {
109
- spy.mockRestore();
110
- delete mongoose_1.default.models.StrictTestModel;
111
- }
112
- });
113
- (0, bun_test_1.it)("passes when all checks pass", function () {
114
- // Create a properly configured schema
115
- var testSchema = new mongoose_1.default.Schema({ name: String });
116
- testSchema.set("toObject", { virtuals: true });
117
- testSchema.set("toJSON", { virtuals: true });
118
- testSchema.set("strict", "throw");
119
- if (mongoose_1.default.models.GoodTestModel) {
120
- delete mongoose_1.default.models.GoodTestModel;
121
- }
122
- mongoose_1.default.model("GoodTestModel", testSchema);
123
- var spy = (0, bun_test_1.spyOn)(mongoose_1.default, "modelNames").mockReturnValue(["GoodTestModel"]);
124
- try {
125
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).not.toThrow();
126
- }
127
- finally {
128
- spy.mockRestore();
129
- delete mongoose_1.default.models.GoodTestModel;
130
- }
131
- });
132
- (0, bun_test_1.it)("skips strict mode check for ignored models", function () {
133
- // Create a properly configured model
134
- var goodSchema = new mongoose_1.default.Schema({ name: String });
135
- goodSchema.set("toObject", { virtuals: true });
136
- goodSchema.set("toJSON", { virtuals: true });
137
- goodSchema.set("strict", "throw");
138
- if (mongoose_1.default.models.GoodModel) {
139
- delete mongoose_1.default.models.GoodModel;
140
- }
141
- mongoose_1.default.model("GoodModel", goodSchema);
142
- // Create a model without strict mode that we'll ignore
143
- var badSchema = new mongoose_1.default.Schema({ name: String });
144
- badSchema.set("toObject", { virtuals: true });
145
- badSchema.set("toJSON", { virtuals: true });
146
- // Not setting strict - should fail unless ignored
147
- if (mongoose_1.default.models.IgnoredModel) {
148
- delete mongoose_1.default.models.IgnoredModel;
149
- }
150
- mongoose_1.default.model("IgnoredModel", badSchema);
151
- var spy = (0, bun_test_1.spyOn)(mongoose_1.default, "modelNames").mockReturnValue(["GoodModel", "IgnoredModel"]);
152
- try {
153
- // Without ignoring, should throw for IgnoredModel
154
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).toThrow("is not set to strict mode");
155
- // With ignoring IgnoredModel, should pass
156
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(["IgnoredModel"]); }).not.toThrow();
157
- }
158
- finally {
159
- spy.mockRestore();
160
- delete mongoose_1.default.models.GoodModel;
161
- delete mongoose_1.default.models.IgnoredModel;
162
- }
163
- });
164
- (0, bun_test_1.it)("handles multiple models and validates all", function () {
165
- // Create three properly configured models
166
- var schema1 = new mongoose_1.default.Schema({ name: String });
167
- schema1.set("toObject", { virtuals: true });
168
- schema1.set("toJSON", { virtuals: true });
169
- schema1.set("strict", "throw");
170
- var schema2 = new mongoose_1.default.Schema({ value: Number });
171
- schema2.set("toObject", { virtuals: true });
172
- schema2.set("toJSON", { virtuals: true });
173
- schema2.set("strict", "throw");
174
- var schema3 = new mongoose_1.default.Schema({ active: Boolean });
175
- schema3.set("toObject", { virtuals: true });
176
- schema3.set("toJSON", { virtuals: true });
177
- schema3.set("strict", "throw");
178
- if (mongoose_1.default.models.MultiModel1)
179
- delete mongoose_1.default.models.MultiModel1;
180
- if (mongoose_1.default.models.MultiModel2)
181
- delete mongoose_1.default.models.MultiModel2;
182
- if (mongoose_1.default.models.MultiModel3)
183
- delete mongoose_1.default.models.MultiModel3;
184
- mongoose_1.default.model("MultiModel1", schema1);
185
- mongoose_1.default.model("MultiModel2", schema2);
186
- mongoose_1.default.model("MultiModel3", schema3);
187
- var spy = (0, bun_test_1.spyOn)(mongoose_1.default, "modelNames").mockReturnValue([
188
- "MultiModel1",
189
- "MultiModel2",
190
- "MultiModel3",
191
- ]);
192
- try {
193
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).not.toThrow();
194
- }
195
- finally {
196
- spy.mockRestore();
197
- delete mongoose_1.default.models.MultiModel1;
198
- delete mongoose_1.default.models.MultiModel2;
199
- delete mongoose_1.default.models.MultiModel3;
200
- }
201
- });
202
- (0, bun_test_1.it)("handles empty model list", function () {
203
- var spy = (0, bun_test_1.spyOn)(mongoose_1.default, "modelNames").mockReturnValue([]);
204
- try {
205
- (0, bun_test_1.expect)(function () { return (0, utils_1.checkModelsStrict)(); }).not.toThrow();
206
- }
207
- finally {
208
- spy.mockRestore();
209
- }
210
- });
211
- });
212
- (0, bun_test_1.describe)("timeout", function () {
213
- (0, bun_test_1.it)("resolves after specified time", function () { return __awaiter(void 0, void 0, void 0, function () {
214
- var start, elapsed;
215
- return __generator(this, function (_a) {
216
- switch (_a.label) {
217
- case 0:
218
- start = Date.now();
219
- return [4 /*yield*/, (0, utils_1.timeout)(50)];
220
- case 1:
221
- _a.sent();
222
- elapsed = Date.now() - start;
223
- (0, bun_test_1.expect)(elapsed).toBeGreaterThanOrEqual(40);
224
- return [2 /*return*/];
225
- }
226
- });
227
- }); });
228
- });
229
- (0, bun_test_1.describe)("isValidObjectId additional cases", function () {
230
- (0, bun_test_1.it)("returns true for valid ObjectId strings", function () {
231
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("507f1f77bcf86cd799439011")).toBe(true);
232
- });
233
- (0, bun_test_1.it)("returns false for invalid ObjectId strings", function () {
234
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("invalid-id")).toBe(false);
235
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("12345")).toBe(false);
236
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("")).toBe(false);
237
- });
238
- (0, bun_test_1.it)("returns false for 12-character strings that are not valid ObjectIds", function () {
239
- (0, bun_test_1.expect)((0, utils_1.isValidObjectId)("123456789012")).toBe(false);
240
- });
241
- });
242
- });