@websolutespa/bom-mixer-store 1.0.1 → 1.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: check redirects by pattern.
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Modified: store refactor.
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,130 +1,148 @@
1
+ import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, IPageRelation, IQuerable, IEquatable, Pagination } from '@websolutespa/bom-core';
1
2
  import { NextApiRequest, NextApiResponse } from 'next';
2
- import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, IPageRelation, IMemoryStore, IEquatable, IQuerable, Pagination } from '@websolutespa/bom-core';
3
3
  import { NextRequest } from 'next/server';
4
4
 
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;
5
+ type ApiRequestOptions = FetchRequestOptions;
6
+ declare const defaultApiRequestOptions: ApiRequestOptions;
7
+ declare function getDefaultApiRequestOptions(): ApiRequestOptions;
8
+
9
+ type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
10
+ type IHandler = (request: NextApiRequest, response: NextApiResponse) => Promise<any>;
11
+ type IApiHandler = Record<ICrudMethod, IHandler>;
12
+ declare function apiHandler(handler: IApiHandler): any;
9
13
  declare function errorHandler(error: any, response: NextApiResponse): Promise<any> | void;
10
14
 
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;
15
+ declare function fromCache<T = unknown>(callback: () => Promise<T>, key?: string): Promise<T>;
16
+
17
+ declare function getLocalApiUrl(pathname: string): string;
18
+ declare function localApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
19
+ locale: string;
20
+ market: string;
21
+ }): Promise<T>;
22
+ declare function localApiGet<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
23
+ locale: string;
24
+ market: string;
25
+ }): Promise<T>;
26
+ declare function localApiPost<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
27
+ locale: string;
28
+ market: string;
29
+ }): Promise<T>;
30
+ declare function localApiPut<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
31
+ locale: string;
32
+ market: string;
33
+ }): Promise<T>;
34
+ declare function localApiPatch<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
35
+ locale: string;
36
+ market: string;
37
+ }): Promise<T>;
38
+ declare function localApiDelete<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
39
+ locale: string;
40
+ market: string;
35
41
  }): Promise<T>;
36
42
 
37
- declare function isStaticRequest(request: NextRequest): boolean;
38
- declare function isNextRequest(request: NextRequest): boolean;
43
+ declare function isStaticRequest(request: NextRequest): boolean;
44
+ declare function isNextRequest(request: NextRequest): boolean;
39
45
  declare function isApiRequest(request: NextRequest): boolean;
40
46
 
41
- declare function mockHandler(getJson: () => Promise<string>): any;
47
+ declare function mockApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
48
+ declare function mockApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
49
+ declare function mockApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
50
+ declare function mockApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
51
+ declare function mockApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
52
+ declare function mockApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
53
+
54
+ declare function mockHandler(): any;
42
55
 
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>;
56
+ declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
57
+ store: IStore;
58
+ constructor(items: T[], store: IStore);
59
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
60
+ }
61
+ declare function isObject(item: unknown): item is Record<string, unknown>;
49
62
  declare function isRelation(item: unknown): item is IPageRelation;
50
63
 
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;
54
-
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
- };
64
+ declare function getMockStore<T extends IStore = IStore>(): Promise<T>;
65
+
66
+ declare function remoteApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
67
+ declare function remoteApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
68
+ declare function remoteApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
69
+ declare function remoteApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
70
+ declare function remoteApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
71
+ declare function remoteApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
72
+
73
+ /**
74
+ * This service handle call to remote api (bowl or over)
75
+ */
76
+ declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T> {
77
+ key: string;
78
+ constructor(key: string);
79
+ findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
80
+ findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
81
+ findPaged<B extends T = T>(params?: QueryParams): Promise<{
82
+ docs: B[];
83
+ } & Pagination>;
84
+ create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
85
+ update<B extends T = T>(payload: Partial<B>): Promise<B>;
86
+ delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
87
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
88
+ }
89
+
90
+ declare function getRemoteStore<T extends IStore>(): Promise<T>;
91
+
92
+ type IField = {
93
+ name: string;
94
+ type: 'text' | 'number' | 'relationship';
95
+ localized?: boolean;
96
+ relationTo?: string;
97
+ hasMany?: boolean;
98
+ required?: boolean;
99
+ };
100
+ type MapTo = Record<string, string>;
101
+ type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
102
+ type StaticServiceConfig<T extends IEntity = IEntity> = {
103
+ src: StaticServiceSrc<T>;
104
+ slug: string;
105
+ fields: IField[];
106
+ map?: MapTo;
107
+ };
71
108
  declare const staticCollections: StaticServiceConfig[];
72
109
 
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;
110
+ declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
111
+ loaded: boolean;
112
+ config: StaticServiceConfig<T>;
113
+ store: IStore;
114
+ constructor(config: StaticServiceConfig<T>, store: IStore);
115
+ getItems<B extends T = T>(): Promise<B[]>;
116
+ findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
117
+ protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
118
+ protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
119
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
83
120
  }
84
121
 
85
- declare enum StoreStrategy {
86
- Api = "api",
87
- Data = "data",
88
- Mock = "mock"
89
- }
122
+ declare enum StoreStrategy {
123
+ Api = "api",
124
+ Data = "data",
125
+ Mock = "mock"
126
+ }
90
127
  declare const storeStrategy: StoreStrategy;
128
+ declare const MOCK_COLLECTIONS: string[];
129
+ declare const STATIC_COLLECTIONS: string[];
130
+ declare const KNOWN_COLLECTIONS: string[];
131
+ declare const COLLECTIONS: string[];
91
132
 
92
- declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
93
- declare function collectionGet<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
94
- declare function collectionPost<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
95
- declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
96
- declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
133
+ declare function storeApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
134
+ declare function storeApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
135
+ declare function storeApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
136
+ declare function storeApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
137
+ declare function storeApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
138
+
139
+ declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
140
+ declare function collectionGet<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
141
+ declare function collectionPost<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
142
+ declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
143
+ declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
97
144
  declare function routePost(store: IStore, request: NextApiRequest, response: NextApiResponse): Promise<void>;
98
145
 
99
- declare const MOCK_COLLECTIONS: string[];
100
- declare const STATIC_COLLECTIONS: string[];
101
- declare const KNOWN_COLLECTIONS: string[];
102
- declare const COLLECTIONS: string[];
103
146
  declare function getStore<T extends IStore>(): Promise<T>;
104
147
 
105
- type ApiRequestOptions = FetchRequestOptions;
106
- declare function storeApiFetch(pathname: string, options?: ApiRequestOptions): Promise<any>;
107
- declare function storeApiGet(url: string, options?: ApiRequestOptions): Promise<any>;
108
- declare function storeApiPost(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
109
- declare function storeApiPut(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
110
- declare function storeApiPatch(url: string, payload: any, options?: ApiRequestOptions): Promise<any>;
111
- declare function storeApiDelete(url: string, options?: ApiRequestOptions): Promise<any>;
112
- declare class StoreApiService<T extends IEntity = IEntity> implements IQuerable<T> {
113
- key: string;
114
- constructor(key: string);
115
- findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
116
- findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
117
- findPaged<B extends T = T>(params?: QueryParams): Promise<{
118
- docs: B[];
119
- } & Pagination>;
120
- create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
121
- update<B extends T = T>(payload: Partial<B>): Promise<B>;
122
- delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
123
- protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
124
- }
125
-
126
- declare function getApiStore<T extends IStore>(collections: string[]): Promise<T>;
127
- declare function getApiRuntimeStore<T extends IStore>(collections: string[]): Promise<T>;
128
- declare function getApiBuildStore<T extends IStore>(): Promise<T>;
129
-
130
- 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, collectionDelete, collectionGet, collectionPatch, collectionPost, errorHandler, getApiBuildStore, getApiRuntimeStore, getApiStore, getApiUrl, getMockStore, getMockStoreFromData, getMockStoreServer, getStore, isApiRequest, isNextRequest, isObject, isRelation, isStaticRequest, mockHandler, routePost, staticCollections, storeApiDelete, storeApiFetch, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeHandler, storeStrategy };
148
+ export { ApiRequestOptions, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, KNOWN_COLLECTIONS, MOCK_COLLECTIONS, MapTo, MockService, RemoteService, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, collectionDelete, collectionGet, collectionPatch, collectionPost, defaultApiRequestOptions, errorHandler, fromCache, getDefaultApiRequestOptions, getLocalApiUrl, getMockStore, getRemoteStore, getStore, isApiRequest, isNextRequest, isObject, isRelation, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeHandler, storeStrategy };