@websolutespa/bom-mixer-store 1.1.1 → 1.2.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.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: MockMenuService collectPages.
8
+
9
+ ## 1.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Updating: next 13.
14
+
3
15
  ## 1.1.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -271,8 +271,7 @@ var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
271
271
  var import_bom_core7 = require("@websolutespa/bom-core");
272
272
 
273
273
  // src/fs/fs.service.ts
274
- var path = require("path");
275
- var fs = require("fs");
274
+ var fs = __toESM(require("fs"));
276
275
  async function fsRead(pathname, option) {
277
276
  try {
278
277
  const data = await fs.promises.readFile(pathname, option?.encoding || "utf8");
@@ -696,7 +695,7 @@ async function collectPages(store, items, params = {}) {
696
695
  }
697
696
  for (const item of items) {
698
697
  if (item.type === "page" && typeof item.page.value === "number" && store[item.page.relationTo] !== void 0) {
699
- const value = await store[item.page.relationTo].findOne(item.page.value, params);
698
+ const value = await store[item.page.relationTo].findOne(item.page.value, { ...params });
700
699
  if (value) {
701
700
  item.page.value = value;
702
701
  }
@@ -971,8 +970,8 @@ function getMockStoreFromData_(data) {
971
970
  }
972
971
  async function getStoreData_() {
973
972
  if (import_bom_core7.isDevelopment) {
974
- const path2 = require("path");
975
- const pathname = path2.join(process.cwd(), ".mixer", "store.json");
973
+ const path = require("path");
974
+ const pathname = path.join(process.cwd(), ".mixer", "store.json");
976
975
  return await fsReadJson(pathname) || {};
977
976
  } else {
978
977
  const store = process.env.STORE_ || {};
package/dist/index.mjs CHANGED
@@ -190,8 +190,7 @@ var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
190
190
  import { isDevelopment } from "@websolutespa/bom-core";
191
191
 
192
192
  // src/fs/fs.service.ts
193
- var path = __require("path");
194
- var fs = __require("fs");
193
+ import * as fs from "fs";
195
194
  async function fsRead(pathname, option) {
196
195
  try {
197
196
  const data = await fs.promises.readFile(pathname, option?.encoding || "utf8");
@@ -617,7 +616,7 @@ async function collectPages(store, items, params = {}) {
617
616
  }
618
617
  for (const item of items) {
619
618
  if (item.type === "page" && typeof item.page.value === "number" && store[item.page.relationTo] !== void 0) {
620
- const value = await store[item.page.relationTo].findOne(item.page.value, params);
619
+ const value = await store[item.page.relationTo].findOne(item.page.value, { ...params });
621
620
  if (value) {
622
621
  item.page.value = value;
623
622
  }
@@ -892,8 +891,8 @@ function getMockStoreFromData_(data) {
892
891
  }
893
892
  async function getStoreData_() {
894
893
  if (isDevelopment) {
895
- const path2 = __require("path");
896
- const pathname = path2.join(process.cwd(), ".mixer", "store.json");
894
+ const path = __require("path");
895
+ const pathname = path.join(process.cwd(), ".mixer", "store.json");
897
896
  return await fsReadJson(pathname) || {};
898
897
  } else {
899
898
  const store = process.env.STORE_ || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -28,19 +28,19 @@
28
28
  "peerDependencies": {
29
29
  "@websolutespa/bom-core": "*",
30
30
  "iron-session": ">= 6.2.1",
31
- "next": ">= 12.3.2"
31
+ "next": ">= 13.4.19"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/mime": "^3.0.1",
35
35
  "@websolutespa/bom-cli": "*",
36
36
  "@websolutespa/test": "*",
37
37
  "@websolutespa/tsconfig": "*",
38
- "eslint": "^8.36.0",
38
+ "eslint": "^8.46.0",
39
39
  "eslint-config-websolute": "*",
40
40
  "npm-run-all": "^4.1.5",
41
41
  "ts-node": "^10.9.1",
42
42
  "tsup": "^6.7.0",
43
- "typescript": "^4.8.4"
43
+ "typescript": "^5.1.6"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
@@ -1,15 +1,17 @@
1
1
  import { Json } from '@websolutespa/bom-core';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
2
4
 
3
- /* eslint-disable @typescript-eslint/no-var-requires */
4
- const path = require('path');
5
- const fs = require('fs');
6
-
7
- export type TFsReadOption = {
5
+ export type fsReadOptions = {
8
6
  encoding?: null | undefined;
9
7
  flag?: number | string | undefined;
10
8
  signal?: AbortSignal | undefined;
11
9
  };
12
10
 
11
+ export type fsWatchOptions = (fs.WatchOptions & { encoding: 'buffer' }) | 'buffer';
12
+ export type fsWatchFileOptions = (fs.WatchFileOptions & { bigint?: false });
13
+ export type fsWriteFileOptions = (fs.ObjectEncodingOptions & { mode?: fs.Mode; flag?: fs.OpenMode }) | BufferEncoding | null;
14
+
13
15
  export async function fsExists(pathname: string): Promise<boolean> {
14
16
  try {
15
17
  await fs.promises.access(pathname);
@@ -19,7 +21,7 @@ export async function fsExists(pathname: string): Promise<boolean> {
19
21
  }
20
22
  }
21
23
 
22
- export async function fsRead(pathname: string, option?: TFsReadOption): Promise<string | undefined> {
24
+ export async function fsRead(pathname: string, option?: fsReadOptions): Promise<string | undefined> {
23
25
  try {
24
26
  const data = await fs.promises.readFile(pathname, option?.encoding || 'utf8');
25
27
  return data || undefined;
@@ -45,7 +47,7 @@ export async function fsReadJson<T = Json>(pathname: string): Promise<T | undefi
45
47
  }
46
48
  }
47
49
 
48
- export async function fsWrite(pathname: string, data: string, encoding = 'utf8'): Promise<void> {
50
+ export async function fsWrite(pathname: string, data: string, encoding: fsWriteFileOptions = 'utf8'): Promise<void> {
49
51
  try {
50
52
  await fs.promises.mkdir(path.dirname(pathname), { recursive: true });
51
53
  await fs.promises.writeFile(pathname, data, encoding);
@@ -54,7 +56,7 @@ export async function fsWrite(pathname: string, data: string, encoding = 'utf8')
54
56
  }
55
57
  }
56
58
 
57
- export async function fsWriteJson(pathname: string, data: any): Promise<void> {
59
+ export async function fsWriteJson(pathname: string, data: Json): Promise<void> {
58
60
  try {
59
61
  await fsWrite(pathname, JSON.stringify(data, null, 2));
60
62
  } catch (error) {
@@ -111,12 +113,12 @@ export async function fsReadJsonDirectory(pathname: string): Promise<{ name: str
111
113
  }
112
114
  }
113
115
 
114
- export function fsWatch(pathname: string, callback: (eventType: any, fileName: string) => void, options?: { interval: 2000 }): void {
116
+ export function fsWatch(pathname: string, callback: (eventType: fs.WatchEventType, fileName: string) => void, options: fsWatchOptions) {
115
117
  const debounced = debounce(callback);
116
118
  return fs.watch(pathname, options, debounced);
117
119
  }
118
120
 
119
- export function fsWatchFile(pathname: string, callback: (eventType: any, fileName: string) => void, options?: { interval: 2000 }): void {
121
+ export function fsWatchFile(pathname: string, callback: (eventType: fs.WatchEventType, fileName: string) => void, options?: fsWatchFileOptions) {
120
122
  const debounced = debounce(callback);
121
123
  return fs.watchFile(pathname, options, debounced);
122
124
  }
@@ -59,7 +59,9 @@ async function collectPages(store: IStore, items?: IUndecoratedMenuItem[], param
59
59
  typeof item.page.value === 'number' &&
60
60
  store[item.page.relationTo] !== undefined
61
61
  ) {
62
- const value = await store[item.page.relationTo].findOne<ICategorized>(item.page.value, params);
62
+ // console.log('collectPages', item.page.relationTo, item.page.value);
63
+ // !!! cloned params due to recursion
64
+ const value = await store[item.page.relationTo].findOne<ICategorized>(item.page.value, { ...params });
63
65
  if (value) {
64
66
  item.page.value = value;
65
67
  }
@@ -88,9 +90,9 @@ export async function decorateMenu(store: IStore, item: IUndecoratedMenu, market
88
90
  },
89
91
  locale: {
90
92
  equals: locale,
91
- }
93
+ },
92
94
  },
93
- market, locale
95
+ market, locale,
94
96
  });
95
97
  await collectPages(store, items, { market, locale });
96
98
  decoratedItem.items = items.filter(x => hasMarket(x, market)).map(x => decorateMenuItem(x, categories, routes, market));
@@ -106,7 +108,7 @@ export function decorateMenuCategory(
106
108
  categories: ICategory[],
107
109
  routes: IRoute[],
108
110
  market: string,
109
- depth: number = 0,
111
+ depth: number = 0
110
112
  ): IMenuItem {
111
113
  const decoratedItem: IMenuCategory = {
112
114
  abstract: item.abstract,
@@ -174,7 +176,7 @@ export function decorateMenuCategory(
174
176
  }
175
177
 
176
178
  export function decorateMenuRoute(
177
- item: IRoute,
179
+ item: IRoute
178
180
  ): IMenuItem {
179
181
  const decoratedItem: IMenuRoute = {
180
182
  id: item.page,
@@ -192,7 +194,7 @@ export function decorateMenuGroup(
192
194
  item: IUndecoratedMenuGroup,
193
195
  categories: ICategory[],
194
196
  routes: IRoute[],
195
- market: string,
197
+ market: string
196
198
  ): IMenuItem {
197
199
  const items = item.items || [];
198
200
  const decoratedItem: IMenuGroup = {
@@ -210,7 +212,7 @@ export function decorateMenuLink(
210
212
  item: IUndecoratedMenuLink,
211
213
  categories: ICategory[],
212
214
  routes: IRoute[],
213
- market: string,
215
+ market: string
214
216
  ): IMenuItem {
215
217
  const items = item.items || [];
216
218
  const decoratedItem: IMenuLink = {
@@ -230,7 +232,7 @@ export function decorateMenuPage(
230
232
  item: IUndecoratedMenuPage,
231
233
  categories: ICategory[],
232
234
  routes: IRoute[],
233
- market: string,
235
+ market: string
234
236
  ): IMenuItem {
235
237
  const items = item.items || [];
236
238
  const route = routes.find(x => x.schema === item.page.relationTo && x.page === item.page.value.id);
@@ -254,7 +256,7 @@ export function decorateMenuItem(
254
256
  categories: ICategory[],
255
257
  routes: IRoute[],
256
258
  market: string,
257
- depth: number = 0,
259
+ depth: number = 0
258
260
  ): IMenuItem {
259
261
  let decoratedItem: IMenuItem;
260
262
  switch (item.type) {