@docknetwork/wallet-sdk-data-store 0.4.19 → 1.4.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/jest.config.ts +0 -1
- package/lib/configs.d.ts.map +1 -1
- package/lib/configs.js +4 -9
- package/lib/configs.js.map +1 -1
- package/lib/helpers.d.ts +5 -4
- package/lib/helpers.d.ts.map +1 -1
- package/lib/helpers.js +53 -44
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +12 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +44 -48
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +2 -0
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +6 -0
- package/lib/logger.js.map +1 -1
- package/lib/types.d.ts +41 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +8 -0
- package/lib/types.js.map +1 -1
- package/package.json +3 -2
- package/src/configs.ts +4 -9
- package/src/helpers.ts +17 -42
- package/src/index.ts +40 -31
- package/src/logger.ts +6 -0
- package/src/types.ts +46 -3
- package/test/mock-local-storage.ts +1 -1
- package/test/wallet.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/LICENSE +0 -39
- package/lib/entities/document/create-document.d.ts +0 -10
- package/lib/entities/document/create-document.d.ts.map +0 -1
- package/lib/entities/document/create-document.js +0 -111
- package/lib/entities/document/create-document.js.map +0 -1
- package/lib/entities/document/document.entity.d.ts +0 -11
- package/lib/entities/document/document.entity.d.ts.map +0 -1
- package/lib/entities/document/document.entity.js +0 -55
- package/lib/entities/document/document.entity.js.map +0 -1
- package/lib/entities/document/get-all-documents.d.ts +0 -11
- package/lib/entities/document/get-all-documents.d.ts.map +0 -1
- package/lib/entities/document/get-all-documents.js +0 -78
- package/lib/entities/document/get-all-documents.js.map +0 -1
- package/lib/entities/document/get-documens-by-type.d.ts +0 -10
- package/lib/entities/document/get-documens-by-type.d.ts.map +0 -1
- package/lib/entities/document/get-documens-by-type.js +0 -71
- package/lib/entities/document/get-documens-by-type.js.map +0 -1
- package/lib/entities/document/get-document-by-id.d.ts +0 -13
- package/lib/entities/document/get-document-by-id.d.ts.map +0 -1
- package/lib/entities/document/get-document-by-id.js +0 -92
- package/lib/entities/document/get-document-by-id.js.map +0 -1
- package/lib/entities/document/get-document-correlations.d.ts +0 -10
- package/lib/entities/document/get-document-correlations.d.ts.map +0 -1
- package/lib/entities/document/get-document-correlations.js +0 -78
- package/lib/entities/document/get-document-correlations.js.map +0 -1
- package/lib/entities/document/helpers.d.ts +0 -30
- package/lib/entities/document/helpers.d.ts.map +0 -1
- package/lib/entities/document/helpers.js +0 -196
- package/lib/entities/document/helpers.js.map +0 -1
- package/lib/entities/document/index.d.ts +0 -10
- package/lib/entities/document/index.d.ts.map +0 -1
- package/lib/entities/document/index.js +0 -26
- package/lib/entities/document/index.js.map +0 -1
- package/lib/entities/document/remove-document.d.ts +0 -15
- package/lib/entities/document/remove-document.d.ts.map +0 -1
- package/lib/entities/document/remove-document.js +0 -94
- package/lib/entities/document/remove-document.js.map +0 -1
- package/lib/entities/document/update-document.d.ts +0 -10
- package/lib/entities/document/update-document.d.ts.map +0 -1
- package/lib/entities/document/update-document.js +0 -72
- package/lib/entities/document/update-document.js.map +0 -1
- package/lib/entities/document-type.entity.d.ts +0 -6
- package/lib/entities/document-type.entity.d.ts.map +0 -1
- package/lib/entities/document-type.entity.js +0 -32
- package/lib/entities/document-type.entity.js.map +0 -1
- package/lib/entities/log.entity.d.ts +0 -15
- package/lib/entities/log.entity.d.ts.map +0 -1
- package/lib/entities/log.entity.js +0 -108
- package/lib/entities/log.entity.js.map +0 -1
- package/lib/entities/network.entity.d.ts +0 -6
- package/lib/entities/network.entity.d.ts.map +0 -1
- package/lib/entities/network.entity.js +0 -35
- package/lib/entities/network.entity.js.map +0 -1
- package/lib/entities/transaction.entity.d.ts +0 -24
- package/lib/entities/transaction.entity.d.ts.map +0 -1
- package/lib/entities/transaction.entity.js +0 -139
- package/lib/entities/transaction.entity.js.map +0 -1
- package/lib/entities/wallet.entity.d.ts +0 -10
- package/lib/entities/wallet.entity.d.ts.map +0 -1
- package/lib/entities/wallet.entity.js +0 -109
- package/lib/entities/wallet.entity.js.map +0 -1
- package/lib/migration/bootstrap-tables.d.ts +0 -3
- package/lib/migration/bootstrap-tables.d.ts.map +0 -1
- package/lib/migration/bootstrap-tables.js +0 -8
- package/lib/migration/bootstrap-tables.js.map +0 -1
- package/lib/migration/index.d.ts +0 -8
- package/lib/migration/index.d.ts.map +0 -1
- package/lib/migration/index.js +0 -132
- package/lib/migration/index.js.map +0 -1
- package/lib/migration/migration1/index.d.ts +0 -16
- package/lib/migration/migration1/index.d.ts.map +0 -1
- package/lib/migration/migration1/index.js +0 -110
- package/lib/migration/migration1/index.js.map +0 -1
- package/lib/migration/migration1/migrate-v1-data.d.ts +0 -8
- package/lib/migration/migration1/migrate-v1-data.d.ts.map +0 -1
- package/lib/migration/migration1/migrate-v1-data.js +0 -171
- package/lib/migration/migration1/migrate-v1-data.js.map +0 -1
- package/lib/migration/migration1/v1-data-store.d.ts +0 -15
- package/lib/migration/migration1/v1-data-store.d.ts.map +0 -1
- package/lib/migration/migration1/v1-data-store.js +0 -80
- package/lib/migration/migration1/v1-data-store.js.map +0 -1
- package/lib/migrations/1691498362273-bootstrap.d.ts +0 -7
- package/lib/migrations/1691498362273-bootstrap.d.ts.map +0 -1
- package/lib/migrations/1691498362273-bootstrap.js +0 -178
- package/lib/migrations/1691498362273-bootstrap.js.map +0 -1
- package/lib/migrations/index.d.ts +0 -4
- package/lib/migrations/index.d.ts.map +0 -1
- package/lib/migrations/index.js +0 -5
- package/lib/migrations/index.js.map +0 -1
- package/lib/migrations-data-source.d.ts +0 -3
- package/lib/migrations-data-source.d.ts.map +0 -1
- package/lib/migrations-data-source.js +0 -8
- package/lib/migrations-data-source.js.map +0 -1
- package/lib/typeorm.d.ts +0 -2
- package/lib/typeorm.d.ts.map +0 -1
- package/lib/typeorm.js +0 -18
- package/lib/typeorm.js.map +0 -1
- package/setup-tests.ts +0 -0
- package/src/entities/document/create-document.ts +0 -72
- package/src/entities/document/decument.entity.test.ts +0 -135
- package/src/entities/document/document.entity.ts +0 -40
- package/src/entities/document/get-all-documents.ts +0 -39
- package/src/entities/document/get-documens-by-type.ts +0 -30
- package/src/entities/document/get-document-by-id.ts +0 -45
- package/src/entities/document/get-document-correlations.ts +0 -34
- package/src/entities/document/helpers.ts +0 -115
- package/src/entities/document/index.ts +0 -9
- package/src/entities/document/remove-document.ts +0 -34
- package/src/entities/document/update-document.ts +0 -25
- package/src/entities/document-type.entity.ts +0 -11
- package/src/entities/log.entity.ts +0 -46
- package/src/entities/network.entity.ts +0 -14
- package/src/entities/transaction.entity.ts +0 -67
- package/src/entities/wallet.entity.ts +0 -37
- package/src/migration/bootstrap-tables.ts +0 -5
- package/src/migration/index.ts +0 -53
- package/src/migration/migration1/index.ts +0 -64
- package/src/migration/migration1/migrate-v1-data.ts +0 -57
- package/src/migration/migration1/v1-data-store.ts +0 -39
- package/src/migrations/1691498362273-bootstrap.ts +0 -130
- package/src/migrations/index.ts +0 -3
- package/src/migrations-data-source.ts +0 -6
- package/src/typeorm.ts +0 -1
package/src/helpers.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// import {SDKConfigsEntity} from './entities/data-store-configs.entity';
|
|
3
|
-
import {logger} from './logger';
|
|
4
|
-
import {DataStoreConfigs} from './types';
|
|
5
|
-
import {NetworkEntity} from './entities/network.entity';
|
|
6
|
-
import {DocumentEntity} from './entities/document/document.entity';
|
|
7
|
-
import {DocumentTypeEntity} from './entities/document-type.entity';
|
|
8
|
-
import {WalletEntity} from './entities/wallet.entity';
|
|
9
|
-
import typeOrmMigrations from './migrations';
|
|
10
|
-
import { LogEntity } from './entities/log.entity';
|
|
11
|
-
import { TransactionEntity } from './entities/transaction.entity';
|
|
1
|
+
import {DataStore, DataStoreConfigs} from './types';
|
|
12
2
|
|
|
13
3
|
export function documentHasType(document: any, type: string) {
|
|
14
4
|
if (Array.isArray(document.type)) {
|
|
@@ -18,35 +8,20 @@ export function documentHasType(document: any, type: string) {
|
|
|
18
8
|
return document.type === type;
|
|
19
9
|
}
|
|
20
10
|
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
migrationsRun: process.env.NODE_ENV !== 'test',
|
|
31
|
-
migrations: typeOrmMigrations,
|
|
32
|
-
...(options.typeORMConfigs || {}),
|
|
33
|
-
});
|
|
11
|
+
export async function importUniversalWalletDocuments({documents, dataStore}: {
|
|
12
|
+
documents: any[];
|
|
13
|
+
dataStore: DataStore;
|
|
14
|
+
}) {
|
|
15
|
+
for (const _document of documents) {
|
|
16
|
+
let document = _document;
|
|
17
|
+
if (documentHasType(document, 'VerifiableCredential') && document.value) {
|
|
18
|
+
document = document.value;
|
|
19
|
+
}
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.initialize()
|
|
43
|
-
.then(() => {
|
|
44
|
-
logger.debug('Data Source initialized successfully');
|
|
45
|
-
})
|
|
46
|
-
.catch(err => {
|
|
47
|
-
logger.error(`Error during Data Source initialization: ${err}`);
|
|
48
|
-
throw err;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return dataSource;
|
|
52
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
await dataStore.documents.addDocument(document);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error(err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {EventEmitter} from 'events';
|
|
2
2
|
import {DataStore, DataStoreConfigs} from './types';
|
|
3
|
-
import {migrate} from './migration';
|
|
4
3
|
import {DEFAULT_CONFIGS} from './configs';
|
|
5
4
|
import {logger} from './logger';
|
|
6
|
-
import {DataSource} from './typeorm';
|
|
7
5
|
import assert from 'assert';
|
|
8
|
-
import {getWallet, updateWallet} from './entities/wallet.entity';
|
|
9
|
-
import { getV1LocalStorage } from './migration/migration1/v1-data-store';
|
|
10
|
-
import { getAllDocuments } from './entities/document';
|
|
11
6
|
|
|
7
|
+
import {DocumentStore, DataSource, WalletStore} from './types';
|
|
12
8
|
|
|
13
|
-
export
|
|
9
|
+
export let _localStorageImpl = global.localStorage;
|
|
10
|
+
export const getLocalStorage = () => _localStorageImpl;
|
|
11
|
+
export const setLocalStorage = impl => {
|
|
12
|
+
console.log('Setting local storage impl', impl);
|
|
13
|
+
_localStorageImpl = impl
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function parseConfigs(configs: DataStoreConfigs): DataStoreConfigs {
|
|
17
|
+
const options: DataStoreConfigs = {
|
|
18
|
+
...DEFAULT_CONFIGS,
|
|
19
|
+
...configs,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (!options.defaultNetwork) {
|
|
23
|
+
options.defaultNetwork = options.networks[0].id;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return options;
|
|
27
|
+
}
|
|
14
28
|
|
|
15
29
|
export async function updateNetwork({
|
|
16
30
|
dataStore,
|
|
@@ -26,23 +40,28 @@ export async function updateNetwork({
|
|
|
26
40
|
dataStore.network = network;
|
|
27
41
|
dataStore.networkId = networkId;
|
|
28
42
|
|
|
29
|
-
await updateWallet({dataStore});
|
|
43
|
+
await dataStore.wallet.updateWallet({dataStore});
|
|
30
44
|
}
|
|
31
45
|
|
|
32
|
-
export async function createDataStore(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
export async function createDataStore({
|
|
47
|
+
configs,
|
|
48
|
+
documentStore,
|
|
49
|
+
walletStore,
|
|
50
|
+
dataSource,
|
|
51
|
+
localStorageImpl,
|
|
52
|
+
}: {
|
|
53
|
+
configs: DataStoreConfigs;
|
|
54
|
+
documentStore: DocumentStore;
|
|
55
|
+
walletStore: WalletStore;
|
|
56
|
+
dataSource: DataSource;
|
|
57
|
+
localStorageImpl: any;
|
|
58
|
+
}): Promise<DataStore> {
|
|
59
|
+
_localStorageImpl = localStorageImpl;
|
|
39
60
|
|
|
40
|
-
|
|
41
|
-
options.defaultNetwork = options.networks[0].id;
|
|
42
|
-
}
|
|
61
|
+
const options = parseConfigs(configs);
|
|
43
62
|
|
|
44
|
-
const dataSource: DataSource = await initializeTypeORM(options);
|
|
45
63
|
const dataStore: DataStore = {
|
|
64
|
+
events: new EventEmitter(),
|
|
46
65
|
db: dataSource,
|
|
47
66
|
networkId: options.defaultNetwork,
|
|
48
67
|
network: options.networks.find(item => item.id === options.defaultNetwork),
|
|
@@ -55,22 +74,12 @@ export async function createDataStore(
|
|
|
55
74
|
logger.debug(`Setting network to ${networkId}`);
|
|
56
75
|
return updateNetwork({dataStore, networkId});
|
|
57
76
|
},
|
|
77
|
+
wallet: walletStore,
|
|
78
|
+
documents: documentStore,
|
|
58
79
|
};
|
|
59
80
|
|
|
60
81
|
logger.debug('Data store initialized');
|
|
61
82
|
|
|
62
|
-
await migrate({dataStore});
|
|
63
|
-
|
|
64
|
-
const wallet = await getWallet({dataStore});
|
|
65
|
-
dataStore.networkId = wallet.networkId;
|
|
66
|
-
dataStore.network = options.networks.find(
|
|
67
|
-
item => item.id === wallet.networkId,
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
getAllDocuments({dataStore}).then(documents => {
|
|
71
|
-
logger.debug(`Wallet loaded with ${documents.length} documents`);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
83
|
return dataStore;
|
|
75
84
|
}
|
|
76
85
|
|
package/src/logger.ts
CHANGED
|
@@ -11,6 +11,9 @@ const ConsoleTransport = {
|
|
|
11
11
|
warn: (message: string) => {
|
|
12
12
|
console.warn(message);
|
|
13
13
|
},
|
|
14
|
+
performance: (action: string, startTime: number) => {
|
|
15
|
+
console.log(`[PERFORMANCE] ${action} in ${new Date().getTime() - startTime}ms`);
|
|
16
|
+
}
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
export let logger = ConsoleTransport;
|
|
@@ -33,5 +36,8 @@ export const createLogger = (prefix: string) => {
|
|
|
33
36
|
warn: (message: string) => {
|
|
34
37
|
logger.warn(`[${prefix}] ${message}`);
|
|
35
38
|
},
|
|
39
|
+
performance: (action: string, time: number) => {
|
|
40
|
+
logger.log(`[PERFORMANCE] ${action} took ${time}ms`);
|
|
41
|
+
}
|
|
36
42
|
};
|
|
37
43
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {WalletEntity} from './entities/wallet.entity';
|
|
1
|
+
import {EventEmitter} from 'events';
|
|
3
2
|
|
|
4
3
|
export type DocumentResolverProps = {
|
|
5
4
|
document: WalletDocument;
|
|
@@ -12,16 +11,40 @@ export type DocumentNetworkResolver = (
|
|
|
12
11
|
export type DocumentResolverResult = {
|
|
13
12
|
networkId: string;
|
|
14
13
|
isFallback: boolean;
|
|
14
|
+
resolver?: Function;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export type Network = {
|
|
18
18
|
name: string;
|
|
19
19
|
id: string;
|
|
20
|
-
credentialHostnames: string
|
|
20
|
+
credentialHostnames: [string | RegExp];
|
|
21
21
|
configs?: any;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
export type DataSource = {
|
|
25
|
+
initialize: () => Promise<void>;
|
|
26
|
+
destroy: () => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type DocumentStore = {
|
|
30
|
+
addDocument: (json: any, options?: any) => Promise<WalletDocument>;
|
|
31
|
+
updateDocument: (json: any, options?: any) => Promise<WalletDocument>;
|
|
32
|
+
removeDocument: (id: string, options?: any) => Promise<void>;
|
|
33
|
+
getDocumentById: (id: string) => Promise<WalletDocument>;
|
|
34
|
+
getDocumentsById: (idList: string[]) => Promise<WalletDocument[]>;
|
|
35
|
+
getDocumentsByType: (type: string) => Promise<WalletDocument[]>;
|
|
36
|
+
getAllDocuments: (allNetworks?: any) => Promise<WalletDocument[]>;
|
|
37
|
+
removeAllDocuments: () => Promise<void>;
|
|
38
|
+
getDocumentCorrelations: (documentId: string) => Promise<WalletDocument[]>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type WalletStore = {
|
|
42
|
+
getWallet: () => Promise<WalletDocument>;
|
|
43
|
+
updateWallet: (json: any) => Promise<WalletDocument>;
|
|
44
|
+
}
|
|
45
|
+
|
|
24
46
|
export type DataStore = {
|
|
47
|
+
events: EventEmitter;
|
|
25
48
|
db: DataSource;
|
|
26
49
|
networkId: string;
|
|
27
50
|
testNetworkId: string;
|
|
@@ -32,6 +55,8 @@ export type DataStore = {
|
|
|
32
55
|
version?: string;
|
|
33
56
|
resolveDocumentNetwork: DocumentNetworkResolver;
|
|
34
57
|
setNetwork: (networkId: string) => Promise<void>;
|
|
58
|
+
documents: DocumentStore;
|
|
59
|
+
wallet: WalletStore;
|
|
35
60
|
};
|
|
36
61
|
|
|
37
62
|
export type ContextProps = {
|
|
@@ -57,6 +82,10 @@ export type DataStoreConfigs = {
|
|
|
57
82
|
documentNetworkResolver?: DocumentNetworkResolver;
|
|
58
83
|
sqlJsConfig?: any;
|
|
59
84
|
typeORMConfigs?: any;
|
|
85
|
+
cloudWallet?: {
|
|
86
|
+
edvUrl: string;
|
|
87
|
+
authKey: string;
|
|
88
|
+
}
|
|
60
89
|
};
|
|
61
90
|
|
|
62
91
|
export type AnyJSON = any;
|
|
@@ -65,3 +94,17 @@ export type WalletDocument = {
|
|
|
65
94
|
id: string;
|
|
66
95
|
type: string[] | string;
|
|
67
96
|
} & AnyJSON;
|
|
97
|
+
|
|
98
|
+
export enum DataStoreEvents {
|
|
99
|
+
DocumentCreated = 'DocumentCreated',
|
|
100
|
+
DocumentUpdated = 'DocumentUpdated',
|
|
101
|
+
DocumentDeleted = 'DocumentDeleted',
|
|
102
|
+
AllDocumentsDeleted = 'AllDocumentsDeleted',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export type LocalStorage = {
|
|
107
|
+
getItem: (key: string) => Promise<string | null>;
|
|
108
|
+
setItem: (key: string, value: string) => Promise<void>;
|
|
109
|
+
removeItem: (key: string) => Promise<void>;
|
|
110
|
+
};
|
package/test/wallet.json
CHANGED
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
"https://ld.dock.io/credentials/prettyvc"
|
|
87
87
|
],
|
|
88
|
-
"id": "https://creds-
|
|
88
|
+
"id": "https://creds-example.dock.io/cca99aae610dc3e0c2c6c60ac9a1866211022499d36cf1c72bb7889316ee6fd0",
|
|
89
89
|
"type": [
|
|
90
90
|
"VerifiableCredential",
|
|
91
91
|
"BasicCredential",
|