Skip to content

Commit

Permalink
Merge pull request #104 from oliver-oloughlin/patch/fix-zod-model-ind…
Browse files Browse the repository at this point in the history
…exable-types

Patch/fix zod model indexable types
  • Loading branch information
oliver-oloughlin authored Nov 12, 2023
2 parents b9bd80f + 37fe938 commit 0b72f93
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,10 @@ const flattened = doc.flat()

## Extensions

Additional features outside of the basic functionality provided by `kvdex` .
Additional features outside of the basic functionality provided by `kvdex`.
While the basic functions are dependency-free, extended features may rely on
some specific dependenices to enhance integration. All extensions are found in
the kvdex/ext sub-path.
some dependenices to enhance integration. All extensions are found in the
`kvdex/ext/` sub-path.

### Zod

Expand Down
9 changes: 3 additions & 6 deletions ext/zod/zod_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ export type ZodObjectInsertModel<T extends ZodRawShape> =
* @param schema - Zod schema.
* @returns A model with base type and insert model.
*/
export function zodModel<
const T1 extends KvValue,
const T2 extends ZodType<T1>,
>(
schema: T2,
): Model<T1, ZodInsertModel<T2>> {
export function zodModel<const T extends KvValue>(
schema: ZodType<T>,
): Model<T, ZodInsertModel<ZodType<T>>> {
return {
parse: (data) => schema.parse(data),
}
Expand Down
7 changes: 6 additions & 1 deletion tests/ext/zod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ Deno.test("ext - zod", async (t) => {
await useKv(async (kv) => {
const db = kvdex(kv, {
users: collection(zodModel(UserSchema)),
i_users: indexableCollection(zodModel(UserSchema), { indices: {} }),
i_users: indexableCollection(zodModel(UserSchema), {
indices: {
username: "primary",
age: "secondary",
},
}),
l_users: largeCollection(zodModel(UserSchema)),
})

Expand Down

0 comments on commit 0b72f93

Please sign in to comment.