@websolutespa/bom-core 0.4.0 → 0.5.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 +64 -50
- package/dist/index.d.ts +66 -10
- package/dist/index.js +214 -58
- package/dist/index.mjs +191 -56
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,50 +1,64 @@
|
|
|
1
|
-
# @websolutespa/bom-core
|
|
2
|
-
|
|
3
|
-
## 0.
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
# @websolutespa/bom-core
|
|
2
|
+
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Modified: JsonService, qs.
|
|
8
|
+
- Added: asEquatable, cloneItem, typeGuards.
|
|
9
|
+
|
|
10
|
+
## 0.4.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Added: IAnchor, babelCase.
|
|
15
|
+
- Modified: IApplication, IPageRelation.
|
|
16
|
+
|
|
17
|
+
## 0.4.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- Updating: next 13.
|
|
22
|
+
|
|
23
|
+
## 0.3.0
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- Modified: HttpService.
|
|
28
|
+
|
|
29
|
+
## 0.2.1
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Added: env ROOT_CATEGORY.
|
|
34
|
+
|
|
35
|
+
## 0.2.0
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- Modified routes, added redirects.
|
|
40
|
+
|
|
41
|
+
## 0.1.2
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Modified: MockMenuService.
|
|
46
|
+
|
|
47
|
+
## 0.1.1
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- Modified: ILocalizable.
|
|
52
|
+
|
|
53
|
+
## 0.1.0
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- Added: splat routes.
|
|
58
|
+
- Added: variants.
|
|
59
|
+
|
|
60
|
+
## 0.0.1
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- Added: first release.
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ type ILocalizedString = Record<string, string>;
|
|
|
59
59
|
type ILocalizable = string | ILocalizedString;
|
|
60
60
|
type ILocalized<T> = IOverride<T, ILocalizable, string>;
|
|
61
61
|
|
|
62
|
+
type IAnchor = {
|
|
63
|
+
id: string;
|
|
64
|
+
title?: ILocalizable;
|
|
65
|
+
};
|
|
66
|
+
|
|
62
67
|
type IEquatable = number | string;
|
|
63
68
|
type SchemaType = string;
|
|
64
69
|
type IOption = Record<string, any> & {
|
|
@@ -178,23 +183,25 @@ type IRoute = {
|
|
|
178
183
|
isDefault?: boolean;
|
|
179
184
|
locale: string;
|
|
180
185
|
market: string;
|
|
186
|
+
media?: IMedia;
|
|
181
187
|
order?: number;
|
|
182
188
|
page: IEquatable;
|
|
183
189
|
schema: string;
|
|
184
190
|
template?: string;
|
|
185
191
|
title: string;
|
|
186
|
-
media?: IMedia;
|
|
187
|
-
useSplat?: boolean;
|
|
188
192
|
updatedAt?: Date;
|
|
193
|
+
useSplat?: boolean;
|
|
189
194
|
};
|
|
190
195
|
type IRouteCanonical = IRoute & {
|
|
191
196
|
alternates: IRoute[];
|
|
192
197
|
};
|
|
193
198
|
type IRouteLink = {
|
|
199
|
+
category: IEquatable;
|
|
194
200
|
href: string;
|
|
195
201
|
id: IEquatable;
|
|
196
202
|
items?: IRouteLink[];
|
|
197
203
|
media?: IMedia;
|
|
204
|
+
schema: string;
|
|
198
205
|
title: string;
|
|
199
206
|
};
|
|
200
207
|
type IRouteParams = Record<string, any> & {
|
|
@@ -217,9 +224,16 @@ type IPage = Record<string, any> & ICategorized & {
|
|
|
217
224
|
slug: string;
|
|
218
225
|
title: string;
|
|
219
226
|
};
|
|
220
|
-
type
|
|
227
|
+
type IPageRelationResult<T extends ICategorized = ICategorized> = {
|
|
228
|
+
href: string;
|
|
229
|
+
} & T;
|
|
230
|
+
type IPageRelation<T extends ICategorized = ICategorized> = {
|
|
231
|
+
relationTo: string;
|
|
232
|
+
value: IPageRelationResult<T>;
|
|
233
|
+
};
|
|
234
|
+
type IPageUnresolvedRelation = {
|
|
221
235
|
relationTo: string;
|
|
222
|
-
value:
|
|
236
|
+
value: IEquatable | IEquatable[];
|
|
223
237
|
};
|
|
224
238
|
type IPageResult<T extends ICategorized = ICategorized> = IPage & T;
|
|
225
239
|
type PageProps<T extends ICategorized = ICategorized> = {
|
|
@@ -233,6 +247,7 @@ type PageProps<T extends ICategorized = ICategorized> = {
|
|
|
233
247
|
|
|
234
248
|
type IMenuBase = {
|
|
235
249
|
abstract?: ILocalizable;
|
|
250
|
+
extra?: ILocalizable;
|
|
236
251
|
customClass?: string;
|
|
237
252
|
id: IEquatable;
|
|
238
253
|
items?: IMenuItem[];
|
|
@@ -278,6 +293,7 @@ type IMenu = {
|
|
|
278
293
|
*/
|
|
279
294
|
type IUndecoratedMenuBase = {
|
|
280
295
|
abstract?: ILocalizable;
|
|
296
|
+
extra?: ILocalizable;
|
|
281
297
|
customClass?: string;
|
|
282
298
|
id?: string;
|
|
283
299
|
items: IUndecoratedMenuItem[];
|
|
@@ -329,6 +345,13 @@ type ILayout = {
|
|
|
329
345
|
tree?: IRouteLink;
|
|
330
346
|
};
|
|
331
347
|
|
|
348
|
+
type IUndecoratedNav<T> = T & {
|
|
349
|
+
nav?: IUndecoratedMenuPage;
|
|
350
|
+
};
|
|
351
|
+
type IDecoratedNav<T> = T & {
|
|
352
|
+
nav?: IMenuPage;
|
|
353
|
+
};
|
|
354
|
+
|
|
332
355
|
type Pagination = {
|
|
333
356
|
hasNextPage: boolean;
|
|
334
357
|
hasPrevPage: boolean;
|
|
@@ -477,7 +500,8 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
|
477
500
|
create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
|
|
478
501
|
update<B extends T = T>(payload: Partial<B>): Promise<B>;
|
|
479
502
|
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
480
|
-
protected
|
|
503
|
+
protected decorateOne_<B extends T = T>(item: B, params?: QueryParams): Promise<B>;
|
|
504
|
+
protected decorateMany_<B extends T = T>(items: B[], params?: QueryParams): Promise<B[]>;
|
|
481
505
|
protected newUUID_(): number;
|
|
482
506
|
protected evaluateValue_(value: unknown): unknown;
|
|
483
507
|
protected existsClause_(value: unknown, exists?: boolean): boolean;
|
|
@@ -497,13 +521,12 @@ declare function isLocalizedString(value: any): value is ILocalizedString;
|
|
|
497
521
|
declare function localizedToString(json: ILocalizedString, locale?: string, defaultLocale?: string): string;
|
|
498
522
|
declare function localize(value: ILocalizable, locale?: string, defaultLocale?: string): string;
|
|
499
523
|
declare function localizeValue(value: any, locale?: string, defaultLocale?: string): any;
|
|
500
|
-
declare function localizeItem(item:
|
|
524
|
+
declare function localizeItem<T = any>(item: T, locale?: string, defaultLocale?: string): T;
|
|
501
525
|
|
|
502
526
|
declare function qsSerialize(queryParams?: QueryParams): string;
|
|
503
|
-
declare function
|
|
504
|
-
declare function deserializeValue(value: string): string | boolean | number;
|
|
505
|
-
declare function deserializeKey(value: string): string | number;
|
|
527
|
+
declare function qsSerializeRaw(queryParams?: {}): string;
|
|
506
528
|
declare function qsDeserialize(query?: string, deserializedParams?: {}): QueryParams;
|
|
529
|
+
declare function qsDeserializeRaw(query?: string, deserializedParams?: {}): {};
|
|
507
530
|
|
|
508
531
|
declare function collectRoutes(store: IMemoryStore<ICategorized>, categories: ICategory[], markets: IMarket[], locales: ILocale[]): IRoute[];
|
|
509
532
|
declare function eachMarketLocale(markets: IMarket[], locales: ILocale[], callback: (market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]) => void): void;
|
|
@@ -517,6 +540,28 @@ declare function getRouteHref(segments: ICategory[], market: IMarket, locale: IL
|
|
|
517
540
|
|
|
518
541
|
declare function textToSlug(title: string): string;
|
|
519
542
|
|
|
543
|
+
declare function asEquatable(value: string): IEquatable;
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* PascalCase
|
|
547
|
+
* camelCase
|
|
548
|
+
* kebab-case
|
|
549
|
+
* snake_case
|
|
550
|
+
* char*case
|
|
551
|
+
**/
|
|
552
|
+
declare function unknownCaseToPascalCase(unknownCase: string): string;
|
|
553
|
+
declare function pascalCaseToCamelCase(pascalCase: string): string;
|
|
554
|
+
declare function pascalCaseToCharCase(pascalCase: string, char?: string): string;
|
|
555
|
+
declare function pascalCaseToKebabCase(pascalCase: string): string;
|
|
556
|
+
declare function pascalCaseToSnakeCase(pascalCase: string): string;
|
|
557
|
+
declare function toPascalCase(unknownCase: string): string;
|
|
558
|
+
declare function toCamelCase(unknownCase: string): string;
|
|
559
|
+
declare function toCharCase(unknownCase: string, char?: string): string;
|
|
560
|
+
declare function toKebabCase(unknownCase: string): string;
|
|
561
|
+
declare function toSnakeCase(unknownCase: string): string;
|
|
562
|
+
|
|
563
|
+
declare function cloneItem<T = unknown>(item: T): T;
|
|
564
|
+
|
|
520
565
|
type ListItem<T> = {
|
|
521
566
|
[K in keyof T]: {
|
|
522
567
|
readonly key: string;
|
|
@@ -530,6 +575,17 @@ type ListItem<T> = {
|
|
|
530
575
|
*/
|
|
531
576
|
declare function enumToList<T extends Record<string, number | string>>(enumeration: T, separatorRegex?: RegExp): ListItem<T>[];
|
|
532
577
|
|
|
578
|
+
declare function isArray<T = unknown>(item: unknown): item is Array<T>;
|
|
579
|
+
declare function isObject<T = Record<string, unknown>>(item: unknown): item is T;
|
|
580
|
+
declare function isNotNullString(item: unknown): item is string;
|
|
581
|
+
declare function isEquatable(item: unknown): item is IEquatable;
|
|
582
|
+
declare function isEntity(item: unknown): item is IEntity;
|
|
583
|
+
declare function isUnresolvedRelation(item: unknown): item is IPageUnresolvedRelation;
|
|
584
|
+
declare function isRelation(item: unknown): item is IPageRelation;
|
|
585
|
+
declare function isUndecoratedMenuItem(item: unknown): item is IUndecoratedMenuItem;
|
|
586
|
+
declare function isUndecoratedNav<T>(item: unknown): item is IUndecoratedNav<T>;
|
|
587
|
+
declare function isUndecoratedMenuPage(item: unknown): item is IUndecoratedMenuPage;
|
|
588
|
+
|
|
533
589
|
declare function getIsDevelopment(): boolean;
|
|
534
590
|
declare function getIsProduction(): boolean;
|
|
535
591
|
declare const isDevelopment: boolean;
|
|
@@ -542,4 +598,4 @@ declare function asServerProps(props: any): any;
|
|
|
542
598
|
declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
|
|
543
599
|
declare function merge(target: any, source: any): any;
|
|
544
600
|
|
|
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,
|
|
601
|
+
export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IDecoratedNav, 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, IPageRelationResult, IPageResult, IPageUnresolvedRelation, 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, IUndecoratedNav, 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, cloneItem, collectRoutes, consoleWarn, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isLocalizedString, isNotNullString, isObject, isProduction, isRelation, isStage, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
|
package/dist/index.js
CHANGED
|
@@ -38,10 +38,9 @@ __export(src_exports, {
|
|
|
38
38
|
asServerProps: () => asServerProps,
|
|
39
39
|
awaitAll: () => awaitAll,
|
|
40
40
|
camelToSnakeCase: () => camelToSnakeCase,
|
|
41
|
+
cloneItem: () => cloneItem,
|
|
41
42
|
collectRoutes: () => collectRoutes,
|
|
42
43
|
consoleWarn: () => consoleWarn,
|
|
43
|
-
deserializeKey: () => deserializeKey,
|
|
44
|
-
deserializeValue: () => deserializeValue,
|
|
45
44
|
eachCategorized: () => eachCategorized,
|
|
46
45
|
eachMarketLocale: () => eachMarketLocale,
|
|
47
46
|
enumToList: () => enumToList,
|
|
@@ -61,26 +60,48 @@ __export(src_exports, {
|
|
|
61
60
|
httpPatch: () => httpPatch,
|
|
62
61
|
httpPost: () => httpPost,
|
|
63
62
|
httpPut: () => httpPut,
|
|
63
|
+
isArray: () => isArray,
|
|
64
64
|
isBrowser: () => isBrowser,
|
|
65
65
|
isCategory: () => isCategory,
|
|
66
66
|
isDevelopment: () => isDevelopment,
|
|
67
|
+
isEntity: () => isEntity,
|
|
68
|
+
isEquatable: () => isEquatable,
|
|
67
69
|
isLocalizedString: () => isLocalizedString,
|
|
70
|
+
isNotNullString: () => isNotNullString,
|
|
71
|
+
isObject: () => isObject,
|
|
68
72
|
isProduction: () => isProduction,
|
|
73
|
+
isRelation: () => isRelation,
|
|
69
74
|
isStage: () => isStage,
|
|
75
|
+
isUndecoratedMenuItem: () => isUndecoratedMenuItem,
|
|
76
|
+
isUndecoratedMenuPage: () => isUndecoratedMenuPage,
|
|
77
|
+
isUndecoratedNav: () => isUndecoratedNav,
|
|
78
|
+
isUnresolvedRelation: () => isUnresolvedRelation,
|
|
70
79
|
isValidCollectionDescription: () => isValidCollectionDescription,
|
|
71
80
|
localize: () => localize,
|
|
72
81
|
localizeItem: () => localizeItem,
|
|
73
82
|
localizeValue: () => localizeValue,
|
|
74
83
|
localizedToString: () => localizedToString,
|
|
75
84
|
merge: () => merge,
|
|
85
|
+
pascalCaseToCamelCase: () => pascalCaseToCamelCase,
|
|
86
|
+
pascalCaseToCharCase: () => pascalCaseToCharCase,
|
|
87
|
+
pascalCaseToKebabCase: () => pascalCaseToKebabCase,
|
|
88
|
+
pascalCaseToSnakeCase: () => pascalCaseToSnakeCase,
|
|
76
89
|
qsDeserialize: () => qsDeserialize,
|
|
90
|
+
qsDeserializeRaw: () => qsDeserializeRaw,
|
|
77
91
|
qsSerialize: () => qsSerialize,
|
|
92
|
+
qsSerializeRaw: () => qsSerializeRaw,
|
|
78
93
|
textToSlug: () => textToSlug,
|
|
94
|
+
toCamelCase: () => toCamelCase,
|
|
95
|
+
toCharCase: () => toCharCase,
|
|
79
96
|
toDisplayName: () => toDisplayName,
|
|
80
97
|
toFindParams: () => toFindParams,
|
|
98
|
+
toKebabCase: () => toKebabCase,
|
|
99
|
+
toPascalCase: () => toPascalCase,
|
|
81
100
|
toPluralName: () => toPluralName,
|
|
101
|
+
toSnakeCase: () => toSnakeCase,
|
|
82
102
|
toTitleCase: () => toTitleCase,
|
|
83
103
|
toValidCollectionName: () => toValidCollectionName,
|
|
104
|
+
unknownCaseToPascalCase: () => unknownCaseToPascalCase,
|
|
84
105
|
withSchema: () => withSchema
|
|
85
106
|
});
|
|
86
107
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -251,6 +272,110 @@ function consoleWarn(message, component) {
|
|
|
251
272
|
console.warn(log);
|
|
252
273
|
}
|
|
253
274
|
|
|
275
|
+
// src/utils/asEquatable.ts
|
|
276
|
+
function asEquatable(value) {
|
|
277
|
+
if (String(parseInt(value)) === value) {
|
|
278
|
+
return Number(value);
|
|
279
|
+
}
|
|
280
|
+
return value;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/utils/babelCase.ts
|
|
284
|
+
function unknownCaseToPascalCase(unknownCase) {
|
|
285
|
+
const pascalCase = unknownCase.replace(
|
|
286
|
+
/(^[a-zA-Z])|(\W|_)+(\w?)([a-z0-9]*)?/g,
|
|
287
|
+
(m, g1, g2, g3, g4) => (g1 ? g1.toUpperCase() : "") + (g3 ? g3.toUpperCase() : "") + (g4 ? g4.toLowerCase() : "")
|
|
288
|
+
);
|
|
289
|
+
return pascalCase;
|
|
290
|
+
}
|
|
291
|
+
function pascalCaseToCamelCase(pascalCase) {
|
|
292
|
+
const camelCase = pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
293
|
+
return camelCase;
|
|
294
|
+
}
|
|
295
|
+
function pascalCaseToCharCase(pascalCase, char = "-") {
|
|
296
|
+
const charCase = pascalCase.replace(
|
|
297
|
+
/([A-Z]+)/g,
|
|
298
|
+
(m, g1, index) => (index > 0 ? char : "") + m
|
|
299
|
+
).toLowerCase();
|
|
300
|
+
return charCase;
|
|
301
|
+
}
|
|
302
|
+
function pascalCaseToKebabCase(pascalCase) {
|
|
303
|
+
const kebabCase = pascalCaseToCharCase(pascalCase, "-");
|
|
304
|
+
return kebabCase;
|
|
305
|
+
}
|
|
306
|
+
function pascalCaseToSnakeCase(pascalCase) {
|
|
307
|
+
const kebabCase = pascalCaseToCharCase(pascalCase, "_");
|
|
308
|
+
return kebabCase;
|
|
309
|
+
}
|
|
310
|
+
function toPascalCase(unknownCase) {
|
|
311
|
+
const pascalCase = unknownCaseToPascalCase(unknownCase);
|
|
312
|
+
return pascalCase;
|
|
313
|
+
}
|
|
314
|
+
function toCamelCase(unknownCase) {
|
|
315
|
+
const pascalCase = unknownCaseToPascalCase(unknownCase);
|
|
316
|
+
const camelCase = pascalCaseToCamelCase(pascalCase);
|
|
317
|
+
return camelCase;
|
|
318
|
+
}
|
|
319
|
+
function toCharCase(unknownCase, char = "-") {
|
|
320
|
+
const pascalCase = unknownCaseToPascalCase(unknownCase);
|
|
321
|
+
const charCase = pascalCaseToCharCase(pascalCase, char);
|
|
322
|
+
return charCase;
|
|
323
|
+
}
|
|
324
|
+
function toKebabCase(unknownCase) {
|
|
325
|
+
const kebabCase = toCharCase(unknownCase, "-");
|
|
326
|
+
return kebabCase;
|
|
327
|
+
}
|
|
328
|
+
function toSnakeCase(unknownCase) {
|
|
329
|
+
const snakeCase = toCharCase(unknownCase, "_");
|
|
330
|
+
return snakeCase;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/utils/typeGuards.ts
|
|
334
|
+
function isArray(item) {
|
|
335
|
+
return Array.isArray(item);
|
|
336
|
+
}
|
|
337
|
+
function isObject(item) {
|
|
338
|
+
return item != null && typeof item === "object" && !isArray(item);
|
|
339
|
+
}
|
|
340
|
+
function isNotNullString(item) {
|
|
341
|
+
return typeof item === "string" && Boolean(item);
|
|
342
|
+
}
|
|
343
|
+
function isEquatable(item) {
|
|
344
|
+
return typeof item === "number" || isNotNullString(item);
|
|
345
|
+
}
|
|
346
|
+
function isEntity(item) {
|
|
347
|
+
return isObject(item) && isEquatable(item.id);
|
|
348
|
+
}
|
|
349
|
+
function isUnresolvedRelation(item) {
|
|
350
|
+
return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
|
|
351
|
+
}
|
|
352
|
+
function isRelation(item) {
|
|
353
|
+
return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
|
|
354
|
+
}
|
|
355
|
+
function isUndecoratedMenuItem(item) {
|
|
356
|
+
return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
|
|
357
|
+
}
|
|
358
|
+
function isUndecoratedNav(item) {
|
|
359
|
+
return isObject(item) && isUndecoratedMenuPage(item.nav);
|
|
360
|
+
}
|
|
361
|
+
function isUndecoratedMenuPage(item) {
|
|
362
|
+
return isObject(item) && item.type === "page" && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/utils/cloneItem.ts
|
|
366
|
+
function cloneItem(item) {
|
|
367
|
+
if (isArray(item)) {
|
|
368
|
+
item = item.map((x) => cloneItem(x));
|
|
369
|
+
} else if (isObject(item)) {
|
|
370
|
+
item = { ...item };
|
|
371
|
+
const object = item;
|
|
372
|
+
Object.keys(object).forEach((key) => {
|
|
373
|
+
object[key] = cloneItem(object[key]);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
return item;
|
|
377
|
+
}
|
|
378
|
+
|
|
254
379
|
// src/utils/enumToList.ts
|
|
255
380
|
function enumToList(enumeration, separatorRegex = /_/g) {
|
|
256
381
|
const array = Object.keys(enumeration);
|
|
@@ -375,7 +500,7 @@ var JsonService = class {
|
|
|
375
500
|
params.where.id = params.where.id || { equals: id };
|
|
376
501
|
items = this.whereItems_(items, params.where);
|
|
377
502
|
if (items.length > 0) {
|
|
378
|
-
return this.
|
|
503
|
+
return await this.decorateOne_(items[0], params);
|
|
379
504
|
} else {
|
|
380
505
|
console.log("JsonService.findOne.notfound", id, params);
|
|
381
506
|
return void 0;
|
|
@@ -390,7 +515,7 @@ var JsonService = class {
|
|
|
390
515
|
if (params.sort) {
|
|
391
516
|
items = this.sortCollection_(items, params.sort);
|
|
392
517
|
}
|
|
393
|
-
return
|
|
518
|
+
return await this.decorateMany_(items, params);
|
|
394
519
|
}
|
|
395
520
|
async findPaged(params = {}) {
|
|
396
521
|
params.pagination = true;
|
|
@@ -402,7 +527,7 @@ var JsonService = class {
|
|
|
402
527
|
items = this.sortCollection_(items, params.sort);
|
|
403
528
|
}
|
|
404
529
|
const pagination = this.paginatedItems_(items, params.page, params.limit);
|
|
405
|
-
pagination.docs =
|
|
530
|
+
pagination.docs = await this.decorateMany_(pagination.docs, params);
|
|
406
531
|
return pagination;
|
|
407
532
|
}
|
|
408
533
|
async create(payload) {
|
|
@@ -439,9 +564,12 @@ var JsonService = class {
|
|
|
439
564
|
}
|
|
440
565
|
return void 0;
|
|
441
566
|
}
|
|
442
|
-
|
|
567
|
+
async decorateOne_(item, params = {}) {
|
|
443
568
|
return item;
|
|
444
569
|
}
|
|
570
|
+
async decorateMany_(items, params = {}) {
|
|
571
|
+
return items;
|
|
572
|
+
}
|
|
445
573
|
newUUID_() {
|
|
446
574
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
447
575
|
}
|
|
@@ -483,24 +611,6 @@ var JsonService = class {
|
|
|
483
611
|
}
|
|
484
612
|
return true;
|
|
485
613
|
}
|
|
486
|
-
// old where
|
|
487
|
-
/*
|
|
488
|
-
protected where_(items: any[], params: FindParams): any[] {
|
|
489
|
-
const where = params.where;
|
|
490
|
-
if (where) {
|
|
491
|
-
const keys = Object.keys(where);
|
|
492
|
-
items = items.filter(x => {
|
|
493
|
-
return keys.reduce<boolean>((p, c) => {
|
|
494
|
-
const whereValue = where[c];
|
|
495
|
-
const shouldMatch = Array.isArray(whereValue) ? whereValue : [whereValue];
|
|
496
|
-
// console.log('key', c, 'value', x[c], 'shouldMatch', shouldMatch);
|
|
497
|
-
return p && (shouldMatch.indexOf(x[c]) !== -1);
|
|
498
|
-
}, true);
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
return items;
|
|
502
|
-
}
|
|
503
|
-
*/
|
|
504
614
|
whereItem_(item, where) {
|
|
505
615
|
let has = true;
|
|
506
616
|
if (typeof where === "object") {
|
|
@@ -562,6 +672,16 @@ var JsonService = class {
|
|
|
562
672
|
return items;
|
|
563
673
|
}
|
|
564
674
|
// ^ sort
|
|
675
|
+
// limit
|
|
676
|
+
/*
|
|
677
|
+
protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
|
|
678
|
+
if (limit) {
|
|
679
|
+
items = items.slice(0, Math.min(limit, items.length));
|
|
680
|
+
}
|
|
681
|
+
return items;
|
|
682
|
+
}
|
|
683
|
+
*/
|
|
684
|
+
// ^ limit
|
|
565
685
|
// pagination
|
|
566
686
|
paginatedItems_(items, page = 1, limit = 10) {
|
|
567
687
|
const totalDocs = items.length;
|
|
@@ -618,60 +738,62 @@ function localizeValue(value, locale = "en", defaultLocale = "en") {
|
|
|
618
738
|
}
|
|
619
739
|
}
|
|
620
740
|
function localizeItem(item, locale = "en", defaultLocale = "en") {
|
|
621
|
-
if (
|
|
741
|
+
if (isArray(item)) {
|
|
622
742
|
item = item.map((x) => localizeValue(x, locale, defaultLocale));
|
|
623
|
-
} else if (
|
|
743
|
+
} else if (isObject(item)) {
|
|
624
744
|
item = { ...item };
|
|
625
|
-
|
|
626
|
-
|
|
745
|
+
const object = item;
|
|
746
|
+
Object.keys(object).forEach((key) => {
|
|
747
|
+
object[key] = localizeValue(object[key], locale, defaultLocale);
|
|
627
748
|
});
|
|
628
749
|
}
|
|
629
750
|
return item;
|
|
630
751
|
}
|
|
631
752
|
|
|
632
753
|
// src/qs/qs.ts
|
|
633
|
-
function
|
|
754
|
+
function qsSerializeKey(key, parentKey = "") {
|
|
634
755
|
return parentKey ? `${parentKey}[${key}]` : String(key);
|
|
635
756
|
}
|
|
636
|
-
function
|
|
757
|
+
function qsSerializeParam(key, value, serializedParams = [], parentKey = "") {
|
|
637
758
|
if (value != null) {
|
|
638
759
|
if (typeof value === "object") {
|
|
639
|
-
serializedParams =
|
|
760
|
+
serializedParams = qsSerializeParams(value, serializedParams, qsSerializeKey(key, parentKey));
|
|
640
761
|
} else {
|
|
641
762
|
serializedParams.push({
|
|
642
|
-
key:
|
|
763
|
+
key: qsSerializeKey(key, parentKey),
|
|
643
764
|
value
|
|
644
765
|
});
|
|
645
766
|
}
|
|
646
767
|
}
|
|
647
768
|
return serializedParams;
|
|
648
769
|
}
|
|
649
|
-
function
|
|
770
|
+
function qsSerializeParams(params, serializedParams = [], parentKey = "") {
|
|
650
771
|
if (Array.isArray(params)) {
|
|
651
772
|
params.forEach((value, key) => {
|
|
652
|
-
serializedParams =
|
|
773
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
653
774
|
});
|
|
654
775
|
} else {
|
|
655
776
|
Object.entries(params).forEach(([key, value]) => {
|
|
656
|
-
serializedParams =
|
|
777
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
657
778
|
});
|
|
658
779
|
}
|
|
659
780
|
return serializedParams;
|
|
660
781
|
}
|
|
661
782
|
function qsSerialize(queryParams = {}) {
|
|
662
|
-
const params =
|
|
783
|
+
const params = qsSerializeParams(queryParams);
|
|
663
784
|
if (params.length) {
|
|
664
785
|
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
665
786
|
}
|
|
666
787
|
return "";
|
|
667
788
|
}
|
|
668
|
-
function
|
|
669
|
-
|
|
670
|
-
|
|
789
|
+
function qsSerializeRaw(queryParams = {}) {
|
|
790
|
+
const params = qsSerializeParams(queryParams);
|
|
791
|
+
if (params.length) {
|
|
792
|
+
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
671
793
|
}
|
|
672
|
-
return
|
|
794
|
+
return "";
|
|
673
795
|
}
|
|
674
|
-
function
|
|
796
|
+
function qsDeserializeValue(value) {
|
|
675
797
|
if (String(parseInt(value)) === value) {
|
|
676
798
|
return Number(value);
|
|
677
799
|
} else if (String(value) === "true") {
|
|
@@ -681,14 +803,14 @@ function deserializeValue(value) {
|
|
|
681
803
|
}
|
|
682
804
|
return value;
|
|
683
805
|
}
|
|
684
|
-
function
|
|
806
|
+
function qsDeserializeKey(value) {
|
|
685
807
|
if (String(parseInt(value)) === value) {
|
|
686
808
|
return Number(value);
|
|
687
809
|
}
|
|
688
810
|
return value;
|
|
689
811
|
}
|
|
690
|
-
function
|
|
691
|
-
const keys = key.replace(/[\]]/g, "").split("[").map((x) =>
|
|
812
|
+
function qsDeserializeKeys(key) {
|
|
813
|
+
const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
|
|
692
814
|
return keys;
|
|
693
815
|
}
|
|
694
816
|
function getNextKeyItem(key) {
|
|
@@ -698,13 +820,13 @@ function getNextKeyItem(key) {
|
|
|
698
820
|
return {};
|
|
699
821
|
}
|
|
700
822
|
}
|
|
701
|
-
function
|
|
702
|
-
const keys =
|
|
823
|
+
function qsDeserializeParam(key, value, deserializedParams = {}) {
|
|
824
|
+
const keys = qsDeserializeKeys(key);
|
|
703
825
|
let target = deserializedParams;
|
|
704
826
|
while (keys.length) {
|
|
705
827
|
const key2 = keys.shift();
|
|
706
828
|
if (keys.length === 0) {
|
|
707
|
-
target[key2] =
|
|
829
|
+
target[key2] = qsDeserializeValue(value);
|
|
708
830
|
} else {
|
|
709
831
|
const next = target[key2] ? target[key2] : target[key2] = getNextKeyItem(keys[0]);
|
|
710
832
|
target = next;
|
|
@@ -712,8 +834,8 @@ function deserializeParam(key, value, deserializedParams = {}) {
|
|
|
712
834
|
}
|
|
713
835
|
return deserializedParams;
|
|
714
836
|
}
|
|
715
|
-
function
|
|
716
|
-
params.forEach((x) =>
|
|
837
|
+
function qsDeserializeParams(params, deserializedParams = {}) {
|
|
838
|
+
params.forEach((x) => qsDeserializeParam(x[0], x[1], deserializedParams));
|
|
717
839
|
return deserializedParams;
|
|
718
840
|
}
|
|
719
841
|
function qsDeserialize(query = "", deserializedParams = {}) {
|
|
@@ -723,7 +845,19 @@ function qsDeserialize(query = "", deserializedParams = {}) {
|
|
|
723
845
|
if (query !== "") {
|
|
724
846
|
const params = query.split("&").map((x) => x.split("="));
|
|
725
847
|
if (params.length) {
|
|
726
|
-
return
|
|
848
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return deserializedParams;
|
|
852
|
+
}
|
|
853
|
+
function qsDeserializeRaw(query = "", deserializedParams = {}) {
|
|
854
|
+
if (query.indexOf("?") === 0) {
|
|
855
|
+
query = query.substring(1);
|
|
856
|
+
}
|
|
857
|
+
if (query !== "") {
|
|
858
|
+
const params = query.split("&").map((x) => x.split("="));
|
|
859
|
+
if (params.length) {
|
|
860
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
727
861
|
}
|
|
728
862
|
}
|
|
729
863
|
return deserializedParams;
|
|
@@ -741,18 +875,19 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
741
875
|
const title = localize(item.title, locale.id);
|
|
742
876
|
const id = getRouteHref(segments, market, locale, markets2, locales2);
|
|
743
877
|
const route = {
|
|
878
|
+
category: item.category,
|
|
744
879
|
id,
|
|
745
|
-
|
|
880
|
+
isDefault: item.isDefault,
|
|
746
881
|
locale: locale.id,
|
|
747
|
-
|
|
882
|
+
market: market.id,
|
|
883
|
+
media: item.media,
|
|
884
|
+
order: item.order,
|
|
748
885
|
page: item.id,
|
|
749
886
|
schema: key,
|
|
750
887
|
template: item.template,
|
|
751
888
|
title,
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
useSplat: item.useSplat,
|
|
755
|
-
updatedAt: item.updatedAt
|
|
889
|
+
updatedAt: item.updatedAt,
|
|
890
|
+
useSplat: item.useSplat
|
|
756
891
|
};
|
|
757
892
|
routes.push(route);
|
|
758
893
|
}
|
|
@@ -878,10 +1013,9 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
878
1013
|
asServerProps,
|
|
879
1014
|
awaitAll,
|
|
880
1015
|
camelToSnakeCase,
|
|
1016
|
+
cloneItem,
|
|
881
1017
|
collectRoutes,
|
|
882
1018
|
consoleWarn,
|
|
883
|
-
deserializeKey,
|
|
884
|
-
deserializeValue,
|
|
885
1019
|
eachCategorized,
|
|
886
1020
|
eachMarketLocale,
|
|
887
1021
|
enumToList,
|
|
@@ -901,25 +1035,47 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
901
1035
|
httpPatch,
|
|
902
1036
|
httpPost,
|
|
903
1037
|
httpPut,
|
|
1038
|
+
isArray,
|
|
904
1039
|
isBrowser,
|
|
905
1040
|
isCategory,
|
|
906
1041
|
isDevelopment,
|
|
1042
|
+
isEntity,
|
|
1043
|
+
isEquatable,
|
|
907
1044
|
isLocalizedString,
|
|
1045
|
+
isNotNullString,
|
|
1046
|
+
isObject,
|
|
908
1047
|
isProduction,
|
|
1048
|
+
isRelation,
|
|
909
1049
|
isStage,
|
|
1050
|
+
isUndecoratedMenuItem,
|
|
1051
|
+
isUndecoratedMenuPage,
|
|
1052
|
+
isUndecoratedNav,
|
|
1053
|
+
isUnresolvedRelation,
|
|
910
1054
|
isValidCollectionDescription,
|
|
911
1055
|
localize,
|
|
912
1056
|
localizeItem,
|
|
913
1057
|
localizeValue,
|
|
914
1058
|
localizedToString,
|
|
915
1059
|
merge,
|
|
1060
|
+
pascalCaseToCamelCase,
|
|
1061
|
+
pascalCaseToCharCase,
|
|
1062
|
+
pascalCaseToKebabCase,
|
|
1063
|
+
pascalCaseToSnakeCase,
|
|
916
1064
|
qsDeserialize,
|
|
1065
|
+
qsDeserializeRaw,
|
|
917
1066
|
qsSerialize,
|
|
1067
|
+
qsSerializeRaw,
|
|
918
1068
|
textToSlug,
|
|
1069
|
+
toCamelCase,
|
|
1070
|
+
toCharCase,
|
|
919
1071
|
toDisplayName,
|
|
920
1072
|
toFindParams,
|
|
1073
|
+
toKebabCase,
|
|
1074
|
+
toPascalCase,
|
|
921
1075
|
toPluralName,
|
|
1076
|
+
toSnakeCase,
|
|
922
1077
|
toTitleCase,
|
|
923
1078
|
toValidCollectionName,
|
|
1079
|
+
unknownCaseToPascalCase,
|
|
924
1080
|
withSchema
|
|
925
1081
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,110 @@ function consoleWarn(message, component) {
|
|
|
164
164
|
console.warn(log);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
// src/utils/asEquatable.ts
|
|
168
|
+
function asEquatable(value) {
|
|
169
|
+
if (String(parseInt(value)) === value) {
|
|
170
|
+
return Number(value);
|
|
171
|
+
}
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/utils/babelCase.ts
|
|
176
|
+
function unknownCaseToPascalCase(unknownCase) {
|
|
177
|
+
const pascalCase = unknownCase.replace(
|
|
178
|
+
/(^[a-zA-Z])|(\W|_)+(\w?)([a-z0-9]*)?/g,
|
|
179
|
+
(m, g1, g2, g3, g4) => (g1 ? g1.toUpperCase() : "") + (g3 ? g3.toUpperCase() : "") + (g4 ? g4.toLowerCase() : "")
|
|
180
|
+
);
|
|
181
|
+
return pascalCase;
|
|
182
|
+
}
|
|
183
|
+
function pascalCaseToCamelCase(pascalCase) {
|
|
184
|
+
const camelCase = pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
185
|
+
return camelCase;
|
|
186
|
+
}
|
|
187
|
+
function pascalCaseToCharCase(pascalCase, char = "-") {
|
|
188
|
+
const charCase = pascalCase.replace(
|
|
189
|
+
/([A-Z]+)/g,
|
|
190
|
+
(m, g1, index) => (index > 0 ? char : "") + m
|
|
191
|
+
).toLowerCase();
|
|
192
|
+
return charCase;
|
|
193
|
+
}
|
|
194
|
+
function pascalCaseToKebabCase(pascalCase) {
|
|
195
|
+
const kebabCase = pascalCaseToCharCase(pascalCase, "-");
|
|
196
|
+
return kebabCase;
|
|
197
|
+
}
|
|
198
|
+
function pascalCaseToSnakeCase(pascalCase) {
|
|
199
|
+
const kebabCase = pascalCaseToCharCase(pascalCase, "_");
|
|
200
|
+
return kebabCase;
|
|
201
|
+
}
|
|
202
|
+
function toPascalCase(unknownCase) {
|
|
203
|
+
const pascalCase = unknownCaseToPascalCase(unknownCase);
|
|
204
|
+
return pascalCase;
|
|
205
|
+
}
|
|
206
|
+
function toCamelCase(unknownCase) {
|
|
207
|
+
const pascalCase = unknownCaseToPascalCase(unknownCase);
|
|
208
|
+
const camelCase = pascalCaseToCamelCase(pascalCase);
|
|
209
|
+
return camelCase;
|
|
210
|
+
}
|
|
211
|
+
function toCharCase(unknownCase, char = "-") {
|
|
212
|
+
const pascalCase = unknownCaseToPascalCase(unknownCase);
|
|
213
|
+
const charCase = pascalCaseToCharCase(pascalCase, char);
|
|
214
|
+
return charCase;
|
|
215
|
+
}
|
|
216
|
+
function toKebabCase(unknownCase) {
|
|
217
|
+
const kebabCase = toCharCase(unknownCase, "-");
|
|
218
|
+
return kebabCase;
|
|
219
|
+
}
|
|
220
|
+
function toSnakeCase(unknownCase) {
|
|
221
|
+
const snakeCase = toCharCase(unknownCase, "_");
|
|
222
|
+
return snakeCase;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/utils/typeGuards.ts
|
|
226
|
+
function isArray(item) {
|
|
227
|
+
return Array.isArray(item);
|
|
228
|
+
}
|
|
229
|
+
function isObject(item) {
|
|
230
|
+
return item != null && typeof item === "object" && !isArray(item);
|
|
231
|
+
}
|
|
232
|
+
function isNotNullString(item) {
|
|
233
|
+
return typeof item === "string" && Boolean(item);
|
|
234
|
+
}
|
|
235
|
+
function isEquatable(item) {
|
|
236
|
+
return typeof item === "number" || isNotNullString(item);
|
|
237
|
+
}
|
|
238
|
+
function isEntity(item) {
|
|
239
|
+
return isObject(item) && isEquatable(item.id);
|
|
240
|
+
}
|
|
241
|
+
function isUnresolvedRelation(item) {
|
|
242
|
+
return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
|
|
243
|
+
}
|
|
244
|
+
function isRelation(item) {
|
|
245
|
+
return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
|
|
246
|
+
}
|
|
247
|
+
function isUndecoratedMenuItem(item) {
|
|
248
|
+
return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
|
|
249
|
+
}
|
|
250
|
+
function isUndecoratedNav(item) {
|
|
251
|
+
return isObject(item) && isUndecoratedMenuPage(item.nav);
|
|
252
|
+
}
|
|
253
|
+
function isUndecoratedMenuPage(item) {
|
|
254
|
+
return isObject(item) && item.type === "page" && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/utils/cloneItem.ts
|
|
258
|
+
function cloneItem(item) {
|
|
259
|
+
if (isArray(item)) {
|
|
260
|
+
item = item.map((x) => cloneItem(x));
|
|
261
|
+
} else if (isObject(item)) {
|
|
262
|
+
item = { ...item };
|
|
263
|
+
const object = item;
|
|
264
|
+
Object.keys(object).forEach((key) => {
|
|
265
|
+
object[key] = cloneItem(object[key]);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return item;
|
|
269
|
+
}
|
|
270
|
+
|
|
167
271
|
// src/utils/enumToList.ts
|
|
168
272
|
function enumToList(enumeration, separatorRegex = /_/g) {
|
|
169
273
|
const array = Object.keys(enumeration);
|
|
@@ -288,7 +392,7 @@ var JsonService = class {
|
|
|
288
392
|
params.where.id = params.where.id || { equals: id };
|
|
289
393
|
items = this.whereItems_(items, params.where);
|
|
290
394
|
if (items.length > 0) {
|
|
291
|
-
return this.
|
|
395
|
+
return await this.decorateOne_(items[0], params);
|
|
292
396
|
} else {
|
|
293
397
|
console.log("JsonService.findOne.notfound", id, params);
|
|
294
398
|
return void 0;
|
|
@@ -303,7 +407,7 @@ var JsonService = class {
|
|
|
303
407
|
if (params.sort) {
|
|
304
408
|
items = this.sortCollection_(items, params.sort);
|
|
305
409
|
}
|
|
306
|
-
return
|
|
410
|
+
return await this.decorateMany_(items, params);
|
|
307
411
|
}
|
|
308
412
|
async findPaged(params = {}) {
|
|
309
413
|
params.pagination = true;
|
|
@@ -315,7 +419,7 @@ var JsonService = class {
|
|
|
315
419
|
items = this.sortCollection_(items, params.sort);
|
|
316
420
|
}
|
|
317
421
|
const pagination = this.paginatedItems_(items, params.page, params.limit);
|
|
318
|
-
pagination.docs =
|
|
422
|
+
pagination.docs = await this.decorateMany_(pagination.docs, params);
|
|
319
423
|
return pagination;
|
|
320
424
|
}
|
|
321
425
|
async create(payload) {
|
|
@@ -352,9 +456,12 @@ var JsonService = class {
|
|
|
352
456
|
}
|
|
353
457
|
return void 0;
|
|
354
458
|
}
|
|
355
|
-
|
|
459
|
+
async decorateOne_(item, params = {}) {
|
|
356
460
|
return item;
|
|
357
461
|
}
|
|
462
|
+
async decorateMany_(items, params = {}) {
|
|
463
|
+
return items;
|
|
464
|
+
}
|
|
358
465
|
newUUID_() {
|
|
359
466
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
360
467
|
}
|
|
@@ -396,24 +503,6 @@ var JsonService = class {
|
|
|
396
503
|
}
|
|
397
504
|
return true;
|
|
398
505
|
}
|
|
399
|
-
// old where
|
|
400
|
-
/*
|
|
401
|
-
protected where_(items: any[], params: FindParams): any[] {
|
|
402
|
-
const where = params.where;
|
|
403
|
-
if (where) {
|
|
404
|
-
const keys = Object.keys(where);
|
|
405
|
-
items = items.filter(x => {
|
|
406
|
-
return keys.reduce<boolean>((p, c) => {
|
|
407
|
-
const whereValue = where[c];
|
|
408
|
-
const shouldMatch = Array.isArray(whereValue) ? whereValue : [whereValue];
|
|
409
|
-
// console.log('key', c, 'value', x[c], 'shouldMatch', shouldMatch);
|
|
410
|
-
return p && (shouldMatch.indexOf(x[c]) !== -1);
|
|
411
|
-
}, true);
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
return items;
|
|
415
|
-
}
|
|
416
|
-
*/
|
|
417
506
|
whereItem_(item, where) {
|
|
418
507
|
let has = true;
|
|
419
508
|
if (typeof where === "object") {
|
|
@@ -475,6 +564,16 @@ var JsonService = class {
|
|
|
475
564
|
return items;
|
|
476
565
|
}
|
|
477
566
|
// ^ sort
|
|
567
|
+
// limit
|
|
568
|
+
/*
|
|
569
|
+
protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
|
|
570
|
+
if (limit) {
|
|
571
|
+
items = items.slice(0, Math.min(limit, items.length));
|
|
572
|
+
}
|
|
573
|
+
return items;
|
|
574
|
+
}
|
|
575
|
+
*/
|
|
576
|
+
// ^ limit
|
|
478
577
|
// pagination
|
|
479
578
|
paginatedItems_(items, page = 1, limit = 10) {
|
|
480
579
|
const totalDocs = items.length;
|
|
@@ -531,60 +630,62 @@ function localizeValue(value, locale = "en", defaultLocale = "en") {
|
|
|
531
630
|
}
|
|
532
631
|
}
|
|
533
632
|
function localizeItem(item, locale = "en", defaultLocale = "en") {
|
|
534
|
-
if (
|
|
633
|
+
if (isArray(item)) {
|
|
535
634
|
item = item.map((x) => localizeValue(x, locale, defaultLocale));
|
|
536
|
-
} else if (
|
|
635
|
+
} else if (isObject(item)) {
|
|
537
636
|
item = { ...item };
|
|
538
|
-
|
|
539
|
-
|
|
637
|
+
const object = item;
|
|
638
|
+
Object.keys(object).forEach((key) => {
|
|
639
|
+
object[key] = localizeValue(object[key], locale, defaultLocale);
|
|
540
640
|
});
|
|
541
641
|
}
|
|
542
642
|
return item;
|
|
543
643
|
}
|
|
544
644
|
|
|
545
645
|
// src/qs/qs.ts
|
|
546
|
-
function
|
|
646
|
+
function qsSerializeKey(key, parentKey = "") {
|
|
547
647
|
return parentKey ? `${parentKey}[${key}]` : String(key);
|
|
548
648
|
}
|
|
549
|
-
function
|
|
649
|
+
function qsSerializeParam(key, value, serializedParams = [], parentKey = "") {
|
|
550
650
|
if (value != null) {
|
|
551
651
|
if (typeof value === "object") {
|
|
552
|
-
serializedParams =
|
|
652
|
+
serializedParams = qsSerializeParams(value, serializedParams, qsSerializeKey(key, parentKey));
|
|
553
653
|
} else {
|
|
554
654
|
serializedParams.push({
|
|
555
|
-
key:
|
|
655
|
+
key: qsSerializeKey(key, parentKey),
|
|
556
656
|
value
|
|
557
657
|
});
|
|
558
658
|
}
|
|
559
659
|
}
|
|
560
660
|
return serializedParams;
|
|
561
661
|
}
|
|
562
|
-
function
|
|
662
|
+
function qsSerializeParams(params, serializedParams = [], parentKey = "") {
|
|
563
663
|
if (Array.isArray(params)) {
|
|
564
664
|
params.forEach((value, key) => {
|
|
565
|
-
serializedParams =
|
|
665
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
566
666
|
});
|
|
567
667
|
} else {
|
|
568
668
|
Object.entries(params).forEach(([key, value]) => {
|
|
569
|
-
serializedParams =
|
|
669
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
570
670
|
});
|
|
571
671
|
}
|
|
572
672
|
return serializedParams;
|
|
573
673
|
}
|
|
574
674
|
function qsSerialize(queryParams = {}) {
|
|
575
|
-
const params =
|
|
675
|
+
const params = qsSerializeParams(queryParams);
|
|
576
676
|
if (params.length) {
|
|
577
677
|
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
578
678
|
}
|
|
579
679
|
return "";
|
|
580
680
|
}
|
|
581
|
-
function
|
|
582
|
-
|
|
583
|
-
|
|
681
|
+
function qsSerializeRaw(queryParams = {}) {
|
|
682
|
+
const params = qsSerializeParams(queryParams);
|
|
683
|
+
if (params.length) {
|
|
684
|
+
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
584
685
|
}
|
|
585
|
-
return
|
|
686
|
+
return "";
|
|
586
687
|
}
|
|
587
|
-
function
|
|
688
|
+
function qsDeserializeValue(value) {
|
|
588
689
|
if (String(parseInt(value)) === value) {
|
|
589
690
|
return Number(value);
|
|
590
691
|
} else if (String(value) === "true") {
|
|
@@ -594,14 +695,14 @@ function deserializeValue(value) {
|
|
|
594
695
|
}
|
|
595
696
|
return value;
|
|
596
697
|
}
|
|
597
|
-
function
|
|
698
|
+
function qsDeserializeKey(value) {
|
|
598
699
|
if (String(parseInt(value)) === value) {
|
|
599
700
|
return Number(value);
|
|
600
701
|
}
|
|
601
702
|
return value;
|
|
602
703
|
}
|
|
603
|
-
function
|
|
604
|
-
const keys = key.replace(/[\]]/g, "").split("[").map((x) =>
|
|
704
|
+
function qsDeserializeKeys(key) {
|
|
705
|
+
const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
|
|
605
706
|
return keys;
|
|
606
707
|
}
|
|
607
708
|
function getNextKeyItem(key) {
|
|
@@ -611,13 +712,13 @@ function getNextKeyItem(key) {
|
|
|
611
712
|
return {};
|
|
612
713
|
}
|
|
613
714
|
}
|
|
614
|
-
function
|
|
615
|
-
const keys =
|
|
715
|
+
function qsDeserializeParam(key, value, deserializedParams = {}) {
|
|
716
|
+
const keys = qsDeserializeKeys(key);
|
|
616
717
|
let target = deserializedParams;
|
|
617
718
|
while (keys.length) {
|
|
618
719
|
const key2 = keys.shift();
|
|
619
720
|
if (keys.length === 0) {
|
|
620
|
-
target[key2] =
|
|
721
|
+
target[key2] = qsDeserializeValue(value);
|
|
621
722
|
} else {
|
|
622
723
|
const next = target[key2] ? target[key2] : target[key2] = getNextKeyItem(keys[0]);
|
|
623
724
|
target = next;
|
|
@@ -625,8 +726,8 @@ function deserializeParam(key, value, deserializedParams = {}) {
|
|
|
625
726
|
}
|
|
626
727
|
return deserializedParams;
|
|
627
728
|
}
|
|
628
|
-
function
|
|
629
|
-
params.forEach((x) =>
|
|
729
|
+
function qsDeserializeParams(params, deserializedParams = {}) {
|
|
730
|
+
params.forEach((x) => qsDeserializeParam(x[0], x[1], deserializedParams));
|
|
630
731
|
return deserializedParams;
|
|
631
732
|
}
|
|
632
733
|
function qsDeserialize(query = "", deserializedParams = {}) {
|
|
@@ -636,7 +737,19 @@ function qsDeserialize(query = "", deserializedParams = {}) {
|
|
|
636
737
|
if (query !== "") {
|
|
637
738
|
const params = query.split("&").map((x) => x.split("="));
|
|
638
739
|
if (params.length) {
|
|
639
|
-
return
|
|
740
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return deserializedParams;
|
|
744
|
+
}
|
|
745
|
+
function qsDeserializeRaw(query = "", deserializedParams = {}) {
|
|
746
|
+
if (query.indexOf("?") === 0) {
|
|
747
|
+
query = query.substring(1);
|
|
748
|
+
}
|
|
749
|
+
if (query !== "") {
|
|
750
|
+
const params = query.split("&").map((x) => x.split("="));
|
|
751
|
+
if (params.length) {
|
|
752
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
640
753
|
}
|
|
641
754
|
}
|
|
642
755
|
return deserializedParams;
|
|
@@ -654,18 +767,19 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
654
767
|
const title = localize(item.title, locale.id);
|
|
655
768
|
const id = getRouteHref(segments, market, locale, markets2, locales2);
|
|
656
769
|
const route = {
|
|
770
|
+
category: item.category,
|
|
657
771
|
id,
|
|
658
|
-
|
|
772
|
+
isDefault: item.isDefault,
|
|
659
773
|
locale: locale.id,
|
|
660
|
-
|
|
774
|
+
market: market.id,
|
|
775
|
+
media: item.media,
|
|
776
|
+
order: item.order,
|
|
661
777
|
page: item.id,
|
|
662
778
|
schema: key,
|
|
663
779
|
template: item.template,
|
|
664
780
|
title,
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
useSplat: item.useSplat,
|
|
668
|
-
updatedAt: item.updatedAt
|
|
781
|
+
updatedAt: item.updatedAt,
|
|
782
|
+
useSplat: item.useSplat
|
|
669
783
|
};
|
|
670
784
|
routes.push(route);
|
|
671
785
|
}
|
|
@@ -790,10 +904,9 @@ export {
|
|
|
790
904
|
asServerProps,
|
|
791
905
|
awaitAll,
|
|
792
906
|
camelToSnakeCase,
|
|
907
|
+
cloneItem,
|
|
793
908
|
collectRoutes,
|
|
794
909
|
consoleWarn,
|
|
795
|
-
deserializeKey,
|
|
796
|
-
deserializeValue,
|
|
797
910
|
eachCategorized,
|
|
798
911
|
eachMarketLocale,
|
|
799
912
|
enumToList,
|
|
@@ -813,25 +926,47 @@ export {
|
|
|
813
926
|
httpPatch,
|
|
814
927
|
httpPost,
|
|
815
928
|
httpPut,
|
|
929
|
+
isArray,
|
|
816
930
|
isBrowser,
|
|
817
931
|
isCategory,
|
|
818
932
|
isDevelopment,
|
|
933
|
+
isEntity,
|
|
934
|
+
isEquatable,
|
|
819
935
|
isLocalizedString,
|
|
936
|
+
isNotNullString,
|
|
937
|
+
isObject,
|
|
820
938
|
isProduction,
|
|
939
|
+
isRelation,
|
|
821
940
|
isStage,
|
|
941
|
+
isUndecoratedMenuItem,
|
|
942
|
+
isUndecoratedMenuPage,
|
|
943
|
+
isUndecoratedNav,
|
|
944
|
+
isUnresolvedRelation,
|
|
822
945
|
isValidCollectionDescription,
|
|
823
946
|
localize,
|
|
824
947
|
localizeItem,
|
|
825
948
|
localizeValue,
|
|
826
949
|
localizedToString,
|
|
827
950
|
merge,
|
|
951
|
+
pascalCaseToCamelCase,
|
|
952
|
+
pascalCaseToCharCase,
|
|
953
|
+
pascalCaseToKebabCase,
|
|
954
|
+
pascalCaseToSnakeCase,
|
|
828
955
|
qsDeserialize,
|
|
956
|
+
qsDeserializeRaw,
|
|
829
957
|
qsSerialize,
|
|
958
|
+
qsSerializeRaw,
|
|
830
959
|
textToSlug,
|
|
960
|
+
toCamelCase,
|
|
961
|
+
toCharCase,
|
|
831
962
|
toDisplayName,
|
|
832
963
|
toFindParams,
|
|
964
|
+
toKebabCase,
|
|
965
|
+
toPascalCase,
|
|
833
966
|
toPluralName,
|
|
967
|
+
toSnakeCase,
|
|
834
968
|
toTitleCase,
|
|
835
969
|
toValidCollectionName,
|
|
970
|
+
unknownCaseToPascalCase,
|
|
836
971
|
withSchema
|
|
837
972
|
};
|