Skip to main content

KeyworkDocumentReference

Overview

Creates an instance associated with specific document within a Cloudflare KV.

Usage

import { KeyworkDocumentReference } from 'keywork/collections'

Type parameters

NameType
ExpectedTypeextends DeserializationTypes

Constructors

constructor

new KeyworkDocumentReference

new KeyworkDocumentReference<ExpectedType>(kvNamespace, relativeDocPath, parentCollection?)

Type parameters

NameType
ExpectedTypeextends {}

Parameters

NameTypeDescription
kvNamespaceKVNamespace<string>
relativeDocPathstring
parentCollection?KeyworkCollection<ExpectedType>-

Defined in

collections/KeyworkDocumentReference.ts:64

Properties

absoluteDocPath

readonly absoluteDocPath: `string`

A POSIX-style, absolute path to a document.

Defined in

collections/KeyworkDocumentReference.ts:62

kvNamespace

protected readonly kvNamespace: `KVNamespace<string>`

The KV namespace binding provided by the parent Worker.

Defined in

collections/KeyworkDocumentReference.ts:66

parentCollection

protected optional readonly parentCollection: [`KeyworkCollection<`ExpectedType`>`](KeyworkCollection.mdx)

Defined in

collections/KeyworkDocumentReference.ts:69

relativeDocPath

readonly relativeDocPath: `string`

A POSIX-style, relative path to a document from a parent collection

Defined in

collections/KeyworkDocumentReference.ts:59

Methods

fetchSnapshot

fetchSnapshot

(options?): `Promise<[`KeyworkDocumentSnapshot<`ExpectedType`>`](../types/KeyworkDocumentSnapshot.mdx)>`

Attempts to fetch a KeyworkDocumentSnapshot associated with the docPath.

If the deserializeAs option is not set, the type will attempt to be inferred from the parent collection's known metadata.

Parameters

NameType
options?KeyworkDocumentFetchOptions

Returns

Promise<[KeyworkDocumentSnapshot<ExpectedType>](/modules/collections/types/KeyworkDocumentSnapshot)>

Defined in

collections/KeyworkDocumentReference.ts:83

patchValue

patchValue

patchValue<E>(nextValue, options?, snapshot?, deepMergeOptions?): `Promise<[`KeyworkDocumentReference<`ExpectedType`>`](KeyworkDocumentReference.mdx)>`

Updates the data associated with this document's path.

Type parameters

NameType
EExpectedType

Parameters

NameTypeDescription
nextValuePartial<E>
options?PutOrPatchOptions-
snapshot?KeyworkDocumentSnapshot<E>
deepMergeOptions?any

Returns

Promise<[KeyworkDocumentReference<ExpectedType>](/modules/collections/classes/KeyworkDocumentReference)>

Defined in

collections/KeyworkDocumentReference.ts:178

putValue

putValue

putValue<E>(nextValue, putOptions?): `Promise<[`KeyworkDocumentReference<`ExpectedType`>`](KeyworkDocumentReference.mdx)>`

Overwrites the entire entity if it already exists, and creates a new resource if it doesn’t exist.

Type parameters

NameType
EExpectedType

Parameters

NameType
nextValuePartial<E>
putOptions?PutOrPatchOptions

Returns

Promise<[KeyworkDocumentReference<ExpectedType>](/modules/collections/classes/KeyworkDocumentReference)>

Defined in

collections/KeyworkDocumentReference.ts:126