@abloatai/humans 0.59.2 → 0.61.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 +1 -1
- package/dist/Ablo.d.ts +2 -10
- package/dist/Ablo.js +0 -1
- package/dist/client.d.ts +1 -48
- package/dist/humans.d.ts +1 -1
- package/dist/local/BaseSyncedStore.d.ts +5 -5
- package/dist/local/BaseSyncedStore.js +7 -7
- package/dist/local/Database.d.ts +2 -2
- package/dist/local/LazyReferenceCollection.d.ts +1 -1
- package/dist/local/Model.js +46 -56
- package/dist/local/NetworkMonitor.js +2 -0
- package/dist/local/RuntimeContext.js +2 -0
- package/dist/local/SyncClient.d.ts +12 -36
- package/dist/local/SyncClient.js +50 -108
- package/dist/local/client/createModelOperations.d.ts +3 -27
- package/dist/local/client/createModelOperations.js +20 -21
- package/dist/local/client/options.d.ts +14 -39
- package/dist/local/client/reactiveEngine.d.ts +3 -9
- package/dist/local/client/reactiveEngine.js +6 -151
- package/dist/local/client/storeLifecycle.js +5 -1
- package/dist/local/fileUploads.d.ts +27 -0
- package/dist/local/fileUploads.js +55 -0
- package/dist/local/storeContract.d.ts +5 -5
- package/dist/local/stores/syncAction.d.ts +4 -4
- package/dist/local/sync/contextOnChange.js +1 -1
- package/dist/local/sync/createClaimStream.js +1 -1
- package/dist/local/sync/credentialLifecycle.d.ts +4 -5
- package/dist/local/sync/credentialLifecycle.js +4 -5
- package/dist/local/sync/deltaPipeline.js +12 -6
- package/dist/local/sync/schemas.d.ts +10 -10
- package/dist/local/sync/scopeGroups.d.ts +11 -0
- package/dist/local/sync/scopeGroups.js +75 -0
- package/dist/local/sync/wsFrameHandlers.d.ts +1 -1
- package/dist/local/transactions/localMutation.js +3 -3
- package/dist/local/transactions/mutations/MutationQueue.d.ts +4 -5
- package/dist/local/transactions/mutations/MutationQueue.js +25 -51
- package/dist/local/transactions/mutations/batchProcessing.js +23 -10
- package/dist/local/transactions/mutations/commitPayload.d.ts +9 -2
- package/dist/local/transactions/mutations/commitTransport.js +3 -1
- package/dist/local/transactions/mutations/executionSelection.d.ts +0 -1
- package/dist/local/transactions/mutations/executionSelection.js +9 -17
- package/dist/local/transactions/mutations/failureHandling.js +9 -0
- package/dist/local/transactions/mutations/localMutation.js +3 -3
- package/dist/local/transactions/mutations/queueCoalescing.js +8 -0
- package/dist/local/transactions/mutations/replayValidation.d.ts +15 -15
- package/dist/react/AbloProvider.d.ts +11 -86
- package/dist/react/AbloProvider.js +11 -163
- package/dist/react/ClientSideSuspense.d.ts +1 -1
- package/dist/react/DefaultFallback.d.ts +1 -1
- package/dist/react/createAbloReact.js +1 -1
- package/dist/react/useErrorListener.js +1 -1
- package/dist/react/useMutationFailureListener.js +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/surface.d.ts +3 -3
- package/dist/surface.js +1 -4
- package/package.json +3 -3
- package/src/Ablo.ts +5 -17
- package/src/client.ts +0 -51
- package/src/local/BaseSyncedStore.ts +14 -14
- package/src/local/Model.ts +45 -55
- package/src/local/NetworkMonitor.ts +2 -0
- package/src/local/RuntimeContext.ts +2 -0
- package/src/local/SyncClient.ts +73 -140
- package/src/local/client/createModelOperations.ts +30 -64
- package/src/local/client/options.ts +20 -43
- package/src/local/client/reactiveEngine.ts +7 -179
- package/src/local/client/storeLifecycle.ts +6 -1
- package/src/local/fileUploads.ts +97 -0
- package/src/local/storeContract.ts +5 -5
- package/src/local/sync/contextOnChange.ts +1 -1
- package/src/local/sync/createClaimStream.ts +1 -1
- package/src/local/sync/credentialLifecycle.ts +4 -5
- package/src/local/sync/deltaPipeline.ts +10 -6
- package/src/local/sync/scopeGroups.ts +91 -0
- package/src/local/sync/wsFrameHandlers.ts +0 -1
- package/src/local/transactions/localMutation.ts +3 -3
- package/src/local/transactions/mutations/MutationQueue.ts +24 -53
- package/src/local/transactions/mutations/batchProcessing.ts +25 -10
- package/src/local/transactions/mutations/commitPayload.ts +11 -1
- package/src/local/transactions/mutations/commitTransport.ts +2 -2
- package/src/local/transactions/mutations/executionSelection.ts +9 -15
- package/src/local/transactions/mutations/failureHandling.ts +10 -0
- package/src/local/transactions/mutations/localMutation.ts +3 -3
- package/src/local/transactions/mutations/queueCoalescing.ts +6 -0
- package/src/react/AbloProvider.tsx +17 -249
- package/src/react/useErrorListener.ts +1 -1
- package/src/react/useMutationFailureListener.ts +1 -1
- package/src/react.ts +1 -5
- package/src/surface.ts +1 -4
- package/dist/local/sync/participants.d.ts +0 -132
- package/dist/local/sync/participants.js +0 -342
- package/dist/local/transactions/mutations/pendingDrain.d.ts +0 -33
- package/dist/local/transactions/mutations/pendingDrain.js +0 -117
- package/src/local/sync/participants.ts +0 -564
- package/src/local/transactions/mutations/pendingDrain.ts +0 -169
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import type { RuntimeContext } from '../../RuntimeContext.js';
|
|
2
|
-
import type { QueuedMutation } from './commitPayload.js';
|
|
3
|
-
import type { MutationStore } from './MutationStore.js';
|
|
4
|
-
import type { OptimisticUpdateEntry } from './localMutation.js';
|
|
5
|
-
import type { MutationCommitResult } from '@abloatai/transaction/commit';
|
|
6
|
-
import type { DurableCommitEnvelope } from '@abloatai/transaction/commit';
|
|
7
|
-
import { applyWriteOptions, collectQueuedReads, TX_TYPE_TO_MUTATION_OP } from './commitPayload.js';
|
|
8
|
-
|
|
9
|
-
export interface PendingDrainContext {
|
|
10
|
-
readonly runtime: RuntimeContext;
|
|
11
|
-
readonly config: { deltaConfirmationTimeout: number };
|
|
12
|
-
readonly store: MutationStore;
|
|
13
|
-
readonly executionQueue: QueuedMutation[];
|
|
14
|
-
readonly optimisticUpdates: Map<string, OptimisticUpdateEntry>;
|
|
15
|
-
readonly assertDurableReplayOpen: () => void;
|
|
16
|
-
readonly processCommitLane: () => Promise<void>;
|
|
17
|
-
readonly takePendingDrainBatch: (pending: QueuedMutation[]) => QueuedMutation[];
|
|
18
|
-
readonly ensureCommitEnvelope: (batch: QueuedMutation[]) => string;
|
|
19
|
-
readonly ensureDerivedFields: (transaction: QueuedMutation) => void;
|
|
20
|
-
readonly sourceMutationIdsFor: (batch: readonly QueuedMutation[]) => string[];
|
|
21
|
-
readonly sealDurableCommit: (input: Parameters<typeof import('./commitTransport.js').sealDurableCommit>[1]) => Promise<DurableCommitEnvelope>;
|
|
22
|
-
readonly assertEnvelopeInsideReplayWindow: (envelope: DurableCommitEnvelope) => void;
|
|
23
|
-
readonly parseMutationCommitResult: (value: Awaited<ReturnType<import('../../interfaces/index.js').MutationExecutor['commit']>>) => MutationCommitResult;
|
|
24
|
-
readonly dispatchCommitBounded: (...args: Parameters<import('../../interfaces/index.js').MutationExecutor['commit']>) => ReturnType<import('../../interfaces/index.js').MutationExecutor['commit']>;
|
|
25
|
-
readonly persistDurableCommitAcceptance: (envelope: DurableCommitEnvelope, result: MutationCommitResult) => Promise<DurableCommitEnvelope>;
|
|
26
|
-
readonly removeDurableCommit: (idempotencyKey: string) => Promise<void>;
|
|
27
|
-
readonly scheduleReplicationLagTimeout: (transactionId: string, clientTxId?: string, correlationId?: string) => void;
|
|
28
|
-
readonly scheduleDeltaConfirmationTimeout: (transaction: QueuedMutation, timeoutMs: number) => void;
|
|
29
|
-
readonly enqueue: (transaction: QueuedMutation) => void;
|
|
30
|
-
readonly recentDeltaCorrelations: Map<string, number>;
|
|
31
|
-
readonly emit: (event: string, payload: object) => boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function drainPendingConfirmations(ctx: PendingDrainContext): Promise<void> {
|
|
35
|
-
ctx.assertDurableReplayOpen();
|
|
36
|
-
// Kick the commit lane too: atomic envelopes from `commits.create()` may
|
|
37
|
-
// have been left at the head of the lane while the connection was down.
|
|
38
|
-
// Fire-and-forget; processCommitLane serializes itself.
|
|
39
|
-
void ctx.processCommitLane();
|
|
40
|
-
|
|
41
|
-
// Collect pending transactions in created order
|
|
42
|
-
const pending = ctx.store.getByStatus('pending').sort((a, b) => a.createdAt - b.createdAt);
|
|
43
|
-
if (pending.length === 0) return;
|
|
44
|
-
const pendingIds = new Set(pending.map((tx) => tx.id));
|
|
45
|
-
// These rows may already be waiting behind the normal batch timer. The
|
|
46
|
-
// reconnect fast path takes ownership of them for this attempt so the same
|
|
47
|
-
// transaction cannot dispatch concurrently through both paths.
|
|
48
|
-
const retainedQueue = ctx.executionQueue.filter(
|
|
49
|
-
(tx) => !pendingIds.has(tx.id),
|
|
50
|
-
);
|
|
51
|
-
ctx.executionQueue.splice(
|
|
52
|
-
0,
|
|
53
|
-
ctx.executionQueue.length,
|
|
54
|
-
...retainedQueue,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const remaining = [...pending];
|
|
58
|
-
while (remaining.length > 0) {
|
|
59
|
-
const batch = ctx.takePendingDrainBatch(remaining);
|
|
60
|
-
if (batch.length === 0) break;
|
|
61
|
-
const batchIds = new Set(batch.map((tx) => tx.id));
|
|
62
|
-
const nextRemaining = remaining.filter((tx) => !batchIds.has(tx.id));
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
const idempotencyKey = ctx.ensureCommitEnvelope(batch);
|
|
66
|
-
const projectedOperations = batch.map((tx) => {
|
|
67
|
-
ctx.ensureDerivedFields(tx);
|
|
68
|
-
return applyWriteOptions(
|
|
69
|
-
{
|
|
70
|
-
type: TX_TYPE_TO_MUTATION_OP[tx.type],
|
|
71
|
-
model: tx.modelKey,
|
|
72
|
-
id: tx.modelId,
|
|
73
|
-
input: tx.type === 'create' || tx.type === 'update' ? tx.data || {} : undefined,
|
|
74
|
-
transactionId: tx.id,
|
|
75
|
-
},
|
|
76
|
-
tx,
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
const durableEnvelope = await ctx.sealDurableCommit({
|
|
80
|
-
idempotencyKey,
|
|
81
|
-
origin: 'model_batch',
|
|
82
|
-
operations: projectedOperations,
|
|
83
|
-
sourceMutationIds: ctx.sourceMutationIdsFor(batch),
|
|
84
|
-
commitOptions: { reads: collectQueuedReads(batch) },
|
|
85
|
-
createdAt: Math.min(...batch.map((transaction) => transaction.createdAt)),
|
|
86
|
-
sealedAt: batch[0]?.commitEnvelope?.sealedAt ?? Date.now(),
|
|
87
|
-
sequence: batch[0]?.commitEnvelope?.sequence,
|
|
88
|
-
});
|
|
89
|
-
ctx.assertEnvelopeInsideReplayWindow(durableEnvelope);
|
|
90
|
-
const result = ctx.parseMutationCommitResult(
|
|
91
|
-
await ctx.dispatchCommitBounded(durableEnvelope.operations, {
|
|
92
|
-
idempotencyKey,
|
|
93
|
-
...(durableEnvelope.commitOptions.reads !== undefined
|
|
94
|
-
? { reads: durableEnvelope.commitOptions.reads }
|
|
95
|
-
: {}),
|
|
96
|
-
}),
|
|
97
|
-
);
|
|
98
|
-
await ctx.persistDurableCommitAcceptance(durableEnvelope, result);
|
|
99
|
-
if (result.status === 'queued') {
|
|
100
|
-
// Reconnect flushes use the same accepted-vs-confirmed contract as
|
|
101
|
-
// the normal lane. A queued source receipt retains the envelope and
|
|
102
|
-
// waits for exact correlation; it is never promoted by the reconnect
|
|
103
|
-
// shortcut itself.
|
|
104
|
-
for (const tx of batch) {
|
|
105
|
-
tx.requiresCorrelatedDelta = true;
|
|
106
|
-
tx.syncIdNeededForCompletion = undefined;
|
|
107
|
-
tx.correlationId = result.correlationId;
|
|
108
|
-
const echoSyncId = result.correlationId
|
|
109
|
-
? ctx.recentDeltaCorrelations.get(result.correlationId)
|
|
110
|
-
: undefined;
|
|
111
|
-
if (echoSyncId !== undefined) {
|
|
112
|
-
ctx.store.updateStatus(tx.id, 'completed');
|
|
113
|
-
ctx.emit('transaction:completed', tx);
|
|
114
|
-
ctx.emit(`transaction:completed:${tx.id}`, tx);
|
|
115
|
-
ctx.optimisticUpdates.delete(tx.id);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
ctx.store.updateStatus(tx.id, 'awaiting_delta');
|
|
119
|
-
ctx.scheduleReplicationLagTimeout(
|
|
120
|
-
tx.id,
|
|
121
|
-
idempotencyKey,
|
|
122
|
-
result.correlationId,
|
|
123
|
-
);
|
|
124
|
-
ctx.scheduleDeltaConfirmationTimeout(
|
|
125
|
-
tx,
|
|
126
|
-
ctx.config.deltaConfirmationTimeout,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
if (batch.every((tx) => tx.status === 'completed')) {
|
|
130
|
-
await ctx.removeDurableCommit(idempotencyKey);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
await ctx.removeDurableCommit(idempotencyKey);
|
|
134
|
-
// Mark this request envelope as completed before moving to the next.
|
|
135
|
-
for (const tx of batch) {
|
|
136
|
-
ctx.store.updateStatus(tx.id, 'completed');
|
|
137
|
-
ctx.emit('transaction:completed', tx);
|
|
138
|
-
ctx.emit(`transaction:completed:${tx.id}`, tx);
|
|
139
|
-
ctx.optimisticUpdates.delete(tx.id);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
ctx.runtime.logger.debug('txn:commit', 0, {
|
|
143
|
-
count: batch.length,
|
|
144
|
-
lastSyncId: result.lastSyncId,
|
|
145
|
-
});
|
|
146
|
-
remaining.splice(0, remaining.length, ...nextRemaining);
|
|
147
|
-
} catch (err) {
|
|
148
|
-
// If one request fails, hand it and every later request back to the
|
|
149
|
-
// normal lane. Their envelopes stay attached for safe retry.
|
|
150
|
-
const networkUnavailable = !ctx.runtime.onlineStatus.isOnline();
|
|
151
|
-
const isNetworkError =
|
|
152
|
-
err instanceof Error &&
|
|
153
|
-
(err.message.includes('Failed to fetch') ||
|
|
154
|
-
err.message.includes('Network request failed') ||
|
|
155
|
-
err.message.includes('NetworkError'));
|
|
156
|
-
|
|
157
|
-
if (!networkUnavailable || !isNetworkError) {
|
|
158
|
-
ctx.runtime.observability.breadcrumb('Batch flush fallback failed', 'sync.transaction', 'warning', {
|
|
159
|
-
error: err instanceof Error ? err.message : String(err),
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
for (const tx of [...batch, ...nextRemaining]) {
|
|
164
|
-
ctx.enqueue(tx);
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|