@dxos/client 2.26.2-dev.4412f210 → 2.27.1-dev.4929c787
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/client/client.d.ts +5 -15
- package/dist/src/client/client.d.ts.map +1 -1
- package/dist/src/client/client.js +6 -89
- package/dist/src/client/client.js.map +1 -1
- package/dist/src/client/client.test.js.map +1 -1
- package/dist/src/client/local-client.test.js +0 -10
- package/dist/src/client/local-client.test.js.map +1 -1
- package/dist/src/client/service-host/services/system.d.ts.map +1 -1
- package/dist/src/client/service-host/services/system.js +1 -7
- package/dist/src/client/service-host/services/system.js.map +1 -1
- package/dist/src/client/service-host/storage.d.ts +1 -1
- package/dist/src/client/service-host/storage.d.ts.map +1 -1
- package/dist/src/client/service-host/storage.js +15 -14
- package/dist/src/client/service-host/storage.js.map +1 -1
- package/dist/src/proto/gen/dxos/config.d.ts +175 -253
- package/dist/src/proto/gen/dxos/config.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/config.js +26 -23
- package/dist/src/proto/gen/dxos/config.js.map +1 -1
- package/dist/src/proto/gen/dxos/devtools.d.ts +2 -2
- package/dist/src/proto/gen/dxos/devtools.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/service.d.ts +1 -0
- package/dist/src/proto/gen/dxos/echo/service.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/snapshot.d.ts +12 -4
- package/dist/src/proto/gen/dxos/echo/snapshot.d.ts.map +1 -1
- package/dist/src/proto/gen/google/protobuf.d.ts +0 -2
- package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/src/proto/gen/google/protobuf.js.map +1 -1
- package/dist/src/proto/gen/index.d.ts +26 -22
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/src/proto/substitutions.d.ts +16 -21
- package/dist/src/proto/substitutions.d.ts.map +1 -1
- package/dist/src/proto/substitutions.js +6 -46
- package/dist/src/proto/substitutions.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -20
- package/src/client/client.test.ts +2 -2
- package/src/client/client.ts +13 -106
- package/src/client/local-client.test.ts +2 -16
- package/src/client/service-host/services/system.ts +1 -7
- package/src/client/service-host/storage.ts +18 -17
- package/src/proto/gen/dxos/config.ts +175 -253
- package/src/proto/gen/dxos/devtools.ts +2 -2
- package/src/proto/gen/dxos/echo/service.ts +1 -0
- package/src/proto/gen/dxos/echo/snapshot.ts +12 -4
- package/src/proto/gen/google/protobuf.ts +0 -2
- package/src/proto/gen/index.ts +27 -23
- package/src/proto/substitutions.ts +9 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.27.1-dev.4929c787",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "DXOS.org",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
"src"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dxos/async": "2.
|
|
14
|
-
"@dxos/codec-protobuf": "2.
|
|
15
|
-
"@dxos/config": "2.
|
|
16
|
-
"@dxos/credentials": "2.
|
|
17
|
-
"@dxos/crypto": "2.
|
|
18
|
-
"@dxos/debug": "2.
|
|
19
|
-
"@dxos/echo-db": "2.
|
|
20
|
-
"@dxos/echo-protocol": "2.
|
|
21
|
-
"@dxos/feed-store": "2.
|
|
22
|
-
"@dxos/model-factory": "2.
|
|
23
|
-
"@dxos/network-manager": "2.
|
|
24
|
-
"@dxos/object-model": "2.
|
|
25
|
-
"@dxos/proto": "2.
|
|
26
|
-
"@dxos/rpc": "2.
|
|
27
|
-
"@dxos/util": "2.
|
|
13
|
+
"@dxos/async": "2.27.1-dev.4929c787",
|
|
14
|
+
"@dxos/codec-protobuf": "2.27.1-dev.4929c787",
|
|
15
|
+
"@dxos/config": "2.27.1-dev.4929c787",
|
|
16
|
+
"@dxos/credentials": "2.27.1-dev.4929c787",
|
|
17
|
+
"@dxos/crypto": "2.27.1-dev.4929c787",
|
|
18
|
+
"@dxos/debug": "2.27.1-dev.4929c787",
|
|
19
|
+
"@dxos/echo-db": "2.27.1-dev.4929c787",
|
|
20
|
+
"@dxos/echo-protocol": "2.27.1-dev.4929c787",
|
|
21
|
+
"@dxos/feed-store": "2.27.1-dev.4929c787",
|
|
22
|
+
"@dxos/model-factory": "2.27.1-dev.4929c787",
|
|
23
|
+
"@dxos/network-manager": "2.27.1-dev.4929c787",
|
|
24
|
+
"@dxos/object-model": "2.27.1-dev.4929c787",
|
|
25
|
+
"@dxos/proto": "2.27.1-dev.4929c787",
|
|
26
|
+
"@dxos/rpc": "2.27.1-dev.4929c787",
|
|
27
|
+
"@dxos/util": "2.27.1-dev.4929c787",
|
|
28
28
|
"@polkadot/keyring": "6.11.1",
|
|
29
29
|
"@polkadot/util": "6.11.1",
|
|
30
30
|
"@polkadot/util-crypto": "6.11.1",
|
|
@@ -41,11 +41,10 @@
|
|
|
41
41
|
"uuid": "^8.3.2"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@dxos/random-access-multi-storage": "2.
|
|
45
|
-
"@dxos/testutils": "2.
|
|
46
|
-
"@dxos/toolchain-node-library": "2.
|
|
44
|
+
"@dxos/random-access-multi-storage": "2.27.1-dev.4929c787",
|
|
45
|
+
"@dxos/testutils": "2.27.0",
|
|
46
|
+
"@dxos/toolchain-node-library": "2.27.0",
|
|
47
47
|
"@types/debug": "^4.1.7",
|
|
48
|
-
"@types/expect": "~24.3.0",
|
|
49
48
|
"@types/jest": "^26.0.7",
|
|
50
49
|
"@types/level-js": "~4.0.1",
|
|
51
50
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
@@ -7,7 +7,7 @@ import expect from 'expect';
|
|
|
7
7
|
import { it as test } from 'mocha';
|
|
8
8
|
|
|
9
9
|
import { sleep, waitForCondition } from '@dxos/async';
|
|
10
|
-
import {
|
|
10
|
+
import { ConfigObject } from '@dxos/config';
|
|
11
11
|
import { generateSeedPhrase, keyPairFromSeedPhrase } from '@dxos/crypto';
|
|
12
12
|
import { throwUnhandledRejection } from '@dxos/debug';
|
|
13
13
|
import { InvitationDescriptor } from '@dxos/echo-db';
|
|
@@ -276,7 +276,7 @@ describe('Client', () => {
|
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
test('late-register models after refresh', async () => {
|
|
279
|
-
const config:
|
|
279
|
+
const config: ConfigObject = {
|
|
280
280
|
version: 1,
|
|
281
281
|
runtime: {
|
|
282
282
|
client: {
|
package/src/client/client.ts
CHANGED
|
@@ -6,19 +6,17 @@ import assert from 'assert';
|
|
|
6
6
|
import debug from 'debug';
|
|
7
7
|
|
|
8
8
|
import { synchronized } from '@dxos/async';
|
|
9
|
-
import { Config,
|
|
9
|
+
import { Config, ConfigObject } from '@dxos/config';
|
|
10
10
|
import { InvalidParameterError, TimeoutError } from '@dxos/debug';
|
|
11
|
-
import { OpenProgress
|
|
12
|
-
import { DatabaseSnapshot } from '@dxos/echo-protocol';
|
|
11
|
+
import { OpenProgress } from '@dxos/echo-db';
|
|
13
12
|
import { ModelConstructor } from '@dxos/model-factory';
|
|
14
|
-
import { ValueUtil } from '@dxos/object-model';
|
|
15
13
|
import { RpcPort } from '@dxos/rpc';
|
|
16
14
|
|
|
17
15
|
import { EchoProxy, HaloProxy } from '../api';
|
|
18
16
|
import { DevtoolsHook } from '../devtools';
|
|
19
17
|
import { ClientServiceProvider, ClientServices, RemoteServiceConnectionTimeout } from '../interfaces';
|
|
20
18
|
import { InvalidConfigurationError } from '../interfaces/errors';
|
|
21
|
-
import {
|
|
19
|
+
import { Runtime } from '../proto/gen/dxos/config';
|
|
22
20
|
import { createWindowMessagePort, isNode } from '../util';
|
|
23
21
|
import { ClientServiceHost } from './service-host';
|
|
24
22
|
import { ClientServiceProxy } from './service-proxy';
|
|
@@ -27,9 +25,9 @@ const log = debug('dxos:client');
|
|
|
27
25
|
|
|
28
26
|
const EXPECTED_CONFIG_VERSION = 1;
|
|
29
27
|
|
|
30
|
-
export const defaultConfig:
|
|
28
|
+
export const defaultConfig: ConfigObject = { version: 1 };
|
|
31
29
|
|
|
32
|
-
export const defaultTestingConfig:
|
|
30
|
+
export const defaultTestingConfig: ConfigObject = {
|
|
33
31
|
version: 1,
|
|
34
32
|
runtime: {
|
|
35
33
|
services: {
|
|
@@ -57,7 +55,7 @@ export class Client {
|
|
|
57
55
|
|
|
58
56
|
private readonly _config: Config;
|
|
59
57
|
private readonly _options: ClientOptions;
|
|
60
|
-
private readonly _mode:
|
|
58
|
+
private readonly _mode: Runtime.Client.Mode;
|
|
61
59
|
private _serviceProvider!: ClientServiceProvider;
|
|
62
60
|
|
|
63
61
|
private _halo!: HaloProxy;
|
|
@@ -69,7 +67,7 @@ export class Client {
|
|
|
69
67
|
* Creates the client object based on supplied configuration.
|
|
70
68
|
* Requires initialization after creating by calling `.initialize()`.
|
|
71
69
|
*/
|
|
72
|
-
constructor (config:
|
|
70
|
+
constructor (config: ConfigObject | Config = { version: 1 }, options: ClientOptions = {}) {
|
|
73
71
|
if (typeof config !== 'object' || config == null) {
|
|
74
72
|
throw new InvalidParameterError('Invalid config.');
|
|
75
73
|
}
|
|
@@ -85,8 +83,8 @@ export class Client {
|
|
|
85
83
|
// TODO(burdon): config.getProperty('system.debug', process.env.DEBUG, '');
|
|
86
84
|
debug.enable(this._config.values.runtime?.system?.debug ?? process.env.DEBUG ?? 'dxos:*:error');
|
|
87
85
|
|
|
88
|
-
this._mode = this._config.get('runtime.client.mode',
|
|
89
|
-
log(`mode=${
|
|
86
|
+
this._mode = this._config.get('runtime.client.mode', Runtime.Client.Mode.AUTOMATIC)!;
|
|
87
|
+
log(`mode=${Runtime.Client.Mode[this._mode]}`);
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
toString () {
|
|
@@ -158,9 +156,9 @@ export class Client {
|
|
|
158
156
|
throw new TimeoutError(`Initialize timed out after ${t}s.`);
|
|
159
157
|
}, t * 1000);
|
|
160
158
|
|
|
161
|
-
if (this._mode ===
|
|
159
|
+
if (this._mode === Runtime.Client.Mode.REMOTE) {
|
|
162
160
|
await this.initializeRemote(onProgressCallback);
|
|
163
|
-
} else if (this._mode ===
|
|
161
|
+
} else if (this._mode === Runtime.Client.Mode.LOCAL) {
|
|
164
162
|
await this.initializeLocal(onProgressCallback);
|
|
165
163
|
} else {
|
|
166
164
|
await this.initializeAuto(onProgressCallback);
|
|
@@ -237,115 +235,24 @@ export class Client {
|
|
|
237
235
|
this._initialized = false;
|
|
238
236
|
}
|
|
239
237
|
|
|
240
|
-
/**
|
|
241
|
-
* This is a minimal solution for party restoration functionality.
|
|
242
|
-
* It has limitations and hacks:
|
|
243
|
-
* - We have to treat some models in a special way, this is not a generic solution
|
|
244
|
-
* - We have to recreate relationship between old IDs in newly created IDs
|
|
245
|
-
* - This won't work when identities are required, e.g. in chess.
|
|
246
|
-
* This solution is appropriate only for short term, expected to work only in Teamwork
|
|
247
|
-
*/
|
|
248
|
-
@synchronized
|
|
249
|
-
async createPartyFromSnapshot (snapshot: DatabaseSnapshot) {
|
|
250
|
-
const party = await this.echo.createParty();
|
|
251
|
-
const items = snapshot.items ?? [];
|
|
252
|
-
|
|
253
|
-
// We have a brand new item ids after creation, which breaks the old structure of id-parentId mapping.
|
|
254
|
-
// That's why we have a mapping of old ids to new ids, to be able to recover the child-parent relations.
|
|
255
|
-
const oldToNewIdMap = new Map<string, string>();
|
|
256
|
-
|
|
257
|
-
for (const item of sortItemsTopologically(items)) {
|
|
258
|
-
assert(item.itemId);
|
|
259
|
-
assert(item.modelType);
|
|
260
|
-
assert(item.model);
|
|
261
|
-
|
|
262
|
-
const model = this.echo.modelFactory.getModel(item.modelType);
|
|
263
|
-
if (!model) {
|
|
264
|
-
console.warn('No model found in model factory (could need registering first): ', item.modelType);
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
let parentId: string | undefined;
|
|
269
|
-
if (item.parentId) {
|
|
270
|
-
parentId = oldToNewIdMap.get(item.parentId);
|
|
271
|
-
assert(parentId, 'Unable to recreate child-parent relationship - missing map record');
|
|
272
|
-
const parentItem = await party.database.getItem(parentId);
|
|
273
|
-
assert(parentItem, 'Unable to recreate child-parent relationship - parent not created');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const createdItem = await party.database.createItem({
|
|
277
|
-
model: model.constructor,
|
|
278
|
-
type: item.itemType,
|
|
279
|
-
parent: parentId
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
oldToNewIdMap.set(item.itemId, createdItem.id);
|
|
283
|
-
|
|
284
|
-
if (item.model.array) {
|
|
285
|
-
for (const mutation of item.model.array.mutations || []) {
|
|
286
|
-
const decodedMutation = model.meta.mutation.decode(mutation.mutation);
|
|
287
|
-
await (createdItem.model as any).write(decodedMutation);
|
|
288
|
-
}
|
|
289
|
-
} else if (item.modelType === 'dxos:model/object') {
|
|
290
|
-
assert(item?.model?.custom);
|
|
291
|
-
assert(model.meta.snapshotCodec);
|
|
292
|
-
assert(createdItem?.model);
|
|
293
|
-
|
|
294
|
-
const decodedItemSnapshot = model.meta.snapshotCodec.decode(item.model.custom);
|
|
295
|
-
const obj: any = {};
|
|
296
|
-
assert(decodedItemSnapshot.root);
|
|
297
|
-
ValueUtil.applyValue(obj, 'root', decodedItemSnapshot.root);
|
|
298
|
-
|
|
299
|
-
// The planner board models have a structure in the object model, which needs to be recreated on new ids.
|
|
300
|
-
if (item.itemType === 'dxos.org/type/planner/card' && obj.root.listId) {
|
|
301
|
-
obj.root.listId = oldToNewIdMap.get(obj.root.listId);
|
|
302
|
-
assert(obj.root.listId, 'Failed to recreate child-parent structure of a planner card');
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
await createdItem.model.setProperties(obj.root);
|
|
306
|
-
} else if (item.modelType === 'dxos:model/text') {
|
|
307
|
-
assert(item?.model?.custom);
|
|
308
|
-
assert(model.meta.snapshotCodec);
|
|
309
|
-
assert(createdItem?.model);
|
|
310
|
-
|
|
311
|
-
const decodedItemSnapshot = model.meta.snapshotCodec.decode(item.model.custom);
|
|
312
|
-
|
|
313
|
-
await createdItem.model.restoreFromSnapshot(decodedItemSnapshot);
|
|
314
|
-
} else {
|
|
315
|
-
throw new InvalidParameterError(`Unhandled model type: ${item.modelType}`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return party;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
//
|
|
323
|
-
// ECHO.
|
|
324
|
-
//
|
|
325
|
-
|
|
326
238
|
/**
|
|
327
239
|
* Registers a new ECHO model.
|
|
328
240
|
*/
|
|
329
|
-
// TODO(burdon): Expose echo directly?
|
|
330
241
|
registerModel (constructor: ModelConstructor<any>): this {
|
|
331
242
|
this.echo.modelFactory.registerModel(constructor);
|
|
332
243
|
return this;
|
|
333
244
|
}
|
|
334
245
|
|
|
335
|
-
//
|
|
336
|
-
// Deprecated.
|
|
337
|
-
// TODO(burdon): Separate wrapper for devtools?
|
|
338
|
-
//
|
|
339
|
-
|
|
340
246
|
/**
|
|
341
247
|
* Returns devtools context.
|
|
342
248
|
* Used by the DXOS DevTool Extension.
|
|
343
249
|
*
|
|
344
|
-
*
|
|
250
|
+
* This is what gets assigned to `window.__DXOS__` global.
|
|
345
251
|
*/
|
|
346
252
|
getDevtoolsContext (): DevtoolsHook {
|
|
347
253
|
const devtoolsContext: DevtoolsHook = {
|
|
348
254
|
client: this,
|
|
255
|
+
// TODO(dmaretskyi): Is serviceHost needed?
|
|
349
256
|
serviceHost: this._serviceProvider
|
|
350
257
|
};
|
|
351
258
|
|
|
@@ -6,32 +6,18 @@ import expect from 'expect';
|
|
|
6
6
|
import { it as test } from 'mocha';
|
|
7
7
|
|
|
8
8
|
import { waitForCondition } from '@dxos/async';
|
|
9
|
-
import {
|
|
9
|
+
import { ConfigObject } from '@dxos/config';
|
|
10
10
|
|
|
11
11
|
import { Client } from './client';
|
|
12
12
|
|
|
13
13
|
describe('Client', () => {
|
|
14
14
|
describe('Local-only tests', () => {
|
|
15
|
-
test.skip('recreating party based on snapshot does not fail', async () => {
|
|
16
|
-
const client = new Client();
|
|
17
|
-
await client.initialize();
|
|
18
15
|
|
|
19
|
-
await client.halo.createProfile({ username: 'test-user' });
|
|
20
|
-
|
|
21
|
-
const party = await client.echo.createParty();
|
|
22
|
-
|
|
23
|
-
const recreatedParty = await client.createPartyFromSnapshot(party.database.createSnapshot());
|
|
24
|
-
|
|
25
|
-
expect(recreatedParty).toBeDefined();
|
|
26
|
-
// More extensive tests on actual Teamwork models are in Teamwork repo.
|
|
27
|
-
|
|
28
|
-
await client.destroy();
|
|
29
|
-
});
|
|
30
16
|
});
|
|
31
17
|
|
|
32
18
|
describe('With persistent storage', () => {
|
|
33
19
|
test('persistent storage', async () => {
|
|
34
|
-
const config:
|
|
20
|
+
const config: ConfigObject = {
|
|
35
21
|
version: 1,
|
|
36
22
|
runtime: {
|
|
37
23
|
client: {
|
|
@@ -8,13 +8,7 @@ import { CreateServicesOpts } from './interfaces';
|
|
|
8
8
|
export const createSystemService = ({ config, echo }: CreateServicesOpts): SystemService => {
|
|
9
9
|
return {
|
|
10
10
|
getConfig: async () => {
|
|
11
|
-
return
|
|
12
|
-
...config.values,
|
|
13
|
-
build: {
|
|
14
|
-
...config.values.build,
|
|
15
|
-
timestamp: undefined // TODO(rzadp): Substitution did not kick in here?.
|
|
16
|
-
}
|
|
17
|
-
};
|
|
11
|
+
return config.values;
|
|
18
12
|
},
|
|
19
13
|
reset: async () => {
|
|
20
14
|
await echo.reset();
|
|
@@ -9,6 +9,7 @@ import memdown from 'memdown';
|
|
|
9
9
|
import { defs } from '@dxos/config';
|
|
10
10
|
import { createStorage } from '@dxos/random-access-multi-storage';
|
|
11
11
|
|
|
12
|
+
import StorageDriver = defs.Runtime.Client.Storage.StorageDriver;
|
|
12
13
|
import { InvalidConfigurationError } from '../../interfaces';
|
|
13
14
|
import { isNode } from '../../util';
|
|
14
15
|
|
|
@@ -16,7 +17,7 @@ export type StorageType = 'ram' | 'idb' | 'chrome' | 'firefox' | 'node';
|
|
|
16
17
|
export type KeyStorageType = 'ram' | 'leveljs' | 'jsondown';
|
|
17
18
|
|
|
18
19
|
// TODO(burdon): Factor out.
|
|
19
|
-
export const createStorageObjects = (config: defs.
|
|
20
|
+
export const createStorageObjects = (config: defs.Runtime.Client.Storage, snapshotsEnabled = false) => {
|
|
20
21
|
const {
|
|
21
22
|
path = 'dxos/storage', // TODO(burdon): Factor out const.
|
|
22
23
|
storageType,
|
|
@@ -24,16 +25,16 @@ export const createStorageObjects = (config: defs.System.Storage, snapshotsEnabl
|
|
|
24
25
|
persistent = false
|
|
25
26
|
} = config ?? {};
|
|
26
27
|
|
|
27
|
-
if (persistent && storageType ===
|
|
28
|
+
if (persistent && storageType === StorageDriver.RAM) {
|
|
28
29
|
throw new InvalidConfigurationError('RAM storage cannot be used in persistent mode.');
|
|
29
30
|
}
|
|
30
|
-
if (!persistent && (storageType !== undefined && storageType !==
|
|
31
|
+
if (!persistent && (storageType !== undefined && storageType !== StorageDriver.RAM)) {
|
|
31
32
|
throw new InvalidConfigurationError('Cannot use a persistent storage in not persistent mode.');
|
|
32
33
|
}
|
|
33
|
-
if (persistent && keyStorage ===
|
|
34
|
+
if (persistent && keyStorage === StorageDriver.RAM) {
|
|
34
35
|
throw new InvalidConfigurationError('RAM key storage cannot be used in persistent mode.');
|
|
35
36
|
}
|
|
36
|
-
if (!persistent && (keyStorage !==
|
|
37
|
+
if (!persistent && (keyStorage !== StorageDriver.RAM && keyStorage !== undefined)) {
|
|
37
38
|
throw new InvalidConfigurationError('Cannot use a persistent key storage in not persistent mode.');
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -61,24 +62,24 @@ const createKeyStorage = (path: string, type?: KeyStorageType) => {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
|
|
64
|
-
const toStorageType = (type:
|
|
65
|
+
const toStorageType = (type: StorageDriver | undefined): StorageType | undefined => {
|
|
65
66
|
switch (type) {
|
|
66
67
|
case undefined: return undefined;
|
|
67
|
-
case
|
|
68
|
-
case
|
|
69
|
-
case
|
|
70
|
-
case
|
|
71
|
-
case
|
|
72
|
-
default: throw new Error(`Invalid storage type: ${
|
|
68
|
+
case StorageDriver.RAM: return 'ram';
|
|
69
|
+
case StorageDriver.CHROME: return 'chrome';
|
|
70
|
+
case StorageDriver.FIREFOX: return 'firefox';
|
|
71
|
+
case StorageDriver.IDB: return 'idb';
|
|
72
|
+
case StorageDriver.NODE: return 'node';
|
|
73
|
+
default: throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
73
74
|
}
|
|
74
75
|
};
|
|
75
76
|
|
|
76
|
-
const toKeyStorageType = (type:
|
|
77
|
+
const toKeyStorageType = (type: StorageDriver | undefined): KeyStorageType | undefined => {
|
|
77
78
|
switch (type) {
|
|
78
79
|
case undefined: return undefined;
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
case
|
|
82
|
-
default: throw new Error(`Invalid key storage type: ${
|
|
80
|
+
case StorageDriver.RAM: return 'ram';
|
|
81
|
+
case StorageDriver.LEVELJS: return 'leveljs';
|
|
82
|
+
case StorageDriver.JSONDOWN: return 'jsondown';
|
|
83
|
+
default: throw new Error(`Invalid key storage type: ${StorageDriver[type]}`);
|
|
83
84
|
}
|
|
84
85
|
};
|