@koine/api 2.0.0-beta.73 → 2.0.0-beta.74
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/createSwrApi.cjs.js +14 -0
- package/createSwrApi.esm.js +7 -0
- package/next/nextApiResponse.d.ts +6 -0
- package/next/nextApiResponse.js +12 -0
- package/next/nextApiResponse12.d.ts +6 -0
- package/next/nextApiResponse12.js +11 -0
- package/next.cjs.js +3 -1
- package/next.d.ts +2 -10
- package/next.esm.js +3 -1
- package/next.js +2 -19
- package/package.json +2 -2
- package/swr/createSwrApi.d.ts +9 -0
- package/swr/createSwrApi.js +22 -0
- package/swr-mutation/createSwrMutationApi.d.ts +19 -0
- package/swr-mutation/createSwrMutationApi.js +27 -0
- package/swr-mutation.cjs.js +2 -2
- package/swr-mutation.d.ts +1 -19
- package/swr-mutation.esm.js +1 -1
- package/swr-mutation.js +1 -26
- package/swr.cjs.js +5 -9
- package/swr.d.ts +1 -9
- package/swr.esm.js +4 -7
- package/swr.js +1 -21
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var e = require('swr');
|
|
4
|
+
var utils = require('@koine/utils');
|
|
5
|
+
var createApi = require('./createApi.cjs.js');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var e__default = /*#__PURE__*/_interopDefaultLegacy(e);
|
|
10
|
+
|
|
11
|
+
let createUseApi=t=>(i,o,p)=>{let a=async()=>{let{data:e}=await t.get(i,{...o||{},throwErr:!0});return e};return e__default["default"](p?.when===!1||utils.isFunction(p?.when)&&p?.when()===!1?null:o?[i,o]:[i],a,p)};let createSwrApi=(...e)=>{let r=createApi.createApi(...e);return r.use=createUseApi(r),r};
|
|
12
|
+
|
|
13
|
+
exports.createSwrApi = createSwrApi;
|
|
14
|
+
exports.createUseApi = createUseApi;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import e from 'swr';
|
|
2
|
+
import { isFunction } from '@koine/utils';
|
|
3
|
+
import { c as createApi } from './createApi.esm.js';
|
|
4
|
+
|
|
5
|
+
let createUseApi=t=>(i,o,p)=>{let a=async()=>{let{data:e}=await t.get(i,{...o||{},throwErr:!0});return e};return e(p?.when===!1||isFunction(p?.when)&&p?.when()===!1?null:o?[i,o]:[i],a,p)};let createSwrApi=(...e)=>{let r=createApi(...e);return r.use=createUseApi(r),r};
|
|
6
|
+
|
|
7
|
+
export { createUseApi as a, createSwrApi as c };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
export declare let nextApiResponse: {
|
|
3
|
+
ok<T>(data: T, msg?: string): NextResponse<import("..").Api.ResultOk<T>>;
|
|
4
|
+
fail<T_1>(data: T_1, msg?: string, status?: number): NextResponse<import("..").Api.ResultFail<T_1>>;
|
|
5
|
+
};
|
|
6
|
+
export default nextApiResponse;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { createApiResultFail } from "../createApiResultFail";
|
|
3
|
+
import { createApiResultOk } from "../createApiResultOk";
|
|
4
|
+
export let nextApiResponse = {
|
|
5
|
+
ok(data, msg) {
|
|
6
|
+
return NextResponse.json(createApiResultOk(data, msg));
|
|
7
|
+
},
|
|
8
|
+
fail(data, msg, status) {
|
|
9
|
+
return NextResponse.json(createApiResultFail(data, msg, status));
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export default nextApiResponse;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createApiResultFail } from "../createApiResultFail";
|
|
2
|
+
import { createApiResultOk } from "../createApiResultOk";
|
|
3
|
+
export let nextApiResponse12 = (nextRes) => ({
|
|
4
|
+
ok(data, msg) {
|
|
5
|
+
nextRes.status(200).json(createApiResultOk(data, msg));
|
|
6
|
+
},
|
|
7
|
+
fail(data, msg, status) {
|
|
8
|
+
nextRes.status(status || 404).json(createApiResultFail(data, msg, status));
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
export default nextApiResponse12;
|
package/next.cjs.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var server = require('next/server');
|
|
6
6
|
var createApiResultOk = require('./createApiResultOk.cjs.js');
|
|
7
7
|
|
|
8
|
-
let nextApiResponse={ok:(t,
|
|
8
|
+
let nextApiResponse={ok:(t,r)=>server.NextResponse.json(createApiResultOk.createApiResultOk(t,r)),fail:(o,r,p)=>server.NextResponse.json(createApiResultOk.createApiResultFail(o,r,p))};
|
|
9
|
+
|
|
10
|
+
let nextApiResponse12=s=>({ok(e,o){s.status(200).json(createApiResultOk.createApiResultOk(e,o));},fail(t,o,p){s.status(p||404).json(createApiResultOk.createApiResultFail(t,o,p));}});
|
|
9
11
|
|
|
10
12
|
exports.nextApiResponse = nextApiResponse;
|
|
11
13
|
exports.nextApiResponse12 = nextApiResponse12;
|
package/next.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare let nextApiResponse: {
|
|
4
|
-
ok<T>(data: T, msg?: string): NextResponse<import("./types").Api.ResultOk<T>>;
|
|
5
|
-
fail<T_1>(data: T_1, msg?: string, status?: number): NextResponse<import("./types").Api.ResultFail<T_1>>;
|
|
6
|
-
};
|
|
7
|
-
export declare let nextApiResponse12: (nextRes: NextApiResponse) => {
|
|
8
|
-
ok<T>(data: T, msg?: string): void;
|
|
9
|
-
fail<T_1>(data: T_1, msg?: string, status?: number): void;
|
|
10
|
-
};
|
|
1
|
+
export { nextApiResponse } from "./next/nextApiResponse";
|
|
2
|
+
export { nextApiResponse12 } from "./next/nextApiResponse12";
|
package/next.esm.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
2
|
import { a as createApiResultOk, c as createApiResultFail } from './createApiResultOk.esm.js';
|
|
3
3
|
|
|
4
|
-
let nextApiResponse={ok:(t,
|
|
4
|
+
let nextApiResponse={ok:(t,r)=>NextResponse.json(createApiResultOk(t,r)),fail:(o,r,p)=>NextResponse.json(createApiResultFail(o,r,p))};
|
|
5
|
+
|
|
6
|
+
let nextApiResponse12=s=>({ok(e,o){s.status(200).json(createApiResultOk(e,o));},fail(t,o,p){s.status(p||404).json(createApiResultFail(t,o,p));}});
|
|
5
7
|
|
|
6
8
|
export { nextApiResponse, nextApiResponse12 };
|
package/next.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { createApiResultOk } from "./createApiResultOk";
|
|
4
|
-
export let nextApiResponse = {
|
|
5
|
-
ok(data, msg) {
|
|
6
|
-
return NextResponse.json(createApiResultOk(data, msg));
|
|
7
|
-
},
|
|
8
|
-
fail(data, msg, status) {
|
|
9
|
-
return NextResponse.json(createApiResultFail(data, msg, status));
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
export let nextApiResponse12 = (nextRes) => ({
|
|
13
|
-
ok(data, msg) {
|
|
14
|
-
nextRes.status(200).json(createApiResultOk(data, msg));
|
|
15
|
-
},
|
|
16
|
-
fail(data, msg, status) {
|
|
17
|
-
nextRes.status(status || 404).json(createApiResultFail(data, msg, status));
|
|
18
|
-
},
|
|
19
|
-
});
|
|
1
|
+
export { nextApiResponse } from "./next/nextApiResponse";
|
|
2
|
+
export { nextApiResponse12 } from "./next/nextApiResponse12";
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@koine/api",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/utils": "2.0.0-beta.74"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"next": "^14.0.4",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
},
|
|
42
42
|
"module": "./index.esm.js",
|
|
43
43
|
"main": "./index.cjs.js",
|
|
44
|
-
"version": "2.0.0-beta.
|
|
44
|
+
"version": "2.0.0-beta.74"
|
|
45
45
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type BareFetcher, type SWRConfiguration, type SWRResponse } from "swr";
|
|
2
|
+
import type { Api } from "../types";
|
|
3
|
+
type SWRConfigurationExtended<Data = any, Error = any, Fn extends BareFetcher<any> = BareFetcher<any>> = SWRConfiguration<Data, Error, Fn> & {
|
|
4
|
+
when?: boolean | (() => boolean);
|
|
5
|
+
};
|
|
6
|
+
export declare let createSwrApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, options?: Api.ClientOptions | undefined) => Api.Client<TEndpoints> & {
|
|
7
|
+
use: <TEndpoint extends Extract<keyof TEndpoints, string>>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, "get"> | undefined, config?: SWRConfigurationExtended<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, BareFetcher<any>> | undefined) => SWRResponse<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, any>;
|
|
8
|
+
};
|
|
9
|
+
export default createSwrApi;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWR, {} from "swr";
|
|
3
|
+
import { isFunction } from "@koine/utils";
|
|
4
|
+
import { createApi } from "../createApi";
|
|
5
|
+
export let createUseApi = (api) => (endpoint, options, config) => {
|
|
6
|
+
const fetcher = async () => {
|
|
7
|
+
const { data } = await api.get(endpoint, {
|
|
8
|
+
...(options || {}),
|
|
9
|
+
throwErr: true,
|
|
10
|
+
});
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
const shouldNotFetch = config?.when === false ||
|
|
14
|
+
(isFunction(config?.when) && config?.when() === false);
|
|
15
|
+
return useSWR(shouldNotFetch ? null : options ? [endpoint, options] : [endpoint], fetcher, config);
|
|
16
|
+
};
|
|
17
|
+
export let createSwrApi = (...args) => {
|
|
18
|
+
const api = createApi(...args);
|
|
19
|
+
api.use = createUseApi(api);
|
|
20
|
+
return api;
|
|
21
|
+
};
|
|
22
|
+
export default createSwrApi;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type SWRMutationConfiguration, type SWRMutationResponse } from "swr/mutation";
|
|
2
|
+
import { createUseApi } from "../swr/createSwrApi";
|
|
3
|
+
import type { Api } from "../types";
|
|
4
|
+
type MutationRequestMethod = Exclude<Api.RequestMethod, "get">;
|
|
5
|
+
type MutationHookName = Exclude<keyof Api.HooksMapsByName, "use">;
|
|
6
|
+
type KoineApiMethodHookSWR<THookName extends MutationHookName, TEndpoints extends Api.Endpoints> = <TEndpoint extends Api.EndpointUrl<TEndpoints>, TMethod extends MutationRequestMethod = Api.HooksMapsByName[THookName]>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, config?: SWRMutationConfiguration<Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, TEndpoint, Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>>) => SWRMutationResponse<Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, TEndpoint, Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>>;
|
|
7
|
+
export declare let createSwrMutationApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, options?: Api.ClientOptions | undefined) => Api.Client<TEndpoints> & {
|
|
8
|
+
usePost: KoineApiMethodHookSWR<"usePost", TEndpoints>;
|
|
9
|
+
usePut: KoineApiMethodHookSWR<"usePut", TEndpoints>;
|
|
10
|
+
usePatch: KoineApiMethodHookSWR<"usePatch", TEndpoints>;
|
|
11
|
+
useDelete: KoineApiMethodHookSWR<"useDelete", TEndpoints>;
|
|
12
|
+
} & {
|
|
13
|
+
use: <TEndpoint extends Extract<keyof TEndpoints, string>>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, "get"> | undefined, config?: (Partial<import("swr/dist/_internal").PublicConfiguration<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, import("swr/dist/_internal").BareFetcher<any>>> & Partial<import("swr/dist/_internal").ProviderConfiguration> & {
|
|
14
|
+
provider?: ((cache: Readonly<import("swr/dist/_internal").Cache<any>>) => import("swr/dist/_internal").Cache<any>) | undefined;
|
|
15
|
+
} & {
|
|
16
|
+
when?: boolean | (() => boolean) | undefined;
|
|
17
|
+
}) | undefined) => import("swr/dist/_internal").SWRResponse<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, any>;
|
|
18
|
+
};
|
|
19
|
+
export default createSwrMutationApi;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWRMutation, {} from "swr/mutation";
|
|
3
|
+
import { createApi } from "../createApi";
|
|
4
|
+
import { createUseApi } from "../swr/createSwrApi";
|
|
5
|
+
let createUseMutationApi = (api, method) => (endpoint, options, config) => {
|
|
6
|
+
const sender = async (_endpoint, _options) => {
|
|
7
|
+
const endpoint = Array.isArray(_endpoint) ? _endpoint[0] : _endpoint;
|
|
8
|
+
const options = Array.isArray(_endpoint) ? _endpoint[1] : {};
|
|
9
|
+
const { ok, data } = await api[method](endpoint, {
|
|
10
|
+
...options,
|
|
11
|
+
...(_options.arg || {}),
|
|
12
|
+
throwErr: true,
|
|
13
|
+
});
|
|
14
|
+
return ok ? data : data;
|
|
15
|
+
};
|
|
16
|
+
return useSWRMutation(options ? [endpoint, options] : endpoint, sender, config);
|
|
17
|
+
};
|
|
18
|
+
export let createSwrMutationApi = (...args) => {
|
|
19
|
+
const api = createApi(...args);
|
|
20
|
+
api.use = createUseApi(api);
|
|
21
|
+
["post", "put", "patch", "delete"].forEach((method) => {
|
|
22
|
+
const hookName = `use${method.charAt(0).toUpperCase() + method.slice(1)}`;
|
|
23
|
+
api[hookName] = createUseMutationApi(api, method);
|
|
24
|
+
});
|
|
25
|
+
return api;
|
|
26
|
+
};
|
|
27
|
+
export default createSwrMutationApi;
|
package/swr-mutation.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var r = require('swr/mutation');
|
|
6
6
|
var createApi = require('./createApi.cjs.js');
|
|
7
|
-
var
|
|
7
|
+
var createSwrApi = require('./createSwrApi.cjs.js');
|
|
8
8
|
require('@koine/utils');
|
|
9
9
|
require('swr');
|
|
10
10
|
|
|
@@ -12,6 +12,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
12
12
|
|
|
13
13
|
var r__default = /*#__PURE__*/_interopDefaultLegacy(r);
|
|
14
14
|
|
|
15
|
-
let a=(t,e)=>(a,o,i)=>r__default["default"](o?[a,o]:a,async(r,a)=>{let o=Array.isArray(r)?r[0]:r,i=Array.isArray(r)?r[1]:{},{ok:p,data:s}=await t[e](o,{...i,...a.arg||{},throwErr:!0});return s},i);let createSwrMutationApi=(...r)=>{let o=createApi.createApi(...r);return o.use=
|
|
15
|
+
let a=(t,e)=>(a,o,i)=>r__default["default"](o?[a,o]:a,async(r,a)=>{let o=Array.isArray(r)?r[0]:r,i=Array.isArray(r)?r[1]:{},{ok:p,data:s}=await t[e](o,{...i,...a.arg||{},throwErr:!0});return s},i);let createSwrMutationApi=(...r)=>{let o=createApi.createApi(...r);return o.use=createSwrApi.createUseApi(o),["post","put","patch","delete"].forEach(r=>{o[`use${r.charAt(0).toUpperCase()+r.slice(1)}`]=a(o,r);}),o};
|
|
16
16
|
|
|
17
17
|
exports.createSwrMutationApi = createSwrMutationApi;
|
package/swr-mutation.d.ts
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { createUseApi } from "./swr";
|
|
3
|
-
import type { Api } from "./types";
|
|
4
|
-
type MutationRequestMethod = Exclude<Api.RequestMethod, "get">;
|
|
5
|
-
type MutationHookName = Exclude<keyof Api.HooksMapsByName, "use">;
|
|
6
|
-
type KoineApiMethodHookSWR<THookName extends MutationHookName, TEndpoints extends Api.Endpoints> = <TEndpoint extends Api.EndpointUrl<TEndpoints>, TMethod extends MutationRequestMethod = Api.HooksMapsByName[THookName]>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, config?: SWRMutationConfiguration<Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, TEndpoint, Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>>) => SWRMutationResponse<Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, TEndpoint, Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>>;
|
|
7
|
-
export declare let createSwrMutationApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, options?: Api.ClientOptions | undefined) => Api.Client<TEndpoints> & {
|
|
8
|
-
usePost: KoineApiMethodHookSWR<"usePost", TEndpoints>;
|
|
9
|
-
usePut: KoineApiMethodHookSWR<"usePut", TEndpoints>;
|
|
10
|
-
usePatch: KoineApiMethodHookSWR<"usePatch", TEndpoints>;
|
|
11
|
-
useDelete: KoineApiMethodHookSWR<"useDelete", TEndpoints>;
|
|
12
|
-
} & {
|
|
13
|
-
use: <TEndpoint extends Extract<keyof TEndpoints, string>>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, "get"> | undefined, config?: (Partial<import("swr/dist/_internal").PublicConfiguration<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, import("swr/dist/_internal").BareFetcher<any>>> & Partial<import("swr/dist/_internal").ProviderConfiguration> & {
|
|
14
|
-
provider?: ((cache: Readonly<import("swr/dist/_internal").Cache<any>>) => import("swr/dist/_internal").Cache<any>) | undefined;
|
|
15
|
-
} & {
|
|
16
|
-
when?: boolean | (() => boolean) | undefined;
|
|
17
|
-
}) | undefined) => import("swr/dist/_internal").SWRResponse<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, any>;
|
|
18
|
-
};
|
|
19
|
-
export {};
|
|
1
|
+
export { createSwrMutationApi } from "./swr-mutation/createSwrMutationApi";
|
package/swr-mutation.esm.js
CHANGED
package/swr-mutation.js
CHANGED
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import useSWRMutation, {} from "swr/mutation";
|
|
3
|
-
import { createApi } from "./createApi";
|
|
4
|
-
import { createUseApi } from "./swr";
|
|
5
|
-
let createUseMutationApi = (api, method) => (endpoint, options, config) => {
|
|
6
|
-
const sender = async (_endpoint, _options) => {
|
|
7
|
-
const endpoint = Array.isArray(_endpoint) ? _endpoint[0] : _endpoint;
|
|
8
|
-
const options = Array.isArray(_endpoint) ? _endpoint[1] : {};
|
|
9
|
-
const { ok, data } = await api[method](endpoint, {
|
|
10
|
-
...options,
|
|
11
|
-
...(_options.arg || {}),
|
|
12
|
-
throwErr: true,
|
|
13
|
-
});
|
|
14
|
-
return ok ? data : data;
|
|
15
|
-
};
|
|
16
|
-
return useSWRMutation(options ? [endpoint, options] : endpoint, sender, config);
|
|
17
|
-
};
|
|
18
|
-
export let createSwrMutationApi = (...args) => {
|
|
19
|
-
const api = createApi(...args);
|
|
20
|
-
api.use = createUseApi(api);
|
|
21
|
-
["post", "put", "patch", "delete"].forEach((method) => {
|
|
22
|
-
const hookName = `use${method.charAt(0).toUpperCase() + method.slice(1)}`;
|
|
23
|
-
api[hookName] = createUseMutationApi(api, method);
|
|
24
|
-
});
|
|
25
|
-
return api;
|
|
26
|
-
};
|
|
1
|
+
export { createSwrMutationApi } from "./swr-mutation/createSwrMutationApi";
|
package/swr.cjs.js
CHANGED
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var createSwrApi = require('./createSwrApi.cjs.js');
|
|
6
|
+
require('swr');
|
|
7
|
+
require('@koine/utils');
|
|
8
|
+
require('./createApi.cjs.js');
|
|
8
9
|
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
10
|
|
|
11
|
-
var e__default = /*#__PURE__*/_interopDefaultLegacy(e);
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.createSwrApi = createSwrApi;
|
|
16
|
-
exports.createUseApi = createUseApi;
|
|
12
|
+
exports.createSwrApi = createSwrApi.createSwrApi;
|
package/swr.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Api } from "./types";
|
|
3
|
-
type SWRConfigurationExtended<Data = any, Error = any, Fn extends BareFetcher<any> = BareFetcher<any>> = SWRConfiguration<Data, Error, Fn> & {
|
|
4
|
-
when?: boolean | (() => boolean);
|
|
5
|
-
};
|
|
6
|
-
export declare let createSwrApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, options?: Api.ClientOptions | undefined) => Api.Client<TEndpoints> & {
|
|
7
|
-
use: <TEndpoint extends Extract<keyof TEndpoints, string>>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, "get"> | undefined, config?: SWRConfigurationExtended<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, BareFetcher<any>> | undefined) => SWRResponse<Api.GetDataType<TEndpoints, TEndpoint, "get", "ok">, Api.GetDataType<TEndpoints, TEndpoint, "get", "fail">, any>;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
1
|
+
export { createSwrApi } from "./swr/createSwrApi";
|
package/swr.esm.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
let createUseApi=t=>(i,o,n)=>{let p=async()=>{let{data:e}=await t.get(i,{...o||{},throwErr:!0});return e};return e(n?.when===!1||isFunction(n?.when)&&n?.when()===!1?null:o?[i,o]:[i],p,n)};let createSwrApi=(...e)=>{let r=createApi(...e);return r.use=createUseApi(r),r};
|
|
6
|
-
|
|
7
|
-
export { createSwrApi, createUseApi };
|
|
1
|
+
export { c as createSwrApi } from './createSwrApi.esm.js';
|
|
2
|
+
import 'swr';
|
|
3
|
+
import '@koine/utils';
|
|
4
|
+
import './createApi.esm.js';
|
package/swr.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import useSWR, {} from "swr";
|
|
3
|
-
import { isFunction } from "@koine/utils";
|
|
4
|
-
import { createApi } from "./createApi";
|
|
5
|
-
export let createUseApi = (api) => (endpoint, options, config) => {
|
|
6
|
-
const fetcher = async () => {
|
|
7
|
-
const { data } = await api.get(endpoint, {
|
|
8
|
-
...(options || {}),
|
|
9
|
-
throwErr: true,
|
|
10
|
-
});
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
const shouldNotFetch = config?.when === false ||
|
|
14
|
-
(isFunction(config?.when) && config?.when() === false);
|
|
15
|
-
return useSWR(shouldNotFetch ? null : options ? [endpoint, options] : [endpoint], fetcher, config);
|
|
16
|
-
};
|
|
17
|
-
export let createSwrApi = (...args) => {
|
|
18
|
-
const api = createApi(...args);
|
|
19
|
-
api.use = createUseApi(api);
|
|
20
|
-
return api;
|
|
21
|
-
};
|
|
1
|
+
export { createSwrApi } from "./swr/createSwrApi";
|