TypeScript API / laikacms/documents/jsonapi-proxy / DocumentsJsonApiProxyRepository
Class: DocumentsJsonApiProxyRepository
Extends
Constructors
Constructor
new DocumentsJsonApiProxyRepository(options): DocumentsJsonApiProxyRepository;Parameters
| Parameter | Type |
|---|---|
options | DocumentsJsonApiProxyRepositoryOptions |
Returns
DocumentsJsonApiProxyRepository
Overrides
DocumentsRepository.constructor
Methods
acquireLock()
acquireLock(
key,
owner,
options?
): LaikaTask<{
acquiredAt: Utc;
expiresAt: Utc;
key: string;
owner: {
id: string;
name: string;
};
token: string & Brand<"LockToken">;
}>;Take the lock on key, or fail with LockConflictError when someone else holds it (unless force is set, which steals it and mints a new token).
Returns the lock including its token — the only place, besides refreshLock, the token is ever handed out.
Parameters
| Parameter | Type |
|---|---|
key | string |
owner | { id: string; name: string; } |
owner.id | string |
owner.name? | string |
options? | { force?: boolean; ttlMs?: number; } |
options.force? | boolean |
options.ttlMs? | number |
Returns
LaikaTask<{ acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; token: string & Brand<"LockToken">; }>
Overrides
DocumentsRepository.acquireLock
applyOperations()
applyOperations(operations): LaikaTask<readonly DocumentBatchOperationResult[]>;Apply several document mutations in a single POST /operations call instead of one HTTP request per op. Follows the upstream documents-api server's fail-fast contract (ADR-004, LCMS-402): ops apply in order, and the task fails with the first op's error the moment one fails — prior ops in the batch stay applied server-side, but this call surfaces no partial result, matching how every other write method here fails the whole task on any upstream error rather than returning a partial value.
Each per-op result's meta.warnings is re-emitted as a local recoverableError via warningsFromMeta, same as the single-op write methods above.
Parameters
| Parameter | Type |
|---|---|
operations | readonly DocumentBatchOperation[] |
Returns
LaikaTask<readonly DocumentBatchOperationResult[]>
createDocument()
createDocument(create): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: "published";
type: "published";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
create | { content: { [key: string]: any; }; key: string; language: string; status: "published"; type: "published"; } |
create.content | { [key: string]: any; } |
create.key | string |
create.language | string |
create.status | "published" |
create.type | "published" |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; }>
Overrides
DocumentsRepository.createDocument
createRevision()
createRevision(create): LaikaTask<{
content: {
[key: string]: any;
};
createdAt: string;
key: string;
language: string;
revision: string;
type: "revision";
updatedAt?: string;
}>;Parameters
| Parameter | Type |
|---|---|
create | { content: { [key: string]: any; }; key: string; language: string; revision: string; type: "revision"; } |
create.content | { [key: string]: any; } |
create.key | string |
create.language | string |
create.revision | string |
create.type | "revision" |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt: string; key: string; language: string; revision: string; type: "revision"; updatedAt?: string; }>
Overrides
DocumentsRepository.createRevision
createUnpublished()
createUnpublished(create): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: string;
type: "unpublished";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
create | { content: { [key: string]: any; }; key: string; language: string; status: string; type: "unpublished"; } |
create.content | { [key: string]: any; } |
create.key | string |
create.language | string |
create.status | string |
create.type | "unpublished" |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>
Overrides
DocumentsRepository.createUnpublished
deleteDocument()
deleteDocument(key): LaikaTask<void>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<void>
Overrides
DocumentsRepository.deleteDocument
deleteUnpublished()
deleteUnpublished(key): LaikaTask<void>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<void>
Overrides
DocumentsRepository.deleteUnpublished
getCapabilities()
getCapabilities(): LaikaTask<{
changes: | {
description: string;
supported: false;
}
| {
changeFeed: boolean;
description: string;
supported: true;
syncToken: boolean;
};
compatibilityDate: string & Brand<"DocumentsRepositoryCompatibilityDate">;
locks?: | {
description: string;
supported: false;
}
| {
description: string;
scope: "in-process" | "shared";
supported: true;
transactional: boolean;
};
pagination: | {
description: string;
supported: false;
}
| {
description: string;
styles: {
cursor: boolean;
offset: boolean;
page: boolean;
};
supported: true;
};
versionTracking: | {
description: string;
supported: false;
}
| {
description: string;
supported: true;
};
}>;Describe what this repository can do — currently which Pagination shapes it honors. Consumers can branch on this to skip or adapt looping logic.
Returns
LaikaTask<{ changes: | { description: string; supported: false; } | { changeFeed: boolean; description: string; supported: true; syncToken: boolean; }; compatibilityDate: string & Brand<"DocumentsRepositoryCompatibilityDate">; locks?: | { description: string; supported: false; } | { description: string; scope: "in-process" | "shared"; supported: true; transactional: boolean; }; pagination: | { description: string; supported: false; } | { description: string; styles: { cursor: boolean; offset: boolean; page: boolean; }; supported: true; }; versionTracking: | { description: string; supported: false; } | { description: string; supported: true; }; }>
Overrides
DocumentsRepository.getCapabilities
getDocument()
getDocument(key): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: "published";
type: "published";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; }>
Overrides
DocumentsRepository.getDocument
getLock()
getLock(key): LaikaTask<
| {
acquiredAt: Utc;
expiresAt: Utc;
key: string;
owner: {
id: string;
name: string;
};
}
| null>;Read the current lock, or null when the document is free. Returns the public projection: no token, so reading a lock never confers the right to release or write through it.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask< | { acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; } | null>
Overrides
getRevision()
getRevision(key, revision): LaikaTask<{
content: {
[key: string]: any;
};
createdAt: string;
key: string;
language: string;
revision: string;
type: "revision";
updatedAt?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
revision | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt: string; key: string; language: string; revision: string; type: "revision"; updatedAt?: string; }>
Overrides
DocumentsRepository.getRevision
getSyncToken()
getSyncToken(options?): LaikaTask<string & Brand<"SyncToken">>;Return an opaque token for the given scope (a folder, or the whole store when omitted) that changes whenever anything inside the scope changes. Compare tokens only by equality. A git implementation returns the branch head sha; a database implementation returns a sequence or max(updatedAt).
Non-abstract on purpose: existing subclasses stay source-compatible. The base implementation fails with NotImplementedError; check getCapabilities().changes before calling.
Parameters
| Parameter | Type |
|---|---|
options? | GetSyncTokenOptions |
Returns
LaikaTask<string & Brand<"SyncToken">>
Overrides
DocumentsRepository.getSyncToken
getUnpublished()
getUnpublished(key): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: string;
type: "unpublished";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>
Overrides
DocumentsRepository.getUnpublished
listChanges()
listChanges(options): LaikaStream<{
deleted: boolean;
key: string;
version?: string;
}, ListChangesDone>;Enumerate what changed inside the scope since a previously obtained sync token. The done value carries the new sync token to resume from.
Non-abstract on purpose: existing subclasses stay source-compatible. The base implementation fails with NotImplementedError; check getCapabilities().changes before calling.
Parameters
| Parameter | Type |
|---|---|
options | ListChangesOptions |
Returns
LaikaStream<{ deleted: boolean; key: string; version?: string; }, ListChangesDone>
Overrides
DocumentsRepository.listChanges
listRecords()
listRecords(options): LaikaStream<
| {
createdAt?: string;
key: string;
type: "folder";
updatedAt?: string;
}
| {
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: "published";
type: "published";
updatedAt?: string;
version?: string;
}
| {
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: string;
type: "unpublished";
updatedAt?: string;
version?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
options | ListRecordsOptions |
Returns
LaikaStream< | { createdAt?: string; key: string; type: "folder"; updatedAt?: string; } | { content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; } | { content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }, LaikaDone>
Overrides
DocumentsRepository.listRecords
listRecordSummaries()
listRecordSummaries(options): LaikaStream<
| {
createdAt?: string;
key: string;
language: string;
status: "published";
type: "published-summary";
updatedAt?: string;
version?: string;
}
| {
createdAt?: string;
key: string;
language: string;
status: string;
type: "unpublished-summary";
updatedAt?: string;
version?: string;
}
| {
createdAt?: string;
key: string;
type: "folder-summary";
updatedAt?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
options | ListRecordsOptions |
Returns
LaikaStream< | { createdAt?: string; key: string; language: string; status: "published"; type: "published-summary"; updatedAt?: string; version?: string; } | { createdAt?: string; key: string; language: string; status: string; type: "unpublished-summary"; updatedAt?: string; version?: string; } | { createdAt?: string; key: string; type: "folder-summary"; updatedAt?: string; }, LaikaDone>
Overrides
DocumentsRepository.listRecordSummaries
listRevisions()
listRevisions(key, options): LaikaStream<{
createdAt?: string;
key: string;
language: string;
revision: string;
type: "revision-summary";
updatedAt?: string;
}, LaikaDone>;Parameters
| Parameter | Type |
|---|---|
key | string |
options | ListRevisionsOptions |
Returns
LaikaStream<{ createdAt?: string; key: string; language: string; revision: string; type: "revision-summary"; updatedAt?: string; }, LaikaDone>
Overrides
DocumentsRepository.listRevisions
publish()
publish(key): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: "published";
type: "published";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; }>
Overrides
refreshLock()
refreshLock(
key,
token,
owner,
options?
): LaikaTask<{
acquiredAt: Utc;
expiresAt: Utc;
key: string;
owner: {
id: string;
name: string;
};
token: string & Brand<"LockToken">;
}>;Extend the lock the caller already holds.
Lenient by design: if the lock has expired or nobody holds it, this re-acquires rather than failing, because an editor whose refresh was late (a slept laptop, a slow network) should keep editing rather than be thrown out of a document nobody else wants. It fails with LockConflictError only when someone else now holds the lock, which is the case the editor must actually be told about.
owner is required for that re-acquire branch: reviving an expired lock has to attribute it to somebody, and the caller always knows who it is. (ADR-007 sketches this as refreshLock(key, token); the owner is the one piece that signature cannot supply.)
Parameters
| Parameter | Type |
|---|---|
key | string |
token | string & Brand<"LockToken"> |
owner | { id: string; name: string; } |
owner.id | string |
owner.name? | string |
options? | { ttlMs?: number; } |
options.ttlMs? | number |
Returns
LaikaTask<{ acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; token: string & Brand<"LockToken">; }>
Overrides
DocumentsRepository.refreshLock
releaseLock()
releaseLock(key, token): LaikaTask<void>;Release the lock. Only the token-holder can: a non-matching token is a no-op, not an error, so a stale client cannot free someone else's lock and does not need to care that it failed.
Parameters
| Parameter | Type |
|---|---|
key | string |
token | string & Brand<"LockToken"> |
Returns
LaikaTask<void>
Overrides
DocumentsRepository.releaseLock
unpublish()
unpublish(key, status): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: string;
type: "unpublished";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
key | string |
status | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>
Overrides
updateDocument()
updateDocument(update): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: "published";
type: "published";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
update | { content?: { [key: string]: any; }; key: string; language?: string; status?: "published"; type?: "published"; } |
update.content? | { [key: string]: any; } |
update.key | string |
update.language? | string |
update.status? | "published" |
update.type? | "published" |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; }>
Overrides
DocumentsRepository.updateDocument
updateUnpublished()
updateUnpublished(update): LaikaTask<{
content: {
[key: string]: any;
};
createdAt?: string;
key: string;
language: string;
status: string;
type: "unpublished";
updatedAt?: string;
version?: string;
}>;Parameters
| Parameter | Type |
|---|---|
update | { content?: { [key: string]: any; }; key: string; language?: string; status?: string; } |
update.content? | { [key: string]: any; } |
update.key | string |
update.language? | string |
update.status? | string |
Returns
LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>
Overrides
DocumentsRepository.updateUnpublished
withDocumentLock()
withDocumentLock(
key,
owner,
options?
): <A, R>(use) => LaikaTask<A, R>;Run use while holding the lock on key, releasing it afterwards on success, failure, or fiber interruption. The TTL is the backstop for the case no release can run at all, i.e. the whole node dies.
The default implementation is a bracket: mutual exclusion, no rollback of partial writes. A backend with a native transaction overrides this and advertises transactional: true; until then a caller that needs atomic multi-write must check the capability rather than assume.
The token is threaded explicitly, never through ambient context:
yield* repo.withDocumentLock(key, owner)(lock =>
repo.updateDocument(key, update, { precondition: { ifLockHeldBy: lock.token } })
);Parameters
| Parameter | Type |
|---|---|
key | string |
owner | { id: string; name: string; } |
owner.id | string |
owner.name? | string |
options? | { force?: boolean; ttlMs?: number; } |
options.force? | boolean |
options.ttlMs? | number |
Returns
<A, R>(use) => LaikaTask<A, R>