@websolutespa/bom-mixer-store 0.1.0 → 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 CHANGED
@@ -1,13 +1,19 @@
1
- # @websolutespa/bom-mixer-store
2
-
3
- ## 0.1.0
4
-
5
- ### Minor Changes
6
-
7
- - mock refactor.
8
-
9
- ## 0.0.2
10
-
11
- ### Patch Changes
12
-
13
- - Added: first release.
1
+ # @websolutespa/bom-mixer-store
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: store service.
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - mock refactor.
14
+
15
+ ## 0.0.2
16
+
17
+ ### Patch Changes
18
+
19
+ - Added: first release.
package/dist/index.d.ts CHANGED
@@ -1,90 +1,90 @@
1
1
  import { FetchRequestOptions, IEntity, IQuerable, IEquatable, QueryParams, Pagination, JsonService } from '@websolutespa/bom-mixer-core';
2
2
  import { NextRequest } from 'next/server';
3
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;
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;
24
24
  }
25
25
 
26
- declare enum StoreStrategy {
27
- Api = "api",
28
- Data = "data",
29
- Mock = "mock"
30
- }
31
- type IStore = Record<string, IQuerable<IEntity>>;
26
+ declare enum StoreStrategy {
27
+ Api = "api",
28
+ Data = "data",
29
+ Mock = "mock"
30
+ }
31
+ type IStore = Record<string, IQuerable<IEntity>>;
32
32
  declare const storeStrategy: StoreStrategy;
33
33
 
34
- declare function getApiStore<T extends IStore>(collections: string[]): Promise<T>;
35
- 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>;
36
36
  declare function getApiBuildStore<T extends IStore>(): Promise<T>;
37
37
 
38
- declare function isStaticRequest(request: NextRequest): boolean;
39
- declare function isNextRequest(request: NextRequest): boolean;
38
+ declare function isStaticRequest(request: NextRequest): boolean;
39
+ declare function isNextRequest(request: NextRequest): boolean;
40
40
  declare function isApiRequest(request: NextRequest): boolean;
41
41
 
42
42
  declare function mockHandler(getJson: () => Promise<string>): any;
43
43
 
44
- declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
45
- protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
44
+ declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
45
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
46
46
  }
47
47
 
48
- declare function getMockStoreServer<T extends IStore>(): Promise<T>;
49
- declare function getMockStore<T extends IStore>(getJson: () => Promise<string>): Promise<T>;
48
+ declare function getMockStoreServer<T extends IStore>(): Promise<T>;
49
+ declare function getMockStore<T extends IStore>(getJson: () => Promise<string>): Promise<T>;
50
50
  declare function getMockStoreFromData<T extends IStore>(data: Record<string, IEntity[]>): T;
51
51
 
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
- };
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
68
  declare const staticCollections: StaticServiceConfig[];
69
69
 
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;
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;
80
80
  }
81
81
 
82
82
  declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
83
83
 
84
- declare const MOCK_COLLECTIONS: string[];
85
- declare const STATIC_COLLECTIONS: string[];
86
- declare const KNOWN_COLLECTIONS: string[];
87
- declare const COLLECTIONS: string[];
84
+ declare const MOCK_COLLECTIONS: string[];
85
+ declare const STATIC_COLLECTIONS: string[];
86
+ declare const KNOWN_COLLECTIONS: string[];
87
+ declare const COLLECTIONS: string[];
88
88
  declare function getStore<T extends IStore>(): Promise<T>;
89
89
 
90
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 };
package/dist/index.js CHANGED
@@ -224,6 +224,9 @@ var ApiService = class {
224
224
  */
225
225
  };
226
226
 
227
+ // src/api/api.store.ts
228
+ var import_bom_mixer_core6 = require("@websolutespa/bom-mixer-core");
229
+
227
230
  // src/mock/mock.service.ts
228
231
  var import_bom_mixer_core2 = require("@websolutespa/bom-mixer-core");
229
232
  var MockService = class extends import_bom_mixer_core2.JsonService {
@@ -236,6 +239,9 @@ var MockService = class extends import_bom_mixer_core2.JsonService {
236
239
  }
237
240
  };
238
241
 
242
+ // src/mock/mock.store.ts
243
+ var import_bom_mixer_core5 = require("@websolutespa/bom-mixer-core");
244
+
239
245
  // src/fs/fs.service.ts
240
246
  var path = require("path");
241
247
  var fs = require("fs");
@@ -632,8 +638,10 @@ async function getMockStoreServer() {
632
638
  const pathname = path2.join(process.cwd(), ".mixer", "store.json");
633
639
  const data = await fsReadJson(pathname);
634
640
  const store = getMockStoreFromData(data);
635
- STORE_ = store;
636
- return STORE_;
641
+ if (!import_bom_mixer_core5.isDevelopment) {
642
+ STORE_ = store;
643
+ }
644
+ return store;
637
645
  }
638
646
  async function getMockStore(getJson) {
639
647
  if (STORE_) {
@@ -642,8 +650,10 @@ async function getMockStore(getJson) {
642
650
  const json = await getJson();
643
651
  const data = JSON.parse(json);
644
652
  const store = getMockStoreFromData(data);
645
- STORE_ = store;
646
- return STORE_;
653
+ if (!import_bom_mixer_core5.isDevelopment) {
654
+ STORE_ = store;
655
+ }
656
+ return store;
647
657
  }
648
658
  function getMockStoreFromData(data) {
649
659
  const store = {};
@@ -725,7 +735,9 @@ async function getApiRuntimeStore(collections) {
725
735
  store[key] = new ApiService(key);
726
736
  }
727
737
  });
728
- RUNTIME_STORE_ = store;
738
+ if (!import_bom_mixer_core6.isDevelopment) {
739
+ RUNTIME_STORE_ = store;
740
+ }
729
741
  return store;
730
742
  }
731
743
  var BUILD_STORE_;
@@ -768,9 +780,9 @@ function isApiRequest(request) {
768
780
  }
769
781
 
770
782
  // src/store/store.handler.ts
771
- var import_bom_mixer_core5 = require("@websolutespa/bom-mixer-core");
783
+ var import_bom_mixer_core7 = require("@websolutespa/bom-mixer-core");
772
784
  function storeHandler(storePromise = async () => await getStore()) {
773
- return (0, import_bom_mixer_core5.apiHandler)({
785
+ return (0, import_bom_mixer_core7.apiHandler)({
774
786
  // find a specific document by id or
775
787
  // find paginated documents
776
788
  get: async (request, response) => {
@@ -783,7 +795,7 @@ function storeHandler(storePromise = async () => await getStore()) {
783
795
  const collection = collections[0];
784
796
  const id = collections[1];
785
797
  const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
786
- const params = (0, import_bom_mixer_core5.qsDeserialize)(qs);
798
+ const params = (0, import_bom_mixer_core7.qsDeserialize)(qs);
787
799
  if (!COLLECTIONS.includes(collection)) {
788
800
  console.error("method not allowed", collection);
789
801
  return response.status(405).send("method not allowed");
@@ -795,7 +807,7 @@ function storeHandler(storePromise = async () => await getStore()) {
795
807
  return response.status(405).send("method not allowed");
796
808
  }
797
809
  if (id) {
798
- const item = await service.findOne((0, import_bom_mixer_core5.asEquatable)(id), params);
810
+ const item = await service.findOne((0, import_bom_mixer_core7.asEquatable)(id), params);
799
811
  if (item) {
800
812
  return response.status(200).json(item);
801
813
  } else {
package/dist/index.mjs CHANGED
@@ -179,6 +179,9 @@ var ApiService = class {
179
179
  */
180
180
  };
181
181
 
182
+ // src/api/api.store.ts
183
+ import { isDevelopment as isDevelopment2 } from "@websolutespa/bom-mixer-core";
184
+
182
185
  // src/mock/mock.service.ts
183
186
  import { JsonService, localizeItem } from "@websolutespa/bom-mixer-core";
184
187
  var MockService = class extends JsonService {
@@ -191,6 +194,9 @@ var MockService = class extends JsonService {
191
194
  }
192
195
  };
193
196
 
197
+ // src/mock/mock.store.ts
198
+ import { isDevelopment } from "@websolutespa/bom-mixer-core";
199
+
194
200
  // src/fs/fs.service.ts
195
201
  var path = __require("path");
196
202
  var fs = __require("fs");
@@ -587,8 +593,10 @@ async function getMockStoreServer() {
587
593
  const pathname = path2.join(process.cwd(), ".mixer", "store.json");
588
594
  const data = await fsReadJson(pathname);
589
595
  const store = getMockStoreFromData(data);
590
- STORE_ = store;
591
- return STORE_;
596
+ if (!isDevelopment) {
597
+ STORE_ = store;
598
+ }
599
+ return store;
592
600
  }
593
601
  async function getMockStore(getJson) {
594
602
  if (STORE_) {
@@ -597,8 +605,10 @@ async function getMockStore(getJson) {
597
605
  const json = await getJson();
598
606
  const data = JSON.parse(json);
599
607
  const store = getMockStoreFromData(data);
600
- STORE_ = store;
601
- return STORE_;
608
+ if (!isDevelopment) {
609
+ STORE_ = store;
610
+ }
611
+ return store;
602
612
  }
603
613
  function getMockStoreFromData(data) {
604
614
  const store = {};
@@ -680,7 +690,9 @@ async function getApiRuntimeStore(collections) {
680
690
  store[key] = new ApiService(key);
681
691
  }
682
692
  });
683
- RUNTIME_STORE_ = store;
693
+ if (!isDevelopment2) {
694
+ RUNTIME_STORE_ = store;
695
+ }
684
696
  return store;
685
697
  }
686
698
  var BUILD_STORE_;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -41,8 +41,8 @@
41
41
  "npm-run-all": "^4.1.5",
42
42
  "react": "^18.2.0",
43
43
  "ts-node": "^10.9.1",
44
- "tsup": "^6.6.3",
45
- "typescript": "^4.8.2"
44
+ "tsup": "^6.7.0",
45
+ "typescript": "^4.8.4"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"