@casual-simulation/aux-records 3.0.5 → 3.0.10-alpha.2282886558
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 +15 -6
- package/DataRecordsController.js +73 -4
- package/DataRecordsController.js.map +1 -1
- package/DataRecordsStore.d.ts +22 -1
- package/DataRecordsStore.js +25 -1
- package/DataRecordsStore.js.map +1 -1
- package/Errors.d.ts +4 -0
- package/MemoryDataRecordsStore.d.ts +2 -2
- package/MemoryDataRecordsStore.js +5 -1
- package/MemoryDataRecordsStore.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NotLoggedInError, ServerError } from './Errors';
|
|
2
|
-
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult, ListDataStoreResult } from './DataRecordsStore';
|
|
1
|
+
import { NotAuthorizedError, NotLoggedInError, ServerError } from './Errors';
|
|
2
|
+
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, SetDataResult, ListDataStoreResult, UserPolicy } 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.
|
|
@@ -20,9 +20,10 @@ export declare class DataRecordsController {
|
|
|
20
20
|
* @param address The address that the record should be stored at inside the record.
|
|
21
21
|
* @param data The data that should be saved.
|
|
22
22
|
* @param subjectId The ID of the user that the data came from.
|
|
23
|
-
* @
|
|
23
|
+
* @param updatePolicy The update policy that the new data should use.
|
|
24
|
+
* @param deletePolicy the delete policy that the new data should use.
|
|
24
25
|
*/
|
|
25
|
-
recordData(recordKey: string, address: string, data: string, subjectId: string): Promise<RecordDataResult>;
|
|
26
|
+
recordData(recordKey: string, address: string, data: string, subjectId: string, updatePolicy: UserPolicy, deletePolicy: UserPolicy): Promise<RecordDataResult>;
|
|
26
27
|
getData(recordName: string, address: string): Promise<GetDataResult>;
|
|
27
28
|
listData(recordName: string, address: string | null): Promise<ListDataResult>;
|
|
28
29
|
/**
|
|
@@ -42,7 +43,7 @@ export interface RecordDataSuccess {
|
|
|
42
43
|
}
|
|
43
44
|
export interface RecordDataFailure {
|
|
44
45
|
success: false;
|
|
45
|
-
errorCode: ServerError | NotLoggedInError | ValidatePublicRecordKeyFailure['errorCode'] | SetDataResult['errorCode'] | 'not_supported';
|
|
46
|
+
errorCode: ServerError | NotLoggedInError | NotAuthorizedError | ValidatePublicRecordKeyFailure['errorCode'] | SetDataResult['errorCode'] | 'not_supported' | 'invalid_update_policy' | 'invalid_delete_policy';
|
|
46
47
|
errorMessage: string;
|
|
47
48
|
}
|
|
48
49
|
export declare type GetDataResult = GetDataSuccess | GetDataFailure;
|
|
@@ -67,6 +68,14 @@ export interface GetDataSuccess {
|
|
|
67
68
|
* The ID of the user that sent the data.
|
|
68
69
|
*/
|
|
69
70
|
subjectId: string;
|
|
71
|
+
/**
|
|
72
|
+
* The update policy that the data uses.
|
|
73
|
+
*/
|
|
74
|
+
updatePolicy: UserPolicy;
|
|
75
|
+
/**
|
|
76
|
+
* The delete policy that the data uses.
|
|
77
|
+
*/
|
|
78
|
+
deletePolicy: UserPolicy;
|
|
70
79
|
}
|
|
71
80
|
export interface GetDataFailure {
|
|
72
81
|
success: false;
|
|
@@ -81,7 +90,7 @@ export interface EraseDataSuccess {
|
|
|
81
90
|
}
|
|
82
91
|
export interface EraseDataFailure {
|
|
83
92
|
success: false;
|
|
84
|
-
errorCode: ServerError | NotLoggedInError | EraseDataStoreResult['errorCode'] | ValidatePublicRecordKeyFailure['errorCode'];
|
|
93
|
+
errorCode: ServerError | NotLoggedInError | NotAuthorizedError | EraseDataStoreResult['errorCode'] | ValidatePublicRecordKeyFailure['errorCode'];
|
|
85
94
|
errorMessage: string;
|
|
86
95
|
}
|
|
87
96
|
export declare type ListDataResult = ListDataSuccess | ListDataFailure;
|
package/DataRecordsController.js
CHANGED
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { doesSubjectMatchPolicy, isValidUserPolicy, } from './DataRecordsStore';
|
|
10
11
|
/**
|
|
11
12
|
* Defines a class that is able to manage data (key/value) records.
|
|
12
13
|
*/
|
|
@@ -27,9 +28,11 @@ export class DataRecordsController {
|
|
|
27
28
|
* @param address The address that the record should be stored at inside the record.
|
|
28
29
|
* @param data The data that should be saved.
|
|
29
30
|
* @param subjectId The ID of the user that the data came from.
|
|
30
|
-
* @
|
|
31
|
+
* @param updatePolicy The update policy that the new data should use.
|
|
32
|
+
* @param deletePolicy the delete policy that the new data should use.
|
|
31
33
|
*/
|
|
32
|
-
recordData(recordKey, address, data, subjectId) {
|
|
34
|
+
recordData(recordKey, address, data, subjectId, updatePolicy, deletePolicy) {
|
|
35
|
+
var _a;
|
|
33
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
37
|
try {
|
|
35
38
|
const result = yield this._manager.validatePublicRecordKey(recordKey);
|
|
@@ -50,8 +53,55 @@ export class DataRecordsController {
|
|
|
50
53
|
if (result.policy === 'subjectless') {
|
|
51
54
|
subjectId = null;
|
|
52
55
|
}
|
|
56
|
+
if (!updatePolicy) {
|
|
57
|
+
updatePolicy = true;
|
|
58
|
+
}
|
|
59
|
+
if (!deletePolicy) {
|
|
60
|
+
deletePolicy = true;
|
|
61
|
+
}
|
|
62
|
+
if (!isValidUserPolicy(updatePolicy)) {
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
errorCode: 'invalid_update_policy',
|
|
66
|
+
errorMessage: 'The given updatePolicy is invalid or not supported.',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (!isValidUserPolicy(deletePolicy)) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
errorCode: 'invalid_delete_policy',
|
|
73
|
+
errorMessage: 'The given deletePolicy is invalid or not supported.',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (result.policy === 'subjectless') {
|
|
77
|
+
if (updatePolicy !== true) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
errorCode: 'invalid_record_key',
|
|
81
|
+
errorMessage: 'It is not possible to set update policies using a subjectless key.',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (deletePolicy !== true) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
errorCode: 'invalid_record_key',
|
|
88
|
+
errorMessage: 'It is not possible to set delete policies using a subjectless key.',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
53
92
|
const recordName = result.recordName;
|
|
54
|
-
const
|
|
93
|
+
const existingRecord = yield this._store.getData(recordName, address);
|
|
94
|
+
if (existingRecord.success) {
|
|
95
|
+
const existingUpdatePolicy = (_a = existingRecord.updatePolicy) !== null && _a !== void 0 ? _a : true;
|
|
96
|
+
if (!doesSubjectMatchPolicy(existingUpdatePolicy, subjectId)) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
errorCode: 'not_authorized',
|
|
100
|
+
errorMessage: 'The updatePolicy does not permit this user to update the data record.',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const result2 = yield this._store.setData(recordName, address, data, result.ownerId, subjectId, updatePolicy, deletePolicy);
|
|
55
105
|
if (result2.success === false) {
|
|
56
106
|
return {
|
|
57
107
|
success: false,
|
|
@@ -75,6 +125,7 @@ export class DataRecordsController {
|
|
|
75
125
|
});
|
|
76
126
|
}
|
|
77
127
|
getData(recordName, address) {
|
|
128
|
+
var _a, _b;
|
|
78
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
130
|
const result = yield this._store.getData(recordName, address);
|
|
80
131
|
if (result.success === false) {
|
|
@@ -90,6 +141,8 @@ export class DataRecordsController {
|
|
|
90
141
|
publisherId: result.publisherId,
|
|
91
142
|
subjectId: result.subjectId,
|
|
92
143
|
recordName,
|
|
144
|
+
updatePolicy: (_a = result.updatePolicy) !== null && _a !== void 0 ? _a : true,
|
|
145
|
+
deletePolicy: (_b = result.deletePolicy) !== null && _b !== void 0 ? _b : true,
|
|
93
146
|
};
|
|
94
147
|
});
|
|
95
148
|
}
|
|
@@ -127,6 +180,7 @@ export class DataRecordsController {
|
|
|
127
180
|
* @param subjectId THe ID of the user that this request came from.
|
|
128
181
|
*/
|
|
129
182
|
eraseData(recordKey, address, subjectId) {
|
|
183
|
+
var _a;
|
|
130
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
185
|
try {
|
|
132
186
|
const result = yield this._manager.validatePublicRecordKey(recordKey);
|
|
@@ -141,10 +195,25 @@ export class DataRecordsController {
|
|
|
141
195
|
return {
|
|
142
196
|
success: false,
|
|
143
197
|
errorCode: 'not_logged_in',
|
|
144
|
-
errorMessage: 'The user must be logged in in order to record
|
|
198
|
+
errorMessage: 'The user must be logged in in order to erase data using the provided record key.',
|
|
145
199
|
};
|
|
146
200
|
}
|
|
201
|
+
if (result.policy === 'subjectless') {
|
|
202
|
+
subjectId = null;
|
|
203
|
+
}
|
|
147
204
|
const recordName = result.recordName;
|
|
205
|
+
const existingRecord = yield this._store.getData(recordName, address);
|
|
206
|
+
if (existingRecord.success) {
|
|
207
|
+
const existingDeletePolicy = (_a = existingRecord.deletePolicy) !== null && _a !== void 0 ? _a : true;
|
|
208
|
+
if (subjectId !== result.ownerId &&
|
|
209
|
+
!doesSubjectMatchPolicy(existingDeletePolicy, subjectId)) {
|
|
210
|
+
return {
|
|
211
|
+
success: false,
|
|
212
|
+
errorCode: 'not_authorized',
|
|
213
|
+
errorMessage: 'The deletePolicy does not permit this user to erase the data record.',
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
148
217
|
const result2 = yield this._store.eraseData(recordName, address);
|
|
149
218
|
if (result2.success === false) {
|
|
150
219
|
return {
|
|
@@ -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":";;;;;;;;;AACA,OAAO,EAOH,sBAAsB,EACtB,iBAAiB,GACpB,MAAM,oBAAoB,CAAC;AAO5B;;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;;;;;;;;;OASG;IACG,UAAU,CACZ,SAAiB,EACjB,OAAe,EACf,IAAY,EACZ,SAAiB,EACjB,YAAwB,EACxB,YAAwB;;;YAExB,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,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,EAAE;oBAC/C,OAAO;wBACH,OAAO,EAAE,KAAK;wBACd,SAAS,EAAE,eAAe;wBAC1B,YAAY,EACR,qDAAqD;qBAC5D,CAAC;iBACL;gBAED,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,EAAE;oBACjC,SAAS,GAAG,IAAI,CAAC;iBACpB;gBAED,IAAI,CAAC,YAAY,EAAE;oBACf,YAAY,GAAG,IAAI,CAAC;iBACvB;gBACD,IAAI,CAAC,YAAY,EAAE;oBACf,YAAY,GAAG,I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AC;gBAEF,IAAI,cAAc,CAAC,OAAO,EAAE;oBACxB,MAAM,oBAAoB,GACtB,MAAA,cAAc,CAAC,YAAY,mCAAI,IAAI,CAAC;oBACxC,IACI,SAAS,KAAK,MAAM,CAAC,OAAO;wBAC5B,CAAC,sBAAsB,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC1D;wBACE,OAAO;4BACH,OAAO,EAAE,KAAK;4BACd,SAAS,EAAE,gBAAgB;4BAC3B,YAAY,EACR,sEAAsE;yBAC7E,CAAC;qBACL;iBACJ;gBAED,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;;KACJ;CACJ"}
|
package/DataRecordsStore.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ export interface DataRecordsStore {
|
|
|
10
10
|
* @param data The data that should be saved.
|
|
11
11
|
* @param publisherId The ID of the user that owns the record this data is being published to.
|
|
12
12
|
* @param subjectId The ID of the user that was logged in when the data was published.
|
|
13
|
+
* @param updatePolicy The update policy that should be stored.
|
|
14
|
+
* @param deletePolicy The delete policy that should be stored.
|
|
13
15
|
*/
|
|
14
|
-
setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string): Promise<SetDataResult>;
|
|
16
|
+
setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string, updatePolicy: UserPolicy, deletePolicy: UserPolicy): Promise<SetDataResult>;
|
|
15
17
|
/**
|
|
16
18
|
* Gets the data stored in the given record and address.
|
|
17
19
|
* @param recordName The name of the record that the data is in.
|
|
@@ -47,6 +49,8 @@ export interface GetDataStoreResult {
|
|
|
47
49
|
data?: any;
|
|
48
50
|
publisherId?: string;
|
|
49
51
|
subjectId?: string;
|
|
52
|
+
updatePolicy?: UserPolicy;
|
|
53
|
+
deletePolicy?: UserPolicy;
|
|
50
54
|
errorCode?: 'data_not_found' | ServerError;
|
|
51
55
|
errorMessage?: string;
|
|
52
56
|
}
|
|
@@ -67,4 +71,21 @@ export interface ListDataStoreResult {
|
|
|
67
71
|
errorCode?: ServerError;
|
|
68
72
|
errorMessage?: string;
|
|
69
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Defines a type that represents a policy that indicates which users are allowed to affect a record.
|
|
76
|
+
*
|
|
77
|
+
* True indicates that any user can edit the record.
|
|
78
|
+
* An array of strings indicates the list of users that are allowed to edit the record.
|
|
79
|
+
*/
|
|
80
|
+
export declare type UserPolicy = true | string[];
|
|
81
|
+
/**
|
|
82
|
+
* Determines if the given value represents a valid user policy.
|
|
83
|
+
*/
|
|
84
|
+
export declare function isValidUserPolicy(value: unknown): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Determines if the given policy allows the given subject ID.
|
|
87
|
+
* @param policy The policy.
|
|
88
|
+
* @param subjectId The subject ID.
|
|
89
|
+
*/
|
|
90
|
+
export declare function doesSubjectMatchPolicy(policy: UserPolicy, subjectId: string): boolean;
|
|
70
91
|
//# sourceMappingURL=DataRecordsStore.d.ts.map
|
package/DataRecordsStore.js
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the given value represents a valid user policy.
|
|
3
|
+
*/
|
|
4
|
+
export function isValidUserPolicy(value) {
|
|
5
|
+
if (value === true) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
else if (Array.isArray(value)) {
|
|
9
|
+
return value.every(v => typeof v === 'string');
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the given policy allows the given subject ID.
|
|
15
|
+
* @param policy The policy.
|
|
16
|
+
* @param subjectId The subject ID.
|
|
17
|
+
*/
|
|
18
|
+
export function doesSubjectMatchPolicy(policy, subjectId) {
|
|
19
|
+
if (policy === true) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return policy.some(id => id === subjectId);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
2
26
|
//# sourceMappingURL=DataRecordsStore.js.map
|
package/DataRecordsStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataRecordsStore.js","sourceRoot":"","sources":["DataRecordsStore.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"DataRecordsStore.js","sourceRoot":"","sources":["DataRecordsStore.ts"],"names":[],"mappings":"AA0GA;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC5C,IAAG,KAAK,KAAK,IAAI,EAAE;QACf,OAAO,IAAI,CAAC;KACf;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;KAClD;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAkB,EAAE,SAAiB;IACxE,IAAI,MAAM,KAAK,IAAI,EAAE;QACjB,OAAO,IAAI,CAAC;KACf;SAAM;QACH,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;KAC9C;AACL,CAAC"}
|
package/Errors.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ export declare type ServerError = 'server_error';
|
|
|
6
6
|
* Defines an error that occurs when the user is not logged in but they are required to be in order to perform an action.
|
|
7
7
|
*/
|
|
8
8
|
export declare type NotLoggedInError = 'not_logged_in';
|
|
9
|
+
/**
|
|
10
|
+
* Defines an error that occurs when the user does not have the right permissions to perform an action.
|
|
11
|
+
*/
|
|
12
|
+
export declare type NotAuthorizedError = 'not_authorized';
|
|
9
13
|
//# sourceMappingURL=Errors.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, ListDataStoreResult, SetDataResult } from './DataRecordsStore';
|
|
1
|
+
import { DataRecordsStore, EraseDataStoreResult, GetDataStoreResult, ListDataStoreResult, SetDataResult, UserPolicy } from './DataRecordsStore';
|
|
2
2
|
export declare class MemoryDataRecordsStore implements DataRecordsStore {
|
|
3
3
|
private _buckets;
|
|
4
|
-
setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string): Promise<SetDataResult>;
|
|
4
|
+
setData(recordName: string, address: string, data: any, publisherId: string, subjectId: string, updatePolicy: UserPolicy, deletePolicy: UserPolicy): Promise<SetDataResult>;
|
|
5
5
|
getData(recordName: string, address: string): Promise<GetDataStoreResult>;
|
|
6
6
|
eraseData(recordName: string, address: string): Promise<EraseDataStoreResult>;
|
|
7
7
|
listData(recordName: string, address: string): Promise<ListDataStoreResult>;
|
|
@@ -11,13 +11,15 @@ export class MemoryDataRecordsStore {
|
|
|
11
11
|
constructor() {
|
|
12
12
|
this._buckets = new Map();
|
|
13
13
|
}
|
|
14
|
-
setData(recordName, address, data, publisherId, subjectId) {
|
|
14
|
+
setData(recordName, address, data, publisherId, subjectId, updatePolicy, deletePolicy) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
let record = this._getRecord(recordName);
|
|
17
17
|
record.set(address, {
|
|
18
18
|
data: data,
|
|
19
19
|
publisherId: publisherId,
|
|
20
20
|
subjectId: subjectId,
|
|
21
|
+
updatePolicy,
|
|
22
|
+
deletePolicy
|
|
21
23
|
});
|
|
22
24
|
return {
|
|
23
25
|
success: true,
|
|
@@ -40,6 +42,8 @@ export class MemoryDataRecordsStore {
|
|
|
40
42
|
data: data.data,
|
|
41
43
|
publisherId: data.publisherId,
|
|
42
44
|
subjectId: data.subjectId,
|
|
45
|
+
updatePolicy: data.updatePolicy,
|
|
46
|
+
deletePolicy: data.deletePolicy,
|
|
43
47
|
};
|
|
44
48
|
});
|
|
45
49
|
}
|
|
@@ -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":";;;;;;;;;AASA,MAAM,OAAO,sBAAsB;IAAnC;QACY,aAAQ,GAAyC,IAAI,GAAG,EAAE,CAAC;IAiGvE,CAAC;IA/FS,OAAO,CACT,UAAkB,EAClB,OAAe,EACf,IAAS,EACT,WAAmB,EACnB,SAAiB,EACjB,YAAwB,EACxB,YAAwB;;YAExB,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;gBACpB,YAAY;gBACZ,YAAY;aACf,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,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC/B,IAAI,CAAC,IA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,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casual-simulation/aux-records",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10-alpha.2282886558",
|
|
4
4
|
"description": "Helpers and managers used by the CasualOS records system.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Casual Simulation, Inc.",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"@casual-simulation/crypto": "^3.0.0",
|
|
42
42
|
"tweetnacl": "1.0.3"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "db7829096c2582cf9ba8f9ce6184b35e498559fc"
|
|
45
45
|
}
|