@devtron-labs/devtron-fe-common-lib 0.0.47 → 0.0.48-beta-4
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/Common/ChartVersionAndTypeSelector.d.ts +4 -0
- package/dist/Common/Common.service.d.ts +1 -0
- package/dist/Common/Constants.d.ts +1 -0
- package/dist/Common/Helper.d.ts +9 -0
- package/dist/Common/Types.d.ts +64 -0
- package/dist/Common/index.d.ts +1 -0
- package/dist/index.js +1650 -17
- package/package.json +3 -1
- package/src/Common/ChartVersionAndTypeSelector.tsx +78 -0
- package/src/Common/Common.service.ts +4 -0
- package/src/Common/Constants.ts +2 -1
- package/src/Common/Helper.tsx +101 -0
- package/src/Common/Types.ts +70 -0
- package/src/Common/index.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var ReactDOM = require('react-dom');
|
|
6
6
|
var reactRouterDom = require('react-router-dom');
|
|
7
|
+
var vm = require('vm');
|
|
7
8
|
var RJSF = require('@rjsf/core');
|
|
8
9
|
var RJSFValidator = require('@rjsf/validator-ajv8');
|
|
9
10
|
var utils = require('@rjsf/utils');
|
|
@@ -47,7 +48,8 @@ var ROUTES = {
|
|
|
47
48
|
PROJECT_LIST_MIN: 'team/autocomplete',
|
|
48
49
|
USER_CHECK_ROLE: 'user/check/roles',
|
|
49
50
|
IMAGE_TAGGING: 'app/image-tagging',
|
|
50
|
-
CD_MATERIAL_GET: 'app/cd-pipeline'
|
|
51
|
+
CD_MATERIAL_GET: 'app/cd-pipeline',
|
|
52
|
+
DEPLOYMENT_TEMPLATE_LIST: 'app/template/list'
|
|
51
53
|
};
|
|
52
54
|
exports.KEY_VALUE = void 0;
|
|
53
55
|
(function (KEY_VALUE) {
|
|
@@ -279,7 +281,7 @@ var extendStatics = function(d, b) {
|
|
|
279
281
|
return extendStatics(d, b);
|
|
280
282
|
};
|
|
281
283
|
|
|
282
|
-
function __extends(d, b) {
|
|
284
|
+
function __extends$1(d, b) {
|
|
283
285
|
if (typeof b !== "function" && b !== null)
|
|
284
286
|
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
285
287
|
extendStatics(d, b);
|
|
@@ -385,7 +387,7 @@ var ServerError = /** @class */ (function () {
|
|
|
385
387
|
return ServerError;
|
|
386
388
|
}());
|
|
387
389
|
var ServerErrors = /** @class */ (function (_super) {
|
|
388
|
-
__extends(ServerErrors, _super);
|
|
390
|
+
__extends$1(ServerErrors, _super);
|
|
389
391
|
function ServerErrors(obj) {
|
|
390
392
|
var _this = _super.call(this) || this;
|
|
391
393
|
_this.code = obj.code;
|
|
@@ -2147,7 +2149,7 @@ eventManager.on(2
|
|
|
2147
2149
|
});
|
|
2148
2150
|
|
|
2149
2151
|
var ToastBody = /** @class */ (function (_super) {
|
|
2150
|
-
__extends(ToastBody, _super);
|
|
2152
|
+
__extends$1(ToastBody, _super);
|
|
2151
2153
|
function ToastBody() {
|
|
2152
2154
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2153
2155
|
}
|
|
@@ -2157,7 +2159,7 @@ var ToastBody = /** @class */ (function (_super) {
|
|
|
2157
2159
|
return ToastBody;
|
|
2158
2160
|
}(React.Component));
|
|
2159
2161
|
var ToastBody3 = /** @class */ (function (_super) {
|
|
2160
|
-
__extends(ToastBody3, _super);
|
|
2162
|
+
__extends$1(ToastBody3, _super);
|
|
2161
2163
|
function ToastBody3() {
|
|
2162
2164
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2163
2165
|
}
|
|
@@ -2167,7 +2169,7 @@ var ToastBody3 = /** @class */ (function (_super) {
|
|
|
2167
2169
|
return ToastBody3;
|
|
2168
2170
|
}(React.Component));
|
|
2169
2171
|
var ToastBodyWithButton = /** @class */ (function (_super) {
|
|
2170
|
-
__extends(ToastBodyWithButton, _super);
|
|
2172
|
+
__extends$1(ToastBodyWithButton, _super);
|
|
2171
2173
|
function ToastBodyWithButton() {
|
|
2172
2174
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2173
2175
|
}
|
|
@@ -2216,7 +2218,7 @@ function ErrorScreenNotFound() {
|
|
|
2216
2218
|
}
|
|
2217
2219
|
|
|
2218
2220
|
var ErrorScreenManager = /** @class */ (function (_super) {
|
|
2219
|
-
__extends(ErrorScreenManager, _super);
|
|
2221
|
+
__extends$1(ErrorScreenManager, _super);
|
|
2220
2222
|
function ErrorScreenManager() {
|
|
2221
2223
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2222
2224
|
}
|
|
@@ -2247,7 +2249,7 @@ var ErrorScreenManager = /** @class */ (function (_super) {
|
|
|
2247
2249
|
return ErrorScreenManager;
|
|
2248
2250
|
}(React.Component));
|
|
2249
2251
|
var ErrorScreenNotAuthorized = /** @class */ (function (_super) {
|
|
2250
|
-
__extends(ErrorScreenNotAuthorized, _super);
|
|
2252
|
+
__extends$1(ErrorScreenNotAuthorized, _super);
|
|
2251
2253
|
function ErrorScreenNotAuthorized() {
|
|
2252
2254
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2253
2255
|
}
|
|
@@ -9836,6 +9838,1506 @@ var moment$1 = {
|
|
|
9836
9838
|
|
|
9837
9839
|
var moment = momentExports;
|
|
9838
9840
|
|
|
9841
|
+
const {
|
|
9842
|
+
hasOwnProperty: hasOwnProp
|
|
9843
|
+
} = Object.prototype;
|
|
9844
|
+
/**
|
|
9845
|
+
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
|
|
9846
|
+
*/
|
|
9847
|
+
|
|
9848
|
+
/**
|
|
9849
|
+
* @typedef {any} AnyItem
|
|
9850
|
+
*/
|
|
9851
|
+
|
|
9852
|
+
/**
|
|
9853
|
+
* @typedef {any} AnyResult
|
|
9854
|
+
*/
|
|
9855
|
+
|
|
9856
|
+
/**
|
|
9857
|
+
* Copies array and then pushes item into it.
|
|
9858
|
+
* @param {GenericArray} arr Array to copy and into which to push
|
|
9859
|
+
* @param {AnyItem} item Array item to add (to end)
|
|
9860
|
+
* @returns {GenericArray} Copy of the original array
|
|
9861
|
+
*/
|
|
9862
|
+
|
|
9863
|
+
function push(arr, item) {
|
|
9864
|
+
arr = arr.slice();
|
|
9865
|
+
arr.push(item);
|
|
9866
|
+
return arr;
|
|
9867
|
+
}
|
|
9868
|
+
/**
|
|
9869
|
+
* Copies array and then unshifts item into it.
|
|
9870
|
+
* @param {AnyItem} item Array item to add (to beginning)
|
|
9871
|
+
* @param {GenericArray} arr Array to copy and into which to unshift
|
|
9872
|
+
* @returns {GenericArray} Copy of the original array
|
|
9873
|
+
*/
|
|
9874
|
+
|
|
9875
|
+
|
|
9876
|
+
function unshift(item, arr) {
|
|
9877
|
+
arr = arr.slice();
|
|
9878
|
+
arr.unshift(item);
|
|
9879
|
+
return arr;
|
|
9880
|
+
}
|
|
9881
|
+
/**
|
|
9882
|
+
* Caught when JSONPath is used without `new` but rethrown if with `new`
|
|
9883
|
+
* @extends Error
|
|
9884
|
+
*/
|
|
9885
|
+
|
|
9886
|
+
|
|
9887
|
+
class NewError extends Error {
|
|
9888
|
+
/**
|
|
9889
|
+
* @param {AnyResult} value The evaluated scalar value
|
|
9890
|
+
*/
|
|
9891
|
+
constructor(value) {
|
|
9892
|
+
super('JSONPath should not be called with "new" (it prevents return ' + 'of (unwrapped) scalar values)');
|
|
9893
|
+
this.avoidNew = true;
|
|
9894
|
+
this.value = value;
|
|
9895
|
+
this.name = 'NewError';
|
|
9896
|
+
}
|
|
9897
|
+
|
|
9898
|
+
}
|
|
9899
|
+
/**
|
|
9900
|
+
* @typedef {PlainObject} ReturnObject
|
|
9901
|
+
* @property {string} path
|
|
9902
|
+
* @property {JSONObject} value
|
|
9903
|
+
* @property {PlainObject|GenericArray} parent
|
|
9904
|
+
* @property {string} parentProperty
|
|
9905
|
+
*/
|
|
9906
|
+
|
|
9907
|
+
/**
|
|
9908
|
+
* @callback JSONPathCallback
|
|
9909
|
+
* @param {string|PlainObject} preferredOutput
|
|
9910
|
+
* @param {"value"|"property"} type
|
|
9911
|
+
* @param {ReturnObject} fullRetObj
|
|
9912
|
+
* @returns {void}
|
|
9913
|
+
*/
|
|
9914
|
+
|
|
9915
|
+
/**
|
|
9916
|
+
* @callback OtherTypeCallback
|
|
9917
|
+
* @param {JSONObject} val
|
|
9918
|
+
* @param {string} path
|
|
9919
|
+
* @param {PlainObject|GenericArray} parent
|
|
9920
|
+
* @param {string} parentPropName
|
|
9921
|
+
* @returns {boolean}
|
|
9922
|
+
*/
|
|
9923
|
+
|
|
9924
|
+
/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
|
|
9925
|
+
|
|
9926
|
+
/**
|
|
9927
|
+
* @typedef {PlainObject} JSONPathOptions
|
|
9928
|
+
* @property {JSON} json
|
|
9929
|
+
* @property {string|string[]} path
|
|
9930
|
+
* @property {"value"|"path"|"pointer"|"parent"|"parentProperty"|"all"} [resultType="value"]
|
|
9931
|
+
* @property {boolean} [flatten=false]
|
|
9932
|
+
* @property {boolean} [wrap=true]
|
|
9933
|
+
* @property {PlainObject} [sandbox={}]
|
|
9934
|
+
* @property {boolean} [preventEval=false]
|
|
9935
|
+
* @property {PlainObject|GenericArray|null} [parent=null]
|
|
9936
|
+
* @property {string|null} [parentProperty=null]
|
|
9937
|
+
* @property {JSONPathCallback} [callback]
|
|
9938
|
+
* @property {OtherTypeCallback} [otherTypeCallback] Defaults to
|
|
9939
|
+
* function which throws on encountering `@other`
|
|
9940
|
+
* @property {boolean} [autostart=true]
|
|
9941
|
+
*/
|
|
9942
|
+
|
|
9943
|
+
/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
|
|
9944
|
+
|
|
9945
|
+
/**
|
|
9946
|
+
* @param {string|JSONPathOptions} opts If a string, will be treated as `expr`
|
|
9947
|
+
* @param {string} [expr] JSON path to evaluate
|
|
9948
|
+
* @param {JSON} [obj] JSON object to evaluate against
|
|
9949
|
+
* @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload
|
|
9950
|
+
* per `resultType`, 2) `"value"|"property"`, 3) Full returned object with
|
|
9951
|
+
* all payloads
|
|
9952
|
+
* @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end
|
|
9953
|
+
* of one's query, this will be invoked with the value of the item, its
|
|
9954
|
+
* path, its parent, and its parent's property name, and it should return
|
|
9955
|
+
* a boolean indicating whether the supplied value belongs to the "other"
|
|
9956
|
+
* type or not (or it may handle transformations and return `false`).
|
|
9957
|
+
* @returns {JSONPath}
|
|
9958
|
+
* @class
|
|
9959
|
+
*/
|
|
9960
|
+
|
|
9961
|
+
|
|
9962
|
+
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
9963
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
9964
|
+
if (!(this instanceof JSONPath)) {
|
|
9965
|
+
try {
|
|
9966
|
+
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
9967
|
+
} catch (e) {
|
|
9968
|
+
if (!e.avoidNew) {
|
|
9969
|
+
throw e;
|
|
9970
|
+
}
|
|
9971
|
+
|
|
9972
|
+
return e.value;
|
|
9973
|
+
}
|
|
9974
|
+
}
|
|
9975
|
+
|
|
9976
|
+
if (typeof opts === 'string') {
|
|
9977
|
+
otherTypeCallback = callback;
|
|
9978
|
+
callback = obj;
|
|
9979
|
+
obj = expr;
|
|
9980
|
+
expr = opts;
|
|
9981
|
+
opts = null;
|
|
9982
|
+
}
|
|
9983
|
+
|
|
9984
|
+
const optObj = opts && typeof opts === 'object';
|
|
9985
|
+
opts = opts || {};
|
|
9986
|
+
this.json = opts.json || obj;
|
|
9987
|
+
this.path = opts.path || expr;
|
|
9988
|
+
this.resultType = opts.resultType || 'value';
|
|
9989
|
+
this.flatten = opts.flatten || false;
|
|
9990
|
+
this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;
|
|
9991
|
+
this.sandbox = opts.sandbox || {};
|
|
9992
|
+
this.preventEval = opts.preventEval || false;
|
|
9993
|
+
this.parent = opts.parent || null;
|
|
9994
|
+
this.parentProperty = opts.parentProperty || null;
|
|
9995
|
+
this.callback = opts.callback || callback || null;
|
|
9996
|
+
|
|
9997
|
+
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function () {
|
|
9998
|
+
throw new TypeError('You must supply an otherTypeCallback callback option ' + 'with the @other() operator.');
|
|
9999
|
+
};
|
|
10000
|
+
|
|
10001
|
+
if (opts.autostart !== false) {
|
|
10002
|
+
const args = {
|
|
10003
|
+
path: optObj ? opts.path : expr
|
|
10004
|
+
};
|
|
10005
|
+
|
|
10006
|
+
if (!optObj) {
|
|
10007
|
+
args.json = obj;
|
|
10008
|
+
} else if ('json' in opts) {
|
|
10009
|
+
args.json = opts.json;
|
|
10010
|
+
}
|
|
10011
|
+
|
|
10012
|
+
const ret = this.evaluate(args);
|
|
10013
|
+
|
|
10014
|
+
if (!ret || typeof ret !== 'object') {
|
|
10015
|
+
throw new NewError(ret);
|
|
10016
|
+
}
|
|
10017
|
+
|
|
10018
|
+
return ret;
|
|
10019
|
+
}
|
|
10020
|
+
} // PUBLIC METHODS
|
|
10021
|
+
|
|
10022
|
+
|
|
10023
|
+
JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) {
|
|
10024
|
+
let currParent = this.parent,
|
|
10025
|
+
currParentProperty = this.parentProperty;
|
|
10026
|
+
let {
|
|
10027
|
+
flatten,
|
|
10028
|
+
wrap
|
|
10029
|
+
} = this;
|
|
10030
|
+
this.currResultType = this.resultType;
|
|
10031
|
+
this.currPreventEval = this.preventEval;
|
|
10032
|
+
this.currSandbox = this.sandbox;
|
|
10033
|
+
callback = callback || this.callback;
|
|
10034
|
+
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
10035
|
+
json = json || this.json;
|
|
10036
|
+
expr = expr || this.path;
|
|
10037
|
+
|
|
10038
|
+
if (expr && typeof expr === 'object' && !Array.isArray(expr)) {
|
|
10039
|
+
if (!expr.path && expr.path !== '') {
|
|
10040
|
+
throw new TypeError('You must supply a "path" property when providing an object ' + 'argument to JSONPath.evaluate().');
|
|
10041
|
+
}
|
|
10042
|
+
|
|
10043
|
+
if (!hasOwnProp.call(expr, 'json')) {
|
|
10044
|
+
throw new TypeError('You must supply a "json" property when providing an object ' + 'argument to JSONPath.evaluate().');
|
|
10045
|
+
}
|
|
10046
|
+
|
|
10047
|
+
({
|
|
10048
|
+
json
|
|
10049
|
+
} = expr);
|
|
10050
|
+
flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;
|
|
10051
|
+
this.currResultType = hasOwnProp.call(expr, 'resultType') ? expr.resultType : this.currResultType;
|
|
10052
|
+
this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox;
|
|
10053
|
+
wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;
|
|
10054
|
+
this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval;
|
|
10055
|
+
callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;
|
|
10056
|
+
this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
10057
|
+
currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;
|
|
10058
|
+
currParentProperty = hasOwnProp.call(expr, 'parentProperty') ? expr.parentProperty : currParentProperty;
|
|
10059
|
+
expr = expr.path;
|
|
10060
|
+
}
|
|
10061
|
+
|
|
10062
|
+
currParent = currParent || null;
|
|
10063
|
+
currParentProperty = currParentProperty || null;
|
|
10064
|
+
|
|
10065
|
+
if (Array.isArray(expr)) {
|
|
10066
|
+
expr = JSONPath.toPathString(expr);
|
|
10067
|
+
}
|
|
10068
|
+
|
|
10069
|
+
if (!expr && expr !== '' || !json) {
|
|
10070
|
+
return undefined;
|
|
10071
|
+
}
|
|
10072
|
+
|
|
10073
|
+
const exprList = JSONPath.toPathArray(expr);
|
|
10074
|
+
|
|
10075
|
+
if (exprList[0] === '$' && exprList.length > 1) {
|
|
10076
|
+
exprList.shift();
|
|
10077
|
+
}
|
|
10078
|
+
|
|
10079
|
+
this._hasParentSelector = null;
|
|
10080
|
+
|
|
10081
|
+
const result = this._trace(exprList, json, ['$'], currParent, currParentProperty, callback).filter(function (ea) {
|
|
10082
|
+
return ea && !ea.isParentSelector;
|
|
10083
|
+
});
|
|
10084
|
+
|
|
10085
|
+
if (!result.length) {
|
|
10086
|
+
return wrap ? [] : undefined;
|
|
10087
|
+
}
|
|
10088
|
+
|
|
10089
|
+
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
10090
|
+
return this._getPreferredOutput(result[0]);
|
|
10091
|
+
}
|
|
10092
|
+
|
|
10093
|
+
return result.reduce((rslt, ea) => {
|
|
10094
|
+
const valOrPath = this._getPreferredOutput(ea);
|
|
10095
|
+
|
|
10096
|
+
if (flatten && Array.isArray(valOrPath)) {
|
|
10097
|
+
rslt = rslt.concat(valOrPath);
|
|
10098
|
+
} else {
|
|
10099
|
+
rslt.push(valOrPath);
|
|
10100
|
+
}
|
|
10101
|
+
|
|
10102
|
+
return rslt;
|
|
10103
|
+
}, []);
|
|
10104
|
+
}; // PRIVATE METHODS
|
|
10105
|
+
|
|
10106
|
+
|
|
10107
|
+
JSONPath.prototype._getPreferredOutput = function (ea) {
|
|
10108
|
+
const resultType = this.currResultType;
|
|
10109
|
+
|
|
10110
|
+
switch (resultType) {
|
|
10111
|
+
case 'all':
|
|
10112
|
+
{
|
|
10113
|
+
const path = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
10114
|
+
ea.pointer = JSONPath.toPointer(path);
|
|
10115
|
+
ea.path = typeof ea.path === 'string' ? ea.path : JSONPath.toPathString(ea.path);
|
|
10116
|
+
return ea;
|
|
10117
|
+
}
|
|
10118
|
+
|
|
10119
|
+
case 'value':
|
|
10120
|
+
case 'parent':
|
|
10121
|
+
case 'parentProperty':
|
|
10122
|
+
return ea[resultType];
|
|
10123
|
+
|
|
10124
|
+
case 'path':
|
|
10125
|
+
return JSONPath.toPathString(ea[resultType]);
|
|
10126
|
+
|
|
10127
|
+
case 'pointer':
|
|
10128
|
+
return JSONPath.toPointer(ea.path);
|
|
10129
|
+
|
|
10130
|
+
default:
|
|
10131
|
+
throw new TypeError('Unknown result type');
|
|
10132
|
+
}
|
|
10133
|
+
};
|
|
10134
|
+
|
|
10135
|
+
JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
|
|
10136
|
+
if (callback) {
|
|
10137
|
+
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
10138
|
+
|
|
10139
|
+
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line n/callback-return
|
|
10140
|
+
|
|
10141
|
+
callback(preferredOutput, type, fullRetObj);
|
|
10142
|
+
}
|
|
10143
|
+
};
|
|
10144
|
+
/**
|
|
10145
|
+
*
|
|
10146
|
+
* @param {string} expr
|
|
10147
|
+
* @param {JSONObject} val
|
|
10148
|
+
* @param {string} path
|
|
10149
|
+
* @param {PlainObject|GenericArray} parent
|
|
10150
|
+
* @param {string} parentPropName
|
|
10151
|
+
* @param {JSONPathCallback} callback
|
|
10152
|
+
* @param {boolean} hasArrExpr
|
|
10153
|
+
* @param {boolean} literalPriority
|
|
10154
|
+
* @returns {ReturnObject|ReturnObject[]}
|
|
10155
|
+
*/
|
|
10156
|
+
|
|
10157
|
+
|
|
10158
|
+
JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
10159
|
+
// No expr to follow? return path and value as the result of
|
|
10160
|
+
// this trace branch
|
|
10161
|
+
let retObj;
|
|
10162
|
+
|
|
10163
|
+
if (!expr.length) {
|
|
10164
|
+
retObj = {
|
|
10165
|
+
path,
|
|
10166
|
+
value: val,
|
|
10167
|
+
parent,
|
|
10168
|
+
parentProperty: parentPropName,
|
|
10169
|
+
hasArrExpr
|
|
10170
|
+
};
|
|
10171
|
+
|
|
10172
|
+
this._handleCallback(retObj, callback, 'value');
|
|
10173
|
+
|
|
10174
|
+
return retObj;
|
|
10175
|
+
}
|
|
10176
|
+
|
|
10177
|
+
const loc = expr[0],
|
|
10178
|
+
x = expr.slice(1); // We need to gather the return value of recursive trace calls in order to
|
|
10179
|
+
// do the parent sel computation.
|
|
10180
|
+
|
|
10181
|
+
const ret = [];
|
|
10182
|
+
/**
|
|
10183
|
+
*
|
|
10184
|
+
* @param {ReturnObject|ReturnObject[]} elems
|
|
10185
|
+
* @returns {void}
|
|
10186
|
+
*/
|
|
10187
|
+
|
|
10188
|
+
function addRet(elems) {
|
|
10189
|
+
if (Array.isArray(elems)) {
|
|
10190
|
+
// This was causing excessive stack size in Node (with or
|
|
10191
|
+
// without Babel) against our performance test:
|
|
10192
|
+
// `ret.push(...elems);`
|
|
10193
|
+
elems.forEach(t => {
|
|
10194
|
+
ret.push(t);
|
|
10195
|
+
});
|
|
10196
|
+
} else {
|
|
10197
|
+
ret.push(elems);
|
|
10198
|
+
}
|
|
10199
|
+
}
|
|
10200
|
+
|
|
10201
|
+
if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc)) {
|
|
10202
|
+
// simple case--directly follow property
|
|
10203
|
+
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
|
|
10204
|
+
} else if (loc === '*') {
|
|
10205
|
+
// all child properties
|
|
10206
|
+
this._walk(val, m => {
|
|
10207
|
+
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true, true));
|
|
10208
|
+
});
|
|
10209
|
+
} else if (loc === '..') {
|
|
10210
|
+
// all descendent parent properties
|
|
10211
|
+
// Check remaining expression with val's immediate children
|
|
10212
|
+
addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr));
|
|
10213
|
+
|
|
10214
|
+
this._walk(val, m => {
|
|
10215
|
+
// We don't join m and x here because we only want parents,
|
|
10216
|
+
// not scalar values
|
|
10217
|
+
if (typeof val[m] === 'object') {
|
|
10218
|
+
// Keep going with recursive descent on val's
|
|
10219
|
+
// object children
|
|
10220
|
+
addRet(this._trace(expr.slice(), val[m], push(path, m), val, m, callback, true));
|
|
10221
|
+
}
|
|
10222
|
+
}); // The parent sel computation is handled in the frame above using the
|
|
10223
|
+
// ancestor object of val
|
|
10224
|
+
|
|
10225
|
+
} else if (loc === '^') {
|
|
10226
|
+
// This is not a final endpoint, so we do not invoke the callback here
|
|
10227
|
+
this._hasParentSelector = true;
|
|
10228
|
+
return {
|
|
10229
|
+
path: path.slice(0, -1),
|
|
10230
|
+
expr: x,
|
|
10231
|
+
isParentSelector: true
|
|
10232
|
+
};
|
|
10233
|
+
} else if (loc === '~') {
|
|
10234
|
+
// property name
|
|
10235
|
+
retObj = {
|
|
10236
|
+
path: push(path, loc),
|
|
10237
|
+
value: parentPropName,
|
|
10238
|
+
parent,
|
|
10239
|
+
parentProperty: null
|
|
10240
|
+
};
|
|
10241
|
+
|
|
10242
|
+
this._handleCallback(retObj, callback, 'property');
|
|
10243
|
+
|
|
10244
|
+
return retObj;
|
|
10245
|
+
} else if (loc === '$') {
|
|
10246
|
+
// root only
|
|
10247
|
+
addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));
|
|
10248
|
+
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
10249
|
+
// [start:end:step] Python slice syntax
|
|
10250
|
+
addRet(this._slice(loc, x, val, path, parent, parentPropName, callback));
|
|
10251
|
+
} else if (loc.indexOf('?(') === 0) {
|
|
10252
|
+
// [?(expr)] (filtering)
|
|
10253
|
+
if (this.currPreventEval) {
|
|
10254
|
+
throw new Error('Eval [?(expr)] prevented in JSONPath expression.');
|
|
10255
|
+
}
|
|
10256
|
+
|
|
10257
|
+
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, '$1');
|
|
10258
|
+
|
|
10259
|
+
this._walk(val, m => {
|
|
10260
|
+
if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
|
|
10261
|
+
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true));
|
|
10262
|
+
}
|
|
10263
|
+
});
|
|
10264
|
+
} else if (loc[0] === '(') {
|
|
10265
|
+
// [(expr)] (dynamic property/index)
|
|
10266
|
+
if (this.currPreventEval) {
|
|
10267
|
+
throw new Error('Eval [(expr)] prevented in JSONPath expression.');
|
|
10268
|
+
} // As this will resolve to a property name (but we don't know it
|
|
10269
|
+
// yet), property and parent information is relative to the
|
|
10270
|
+
// parent of the property to which this expression will resolve
|
|
10271
|
+
|
|
10272
|
+
|
|
10273
|
+
addRet(this._trace(unshift(this._eval(loc, val, path[path.length - 1], path.slice(0, -1), parent, parentPropName), x), val, path, parent, parentPropName, callback, hasArrExpr));
|
|
10274
|
+
} else if (loc[0] === '@') {
|
|
10275
|
+
// value type: @boolean(), etc.
|
|
10276
|
+
let addType = false;
|
|
10277
|
+
const valueType = loc.slice(1, -2);
|
|
10278
|
+
|
|
10279
|
+
switch (valueType) {
|
|
10280
|
+
case 'scalar':
|
|
10281
|
+
if (!val || !['object', 'function'].includes(typeof val)) {
|
|
10282
|
+
addType = true;
|
|
10283
|
+
}
|
|
10284
|
+
|
|
10285
|
+
break;
|
|
10286
|
+
|
|
10287
|
+
case 'boolean':
|
|
10288
|
+
case 'string':
|
|
10289
|
+
case 'undefined':
|
|
10290
|
+
case 'function':
|
|
10291
|
+
// eslint-disable-next-line valid-typeof
|
|
10292
|
+
if (typeof val === valueType) {
|
|
10293
|
+
addType = true;
|
|
10294
|
+
}
|
|
10295
|
+
|
|
10296
|
+
break;
|
|
10297
|
+
|
|
10298
|
+
case 'integer':
|
|
10299
|
+
if (Number.isFinite(val) && !(val % 1)) {
|
|
10300
|
+
addType = true;
|
|
10301
|
+
}
|
|
10302
|
+
|
|
10303
|
+
break;
|
|
10304
|
+
|
|
10305
|
+
case 'number':
|
|
10306
|
+
if (Number.isFinite(val)) {
|
|
10307
|
+
addType = true;
|
|
10308
|
+
}
|
|
10309
|
+
|
|
10310
|
+
break;
|
|
10311
|
+
|
|
10312
|
+
case 'nonFinite':
|
|
10313
|
+
if (typeof val === 'number' && !Number.isFinite(val)) {
|
|
10314
|
+
addType = true;
|
|
10315
|
+
}
|
|
10316
|
+
|
|
10317
|
+
break;
|
|
10318
|
+
|
|
10319
|
+
case 'object':
|
|
10320
|
+
// eslint-disable-next-line valid-typeof
|
|
10321
|
+
if (val && typeof val === valueType) {
|
|
10322
|
+
addType = true;
|
|
10323
|
+
}
|
|
10324
|
+
|
|
10325
|
+
break;
|
|
10326
|
+
|
|
10327
|
+
case 'array':
|
|
10328
|
+
if (Array.isArray(val)) {
|
|
10329
|
+
addType = true;
|
|
10330
|
+
}
|
|
10331
|
+
|
|
10332
|
+
break;
|
|
10333
|
+
|
|
10334
|
+
case 'other':
|
|
10335
|
+
addType = this.currOtherTypeCallback(val, path, parent, parentPropName);
|
|
10336
|
+
break;
|
|
10337
|
+
|
|
10338
|
+
case 'null':
|
|
10339
|
+
if (val === null) {
|
|
10340
|
+
addType = true;
|
|
10341
|
+
}
|
|
10342
|
+
|
|
10343
|
+
break;
|
|
10344
|
+
|
|
10345
|
+
/* c8 ignore next 2 */
|
|
10346
|
+
|
|
10347
|
+
default:
|
|
10348
|
+
throw new TypeError('Unknown value type ' + valueType);
|
|
10349
|
+
}
|
|
10350
|
+
|
|
10351
|
+
if (addType) {
|
|
10352
|
+
retObj = {
|
|
10353
|
+
path,
|
|
10354
|
+
value: val,
|
|
10355
|
+
parent,
|
|
10356
|
+
parentProperty: parentPropName
|
|
10357
|
+
};
|
|
10358
|
+
|
|
10359
|
+
this._handleCallback(retObj, callback, 'value');
|
|
10360
|
+
|
|
10361
|
+
return retObj;
|
|
10362
|
+
} // `-escaped property
|
|
10363
|
+
|
|
10364
|
+
} else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {
|
|
10365
|
+
const locProp = loc.slice(1);
|
|
10366
|
+
addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, hasArrExpr, true));
|
|
10367
|
+
} else if (loc.includes(',')) {
|
|
10368
|
+
// [name1,name2,...]
|
|
10369
|
+
const parts = loc.split(',');
|
|
10370
|
+
|
|
10371
|
+
for (const part of parts) {
|
|
10372
|
+
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
|
|
10373
|
+
} // simple case--directly follow property
|
|
10374
|
+
|
|
10375
|
+
} else if (!literalPriority && val && hasOwnProp.call(val, loc)) {
|
|
10376
|
+
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true));
|
|
10377
|
+
} // We check the resulting values for parent selections. For parent
|
|
10378
|
+
// selections we discard the value object and continue the trace with the
|
|
10379
|
+
// current val object
|
|
10380
|
+
|
|
10381
|
+
|
|
10382
|
+
if (this._hasParentSelector) {
|
|
10383
|
+
for (let t = 0; t < ret.length; t++) {
|
|
10384
|
+
const rett = ret[t];
|
|
10385
|
+
|
|
10386
|
+
if (rett && rett.isParentSelector) {
|
|
10387
|
+
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
10388
|
+
|
|
10389
|
+
if (Array.isArray(tmp)) {
|
|
10390
|
+
ret[t] = tmp[0];
|
|
10391
|
+
const tl = tmp.length;
|
|
10392
|
+
|
|
10393
|
+
for (let tt = 1; tt < tl; tt++) {
|
|
10394
|
+
t++;
|
|
10395
|
+
ret.splice(t, 0, tmp[tt]);
|
|
10396
|
+
}
|
|
10397
|
+
} else {
|
|
10398
|
+
ret[t] = tmp;
|
|
10399
|
+
}
|
|
10400
|
+
}
|
|
10401
|
+
}
|
|
10402
|
+
}
|
|
10403
|
+
|
|
10404
|
+
return ret;
|
|
10405
|
+
};
|
|
10406
|
+
|
|
10407
|
+
JSONPath.prototype._walk = function (val, f) {
|
|
10408
|
+
if (Array.isArray(val)) {
|
|
10409
|
+
const n = val.length;
|
|
10410
|
+
|
|
10411
|
+
for (let i = 0; i < n; i++) {
|
|
10412
|
+
f(i);
|
|
10413
|
+
}
|
|
10414
|
+
} else if (val && typeof val === 'object') {
|
|
10415
|
+
Object.keys(val).forEach(m => {
|
|
10416
|
+
f(m);
|
|
10417
|
+
});
|
|
10418
|
+
}
|
|
10419
|
+
};
|
|
10420
|
+
|
|
10421
|
+
JSONPath.prototype._slice = function (loc, expr, val, path, parent, parentPropName, callback) {
|
|
10422
|
+
if (!Array.isArray(val)) {
|
|
10423
|
+
return undefined;
|
|
10424
|
+
}
|
|
10425
|
+
|
|
10426
|
+
const len = val.length,
|
|
10427
|
+
parts = loc.split(':'),
|
|
10428
|
+
step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
10429
|
+
let start = parts[0] && Number.parseInt(parts[0]) || 0,
|
|
10430
|
+
end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
10431
|
+
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
10432
|
+
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
10433
|
+
const ret = [];
|
|
10434
|
+
|
|
10435
|
+
for (let i = start; i < end; i += step) {
|
|
10436
|
+
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true); // Should only be possible to be an array here since first part of
|
|
10437
|
+
// ``unshift(i, expr)` passed in above would not be empty, nor `~`,
|
|
10438
|
+
// nor begin with `@` (as could return objects)
|
|
10439
|
+
// This was causing excessive stack size in Node (with or
|
|
10440
|
+
// without Babel) against our performance test: `ret.push(...tmp);`
|
|
10441
|
+
|
|
10442
|
+
|
|
10443
|
+
tmp.forEach(t => {
|
|
10444
|
+
ret.push(t);
|
|
10445
|
+
});
|
|
10446
|
+
}
|
|
10447
|
+
|
|
10448
|
+
return ret;
|
|
10449
|
+
};
|
|
10450
|
+
|
|
10451
|
+
JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropName) {
|
|
10452
|
+
this.currSandbox._$_parentProperty = parentPropName;
|
|
10453
|
+
this.currSandbox._$_parent = parent;
|
|
10454
|
+
this.currSandbox._$_property = _vname;
|
|
10455
|
+
this.currSandbox._$_root = this.json;
|
|
10456
|
+
this.currSandbox._$_v = _v;
|
|
10457
|
+
const containsPath = code.includes('@path');
|
|
10458
|
+
|
|
10459
|
+
if (containsPath) {
|
|
10460
|
+
this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));
|
|
10461
|
+
}
|
|
10462
|
+
|
|
10463
|
+
const scriptCacheKey = 'script:' + code;
|
|
10464
|
+
|
|
10465
|
+
if (!JSONPath.cache[scriptCacheKey]) {
|
|
10466
|
+
let script = code.replace(/@parentProperty/gu, '_$_parentProperty').replace(/@parent/gu, '_$_parent').replace(/@property/gu, '_$_property').replace(/@root/gu, '_$_root').replace(/@([.\s)[])/gu, '_$_v$1');
|
|
10467
|
+
|
|
10468
|
+
if (containsPath) {
|
|
10469
|
+
script = script.replace(/@path/gu, '_$_path');
|
|
10470
|
+
}
|
|
10471
|
+
|
|
10472
|
+
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
10473
|
+
}
|
|
10474
|
+
|
|
10475
|
+
try {
|
|
10476
|
+
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
10477
|
+
} catch (e) {
|
|
10478
|
+
throw new Error('jsonPath: ' + e.message + ': ' + code);
|
|
10479
|
+
}
|
|
10480
|
+
}; // PUBLIC CLASS PROPERTIES AND METHODS
|
|
10481
|
+
// Could store the cache object itself
|
|
10482
|
+
|
|
10483
|
+
|
|
10484
|
+
JSONPath.cache = {};
|
|
10485
|
+
/**
|
|
10486
|
+
* @param {string[]} pathArr Array to convert
|
|
10487
|
+
* @returns {string} The path string
|
|
10488
|
+
*/
|
|
10489
|
+
|
|
10490
|
+
JSONPath.toPathString = function (pathArr) {
|
|
10491
|
+
const x = pathArr,
|
|
10492
|
+
n = x.length;
|
|
10493
|
+
let p = '$';
|
|
10494
|
+
|
|
10495
|
+
for (let i = 1; i < n; i++) {
|
|
10496
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
10497
|
+
p += /^[0-9*]+$/u.test(x[i]) ? '[' + x[i] + ']' : "['" + x[i] + "']";
|
|
10498
|
+
}
|
|
10499
|
+
}
|
|
10500
|
+
|
|
10501
|
+
return p;
|
|
10502
|
+
};
|
|
10503
|
+
/**
|
|
10504
|
+
* @param {string} pointer JSON Path
|
|
10505
|
+
* @returns {string} JSON Pointer
|
|
10506
|
+
*/
|
|
10507
|
+
|
|
10508
|
+
|
|
10509
|
+
JSONPath.toPointer = function (pointer) {
|
|
10510
|
+
const x = pointer,
|
|
10511
|
+
n = x.length;
|
|
10512
|
+
let p = '';
|
|
10513
|
+
|
|
10514
|
+
for (let i = 1; i < n; i++) {
|
|
10515
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
10516
|
+
p += '/' + x[i].toString().replace(/~/gu, '~0').replace(/\//gu, '~1');
|
|
10517
|
+
}
|
|
10518
|
+
}
|
|
10519
|
+
|
|
10520
|
+
return p;
|
|
10521
|
+
};
|
|
10522
|
+
/**
|
|
10523
|
+
* @param {string} expr Expression to convert
|
|
10524
|
+
* @returns {string[]}
|
|
10525
|
+
*/
|
|
10526
|
+
|
|
10527
|
+
|
|
10528
|
+
JSONPath.toPathArray = function (expr) {
|
|
10529
|
+
const {
|
|
10530
|
+
cache
|
|
10531
|
+
} = JSONPath;
|
|
10532
|
+
|
|
10533
|
+
if (cache[expr]) {
|
|
10534
|
+
return cache[expr].concat();
|
|
10535
|
+
}
|
|
10536
|
+
|
|
10537
|
+
const subx = [];
|
|
10538
|
+
const normalized = expr // Properties
|
|
10539
|
+
.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ';$&;') // Parenthetical evaluations (filtering and otherwise), directly
|
|
10540
|
+
// within brackets or single quotes
|
|
10541
|
+
.replace(/[['](\??\(.*?\))[\]']/gu, function ($0, $1) {
|
|
10542
|
+
return '[#' + (subx.push($1) - 1) + ']';
|
|
10543
|
+
}) // Escape periods and tildes within properties
|
|
10544
|
+
.replace(/\[['"]([^'\]]*)['"]\]/gu, function ($0, prop) {
|
|
10545
|
+
return "['" + prop.replace(/\./gu, '%@%').replace(/~/gu, '%%@@%%') + "']";
|
|
10546
|
+
}) // Properties operator
|
|
10547
|
+
.replace(/~/gu, ';~;') // Split by property boundaries
|
|
10548
|
+
.replace(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ';') // Reinsert periods within properties
|
|
10549
|
+
.replace(/%@%/gu, '.') // Reinsert tildes within properties
|
|
10550
|
+
.replace(/%%@@%%/gu, '~') // Parent
|
|
10551
|
+
.replace(/(?:;)?(\^+)(?:;)?/gu, function ($0, ups) {
|
|
10552
|
+
return ';' + ups.split('').join(';') + ';';
|
|
10553
|
+
}) // Descendents
|
|
10554
|
+
.replace(/;;;|;;/gu, ';..;') // Remove trailing
|
|
10555
|
+
.replace(/;$|'?\]|'$/gu, '');
|
|
10556
|
+
const exprList = normalized.split(';').map(function (exp) {
|
|
10557
|
+
const match = exp.match(/#(\d+)/u);
|
|
10558
|
+
return !match || !match[1] ? exp : subx[match[1]];
|
|
10559
|
+
});
|
|
10560
|
+
cache[expr] = exprList;
|
|
10561
|
+
return cache[expr].concat();
|
|
10562
|
+
};
|
|
10563
|
+
|
|
10564
|
+
JSONPath.prototype.vm = vm;
|
|
10565
|
+
|
|
10566
|
+
/*!
|
|
10567
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
10568
|
+
* (c) 2017-2022 Joachim Wester
|
|
10569
|
+
* MIT licensed
|
|
10570
|
+
*/
|
|
10571
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
10572
|
+
var extendStatics = function (d, b) {
|
|
10573
|
+
extendStatics = Object.setPrototypeOf ||
|
|
10574
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10575
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
10576
|
+
return extendStatics(d, b);
|
|
10577
|
+
};
|
|
10578
|
+
return function (d, b) {
|
|
10579
|
+
extendStatics(d, b);
|
|
10580
|
+
function __() { this.constructor = d; }
|
|
10581
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
10582
|
+
};
|
|
10583
|
+
})();
|
|
10584
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
10585
|
+
function hasOwnProperty$b(obj, key) {
|
|
10586
|
+
return _hasOwnProperty.call(obj, key);
|
|
10587
|
+
}
|
|
10588
|
+
function _objectKeys(obj) {
|
|
10589
|
+
if (Array.isArray(obj)) {
|
|
10590
|
+
var keys_1 = new Array(obj.length);
|
|
10591
|
+
for (var k = 0; k < keys_1.length; k++) {
|
|
10592
|
+
keys_1[k] = "" + k;
|
|
10593
|
+
}
|
|
10594
|
+
return keys_1;
|
|
10595
|
+
}
|
|
10596
|
+
if (Object.keys) {
|
|
10597
|
+
return Object.keys(obj);
|
|
10598
|
+
}
|
|
10599
|
+
var keys = [];
|
|
10600
|
+
for (var i in obj) {
|
|
10601
|
+
if (hasOwnProperty$b(obj, i)) {
|
|
10602
|
+
keys.push(i);
|
|
10603
|
+
}
|
|
10604
|
+
}
|
|
10605
|
+
return keys;
|
|
10606
|
+
}
|
|
10607
|
+
/**
|
|
10608
|
+
* Deeply clone the object.
|
|
10609
|
+
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
|
10610
|
+
* @param {any} obj value to clone
|
|
10611
|
+
* @return {any} cloned obj
|
|
10612
|
+
*/
|
|
10613
|
+
function _deepClone(obj) {
|
|
10614
|
+
switch (typeof obj) {
|
|
10615
|
+
case "object":
|
|
10616
|
+
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
10617
|
+
case "undefined":
|
|
10618
|
+
return null; //this is how JSON.stringify behaves for array items
|
|
10619
|
+
default:
|
|
10620
|
+
return obj; //no need to clone primitives
|
|
10621
|
+
}
|
|
10622
|
+
}
|
|
10623
|
+
//3x faster than cached /^\d+$/.test(str)
|
|
10624
|
+
function isInteger(str) {
|
|
10625
|
+
var i = 0;
|
|
10626
|
+
var len = str.length;
|
|
10627
|
+
var charCode;
|
|
10628
|
+
while (i < len) {
|
|
10629
|
+
charCode = str.charCodeAt(i);
|
|
10630
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
10631
|
+
i++;
|
|
10632
|
+
continue;
|
|
10633
|
+
}
|
|
10634
|
+
return false;
|
|
10635
|
+
}
|
|
10636
|
+
return true;
|
|
10637
|
+
}
|
|
10638
|
+
/**
|
|
10639
|
+
* Escapes a json pointer path
|
|
10640
|
+
* @param path The raw pointer
|
|
10641
|
+
* @return the Escaped path
|
|
10642
|
+
*/
|
|
10643
|
+
function escapePathComponent(path) {
|
|
10644
|
+
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
|
|
10645
|
+
return path;
|
|
10646
|
+
return path.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
10647
|
+
}
|
|
10648
|
+
/**
|
|
10649
|
+
* Unescapes a json pointer path
|
|
10650
|
+
* @param path The escaped pointer
|
|
10651
|
+
* @return The unescaped path
|
|
10652
|
+
*/
|
|
10653
|
+
function unescapePathComponent(path) {
|
|
10654
|
+
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
10655
|
+
}
|
|
10656
|
+
/**
|
|
10657
|
+
* Recursively checks whether an object has any undefined values inside.
|
|
10658
|
+
*/
|
|
10659
|
+
function hasUndefined(obj) {
|
|
10660
|
+
if (obj === undefined) {
|
|
10661
|
+
return true;
|
|
10662
|
+
}
|
|
10663
|
+
if (obj) {
|
|
10664
|
+
if (Array.isArray(obj)) {
|
|
10665
|
+
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
|
10666
|
+
if (hasUndefined(obj[i_1])) {
|
|
10667
|
+
return true;
|
|
10668
|
+
}
|
|
10669
|
+
}
|
|
10670
|
+
}
|
|
10671
|
+
else if (typeof obj === "object") {
|
|
10672
|
+
var objKeys = _objectKeys(obj);
|
|
10673
|
+
var objKeysLength = objKeys.length;
|
|
10674
|
+
for (var i = 0; i < objKeysLength; i++) {
|
|
10675
|
+
if (hasUndefined(obj[objKeys[i]])) {
|
|
10676
|
+
return true;
|
|
10677
|
+
}
|
|
10678
|
+
}
|
|
10679
|
+
}
|
|
10680
|
+
}
|
|
10681
|
+
return false;
|
|
10682
|
+
}
|
|
10683
|
+
function patchErrorMessageFormatter(message, args) {
|
|
10684
|
+
var messageParts = [message];
|
|
10685
|
+
for (var key in args) {
|
|
10686
|
+
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
|
|
10687
|
+
if (typeof value !== 'undefined') {
|
|
10688
|
+
messageParts.push(key + ": " + value);
|
|
10689
|
+
}
|
|
10690
|
+
}
|
|
10691
|
+
return messageParts.join('\n');
|
|
10692
|
+
}
|
|
10693
|
+
var PatchError = /** @class */ (function (_super) {
|
|
10694
|
+
__extends(PatchError, _super);
|
|
10695
|
+
function PatchError(message, name, index, operation, tree) {
|
|
10696
|
+
var _newTarget = this.constructor;
|
|
10697
|
+
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
|
|
10698
|
+
_this.name = name;
|
|
10699
|
+
_this.index = index;
|
|
10700
|
+
_this.operation = operation;
|
|
10701
|
+
_this.tree = tree;
|
|
10702
|
+
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
|
10703
|
+
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
|
|
10704
|
+
return _this;
|
|
10705
|
+
}
|
|
10706
|
+
return PatchError;
|
|
10707
|
+
}(Error));
|
|
10708
|
+
|
|
10709
|
+
var JsonPatchError = PatchError;
|
|
10710
|
+
var deepClone = _deepClone;
|
|
10711
|
+
/* We use a Javascript hash to store each
|
|
10712
|
+
function. Each hash entry (property) uses
|
|
10713
|
+
the operation identifiers specified in rfc6902.
|
|
10714
|
+
In this way, we can map each patch operation
|
|
10715
|
+
to its dedicated function in efficient way.
|
|
10716
|
+
*/
|
|
10717
|
+
/* The operations applicable to an object */
|
|
10718
|
+
var objOps = {
|
|
10719
|
+
add: function (obj, key, document) {
|
|
10720
|
+
obj[key] = this.value;
|
|
10721
|
+
return { newDocument: document };
|
|
10722
|
+
},
|
|
10723
|
+
remove: function (obj, key, document) {
|
|
10724
|
+
var removed = obj[key];
|
|
10725
|
+
delete obj[key];
|
|
10726
|
+
return { newDocument: document, removed: removed };
|
|
10727
|
+
},
|
|
10728
|
+
replace: function (obj, key, document) {
|
|
10729
|
+
var removed = obj[key];
|
|
10730
|
+
obj[key] = this.value;
|
|
10731
|
+
return { newDocument: document, removed: removed };
|
|
10732
|
+
},
|
|
10733
|
+
move: function (obj, key, document) {
|
|
10734
|
+
/* in case move target overwrites an existing value,
|
|
10735
|
+
return the removed value, this can be taxing performance-wise,
|
|
10736
|
+
and is potentially unneeded */
|
|
10737
|
+
var removed = getValueByPointer(document, this.path);
|
|
10738
|
+
if (removed) {
|
|
10739
|
+
removed = _deepClone(removed);
|
|
10740
|
+
}
|
|
10741
|
+
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
|
10742
|
+
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
|
10743
|
+
return { newDocument: document, removed: removed };
|
|
10744
|
+
},
|
|
10745
|
+
copy: function (obj, key, document) {
|
|
10746
|
+
var valueToCopy = getValueByPointer(document, this.from);
|
|
10747
|
+
// enforce copy by value so further operations don't affect source (see issue #177)
|
|
10748
|
+
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
|
|
10749
|
+
return { newDocument: document };
|
|
10750
|
+
},
|
|
10751
|
+
test: function (obj, key, document) {
|
|
10752
|
+
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
|
10753
|
+
},
|
|
10754
|
+
_get: function (obj, key, document) {
|
|
10755
|
+
this.value = obj[key];
|
|
10756
|
+
return { newDocument: document };
|
|
10757
|
+
}
|
|
10758
|
+
};
|
|
10759
|
+
/* The operations applicable to an array. Many are the same as for the object */
|
|
10760
|
+
var arrOps = {
|
|
10761
|
+
add: function (arr, i, document) {
|
|
10762
|
+
if (isInteger(i)) {
|
|
10763
|
+
arr.splice(i, 0, this.value);
|
|
10764
|
+
}
|
|
10765
|
+
else { // array props
|
|
10766
|
+
arr[i] = this.value;
|
|
10767
|
+
}
|
|
10768
|
+
// this may be needed when using '-' in an array
|
|
10769
|
+
return { newDocument: document, index: i };
|
|
10770
|
+
},
|
|
10771
|
+
remove: function (arr, i, document) {
|
|
10772
|
+
var removedList = arr.splice(i, 1);
|
|
10773
|
+
return { newDocument: document, removed: removedList[0] };
|
|
10774
|
+
},
|
|
10775
|
+
replace: function (arr, i, document) {
|
|
10776
|
+
var removed = arr[i];
|
|
10777
|
+
arr[i] = this.value;
|
|
10778
|
+
return { newDocument: document, removed: removed };
|
|
10779
|
+
},
|
|
10780
|
+
move: objOps.move,
|
|
10781
|
+
copy: objOps.copy,
|
|
10782
|
+
test: objOps.test,
|
|
10783
|
+
_get: objOps._get
|
|
10784
|
+
};
|
|
10785
|
+
/**
|
|
10786
|
+
* Retrieves a value from a JSON document by a JSON pointer.
|
|
10787
|
+
* Returns the value.
|
|
10788
|
+
*
|
|
10789
|
+
* @param document The document to get the value from
|
|
10790
|
+
* @param pointer an escaped JSON pointer
|
|
10791
|
+
* @return The retrieved value
|
|
10792
|
+
*/
|
|
10793
|
+
function getValueByPointer(document, pointer) {
|
|
10794
|
+
if (pointer == '') {
|
|
10795
|
+
return document;
|
|
10796
|
+
}
|
|
10797
|
+
var getOriginalDestination = { op: "_get", path: pointer };
|
|
10798
|
+
applyOperation(document, getOriginalDestination);
|
|
10799
|
+
return getOriginalDestination.value;
|
|
10800
|
+
}
|
|
10801
|
+
/**
|
|
10802
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
|
10803
|
+
* Returns the {newDocument, result} of the operation.
|
|
10804
|
+
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
|
10805
|
+
* If you would like to avoid touching your values, clone them:
|
|
10806
|
+
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
|
10807
|
+
*
|
|
10808
|
+
* @param document The document to patch
|
|
10809
|
+
* @param operation The operation to apply
|
|
10810
|
+
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
|
10811
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
|
10812
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
|
10813
|
+
* @return `{newDocument, result}` after the operation
|
|
10814
|
+
*/
|
|
10815
|
+
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
|
10816
|
+
if (validateOperation === void 0) { validateOperation = false; }
|
|
10817
|
+
if (mutateDocument === void 0) { mutateDocument = true; }
|
|
10818
|
+
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
|
10819
|
+
if (index === void 0) { index = 0; }
|
|
10820
|
+
if (validateOperation) {
|
|
10821
|
+
if (typeof validateOperation == 'function') {
|
|
10822
|
+
validateOperation(operation, 0, document, operation.path);
|
|
10823
|
+
}
|
|
10824
|
+
else {
|
|
10825
|
+
validator$1(operation, 0);
|
|
10826
|
+
}
|
|
10827
|
+
}
|
|
10828
|
+
/* ROOT OPERATIONS */
|
|
10829
|
+
if (operation.path === "") {
|
|
10830
|
+
var returnValue = { newDocument: document };
|
|
10831
|
+
if (operation.op === 'add') {
|
|
10832
|
+
returnValue.newDocument = operation.value;
|
|
10833
|
+
return returnValue;
|
|
10834
|
+
}
|
|
10835
|
+
else if (operation.op === 'replace') {
|
|
10836
|
+
returnValue.newDocument = operation.value;
|
|
10837
|
+
returnValue.removed = document; //document we removed
|
|
10838
|
+
return returnValue;
|
|
10839
|
+
}
|
|
10840
|
+
else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
|
|
10841
|
+
returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
|
|
10842
|
+
if (operation.op === 'move') { // report removed item
|
|
10843
|
+
returnValue.removed = document;
|
|
10844
|
+
}
|
|
10845
|
+
return returnValue;
|
|
10846
|
+
}
|
|
10847
|
+
else if (operation.op === 'test') {
|
|
10848
|
+
returnValue.test = _areEquals(document, operation.value);
|
|
10849
|
+
if (returnValue.test === false) {
|
|
10850
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
10851
|
+
}
|
|
10852
|
+
returnValue.newDocument = document;
|
|
10853
|
+
return returnValue;
|
|
10854
|
+
}
|
|
10855
|
+
else if (operation.op === 'remove') { // a remove on root
|
|
10856
|
+
returnValue.removed = document;
|
|
10857
|
+
returnValue.newDocument = null;
|
|
10858
|
+
return returnValue;
|
|
10859
|
+
}
|
|
10860
|
+
else if (operation.op === '_get') {
|
|
10861
|
+
operation.value = document;
|
|
10862
|
+
return returnValue;
|
|
10863
|
+
}
|
|
10864
|
+
else { /* bad operation */
|
|
10865
|
+
if (validateOperation) {
|
|
10866
|
+
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
|
10867
|
+
}
|
|
10868
|
+
else {
|
|
10869
|
+
return returnValue;
|
|
10870
|
+
}
|
|
10871
|
+
}
|
|
10872
|
+
} /* END ROOT OPERATIONS */
|
|
10873
|
+
else {
|
|
10874
|
+
if (!mutateDocument) {
|
|
10875
|
+
document = _deepClone(document);
|
|
10876
|
+
}
|
|
10877
|
+
var path = operation.path || "";
|
|
10878
|
+
var keys = path.split('/');
|
|
10879
|
+
var obj = document;
|
|
10880
|
+
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
|
|
10881
|
+
var len = keys.length;
|
|
10882
|
+
var existingPathFragment = undefined;
|
|
10883
|
+
var key = void 0;
|
|
10884
|
+
var validateFunction = void 0;
|
|
10885
|
+
if (typeof validateOperation == 'function') {
|
|
10886
|
+
validateFunction = validateOperation;
|
|
10887
|
+
}
|
|
10888
|
+
else {
|
|
10889
|
+
validateFunction = validator$1;
|
|
10890
|
+
}
|
|
10891
|
+
while (true) {
|
|
10892
|
+
key = keys[t];
|
|
10893
|
+
if (key && key.indexOf('~') != -1) {
|
|
10894
|
+
key = unescapePathComponent(key);
|
|
10895
|
+
}
|
|
10896
|
+
if (banPrototypeModifications &&
|
|
10897
|
+
(key == '__proto__' ||
|
|
10898
|
+
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
|
|
10899
|
+
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
|
|
10900
|
+
}
|
|
10901
|
+
if (validateOperation) {
|
|
10902
|
+
if (existingPathFragment === undefined) {
|
|
10903
|
+
if (obj[key] === undefined) {
|
|
10904
|
+
existingPathFragment = keys.slice(0, t).join('/');
|
|
10905
|
+
}
|
|
10906
|
+
else if (t == len - 1) {
|
|
10907
|
+
existingPathFragment = operation.path;
|
|
10908
|
+
}
|
|
10909
|
+
if (existingPathFragment !== undefined) {
|
|
10910
|
+
validateFunction(operation, 0, document, existingPathFragment);
|
|
10911
|
+
}
|
|
10912
|
+
}
|
|
10913
|
+
}
|
|
10914
|
+
t++;
|
|
10915
|
+
if (Array.isArray(obj)) {
|
|
10916
|
+
if (key === '-') {
|
|
10917
|
+
key = obj.length;
|
|
10918
|
+
}
|
|
10919
|
+
else {
|
|
10920
|
+
if (validateOperation && !isInteger(key)) {
|
|
10921
|
+
throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
|
10922
|
+
} // only parse key when it's an integer for `arr.prop` to work
|
|
10923
|
+
else if (isInteger(key)) {
|
|
10924
|
+
key = ~~key;
|
|
10925
|
+
}
|
|
10926
|
+
}
|
|
10927
|
+
if (t >= len) {
|
|
10928
|
+
if (validateOperation && operation.op === "add" && key > obj.length) {
|
|
10929
|
+
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
|
10930
|
+
}
|
|
10931
|
+
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
|
|
10932
|
+
if (returnValue.test === false) {
|
|
10933
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
10934
|
+
}
|
|
10935
|
+
return returnValue;
|
|
10936
|
+
}
|
|
10937
|
+
}
|
|
10938
|
+
else {
|
|
10939
|
+
if (t >= len) {
|
|
10940
|
+
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
|
|
10941
|
+
if (returnValue.test === false) {
|
|
10942
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
10943
|
+
}
|
|
10944
|
+
return returnValue;
|
|
10945
|
+
}
|
|
10946
|
+
}
|
|
10947
|
+
obj = obj[key];
|
|
10948
|
+
// If we have more keys in the path, but the next value isn't a non-null object,
|
|
10949
|
+
// throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.
|
|
10950
|
+
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
|
10951
|
+
throw new JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
|
10952
|
+
}
|
|
10953
|
+
}
|
|
10954
|
+
}
|
|
10955
|
+
}
|
|
10956
|
+
/**
|
|
10957
|
+
* Apply a full JSON Patch array on a JSON document.
|
|
10958
|
+
* Returns the {newDocument, result} of the patch.
|
|
10959
|
+
* It modifies the `document` object and `patch` - it gets the values by reference.
|
|
10960
|
+
* If you would like to avoid touching your values, clone them:
|
|
10961
|
+
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
|
10962
|
+
*
|
|
10963
|
+
* @param document The document to patch
|
|
10964
|
+
* @param patch The patch to apply
|
|
10965
|
+
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
|
|
10966
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
|
10967
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
|
10968
|
+
* @return An array of `{newDocument, result}` after the patch
|
|
10969
|
+
*/
|
|
10970
|
+
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
|
10971
|
+
if (mutateDocument === void 0) { mutateDocument = true; }
|
|
10972
|
+
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
|
10973
|
+
if (validateOperation) {
|
|
10974
|
+
if (!Array.isArray(patch)) {
|
|
10975
|
+
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
|
10976
|
+
}
|
|
10977
|
+
}
|
|
10978
|
+
if (!mutateDocument) {
|
|
10979
|
+
document = _deepClone(document);
|
|
10980
|
+
}
|
|
10981
|
+
var results = new Array(patch.length);
|
|
10982
|
+
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
|
10983
|
+
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
|
|
10984
|
+
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
|
10985
|
+
document = results[i].newDocument; // in case root was replaced
|
|
10986
|
+
}
|
|
10987
|
+
results.newDocument = document;
|
|
10988
|
+
return results;
|
|
10989
|
+
}
|
|
10990
|
+
/**
|
|
10991
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
|
10992
|
+
* Returns the updated document.
|
|
10993
|
+
* Suitable as a reducer.
|
|
10994
|
+
*
|
|
10995
|
+
* @param document The document to patch
|
|
10996
|
+
* @param operation The operation to apply
|
|
10997
|
+
* @return The updated document
|
|
10998
|
+
*/
|
|
10999
|
+
function applyReducer(document, operation, index) {
|
|
11000
|
+
var operationResult = applyOperation(document, operation);
|
|
11001
|
+
if (operationResult.test === false) { // failed test
|
|
11002
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
11003
|
+
}
|
|
11004
|
+
return operationResult.newDocument;
|
|
11005
|
+
}
|
|
11006
|
+
/**
|
|
11007
|
+
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
|
11008
|
+
* @param {object} operation - operation object (patch)
|
|
11009
|
+
* @param {number} index - index of operation in the sequence
|
|
11010
|
+
* @param {object} [document] - object where the operation is supposed to be applied
|
|
11011
|
+
* @param {string} [existingPathFragment] - comes along with `document`
|
|
11012
|
+
*/
|
|
11013
|
+
function validator$1(operation, index, document, existingPathFragment) {
|
|
11014
|
+
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
|
|
11015
|
+
throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
|
|
11016
|
+
}
|
|
11017
|
+
else if (!objOps[operation.op]) {
|
|
11018
|
+
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
|
11019
|
+
}
|
|
11020
|
+
else if (typeof operation.path !== 'string') {
|
|
11021
|
+
throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
|
|
11022
|
+
}
|
|
11023
|
+
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
|
|
11024
|
+
// paths that aren't empty string should start with "/"
|
|
11025
|
+
throw new JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
|
|
11026
|
+
}
|
|
11027
|
+
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
|
|
11028
|
+
throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
|
|
11029
|
+
}
|
|
11030
|
+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
|
|
11031
|
+
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
|
|
11032
|
+
}
|
|
11033
|
+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
|
|
11034
|
+
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
|
|
11035
|
+
}
|
|
11036
|
+
else if (document) {
|
|
11037
|
+
if (operation.op == "add") {
|
|
11038
|
+
var pathLen = operation.path.split("/").length;
|
|
11039
|
+
var existingPathLen = existingPathFragment.split("/").length;
|
|
11040
|
+
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
|
11041
|
+
throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
|
|
11042
|
+
}
|
|
11043
|
+
}
|
|
11044
|
+
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
|
|
11045
|
+
if (operation.path !== existingPathFragment) {
|
|
11046
|
+
throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
|
11047
|
+
}
|
|
11048
|
+
}
|
|
11049
|
+
else if (operation.op === 'move' || operation.op === 'copy') {
|
|
11050
|
+
var existingValue = { op: "_get", path: operation.from, value: undefined };
|
|
11051
|
+
var error = validate([existingValue], document);
|
|
11052
|
+
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
|
|
11053
|
+
throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
|
|
11054
|
+
}
|
|
11055
|
+
}
|
|
11056
|
+
}
|
|
11057
|
+
}
|
|
11058
|
+
/**
|
|
11059
|
+
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
|
11060
|
+
* If error is encountered, returns a JsonPatchError object
|
|
11061
|
+
* @param sequence
|
|
11062
|
+
* @param document
|
|
11063
|
+
* @returns {JsonPatchError|undefined}
|
|
11064
|
+
*/
|
|
11065
|
+
function validate(sequence, document, externalValidator) {
|
|
11066
|
+
try {
|
|
11067
|
+
if (!Array.isArray(sequence)) {
|
|
11068
|
+
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
|
11069
|
+
}
|
|
11070
|
+
if (document) {
|
|
11071
|
+
//clone document and sequence so that we can safely try applying operations
|
|
11072
|
+
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
|
|
11073
|
+
}
|
|
11074
|
+
else {
|
|
11075
|
+
externalValidator = externalValidator || validator$1;
|
|
11076
|
+
for (var i = 0; i < sequence.length; i++) {
|
|
11077
|
+
externalValidator(sequence[i], i, document, undefined);
|
|
11078
|
+
}
|
|
11079
|
+
}
|
|
11080
|
+
}
|
|
11081
|
+
catch (e) {
|
|
11082
|
+
if (e instanceof JsonPatchError) {
|
|
11083
|
+
return e;
|
|
11084
|
+
}
|
|
11085
|
+
else {
|
|
11086
|
+
throw e;
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11089
|
+
}
|
|
11090
|
+
// based on https://github.com/epoberezkin/fast-deep-equal
|
|
11091
|
+
// MIT License
|
|
11092
|
+
// Copyright (c) 2017 Evgeny Poberezkin
|
|
11093
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11094
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
11095
|
+
// in the Software without restriction, including without limitation the rights
|
|
11096
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11097
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11098
|
+
// furnished to do so, subject to the following conditions:
|
|
11099
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11100
|
+
// copies or substantial portions of the Software.
|
|
11101
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
11102
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
11103
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
11104
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
11105
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
11106
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
11107
|
+
// SOFTWARE.
|
|
11108
|
+
function _areEquals(a, b) {
|
|
11109
|
+
if (a === b)
|
|
11110
|
+
return true;
|
|
11111
|
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
11112
|
+
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
|
11113
|
+
if (arrA && arrB) {
|
|
11114
|
+
length = a.length;
|
|
11115
|
+
if (length != b.length)
|
|
11116
|
+
return false;
|
|
11117
|
+
for (i = length; i-- !== 0;)
|
|
11118
|
+
if (!_areEquals(a[i], b[i]))
|
|
11119
|
+
return false;
|
|
11120
|
+
return true;
|
|
11121
|
+
}
|
|
11122
|
+
if (arrA != arrB)
|
|
11123
|
+
return false;
|
|
11124
|
+
var keys = Object.keys(a);
|
|
11125
|
+
length = keys.length;
|
|
11126
|
+
if (length !== Object.keys(b).length)
|
|
11127
|
+
return false;
|
|
11128
|
+
for (i = length; i-- !== 0;)
|
|
11129
|
+
if (!b.hasOwnProperty(keys[i]))
|
|
11130
|
+
return false;
|
|
11131
|
+
for (i = length; i-- !== 0;) {
|
|
11132
|
+
key = keys[i];
|
|
11133
|
+
if (!_areEquals(a[key], b[key]))
|
|
11134
|
+
return false;
|
|
11135
|
+
}
|
|
11136
|
+
return true;
|
|
11137
|
+
}
|
|
11138
|
+
return a !== a && b !== b;
|
|
11139
|
+
}
|
|
11140
|
+
|
|
11141
|
+
var core = /*#__PURE__*/Object.freeze({
|
|
11142
|
+
__proto__: null,
|
|
11143
|
+
JsonPatchError: JsonPatchError,
|
|
11144
|
+
_areEquals: _areEquals,
|
|
11145
|
+
applyOperation: applyOperation,
|
|
11146
|
+
applyPatch: applyPatch,
|
|
11147
|
+
applyReducer: applyReducer,
|
|
11148
|
+
deepClone: deepClone,
|
|
11149
|
+
getValueByPointer: getValueByPointer,
|
|
11150
|
+
validate: validate,
|
|
11151
|
+
validator: validator$1
|
|
11152
|
+
});
|
|
11153
|
+
|
|
11154
|
+
/*!
|
|
11155
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
11156
|
+
* (c) 2017-2021 Joachim Wester
|
|
11157
|
+
* MIT license
|
|
11158
|
+
*/
|
|
11159
|
+
var beforeDict = new WeakMap();
|
|
11160
|
+
var Mirror = /** @class */ (function () {
|
|
11161
|
+
function Mirror(obj) {
|
|
11162
|
+
this.observers = new Map();
|
|
11163
|
+
this.obj = obj;
|
|
11164
|
+
}
|
|
11165
|
+
return Mirror;
|
|
11166
|
+
}());
|
|
11167
|
+
var ObserverInfo = /** @class */ (function () {
|
|
11168
|
+
function ObserverInfo(callback, observer) {
|
|
11169
|
+
this.callback = callback;
|
|
11170
|
+
this.observer = observer;
|
|
11171
|
+
}
|
|
11172
|
+
return ObserverInfo;
|
|
11173
|
+
}());
|
|
11174
|
+
function getMirror(obj) {
|
|
11175
|
+
return beforeDict.get(obj);
|
|
11176
|
+
}
|
|
11177
|
+
function getObserverFromMirror(mirror, callback) {
|
|
11178
|
+
return mirror.observers.get(callback);
|
|
11179
|
+
}
|
|
11180
|
+
function removeObserverFromMirror(mirror, observer) {
|
|
11181
|
+
mirror.observers.delete(observer.callback);
|
|
11182
|
+
}
|
|
11183
|
+
/**
|
|
11184
|
+
* Detach an observer from an object
|
|
11185
|
+
*/
|
|
11186
|
+
function unobserve(root, observer) {
|
|
11187
|
+
observer.unobserve();
|
|
11188
|
+
}
|
|
11189
|
+
/**
|
|
11190
|
+
* Observes changes made to an object, which can then be retrieved using generate
|
|
11191
|
+
*/
|
|
11192
|
+
function observe(obj, callback) {
|
|
11193
|
+
var patches = [];
|
|
11194
|
+
var observer;
|
|
11195
|
+
var mirror = getMirror(obj);
|
|
11196
|
+
if (!mirror) {
|
|
11197
|
+
mirror = new Mirror(obj);
|
|
11198
|
+
beforeDict.set(obj, mirror);
|
|
11199
|
+
}
|
|
11200
|
+
else {
|
|
11201
|
+
var observerInfo = getObserverFromMirror(mirror, callback);
|
|
11202
|
+
observer = observerInfo && observerInfo.observer;
|
|
11203
|
+
}
|
|
11204
|
+
if (observer) {
|
|
11205
|
+
return observer;
|
|
11206
|
+
}
|
|
11207
|
+
observer = {};
|
|
11208
|
+
mirror.value = _deepClone(obj);
|
|
11209
|
+
if (callback) {
|
|
11210
|
+
observer.callback = callback;
|
|
11211
|
+
observer.next = null;
|
|
11212
|
+
var dirtyCheck = function () {
|
|
11213
|
+
generate(observer);
|
|
11214
|
+
};
|
|
11215
|
+
var fastCheck = function () {
|
|
11216
|
+
clearTimeout(observer.next);
|
|
11217
|
+
observer.next = setTimeout(dirtyCheck);
|
|
11218
|
+
};
|
|
11219
|
+
if (typeof window !== 'undefined') { //not Node
|
|
11220
|
+
window.addEventListener('mouseup', fastCheck);
|
|
11221
|
+
window.addEventListener('keyup', fastCheck);
|
|
11222
|
+
window.addEventListener('mousedown', fastCheck);
|
|
11223
|
+
window.addEventListener('keydown', fastCheck);
|
|
11224
|
+
window.addEventListener('change', fastCheck);
|
|
11225
|
+
}
|
|
11226
|
+
}
|
|
11227
|
+
observer.patches = patches;
|
|
11228
|
+
observer.object = obj;
|
|
11229
|
+
observer.unobserve = function () {
|
|
11230
|
+
generate(observer);
|
|
11231
|
+
clearTimeout(observer.next);
|
|
11232
|
+
removeObserverFromMirror(mirror, observer);
|
|
11233
|
+
if (typeof window !== 'undefined') {
|
|
11234
|
+
window.removeEventListener('mouseup', fastCheck);
|
|
11235
|
+
window.removeEventListener('keyup', fastCheck);
|
|
11236
|
+
window.removeEventListener('mousedown', fastCheck);
|
|
11237
|
+
window.removeEventListener('keydown', fastCheck);
|
|
11238
|
+
window.removeEventListener('change', fastCheck);
|
|
11239
|
+
}
|
|
11240
|
+
};
|
|
11241
|
+
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
|
11242
|
+
return observer;
|
|
11243
|
+
}
|
|
11244
|
+
/**
|
|
11245
|
+
* Generate an array of patches from an observer
|
|
11246
|
+
*/
|
|
11247
|
+
function generate(observer, invertible) {
|
|
11248
|
+
if (invertible === void 0) { invertible = false; }
|
|
11249
|
+
var mirror = beforeDict.get(observer.object);
|
|
11250
|
+
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
|
11251
|
+
if (observer.patches.length) {
|
|
11252
|
+
applyPatch(mirror.value, observer.patches);
|
|
11253
|
+
}
|
|
11254
|
+
var temp = observer.patches;
|
|
11255
|
+
if (temp.length > 0) {
|
|
11256
|
+
observer.patches = [];
|
|
11257
|
+
if (observer.callback) {
|
|
11258
|
+
observer.callback(temp);
|
|
11259
|
+
}
|
|
11260
|
+
}
|
|
11261
|
+
return temp;
|
|
11262
|
+
}
|
|
11263
|
+
// Dirty check if obj is different from mirror, generate patches and update mirror
|
|
11264
|
+
function _generate(mirror, obj, patches, path, invertible) {
|
|
11265
|
+
if (obj === mirror) {
|
|
11266
|
+
return;
|
|
11267
|
+
}
|
|
11268
|
+
if (typeof obj.toJSON === "function") {
|
|
11269
|
+
obj = obj.toJSON();
|
|
11270
|
+
}
|
|
11271
|
+
var newKeys = _objectKeys(obj);
|
|
11272
|
+
var oldKeys = _objectKeys(mirror);
|
|
11273
|
+
var deleted = false;
|
|
11274
|
+
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
|
|
11275
|
+
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
|
11276
|
+
var key = oldKeys[t];
|
|
11277
|
+
var oldVal = mirror[key];
|
|
11278
|
+
if (hasOwnProperty$b(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
|
|
11279
|
+
var newVal = obj[key];
|
|
11280
|
+
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
|
11281
|
+
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
|
|
11282
|
+
}
|
|
11283
|
+
else {
|
|
11284
|
+
if (oldVal !== newVal) {
|
|
11285
|
+
if (invertible) {
|
|
11286
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
11287
|
+
}
|
|
11288
|
+
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
|
|
11289
|
+
}
|
|
11290
|
+
}
|
|
11291
|
+
}
|
|
11292
|
+
else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
|
11293
|
+
if (invertible) {
|
|
11294
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
11295
|
+
}
|
|
11296
|
+
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
|
|
11297
|
+
deleted = true; // property has been deleted
|
|
11298
|
+
}
|
|
11299
|
+
else {
|
|
11300
|
+
if (invertible) {
|
|
11301
|
+
patches.push({ op: "test", path: path, value: mirror });
|
|
11302
|
+
}
|
|
11303
|
+
patches.push({ op: "replace", path: path, value: obj });
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
if (!deleted && newKeys.length == oldKeys.length) {
|
|
11307
|
+
return;
|
|
11308
|
+
}
|
|
11309
|
+
for (var t = 0; t < newKeys.length; t++) {
|
|
11310
|
+
var key = newKeys[t];
|
|
11311
|
+
if (!hasOwnProperty$b(mirror, key) && obj[key] !== undefined) {
|
|
11312
|
+
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
|
|
11313
|
+
}
|
|
11314
|
+
}
|
|
11315
|
+
}
|
|
11316
|
+
/**
|
|
11317
|
+
* Create an array of patches from the differences in two objects
|
|
11318
|
+
*/
|
|
11319
|
+
function compare(tree1, tree2, invertible) {
|
|
11320
|
+
if (invertible === void 0) { invertible = false; }
|
|
11321
|
+
var patches = [];
|
|
11322
|
+
_generate(tree1, tree2, patches, '', invertible);
|
|
11323
|
+
return patches;
|
|
11324
|
+
}
|
|
11325
|
+
|
|
11326
|
+
var duplex = /*#__PURE__*/Object.freeze({
|
|
11327
|
+
__proto__: null,
|
|
11328
|
+
compare: compare,
|
|
11329
|
+
generate: generate,
|
|
11330
|
+
observe: observe,
|
|
11331
|
+
unobserve: unobserve
|
|
11332
|
+
});
|
|
11333
|
+
|
|
11334
|
+
Object.assign({}, core, duplex, {
|
|
11335
|
+
JsonPatchError: PatchError,
|
|
11336
|
+
deepClone: _deepClone,
|
|
11337
|
+
escapePathComponent,
|
|
11338
|
+
unescapePathComponent
|
|
11339
|
+
});
|
|
11340
|
+
|
|
9839
11341
|
toast.configure({
|
|
9840
11342
|
autoClose: 3000,
|
|
9841
11343
|
hideProgressBar: true,
|
|
@@ -10233,7 +11735,82 @@ var getUrlWithSearchParams = function (url, params) {
|
|
|
10233
11735
|
/**
|
|
10234
11736
|
* Custom exception logger function for logging errors to sentry
|
|
10235
11737
|
*/
|
|
10236
|
-
var logExceptionToSentry = captureException.bind(window);
|
|
11738
|
+
var logExceptionToSentry = captureException.bind(window);
|
|
11739
|
+
var customStyles = {
|
|
11740
|
+
control: function (base, state) { return (__assign(__assign({}, base), { minHeight: '32px', boxShadow: 'none', border: 'none', cursor: 'pointer', background: 'transparent' })); },
|
|
11741
|
+
indicatorSeparator: function (base, state) { return (__assign(__assign({}, base), { width: 0 })); },
|
|
11742
|
+
valueContainer: function (base, state) { return (__assign(__assign({}, base), { padding: '0', fontSize: '13px', fontWeight: '600' })); },
|
|
11743
|
+
dropdownIndicator: function (base, state) { return (__assign(__assign({}, base), { color: 'var(--N400)', padding: '0 8px', transition: 'all .2s ease', transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)' })); },
|
|
11744
|
+
};
|
|
11745
|
+
var getFilteredChartVersions = function (charts, selectedChartType) {
|
|
11746
|
+
// Filter chart versions based on selected chart type
|
|
11747
|
+
return charts
|
|
11748
|
+
.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.chartType) === selectedChartType.value; })
|
|
11749
|
+
.map(function (item) { return ({
|
|
11750
|
+
value: item === null || item === void 0 ? void 0 : item.chartVersion,
|
|
11751
|
+
label: item === null || item === void 0 ? void 0 : item.chartVersion,
|
|
11752
|
+
chartRefId: item.chartRefId,
|
|
11753
|
+
}); });
|
|
11754
|
+
};
|
|
11755
|
+
function removeEmptyObjectKeysAndNullValues(obj) {
|
|
11756
|
+
// It recursively removes empty object keys and array values that are null
|
|
11757
|
+
for (var key in obj) {
|
|
11758
|
+
if (Array.isArray(obj[key])) {
|
|
11759
|
+
if (obj[key].length === 0)
|
|
11760
|
+
continue;
|
|
11761
|
+
obj[key] = obj[key].filter(function (item) { return item !== null; });
|
|
11762
|
+
// Check if the array is empty
|
|
11763
|
+
if (obj[key].length === 0) {
|
|
11764
|
+
delete obj[key]; // Delete the key if the array is empty
|
|
11765
|
+
}
|
|
11766
|
+
}
|
|
11767
|
+
else if (obj[key] && typeof obj[key] === 'object') {
|
|
11768
|
+
if (removeEmptyObjectKeysAndNullValues(obj[key])) {
|
|
11769
|
+
delete obj[key];
|
|
11770
|
+
}
|
|
11771
|
+
}
|
|
11772
|
+
else if (obj[key] === undefined) {
|
|
11773
|
+
delete obj[key];
|
|
11774
|
+
}
|
|
11775
|
+
}
|
|
11776
|
+
return Object.keys(obj).length === 0;
|
|
11777
|
+
}
|
|
11778
|
+
function getUnlockedJSON(json, jsonPathArray) {
|
|
11779
|
+
var jsonCopy = JSON.parse(JSON.stringify(json));
|
|
11780
|
+
var patches = jsonPathArray.flatMap(function (jsonPath) {
|
|
11781
|
+
var pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' });
|
|
11782
|
+
return pathsToRemove.map(function (result) {
|
|
11783
|
+
return Array.isArray(result.parent)
|
|
11784
|
+
? { op: 'replace', path: result.pointer, value: null }
|
|
11785
|
+
: { op: 'remove', path: result.pointer };
|
|
11786
|
+
});
|
|
11787
|
+
});
|
|
11788
|
+
var newDocument = applyPatch(jsonCopy, patches).newDocument;
|
|
11789
|
+
removeEmptyObjectKeysAndNullValues(newDocument);
|
|
11790
|
+
return newDocument;
|
|
11791
|
+
}
|
|
11792
|
+
function getLockedJSON(json, jsonPathArray) {
|
|
11793
|
+
var jsonCopy = JSON.parse(JSON.stringify(json));
|
|
11794
|
+
var resultJson = {};
|
|
11795
|
+
jsonPathArray.forEach(function (jsonPath) {
|
|
11796
|
+
var elements = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' });
|
|
11797
|
+
elements.forEach(function (element) {
|
|
11798
|
+
var pathArray = JSONPath.toPathArray(element.path);
|
|
11799
|
+
var lastPath = pathArray.pop();
|
|
11800
|
+
var current = resultJson;
|
|
11801
|
+
for (var i = 0; i < pathArray.length; i++) {
|
|
11802
|
+
var key_1 = isNaN(Number(pathArray[i])) ? pathArray[i] : parseInt(pathArray[i]);
|
|
11803
|
+
if (!current[key_1]) {
|
|
11804
|
+
current[key_1] = isNaN(Number(pathArray[i + 1])) ? {} : [];
|
|
11805
|
+
}
|
|
11806
|
+
current = current[key_1];
|
|
11807
|
+
}
|
|
11808
|
+
var key = isNaN(Number(lastPath)) ? lastPath : parseInt(lastPath);
|
|
11809
|
+
current[key] = element.value;
|
|
11810
|
+
});
|
|
11811
|
+
});
|
|
11812
|
+
return resultJson['$'];
|
|
11813
|
+
}
|
|
10237
11814
|
|
|
10238
11815
|
function Progressing(_a) {
|
|
10239
11816
|
var pageLoader = _a.pageLoader, size = _a.size, theme = _a.theme, styles = _a.styles, fillColor = _a.fillColor;
|
|
@@ -10246,7 +11823,7 @@ function DetailsProgressing(_a) {
|
|
|
10246
11823
|
}
|
|
10247
11824
|
|
|
10248
11825
|
var VisibleModal = /** @class */ (function (_super) {
|
|
10249
|
-
__extends(VisibleModal, _super);
|
|
11826
|
+
__extends$1(VisibleModal, _super);
|
|
10250
11827
|
function VisibleModal(props) {
|
|
10251
11828
|
var _this = _super.call(this, props) || this;
|
|
10252
11829
|
_this.modalRef = document.getElementById('visible-modal');
|
|
@@ -10377,7 +11954,7 @@ var SvgIcCross = function SvgIcCross(props) {
|
|
|
10377
11954
|
var close = "data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M19.2803%205.78033C19.5732%205.48744%2019.5732%205.01256%2019.2803%204.71967C18.9874%204.42678%2018.5126%204.42678%2018.2197%204.71967L19.2803%205.78033ZM4.71967%2018.2197C4.42678%2018.5126%204.42678%2018.9874%204.71967%2019.2803C5.01256%2019.5732%205.48744%2019.5732%205.78033%2019.2803L4.71967%2018.2197ZM18.2197%2019.2803C18.5126%2019.5732%2018.9874%2019.5732%2019.2803%2019.2803C19.5732%2018.9874%2019.5732%2018.5126%2019.2803%2018.2197L18.2197%2019.2803ZM5.78033%204.71967C5.48744%204.42678%205.01256%204.42678%204.71967%204.71967C4.42678%205.01256%204.42678%205.48744%204.71967%205.78033L5.78033%204.71967ZM18.2197%204.71967L11.4697%2011.4697L12.5303%2012.5303L19.2803%205.78033L18.2197%204.71967ZM11.4697%2011.4697L4.71967%2018.2197L5.78033%2019.2803L12.5303%2012.5303L11.4697%2011.4697ZM19.2803%2018.2197L12.5303%2011.4697L11.4697%2012.5303L18.2197%2019.2803L19.2803%2018.2197ZM12.5303%2011.4697L5.78033%204.71967L4.71967%205.78033L11.4697%2012.5303L12.5303%2011.4697Z%22%20fill%3D%22%23596168%22%2F%3E%3C%2Fsvg%3E";
|
|
10378
11955
|
|
|
10379
11956
|
var OpaqueModal = /** @class */ (function (_super) {
|
|
10380
|
-
__extends(OpaqueModal, _super);
|
|
11957
|
+
__extends$1(OpaqueModal, _super);
|
|
10381
11958
|
function OpaqueModal() {
|
|
10382
11959
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
10383
11960
|
_this.modalRef = document.getElementById('full-screen-modal');
|
|
@@ -10401,7 +11978,7 @@ var OpaqueModal = /** @class */ (function (_super) {
|
|
|
10401
11978
|
}(React.Component));
|
|
10402
11979
|
|
|
10403
11980
|
var VisibleModal2 = /** @class */ (function (_super) {
|
|
10404
|
-
__extends(VisibleModal2, _super);
|
|
11981
|
+
__extends$1(VisibleModal2, _super);
|
|
10405
11982
|
function VisibleModal2(props) {
|
|
10406
11983
|
var _this = _super.call(this, props) || this;
|
|
10407
11984
|
_this.modalRef = document.getElementById('visible-modal-2');
|
|
@@ -10512,7 +12089,7 @@ var BreadCrumb = function (_a) {
|
|
|
10512
12089
|
|
|
10513
12090
|
var RadioGroupContext = React.createContext({ name: '', value: '', disabled: false, onChange: function (event) { } });
|
|
10514
12091
|
var RadioGroupItem = /** @class */ (function (_super) {
|
|
10515
|
-
__extends(RadioGroupItem, _super);
|
|
12092
|
+
__extends$1(RadioGroupItem, _super);
|
|
10516
12093
|
function RadioGroupItem() {
|
|
10517
12094
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
10518
12095
|
}
|
|
@@ -10525,7 +12102,7 @@ var RadioGroupItem = /** @class */ (function (_super) {
|
|
|
10525
12102
|
return RadioGroupItem;
|
|
10526
12103
|
}(React.Component));
|
|
10527
12104
|
var RadioGroup$1 = /** @class */ (function (_super) {
|
|
10528
|
-
__extends(RadioGroup, _super);
|
|
12105
|
+
__extends$1(RadioGroup, _super);
|
|
10529
12106
|
function RadioGroup() {
|
|
10530
12107
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
10531
12108
|
}
|
|
@@ -15106,7 +16683,7 @@ DeleteDialog.Description = DeleteDialogDescription;
|
|
|
15106
16683
|
//TODO: may not need context
|
|
15107
16684
|
var DialogFormContext = React.createContext({ title: '', isLoading: false, close: function (event) { }, onSave: function (event) { } });
|
|
15108
16685
|
var DialogForm = /** @class */ (function (_super) {
|
|
15109
|
-
__extends(DialogForm, _super);
|
|
16686
|
+
__extends$1(DialogForm, _super);
|
|
15110
16687
|
function DialogForm(props) {
|
|
15111
16688
|
var _this = _super.call(this, props) || this;
|
|
15112
16689
|
_this.escFunction = _this.escFunction.bind(_this);
|
|
@@ -15142,7 +16719,7 @@ var DialogForm = /** @class */ (function (_super) {
|
|
|
15142
16719
|
return DialogForm;
|
|
15143
16720
|
}(React.Component));
|
|
15144
16721
|
var DialogFormSubmit = /** @class */ (function (_super) {
|
|
15145
|
-
__extends(DialogFormSubmit, _super);
|
|
16722
|
+
__extends$1(DialogFormSubmit, _super);
|
|
15146
16723
|
function DialogFormSubmit() {
|
|
15147
16724
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
15148
16725
|
}
|
|
@@ -22909,6 +24486,9 @@ function createGitCommitUrl(url, revision) {
|
|
|
22909
24486
|
}
|
|
22910
24487
|
}
|
|
22911
24488
|
return "NA";
|
|
24489
|
+
}
|
|
24490
|
+
function fetchChartTemplateVersions() {
|
|
24491
|
+
return get("".concat(ROUTES.DEPLOYMENT_TEMPLATE_LIST, "?appId=-1&envId=-1"));
|
|
22912
24492
|
}
|
|
22913
24493
|
|
|
22914
24494
|
/*
|
|
@@ -22921,7 +24501,7 @@ Valid States of Checkbox:
|
|
|
22921
24501
|
6. disabled: false, checked: true, value: CHECKED
|
|
22922
24502
|
*/
|
|
22923
24503
|
var Checkbox$1 = /** @class */ (function (_super) {
|
|
22924
|
-
__extends(Checkbox, _super);
|
|
24504
|
+
__extends$1(Checkbox, _super);
|
|
22925
24505
|
function Checkbox() {
|
|
22926
24506
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
22927
24507
|
}
|
|
@@ -26623,6 +28203,53 @@ function DevtronProgressing(_a) {
|
|
|
26623
28203
|
return (jsxRuntime.jsx("div", __assign({ className: parentClasses ? parentClasses : '' }, { children: jsxRuntime.jsx(SvgIcRotateDevtron, { className: classes ? classes : '' }) })));
|
|
26624
28204
|
}
|
|
26625
28205
|
|
|
28206
|
+
// @TODO: Generalize this component to be used in CodeEditor as Chart selector toolbar
|
|
28207
|
+
// when the Code Editor is moved to the fe-common-lib
|
|
28208
|
+
var ChartVersionAndTypeSelector = function (_a) {
|
|
28209
|
+
var setSelectedChartRefId = _a.setSelectedChartRefId;
|
|
28210
|
+
var _b = __read(React.useState([]), 2), charts = _b[0], setCharts = _b[1];
|
|
28211
|
+
var _c = __read(React.useState(null), 2), selectedChartType = _c[0], setSelectedChartType = _c[1];
|
|
28212
|
+
var _d = __read(React.useState([]), 2), chartVersionOptions = _d[0], setChartVersionOptions = _d[1];
|
|
28213
|
+
var _e = __read(React.useState([]), 2), chartTypeOptions = _e[0], setChartTypeOptions = _e[1];
|
|
28214
|
+
var _f = __read(React.useState(null), 2), selectedChartVersion = _f[0], setSelectedChartVersion = _f[1];
|
|
28215
|
+
React.useEffect(function () {
|
|
28216
|
+
fetchChartTemplateVersions()
|
|
28217
|
+
.then(function (res) {
|
|
28218
|
+
var charts = (res === null || res === void 0 ? void 0 : res.result) || [];
|
|
28219
|
+
setCharts(charts);
|
|
28220
|
+
// Extract unique chart types from the data
|
|
28221
|
+
var chartTypeOptions = __spreadArray([], __read(new Set(charts.map(function (item) { return item.chartType; }))), false).map(function (type) { return ({
|
|
28222
|
+
value: type,
|
|
28223
|
+
label: type,
|
|
28224
|
+
}); });
|
|
28225
|
+
setChartTypeOptions(chartTypeOptions);
|
|
28226
|
+
var filteredVersions = getFilteredChartVersions(charts, chartTypeOptions[0]);
|
|
28227
|
+
selectFirstChartVersion(filteredVersions);
|
|
28228
|
+
})
|
|
28229
|
+
.catch(function (err) {
|
|
28230
|
+
showError(err);
|
|
28231
|
+
});
|
|
28232
|
+
}, []);
|
|
28233
|
+
var selectFirstChartVersion = function (filteredVersions) {
|
|
28234
|
+
var _a;
|
|
28235
|
+
setChartVersionOptions(filteredVersions);
|
|
28236
|
+
setSelectedChartVersion(filteredVersions[0]); // Select the first chart version by default
|
|
28237
|
+
setSelectedChartRefId((_a = filteredVersions[0]) === null || _a === void 0 ? void 0 : _a.chartRefId);
|
|
28238
|
+
};
|
|
28239
|
+
// Function to update chart version options based on selected chart type
|
|
28240
|
+
var handleChartTypeChange = function (selectedOption) {
|
|
28241
|
+
setSelectedChartType(selectedOption);
|
|
28242
|
+
var filteredVersions = getFilteredChartVersions(charts, selectedOption);
|
|
28243
|
+
selectFirstChartVersion(filteredVersions);
|
|
28244
|
+
};
|
|
28245
|
+
// Function to handle the change of the selected chart version
|
|
28246
|
+
var handleChartVersionChange = function (selectedOption) {
|
|
28247
|
+
setSelectedChartVersion(selectedOption);
|
|
28248
|
+
setSelectedChartRefId(selectedOption.chartRefId);
|
|
28249
|
+
};
|
|
28250
|
+
return (jsxRuntime.jsxs("div", __assign({ className: "flex" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "chart-type-options flex", "data-testid": "chart-type-options" }, { children: [jsxRuntime.jsx("span", __assign({ className: "chart-type-options-label mr-4" }, { children: "Chart Type" })), jsxRuntime.jsx(ReactSelect, { value: selectedChartType !== null && selectedChartType !== void 0 ? selectedChartType : chartTypeOptions[0], options: chartTypeOptions, onChange: handleChartTypeChange, styles: customStyles })] })), jsxRuntime.jsxs("div", __assign({ className: "chart-version-options flex", "data-testid": "chart-version-options" }, { children: [jsxRuntime.jsx("span", __assign({ className: "chart-version-options-label mr-4" }, { children: "Chart Version" })), jsxRuntime.jsx(ReactSelect, { value: selectedChartVersion !== null && selectedChartVersion !== void 0 ? selectedChartVersion : chartVersionOptions[0], options: chartVersionOptions, onChange: handleChartVersionChange, styles: customStyles })] }))] })));
|
|
28251
|
+
};
|
|
28252
|
+
|
|
26626
28253
|
function CustomInput(_a) {
|
|
26627
28254
|
var name = _a.name, value = _a.value, error = _a.error, onChange = _a.onChange, _b = _a.onFocus, onFocus = _b === void 0 ? function (e) { } : _b, label = _a.label, _c = _a.type, type = _c === void 0 ? 'text' : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.labelClassName, labelClassName = _e === void 0 ? '' : _e, _f = _a.placeholder, placeholder = _f === void 0 ? '' : _f, _g = _a.tabIndex, tabIndex = _g === void 0 ? 1 : _g, _h = _a.dataTestid, dataTestid = _h === void 0 ? '' : _h, _j = _a.isRequiredField, isRequiredField = _j === void 0 ? false : _j, _k = _a.autoFocus, autoFocus = _k === void 0 ? false : _k, _l = _a.rootClassName, rootClassName = _l === void 0 ? '' : _l, _m = _a.autoComplete, autoComplete = _m === void 0 ? 'off' : _m, _o = _a.helperText, helperText = _o === void 0 ? '' : _o, handleOnBlur = _a.handleOnBlur, _p = _a.readOnly, readOnly = _p === void 0 ? false : _p, _q = _a.noTrim, noTrim = _q === void 0 ? false : _q, ref = _a.ref, onKeyPress = _a.onKeyPress, defaultValue = _a.defaultValue, onKeyDown = _a.onKeyDown, required = _a.required, additionalErrorInfo = _a.additionalErrorInfo;
|
|
26628
28255
|
function handleError(error) {
|
|
@@ -26684,6 +28311,7 @@ exports.BreadCrumb = BreadCrumb;
|
|
|
26684
28311
|
exports.BreadcrumbStore = Store;
|
|
26685
28312
|
exports.BuildStageVariable = BuildStageVariable;
|
|
26686
28313
|
exports.CDModalTab = CDModalTab;
|
|
28314
|
+
exports.ChartVersionAndTypeSelector = ChartVersionAndTypeSelector;
|
|
26687
28315
|
exports.Checkbox = Checkbox$1;
|
|
26688
28316
|
exports.ClearIndicator = ClearIndicator;
|
|
26689
28317
|
exports.ClipboardButton = ClipboardButton;
|
|
@@ -26756,17 +28384,22 @@ exports.VisibleModal2 = VisibleModal2;
|
|
|
26756
28384
|
exports.closeOnEscKeyPressed = closeOnEscKeyPressed;
|
|
26757
28385
|
exports.copyToClipboard = copyToClipboard;
|
|
26758
28386
|
exports.createGitCommitUrl = createGitCommitUrl;
|
|
28387
|
+
exports.customStyles = customStyles;
|
|
26759
28388
|
exports.extractImage = extractImage;
|
|
28389
|
+
exports.fetchChartTemplateVersions = fetchChartTemplateVersions;
|
|
26760
28390
|
exports.genericCDMaterialsService = genericCDMaterialsService;
|
|
26761
28391
|
exports.get = get;
|
|
26762
28392
|
exports.getAlphabetIcon = getAlphabetIcon;
|
|
26763
28393
|
exports.getCookie = getCookie;
|
|
26764
28394
|
exports.getEmptyArrayOfLength = getEmptyArrayOfLength;
|
|
28395
|
+
exports.getFilteredChartVersions = getFilteredChartVersions;
|
|
26765
28396
|
exports.getInferredTypeFromValueType = getInferredTypeFromValueType;
|
|
28397
|
+
exports.getLockedJSON = getLockedJSON;
|
|
26766
28398
|
exports.getLoginInfo = getLoginInfo;
|
|
26767
28399
|
exports.getRandomColor = getRandomColor;
|
|
26768
28400
|
exports.getRedirectionProps = getRedirectionProps;
|
|
26769
28401
|
exports.getTeamListMin = getTeamListMin;
|
|
28402
|
+
exports.getUnlockedJSON = getUnlockedJSON;
|
|
26770
28403
|
exports.getUrlWithSearchParams = getUrlWithSearchParams;
|
|
26771
28404
|
exports.getUserRole = getUserRole;
|
|
26772
28405
|
exports.handleUTCTime = handleUTCTime;
|