Skip to content

Commit

Permalink
fix: correctly infer schema type (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-oloughlin authored Nov 20, 2024
1 parent 2f4c183 commit 9d1bdbf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@olli/kvdex",
"version": "3.0.0",
"version": "3.0.1",
"exports": {
".": "./mod.ts",
"./zod": "./src/ext/zod/mod.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/kvdex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ import { AtomicWrapper } from "./atomic_wrapper.ts";
* @param schemaDefinition - The schema definition used to build collections and create the database schema.
* @returns A Kvdex instance with attached schema.
*/
export function kvdex<const T extends KvdexOptions>(
options: T,
): Kvdex<Schema<T["schema"]>> & Schema<T["schema"]> {
export function kvdex<const TSchema extends SchemaDefinition>(
options: KvdexOptions<TSchema>,
): Kvdex<Schema<TSchema>> & Schema<TSchema> {
// Set listener activated flag and queue handlers map
let listener: Promise<void>;
const queueHandlers = new Map<string, QueueMessageHandler<KvValue>[]>();
Expand Down Expand Up @@ -117,7 +117,7 @@ export function kvdex<const T extends KvdexOptions>(
options.kv,
queueHandlers,
idempotentListener,
) as Schema<T["schema"]>;
) as Schema<TSchema>;

// Create KvDex object
const db = new Kvdex(
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,12 @@ export type Schema<T extends SchemaDefinition | undefined> = T extends undefined
};

/** Database options */
export type KvdexOptions = {
export type KvdexOptions<T extends SchemaDefinition> = {
/** The KV instance that will power the database. */
kv: DenoKv;

/** Schema definition containing the database collections */
schema?: SchemaDefinition;
schema?: T;
};

/*******************/
Expand Down

0 comments on commit 9d1bdbf

Please sign in to comment.