diff --git a/common/.eslintrc.js b/common/.eslintrc.js new file mode 100644 index 0000000..08ac960 --- /dev/null +++ b/common/.eslintrc.js @@ -0,0 +1,14 @@ +// Copyright The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = require('../.eslintrc.base.js'); diff --git a/common/README.md b/common/README.md new file mode 100644 index 0000000..0df0bee --- /dev/null +++ b/common/README.md @@ -0,0 +1,3 @@ +# Perses Common Package + +this [package] This [package](https://www.npmjs.com/package/@perses-dev/common) includes basic types and utilities which are common among other packages. \ No newline at end of file diff --git a/common/package.json b/common/package.json new file mode 100644 index 0000000..abddaf3 --- /dev/null +++ b/common/package.json @@ -0,0 +1,33 @@ +{ + "name": "@perses-dev/common", + "version": "0.54.0-beta.0", + "description": "Common types and utilities of Perses", + "license": "Apache-2.0", + "homepage": "https://github.com/perses/perses/blob/main/README.md", + "repository": { + "type": "git", + "url": "git+https://github.com/perses/perses.git" + }, + "bugs": { + "url": "https://github.com/perses/perses/issues" + }, + "module": "dist/index.js", + "main": "dist/cjs/index.js", + "types": "dist/index.d.ts", + "scripts": { + "clean": "rimraf dist/", + "build": "concurrently \"npm:build:*\"", + "build:cjs": "swc ./src -d dist/cjs --strip-leading-paths --config-file ../.cjs.swcrc", + "build:esm": "swc ./src -d dist --strip-leading-paths --config-file ../.swcrc", + "build:types": "tsc --project tsconfig.build.json", + "type-check": "tsc --noEmit", + "start": "concurrently -P \"npm:build:* -- {*}\" -- --watch", + "test": "cross-env TZ=UTC jest", + "test:watch": "cross-env TZ=UTC jest --watch", + "lint": "eslint src --ext .ts,.tsx", + "lint:fix": "eslint --fix src --ext .ts,.tsx" + }, + "files": [ + "dist" + ] +} diff --git a/common/src/index.ts b/common/src/index.ts new file mode 100644 index 0000000..c858d9a --- /dev/null +++ b/common/src/index.ts @@ -0,0 +1,14 @@ +// Copyright The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export * from './types'; diff --git a/common/src/types/crud.ts b/common/src/types/crud.ts new file mode 100644 index 0000000..a728894 --- /dev/null +++ b/common/src/types/crud.ts @@ -0,0 +1,14 @@ +// Copyright The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export type CrudAction = 'create' | 'read' | 'update' | 'delete' | '*'; diff --git a/common/src/types/http.ts b/common/src/types/http.ts new file mode 100644 index 0000000..6dffd1f --- /dev/null +++ b/common/src/types/http.ts @@ -0,0 +1,42 @@ +// Copyright The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export interface HTTPProxy { + kind: 'HTTPProxy'; + spec: HTTPProxySpec; +} +export interface HTTPProxySpec { + // url is the url of the datasource. It is not the url of the proxy. + // The Perses server is the proxy, so it needs to know where to redirect the request. + url: string; + // allowedEndpoints is a list of tuples of http methods and http endpoints that will be accessible. + // Leave it empty if you don't want to restrict the access to the datasource. + allowedEndpoints?: HTTPAllowedEndpoint[]; + // headers can be used to provide additional headers that need to be forwarded when requesting the datasource + headers?: RequestHeaders; + // secret is the name of the secret that should be used for the proxy or discovery configuration + // It will contain any sensitive information such as password, token, certificate. + secret?: string; +} + +export interface HTTPAllowedEndpoint { + endpointPattern: string; + method: string; +} + +export type RequestHeaders = Record; + +export interface HTTPDatasourceSpec { + directUrl?: string; + proxy?: HTTPProxy; +} diff --git a/common/src/types/index.ts b/common/src/types/index.ts new file mode 100644 index 0000000..b3e1708 --- /dev/null +++ b/common/src/types/index.ts @@ -0,0 +1,15 @@ +// Copyright The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export * from './http'; +export * from './crud'; diff --git a/common/tsconfig.build.json b/common/tsconfig.build.json new file mode 100644 index 0000000..48d8e2b --- /dev/null +++ b/common/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["**/*.stories.*", "**/*.test.*"], + "compilerOptions": { + "emitDeclarationOnly": true, + "declaration": true, + "preserveWatchOutput": true + } + } \ No newline at end of file diff --git a/common/tsconfig.json b/common/tsconfig.json new file mode 100644 index 0000000..9d71d29 --- /dev/null +++ b/common/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["src"], + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "paths": { + "@perses-dev/components": ["./src"] + } + } + } + \ No newline at end of file diff --git a/package.json b/package.json index 865eaaf..b7ea777 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "components", "dashboards", "plugin-system", - "explore" + "explore", + "common" ], "devDependencies": { "@emotion/react": "^11.14.0",