@unshared/client 0.2.3 → 0.3.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.
- package/dist/HttpHeaders.cjs +4 -0
- package/dist/HttpHeaders.cjs.map +1 -0
- package/dist/{chunks/8BFCFxqa.d.ts → HttpHeaders.d.ts} +1 -1
- package/dist/HttpHeaders.js +5 -0
- package/dist/HttpHeaders.js.map +1 -0
- package/dist/HttpMethods.cjs +4 -0
- package/dist/HttpMethods.cjs.map +1 -0
- package/dist/{chunks/DZp6zyqV.d.ts → HttpMethods.d.ts} +1 -98
- package/dist/HttpMethods.js +5 -0
- package/dist/HttpMethods.js.map +1 -0
- package/dist/HttpStatusCodes.cjs +4 -0
- package/dist/HttpStatusCodes.cjs.map +1 -0
- package/dist/HttpStatusCodes.d.ts +615 -0
- package/dist/HttpStatusCodes.js +5 -0
- package/dist/HttpStatusCodes.js.map +1 -0
- package/dist/chunks/B92aAMq0.d.ts +144 -0
- package/dist/chunks/{D-WqCFul.js → Biic1J5b.js} +11 -9
- package/dist/chunks/Biic1J5b.js.map +1 -0
- package/dist/chunks/CfKxYeRr.cjs +155 -0
- package/dist/chunks/CfKxYeRr.cjs.map +1 -0
- package/dist/chunks/CjU0376e.d.ts +229 -0
- package/dist/chunks/{xRZPkxch.cjs → CtW2aMuA.cjs} +11 -9
- package/dist/chunks/CtW2aMuA.cjs.map +1 -0
- package/dist/chunks/D51s1VII.js +156 -0
- package/dist/chunks/D51s1VII.js.map +1 -0
- package/dist/chunks/iA98-4f5.cjs +8 -0
- package/dist/chunks/iA98-4f5.cjs.map +1 -0
- package/dist/chunks/lMH6B5BV.js +9 -0
- package/dist/chunks/lMH6B5BV.js.map +1 -0
- package/dist/createClient.cjs +81 -18
- package/dist/createClient.cjs.map +1 -1
- package/dist/createClient.d.ts +93 -29
- package/dist/createClient.js +83 -20
- package/dist/createClient.js.map +1 -1
- package/dist/createService.cjs +17 -0
- package/dist/createService.cjs.map +1 -0
- package/dist/createService.d.ts +38 -0
- package/dist/createService.js +19 -0
- package/dist/createService.js.map +1 -0
- package/dist/index.cjs +22 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -624
- package/dist/index.js +24 -19
- package/dist/index.js.map +1 -1
- package/dist/openapi.cjs +3 -15
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.d.ts +7 -35
- package/dist/openapi.js +3 -15
- package/dist/openapi.js.map +1 -1
- package/dist/utils.cjs +13 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +57 -27
- package/dist/utils.js +11 -9
- package/package.json +23 -8
- package/dist/chunks/B2OrSen1.d.ts +0 -185
- package/dist/chunks/B5hc73Po.js +0 -96
- package/dist/chunks/B5hc73Po.js.map +0 -1
- package/dist/chunks/CKfJvIQ8.js +0 -50
- package/dist/chunks/CKfJvIQ8.js.map +0 -1
- package/dist/chunks/Cx8m1YzL.cjs +0 -49
- package/dist/chunks/Cx8m1YzL.cjs.map +0 -1
- package/dist/chunks/D-WqCFul.js.map +0 -1
- package/dist/chunks/D8Tsm7xC.cjs +0 -95
- package/dist/chunks/D8Tsm7xC.cjs.map +0 -1
- package/dist/chunks/r8pYO6Hx.d.ts +0 -38
- package/dist/chunks/xRZPkxch.cjs.map +0 -1
- package/dist/fetch.cjs +0 -8
- package/dist/fetch.cjs.map +0 -1
- package/dist/fetch.d.ts +0 -16
- package/dist/fetch.js +0 -9
- package/dist/fetch.js.map +0 -1
@@ -1,38 +0,0 @@
|
|
1
|
-
interface RequestHooks {
|
2
|
-
/**
|
3
|
-
* The callback that is called when an error occurs during the request.
|
4
|
-
*/
|
5
|
-
onError?: (error: Error) => any;
|
6
|
-
/**
|
7
|
-
* The callback that is called when data is received from the request. This callback
|
8
|
-
* will be called for each chunk of data that is received from the request.
|
9
|
-
*/
|
10
|
-
onData?: (data: unknown) => any;
|
11
|
-
/**
|
12
|
-
* The callback that is called when the request is successful. This callback will be
|
13
|
-
* called after the request is complete and all data has been received.
|
14
|
-
*/
|
15
|
-
onSuccess?: (response: Response) => any;
|
16
|
-
/**
|
17
|
-
* The callback that is called when the status code is not OK. This callback will be called
|
18
|
-
* after the request is complete and before the data is consumed.
|
19
|
-
*/
|
20
|
-
onFailure?: (response: Response) => any;
|
21
|
-
/**
|
22
|
-
* The callback that is called when the request is complete. This callback will be called
|
23
|
-
* after the request is complete and all data has been received.
|
24
|
-
*/
|
25
|
-
onEnd?: (response: Response) => any;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Handle a request response. This function will parse the response based on the content type and
|
29
|
-
* return the data. If an error occurs, the `onError` callback will be called and the function will
|
30
|
-
* throw an error.
|
31
|
-
*
|
32
|
-
* @param response The response to handle.
|
33
|
-
* @param options The options to pass to the request.
|
34
|
-
* @returns The parsed data from the response.
|
35
|
-
*/
|
36
|
-
declare function handleResponse(response: Response, options: RequestHooks): Promise<unknown>;
|
37
|
-
|
38
|
-
export { type RequestHooks as R, handleResponse as h };
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"xRZPkxch.cjs","sources":["../../openapi/getBaseUrl.ts","../../openapi/getOperationById.ts"],"sourcesContent":["import type { OpenAPI } from 'openapi-types'\n\n/**\n * Given an OpenAPI specification, get the first base URL.\n *\n * @param specification The OpenAPI specification.\n * @returns The first base URL.\n * @example getBaseUrl(specification) // 'https://api.example.com/v1'\n */\nexport function getBaseUrl(specification: OpenAPI.Document): string {\n\n // --- Handle OpenAPI 3.0 specifications.\n if ('servers' in specification && Array.isArray(specification.servers) && specification.servers.length > 0)\n return specification.servers[0].url\n\n // --- Handle OpenAPI 2.0 specifications.\n if ('host' in specification && typeof specification.host === 'string') {\n const scheme = specification.schemes && specification.schemes.length > 0 ? specification.schemes[0] : 'https'\n const basePath = specification.basePath && typeof specification.basePath === 'string' ? specification.basePath : '/'\n return `${scheme}://${specification.host}${basePath}`\n }\n\n throw new Error('No base URL found in the OpenAPI specification.')\n}\n","import type { OpenAPI } from 'openapi-types'\nimport type { OpenAPIV2 } from './OpenApiV2'\n\n/** The HTTP methods supported by OpenAPI. */\nconst methods = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch'] as const\n\n/**\n * Given an OpenAPI specification, find an operation by its operationId.\n *\n * @param specification The OpenAPI specification.\n * @param operationId The operationId of the operation to resolve.\n * @returns The resolved operation.\n * @example openapiGetOperation(specification, 'getUser') // { method: 'get', path: '/users/{username}', ... }\n */\nexport function getOperationById<T, U extends OpenAPIV2.OperationId<T>>(\n specification: T,\n operationId: U,\n): OpenAPIV2.OperationById<T, U> {\n\n // --- Validate the specification.\n if (!specification\n || typeof specification !== 'object'\n || specification === null\n || 'paths' in specification === false\n || typeof specification.paths !== 'object'\n || specification.paths === null)\n throw new Error('Missing paths object in the OpenAPI specification.')\n\n // --- Search for the operation in the specification's paths.\n const paths = specification.paths as OpenAPI.Document['paths']\n for (const path in paths) {\n const route = paths[path]\n if (typeof route !== 'object' || route === null) continue\n\n // --- Search in each method for the operation.\n for (const method of methods) {\n const operation = route[method]\n if (method in route === false\n || typeof operation !== 'object'\n || operation === null\n || 'operationId' in operation === false\n || operation.operationId !== operationId) continue\n\n // --- Route was found, return the operation.\n return { ...route[method], method, path } as OpenAPIV2.OperationById<T, U>\n }\n }\n\n // --- Throw an error if the operation was not found.\n throw new Error(`Operation \"${operationId}\" not found in specification.`)\n}\n"],"names":[],"mappings":";AASO,SAAS,WAAW,eAAyC;AAG9D,MAAA,aAAa,iBAAiB,MAAM,QAAQ,cAAc,OAAO,KAAK,cAAc,QAAQ,SAAS;AAChG,WAAA,cAAc,QAAQ,CAAC,EAAE;AAGlC,MAAI,UAAU,iBAAiB,OAAO,cAAc,QAAS,UAAU;AAC/D,UAAA,SAAS,cAAc,WAAW,cAAc,QAAQ,SAAS,IAAI,cAAc,QAAQ,CAAC,IAAI,SAChG,WAAW,cAAc,YAAY,OAAO,cAAc,YAAa,WAAW,cAAc,WAAW;AACjH,WAAO,GAAG,MAAM,MAAM,cAAc,IAAI,GAAG,QAAQ;AAAA,EAAA;AAG/C,QAAA,IAAI,MAAM,iDAAiD;AACnE;ACnBA,MAAM,UAAU,CAAC,OAAO,OAAO,QAAQ,UAAU,WAAW,QAAQ,OAAO;AAU3D,SAAA,iBACd,eACA,aAC+B;AAG/B,MAAI,CAAC,iBACA,OAAO,iBAAkB,YACzB,kBAAkB,QAClB,EAAW,WAAA,kBACX,OAAO,cAAc,SAAU,YAC/B,cAAc,UAAU;AACrB,UAAA,IAAI,MAAM,oDAAoD;AAGtE,QAAM,QAAQ,cAAc;AAC5B,aAAW,QAAQ,OAAO;AAClB,UAAA,QAAQ,MAAM,IAAI;AACpB,QAAA,EAAA,OAAO,SAAU,YAAY,UAAU;AAG3C,iBAAW,UAAU,SAAS;AACtB,cAAA,YAAY,MAAM,MAAM;AAC1B,YAAA,EAAA,EAAA,UAAU,UACT,OAAO,aAAc,YACrB,cAAc,QACd,EAAA,iBAAiB,cACjB,UAAU,gBAAgB;AAG/B,iBAAO,EAAE,GAAG,MAAM,MAAM,GAAG,QAAQ,KAAK;AAAA,MAAA;AAAA,EAC1C;AAIF,QAAM,IAAI,MAAM,cAAc,WAAW,+BAA+B;AAC1E;;;"}
|
package/dist/fetch.cjs
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var parseRequest = require("./chunks/D8Tsm7xC.cjs");
|
3
|
-
function fetch(route, options = {}) {
|
4
|
-
const { url, init } = parseRequest.parseRequest(route, options);
|
5
|
-
return globalThis.fetch(url, init);
|
6
|
-
}
|
7
|
-
exports.fetch = fetch;
|
8
|
-
//# sourceMappingURL=fetch.cjs.map
|
package/dist/fetch.cjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"fetch.cjs","sources":["../fetch.ts"],"sourcesContent":["import type { RequestOptions } from './utils/parseRequest'\nimport { parseRequest } from './utils/parseRequest'\n\n/**\n * Fetch a route with the provided options. This function will parse the route and\n * options to create a `Request` object and return the response from the server.\n *\n * @param route The name of the route to fetch.\n * @param options The options to pass to the request.\n * @returns The response from the server.\n * @example fetch('GET /users', { query: { limit: 10 } })\n */\nexport function fetch(route: string, options: RequestOptions = {}) {\n const { url, init } = parseRequest(route, options)\n return globalThis.fetch(url!, init)\n}\n"],"names":["parseRequest"],"mappings":";;AAYO,SAAS,MAAM,OAAe,UAA0B,IAAI;AACjE,QAAM,EAAE,KAAK,KAAA,IAASA,aAAAA,aAAa,OAAO,OAAO;AAC1C,SAAA,WAAW,MAAM,KAAM,IAAI;AACpC;;"}
|
package/dist/fetch.d.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import { c as RequestOptions } from './chunks/DZp6zyqV.js';
|
2
|
-
import '@unshared/types';
|
3
|
-
import './chunks/8BFCFxqa.js';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Fetch a route with the provided options. This function will parse the route and
|
7
|
-
* options to create a `Request` object and return the response from the server.
|
8
|
-
*
|
9
|
-
* @param route The name of the route to fetch.
|
10
|
-
* @param options The options to pass to the request.
|
11
|
-
* @returns The response from the server.
|
12
|
-
* @example fetch('GET /users', { query: { limit: 10 } })
|
13
|
-
*/
|
14
|
-
declare function fetch(route: string, options?: RequestOptions): Promise<Response>;
|
15
|
-
|
16
|
-
export { fetch };
|
package/dist/fetch.js
DELETED
package/dist/fetch.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"fetch.js","sources":["../fetch.ts"],"sourcesContent":["import type { RequestOptions } from './utils/parseRequest'\nimport { parseRequest } from './utils/parseRequest'\n\n/**\n * Fetch a route with the provided options. This function will parse the route and\n * options to create a `Request` object and return the response from the server.\n *\n * @param route The name of the route to fetch.\n * @param options The options to pass to the request.\n * @returns The response from the server.\n * @example fetch('GET /users', { query: { limit: 10 } })\n */\nexport function fetch(route: string, options: RequestOptions = {}) {\n const { url, init } = parseRequest(route, options)\n return globalThis.fetch(url!, init)\n}\n"],"names":[],"mappings":";AAYO,SAAS,MAAM,OAAe,UAA0B,IAAI;AACjE,QAAM,EAAE,KAAK,KAAA,IAAS,aAAa,OAAO,OAAO;AAC1C,SAAA,WAAW,MAAM,KAAM,IAAI;AACpC;"}
|