@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,599 +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 openApiBuilder_1 = require("./openApiBuilder");
57
- var permissions_1 = require("./permissions");
58
- var terrenoApp_1 = require("./terrenoApp");
59
- var tests_1 = require("./tests");
60
- function addRoutesWithBuilder(router, options) {
61
- var _this = this;
62
- // Add a custom endpoint using the OpenApiMiddlewareBuilder
63
- var statsMiddleware = (0, openApiBuilder_1.createOpenApiBuilder)(options !== null && options !== void 0 ? options : {})
64
- .withTags(["Stats"])
65
- .withSummary("Get food statistics")
66
- .withOperationId("getFoodStats")
67
- .withDescription("Returns aggregated statistics about food items")
68
- .withQueryParameter("category", { type: "string" }, {
69
- description: "Filter by food category",
70
- required: false,
71
- })
72
- .withResponse(200, {
73
- avgCalories: { description: "Average calories", type: "number" },
74
- count: { description: "Total number of food items", type: "number" },
75
- })
76
- .build();
77
- router.get("/food/stats", statsMiddleware, function (_req, res) { return __awaiter(_this, void 0, void 0, function () {
78
- return __generator(this, function (_a) {
79
- res.json({ avgCalories: 250, count: 10 });
80
- return [2 /*return*/];
81
- });
82
- }); });
83
- // Add endpoint with request body
84
- var createReportMiddleware = (0, openApiBuilder_1.createOpenApiBuilder)(options !== null && options !== void 0 ? options : {})
85
- .withTags(["Reports"])
86
- .withSummary("Create a food report")
87
- .withDescription("Generates a report based on provided criteria")
88
- .withRequestBody({
89
- endDate: {
90
- description: "Report end date",
91
- format: "date",
92
- required: true,
93
- type: "string",
94
- },
95
- includeDeleted: {
96
- description: "Whether to include deleted items",
97
- type: "boolean",
98
- },
99
- startDate: {
100
- description: "Report start date",
101
- format: "date",
102
- required: true,
103
- type: "string",
104
- },
105
- })
106
- .withResponse(201, {
107
- reportId: { description: "Generated report ID", type: "string" },
108
- }, { description: "Report created successfully" })
109
- .build();
110
- router.post("/food/reports", createReportMiddleware, function (_req, res) { return __awaiter(_this, void 0, void 0, function () {
111
- return __generator(this, function (_a) {
112
- res.status(201).json({ reportId: "report-123" });
113
- return [2 /*return*/];
114
- });
115
- }); });
116
- // Add endpoint with array response
117
- var listCategoriesMiddleware = (0, openApiBuilder_1.createOpenApiBuilder)(options !== null && options !== void 0 ? options : {})
118
- .withTags(["Categories"])
119
- .withSummary("List food categories")
120
- .withArrayResponse(200, {
121
- count: { description: "Number of items in category", type: "number" },
122
- id: { description: "Category ID", type: "string" },
123
- name: { description: "Category name", type: "string" },
124
- }, { description: "List of categories" })
125
- .build();
126
- router.get("/food/categories", listCategoriesMiddleware, function (_req, res) { return __awaiter(_this, void 0, void 0, function () {
127
- return __generator(this, function (_a) {
128
- res.json([
129
- { count: 5, id: "1", name: "Fruits" },
130
- { count: 3, id: "2", name: "Vegetables" },
131
- ]);
132
- return [2 /*return*/];
133
- });
134
- }); });
135
- // Add endpoint with path parameter
136
- var getCategoryMiddleware = (0, openApiBuilder_1.createOpenApiBuilder)(options !== null && options !== void 0 ? options : {})
137
- .withTags(["Categories"])
138
- .withSummary("Get category by ID")
139
- .withPathParameter("categoryId", { type: "string" }, {
140
- description: "The category identifier",
141
- })
142
- .withResponse(200, {
143
- id: { type: "string" },
144
- name: { type: "string" },
145
- })
146
- .withResponse(404, "Category not found")
147
- .build();
148
- router.get("/food/categories/:categoryId", getCategoryMiddleware, function (req, res) { return __awaiter(_this, void 0, void 0, function () {
149
- return __generator(this, function (_a) {
150
- res.json({ id: req.params.categoryId, name: "Fruits" });
151
- return [2 /*return*/];
152
- });
153
- }); });
154
- // Standard modelRouter for food
155
- router.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, __assign(__assign({}, options), { allowAnonymous: true, permissions: {
156
- create: [permissions_1.Permissions.IsAny],
157
- delete: [permissions_1.Permissions.IsAny],
158
- list: [permissions_1.Permissions.IsAny],
159
- read: [permissions_1.Permissions.IsAny],
160
- update: [permissions_1.Permissions.IsAny],
161
- } })));
162
- }
163
- (0, bun_test_1.describe)("OpenApiMiddlewareBuilder", function () {
164
- var server;
165
- var app;
166
- (0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
167
- return __generator(this, function (_a) {
168
- process.env.REFRESH_TOKEN_SECRET = "testsecret1234";
169
- process.env.ENABLE_SWAGGER = "true";
170
- app = new terrenoApp_1.TerrenoApp({
171
- configureApp: addRoutesWithBuilder,
172
- skipListen: true,
173
- userModel: tests_1.UserModel,
174
- }).build();
175
- return [2 /*return*/];
176
- });
177
- }); });
178
- (0, bun_test_1.describe)("builder pattern", function () {
179
- (0, bun_test_1.it)("returns a builder instance from createOpenApiBuilder", function () {
180
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({});
181
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
182
- });
183
- (0, bun_test_1.it)("supports method chaining", function () {
184
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({});
185
- var result = builder
186
- .withTags(["test"])
187
- .withSummary("Test summary")
188
- .withDescription("Test description");
189
- (0, bun_test_1.expect)(result).toBe(builder);
190
- });
191
- (0, bun_test_1.it)("returns noop middleware when openApi is not configured", function () {
192
- var middleware = (0, openApiBuilder_1.createOpenApiBuilder)({}).build();
193
- (0, bun_test_1.expect)(typeof middleware).toBe("function");
194
- (0, bun_test_1.expect)(middleware.length).toBe(3); // Express middleware signature
195
- });
196
- });
197
- (0, bun_test_1.describe)("OpenAPI spec generation", function () {
198
- (0, bun_test_1.it)("includes custom endpoint with query parameter in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
199
- var res, statsPath, categoryParam;
200
- return __generator(this, function (_a) {
201
- switch (_a.label) {
202
- case 0:
203
- server = (0, supertest_1.default)(app);
204
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
205
- case 1:
206
- res = _a.sent();
207
- statsPath = res.body.paths["/food/stats"];
208
- (0, bun_test_1.expect)(statsPath).toBeDefined();
209
- (0, bun_test_1.expect)(statsPath.get).toBeDefined();
210
- (0, bun_test_1.expect)(statsPath.get.tags).toContain("Stats");
211
- (0, bun_test_1.expect)(statsPath.get.summary).toBe("Get food statistics");
212
- (0, bun_test_1.expect)(statsPath.get.description).toBe("Returns aggregated statistics about food items");
213
- categoryParam = statsPath.get.parameters.find(function (p) { return p.name === "category"; });
214
- (0, bun_test_1.expect)(categoryParam).toBeDefined();
215
- (0, bun_test_1.expect)(categoryParam.in).toBe("query");
216
- (0, bun_test_1.expect)(categoryParam.schema.type).toBe("string");
217
- (0, bun_test_1.expect)(categoryParam.description).toBe("Filter by food category");
218
- (0, bun_test_1.expect)(categoryParam.required).toBe(false);
219
- return [2 /*return*/];
220
- }
221
- });
222
- }); });
223
- (0, bun_test_1.it)("includes the explicit operationId in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
224
- var res, statsPath;
225
- return __generator(this, function (_a) {
226
- switch (_a.label) {
227
- case 0:
228
- server = (0, supertest_1.default)(app);
229
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
230
- case 1:
231
- res = _a.sent();
232
- statsPath = res.body.paths["/food/stats"];
233
- (0, bun_test_1.expect)(statsPath.get.operationId).toBe("getFoodStats");
234
- return [2 /*return*/];
235
- }
236
- });
237
- }); });
238
- (0, bun_test_1.it)("includes request body schema in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
239
- var res, reportsPath, requestBody, schema;
240
- return __generator(this, function (_a) {
241
- switch (_a.label) {
242
- case 0:
243
- server = (0, supertest_1.default)(app);
244
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
245
- case 1:
246
- res = _a.sent();
247
- reportsPath = res.body.paths["/food/reports"];
248
- (0, bun_test_1.expect)(reportsPath).toBeDefined();
249
- (0, bun_test_1.expect)(reportsPath.post).toBeDefined();
250
- (0, bun_test_1.expect)(reportsPath.post.tags).toContain("Reports");
251
- requestBody = reportsPath.post.requestBody;
252
- (0, bun_test_1.expect)(requestBody).toBeDefined();
253
- (0, bun_test_1.expect)(requestBody.required).toBe(true);
254
- schema = requestBody.content["application/json"].schema;
255
- (0, bun_test_1.expect)(schema.type).toBe("object");
256
- (0, bun_test_1.expect)(schema.properties.startDate.type).toBe("string");
257
- (0, bun_test_1.expect)(schema.properties.startDate.format).toBe("date");
258
- (0, bun_test_1.expect)(schema.properties.endDate.type).toBe("string");
259
- (0, bun_test_1.expect)(schema.properties.includeDeleted.type).toBe("boolean");
260
- (0, bun_test_1.expect)(schema.required).toContain("startDate");
261
- (0, bun_test_1.expect)(schema.required).toContain("endDate");
262
- (0, bun_test_1.expect)(schema.required).not.toContain("includeDeleted");
263
- return [2 /*return*/];
264
- }
265
- });
266
- }); });
267
- (0, bun_test_1.it)("includes response schema in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
268
- var res, statsPath, response200, schema;
269
- return __generator(this, function (_a) {
270
- switch (_a.label) {
271
- case 0:
272
- server = (0, supertest_1.default)(app);
273
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
274
- case 1:
275
- res = _a.sent();
276
- statsPath = res.body.paths["/food/stats"];
277
- response200 = statsPath.get.responses["200"];
278
- (0, bun_test_1.expect)(response200).toBeDefined();
279
- (0, bun_test_1.expect)(response200.description).toBe("Success");
280
- schema = response200.content["application/json"].schema;
281
- (0, bun_test_1.expect)(schema.type).toBe("object");
282
- (0, bun_test_1.expect)(schema.properties.count.type).toBe("number");
283
- (0, bun_test_1.expect)(schema.properties.avgCalories.type).toBe("number");
284
- return [2 /*return*/];
285
- }
286
- });
287
- }); });
288
- (0, bun_test_1.it)("includes array response schema in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
289
- var res, categoriesPath, response200, schema;
290
- return __generator(this, function (_a) {
291
- switch (_a.label) {
292
- case 0:
293
- server = (0, supertest_1.default)(app);
294
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
295
- case 1:
296
- res = _a.sent();
297
- categoriesPath = res.body.paths["/food/categories"];
298
- (0, bun_test_1.expect)(categoriesPath).toBeDefined();
299
- response200 = categoriesPath.get.responses["200"];
300
- (0, bun_test_1.expect)(response200.description).toBe("List of categories");
301
- schema = response200.content["application/json"].schema;
302
- (0, bun_test_1.expect)(schema.type).toBe("array");
303
- (0, bun_test_1.expect)(schema.items.type).toBe("object");
304
- (0, bun_test_1.expect)(schema.items.properties.id.type).toBe("string");
305
- (0, bun_test_1.expect)(schema.items.properties.name.type).toBe("string");
306
- (0, bun_test_1.expect)(schema.items.properties.count.type).toBe("number");
307
- return [2 /*return*/];
308
- }
309
- });
310
- }); });
311
- (0, bun_test_1.it)("includes path parameter in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
312
- var res, categoryPath, pathParam;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0:
316
- server = (0, supertest_1.default)(app);
317
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
318
- case 1:
319
- res = _a.sent();
320
- categoryPath = res.body.paths["/food/categories/{categoryId}"];
321
- (0, bun_test_1.expect)(categoryPath).toBeDefined();
322
- pathParam = categoryPath.get.parameters.find(function (p) { return p.name === "categoryId"; });
323
- (0, bun_test_1.expect)(pathParam).toBeDefined();
324
- (0, bun_test_1.expect)(pathParam.in).toBe("path");
325
- (0, bun_test_1.expect)(pathParam.required).toBe(true);
326
- (0, bun_test_1.expect)(pathParam.schema.type).toBe("string");
327
- (0, bun_test_1.expect)(pathParam.description).toBe("The category identifier");
328
- return [2 /*return*/];
329
- }
330
- });
331
- }); });
332
- (0, bun_test_1.it)("includes custom response without body in OpenAPI spec", function () { return __awaiter(void 0, void 0, void 0, function () {
333
- var res, reportsPath, response201;
334
- return __generator(this, function (_a) {
335
- switch (_a.label) {
336
- case 0:
337
- server = (0, supertest_1.default)(app);
338
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
339
- case 1:
340
- res = _a.sent();
341
- reportsPath = res.body.paths["/food/reports"];
342
- response201 = reportsPath.post.responses["201"];
343
- (0, bun_test_1.expect)(response201).toBeDefined();
344
- (0, bun_test_1.expect)(response201.description).toBe("Report created successfully");
345
- (0, bun_test_1.expect)(response201.content).toBeDefined();
346
- return [2 /*return*/];
347
- }
348
- });
349
- }); });
350
- (0, bun_test_1.it)("includes default error responses", function () { return __awaiter(void 0, void 0, void 0, function () {
351
- var res, statsPath, responses;
352
- return __generator(this, function (_a) {
353
- switch (_a.label) {
354
- case 0:
355
- server = (0, supertest_1.default)(app);
356
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
357
- case 1:
358
- res = _a.sent();
359
- statsPath = res.body.paths["/food/stats"];
360
- responses = statsPath.get.responses;
361
- // Default error responses should be merged
362
- (0, bun_test_1.expect)(responses["400"]).toBeDefined();
363
- (0, bun_test_1.expect)(responses["401"]).toBeDefined();
364
- (0, bun_test_1.expect)(responses["403"]).toBeDefined();
365
- (0, bun_test_1.expect)(responses["404"]).toBeDefined();
366
- (0, bun_test_1.expect)(responses["405"]).toBeDefined();
367
- return [2 /*return*/];
368
- }
369
- });
370
- }); });
371
- });
372
- (0, bun_test_1.describe)("endpoint functionality", function () {
373
- (0, bun_test_1.it)("stats endpoint returns correct data", function () { return __awaiter(void 0, void 0, void 0, function () {
374
- var res;
375
- return __generator(this, function (_a) {
376
- switch (_a.label) {
377
- case 0:
378
- server = (0, supertest_1.default)(app);
379
- return [4 /*yield*/, server.get("/food/stats").expect(200)];
380
- case 1:
381
- res = _a.sent();
382
- (0, bun_test_1.expect)(res.body).toEqual({
383
- avgCalories: 250,
384
- count: 10,
385
- requestId: res.headers["x-request-id"],
386
- });
387
- return [2 /*return*/];
388
- }
389
- });
390
- }); });
391
- (0, bun_test_1.it)("reports endpoint returns correct data", function () { return __awaiter(void 0, void 0, void 0, function () {
392
- var res;
393
- return __generator(this, function (_a) {
394
- switch (_a.label) {
395
- case 0:
396
- server = (0, supertest_1.default)(app);
397
- return [4 /*yield*/, server
398
- .post("/food/reports")
399
- .send({ endDate: "2024-12-31", startDate: "2024-01-01" })
400
- .expect(201)];
401
- case 1:
402
- res = _a.sent();
403
- (0, bun_test_1.expect)(res.body).toEqual({
404
- reportId: "report-123",
405
- requestId: res.headers["x-request-id"],
406
- });
407
- return [2 /*return*/];
408
- }
409
- });
410
- }); });
411
- (0, bun_test_1.it)("categories endpoint returns array data", function () { return __awaiter(void 0, void 0, void 0, function () {
412
- var res;
413
- return __generator(this, function (_a) {
414
- switch (_a.label) {
415
- case 0:
416
- server = (0, supertest_1.default)(app);
417
- return [4 /*yield*/, server.get("/food/categories").expect(200)];
418
- case 1:
419
- res = _a.sent();
420
- (0, bun_test_1.expect)(res.body).toHaveLength(2);
421
- (0, bun_test_1.expect)(res.body[0]).toHaveProperty("id");
422
- (0, bun_test_1.expect)(res.body[0]).toHaveProperty("name");
423
- return [2 /*return*/];
424
- }
425
- });
426
- }); });
427
- (0, bun_test_1.it)("category by id endpoint returns correct data", function () { return __awaiter(void 0, void 0, void 0, function () {
428
- var res;
429
- return __generator(this, function (_a) {
430
- switch (_a.label) {
431
- case 0:
432
- server = (0, supertest_1.default)(app);
433
- return [4 /*yield*/, server.get("/food/categories/cat-123").expect(200)];
434
- case 1:
435
- res = _a.sent();
436
- (0, bun_test_1.expect)(res.body).toEqual({
437
- id: "cat-123",
438
- name: "Fruits",
439
- requestId: res.headers["x-request-id"],
440
- });
441
- return [2 /*return*/];
442
- }
443
- });
444
- }); });
445
- });
446
- (0, bun_test_1.describe)("snapshot tests", function () {
447
- (0, bun_test_1.it)("matches OpenAPI spec snapshot", function () { return __awaiter(void 0, void 0, void 0, function () {
448
- var res;
449
- return __generator(this, function (_a) {
450
- switch (_a.label) {
451
- case 0:
452
- server = (0, supertest_1.default)(app);
453
- return [4 /*yield*/, server.get("/openapi.json").expect(200)];
454
- case 1:
455
- res = _a.sent();
456
- (0, bun_test_1.expect)(res.body).toMatchSnapshot();
457
- return [2 /*return*/];
458
- }
459
- });
460
- }); });
461
- });
462
- });
463
- (0, bun_test_1.describe)("OpenApiMiddlewareBuilder without OpenAPI", function () {
464
- (0, bun_test_1.it)("build returns noop middleware when openApi.path is not configured", function () {
465
- var builder = new openApiBuilder_1.OpenApiMiddlewareBuilder({});
466
- var middleware = builder
467
- .withTags(["test"])
468
- .withSummary("Test")
469
- .withResponse(200, { id: { type: "string" } })
470
- .build();
471
- // Middleware should be a function
472
- (0, bun_test_1.expect)(typeof middleware).toBe("function");
473
- // Should call next() without error
474
- var nextCalled = false;
475
- middleware({}, {}, function () {
476
- nextCalled = true;
477
- });
478
- (0, bun_test_1.expect)(nextCalled).toBe(true);
479
- });
480
- (0, bun_test_1.it)("build returns noop middleware when options is empty", function () {
481
- var middleware = (0, openApiBuilder_1.createOpenApiBuilder)({}).build();
482
- var nextCalled = false;
483
- middleware({}, {}, function () {
484
- nextCalled = true;
485
- });
486
- (0, bun_test_1.expect)(nextCalled).toBe(true);
487
- });
488
- });
489
- (0, bun_test_1.describe)("OpenApiMiddlewareBuilder configuration", function () {
490
- (0, bun_test_1.it)("correctly extracts required fields from request body schema", function () {
491
- // We can't easily test this without a mock openApi.path, but we can at least
492
- // verify the builder accepts the configuration
493
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({}).withRequestBody({
494
- optional: { type: "string" },
495
- required1: { required: true, type: "string" },
496
- required2: { required: true, type: "string" },
497
- });
498
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
499
- });
500
- (0, bun_test_1.it)("supports custom media types for request body", function () {
501
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({}).withRequestBody({ data: { type: "string" } }, { mediaType: "application/xml" });
502
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
503
- });
504
- (0, bun_test_1.it)("supports custom media types for response", function () {
505
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({}).withResponse(200, { data: { type: "string" } }, { mediaType: "text/plain" });
506
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
507
- });
508
- (0, bun_test_1.it)("supports optional request body", function () {
509
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({}).withRequestBody({ data: { type: "string" } }, { required: false });
510
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
511
- });
512
- (0, bun_test_1.it)("supports multiple query parameters", function () {
513
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({})
514
- .withQueryParameter("limit", { type: "number" }, { required: false })
515
- .withQueryParameter("offset", { type: "number" }, { required: false })
516
- .withQueryParameter("search", { type: "string" });
517
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
518
- });
519
- (0, bun_test_1.it)("supports multiple path parameters", function () {
520
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({})
521
- .withPathParameter("userId", { type: "string" })
522
- .withPathParameter("postId", { type: "string" });
523
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
524
- });
525
- (0, bun_test_1.it)("supports multiple responses", function () {
526
- var builder = (0, openApiBuilder_1.createOpenApiBuilder)({})
527
- .withResponse(200, { data: { type: "string" } })
528
- .withResponse(201, { id: { type: "string" } })
529
- .withResponse(204, "No content")
530
- .withResponse(404, "Not found");
531
- (0, bun_test_1.expect)(builder).toBeInstanceOf(openApiBuilder_1.OpenApiMiddlewareBuilder);
532
- });
533
- });
534
- (0, bun_test_1.describe)("OpenApiMiddlewareBuilder withValidation / buildWithSchemas", function () {
535
- (0, bun_test_1.beforeEach)(function () {
536
- var resetOpenApiValidatorConfig = require("./openApiValidator").resetOpenApiValidatorConfig;
537
- resetOpenApiValidatorConfig();
538
- });
539
- (0, bun_test_1.it)("buildWithSchemas returns bodySchema and querySchema", function () {
540
- var _a, _b;
541
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
542
- .withRequestBody({ name: { required: true, type: "string" } })
543
- .withQueryParameter("page", { type: "number" })
544
- .buildWithSchemas();
545
- (0, bun_test_1.expect)(result.bodySchema).toBeDefined();
546
- (0, bun_test_1.expect)((_a = result.bodySchema) === null || _a === void 0 ? void 0 : _a.name).toBeDefined();
547
- (0, bun_test_1.expect)(result.querySchema).toBeDefined();
548
- (0, bun_test_1.expect)((_b = result.querySchema) === null || _b === void 0 ? void 0 : _b.page).toBeDefined();
549
- (0, bun_test_1.expect)(typeof result.middleware).toBe("function");
550
- });
551
- (0, bun_test_1.it)("buildWithSchemas returns undefined schemas when no body/query defined", function () {
552
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({}).buildWithSchemas();
553
- (0, bun_test_1.expect)(result.bodySchema).toBeUndefined();
554
- (0, bun_test_1.expect)(result.querySchema).toBeUndefined();
555
- });
556
- (0, bun_test_1.it)("withValidation with defaults enables body and query validation", function () {
557
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
558
- .withRequestBody({ name: { required: true, type: "string" } })
559
- .withQueryParameter("page", { type: "number" })
560
- .withValidation()
561
- .buildWithSchemas();
562
- (0, bun_test_1.expect)(result.validationEnabled).toBe(true);
563
- });
564
- (0, bun_test_1.it)("withValidation with enabled=false disables validation", function () {
565
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
566
- .withRequestBody({ name: { required: true, type: "string" } })
567
- .withValidation({ enabled: false })
568
- .buildWithSchemas();
569
- (0, bun_test_1.expect)(result.validationEnabled).toBe(false);
570
- });
571
- (0, bun_test_1.it)("build() returns an array when validation is enabled with body and query", function () {
572
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
573
- .withRequestBody({ name: { required: true, type: "string" } })
574
- .withQueryParameter("page", { type: "number" })
575
- .withValidation()
576
- .build();
577
- (0, bun_test_1.expect)(Array.isArray(result)).toBe(true);
578
- (0, bun_test_1.expect)(result).toHaveLength(3);
579
- });
580
- (0, bun_test_1.it)("build() returns a single middleware when validation is disabled", function () {
581
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
582
- .withRequestBody({ name: { required: true, type: "string" } })
583
- .build();
584
- (0, bun_test_1.expect)(typeof result).toBe("function");
585
- });
586
- (0, bun_test_1.it)("build() falls back to single middleware when there is nothing to validate", function () {
587
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({}).withValidation().build();
588
- (0, bun_test_1.expect)(typeof result).toBe("function");
589
- });
590
- (0, bun_test_1.it)("withValidation options body=false and query=false is respected", function () {
591
- var result = (0, openApiBuilder_1.createOpenApiBuilder)({})
592
- .withRequestBody({ name: { required: true, type: "string" } })
593
- .withQueryParameter("page", { type: "number" })
594
- .withValidation({ body: false, query: false })
595
- .build();
596
- // No body/query validation = just the openApi middleware (single fn)
597
- (0, bun_test_1.expect)(typeof result).toBe("function");
598
- });
599
- });
@@ -1 +0,0 @@
1
- export {};