libshv-js 3.2.1 → 3.2.3
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/package.json +1 -1
- package/src/rpcvalue.ts +3 -3
- package/src/zod.ts +7 -6
package/package.json
CHANGED
package/src/rpcvalue.ts
CHANGED
|
@@ -109,17 +109,17 @@ const isShvMap = (x: RpcValue): x is ShvMap => typeof x === 'object' && (x as Sh
|
|
|
109
109
|
|
|
110
110
|
const isIMap = (x: RpcValue): x is IMap => typeof x === 'object' && (x as IMap)[shvMapType] === 'imap';
|
|
111
111
|
|
|
112
|
-
const makeMetaMap = <T extends Record<string | number, RpcValue> = Record<string | number, RpcValue>>(x:
|
|
112
|
+
const makeMetaMap = <T extends Record<string | number, RpcValue> = Record<string | number, RpcValue>, U extends Record<number, RpcValue> = Omit<T, typeof shvMapType>>(x: U = {} as U): MetaMap<U> => ({
|
|
113
113
|
...x,
|
|
114
114
|
[shvMapType]: 'metamap',
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
const makeIMap = <T extends Record<number, RpcValue> = Record<number, RpcValue>>(x:
|
|
117
|
+
const makeIMap = <T extends Record<number, RpcValue> = Record<number, RpcValue>, U extends Record<number, RpcValue> = Omit<T, typeof shvMapType>>(x: U = {} as U): IMap<U> => ({
|
|
118
118
|
...x,
|
|
119
119
|
[shvMapType]: 'imap',
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
const makeMap = <T extends Record<string, RpcValue> = Record<string, RpcValue>>(x:
|
|
122
|
+
const makeMap = <T extends Record<string, RpcValue> = Record<string, RpcValue>, U extends Record<string, RpcValue> = Omit<T, typeof shvMapType>>(x: U = {} as U): ShvMap<U> => ({
|
|
123
123
|
...x,
|
|
124
124
|
[shvMapType]: 'map',
|
|
125
125
|
});
|
package/src/zod.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {z, type ZodType} from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import {Int, shvMapType, UInt} from './rpcvalue';
|
|
3
3
|
|
|
4
|
-
export const map = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.
|
|
5
|
-
export const recmap = <T extends ZodType<any, any, any>>(schema: T) => z.
|
|
6
|
-
export const imap = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.
|
|
7
|
-
|
|
8
|
-
export const
|
|
4
|
+
export const map = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.object(schema).and(z.object({[shvMapType]: z.literal('map')}));
|
|
5
|
+
export const recmap = <T extends ZodType<any, any, any>>(schema: T) => z.record(z.string(), schema).and(z.object({[shvMapType]: z.literal('map')}));
|
|
6
|
+
export const imap = <T extends Record<string, ZodType<any, any, any>>>(schema: T) => z.object(schema).and(z.object({[shvMapType]: z.literal('imap')}));
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- Zod needs the default argument, otherwise it'll infer as Int<unknown>
|
|
8
|
+
export const int = () => z.instanceof(Int<number>);
|
|
9
|
+
export const uint = () => z.instanceof(UInt);
|
|
9
10
|
|
|
10
11
|
export * from 'zod';
|