@websolutespa/bom-core 0.3.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Updating: next 13.
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,549 +1,545 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
2
  import { ParsedUrlQuery } from 'querystring';
3
3
 
4
- type Json = string | number | boolean | null | Json[] | {
5
- [key: string]: Json;
6
- };
7
- type ValueOf<T> = T[keyof T];
8
- type LiteralUnion<T extends string | number> = T | Omit<T, T>;
9
- type PreviewData = string | false | object | undefined;
10
- type IContextBaseParams = {
11
- market: string;
12
- locale: string;
13
- };
14
- type IContextParams = IContextBaseParams & {
15
- id: string;
16
- };
17
- type StaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = {
18
- params: Q;
19
- preview?: boolean;
20
- previewData?: D;
21
- locale?: string;
22
- locales?: string[];
23
- defaultLocale?: string;
24
- };
25
- type IStaticContext<T extends {} = {}> = StaticPropsContext<IContextParams & T>;
26
- declare type NextApiRequestCookies = Partial<{
27
- [key: string]: string;
28
- }>;
29
- type ServerSidePropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = {
30
- req: IncomingMessage & {
31
- cookies: NextApiRequestCookies;
32
- };
33
- res: ServerResponse;
34
- params: Q;
35
- query: ParsedUrlQuery;
36
- preview?: boolean;
37
- previewData?: D;
38
- resolvedUrl: string;
39
- locale?: string;
40
- locales?: string[];
41
- defaultLocale?: string;
42
- };
43
- type IServerSideSplatContext<T extends {} = {}> = ServerSidePropsContext<IContextBaseParams & T>;
44
- type IServerSideContext<T extends {} = {}> = ServerSidePropsContext<IContextParams & T>;
45
- type StateValue = StateValue[] | {
46
- [key: string]: StateValue;
47
- } | number | string | boolean | null | undefined;
48
- type IPartial<T> = {
49
- [P in keyof T]?: Partial<T[P]>;
50
- };
51
- type IPrettify<T> = {
52
- [K in keyof T]: T[K];
53
- } & {};
54
- type IOverride<T, TypeToReplace, TypeToReplaceWith> = {
55
- [K in keyof T]: T[K] extends Record<string, unknown> ? IOverride<T[K], TypeToReplace, TypeToReplaceWith> : T[K] extends TypeToReplace ? TypeToReplaceWith : T[K];
56
- };
57
-
58
- type ILocalizedString = Record<string, string>;
59
- type ILocalizable = string | ILocalizedString;
4
+ type Json = string | number | boolean | null | Json[] | {
5
+ [key: string]: Json;
6
+ };
7
+ type ValueOf<T> = T[keyof T];
8
+ type LiteralUnion<T extends string | number> = T | Omit<T, T>;
9
+ type PreviewData = string | false | object | undefined;
10
+ type IContextBaseParams = {
11
+ market: string;
12
+ locale: string;
13
+ };
14
+ type IContextParams = IContextBaseParams & {
15
+ id: string;
16
+ };
17
+ type StaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = {
18
+ params: Q;
19
+ preview?: boolean;
20
+ previewData?: D;
21
+ locale?: string;
22
+ locales?: string[];
23
+ defaultLocale?: string;
24
+ };
25
+ type IStaticContext<T extends {} = {}> = StaticPropsContext<IContextParams & T>;
26
+ declare type NextApiRequestCookies = Partial<{
27
+ [key: string]: string;
28
+ }>;
29
+ type ServerSidePropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = {
30
+ req: IncomingMessage & {
31
+ cookies: NextApiRequestCookies;
32
+ };
33
+ res: ServerResponse;
34
+ params: Q;
35
+ query: ParsedUrlQuery;
36
+ preview?: boolean;
37
+ previewData?: D;
38
+ resolvedUrl: string;
39
+ locale?: string;
40
+ locales?: string[];
41
+ defaultLocale?: string;
42
+ };
43
+ type IServerSideSplatContext<T extends {} = {}> = ServerSidePropsContext<IContextBaseParams & T>;
44
+ type IServerSideContext<T extends {} = {}> = ServerSidePropsContext<IContextParams & T>;
45
+ type StateValue = StateValue[] | {
46
+ [key: string]: StateValue;
47
+ } | number | string | boolean | null | undefined;
48
+ type IPartial<T> = {
49
+ [P in keyof T]?: Partial<T[P]>;
50
+ };
51
+ type IPrettify<T> = {
52
+ [K in keyof T]: T[K];
53
+ } & {};
54
+ type IOverride<T, TypeToReplace, TypeToReplaceWith> = {
55
+ [K in keyof T]: T[K] extends Record<string, unknown> ? IOverride<T[K], TypeToReplace, TypeToReplaceWith> : T[K] extends TypeToReplace ? TypeToReplaceWith : T[K];
56
+ };
57
+
58
+ type ILocalizedString = Record<string, string>;
59
+ type ILocalizable = string | ILocalizedString;
60
60
  type ILocalized<T> = IOverride<T, ILocalizable, string>;
61
61
 
62
- type IEquatable = number | string;
63
- type SchemaType = string;
64
- type IOption = Record<string, any> & {
65
- id: IEquatable;
66
- name: string;
67
- };
68
- type ISchema = {
69
- id: IEquatable;
70
- schema?: string;
71
- };
72
- type IEntity = Record<string, unknown> & ISchema;
73
- type INamedEntity = IEntity & {
74
- name: ILocalizable;
75
- };
76
- type ITitledEntity = IEntity & {
77
- title: ILocalizable;
78
- };
79
-
80
- type IMediaType = 'image' | 'video' | string;
81
- type IMedia = {
82
- src: string;
83
- type: IMediaType;
84
- alt?: string;
85
- title?: string;
86
- abstract?: string;
87
- width?: number;
88
- height?: number;
89
- url?: string;
90
- media?: IMedia;
91
- };
92
-
93
- type ICategory = IEntity & {
94
- category?: IEquatable | ICategory;
95
- id: IEquatable;
96
- media?: IMedia;
97
- order?: number;
98
- slug: ILocalizable;
99
- title: ILocalizable;
100
- };
101
- type ICategoryItem = ICategory & {
102
- items: ICategory[];
103
- };
104
- type ICategorized = {
105
- abstract?: ILocalizable;
106
- category: IEquatable | ICategory;
107
- id: IEquatable;
108
- isDefault?: boolean;
109
- markets?: string[];
110
- media?: IMedia;
111
- order?: number;
112
- schema?: string;
113
- slug: ILocalizable;
114
- template?: string;
115
- title: ILocalizable;
116
- useSplat?: boolean;
117
- createdAt?: Date;
118
- updatedAt?: Date;
119
- };
120
-
121
- type IClassNameValue = string | boolean | number | null | undefined;
122
- type IClassNameCollection = Record<string, IClassNameValue>;
62
+ type IEquatable = number | string;
63
+ type SchemaType = string;
64
+ type IOption = Record<string, any> & {
65
+ id: IEquatable;
66
+ name: string;
67
+ };
68
+ type ISchema = {
69
+ id: IEquatable;
70
+ schema?: string;
71
+ };
72
+ type IEntity = Record<string, unknown> & ISchema;
73
+ type INamedEntity = IEntity & {
74
+ name: ILocalizable;
75
+ };
76
+ type ITitledEntity = IEntity & {
77
+ title: ILocalizable;
78
+ };
79
+
80
+ type IMediaType = 'image' | 'video' | string;
81
+ type IMedia = {
82
+ src: string;
83
+ type: IMediaType;
84
+ alt?: string;
85
+ title?: string;
86
+ abstract?: string;
87
+ width?: number;
88
+ height?: number;
89
+ url?: string;
90
+ media?: IMedia;
91
+ };
92
+
93
+ type ICategory = IEntity & {
94
+ category?: IEquatable | ICategory;
95
+ id: IEquatable;
96
+ media?: IMedia;
97
+ order?: number;
98
+ slug: ILocalizable;
99
+ title: ILocalizable;
100
+ };
101
+ type ICategoryItem = ICategory & {
102
+ items: ICategory[];
103
+ };
104
+ type ICategorized = {
105
+ abstract?: ILocalizable;
106
+ category: IEquatable | ICategory;
107
+ id: IEquatable;
108
+ isDefault?: boolean;
109
+ markets?: string[];
110
+ media?: IMedia;
111
+ order?: number;
112
+ schema?: string;
113
+ slug: ILocalizable;
114
+ template?: string;
115
+ title: ILocalizable;
116
+ useSplat?: boolean;
117
+ createdAt?: Date;
118
+ updatedAt?: Date;
119
+ };
120
+
121
+ type IClassNameValue = string | boolean | number | null | undefined;
122
+ type IClassNameCollection = Record<string, IClassNameValue>;
123
123
  type IClassName = IClassNameCollection | IClassNameValue;
124
124
 
125
- type FetchRequestOptions = {
126
- method?: string;
127
- headers?: {
128
- [key: string]: string;
129
- };
130
- body?: Blob | BufferSource | FormData | URLSearchParams | string | ReadableStream;
131
- mode?: 'cors' | 'no-cors' | 'same-origin';
132
- credentials?: 'omit' | 'same-origin' | 'include';
133
- cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached';
134
- redirect?: 'follow' | 'error' | 'manual';
135
- referrer?: string;
136
- referrerPolicy?: 'no-referrer, no-referrer-when-downgrade, same-origin, origin, strict-origin, origin-when-cross-origin, strict-origin-when-cross-origin, or unsafe-url';
137
- integrity?: string;
138
- keepalive?: boolean;
139
- signal?: AbortSignal;
140
- };
141
- type FetchService<T = unknown> = (url: string, options?: FetchRequestOptions, serviceOptions?: any) => Promise<T>;
125
+ type FetchRequestOptions = {
126
+ method?: string;
127
+ headers?: {
128
+ [key: string]: string;
129
+ };
130
+ body?: Blob | BufferSource | FormData | URLSearchParams | string | ReadableStream;
131
+ mode?: 'cors' | 'no-cors' | 'same-origin';
132
+ credentials?: 'omit' | 'same-origin' | 'include';
133
+ cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached';
134
+ redirect?: 'follow' | 'error' | 'manual';
135
+ referrer?: string;
136
+ referrerPolicy?: 'no-referrer, no-referrer-when-downgrade, same-origin, origin, strict-origin, origin-when-cross-origin, strict-origin-when-cross-origin, or unsafe-url';
137
+ integrity?: string;
138
+ keepalive?: boolean;
139
+ signal?: AbortSignal;
140
+ };
141
+ type FetchService<T = unknown> = (url: string, options?: FetchRequestOptions, serviceOptions?: any) => Promise<T>;
142
142
  type FetchError = any;
143
143
 
144
- type ILabel = IEntity & {
145
- id: IEquatable;
146
- text?: ILocalizable;
147
- };
148
-
149
- type ILocale = IEntity & {
150
- id: string;
151
- title?: string;
152
- isActive?: boolean;
153
- isDefault?: boolean;
154
- isHidden?: boolean;
155
- };
156
-
157
- type IMarket = IEntity & {
158
- id: string;
159
- title?: string;
160
- countries?: string[];
161
- languages?: string[];
162
- defaultLanguage?: string;
163
- isActive?: boolean;
164
- isDefault?: boolean;
165
- isHidden?: boolean;
166
- };
167
-
168
- type IMeta = {
169
- title?: string;
170
- description?: string;
171
- keywords?: string;
172
- robots?: string;
173
- };
174
-
175
- type IRoute = {
176
- category: IEquatable | ICategory;
177
- id: string;
178
- isDefault?: boolean;
179
- locale: string;
180
- market: string;
181
- order?: number;
182
- page: IEquatable;
183
- schema: string;
184
- template?: string;
185
- title: string;
186
- media?: IMedia;
187
- useSplat?: boolean;
188
- updatedAt?: Date;
189
- };
190
- type IRouteCanonical = IRoute & {
191
- alternates: IRoute[];
192
- };
193
- type IRouteLink = {
194
- href: string;
195
- id: IEquatable;
196
- items?: IRouteLink[];
197
- media?: IMedia;
198
- title: string;
199
- };
200
- type IRouteParams = Record<string, any> & {
201
- id: IEquatable;
202
- locale: string;
203
- market: string;
204
- };
205
-
206
- type IPage = Record<string, any> & ICategorized & {
207
- abstract?: string;
208
- alternates: IRoute[];
209
- breadcrumb: IRouteLink[];
210
- content?: string;
211
- description?: string;
212
- href: string;
213
- locale: string;
214
- market: string;
215
- meta?: IMeta;
216
- parentRoute?: IRouteLink;
217
- slug: string;
218
- title: string;
219
- };
220
- type IPageRelation = {
221
- relationTo: string;
222
- value: ICategorized;
223
- };
224
- type IPageResult<T extends ICategorized = ICategorized> = IPage & T;
225
- type PageProps<T extends ICategorized = ICategorized> = {
226
- layout: ILayout;
227
- page: IPageResult<T>;
228
- params: IRouteParams;
229
- locales?: string[];
230
- locale?: string;
231
- defaultLocale?: string;
232
- };
233
-
234
- type IMenuBase = {
235
- abstract?: ILocalizable;
236
- customClass?: string;
237
- id: IEquatable;
238
- items?: IMenuItem[];
239
- media?: IMedia;
240
- title: ILocalizable;
241
- };
242
- type IMenuCategory = IMenuBase & {
243
- type: 'category';
244
- href: string;
245
- category: IEquatable;
246
- };
247
- type IMenuGroup = IMenuBase & {
248
- type: 'group';
249
- };
250
- type IMenuLink = IMenuBase & {
251
- type: 'link';
252
- href: string;
253
- target: string;
254
- };
255
- type IMenuRoute = IMenuBase & {
256
- type: 'route';
257
- href: string;
258
- page: IEquatable;
259
- schema: string;
260
- };
261
- type IMenuPage = IMenuBase & {
262
- type: 'page';
263
- href: string;
264
- page: IEquatable;
265
- schema: string;
266
- };
267
- type IMenuCustom = Record<string, unknown> & {
268
- id: IEquatable;
269
- type: string;
270
- };
271
- type IMenuItem = IMenuCategory | IMenuGroup | IMenuLink | IMenuPage | IMenuRoute;
272
- type IMenu = {
273
- id: string;
274
- items: IMenuItem[];
275
- };
276
- /**
277
- * this is the original menu model from cms
278
- */
279
- type IUndecoratedMenuBase = {
280
- abstract?: ILocalizable;
281
- customClass?: string;
282
- id?: string;
283
- items: IUndecoratedMenuItem[];
284
- markets?: string[];
285
- media?: IMedia;
286
- type: string;
287
- };
288
- type IUndecoratedMenuCategory = Omit<IUndecoratedMenuBase, 'type'> & {
289
- type: 'category';
290
- category: string;
291
- maxDepth?: number;
292
- title?: ILocalizable;
293
- };
294
- type IUndecoratedMenuGroup = Omit<IUndecoratedMenuBase, 'type'> & {
295
- type: 'group';
296
- title: ILocalizable;
297
- };
298
- type IUndecoratedMenuLink = Omit<IUndecoratedMenuBase, 'type'> & {
299
- type: 'link';
300
- title: ILocalizable;
301
- href: string;
302
- target?: string;
303
- };
304
- type IUndecoratedMenuPage = Omit<IUndecoratedMenuBase, 'type'> & {
305
- type: 'page';
306
- page: IPageRelation;
307
- title?: ILocalizable;
308
- };
309
- type IUndecoratedMenuCustom = Record<string, unknown> & {
310
- id: IEquatable;
311
- type: 'custom';
312
- blockType: string;
313
- };
314
- type IUndecoratedMenuItem = IUndecoratedMenuCategory | IUndecoratedMenuGroup | IUndecoratedMenuLink | IUndecoratedMenuPage | IUndecoratedMenuCustom;
315
- type IUndecoratedMenu = {
316
- id: string;
317
- items: IUndecoratedMenuItem[];
318
- };
319
-
320
- type ILayout = {
321
- labels: ILabel[];
322
- locale: string;
323
- locales: ILocale[];
324
- market: string;
325
- markets: IMarket[];
326
- menu: Record<string, IMenu>;
327
- topLevelHrefs: Record<string, string>;
328
- topLevelRoutes: Record<string, IRouteLink>;
329
- tree?: IRouteLink;
330
- };
331
-
332
- type Pagination = {
333
- hasNextPage: boolean;
334
- hasPrevPage: boolean;
335
- limit: number;
336
- nextPage: number | null;
337
- page: number;
338
- pagingCounter: number;
339
- prevPage: number | null;
340
- totalDocs: number;
341
- totalPages: number;
342
- };
343
-
344
- type Operator = 'equals' | 'contains' | 'not_equals' | 'in' | 'not_in' | 'exists' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'near';
345
- type WhereField = {
346
- [key in Operator]?: unknown;
347
- };
348
- type WhereBase = {
349
- [key: string]: WhereField | Where[];
350
- };
351
- type WhereAndOr = {
352
- or?: Where[];
353
- and?: Where[];
354
- };
355
- type Where = WhereBase & WhereAndOr;
356
- type QueryParams = {
357
- where?: Where;
358
- locale?: string;
359
- market?: string;
360
- sort?: string;
361
- page?: number;
362
- limit?: number;
363
- depth?: number;
364
- draft?: boolean;
365
- pagination?: boolean;
366
- richText?: boolean;
367
- };
368
-
369
- type IQuerable<T extends IEntity = IEntity> = {
370
- findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
371
- findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
372
- findPaged<B extends T = T>(params?: QueryParams): Promise<{
373
- docs: B[];
374
- } & Pagination>;
375
- create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
376
- update<B extends T = T>(payload: Partial<B>): Promise<B>;
377
- delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
378
- };
379
- type FindParams = {
380
- where?: {
381
- [key: string]: unknown;
382
- };
383
- market?: string;
384
- locale?: string;
385
- };
386
- type FindWhereParams = {
387
- where: {
388
- [key: string]: unknown;
389
- };
390
- market?: string;
391
- locale?: string;
392
- };
144
+ type ILabel = IEntity & {
145
+ id: IEquatable;
146
+ text?: ILocalizable;
147
+ };
148
+
149
+ type ILocale = IEntity & {
150
+ id: string;
151
+ title?: string;
152
+ isActive?: boolean;
153
+ isDefault?: boolean;
154
+ isHidden?: boolean;
155
+ };
156
+
157
+ type IMarket = IEntity & {
158
+ id: string;
159
+ title?: string;
160
+ countries?: string[];
161
+ languages?: string[];
162
+ defaultLanguage?: string;
163
+ isActive?: boolean;
164
+ isDefault?: boolean;
165
+ isHidden?: boolean;
166
+ };
167
+
168
+ type IMeta = {
169
+ title?: string;
170
+ description?: string;
171
+ keywords?: string;
172
+ robots?: string;
173
+ };
174
+
175
+ type IRoute = {
176
+ category: IEquatable | ICategory;
177
+ id: string;
178
+ isDefault?: boolean;
179
+ locale: string;
180
+ market: string;
181
+ order?: number;
182
+ page: IEquatable;
183
+ schema: string;
184
+ template?: string;
185
+ title: string;
186
+ media?: IMedia;
187
+ useSplat?: boolean;
188
+ updatedAt?: Date;
189
+ };
190
+ type IRouteCanonical = IRoute & {
191
+ alternates: IRoute[];
192
+ };
193
+ type IRouteLink = {
194
+ href: string;
195
+ id: IEquatable;
196
+ items?: IRouteLink[];
197
+ media?: IMedia;
198
+ title: string;
199
+ };
200
+ type IRouteParams = Record<string, any> & {
201
+ id: IEquatable;
202
+ locale: string;
203
+ market: string;
204
+ };
205
+
206
+ type IPage = Record<string, any> & ICategorized & {
207
+ abstract?: string;
208
+ alternates: IRoute[];
209
+ breadcrumb: IRouteLink[];
210
+ content?: string;
211
+ description?: string;
212
+ href: string;
213
+ locale: string;
214
+ market: string;
215
+ meta?: IMeta;
216
+ parentRoute?: IRouteLink;
217
+ slug: string;
218
+ title: string;
219
+ };
220
+ type IPageRelation = {
221
+ relationTo: string;
222
+ value: ICategorized;
223
+ };
224
+ type IPageResult<T extends ICategorized = ICategorized> = IPage & T;
225
+ type PageProps<T extends ICategorized = ICategorized> = {
226
+ layout: ILayout;
227
+ page: IPageResult<T>;
228
+ params: IRouteParams;
229
+ locales?: string[];
230
+ locale?: string;
231
+ defaultLocale?: string;
232
+ };
233
+
234
+ type IMenuBase = {
235
+ abstract?: ILocalizable;
236
+ customClass?: string;
237
+ id: IEquatable;
238
+ items?: IMenuItem[];
239
+ media?: IMedia;
240
+ title: ILocalizable;
241
+ };
242
+ type IMenuCategory = IMenuBase & {
243
+ type: 'category';
244
+ href: string;
245
+ category: IEquatable;
246
+ };
247
+ type IMenuGroup = IMenuBase & {
248
+ type: 'group';
249
+ };
250
+ type IMenuLink = IMenuBase & {
251
+ type: 'link';
252
+ href: string;
253
+ target: string;
254
+ };
255
+ type IMenuRoute = IMenuBase & {
256
+ type: 'route';
257
+ href: string;
258
+ page: IEquatable;
259
+ schema: string;
260
+ };
261
+ type IMenuPage = IMenuBase & {
262
+ type: 'page';
263
+ href: string;
264
+ page: IEquatable;
265
+ schema: string;
266
+ };
267
+ type IMenuCustom = Record<string, unknown> & {
268
+ id: IEquatable;
269
+ type: string;
270
+ };
271
+ type IMenuItem = IMenuCategory | IMenuGroup | IMenuLink | IMenuPage | IMenuRoute;
272
+ type IMenu = {
273
+ id: string;
274
+ items: IMenuItem[];
275
+ };
276
+ /**
277
+ * this is the original menu model from cms
278
+ */
279
+ type IUndecoratedMenuBase = {
280
+ abstract?: ILocalizable;
281
+ customClass?: string;
282
+ id?: string;
283
+ items: IUndecoratedMenuItem[];
284
+ markets?: string[];
285
+ media?: IMedia;
286
+ type: string;
287
+ };
288
+ type IUndecoratedMenuCategory = Omit<IUndecoratedMenuBase, 'type'> & {
289
+ type: 'category';
290
+ category: string;
291
+ maxDepth?: number;
292
+ title?: ILocalizable;
293
+ };
294
+ type IUndecoratedMenuGroup = Omit<IUndecoratedMenuBase, 'type'> & {
295
+ type: 'group';
296
+ title: ILocalizable;
297
+ };
298
+ type IUndecoratedMenuLink = Omit<IUndecoratedMenuBase, 'type'> & {
299
+ type: 'link';
300
+ title: ILocalizable;
301
+ href: string;
302
+ target?: string;
303
+ };
304
+ type IUndecoratedMenuPage = Omit<IUndecoratedMenuBase, 'type'> & {
305
+ type: 'page';
306
+ page: IPageRelation;
307
+ title?: ILocalizable;
308
+ };
309
+ type IUndecoratedMenuCustom = Record<string, unknown> & {
310
+ id: IEquatable;
311
+ type: 'custom';
312
+ blockType: string;
313
+ };
314
+ type IUndecoratedMenuItem = IUndecoratedMenuCategory | IUndecoratedMenuGroup | IUndecoratedMenuLink | IUndecoratedMenuPage | IUndecoratedMenuCustom;
315
+ type IUndecoratedMenu = {
316
+ id: string;
317
+ items: IUndecoratedMenuItem[];
318
+ };
319
+
320
+ type ILayout = {
321
+ labels: ILabel[];
322
+ locale: string;
323
+ locales: ILocale[];
324
+ market: string;
325
+ markets: IMarket[];
326
+ menu: Record<string, IMenu>;
327
+ topLevelHrefs: Record<string, string>;
328
+ topLevelRoutes: Record<string, IRouteLink>;
329
+ tree?: IRouteLink;
330
+ };
331
+
332
+ type Pagination = {
333
+ hasNextPage: boolean;
334
+ hasPrevPage: boolean;
335
+ limit: number;
336
+ nextPage: number | null;
337
+ page: number;
338
+ pagingCounter: number;
339
+ prevPage: number | null;
340
+ totalDocs: number;
341
+ totalPages: number;
342
+ };
343
+
344
+ type Operator = 'equals' | 'contains' | 'not_equals' | 'in' | 'not_in' | 'exists' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'near';
345
+ type WhereField = {
346
+ [key in Operator]?: unknown;
347
+ };
348
+ type WhereBase = {
349
+ [key: string]: WhereField | Where[];
350
+ };
351
+ type WhereAndOr = {
352
+ or?: Where[];
353
+ and?: Where[];
354
+ };
355
+ type Where = WhereBase & WhereAndOr;
356
+ type QueryParams = {
357
+ where?: Where;
358
+ locale?: string;
359
+ market?: string;
360
+ sort?: string;
361
+ page?: number;
362
+ limit?: number;
363
+ depth?: number;
364
+ draft?: boolean;
365
+ pagination?: boolean;
366
+ richText?: boolean;
367
+ };
368
+
369
+ type IQuerable<T extends IEntity = IEntity> = {
370
+ findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
371
+ findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
372
+ findPaged<B extends T = T>(params?: QueryParams): Promise<{
373
+ docs: B[];
374
+ } & Pagination>;
375
+ create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
376
+ update<B extends T = T>(payload: Partial<B>): Promise<B>;
377
+ delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
378
+ };
379
+ type FindParams = {
380
+ where?: {
381
+ [key: string]: unknown;
382
+ };
383
+ market?: string;
384
+ locale?: string;
385
+ };
386
+ type FindWhereParams = {
387
+ where: {
388
+ [key: string]: unknown;
389
+ };
390
+ market?: string;
391
+ locale?: string;
392
+ };
393
393
  declare function toFindParams(idOrParams: IEquatable | FindWhereParams): FindWhereParams;
394
394
 
395
- declare enum RedirectReason {
396
- MovedPermanently = "301",
397
- Found = "302",
398
- TemporaryRedirect = "307",
399
- PermanentRedirect = "308",
400
- Gone = "410"
401
- }
402
- type IRedirect = {
403
- id: IEquatable;
404
- status: RedirectReason;
405
- from: string;
406
- to?: string;
407
- name?: string;
408
- order?: number;
409
- isActive: boolean;
410
- };
411
-
412
- type IMemoryStore<T extends IEntity = IEntity> = Record<string, T[]>;
413
- type IStore = Record<string, IQuerable<IEntity>>;
414
- type IConfig = {
415
- collections: string[];
416
- mocks: string[];
417
- pages: string[];
418
- };
419
- type IPackages = {
420
- icons: string;
421
- models: string;
422
- ui: string;
423
- };
424
- type ICollectionDescription = {
425
- singularName: string;
426
- pluralName: string;
427
- pluralDisplayName: string;
428
- displayName: string;
429
- title: string;
430
- };
431
- type ISerializedCollection = {
432
- singularName: string;
433
- pluralName: string;
434
- pluralDisplayName: string;
435
- displayName: string;
436
- items: IEntity[];
437
- };
395
+ declare enum RedirectReason {
396
+ MovedPermanently = "301",
397
+ Found = "302",
398
+ TemporaryRedirect = "307",
399
+ PermanentRedirect = "308",
400
+ Gone = "410"
401
+ }
402
+ type IRedirect = {
403
+ id: IEquatable;
404
+ status: RedirectReason;
405
+ from: string;
406
+ to?: string;
407
+ name?: string;
408
+ order?: number;
409
+ isActive: boolean;
410
+ };
411
+
412
+ type IMemoryStore<T extends IEntity = IEntity> = Record<string, T[]>;
413
+ type IStore = Record<string, IQuerable<IEntity>>;
414
+ type IConfig = {
415
+ collections: string[];
416
+ mocks: string[];
417
+ pages: string[];
418
+ };
419
+ type IPackages = {
420
+ icons: string;
421
+ models: string;
422
+ ui: string;
423
+ };
424
+ type ICollectionDescription = {
425
+ singularName: string;
426
+ pluralName: string;
427
+ pluralDisplayName: string;
428
+ displayName: string;
429
+ title: string;
430
+ };
431
+ type ISerializedCollection<T extends IEntity = IEntity> = ICollectionDescription & {
432
+ items: T[];
433
+ };
438
434
  type ISerializedStore = Record<string, ISerializedCollection>;
439
435
 
440
- type ITemplate = {
441
- id: IEquatable;
442
- name: ILocalizable;
443
- collections: string[];
436
+ type ITemplate = {
437
+ id: IEquatable;
438
+ name: ILocalizable;
439
+ collections: string[];
444
440
  };
445
441
 
446
- declare function isCategory(value?: ICategory | IEquatable): value is ICategory;
447
- declare function asCategoryId(value?: ICategory | IEquatable): string | undefined;
448
- declare function getRootCategory(categories: ICategory[]): ICategory | undefined;
449
- declare function getParentCategoriesById(id: string | undefined, categories: ICategory[]): ICategory[];
450
- declare function getCategorySegments(item: ICategorized, categories: ICategory[]): ICategory[];
442
+ declare function isCategory(value?: ICategory | IEquatable): value is ICategory;
443
+ declare function asCategoryId(value?: ICategory | IEquatable): string | undefined;
444
+ declare function getRootCategory(categories: ICategory[]): ICategory | undefined;
445
+ declare function getParentCategoriesById(id: string | undefined, categories: ICategory[]): ICategory[];
446
+ declare function getCategorySegments(item: ICategorized, categories: ICategory[]): ICategory[];
451
447
  declare function getCategorySegmentsByCategory(item: ICategory, categories: ICategory[]): ICategory[];
452
448
 
453
449
  declare function getClassNames(...props: Array<IClassName>): string;
454
450
 
455
- declare function getCollectionDescription(text: string): ICollectionDescription;
456
- declare function isValidCollectionDescription(description: ICollectionDescription): boolean;
457
- declare function toValidCollectionName(text: string): string;
458
- declare function camelToSnakeCase(text: string): string;
459
- declare function toDisplayName(text: string): string;
460
- declare function toPluralName(text: string): string;
451
+ declare function getCollectionDescription(text: string): ICollectionDescription;
452
+ declare function camelToSnakeCase(text: string): string;
453
+ declare function isValidCollectionDescription(description: ICollectionDescription): boolean;
454
+ declare function toDisplayName(text: string): string;
455
+ declare function toPluralName(text: string): string;
461
456
  declare function toTitleCase(text: string): string;
457
+ declare function toValidCollectionName(text: string): string;
462
458
 
463
459
  declare function consoleWarn(message: string, component?: string): void;
464
460
 
465
- declare function httpFetch(url: string, options?: FetchRequestOptions, serviceOptions?: any): Promise<any>;
466
- declare function httpGet(url: string, options?: FetchRequestOptions): Promise<any>;
467
- declare function httpPost(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
468
- declare function httpPut(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
469
- declare function httpPatch(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
461
+ declare function httpFetch(url: string, options?: FetchRequestOptions, serviceOptions?: any): Promise<any>;
462
+ declare function httpGet(url: string, options?: FetchRequestOptions): Promise<any>;
463
+ declare function httpPost(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
464
+ declare function httpPut(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
465
+ declare function httpPatch(url: string, payload: any, options?: FetchRequestOptions): Promise<any>;
470
466
  declare function httpDelete(url: string, options?: FetchRequestOptions): Promise<any>;
471
467
 
472
- declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
473
- items: T[];
474
- constructor(items: T[]);
475
- getItems<B extends T = T>(): Promise<B[]>;
476
- findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
477
- findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
478
- findPaged<B extends T = T>(params?: QueryParams): Promise<{
479
- docs: B[];
480
- } & Pagination>;
481
- create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
482
- update<B extends T = T>(payload: Partial<B>): Promise<B>;
483
- delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
484
- protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
485
- protected newUUID_(): number;
486
- protected evaluateValue_(value: unknown): unknown;
487
- protected existsClause_(value: unknown, exists?: boolean): boolean;
488
- protected equalsClause_(value: unknown, equals?: unknown): boolean;
489
- protected inClause_(value: unknown, values?: unknown[]): boolean;
490
- protected notInClause_(value: unknown, values?: unknown[]): boolean;
491
- protected likeClause_(value: unknown, query?: string): boolean;
492
- protected whereItem_<B extends T = T>(item: B, where?: Where): boolean;
493
- protected whereItems_<B extends T = T>(items: B[], where?: Where): B[];
494
- protected sortCollection_<B extends T = T>(items: B[], sort?: string): B[];
495
- protected paginatedItems_<B extends T = T>(items: B[], page?: number, limit?: number): ({
496
- docs: B[];
497
- } & Pagination);
468
+ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
469
+ items: T[];
470
+ constructor(items: T[]);
471
+ getItems<B extends T = T>(): Promise<B[]>;
472
+ findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
473
+ findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
474
+ findPaged<B extends T = T>(params?: QueryParams): Promise<{
475
+ docs: B[];
476
+ } & Pagination>;
477
+ create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
478
+ update<B extends T = T>(payload: Partial<B>): Promise<B>;
479
+ delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
480
+ protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
481
+ protected newUUID_(): number;
482
+ protected evaluateValue_(value: unknown): unknown;
483
+ protected existsClause_(value: unknown, exists?: boolean): boolean;
484
+ protected equalsClause_(value: unknown, equals?: unknown): boolean;
485
+ protected inClause_(value: unknown, values?: unknown[]): boolean;
486
+ protected notInClause_(value: unknown, values?: unknown[]): boolean;
487
+ protected likeClause_(value: unknown, query?: string): boolean;
488
+ protected whereItem_<B extends T = T>(item: B, where?: Where): boolean;
489
+ protected whereItems_<B extends T = T>(items: B[], where?: Where): B[];
490
+ protected sortCollection_<B extends T = T>(items: B[], sort?: string): B[];
491
+ protected paginatedItems_<B extends T = T>(items: B[], page?: number, limit?: number): ({
492
+ docs: B[];
493
+ } & Pagination);
498
494
  }
499
495
 
500
- declare function isLocalizedString(value: any): value is ILocalizedString;
501
- declare function localizedToString(json: ILocalizedString, locale?: string, defaultLocale?: string): string;
502
- declare function localize(value: ILocalizable, locale?: string, defaultLocale?: string): string;
503
- declare function localizeValue(value: any, locale?: string, defaultLocale?: string): any;
496
+ declare function isLocalizedString(value: any): value is ILocalizedString;
497
+ declare function localizedToString(json: ILocalizedString, locale?: string, defaultLocale?: string): string;
498
+ declare function localize(value: ILocalizable, locale?: string, defaultLocale?: string): string;
499
+ declare function localizeValue(value: any, locale?: string, defaultLocale?: string): any;
504
500
  declare function localizeItem(item: any, locale?: string, defaultLocale?: string): any;
505
501
 
506
- declare function qsSerialize(queryParams?: QueryParams): string;
507
- declare function asEquatable(value: string): IEquatable;
508
- declare function deserializeValue(value: string): string | boolean | number;
509
- declare function deserializeKey(value: string): string | number;
502
+ declare function qsSerialize(queryParams?: QueryParams): string;
503
+ declare function asEquatable(value: string): IEquatable;
504
+ declare function deserializeValue(value: string): string | boolean | number;
505
+ declare function deserializeKey(value: string): string | number;
510
506
  declare function qsDeserialize(query?: string, deserializedParams?: {}): QueryParams;
511
507
 
512
- declare function collectRoutes(store: IMemoryStore<ICategorized>, categories: ICategory[], markets: IMarket[], locales: ILocale[]): IRoute[];
513
- declare function eachMarketLocale(markets: IMarket[], locales: ILocale[], callback: (market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]) => void): void;
514
- declare function eachCategorized(store: IMemoryStore<ICategorized>, callback: (item: ICategorized, key: string) => void): void;
515
- declare enum RouteStrategy {
516
- Auto = "auto",
517
- Default = "default",
518
- Manual = "manual"
519
- }
508
+ declare function collectRoutes(store: IMemoryStore<ICategorized>, categories: ICategory[], markets: IMarket[], locales: ILocale[]): IRoute[];
509
+ declare function eachMarketLocale(markets: IMarket[], locales: ILocale[], callback: (market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]) => void): void;
510
+ declare function eachCategorized(store: IMemoryStore<ICategorized>, callback: (item: ICategorized, key: string) => void): void;
511
+ declare enum RouteStrategy {
512
+ Auto = "auto",
513
+ Default = "default",
514
+ Manual = "manual"
515
+ }
520
516
  declare function getRouteHref(segments: ICategory[], market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]): string;
521
517
 
522
518
  declare function textToSlug(title: string): string;
523
519
 
524
- type ListItem<T> = {
525
- [K in keyof T]: {
526
- readonly key: string;
527
- readonly value: T[K];
528
- };
529
- }[keyof T];
530
- /**
531
- * Helper to produce an array of enum descriptors.
532
- * @param enumeration Enumeration object.
533
- * @param separatorRegex Regex that would catch the separator in your enum key.
534
- */
520
+ type ListItem<T> = {
521
+ [K in keyof T]: {
522
+ readonly key: string;
523
+ readonly value: T[K];
524
+ };
525
+ }[keyof T];
526
+ /**
527
+ * Helper to produce an array of enum descriptors.
528
+ * @param enumeration Enumeration object.
529
+ * @param separatorRegex Regex that would catch the separator in your enum key.
530
+ */
535
531
  declare function enumToList<T extends Record<string, number | string>>(enumeration: T, separatorRegex?: RegExp): ListItem<T>[];
536
532
 
537
- declare function getIsDevelopment(): boolean;
538
- declare function getIsProduction(): boolean;
539
- declare const isDevelopment: boolean;
540
- declare const isProduction: boolean;
541
- declare const isStage: boolean;
542
- declare const isBrowser: boolean;
543
- declare function getEnv(): Record<string, Json>;
544
- declare function withSchema<Component extends {}, Schema>(component: Component, schema: Schema): Component & Schema;
545
- declare function asServerProps(props: any): any;
546
- declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
533
+ declare function getIsDevelopment(): boolean;
534
+ declare function getIsProduction(): boolean;
535
+ declare const isDevelopment: boolean;
536
+ declare const isProduction: boolean;
537
+ declare const isStage: boolean;
538
+ declare const isBrowser: boolean;
539
+ declare function getEnv(): Record<string, Json>;
540
+ declare function withSchema<Component extends {}, Schema>(component: Component, schema: Schema): Component & Schema;
541
+ declare function asServerProps(props: any): any;
542
+ declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
547
543
  declare function merge(target: any, source: any): any;
548
544
 
549
545
  export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IEntity, IEquatable, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageResult, IPartial, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, Json, JsonService, LiteralUnion, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, collectRoutes, consoleWarn, deserializeKey, deserializeValue, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isBrowser, isCategory, isDevelopment, isLocalizedString, isProduction, isStage, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, qsDeserialize, qsSerialize, textToSlug, toDisplayName, toFindParams, toPluralName, toTitleCase, toValidCollectionName, withSchema };
package/dist/index.js CHANGED
@@ -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 = {};
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 = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "0.3.0",
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"