@zthun/webigail-rest 3.1.1 → 3.1.3
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/LICENSE +13 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/LICENSE
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Anthony Bonta
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
11
|
|
|
12
12
|
The above copyright notice and this permission notice shall be included in all
|
|
13
13
|
copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
SOFTWARE.
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/service/restful-service.mts"],"sourcesContent":["import {\n IZDataRequest,\n IZDataSource,\n ZFilterSerialize,\n ZSortSerialize,\n} from \"@zthun/helpful-query\";\nimport { IZHttpService, ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { IZRestfulCreate } from \"./restful-create.mjs\";\nimport { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport { IZRestfulGet } from \"./restful-get.mjs\";\nimport { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const url = this.endpoint()\n .page(1)\n .size(1)\n .search(req.search)\n .filter(filter)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const sort = new ZSortSerialize().serialize(req.sort);\n const url = this.endpoint()\n .page(req.page)\n .size(req.size)\n .search(req.search)\n .filter(filter)\n .sort(sort)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":["ZHttpRequestBuilder","ZUrlBuilder","ZFilterSerialize","ZSortSerialize"],"mappings":";;;;;AAuCO,MAAM,gBAAkD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAetD,YACY,OACA,cACA,WAAW,IAAIA,aAAuB,oBAAA,EAAE,SACzD;AAHiB,SAAA,QAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/service/restful-service.mts"],"sourcesContent":["import {\n IZDataRequest,\n IZDataSource,\n ZFilterSerialize,\n ZSortSerialize,\n} from \"@zthun/helpful-query\";\nimport { IZHttpService, ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { IZRestfulCreate } from \"./restful-create.mjs\";\nimport { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport { IZRestfulGet } from \"./restful-get.mjs\";\nimport { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const url = this.endpoint()\n .page(1)\n .size(1)\n .search(req.search)\n .filter(filter)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const sort = new ZSortSerialize().serialize(req.sort);\n const url = this.endpoint()\n .page(req.page)\n .size(req.size)\n .search(req.search)\n .filter(filter)\n .sort(sort)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":["ZHttpRequestBuilder","ZUrlBuilder","ZFilterSerialize","ZSortSerialize"],"mappings":";;;;;AAuCO,MAAM,gBAAkD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAetD,YACY,OACA,cACA,WAAW,IAAIA,aAAuB,oBAAA,EAAE,SACzD;AAHiB,SAAA,QAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaZ,SAAS,gBAAkC;AAChD,UAAM,MAAM,IAAIC,YAAA,YAAA,EAAc,MAAM,KAAK,YAAY;AACrD,WAAO,iBAAiB,IAAI,OAAO,GAAG,cAAc,EAAE,IAAI;AAAA,EAAA;AAAA,EAG5D,MAAa,MAAM,KAAqC;AACtD,UAAM,SAAS,IAAIC,aAAA,iBAAA,EAAmB,UAAU,IAAI,MAAM;AAC1D,UAAM,MAAM,KAAK,SACd,EAAA,KAAK,CAAC,EACN,KAAK,CAAC,EACN,OAAO,IAAI,MAAM,EAC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AACvC,WAAA;AAAA,EAAA;AAAA,EAGT,MAAa,OAAO,MAAqB;AACvC,UAAM,MAAM,KAAK,SAAS,EAAE,MAAM;AAClC,UAAM,IAAI,IAAIA,aAAAA,sBACX,KAAK,KAAK,QAAQ,EAClB,IAAI,IAAI,EACR,IAAI,GAAG,EACP,MAAM;AACT,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,MAAM,QAAW,CAAC;AACvC,WAAA;AAAA,EAAA;AAAA,EAGT,MAAa,OACX,gBACA,QACY;AACZ,UAAM,MAAM,KAAK,SAAS,cAAc,EAAE,MAAM;AAChD,UAAM,IAAI,IAAIA,aAAAA,sBACX,KAAK,KAAK,QAAQ,EAClB,MAAM,MAAM,EACZ,IAAI,GAAG,EACP,MAAM;AACT,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,MAAM,QAAW,CAAC;AACvC,WAAA;AAAA,EAAA;AAAA,EAGT,MAAa,OAAO,gBAAgD;AAClE,UAAM,MAAM,KAAK,SAAS,cAAc,EAAE,MAAM;AAChD,UAAM,IAAI,IAAIA,iCAA+B,EAC1C,KAAK,KAAK,QAAQ,EAClB,OAAO,EACP,IAAI,GAAG,EACP,MAAM;AACH,UAAA,KAAK,MAAM,QAAQ,CAAC;AAAA,EAAA;AAE9B;;"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/service/restful-service.mts"],"sourcesContent":["import {\n IZDataRequest,\n IZDataSource,\n ZFilterSerialize,\n ZSortSerialize,\n} from \"@zthun/helpful-query\";\nimport { IZHttpService, ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { IZRestfulCreate } from \"./restful-create.mjs\";\nimport { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport { IZRestfulGet } from \"./restful-get.mjs\";\nimport { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const url = this.endpoint()\n .page(1)\n .size(1)\n .search(req.search)\n .filter(filter)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const sort = new ZSortSerialize().serialize(req.sort);\n const url = this.endpoint()\n .page(req.page)\n .size(req.size)\n .search(req.search)\n .filter(filter)\n .sort(sort)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":[],"mappings":";;;AAuCO,MAAM,gBAAkD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAetD,YACY,OACA,cACA,WAAW,IAAI,oBAAuB,EAAE,SACzD;AAHiB,SAAA,QAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/service/restful-service.mts"],"sourcesContent":["import {\n IZDataRequest,\n IZDataSource,\n ZFilterSerialize,\n ZSortSerialize,\n} from \"@zthun/helpful-query\";\nimport { IZHttpService, ZHttpRequestBuilder } from \"@zthun/webigail-http\";\nimport { ZUrlBuilder } from \"@zthun/webigail-url\";\nimport { IZRestfulCreate } from \"./restful-create.mjs\";\nimport { IZRestfulDelete } from \"./restful-delete.mjs\";\nimport { IZRestfulGet } from \"./restful-get.mjs\";\nimport { IZRestfulUpdate } from \"./restful-update.mjs\";\nimport { IZRestfulUpsert } from \"./restful-upsert.mjs\";\n\n/**\n * A service that conforms to all known restful standards.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport interface IZRestfulService<T>\n extends IZRestfulCreate<T>,\n IZRestfulDelete,\n IZRestfulGet<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpdate<T>,\n IZRestfulUpsert<T>,\n IZDataSource<T> {}\n\n/**\n * A generic implementation of a restful service that assumes all verbs are implemented.\n *\n * This can be used to invoke a service that is only partially implemented. If your service,\n * for example, is read only, then create, upsert, update, and delete should all return\n * not found or forbidden errors.\n *\n * @param T -\n * The type of resource being retrieved or mutated.\n */\nexport class ZRestfulService<T> implements IZRestfulService<T> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _http -\n * The http service to use when invoking the RESTful service.\n * @param _endpointUrl -\n * The root url of the endpoint to hit. This can include params\n * to send them with every request, but standard params of page,\n * size, search, filter, and sort will be overridden depending on\n * which method is being invoked.\n * @param _request -\n * The base request to use when constructing requests in the http\n * service.\n */\n public constructor(\n private readonly _http: IZHttpService,\n private readonly _endpointUrl: string,\n private readonly _request = new ZHttpRequestBuilder<T>().build(),\n ) {}\n\n /**\n * Gets the final endpoint for a resource.\n *\n * @param identification -\n * The identification of a single resource. If this is falsy, then\n * the entire data scope is used.\n *\n * @returns\n * A url builder that points to the target resource endpoint.\n */\n public endpoint(identification?: number | string) {\n const url = new ZUrlBuilder().parse(this._endpointUrl);\n return identification ? url.append(`${identification}`) : url;\n }\n\n public async count(req: IZDataRequest): Promise<number> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const url = this.endpoint()\n .page(1)\n .size(1)\n .search(req.search)\n .filter(filter)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.count;\n }\n\n public async retrieve(req: IZDataRequest): Promise<T[]> {\n const filter = new ZFilterSerialize().serialize(req.filter);\n const sort = new ZSortSerialize().serialize(req.sort);\n const url = this.endpoint()\n .page(req.page)\n .size(req.size)\n .search(req.search)\n .filter(filter)\n .sort(sort)\n .build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data: page } = await this._http.request<any>(r);\n return page.data ?? page.result;\n }\n\n public async get(identification: number | string): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder()\n .copy(this._request)\n .get()\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async create(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .post(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async upsert(body: T): Promise<T> {\n const url = this.endpoint().build();\n const r = new ZHttpRequestBuilder<T>()\n .copy(this._request)\n .put(body)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(\n identification: number | string,\n fields: Partial<T>,\n ): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>()\n .copy(this._request)\n .patch(fields)\n .url(url)\n .build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async delete(identification: number | string): Promise<void> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<undefined>()\n .copy(this._request)\n .delete()\n .url(url)\n .build();\n await this._http.request(r);\n }\n}\n"],"names":[],"mappings":";;;AAuCO,MAAM,gBAAkD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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Q,CAAC;AAAA,EAAA;AAE9B;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/webigail-rest",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "Helpful services for querying rest services based on specific standards.",
|
|
5
5
|
"author": "Anthony Bonta",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,21 +9,27 @@
|
|
|
9
9
|
"url": "https://github.com/zthun/webigail",
|
|
10
10
|
"directory": "packages/webigail-rest"
|
|
11
11
|
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
12
14
|
"main": "./dist/index.cjs",
|
|
13
15
|
"module": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
16
|
"exports": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
16
18
|
"import": "./dist/index.js",
|
|
17
|
-
"require": "./dist/index.cjs"
|
|
18
|
-
"types": "./dist/index.d.ts"
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
19
20
|
},
|
|
20
|
-
"type": "module",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "vite build"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@zthun/helpful-fn": "^7.0.5",
|
|
29
|
+
"@zthun/helpful-query": "^7.0.5",
|
|
30
|
+
"@zthun/webigail-http": "^3.1.3",
|
|
31
|
+
"@zthun/webigail-url": "^3.1.3"
|
|
32
|
+
},
|
|
27
33
|
"devDependencies": {
|
|
28
34
|
"vite": "^5.4.11",
|
|
29
35
|
"vitest": "^2.1.8"
|
|
@@ -31,12 +37,6 @@
|
|
|
31
37
|
"files": [
|
|
32
38
|
"dist"
|
|
33
39
|
],
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@zthun/helpful-fn": "^6.7.0",
|
|
36
|
-
"@zthun/helpful-query": "^6.7.0",
|
|
37
|
-
"@zthun/webigail-http": "^3.1.1",
|
|
38
|
-
"@zthun/webigail-url": "^3.0.2"
|
|
39
|
-
},
|
|
40
40
|
"sideEffects": false,
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "129b0ed33ea50260b12246d48a9e9f177f072308"
|
|
42
42
|
}
|