@terreno/api 57.3.0 → 57.4.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/.ai/skills/mongoose-schema-safety/SKILL.md +23 -10
- package/README.md +6 -0
- package/dist/adminTypes.d.ts +7 -0
- package/dist/adminTypes.js +6 -1
- package/dist/api.d.ts +10 -0
- package/dist/api.js +99 -36
- package/dist/audit/auditApp.d.ts +30 -0
- package/dist/audit/auditApp.js +155 -0
- package/dist/audit/auditEventModel.d.ts +29 -0
- package/dist/audit/auditEventModel.js +102 -0
- package/dist/audit/cloudTasksEnqueue.d.ts +32 -0
- package/dist/audit/cloudTasksEnqueue.js +162 -0
- package/dist/audit/diff.d.ts +10 -0
- package/dist/audit/diff.js +230 -0
- package/dist/audit/processQueue.d.ts +6 -0
- package/dist/audit/processQueue.js +101 -0
- package/dist/audit/rbacSink.d.ts +2 -0
- package/dist/audit/rbacSink.js +82 -0
- package/dist/audit/record.d.ts +56 -0
- package/dist/audit/record.js +373 -0
- package/dist/betterAuth.d.ts +6 -0
- package/dist/betterAuthSetup.js +1 -1
- package/dist/collectionRegistry.d.ts +3 -1
- package/dist/collectionRegistry.js +25 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +48 -2
- package/dist/mcp/query.d.ts +0 -13
- package/dist/mcp/query.js +8 -8
- package/dist/migrations/fixtures/all-down/20260910120000-one.d.ts +4 -0
- package/dist/migrations/fixtures/all-down/20260910120000-one.js +49 -0
- package/dist/migrations/fixtures/all-down/20260910120001-two.d.ts +4 -0
- package/dist/migrations/fixtures/all-down/20260910120001-two.js +49 -0
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.d.ts +3 -0
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +45 -0
- package/dist/migrations/fixtures/bad-name/not-a-migration.d.ts +3 -0
- package/dist/migrations/fixtures/bad-name/not-a-migration.js +45 -0
- package/dist/migrations/fixtures/missing-up/20260910120000-noup.d.ts +2 -0
- package/dist/migrations/fixtures/missing-up/20260910120000-noup.js +5 -0
- package/dist/migrations/fixtures/valid/20260910120000-alpha.d.ts +3 -0
- package/dist/migrations/fixtures/valid/20260910120000-alpha.js +45 -0
- package/dist/migrations/fixtures/valid/20260910120001-beta.d.ts +4 -0
- package/dist/migrations/fixtures/valid/20260910120001-beta.js +49 -0
- package/dist/migrations/generate.d.ts +17 -0
- package/dist/migrations/generate.js +277 -0
- package/dist/migrations/load.d.ts +20 -0
- package/dist/migrations/load.js +236 -0
- package/dist/migrations/lock.d.ts +13 -0
- package/dist/migrations/lock.js +145 -0
- package/dist/migrations/runner.d.ts +42 -0
- package/dist/migrations/runner.js +503 -0
- package/dist/migrations/schemaCatalog.d.ts +44 -0
- package/dist/migrations/schemaCatalog.js +326 -0
- package/dist/migrations/types.d.ts +87 -0
- package/dist/migrations/types.js +7 -0
- package/dist/models/notification.d.ts +2 -0
- package/dist/models/notification.js +62 -0
- package/dist/models/notificationPreference.d.ts +2 -0
- package/dist/models/notificationPreference.js +49 -0
- package/dist/notifications/notificationService.d.ts +40 -0
- package/dist/notifications/notificationService.js +323 -0
- package/dist/notifications/notificationsApp.d.ts +18 -0
- package/dist/notifications/notificationsApp.js +250 -0
- package/dist/notifications/notificationsBeforeSend.d.ts +14 -0
- package/dist/notifications/notificationsBeforeSend.js +77 -0
- package/dist/openApi.d.ts +1 -7
- package/dist/openApi.js +7 -6
- package/dist/openApiBuilder.d.ts +14 -3
- package/dist/openApiValidator.d.ts +13 -1
- package/dist/openApiValidator.js +200 -36
- package/dist/orgs/orgContext.d.ts +23 -0
- package/dist/orgs/orgContext.js +198 -0
- package/dist/orgs/orgPermissions.d.ts +4 -0
- package/dist/orgs/orgPermissions.js +77 -0
- package/dist/orgs/orgPlugin.d.ts +13 -0
- package/dist/orgs/orgPlugin.js +84 -0
- package/dist/orgs/organizationModel.d.ts +13 -0
- package/dist/orgs/organizationModel.js +301 -0
- package/dist/orgs/organizationSettings.d.ts +19 -0
- package/dist/orgs/organizationSettings.js +120 -0
- package/dist/orgs/orgsApp.d.ts +28 -0
- package/dist/orgs/orgsApp.js +678 -0
- package/dist/permissions.d.ts +7 -13
- package/dist/permissions.js +8 -31
- package/dist/rateLimit/middleware.d.ts +0 -8
- package/dist/rateLimit/middleware.js +2 -3
- package/dist/rateLimit/mongoStore.d.ts +1 -0
- package/dist/rateLimit/mongoStore.js +1 -0
- package/dist/rateLimit/policies.d.ts +0 -4
- package/dist/rateLimit/policies.js +5 -7
- package/dist/rateLimit/redisStore.d.ts +1 -0
- package/dist/rateLimit/redisStore.js +1 -0
- package/dist/rbac/access.js +30 -13
- package/dist/rbac/membershipOrgAdminSource.d.ts +6 -0
- package/dist/rbac/membershipOrgAdminSource.js +122 -0
- package/dist/rbac/modelRouterAccess.d.ts +3 -0
- package/dist/rbac/modelRouterAccess.js +3 -0
- package/dist/rbac/resolve.js +60 -31
- package/dist/rbac/roleModel.d.ts +2 -5
- package/dist/rbac/roleModel.js +18 -4
- package/dist/rbac/statements.d.ts +10 -1
- package/dist/rbac/statements.js +19 -2
- package/dist/rbac/types.d.ts +5 -0
- package/dist/realtime/changeStreamWatcher.d.ts +10 -4
- package/dist/realtime/changeStreamWatcher.js +110 -64
- package/dist/realtime/deprecation.d.ts +1 -0
- package/dist/realtime/deprecation.js +1 -0
- package/dist/realtime/realtimeApp.d.ts +1 -0
- package/dist/realtime/realtimeApp.js +1 -0
- package/dist/schemaMetadata.js +16 -5
- package/dist/sync/adminBroadcastScope.d.ts +40 -0
- package/dist/sync/adminBroadcastScope.js +194 -0
- package/dist/sync/adminWindowAccess.d.ts +13 -0
- package/dist/sync/adminWindowAccess.js +96 -0
- package/dist/sync/adminWindowMutation.d.ts +88 -0
- package/dist/sync/adminWindowMutation.js +247 -0
- package/dist/sync/executors.d.ts +9 -3
- package/dist/sync/executors.js +190 -159
- package/dist/sync/mutationHandler.d.ts +5 -2
- package/dist/sync/mutationHandler.js +191 -71
- package/dist/sync/registry.js +4 -0
- package/dist/sync/routes.d.ts +13 -0
- package/dist/sync/routes.js +113 -56
- package/dist/sync/socketHandlers.d.ts +8 -2
- package/dist/sync/socketHandlers.js +144 -50
- package/dist/sync/streams.d.ts +2 -0
- package/dist/sync/streams.js +7 -1
- package/dist/sync/syncApp.d.ts +2 -1
- package/dist/sync/syncApp.js +2 -1
- package/dist/sync/syncBatch.d.ts +5 -2
- package/dist/sync/syncBatch.js +4 -4
- package/dist/sync/types.d.ts +18 -0
- package/dist/terrenoApp.d.ts +29 -0
- package/dist/terrenoApp.js +91 -54
- package/dist/tests/createTestData.d.ts +1 -3
- package/dist/tests/createTestData.js +3 -5
- package/dist/tests/models.d.ts +1 -0
- package/dist/tests/models.js +9 -2
- package/dist/tests/testHelper.d.ts +0 -5
- package/dist/tests/testHelper.js +2 -9
- package/dist/types/authToken.d.ts +3 -3
- package/dist/types/mcpServiceToken.d.ts +2 -2
- package/dist/types/membership.d.ts +23 -0
- package/dist/types/membership.js +2 -0
- package/dist/types/notification.d.ts +28 -0
- package/dist/types/notification.js +2 -0
- package/dist/types/notificationPreference.d.ts +20 -0
- package/dist/types/notificationPreference.js +2 -0
- package/dist/types/organization.d.ts +36 -0
- package/dist/types/organization.js +2 -0
- package/dist/webhooks/idempotency/webhookReceipt.d.ts +4 -49
- package/dist/webhooks/idempotency/webhookReceipt.js +7 -7
- package/dist/webhooks/rawBody.d.ts +1 -0
- package/dist/webhooks/rawBody.js +1 -0
- package/package.json +31 -25
- package/src/__snapshots__/openApi.test.ts.snap +192 -54
- package/src/__snapshots__/openApiBuilder.test.ts.snap +0 -18
- package/src/__snapshots__/schemaMetadata.test.ts.snap +0 -1
- package/src/adminTypes.ts +8 -0
- package/src/api.test.ts +39 -2
- package/src/api.ts +68 -0
- package/src/audit/auditApp.test.ts +243 -0
- package/src/audit/auditApp.ts +139 -0
- package/src/audit/auditEventModel.ts +156 -0
- package/src/audit/auditRouter.test.ts +456 -0
- package/src/audit/cloudTasksEnqueue.test.ts +124 -0
- package/src/audit/cloudTasksEnqueue.ts +104 -0
- package/src/audit/diff.ts +163 -0
- package/src/audit/processQueue.ts +69 -0
- package/src/audit/rbacSink.test.ts +86 -0
- package/src/audit/rbacSink.ts +42 -0
- package/src/audit/record.test.ts +402 -0
- package/src/audit/record.ts +328 -0
- package/src/auth.test.ts +1 -1
- package/src/betterAuth.ts +7 -0
- package/src/betterAuthSetup.test.ts +27 -0
- package/src/betterAuthSetup.ts +1 -0
- package/src/collectionRegistry.test.ts +8 -9
- package/src/collectionRegistry.ts +21 -1
- package/src/express.d.ts +2 -0
- package/src/expressServer.test.ts +50 -2
- package/src/index.ts +69 -0
- package/src/mcp/handlers.test.ts +275 -0
- package/src/mcp/query.ts +3 -3
- package/src/mcp/toolGenerator.test.ts +81 -0
- package/src/migrations/cli.test.ts +376 -0
- package/src/migrations/cli.ts +283 -0
- package/src/migrations/fixtures/all-down/20260910120000-one.ts +6 -0
- package/src/migrations/fixtures/all-down/20260910120001-two.ts +6 -0
- package/src/migrations/fixtures/bad-id/20260910120000-mismatch.ts +4 -0
- package/src/migrations/fixtures/bad-name/not-a-migration.ts +4 -0
- package/src/migrations/fixtures/missing-up/20260910120000-noup.ts +2 -0
- package/src/migrations/fixtures/valid/20260910120000-alpha.ts +4 -0
- package/src/migrations/fixtures/valid/20260910120001-beta.ts +6 -0
- package/src/migrations/generate.test.ts +333 -0
- package/src/migrations/generate.ts +216 -0
- package/src/migrations/load.test.ts +103 -0
- package/src/migrations/load.ts +124 -0
- package/src/migrations/lock.test.ts +133 -0
- package/src/migrations/lock.ts +118 -0
- package/src/migrations/runner.test.ts +504 -0
- package/src/migrations/runner.ts +358 -0
- package/src/migrations/schemaCatalog.test.ts +159 -0
- package/src/migrations/schemaCatalog.ts +262 -0
- package/src/migrations/types.ts +94 -0
- package/src/models/notification.ts +68 -0
- package/src/models/notificationPreference.ts +62 -0
- package/src/notifications/notificationService.ts +254 -0
- package/src/notifications/notificationsApp.test.ts +505 -0
- package/src/notifications/notificationsApp.ts +200 -0
- package/src/notifications/notificationsBeforeSend.ts +51 -0
- package/src/openApi.test.ts +0 -1
- package/src/openApi.ts +2 -1
- package/src/openApiBuilder.ts +14 -3
- package/src/openApiValidator.test.ts +221 -2
- package/src/openApiValidator.ts +218 -33
- package/src/orgs/orgAccessOptIn.test.ts +87 -0
- package/src/orgs/orgContext.test.ts +259 -0
- package/src/orgs/orgContext.ts +151 -0
- package/src/orgs/orgPermissions.test.ts +105 -0
- package/src/orgs/orgPermissions.ts +40 -0
- package/src/orgs/orgPlugin.test.ts +130 -0
- package/src/orgs/orgPlugin.ts +70 -0
- package/src/orgs/orgRbac.test.ts +267 -0
- package/src/orgs/orgSecurityDefects.test.ts +415 -0
- package/src/orgs/organizationModel.test.ts +205 -0
- package/src/orgs/organizationModel.ts +257 -0
- package/src/orgs/organizationSettings.test.ts +113 -0
- package/src/orgs/organizationSettings.ts +126 -0
- package/src/orgs/orgsApp.test.ts +382 -0
- package/src/orgs/orgsApp.ts +563 -0
- package/src/permissions.test.ts +62 -36
- package/src/permissions.ts +8 -30
- package/src/rateLimit/middleware.ts +1 -1
- package/src/rateLimit/mongoStore.ts +1 -0
- package/src/rateLimit/policies.ts +2 -2
- package/src/rateLimit/redisStore.ts +1 -0
- package/src/rbac/access.ts +11 -3
- package/src/rbac/membershipOrgAdminSource.ts +59 -0
- package/src/rbac/modelRouterAccess.ts +3 -0
- package/src/rbac/permissionUtils.test.ts +26 -5
- package/src/rbac/resolve.test.ts +34 -2
- package/src/rbac/resolve.ts +26 -7
- package/src/rbac/roleModel.test.ts +34 -1
- package/src/rbac/roleModel.ts +17 -1
- package/src/rbac/statements.test.ts +19 -0
- package/src/rbac/statements.ts +19 -1
- package/src/rbac/types.ts +5 -0
- package/src/realtime/changeStreamWatcher.ts +73 -33
- package/src/realtime/deprecation.ts +1 -0
- package/src/realtime/realtime.test.ts +357 -185
- package/src/realtime/realtimeApp.ts +1 -0
- package/src/schemaMetadata.test.ts +14 -0
- package/src/schemaMetadata.ts +5 -5
- package/src/sync/adminBroadcastConfig.test.ts +96 -0
- package/src/sync/adminBroadcastScope.test.ts +155 -0
- package/src/sync/adminBroadcastScope.ts +123 -0
- package/src/sync/adminWindowAccess.test.ts +57 -0
- package/src/sync/adminWindowAccess.ts +32 -0
- package/src/sync/adminWindowMutation.test.ts +450 -0
- package/src/sync/adminWindowMutation.ts +283 -0
- package/src/sync/executors.ts +33 -6
- package/src/sync/mutationHandler.test.ts +277 -1
- package/src/sync/mutationHandler.ts +171 -29
- package/src/sync/registry.ts +4 -0
- package/src/sync/routes.ts +52 -8
- package/src/sync/socketHandlers.ts +154 -58
- package/src/sync/streams.ts +6 -0
- package/src/sync/sync.test.ts +3 -2
- package/src/sync/syncApp.ts +2 -1
- package/src/sync/syncBatch.ts +7 -2
- package/src/sync/syncRoutes.test.ts +297 -3
- package/src/sync/syncSocket.test.ts +229 -0
- package/src/sync/types.ts +20 -0
- package/src/terrenoApp.migrations.test.ts +114 -0
- package/src/terrenoApp.test.ts +41 -0
- package/src/terrenoApp.ts +94 -31
- package/src/tests/createTestData.ts +2 -2
- package/src/tests/models.ts +10 -2
- package/src/tests/testHelper.ts +1 -7
- package/src/types/authToken.ts +2 -4
- package/src/types/mcpServiceToken.ts +1 -7
- package/src/types/membership.ts +48 -0
- package/src/types/notification.ts +34 -0
- package/src/types/notificationPreference.ts +28 -0
- package/src/types/organization.ts +49 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +4 -7
- package/src/webhooks/rawBody.test.ts +33 -0
- package/src/webhooks/rawBody.ts +1 -0
- package/tsconfig.json +1 -1
- package/tsconfig.typedoc.json +2 -1
- package/dist/vendor/wesleytodd-openapi/lib/convert-yaml.d.ts +0 -2
- package/dist/vendor/wesleytodd-openapi/lib/convert-yaml.js +0 -13
- package/src/vendor/wesleytodd-openapi/lib/convert-yaml.js +0 -13
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.withMigrationLock = exports.MIGRATION_LOCK_TTL_MS = void 0;
|
|
40
|
+
/**
|
|
41
|
+
* Exclusive lock for wet migrate so concurrent CLI, boot, and admin runs cannot
|
|
42
|
+
* double-apply. Holders heartbeat; a stale lock may be stolen after the TTL.
|
|
43
|
+
*/
|
|
44
|
+
var node_crypto_1 = require("node:crypto");
|
|
45
|
+
var luxon_1 = require("luxon");
|
|
46
|
+
var types_1 = require("./types");
|
|
47
|
+
/** Default lock lifetime before another runner may steal it. */
|
|
48
|
+
exports.MIGRATION_LOCK_TTL_MS = 10 * 60 * 1000;
|
|
49
|
+
var lockCollection = function (connection) {
|
|
50
|
+
return connection.collection(types_1.MIGRATIONS_COLLECTION);
|
|
51
|
+
};
|
|
52
|
+
var isDuplicateKey = function (error) {
|
|
53
|
+
if (typeof error !== "object" || error === null) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
var code = "code" in error ? error.code : undefined;
|
|
57
|
+
return code === 11000;
|
|
58
|
+
};
|
|
59
|
+
var tryAcquire = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
60
|
+
var error_1, stolen;
|
|
61
|
+
var col = _b.col, expiresAt = _b.expiresAt, holder = _b.holder, nowJs = _b.nowJs;
|
|
62
|
+
return __generator(this, function (_c) {
|
|
63
|
+
switch (_c.label) {
|
|
64
|
+
case 0:
|
|
65
|
+
_c.trys.push([0, 2, , 3]);
|
|
66
|
+
return [4 /*yield*/, col.insertOne({
|
|
67
|
+
_id: types_1.MIGRATION_LOCK_ID,
|
|
68
|
+
expiresAt: expiresAt,
|
|
69
|
+
heartbeatAt: nowJs,
|
|
70
|
+
holder: holder,
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
_c.sent();
|
|
74
|
+
return [2 /*return*/, true];
|
|
75
|
+
case 2:
|
|
76
|
+
error_1 = _c.sent();
|
|
77
|
+
if (!isDuplicateKey(error_1)) {
|
|
78
|
+
throw error_1;
|
|
79
|
+
}
|
|
80
|
+
return [3 /*break*/, 3];
|
|
81
|
+
case 3: return [4 /*yield*/, col.findOneAndUpdate({ _id: types_1.MIGRATION_LOCK_ID, expiresAt: { $lte: nowJs } }, { $set: { expiresAt: expiresAt, heartbeatAt: nowJs, holder: holder } }, { returnDocument: "after" })];
|
|
82
|
+
case 4:
|
|
83
|
+
stolen = _c.sent();
|
|
84
|
+
return [2 /*return*/, stolen !== null && stolen.holder === holder];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); };
|
|
88
|
+
var withMigrationLock = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
89
|
+
var col, acquire, heartbeat;
|
|
90
|
+
var connection = _b.connection, fn = _b.fn, _c = _b.holder, holder = _c === void 0 ? (0, node_crypto_1.randomUUID)() : _c, _d = _b.now, now = _d === void 0 ? function () { return luxon_1.DateTime.now(); } : _d, _e = _b.pollMs, pollMs = _e === void 0 ? 1000 : _e, _f = _b.ttlMs, ttlMs = _f === void 0 ? exports.MIGRATION_LOCK_TTL_MS : _f;
|
|
91
|
+
return __generator(this, function (_g) {
|
|
92
|
+
switch (_g.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
col = lockCollection(connection);
|
|
95
|
+
acquire = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
+
var nowDt, nowJs, expiresAt, acquired;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0:
|
|
100
|
+
if (!true) return [3 /*break*/, 3];
|
|
101
|
+
nowDt = now();
|
|
102
|
+
nowJs = nowDt.toJSDate();
|
|
103
|
+
expiresAt = nowDt.plus({ milliseconds: ttlMs }).toJSDate();
|
|
104
|
+
return [4 /*yield*/, tryAcquire({ col: col, expiresAt: expiresAt, holder: holder, nowJs: nowJs })];
|
|
105
|
+
case 1:
|
|
106
|
+
acquired = _a.sent();
|
|
107
|
+
if (acquired) {
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
return [4 /*yield*/, Bun.sleep(pollMs)];
|
|
111
|
+
case 2:
|
|
112
|
+
_a.sent();
|
|
113
|
+
return [3 /*break*/, 0];
|
|
114
|
+
case 3: return [2 /*return*/];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}); };
|
|
118
|
+
return [4 /*yield*/, acquire()];
|
|
119
|
+
case 1:
|
|
120
|
+
_g.sent();
|
|
121
|
+
heartbeat = setInterval(function () {
|
|
122
|
+
var nowDt = now();
|
|
123
|
+
void col.updateOne({ _id: types_1.MIGRATION_LOCK_ID, holder: holder }, {
|
|
124
|
+
$set: {
|
|
125
|
+
expiresAt: nowDt.plus({ milliseconds: ttlMs }).toJSDate(),
|
|
126
|
+
heartbeatAt: nowDt.toJSDate(),
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}, Math.max(50, Math.floor(ttlMs / 3)));
|
|
130
|
+
_g.label = 2;
|
|
131
|
+
case 2:
|
|
132
|
+
_g.trys.push([2, , 4, 6]);
|
|
133
|
+
return [4 /*yield*/, fn()];
|
|
134
|
+
case 3: return [2 /*return*/, _g.sent()];
|
|
135
|
+
case 4:
|
|
136
|
+
clearInterval(heartbeat);
|
|
137
|
+
return [4 /*yield*/, col.deleteOne({ _id: types_1.MIGRATION_LOCK_ID, holder: holder })];
|
|
138
|
+
case 5:
|
|
139
|
+
_g.sent();
|
|
140
|
+
return [7 /*endfinally*/];
|
|
141
|
+
case 6: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); };
|
|
145
|
+
exports.withMigrationLock = withMigrationLock;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { type LoadedMigration, type MigrationStatus, type RunDownMigrationsOptions, type RunDownMigrationsResult, type RunMigrationsOptions, type RunMigrationsResult } from "./types";
|
|
3
|
+
export declare const runMigrations: ({ addLog, checkCancellation, connection, dryRun, lockPollMs, lockTtlMs, logger, migrations, mongoose: mongooseNs, }: RunMigrationsOptions) => Promise<RunMigrationsResult>;
|
|
4
|
+
export declare const getMigrationStatus: ({ connection, migrations, }: {
|
|
5
|
+
connection: mongoose.Connection;
|
|
6
|
+
migrations: LoadedMigration[];
|
|
7
|
+
}) => Promise<MigrationStatus>;
|
|
8
|
+
export declare const runDownMigrations: ({ connection, dryRun, lockPollMs, lockTtlMs, logger, migrations, mongoose: mongooseNs, steps, }: RunDownMigrationsOptions) => Promise<RunDownMigrationsResult>;
|
|
9
|
+
export interface AssertMigrationsAllowedOptions {
|
|
10
|
+
allowEnv: boolean;
|
|
11
|
+
dryRun: boolean;
|
|
12
|
+
force: boolean;
|
|
13
|
+
isProduction: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Fail closed for production wet apply unless ALLOW_MIGRATIONS and force (CLI `--force` or boot/admin Apply). */
|
|
16
|
+
export declare const assertMigrationsAllowed: ({ allowEnv, dryRun, force, isProduction, }: AssertMigrationsAllowedOptions) => void;
|
|
17
|
+
export interface StartupMigrationsOption {
|
|
18
|
+
dir: string;
|
|
19
|
+
runOnStart?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const runStartupMigrations: ({ env, migrations, mongoose: mongooseNs, }: {
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
migrations?: StartupMigrationsOption;
|
|
24
|
+
mongoose: typeof mongoose;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
applied: string[];
|
|
27
|
+
ran: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
export interface ExerciseReversibleMigrationsOptions {
|
|
30
|
+
dir: string;
|
|
31
|
+
connect: () => Promise<mongoose.Connection>;
|
|
32
|
+
}
|
|
33
|
+
export interface ExerciseReversibleMigrationsResult {
|
|
34
|
+
applied: string[];
|
|
35
|
+
reversed: string[];
|
|
36
|
+
skippedIrreversible: string | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* CI helper: apply every file, then roll back in reverse until a file without
|
|
40
|
+
* `down` stops the chain. The irreversible id is recorded; earlier files stay applied.
|
|
41
|
+
*/
|
|
42
|
+
export declare const exerciseReversibleMigrations: ({ connect, dir, }: ExerciseReversibleMigrationsOptions) => Promise<ExerciseReversibleMigrationsResult>;
|