@websolutespa/bom-core 1.8.11 → 1.8.13
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 +12 -0
- package/dist/index.d.ts +19 -11
- package/dist/index.js +74 -0
- package/dist/index.mjs +74 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -600,28 +600,32 @@ type WhereAndOr = {
|
|
|
600
600
|
};
|
|
601
601
|
type Where = WhereBase & WhereAndOr;
|
|
602
602
|
type QueryParams = {
|
|
603
|
-
|
|
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> = {
|
|
616
616
|
docs: T[];
|
|
617
617
|
} & Pagination;
|
|
618
618
|
type IQuerable<T extends IEntity = IEntity> = {
|
|
619
|
-
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
620
|
-
findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
621
|
-
findPaged<B extends T = T>(params?: QueryParams): Promise<IPagedResult<B>>;
|
|
622
|
-
create<B extends T = T>(payload: Omit<B, 'id'
|
|
623
|
-
|
|
624
|
-
|
|
619
|
+
findOne<B extends T = T>(id: IEquatable, params?: QueryParams, token?: string): Promise<B | undefined>;
|
|
620
|
+
findMany<B extends T = T>(params?: QueryParams, token?: string): Promise<B[]>;
|
|
621
|
+
findPaged<B extends T = T>(params?: QueryParams, token?: string): Promise<IPagedResult<B>>;
|
|
622
|
+
create<B extends T = T>(payload: Omit<B, 'id'>, params?: QueryParams, token?: string): Promise<B>;
|
|
623
|
+
updateOne<B extends T = T>(id: IEquatable, payload: Partial<B>, params?: Omit<QueryParams, 'where'>, token?: string): Promise<B>;
|
|
624
|
+
updateMany<B extends T = T>(payload: Partial<B>, params?: QueryParams, token?: string): Promise<B[]>;
|
|
625
|
+
deleteOne<B extends T = T>(id: IEquatable, params?: Omit<QueryParams, 'where'>, token?: string): Promise<B | undefined>;
|
|
626
|
+
deleteMany<B extends T = T>(params?: QueryParams, token?: string): Promise<B[]>;
|
|
627
|
+
update<B extends T = T>(payload: Partial<B>, params?: QueryParams, token?: string): Promise<B>;
|
|
628
|
+
delete<B extends T = T>(id: IEquatable, token?: string): Promise<B | undefined>;
|
|
625
629
|
};
|
|
626
630
|
type FindParams = {
|
|
627
631
|
where?: {
|
|
@@ -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>;
|
package/dist/index.js
CHANGED
|
@@ -833,6 +833,80 @@ var JsonService = class {
|
|
|
833
833
|
this.items = [...items, item];
|
|
834
834
|
return item;
|
|
835
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
|
|
836
910
|
async update(payload) {
|
|
837
911
|
let items = await this.getItems();
|
|
838
912
|
const index = items.reduce((p, c, i) => {
|
package/dist/index.mjs
CHANGED
|
@@ -678,6 +678,80 @@ var JsonService = class {
|
|
|
678
678
|
this.items = [...items, item];
|
|
679
679
|
return item;
|
|
680
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
|
|
681
755
|
async update(payload) {
|
|
682
756
|
let items = await this.getItems();
|
|
683
757
|
const index = items.reduce((p, c, i) => {
|