@superbee/core 0.1.6 → 0.2.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +38 -13
- package/dist/backend.js.map +1 -1
- package/dist/bundle-ops.d.ts +42 -0
- package/dist/bundle-ops.d.ts.map +1 -0
- package/dist/bundle-ops.js +88 -0
- package/dist/bundle-ops.js.map +1 -0
- package/dist/bundle.d.ts +8 -27
- package/dist/bundle.d.ts.map +1 -1
- package/dist/bundle.js +9 -66
- package/dist/bundle.js.map +1 -1
- package/dist/document-field-actions.d.ts +95 -0
- package/dist/document-field-actions.d.ts.map +1 -0
- package/dist/document-field-actions.js +261 -0
- package/dist/document-field-actions.js.map +1 -0
- package/dist/document-mutation.d.ts +46 -2
- package/dist/document-mutation.d.ts.map +1 -1
- package/dist/document-mutation.js +79 -19
- package/dist/document-mutation.js.map +1 -1
- package/dist/document-write-policy.d.ts +0 -1
- package/dist/document-write-policy.d.ts.map +1 -1
- package/dist/document-write-policy.js +3 -2
- package/dist/document-write-policy.js.map +1 -1
- package/dist/engine.d.ts +2 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +2 -1
- package/dist/engine.js.map +1 -1
- package/dist/freshness.d.ts +10 -7
- package/dist/freshness.d.ts.map +1 -1
- package/dist/freshness.js +14 -11
- package/dist/freshness.js.map +1 -1
- package/dist/frontmatter-contract.d.ts +2 -2
- package/dist/frontmatter-contract.js +2 -2
- package/dist/frontmatter.d.ts +3 -1
- package/dist/frontmatter.d.ts.map +1 -1
- package/dist/frontmatter.js +7 -4
- package/dist/frontmatter.js.map +1 -1
- package/dist/heads-digest.d.ts +32 -0
- package/dist/heads-digest.d.ts.map +1 -0
- package/dist/heads-digest.js +37 -0
- package/dist/heads-digest.js.map +1 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-backend.d.ts +175 -0
- package/dist/indexeddb-backend.d.ts.map +1 -0
- package/dist/indexeddb-backend.js +804 -0
- package/dist/indexeddb-backend.js.map +1 -0
- package/dist/journaled-backend.d.ts +238 -0
- package/dist/journaled-backend.d.ts.map +1 -0
- package/dist/journaled-backend.js +88 -0
- package/dist/journaled-backend.js.map +1 -0
- package/dist/kind-field-mutation.d.ts +15 -0
- package/dist/kind-field-mutation.d.ts.map +1 -0
- package/dist/kind-field-mutation.js +160 -0
- package/dist/kind-field-mutation.js.map +1 -0
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +3 -1
- package/dist/kinds.js.map +1 -1
- package/dist/meaningful-change-time.d.ts +6 -6
- package/dist/meaningful-change-time.d.ts.map +1 -1
- package/dist/meaningful-change-time.js +12 -13
- package/dist/meaningful-change-time.js.map +1 -1
- package/dist/memory-backend.d.ts.map +1 -1
- package/dist/memory-backend.js +6 -5
- package/dist/memory-backend.js.map +1 -1
- package/dist/mutation.d.ts.map +1 -1
- package/dist/mutation.js +2 -2
- package/dist/mutation.js.map +1 -1
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +2 -1
- package/dist/page.js.map +1 -1
- package/dist/paths.d.ts +6 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +35 -33
- package/dist/paths.js.map +1 -1
- package/dist/platform.d.ts +232 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +82 -0
- package/dist/platform.js.map +1 -0
- package/dist/recipes.d.ts +3 -1
- package/dist/recipes.d.ts.map +1 -1
- package/dist/recipes.js +4 -4
- package/dist/recipes.js.map +1 -1
- package/dist/remote-backend.d.ts +94 -2
- package/dist/remote-backend.d.ts.map +1 -1
- package/dist/remote-backend.js +280 -7
- package/dist/remote-backend.js.map +1 -1
- package/dist/remote-operations.d.ts +60 -0
- package/dist/remote-operations.d.ts.map +1 -0
- package/dist/remote-operations.js +110 -0
- package/dist/remote-operations.js.map +1 -0
- package/dist/remote.d.ts +3 -1
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +1 -0
- package/dist/remote.js.map +1 -1
- package/dist/sha256.d.ts +21 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +114 -0
- package/dist/sha256.js.map +1 -0
- package/dist/storage.d.ts +8 -2
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +11 -2
- package/dist/storage.js.map +1 -1
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/uncertain-write.d.ts +142 -0
- package/dist/uncertain-write.d.ts.map +1 -0
- package/dist/uncertain-write.js +174 -0
- package/dist/uncertain-write.js.map +1 -0
- package/dist/version-transport.d.ts +7 -0
- package/dist/version-transport.d.ts.map +1 -1
- package/dist/version-transport.js +9 -0
- package/dist/version-transport.js.map +1 -1
- package/dist/versioning.d.ts +9 -3
- package/dist/versioning.d.ts.map +1 -1
- package/dist/versioning.js +14 -10
- package/dist/versioning.js.map +1 -1
- package/package.json +42 -3
package/dist/index.js
CHANGED
|
@@ -51,6 +51,10 @@ export { TRUST_TIERS, TRUST_TIER_FIELD, appendVerificationEvent, latestVerifiedA
|
|
|
51
51
|
// enforced compare-and-swap, per-write actor) and proves the engine is backend-neutral.
|
|
52
52
|
export { FilesystemBackend } from "./backend.js";
|
|
53
53
|
export { MemoryBackend } from "./memory-backend.js";
|
|
54
|
+
// The journaled-backend seam (`journaled-backend.ts`): what an adapter adds to `StorageBackend`
|
|
55
|
+
// so a browser-local working copy's sync runtime can journal intents through it. The IndexedDB
|
|
56
|
+
// adapter implements it behind the `indexeddb-backend` subpath.
|
|
57
|
+
export { IntentHoldConflict, IntentStateConflict } from "./journaled-backend.js";
|
|
54
58
|
// Internal-workspace filesystem arbitration authority. CLI create-only policy reuses this
|
|
55
59
|
// external same-user lock rather than defining a second lock protocol or writing claims into a
|
|
56
60
|
// portable bundle tree.
|
|
@@ -60,11 +64,15 @@ export { withFilesystemMutationLock, FilesystemMutationLockError, filesystemMuta
|
|
|
60
64
|
// in-repo reference server (`@superbee/server`) by the tri-backend contract
|
|
61
65
|
// tests. No CF/D1/production deployment is implied by its presence.
|
|
62
66
|
export { RemoteBackend, RemoteError } from "./remote-backend.js";
|
|
67
|
+
export { headsDigest, isHeadsDigest, sortHeads } from "./heads-digest.js";
|
|
68
|
+
// The uncertain-write transport over `RemoteBackend`: identified document writes plus outcome
|
|
69
|
+
// lookup, the client side of the wire's request identity.
|
|
70
|
+
export { createRemoteOperationTransport, openRemoteOperationTransport, OperationsUnsupportedError } from "./remote-operations.js";
|
|
63
71
|
// Versioning / attribution primitives shared by every adapter: the content-addressed
|
|
64
72
|
// version token, a default actor, and the typed compare-and-swap conflict error.
|
|
65
73
|
// `blobVersion` is the raw-bytes sibling of `contentVersion`/`versionOfBytes` (blobs
|
|
66
74
|
// are hashed directly, never routed through a string/UTF-8 step).
|
|
67
|
-
export { contentVersion, versionOfBytes, blobVersion, defaultActor, VersionConflict, stripETagWrapper, } from "./versioning.js";
|
|
75
|
+
export { contentVersion, versionOfBytes, blobVersion, defaultActor, VersionConflict, isContentVersion, stripETagWrapper, } from "./versioning.js";
|
|
68
76
|
// The ONE versioned-mutation boundary: a shared read-decide-CAS-retry
|
|
69
77
|
// primitive consumed by document, link, and index mutation policies instead of
|
|
70
78
|
// independently hand-rolled loops.
|
|
@@ -89,9 +97,9 @@ export { applyQuerySelectionFilters } from "./query-selection.js";
|
|
|
89
97
|
// Portable, ownership-governed `index.md` projection. Raw reserved-file interop stays on the backend seam.
|
|
90
98
|
export { GENERATED_INDEX_MARKER, IndexProjectionWriteError, planIndexProjection, prepareIndexProjection, applyIndexProjection, } from "./index-projection.js";
|
|
91
99
|
// Pure, unit-testable path / link / note / freshness helpers.
|
|
92
|
-
export { RESERVED_FILENAMES, isReservedFile, conceptIdFromPath, pathFromConceptId, assertSafeConceptId, assertSafeReservedDir, assertSafeBlobKey, toPosix, } from "./paths.js";
|
|
100
|
+
export { RESERVED_FILENAMES, isReservedFile, conceptIdFromPath, pathFromConceptId, assertSafeConceptId, assertSafeReservedDir, assertSafeReservedFilename, compareStorageKeys, assertSafeBlobKey, toPosix, } from "./paths.js";
|
|
93
101
|
export { extractMarkdownLinks, resolveConceptId, relativeHref, parseLinksFromDoc, isExternalHref, } from "./links.js";
|
|
94
|
-
export { parseTimestamp } from "./freshness.js";
|
|
102
|
+
export { parseTimestamp, invalidLegacyTimestamp } from "./freshness.js";
|
|
95
103
|
export { SUPERBEE_UPDATED_BY_FIELD, mutationActorFromFrontmatter, persistMutationActor, } from "./mutation-attribution.js";
|
|
96
104
|
export { parseMarkdown, stringifyDoc, stringifyWithData, normalizeDocumentBodyForStorage, isUsableTimestamp, MalformedDocumentError, } from "./frontmatter.js";
|
|
97
105
|
// Typed input-validation rejection — consumer boundaries branch on the TYPE (CLI: USAGE/exit 2),
|
|
@@ -113,4 +121,7 @@ export { loadKinds } from "./kinds-load.js";
|
|
|
113
121
|
export { EXTENSION_CONTENT_TYPES, extensionOfDocKey, inferContentTypeFromDocKey, inferContentTypeForNewBlob, resolveContentType, DEFAULT_BLOB_CONTENT_TYPE, } from "./content-type.js";
|
|
114
122
|
export { invalidOkfTimestamps, assertAuthoredOkfTimestamps } from "./okf-timestamps.js";
|
|
115
123
|
export { isOkfLifecycleStatus, OKF_LIFECYCLE_STATUSES } from "./okf-lifecycle.js";
|
|
124
|
+
export { prepareDocumentFieldAction, isStandardDocumentSetField, FieldActionError } from "./document-field-actions.js";
|
|
125
|
+
export { prepareDocumentMutationCandidate } from "./document-mutation.js";
|
|
126
|
+
export { KindFieldMutationConflict, prepareKindFieldMutation } from "./kind-field-mutation.js";
|
|
116
127
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AA0BH,iFAAiF;AACjF,OAAO,EACL,UAAU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B,aAAa,EACb,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,qFAAqF;AACrF,oFAAoF;AACpF,gFAAgF;AAChF,2CAA2C;AAC3C,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAA4B,MAAM,qBAAqB,CAAC;AAElH,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,gBAAgB,EAAyM,MAAM,6BAA6B,CAAC;AAC9T,OAAO,EAAE,gCAAgC,EAAmE,MAAM,wBAAwB,CAAC;AAC3I,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAA0B,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IndexedDB-backed {@link JournaledBackend}: the browser-local working copy's first persistent
|
|
3
|
+
* store candidate, sitting behind the same core seam as {@link FilesystemBackend} and
|
|
4
|
+
* {@link MemoryBackend} and proven by the same adapter contract kit, plus the journal seam the
|
|
5
|
+
* sync runtime needs (`journaled-backend.ts`), proven by that kit's journal rows.
|
|
6
|
+
*
|
|
7
|
+
* Storage shape mirrors the filesystem adapter, not the memory adapter: a concept document is
|
|
8
|
+
* stored as its exact OKF-serialized string and parsed on every read, so the read body carries
|
|
9
|
+
* the serializer's normalization (the trailing newline) and the version token is
|
|
10
|
+
* `versionOfBytes(raw)` over the same bytes the disk copy would hold. Reserved files are stored
|
|
11
|
+
* as raw strings and blobs as raw bytes, both content-addressed with the shared primitives, so a
|
|
12
|
+
* document, reserved file, or blob carries one token on disk, in memory, and in the browser.
|
|
13
|
+
*
|
|
14
|
+
* Compare-and-swap is one IndexedDB readwrite transaction per mutation: the current record is
|
|
15
|
+
* read, compared, and replaced (or the transaction aborted with a {@link VersionConflict}) before
|
|
16
|
+
* the transaction commits. IndexedDB serializes readwrite transactions that overlap on a store,
|
|
17
|
+
* so two adapter instances (two tabs, two workers) over the same database cannot both win a
|
|
18
|
+
* conditional write. A write resolves only after the transaction's `complete` event, which is
|
|
19
|
+
* the point a local-save indicator may follow. That is a commit promise, not a power-loss
|
|
20
|
+
* promise: the browser decides when committed pages reach stable storage.
|
|
21
|
+
*
|
|
22
|
+
* Two further stores serve the working copy's synchronization: `intents` journals every local
|
|
23
|
+
* write as a pending-change intent committed in the same transaction as the document record
|
|
24
|
+
* ({@link IndexedDbBackend.writeJournaled}), and `meta` holds opaque key-value rows such as the
|
|
25
|
+
* bootstrap marker and per-document shared bases. The adapter owns the transaction mechanics;
|
|
26
|
+
* what the rows mean belongs to the sync component that writes them, and what the verbs
|
|
27
|
+
* promise is stated once on the seam.
|
|
28
|
+
*
|
|
29
|
+
* This module imports no Node builtin so it bundles for the browser; the IndexedDB factory is
|
|
30
|
+
* injectable so a Node test can supply an in-memory implementation without touching globals.
|
|
31
|
+
*/
|
|
32
|
+
import { type IntentPatch, type IntentRecord, type JournaledBackend, type JournaledDeleteOptions, type JournaledDeleteResult, type JournaledReadResult, type JournaledWriteOptions, type MetaRecord } from "./journaled-backend.js";
|
|
33
|
+
import type { OperationState } from "./uncertain-write.js";
|
|
34
|
+
import type { BlobKey, ConceptId, DeleteOptions, OkfDocument, ReadBlobResult, ReadResult, ReservedFilename, ReservedReadResult, StorageCapabilities, Version, VersionInfo, WriteOptions } from "./types.js";
|
|
35
|
+
export { IntentHoldConflict, IntentStateConflict } from "./journaled-backend.js";
|
|
36
|
+
export type { IntentPatch, IntentRecord, JournaledDeleteOptions, JournaledDeleteResult, JournaledReadResult, JournaledWriteOptions, MetaRecord, NewIntentRecord } from "./journaled-backend.js";
|
|
37
|
+
type Handler = ((this: any, event: any) => any) | null;
|
|
38
|
+
export interface IdbRequestLike<T = unknown> {
|
|
39
|
+
readonly result: T;
|
|
40
|
+
readonly error: unknown;
|
|
41
|
+
onsuccess: Handler;
|
|
42
|
+
onerror: Handler;
|
|
43
|
+
}
|
|
44
|
+
export interface IdbOpenRequestLike extends IdbRequestLike<IdbDatabaseLike> {
|
|
45
|
+
onupgradeneeded: Handler;
|
|
46
|
+
onblocked: Handler;
|
|
47
|
+
readonly transaction: IdbTransactionLike | null;
|
|
48
|
+
}
|
|
49
|
+
export interface IdbObjectStoreLike {
|
|
50
|
+
get(key: string): IdbRequestLike;
|
|
51
|
+
getAll(): IdbRequestLike<unknown[]>;
|
|
52
|
+
getAllKeys(): IdbRequestLike<unknown[]>;
|
|
53
|
+
count(key: string): IdbRequestLike<number>;
|
|
54
|
+
put(value: unknown): IdbRequestLike;
|
|
55
|
+
delete(key: string): IdbRequestLike;
|
|
56
|
+
}
|
|
57
|
+
export interface IdbTransactionLike {
|
|
58
|
+
objectStore(name: string): IdbObjectStoreLike;
|
|
59
|
+
abort(): void;
|
|
60
|
+
readonly error: unknown;
|
|
61
|
+
oncomplete: Handler;
|
|
62
|
+
onerror: Handler;
|
|
63
|
+
onabort: Handler;
|
|
64
|
+
}
|
|
65
|
+
export interface IdbDatabaseLike {
|
|
66
|
+
readonly version: number;
|
|
67
|
+
readonly objectStoreNames: {
|
|
68
|
+
contains(name: string): boolean;
|
|
69
|
+
readonly length: number;
|
|
70
|
+
};
|
|
71
|
+
createObjectStore(name: string, options?: {
|
|
72
|
+
keyPath?: string;
|
|
73
|
+
}): unknown;
|
|
74
|
+
transaction(storeNames: string | string[], mode?: "readonly" | "readwrite"): IdbTransactionLike;
|
|
75
|
+
close(): void;
|
|
76
|
+
onversionchange: Handler;
|
|
77
|
+
}
|
|
78
|
+
export interface IdbFactoryLike {
|
|
79
|
+
open(name: string, version?: number): IdbOpenRequestLike;
|
|
80
|
+
}
|
|
81
|
+
export interface IndexedDbBackendOptions {
|
|
82
|
+
/** The IndexedDB database holding this working copy; one bundle per database. */
|
|
83
|
+
databaseName: string;
|
|
84
|
+
/** The factory to open it with. Defaults to the host's global `indexedDB`. */
|
|
85
|
+
indexedDB?: IdbFactoryLike;
|
|
86
|
+
}
|
|
87
|
+
/** The database does not carry this adapter's schema and the adapter refuses to touch it. */
|
|
88
|
+
export declare class IndexedDbSchemaError extends Error {
|
|
89
|
+
readonly name = "IndexedDbSchemaError";
|
|
90
|
+
}
|
|
91
|
+
/** Bumping this requires a migration in `upgrade`; the handler refuses any other older layout. */
|
|
92
|
+
export declare const INDEXEDDB_SCHEMA_VERSION = 1;
|
|
93
|
+
/**
|
|
94
|
+
* A persistent browser-local OKF store implementing the {@link JournaledBackend} contract over
|
|
95
|
+
* IndexedDB. One instance per bundle per JavaScript realm; several instances over the same
|
|
96
|
+
* database name are peers whose conditional writes are serialized by the database.
|
|
97
|
+
*/
|
|
98
|
+
export declare class IndexedDbBackend implements JournaledBackend {
|
|
99
|
+
#private;
|
|
100
|
+
/**
|
|
101
|
+
* What a resolved write promises: the IndexedDB transaction reported `complete`. Whether the
|
|
102
|
+
* committed pages survive power loss is the browser's and the operating system's decision.
|
|
103
|
+
*/
|
|
104
|
+
readonly durability: "transaction-committed";
|
|
105
|
+
constructor(options: IndexedDbBackendOptions);
|
|
106
|
+
/** Whether an IndexedDB factory is reachable, so a caller can fall back to another store. */
|
|
107
|
+
static available(indexedDB?: IdbFactoryLike): boolean;
|
|
108
|
+
/** The database name this adapter opens. */
|
|
109
|
+
get databaseName(): string;
|
|
110
|
+
capabilities(): StorageCapabilities;
|
|
111
|
+
/** Release the database handle. The next operation reopens it lazily. */
|
|
112
|
+
close(): void;
|
|
113
|
+
read(id: ConceptId): Promise<ReadResult>;
|
|
114
|
+
readMany(ids: ConceptId[]): Promise<ReadResult[]>;
|
|
115
|
+
write(id: ConceptId, doc: OkfDocument, options?: WriteOptions): Promise<Version>;
|
|
116
|
+
delete(id: ConceptId, options?: DeleteOptions): Promise<boolean>;
|
|
117
|
+
exists(id: ConceptId): Promise<boolean>;
|
|
118
|
+
list(prefix?: string): Promise<ConceptId[]>;
|
|
119
|
+
versions(id: ConceptId): Promise<VersionInfo[]>;
|
|
120
|
+
readReserved(dir: string, name: ReservedFilename): Promise<ReservedReadResult | null>;
|
|
121
|
+
writeReserved(dir: string, name: ReservedFilename, content: string, options?: WriteOptions): Promise<Version>;
|
|
122
|
+
/**
|
|
123
|
+
* One transaction over documents, intents, and meta: the document compare-and-swap of
|
|
124
|
+
* {@link write}, plus (optionally) deleting a superseded intent, recording a new intent for
|
|
125
|
+
* the written bytes, and putting meta rows. Every step is conditional on every other: a
|
|
126
|
+
* failed document CAS records no intent, and a superseded intent whose state moved fails the
|
|
127
|
+
* whole write with {@link IntentStateConflict} so the caller composes against fresh state.
|
|
128
|
+
* With `requireSettled`, an unsettled intent on the target fails it with
|
|
129
|
+
* {@link IntentHoldConflict} before the document is touched.
|
|
130
|
+
*/
|
|
131
|
+
writeJournaled(id: ConceptId, doc: OkfDocument, options?: JournaledWriteOptions): Promise<{
|
|
132
|
+
version: Version;
|
|
133
|
+
raw: string;
|
|
134
|
+
intent: IntentRecord | null;
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* One transaction over documents, intents, and meta: the document compare-and-swap of
|
|
138
|
+
* {@link delete}, plus putting and removing meta rows. With `requireSettled`, an unsettled
|
|
139
|
+
* intent on the target refuses it before anything is touched: a rejection with
|
|
140
|
+
* {@link IntentHoldConflict}, or with `onHeld` the `held` outcome whose meta rows are put in
|
|
141
|
+
* this same transaction, so the hold the caller acts on is the one that refused it. An absent
|
|
142
|
+
* target resolves `absent` with the meta changes applied, as {@link delete} answers absence
|
|
143
|
+
* with `false` even under a compare-and-swap.
|
|
144
|
+
*/
|
|
145
|
+
deleteJournaled(id: ConceptId, options?: JournaledDeleteOptions): Promise<JournaledDeleteResult>;
|
|
146
|
+
/**
|
|
147
|
+
* The document, every intent targeting it, and the named meta rows, from ONE readonly
|
|
148
|
+
* transaction over documents, reserved, intents, and meta. A caller deriving where a document
|
|
149
|
+
* stands (its bytes against its shared base and its journal) reads them here so a write in
|
|
150
|
+
* another realm between separate reads can never show it a document of one moment beside a
|
|
151
|
+
* journal of another; with this snapshot a mismatch is a genuine working-copy defect.
|
|
152
|
+
*/
|
|
153
|
+
readWithJournal(id: ConceptId, options?: {
|
|
154
|
+
meta?: readonly string[];
|
|
155
|
+
}): Promise<JournaledReadResult>;
|
|
156
|
+
/** Intents in local commit order, optionally restricted to one or more states. */
|
|
157
|
+
listIntents(state?: OperationState | readonly OperationState[]): Promise<IntentRecord[]>;
|
|
158
|
+
readIntent(requestId: string): Promise<IntentRecord | undefined>;
|
|
159
|
+
/**
|
|
160
|
+
* Compare-and-swap on an intent's `state`: the patch applies only while the record is in
|
|
161
|
+
* `expectedState`, together with any meta rows, in one transaction. A different state or a
|
|
162
|
+
* missing record rejects with {@link IntentStateConflict} and writes nothing.
|
|
163
|
+
*/
|
|
164
|
+
updateIntent(requestId: string, expectedState: OperationState, patch: IntentPatch, options?: {
|
|
165
|
+
meta?: MetaRecord[];
|
|
166
|
+
}): Promise<IntentRecord>;
|
|
167
|
+
readMeta<T = unknown>(key: string): Promise<T | undefined>;
|
|
168
|
+
writeMeta(key: string, value: unknown): Promise<void>;
|
|
169
|
+
readBlob(key: BlobKey): Promise<ReadBlobResult | null>;
|
|
170
|
+
writeBlob(key: BlobKey, bytes: Uint8Array, contentType?: string, options?: WriteOptions): Promise<Version>;
|
|
171
|
+
deleteBlob(key: BlobKey, options?: DeleteOptions): Promise<boolean>;
|
|
172
|
+
existsBlob(key: BlobKey): Promise<boolean>;
|
|
173
|
+
listBlobs(prefix?: string): Promise<BlobKey[]>;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=indexeddb-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-backend.d.ts","sourceRoot":"","sources":["../src/indexeddb-backend.ts"],"names":[],"mappings":"AAAA;;;;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