# Interface: NodeRecords

Defined in: [packages/core/src/node/types.ts:565](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L565)

## Methods

### addFile()

```ts
addFile(
   spaceId, 
   bytes, 
   about
): Promise<FileRef>;
```

Defined in: [packages/core/src/node/types.ts:621](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L621)

Seals and keeps a file, giving the reference to put in a body (spec 05 §16.6)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `bytes` | `Uint8Array` |
| `about` | \{ `mime`: `string`; `name?`: `string`; \} |
| `about.mime` | `string` |
| `about.name?` | `string` |

#### Returns

`Promise`\<[`FileRef`](https://minca.dev/api/core/interfaces/FileRef.md)\>

***

### can()

```ts
can(
   spaceId, 
   action, 
   target
): Promise<boolean>;
```

Defined in: [packages/core/src/node/types.ts:619](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L619)

Whether this account may `create` in a collection, or `edit` / `delete` a record; `target` names it

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `action` | `"delete"` \| `"create"` \| `"edit"` |
| `target` | `string` |

#### Returns

`Promise`\<`boolean`\>

***

### contracts()

```ts
contracts(
   spaceId, 
   key, 
   version?
): Promise<RecordContracts | null>;
```

Defined in: [packages/core/src/node/types.ts:577](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L577)

How a record's newest standing version, or the one named, fares under its
collection's contract: `{ version, passes, reason?, pending?, unjudged? }`.
`passes` is false with the failing condition's `else` as `reason`, and null
when the collection has no contract, the version waits on one it cites
(`pending`), or this library can't judge it (`unjudged`, with why)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `key` | `string` |
| `version?` | `string` |

#### Returns

`Promise`\<`RecordContracts` \| `null`\>

***

### delete()

```ts
delete(spaceId, key): Promise<void>;
```

Defined in: [packages/core/src/node/types.ts:615](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L615)

Deletes a record everywhere, by writing a version marked deleted

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `key` | `string` |

#### Returns

`Promise`\<`void`\>

***

### get()

```ts
get<T>(spaceId, key): Promise<NodeRecord<T> | null>;
```

Defined in: [packages/core/src/node/types.ts:569](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L569)

A record's current version, or null when there is none or it was deleted

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-t"></a> `T` | `unknown` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `key` | `string` |

#### Returns

`Promise`\<[`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<`T`\> \| `null`\>

***

### history()

```ts
history<T>(spaceId, key): Promise<readonly NodeRecord<T>[]>;
```

Defined in: [packages/core/src/node/types.ts:617](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L617)

The versions of a record kept whole here, newest first: the current one, or every one in a collection defined with `history: 'all'`

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-t-1"></a> `T` | `unknown` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `key` | `string` |

#### Returns

`Promise`\<readonly [`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<`T`\>[]\>

***

### keyFor()

```ts
keyFor(
   spaceId, 
   name, 
   account?
): Promise<string>;
```

Defined in: [packages/core/src/node/types.ts:579](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L579)

The key `name` has in an account's namespace (this one's by default): where `put(…, { key: name })` writes

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `name` | `string` |
| `account?` | `string` |

#### Returns

`Promise`\<`string`\>

***

### linked()

```ts
linked<T>(
   spaceId, 
   key, 
   options?
): Promise<readonly NodeRecord<T>[]>;
```

Defined in: [packages/core/src/node/types.ts:609](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L609)

The records whose current version points at this one, optionally by role or collection

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-t-2"></a> `T` | `unknown` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `key` | `string` |
| `options?` | \{ `collection?`: `string`; `rel?`: `string`; \} |
| `options.collection?` | `string` |
| `options.rel?` | `string` |

#### Returns

`Promise`\<readonly [`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<`T`\>[]\>

***

### list()

```ts
list<T>(spaceId, options?): Promise<readonly NodeRecord<T>[]>;
```

Defined in: [packages/core/src/node/types.ts:567](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L567)

Current versions, oldest record first; deleted records only with `includeDeleted`

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-t-3"></a> `T` | `unknown` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `options?` | [`ListOptions`](https://minca.dev/api/core/interfaces/ListOptions.md) |

#### Returns

`Promise`\<readonly [`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<`T`\>[]\>

***

### onePerKey()

```ts
onePerKey(
   spaceId, 
   collection, 
   body, 
   options?
): Promise<string | null>;
```

Defined in: [packages/core/src/node/types.ts:581](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L581)

The key a record with this body has under its collection's `onePer`; null when there is none

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `collection` | `string` |
| `body` | `unknown` |
| `options?` | \{ `account?`: `string`; `links?`: readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[]; \} |
| `options.account?` | `string` |
| `options.links?` | readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[] |

#### Returns

`Promise`\<`string` \| `null`\>

***

### put()

#### Call Signature

```ts
put<T>(
   spaceId, 
   collection, 
   body, 
   options?
): Promise<NodeRecord<T>>;
```

Defined in: [packages/core/src/node/types.ts:588](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L588)

Creates a record under a fresh key, or `key` in this account's namespace. Writing a deleted key brings it back.

##### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-t-4"></a> `T` | `unknown` |

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `collection` | `string` |
| `body` | `T` |
| `options?` | \{ `key?`: `string`; `links?`: readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[]; \} |
| `options.key?` | `string` |
| `options.links?` | readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[] |

##### Returns

`Promise`\<[`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<`T`\>\>

#### Call Signature

```ts
put<C>(
   spaceId, 
   collection, 
   body, 
   options?
): Promise<NodeRecord<BodyOf<C>>>;
```

Defined in: [packages/core/src/node/types.ts:595](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L595)

The same, typed by the collection's definition

##### Type Parameters

| Type Parameter |
| ------ |
| <a id="type-parameter-c"></a> `C` *extends* `object` |

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `collection` | `C` |
| `body` | [`BodyOf`](https://minca.dev/api/core/type-aliases/BodyOf.md)\<`C`\> |
| `options?` | \{ `key?`: `string`; `links?`: readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[]; \} |
| `options.key?` | `string` |
| `options.links?` | readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[] |

##### Returns

`Promise`\<[`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<[`BodyOf`](https://minca.dev/api/core/type-aliases/BodyOf.md)\<`C`\>\>\>

***

### query()

```ts
query<C, I>(spaceId, query): Promise<ResultFor<C, I>>;
```

Defined in: [packages/core/src/node/types.ts:632](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L632)

Records matching a query, typed when it names a collection by its definition.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-c-1"></a> `C` *extends* [`CollectionRef`](https://minca.dev/api/core/type-aliases/CollectionRef.md) | - |
| <a id="type-parameter-i"></a> `I` *extends* `Readonly`\<`Record`\<`string`, [`Include`](https://minca.dev/api/core/interfaces/Include.md)\>\> \| `undefined` | `undefined` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `query` | [`Query`](https://minca.dev/api/core/interfaces/Query.md)\<`C`, `I`\> |

#### Returns

`Promise`\<[`ResultFor`](https://minca.dev/api/core/type-aliases/ResultFor.md)\<`C`, `I`\>\>

#### Throws

When the query is malformed, saying what to fix

***

### readFile()

```ts
readFile(spaceId, ref): Promise<Uint8Array<ArrayBufferLike>>;
```

Defined in: [packages/core/src/node/types.ts:627](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L627)

The bytes of a file a body refers to: held here, or fetched from peers or mirrors,
checking every chunk. While nobody has it, it waits and asks again.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `ref` | [`FileRef`](https://minca.dev/api/core/interfaces/FileRef.md) |

#### Returns

`Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>

#### Throws

When no record here names it, when it won't open as named, or when the space closes

***

### update()

```ts
update<T>(
   spaceId, 
   key, 
   body, 
   options?
): Promise<NodeRecord<T>>;
```

Defined in: [packages/core/src/node/types.ts:602](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L602)

Writes the record's next version; links carry over unless given

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-t-5"></a> `T` | `unknown` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `key` | `string` |
| `body` | `T` |
| `options?` | \{ `links?`: readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[]; \} |
| `options.links?` | readonly [`Link`](https://minca.dev/api/core/interfaces/Link.md)[] |

#### Returns

`Promise`\<[`NodeRecord`](https://minca.dev/api/core/interfaces/NodeRecord.md)\<`T`\>\>

***

### watch()

```ts
watch<C, I>(
   spaceId, 
   query, 
   onResult, 
   onError?
): () => void;
```

Defined in: [packages/core/src/node/types.ts:637](https://github.com/leifriksheim/minca/blob/main/core/src/node/types.ts#L637)

Runs a query now and whenever the space's records change; returns a function that stops it

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-c-2"></a> `C` *extends* [`CollectionRef`](https://minca.dev/api/core/type-aliases/CollectionRef.md) | - |
| <a id="type-parameter-i-1"></a> `I` *extends* `Readonly`\<`Record`\<`string`, [`Include`](https://minca.dev/api/core/interfaces/Include.md)\>\> \| `undefined` | `undefined` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `spaceId` | `string` |
| `query` | [`Query`](https://minca.dev/api/core/interfaces/Query.md)\<`C`, `I`\> |
| `onResult` | (`result`) => `void` |
| `onError?` | (`error`) => `void` |

#### Returns

() => `void`
