@docknetwork/wallet-sdk-data-store 0.4.1

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.
Files changed (164) hide show
  1. package/LICENSE +39 -0
  2. package/jest.config.ts +21 -0
  3. package/lib/configs.d.ts +3 -0
  4. package/lib/configs.d.ts.map +1 -0
  5. package/lib/configs.js +30 -0
  6. package/lib/configs.js.map +1 -0
  7. package/lib/document-network-resolver.d.ts +3 -0
  8. package/lib/document-network-resolver.d.ts.map +1 -0
  9. package/lib/document-network-resolver.js +52 -0
  10. package/lib/document-network-resolver.js.map +1 -0
  11. package/lib/entities/document/create-document.d.ts +10 -0
  12. package/lib/entities/document/create-document.d.ts.map +1 -0
  13. package/lib/entities/document/create-document.js +111 -0
  14. package/lib/entities/document/create-document.js.map +1 -0
  15. package/lib/entities/document/document.entity.d.ts +11 -0
  16. package/lib/entities/document/document.entity.d.ts.map +1 -0
  17. package/lib/entities/document/document.entity.js +55 -0
  18. package/lib/entities/document/document.entity.js.map +1 -0
  19. package/lib/entities/document/get-all-documents.d.ts +11 -0
  20. package/lib/entities/document/get-all-documents.d.ts.map +1 -0
  21. package/lib/entities/document/get-all-documents.js +78 -0
  22. package/lib/entities/document/get-all-documents.js.map +1 -0
  23. package/lib/entities/document/get-documens-by-type.d.ts +10 -0
  24. package/lib/entities/document/get-documens-by-type.d.ts.map +1 -0
  25. package/lib/entities/document/get-documens-by-type.js +71 -0
  26. package/lib/entities/document/get-documens-by-type.js.map +1 -0
  27. package/lib/entities/document/get-document-by-id.d.ts +13 -0
  28. package/lib/entities/document/get-document-by-id.d.ts.map +1 -0
  29. package/lib/entities/document/get-document-by-id.js +92 -0
  30. package/lib/entities/document/get-document-by-id.js.map +1 -0
  31. package/lib/entities/document/get-document-correlations.d.ts +10 -0
  32. package/lib/entities/document/get-document-correlations.d.ts.map +1 -0
  33. package/lib/entities/document/get-document-correlations.js +78 -0
  34. package/lib/entities/document/get-document-correlations.js.map +1 -0
  35. package/lib/entities/document/helpers.d.ts +30 -0
  36. package/lib/entities/document/helpers.d.ts.map +1 -0
  37. package/lib/entities/document/helpers.js +196 -0
  38. package/lib/entities/document/helpers.js.map +1 -0
  39. package/lib/entities/document/index.d.ts +10 -0
  40. package/lib/entities/document/index.d.ts.map +1 -0
  41. package/lib/entities/document/index.js +26 -0
  42. package/lib/entities/document/index.js.map +1 -0
  43. package/lib/entities/document/remove-document.d.ts +15 -0
  44. package/lib/entities/document/remove-document.d.ts.map +1 -0
  45. package/lib/entities/document/remove-document.js +94 -0
  46. package/lib/entities/document/remove-document.js.map +1 -0
  47. package/lib/entities/document/update-document.d.ts +10 -0
  48. package/lib/entities/document/update-document.d.ts.map +1 -0
  49. package/lib/entities/document/update-document.js +72 -0
  50. package/lib/entities/document/update-document.js.map +1 -0
  51. package/lib/entities/document-type.entity.d.ts +6 -0
  52. package/lib/entities/document-type.entity.d.ts.map +1 -0
  53. package/lib/entities/document-type.entity.js +32 -0
  54. package/lib/entities/document-type.entity.js.map +1 -0
  55. package/lib/entities/log.entity.d.ts +15 -0
  56. package/lib/entities/log.entity.d.ts.map +1 -0
  57. package/lib/entities/log.entity.js +108 -0
  58. package/lib/entities/log.entity.js.map +1 -0
  59. package/lib/entities/network.entity.d.ts +6 -0
  60. package/lib/entities/network.entity.d.ts.map +1 -0
  61. package/lib/entities/network.entity.js +35 -0
  62. package/lib/entities/network.entity.js.map +1 -0
  63. package/lib/entities/transaction.entity.d.ts +24 -0
  64. package/lib/entities/transaction.entity.d.ts.map +1 -0
  65. package/lib/entities/transaction.entity.js +139 -0
  66. package/lib/entities/transaction.entity.js.map +1 -0
  67. package/lib/entities/wallet.entity.d.ts +10 -0
  68. package/lib/entities/wallet.entity.d.ts.map +1 -0
  69. package/lib/entities/wallet.entity.js +109 -0
  70. package/lib/entities/wallet.entity.js.map +1 -0
  71. package/lib/helpers.d.ts +6 -0
  72. package/lib/helpers.d.ts.map +1 -0
  73. package/lib/helpers.js +98 -0
  74. package/lib/helpers.js.map +1 -0
  75. package/lib/index.d.ts +14 -0
  76. package/lib/index.d.ts.map +1 -0
  77. package/lib/index.js +145 -0
  78. package/lib/index.js.map +1 -0
  79. package/lib/logger.d.ts +14 -0
  80. package/lib/logger.d.ts.map +1 -0
  81. package/lib/logger.js +40 -0
  82. package/lib/logger.js.map +1 -0
  83. package/lib/migration/bootstrap-tables.d.ts +3 -0
  84. package/lib/migration/bootstrap-tables.d.ts.map +1 -0
  85. package/lib/migration/bootstrap-tables.js +8 -0
  86. package/lib/migration/bootstrap-tables.js.map +1 -0
  87. package/lib/migration/index.d.ts +8 -0
  88. package/lib/migration/index.d.ts.map +1 -0
  89. package/lib/migration/index.js +132 -0
  90. package/lib/migration/index.js.map +1 -0
  91. package/lib/migration/migration1/index.d.ts +16 -0
  92. package/lib/migration/migration1/index.d.ts.map +1 -0
  93. package/lib/migration/migration1/index.js +110 -0
  94. package/lib/migration/migration1/index.js.map +1 -0
  95. package/lib/migration/migration1/migrate-v1-data.d.ts +8 -0
  96. package/lib/migration/migration1/migrate-v1-data.d.ts.map +1 -0
  97. package/lib/migration/migration1/migrate-v1-data.js +171 -0
  98. package/lib/migration/migration1/migrate-v1-data.js.map +1 -0
  99. package/lib/migration/migration1/v1-data-store.d.ts +15 -0
  100. package/lib/migration/migration1/v1-data-store.d.ts.map +1 -0
  101. package/lib/migration/migration1/v1-data-store.js +80 -0
  102. package/lib/migration/migration1/v1-data-store.js.map +1 -0
  103. package/lib/migrations/1691498362273-bootstrap.d.ts +7 -0
  104. package/lib/migrations/1691498362273-bootstrap.d.ts.map +1 -0
  105. package/lib/migrations/1691498362273-bootstrap.js +178 -0
  106. package/lib/migrations/1691498362273-bootstrap.js.map +1 -0
  107. package/lib/migrations/index.d.ts +4 -0
  108. package/lib/migrations/index.d.ts.map +1 -0
  109. package/lib/migrations/index.js +5 -0
  110. package/lib/migrations/index.js.map +1 -0
  111. package/lib/migrations-data-source.d.ts +3 -0
  112. package/lib/migrations-data-source.d.ts.map +1 -0
  113. package/lib/migrations-data-source.js +8 -0
  114. package/lib/migrations-data-source.js.map +1 -0
  115. package/lib/typeorm.d.ts +2 -0
  116. package/lib/typeorm.d.ts.map +1 -0
  117. package/lib/typeorm.js +18 -0
  118. package/lib/typeorm.js.map +1 -0
  119. package/lib/types.d.ts +49 -0
  120. package/lib/types.d.ts.map +1 -0
  121. package/lib/types.js +3 -0
  122. package/lib/types.js.map +1 -0
  123. package/package.json +31 -0
  124. package/scripts/publish.sh +3 -0
  125. package/setup-tests.ts +0 -0
  126. package/src/__tests__/index.test.ts +56 -0
  127. package/src/__tests__/v1-data-store.test.ts +24 -0
  128. package/src/configs.ts +28 -0
  129. package/src/document-network-resolver.ts +19 -0
  130. package/src/entities/document/create-document.ts +72 -0
  131. package/src/entities/document/decument.entity.test.ts +135 -0
  132. package/src/entities/document/document.entity.ts +40 -0
  133. package/src/entities/document/get-all-documents.ts +39 -0
  134. package/src/entities/document/get-documens-by-type.ts +30 -0
  135. package/src/entities/document/get-document-by-id.ts +45 -0
  136. package/src/entities/document/get-document-correlations.ts +34 -0
  137. package/src/entities/document/helpers.ts +115 -0
  138. package/src/entities/document/index.ts +9 -0
  139. package/src/entities/document/remove-document.ts +34 -0
  140. package/src/entities/document/update-document.ts +25 -0
  141. package/src/entities/document-type.entity.ts +11 -0
  142. package/src/entities/log.entity.ts +46 -0
  143. package/src/entities/network.entity.ts +14 -0
  144. package/src/entities/transaction.entity.ts +67 -0
  145. package/src/entities/wallet.entity.ts +37 -0
  146. package/src/helpers.ts +52 -0
  147. package/src/index.ts +83 -0
  148. package/src/logger.ts +37 -0
  149. package/src/migration/bootstrap-tables.ts +5 -0
  150. package/src/migration/index.ts +53 -0
  151. package/src/migration/migration1/index.ts +64 -0
  152. package/src/migration/migration1/migrate-v1-data.ts +57 -0
  153. package/src/migration/migration1/v1-data-store.ts +39 -0
  154. package/src/migrations/1691498362273-bootstrap.ts +130 -0
  155. package/src/migrations/index.ts +3 -0
  156. package/src/migrations-data-source.ts +6 -0
  157. package/src/typeorm.ts +1 -0
  158. package/src/types.ts +67 -0
  159. package/test/mock-local-storage.ts +17 -0
  160. package/test/test-utils.ts +23 -0
  161. package/test/wallet.json +209 -0
  162. package/tsconfig.build.json +25 -0
  163. package/tsconfig.build.tsbuildinfo +1 -0
  164. package/tsconfig.json +32 -0
package/lib/helpers.js ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.initializeTypeORM = exports.getDataSource = exports.documentHasType = void 0;
54
+ var typeorm_1 = require("./typeorm");
55
+ // import {SDKConfigsEntity} from './entities/data-store-configs.entity';
56
+ var logger_1 = require("./logger");
57
+ var network_entity_1 = require("./entities/network.entity");
58
+ var document_entity_1 = require("./entities/document/document.entity");
59
+ var document_type_entity_1 = require("./entities/document-type.entity");
60
+ var wallet_entity_1 = require("./entities/wallet.entity");
61
+ var migrations_1 = __importDefault(require("./migrations"));
62
+ function documentHasType(document, type) {
63
+ if (Array.isArray(document.type)) {
64
+ return document.type.includes(type);
65
+ }
66
+ return document.type === type;
67
+ }
68
+ exports.documentHasType = documentHasType;
69
+ function getDataSource(options) {
70
+ var dataSource = new typeorm_1.DataSource(__assign({ type: options.dbType || 'sqlite', database: options.databasePath, entities: [wallet_entity_1.WalletEntity, network_entity_1.NetworkEntity, document_entity_1.DocumentEntity, document_type_entity_1.DocumentTypeEntity], synchronize: process.env.NODE_ENV === 'test', dropSchema: options.dropSchema, driver: options.driver, sqlJsConfig: options.sqlJsConfig, migrationsRun: process.env.NODE_ENV !== 'test', migrations: migrations_1.default }, (options.typeORMConfigs || {})));
71
+ return dataSource;
72
+ }
73
+ exports.getDataSource = getDataSource;
74
+ function initializeTypeORM(options) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var dataSource;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ dataSource = getDataSource(options);
81
+ return [4 /*yield*/, dataSource
82
+ .initialize()
83
+ .then(function () {
84
+ logger_1.logger.debug('Data Source initialized successfully');
85
+ })
86
+ .catch(function (err) {
87
+ logger_1.logger.error("Error during Data Source initialization: ".concat(err));
88
+ throw err;
89
+ })];
90
+ case 1:
91
+ _a.sent();
92
+ return [2 /*return*/, dataSource];
93
+ }
94
+ });
95
+ });
96
+ }
97
+ exports.initializeTypeORM = initializeTypeORM;
98
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AACrC,yEAAyE;AACzE,mCAAgC;AAEhC,4DAAwD;AACxD,uEAAmE;AACnE,wEAAmE;AACnE,0DAAsD;AACtD,4DAA6C;AAI7C,SAAgB,eAAe,CAAC,QAAa,EAAE,IAAY;IACzD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAChC,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KACrC;IAED,OAAO,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC;AAChC,CAAC;AAND,0CAMC;AAED,SAAgB,aAAa,CAAC,OAAyB;IACrD,IAAM,UAAU,GAAG,IAAI,oBAAU,YAC/B,IAAI,EAAG,OAAO,CAAC,MAAc,IAAI,QAAQ,EACzC,QAAQ,EAAE,OAAO,CAAC,YAAY,EAC9B,QAAQ,EAAE,CAAC,4BAAY,EAAE,8BAAa,EAAE,gCAAc,EAAE,yCAAkB,CAAC,EAC3E,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAC5C,UAAU,EAAE,OAAO,CAAC,UAAU,EAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAC9C,UAAU,EAAE,oBAAiB,IAC1B,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC,EACjC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC;AAfD,sCAeC;AAED,SAAsB,iBAAiB,CAAC,OAAyB;;;;;;oBACzD,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;oBAE1C,qBAAM,UAAU;6BACb,UAAU,EAAE;6BACZ,IAAI,CAAC;4BACJ,eAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;wBACvD,CAAC,CAAC;6BACD,KAAK,CAAC,UAAA,GAAG;4BACR,eAAM,CAAC,KAAK,CAAC,mDAA4C,GAAG,CAAE,CAAC,CAAC;4BAChE,MAAM,GAAG,CAAC;wBACZ,CAAC,CAAC,EAAA;;oBARJ,SAQI,CAAC;oBAEL,sBAAO,UAAU,EAAC;;;;CACnB;AAdD,8CAcC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { DataStore, DataStoreConfigs } from './types';
2
+ import { getV1LocalStorage } from './migration/migration1/v1-data-store';
3
+ export declare const getLocalStorage: typeof getV1LocalStorage;
4
+ export declare function updateNetwork({ dataStore, networkId, }: {
5
+ dataStore: DataStore;
6
+ networkId: string;
7
+ }): Promise<void>;
8
+ export declare function createDataStore(_options: DataStoreConfigs): Promise<DataStore>;
9
+ /**
10
+ * Close the data store connection with the database
11
+ *
12
+ */
13
+ export declare function closeDataStore(dataStore: DataStore): Promise<void>;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAOpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,eAAO,MAAM,eAAe,0BAAoB,CAAC;AAEjD,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,SAAS,GACV,EAAE;IACD,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAShB;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,SAAS,CAAC,CAyCpB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,SAAS,EAAE,SAAS,iBAExD"}
package/lib/index.js ADDED
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.closeDataStore = exports.createDataStore = exports.updateNetwork = exports.getLocalStorage = void 0;
54
+ var helpers_1 = require("./helpers");
55
+ var migration_1 = require("./migration");
56
+ var configs_1 = require("./configs");
57
+ var logger_1 = require("./logger");
58
+ var assert_1 = __importDefault(require("assert"));
59
+ var wallet_entity_1 = require("./entities/wallet.entity");
60
+ var v1_data_store_1 = require("./migration/migration1/v1-data-store");
61
+ var document_1 = require("./entities/document");
62
+ exports.getLocalStorage = v1_data_store_1.getV1LocalStorage;
63
+ function updateNetwork(_a) {
64
+ var dataStore = _a.dataStore, networkId = _a.networkId;
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ var network;
67
+ return __generator(this, function (_b) {
68
+ switch (_b.label) {
69
+ case 0:
70
+ network = dataStore.networks.find(function (item) { return item.id === networkId; });
71
+ (0, assert_1.default)(!!network, "Invalid network id ".concat(networkId));
72
+ dataStore.network = network;
73
+ dataStore.networkId = networkId;
74
+ return [4 /*yield*/, (0, wallet_entity_1.updateWallet)({ dataStore: dataStore })];
75
+ case 1:
76
+ _b.sent();
77
+ return [2 /*return*/];
78
+ }
79
+ });
80
+ });
81
+ }
82
+ exports.updateNetwork = updateNetwork;
83
+ function createDataStore(_options) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var options, dataSource, dataStore, wallet;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ options = __assign(__assign({}, configs_1.DEFAULT_CONFIGS), _options);
90
+ if (!options.defaultNetwork) {
91
+ options.defaultNetwork = options.networks[0].id;
92
+ }
93
+ return [4 /*yield*/, (0, helpers_1.initializeTypeORM)(options)];
94
+ case 1:
95
+ dataSource = _a.sent();
96
+ dataStore = {
97
+ db: dataSource,
98
+ networkId: options.defaultNetwork,
99
+ network: options.networks.find(function (item) { return item.id === options.defaultNetwork; }),
100
+ testNetworkId: options.testNetworkId,
101
+ mainNetworkId: options.mainNetworkId,
102
+ version: null,
103
+ networks: options.networks,
104
+ resolveDocumentNetwork: options.documentNetworkResolver,
105
+ setNetwork: function (networkId) {
106
+ logger_1.logger.debug("Setting network to ".concat(networkId));
107
+ return updateNetwork({ dataStore: dataStore, networkId: networkId });
108
+ },
109
+ };
110
+ logger_1.logger.debug('Data store initialized');
111
+ return [4 /*yield*/, (0, migration_1.migrate)({ dataStore: dataStore })];
112
+ case 2:
113
+ _a.sent();
114
+ return [4 /*yield*/, (0, wallet_entity_1.getWallet)({ dataStore: dataStore })];
115
+ case 3:
116
+ wallet = _a.sent();
117
+ dataStore.networkId = wallet.networkId;
118
+ dataStore.network = options.networks.find(function (item) { return item.id === wallet.networkId; });
119
+ (0, document_1.getAllDocuments)({ dataStore: dataStore }).then(function (documents) {
120
+ logger_1.logger.debug("Wallet loaded with ".concat(documents.length, " documents"));
121
+ });
122
+ return [2 /*return*/, dataStore];
123
+ }
124
+ });
125
+ });
126
+ }
127
+ exports.createDataStore = createDataStore;
128
+ /**
129
+ * Close the data store connection with the database
130
+ *
131
+ */
132
+ function closeDataStore(dataStore) {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ return __generator(this, function (_a) {
135
+ switch (_a.label) {
136
+ case 0: return [4 /*yield*/, dataStore.db.destroy()];
137
+ case 1:
138
+ _a.sent();
139
+ return [2 /*return*/];
140
+ }
141
+ });
142
+ });
143
+ }
144
+ exports.closeDataStore = closeDataStore;
145
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,14 @@
1
+ export declare let logger: {
2
+ log: (message: string) => void;
3
+ error: (message: string) => void;
4
+ debug: (message: string) => void;
5
+ warn: (message: string) => void;
6
+ };
7
+ export declare function setLogger(impl: any): void;
8
+ export declare const createLogger: (prefix: string) => {
9
+ log: (message: string) => void;
10
+ error: (message: string) => void;
11
+ debug: (message: string) => void;
12
+ warn: (message: string) => void;
13
+ };
14
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAeA,eAAO,IAAI,MAAM;mBAdA,MAAM;qBAGJ,MAAM;qBAGN,MAAM;oBAGP,MAAM;CAKY,CAAC;AAErC,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,QAElC;AAED,eAAO,MAAM,YAAY,WAAY,MAAM;mBAExB,MAAM;qBAGJ,MAAM;qBAGN,MAAM;oBAGP,MAAM;CAIzB,CAAC"}
package/lib/logger.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLogger = exports.setLogger = exports.logger = void 0;
4
+ var ConsoleTransport = {
5
+ log: function (message) {
6
+ console.log(message);
7
+ },
8
+ error: function (message) {
9
+ console.error(message);
10
+ },
11
+ debug: function (message) {
12
+ console.debug(message);
13
+ },
14
+ warn: function (message) {
15
+ console.warn(message);
16
+ },
17
+ };
18
+ exports.logger = ConsoleTransport;
19
+ function setLogger(impl) {
20
+ exports.logger = impl;
21
+ }
22
+ exports.setLogger = setLogger;
23
+ var createLogger = function (prefix) {
24
+ return {
25
+ log: function (message) {
26
+ exports.logger.log("[".concat(prefix, "] ").concat(message));
27
+ },
28
+ error: function (message) {
29
+ exports.logger.error("[".concat(prefix, "] ").concat(message));
30
+ },
31
+ debug: function (message) {
32
+ exports.logger.debug("[".concat(prefix, "] ").concat(message));
33
+ },
34
+ warn: function (message) {
35
+ exports.logger.warn("[".concat(prefix, "] ").concat(message));
36
+ },
37
+ };
38
+ };
39
+ exports.createLogger = createLogger;
40
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,IAAM,gBAAgB,GAAG;IACvB,GAAG,EAAE,UAAC,OAAe;QACnB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IACD,KAAK,EAAE,UAAC,OAAe;QACrB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,KAAK,EAAE,UAAC,OAAe;QACrB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,EAAE,UAAC,OAAe;QACpB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACF,CAAC;AAES,QAAA,MAAM,GAAG,gBAAgB,CAAC;AAErC,SAAgB,SAAS,CAAC,IAAS;IACjC,cAAM,GAAG,IAAI,CAAC;AAChB,CAAC;AAFD,8BAEC;AAEM,IAAM,YAAY,GAAG,UAAC,MAAc;IACzC,OAAO;QACL,GAAG,EAAE,UAAC,OAAe;YACnB,cAAM,CAAC,GAAG,CAAC,WAAI,MAAM,eAAK,OAAO,CAAE,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,EAAE,UAAC,OAAe;YACrB,cAAM,CAAC,KAAK,CAAC,WAAI,MAAM,eAAK,OAAO,CAAE,CAAC,CAAC;QACzC,CAAC;QACD,KAAK,EAAE,UAAC,OAAe;YACrB,cAAM,CAAC,KAAK,CAAC,WAAI,MAAM,eAAK,OAAO,CAAE,CAAC,CAAC;QACzC,CAAC;QACD,IAAI,EAAE,UAAC,OAAe;YACpB,cAAM,CAAC,IAAI,CAAC,WAAI,MAAM,eAAK,OAAO,CAAE,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB"}
@@ -0,0 +1,3 @@
1
+ import { DataSource } from '../typeorm';
2
+ export declare function bootstrapTables(dataSource: DataSource): void;
3
+ //# sourceMappingURL=bootstrap-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-tables.d.ts","sourceRoot":"","sources":["../../src/migration/bootstrap-tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAEtC,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,QAErD"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bootstrapTables = void 0;
4
+ function bootstrapTables(dataSource) {
5
+ // will be generated from typeorm once the schema is defined
6
+ }
7
+ exports.bootstrapTables = bootstrapTables;
8
+ //# sourceMappingURL=bootstrap-tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-tables.js","sourceRoot":"","sources":["../../src/migration/bootstrap-tables.ts"],"names":[],"mappings":";;;AAEA,SAAgB,eAAe,CAAC,UAAsB;IACpD,4DAA4D;AAC9D,CAAC;AAFD,0CAEC"}
@@ -0,0 +1,8 @@
1
+ import { ContextProps } from '../types';
2
+ export declare const CURRENT_DATA_STORE_VERSION = "v2";
3
+ export type MigrationResult = {
4
+ migrated: boolean;
5
+ version: string;
6
+ };
7
+ export declare function migrate({ dataStore }: ContextProps): Promise<void>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migration/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAKtC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAOF,wBAAsB,OAAO,CAAC,EAAC,SAAS,EAAC,EAAE,YAAY,iBAkCtD"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.migrate = exports.CURRENT_DATA_STORE_VERSION = void 0;
51
+ var migration1_1 = require("./migration1");
52
+ var logger_1 = require("../logger");
53
+ var wallet_entity_1 = require("../entities/wallet.entity");
54
+ var bootstrap_tables_1 = require("./bootstrap-tables");
55
+ exports.CURRENT_DATA_STORE_VERSION = 'v2';
56
+ var migrations = [
57
+ migration1_1.migration1,
58
+ // add new migrations here
59
+ ];
60
+ function migrate(_a) {
61
+ var dataStore = _a.dataStore;
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var existingConfigs, isV1DataStore, migrations_1, migrations_1_1, migrate_1, results, e_1_1;
64
+ var e_1, _b;
65
+ return __generator(this, function (_c) {
66
+ switch (_c.label) {
67
+ case 0:
68
+ // bootstrap v2 data
69
+ return [4 /*yield*/, (0, bootstrap_tables_1.bootstrapTables)(dataStore.db)];
70
+ case 1:
71
+ // bootstrap v2 data
72
+ _c.sent();
73
+ return [4 /*yield*/, (0, wallet_entity_1.getWallet)({ dataStore: dataStore })];
74
+ case 2:
75
+ existingConfigs = _c.sent();
76
+ if (!!existingConfigs) return [3 /*break*/, 5];
77
+ logger_1.logger.debug('Wallet not found in the database, creating a new wallet...');
78
+ return [4 /*yield*/, (0, migration1_1.isRunningOnV1DataStore)({ dataStore: dataStore })];
79
+ case 3:
80
+ isV1DataStore = _c.sent();
81
+ logger_1.logger.debug("Is v1 data store: ".concat(isV1DataStore));
82
+ dataStore.version = isV1DataStore ? 'v1' : exports.CURRENT_DATA_STORE_VERSION;
83
+ return [4 /*yield*/, (0, wallet_entity_1.createWallet)({
84
+ dataStore: dataStore,
85
+ })];
86
+ case 4:
87
+ _c.sent();
88
+ logger_1.logger.debug('universal wallet created');
89
+ _c.label = 5;
90
+ case 5:
91
+ _c.trys.push([5, 12, 13, 14]);
92
+ migrations_1 = __values(migrations), migrations_1_1 = migrations_1.next();
93
+ _c.label = 6;
94
+ case 6:
95
+ if (!!migrations_1_1.done) return [3 /*break*/, 11];
96
+ migrate_1 = migrations_1_1.value;
97
+ return [4 /*yield*/, migrate_1({ dataStore: dataStore })];
98
+ case 7:
99
+ results = _c.sent();
100
+ if (!results.migrated) return [3 /*break*/, 9];
101
+ logger_1.logger.debug('Migration completed');
102
+ dataStore.version = results.version;
103
+ return [4 /*yield*/, (0, wallet_entity_1.updateWallet)({ dataStore: dataStore })];
104
+ case 8:
105
+ _c.sent();
106
+ return [3 /*break*/, 10];
107
+ case 9:
108
+ logger_1.logger.debug('Migration not required');
109
+ _c.label = 10;
110
+ case 10:
111
+ migrations_1_1 = migrations_1.next();
112
+ return [3 /*break*/, 6];
113
+ case 11: return [3 /*break*/, 14];
114
+ case 12:
115
+ e_1_1 = _c.sent();
116
+ e_1 = { error: e_1_1 };
117
+ return [3 /*break*/, 14];
118
+ case 13:
119
+ try {
120
+ if (migrations_1_1 && !migrations_1_1.done && (_b = migrations_1.return)) _b.call(migrations_1);
121
+ }
122
+ finally { if (e_1) throw e_1.error; }
123
+ return [7 /*endfinally*/];
124
+ case 14:
125
+ logger_1.logger.debug("DataStore version: ".concat(dataStore.version));
126
+ return [2 /*return*/];
127
+ }
128
+ });
129
+ });
130
+ }
131
+ exports.migrate = migrate;
132
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migration/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAEhE,oCAAiC;AACjC,2DAAgF;AAChF,uDAAmD;AAEtC,QAAA,0BAA0B,GAAG,IAAI,CAAC;AAO/C,IAAM,UAAU,GAAG;IACjB,uBAAU;IACV,0BAA0B;CAC3B,CAAC;AAEF,SAAsB,OAAO,CAAC,EAAyB;QAAxB,SAAS,eAAA;;;;;;;gBACtC,oBAAoB;gBACpB,qBAAM,IAAA,kCAAe,EAAC,SAAS,CAAC,EAAE,CAAC,EAAA;;oBADnC,oBAAoB;oBACpB,SAAmC,CAAC;oBAGd,qBAAM,IAAA,yBAAS,EAAC,EAAC,SAAS,WAAA,EAAC,CAAC,EAAA;;oBAA9C,eAAe,GAAG,SAA4B;yBAK9C,CAAC,eAAe,EAAhB,wBAAgB;oBAClB,eAAM,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAC;oBACrD,qBAAM,IAAA,mCAAsB,EAAC,EAAC,SAAS,WAAA,EAAC,CAAC,EAAA;;oBAAzD,aAAa,GAAG,SAAyC;oBAC/D,eAAM,CAAC,KAAK,CAAC,4BAAqB,aAAa,CAAE,CAAC,CAAC;oBACnD,SAAS,CAAC,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,kCAA0B,CAAC;oBACtE,qBAAM,IAAA,4BAAY,EAAC;4BACjB,SAAS,WAAA;yBACV,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBACH,eAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;;;;oBAGrB,eAAA,SAAA,UAAU,CAAA;;;;oBAA3B;oBACa,qBAAM,SAAO,CAAC,EAAC,SAAS,WAAA,EAAC,CAAC,EAAA;;oBAApC,OAAO,GAAG,SAA0B;yBAEtC,OAAO,CAAC,QAAQ,EAAhB,wBAAgB;oBAClB,eAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;oBACpC,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;oBACpC,qBAAM,IAAA,4BAAY,EAAC,EAAC,SAAS,WAAA,EAAC,CAAC,EAAA;;oBAA/B,SAA+B,CAAC;;;oBAEhC,eAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;;;;;;;;;;;;;;;;;oBAI3C,eAAM,CAAC,KAAK,CAAC,6BAAsB,SAAS,CAAC,OAAO,CAAE,CAAC,CAAC;;;;;CACzD;AAlCD,0BAkCC"}
@@ -0,0 +1,16 @@
1
+ import { MigrationResult } from '../index';
2
+ import { ContextProps } from '../../types';
3
+ /**
4
+ * Migrate from v1 to v2
5
+ *
6
+ * v1 data store is stored in local storage
7
+ * v2 will store on typeorm
8
+ *
9
+ */
10
+ export declare function migration1({ dataStore, }: ContextProps): Promise<MigrationResult>;
11
+ /**
12
+ * Check if a migration from v2 is required
13
+ * Once v2 is migrated, the local storage entry will be removed
14
+ */
15
+ export declare function isRunningOnV1DataStore({ dataStore, }: ContextProps): Promise<boolean>;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migration/migration1/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AACzC,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzC;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,GACV,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAmBzC;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,SAAS,GACV,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAqBjC"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.isRunningOnV1DataStore = exports.migration1 = void 0;
40
+ var v1_data_store_1 = require("./v1-data-store");
41
+ var logger_1 = require("../../logger");
42
+ var migrate_v1_data_1 = require("./migrate-v1-data");
43
+ /**
44
+ * Migrate from v1 to v2
45
+ *
46
+ * v1 data store is stored in local storage
47
+ * v2 will store on typeorm
48
+ *
49
+ */
50
+ function migration1(_a) {
51
+ var dataStore = _a.dataStore;
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ return __generator(this, function (_b) {
54
+ switch (_b.label) {
55
+ case 0:
56
+ logger_1.logger.debug('Checking if v1 migration is required');
57
+ if (dataStore.version !== 'v1') {
58
+ logger_1.logger.debug('v1 data migration NOT required');
59
+ return [2 /*return*/, {
60
+ migrated: false,
61
+ version: dataStore.version,
62
+ }];
63
+ }
64
+ logger_1.logger.debug('v1 data Migration required');
65
+ return [4 /*yield*/, (0, migrate_v1_data_1.migrateV1Data)({ dataStore: dataStore })];
66
+ case 1:
67
+ _b.sent();
68
+ return [2 /*return*/, {
69
+ migrated: true,
70
+ version: 'v2',
71
+ }];
72
+ }
73
+ });
74
+ });
75
+ }
76
+ exports.migration1 = migration1;
77
+ /**
78
+ * Check if a migration from v2 is required
79
+ * Once v2 is migrated, the local storage entry will be removed
80
+ */
81
+ function isRunningOnV1DataStore(_a) {
82
+ var dataStore = _a.dataStore;
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var v1LocalStorage, documents;
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
87
+ case 0:
88
+ // If sdk version is defined, can skip migration
89
+ if (dataStore.version) {
90
+ return [2 /*return*/, false];
91
+ }
92
+ v1LocalStorage = (0, v1_data_store_1.getV1LocalStorage)();
93
+ if (!v1LocalStorage) {
94
+ logger_1.logger.debug('v1 local storage not found');
95
+ return [2 /*return*/, false];
96
+ }
97
+ return [4 /*yield*/, (0, v1_data_store_1.getWalletDocuments)()];
98
+ case 1:
99
+ documents = _b.sent();
100
+ if (documents.length === 0) {
101
+ logger_1.logger.debug('no documents found on v1 data store');
102
+ return [2 /*return*/, false];
103
+ }
104
+ return [2 /*return*/, true];
105
+ }
106
+ });
107
+ });
108
+ }
109
+ exports.isRunningOnV1DataStore = isRunningOnV1DataStore;
110
+ //# sourceMappingURL=index.js.map