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