@seam-rpc/server 4.3.2 → 4.3.4

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.
@@ -2,7 +2,7 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import fg from "fast-glob";
4
4
  import ts from "typescript";
5
- import { zodToTs, createAuxiliaryTypeStore, printNode } from "zod-to-ts";
5
+ import { zodToTs, createAuxiliaryTypeStore } from "zod-to-ts";
6
6
  import { existsSync, writeFileSync } from "fs";
7
7
  export async function generateClient() {
8
8
  const config = loadConfig();
@@ -111,10 +111,23 @@ function getFullComment(node, sourceText) {
111
111
  }
112
112
  return "";
113
113
  }
114
+ // function convert(schema: z.ZodType): string {
115
+ // const store = createAuxiliaryTypeStore();
116
+ // const { node } = zodToTs(schema, { auxiliaryTypeStore: store });
117
+ // return printNode(node);
118
+ // }
114
119
  function convert(schema) {
115
120
  const store = createAuxiliaryTypeStore();
116
- const { node } = zodToTs(schema, { auxiliaryTypeStore: store });
117
- return printNode(node);
121
+ const { node } = zodToTs(schema, {
122
+ auxiliaryTypeStore: store,
123
+ });
124
+ const typeAlias = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier("GeneratedType"), undefined, node);
125
+ const file = ts.createSourceFile("types.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
126
+ const printer = ts.createPrinter({
127
+ newLine: ts.NewLineKind.LineFeed,
128
+ removeComments: false,
129
+ });
130
+ return printer.printNode(ts.EmitHint.Unspecified, typeAlias, file);
118
131
  }
119
132
  export async function generateClientFile({ tsPath, jsPath, outputPath, }) {
120
133
  const tsFile = path.resolve(process.cwd(), tsPath);
@@ -137,7 +150,7 @@ export async function generateClientFile({ tsPath, jsPath, outputPath, }) {
137
150
  * +===================================+
138
151
  */
139
152
 
140
- import { callApi, Result, RpcError } from "@seam-rpc/client";
153
+ import { callApi } from "@seam-rpc/client";
141
154
 
142
155
  `;
143
156
  const functions = [];
package/dist/test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import * as z from "zod";
2
+ export declare function convert(schema: z.ZodTypeAny): string;
package/dist/test.js ADDED
@@ -0,0 +1,56 @@
1
+ import { zodToTs, createAuxiliaryTypeStore, printNode } from "zod-to-ts";
2
+ import * as z from "zod";
3
+ import ts from "typescript";
4
+ export function convert(schema) {
5
+ const store = createAuxiliaryTypeStore();
6
+ const { node } = zodToTs(schema, {
7
+ auxiliaryTypeStore: store,
8
+ });
9
+ const typeAlias = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier("GeneratedType"), undefined, node);
10
+ const file = ts.createSourceFile("types.ts", "", ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
11
+ const printer = ts.createPrinter({
12
+ newLine: ts.NewLineKind.LineFeed,
13
+ removeComments: false,
14
+ });
15
+ return printer.printNode(ts.EmitHint.Unspecified, typeAlias, file);
16
+ }
17
+ function convert2(schema) {
18
+ const store = createAuxiliaryTypeStore();
19
+ const { node } = zodToTs(schema, { auxiliaryTypeStore: store });
20
+ return printNode(node);
21
+ }
22
+ console.log(convert2(z.object({
23
+ user: z.object({
24
+ email: z.string(),
25
+ id: z.string(),
26
+ createdAt: z.date(),
27
+ firstName: z.string(),
28
+ lastName: z.string(),
29
+ trackingStartDate: z.string(),
30
+ trackingWorkItemId: z.string(),
31
+ }),
32
+ roles: z.object({
33
+ id: z.string(),
34
+ name: z.string(),
35
+ createdAt: z.date(),
36
+ permissions: z.number().array(),
37
+ projectId: z.string(),
38
+ }),
39
+ workItems: z.object({
40
+ id: z.string(),
41
+ createdAt: z.date(),
42
+ date: z.date(),
43
+ link: z.string(),
44
+ title: z.string(),
45
+ description: z.string(),
46
+ projectId: z.string(),
47
+ authorId: z.string(),
48
+ durationMethod: z.string(),
49
+ startTime: z.number(),
50
+ endTime: z.number(),
51
+ duration: z.number(),
52
+ labels: z.string(),
53
+ updatedAt: z.string(),
54
+ projectMemberId: z.string(),
55
+ })
56
+ })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seam-rpc/server",
3
- "version": "4.3.2",
3
+ "version": "4.3.4",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "bin": {