├── example
├── src
│ ├── react-app-env.d.ts
│ ├── setupTests.ts
│ ├── index.css
│ ├── reportWebVitals.ts
│ ├── index.tsx
│ ├── App.css
│ ├── App.tsx
│ ├── interfaces
│ │ └── index.d.ts
│ ├── pages
│ │ └── posts
│ │ │ ├── show.tsx
│ │ │ ├── create.tsx
│ │ │ ├── edit.tsx
│ │ │ └── list.tsx
│ ├── logo.svg
│ └── lib
│ │ └── index.ts
├── public
│ ├── robots.txt
│ ├── favicon.ico
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── index.html
├── .gitignore
├── tsconfig.json
├── package.json
└── README.md
├── test
├── jest.setup.ts
├── deleteOne
│ ├── index.mock.ts
│ └── index.spec.ts
├── utils.ts
├── getOne
│ ├── index.spec.ts
│ └── index.mock.ts
├── custom
│ ├── index.spec.ts
│ └── index.mock.ts
├── update
│ ├── index.mock.ts
│ └── index.spec.ts
├── create
│ ├── index.mock.ts
│ └── index.spec.ts
├── getMany
│ ├── index.spec.ts
│ └── index.mock.ts
└── getList
│ ├── index.spec.ts
│ └── index.mock.ts
├── jest.config.js
├── README.md
├── tsup.config.ts
├── tsconfig.json
├── package.json
├── .gitignore
├── src
└── index.ts
└── LICENSE
/example/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/example/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/example/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chirdeeptomar/refine-elide-rest/HEAD/example/public/favicon.ico
--------------------------------------------------------------------------------
/example/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chirdeeptomar/refine-elide-rest/HEAD/example/public/logo192.png
--------------------------------------------------------------------------------
/example/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chirdeeptomar/refine-elide-rest/HEAD/example/public/logo512.png
--------------------------------------------------------------------------------
/test/jest.setup.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 |
3 | afterAll(() => {
4 | nock.cleanAll();
5 | nock.restore();
6 | });
7 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: "ts-jest",
3 | rootDir: "./",
4 | name: "elide-rest",
5 | displayName: "elide-rest",
6 | setupFilesAfterEnv: ["/test/jest.setup.ts"],
7 | testEnvironment: "jsdom",
8 | };
9 |
--------------------------------------------------------------------------------
/test/deleteOne/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 | import { ELIDE_REST_API_URL } from "../utils";
3 |
4 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
5 | .delete("/group/11ecbb46-6775-4c05-8c26-b53ca0164e1c")
6 | .reply(204);
7 |
--------------------------------------------------------------------------------
/example/src/setupTests.ts:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/example/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/test/utils.ts:
--------------------------------------------------------------------------------
1 | export function makeid(length: number) {
2 | let result = '';
3 | const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
4 | const charactersLength = characters.length;
5 | for (let i = 0; i < length; i++) {
6 | result += characters.charAt(Math.floor(Math.random() * charactersLength));
7 | }
8 | return result;
9 | }
10 |
11 | export const ELIDE_REST_API_URL = 'http://localhost:8080/api/v1'
12 |
--------------------------------------------------------------------------------
/example/src/reportWebVitals.ts:
--------------------------------------------------------------------------------
1 | import { ReportHandler } from 'web-vitals';
2 |
3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4 | if (onPerfEntry && onPerfEntry instanceof Function) {
5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6 | getCLS(onPerfEntry);
7 | getFID(onPerfEntry);
8 | getFCP(onPerfEntry);
9 | getLCP(onPerfEntry);
10 | getTTFB(onPerfEntry);
11 | });
12 | }
13 | };
14 |
15 | export default reportWebVitals;
16 |
--------------------------------------------------------------------------------
/test/deleteOne/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import JsonServer from "../../src/index";
3 | import "./index.mock";
4 | import { ELIDE_REST_API_URL } from "../utils"
5 |
6 | axios.defaults.adapter = require("axios/lib/adapters/http");
7 |
8 | describe("deleteOne", () => {
9 | it("correct response", async () => {
10 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
11 | .deleteOne({ resource: "group", id: "11ecbb46-6775-4c05-8c26-b53ca0164e1c" });
12 |
13 | const { data } = response;
14 |
15 | expect(data).toEqual("");
16 | });
17 | });
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **refine** is a [React](https://react.dev/)-based framework for building internal tools, rapidly.
2 |
3 | **[Elide](https://elide.io/)** is Java library that lets you setup model driven GraphQL or JSON API web service with minimal effort.
4 |
5 | ## About
6 |
7 | This repository is a data provider for elide that lets you connect refine to Elide.
8 |
9 | ## Documentation
10 |
11 | For more detailed information and usage, refer to the [refine data provider documentation](https://refine.dev/docs/core/providers/data-provider).
12 |
13 | ## Install
14 |
15 | ```
16 | npm install elide-simple-rest
17 | ```
18 |
--------------------------------------------------------------------------------
/example/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/example/src/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
7 | const root = ReactDOM.createRoot(
8 | document.getElementById('root') as HTMLElement
9 | );
10 | root.render(
11 |
12 |
13 |
14 | );
15 |
16 | // If you want to start measuring performance in your app, pass a function
17 | // to log results (for example: reportWebVitals(console.log))
18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
19 | reportWebVitals();
20 |
--------------------------------------------------------------------------------
/test/getOne/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import JsonServer from "../../src/index";
3 | import { ELIDE_REST_API_URL } from "../utils";
4 | import "./index.mock";
5 |
6 | axios.defaults.adapter = require("axios/lib/adapters/http");
7 |
8 | describe("getOne", () => {
9 | it("correct response", async () => {
10 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
11 | .getOne({ resource: "group", id: "com.yahoo.elide" });
12 |
13 | const { data } = response;
14 |
15 | expect(data.id).toBe("com.yahoo.elide");
16 | expect(data.attributes.commonName).toBe("Elide");
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/example/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "strict": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "noFallthroughCasesInSwitch": true,
16 | "module": "esnext",
17 | "moduleResolution": "node",
18 | "resolveJsonModule": true,
19 | "isolatedModules": true,
20 | "noEmit": true,
21 | "jsx": "react-jsx"
22 | },
23 | "include": [
24 | "src"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/test/custom/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 |
3 | import JsonServer from "../../src/index";
4 | import { ELIDE_REST_API_URL } from "../utils";
5 | import "./index.mock";
6 |
7 | axios.defaults.adapter = require("axios/lib/adapters/http");
8 |
9 | describe("custom", () => {
10 |
11 | it("correct get response", async () => {
12 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
13 | .custom({
14 | url: `${ELIDE_REST_API_URL}/group`,
15 | method: "get"
16 | });
17 |
18 | expect(response.data.data[0]["id"]).toBe("com.example.repository");
19 | expect(response.data.data[0]["type"]).toBe("group");
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/tsup.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "tsup";
2 | import { NodeResolvePlugin } from "@esbuild-plugins/node-resolve";
3 |
4 | export default defineConfig({
5 | entry: ["src/index.ts"],
6 | splitting: false,
7 | sourcemap: true,
8 | clean: false,
9 | platform: "browser",
10 | esbuildPlugins: [
11 | NodeResolvePlugin({
12 | extensions: [".js", "ts", "tsx", "jsx"],
13 | onResolved: (resolved) => {
14 | if (resolved.includes("node_modules")) {
15 | return {
16 | external: true,
17 | };
18 | }
19 | return resolved;
20 | },
21 | }),
22 | ],
23 | });
24 |
--------------------------------------------------------------------------------
/example/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "include": [
3 | "src",
4 | "types",
5 | "example/src/pages"
6 | ],
7 | "compilerOptions": {
8 | "rootDir": "./src",
9 | "baseUrl": ".",
10 | "module": "esnext",
11 | "lib": [
12 | "dom",
13 | "esnext",
14 | "DOM.Iterable"
15 | ],
16 | "importHelpers": true,
17 | "declaration": true,
18 | "sourceMap": true,
19 | "strict": true,
20 | "noImplicitReturns": true,
21 | "noFallthroughCasesInSwitch": true,
22 | "moduleResolution": "node",
23 | "jsx": "react",
24 | "esModuleInterop": true,
25 | "noEmit": true,
26 | "skipLibCheck": true,
27 | "forceConsistentCasingInFileNames": true,
28 | "allowSyntheticDefaultImports": true,
29 | }
30 | }
--------------------------------------------------------------------------------
/test/update/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 | import { ELIDE_REST_API_URL } from "../utils";
3 |
4 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
5 | .patch("/group/com.example.repository", {
6 | "data":
7 | {
8 | "type": "group",
9 | "id": "com.example.repository",
10 | "attributes": { "description": "Updated Repository Group" }
11 | }
12 | })
13 | .reply(204);
14 |
15 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
16 | .patch("/group/1004", {
17 | "data":
18 | {
19 | "type": "group",
20 | "id": "1004",
21 | "attributes": { "description": "Updated Repository Group" }
22 | }
23 | })
24 | .reply(404, { "errors": [{ "detail": "Unknown identifier 1004 for group" }] });
25 |
--------------------------------------------------------------------------------
/test/create/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 |
3 | import { ELIDE_REST_API_URL } from "../utils"
4 |
5 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
6 | .post("/group", {
7 | "data": {
8 | "type": "group",
9 | "id": "3813d589-2514-4299-ad71-3d70de40f1d3",
10 | "attributes": {
11 | "commonName": "test-group",
12 | "description": "this is a test group"
13 | }
14 | }
15 | })
16 | .reply(201, {
17 | "data": {
18 | "type": "group",
19 | "id": "3813d589-2514-4299-ad71-3d70de40f1d3",
20 | "attributes": {
21 | "commonName": "test-group",
22 | "description": "this is a test group"
23 | },
24 | "relationships": {
25 | "products": {
26 | "data": []
27 | }
28 | }
29 | }
30 | }, []
31 | );
32 |
--------------------------------------------------------------------------------
/example/src/App.tsx:
--------------------------------------------------------------------------------
1 | import { Refine } from "@pankod/refine-core";
2 | import {
3 | Layout,
4 | ReadyPage,
5 | notificationProvider,
6 | ErrorComponent,
7 | } from "@pankod/refine-antd";
8 | import routerProvider from "@pankod/refine-react-router-v6";
9 | import dataProvider from "./lib"
10 |
11 | import "@pankod/refine-antd/dist/styles.min.css";
12 | import { PostList } from "./pages/posts/list";
13 | import { PostShow } from "./pages/posts/show";
14 | import { PostEdit } from "./pages/posts/edit";
15 | import { PostCreate } from "./pages/posts/create";
16 |
17 | const App: React.FC = () => {
18 | return (
19 | }
26 | resources={[{
27 | name: "post", list: PostList, show: PostShow, edit: PostEdit, create: PostCreate
28 | }]}
29 | />
30 | );
31 | };
32 |
33 | export default App;
34 |
--------------------------------------------------------------------------------
/example/src/interfaces/index.d.ts:
--------------------------------------------------------------------------------
1 | export interface ApiResponse> {
2 | data: T
3 | meta?: Meta
4 | }
5 |
6 | export interface Entity {
7 | type: string;
8 | id?: string;
9 | attributes: A;
10 | relationships: R;
11 | }
12 |
13 | export interface Relation {
14 | data: {
15 | type: string;
16 | id: string;
17 | }
18 | }
19 |
20 | export interface Post extends Entity { }
21 | export interface Category extends Entity { }
22 |
23 | export interface PostAttributes {
24 | content: string;
25 | title: string;
26 | }
27 |
28 | export interface PostRelationships {
29 | category: Relation;
30 | }
31 |
32 | export interface CategoryAttributes {
33 | title: string;
34 | }
35 |
36 | export interface CategoryRelationships {
37 | posts: Relation[];
38 | }
39 |
40 | export interface Meta {
41 | page: Page;
42 | }
43 |
44 | export interface Page {
45 | number: number;
46 | totalRecords: number;
47 | limit: number;
48 | totalPages: number;
49 | }
--------------------------------------------------------------------------------
/test/getMany/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import JsonServer from "../../src/index";
3 | import { ELIDE_REST_API_URL } from "../utils";
4 | import "./index.mock";
5 |
6 |
7 | axios.defaults.adapter = require("axios/lib/adapters/http");
8 |
9 | describe("getMany", () => {
10 | it("correct response", async () => {
11 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
12 | .getMany({ resource: "group", ids: ["com.example.repository", "com.yahoo.elide"] });
13 |
14 | const { data } = response;
15 |
16 | expect(data[0]["id"]).toBe("com.example.repository");
17 | expect(data[1]["id"]).toBe("com.yahoo.elide");
18 | expect(response.data.length).toBe(2);
19 | });
20 |
21 | it("correct response with one item", async () => {
22 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
23 | .getMany({ resource: "group", ids: ["com.example.repository"] });
24 |
25 | const { data } = response;
26 |
27 | expect(data[0]["id"]).toBe("com.example.repository");
28 | expect(response.data.length).toBe(1);
29 | });
30 | });
31 |
--------------------------------------------------------------------------------
/test/getOne/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 | import { ELIDE_REST_API_URL } from "../utils";
3 |
4 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
5 | .get("/group/com.yahoo.elide")
6 | .reply(
7 | 200,
8 | {
9 | "type": "group",
10 | "id": "com.yahoo.elide",
11 | "attributes": {
12 | "commonName": "Elide",
13 | "description": "The magical library powering this project"
14 | },
15 | "relationships": {
16 | "products": {
17 | "data": [
18 | {
19 | "type": "product",
20 | "id": "elide-core"
21 | },
22 | {
23 | "type": "product",
24 | "id": "elide-standalone"
25 | },
26 | {
27 | "type": "product",
28 | "id": "elide-datastore-hibernate5"
29 | }
30 | ]
31 | }
32 | }
33 | }
34 | );
35 |
--------------------------------------------------------------------------------
/example/src/pages/posts/show.tsx:
--------------------------------------------------------------------------------
1 | import { useShow, useOne } from "@pankod/refine-core";
2 | import { Show, Typography } from "@pankod/refine-antd";
3 |
4 | import { Post, Category, ApiResponse } from "./../../interfaces";
5 |
6 | const { Title, Text } = Typography;
7 |
8 | export const PostShow = () => {
9 | const { queryResult } = useShow>();
10 | const { data, isLoading } = queryResult;
11 | const record = data?.data;
12 |
13 | console.log(record)
14 |
15 | const { data: categoryData } = useOne>({
16 | resource: "category",
17 | id: record?.data.relationships.category.data.id || "",
18 | queryOptions: {
19 | enabled: !!record?.data.relationships.category.data.id,
20 | },
21 | });
22 |
23 | return (
24 |
25 | Title
26 | {record?.data.attributes.title}
27 | Content
28 | {record?.data.attributes.content}
29 | Category
30 | {categoryData?.data.data.attributes.title}
31 |
32 | );
33 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "elide-simple-rest",
3 | "description": "Elide simple REST data provider for refine.",
4 | "version": "0.0.2",
5 | "license": "MIT",
6 | "main": "dist/index.js",
7 | "typings": "dist/index.d.ts",
8 | "private": false,
9 | "files": [
10 | "dist",
11 | "src"
12 | ],
13 | "engines": {
14 | "node": ">=10"
15 | },
16 | "scripts": {
17 | "start": "tsup --watch --dts --format esm,cjs,iife --legacy-output",
18 | "build": "tsup --dts --format esm,cjs,iife --minify --legacy-output",
19 | "test": "jest --passWithNoTests --runInBand",
20 | "prepare": "npm run build"
21 | },
22 | "author": "Chirdeep Tomar",
23 | "module": "dist/esm/index.js",
24 | "devDependencies": {
25 | "@pankod/refine-core": "^3.18.0",
26 | "@esbuild-plugins/node-resolve": "^0.1.4",
27 | "@types/jest": "^27.5.1",
28 | "jest": "^27.5.1",
29 | "nock": "^13.1.3",
30 | "ts-jest": "^27.1.3",
31 | "tslib": "^2.3.1",
32 | "tsup": "^5.11.13"
33 | },
34 | "peerDependencies": {
35 | "@pankod/refine-core": "^3.18.0"
36 | },
37 | "dependencies": {
38 | "axios": "^0.27.2",
39 | "query-string": "^7.0.1"
40 | },
41 | "publishConfig": {
42 | "access": "public"
43 | }
44 | }
--------------------------------------------------------------------------------
/test/create/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import JsonServer from "../../src/index";
3 | import { ELIDE_REST_API_URL } from "../utils";
4 | import "./index.mock";
5 |
6 |
7 | axios.defaults.adapter = require("axios/lib/adapters/http");
8 |
9 | describe("create", () => {
10 |
11 | it("correct response", async () => {
12 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
13 | .create({
14 | resource: "group",
15 | variables: {
16 | data: {
17 | id: "3813d589-2514-4299-ad71-3d70de40f1d3",
18 | type: "group",
19 | attributes: {
20 | "commonName": "test-group",
21 | "description": "this is a test group"
22 | }
23 | }
24 | },
25 | })
26 |
27 | const { data } = response;
28 |
29 | expect(data["id"]).toBe("3813d589-2514-4299-ad71-3d70de40f1d3")
30 | expect(data["type"]).toBe("group")
31 | expect(data["attributes"]["commonName"]).toBe("test-group")
32 | expect(data["attributes"]["description"]).toBe("this is a test group")
33 | });
34 | });
35 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@pankod/refine-antd": "^3.62.0",
7 | "@pankod/refine-core": "^3.88.0",
8 | "@pankod/refine-react-router-v6": "^3.36.2",
9 | "@testing-library/jest-dom": "^5.16.5",
10 | "@testing-library/react": "^13.4.0",
11 | "@testing-library/user-event": "^13.5.0",
12 | "@types/jest": "^27.5.2",
13 | "@types/node": "^16.18.3",
14 | "@types/react": "^18.0.24",
15 | "@types/react-dom": "^18.0.8",
16 | "elide-simple-rest": "^0.0.1",
17 | "react": "^18.2.0",
18 | "react-dom": "^18.2.0",
19 | "react-scripts": "5.0.1",
20 | "typescript": "^4.8.4",
21 | "web-vitals": "^2.1.4"
22 | },
23 | "scripts": {
24 | "start": "react-scripts start",
25 | "build": "react-scripts build",
26 | "test": "react-scripts test",
27 | "eject": "react-scripts eject"
28 | },
29 | "eslintConfig": {
30 | "extends": [
31 | "react-app",
32 | "react-app/jest"
33 | ]
34 | },
35 | "browserslist": {
36 | "production": [
37 | ">0.2%",
38 | "not dead",
39 | "not op_mini all"
40 | ],
41 | "development": [
42 | "last 1 chrome version",
43 | "last 1 firefox version",
44 | "last 1 safari version"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/test/update/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import JsonServer from "../../src/index";
3 | import { ELIDE_REST_API_URL } from "../utils";
4 | import "./index.mock";
5 |
6 |
7 | axios.defaults.adapter = require("axios/lib/adapters/http");
8 |
9 | describe("update", () => {
10 | it("correct response", async () => {
11 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
12 | .update({
13 | resource: "group",
14 | id: "com.example.repository",
15 | variables: {
16 | data: {
17 | type: "group",
18 | id: "com.example.repository",
19 | attributes: { description: "Updated Repository Group" }
20 | }
21 | },
22 | });
23 |
24 | const { data } = response;
25 |
26 | expect(data).toBe("")
27 | });
28 |
29 | it("correct error response", async () => {
30 | const response = await JsonServer(ELIDE_REST_API_URL, axios)
31 | .update({
32 | resource: "group",
33 | id: "1004",
34 | variables: {
35 | data: {
36 | type: "group",
37 | id: "1004",
38 | attributes: { description: "Updated Repository Group" }
39 | }
40 | },
41 | });
42 |
43 | const { data } = response;
44 |
45 | expect(data).toStrictEqual({ "errors": [{ "detail": "Unknown identifier 1004 for group" }] })
46 | });
47 | });
48 |
--------------------------------------------------------------------------------
/example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/test/custom/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 | import { ELIDE_REST_API_URL } from "../utils";
3 |
4 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
5 | .get("/group")
6 | .reply(
7 | 200,
8 | {
9 | "data": [
10 | {
11 | "type": "group",
12 | "id": "com.example.repository",
13 | "attributes": {
14 | "commonName": "string",
15 | "description": "string"
16 | },
17 | "relationships": {
18 | "products": {
19 | "data": []
20 | }
21 | }
22 | },
23 | {
24 | "type": "group",
25 | "id": "com.yahoo.elide",
26 | "attributes": {
27 | "commonName": "Elide",
28 | "description": "The magical library powering this project"
29 | },
30 | "relationships": {
31 | "products": {
32 | "data": [
33 | {
34 | "type": "product",
35 | "id": "elide-core"
36 | },
37 | {
38 | "type": "product",
39 | "id": "elide-standalone"
40 | },
41 | {
42 | "type": "product",
43 | "id": "elide-datastore-hibernate5"
44 | }
45 | ]
46 | }
47 | }
48 | }
49 | ]
50 | }
51 | );
52 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13 |
14 | The page will reload if you make edits.\
15 | You will also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35 |
36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39 |
40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
--------------------------------------------------------------------------------
/example/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/getMany/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 | import { ELIDE_REST_API_URL } from "../utils";
3 |
4 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
5 | .get("/group?filter[group]=id=in=(com.example.repository,com.yahoo.elide)")
6 | .reply(
7 | 200,
8 | {
9 | "data": [
10 | {
11 | "type": "group",
12 | "id": "com.example.repository",
13 | "attributes": {
14 | "commonName": "Example Repository",
15 | "description": "Updated Repository Group"
16 | },
17 | "relationships": {
18 | "products": {
19 | "data": []
20 | }
21 | }
22 | },
23 | {
24 | "type": "group",
25 | "id": "com.yahoo.elide",
26 | "attributes": {
27 | "commonName": "Elide",
28 | "description": "The magical library powering this project"
29 | },
30 | "relationships": {
31 | "products": {
32 | "data": [
33 | {
34 | "type": "product",
35 | "id": "elide-core"
36 | },
37 | {
38 | "type": "product",
39 | "id": "elide-standalone"
40 | },
41 | {
42 | "type": "product",
43 | "id": "elide-datastore-hibernate5"
44 | }
45 | ]
46 | }
47 | }
48 | }
49 | ]
50 | }
51 | );
52 |
53 | nock(ELIDE_REST_API_URL, { encodedQueryParams: true })
54 | .get("/group?filter[group]=id=in=(com.example.repository)")
55 | .reply(
56 | 200,
57 | {
58 | "data": [
59 | {
60 | "type": "group",
61 | "id": "com.example.repository",
62 | "attributes": {
63 | "commonName": "Example Repository",
64 | "description": "Updated Repository Group"
65 | },
66 | "relationships": {
67 | "products": {
68 | "data": []
69 | }
70 | }
71 | }
72 | ]
73 | }
74 | );
75 |
--------------------------------------------------------------------------------
/example/src/pages/posts/create.tsx:
--------------------------------------------------------------------------------
1 | import {
2 | Create,
3 | Form,
4 | Input,
5 | Select,
6 | useForm,
7 | useSelect,
8 | } from "@pankod/refine-antd";
9 | import { HttpError } from "@pankod/refine-core";
10 |
11 | import { Category, Post } from "./../../interfaces";
12 |
13 |
14 | export const PostCreate = () => {
15 | const { formProps, saveButtonProps } = useForm();
16 | const { selectProps: categorySelectProps } = useSelect({
17 | resource: "category",
18 | optionLabel: "attributes.title",
19 | optionValue: "id"
20 | });
21 |
22 | return (
23 |
24 |
56 |
57 |
58 |
67 |
68 |
69 |
78 |
79 |
80 |
81 |
82 | );
83 | };
--------------------------------------------------------------------------------
/example/src/pages/posts/edit.tsx:
--------------------------------------------------------------------------------
1 | import {
2 | useForm,
3 | Form,
4 | Input,
5 | Select,
6 | Edit,
7 | useSelect,
8 | } from "@pankod/refine-antd";
9 | import { HttpError } from "@pankod/refine-core";
10 | import { Category, Post } from "./../../interfaces";
11 |
12 | export const PostEdit: React.FC = () => {
13 | const { formProps, saveButtonProps, queryResult } = useForm<{ data: Post }, HttpError, { data: Post }>();
14 |
15 | const { selectProps: categorySelectProps } = useSelect({
16 | resource: "category",
17 | optionLabel: "attributes.title",
18 | optionValue: "id",
19 | defaultValue: queryResult?.data?.data?.data.relationships?.category.data.id,
20 | });
21 |
22 | return (
23 |
24 |
57 |
58 |
59 |
68 |
69 |
70 |
79 |
80 |
81 |
82 |
83 | );
84 | };
--------------------------------------------------------------------------------
/test/getList/index.spec.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | import JsonServer from "../../src/index";
3 | import { ELIDE_REST_API_URL } from "../utils";
4 | import "./index.mock";
5 |
6 | axios.defaults.adapter = require("axios/lib/adapters/http");
7 |
8 | describe("getList", () => {
9 | it("correct response", async () => {
10 | const response = await JsonServer(ELIDE_REST_API_URL, axios).getList({ resource: "group" });
11 | expect(response.data[0]["id"]).toBe("com.example.repository");
12 | expect(response.data[0]["attributes"]["commonName"]).toBe("Example Repository");
13 | expect(response.total).toBe(2);
14 | });
15 |
16 | it("correct sorting asc response", async () => {
17 | const response = await JsonServer(
18 | ELIDE_REST_API_URL,
19 | axios,
20 | ).getList({
21 | resource: "group",
22 | sort: [
23 | {
24 | field: "id",
25 | order: "asc",
26 | },
27 | ],
28 | });
29 |
30 | expect(response.data[0]["id"]).toBe("com.example.repository");
31 | expect(response.data[0]["attributes"]["commonName"]).toBe("Example Repository");
32 | expect(response.total).toBe(2);
33 | });
34 |
35 | it("correct sorting desc response", async () => {
36 | const response = await JsonServer(
37 | ELIDE_REST_API_URL,
38 | axios,
39 | ).getList({
40 | resource: "group",
41 | sort: [
42 | {
43 | field: "id",
44 | order: "desc",
45 | },
46 | ],
47 | });
48 |
49 | expect(response.data[0]["id"]).toBe("com.yahoo.elide");
50 | expect(response.data[0]["attributes"]["commonName"]).toBe("Elide");
51 | expect(response.total).toBe(2);
52 | });
53 |
54 | it("correct filter response", async () => {
55 | const response = await JsonServer(
56 | ELIDE_REST_API_URL,
57 | axios,
58 | ).getList({
59 | resource: "group",
60 | filters: [
61 | {
62 | field: "id",
63 | operator: "eq",
64 | value: ["com.yahoo.elide"],
65 | },
66 | ],
67 | });
68 |
69 | expect(response.data[0]["id"]).toBe("com.yahoo.elide");
70 | expect(response.total).toBe(1);
71 | });
72 |
73 | it("correct filter and sort response", async () => {
74 | const response = await JsonServer(
75 | ELIDE_REST_API_URL,
76 | axios,
77 | ).getList({
78 | resource: "group",
79 | filters: [
80 | {
81 | field: "id",
82 | operator: "eq",
83 | value: ["com.yahoo.elide"],
84 | },
85 | ],
86 | sort: [
87 | {
88 | field: "id",
89 | order: "asc",
90 | },
91 | ],
92 | });
93 |
94 | expect(response.data[0]["id"]).toBe("com.yahoo.elide");
95 | expect(response.total).toBe(1);
96 | });
97 | });
98 |
--------------------------------------------------------------------------------
/example/src/pages/posts/list.tsx:
--------------------------------------------------------------------------------
1 | import {
2 | List,
3 | Table,
4 | useTable,
5 | TextField,
6 | FilterDropdown,
7 | Select,
8 | ShowButton,
9 | EditButton,
10 | Space,
11 | useSelect,
12 | DeleteButton,
13 | } from "@pankod/refine-antd";
14 | import { useMany } from "@pankod/refine-core";
15 |
16 | import { Category, Post } from "../../interfaces";
17 |
18 | export const PostList: React.FC = () => {
19 | const { tableProps } = useTable()
20 |
21 | const categoryIds =
22 | tableProps?.dataSource?.map((item) => item?.relationships.category.data.id) ?? [];
23 |
24 | const { data: categories, isLoading } = useMany({
25 | resource: "category",
26 | ids: categoryIds,
27 | queryOptions: {
28 | enabled: categoryIds.length > 0,
29 | },
30 | });
31 |
32 | const { selectProps: categorySelectProps } = useSelect({
33 | resource: "category",
34 | optionLabel: "attributes.title",
35 | optionValue: "id"
36 | });
37 |
38 | return (
39 |
40 |
41 |
42 |
43 | {
47 | if (isLoading) {
48 | return ;
49 | }
50 |
51 | return (
52 | item.id === value,
56 | )?.attributes.title
57 | }
58 | />
59 | );
60 | }}
61 | filterDropdown={(props) => (
62 |
63 |
69 |
70 | )}
71 | />
72 |
73 | title="Actions"
74 | dataIndex="actions"
75 | render={(_text, record): React.ReactNode => {
76 | return (
77 |
78 |
83 |
88 |
93 |
94 | );
95 | }}
96 | />
97 |
98 |
99 | );
100 | };
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,webstorm,node
3 | # Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,webstorm,node
4 |
5 | ### Node ###
6 | # Logs
7 | logs
8 | *.log
9 | npm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 | lerna-debug.log*
13 | .pnpm-debug.log*
14 |
15 | # Diagnostic reports (https://nodejs.org/api/report.html)
16 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17 |
18 | # Runtime data
19 | pids
20 | *.pid
21 | *.seed
22 | *.pid.lock
23 |
24 | # Directory for instrumented libs generated by jscoverage/JSCover
25 | lib-cov
26 |
27 | # Coverage directory used by tools like istanbul
28 | coverage
29 | *.lcov
30 |
31 | # nyc test coverage
32 | .nyc_output
33 |
34 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35 | .grunt
36 |
37 | # Bower dependency directory (https://bower.io/)
38 | bower_components
39 |
40 | # node-waf configuration
41 | .lock-wscript
42 |
43 | # Compiled binary addons (https://nodejs.org/api/addons.html)
44 | build/Release
45 |
46 | # Dependency directories
47 | node_modules/
48 | jspm_packages/
49 |
50 | # Snowpack dependency directory (https://snowpack.dev/)
51 | web_modules/
52 |
53 | # TypeScript cache
54 | *.tsbuildinfo
55 |
56 | # Optional npm cache directory
57 | .npm
58 |
59 | # Optional eslint cache
60 | .eslintcache
61 |
62 | # Optional stylelint cache
63 | .stylelintcache
64 |
65 | # Microbundle cache
66 | .rpt2_cache/
67 | .rts2_cache_cjs/
68 | .rts2_cache_es/
69 | .rts2_cache_umd/
70 |
71 | # Optional REPL history
72 | .node_repl_history
73 |
74 | # Output of 'npm pack'
75 | *.tgz
76 |
77 | # Yarn Integrity file
78 | .yarn-integrity
79 |
80 | # dotenv environment variable files
81 | .env
82 | .env.development.local
83 | .env.test.local
84 | .env.production.local
85 | .env.local
86 |
87 | # parcel-bundler cache (https://parceljs.org/)
88 | .cache
89 | .parcel-cache
90 |
91 | # Next.js build output
92 | .next
93 | out
94 |
95 | # Nuxt.js build / generate output
96 | .nuxt
97 | dist
98 |
99 | # Gatsby files
100 | .cache/
101 | # Comment in the public line in if your project uses Gatsby and not Next.js
102 | # https://nextjs.org/blog/next-9-1#public-directory-support
103 | # public
104 |
105 | # vuepress build output
106 | .vuepress/dist
107 |
108 | # vuepress v2.x temp and cache directory
109 | .temp
110 |
111 | # Docusaurus cache and generated files
112 | .docusaurus
113 |
114 | # Serverless directories
115 | .serverless/
116 |
117 | # FuseBox cache
118 | .fusebox/
119 |
120 | # DynamoDB Local files
121 | .dynamodb/
122 |
123 | # TernJS port file
124 | .tern-port
125 |
126 | # Stores VSCode versions used for testing VSCode extensions
127 | .vscode-test
128 |
129 | # yarn v2
130 | .yarn/cache
131 | .yarn/unplugged
132 | .yarn/build-state.yml
133 | .yarn/install-state.gz
134 | .pnp.*
135 |
136 | ### Node Patch ###
137 | # Serverless Webpack directories
138 | .webpack/
139 |
140 | # Optional stylelint cache
141 |
142 | # SvelteKit build / generate output
143 | .svelte-kit
144 |
145 | ### VisualStudioCode ###
146 | .vscode/*
147 | !.vscode/settings.json
148 | !.vscode/tasks.json
149 | !.vscode/launch.json
150 | !.vscode/extensions.json
151 | !.vscode/*.code-snippets
152 |
153 | # Local History for Visual Studio Code
154 | .history/
155 |
156 | # Built Visual Studio Code Extensions
157 | *.vsix
158 |
159 | ### VisualStudioCode Patch ###
160 | # Ignore all local history of files
161 | .history
162 | .ionide
163 |
164 | # Support for Project snippet scope
165 | .vscode/*.code-snippets
166 |
167 | # Ignore code-workspaces
168 | *.code-workspace
169 |
170 | ### WebStorm ###
171 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
172 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
173 |
174 | # User-specific stuff
175 | .idea/**/workspace.xml
176 | .idea/**/tasks.xml
177 | .idea/**/usage.statistics.xml
178 | .idea/**/dictionaries
179 | .idea/**/shelf
180 |
181 | # AWS User-specific
182 | .idea/**/aws.xml
183 |
184 | # Generated files
185 | .idea/**/contentModel.xml
186 |
187 | # Sensitive or high-churn files
188 | .idea/**/dataSources/
189 | .idea/**/dataSources.ids
190 | .idea/**/dataSources.local.xml
191 | .idea/**/sqlDataSources.xml
192 | .idea/**/dynamic.xml
193 | .idea/**/uiDesigner.xml
194 | .idea/**/dbnavigator.xml
195 |
196 | # Gradle
197 | .idea/**/gradle.xml
198 | .idea/**/libraries
199 |
200 | # Gradle and Maven with auto-import
201 | # When using Gradle or Maven with auto-import, you should exclude module files,
202 | # since they will be recreated, and may cause churn. Uncomment if using
203 | # auto-import.
204 | # .idea/artifacts
205 | # .idea/compiler.xml
206 | # .idea/jarRepositories.xml
207 | # .idea/modules.xml
208 | # .idea/*.iml
209 | # .idea/modules
210 | # *.iml
211 | # *.ipr
212 |
213 | # CMake
214 | cmake-build-*/
215 |
216 | # Mongo Explorer plugin
217 | .idea/**/mongoSettings.xml
218 |
219 | # File-based project format
220 | *.iws
221 |
222 | # IntelliJ
223 | out/
224 |
225 | # mpeltonen/sbt-idea plugin
226 | .idea_modules/
227 |
228 | # JIRA plugin
229 | atlassian-ide-plugin.xml
230 |
231 | # Cursive Clojure plugin
232 | .idea/replstate.xml
233 |
234 | # SonarLint plugin
235 | .idea/sonarlint/
236 |
237 | # Crashlytics plugin (for Android Studio and IntelliJ)
238 | com_crashlytics_export_strings.xml
239 | crashlytics.properties
240 | crashlytics-build.properties
241 | fabric.properties
242 |
243 | # Editor-based Rest Client
244 | .idea/httpRequests
245 |
246 | # Android studio 3.1+ serialized cache file
247 | .idea/caches/build_file_checksums.ser
248 |
249 | ### WebStorm Patch ###
250 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
251 |
252 | # *.iml
253 | # modules.xml
254 | # .idea/misc.xml
255 | # *.ipr
256 |
257 | # Sonarlint plugin
258 | # https://plugins.jetbrains.com/plugin/7973-sonarlint
259 | .idea/**/sonarlint/
260 |
261 | # SonarQube Plugin
262 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
263 | .idea/**/sonarIssues.xml
264 |
265 | # Markdown Navigator plugin
266 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
267 | .idea/**/markdown-navigator.xml
268 | .idea/**/markdown-navigator-enh.xml
269 | .idea/**/markdown-navigator/
270 |
271 | # Cache file creation bug
272 | # See https://youtrack.jetbrains.com/issue/JBR-2257
273 | .idea/$CACHE_FILE$
274 |
275 | # CodeStream plugin
276 | # https://plugins.jetbrains.com/plugin/12206-codestream
277 | .idea/codestream.xml
278 |
279 | # Azure Toolkit for IntelliJ plugin
280 | # https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
281 | .idea/**/azureSettings.xml
282 |
283 | # End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,webstorm,node
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | CrudFilters, CrudOperators, CrudSorting, DataProvider,
3 | HttpError
4 | } from "@pankod/refine-core";
5 | import axios, { AxiosError, AxiosInstance } from "axios";
6 |
7 | const axiosInstance = axios.create();
8 |
9 | axiosInstance.interceptors.response.use(
10 | (response) => {
11 | return response;
12 | },
13 | (error) => {
14 | const customError: HttpError = {
15 | ...error,
16 | message: error.response?.data?.message,
17 | statusCode: error.response?.status,
18 | };
19 |
20 | return Promise.reject(customError);
21 | },
22 | );
23 |
24 | const mapOperator = (operator: CrudOperators): string => {
25 | switch (operator) {
26 | case "ne":
27 | case "gte":
28 | case "lte":
29 | return `_${operator}`;
30 | case "contains":
31 | case "eq":
32 | default:
33 | return "==";
34 | }
35 | };
36 |
37 | const generateSort = (sort?: CrudSorting) => {
38 | if (sort && sort.length > 0) {
39 | let sortQueryParams: string = "sort="
40 | sort.forEach((item) => {
41 | if (item !== undefined && item.field !== "attributes") {
42 | const sortField = item.field.replace("attributes,", "")
43 | sortQueryParams += (item.order === "desc" ? `-${sortField}` : sortField) + ","
44 | }
45 | })
46 | return sortQueryParams;
47 | }
48 |
49 | return "";
50 | };
51 |
52 | const generateFilter = (resource: string, filters?: CrudFilters) => {
53 |
54 | let queryFilters: string = '';
55 | if (filters) {
56 | filters.forEach((filter: any) => {
57 | if (filter.operator !== "or") {
58 | const { field, value } = filter;
59 | let modifiedField = field.toString().replace("relationships.", "")
60 | modifiedField = modifiedField.toString().replace("data.", "")
61 |
62 | const filterField = modifiedField ? modifiedField : field;
63 |
64 | // ?filter[book]=genre=='Science Fiction';title=='The Red Giant'
65 | if (queryFilters.includes(`filter`)) {
66 | queryFilters = queryFilters + `;${filterField}=ini=(${value})`
67 | } else {
68 | queryFilters = queryFilters + `filter=${filterField}=ini=(${value})`
69 | }
70 | }
71 | });
72 | }
73 |
74 | return queryFilters;
75 | };
76 |
77 | const JsonServer = (
78 | apiUrl: string,
79 | httpClient: AxiosInstance = axiosInstance,
80 | ): Omit, "updateMany" | "deleteMany"> => ({
81 | getList: async ({ resource, pagination, filters, sort }) => {
82 | const url = `${apiUrl}/${resource}`;
83 | // pagination
84 | const current = pagination?.current || 1;
85 | const pageSize = pagination?.pageSize || 10;
86 |
87 | const queryFilters = generateFilter(resource, filters);
88 |
89 | const query: {
90 | _start: number;
91 | _end: number;
92 | _sort?: string;
93 | _order?: string;
94 | } = {
95 | _start: (current - 1) * pageSize,
96 | _end: current * pageSize,
97 | };
98 |
99 | const generatedSort = generateSort(sort);
100 |
101 | const page = `page[offset]=${query._start}&page[limit]=${pageSize}&page[totals]&${generatedSort}`
102 | const formedQuery = `${url}?${page}&${queryFilters}`
103 | const { data } = await httpClient.get(formedQuery)
104 | return {
105 | data: data.data,
106 | total: data.meta.page.totalRecords,
107 | };
108 | },
109 |
110 | getMany: async ({ resource, ids }) => {
111 | const inQuery = `filter[${resource}]=id=in=(${ids})`
112 | const { data } = await httpClient.get(
113 | `${apiUrl}/${resource}?${inQuery}`,
114 | );
115 |
116 | return {
117 | data: data.data,
118 | };
119 | },
120 |
121 | create: async ({ resource, variables }) => {
122 | const url = `${apiUrl}/${resource}`;
123 | const { data } = await httpClient.post(url, { ...variables },
124 | {
125 | headers: {
126 | "accept": "application/vnd.api+json",
127 | "content-type": "application/vnd.api+json"
128 | }
129 | });
130 |
131 | return {
132 | data: data.data,
133 | };
134 | },
135 |
136 | createMany: async ({ resource, variables }) => {
137 | const response = await Promise.all(
138 | variables.map(async (param) => {
139 | const { data } = await httpClient.post(
140 | `${apiUrl}/${resource}`,
141 | param,
142 | );
143 | return data;
144 | }),
145 | );
146 |
147 | return { data: response };
148 | },
149 |
150 | update: async ({ resource, id, variables }) => {
151 | const url = `${apiUrl}/${resource}/${id}`;
152 |
153 | try {
154 | const { data } = await httpClient.patch(url, { ...variables },
155 | {
156 | headers: {
157 | "accept": "application/vnd.api+json",
158 | "content-type": "application/vnd.api+json"
159 | }
160 | });
161 |
162 | return {
163 | data
164 | }
165 | } catch (error) {
166 | const err = error as AxiosError
167 | return { data: err.response?.data }
168 | }
169 | },
170 |
171 | getOne: async ({ resource, id }) => {
172 | const url = `${apiUrl}/${resource}/${id}`;
173 |
174 | const { data } = await httpClient.get(url);
175 |
176 | return {
177 | data: data
178 | };
179 | },
180 |
181 | deleteOne: async ({ resource, id }) => {
182 | const url = `${apiUrl}/${resource}/${id}`;
183 |
184 | const { data } = await httpClient.delete(url);
185 |
186 | return {
187 | data
188 | };
189 | },
190 |
191 | getApiUrl: () => {
192 | return apiUrl;
193 | },
194 |
195 | custom: async ({ url, method, filters, sort, payload, query, headers }) => {
196 |
197 | if (headers) {
198 | httpClient.defaults.headers = {
199 | ...httpClient.defaults.headers,
200 | ...headers,
201 | };
202 | }
203 |
204 | let axiosResponse;
205 | switch (method) {
206 | case "put":
207 | case "post":
208 | case "patch":
209 | axiosResponse = httpClient[method](url, payload);
210 | break;
211 | case "delete":
212 | axiosResponse = httpClient.delete(url);
213 | break;
214 | default:
215 | axiosResponse = httpClient.get(url);
216 | break;
217 | }
218 |
219 | const { data } = await axiosResponse;
220 |
221 | return { data };
222 | },
223 | });
224 |
225 | export default JsonServer;
226 |
--------------------------------------------------------------------------------
/example/src/lib/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | CrudFilters, CrudOperators, CrudSorting, DataProvider,
3 | HttpError
4 | } from "@pankod/refine-core";
5 | import axios, { AxiosError, AxiosInstance } from "axios";
6 |
7 | const axiosInstance = axios.create();
8 |
9 | axiosInstance.interceptors.response.use(
10 | (response) => {
11 | return response;
12 | },
13 | (error) => {
14 | const customError: HttpError = {
15 | ...error,
16 | message: error.response?.data?.message,
17 | statusCode: error.response?.status,
18 | };
19 |
20 | return Promise.reject(customError);
21 | },
22 | );
23 |
24 | const mapOperator = (operator: CrudOperators): string => {
25 | switch (operator) {
26 | case "ne":
27 | case "gte":
28 | case "lte":
29 | return `_${operator}`;
30 | case "contains":
31 | case "eq":
32 | default:
33 | return "==";
34 | }
35 | };
36 |
37 | const generateSort = (sort?: CrudSorting) => {
38 | if (sort && sort.length > 0) {
39 | let sortQueryParams: string = "sort="
40 | sort.forEach((item) => {
41 | if (item !== undefined && item.field !== "attributes") {
42 | const sortField = item.field.replace("attributes,", "")
43 | sortQueryParams += (item.order === "desc" ? `-${sortField}` : sortField) + ","
44 | }
45 | })
46 | return sortQueryParams;
47 | }
48 |
49 | return "";
50 | };
51 |
52 | const generateFilter = (resource: string, filters?: CrudFilters) => {
53 |
54 | let queryFilters: string = '';
55 | if (filters) {
56 | filters.forEach((filter: any) => {
57 | if (filter.operator !== "or") {
58 | const { field, value } = filter;
59 | let modifiedField = field.toString().replace("relationships.", "")
60 | modifiedField = modifiedField.toString().replace("data.", "")
61 |
62 | const filterField = modifiedField ? modifiedField : field;
63 |
64 | // ?filter[book]=genre=='Science Fiction';title=='The Red Giant'
65 | if (queryFilters.includes(`filter`)) {
66 | queryFilters = queryFilters + `;${filterField}=ini=(${value})`
67 | } else {
68 | queryFilters = queryFilters + `filter=${filterField}=ini=(${value})`
69 | }
70 | }
71 | });
72 | }
73 |
74 | return queryFilters;
75 | };
76 |
77 | const JsonServer = (
78 | apiUrl: string,
79 | httpClient: AxiosInstance = axiosInstance,
80 | ): Omit, "updateMany" | "deleteMany"> => ({
81 | getList: async ({ resource, pagination, filters, sort }) => {
82 | const url = `${apiUrl}/${resource}`;
83 | // pagination
84 | const current = pagination?.current || 1;
85 | const pageSize = pagination?.pageSize || 10;
86 |
87 | const queryFilters = generateFilter(resource, filters);
88 |
89 | const query: {
90 | _start: number;
91 | _end: number;
92 | _sort?: string;
93 | _order?: string;
94 | } = {
95 | _start: (current - 1) * pageSize,
96 | _end: current * pageSize,
97 | };
98 |
99 | const generatedSort = generateSort(sort);
100 |
101 | const page = `page[offset]=${query._start}&page[limit]=${pageSize}&page[totals]&${generatedSort}`
102 | const formedQuery = `${url}?${page}&${queryFilters}`
103 | const { data } = await httpClient.get(formedQuery)
104 | return {
105 | data: data.data,
106 | total: data.meta.page.totalRecords,
107 | };
108 | },
109 |
110 | getMany: async ({ resource, ids }) => {
111 | const inQuery = `filter[${resource}]=id=in=(${ids})`
112 | const { data } = await httpClient.get(
113 | `${apiUrl}/${resource}?${inQuery}`,
114 | );
115 |
116 | return {
117 | data: data.data,
118 | };
119 | },
120 |
121 | create: async ({ resource, variables }) => {
122 | const url = `${apiUrl}/${resource}`;
123 | const { data } = await httpClient.post(url, { ...variables },
124 | {
125 | headers: {
126 | "accept": "application/vnd.api+json",
127 | "content-type": "application/vnd.api+json"
128 | }
129 | });
130 |
131 | return {
132 | data: data.data,
133 | };
134 | },
135 |
136 | createMany: async ({ resource, variables }) => {
137 | const response = await Promise.all(
138 | variables.map(async (param) => {
139 | const { data } = await httpClient.post(
140 | `${apiUrl}/${resource}`,
141 | param,
142 | );
143 | return data;
144 | }),
145 | );
146 |
147 | return { data: response };
148 | },
149 |
150 | update: async ({ resource, id, variables }) => {
151 | const url = `${apiUrl}/${resource}/${id}`;
152 |
153 | try {
154 | const { data } = await httpClient.patch(url, { ...variables },
155 | {
156 | headers: {
157 | "accept": "application/vnd.api+json",
158 | "content-type": "application/vnd.api+json"
159 | }
160 | });
161 |
162 | return {
163 | data
164 | }
165 | } catch (error) {
166 | const err = error as AxiosError
167 | return { data: err.response?.data }
168 | }
169 | },
170 |
171 | getOne: async ({ resource, id }) => {
172 | const url = `${apiUrl}/${resource}/${id}`;
173 |
174 | const { data } = await httpClient.get(url);
175 |
176 | return {
177 | data: data
178 | };
179 | },
180 |
181 | deleteOne: async ({ resource, id }) => {
182 | const url = `${apiUrl}/${resource}/${id}`;
183 |
184 | const { data } = await httpClient.delete(url);
185 |
186 | return {
187 | data
188 | };
189 | },
190 |
191 | getApiUrl: () => {
192 | return apiUrl;
193 | },
194 |
195 | custom: async ({ url, method, filters, sort, payload, query, headers }) => {
196 |
197 | if (headers) {
198 | httpClient.defaults.headers = {
199 | ...httpClient.defaults.headers,
200 | ...headers,
201 | };
202 | }
203 |
204 | let axiosResponse;
205 | switch (method) {
206 | case "put":
207 | case "post":
208 | case "patch":
209 | axiosResponse = httpClient[method](url, payload);
210 | break;
211 | case "delete":
212 | axiosResponse = httpClient.delete(url);
213 | break;
214 | default:
215 | axiosResponse = httpClient.get(url);
216 | break;
217 | }
218 |
219 | const { data } = await axiosResponse;
220 |
221 | return { data };
222 | },
223 | });
224 |
225 | export default JsonServer;
226 |
--------------------------------------------------------------------------------
/test/getList/index.mock.ts:
--------------------------------------------------------------------------------
1 | import nock from "nock";
2 | import { ELIDE_REST_API_URL } from "../utils";
3 |
4 | nock(ELIDE_REST_API_URL)
5 | .get("/group?page[offset]=0&page[limit]=10&page[totals]&&")
6 | .reply(
7 | 200,
8 | {
9 | "data": [
10 | {
11 | "type": "group",
12 | "id": "com.example.repository",
13 | "attributes": {
14 | "commonName": "Example Repository",
15 | "description": "Updated Repository Group"
16 | },
17 | "relationships": {
18 | "products": {
19 | "data": []
20 | }
21 | }
22 | },
23 | {
24 | "type": "group",
25 | "id": "com.yahoo.elide",
26 | "attributes": {
27 | "commonName": "Elide",
28 | "description": "The magical library powering this project"
29 | },
30 | "relationships": {
31 | "products": {
32 | "data": [
33 | {
34 | "type": "product",
35 | "id": "elide-core"
36 | },
37 | {
38 | "type": "product",
39 | "id": "elide-standalone"
40 | },
41 | {
42 | "type": "product",
43 | "id": "elide-datastore-hibernate5"
44 | }
45 | ]
46 | }
47 | }
48 | }
49 | ],
50 | "meta": {
51 | "page": {
52 | "number": 1,
53 | "totalRecords": 2,
54 | "limit": 10,
55 | "totalPages": 1
56 | }
57 | }
58 | }
59 | );
60 |
61 | nock("http://localhost:8080/api/v1")
62 | .get("/group?page[offset]=0&page[limit]=10&page[totals]&sort=id,&")
63 | .reply(
64 | 200,
65 | {
66 | "data": [
67 | {
68 | "type": "group",
69 | "id": "com.example.repository",
70 | "attributes": {
71 | "commonName": "Example Repository",
72 | "description": "Updated Repository Group"
73 | },
74 | "relationships": {
75 | "products": {
76 | "data": []
77 | }
78 | }
79 | },
80 | {
81 | "type": "group",
82 | "id": "com.yahoo.elide",
83 | "attributes": {
84 | "commonName": "Elide",
85 | "description": "The magical library powering this project"
86 | },
87 | "relationships": {
88 | "products": {
89 | "data": [
90 | {
91 | "type": "product",
92 | "id": "elide-core"
93 | },
94 | {
95 | "type": "product",
96 | "id": "elide-standalone"
97 | },
98 | {
99 | "type": "product",
100 | "id": "elide-datastore-hibernate5"
101 | }
102 | ]
103 | }
104 | }
105 | }
106 | ],
107 | "meta": {
108 | "page": {
109 | "number": 1,
110 | "totalRecords": 2,
111 | "limit": 10,
112 | "totalPages": 1
113 | }
114 | }
115 | }
116 | );
117 |
118 | nock("http://localhost:8080/api/v1")
119 | .get("/group?page[offset]=0&page[limit]=10&page[totals]&sort=-id,&")
120 | .reply(
121 | 200,
122 | {
123 | "data": [
124 | {
125 | "type": "group",
126 | "id": "com.yahoo.elide",
127 | "attributes": {
128 | "commonName": "Elide",
129 | "description": "The magical library powering this project"
130 | },
131 | "relationships": {
132 | "products": {
133 | "data": [
134 | {
135 | "type": "product",
136 | "id": "elide-core"
137 | },
138 | {
139 | "type": "product",
140 | "id": "elide-standalone"
141 | },
142 | {
143 | "type": "product",
144 | "id": "elide-datastore-hibernate5"
145 | }
146 | ]
147 | }
148 | }
149 | },
150 | {
151 | "type": "group",
152 | "id": "com.example.repository",
153 | "attributes": {
154 | "commonName": "Example Repository",
155 | "description": "Updated Repository Group"
156 | },
157 | "relationships": {
158 | "products": {
159 | "data": []
160 | }
161 | }
162 | }
163 | ],
164 | "meta": {
165 | "page": {
166 | "number": 1,
167 | "totalRecords": 2,
168 | "limit": 10,
169 | "totalPages": 1
170 | }
171 | }
172 | }
173 | );
174 |
175 |
176 | nock("http://localhost:8080/api/v1")
177 | .get("/group?page[offset]=0&page[limit]=10&page[totals]&&filter=id=ini=(com.yahoo.elide)")
178 | .reply(
179 | 200,
180 | {
181 | "data": [
182 | {
183 | "type": "group",
184 | "id": "com.yahoo.elide",
185 | "attributes": {
186 | "commonName": "Elide",
187 | "description": "The magical library powering this project"
188 | },
189 | "relationships": {
190 | "products": {
191 | "data": [
192 | {
193 | "type": "product",
194 | "id": "elide-core"
195 | },
196 | {
197 | "type": "product",
198 | "id": "elide-standalone"
199 | },
200 | {
201 | "type": "product",
202 | "id": "elide-datastore-hibernate5"
203 | }
204 | ]
205 | }
206 | }
207 | }
208 | ],
209 | "meta": {
210 | "page": {
211 | "number": 1,
212 | "totalRecords": 1,
213 | "limit": 10,
214 | "totalPages": 1
215 | }
216 | }
217 | }
218 | );
219 |
220 | nock("http://localhost:8080/api/v1")
221 | .get("/group?page[offset]=0&page[limit]=10&page[totals]&sort=id,&filter=id=ini=(com.yahoo.elide)")
222 | .reply(
223 | 200,
224 | {
225 | "data": [
226 | {
227 | "type": "group",
228 | "id": "com.yahoo.elide",
229 | "attributes": {
230 | "commonName": "Elide",
231 | "description": "The magical library powering this project"
232 | },
233 | "relationships": {
234 | "products": {
235 | "data": [
236 | {
237 | "type": "product",
238 | "id": "elide-core"
239 | },
240 | {
241 | "type": "product",
242 | "id": "elide-standalone"
243 | },
244 | {
245 | "type": "product",
246 | "id": "elide-datastore-hibernate5"
247 | }
248 | ]
249 | }
250 | }
251 | }
252 | ],
253 | "meta": {
254 | "page": {
255 | "number": 1,
256 | "totalRecords": 1,
257 | "limit": 10,
258 | "totalPages": 1
259 | }
260 | }
261 | }
262 | );
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------