@zthun/webigail-rest 2.1.0 → 2.2.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/service/restful-service.mts"],"sourcesContent":["import { IZDataRequest, IZDataSource } from '@zthun/helpful-query';\nimport { IZHttpService, ZHttpRequestBuilder } from '@zthun/webigail-http';\nimport { ZUrlBuilder } from '@zthun/webigail-url';\n\n/**\n * A service that conforms to restful standards.\n */\nexport interface IZRestfulService<T> extends IZDataSource<T> {\n /**\n * Retrieves a single item by it's identification.\n *\n * This uses a GET verb.\n *\n * @param identification -\n * The identification of the resource to retrieve.\n *\n * @returns\n * The json representation of the entity.\n */\n get(identification: number | string): Promise<T>;\n\n /**\n * Creates a new entity.\n *\n * This uses a POST verb.\n *\n * @param body -\n * The post body that represents the resource to create.\n *\n * @returns\n * The resource that was created.\n */\n create(body: T): Promise<T>;\n\n /**\n * Creates a new entity or updates an existing entity.\n *\n * This is determined by the body parameters on whether\n * or not an entity already exists.\n *\n * This uses the PUT verb.\n *\n * @param body -\n * The post body that represents the resource to create\n * or update.\n *\n * @returns\n * The resource that was created or updated.\n */\n upsert(body: T): Promise<T>;\n\n /**\n * Partially updates an existing resource entity.\n *\n * This uses the PATCH verb.\n *\n * @param identification -\n * The identification of the resource to update.\n * @param fields -\n * The partial fields to update.\n *\n * @returns\n * The resource that was updated.\n */\n update(identification: string, fields: Partial<T>): Promise<T>;\n\n /**\n * Deletes a resource entity.\n *\n * This uses the DELETE verb.\n *\n * @param identification -\n * The identification of the resource to delete.\n */\n delete(identification: string): Promise<void>;\n}\n\n/**\n * A factory for constructing basic http request builders.\n *\n * This is used to create a common construction for http requests\n * that contain common options like headers and timeouts.\n */\nexport type ZHttpRequestFactory = () => ZHttpRequestBuilder;\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 */\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 url = this.endpoint().page(1).size(1).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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 url = this.endpoint().page(req.page).size(req.size).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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().copy(this._request).get().url(url).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>().copy(this._request).post(body).url(url).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>().copy(this._request).put(body).url(url).build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(identification: number | string, fields: Partial<T>): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>().copy(this._request).patch(fields).url(url).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>().copy(this._request).delete().url(url).build();\n await this._http.request(r);\n }\n}\n"],"names":["ZHttpRequestBuilder","ZUrlBuilder"],"mappings":";;;;AA4FO,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,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYI,SAAS,gBAAkC;AAChD,UAAM,MAAM,IAAIC,YAAA,YAAA,EAAc,MAAM,KAAK,YAAY;AACrD,WAAO,iBAAiB,IAAI,OAAO,GAAG,cAAc,EAAE,IAAI;AAAA,EAC5D;AAAA,EAEA,MAAa,MAAM,KAAqC;AACtD,UAAM,MAAM,KAAK,SAAS,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM;AACrE,UAAM,IAAI,IAAID,aAAAA,sBAAsB,KAAK,KAAK,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,MAAM;AACvE,UAAA,EAAE,MAAM,SAAS,MAAM,KAAK,MAAM,QAAa,CAAC;AACtD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,SAAS,KAAkC;AACtD,UAAM,MAAM,KAAK,SAAW,EAAA,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,OAAO,IAAI,MAAM,EAAE;AAC7E,UAAM,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IAAI,MAAM,KAAK,MAAM,QAAW,CAAC;AACvC,WAAA;AAAA,EACT;AAAA,EAEA,MAAa,OAAO,gBAAgD;AAClE,UAAM,MAAM,KAAK,SAAS,cAAc,EAAE,MAAM;AAChD,UAAM,IAAI,IAAIA,aAAAA,sBAAiC,KAAK,KAAK,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,MAAM;AACrF,UAAA,KAAK,MAAM,QAAQ,CAAC;AAAA,EAC5B;AACF;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/service/restful-service.mts"],"sourcesContent":["import { IZDataRequest, IZDataSource } 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 url = this.endpoint().page(1).size(1).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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 url = this.endpoint().page(req.page).size(req.size).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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().copy(this._request).get().url(url).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>().copy(this._request).post(body).url(url).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>().copy(this._request).put(body).url(url).build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(identification: number | string, fields: Partial<T>): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>().copy(this._request).patch(fields).url(url).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>().copy(this._request).delete().url(url).build();\n await this._http.request(r);\n }\n}\n"],"names":["ZHttpR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AQ,CAAC;AAAA,EAC5B;AACF;;"}
package/dist/index.d.ts CHANGED
@@ -1 +1,6 @@
1
+ export * from './service/restful-create.mjs';
2
+ export * from './service/restful-delete.mjs';
3
+ export * from './service/restful-get.mjs';
1
4
  export * from './service/restful-service.mjs';
5
+ export * from './service/restful-update.mjs';
6
+ export * from './service/restful-upsert.mjs';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/service/restful-service.mts"],"sourcesContent":["import { IZDataRequest, IZDataSource } from '@zthun/helpful-query';\nimport { IZHttpService, ZHttpRequestBuilder } from '@zthun/webigail-http';\nimport { ZUrlBuilder } from '@zthun/webigail-url';\n\n/**\n * A service that conforms to restful standards.\n */\nexport interface IZRestfulService<T> extends IZDataSource<T> {\n /**\n * Retrieves a single item by it's identification.\n *\n * This uses a GET verb.\n *\n * @param identification -\n * The identification of the resource to retrieve.\n *\n * @returns\n * The json representation of the entity.\n */\n get(identification: number | string): Promise<T>;\n\n /**\n * Creates a new entity.\n *\n * This uses a POST verb.\n *\n * @param body -\n * The post body that represents the resource to create.\n *\n * @returns\n * The resource that was created.\n */\n create(body: T): Promise<T>;\n\n /**\n * Creates a new entity or updates an existing entity.\n *\n * This is determined by the body parameters on whether\n * or not an entity already exists.\n *\n * This uses the PUT verb.\n *\n * @param body -\n * The post body that represents the resource to create\n * or update.\n *\n * @returns\n * The resource that was created or updated.\n */\n upsert(body: T): Promise<T>;\n\n /**\n * Partially updates an existing resource entity.\n *\n * This uses the PATCH verb.\n *\n * @param identification -\n * The identification of the resource to update.\n * @param fields -\n * The partial fields to update.\n *\n * @returns\n * The resource that was updated.\n */\n update(identification: string, fields: Partial<T>): Promise<T>;\n\n /**\n * Deletes a resource entity.\n *\n * This uses the DELETE verb.\n *\n * @param identification -\n * The identification of the resource to delete.\n */\n delete(identification: string): Promise<void>;\n}\n\n/**\n * A factory for constructing basic http request builders.\n *\n * This is used to create a common construction for http requests\n * that contain common options like headers and timeouts.\n */\nexport type ZHttpRequestFactory = () => ZHttpRequestBuilder;\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 */\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 url = this.endpoint().page(1).size(1).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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 url = this.endpoint().page(req.page).size(req.size).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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().copy(this._request).get().url(url).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>().copy(this._request).post(body).url(url).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>().copy(this._request).put(body).url(url).build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(identification: number | string, fields: Partial<T>): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>().copy(this._request).patch(fields).url(url).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>().copy(this._request).delete().url(url).build();\n await this._http.request(r);\n }\n}\n"],"names":[],"mappings":";;AA4FO,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,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYI,SAAS,gBAAkC;AAChD,UAAM,MAAM,IAAI,YAAA,EAAc,MAAM,KAAK,YAAY;AACrD,WAAO,iBAAiB,IAAI,OAAO,GAAG,cAAc,EAAE,IAAI;AAAA,EAC5D;AAAA,EAEA,MAAa,MAAM,KAAqC;AACtD,UAAM,MAAM,KAAK,SAAS,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM;AACrE,UAAM,IAAI,IAAI,sBAAsB,KAAK,KAAK,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,MAAM;AACvE,UAAA,EAAE,MAAM,SAAS,MAAM,KAAK,MAAM,QAAa,CAAC;AACtD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,SAAS,KAAkC;AACtD,UAAM,MAAM,KAAK,SAAW,EAAA,KAAK,IAAI,IA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AAM;AACjG,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,MAAM,QAAW,CAAC;AACvC,WAAA;AAAA,EACT;AAAA,EAEA,MAAa,OAAO,gBAAgD;AAClE,UAAM,MAAM,KAAK,SAAS,cAAc,EAAE,MAAM;AAChD,UAAM,IAAI,IAAI,sBAAiC,KAAK,KAAK,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,MAAM;AACrF,UAAA,KAAK,MAAM,QAAQ,CAAC;AAAA,EAC5B;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../src/service/restful-service.mts"],"sourcesContent":["import { IZDataRequest, IZDataSource } 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 url = this.endpoint().page(1).size(1).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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 url = this.endpoint().page(req.page).size(req.size).search(req.search).build();\n const r = new ZHttpRequestBuilder().copy(this._request).get().url(url).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().copy(this._request).get().url(url).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>().copy(this._request).post(body).url(url).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>().copy(this._request).put(body).url(url).build();\n const { data } = await this._http.request<T>(r);\n return data;\n }\n\n public async update(identification: number | string, fields: Partial<T>): Promise<T> {\n const url = this.endpoint(identification).build();\n const r = new ZHttpRequestBuilder<Partial<T>>().copy(this._request).patch(fields).url(url).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>().copy(this._request).delete().url(url).build();\n await this._http.request(r);\n }\n}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: T): Promise<T>;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface IZRestfulDelete {
2
+ delete(identification: string): Promise<void>;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface IZRestfulGet<T> {
2
+ get(identification: number | string): Promise<T>;
3
+ }
@@ -1,14 +1,13 @@
1
1
  import { IZDataRequest, IZDataSource } from '@zthun/helpful-query';
2
- import { IZHttpService, ZHttpRequestBuilder } from '@zthun/webigail-http';
2
+ import { IZHttpService } from '@zthun/webigail-http';
3
3
  import { ZUrlBuilder } from '@zthun/webigail-url';
4
- export interface IZRestfulService<T> extends IZDataSource<T> {
5
- get(identification: number | string): Promise<T>;
6
- create(body: T): Promise<T>;
7
- upsert(body: T): Promise<T>;
8
- update(identification: string, fields: Partial<T>): Promise<T>;
9
- delete(identification: string): Promise<void>;
4
+ import { IZRestfulCreate } from './restful-create.mjs';
5
+ import { IZRestfulDelete } from './restful-delete.mjs';
6
+ import { IZRestfulGet } from './restful-get.mjs';
7
+ import { IZRestfulUpdate } from './restful-update.mjs';
8
+ import { IZRestfulUpsert } from './restful-upsert.mjs';
9
+ export interface IZRestfulService<T> extends IZRestfulCreate<T>, IZRestfulDelete, IZRestfulGet<T>, IZRestfulUpdate<T>, IZRestfulUpdate<T>, IZRestfulUpsert<T>, IZDataSource<T> {
10
10
  }
11
- export type ZHttpRequestFactory = () => ZHttpRequestBuilder;
12
11
  export declare class ZRestfulService<T> implements IZRestfulService<T> {
13
12
  private readonly _http;
14
13
  private readonly _endpointUrl;
@@ -0,0 +1,3 @@
1
+ export interface IZRestfulUpdate<T> {
2
+ update(identification: string, fields: Partial<T>): Promise<T>;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface IZRestfulUpsert<T> {
2
+ upsert(body: T): Promise<T>;
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/webigail-rest",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Helpful services for querying rest services based on specific standards.",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -34,9 +34,9 @@
34
34
  "dependencies": {
35
35
  "@zthun/helpful-fn": "^3.2.0",
36
36
  "@zthun/helpful-query": "^3.2.0",
37
- "@zthun/webigail-http": "^2.1.0",
38
- "@zthun/webigail-url": "^2.1.0"
37
+ "@zthun/webigail-http": "^2.2.0",
38
+ "@zthun/webigail-url": "^2.1.1"
39
39
  },
40
40
  "sideEffects": false,
41
- "gitHead": "a013c6401a9b2cca4bfc113987c09d3f2f23ed44"
41
+ "gitHead": "b17031c94ee5585b87d7460fbb90b7b00e4fc87b"
42
42
  }