@budibase/backend-core 3.2.41 → 3.2.43
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/package.json +3 -3
- package/dist/src/accounts/accounts.js +83 -0
- package/dist/src/accounts/accounts.js.map +1 -0
- package/dist/src/accounts/api.js +102 -0
- package/dist/src/accounts/api.js.map +1 -0
- package/dist/src/accounts/index.js +18 -0
- package/dist/src/accounts/index.js.map +1 -0
- package/dist/src/cache/appMetadata.js +96 -0
- package/dist/src/cache/appMetadata.js.map +1 -0
- package/dist/src/cache/base/index.js +189 -0
- package/dist/src/cache/base/index.js.map +1 -0
- package/dist/src/cache/docWritethrough.js +123 -0
- package/dist/src/cache/docWritethrough.js.map +1 -0
- package/dist/src/cache/generic.js +37 -0
- package/dist/src/cache/generic.js.map +1 -0
- package/dist/src/cache/index.js +48 -0
- package/dist/src/cache/index.js.map +1 -0
- package/dist/src/cache/invite.js +128 -0
- package/dist/src/cache/invite.js.map +1 -0
- package/dist/src/cache/passwordReset.js +92 -0
- package/dist/src/cache/passwordReset.js.map +1 -0
- package/dist/src/cache/user.js +183 -0
- package/dist/src/cache/user.js.map +1 -0
- package/dist/src/cache/writethrough.js +170 -0
- package/dist/src/cache/writethrough.js.map +1 -0
- package/dist/src/configs/configs.js +294 -0
- package/dist/src/configs/configs.js.map +1 -0
- package/dist/src/configs/index.js +18 -0
- package/dist/src/configs/index.js.map +1 -0
- package/dist/src/constants/db.js +75 -0
- package/dist/src/constants/db.js.map +1 -0
- package/dist/src/constants/index.js +19 -0
- package/dist/src/constants/index.js.map +1 -0
- package/dist/src/constants/misc.js +40 -0
- package/dist/src/constants/misc.js.map +1 -0
- package/dist/src/context/Context.js +14 -0
- package/dist/src/context/Context.js.map +1 -0
- package/dist/src/context/identity.js +81 -0
- package/dist/src/context/identity.js.map +1 -0
- package/dist/src/context/index.js +44 -0
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/mainContext.js +446 -0
- package/dist/src/context/mainContext.js.map +1 -0
- package/dist/src/context/types.js +3 -0
- package/dist/src/context/types.js.map +1 -0
- package/dist/src/db/Replication.js +90 -0
- package/dist/src/db/Replication.js.map +1 -0
- package/dist/src/db/couch/DatabaseImpl.js +475 -0
- package/dist/src/db/couch/DatabaseImpl.js.map +1 -0
- package/dist/src/db/couch/connections.js +101 -0
- package/dist/src/db/couch/connections.js.map +1 -0
- package/dist/src/db/couch/index.js +26 -0
- package/dist/src/db/couch/index.js.map +1 -0
- package/dist/src/db/couch/pouchDB.js +108 -0
- package/dist/src/db/couch/pouchDB.js.map +1 -0
- package/dist/src/db/couch/utils.js +60 -0
- package/dist/src/db/couch/utils.js.map +1 -0
- package/dist/src/db/db.js +47 -0
- package/dist/src/db/db.js.map +1 -0
- package/dist/src/db/errors.js +21 -0
- package/dist/src/db/errors.js.map +1 -0
- package/dist/src/db/index.js +58 -0
- package/dist/src/db/index.js.map +1 -0
- package/dist/src/db/instrumentation.js +202 -0
- package/dist/src/db/instrumentation.js.map +1 -0
- package/dist/src/db/lucene.js +638 -0
- package/dist/src/db/lucene.js.map +1 -0
- package/dist/src/db/searchIndexes/index.js +18 -0
- package/dist/src/db/searchIndexes/index.js.map +1 -0
- package/dist/src/db/searchIndexes/searchIndexes.js +76 -0
- package/dist/src/db/searchIndexes/searchIndexes.js.map +1 -0
- package/dist/src/db/utils.js +212 -0
- package/dist/src/db/utils.js.map +1 -0
- package/dist/src/db/views.js +224 -0
- package/dist/src/db/views.js.map +1 -0
- package/dist/src/docIds/conversions.js +62 -0
- package/dist/src/docIds/conversions.js.map +1 -0
- package/dist/src/docIds/ids.js +125 -0
- package/dist/src/docIds/ids.js.map +1 -0
- package/dist/src/docIds/index.js +19 -0
- package/dist/src/docIds/index.js.map +1 -0
- package/dist/src/docIds/newid.js +8 -0
- package/dist/src/docIds/newid.js.map +1 -0
- package/dist/src/docIds/params.js +141 -0
- package/dist/src/docIds/params.js.map +1 -0
- package/dist/src/environment.js +182 -0
- package/dist/src/environment.js.map +1 -0
- package/dist/src/errors/errors.js +97 -0
- package/dist/src/errors/errors.js.map +1 -0
- package/dist/src/errors/index.js +18 -0
- package/dist/src/errors/index.js.map +1 -0
- package/dist/src/events/analytics.js +52 -0
- package/dist/src/events/analytics.js.map +1 -0
- package/dist/src/events/asyncEvents/index.js +19 -0
- package/dist/src/events/asyncEvents/index.js.map +1 -0
- package/dist/src/events/asyncEvents/publisher.js +26 -0
- package/dist/src/events/asyncEvents/publisher.js.map +1 -0
- package/dist/src/events/asyncEvents/queue.js +26 -0
- package/dist/src/events/asyncEvents/queue.js.map +1 -0
- package/dist/src/events/backfill.js +189 -0
- package/dist/src/events/backfill.js.map +1 -0
- package/dist/src/events/events.js +87 -0
- package/dist/src/events/events.js.map +1 -0
- package/dist/src/events/identification.js +299 -0
- package/dist/src/events/identification.js.map +1 -0
- package/dist/src/events/index.js +59 -0
- package/dist/src/events/index.js.map +1 -0
- package/dist/src/events/processors/AnalyticsProcessor.js +103 -0
- package/dist/src/events/processors/AnalyticsProcessor.js.map +1 -0
- package/dist/src/events/processors/AuditLogsProcessor.js +86 -0
- package/dist/src/events/processors/AuditLogsProcessor.js.map +1 -0
- package/dist/src/events/processors/LoggingProcessor.js +47 -0
- package/dist/src/events/processors/LoggingProcessor.js.map +1 -0
- package/dist/src/events/processors/Processors.js +52 -0
- package/dist/src/events/processors/Processors.js.map +1 -0
- package/dist/src/events/processors/index.js +23 -0
- package/dist/src/events/processors/index.js.map +1 -0
- package/dist/src/events/processors/posthog/PosthogProcessor.js +147 -0
- package/dist/src/events/processors/posthog/PosthogProcessor.js.map +1 -0
- package/dist/src/events/processors/posthog/index.js +8 -0
- package/dist/src/events/processors/posthog/index.js.map +1 -0
- package/dist/src/events/processors/posthog/rateLimiting.js +129 -0
- package/dist/src/events/processors/posthog/rateLimiting.js.map +1 -0
- package/dist/src/events/processors/types.js +3 -0
- package/dist/src/events/processors/types.js.map +1 -0
- package/dist/src/events/publishers/account.js +43 -0
- package/dist/src/events/publishers/account.js.map +1 -0
- package/dist/src/events/publishers/ai.js +30 -0
- package/dist/src/events/publishers/ai.js.map +1 -0
- package/dist/src/events/publishers/app.js +166 -0
- package/dist/src/events/publishers/app.js.map +1 -0
- package/dist/src/events/publishers/auditLog.js +34 -0
- package/dist/src/events/publishers/auditLog.js.map +1 -0
- package/dist/src/events/publishers/auth.js +80 -0
- package/dist/src/events/publishers/auth.js.map +1 -0
- package/dist/src/events/publishers/automation.js +117 -0
- package/dist/src/events/publishers/automation.js.map +1 -0
- package/dist/src/events/publishers/backfill.js +85 -0
- package/dist/src/events/publishers/backfill.js.map +1 -0
- package/dist/src/events/publishers/backup.js +41 -0
- package/dist/src/events/publishers/backup.js.map +1 -0
- package/dist/src/events/publishers/datasource.js +54 -0
- package/dist/src/events/publishers/datasource.js.map +1 -0
- package/dist/src/events/publishers/email.js +30 -0
- package/dist/src/events/publishers/email.js.map +1 -0
- package/dist/src/events/publishers/environmentVariable.js +44 -0
- package/dist/src/events/publishers/environmentVariable.js.map +1 -0
- package/dist/src/events/publishers/group.js +107 -0
- package/dist/src/events/publishers/group.js.map +1 -0
- package/dist/src/events/publishers/index.js +59 -0
- package/dist/src/events/publishers/index.js.map +1 -0
- package/dist/src/events/publishers/installation.js +52 -0
- package/dist/src/events/publishers/installation.js.map +1 -0
- package/dist/src/events/publishers/layout.js +34 -0
- package/dist/src/events/publishers/layout.js.map +1 -0
- package/dist/src/events/publishers/license.js +77 -0
- package/dist/src/events/publishers/license.js.map +1 -0
- package/dist/src/events/publishers/org.js +52 -0
- package/dist/src/events/publishers/org.js.map +1 -0
- package/dist/src/events/publishers/plugin.js +55 -0
- package/dist/src/events/publishers/plugin.js.map +1 -0
- package/dist/src/events/publishers/query.js +73 -0
- package/dist/src/events/publishers/query.js.map +1 -0
- package/dist/src/events/publishers/role.js +69 -0
- package/dist/src/events/publishers/role.js.map +1 -0
- package/dist/src/events/publishers/rowAction.js +22 -0
- package/dist/src/events/publishers/rowAction.js.map +1 -0
- package/dist/src/events/publishers/rows.js +31 -0
- package/dist/src/events/publishers/rows.js.map +1 -0
- package/dist/src/events/publishers/screen.js +46 -0
- package/dist/src/events/publishers/screen.js.map +1 -0
- package/dist/src/events/publishers/serve.js +47 -0
- package/dist/src/events/publishers/serve.js.map +1 -0
- package/dist/src/events/publishers/table.js +95 -0
- package/dist/src/events/publishers/table.js.map +1 -0
- package/dist/src/events/publishers/user.js +201 -0
- package/dist/src/events/publishers/user.js.map +1 -0
- package/dist/src/events/publishers/view.js +123 -0
- package/dist/src/events/publishers/view.js.map +1 -0
- package/dist/src/helpers.js +13 -0
- package/dist/src/helpers.js.map +1 -0
- package/dist/src/installation.js +159 -0
- package/dist/src/installation.js.map +1 -0
- package/dist/src/logging/alerts.js +23 -0
- package/dist/src/logging/alerts.js.map +1 -0
- package/dist/src/logging/correlation/correlation.js +18 -0
- package/dist/src/logging/correlation/correlation.js.map +1 -0
- package/dist/src/logging/correlation/index.js +18 -0
- package/dist/src/logging/correlation/index.js.map +1 -0
- package/dist/src/logging/index.js +45 -0
- package/dist/src/logging/index.js.map +1 -0
- package/dist/src/logging/pino/logger.js +234 -0
- package/dist/src/logging/pino/logger.js.map +1 -0
- package/dist/src/logging/system.js +110 -0
- package/dist/src/logging/system.js.map +1 -0
- package/dist/src/objectStore/buckets/app.js +95 -0
- package/dist/src/objectStore/buckets/app.js.map +1 -0
- package/dist/src/objectStore/buckets/global.js +68 -0
- package/dist/src/objectStore/buckets/global.js.map +1 -0
- package/dist/src/objectStore/buckets/index.js +20 -0
- package/dist/src/objectStore/buckets/index.js.map +1 -0
- package/dist/src/objectStore/buckets/plugins.js +104 -0
- package/dist/src/objectStore/buckets/plugins.js.map +1 -0
- package/dist/src/objectStore/cloudfront.js +73 -0
- package/dist/src/objectStore/cloudfront.js.map +1 -0
- package/dist/src/objectStore/index.js +20 -0
- package/dist/src/objectStore/index.js.map +1 -0
- package/dist/src/objectStore/objectStore.js +509 -0
- package/dist/src/objectStore/objectStore.js.map +1 -0
- package/dist/src/objectStore/utils.js +148 -0
- package/dist/src/objectStore/utils.js.map +1 -0
- package/dist/src/platform/index.js +43 -0
- package/dist/src/platform/index.js.map +1 -0
- package/dist/src/platform/platformDb.js +9 -0
- package/dist/src/platform/platformDb.js.map +1 -0
- package/dist/src/platform/tenants.js +149 -0
- package/dist/src/platform/tenants.js.map +1 -0
- package/dist/src/platform/users.js +118 -0
- package/dist/src/platform/users.js.map +1 -0
- package/dist/src/queue/constants.js +13 -0
- package/dist/src/queue/constants.js.map +1 -0
- package/dist/src/queue/inMemoryQueue.js +192 -0
- package/dist/src/queue/inMemoryQueue.js.map +1 -0
- package/dist/src/queue/index.js +19 -0
- package/dist/src/queue/index.js.map +1 -0
- package/dist/src/queue/listeners.js +199 -0
- package/dist/src/queue/listeners.js.map +1 -0
- package/dist/src/queue/queue.js +124 -0
- package/dist/src/queue/queue.js.map +1 -0
- package/dist/src/redis/index.js +47 -0
- package/dist/src/redis/index.js.map +1 -0
- package/dist/src/redis/init.js +184 -0
- package/dist/src/redis/init.js.map +1 -0
- package/dist/src/redis/redis.js +396 -0
- package/dist/src/redis/redis.js.map +1 -0
- package/dist/src/redis/redlockImpl.js +181 -0
- package/dist/src/redis/redlockImpl.js.map +1 -0
- package/dist/src/redis/utils.js +131 -0
- package/dist/src/redis/utils.js.map +1 -0
- package/dist/src/security/auth.js +26 -0
- package/dist/src/security/auth.js.map +1 -0
- package/dist/src/security/index.js +18 -0
- package/dist/src/security/index.js.map +1 -0
- package/dist/src/security/roles.js +566 -0
- package/dist/src/security/roles.js.map +1 -0
- package/dist/src/security/sessions.js +156 -0
- package/dist/src/security/sessions.js.map +1 -0
- package/dist/src/sql/utils.js +180 -0
- package/dist/src/sql/utils.js.map +1 -0
- package/dist/src/tenancy/db.js +9 -0
- package/dist/src/tenancy/db.js.map +1 -0
- package/dist/src/tenancy/index.js +19 -0
- package/dist/src/tenancy/index.js.map +1 -0
- package/dist/src/tenancy/tenancy.js +125 -0
- package/dist/src/tenancy/tenancy.js.map +1 -0
- package/dist/src/timers/index.js +18 -0
- package/dist/src/timers/index.js.map +1 -0
- package/dist/src/timers/timers.js +25 -0
- package/dist/src/timers/timers.js.map +1 -0
- package/dist/src/users/db.js +489 -0
- package/dist/src/users/db.js.map +1 -0
- package/dist/src/users/events.js +179 -0
- package/dist/src/users/events.js.map +1 -0
- package/dist/src/users/index.js +23 -0
- package/dist/src/users/index.js.map +1 -0
- package/dist/src/users/lookup.js +126 -0
- package/dist/src/users/lookup.js.map +1 -0
- package/dist/src/users/users.js +376 -0
- package/dist/src/users/users.js.map +1 -0
- package/dist/src/users/utils.js +127 -0
- package/dist/src/users/utils.js.map +1 -0
- package/dist/src/utils/Duration.js +54 -0
- package/dist/src/utils/Duration.js.map +1 -0
- package/dist/src/utils/hashing.js +46 -0
- package/dist/src/utils/hashing.js.map +1 -0
- package/dist/src/utils/index.js +21 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/stringUtils.js +8 -0
- package/dist/src/utils/stringUtils.js.map +1 -0
- package/dist/src/utils/utils.js +267 -0
- package/dist/src/utils/utils.js.map +1 -0
- package/dist/tests/core/logging.js +33 -0
- package/dist/tests/core/logging.js.map +1 -0
- package/dist/tests/core/utilities/index.js +48 -0
- package/dist/tests/core/utilities/index.js.map +1 -0
- package/dist/tests/core/utilities/jestUtils.js +21 -0
- package/dist/tests/core/utilities/jestUtils.js.map +1 -0
- package/dist/tests/core/utilities/mocks/alerts.js +40 -0
- package/dist/tests/core/utilities/mocks/alerts.js.map +1 -0
- package/dist/tests/core/utilities/mocks/date.js +6 -0
- package/dist/tests/core/utilities/mocks/date.js.map +1 -0
- package/dist/tests/core/utilities/mocks/events.js +155 -0
- package/dist/tests/core/utilities/mocks/events.js.map +1 -0
- package/dist/tests/core/utilities/mocks/index.js +47 -0
- package/dist/tests/core/utilities/mocks/index.js.map +1 -0
- package/dist/tests/core/utilities/mocks/licenses.js +109 -0
- package/dist/tests/core/utilities/mocks/licenses.js.map +1 -0
- package/dist/tests/core/utilities/queue.js +21 -0
- package/dist/tests/core/utilities/queue.js.map +1 -0
- package/dist/tests/core/utilities/structures/Chance.js +21 -0
- package/dist/tests/core/utilities/structures/Chance.js.map +1 -0
- package/dist/tests/core/utilities/structures/accounts.js +43 -0
- package/dist/tests/core/utilities/structures/accounts.js.map +1 -0
- package/dist/tests/core/utilities/structures/apps.js +23 -0
- package/dist/tests/core/utilities/structures/apps.js.map +1 -0
- package/dist/tests/core/utilities/structures/common.js +11 -0
- package/dist/tests/core/utilities/structures/common.js.map +1 -0
- package/dist/tests/core/utilities/structures/db.js +15 -0
- package/dist/tests/core/utilities/structures/db.js.map +1 -0
- package/dist/tests/core/utilities/structures/documents/index.js +18 -0
- package/dist/tests/core/utilities/structures/documents/index.js.map +1 -0
- package/dist/tests/core/utilities/structures/documents/platform/index.js +38 -0
- package/dist/tests/core/utilities/structures/documents/platform/index.js.map +1 -0
- package/dist/tests/core/utilities/structures/documents/platform/installation.js +47 -0
- package/dist/tests/core/utilities/structures/documents/platform/installation.js.map +1 -0
- package/dist/tests/core/utilities/structures/generator.js +9 -0
- package/dist/tests/core/utilities/structures/generator.js.map +1 -0
- package/dist/tests/core/utilities/structures/index.js +56 -0
- package/dist/tests/core/utilities/structures/index.js.map +1 -0
- package/dist/tests/core/utilities/structures/koa.js +10 -0
- package/dist/tests/core/utilities/structures/koa.js.map +1 -0
- package/dist/tests/core/utilities/structures/licenses.js +157 -0
- package/dist/tests/core/utilities/structures/licenses.js.map +1 -0
- package/dist/tests/core/utilities/structures/plugins.js +22 -0
- package/dist/tests/core/utilities/structures/plugins.js.map +1 -0
- package/dist/tests/core/utilities/structures/quotas.js +73 -0
- package/dist/tests/core/utilities/structures/quotas.js.map +1 -0
- package/dist/tests/core/utilities/structures/scim.js +62 -0
- package/dist/tests/core/utilities/structures/scim.js.map +1 -0
- package/dist/tests/core/utilities/structures/sso.js +140 -0
- package/dist/tests/core/utilities/structures/sso.js.map +1 -0
- package/dist/tests/core/utilities/structures/tenants.js +8 -0
- package/dist/tests/core/utilities/structures/tenants.js.map +1 -0
- package/dist/tests/core/utilities/structures/userGroups.js +12 -0
- package/dist/tests/core/utilities/structures/userGroups.js.map +1 -0
- package/dist/tests/core/utilities/structures/users.js +53 -0
- package/dist/tests/core/utilities/structures/users.js.map +1 -0
- package/dist/tests/core/utilities/testContainerUtils.js +161 -0
- package/dist/tests/core/utilities/testContainerUtils.js.map +1 -0
- package/dist/tests/core/utilities/utils/index.js +39 -0
- package/dist/tests/core/utilities/utils/index.js.map +1 -0
- package/dist/tests/core/utilities/utils/queue.js +37 -0
- package/dist/tests/core/utilities/utils/queue.js.map +1 -0
- package/dist/tests/core/utilities/utils/time.js +7 -0
- package/dist/tests/core/utilities/utils/time.js.map +1 -0
- package/dist/tests/extra/DBTestConfiguration.js +65 -0
- package/dist/tests/extra/DBTestConfiguration.js.map +1 -0
- package/dist/tests/extra/index.js +43 -0
- package/dist/tests/extra/index.js.map +1 -0
- package/dist/tests/extra/testEnv.js +136 -0
- package/dist/tests/extra/testEnv.js.map +1 -0
- package/dist/tests/index.js +19 -0
- package/dist/tests/index.js.map +1 -0
- package/dist/tests/jestEnv.js +12 -0
- package/dist/tests/jestEnv.js.map +1 -0
- package/dist/tests/jestSetup.js +33 -0
- package/dist/tests/jestSetup.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,396 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.closeAll = closeAll;
|
|
49
|
+
const environment_1 = __importDefault(require("../environment"));
|
|
50
|
+
const ioredis_1 = __importDefault(require("ioredis"));
|
|
51
|
+
// mock-redis doesn't have any typing
|
|
52
|
+
let MockRedis;
|
|
53
|
+
if (environment_1.default.MOCK_REDIS) {
|
|
54
|
+
try {
|
|
55
|
+
// ioredis mock is all in memory
|
|
56
|
+
MockRedis = require("ioredis-mock");
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
console.log("Mock redis unavailable");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const utils_1 = require("./utils");
|
|
63
|
+
const logging_1 = require("../logging");
|
|
64
|
+
const timers = __importStar(require("../timers"));
|
|
65
|
+
const RETRY_PERIOD_MS = 2000;
|
|
66
|
+
const STARTUP_TIMEOUT_MS = 5000;
|
|
67
|
+
const CLUSTERED = environment_1.default.REDIS_CLUSTERED;
|
|
68
|
+
const DEFAULT_SELECT_DB = utils_1.SelectableDatabase.DEFAULT;
|
|
69
|
+
// for testing just generate the client once
|
|
70
|
+
let CLOSED = false;
|
|
71
|
+
const CLIENTS = {};
|
|
72
|
+
let CONNECTED = false;
|
|
73
|
+
// mock redis always connected
|
|
74
|
+
if (environment_1.default.MOCK_REDIS) {
|
|
75
|
+
CONNECTED = true;
|
|
76
|
+
}
|
|
77
|
+
function pickClient(selectDb) {
|
|
78
|
+
return CLIENTS[selectDb];
|
|
79
|
+
}
|
|
80
|
+
function connectionError(timeout, err) {
|
|
81
|
+
// manually shut down, ignore errors
|
|
82
|
+
if (CLOSED) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
CLOSED = true;
|
|
86
|
+
// always clear this on error
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
CONNECTED = false;
|
|
89
|
+
(0, logging_1.logAlert)("Redis connection failed", err);
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
init();
|
|
92
|
+
}, RETRY_PERIOD_MS);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Inits the system, will error if unable to connect to redis cluster (may take up to 10 seconds) otherwise
|
|
96
|
+
* will return the ioredis client which will be ready to use.
|
|
97
|
+
*/
|
|
98
|
+
function init(selectDb = DEFAULT_SELECT_DB) {
|
|
99
|
+
const RedisCore = environment_1.default.MOCK_REDIS && MockRedis ? MockRedis : ioredis_1.default;
|
|
100
|
+
let timeout;
|
|
101
|
+
CLOSED = false;
|
|
102
|
+
let client = pickClient(selectDb);
|
|
103
|
+
// already connected, ignore
|
|
104
|
+
if (client && CONNECTED) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// testing uses a single in memory client
|
|
108
|
+
if (environment_1.default.MOCK_REDIS) {
|
|
109
|
+
CLIENTS[selectDb] = new RedisCore((0, utils_1.getRedisOptions)());
|
|
110
|
+
}
|
|
111
|
+
// start the timer - only allowed 5 seconds to connect
|
|
112
|
+
timeout = setTimeout(() => {
|
|
113
|
+
if (!CONNECTED) {
|
|
114
|
+
connectionError(timeout, "Did not successfully connect in timeout");
|
|
115
|
+
}
|
|
116
|
+
}, STARTUP_TIMEOUT_MS);
|
|
117
|
+
// disconnect any lingering client
|
|
118
|
+
if (client) {
|
|
119
|
+
client.disconnect();
|
|
120
|
+
}
|
|
121
|
+
const { host, port } = (0, utils_1.getRedisConnectionDetails)();
|
|
122
|
+
const opts = (0, utils_1.getRedisOptions)();
|
|
123
|
+
if (CLUSTERED) {
|
|
124
|
+
client = new RedisCore.Cluster([{ host, port }], opts);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
client = new RedisCore(opts);
|
|
128
|
+
}
|
|
129
|
+
// attach handlers
|
|
130
|
+
client.on("end", (err) => {
|
|
131
|
+
if (environment_1.default.isTest()) {
|
|
132
|
+
// don't try to re-connect in test env
|
|
133
|
+
// allow the process to exit
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
connectionError(timeout, err);
|
|
137
|
+
});
|
|
138
|
+
client.on("error", (err) => {
|
|
139
|
+
connectionError(timeout, err);
|
|
140
|
+
});
|
|
141
|
+
client.on("connect", () => {
|
|
142
|
+
console.log(`Connected to Redis DB: ${selectDb}`);
|
|
143
|
+
clearTimeout(timeout);
|
|
144
|
+
CONNECTED = true;
|
|
145
|
+
});
|
|
146
|
+
CLIENTS[selectDb] = client;
|
|
147
|
+
}
|
|
148
|
+
function closeAll() {
|
|
149
|
+
Object.values(CLIENTS).forEach(client => client.disconnect());
|
|
150
|
+
}
|
|
151
|
+
function waitForConnection(selectDb = DEFAULT_SELECT_DB) {
|
|
152
|
+
return new Promise(resolve => {
|
|
153
|
+
if (pickClient(selectDb) == null) {
|
|
154
|
+
init();
|
|
155
|
+
}
|
|
156
|
+
else if (CONNECTED) {
|
|
157
|
+
resolve("");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
// check if the connection is ready
|
|
161
|
+
const interval = timers.set(() => {
|
|
162
|
+
if (CONNECTED) {
|
|
163
|
+
timers.clear(interval);
|
|
164
|
+
resolve("");
|
|
165
|
+
}
|
|
166
|
+
}, 500);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Utility function, takes a redis stream and converts it to a promisified response -
|
|
171
|
+
* this can only be done with redis streams because they will have an end.
|
|
172
|
+
* @param stream A redis stream, specifically as this type of stream will have an end.
|
|
173
|
+
* @param client The client to use for further lookups.
|
|
174
|
+
* @return The final output of the stream
|
|
175
|
+
*/
|
|
176
|
+
function promisifyStream(stream, client) {
|
|
177
|
+
return new Promise((resolve, reject) => {
|
|
178
|
+
const outputKeys = new Set();
|
|
179
|
+
stream.on("data", (keys) => {
|
|
180
|
+
keys.forEach(key => {
|
|
181
|
+
outputKeys.add(key);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
stream.on("error", (err) => {
|
|
185
|
+
reject(err);
|
|
186
|
+
});
|
|
187
|
+
stream.on("end", () => __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const keysArray = Array.from(outputKeys);
|
|
189
|
+
try {
|
|
190
|
+
let getPromises = [];
|
|
191
|
+
for (let key of keysArray) {
|
|
192
|
+
getPromises.push(client.get(key));
|
|
193
|
+
}
|
|
194
|
+
const jsonArray = yield Promise.all(getPromises);
|
|
195
|
+
resolve(keysArray.map(key => ({
|
|
196
|
+
key: (0, utils_1.removeDbPrefix)(key),
|
|
197
|
+
value: JSON.parse(jsonArray.shift()),
|
|
198
|
+
})));
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
reject(err);
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
class RedisWrapper {
|
|
207
|
+
constructor(db, selectDb = null) {
|
|
208
|
+
this._db = db;
|
|
209
|
+
this._select = selectDb || DEFAULT_SELECT_DB;
|
|
210
|
+
}
|
|
211
|
+
getClient() {
|
|
212
|
+
return pickClient(this._select);
|
|
213
|
+
}
|
|
214
|
+
init() {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
CLOSED = false;
|
|
217
|
+
init(this._select);
|
|
218
|
+
yield waitForConnection(this._select);
|
|
219
|
+
if (this._select && !environment_1.default.isTest()) {
|
|
220
|
+
this.getClient().select(this._select);
|
|
221
|
+
}
|
|
222
|
+
return this;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
finish() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
CLOSED = true;
|
|
228
|
+
this.getClient().disconnect();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
scan() {
|
|
232
|
+
return __awaiter(this, arguments, void 0, function* (key = "") {
|
|
233
|
+
const db = this._db;
|
|
234
|
+
key = `${db}${utils_1.SEPARATOR}${key}`;
|
|
235
|
+
let stream;
|
|
236
|
+
if (CLUSTERED) {
|
|
237
|
+
let node = this.getClient().nodes("master");
|
|
238
|
+
stream = node[0].scanStream({ match: key + "*", count: 100 });
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
stream = this.getClient().scanStream({
|
|
242
|
+
match: key + "*",
|
|
243
|
+
count: 100,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return promisifyStream(stream, this.getClient());
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
keys(pattern) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
const db = this._db;
|
|
252
|
+
return this.getClient().keys((0, utils_1.addDbPrefix)(db, pattern));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
exists(key) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const db = this._db;
|
|
258
|
+
return yield this.getClient().exists((0, utils_1.addDbPrefix)(db, key));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
get(key) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
const db = this._db;
|
|
264
|
+
const response = yield this.getClient().get((0, utils_1.addDbPrefix)(db, key));
|
|
265
|
+
// overwrite the prefixed key
|
|
266
|
+
// @ts-ignore
|
|
267
|
+
if (response != null && response.key) {
|
|
268
|
+
// @ts-ignore
|
|
269
|
+
response.key = key;
|
|
270
|
+
}
|
|
271
|
+
// if its not an object just return the response
|
|
272
|
+
try {
|
|
273
|
+
return JSON.parse(response);
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
return response;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
bulkGet(keys) {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
const db = this._db;
|
|
283
|
+
if (keys.length === 0) {
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
const prefixedKeys = keys.map(key => (0, utils_1.addDbPrefix)(db, key));
|
|
287
|
+
let response = yield this.getClient().mget(prefixedKeys);
|
|
288
|
+
if (Array.isArray(response)) {
|
|
289
|
+
let final = {};
|
|
290
|
+
let count = 0;
|
|
291
|
+
for (let result of response) {
|
|
292
|
+
if (result) {
|
|
293
|
+
let parsed;
|
|
294
|
+
try {
|
|
295
|
+
parsed = JSON.parse(result);
|
|
296
|
+
}
|
|
297
|
+
catch (err) {
|
|
298
|
+
parsed = result;
|
|
299
|
+
}
|
|
300
|
+
final[keys[count]] = parsed;
|
|
301
|
+
}
|
|
302
|
+
count++;
|
|
303
|
+
}
|
|
304
|
+
return final;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
throw new Error(`Invalid response: ${response}`);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
store(key_1, value_1) {
|
|
312
|
+
return __awaiter(this, arguments, void 0, function* (key, value, expirySeconds = null) {
|
|
313
|
+
const db = this._db;
|
|
314
|
+
if (typeof value === "object") {
|
|
315
|
+
value = JSON.stringify(value);
|
|
316
|
+
}
|
|
317
|
+
const prefixedKey = (0, utils_1.addDbPrefix)(db, key);
|
|
318
|
+
yield this.getClient().set(prefixedKey, value);
|
|
319
|
+
if (expirySeconds) {
|
|
320
|
+
yield this.getClient().expire(prefixedKey, expirySeconds);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
bulkStore(data_1) {
|
|
325
|
+
return __awaiter(this, arguments, void 0, function* (data, expirySeconds = null) {
|
|
326
|
+
const client = this.getClient();
|
|
327
|
+
const dataToStore = Object.entries(data).reduce((acc, [key, value]) => {
|
|
328
|
+
acc[(0, utils_1.addDbPrefix)(this._db, key)] =
|
|
329
|
+
typeof value === "object" ? JSON.stringify(value) : value;
|
|
330
|
+
return acc;
|
|
331
|
+
}, {});
|
|
332
|
+
const pipeline = client.pipeline();
|
|
333
|
+
pipeline.mset(dataToStore);
|
|
334
|
+
if (expirySeconds !== null) {
|
|
335
|
+
for (const key of Object.keys(dataToStore)) {
|
|
336
|
+
pipeline.expire(key, expirySeconds);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
yield pipeline.exec();
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
getTTL(key) {
|
|
343
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
const db = this._db;
|
|
345
|
+
const prefixedKey = (0, utils_1.addDbPrefix)(db, key);
|
|
346
|
+
return this.getClient().ttl(prefixedKey);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
setExpiry(key, expirySeconds) {
|
|
350
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
351
|
+
const db = this._db;
|
|
352
|
+
const prefixedKey = (0, utils_1.addDbPrefix)(db, key);
|
|
353
|
+
yield this.getClient().expire(prefixedKey, expirySeconds);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
delete(key) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
358
|
+
const db = this._db;
|
|
359
|
+
yield this.getClient().del((0, utils_1.addDbPrefix)(db, key));
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
bulkDelete(keys) {
|
|
363
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
364
|
+
const db = this._db;
|
|
365
|
+
yield this.getClient().del(keys.map(key => (0, utils_1.addDbPrefix)(db, key)));
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
clear() {
|
|
369
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
let items = yield this.scan();
|
|
371
|
+
yield Promise.all(items.map((obj) => this.delete(obj.key)));
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
increment(key) {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
const result = yield this.getClient().incr((0, utils_1.addDbPrefix)(this._db, key));
|
|
377
|
+
if (isNaN(result)) {
|
|
378
|
+
throw new Error(`Redis ${key} does not contain a number`);
|
|
379
|
+
}
|
|
380
|
+
return result;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
deleteIfValue(key, value) {
|
|
384
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
385
|
+
const client = this.getClient();
|
|
386
|
+
const luaScript = `
|
|
387
|
+
if redis.call('GET', KEYS[1]) == ARGV[1] then
|
|
388
|
+
redis.call('DEL', KEYS[1])
|
|
389
|
+
end
|
|
390
|
+
`;
|
|
391
|
+
yield client.eval(luaScript, 1, (0, utils_1.addDbPrefix)(this._db, key), value);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
exports.default = RedisWrapper;
|
|
396
|
+
//# sourceMappingURL=redis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/redis/redis.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,4BAEC;AAnHD,iEAAgC;AAChC,sDAAwC;AACxC,qCAAqC;AACrC,IAAI,SAA0B,CAAA;AAC9B,IAAI,qBAAG,CAAC,UAAU,EAAE,CAAC;IACnB,IAAI,CAAC;QACH,gCAAgC;QAChC,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;IACvC,CAAC;AACH,CAAC;AACD,mCAOgB;AAChB,wCAAqC;AACrC,kDAAmC;AAEnC,MAAM,eAAe,GAAG,IAAI,CAAA;AAC5B,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAC/B,MAAM,SAAS,GAAG,qBAAG,CAAC,eAAe,CAAA;AACrC,MAAM,iBAAiB,GAAG,0BAAkB,CAAC,OAAO,CAAA;AAEpD,4CAA4C;AAC5C,IAAI,MAAM,GAAG,KAAK,CAAA;AAClB,MAAM,OAAO,GAA0B,EAAE,CAAA;AACzC,IAAI,SAAS,GAAG,KAAK,CAAA;AAErB,8BAA8B;AAC9B,IAAI,q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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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.AUTO_EXTEND_POLLING_MS = void 0;
|
|
49
|
+
exports.newRedlock = newRedlock;
|
|
50
|
+
exports.doWithLock = doWithLock;
|
|
51
|
+
const redlock_1 = __importDefault(require("redlock"));
|
|
52
|
+
const init_1 = require("./init");
|
|
53
|
+
const types_1 = require("@budibase/types");
|
|
54
|
+
const context = __importStar(require("../context"));
|
|
55
|
+
const shared_core_1 = require("@budibase/shared-core");
|
|
56
|
+
const utils_1 = require("../utils");
|
|
57
|
+
function getClient(type, opts) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (type === types_1.LockType.CUSTOM) {
|
|
60
|
+
return newRedlock(opts);
|
|
61
|
+
}
|
|
62
|
+
switch (type) {
|
|
63
|
+
case types_1.LockType.TRY_ONCE: {
|
|
64
|
+
return newRedlock(OPTIONS.TRY_ONCE);
|
|
65
|
+
}
|
|
66
|
+
case types_1.LockType.TRY_TWICE: {
|
|
67
|
+
return newRedlock(OPTIONS.TRY_TWICE);
|
|
68
|
+
}
|
|
69
|
+
case types_1.LockType.DEFAULT: {
|
|
70
|
+
return newRedlock(OPTIONS.DEFAULT);
|
|
71
|
+
}
|
|
72
|
+
case types_1.LockType.DELAY_500: {
|
|
73
|
+
return newRedlock(OPTIONS.DELAY_500);
|
|
74
|
+
}
|
|
75
|
+
case types_1.LockType.AUTO_EXTEND: {
|
|
76
|
+
return newRedlock(OPTIONS.AUTO_EXTEND);
|
|
77
|
+
}
|
|
78
|
+
default: {
|
|
79
|
+
throw shared_core_1.utils.unreachable(type);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const OPTIONS = {
|
|
85
|
+
TRY_ONCE: {
|
|
86
|
+
// immediately throws an error if the lock is already held
|
|
87
|
+
retryCount: 0,
|
|
88
|
+
},
|
|
89
|
+
TRY_TWICE: {
|
|
90
|
+
retryCount: 1,
|
|
91
|
+
},
|
|
92
|
+
DEFAULT: {
|
|
93
|
+
// the expected clock drift; for more details
|
|
94
|
+
// see http://redis.io/topics/distlock
|
|
95
|
+
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
96
|
+
// the max number of times Redlock will attempt
|
|
97
|
+
// to lock a resource before erroring
|
|
98
|
+
retryCount: 10,
|
|
99
|
+
// the time in ms between attempts
|
|
100
|
+
retryDelay: 200, // time in ms
|
|
101
|
+
// the max time in ms randomly added to retries
|
|
102
|
+
// to improve performance under high contention
|
|
103
|
+
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
104
|
+
retryJitter: 100, // time in ms
|
|
105
|
+
},
|
|
106
|
+
DELAY_500: {
|
|
107
|
+
retryDelay: 500,
|
|
108
|
+
},
|
|
109
|
+
CUSTOM: {},
|
|
110
|
+
AUTO_EXTEND: {
|
|
111
|
+
retryCount: -1,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
function newRedlock() {
|
|
115
|
+
return __awaiter(this, arguments, void 0, function* (opts = {}) {
|
|
116
|
+
const options = Object.assign(Object.assign({}, OPTIONS.DEFAULT), opts);
|
|
117
|
+
const redisWrapper = yield (0, init_1.getLockClient)();
|
|
118
|
+
const client = redisWrapper.getClient();
|
|
119
|
+
return new redlock_1.default([client], options);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function getLockName(opts) {
|
|
123
|
+
// determine lock name
|
|
124
|
+
// by default use the tenantId for uniqueness, unless using a system lock
|
|
125
|
+
const prefix = opts.systemLock ? "system" : context.getTenantId();
|
|
126
|
+
let name = `lock:${prefix}_${opts.name}`;
|
|
127
|
+
// add additional unique name if required
|
|
128
|
+
if (opts.resource) {
|
|
129
|
+
name = name + `_${opts.resource}`;
|
|
130
|
+
}
|
|
131
|
+
return name;
|
|
132
|
+
}
|
|
133
|
+
exports.AUTO_EXTEND_POLLING_MS = utils_1.Duration.fromSeconds(10).toMs();
|
|
134
|
+
function doWithLock(opts, task) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const redlock = yield getClient(opts.type, opts.customOptions);
|
|
137
|
+
let lock;
|
|
138
|
+
let timeout;
|
|
139
|
+
try {
|
|
140
|
+
const name = getLockName(opts);
|
|
141
|
+
const ttl = opts.type === types_1.LockType.AUTO_EXTEND ? exports.AUTO_EXTEND_POLLING_MS : opts.ttl;
|
|
142
|
+
// create the lock
|
|
143
|
+
lock = yield redlock.lock(name, ttl);
|
|
144
|
+
if (opts.type === types_1.LockType.AUTO_EXTEND) {
|
|
145
|
+
// We keep extending the lock while the task is running
|
|
146
|
+
const extendInIntervals = () => {
|
|
147
|
+
timeout = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
lock = yield lock.extend(ttl, () => opts.onExtend && opts.onExtend());
|
|
149
|
+
extendInIntervals();
|
|
150
|
+
}), ttl / 2);
|
|
151
|
+
};
|
|
152
|
+
extendInIntervals();
|
|
153
|
+
}
|
|
154
|
+
// perform locked task
|
|
155
|
+
// need to await to ensure completion before unlocking
|
|
156
|
+
const result = yield task();
|
|
157
|
+
return { executed: true, result };
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
// lock limit exceeded
|
|
161
|
+
if (e.name === "LockError") {
|
|
162
|
+
if (opts.type === types_1.LockType.TRY_ONCE) {
|
|
163
|
+
// don't throw for try-once locks, they will always error
|
|
164
|
+
// due to retry count (0) exceeded
|
|
165
|
+
return { executed: false };
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw e;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
clearTimeout(timeout);
|
|
177
|
+
yield (lock === null || lock === void 0 ? void 0 : lock.unlock());
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=redlockImpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redlockImpl.js","sourceRoot":"","sources":["../../../src/redis/redlockImpl.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,gCAKC;AA4BD,gCAkDC;AA1JD,sDAA6B;AAC7B,iCAAsC;AACtC,2CAAuD;AACvD,oDAAqC;AACrC,uDAA6C;AAC7C,oCAAmC;AAEnC,SAAe,SAAS,CACtB,IAAc,EACd,IAAsB;;QAEtB,IAAI,IAAI,KAAK,gBAAQ,CAAC,MAAM,EAAE,CAAC;YAC7B,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;QAED,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,gBAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACvB,OAAO,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACrC,CAAC;YACD,KAAK,gBAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;gBACxB,OAAO,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;YACtC,CAAC;YACD,KAAK,gBAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;gBACtB,OAAO,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YACpC,CAAC;YACD,KAAK,gBAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;gBACxB,OAAO,UAAU,C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