@or-sdk/views 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Views.js +56 -1
- package/dist/cjs/Views.js.map +1 -1
- package/dist/cjs/utils/addTagsIds.js +20 -0
- package/dist/cjs/utils/addTagsIds.js.map +1 -0
- package/dist/cjs/utils/filterTagIds.js +25 -0
- package/dist/cjs/utils/filterTagIds.js.map +1 -0
- package/dist/cjs/utils/index.js +13 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/removeTagIds.js +11 -0
- package/dist/cjs/utils/removeTagIds.js.map +1 -0
- package/dist/esm/Views.js +31 -1
- package/dist/esm/Views.js.map +1 -1
- package/dist/esm/utils/addTagsIds.js +9 -0
- package/dist/esm/utils/addTagsIds.js.map +1 -0
- package/dist/esm/utils/filterTagIds.js +23 -0
- package/dist/esm/utils/filterTagIds.js.map +1 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/removeTagIds.js +9 -0
- package/dist/esm/utils/removeTagIds.js.map +1 -0
- package/dist/types/Views.d.ts +5 -1
- package/dist/types/utils/addTagsIds.d.ts +3 -0
- package/dist/types/utils/filterTagIds.d.ts +6 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/removeTagIds.d.ts +3 -0
- package/package.json +5 -4
- package/src/Views.ts +67 -2
- package/src/utils/addTagsIds.ts +15 -0
- package/src/utils/filterTagIds.ts +27 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/removeTagIds.ts +15 -0
package/dist/cjs/Views.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -39,6 +50,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
50
|
exports.Views = void 0;
|
|
40
51
|
var data_hub_1 = require("@or-sdk/data-hub");
|
|
41
52
|
var constants_1 = require("./constants");
|
|
53
|
+
var tags_1 = require("@or-sdk/tags");
|
|
42
54
|
var Views = (function () {
|
|
43
55
|
function Views(params) {
|
|
44
56
|
var token = params.token, discoveryUrl = params.discoveryUrl;
|
|
@@ -46,12 +58,19 @@ var Views = (function () {
|
|
|
46
58
|
token: token,
|
|
47
59
|
discoveryUrl: discoveryUrl,
|
|
48
60
|
});
|
|
61
|
+
this.tags = new tags_1.Tags({
|
|
62
|
+
token: token,
|
|
63
|
+
discoveryUrl: discoveryUrl,
|
|
64
|
+
});
|
|
49
65
|
}
|
|
50
66
|
Views.prototype.init = function () {
|
|
51
67
|
return __awaiter(this, void 0, void 0, function () {
|
|
52
68
|
return __generator(this, function (_a) {
|
|
53
69
|
switch (_a.label) {
|
|
54
|
-
case 0: return [4,
|
|
70
|
+
case 0: return [4, Promise.all([
|
|
71
|
+
this.dataHub.init(),
|
|
72
|
+
this.tags.init(),
|
|
73
|
+
])];
|
|
55
74
|
case 1:
|
|
56
75
|
_a.sent();
|
|
57
76
|
return [2];
|
|
@@ -209,6 +228,42 @@ var Views = (function () {
|
|
|
209
228
|
});
|
|
210
229
|
});
|
|
211
230
|
};
|
|
231
|
+
Views.prototype.addTags = function (source, tagNames) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
var tags, tagIds, newIds;
|
|
234
|
+
return __generator(this, function (_a) {
|
|
235
|
+
switch (_a.label) {
|
|
236
|
+
case 0: return [4, this.tags.getMultipleTagsByName(tagNames, true)];
|
|
237
|
+
case 1:
|
|
238
|
+
tags = _a.sent();
|
|
239
|
+
tagIds = tags.map(function (tag) { return tag.id; });
|
|
240
|
+
newIds = (0, tags_1.filterTagIds)(source.data.data.filterByTagIds, tagIds).newIds;
|
|
241
|
+
if (!newIds.length) {
|
|
242
|
+
throw Error('No tag IDs to add.');
|
|
243
|
+
}
|
|
244
|
+
return [2, this.saveView(__assign(__assign({}, source), { data: __assign(__assign({}, source.data), { data: __assign(__assign({}, source.data.data), { filterByTagIds: (0, tags_1.addTagsIds)(source.data.data.filterByTagIds, newIds) }) }) }))];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
Views.prototype.removeTags = function (source, tagNames) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
251
|
+
var tags, tagIds, existingIds;
|
|
252
|
+
return __generator(this, function (_a) {
|
|
253
|
+
switch (_a.label) {
|
|
254
|
+
case 0: return [4, this.tags.getMultipleTagsByName(tagNames)];
|
|
255
|
+
case 1:
|
|
256
|
+
tags = _a.sent();
|
|
257
|
+
tagIds = tags.map(function (tag) { return tag.id; });
|
|
258
|
+
existingIds = (0, tags_1.filterTagIds)(source.data.data.filterByTagIds, tagIds).existingIds;
|
|
259
|
+
if (!existingIds.length) {
|
|
260
|
+
throw Error('No tag IDs to remove.');
|
|
261
|
+
}
|
|
262
|
+
return [2, this.saveView(__assign(__assign({}, source), { data: __assign(__assign({}, source.data), { data: __assign(__assign({}, source.data.data), { filterByTagIds: (0, tags_1.removeTagIds)(source.data.data.filterByTagIds, existingIds) }) }) }))];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
212
267
|
return Views;
|
|
213
268
|
}());
|
|
214
269
|
exports.Views = Views;
|
package/dist/cjs/Views.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Views.js","sourceRoot":"","sources":["../../src/Views.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Views.js","sourceRoot":"","sources":["../../src/Views.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6CAA2F;AAE3F,yCAA2G;AAC3G,qCAAsF;AAStF;IAWE,eAAY,MAAmB;QACrB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,YAAY,GAAK,MAAM,aAAX,CAAY;QAEvC,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAO,CAAC;YACzB,KAAK,OAAA;YACL,YAAY,cAAA;SACb,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC;YACnB,KAAK,OAAA;YACL,YAAY,cAAA;SACb,CAAC,CAAC;IACL,CAAC;IAEK,oBAAI,GAAV;;;;4BACE,WAAM,OAAO,CAAC,GAAG,CAAC;4BAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;yBACjB,CAAC,EAAA;;wBAHF,SAGE,CAAC;;;;;KACJ;IAQY,yBAAS,GAAtB;;;;gBACQ,SAAS,GAAG;oBAChB,MAAM,EAAE,uBAAW;oBACnB,MAAM,EAAE;wBACN,WAAW,EAAE,EAAE;wBACf,cAAc,EAAE,KAAK;wBACrB,eAAe,EAAE,IAAI;wBACrB,KAAK,EAAE,EAAE;qBACV;oBACD,OAAO,EAAE,KAAK;iBACf,CAAC;gBAEI,IAAI,GAAG;oBACX,aAAa,EAAE,MAAM;oBACrB,KAAK,EAAE,sBAAU;oBACjB,SAAS,WAAA;iBACV,CAAC;gBAEF,WAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAO,MAAM,EAAE,UAAU,EAAE,IAAI,C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AI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,UAG9E,EAAC;;;;KACJ;IACH,YAAC;AAAD,CAAC,AArPD,IAqPC;AArPY,sBAAK"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
function addTagIds(source, tagIds) {
|
|
13
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
14
|
+
source.data.data.filterByTagIds = [];
|
|
15
|
+
}
|
|
16
|
+
source.data.data.filterByTagIds = __spreadArray(__spreadArray([], source.data.data.filterByTagIds, true), tagIds, true);
|
|
17
|
+
return source;
|
|
18
|
+
}
|
|
19
|
+
exports.default = addTagIds;
|
|
20
|
+
//# sourceMappingURL=addTagsIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addTagsIds.js","sourceRoot":"","sources":["../../../src/utils/addTagsIds.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,SAAS,SAAS,CAAC,MAAY,EAAE,MAAgB;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,mCAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,SAAK,MAAM,OAAC,CAAC;IAElF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function filterTagIds(source, tagIdsToFilter) {
|
|
4
|
+
var newIds = [];
|
|
5
|
+
var existingIds = [];
|
|
6
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
7
|
+
newIds = tagIdsToFilter;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
tagIdsToFilter.forEach(function (tagId) {
|
|
11
|
+
if (source.data.data.filterByTagIds.indexOf(tagId) !== -1) {
|
|
12
|
+
existingIds.push(tagId);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
newIds.push(tagId);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
newIds: newIds,
|
|
21
|
+
existingIds: existingIds,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.default = filterTagIds;
|
|
25
|
+
//# sourceMappingURL=filterTagIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterTagIds.js","sourceRoot":"","sources":["../../../src/utils/filterTagIds.ts"],"names":[],"mappings":";;AAIA,SAAS,YAAY,CAAC,MAAY,EAAE,cAAwB;IAC1D,IAAI,MAAM,GAAa,EAAE,CAAC;IAC1B,IAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,GAAG,cAAc,CAAC;KACzB;SAAM;QACL,cAAc,CAAC,OAAO,CAAC,UAAA,KAAK;YAC1B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAe,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC1D,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACzB;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO;QACL,MAAM,QAAA;QACN,WAAW,aAAA;KACZ,CAAC;AACJ,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.removeTagIds = exports.addTagsIds = exports.filterTagIds = void 0;
|
|
7
|
+
var filterTagIds_1 = require("./filterTagIds");
|
|
8
|
+
Object.defineProperty(exports, "filterTagIds", { enumerable: true, get: function () { return __importDefault(filterTagIds_1).default; } });
|
|
9
|
+
var addTagsIds_1 = require("./addTagsIds");
|
|
10
|
+
Object.defineProperty(exports, "addTagsIds", { enumerable: true, get: function () { return __importDefault(addTagsIds_1).default; } });
|
|
11
|
+
var removeTagIds_1 = require("./removeTagIds");
|
|
12
|
+
Object.defineProperty(exports, "removeTagIds", { enumerable: true, get: function () { return __importDefault(removeTagIds_1).default; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAGA,+CAAyD;AAAhD,6HAAA,OAAO,OAAgB;AAChC,2CAAqD;AAA5C,yHAAA,OAAO,OAAc;AAC9B,+CAAyD;AAAhD,6HAAA,OAAO,OAAgB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function removeTagIds(source, tagIds) {
|
|
4
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
5
|
+
source.data.data.filterByTagIds = [];
|
|
6
|
+
}
|
|
7
|
+
source.data.data.filterByTagIds = source.data.data.filterByTagIds.filter(function (id) { return tagIds.indexOf(id) === -1; });
|
|
8
|
+
return source;
|
|
9
|
+
}
|
|
10
|
+
exports.default = removeTagIds;
|
|
11
|
+
//# sourceMappingURL=removeTagIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeTagIds.js","sourceRoot":"","sources":["../../../src/utils/removeTagIds.ts"],"names":[],"mappings":";;AAIA,SAAS,YAAY,CAAC,MAAY,EAAE,MAAgB;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,UAAC,EAAU,IAAK,OAAA,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAzB,CAAyB,CAAC,CAAC;IAEpH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
package/dist/esm/Views.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { DataHub } from '@or-sdk/data-hub';
|
|
11
11
|
import { ENTITY_NAME, QUERY_LIST, QUERY_GET, QUERY_CREATE, QUERY_UPDATE, QUERY_DELETE } from './constants';
|
|
12
|
+
import { Tags, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
|
|
12
13
|
export class Views {
|
|
13
14
|
constructor(params) {
|
|
14
15
|
const { token, discoveryUrl } = params;
|
|
@@ -16,10 +17,17 @@ export class Views {
|
|
|
16
17
|
token,
|
|
17
18
|
discoveryUrl,
|
|
18
19
|
});
|
|
20
|
+
this.tags = new Tags({
|
|
21
|
+
token,
|
|
22
|
+
discoveryUrl,
|
|
23
|
+
});
|
|
19
24
|
}
|
|
20
25
|
init() {
|
|
21
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
yield
|
|
27
|
+
yield Promise.all([
|
|
28
|
+
this.dataHub.init(),
|
|
29
|
+
this.tags.init(),
|
|
30
|
+
]);
|
|
23
31
|
});
|
|
24
32
|
}
|
|
25
33
|
listViews() {
|
|
@@ -135,5 +143,27 @@ export class Views {
|
|
|
135
143
|
return this.dataHub.subscribe(requestId);
|
|
136
144
|
});
|
|
137
145
|
}
|
|
146
|
+
addTags(source, tagNames) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const tags = yield this.tags.getMultipleTagsByName(tagNames, true);
|
|
149
|
+
const tagIds = tags.map(tag => tag.id);
|
|
150
|
+
const { newIds } = filterTagIds(source.data.data.filterByTagIds, tagIds);
|
|
151
|
+
if (!newIds.length) {
|
|
152
|
+
throw Error('No tag IDs to add.');
|
|
153
|
+
}
|
|
154
|
+
return this.saveView(Object.assign(Object.assign({}, source), { data: Object.assign(Object.assign({}, source.data), { data: Object.assign(Object.assign({}, source.data.data), { filterByTagIds: addTagsIds(source.data.data.filterByTagIds, newIds) }) }) }));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
removeTags(source, tagNames) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const tags = yield this.tags.getMultipleTagsByName(tagNames);
|
|
160
|
+
const tagIds = tags.map(tag => tag.id);
|
|
161
|
+
const { existingIds } = filterTagIds(source.data.data.filterByTagIds, tagIds);
|
|
162
|
+
if (!existingIds.length) {
|
|
163
|
+
throw Error('No tag IDs to remove.');
|
|
164
|
+
}
|
|
165
|
+
return this.saveView(Object.assign(Object.assign({}, source), { data: Object.assign(Object.assign({}, source.data), { data: Object.assign(Object.assign({}, source.data.data), { filterByTagIds: removeTagIds(source.data.data.filterByTagIds, existingIds) }) }) }));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
138
168
|
}
|
|
139
169
|
//# sourceMappingURL=Views.js.map
|
package/dist/esm/Views.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Views.js","sourceRoot":"","sources":["../../src/Views.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAkD,MAAM,kBAAkB,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Views.js","sourceRoot":"","sources":["../../src/Views.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,OAAO,EAAkD,MAAM,kBAAkB,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,EAAE,IAAI,EAAY,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAStF,MAAM,OAAO,KAAK;IAWhB,YAAY,MAAmB;QAC7B,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAEvC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC;YACzB,KAAK;YACL,YAAY;SACb,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC;YACnB,KAAK;YACL,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEK,IAAI;;YACR,MAAM,OAAO,CAAC,GAAG,CAAC;gBAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;gBACnB,IAAI,CAAC,IAAI,CA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ExC,MAAM,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;YAE9E,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;gBACvB,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAC;aACtC;YAED,OAAO,IAAI,CAAC,QAAQ,iCACf,MAAM,KACT,IAAI,kCACC,MAAM,CAAC,IAAI,KACd,IAAI,kCACC,MAAM,CAAC,IAAI,CAAC,IAAI,KACnB,cAAc,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,UAG9E,CAAC;QACL,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function addTagIds(source, tagIds) {
|
|
2
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
3
|
+
source.data.data.filterByTagIds = [];
|
|
4
|
+
}
|
|
5
|
+
source.data.data.filterByTagIds = [...source.data.data.filterByTagIds, ...tagIds];
|
|
6
|
+
return source;
|
|
7
|
+
}
|
|
8
|
+
export default addTagIds;
|
|
9
|
+
//# sourceMappingURL=addTagsIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addTagsIds.js","sourceRoot":"","sources":["../../../src/utils/addTagsIds.ts"],"names":[],"mappings":"AAIA,SAAS,SAAS,CAAC,MAAY,EAAE,MAAgB;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,CAAC;IAElF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function filterTagIds(source, tagIdsToFilter) {
|
|
2
|
+
let newIds = [];
|
|
3
|
+
const existingIds = [];
|
|
4
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
5
|
+
newIds = tagIdsToFilter;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
tagIdsToFilter.forEach(tagId => {
|
|
9
|
+
if (source.data.data.filterByTagIds.indexOf(tagId) !== -1) {
|
|
10
|
+
existingIds.push(tagId);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
newIds.push(tagId);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
newIds,
|
|
19
|
+
existingIds,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default filterTagIds;
|
|
23
|
+
//# sourceMappingURL=filterTagIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterTagIds.js","sourceRoot":"","sources":["../../../src/utils/filterTagIds.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,MAAY,EAAE,cAAwB;IAC1D,IAAI,MAAM,GAAa,EAAE,CAAC;IAC1B,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,GAAG,cAAc,CAAC;KACzB;SAAM;QACL,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAe,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC1D,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACzB;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO;QACL,MAAM;QACN,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function removeTagIds(source, tagIds) {
|
|
2
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
3
|
+
source.data.data.filterByTagIds = [];
|
|
4
|
+
}
|
|
5
|
+
source.data.data.filterByTagIds = source.data.data.filterByTagIds.filter((id) => tagIds.indexOf(id) === -1);
|
|
6
|
+
return source;
|
|
7
|
+
}
|
|
8
|
+
export default removeTagIds;
|
|
9
|
+
//# sourceMappingURL=removeTagIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeTagIds.js","sourceRoot":"","sources":["../../../src/utils/removeTagIds.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,MAAY,EAAE,MAAgB;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEpH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,YAAY,CAAC"}
|
package/dist/types/Views.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { List } from '@or-sdk/base';
|
|
2
2
|
import { GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
|
|
3
3
|
import { ViewsConfig, View } from './types';
|
|
4
|
-
|
|
4
|
+
import { Taggable } from '@or-sdk/tags';
|
|
5
|
+
export declare class Views implements Taggable<View> {
|
|
5
6
|
private readonly dataHub;
|
|
7
|
+
private readonly tags;
|
|
6
8
|
constructor(params: ViewsConfig);
|
|
7
9
|
init(): Promise<void>;
|
|
8
10
|
listViews(): Promise<List<View>>;
|
|
@@ -11,4 +13,6 @@ export declare class Views {
|
|
|
11
13
|
createView(source: View): Promise<View>;
|
|
12
14
|
updateView(source: View): Promise<View>;
|
|
13
15
|
deleteView(viewId: string): Promise<GraphqlResponseCheckExecution>;
|
|
16
|
+
addTags(source: View, tagNames: string[]): Promise<View>;
|
|
17
|
+
removeTags(source: View, tagNames: string[]): Promise<View>;
|
|
14
18
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.14.0",
|
|
3
3
|
"name": "@or-sdk/views",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@or-sdk/base": "^0.
|
|
27
|
-
"@or-sdk/data-hub": "^0.
|
|
26
|
+
"@or-sdk/base": "^0.14.0",
|
|
27
|
+
"@or-sdk/data-hub": "^0.14.0",
|
|
28
|
+
"@or-sdk/tags": "^0.14.0"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "5a9977bbaa2aabe4461155b78bf59ac68c698668"
|
|
30
31
|
}
|
package/src/Views.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { List } from '@or-sdk/base';
|
|
|
2
2
|
import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
|
|
3
3
|
import { ViewsConfig, View } from './types';
|
|
4
4
|
import { ENTITY_NAME, QUERY_LIST, QUERY_GET, QUERY_CREATE, QUERY_UPDATE, QUERY_DELETE } from './constants';
|
|
5
|
+
import { Tags, Taggable, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* OneReach Views service client
|
|
@@ -10,8 +11,9 @@ import { ENTITY_NAME, QUERY_LIST, QUERY_GET, QUERY_CREATE, QUERY_UPDATE, QUERY_D
|
|
|
10
11
|
* $ npm i @or-sdk/views
|
|
11
12
|
* ```
|
|
12
13
|
*/
|
|
13
|
-
export class Views {
|
|
14
|
+
export class Views implements Taggable<View> {
|
|
14
15
|
private readonly dataHub: DataHub;
|
|
16
|
+
private readonly tags: Tags;
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* ```typescript
|
|
@@ -27,10 +29,17 @@ export class Views {
|
|
|
27
29
|
token,
|
|
28
30
|
discoveryUrl,
|
|
29
31
|
});
|
|
32
|
+
this.tags = new Tags({
|
|
33
|
+
token,
|
|
34
|
+
discoveryUrl,
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
async init() {
|
|
33
|
-
await
|
|
39
|
+
await Promise.all([
|
|
40
|
+
this.dataHub.init(),
|
|
41
|
+
this.tags.init(),
|
|
42
|
+
]);
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
/**
|
|
@@ -191,4 +200,60 @@ export class Views {
|
|
|
191
200
|
|
|
192
201
|
return this.dataHub.subscribe(requestId);
|
|
193
202
|
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Add tags
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const view = await views.addTags(viewSource, tagIdsArr);
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
public async addTags(source: View, tagNames: string[]): Promise<View> {
|
|
211
|
+
const tags = await this.tags.getMultipleTagsByName(tagNames, true);
|
|
212
|
+
const tagIds = tags.map(tag => tag.id!);
|
|
213
|
+
|
|
214
|
+
const { newIds } = filterTagIds(source.data.data.filterByTagIds, tagIds);
|
|
215
|
+
|
|
216
|
+
if (!newIds.length) {
|
|
217
|
+
throw Error('No tag IDs to add.');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return this.saveView({
|
|
221
|
+
...source,
|
|
222
|
+
data: {
|
|
223
|
+
...source.data,
|
|
224
|
+
data: {
|
|
225
|
+
...source.data.data,
|
|
226
|
+
filterByTagIds: addTagsIds(source.data.data.filterByTagIds, newIds),
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Remove tags
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const view = await views.removeTags(viewSource, tagIdsArr);
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
public async removeTags(source: View, tagNames: string[]): Promise<View> {
|
|
239
|
+
const tags = await this.tags.getMultipleTagsByName(tagNames);
|
|
240
|
+
const tagIds = tags.map(tag => tag.id!);
|
|
241
|
+
|
|
242
|
+
const { existingIds } = filterTagIds(source.data.data.filterByTagIds, tagIds);
|
|
243
|
+
|
|
244
|
+
if (!existingIds.length) {
|
|
245
|
+
throw Error('No tag IDs to remove.');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return this.saveView({
|
|
249
|
+
...source,
|
|
250
|
+
data: {
|
|
251
|
+
...source.data,
|
|
252
|
+
data: {
|
|
253
|
+
...source.data.data,
|
|
254
|
+
filterByTagIds: removeTagIds(source.data.data.filterByTagIds, existingIds),
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
194
259
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
View,
|
|
3
|
+
} from '../types';
|
|
4
|
+
|
|
5
|
+
function addTagIds(source: View, tagIds: string[]): View {
|
|
6
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
7
|
+
source.data.data.filterByTagIds = [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
source.data.data.filterByTagIds = [...source.data.data.filterByTagIds, ...tagIds];
|
|
11
|
+
|
|
12
|
+
return source;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default addTagIds;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
View,
|
|
3
|
+
} from '../types';
|
|
4
|
+
|
|
5
|
+
function filterTagIds(source: View, tagIdsToFilter: string[]): { newIds: string[]; existingIds: string[]; } {
|
|
6
|
+
let newIds: string[] = [];
|
|
7
|
+
const existingIds: string[] = [];
|
|
8
|
+
|
|
9
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
10
|
+
newIds = tagIdsToFilter;
|
|
11
|
+
} else {
|
|
12
|
+
tagIdsToFilter.forEach(tagId => {
|
|
13
|
+
if (source.data.data.filterByTagIds!.indexOf(tagId) !== -1) {
|
|
14
|
+
existingIds.push(tagId);
|
|
15
|
+
} else {
|
|
16
|
+
newIds.push(tagId);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
newIds,
|
|
23
|
+
existingIds,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default filterTagIds;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
View,
|
|
3
|
+
} from '../types';
|
|
4
|
+
|
|
5
|
+
function removeTagIds(source: View, tagIds: string[]): View {
|
|
6
|
+
if (!Array.isArray(source.data.data.filterByTagIds)) {
|
|
7
|
+
source.data.data.filterByTagIds = [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
source.data.data.filterByTagIds = source.data.data.filterByTagIds.filter((id: string) => tagIds.indexOf(id) === -1);
|
|
11
|
+
|
|
12
|
+
return source;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default removeTagIds;
|