@jwork-space/strapi-sdk 1.0.4 → 1.0.6

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/dist/index.d.mts CHANGED
@@ -115,11 +115,11 @@ declare class StrapiSDK<T extends BaseModel> extends BaseAPI<T> {
115
115
  private config;
116
116
  constructor(resource: string, config?: StrapiConfig);
117
117
  exist: (opt: RequestOptions<T>) => Promise<boolean>;
118
- protected getQueryParams(opt?: RequestOptions<T>): AnyObject & {
118
+ protected getQueryParams(opt?: RequestOptions<T>, excludePagination?: boolean): AnyObject & {
119
119
  filters?: AnyObject;
120
120
  };
121
121
  protected normalizeBody(model: T, action: "save" | "update", { multipart, transformModel }: RequestOptions<T>, serializeOptions?: SerializeOptions): AnyObject | FormData;
122
- protected getRequestParams(opt?: RequestOptions<T>): RequestData;
122
+ protected getRequestParams(opt?: RequestOptions<T>, excludePagination?: boolean): RequestData;
123
123
  requestExecutor({ uri, data }: {
124
124
  uri: string;
125
125
  data: RequestData;
@@ -212,6 +212,8 @@ declare class StrapiSDK<T extends BaseModel> extends BaseAPI<T> {
212
212
  findAndUpdate(data: T, optFilter: RequestOptions<T>, optPayload?: RequestOptions<T>, serializeOptionsPayload?: SerializeOptions): Promise<T | undefined>;
213
213
  finOneEntity: (opt?: RequestOptions<T>) => Promise<T | null>;
214
214
  upsert(data: T, opt?: RequestOptions<T>, serializeOptions?: SerializeOptions): Promise<T>;
215
+ invalidateQueries: (keys: (string | unknown[])[]) => () => Promise<void>;
216
+ invalidateListAll: () => () => Promise<void>;
215
217
  }
216
218
 
217
219
  type AnyObject = Record<string, any>;
package/dist/index.d.ts CHANGED
@@ -115,11 +115,11 @@ declare class StrapiSDK<T extends BaseModel> extends BaseAPI<T> {
115
115
  private config;
116
116
  constructor(resource: string, config?: StrapiConfig);
117
117
  exist: (opt: RequestOptions<T>) => Promise<boolean>;
118
- protected getQueryParams(opt?: RequestOptions<T>): AnyObject & {
118
+ protected getQueryParams(opt?: RequestOptions<T>, excludePagination?: boolean): AnyObject & {
119
119
  filters?: AnyObject;
120
120
  };
121
121
  protected normalizeBody(model: T, action: "save" | "update", { multipart, transformModel }: RequestOptions<T>, serializeOptions?: SerializeOptions): AnyObject | FormData;
122
- protected getRequestParams(opt?: RequestOptions<T>): RequestData;
122
+ protected getRequestParams(opt?: RequestOptions<T>, excludePagination?: boolean): RequestData;
123
123
  requestExecutor({ uri, data }: {
124
124
  uri: string;
125
125
  data: RequestData;
@@ -212,6 +212,8 @@ declare class StrapiSDK<T extends BaseModel> extends BaseAPI<T> {
212
212
  findAndUpdate(data: T, optFilter: RequestOptions<T>, optPayload?: RequestOptions<T>, serializeOptionsPayload?: SerializeOptions): Promise<T | undefined>;
213
213
  finOneEntity: (opt?: RequestOptions<T>) => Promise<T | null>;
214
214
  upsert(data: T, opt?: RequestOptions<T>, serializeOptions?: SerializeOptions): Promise<T>;
215
+ invalidateQueries: (keys: (string | unknown[])[]) => () => Promise<void>;
216
+ invalidateListAll: () => () => Promise<void>;
215
217
  }
216
218
 
217
219
  type AnyObject = Record<string, any>;
package/dist/index.js CHANGED
@@ -489,7 +489,8 @@ var StrapiSDK = class extends BaseAPI {
489
489
  this.findById = async (id, opt) => {
490
490
  const uri = `${opt?.url ?? this.endpoint}/${id}`;
491
491
  if (opt) delete opt.sort;
492
- const { data } = opt?.method === "get" ? await this.getCall(uri, this.getRequestParams(opt)) : await this.postCall(uri, this.getRequestParams(opt));
492
+ const parameters = this.getRequestParams(opt, true);
493
+ const { data } = opt?.method === "get" ? await this.getCall(uri, parameters) : await this.postCall(uri, parameters);
493
494
  return data;
494
495
  };
495
496
  this.useListAll = (opt) => {
@@ -705,6 +706,20 @@ var StrapiSDK = class extends BaseAPI {
705
706
  const list = data;
706
707
  return list.length > 0 ? list[0] : null;
707
708
  };
709
+ this.invalidateQueries = (keys) => {
710
+ const queryClient = (0, import_react_query.useQueryClient)();
711
+ return async () => {
712
+ if (!keys || keys.length === 0) return;
713
+ for (const key of keys) {
714
+ await queryClient.invalidateQueries({
715
+ queryKey: Array.isArray(key) ? key : [key]
716
+ });
717
+ }
718
+ };
719
+ };
720
+ this.invalidateListAll = () => {
721
+ return this.invalidateQueries([[this.endpoint, "listAll"]]);
722
+ };
708
723
  this.config = {
709
724
  onCreate: {
710
725
  generateUID: config?.onCreate?.generateUID ?? true,
@@ -719,12 +734,14 @@ var StrapiSDK = class extends BaseAPI {
719
734
  baseURL
720
735
  };
721
736
  }
722
- getQueryParams(opt) {
737
+ getQueryParams(opt, excludePagination = false) {
723
738
  const query = {
724
739
  sort: opt?.sort || "id:asc",
725
- pagination: {
726
- page: opt?.pagination?.page || 1,
727
- pageSize: opt?.pagination?.pageSize || this.config.pageSize
740
+ ...excludePagination ? {} : {
741
+ pagination: {
742
+ page: opt?.pagination?.page || 1,
743
+ pageSize: opt?.pagination?.pageSize || this.config.pageSize
744
+ }
728
745
  }
729
746
  };
730
747
  if (opt?.populate) query.populate = opt.populate;
@@ -741,10 +758,10 @@ var StrapiSDK = class extends BaseAPI {
741
758
  const body = this.serialize(data, serializeOptions);
742
759
  return this.config.wrapBodyInData ? { data: body } : body;
743
760
  }
744
- getRequestParams(opt) {
761
+ getRequestParams(opt, excludePagination = false) {
745
762
  const options = {
746
763
  auth: opt?.auth ?? true,
747
- query: this.getQueryParams(opt)
764
+ query: this.getQueryParams(opt, excludePagination)
748
765
  };
749
766
  return options;
750
767
  }
package/dist/index.mjs CHANGED
@@ -440,7 +440,8 @@ var StrapiSDK = class extends BaseAPI {
440
440
  this.findById = async (id, opt) => {
441
441
  const uri = `${opt?.url ?? this.endpoint}/${id}`;
442
442
  if (opt) delete opt.sort;
443
- const { data } = opt?.method === "get" ? await this.getCall(uri, this.getRequestParams(opt)) : await this.postCall(uri, this.getRequestParams(opt));
443
+ const parameters = this.getRequestParams(opt, true);
444
+ const { data } = opt?.method === "get" ? await this.getCall(uri, parameters) : await this.postCall(uri, parameters);
444
445
  return data;
445
446
  };
446
447
  this.useListAll = (opt) => {
@@ -656,6 +657,20 @@ var StrapiSDK = class extends BaseAPI {
656
657
  const list = data;
657
658
  return list.length > 0 ? list[0] : null;
658
659
  };
660
+ this.invalidateQueries = (keys) => {
661
+ const queryClient = useQueryClient();
662
+ return async () => {
663
+ if (!keys || keys.length === 0) return;
664
+ for (const key of keys) {
665
+ await queryClient.invalidateQueries({
666
+ queryKey: Array.isArray(key) ? key : [key]
667
+ });
668
+ }
669
+ };
670
+ };
671
+ this.invalidateListAll = () => {
672
+ return this.invalidateQueries([[this.endpoint, "listAll"]]);
673
+ };
659
674
  this.config = {
660
675
  onCreate: {
661
676
  generateUID: config?.onCreate?.generateUID ?? true,
@@ -670,12 +685,14 @@ var StrapiSDK = class extends BaseAPI {
670
685
  baseURL
671
686
  };
672
687
  }
673
- getQueryParams(opt) {
688
+ getQueryParams(opt, excludePagination = false) {
674
689
  const query = {
675
690
  sort: opt?.sort || "id:asc",
676
- pagination: {
677
- page: opt?.pagination?.page || 1,
678
- pageSize: opt?.pagination?.pageSize || this.config.pageSize
691
+ ...excludePagination ? {} : {
692
+ pagination: {
693
+ page: opt?.pagination?.page || 1,
694
+ pageSize: opt?.pagination?.pageSize || this.config.pageSize
695
+ }
679
696
  }
680
697
  };
681
698
  if (opt?.populate) query.populate = opt.populate;
@@ -692,10 +709,10 @@ var StrapiSDK = class extends BaseAPI {
692
709
  const body = this.serialize(data, serializeOptions);
693
710
  return this.config.wrapBodyInData ? { data: body } : body;
694
711
  }
695
- getRequestParams(opt) {
712
+ getRequestParams(opt, excludePagination = false) {
696
713
  const options = {
697
714
  auth: opt?.auth ?? true,
698
- query: this.getQueryParams(opt)
715
+ query: this.getQueryParams(opt, excludePagination)
699
716
  };
700
717
  return options;
701
718
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jwork-space/strapi-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "SDK para Strapi con soporte para React Query y TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",