@websolutespa/bom-core 0.4.1 → 0.6.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 +14 -1
- package/dist/index.d.ts +59 -8
- package/dist/index.js +182 -58
- package/dist/index.mjs +167 -56
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
# @websolutespa/bom-core
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added Logger, IPaginationResult.
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Modified: JsonService, qs.
|
|
14
|
+
- Added: asEquatable, cloneItem, typeGuards.
|
|
15
|
+
|
|
3
16
|
## 0.4.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
6
19
|
|
|
7
20
|
- Added: IAnchor, babelCase.
|
|
8
|
-
- Modified: IApplication, IPageRelation.
|
|
21
|
+
- Modified: IApplication, IPageRelation.
|
|
9
22
|
|
|
10
23
|
## 0.4.0
|
|
11
24
|
|
package/dist/index.d.ts
CHANGED
|
@@ -183,23 +183,25 @@ type IRoute = {
|
|
|
183
183
|
isDefault?: boolean;
|
|
184
184
|
locale: string;
|
|
185
185
|
market: string;
|
|
186
|
+
media?: IMedia;
|
|
186
187
|
order?: number;
|
|
187
188
|
page: IEquatable;
|
|
188
189
|
schema: string;
|
|
189
190
|
template?: string;
|
|
190
191
|
title: string;
|
|
191
|
-
media?: IMedia;
|
|
192
|
-
useSplat?: boolean;
|
|
193
192
|
updatedAt?: Date;
|
|
193
|
+
useSplat?: boolean;
|
|
194
194
|
};
|
|
195
195
|
type IRouteCanonical = IRoute & {
|
|
196
196
|
alternates: IRoute[];
|
|
197
197
|
};
|
|
198
198
|
type IRouteLink = {
|
|
199
|
+
category: IEquatable;
|
|
199
200
|
href: string;
|
|
200
201
|
id: IEquatable;
|
|
201
202
|
items?: IRouteLink[];
|
|
202
203
|
media?: IMedia;
|
|
204
|
+
schema: string;
|
|
203
205
|
title: string;
|
|
204
206
|
};
|
|
205
207
|
type IRouteParams = Record<string, any> & {
|
|
@@ -229,6 +231,10 @@ type IPageRelation<T extends ICategorized = ICategorized> = {
|
|
|
229
231
|
relationTo: string;
|
|
230
232
|
value: IPageRelationResult<T>;
|
|
231
233
|
};
|
|
234
|
+
type IPageUnresolvedRelation = {
|
|
235
|
+
relationTo: string;
|
|
236
|
+
value: IEquatable | IEquatable[];
|
|
237
|
+
};
|
|
232
238
|
type IPageResult<T extends ICategorized = ICategorized> = IPage & T;
|
|
233
239
|
type PageProps<T extends ICategorized = ICategorized> = {
|
|
234
240
|
layout: ILayout;
|
|
@@ -241,6 +247,7 @@ type PageProps<T extends ICategorized = ICategorized> = {
|
|
|
241
247
|
|
|
242
248
|
type IMenuBase = {
|
|
243
249
|
abstract?: ILocalizable;
|
|
250
|
+
extra?: ILocalizable;
|
|
244
251
|
customClass?: string;
|
|
245
252
|
id: IEquatable;
|
|
246
253
|
items?: IMenuItem[];
|
|
@@ -286,6 +293,7 @@ type IMenu = {
|
|
|
286
293
|
*/
|
|
287
294
|
type IUndecoratedMenuBase = {
|
|
288
295
|
abstract?: ILocalizable;
|
|
296
|
+
extra?: ILocalizable;
|
|
289
297
|
customClass?: string;
|
|
290
298
|
id?: string;
|
|
291
299
|
items: IUndecoratedMenuItem[];
|
|
@@ -337,6 +345,13 @@ type ILayout = {
|
|
|
337
345
|
tree?: IRouteLink;
|
|
338
346
|
};
|
|
339
347
|
|
|
348
|
+
type IUndecoratedNav<T> = T & {
|
|
349
|
+
nav?: IUndecoratedMenuPage;
|
|
350
|
+
};
|
|
351
|
+
type IDecoratedNav<T> = T & {
|
|
352
|
+
nav?: IMenuPage;
|
|
353
|
+
};
|
|
354
|
+
|
|
340
355
|
type Pagination = {
|
|
341
356
|
hasNextPage: boolean;
|
|
342
357
|
hasPrevPage: boolean;
|
|
@@ -348,6 +363,9 @@ type Pagination = {
|
|
|
348
363
|
totalDocs: number;
|
|
349
364
|
totalPages: number;
|
|
350
365
|
};
|
|
366
|
+
type IPaginationResult<T> = {
|
|
367
|
+
docs: T[];
|
|
368
|
+
} & Pagination;
|
|
351
369
|
|
|
352
370
|
type Operator = 'equals' | 'contains' | 'not_equals' | 'in' | 'not_in' | 'exists' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'near';
|
|
353
371
|
type WhereField = {
|
|
@@ -485,7 +503,8 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
|
485
503
|
create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
|
|
486
504
|
update<B extends T = T>(payload: Partial<B>): Promise<B>;
|
|
487
505
|
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
488
|
-
protected
|
|
506
|
+
protected decorateOne_<B extends T = T>(item: B, params?: QueryParams): Promise<B>;
|
|
507
|
+
protected decorateMany_<B extends T = T>(items: B[], params?: QueryParams): Promise<B[]>;
|
|
489
508
|
protected newUUID_(): number;
|
|
490
509
|
protected evaluateValue_(value: unknown): unknown;
|
|
491
510
|
protected existsClause_(value: unknown, exists?: boolean): boolean;
|
|
@@ -505,13 +524,30 @@ declare function isLocalizedString(value: any): value is ILocalizedString;
|
|
|
505
524
|
declare function localizedToString(json: ILocalizedString, locale?: string, defaultLocale?: string): string;
|
|
506
525
|
declare function localize(value: ILocalizable, locale?: string, defaultLocale?: string): string;
|
|
507
526
|
declare function localizeValue(value: any, locale?: string, defaultLocale?: string): any;
|
|
508
|
-
declare function localizeItem(item:
|
|
527
|
+
declare function localizeItem<T = any>(item: T, locale?: string, defaultLocale?: string): T;
|
|
528
|
+
|
|
529
|
+
declare enum LoggerLevel {
|
|
530
|
+
NONE = 0,
|
|
531
|
+
ERROR = 1,
|
|
532
|
+
WARN = 2,
|
|
533
|
+
INFO = 3,
|
|
534
|
+
LOG = 4,
|
|
535
|
+
ALL = 5
|
|
536
|
+
}
|
|
537
|
+
declare class Logger {
|
|
538
|
+
static level_: LoggerLevel;
|
|
539
|
+
static setLevel(level: LoggerLevel): void;
|
|
540
|
+
static getLevel(): LoggerLevel;
|
|
541
|
+
static error(...args: unknown[]): void;
|
|
542
|
+
static warn(...args: unknown[]): void;
|
|
543
|
+
static info(...args: unknown[]): void;
|
|
544
|
+
static log(...args: unknown[]): void;
|
|
545
|
+
}
|
|
509
546
|
|
|
510
547
|
declare function qsSerialize(queryParams?: QueryParams): string;
|
|
511
|
-
declare function
|
|
512
|
-
declare function deserializeValue(value: string): string | boolean | number;
|
|
513
|
-
declare function deserializeKey(value: string): string | number;
|
|
548
|
+
declare function qsSerializeRaw(queryParams?: {}): string;
|
|
514
549
|
declare function qsDeserialize(query?: string, deserializedParams?: {}): QueryParams;
|
|
550
|
+
declare function qsDeserializeRaw(query?: string, deserializedParams?: {}): {};
|
|
515
551
|
|
|
516
552
|
declare function collectRoutes(store: IMemoryStore<ICategorized>, categories: ICategory[], markets: IMarket[], locales: ILocale[]): IRoute[];
|
|
517
553
|
declare function eachMarketLocale(markets: IMarket[], locales: ILocale[], callback: (market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]) => void): void;
|
|
@@ -525,6 +561,8 @@ declare function getRouteHref(segments: ICategory[], market: IMarket, locale: IL
|
|
|
525
561
|
|
|
526
562
|
declare function textToSlug(title: string): string;
|
|
527
563
|
|
|
564
|
+
declare function asEquatable(value: string): IEquatable;
|
|
565
|
+
|
|
528
566
|
/**
|
|
529
567
|
* PascalCase
|
|
530
568
|
* camelCase
|
|
@@ -543,6 +581,8 @@ declare function toCharCase(unknownCase: string, char?: string): string;
|
|
|
543
581
|
declare function toKebabCase(unknownCase: string): string;
|
|
544
582
|
declare function toSnakeCase(unknownCase: string): string;
|
|
545
583
|
|
|
584
|
+
declare function cloneItem<T = unknown>(item: T): T;
|
|
585
|
+
|
|
546
586
|
type ListItem<T> = {
|
|
547
587
|
[K in keyof T]: {
|
|
548
588
|
readonly key: string;
|
|
@@ -556,6 +596,17 @@ type ListItem<T> = {
|
|
|
556
596
|
*/
|
|
557
597
|
declare function enumToList<T extends Record<string, number | string>>(enumeration: T, separatorRegex?: RegExp): ListItem<T>[];
|
|
558
598
|
|
|
599
|
+
declare function isArray<T = unknown>(item: unknown): item is Array<T>;
|
|
600
|
+
declare function isObject<T = Record<string, unknown>>(item: unknown): item is T;
|
|
601
|
+
declare function isNotNullString(item: unknown): item is string;
|
|
602
|
+
declare function isEquatable(item: unknown): item is IEquatable;
|
|
603
|
+
declare function isEntity(item: unknown): item is IEntity;
|
|
604
|
+
declare function isUnresolvedRelation(item: unknown): item is IPageUnresolvedRelation;
|
|
605
|
+
declare function isRelation(item: unknown): item is IPageRelation;
|
|
606
|
+
declare function isUndecoratedMenuItem(item: unknown): item is IUndecoratedMenuItem;
|
|
607
|
+
declare function isUndecoratedNav<T>(item: unknown): item is IUndecoratedNav<T>;
|
|
608
|
+
declare function isUndecoratedMenuPage(item: unknown): item is IUndecoratedMenuPage;
|
|
609
|
+
|
|
559
610
|
declare function getIsDevelopment(): boolean;
|
|
560
611
|
declare function getIsProduction(): boolean;
|
|
561
612
|
declare const isDevelopment: boolean;
|
|
@@ -568,4 +619,4 @@ declare function asServerProps(props: any): any;
|
|
|
568
619
|
declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
|
|
569
620
|
declare function merge(target: any, source: any): any;
|
|
570
621
|
|
|
571
|
-
export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, 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, IPageRelationResult, 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,
|
|
622
|
+
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, IPaginationResult, 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, Logger, LoggerLevel, 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
|
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
JsonService: () => JsonService,
|
|
34
|
+
Logger: () => Logger,
|
|
35
|
+
LoggerLevel: () => LoggerLevel,
|
|
34
36
|
RedirectReason: () => RedirectReason,
|
|
35
37
|
RouteStrategy: () => RouteStrategy,
|
|
36
38
|
asCategoryId: () => asCategoryId,
|
|
@@ -38,10 +40,9 @@ __export(src_exports, {
|
|
|
38
40
|
asServerProps: () => asServerProps,
|
|
39
41
|
awaitAll: () => awaitAll,
|
|
40
42
|
camelToSnakeCase: () => camelToSnakeCase,
|
|
43
|
+
cloneItem: () => cloneItem,
|
|
41
44
|
collectRoutes: () => collectRoutes,
|
|
42
45
|
consoleWarn: () => consoleWarn,
|
|
43
|
-
deserializeKey: () => deserializeKey,
|
|
44
|
-
deserializeValue: () => deserializeValue,
|
|
45
46
|
eachCategorized: () => eachCategorized,
|
|
46
47
|
eachMarketLocale: () => eachMarketLocale,
|
|
47
48
|
enumToList: () => enumToList,
|
|
@@ -61,12 +62,22 @@ __export(src_exports, {
|
|
|
61
62
|
httpPatch: () => httpPatch,
|
|
62
63
|
httpPost: () => httpPost,
|
|
63
64
|
httpPut: () => httpPut,
|
|
65
|
+
isArray: () => isArray,
|
|
64
66
|
isBrowser: () => isBrowser,
|
|
65
67
|
isCategory: () => isCategory,
|
|
66
68
|
isDevelopment: () => isDevelopment,
|
|
69
|
+
isEntity: () => isEntity,
|
|
70
|
+
isEquatable: () => isEquatable,
|
|
67
71
|
isLocalizedString: () => isLocalizedString,
|
|
72
|
+
isNotNullString: () => isNotNullString,
|
|
73
|
+
isObject: () => isObject,
|
|
68
74
|
isProduction: () => isProduction,
|
|
75
|
+
isRelation: () => isRelation,
|
|
69
76
|
isStage: () => isStage,
|
|
77
|
+
isUndecoratedMenuItem: () => isUndecoratedMenuItem,
|
|
78
|
+
isUndecoratedMenuPage: () => isUndecoratedMenuPage,
|
|
79
|
+
isUndecoratedNav: () => isUndecoratedNav,
|
|
80
|
+
isUnresolvedRelation: () => isUnresolvedRelation,
|
|
70
81
|
isValidCollectionDescription: () => isValidCollectionDescription,
|
|
71
82
|
localize: () => localize,
|
|
72
83
|
localizeItem: () => localizeItem,
|
|
@@ -78,7 +89,9 @@ __export(src_exports, {
|
|
|
78
89
|
pascalCaseToKebabCase: () => pascalCaseToKebabCase,
|
|
79
90
|
pascalCaseToSnakeCase: () => pascalCaseToSnakeCase,
|
|
80
91
|
qsDeserialize: () => qsDeserialize,
|
|
92
|
+
qsDeserializeRaw: () => qsDeserializeRaw,
|
|
81
93
|
qsSerialize: () => qsSerialize,
|
|
94
|
+
qsSerializeRaw: () => qsSerializeRaw,
|
|
82
95
|
textToSlug: () => textToSlug,
|
|
83
96
|
toCamelCase: () => toCamelCase,
|
|
84
97
|
toCharCase: () => toCharCase,
|
|
@@ -261,6 +274,14 @@ function consoleWarn(message, component) {
|
|
|
261
274
|
console.warn(log);
|
|
262
275
|
}
|
|
263
276
|
|
|
277
|
+
// src/utils/asEquatable.ts
|
|
278
|
+
function asEquatable(value) {
|
|
279
|
+
if (String(parseInt(value)) === value) {
|
|
280
|
+
return Number(value);
|
|
281
|
+
}
|
|
282
|
+
return value;
|
|
283
|
+
}
|
|
284
|
+
|
|
264
285
|
// src/utils/babelCase.ts
|
|
265
286
|
function unknownCaseToPascalCase(unknownCase) {
|
|
266
287
|
const pascalCase = unknownCase.replace(
|
|
@@ -311,6 +332,52 @@ function toSnakeCase(unknownCase) {
|
|
|
311
332
|
return snakeCase;
|
|
312
333
|
}
|
|
313
334
|
|
|
335
|
+
// src/utils/typeGuards.ts
|
|
336
|
+
function isArray(item) {
|
|
337
|
+
return Array.isArray(item);
|
|
338
|
+
}
|
|
339
|
+
function isObject(item) {
|
|
340
|
+
return item != null && typeof item === "object" && !isArray(item);
|
|
341
|
+
}
|
|
342
|
+
function isNotNullString(item) {
|
|
343
|
+
return typeof item === "string" && Boolean(item);
|
|
344
|
+
}
|
|
345
|
+
function isEquatable(item) {
|
|
346
|
+
return typeof item === "number" || isNotNullString(item);
|
|
347
|
+
}
|
|
348
|
+
function isEntity(item) {
|
|
349
|
+
return isObject(item) && isEquatable(item.id);
|
|
350
|
+
}
|
|
351
|
+
function isUnresolvedRelation(item) {
|
|
352
|
+
return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
|
|
353
|
+
}
|
|
354
|
+
function isRelation(item) {
|
|
355
|
+
return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
|
|
356
|
+
}
|
|
357
|
+
function isUndecoratedMenuItem(item) {
|
|
358
|
+
return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
|
|
359
|
+
}
|
|
360
|
+
function isUndecoratedNav(item) {
|
|
361
|
+
return isObject(item) && isUndecoratedMenuPage(item.nav);
|
|
362
|
+
}
|
|
363
|
+
function isUndecoratedMenuPage(item) {
|
|
364
|
+
return isObject(item) && item.type === "page" && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/utils/cloneItem.ts
|
|
368
|
+
function cloneItem(item) {
|
|
369
|
+
if (isArray(item)) {
|
|
370
|
+
item = item.map((x) => cloneItem(x));
|
|
371
|
+
} else if (isObject(item)) {
|
|
372
|
+
item = { ...item };
|
|
373
|
+
const object = item;
|
|
374
|
+
Object.keys(object).forEach((key) => {
|
|
375
|
+
object[key] = cloneItem(object[key]);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return item;
|
|
379
|
+
}
|
|
380
|
+
|
|
314
381
|
// src/utils/enumToList.ts
|
|
315
382
|
function enumToList(enumeration, separatorRegex = /_/g) {
|
|
316
383
|
const array = Object.keys(enumeration);
|
|
@@ -435,7 +502,7 @@ var JsonService = class {
|
|
|
435
502
|
params.where.id = params.where.id || { equals: id };
|
|
436
503
|
items = this.whereItems_(items, params.where);
|
|
437
504
|
if (items.length > 0) {
|
|
438
|
-
return this.
|
|
505
|
+
return await this.decorateOne_(items[0], params);
|
|
439
506
|
} else {
|
|
440
507
|
console.log("JsonService.findOne.notfound", id, params);
|
|
441
508
|
return void 0;
|
|
@@ -450,7 +517,7 @@ var JsonService = class {
|
|
|
450
517
|
if (params.sort) {
|
|
451
518
|
items = this.sortCollection_(items, params.sort);
|
|
452
519
|
}
|
|
453
|
-
return
|
|
520
|
+
return await this.decorateMany_(items, params);
|
|
454
521
|
}
|
|
455
522
|
async findPaged(params = {}) {
|
|
456
523
|
params.pagination = true;
|
|
@@ -462,7 +529,7 @@ var JsonService = class {
|
|
|
462
529
|
items = this.sortCollection_(items, params.sort);
|
|
463
530
|
}
|
|
464
531
|
const pagination = this.paginatedItems_(items, params.page, params.limit);
|
|
465
|
-
pagination.docs =
|
|
532
|
+
pagination.docs = await this.decorateMany_(pagination.docs, params);
|
|
466
533
|
return pagination;
|
|
467
534
|
}
|
|
468
535
|
async create(payload) {
|
|
@@ -499,9 +566,12 @@ var JsonService = class {
|
|
|
499
566
|
}
|
|
500
567
|
return void 0;
|
|
501
568
|
}
|
|
502
|
-
|
|
569
|
+
async decorateOne_(item, params = {}) {
|
|
503
570
|
return item;
|
|
504
571
|
}
|
|
572
|
+
async decorateMany_(items, params = {}) {
|
|
573
|
+
return items;
|
|
574
|
+
}
|
|
505
575
|
newUUID_() {
|
|
506
576
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
507
577
|
}
|
|
@@ -543,24 +613,6 @@ var JsonService = class {
|
|
|
543
613
|
}
|
|
544
614
|
return true;
|
|
545
615
|
}
|
|
546
|
-
// old where
|
|
547
|
-
/*
|
|
548
|
-
protected where_(items: any[], params: FindParams): any[] {
|
|
549
|
-
const where = params.where;
|
|
550
|
-
if (where) {
|
|
551
|
-
const keys = Object.keys(where);
|
|
552
|
-
items = items.filter(x => {
|
|
553
|
-
return keys.reduce<boolean>((p, c) => {
|
|
554
|
-
const whereValue = where[c];
|
|
555
|
-
const shouldMatch = Array.isArray(whereValue) ? whereValue : [whereValue];
|
|
556
|
-
// console.log('key', c, 'value', x[c], 'shouldMatch', shouldMatch);
|
|
557
|
-
return p && (shouldMatch.indexOf(x[c]) !== -1);
|
|
558
|
-
}, true);
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
return items;
|
|
562
|
-
}
|
|
563
|
-
*/
|
|
564
616
|
whereItem_(item, where) {
|
|
565
617
|
let has = true;
|
|
566
618
|
if (typeof where === "object") {
|
|
@@ -688,60 +740,106 @@ function localizeValue(value, locale = "en", defaultLocale = "en") {
|
|
|
688
740
|
}
|
|
689
741
|
}
|
|
690
742
|
function localizeItem(item, locale = "en", defaultLocale = "en") {
|
|
691
|
-
if (
|
|
743
|
+
if (isArray(item)) {
|
|
692
744
|
item = item.map((x) => localizeValue(x, locale, defaultLocale));
|
|
693
|
-
} else if (
|
|
745
|
+
} else if (isObject(item)) {
|
|
694
746
|
item = { ...item };
|
|
695
|
-
|
|
696
|
-
|
|
747
|
+
const object = item;
|
|
748
|
+
Object.keys(object).forEach((key) => {
|
|
749
|
+
object[key] = localizeValue(object[key], locale, defaultLocale);
|
|
697
750
|
});
|
|
698
751
|
}
|
|
699
752
|
return item;
|
|
700
753
|
}
|
|
701
754
|
|
|
755
|
+
// src/logger/logger.ts
|
|
756
|
+
var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
|
|
757
|
+
LoggerLevel2[LoggerLevel2["NONE"] = 0] = "NONE";
|
|
758
|
+
LoggerLevel2[LoggerLevel2["ERROR"] = 1] = "ERROR";
|
|
759
|
+
LoggerLevel2[LoggerLevel2["WARN"] = 2] = "WARN";
|
|
760
|
+
LoggerLevel2[LoggerLevel2["INFO"] = 3] = "INFO";
|
|
761
|
+
LoggerLevel2[LoggerLevel2["LOG"] = 4] = "LOG";
|
|
762
|
+
LoggerLevel2[LoggerLevel2["ALL"] = 5] = "ALL";
|
|
763
|
+
return LoggerLevel2;
|
|
764
|
+
})(LoggerLevel || {});
|
|
765
|
+
var Logger = class {
|
|
766
|
+
static setLevel(level) {
|
|
767
|
+
this.level_ = level;
|
|
768
|
+
}
|
|
769
|
+
static getLevel() {
|
|
770
|
+
if (isProduction) {
|
|
771
|
+
return 1 /* ERROR */;
|
|
772
|
+
} else {
|
|
773
|
+
return this.level_;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
static error(...args) {
|
|
777
|
+
if (this.getLevel() >= 1 /* ERROR */) {
|
|
778
|
+
console.error(...args);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
static warn(...args) {
|
|
782
|
+
if (this.getLevel() >= 2 /* WARN */) {
|
|
783
|
+
console.warn(...args);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
static info(...args) {
|
|
787
|
+
if (this.getLevel() >= 3 /* INFO */) {
|
|
788
|
+
console.info(...args);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
static log(...args) {
|
|
792
|
+
if (this.getLevel() >= 4 /* LOG */) {
|
|
793
|
+
console.log(...args);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
Logger.level_ = 5 /* ALL */;
|
|
798
|
+
|
|
702
799
|
// src/qs/qs.ts
|
|
703
|
-
function
|
|
800
|
+
function qsSerializeKey(key, parentKey = "") {
|
|
704
801
|
return parentKey ? `${parentKey}[${key}]` : String(key);
|
|
705
802
|
}
|
|
706
|
-
function
|
|
803
|
+
function qsSerializeParam(key, value, serializedParams = [], parentKey = "") {
|
|
707
804
|
if (value != null) {
|
|
708
805
|
if (typeof value === "object") {
|
|
709
|
-
serializedParams =
|
|
806
|
+
serializedParams = qsSerializeParams(value, serializedParams, qsSerializeKey(key, parentKey));
|
|
710
807
|
} else {
|
|
711
808
|
serializedParams.push({
|
|
712
|
-
key:
|
|
809
|
+
key: qsSerializeKey(key, parentKey),
|
|
713
810
|
value
|
|
714
811
|
});
|
|
715
812
|
}
|
|
716
813
|
}
|
|
717
814
|
return serializedParams;
|
|
718
815
|
}
|
|
719
|
-
function
|
|
816
|
+
function qsSerializeParams(params, serializedParams = [], parentKey = "") {
|
|
720
817
|
if (Array.isArray(params)) {
|
|
721
818
|
params.forEach((value, key) => {
|
|
722
|
-
serializedParams =
|
|
819
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
723
820
|
});
|
|
724
821
|
} else {
|
|
725
822
|
Object.entries(params).forEach(([key, value]) => {
|
|
726
|
-
serializedParams =
|
|
823
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
727
824
|
});
|
|
728
825
|
}
|
|
729
826
|
return serializedParams;
|
|
730
827
|
}
|
|
731
828
|
function qsSerialize(queryParams = {}) {
|
|
732
|
-
const params =
|
|
829
|
+
const params = qsSerializeParams(queryParams);
|
|
733
830
|
if (params.length) {
|
|
734
831
|
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
735
832
|
}
|
|
736
833
|
return "";
|
|
737
834
|
}
|
|
738
|
-
function
|
|
739
|
-
|
|
740
|
-
|
|
835
|
+
function qsSerializeRaw(queryParams = {}) {
|
|
836
|
+
const params = qsSerializeParams(queryParams);
|
|
837
|
+
if (params.length) {
|
|
838
|
+
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
741
839
|
}
|
|
742
|
-
return
|
|
840
|
+
return "";
|
|
743
841
|
}
|
|
744
|
-
function
|
|
842
|
+
function qsDeserializeValue(value) {
|
|
745
843
|
if (String(parseInt(value)) === value) {
|
|
746
844
|
return Number(value);
|
|
747
845
|
} else if (String(value) === "true") {
|
|
@@ -751,14 +849,14 @@ function deserializeValue(value) {
|
|
|
751
849
|
}
|
|
752
850
|
return value;
|
|
753
851
|
}
|
|
754
|
-
function
|
|
852
|
+
function qsDeserializeKey(value) {
|
|
755
853
|
if (String(parseInt(value)) === value) {
|
|
756
854
|
return Number(value);
|
|
757
855
|
}
|
|
758
856
|
return value;
|
|
759
857
|
}
|
|
760
|
-
function
|
|
761
|
-
const keys = key.replace(/[\]]/g, "").split("[").map((x) =>
|
|
858
|
+
function qsDeserializeKeys(key) {
|
|
859
|
+
const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
|
|
762
860
|
return keys;
|
|
763
861
|
}
|
|
764
862
|
function getNextKeyItem(key) {
|
|
@@ -768,13 +866,13 @@ function getNextKeyItem(key) {
|
|
|
768
866
|
return {};
|
|
769
867
|
}
|
|
770
868
|
}
|
|
771
|
-
function
|
|
772
|
-
const keys =
|
|
869
|
+
function qsDeserializeParam(key, value, deserializedParams = {}) {
|
|
870
|
+
const keys = qsDeserializeKeys(key);
|
|
773
871
|
let target = deserializedParams;
|
|
774
872
|
while (keys.length) {
|
|
775
873
|
const key2 = keys.shift();
|
|
776
874
|
if (keys.length === 0) {
|
|
777
|
-
target[key2] =
|
|
875
|
+
target[key2] = qsDeserializeValue(value);
|
|
778
876
|
} else {
|
|
779
877
|
const next = target[key2] ? target[key2] : target[key2] = getNextKeyItem(keys[0]);
|
|
780
878
|
target = next;
|
|
@@ -782,8 +880,8 @@ function deserializeParam(key, value, deserializedParams = {}) {
|
|
|
782
880
|
}
|
|
783
881
|
return deserializedParams;
|
|
784
882
|
}
|
|
785
|
-
function
|
|
786
|
-
params.forEach((x) =>
|
|
883
|
+
function qsDeserializeParams(params, deserializedParams = {}) {
|
|
884
|
+
params.forEach((x) => qsDeserializeParam(x[0], x[1], deserializedParams));
|
|
787
885
|
return deserializedParams;
|
|
788
886
|
}
|
|
789
887
|
function qsDeserialize(query = "", deserializedParams = {}) {
|
|
@@ -793,7 +891,19 @@ function qsDeserialize(query = "", deserializedParams = {}) {
|
|
|
793
891
|
if (query !== "") {
|
|
794
892
|
const params = query.split("&").map((x) => x.split("="));
|
|
795
893
|
if (params.length) {
|
|
796
|
-
return
|
|
894
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return deserializedParams;
|
|
898
|
+
}
|
|
899
|
+
function qsDeserializeRaw(query = "", deserializedParams = {}) {
|
|
900
|
+
if (query.indexOf("?") === 0) {
|
|
901
|
+
query = query.substring(1);
|
|
902
|
+
}
|
|
903
|
+
if (query !== "") {
|
|
904
|
+
const params = query.split("&").map((x) => x.split("="));
|
|
905
|
+
if (params.length) {
|
|
906
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
797
907
|
}
|
|
798
908
|
}
|
|
799
909
|
return deserializedParams;
|
|
@@ -811,18 +921,19 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
811
921
|
const title = localize(item.title, locale.id);
|
|
812
922
|
const id = getRouteHref(segments, market, locale, markets2, locales2);
|
|
813
923
|
const route = {
|
|
924
|
+
category: item.category,
|
|
814
925
|
id,
|
|
815
|
-
|
|
926
|
+
isDefault: item.isDefault,
|
|
816
927
|
locale: locale.id,
|
|
817
|
-
|
|
928
|
+
market: market.id,
|
|
929
|
+
media: item.media,
|
|
930
|
+
order: item.order,
|
|
818
931
|
page: item.id,
|
|
819
932
|
schema: key,
|
|
820
933
|
template: item.template,
|
|
821
934
|
title,
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
useSplat: item.useSplat,
|
|
825
|
-
updatedAt: item.updatedAt
|
|
935
|
+
updatedAt: item.updatedAt,
|
|
936
|
+
useSplat: item.useSplat
|
|
826
937
|
};
|
|
827
938
|
routes.push(route);
|
|
828
939
|
}
|
|
@@ -941,6 +1052,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
941
1052
|
// Annotate the CommonJS export names for ESM import in node:
|
|
942
1053
|
0 && (module.exports = {
|
|
943
1054
|
JsonService,
|
|
1055
|
+
Logger,
|
|
1056
|
+
LoggerLevel,
|
|
944
1057
|
RedirectReason,
|
|
945
1058
|
RouteStrategy,
|
|
946
1059
|
asCategoryId,
|
|
@@ -948,10 +1061,9 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
948
1061
|
asServerProps,
|
|
949
1062
|
awaitAll,
|
|
950
1063
|
camelToSnakeCase,
|
|
1064
|
+
cloneItem,
|
|
951
1065
|
collectRoutes,
|
|
952
1066
|
consoleWarn,
|
|
953
|
-
deserializeKey,
|
|
954
|
-
deserializeValue,
|
|
955
1067
|
eachCategorized,
|
|
956
1068
|
eachMarketLocale,
|
|
957
1069
|
enumToList,
|
|
@@ -971,12 +1083,22 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
971
1083
|
httpPatch,
|
|
972
1084
|
httpPost,
|
|
973
1085
|
httpPut,
|
|
1086
|
+
isArray,
|
|
974
1087
|
isBrowser,
|
|
975
1088
|
isCategory,
|
|
976
1089
|
isDevelopment,
|
|
1090
|
+
isEntity,
|
|
1091
|
+
isEquatable,
|
|
977
1092
|
isLocalizedString,
|
|
1093
|
+
isNotNullString,
|
|
1094
|
+
isObject,
|
|
978
1095
|
isProduction,
|
|
1096
|
+
isRelation,
|
|
979
1097
|
isStage,
|
|
1098
|
+
isUndecoratedMenuItem,
|
|
1099
|
+
isUndecoratedMenuPage,
|
|
1100
|
+
isUndecoratedNav,
|
|
1101
|
+
isUnresolvedRelation,
|
|
980
1102
|
isValidCollectionDescription,
|
|
981
1103
|
localize,
|
|
982
1104
|
localizeItem,
|
|
@@ -988,7 +1110,9 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
988
1110
|
pascalCaseToKebabCase,
|
|
989
1111
|
pascalCaseToSnakeCase,
|
|
990
1112
|
qsDeserialize,
|
|
1113
|
+
qsDeserializeRaw,
|
|
991
1114
|
qsSerialize,
|
|
1115
|
+
qsSerializeRaw,
|
|
992
1116
|
textToSlug,
|
|
993
1117
|
toCamelCase,
|
|
994
1118
|
toCharCase,
|
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,14 @@ 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
|
+
|
|
167
175
|
// src/utils/babelCase.ts
|
|
168
176
|
function unknownCaseToPascalCase(unknownCase) {
|
|
169
177
|
const pascalCase = unknownCase.replace(
|
|
@@ -214,6 +222,52 @@ function toSnakeCase(unknownCase) {
|
|
|
214
222
|
return snakeCase;
|
|
215
223
|
}
|
|
216
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
|
+
|
|
217
271
|
// src/utils/enumToList.ts
|
|
218
272
|
function enumToList(enumeration, separatorRegex = /_/g) {
|
|
219
273
|
const array = Object.keys(enumeration);
|
|
@@ -338,7 +392,7 @@ var JsonService = class {
|
|
|
338
392
|
params.where.id = params.where.id || { equals: id };
|
|
339
393
|
items = this.whereItems_(items, params.where);
|
|
340
394
|
if (items.length > 0) {
|
|
341
|
-
return this.
|
|
395
|
+
return await this.decorateOne_(items[0], params);
|
|
342
396
|
} else {
|
|
343
397
|
console.log("JsonService.findOne.notfound", id, params);
|
|
344
398
|
return void 0;
|
|
@@ -353,7 +407,7 @@ var JsonService = class {
|
|
|
353
407
|
if (params.sort) {
|
|
354
408
|
items = this.sortCollection_(items, params.sort);
|
|
355
409
|
}
|
|
356
|
-
return
|
|
410
|
+
return await this.decorateMany_(items, params);
|
|
357
411
|
}
|
|
358
412
|
async findPaged(params = {}) {
|
|
359
413
|
params.pagination = true;
|
|
@@ -365,7 +419,7 @@ var JsonService = class {
|
|
|
365
419
|
items = this.sortCollection_(items, params.sort);
|
|
366
420
|
}
|
|
367
421
|
const pagination = this.paginatedItems_(items, params.page, params.limit);
|
|
368
|
-
pagination.docs =
|
|
422
|
+
pagination.docs = await this.decorateMany_(pagination.docs, params);
|
|
369
423
|
return pagination;
|
|
370
424
|
}
|
|
371
425
|
async create(payload) {
|
|
@@ -402,9 +456,12 @@ var JsonService = class {
|
|
|
402
456
|
}
|
|
403
457
|
return void 0;
|
|
404
458
|
}
|
|
405
|
-
|
|
459
|
+
async decorateOne_(item, params = {}) {
|
|
406
460
|
return item;
|
|
407
461
|
}
|
|
462
|
+
async decorateMany_(items, params = {}) {
|
|
463
|
+
return items;
|
|
464
|
+
}
|
|
408
465
|
newUUID_() {
|
|
409
466
|
return (/* @__PURE__ */ new Date()).getTime();
|
|
410
467
|
}
|
|
@@ -446,24 +503,6 @@ var JsonService = class {
|
|
|
446
503
|
}
|
|
447
504
|
return true;
|
|
448
505
|
}
|
|
449
|
-
// old where
|
|
450
|
-
/*
|
|
451
|
-
protected where_(items: any[], params: FindParams): any[] {
|
|
452
|
-
const where = params.where;
|
|
453
|
-
if (where) {
|
|
454
|
-
const keys = Object.keys(where);
|
|
455
|
-
items = items.filter(x => {
|
|
456
|
-
return keys.reduce<boolean>((p, c) => {
|
|
457
|
-
const whereValue = where[c];
|
|
458
|
-
const shouldMatch = Array.isArray(whereValue) ? whereValue : [whereValue];
|
|
459
|
-
// console.log('key', c, 'value', x[c], 'shouldMatch', shouldMatch);
|
|
460
|
-
return p && (shouldMatch.indexOf(x[c]) !== -1);
|
|
461
|
-
}, true);
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
return items;
|
|
465
|
-
}
|
|
466
|
-
*/
|
|
467
506
|
whereItem_(item, where) {
|
|
468
507
|
let has = true;
|
|
469
508
|
if (typeof where === "object") {
|
|
@@ -591,60 +630,106 @@ function localizeValue(value, locale = "en", defaultLocale = "en") {
|
|
|
591
630
|
}
|
|
592
631
|
}
|
|
593
632
|
function localizeItem(item, locale = "en", defaultLocale = "en") {
|
|
594
|
-
if (
|
|
633
|
+
if (isArray(item)) {
|
|
595
634
|
item = item.map((x) => localizeValue(x, locale, defaultLocale));
|
|
596
|
-
} else if (
|
|
635
|
+
} else if (isObject(item)) {
|
|
597
636
|
item = { ...item };
|
|
598
|
-
|
|
599
|
-
|
|
637
|
+
const object = item;
|
|
638
|
+
Object.keys(object).forEach((key) => {
|
|
639
|
+
object[key] = localizeValue(object[key], locale, defaultLocale);
|
|
600
640
|
});
|
|
601
641
|
}
|
|
602
642
|
return item;
|
|
603
643
|
}
|
|
604
644
|
|
|
645
|
+
// src/logger/logger.ts
|
|
646
|
+
var LoggerLevel = /* @__PURE__ */ ((LoggerLevel2) => {
|
|
647
|
+
LoggerLevel2[LoggerLevel2["NONE"] = 0] = "NONE";
|
|
648
|
+
LoggerLevel2[LoggerLevel2["ERROR"] = 1] = "ERROR";
|
|
649
|
+
LoggerLevel2[LoggerLevel2["WARN"] = 2] = "WARN";
|
|
650
|
+
LoggerLevel2[LoggerLevel2["INFO"] = 3] = "INFO";
|
|
651
|
+
LoggerLevel2[LoggerLevel2["LOG"] = 4] = "LOG";
|
|
652
|
+
LoggerLevel2[LoggerLevel2["ALL"] = 5] = "ALL";
|
|
653
|
+
return LoggerLevel2;
|
|
654
|
+
})(LoggerLevel || {});
|
|
655
|
+
var Logger = class {
|
|
656
|
+
static setLevel(level) {
|
|
657
|
+
this.level_ = level;
|
|
658
|
+
}
|
|
659
|
+
static getLevel() {
|
|
660
|
+
if (isProduction) {
|
|
661
|
+
return 1 /* ERROR */;
|
|
662
|
+
} else {
|
|
663
|
+
return this.level_;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
static error(...args) {
|
|
667
|
+
if (this.getLevel() >= 1 /* ERROR */) {
|
|
668
|
+
console.error(...args);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
static warn(...args) {
|
|
672
|
+
if (this.getLevel() >= 2 /* WARN */) {
|
|
673
|
+
console.warn(...args);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
static info(...args) {
|
|
677
|
+
if (this.getLevel() >= 3 /* INFO */) {
|
|
678
|
+
console.info(...args);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
static log(...args) {
|
|
682
|
+
if (this.getLevel() >= 4 /* LOG */) {
|
|
683
|
+
console.log(...args);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
Logger.level_ = 5 /* ALL */;
|
|
688
|
+
|
|
605
689
|
// src/qs/qs.ts
|
|
606
|
-
function
|
|
690
|
+
function qsSerializeKey(key, parentKey = "") {
|
|
607
691
|
return parentKey ? `${parentKey}[${key}]` : String(key);
|
|
608
692
|
}
|
|
609
|
-
function
|
|
693
|
+
function qsSerializeParam(key, value, serializedParams = [], parentKey = "") {
|
|
610
694
|
if (value != null) {
|
|
611
695
|
if (typeof value === "object") {
|
|
612
|
-
serializedParams =
|
|
696
|
+
serializedParams = qsSerializeParams(value, serializedParams, qsSerializeKey(key, parentKey));
|
|
613
697
|
} else {
|
|
614
698
|
serializedParams.push({
|
|
615
|
-
key:
|
|
699
|
+
key: qsSerializeKey(key, parentKey),
|
|
616
700
|
value
|
|
617
701
|
});
|
|
618
702
|
}
|
|
619
703
|
}
|
|
620
704
|
return serializedParams;
|
|
621
705
|
}
|
|
622
|
-
function
|
|
706
|
+
function qsSerializeParams(params, serializedParams = [], parentKey = "") {
|
|
623
707
|
if (Array.isArray(params)) {
|
|
624
708
|
params.forEach((value, key) => {
|
|
625
|
-
serializedParams =
|
|
709
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
626
710
|
});
|
|
627
711
|
} else {
|
|
628
712
|
Object.entries(params).forEach(([key, value]) => {
|
|
629
|
-
serializedParams =
|
|
713
|
+
serializedParams = qsSerializeParam(key, value, serializedParams, parentKey);
|
|
630
714
|
});
|
|
631
715
|
}
|
|
632
716
|
return serializedParams;
|
|
633
717
|
}
|
|
634
718
|
function qsSerialize(queryParams = {}) {
|
|
635
|
-
const params =
|
|
719
|
+
const params = qsSerializeParams(queryParams);
|
|
636
720
|
if (params.length) {
|
|
637
721
|
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
638
722
|
}
|
|
639
723
|
return "";
|
|
640
724
|
}
|
|
641
|
-
function
|
|
642
|
-
|
|
643
|
-
|
|
725
|
+
function qsSerializeRaw(queryParams = {}) {
|
|
726
|
+
const params = qsSerializeParams(queryParams);
|
|
727
|
+
if (params.length) {
|
|
728
|
+
return params.map((x) => `${x.key}=${x.value}`).join("&");
|
|
644
729
|
}
|
|
645
|
-
return
|
|
730
|
+
return "";
|
|
646
731
|
}
|
|
647
|
-
function
|
|
732
|
+
function qsDeserializeValue(value) {
|
|
648
733
|
if (String(parseInt(value)) === value) {
|
|
649
734
|
return Number(value);
|
|
650
735
|
} else if (String(value) === "true") {
|
|
@@ -654,14 +739,14 @@ function deserializeValue(value) {
|
|
|
654
739
|
}
|
|
655
740
|
return value;
|
|
656
741
|
}
|
|
657
|
-
function
|
|
742
|
+
function qsDeserializeKey(value) {
|
|
658
743
|
if (String(parseInt(value)) === value) {
|
|
659
744
|
return Number(value);
|
|
660
745
|
}
|
|
661
746
|
return value;
|
|
662
747
|
}
|
|
663
|
-
function
|
|
664
|
-
const keys = key.replace(/[\]]/g, "").split("[").map((x) =>
|
|
748
|
+
function qsDeserializeKeys(key) {
|
|
749
|
+
const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
|
|
665
750
|
return keys;
|
|
666
751
|
}
|
|
667
752
|
function getNextKeyItem(key) {
|
|
@@ -671,13 +756,13 @@ function getNextKeyItem(key) {
|
|
|
671
756
|
return {};
|
|
672
757
|
}
|
|
673
758
|
}
|
|
674
|
-
function
|
|
675
|
-
const keys =
|
|
759
|
+
function qsDeserializeParam(key, value, deserializedParams = {}) {
|
|
760
|
+
const keys = qsDeserializeKeys(key);
|
|
676
761
|
let target = deserializedParams;
|
|
677
762
|
while (keys.length) {
|
|
678
763
|
const key2 = keys.shift();
|
|
679
764
|
if (keys.length === 0) {
|
|
680
|
-
target[key2] =
|
|
765
|
+
target[key2] = qsDeserializeValue(value);
|
|
681
766
|
} else {
|
|
682
767
|
const next = target[key2] ? target[key2] : target[key2] = getNextKeyItem(keys[0]);
|
|
683
768
|
target = next;
|
|
@@ -685,8 +770,8 @@ function deserializeParam(key, value, deserializedParams = {}) {
|
|
|
685
770
|
}
|
|
686
771
|
return deserializedParams;
|
|
687
772
|
}
|
|
688
|
-
function
|
|
689
|
-
params.forEach((x) =>
|
|
773
|
+
function qsDeserializeParams(params, deserializedParams = {}) {
|
|
774
|
+
params.forEach((x) => qsDeserializeParam(x[0], x[1], deserializedParams));
|
|
690
775
|
return deserializedParams;
|
|
691
776
|
}
|
|
692
777
|
function qsDeserialize(query = "", deserializedParams = {}) {
|
|
@@ -696,7 +781,19 @@ function qsDeserialize(query = "", deserializedParams = {}) {
|
|
|
696
781
|
if (query !== "") {
|
|
697
782
|
const params = query.split("&").map((x) => x.split("="));
|
|
698
783
|
if (params.length) {
|
|
699
|
-
return
|
|
784
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return deserializedParams;
|
|
788
|
+
}
|
|
789
|
+
function qsDeserializeRaw(query = "", deserializedParams = {}) {
|
|
790
|
+
if (query.indexOf("?") === 0) {
|
|
791
|
+
query = query.substring(1);
|
|
792
|
+
}
|
|
793
|
+
if (query !== "") {
|
|
794
|
+
const params = query.split("&").map((x) => x.split("="));
|
|
795
|
+
if (params.length) {
|
|
796
|
+
return qsDeserializeParams(params, deserializedParams);
|
|
700
797
|
}
|
|
701
798
|
}
|
|
702
799
|
return deserializedParams;
|
|
@@ -714,18 +811,19 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
714
811
|
const title = localize(item.title, locale.id);
|
|
715
812
|
const id = getRouteHref(segments, market, locale, markets2, locales2);
|
|
716
813
|
const route = {
|
|
814
|
+
category: item.category,
|
|
717
815
|
id,
|
|
718
|
-
|
|
816
|
+
isDefault: item.isDefault,
|
|
719
817
|
locale: locale.id,
|
|
720
|
-
|
|
818
|
+
market: market.id,
|
|
819
|
+
media: item.media,
|
|
820
|
+
order: item.order,
|
|
721
821
|
page: item.id,
|
|
722
822
|
schema: key,
|
|
723
823
|
template: item.template,
|
|
724
824
|
title,
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
useSplat: item.useSplat,
|
|
728
|
-
updatedAt: item.updatedAt
|
|
825
|
+
updatedAt: item.updatedAt,
|
|
826
|
+
useSplat: item.useSplat
|
|
729
827
|
};
|
|
730
828
|
routes.push(route);
|
|
731
829
|
}
|
|
@@ -843,6 +941,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
843
941
|
})(RedirectReason || {});
|
|
844
942
|
export {
|
|
845
943
|
JsonService,
|
|
944
|
+
Logger,
|
|
945
|
+
LoggerLevel,
|
|
846
946
|
RedirectReason,
|
|
847
947
|
RouteStrategy,
|
|
848
948
|
asCategoryId,
|
|
@@ -850,10 +950,9 @@ export {
|
|
|
850
950
|
asServerProps,
|
|
851
951
|
awaitAll,
|
|
852
952
|
camelToSnakeCase,
|
|
953
|
+
cloneItem,
|
|
853
954
|
collectRoutes,
|
|
854
955
|
consoleWarn,
|
|
855
|
-
deserializeKey,
|
|
856
|
-
deserializeValue,
|
|
857
956
|
eachCategorized,
|
|
858
957
|
eachMarketLocale,
|
|
859
958
|
enumToList,
|
|
@@ -873,12 +972,22 @@ export {
|
|
|
873
972
|
httpPatch,
|
|
874
973
|
httpPost,
|
|
875
974
|
httpPut,
|
|
975
|
+
isArray,
|
|
876
976
|
isBrowser,
|
|
877
977
|
isCategory,
|
|
878
978
|
isDevelopment,
|
|
979
|
+
isEntity,
|
|
980
|
+
isEquatable,
|
|
879
981
|
isLocalizedString,
|
|
982
|
+
isNotNullString,
|
|
983
|
+
isObject,
|
|
880
984
|
isProduction,
|
|
985
|
+
isRelation,
|
|
881
986
|
isStage,
|
|
987
|
+
isUndecoratedMenuItem,
|
|
988
|
+
isUndecoratedMenuPage,
|
|
989
|
+
isUndecoratedNav,
|
|
990
|
+
isUnresolvedRelation,
|
|
882
991
|
isValidCollectionDescription,
|
|
883
992
|
localize,
|
|
884
993
|
localizeItem,
|
|
@@ -890,7 +999,9 @@ export {
|
|
|
890
999
|
pascalCaseToKebabCase,
|
|
891
1000
|
pascalCaseToSnakeCase,
|
|
892
1001
|
qsDeserialize,
|
|
1002
|
+
qsDeserializeRaw,
|
|
893
1003
|
qsSerialize,
|
|
1004
|
+
qsSerializeRaw,
|
|
894
1005
|
textToSlug,
|
|
895
1006
|
toCamelCase,
|
|
896
1007
|
toCharCase,
|