@trpc/openapi 0.0.0-alpha.0 → 11.13.2-alpha
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 +21 -0
- package/README.md +14 -0
- package/dist/cli.js +937 -0
- package/dist/heyapi/index.cjs +141 -0
- package/dist/heyapi/index.d.cts +67 -0
- package/dist/heyapi/index.d.cts.map +1 -0
- package/dist/heyapi/index.d.mts +67 -0
- package/dist/heyapi/index.d.mts.map +1 -0
- package/dist/heyapi/index.mjs +139 -0
- package/dist/heyapi/index.mjs.map +1 -0
- package/dist/index.cjs +834 -0
- package/dist/index.d.cts +63 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +63 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +835 -0
- package/dist/index.mjs.map +1 -0
- package/dist/objectSpread2-Cw30I7tb.cjs +131 -0
- package/dist/objectSpread2-UxrN8MPM.mjs +114 -0
- package/dist/objectSpread2-UxrN8MPM.mjs.map +1 -0
- package/package.json +101 -1
- package/src/cli.ts +133 -0
- package/src/generate.ts +1265 -0
- package/src/heyapi/index.ts +174 -0
- package/src/index.ts +2 -0
- package/src/schemaExtraction.ts +383 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const require_objectSpread2$1 = require('../objectSpread2-Cw30I7tb.cjs');
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js
|
|
4
|
+
var require_objectWithoutPropertiesLoose = require_objectSpread2$1.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js"(exports, module) {
|
|
5
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
6
|
+
if (null == r) return {};
|
|
7
|
+
var t = {};
|
|
8
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
9
|
+
if (e.includes(n)) continue;
|
|
10
|
+
t[n] = r[n];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
15
|
+
} });
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js
|
|
19
|
+
var require_objectWithoutProperties = require_objectSpread2$1.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js"(exports, module) {
|
|
20
|
+
var objectWithoutPropertiesLoose = require_objectWithoutPropertiesLoose();
|
|
21
|
+
function _objectWithoutProperties$1(e, t) {
|
|
22
|
+
if (null == e) return {};
|
|
23
|
+
var o, r, i = objectWithoutPropertiesLoose(e, t);
|
|
24
|
+
if (Object.getOwnPropertySymbols) {
|
|
25
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
26
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
27
|
+
}
|
|
28
|
+
return i;
|
|
29
|
+
}
|
|
30
|
+
module.exports = _objectWithoutProperties$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
31
|
+
} });
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/heyapi/index.ts
|
|
35
|
+
var import_objectSpread2 = require_objectSpread2$1.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
36
|
+
var import_objectWithoutProperties = require_objectSpread2$1.__toESM(require_objectWithoutProperties(), 1);
|
|
37
|
+
const _excluded = ["transformer"];
|
|
38
|
+
function resolveTransformer(transformer) {
|
|
39
|
+
if ("input" in transformer) return transformer;
|
|
40
|
+
return {
|
|
41
|
+
input: transformer,
|
|
42
|
+
output: transformer
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the `~resolvers` object for the `@hey-api/typescript` plugin.
|
|
47
|
+
*
|
|
48
|
+
* Maps `date` and `date-time` string formats to `Date` so that the
|
|
49
|
+
* generated SDK uses `Date` instead of `string` for those fields.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { createClient } from '@hey-api/openapi-ts';
|
|
54
|
+
* import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';
|
|
55
|
+
*
|
|
56
|
+
* await createClient({
|
|
57
|
+
* plugins: [
|
|
58
|
+
* { name: '@hey-api/typescript', '~resolvers': createTRPCHeyApiTypeResolvers() },
|
|
59
|
+
* ],
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function createTRPCHeyApiTypeResolvers() {
|
|
64
|
+
return {
|
|
65
|
+
string(ctx) {
|
|
66
|
+
if (ctx.schema.format === "date-time" || ctx.schema.format === "date") return ctx.$.type("Date");
|
|
67
|
+
return void 0;
|
|
68
|
+
},
|
|
69
|
+
number(ctx) {
|
|
70
|
+
if (ctx.schema.format === "bigint") return ctx.$.type("bigint");
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
77
|
+
*/
|
|
78
|
+
function createTRPCHeyApiClientConfig(opts) {
|
|
79
|
+
const transformer = (opts === null || opts === void 0 ? void 0 : opts.transformer) ? resolveTransformer(opts.transformer) : void 0;
|
|
80
|
+
return (0, import_objectSpread2.default)({ querySerializer: (query) => {
|
|
81
|
+
const params = new URLSearchParams();
|
|
82
|
+
for (const [key, value] of Object.entries(query)) {
|
|
83
|
+
if (value === void 0) continue;
|
|
84
|
+
if (key === "input" && transformer) params.append(key, JSON.stringify(transformer.input.serialize(value)));
|
|
85
|
+
else params.append(key, JSON.stringify(value));
|
|
86
|
+
}
|
|
87
|
+
return params.toString();
|
|
88
|
+
} }, transformer && {
|
|
89
|
+
bodySerializer: (body) => {
|
|
90
|
+
return JSON.stringify(transformer.input.serialize(body));
|
|
91
|
+
},
|
|
92
|
+
responseTransformer: async (data) => {
|
|
93
|
+
if (!!data && typeof data === "object" && "result" in data) {
|
|
94
|
+
const result = data.result;
|
|
95
|
+
if (!result.type || result.type === "data") result.data = transformer.output.deserialize(result.data);
|
|
96
|
+
}
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
103
|
+
*/
|
|
104
|
+
function createTRPCErrorInterceptor(transformerOpts) {
|
|
105
|
+
const transformer = resolveTransformer(transformerOpts);
|
|
106
|
+
return (error) => {
|
|
107
|
+
if (!!error && typeof error === "object" && "error" in error) error.error = transformer.output.deserialize(error.error);
|
|
108
|
+
return error;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Configures a hey-api client for use with a tRPC OpenAPI backend.
|
|
113
|
+
*
|
|
114
|
+
* Sets up querySerializer, bodySerializer, responseTransformer, and
|
|
115
|
+
* an error interceptor (for transformer-based error deserialization)
|
|
116
|
+
* in a single call.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
|
|
121
|
+
* import superjson from 'superjson';
|
|
122
|
+
* import { client } from './generated/client.gen';
|
|
123
|
+
*
|
|
124
|
+
* configureTRPCHeyApiClient(client, {
|
|
125
|
+
* baseUrl: 'http://localhost:3000',
|
|
126
|
+
* transformer: superjson,
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
function configureTRPCHeyApiClient(client, opts) {
|
|
131
|
+
const { transformer } = opts, heyConfig = (0, import_objectWithoutProperties.default)(opts, _excluded);
|
|
132
|
+
const trpcConfig = createTRPCHeyApiClientConfig({ transformer });
|
|
133
|
+
client.setConfig((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, heyConfig), trpcConfig));
|
|
134
|
+
if (transformer) client.interceptors.error.use(createTRPCErrorInterceptor(transformer));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
exports.configureTRPCHeyApiClient = configureTRPCHeyApiClient;
|
|
139
|
+
exports.createTRPCErrorInterceptor = createTRPCErrorInterceptor;
|
|
140
|
+
exports.createTRPCHeyApiClientConfig = createTRPCHeyApiClientConfig;
|
|
141
|
+
exports.createTRPCHeyApiTypeResolvers = createTRPCHeyApiTypeResolvers;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { FetchClient, UserConfig } from "@hey-api/openapi-ts";
|
|
2
|
+
import { TRPCCombinedDataTransformer, TRPCDataTransformer } from "@trpc/server";
|
|
3
|
+
|
|
4
|
+
//#region src/heyapi/index.d.ts
|
|
5
|
+
type DataTransformerOptions = TRPCDataTransformer | TRPCCombinedDataTransformer;
|
|
6
|
+
type HeyAPIResolvers = Exclude<Extract<Exclude<UserConfig['plugins'], undefined | string>[number], {
|
|
7
|
+
name: '@hey-api/typescript';
|
|
8
|
+
}>['~resolvers'], undefined>;
|
|
9
|
+
interface TRPCHeyApiClientOptions {
|
|
10
|
+
transformer?: DataTransformerOptions;
|
|
11
|
+
}
|
|
12
|
+
type HeyApiConfig = ReturnType<FetchClient['getConfig']>;
|
|
13
|
+
type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> & Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the `~resolvers` object for the `@hey-api/typescript` plugin.
|
|
16
|
+
*
|
|
17
|
+
* Maps `date` and `date-time` string formats to `Date` so that the
|
|
18
|
+
* generated SDK uses `Date` instead of `string` for those fields.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { createClient } from '@hey-api/openapi-ts';
|
|
23
|
+
* import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';
|
|
24
|
+
*
|
|
25
|
+
* await createClient({
|
|
26
|
+
* plugins: [
|
|
27
|
+
* { name: '@hey-api/typescript', '~resolvers': createTRPCHeyApiTypeResolvers() },
|
|
28
|
+
* ],
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers;
|
|
33
|
+
/**
|
|
34
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
35
|
+
*/
|
|
36
|
+
declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
37
|
+
readonly bodySerializer?: ((body: unknown) => string) | undefined;
|
|
38
|
+
readonly responseTransformer?: ((data: unknown) => Promise<unknown>) | undefined;
|
|
39
|
+
readonly querySerializer: (query: Record<string, unknown>) => string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
43
|
+
*/
|
|
44
|
+
declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOptions): (error: unknown) => unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Configures a hey-api client for use with a tRPC OpenAPI backend.
|
|
47
|
+
*
|
|
48
|
+
* Sets up querySerializer, bodySerializer, responseTransformer, and
|
|
49
|
+
* an error interceptor (for transformer-based error deserialization)
|
|
50
|
+
* in a single call.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
|
|
55
|
+
* import superjson from 'superjson';
|
|
56
|
+
* import { client } from './generated/client.gen';
|
|
57
|
+
*
|
|
58
|
+
* configureTRPCHeyApiClient(client, {
|
|
59
|
+
* baseUrl: 'http://localhost:3000',
|
|
60
|
+
* transformer: superjson,
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function configureTRPCHeyApiClient(client: FetchClient, opts: TRPCHeyApiClientOptions & Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>): void;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { DataTransformerOptions, HeyApiConfig, TRPCHeyApiClientConfig, TRPCHeyApiClientOptions, configureTRPCHeyApiClient, createTRPCErrorInterceptor, createTRPCHeyApiClientConfig, createTRPCHeyApiTypeResolvers };
|
|
67
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/heyapi/index.ts"],"sourcesContent":[],"mappings":";;;;KASY,sBAAA,GACR,sBACA;KAEC,eAAA,GAAkB,QACrB,QACE,QAAQ;EANA,IAAA,EAAA,qBAAsB;CAAA,CAAA,CAAA,YAAA,CAAA,EAAA,SAAA,CAAA;AAC9B,UAoBa,uBAAA,CApBb;EAAmB,WACnB,CAAA,EAoBY,sBApBZ;AAA2B;AAE1B,KAqBO,YAAA,GAAe,UArBP,CAqBkB,WArBlB,CAAA,WAAA,CAAA,CAAA;AAAA,KAsBR,sBAAA,GAAyB,QAtBjB,CAuBlB,IAvBkB,CAuBb,YAvBa,EAAA,iBAAA,CAAA,CAAA,GAyBlB,IAzBkB,CAyBb,YAzBa,EAAA,gBAAA,GAAA,qBAAA,CAAA;;;;;AAAU;AAiB9B;AAIA;;;;AAAqC;AACrC;;;;;;;AAGM,iBAoBU,6BAAA,CAAA,CApBV,EAoB2C,eApB3C;AAoBN;AAoBA;;AAAoD,iBAApC,4BAAA,CAAoC,IAAA,CAAA,EAAA,uBAAA,CAAA,EAAA;EAAuB,SAgC5B,cAAA,CAAA,EAAA,CAAA,CAAA,IAAA,EAAA,OAAA,EAAA,GAAA,MAAA,CAAA,GAAA,SAAA;EAAA,SA1BlB,mBAAA,CAAA,EAAA,CAAA,CAAA,IAAA,EAAA,OAAA,EAAA,GA0BkB,OA1BlB,CAAA,OAAA,CAAA,CAAA,GAAA,SAAA;EAAM,SAAA,eAAA,EAAA,CAAA,KAAA,EAAN,MAAM,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,MAAA;AA2CnC,CAAA;AAiCA;;;AAEQ,iBAnCQ,0BAAA,CAmCR,eAAA,EAlCW,sBAkCX,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,OAAA;;;;AACA;;;;;;;;;;;;;;;;iBAHQ,yBAAA,SACN,mBACF,0BACJ,KAAK,oBAAoB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { FetchClient, UserConfig } from "@hey-api/openapi-ts";
|
|
2
|
+
import { TRPCCombinedDataTransformer, TRPCDataTransformer } from "@trpc/server";
|
|
3
|
+
|
|
4
|
+
//#region src/heyapi/index.d.ts
|
|
5
|
+
type DataTransformerOptions = TRPCDataTransformer | TRPCCombinedDataTransformer;
|
|
6
|
+
type HeyAPIResolvers = Exclude<Extract<Exclude<UserConfig['plugins'], undefined | string>[number], {
|
|
7
|
+
name: '@hey-api/typescript';
|
|
8
|
+
}>['~resolvers'], undefined>;
|
|
9
|
+
interface TRPCHeyApiClientOptions {
|
|
10
|
+
transformer?: DataTransformerOptions;
|
|
11
|
+
}
|
|
12
|
+
type HeyApiConfig = ReturnType<FetchClient['getConfig']>;
|
|
13
|
+
type TRPCHeyApiClientConfig = Required<Pick<HeyApiConfig, 'querySerializer'>> & Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the `~resolvers` object for the `@hey-api/typescript` plugin.
|
|
16
|
+
*
|
|
17
|
+
* Maps `date` and `date-time` string formats to `Date` so that the
|
|
18
|
+
* generated SDK uses `Date` instead of `string` for those fields.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { createClient } from '@hey-api/openapi-ts';
|
|
23
|
+
* import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';
|
|
24
|
+
*
|
|
25
|
+
* await createClient({
|
|
26
|
+
* plugins: [
|
|
27
|
+
* { name: '@hey-api/typescript', '~resolvers': createTRPCHeyApiTypeResolvers() },
|
|
28
|
+
* ],
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers;
|
|
33
|
+
/**
|
|
34
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
35
|
+
*/
|
|
36
|
+
declare function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions): {
|
|
37
|
+
readonly bodySerializer?: ((body: unknown) => string) | undefined;
|
|
38
|
+
readonly responseTransformer?: ((data: unknown) => Promise<unknown>) | undefined;
|
|
39
|
+
readonly querySerializer: (query: Record<string, unknown>) => string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
43
|
+
*/
|
|
44
|
+
declare function createTRPCErrorInterceptor(transformerOpts: DataTransformerOptions): (error: unknown) => unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Configures a hey-api client for use with a tRPC OpenAPI backend.
|
|
47
|
+
*
|
|
48
|
+
* Sets up querySerializer, bodySerializer, responseTransformer, and
|
|
49
|
+
* an error interceptor (for transformer-based error deserialization)
|
|
50
|
+
* in a single call.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
|
|
55
|
+
* import superjson from 'superjson';
|
|
56
|
+
* import { client } from './generated/client.gen';
|
|
57
|
+
*
|
|
58
|
+
* configureTRPCHeyApiClient(client, {
|
|
59
|
+
* baseUrl: 'http://localhost:3000',
|
|
60
|
+
* transformer: superjson,
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function configureTRPCHeyApiClient(client: FetchClient, opts: TRPCHeyApiClientOptions & Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>): void;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { DataTransformerOptions, HeyApiConfig, TRPCHeyApiClientConfig, TRPCHeyApiClientOptions, configureTRPCHeyApiClient, createTRPCErrorInterceptor, createTRPCHeyApiClientConfig, createTRPCHeyApiTypeResolvers };
|
|
67
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/heyapi/index.ts"],"sourcesContent":[],"mappings":";;;;KASY,sBAAA,GACR,sBACA;KAEC,eAAA,GAAkB,QACrB,QACE,QAAQ;EANA,IAAA,EAAA,qBAAsB;CAAA,CAAA,CAAA,YAAA,CAAA,EAAA,SAAA,CAAA;AAC9B,UAoBa,uBAAA,CApBb;EAAmB,WACnB,CAAA,EAoBY,sBApBZ;AAA2B;AAE1B,KAqBO,YAAA,GAAe,UArBP,CAqBkB,WArBlB,CAAA,WAAA,CAAA,CAAA;AAAA,KAsBR,sBAAA,GAAyB,QAtBjB,CAuBlB,IAvBkB,CAuBb,YAvBa,EAAA,iBAAA,CAAA,CAAA,GAyBlB,IAzBkB,CAyBb,YAzBa,EAAA,gBAAA,GAAA,qBAAA,CAAA;;;;;AAAU;AAiB9B;AAIA;;;;AAAqC;AACrC;;;;;;;AAGM,iBAoBU,6BAAA,CAAA,CApBV,EAoB2C,eApB3C;AAoBN;AAoBA;;AAAoD,iBAApC,4BAAA,CAAoC,IAAA,CAAA,EAAA,uBAAA,CAAA,EAAA;EAAuB,SAgC5B,cAAA,CAAA,EAAA,CAAA,CAAA,IAAA,EAAA,OAAA,EAAA,GAAA,MAAA,CAAA,GAAA,SAAA;EAAA,SA1BlB,mBAAA,CAAA,EAAA,CAAA,CAAA,IAAA,EAAA,OAAA,EAAA,GA0BkB,OA1BlB,CAAA,OAAA,CAAA,CAAA,GAAA,SAAA;EAAM,SAAA,eAAA,EAAA,CAAA,KAAA,EAAN,MAAM,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,MAAA;AA2CnC,CAAA;AAiCA;;;AAEQ,iBAnCQ,0BAAA,CAmCR,eAAA,EAlCW,sBAkCX,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,OAAA;;;;AACA;;;;;;;;;;;;;;;;iBAHQ,yBAAA,SACN,mBACF,0BACJ,KAAK,oBAAoB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { __commonJS, __toESM, require_objectSpread2 } from "../objectSpread2-UxrN8MPM.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js
|
|
4
|
+
var require_objectWithoutPropertiesLoose = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js"(exports, module) {
|
|
5
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
6
|
+
if (null == r) return {};
|
|
7
|
+
var t = {};
|
|
8
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
9
|
+
if (e.includes(n)) continue;
|
|
10
|
+
t[n] = r[n];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
15
|
+
} });
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js
|
|
19
|
+
var require_objectWithoutProperties = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js"(exports, module) {
|
|
20
|
+
var objectWithoutPropertiesLoose = require_objectWithoutPropertiesLoose();
|
|
21
|
+
function _objectWithoutProperties$1(e, t) {
|
|
22
|
+
if (null == e) return {};
|
|
23
|
+
var o, r, i = objectWithoutPropertiesLoose(e, t);
|
|
24
|
+
if (Object.getOwnPropertySymbols) {
|
|
25
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
26
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
27
|
+
}
|
|
28
|
+
return i;
|
|
29
|
+
}
|
|
30
|
+
module.exports = _objectWithoutProperties$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
31
|
+
} });
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/heyapi/index.ts
|
|
35
|
+
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
36
|
+
var import_objectWithoutProperties = __toESM(require_objectWithoutProperties(), 1);
|
|
37
|
+
const _excluded = ["transformer"];
|
|
38
|
+
function resolveTransformer(transformer) {
|
|
39
|
+
if ("input" in transformer) return transformer;
|
|
40
|
+
return {
|
|
41
|
+
input: transformer,
|
|
42
|
+
output: transformer
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the `~resolvers` object for the `@hey-api/typescript` plugin.
|
|
47
|
+
*
|
|
48
|
+
* Maps `date` and `date-time` string formats to `Date` so that the
|
|
49
|
+
* generated SDK uses `Date` instead of `string` for those fields.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { createClient } from '@hey-api/openapi-ts';
|
|
54
|
+
* import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';
|
|
55
|
+
*
|
|
56
|
+
* await createClient({
|
|
57
|
+
* plugins: [
|
|
58
|
+
* { name: '@hey-api/typescript', '~resolvers': createTRPCHeyApiTypeResolvers() },
|
|
59
|
+
* ],
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function createTRPCHeyApiTypeResolvers() {
|
|
64
|
+
return {
|
|
65
|
+
string(ctx) {
|
|
66
|
+
if (ctx.schema.format === "date-time" || ctx.schema.format === "date") return ctx.$.type("Date");
|
|
67
|
+
return void 0;
|
|
68
|
+
},
|
|
69
|
+
number(ctx) {
|
|
70
|
+
if (ctx.schema.format === "bigint") return ctx.$.type("bigint");
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
77
|
+
*/
|
|
78
|
+
function createTRPCHeyApiClientConfig(opts) {
|
|
79
|
+
const transformer = (opts === null || opts === void 0 ? void 0 : opts.transformer) ? resolveTransformer(opts.transformer) : void 0;
|
|
80
|
+
return (0, import_objectSpread2.default)({ querySerializer: (query) => {
|
|
81
|
+
const params = new URLSearchParams();
|
|
82
|
+
for (const [key, value] of Object.entries(query)) {
|
|
83
|
+
if (value === void 0) continue;
|
|
84
|
+
if (key === "input" && transformer) params.append(key, JSON.stringify(transformer.input.serialize(value)));
|
|
85
|
+
else params.append(key, JSON.stringify(value));
|
|
86
|
+
}
|
|
87
|
+
return params.toString();
|
|
88
|
+
} }, transformer && {
|
|
89
|
+
bodySerializer: (body) => {
|
|
90
|
+
return JSON.stringify(transformer.input.serialize(body));
|
|
91
|
+
},
|
|
92
|
+
responseTransformer: async (data) => {
|
|
93
|
+
if (!!data && typeof data === "object" && "result" in data) {
|
|
94
|
+
const result = data.result;
|
|
95
|
+
if (!result.type || result.type === "data") result.data = transformer.output.deserialize(result.data);
|
|
96
|
+
}
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @internal - Prefer `configureTRPCHeyApiClient`
|
|
103
|
+
*/
|
|
104
|
+
function createTRPCErrorInterceptor(transformerOpts) {
|
|
105
|
+
const transformer = resolveTransformer(transformerOpts);
|
|
106
|
+
return (error) => {
|
|
107
|
+
if (!!error && typeof error === "object" && "error" in error) error.error = transformer.output.deserialize(error.error);
|
|
108
|
+
return error;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Configures a hey-api client for use with a tRPC OpenAPI backend.
|
|
113
|
+
*
|
|
114
|
+
* Sets up querySerializer, bodySerializer, responseTransformer, and
|
|
115
|
+
* an error interceptor (for transformer-based error deserialization)
|
|
116
|
+
* in a single call.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';
|
|
121
|
+
* import superjson from 'superjson';
|
|
122
|
+
* import { client } from './generated/client.gen';
|
|
123
|
+
*
|
|
124
|
+
* configureTRPCHeyApiClient(client, {
|
|
125
|
+
* baseUrl: 'http://localhost:3000',
|
|
126
|
+
* transformer: superjson,
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
function configureTRPCHeyApiClient(client, opts) {
|
|
131
|
+
const { transformer } = opts, heyConfig = (0, import_objectWithoutProperties.default)(opts, _excluded);
|
|
132
|
+
const trpcConfig = createTRPCHeyApiClientConfig({ transformer });
|
|
133
|
+
client.setConfig((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, heyConfig), trpcConfig));
|
|
134
|
+
if (transformer) client.interceptors.error.use(createTRPCErrorInterceptor(transformer));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
export { configureTRPCHeyApiClient, createTRPCErrorInterceptor, createTRPCHeyApiClientConfig, createTRPCHeyApiTypeResolvers };
|
|
139
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["_objectWithoutProperties","transformer: DataTransformerOptions","opts?: TRPCHeyApiClientOptions","query: Record<string, unknown>","body: unknown","data: unknown","transformerOpts: DataTransformerOptions","error: unknown","client: HeyApiFetchClient","opts: TRPCHeyApiClientOptions &\n Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>"],"sources":["../../../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js","../../../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js","../../src/heyapi/index.ts"],"sourcesContent":["function _objectWithoutPropertiesLoose(r, e) {\n if (null == r) return {};\n var t = {};\n for (var n in r) if ({}.hasOwnProperty.call(r, n)) {\n if (e.includes(n)) continue;\n t[n] = r[n];\n }\n return t;\n}\nmodule.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var objectWithoutPropertiesLoose = require(\"./objectWithoutPropertiesLoose.js\");\nfunction _objectWithoutProperties(e, t) {\n if (null == e) return {};\n var o,\n r,\n i = objectWithoutPropertiesLoose(e, t);\n if (Object.getOwnPropertySymbols) {\n var s = Object.getOwnPropertySymbols(e);\n for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);\n }\n return i;\n}\nmodule.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","import type {\n FetchClient as HeyApiFetchClient,\n UserConfig,\n} from '@hey-api/openapi-ts';\nimport type {\n TRPCCombinedDataTransformer,\n TRPCDataTransformer,\n} from '@trpc/server';\n\nexport type DataTransformerOptions =\n | TRPCDataTransformer\n | TRPCCombinedDataTransformer;\n\ntype HeyAPIResolvers = Exclude<\n Extract<\n Exclude<UserConfig['plugins'], undefined | string>[number],\n { name: '@hey-api/typescript' }\n >['~resolvers'],\n undefined\n>;\n\nfunction resolveTransformer(\n transformer: DataTransformerOptions,\n): TRPCCombinedDataTransformer {\n if ('input' in transformer) {\n return transformer;\n }\n return { input: transformer, output: transformer };\n}\n\nexport interface TRPCHeyApiClientOptions {\n transformer?: DataTransformerOptions;\n}\n\nexport type HeyApiConfig = ReturnType<HeyApiFetchClient['getConfig']>;\nexport type TRPCHeyApiClientConfig = Required<\n Pick<HeyApiConfig, 'querySerializer'>\n> &\n Pick<HeyApiConfig, 'bodySerializer' | 'responseTransformer'>;\n\n/**\n * Returns the `~resolvers` object for the `@hey-api/typescript` plugin.\n *\n * Maps `date` and `date-time` string formats to `Date` so that the\n * generated SDK uses `Date` instead of `string` for those fields.\n *\n * @example\n * ```ts\n * import { createClient } from '@hey-api/openapi-ts';\n * import { createTRPCHeyApiTypeResolvers } from '@trpc/openapi/heyapi';\n *\n * await createClient({\n * plugins: [\n * { name: '@hey-api/typescript', '~resolvers': createTRPCHeyApiTypeResolvers() },\n * ],\n * });\n * ```\n */\nexport function createTRPCHeyApiTypeResolvers(): HeyAPIResolvers {\n return {\n string(ctx) {\n if (ctx.schema.format === 'date-time' || ctx.schema.format === 'date') {\n return ctx.$.type('Date');\n }\n return undefined;\n },\n number(ctx) {\n if (ctx.schema.format === 'bigint') {\n return ctx.$.type('bigint');\n }\n return undefined;\n },\n };\n}\n\n/**\n * @internal - Prefer `configureTRPCHeyApiClient`\n */\nexport function createTRPCHeyApiClientConfig(opts?: TRPCHeyApiClientOptions) {\n const transformer = opts?.transformer\n ? resolveTransformer(opts.transformer)\n : undefined;\n\n return {\n querySerializer: (query: Record<string, unknown>) => {\n const params = new URLSearchParams();\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) {\n continue;\n }\n\n if (key === 'input' && transformer) {\n params.append(\n key,\n JSON.stringify(transformer.input.serialize(value)),\n );\n } else {\n params.append(key, JSON.stringify(value));\n }\n }\n\n return params.toString();\n },\n\n ...(transformer && {\n bodySerializer: (body: unknown) => {\n return JSON.stringify(transformer.input.serialize(body));\n },\n\n responseTransformer: async (data: unknown) => {\n if (!!data && typeof data === 'object' && 'result' in data) {\n const result = (data as any).result;\n if (!result.type || result.type === 'data') {\n result.data = transformer.output.deserialize(result.data);\n }\n }\n\n return data;\n },\n }),\n } as const satisfies TRPCHeyApiClientConfig;\n}\n\n/**\n * @internal - Prefer `configureTRPCHeyApiClient`\n */\nexport function createTRPCErrorInterceptor(\n transformerOpts: DataTransformerOptions,\n) {\n const transformer = resolveTransformer(transformerOpts);\n return (error: unknown) => {\n if (!!error && typeof error === 'object' && 'error' in error) {\n (error as any).error = transformer.output.deserialize(\n (error as any).error,\n );\n }\n return error;\n };\n}\n\n/**\n * Configures a hey-api client for use with a tRPC OpenAPI backend.\n *\n * Sets up querySerializer, bodySerializer, responseTransformer, and\n * an error interceptor (for transformer-based error deserialization)\n * in a single call.\n *\n * @example\n * ```ts\n * import { configureTRPCHeyApiClient } from '@trpc/openapi/heyapi';\n * import superjson from 'superjson';\n * import { client } from './generated/client.gen';\n *\n * configureTRPCHeyApiClient(client, {\n * baseUrl: 'http://localhost:3000',\n * transformer: superjson,\n * });\n * ```\n */\nexport function configureTRPCHeyApiClient(\n client: HeyApiFetchClient,\n opts: TRPCHeyApiClientOptions &\n Omit<HeyApiConfig, keyof TRPCHeyApiClientConfig>,\n) {\n const { transformer, ...heyConfig } = opts;\n const trpcConfig = createTRPCHeyApiClientConfig({ transformer });\n\n client.setConfig({ ...heyConfig, ...trpcConfig });\n\n if (transformer) {\n client.interceptors.error.use(createTRPCErrorInterceptor(transformer));\n }\n}\n"],"x_google_ignoreList":[0,1],"mappings":"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"}
|