@uniformdev/project-map 17.7.1-alpha.140 → 17.7.1-alpha.169

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.
@@ -0,0 +1,224 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw new Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __esm = (fn, res) => function __init() {
15
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
+ };
17
+ var __commonJS = (cb, mod) => function __require2() {
18
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // src/projectMapClient.ts
39
+ import { ApiClient } from "@uniformdev/context/api";
40
+ var ROOT_NODE_PATH = "/";
41
+ var ProjectMapClient = class extends ApiClient {
42
+ constructor(options) {
43
+ super(options);
44
+ this.getProjectMapDefinitions = async () => {
45
+ const { projectId } = this.options;
46
+ const fetchUri = this.createUrl("/api/v1/project-map", { projectId });
47
+ return await this.apiClient(fetchUri);
48
+ };
49
+ this.getProjectMapDefinition = async (options) => {
50
+ const { projectId } = this.options;
51
+ const fetchUri = this.createUrl("/api/v1/project-map", {
52
+ ...options,
53
+ projectId
54
+ });
55
+ return await this.apiClient(fetchUri);
56
+ };
57
+ this.upsertProjectMap = async (options) => {
58
+ const { projectId } = this.options;
59
+ const fetchUri = this.createUrl("/api/v1/project-map");
60
+ const result = await this.apiClient(fetchUri, {
61
+ method: "PUT",
62
+ body: JSON.stringify({ ...options, projectId })
63
+ });
64
+ return result.projectMapId;
65
+ };
66
+ this.deleteProjectMap = async (options) => {
67
+ const { projectId } = this.options;
68
+ const fetchUri = this.createUrl("/api/v1/project-map");
69
+ await this.apiClient(fetchUri, {
70
+ method: "DELETE",
71
+ body: JSON.stringify({ ...options, projectId }),
72
+ expectNoContent: true
73
+ });
74
+ };
75
+ this.upsertProjectMapNodes = async (options) => {
76
+ const { projectId } = this.options;
77
+ const fetchUri = this.createUrl("/api/v1/project-map-nodes");
78
+ await this.apiClient(fetchUri, {
79
+ method: "PUT",
80
+ body: JSON.stringify({
81
+ ...options,
82
+ projectId,
83
+ nodes: options.nodes.map((n) => {
84
+ return {
85
+ ...n,
86
+ node: { ...this.cleanProjectMapNode(n.node) }
87
+ };
88
+ })
89
+ }),
90
+ expectNoContent: true
91
+ });
92
+ };
93
+ this.deleteProjectMapNode = async (options) => {
94
+ const { projectId } = this.options;
95
+ const fetchUri = this.createUrl("/api/v1/project-map-nodes");
96
+ if (!options.path || this.validatePath(options.path)) {
97
+ await this.apiClient(fetchUri, {
98
+ method: "DELETE",
99
+ body: JSON.stringify({
100
+ ...options,
101
+ projectId
102
+ }),
103
+ expectNoContent: true
104
+ });
105
+ }
106
+ };
107
+ this.getSubtree = async (options) => {
108
+ var _a;
109
+ const { projectId } = this.options;
110
+ const fetchOptions = {
111
+ projectId,
112
+ projectMapId: options.projectMapId
113
+ };
114
+ if (options.search) {
115
+ fetchOptions["search"] = options.search;
116
+ } else if (options.id) {
117
+ fetchOptions["id"] = options.id;
118
+ } else if (options.path && this.validatePath(options.path)) {
119
+ fetchOptions["path"] = options.path;
120
+ } else if (options.compositionId) {
121
+ fetchOptions["compositionId"] = options.compositionId;
122
+ }
123
+ if (options.depth) {
124
+ fetchOptions["depth"] = options.depth.toString();
125
+ }
126
+ if (options.expanded) {
127
+ fetchOptions["expanded"] = "true";
128
+ }
129
+ fetchOptions["tree"] = "true";
130
+ const fetchUri = this.createUrl("/api/v1/project-map-nodes", fetchOptions);
131
+ const result = await this.apiClient(fetchUri);
132
+ const root = {
133
+ ...result.tree
134
+ };
135
+ const nodes = [root];
136
+ while (nodes && nodes.length > 0) {
137
+ const currentNode = nodes.pop();
138
+ let lastChild = void 0;
139
+ (_a = currentNode == null ? void 0 : currentNode.children) == null ? void 0 : _a.forEach((child) => {
140
+ child.parent = cutReferences(currentNode);
141
+ child.previousSibling = cutReferences(lastChild);
142
+ if (lastChild) {
143
+ lastChild.nextSibling = cutReferences(child);
144
+ }
145
+ lastChild = child;
146
+ nodes.push(child);
147
+ });
148
+ }
149
+ return root;
150
+ };
151
+ this.getNodes = async (options) => {
152
+ const { projectId } = this.options;
153
+ const fetchOptions = {
154
+ projectId
155
+ };
156
+ if (options.projectMapId) {
157
+ fetchOptions["projectMapId"] = options.projectMapId;
158
+ }
159
+ if (options.search) {
160
+ fetchOptions["search"] = options.search;
161
+ } else if (options.id) {
162
+ fetchOptions["id"] = options.id;
163
+ } else if (options.path && this.validatePath(options.path)) {
164
+ fetchOptions["path"] = options.path;
165
+ } else if (options.compositionId) {
166
+ fetchOptions["compositionId"] = options.compositionId;
167
+ }
168
+ if (options.limit) {
169
+ fetchOptions["limit"] = options.limit.toString();
170
+ }
171
+ if (options.offset) {
172
+ fetchOptions["offset"] = options.offset.toString();
173
+ }
174
+ if (options.expanded) {
175
+ fetchOptions["expanded"] = "true";
176
+ }
177
+ const fetchUri = this.createUrl("/api/v1/project-map-nodes", fetchOptions);
178
+ return await this.apiClient(fetchUri);
179
+ };
180
+ }
181
+ cleanProjectMapNode(node) {
182
+ var _a, _b, _c;
183
+ return {
184
+ id: ((_c = (_b = (_a = node.id) == null ? void 0 : _a.match(/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i)) == null ? void 0 : _b.length) != null ? _c : 0) == 1 ? node.id : void 0,
185
+ path: node.path,
186
+ name: node.name,
187
+ type: node.type,
188
+ order: node.order,
189
+ data: node.data,
190
+ compositionId: node.compositionId,
191
+ description: node.description
192
+ };
193
+ }
194
+ validatePath(path) {
195
+ const regex = /[*%!&@]/g;
196
+ const match = path == null ? void 0 : path.match(regex);
197
+ if (match) {
198
+ throw "Path cannot contain reserved characters * % ! & @";
199
+ }
200
+ return true;
201
+ }
202
+ };
203
+ var UncachedProjectMapClient = class extends ProjectMapClient {
204
+ constructor(options) {
205
+ super({ ...options, bypassCache: true });
206
+ }
207
+ };
208
+ var cutReferences = (node) => node ? {
209
+ ...node,
210
+ parent: void 0,
211
+ children: void 0
212
+ } : void 0;
213
+
214
+ export {
215
+ __require,
216
+ __esm,
217
+ __commonJS,
218
+ __export,
219
+ __toESM,
220
+ __toCommonJS,
221
+ ROOT_NODE_PATH,
222
+ ProjectMapClient,
223
+ UncachedProjectMapClient
224
+ };