@websolutespa/bom-core 1.8.10 → 1.8.12

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.8.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: IQuerable
8
+
9
+ ## 1.8.11
10
+
11
+ ### Patch Changes
12
+
13
+ - Added: isUnresolvedCategory, isUndecoratedCategory
14
+
3
15
  ## 1.8.10
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -600,16 +600,16 @@ type WhereAndOr = {
600
600
  };
601
601
  type Where = WhereBase & WhereAndOr;
602
602
  type QueryParams = {
603
- where?: Where;
603
+ depth?: number;
604
+ draft?: boolean;
605
+ limit?: number;
604
606
  locale?: string;
605
607
  market?: string;
606
- sort?: string;
607
608
  page?: number;
608
- limit?: number;
609
- depth?: number;
610
- draft?: boolean;
611
609
  pagination?: boolean;
612
610
  richText?: boolean;
611
+ sort?: string;
612
+ where?: Where;
613
613
  };
614
614
 
615
615
  type IPagedResult<T extends IEntity = IEntity> = {
@@ -620,6 +620,10 @@ type IQuerable<T extends IEntity = IEntity> = {
620
620
  findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
621
621
  findPaged<B extends T = T>(params?: QueryParams): Promise<IPagedResult<B>>;
622
622
  create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
623
+ updateOne<B extends T = T>(id: IEquatable, payload: Partial<B>, params?: Omit<QueryParams, 'where'>): Promise<B>;
624
+ updateMany<B extends T = T>(payload: Partial<B>, params?: QueryParams): Promise<B[]>;
625
+ deleteOne<B extends T = T>(id: IEquatable, params?: Omit<QueryParams, 'where'>): Promise<B | undefined>;
626
+ deleteMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
623
627
  update<B extends T = T>(payload: Partial<B>): Promise<B>;
624
628
  delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
625
629
  };
@@ -871,6 +875,10 @@ declare class JsonService<T extends IEntity = IEntity> implements IQuerable<T> {
871
875
  findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
872
876
  findPaged<B extends T = T>(params?: QueryParams): Promise<IPagedResult<B>>;
873
877
  create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
878
+ updateOne<B extends T = T>(id: IEquatable, payload: Partial<B>, params?: QueryParams): Promise<B>;
879
+ updateMany<B extends T = T>(payload: Partial<B>, params?: QueryParams): Promise<B[]>;
880
+ deleteOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
881
+ deleteMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
874
882
  update<B extends T = T>(payload: Partial<B>): Promise<B>;
875
883
  delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
876
884
  protected decorateOne_<B extends T = T>(item: B, params?: QueryParams): Promise<B>;
@@ -1267,6 +1275,8 @@ declare function isUnresolvedRelation(item: unknown): item is IPageUnresolvedRel
1267
1275
  * @returns True if the item is a relation, false otherwise.
1268
1276
  */
1269
1277
  declare function isRelation(item: unknown): item is IPageRelation;
1278
+ declare function isUnresolvedCategory(category?: IEquatable | ICategory): category is IEquatable;
1279
+ declare function isUndecoratedCategory(category: unknown): category is Omit<ICategory, 'href'>;
1270
1280
  /**
1271
1281
  * Checks if the given item is an undecorated menu item.
1272
1282
  * @param item The item to check.
@@ -1311,4 +1321,4 @@ declare function asServerProps(props: any): any;
1311
1321
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
1312
1322
  declare function merge(target: any, source: any): any;
1313
1323
 
1314
- export { DeepPartial, Dynamic, FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IActionEmailData, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEmailConfig, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, IImageResize, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedMenu, ILocalizedString, IMarket, IMedia, IMediaImage, IMediaInfo, IMediaJson, IMediaPdf, IMediaType, IMediaVideo, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageItem, 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, ImageStrategy, Json, JsonService, LiteralUnion, Logger, LoggerLevel, MenuCategoryStrategy, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, Primitive, QueryParams, RedirectReason, RequireAtLeastOne, RouteStrategy, SchemaType, ServerSidePropsContext, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, arrayShuffle, asCategoryId, asEntityId, asEquatable, asEquatableNumber, asEquatableString, asServerProps, asSortedOptions, awaitAll, base64ToString, camelToSnakeCase, cloneItem, collectFeatureTypes, collectFeatureTypes__, collectOptions, collectRoutes, consoleWarn, decryptImageResize, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, encryptImageToken, enumToList, findCategoryInCategories, findChildCategories, findRouteOfCategory, findRoutesOfCategory, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getOrigin, getParentCategoriesById, getParentCategory, getProto, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMediaImage, isMediaJson, isMediaPdf, isMediaVideo, isMenuCategory, isMenuGroup, isMenuHref, isMenuLink, isMenuPage, isMenuRoute, isNotNullString, isNumber, isObject, isProduction, isPromise, isRelation, isReservedCollectionDescription, isStage, isString, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, isValidString, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, stringToBase64, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, uuidv4, withSchema };
1324
+ export { DeepPartial, Dynamic, FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAction, IActionEmailData, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IComponent, IConfig, IConsentPreference, IContextBaseParams, IContextParams, IDecoratedNav, IEmailConfig, IEndUser, IEntity, IEquatable, IFeature, IFeatureType, IImageResize, ILabel, ILayout, ILegalNotice, ILetter, ILocale, ILocaleId, ILocalizable, ILocalized, ILocalizedMenu, ILocalizedString, IMarket, IMedia, IMediaImage, IMediaInfo, IMediaJson, IMediaPdf, IMediaType, IMediaVideo, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuHref, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IOverrideReturnValue, IOverrideValue, IPackages, IPage, IPageItem, 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, ImageStrategy, Json, JsonService, LiteralUnion, Logger, LoggerLevel, MenuCategoryStrategy, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, Primitive, QueryParams, RedirectReason, RequireAtLeastOne, RouteStrategy, SchemaType, ServerSidePropsContext, StaticPropsContext, User, UserRole, UserWithRoles, ValueOf, Where, WhereAndOr, WhereBase, WhereField, arrayShuffle, asCategoryId, asEntityId, asEquatable, asEquatableNumber, asEquatableString, asServerProps, asSortedOptions, awaitAll, base64ToString, camelToSnakeCase, cloneItem, collectFeatureTypes, collectFeatureTypes__, collectOptions, collectRoutes, consoleWarn, decryptImageResize, deepMerge, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, encryptImageToken, enumToList, findCategoryInCategories, findChildCategories, findRouteOfCategory, findRoutesOfCategory, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getHost, getIsDevelopment, getIsProduction, getOrigin, getParentCategoriesById, getParentCategory, getProto, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isDevelopment, isEntity, isEquatable, isHeaders, isIncomingHttpHeaders, isLocalizedString, isMediaImage, isMediaJson, isMediaPdf, isMediaVideo, isMenuCategory, isMenuGroup, isMenuHref, isMenuLink, isMenuPage, isMenuRoute, isNotNullString, isNumber, isObject, isProduction, isPromise, isRelation, isReservedCollectionDescription, isStage, isString, isUndecoratedCategory, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedCategory, isUnresolvedRelation, isValidCollectionDescription, isValidString, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, stringToBase64, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, uuidv4, withSchema };
package/dist/index.js CHANGED
@@ -113,10 +113,12 @@ __export(src_exports, {
113
113
  isReservedCollectionDescription: () => isReservedCollectionDescription,
114
114
  isStage: () => isStage,
115
115
  isString: () => isString,
116
+ isUndecoratedCategory: () => isUndecoratedCategory,
116
117
  isUndecoratedMenuCategory: () => isUndecoratedMenuCategory,
117
118
  isUndecoratedMenuItem: () => isUndecoratedMenuItem,
118
119
  isUndecoratedMenuPage: () => isUndecoratedMenuPage,
119
120
  isUndecoratedNav: () => isUndecoratedNav,
121
+ isUnresolvedCategory: () => isUnresolvedCategory,
120
122
  isUnresolvedRelation: () => isUnresolvedRelation,
121
123
  isValidCollectionDescription: () => isValidCollectionDescription,
122
124
  isValidString: () => isValidString,
@@ -190,6 +192,12 @@ function isUnresolvedRelation(item) {
190
192
  function isRelation(item) {
191
193
  return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
192
194
  }
195
+ function isUnresolvedCategory(category) {
196
+ return category ? typeof category === "string" : false;
197
+ }
198
+ function isUndecoratedCategory(category) {
199
+ return isObject(category) && !category.href;
200
+ }
193
201
  function isUndecoratedMenuItem(item) {
194
202
  return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
195
203
  }
@@ -825,6 +833,80 @@ var JsonService = class {
825
833
  this.items = [...items, item];
826
834
  return item;
827
835
  }
836
+ async updateOne(id, payload, params = {}) {
837
+ let items = await this.getItems();
838
+ params.where = params.where || {};
839
+ params.where.id = params.where.id || { equals: id };
840
+ const whereItems = this.whereItems_(items, params.where);
841
+ if (whereItems.length > 0) {
842
+ const index = items.indexOf(whereItems[0]);
843
+ const item = { ...items[index], payload };
844
+ items = [...items];
845
+ items[index] = item;
846
+ this.items = items;
847
+ return await this.decorateOne_(item, params);
848
+ }
849
+ throw "not found";
850
+ }
851
+ async updateMany(payload, params = {}) {
852
+ params.pagination = false;
853
+ let items = await this.getItems();
854
+ let filteredItems = items;
855
+ if (params.where) {
856
+ filteredItems = this.whereItems_(filteredItems, params.where, params.limit);
857
+ }
858
+ if (params.sort) {
859
+ filteredItems = this.sortCollection_(filteredItems, params.sort);
860
+ }
861
+ if (params.limit && !params.where) {
862
+ filteredItems = this.limitCollection_(filteredItems, params.limit);
863
+ }
864
+ items = [...items];
865
+ filteredItems = filteredItems.map((x) => {
866
+ const index = items.indexOf(x);
867
+ const item = { ...items[index], payload };
868
+ items[index] = item;
869
+ return item;
870
+ });
871
+ this.items = items;
872
+ return await this.decorateMany_(filteredItems, params);
873
+ }
874
+ async deleteOne(id, params = {}) {
875
+ let items = await this.getItems();
876
+ params.where = params.where || {};
877
+ params.where.id = params.where.id || { equals: id };
878
+ const whereItems = this.whereItems_(items, params.where);
879
+ if (whereItems.length > 0) {
880
+ const index = items.indexOf(whereItems[0]);
881
+ if (index !== -1) {
882
+ const item = items[index];
883
+ items = [...items];
884
+ items.splice(index, 1);
885
+ this.items = items;
886
+ return await this.decorateOne_(item, params);
887
+ }
888
+ return void 0;
889
+ }
890
+ return void 0;
891
+ }
892
+ async deleteMany(params = {}) {
893
+ params.pagination = false;
894
+ let items = await this.getItems();
895
+ let filteredItems = items;
896
+ if (params.where) {
897
+ filteredItems = this.whereItems_(filteredItems, params.where, params.limit);
898
+ }
899
+ if (params.sort) {
900
+ filteredItems = this.sortCollection_(filteredItems, params.sort);
901
+ }
902
+ if (params.limit && !params.where) {
903
+ filteredItems = this.limitCollection_(filteredItems, params.limit);
904
+ }
905
+ items = [...items];
906
+ this.items = items.filter((x) => filteredItems.indexOf(x) === -1);
907
+ return await this.decorateMany_(filteredItems, params);
908
+ }
909
+ // !!! old
828
910
  async update(payload) {
829
911
  let items = await this.getItems();
830
912
  const index = items.reduce((p, c, i) => {
@@ -1689,10 +1771,12 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1689
1771
  isReservedCollectionDescription,
1690
1772
  isStage,
1691
1773
  isString,
1774
+ isUndecoratedCategory,
1692
1775
  isUndecoratedMenuCategory,
1693
1776
  isUndecoratedMenuItem,
1694
1777
  isUndecoratedMenuPage,
1695
1778
  isUndecoratedNav,
1779
+ isUnresolvedCategory,
1696
1780
  isUnresolvedRelation,
1697
1781
  isValidCollectionDescription,
1698
1782
  isValidString,
package/dist/index.mjs CHANGED
@@ -37,6 +37,12 @@ function isUnresolvedRelation(item) {
37
37
  function isRelation(item) {
38
38
  return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
39
39
  }
40
+ function isUnresolvedCategory(category) {
41
+ return category ? typeof category === "string" : false;
42
+ }
43
+ function isUndecoratedCategory(category) {
44
+ return isObject(category) && !category.href;
45
+ }
40
46
  function isUndecoratedMenuItem(item) {
41
47
  return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
42
48
  }
@@ -672,6 +678,80 @@ var JsonService = class {
672
678
  this.items = [...items, item];
673
679
  return item;
674
680
  }
681
+ async updateOne(id, payload, params = {}) {
682
+ let items = await this.getItems();
683
+ params.where = params.where || {};
684
+ params.where.id = params.where.id || { equals: id };
685
+ const whereItems = this.whereItems_(items, params.where);
686
+ if (whereItems.length > 0) {
687
+ const index = items.indexOf(whereItems[0]);
688
+ const item = { ...items[index], payload };
689
+ items = [...items];
690
+ items[index] = item;
691
+ this.items = items;
692
+ return await this.decorateOne_(item, params);
693
+ }
694
+ throw "not found";
695
+ }
696
+ async updateMany(payload, params = {}) {
697
+ params.pagination = false;
698
+ let items = await this.getItems();
699
+ let filteredItems = items;
700
+ if (params.where) {
701
+ filteredItems = this.whereItems_(filteredItems, params.where, params.limit);
702
+ }
703
+ if (params.sort) {
704
+ filteredItems = this.sortCollection_(filteredItems, params.sort);
705
+ }
706
+ if (params.limit && !params.where) {
707
+ filteredItems = this.limitCollection_(filteredItems, params.limit);
708
+ }
709
+ items = [...items];
710
+ filteredItems = filteredItems.map((x) => {
711
+ const index = items.indexOf(x);
712
+ const item = { ...items[index], payload };
713
+ items[index] = item;
714
+ return item;
715
+ });
716
+ this.items = items;
717
+ return await this.decorateMany_(filteredItems, params);
718
+ }
719
+ async deleteOne(id, params = {}) {
720
+ let items = await this.getItems();
721
+ params.where = params.where || {};
722
+ params.where.id = params.where.id || { equals: id };
723
+ const whereItems = this.whereItems_(items, params.where);
724
+ if (whereItems.length > 0) {
725
+ const index = items.indexOf(whereItems[0]);
726
+ if (index !== -1) {
727
+ const item = items[index];
728
+ items = [...items];
729
+ items.splice(index, 1);
730
+ this.items = items;
731
+ return await this.decorateOne_(item, params);
732
+ }
733
+ return void 0;
734
+ }
735
+ return void 0;
736
+ }
737
+ async deleteMany(params = {}) {
738
+ params.pagination = false;
739
+ let items = await this.getItems();
740
+ let filteredItems = items;
741
+ if (params.where) {
742
+ filteredItems = this.whereItems_(filteredItems, params.where, params.limit);
743
+ }
744
+ if (params.sort) {
745
+ filteredItems = this.sortCollection_(filteredItems, params.sort);
746
+ }
747
+ if (params.limit && !params.where) {
748
+ filteredItems = this.limitCollection_(filteredItems, params.limit);
749
+ }
750
+ items = [...items];
751
+ this.items = items.filter((x) => filteredItems.indexOf(x) === -1);
752
+ return await this.decorateMany_(filteredItems, params);
753
+ }
754
+ // !!! old
675
755
  async update(payload) {
676
756
  let items = await this.getItems();
677
757
  const index = items.reduce((p, c, i) => {
@@ -1535,10 +1615,12 @@ export {
1535
1615
  isReservedCollectionDescription,
1536
1616
  isStage,
1537
1617
  isString,
1618
+ isUndecoratedCategory,
1538
1619
  isUndecoratedMenuCategory,
1539
1620
  isUndecoratedMenuItem,
1540
1621
  isUndecoratedMenuPage,
1541
1622
  isUndecoratedNav,
1623
+ isUnresolvedCategory,
1542
1624
  isUnresolvedRelation,
1543
1625
  isValidCollectionDescription,
1544
1626
  isValidString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "1.8.10",
3
+ "version": "1.8.12",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",