@ldsg/utils 0.3.28 → 0.3.30
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/browser.cjs +19 -1
- package/dist/browser.js +9 -1
- package/dist/index.cjs +12 -20
- package/dist/index.js +12 -9
- package/package.json +6 -6
package/dist/browser.cjs
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
3
12
|
(()=>{
|
|
4
13
|
__webpack_require__.d = (exports1, definition)=>{
|
|
5
14
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -55,10 +64,19 @@ const getTreeResourceRecords = (params)=>{
|
|
|
55
64
|
};
|
|
56
65
|
return res;
|
|
57
66
|
};
|
|
67
|
+
const external_lodash_namespaceObject = require("lodash");
|
|
68
|
+
var external_lodash_default = /*#__PURE__*/ __webpack_require__.n(external_lodash_namespaceObject);
|
|
58
69
|
const replaceResourceIdsInString = (params)=>{
|
|
59
70
|
const { jsonString, oldResourceIdToNewResourceIdMap } = params;
|
|
71
|
+
const invalidOldResourceIds = external_lodash_default().filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
|
|
72
|
+
if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
|
|
60
73
|
let result = jsonString;
|
|
61
|
-
|
|
74
|
+
const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
|
|
75
|
+
for (const [oldResourceId, newResourceId] of entries){
|
|
76
|
+
const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
77
|
+
const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
|
|
78
|
+
result = result.replace(regex, newResourceId);
|
|
79
|
+
}
|
|
62
80
|
const res = {
|
|
63
81
|
jsonString: result
|
|
64
82
|
};
|
package/dist/browser.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import lodash from "lodash";
|
|
1
2
|
const getTreeResourceRecords = (params)=>{
|
|
2
3
|
const { resourceRecords, rootId } = params;
|
|
3
4
|
const childrenMap = new Map();
|
|
@@ -28,8 +29,15 @@ const getTreeResourceRecords = (params)=>{
|
|
|
28
29
|
};
|
|
29
30
|
const replaceResourceIdsInString = (params)=>{
|
|
30
31
|
const { jsonString, oldResourceIdToNewResourceIdMap } = params;
|
|
32
|
+
const invalidOldResourceIds = lodash.filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
|
|
33
|
+
if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
|
|
31
34
|
let result = jsonString;
|
|
32
|
-
|
|
35
|
+
const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
|
|
36
|
+
for (const [oldResourceId, newResourceId] of entries){
|
|
37
|
+
const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
38
|
+
const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
|
|
39
|
+
result = result.replace(regex, newResourceId);
|
|
40
|
+
}
|
|
33
41
|
const res = {
|
|
34
42
|
jsonString: result
|
|
35
43
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -265,29 +265,14 @@ const readSourceData = async (uri)=>{
|
|
|
265
265
|
if (external_path_default().isAbsolute(uri)) return external_fs_extra_default().readJson(uri);
|
|
266
266
|
return external_fs_extra_default().readJson(external_path_default().resolve(process.cwd(), uri));
|
|
267
267
|
};
|
|
268
|
-
const normalizeSourceData = async (rawData, expression)=>{
|
|
269
|
-
if (expression) {
|
|
270
|
-
console.debug("normalizeSourceData expression",expression)
|
|
271
|
-
|
|
272
|
-
const exp = external_jsonata_default()(expression);
|
|
273
|
-
|
|
274
|
-
console.debug("normalizeSourceData exp",exp)
|
|
275
|
-
const res = await exp.evaluate(rawData);
|
|
276
|
-
|
|
277
|
-
console.debug("normalizeSourceData res",res)
|
|
278
|
-
|
|
279
|
-
return res
|
|
280
|
-
}
|
|
281
|
-
return rawData;
|
|
282
|
-
};
|
|
283
268
|
const loadAppResourceRecords = async (params)=>{
|
|
284
269
|
const { appDataUri, apaasAppDataUri, apaasAppDataExpression } = params;
|
|
285
270
|
if (apaasAppDataUri) {
|
|
286
271
|
const rawData = await readSourceData(apaasAppDataUri);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
272
|
+
const expression = apaasAppDataExpression || '$';
|
|
273
|
+
const exp = external_jsonata_default()(expression);
|
|
274
|
+
const appData = await exp.evaluate(rawData);
|
|
275
|
+
const { resourceRecords } = appData;
|
|
291
276
|
const apaasRecords = resourceRecords.map((record)=>({
|
|
292
277
|
id: record.id,
|
|
293
278
|
kind: record.kind,
|
|
@@ -382,8 +367,15 @@ const prepare = async (params)=>{
|
|
|
382
367
|
};
|
|
383
368
|
const replaceResourceIdsInString = (params)=>{
|
|
384
369
|
const { jsonString, oldResourceIdToNewResourceIdMap } = params;
|
|
370
|
+
const invalidOldResourceIds = external_lodash_default().filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
|
|
371
|
+
if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
|
|
385
372
|
let result = jsonString;
|
|
386
|
-
|
|
373
|
+
const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
|
|
374
|
+
for (const [oldResourceId, newResourceId] of entries){
|
|
375
|
+
const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
376
|
+
const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
|
|
377
|
+
result = result.replace(regex, newResourceId);
|
|
378
|
+
}
|
|
387
379
|
const res = {
|
|
388
380
|
jsonString: result
|
|
389
381
|
};
|
package/dist/index.js
CHANGED
|
@@ -203,18 +203,14 @@ const readSourceData = async (uri)=>{
|
|
|
203
203
|
if (path_0.isAbsolute(uri)) return fs_extra.readJson(uri);
|
|
204
204
|
return fs_extra.readJson(path_0.resolve(process.cwd(), uri));
|
|
205
205
|
};
|
|
206
|
-
const normalizeSourceData = async (rawData, expression)=>{
|
|
207
|
-
if (expression) {
|
|
208
|
-
const exp = jsonata(expression);
|
|
209
|
-
return await exp.evaluate(rawData);
|
|
210
|
-
}
|
|
211
|
-
return rawData;
|
|
212
|
-
};
|
|
213
206
|
const loadAppResourceRecords = async (params)=>{
|
|
214
207
|
const { appDataUri, apaasAppDataUri, apaasAppDataExpression } = params;
|
|
215
208
|
if (apaasAppDataUri) {
|
|
216
209
|
const rawData = await readSourceData(apaasAppDataUri);
|
|
217
|
-
const
|
|
210
|
+
const expression = apaasAppDataExpression || '$';
|
|
211
|
+
const exp = jsonata(expression);
|
|
212
|
+
const appData = await exp.evaluate(rawData);
|
|
213
|
+
const { resourceRecords } = appData;
|
|
218
214
|
const apaasRecords = resourceRecords.map((record)=>({
|
|
219
215
|
id: record.id,
|
|
220
216
|
kind: record.kind,
|
|
@@ -307,8 +303,15 @@ const prepare = async (params)=>{
|
|
|
307
303
|
};
|
|
308
304
|
const replaceResourceIdsInString = (params)=>{
|
|
309
305
|
const { jsonString, oldResourceIdToNewResourceIdMap } = params;
|
|
306
|
+
const invalidOldResourceIds = lodash.filter(Object.keys(oldResourceIdToNewResourceIdMap), (id)=>!id || !/^[a-zA-Z0-9_-]+$/.test(id)).map((id)=>id || '(empty)');
|
|
307
|
+
if (invalidOldResourceIds.length > 0) throw new Error(`Invalid old resource IDs: ${invalidOldResourceIds.join(', ')}. Only [a-zA-Z0-9_-] are allowed and must not be empty.`);
|
|
310
308
|
let result = jsonString;
|
|
311
|
-
|
|
309
|
+
const entries = Object.entries(oldResourceIdToNewResourceIdMap).sort((a, b)=>b[0].length - a[0].length);
|
|
310
|
+
for (const [oldResourceId, newResourceId] of entries){
|
|
311
|
+
const escaped = oldResourceId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
312
|
+
const regex = new RegExp(`(?<=^|[^a-zA-Z0-9_-])${escaped}(?=$|[^a-zA-Z0-9_-])`, 'g');
|
|
313
|
+
result = result.replace(regex, newResourceId);
|
|
314
|
+
}
|
|
312
315
|
const res = {
|
|
313
316
|
jsonString: result
|
|
314
317
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "wanxger",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"jsonata": "^2.0.6",
|
|
34
34
|
"jszip": "^3.10.1",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
|
-
"@ldsg/constants": "0.3.
|
|
37
|
-
"@ldsg/
|
|
38
|
-
"@ldsg/
|
|
39
|
-
"@ldsg/
|
|
40
|
-
"@ldsg/types": "0.3.
|
|
36
|
+
"@ldsg/apaas-constants": "0.3.30",
|
|
37
|
+
"@ldsg/constants": "0.3.30",
|
|
38
|
+
"@ldsg/core": "0.3.30",
|
|
39
|
+
"@ldsg/handler": "0.3.30",
|
|
40
|
+
"@ldsg/types": "0.3.30"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@rslib/core": "^0.17.1",
|