@terreno/api 0.0.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 (119) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +170 -0
  3. package/biome.jsonc +22 -0
  4. package/bunfig.toml +4 -0
  5. package/dist/api.d.ts +227 -0
  6. package/dist/api.js +1024 -0
  7. package/dist/api.test.d.ts +1 -0
  8. package/dist/api.test.js +2143 -0
  9. package/dist/auth.d.ts +50 -0
  10. package/dist/auth.js +512 -0
  11. package/dist/auth.test.d.ts +1 -0
  12. package/dist/auth.test.js +778 -0
  13. package/dist/errors.d.ts +75 -0
  14. package/dist/errors.js +216 -0
  15. package/dist/example.d.ts +1 -0
  16. package/dist/example.js +118 -0
  17. package/dist/expressServer.d.ts +35 -0
  18. package/dist/expressServer.js +436 -0
  19. package/dist/index.d.ts +14 -0
  20. package/dist/index.js +30 -0
  21. package/dist/logger.d.ts +23 -0
  22. package/dist/logger.js +249 -0
  23. package/dist/middleware.d.ts +10 -0
  24. package/dist/middleware.js +52 -0
  25. package/dist/notifiers/googleChatNotifier.d.ts +5 -0
  26. package/dist/notifiers/googleChatNotifier.js +130 -0
  27. package/dist/notifiers/googleChatNotifier.test.d.ts +1 -0
  28. package/dist/notifiers/googleChatNotifier.test.js +260 -0
  29. package/dist/notifiers/index.d.ts +3 -0
  30. package/dist/notifiers/index.js +19 -0
  31. package/dist/notifiers/slackNotifier.d.ts +5 -0
  32. package/dist/notifiers/slackNotifier.js +130 -0
  33. package/dist/notifiers/slackNotifier.test.d.ts +1 -0
  34. package/dist/notifiers/slackNotifier.test.js +259 -0
  35. package/dist/notifiers/zoomNotifier.d.ts +34 -0
  36. package/dist/notifiers/zoomNotifier.js +181 -0
  37. package/dist/notifiers/zoomNotifier.test.d.ts +1 -0
  38. package/dist/notifiers/zoomNotifier.test.js +370 -0
  39. package/dist/openApi.d.ts +60 -0
  40. package/dist/openApi.js +441 -0
  41. package/dist/openApi.test.d.ts +1 -0
  42. package/dist/openApi.test.js +445 -0
  43. package/dist/openApiBuilder.d.ts +419 -0
  44. package/dist/openApiBuilder.js +424 -0
  45. package/dist/openApiBuilder.test.d.ts +1 -0
  46. package/dist/openApiBuilder.test.js +509 -0
  47. package/dist/openApiEtag.d.ts +7 -0
  48. package/dist/openApiEtag.js +38 -0
  49. package/dist/permissions.d.ts +26 -0
  50. package/dist/permissions.js +331 -0
  51. package/dist/permissions.test.d.ts +1 -0
  52. package/dist/permissions.test.js +413 -0
  53. package/dist/plugins.d.ts +67 -0
  54. package/dist/plugins.js +315 -0
  55. package/dist/plugins.test.d.ts +1 -0
  56. package/dist/plugins.test.js +639 -0
  57. package/dist/populate.d.ts +14 -0
  58. package/dist/populate.js +315 -0
  59. package/dist/populate.test.d.ts +1 -0
  60. package/dist/populate.test.js +133 -0
  61. package/dist/response.d.ts +0 -0
  62. package/dist/response.js +1 -0
  63. package/dist/tests/bunSetup.d.ts +1 -0
  64. package/dist/tests/bunSetup.js +297 -0
  65. package/dist/tests/index.d.ts +1 -0
  66. package/dist/tests/index.js +17 -0
  67. package/dist/tests.d.ts +99 -0
  68. package/dist/tests.js +273 -0
  69. package/dist/transformers.d.ts +25 -0
  70. package/dist/transformers.js +217 -0
  71. package/dist/transformers.test.d.ts +1 -0
  72. package/dist/transformers.test.js +370 -0
  73. package/dist/utils.d.ts +11 -0
  74. package/dist/utils.js +143 -0
  75. package/dist/utils.test.d.ts +1 -0
  76. package/dist/utils.test.js +14 -0
  77. package/index.ts +1 -0
  78. package/package.json +88 -0
  79. package/src/__snapshots__/openApi.test.ts.snap +4814 -0
  80. package/src/__snapshots__/openApiBuilder.test.ts.snap +1485 -0
  81. package/src/api.test.ts +1661 -0
  82. package/src/api.ts +1036 -0
  83. package/src/auth.test.ts +550 -0
  84. package/src/auth.ts +408 -0
  85. package/src/errors.ts +225 -0
  86. package/src/example.ts +99 -0
  87. package/src/express.d.ts +5 -0
  88. package/src/expressServer.ts +387 -0
  89. package/src/index.ts +14 -0
  90. package/src/logger.ts +190 -0
  91. package/src/middleware.ts +18 -0
  92. package/src/notifiers/googleChatNotifier.test.ts +114 -0
  93. package/src/notifiers/googleChatNotifier.ts +47 -0
  94. package/src/notifiers/index.ts +3 -0
  95. package/src/notifiers/slackNotifier.test.ts +113 -0
  96. package/src/notifiers/slackNotifier.ts +55 -0
  97. package/src/notifiers/zoomNotifier.test.ts +207 -0
  98. package/src/notifiers/zoomNotifier.ts +111 -0
  99. package/src/openApi.test.ts +331 -0
  100. package/src/openApi.ts +494 -0
  101. package/src/openApiBuilder.test.ts +442 -0
  102. package/src/openApiBuilder.ts +636 -0
  103. package/src/openApiEtag.ts +40 -0
  104. package/src/permissions.test.ts +219 -0
  105. package/src/permissions.ts +228 -0
  106. package/src/plugins.test.ts +390 -0
  107. package/src/plugins.ts +289 -0
  108. package/src/populate.test.ts +65 -0
  109. package/src/populate.ts +258 -0
  110. package/src/response.ts +0 -0
  111. package/src/tests/bunSetup.ts +234 -0
  112. package/src/tests/index.ts +1 -0
  113. package/src/tests.ts +218 -0
  114. package/src/transformers.test.ts +202 -0
  115. package/src/transformers.ts +170 -0
  116. package/src/utils.test.ts +14 -0
  117. package/src/utils.ts +47 -0
  118. package/tsconfig.json +60 -0
  119. package/types.d.ts +17 -0
@@ -0,0 +1,413 @@
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 __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ var __importDefault = (this && this.__importDefault) || function (mod) {
55
+ return (mod && mod.__esModule) ? mod : { "default": mod };
56
+ };
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ var bun_test_1 = require("bun:test");
59
+ var supertest_1 = __importDefault(require("supertest"));
60
+ var api_1 = require("./api");
61
+ var auth_1 = require("./auth");
62
+ var permissions_1 = require("./permissions");
63
+ var tests_1 = require("./tests");
64
+ (0, bun_test_1.describe)("permissions", function () {
65
+ var server;
66
+ var app;
67
+ (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
68
+ var _a, admin, notAdmin;
69
+ return __generator(this, function (_b) {
70
+ switch (_b.label) {
71
+ case 0:
72
+ process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
73
+ return [4 /*yield*/, (0, tests_1.setupDb)()];
74
+ case 1:
75
+ _a = __read.apply(void 0, [_b.sent(), 2]), admin = _a[0], notAdmin = _a[1];
76
+ return [4 /*yield*/, Promise.all([
77
+ tests_1.FoodModel.create({
78
+ calories: 1,
79
+ created: new Date(),
80
+ name: "Spinach",
81
+ ownerId: notAdmin._id,
82
+ }),
83
+ tests_1.FoodModel.create({
84
+ calories: 100,
85
+ created: Date.now() - 10,
86
+ name: "Apple",
87
+ ownerId: admin._id,
88
+ }),
89
+ ])];
90
+ case 2:
91
+ _b.sent();
92
+ app = (0, tests_1.getBaseServer)();
93
+ (0, auth_1.setupAuth)(app, tests_1.UserModel);
94
+ (0, auth_1.addAuthRoutes)(app, tests_1.UserModel);
95
+ app.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, {
96
+ allowAnonymous: true,
97
+ permissions: {
98
+ create: [permissions_1.Permissions.IsAuthenticated],
99
+ delete: [permissions_1.Permissions.IsAdmin],
100
+ list: [permissions_1.Permissions.IsAny],
101
+ read: [permissions_1.Permissions.IsAny],
102
+ update: [permissions_1.Permissions.IsOwner],
103
+ },
104
+ }));
105
+ app.use("/required", (0, api_1.modelRouter)(tests_1.RequiredModel, {
106
+ permissions: {
107
+ create: [permissions_1.Permissions.IsAuthenticated],
108
+ delete: [permissions_1.Permissions.IsAdmin],
109
+ list: [permissions_1.Permissions.IsAny],
110
+ read: [permissions_1.Permissions.IsAny],
111
+ update: [permissions_1.Permissions.IsOwner],
112
+ },
113
+ }));
114
+ server = (0, supertest_1.default)(app);
115
+ return [2 /*return*/];
116
+ }
117
+ });
118
+ }); });
119
+ (0, bun_test_1.describe)("anonymous food", function () {
120
+ (0, bun_test_1.it)("list", function () { return __awaiter(void 0, void 0, void 0, function () {
121
+ var res;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0: return [4 /*yield*/, server.get("/food").expect(200)];
125
+ case 1:
126
+ res = _a.sent();
127
+ (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
128
+ return [2 /*return*/];
129
+ }
130
+ });
131
+ }); });
132
+ (0, bun_test_1.it)("get", function () { return __awaiter(void 0, void 0, void 0, function () {
133
+ var res, res2;
134
+ return __generator(this, function (_a) {
135
+ switch (_a.label) {
136
+ case 0: return [4 /*yield*/, server.get("/food").expect(200)];
137
+ case 1:
138
+ res = _a.sent();
139
+ (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
140
+ return [4 /*yield*/, server.get("/food/".concat(res.body.data[0]._id)).expect(200)];
141
+ case 2:
142
+ res2 = _a.sent();
143
+ (0, bun_test_1.expect)(res.body.data[0]._id).toBe(res2.body.data._id);
144
+ return [2 /*return*/];
145
+ }
146
+ });
147
+ }); });
148
+ (0, bun_test_1.it)("post", function () { return __awaiter(void 0, void 0, void 0, function () {
149
+ var res;
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0: return [4 /*yield*/, server.post("/food").send({
153
+ calories: 15,
154
+ name: "Broccoli",
155
+ })];
156
+ case 1:
157
+ res = _a.sent();
158
+ (0, bun_test_1.expect)(res.status).toBe(405);
159
+ return [2 /*return*/];
160
+ }
161
+ });
162
+ }); });
163
+ (0, bun_test_1.it)("patch", function () { return __awaiter(void 0, void 0, void 0, function () {
164
+ var res, res2;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0: return [4 /*yield*/, server.get("/food")];
168
+ case 1:
169
+ res = _a.sent();
170
+ return [4 /*yield*/, server.patch("/food/".concat(res.body.data[0]._id)).send({
171
+ name: "Broccoli",
172
+ })];
173
+ case 2:
174
+ res2 = _a.sent();
175
+ (0, bun_test_1.expect)(res2.status).toBe(403);
176
+ return [2 /*return*/];
177
+ }
178
+ });
179
+ }); });
180
+ (0, bun_test_1.it)("delete", function () { return __awaiter(void 0, void 0, void 0, function () {
181
+ var res, res2;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0: return [4 /*yield*/, server.get("/food")];
185
+ case 1:
186
+ res = _a.sent();
187
+ return [4 /*yield*/, server.delete("/food/".concat(res.body.data[0]._id))];
188
+ case 2:
189
+ res2 = _a.sent();
190
+ (0, bun_test_1.expect)(res2.status).toBe(405);
191
+ return [2 /*return*/];
192
+ }
193
+ });
194
+ }); });
195
+ });
196
+ (0, bun_test_1.describe)("non admin food", function () {
197
+ var agent;
198
+ (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
202
+ case 1:
203
+ agent = _a.sent();
204
+ return [2 /*return*/];
205
+ }
206
+ });
207
+ }); });
208
+ (0, bun_test_1.it)("list", function () { return __awaiter(void 0, void 0, void 0, function () {
209
+ var res;
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0: return [4 /*yield*/, agent.get("/food").expect(200)];
213
+ case 1:
214
+ res = _a.sent();
215
+ (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
216
+ return [2 /*return*/];
217
+ }
218
+ });
219
+ }); });
220
+ (0, bun_test_1.it)("get", function () { return __awaiter(void 0, void 0, void 0, function () {
221
+ var res, res2;
222
+ return __generator(this, function (_a) {
223
+ switch (_a.label) {
224
+ case 0: return [4 /*yield*/, agent.get("/food").expect(200)];
225
+ case 1:
226
+ res = _a.sent();
227
+ (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
228
+ return [4 /*yield*/, server.get("/food/".concat(res.body.data[0]._id)).expect(200)];
229
+ case 2:
230
+ res2 = _a.sent();
231
+ (0, bun_test_1.expect)(res.body.data[0]._id).toBe(res2.body.data._id);
232
+ return [2 /*return*/];
233
+ }
234
+ });
235
+ }); });
236
+ (0, bun_test_1.it)("post", function () { return __awaiter(void 0, void 0, void 0, function () {
237
+ return __generator(this, function (_a) {
238
+ switch (_a.label) {
239
+ case 0: return [4 /*yield*/, agent
240
+ .post("/food")
241
+ .send({
242
+ calories: 15,
243
+ name: "Broccoli",
244
+ })
245
+ .expect(201)];
246
+ case 1:
247
+ _a.sent();
248
+ return [2 /*return*/];
249
+ }
250
+ });
251
+ }); });
252
+ (0, bun_test_1.it)("patch own item", function () { return __awaiter(void 0, void 0, void 0, function () {
253
+ var res, spinach, res2;
254
+ return __generator(this, function (_a) {
255
+ switch (_a.label) {
256
+ case 0: return [4 /*yield*/, agent.get("/food")];
257
+ case 1:
258
+ res = _a.sent();
259
+ spinach = res.body.data.find(function (food) { return food.name === "Spinach"; });
260
+ return [4 /*yield*/, agent
261
+ .patch("/food/".concat(spinach._id))
262
+ .send({
263
+ name: "Broccoli",
264
+ })
265
+ .expect(200)];
266
+ case 2:
267
+ res2 = _a.sent();
268
+ (0, bun_test_1.expect)(res2.body.data.name).toBe("Broccoli");
269
+ return [2 /*return*/];
270
+ }
271
+ });
272
+ }); });
273
+ (0, bun_test_1.it)("patch other item", function () { return __awaiter(void 0, void 0, void 0, function () {
274
+ var res, spinach;
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0: return [4 /*yield*/, agent.get("/food")];
278
+ case 1:
279
+ res = _a.sent();
280
+ spinach = res.body.data.find(function (food) { return food.name === "Apple"; });
281
+ return [4 /*yield*/, agent
282
+ .patch("/food/".concat(spinach._id))
283
+ .send({
284
+ name: "Broccoli",
285
+ })
286
+ .expect(403)];
287
+ case 2:
288
+ _a.sent();
289
+ return [2 /*return*/];
290
+ }
291
+ });
292
+ }); });
293
+ (0, bun_test_1.it)("delete", function () { return __awaiter(void 0, void 0, void 0, function () {
294
+ var res, res2;
295
+ return __generator(this, function (_a) {
296
+ switch (_a.label) {
297
+ case 0: return [4 /*yield*/, agent.get("/food")];
298
+ case 1:
299
+ res = _a.sent();
300
+ return [4 /*yield*/, agent.delete("/food/".concat(res.body.data[0]._id))];
301
+ case 2:
302
+ res2 = _a.sent();
303
+ (0, bun_test_1.expect)(res2.status).toBe(405);
304
+ return [2 /*return*/];
305
+ }
306
+ });
307
+ }); });
308
+ });
309
+ (0, bun_test_1.describe)("admin food", function () {
310
+ var agent;
311
+ (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
312
+ return __generator(this, function (_a) {
313
+ switch (_a.label) {
314
+ case 0: return [4 /*yield*/, (0, tests_1.authAsUser)(app, "admin")];
315
+ case 1:
316
+ agent = _a.sent();
317
+ return [2 /*return*/];
318
+ }
319
+ });
320
+ }); });
321
+ (0, bun_test_1.it)("list", function () { return __awaiter(void 0, void 0, void 0, function () {
322
+ var res;
323
+ return __generator(this, function (_a) {
324
+ switch (_a.label) {
325
+ case 0: return [4 /*yield*/, agent.get("/food")];
326
+ case 1:
327
+ res = _a.sent();
328
+ (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
329
+ return [2 /*return*/];
330
+ }
331
+ });
332
+ }); });
333
+ (0, bun_test_1.it)("get", function () { return __awaiter(void 0, void 0, void 0, function () {
334
+ var res, res2;
335
+ return __generator(this, function (_a) {
336
+ switch (_a.label) {
337
+ case 0: return [4 /*yield*/, agent.get("/food")];
338
+ case 1:
339
+ res = _a.sent();
340
+ (0, bun_test_1.expect)(res.body.data).toHaveLength(2);
341
+ return [4 /*yield*/, agent.get("/food/".concat(res.body.data[0]._id))];
342
+ case 2:
343
+ res2 = _a.sent();
344
+ (0, bun_test_1.expect)(res.body.data[0]._id).toBe(res2.body.data._id);
345
+ return [2 /*return*/];
346
+ }
347
+ });
348
+ }); });
349
+ (0, bun_test_1.it)("post", function () { return __awaiter(void 0, void 0, void 0, function () {
350
+ var res;
351
+ return __generator(this, function (_a) {
352
+ switch (_a.label) {
353
+ case 0: return [4 /*yield*/, agent.post("/food").send({
354
+ calories: 15,
355
+ name: "Broccoli",
356
+ })];
357
+ case 1:
358
+ res = _a.sent();
359
+ (0, bun_test_1.expect)(res.status).toBe(201);
360
+ return [2 /*return*/];
361
+ }
362
+ });
363
+ }); });
364
+ (0, bun_test_1.it)("patch", function () { return __awaiter(void 0, void 0, void 0, function () {
365
+ var res;
366
+ return __generator(this, function (_a) {
367
+ switch (_a.label) {
368
+ case 0: return [4 /*yield*/, agent.get("/food")];
369
+ case 1:
370
+ res = _a.sent();
371
+ return [4 /*yield*/, agent
372
+ .patch("/food/".concat(res.body.data[0]._id))
373
+ .send({
374
+ name: "Broccoli",
375
+ })
376
+ .expect(200)];
377
+ case 2:
378
+ _a.sent();
379
+ return [2 /*return*/];
380
+ }
381
+ });
382
+ }); });
383
+ (0, bun_test_1.it)("delete", function () { return __awaiter(void 0, void 0, void 0, function () {
384
+ var res;
385
+ return __generator(this, function (_a) {
386
+ switch (_a.label) {
387
+ case 0: return [4 /*yield*/, agent.get("/food")];
388
+ case 1:
389
+ res = _a.sent();
390
+ return [4 /*yield*/, agent.delete("/food/".concat(res.body.data[0]._id)).expect(204)];
391
+ case 2:
392
+ _a.sent();
393
+ return [2 /*return*/];
394
+ }
395
+ });
396
+ }); });
397
+ (0, bun_test_1.it)("handles validation errors", function () { return __awaiter(void 0, void 0, void 0, function () {
398
+ return __generator(this, function (_a) {
399
+ switch (_a.label) {
400
+ case 0: return [4 /*yield*/, agent
401
+ .post("/required")
402
+ .send({
403
+ about: "Whoops forgot required",
404
+ })
405
+ .expect(400)];
406
+ case 1:
407
+ _a.sent();
408
+ return [2 /*return*/];
409
+ }
410
+ });
411
+ }); });
412
+ });
413
+ });
@@ -0,0 +1,67 @@
1
+ import { type Document, type Schema, SchemaType, type SchemaTypeOptions } from "mongoose";
2
+ import { type APIErrorConstructor } from "./errors";
3
+ export interface BaseUser {
4
+ admin: boolean;
5
+ email: string;
6
+ }
7
+ export declare function baseUserPlugin(schema: Schema<any, any, any, any>): void;
8
+ /** For models with the isDeletedPlugin, extend this interface to add the appropriate fields. */
9
+ export interface IsDeleted {
10
+ deleted: boolean;
11
+ }
12
+ export declare function isDeletedPlugin(schema: Schema<any, any, any, any>, defaultValue?: boolean): void;
13
+ export declare function isDisabledPlugin(schema: Schema<any, any, any, any>, defaultValue?: boolean): void;
14
+ export interface CreatedDeleted {
15
+ updated: {
16
+ type: Date;
17
+ required: true;
18
+ };
19
+ created: {
20
+ type: Date;
21
+ required: true;
22
+ };
23
+ }
24
+ export declare function createdUpdatedPlugin(schema: Schema<any, any, any, any>): void;
25
+ export declare function firebaseJWTPlugin(schema: Schema): void;
26
+ /**
27
+ * This adds a static method `Model.findOneOrNone` to the schema. This should replace `Model.findOne` in most instances.
28
+ * `Model.findOne` should only be used with a unique index, but that's not apparent from the docs. Otherwise you can wind
29
+ * up with a random document that matches the query. The returns either null if no document matches, the actual
30
+ * document, or throws an exception if multiple are found.
31
+ * @param schema Mongoose Schema
32
+ */
33
+ export declare function findOneOrNone<T>(schema: Schema<T>): void;
34
+ /**
35
+ * This adds a static method `Model.findExactlyOne` to the schema. This or findOneOrNone should replace `Model.findOne`
36
+ * in most instances.
37
+ * `Model.findOne` should only be used with a unique index, but that's not apparent from the docs. Otherwise you can wind
38
+ * up with a random document that matches the query. The returns the one matching document, or throws an exception if
39
+ * multiple or none are found.
40
+ * @param schema Mongoose Schema
41
+ */
42
+ export declare function findExactlyOne<T>(schema: Schema<T>): void;
43
+ /**
44
+ * This adds a static method `Model.upsert` to the schema. This method will either update an existing document
45
+ * that matches the conditions or create a new document if none exists. It throws an error if multiple documents
46
+ * match the conditions to prevent ambiguous updates.
47
+ * @param schema Mongoose Schema
48
+ */
49
+ export declare function upsertPlugin<T>(schema: Schema<any, any, any, any>): void;
50
+ /** For models with the upsertPlugin, extend this interface to add the upsert static method. */
51
+ export interface HasUpsert<T> {
52
+ upsert(conditions: Record<string, any>, update: Record<string, any>): Promise<T>;
53
+ }
54
+ export interface FindOneOrNonePlugin<T> {
55
+ findOneOrNone(query: Record<string, any>, errorArgs?: Partial<APIErrorConstructor>): Promise<(Document & T) | null>;
56
+ }
57
+ export interface FindExactlyOnePlugin<T> {
58
+ findExactlyOne(query: Record<string, any>, errorArgs?: Partial<APIErrorConstructor>): Promise<Document & T>;
59
+ }
60
+ export declare class DateOnly extends SchemaType {
61
+ constructor(key: string, options: SchemaTypeOptions<any>);
62
+ handleSingle(val: any): Date | undefined;
63
+ $conditionalHandlers: any;
64
+ castForQuery($conditional: any, val: any, context: any): Date | undefined;
65
+ cast(val: any): Date | undefined;
66
+ get(val: any): this;
67
+ }