nuxt-api-contract 0.1.0 → 0.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.
- package/README.md +32 -7
- package/dist/chunks/server.mjs +162 -0
- package/dist/cli.mjs +33 -1
- package/dist/client.d.mts +5 -69
- package/dist/client.d.ts +5 -69
- package/dist/client.mjs +3 -1
- package/dist/composables.mjs +2 -1
- package/dist/mock.d.mts +54 -0
- package/dist/mock.d.ts +54 -0
- package/dist/mock.mjs +8 -0
- package/dist/module.d.mts +8 -2
- package/dist/module.d.ts +8 -2
- package/dist/module.mjs +4 -2
- package/dist/runtime/shared/mock.mjs +188 -0
- package/dist/server.d.mts +7 -4
- package/dist/server.d.ts +7 -4
- package/dist/server.mjs +6 -3
- package/dist/shared/nuxt-api-contract.BOxyDvRy.d.mts +40 -0
- package/dist/shared/{nuxt-api-contract.S1zqCiJX.d.ts → nuxt-api-contract.B_UvrNC8.d.ts} +1 -1
- package/dist/shared/nuxt-api-contract.Bd2Y7Lx0.mjs +191 -0
- package/dist/shared/nuxt-api-contract.BgPd-YXc.d.mts +53 -0
- package/dist/shared/nuxt-api-contract.BuWjAHJe.d.ts +40 -0
- package/dist/shared/nuxt-api-contract.C7KxMQHa.d.ts +53 -0
- package/dist/shared/{nuxt-api-contract.CPm9WbWA.d.mts → nuxt-api-contract.CFG8gzJH.d.mts} +2 -2
- package/dist/shared/{nuxt-api-contract.CPm9WbWA.d.ts → nuxt-api-contract.CFG8gzJH.d.ts} +2 -2
- package/dist/shared/nuxt-api-contract.DZfOzVaB.d.mts +16 -0
- package/dist/shared/nuxt-api-contract.DZfOzVaB.d.ts +16 -0
- package/dist/shared/nuxt-api-contract.Dr4tPqGB.mjs +38 -0
- package/dist/shared/{nuxt-api-contract.QDGSGaVY.mjs → nuxt-api-contract.V15soI_f.mjs} +1 -38
- package/dist/shared/{nuxt-api-contract.B9JBCRk8.d.mts → nuxt-api-contract.VCevNWQV.d.mts} +1 -1
- package/dist/shared.d.mts +4 -2
- package/dist/shared.d.ts +4 -2
- package/dist/shared.mjs +3 -1
- package/package.json +5 -1
|
@@ -161,5 +161,5 @@ type ResolvedApiRequestOptions = {
|
|
|
161
161
|
*/
|
|
162
162
|
type ExtractSchemaOutput<T> = T extends ZodType<infer Output, any, any> ? Output : unknown;
|
|
163
163
|
|
|
164
|
-
export { API_CONTRACT_KIND as
|
|
165
|
-
export type {
|
|
164
|
+
export { API_CONTRACT_KIND as A };
|
|
165
|
+
export type { ContractBodyInput as C, EmptyObject as E, HttpMethod as H, IsEmptyObject as I, MaybePromise as M, PathParams as P, ResolvedApiRequestOptions as R, SplitPath as S, AnyApiContract as a, ApiContract as b, ApiContractDefinition as c, ApiRequestOptions as d, AuthConfig as e, ContractClientResponse as f, ContractErrorCode as g, ContractFromDefinition as h, ContractHandlerResponse as i, ContractHeadersInput as j, ContractParamsInput as k, ContractPathParams as l, ContractQueryInput as m, ExtractSchemaInput as n, ExtractSchemaOutput as o };
|
|
@@ -161,5 +161,5 @@ type ResolvedApiRequestOptions = {
|
|
|
161
161
|
*/
|
|
162
162
|
type ExtractSchemaOutput<T> = T extends ZodType<infer Output, any, any> ? Output : unknown;
|
|
163
163
|
|
|
164
|
-
export { API_CONTRACT_KIND as
|
|
165
|
-
export type {
|
|
164
|
+
export { API_CONTRACT_KIND as A };
|
|
165
|
+
export type { ContractBodyInput as C, EmptyObject as E, HttpMethod as H, IsEmptyObject as I, MaybePromise as M, PathParams as P, ResolvedApiRequestOptions as R, SplitPath as S, AnyApiContract as a, ApiContract as b, ApiContractDefinition as c, ApiRequestOptions as d, AuthConfig as e, ContractClientResponse as f, ContractErrorCode as g, ContractFromDefinition as h, ContractHandlerResponse as i, ContractHeadersInput as j, ContractParamsInput as k, ContractPathParams as l, ContractQueryInput as m, ExtractSchemaInput as n, ExtractSchemaOutput as o };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization helpers shared by the client transport and cache keys.
|
|
3
|
+
*
|
|
4
|
+
* The protocol intentionally stays minimal: standard JSON plus two common
|
|
5
|
+
* edge cases (Date and bigint). Response serialization relies on Nitro's
|
|
6
|
+
* built-in devalue support, which already handles Date, RegExp, etc.
|
|
7
|
+
*/
|
|
8
|
+
/** Converts query values into URL-safe primitives (Date -> ISO, bigint -> string). */
|
|
9
|
+
type SerializedQueryValue = string | number | boolean | Array<string | number | boolean>;
|
|
10
|
+
declare function serializeQueryValue(value: unknown): SerializedQueryValue;
|
|
11
|
+
/** Prepares a query object for `$fetch` / URL building; drops `undefined` entries. */
|
|
12
|
+
declare function serializeQuery(query: Record<string, unknown> | undefined): Record<string, SerializedQueryValue> | undefined;
|
|
13
|
+
/** Deterministic JSON stringify (sorted keys) for stable SSR cache keys. */
|
|
14
|
+
declare function stableStringify(value: unknown): string;
|
|
15
|
+
|
|
16
|
+
export { serializeQueryValue as a, stableStringify as b, serializeQuery as s };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization helpers shared by the client transport and cache keys.
|
|
3
|
+
*
|
|
4
|
+
* The protocol intentionally stays minimal: standard JSON plus two common
|
|
5
|
+
* edge cases (Date and bigint). Response serialization relies on Nitro's
|
|
6
|
+
* built-in devalue support, which already handles Date, RegExp, etc.
|
|
7
|
+
*/
|
|
8
|
+
/** Converts query values into URL-safe primitives (Date -> ISO, bigint -> string). */
|
|
9
|
+
type SerializedQueryValue = string | number | boolean | Array<string | number | boolean>;
|
|
10
|
+
declare function serializeQueryValue(value: unknown): SerializedQueryValue;
|
|
11
|
+
/** Prepares a query object for `$fetch` / URL building; drops `undefined` entries. */
|
|
12
|
+
declare function serializeQuery(query: Record<string, unknown> | undefined): Record<string, SerializedQueryValue> | undefined;
|
|
13
|
+
/** Deterministic JSON stringify (sorted keys) for stable SSR cache keys. */
|
|
14
|
+
declare function stableStringify(value: unknown): string;
|
|
15
|
+
|
|
16
|
+
export { serializeQueryValue as a, stableStringify as b, serializeQuery as s };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function serializeQueryValue(value) {
|
|
2
|
+
if (value instanceof Date) return value.toISOString();
|
|
3
|
+
if (typeof value === "bigint") return value.toString();
|
|
4
|
+
if (Array.isArray(value)) return value.map((item) => serializePrimitive(item));
|
|
5
|
+
if (value === void 0 || value === null) return "";
|
|
6
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function serializePrimitive(value) {
|
|
10
|
+
if (value instanceof Date) return value.toISOString();
|
|
11
|
+
if (typeof value === "bigint") return value.toString();
|
|
12
|
+
if (value === void 0 || value === null || typeof value === "object") return JSON.stringify(value) ?? "";
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function serializeQuery(query) {
|
|
16
|
+
if (!query) return void 0;
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const [key, value] of Object.entries(query)) {
|
|
19
|
+
if (value === void 0) continue;
|
|
20
|
+
result[key] = serializeQueryValue(value);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
function stableStringify(value) {
|
|
25
|
+
return JSON.stringify(sortValue(value));
|
|
26
|
+
}
|
|
27
|
+
function sortValue(value) {
|
|
28
|
+
if (Array.isArray(value)) return value.map((item) => sortValue(item));
|
|
29
|
+
if (value instanceof Date) return value.toISOString();
|
|
30
|
+
if (typeof value === "bigint") return value.toString();
|
|
31
|
+
if (value !== null && typeof value === "object") {
|
|
32
|
+
const entries = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
33
|
+
return Object.fromEntries(entries.map(([key, item]) => [key, sortValue(item)]));
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { serializeQueryValue as a, stableStringify as b, serializeQuery as s };
|
|
@@ -77,41 +77,4 @@ function buildRequestPath(path, params) {
|
|
|
77
77
|
return url;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
if (value instanceof Date) return value.toISOString();
|
|
82
|
-
if (typeof value === "bigint") return value.toString();
|
|
83
|
-
if (Array.isArray(value)) return value.map((item) => serializePrimitive(item));
|
|
84
|
-
if (value === void 0 || value === null) return "";
|
|
85
|
-
if (typeof value === "object") return JSON.stringify(value);
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
function serializePrimitive(value) {
|
|
89
|
-
if (value instanceof Date) return value.toISOString();
|
|
90
|
-
if (typeof value === "bigint") return value.toString();
|
|
91
|
-
if (value === void 0 || value === null || typeof value === "object") return JSON.stringify(value) ?? "";
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
function serializeQuery(query) {
|
|
95
|
-
if (!query) return void 0;
|
|
96
|
-
const result = {};
|
|
97
|
-
for (const [key, value] of Object.entries(query)) {
|
|
98
|
-
if (value === void 0) continue;
|
|
99
|
-
result[key] = serializeQueryValue(value);
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
function stableStringify(value) {
|
|
104
|
-
return JSON.stringify(sortValue(value));
|
|
105
|
-
}
|
|
106
|
-
function sortValue(value) {
|
|
107
|
-
if (Array.isArray(value)) return value.map((item) => sortValue(item));
|
|
108
|
-
if (value instanceof Date) return value.toISOString();
|
|
109
|
-
if (typeof value === "bigint") return value.toString();
|
|
110
|
-
if (value !== null && typeof value === "object") {
|
|
111
|
-
const entries = Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
112
|
-
return Object.fromEntries(entries.map(([key, item]) => [key, sortValue(item)]));
|
|
113
|
-
}
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export { getContractMock as a, buildRequestPath as b, clearContractRegistry as c, defineApiContract as d, serializeQueryValue as e, stableStringify as f, getContractByName as g, isApiContract as i, listRegisteredContracts as l, mockContract as m, registerContract as r, serializeQuery as s };
|
|
80
|
+
export { getContractMock as a, buildRequestPath as b, clearContractRegistry as c, defineApiContract as d, getContractByName as g, isApiContract as i, listRegisteredContracts as l, mockContract as m, registerContract as r };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { H3Event, EventHandler } from 'h3';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import { a as AnyApiContract, M as MaybePromise, i as ContractHandlerResponse } from './nuxt-api-contract.CFG8gzJH.mjs';
|
|
4
4
|
|
|
5
5
|
type Infer<T> = T extends z.ZodType ? z.infer<T> : never;
|
|
6
6
|
/**
|
package/dist/shared.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { ContractMock, MockResponseInput, buildRequestPath, clearContractRegistry, defineApiContract, getContractByName, getContractMock, isApiContract, listRegisteredContracts, mockContract,
|
|
1
|
+
export { C as ContractMock, M as MockResponseInput, b as buildRequestPath, c as clearContractRegistry, d as defineApiContract, g as getContractByName, a as getContractMock, i as isApiContract, l as listRegisteredContracts, m as mockContract, r as registerContract } from './shared/nuxt-api-contract.BgPd-YXc.mjs';
|
|
2
2
|
export { A as ApiError, a as ApiErrorPayload, B as BUILT_IN_ERROR_CODES, C as CreateApiErrorInput, V as ValidationIssue, c as createApiError, f as formatValidationMessage, i as isApiError, p as parseApiErrorPayload, s as sanitizeIssues, b as serializeApiError, t as toApiError, d as toValidationIssues } from './shared/nuxt-api-contract.D31EDcwH.mjs';
|
|
3
|
-
export {
|
|
3
|
+
export { s as serializeQuery, a as serializeQueryValue, b as stableStringify } from './shared/nuxt-api-contract.DZfOzVaB.mjs';
|
|
4
|
+
export { A as API_CONTRACT_KIND, a as AnyApiContract, b as ApiContract, c as ApiContractDefinition, d as ApiRequestOptions, e as AuthConfig, C as ContractBodyInput, f as ContractClientResponse, g as ContractErrorCode, h as ContractFromDefinition, i as ContractHandlerResponse, j as ContractHeadersInput, k as ContractParamsInput, l as ContractPathParams, m as ContractQueryInput, E as EmptyObject, n as ExtractSchemaInput, o as ExtractSchemaOutput, H as HttpMethod, I as IsEmptyObject, M as MaybePromise, P as PathParams, R as ResolvedApiRequestOptions, S as SplitPath } from './shared/nuxt-api-contract.CFG8gzJH.mjs';
|
|
5
|
+
export { M as MockGenerateOptions, a as autoMockContract, c as createRng, g as generateMockResponse, b as generateMockValue } from './shared/nuxt-api-contract.BOxyDvRy.mjs';
|
|
4
6
|
import 'zod';
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { ContractMock, MockResponseInput, buildRequestPath, clearContractRegistry, defineApiContract, getContractByName, getContractMock, isApiContract, listRegisteredContracts, mockContract,
|
|
1
|
+
export { C as ContractMock, M as MockResponseInput, b as buildRequestPath, c as clearContractRegistry, d as defineApiContract, g as getContractByName, a as getContractMock, i as isApiContract, l as listRegisteredContracts, m as mockContract, r as registerContract } from './shared/nuxt-api-contract.C7KxMQHa.js';
|
|
2
2
|
export { A as ApiError, a as ApiErrorPayload, B as BUILT_IN_ERROR_CODES, C as CreateApiErrorInput, V as ValidationIssue, c as createApiError, f as formatValidationMessage, i as isApiError, p as parseApiErrorPayload, s as sanitizeIssues, b as serializeApiError, t as toApiError, d as toValidationIssues } from './shared/nuxt-api-contract.D31EDcwH.js';
|
|
3
|
-
export {
|
|
3
|
+
export { s as serializeQuery, a as serializeQueryValue, b as stableStringify } from './shared/nuxt-api-contract.DZfOzVaB.js';
|
|
4
|
+
export { A as API_CONTRACT_KIND, a as AnyApiContract, b as ApiContract, c as ApiContractDefinition, d as ApiRequestOptions, e as AuthConfig, C as ContractBodyInput, f as ContractClientResponse, g as ContractErrorCode, h as ContractFromDefinition, i as ContractHandlerResponse, j as ContractHeadersInput, k as ContractParamsInput, l as ContractPathParams, m as ContractQueryInput, E as EmptyObject, n as ExtractSchemaInput, o as ExtractSchemaOutput, H as HttpMethod, I as IsEmptyObject, M as MaybePromise, P as PathParams, R as ResolvedApiRequestOptions, S as SplitPath } from './shared/nuxt-api-contract.CFG8gzJH.js';
|
|
5
|
+
export { M as MockGenerateOptions, a as autoMockContract, c as createRng, g as generateMockResponse, b as generateMockValue } from './shared/nuxt-api-contract.BuWjAHJe.js';
|
|
4
6
|
import 'zod';
|
package/dist/shared.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { b as buildRequestPath, c as clearContractRegistry, d as defineApiContract, g as getContractByName, a as getContractMock, i as isApiContract, l as listRegisteredContracts, m as mockContract, r as registerContract
|
|
1
|
+
export { b as buildRequestPath, c as clearContractRegistry, d as defineApiContract, g as getContractByName, a as getContractMock, i as isApiContract, l as listRegisteredContracts, m as mockContract, r as registerContract } from './shared/nuxt-api-contract.V15soI_f.mjs';
|
|
2
2
|
export { A as ApiError, B as BUILT_IN_ERROR_CODES, c as createApiError, i as isApiError, p as parseApiErrorPayload, s as serializeApiError, t as toApiError } from './shared/nuxt-api-contract.obS6uV8A.mjs';
|
|
3
3
|
export { f as formatValidationMessage, s as sanitizeIssues, t as toValidationIssues } from './shared/nuxt-api-contract.DCAU2j7t.mjs';
|
|
4
|
+
export { s as serializeQuery, a as serializeQueryValue, b as stableStringify } from './shared/nuxt-api-contract.Dr4tPqGB.mjs';
|
|
5
|
+
export { a as autoMockContract, c as createRng, g as generateMockResponse, b as generateMockValue } from './shared/nuxt-api-contract.Bd2Y7Lx0.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-api-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Type-safe API contracts between Nitro server routes and the Nuxt client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,6 +56,10 @@
|
|
|
56
56
|
"types": "./dist/openapi.d.mts",
|
|
57
57
|
"import": "./dist/openapi.mjs"
|
|
58
58
|
},
|
|
59
|
+
"./mock": {
|
|
60
|
+
"types": "./dist/mock.d.mts",
|
|
61
|
+
"import": "./dist/mock.mjs"
|
|
62
|
+
},
|
|
59
63
|
"./package.json": "./package.json"
|
|
60
64
|
},
|
|
61
65
|
"bin": {
|