@terreno/api 0.31.0 → 56.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/dist/api.d.ts +10 -0
  2. package/dist/api.js +110 -361
  3. package/dist/auth.d.ts +26 -0
  4. package/dist/auth.js +121 -26
  5. package/dist/betterAuth.d.ts +5 -0
  6. package/dist/betterAuthSetup.js +23 -4
  7. package/dist/docLoader.js +12 -9
  8. package/dist/errors.d.ts +13 -0
  9. package/dist/errors.js +29 -1
  10. package/dist/index.d.ts +17 -1
  11. package/dist/index.js +29 -1
  12. package/dist/middleware.d.ts +7 -0
  13. package/dist/middleware.js +16 -1
  14. package/dist/openApiCompat.d.ts +10 -1
  15. package/dist/openApiCompat.js +115 -47
  16. package/dist/permissions.d.ts +27 -0
  17. package/dist/permissions.js +42 -1
  18. package/dist/plugins.d.ts +13 -0
  19. package/dist/plugins.js +47 -1
  20. package/dist/realtime/changeStreamWatcher.d.ts +100 -3
  21. package/dist/realtime/changeStreamWatcher.js +542 -137
  22. package/dist/realtime/realtimeApp.d.ts +2 -0
  23. package/dist/realtime/realtimeApp.js +83 -27
  24. package/dist/realtime/sessionRevalidation.d.ts +90 -0
  25. package/dist/realtime/sessionRevalidation.js +438 -0
  26. package/dist/realtime/socketAuth.d.ts +97 -0
  27. package/dist/realtime/socketAuth.js +272 -0
  28. package/dist/realtime/socketUser.d.ts +54 -0
  29. package/dist/realtime/socketUser.js +75 -5
  30. package/dist/realtime/types.d.ts +54 -0
  31. package/dist/secretProviders.d.ts +23 -0
  32. package/dist/secretProviders.js +9 -3
  33. package/dist/sync/executors.d.ts +198 -0
  34. package/dist/sync/executors.js +670 -0
  35. package/dist/sync/loadHarness.js +807 -0
  36. package/dist/sync/models.d.ts +216 -0
  37. package/dist/sync/models.js +644 -0
  38. package/dist/sync/mutationHandler.d.ts +97 -0
  39. package/dist/sync/mutationHandler.js +886 -0
  40. package/dist/sync/registry.d.ts +73 -0
  41. package/dist/sync/registry.js +223 -0
  42. package/dist/sync/routes.d.ts +62 -0
  43. package/dist/sync/routes.js +936 -0
  44. package/dist/sync/scripts/compactTombstones.d.ts +47 -0
  45. package/dist/sync/scripts/compactTombstones.js +270 -0
  46. package/dist/sync/serialize.d.ts +20 -0
  47. package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
  48. package/dist/sync/socketHandlers.d.ts +54 -0
  49. package/dist/sync/socketHandlers.js +470 -0
  50. package/dist/sync/streams.d.ts +85 -0
  51. package/dist/sync/streams.js +221 -0
  52. package/dist/sync/syncApp.d.ts +29 -0
  53. package/dist/sync/syncApp.js +44 -0
  54. package/dist/sync/syncBatch.d.ts +71 -0
  55. package/dist/sync/syncBatch.js +252 -0
  56. package/dist/sync/syncSeqPlugin.d.ts +8 -0
  57. package/dist/sync/syncSeqPlugin.js +899 -0
  58. package/dist/sync/types.d.ts +254 -0
  59. package/dist/sync/types.js +9 -0
  60. package/dist/terrenoApp.js +90 -27
  61. package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
  62. package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
  63. package/package.json +7 -6
  64. package/src/__tests__/openApiCompat.test.ts +20 -0
  65. package/src/api.errors.test.ts +32 -23
  66. package/src/api.test.ts +12 -0
  67. package/src/api.ts +87 -296
  68. package/src/auth.test.ts +202 -0
  69. package/src/auth.ts +134 -23
  70. package/src/betterAuth.ts +6 -0
  71. package/src/betterAuthSetup.test.ts +34 -0
  72. package/src/betterAuthSetup.ts +20 -1
  73. package/src/configuration.test.ts +59 -38
  74. package/src/configurationPlugin.test.ts +72 -42
  75. package/src/docLoader.ts +3 -1
  76. package/src/errors.ts +33 -0
  77. package/src/expressServer.test.ts +7 -1
  78. package/src/index.ts +42 -0
  79. package/src/middleware.test.ts +56 -1
  80. package/src/middleware.ts +15 -0
  81. package/src/openApiCompat.ts +99 -45
  82. package/src/permissions.test.ts +101 -17
  83. package/src/permissions.ts +49 -0
  84. package/src/plugins.test.ts +64 -0
  85. package/src/plugins.ts +56 -0
  86. package/src/realtime/changeStreamWatcher.ts +552 -114
  87. package/src/realtime/realtime.test.ts +157 -0
  88. package/src/realtime/realtimeApp.ts +82 -14
  89. package/src/realtime/realtimeAppSetup.test.ts +25 -27
  90. package/src/realtime/sessionRevalidation.test.ts +423 -0
  91. package/src/realtime/sessionRevalidation.ts +273 -0
  92. package/src/realtime/socketAuth.test.ts +355 -0
  93. package/src/realtime/socketAuth.ts +228 -0
  94. package/src/realtime/socketUser.ts +69 -0
  95. package/src/realtime/types.ts +54 -0
  96. package/src/secretProviders.test.ts +7 -1
  97. package/src/secretProviders.ts +15 -3
  98. package/src/secretProvidersGcpClient.test.ts +66 -0
  99. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  100. package/src/sync/executors.test.ts +882 -0
  101. package/src/sync/executors.ts +705 -0
  102. package/src/sync/integration.test.ts +1160 -0
  103. package/src/sync/loadHarness.ts +618 -0
  104. package/src/sync/models.ts +641 -0
  105. package/src/sync/mutationHandler.test.ts +1252 -0
  106. package/src/sync/mutationHandler.ts +850 -0
  107. package/src/sync/registry.ts +232 -0
  108. package/src/sync/routes.ts +812 -0
  109. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  110. package/src/sync/scripts/compactTombstones.ts +145 -0
  111. package/src/sync/serialize.ts +48 -0
  112. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  113. package/src/sync/socketHandlers.ts +320 -0
  114. package/src/sync/streams.ts +188 -0
  115. package/src/sync/sync.test.ts +582 -0
  116. package/src/sync/syncApp.ts +44 -0
  117. package/src/sync/syncBatch.ts +219 -0
  118. package/src/sync/syncFrontier.test.ts +494 -0
  119. package/src/sync/syncPhaseC.test.ts +718 -0
  120. package/src/sync/syncRoutes.test.ts +865 -0
  121. package/src/sync/syncSeqPlugin.ts +730 -0
  122. package/src/sync/syncSocket.test.ts +1440 -0
  123. package/src/sync/types.ts +270 -0
  124. package/src/terrenoApp.ts +37 -17
  125. package/src/tests/bunSetup.ts +8 -0
  126. package/tsconfig.json +4 -4
  127. package/tsconfig.typedoc.json +7 -1
  128. package/dist/__tests__/openApiCompat.test.js +0 -317
  129. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  130. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  131. package/dist/actions.openApi.test.d.ts +0 -1
  132. package/dist/actions.openApi.test.js +0 -253
  133. package/dist/actions.test.d.ts +0 -1
  134. package/dist/actions.test.js +0 -1087
  135. package/dist/api.arrayOperations.test.d.ts +0 -1
  136. package/dist/api.arrayOperations.test.js +0 -878
  137. package/dist/api.asyncHandler.test.d.ts +0 -1
  138. package/dist/api.asyncHandler.test.js +0 -236
  139. package/dist/api.coverage.test.d.ts +0 -1
  140. package/dist/api.coverage.test.js +0 -192
  141. package/dist/api.errorPaths.test.d.ts +0 -1
  142. package/dist/api.errorPaths.test.js +0 -887
  143. package/dist/api.errors.test.d.ts +0 -1
  144. package/dist/api.errors.test.js +0 -185
  145. package/dist/api.hooks.test.d.ts +0 -1
  146. package/dist/api.hooks.test.js +0 -950
  147. package/dist/api.query.test.d.ts +0 -1
  148. package/dist/api.query.test.js +0 -948
  149. package/dist/api.test.d.ts +0 -1
  150. package/dist/api.test.js +0 -2820
  151. package/dist/auth.compile.test.d.ts +0 -1
  152. package/dist/auth.compile.test.js +0 -201
  153. package/dist/auth.coverage.test.d.ts +0 -1
  154. package/dist/auth.coverage.test.js +0 -202
  155. package/dist/auth.test.d.ts +0 -1
  156. package/dist/auth.test.js +0 -2286
  157. package/dist/betterAuth.test.d.ts +0 -1
  158. package/dist/betterAuth.test.js +0 -181
  159. package/dist/betterAuthApp.test.d.ts +0 -1
  160. package/dist/betterAuthApp.test.js +0 -242
  161. package/dist/betterAuthSetup.test.d.ts +0 -1
  162. package/dist/betterAuthSetup.test.js +0 -762
  163. package/dist/config.test.d.ts +0 -1
  164. package/dist/config.test.js +0 -353
  165. package/dist/configuration.test.d.ts +0 -1
  166. package/dist/configuration.test.js +0 -980
  167. package/dist/configurationPlugin.test.d.ts +0 -1
  168. package/dist/configurationPlugin.test.js +0 -827
  169. package/dist/consentApp.test.d.ts +0 -1
  170. package/dist/consentApp.test.js +0 -1411
  171. package/dist/docLoader.test.d.ts +0 -1
  172. package/dist/docLoader.test.js +0 -137
  173. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  174. package/dist/envConfigurationPlugin.test.js +0 -369
  175. package/dist/errors.test.d.ts +0 -1
  176. package/dist/errors.test.js +0 -607
  177. package/dist/expressServer.test.d.ts +0 -1
  178. package/dist/expressServer.test.js +0 -1249
  179. package/dist/githubAuth.test.d.ts +0 -1
  180. package/dist/githubAuth.test.js +0 -1142
  181. package/dist/httpClient.test.d.ts +0 -1
  182. package/dist/httpClient.test.js +0 -1471
  183. package/dist/logger.test.d.ts +0 -1
  184. package/dist/logger.test.js +0 -685
  185. package/dist/middleware.test.d.ts +0 -1
  186. package/dist/middleware.test.js +0 -241
  187. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  188. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  189. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  190. package/dist/notifiers/slackNotifier.test.js +0 -297
  191. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  192. package/dist/notifiers/zoomNotifier.test.js +0 -373
  193. package/dist/openApi.test.d.ts +0 -1
  194. package/dist/openApi.test.js +0 -620
  195. package/dist/openApiBuilder.test.d.ts +0 -1
  196. package/dist/openApiBuilder.test.js +0 -599
  197. package/dist/openApiEtag.test.d.ts +0 -1
  198. package/dist/openApiEtag.test.js +0 -86
  199. package/dist/openApiValidator.test.d.ts +0 -1
  200. package/dist/openApiValidator.test.js +0 -795
  201. package/dist/permissions.middleware.test.d.ts +0 -1
  202. package/dist/permissions.middleware.test.js +0 -308
  203. package/dist/permissions.test.d.ts +0 -1
  204. package/dist/permissions.test.js +0 -439
  205. package/dist/plugins.test.d.ts +0 -1
  206. package/dist/plugins.test.js +0 -902
  207. package/dist/populate.test.d.ts +0 -1
  208. package/dist/populate.test.js +0 -370
  209. package/dist/realtime/realtime.test.d.ts +0 -10
  210. package/dist/realtime/realtime.test.js +0 -4213
  211. package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
  212. package/dist/realtime/realtimeAppSetup.test.js +0 -213
  213. package/dist/requestContext.test.d.ts +0 -1
  214. package/dist/requestContext.test.js +0 -412
  215. package/dist/scriptRunner.test.d.ts +0 -1
  216. package/dist/scriptRunner.test.js +0 -386
  217. package/dist/secretProviders.test.d.ts +0 -1
  218. package/dist/secretProviders.test.js +0 -726
  219. package/dist/syncConsents.test.d.ts +0 -1
  220. package/dist/syncConsents.test.js +0 -522
  221. package/dist/terrenoApp.test.d.ts +0 -1
  222. package/dist/terrenoApp.test.js +0 -489
  223. package/dist/tests/bunSetup.d.ts +0 -1
  224. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  225. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  226. package/dist/tests/testEnv.d.ts +0 -0
  227. package/dist/tests/testEnv.js +0 -6
  228. package/dist/transformers.test.d.ts +0 -1
  229. package/dist/transformers.test.js +0 -423
  230. package/dist/utils.test.d.ts +0 -1
  231. package/dist/utils.test.js +0 -242
  232. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1 +0,0 @@
1
- export {};
@@ -1,236 +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 express_1 = __importDefault(require("express"));
44
- var supertest_1 = __importDefault(require("supertest"));
45
- var api_1 = require("./api");
46
- var openApiValidator_1 = require("./openApiValidator");
47
- (0, bun_test_1.afterEach)(function () {
48
- (0, openApiValidator_1.resetOpenApiValidatorConfig)();
49
- });
50
- var createApp = function () {
51
- var app = (0, express_1.default)();
52
- app.use(express_1.default.json());
53
- return app;
54
- };
55
- var errorHandler = function (err, _req, res, _next) {
56
- res.status(err.status || 500).json({ error: err.title || err.message });
57
- };
58
- (0, bun_test_1.describe)("asyncHandler with bodySchema validation", function () {
59
- (0, bun_test_1.it)("validates and accepts a conforming body", function () { return __awaiter(void 0, void 0, void 0, function () {
60
- var app, res;
61
- return __generator(this, function (_a) {
62
- switch (_a.label) {
63
- case 0:
64
- (0, openApiValidator_1.configureOpenApiValidator)({});
65
- app = createApp();
66
- app.post("/test", (0, api_1.asyncHandler)(function (_req, res) { return __awaiter(void 0, void 0, void 0, function () {
67
- return __generator(this, function (_a) {
68
- res.json({ ok: true });
69
- return [2 /*return*/];
70
- });
71
- }); }, {
72
- bodySchema: { name: { required: true, type: "string" } },
73
- validate: true,
74
- }));
75
- app.use(errorHandler);
76
- return [4 /*yield*/, (0, supertest_1.default)(app).post("/test").send({ name: "hello" }).expect(200)];
77
- case 1:
78
- res = _a.sent();
79
- (0, bun_test_1.expect)(res.body.ok).toBe(true);
80
- return [2 /*return*/];
81
- }
82
- });
83
- }); });
84
- (0, bun_test_1.it)("rejects a body missing a required field", function () { return __awaiter(void 0, void 0, void 0, function () {
85
- var app;
86
- return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0:
89
- (0, openApiValidator_1.configureOpenApiValidator)({});
90
- app = createApp();
91
- app.post("/test", (0, api_1.asyncHandler)(function (_req, res) { return __awaiter(void 0, void 0, void 0, function () {
92
- return __generator(this, function (_a) {
93
- res.json({ ok: true });
94
- return [2 /*return*/];
95
- });
96
- }); }, {
97
- bodySchema: { name: { required: true, type: "string" } },
98
- validate: true,
99
- }));
100
- app.use(errorHandler);
101
- return [4 /*yield*/, (0, supertest_1.default)(app).post("/test").send({}).expect(400)];
102
- case 1:
103
- _a.sent();
104
- return [2 /*return*/];
105
- }
106
- });
107
- }); });
108
- (0, bun_test_1.it)("skips body validation when validate is false", function () { return __awaiter(void 0, void 0, void 0, function () {
109
- var app, res;
110
- return __generator(this, function (_a) {
111
- switch (_a.label) {
112
- case 0:
113
- (0, openApiValidator_1.configureOpenApiValidator)({});
114
- app = createApp();
115
- app.post("/test", (0, api_1.asyncHandler)(function (_req, res) { return __awaiter(void 0, void 0, void 0, function () {
116
- return __generator(this, function (_a) {
117
- res.json({ ok: true });
118
- return [2 /*return*/];
119
- });
120
- }); }, {
121
- bodySchema: { name: { required: true, type: "string" } },
122
- validate: false,
123
- }));
124
- app.use(errorHandler);
125
- return [4 /*yield*/, (0, supertest_1.default)(app).post("/test").send({}).expect(200)];
126
- case 1:
127
- res = _a.sent();
128
- (0, bun_test_1.expect)(res.body.ok).toBe(true);
129
- return [2 /*return*/];
130
- }
131
- });
132
- }); });
133
- });
134
- (0, bun_test_1.describe)("asyncHandler with querySchema validation", function () {
135
- (0, bun_test_1.it)("validates and accepts conforming query params", function () { return __awaiter(void 0, void 0, void 0, function () {
136
- var app, res;
137
- return __generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0:
140
- (0, openApiValidator_1.configureOpenApiValidator)({});
141
- app = createApp();
142
- app.get("/test", (0, api_1.asyncHandler)(function (_req, res) { return __awaiter(void 0, void 0, void 0, function () {
143
- return __generator(this, function (_a) {
144
- res.json({ ok: true });
145
- return [2 /*return*/];
146
- });
147
- }); }, {
148
- querySchema: { page: { type: "integer" } },
149
- validate: true,
150
- }));
151
- app.use(errorHandler);
152
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/test?page=1").expect(200)];
153
- case 1:
154
- res = _a.sent();
155
- (0, bun_test_1.expect)(res.body.ok).toBe(true);
156
- return [2 /*return*/];
157
- }
158
- });
159
- }); });
160
- (0, bun_test_1.it)("rejects invalid query params", function () { return __awaiter(void 0, void 0, void 0, function () {
161
- var app;
162
- return __generator(this, function (_a) {
163
- switch (_a.label) {
164
- case 0:
165
- (0, openApiValidator_1.configureOpenApiValidator)({});
166
- app = createApp();
167
- app.get("/test", (0, api_1.asyncHandler)(function (_req, res) { return __awaiter(void 0, void 0, void 0, function () {
168
- return __generator(this, function (_a) {
169
- res.json({ ok: true });
170
- return [2 /*return*/];
171
- });
172
- }); }, {
173
- querySchema: { page: { required: true, type: "integer" } },
174
- validate: true,
175
- }));
176
- app.use(errorHandler);
177
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/test").expect(400)];
178
- case 1:
179
- _a.sent();
180
- return [2 /*return*/];
181
- }
182
- });
183
- }); });
184
- });
185
- (0, bun_test_1.describe)("asyncHandler with both schemas", function () {
186
- (0, bun_test_1.it)("runs both body and query validators sequentially", function () { return __awaiter(void 0, void 0, void 0, function () {
187
- var app, res;
188
- return __generator(this, function (_a) {
189
- switch (_a.label) {
190
- case 0:
191
- (0, openApiValidator_1.configureOpenApiValidator)({});
192
- app = createApp();
193
- app.post("/test", (0, api_1.asyncHandler)(function (_req, res) { return __awaiter(void 0, void 0, void 0, function () {
194
- return __generator(this, function (_a) {
195
- res.json({ ok: true });
196
- return [2 /*return*/];
197
- });
198
- }); }, {
199
- bodySchema: { name: { required: true, type: "string" } },
200
- querySchema: { page: { type: "integer" } },
201
- validate: true,
202
- }));
203
- app.use(errorHandler);
204
- return [4 /*yield*/, (0, supertest_1.default)(app).post("/test?page=1").send({ name: "hi" }).expect(200)];
205
- case 1:
206
- res = _a.sent();
207
- (0, bun_test_1.expect)(res.body.ok).toBe(true);
208
- return [2 /*return*/];
209
- }
210
- });
211
- }); });
212
- (0, bun_test_1.it)("forwards handler errors through next", function () { return __awaiter(void 0, void 0, void 0, function () {
213
- var app, res;
214
- return __generator(this, function (_a) {
215
- switch (_a.label) {
216
- case 0:
217
- (0, openApiValidator_1.configureOpenApiValidator)({});
218
- app = createApp();
219
- app.post("/test", (0, api_1.asyncHandler)(function () { return __awaiter(void 0, void 0, void 0, function () {
220
- return __generator(this, function (_a) {
221
- throw new Error("handler boom");
222
- });
223
- }); }, {
224
- bodySchema: { name: { type: "string" } },
225
- validate: true,
226
- }));
227
- app.use(errorHandler);
228
- return [4 /*yield*/, (0, supertest_1.default)(app).post("/test").send({ name: "ok" }).expect(500)];
229
- case 1:
230
- res = _a.sent();
231
- (0, bun_test_1.expect)(res.body.error).toBe("handler boom");
232
- return [2 /*return*/];
233
- }
234
- });
235
- }); });
236
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,192 +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 __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 mongoose_1 = __importDefault(require("mongoose"));
60
- var supertest_1 = __importDefault(require("supertest"));
61
- var api_1 = require("./api");
62
- var auth_1 = require("./auth");
63
- var permissions_1 = require("./permissions");
64
- var tests_1 = require("./tests");
65
- // A model without the isDeleted plugin so deletes call doc.deleteOne(). The
66
- // document delete hook throws to exercise the hard-delete error branch.
67
- var explosiveSchema = new mongoose_1.default.Schema({
68
- name: { description: "The name of the item", type: String },
69
- });
70
- explosiveSchema.pre("deleteOne", { document: true, query: false }, function () {
71
- throw new Error("deleteOne exploded");
72
- });
73
- var ExplosiveModel = mongoose_1.default.model("ExplosiveCoverage", explosiveSchema);
74
- (0, bun_test_1.describe)("modelRouter error path coverage", function () {
75
- var server;
76
- var app;
77
- var admin;
78
- var apple;
79
- (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
80
- var _a;
81
- return __generator(this, function (_b) {
82
- switch (_b.label) {
83
- case 0: return [4 /*yield*/, (0, tests_1.setupDb)()];
84
- case 1:
85
- _a = __read.apply(void 0, [_b.sent(), 1]), admin = _a[0];
86
- return [4 /*yield*/, tests_1.FoodModel.create({
87
- calories: 100,
88
- categories: [
89
- { name: "Fruit", show: true },
90
- { name: "Popular", show: false },
91
- ],
92
- created: new Date("2021-12-03T00:00:30.000Z"),
93
- hidden: false,
94
- name: "Apple",
95
- ownerId: admin._id,
96
- tags: ["healthy", "cheap"],
97
- })];
98
- case 2:
99
- apple = _b.sent();
100
- app = (0, tests_1.getBaseServer)();
101
- (0, auth_1.setupAuth)(app, tests_1.UserModel);
102
- (0, auth_1.addAuthRoutes)(app, tests_1.UserModel);
103
- return [2 /*return*/];
104
- }
105
- });
106
- }); });
107
- (0, bun_test_1.it)("returns 400 when an array operation transformer throws a non-APIError", function () { return __awaiter(void 0, void 0, void 0, function () {
108
- var res;
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
111
- case 0:
112
- app.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, {
113
- allowAnonymous: true,
114
- permissions: {
115
- create: [permissions_1.Permissions.IsAny],
116
- delete: [permissions_1.Permissions.IsAny],
117
- list: [permissions_1.Permissions.IsAny],
118
- read: [permissions_1.Permissions.IsAny],
119
- update: [permissions_1.Permissions.IsAny],
120
- },
121
- transformer: {
122
- transform: function () {
123
- throw new Error("array transform boom");
124
- },
125
- },
126
- }));
127
- server = (0, supertest_1.default)(app);
128
- return [4 /*yield*/, server.post("/food/".concat(apple._id, "/tags")).send({ tags: "organic" }).expect(403)];
129
- case 1:
130
- res = _a.sent();
131
- (0, bun_test_1.expect)(res.body.title).toBe("Transform error");
132
- (0, bun_test_1.expect)(res.body.detail).toContain("array transform boom");
133
- return [2 /*return*/];
134
- }
135
- });
136
- }); });
137
- (0, bun_test_1.it)("returns 400 when saving an array operation fails validation", function () { return __awaiter(void 0, void 0, void 0, function () {
138
- var res;
139
- return __generator(this, function (_a) {
140
- switch (_a.label) {
141
- case 0:
142
- app.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, {
143
- allowAnonymous: true,
144
- permissions: {
145
- create: [permissions_1.Permissions.IsAny],
146
- delete: [permissions_1.Permissions.IsAny],
147
- list: [permissions_1.Permissions.IsAny],
148
- read: [permissions_1.Permissions.IsAny],
149
- update: [permissions_1.Permissions.IsAny],
150
- },
151
- }));
152
- server = (0, supertest_1.default)(app);
153
- return [4 /*yield*/, server
154
- .post("/food/".concat(apple._id, "/eatenBy"))
155
- .send({ eatenBy: "not-an-object-id" })
156
- .expect(400)];
157
- case 1:
158
- res = _a.sent();
159
- (0, bun_test_1.expect)(res.body.title).toBe("Validation failed");
160
- (0, bun_test_1.expect)(res.body.meta.fields["eatenBy.0"]).toContain("ObjectId");
161
- return [2 /*return*/];
162
- }
163
- });
164
- }); });
165
- (0, bun_test_1.it)("returns 400 when a hard delete (no isDeleted plugin) fails", function () { return __awaiter(void 0, void 0, void 0, function () {
166
- var doc, res;
167
- return __generator(this, function (_a) {
168
- switch (_a.label) {
169
- case 0: return [4 /*yield*/, ExplosiveModel.create({ name: "boom" })];
170
- case 1:
171
- doc = _a.sent();
172
- app.use("/explosive", (0, api_1.modelRouter)(ExplosiveModel, {
173
- allowAnonymous: true,
174
- permissions: {
175
- create: [permissions_1.Permissions.IsAny],
176
- delete: [permissions_1.Permissions.IsAny],
177
- list: [permissions_1.Permissions.IsAny],
178
- read: [permissions_1.Permissions.IsAny],
179
- update: [permissions_1.Permissions.IsAny],
180
- },
181
- }));
182
- server = (0, supertest_1.default)(app);
183
- return [4 /*yield*/, server.delete("/explosive/".concat(doc._id)).expect(400)];
184
- case 2:
185
- res = _a.sent();
186
- (0, bun_test_1.expect)(res.body.title).toBe("Delete error");
187
- (0, bun_test_1.expect)(res.body.detail).toContain("deleteOne exploded");
188
- return [2 /*return*/];
189
- }
190
- });
191
- }); });
192
- });
@@ -1 +0,0 @@
1
- export {};