@websolutespa/bom-mixer-store 0.1.1 → 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 +25 -19
- package/dist/index.d.ts +107 -72
- package/dist/index.js +597 -242
- package/dist/index.mjs +585 -233
- package/package.json +8 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
# @websolutespa/bom-mixer-store
|
|
2
|
-
|
|
3
|
-
## 0.
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
## 0.1.
|
|
10
|
-
|
|
11
|
-
###
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
## 0.0
|
|
16
|
-
|
|
17
|
-
###
|
|
18
|
-
|
|
19
|
-
-
|
|
1
|
+
# @websolutespa/bom-mixer-store
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added: @websolutespa/bom-core.
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Modified: store service.
|
|
14
|
+
|
|
15
|
+
## 0.1.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- mock refactor.
|
|
20
|
+
|
|
21
|
+
## 0.0.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Added: first release.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,90 +1,125 @@
|
|
|
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
|
-
}
|
|
25
|
-
|
|
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;
|
|
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;
|
|
33
10
|
|
|
34
|
-
declare function
|
|
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
|
-
declare function isStaticRequest(request: NextRequest): boolean;
|
|
39
|
-
declare function isNextRequest(request: NextRequest): boolean;
|
|
37
|
+
declare function isStaticRequest(request: NextRequest): boolean;
|
|
38
|
+
declare function isNextRequest(request: NextRequest): boolean;
|
|
40
39
|
declare function isApiRequest(request: NextRequest): boolean;
|
|
41
40
|
|
|
42
41
|
declare function mockHandler(getJson: () => Promise<string>): any;
|
|
43
42
|
|
|
44
|
-
declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
44
|
+
store: IStore;
|
|
45
|
+
constructor(items: T[], store: IStore);
|
|
46
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
47
|
+
}
|
|
48
|
+
declare function isObject(item: unknown): item is Record<string, unknown>;
|
|
49
|
+
declare function isRelation(item: unknown): item is IPageRelation;
|
|
47
50
|
|
|
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:
|
|
51
|
+
declare function getMockStoreServer<T extends IStore>(): Promise<T>;
|
|
52
|
+
declare function getMockStore<T extends IStore>(getJson: () => Promise<string>): Promise<T>;
|
|
53
|
+
declare function getMockStoreFromData<T extends IStore>(data: IMemoryStore): T;
|
|
51
54
|
|
|
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
|
-
};
|
|
55
|
+
type IField = {
|
|
56
|
+
name: string;
|
|
57
|
+
type: 'text' | 'number' | 'relationship';
|
|
58
|
+
localized?: boolean;
|
|
59
|
+
relationTo?: string;
|
|
60
|
+
hasMany?: boolean;
|
|
61
|
+
required?: boolean;
|
|
62
|
+
};
|
|
63
|
+
type MapTo = Record<string, string>;
|
|
64
|
+
type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
|
|
65
|
+
type StaticServiceConfig<T extends IEntity = IEntity> = {
|
|
66
|
+
src: StaticServiceSrc<T>;
|
|
67
|
+
slug: string;
|
|
68
|
+
fields: IField[];
|
|
69
|
+
map?: MapTo;
|
|
70
|
+
};
|
|
68
71
|
declare const staticCollections: StaticServiceConfig[];
|
|
69
72
|
|
|
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;
|
|
73
|
+
declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
74
|
+
loaded: boolean;
|
|
75
|
+
config: StaticServiceConfig<T>;
|
|
76
|
+
store: IStore;
|
|
77
|
+
constructor(config: StaticServiceConfig<T>, store: IStore);
|
|
78
|
+
getItems<B extends T = T>(): Promise<B[]>;
|
|
79
|
+
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
80
|
+
protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
|
|
81
|
+
protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
|
|
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
|
-
declare const MOCK_COLLECTIONS: string[];
|
|
85
|
-
declare const STATIC_COLLECTIONS: string[];
|
|
86
|
-
declare const KNOWN_COLLECTIONS: string[];
|
|
87
|
-
declare const COLLECTIONS: string[];
|
|
94
|
+
declare const MOCK_COLLECTIONS: string[];
|
|
95
|
+
declare const STATIC_COLLECTIONS: string[];
|
|
96
|
+
declare const KNOWN_COLLECTIONS: string[];
|
|
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 };
|