Skip to content

Commit 11e6c21

Browse files
committed
Merge branch 'release/v0.28.2'
2 parents 041b9a1 + 30feaa4 commit 11e6c21

11 files changed

Lines changed: 341 additions & 36 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 🌱 Zeed Library
22

3-
> Plant the "zeed" for your next Typescript project and let it grow with this useful lib, providing basic functionalities handy in most projects.
3+
> [!CAUTION]
4+
> The main repository is now at <https://codeberg.org/holtwick/zeed> to strengthen European sovereignty. Learn more at [UnplugTrump](https://holtwick.de/blog/unplug-trump).
45
56
- Strict **TypeScript**
67
- **Zero dependencies** and lightweight, **tree-shakable**

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "zeed",
33
"type": "module",
4-
"version": "0.28.1",
5-
"packageManager": "pnpm@10.7.0",
4+
"version": "0.28.2",
5+
"packageManager": "pnpm@10.8.1",
66
"description": "🌱 Simple foundation library",
77
"author": {
88
"name": "Dirk Holtwick",
@@ -70,23 +70,24 @@
7070
"watch": "nr build -- --watch src"
7171
},
7272
"devDependencies": {
73-
"@antfu/eslint-config": "^4.11.0",
73+
"@antfu/eslint-config": "^4.12.0",
7474
"@antfu/ni": "^24.3.0",
75-
"@types/node": "^22.13.14",
75+
"@types/node": "^22.14.1",
7676
"@vitejs/plugin-vue": "^5.2.3",
7777
"@vitest/browser": "^3.1.1",
7878
"@vitest/coverage-v8": "^3.1.1",
7979
"esbuild": "^0.25.2",
80-
"eslint": "^9.23.0",
80+
"eslint": "^9.24.0",
8181
"playwright": "^1.51.1",
8282
"pnpm": "^10.7.0",
8383
"tsup": "^8.4.0",
84-
"typescript": "^5.8.2",
85-
"vite": "^6.2.4",
84+
"typescript": "^5.8.3",
85+
"vite": "^6.2.6",
8686
"vitest": "^3.1.1"
8787
},
8888
"pnpm": {
8989
"overrides": {
90+
"@babel/runtime@<7.26.10": ">=7.26.10",
9091
"braces@<3.0.3": ">=3.0.3"
9192
}
9293
}

src/common/msg/rpc.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ describe('rpc async', () => {
7373
await new Promise(resolve => setTimeout(resolve, 100))
7474
expect(Bob.getCount()).toBe(1)
7575

76-
c1.close()
77-
c2.close()
76+
c1.dispose()
77+
c2.dispose()
7878

7979
expect(log).toMatchInlineSnapshot(`
8080
Array [
@@ -146,8 +146,8 @@ describe('rpc async', () => {
146146
await new Promise(resolve => setTimeout(resolve, 100))
147147
expect(Bob.getCount()).toBe(1)
148148

149-
c1.close()
150-
c2.close()
149+
c1.dispose()
150+
c2.dispose()
151151
})
152152

153153
it('timeout async', async (done) => {

src/common/schema/args.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ describe('args.spec', () => {
1515
})
1616

1717
type t = Infer<typeof schema>
18-
expectTypeOf<t>().toMatchTypeOf<any>()
18+
expectTypeOf<t>().toMatchObjectType<{
19+
someStuff?: number | undefined
20+
help: boolean
21+
}>()
1922

2023
const args = ['test.txt', '-h', '--some-stuff=8888']
2124

@@ -39,5 +42,44 @@ describe('args.spec', () => {
3942
--help, -h
4043
Shows help"
4144
`)
45+
46+
//
47+
48+
const rr = parseSchemaArgs(schema, [])
49+
expect(rr).toMatchInlineSnapshot(`
50+
Array [
51+
Object {
52+
"help": false,
53+
"someStuff": undefined,
54+
},
55+
Array [],
56+
]
57+
`)
58+
59+
expect(schema).toMatchInlineSnapshot(`
60+
TypeObjectClass {
61+
"_check": [Function],
62+
"_object": Object {
63+
"help": TypeGeneric {
64+
"_check": [Function],
65+
"_default": false,
66+
"_props": Object {
67+
"argDesc": "Shows help",
68+
"argShort": "h",
69+
},
70+
"type": "boolean",
71+
},
72+
"someStuff": TypeGeneric {
73+
"_check": [Function],
74+
"_optional": true,
75+
"_props": Object {
76+
"argDesc": "Does some stuff",
77+
},
78+
"type": "number",
79+
},
80+
},
81+
"type": "object",
82+
}
83+
`)
4284
})
4385
})

src/common/schema/args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function parseSchemaArgs<T>(schema: Type<T>, args: any = process?.argv ??
5959

6060
const argsResult = objectMap(schema._object!, (key, schema) => {
6161
let value = argsObj[toCamelCase(key)]
62-
if (schema.type === 'number') {
62+
if (schema.type === 'number' && value != null) {
6363
value = valueToInteger(value)
6464
}
6565
return schema.parse(value)

src/common/schema/env.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Infer } from './schema'
12
import { parseSchemaEnv, stringFromSchemaEnv } from './env'
23
import { boolean, number, object, string } from './schema'
34

@@ -9,6 +10,13 @@ describe('env.spec', () => {
910
ServiceFlag: boolean().default(true),
1011
})
1112

13+
type t = Infer<typeof schema>
14+
expectTypeOf<t>().toMatchObjectType<{
15+
ServiceName: string
16+
servicePort: number
17+
ServiceFlag: boolean
18+
}>()
19+
1220
const r = parseSchemaEnv(schema, {
1321
SERVICE_NAME: 'SomeThing',
1422
SERVICE_PORT: ' 8888 ',

src/common/schema/export-swift.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ describe('swift.spec', () => {
1212
})
1313

1414
type t = Infer<typeof schema>
15-
expectTypeOf<t>().toMatchTypeOf<any>()
15+
expectTypeOf<t>().toMatchObjectType<{
16+
anInt?: number | undefined
17+
aBool: boolean
18+
aNumber: number
19+
aString: string
20+
}>()
1621

1722
const r = schemaExportSwiftStruct(schema, 'Test')
1823

src/common/schema/export-typescript.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ describe('typescript.spec', () => {
1212
})
1313

1414
type t = Infer<typeof schema>
15-
expectTypeOf<t>().toMatchTypeOf<any>()
15+
expectTypeOf<t>().toMatchObjectType<{
16+
anInt?: number | undefined
17+
aBool: boolean
18+
aNumber: number
19+
aString: string
20+
}>()
1621

1722
const r = schemaExportTypescriptInterface(schema, 'Test')
1823

src/common/schema/rpc.spec.ts

Lines changed: 176 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,188 @@
11
import type { Infer } from './schema'
2-
import { func, object, string } from './schema'
2+
import { expectTypeOf } from 'vitest'
3+
import { boolean, func, number, object, rpc, string } from './schema'
34

45
// see https://github.com/colinhacks/zod?tab=readme-ov-file#functions
56

7+
declare module './schema' {
8+
interface TypeProps {
9+
rpcDesc?: string
10+
}
11+
}
12+
613
describe('rpc.spec', () => {
714
it('should do something', async () => {
15+
const rpcFn = object({ rpc: rpc() })
16+
type RpcFn = Infer<typeof rpcFn>
17+
expectTypeOf<RpcFn>().toMatchObjectType<{
18+
rpc: () => undefined
19+
}>()
20+
21+
const rpcFn2 = object({ rpc: rpc(object({
22+
a: number(),
23+
}), string()) })
24+
type RpcFn2 = Infer<typeof rpcFn2>
25+
expectTypeOf<RpcFn2>().toMatchObjectType<{
26+
rpc: (info: { a: number }) => string
27+
}>()
28+
29+
const payloadSchema = object({
30+
id: string(),
31+
method: string(),
32+
params: object({
33+
a: string(),
34+
b: boolean(),
35+
}),
36+
})
37+
38+
type PayloadSchema = Infer<typeof payloadSchema>
39+
40+
expectTypeOf<PayloadSchema>().toMatchObjectType<{
41+
id: string
42+
method: string
43+
params: {
44+
a: string
45+
b: boolean
46+
}
47+
}>()
48+
849
const rpcSchema = object({
9-
echo: func([string()], string()),
50+
echo: func(
51+
[string(), boolean()],
52+
string().optional(),
53+
).props({
54+
rpcDesc: 'Just echo the string',
55+
}),
56+
rpc: rpc(payloadSchema),
57+
noFunc: string(),
1058
})
1159

1260
type RpcRaw = Infer<typeof rpcSchema>
61+
62+
expectTypeOf<RpcRaw>().toMatchObjectType<{
63+
echo: (args_0: string, args_1: boolean) => string | undefined
64+
rpc: (info: {
65+
id: string
66+
method: string
67+
params: {
68+
a: string
69+
b: boolean
70+
}
71+
}) => undefined
72+
noFunc: string
73+
}>()
74+
75+
const api: RpcRaw = {
76+
echo: (a: string, b: boolean) => {
77+
return a + b
78+
},
79+
noFunc: 'noFunc',
80+
rpc(info) {
81+
const _ = info.id
82+
},
83+
}
84+
85+
expect(rpcSchema).toMatchInlineSnapshot(`
86+
TypeObjectClass {
87+
"_check": [Function],
88+
"_object": Object {
89+
"echo": TypeFuncClass {
90+
"_args": Array [
91+
TypeStringClass {
92+
"_check": [Function],
93+
"type": "string",
94+
},
95+
TypeGeneric {
96+
"_check": [Function],
97+
"type": "boolean",
98+
},
99+
],
100+
"_check": [Function],
101+
"_props": Object {
102+
"rpcDesc": "Just echo the string",
103+
},
104+
"_ret": TypeStringClass {
105+
"_check": [Function],
106+
"_optional": true,
107+
"type": "string",
108+
},
109+
"type": "function",
110+
},
111+
"noFunc": TypeStringClass {
112+
"_check": [Function],
113+
"type": "string",
114+
},
115+
"rpc": TypeRpcClass {
116+
"_check": [Function],
117+
"_info": TypeObjectClass {
118+
"_check": [Function],
119+
"_object": Object {
120+
"id": TypeStringClass {
121+
"_check": [Function],
122+
"type": "string",
123+
},
124+
"method": TypeStringClass {
125+
"_check": [Function],
126+
"type": "string",
127+
},
128+
"params": TypeObjectClass {
129+
"_check": [Function],
130+
"_object": Object {
131+
"a": TypeStringClass {
132+
"_check": [Function],
133+
"type": "string",
134+
},
135+
"b": TypeGeneric {
136+
"_check": [Function],
137+
"type": "boolean",
138+
},
139+
},
140+
"type": "object",
141+
},
142+
},
143+
"type": "object",
144+
},
145+
"_ret": TypeGeneric {
146+
"_check": [Function],
147+
"type": "none",
148+
},
149+
"type": "rpc",
150+
},
151+
},
152+
"type": "object",
153+
}
154+
`)
13155
})
156+
157+
// it('should use a schema for useRPC', async () => {
158+
// const rpcSchema = object({
159+
// echo: func(
160+
// [string(), boolean()],
161+
// string().optional(),
162+
// ).props({
163+
// rpcDesc: 'Just echo the string',
164+
// }),
165+
// noFunc: string(),
166+
// })
167+
168+
// type RpcRaw = Infer<typeof rpcSchema>
169+
170+
// expectTypeOf<RpcRaw>().toMatchObjectType<{
171+
// echo: (args_0: string, args_1: boolean) => string | undefined
172+
// noFunc: string
173+
// }>()
174+
175+
// const bob = useRPC<RpcRaw>({
176+
// echo: (a: string, b: boolean) => {
177+
// return a + b
178+
// },
179+
// noFunc: 'noFunc',
180+
// }, {
181+
// post: () => { },
182+
// on: () => { },
183+
// })
184+
185+
// const r = await bob.echo('hello', true)
186+
// expect(r).toEqual('hellotrue')
187+
// })
14188
})

0 commit comments

Comments
 (0)