one-shared 1.1.1 → 1.1.2
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 +11 -6
- package/package.json +1 -1
- package/schema.ts +7 -0
- package/types.ts +4 -5
package/client.ts
CHANGED
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
ApiSchemas,
|
|
5
5
|
ProcedureName,
|
|
6
6
|
OptionalParams,
|
|
7
|
-
|
|
7
|
+
} from "./types";
|
|
8
|
+
import { parseOutput } from "./schema";
|
|
8
9
|
|
|
9
10
|
/*
|
|
10
11
|
export const emptyParamsSchema = z.tuple([]).readonly()
|
|
@@ -39,7 +40,7 @@ export const apiSchemas = {
|
|
|
39
40
|
export default async function client<P extends ProcedureName>(
|
|
40
41
|
props: { procedure: P } & OptionalParams<ApiSchemas[P], "params"> &
|
|
41
42
|
OptionalParams<ApiSchemas[P], "input">,
|
|
42
|
-
): Promise<z.infer<ApiSchemas[P][
|
|
43
|
+
): Promise<z.infer<ApiSchemas[P]["output"]>> {
|
|
43
44
|
const base = "http://localhost:3000";
|
|
44
45
|
const procedureSchemas = apiSchemas[props.procedure];
|
|
45
46
|
|
|
@@ -52,7 +53,7 @@ export default async function client<P extends ProcedureName>(
|
|
|
52
53
|
const json = JSON.stringify(parsed);
|
|
53
54
|
init.body = json;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
|
|
56
57
|
// URL
|
|
57
58
|
const parts = [base, procedureSchemas.path];
|
|
58
59
|
if ("params" in procedureSchemas) {
|
|
@@ -65,8 +66,12 @@ export default async function client<P extends ProcedureName>(
|
|
|
65
66
|
const response = await fetch(url, init);
|
|
66
67
|
const data: unknown = await response.json();
|
|
67
68
|
|
|
68
|
-
const
|
|
69
|
-
const output =
|
|
69
|
+
// const parser: ParsersByProcedure[P] = apiSchemas[props.procedure];
|
|
70
|
+
// const output = parser.output.parse(data);
|
|
71
|
+
|
|
72
|
+
const output = parseOutput(apiSchemas[props.procedure], data)
|
|
70
73
|
|
|
71
74
|
return output;
|
|
72
|
-
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
package/package.json
CHANGED
package/schema.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
boolean,
|
|
12
12
|
varchar,
|
|
13
13
|
} from "drizzle-orm/pg-core";
|
|
14
|
+
import z from "zod";
|
|
14
15
|
|
|
15
16
|
export const statusSignalEnum = pgEnum("status_signal", [
|
|
16
17
|
"recovery",
|
|
@@ -209,3 +210,9 @@ export const relations = defineRelations(tables, (props) => {
|
|
|
209
210
|
};
|
|
210
211
|
});
|
|
211
212
|
|
|
213
|
+
export function parseOutput<Parser extends { output: z.ZodType; }>(
|
|
214
|
+
parser: Parser,
|
|
215
|
+
data: unknown): z.infer<Parser["output"]> {
|
|
216
|
+
return z.parse<Parser["output"]>(parser.output, data);
|
|
217
|
+
}
|
|
218
|
+
|
package/types.ts
CHANGED
|
@@ -170,14 +170,14 @@ 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
|
-
|
|
175
|
-
}
|
|
173
|
+
// export type OutputByProcedure = {
|
|
174
|
+
// [Name in ProcedureName]: z.infer<ApiSchemas[Name]['output']>
|
|
175
|
+
// }
|
|
176
176
|
|
|
177
177
|
export type ParsersByProcedure = {
|
|
178
178
|
[Name in ProcedureName]: {
|
|
179
179
|
output: {
|
|
180
|
-
parse(data: unknown):
|
|
180
|
+
parse(data: unknown): z.infer<ApiSchemas[Name]['output']>
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
}
|
|
@@ -240,4 +240,3 @@ export type ApiSchemas = typeof apiSchemas;
|
|
|
240
240
|
export type ProcedureName = keyof ApiSchemas;
|
|
241
241
|
// 'getHealth' | 'getIncidents' | 'getIncident' ...
|
|
242
242
|
|
|
243
|
-
const a = await Promise<z.infer<ApiSchemas['getHealth']["output"]>>
|