@websolutespa/bom-core 1.6.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 1.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: JsonService containsClause
8
+
9
+ ## 1.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 28e86bd: Modified: IPage, Store services & decorators
14
+
3
15
  ## 1.6.0
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
2
  import { ParsedUrlQuery } from 'querystring';
3
+ import React from 'react';
3
4
 
4
5
  type Json = string | number | boolean | null | Json[] | {
5
6
  [key: string]: Json;
@@ -51,11 +52,19 @@ type IPartial<T> = {
51
52
  type IPrettify<T> = {
52
53
  [K in keyof T]: T[K];
53
54
  } & {};
54
- type IOverride<T, TypeToReplace, TypeToReplaceWith> = {
55
- [K in keyof T]: T[K] extends Record<string, unknown> ? IOverride<T[K], TypeToReplace, TypeToReplaceWith> : T[K] extends TypeToReplace ? TypeToReplaceWith : T[K];
55
+ type IOverrideReturnValue<T, FromType, ToType> = T extends Record<string, unknown> ? IOverride<T, FromType, ToType> : T;
56
+ type IOverrideValue<T, FromType, ToType> = T extends FromType ? ToType : IOverrideReturnValue<T, FromType, ToType>;
57
+ type IOverride<T, FromType, ToType> = {
58
+ [Property in keyof T]: IOverrideValue<T[Property], FromType, ToType>;
56
59
  };
57
60
 
58
- type ILocalizedString = Record<string, string>;
61
+ /**
62
+ * List of ISO 639 language codes (set 1)
63
+ * https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
64
+ */
65
+ type ILetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
66
+ type ILocaleId = `${ILetter}${ILetter}`;
67
+ type ILocalizedString = Record<ILocaleId, string>;
59
68
  type ILocalizable = string | ILocalizedString;
60
69
  type ILocalized<T> = IOverride<T, ILocalizable, string>;
61
70
 
@@ -102,6 +111,11 @@ type IAnchor = {
102
111
  title?: ILocalizable;
103
112
  };
104
113
 
114
+ type IComponent = {
115
+ schema: string;
116
+ [key: string]: unknown;
117
+ };
118
+
105
119
  type IEquatable = number | string;
106
120
  type SchemaType = string;
107
121
  type ISchema = {
@@ -146,6 +160,13 @@ type IMedia = {
146
160
  };
147
161
  declare function resolveMediaType(media: IMedia): IMediaType;
148
162
 
163
+ type IMeta = {
164
+ title?: string;
165
+ description?: string;
166
+ keywords?: string;
167
+ robots?: string;
168
+ };
169
+
149
170
  type ICategory = IEntity & {
150
171
  category?: IEquatable | ICategory;
151
172
  id: IEquatable;
@@ -157,19 +178,20 @@ type ICategory = IEntity & {
157
178
  type ICategoryItem = ICategory & {
158
179
  items: ICategory[];
159
180
  };
160
- type ICategorized = {
161
- abstract?: ILocalizable;
162
- category: IEquatable | ICategory;
163
- id: IEquatable;
164
- isDefault?: boolean;
165
- markets?: string[];
181
+ type ICategorized = IEntity & {
182
+ title: ILocalizable;
183
+ abstract?: string;
184
+ description?: string;
166
185
  media?: IMedia;
167
- order?: number;
168
- schema?: string;
186
+ meta?: IMeta;
187
+ components?: IComponent[];
188
+ category: IEquatable | ICategory;
169
189
  slug: ILocalizable;
170
190
  template?: string;
171
- title: ILocalizable;
191
+ isDefault?: boolean;
172
192
  useSplat?: boolean;
193
+ order?: number;
194
+ markets?: string[];
173
195
  createdAt?: Date;
174
196
  updatedAt?: Date;
175
197
  };
@@ -221,13 +243,6 @@ type IMarket = IEntity & {
221
243
  isHidden?: boolean;
222
244
  };
223
245
 
224
- type IMeta = {
225
- title?: string;
226
- description?: string;
227
- keywords?: string;
228
- robots?: string;
229
- };
230
-
231
246
  type IRoute = {
232
247
  category: IEquatable | ICategory;
233
248
  id: string;
@@ -261,20 +276,25 @@ type IRouteParams = Record<string, any> & {
261
276
  market: string;
262
277
  };
263
278
 
264
- type IPage = Record<string, any> & ICategorized & {
265
- abstract?: string;
279
+ type IPage<T extends ICategorized = ICategorized> = ILocalized<T> & {
266
280
  alternates: IRoute[];
267
281
  breadcrumb: IRouteLink[];
268
- content?: string;
269
- description?: string;
282
+ category: ILocalized<ICategory>;
270
283
  href: string;
271
284
  locale: string;
272
285
  market: string;
273
- meta?: IMeta;
274
286
  parentRoute?: IRouteLink;
275
287
  slug: string;
276
288
  title: string;
277
289
  };
290
+ type PageProps<T extends ICategorized = ICategorized> = {
291
+ layout: ILayout;
292
+ page: IPage<T>;
293
+ params: IRouteParams;
294
+ locales?: string[];
295
+ locale?: string;
296
+ defaultLocale?: string;
297
+ };
278
298
  type IPageRelationResult<T extends ICategorized = ICategorized> = {
279
299
  href: string;
280
300
  } & T;
@@ -286,15 +306,6 @@ type IPageUnresolvedRelation = {
286
306
  relationTo: string;
287
307
  value: IEquatable | IEquatable[];
288
308
  };
289
- type IPageResult<T extends ICategorized = ICategorized> = IPage & T;
290
- type PageProps<T extends ICategorized = ICategorized> = {
291
- layout: ILayout;
292
- page: IPageResult<T>;
293
- params: IRouteParams;
294
- locales?: string[];
295
- locale?: string;
296
- defaultLocale?: string;
297
- };
298
309
 
299
310
  type IMenuBase = {
300
311
  abstract?: ILocalizable;
@@ -391,7 +402,7 @@ type ILayout = {
391
402
  locales: ILocale[];
392
403
  market: string;
393
404
  markets: IMarket[];
394
- menu: Record<string, IMenu>;
405
+ menu: Record<string, ILocalized<IMenu>>;
395
406
  topLevelHrefs: Record<string, string>;
396
407
  topLevelRoutes: Record<string, IRouteLink>;
397
408
  tree?: IRouteLink;
@@ -489,7 +500,7 @@ type IRedirect = {
489
500
  };
490
501
 
491
502
  type IMemoryStore<T extends IEntity = IEntity> = Record<string, T[]>;
492
- type IStore = Record<string, IQuerable<IEntity>>;
503
+ type IStore = Record<string, IQuerable>;
493
504
  type IConfig = {
494
505
  collections: string[];
495
506
  mocks: string[];
@@ -559,11 +570,27 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
559
570
  protected decorateMany_<B extends T = T>(items: B[], params?: QueryParams): Promise<B[]>;
560
571
  protected newUUID_(): number;
561
572
  protected evaluateValue_(value: unknown): unknown;
573
+ /**
574
+ equals The value must be exactly equal.
575
+ not_equals The query will return all documents where the value is not equal.
576
+ greater_than For numeric or date-based fields.
577
+ greater_than_equal For numeric or date-based fields.
578
+ less_than For numeric or date-based fields.
579
+ less_than_equal For numeric or date-based fields.
580
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
581
+ contains Must contain the value entered, case-insensitive.
582
+ in The value must be found within the provided comma-delimited list of values.
583
+ not_in The value must NOT be within the provided comma-delimited list of values.
584
+ all The value must contain all values provided in the comma-delimited list.
585
+ exists Only return documents where the value either exists (true) or does not exist (false).
586
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
587
+ */
562
588
  protected existsClause_(value: unknown, exists?: boolean): boolean;
563
589
  protected equalsClause_(value: unknown, equals?: unknown): boolean;
564
590
  protected inClause_(value: unknown, values?: unknown[]): boolean;
565
591
  protected notInClause_(value: unknown, values?: unknown[]): boolean;
566
592
  protected likeClause_(value: unknown, query?: string): boolean;
593
+ protected containsClause_(value: unknown, contains?: IEquatable): boolean;
567
594
  protected whereItem_<B extends T = T>(item: B, where?: Where): boolean;
568
595
  protected whereItems_<B extends T = T>(items: B[], where?: Where): B[];
569
596
  protected sortCollection_<B extends T = T>(items: B[], sort?: string): B[];
@@ -677,9 +704,9 @@ declare const isProduction: boolean;
677
704
  declare const isStage: boolean;
678
705
  declare const isBrowser: boolean;
679
706
  declare function getEnv(): Record<string, Json>;
680
- declare function withSchema<Component extends {}, Schema>(component: Component, schema: Schema): Component & Schema;
707
+ declare function withSchema<Component extends React.FC<any>, Schema>(component: Component, schema: Schema): Component & Schema;
681
708
  declare function asServerProps(props: any): any;
682
709
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
683
710
  declare function merge(target: any, source: any): any;
684
711
 
685
- export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageRelationResult, IPageResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, 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, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, defaultLocale, defaultMarket, 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, isMenuHref, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
712
+ export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageRelation, IPageRelationResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPreference, 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, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, defaultLocale, defaultMarket, 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, isMenuHref, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
package/dist/index.js CHANGED
@@ -652,6 +652,21 @@ var JsonService = class {
652
652
  return value;
653
653
  }
654
654
  }
655
+ /**
656
+ equals The value must be exactly equal.
657
+ not_equals The query will return all documents where the value is not equal.
658
+ greater_than For numeric or date-based fields.
659
+ greater_than_equal For numeric or date-based fields.
660
+ less_than For numeric or date-based fields.
661
+ less_than_equal For numeric or date-based fields.
662
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
663
+ contains Must contain the value entered, case-insensitive.
664
+ in The value must be found within the provided comma-delimited list of values.
665
+ not_in The value must NOT be within the provided comma-delimited list of values.
666
+ all The value must contain all values provided in the comma-delimited list.
667
+ exists Only return documents where the value either exists (true) or does not exist (false).
668
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
669
+ */
655
670
  existsClause_(value, exists) {
656
671
  if (typeof exists === "boolean") {
657
672
  return value != null === exists;
@@ -682,6 +697,18 @@ var JsonService = class {
682
697
  }
683
698
  return true;
684
699
  }
700
+ containsClause_(value, contains) {
701
+ if (typeof contains !== "undefined") {
702
+ if (Array.isArray(value)) {
703
+ return value.reduce((p, c) => p || String(c).toLowerCase() === String(value).toLowerCase(), false);
704
+ } else if (typeof value === "string") {
705
+ return value.toLowerCase().includes(String(contains).toLowerCase());
706
+ } else {
707
+ return false;
708
+ }
709
+ }
710
+ return true;
711
+ }
685
712
  whereItem_(item, where) {
686
713
  let has = true;
687
714
  if (typeof where === "object") {
@@ -710,6 +737,7 @@ var JsonService = class {
710
737
  has = has && this.inClause_(value, v.in);
711
738
  has = has && this.notInClause_(value, v.not_in);
712
739
  has = has && this.likeClause_(value, v.like);
740
+ has = has && this.containsClause_(value, v.contains);
713
741
  }
714
742
  }
715
743
  });
package/dist/index.mjs CHANGED
@@ -534,6 +534,21 @@ var JsonService = class {
534
534
  return value;
535
535
  }
536
536
  }
537
+ /**
538
+ equals The value must be exactly equal.
539
+ not_equals The query will return all documents where the value is not equal.
540
+ greater_than For numeric or date-based fields.
541
+ greater_than_equal For numeric or date-based fields.
542
+ less_than For numeric or date-based fields.
543
+ less_than_equal For numeric or date-based fields.
544
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
545
+ contains Must contain the value entered, case-insensitive.
546
+ in The value must be found within the provided comma-delimited list of values.
547
+ not_in The value must NOT be within the provided comma-delimited list of values.
548
+ all The value must contain all values provided in the comma-delimited list.
549
+ exists Only return documents where the value either exists (true) or does not exist (false).
550
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
551
+ */
537
552
  existsClause_(value, exists) {
538
553
  if (typeof exists === "boolean") {
539
554
  return value != null === exists;
@@ -564,6 +579,18 @@ var JsonService = class {
564
579
  }
565
580
  return true;
566
581
  }
582
+ containsClause_(value, contains) {
583
+ if (typeof contains !== "undefined") {
584
+ if (Array.isArray(value)) {
585
+ return value.reduce((p, c) => p || String(c).toLowerCase() === String(value).toLowerCase(), false);
586
+ } else if (typeof value === "string") {
587
+ return value.toLowerCase().includes(String(contains).toLowerCase());
588
+ } else {
589
+ return false;
590
+ }
591
+ }
592
+ return true;
593
+ }
567
594
  whereItem_(item, where) {
568
595
  let has = true;
569
596
  if (typeof where === "object") {
@@ -592,6 +619,7 @@ var JsonService = class {
592
619
  has = has && this.inClause_(value, v.in);
593
620
  has = has && this.notInClause_(value, v.not_in);
594
621
  has = has && this.likeClause_(value, v.like);
622
+ has = has && this.containsClause_(value, v.contains);
595
623
  }
596
624
  }
597
625
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",