@websolutespa/bom-core 0.2.1 → 0.4.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/dist/index.js CHANGED
@@ -40,7 +40,6 @@ __export(src_exports, {
40
40
  camelToSnakeCase: () => camelToSnakeCase,
41
41
  collectRoutes: () => collectRoutes,
42
42
  consoleWarn: () => consoleWarn,
43
- deepCopy: () => deepCopy,
44
43
  deserializeKey: () => deserializeKey,
45
44
  deserializeValue: () => deserializeValue,
46
45
  eachCategorized: () => eachCategorized,
@@ -50,6 +49,7 @@ __export(src_exports, {
50
49
  getCategorySegmentsByCategory: () => getCategorySegmentsByCategory,
51
50
  getClassNames: () => getClassNames,
52
51
  getCollectionDescription: () => getCollectionDescription,
52
+ getEnv: () => getEnv,
53
53
  getIsDevelopment: () => getIsDevelopment,
54
54
  getIsProduction: () => getIsProduction,
55
55
  getParentCategoriesById: () => getParentCategoriesById,
@@ -102,13 +102,14 @@ function getRootCategory(categories) {
102
102
  }
103
103
  }
104
104
  function getParentCategoriesById(id, categories) {
105
+ const rootCategory = getRootCategory(categories);
105
106
  const routeCategories = [];
106
107
  const segments = [];
107
108
  let parentId = id || null;
108
109
  while (parentId != null) {
109
110
  const parentCategory = categories.find((c) => c.id === parentId);
110
111
  if (parentCategory) {
111
- if (parentCategory.slug) {
112
+ if (parentCategory.slug || parentCategory.id === rootCategory?.id) {
112
113
  const segment = { ...parentCategory };
113
114
  segments.unshift(segment);
114
115
  }
@@ -130,7 +131,6 @@ function getParentCategoriesById(id, categories) {
130
131
  function getCategorySegments(item, categories) {
131
132
  const categoryId = asCategoryId(item.category);
132
133
  const segments = getParentCategoriesById(categoryId, categories);
133
- [];
134
134
  if (item.isDefault !== true) {
135
135
  const category = categories.find((x) => x.id === item.category);
136
136
  if (category) {
@@ -197,7 +197,7 @@ function getCollectionDescription(text) {
197
197
  text = toValidCollectionName(text);
198
198
  const displayName = toDisplayName(text);
199
199
  const pluralName = toPluralName(text);
200
- const pluralDisplayName = toPluralName(displayName);
200
+ const pluralDisplayName = toDisplayName(pluralName);
201
201
  const singularName = text;
202
202
  const title = toTitleCase(text);
203
203
  return {
@@ -208,29 +208,30 @@ function getCollectionDescription(text) {
208
208
  title
209
209
  };
210
210
  }
211
- function isValidCollectionDescription(description) {
212
- return description.singularName !== description.pluralName;
213
- }
214
- function toValidCollectionName(text) {
215
- text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
216
- text = camelToSnakeCase(text);
217
- text = text.replace(/__/g, "_");
218
- return text.toLowerCase();
219
- }
220
211
  function camelToSnakeCase(text) {
221
212
  return text.replace(/[A-Z]/g, (letter, index) => {
222
213
  return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
223
214
  });
224
215
  }
216
+ function isValidCollectionDescription(description) {
217
+ return description.singularName !== description.pluralName;
218
+ }
225
219
  function toDisplayName(text) {
226
220
  return toTitleCase(text).replace(/\s/g, "");
227
221
  }
228
222
  function toPluralName(text) {
229
- return import_pluralize.default.plural(text);
223
+ const plural = import_pluralize.default.plural(text);
224
+ return plural === text ? `${plural}es` : plural;
230
225
  }
231
226
  function toTitleCase(text) {
232
227
  return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
233
228
  }
229
+ function toValidCollectionName(text) {
230
+ text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
231
+ text = camelToSnakeCase(text);
232
+ text = text.replace(/__/g, "_");
233
+ return text.toLowerCase();
234
+ }
234
235
 
235
236
  // src/consoleWarn/consoleWarn.ts
236
237
  var warningStack = {};
@@ -270,6 +271,14 @@ var isDevelopment = getIsDevelopment();
270
271
  var isProduction = getIsProduction();
271
272
  var isStage = !isProduction && !isDevelopment;
272
273
  var isBrowser = typeof window !== "undefined";
274
+ function getEnv() {
275
+ const env = {};
276
+ const keys = Object.keys(process.env).sort();
277
+ keys.forEach((key) => {
278
+ env[key] = process.env[key];
279
+ });
280
+ return env;
281
+ }
273
282
  function withSchema(component, schema) {
274
283
  return Object.assign(component, schema);
275
284
  }
@@ -303,19 +312,6 @@ function merge(target, source) {
303
312
  }
304
313
  return target;
305
314
  }
306
- function deepCopy(source) {
307
- if (Array.isArray(source)) {
308
- return source.map((x) => deepCopy(x));
309
- } else if (source && typeof source === "object") {
310
- const copy = {};
311
- Object.keys(source).forEach((key) => {
312
- copy[key] = deepCopy(source[key]);
313
- });
314
- return copy;
315
- } else {
316
- return source;
317
- }
318
- }
319
315
 
320
316
  // src/http/http.service.ts
321
317
  var defaultOptions = {
@@ -332,13 +328,22 @@ var defaultOptions = {
332
328
  // body: JSON.stringify(data) // body data type must match 'Content-Type' header
333
329
  };
334
330
  async function httpFetch(url, options = {}, serviceOptions) {
335
- const httpOptions = merge({ ...defaultOptions }, options);
336
- const httpResponse = await fetch(url, httpOptions);
337
- if (!httpResponse.ok) {
338
- throw httpResponse;
331
+ try {
332
+ const httpOptions = merge({ ...defaultOptions }, options);
333
+ const httpResponse = await fetch(url, httpOptions);
334
+ if (!httpResponse.ok) {
335
+ throw httpResponse;
336
+ }
337
+ const response = await httpResponse.json();
338
+ return response;
339
+ } catch (error) {
340
+ if (typeof error === "object" && error.status) {
341
+ console.log("httpFetch.error", options.method, url, error.status, error.statusText);
342
+ } else {
343
+ console.log("httpFetch.error", options.method, url, error);
344
+ }
345
+ throw error;
339
346
  }
340
- const response = await httpResponse.json();
341
- return response;
342
347
  }
343
348
  async function httpGet(url, options = {}) {
344
349
  return await httpFetch(url, { ...options, method: "GET" });
@@ -875,7 +880,6 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
875
880
  camelToSnakeCase,
876
881
  collectRoutes,
877
882
  consoleWarn,
878
- deepCopy,
879
883
  deserializeKey,
880
884
  deserializeValue,
881
885
  eachCategorized,
@@ -885,6 +889,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
885
889
  getCategorySegmentsByCategory,
886
890
  getClassNames,
887
891
  getCollectionDescription,
892
+ getEnv,
888
893
  getIsDevelopment,
889
894
  getIsProduction,
890
895
  getParentCategoriesById,
package/dist/index.mjs CHANGED
@@ -15,13 +15,14 @@ function getRootCategory(categories) {
15
15
  }
16
16
  }
17
17
  function getParentCategoriesById(id, categories) {
18
+ const rootCategory = getRootCategory(categories);
18
19
  const routeCategories = [];
19
20
  const segments = [];
20
21
  let parentId = id || null;
21
22
  while (parentId != null) {
22
23
  const parentCategory = categories.find((c) => c.id === parentId);
23
24
  if (parentCategory) {
24
- if (parentCategory.slug) {
25
+ if (parentCategory.slug || parentCategory.id === rootCategory?.id) {
25
26
  const segment = { ...parentCategory };
26
27
  segments.unshift(segment);
27
28
  }
@@ -43,7 +44,6 @@ function getParentCategoriesById(id, categories) {
43
44
  function getCategorySegments(item, categories) {
44
45
  const categoryId = asCategoryId(item.category);
45
46
  const segments = getParentCategoriesById(categoryId, categories);
46
- [];
47
47
  if (item.isDefault !== true) {
48
48
  const category = categories.find((x) => x.id === item.category);
49
49
  if (category) {
@@ -110,7 +110,7 @@ function getCollectionDescription(text) {
110
110
  text = toValidCollectionName(text);
111
111
  const displayName = toDisplayName(text);
112
112
  const pluralName = toPluralName(text);
113
- const pluralDisplayName = toPluralName(displayName);
113
+ const pluralDisplayName = toDisplayName(pluralName);
114
114
  const singularName = text;
115
115
  const title = toTitleCase(text);
116
116
  return {
@@ -121,29 +121,30 @@ function getCollectionDescription(text) {
121
121
  title
122
122
  };
123
123
  }
124
- function isValidCollectionDescription(description) {
125
- return description.singularName !== description.pluralName;
126
- }
127
- function toValidCollectionName(text) {
128
- text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
129
- text = camelToSnakeCase(text);
130
- text = text.replace(/__/g, "_");
131
- return text.toLowerCase();
132
- }
133
124
  function camelToSnakeCase(text) {
134
125
  return text.replace(/[A-Z]/g, (letter, index) => {
135
126
  return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
136
127
  });
137
128
  }
129
+ function isValidCollectionDescription(description) {
130
+ return description.singularName !== description.pluralName;
131
+ }
138
132
  function toDisplayName(text) {
139
133
  return toTitleCase(text).replace(/\s/g, "");
140
134
  }
141
135
  function toPluralName(text) {
142
- return pluralize.plural(text);
136
+ const plural = pluralize.plural(text);
137
+ return plural === text ? `${plural}es` : plural;
143
138
  }
144
139
  function toTitleCase(text) {
145
140
  return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
146
141
  }
142
+ function toValidCollectionName(text) {
143
+ text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
144
+ text = camelToSnakeCase(text);
145
+ text = text.replace(/__/g, "_");
146
+ return text.toLowerCase();
147
+ }
147
148
 
148
149
  // src/consoleWarn/consoleWarn.ts
149
150
  var warningStack = {};
@@ -183,6 +184,14 @@ var isDevelopment = getIsDevelopment();
183
184
  var isProduction = getIsProduction();
184
185
  var isStage = !isProduction && !isDevelopment;
185
186
  var isBrowser = typeof window !== "undefined";
187
+ function getEnv() {
188
+ const env = {};
189
+ const keys = Object.keys(process.env).sort();
190
+ keys.forEach((key) => {
191
+ env[key] = process.env[key];
192
+ });
193
+ return env;
194
+ }
186
195
  function withSchema(component, schema) {
187
196
  return Object.assign(component, schema);
188
197
  }
@@ -216,19 +225,6 @@ function merge(target, source) {
216
225
  }
217
226
  return target;
218
227
  }
219
- function deepCopy(source) {
220
- if (Array.isArray(source)) {
221
- return source.map((x) => deepCopy(x));
222
- } else if (source && typeof source === "object") {
223
- const copy = {};
224
- Object.keys(source).forEach((key) => {
225
- copy[key] = deepCopy(source[key]);
226
- });
227
- return copy;
228
- } else {
229
- return source;
230
- }
231
- }
232
228
 
233
229
  // src/http/http.service.ts
234
230
  var defaultOptions = {
@@ -245,13 +241,22 @@ var defaultOptions = {
245
241
  // body: JSON.stringify(data) // body data type must match 'Content-Type' header
246
242
  };
247
243
  async function httpFetch(url, options = {}, serviceOptions) {
248
- const httpOptions = merge({ ...defaultOptions }, options);
249
- const httpResponse = await fetch(url, httpOptions);
250
- if (!httpResponse.ok) {
251
- throw httpResponse;
244
+ try {
245
+ const httpOptions = merge({ ...defaultOptions }, options);
246
+ const httpResponse = await fetch(url, httpOptions);
247
+ if (!httpResponse.ok) {
248
+ throw httpResponse;
249
+ }
250
+ const response = await httpResponse.json();
251
+ return response;
252
+ } catch (error) {
253
+ if (typeof error === "object" && error.status) {
254
+ console.log("httpFetch.error", options.method, url, error.status, error.statusText);
255
+ } else {
256
+ console.log("httpFetch.error", options.method, url, error);
257
+ }
258
+ throw error;
252
259
  }
253
- const response = await httpResponse.json();
254
- return response;
255
260
  }
256
261
  async function httpGet(url, options = {}) {
257
262
  return await httpFetch(url, { ...options, method: "GET" });
@@ -787,7 +792,6 @@ export {
787
792
  camelToSnakeCase,
788
793
  collectRoutes,
789
794
  consoleWarn,
790
- deepCopy,
791
795
  deserializeKey,
792
796
  deserializeValue,
793
797
  eachCategorized,
@@ -797,6 +801,7 @@ export {
797
801
  getCategorySegmentsByCategory,
798
802
  getClassNames,
799
803
  getCollectionDescription,
804
+ getEnv,
800
805
  getIsDevelopment,
801
806
  getIsProduction,
802
807
  getParentCategoriesById,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -26,19 +26,19 @@
26
26
  "pluralize": "latest"
27
27
  },
28
28
  "peerDependencies": {
29
- "next": ">= 12.3.2"
29
+ "next": ">= 13.4.19"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@websolutespa/bom-cli": "*",
33
33
  "@websolutespa/test": "*",
34
34
  "@websolutespa/tsconfig": "*",
35
- "eslint": "^8.36.0",
35
+ "eslint": "^8.46.0",
36
36
  "eslint-config-websolute": "*",
37
37
  "npm-run-all": "^4.1.5",
38
38
  "raw-loader": "^4.0.2",
39
39
  "ts-node": "^10.9.1",
40
40
  "tsup": "^6.7.0",
41
- "typescript": "^4.8.4"
41
+ "typescript": "^5.1.6"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"