@docknetwork/wallet-sdk-data-store-web 0.4.19

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 (87) hide show
  1. package/jest.config.ts +20 -0
  2. package/lib/entities/document/create-document.d.ts +12 -0
  3. package/lib/entities/document/create-document.d.ts.map +1 -0
  4. package/lib/entities/document/create-document.js +150 -0
  5. package/lib/entities/document/create-document.js.map +1 -0
  6. package/lib/entities/document/document.entity.d.ts +8 -0
  7. package/lib/entities/document/document.entity.d.ts.map +1 -0
  8. package/lib/entities/document/document.entity.js +3 -0
  9. package/lib/entities/document/document.entity.js.map +1 -0
  10. package/lib/entities/document/get-all-documents.d.ts +11 -0
  11. package/lib/entities/document/get-all-documents.d.ts.map +1 -0
  12. package/lib/entities/document/get-all-documents.js +73 -0
  13. package/lib/entities/document/get-all-documents.js.map +1 -0
  14. package/lib/entities/document/get-document-by-id.d.ts +13 -0
  15. package/lib/entities/document/get-document-by-id.d.ts.map +1 -0
  16. package/lib/entities/document/get-document-by-id.js +76 -0
  17. package/lib/entities/document/get-document-by-id.js.map +1 -0
  18. package/lib/entities/document/get-document-correlations.d.ts +10 -0
  19. package/lib/entities/document/get-document-correlations.d.ts.map +1 -0
  20. package/lib/entities/document/get-document-correlations.js +62 -0
  21. package/lib/entities/document/get-document-correlations.js.map +1 -0
  22. package/lib/entities/document/get-documents-by-type.d.ts +10 -0
  23. package/lib/entities/document/get-documents-by-type.d.ts.map +1 -0
  24. package/lib/entities/document/get-documents-by-type.js +61 -0
  25. package/lib/entities/document/get-documents-by-type.js.map +1 -0
  26. package/lib/entities/document/helpers.d.ts +18 -0
  27. package/lib/entities/document/helpers.d.ts.map +1 -0
  28. package/lib/entities/document/helpers.js +81 -0
  29. package/lib/entities/document/helpers.js.map +1 -0
  30. package/lib/entities/document/index.d.ts +10 -0
  31. package/lib/entities/document/index.d.ts.map +1 -0
  32. package/lib/entities/document/index.js +26 -0
  33. package/lib/entities/document/index.js.map +1 -0
  34. package/lib/entities/document/remove-document.d.ts +16 -0
  35. package/lib/entities/document/remove-document.d.ts.map +1 -0
  36. package/lib/entities/document/remove-document.js +89 -0
  37. package/lib/entities/document/remove-document.js.map +1 -0
  38. package/lib/entities/document/update-document.d.ts +11 -0
  39. package/lib/entities/document/update-document.d.ts.map +1 -0
  40. package/lib/entities/document/update-document.js +78 -0
  41. package/lib/entities/document/update-document.js.map +1 -0
  42. package/lib/entities/log.entity.d.ts +13 -0
  43. package/lib/entities/log.entity.d.ts.map +1 -0
  44. package/lib/entities/log.entity.js +91 -0
  45. package/lib/entities/log.entity.js.map +1 -0
  46. package/lib/entities/network.entity.d.ts +6 -0
  47. package/lib/entities/network.entity.d.ts.map +1 -0
  48. package/lib/entities/network.entity.js +3 -0
  49. package/lib/entities/network.entity.js.map +1 -0
  50. package/lib/entities/wallet.entity.d.ts +10 -0
  51. package/lib/entities/wallet.entity.d.ts.map +1 -0
  52. package/lib/entities/wallet.entity.js +77 -0
  53. package/lib/entities/wallet.entity.js.map +1 -0
  54. package/lib/index.d.ts +3 -0
  55. package/lib/index.d.ts.map +1 -0
  56. package/lib/index.js +185 -0
  57. package/lib/index.js.map +1 -0
  58. package/lib/localStorageJSON.d.ts +7 -0
  59. package/lib/localStorageJSON.d.ts.map +1 -0
  60. package/lib/localStorageJSON.js +80 -0
  61. package/lib/localStorageJSON.js.map +1 -0
  62. package/package.json +32 -0
  63. package/scripts/publish.sh +3 -0
  64. package/src/__tests__/index.test.ts +56 -0
  65. package/src/__tests__/v1-data-store.test.ts +24 -0
  66. package/src/entities/document/create-document.ts +82 -0
  67. package/src/entities/document/decument.entity.test.ts +135 -0
  68. package/src/entities/document/document.entity.ts +7 -0
  69. package/src/entities/document/get-all-documents.ts +42 -0
  70. package/src/entities/document/get-document-by-id.ts +31 -0
  71. package/src/entities/document/get-document-correlations.ts +22 -0
  72. package/src/entities/document/get-documents-by-type.ts +21 -0
  73. package/src/entities/document/helpers.ts +50 -0
  74. package/src/entities/document/index.ts +9 -0
  75. package/src/entities/document/remove-document.ts +43 -0
  76. package/src/entities/document/update-document.ts +36 -0
  77. package/src/entities/log.entity.ts +26 -0
  78. package/src/entities/network.entity.ts +5 -0
  79. package/src/entities/wallet.entity.ts +29 -0
  80. package/src/index.ts +134 -0
  81. package/src/localStorageJSON.ts +24 -0
  82. package/test/mock-local-storage.ts +17 -0
  83. package/test/test-utils.ts +23 -0
  84. package/test/wallet.json +209 -0
  85. package/tsconfig.build.json +25 -0
  86. package/tsconfig.build.tsbuildinfo +1 -0
  87. package/tsconfig.json +32 -0
package/lib/index.js ADDED
@@ -0,0 +1,185 @@
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.createDataStore = void 0;
40
+ var wallet_entity_1 = require("./entities/wallet.entity");
41
+ var document_1 = require("./entities/document");
42
+ var index_1 = require("@docknetwork/wallet-sdk-data-store/lib/index");
43
+ var logger_1 = require("@docknetwork/wallet-sdk-data-store/lib/logger");
44
+ // setLocalStorage(global.localStorage);
45
+ function createDataStore(configs) {
46
+ return __awaiter(this, void 0, void 0, function () {
47
+ var dataSource, dataStore, wallet;
48
+ var _this = this;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ dataSource = {
53
+ destroy: function () {
54
+ return __awaiter(this, void 0, void 0, function () {
55
+ return __generator(this, function (_a) {
56
+ return [2 /*return*/];
57
+ });
58
+ });
59
+ },
60
+ initialize: function () {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ return __generator(this, function (_a) {
63
+ return [2 /*return*/];
64
+ });
65
+ });
66
+ }
67
+ };
68
+ return [4 /*yield*/, (0, index_1.createDataStore)({
69
+ configs: configs,
70
+ dataSource: dataSource,
71
+ documentStore: {
72
+ addDocument: function (json, options) { return __awaiter(_this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ return [2 /*return*/, (0, document_1.createDocument)({
75
+ dataStore: dataStore,
76
+ json: json,
77
+ options: options,
78
+ })];
79
+ });
80
+ }); },
81
+ removeDocument: function (id, options) { return __awaiter(_this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ return [2 /*return*/, (0, document_1.removeDocument)({
84
+ dataStore: dataStore,
85
+ id: id,
86
+ options: options,
87
+ })];
88
+ });
89
+ }); },
90
+ updateDocument: function (document, options) { return __awaiter(_this, void 0, void 0, function () {
91
+ return __generator(this, function (_a) {
92
+ return [2 /*return*/, (0, document_1.updateDocument)({
93
+ dataStore: dataStore,
94
+ document: document,
95
+ options: options,
96
+ })];
97
+ });
98
+ }); },
99
+ getDocumentById: function (id) { return __awaiter(_this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ return [2 /*return*/, (0, document_1.getDocumentById)({
102
+ dataStore: dataStore,
103
+ id: id,
104
+ })];
105
+ });
106
+ }); },
107
+ getDocumentsByType: function (type) { return __awaiter(_this, void 0, void 0, function () {
108
+ return __generator(this, function (_a) {
109
+ return [2 /*return*/, (0, document_1.getDocumentsByType)({
110
+ dataStore: dataStore,
111
+ type: type,
112
+ })];
113
+ });
114
+ }); },
115
+ getDocumentsById: function (idList) { return __awaiter(_this, void 0, void 0, function () {
116
+ return __generator(this, function (_a) {
117
+ return [2 /*return*/, (0, document_1.getDocumentsById)({
118
+ dataStore: dataStore,
119
+ idList: idList,
120
+ })];
121
+ });
122
+ }); },
123
+ getAllDocuments: function (allNetworks) { return __awaiter(_this, void 0, void 0, function () {
124
+ return __generator(this, function (_a) {
125
+ return [2 /*return*/, (0, document_1.getAllDocuments)({
126
+ allNetworks: allNetworks,
127
+ dataStore: dataStore,
128
+ })];
129
+ });
130
+ }); },
131
+ removeAllDocuments: function () { return __awaiter(_this, void 0, void 0, function () {
132
+ return __generator(this, function (_a) {
133
+ return [2 /*return*/, (0, document_1.removeAllDocuments)({
134
+ dataStore: dataStore,
135
+ })];
136
+ });
137
+ }); },
138
+ getDocumentCorrelations: function (documentId) { return __awaiter(_this, void 0, void 0, function () {
139
+ return __generator(this, function (_a) {
140
+ return [2 /*return*/, (0, document_1.getDocumentCorrelations)({
141
+ dataStore: dataStore,
142
+ documentId: documentId,
143
+ })];
144
+ });
145
+ }); },
146
+ },
147
+ localStorageImpl: global.localStorage,
148
+ walletStore: {
149
+ getWallet: function () { return __awaiter(_this, void 0, void 0, function () {
150
+ return __generator(this, function (_a) {
151
+ return [2 /*return*/, (0, wallet_entity_1.getWallet)({ dataStore: dataStore })];
152
+ });
153
+ }); },
154
+ updateWallet: function () { return __awaiter(_this, void 0, void 0, function () {
155
+ return __generator(this, function (_a) {
156
+ return [2 /*return*/, (0, wallet_entity_1.updateWallet)({ dataStore: dataStore })];
157
+ });
158
+ }); },
159
+ },
160
+ })];
161
+ case 1:
162
+ dataStore = _a.sent();
163
+ return [4 /*yield*/, dataStore.wallet.getWallet()];
164
+ case 2:
165
+ wallet = _a.sent();
166
+ if (!!wallet) return [3 /*break*/, 4];
167
+ return [4 /*yield*/, (0, wallet_entity_1.createWallet)({
168
+ dataStore: dataStore,
169
+ })];
170
+ case 3:
171
+ wallet = _a.sent();
172
+ _a.label = 4;
173
+ case 4:
174
+ dataStore.networkId = wallet.networkId;
175
+ dataStore.network = dataStore.networks.find(function (item) { return item.id === wallet.networkId; });
176
+ dataStore.documents.getAllDocuments().then(function (documents) {
177
+ logger_1.logger.debug("Wallet loaded with ".concat(documents.length, " documents"));
178
+ });
179
+ return [2 /*return*/, dataStore];
180
+ }
181
+ });
182
+ });
183
+ }
184
+ exports.createDataStore = createDataStore;
185
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAM,eAAY,CAAC,CAAC;oBACnE,CAAC,CAAC,CAAC;oBAGH,sBAAO,SAAS,EAAC;;;;CAClB;AAzGD,0CAyGC"}
@@ -0,0 +1,7 @@
1
+ export declare const setLocalStorageImpl: (impl: any) => void;
2
+ export declare const localStorageJSON: {
3
+ getItem: (key: string) => Promise<any>;
4
+ setItem: (key: string, value: any) => Promise<any>;
5
+ removeItem: (key: string) => any;
6
+ };
7
+ //# sourceMappingURL=localStorageJSON.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localStorageJSON.d.ts","sourceRoot":"","sources":["../src/localStorageJSON.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,SAAU,GAAG,SAE5C,CAAC;AAEF,eAAO,MAAM,gBAAgB;mBACN,MAAM;mBAQN,MAAM,SAAS,GAAG;sBAKrB,MAAM;CAGzB,CAAC"}
@@ -0,0 +1,80 @@
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.localStorageJSON = exports.setLocalStorageImpl = void 0;
40
+ var _localStorage;
41
+ var setLocalStorageImpl = function (impl) {
42
+ _localStorage = impl;
43
+ };
44
+ exports.setLocalStorageImpl = setLocalStorageImpl;
45
+ exports.localStorageJSON = {
46
+ getItem: function (key) { return __awaiter(void 0, void 0, void 0, function () {
47
+ var value;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4 /*yield*/, _localStorage.getItem(key)];
51
+ case 1:
52
+ value = _a.sent();
53
+ try {
54
+ return [2 /*return*/, JSON.parse(value)];
55
+ }
56
+ catch (e) {
57
+ return [2 /*return*/, value];
58
+ }
59
+ return [2 /*return*/];
60
+ }
61
+ });
62
+ }); },
63
+ setItem: function (key, value) { return __awaiter(void 0, void 0, void 0, function () {
64
+ var serializedValue;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ serializedValue = typeof value === "string" ? value : JSON.stringify(value);
69
+ return [4 /*yield*/, _localStorage.setItem(key, serializedValue)];
70
+ case 1:
71
+ _a.sent();
72
+ return [2 /*return*/, value];
73
+ }
74
+ });
75
+ }); },
76
+ removeItem: function (key) {
77
+ return _localStorage.removeItem(key);
78
+ },
79
+ };
80
+ //# sourceMappingURL=localStorageJSON.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localStorageJSON.js","sourceRoot":"","sources":["../src/localStorageJSON.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,aAAa,CAAC;AAEX,IAAM,mBAAmB,GAAG,UAAC,IAAS;IAC3C,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B;AAEW,QAAA,gBAAgB,GAAG;IAC9B,OAAO,EAAE,UAAO,GAAW;;;;wBACX,qBAAM,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;oBAAxC,KAAK,GAAG,SAAgC;oBAC9C,IAAI;wBACF,sBAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAC;qBAC1B;oBAAC,OAAO,CAAC,EAAE;wBACV,sBAAO,KAAK,EAAC;qBACd;;;;SACF;IACD,OAAO,EAAE,UAAO,GAAW,EAAE,KAAU;;;;;oBAC/B,eAAe,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;oBAClF,qBAAM,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,EAAA;;oBAAjD,SAAiD,CAAC;oBAClD,sBAAO,KAAK,EAAC;;;SACd;IACD,UAAU,EAAE,UAAC,GAAW;QACtB,OAAO,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;CACF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@docknetwork/wallet-sdk-data-store-web",
3
+ "version": "0.4.19",
4
+ "license": "https://github.com/docknetwork/react-native-sdk/LICENSE",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/docknetwork/react-native-sdk",
10
+ "directory": "packages/data-store"
11
+ },
12
+ "scripts": {
13
+ "test": "jest",
14
+ "build": "rm -rf lib && rm -rf tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json && node ../../scripts/fix-build-imports.js ./lib"
15
+ },
16
+ "peerDependencies": {
17
+ "typeorm": "^0.3.15"
18
+ },
19
+ "dependencies": {
20
+ "@docknetwork/wallet-sdk-wasm": "^0.4.19",
21
+ "uuid": "^8.3.2"
22
+ },
23
+ "devDependencies": {
24
+ "jest": "29.1.0",
25
+ "ts-jest": "29.1.0",
26
+ "ts-node": "^10.9.1",
27
+ "typescript": "^5.0.4",
28
+ "typeorm": "^0.3.15",
29
+ "sqlite3": "^5.0.2",
30
+ "reflect-metadata": "^0.1.13"
31
+ }
32
+ }
@@ -0,0 +1,3 @@
1
+ yarn build
2
+ npm publish --access public
3
+
@@ -0,0 +1,56 @@
1
+ import {
2
+ createTestDataStore,
3
+ createV1EmptyDataStore,
4
+ setupV1MockDataStore,
5
+ } from '../../test/test-utils';
6
+ import {getV1LocalStorage} from '../migration/migration1/v1-data-store';
7
+ import {CURRENT_DATA_STORE_VERSION} from '../migration';
8
+ import {DataStore} from '../types';
9
+ import {WalletEntity, getWallet} from '../entities/wallet.entity';
10
+ import {closeDataStore} from '../index';
11
+
12
+ describe('Data store', () => {
13
+ describe('v2-data-store migration', () => {
14
+ let dataStore: DataStore;
15
+
16
+ beforeAll(async () => {
17
+ await setupV1MockDataStore();
18
+ dataStore = await createTestDataStore();
19
+ });
20
+
21
+ it('should remove wallet json from local storage', async () => {
22
+ const jsonData = await getV1LocalStorage().getItem('wallet');
23
+ expect(jsonData).toBeUndefined();
24
+ });
25
+
26
+ it('should create DataStoreConfigs', async () => {
27
+ const configs = await getWallet({dataStore});
28
+ expect(configs).toBeDefined();
29
+ expect(configs.networkId).toBe('mainnet');
30
+ expect(configs.version).toBe(CURRENT_DATA_STORE_VERSION);
31
+ });
32
+
33
+ afterAll(() => {
34
+ closeDataStore(dataStore);
35
+ });
36
+ });
37
+
38
+ describe('empty wallet migration', () => {
39
+ let dataStore: DataStore;
40
+
41
+ beforeAll(async () => {
42
+ await createV1EmptyDataStore();
43
+ dataStore = await createTestDataStore();
44
+ });
45
+
46
+ it('should create SDKConfigs', async () => {
47
+ const configs = await getWallet({dataStore});
48
+ expect(configs.networkId).toBe('mainnet');
49
+ expect(configs.version).toBe(CURRENT_DATA_STORE_VERSION);
50
+ });
51
+
52
+ afterAll(() => {
53
+ closeDataStore(dataStore);
54
+ });
55
+ });
56
+ });
@@ -0,0 +1,24 @@
1
+ import {setupV1MockDataStore} from '../../test/test-utils';
2
+ import {
3
+ getV1LocalStorage,
4
+ getWalletDocuments,
5
+ } from '../migration/migration1/v1-data-store';
6
+ import _walletJSON from '../../test/wallet.json';
7
+
8
+ describe('v2-data-store', () => {
9
+ beforeAll(async () => {
10
+ await setupV1MockDataStore();
11
+ });
12
+
13
+ it('should have access to v2 localStorage', async () => {
14
+ const jsonData = await getV1LocalStorage().getItem('wallet');
15
+ expect(jsonData).toBeDefined();
16
+ const wallet = JSON.parse(jsonData as string);
17
+ expect(wallet).toStrictEqual(_walletJSON);
18
+ });
19
+
20
+ it('should be able to fetch v2 documents', async () => {
21
+ const documents = await getWalletDocuments();
22
+ expect(documents.length).toBeGreaterThan(1);
23
+ });
24
+ });
@@ -0,0 +1,82 @@
1
+ import {
2
+ ContextProps,
3
+ DataStoreEvents,
4
+ WalletDocument,
5
+ } from '@docknetwork/wallet-sdk-data-store/src/types';
6
+ import {v4 as uuid} from 'uuid';
7
+ import {DocumentEntity} from './document.entity';
8
+ import {getDocumentById} from './get-document-by-id';
9
+ import {logger} from '@docknetwork/wallet-sdk-data-store/src/logger';
10
+ import {localStorageJSON} from '../../localStorageJSON';
11
+ import {getAllDocuments} from './get-all-documents';
12
+
13
+ export async function appendDocument(document: WalletDocument) {
14
+ const entities = (await localStorageJSON.getItem('documents')) || [];
15
+
16
+ await localStorageJSON.setItem('documents', [...entities, document]);
17
+ }
18
+
19
+ /**
20
+ * Create document
21
+ * @param dataStore
22
+ * @param json
23
+ */
24
+ export async function createDocument({
25
+ dataStore,
26
+ json,
27
+ options,
28
+ }: ContextProps & {
29
+ json: any;
30
+ options?: any;
31
+ }): Promise<WalletDocument> {
32
+ logger.debug(`Creating document with id ${json.id}...`);
33
+ if (json.id) {
34
+ const existingDocument = await getDocumentById({
35
+ dataStore,
36
+ id: json.id,
37
+ });
38
+
39
+ if (existingDocument) {
40
+ logger.debug(`Document with id ${json.id} already exists`);
41
+ throw new Error(`Document with id ${json.id} already exists`);
42
+ }
43
+ }
44
+
45
+ if (!json.id) {
46
+ json.id = uuid();
47
+ }
48
+
49
+ let networkId;
50
+
51
+ if (json._networkId) {
52
+ networkId = json._networkId;
53
+ delete json._networkId;
54
+ } else {
55
+ const resolution = await dataStore.resolveDocumentNetwork({
56
+ document: json,
57
+ dataStore,
58
+ });
59
+
60
+ networkId = resolution.networkId || dataStore.networkId;
61
+ }
62
+
63
+ const entity: DocumentEntity = {
64
+ networkId,
65
+ id: json.id,
66
+ type: json.type,
67
+ correlation: json.correlation || [],
68
+ data: json,
69
+ };
70
+
71
+ appendDocument(entity);
72
+
73
+ if (!options?.stopPropagation) {
74
+ dataStore.events.emit(DataStoreEvents.DocumentCreated, json);
75
+ } else {
76
+ console.log('stopPropagation is true');
77
+ }
78
+
79
+ logger.debug(`Document added to the wallet`);
80
+
81
+ return entity;
82
+ }
@@ -0,0 +1,135 @@
1
+ import {DocumentEntity} from './document.entity';
2
+ import {createTestDataStore} from '../../../test/test-utils';
3
+ import {DataStore} from '../../types';
4
+ import {createDocument} from './create-document';
5
+ import {getDocumentsByType} from './get-documents-by-type';
6
+ import {getDocumentById} from './get-document-by-id';
7
+ import {getDocumentCorrelations} from './get-document-correlations';
8
+
9
+ const mockDocuments = [
10
+ {
11
+ '@context': [
12
+ 'https://www.w3.org/2018/credentials/v1',
13
+ 'https://www.w3.org/2018/credentials/examples/v1',
14
+ ],
15
+ id: 'http://example.gov/credentials/test',
16
+ type: ['VerifiableCredential', 'UniversityDegreeCredential'],
17
+ issuer: {
18
+ id: 'did:example:123456789abcdefghi',
19
+ },
20
+ issuanceDate: '2020-03-10T04:24:12.164Z',
21
+ credentialSubject: {
22
+ id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
23
+ degree: {
24
+ type: 'BachelorDegree',
25
+ name: 'Bachelor of Science and Arts',
26
+ },
27
+ },
28
+ },
29
+ {
30
+ '@context': [
31
+ 'https://www.w3.org/2018/credentials/v1',
32
+ 'https://www.w3.org/2018/credentials/examples/v1',
33
+ ],
34
+ id: 'http://example.gov/credentials/test2',
35
+ type: ['VerifiableCredential', 'BasicCredential'],
36
+ issuer: {
37
+ id: 'did:example:123456789abcdefghi',
38
+ },
39
+ issuanceDate: '2020-03-10T04:24:12.164Z',
40
+ credentialSubject: {
41
+ id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
42
+ name: 'Testing',
43
+ },
44
+ },
45
+ {
46
+ '@context': ['https://w3id.org/wallet/v1'],
47
+ id: 'urn:uuid:c410e44a-9525-11ea-bb37-0242ac130002',
48
+ name: 'My Ropsten Mnemonic 1',
49
+ image: 'https://via.placeholder.com/150',
50
+ description: 'For testing only, totally compromised.',
51
+ tags: ['professional', 'organization', 'compromised'],
52
+ correlation: [],
53
+ type: 'Mnemonic',
54
+ value:
55
+ 'humble piece toy mimic miss hurdle smile awkward patch drama hurry mixture',
56
+ },
57
+ {
58
+ '@context': ['https://w3id.org/wallet/v1'],
59
+ id: 'c47f3ed0-b4b5-4983-8962-759196fd3ece',
60
+ type: 'Currency',
61
+ value: 0,
62
+ symbol: 'DOCK',
63
+ },
64
+ {
65
+ '@context': ['https://w3id.org/wallet/v1'],
66
+ id: '37NKEP14n9omsAgxJ3sn14XtHo2vs5a34UcpCyybXQJoUQ92',
67
+ type: 'Address',
68
+ value: '37NKEP14n9omsAgxJ3sn14XtHo2vs5a34UcpCyybXQJoUQ92',
69
+ address: '37NKEP14n9omsAgxJ3sn14XtHo2vs5a34UcpCyybXQJoUQ92',
70
+ name: 'Test',
71
+ correlation: [
72
+ 'urn:uuid:c410e44a-9525-11ea-bb37-0242ac130002',
73
+ 'c47f3ed0-b4b5-4983-8962-759196fd3ece',
74
+ ],
75
+ },
76
+ ];
77
+
78
+ describe('DocumentEntity', () => {
79
+ let dataStore: DataStore;
80
+
81
+ beforeAll(async () => {
82
+ dataStore = await createTestDataStore();
83
+
84
+ for (const document of mockDocuments) {
85
+ await createDocument({
86
+ dataStore,
87
+ json: document,
88
+ });
89
+ }
90
+ });
91
+
92
+ it('should be able to find a document by id', async () => {
93
+ const mockData = mockDocuments[0];
94
+ const document = await getDocumentById({
95
+ dataStore,
96
+ id: mockData.id,
97
+ });
98
+ expect(document).toBeDefined();
99
+ expect(document.type).toEqual(mockData.type);
100
+ });
101
+
102
+ describe('getDocumentsByType', () => {
103
+ it('should be able to query all VerifiableCredential', async () => {
104
+ const documents = await getDocumentsByType({
105
+ dataStore,
106
+ type: 'VerifiableCredential',
107
+ });
108
+
109
+ expect(documents).toBeDefined();
110
+ expect(documents.length).toEqual(2);
111
+ });
112
+
113
+ it('should be able query only BasicCredential', async () => {
114
+ const documents = await getDocumentsByType({
115
+ dataStore,
116
+ type: 'BasicCredential',
117
+ });
118
+
119
+ expect(documents).toBeDefined();
120
+ expect(documents.length).toEqual(1);
121
+ });
122
+ });
123
+
124
+ describe('getDocumentCorrelations', () => {
125
+ it('expect to query all correlations', async () => {
126
+ const documents = await getDocumentCorrelations({
127
+ dataStore,
128
+ documentId: '37NKEP14n9omsAgxJ3sn14XtHo2vs5a34UcpCyybXQJoUQ92',
129
+ });
130
+
131
+ expect(documents).toBeDefined();
132
+ expect(documents.length).toEqual(2);
133
+ });
134
+ });
135
+ });
@@ -0,0 +1,7 @@
1
+ export interface DocumentEntity {
2
+ id: string;
3
+ networkId: string;
4
+ type: string[];
5
+ correlation: string[];
6
+ data: string;
7
+ }