@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
package/dist/populate.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/populate.test.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
-
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);
|
|
46
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
-
function step(op) {
|
|
49
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
-
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;
|
|
52
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
-
switch (op[0]) {
|
|
54
|
-
case 0: case 1: t = op; break;
|
|
55
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
-
default:
|
|
59
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
-
if (t[2]) _.ops.pop();
|
|
64
|
-
_.trys.pop(); continue;
|
|
65
|
-
}
|
|
66
|
-
op = body.call(thisArg, _);
|
|
67
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
72
|
-
// noExplicitAny: test mock typing
|
|
73
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
74
|
-
var bun_test_1 = require("bun:test");
|
|
75
|
-
var mongoose_1 = __importStar(require("mongoose"));
|
|
76
|
-
var populate_1 = require("./populate");
|
|
77
|
-
var tests_1 = require("./tests");
|
|
78
|
-
(0, bun_test_1.describe)("populate functions", function () {
|
|
79
|
-
var admin;
|
|
80
|
-
var notAdmin;
|
|
81
|
-
// noExplicitAny: typing as HydratedDocument<Food> causes cascading errors on populated field access patterns (e.g. populated.ownerId.name)
|
|
82
|
-
var spinach;
|
|
83
|
-
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
-
var testData;
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, (0, tests_1.setupTestData)()];
|
|
88
|
-
case 1:
|
|
89
|
-
testData = _a.sent();
|
|
90
|
-
admin = testData.users.admin;
|
|
91
|
-
notAdmin = testData.users.notAdmin;
|
|
92
|
-
spinach = testData.foods.spinach;
|
|
93
|
-
return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}); });
|
|
97
|
-
(0, bun_test_1.it)("unpopulate", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
-
var populated, unpopulated;
|
|
99
|
-
var _a, _b;
|
|
100
|
-
return __generator(this, function (_c) {
|
|
101
|
-
switch (_c.label) {
|
|
102
|
-
case 0: return [4 /*yield*/, spinach.populate("ownerId")];
|
|
103
|
-
case 1:
|
|
104
|
-
populated = _c.sent();
|
|
105
|
-
return [4 /*yield*/, populated.populate("eatenBy")];
|
|
106
|
-
case 2:
|
|
107
|
-
populated = _c.sent();
|
|
108
|
-
return [4 /*yield*/, populated.populate("likesIds.userId")];
|
|
109
|
-
case 3:
|
|
110
|
-
populated = _c.sent();
|
|
111
|
-
(0, bun_test_1.expect)(populated.ownerId.name).toBe("Not Admin");
|
|
112
|
-
(0, bun_test_1.expect)(populated.eatenBy[0].id).toBe(admin.id);
|
|
113
|
-
(0, bun_test_1.expect)(populated.eatenBy[0].name).toBe("Admin");
|
|
114
|
-
(0, bun_test_1.expect)(populated.likesIds[0].userId.id).toBe(admin.id);
|
|
115
|
-
(0, bun_test_1.expect)(populated.likesIds[0].userId.name).toBe("Admin");
|
|
116
|
-
(0, bun_test_1.expect)(populated.likesIds[1].userId.id).toBe(notAdmin.id);
|
|
117
|
-
(0, bun_test_1.expect)(populated.likesIds[1].userId.name).toBe("Not Admin");
|
|
118
|
-
unpopulated = (0, populate_1.unpopulate)(populated, "ownerId");
|
|
119
|
-
(0, bun_test_1.expect)(spinach.ownerId.name).toBeUndefined();
|
|
120
|
-
(0, bun_test_1.expect)(unpopulated.ownerId.toString()).toBe(notAdmin.id);
|
|
121
|
-
// Ensure nothing else was touched.
|
|
122
|
-
(0, bun_test_1.expect)(populated.likesIds[0].userId.id).toBe(admin.id);
|
|
123
|
-
(0, bun_test_1.expect)(populated.likesIds[0].userId.name).toBe("Admin");
|
|
124
|
-
(0, bun_test_1.expect)(populated.likesIds[1].userId.id).toBe(notAdmin.id);
|
|
125
|
-
(0, bun_test_1.expect)(populated.likesIds[1].userId.name).toBe("Not Admin");
|
|
126
|
-
unpopulated = (0, populate_1.unpopulate)(populated, "eatenBy");
|
|
127
|
-
(0, bun_test_1.expect)(populated.eatenBy.toString()).toBe(admin.id);
|
|
128
|
-
(0, bun_test_1.expect)((_a = populated.eatenBy[0]) === null || _a === void 0 ? void 0 : _a.name).toBeUndefined();
|
|
129
|
-
unpopulated = (0, populate_1.unpopulate)(populated, "likesIds.userId");
|
|
130
|
-
(0, bun_test_1.expect)(populated.likesIds[0].userId.toString()).toBe(admin.id);
|
|
131
|
-
(0, bun_test_1.expect)((_b = populated.likesIds[0].userId) === null || _b === void 0 ? void 0 : _b.name).toBeUndefined();
|
|
132
|
-
(0, bun_test_1.expect)(populated.likesIds[1].userId.toString()).toBe(notAdmin.id);
|
|
133
|
-
(0, bun_test_1.expect)(populated.likesIds[1].userId.name).toBeUndefined();
|
|
134
|
-
return [2 /*return*/];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}); });
|
|
138
|
-
});
|
|
139
|
-
(0, bun_test_1.describe)("unpopulate edge cases", function () {
|
|
140
|
-
(0, bun_test_1.it)("throws error when path is empty", function () {
|
|
141
|
-
var doc = { name: "test" };
|
|
142
|
-
(0, bun_test_1.expect)(function () { return (0, populate_1.unpopulate)(doc, ""); }).toThrow("path is required");
|
|
143
|
-
});
|
|
144
|
-
(0, bun_test_1.it)("unpopulates single populated field", function () {
|
|
145
|
-
var doc = {
|
|
146
|
-
name: "test",
|
|
147
|
-
ownerId: { _id: "owner-123", email: "owner@test.com" },
|
|
148
|
-
};
|
|
149
|
-
var result = (0, populate_1.unpopulate)(doc, "ownerId");
|
|
150
|
-
(0, bun_test_1.expect)(result.ownerId).toBe("owner-123");
|
|
151
|
-
});
|
|
152
|
-
(0, bun_test_1.it)("unpopulates array of populated fields", function () {
|
|
153
|
-
var doc = {
|
|
154
|
-
items: [{ _id: "item-1", name: "Item 1" }, { _id: "item-2", name: "Item 2" }, "item-3"],
|
|
155
|
-
name: "test",
|
|
156
|
-
};
|
|
157
|
-
var result = (0, populate_1.unpopulate)(doc, "items");
|
|
158
|
-
(0, bun_test_1.expect)(result.items).toEqual(["item-1", "item-2", "item-3"]);
|
|
159
|
-
});
|
|
160
|
-
(0, bun_test_1.it)("handles nested paths", function () {
|
|
161
|
-
var doc = {
|
|
162
|
-
name: "test",
|
|
163
|
-
nested: {
|
|
164
|
-
items: [
|
|
165
|
-
{ _id: "item-1", name: "Item 1" },
|
|
166
|
-
{ _id: "item-2", name: "Item 2" },
|
|
167
|
-
],
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
var result = (0, populate_1.unpopulate)(doc, "nested.items");
|
|
171
|
-
(0, bun_test_1.expect)(result.nested.items).toEqual(["item-1", "item-2"]);
|
|
172
|
-
});
|
|
173
|
-
(0, bun_test_1.it)("returns original doc when path does not exist", function () {
|
|
174
|
-
var doc = { name: "test" };
|
|
175
|
-
var result = (0, populate_1.unpopulate)(doc, "nonexistent");
|
|
176
|
-
(0, bun_test_1.expect)(result).toEqual(doc);
|
|
177
|
-
});
|
|
178
|
-
(0, bun_test_1.it)("handles nested array paths", function () {
|
|
179
|
-
var doc = {
|
|
180
|
-
containers: [
|
|
181
|
-
{ items: [{ _id: "item-1" }, { _id: "item-2" }] },
|
|
182
|
-
{ items: [{ _id: "item-3" }, { _id: "item-4" }] },
|
|
183
|
-
],
|
|
184
|
-
name: "test",
|
|
185
|
-
};
|
|
186
|
-
var result = (0, populate_1.unpopulate)(doc, "containers.items");
|
|
187
|
-
(0, bun_test_1.expect)(result.containers[0].items).toEqual(["item-1", "item-2"]);
|
|
188
|
-
(0, bun_test_1.expect)(result.containers[1].items).toEqual(["item-3", "item-4"]);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
(0, bun_test_1.describe)("fixMixedFields", function () {
|
|
192
|
-
(0, bun_test_1.it)("returns early when schema is missing", function () {
|
|
193
|
-
var properties = { foo: { type: "object" } };
|
|
194
|
-
(0, bun_test_1.expect)(function () { return (0, populate_1.fixMixedFields)(null, properties); }).not.toThrow();
|
|
195
|
-
});
|
|
196
|
-
(0, bun_test_1.it)("returns early when properties is missing", function () {
|
|
197
|
-
var schema = new mongoose_1.Schema({});
|
|
198
|
-
(0, bun_test_1.expect)(function () { return (0, populate_1.fixMixedFields)(schema, null); }).not.toThrow();
|
|
199
|
-
});
|
|
200
|
-
(0, bun_test_1.it)("replaces Mixed fields with only description", function () {
|
|
201
|
-
var schema = new mongoose_1.Schema({ data: { description: "any data", type: mongoose_1.Schema.Types.Mixed } });
|
|
202
|
-
var properties = {
|
|
203
|
-
data: { description: "any data", type: "object" },
|
|
204
|
-
};
|
|
205
|
-
(0, populate_1.fixMixedFields)(schema, properties);
|
|
206
|
-
(0, bun_test_1.expect)(properties.data).toEqual({ description: "any data" });
|
|
207
|
-
});
|
|
208
|
-
(0, bun_test_1.it)("recurses into arrays of sub-documents", function () {
|
|
209
|
-
var subSchema = new mongoose_1.Schema({ meta: { type: mongoose_1.Schema.Types.Mixed } });
|
|
210
|
-
var schema = new mongoose_1.Schema({ items: [subSchema] });
|
|
211
|
-
var properties = {
|
|
212
|
-
items: {
|
|
213
|
-
items: {
|
|
214
|
-
properties: {
|
|
215
|
-
meta: { type: "object" },
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
type: "array",
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
(0, populate_1.fixMixedFields)(schema, properties);
|
|
222
|
-
(0, bun_test_1.expect)(properties.items.items.properties.meta).toEqual({ description: undefined });
|
|
223
|
-
});
|
|
224
|
-
(0, bun_test_1.it)("skips unknown paths", function () {
|
|
225
|
-
var schema = new mongoose_1.Schema({ foo: String });
|
|
226
|
-
var properties = { unknownKey: { type: "string" } };
|
|
227
|
-
(0, bun_test_1.expect)(function () { return (0, populate_1.fixMixedFields)(schema, properties); }).not.toThrow();
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
(0, bun_test_1.describe)("getOpenApiSpecForModel edge cases", function () {
|
|
231
|
-
(0, bun_test_1.it)("returns model properties without populatePaths", function () {
|
|
232
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.UserModel);
|
|
233
|
-
(0, bun_test_1.expect)(result.properties).toBeDefined();
|
|
234
|
-
});
|
|
235
|
-
(0, bun_test_1.it)("returns with extraModelProperties merged", function () {
|
|
236
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.UserModel, {
|
|
237
|
-
extraModelProperties: { customField: { type: "string" } },
|
|
238
|
-
});
|
|
239
|
-
(0, bun_test_1.expect)(result.properties.customField).toEqual({ type: "string" });
|
|
240
|
-
});
|
|
241
|
-
(0, bun_test_1.it)("skips populate paths without ref", function () {
|
|
242
|
-
// Create a schema with a non-referenced ObjectId field
|
|
243
|
-
var testSchema = new mongoose_1.Schema({ name: String, simpleId: mongoose_1.Schema.Types.ObjectId });
|
|
244
|
-
var TestModelNoRef = mongoose_1.default.models.TestModelNoRef || mongoose_1.default.model("TestModelNoRef", testSchema);
|
|
245
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(TestModelNoRef, {
|
|
246
|
-
populatePaths: [{ path: "simpleId" }],
|
|
247
|
-
});
|
|
248
|
-
// Should not throw, simpleId stays as-is
|
|
249
|
-
(0, bun_test_1.expect)(result.properties).toBeDefined();
|
|
250
|
-
});
|
|
251
|
-
(0, bun_test_1.it)("populates with fields allowlist", function () {
|
|
252
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
253
|
-
populatePaths: [{ fields: ["name"], path: "ownerId" }],
|
|
254
|
-
});
|
|
255
|
-
(0, bun_test_1.expect)(result.properties).toBeDefined();
|
|
256
|
-
});
|
|
257
|
-
(0, bun_test_1.it)("uses openApiComponent $ref when provided", function () {
|
|
258
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
259
|
-
populatePaths: [{ openApiComponent: "UserComponent", path: "ownerId" }],
|
|
260
|
-
});
|
|
261
|
-
(0, bun_test_1.expect)(result.properties.ownerId).toEqual({
|
|
262
|
-
$ref: "#/components/schemas/UserComponent",
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
(0, bun_test_1.it)("populates array ref fields (eatenBy)", function () {
|
|
266
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
267
|
-
populatePaths: [{ path: "eatenBy" }],
|
|
268
|
-
});
|
|
269
|
-
(0, bun_test_1.expect)(result.properties.eatenBy).toBeDefined();
|
|
270
|
-
(0, bun_test_1.expect)(result.properties.eatenBy.items).toBeDefined();
|
|
271
|
-
});
|
|
272
|
-
(0, bun_test_1.it)("populates nested ref in sub-schema (likesIds.userId)", function () {
|
|
273
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
274
|
-
populatePaths: [{ path: "likesIds.userId" }],
|
|
275
|
-
});
|
|
276
|
-
(0, bun_test_1.expect)(result.properties.likesIds).toBeDefined();
|
|
277
|
-
});
|
|
278
|
-
(0, bun_test_1.it)("includes virtuals from model schema", function () {
|
|
279
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel);
|
|
280
|
-
(0, bun_test_1.expect)(result.properties.description).toBeDefined();
|
|
281
|
-
(0, bun_test_1.expect)(result.properties.description.type).toBe("any");
|
|
282
|
-
});
|
|
283
|
-
(0, bun_test_1.it)("includes virtuals from child schemas", function () {
|
|
284
|
-
var childSub = new mongoose_1.Schema({ amount: { description: "Amount", type: Number } });
|
|
285
|
-
childSub.virtual("displayAmount").get(function () {
|
|
286
|
-
return "".concat(this.amount, " units");
|
|
287
|
-
});
|
|
288
|
-
var parentSchema = new mongoose_1.Schema({
|
|
289
|
-
detail: { description: "Single embedded detail", type: childSub },
|
|
290
|
-
title: { description: "Title", type: String },
|
|
291
|
-
});
|
|
292
|
-
var ParentModel = mongoose_1.default.models.ParentWithChildVirtual ||
|
|
293
|
-
mongoose_1.default.model("ParentWithChildVirtual", parentSchema);
|
|
294
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(ParentModel);
|
|
295
|
-
var detail = result.properties.detail;
|
|
296
|
-
(0, bun_test_1.expect)(detail.properties.displayAmount).toBeDefined();
|
|
297
|
-
(0, bun_test_1.expect)(detail.properties.displayAmount.type).toBe("any");
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
(0, bun_test_1.describe)("getOpenApiSpecForModel populate with existing properties", function () {
|
|
301
|
-
(0, bun_test_1.it)("merges populated properties into a path that already has properties", function () {
|
|
302
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
303
|
-
populatePaths: [{ path: "likesIds.userId" }],
|
|
304
|
-
});
|
|
305
|
-
// likesIds is an array subschema with its own properties already;
|
|
306
|
-
// populating userId should merge the user properties into the existing structure.
|
|
307
|
-
(0, bun_test_1.expect)(result.properties.likesIds).toBeDefined();
|
|
308
|
-
var likesIds = result.properties.likesIds;
|
|
309
|
-
var items = likesIds.items;
|
|
310
|
-
(0, bun_test_1.expect)(items.properties.userId).toBeDefined();
|
|
311
|
-
});
|
|
312
|
-
(0, bun_test_1.it)("creates intermediate path structure when navigating to nested populate", function () {
|
|
313
|
-
// eatenBy is defined as [{ ref: "User", type: ObjectId }] - an array of refs.
|
|
314
|
-
// When we populate eatenBy, the openApiPath resolves through items.
|
|
315
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
316
|
-
populatePaths: [{ path: "eatenBy" }],
|
|
317
|
-
});
|
|
318
|
-
(0, bun_test_1.expect)(result.properties.eatenBy).toBeDefined();
|
|
319
|
-
var eatenBy = result.properties.eatenBy;
|
|
320
|
-
(0, bun_test_1.expect)(eatenBy.items).toBeDefined();
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
(0, bun_test_1.describe)("getOpenApiSpecForModel populate property merge", function () {
|
|
324
|
-
(0, bun_test_1.it)("merges properties when the same path is populated twice", function () {
|
|
325
|
-
// First populate sets the field properties, second triggers the merge branch.
|
|
326
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
327
|
-
populatePaths: [{ fields: ["name"], path: "likesIds.userId" }, { path: "likesIds.userId" }],
|
|
328
|
-
});
|
|
329
|
-
var likesIds = result.properties.likesIds;
|
|
330
|
-
var items = likesIds.items;
|
|
331
|
-
var userIdProps = items.properties.userId;
|
|
332
|
-
// After the merge the wider populate should have contributed all user fields.
|
|
333
|
-
(0, bun_test_1.expect)(userIdProps.properties).toBeDefined();
|
|
334
|
-
(0, bun_test_1.expect)(userIdProps.properties.name).toBeDefined();
|
|
335
|
-
});
|
|
336
|
-
(0, bun_test_1.it)("merges openApiComponent ref into an already-populated path", function () {
|
|
337
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
338
|
-
populatePaths: [
|
|
339
|
-
{ path: "likesIds.userId" },
|
|
340
|
-
{ openApiComponent: "UserComponent", path: "likesIds.userId" },
|
|
341
|
-
],
|
|
342
|
-
});
|
|
343
|
-
var likesIds = result.properties.likesIds;
|
|
344
|
-
var items = likesIds.items;
|
|
345
|
-
var userIdProps = items.properties.userId;
|
|
346
|
-
// Merge path adds the $ref key inside the existing properties.
|
|
347
|
-
(0, bun_test_1.expect)(userIdProps.properties).toBeDefined();
|
|
348
|
-
(0, bun_test_1.expect)(userIdProps.properties.userId).toEqual({
|
|
349
|
-
$ref: "#/components/schemas/UserComponent",
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
(0, bun_test_1.describe)("filterKeys (via getOpenApiSpecForModel populatePaths)", function () {
|
|
354
|
-
(0, bun_test_1.it)("filters populated fields using dot-notation keys", function () {
|
|
355
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
356
|
-
populatePaths: [{ fields: ["name.nested"], path: "ownerId" }],
|
|
357
|
-
});
|
|
358
|
-
var ownerProps = result.properties.ownerId.properties;
|
|
359
|
-
(0, bun_test_1.expect)(ownerProps.name).toBeDefined();
|
|
360
|
-
(0, bun_test_1.expect)(typeof ownerProps.name).toBe("object");
|
|
361
|
-
});
|
|
362
|
-
(0, bun_test_1.it)("rejects prototype pollution keys in nested dot-notation", function () {
|
|
363
|
-
var result = (0, populate_1.getOpenApiSpecForModel)(tests_1.FoodModel, {
|
|
364
|
-
populatePaths: [{ fields: ["__proto__.polluted"], path: "ownerId" }],
|
|
365
|
-
});
|
|
366
|
-
(0, bun_test_1.expect)(result.properties).toBeDefined();
|
|
367
|
-
// noExplicitAny: testing that prototype pollution did not add a 'polluted' property to Object.prototype
|
|
368
|
-
(0, bun_test_1.expect)(Object.prototype.polluted).toBeUndefined();
|
|
369
|
-
var ownerProps = result.properties.ownerId.properties;
|
|
370
|
-
(0, bun_test_1.expect)(ownerProps).toBeDefined();
|
|
371
|
-
(0, bun_test_1.expect)(Object.keys(ownerProps)).not.toContain("__proto__");
|
|
372
|
-
});
|
|
373
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the realtime module's pure functions and classes:
|
|
3
|
-
* - queryMatcher.ts (matchesQuery)
|
|
4
|
-
* - queryStore.ts (addQuerySubscription, removeQuerySubscription, etc.)
|
|
5
|
-
* - registry.ts (registerRealtime, getRealtimeRegistry, etc.)
|
|
6
|
-
* - realtimeApp.ts (RealtimeApp class — register, getIo, close)
|
|
7
|
-
* - realtimeApp.ts (installRealtimeSocketHandlers — permission and rate-limit logic)
|
|
8
|
-
* - changeStreamWatcher.ts (serializeDoc — responseHandler fallback)
|
|
9
|
-
*/
|
|
10
|
-
export {};
|