@docknetwork/wallet-sdk-data-store 0.4.19 → 0.4.22
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
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Entity, Column, PrimaryColumn } from 'typeorm';
|
|
2
|
-
import { DataStore } from '../types';
|
|
3
|
-
|
|
4
|
-
@Entity()
|
|
5
|
-
export class TransactionEntity {
|
|
6
|
-
@PrimaryColumn()
|
|
7
|
-
id: string;
|
|
8
|
-
|
|
9
|
-
@Column({ nullable: true })
|
|
10
|
-
hash: string;
|
|
11
|
-
|
|
12
|
-
@Column({ default: 'transfer' })
|
|
13
|
-
type: string;
|
|
14
|
-
|
|
15
|
-
@Column({ nullable: true })
|
|
16
|
-
error: string;
|
|
17
|
-
|
|
18
|
-
@Column({ nullable: true })
|
|
19
|
-
metadata: string;
|
|
20
|
-
|
|
21
|
-
@Column()
|
|
22
|
-
date: Date;
|
|
23
|
-
|
|
24
|
-
@Column()
|
|
25
|
-
fromAddress: string;
|
|
26
|
-
|
|
27
|
-
@Column()
|
|
28
|
-
recipientAddress: string;
|
|
29
|
-
|
|
30
|
-
@Column({ nullable: true })
|
|
31
|
-
amount: string;
|
|
32
|
-
|
|
33
|
-
@Column()
|
|
34
|
-
feeAmount: string;
|
|
35
|
-
|
|
36
|
-
@Column({ default: 'testnet' })
|
|
37
|
-
network: string;
|
|
38
|
-
|
|
39
|
-
@Column()
|
|
40
|
-
status: string;
|
|
41
|
-
|
|
42
|
-
@Column({ default: false })
|
|
43
|
-
retrySucceeded: boolean;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function getLogs({
|
|
47
|
-
dataStore,
|
|
48
|
-
}: {
|
|
49
|
-
dataStore: DataStore;
|
|
50
|
-
}): Promise<TransactionEntity[]> {
|
|
51
|
-
const repository = dataStore.db.getRepository(TransactionEntity);
|
|
52
|
-
const entities = await repository.find({});
|
|
53
|
-
|
|
54
|
-
return entities;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function createTransaction({
|
|
58
|
-
dataStore,
|
|
59
|
-
transaction,
|
|
60
|
-
}: {
|
|
61
|
-
dataStore: DataStore;
|
|
62
|
-
transaction: TransactionEntity,
|
|
63
|
-
}): Promise<TransactionEntity> {
|
|
64
|
-
const repository = dataStore.db.getRepository(TransactionEntity);
|
|
65
|
-
|
|
66
|
-
return repository.save(transaction);
|
|
67
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {Entity, Column, PrimaryGeneratedColumn, PrimaryColumn} from '../typeorm';
|
|
2
|
-
import {ContextProps} from '../types';
|
|
3
|
-
|
|
4
|
-
@Entity()
|
|
5
|
-
export class WalletEntity {
|
|
6
|
-
@PrimaryColumn()
|
|
7
|
-
id: string;
|
|
8
|
-
|
|
9
|
-
@Column({
|
|
10
|
-
nullable: true,
|
|
11
|
-
})
|
|
12
|
-
version?: string;
|
|
13
|
-
|
|
14
|
-
@Column()
|
|
15
|
-
networkId: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function getWallet({
|
|
19
|
-
dataStore,
|
|
20
|
-
}: ContextProps): Promise<WalletEntity> {
|
|
21
|
-
const result = await dataStore.db.getRepository(WalletEntity).find();
|
|
22
|
-
return result[0];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function createWallet({dataStore}: ContextProps): Promise<WalletEntity> {
|
|
26
|
-
return dataStore.db.getRepository(WalletEntity).save({
|
|
27
|
-
id: 'configs',
|
|
28
|
-
...dataStore,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function updateWallet({dataStore}: ContextProps): Promise<WalletEntity> {
|
|
33
|
-
return dataStore.db.getRepository(WalletEntity).save({
|
|
34
|
-
id: 'configs',
|
|
35
|
-
...dataStore,
|
|
36
|
-
});
|
|
37
|
-
}
|
package/src/migration/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {isRunningOnV1DataStore, migration1} from './migration1';
|
|
2
|
-
import {ContextProps} from '../types';
|
|
3
|
-
import {logger} from '../logger';
|
|
4
|
-
import {createWallet, getWallet, updateWallet} from '../entities/wallet.entity';
|
|
5
|
-
import {bootstrapTables} from './bootstrap-tables';
|
|
6
|
-
|
|
7
|
-
export const CURRENT_DATA_STORE_VERSION = 'v2';
|
|
8
|
-
|
|
9
|
-
export type MigrationResult = {
|
|
10
|
-
migrated: boolean;
|
|
11
|
-
version: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const migrations = [
|
|
15
|
-
migration1,
|
|
16
|
-
// add new migrations here
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export async function migrate({dataStore}: ContextProps) {
|
|
20
|
-
// bootstrap v2 data
|
|
21
|
-
await bootstrapTables(dataStore.db);
|
|
22
|
-
|
|
23
|
-
// Fetch existing configs from the database
|
|
24
|
-
let existingConfigs = await getWallet({dataStore});
|
|
25
|
-
|
|
26
|
-
// Force v1 migration
|
|
27
|
-
// dataStore.version = 'v1';
|
|
28
|
-
// If no configs exist, create a new one
|
|
29
|
-
if (!existingConfigs) {
|
|
30
|
-
logger.debug('Wallet not found in the database, creating a new wallet...');
|
|
31
|
-
const isV1DataStore = await isRunningOnV1DataStore({dataStore});
|
|
32
|
-
logger.debug(`Is v1 data store: ${isV1DataStore}`);
|
|
33
|
-
dataStore.version = isV1DataStore ? 'v1' : CURRENT_DATA_STORE_VERSION;
|
|
34
|
-
await createWallet({
|
|
35
|
-
dataStore,
|
|
36
|
-
});
|
|
37
|
-
logger.debug('universal wallet created');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (const migrate of migrations) {
|
|
41
|
-
const results = await migrate({dataStore});
|
|
42
|
-
|
|
43
|
-
if (results.migrated) {
|
|
44
|
-
logger.debug('Migration completed');
|
|
45
|
-
dataStore.version = results.version;
|
|
46
|
-
await updateWallet({dataStore});
|
|
47
|
-
} else {
|
|
48
|
-
logger.debug('Migration not required');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
logger.debug(`DataStore version: ${dataStore.version}`);
|
|
53
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {getV1LocalStorage, getWalletDocuments} from './v1-data-store';
|
|
2
|
-
import {logger} from '../../logger';
|
|
3
|
-
import {migrateV1Data} from './migrate-v1-data';
|
|
4
|
-
import {MigrationResult} from '../index';
|
|
5
|
-
import {ContextProps} from '../../types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Migrate from v1 to v2
|
|
9
|
-
*
|
|
10
|
-
* v1 data store is stored in local storage
|
|
11
|
-
* v2 will store on typeorm
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
export async function migration1({
|
|
15
|
-
dataStore,
|
|
16
|
-
}: ContextProps): Promise<MigrationResult> {
|
|
17
|
-
logger.debug('Checking if v1 migration is required');
|
|
18
|
-
|
|
19
|
-
if (dataStore.version !== 'v1') {
|
|
20
|
-
logger.debug('v1 data migration NOT required');
|
|
21
|
-
return {
|
|
22
|
-
migrated: false,
|
|
23
|
-
version: dataStore.version,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
logger.debug('v1 data Migration required');
|
|
28
|
-
|
|
29
|
-
await migrateV1Data({dataStore});
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
migrated: true,
|
|
33
|
-
version: 'v2',
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Check if a migration from v2 is required
|
|
39
|
-
* Once v2 is migrated, the local storage entry will be removed
|
|
40
|
-
*/
|
|
41
|
-
export async function isRunningOnV1DataStore({
|
|
42
|
-
dataStore,
|
|
43
|
-
}: ContextProps): Promise<boolean> {
|
|
44
|
-
// If sdk version is defined, can skip migration
|
|
45
|
-
if (dataStore.version) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const v1LocalStorage = getV1LocalStorage();
|
|
50
|
-
|
|
51
|
-
if (!v1LocalStorage) {
|
|
52
|
-
logger.debug('v1 local storage not found');
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const documents = await getWalletDocuments();
|
|
57
|
-
|
|
58
|
-
if (documents.length === 0) {
|
|
59
|
-
logger.debug('no documents found on v1 data store');
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {getV1LocalStorage} from './v1-data-store';
|
|
2
|
-
import {createDocument} from '../../entities/document';
|
|
3
|
-
import {documentHasType} from '../../helpers';
|
|
4
|
-
|
|
5
|
-
export async function importUniversalWalletDocuments({documents, dataStore}) {
|
|
6
|
-
for (const _document of documents) {
|
|
7
|
-
let document = _document;
|
|
8
|
-
if (documentHasType(document, 'VerifiableCredential') && document.value) {
|
|
9
|
-
document = document.value;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
await createDocument({
|
|
14
|
-
dataStore,
|
|
15
|
-
json: document,
|
|
16
|
-
});
|
|
17
|
-
} catch (err) {
|
|
18
|
-
console.error(err);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async function migrateDocuments({v1Storage, dataStore}) {
|
|
23
|
-
const walletJSON = await v1Storage.getItem('wallet');
|
|
24
|
-
const wallet = JSON.parse(walletJSON);
|
|
25
|
-
|
|
26
|
-
const documents = Object.keys(wallet).map(key => wallet[key]);
|
|
27
|
-
|
|
28
|
-
await importUniversalWalletDocuments({documents, dataStore});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function migrateNotificaions() {}
|
|
32
|
-
|
|
33
|
-
function migrateDevSettings() {}
|
|
34
|
-
|
|
35
|
-
function migrateTransactions() {
|
|
36
|
-
// Will skip this migration for performance improvements
|
|
37
|
-
// That would require Realm db as dependency
|
|
38
|
-
// We can drop the realm.db dependency from the wallet-sdk
|
|
39
|
-
// Transactions will be pulled from subscan into in the new data-store automatically
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function migrateV1Data({dataStore}) {
|
|
43
|
-
const v1Storage = getV1LocalStorage();
|
|
44
|
-
|
|
45
|
-
await migrateDocuments({
|
|
46
|
-
v1Storage,
|
|
47
|
-
dataStore,
|
|
48
|
-
});
|
|
49
|
-
await migrateNotificaions();
|
|
50
|
-
await migrateDevSettings();
|
|
51
|
-
await migrateTransactions();
|
|
52
|
-
|
|
53
|
-
// remove localStorage entries
|
|
54
|
-
const walletJSON = await v1Storage.getItem('wallet');
|
|
55
|
-
await v1Storage.setItem('wallet-backup', walletJSON);
|
|
56
|
-
await v1Storage.removeItem('wallet');
|
|
57
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
|
|
3
|
-
export type LocalStorage = {
|
|
4
|
-
getItem: (key: string) => Promise<string | null>;
|
|
5
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
6
|
-
removeItem: (key: string) => Promise<void>;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
let _localStorage: LocalStorage;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Legacy data-store was based on AsyncLocalStorage
|
|
13
|
-
* The wallet will inject its implementation here, so that the migration scripts can use it
|
|
14
|
-
*
|
|
15
|
-
* @param _impl
|
|
16
|
-
*/
|
|
17
|
-
export function setV1LocalStorage(_impl: LocalStorage) {
|
|
18
|
-
assert(!!_impl, 'LocalStorage implementation is required');
|
|
19
|
-
|
|
20
|
-
_localStorage = _impl;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function getV1LocalStorage(): LocalStorage {
|
|
24
|
-
return _localStorage;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function getWalletDocuments() {
|
|
28
|
-
const jsonData = await _localStorage.getItem('wallet');
|
|
29
|
-
|
|
30
|
-
if (!jsonData) {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const wallet = JSON.parse(jsonData as string);
|
|
35
|
-
|
|
36
|
-
return Object.keys(wallet).map(key => {
|
|
37
|
-
return wallet[key];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MigrationInterface,
|
|
3
|
-
QueryRunner,
|
|
4
|
-
Table,
|
|
5
|
-
TableColumn,
|
|
6
|
-
TableForeignKey,
|
|
7
|
-
TableIndex,
|
|
8
|
-
} from 'typeorm';
|
|
9
|
-
import { logger } from '../logger';
|
|
10
|
-
|
|
11
|
-
export class Bootstrap1691498362273 implements MigrationInterface {
|
|
12
|
-
name = 'Bootstrap1691498362273';
|
|
13
|
-
|
|
14
|
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
15
|
-
const hasNetworkEntityTable = await queryRunner.hasTable('network_entity');
|
|
16
|
-
|
|
17
|
-
if (hasNetworkEntityTable) {
|
|
18
|
-
logger.debug('Table already bootstrapped');
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
logger.debug('Running table bootstrap migration');
|
|
23
|
-
|
|
24
|
-
await queryRunner.createTable(
|
|
25
|
-
new Table({
|
|
26
|
-
name: 'network_entity',
|
|
27
|
-
columns: [
|
|
28
|
-
new TableColumn({name: 'id', type: 'varchar', isPrimary: true}),
|
|
29
|
-
new TableColumn({name: 'name', type: 'varchar'}),
|
|
30
|
-
new TableColumn({name: 'configs', type: 'varchar'}),
|
|
31
|
-
],
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
await queryRunner.createTable(
|
|
36
|
-
new Table({
|
|
37
|
-
name: 'document_type_entity',
|
|
38
|
-
columns: [new TableColumn({name: 'id', type: 'text', isPrimary: true})],
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
await queryRunner.createTable(
|
|
43
|
-
new Table({
|
|
44
|
-
name: 'document_entity',
|
|
45
|
-
columns: [
|
|
46
|
-
new TableColumn({name: 'id', type: 'text', isPrimary: true}),
|
|
47
|
-
new TableColumn({name: 'networkId', type: 'text', isNullable: true}),
|
|
48
|
-
new TableColumn({name: 'type', type: 'text'}),
|
|
49
|
-
new TableColumn({name: 'correlation', type: 'text'}),
|
|
50
|
-
new TableColumn({name: 'data', type: 'blob'}),
|
|
51
|
-
],
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
await queryRunner.createTable(
|
|
56
|
-
new Table({
|
|
57
|
-
name: 'wallet_entity',
|
|
58
|
-
columns: [
|
|
59
|
-
new TableColumn({name: 'id', type: 'varchar', isPrimary: true}),
|
|
60
|
-
new TableColumn({name: 'version', type: 'varchar', isNullable: true}),
|
|
61
|
-
new TableColumn({name: 'networkId', type: 'varchar'}),
|
|
62
|
-
],
|
|
63
|
-
}),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
await queryRunner.createTable(
|
|
67
|
-
new Table({
|
|
68
|
-
name: 'document_entity__type_rel_document_type_entity',
|
|
69
|
-
columns: [
|
|
70
|
-
new TableColumn({
|
|
71
|
-
name: 'documentEntityId',
|
|
72
|
-
type: 'text',
|
|
73
|
-
isPrimary: true,
|
|
74
|
-
}),
|
|
75
|
-
new TableColumn({
|
|
76
|
-
name: 'documentTypeEntityId',
|
|
77
|
-
type: 'text',
|
|
78
|
-
isPrimary: true,
|
|
79
|
-
}),
|
|
80
|
-
],
|
|
81
|
-
foreignKeys: [
|
|
82
|
-
new TableForeignKey({
|
|
83
|
-
columnNames: ['documentEntityId'],
|
|
84
|
-
referencedColumnNames: ['id'],
|
|
85
|
-
referencedTableName: 'document_entity',
|
|
86
|
-
onDelete: 'CASCADE',
|
|
87
|
-
onUpdate: 'CASCADE',
|
|
88
|
-
}),
|
|
89
|
-
new TableForeignKey({
|
|
90
|
-
columnNames: ['documentTypeEntityId'],
|
|
91
|
-
referencedColumnNames: ['id'],
|
|
92
|
-
referencedTableName: 'document_type_entity',
|
|
93
|
-
onDelete: 'NO ACTION',
|
|
94
|
-
onUpdate: 'NO ACTION',
|
|
95
|
-
}),
|
|
96
|
-
],
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
await queryRunner.createIndex(
|
|
101
|
-
'document_entity__type_rel_document_type_entity',
|
|
102
|
-
new TableIndex({
|
|
103
|
-
name: 'IDX_e929f32563f62d753a51bcd8b9',
|
|
104
|
-
columnNames: ['documentEntityId'],
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
await queryRunner.createIndex(
|
|
109
|
-
'document_entity__type_rel_document_type_entity',
|
|
110
|
-
new TableIndex({
|
|
111
|
-
name: 'IDX_7d377ef9ddb323247aedd63d66',
|
|
112
|
-
columnNames: ['documentTypeEntityId'],
|
|
113
|
-
}),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
logger.debug('Table bootstrap migration completed');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
120
|
-
logger.debug('Running table bootstrap migration revert');
|
|
121
|
-
await queryRunner.dropTable(
|
|
122
|
-
'document_entity__type_rel_document_type_entity',
|
|
123
|
-
);
|
|
124
|
-
await queryRunner.dropTable('wallet_entity');
|
|
125
|
-
await queryRunner.dropTable('document_entity');
|
|
126
|
-
await queryRunner.dropTable('document_type_entity');
|
|
127
|
-
await queryRunner.dropTable('network_entity');
|
|
128
|
-
logger.debug('Revert completed');
|
|
129
|
-
}
|
|
130
|
-
}
|
package/src/migrations/index.ts
DELETED
package/src/typeorm.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from 'typeorm';
|