Skip to content

Commit

Permalink
chore: added additional documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-oloughlin committed Mar 6, 2024
1 parent 84eedbd commit 1e14e52
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ _Supported Deno verisons:_ **^1.40.0**
- [flat()](#flat)
- [Extensions](#extensions)
- [Zod](#zod)
- [`zodModel()`](#zodmodel)
- [zodModel()](#zodmodel)
- [Schemas](#schemas)
- [Migrate](#migrate)
- [Script](#script)
Expand Down Expand Up @@ -1241,7 +1241,9 @@ some dependenices to enhance integration. All extensions are found in the

### Zod

#### `zodModel()`
Extended support for Zod. Includes a model parser and schemas for some KV-types.

#### zodModel()

Provides additional compatibility when using zod schemas as models. While zod
schemas can be used as models directly, `zodModel()` properly parses a model
Expand Down
2 changes: 1 addition & 1 deletion ext/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Extended support for Zod. Includes a model parser and schemas for some KV-types.
*
* ## `zodModel()`
* ## zodModel()
*
* Provides additional compatibility when using zod schemas as models. While zod
* schemas can be used as models directly, `zodModel()` properly parses a model
Expand Down
1 change: 1 addition & 0 deletions src/atomic_pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { AtomicSetOptions } from "./types.ts"

/** Holds atomic mutations in a pool until bound to an actual atomic operation */
export class AtomicPool implements Deno.AtomicOperation {
private pool: Array<(op: Deno.AtomicOperation) => Deno.AtomicOperation>

Expand Down
4 changes: 4 additions & 0 deletions src/atomic_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
} from "./constants.ts"
import type { AtomicSetOptions } from "./types.ts"

/**
* Implements the AtomicOperation interface and automatically executes
* batched operations using a dynamic attributes such as count and size.
*/
export class AtomicWrapper implements Deno.AtomicOperation {
private kv: Deno.Kv
private atomics: Deno.AtomicOperation[]
Expand Down
1 change: 1 addition & 0 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function collection<
)
}

/** Represents a collection of documents and provides methods for handling them, alongside queues. */
export class Collection<
const TInput,
const TOutput extends KvValue,
Expand Down
2 changes: 1 addition & 1 deletion src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import type {
} from "./types.ts"
import { isKvObject } from "./utils.ts"

/** Represents a database entry with id, versionstamp and value. */
export class Document<const TOutput extends KvValue> {
readonly id: KvId
readonly versionstamp: KvVersionstamp<TOutput>
readonly value: TOutput

constructor(
// deno-lint-ignore no-explicit-any
model: Model<any, TOutput>,
{ id, versionstamp, value }: DocumentData<TOutput>,
) {
Expand Down
1 change: 1 addition & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Error representing the use, selection or creation of an invalid collection in a given context. */
export class InvalidCollectionError extends Error {
constructor(message?: string, options?: ErrorOptions) {
super(message, options)
Expand Down
1 change: 1 addition & 0 deletions src/kvdex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function kvdex<const T extends SchemaDefinition>(
return Object.assign(db, schema)
}

/** Represents a database instance and contains methods for working on all documents and top-level queues. */
export class Kvdex<const TSchema extends Schema<SchemaDefinition>> {
private kv: Deno.Kv
private schema: TSchema
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,14 @@ export type ParseInputType<TInput, TOutput extends KvValue> = TInput extends
* Contains a parse function, and optionally a __validate function used instead of parse upon reading data.
*/
export type Model<TInput, TOutput extends KvValue> = {
/** A parse function that takes an input type and returns an output type */
parse: (data: TInput) => TOutput

/**
* An optional validate function that takes any input value and returns an output type.
*
* Is used instead of `parse()` upon reading a document.
*/
__validate?: (data: unknown) => TOutput
}

Expand Down

0 comments on commit 1e14e52

Please sign in to comment.