@or-sdk/graph 0.22.5-251.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.
Files changed (64) hide show
  1. package/dist/cjs/Graph.js +191 -0
  2. package/dist/cjs/Graph.js.map +1 -0
  3. package/dist/cjs/constants.js +5 -0
  4. package/dist/cjs/constants.js.map +1 -0
  5. package/dist/cjs/index.js +21 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/types.js +3 -0
  8. package/dist/cjs/types.js.map +1 -0
  9. package/dist/cjs/utils/getCreateNodeQuery.js +4 -0
  10. package/dist/cjs/utils/getCreateNodeQuery.js.map +1 -0
  11. package/dist/cjs/utils/getDeleteNodeQuery.js +5 -0
  12. package/dist/cjs/utils/getDeleteNodeQuery.js.map +1 -0
  13. package/dist/cjs/utils/getMatchNodeQuery.js +5 -0
  14. package/dist/cjs/utils/getMatchNodeQuery.js.map +1 -0
  15. package/dist/cjs/utils/getSetNodeQuery.js +5 -0
  16. package/dist/cjs/utils/getSetNodeQuery.js.map +1 -0
  17. package/dist/cjs/utils/index.js +17 -0
  18. package/dist/cjs/utils/index.js.map +1 -0
  19. package/dist/cjs/utils/stringify.js +16 -0
  20. package/dist/cjs/utils/stringify.js.map +1 -0
  21. package/dist/esm/Graph.js +112 -0
  22. package/dist/esm/Graph.js.map +1 -0
  23. package/dist/esm/constants.js +2 -0
  24. package/dist/esm/constants.js.map +1 -0
  25. package/dist/esm/index.js +3 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/types.js +2 -0
  28. package/dist/esm/types.js.map +1 -0
  29. package/dist/esm/utils/getCreateNodeQuery.js +2 -0
  30. package/dist/esm/utils/getCreateNodeQuery.js.map +1 -0
  31. package/dist/esm/utils/getDeleteNodeQuery.js +3 -0
  32. package/dist/esm/utils/getDeleteNodeQuery.js.map +1 -0
  33. package/dist/esm/utils/getMatchNodeQuery.js +3 -0
  34. package/dist/esm/utils/getMatchNodeQuery.js.map +1 -0
  35. package/dist/esm/utils/getSetNodeQuery.js +3 -0
  36. package/dist/esm/utils/getSetNodeQuery.js.map +1 -0
  37. package/dist/esm/utils/index.js +6 -0
  38. package/dist/esm/utils/index.js.map +1 -0
  39. package/dist/esm/utils/stringify.js +8 -0
  40. package/dist/esm/utils/stringify.js.map +1 -0
  41. package/dist/types/Graph.d.ts +21 -0
  42. package/dist/types/constants.d.ts +1 -0
  43. package/dist/types/index.d.ts +2 -0
  44. package/dist/types/types.d.ts +141 -0
  45. package/dist/types/utils/getCreateNodeQuery.d.ts +2 -0
  46. package/dist/types/utils/getDeleteNodeQuery.d.ts +4 -0
  47. package/dist/types/utils/getMatchNodeQuery.d.ts +4 -0
  48. package/dist/types/utils/getSetNodeQuery.d.ts +4 -0
  49. package/dist/types/utils/index.d.ts +5 -0
  50. package/dist/types/utils/stringify.d.ts +4 -0
  51. package/package.json +30 -0
  52. package/src/Graph.ts +192 -0
  53. package/src/constants.ts +1 -0
  54. package/src/index.ts +2 -0
  55. package/src/types.ts +177 -0
  56. package/src/utils/getCreateNodeQuery.ts +1 -0
  57. package/src/utils/getDeleteNodeQuery.ts +3 -0
  58. package/src/utils/getMatchNodeQuery.ts +3 -0
  59. package/src/utils/getSetNodeQuery.ts +3 -0
  60. package/src/utils/index.ts +9 -0
  61. package/src/utils/stringify.ts +9 -0
  62. package/tsconfig.esm.json +9 -0
  63. package/tsconfig.json +7 -0
  64. package/tsconfig.types.json +9 -0
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.Graph = void 0;
55
+ var base_1 = require("@or-sdk/base");
56
+ var constants_1 = require("./constants");
57
+ var utils_1 = require("./utils");
58
+ var Graph = (function (_super) {
59
+ __extends(Graph, _super);
60
+ function Graph(params) {
61
+ var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, graphUrl = params.graphUrl;
62
+ return _super.call(this, {
63
+ token: token,
64
+ discoveryUrl: discoveryUrl,
65
+ serviceKey: constants_1.SERVICE_KEY,
66
+ accountId: accountId,
67
+ serviceUrl: graphUrl,
68
+ }) || this;
69
+ }
70
+ Graph.prototype.makeApiUrl = function (data) {
71
+ return this.isCrossAccount
72
+ ? "".concat(data.url, "/").concat(this.targetAccountId)
73
+ : "".concat(data.url, "/current");
74
+ };
75
+ Graph.prototype.executeQuery = function (_a) {
76
+ var query = _a.query, params = _a.params, database = _a.database;
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ return __generator(this, function (_b) {
79
+ return [2, this.callApi({
80
+ data: {
81
+ query: query,
82
+ params: params,
83
+ database: database,
84
+ },
85
+ method: 'POST',
86
+ route: 'query',
87
+ })];
88
+ });
89
+ });
90
+ };
91
+ Graph.prototype.createNode = function (_a) {
92
+ var label = _a.label, data = _a.data, database = _a.database;
93
+ return __awaiter(this, void 0, void 0, function () {
94
+ return __generator(this, function (_b) {
95
+ return [2, this.executeQuery({
96
+ query: (0, utils_1.getCreateNodeQuery)(label),
97
+ params: { data: data },
98
+ database: database,
99
+ })];
100
+ });
101
+ });
102
+ };
103
+ Graph.prototype.matchNode = function (_a) {
104
+ var label = _a.label, where = _a.where, database = _a.database;
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ return __generator(this, function (_b) {
107
+ return [2, this.executeQuery({
108
+ query: (0, utils_1.getMatchNodeQuery)(label, where),
109
+ database: database,
110
+ })];
111
+ });
112
+ });
113
+ };
114
+ Graph.prototype.deleteNode = function (_a) {
115
+ var label = _a.label, where = _a.where, database = _a.database;
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ return __generator(this, function (_b) {
118
+ return [2, this.executeQuery({
119
+ query: (0, utils_1.getDeleteNodeQuery)(label, where),
120
+ database: database,
121
+ })];
122
+ });
123
+ });
124
+ };
125
+ Graph.prototype.setNode = function (_a) {
126
+ var label = _a.label, data = _a.data, where = _a.where, database = _a.database;
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ return __generator(this, function (_b) {
129
+ return [2, this.executeQuery({
130
+ query: (0, utils_1.getSetNodeQuery)(label, where),
131
+ params: { data: data },
132
+ database: database,
133
+ })];
134
+ });
135
+ });
136
+ };
137
+ Graph.prototype.listDatabases = function () {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var databases;
140
+ return __generator(this, function (_a) {
141
+ switch (_a.label) {
142
+ case 0: return [4, this.callApi({
143
+ method: 'GET',
144
+ route: 'databases',
145
+ })];
146
+ case 1:
147
+ databases = (_a.sent()).databases;
148
+ return [2, (0, base_1.makeList)(databases.map(function (database) { return database.name; }))];
149
+ }
150
+ });
151
+ });
152
+ };
153
+ Graph.prototype.createDatabase = function (_a) {
154
+ var database = _a.database;
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ return __generator(this, function (_b) {
157
+ return [2, this.callApi({
158
+ data: { database: database },
159
+ method: 'PUT',
160
+ route: 'databases',
161
+ })];
162
+ });
163
+ });
164
+ };
165
+ Graph.prototype.getDatabaseInfo = function (_a) {
166
+ var database = _a.database;
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ return __generator(this, function (_b) {
169
+ return [2, this.callApi({
170
+ method: 'GET',
171
+ route: "databases/".concat(encodeURIComponent(database)),
172
+ })];
173
+ });
174
+ });
175
+ };
176
+ Graph.prototype.dropDatabase = function (_a) {
177
+ var database = _a.database;
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ return __generator(this, function (_b) {
180
+ return [2, this.callApi({
181
+ data: { database: database },
182
+ method: 'DELETE',
183
+ route: 'databases',
184
+ })];
185
+ });
186
+ });
187
+ };
188
+ return Graph;
189
+ }(base_1.Base));
190
+ exports.Graph = Graph;
191
+ //# sourceMappingURL=Graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../src/Graph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA8E;AAU9E,yCAA0C;AAC1C,iCAAqG;AASrG;IAA2B,yBAAI;IAO7B,eAAY,MAAmB;QACrB,IAAA,KAAK,GAAwC,MAAM,MAA9C,EAAE,YAAY,GAA0B,MAAM,aAAhC,EAAE,SAAS,GAAe,MAAM,UAArB,EAAE,QAAQ,GAAK,MAAM,SAAX,CAAY;eAE5D,kBAAM;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,UAAU,EAAE,uBAAW;YACvB,SAAS,WAAA;YACT,UAAU,EAAE,QAAQ;SACrB,CAAC;IACJ,CAAC;IAED,0BAAU,GAAV,UAAW,IAA8B;QACvC,OAAO,IAAI,CAAC,cAAc;YACxB,CAAC,CAAC,UAAG,IAAI,CAAC,GAAG,cAAI,IAAI,CAAC,eAAe,CAAE;YACvC,CAAC,CAAC,UAAG,IAAI,CAAC,GAAG,aAAU,CAAC;IAC5B,CAAC;IAWY,4BAAY,GAAzB,UAA0B,EAA6C;YAA3C,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,QAAQ,cAAA;;;gBACjD,WAAO,IAAI,CAAC,OAAO,CAAuB;wBACxC,IAAI,EAAE;4BACJ,KAAK,OAAA;4BACL,MAAM,QAAA;4BACN,QAAQ,UAAA;yBACT;wBACD,MAAM,EAAE,MAAM;wBACd,KAAK,EAAE,OAAO;qBACf,CAAC,EAAC;;;KACJ;IAYY,0BAAU,GAAvB,UAAwB,EAAyC;YAAvC,KAAK,WAAA,EAAE,IAAI,UAAA,EAAE,QAAQ,cAAA;;;gBAC7C,WAAO,IAAI,CAAC,YAAY,CAAC;wBACvB,KAAK,EAAE,IAAA,0BAAkB,EAAC,KAAK,CAAC;wBAChC,MAAM,EAAE,EAAE,IAAI,MAAA,EAAE;wBAChB,QAAQ,UAAA;qBACT,CAAC,EAAC;;;KACJ;IAYY,yBAAS,GAAtB,UAAuB,EAAyC;YAAvC,KAAK,WAAA,EAAE,KAAK,WAAA,EAAE,QAAQ,cAAA;;;gBAC7C,WAAO,IAAI,CAAC,YAAY,CAAC;wBACvB,KAAK,EAAE,IAAA,yBAAiB,EAAC,KAAK,EAAE,KAAK,CAAC;wBACtC,QAAQ,UAAA;qBACT,CAAC,EAAC;;;KACJ;IAYY,0BAAU,GAAvB,UAAwB,EAA0C;YAAxC,KAAK,WAAA,EAAE,KAAK,WAAA,EAAE,QAAQ,cAAA;;;gBAC9C,WAAO,IAAI,CAAC,YAAY,CAAC;wBACvB,KAAK,EAAE,IAAA,0BAAkB,EAAC,KAAK,EAAE,KAAK,CAAC;wBACvC,QAAQ,UAAA;qBACT,CAAC,EAAC;;;KACJ;IAaY,uBAAO,GAApB,UAAqB,EAA6C;YAA3C,KAAK,WAAA,EAAE,IAAI,UAAA,EAAE,KAAK,WAAA,EAAE,QAAQ,cAAA;;;gBACjD,WAAO,IAAI,CAAC,YAAY,CAAC;wBACvB,KAAK,EAAE,IAAA,uBAAe,EAAC,KAAK,EAAE,KAAK,CAAC;wBACpC,MAAM,EAAE,EAAE,IAAI,MAAA,EAAE;wBAChB,QAAQ,UAAA;qBACT,CAAC,EAAC;;;KACJ;IAQY,6BAAa,GAA1B;;;;;4BACwB,WAAM,IAAI,CAAC,OAAO,CAAuB;4BAC7D,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,WAAW;yBACnB,CAAC,EAAA;;wBAHM,SAAS,GAAK,CAAA,SAGpB,CAAA,UAHe;wBAIjB,WAAO,IAAA,eAAQ,EAAS,SAAS,CAAC,GAAG,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,EAAb,CAAa,CAAC,CAAC,EAAC;;;;KACnE;IAQY,8BAAc,GAA3B,UAA4B,EAAmC;YAAjC,QAAQ,cAAA;;;gBACpC,WAAO,IAAI,CAAC,OAAO,CAAyB;wBAC1C,IAAI,EAAE,EAAE,QAAQ,UAAA,EAAE;wBAClB,MAAM,EAAE,KAAK;wBACb,KAAK,EAAE,WAAW;qBACnB,CAAC,EAAC;;;KACJ;IAQY,+BAAe,GAA5B,UAA6B,EAAmC;YAAjC,QAAQ,cAAA;;;gBACrC,WAAO,IAAI,CAAC,OAAO,CAA0B;wBAC3C,MAAM,EAAE,KAAK;wBACb,KAAK,EAAE,oBAAa,kBAAkB,CAAC,QAAQ,CAAC,CAAE;qBACnD,CAAC,EAAC;;;KACJ;IAQY,4BAAY,GAAzB,UAA0B,EAAmC;YAAjC,QAAQ,cAAA;;;gBAClC,WAAO,IAAI,CAAC,OAAO,CAAuB;wBACxC,IAAI,EAAE,EAAE,QAAQ,UAAA,EAAE;wBAClB,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE,WAAW;qBACnB,CAAC,EAAC;;;KACJ;IACH,YAAC;AAAD,CAAC,AA3KD,CAA2B,WAAI,GA2K9B;AA3KY,sBAAK"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SERVICE_KEY = void 0;
4
+ exports.SERVICE_KEY = 'graphdb';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,SAAS,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Graph = void 0;
18
+ var Graph_1 = require("./Graph");
19
+ Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return Graph_1.Graph; } });
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (function (label) { return "create (n:".concat(label, " $data) return n"); });
4
+ //# sourceMappingURL=getCreateNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCreateNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getCreateNodeQuery.ts"],"names":[],"mappings":";;AAAA,mBAAe,UAAC,KAAa,IAAK,OAAA,oBAAa,KAAK,qBAAkB,EAApC,CAAoC,EAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("../utils");
4
+ exports.default = (function (label, where) { return "match (n:".concat(label, " ").concat((0, utils_1.stringify)(where), ") delete n"); });
5
+ //# sourceMappingURL=getDeleteNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDeleteNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getDeleteNodeQuery.ts"],"names":[],"mappings":";;AAAA,kCAAqC;AAErC,mBAAe,UAAC,KAAa,EAAE,KAAkC,IAAK,OAAA,mBAAY,KAAK,cAAI,IAAA,iBAAS,EAAC,KAAK,CAAC,eAAY,EAAjD,CAAiD,EAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("../utils");
4
+ exports.default = (function (label, where) { return "match (n:".concat(label, " ").concat((0, utils_1.stringify)(where), ") return n"); });
5
+ //# sourceMappingURL=getMatchNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMatchNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getMatchNodeQuery.ts"],"names":[],"mappings":";;AAAA,kCAAqC;AAErC,mBAAe,UAAC,KAAa,EAAE,KAAkC,IAAK,OAAA,mBAAY,KAAK,cAAI,IAAA,iBAAS,EAAC,KAAK,CAAC,eAAY,EAAjD,CAAiD,EAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("../utils");
4
+ exports.default = (function (label, where) { return "match (n:".concat(label, " ").concat((0, utils_1.stringify)(where), ") set n+=$data return n"); });
5
+ //# sourceMappingURL=getSetNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSetNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getSetNodeQuery.ts"],"names":[],"mappings":";;AAAA,kCAAqC;AAErC,mBAAe,UAAC,KAAa,EAAE,KAAkC,IAAK,OAAA,mBAAY,KAAK,cAAI,IAAA,iBAAS,EAAC,KAAK,CAAC,4BAAyB,EAA9D,CAA8D,EAAC"}
@@ -0,0 +1,17 @@
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.getSetNodeQuery = exports.getDeleteNodeQuery = exports.getMatchNodeQuery = exports.getCreateNodeQuery = exports.stringify = void 0;
7
+ var stringify_1 = require("./stringify");
8
+ Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return __importDefault(stringify_1).default; } });
9
+ var getCreateNodeQuery_1 = require("./getCreateNodeQuery");
10
+ Object.defineProperty(exports, "getCreateNodeQuery", { enumerable: true, get: function () { return __importDefault(getCreateNodeQuery_1).default; } });
11
+ var getMatchNodeQuery_1 = require("./getMatchNodeQuery");
12
+ Object.defineProperty(exports, "getMatchNodeQuery", { enumerable: true, get: function () { return __importDefault(getMatchNodeQuery_1).default; } });
13
+ var getDeleteNodeQuery_1 = require("./getDeleteNodeQuery");
14
+ Object.defineProperty(exports, "getDeleteNodeQuery", { enumerable: true, get: function () { return __importDefault(getDeleteNodeQuery_1).default; } });
15
+ var getSetNodeQuery_1 = require("./getSetNodeQuery");
16
+ Object.defineProperty(exports, "getSetNodeQuery", { enumerable: true, get: function () { return __importDefault(getSetNodeQuery_1).default; } });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAIA,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAC7B,2DAAqE;AAA5D,yIAAA,OAAO,OAAsB;AACtC,yDAAmE;AAA1D,uIAAA,OAAO,OAAqB;AACrC,2DAAqE;AAA5D,yIAAA,OAAO,OAAsB;AACtC,qDAA+D;AAAtD,mIAAA,OAAO,OAAmB"}
@@ -0,0 +1,16 @@
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
+ var lodash_1 = __importDefault(require("lodash"));
7
+ function stringify(obj) {
8
+ if (lodash_1.default.isObject(obj))
9
+ return "{".concat(Object.entries(obj).map(function (_a) {
10
+ var key = _a[0], value = _a[1];
11
+ return "".concat(key, ":").concat(JSON.stringify(value));
12
+ }).join(', '), "}");
13
+ return obj || '';
14
+ }
15
+ exports.default = stringify;
16
+ //# sourceMappingURL=stringify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../src/utils/stringify.ts"],"names":[],"mappings":";;;;;AAAA,kDAAuB;AAEvB,SAAS,SAAS,CAAC,GAAgC;IACjD,IAAI,gBAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;QACjB,OAAO,WAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAC,EAAY;gBAAX,GAAG,QAAA,EAAE,KAAK,QAAA;YAAM,OAAA,UAAG,GAAG,cAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAE;QAAjC,CAAiC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAG,CAAC;IACxG,OAAO,GAAG,IAAI,EAAE,CAAC;AACnB,CAAC;AAED,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,112 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Base, makeList } from '@or-sdk/base';
11
+ import { SERVICE_KEY } from './constants';
12
+ import { getCreateNodeQuery, getMatchNodeQuery, getDeleteNodeQuery, getSetNodeQuery } from './utils';
13
+ export class Graph extends Base {
14
+ constructor(params) {
15
+ const { token, discoveryUrl, accountId, graphUrl } = params;
16
+ super({
17
+ token,
18
+ discoveryUrl,
19
+ serviceKey: SERVICE_KEY,
20
+ accountId,
21
+ serviceUrl: graphUrl,
22
+ });
23
+ }
24
+ makeApiUrl(data) {
25
+ return this.isCrossAccount
26
+ ? `${data.url}/${this.targetAccountId}`
27
+ : `${data.url}/current`;
28
+ }
29
+ executeQuery({ query, params, database }) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this.callApi({
32
+ data: {
33
+ query,
34
+ params,
35
+ database,
36
+ },
37
+ method: 'POST',
38
+ route: 'query',
39
+ });
40
+ });
41
+ }
42
+ createNode({ label, data, database }) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return this.executeQuery({
45
+ query: getCreateNodeQuery(label),
46
+ params: { data },
47
+ database,
48
+ });
49
+ });
50
+ }
51
+ matchNode({ label, where, database }) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return this.executeQuery({
54
+ query: getMatchNodeQuery(label, where),
55
+ database,
56
+ });
57
+ });
58
+ }
59
+ deleteNode({ label, where, database }) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ return this.executeQuery({
62
+ query: getDeleteNodeQuery(label, where),
63
+ database,
64
+ });
65
+ });
66
+ }
67
+ setNode({ label, data, where, database }) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return this.executeQuery({
70
+ query: getSetNodeQuery(label, where),
71
+ params: { data },
72
+ database,
73
+ });
74
+ });
75
+ }
76
+ listDatabases() {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const { databases } = yield this.callApi({
79
+ method: 'GET',
80
+ route: 'databases',
81
+ });
82
+ return makeList(databases.map(database => database.name));
83
+ });
84
+ }
85
+ createDatabase({ database }) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ return this.callApi({
88
+ data: { database },
89
+ method: 'PUT',
90
+ route: 'databases',
91
+ });
92
+ });
93
+ }
94
+ getDatabaseInfo({ database }) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ return this.callApi({
97
+ method: 'GET',
98
+ route: `databases/${encodeURIComponent(database)}`,
99
+ });
100
+ });
101
+ }
102
+ dropDatabase({ database }) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ return this.callApi({
105
+ data: { database },
106
+ method: 'DELETE',
107
+ route: 'databases',
108
+ });
109
+ });
110
+ }
111
+ }
112
+ //# sourceMappingURL=Graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../src/Graph.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export const SERVICE_KEY = 'graphdb';
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Graph } from './Graph';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export default (label) => `create (n:${label} $data) return n`;
2
+ //# sourceMappingURL=getCreateNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCreateNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getCreateNodeQuery.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,KAAa,EAAE,EAAE,CAAC,aAAa,KAAK,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { stringify } from '../utils';
2
+ export default (label, where) => `match (n:${label} ${stringify(where)}) delete n`;
3
+ //# sourceMappingURL=getDeleteNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDeleteNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getDeleteNodeQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,eAAe,CAAC,KAAa,EAAE,KAAkC,EAAE,EAAE,CAAC,YAAY,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { stringify } from '../utils';
2
+ export default (label, where) => `match (n:${label} ${stringify(where)}) return n`;
3
+ //# sourceMappingURL=getMatchNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMatchNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getMatchNodeQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,eAAe,CAAC,KAAa,EAAE,KAAkC,EAAE,EAAE,CAAC,YAAY,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { stringify } from '../utils';
2
+ export default (label, where) => `match (n:${label} ${stringify(where)}) set n+=$data return n`;
3
+ //# sourceMappingURL=getSetNodeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSetNodeQuery.js","sourceRoot":"","sources":["../../../src/utils/getSetNodeQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,eAAe,CAAC,KAAa,EAAE,KAAkC,EAAE,EAAE,CAAC,YAAY,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,yBAAyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { default as stringify } from './stringify';
2
+ export { default as getCreateNodeQuery } from './getCreateNodeQuery';
3
+ export { default as getMatchNodeQuery } from './getMatchNodeQuery';
4
+ export { default as getDeleteNodeQuery } from './getDeleteNodeQuery';
5
+ export { default as getSetNodeQuery } from './getSetNodeQuery';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import _ from 'lodash';
2
+ function stringify(obj) {
3
+ if (_.isObject(obj))
4
+ return `{${Object.entries(obj).map(([key, value]) => `${key}:${JSON.stringify(value)}`).join(', ')}}`;
5
+ return obj || '';
6
+ }
7
+ export default stringify;
8
+ //# sourceMappingURL=stringify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify.js","sourceRoot":"","sources":["../../../src/utils/stringify.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,SAAS,SAAS,CAAC,GAAgC;IACjD,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;QACjB,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACxG,OAAO,GAAG,IAAI,EAAE,CAAC;AACnB,CAAC;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Base, ServiceDiscoveryResponse, List } from '@or-sdk/base';
2
+ import { CreateDatabaseResponse, CreateNodeArgs, DeleteNodeArgs, DropDatabaseResponse, ExecuteQueryArgs, ExecuteQueryResponse, GetDatabaseInfoResponse, GraphConfig, MatchNodeArgs, SetNodeArgs } from './types';
3
+ export declare class Graph extends Base {
4
+ constructor(params: GraphConfig);
5
+ makeApiUrl(data: ServiceDiscoveryResponse): string;
6
+ executeQuery({ query, params, database }: ExecuteQueryArgs): Promise<ExecuteQueryResponse>;
7
+ createNode({ label, data, database }: CreateNodeArgs): Promise<ExecuteQueryResponse>;
8
+ matchNode({ label, where, database }: MatchNodeArgs): Promise<ExecuteQueryResponse>;
9
+ deleteNode({ label, where, database }: DeleteNodeArgs): Promise<ExecuteQueryResponse>;
10
+ setNode({ label, data, where, database }: SetNodeArgs): Promise<ExecuteQueryResponse>;
11
+ listDatabases(): Promise<List<string>>;
12
+ createDatabase({ database }: {
13
+ database: string;
14
+ }): Promise<CreateDatabaseResponse>;
15
+ getDatabaseInfo({ database }: {
16
+ database: string;
17
+ }): Promise<GetDatabaseInfoResponse>;
18
+ dropDatabase({ database }: {
19
+ database: string;
20
+ }): Promise<DropDatabaseResponse>;
21
+ }
@@ -0,0 +1 @@
1
+ export declare const SERVICE_KEY = "graphdb";
@@ -0,0 +1,2 @@
1
+ export { Graph } from './Graph';
2
+ export * from './types';
@@ -0,0 +1,141 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export declare type GraphConfig = {
3
+ token: Token;
4
+ discoveryUrl?: string;
5
+ accountId?: string;
6
+ graphUrl?: string;
7
+ };
8
+ export declare type ExecuteQueryArgs = {
9
+ query: string;
10
+ params?: {
11
+ [key: string]: unknown;
12
+ };
13
+ database: string;
14
+ };
15
+ export declare type CreateNodeArgs = {
16
+ label: string;
17
+ data: {
18
+ [key: string]: unknown;
19
+ };
20
+ database: string;
21
+ };
22
+ export declare type MatchNodeArgs = {
23
+ label: string;
24
+ where: {
25
+ [key: string]: unknown;
26
+ };
27
+ database: string;
28
+ };
29
+ export declare type DeleteNodeArgs = {
30
+ label: string;
31
+ where: {
32
+ [key: string]: unknown;
33
+ };
34
+ database: string;
35
+ };
36
+ export declare type SetNodeArgs = {
37
+ label: string;
38
+ data: {
39
+ [key: string]: unknown;
40
+ };
41
+ where: {
42
+ [key: string]: unknown;
43
+ };
44
+ database: string;
45
+ };
46
+ export declare type Database = {
47
+ name: string;
48
+ };
49
+ export declare type ListDatabaseResponse = {
50
+ databases: Database[];
51
+ };
52
+ export declare type CreateDatabaseResponse = {
53
+ ok?: number;
54
+ };
55
+ export declare type DropDatabaseResponse = {
56
+ ok?: number;
57
+ };
58
+ export declare type GetDatabaseInfoResponse = {
59
+ labels: string[];
60
+ relationships: string[];
61
+ };
62
+ export declare type RecordNode = {
63
+ identity: number;
64
+ labels: string[];
65
+ properties: {
66
+ [key: string]: unknown;
67
+ };
68
+ };
69
+ export declare type SegmentRelationship = {
70
+ identity: number;
71
+ start: number;
72
+ end: number;
73
+ type: string;
74
+ properties: {
75
+ [key: string]: unknown;
76
+ };
77
+ };
78
+ export declare type Segment = {
79
+ start: RecordNode;
80
+ relationship: SegmentRelationship;
81
+ end: RecordNode;
82
+ };
83
+ export declare type RecordRelationship = {
84
+ start: RecordNode;
85
+ end: RecordNode;
86
+ segments: Segment[];
87
+ length: number;
88
+ };
89
+ export declare type Record = {
90
+ [key: string]: RecordNode | RecordRelationship;
91
+ };
92
+ export declare type Query = {
93
+ text: string;
94
+ parameters: {
95
+ data?: {
96
+ [key: string]: unknown;
97
+ };
98
+ };
99
+ };
100
+ export declare type Counters = {
101
+ _stats: {
102
+ nodesCreated: number;
103
+ nodesDeleted: number;
104
+ relationshipsCreated: number;
105
+ relationshipsDeleted: number;
106
+ propertiesSet: number;
107
+ labelsAdded: number;
108
+ labelsRemoved: number;
109
+ indexesAdded: number;
110
+ indexesRemoved: number;
111
+ constraintsAdded: number;
112
+ constraintsRemoved: number;
113
+ };
114
+ _systemUpdates: number;
115
+ };
116
+ export declare type UpdateStatistics = Counters;
117
+ export declare type Notification = {
118
+ code: string;
119
+ title: string;
120
+ description: string;
121
+ severity: string;
122
+ position: {
123
+ offset: 0;
124
+ line: 1;
125
+ column: 1;
126
+ };
127
+ };
128
+ export declare type ExecuteQueryResponse = {
129
+ records: Record[];
130
+ summary: {
131
+ query: Query;
132
+ queryType: string;
133
+ counters: Counters;
134
+ updateStatistics: UpdateStatistics;
135
+ plan: boolean;
136
+ profile: boolean;
137
+ notifications?: Notification[];
138
+ resultConsumedAfter: number;
139
+ resultAvailableAfter: number;
140
+ };
141
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: (label: string) => string;
2
+ export default _default;
@@ -0,0 +1,4 @@
1
+ declare const _default: (label: string, where: {
2
+ [key: string]: unknown;
3
+ }) => string;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ declare const _default: (label: string, where: {
2
+ [key: string]: unknown;
3
+ }) => string;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ declare const _default: (label: string, where: {
2
+ [key: string]: unknown;
3
+ }) => string;
4
+ export default _default;
@@ -0,0 +1,5 @@
1
+ export { default as stringify } from './stringify';
2
+ export { default as getCreateNodeQuery } from './getCreateNodeQuery';
3
+ export { default as getMatchNodeQuery } from './getMatchNodeQuery';
4
+ export { default as getDeleteNodeQuery } from './getDeleteNodeQuery';
5
+ export { default as getSetNodeQuery } from './getSetNodeQuery';
@@ -0,0 +1,4 @@
1
+ declare function stringify(obj: {
2
+ [key: string]: unknown;
3
+ }): string;
4
+ export default stringify;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "version": "0.22.5-251.0",
3
+ "name": "@or-sdk/graph",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && concurrently \"npm run build:cjs\" \"npm run build:esm\" \"npm run build:types\"",
9
+ "build:watch": "concurrently -r --hide 1,2 \"npm run build:watch:cjs\" \"npm run build:watch:esm\" \"npm run build:watch:types\"",
10
+ "build:cjs": "tsc --project tsconfig.json",
11
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
12
+ "build:esm": "tsc --project tsconfig.esm.json",
13
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
14
+ "build:types": "tsc --project tsconfig.types.json",
15
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
16
+ "clean": "rm -rf ./dist"
17
+ },
18
+ "devDependencies": {
19
+ "@types/lodash": "^4.14.176",
20
+ "concurrently": "^6.4.0",
21
+ "typescript": "^4.4.4"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "dependencies": {
27
+ "@or-sdk/base": "^0.22.4",
28
+ "lodash": "^4.17.21"
29
+ }
30
+ }
package/src/Graph.ts ADDED
@@ -0,0 +1,192 @@
1
+ import { Base, ServiceDiscoveryResponse, List, makeList } from '@or-sdk/base';
2
+ import {
3
+ CreateDatabaseResponse,
4
+ CreateNodeArgs,
5
+ DeleteNodeArgs, DropDatabaseResponse,
6
+ ExecuteQueryArgs, ExecuteQueryResponse, GetDatabaseInfoResponse,
7
+ GraphConfig, ListDatabaseResponse,
8
+ MatchNodeArgs,
9
+ SetNodeArgs,
10
+ } from './types';
11
+ import { SERVICE_KEY } from './constants';
12
+ import { getCreateNodeQuery, getMatchNodeQuery, getDeleteNodeQuery, getSetNodeQuery } from './utils';
13
+
14
+ /**
15
+ * OneReach Graph service client
16
+ * ## Installation:
17
+ * ```
18
+ * $ npm i @or-sdk/graph
19
+ * ```
20
+ */
21
+ export class Graph extends Base {
22
+ /**
23
+ * ```typescript
24
+ * import { Graph } from '@or-sdk/graph'
25
+ * const graph = new Graph({token: 'my-account-token-string', discoveryUrl: 'http://example.graph/endpoint'});
26
+ * ```
27
+ */
28
+ constructor(params: GraphConfig) {
29
+ const { token, discoveryUrl, accountId, graphUrl } = params;
30
+
31
+ super({
32
+ token,
33
+ discoveryUrl,
34
+ serviceKey: SERVICE_KEY,
35
+ accountId,
36
+ serviceUrl: graphUrl,
37
+ });
38
+ }
39
+
40
+ makeApiUrl(data: ServiceDiscoveryResponse): string {
41
+ return this.isCrossAccount
42
+ ? `${data.url}/${this.targetAccountId}`
43
+ : `${data.url}/current`;
44
+ }
45
+
46
+ /**
47
+ * Execute query
48
+ * ```typescript
49
+ * const result = await graph.executeQuery({
50
+ * query: 'match(n:node_name) return n',
51
+ * database: 'db-name'
52
+ * });
53
+ * ```
54
+ */
55
+ public async executeQuery({ query, params, database }: ExecuteQueryArgs): Promise<ExecuteQueryResponse> {
56
+ return this.callApi<ExecuteQueryResponse>({
57
+ data: {
58
+ query,
59
+ params,
60
+ database,
61
+ },
62
+ method: 'POST',
63
+ route: 'query',
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Create node
69
+ * ```typescript
70
+ * const result = await graph.createNode({
71
+ * label: 'node-name',
72
+ * data: { id: 1 },
73
+ * database: 'database-name'
74
+ * });
75
+ * ```
76
+ */
77
+ public async createNode({ label, data, database }: CreateNodeArgs): Promise<ExecuteQueryResponse> {
78
+ return this.executeQuery({
79
+ query: getCreateNodeQuery(label),
80
+ params: { data },
81
+ database,
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Match node
87
+ * ```typescript
88
+ * const result = await graph.matchNode({
89
+ * label: 'node-name',
90
+ * where: { id:1 },
91
+ * database: 'database-name'
92
+ * });
93
+ * ```
94
+ */
95
+ public async matchNode({ label, where, database }: MatchNodeArgs): Promise<ExecuteQueryResponse> {
96
+ return this.executeQuery({
97
+ query: getMatchNodeQuery(label, where),
98
+ database,
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Delete node
104
+ * ```typescript
105
+ * const result = await graph.deleteNode({
106
+ * label: 'node-name',
107
+ * where: { id:1 },
108
+ * database: 'database-name'
109
+ * });
110
+ * ```
111
+ */
112
+ public async deleteNode({ label, where, database }: DeleteNodeArgs): Promise<ExecuteQueryResponse> {
113
+ return this.executeQuery({
114
+ query: getDeleteNodeQuery(label, where),
115
+ database,
116
+ });
117
+ }
118
+
119
+ /**
120
+ * Set node
121
+ * ```typescript
122
+ * const result = await graph.setNode({
123
+ * label: 'node-name',
124
+ * data: { key: 'value' },
125
+ * where: { id:1 },
126
+ * database: 'database-name'
127
+ * });
128
+ * ```
129
+ */
130
+ public async setNode({ label, data, where, database }: SetNodeArgs): Promise<ExecuteQueryResponse> {
131
+ return this.executeQuery({
132
+ query: getSetNodeQuery(label, where),
133
+ params: { data },
134
+ database,
135
+ });
136
+ }
137
+
138
+ /**
139
+ * List databases
140
+ * ```typescript
141
+ * const databaseList = await graph.listDatabases();
142
+ * ```
143
+ */
144
+ public async listDatabases(): Promise<List<string>> {
145
+ const { databases } = await this.callApi<ListDatabaseResponse>({
146
+ method: 'GET',
147
+ route: 'databases',
148
+ });
149
+ return makeList<string>(databases.map(database => database.name));
150
+ }
151
+
152
+ /**
153
+ * Create database
154
+ * ```typescript
155
+ * const result = await graph.createDatabase({ database: 'db-name' });
156
+ * ```
157
+ */
158
+ public async createDatabase({ database }: { database: string; }): Promise<CreateDatabaseResponse> {
159
+ return this.callApi<CreateDatabaseResponse>({
160
+ data: { database },
161
+ method: 'PUT',
162
+ route: 'databases',
163
+ });
164
+ }
165
+
166
+ /**
167
+ * Get database info
168
+ * ```typescript
169
+ * const result = await graph.getDatabaseInfo({ database: 'db-name' });
170
+ * ```
171
+ */
172
+ public async getDatabaseInfo({ database }: { database: string; }): Promise<GetDatabaseInfoResponse> {
173
+ return this.callApi<GetDatabaseInfoResponse>({
174
+ method: 'GET',
175
+ route: `databases/${encodeURIComponent(database)}`,
176
+ });
177
+ }
178
+
179
+ /**
180
+ * Drop database
181
+ * ```typescript
182
+ * const result = await graph.dropDatabase({ database: 'db-name' });
183
+ * ```
184
+ */
185
+ public async dropDatabase({ database }: { database: string; }): Promise<DropDatabaseResponse> {
186
+ return this.callApi<DropDatabaseResponse>({
187
+ data: { database },
188
+ method: 'DELETE',
189
+ route: 'databases',
190
+ });
191
+ }
192
+ }
@@ -0,0 +1 @@
1
+ export const SERVICE_KEY = 'graphdb';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Graph } from './Graph';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,177 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type GraphConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+
9
+ /**
10
+ * Url of OneReach service discovery api
11
+ */
12
+ discoveryUrl?: string;
13
+
14
+ /**
15
+ * Account ID for cross-account requests (super admin only)
16
+ */
17
+ accountId?: string;
18
+
19
+ /**
20
+ * Url of OneReach graph api
21
+ */
22
+ graphUrl?: string;
23
+ };
24
+
25
+ export type ExecuteQueryArgs = {
26
+ query: string;
27
+ params?: {
28
+ [key: string]: unknown;
29
+ };
30
+ database: string;
31
+ };
32
+
33
+ export type CreateNodeArgs = {
34
+ label: string;
35
+ data: {
36
+ [key: string]: unknown;
37
+ };
38
+ database: string;
39
+ };
40
+
41
+ export type MatchNodeArgs = {
42
+ label: string;
43
+ where: {
44
+ [key: string]: unknown;
45
+ };
46
+ database: string;
47
+ };
48
+
49
+ export type DeleteNodeArgs = {
50
+ label: string;
51
+ where: {
52
+ [key: string]: unknown;
53
+ };
54
+ database: string;
55
+ };
56
+
57
+ export type SetNodeArgs = {
58
+ label: string;
59
+ data: {
60
+ [key: string]: unknown;
61
+ };
62
+ where: {
63
+ [key: string]: unknown;
64
+ };
65
+ database: string;
66
+ };
67
+
68
+ export type Database = {
69
+ name: string;
70
+ };
71
+
72
+ export type ListDatabaseResponse = {
73
+ databases: Database[];
74
+ };
75
+
76
+ export type CreateDatabaseResponse = {
77
+ ok?: number;
78
+ };
79
+
80
+ export type DropDatabaseResponse = {
81
+ ok?: number;
82
+ };
83
+
84
+ export type GetDatabaseInfoResponse = {
85
+ labels: string[];
86
+ relationships: string[];
87
+ };
88
+
89
+ export type RecordNode = {
90
+ identity: number;
91
+ labels: string[];
92
+ properties: {
93
+ [key: string]: unknown;
94
+ };
95
+ };
96
+
97
+ export type SegmentRelationship = {
98
+ identity: number;
99
+ start: number;
100
+ end: number;
101
+ type: string;
102
+ properties: {
103
+ [key: string]: unknown;
104
+ };
105
+ };
106
+
107
+ export type Segment = {
108
+ start: RecordNode;
109
+ relationship: SegmentRelationship;
110
+ end: RecordNode;
111
+ };
112
+
113
+ export type RecordRelationship = {
114
+ start: RecordNode;
115
+ end: RecordNode;
116
+ segments: Segment[];
117
+ length: number;
118
+ };
119
+
120
+ export type Record = {
121
+ [key: string]: RecordNode | RecordRelationship;
122
+ };
123
+
124
+ export type Query = {
125
+ text: string;
126
+ parameters: {
127
+ data?: {
128
+ [key: string]: unknown;
129
+ };
130
+ };
131
+ };
132
+
133
+ export type Counters = {
134
+ _stats: {
135
+ nodesCreated: number;
136
+ nodesDeleted: number;
137
+ relationshipsCreated: number;
138
+ relationshipsDeleted: number;
139
+ propertiesSet: number;
140
+ labelsAdded: number;
141
+ labelsRemoved: number;
142
+ indexesAdded: number;
143
+ indexesRemoved: number;
144
+ constraintsAdded: number;
145
+ constraintsRemoved: number;
146
+ };
147
+ _systemUpdates: number;
148
+ };
149
+
150
+ export type UpdateStatistics = Counters;
151
+
152
+ export type Notification = {
153
+ code: string;
154
+ title: string;
155
+ description: string;
156
+ severity: string;
157
+ position: {
158
+ offset: 0;
159
+ line: 1;
160
+ column: 1;
161
+ };
162
+ };
163
+
164
+ export type ExecuteQueryResponse = {
165
+ records: Record[];
166
+ summary: {
167
+ query: Query;
168
+ queryType: string;
169
+ counters: Counters;
170
+ updateStatistics: UpdateStatistics;
171
+ plan: boolean;
172
+ profile: boolean;
173
+ notifications?: Notification[];
174
+ resultConsumedAfter: number;
175
+ resultAvailableAfter: number;
176
+ };
177
+ };
@@ -0,0 +1 @@
1
+ export default (label: string) => `create (n:${label} $data) return n`;
@@ -0,0 +1,3 @@
1
+ import { stringify } from '../utils';
2
+
3
+ export default (label: string, where: { [key: string]: unknown; }) => `match (n:${label} ${stringify(where)}) delete n`;
@@ -0,0 +1,3 @@
1
+ import { stringify } from '../utils';
2
+
3
+ export default (label: string, where: { [key: string]: unknown; }) => `match (n:${label} ${stringify(where)}) return n`;
@@ -0,0 +1,3 @@
1
+ import { stringify } from '../utils';
2
+
3
+ export default (label: string, where: { [key: string]: unknown; }) => `match (n:${label} ${stringify(where)}) set n+=$data return n`;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @internal
3
+ */
4
+
5
+ export { default as stringify } from './stringify';
6
+ export { default as getCreateNodeQuery } from './getCreateNodeQuery';
7
+ export { default as getMatchNodeQuery } from './getMatchNodeQuery';
8
+ export { default as getDeleteNodeQuery } from './getDeleteNodeQuery';
9
+ export { default as getSetNodeQuery } from './getSetNodeQuery';
@@ -0,0 +1,9 @@
1
+ import _ from 'lodash';
2
+
3
+ function stringify(obj: { [key: string]: unknown; }): string {
4
+ if (_.isObject(obj))
5
+ return `{${Object.entries(obj).map(([key, value]) => `${key}:${JSON.stringify(value)}`).join(', ')}}`;
6
+ return obj || '';
7
+ }
8
+
9
+ export default stringify;
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES6",
5
+ "target": "es6",
6
+ "outDir": "./dist/esm/",
7
+ "rootDir": "./src"
8
+ }
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true
8
+ }
9
+ }