@websolutespa/bom-mixer-store 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +71 -36
- package/dist/index.js +608 -241
- package/dist/index.mjs +599 -235
- package/package.json +10 -14
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, IPageRelation, IMemoryStore, IEquatable, IQuerable, Pagination } from '@websolutespa/bom-core';
|
|
2
3
|
import { NextRequest } from 'next/server';
|
|
3
4
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
declare function apiPatch(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
|
|
10
|
-
declare function apiDelete(url: string, options?: ApiRequestOptions): Promise<any>;
|
|
11
|
-
declare class ApiService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
12
|
-
key: string;
|
|
13
|
-
constructor(key: string);
|
|
14
|
-
findOne___<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
15
|
-
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
16
|
-
findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
17
|
-
findPaged<B extends T = T>(params?: QueryParams): Promise<{
|
|
18
|
-
docs: B[];
|
|
19
|
-
} & Pagination>;
|
|
20
|
-
create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
|
|
21
|
-
update<B extends T = T>(payload: Partial<B>): Promise<B>;
|
|
22
|
-
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
23
|
-
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
24
|
-
}
|
|
5
|
+
type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
|
|
6
|
+
type IHandler = (request: NextApiRequest, response: NextApiResponse) => Promise<any>;
|
|
7
|
+
type IApiHandler = Record<ICrudMethod, IHandler>;
|
|
8
|
+
declare function apiHandler(handler: IApiHandler): any;
|
|
9
|
+
declare function errorHandler(error: any, response: NextApiResponse): Promise<any> | void;
|
|
25
10
|
|
|
26
|
-
declare
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
declare function
|
|
36
|
-
|
|
11
|
+
declare function getApiUrl(pathname: string): string;
|
|
12
|
+
declare function apiFetch<T = any>(pathname: string, options?: FetchRequestOptions, serviceOptions?: {
|
|
13
|
+
locale: string;
|
|
14
|
+
market: string;
|
|
15
|
+
}): Promise<T>;
|
|
16
|
+
declare function apiGet<T = any>(url: string, options?: FetchRequestOptions, serviceOptions?: {
|
|
17
|
+
locale: string;
|
|
18
|
+
market: string;
|
|
19
|
+
}): Promise<T>;
|
|
20
|
+
declare function apiPost<T = any>(url: string, payload?: unknown, options?: FetchRequestOptions, serviceOptions?: {
|
|
21
|
+
locale: string;
|
|
22
|
+
market: string;
|
|
23
|
+
}): Promise<T>;
|
|
24
|
+
declare function apiPut<T = any>(url: string, payload?: unknown, options?: FetchRequestOptions, serviceOptions?: {
|
|
25
|
+
locale: string;
|
|
26
|
+
market: string;
|
|
27
|
+
}): Promise<T>;
|
|
28
|
+
declare function apiPatch<T = any>(url: string, payload?: unknown, options?: FetchRequestOptions, serviceOptions?: {
|
|
29
|
+
locale: string;
|
|
30
|
+
market: string;
|
|
31
|
+
}): Promise<T>;
|
|
32
|
+
declare function apiDelete<T = any>(url: string, options?: FetchRequestOptions, serviceOptions?: {
|
|
33
|
+
locale: string;
|
|
34
|
+
market: string;
|
|
35
|
+
}): Promise<T>;
|
|
37
36
|
|
|
38
37
|
declare function isStaticRequest(request: NextRequest): boolean;
|
|
39
38
|
declare function isNextRequest(request: NextRequest): boolean;
|
|
@@ -42,12 +41,16 @@ declare function isApiRequest(request: NextRequest): boolean;
|
|
|
42
41
|
declare function mockHandler(getJson: () => Promise<string>): any;
|
|
43
42
|
|
|
44
43
|
declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
44
|
+
store: IStore;
|
|
45
|
+
constructor(items: T[], store: IStore);
|
|
45
46
|
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
46
|
-
}
|
|
47
|
+
}
|
|
48
|
+
declare function isObject(item: unknown): item is Record<string, unknown>;
|
|
49
|
+
declare function isRelation(item: unknown): item is IPageRelation;
|
|
47
50
|
|
|
48
51
|
declare function getMockStoreServer<T extends IStore>(): Promise<T>;
|
|
49
52
|
declare function getMockStore<T extends IStore>(getJson: () => Promise<string>): Promise<T>;
|
|
50
|
-
declare function getMockStoreFromData<T extends IStore>(data:
|
|
53
|
+
declare function getMockStoreFromData<T extends IStore>(data: IMemoryStore): T;
|
|
51
54
|
|
|
52
55
|
type IField = {
|
|
53
56
|
name: string;
|
|
@@ -79,6 +82,13 @@ declare class StaticService<T extends IEntity = IEntity> extends JsonService<T>
|
|
|
79
82
|
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
declare enum StoreStrategy {
|
|
86
|
+
Api = "api",
|
|
87
|
+
Data = "data",
|
|
88
|
+
Mock = "mock"
|
|
89
|
+
}
|
|
90
|
+
declare const storeStrategy: StoreStrategy;
|
|
91
|
+
|
|
82
92
|
declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
|
|
83
93
|
|
|
84
94
|
declare const MOCK_COLLECTIONS: string[];
|
|
@@ -87,4 +97,29 @@ declare const KNOWN_COLLECTIONS: string[];
|
|
|
87
97
|
declare const COLLECTIONS: string[];
|
|
88
98
|
declare function getStore<T extends IStore>(): Promise<T>;
|
|
89
99
|
|
|
90
|
-
|
|
100
|
+
type ApiRequestOptions = FetchRequestOptions;
|
|
101
|
+
declare function storeApiFetch(pathname: string, options?: ApiRequestOptions): Promise<any>;
|
|
102
|
+
declare function storeApiGet(url: string, options?: ApiRequestOptions): Promise<any>;
|
|
103
|
+
declare function storeApiPost(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
|
|
104
|
+
declare function storeApiPut(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
|
|
105
|
+
declare function storeApiPatch(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
|
|
106
|
+
declare function storeApiDelete(url: string, options?: ApiRequestOptions): Promise<any>;
|
|
107
|
+
declare class StoreApiService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
108
|
+
key: string;
|
|
109
|
+
constructor(key: string);
|
|
110
|
+
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
111
|
+
findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
112
|
+
findPaged<B extends T = T>(params?: QueryParams): Promise<{
|
|
113
|
+
docs: B[];
|
|
114
|
+
} & Pagination>;
|
|
115
|
+
create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
|
|
116
|
+
update<B extends T = T>(payload: Partial<B>): Promise<B>;
|
|
117
|
+
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
118
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare function getApiStore<T extends IStore>(collections: string[]): Promise<T>;
|
|
122
|
+
declare function getApiRuntimeStore<T extends IStore>(collections: string[]): Promise<T>;
|
|
123
|
+
declare function getApiBuildStore<T extends IStore>(): Promise<T>;
|
|
124
|
+
|
|
125
|
+
export { ApiRequestOptions, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, MapTo, MockService, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreApiService, StoreStrategy, apiDelete, apiFetch, apiGet, apiHandler, apiPatch, apiPost, apiPut, errorHandler, getApiBuildStore, getApiRuntimeStore, getApiStore, getApiUrl, getMockStore, getMockStoreFromData, getMockStoreServer, getStore, isApiRequest, isNextRequest, isObject, isRelation, isStaticRequest, mockHandler, staticCollections, storeApiDelete, storeApiFetch, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeHandler, storeStrategy };
|