@websolutespa/bom-mixer-store 0.0.1 → 0.1.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +11 -0
  3. package/dist/index.d.ts +66 -36
  4. package/dist/index.js +692 -1771
  5. package/dist/index.mjs +674 -1770
  6. package/package.json +24 -19
  7. package/.turbo/turbo-build.log +0 -17
  8. package/coverage/api/api.service.ts.html +0 -559
  9. package/coverage/api/api.store.ts.html +0 -253
  10. package/coverage/api/index.html +0 -131
  11. package/coverage/base.css +0 -224
  12. package/coverage/block-navigation.js +0 -87
  13. package/coverage/cobertura-coverage.xml +0 -517
  14. package/coverage/favicon.png +0 -0
  15. package/coverage/fs/fs.service.ts.html +0 -466
  16. package/coverage/fs/index.html +0 -116
  17. package/coverage/index.html +0 -176
  18. package/coverage/middleware/index.html +0 -116
  19. package/coverage/middleware/middleware.service.ts.html +0 -340
  20. package/coverage/mock/index.html +0 -161
  21. package/coverage/mock/mock.api.ts.html +0 -118
  22. package/coverage/mock/mock.interceptor.ts.html +0 -133
  23. package/coverage/mock/mock.service.ts.html +0 -178
  24. package/coverage/mock/mock.store.ts.html +0 -175
  25. package/coverage/prettify.css +0 -1
  26. package/coverage/prettify.js +0 -2
  27. package/coverage/sort-arrow-sprite.png +0 -0
  28. package/coverage/sorter.js +0 -196
  29. package/coverage/store/index.html +0 -131
  30. package/coverage/store/store.service.ts.html +0 -157
  31. package/coverage/store/store.ts.html +0 -172
  32. package/jest.config.ts +0 -3
  33. package/src/api/api.service.ts +0 -158
  34. package/src/api/api.store.ts +0 -56
  35. package/src/example.test.ts +0 -8
  36. package/src/fs/fs.service.ts +0 -127
  37. package/src/index.ts +0 -9
  38. package/src/middleware/middleware.service.ts +0 -85
  39. package/src/mock/mock.api.ts +0 -11
  40. package/src/mock/mock.interceptor.ts +0 -16
  41. package/src/mock/mock.service.ts +0 -31
  42. package/src/mock/mock.store.ts +0 -30
  43. package/src/store/store.service.ts +0 -24
  44. package/src/store/store.ts +0 -29
  45. package/tsconfig.json +0 -16
package/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
- ## 0.0.1
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - mock refactor.
8
+
9
+ ## 0.0.2
4
10
 
5
11
  ### Patch Changes
6
12
 
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @websolutespa/bom-mixer-store
2
+
3
+ [![npm version](https://badge.fury.io/js/%40websolutespa%2Fbom-mixer-store.svg)](https://badge.fury.io/js/%40websolutespa%2Fbom-mixer-store)
4
+
5
+ [![status alpha](https://img.shields.io/badge/status-alpha-red.svg)](https://shields.io/)
6
+
7
+ Mixer Store module of the [BOM Repository](https://github.com/websolutespa/bom) by [websolute](https://www.websolute.com/).
8
+
9
+ ---
10
+
11
+ ##### *this library is for internal usage and not production ready*
package/dist/index.d.ts CHANGED
@@ -1,38 +1,35 @@
1
- import { FetchRequestOptions, IEntity, IQuerable, QueryParams, IEquatable, JsonService } from '@websolutespa/bom-mixer-core';
2
- import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
3
-
4
- declare function apiFetch(pathname: string, options?: FetchRequestOptions): Promise<any>;
5
- declare function apiGet(url: string, options?: FetchRequestOptions): Promise<any>;
6
- declare function apiPost(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
7
- declare function apiPut(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
8
- declare function apiPatch(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
9
- declare function apiDelete(url: string, options?: FetchRequestOptions): Promise<any>;
10
- declare class ApiService<T extends IEntity> implements IQuerable<IEntity> {
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> {
11
12
  key: string;
12
13
  constructor(key: string);
13
- findOne(params?: QueryParams): Promise<T | undefined>;
14
- findMany(params?: QueryParams): Promise<T[]>;
15
- create(payload: any): Promise<T>;
16
- update(payload: T): Promise<T>;
17
- delete(id: IEquatable): Promise<any>;
18
- protected decorator_(item: any, params?: QueryParams): any;
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
- type Store = {
22
- [key: string]: IQuerable<IEntity>;
23
- };
24
- type MockStore = {
25
- [key: string]: any[];
26
- };
27
26
  declare enum StoreStrategy {
28
27
  Api = "api",
29
28
  Data = "data",
30
29
  Mock = "mock"
31
30
  }
32
- declare const storeStrategy: StoreStrategy;
33
- type IStore = {
34
- [key: string]: IQuerable<IEntity>;
35
- };
31
+ type IStore = Record<string, IQuerable<IEntity>>;
32
+ declare const storeStrategy: StoreStrategy;
36
33
 
37
34
  declare function getApiStore<T extends IStore>(collections: string[]): Promise<T>;
38
35
  declare function getApiRuntimeStore<T extends IStore>(collections: string[]): Promise<T>;
@@ -40,21 +37,54 @@ declare function getApiBuildStore<T extends IStore>(): Promise<T>;
40
37
 
41
38
  declare function isStaticRequest(request: NextRequest): boolean;
42
39
  declare function isNextRequest(request: NextRequest): boolean;
43
- declare function isApiRequest(request: NextRequest): boolean;
44
- declare function isExistingApiRoute(request: NextRequest): boolean;
40
+ declare function isApiRequest(request: NextRequest): boolean;
41
+
42
+ declare function mockHandler(getJson: () => Promise<string>): any;
45
43
 
46
- declare function resolveMockApi(api: string): Promise<any>;
47
- declare function parseMockApi(api: string): Promise<any>;
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
- declare function mockInterceptor(request: NextRequest, next: NextFetchEvent): Promise<NextResponse | undefined>;
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 MockService<T extends IEntity = any> extends JsonService<T> {
52
- protected decorator_(item: any, params?: QueryParams): any;
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 getMockStore<T extends IStore>(): Promise<T>;
82
+ declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
56
83
 
57
- declare function registerCollections(collections?: string[]): void;
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, MockStore, Store, StoreStrategy, apiDelete, apiFetch, apiGet, apiPatch, apiPost, apiPut, getApiBuildStore, getApiRuntimeStore, getApiStore, getMockStore, getStore, isApiRequest, isExistingApiRoute, isNextRequest, isStaticRequest, mockInterceptor, parseMockApi, registerCollections, resolveMockApi, storeStrategy };
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 };