@bitblit/ratchet-aws 4.0.115-alpha → 4.0.119-alpha
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/lib/build/ratchet-aws-info.d.ts +1 -1
- package/lib/cloudwatch/cloud-watch-log-group-ratchet.d.ts +1 -0
- package/lib/cloudwatch/cloud-watch-logs-ratchet.d.ts +1 -0
- package/lib/cloudwatch/cloud-watch-metrics-ratchet.d.ts +2 -1
- package/lib/daemon/daemon-like.d.ts +1 -1
- package/lib/daemon/daemon-process-state-public-token.d.ts +1 -1
- package/lib/daemon/daemon-util.d.ts +2 -2
- package/lib/daemon/daemon.d.ts +2 -2
- package/lib/dynamodb/dynamo-ratchet.d.ts +1 -0
- package/lib/ec2/ec2-ratchet.d.ts +4 -2
- package/lib/index.d.ts +78 -1
- package/lib/index.mjs +11 -0
- package/lib/index.mjs.map +1 -0
- package/lib/model/cloud-watch-metrics-minute-level-dynamo-count-request.d.ts +1 -1
- package/lib/route53/route-53-ratchet.d.ts +1 -0
- package/lib/s3/s3-cache-ratchet.d.ts +3 -2
- package/lib/s3/s3-cache-to-local-disk-ratchet.d.ts +1 -1
- package/lib/ses/mailer.d.ts +1 -0
- package/lib/sns/sns-ratchet.d.ts +1 -0
- package/package.json +33 -103
- package/lib/batch/aws-batch-background-processor.js +0 -45
- package/lib/batch/aws-batch-background-processor.spec.js +0 -15
- package/lib/batch/aws-batch-ratchet.js +0 -55
- package/lib/batch/aws-batch-ratchet.spec.js +0 -33
- package/lib/build/ratchet-aws-info.js +0 -14
- package/lib/cache/dynamo-db-storage-provider.js +0 -109
- package/lib/cache/s3-storage-provider.js +0 -43
- package/lib/cache/simple-cache-object-wrapper.js +0 -1
- package/lib/cache/simple-cache-read-options.js +0 -1
- package/lib/cache/simple-cache-storage-provider.js +0 -1
- package/lib/cache/simple-cache.js +0 -64
- package/lib/cache/simple-cache.spec.js +0 -67
- package/lib/cloudwatch/cloud-watch-log-group-ratchet.js +0 -71
- package/lib/cloudwatch/cloud-watch-log-group-ratchet.spec.js +0 -19
- package/lib/cloudwatch/cloud-watch-logs-ratchet.js +0 -170
- package/lib/cloudwatch/cloud-watch-logs-ratchet.spec.js +0 -84
- package/lib/cloudwatch/cloud-watch-metrics-ratchet.js +0 -54
- package/lib/cloudwatch/cloud-watch-metrics-ratchet.spec.js +0 -23
- package/lib/daemon/daemon-like.js +0 -1
- package/lib/daemon/daemon-process-create-options.js +0 -1
- package/lib/daemon/daemon-process-state-public-token.js +0 -1
- package/lib/daemon/daemon-process-state.js +0 -1
- package/lib/daemon/daemon-util.js +0 -148
- package/lib/daemon/daemon-util.spec.js +0 -79
- package/lib/daemon/daemon.js +0 -128
- package/lib/dao/prototype-dao-config.js +0 -1
- package/lib/dao/prototype-dao-db.js +0 -1
- package/lib/dao/prototype-dao-provider.js +0 -1
- package/lib/dao/prototype-dao.js +0 -88
- package/lib/dao/prototype-dao.spec.js +0 -26
- package/lib/dao/s3-prototype-dao-provider.js +0 -26
- package/lib/dao/s3-simple-dao.js +0 -76
- package/lib/dao/simple-dao-item.js +0 -1
- package/lib/dynamodb/dynamo-ratchet-like.js +0 -1
- package/lib/dynamodb/dynamo-ratchet.js +0 -666
- package/lib/dynamodb/dynamo-ratchet.spec.js +0 -156
- package/lib/dynamodb/dynamo-table-ratchet.js +0 -88
- package/lib/dynamodb/hash-spreader.js +0 -65
- package/lib/dynamodb/hash-spreader.spec.js +0 -17
- package/lib/ec2/ec2-ratchet.js +0 -107
- package/lib/ec2/ec2-ratchet.spec.js +0 -31
- package/lib/environment/cascade-environment-service-provider.js +0 -24
- package/lib/environment/env-var-environment-service-provider.js +0 -30
- package/lib/environment/environment-service-config.js +0 -1
- package/lib/environment/environment-service-provider.js +0 -1
- package/lib/environment/environment-service.js +0 -50
- package/lib/environment/environment-service.spec.js +0 -22
- package/lib/environment/fixed-environment-service-provider.js +0 -21
- package/lib/environment/s3-environment-service-provider.js +0 -27
- package/lib/environment/ssm-environment-service-provider.js +0 -59
- package/lib/expiring-code/dynamo-expiring-code-provider.js +0 -24
- package/lib/expiring-code/expiring-code-params.js +0 -1
- package/lib/expiring-code/expiring-code-provider.js +0 -1
- package/lib/expiring-code/expiring-code-ratchet.js +0 -34
- package/lib/expiring-code/expiring-code-ratchet.spec.js +0 -7
- package/lib/expiring-code/expiring-code.js +0 -1
- package/lib/expiring-code/s3-expiring-code-provider.js +0 -48
- package/lib/expiring-code/s3-expiring-code-provider.spec.js +0 -46
- package/lib/iam/aws-credentials-ratchet.js +0 -18
- package/lib/index.js +0 -1
- package/lib/lambda/lambda-event-detector.js +0 -38
- package/lib/lambda/lambda-event-type-guards.js +0 -24
- package/lib/model/cloud-watch-metrics-minute-level-dynamo-count-request.js +0 -1
- package/lib/model/cloud-watch-metrics-unit.js +0 -30
- package/lib/model/dynamo/doc-put-item-command-input.js +0 -1
- package/lib/model/dynamo/doc-query-command-input.js +0 -1
- package/lib/model/dynamo/doc-scan-command-input.js +0 -1
- package/lib/model/dynamo/doc-update-item-command-input.js +0 -1
- package/lib/model/dynamo-count-result.js +0 -1
- package/lib/route53/route-53-ratchet.js +0 -55
- package/lib/runtime-parameter/cached-stored-runtime-parameter.js +0 -1
- package/lib/runtime-parameter/dynamo-runtime-parameter-provider.js +0 -36
- package/lib/runtime-parameter/dynamo-runtime-parameter-provider.spec.js +0 -49
- package/lib/runtime-parameter/global-variable-override-runtime-parameter-provider.js +0 -51
- package/lib/runtime-parameter/global-variable-override-runtime-parameter-provider.spec.js +0 -37
- package/lib/runtime-parameter/memory-runtime-parameter-provider.js +0 -27
- package/lib/runtime-parameter/runtime-parameter-provider.js +0 -1
- package/lib/runtime-parameter/runtime-parameter-ratchet.js +0 -71
- package/lib/runtime-parameter/runtime-parameter-ratchet.spec.js +0 -39
- package/lib/runtime-parameter/stored-runtime-parameter.js +0 -1
- package/lib/s3/s3-cache-ratchet.js +0 -330
- package/lib/s3/s3-cache-ratchet.spec.js +0 -97
- package/lib/s3/s3-cache-to-local-disk-ratchet.js +0 -105
- package/lib/s3/s3-cache-to-local-dist-ratchet.spec.js +0 -22
- package/lib/s3/s3-location-sync-ratchet.js +0 -140
- package/lib/s3/s3-ratchet.js +0 -22
- package/lib/s3/s3-ratchet.spec.js +0 -20
- package/lib/ses/email-attachment.js +0 -1
- package/lib/ses/mailer-config.js +0 -1
- package/lib/ses/mailer-like.js +0 -1
- package/lib/ses/mailer.js +0 -206
- package/lib/ses/mailer.spec.js +0 -104
- package/lib/ses/ratchet-template-renderer.js +0 -1
- package/lib/ses/ready-to-send-email.js +0 -1
- package/lib/ses/remote-handlebars-template-renderer.js +0 -78
- package/lib/ses/resolved-ready-to-send-email.js +0 -1
- package/lib/sns/sns-ratchet.js +0 -45
- package/lib/sns/sns-ratchet.spec.js +0 -17
- package/lib/sync-lock/dynamo-db-sync-lock.js +0 -69
- package/lib/sync-lock/dynamo-db-sync-lock.spec.js +0 -30
- package/lib/sync-lock/memory-sync-lock.js +0 -35
- package/lib/sync-lock/sync-lock-provider.js +0 -1
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
2
|
-
import { RequireRatchet } from '@bitblit/ratchet-common/lib/lang/require-ratchet.js';
|
|
3
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
4
|
-
import { PutItemCommand } from '@aws-sdk/client-dynamodb';
|
|
5
|
-
export class DynamoDbSyncLock {
|
|
6
|
-
ratchet;
|
|
7
|
-
tableName;
|
|
8
|
-
constructor(ratchet, tableName) {
|
|
9
|
-
this.ratchet = ratchet;
|
|
10
|
-
this.tableName = tableName;
|
|
11
|
-
RequireRatchet.notNullOrUndefined(ratchet, 'ratchet');
|
|
12
|
-
RequireRatchet.notNullOrUndefined(StringRatchet.trimToNull(this.tableName), 'tableName');
|
|
13
|
-
}
|
|
14
|
-
async acquireLock(lockKey, expirationSeconds = 30) {
|
|
15
|
-
let rval = false;
|
|
16
|
-
if (!!lockKey && !!expirationSeconds) {
|
|
17
|
-
const nowSeconds = Math.floor(new Date().getTime() / 1000);
|
|
18
|
-
const row = {
|
|
19
|
-
lockingKey: lockKey,
|
|
20
|
-
timestamp: nowSeconds,
|
|
21
|
-
expires: nowSeconds + expirationSeconds,
|
|
22
|
-
};
|
|
23
|
-
const params = {
|
|
24
|
-
Item: row,
|
|
25
|
-
ReturnConsumedCapacity: 'TOTAL',
|
|
26
|
-
TableName: this.tableName,
|
|
27
|
-
ConditionExpression: 'attribute_not_exists(lockingKey)',
|
|
28
|
-
};
|
|
29
|
-
try {
|
|
30
|
-
const pio = await this.ratchet.getDDB().send(new PutItemCommand(params));
|
|
31
|
-
rval = true;
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
if (String(err).indexOf('ConditionalCheckFailedException') > -1) {
|
|
35
|
-
Logger.silly('Unable to acquire lock on %s', lockKey);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return rval;
|
|
40
|
-
}
|
|
41
|
-
async releaseLock(lockKey) {
|
|
42
|
-
if (StringRatchet.trimToNull(lockKey)) {
|
|
43
|
-
try {
|
|
44
|
-
const dio = await this.ratchet.simpleDelete(this.tableName, { lockingKey: lockKey });
|
|
45
|
-
Logger.silly('Released lock %s : %s', lockKey, dio);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
Logger.warn('Failed to release lock key : %s : %s', lockKey, err, err);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async clearExpiredSyncLocks() {
|
|
53
|
-
const nowSeconds = Math.floor(new Date().getTime() / 1000);
|
|
54
|
-
const scan = {
|
|
55
|
-
TableName: this.tableName,
|
|
56
|
-
FilterExpression: 'expires < :now',
|
|
57
|
-
ExpressionAttributeValues: {
|
|
58
|
-
':now': nowSeconds,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
const vals = await this.ratchet.fullyExecuteScan(scan);
|
|
62
|
-
const keysOnly = vals.map((v) => {
|
|
63
|
-
const next = { lockingKey: v['lockingKey'] };
|
|
64
|
-
return next;
|
|
65
|
-
});
|
|
66
|
-
const removed = await this.ratchet.deleteAllInBatches(this.tableName, keysOnly, 25);
|
|
67
|
-
return removed;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { DynamoDbSyncLock } from './dynamo-db-sync-lock.js';
|
|
2
|
-
import { Logger } from '@bitblit/ratchet-common/lib/logger/logger.js';
|
|
3
|
-
import { JestRatchet } from '@bitblit/ratchet-jest/lib/jest/jest-ratchet.js';
|
|
4
|
-
import { jest } from '@jest/globals';
|
|
5
|
-
let mockDR;
|
|
6
|
-
describe('#syncLockService', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
mockDR = JestRatchet.mock(jest.fn);
|
|
9
|
-
});
|
|
10
|
-
xit('should test sync locks', async () => {
|
|
11
|
-
const svc = new DynamoDbSyncLock(mockDR, 'test-table');
|
|
12
|
-
const lockTestValue = 'SYNC_LOCK_TEST';
|
|
13
|
-
const aq1 = await svc.acquireLock(lockTestValue);
|
|
14
|
-
expect(aq1).toBe(true);
|
|
15
|
-
const aq2 = await svc.acquireLock(lockTestValue);
|
|
16
|
-
expect(aq2).toBe(false);
|
|
17
|
-
await svc.releaseLock(lockTestValue);
|
|
18
|
-
const aq3 = await svc.acquireLock(lockTestValue);
|
|
19
|
-
expect(aq3).toBe(true);
|
|
20
|
-
await svc.releaseLock(lockTestValue);
|
|
21
|
-
});
|
|
22
|
-
it('should clear expired sync locks', async () => {
|
|
23
|
-
mockDR.fullyExecuteScan.mockResolvedValue([{ lockingKey: 'aa' }, { lockingKey: 'ab' }]);
|
|
24
|
-
mockDR.deleteAllInBatches.mockResolvedValue(2);
|
|
25
|
-
const svc = new DynamoDbSyncLock(mockDR, 'test-table');
|
|
26
|
-
const res = await svc.clearExpiredSyncLocks();
|
|
27
|
-
Logger.info('Got : %s', res);
|
|
28
|
-
expect(res).toEqual(2);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { StringRatchet } from '@bitblit/ratchet-common/lib/lang/string-ratchet.js';
|
|
2
|
-
export class MemorySyncLock {
|
|
3
|
-
_locks = new Map();
|
|
4
|
-
constructor() { }
|
|
5
|
-
async acquireLock(lockKey, expirationSeconds = 30) {
|
|
6
|
-
let rval = false;
|
|
7
|
-
if (StringRatchet.trimToNull(lockKey)) {
|
|
8
|
-
const now = Date.now();
|
|
9
|
-
const val = this._locks.get(lockKey);
|
|
10
|
-
if (!val || val < now) {
|
|
11
|
-
this._locks.set(lockKey, now + expirationSeconds * 1000);
|
|
12
|
-
rval = true;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return rval;
|
|
16
|
-
}
|
|
17
|
-
async releaseLock(lockKey) {
|
|
18
|
-
if (StringRatchet.trimToNull(lockKey)) {
|
|
19
|
-
this._locks.delete(lockKey);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async clearExpiredSyncLocks() {
|
|
23
|
-
const toRemove = [];
|
|
24
|
-
const now = Date.now();
|
|
25
|
-
this._locks.forEach((v, k) => {
|
|
26
|
-
if (v < now) {
|
|
27
|
-
toRemove.push(k);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
toRemove.forEach((k) => {
|
|
31
|
-
this._locks.delete(k);
|
|
32
|
-
});
|
|
33
|
-
return toRemove.length;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|