@perses-dev/client 0.54.0-beta.2
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/README.md +3 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/model/datasource-api.js +16 -0
- package/dist/cjs/model/datasource.js +16 -0
- package/dist/cjs/model/http-proxy.js +16 -0
- package/dist/cjs/model/http.js +16 -0
- package/dist/cjs/model/index.js +35 -0
- package/dist/cjs/model/kind.js +39 -0
- package/dist/cjs/model/resource.js +36 -0
- package/dist/cjs/schema/datasource.js +66 -0
- package/dist/cjs/schema/index.js +31 -0
- package/dist/cjs/schema/metadata.js +41 -0
- package/dist/cjs/test/index.js +30 -0
- package/dist/cjs/test/render.js +38 -0
- package/dist/cjs/test/setup-tests.js +18 -0
- package/dist/cjs/util/fetch.js +82 -0
- package/dist/cjs/util/index.js +30 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/model/datasource-api.d.ts +41 -0
- package/dist/model/datasource-api.d.ts.map +1 -0
- package/dist/model/datasource-api.js +19 -0
- package/dist/model/datasource-api.js.map +1 -0
- package/dist/model/datasource.d.ts +28 -0
- package/dist/model/datasource.d.ts.map +1 -0
- package/dist/model/datasource.js +15 -0
- package/dist/model/datasource.js.map +1 -0
- package/dist/model/http-proxy.d.ts +16 -0
- package/dist/model/http-proxy.d.ts.map +1 -0
- package/dist/model/http-proxy.js +15 -0
- package/dist/model/http-proxy.js.map +1 -0
- package/dist/model/http.d.ts +7 -0
- package/dist/model/http.d.ts.map +1 -0
- package/dist/model/http.js +15 -0
- package/dist/model/http.js.map +1 -0
- package/dist/model/index.d.ts +7 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +20 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/kind.d.ts +3 -0
- package/dist/model/kind.d.ts.map +1 -0
- package/dist/model/kind.js +31 -0
- package/dist/model/kind.js.map +1 -0
- package/dist/model/resource.d.ts +19 -0
- package/dist/model/resource.d.ts.map +1 -0
- package/dist/model/resource.js +20 -0
- package/dist/model/resource.js.map +1 -0
- package/dist/schema/datasource.d.ts +59 -0
- package/dist/schema/datasource.d.ts.map +1 -0
- package/dist/schema/datasource.js +41 -0
- package/dist/schema/datasource.js.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +16 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/metadata.d.ts +21 -0
- package/dist/schema/metadata.d.ts.map +1 -0
- package/dist/schema/metadata.js +22 -0
- package/dist/schema/metadata.js.map +1 -0
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +15 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/render.d.ts +7 -0
- package/dist/test/render.d.ts.map +1 -0
- package/dist/test/render.js +32 -0
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.d.ts +2 -0
- package/dist/test/setup-tests.d.ts.map +1 -0
- package/dist/test/setup-tests.js +16 -0
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/util/fetch.d.ts +28 -0
- package/dist/util/fetch.d.ts.map +1 -0
- package/dist/util/fetch.js +68 -0
- package/dist/util/fetch.js.map +1 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +15 -0
- package/dist/util/index.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `globalThis.fetch` and determines which type of error to show for non-200 responses.
|
|
3
|
+
*/
|
|
4
|
+
export declare function fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* Calls `globalThis.fetch` and throws a `FetchError` on non-200 responses, but also
|
|
7
|
+
* decodes the response body as JSON, casting it to type `T`. Returns the
|
|
8
|
+
* decoded body.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetchJson<T>(...args: Parameters<typeof globalThis.fetch>): Promise<T>;
|
|
11
|
+
export interface StatusError extends Error {
|
|
12
|
+
status: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when fetch returns a non-200 response.
|
|
16
|
+
*/
|
|
17
|
+
export declare class FetchError extends Error implements StatusError {
|
|
18
|
+
status: number;
|
|
19
|
+
constructor(response: Readonly<Response>);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* General error type for an error that has a message that is OK to show to the end user.
|
|
23
|
+
*/
|
|
24
|
+
export declare class UserFriendlyError extends Error implements StatusError {
|
|
25
|
+
status: number;
|
|
26
|
+
constructor(message: string, status: number);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/util/fetch.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqB3F;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM3F;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAM,YAAW,WAAW;IAC1D,MAAM,EAAE,MAAM,CAAC;gBACH,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;CAKzC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAM,YAAW,WAAW;IACjE,MAAM,EAAE,MAAM,CAAC;gBACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK5C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Calls `globalThis.fetch` and determines which type of error to show for non-200 responses.
|
|
15
|
+
*/ export async function fetch(...args) {
|
|
16
|
+
const response = await globalThis.fetch(...args);
|
|
17
|
+
if (response.ok === false) {
|
|
18
|
+
const contentType = response.headers.get('content-type');
|
|
19
|
+
if (contentType?.includes('application/json')) {
|
|
20
|
+
const json = await response.clone().json();
|
|
21
|
+
if (json.error) {
|
|
22
|
+
throw new UserFriendlyError(json.error, response.status);
|
|
23
|
+
}
|
|
24
|
+
if (json.message) {
|
|
25
|
+
throw new UserFriendlyError(json.message, response.status);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const text = await response.clone().text();
|
|
29
|
+
if (text) {
|
|
30
|
+
throw new UserFriendlyError(text, response.status);
|
|
31
|
+
}
|
|
32
|
+
throw new FetchError(response);
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Calls `globalThis.fetch` and throws a `FetchError` on non-200 responses, but also
|
|
38
|
+
* decodes the response body as JSON, casting it to type `T`. Returns the
|
|
39
|
+
* decoded body.
|
|
40
|
+
*/ export async function fetchJson(...args) {
|
|
41
|
+
const response = await fetch(...args);
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new FetchError(response);
|
|
44
|
+
}
|
|
45
|
+
return await response.json();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Error thrown when fetch returns a non-200 response.
|
|
49
|
+
*/ export class FetchError extends Error {
|
|
50
|
+
status;
|
|
51
|
+
constructor(response){
|
|
52
|
+
super(`${response.status} ${response.statusText}`);
|
|
53
|
+
this.status = response.status;
|
|
54
|
+
Object.setPrototypeOf(this, FetchError.prototype);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* General error type for an error that has a message that is OK to show to the end user.
|
|
59
|
+
*/ export class UserFriendlyError extends Error {
|
|
60
|
+
status;
|
|
61
|
+
constructor(message, status){
|
|
62
|
+
super(message);
|
|
63
|
+
this.status = status;
|
|
64
|
+
Object.setPrototypeOf(this, UserFriendlyError.prototype);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/fetch.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\n/**\n * Calls `globalThis.fetch` and determines which type of error to show for non-200 responses.\n */\nexport async function fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response> {\n const response = await globalThis.fetch(...args);\n if (response.ok === false) {\n const contentType = response.headers.get('content-type');\n if (contentType?.includes('application/json')) {\n const json = await response.clone().json();\n if (json.error) {\n throw new UserFriendlyError(json.error, response.status);\n }\n if (json.message) {\n throw new UserFriendlyError(json.message, response.status);\n }\n }\n\n const text = await response.clone().text();\n if (text) {\n throw new UserFriendlyError(text, response.status);\n }\n throw new FetchError(response);\n }\n return response;\n}\n\n/**\n * Calls `globalThis.fetch` and throws a `FetchError` on non-200 responses, but also\n * decodes the response body as JSON, casting it to type `T`. Returns the\n * decoded body.\n */\nexport async function fetchJson<T>(...args: Parameters<typeof globalThis.fetch>): Promise<T> {\n const response = await fetch(...args);\n if (!response.ok) {\n throw new FetchError(response);\n }\n return await response.json();\n}\n\nexport interface StatusError extends Error {\n status: number;\n}\n\n/**\n * Error thrown when fetch returns a non-200 response.\n */\nexport class FetchError extends Error implements StatusError {\n status: number;\n constructor(response: Readonly<Response>) {\n super(`${response.status} ${response.statusText}`);\n this.status = response.status;\n Object.setPrototypeOf(this, FetchError.prototype);\n }\n}\n\n/**\n * General error type for an error that has a message that is OK to show to the end user.\n */\nexport class UserFriendlyError extends Error implements StatusError {\n status: number;\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n Object.setPrototypeOf(this, UserFriendlyError.prototype);\n }\n}\n"],"names":["fetch","args","response","globalThis","ok","contentType","headers","get","includes","json","clone","error","UserFriendlyError","status","message","text","FetchError","fetchJson","Error","statusText","Object","setPrototypeOf","prototype"],"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;;CAEC,GACD,OAAO,eAAeA,MAAM,GAAGC,IAAyC;IACtE,MAAMC,WAAW,MAAMC,WAAWH,KAAK,IAAIC;IAC3C,IAAIC,SAASE,EAAE,KAAK,OAAO;QACzB,MAAMC,cAAcH,SAASI,OAAO,CAACC,GAAG,CAAC;QACzC,IAAIF,aAAaG,SAAS,qBAAqB;YAC7C,MAAMC,OAAO,MAAMP,SAASQ,KAAK,GAAGD,IAAI;YACxC,IAAIA,KAAKE,KAAK,EAAE;gBACd,MAAM,IAAIC,kBAAkBH,KAAKE,KAAK,EAAET,SAASW,MAAM;YACzD;YACA,IAAIJ,KAAKK,OAAO,EAAE;gBAChB,MAAM,IAAIF,kBAAkBH,KAAKK,OAAO,EAAEZ,SAASW,MAAM;YAC3D;QACF;QAEA,MAAME,OAAO,MAAMb,SAASQ,KAAK,GAAGK,IAAI;QACxC,IAAIA,MAAM;YACR,MAAM,IAAIH,kBAAkBG,MAAMb,SAASW,MAAM;QACnD;QACA,MAAM,IAAIG,WAAWd;IACvB;IACA,OAAOA;AACT;AAEA;;;;CAIC,GACD,OAAO,eAAee,UAAa,GAAGhB,IAAyC;IAC7E,MAAMC,WAAW,MAAMF,SAASC;IAChC,IAAI,CAACC,SAASE,EAAE,EAAE;QAChB,MAAM,IAAIY,WAAWd;IACvB;IACA,OAAO,MAAMA,SAASO,IAAI;AAC5B;AAMA;;CAEC,GACD,OAAO,MAAMO,mBAAmBE;IAC9BL,OAAe;IACf,YAAYX,QAA4B,CAAE;QACxC,KAAK,CAAC,GAAGA,SAASW,MAAM,CAAC,CAAC,EAAEX,SAASiB,UAAU,EAAE;QACjD,IAAI,CAACN,MAAM,GAAGX,SAASW,MAAM;QAC7BO,OAAOC,cAAc,CAAC,IAAI,EAAEL,WAAWM,SAAS;IAClD;AACF;AAEA;;CAEC,GACD,OAAO,MAAMV,0BAA0BM;IACrCL,OAAe;IACf,YAAYC,OAAe,EAAED,MAAc,CAAE;QAC3C,KAAK,CAACC;QACN,IAAI,CAACD,MAAM,GAAGA;QACdO,OAAOC,cAAc,CAAC,IAAI,EAAET,kBAAkBU,SAAS;IACzD;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,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 './fetch';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/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 './fetch';\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,UAAU"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@perses-dev/client",
|
|
3
|
+
"version": "0.54.0-beta.2",
|
|
4
|
+
"description": "Functions as an API client or Data fetching Layer for interacting with a backend service",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/perses/perses.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/perses/perses/issues"
|
|
13
|
+
},
|
|
14
|
+
"module": "dist/index.js",
|
|
15
|
+
"main": "dist/cjs/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@perses-dev/spec": "0.2.0-beta.0",
|
|
19
|
+
"zod": "^3.21.4"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rimraf dist/",
|
|
23
|
+
"build": "concurrently \"npm:build:*\"",
|
|
24
|
+
"build:cjs": "swc ./src -d dist/cjs --strip-leading-paths --config-file ../.cjs.swcrc",
|
|
25
|
+
"build:esm": "swc ./src -d dist --strip-leading-paths --config-file ../.swcrc",
|
|
26
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
27
|
+
"type-check": "tsc --noEmit",
|
|
28
|
+
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
29
|
+
"test": "cross-env TZ=UTC jest --passWithNoTests",
|
|
30
|
+
"test:watch": "cross-env TZ=UTC jest --watch",
|
|
31
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
32
|
+
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
]
|
|
37
|
+
}
|