@perses-dev/client 0.54.0-rc.1 → 0.55.0-beta.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.
@@ -0,0 +1,53 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get FetchProvider () {
25
+ return FetchProvider;
26
+ },
27
+ get useFetch () {
28
+ return useFetch;
29
+ }
30
+ });
31
+ const _jsxruntime = require("react/jsx-runtime");
32
+ const _react = require("react");
33
+ const _fetch = require("../util/fetch");
34
+ const FetchContext = /*#__PURE__*/ (0, _react.createContext)(_fetch.fetch);
35
+ function FetchProvider({ fetchFn, children }) {
36
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(FetchContext.Provider, {
37
+ value: fetchFn,
38
+ children: children
39
+ });
40
+ }
41
+ function useFetch() {
42
+ const fetch = (0, _react.useContext)(FetchContext);
43
+ const fetchJson = (0, _react.useCallback)(async (...args)=>{
44
+ const response = await fetch(...args);
45
+ return await response.json();
46
+ }, [
47
+ fetch
48
+ ]);
49
+ return {
50
+ fetch,
51
+ fetchJson
52
+ };
53
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _export_star(require("./FetchContext"), exports);
18
+ function _export_star(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ return from;
30
+ }
package/dist/cjs/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _export_star(require("./util"), exports);
18
18
  _export_star(require("./model"), exports);
19
19
  _export_star(require("./schema"), exports);
20
+ _export_star(require("./context"), exports);
20
21
  function _export_star(from, to) {
21
22
  Object.keys(from).forEach(function(k) {
22
23
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,12 @@
1
+ import { ReactElement, ReactNode } from 'react';
2
+ export type FetchFn = (...args: Parameters<typeof globalThis.fetch>) => Promise<Response>;
3
+ export interface FetchProviderProps {
4
+ fetchFn: FetchFn;
5
+ children: ReactNode;
6
+ }
7
+ export declare function FetchProvider({ fetchFn, children }: FetchProviderProps): ReactElement;
8
+ export declare function useFetch(): {
9
+ fetch: FetchFn;
10
+ fetchJson: <T>(...args: Parameters<typeof globalThis.fetch>) => Promise<T>;
11
+ };
12
+ //# sourceMappingURL=FetchContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FetchContext.d.ts","sourceRoot":"","sources":["../../src/context/FetchContext.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAE,SAAS,EAA2B,MAAM,OAAO,CAAC;AAGxF,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAI1F,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,kBAAkB,GAAG,YAAY,CAErF;AAED,wBAAgB,QAAQ,IAAI;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CAC5E,CAYA"}
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Copyright 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
+ import { createContext, useCallback, useContext } from 'react';
15
+ import { fetch as defaultFetch } from '../util/fetch';
16
+ const FetchContext = /*#__PURE__*/ createContext(defaultFetch);
17
+ export function FetchProvider({ fetchFn, children }) {
18
+ return /*#__PURE__*/ _jsx(FetchContext.Provider, {
19
+ value: fetchFn,
20
+ children: children
21
+ });
22
+ }
23
+ export function useFetch() {
24
+ const fetch = useContext(FetchContext);
25
+ const fetchJson = useCallback(async (...args)=>{
26
+ const response = await fetch(...args);
27
+ return await response.json();
28
+ }, [
29
+ fetch
30
+ ]);
31
+ return {
32
+ fetch,
33
+ fetchJson
34
+ };
35
+ }
36
+
37
+ //# sourceMappingURL=FetchContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/FetchContext.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, ReactNode, useCallback, useContext } from 'react';\nimport { fetch as defaultFetch } from '../util/fetch';\n\nexport type FetchFn = (...args: Parameters<typeof globalThis.fetch>) => Promise<Response>;\n\nconst FetchContext = createContext<FetchFn>(defaultFetch);\n\nexport interface FetchProviderProps {\n fetchFn: FetchFn;\n children: ReactNode;\n}\n\nexport function FetchProvider({ fetchFn, children }: FetchProviderProps): ReactElement {\n return <FetchContext.Provider value={fetchFn}>{children}</FetchContext.Provider>;\n}\n\nexport function useFetch(): {\n fetch: FetchFn;\n fetchJson: <T>(...args: Parameters<typeof globalThis.fetch>) => Promise<T>;\n} {\n const fetch = useContext(FetchContext);\n\n const fetchJson = useCallback(\n async <T,>(...args: Parameters<typeof globalThis.fetch>): Promise<T> => {\n const response = await fetch(...args);\n return await response.json();\n },\n [fetch]\n );\n\n return { fetch, fetchJson };\n}\n"],"names":["createContext","useCallback","useContext","fetch","defaultFetch","FetchContext","FetchProvider","fetchFn","children","Provider","value","useFetch","fetchJson","args","response","json"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAA2BC,WAAW,EAAEC,UAAU,QAAQ,QAAQ;AACxF,SAASC,SAASC,YAAY,QAAQ,gBAAgB;AAItD,MAAMC,6BAAeL,cAAuBI;AAO5C,OAAO,SAASE,cAAc,EAAEC,OAAO,EAAEC,QAAQ,EAAsB;IACrE,qBAAO,KAACH,aAAaI,QAAQ;QAACC,OAAOH;kBAAUC;;AACjD;AAEA,OAAO,SAASG;IAId,MAAMR,QAAQD,WAAWG;IAEzB,MAAMO,YAAYX,YAChB,OAAW,GAAGY;QACZ,MAAMC,WAAW,MAAMX,SAASU;QAChC,OAAO,MAAMC,SAASC,IAAI;IAC5B,GACA;QAACZ;KAAM;IAGT,OAAO;QAAEA;QAAOS;IAAU;AAC5B"}
@@ -0,0 +1,2 @@
1
+ export * from './FetchContext';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './FetchContext';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './FetchContext';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,iBAAiB"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './util';
2
2
  export * from './model';
3
3
  export * from './schema';
4
+ export * from './context';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -13,5 +13,6 @@
13
13
  export * from './util';
14
14
  export * from './model';
15
15
  export * from './schema';
16
+ export * from './context';
16
17
 
17
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './util';\nexport * from './model';\nexport * from './schema';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,WAAW"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './util';\nexport * from './model';\nexport * from './schema';\nexport * from './context';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,WAAW;AACzB,cAAc,YAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/client",
3
- "version": "0.54.0-rc.1",
3
+ "version": "0.55.0-beta.0",
4
4
  "description": "Functions as an API client or Data fetching Layer for interacting with a backend service",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -15,9 +15,12 @@
15
15
  "main": "dist/cjs/index.js",
16
16
  "types": "dist/index.d.ts",
17
17
  "dependencies": {
18
- "@perses-dev/spec": "0.2.0-rc.0",
18
+ "@perses-dev/spec": "0.3.0-beta.0",
19
19
  "zod": "^3.21.4"
20
20
  },
21
+ "peerDependencies": {
22
+ "react": "^17.0.2 || ^18.0.0"
23
+ },
21
24
  "scripts": {
22
25
  "clean": "rimraf dist/",
23
26
  "build": "concurrently \"npm:build:*\"",