@casual-simulation/aux-records 2.0.28 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DataRecordsController.d.ts +28 -1
- package/DataRecordsController.js +61 -0
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +30 -1
- package/EventRecordsController.d.ts +66 -0
- package/EventRecordsController.js +102 -0
- package/EventRecordsController.js.map +1 -0
- package/EventRecordsStore.d.ts +31 -0
- package/EventRecordsStore.js +2 -0
- package/EventRecordsStore.js.map +1 -0
- package/FileRecordsController.d.ts +13 -1
- package/FileRecordsController.js +32 -0
- package/FileRecordsController.js.map +1 -1
- package/FileRecordsStore.d.ts +11 -0
- package/MemoryDataRecordsStore.d.ts +3 -1
- package/MemoryDataRecordsStore.js +34 -0
- package/MemoryDataRecordsStore.js.map +1 -1
- package/MemoryEventRecordsStore.d.ts +8 -0
- package/MemoryEventRecordsStore.js +50 -0
- package/MemoryEventRecordsStore.js.map +1 -0
- package/MemoryFileRecordsStore.d.ts +2 -1
- package/MemoryFileRecordsStore.js +15 -0
- package/MemoryFileRecordsStore.js.map +1 -1
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NotLoggedInError, ServerError } from './Errors';
|
|
2
|
-
import { DataRecordsStore, GetDataStoreResult, SetDataResult } from './DataRecordsStore';
|
|
2
|
+
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult, ListDataStoreResult } from './DataRecordsStore';
|
|
3
3
|
import { RecordsController, ValidatePublicRecordKeyFailure } from './RecordsController';
|
|
4
4
|
/**
|
|
5
5
|
* Defines a class that is able to manage data (key/value) records.
|
|
@@ -24,6 +24,8 @@ export declare class DataRecordsController {
|
|
|
24
24
|
*/
|
|
25
25
|
recordData(recordKey: string, address: string, data: string, subjectId: string): Promise<RecordDataResult>;
|
|
26
26
|
getData(recordName: string, address: string): Promise<GetDataResult>;
|
|
27
|
+
listData(recordName: string, address: string | null): Promise<ListDataResult>;
|
|
28
|
+
eraseData(recordKey: string, address: string): Promise<EraseDataResult>;
|
|
27
29
|
}
|
|
28
30
|
export declare type RecordDataResult = RecordDataSuccess | RecordDataFailure;
|
|
29
31
|
export interface RecordDataSuccess {
|
|
@@ -64,4 +66,29 @@ export interface GetDataFailure {
|
|
|
64
66
|
errorCode: ServerError | GetDataStoreResult['errorCode'] | 'not_supported';
|
|
65
67
|
errorMessage: string;
|
|
66
68
|
}
|
|
69
|
+
export declare type EraseDataResult = EraseDataSuccess | EraseDataFailure;
|
|
70
|
+
export interface EraseDataSuccess {
|
|
71
|
+
success: true;
|
|
72
|
+
recordName: string;
|
|
73
|
+
address: string;
|
|
74
|
+
}
|
|
75
|
+
export interface EraseDataFailure {
|
|
76
|
+
success: false;
|
|
77
|
+
errorCode: ServerError | EraseDataStoreResult['errorCode'] | ValidatePublicRecordKeyFailure['errorCode'];
|
|
78
|
+
errorMessage: string;
|
|
79
|
+
}
|
|
80
|
+
export declare type ListDataResult = ListDataSuccess | ListDataFailure;
|
|
81
|
+
export interface ListDataSuccess {
|
|
82
|
+
success: true;
|
|
83
|
+
recordName: string;
|
|
84
|
+
items: {
|
|
85
|
+
data: any;
|
|
86
|
+
address: string;
|
|
87
|
+
}[];
|
|
88
|
+
}
|
|
89
|
+
export interface ListDataFailure {
|
|
90
|
+
success: false;
|
|
91
|
+
errorCode: ServerError | ListDataStoreResult['errorCode'] | 'not_supported';
|
|
92
|
+
errorMessage: string;
|
|
93
|
+
}
|
|
67
94
|
//# sourceMappingURL=DataRecordsController.d.ts.map
|
package/DataRecordsController.js
CHANGED
|
@@ -83,5 +83,66 @@ export class DataRecordsController {
|
|
|
83
83
|
};
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
+
listData(recordName, address) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
try {
|
|
89
|
+
const result2 = yield this._store.listData(recordName, address);
|
|
90
|
+
if (result2.success === false) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
errorCode: result2.errorCode,
|
|
94
|
+
errorMessage: result2.errorMessage,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
success: true,
|
|
99
|
+
recordName,
|
|
100
|
+
items: result2.items,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
errorCode: 'server_error',
|
|
107
|
+
errorMessage: err.toString(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
eraseData(recordKey, address) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
try {
|
|
115
|
+
const result = yield this._manager.validatePublicRecordKey(recordKey);
|
|
116
|
+
if (result.success === false) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
errorCode: result.errorCode,
|
|
120
|
+
errorMessage: result.errorMessage,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const recordName = result.recordName;
|
|
124
|
+
const result2 = yield this._store.eraseData(recordName, address);
|
|
125
|
+
if (result2.success === false) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
errorCode: result2.errorCode,
|
|
129
|
+
errorMessage: result2.errorMessage,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
recordName,
|
|
135
|
+
address,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
errorCode: 'server_error',
|
|
142
|
+
errorMessage: err.toString(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
86
147
|
}
|
|
87
148
|
//# sourceMappingURL=DataRecordsController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataRecordsController.js","sourceRoot":"","sources":["DataRecordsController.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"DataRecordsController.js","sourceRoot":"","sources":["DataRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAaA;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAI9B;;;;OAIG;IACH,YAAY,OAA0B,EAAE,KAAuB;QAC3D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACG,UAAU,CACZ,SAAiB,EACjB,OAAe,EACf,IAAY,EACZ,SAAiB;;YAEjB,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CACtD,SAAS,CACZ,CAAC;gBACF,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;gBAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;gBACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACrC,UAAU,EACV,OAAO,EACP,IAAI,EACJ,MAAM,CAAC,OAAO,EACd,SAAS,CACZ,CAAC;gBAEF,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC3B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;qBACrC,CAAC;iBACL;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,UAAU;oBACtB,OAAO,EAAE,OAAO;iBACnB,CAAC;a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EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;IAEK,SAAS,CACX,SAAiB,EACjB,OAAe;;YAEf,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CACtD,SAAS,CACZ,CAAC;gBACF,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;gBAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;gBACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;gBAEjE,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC3B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;qBACrC,CAAC;iBACL;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,UAAU;oBACV,OAAO;iBACV,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;CACJ"}
|
package/DataRecordsStore.d.ts
CHANGED
|
@@ -14,10 +14,22 @@ export interface DataRecordsStore {
|
|
|
14
14
|
setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string): Promise<SetDataResult>;
|
|
15
15
|
/**
|
|
16
16
|
* Gets the data stored in the given record and address.
|
|
17
|
-
* @param recordName The name of
|
|
17
|
+
* @param recordName The name of the record that the data is in.
|
|
18
18
|
* @param address The address that the data is stored at.
|
|
19
19
|
*/
|
|
20
20
|
getData(recordName: string, address: string): Promise<GetDataStoreResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Lists data stored in the given record starting with the given address.
|
|
23
|
+
* @param recordName The name of the record.
|
|
24
|
+
* @param address The address so start listing items at.
|
|
25
|
+
*/
|
|
26
|
+
listData(recordName: string, address: string | null): Promise<ListDataStoreResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Deletes the data stored in the given record and address.
|
|
29
|
+
* @param recordName The name of the record that the data is in.
|
|
30
|
+
* @param address The address that the data is stored at.
|
|
31
|
+
*/
|
|
32
|
+
eraseData(recordName: string, address: string): Promise<EraseDataStoreResult>;
|
|
21
33
|
}
|
|
22
34
|
/**
|
|
23
35
|
* Defines an interface that represents the result of a "set data" operation.
|
|
@@ -38,4 +50,21 @@ export interface GetDataStoreResult {
|
|
|
38
50
|
errorCode?: 'data_not_found' | ServerError;
|
|
39
51
|
errorMessage?: string;
|
|
40
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Defines an interface that represents the result of a "erase data" operation.
|
|
55
|
+
*/
|
|
56
|
+
export interface EraseDataStoreResult {
|
|
57
|
+
success: boolean;
|
|
58
|
+
errorCode?: 'data_not_found' | ServerError;
|
|
59
|
+
errorMessage?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ListDataStoreResult {
|
|
62
|
+
success: boolean;
|
|
63
|
+
items?: {
|
|
64
|
+
data: any;
|
|
65
|
+
address: string;
|
|
66
|
+
}[];
|
|
67
|
+
errorCode?: ServerError;
|
|
68
|
+
errorMessage?: string;
|
|
69
|
+
}
|
|
41
70
|
//# sourceMappingURL=DataRecordsStore.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { NotLoggedInError, ServerError } from './Errors';
|
|
2
|
+
import { EventRecordsStore, AddEventCountStoreResult, GetEventCountStoreResult } from './EventRecordsStore';
|
|
3
|
+
import { RecordsController, ValidatePublicRecordKeyFailure } from './RecordsController';
|
|
4
|
+
/**
|
|
5
|
+
* Defines a class that is able to manage event (count) records.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EventRecordsController {
|
|
8
|
+
private _manager;
|
|
9
|
+
private _store;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a DataRecordsController.
|
|
12
|
+
* @param manager The records manager that should be used to validate record keys.
|
|
13
|
+
* @param store The store that should be used to save data.
|
|
14
|
+
*/
|
|
15
|
+
constructor(manager: RecordsController, store: EventRecordsStore);
|
|
16
|
+
/**
|
|
17
|
+
* Adds the given count of events to the total count of events with the given name.
|
|
18
|
+
* @param recordKey The record key that should be used to add the events.
|
|
19
|
+
* @param eventName The name of the events to record.
|
|
20
|
+
* @param count The number of events to add/subtract.
|
|
21
|
+
*/
|
|
22
|
+
addCount(recordKey: string, eventName: string, count: number): Promise<AddCountResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the current count of events with the given name from the given record.
|
|
25
|
+
* @param recordName The name of the record.
|
|
26
|
+
* @param eventName The name of the events
|
|
27
|
+
*/
|
|
28
|
+
getCount(recordName: string, eventName: string): Promise<GetCountResult>;
|
|
29
|
+
}
|
|
30
|
+
export declare type AddCountResult = AddCountSuccess | AddCountFailure;
|
|
31
|
+
export interface AddCountSuccess {
|
|
32
|
+
success: true;
|
|
33
|
+
recordName: string;
|
|
34
|
+
eventName: string;
|
|
35
|
+
countAdded: number;
|
|
36
|
+
}
|
|
37
|
+
export interface AddCountFailure {
|
|
38
|
+
success: false;
|
|
39
|
+
errorCode: ServerError | NotLoggedInError | ValidatePublicRecordKeyFailure['errorCode'] | AddEventCountStoreResult['errorCode'] | 'not_supported';
|
|
40
|
+
errorMessage: string;
|
|
41
|
+
}
|
|
42
|
+
export declare type GetCountResult = GetCountSuccess | GetCountFailure;
|
|
43
|
+
/**
|
|
44
|
+
* Defines an interface that represents a successful "get data" result.
|
|
45
|
+
*/
|
|
46
|
+
export interface GetCountSuccess {
|
|
47
|
+
success: true;
|
|
48
|
+
/**
|
|
49
|
+
* The total count of events.
|
|
50
|
+
*/
|
|
51
|
+
count: number;
|
|
52
|
+
/**
|
|
53
|
+
* The name of the record.
|
|
54
|
+
*/
|
|
55
|
+
recordName: string;
|
|
56
|
+
/**
|
|
57
|
+
* The name of the event.
|
|
58
|
+
*/
|
|
59
|
+
eventName: string;
|
|
60
|
+
}
|
|
61
|
+
export interface GetCountFailure {
|
|
62
|
+
success: false;
|
|
63
|
+
errorCode: ServerError | GetEventCountStoreResult['errorCode'] | 'not_supported';
|
|
64
|
+
errorMessage: string;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=EventRecordsController.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
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 class that is able to manage event (count) records.
|
|
12
|
+
*/
|
|
13
|
+
export class EventRecordsController {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a DataRecordsController.
|
|
16
|
+
* @param manager The records manager that should be used to validate record keys.
|
|
17
|
+
* @param store The store that should be used to save data.
|
|
18
|
+
*/
|
|
19
|
+
constructor(manager, store) {
|
|
20
|
+
this._manager = manager;
|
|
21
|
+
this._store = store;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Adds the given count of events to the total count of events with the given name.
|
|
25
|
+
* @param recordKey The record key that should be used to add the events.
|
|
26
|
+
* @param eventName The name of the events to record.
|
|
27
|
+
* @param count The number of events to add/subtract.
|
|
28
|
+
*/
|
|
29
|
+
addCount(recordKey, eventName, count) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
try {
|
|
32
|
+
const result = yield this._manager.validatePublicRecordKey(recordKey);
|
|
33
|
+
if (result.success === false) {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
errorCode: result.errorCode,
|
|
37
|
+
errorMessage: result.errorMessage,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const recordName = result.recordName;
|
|
41
|
+
const result2 = yield this._store.addEventCount(recordName, eventName, count);
|
|
42
|
+
if (result2.success === true) {
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
countAdded: count,
|
|
46
|
+
eventName: eventName,
|
|
47
|
+
recordName: recordName,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
errorCode: result2.errorCode,
|
|
54
|
+
errorMessage: result2.errorMessage,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
errorCode: 'server_error',
|
|
62
|
+
errorMessage: err.toString(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current count of events with the given name from the given record.
|
|
69
|
+
* @param recordName The name of the record.
|
|
70
|
+
* @param eventName The name of the events
|
|
71
|
+
*/
|
|
72
|
+
getCount(recordName, eventName) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
try {
|
|
75
|
+
const result = yield this._store.getEventCount(recordName, eventName);
|
|
76
|
+
if (result.success) {
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
count: result.count,
|
|
80
|
+
eventName: eventName,
|
|
81
|
+
recordName: recordName,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
errorCode: result.errorCode,
|
|
88
|
+
errorMessage: result.errorMessage,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
errorCode: 'server_error',
|
|
96
|
+
errorMessage: err.toString(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=EventRecordsController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventRecordsController.js","sourceRoot":"","sources":["EventRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAWA;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAI/B;;;;OAIG;IACH,YAAY,OAA0B,EAAE,KAAwB;QAC5D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACG,QAAQ,CACV,SAAiB,EACjB,SAAiB,EACjB,KAAa;;YAEb,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CACtD,SAAS,CACZ,CAAC;gBACF,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;gBAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;gBACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAC3C,UAAU,EACV,SAAS,EACT,KAAK,CACR,CAAC;gBAEF,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,EAAE;oBAC1B,OAAO;wBACH,OAAO,EAAE,IAAI;wBACb,UAAU,EAAE,KAAK;wBACjB,SAAS,EAAE,SAAS;wBACpB,UAAU,EAAE,UAAU;qBACzB,CAAC;iBACL;qBAAM;oBACH,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;qBACrC,CAAC;iBACL;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;IAED;;;;OAIG;IACG,QAAQ,CACV,UAAkB,EAClB,SAAiB;;YAEjB,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAC1C,UAAU,EACV,SAAS,CACZ,CAAC;gBAEF,IAAI,MAAM,CAAC,OAAO,EAAE;oBAChB,OAAO;wBACH,OAAO,EAAE,IAAI;wBACb,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,SAAS,EAAE,SAAS;wBACpB,UAAU,EAAE,UAAU;qBACzB,CAAC;iBACL;qBAAM;oBACH,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;qBACpC,CAAC;iBACL;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;CACJ"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ServerError } from './Errors';
|
|
2
|
+
/**
|
|
3
|
+
* Defines an interface for objects that can store event records.
|
|
4
|
+
*/
|
|
5
|
+
export interface EventRecordsStore {
|
|
6
|
+
/**
|
|
7
|
+
* Adds the given count to the given event and record.
|
|
8
|
+
* @param recordName The name of the record.
|
|
9
|
+
* @param eventName The name of the event.
|
|
10
|
+
* @param count The amount to add or subtract.
|
|
11
|
+
*/
|
|
12
|
+
addEventCount(recordName: string, eventName: string, count: number): Promise<AddEventCountStoreResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the count stored on the given event and record.
|
|
15
|
+
* @param recordName The name of the record.
|
|
16
|
+
* @param eventName The name of the event.
|
|
17
|
+
*/
|
|
18
|
+
getEventCount(recordName: string, eventName: string): Promise<GetEventCountStoreResult>;
|
|
19
|
+
}
|
|
20
|
+
export interface AddEventCountStoreResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
errorCode?: ServerError;
|
|
23
|
+
errorMessage?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GetEventCountStoreResult {
|
|
26
|
+
success: boolean;
|
|
27
|
+
count?: number;
|
|
28
|
+
errorCode?: ServerError;
|
|
29
|
+
errorMessage?: string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=EventRecordsStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventRecordsStore.js","sourceRoot":"","sources":["EventRecordsStore.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileRecordsStore, AddFileFailure, MarkFileRecordAsUploadedFailure } from './FileRecordsStore';
|
|
1
|
+
import { FileRecordsStore, AddFileFailure, MarkFileRecordAsUploadedFailure, EraseFileStoreResult } from './FileRecordsStore';
|
|
2
2
|
import { NotLoggedInError, ServerError } from './Errors';
|
|
3
3
|
import { RecordsController, ValidatePublicRecordKeyFailure } from './RecordsController';
|
|
4
4
|
/**
|
|
@@ -9,6 +9,7 @@ export declare class FileRecordsController {
|
|
|
9
9
|
private _store;
|
|
10
10
|
constructor(controller: RecordsController, store: FileRecordsStore);
|
|
11
11
|
recordFile(recordKey: string, userId: string, request: RecordFileRequest): Promise<RecordFileResult>;
|
|
12
|
+
eraseFile(recordKey: string, fileName: string): Promise<EraseFileResult>;
|
|
12
13
|
markFileAsUploaded(recordName: string, fileName: string): Promise<FileUploadedResult>;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
@@ -69,6 +70,17 @@ export interface RecordFileFailure {
|
|
|
69
70
|
*/
|
|
70
71
|
existingFileUrl?: string;
|
|
71
72
|
}
|
|
73
|
+
export declare type EraseFileResult = EraseFileSuccess | EraseFileFailure;
|
|
74
|
+
export interface EraseFileSuccess {
|
|
75
|
+
success: true;
|
|
76
|
+
recordName: string;
|
|
77
|
+
fileName: string;
|
|
78
|
+
}
|
|
79
|
+
export interface EraseFileFailure {
|
|
80
|
+
success: false;
|
|
81
|
+
errorCode: ServerError | EraseFileStoreResult['errorCode'] | NotLoggedInError | ValidatePublicRecordKeyFailure['errorCode'];
|
|
82
|
+
errorMessage: string;
|
|
83
|
+
}
|
|
72
84
|
export declare type FileUploadedResult = FileUploadedSuccess | FileUploadedFailure;
|
|
73
85
|
export interface FileUploadedSuccess {
|
|
74
86
|
success: true;
|
package/FileRecordsController.js
CHANGED
|
@@ -91,6 +91,38 @@ export class FileRecordsController {
|
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
+
eraseFile(recordKey, fileName) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
try {
|
|
97
|
+
const keyResult = yield this._controller.validatePublicRecordKey(recordKey);
|
|
98
|
+
if (keyResult.success === false) {
|
|
99
|
+
return keyResult;
|
|
100
|
+
}
|
|
101
|
+
const publisherId = keyResult.ownerId;
|
|
102
|
+
const recordName = keyResult.recordName;
|
|
103
|
+
const eraseResult = yield this._store.eraseFileRecord(recordName, fileName);
|
|
104
|
+
if (eraseResult.success === false) {
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
errorCode: eraseResult.errorCode,
|
|
108
|
+
errorMessage: eraseResult.errorMessage,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
success: true,
|
|
113
|
+
recordName,
|
|
114
|
+
fileName,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
errorCode: 'server_error',
|
|
121
|
+
errorMessage: err.toString(),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
94
126
|
markFileAsUploaded(recordName, fileName) {
|
|
95
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
128
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileRecordsController.js","sourceRoot":"","sources":["FileRecordsController.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"FileRecordsController.js","sourceRoot":"","sources":["FileRecordsController.ts"],"names":[],"mappings":";;;;;;;;;AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAI9B,YAAY,UAA6B,EAAE,KAAuB;QAC9D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAEK,UAAU,CACZ,SAAiB,EACjB,MAAc,EACd,OAA0B;;YAE1B,IAAI;gBACA,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAC5D,SAAS,CACZ,CAAC;gBAEF,IAAI,SAAS,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC7B,OAAO,SAAS,CAAC;iBACpB;gBAED,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC;gBACtC,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC;gBACxC,MAAM,SAAS,GAAG,MAAM,CAAC;gBAEzB,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,YAAY,C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AY;qBACzC,CAAC;iBACL;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,UAAU;oBACV,QAAQ;iBACX,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;IAEK,kBAAkB,CACpB,UAAkB,EAClB,QAAgB;;YAEhB,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,uBAAuB,CACpD,UAAU,EACV,QAAQ,CACX,CAAC;gBAEF,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE;oBAC1B,OAAO,MAAM,CAAC;iBACjB;gBAED,OAAO;oBACH,OAAO,EAAE,IAAI;iBAChB,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,cAAc;oBACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAAE;iBAC/B,CAAC;aACL;QACL,CAAC;KAAA;CACJ"}
|
package/FileRecordsStore.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ export interface FileRecordsStore {
|
|
|
31
31
|
* @param fileName The name of the file that was uploaded.
|
|
32
32
|
*/
|
|
33
33
|
setFileRecordAsUploaded(recordName: string, fileName: string): Promise<MarkFileRecordAsUploadedResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Attempts to delete the given file from the given record.
|
|
36
|
+
* @param recordName The name of the record that the file was recorded in.
|
|
37
|
+
* @param fileName The name of the file that should be deleted.
|
|
38
|
+
*/
|
|
39
|
+
eraseFileRecord(recordName: string, fileName: string): Promise<EraseFileStoreResult>;
|
|
34
40
|
}
|
|
35
41
|
export declare type GetFileRecordResult = GetFileRecordSuccess | GetFileRecordFailure;
|
|
36
42
|
export interface GetFileRecordSuccess {
|
|
@@ -143,4 +149,9 @@ export interface AddFileFailure {
|
|
|
143
149
|
errorCode: ServerError | 'file_already_exists';
|
|
144
150
|
errorMessage: string;
|
|
145
151
|
}
|
|
152
|
+
export interface EraseFileStoreResult {
|
|
153
|
+
success: boolean;
|
|
154
|
+
errorCode?: ServerError | 'file_not_found';
|
|
155
|
+
errorMessage?: string;
|
|
156
|
+
}
|
|
146
157
|
//# sourceMappingURL=FileRecordsStore.d.ts.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { DataRecordsStore, GetDataStoreResult, SetDataResult } from './DataRecordsStore';
|
|
1
|
+
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, ListDataStoreResult, SetDataResult } from './DataRecordsStore';
|
|
2
2
|
export declare class MemoryDataRecordsStore implements DataRecordsStore {
|
|
3
3
|
private _buckets;
|
|
4
4
|
setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string): Promise<SetDataResult>;
|
|
5
5
|
getData(recordName: string, address: string): Promise<GetDataStoreResult>;
|
|
6
|
+
eraseData(recordName: string, address: string): Promise<EraseDataStoreResult>;
|
|
7
|
+
listData(recordName: string, address: string): Promise<ListDataStoreResult>;
|
|
6
8
|
private _getRecord;
|
|
7
9
|
}
|
|
8
10
|
//# sourceMappingURL=MemoryDataRecordsStore.d.ts.map
|
|
@@ -43,6 +43,40 @@ export class MemoryDataRecordsStore {
|
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
+
eraseData(recordName, address) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
let record = this._getRecord(recordName);
|
|
49
|
+
let deleted = record.delete(address);
|
|
50
|
+
if (!deleted) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
errorCode: 'data_not_found',
|
|
54
|
+
errorMessage: 'The data was not found.',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
listData(recordName, address) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
let record = this._getRecord(recordName);
|
|
65
|
+
let items = [];
|
|
66
|
+
for (let [key, item] of record.entries()) {
|
|
67
|
+
if (!address || key > address) {
|
|
68
|
+
items.push({
|
|
69
|
+
address: key,
|
|
70
|
+
data: item.data,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
success: true,
|
|
76
|
+
items,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
46
80
|
_getRecord(recordName) {
|
|
47
81
|
let record = this._buckets.get(recordName);
|
|
48
82
|
if (!record) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryDataRecordsStore.js","sourceRoot":"","sources":["MemoryDataRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"MemoryDataRecordsStore.js","sourceRoot":"","sources":["MemoryDataRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;AAQA,MAAM,OAAO,sBAAsB;IAAnC;QACY,aAAQ,GAAyC,IAAI,GAAG,EAAE,CAAC;IA2FvE,CAAC;IAzFS,OAAO,CACT,UAAkB,EAClB,OAAe,EACf,IAAS,EACT,WAAmB,EACnB,SAAiB;;YAEjB,IAAI,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YACzC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE;gBAChB,IAAI,EAAE,IAAI;gBACV,WAAW,EAAE,WAAW;gBACxB,SAAS,EAAE,SAAS;aACvB,CAAC,CAAC;YACH,OAAO;gBACH,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;KAAA;IAEK,OAAO,CACT,UAAkB,EAClB,OAAe;;YAEf,IAAI,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YACzC,IAAI,IAAI,GAAG,MA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UAAkB;QACjC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;SACzC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AddEventCountStoreResult, EventRecordsStore, GetEventCountStoreResult } from './EventRecordsStore';
|
|
2
|
+
export declare class MemoryEventRecordsStore implements EventRecordsStore {
|
|
3
|
+
private _buckets;
|
|
4
|
+
addEventCount(recordName: string, eventName: string, count: number): Promise<AddEventCountStoreResult>;
|
|
5
|
+
getEventCount(recordName: string, eventName: string): Promise<GetEventCountStoreResult>;
|
|
6
|
+
private _getRecord;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=MemoryEventRecordsStore.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
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 MemoryEventRecordsStore {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._buckets = new Map();
|
|
13
|
+
}
|
|
14
|
+
addEventCount(recordName, eventName, count) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const record = this._getRecord(recordName);
|
|
17
|
+
if (record.has(eventName)) {
|
|
18
|
+
let data = record.get(eventName);
|
|
19
|
+
data.count += count;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
record.set(eventName, {
|
|
23
|
+
count: count,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
success: true,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getEventCount(recordName, eventName) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const record = this._getRecord(recordName);
|
|
34
|
+
const count = record.has(eventName) ? record.get(eventName).count : 0;
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
count: count,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
_getRecord(recordName) {
|
|
42
|
+
let record = this._buckets.get(recordName);
|
|
43
|
+
if (!record) {
|
|
44
|
+
record = new Map();
|
|
45
|
+
this._buckets.set(recordName, record);
|
|
46
|
+
}
|
|
47
|
+
return record;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=MemoryEventRecordsStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryEventRecordsStore.js","sourceRoot":"","sources":["MemoryEventRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;AAMA,MAAM,OAAO,uBAAuB;IAApC;QACY,aAAQ,GAAyC,IAAI,GAAG,EAAE,CAAC;IA6CvE,CAAC;IA3CS,aAAa,CACf,UAAkB,EAClB,SAAiB,EACjB,KAAa;;YAEb,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAE3C,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;gBACvB,IAAI,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACjC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;aACvB;iBAAM;gBACH,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE;oBAClB,KAAK,EAAE,KAAK;iBACf,CAAC,CAAC;aACN;YAED,OAAO;gBACH,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;KAAA;IAEK,aAAa,CACf,UAAkB,EAClB,SAAiB;;YAEjB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAE3C,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtE,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,KAAK;aACf,CAAC;QACN,CAAC;KAAA;IAEO,UAAU,CAAC,UAAkB;QACjC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;SACzC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AddFileResult, FileRecordsStore, GetFileRecordResult, MarkFileRecordAsUploadedResult, PresignFileUploadRequest, PresignFileUploadResult } from './FileRecordsStore';
|
|
1
|
+
import { AddFileResult, EraseFileStoreResult, FileRecordsStore, GetFileRecordResult, MarkFileRecordAsUploadedResult, PresignFileUploadRequest, PresignFileUploadResult } from './FileRecordsStore';
|
|
2
2
|
export declare class MemoryFileRecordsStore implements FileRecordsStore {
|
|
3
3
|
private _files;
|
|
4
4
|
presignFileUpload(request: PresignFileUploadRequest): Promise<PresignFileUploadResult>;
|
|
5
5
|
getFileRecord(recordName: string, fileName: string): Promise<GetFileRecordResult>;
|
|
6
6
|
addFileRecord(recordName: string, fileName: string, publisherId: string, subjectId: string, sizeInBytes: number, description: string): Promise<AddFileResult>;
|
|
7
7
|
setFileRecordAsUploaded(recordName: string, fileName: string): Promise<MarkFileRecordAsUploadedResult>;
|
|
8
|
+
eraseFileRecord(recordName: string, fileName: string): Promise<EraseFileStoreResult>;
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=MemoryFileRecordsStore.d.ts.map
|
|
@@ -79,5 +79,20 @@ export class MemoryFileRecordsStore {
|
|
|
79
79
|
};
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
+
eraseFileRecord(recordName, fileName) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const deleted = this._files.delete(fileName);
|
|
85
|
+
if (!deleted) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
errorCode: 'file_not_found',
|
|
89
|
+
errorMessage: 'The file was not found in the store.',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
82
97
|
}
|
|
83
98
|
//# sourceMappingURL=MemoryFileRecordsStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryFileRecordsStore.js","sourceRoot":"","sources":["MemoryFileRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"MemoryFileRecordsStore.js","sourceRoot":"","sources":["MemoryFileRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;AAUA,MAAM,OAAO,sBAAsB;IAAnC;QACY,WAAM,GAA4B,IAAI,GAAG,EAAE,CAAC;IAyGxD,CAAC;IAvGG,iBAAiB,CACb,OAAiC;QAEjC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAEK,aAAa,CACf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;IAEK,uBAAuB,CACzB,UAAkB,EAClB,QAAgB;;YAEhB,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAErC,IAAI,CAAC,IAAI,EAAE;gBACP,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,gBAAgB;oBAC3B,YAAY,EAAE,sCAAsC;iBACvD,CAAC;aACL;YAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,OAAO;gBACH,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;KAAA;IAEK,eAAe,CACjB,UAAkB,EAClB,QAAgB;;YAEhB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7C,IAAI,CAAC,OAAO,EAAE;gBACV,OAAO;oBACH,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,gBAAgB;oBAC3B,YAAY,EAAE,sCAAsC;iBACvD,CAAC;aACL;YAED,OAAO;gBACH,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;KAAA;CACJ"}
|
package/index.d.ts
CHANGED
|
@@ -7,4 +7,7 @@ export * from './DataRecordsStore';
|
|
|
7
7
|
export * from './FileRecordsController';
|
|
8
8
|
export * from './FileRecordsStore';
|
|
9
9
|
export * from './MemoryFileRecordsStore';
|
|
10
|
+
export * from './EventRecordsController';
|
|
11
|
+
export * from './EventRecordsStore';
|
|
12
|
+
export * from './MemoryEventRecordsStore';
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -7,4 +7,7 @@ export * from './DataRecordsStore';
|
|
|
7
7
|
export * from './FileRecordsController';
|
|
8
8
|
export * from './FileRecordsStore';
|
|
9
9
|
export * from './MemoryFileRecordsStore';
|
|
10
|
+
export * from './EventRecordsController';
|
|
11
|
+
export * from './EventRecordsStore';
|
|
12
|
+
export * from './MemoryEventRecordsStore';
|
|
10
13
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casual-simulation/aux-records",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Helpers and managers used by the CasualOS records system.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Casual Simulation, Inc.",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@casual-simulation/crypto": "^
|
|
41
|
+
"@casual-simulation/crypto": "^3.0.0",
|
|
42
42
|
"tweetnacl": "1.0.3"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "61191ee46ea40ab2cc79d9d4cb85f5e98cdd7d38"
|
|
45
45
|
}
|