@uipath/data-fabric-tool 1.204.0-preview.255 → 1.205.0-preview.256
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/THIRD-PARTY-NOTICES.md +34 -3
- package/dist/entities-inline-9s390vev.js +2777 -0
- package/dist/federated-payload-nfjfj8v9.js +7333 -0
- package/dist/index.js +8 -4
- package/dist/packager-tool-2wp1xwz4.js +101 -0
- package/dist/packager-tool-m0btwdsf.js +884 -0
- package/dist/packager-tool-pz3g5mpk.js +2172 -0
- package/dist/packager-tool-r918t36v.js +2240 -0
- package/dist/{packager-tool-awbse7ws.js → packager-tool-w9r3qa12.js} +7226 -15066
- package/dist/packager-tool-xnrdmg37.js +6410 -0
- package/dist/packager-tool.js +5 -1724
- package/dist/tool.js +6 -3
- package/package.json +2 -2
- package/dist/packager-tool-wq4qexcc.js +0 -239
|
@@ -0,0 +1,2777 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTHORABLE_FIELD_TYPES,
|
|
3
|
+
AuthoredFieldError,
|
|
4
|
+
ENTITY_EXTENSION_CONST,
|
|
5
|
+
ENTITY_RESOURCE_DIR,
|
|
6
|
+
SOLUTION_FOLDER,
|
|
7
|
+
authorField,
|
|
8
|
+
byName,
|
|
9
|
+
collectSolutionEntityNames,
|
|
10
|
+
createEntitySkeleton,
|
|
11
|
+
entityResourcePath,
|
|
12
|
+
findProjectsOwningEntity,
|
|
13
|
+
findSolutionRoot,
|
|
14
|
+
isLocallyAuthored,
|
|
15
|
+
isMissingPathError,
|
|
16
|
+
isSystemField,
|
|
17
|
+
isUnreadablePathError,
|
|
18
|
+
requireAuthoredName,
|
|
19
|
+
serialize,
|
|
20
|
+
siblingNamesFor,
|
|
21
|
+
unwrapResource,
|
|
22
|
+
updateResourceSchema,
|
|
23
|
+
validateEntity,
|
|
24
|
+
verifyPair,
|
|
25
|
+
wrapEntityJson
|
|
26
|
+
} from "./packager-tool-pz3g5mpk.js";
|
|
27
|
+
import {
|
|
28
|
+
fail,
|
|
29
|
+
failInvalidArgument,
|
|
30
|
+
failWithCode,
|
|
31
|
+
readJsonInput,
|
|
32
|
+
requireDestructiveConfirmation
|
|
33
|
+
} from "./packager-tool-2wp1xwz4.js";
|
|
34
|
+
import {
|
|
35
|
+
OutputFormatter,
|
|
36
|
+
RESULTS,
|
|
37
|
+
getFileSystem,
|
|
38
|
+
getSdkUserAgentToken,
|
|
39
|
+
installSdkUserAgentHeader,
|
|
40
|
+
logger,
|
|
41
|
+
processContext,
|
|
42
|
+
quoteForShell,
|
|
43
|
+
unsupportedSolutionProjectType,
|
|
44
|
+
validateFieldsPayload,
|
|
45
|
+
validateSchemaMetadata
|
|
46
|
+
} from "./packager-tool-xnrdmg37.js";
|
|
47
|
+
import {
|
|
48
|
+
catchError,
|
|
49
|
+
validateNameFormat
|
|
50
|
+
} from "./packager-tool-m0btwdsf.js";
|
|
51
|
+
import {
|
|
52
|
+
__commonJS,
|
|
53
|
+
__toESM
|
|
54
|
+
} from "./packager-tool-1de529jm.js";
|
|
55
|
+
|
|
56
|
+
// ../../node_modules/ignore/index.js
|
|
57
|
+
var require_ignore = __commonJS(function(exports, module) {
|
|
58
|
+
function makeArray(subject) {
|
|
59
|
+
return Array.isArray(subject) ? subject : [subject];
|
|
60
|
+
}
|
|
61
|
+
var EMPTY = "";
|
|
62
|
+
var SPACE = " ";
|
|
63
|
+
var ESCAPE = "\\";
|
|
64
|
+
var REGEX_TEST_BLANK_LINE = /^\s+$/;
|
|
65
|
+
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
66
|
+
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
67
|
+
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
68
|
+
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
69
|
+
var REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/;
|
|
70
|
+
var SLASH = "/";
|
|
71
|
+
var TMP_KEY_IGNORE = "node-ignore";
|
|
72
|
+
if (typeof Symbol !== "undefined") {
|
|
73
|
+
TMP_KEY_IGNORE = Symbol.for("node-ignore");
|
|
74
|
+
}
|
|
75
|
+
var KEY_IGNORE = TMP_KEY_IGNORE;
|
|
76
|
+
var define = (object, key, value) => Object.defineProperty(object, key, { value });
|
|
77
|
+
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
|
|
78
|
+
var RETURN_FALSE = () => false;
|
|
79
|
+
var sanitizeRange = (range) => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY);
|
|
80
|
+
var cleanRangeBackSlash = (slashes) => {
|
|
81
|
+
const { length } = slashes;
|
|
82
|
+
return slashes.slice(0, length - length % 2);
|
|
83
|
+
};
|
|
84
|
+
var REPLACERS = [
|
|
85
|
+
[
|
|
86
|
+
/^\uFEFF/,
|
|
87
|
+
() => EMPTY
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
/((?:\\\\)*?)(\\?\s+)$/,
|
|
91
|
+
(_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
/(\\+?)\s/g,
|
|
95
|
+
(_, m1) => {
|
|
96
|
+
const { length } = m1;
|
|
97
|
+
return m1.slice(0, length - length % 2) + SPACE;
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
/[\\$.|*+(){^]/g,
|
|
102
|
+
(match) => `\\${match}`
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
/(?!\\)\?/g,
|
|
106
|
+
() => "[^/]"
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
/^\//,
|
|
110
|
+
() => "^"
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
/\//g,
|
|
114
|
+
() => "\\/"
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
/^\^*\\\*\\\*\\\//,
|
|
118
|
+
() => "^(?:.*\\/)?"
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
/^(?=[^^])/,
|
|
122
|
+
function startingReplacer() {
|
|
123
|
+
return !/\/(?!$)/.test(this) ? "(?:^|\\/)" : "^";
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
128
|
+
(_, index, str) => index + 6 < str.length ? "(?:\\/[^\\/]+)*" : "\\/.+"
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
132
|
+
(_, p1, p2) => {
|
|
133
|
+
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
134
|
+
return p1 + unescaped;
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
[
|
|
138
|
+
/\\\\\\(?=[$.|*+(){^])/g,
|
|
139
|
+
() => ESCAPE
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
/\\\\/g,
|
|
143
|
+
() => ESCAPE
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
/(\\)?\[([^\]/]*?)(\\*)($|\])/g,
|
|
147
|
+
(match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` : close === "]" ? endEscape.length % 2 === 0 ? `[${sanitizeRange(range)}${endEscape}]` : "[]" : "[]"
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
/(?:[^*])$/,
|
|
151
|
+
(match) => /\/$/.test(match) ? `${match}$` : `${match}(?=$|\\/$)`
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
/(\^|\\\/)?\\\*$/,
|
|
155
|
+
(_, p1) => {
|
|
156
|
+
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
157
|
+
return `${prefix}(?=$|\\/$)`;
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
];
|
|
161
|
+
var regexCache = Object.create(null);
|
|
162
|
+
var makeRegex = (pattern, ignoreCase) => {
|
|
163
|
+
let source = regexCache[pattern];
|
|
164
|
+
if (!source) {
|
|
165
|
+
source = REPLACERS.reduce((prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)), pattern);
|
|
166
|
+
regexCache[pattern] = source;
|
|
167
|
+
}
|
|
168
|
+
return ignoreCase ? new RegExp(source, "i") : new RegExp(source);
|
|
169
|
+
};
|
|
170
|
+
var isString = (subject) => typeof subject === "string";
|
|
171
|
+
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
172
|
+
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF);
|
|
173
|
+
|
|
174
|
+
class IgnoreRule {
|
|
175
|
+
constructor(origin, pattern, negative, regex) {
|
|
176
|
+
this.origin = origin;
|
|
177
|
+
this.pattern = pattern;
|
|
178
|
+
this.negative = negative;
|
|
179
|
+
this.regex = regex;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
var createRule = (pattern, ignoreCase) => {
|
|
183
|
+
const origin = pattern;
|
|
184
|
+
let negative = false;
|
|
185
|
+
if (pattern.indexOf("!") === 0) {
|
|
186
|
+
negative = true;
|
|
187
|
+
pattern = pattern.substr(1);
|
|
188
|
+
}
|
|
189
|
+
pattern = pattern.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
190
|
+
const regex = makeRegex(pattern, ignoreCase);
|
|
191
|
+
return new IgnoreRule(origin, pattern, negative, regex);
|
|
192
|
+
};
|
|
193
|
+
var throwError = (message, Ctor) => {
|
|
194
|
+
throw new Ctor(message);
|
|
195
|
+
};
|
|
196
|
+
var checkPath = (path, originalPath, doThrow) => {
|
|
197
|
+
if (!isString(path)) {
|
|
198
|
+
return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
|
|
199
|
+
}
|
|
200
|
+
if (!path) {
|
|
201
|
+
return doThrow(`path must not be empty`, TypeError);
|
|
202
|
+
}
|
|
203
|
+
if (checkPath.isNotRelative(path)) {
|
|
204
|
+
const r = "`path.relative()`d";
|
|
205
|
+
return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError);
|
|
206
|
+
}
|
|
207
|
+
return true;
|
|
208
|
+
};
|
|
209
|
+
var isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
|
|
210
|
+
checkPath.isNotRelative = isNotRelative;
|
|
211
|
+
checkPath.convert = (p) => p;
|
|
212
|
+
|
|
213
|
+
class Ignore {
|
|
214
|
+
constructor({
|
|
215
|
+
ignorecase = true,
|
|
216
|
+
ignoreCase = ignorecase,
|
|
217
|
+
allowRelativePaths = false
|
|
218
|
+
} = {}) {
|
|
219
|
+
define(this, KEY_IGNORE, true);
|
|
220
|
+
this._rules = [];
|
|
221
|
+
this._ignoreCase = ignoreCase;
|
|
222
|
+
this._allowRelativePaths = allowRelativePaths;
|
|
223
|
+
this._initCache();
|
|
224
|
+
}
|
|
225
|
+
_initCache() {
|
|
226
|
+
this._ignoreCache = Object.create(null);
|
|
227
|
+
this._testCache = Object.create(null);
|
|
228
|
+
}
|
|
229
|
+
_addPattern(pattern) {
|
|
230
|
+
if (pattern && pattern[KEY_IGNORE]) {
|
|
231
|
+
this._rules = this._rules.concat(pattern._rules);
|
|
232
|
+
this._added = true;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (checkPattern(pattern)) {
|
|
236
|
+
const rule = createRule(pattern, this._ignoreCase);
|
|
237
|
+
this._added = true;
|
|
238
|
+
this._rules.push(rule);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
add(pattern) {
|
|
242
|
+
this._added = false;
|
|
243
|
+
makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this);
|
|
244
|
+
if (this._added) {
|
|
245
|
+
this._initCache();
|
|
246
|
+
}
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
addPattern(pattern) {
|
|
250
|
+
return this.add(pattern);
|
|
251
|
+
}
|
|
252
|
+
_testOne(path, checkUnignored) {
|
|
253
|
+
let ignored = false;
|
|
254
|
+
let unignored = false;
|
|
255
|
+
this._rules.forEach((rule) => {
|
|
256
|
+
const { negative } = rule;
|
|
257
|
+
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const matched = rule.regex.test(path);
|
|
261
|
+
if (matched) {
|
|
262
|
+
ignored = !negative;
|
|
263
|
+
unignored = negative;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return {
|
|
267
|
+
ignored,
|
|
268
|
+
unignored
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
_test(originalPath, cache, checkUnignored, slices) {
|
|
272
|
+
const path = originalPath && checkPath.convert(originalPath);
|
|
273
|
+
checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
|
|
274
|
+
return this._t(path, cache, checkUnignored, slices);
|
|
275
|
+
}
|
|
276
|
+
_t(path, cache, checkUnignored, slices) {
|
|
277
|
+
if (path in cache) {
|
|
278
|
+
return cache[path];
|
|
279
|
+
}
|
|
280
|
+
if (!slices) {
|
|
281
|
+
slices = path.split(SLASH);
|
|
282
|
+
}
|
|
283
|
+
slices.pop();
|
|
284
|
+
if (!slices.length) {
|
|
285
|
+
return cache[path] = this._testOne(path, checkUnignored);
|
|
286
|
+
}
|
|
287
|
+
const parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
|
|
288
|
+
return cache[path] = parent.ignored ? parent : this._testOne(path, checkUnignored);
|
|
289
|
+
}
|
|
290
|
+
ignores(path) {
|
|
291
|
+
return this._test(path, this._ignoreCache, false).ignored;
|
|
292
|
+
}
|
|
293
|
+
createFilter() {
|
|
294
|
+
return (path) => !this.ignores(path);
|
|
295
|
+
}
|
|
296
|
+
filter(paths) {
|
|
297
|
+
return makeArray(paths).filter(this.createFilter());
|
|
298
|
+
}
|
|
299
|
+
test(path) {
|
|
300
|
+
return this._test(path, this._testCache, true);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
var factory = (options) => new Ignore(options);
|
|
304
|
+
var isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
|
305
|
+
factory.isPathValid = isPathValid;
|
|
306
|
+
factory.default = factory;
|
|
307
|
+
module.exports = factory;
|
|
308
|
+
if (typeof process !== "undefined" && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === "win32")) {
|
|
309
|
+
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
310
|
+
checkPath.convert = makePosix;
|
|
311
|
+
const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
312
|
+
checkPath.isNotRelative = (path) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// ../solution-sdk/generated/src/runtime.ts
|
|
317
|
+
var BASE_PATH = "https://alpha.uipath.com/uipattycyrhx/abizon_1/automationsolutions_".replace(/\/+$/, "");
|
|
318
|
+
|
|
319
|
+
class Configuration {
|
|
320
|
+
configuration;
|
|
321
|
+
constructor(configuration = {}) {
|
|
322
|
+
this.configuration = configuration;
|
|
323
|
+
}
|
|
324
|
+
set config(configuration) {
|
|
325
|
+
this.configuration = configuration;
|
|
326
|
+
}
|
|
327
|
+
get basePath() {
|
|
328
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
329
|
+
}
|
|
330
|
+
get fetchApi() {
|
|
331
|
+
return this.configuration.fetchApi;
|
|
332
|
+
}
|
|
333
|
+
get middleware() {
|
|
334
|
+
return this.configuration.middleware || [];
|
|
335
|
+
}
|
|
336
|
+
get queryParamsStringify() {
|
|
337
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
338
|
+
}
|
|
339
|
+
get username() {
|
|
340
|
+
return this.configuration.username;
|
|
341
|
+
}
|
|
342
|
+
get password() {
|
|
343
|
+
return this.configuration.password;
|
|
344
|
+
}
|
|
345
|
+
get apiKey() {
|
|
346
|
+
const apiKey = this.configuration.apiKey;
|
|
347
|
+
if (apiKey) {
|
|
348
|
+
return typeof apiKey === "function" ? apiKey : () => apiKey;
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
get accessToken() {
|
|
353
|
+
const accessToken = this.configuration.accessToken;
|
|
354
|
+
if (accessToken) {
|
|
355
|
+
return typeof accessToken === "function" ? accessToken : async () => accessToken;
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
get headers() {
|
|
360
|
+
return this.configuration.headers;
|
|
361
|
+
}
|
|
362
|
+
get credentials() {
|
|
363
|
+
return this.configuration.credentials;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
var DefaultConfig = new Configuration;
|
|
367
|
+
|
|
368
|
+
class BaseAPI {
|
|
369
|
+
configuration;
|
|
370
|
+
static jsonRegex = new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$", "i");
|
|
371
|
+
middleware;
|
|
372
|
+
constructor(configuration = DefaultConfig) {
|
|
373
|
+
this.configuration = configuration;
|
|
374
|
+
this.middleware = configuration.middleware;
|
|
375
|
+
}
|
|
376
|
+
withMiddleware(...middlewares) {
|
|
377
|
+
const next = this.clone();
|
|
378
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
379
|
+
return next;
|
|
380
|
+
}
|
|
381
|
+
withPreMiddleware(...preMiddlewares) {
|
|
382
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
383
|
+
return this.withMiddleware(...middlewares);
|
|
384
|
+
}
|
|
385
|
+
withPostMiddleware(...postMiddlewares) {
|
|
386
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
387
|
+
return this.withMiddleware(...middlewares);
|
|
388
|
+
}
|
|
389
|
+
isJsonMime(mime) {
|
|
390
|
+
if (!mime) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
return BaseAPI.jsonRegex.test(mime);
|
|
394
|
+
}
|
|
395
|
+
async request(context, initOverrides) {
|
|
396
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
397
|
+
const response = await this.fetchApi(url, init);
|
|
398
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
399
|
+
return response;
|
|
400
|
+
}
|
|
401
|
+
throw new ResponseError(response, "Response returned an error code");
|
|
402
|
+
}
|
|
403
|
+
async createFetchParams(context, initOverrides) {
|
|
404
|
+
let url = this.configuration.basePath + context.path;
|
|
405
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
406
|
+
url += "?" + this.configuration.queryParamsStringify(context.query);
|
|
407
|
+
}
|
|
408
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
409
|
+
Object.keys(headers).forEach((key) => headers[key] === undefined ? delete headers[key] : {});
|
|
410
|
+
const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides;
|
|
411
|
+
const initParams = {
|
|
412
|
+
method: context.method,
|
|
413
|
+
headers,
|
|
414
|
+
body: context.body,
|
|
415
|
+
credentials: this.configuration.credentials
|
|
416
|
+
};
|
|
417
|
+
const overriddenInit = {
|
|
418
|
+
...initParams,
|
|
419
|
+
...await initOverrideFn({
|
|
420
|
+
init: initParams,
|
|
421
|
+
context
|
|
422
|
+
})
|
|
423
|
+
};
|
|
424
|
+
let body;
|
|
425
|
+
if (isFormData(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob(overriddenInit.body)) {
|
|
426
|
+
body = overriddenInit.body;
|
|
427
|
+
} else if (this.isJsonMime(headers["Content-Type"])) {
|
|
428
|
+
body = JSON.stringify(overriddenInit.body);
|
|
429
|
+
} else {
|
|
430
|
+
body = overriddenInit.body;
|
|
431
|
+
}
|
|
432
|
+
const init = {
|
|
433
|
+
...overriddenInit,
|
|
434
|
+
body
|
|
435
|
+
};
|
|
436
|
+
return { url, init };
|
|
437
|
+
}
|
|
438
|
+
fetchApi = async (url, init) => {
|
|
439
|
+
let fetchParams = { url, init };
|
|
440
|
+
for (const middleware of this.middleware) {
|
|
441
|
+
if (middleware.pre) {
|
|
442
|
+
fetchParams = await middleware.pre({
|
|
443
|
+
fetch: this.fetchApi,
|
|
444
|
+
...fetchParams
|
|
445
|
+
}) || fetchParams;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
let response = undefined;
|
|
449
|
+
try {
|
|
450
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
451
|
+
} catch (e) {
|
|
452
|
+
for (const middleware of this.middleware) {
|
|
453
|
+
if (middleware.onError) {
|
|
454
|
+
response = await middleware.onError({
|
|
455
|
+
fetch: this.fetchApi,
|
|
456
|
+
url: fetchParams.url,
|
|
457
|
+
init: fetchParams.init,
|
|
458
|
+
error: e,
|
|
459
|
+
response: response ? response.clone() : undefined
|
|
460
|
+
}) || response;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (response === undefined) {
|
|
464
|
+
if (e instanceof Error) {
|
|
465
|
+
throw new FetchError(e, "The request failed and the interceptors did not return an alternative response");
|
|
466
|
+
} else {
|
|
467
|
+
throw e;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
for (const middleware of this.middleware) {
|
|
472
|
+
if (middleware.post) {
|
|
473
|
+
response = await middleware.post({
|
|
474
|
+
fetch: this.fetchApi,
|
|
475
|
+
url: fetchParams.url,
|
|
476
|
+
init: fetchParams.init,
|
|
477
|
+
response: response.clone()
|
|
478
|
+
}) || response;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return response;
|
|
482
|
+
};
|
|
483
|
+
clone() {
|
|
484
|
+
const constructor = this.constructor;
|
|
485
|
+
const next = new constructor(this.configuration);
|
|
486
|
+
next.middleware = this.middleware.slice();
|
|
487
|
+
return next;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function isBlob(value) {
|
|
491
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
492
|
+
}
|
|
493
|
+
function isFormData(value) {
|
|
494
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
class ResponseError extends Error {
|
|
498
|
+
response;
|
|
499
|
+
name = "ResponseError";
|
|
500
|
+
constructor(response, msg) {
|
|
501
|
+
super(msg);
|
|
502
|
+
this.response = response;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
class FetchError extends Error {
|
|
507
|
+
cause;
|
|
508
|
+
name = "FetchError";
|
|
509
|
+
constructor(cause, msg) {
|
|
510
|
+
super(msg);
|
|
511
|
+
this.cause = cause;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function querystring(params, prefix = "") {
|
|
515
|
+
return Object.keys(params).map((key) => querystringSingleKey(key, params[key], prefix)).filter((part) => part.length > 0).join("&");
|
|
516
|
+
}
|
|
517
|
+
function querystringSingleKey(key, value, keyPrefix = "") {
|
|
518
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
519
|
+
if (value instanceof Array) {
|
|
520
|
+
const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`);
|
|
521
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
522
|
+
}
|
|
523
|
+
if (value instanceof Set) {
|
|
524
|
+
const valueAsArray = Array.from(value);
|
|
525
|
+
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
|
526
|
+
}
|
|
527
|
+
if (value instanceof Date) {
|
|
528
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
529
|
+
}
|
|
530
|
+
if (value instanceof Object) {
|
|
531
|
+
return querystring(value, fullKey);
|
|
532
|
+
}
|
|
533
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
534
|
+
}
|
|
535
|
+
// ../solution-sdk/package.json
|
|
536
|
+
var package_default = {
|
|
537
|
+
name: "@uipath/solution-sdk",
|
|
538
|
+
author: "UiPath",
|
|
539
|
+
license: "SEE LICENSE IN LICENSE.txt",
|
|
540
|
+
version: "1.205.0-preview.256",
|
|
541
|
+
repository: {
|
|
542
|
+
type: "git",
|
|
543
|
+
url: "https://github.com/UiPath/cli.git",
|
|
544
|
+
directory: "packages/solution-sdk"
|
|
545
|
+
},
|
|
546
|
+
publishConfig: {
|
|
547
|
+
registry: "https://npm.pkg.github.com/@uipath"
|
|
548
|
+
},
|
|
549
|
+
keywords: [
|
|
550
|
+
"uipath",
|
|
551
|
+
"solution",
|
|
552
|
+
"sdk"
|
|
553
|
+
],
|
|
554
|
+
type: "module",
|
|
555
|
+
main: "./dist/index.js",
|
|
556
|
+
types: "./dist/src/index.d.ts",
|
|
557
|
+
exports: {
|
|
558
|
+
".": {
|
|
559
|
+
types: "./dist/src/index.d.ts",
|
|
560
|
+
default: "./dist/index.js"
|
|
561
|
+
},
|
|
562
|
+
"./resources": {
|
|
563
|
+
types: "./dist/src/resources/index.d.ts",
|
|
564
|
+
default: "./dist/resources/index.js"
|
|
565
|
+
},
|
|
566
|
+
"./auth": {
|
|
567
|
+
types: "./dist/src/solution-auth.d.ts",
|
|
568
|
+
default: "./dist/solution-auth.js"
|
|
569
|
+
},
|
|
570
|
+
"./deployments": {
|
|
571
|
+
types: "./dist/src/deployment-search.d.ts",
|
|
572
|
+
default: "./dist/deployment-search.js"
|
|
573
|
+
},
|
|
574
|
+
"./packages": {
|
|
575
|
+
types: "./dist/src/package-search.d.ts",
|
|
576
|
+
default: "./dist/package-search.js"
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
bin: {
|
|
580
|
+
"generate-sdk": "./dist/scripts/generate-sdk.js"
|
|
581
|
+
},
|
|
582
|
+
files: [
|
|
583
|
+
"dist"
|
|
584
|
+
],
|
|
585
|
+
private: false,
|
|
586
|
+
scripts: {
|
|
587
|
+
build: "bun build ./src/index.ts ./src/resources/index.ts ./src/solution-auth.ts ./src/deployment-search.ts ./src/package-search.ts --outdir dist --format esm --target node --splitting --sourcemap=linked && bun build ./src/scripts/generate-sdk.ts --outdir dist/scripts --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
|
|
588
|
+
generate: "bun run src/scripts/generate-sdk.ts",
|
|
589
|
+
lint: "biome check .",
|
|
590
|
+
test: "vitest run",
|
|
591
|
+
"test:coverage": "vitest run --coverage"
|
|
592
|
+
},
|
|
593
|
+
devDependencies: {
|
|
594
|
+
"@openapitools/openapi-generator-cli": "^2.31.1",
|
|
595
|
+
"@uipath/auth": "workspace:*",
|
|
596
|
+
"@uipath/common": "workspace:*",
|
|
597
|
+
"@uipath/filesystem": "workspace:*",
|
|
598
|
+
"@uipath/orchestrator-sdk": "workspace:*",
|
|
599
|
+
"@uipath/pipelines-sdk": "workspace:*",
|
|
600
|
+
"@uipath/resource-builder-sdk": "2025.11.0-alpha6584-4367",
|
|
601
|
+
"@uipath/solutionpackager-tool-core": "workspace:*",
|
|
602
|
+
"@uipath/studioweb-sdk": "workspace:*",
|
|
603
|
+
"@types/node": "^25.5.2",
|
|
604
|
+
fflate: "^0.8.2",
|
|
605
|
+
ignore: "^5.3.2",
|
|
606
|
+
typescript: "^7.0.2"
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
// ../solution-sdk/src/user-agent.ts
|
|
611
|
+
var SDK_USER_AGENT = getSdkUserAgentToken(package_default);
|
|
612
|
+
installSdkUserAgentHeader(BaseAPI, SDK_USER_AGENT);
|
|
613
|
+
|
|
614
|
+
// ../studioweb-sdk/generated/src/runtime.ts
|
|
615
|
+
var BASE_PATH2 = "https://alpha.uipath.com/studio_/backend".replace(/\/+$/, "");
|
|
616
|
+
|
|
617
|
+
class Configuration2 {
|
|
618
|
+
configuration;
|
|
619
|
+
constructor(configuration = {}) {
|
|
620
|
+
this.configuration = configuration;
|
|
621
|
+
}
|
|
622
|
+
set config(configuration) {
|
|
623
|
+
this.configuration = configuration;
|
|
624
|
+
}
|
|
625
|
+
get basePath() {
|
|
626
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH2;
|
|
627
|
+
}
|
|
628
|
+
get fetchApi() {
|
|
629
|
+
return this.configuration.fetchApi;
|
|
630
|
+
}
|
|
631
|
+
get middleware() {
|
|
632
|
+
return this.configuration.middleware || [];
|
|
633
|
+
}
|
|
634
|
+
get queryParamsStringify() {
|
|
635
|
+
return this.configuration.queryParamsStringify || querystring2;
|
|
636
|
+
}
|
|
637
|
+
get username() {
|
|
638
|
+
return this.configuration.username;
|
|
639
|
+
}
|
|
640
|
+
get password() {
|
|
641
|
+
return this.configuration.password;
|
|
642
|
+
}
|
|
643
|
+
get apiKey() {
|
|
644
|
+
const apiKey = this.configuration.apiKey;
|
|
645
|
+
if (apiKey) {
|
|
646
|
+
return typeof apiKey === "function" ? apiKey : () => apiKey;
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
get accessToken() {
|
|
651
|
+
const accessToken = this.configuration.accessToken;
|
|
652
|
+
if (accessToken) {
|
|
653
|
+
return typeof accessToken === "function" ? accessToken : async () => accessToken;
|
|
654
|
+
}
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
get headers() {
|
|
658
|
+
return this.configuration.headers;
|
|
659
|
+
}
|
|
660
|
+
get credentials() {
|
|
661
|
+
return this.configuration.credentials;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
var DefaultConfig2 = new Configuration2;
|
|
665
|
+
|
|
666
|
+
class BaseAPI2 {
|
|
667
|
+
configuration;
|
|
668
|
+
static jsonRegex = new RegExp("^(:?application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$", "i");
|
|
669
|
+
middleware;
|
|
670
|
+
constructor(configuration = DefaultConfig2) {
|
|
671
|
+
this.configuration = configuration;
|
|
672
|
+
this.middleware = configuration.middleware;
|
|
673
|
+
}
|
|
674
|
+
withMiddleware(...middlewares) {
|
|
675
|
+
const next = this.clone();
|
|
676
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
677
|
+
return next;
|
|
678
|
+
}
|
|
679
|
+
withPreMiddleware(...preMiddlewares) {
|
|
680
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
681
|
+
return this.withMiddleware(...middlewares);
|
|
682
|
+
}
|
|
683
|
+
withPostMiddleware(...postMiddlewares) {
|
|
684
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
685
|
+
return this.withMiddleware(...middlewares);
|
|
686
|
+
}
|
|
687
|
+
isJsonMime(mime) {
|
|
688
|
+
if (!mime) {
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
return BaseAPI2.jsonRegex.test(mime);
|
|
692
|
+
}
|
|
693
|
+
async request(context, initOverrides) {
|
|
694
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
695
|
+
const response = await this.fetchApi(url, init);
|
|
696
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
697
|
+
return response;
|
|
698
|
+
}
|
|
699
|
+
throw new ResponseError2(response, "Response returned an error code");
|
|
700
|
+
}
|
|
701
|
+
async createFetchParams(context, initOverrides) {
|
|
702
|
+
let url = this.configuration.basePath + context.path;
|
|
703
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
704
|
+
url += "?" + this.configuration.queryParamsStringify(context.query);
|
|
705
|
+
}
|
|
706
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
707
|
+
Object.keys(headers).forEach((key) => headers[key] === undefined ? delete headers[key] : {});
|
|
708
|
+
const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides;
|
|
709
|
+
const initParams = {
|
|
710
|
+
method: context.method,
|
|
711
|
+
headers,
|
|
712
|
+
body: context.body,
|
|
713
|
+
credentials: this.configuration.credentials
|
|
714
|
+
};
|
|
715
|
+
const overriddenInit = {
|
|
716
|
+
...initParams,
|
|
717
|
+
...await initOverrideFn({
|
|
718
|
+
init: initParams,
|
|
719
|
+
context
|
|
720
|
+
})
|
|
721
|
+
};
|
|
722
|
+
let body;
|
|
723
|
+
if (isFormData2(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob2(overriddenInit.body)) {
|
|
724
|
+
body = overriddenInit.body;
|
|
725
|
+
} else if (this.isJsonMime(headers["Content-Type"])) {
|
|
726
|
+
body = JSON.stringify(overriddenInit.body);
|
|
727
|
+
} else {
|
|
728
|
+
body = overriddenInit.body;
|
|
729
|
+
}
|
|
730
|
+
const init = {
|
|
731
|
+
...overriddenInit,
|
|
732
|
+
body
|
|
733
|
+
};
|
|
734
|
+
return { url, init };
|
|
735
|
+
}
|
|
736
|
+
fetchApi = async (url, init) => {
|
|
737
|
+
let fetchParams = { url, init };
|
|
738
|
+
for (const middleware of this.middleware) {
|
|
739
|
+
if (middleware.pre) {
|
|
740
|
+
fetchParams = await middleware.pre({
|
|
741
|
+
fetch: this.fetchApi,
|
|
742
|
+
...fetchParams
|
|
743
|
+
}) || fetchParams;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
let response = undefined;
|
|
747
|
+
try {
|
|
748
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
749
|
+
} catch (e) {
|
|
750
|
+
for (const middleware of this.middleware) {
|
|
751
|
+
if (middleware.onError) {
|
|
752
|
+
response = await middleware.onError({
|
|
753
|
+
fetch: this.fetchApi,
|
|
754
|
+
url: fetchParams.url,
|
|
755
|
+
init: fetchParams.init,
|
|
756
|
+
error: e,
|
|
757
|
+
response: response ? response.clone() : undefined
|
|
758
|
+
}) || response;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (response === undefined) {
|
|
762
|
+
if (e instanceof Error) {
|
|
763
|
+
throw new FetchError2(e, "The request failed and the interceptors did not return an alternative response");
|
|
764
|
+
} else {
|
|
765
|
+
throw e;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
for (const middleware of this.middleware) {
|
|
770
|
+
if (middleware.post) {
|
|
771
|
+
response = await middleware.post({
|
|
772
|
+
fetch: this.fetchApi,
|
|
773
|
+
url: fetchParams.url,
|
|
774
|
+
init: fetchParams.init,
|
|
775
|
+
response: response.clone()
|
|
776
|
+
}) || response;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return response;
|
|
780
|
+
};
|
|
781
|
+
clone() {
|
|
782
|
+
const constructor = this.constructor;
|
|
783
|
+
const next = new constructor(this.configuration);
|
|
784
|
+
next.middleware = this.middleware.slice();
|
|
785
|
+
return next;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
function isBlob2(value) {
|
|
789
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
790
|
+
}
|
|
791
|
+
function isFormData2(value) {
|
|
792
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
class ResponseError2 extends Error {
|
|
796
|
+
response;
|
|
797
|
+
name = "ResponseError";
|
|
798
|
+
constructor(response, msg) {
|
|
799
|
+
super(msg);
|
|
800
|
+
this.response = response;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
class FetchError2 extends Error {
|
|
805
|
+
cause;
|
|
806
|
+
name = "FetchError";
|
|
807
|
+
constructor(cause, msg) {
|
|
808
|
+
super(msg);
|
|
809
|
+
this.cause = cause;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function querystring2(params, prefix = "") {
|
|
813
|
+
return Object.keys(params).map((key) => querystringSingleKey2(key, params[key], prefix)).filter((part) => part.length > 0).join("&");
|
|
814
|
+
}
|
|
815
|
+
function querystringSingleKey2(key, value, keyPrefix = "") {
|
|
816
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
817
|
+
if (value instanceof Array) {
|
|
818
|
+
const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`);
|
|
819
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
820
|
+
}
|
|
821
|
+
if (value instanceof Set) {
|
|
822
|
+
const valueAsArray = Array.from(value);
|
|
823
|
+
return querystringSingleKey2(key, valueAsArray, keyPrefix);
|
|
824
|
+
}
|
|
825
|
+
if (value instanceof Date) {
|
|
826
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
827
|
+
}
|
|
828
|
+
if (value instanceof Object) {
|
|
829
|
+
return querystring2(value, fullKey);
|
|
830
|
+
}
|
|
831
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
832
|
+
}
|
|
833
|
+
// ../solution-sdk/src/solution-file.ts
|
|
834
|
+
var STUDIO_WEB_PROJECT_TYPE_OVERRIDES = {
|
|
835
|
+
ProcessOrchestration: "processOrchestration"
|
|
836
|
+
};
|
|
837
|
+
function normalizeProjectType(projectType) {
|
|
838
|
+
return STUDIO_WEB_PROJECT_TYPE_OVERRIDES[projectType] ?? projectType;
|
|
839
|
+
}
|
|
840
|
+
function toPortableRelativePath(relativePath) {
|
|
841
|
+
return relativePath.replace(/\\/g, "/");
|
|
842
|
+
}
|
|
843
|
+
function isRecord(value) {
|
|
844
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
845
|
+
}
|
|
846
|
+
async function createSolutionManifest(fs, solutionDir, solutionName, options = {}) {
|
|
847
|
+
const resolvedDir = fs.path.resolve(solutionDir);
|
|
848
|
+
if (!(options.allowExistingDir && await fs.exists(resolvedDir))) {
|
|
849
|
+
await fs.mkdir(resolvedDir);
|
|
850
|
+
}
|
|
851
|
+
const solutionId = crypto.randomUUID();
|
|
852
|
+
const manifest = {
|
|
853
|
+
DocVersion: "1.0.0",
|
|
854
|
+
StudioMinVersion: "2025.10.0",
|
|
855
|
+
SolutionId: solutionId,
|
|
856
|
+
Projects: []
|
|
857
|
+
};
|
|
858
|
+
const solutionFile = fs.path.join(resolvedDir, `${solutionName}.uipx`);
|
|
859
|
+
await fs.writeFile(solutionFile, `${JSON.stringify(manifest, null, 2)}
|
|
860
|
+
`);
|
|
861
|
+
return {
|
|
862
|
+
solutionDir: resolvedDir,
|
|
863
|
+
solutionFile,
|
|
864
|
+
solutionId
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
var AUTO_SOLUTION_SUFFIX = "Solution";
|
|
868
|
+
async function autoScaffoldSolution(fs, baseDir, projectName) {
|
|
869
|
+
const solutionName = `${projectName}${AUTO_SOLUTION_SUFFIX}`;
|
|
870
|
+
const solutionDir = fs.path.resolve(baseDir, solutionName);
|
|
871
|
+
const expectedSolutionFile = fs.path.join(solutionDir, `${solutionName}.uipx`);
|
|
872
|
+
if (await fs.exists(expectedSolutionFile)) {
|
|
873
|
+
return {
|
|
874
|
+
Name: solutionName,
|
|
875
|
+
Path: solutionDir,
|
|
876
|
+
SolutionFile: expectedSolutionFile
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
const { solutionFile } = await createSolutionManifest(fs, solutionDir, solutionName, { allowExistingDir: true });
|
|
880
|
+
return {
|
|
881
|
+
Name: solutionName,
|
|
882
|
+
Path: solutionDir,
|
|
883
|
+
SolutionFile: solutionFile
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
async function prepareProjectLocation(fs, candidateProjectDir, projectName, options = {}) {
|
|
887
|
+
const resolved = fs.path.resolve(candidateProjectDir);
|
|
888
|
+
if (options.skipRegistration) {
|
|
889
|
+
return { projectDir: resolved };
|
|
890
|
+
}
|
|
891
|
+
const discovery = await findNearestParentUipxFile(fs, resolved);
|
|
892
|
+
if (discovery.status !== "notFound") {
|
|
893
|
+
return { projectDir: resolved };
|
|
894
|
+
}
|
|
895
|
+
const baseDir = fs.path.dirname(resolved);
|
|
896
|
+
const autoCreatedSolution = await autoScaffoldSolution(fs, baseDir, projectName);
|
|
897
|
+
const projectDir = fs.path.join(autoCreatedSolution.Path, projectName);
|
|
898
|
+
await warnIfCandidateDirShadowed(fs, resolved, projectDir);
|
|
899
|
+
return { projectDir, autoCreatedSolution };
|
|
900
|
+
}
|
|
901
|
+
async function warnIfCandidateDirShadowed(fs, candidateDir, projectDir) {
|
|
902
|
+
const [, exists] = await catchError(fs.exists(candidateDir));
|
|
903
|
+
if (!exists) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
const [, entries] = await catchError(fs.readdir(candidateDir));
|
|
907
|
+
if (!entries || entries.length === 0) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
logger.warn(`An existing directory "${candidateDir}" was left untouched. ` + `The project was created inside the auto-created solution at "${projectDir}". ` + "Run init from inside an existing solution, or pass --skip-solution-registration, if you meant to use the existing directory.");
|
|
911
|
+
}
|
|
912
|
+
async function tryRegisterProjectInParentSolution(fs, projectDir, options) {
|
|
913
|
+
if (options?.skipRegistration) {
|
|
914
|
+
return {
|
|
915
|
+
Status: "OptedOut",
|
|
916
|
+
Message: "Solution auto-registration skipped (--skip-solution-registration).",
|
|
917
|
+
Instructions: buildOptedOutInstructions(fs.path.resolve(projectDir))
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
const [registrationError, registration] = await catchError(registerProjectInParentSolution(fs, projectDir));
|
|
921
|
+
if (registrationError) {
|
|
922
|
+
return {
|
|
923
|
+
Status: "Failed",
|
|
924
|
+
Message: "Project registration failed.",
|
|
925
|
+
Instructions: buildRegistrationFailureInstructions(projectDir, registrationError.message)
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
return registration;
|
|
929
|
+
}
|
|
930
|
+
async function registerProjectInParentSolution(fs, projectDir) {
|
|
931
|
+
const resolvedProjectDir = fs.path.resolve(projectDir);
|
|
932
|
+
const discovery = await findNearestParentUipxFile(fs, resolvedProjectDir);
|
|
933
|
+
if (discovery.status === "notFound") {
|
|
934
|
+
return {
|
|
935
|
+
Status: "NotInSolution",
|
|
936
|
+
Message: "Project created in standalone mode; no parent .uipx solution found.",
|
|
937
|
+
Instructions: buildStandaloneInstructions(resolvedProjectDir)
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
if (discovery.status === "skipped") {
|
|
941
|
+
return discovery.registration;
|
|
942
|
+
}
|
|
943
|
+
const solutionFile = discovery.solutionFile;
|
|
944
|
+
const solutionDir = fs.path.dirname(solutionFile);
|
|
945
|
+
const relativeProjectDir = fs.path.relative(solutionDir, resolvedProjectDir);
|
|
946
|
+
if (relativeProjectDir === "" || relativeProjectDir.startsWith("..") || fs.path.isAbsolute(relativeProjectDir)) {
|
|
947
|
+
return {
|
|
948
|
+
Status: "Skipped",
|
|
949
|
+
Message: "Project registration skipped.",
|
|
950
|
+
Solution: solutionFile,
|
|
951
|
+
Instructions: `Project must reside within the solution folder.
|
|
952
|
+
Solution: ${solutionDir}
|
|
953
|
+
Project: ${resolvedProjectDir}`
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
const [projectFileError, projectFile] = await findProjectFile(fs, resolvedProjectDir);
|
|
957
|
+
if (projectFileError) {
|
|
958
|
+
return {
|
|
959
|
+
Status: "Failed",
|
|
960
|
+
Message: "Project registration failed.",
|
|
961
|
+
Solution: solutionFile,
|
|
962
|
+
Instructions: buildRegistrationFailureInstructions(resolvedProjectDir, projectFileError.message)
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
const [projectManifestError, projectManifest] = await readProjectManifest(fs, projectFile.filePath, projectFile.useProjectJson);
|
|
966
|
+
if (projectManifestError) {
|
|
967
|
+
return {
|
|
968
|
+
Status: "Failed",
|
|
969
|
+
Message: "Project registration failed.",
|
|
970
|
+
Solution: solutionFile,
|
|
971
|
+
Instructions: buildRegistrationFailureInstructions(resolvedProjectDir, projectManifestError.message)
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
const unsupportedReason = unsupportedSolutionProjectType(projectManifest.projectType);
|
|
975
|
+
if (unsupportedReason) {
|
|
976
|
+
return {
|
|
977
|
+
Status: "Skipped",
|
|
978
|
+
Message: "Project registration skipped.",
|
|
979
|
+
Solution: solutionFile,
|
|
980
|
+
Instructions: unsupportedReason
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
const projectRelativePath = toPortableRelativePath(fs.path.join(relativeProjectDir, projectFile.fileName));
|
|
984
|
+
const [solutionError, solution] = await readSolutionManifest(fs, solutionFile);
|
|
985
|
+
if (solutionError) {
|
|
986
|
+
return {
|
|
987
|
+
Status: "Failed",
|
|
988
|
+
Message: "Project registration failed.",
|
|
989
|
+
Solution: solutionFile,
|
|
990
|
+
Project: projectRelativePath,
|
|
991
|
+
Instructions: buildRegistrationFailureInstructions(resolvedProjectDir, solutionError.message)
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
const existingProject = solution.projects.find((project) => toPortableRelativePath(project.ProjectRelativePath) === projectRelativePath);
|
|
995
|
+
if (existingProject) {
|
|
996
|
+
return {
|
|
997
|
+
Status: "AlreadyRegistered",
|
|
998
|
+
Message: "Project already registered in solution.",
|
|
999
|
+
Solution: solutionFile,
|
|
1000
|
+
Project: projectRelativePath,
|
|
1001
|
+
ProjectId: typeof existingProject.Id === "string" ? existingProject.Id : undefined,
|
|
1002
|
+
Instructions: buildRegistrationSuccessInstructions(solutionDir)
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
const projectId = crypto.randomUUID();
|
|
1006
|
+
solution.projects.push({
|
|
1007
|
+
Type: normalizeProjectType(projectManifest.projectType),
|
|
1008
|
+
ProjectRelativePath: projectRelativePath,
|
|
1009
|
+
Id: projectId
|
|
1010
|
+
});
|
|
1011
|
+
solution.content.Projects = solution.projects;
|
|
1012
|
+
const [writeError] = await catchError(fs.writeFile(solutionFile, `${JSON.stringify(solution.content, null, 2)}
|
|
1013
|
+
`));
|
|
1014
|
+
if (writeError) {
|
|
1015
|
+
return {
|
|
1016
|
+
Status: "Failed",
|
|
1017
|
+
Message: "Project registration failed.",
|
|
1018
|
+
Solution: solutionFile,
|
|
1019
|
+
Project: projectRelativePath,
|
|
1020
|
+
Instructions: buildRegistrationFailureInstructions(resolvedProjectDir, writeError.message)
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
return {
|
|
1024
|
+
Status: "Registered",
|
|
1025
|
+
Message: "Project registered in parent solution.",
|
|
1026
|
+
Solution: solutionFile,
|
|
1027
|
+
Project: projectRelativePath,
|
|
1028
|
+
ProjectId: projectId,
|
|
1029
|
+
Instructions: buildRegistrationSuccessInstructions(solutionDir)
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
async function findNearestParentUipxFile(fs, projectDir) {
|
|
1033
|
+
let currentDir = fs.path.dirname(fs.path.resolve(projectDir));
|
|
1034
|
+
while (true) {
|
|
1035
|
+
const [readDirError, entries] = await catchError(fs.readdir(currentDir));
|
|
1036
|
+
if (readDirError) {
|
|
1037
|
+
return {
|
|
1038
|
+
status: "skipped",
|
|
1039
|
+
registration: {
|
|
1040
|
+
Status: "Failed",
|
|
1041
|
+
Message: "Project registration failed.",
|
|
1042
|
+
Instructions: buildRegistrationFailureInstructions(projectDir, `Could not inspect parent directory for a solution: ${currentDir}
|
|
1043
|
+
${readDirError.message}`)
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
const solutionFiles = entries.filter((entry) => entry.endsWith(".uipx"));
|
|
1048
|
+
if (solutionFiles.length > 1) {
|
|
1049
|
+
return {
|
|
1050
|
+
status: "skipped",
|
|
1051
|
+
registration: {
|
|
1052
|
+
Status: "Skipped",
|
|
1053
|
+
Message: "Project registration skipped.",
|
|
1054
|
+
Instructions: `Found multiple .uipx files in ${currentDir}: ${solutionFiles.join(", ")}. Run 'uip solution projects add "${projectDir}" <solution.uipx>' to choose one.`
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
if (solutionFiles.length === 1) {
|
|
1059
|
+
return {
|
|
1060
|
+
status: "found",
|
|
1061
|
+
solutionFile: fs.path.join(currentDir, solutionFiles[0])
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
const parentDir = fs.path.dirname(currentDir);
|
|
1065
|
+
if (parentDir === currentDir) {
|
|
1066
|
+
return { status: "notFound" };
|
|
1067
|
+
}
|
|
1068
|
+
currentDir = parentDir;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
async function findProjectFile(fs, projectDir) {
|
|
1072
|
+
const uiprojPath = fs.path.join(projectDir, "project.uiproj");
|
|
1073
|
+
if (await fs.exists(uiprojPath)) {
|
|
1074
|
+
return [
|
|
1075
|
+
null,
|
|
1076
|
+
{
|
|
1077
|
+
filePath: uiprojPath,
|
|
1078
|
+
fileName: "project.uiproj",
|
|
1079
|
+
useProjectJson: false
|
|
1080
|
+
}
|
|
1081
|
+
];
|
|
1082
|
+
}
|
|
1083
|
+
const jsonProjectPath = fs.path.join(projectDir, "project.json");
|
|
1084
|
+
if (await fs.exists(jsonProjectPath)) {
|
|
1085
|
+
return [
|
|
1086
|
+
null,
|
|
1087
|
+
{
|
|
1088
|
+
filePath: jsonProjectPath,
|
|
1089
|
+
fileName: "project.json",
|
|
1090
|
+
useProjectJson: true
|
|
1091
|
+
}
|
|
1092
|
+
];
|
|
1093
|
+
}
|
|
1094
|
+
return [
|
|
1095
|
+
new Error(`No project file found in ${projectDir}. Expected project.uiproj or project.json.`),
|
|
1096
|
+
null
|
|
1097
|
+
];
|
|
1098
|
+
}
|
|
1099
|
+
async function readProjectManifest(fs, filePath, useProjectJson) {
|
|
1100
|
+
const [readError, rawContent] = await catchError(fs.readFile(filePath, "utf-8"));
|
|
1101
|
+
if (readError || !rawContent) {
|
|
1102
|
+
return [readError ?? new Error(`Unable to read ${filePath}.`), null];
|
|
1103
|
+
}
|
|
1104
|
+
const [parseError, parsed] = catchError(() => JSON.parse(rawContent));
|
|
1105
|
+
if (parseError) {
|
|
1106
|
+
return [
|
|
1107
|
+
new Error(`Invalid JSON in project file: ${parseError.message}`),
|
|
1108
|
+
null
|
|
1109
|
+
];
|
|
1110
|
+
}
|
|
1111
|
+
if (!isRecord(parsed)) {
|
|
1112
|
+
return [new Error(`Invalid project file: ${filePath}`), null];
|
|
1113
|
+
}
|
|
1114
|
+
const designOptions = parsed.designOptions;
|
|
1115
|
+
const outputType = useProjectJson && isRecord(designOptions) ? readString(designOptions.outputType) : undefined;
|
|
1116
|
+
const projectType = outputType ?? readString(parsed.ProjectType);
|
|
1117
|
+
if (!projectType) {
|
|
1118
|
+
return [new Error(`ProjectType not found in ${filePath}`), null];
|
|
1119
|
+
}
|
|
1120
|
+
return [
|
|
1121
|
+
null,
|
|
1122
|
+
{
|
|
1123
|
+
projectType
|
|
1124
|
+
}
|
|
1125
|
+
];
|
|
1126
|
+
}
|
|
1127
|
+
async function readSolutionManifest(fs, solutionFile) {
|
|
1128
|
+
const [readError, rawContent] = await catchError(fs.readFile(solutionFile, "utf-8"));
|
|
1129
|
+
if (readError || !rawContent) {
|
|
1130
|
+
return [
|
|
1131
|
+
readError ?? new Error(`Unable to read solution file: ${solutionFile}`),
|
|
1132
|
+
null
|
|
1133
|
+
];
|
|
1134
|
+
}
|
|
1135
|
+
const [parseError, parsed] = catchError(() => JSON.parse(rawContent));
|
|
1136
|
+
if (parseError) {
|
|
1137
|
+
return [
|
|
1138
|
+
new Error(`Invalid JSON in solution file: ${parseError.message}`),
|
|
1139
|
+
null
|
|
1140
|
+
];
|
|
1141
|
+
}
|
|
1142
|
+
if (!isRecord(parsed)) {
|
|
1143
|
+
return [
|
|
1144
|
+
new Error(`Invalid solution file: ${solutionFile} must contain a JSON object.`),
|
|
1145
|
+
null
|
|
1146
|
+
];
|
|
1147
|
+
}
|
|
1148
|
+
if (!Array.isArray(parsed.Projects)) {
|
|
1149
|
+
return [
|
|
1150
|
+
new Error(`Invalid solution file: ${solutionFile} must contain a Projects array.`),
|
|
1151
|
+
null
|
|
1152
|
+
];
|
|
1153
|
+
}
|
|
1154
|
+
const projects = [];
|
|
1155
|
+
for (const [index, project] of parsed.Projects.entries()) {
|
|
1156
|
+
if (!isRecord(project)) {
|
|
1157
|
+
return [
|
|
1158
|
+
new Error(`Invalid solution file: Projects[${index}] must be an object.`),
|
|
1159
|
+
null
|
|
1160
|
+
];
|
|
1161
|
+
}
|
|
1162
|
+
const projectRelativePath = readString(project.ProjectRelativePath);
|
|
1163
|
+
if (!projectRelativePath) {
|
|
1164
|
+
return [
|
|
1165
|
+
new Error(`Invalid solution file: Projects[${index}] is missing ProjectRelativePath. Use 'uip solution projects add' to repair the manifest.`),
|
|
1166
|
+
null
|
|
1167
|
+
];
|
|
1168
|
+
}
|
|
1169
|
+
projects.push({
|
|
1170
|
+
...project,
|
|
1171
|
+
Type: readString(project.Type) ?? "",
|
|
1172
|
+
ProjectRelativePath: projectRelativePath,
|
|
1173
|
+
Id: readString(project.Id) ?? ""
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
return [null, { content: parsed, projects }];
|
|
1177
|
+
}
|
|
1178
|
+
function readString(value) {
|
|
1179
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
1180
|
+
}
|
|
1181
|
+
function buildRegistrationSuccessInstructions(solutionDir) {
|
|
1182
|
+
return [
|
|
1183
|
+
"The project is listed in the parent solution manifest.",
|
|
1184
|
+
"Packing or uploading the solution will sync solution resources automatically.",
|
|
1185
|
+
`To sync resources before packaging, run: uip solution resources refresh --solution-folder ${quoteForShell(solutionDir)}`
|
|
1186
|
+
].join(`
|
|
1187
|
+
`);
|
|
1188
|
+
}
|
|
1189
|
+
function buildRegistrationFailureInstructions(projectDir, details) {
|
|
1190
|
+
return [
|
|
1191
|
+
"Automatic solution registration could not complete.",
|
|
1192
|
+
`Run 'uip solution projects add "${projectDir}" <solution.uipx>' after checking the project and solution files.`,
|
|
1193
|
+
`Details: ${details}`
|
|
1194
|
+
].join(`
|
|
1195
|
+
`);
|
|
1196
|
+
}
|
|
1197
|
+
function buildStandaloneInstructions(projectDir) {
|
|
1198
|
+
return [
|
|
1199
|
+
"No parent solution was found by walking ancestor directories.",
|
|
1200
|
+
"Studio Web upload, `flow debug`, and packaging require an enclosing solution.",
|
|
1201
|
+
`To link this project to a solution, run 'uip solution init "<SolutionName>"' then 'uip solution projects add "${projectDir}" <SolutionName>.uipx'.`
|
|
1202
|
+
].join(`
|
|
1203
|
+
`);
|
|
1204
|
+
}
|
|
1205
|
+
function buildOptedOutInstructions(projectDir) {
|
|
1206
|
+
return [
|
|
1207
|
+
"Automatic solution registration was skipped because --skip-solution-registration was passed.",
|
|
1208
|
+
`To register this project later, run 'uip solution projects add "${projectDir}" <SolutionName>.uipx' from within the solution.`
|
|
1209
|
+
].join(`
|
|
1210
|
+
`);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// ../solution-sdk/src/studio-web-compat.ts
|
|
1214
|
+
var API_PROJECT_TYPES = new Set(["api", "apiautomation"]);
|
|
1215
|
+
|
|
1216
|
+
// ../solution-sdk/src/zip-utils.ts
|
|
1217
|
+
var import_ignore = __toESM(require_ignore(), 1);
|
|
1218
|
+
var DEFAULT_EXCLUDED_DIR_NAMES = new Set([
|
|
1219
|
+
".venv",
|
|
1220
|
+
"node_modules",
|
|
1221
|
+
"__pycache__",
|
|
1222
|
+
".git",
|
|
1223
|
+
".local",
|
|
1224
|
+
".flow-sdk",
|
|
1225
|
+
".flow-debug"
|
|
1226
|
+
]);
|
|
1227
|
+
// ../solution-sdk/src/project-debug-status.ts
|
|
1228
|
+
var SUCCEEDED = "creationsucceeded";
|
|
1229
|
+
var TERMINAL = new Set([SUCCEEDED, "creationfailed", "validationfailed"]);
|
|
1230
|
+
// ../packager/packager-tool-datafabric/src/canonical-path.ts
|
|
1231
|
+
async function canonicalPathAsync(target, fs) {
|
|
1232
|
+
const realpath = fs.realpath?.bind(fs);
|
|
1233
|
+
const absolute = fs.path.resolve(target);
|
|
1234
|
+
if (realpath === undefined)
|
|
1235
|
+
return absolute;
|
|
1236
|
+
const tail = [];
|
|
1237
|
+
let current = absolute;
|
|
1238
|
+
while (!await fs.exists(current)) {
|
|
1239
|
+
const parent = fs.path.dirname(current);
|
|
1240
|
+
if (parent === current)
|
|
1241
|
+
return absolute;
|
|
1242
|
+
tail.unshift(fs.path.basename(current));
|
|
1243
|
+
current = parent;
|
|
1244
|
+
}
|
|
1245
|
+
return fs.path.join(await realpath(current), ...tail);
|
|
1246
|
+
}
|
|
1247
|
+
async function resolvesInsideAsync(target, root, fs) {
|
|
1248
|
+
const canonicalRoot = await canonicalPathAsync(root, fs);
|
|
1249
|
+
const resolved = await canonicalPathAsync(target, fs);
|
|
1250
|
+
const relative = fs.path.relative(canonicalRoot, resolved);
|
|
1251
|
+
const inside = relative !== "" && relative.split(/[\\/]/)[0] !== ".." && !fs.path.isAbsolute(relative);
|
|
1252
|
+
return { inside, resolved, root: canonicalRoot };
|
|
1253
|
+
}
|
|
1254
|
+
async function isSymlinkEntryAsync(target, fs) {
|
|
1255
|
+
const isSymbolicLink = fs.isSymbolicLink?.bind(fs);
|
|
1256
|
+
return isSymbolicLink === undefined ? false : isSymbolicLink(fs.path.resolve(target));
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// ../packager/packager-tool-datafabric/src/init/entity-init-service.ts
|
|
1260
|
+
var VALID_PROJECT_NAME_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
1261
|
+
async function entityInitAsync(name, options) {
|
|
1262
|
+
if (!VALID_PROJECT_NAME_REGEX.test(name)) {
|
|
1263
|
+
throw new Error(`Invalid project name "${name}". Name can only contain letters, numbers, underscores (_), and hyphens (-).`);
|
|
1264
|
+
}
|
|
1265
|
+
const entityName = options.firstEntityName;
|
|
1266
|
+
requireAuthoredName(options.firstEntity, entityName);
|
|
1267
|
+
const nameError = validateNameFormat(entityName, "entity");
|
|
1268
|
+
if (nameError) {
|
|
1269
|
+
throw new Error(`${nameError.message}. ${nameError.instructions}`);
|
|
1270
|
+
}
|
|
1271
|
+
const fs = getFileSystem();
|
|
1272
|
+
const solutionFile = await resolveSolutionFileAsync(options);
|
|
1273
|
+
const { projectDir, autoCreatedSolution } = solutionFile ? { projectDir: fs.path.join(fs.path.dirname(solutionFile), name) } : await prepareProjectLocation(fs, fs.path.resolve(requireCwd(options), name), name, {});
|
|
1274
|
+
const [statError, stat] = await catchError(fs.stat(projectDir));
|
|
1275
|
+
if (statError && !isMissingPathError(statError)) {
|
|
1276
|
+
throw statError;
|
|
1277
|
+
}
|
|
1278
|
+
const projectDirExisted = !statError && stat !== null;
|
|
1279
|
+
if (await isSymlinkEntryAsync(projectDir, fs)) {
|
|
1280
|
+
throw new Error(`Directory "${name}" is a link, not a project directory in the solution. ` + "Replace the link with the directory itself, or pick a different name.");
|
|
1281
|
+
}
|
|
1282
|
+
if (projectDirExisted && !options.force) {
|
|
1283
|
+
const existingEntries = await fs.readdir(projectDir);
|
|
1284
|
+
if (existingEntries.length > 0) {
|
|
1285
|
+
throw new Error(`Directory "${name}" already exists and is not empty. Use --force to overwrite.`);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
let registered;
|
|
1289
|
+
const created = [];
|
|
1290
|
+
const writeTracked = async (path, content) => {
|
|
1291
|
+
if (await isSymlinkEntryAsync(path, fs)) {
|
|
1292
|
+
throw new Error(`'${path}' is a symbolic link. Entity project files must be real files; replace the link with the file itself.`);
|
|
1293
|
+
}
|
|
1294
|
+
const [readError, previous] = await catchError(fs.readFile(path, "utf-8"));
|
|
1295
|
+
if (readError && !isMissingPathError(readError))
|
|
1296
|
+
throw readError;
|
|
1297
|
+
created.push({
|
|
1298
|
+
path,
|
|
1299
|
+
previous: typeof previous === "string" ? previous : undefined
|
|
1300
|
+
});
|
|
1301
|
+
await fs.writeFile(path, content);
|
|
1302
|
+
};
|
|
1303
|
+
const rollback = async () => {
|
|
1304
|
+
if (registered) {
|
|
1305
|
+
await unregisterProject(registered);
|
|
1306
|
+
}
|
|
1307
|
+
for (const { path, previous } of [...created].reverse()) {
|
|
1308
|
+
const [undoError] = await catchError(previous === undefined ? fs.rm(path) : fs.writeFile(path, previous));
|
|
1309
|
+
if (undoError) {
|
|
1310
|
+
await reportUndoFailureAsync(path, previous, undoError);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
if (!projectDirExisted) {
|
|
1314
|
+
await catchError(fs.rm(projectDir));
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
try {
|
|
1318
|
+
await fs.mkdir(projectDir);
|
|
1319
|
+
const projectFile = fs.path.join(projectDir, "project.uiproj");
|
|
1320
|
+
await writeTracked(projectFile, serialize({ Name: name, ProjectType: "Entity" }));
|
|
1321
|
+
const relativeResourcePath = entityResourcePath(entityName);
|
|
1322
|
+
const entityFile = fs.path.join(projectDir, `${entityName}${ENTITY_EXTENSION_CONST}`);
|
|
1323
|
+
await writeTracked(entityFile, serialize({ name: entityName, resourcePath: relativeResourcePath }));
|
|
1324
|
+
const registration = await tryRegisterProjectInParentSolution(fs, projectDir, {});
|
|
1325
|
+
if (registration.Status === "Registered" && registration.Solution && registration.ProjectId) {
|
|
1326
|
+
registered = {
|
|
1327
|
+
solutionFile: registration.Solution,
|
|
1328
|
+
projectId: registration.ProjectId
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
if (registration.Status !== "Registered" && registration.Status !== "AlreadyRegistered" || !registration.Solution) {
|
|
1332
|
+
if (solutionFile && registration.Status === "Skipped") {
|
|
1333
|
+
throw new Error(`Entity project "${name}" could not be registered in '${solutionFile}': ` + `${registration.Instructions ?? registration.Message ?? "registration was skipped"}. ` + "A solution folder containing more than one .uipx is not supported yet — " + "register the project with 'uip solution projects add' instead.");
|
|
1334
|
+
}
|
|
1335
|
+
throw new Error(`Entity project "${name}" requires a parent solution (registration status: ${registration.Status}). ` + "Run inside a solution directory, or create one first with 'uip solution init'.");
|
|
1336
|
+
}
|
|
1337
|
+
const solutionDir = fs.path.dirname(registration.Solution);
|
|
1338
|
+
const resourceFile = fs.path.join(solutionDir, ...relativeResourcePath.split("/"));
|
|
1339
|
+
const document = options.firstEntity ?? createEntitySkeleton(entityName);
|
|
1340
|
+
const diagnostics = validateEntity(document, {
|
|
1341
|
+
siblingNames: await siblingNamesFor(solutionDir, entityName, fs)
|
|
1342
|
+
});
|
|
1343
|
+
if (diagnostics.length > 0) {
|
|
1344
|
+
throw new Error(`Cannot create entity "${entityName}": ${diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join("; ")}`);
|
|
1345
|
+
}
|
|
1346
|
+
if (await fs.exists(resourceFile)) {
|
|
1347
|
+
throw new Error(`An entity definition for "${entityName}" already exists in this solution ` + `('${relativeResourcePath}'). Entity names are solution-wide unique — ` + "pick a different name, or edit the existing entity with 'uip df entities update <Name> --local'.");
|
|
1348
|
+
}
|
|
1349
|
+
const destination = await resolvesInsideAsync(resourceFile, solutionDir, fs);
|
|
1350
|
+
if (!destination.inside) {
|
|
1351
|
+
throw new Error(`The entity definition path '${relativeResourcePath}' resolves outside the solution, to '${destination.resolved}'. ` + `Entity definitions must live inside the solution at '${destination.root}'; replace the link with the directory itself.`);
|
|
1352
|
+
}
|
|
1353
|
+
await fs.mkdir(fs.path.dirname(resourceFile));
|
|
1354
|
+
await writeTracked(resourceFile, serialize(wrapEntityJson(document)));
|
|
1355
|
+
return {
|
|
1356
|
+
projectName: name,
|
|
1357
|
+
projectDir,
|
|
1358
|
+
entityFile,
|
|
1359
|
+
resourceFile,
|
|
1360
|
+
registration,
|
|
1361
|
+
autoCreatedSolution
|
|
1362
|
+
};
|
|
1363
|
+
} catch (error) {
|
|
1364
|
+
await rollback();
|
|
1365
|
+
throw error;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
async function reportUndoFailureAsync(path, previous, undoError) {
|
|
1369
|
+
const fs = getFileSystem();
|
|
1370
|
+
if (previous !== undefined) {
|
|
1371
|
+
const [readError, now] = await catchError(fs.readFile(path, "utf-8"));
|
|
1372
|
+
if (readError) {
|
|
1373
|
+
logger.warn(`Could not restore '${path}' after a failed --force (${undoError.message}), nor read it to check (${readError.message}). Check its content before retrying.`);
|
|
1374
|
+
} else if (now !== previous) {
|
|
1375
|
+
logger.warn(`Could not restore '${path}' after a failed --force: ${undoError.message}. ` + "Its previous content was not written back; recover it from version control or a backup.");
|
|
1376
|
+
}
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
const [statError, stat] = await catchError(fs.stat(path));
|
|
1380
|
+
if (statError || stat !== null) {
|
|
1381
|
+
logger.warn(`Could not remove '${path}', written by the failed run: ${undoError.message}. Delete it before retrying.`);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
function requireCwd(options) {
|
|
1385
|
+
if (!options.cwd) {
|
|
1386
|
+
throw new Error("Either 'cwd' or 'uipxPath' is required: without one there is no base " + "directory to create the project in.");
|
|
1387
|
+
}
|
|
1388
|
+
return options.cwd;
|
|
1389
|
+
}
|
|
1390
|
+
async function resolveSolutionFileAsync(options) {
|
|
1391
|
+
if (!options.uipxPath) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
const fs = getFileSystem();
|
|
1395
|
+
let resolved;
|
|
1396
|
+
if (fs.path.isAbsolute(options.uipxPath)) {
|
|
1397
|
+
resolved = options.uipxPath;
|
|
1398
|
+
} else if (options.cwd) {
|
|
1399
|
+
resolved = fs.path.resolve(options.cwd, options.uipxPath);
|
|
1400
|
+
} else {
|
|
1401
|
+
throw new Error(`uipxPath '${options.uipxPath}' is relative and no 'cwd' was given to resolve it against. ` + "Pass an absolute path, or set 'cwd'.");
|
|
1402
|
+
}
|
|
1403
|
+
if (!resolved.endsWith(".uipx")) {
|
|
1404
|
+
throw new Error(`uipxPath must point at a .uipx file, got '${resolved}'. Pass the manifest itself, not its directory.`);
|
|
1405
|
+
}
|
|
1406
|
+
const [statError, stat] = await catchError(fs.stat(resolved));
|
|
1407
|
+
if (statError || stat === null) {
|
|
1408
|
+
throw new Error(`Solution manifest not found: '${resolved}'. Create the solution first, or omit uipxPath to search for one.`);
|
|
1409
|
+
}
|
|
1410
|
+
if (stat.isDirectory()) {
|
|
1411
|
+
throw new Error(`uipxPath must point at a .uipx file, but '${resolved}' is a directory.`);
|
|
1412
|
+
}
|
|
1413
|
+
return resolved;
|
|
1414
|
+
}
|
|
1415
|
+
async function unregisterProject(registered) {
|
|
1416
|
+
const { solutionFile, projectId } = registered;
|
|
1417
|
+
const fs = getFileSystem();
|
|
1418
|
+
const [readError, solution] = await readSolutionManifest(fs, solutionFile);
|
|
1419
|
+
if (readError) {
|
|
1420
|
+
logger.warn(`Could not undo the solution registration for project id ${projectId} in '${solutionFile}': ${readError.message}. ` + "Remove the stale entry with 'uip solution project remove'.");
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
solution.content.Projects = solution.projects.filter((project) => project.Id !== projectId);
|
|
1424
|
+
const [writeError] = await catchError(fs.writeFile(solutionFile, serialize(solution.content)));
|
|
1425
|
+
if (writeError) {
|
|
1426
|
+
logger.warn(`Could not undo the solution registration for project id ${projectId} in '${solutionFile}': ${writeError.message}. ` + "Remove the stale entry with 'uip solution project remove'.");
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
// ../packager/packager-tool-datafabric/src/inline/inline-entity-service.ts
|
|
1430
|
+
var INLINE_ENTITY_ERROR_CODES = {
|
|
1431
|
+
projectNotFound: "PROJECT_NOT_FOUND",
|
|
1432
|
+
noParentSolution: "NO_PARENT_SOLUTION",
|
|
1433
|
+
entityNotFound: "ENTITY_NOT_FOUND",
|
|
1434
|
+
notLocallyAuthored: "NOT_LOCALLY_AUTHORED"
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
class InlineEntityError extends Error {
|
|
1438
|
+
instructions;
|
|
1439
|
+
code;
|
|
1440
|
+
constructor(message, instructions, code) {
|
|
1441
|
+
super(message);
|
|
1442
|
+
this.instructions = instructions;
|
|
1443
|
+
this.code = code;
|
|
1444
|
+
this.name = "InlineEntityError";
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
function fsOf() {
|
|
1448
|
+
return getFileSystem();
|
|
1449
|
+
}
|
|
1450
|
+
var VALID_PROJECT_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
1451
|
+
var PRESERVED_FIELD_PROPS = [
|
|
1452
|
+
"Id",
|
|
1453
|
+
"IsEncrypted",
|
|
1454
|
+
"IsRbacEnabled",
|
|
1455
|
+
"IsHiddenField",
|
|
1456
|
+
"IsAttachment",
|
|
1457
|
+
"Transformation",
|
|
1458
|
+
"FieldCategoryId",
|
|
1459
|
+
"ReferenceEntity",
|
|
1460
|
+
"ReferenceField",
|
|
1461
|
+
"ReferenceType",
|
|
1462
|
+
"ReferenceChoiceSet",
|
|
1463
|
+
"ReferenceName",
|
|
1464
|
+
"CreateTime",
|
|
1465
|
+
"CreatedBy",
|
|
1466
|
+
"UpdateTime",
|
|
1467
|
+
"UpdatedBy"
|
|
1468
|
+
];
|
|
1469
|
+
async function assertInsideSolutionAsync(target, solutionDir, fs) {
|
|
1470
|
+
const { inside, resolved, root } = await resolvesInsideAsync(target, solutionDir, fs);
|
|
1471
|
+
if (!inside) {
|
|
1472
|
+
throw new InlineEntityError(`'${target}' resolves outside the solution`, `It leads to '${resolved}' once symlinks are followed. Projects and entity definitions must live inside the solution at '${root}'; replace the link with the directory or file itself.`);
|
|
1473
|
+
}
|
|
1474
|
+
if (await isSymlinkEntryAsync(target, fs)) {
|
|
1475
|
+
throw new InlineEntityError(`'${target}' is a symbolic link`, "Entity stubs and definition resources must be real files, not links — a link is followed by every read and write, wherever it points. Replace it with the file itself.");
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
async function containmentProblemAsync(target, solutionDir, fs) {
|
|
1479
|
+
try {
|
|
1480
|
+
await assertInsideSolutionAsync(target, solutionDir, fs);
|
|
1481
|
+
return;
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
if (error instanceof InlineEntityError)
|
|
1484
|
+
return error.message;
|
|
1485
|
+
throw error;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
async function checkedPairAsync(stubFile, solutionDir, fs) {
|
|
1489
|
+
const stubProblem = await containmentProblemAsync(stubFile, solutionDir, fs);
|
|
1490
|
+
if (stubProblem !== undefined)
|
|
1491
|
+
return { ok: false, problem: stubProblem };
|
|
1492
|
+
const pointed = await lexicalResourcePathAsync(stubFile, solutionDir, fs);
|
|
1493
|
+
if (pointed !== undefined) {
|
|
1494
|
+
const resourceProblem = await containmentProblemAsync(pointed, solutionDir, fs);
|
|
1495
|
+
if (resourceProblem !== undefined) {
|
|
1496
|
+
return { ok: false, problem: resourceProblem };
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
const pair = await verifyPair(stubFile, solutionDir, fs);
|
|
1500
|
+
return pair.ok ? { ok: true, pair } : { ok: false, problem: pair.failure.message };
|
|
1501
|
+
}
|
|
1502
|
+
async function lexicalResourcePathAsync(stubFile, solutionDir, fs) {
|
|
1503
|
+
let pointer;
|
|
1504
|
+
try {
|
|
1505
|
+
const raw = await fs.readFile(stubFile);
|
|
1506
|
+
pointer = JSON.parse(typeof raw === "string" ? raw : new TextDecoder().decode(raw ?? new Uint8Array)).resourcePath;
|
|
1507
|
+
} catch {
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
return typeof pointer === "string" ? fs.path.resolve(solutionDir, ...pointer.split("/")) : undefined;
|
|
1511
|
+
}
|
|
1512
|
+
function assertEntityTextInput(input) {
|
|
1513
|
+
for (const key of ["displayName", "description"]) {
|
|
1514
|
+
const value = input[key];
|
|
1515
|
+
if (value !== undefined && typeof value !== "string") {
|
|
1516
|
+
throw new InlineEntityError(`'${key}' must be a string`, `Received ${JSON.stringify(value)}. Pass text, or "" for none.`);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
async function solutionRootAsync(options = {}) {
|
|
1521
|
+
const fs = fsOf();
|
|
1522
|
+
const from = options.cwd ?? process.cwd();
|
|
1523
|
+
const root = await findSolutionRoot(from, fs);
|
|
1524
|
+
if (root === undefined) {
|
|
1525
|
+
throw new InlineEntityError("Not inside a solution", `Looked upward from '${from}' for a .uipx. Run this from the solution directory, or create one with 'uip solution init'.`, INLINE_ENTITY_ERROR_CODES.noParentSolution);
|
|
1526
|
+
}
|
|
1527
|
+
return root;
|
|
1528
|
+
}
|
|
1529
|
+
async function resolveProjectAsync(projectName, options = {}) {
|
|
1530
|
+
const fs = fsOf();
|
|
1531
|
+
if (!VALID_PROJECT_NAME.test(projectName)) {
|
|
1532
|
+
throw new InlineEntityError(`Invalid project name '${projectName}'`, "Project names contain only letters, numbers, underscores (_) and hyphens (-) — they are a single directory name, never a path.");
|
|
1533
|
+
}
|
|
1534
|
+
const root = await solutionRootAsync(options);
|
|
1535
|
+
const projectDir = fs.path.resolve(root, projectName);
|
|
1536
|
+
if (await isSymlinkEntryAsync(projectDir, fs)) {
|
|
1537
|
+
throw new InlineEntityError(`Entity project '${projectName}' is a symbolic link`, "A project is addressed by its own directory in the solution — a link would have stubs written wherever it points. Replace the link with the directory itself.");
|
|
1538
|
+
}
|
|
1539
|
+
let stat = null;
|
|
1540
|
+
try {
|
|
1541
|
+
stat = await fs.stat(projectDir);
|
|
1542
|
+
} catch (error) {
|
|
1543
|
+
if (!isMissingPathError(error)) {
|
|
1544
|
+
throw error;
|
|
1545
|
+
}
|
|
1546
|
+
stat = null;
|
|
1547
|
+
}
|
|
1548
|
+
if (stat === null || !stat.isDirectory()) {
|
|
1549
|
+
throw new InlineEntityError(`Entity project '${projectName}' not found`, `Looked for '${projectDir}'. Run the command from the solution directory, or create the project with 'uip df entities create <Name> --local --project-name ${projectName}'.`, INLINE_ENTITY_ERROR_CODES.projectNotFound);
|
|
1550
|
+
}
|
|
1551
|
+
await assertInsideSolutionAsync(projectDir, root, fs);
|
|
1552
|
+
return { projectDir, solutionDir: root };
|
|
1553
|
+
}
|
|
1554
|
+
async function registeredProjectTypesAsync(solutionDir, fs) {
|
|
1555
|
+
const registered = new Map;
|
|
1556
|
+
for (const file of await fs.readdir(solutionDir)) {
|
|
1557
|
+
if (!file.endsWith(".uipx"))
|
|
1558
|
+
continue;
|
|
1559
|
+
const raw = await fs.readFile(fs.path.join(solutionDir, file), "utf-8");
|
|
1560
|
+
let projects;
|
|
1561
|
+
try {
|
|
1562
|
+
projects = JSON.parse(typeof raw === "string" ? raw : new TextDecoder().decode(raw ?? new Uint8Array)).Projects;
|
|
1563
|
+
} catch {
|
|
1564
|
+
throw new InlineEntityError(`Solution manifest '${file}' is not valid JSON`, `Fix '${fs.path.join(solutionDir, file)}' — 'uip solution pack' cannot read it either.`);
|
|
1565
|
+
}
|
|
1566
|
+
for (const project of Array.isArray(projects) ? projects : []) {
|
|
1567
|
+
const { Type, ProjectRelativePath } = project ?? {};
|
|
1568
|
+
if (typeof Type === "string" && typeof ProjectRelativePath === "string") {
|
|
1569
|
+
const segments = ProjectRelativePath.split(/[\\/]/);
|
|
1570
|
+
const key = segments.length === 2 ? segments[0]?.toLowerCase() : undefined;
|
|
1571
|
+
if (key && registered.get(key)?.toLowerCase() !== "entity") {
|
|
1572
|
+
registered.set(key, Type);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
return registered;
|
|
1578
|
+
}
|
|
1579
|
+
async function requireEntityProjectAsync(projectDir, projectName, solutionDir, fs) {
|
|
1580
|
+
const projectFile = fs.path.join(projectDir, "project.uiproj");
|
|
1581
|
+
let raw = null;
|
|
1582
|
+
try {
|
|
1583
|
+
raw = await fs.readFile(projectFile, "utf-8");
|
|
1584
|
+
} catch (error) {
|
|
1585
|
+
if (!isMissingPathError(error)) {
|
|
1586
|
+
throw error;
|
|
1587
|
+
}
|
|
1588
|
+
raw = null;
|
|
1589
|
+
}
|
|
1590
|
+
if (raw === null) {
|
|
1591
|
+
throw new InlineEntityError(`Directory '${projectName}' is not an Entity project`, `No 'project.uiproj' in '${projectDir}'. An entity can only be authored into a project of type Entity — create one with 'uip df entities create <Name> --local --project-name <NewProject>'.`);
|
|
1592
|
+
}
|
|
1593
|
+
let projectType;
|
|
1594
|
+
try {
|
|
1595
|
+
projectType = JSON.parse(typeof raw === "string" ? raw : new TextDecoder().decode(raw)).ProjectType;
|
|
1596
|
+
} catch {
|
|
1597
|
+
throw new InlineEntityError(`Project file for '${projectName}' is not valid JSON`, `Fix '${projectFile}' — it must be a JSON object naming a 'ProjectType'.`);
|
|
1598
|
+
}
|
|
1599
|
+
if (typeof projectType !== "string" || projectType.toLowerCase() !== "entity") {
|
|
1600
|
+
throw new InlineEntityError(`Project '${projectName}' is not an Entity project`, `'${projectFile}' declares ProjectType '${String(projectType)}'. Pack only ships entities from a project of type Entity, so an entity written here would never deploy. Use an Entity project, or create one with 'uip df entities create <Name> --local --project-name <NewProject>'.`);
|
|
1601
|
+
}
|
|
1602
|
+
await requireRegisteredAsync(projectName, solutionDir, fs);
|
|
1603
|
+
}
|
|
1604
|
+
async function requireRegisteredAsync(projectName, solutionDir, fs) {
|
|
1605
|
+
const type = (await registeredProjectTypesAsync(solutionDir, fs)).get(projectName.toLowerCase());
|
|
1606
|
+
if (type !== undefined && type.toLowerCase() !== "entity") {
|
|
1607
|
+
throw new InlineEntityError(`Project '${projectName}' is registered as '${type}', not as an Entity project`, `The solution's .uipx lists '${projectName}' as a ${type} project, so pack never reads entities from it. Author entities in an Entity project — create one with 'uip df entities create <Name> --local --project-name <NewProject>'.`);
|
|
1608
|
+
}
|
|
1609
|
+
if (type === undefined) {
|
|
1610
|
+
throw new InlineEntityError(`Entity project '${projectName}' is not registered in the solution`, `'${projectName}' is not in the solution's .uipx as an Entity project, so 'uip solution pack' never visits it and nothing written there would deploy. Register it with 'uip solution projects add ${projectName}'.`);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
function entityStubPath(projectDir, entityName, fs) {
|
|
1614
|
+
const nameError = validateNameFormat(entityName, "entity");
|
|
1615
|
+
if (nameError) {
|
|
1616
|
+
throw new InlineEntityError(nameError.message, nameError.instructions);
|
|
1617
|
+
}
|
|
1618
|
+
const stubFile = fs.path.join(projectDir, `${entityName}${ENTITY_EXTENSION_CONST}`);
|
|
1619
|
+
if (fs.path.dirname(fs.path.resolve(stubFile)) !== fs.path.resolve(projectDir)) {
|
|
1620
|
+
throw new InlineEntityError(`Entity name '${entityName}' does not resolve inside project directory`, "Entity names are plain identifiers, never paths.");
|
|
1621
|
+
}
|
|
1622
|
+
return stubFile;
|
|
1623
|
+
}
|
|
1624
|
+
async function resolveOwningProjectAsync(entityName, options = {}) {
|
|
1625
|
+
const fs = fsOf();
|
|
1626
|
+
const from = options.cwd ?? process.cwd();
|
|
1627
|
+
const solutionDir = await findSolutionRoot(from, fs);
|
|
1628
|
+
if (solutionDir === undefined) {
|
|
1629
|
+
throw new InlineEntityError("Not inside a solution", `Looked upward from '${from}' for a .uipx. Run this from the solution directory, or name the project with --project-name.`, INLINE_ENTITY_ERROR_CODES.noParentSolution);
|
|
1630
|
+
}
|
|
1631
|
+
const owners = await findProjectsOwningEntity(solutionDir, entityName, fs);
|
|
1632
|
+
const owner = owners[0];
|
|
1633
|
+
if (owners.length === 1 && owner !== undefined) {
|
|
1634
|
+
return {
|
|
1635
|
+
projectName: owner.projectName,
|
|
1636
|
+
entityName: owner.entityName,
|
|
1637
|
+
solutionDir
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
if (owners.length === 0) {
|
|
1641
|
+
const known = await collectSolutionEntityNames(solutionDir, fs);
|
|
1642
|
+
throw new InlineEntityError(`No entity named '${entityName}' in this solution`, known.length === 0 ? "The solution has no authored entities yet. Create one with 'uip df entities create <Name> --local'." : `Entities here: ${[...new Set(known)].sort(byName).join(", ")}.`, INLINE_ENTITY_ERROR_CODES.entityNotFound);
|
|
1643
|
+
}
|
|
1644
|
+
throw new InlineEntityError(`More than one project owns an entity named '${entityName}'`, `Found in: ${owners.map((each) => each.projectName).join(", ")}. Name the one you mean with --project-name.`);
|
|
1645
|
+
}
|
|
1646
|
+
async function stubNamesAsync(projectDir, fs) {
|
|
1647
|
+
let entries = [];
|
|
1648
|
+
try {
|
|
1649
|
+
entries = await fs.readdir(projectDir);
|
|
1650
|
+
} catch (error) {
|
|
1651
|
+
if (!isMissingPathError(error)) {
|
|
1652
|
+
throw error;
|
|
1653
|
+
}
|
|
1654
|
+
return [];
|
|
1655
|
+
}
|
|
1656
|
+
return entries.filter((name) => name.endsWith(ENTITY_EXTENSION_CONST)).sort(byName);
|
|
1657
|
+
}
|
|
1658
|
+
async function inlineEntityListAsync(projectName, options = {}) {
|
|
1659
|
+
const fs = fsOf();
|
|
1660
|
+
const { projectDir, solutionDir } = await resolveProjectAsync(projectName, options);
|
|
1661
|
+
await requireRegisteredAsync(projectName, solutionDir, fs);
|
|
1662
|
+
const summaries = [];
|
|
1663
|
+
for (const stubName of await stubNamesAsync(projectDir, fs)) {
|
|
1664
|
+
const stubFile = fs.path.join(projectDir, stubName);
|
|
1665
|
+
const checked = await checkedPairAsync(stubFile, solutionDir, fs);
|
|
1666
|
+
if (!checked.ok) {
|
|
1667
|
+
summaries.push({
|
|
1668
|
+
name: fs.path.basename(stubName, ENTITY_EXTENSION_CONST),
|
|
1669
|
+
stubFile,
|
|
1670
|
+
problem: checked.problem
|
|
1671
|
+
});
|
|
1672
|
+
continue;
|
|
1673
|
+
}
|
|
1674
|
+
const { pair } = checked;
|
|
1675
|
+
summaries.push({
|
|
1676
|
+
name: pair.entityName,
|
|
1677
|
+
stubFile,
|
|
1678
|
+
resourceFile: pair.resourceFile,
|
|
1679
|
+
locallyAuthored: isLocallyAuthored(pair.entity)
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
return summaries;
|
|
1683
|
+
}
|
|
1684
|
+
async function inlineEntityListAllAsync(options = {}) {
|
|
1685
|
+
const fs = fsOf();
|
|
1686
|
+
const from = options.cwd ?? process.cwd();
|
|
1687
|
+
const solutionDir = await findSolutionRoot(from, fs);
|
|
1688
|
+
if (solutionDir === undefined) {
|
|
1689
|
+
throw new InlineEntityError("Not inside a solution", `Looked upward from '${from}' for a .uipx. Run this from the solution directory.`, INLINE_ENTITY_ERROR_CODES.noParentSolution);
|
|
1690
|
+
}
|
|
1691
|
+
const rows = [];
|
|
1692
|
+
for (const entry of (await fs.readdir(solutionDir)).sort(byName)) {
|
|
1693
|
+
if (entry === "resources" || entry.startsWith(".")) {
|
|
1694
|
+
continue;
|
|
1695
|
+
}
|
|
1696
|
+
const dir = fs.path.join(solutionDir, entry);
|
|
1697
|
+
const [statError, stat] = await catchInline(() => fs.stat(dir));
|
|
1698
|
+
if (statError !== undefined && !isMissingPathError(statError)) {
|
|
1699
|
+
rows.push({
|
|
1700
|
+
projectName: entry,
|
|
1701
|
+
name: entry,
|
|
1702
|
+
stubFile: dir,
|
|
1703
|
+
solutionDir,
|
|
1704
|
+
projectProblem: `Directory '${entry}' could not be read: ${messageOf(statError)}`
|
|
1705
|
+
});
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
if (!stat?.isDirectory()) {
|
|
1709
|
+
continue;
|
|
1710
|
+
}
|
|
1711
|
+
const [readError, entries] = await catchInline(() => fs.readdir(dir));
|
|
1712
|
+
if (readError !== undefined) {
|
|
1713
|
+
if (isMissingPathError(readError)) {
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
rows.push({
|
|
1717
|
+
projectName: entry,
|
|
1718
|
+
name: entry,
|
|
1719
|
+
stubFile: dir,
|
|
1720
|
+
solutionDir,
|
|
1721
|
+
projectProblem: `Directory '${entry}' could not be read: ${messageOf(readError)}`
|
|
1722
|
+
});
|
|
1723
|
+
continue;
|
|
1724
|
+
}
|
|
1725
|
+
if (!(entries ?? []).some((file) => file.endsWith(ENTITY_EXTENSION_CONST))) {
|
|
1726
|
+
continue;
|
|
1727
|
+
}
|
|
1728
|
+
const [listError, listed] = await catchInline(() => inlineEntityListAsync(entry, { cwd: solutionDir }));
|
|
1729
|
+
if (listError !== undefined) {
|
|
1730
|
+
rows.push({
|
|
1731
|
+
projectName: entry,
|
|
1732
|
+
name: entry,
|
|
1733
|
+
stubFile: dir,
|
|
1734
|
+
solutionDir,
|
|
1735
|
+
projectProblem: listError instanceof InlineEntityError && listError.instructions ? `${listError.message}. ${listError.instructions}` : messageOf(listError)
|
|
1736
|
+
});
|
|
1737
|
+
continue;
|
|
1738
|
+
}
|
|
1739
|
+
for (const summary of listed ?? []) {
|
|
1740
|
+
rows.push({ ...summary, projectName: entry, solutionDir });
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
return rows;
|
|
1744
|
+
}
|
|
1745
|
+
function messageOf(error) {
|
|
1746
|
+
return error instanceof Error ? error.message : String(error);
|
|
1747
|
+
}
|
|
1748
|
+
async function catchInline(run) {
|
|
1749
|
+
try {
|
|
1750
|
+
return [undefined, await run()];
|
|
1751
|
+
} catch (error) {
|
|
1752
|
+
return [error, undefined];
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
async function resolveEntityAsync(projectName, entityName, options) {
|
|
1756
|
+
const fs = fsOf();
|
|
1757
|
+
const { projectDir, solutionDir } = await resolveProjectAsync(projectName, options);
|
|
1758
|
+
const stubFile = entityStubPath(projectDir, entityName, fs);
|
|
1759
|
+
const checked = await checkedPairAsync(stubFile, solutionDir, fs);
|
|
1760
|
+
if (!checked.ok) {
|
|
1761
|
+
const known = (await stubNamesAsync(projectDir, fs)).map((name) => fs.path.basename(name, ENTITY_EXTENSION_CONST));
|
|
1762
|
+
throw new InlineEntityError(`Entity '${entityName}' is not usable in project '${projectName}': ${checked.problem}`, known.length === 0 ? `Project '${projectName}' has no entities. Add one with 'uip df entities create ${entityName} --local --project-name ${projectName}'.` : `Entities in this project: ${known.join(", ")}.`);
|
|
1763
|
+
}
|
|
1764
|
+
const { pair } = checked;
|
|
1765
|
+
await assertInsideSolutionAsync(pair.resourceFile, solutionDir, fs);
|
|
1766
|
+
const rawResource = await fs.readFile(pair.resourceFile, "utf-8");
|
|
1767
|
+
if (rawResource === null) {
|
|
1768
|
+
throw new InlineEntityError(`Entity definition for '${pair.entityName}' could not be read`, `Expected it at '${pair.resourceFile}'.`);
|
|
1769
|
+
}
|
|
1770
|
+
const resource = JSON.parse(rawResource);
|
|
1771
|
+
return {
|
|
1772
|
+
projectDir,
|
|
1773
|
+
solutionDir,
|
|
1774
|
+
entityName: pair.entityName,
|
|
1775
|
+
stubFile,
|
|
1776
|
+
resourceFile: pair.resourceFile,
|
|
1777
|
+
entity: pair.entity,
|
|
1778
|
+
resource
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
async function inlineEntityGetAsync(projectName, entityName, options = {}) {
|
|
1782
|
+
return (await resolveEntityAsync(projectName, entityName, options)).entity;
|
|
1783
|
+
}
|
|
1784
|
+
async function inlineEntityValidateAsync(projectName, options = {}) {
|
|
1785
|
+
const fs = fsOf();
|
|
1786
|
+
const { projectDir, solutionDir } = await resolveProjectAsync(projectName, options);
|
|
1787
|
+
await requireRegisteredAsync(projectName, solutionDir, fs);
|
|
1788
|
+
const stubFiles = options.entityName === undefined ? (await stubNamesAsync(projectDir, fs)).map((stubName) => fs.path.join(projectDir, stubName)) : [entityStubPath(projectDir, options.entityName, fs)];
|
|
1789
|
+
const results = [];
|
|
1790
|
+
for (const stubFile of stubFiles) {
|
|
1791
|
+
const name = fs.path.basename(stubFile, ENTITY_EXTENSION_CONST);
|
|
1792
|
+
const checked = await checkedPairAsync(stubFile, solutionDir, fs);
|
|
1793
|
+
if (!checked.ok) {
|
|
1794
|
+
results.push({
|
|
1795
|
+
entityName: name,
|
|
1796
|
+
diagnostics: [],
|
|
1797
|
+
pairProblem: checked.problem
|
|
1798
|
+
});
|
|
1799
|
+
continue;
|
|
1800
|
+
}
|
|
1801
|
+
const { pair } = checked;
|
|
1802
|
+
results.push({
|
|
1803
|
+
entityName: pair.entityName,
|
|
1804
|
+
resourceFile: pair.resourceFile,
|
|
1805
|
+
diagnostics: validateEntity(pair.entity, {
|
|
1806
|
+
siblingNames: await siblingNamesFor(solutionDir, pair.entityName, fs)
|
|
1807
|
+
})
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
return results;
|
|
1811
|
+
}
|
|
1812
|
+
function requireLocallyAuthored(resolved) {
|
|
1813
|
+
if (isLocallyAuthored(resolved.entity)) {
|
|
1814
|
+
return;
|
|
1815
|
+
}
|
|
1816
|
+
throw new InlineEntityError(`Entity '${resolved.entityName}' is a platform entity this solution references, not an inline one`, `It resolves to Data Fabric folder '${resolved.entity.FolderId}'. Change its schema with 'uip df entities update <id>' or in Data Fabric; the inline commands only author entities created locally.`, INLINE_ENTITY_ERROR_CODES.notLocallyAuthored);
|
|
1817
|
+
}
|
|
1818
|
+
async function inlineEntityUpdateAsync(projectName, entityName, update, options = {}) {
|
|
1819
|
+
assertEntityTextInput(update);
|
|
1820
|
+
const fs = fsOf();
|
|
1821
|
+
const resolved = await resolveEntityAsync(projectName, entityName, options);
|
|
1822
|
+
requireLocallyAuthored(resolved);
|
|
1823
|
+
await requireEntityProjectAsync(resolved.projectDir, projectName, resolved.solutionDir, fs);
|
|
1824
|
+
const next = {
|
|
1825
|
+
...resolved.entity,
|
|
1826
|
+
Fields: [...resolved.entity.Fields]
|
|
1827
|
+
};
|
|
1828
|
+
if (update.displayName !== undefined)
|
|
1829
|
+
next.DisplayName = update.displayName;
|
|
1830
|
+
if (update.description !== undefined)
|
|
1831
|
+
next.Description = update.description;
|
|
1832
|
+
const indexOfField = (name) => fieldIndexOf(next, name);
|
|
1833
|
+
for (const remove of update.removeFields ?? []) {
|
|
1834
|
+
const at = indexOfField(remove.name);
|
|
1835
|
+
if (at < 0) {
|
|
1836
|
+
throw new InlineEntityError(`Field '${remove.name}' is not on entity '${resolved.entityName}'`, `Fields: ${next.Fields.map((field) => field.Name).join(", ")}.`);
|
|
1837
|
+
}
|
|
1838
|
+
if (isSystemField(next.Fields[at])) {
|
|
1839
|
+
throw new InlineEntityError(`Field '${remove.name}' is a system field and cannot be removed`, "Data Fabric owns Id, CreateTime, CreatedBy, UpdateTime and UpdatedBy on every entity.");
|
|
1840
|
+
}
|
|
1841
|
+
next.Fields.splice(at, 1);
|
|
1842
|
+
}
|
|
1843
|
+
for (const change of update.updateFields ?? []) {
|
|
1844
|
+
const at = indexOfField(change.name);
|
|
1845
|
+
if (at < 0) {
|
|
1846
|
+
throw new InlineEntityError(`Field '${change.name}' is not on entity '${resolved.entityName}'`, `Fields: ${next.Fields.map((field) => field.Name).join(", ")}.`);
|
|
1847
|
+
}
|
|
1848
|
+
const current = next.Fields[at];
|
|
1849
|
+
if (current === undefined || isSystemField(current)) {
|
|
1850
|
+
throw new InlineEntityError(`Field '${change.name}' is a system field and cannot be changed`, "Data Fabric owns Id, CreateTime, CreatedBy, UpdateTime and UpdatedBy on every entity.");
|
|
1851
|
+
}
|
|
1852
|
+
const merged = (key, fallback) => (key in change) ? change[key] : fallback;
|
|
1853
|
+
const currentType = sdkTypeOf(current);
|
|
1854
|
+
const retyped = change.type !== undefined && change.type !== currentType;
|
|
1855
|
+
const inherited = (key, fallback) => retyped ? merged(key, undefined) : merged(key, fallback);
|
|
1856
|
+
next.Fields[at] = authorField({
|
|
1857
|
+
name: current.Name,
|
|
1858
|
+
type: merged("type", currentType),
|
|
1859
|
+
displayName: merged("displayName", current.DisplayName),
|
|
1860
|
+
description: merged("description", current.Description),
|
|
1861
|
+
isRequired: merged("isRequired", current.IsRequired),
|
|
1862
|
+
isUnique: merged("isUnique", current.IsUnique),
|
|
1863
|
+
lengthLimit: inherited("lengthLimit", current.SqlType?.LengthLimit),
|
|
1864
|
+
decimalPrecision: inherited("decimalPrecision", current.SqlType?.DecimalPrecision),
|
|
1865
|
+
maxValue: inherited("maxValue", current.SqlType?.MaxValue),
|
|
1866
|
+
minValue: inherited("minValue", current.SqlType?.MinValue),
|
|
1867
|
+
defaultValue: merged("defaultValue", retyped && typeof current.DefaultValue === "boolean" ? String(current.DefaultValue) : current.DefaultValue)
|
|
1868
|
+
}, {
|
|
1869
|
+
defaultValueFromCaller: retyped || "defaultValue" in change
|
|
1870
|
+
});
|
|
1871
|
+
const rebuilt = next.Fields[at];
|
|
1872
|
+
const previous = current;
|
|
1873
|
+
for (const key of Object.keys(previous)) {
|
|
1874
|
+
if (!(key in rebuilt)) {
|
|
1875
|
+
rebuilt[key] = previous[key];
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
for (const preserved of PRESERVED_FIELD_PROPS) {
|
|
1879
|
+
if (previous[preserved] !== undefined) {
|
|
1880
|
+
rebuilt[preserved] = previous[preserved];
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
addAuthoredFields(next, update.addFields ?? [], resolved.entityName, "Field names are case-insensitive. Use updateFields to change the existing one.");
|
|
1885
|
+
const diagnostics = validateEntity(next, {
|
|
1886
|
+
siblingNames: await siblingNamesFor(resolved.solutionDir, resolved.entityName, fs)
|
|
1887
|
+
});
|
|
1888
|
+
if (diagnostics.length > 0) {
|
|
1889
|
+
throw new InlineEntityError(`The edit would leave entity '${resolved.entityName}' invalid, so nothing was written`, diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join(`
|
|
1890
|
+
`));
|
|
1891
|
+
}
|
|
1892
|
+
await fs.writeFile(resolved.resourceFile, serialize(updateResourceSchema(resolved.resource, next)));
|
|
1893
|
+
return { entity: next, resourceFile: resolved.resourceFile };
|
|
1894
|
+
}
|
|
1895
|
+
function fieldIndexOf(entity, name) {
|
|
1896
|
+
return entity.Fields.findIndex((field) => typeof field?.Name === "string" && field.Name.toLowerCase() === name.toLowerCase());
|
|
1897
|
+
}
|
|
1898
|
+
function addAuthoredFields(next, fields, entityName, duplicateAdvice) {
|
|
1899
|
+
for (const add of fields) {
|
|
1900
|
+
const existing = next.Fields[fieldIndexOf(next, add.name)];
|
|
1901
|
+
if (isSystemField(existing)) {
|
|
1902
|
+
throw new InlineEntityError(`'${existing.Name}' is a system field on entity '${entityName}'`, "Data Fabric adds Id, CreateTime, CreatedBy, UpdateTime and UpdatedBy to every entity. Choose another name.");
|
|
1903
|
+
}
|
|
1904
|
+
if (existing !== undefined) {
|
|
1905
|
+
throw new InlineEntityError(`Entity '${entityName}' already has a field named '${add.name}'`, duplicateAdvice);
|
|
1906
|
+
}
|
|
1907
|
+
next.Fields.push(authorField(add));
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
function authorNewEntity(entityName, definition) {
|
|
1911
|
+
assertEntityTextInput(definition);
|
|
1912
|
+
const next = createEntitySkeleton(entityName);
|
|
1913
|
+
if (definition.displayName !== undefined) {
|
|
1914
|
+
next.DisplayName = definition.displayName;
|
|
1915
|
+
}
|
|
1916
|
+
if (definition.description !== undefined) {
|
|
1917
|
+
next.Description = definition.description;
|
|
1918
|
+
}
|
|
1919
|
+
addAuthoredFields(next, definition.addFields ?? [], entityName, "Field names are case-insensitive. Give each field a distinct name.");
|
|
1920
|
+
const diagnostics = validateEntity(next, { siblingNames: [] });
|
|
1921
|
+
if (diagnostics.length > 0) {
|
|
1922
|
+
throw new InlineEntityError(`Cannot create entity '${entityName}'`, diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join(`
|
|
1923
|
+
`));
|
|
1924
|
+
}
|
|
1925
|
+
return next;
|
|
1926
|
+
}
|
|
1927
|
+
function sdkTypeOf(field) {
|
|
1928
|
+
const pair = `${field.FieldDisplayType}:${field.SqlType.Name}`;
|
|
1929
|
+
const known = {
|
|
1930
|
+
"Basic:NVARCHAR": "STRING",
|
|
1931
|
+
"Basic:DECIMAL": "DECIMAL",
|
|
1932
|
+
"Basic:BIT": "BOOLEAN",
|
|
1933
|
+
"Basic:DATE": "DATE",
|
|
1934
|
+
"Basic:DATETIMEOFFSET": "DATETIME_WITH_TZ",
|
|
1935
|
+
"Basic:MULTILINE": "MULTILINE_TEXT",
|
|
1936
|
+
"Basic:MULTILINE_MAX": "MULTILINE_MAX",
|
|
1937
|
+
"MultiLineText:MULTILINE": "MULTILINE_TEXT",
|
|
1938
|
+
"MultiLineText:MULTILINE_MAX": "MULTILINE_MAX",
|
|
1939
|
+
"AutoNumber:DECIMAL": "AUTO_NUMBER",
|
|
1940
|
+
"File:UNIQUEIDENTIFIER": "FILE"
|
|
1941
|
+
};
|
|
1942
|
+
const type = known[pair];
|
|
1943
|
+
if (type === undefined) {
|
|
1944
|
+
throw new InlineEntityError(`Field type ${pair} cannot be edited by the inline commands`, "Only fields authored from the supported type list can be changed here. Edit this one in Data Fabric.");
|
|
1945
|
+
}
|
|
1946
|
+
return type;
|
|
1947
|
+
}
|
|
1948
|
+
async function inlineEntityAddAsync(projectName, entityName, options = {}, authored) {
|
|
1949
|
+
requireAuthoredName(authored, entityName);
|
|
1950
|
+
const fs = fsOf();
|
|
1951
|
+
const { projectDir, solutionDir } = await resolveProjectAsync(projectName, options);
|
|
1952
|
+
await requireEntityProjectAsync(projectDir, projectName, solutionDir, fs);
|
|
1953
|
+
const stubFile = entityStubPath(projectDir, entityName, fs);
|
|
1954
|
+
let exists = false;
|
|
1955
|
+
try {
|
|
1956
|
+
exists = await fs.stat(stubFile) !== null;
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
if (!isMissingPathError(error)) {
|
|
1959
|
+
throw error;
|
|
1960
|
+
}
|
|
1961
|
+
exists = false;
|
|
1962
|
+
}
|
|
1963
|
+
if (exists) {
|
|
1964
|
+
throw new InlineEntityError(`Entity '${entityName}' already exists in project '${projectName}'`, `Edit it with 'uip df entities update ${entityName} --local'.`);
|
|
1965
|
+
}
|
|
1966
|
+
const document = authored ?? createEntitySkeleton(entityName);
|
|
1967
|
+
const diagnostics = validateEntity(document, {
|
|
1968
|
+
siblingNames: await collectSolutionEntityNames(solutionDir, fs)
|
|
1969
|
+
});
|
|
1970
|
+
if (diagnostics.length > 0) {
|
|
1971
|
+
throw new InlineEntityError(`Cannot create entity '${entityName}'`, diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join(`
|
|
1972
|
+
`));
|
|
1973
|
+
}
|
|
1974
|
+
const relativeResourcePath = entityResourcePath(entityName);
|
|
1975
|
+
const resourceFile = fs.path.join(solutionDir, ...relativeResourcePath.split("/"));
|
|
1976
|
+
let resourceExists = false;
|
|
1977
|
+
try {
|
|
1978
|
+
resourceExists = await fs.stat(resourceFile) !== null;
|
|
1979
|
+
} catch (error) {
|
|
1980
|
+
if (!isMissingPathError(error)) {
|
|
1981
|
+
throw error;
|
|
1982
|
+
}
|
|
1983
|
+
resourceExists = false;
|
|
1984
|
+
}
|
|
1985
|
+
if (resourceExists) {
|
|
1986
|
+
throw new InlineEntityError(`An entity definition for '${entityName}' already exists in this solution`, `'${relativeResourcePath}' is already present. Entity names are solution-wide unique — pick a different name, or edit the existing entity with 'uip df entities update ${entityName} --local'. If no .entity stub points at it (an interrupted create or delete leaves one behind), clear it with 'uip df entities delete ${entityName} --local --project-name ${projectName} --force --yes'.`);
|
|
1987
|
+
}
|
|
1988
|
+
await assertInsideSolutionAsync(resourceFile, solutionDir, fs);
|
|
1989
|
+
await assertInsideSolutionAsync(stubFile, solutionDir, fs);
|
|
1990
|
+
await fs.mkdir(fs.path.dirname(resourceFile));
|
|
1991
|
+
await fs.writeFile(resourceFile, serialize(wrapEntityJson(document)));
|
|
1992
|
+
await fs.writeFile(stubFile, serialize({ name: entityName, resourcePath: relativeResourcePath }));
|
|
1993
|
+
return { entityFile: stubFile, resourceFile };
|
|
1994
|
+
}
|
|
1995
|
+
async function inlineEntityDeleteAsync(projectName, entityName, options = {}) {
|
|
1996
|
+
const fs = fsOf();
|
|
1997
|
+
const { projectDir, solutionDir } = await resolveProjectAsync(projectName, options);
|
|
1998
|
+
const stubFile = entityStubPath(projectDir, entityName, fs);
|
|
1999
|
+
const checked = await checkedPairAsync(stubFile, solutionDir, fs);
|
|
2000
|
+
if (checked.ok) {
|
|
2001
|
+
const { pair } = checked;
|
|
2002
|
+
requireLocallyAuthored({
|
|
2003
|
+
entityName: pair.entityName,
|
|
2004
|
+
entity: pair.entity
|
|
2005
|
+
});
|
|
2006
|
+
await assertInsideSolutionAsync(pair.resourceFile, solutionDir, fs);
|
|
2007
|
+
const shared = await derivedResourceOwnershipProblem(pair.resourceFile, projectName, pair.entityName, solutionDir, fs);
|
|
2008
|
+
if (shared !== undefined) {
|
|
2009
|
+
throw new InlineEntityError(`Refusing to delete entity '${pair.entityName}' from project '${projectName}'`, shared);
|
|
2010
|
+
}
|
|
2011
|
+
await fs.rm(stubFile);
|
|
2012
|
+
await fs.rm(pair.resourceFile);
|
|
2013
|
+
return { stubFile, resourceFile: pair.resourceFile };
|
|
2014
|
+
}
|
|
2015
|
+
if (!options.force) {
|
|
2016
|
+
const stubMissing = !await pathOrLinkExistsAsync(stubFile, fs);
|
|
2017
|
+
const known = (await stubNamesAsync(projectDir, fs)).map((name) => fs.path.basename(name, ENTITY_EXTENSION_CONST));
|
|
2018
|
+
throw new InlineEntityError(`Entity '${entityName}' is not usable in project '${projectName}': ${checked.problem}`, stubMissing ? known.length === 0 ? `Project '${projectName}' has no entities.` : `Entities in this project: ${known.join(", ")}.` : `Add --force to delete it anyway: that removes the stub and the definition resource for '${entityName}' without needing either to parse. It still refuses when it cannot prove the files are this project's to remove.`);
|
|
2019
|
+
}
|
|
2020
|
+
const derived = fs.path.join(solutionDir, ...entityResourcePath(entityName).split("/"));
|
|
2021
|
+
const stubIsLink = await isSymlinkEntryAsync(stubFile, fs);
|
|
2022
|
+
const stubExists = stubIsLink || await pathExistsAsync(stubFile, fs);
|
|
2023
|
+
const pointed = stubExists && !stubIsLink ? await stubResourcePathAsync(stubFile, entityName, solutionDir, fs) : undefined;
|
|
2024
|
+
const candidates = [];
|
|
2025
|
+
if (pointed !== undefined && await pathOrLinkExistsAsync(pointed, fs)) {
|
|
2026
|
+
candidates.push(pointed);
|
|
2027
|
+
}
|
|
2028
|
+
if (await pathOrLinkExistsAsync(derived, fs)) {
|
|
2029
|
+
candidates.push(derived);
|
|
2030
|
+
}
|
|
2031
|
+
for (const candidate of candidates) {
|
|
2032
|
+
await assertResourceRemovableAsync(candidate, projectName, entityName, solutionDir, fs);
|
|
2033
|
+
}
|
|
2034
|
+
if (!stubExists && candidates.length === 0) {
|
|
2035
|
+
throw new InlineEntityError(`Nothing to delete for entity '${entityName}' in project '${projectName}'`, `Neither '${stubFile}' nor a definition resource for '${entityName}' is on disk.`);
|
|
2036
|
+
}
|
|
2037
|
+
const removed = { forced: true };
|
|
2038
|
+
if (stubExists) {
|
|
2039
|
+
await fs.rm(stubFile);
|
|
2040
|
+
removed.stubFile = stubFile;
|
|
2041
|
+
}
|
|
2042
|
+
const removedPaths = [];
|
|
2043
|
+
for (const candidate of candidates) {
|
|
2044
|
+
if (await pathOrLinkExistsAsync(candidate, fs)) {
|
|
2045
|
+
await fs.rm(candidate);
|
|
2046
|
+
removedPaths.push(candidate);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
removed.resourceFile = removedPaths[0];
|
|
2050
|
+
return removed;
|
|
2051
|
+
}
|
|
2052
|
+
async function assertResourceRemovableAsync(resource, projectName, entityName, solutionDir, fs) {
|
|
2053
|
+
if (await isSymlinkEntryAsync(resource, fs)) {
|
|
2054
|
+
await assertInsideSolutionAsync(fs.path.dirname(resource), solutionDir, fs);
|
|
2055
|
+
const blocked2 = await derivedResourceOwnershipProblem(resource, projectName, entityName, solutionDir, fs, { ownersOnly: true });
|
|
2056
|
+
if (blocked2 !== undefined) {
|
|
2057
|
+
throw new InlineEntityError(`Refusing to delete the definition resource for '${entityName}'`, blocked2);
|
|
2058
|
+
}
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
await assertInsideSolutionAsync(resource, solutionDir, fs);
|
|
2062
|
+
const stat = await fs.stat(resource);
|
|
2063
|
+
if (stat !== null && !stat.isFile()) {
|
|
2064
|
+
throw new InlineEntityError(`Refusing to delete '${resource}'`, "It is a directory, not an entity definition file. Remove it by hand if it is not needed.");
|
|
2065
|
+
}
|
|
2066
|
+
const blocked = await derivedResourceOwnershipProblem(resource, projectName, entityName, solutionDir, fs);
|
|
2067
|
+
if (blocked !== undefined) {
|
|
2068
|
+
throw new InlineEntityError(`Refusing to delete the definition resource for '${entityName}'`, blocked);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
async function inlineEntityDeleteOrphanAsync(entityName, options = {}) {
|
|
2072
|
+
const fs = fsOf();
|
|
2073
|
+
const nameError = validateNameFormat(entityName, "entity");
|
|
2074
|
+
if (nameError) {
|
|
2075
|
+
throw new InlineEntityError(nameError.message, nameError.instructions);
|
|
2076
|
+
}
|
|
2077
|
+
const solutionDir = await solutionRootAsync(options);
|
|
2078
|
+
const resource = fs.path.join(solutionDir, ...entityResourcePath(entityName).split("/"));
|
|
2079
|
+
if (!await pathOrLinkExistsAsync(resource, fs)) {
|
|
2080
|
+
throw new InlineEntityError(`Entity '${entityName}' not found`, `No project declares it and no definition resource for it is at '${resource}'.`, INLINE_ENTITY_ERROR_CODES.entityNotFound);
|
|
2081
|
+
}
|
|
2082
|
+
await assertResourceRemovableAsync(resource, "", entityName, solutionDir, fs);
|
|
2083
|
+
await fs.rm(resource);
|
|
2084
|
+
return { resourceFile: resource, forced: true };
|
|
2085
|
+
}
|
|
2086
|
+
async function pathOrLinkExistsAsync(path, fs) {
|
|
2087
|
+
return await isSymlinkEntryAsync(path, fs) || await pathExistsAsync(path, fs);
|
|
2088
|
+
}
|
|
2089
|
+
async function pathExistsAsync(path, fs) {
|
|
2090
|
+
try {
|
|
2091
|
+
return await fs.stat(path) !== null;
|
|
2092
|
+
} catch (error) {
|
|
2093
|
+
if (isMissingPathError(error)) {
|
|
2094
|
+
return false;
|
|
2095
|
+
}
|
|
2096
|
+
throw error;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
async function stubResourcePathAsync(stubFile, entityName, solutionDir, fs) {
|
|
2100
|
+
let pointer;
|
|
2101
|
+
try {
|
|
2102
|
+
const raw = await fs.readFile(stubFile, "utf-8");
|
|
2103
|
+
if (raw === null)
|
|
2104
|
+
return;
|
|
2105
|
+
pointer = JSON.parse(raw).resourcePath;
|
|
2106
|
+
} catch (error) {
|
|
2107
|
+
if (isUnreadablePathError(error))
|
|
2108
|
+
throw error;
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
if (typeof pointer !== "string")
|
|
2112
|
+
return;
|
|
2113
|
+
const solutionRoot = fs.path.resolve(solutionDir);
|
|
2114
|
+
const resolved = fs.path.resolve(solutionRoot, ...pointer.split("/"));
|
|
2115
|
+
const boundary = resolved.charAt(solutionRoot.length);
|
|
2116
|
+
if (!resolved.startsWith(solutionRoot) || boundary !== "/" && boundary !== "\\") {
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
2119
|
+
const canonicalTree = await canonicalPathAsync(entityTreeDir(solutionRoot, fs), fs);
|
|
2120
|
+
const canonical = await canonicalPathAsync(resolved, fs);
|
|
2121
|
+
const parent = fs.path.dirname(canonical);
|
|
2122
|
+
const sameDir = parent.toLowerCase() === canonicalTree.toLowerCase();
|
|
2123
|
+
const expected = `${entityName}.json`.toLowerCase();
|
|
2124
|
+
if (!sameDir || fs.path.basename(canonical).toLowerCase() !== expected) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
let stat = null;
|
|
2128
|
+
try {
|
|
2129
|
+
stat = await fs.stat(canonical);
|
|
2130
|
+
} catch (error) {
|
|
2131
|
+
if (!isMissingPathError(error))
|
|
2132
|
+
throw error;
|
|
2133
|
+
}
|
|
2134
|
+
if (stat !== null && !stat.isFile()) {
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
return canonical;
|
|
2138
|
+
}
|
|
2139
|
+
function entityTreeDir(solutionRoot, fs) {
|
|
2140
|
+
return fs.path.resolve(solutionRoot, "resources", SOLUTION_FOLDER, ...ENTITY_RESOURCE_DIR.split("/"));
|
|
2141
|
+
}
|
|
2142
|
+
async function derivedResourceOwnershipProblem(derived, projectName, entityName, solutionDir, fs, options = {}) {
|
|
2143
|
+
let owners;
|
|
2144
|
+
try {
|
|
2145
|
+
owners = await findProjectsOwningEntity(solutionDir, entityName, fs);
|
|
2146
|
+
} catch (error) {
|
|
2147
|
+
return `Could not check whether another project still declares an entity named '${entityName}' (${error instanceof Error ? error.message : String(error)}), and the definition resource is shared by name across the solution. Fix access to the solution's project directories and retry.`;
|
|
2148
|
+
}
|
|
2149
|
+
const others = owners.filter((owner) => owner.projectName.toLowerCase() !== projectName.toLowerCase());
|
|
2150
|
+
if (others.length > 0) {
|
|
2151
|
+
return `'${others.map((owner) => owner.projectName).join("', '")}' still declare an entity named '${entityName}', and the definition resource is shared by name across the solution. Delete it from there instead, or remove those stubs first.`;
|
|
2152
|
+
}
|
|
2153
|
+
if (options.ownersOnly)
|
|
2154
|
+
return;
|
|
2155
|
+
let entity;
|
|
2156
|
+
try {
|
|
2157
|
+
const raw = await fs.readFile(derived, "utf-8");
|
|
2158
|
+
if (typeof raw !== "string")
|
|
2159
|
+
return;
|
|
2160
|
+
entity = unwrapResource(JSON.parse(raw));
|
|
2161
|
+
} catch (error) {
|
|
2162
|
+
if (isUnreadablePathError(error)) {
|
|
2163
|
+
return `Could not read the definition resource '${derived}' (${messageOf(error)}), so whether it is safe to delete cannot be checked. Fix access to the file and retry.`;
|
|
2164
|
+
}
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
if (!isLocallyAuthored(entity)) {
|
|
2168
|
+
return `It describes a platform entity this solution references, not one authored here — it resolves to Data Fabric folder '${entity.FolderId}'. Remove the reference with 'uip solution resources remove' instead; deleting the file drops the reference without recording it.`;
|
|
2169
|
+
}
|
|
2170
|
+
return;
|
|
2171
|
+
}
|
|
2172
|
+
// src/commands/entities-inline.ts
|
|
2173
|
+
var NOT_FOUND_CODES = new Set([
|
|
2174
|
+
INLINE_ENTITY_ERROR_CODES.projectNotFound,
|
|
2175
|
+
INLINE_ENTITY_ERROR_CODES.noParentSolution,
|
|
2176
|
+
INLINE_ENTITY_ERROR_CODES.entityNotFound
|
|
2177
|
+
]);
|
|
2178
|
+
function isFilesystemFault(error) {
|
|
2179
|
+
const code = error?.code;
|
|
2180
|
+
return typeof code === "string" && /^E[A-Z]+$/.test(code);
|
|
2181
|
+
}
|
|
2182
|
+
function failFromService(error) {
|
|
2183
|
+
if (error instanceof InlineEntityError) {
|
|
2184
|
+
failWithCode(error.message, error.instructions, error.code !== undefined && NOT_FOUND_CODES.has(error.code) ? "not_found" : "invalid_argument");
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2187
|
+
if (error instanceof AuthoredFieldError) {
|
|
2188
|
+
failWithCode(error.message, error.instructions, "invalid_argument");
|
|
2189
|
+
return;
|
|
2190
|
+
}
|
|
2191
|
+
throw error;
|
|
2192
|
+
}
|
|
2193
|
+
var LOCAL_AUTHORING_AVAILABLE = true;
|
|
2194
|
+
async function runLocalCreate(name, options) {
|
|
2195
|
+
const project = options.projectName ?? name;
|
|
2196
|
+
const entity = name;
|
|
2197
|
+
const authored = await readCreateBodyAsync(entity, options);
|
|
2198
|
+
if (authored === FAILED)
|
|
2199
|
+
return;
|
|
2200
|
+
const [resolveError] = await catchError(resolveProjectAsync(project));
|
|
2201
|
+
if (resolveError instanceof InlineEntityError && resolveError.code === INLINE_ENTITY_ERROR_CODES.noParentSolution) {
|
|
2202
|
+
return failFromService(resolveError);
|
|
2203
|
+
}
|
|
2204
|
+
if (resolveError && !(resolveError instanceof InlineEntityError && resolveError.code === INLINE_ENTITY_ERROR_CODES.projectNotFound)) {
|
|
2205
|
+
if (resolveError instanceof InlineEntityError) {
|
|
2206
|
+
return failFromService(resolveError);
|
|
2207
|
+
}
|
|
2208
|
+
return fail(`Could not resolve Entity project '${project}'`, resolveError.message);
|
|
2209
|
+
}
|
|
2210
|
+
if (resolveError) {
|
|
2211
|
+
const [rootError, root] = await catchError(solutionRootAsync({ cwd: process.cwd() }));
|
|
2212
|
+
if (rootError)
|
|
2213
|
+
return failFromService(rootError);
|
|
2214
|
+
const [initError, result] = await catchError(entityInitAsync(project, {
|
|
2215
|
+
cwd: root,
|
|
2216
|
+
firstEntityName: entity,
|
|
2217
|
+
firstEntity: authored
|
|
2218
|
+
}));
|
|
2219
|
+
if (initError) {
|
|
2220
|
+
if (isFilesystemFault(initError)) {
|
|
2221
|
+
return fail(`Could not create Entity project '${project}'`, initError.message);
|
|
2222
|
+
}
|
|
2223
|
+
return failWithCode(`Could not create Entity project '${project}'`, initError.message, "invalid_argument");
|
|
2224
|
+
}
|
|
2225
|
+
const scaffolded = authoredFieldNames(authored);
|
|
2226
|
+
return OutputFormatter.success({
|
|
2227
|
+
Result: RESULTS.Success,
|
|
2228
|
+
Code: "InlineEntityCreated",
|
|
2229
|
+
Data: {
|
|
2230
|
+
Project: project,
|
|
2231
|
+
Entity: entity,
|
|
2232
|
+
EntityFile: result?.entityFile,
|
|
2233
|
+
ResourceFile: result?.resourceFile,
|
|
2234
|
+
Created: "project",
|
|
2235
|
+
SolutionRegistration: result?.registration,
|
|
2236
|
+
...scaffolded.length > 0 && { Fields: scaffolded }
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
const [addError, added] = await catchError(inlineEntityAddAsync(project, entity, {}, authored));
|
|
2241
|
+
if (addError)
|
|
2242
|
+
return failFromService(addError);
|
|
2243
|
+
const fields = authoredFieldNames(authored);
|
|
2244
|
+
OutputFormatter.success({
|
|
2245
|
+
Result: RESULTS.Success,
|
|
2246
|
+
Code: "InlineEntityCreated",
|
|
2247
|
+
Data: {
|
|
2248
|
+
Project: project,
|
|
2249
|
+
Entity: entity,
|
|
2250
|
+
EntityFile: added?.entityFile,
|
|
2251
|
+
ResourceFile: added?.resourceFile,
|
|
2252
|
+
Created: "entity",
|
|
2253
|
+
...fields.length > 0 && { Fields: fields }
|
|
2254
|
+
}
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
var FAILED = Symbol("failed");
|
|
2258
|
+
async function readCreateBodyAsync(entity, options) {
|
|
2259
|
+
if (options.body === undefined && options.file === undefined) {
|
|
2260
|
+
return authorOrFail(entity, {});
|
|
2261
|
+
}
|
|
2262
|
+
const [parseError, parsed] = await catchError(readJsonInput(options.file, options.body, "Provide entity definition via --file or --body."));
|
|
2263
|
+
if (parseError) {
|
|
2264
|
+
failInvalidArgument("Error parsing entity definition", parseError.message);
|
|
2265
|
+
return FAILED;
|
|
2266
|
+
}
|
|
2267
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
2268
|
+
failInvalidArgument("Entity definition must be a JSON object", `Provide a JSON object with ${keyList(CREATE_BODY_KEYS)}.`);
|
|
2269
|
+
return FAILED;
|
|
2270
|
+
}
|
|
2271
|
+
const definition = parsed;
|
|
2272
|
+
if (!rejectUnsupportedKeys(definition, {
|
|
2273
|
+
accepted: CREATE_BODY_KEYS,
|
|
2274
|
+
where: "the entity definition",
|
|
2275
|
+
tenantOnly: TENANT_ONLY_ENTITY_KEYS,
|
|
2276
|
+
federated: federatedKeysIn(definition)
|
|
2277
|
+
})) {
|
|
2278
|
+
return FAILED;
|
|
2279
|
+
}
|
|
2280
|
+
const body = {};
|
|
2281
|
+
for (const [from, to] of Object.entries(CREATE_BODY_KEYS)) {
|
|
2282
|
+
if (definition[from] !== undefined) {
|
|
2283
|
+
body[to] = definition[from];
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
if (!validateLocalBody(body, {
|
|
2287
|
+
addFieldsLabel: "fields",
|
|
2288
|
+
entityName: entity
|
|
2289
|
+
})) {
|
|
2290
|
+
return FAILED;
|
|
2291
|
+
}
|
|
2292
|
+
return authorOrFail(entity, body);
|
|
2293
|
+
}
|
|
2294
|
+
function authorOrFail(entity, body) {
|
|
2295
|
+
const [authorError, authored] = catchError(() => authorNewEntity(entity, body));
|
|
2296
|
+
if (authorError) {
|
|
2297
|
+
failFromService(authorError);
|
|
2298
|
+
return FAILED;
|
|
2299
|
+
}
|
|
2300
|
+
return authored;
|
|
2301
|
+
}
|
|
2302
|
+
function authoredFieldNames(authored) {
|
|
2303
|
+
return (authored?.Fields ?? []).filter((field) => !field.IsSystemField).map((field) => field.Name);
|
|
2304
|
+
}
|
|
2305
|
+
async function runLocalList(options) {
|
|
2306
|
+
const project = options.projectName;
|
|
2307
|
+
if (project === undefined) {
|
|
2308
|
+
const [allError, all] = await catchError(inlineEntityListAllAsync());
|
|
2309
|
+
if (allError)
|
|
2310
|
+
return failFromService(allError);
|
|
2311
|
+
OutputFormatter.success({
|
|
2312
|
+
Result: RESULTS.Success,
|
|
2313
|
+
Code: "InlineEntityList",
|
|
2314
|
+
Data: (all ?? []).map((entity) => ({
|
|
2315
|
+
Project: entity.projectName,
|
|
2316
|
+
Entity: entity.projectProblem === undefined ? entity.name : undefined,
|
|
2317
|
+
EntityFile: entity.projectProblem === undefined ? entity.stubFile : undefined,
|
|
2318
|
+
ResourceFile: entity.resourceFile,
|
|
2319
|
+
LocallyAuthored: entity.locallyAuthored,
|
|
2320
|
+
Problem: entity.projectProblem ?? entity.problem
|
|
2321
|
+
}))
|
|
2322
|
+
});
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
const [listError, list] = await catchError(inlineEntityListAsync(project));
|
|
2326
|
+
if (listError)
|
|
2327
|
+
return failFromService(listError);
|
|
2328
|
+
OutputFormatter.success({
|
|
2329
|
+
Result: RESULTS.Success,
|
|
2330
|
+
Code: "InlineEntityList",
|
|
2331
|
+
Data: (list ?? []).map((entity) => ({
|
|
2332
|
+
Entity: entity.name,
|
|
2333
|
+
EntityFile: entity.stubFile,
|
|
2334
|
+
ResourceFile: entity.resourceFile,
|
|
2335
|
+
LocallyAuthored: entity.locallyAuthored,
|
|
2336
|
+
Problem: entity.problem
|
|
2337
|
+
}))
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
async function resolveLocalTargetAsync(name, projectName) {
|
|
2341
|
+
if (projectName === undefined) {
|
|
2342
|
+
const owner2 = await resolveOwningProjectAsync(name);
|
|
2343
|
+
return {
|
|
2344
|
+
project: owner2.projectName,
|
|
2345
|
+
entity: owner2.entityName,
|
|
2346
|
+
scope: { cwd: owner2.solutionDir }
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
const owner = await resolveOwningProjectAsync(name).catch(() => {
|
|
2350
|
+
return;
|
|
2351
|
+
});
|
|
2352
|
+
if (owner?.projectName.toLowerCase() === projectName.toLowerCase()) {
|
|
2353
|
+
return {
|
|
2354
|
+
project: owner.projectName,
|
|
2355
|
+
entity: owner.entityName,
|
|
2356
|
+
scope: { cwd: owner.solutionDir }
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
return { project: projectName, entity: name, scope: {} };
|
|
2360
|
+
}
|
|
2361
|
+
async function resolveLocalTargetOrFailAsync(name, projectName) {
|
|
2362
|
+
const [error, target] = await catchError(resolveLocalTargetAsync(name, projectName));
|
|
2363
|
+
if (error)
|
|
2364
|
+
return failFromService(error);
|
|
2365
|
+
return target;
|
|
2366
|
+
}
|
|
2367
|
+
async function runLocalGet(name, options) {
|
|
2368
|
+
const target = await resolveLocalTargetOrFailAsync(name, options.projectName);
|
|
2369
|
+
if (target === undefined)
|
|
2370
|
+
return;
|
|
2371
|
+
const { project, entity, scope } = target;
|
|
2372
|
+
const [getError, document] = await catchError(inlineEntityGetAsync(project, entity, scope));
|
|
2373
|
+
if (getError)
|
|
2374
|
+
return failFromService(getError);
|
|
2375
|
+
OutputFormatter.success({
|
|
2376
|
+
Result: RESULTS.Success,
|
|
2377
|
+
Code: "InlineEntitySchema",
|
|
2378
|
+
Data: document
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
async function readUpdateBodyAsync(name, options) {
|
|
2382
|
+
const [parseError, parsed] = await catchError(readJsonInput(options.file, options.body, "Provide update options via --file or --body."));
|
|
2383
|
+
if (parseError) {
|
|
2384
|
+
failInvalidArgument("Error parsing update options", parseError.message);
|
|
2385
|
+
return FAILED;
|
|
2386
|
+
}
|
|
2387
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
2388
|
+
failInvalidArgument("Update options must be a JSON object", `Provide a JSON object with ${keyList(UPDATE_BODY_KEYS)}.`);
|
|
2389
|
+
return FAILED;
|
|
2390
|
+
}
|
|
2391
|
+
const definition = parsed;
|
|
2392
|
+
if (!rejectUnsupportedKeys(definition, {
|
|
2393
|
+
accepted: UPDATE_BODY_KEYS,
|
|
2394
|
+
where: "the update body",
|
|
2395
|
+
tenantOnly: TENANT_ONLY_ENTITY_KEYS,
|
|
2396
|
+
federated: federatedKeysIn(definition)
|
|
2397
|
+
})) {
|
|
2398
|
+
return FAILED;
|
|
2399
|
+
}
|
|
2400
|
+
const body = definition;
|
|
2401
|
+
if (!hasAnythingToApply(body)) {
|
|
2402
|
+
failInvalidArgument("Update body has nothing to apply", `Provide at least one of ${keyList(UPDATE_BODY_KEYS)}; an empty field list changes nothing.`);
|
|
2403
|
+
return FAILED;
|
|
2404
|
+
}
|
|
2405
|
+
if (!validateLocalBody(body, {
|
|
2406
|
+
addFieldsLabel: "addFields",
|
|
2407
|
+
entityName: name
|
|
2408
|
+
})) {
|
|
2409
|
+
return FAILED;
|
|
2410
|
+
}
|
|
2411
|
+
return body;
|
|
2412
|
+
}
|
|
2413
|
+
async function runLocalUpdate(name, options) {
|
|
2414
|
+
const body = await readUpdateBodyAsync(name, options);
|
|
2415
|
+
if (body === FAILED)
|
|
2416
|
+
return;
|
|
2417
|
+
const target = await resolveLocalTargetOrFailAsync(name, options.projectName);
|
|
2418
|
+
if (target === undefined)
|
|
2419
|
+
return;
|
|
2420
|
+
const { project, entity, scope } = target;
|
|
2421
|
+
const [updateError, updated] = await catchError(inlineEntityUpdateAsync(project, entity, body, scope));
|
|
2422
|
+
if (updateError)
|
|
2423
|
+
return failFromService(updateError);
|
|
2424
|
+
OutputFormatter.success({
|
|
2425
|
+
Result: RESULTS.Success,
|
|
2426
|
+
Code: "InlineEntityUpdated",
|
|
2427
|
+
Data: {
|
|
2428
|
+
Project: project,
|
|
2429
|
+
Entity: updated?.entity.Name,
|
|
2430
|
+
ResourceFile: updated?.resourceFile,
|
|
2431
|
+
Fields: authoredFieldNames(updated?.entity)
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
async function runLocalValidateAll() {
|
|
2436
|
+
const [listError, all] = await catchError(inlineEntityListAllAsync());
|
|
2437
|
+
if (listError)
|
|
2438
|
+
return failFromService(listError);
|
|
2439
|
+
const scope = all?.[0]?.solutionDir ? { cwd: all[0].solutionDir } : {};
|
|
2440
|
+
const rows = [];
|
|
2441
|
+
const projects = [];
|
|
2442
|
+
for (const row of all ?? []) {
|
|
2443
|
+
if (row.projectProblem !== undefined) {
|
|
2444
|
+
rows.push({
|
|
2445
|
+
Project: row.projectName,
|
|
2446
|
+
ProjectProblem: row.projectProblem,
|
|
2447
|
+
Diagnostics: []
|
|
2448
|
+
});
|
|
2449
|
+
continue;
|
|
2450
|
+
}
|
|
2451
|
+
if (!projects.includes(row.projectName)) {
|
|
2452
|
+
projects.push(row.projectName);
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
if (projects.length === 0 && rows.length === 0) {
|
|
2456
|
+
OutputFormatter.success({
|
|
2457
|
+
Result: RESULTS.Success,
|
|
2458
|
+
Code: "InlineEntityValidated",
|
|
2459
|
+
Data: { Valid: true, Entities: [] }
|
|
2460
|
+
});
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
for (const project of projects) {
|
|
2464
|
+
const [validateError, results] = await catchError(inlineEntityValidateAsync(project, scope));
|
|
2465
|
+
if (validateError)
|
|
2466
|
+
return failFromService(validateError);
|
|
2467
|
+
for (const result of results ?? []) {
|
|
2468
|
+
rows.push({
|
|
2469
|
+
Project: project,
|
|
2470
|
+
Entity: result.entityName,
|
|
2471
|
+
ResourceFile: result.resourceFile,
|
|
2472
|
+
PairProblem: result.pairProblem,
|
|
2473
|
+
Diagnostics: result.diagnostics.map((diagnostic) => ({
|
|
2474
|
+
Code: diagnostic.code,
|
|
2475
|
+
Message: diagnostic.message,
|
|
2476
|
+
Field: diagnostic.fieldName
|
|
2477
|
+
}))
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
const valid = rows.every((row) => row.ProjectProblem === undefined && row.PairProblem === undefined && row.Diagnostics.length === 0);
|
|
2482
|
+
if (!valid) {
|
|
2483
|
+
return failValidation("Entity validation failed", rows);
|
|
2484
|
+
}
|
|
2485
|
+
OutputFormatter.success({
|
|
2486
|
+
Result: RESULTS.Success,
|
|
2487
|
+
Code: "InlineEntityValidated",
|
|
2488
|
+
Data: { Valid: true, Entities: rows }
|
|
2489
|
+
});
|
|
2490
|
+
}
|
|
2491
|
+
async function runLocalValidate(name, options) {
|
|
2492
|
+
if (name === undefined && options.projectName === undefined) {
|
|
2493
|
+
return runLocalValidateAll();
|
|
2494
|
+
}
|
|
2495
|
+
const target = name !== undefined ? await resolveLocalTargetOrFailAsync(name, options.projectName) : {
|
|
2496
|
+
project: options.projectName,
|
|
2497
|
+
entity: undefined,
|
|
2498
|
+
scope: {}
|
|
2499
|
+
};
|
|
2500
|
+
if (target === undefined)
|
|
2501
|
+
return;
|
|
2502
|
+
const resolvedName = target.project;
|
|
2503
|
+
const [validateError, results] = await catchError(inlineEntityValidateAsync(resolvedName, {
|
|
2504
|
+
...target.scope,
|
|
2505
|
+
...target.entity !== undefined && { entityName: target.entity }
|
|
2506
|
+
}));
|
|
2507
|
+
if (validateError)
|
|
2508
|
+
return failFromService(validateError);
|
|
2509
|
+
const rows = (results ?? []).map((result) => ({
|
|
2510
|
+
Entity: result.entityName,
|
|
2511
|
+
ResourceFile: result.resourceFile,
|
|
2512
|
+
PairProblem: result.pairProblem,
|
|
2513
|
+
Diagnostics: result.diagnostics.map((diagnostic) => ({
|
|
2514
|
+
Code: diagnostic.code,
|
|
2515
|
+
Message: diagnostic.message,
|
|
2516
|
+
Field: diagnostic.fieldName
|
|
2517
|
+
}))
|
|
2518
|
+
}));
|
|
2519
|
+
const valid = rows.every((row) => row.PairProblem === undefined && row.Diagnostics.length === 0);
|
|
2520
|
+
if (!valid) {
|
|
2521
|
+
return failValidation(`Entity validation failed for project '${resolvedName}'`, rows);
|
|
2522
|
+
}
|
|
2523
|
+
OutputFormatter.success({
|
|
2524
|
+
Result: RESULTS.Success,
|
|
2525
|
+
Code: "InlineEntityValidated",
|
|
2526
|
+
Data: { Project: resolvedName, Valid: true, Entities: rows }
|
|
2527
|
+
});
|
|
2528
|
+
}
|
|
2529
|
+
async function runLocalDelete(name, options) {
|
|
2530
|
+
if (options.force === true && options.projectName === undefined) {
|
|
2531
|
+
const [lookupError] = await catchError(resolveOwningProjectAsync(name));
|
|
2532
|
+
if (lookupError instanceof InlineEntityError && lookupError.code === INLINE_ENTITY_ERROR_CODES.entityNotFound) {
|
|
2533
|
+
return runLocalDeleteOrphan(name, options);
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
const target = await resolveLocalTargetOrFailAsync(name, options.projectName);
|
|
2537
|
+
if (target === undefined)
|
|
2538
|
+
return;
|
|
2539
|
+
const { project, entity, scope } = target;
|
|
2540
|
+
const confirmed = requireDestructiveConfirmation({ ...options, reason: "local" }, `delete the authored entity '${entity}' from project '${project}'`, "Pass --yes to confirm. The .entity stub and its definition resource are both removed.");
|
|
2541
|
+
if (confirmed === null)
|
|
2542
|
+
return;
|
|
2543
|
+
const [deleteError, removed] = await catchError(inlineEntityDeleteAsync(project, entity, {
|
|
2544
|
+
...scope,
|
|
2545
|
+
...options.force === true && { force: true }
|
|
2546
|
+
}));
|
|
2547
|
+
if (deleteError)
|
|
2548
|
+
return failFromService(deleteError);
|
|
2549
|
+
OutputFormatter.success({
|
|
2550
|
+
Result: RESULTS.Success,
|
|
2551
|
+
Code: "InlineEntityDeleted",
|
|
2552
|
+
Data: {
|
|
2553
|
+
Project: project,
|
|
2554
|
+
Entity: entity,
|
|
2555
|
+
EntityFile: removed?.stubFile,
|
|
2556
|
+
ResourceFile: removed?.resourceFile,
|
|
2557
|
+
...removed?.forced === true && { Forced: true }
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
function reportInvalid(message, instructions) {
|
|
2562
|
+
failInvalidArgument(message, instructions);
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
var CREATE_BODY_KEYS = {
|
|
2566
|
+
fields: "addFields",
|
|
2567
|
+
displayName: "displayName",
|
|
2568
|
+
description: "description"
|
|
2569
|
+
};
|
|
2570
|
+
var REMOVE_FIELD_KEYS = { name: true };
|
|
2571
|
+
var SDK_ENTITY_KEYS = {
|
|
2572
|
+
addFields: "local",
|
|
2573
|
+
updateFields: "local",
|
|
2574
|
+
removeFields: "local",
|
|
2575
|
+
displayName: "local",
|
|
2576
|
+
description: "local",
|
|
2577
|
+
isRbacEnabled: "tenant",
|
|
2578
|
+
isAnalyticsEnabled: "tenant",
|
|
2579
|
+
folderKey: "tenant",
|
|
2580
|
+
externalFields: "federated"
|
|
2581
|
+
};
|
|
2582
|
+
var SDK_FIELD_KEYS = {
|
|
2583
|
+
name: "local",
|
|
2584
|
+
type: "local",
|
|
2585
|
+
displayName: "local",
|
|
2586
|
+
description: "local",
|
|
2587
|
+
isRequired: "local",
|
|
2588
|
+
isUnique: "local",
|
|
2589
|
+
lengthLimit: "local",
|
|
2590
|
+
decimalPrecision: "local",
|
|
2591
|
+
maxValue: "local",
|
|
2592
|
+
minValue: "local",
|
|
2593
|
+
defaultValue: "local",
|
|
2594
|
+
id: "tenant",
|
|
2595
|
+
isRbacEnabled: "tenant",
|
|
2596
|
+
isEncrypted: "tenant",
|
|
2597
|
+
isHiddenField: "tenant",
|
|
2598
|
+
choiceSetId: "tenant",
|
|
2599
|
+
referenceEntityId: "tenant",
|
|
2600
|
+
referenceFieldId: "tenant",
|
|
2601
|
+
referenceFolderKey: "tenant"
|
|
2602
|
+
};
|
|
2603
|
+
function keysWith(table, disposition) {
|
|
2604
|
+
return Object.keys(table).filter((key) => table[key] === disposition);
|
|
2605
|
+
}
|
|
2606
|
+
function localKeys(table, _sameKeys) {
|
|
2607
|
+
return Object.fromEntries(keysWith(table, "local").map((key) => [key, true]));
|
|
2608
|
+
}
|
|
2609
|
+
var UPDATE_BODY_KEYS = localKeys(SDK_ENTITY_KEYS, true);
|
|
2610
|
+
var FIELD_KEYS = localKeys(SDK_FIELD_KEYS, true);
|
|
2611
|
+
var TENANT_ONLY_ENTITY_KEYS = keysWith(SDK_ENTITY_KEYS, "tenant");
|
|
2612
|
+
var TENANT_ONLY_FIELD_KEYS = keysWith(SDK_FIELD_KEYS, "tenant");
|
|
2613
|
+
var FEDERATED_SDK_KEYS = keysWith(SDK_ENTITY_KEYS, "federated");
|
|
2614
|
+
function federatedKeysIn(value) {
|
|
2615
|
+
const present = (entry) => Array.isArray(entry) ? entry.length > 0 : typeof entry === "object" && entry !== null && Object.keys(entry).length > 0;
|
|
2616
|
+
return Object.keys(value).filter((key) => {
|
|
2617
|
+
if (key === "entityClass") {
|
|
2618
|
+
return typeof value.entityClass === "string" && value.entityClass.trim().toLowerCase() === "federated";
|
|
2619
|
+
}
|
|
2620
|
+
return (FEDERATED_SDK_KEYS.includes(key) || key === "sourceJoinCriterias" || key === "sourceJoinConditionDetails") && present(value[key]);
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
function quoteList(keys) {
|
|
2624
|
+
return keys.map((key) => `'${key}'`).join(", ");
|
|
2625
|
+
}
|
|
2626
|
+
function keyList(keys) {
|
|
2627
|
+
return Object.keys(keys).join(", ");
|
|
2628
|
+
}
|
|
2629
|
+
function hasAnythingToApply(body) {
|
|
2630
|
+
if (body.displayName !== undefined || body.description !== undefined) {
|
|
2631
|
+
return true;
|
|
2632
|
+
}
|
|
2633
|
+
return [body.addFields, body.updateFields, body.removeFields].some((list) => list !== undefined && (!Array.isArray(list) || list.length > 0));
|
|
2634
|
+
}
|
|
2635
|
+
function rejectUnsupportedKeys(value, rules) {
|
|
2636
|
+
const keys = Object.keys(value);
|
|
2637
|
+
const federated = rules.federated ?? [];
|
|
2638
|
+
if (federated.length > 0) {
|
|
2639
|
+
return reportInvalid("Federated entities cannot be authored locally", `${quoteList(federated)} describes a federated entity, whose data lives in an external system behind a connection. --local authors native entities only. Create the federated entity in Data Fabric, then add it to the solution with 'uip solution resources add --source remote --kind Entity --name <Name>'.`);
|
|
2640
|
+
}
|
|
2641
|
+
const tenantOnly = keys.filter((key) => rules.tenantOnly.includes(key));
|
|
2642
|
+
if (tenantOnly.length > 0) {
|
|
2643
|
+
return reportInvalid(`${quoteList(tenantOnly)} in ${rules.where} ${tenantOnly.length === 1 ? "does" : "do"} not apply to an entity authored locally`, "These configure an entity that already lives on a tenant, and this one does not exist until the solution deploys. Remove them, and set them in Data Fabric after deployment.");
|
|
2644
|
+
}
|
|
2645
|
+
const unknown = keys.filter((key) => !Object.hasOwn(rules.accepted, key));
|
|
2646
|
+
if (unknown.length > 0) {
|
|
2647
|
+
return reportInvalid(`Unknown ${unknown.length === 1 ? "key" : "keys"} ${quoteList(unknown)} in ${rules.where}`, `Accepted keys: ${keyList(rules.accepted)}.`);
|
|
2648
|
+
}
|
|
2649
|
+
return true;
|
|
2650
|
+
}
|
|
2651
|
+
function validateLocalBody(body, context) {
|
|
2652
|
+
const { addFieldsLabel } = context;
|
|
2653
|
+
for (const key of ["addFields", "updateFields", "removeFields"]) {
|
|
2654
|
+
const value = body[key];
|
|
2655
|
+
if (value === undefined) {
|
|
2656
|
+
continue;
|
|
2657
|
+
}
|
|
2658
|
+
const label = key === "addFields" ? addFieldsLabel : key;
|
|
2659
|
+
if (!Array.isArray(value)) {
|
|
2660
|
+
return reportInvalid(`'${label}' must be an array`, `Received ${value === null ? "null" : typeof value}. Provide a JSON array of field objects.`);
|
|
2661
|
+
}
|
|
2662
|
+
for (const [index, item] of value.entries()) {
|
|
2663
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
2664
|
+
return reportInvalid(`'${label}[${index}]' must be an object`, `Received ${item === null ? "null" : typeof item}. Each entry describes one field.`);
|
|
2665
|
+
}
|
|
2666
|
+
const fieldName = item.name;
|
|
2667
|
+
if (typeof fieldName !== "string" || fieldName.trim() === "") {
|
|
2668
|
+
return reportInvalid(`'${label}[${index}].name' must be a non-empty string`, "Every entry names the field it applies to.");
|
|
2669
|
+
}
|
|
2670
|
+
if (key === "updateFields" && Object.keys(item).length === 1) {
|
|
2671
|
+
return reportInvalid(`'${label}[${index}]' names no property to change`, `Add the properties to change on '${fieldName}', such as isRequired or displayName.`);
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
for (const field of [
|
|
2676
|
+
...body.addFields ?? [],
|
|
2677
|
+
...body.updateFields ?? []
|
|
2678
|
+
]) {
|
|
2679
|
+
const type = field.type;
|
|
2680
|
+
if (typeof type === "string" && !AUTHORABLE_FIELD_TYPES.includes(type)) {
|
|
2681
|
+
const [typeError] = catchError(() => authorField({
|
|
2682
|
+
...field,
|
|
2683
|
+
type
|
|
2684
|
+
}));
|
|
2685
|
+
if (typeError) {
|
|
2686
|
+
failFromService(typeError);
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
for (const [key, accepted] of [
|
|
2692
|
+
["addFields", FIELD_KEYS],
|
|
2693
|
+
["updateFields", FIELD_KEYS],
|
|
2694
|
+
["removeFields", REMOVE_FIELD_KEYS]
|
|
2695
|
+
]) {
|
|
2696
|
+
const label = key === "addFields" ? addFieldsLabel : key;
|
|
2697
|
+
for (const [index, item] of (body[key] ?? []).entries()) {
|
|
2698
|
+
if (!rejectUnsupportedKeys(item, {
|
|
2699
|
+
accepted,
|
|
2700
|
+
where: `'${label}[${index}]'`,
|
|
2701
|
+
tenantOnly: key === "removeFields" ? [] : TENANT_ONLY_FIELD_KEYS
|
|
2702
|
+
})) {
|
|
2703
|
+
return false;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
for (const [fields, entityName] of [
|
|
2708
|
+
[body.addFields, context.entityName],
|
|
2709
|
+
[body.updateFields, undefined]
|
|
2710
|
+
]) {
|
|
2711
|
+
const fieldError = fields ? validateFieldsPayload(fields.map(withoutClearedQualifiers), entityName) : null;
|
|
2712
|
+
if (fieldError) {
|
|
2713
|
+
return reportInvalid(fieldError.message, fieldError.instructions);
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
const metadataError = validateSchemaMetadata(body, "Entity");
|
|
2717
|
+
if (metadataError) {
|
|
2718
|
+
return reportInvalid(metadataError.message, metadataError.instructions);
|
|
2719
|
+
}
|
|
2720
|
+
return true;
|
|
2721
|
+
}
|
|
2722
|
+
var CLEARABLE_QUALIFIERS = [
|
|
2723
|
+
"lengthLimit",
|
|
2724
|
+
"decimalPrecision",
|
|
2725
|
+
"maxValue",
|
|
2726
|
+
"minValue",
|
|
2727
|
+
"defaultValue"
|
|
2728
|
+
];
|
|
2729
|
+
function withoutClearedQualifiers(field) {
|
|
2730
|
+
if (typeof field !== "object" || field === null)
|
|
2731
|
+
return field;
|
|
2732
|
+
const copy = { ...field };
|
|
2733
|
+
for (const key of CLEARABLE_QUALIFIERS) {
|
|
2734
|
+
if (copy[key] === null)
|
|
2735
|
+
delete copy[key];
|
|
2736
|
+
}
|
|
2737
|
+
return copy;
|
|
2738
|
+
}
|
|
2739
|
+
function failValidation(message, rows) {
|
|
2740
|
+
OutputFormatter.error({
|
|
2741
|
+
Result: RESULTS.Failure,
|
|
2742
|
+
Message: message,
|
|
2743
|
+
Instructions: "Fix the findings in Data.Diagnostics and re-run 'uip df entities validate --local'. Each row names the entity, the resource file, and the diagnostic code; a PairProblem means the .entity stub and its definition resource do not agree, which 'uip df entities delete <name> --local --force' clears.",
|
|
2744
|
+
ErrorCode: "invalid_argument",
|
|
2745
|
+
Retry: "RetryWillNotFix",
|
|
2746
|
+
Data: { Diagnostics: rows }
|
|
2747
|
+
});
|
|
2748
|
+
processContext.exit(1);
|
|
2749
|
+
}
|
|
2750
|
+
async function runLocalDeleteOrphan(name, options) {
|
|
2751
|
+
const confirmed = requireDestructiveConfirmation({ ...options, reason: "local" }, `delete the orphaned definition resource for '${name}'`, "Pass --yes to confirm. No project declares this entity; only its definition resource is removed.");
|
|
2752
|
+
if (confirmed === null)
|
|
2753
|
+
return;
|
|
2754
|
+
const [deleteError, removed] = await catchError(inlineEntityDeleteOrphanAsync(name));
|
|
2755
|
+
if (deleteError)
|
|
2756
|
+
return failFromService(deleteError);
|
|
2757
|
+
OutputFormatter.success({
|
|
2758
|
+
Result: RESULTS.Success,
|
|
2759
|
+
Code: "InlineEntityDeleted",
|
|
2760
|
+
Data: {
|
|
2761
|
+
Entity: name,
|
|
2762
|
+
ResourceFile: removed?.resourceFile,
|
|
2763
|
+
Forced: true
|
|
2764
|
+
}
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
export {
|
|
2768
|
+
LOCAL_AUTHORING_AVAILABLE,
|
|
2769
|
+
runLocalCreate,
|
|
2770
|
+
runLocalDelete,
|
|
2771
|
+
runLocalGet,
|
|
2772
|
+
runLocalList,
|
|
2773
|
+
runLocalUpdate,
|
|
2774
|
+
runLocalValidate
|
|
2775
|
+
};
|
|
2776
|
+
|
|
2777
|
+
//# debugId=A5C8F1D1CE6F46BE64756E2164756E21
|