@bitblit/ratchet-aws 4.0.80-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/dist/cjs/batch/aws-batch-background-processor.js +44 -0
- package/dist/cjs/batch/aws-batch-ratchet.js +55 -0
- package/dist/cjs/build/ratchet-aws-info.js +18 -0
- package/dist/cjs/cache/dynamo-db-storage-provider.js +111 -0
- package/dist/cjs/cache/s3-storage-provider.js +44 -0
- package/dist/cjs/cache/simple-cache-object-wrapper.js +2 -0
- package/dist/cjs/cache/simple-cache-read-options.js +2 -0
- package/dist/cjs/cache/simple-cache-storage-provider.js +2 -0
- package/dist/cjs/cache/simple-cache.js +66 -0
- package/dist/cjs/cloudwatch/cloud-watch-log-group-ratchet.js +73 -0
- package/dist/cjs/cloudwatch/cloud-watch-logs-ratchet.js +173 -0
- package/dist/cjs/cloudwatch/cloud-watch-metrics-ratchet.js +57 -0
- package/dist/cjs/daemon/daemon-like.js +2 -0
- package/dist/cjs/daemon/daemon-process-create-options.js +2 -0
- package/dist/cjs/daemon/daemon-process-state-public-token.js +2 -0
- package/dist/cjs/daemon/daemon-process-state.js +2 -0
- package/dist/cjs/daemon/daemon-util.js +152 -0
- package/dist/cjs/daemon/daemon.js +126 -0
- package/dist/cjs/dao/prototype-dao-config.js +2 -0
- package/dist/cjs/dao/prototype-dao-db.js +2 -0
- package/dist/cjs/dao/prototype-dao-provider.js +2 -0
- package/dist/cjs/dao/prototype-dao.js +88 -0
- package/dist/cjs/dao/s3-prototype-dao-provider.js +28 -0
- package/dist/cjs/dao/s3-simple-dao.js +78 -0
- package/dist/cjs/dao/simple-dao-item.js +2 -0
- package/dist/cjs/dynamodb/dynamo-ratchet-like.js +2 -0
- package/dist/cjs/dynamodb/dynamo-ratchet.js +667 -0
- package/dist/cjs/dynamodb/dynamo-table-ratchet.js +91 -0
- package/dist/cjs/dynamodb/hash-spreader.js +62 -0
- package/dist/cjs/ec2/ec2-ratchet.js +107 -0
- package/dist/cjs/environment/cascade-environment-service-provider.js +27 -0
- package/dist/cjs/environment/env-var-environment-service-provider.js +33 -0
- package/dist/cjs/environment/environment-service-config.js +2 -0
- package/dist/cjs/environment/environment-service-provider.js +2 -0
- package/dist/cjs/environment/environment-service.js +52 -0
- package/dist/cjs/environment/fixed-environment-service-provider.js +24 -0
- package/dist/cjs/environment/s3-environment-service-provider.js +29 -0
- package/dist/cjs/environment/ssm-environment-service-provider.js +61 -0
- package/dist/cjs/expiring-code/dynamo-expiring-code-provider.js +26 -0
- package/dist/cjs/expiring-code/expiring-code-params.js +2 -0
- package/dist/cjs/expiring-code/expiring-code-provider.js +2 -0
- package/dist/cjs/expiring-code/expiring-code-ratchet.js +37 -0
- package/dist/cjs/expiring-code/expiring-code.js +2 -0
- package/dist/cjs/expiring-code/s3-expiring-code-provider.js +49 -0
- package/dist/cjs/iam/aws-credentials-ratchet.js +21 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/lambda/lambda-event-detector.js +42 -0
- package/dist/cjs/lambda/lambda-event-type-guards.js +28 -0
- package/dist/cjs/model/cloud-watch-metrics-minute-level-dynamo-count-request.js +2 -0
- package/dist/cjs/model/cloud-watch-metrics-unit.js +33 -0
- package/dist/cjs/model/dynamo/doc-put-item-command-input.js +2 -0
- package/dist/cjs/model/dynamo/doc-query-command-input.js +2 -0
- package/dist/cjs/model/dynamo/doc-scan-command-input.js +2 -0
- package/dist/cjs/model/dynamo/doc-update-item-command-input.js +2 -0
- package/dist/cjs/model/dynamo-count-result.js +2 -0
- package/dist/cjs/route53/route-53-ratchet.js +57 -0
- package/dist/cjs/runtime-parameter/cached-stored-runtime-parameter.js +2 -0
- package/dist/cjs/runtime-parameter/dynamo-runtime-parameter-provider.js +38 -0
- package/dist/cjs/runtime-parameter/global-variable-override-runtime-parameter-provider.js +54 -0
- package/dist/cjs/runtime-parameter/memory-runtime-parameter-provider.js +30 -0
- package/dist/cjs/runtime-parameter/runtime-parameter-provider.js +2 -0
- package/dist/cjs/runtime-parameter/runtime-parameter-ratchet.js +74 -0
- package/dist/cjs/runtime-parameter/stored-runtime-parameter.js +2 -0
- package/dist/cjs/s3/s3-cache-ratchet.js +332 -0
- package/dist/cjs/s3/s3-cache-to-local-disk-ratchet.js +105 -0
- package/dist/cjs/s3/s3-location-sync-ratchet.js +142 -0
- package/dist/cjs/s3/s3-ratchet.js +26 -0
- package/dist/cjs/ses/email-attachment.js +2 -0
- package/dist/cjs/ses/mailer-config.js +2 -0
- package/dist/cjs/ses/mailer-like.js +2 -0
- package/dist/cjs/ses/mailer.js +208 -0
- package/dist/cjs/ses/ratchet-template-renderer.js +2 -0
- package/dist/cjs/ses/ready-to-send-email.js +2 -0
- package/dist/cjs/ses/remote-handlebars-template-renderer.js +79 -0
- package/dist/cjs/ses/resolved-ready-to-send-email.js +2 -0
- package/dist/cjs/sns/sns-ratchet.js +47 -0
- package/dist/cjs/sync-lock/dynamo-db-sync-lock.js +69 -0
- package/dist/cjs/sync-lock/memory-sync-lock.js +40 -0
- package/dist/cjs/sync-lock/sync-lock-provider.js +2 -0
- package/dist/es/batch/aws-batch-background-processor.js +40 -0
- package/dist/es/batch/aws-batch-ratchet.js +51 -0
- package/dist/es/build/ratchet-aws-info.js +14 -0
- package/dist/es/cache/dynamo-db-storage-provider.js +107 -0
- package/dist/es/cache/s3-storage-provider.js +40 -0
- package/dist/es/cache/simple-cache-object-wrapper.js +1 -0
- package/dist/es/cache/simple-cache-read-options.js +1 -0
- package/dist/es/cache/simple-cache-storage-provider.js +1 -0
- package/dist/es/cache/simple-cache.js +62 -0
- package/dist/es/cloudwatch/cloud-watch-log-group-ratchet.js +69 -0
- package/dist/es/cloudwatch/cloud-watch-logs-ratchet.js +169 -0
- package/dist/es/cloudwatch/cloud-watch-metrics-ratchet.js +53 -0
- package/dist/es/daemon/daemon-like.js +1 -0
- package/dist/es/daemon/daemon-process-create-options.js +1 -0
- package/dist/es/daemon/daemon-process-state-public-token.js +1 -0
- package/dist/es/daemon/daemon-process-state.js +1 -0
- package/dist/es/daemon/daemon-util.js +148 -0
- package/dist/es/daemon/daemon.js +122 -0
- package/dist/es/dao/prototype-dao-config.js +1 -0
- package/dist/es/dao/prototype-dao-db.js +1 -0
- package/dist/es/dao/prototype-dao-provider.js +1 -0
- package/dist/es/dao/prototype-dao.js +84 -0
- package/dist/es/dao/s3-prototype-dao-provider.js +24 -0
- package/dist/es/dao/s3-simple-dao.js +74 -0
- package/dist/es/dao/simple-dao-item.js +1 -0
- package/dist/es/dynamodb/dynamo-ratchet-like.js +1 -0
- package/dist/es/dynamodb/dynamo-ratchet.js +663 -0
- package/dist/es/dynamodb/dynamo-table-ratchet.js +87 -0
- package/dist/es/dynamodb/hash-spreader.js +58 -0
- package/dist/es/ec2/ec2-ratchet.js +103 -0
- package/dist/es/environment/cascade-environment-service-provider.js +23 -0
- package/dist/es/environment/env-var-environment-service-provider.js +29 -0
- package/dist/es/environment/environment-service-config.js +1 -0
- package/dist/es/environment/environment-service-provider.js +1 -0
- package/dist/es/environment/environment-service.js +48 -0
- package/dist/es/environment/fixed-environment-service-provider.js +20 -0
- package/dist/es/environment/s3-environment-service-provider.js +25 -0
- package/dist/es/environment/ssm-environment-service-provider.js +56 -0
- package/dist/es/expiring-code/dynamo-expiring-code-provider.js +22 -0
- package/dist/es/expiring-code/expiring-code-params.js +1 -0
- package/dist/es/expiring-code/expiring-code-provider.js +1 -0
- package/dist/es/expiring-code/expiring-code-ratchet.js +33 -0
- package/dist/es/expiring-code/expiring-code.js +1 -0
- package/dist/es/expiring-code/s3-expiring-code-provider.js +45 -0
- package/dist/es/iam/aws-credentials-ratchet.js +17 -0
- package/dist/es/index.js +78 -0
- package/dist/es/lambda/lambda-event-detector.js +38 -0
- package/dist/es/lambda/lambda-event-type-guards.js +24 -0
- package/dist/es/model/cloud-watch-metrics-minute-level-dynamo-count-request.js +1 -0
- package/dist/es/model/cloud-watch-metrics-unit.js +30 -0
- package/dist/es/model/dynamo/doc-put-item-command-input.js +1 -0
- package/dist/es/model/dynamo/doc-query-command-input.js +1 -0
- package/dist/es/model/dynamo/doc-scan-command-input.js +1 -0
- package/dist/es/model/dynamo/doc-update-item-command-input.js +1 -0
- package/dist/es/model/dynamo-count-result.js +1 -0
- package/dist/es/route53/route-53-ratchet.js +53 -0
- package/dist/es/runtime-parameter/cached-stored-runtime-parameter.js +1 -0
- package/dist/es/runtime-parameter/dynamo-runtime-parameter-provider.js +34 -0
- package/dist/es/runtime-parameter/global-variable-override-runtime-parameter-provider.js +49 -0
- package/dist/es/runtime-parameter/memory-runtime-parameter-provider.js +26 -0
- package/dist/es/runtime-parameter/runtime-parameter-provider.js +1 -0
- package/dist/es/runtime-parameter/runtime-parameter-ratchet.js +70 -0
- package/dist/es/runtime-parameter/stored-runtime-parameter.js +1 -0
- package/dist/es/s3/s3-cache-ratchet.js +328 -0
- package/dist/es/s3/s3-cache-to-local-disk-ratchet.js +100 -0
- package/dist/es/s3/s3-location-sync-ratchet.js +137 -0
- package/dist/es/s3/s3-ratchet.js +22 -0
- package/dist/es/ses/email-attachment.js +1 -0
- package/dist/es/ses/mailer-config.js +1 -0
- package/dist/es/ses/mailer-like.js +1 -0
- package/dist/es/ses/mailer.js +204 -0
- package/dist/es/ses/ratchet-template-renderer.js +1 -0
- package/dist/es/ses/ready-to-send-email.js +1 -0
- package/dist/es/ses/remote-handlebars-template-renderer.js +74 -0
- package/dist/es/ses/resolved-ready-to-send-email.js +1 -0
- package/dist/es/sns/sns-ratchet.js +43 -0
- package/dist/es/sync-lock/dynamo-db-sync-lock.js +65 -0
- package/dist/es/sync-lock/memory-sync-lock.js +36 -0
- package/dist/es/sync-lock/sync-lock-provider.js +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.es.tsbuildinfo +1 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/batch/aws-batch-background-processor.d.ts +12 -0
- package/dist/types/batch/aws-batch-ratchet.d.ts +16 -0
- package/dist/types/build/ratchet-aws-info.d.ts +5 -0
- package/dist/types/cache/dynamo-db-storage-provider.d.ts +25 -0
- package/dist/types/cache/s3-storage-provider.d.ts +14 -0
- package/dist/types/cache/simple-cache-object-wrapper.d.ts +7 -0
- package/dist/types/cache/simple-cache-read-options.d.ts +5 -0
- package/dist/types/cache/simple-cache-storage-provider.d.ts +8 -0
- package/dist/types/cache/simple-cache.d.ts +14 -0
- package/dist/types/cloudwatch/cloud-watch-log-group-ratchet.d.ts +9 -0
- package/dist/types/cloudwatch/cloud-watch-logs-ratchet.d.ts +14 -0
- package/dist/types/cloudwatch/cloud-watch-metrics-ratchet.d.ts +10 -0
- package/dist/types/daemon/daemon-like.d.ts +17 -0
- package/dist/types/daemon/daemon-process-create-options.d.ts +7 -0
- package/dist/types/daemon/daemon-process-state-public-token.d.ts +4 -0
- package/dist/types/daemon/daemon-process-state.d.ts +13 -0
- package/dist/types/daemon/daemon-util.d.ts +24 -0
- package/dist/types/daemon/daemon.d.ts +33 -0
- package/dist/types/dao/prototype-dao-config.d.ts +8 -0
- package/dist/types/dao/prototype-dao-db.d.ts +4 -0
- package/dist/types/dao/prototype-dao-provider.d.ts +5 -0
- package/dist/types/dao/prototype-dao.d.ts +15 -0
- package/dist/types/dao/s3-prototype-dao-provider.d.ts +10 -0
- package/dist/types/dao/s3-simple-dao.d.ts +15 -0
- package/dist/types/dao/simple-dao-item.d.ts +5 -0
- package/dist/types/dynamodb/dynamo-ratchet-like.d.ts +27 -0
- package/dist/types/dynamodb/dynamo-ratchet.d.ts +36 -0
- package/dist/types/dynamodb/dynamo-table-ratchet.d.ts +11 -0
- package/dist/types/dynamodb/hash-spreader.d.ts +15 -0
- package/dist/types/ec2/ec2-ratchet.d.ts +25 -0
- package/dist/types/environment/cascade-environment-service-provider.d.ts +9 -0
- package/dist/types/environment/env-var-environment-service-provider.d.ts +10 -0
- package/dist/types/environment/environment-service-config.d.ts +7 -0
- package/dist/types/environment/environment-service-provider.d.ts +7 -0
- package/dist/types/environment/environment-service.d.ts +14 -0
- package/dist/types/environment/fixed-environment-service-provider.d.ts +10 -0
- package/dist/types/environment/s3-environment-service-provider.d.ts +18 -0
- package/dist/types/environment/ssm-environment-service-provider.d.ts +12 -0
- package/dist/types/expiring-code/dynamo-expiring-code-provider.d.ts +12 -0
- package/dist/types/expiring-code/expiring-code-params.d.ts +7 -0
- package/dist/types/expiring-code/expiring-code-provider.d.ts +5 -0
- package/dist/types/expiring-code/expiring-code-ratchet.d.ts +13 -0
- package/dist/types/expiring-code/expiring-code.d.ts +6 -0
- package/dist/types/expiring-code/s3-expiring-code-provider.d.ts +17 -0
- package/dist/types/iam/aws-credentials-ratchet.d.ts +9 -0
- package/dist/types/index.d.ts +81 -0
- package/dist/types/lambda/lambda-event-detector.d.ts +14 -0
- package/dist/types/lambda/lambda-event-type-guards.d.ts +10 -0
- package/dist/types/model/cloud-watch-metrics-minute-level-dynamo-count-request.d.ts +12 -0
- package/dist/types/model/cloud-watch-metrics-unit.d.ts +29 -0
- package/dist/types/model/dynamo/doc-put-item-command-input.d.ts +4 -0
- package/dist/types/model/dynamo/doc-query-command-input.d.ts +5 -0
- package/dist/types/model/dynamo/doc-scan-command-input.d.ts +5 -0
- package/dist/types/model/dynamo/doc-update-item-command-input.d.ts +5 -0
- package/dist/types/model/dynamo-count-result.d.ts +5 -0
- package/dist/types/route53/route-53-ratchet.d.ts +7 -0
- package/dist/types/runtime-parameter/cached-stored-runtime-parameter.d.ts +4 -0
- package/dist/types/runtime-parameter/dynamo-runtime-parameter-provider.d.ts +11 -0
- package/dist/types/runtime-parameter/global-variable-override-runtime-parameter-provider.d.ts +24 -0
- package/dist/types/runtime-parameter/memory-runtime-parameter-provider.d.ts +13 -0
- package/dist/types/runtime-parameter/runtime-parameter-provider.d.ts +11 -0
- package/dist/types/runtime-parameter/runtime-parameter-ratchet.d.ts +15 -0
- package/dist/types/runtime-parameter/stored-runtime-parameter.d.ts +6 -0
- package/dist/types/s3/s3-cache-ratchet.d.ts +38 -0
- package/dist/types/s3/s3-cache-to-local-disk-ratchet.d.ts +21 -0
- package/dist/types/s3/s3-location-sync-ratchet.d.ts +21 -0
- package/dist/types/s3/s3-ratchet.d.ts +5 -0
- package/dist/types/ses/email-attachment.d.ts +23 -0
- package/dist/types/ses/mailer-config.d.ts +15 -0
- package/dist/types/ses/mailer-like.d.ts +18 -0
- package/dist/types/ses/mailer.d.ts +26 -0
- package/dist/types/ses/ratchet-template-renderer.d.ts +8 -0
- package/dist/types/ses/ready-to-send-email.d.ts +66 -0
- package/dist/types/ses/remote-handlebars-template-renderer.d.ts +15 -0
- package/dist/types/ses/resolved-ready-to-send-email.d.ts +16 -0
- package/dist/types/sns/sns-ratchet.d.ts +8 -0
- package/dist/types/sync-lock/dynamo-db-sync-lock.d.ts +10 -0
- package/dist/types/sync-lock/memory-sync-lock.d.ts +11 -0
- package/dist/types/sync-lock/sync-lock-provider.d.ts +5 -0
- package/package.json +112 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Logger } from '@bitblit/ratchet-common';
|
|
2
|
+
import { S3CacheRatchet } from '../s3/s3-cache-ratchet';
|
|
3
|
+
import { StringRatchet } from '@bitblit/ratchet-common';
|
|
4
|
+
import { DaemonUtil } from './daemon-util';
|
|
5
|
+
import { RequireRatchet } from '@bitblit/ratchet-common';
|
|
6
|
+
export class Daemon {
|
|
7
|
+
constructor(s3, bucket, prefix = '', _defaultGroup = Daemon.DEFAULT_DEFAULT_GROUP, jwtRatchet) {
|
|
8
|
+
this.s3 = s3;
|
|
9
|
+
this.bucket = bucket;
|
|
10
|
+
this.prefix = prefix;
|
|
11
|
+
this._defaultGroup = _defaultGroup;
|
|
12
|
+
this.jwtRatchet = jwtRatchet;
|
|
13
|
+
this.cache = new S3CacheRatchet(this.s3, this.bucket);
|
|
14
|
+
}
|
|
15
|
+
get defaultGroup() {
|
|
16
|
+
return this._defaultGroup;
|
|
17
|
+
}
|
|
18
|
+
async keyToPublicToken(key, expirationSeconds) {
|
|
19
|
+
RequireRatchet.notNullOrUndefined(this.jwtRatchet, 'You must set jwtRatchet if you wish to use public tokens');
|
|
20
|
+
RequireRatchet.notNullOrUndefined(key, 'key');
|
|
21
|
+
RequireRatchet.true(expirationSeconds > 0, 'Expiration seconds must be larger than 0');
|
|
22
|
+
const token = { daemonKey: key };
|
|
23
|
+
const publicToken = await this.jwtRatchet.createTokenString(token, expirationSeconds);
|
|
24
|
+
return publicToken;
|
|
25
|
+
}
|
|
26
|
+
keyToPath(key) {
|
|
27
|
+
return Buffer.from(key, 'base64').toString();
|
|
28
|
+
}
|
|
29
|
+
pathToKey(path) {
|
|
30
|
+
return Buffer.from(path).toString('base64');
|
|
31
|
+
}
|
|
32
|
+
generatePath(group = this._defaultGroup) {
|
|
33
|
+
return this.generatePrefix(group) + StringRatchet.createType4Guid();
|
|
34
|
+
}
|
|
35
|
+
generatePrefix(group = this._defaultGroup) {
|
|
36
|
+
return this.prefix + group + '/';
|
|
37
|
+
}
|
|
38
|
+
async start(options) {
|
|
39
|
+
options.group = options.group || this._defaultGroup;
|
|
40
|
+
const path = this.generatePath(options.group);
|
|
41
|
+
const key = this.pathToKey(path);
|
|
42
|
+
return DaemonUtil.start(this.cache, key, path, options);
|
|
43
|
+
}
|
|
44
|
+
async writeState(newState, contents) {
|
|
45
|
+
const key = this.keyToPath(newState.id);
|
|
46
|
+
return DaemonUtil.writeState(this.cache, key, newState, contents);
|
|
47
|
+
}
|
|
48
|
+
async clean(group = this._defaultGroup, olderThanSeconds = 60 * 60 * 24 * 7) {
|
|
49
|
+
try {
|
|
50
|
+
Logger.info('Daemon removing items older than %d seconds from group %s', olderThanSeconds, group);
|
|
51
|
+
const original = await this.list(group);
|
|
52
|
+
const now = new Date().getTime();
|
|
53
|
+
const removed = [];
|
|
54
|
+
for (let i = 0; i < original.length; i++) {
|
|
55
|
+
const test = original[i];
|
|
56
|
+
const ageSeconds = (now - test.startedEpochMS) / 1000;
|
|
57
|
+
if (ageSeconds > olderThanSeconds) {
|
|
58
|
+
const remove = await this.cache.removeCacheFile(this.keyToPath(test.id));
|
|
59
|
+
removed.push(test);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Logger.debug('Removed %d of %d items', removed.length, original.length);
|
|
63
|
+
return removed;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
Logger.error('Error while trying to clean a daemon: %j %s', group, err);
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async listKeys(group = this._defaultGroup) {
|
|
71
|
+
try {
|
|
72
|
+
const prefix = this.generatePrefix(group);
|
|
73
|
+
Logger.info('Fetching children of %s', prefix);
|
|
74
|
+
const rval = await this.cache.directChildrenOfPrefix(prefix);
|
|
75
|
+
Logger.debug('Found : %j', rval);
|
|
76
|
+
return rval;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
Logger.error('Error while trying to list daemon keys: %j %s', group, err);
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async list(group = this._defaultGroup) {
|
|
84
|
+
try {
|
|
85
|
+
const prefix = this.generatePrefix(group);
|
|
86
|
+
Logger.info('Fetching children of %s', prefix);
|
|
87
|
+
const keys = await this.listKeys(group);
|
|
88
|
+
const proms = keys.map((k) => this.stat(this.pathToKey(this.generatePrefix(group) + k)));
|
|
89
|
+
const rval = await Promise.all(proms);
|
|
90
|
+
return rval;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
Logger.error('Error while trying to list daemon states: %j %s', group, err);
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async updateMessage(id, newMessage) {
|
|
98
|
+
const itemPath = this.keyToPath(id);
|
|
99
|
+
return DaemonUtil.updateMessage(this.cache, itemPath, newMessage);
|
|
100
|
+
}
|
|
101
|
+
async stat(key) {
|
|
102
|
+
const itemPath = this.keyToPath(key);
|
|
103
|
+
return DaemonUtil.stat(this.cache, itemPath);
|
|
104
|
+
}
|
|
105
|
+
async statFromPublicToken(publicToken) {
|
|
106
|
+
RequireRatchet.notNullOrUndefined(this.jwtRatchet, 'You must set jwtRatchet if you wish to use public tokens');
|
|
107
|
+
RequireRatchet.notNullOrUndefined(publicToken, 'publicToken');
|
|
108
|
+
const parsed = await this.jwtRatchet.decodeToken(publicToken);
|
|
109
|
+
const key = parsed?.daemonKey;
|
|
110
|
+
return key ? this.stat(key) : null;
|
|
111
|
+
}
|
|
112
|
+
async abort(id) {
|
|
113
|
+
return DaemonUtil.abort(this.cache, this.keyToPath(id));
|
|
114
|
+
}
|
|
115
|
+
async error(id, error) {
|
|
116
|
+
return DaemonUtil.error(this.cache, this.keyToPath(id), error);
|
|
117
|
+
}
|
|
118
|
+
async finalize(id, contents) {
|
|
119
|
+
return DaemonUtil.finalize(this.cache, this.keyToPath(id), contents);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
Daemon.DEFAULT_DEFAULT_GROUP = 'DEFAULT';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MapRatchet, RequireRatchet, StringRatchet } from '@bitblit/ratchet-common';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
3
|
+
export class PrototypeDao {
|
|
4
|
+
static defaultDaoConfig() {
|
|
5
|
+
return {
|
|
6
|
+
guidCreateFunction: StringRatchet.createType4Guid,
|
|
7
|
+
guidFieldName: 'guid',
|
|
8
|
+
createdEpochMSFieldName: 'createdEpochMS',
|
|
9
|
+
updatedEpochMSFieldName: 'updatedEpochMS',
|
|
10
|
+
createdUtcTimestampFieldName: null,
|
|
11
|
+
updatedUtcTimestampFieldName: null,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
constructor(provider, cfg = PrototypeDao.defaultDaoConfig()) {
|
|
15
|
+
this.provider = provider;
|
|
16
|
+
this.cfg = cfg;
|
|
17
|
+
RequireRatchet.notNullOrUndefined(provider, 'provider');
|
|
18
|
+
RequireRatchet.notNullOrUndefined(cfg, 'cfg');
|
|
19
|
+
RequireRatchet.notNullOrUndefined(cfg.guidCreateFunction, 'cfg.guidCreateFunction');
|
|
20
|
+
RequireRatchet.notNullOrUndefined(cfg.guidFieldName, 'cfg.guidFieldName');
|
|
21
|
+
}
|
|
22
|
+
async fetchAll() {
|
|
23
|
+
const db = await this.provider.loadDatabase();
|
|
24
|
+
return db.items || [];
|
|
25
|
+
}
|
|
26
|
+
async resetDatabase() {
|
|
27
|
+
await this.provider.storeDatabase({ items: [], lastModifiedEpochMS: Date.now() });
|
|
28
|
+
}
|
|
29
|
+
async removeItems(guids) {
|
|
30
|
+
let old = await this.fetchAll();
|
|
31
|
+
if (guids) {
|
|
32
|
+
old = old.filter((t) => !guids.includes(t[this.cfg.guidFieldName]));
|
|
33
|
+
await this.provider.storeDatabase({ items: old, lastModifiedEpochMS: Date.now() });
|
|
34
|
+
}
|
|
35
|
+
return old;
|
|
36
|
+
}
|
|
37
|
+
async store(value) {
|
|
38
|
+
let old = await this.fetchAll();
|
|
39
|
+
if (value) {
|
|
40
|
+
value[this.cfg.guidFieldName] = value[this.cfg.guidFieldName] || this.cfg.guidCreateFunction();
|
|
41
|
+
if (this.cfg.createdEpochMSFieldName) {
|
|
42
|
+
value[this.cfg.createdEpochMSFieldName] = value[this.cfg.createdEpochMSFieldName] || Date.now();
|
|
43
|
+
}
|
|
44
|
+
if (this.cfg.createdUtcTimestampFieldName) {
|
|
45
|
+
value[this.cfg.createdUtcTimestampFieldName] = value[this.cfg.createdUtcTimestampFieldName] || DateTime.utc().toISO();
|
|
46
|
+
}
|
|
47
|
+
if (this.cfg.updatedEpochMSFieldName) {
|
|
48
|
+
value[this.cfg.updatedEpochMSFieldName] = Date.now();
|
|
49
|
+
}
|
|
50
|
+
if (this.cfg.updatedUtcTimestampFieldName) {
|
|
51
|
+
value[this.cfg.updatedUtcTimestampFieldName] = DateTime.utc().toISO();
|
|
52
|
+
}
|
|
53
|
+
old = old.filter((t) => t[this.cfg.guidFieldName] !== value[this.cfg.guidFieldName]);
|
|
54
|
+
old.push(value);
|
|
55
|
+
await this.provider.storeDatabase({ items: old, lastModifiedEpochMS: Date.now() });
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
async fetchById(guid) {
|
|
60
|
+
const old = await this.fetchAll();
|
|
61
|
+
return old.find((t) => t[this.cfg.guidFieldName] === guid);
|
|
62
|
+
}
|
|
63
|
+
async searchByField(fieldDotPath, fieldValue) {
|
|
64
|
+
RequireRatchet.notNullOrUndefined(fieldDotPath, 'fieldDotPath');
|
|
65
|
+
RequireRatchet.notNullOrUndefined(fieldValue, 'fieldValue');
|
|
66
|
+
const map = {};
|
|
67
|
+
map[fieldDotPath] = fieldValue;
|
|
68
|
+
return this.searchByFieldMap(map);
|
|
69
|
+
}
|
|
70
|
+
async searchByFieldMap(input) {
|
|
71
|
+
RequireRatchet.notNullOrUndefined(input, 'input');
|
|
72
|
+
let old = await this.fetchAll();
|
|
73
|
+
old = old.filter((t) => {
|
|
74
|
+
let matchAll = true;
|
|
75
|
+
Object.keys(input).forEach((k) => {
|
|
76
|
+
const val = MapRatchet.findValueDotPath(t, k);
|
|
77
|
+
const fieldValue = input[k];
|
|
78
|
+
matchAll = matchAll && val === fieldValue;
|
|
79
|
+
});
|
|
80
|
+
return matchAll;
|
|
81
|
+
});
|
|
82
|
+
return old;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RequireRatchet } from '@bitblit/ratchet-common';
|
|
2
|
+
export class S3PrototypeDaoProvider {
|
|
3
|
+
constructor(s3CacheRatchet, keyName) {
|
|
4
|
+
this.s3CacheRatchet = s3CacheRatchet;
|
|
5
|
+
this.keyName = keyName;
|
|
6
|
+
RequireRatchet.notNullOrUndefined(s3CacheRatchet, 's3CacheRatchet');
|
|
7
|
+
RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(s3CacheRatchet.getDefaultBucket(), 's3CacheRatchet.defaultBucket');
|
|
8
|
+
RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(keyName, 'keyName');
|
|
9
|
+
}
|
|
10
|
+
async storeDatabase(inDb) {
|
|
11
|
+
const toSave = inDb || { items: [], lastModifiedEpochMS: null };
|
|
12
|
+
toSave.lastModifiedEpochMS = Date.now();
|
|
13
|
+
const put = await this.s3CacheRatchet.writeObjectToCacheFile(this.keyName, toSave);
|
|
14
|
+
const rval = !!put;
|
|
15
|
+
return rval;
|
|
16
|
+
}
|
|
17
|
+
async loadDatabase() {
|
|
18
|
+
const rval = (await this.s3CacheRatchet.fetchCacheFileAsObject(this.keyName)) || {
|
|
19
|
+
items: [],
|
|
20
|
+
lastModifiedEpochMS: Date.now(),
|
|
21
|
+
};
|
|
22
|
+
return rval;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Logger } from '@bitblit/ratchet-common';
|
|
2
|
+
import { StringRatchet } from '@bitblit/ratchet-common';
|
|
3
|
+
export class S3SimpleDao {
|
|
4
|
+
constructor(cache, prefix) {
|
|
5
|
+
this.cache = cache;
|
|
6
|
+
this.prefix = prefix;
|
|
7
|
+
if (!cache) {
|
|
8
|
+
throw new Error('cache object may not be null');
|
|
9
|
+
}
|
|
10
|
+
if (!cache.getDefaultBucket()) {
|
|
11
|
+
throw new Error('Supplied cache must have default bucket set');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
buildPathPrefix(path) {
|
|
15
|
+
let rval = '';
|
|
16
|
+
if (this.prefix) {
|
|
17
|
+
rval += this.prefix;
|
|
18
|
+
}
|
|
19
|
+
if (path) {
|
|
20
|
+
rval += path;
|
|
21
|
+
}
|
|
22
|
+
return rval;
|
|
23
|
+
}
|
|
24
|
+
buildFullPath(id, path) {
|
|
25
|
+
let rval = this.buildPathPrefix(path);
|
|
26
|
+
if (rval.length > 0) {
|
|
27
|
+
rval += '/';
|
|
28
|
+
}
|
|
29
|
+
rval += id + '.json';
|
|
30
|
+
return rval;
|
|
31
|
+
}
|
|
32
|
+
async exists(id, path) {
|
|
33
|
+
const fullPath = this.buildFullPath(id, path);
|
|
34
|
+
Logger.debug('Check file existence : %s', fullPath);
|
|
35
|
+
return this.cache.fileExists(fullPath);
|
|
36
|
+
}
|
|
37
|
+
async fetch(id, path) {
|
|
38
|
+
const fullPath = this.buildFullPath(id, path);
|
|
39
|
+
Logger.debug('Fetching : %s', fullPath);
|
|
40
|
+
const rval = (await this.cache.fetchCacheFileAsObject(fullPath));
|
|
41
|
+
rval.id = id;
|
|
42
|
+
rval.path = path;
|
|
43
|
+
return rval;
|
|
44
|
+
}
|
|
45
|
+
async store(item, path) {
|
|
46
|
+
item.id = item.id || StringRatchet.createType4Guid();
|
|
47
|
+
item.lastModifiedEpochMS = new Date().getTime();
|
|
48
|
+
const fullPath = this.buildFullPath(item.id, path);
|
|
49
|
+
Logger.debug('Storing : %s', fullPath);
|
|
50
|
+
const stored = await this.cache.writeObjectToCacheFile(fullPath, item);
|
|
51
|
+
const read = await this.fetch(item.id, path);
|
|
52
|
+
return read;
|
|
53
|
+
}
|
|
54
|
+
async listItems(path) {
|
|
55
|
+
const fullPath = this.buildPathPrefix(path);
|
|
56
|
+
Logger.debug('Listing : %s', fullPath);
|
|
57
|
+
const rval = await this.cache.directChildrenOfPrefix(fullPath);
|
|
58
|
+
return rval;
|
|
59
|
+
}
|
|
60
|
+
async fetchItemsInPath(path) {
|
|
61
|
+
const fullPath = this.buildPathPrefix(path);
|
|
62
|
+
Logger.debug('Full fetch of : %s', fullPath);
|
|
63
|
+
const items = await this.listItems(path);
|
|
64
|
+
const promises = items.map((s) => this.fetch(s, path));
|
|
65
|
+
const rval = await Promise.all(promises);
|
|
66
|
+
return rval;
|
|
67
|
+
}
|
|
68
|
+
async delete(id, path) {
|
|
69
|
+
const fullPath = this.buildFullPath(id, path);
|
|
70
|
+
Logger.debug('Deleting : %s', fullPath);
|
|
71
|
+
const del = await this.cache.removeCacheFile(fullPath);
|
|
72
|
+
return del != null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|