@websolutespa/bom-mixer-store 0.0.2 → 0.1.1
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 +77 -47
- package/dist/index.js +699 -143
- package/dist/index.mjs +689 -138
- package/package.json +18 -16
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,60 +1,90 @@
|
|
|
1
|
-
import { FetchRequestOptions, IEntity, IQuerable, QueryParams,
|
|
2
|
-
import { NextRequest
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
declare function
|
|
10
|
-
declare
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { FetchRequestOptions, IEntity, IQuerable, IEquatable, QueryParams, Pagination, JsonService } from '@websolutespa/bom-mixer-core';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
|
|
4
|
+
type ApiRequestOptions = FetchRequestOptions;
|
|
5
|
+
declare function apiFetch(pathname: string, options?: ApiRequestOptions): Promise<any>;
|
|
6
|
+
declare function apiGet(url: string, options?: ApiRequestOptions): Promise<any>;
|
|
7
|
+
declare function apiPost(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
|
|
8
|
+
declare function apiPut(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
|
|
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;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
declare
|
|
28
|
-
Api = "api",
|
|
29
|
-
Data = "data",
|
|
30
|
-
Mock = "mock"
|
|
31
|
-
}
|
|
32
|
-
declare const storeStrategy: StoreStrategy;
|
|
33
|
-
type IStore = {
|
|
34
|
-
[key: string]: IQuerable<IEntity>;
|
|
35
|
-
};
|
|
26
|
+
declare enum StoreStrategy {
|
|
27
|
+
Api = "api",
|
|
28
|
+
Data = "data",
|
|
29
|
+
Mock = "mock"
|
|
30
|
+
}
|
|
31
|
+
type IStore = Record<string, IQuerable<IEntity>>;
|
|
32
|
+
declare const storeStrategy: StoreStrategy;
|
|
36
33
|
|
|
37
|
-
declare function getApiStore<T extends IStore>(collections: string[]): Promise<T>;
|
|
38
|
-
declare function getApiRuntimeStore<T extends IStore>(collections: string[]): Promise<T>;
|
|
34
|
+
declare function getApiStore<T extends IStore>(collections: string[]): Promise<T>;
|
|
35
|
+
declare function getApiRuntimeStore<T extends IStore>(collections: string[]): Promise<T>;
|
|
39
36
|
declare function getApiBuildStore<T extends IStore>(): Promise<T>;
|
|
40
37
|
|
|
41
|
-
declare function isStaticRequest(request: NextRequest): boolean;
|
|
42
|
-
declare function isNextRequest(request: NextRequest): boolean;
|
|
43
|
-
declare function isApiRequest(request: NextRequest): boolean;
|
|
44
|
-
|
|
38
|
+
declare function isStaticRequest(request: NextRequest): boolean;
|
|
39
|
+
declare function isNextRequest(request: NextRequest): boolean;
|
|
40
|
+
declare function isApiRequest(request: NextRequest): boolean;
|
|
41
|
+
|
|
42
|
+
declare function mockHandler(getJson: () => Promise<string>): any;
|
|
45
43
|
|
|
46
|
-
declare
|
|
47
|
-
|
|
44
|
+
declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
45
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare function getMockStoreServer<T extends IStore>(): Promise<T>;
|
|
49
|
+
declare function getMockStore<T extends IStore>(getJson: () => Promise<string>): Promise<T>;
|
|
50
|
+
declare function getMockStoreFromData<T extends IStore>(data: Record<string, IEntity[]>): T;
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
type IField = {
|
|
53
|
+
name: string;
|
|
54
|
+
type: 'text' | 'number' | 'relationship';
|
|
55
|
+
localized?: boolean;
|
|
56
|
+
relationTo?: string;
|
|
57
|
+
hasMany?: boolean;
|
|
58
|
+
required?: boolean;
|
|
59
|
+
};
|
|
60
|
+
type MapTo = Record<string, string>;
|
|
61
|
+
type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
|
|
62
|
+
type StaticServiceConfig<T extends IEntity = IEntity> = {
|
|
63
|
+
src: StaticServiceSrc<T>;
|
|
64
|
+
slug: string;
|
|
65
|
+
fields: IField[];
|
|
66
|
+
map?: MapTo;
|
|
67
|
+
};
|
|
68
|
+
declare const staticCollections: StaticServiceConfig[];
|
|
50
69
|
|
|
51
|
-
declare class
|
|
52
|
-
|
|
70
|
+
declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
71
|
+
loaded: boolean;
|
|
72
|
+
config: StaticServiceConfig<T>;
|
|
73
|
+
store: IStore;
|
|
74
|
+
constructor(config: StaticServiceConfig<T>, store: IStore);
|
|
75
|
+
getItems<B extends T = T>(): Promise<B[]>;
|
|
76
|
+
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
77
|
+
protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
|
|
78
|
+
protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
|
|
79
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
53
80
|
}
|
|
54
81
|
|
|
55
|
-
declare function
|
|
82
|
+
declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
|
|
56
83
|
|
|
57
|
-
declare
|
|
84
|
+
declare const MOCK_COLLECTIONS: string[];
|
|
85
|
+
declare const STATIC_COLLECTIONS: string[];
|
|
86
|
+
declare const KNOWN_COLLECTIONS: string[];
|
|
87
|
+
declare const COLLECTIONS: string[];
|
|
58
88
|
declare function getStore<T extends IStore>(): Promise<T>;
|
|
59
89
|
|
|
60
|
-
export { ApiService, IStore, MockService,
|
|
90
|
+
export { ApiRequestOptions, ApiService, COLLECTIONS, IField, IStore, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, MapTo, MockService, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiDelete, apiFetch, apiGet, apiPatch, apiPost, apiPut, getApiBuildStore, getApiRuntimeStore, getApiStore, getMockStore, getMockStoreFromData, getMockStoreServer, getStore, isApiRequest, isNextRequest, isStaticRequest, mockHandler, staticCollections, storeHandler, storeStrategy };
|