@devtron-labs/devtron-fe-common-lib 0.0.50 → 0.0.51
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 +1651 -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 +69 -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;
|
|
@@ -2175,7 +2177,7 @@ eventManager.on(2
|
|
|
2175
2177
|
});
|
|
2176
2178
|
|
|
2177
2179
|
var ToastBody = /** @class */ (function (_super) {
|
|
2178
|
-
__extends(ToastBody, _super);
|
|
2180
|
+
__extends$1(ToastBody, _super);
|
|
2179
2181
|
function ToastBody() {
|
|
2180
2182
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2181
2183
|
}
|
|
@@ -2185,7 +2187,7 @@ var ToastBody = /** @class */ (function (_super) {
|
|
|
2185
2187
|
return ToastBody;
|
|
2186
2188
|
}(React.Component));
|
|
2187
2189
|
var ToastBody3 = /** @class */ (function (_super) {
|
|
2188
|
-
__extends(ToastBody3, _super);
|
|
2190
|
+
__extends$1(ToastBody3, _super);
|
|
2189
2191
|
function ToastBody3() {
|
|
2190
2192
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2191
2193
|
}
|
|
@@ -2195,7 +2197,7 @@ var ToastBody3 = /** @class */ (function (_super) {
|
|
|
2195
2197
|
return ToastBody3;
|
|
2196
2198
|
}(React.Component));
|
|
2197
2199
|
var ToastBodyWithButton = /** @class */ (function (_super) {
|
|
2198
|
-
__extends(ToastBodyWithButton, _super);
|
|
2200
|
+
__extends$1(ToastBodyWithButton, _super);
|
|
2199
2201
|
function ToastBodyWithButton() {
|
|
2200
2202
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2201
2203
|
}
|
|
@@ -2244,7 +2246,7 @@ function ErrorScreenNotFound() {
|
|
|
2244
2246
|
}
|
|
2245
2247
|
|
|
2246
2248
|
var ErrorScreenManager = /** @class */ (function (_super) {
|
|
2247
|
-
__extends(ErrorScreenManager, _super);
|
|
2249
|
+
__extends$1(ErrorScreenManager, _super);
|
|
2248
2250
|
function ErrorScreenManager() {
|
|
2249
2251
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2250
2252
|
}
|
|
@@ -2275,7 +2277,7 @@ var ErrorScreenManager = /** @class */ (function (_super) {
|
|
|
2275
2277
|
return ErrorScreenManager;
|
|
2276
2278
|
}(React.Component));
|
|
2277
2279
|
var ErrorScreenNotAuthorized = /** @class */ (function (_super) {
|
|
2278
|
-
__extends(ErrorScreenNotAuthorized, _super);
|
|
2280
|
+
__extends$1(ErrorScreenNotAuthorized, _super);
|
|
2279
2281
|
function ErrorScreenNotAuthorized() {
|
|
2280
2282
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
2281
2283
|
}
|
|
@@ -9864,6 +9866,1506 @@ var moment$1 = {
|
|
|
9864
9866
|
|
|
9865
9867
|
var moment = momentExports;
|
|
9866
9868
|
|
|
9869
|
+
const {
|
|
9870
|
+
hasOwnProperty: hasOwnProp
|
|
9871
|
+
} = Object.prototype;
|
|
9872
|
+
/**
|
|
9873
|
+
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
|
|
9874
|
+
*/
|
|
9875
|
+
|
|
9876
|
+
/**
|
|
9877
|
+
* @typedef {any} AnyItem
|
|
9878
|
+
*/
|
|
9879
|
+
|
|
9880
|
+
/**
|
|
9881
|
+
* @typedef {any} AnyResult
|
|
9882
|
+
*/
|
|
9883
|
+
|
|
9884
|
+
/**
|
|
9885
|
+
* Copies array and then pushes item into it.
|
|
9886
|
+
* @param {GenericArray} arr Array to copy and into which to push
|
|
9887
|
+
* @param {AnyItem} item Array item to add (to end)
|
|
9888
|
+
* @returns {GenericArray} Copy of the original array
|
|
9889
|
+
*/
|
|
9890
|
+
|
|
9891
|
+
function push(arr, item) {
|
|
9892
|
+
arr = arr.slice();
|
|
9893
|
+
arr.push(item);
|
|
9894
|
+
return arr;
|
|
9895
|
+
}
|
|
9896
|
+
/**
|
|
9897
|
+
* Copies array and then unshifts item into it.
|
|
9898
|
+
* @param {AnyItem} item Array item to add (to beginning)
|
|
9899
|
+
* @param {GenericArray} arr Array to copy and into which to unshift
|
|
9900
|
+
* @returns {GenericArray} Copy of the original array
|
|
9901
|
+
*/
|
|
9902
|
+
|
|
9903
|
+
|
|
9904
|
+
function unshift(item, arr) {
|
|
9905
|
+
arr = arr.slice();
|
|
9906
|
+
arr.unshift(item);
|
|
9907
|
+
return arr;
|
|
9908
|
+
}
|
|
9909
|
+
/**
|
|
9910
|
+
* Caught when JSONPath is used without `new` but rethrown if with `new`
|
|
9911
|
+
* @extends Error
|
|
9912
|
+
*/
|
|
9913
|
+
|
|
9914
|
+
|
|
9915
|
+
class NewError extends Error {
|
|
9916
|
+
/**
|
|
9917
|
+
* @param {AnyResult} value The evaluated scalar value
|
|
9918
|
+
*/
|
|
9919
|
+
constructor(value) {
|
|
9920
|
+
super('JSONPath should not be called with "new" (it prevents return ' + 'of (unwrapped) scalar values)');
|
|
9921
|
+
this.avoidNew = true;
|
|
9922
|
+
this.value = value;
|
|
9923
|
+
this.name = 'NewError';
|
|
9924
|
+
}
|
|
9925
|
+
|
|
9926
|
+
}
|
|
9927
|
+
/**
|
|
9928
|
+
* @typedef {PlainObject} ReturnObject
|
|
9929
|
+
* @property {string} path
|
|
9930
|
+
* @property {JSONObject} value
|
|
9931
|
+
* @property {PlainObject|GenericArray} parent
|
|
9932
|
+
* @property {string} parentProperty
|
|
9933
|
+
*/
|
|
9934
|
+
|
|
9935
|
+
/**
|
|
9936
|
+
* @callback JSONPathCallback
|
|
9937
|
+
* @param {string|PlainObject} preferredOutput
|
|
9938
|
+
* @param {"value"|"property"} type
|
|
9939
|
+
* @param {ReturnObject} fullRetObj
|
|
9940
|
+
* @returns {void}
|
|
9941
|
+
*/
|
|
9942
|
+
|
|
9943
|
+
/**
|
|
9944
|
+
* @callback OtherTypeCallback
|
|
9945
|
+
* @param {JSONObject} val
|
|
9946
|
+
* @param {string} path
|
|
9947
|
+
* @param {PlainObject|GenericArray} parent
|
|
9948
|
+
* @param {string} parentPropName
|
|
9949
|
+
* @returns {boolean}
|
|
9950
|
+
*/
|
|
9951
|
+
|
|
9952
|
+
/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
|
|
9953
|
+
|
|
9954
|
+
/**
|
|
9955
|
+
* @typedef {PlainObject} JSONPathOptions
|
|
9956
|
+
* @property {JSON} json
|
|
9957
|
+
* @property {string|string[]} path
|
|
9958
|
+
* @property {"value"|"path"|"pointer"|"parent"|"parentProperty"|"all"} [resultType="value"]
|
|
9959
|
+
* @property {boolean} [flatten=false]
|
|
9960
|
+
* @property {boolean} [wrap=true]
|
|
9961
|
+
* @property {PlainObject} [sandbox={}]
|
|
9962
|
+
* @property {boolean} [preventEval=false]
|
|
9963
|
+
* @property {PlainObject|GenericArray|null} [parent=null]
|
|
9964
|
+
* @property {string|null} [parentProperty=null]
|
|
9965
|
+
* @property {JSONPathCallback} [callback]
|
|
9966
|
+
* @property {OtherTypeCallback} [otherTypeCallback] Defaults to
|
|
9967
|
+
* function which throws on encountering `@other`
|
|
9968
|
+
* @property {boolean} [autostart=true]
|
|
9969
|
+
*/
|
|
9970
|
+
|
|
9971
|
+
/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
|
|
9972
|
+
|
|
9973
|
+
/**
|
|
9974
|
+
* @param {string|JSONPathOptions} opts If a string, will be treated as `expr`
|
|
9975
|
+
* @param {string} [expr] JSON path to evaluate
|
|
9976
|
+
* @param {JSON} [obj] JSON object to evaluate against
|
|
9977
|
+
* @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload
|
|
9978
|
+
* per `resultType`, 2) `"value"|"property"`, 3) Full returned object with
|
|
9979
|
+
* all payloads
|
|
9980
|
+
* @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end
|
|
9981
|
+
* of one's query, this will be invoked with the value of the item, its
|
|
9982
|
+
* path, its parent, and its parent's property name, and it should return
|
|
9983
|
+
* a boolean indicating whether the supplied value belongs to the "other"
|
|
9984
|
+
* type or not (or it may handle transformations and return `false`).
|
|
9985
|
+
* @returns {JSONPath}
|
|
9986
|
+
* @class
|
|
9987
|
+
*/
|
|
9988
|
+
|
|
9989
|
+
|
|
9990
|
+
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
9991
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
9992
|
+
if (!(this instanceof JSONPath)) {
|
|
9993
|
+
try {
|
|
9994
|
+
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
9995
|
+
} catch (e) {
|
|
9996
|
+
if (!e.avoidNew) {
|
|
9997
|
+
throw e;
|
|
9998
|
+
}
|
|
9999
|
+
|
|
10000
|
+
return e.value;
|
|
10001
|
+
}
|
|
10002
|
+
}
|
|
10003
|
+
|
|
10004
|
+
if (typeof opts === 'string') {
|
|
10005
|
+
otherTypeCallback = callback;
|
|
10006
|
+
callback = obj;
|
|
10007
|
+
obj = expr;
|
|
10008
|
+
expr = opts;
|
|
10009
|
+
opts = null;
|
|
10010
|
+
}
|
|
10011
|
+
|
|
10012
|
+
const optObj = opts && typeof opts === 'object';
|
|
10013
|
+
opts = opts || {};
|
|
10014
|
+
this.json = opts.json || obj;
|
|
10015
|
+
this.path = opts.path || expr;
|
|
10016
|
+
this.resultType = opts.resultType || 'value';
|
|
10017
|
+
this.flatten = opts.flatten || false;
|
|
10018
|
+
this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;
|
|
10019
|
+
this.sandbox = opts.sandbox || {};
|
|
10020
|
+
this.preventEval = opts.preventEval || false;
|
|
10021
|
+
this.parent = opts.parent || null;
|
|
10022
|
+
this.parentProperty = opts.parentProperty || null;
|
|
10023
|
+
this.callback = opts.callback || callback || null;
|
|
10024
|
+
|
|
10025
|
+
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function () {
|
|
10026
|
+
throw new TypeError('You must supply an otherTypeCallback callback option ' + 'with the @other() operator.');
|
|
10027
|
+
};
|
|
10028
|
+
|
|
10029
|
+
if (opts.autostart !== false) {
|
|
10030
|
+
const args = {
|
|
10031
|
+
path: optObj ? opts.path : expr
|
|
10032
|
+
};
|
|
10033
|
+
|
|
10034
|
+
if (!optObj) {
|
|
10035
|
+
args.json = obj;
|
|
10036
|
+
} else if ('json' in opts) {
|
|
10037
|
+
args.json = opts.json;
|
|
10038
|
+
}
|
|
10039
|
+
|
|
10040
|
+
const ret = this.evaluate(args);
|
|
10041
|
+
|
|
10042
|
+
if (!ret || typeof ret !== 'object') {
|
|
10043
|
+
throw new NewError(ret);
|
|
10044
|
+
}
|
|
10045
|
+
|
|
10046
|
+
return ret;
|
|
10047
|
+
}
|
|
10048
|
+
} // PUBLIC METHODS
|
|
10049
|
+
|
|
10050
|
+
|
|
10051
|
+
JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) {
|
|
10052
|
+
let currParent = this.parent,
|
|
10053
|
+
currParentProperty = this.parentProperty;
|
|
10054
|
+
let {
|
|
10055
|
+
flatten,
|
|
10056
|
+
wrap
|
|
10057
|
+
} = this;
|
|
10058
|
+
this.currResultType = this.resultType;
|
|
10059
|
+
this.currPreventEval = this.preventEval;
|
|
10060
|
+
this.currSandbox = this.sandbox;
|
|
10061
|
+
callback = callback || this.callback;
|
|
10062
|
+
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
10063
|
+
json = json || this.json;
|
|
10064
|
+
expr = expr || this.path;
|
|
10065
|
+
|
|
10066
|
+
if (expr && typeof expr === 'object' && !Array.isArray(expr)) {
|
|
10067
|
+
if (!expr.path && expr.path !== '') {
|
|
10068
|
+
throw new TypeError('You must supply a "path" property when providing an object ' + 'argument to JSONPath.evaluate().');
|
|
10069
|
+
}
|
|
10070
|
+
|
|
10071
|
+
if (!hasOwnProp.call(expr, 'json')) {
|
|
10072
|
+
throw new TypeError('You must supply a "json" property when providing an object ' + 'argument to JSONPath.evaluate().');
|
|
10073
|
+
}
|
|
10074
|
+
|
|
10075
|
+
({
|
|
10076
|
+
json
|
|
10077
|
+
} = expr);
|
|
10078
|
+
flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;
|
|
10079
|
+
this.currResultType = hasOwnProp.call(expr, 'resultType') ? expr.resultType : this.currResultType;
|
|
10080
|
+
this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox;
|
|
10081
|
+
wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;
|
|
10082
|
+
this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval;
|
|
10083
|
+
callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;
|
|
10084
|
+
this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
10085
|
+
currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;
|
|
10086
|
+
currParentProperty = hasOwnProp.call(expr, 'parentProperty') ? expr.parentProperty : currParentProperty;
|
|
10087
|
+
expr = expr.path;
|
|
10088
|
+
}
|
|
10089
|
+
|
|
10090
|
+
currParent = currParent || null;
|
|
10091
|
+
currParentProperty = currParentProperty || null;
|
|
10092
|
+
|
|
10093
|
+
if (Array.isArray(expr)) {
|
|
10094
|
+
expr = JSONPath.toPathString(expr);
|
|
10095
|
+
}
|
|
10096
|
+
|
|
10097
|
+
if (!expr && expr !== '' || !json) {
|
|
10098
|
+
return undefined;
|
|
10099
|
+
}
|
|
10100
|
+
|
|
10101
|
+
const exprList = JSONPath.toPathArray(expr);
|
|
10102
|
+
|
|
10103
|
+
if (exprList[0] === '$' && exprList.length > 1) {
|
|
10104
|
+
exprList.shift();
|
|
10105
|
+
}
|
|
10106
|
+
|
|
10107
|
+
this._hasParentSelector = null;
|
|
10108
|
+
|
|
10109
|
+
const result = this._trace(exprList, json, ['$'], currParent, currParentProperty, callback).filter(function (ea) {
|
|
10110
|
+
return ea && !ea.isParentSelector;
|
|
10111
|
+
});
|
|
10112
|
+
|
|
10113
|
+
if (!result.length) {
|
|
10114
|
+
return wrap ? [] : undefined;
|
|
10115
|
+
}
|
|
10116
|
+
|
|
10117
|
+
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
10118
|
+
return this._getPreferredOutput(result[0]);
|
|
10119
|
+
}
|
|
10120
|
+
|
|
10121
|
+
return result.reduce((rslt, ea) => {
|
|
10122
|
+
const valOrPath = this._getPreferredOutput(ea);
|
|
10123
|
+
|
|
10124
|
+
if (flatten && Array.isArray(valOrPath)) {
|
|
10125
|
+
rslt = rslt.concat(valOrPath);
|
|
10126
|
+
} else {
|
|
10127
|
+
rslt.push(valOrPath);
|
|
10128
|
+
}
|
|
10129
|
+
|
|
10130
|
+
return rslt;
|
|
10131
|
+
}, []);
|
|
10132
|
+
}; // PRIVATE METHODS
|
|
10133
|
+
|
|
10134
|
+
|
|
10135
|
+
JSONPath.prototype._getPreferredOutput = function (ea) {
|
|
10136
|
+
const resultType = this.currResultType;
|
|
10137
|
+
|
|
10138
|
+
switch (resultType) {
|
|
10139
|
+
case 'all':
|
|
10140
|
+
{
|
|
10141
|
+
const path = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
10142
|
+
ea.pointer = JSONPath.toPointer(path);
|
|
10143
|
+
ea.path = typeof ea.path === 'string' ? ea.path : JSONPath.toPathString(ea.path);
|
|
10144
|
+
return ea;
|
|
10145
|
+
}
|
|
10146
|
+
|
|
10147
|
+
case 'value':
|
|
10148
|
+
case 'parent':
|
|
10149
|
+
case 'parentProperty':
|
|
10150
|
+
return ea[resultType];
|
|
10151
|
+
|
|
10152
|
+
case 'path':
|
|
10153
|
+
return JSONPath.toPathString(ea[resultType]);
|
|
10154
|
+
|
|
10155
|
+
case 'pointer':
|
|
10156
|
+
return JSONPath.toPointer(ea.path);
|
|
10157
|
+
|
|
10158
|
+
default:
|
|
10159
|
+
throw new TypeError('Unknown result type');
|
|
10160
|
+
}
|
|
10161
|
+
};
|
|
10162
|
+
|
|
10163
|
+
JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
|
|
10164
|
+
if (callback) {
|
|
10165
|
+
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
10166
|
+
|
|
10167
|
+
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line n/callback-return
|
|
10168
|
+
|
|
10169
|
+
callback(preferredOutput, type, fullRetObj);
|
|
10170
|
+
}
|
|
10171
|
+
};
|
|
10172
|
+
/**
|
|
10173
|
+
*
|
|
10174
|
+
* @param {string} expr
|
|
10175
|
+
* @param {JSONObject} val
|
|
10176
|
+
* @param {string} path
|
|
10177
|
+
* @param {PlainObject|GenericArray} parent
|
|
10178
|
+
* @param {string} parentPropName
|
|
10179
|
+
* @param {JSONPathCallback} callback
|
|
10180
|
+
* @param {boolean} hasArrExpr
|
|
10181
|
+
* @param {boolean} literalPriority
|
|
10182
|
+
* @returns {ReturnObject|ReturnObject[]}
|
|
10183
|
+
*/
|
|
10184
|
+
|
|
10185
|
+
|
|
10186
|
+
JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
10187
|
+
// No expr to follow? return path and value as the result of
|
|
10188
|
+
// this trace branch
|
|
10189
|
+
let retObj;
|
|
10190
|
+
|
|
10191
|
+
if (!expr.length) {
|
|
10192
|
+
retObj = {
|
|
10193
|
+
path,
|
|
10194
|
+
value: val,
|
|
10195
|
+
parent,
|
|
10196
|
+
parentProperty: parentPropName,
|
|
10197
|
+
hasArrExpr
|
|
10198
|
+
};
|
|
10199
|
+
|
|
10200
|
+
this._handleCallback(retObj, callback, 'value');
|
|
10201
|
+
|
|
10202
|
+
return retObj;
|
|
10203
|
+
}
|
|
10204
|
+
|
|
10205
|
+
const loc = expr[0],
|
|
10206
|
+
x = expr.slice(1); // We need to gather the return value of recursive trace calls in order to
|
|
10207
|
+
// do the parent sel computation.
|
|
10208
|
+
|
|
10209
|
+
const ret = [];
|
|
10210
|
+
/**
|
|
10211
|
+
*
|
|
10212
|
+
* @param {ReturnObject|ReturnObject[]} elems
|
|
10213
|
+
* @returns {void}
|
|
10214
|
+
*/
|
|
10215
|
+
|
|
10216
|
+
function addRet(elems) {
|
|
10217
|
+
if (Array.isArray(elems)) {
|
|
10218
|
+
// This was causing excessive stack size in Node (with or
|
|
10219
|
+
// without Babel) against our performance test:
|
|
10220
|
+
// `ret.push(...elems);`
|
|
10221
|
+
elems.forEach(t => {
|
|
10222
|
+
ret.push(t);
|
|
10223
|
+
});
|
|
10224
|
+
} else {
|
|
10225
|
+
ret.push(elems);
|
|
10226
|
+
}
|
|
10227
|
+
}
|
|
10228
|
+
|
|
10229
|
+
if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc)) {
|
|
10230
|
+
// simple case--directly follow property
|
|
10231
|
+
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
|
|
10232
|
+
} else if (loc === '*') {
|
|
10233
|
+
// all child properties
|
|
10234
|
+
this._walk(val, m => {
|
|
10235
|
+
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true, true));
|
|
10236
|
+
});
|
|
10237
|
+
} else if (loc === '..') {
|
|
10238
|
+
// all descendent parent properties
|
|
10239
|
+
// Check remaining expression with val's immediate children
|
|
10240
|
+
addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr));
|
|
10241
|
+
|
|
10242
|
+
this._walk(val, m => {
|
|
10243
|
+
// We don't join m and x here because we only want parents,
|
|
10244
|
+
// not scalar values
|
|
10245
|
+
if (typeof val[m] === 'object') {
|
|
10246
|
+
// Keep going with recursive descent on val's
|
|
10247
|
+
// object children
|
|
10248
|
+
addRet(this._trace(expr.slice(), val[m], push(path, m), val, m, callback, true));
|
|
10249
|
+
}
|
|
10250
|
+
}); // The parent sel computation is handled in the frame above using the
|
|
10251
|
+
// ancestor object of val
|
|
10252
|
+
|
|
10253
|
+
} else if (loc === '^') {
|
|
10254
|
+
// This is not a final endpoint, so we do not invoke the callback here
|
|
10255
|
+
this._hasParentSelector = true;
|
|
10256
|
+
return {
|
|
10257
|
+
path: path.slice(0, -1),
|
|
10258
|
+
expr: x,
|
|
10259
|
+
isParentSelector: true
|
|
10260
|
+
};
|
|
10261
|
+
} else if (loc === '~') {
|
|
10262
|
+
// property name
|
|
10263
|
+
retObj = {
|
|
10264
|
+
path: push(path, loc),
|
|
10265
|
+
value: parentPropName,
|
|
10266
|
+
parent,
|
|
10267
|
+
parentProperty: null
|
|
10268
|
+
};
|
|
10269
|
+
|
|
10270
|
+
this._handleCallback(retObj, callback, 'property');
|
|
10271
|
+
|
|
10272
|
+
return retObj;
|
|
10273
|
+
} else if (loc === '$') {
|
|
10274
|
+
// root only
|
|
10275
|
+
addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));
|
|
10276
|
+
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
10277
|
+
// [start:end:step] Python slice syntax
|
|
10278
|
+
addRet(this._slice(loc, x, val, path, parent, parentPropName, callback));
|
|
10279
|
+
} else if (loc.indexOf('?(') === 0) {
|
|
10280
|
+
// [?(expr)] (filtering)
|
|
10281
|
+
if (this.currPreventEval) {
|
|
10282
|
+
throw new Error('Eval [?(expr)] prevented in JSONPath expression.');
|
|
10283
|
+
}
|
|
10284
|
+
|
|
10285
|
+
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, '$1');
|
|
10286
|
+
|
|
10287
|
+
this._walk(val, m => {
|
|
10288
|
+
if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
|
|
10289
|
+
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true));
|
|
10290
|
+
}
|
|
10291
|
+
});
|
|
10292
|
+
} else if (loc[0] === '(') {
|
|
10293
|
+
// [(expr)] (dynamic property/index)
|
|
10294
|
+
if (this.currPreventEval) {
|
|
10295
|
+
throw new Error('Eval [(expr)] prevented in JSONPath expression.');
|
|
10296
|
+
} // As this will resolve to a property name (but we don't know it
|
|
10297
|
+
// yet), property and parent information is relative to the
|
|
10298
|
+
// parent of the property to which this expression will resolve
|
|
10299
|
+
|
|
10300
|
+
|
|
10301
|
+
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));
|
|
10302
|
+
} else if (loc[0] === '@') {
|
|
10303
|
+
// value type: @boolean(), etc.
|
|
10304
|
+
let addType = false;
|
|
10305
|
+
const valueType = loc.slice(1, -2);
|
|
10306
|
+
|
|
10307
|
+
switch (valueType) {
|
|
10308
|
+
case 'scalar':
|
|
10309
|
+
if (!val || !['object', 'function'].includes(typeof val)) {
|
|
10310
|
+
addType = true;
|
|
10311
|
+
}
|
|
10312
|
+
|
|
10313
|
+
break;
|
|
10314
|
+
|
|
10315
|
+
case 'boolean':
|
|
10316
|
+
case 'string':
|
|
10317
|
+
case 'undefined':
|
|
10318
|
+
case 'function':
|
|
10319
|
+
// eslint-disable-next-line valid-typeof
|
|
10320
|
+
if (typeof val === valueType) {
|
|
10321
|
+
addType = true;
|
|
10322
|
+
}
|
|
10323
|
+
|
|
10324
|
+
break;
|
|
10325
|
+
|
|
10326
|
+
case 'integer':
|
|
10327
|
+
if (Number.isFinite(val) && !(val % 1)) {
|
|
10328
|
+
addType = true;
|
|
10329
|
+
}
|
|
10330
|
+
|
|
10331
|
+
break;
|
|
10332
|
+
|
|
10333
|
+
case 'number':
|
|
10334
|
+
if (Number.isFinite(val)) {
|
|
10335
|
+
addType = true;
|
|
10336
|
+
}
|
|
10337
|
+
|
|
10338
|
+
break;
|
|
10339
|
+
|
|
10340
|
+
case 'nonFinite':
|
|
10341
|
+
if (typeof val === 'number' && !Number.isFinite(val)) {
|
|
10342
|
+
addType = true;
|
|
10343
|
+
}
|
|
10344
|
+
|
|
10345
|
+
break;
|
|
10346
|
+
|
|
10347
|
+
case 'object':
|
|
10348
|
+
// eslint-disable-next-line valid-typeof
|
|
10349
|
+
if (val && typeof val === valueType) {
|
|
10350
|
+
addType = true;
|
|
10351
|
+
}
|
|
10352
|
+
|
|
10353
|
+
break;
|
|
10354
|
+
|
|
10355
|
+
case 'array':
|
|
10356
|
+
if (Array.isArray(val)) {
|
|
10357
|
+
addType = true;
|
|
10358
|
+
}
|
|
10359
|
+
|
|
10360
|
+
break;
|
|
10361
|
+
|
|
10362
|
+
case 'other':
|
|
10363
|
+
addType = this.currOtherTypeCallback(val, path, parent, parentPropName);
|
|
10364
|
+
break;
|
|
10365
|
+
|
|
10366
|
+
case 'null':
|
|
10367
|
+
if (val === null) {
|
|
10368
|
+
addType = true;
|
|
10369
|
+
}
|
|
10370
|
+
|
|
10371
|
+
break;
|
|
10372
|
+
|
|
10373
|
+
/* c8 ignore next 2 */
|
|
10374
|
+
|
|
10375
|
+
default:
|
|
10376
|
+
throw new TypeError('Unknown value type ' + valueType);
|
|
10377
|
+
}
|
|
10378
|
+
|
|
10379
|
+
if (addType) {
|
|
10380
|
+
retObj = {
|
|
10381
|
+
path,
|
|
10382
|
+
value: val,
|
|
10383
|
+
parent,
|
|
10384
|
+
parentProperty: parentPropName
|
|
10385
|
+
};
|
|
10386
|
+
|
|
10387
|
+
this._handleCallback(retObj, callback, 'value');
|
|
10388
|
+
|
|
10389
|
+
return retObj;
|
|
10390
|
+
} // `-escaped property
|
|
10391
|
+
|
|
10392
|
+
} else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {
|
|
10393
|
+
const locProp = loc.slice(1);
|
|
10394
|
+
addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, hasArrExpr, true));
|
|
10395
|
+
} else if (loc.includes(',')) {
|
|
10396
|
+
// [name1,name2,...]
|
|
10397
|
+
const parts = loc.split(',');
|
|
10398
|
+
|
|
10399
|
+
for (const part of parts) {
|
|
10400
|
+
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
|
|
10401
|
+
} // simple case--directly follow property
|
|
10402
|
+
|
|
10403
|
+
} else if (!literalPriority && val && hasOwnProp.call(val, loc)) {
|
|
10404
|
+
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true));
|
|
10405
|
+
} // We check the resulting values for parent selections. For parent
|
|
10406
|
+
// selections we discard the value object and continue the trace with the
|
|
10407
|
+
// current val object
|
|
10408
|
+
|
|
10409
|
+
|
|
10410
|
+
if (this._hasParentSelector) {
|
|
10411
|
+
for (let t = 0; t < ret.length; t++) {
|
|
10412
|
+
const rett = ret[t];
|
|
10413
|
+
|
|
10414
|
+
if (rett && rett.isParentSelector) {
|
|
10415
|
+
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
10416
|
+
|
|
10417
|
+
if (Array.isArray(tmp)) {
|
|
10418
|
+
ret[t] = tmp[0];
|
|
10419
|
+
const tl = tmp.length;
|
|
10420
|
+
|
|
10421
|
+
for (let tt = 1; tt < tl; tt++) {
|
|
10422
|
+
t++;
|
|
10423
|
+
ret.splice(t, 0, tmp[tt]);
|
|
10424
|
+
}
|
|
10425
|
+
} else {
|
|
10426
|
+
ret[t] = tmp;
|
|
10427
|
+
}
|
|
10428
|
+
}
|
|
10429
|
+
}
|
|
10430
|
+
}
|
|
10431
|
+
|
|
10432
|
+
return ret;
|
|
10433
|
+
};
|
|
10434
|
+
|
|
10435
|
+
JSONPath.prototype._walk = function (val, f) {
|
|
10436
|
+
if (Array.isArray(val)) {
|
|
10437
|
+
const n = val.length;
|
|
10438
|
+
|
|
10439
|
+
for (let i = 0; i < n; i++) {
|
|
10440
|
+
f(i);
|
|
10441
|
+
}
|
|
10442
|
+
} else if (val && typeof val === 'object') {
|
|
10443
|
+
Object.keys(val).forEach(m => {
|
|
10444
|
+
f(m);
|
|
10445
|
+
});
|
|
10446
|
+
}
|
|
10447
|
+
};
|
|
10448
|
+
|
|
10449
|
+
JSONPath.prototype._slice = function (loc, expr, val, path, parent, parentPropName, callback) {
|
|
10450
|
+
if (!Array.isArray(val)) {
|
|
10451
|
+
return undefined;
|
|
10452
|
+
}
|
|
10453
|
+
|
|
10454
|
+
const len = val.length,
|
|
10455
|
+
parts = loc.split(':'),
|
|
10456
|
+
step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
10457
|
+
let start = parts[0] && Number.parseInt(parts[0]) || 0,
|
|
10458
|
+
end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
10459
|
+
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
10460
|
+
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
10461
|
+
const ret = [];
|
|
10462
|
+
|
|
10463
|
+
for (let i = start; i < end; i += step) {
|
|
10464
|
+
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
|
|
10465
|
+
// ``unshift(i, expr)` passed in above would not be empty, nor `~`,
|
|
10466
|
+
// nor begin with `@` (as could return objects)
|
|
10467
|
+
// This was causing excessive stack size in Node (with or
|
|
10468
|
+
// without Babel) against our performance test: `ret.push(...tmp);`
|
|
10469
|
+
|
|
10470
|
+
|
|
10471
|
+
tmp.forEach(t => {
|
|
10472
|
+
ret.push(t);
|
|
10473
|
+
});
|
|
10474
|
+
}
|
|
10475
|
+
|
|
10476
|
+
return ret;
|
|
10477
|
+
};
|
|
10478
|
+
|
|
10479
|
+
JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropName) {
|
|
10480
|
+
this.currSandbox._$_parentProperty = parentPropName;
|
|
10481
|
+
this.currSandbox._$_parent = parent;
|
|
10482
|
+
this.currSandbox._$_property = _vname;
|
|
10483
|
+
this.currSandbox._$_root = this.json;
|
|
10484
|
+
this.currSandbox._$_v = _v;
|
|
10485
|
+
const containsPath = code.includes('@path');
|
|
10486
|
+
|
|
10487
|
+
if (containsPath) {
|
|
10488
|
+
this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));
|
|
10489
|
+
}
|
|
10490
|
+
|
|
10491
|
+
const scriptCacheKey = 'script:' + code;
|
|
10492
|
+
|
|
10493
|
+
if (!JSONPath.cache[scriptCacheKey]) {
|
|
10494
|
+
let script = code.replace(/@parentProperty/gu, '_$_parentProperty').replace(/@parent/gu, '_$_parent').replace(/@property/gu, '_$_property').replace(/@root/gu, '_$_root').replace(/@([.\s)[])/gu, '_$_v$1');
|
|
10495
|
+
|
|
10496
|
+
if (containsPath) {
|
|
10497
|
+
script = script.replace(/@path/gu, '_$_path');
|
|
10498
|
+
}
|
|
10499
|
+
|
|
10500
|
+
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
10501
|
+
}
|
|
10502
|
+
|
|
10503
|
+
try {
|
|
10504
|
+
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
10505
|
+
} catch (e) {
|
|
10506
|
+
throw new Error('jsonPath: ' + e.message + ': ' + code);
|
|
10507
|
+
}
|
|
10508
|
+
}; // PUBLIC CLASS PROPERTIES AND METHODS
|
|
10509
|
+
// Could store the cache object itself
|
|
10510
|
+
|
|
10511
|
+
|
|
10512
|
+
JSONPath.cache = {};
|
|
10513
|
+
/**
|
|
10514
|
+
* @param {string[]} pathArr Array to convert
|
|
10515
|
+
* @returns {string} The path string
|
|
10516
|
+
*/
|
|
10517
|
+
|
|
10518
|
+
JSONPath.toPathString = function (pathArr) {
|
|
10519
|
+
const x = pathArr,
|
|
10520
|
+
n = x.length;
|
|
10521
|
+
let p = '$';
|
|
10522
|
+
|
|
10523
|
+
for (let i = 1; i < n; i++) {
|
|
10524
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
10525
|
+
p += /^[0-9*]+$/u.test(x[i]) ? '[' + x[i] + ']' : "['" + x[i] + "']";
|
|
10526
|
+
}
|
|
10527
|
+
}
|
|
10528
|
+
|
|
10529
|
+
return p;
|
|
10530
|
+
};
|
|
10531
|
+
/**
|
|
10532
|
+
* @param {string} pointer JSON Path
|
|
10533
|
+
* @returns {string} JSON Pointer
|
|
10534
|
+
*/
|
|
10535
|
+
|
|
10536
|
+
|
|
10537
|
+
JSONPath.toPointer = function (pointer) {
|
|
10538
|
+
const x = pointer,
|
|
10539
|
+
n = x.length;
|
|
10540
|
+
let p = '';
|
|
10541
|
+
|
|
10542
|
+
for (let i = 1; i < n; i++) {
|
|
10543
|
+
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
10544
|
+
p += '/' + x[i].toString().replace(/~/gu, '~0').replace(/\//gu, '~1');
|
|
10545
|
+
}
|
|
10546
|
+
}
|
|
10547
|
+
|
|
10548
|
+
return p;
|
|
10549
|
+
};
|
|
10550
|
+
/**
|
|
10551
|
+
* @param {string} expr Expression to convert
|
|
10552
|
+
* @returns {string[]}
|
|
10553
|
+
*/
|
|
10554
|
+
|
|
10555
|
+
|
|
10556
|
+
JSONPath.toPathArray = function (expr) {
|
|
10557
|
+
const {
|
|
10558
|
+
cache
|
|
10559
|
+
} = JSONPath;
|
|
10560
|
+
|
|
10561
|
+
if (cache[expr]) {
|
|
10562
|
+
return cache[expr].concat();
|
|
10563
|
+
}
|
|
10564
|
+
|
|
10565
|
+
const subx = [];
|
|
10566
|
+
const normalized = expr // Properties
|
|
10567
|
+
.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ';$&;') // Parenthetical evaluations (filtering and otherwise), directly
|
|
10568
|
+
// within brackets or single quotes
|
|
10569
|
+
.replace(/[['](\??\(.*?\))[\]']/gu, function ($0, $1) {
|
|
10570
|
+
return '[#' + (subx.push($1) - 1) + ']';
|
|
10571
|
+
}) // Escape periods and tildes within properties
|
|
10572
|
+
.replace(/\[['"]([^'\]]*)['"]\]/gu, function ($0, prop) {
|
|
10573
|
+
return "['" + prop.replace(/\./gu, '%@%').replace(/~/gu, '%%@@%%') + "']";
|
|
10574
|
+
}) // Properties operator
|
|
10575
|
+
.replace(/~/gu, ';~;') // Split by property boundaries
|
|
10576
|
+
.replace(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ';') // Reinsert periods within properties
|
|
10577
|
+
.replace(/%@%/gu, '.') // Reinsert tildes within properties
|
|
10578
|
+
.replace(/%%@@%%/gu, '~') // Parent
|
|
10579
|
+
.replace(/(?:;)?(\^+)(?:;)?/gu, function ($0, ups) {
|
|
10580
|
+
return ';' + ups.split('').join(';') + ';';
|
|
10581
|
+
}) // Descendents
|
|
10582
|
+
.replace(/;;;|;;/gu, ';..;') // Remove trailing
|
|
10583
|
+
.replace(/;$|'?\]|'$/gu, '');
|
|
10584
|
+
const exprList = normalized.split(';').map(function (exp) {
|
|
10585
|
+
const match = exp.match(/#(\d+)/u);
|
|
10586
|
+
return !match || !match[1] ? exp : subx[match[1]];
|
|
10587
|
+
});
|
|
10588
|
+
cache[expr] = exprList;
|
|
10589
|
+
return cache[expr].concat();
|
|
10590
|
+
};
|
|
10591
|
+
|
|
10592
|
+
JSONPath.prototype.vm = vm;
|
|
10593
|
+
|
|
10594
|
+
/*!
|
|
10595
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
10596
|
+
* (c) 2017-2022 Joachim Wester
|
|
10597
|
+
* MIT licensed
|
|
10598
|
+
*/
|
|
10599
|
+
var __extends = (undefined && undefined.__extends) || (function () {
|
|
10600
|
+
var extendStatics = function (d, b) {
|
|
10601
|
+
extendStatics = Object.setPrototypeOf ||
|
|
10602
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10603
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
10604
|
+
return extendStatics(d, b);
|
|
10605
|
+
};
|
|
10606
|
+
return function (d, b) {
|
|
10607
|
+
extendStatics(d, b);
|
|
10608
|
+
function __() { this.constructor = d; }
|
|
10609
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
10610
|
+
};
|
|
10611
|
+
})();
|
|
10612
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
10613
|
+
function hasOwnProperty$b(obj, key) {
|
|
10614
|
+
return _hasOwnProperty.call(obj, key);
|
|
10615
|
+
}
|
|
10616
|
+
function _objectKeys(obj) {
|
|
10617
|
+
if (Array.isArray(obj)) {
|
|
10618
|
+
var keys_1 = new Array(obj.length);
|
|
10619
|
+
for (var k = 0; k < keys_1.length; k++) {
|
|
10620
|
+
keys_1[k] = "" + k;
|
|
10621
|
+
}
|
|
10622
|
+
return keys_1;
|
|
10623
|
+
}
|
|
10624
|
+
if (Object.keys) {
|
|
10625
|
+
return Object.keys(obj);
|
|
10626
|
+
}
|
|
10627
|
+
var keys = [];
|
|
10628
|
+
for (var i in obj) {
|
|
10629
|
+
if (hasOwnProperty$b(obj, i)) {
|
|
10630
|
+
keys.push(i);
|
|
10631
|
+
}
|
|
10632
|
+
}
|
|
10633
|
+
return keys;
|
|
10634
|
+
}
|
|
10635
|
+
/**
|
|
10636
|
+
* Deeply clone the object.
|
|
10637
|
+
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
|
10638
|
+
* @param {any} obj value to clone
|
|
10639
|
+
* @return {any} cloned obj
|
|
10640
|
+
*/
|
|
10641
|
+
function _deepClone(obj) {
|
|
10642
|
+
switch (typeof obj) {
|
|
10643
|
+
case "object":
|
|
10644
|
+
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
10645
|
+
case "undefined":
|
|
10646
|
+
return null; //this is how JSON.stringify behaves for array items
|
|
10647
|
+
default:
|
|
10648
|
+
return obj; //no need to clone primitives
|
|
10649
|
+
}
|
|
10650
|
+
}
|
|
10651
|
+
//3x faster than cached /^\d+$/.test(str)
|
|
10652
|
+
function isInteger(str) {
|
|
10653
|
+
var i = 0;
|
|
10654
|
+
var len = str.length;
|
|
10655
|
+
var charCode;
|
|
10656
|
+
while (i < len) {
|
|
10657
|
+
charCode = str.charCodeAt(i);
|
|
10658
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
10659
|
+
i++;
|
|
10660
|
+
continue;
|
|
10661
|
+
}
|
|
10662
|
+
return false;
|
|
10663
|
+
}
|
|
10664
|
+
return true;
|
|
10665
|
+
}
|
|
10666
|
+
/**
|
|
10667
|
+
* Escapes a json pointer path
|
|
10668
|
+
* @param path The raw pointer
|
|
10669
|
+
* @return the Escaped path
|
|
10670
|
+
*/
|
|
10671
|
+
function escapePathComponent(path) {
|
|
10672
|
+
if (path.indexOf('/') === -1 && path.indexOf('~') === -1)
|
|
10673
|
+
return path;
|
|
10674
|
+
return path.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
10675
|
+
}
|
|
10676
|
+
/**
|
|
10677
|
+
* Unescapes a json pointer path
|
|
10678
|
+
* @param path The escaped pointer
|
|
10679
|
+
* @return The unescaped path
|
|
10680
|
+
*/
|
|
10681
|
+
function unescapePathComponent(path) {
|
|
10682
|
+
return path.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
10683
|
+
}
|
|
10684
|
+
/**
|
|
10685
|
+
* Recursively checks whether an object has any undefined values inside.
|
|
10686
|
+
*/
|
|
10687
|
+
function hasUndefined(obj) {
|
|
10688
|
+
if (obj === undefined) {
|
|
10689
|
+
return true;
|
|
10690
|
+
}
|
|
10691
|
+
if (obj) {
|
|
10692
|
+
if (Array.isArray(obj)) {
|
|
10693
|
+
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
|
10694
|
+
if (hasUndefined(obj[i_1])) {
|
|
10695
|
+
return true;
|
|
10696
|
+
}
|
|
10697
|
+
}
|
|
10698
|
+
}
|
|
10699
|
+
else if (typeof obj === "object") {
|
|
10700
|
+
var objKeys = _objectKeys(obj);
|
|
10701
|
+
var objKeysLength = objKeys.length;
|
|
10702
|
+
for (var i = 0; i < objKeysLength; i++) {
|
|
10703
|
+
if (hasUndefined(obj[objKeys[i]])) {
|
|
10704
|
+
return true;
|
|
10705
|
+
}
|
|
10706
|
+
}
|
|
10707
|
+
}
|
|
10708
|
+
}
|
|
10709
|
+
return false;
|
|
10710
|
+
}
|
|
10711
|
+
function patchErrorMessageFormatter(message, args) {
|
|
10712
|
+
var messageParts = [message];
|
|
10713
|
+
for (var key in args) {
|
|
10714
|
+
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
|
|
10715
|
+
if (typeof value !== 'undefined') {
|
|
10716
|
+
messageParts.push(key + ": " + value);
|
|
10717
|
+
}
|
|
10718
|
+
}
|
|
10719
|
+
return messageParts.join('\n');
|
|
10720
|
+
}
|
|
10721
|
+
var PatchError = /** @class */ (function (_super) {
|
|
10722
|
+
__extends(PatchError, _super);
|
|
10723
|
+
function PatchError(message, name, index, operation, tree) {
|
|
10724
|
+
var _newTarget = this.constructor;
|
|
10725
|
+
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
|
|
10726
|
+
_this.name = name;
|
|
10727
|
+
_this.index = index;
|
|
10728
|
+
_this.operation = operation;
|
|
10729
|
+
_this.tree = tree;
|
|
10730
|
+
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
|
10731
|
+
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
|
|
10732
|
+
return _this;
|
|
10733
|
+
}
|
|
10734
|
+
return PatchError;
|
|
10735
|
+
}(Error));
|
|
10736
|
+
|
|
10737
|
+
var JsonPatchError = PatchError;
|
|
10738
|
+
var deepClone = _deepClone;
|
|
10739
|
+
/* We use a Javascript hash to store each
|
|
10740
|
+
function. Each hash entry (property) uses
|
|
10741
|
+
the operation identifiers specified in rfc6902.
|
|
10742
|
+
In this way, we can map each patch operation
|
|
10743
|
+
to its dedicated function in efficient way.
|
|
10744
|
+
*/
|
|
10745
|
+
/* The operations applicable to an object */
|
|
10746
|
+
var objOps = {
|
|
10747
|
+
add: function (obj, key, document) {
|
|
10748
|
+
obj[key] = this.value;
|
|
10749
|
+
return { newDocument: document };
|
|
10750
|
+
},
|
|
10751
|
+
remove: function (obj, key, document) {
|
|
10752
|
+
var removed = obj[key];
|
|
10753
|
+
delete obj[key];
|
|
10754
|
+
return { newDocument: document, removed: removed };
|
|
10755
|
+
},
|
|
10756
|
+
replace: function (obj, key, document) {
|
|
10757
|
+
var removed = obj[key];
|
|
10758
|
+
obj[key] = this.value;
|
|
10759
|
+
return { newDocument: document, removed: removed };
|
|
10760
|
+
},
|
|
10761
|
+
move: function (obj, key, document) {
|
|
10762
|
+
/* in case move target overwrites an existing value,
|
|
10763
|
+
return the removed value, this can be taxing performance-wise,
|
|
10764
|
+
and is potentially unneeded */
|
|
10765
|
+
var removed = getValueByPointer(document, this.path);
|
|
10766
|
+
if (removed) {
|
|
10767
|
+
removed = _deepClone(removed);
|
|
10768
|
+
}
|
|
10769
|
+
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
|
10770
|
+
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
|
10771
|
+
return { newDocument: document, removed: removed };
|
|
10772
|
+
},
|
|
10773
|
+
copy: function (obj, key, document) {
|
|
10774
|
+
var valueToCopy = getValueByPointer(document, this.from);
|
|
10775
|
+
// enforce copy by value so further operations don't affect source (see issue #177)
|
|
10776
|
+
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
|
|
10777
|
+
return { newDocument: document };
|
|
10778
|
+
},
|
|
10779
|
+
test: function (obj, key, document) {
|
|
10780
|
+
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
|
10781
|
+
},
|
|
10782
|
+
_get: function (obj, key, document) {
|
|
10783
|
+
this.value = obj[key];
|
|
10784
|
+
return { newDocument: document };
|
|
10785
|
+
}
|
|
10786
|
+
};
|
|
10787
|
+
/* The operations applicable to an array. Many are the same as for the object */
|
|
10788
|
+
var arrOps = {
|
|
10789
|
+
add: function (arr, i, document) {
|
|
10790
|
+
if (isInteger(i)) {
|
|
10791
|
+
arr.splice(i, 0, this.value);
|
|
10792
|
+
}
|
|
10793
|
+
else { // array props
|
|
10794
|
+
arr[i] = this.value;
|
|
10795
|
+
}
|
|
10796
|
+
// this may be needed when using '-' in an array
|
|
10797
|
+
return { newDocument: document, index: i };
|
|
10798
|
+
},
|
|
10799
|
+
remove: function (arr, i, document) {
|
|
10800
|
+
var removedList = arr.splice(i, 1);
|
|
10801
|
+
return { newDocument: document, removed: removedList[0] };
|
|
10802
|
+
},
|
|
10803
|
+
replace: function (arr, i, document) {
|
|
10804
|
+
var removed = arr[i];
|
|
10805
|
+
arr[i] = this.value;
|
|
10806
|
+
return { newDocument: document, removed: removed };
|
|
10807
|
+
},
|
|
10808
|
+
move: objOps.move,
|
|
10809
|
+
copy: objOps.copy,
|
|
10810
|
+
test: objOps.test,
|
|
10811
|
+
_get: objOps._get
|
|
10812
|
+
};
|
|
10813
|
+
/**
|
|
10814
|
+
* Retrieves a value from a JSON document by a JSON pointer.
|
|
10815
|
+
* Returns the value.
|
|
10816
|
+
*
|
|
10817
|
+
* @param document The document to get the value from
|
|
10818
|
+
* @param pointer an escaped JSON pointer
|
|
10819
|
+
* @return The retrieved value
|
|
10820
|
+
*/
|
|
10821
|
+
function getValueByPointer(document, pointer) {
|
|
10822
|
+
if (pointer == '') {
|
|
10823
|
+
return document;
|
|
10824
|
+
}
|
|
10825
|
+
var getOriginalDestination = { op: "_get", path: pointer };
|
|
10826
|
+
applyOperation(document, getOriginalDestination);
|
|
10827
|
+
return getOriginalDestination.value;
|
|
10828
|
+
}
|
|
10829
|
+
/**
|
|
10830
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
|
10831
|
+
* Returns the {newDocument, result} of the operation.
|
|
10832
|
+
* It modifies the `document` and `operation` objects - it gets the values by reference.
|
|
10833
|
+
* If you would like to avoid touching your values, clone them:
|
|
10834
|
+
* `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.
|
|
10835
|
+
*
|
|
10836
|
+
* @param document The document to patch
|
|
10837
|
+
* @param operation The operation to apply
|
|
10838
|
+
* @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.
|
|
10839
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
|
10840
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
|
10841
|
+
* @return `{newDocument, result}` after the operation
|
|
10842
|
+
*/
|
|
10843
|
+
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
|
10844
|
+
if (validateOperation === void 0) { validateOperation = false; }
|
|
10845
|
+
if (mutateDocument === void 0) { mutateDocument = true; }
|
|
10846
|
+
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
|
10847
|
+
if (index === void 0) { index = 0; }
|
|
10848
|
+
if (validateOperation) {
|
|
10849
|
+
if (typeof validateOperation == 'function') {
|
|
10850
|
+
validateOperation(operation, 0, document, operation.path);
|
|
10851
|
+
}
|
|
10852
|
+
else {
|
|
10853
|
+
validator$1(operation, 0);
|
|
10854
|
+
}
|
|
10855
|
+
}
|
|
10856
|
+
/* ROOT OPERATIONS */
|
|
10857
|
+
if (operation.path === "") {
|
|
10858
|
+
var returnValue = { newDocument: document };
|
|
10859
|
+
if (operation.op === 'add') {
|
|
10860
|
+
returnValue.newDocument = operation.value;
|
|
10861
|
+
return returnValue;
|
|
10862
|
+
}
|
|
10863
|
+
else if (operation.op === 'replace') {
|
|
10864
|
+
returnValue.newDocument = operation.value;
|
|
10865
|
+
returnValue.removed = document; //document we removed
|
|
10866
|
+
return returnValue;
|
|
10867
|
+
}
|
|
10868
|
+
else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root
|
|
10869
|
+
returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field
|
|
10870
|
+
if (operation.op === 'move') { // report removed item
|
|
10871
|
+
returnValue.removed = document;
|
|
10872
|
+
}
|
|
10873
|
+
return returnValue;
|
|
10874
|
+
}
|
|
10875
|
+
else if (operation.op === 'test') {
|
|
10876
|
+
returnValue.test = _areEquals(document, operation.value);
|
|
10877
|
+
if (returnValue.test === false) {
|
|
10878
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
10879
|
+
}
|
|
10880
|
+
returnValue.newDocument = document;
|
|
10881
|
+
return returnValue;
|
|
10882
|
+
}
|
|
10883
|
+
else if (operation.op === 'remove') { // a remove on root
|
|
10884
|
+
returnValue.removed = document;
|
|
10885
|
+
returnValue.newDocument = null;
|
|
10886
|
+
return returnValue;
|
|
10887
|
+
}
|
|
10888
|
+
else if (operation.op === '_get') {
|
|
10889
|
+
operation.value = document;
|
|
10890
|
+
return returnValue;
|
|
10891
|
+
}
|
|
10892
|
+
else { /* bad operation */
|
|
10893
|
+
if (validateOperation) {
|
|
10894
|
+
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
|
10895
|
+
}
|
|
10896
|
+
else {
|
|
10897
|
+
return returnValue;
|
|
10898
|
+
}
|
|
10899
|
+
}
|
|
10900
|
+
} /* END ROOT OPERATIONS */
|
|
10901
|
+
else {
|
|
10902
|
+
if (!mutateDocument) {
|
|
10903
|
+
document = _deepClone(document);
|
|
10904
|
+
}
|
|
10905
|
+
var path = operation.path || "";
|
|
10906
|
+
var keys = path.split('/');
|
|
10907
|
+
var obj = document;
|
|
10908
|
+
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
|
|
10909
|
+
var len = keys.length;
|
|
10910
|
+
var existingPathFragment = undefined;
|
|
10911
|
+
var key = void 0;
|
|
10912
|
+
var validateFunction = void 0;
|
|
10913
|
+
if (typeof validateOperation == 'function') {
|
|
10914
|
+
validateFunction = validateOperation;
|
|
10915
|
+
}
|
|
10916
|
+
else {
|
|
10917
|
+
validateFunction = validator$1;
|
|
10918
|
+
}
|
|
10919
|
+
while (true) {
|
|
10920
|
+
key = keys[t];
|
|
10921
|
+
if (key && key.indexOf('~') != -1) {
|
|
10922
|
+
key = unescapePathComponent(key);
|
|
10923
|
+
}
|
|
10924
|
+
if (banPrototypeModifications &&
|
|
10925
|
+
(key == '__proto__' ||
|
|
10926
|
+
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
|
|
10927
|
+
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');
|
|
10928
|
+
}
|
|
10929
|
+
if (validateOperation) {
|
|
10930
|
+
if (existingPathFragment === undefined) {
|
|
10931
|
+
if (obj[key] === undefined) {
|
|
10932
|
+
existingPathFragment = keys.slice(0, t).join('/');
|
|
10933
|
+
}
|
|
10934
|
+
else if (t == len - 1) {
|
|
10935
|
+
existingPathFragment = operation.path;
|
|
10936
|
+
}
|
|
10937
|
+
if (existingPathFragment !== undefined) {
|
|
10938
|
+
validateFunction(operation, 0, document, existingPathFragment);
|
|
10939
|
+
}
|
|
10940
|
+
}
|
|
10941
|
+
}
|
|
10942
|
+
t++;
|
|
10943
|
+
if (Array.isArray(obj)) {
|
|
10944
|
+
if (key === '-') {
|
|
10945
|
+
key = obj.length;
|
|
10946
|
+
}
|
|
10947
|
+
else {
|
|
10948
|
+
if (validateOperation && !isInteger(key)) {
|
|
10949
|
+
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);
|
|
10950
|
+
} // only parse key when it's an integer for `arr.prop` to work
|
|
10951
|
+
else if (isInteger(key)) {
|
|
10952
|
+
key = ~~key;
|
|
10953
|
+
}
|
|
10954
|
+
}
|
|
10955
|
+
if (t >= len) {
|
|
10956
|
+
if (validateOperation && operation.op === "add" && key > obj.length) {
|
|
10957
|
+
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);
|
|
10958
|
+
}
|
|
10959
|
+
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
|
|
10960
|
+
if (returnValue.test === false) {
|
|
10961
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
10962
|
+
}
|
|
10963
|
+
return returnValue;
|
|
10964
|
+
}
|
|
10965
|
+
}
|
|
10966
|
+
else {
|
|
10967
|
+
if (t >= len) {
|
|
10968
|
+
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
|
|
10969
|
+
if (returnValue.test === false) {
|
|
10970
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
10971
|
+
}
|
|
10972
|
+
return returnValue;
|
|
10973
|
+
}
|
|
10974
|
+
}
|
|
10975
|
+
obj = obj[key];
|
|
10976
|
+
// If we have more keys in the path, but the next value isn't a non-null object,
|
|
10977
|
+
// throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.
|
|
10978
|
+
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
|
10979
|
+
throw new JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
|
10980
|
+
}
|
|
10981
|
+
}
|
|
10982
|
+
}
|
|
10983
|
+
}
|
|
10984
|
+
/**
|
|
10985
|
+
* Apply a full JSON Patch array on a JSON document.
|
|
10986
|
+
* Returns the {newDocument, result} of the patch.
|
|
10987
|
+
* It modifies the `document` object and `patch` - it gets the values by reference.
|
|
10988
|
+
* If you would like to avoid touching your values, clone them:
|
|
10989
|
+
* `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.
|
|
10990
|
+
*
|
|
10991
|
+
* @param document The document to patch
|
|
10992
|
+
* @param patch The patch to apply
|
|
10993
|
+
* @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.
|
|
10994
|
+
* @param mutateDocument Whether to mutate the original document or clone it before applying
|
|
10995
|
+
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
|
|
10996
|
+
* @return An array of `{newDocument, result}` after the patch
|
|
10997
|
+
*/
|
|
10998
|
+
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
|
10999
|
+
if (mutateDocument === void 0) { mutateDocument = true; }
|
|
11000
|
+
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
|
|
11001
|
+
if (validateOperation) {
|
|
11002
|
+
if (!Array.isArray(patch)) {
|
|
11003
|
+
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
|
11004
|
+
}
|
|
11005
|
+
}
|
|
11006
|
+
if (!mutateDocument) {
|
|
11007
|
+
document = _deepClone(document);
|
|
11008
|
+
}
|
|
11009
|
+
var results = new Array(patch.length);
|
|
11010
|
+
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
|
11011
|
+
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
|
|
11012
|
+
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
|
11013
|
+
document = results[i].newDocument; // in case root was replaced
|
|
11014
|
+
}
|
|
11015
|
+
results.newDocument = document;
|
|
11016
|
+
return results;
|
|
11017
|
+
}
|
|
11018
|
+
/**
|
|
11019
|
+
* Apply a single JSON Patch Operation on a JSON document.
|
|
11020
|
+
* Returns the updated document.
|
|
11021
|
+
* Suitable as a reducer.
|
|
11022
|
+
*
|
|
11023
|
+
* @param document The document to patch
|
|
11024
|
+
* @param operation The operation to apply
|
|
11025
|
+
* @return The updated document
|
|
11026
|
+
*/
|
|
11027
|
+
function applyReducer(document, operation, index) {
|
|
11028
|
+
var operationResult = applyOperation(document, operation);
|
|
11029
|
+
if (operationResult.test === false) { // failed test
|
|
11030
|
+
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
|
|
11031
|
+
}
|
|
11032
|
+
return operationResult.newDocument;
|
|
11033
|
+
}
|
|
11034
|
+
/**
|
|
11035
|
+
* Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.
|
|
11036
|
+
* @param {object} operation - operation object (patch)
|
|
11037
|
+
* @param {number} index - index of operation in the sequence
|
|
11038
|
+
* @param {object} [document] - object where the operation is supposed to be applied
|
|
11039
|
+
* @param {string} [existingPathFragment] - comes along with `document`
|
|
11040
|
+
*/
|
|
11041
|
+
function validator$1(operation, index, document, existingPathFragment) {
|
|
11042
|
+
if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {
|
|
11043
|
+
throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);
|
|
11044
|
+
}
|
|
11045
|
+
else if (!objOps[operation.op]) {
|
|
11046
|
+
throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);
|
|
11047
|
+
}
|
|
11048
|
+
else if (typeof operation.path !== 'string') {
|
|
11049
|
+
throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);
|
|
11050
|
+
}
|
|
11051
|
+
else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {
|
|
11052
|
+
// paths that aren't empty string should start with "/"
|
|
11053
|
+
throw new JsonPatchError('Operation `path` property must start with "/"', 'OPERATION_PATH_INVALID', index, operation, document);
|
|
11054
|
+
}
|
|
11055
|
+
else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {
|
|
11056
|
+
throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);
|
|
11057
|
+
}
|
|
11058
|
+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {
|
|
11059
|
+
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);
|
|
11060
|
+
}
|
|
11061
|
+
else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && hasUndefined(operation.value)) {
|
|
11062
|
+
throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);
|
|
11063
|
+
}
|
|
11064
|
+
else if (document) {
|
|
11065
|
+
if (operation.op == "add") {
|
|
11066
|
+
var pathLen = operation.path.split("/").length;
|
|
11067
|
+
var existingPathLen = existingPathFragment.split("/").length;
|
|
11068
|
+
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
|
11069
|
+
throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);
|
|
11070
|
+
}
|
|
11071
|
+
}
|
|
11072
|
+
else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {
|
|
11073
|
+
if (operation.path !== existingPathFragment) {
|
|
11074
|
+
throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);
|
|
11075
|
+
}
|
|
11076
|
+
}
|
|
11077
|
+
else if (operation.op === 'move' || operation.op === 'copy') {
|
|
11078
|
+
var existingValue = { op: "_get", path: operation.from, value: undefined };
|
|
11079
|
+
var error = validate([existingValue], document);
|
|
11080
|
+
if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {
|
|
11081
|
+
throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);
|
|
11082
|
+
}
|
|
11083
|
+
}
|
|
11084
|
+
}
|
|
11085
|
+
}
|
|
11086
|
+
/**
|
|
11087
|
+
* Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.
|
|
11088
|
+
* If error is encountered, returns a JsonPatchError object
|
|
11089
|
+
* @param sequence
|
|
11090
|
+
* @param document
|
|
11091
|
+
* @returns {JsonPatchError|undefined}
|
|
11092
|
+
*/
|
|
11093
|
+
function validate(sequence, document, externalValidator) {
|
|
11094
|
+
try {
|
|
11095
|
+
if (!Array.isArray(sequence)) {
|
|
11096
|
+
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
|
|
11097
|
+
}
|
|
11098
|
+
if (document) {
|
|
11099
|
+
//clone document and sequence so that we can safely try applying operations
|
|
11100
|
+
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
|
|
11101
|
+
}
|
|
11102
|
+
else {
|
|
11103
|
+
externalValidator = externalValidator || validator$1;
|
|
11104
|
+
for (var i = 0; i < sequence.length; i++) {
|
|
11105
|
+
externalValidator(sequence[i], i, document, undefined);
|
|
11106
|
+
}
|
|
11107
|
+
}
|
|
11108
|
+
}
|
|
11109
|
+
catch (e) {
|
|
11110
|
+
if (e instanceof JsonPatchError) {
|
|
11111
|
+
return e;
|
|
11112
|
+
}
|
|
11113
|
+
else {
|
|
11114
|
+
throw e;
|
|
11115
|
+
}
|
|
11116
|
+
}
|
|
11117
|
+
}
|
|
11118
|
+
// based on https://github.com/epoberezkin/fast-deep-equal
|
|
11119
|
+
// MIT License
|
|
11120
|
+
// Copyright (c) 2017 Evgeny Poberezkin
|
|
11121
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11122
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
11123
|
+
// in the Software without restriction, including without limitation the rights
|
|
11124
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11125
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11126
|
+
// furnished to do so, subject to the following conditions:
|
|
11127
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
11128
|
+
// copies or substantial portions of the Software.
|
|
11129
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
11130
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
11131
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
11132
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
11133
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
11134
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
11135
|
+
// SOFTWARE.
|
|
11136
|
+
function _areEquals(a, b) {
|
|
11137
|
+
if (a === b)
|
|
11138
|
+
return true;
|
|
11139
|
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
11140
|
+
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
|
11141
|
+
if (arrA && arrB) {
|
|
11142
|
+
length = a.length;
|
|
11143
|
+
if (length != b.length)
|
|
11144
|
+
return false;
|
|
11145
|
+
for (i = length; i-- !== 0;)
|
|
11146
|
+
if (!_areEquals(a[i], b[i]))
|
|
11147
|
+
return false;
|
|
11148
|
+
return true;
|
|
11149
|
+
}
|
|
11150
|
+
if (arrA != arrB)
|
|
11151
|
+
return false;
|
|
11152
|
+
var keys = Object.keys(a);
|
|
11153
|
+
length = keys.length;
|
|
11154
|
+
if (length !== Object.keys(b).length)
|
|
11155
|
+
return false;
|
|
11156
|
+
for (i = length; i-- !== 0;)
|
|
11157
|
+
if (!b.hasOwnProperty(keys[i]))
|
|
11158
|
+
return false;
|
|
11159
|
+
for (i = length; i-- !== 0;) {
|
|
11160
|
+
key = keys[i];
|
|
11161
|
+
if (!_areEquals(a[key], b[key]))
|
|
11162
|
+
return false;
|
|
11163
|
+
}
|
|
11164
|
+
return true;
|
|
11165
|
+
}
|
|
11166
|
+
return a !== a && b !== b;
|
|
11167
|
+
}
|
|
11168
|
+
|
|
11169
|
+
var core = /*#__PURE__*/Object.freeze({
|
|
11170
|
+
__proto__: null,
|
|
11171
|
+
JsonPatchError: JsonPatchError,
|
|
11172
|
+
_areEquals: _areEquals,
|
|
11173
|
+
applyOperation: applyOperation,
|
|
11174
|
+
applyPatch: applyPatch,
|
|
11175
|
+
applyReducer: applyReducer,
|
|
11176
|
+
deepClone: deepClone,
|
|
11177
|
+
getValueByPointer: getValueByPointer,
|
|
11178
|
+
validate: validate,
|
|
11179
|
+
validator: validator$1
|
|
11180
|
+
});
|
|
11181
|
+
|
|
11182
|
+
/*!
|
|
11183
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
11184
|
+
* (c) 2017-2021 Joachim Wester
|
|
11185
|
+
* MIT license
|
|
11186
|
+
*/
|
|
11187
|
+
var beforeDict = new WeakMap();
|
|
11188
|
+
var Mirror = /** @class */ (function () {
|
|
11189
|
+
function Mirror(obj) {
|
|
11190
|
+
this.observers = new Map();
|
|
11191
|
+
this.obj = obj;
|
|
11192
|
+
}
|
|
11193
|
+
return Mirror;
|
|
11194
|
+
}());
|
|
11195
|
+
var ObserverInfo = /** @class */ (function () {
|
|
11196
|
+
function ObserverInfo(callback, observer) {
|
|
11197
|
+
this.callback = callback;
|
|
11198
|
+
this.observer = observer;
|
|
11199
|
+
}
|
|
11200
|
+
return ObserverInfo;
|
|
11201
|
+
}());
|
|
11202
|
+
function getMirror(obj) {
|
|
11203
|
+
return beforeDict.get(obj);
|
|
11204
|
+
}
|
|
11205
|
+
function getObserverFromMirror(mirror, callback) {
|
|
11206
|
+
return mirror.observers.get(callback);
|
|
11207
|
+
}
|
|
11208
|
+
function removeObserverFromMirror(mirror, observer) {
|
|
11209
|
+
mirror.observers.delete(observer.callback);
|
|
11210
|
+
}
|
|
11211
|
+
/**
|
|
11212
|
+
* Detach an observer from an object
|
|
11213
|
+
*/
|
|
11214
|
+
function unobserve(root, observer) {
|
|
11215
|
+
observer.unobserve();
|
|
11216
|
+
}
|
|
11217
|
+
/**
|
|
11218
|
+
* Observes changes made to an object, which can then be retrieved using generate
|
|
11219
|
+
*/
|
|
11220
|
+
function observe(obj, callback) {
|
|
11221
|
+
var patches = [];
|
|
11222
|
+
var observer;
|
|
11223
|
+
var mirror = getMirror(obj);
|
|
11224
|
+
if (!mirror) {
|
|
11225
|
+
mirror = new Mirror(obj);
|
|
11226
|
+
beforeDict.set(obj, mirror);
|
|
11227
|
+
}
|
|
11228
|
+
else {
|
|
11229
|
+
var observerInfo = getObserverFromMirror(mirror, callback);
|
|
11230
|
+
observer = observerInfo && observerInfo.observer;
|
|
11231
|
+
}
|
|
11232
|
+
if (observer) {
|
|
11233
|
+
return observer;
|
|
11234
|
+
}
|
|
11235
|
+
observer = {};
|
|
11236
|
+
mirror.value = _deepClone(obj);
|
|
11237
|
+
if (callback) {
|
|
11238
|
+
observer.callback = callback;
|
|
11239
|
+
observer.next = null;
|
|
11240
|
+
var dirtyCheck = function () {
|
|
11241
|
+
generate(observer);
|
|
11242
|
+
};
|
|
11243
|
+
var fastCheck = function () {
|
|
11244
|
+
clearTimeout(observer.next);
|
|
11245
|
+
observer.next = setTimeout(dirtyCheck);
|
|
11246
|
+
};
|
|
11247
|
+
if (typeof window !== 'undefined') { //not Node
|
|
11248
|
+
window.addEventListener('mouseup', fastCheck);
|
|
11249
|
+
window.addEventListener('keyup', fastCheck);
|
|
11250
|
+
window.addEventListener('mousedown', fastCheck);
|
|
11251
|
+
window.addEventListener('keydown', fastCheck);
|
|
11252
|
+
window.addEventListener('change', fastCheck);
|
|
11253
|
+
}
|
|
11254
|
+
}
|
|
11255
|
+
observer.patches = patches;
|
|
11256
|
+
observer.object = obj;
|
|
11257
|
+
observer.unobserve = function () {
|
|
11258
|
+
generate(observer);
|
|
11259
|
+
clearTimeout(observer.next);
|
|
11260
|
+
removeObserverFromMirror(mirror, observer);
|
|
11261
|
+
if (typeof window !== 'undefined') {
|
|
11262
|
+
window.removeEventListener('mouseup', fastCheck);
|
|
11263
|
+
window.removeEventListener('keyup', fastCheck);
|
|
11264
|
+
window.removeEventListener('mousedown', fastCheck);
|
|
11265
|
+
window.removeEventListener('keydown', fastCheck);
|
|
11266
|
+
window.removeEventListener('change', fastCheck);
|
|
11267
|
+
}
|
|
11268
|
+
};
|
|
11269
|
+
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
|
11270
|
+
return observer;
|
|
11271
|
+
}
|
|
11272
|
+
/**
|
|
11273
|
+
* Generate an array of patches from an observer
|
|
11274
|
+
*/
|
|
11275
|
+
function generate(observer, invertible) {
|
|
11276
|
+
if (invertible === void 0) { invertible = false; }
|
|
11277
|
+
var mirror = beforeDict.get(observer.object);
|
|
11278
|
+
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
|
11279
|
+
if (observer.patches.length) {
|
|
11280
|
+
applyPatch(mirror.value, observer.patches);
|
|
11281
|
+
}
|
|
11282
|
+
var temp = observer.patches;
|
|
11283
|
+
if (temp.length > 0) {
|
|
11284
|
+
observer.patches = [];
|
|
11285
|
+
if (observer.callback) {
|
|
11286
|
+
observer.callback(temp);
|
|
11287
|
+
}
|
|
11288
|
+
}
|
|
11289
|
+
return temp;
|
|
11290
|
+
}
|
|
11291
|
+
// Dirty check if obj is different from mirror, generate patches and update mirror
|
|
11292
|
+
function _generate(mirror, obj, patches, path, invertible) {
|
|
11293
|
+
if (obj === mirror) {
|
|
11294
|
+
return;
|
|
11295
|
+
}
|
|
11296
|
+
if (typeof obj.toJSON === "function") {
|
|
11297
|
+
obj = obj.toJSON();
|
|
11298
|
+
}
|
|
11299
|
+
var newKeys = _objectKeys(obj);
|
|
11300
|
+
var oldKeys = _objectKeys(mirror);
|
|
11301
|
+
var deleted = false;
|
|
11302
|
+
//if ever "move" operation is implemented here, make sure this test runs OK: "should not generate the same patch twice (move)"
|
|
11303
|
+
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
|
11304
|
+
var key = oldKeys[t];
|
|
11305
|
+
var oldVal = mirror[key];
|
|
11306
|
+
if (hasOwnProperty$b(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {
|
|
11307
|
+
var newVal = obj[key];
|
|
11308
|
+
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
|
11309
|
+
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
|
|
11310
|
+
}
|
|
11311
|
+
else {
|
|
11312
|
+
if (oldVal !== newVal) {
|
|
11313
|
+
if (invertible) {
|
|
11314
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
11315
|
+
}
|
|
11316
|
+
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
|
|
11317
|
+
}
|
|
11318
|
+
}
|
|
11319
|
+
}
|
|
11320
|
+
else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
|
11321
|
+
if (invertible) {
|
|
11322
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
11323
|
+
}
|
|
11324
|
+
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
|
|
11325
|
+
deleted = true; // property has been deleted
|
|
11326
|
+
}
|
|
11327
|
+
else {
|
|
11328
|
+
if (invertible) {
|
|
11329
|
+
patches.push({ op: "test", path: path, value: mirror });
|
|
11330
|
+
}
|
|
11331
|
+
patches.push({ op: "replace", path: path, value: obj });
|
|
11332
|
+
}
|
|
11333
|
+
}
|
|
11334
|
+
if (!deleted && newKeys.length == oldKeys.length) {
|
|
11335
|
+
return;
|
|
11336
|
+
}
|
|
11337
|
+
for (var t = 0; t < newKeys.length; t++) {
|
|
11338
|
+
var key = newKeys[t];
|
|
11339
|
+
if (!hasOwnProperty$b(mirror, key) && obj[key] !== undefined) {
|
|
11340
|
+
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
|
|
11341
|
+
}
|
|
11342
|
+
}
|
|
11343
|
+
}
|
|
11344
|
+
/**
|
|
11345
|
+
* Create an array of patches from the differences in two objects
|
|
11346
|
+
*/
|
|
11347
|
+
function compare(tree1, tree2, invertible) {
|
|
11348
|
+
if (invertible === void 0) { invertible = false; }
|
|
11349
|
+
var patches = [];
|
|
11350
|
+
_generate(tree1, tree2, patches, '', invertible);
|
|
11351
|
+
return patches;
|
|
11352
|
+
}
|
|
11353
|
+
|
|
11354
|
+
var duplex = /*#__PURE__*/Object.freeze({
|
|
11355
|
+
__proto__: null,
|
|
11356
|
+
compare: compare,
|
|
11357
|
+
generate: generate,
|
|
11358
|
+
observe: observe,
|
|
11359
|
+
unobserve: unobserve
|
|
11360
|
+
});
|
|
11361
|
+
|
|
11362
|
+
Object.assign({}, core, duplex, {
|
|
11363
|
+
JsonPatchError: PatchError,
|
|
11364
|
+
deepClone: _deepClone,
|
|
11365
|
+
escapePathComponent,
|
|
11366
|
+
unescapePathComponent
|
|
11367
|
+
});
|
|
11368
|
+
|
|
9867
11369
|
toast.configure({
|
|
9868
11370
|
autoClose: 3000,
|
|
9869
11371
|
hideProgressBar: true,
|
|
@@ -10261,7 +11763,83 @@ var getUrlWithSearchParams = function (url, params) {
|
|
|
10261
11763
|
/**
|
|
10262
11764
|
* Custom exception logger function for logging errors to sentry
|
|
10263
11765
|
*/
|
|
10264
|
-
var logExceptionToSentry = captureException.bind(window);
|
|
11766
|
+
var logExceptionToSentry = captureException.bind(window);
|
|
11767
|
+
var customStyles = {
|
|
11768
|
+
control: function (base, state) { return (__assign(__assign({}, base), { minHeight: '32px', boxShadow: 'none', border: 'none', cursor: 'pointer', background: 'transparent' })); },
|
|
11769
|
+
indicatorSeparator: function (base, state) { return (__assign(__assign({}, base), { width: 0 })); },
|
|
11770
|
+
valueContainer: function (base, state) { return (__assign(__assign({}, base), { padding: '0', fontSize: '13px', fontWeight: '600' })); },
|
|
11771
|
+
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)' })); },
|
|
11772
|
+
};
|
|
11773
|
+
var getFilteredChartVersions = function (charts, selectedChartType) {
|
|
11774
|
+
// Filter chart versions based on selected chart type
|
|
11775
|
+
return charts
|
|
11776
|
+
.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.chartType) === selectedChartType.value; })
|
|
11777
|
+
.map(function (item) { return ({
|
|
11778
|
+
value: item === null || item === void 0 ? void 0 : item.chartVersion,
|
|
11779
|
+
label: item === null || item === void 0 ? void 0 : item.chartVersion,
|
|
11780
|
+
chartRefId: item.chartRefId,
|
|
11781
|
+
}); });
|
|
11782
|
+
};
|
|
11783
|
+
function removeEmptyObjectKeysAndNullValues(obj) {
|
|
11784
|
+
// It recursively removes empty object keys and array values that are null
|
|
11785
|
+
for (var key in obj) {
|
|
11786
|
+
if (Array.isArray(obj[key])) {
|
|
11787
|
+
if (obj[key].length === 0)
|
|
11788
|
+
continue;
|
|
11789
|
+
obj[key] = obj[key].filter(function (item) { return item !== null; });
|
|
11790
|
+
// Check if the array is empty
|
|
11791
|
+
if (obj[key].length === 0) {
|
|
11792
|
+
delete obj[key]; // Delete the key if the array is empty
|
|
11793
|
+
}
|
|
11794
|
+
}
|
|
11795
|
+
else if (obj[key] && typeof obj[key] === 'object') {
|
|
11796
|
+
if (removeEmptyObjectKeysAndNullValues(obj[key])) {
|
|
11797
|
+
delete obj[key];
|
|
11798
|
+
}
|
|
11799
|
+
}
|
|
11800
|
+
else if (obj[key] === undefined) {
|
|
11801
|
+
delete obj[key];
|
|
11802
|
+
}
|
|
11803
|
+
}
|
|
11804
|
+
return Object.keys(obj).length === 0;
|
|
11805
|
+
}
|
|
11806
|
+
function getUnlockedJSON(json, jsonPathArray) {
|
|
11807
|
+
var jsonCopy = JSON.parse(JSON.stringify(json));
|
|
11808
|
+
var patches = jsonPathArray.flatMap(function (jsonPath) {
|
|
11809
|
+
var pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' });
|
|
11810
|
+
return pathsToRemove.map(function (result) {
|
|
11811
|
+
return Array.isArray(result.parent)
|
|
11812
|
+
? { op: 'replace', path: result.pointer, value: null }
|
|
11813
|
+
: { op: 'remove', path: result.pointer };
|
|
11814
|
+
});
|
|
11815
|
+
});
|
|
11816
|
+
var newDocument = applyPatch(jsonCopy, patches).newDocument;
|
|
11817
|
+
removeEmptyObjectKeysAndNullValues(newDocument);
|
|
11818
|
+
return newDocument;
|
|
11819
|
+
}
|
|
11820
|
+
function getLockedJSON(json, jsonPathArray) {
|
|
11821
|
+
var jsonCopy = JSON.parse(JSON.stringify(json));
|
|
11822
|
+
var resultJson = {};
|
|
11823
|
+
jsonPathArray.forEach(function (jsonPath) {
|
|
11824
|
+
var elements = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' });
|
|
11825
|
+
elements.forEach(function (element) {
|
|
11826
|
+
var _a;
|
|
11827
|
+
var pathArray = JSONPath.toPathArray(element.path);
|
|
11828
|
+
var lastPath = pathArray.pop();
|
|
11829
|
+
var current = resultJson;
|
|
11830
|
+
for (var i = 0; i < pathArray.length; i++) {
|
|
11831
|
+
var key_1 = isNaN(Number(pathArray[i])) ? pathArray[i] : parseInt(pathArray[i]);
|
|
11832
|
+
if (!current[key_1]) {
|
|
11833
|
+
current[key_1] = isNaN(Number((_a = pathArray[i + 1]) !== null && _a !== void 0 ? _a : lastPath)) ? {} : [];
|
|
11834
|
+
}
|
|
11835
|
+
current = current[key_1];
|
|
11836
|
+
}
|
|
11837
|
+
var key = isNaN(Number(lastPath)) ? lastPath : parseInt(lastPath);
|
|
11838
|
+
current[key] = element.value;
|
|
11839
|
+
});
|
|
11840
|
+
});
|
|
11841
|
+
return resultJson['$'];
|
|
11842
|
+
}
|
|
10265
11843
|
|
|
10266
11844
|
function Progressing(_a) {
|
|
10267
11845
|
var pageLoader = _a.pageLoader, size = _a.size, theme = _a.theme, styles = _a.styles, fillColor = _a.fillColor;
|
|
@@ -10274,7 +11852,7 @@ function DetailsProgressing(_a) {
|
|
|
10274
11852
|
}
|
|
10275
11853
|
|
|
10276
11854
|
var VisibleModal = /** @class */ (function (_super) {
|
|
10277
|
-
__extends(VisibleModal, _super);
|
|
11855
|
+
__extends$1(VisibleModal, _super);
|
|
10278
11856
|
function VisibleModal(props) {
|
|
10279
11857
|
var _this = _super.call(this, props) || this;
|
|
10280
11858
|
_this.modalRef = document.getElementById('visible-modal');
|
|
@@ -10405,7 +11983,7 @@ var SvgIcCross = function SvgIcCross(props) {
|
|
|
10405
11983
|
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";
|
|
10406
11984
|
|
|
10407
11985
|
var OpaqueModal = /** @class */ (function (_super) {
|
|
10408
|
-
__extends(OpaqueModal, _super);
|
|
11986
|
+
__extends$1(OpaqueModal, _super);
|
|
10409
11987
|
function OpaqueModal() {
|
|
10410
11988
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
10411
11989
|
_this.modalRef = document.getElementById('full-screen-modal');
|
|
@@ -10429,7 +12007,7 @@ var OpaqueModal = /** @class */ (function (_super) {
|
|
|
10429
12007
|
}(React.Component));
|
|
10430
12008
|
|
|
10431
12009
|
var VisibleModal2 = /** @class */ (function (_super) {
|
|
10432
|
-
__extends(VisibleModal2, _super);
|
|
12010
|
+
__extends$1(VisibleModal2, _super);
|
|
10433
12011
|
function VisibleModal2(props) {
|
|
10434
12012
|
var _this = _super.call(this, props) || this;
|
|
10435
12013
|
_this.modalRef = document.getElementById('visible-modal-2');
|
|
@@ -10540,7 +12118,7 @@ var BreadCrumb = function (_a) {
|
|
|
10540
12118
|
|
|
10541
12119
|
var RadioGroupContext = React.createContext({ name: '', value: '', disabled: false, onChange: function (event) { } });
|
|
10542
12120
|
var RadioGroupItem = /** @class */ (function (_super) {
|
|
10543
|
-
__extends(RadioGroupItem, _super);
|
|
12121
|
+
__extends$1(RadioGroupItem, _super);
|
|
10544
12122
|
function RadioGroupItem() {
|
|
10545
12123
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
10546
12124
|
}
|
|
@@ -10553,7 +12131,7 @@ var RadioGroupItem = /** @class */ (function (_super) {
|
|
|
10553
12131
|
return RadioGroupItem;
|
|
10554
12132
|
}(React.Component));
|
|
10555
12133
|
var RadioGroup$1 = /** @class */ (function (_super) {
|
|
10556
|
-
__extends(RadioGroup, _super);
|
|
12134
|
+
__extends$1(RadioGroup, _super);
|
|
10557
12135
|
function RadioGroup() {
|
|
10558
12136
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
10559
12137
|
}
|
|
@@ -15134,7 +16712,7 @@ DeleteDialog.Description = DeleteDialogDescription;
|
|
|
15134
16712
|
//TODO: may not need context
|
|
15135
16713
|
var DialogFormContext = React.createContext({ title: '', isLoading: false, close: function (event) { }, onSave: function (event) { } });
|
|
15136
16714
|
var DialogForm = /** @class */ (function (_super) {
|
|
15137
|
-
__extends(DialogForm, _super);
|
|
16715
|
+
__extends$1(DialogForm, _super);
|
|
15138
16716
|
function DialogForm(props) {
|
|
15139
16717
|
var _this = _super.call(this, props) || this;
|
|
15140
16718
|
_this.escFunction = _this.escFunction.bind(_this);
|
|
@@ -15170,7 +16748,7 @@ var DialogForm = /** @class */ (function (_super) {
|
|
|
15170
16748
|
return DialogForm;
|
|
15171
16749
|
}(React.Component));
|
|
15172
16750
|
var DialogFormSubmit = /** @class */ (function (_super) {
|
|
15173
|
-
__extends(DialogFormSubmit, _super);
|
|
16751
|
+
__extends$1(DialogFormSubmit, _super);
|
|
15174
16752
|
function DialogFormSubmit() {
|
|
15175
16753
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
15176
16754
|
}
|
|
@@ -22937,6 +24515,9 @@ function createGitCommitUrl(url, revision) {
|
|
|
22937
24515
|
}
|
|
22938
24516
|
}
|
|
22939
24517
|
return "NA";
|
|
24518
|
+
}
|
|
24519
|
+
function fetchChartTemplateVersions() {
|
|
24520
|
+
return get("".concat(ROUTES.DEPLOYMENT_TEMPLATE_LIST, "?appId=-1&envId=-1"));
|
|
22940
24521
|
}
|
|
22941
24522
|
|
|
22942
24523
|
/*
|
|
@@ -22949,7 +24530,7 @@ Valid States of Checkbox:
|
|
|
22949
24530
|
6. disabled: false, checked: true, value: CHECKED
|
|
22950
24531
|
*/
|
|
22951
24532
|
var Checkbox$1 = /** @class */ (function (_super) {
|
|
22952
|
-
__extends(Checkbox, _super);
|
|
24533
|
+
__extends$1(Checkbox, _super);
|
|
22953
24534
|
function Checkbox() {
|
|
22954
24535
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
22955
24536
|
}
|
|
@@ -26651,6 +28232,53 @@ function DevtronProgressing(_a) {
|
|
|
26651
28232
|
return (jsxRuntime.jsx("div", __assign({ className: parentClasses ? parentClasses : '' }, { children: jsxRuntime.jsx(SvgIcRotateDevtron, { className: classes ? classes : '' }) })));
|
|
26652
28233
|
}
|
|
26653
28234
|
|
|
28235
|
+
// @TODO: Generalize this component to be used in CodeEditor as Chart selector toolbar
|
|
28236
|
+
// when the Code Editor is moved to the fe-common-lib
|
|
28237
|
+
var ChartVersionAndTypeSelector = function (_a) {
|
|
28238
|
+
var setSelectedChartRefId = _a.setSelectedChartRefId;
|
|
28239
|
+
var _b = __read(React.useState([]), 2), charts = _b[0], setCharts = _b[1];
|
|
28240
|
+
var _c = __read(React.useState(null), 2), selectedChartType = _c[0], setSelectedChartType = _c[1];
|
|
28241
|
+
var _d = __read(React.useState([]), 2), chartVersionOptions = _d[0], setChartVersionOptions = _d[1];
|
|
28242
|
+
var _e = __read(React.useState([]), 2), chartTypeOptions = _e[0], setChartTypeOptions = _e[1];
|
|
28243
|
+
var _f = __read(React.useState(null), 2), selectedChartVersion = _f[0], setSelectedChartVersion = _f[1];
|
|
28244
|
+
React.useEffect(function () {
|
|
28245
|
+
fetchChartTemplateVersions()
|
|
28246
|
+
.then(function (res) {
|
|
28247
|
+
var charts = (res === null || res === void 0 ? void 0 : res.result) || [];
|
|
28248
|
+
setCharts(charts);
|
|
28249
|
+
// Extract unique chart types from the data
|
|
28250
|
+
var chartTypeOptions = __spreadArray([], __read(new Set(charts.map(function (item) { return item.chartType; }))), false).map(function (type) { return ({
|
|
28251
|
+
value: type,
|
|
28252
|
+
label: type,
|
|
28253
|
+
}); });
|
|
28254
|
+
setChartTypeOptions(chartTypeOptions);
|
|
28255
|
+
var filteredVersions = getFilteredChartVersions(charts, chartTypeOptions[0]);
|
|
28256
|
+
selectFirstChartVersion(filteredVersions);
|
|
28257
|
+
})
|
|
28258
|
+
.catch(function (err) {
|
|
28259
|
+
showError(err);
|
|
28260
|
+
});
|
|
28261
|
+
}, []);
|
|
28262
|
+
var selectFirstChartVersion = function (filteredVersions) {
|
|
28263
|
+
var _a;
|
|
28264
|
+
setChartVersionOptions(filteredVersions);
|
|
28265
|
+
setSelectedChartVersion(filteredVersions[0]); // Select the first chart version by default
|
|
28266
|
+
setSelectedChartRefId((_a = filteredVersions[0]) === null || _a === void 0 ? void 0 : _a.chartRefId);
|
|
28267
|
+
};
|
|
28268
|
+
// Function to update chart version options based on selected chart type
|
|
28269
|
+
var handleChartTypeChange = function (selectedOption) {
|
|
28270
|
+
setSelectedChartType(selectedOption);
|
|
28271
|
+
var filteredVersions = getFilteredChartVersions(charts, selectedOption);
|
|
28272
|
+
selectFirstChartVersion(filteredVersions);
|
|
28273
|
+
};
|
|
28274
|
+
// Function to handle the change of the selected chart version
|
|
28275
|
+
var handleChartVersionChange = function (selectedOption) {
|
|
28276
|
+
setSelectedChartVersion(selectedOption);
|
|
28277
|
+
setSelectedChartRefId(selectedOption.chartRefId);
|
|
28278
|
+
};
|
|
28279
|
+
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 })] }))] })));
|
|
28280
|
+
};
|
|
28281
|
+
|
|
26654
28282
|
function TooltipContent(_a) {
|
|
26655
28283
|
var tooltipContent = _a.tooltipContent;
|
|
26656
28284
|
if (tooltipContent) {
|
|
@@ -26755,6 +28383,7 @@ exports.BreadCrumb = BreadCrumb;
|
|
|
26755
28383
|
exports.BreadcrumbStore = Store;
|
|
26756
28384
|
exports.BuildStageVariable = BuildStageVariable;
|
|
26757
28385
|
exports.CDModalTab = CDModalTab;
|
|
28386
|
+
exports.ChartVersionAndTypeSelector = ChartVersionAndTypeSelector;
|
|
26758
28387
|
exports.Checkbox = Checkbox$1;
|
|
26759
28388
|
exports.ClearIndicator = ClearIndicator;
|
|
26760
28389
|
exports.ClipboardButton = ClipboardButton;
|
|
@@ -26827,17 +28456,22 @@ exports.VisibleModal2 = VisibleModal2;
|
|
|
26827
28456
|
exports.closeOnEscKeyPressed = closeOnEscKeyPressed;
|
|
26828
28457
|
exports.copyToClipboard = copyToClipboard;
|
|
26829
28458
|
exports.createGitCommitUrl = createGitCommitUrl;
|
|
28459
|
+
exports.customStyles = customStyles;
|
|
26830
28460
|
exports.extractImage = extractImage;
|
|
28461
|
+
exports.fetchChartTemplateVersions = fetchChartTemplateVersions;
|
|
26831
28462
|
exports.genericCDMaterialsService = genericCDMaterialsService;
|
|
26832
28463
|
exports.get = get;
|
|
26833
28464
|
exports.getAlphabetIcon = getAlphabetIcon;
|
|
26834
28465
|
exports.getCookie = getCookie;
|
|
26835
28466
|
exports.getEmptyArrayOfLength = getEmptyArrayOfLength;
|
|
28467
|
+
exports.getFilteredChartVersions = getFilteredChartVersions;
|
|
26836
28468
|
exports.getInferredTypeFromValueType = getInferredTypeFromValueType;
|
|
28469
|
+
exports.getLockedJSON = getLockedJSON;
|
|
26837
28470
|
exports.getLoginInfo = getLoginInfo;
|
|
26838
28471
|
exports.getRandomColor = getRandomColor;
|
|
26839
28472
|
exports.getRedirectionProps = getRedirectionProps;
|
|
26840
28473
|
exports.getTeamListMin = getTeamListMin;
|
|
28474
|
+
exports.getUnlockedJSON = getUnlockedJSON;
|
|
26841
28475
|
exports.getUrlWithSearchParams = getUrlWithSearchParams;
|
|
26842
28476
|
exports.getUserRole = getUserRole;
|
|
26843
28477
|
exports.handleAddCD = handleAddCD;
|