@casual-simulation/aux-records-aws 2.0.22-alpha.1651045562

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.
@@ -0,0 +1,10 @@
1
+ export declare function awsResult(value: any): {
2
+ promise(): Promise<any>;
3
+ };
4
+ export declare function awsError(error: any): {
5
+ promise(): Promise<never>;
6
+ };
7
+ export declare class ConditionalCheckFailedException extends Error {
8
+ constructor(message?: string);
9
+ }
10
+ //# sourceMappingURL=AwsTestUtils.d.ts.map
@@ -0,0 +1,21 @@
1
+ export function awsResult(value) {
2
+ return {
3
+ promise() {
4
+ return Promise.resolve(value);
5
+ },
6
+ };
7
+ }
8
+ export function awsError(error) {
9
+ return {
10
+ promise() {
11
+ return Promise.reject(error);
12
+ },
13
+ };
14
+ }
15
+ export class ConditionalCheckFailedException extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ this.name = 'ConditionalCheckFailedException';
19
+ }
20
+ }
21
+ //# sourceMappingURL=AwsTestUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AwsTestUtils.js","sourceRoot":"","sources":["AwsTestUtils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,OAAO;QACH,OAAO;YACH,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;KACJ,CAAC;AACN,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAU;IAC/B,OAAO;QACH,OAAO;YACH,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;KACJ,CAAC;AACN,CAAC;AAED,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IACtD,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAC;IAClD,CAAC;CACJ"}
@@ -0,0 +1,14 @@
1
+ import { DataRecordsStore } from '@casual-simulation/aux-records';
2
+ import { SetDataResult, GetDataStoreResult } from '@casual-simulation/aux-records/DataRecordsStore';
3
+ import dynamodb from 'aws-sdk/clients/dynamodb';
4
+ /**
5
+ * Defines a DataRecordsStore that can store data items in DynamoDB.
6
+ */
7
+ export declare class DynamoDBDataStore implements DataRecordsStore {
8
+ private _dynamo;
9
+ private _tableName;
10
+ constructor(dynamo: dynamodb.DocumentClient, tableName: string);
11
+ setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string): Promise<SetDataResult>;
12
+ getData(recordName: string, address: string): Promise<GetDataStoreResult>;
13
+ }
14
+ //# sourceMappingURL=DynamoDBDataStore.d.ts.map
@@ -0,0 +1,104 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * Defines a DataRecordsStore that can store data items in DynamoDB.
12
+ */
13
+ export class DynamoDBDataStore {
14
+ constructor(dynamo, tableName) {
15
+ this._dynamo = dynamo;
16
+ this._tableName = tableName;
17
+ }
18
+ setData(recordName, address, data, publisherId, subjectId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const item = {
21
+ recordName: recordName,
22
+ address: address,
23
+ data: data,
24
+ publisherId: publisherId,
25
+ subjectId: subjectId,
26
+ publishTime: Date.now(),
27
+ };
28
+ const result = yield this._dynamo
29
+ .put({
30
+ TableName: this._tableName,
31
+ Item: item,
32
+ })
33
+ .promise()
34
+ .then((result) => ({
35
+ success: true,
36
+ result,
37
+ }), (err) => ({
38
+ success: false,
39
+ error: err,
40
+ }));
41
+ if (result.success === true) {
42
+ return {
43
+ success: true,
44
+ };
45
+ }
46
+ console.warn('[DynamoDBDataStore] Error setting data:', result.error);
47
+ if (result.error.name === 'ValidationError') {
48
+ return {
49
+ success: false,
50
+ errorCode: 'data_too_large',
51
+ errorMessage: 'Data is too large to store in the database.',
52
+ };
53
+ }
54
+ return {
55
+ success: false,
56
+ errorCode: 'server_error',
57
+ errorMessage: result.error.toString(),
58
+ };
59
+ });
60
+ }
61
+ getData(recordName, address) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const result = yield this._dynamo
64
+ .get({
65
+ TableName: this._tableName,
66
+ Key: {
67
+ recordName: recordName,
68
+ address: address,
69
+ },
70
+ })
71
+ .promise()
72
+ .then((result) => ({
73
+ success: true,
74
+ result,
75
+ }), (err) => ({
76
+ success: false,
77
+ error: err,
78
+ }));
79
+ if (result.success === true) {
80
+ const item = result.result.Item;
81
+ if (!item) {
82
+ return {
83
+ success: false,
84
+ errorCode: 'data_not_found',
85
+ errorMessage: 'The data was not found.',
86
+ };
87
+ }
88
+ return {
89
+ success: true,
90
+ data: item.data,
91
+ publisherId: item.publisherId,
92
+ subjectId: item.subjectId,
93
+ };
94
+ }
95
+ console.warn('[DynamoDBDataStore] Error getting data:', result.error);
96
+ return {
97
+ success: false,
98
+ errorCode: 'server_error',
99
+ errorMessage: result.error.toString(),
100
+ };
101
+ });
102
+ }
103
+ }
104
+ //# sourceMappingURL=DynamoDBDataStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamoDBDataStore.js","sourceRoot":"","sources":["DynamoDBDataStore.ts"],"names":[],"mappings":";;;;;;;;;AAWA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAI1B,YAAY,MAA+B,EAAE,SAAiB;QAC1D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAEK,OAAO,CACT,UAAkB,EAClB,OAAe,EACf,IAAS,EAC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UAAU;gBAC1B,GAAG,EAAE;oBACD,UAAU,EAAE,UAAU;oBACtB,OAAO,EAAE,OAAO;iBACnB;aACJ,CAAC;iBACD,OAAO,EAAE;iBACT,IAAI,CACD,CAAC,MAAM,EAAE,EAAE,CACP,CAAC;gBACG,OAAO,EAAE,IAAI;gBACb,MAAM;aACC,CAAA,EACf,CAAC,GAAG,EAAE,EAAE,CACJ,CAAC;gBACG,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG;aACH,CAAA,CAClB,CAAC;YAEN,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE;gBACzB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAkB,CAAC;gBAE9C,IAAI,CAAC,IAAI,EAAE;oBACP,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,gBAAgB;wBAC3B,YAAY,EAAE,yBAAyB;qBAC1C,CAAC;iBACL;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;iBAC5B,CAAC;aACL;YAED,OAAO,CAAC,IAAI,CAAC,yCAAyC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YACtE,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,cAAc;gBACzB,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;aACxC,CAAC;QACN,CAAC;KAAA;CACJ"}
@@ -0,0 +1,24 @@
1
+ import { FileRecordsStore } from '@casual-simulation/aux-records';
2
+ import { PresignFileUploadRequest, PresignFileUploadResult, GetFileRecordResult, AddFileResult, MarkFileRecordAsUploadedResult } from '@casual-simulation/aux-records';
3
+ import AWS from 'aws-sdk';
4
+ import dynamodb from 'aws-sdk/clients/dynamodb';
5
+ /**
6
+ * Defines a class that can manage file records in DynamoDB and S3.
7
+ */
8
+ export declare class DynamoDBFileStore implements FileRecordsStore {
9
+ private _region;
10
+ private _bucket;
11
+ private _storageClass;
12
+ private _aws;
13
+ private _dynamo;
14
+ private _tableName;
15
+ private _s3Host;
16
+ constructor(region: string, bucket: string, documentClient: dynamodb.DocumentClient, tableName: string, storageClass?: string, aws?: typeof AWS, s3Host?: string);
17
+ presignFileUpload(request: PresignFileUploadRequest): Promise<PresignFileUploadResult>;
18
+ getFileRecord(recordName: string, fileName: string): Promise<GetFileRecordResult>;
19
+ addFileRecord(recordName: string, fileName: string, publisherId: string, subjectId: string, sizeInBytes: number, description: string): Promise<AddFileResult>;
20
+ setFileRecordAsUploaded(recordName: string, fileName: string): Promise<MarkFileRecordAsUploadedResult>;
21
+ private _getCredentials;
22
+ private _fileUrl;
23
+ }
24
+ //# sourceMappingURL=DynamoDBFileStore.d.ts.map
@@ -0,0 +1,206 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { signRequest } from '@casual-simulation/aux-records';
11
+ import AWS from 'aws-sdk';
12
+ /**
13
+ * Defines a class that can manage file records in DynamoDB and S3.
14
+ */
15
+ export class DynamoDBFileStore {
16
+ constructor(region, bucket, documentClient, tableName, storageClass = 'STANDARD', aws = AWS, s3Host = null) {
17
+ this._region = region;
18
+ this._bucket = bucket;
19
+ this._dynamo = documentClient;
20
+ this._tableName = tableName;
21
+ this._storageClass = storageClass;
22
+ this._aws = aws;
23
+ this._s3Host = s3Host;
24
+ }
25
+ presignFileUpload(request) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const credentials = yield this._getCredentials();
28
+ const secretAccessKey = credentials
29
+ ? credentials.secretAccessKey
30
+ : null;
31
+ const accessKeyId = credentials ? credentials.accessKeyId : null;
32
+ const now = new Date();
33
+ const result = signRequest({
34
+ method: 'PUT',
35
+ payloadSha256Hex: request.fileSha256Hex,
36
+ headers: {
37
+ 'content-type': request.fileMimeType,
38
+ 'content-length': request.fileByteLength.toString(),
39
+ 'cache-control': 'max-age=31536000',
40
+ 'x-amz-acl': 'public-read',
41
+ 'x-amz-storage-class': this._storageClass,
42
+ 'x-amz-tagging': `RecordName=${encodeURIComponent(request.recordName)}&FileName=${encodeURIComponent(request.fileName)}`,
43
+ },
44
+ queryString: {},
45
+ uri: this._fileUrl(request.recordName, request.fileName),
46
+ }, secretAccessKey, accessKeyId, now, this._region, 's3');
47
+ return {
48
+ success: true,
49
+ uploadUrl: result.uri,
50
+ uploadHeaders: result.headers,
51
+ uploadMethod: result.method,
52
+ };
53
+ });
54
+ }
55
+ getFileRecord(recordName, fileName) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ const result = yield this._dynamo
59
+ .get({
60
+ TableName: this._tableName,
61
+ Key: {
62
+ recordName: recordName,
63
+ fileName: fileName,
64
+ },
65
+ })
66
+ .promise();
67
+ if (result.Item) {
68
+ const file = result.Item;
69
+ return {
70
+ success: true,
71
+ recordName: file.recordName,
72
+ fileName: file.fileName,
73
+ description: file.description,
74
+ publisherId: file.publisherId,
75
+ subjectId: file.subjectId,
76
+ sizeInBytes: file.sizeInBytes,
77
+ uploaded: file.uploadTime !== null,
78
+ url: this._fileUrl(file.recordName, file.fileName),
79
+ };
80
+ }
81
+ else {
82
+ return {
83
+ success: false,
84
+ errorCode: 'file_not_found',
85
+ errorMessage: 'The file was not found.',
86
+ };
87
+ }
88
+ }
89
+ catch (err) {
90
+ console.error(err);
91
+ return {
92
+ success: false,
93
+ errorCode: 'server_error',
94
+ errorMessage: 'An unexpected error occurred.',
95
+ };
96
+ }
97
+ });
98
+ }
99
+ addFileRecord(recordName, fileName, publisherId, subjectId, sizeInBytes, description) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ try {
102
+ const publishTime = Date.now();
103
+ const file = {
104
+ recordName,
105
+ fileName,
106
+ publisherId,
107
+ subjectId,
108
+ sizeInBytes,
109
+ description,
110
+ publishTime,
111
+ uploadTime: null,
112
+ };
113
+ yield this._dynamo
114
+ .put({
115
+ TableName: this._tableName,
116
+ Item: file,
117
+ ConditionExpression: 'attribute_not_exists(recordName) AND attribute_not_exists(fileName)',
118
+ })
119
+ .promise();
120
+ return {
121
+ success: true,
122
+ };
123
+ }
124
+ catch (err) {
125
+ if (err instanceof Error &&
126
+ err.name === 'ConditionalCheckFailedException') {
127
+ return {
128
+ success: false,
129
+ errorCode: 'file_already_exists',
130
+ errorMessage: 'The file already exists.',
131
+ };
132
+ }
133
+ else {
134
+ console.error(err);
135
+ return {
136
+ success: false,
137
+ errorCode: 'server_error',
138
+ errorMessage: 'An unexpected error occurred.',
139
+ };
140
+ }
141
+ }
142
+ });
143
+ }
144
+ setFileRecordAsUploaded(recordName, fileName) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ try {
147
+ yield this._dynamo
148
+ .update({
149
+ TableName: this._tableName,
150
+ Key: {
151
+ recordName: recordName,
152
+ fileName: fileName,
153
+ },
154
+ ConditionExpression: 'attribute_exists(recordName) AND attribute_exists(fileName)',
155
+ UpdateExpression: 'SET uploadTime = :uploadTime',
156
+ ExpressionAttributeValues: {
157
+ ':uploadTime': Date.now(),
158
+ },
159
+ })
160
+ .promise();
161
+ return {
162
+ success: true,
163
+ };
164
+ }
165
+ catch (err) {
166
+ if (err instanceof Error &&
167
+ err.name === 'ConditionalCheckFailedException') {
168
+ return {
169
+ success: false,
170
+ errorCode: 'file_not_found',
171
+ errorMessage: 'The file was not found.',
172
+ };
173
+ }
174
+ else {
175
+ console.error(err);
176
+ return {
177
+ success: false,
178
+ errorCode: 'server_error',
179
+ errorMessage: 'An unexpected error occurred.',
180
+ };
181
+ }
182
+ }
183
+ });
184
+ }
185
+ _getCredentials() {
186
+ return new Promise((resolve, reject) => {
187
+ this._aws.config.getCredentials(function (err) {
188
+ if (err) {
189
+ reject(err);
190
+ }
191
+ else {
192
+ resolve(this);
193
+ }
194
+ });
195
+ });
196
+ }
197
+ _fileUrl(recordName, fileName) {
198
+ let filePath = `${recordName}/${fileName}`;
199
+ if (this._s3Host) {
200
+ filePath = `${this._s3Host}/${this._bucket}/${filePath}`;
201
+ }
202
+ return new URL(filePath, `https://${this._bucket}.s3.amazonaws.com`)
203
+ .href;
204
+ }
205
+ }
206
+ //# sourceMappingURL=DynamoDBFileStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamoDBFileStore.js","sourceRoot":"","sources":["DynamoDBFileStore.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAoB,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAQ/E,OAAO,GAAG,MAAM,SAAS,CAAC;AAG1B;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAS1B,YACI,MAAc,EACd,MAAc,EACd,cAAuC,EACvC,SAAiB,EACjB,eAAuB,UAAU,EACjC,MAAkB,GAAG,EACrB,SAAiB,IAAI;QAErB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAEK,iBAAiB,CACnB,OAAiC;;YAEjC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;YAEjD,MAAM,eAAe,GAAG,WA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AY,EAAE,yBAAyB;qBAC1C,CAAC;iBACL;qBAAM;oBACH,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACnB,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,cAAc;wBACzB,YAAY,EAAE,+BAA+B;qBAChD,CAAC;iBACL;aACJ;QACL,CAAC;KAAA;IAEO,eAAe;QACnB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG;gBACzC,IAAI,GAAG,EAAE;oBACL,MAAM,CAAC,GAAG,CAAC,CAAC;iBACf;qBAAM;oBACH,OAAO,CAAC,IAAI,CAAC,CAAC;iBACjB;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,QAAQ,CAAC,UAAkB,EAAE,QAAgB;QACjD,IAAI,QAAQ,GAAG,GAAG,UAAU,IAAI,QAAQ,EAAE,CAAC;QAE3C,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,QAAQ,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,CAAC;SAC5D;QAED,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,WAAW,IAAI,CAAC,OAAO,mBAAmB,CAAC;aAC/D,IAAI,CAAC;IACd,CAAC;CACJ"}
@@ -0,0 +1,12 @@
1
+ import { Record, RecordsStore } from '@casual-simulation/aux-records';
2
+ import dynamodb from 'aws-sdk/clients/dynamodb';
3
+ export declare class DynamoDBRecordsStore implements RecordsStore {
4
+ private _dynamo;
5
+ private _tableName;
6
+ constructor(dynamo: dynamodb.DocumentClient, tableName: string);
7
+ getRecordByName(name: string): Promise<Record>;
8
+ updateRecord(record: Record): Promise<void>;
9
+ addRecord(record: Record): Promise<void>;
10
+ private _getRecord;
11
+ }
12
+ //# sourceMappingURL=DynamoDBRecordsStore.d.ts.map
@@ -0,0 +1,73 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class DynamoDBRecordsStore {
11
+ constructor(dynamo, tableName) {
12
+ this._dynamo = dynamo;
13
+ this._tableName = tableName;
14
+ }
15
+ getRecordByName(name) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const record = yield this._getRecord(name);
18
+ if (!record) {
19
+ return null;
20
+ }
21
+ return {
22
+ name: record.recordName,
23
+ ownerId: record.ownerId,
24
+ secretHashes: record.secretHashes,
25
+ secretSalt: record.secretSalt,
26
+ };
27
+ });
28
+ }
29
+ updateRecord(record) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const r = yield this._getRecord(record.name);
32
+ let now = Date.now();
33
+ let update = {
34
+ recordName: record.name,
35
+ ownerId: record.ownerId,
36
+ secretHashes: record.secretHashes,
37
+ secretSalt: record.secretSalt,
38
+ updateTime: now,
39
+ };
40
+ if (!r) {
41
+ update.creationTime = now;
42
+ }
43
+ else {
44
+ update.creationTime = r.creationTime;
45
+ }
46
+ yield this._dynamo
47
+ .put({
48
+ TableName: this._tableName,
49
+ Item: update,
50
+ })
51
+ .promise();
52
+ });
53
+ }
54
+ addRecord(record) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return yield this.updateRecord(record);
57
+ });
58
+ }
59
+ _getRecord(name) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const record = yield this._dynamo
62
+ .get({
63
+ TableName: this._tableName,
64
+ Key: {
65
+ recordName: name,
66
+ },
67
+ })
68
+ .promise();
69
+ return record.Item;
70
+ });
71
+ }
72
+ }
73
+ //# sourceMappingURL=DynamoDBRecordsStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamoDBRecordsStore.js","sourceRoot":"","sources":["DynamoDBRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;AAGA,MAAM,OAAO,oBAAoB;IAI7B,YAAY,MAA+B,EAAE,SAAiB;QAC1D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAEK,eAAe,CAAC,IAAY;;YAC9B,MAAM,MAAM,GAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAEzD,IAAI,CAAC,MAAM,EAAE;gBACT,OAAO,IAAI,CAAC;aACf;YAED,OAAO;gBACH,IAAI,EAAE,MAAM,CAAC,UAAU;gBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,UAAU,EAAE,MAAM,CAAC,UAAU;aAChC,CAAC;QACN,CAAC;KAAA;IAEK,YAAY,CAAC,MAAc;;YAC7B,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAE7C,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACrB,IAAI,MAAM,GAA0B;gBAChC,UAAU,EAAE,MAAM,CAAC,IAAI;gBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,UAAU,EAAE,GAAG;aAClB,CAAC;YAEF,IAAI,CAAC,CAAC,EAAE;gBACJ,MAAM,CAAC,YAAY,GAAG,GAAG,CAAC;aAC7B;iBAAM;gBACH,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;aACxC;YAED,MAAM,IAAI,CAAC,OAAO;iBACb,GAAG,CAAC;gBACD,SAAS,EAAE,IAAI,CAAC,UAAU;gBAC1B,IAAI,EAAE,MAAM;aACf,CAAC;iBACD,OAAO,EAAE,CAAC;QACnB,CAAC;KAAA;IAEK,SAAS,CAAC,MAAc;;YAC1B,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;KAAA;IAEa,UAAU,CAAC,IAAY;;YACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO;iBAC5B,GAAG,CAAC;gBACD,SAAS,EAAE,IAAI,CAAC,UAAU;gBAC1B,GAAG,EAAE;oBACD,UAAU,EAAE,IAAI;iBACnB;aACJ,CAAC;iBACD,OAAO,EAAE,CAAC;YAEf,OAAO,MAAM,CAAC,IAAoB,CAAC;QACvC,CAAC;KAAA;CACJ"}
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Casual Simulation, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Records AWS
2
+
3
+ A set of stores that allow saving records to AWS.
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './DynamoDBRecordsStore';
2
+ export * from './DynamoDBDataStore';
3
+ export * from './DynamoDBFileStore';
4
+ //# sourceMappingURL=index.d.ts.map
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './DynamoDBRecordsStore';
2
+ export * from './DynamoDBDataStore';
3
+ export * from './DynamoDBFileStore';
4
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@casual-simulation/aux-records-aws",
3
+ "version": "2.0.22-alpha.1651045562",
4
+ "description": "AWS Store implementations for the CasualOS Records System.",
5
+ "keywords": [],
6
+ "author": "Casual Simulation, Inc.",
7
+ "homepage": "https://github.com/casual-simulation/casualos",
8
+ "license": "MIT",
9
+ "main": "index.js",
10
+ "types": "index.d.ts",
11
+ "module": "index",
12
+ "directories": {
13
+ "lib": "."
14
+ },
15
+ "files": [
16
+ "/README.md",
17
+ "/LICENSE.txt",
18
+ "**/*.js",
19
+ "**/*.js.map",
20
+ "**/*.d.ts"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/casual-simulation/casualos.git"
25
+ },
26
+ "scripts": {
27
+ "watch": "tsc --watch",
28
+ "watch:player": "npm run watch",
29
+ "build": "echo \"Nothing to do.\"",
30
+ "build:docs": "typedoc --mode file --excludeNotExported --out ../../api-docs/crypto .",
31
+ "test": "jest",
32
+ "test:watch": "jest --watchAll"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/casual-simulation/casualos/issues"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "dependencies": {
41
+ "@casual-simulation/aux-records": "^2.0.22-alpha.1651045562"
42
+ },
43
+ "gitHead": "874f0a46dad3edeb703965575a0a97129ae6746c"
44
+ }