@perses-dev/core 0.2.1 → 0.4.0
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/cjs/index.js +30 -0
- package/dist/cjs/model/dashboard.js +14 -0
- package/dist/cjs/model/datasource.js +14 -0
- package/dist/cjs/model/definitions.js +14 -0
- package/dist/cjs/model/http.js +19 -0
- package/dist/cjs/model/index.js +37 -0
- package/dist/cjs/model/layout.js +14 -0
- package/dist/cjs/model/panels.js +14 -0
- package/dist/cjs/model/resource.js +14 -0
- package/dist/cjs/model/time.js +69 -0
- package/dist/cjs/model/variables.js +16 -0
- package/dist/cjs/utils/fetch.js +48 -0
- package/dist/cjs/utils/index.js +31 -0
- package/dist/cjs/utils/memo.js +50 -0
- package/dist/cjs/utils/panel-refs.js +28 -0
- package/package.json +5 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./model"), exports);
|
|
30
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.buildDatasourceURL = void 0;
|
|
16
|
+
function buildDatasourceURL(datasourceName, config) {
|
|
17
|
+
return config.access === 'server' ? `/proxy/globaldatasources/${datasourceName}` : config.url;
|
|
18
|
+
}
|
|
19
|
+
exports.buildDatasourceURL = buildDatasourceURL;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./dashboard"), exports);
|
|
30
|
+
__exportStar(require("./datasource"), exports);
|
|
31
|
+
__exportStar(require("./definitions"), exports);
|
|
32
|
+
__exportStar(require("./http"), exports);
|
|
33
|
+
__exportStar(require("./layout"), exports);
|
|
34
|
+
__exportStar(require("./panels"), exports);
|
|
35
|
+
__exportStar(require("./resource"), exports);
|
|
36
|
+
__exportStar(require("./time"), exports);
|
|
37
|
+
__exportStar(require("./variables"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getSuggestedStepMs = exports.isDurationString = exports.parseDurationString = exports.toAbsoluteTimeRange = void 0;
|
|
16
|
+
const date_fns_1 = require("date-fns");
|
|
17
|
+
/**
|
|
18
|
+
* Returns an absolute time range from a RelativeTimeRange.
|
|
19
|
+
*/
|
|
20
|
+
function toAbsoluteTimeRange(timeRange) {
|
|
21
|
+
var _a;
|
|
22
|
+
const end = (_a = timeRange.end) !== null && _a !== void 0 ? _a : new Date();
|
|
23
|
+
return {
|
|
24
|
+
start: (0, date_fns_1.sub)(end, parseDurationString(timeRange.pastDuration)),
|
|
25
|
+
end,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.toAbsoluteTimeRange = toAbsoluteTimeRange;
|
|
29
|
+
const DURATION_REGEX = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?(?:(\d+)ms)?$/;
|
|
30
|
+
/**
|
|
31
|
+
* Parses a DurationString into a Duration object with numeric values that can
|
|
32
|
+
* be used to do Date math. Throws if not a valid duration string.
|
|
33
|
+
*/
|
|
34
|
+
function parseDurationString(durationString) {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
|
+
const matches = DURATION_REGEX.exec(durationString);
|
|
37
|
+
if (matches === null) {
|
|
38
|
+
throw new Error(`Invalid duration string '${durationString}'`);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
years: parseInt((_a = matches[1]) !== null && _a !== void 0 ? _a : '0'),
|
|
42
|
+
months: 0,
|
|
43
|
+
weeks: parseInt((_b = matches[2]) !== null && _b !== void 0 ? _b : '0'),
|
|
44
|
+
days: parseInt((_c = matches[3]) !== null && _c !== void 0 ? _c : '0'),
|
|
45
|
+
hours: parseInt((_d = matches[4]) !== null && _d !== void 0 ? _d : '0'),
|
|
46
|
+
minutes: parseInt((_e = matches[5]) !== null && _e !== void 0 ? _e : '0'),
|
|
47
|
+
seconds: parseInt((_f = matches[6]) !== null && _f !== void 0 ? _f : '0') + parseInt((_g = matches[7]) !== null && _g !== void 0 ? _g : '0') / 1000,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.parseDurationString = parseDurationString;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if the given string is a valid DurationString.
|
|
53
|
+
*/
|
|
54
|
+
function isDurationString(maybeDuration) {
|
|
55
|
+
if (maybeDuration === '')
|
|
56
|
+
return false;
|
|
57
|
+
return DURATION_REGEX.test(maybeDuration);
|
|
58
|
+
}
|
|
59
|
+
exports.isDurationString = isDurationString;
|
|
60
|
+
/**
|
|
61
|
+
* Gets a suggested step/interval size for a time range based on the width of a visual component.
|
|
62
|
+
*/
|
|
63
|
+
function getSuggestedStepMs(timeRange, width) {
|
|
64
|
+
// TODO: Should we try to suggest more "rounded" step values based around
|
|
65
|
+
// time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)
|
|
66
|
+
const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
|
|
67
|
+
return Math.floor(queryRangeMs / width);
|
|
68
|
+
}
|
|
69
|
+
exports.getSuggestedStepMs = getSuggestedStepMs;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DEFAULT_ALL_VALUE = void 0;
|
|
16
|
+
exports.DEFAULT_ALL_VALUE = '$__all';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FetchError = exports.fetchJson = exports.fetch = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* Calls `global.fetch`, but throws a `FetchError` for non-200 responses.
|
|
18
|
+
*/
|
|
19
|
+
async function fetch(...args) {
|
|
20
|
+
const response = await global.fetch(...args);
|
|
21
|
+
if (response.ok === false) {
|
|
22
|
+
throw new FetchError(response);
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
exports.fetch = fetch;
|
|
27
|
+
/**
|
|
28
|
+
* Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also
|
|
29
|
+
* decodes the response body as JSON, casting it to type `T`. Returns the
|
|
30
|
+
* decoded body.
|
|
31
|
+
*/
|
|
32
|
+
async function fetchJson(...args) {
|
|
33
|
+
const response = await fetch(...args);
|
|
34
|
+
const json = await response.json();
|
|
35
|
+
return json;
|
|
36
|
+
}
|
|
37
|
+
exports.fetchJson = fetchJson;
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when fetch returns a non-200 response.
|
|
40
|
+
*/
|
|
41
|
+
class FetchError extends Error {
|
|
42
|
+
constructor(response) {
|
|
43
|
+
super(`${response.status} ${response.statusText}`);
|
|
44
|
+
this.response = response;
|
|
45
|
+
Object.setPrototypeOf(this, FetchError.prototype);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.FetchError = FetchError;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./fetch"), exports);
|
|
30
|
+
__exportStar(require("./memo"), exports);
|
|
31
|
+
__exportStar(require("./panel-refs"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useDeepMemo = exports.useMemoized = void 0;
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const lodash_es_1 = require("lodash-es");
|
|
18
|
+
/**
|
|
19
|
+
* Like React's useMemo, but guarantees the value will only be recalulated if
|
|
20
|
+
* a dependency changes. Uses strict equality (===) for comparison. (React's
|
|
21
|
+
* useMemo does not offer this guarantee, it's only a performance optimization).
|
|
22
|
+
*/
|
|
23
|
+
function useMemoized(factory, deps) {
|
|
24
|
+
var _a;
|
|
25
|
+
const ref = (0, react_1.useRef)();
|
|
26
|
+
let areEqual = true;
|
|
27
|
+
for (let i = 0; i < deps.length; i++) {
|
|
28
|
+
if (((_a = ref.current) === null || _a === void 0 ? void 0 : _a.deps[i]) !== deps[i]) {
|
|
29
|
+
areEqual = false;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (ref.current === undefined || areEqual === false) {
|
|
34
|
+
ref.current = { value: factory(), deps: deps };
|
|
35
|
+
}
|
|
36
|
+
return ref.current.value;
|
|
37
|
+
}
|
|
38
|
+
exports.useMemoized = useMemoized;
|
|
39
|
+
/**
|
|
40
|
+
* Like React's useMemo, except it does a deep equality comparison with lodash's
|
|
41
|
+
* isEqual on the dependency list.
|
|
42
|
+
*/
|
|
43
|
+
function useDeepMemo(factory, deps) {
|
|
44
|
+
const ref = (0, react_1.useRef)();
|
|
45
|
+
if (ref.current === undefined || (0, lodash_es_1.isEqual)(deps, ref.current.deps) === false) {
|
|
46
|
+
ref.current = { value: factory(), deps };
|
|
47
|
+
}
|
|
48
|
+
return ref.current.value;
|
|
49
|
+
}
|
|
50
|
+
exports.useDeepMemo = useDeepMemo;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.resolvePanelRef = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a PanelRef (JSON reference) against the provided DashboardSpec to
|
|
18
|
+
* a PanelDefinition.
|
|
19
|
+
*/
|
|
20
|
+
function resolvePanelRef(spec, panelRef) {
|
|
21
|
+
const panelsKey = panelRef.$ref.substring(9);
|
|
22
|
+
const panelDefinition = spec.panels[panelsKey];
|
|
23
|
+
if (panelDefinition === undefined) {
|
|
24
|
+
throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);
|
|
25
|
+
}
|
|
26
|
+
return panelDefinition;
|
|
27
|
+
}
|
|
28
|
+
exports.resolvePanelRef = resolvePanelRef;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Core functionality consumed by both the Perses UI and plugins",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -12,15 +12,18 @@
|
|
|
12
12
|
"url": "https://github.com/perses/perses/issues"
|
|
13
13
|
},
|
|
14
14
|
"module": "dist/index.js",
|
|
15
|
+
"main": "dist/cjs/index.js",
|
|
15
16
|
"types": "dist/index.d.ts",
|
|
16
17
|
"scripts": {
|
|
17
18
|
"clean": "rimraf dist/",
|
|
18
|
-
"build": "tsc",
|
|
19
|
+
"build": "tsc --build",
|
|
20
|
+
"build:cjs": "tsc --project ./tsconfig.cjs.json",
|
|
19
21
|
"test": "echo 'no test to run' && exit 0",
|
|
20
22
|
"lint": "eslint src --ext .ts,.tsx",
|
|
21
23
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
22
24
|
},
|
|
23
25
|
"dependencies": {
|
|
26
|
+
"@perses-dev/core": "^0.4.0",
|
|
24
27
|
"date-fns": "^2.28.0",
|
|
25
28
|
"lodash-es": "^4.17.21"
|
|
26
29
|
},
|