@framers/agentos-ext-account-sources 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @framers/agentos-ext-account-sources
2
2
 
3
- A person's own accounts as sources. This library defines `AccountSourceConnector` and the `SourceRef` every passage carries, with helpers for line ranges, links, bounded body reads, requests under the shared public-sources limiter and the cache lifetime of a read, and the contracts and pure rules of a durable, resumable synchronization.
3
+ A person's own accounts as sources. This library defines `AccountSourceConnector` and the `SourceRef` every passage carries, with helpers for line ranges, links, bounded body reads, requests under the shared public-sources limiter and the cache lifetime of a read, and the contracts, pure rules and PostgreSQL store of a durable, resumable synchronization.
4
4
 
5
- Install `@framers/agentos-ext-account-sources` with its peer `@framers/agentos` 0.10.40 or later. Node.js 20.19 or later is required. The runtime dependency is `@framers/agentos-ext-public-sources`.
5
+ Install `@framers/agentos-ext-account-sources` with its peer `@framers/agentos` 0.13.134 or later. Node.js 20.19 or later is required. The runtime dependencies are `@framers/agentos-ext-public-sources` and `@framers/sql-storage-adapter`.
6
6
 
7
7
  ## Connector
8
8
 
@@ -184,6 +184,50 @@ The rules are pure and take no lock: the store that commits a cursor reads the s
184
184
 
185
185
  `new SourceSyncFault(code, retryAt?)` carries a fixed failure code as its message (`source_sync_<code>`), never a provider's text, exposes `code` and `retryAt`, and throws `invalid_source_sync_fault` for an unknown code or a `retryAt` that is not a nonnegative safe integer. `assertSourceSyncPolicy(policy)` throws `invalid_source_sync_policy` unless every policy value is a positive safe integer.
186
186
 
187
+ ### The SQL store
188
+
189
+ ```ts
190
+ import { createPostgresAdapter } from '@framers/sql-storage-adapter';
191
+ import { sourceDerivationSchema } from '@framers/agentos/cognition/library';
192
+ import { SqlAccountSourceSyncStore, sourceSyncSchema } from '@framers/agentos-ext-account-sources';
193
+
194
+ const db = createPostgresAdapter({ connectionString: process.env.DATABASE_URL! });
195
+ await db.open();
196
+ // The host's migration runs the DDL; the store never does.
197
+ for (const sql of [...sourceDerivationSchema(), ...sourceSyncSchema()]) await db.exec(sql);
198
+
199
+ const store = new SqlAccountSourceSyncStore<PreparedPassages>(db, { bindings });
200
+ const scope = { tenantId: 'tenant-1', ownerId: 'owner-1', connectionId: 'connection-1' };
201
+ await store.create(scope, policy);
202
+ await store.control(scope, { type: 'connect_started' });
203
+ await store.control(scope, { type: 'grant_ready', use: { searchAskEnabled: true, liveEnabled: false } });
204
+ const handle = await store.claim(scope, 'scheduled'); // null unless the connection is due and free
205
+ ```
206
+
207
+ `SqlAccountSourceSyncStore` keeps each connection's state, policy, open checkpoint, lease and barrier, the cycle's work rows, the provenance of retained sources and the connection's exclusions in the tables `sourceSyncSchema(prefix)` creates: six statements, with a prefix of a lower-case letter and at most 31 lower-case letters, digits or underscores (`agentos_source_sync` unless given). It needs a PostgreSQL adapter with transactions and runs no DDL. Its `fence` is the core `SqlSourceDerivationStore` on the same adapter, over the tables of `sourceDerivationSchema(derivationPrefix)`: every change to an owner's sources runs under that owner's fence, the one that also commits and delivers results derived from them.
208
+
209
+ The host supplies seven bindings. The store calls each inside its own transaction, on the transaction adapter it passes:
210
+
211
+ | Binding | What it does |
212
+ |---|---|
213
+ | `active(tx, owner)` | Answers false for an account that is deleted or being deleted, whose admission is off or whose purge is pending; the store then claims, commits and reactivates nothing for it and answers no source state |
214
+ | `allowance(tx, scope)` | Answers the connection's document and held-character ceilings after unrelated sources, and the remaining indexing balance |
215
+ | `write(tx, scope, dependency, document, prepared)` | Writes the document's text and the host's prepared passages and vectors |
216
+ | `chargeIndexed(tx, scope, characters)` | Charges committed characters to the indexing allowance |
217
+ | `purge(tx, owner, affected)` | Deletes the host's text, passages and vectors in the affected scope |
218
+ | `purgeResults(tx, owner, ids)` | Deletes the host's rows for these derived results |
219
+ | `rebind(tx, scope, generation)` | Moves the connection's host rows to a new generation without changing their content, version or expiry |
220
+
221
+ Provider reads, embedding and model calls run between store calls, never inside a binding.
222
+
223
+ A sync holds a lease. `claim(scope, trigger)` answers a handle only when the owner is active, the `active` binding agrees, no barrier or live lease is set and `sourceSyncDue` holds; `renew(handle)` extends the lease by `leaseMs`; `release(handle, event?)` gives it up, records a deferral or a fixed failure when one is given, and keeps the checkpoint and work for the next claim. `openCycle` opens a checkpoint or answers the one already open, `page` records a page and queues its ids in one transaction (the same page sent again right after answers the same checkpoint; any other stale revision answers null), and `takeWork` marks the next due item attempted before the read. Every call made with a handle checks the owner fence, the lease token and expiry, the generation and the `active` binding in the same transaction, and answers null once any of them has moved on.
224
+
225
+ `applyResult(handle, work, result, prepared)` keeps a `retry` result unresolved. Any other result first removes the source's previous copy and every derived result that depends on it, through the fence. A `document` result then replaces it in the same transaction (host write, indexing charge and provenance) when the source is not excluded and fits: the store ranks this connection's retained sources and the new one by activity time, newest first with ties broken by source id, keeps those inside `maxRetainedDocuments`, `maxHeldCharacters` and the allowance, and removes this connection's other sources, never another connection's. A document that does not fit is recorded as skipped with `document_limit`, `held_limit` or `indexing_limit`, and an excluded one with `excluded`. A failing binding rolls the whole application back. The answer carries a new handle, because each removal advances the owner's fence; later calls use it. `finish` commits the cycle's target cursor once every work item is terminal, counting from the stored work, and `progress` records the counts so far.
226
+
227
+ Controls run with the owner blocked. `control(scope, event, policy?)` applies `connect_started`, `grant_ready`, `pause`, `resume`, `use_changed`, `policy_changed` (with the new policy), `grant_lost` or `disconnect`: it records a content-free barrier and drops the open cycle in one transaction, then completes the barrier and reactivates the owner. Connecting, grant loss and disconnecting remove the connection's sources, their derived results and its exclusions. Pause, resume, a use change and a policy change move retained content to the new generation with its version kept and its expiry never extended, so no result derived before the change can be delivered again; a policy change also removes the sources the new limits leave out and shortens the expiry of the rest to the new window. `exclude(scope, sourceId)` removes one source and keeps a content-free exclusion; `resetExclusions(scope)` clears them. Both raise the generation and clear the cursor. A control other than disconnecting throws `stale_source_sync` while the `active` binding refuses the owner. A barrier left by a failure blocks claims and reactivation until `recoverControl(scope)` completes it, and a lifecycle worker calls it even for a paused connection. `expire(scope, limit)` removes retained sources whose expiry has passed, also while the connection is paused, then the owner's expired derived results; reads refuse an expired source either way.
228
+
229
+ `readCurrent(tx, derivation)` answers the current state of a derivation's sources for the fence's commit and delivery checks, and a connection with a barrier or pending revalidation reads as disconnected. `snapshot(scope)` answers metadata for authenticated controls and `documents(scope)` the retained provenance; neither authorizes delivery. Work rows and barriers hold ids and fixed values only. The documents table holds provenance, message timing and counts, never text; treat it, like the host's own tables, as restricted data for retention and backups.
230
+
187
231
  ## License
188
232
 
189
233
  Apache-2.0. This pack carries a copy of the repository's license.
package/dist/index.d.ts CHANGED
@@ -11,4 +11,7 @@ export * from './cachePolicy.js';
11
11
  /** Durable synchronization contracts and pure state/checkpoint rules. */
12
12
  export * from './sync/types.js';
13
13
  export * from './sync/state.js';
14
+ /** The migration-owned schema and the SQL store that persists synchronization under the owner fence. */
15
+ export { sourceSyncSchema } from './sync/schema.js';
16
+ export { SqlAccountSourceSyncStore, type SourceSyncStoredDocument, type SourceSyncAllowance, type SourceSyncStorageBindings, type SourceSyncStoreOptions, type SourceSyncHandle, type SourceSyncSnapshot, type SourceSyncControl, type SourceSyncApplication, type SourceSyncBarrier, } from './sync/SqlAccountSourceSyncStore.js';
14
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,cAAc,YAAY,CAAC;AAC3B,yDAAyD;AACzD,cAAc,gBAAgB,CAAC;AAC/B,8DAA8D;AAC9D,cAAc,iBAAiB,CAAC;AAChC,oEAAoE;AACpE,cAAc,cAAc,CAAC;AAC7B,0EAA0E;AAC1E,cAAc,kBAAkB,CAAC;AACjC,yEAAyE;AACzE,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,cAAc,YAAY,CAAC;AAC3B,yDAAyD;AACzD,cAAc,gBAAgB,CAAC;AAC/B,8DAA8D;AAC9D,cAAc,iBAAiB,CAAC;AAChC,oEAAoE;AACpE,cAAc,cAAc,CAAC;AAC7B,0EAA0E;AAC1E,cAAc,kBAAkB,CAAC;AACjC,yEAAyE;AACzE,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,wGAAwG;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,yBAAyB,EACzB,KAAK,wBAAwB,EAAE,KAAK,mBAAmB,EAAE,KAAK,yBAAyB,EACvF,KAAK,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAC3E,KAAK,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,GAC3E,MAAM,qCAAqC,CAAC"}
package/dist/index.js CHANGED
@@ -11,4 +11,7 @@ export * from './cachePolicy.js';
11
11
  /** Durable synchronization contracts and pure state/checkpoint rules. */
12
12
  export * from './sync/types.js';
13
13
  export * from './sync/state.js';
14
+ /** The migration-owned schema and the SQL store that persists synchronization under the owner fence. */
15
+ export { sourceSyncSchema } from './sync/schema.js';
16
+ export { SqlAccountSourceSyncStore, } from './sync/SqlAccountSourceSyncStore.js';
14
17
  //# 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,4EAA4E;AAC5E,cAAc,YAAY,CAAC;AAC3B,yDAAyD;AACzD,cAAc,gBAAgB,CAAC;AAC/B,8DAA8D;AAC9D,cAAc,iBAAiB,CAAC;AAChC,oEAAoE;AACpE,cAAc,cAAc,CAAC;AAC7B,0EAA0E;AAC1E,cAAc,kBAAkB,CAAC;AACjC,yEAAyE;AACzE,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,cAAc,YAAY,CAAC;AAC3B,yDAAyD;AACzD,cAAc,gBAAgB,CAAC;AAC/B,8DAA8D;AAC9D,cAAc,iBAAiB,CAAC;AAChC,oEAAoE;AACpE,cAAc,cAAc,CAAC;AAC7B,0EAA0E;AAC1E,cAAc,kBAAkB,CAAC;AACjC,yEAAyE;AACzE,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,wGAAwG;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,yBAAyB,GAI1B,MAAM,qCAAqC,CAAC"}
@@ -0,0 +1,285 @@
1
+ /**
2
+ * @fileoverview The durable source synchronization store on PostgreSQL through `@framers/sql-storage-adapter`:
3
+ * connection state, leases, checkpoints, work rows and the provenance of retained documents, with every change to
4
+ * an owner's content made under that owner's fence from the core derivation store.
5
+ * @module account-sources/sync/SqlAccountSourceSyncStore
6
+ */
7
+ import type { StorageAdapter } from '@framers/sql-storage-adapter';
8
+ import { SqlSourceDerivationStore, type SourceDependency, type SourceDependencyState, type SourceDerivation, type SourceOwnerScope, type SourceInvalidation, type SourceFenceTicket } from '@framers/agentos/cognition/library';
9
+ import type { SourceSyncScope, SourceSyncState, SourceSyncPolicy, SourceSyncLease, SourceSyncTrigger, SourceSyncCheckpoint, SourceSyncCycleInput, SourceSyncPage, SourceSyncWork, SourceSyncDocument, SourceSyncMessageSpan, SourceSyncReadResult, SourceSyncWorkDisposition, SourceSyncTransition } from './types.js';
10
+ /**
11
+ * The provenance kept for one retained source: its dependency, message spans, activity time, character count and
12
+ * content hash, never its text.
13
+ */
14
+ export interface SourceSyncStoredDocument {
15
+ readonly dependency: SourceDependency;
16
+ readonly messages: readonly SourceSyncMessageSpan[];
17
+ readonly activityAt: number;
18
+ readonly characters: number;
19
+ readonly contentHash: string;
20
+ }
21
+ /** The host's limits for one connection, read under the owner fence in the transaction that uses them. */
22
+ export interface SourceSyncAllowance {
23
+ readonly maximumConnectionDocuments: number;
24
+ readonly maximumConnectionHeldCharacters: number;
25
+ readonly additionalIndexedCharacters: number;
26
+ }
27
+ /**
28
+ * The host's table bindings. The store calls each one inside the owner fence, on the transaction adapter it is given
29
+ * and only there; a binding never calls a provider, embeds, generates, delivers over the network or refreshes a grant.
30
+ *
31
+ * @typeParam Prepared - The host's in-memory value for one document, such as its computed passages and vectors.
32
+ */
33
+ export interface SourceSyncStorageBindings<Prepared> {
34
+ /**
35
+ * False for an account that is deleted or being deleted, disabled admission or a pending host purge: the store then
36
+ * claims, commits and reactivates nothing for the owner and answers no source state.
37
+ */
38
+ active(tx: StorageAdapter, scope: SourceOwnerScope): Promise<boolean>;
39
+ /** Absolute ceilings for this connection after subtracting unrelated sources; indexing is the remaining period balance. All writers take the owner fence first. */
40
+ allowance(tx: StorageAdapter, scope: SourceSyncScope): Promise<SourceSyncAllowance>;
41
+ /** Writes the document's content and the prepared value under this dependency, on the given transaction. */
42
+ write(tx: StorageAdapter, scope: SourceSyncScope, dependency: SourceDependency, document: SourceSyncDocument, prepared: Prepared): Promise<void>;
43
+ /** Charges committed sanitized characters to the owner's indexing allowance. */
44
+ chargeIndexed(tx: StorageAdapter, scope: SourceSyncScope, characters: number): Promise<void>;
45
+ /** Removes the host's source content in the affected scope: text, passages and vectors. */
46
+ purge(tx: StorageAdapter, scope: SourceOwnerScope, affected: SourceInvalidation): Promise<void>;
47
+ /** Removes every host row stored for these derived result ids, whole. */
48
+ purgeResults(tx: StorageAdapter, scope: SourceOwnerScope, ids: readonly string[]): Promise<void>;
49
+ /** Moves this connection's host rows to a new generation without changing their content, version or expiry. */
50
+ rebind(tx: StorageAdapter, scope: SourceSyncScope, generation: number): Promise<void>;
51
+ }
52
+ /** The store's table prefixes, clock and host bindings. */
53
+ export interface SourceSyncStoreOptions<Prepared> {
54
+ /** Prefix of the synchronization tables, the one given to `sourceSyncSchema`; `agentos_source_sync` unless given. */
55
+ readonly tablePrefix?: string;
56
+ /** Prefix of the core derivation store's tables, the one given to `sourceDerivationSchema`; core's default unless given. */
57
+ readonly derivationPrefix?: string;
58
+ /** Current time as integer UTC epoch milliseconds; `Date.now` unless given. */
59
+ readonly clock?: () => number;
60
+ /** The host's table bindings. */
61
+ readonly bindings: SourceSyncStorageBindings<Prepared>;
62
+ }
63
+ /**
64
+ * A claimed lease with the owner fence ticket it was claimed under. A source change advances the owner's fence, so
65
+ * `applyResult` answers a handle with the new ticket: later calls use that handle.
66
+ */
67
+ export interface SourceSyncHandle {
68
+ readonly ticket: SourceFenceTicket;
69
+ readonly lease: SourceSyncLease;
70
+ }
71
+ /**
72
+ * The transitions a host control applies: connecting, a ready or lost grant, pause, resume, a use or policy change,
73
+ * and disconnecting.
74
+ */
75
+ export type SourceSyncControl = Extract<SourceSyncTransition, {
76
+ type: 'connect_started' | 'grant_ready' | 'pause' | 'resume' | 'use_changed' | 'policy_changed' | 'grant_lost' | 'disconnect';
77
+ }>;
78
+ /**
79
+ * A control's durable, content-free record of the work it still owes: purging the connection, pruning it to its
80
+ * limits, excluding one source, or completing a rebind or a reset. No claim succeeds and the owner is not reactivated
81
+ * while one is set; `recoverControl` completes it.
82
+ */
83
+ export interface SourceSyncBarrier {
84
+ readonly token: string;
85
+ readonly action: 'rebind' | 'purge' | 'prune' | 'exclude' | 'reset';
86
+ readonly sourceId: string | null;
87
+ }
88
+ /**
89
+ * A connection's metadata for authenticated host controls: state, policy, open checkpoint, barrier and last
90
+ * reconciliation time.
91
+ */
92
+ export interface SourceSyncSnapshot {
93
+ readonly state: SourceSyncState;
94
+ readonly policy: SourceSyncPolicy;
95
+ readonly checkpoint: SourceSyncCheckpoint | null;
96
+ readonly barrier: SourceSyncBarrier | null;
97
+ readonly lastReconcileAt: number | null;
98
+ }
99
+ /** What applying one read result answers: the handle to use next and the work's disposition. */
100
+ export interface SourceSyncApplication {
101
+ readonly handle: SourceSyncHandle;
102
+ readonly disposition: SourceSyncWorkDisposition;
103
+ }
104
+ /**
105
+ * Durable synchronization state for account sources on PostgreSQL. Every change to an owner's content runs under
106
+ * that owner's fence (`fence`), and a change made with a handle checks its lease, generation and host liveness in
107
+ * the same transaction. Applying a source purges its old copy and every derived result that depends on it before the
108
+ * replacement is written. Provider reads, embedding and model calls stay outside the store. The constructor runs no
109
+ * DDL: the host's migration runs `sourceSyncSchema` and core's `sourceDerivationSchema` first.
110
+ *
111
+ * @typeParam Prepared - The host's in-memory value for one document, passed through to its `write` binding.
112
+ */
113
+ export declare class SqlAccountSourceSyncStore<Prepared = unknown> {
114
+ private readonly db;
115
+ private readonly options;
116
+ private readonly t;
117
+ private readonly clock;
118
+ /**
119
+ * The owner fence. The same instance commits and delivers derived results and fences account deletion. Host code
120
+ * never activates an owner through it with a callback that answers true unconditionally.
121
+ */
122
+ readonly fence: SqlSourceDerivationStore;
123
+ /**
124
+ * @param db - A PostgreSQL adapter with transactions.
125
+ * @param options - Table prefixes, clock and the host's bindings.
126
+ * @throws {Error} `source_sync_requires_postgres` for another kind of adapter or one without transactions, and
127
+ * `invalid_source_sync_prefix` or core's `invalid_derivation_table_prefix` for a malformed prefix.
128
+ */
129
+ constructor(db: StorageAdapter, options: SourceSyncStoreOptions<Prepared>);
130
+ private now;
131
+ private fenceOn;
132
+ private row;
133
+ private save;
134
+ private clearCycle;
135
+ private activate;
136
+ /**
137
+ * Creates the connection in `not_connected` and activates its owner when the host's `active` binding allows it and
138
+ * no barrier of the owner is pending; otherwise nothing changes. An existing connection is kept as it is.
139
+ *
140
+ * @throws {Error} `invalid_source_sync_policy` for an invalid policy and `invalid_source_sync_state` for an
141
+ * invalid scope.
142
+ */
143
+ create(scope: SourceSyncScope, policy: SourceSyncPolicy): Promise<void>;
144
+ /** Metadata for authenticated host controls only; no content-delivery authorization. */
145
+ snapshot(scope: SourceSyncScope): Promise<SourceSyncSnapshot | null>;
146
+ /** Operator scheduler only. The claim performs fresh host and owner checks. */
147
+ scopes(after?: SourceSyncScope | null, limit?: number): Promise<readonly SourceSyncScope[]>;
148
+ /**
149
+ * Connections whose next sync time has come, with no barrier and no live lease, earliest first.
150
+ *
151
+ * @param limit - At most this many, an integer from 1 to 1,000.
152
+ * @throws {Error} `invalid_sync_batch` for another limit.
153
+ */
154
+ due(limit?: number): Promise<readonly SourceSyncScope[]>;
155
+ /**
156
+ * Claims the connection's lease for one sync. The owner must be active, the host's `active` binding must allow it,
157
+ * no barrier or live lease may be set and the connection must be due for `trigger`; a manual claim records the
158
+ * request.
159
+ *
160
+ * @returns The handle, or null.
161
+ */
162
+ claim(scope: SourceSyncScope, trigger: SourceSyncTrigger): Promise<SourceSyncHandle | null>;
163
+ private checked;
164
+ private withHandle;
165
+ /**
166
+ * Extends a live lease by the policy's `leaseMs`.
167
+ *
168
+ * @returns The renewed handle, or null when the lease, its generation or the owner fence has moved on.
169
+ */
170
+ renew(h: SourceSyncHandle): Promise<SourceSyncHandle | null>;
171
+ /**
172
+ * Opens a cycle's durable checkpoint and drops the previous cycle's work, or answers the checkpoint already open.
173
+ * An incremental cycle starts from the committed cursor. With `replaceExpiredHistory`, a `recovery` cycle replaces
174
+ * the open one. The cutoff defaults to the connection's last change.
175
+ *
176
+ * @returns The checkpoint, or null for a stale handle or an incremental cycle from another cursor.
177
+ * @throws {SourceSyncFault} `invalid_response` for a cutoff in the future or a replacement that is not `recovery`.
178
+ */
179
+ openCycle(h: SourceSyncHandle, input: Pick<SourceSyncCycleInput, 'mode' | 'fromCursor'> & {
180
+ readonly cutoff?: number;
181
+ readonly cycleId?: string;
182
+ }, replaceExpiredHistory?: boolean): Promise<SourceSyncCheckpoint | null>;
183
+ /**
184
+ * Records one page: the next checkpoint and its queued work, in one transaction. The same page sent again right
185
+ * after it was recorded answers the same checkpoint; any other stale revision answers null.
186
+ *
187
+ * @throws {SourceSyncFault} `invalid_response` for an id longer than 512 characters, and the page rules'
188
+ * `invalid_source_sync_page` for a page the checkpoint does not admit.
189
+ */
190
+ page(h: SourceSyncHandle, expected: SourceSyncCheckpoint, page: SourceSyncPage): Promise<SourceSyncCheckpoint | null>;
191
+ private putWork;
192
+ /** Null id takes the first due item. Increment before external work; a crash leaves it pending. */
193
+ takeWork(h: SourceSyncHandle, id?: string | null): Promise<SourceSyncWork | null>;
194
+ private currentWork;
195
+ private normalized;
196
+ private documentRows;
197
+ /** Internal provenance enumeration. Never expose this as a browser retrieval response. */
198
+ documents(scope: SourceSyncScope): Promise<readonly SourceSyncStoredDocument[]>;
199
+ /** Whether the connection holds an exclusion for this source id. */
200
+ isExcluded(scope: SourceSyncScope, id: string): Promise<boolean>;
201
+ private choose;
202
+ /**
203
+ * Applies one read result for a work item taken in this cycle, under a live lease and the owner fence. A retry
204
+ * keeps the work unresolved. Any other result first purges the source's old copy and every result derived from it;
205
+ * a document then replaces it in the same transaction (host write, indexing charge and provenance) when it is not
206
+ * excluded and fits the retained and indexing limits, evicting this connection's older sources the limits no
207
+ * longer admit. A document that is excluded or does not fit is recorded as a skip with its reason.
208
+ *
209
+ * @param prepared - The host's prepared value for a document result; null for any other result.
210
+ * @returns The disposition and the handle later calls use, whose ticket reflects the purge; null for a stale
211
+ * handle or work item.
212
+ * @throws {SourceSyncFault} `invalid_response` for a result that does not match its work item or is malformed.
213
+ * @throws {Error} `invalid_source_allowance` when the host's allowance is not made of nonnegative safe integers.
214
+ */
215
+ applyResult(h: SourceSyncHandle, work: SourceSyncWork, result: SourceSyncReadResult, prepared: Prepared | null): Promise<SourceSyncApplication | null>;
216
+ private summary;
217
+ /**
218
+ * Records the cycle's progress, counted from its stored work and the retained documents.
219
+ *
220
+ * @returns The state, or null for a stale handle.
221
+ */
222
+ progress(h: SourceSyncHandle): Promise<SourceSyncState | null>;
223
+ /**
224
+ * Commits the cycle's target cursor once every work item is terminal, counting from the stored work and never from
225
+ * a caller's numbers, then clears the cycle, releases the lease and schedules the next poll.
226
+ *
227
+ * @returns The connected state, or null while work is unresolved or for a stale handle.
228
+ */
229
+ finish(h: SourceSyncHandle, expected: SourceSyncCheckpoint): Promise<SourceSyncState | null>;
230
+ /**
231
+ * Releases the lease, recording a deferral or a fixed failure when one is given; the cycle's checkpoint and work
232
+ * stay for the next claim.
233
+ *
234
+ * @returns Whether the lease was released.
235
+ */
236
+ release(h: SourceSyncHandle, event?: Extract<SourceSyncTransition, {
237
+ type: 'sync_deferred' | 'sync_failed';
238
+ }> | null): Promise<boolean>;
239
+ /**
240
+ * The current state of each of the derivation's retained sources, read in the given transaction for the fence's
241
+ * commit and delivery checks; not an authorization answer of its own. An owner the host's `active` binding refuses
242
+ * has no sources, and a connection with a barrier or pending revalidation reads as disconnected.
243
+ */
244
+ readCurrent(tx: StorageAdapter, derivation: SourceDerivation): Promise<readonly SourceDependencyState[]>;
245
+ /** Removes the host's content and this store's provenance in the affected scope; the fence calls it inside an invalidation. */
246
+ purgeSources(tx: StorageAdapter, scope: SourceOwnerScope, affected: SourceInvalidation): Promise<void>;
247
+ /**
248
+ * Applies a host control: completes any earlier barrier, then blocks the owner, moves the connection, records a
249
+ * barrier and drops the open cycle in one transaction, and completes the barrier before reactivating the owner.
250
+ * Connecting, grant loss and disconnecting purge the connection and its exclusions; a policy change, which takes
251
+ * the new policy, prunes retained sources to it and shortens their expiry to its window; the other controls rebind
252
+ * content to the new generation without changing its version or expiry.
253
+ *
254
+ * @returns The snapshot after the barrier is complete.
255
+ * @throws {Error} `source_policy_control_required` unless a policy comes exactly with `policy_changed`, and
256
+ * `stale_source_sync` when the host's `active` binding refuses anything but disconnecting or a barrier is still set.
257
+ */
258
+ control(scope: SourceSyncScope, event: SourceSyncControl, policy?: SourceSyncPolicy): Promise<SourceSyncSnapshot | null>;
259
+ private rebind;
260
+ /** Called by the lifecycle worker even when a connection is paused or the owner is blocked. */
261
+ recoverControl(scope: SourceSyncScope): Promise<void>;
262
+ /**
263
+ * Removes one source and every result derived from it, and keeps a content-free exclusion so later syncs skip it.
264
+ * The connection moves to a new generation, its cursor is cleared and its open cycle is dropped.
265
+ *
266
+ * @throws {SourceSyncFault} `invalid_response` for an empty id or one longer than 512 characters.
267
+ */
268
+ exclude(scope: SourceSyncScope, sourceId: string): Promise<void>;
269
+ /**
270
+ * Clears the connection's exclusions. The connection moves to a new generation, its cursor is cleared and its open
271
+ * cycle is dropped.
272
+ */
273
+ resetExclusions(scope: SourceSyncScope): Promise<void>;
274
+ /**
275
+ * Removes retained sources whose expiry has passed, with every result derived from them, also while the connection
276
+ * is paused, then expires the owner's derived results. Sources are removed only while the owner's fence is active;
277
+ * reads refuse an expired source regardless.
278
+ *
279
+ * @param limit - At most this many sources, an integer from 1 to 1,000.
280
+ * @returns How many sources were removed.
281
+ * @throws {Error} `invalid_sync_batch` for another limit.
282
+ */
283
+ expire(scope: SourceSyncScope, limit?: number): Promise<number>;
284
+ }
285
+ //# sourceMappingURL=SqlAccountSourceSyncStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqlAccountSourceSyncStore.d.ts","sourceRoot":"","sources":["../../src/sync/SqlAccountSourceSyncStore.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,wBAAwB,EACxB,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,KAAK,gBAAgB,EACxE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EACvE,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACV,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EACtF,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,EAC1E,kBAAkB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,yBAAyB,EAC1F,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAOpB;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,QAAQ,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