one-shared 1.1.0 → 1.1.1
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/client.ts +4 -2
- package/package.json +1 -1
- package/types.ts +15 -1
package/client.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ApiSchemas,
|
|
5
5
|
ProcedureName,
|
|
6
6
|
OptionalParams,
|
|
7
|
-
} from "./types";
|
|
7
|
+
ParsersByProcedure } from "./types";
|
|
8
8
|
|
|
9
9
|
/*
|
|
10
10
|
export const emptyParamsSchema = z.tuple([]).readonly()
|
|
@@ -64,7 +64,9 @@ export default async function client<P extends ProcedureName>(
|
|
|
64
64
|
|
|
65
65
|
const response = await fetch(url, init);
|
|
66
66
|
const data: unknown = await response.json();
|
|
67
|
-
|
|
67
|
+
|
|
68
|
+
const parsers: ParsersByProcedure = apiSchemas;
|
|
69
|
+
const output = parsers[props.procedure].output.parse(data)
|
|
68
70
|
|
|
69
71
|
return output;
|
|
70
72
|
}
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import db from "./db";
|
|
2
|
-
import { z } from "zod";
|
|
2
|
+
import { output, z } from "zod";
|
|
3
3
|
import {
|
|
4
4
|
channelsTable,
|
|
5
5
|
eventsTable,
|
|
@@ -170,6 +170,18 @@ export type OptionalParams<S, K extends PropertyKey> = S extends {
|
|
|
170
170
|
? { [P in K]: z.infer<T> }
|
|
171
171
|
: { [P in K]?: never };
|
|
172
172
|
|
|
173
|
+
export type OutputByProcedure = {
|
|
174
|
+
[Name in ProcedureName]: z.infer<ApiSchemas[Name]['output']>
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type ParsersByProcedure = {
|
|
178
|
+
[Name in ProcedureName]: {
|
|
179
|
+
output: {
|
|
180
|
+
parse(data: unknown): OutputByProcedure[Name]
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
173
185
|
export const incidentWithChannelSchema = incidentSchema.extend({
|
|
174
186
|
channel: channelSchema,
|
|
175
187
|
});
|
|
@@ -227,3 +239,5 @@ export type ApiSchemas = typeof apiSchemas;
|
|
|
227
239
|
|
|
228
240
|
export type ProcedureName = keyof ApiSchemas;
|
|
229
241
|
// 'getHealth' | 'getIncidents' | 'getIncident' ...
|
|
242
|
+
|
|
243
|
+
const a = await Promise<z.infer<ApiSchemas['getHealth']["output"]>>
|