@casual-simulation/aux-records 3.2.6 → 3.2.7-alpha.6227012901
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/AIController.d.ts +1 -1
- package/AIGenerateSkyboxInterface.d.ts +1 -1
- package/AuthController.d.ts +53 -1
- package/AuthController.js +117 -1
- package/AuthController.js.map +1 -1
- package/AuthMessenger.d.ts +1 -1
- package/AuthStore.d.ts +5 -1
- package/AuthUtils.d.ts +55 -1
- package/AuthUtils.js +130 -2
- package/AuthUtils.js.map +1 -1
- package/DataRecordsController.d.ts +1 -1
- package/DataRecordsStore.d.ts +1 -1
- package/EventRecordsController.d.ts +1 -1
- package/EventRecordsController.js.map +1 -1
- package/EventRecordsStore.d.ts +1 -1
- package/FileRecordsController.d.ts +1 -1
- package/FileRecordsStore.d.ts +2 -2
- package/LivekitEvents.d.ts +1 -1
- package/MemoryRateLimiter.js +1 -1
- package/MemoryRateLimiter.js.map +1 -1
- package/MemoryStore.d.ts +2 -2
- package/MemoryStore.js +2 -0
- package/MemoryStore.js.map +1 -1
- package/PolicyController.d.ts +1 -1
- package/PolicyController.js.map +1 -1
- package/PolicyPermissions.d.ts +212 -1
- package/PolicyPermissions.js +67 -0
- package/PolicyPermissions.js.map +1 -1
- package/PolicyStore.d.ts +1 -1
- package/RateLimitController.d.ts +3 -1
- package/RateLimitController.js +2 -0
- package/RateLimitController.js.map +1 -1
- package/RecordsController.d.ts +30 -2
- package/RecordsController.js +12 -8
- package/RecordsController.js.map +1 -1
- package/{RecordsHttpServer.d.ts → RecordsServer.d.ts} +35 -5
- package/{RecordsHttpServer.js → RecordsServer.js} +153 -6
- package/RecordsServer.js.map +1 -0
- package/RecordsStore.d.ts +12 -6
- package/SubscriptionConfiguration.d.ts +479 -74
- package/SubscriptionConfiguration.js +34 -1
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.d.ts +1 -1
- package/TestUtils.d.ts +2 -0
- package/TestUtils.js +5 -0
- package/TestUtils.js.map +1 -1
- package/Utils.d.ts +0 -10
- package/Utils.js +0 -19
- package/Utils.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +6 -3
- package/websockets/InstRecordsStore.d.ts +186 -0
- package/websockets/InstRecordsStore.js +2 -0
- package/websockets/InstRecordsStore.js.map +1 -0
- package/websockets/MemoryInstRecordsStore.d.ts +31 -0
- package/websockets/MemoryInstRecordsStore.js +310 -0
- package/websockets/MemoryInstRecordsStore.js.map +1 -0
- package/websockets/MemoryTempInstRecordsStore.d.ts +31 -0
- package/websockets/MemoryTempInstRecordsStore.js +169 -0
- package/websockets/MemoryTempInstRecordsStore.js.map +1 -0
- package/websockets/MemoryWebsocketConnectionStore.d.ts +33 -0
- package/websockets/MemoryWebsocketConnectionStore.js +169 -0
- package/websockets/MemoryWebsocketConnectionStore.js.map +1 -0
- package/websockets/MemoryWebsocketMessenger.d.ts +21 -0
- package/websockets/MemoryWebsocketMessenger.js +94 -0
- package/websockets/MemoryWebsocketMessenger.js.map +1 -0
- package/websockets/SplitInstRecordsStore.d.ts +21 -0
- package/websockets/SplitInstRecordsStore.js +186 -0
- package/websockets/SplitInstRecordsStore.js.map +1 -0
- package/websockets/TemporaryInstRecordsStore.d.ts +130 -0
- package/websockets/TemporaryInstRecordsStore.js +2 -0
- package/websockets/TemporaryInstRecordsStore.js.map +1 -0
- package/websockets/Utils.d.ts +16 -0
- package/websockets/Utils.js +26 -0
- package/websockets/Utils.js.map +1 -0
- package/websockets/WebsocketConnectionStore.d.ts +141 -0
- package/websockets/WebsocketConnectionStore.js +2 -0
- package/websockets/WebsocketConnectionStore.js.map +1 -0
- package/websockets/WebsocketController.d.ts +97 -0
- package/websockets/WebsocketController.js +707 -0
- package/websockets/WebsocketController.js.map +1 -0
- package/websockets/WebsocketMessenger.d.ts +42 -0
- package/websockets/WebsocketMessenger.js +2 -0
- package/websockets/WebsocketMessenger.js.map +1 -0
- package/websockets/index.d.ts +12 -0
- package/websockets/index.js +12 -0
- package/websockets/index.js.map +1 -0
- package/Errors.d.ts +0 -29
- package/Errors.js +0 -2
- package/Errors.js.map +0 -1
- package/RecordsHttpServer.js.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
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 { sortedIndexBy } from 'lodash';
|
|
11
|
+
import { branchNamespace } from './Utils';
|
|
12
|
+
/**
|
|
13
|
+
* Defines a WebsocketConnectionStore that keeps all data in memory.
|
|
14
|
+
*/
|
|
15
|
+
export class MemoryWebsocketConnectionStore {
|
|
16
|
+
constructor() {
|
|
17
|
+
/**
|
|
18
|
+
* A map of namespaces to device connections.
|
|
19
|
+
*/
|
|
20
|
+
this._namespaceMap = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* A map of connection IDs to connections.
|
|
23
|
+
*/
|
|
24
|
+
this._connectionMap = new Map();
|
|
25
|
+
this._connections = new Map();
|
|
26
|
+
this._rateLimits = new Map();
|
|
27
|
+
}
|
|
28
|
+
reset() {
|
|
29
|
+
this._namespaceMap = new Map();
|
|
30
|
+
this._connectionMap = new Map();
|
|
31
|
+
this._connections = new Map();
|
|
32
|
+
this._rateLimits = new Map();
|
|
33
|
+
}
|
|
34
|
+
saveConnection(connection) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
this._connections.set(connection.serverConnectionId, connection);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
saveBranchConnection(connection) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const namespace = branchNamespace(connection.mode, connection.recordName, connection.inst, connection.branch);
|
|
42
|
+
let namespaceList = this._getNamespaceList(namespace);
|
|
43
|
+
let connectionList = this._getConnectionList(connection.serverConnectionId);
|
|
44
|
+
const namespaceIndex = sortedIndexBy(namespaceList, connection, (c) => c.serverConnectionId);
|
|
45
|
+
const namespaceItem = namespaceList[namespaceIndex];
|
|
46
|
+
if (!namespaceItem ||
|
|
47
|
+
namespaceItem.serverConnectionId !== connection.serverConnectionId) {
|
|
48
|
+
namespaceList.splice(namespaceIndex, 0, connection);
|
|
49
|
+
}
|
|
50
|
+
const connectionIndex = sortedIndexBy(connectionList, connection, (c) => branchNamespace(c.mode, c.recordName, c.inst, c.branch));
|
|
51
|
+
const connectionItem = connectionList[connectionIndex];
|
|
52
|
+
if (!connectionItem ||
|
|
53
|
+
connectionItem.recordName !== connection.recordName ||
|
|
54
|
+
connectionItem.inst !== connection.inst ||
|
|
55
|
+
connectionItem.branch !== connection.branch) {
|
|
56
|
+
connectionList.splice(connectionIndex, 0, connection);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
deleteBranchConnection(serverConnectionId, mode, recordName, inst, branch) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const namespace = branchNamespace(mode, recordName, inst, branch);
|
|
63
|
+
let namespaceList = this._getNamespaceList(namespace);
|
|
64
|
+
let connectionList = this._getConnectionList(serverConnectionId);
|
|
65
|
+
const namespaceIndex = sortedIndexBy(namespaceList, { serverConnectionId: serverConnectionId }, (c) => c.serverConnectionId);
|
|
66
|
+
const namespaceItem = namespaceList[namespaceIndex];
|
|
67
|
+
if (namespaceItem.serverConnectionId === serverConnectionId) {
|
|
68
|
+
namespaceList.splice(namespaceIndex, 1);
|
|
69
|
+
}
|
|
70
|
+
const connectionIndex = sortedIndexBy(connectionList, { mode, recordName, inst, branch }, (c) => branchNamespace(c.mode, c.recordName, c.inst, c.branch));
|
|
71
|
+
const connectionItem = connectionList[connectionIndex];
|
|
72
|
+
if (connectionItem.recordName === recordName &&
|
|
73
|
+
connectionItem.inst === inst &&
|
|
74
|
+
connectionItem.branch === branch) {
|
|
75
|
+
connectionList.splice(connectionIndex, 1);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
clearConnection(serverConnectionId) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
let connectionList = this._getConnectionList(serverConnectionId);
|
|
82
|
+
for (let connection of connectionList) {
|
|
83
|
+
let namespaceList = this._getNamespaceList(branchNamespace(connection.mode, connection.recordName, connection.inst, connection.branch));
|
|
84
|
+
const namespaceIndex = sortedIndexBy(namespaceList, connection, (c) => c.serverConnectionId);
|
|
85
|
+
const namespaceItem = namespaceList[namespaceIndex];
|
|
86
|
+
if (namespaceItem.serverConnectionId === serverConnectionId) {
|
|
87
|
+
namespaceList.splice(namespaceIndex, 1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
this._connectionMap.set(serverConnectionId, []);
|
|
91
|
+
this._connections.delete(serverConnectionId);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
expireConnection(serverConnectionId) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
try {
|
|
98
|
+
yield this.clearConnection(serverConnectionId);
|
|
99
|
+
resolve();
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
reject(err);
|
|
103
|
+
}
|
|
104
|
+
}), 10);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
getConnectionsByBranch(mode, recordName, inst, branch) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
return this._getNamespaceList(branchNamespace(mode, recordName, inst, branch));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
countConnectionsByBranch(mode, recordName, inst, branch) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return this._getNamespaceList(branchNamespace(mode, recordName, inst, branch)).length;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getConnections(connectionId) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
return this._getConnectionList(connectionId);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
getConnection(connectionId) {
|
|
123
|
+
var _a;
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
return (_a = this._connections.get(connectionId)) !== null && _a !== void 0 ? _a : null;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
countConnections() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
return this._connections.size;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
getBranchConnection(connectionId, mode, recordName, inst, branch) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
return this._getConnectionList(connectionId).find((c) => c.mode === mode &&
|
|
136
|
+
c.recordName === recordName &&
|
|
137
|
+
c.inst === inst &&
|
|
138
|
+
c.branch === branch);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
_getNamespaceList(namespace) {
|
|
142
|
+
let list = this._namespaceMap.get(namespace);
|
|
143
|
+
if (!list) {
|
|
144
|
+
list = [];
|
|
145
|
+
this._namespaceMap.set(namespace, list);
|
|
146
|
+
}
|
|
147
|
+
return list;
|
|
148
|
+
}
|
|
149
|
+
_getConnectionList(connectionId) {
|
|
150
|
+
let list = this._connectionMap.get(connectionId);
|
|
151
|
+
if (!list) {
|
|
152
|
+
list = [];
|
|
153
|
+
this._connectionMap.set(connectionId, list);
|
|
154
|
+
}
|
|
155
|
+
return list;
|
|
156
|
+
}
|
|
157
|
+
getConnectionRateLimitExceededTime(connectionId) {
|
|
158
|
+
var _a;
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
return (_a = this._rateLimits.get(connectionId)) !== null && _a !== void 0 ? _a : null;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
setConnectionRateLimitExceededTime(connectionId, timeMs) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
this._rateLimits.set(connectionId, timeMs);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=MemoryWebsocketConnectionStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryWebsocketConnectionStore.js","sourceRoot":"","sources":["MemoryWebsocketConnectionStore.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAOvC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAO,8BAA8B;IAA3C;QAGI;;WAEG;QACK,kBAAa,GAAG,IAAI,GAAG,EAAoC,CAAC;QAEpE;;WAEG;QACK,mBAAc,GAAG,IAAI,GAAG,EAAoC,CAAC;QAE7D,iBAAY,GAAG,IAAI,GAAG,EAA4B,CAAC;QAEnD,gBAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAoNpD,CAAC;IAlNG,KAAK;QACD,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;IACjC,CAAC;IAEK,cAAc,CAAC,UAA4B;;YAC7C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,kBAAkB,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Ac,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,EAAE;YACP,IAAI,GAAG,EAAE,CAAC;YACV,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;SAC/C;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAEK,kCAAkC,CACpC,YAAoB;;;YAEpB,OAAO,MAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,mCAAI,IAAI,CAAC;;KACrD;IAEK,kCAAkC,CACpC,YAAoB,EACpB,MAAc;;YAEd,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;KAAA;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PresignFileUploadResult } from '../FileRecordsStore';
|
|
2
|
+
import { WebsocketEvent } from '@casual-simulation/aux-common/websockets/WebsocketEvents';
|
|
3
|
+
import { WebsocketMessenger } from './WebsocketMessenger';
|
|
4
|
+
export declare class MemoryWebsocketMessenger implements WebsocketMessenger {
|
|
5
|
+
private _messages;
|
|
6
|
+
private _events;
|
|
7
|
+
private _messageUploadUrl;
|
|
8
|
+
uploadedMessages: Map<string, string>;
|
|
9
|
+
get messageUploadUrl(): string;
|
|
10
|
+
set messageUploadUrl(value: string);
|
|
11
|
+
getMessages(connectionId: string): any[];
|
|
12
|
+
getEvents(connectionId: string): WebsocketEvent[];
|
|
13
|
+
reset(): void;
|
|
14
|
+
sendMessage(connectionIds: string[], data: any, excludeConnection?: string): Promise<void>;
|
|
15
|
+
sendEvent(connectionId: string, event: WebsocketEvent): Promise<void>;
|
|
16
|
+
presignMessageUpload(): Promise<PresignFileUploadResult>;
|
|
17
|
+
downloadMessage(url: string): Promise<string | null | undefined>;
|
|
18
|
+
private _getMessages;
|
|
19
|
+
private _getEvents;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=MemoryWebsocketMessenger.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
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 MemoryWebsocketMessenger {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._messages = new Map();
|
|
13
|
+
this._events = new Map();
|
|
14
|
+
this._messageUploadUrl = null;
|
|
15
|
+
this.uploadedMessages = null;
|
|
16
|
+
}
|
|
17
|
+
get messageUploadUrl() {
|
|
18
|
+
return this._messageUploadUrl;
|
|
19
|
+
}
|
|
20
|
+
set messageUploadUrl(value) {
|
|
21
|
+
this._messageUploadUrl = value;
|
|
22
|
+
}
|
|
23
|
+
getMessages(connectionId) {
|
|
24
|
+
return this._getMessages(connectionId);
|
|
25
|
+
}
|
|
26
|
+
getEvents(connectionId) {
|
|
27
|
+
return this._getEvents(connectionId);
|
|
28
|
+
}
|
|
29
|
+
reset() {
|
|
30
|
+
this._messages = new Map();
|
|
31
|
+
this._events = new Map();
|
|
32
|
+
this.uploadedMessages = null;
|
|
33
|
+
}
|
|
34
|
+
sendMessage(connectionIds, data, excludeConnection) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
for (let id of connectionIds) {
|
|
37
|
+
if (id === excludeConnection) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const list = this._getMessages(id);
|
|
41
|
+
list.push(JSON.parse(JSON.stringify(data)));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
sendEvent(connectionId, event) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const events = this._getEvents(connectionId);
|
|
48
|
+
events.push(JSON.parse(JSON.stringify(event)));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
presignMessageUpload() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
if (!this._messageUploadUrl) {
|
|
54
|
+
return {
|
|
55
|
+
success: false,
|
|
56
|
+
errorCode: 'not_supported',
|
|
57
|
+
errorMessage: 'Message uploads are not supported.',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
uploadMethod: 'POST',
|
|
63
|
+
uploadUrl: this._messageUploadUrl,
|
|
64
|
+
uploadHeaders: {},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
downloadMessage(url) {
|
|
69
|
+
var _a;
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (!this.uploadedMessages) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return (_a = this.uploadedMessages.get(url)) !== null && _a !== void 0 ? _a : null;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
_getMessages(connectionId) {
|
|
78
|
+
let list = this._messages.get(connectionId);
|
|
79
|
+
if (!list) {
|
|
80
|
+
list = [];
|
|
81
|
+
this._messages.set(connectionId, list);
|
|
82
|
+
}
|
|
83
|
+
return list;
|
|
84
|
+
}
|
|
85
|
+
_getEvents(connectionId) {
|
|
86
|
+
let list = this._events.get(connectionId);
|
|
87
|
+
if (!list) {
|
|
88
|
+
list = [];
|
|
89
|
+
this._events.set(connectionId, list);
|
|
90
|
+
}
|
|
91
|
+
return list;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=MemoryWebsocketM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CAAC,CAAC;SACxC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AddUpdatesResult, BranchRecord, BranchRecordWithInst, CurrentUpdates, InstRecord, InstRecordsStore, InstWithBranches, ReplaceUpdatesResult, StoredUpdates } from './InstRecordsStore';
|
|
2
|
+
import { TemporaryInstRecordsStore } from './TemporaryInstRecordsStore';
|
|
3
|
+
/**
|
|
4
|
+
* Defines a class that implements the InstRecordsStore interface by first storing updates in a temporary store and then sending them to a permanent store.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SplitInstRecordsStore implements InstRecordsStore {
|
|
7
|
+
private _temp;
|
|
8
|
+
private _permanent;
|
|
9
|
+
constructor(temporary: TemporaryInstRecordsStore, permanent: InstRecordsStore);
|
|
10
|
+
getInstByName(recordName: string | null, inst: string): Promise<InstRecord>;
|
|
11
|
+
getBranchByName(recordName: string | null, inst: string, branch: string): Promise<BranchRecordWithInst>;
|
|
12
|
+
saveInst(inst: InstWithBranches): Promise<void>;
|
|
13
|
+
saveBranch(branch: BranchRecord): Promise<void>;
|
|
14
|
+
getCurrentUpdates(recordName: string | null, inst: string, branch: string): Promise<CurrentUpdates>;
|
|
15
|
+
getAllUpdates(recordName: string, inst: string, branch: string): Promise<StoredUpdates>;
|
|
16
|
+
getInstSize(recordName: string | null, inst: string): Promise<number>;
|
|
17
|
+
addUpdates(recordName: string | null, inst: string, branch: string, updates: string[], sizeInBytes: number): Promise<AddUpdatesResult>;
|
|
18
|
+
deleteBranch(recordName: string | null, inst: string, branch: string): Promise<void>;
|
|
19
|
+
replaceCurrentUpdates(recordName: string, inst: string, branch: string, updateToAdd: string, sizeInBytes: number): Promise<ReplaceUpdatesResult>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=SplitInstRecordsStore.d.ts.map
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { sortBy } from 'lodash';
|
|
22
|
+
/**
|
|
23
|
+
* Defines a class that implements the InstRecordsStore interface by first storing updates in a temporary store and then sending them to a permanent store.
|
|
24
|
+
*/
|
|
25
|
+
export class SplitInstRecordsStore {
|
|
26
|
+
constructor(temporary, permanent) {
|
|
27
|
+
this._temp = temporary;
|
|
28
|
+
this._permanent = permanent;
|
|
29
|
+
}
|
|
30
|
+
getInstByName(recordName, inst) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return yield this._permanent.getInstByName(recordName, inst);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getBranchByName(recordName, inst, branch) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const tempResult = yield this._temp.getBranchByName(recordName, inst, branch);
|
|
38
|
+
if (tempResult) {
|
|
39
|
+
const { branchSizeInBytes } = tempResult, result = __rest(tempResult, ["branchSizeInBytes"]);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
else if (!recordName) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const info = yield this._permanent.getBranchByName(recordName, inst, branch);
|
|
46
|
+
if (info) {
|
|
47
|
+
yield this._temp.saveBranchInfo(info);
|
|
48
|
+
}
|
|
49
|
+
return info;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
saveInst(inst) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (inst.recordName) {
|
|
55
|
+
yield this._permanent.saveInst(inst);
|
|
56
|
+
yield this._temp.deleteAllInstBranchInfo(inst.recordName, inst.inst);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
saveBranch(branch) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
if (branch.recordName) {
|
|
63
|
+
yield this._permanent.saveBranch(branch);
|
|
64
|
+
const info = yield this._permanent.getBranchByName(branch.recordName, branch.inst, branch.branch);
|
|
65
|
+
if (info) {
|
|
66
|
+
yield this._temp.saveBranchInfo(info);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
yield this._temp.saveBranchInfo({
|
|
71
|
+
recordName: null,
|
|
72
|
+
inst: branch.inst,
|
|
73
|
+
branch: branch.branch,
|
|
74
|
+
linkedInst: null,
|
|
75
|
+
temporary: branch.temporary,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getCurrentUpdates(recordName, inst, branch) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const tempUpdates = yield this._temp.getUpdates(recordName, inst, branch);
|
|
83
|
+
if (tempUpdates) {
|
|
84
|
+
const { branchSizeInBytes } = tempUpdates, result = __rest(tempUpdates, ["branchSizeInBytes"]);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
else if (!recordName) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const updates = yield this._permanent.getCurrentUpdates(recordName, inst, branch);
|
|
91
|
+
if (updates.updates.length > 0) {
|
|
92
|
+
yield this._temp.addUpdates(recordName, inst, branch, updates.updates, updates.instSizeInBytes);
|
|
93
|
+
}
|
|
94
|
+
return updates;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getAllUpdates(recordName, inst, branch) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const tempUpdates = yield this._temp.getUpdates(recordName, inst, branch);
|
|
100
|
+
const permUpdates = yield this._permanent.getAllUpdates(recordName, inst, branch);
|
|
101
|
+
if (!tempUpdates) {
|
|
102
|
+
return permUpdates;
|
|
103
|
+
}
|
|
104
|
+
else if (!permUpdates) {
|
|
105
|
+
return tempUpdates;
|
|
106
|
+
}
|
|
107
|
+
let allUpdates = new Set();
|
|
108
|
+
let merged = [];
|
|
109
|
+
for (let i = 0; i < permUpdates.updates.length; i++) {
|
|
110
|
+
let u = permUpdates.updates[i];
|
|
111
|
+
let t = permUpdates.timestamps[i];
|
|
112
|
+
allUpdates.add(u);
|
|
113
|
+
merged.push({
|
|
114
|
+
u,
|
|
115
|
+
t,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (let i = 0; i < tempUpdates.updates.length; i++) {
|
|
119
|
+
let u = tempUpdates.updates[i];
|
|
120
|
+
let t = tempUpdates.timestamps[i];
|
|
121
|
+
if (allUpdates.has(u)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
allUpdates.add(u);
|
|
125
|
+
merged.push({
|
|
126
|
+
u,
|
|
127
|
+
t,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const sorted = sortBy(merged, (m) => m.t);
|
|
131
|
+
let updates = [];
|
|
132
|
+
let timestamps = [];
|
|
133
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
134
|
+
let m = sorted[i];
|
|
135
|
+
updates.push(m.u);
|
|
136
|
+
timestamps.push(m.t);
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
updates,
|
|
140
|
+
timestamps,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
getInstSize(recordName, inst) {
|
|
145
|
+
var _a;
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
return ((_a = (yield this._temp.getInstSize(recordName, inst))) !== null && _a !== void 0 ? _a : (yield this._permanent.getInstSize(recordName, inst)));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
addUpdates(recordName, inst, branch, updates, sizeInBytes) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
yield this._temp.addUpdates(recordName, inst, branch, updates, sizeInBytes);
|
|
153
|
+
const size = yield this._temp.getInstSize(recordName, inst);
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
instSizeInBytes: size,
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
deleteBranch(recordName, inst, branch) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
let promises = [
|
|
163
|
+
this._temp.deleteBranch(recordName, inst, branch),
|
|
164
|
+
];
|
|
165
|
+
if (recordName) {
|
|
166
|
+
promises.push(this._permanent.deleteBranch(recordName, inst, branch));
|
|
167
|
+
}
|
|
168
|
+
yield Promise.all(promises);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
replaceCurrentUpdates(recordName, inst, branch, updateToAdd, sizeInBytes) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const updateCount = yield this._temp.countBranchUpdates(recordName, inst, branch);
|
|
174
|
+
const permanentReplaceResult = yield this._permanent.replaceCurrentUpdates(recordName, inst, branch, updateToAdd, sizeInBytes);
|
|
175
|
+
if (permanentReplaceResult.success === false) {
|
|
176
|
+
return permanentReplaceResult;
|
|
177
|
+
}
|
|
178
|
+
yield this._temp.addUpdates(recordName, inst, branch, [updateToAdd], sizeInBytes);
|
|
179
|
+
yield this._temp.trimUpdates(recordName, inst, branch, updateCount);
|
|
180
|
+
return {
|
|
181
|
+
success: true,
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=SplitInstRecordsStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SplitInstRecordsStore.js","sourceRoot":"","sources":["SplitInstRecordsStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAchC;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAI9B,YACI,SAAoC,EACpC,SAA2B;QAE3B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAEK,aAAa,CACf,UAAyB,EACzB,IAAY;;YAEZ,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACjE,CAAC;KAAA;IAEK,eAAe,CACjB,UAAyB,EACzB,IAAY,EACZ,MAAc;;YAEd,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,CAC/C,UAAU,EACV,IAAI,EACJ,MAAM,CACT,CAAC;YAEF,IAAI,UAAU,EAAE;gBACZ,MAAM,EAAE,iBAAiB,KAAgB,UAAU,EAArB,MAAM,UAAK,UAAU,EAA7C,qBAAgC,CAAa,CAAC;gBACpD,OAAO,MAAM,CAAC;aACjB;iBAAM,IAAI,CAAC,UAAU,EAAE;gBACpB,OAAO,IAAI,CAAC;aACf;YAED,MAAM,IAAI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I,EACJ,MAAM,EACN,WAAW,EACX,WAAW,CACd,CAAC;YACN,IAAI,sBAAsB,CAAC,OAAO,KAAK,KAAK,EAAE;gBAC1C,OAAO,sBAAsB,CAAC;aACjC;YACD,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CACvB,UAAU,EACV,IAAI,EACJ,MAAM,EACN,CAAC,WAAW,CAAC,EACb,WAAW,CACd,CAAC;YACF,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;YACpE,OAAO;gBACH,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;KAAA;CACJ"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { BranchRecordWithInst, CurrentUpdates } from './InstRecordsStore';
|
|
2
|
+
/**
|
|
3
|
+
* Defines an interface for a store that keeps track of temporary inst records.
|
|
4
|
+
*
|
|
5
|
+
* A key feature of temporary records stores is that they act like a cache.
|
|
6
|
+
* As a result, it may evict data based on configuration or other factors (like memory pressure).
|
|
7
|
+
*/
|
|
8
|
+
export interface TemporaryInstRecordsStore {
|
|
9
|
+
/**
|
|
10
|
+
* Gets info for the given branch.
|
|
11
|
+
* @param branchKey The key for the branch.
|
|
12
|
+
*/
|
|
13
|
+
getBranchByName(recordName: string | null, inst: string, branch: string): Promise<(TempBranchInfo & {
|
|
14
|
+
branchSizeInBytes: number;
|
|
15
|
+
}) | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Saves the branch info to the temporary store.
|
|
18
|
+
* @param branch
|
|
19
|
+
*/
|
|
20
|
+
saveBranchInfo(branch: TempBranchInfo): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Deletes all the branches that are associated with the given inst.
|
|
23
|
+
* @param recordName The name of the record.
|
|
24
|
+
* @param inst The name of the inst.
|
|
25
|
+
*/
|
|
26
|
+
deleteAllInstBranchInfo(recordName: string | null, inst: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the updates that are stored in this temporary store.
|
|
29
|
+
* Returns null if no updates are stored.
|
|
30
|
+
* @param branchKey The key for the branch.
|
|
31
|
+
*/
|
|
32
|
+
getUpdates(recordName: string | null, inst: string, branch: string): Promise<BranchUpdates | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Adds the given updates to this temporary store.
|
|
35
|
+
* @param recordName The name of the record.
|
|
36
|
+
* @param inst The name of the inst.
|
|
37
|
+
* @param branch The name of the branch.
|
|
38
|
+
* @param updates The updates that should be added.
|
|
39
|
+
* @param sizeInBytes The size of the updates in bytes.
|
|
40
|
+
*/
|
|
41
|
+
addUpdates(recordName: string | null, inst: string, branch: string, updates: string[], sizeInBytes: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the size of the inst in bytes.
|
|
44
|
+
* Returns null if no size is stored.
|
|
45
|
+
*
|
|
46
|
+
* @param recordName The name of the record.
|
|
47
|
+
* @param inst The name of the inst.
|
|
48
|
+
*/
|
|
49
|
+
getInstSize(recordName: string | null, inst: string): Promise<number | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Sets the size of the inst in bytes.
|
|
52
|
+
* @param recordName The name of the record.
|
|
53
|
+
* @param inst The name of the inst.
|
|
54
|
+
* @param sizeInBytes The size of the inst in bytes.
|
|
55
|
+
*/
|
|
56
|
+
setInstSize(recordName: string | null, inst: string, sizeInBytes: number): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Adds the given amount to the size of the inst.
|
|
59
|
+
* @param recordName The name of the record.
|
|
60
|
+
* @param inst The name of the inst.
|
|
61
|
+
* @param sizeInBytes The size.
|
|
62
|
+
*/
|
|
63
|
+
addInstSize(recordName: string | null, inst: string, sizeInBytes: number): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Deletes the inst size.
|
|
66
|
+
* @param recordName The name of the record.
|
|
67
|
+
* @param inst The name of the inst.
|
|
68
|
+
*/
|
|
69
|
+
deleteInstSize(recordName: string | null, inst: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the size of the branch in bytes.
|
|
72
|
+
* Returns null if no size is stored.
|
|
73
|
+
*
|
|
74
|
+
* @param recordName The name of the record.
|
|
75
|
+
* @param inst The name of the inst.
|
|
76
|
+
* @param branch The name of the branch.
|
|
77
|
+
*/
|
|
78
|
+
getBranchSize(recordName: string | null, inst: string, branch: string): Promise<number | null>;
|
|
79
|
+
/**
|
|
80
|
+
* Sets the size of the branch in bytes.
|
|
81
|
+
* @param recordName The name of the record.
|
|
82
|
+
* @param inst The name of the inst.
|
|
83
|
+
* @param branch The name of the branch.
|
|
84
|
+
* @param sizeInBytes The size of the inst in bytes.
|
|
85
|
+
*/
|
|
86
|
+
setBranchSize(recordName: string | null, inst: string, branch: string, sizeInBytes: number): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Adds the given amount to the size of the branch.
|
|
89
|
+
* @param recordName The name of the record.
|
|
90
|
+
* @param inst The name of the inst.
|
|
91
|
+
* @param branch The name of the branch.
|
|
92
|
+
* @param sizeInBytes The size.
|
|
93
|
+
*/
|
|
94
|
+
addBranchSize(recordName: string | null, inst: string, branch: string, sizeInBytes: number): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Deletes the branch size.
|
|
97
|
+
* @param recordName The name of the record.
|
|
98
|
+
* @param inst The name of the inst.
|
|
99
|
+
* @param branch The name of the branch.
|
|
100
|
+
*/
|
|
101
|
+
deleteBranchSize(recordName: string | null, inst: string, branch: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Deletes the given number of updates from the beginning of the updates list.
|
|
104
|
+
* @param recordName The name of the record.
|
|
105
|
+
* @param inst The name of the inst.
|
|
106
|
+
* @param branch The name of the branch.
|
|
107
|
+
* @param numToDelete The number of updates that should be deleted from the beginning of the list.
|
|
108
|
+
*/
|
|
109
|
+
trimUpdates(recordName: string | null, inst: string, branch: string, numToDelete: number): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the number of updates that are currently stored in the given branch.
|
|
112
|
+
* @param recordName The name of the record.
|
|
113
|
+
* @param inst The name of the inst.
|
|
114
|
+
* @param branch The name of the branch.
|
|
115
|
+
*/
|
|
116
|
+
countBranchUpdates(recordName: string | null, inst: string, branch: string): Promise<number>;
|
|
117
|
+
/**
|
|
118
|
+
* Deletes all the info that the branch has stored.
|
|
119
|
+
* @param recordName The name of the record.
|
|
120
|
+
* @param inst The name of the inst.
|
|
121
|
+
* @param branch The name of the branch.
|
|
122
|
+
*/
|
|
123
|
+
deleteBranch(recordName: string | null, inst: string, branch: string): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
export interface BranchUpdates extends CurrentUpdates {
|
|
126
|
+
branchSizeInBytes: number;
|
|
127
|
+
}
|
|
128
|
+
export interface TempBranchInfo extends BranchRecordWithInst {
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=TemporaryInstRecordsStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemporaryInstRecordsStore.js","sourceRoot":"","sources":["TemporaryInstRecordsStore.ts"],"names":[],"mappings":""}
|