Skip to content

TypeScript API / laikacms/documents / DocumentsRepository

Abstract Class: DocumentsRepository ​

Extended by ​

Constructors ​

Constructor ​

ts
new DocumentsRepository(): DocumentsRepository;

Returns ​

DocumentsRepository

Methods ​

acquireLock() ​

ts
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 ​

ParameterType
keystring
owner{ id: string; name: string; }
owner.idstring
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">; }>


createDocument() ​

ts
abstract createDocument(create): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: "published";
  type: "published";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
create{ content: { [key: string]: any; }; key: string; language: string; status: "published"; type: "published"; }
create.content{ [key: string]: any; }
create.keystring
create.languagestring
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; }>


createRevision() ​

ts
abstract createRevision(create): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt: string;
  key: string;
  language: string;
  revision: string;
  type: "revision";
  updatedAt?: string;
}>;

Parameters ​

ParameterType
create{ content: { [key: string]: any; }; key: string; language: string; revision: string; type: "revision"; }
create.content{ [key: string]: any; }
create.keystring
create.languagestring
create.revisionstring
create.type"revision"

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt: string; key: string; language: string; revision: string; type: "revision"; updatedAt?: string; }>


createUnpublished() ​

ts
abstract createUnpublished(create): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: string;
  type: "unpublished";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
create{ content: { [key: string]: any; }; key: string; language: string; status: string; type: "unpublished"; }
create.content{ [key: string]: any; }
create.keystring
create.languagestring
create.statusstring
create.type"unpublished"

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>


deleteDocument() ​

ts
abstract deleteDocument(key): LaikaTask<void>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<void>


deleteUnpublished() ​

ts
abstract deleteUnpublished(key): LaikaTask<void>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<void>


getCapabilities() ​

ts
abstract 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; }; }>


getDocument() ​

ts
abstract getDocument(key): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: "published";
  type: "published";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; }>


getLock() ​

ts
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 ​

ParameterType
keystring

Returns ​

LaikaTask< | { acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; } | null>


getRevision() ​

ts
abstract getRevision(key, revision): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt: string;
  key: string;
  language: string;
  revision: string;
  type: "revision";
  updatedAt?: string;
}>;

Parameters ​

ParameterType
keystring
revisionstring

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt: string; key: string; language: string; revision: string; type: "revision"; updatedAt?: string; }>


getSyncToken() ​

ts
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 ​

ParameterType
options?GetSyncTokenOptions

Returns ​

LaikaTask<string & Brand<"SyncToken">>


getUnpublished() ​

ts
abstract getUnpublished(key): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: string;
  type: "unpublished";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>


listChanges() ​

ts
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 ​

ParameterType
optionsListChangesOptions

Returns ​

LaikaStream<{ deleted: boolean; key: string; version?: string; }, ListChangesDone>


listRecords() ​

ts
abstract 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 ​

ParameterType
optionsListRecordsOptions

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>


listRecordSummaries() ​

ts
abstract 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 ​

ParameterType
optionsListRecordsOptions

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>


listRevisions() ​

ts
abstract listRevisions(key, options): LaikaStream<{
  createdAt?: string;
  key: string;
  language: string;
  revision: string;
  type: "revision-summary";
  updatedAt?: string;
}, LaikaDone>;

Parameters ​

ParameterType
keystring
optionsListRevisionsOptions

Returns ​

LaikaStream<{ createdAt?: string; key: string; language: string; revision: string; type: "revision-summary"; updatedAt?: string; }, LaikaDone>


publish() ​

ts
abstract publish(key): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: "published";
  type: "published";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: "published"; type: "published"; updatedAt?: string; version?: string; }>


refreshLock() ​

ts
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 ​

ParameterType
keystring
tokenstring & Brand<"LockToken">
owner{ id: string; name: string; }
owner.idstring
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">; }>


releaseLock() ​

ts
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 ​

ParameterType
keystring
tokenstring & Brand<"LockToken">

Returns ​

LaikaTask<void>


unpublish() ​

ts
abstract unpublish(key, status): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: string;
  type: "unpublished";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
keystring
statusstring

Returns ​

LaikaTask<{ content: { [key: string]: any; }; createdAt?: string; key: string; language: string; status: string; type: "unpublished"; updatedAt?: string; version?: string; }>


updateDocument() ​

ts
abstract updateDocument(update): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: "published";
  type: "published";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
update{ content?: { [key: string]: any; }; key: string; language?: string; status?: "published"; type?: "published"; }
update.content?{ [key: string]: any; }
update.keystring
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; }>


updateUnpublished() ​

ts
abstract updateUnpublished(update): LaikaTask<{
  content: {
   [key: string]: any;
  };
  createdAt?: string;
  key: string;
  language: string;
  status: string;
  type: "unpublished";
  updatedAt?: string;
  version?: string;
}>;

Parameters ​

ParameterType
update{ content?: { [key: string]: any; }; key: string; language?: string; status?: string; }
update.content?{ [key: string]: any; }
update.keystring
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; }>


withDocumentLock() ​

ts
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:

ts
yield* repo.withDocumentLock(key, owner)(lock =>
  repo.updateDocument(key, update, { precondition: { ifLockHeldBy: lock.token } })
);

Parameters ​

ParameterType
keystring
owner{ id: string; name: string; }
owner.idstring
owner.name?string
options?{ force?: boolean; ttlMs?: number; }
options.force?boolean
options.ttlMs?number

Returns ​

<A, R>(use) => LaikaTask<A, R>

Released under the MIT License.