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