@abloatai/ablo 0.28.0 → 0.29.1
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/CHANGELOG.md +36 -0
- package/dist/Database.js +9 -6
- package/dist/SyncClient.d.ts +2 -2
- package/dist/SyncClient.js +22 -10
- package/dist/adapters/inMemoryStorage.js +18 -14
- package/dist/ai-sdk/coordinatedTool.d.ts +15 -2
- package/dist/auth/schemas.d.ts +6 -0
- package/dist/auth/schemas.js +7 -0
- package/dist/cli.cjs +815 -400
- package/dist/client/Ablo.d.ts +29 -23
- package/dist/client/Ablo.js +8 -196
- package/dist/client/claimHeartbeatLoop.d.ts +1 -1
- package/dist/client/claimHeartbeatLoop.js +1 -1
- package/dist/client/createInternalComponents.d.ts +4 -2
- package/dist/client/createInternalComponents.js +3 -1
- package/dist/client/durableWrites.d.ts +21 -0
- package/dist/client/durableWrites.js +46 -0
- package/dist/client/httpClient.d.ts +19 -45
- package/dist/client/httpClient.js +104 -26
- package/dist/client/httpTransport.d.ts +8 -0
- package/dist/client/{ApiClient.js → httpTransport.js} +78 -291
- package/dist/client/options.d.ts +43 -19
- package/dist/client/options.js +3 -2
- package/dist/client/resourceTypes.d.ts +9 -85
- package/dist/client/resourceTypes.js +1 -1
- package/dist/client/sessionMint.d.ts +5 -6
- package/dist/client/sessionMint.js +4 -5
- package/dist/client/validateAbloOptions.js +3 -3
- package/dist/coordination/schema.d.ts +30 -0
- package/dist/coordination/schema.js +14 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/errors.d.ts +4 -40
- package/dist/errors.js +5 -5
- package/dist/index.d.ts +14 -8
- package/dist/index.js +7 -5
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/mutators/defineMutators.d.ts +18 -0
- package/dist/mutators/defineMutators.js +4 -8
- package/dist/react/index.d.ts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/select.d.ts +15 -0
- package/dist/schema/select.js +27 -3
- package/dist/source/connector.d.ts +3 -3
- package/dist/source/factory.d.ts +4 -6
- package/dist/source/factory.js +4 -7
- package/dist/source/index.d.ts +4 -4
- package/dist/source/index.js +2 -2
- package/dist/source/signing.d.ts +0 -3
- package/dist/source/types.d.ts +0 -26
- package/dist/stores/ObjectStore.js +8 -8
- package/dist/surface.d.ts +1 -1
- package/dist/surface.js +1 -0
- package/dist/sync/BootstrapFetcher.d.ts +10 -0
- package/dist/sync/BootstrapFetcher.js +27 -4
- package/dist/sync/createClaimStream.d.ts +11 -2
- package/dist/sync/createClaimStream.js +4 -3
- package/dist/testing/mocks/FakeDatabase.d.ts +1 -1
- package/dist/transactions/TransactionQueue.d.ts +2 -2
- package/dist/transactions/TransactionQueue.js +3 -3
- package/dist/transactions/commitEnvelope.d.ts +1 -1
- package/dist/transactions/commitEnvelope.js +2 -2
- package/dist/transactions/commitOutboxStore.d.ts +19 -19
- package/dist/transactions/durableWriteStore.d.ts +123 -0
- package/dist/transactions/durableWriteStore.js +30 -0
- package/dist/transactions/httpCommitEnvelope.d.ts +1 -0
- package/dist/transactions/httpCommitEnvelope.js +14 -12
- package/dist/transactions/idempotencyKey.d.ts +10 -0
- package/dist/transactions/idempotencyKey.js +9 -0
- package/dist/types/global.d.ts +10 -29
- package/dist/types/global.js +4 -7
- package/dist/types/streams.d.ts +2 -28
- package/dist/wire/frames.d.ts +6 -257
- package/dist/wire/frames.js +4 -25
- package/dist/wire/index.d.ts +4 -3
- package/dist/wire/index.js +2 -2
- package/dist/wire/protocolVersion.d.ts +30 -17
- package/dist/wire/protocolVersion.js +34 -18
- package/docs/agents.md +8 -3
- package/docs/api.md +6 -4
- package/docs/client-behavior.md +6 -3
- package/docs/coordination.md +2 -3
- package/docs/data-sources.md +5 -8
- package/docs/guarantees.md +21 -0
- package/docs/integration-guide.md +1 -0
- package/docs/migration.md +21 -1
- package/docs/quickstart.md +11 -0
- package/docs/react.md +0 -46
- package/examples/README.md +6 -5
- package/llms.txt +15 -15
- package/package.json +2 -7
- package/dist/client/ApiClient.d.ts +0 -177
- package/dist/commit/contract.d.ts +0 -493
- package/dist/commit/contract.js +0 -187
- package/dist/commit/index.d.ts +0 -6
- package/dist/commit/index.js +0 -5
|
@@ -12,52 +12,130 @@
|
|
|
12
12
|
* where the credential itself carries identity and the server resolves it on
|
|
13
13
|
* every request.
|
|
14
14
|
*
|
|
15
|
-
* Under the hood this wraps
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* The proxy gives server code the same typed `client.<model>` surface the
|
|
20
|
-
* stateful client offers, over stateless transport.
|
|
15
|
+
* Under the hood this wraps one schema-agnostic protocol client in a typed
|
|
16
|
+
* proxy. That protocol layer keeps transport envelopes and string-keyed model
|
|
17
|
+
* routing private; application code gets the same `client.<model>` surface the
|
|
18
|
+
* stateful client offers.
|
|
21
19
|
*/
|
|
22
|
-
import {
|
|
20
|
+
import { createHttpTransport, } from './httpTransport.js';
|
|
21
|
+
import { AbloConnectionError, AbloValidationError } from '../errors.js';
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `tasks`, `claims`, `capabilities`, `agent` — so that `client.tasks` resolves to
|
|
27
|
-
* the schema model named `tasks` rather than a protocol resource. Only lifecycle
|
|
28
|
-
* methods and the genuinely protocol-level members belong here.
|
|
23
|
+
* Private transport members that pass straight through the facade. Everything
|
|
24
|
+
* else must be a declared schema model; there is no dynamic fallback namespace.
|
|
29
25
|
*/
|
|
30
26
|
const PROTOCOL_MEMBERS = new Set([
|
|
31
27
|
'ready',
|
|
32
28
|
'waitForFlush',
|
|
33
29
|
'dispose',
|
|
34
|
-
'purge',
|
|
35
30
|
'commits',
|
|
36
|
-
'model',
|
|
37
31
|
'getAuthToken',
|
|
38
32
|
'sessions',
|
|
39
33
|
]);
|
|
34
|
+
/** Narrows a bare property name to a transport key so the facade can index it typed. */
|
|
35
|
+
function isProtocolMember(prop) {
|
|
36
|
+
return PROTOCOL_MEMBERS.has(prop);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Adapts one low-level protocol model to the public typed model contract. The
|
|
40
|
+
* protocol deliberately retains `{ data, stamp, claims }` reads and commit
|
|
41
|
+
* receipts because functional updates need them. This is the single boundary
|
|
42
|
+
* that unwraps those transport details for application code.
|
|
43
|
+
*/
|
|
44
|
+
function createHttpModelClient(protocol) {
|
|
45
|
+
async function readRow(id) {
|
|
46
|
+
const read = await protocol.retrieve({ id });
|
|
47
|
+
return read.data;
|
|
48
|
+
}
|
|
49
|
+
async function requireUpdatedRow(id) {
|
|
50
|
+
const row = await readRow(id);
|
|
51
|
+
if (row === undefined) {
|
|
52
|
+
throw new AbloConnectionError(`update settled but ${id} could not be read back from the server.`, { code: 'commit_no_result' });
|
|
53
|
+
}
|
|
54
|
+
return row;
|
|
55
|
+
}
|
|
56
|
+
// The protocol resource is schema-agnostic and types claim handles as records.
|
|
57
|
+
// The typed facade carries the same handle with its row type attached; runtime
|
|
58
|
+
// mutation code only reads the handle identity. Normalize that one generic
|
|
59
|
+
// boundary here instead of leaking casts into every model method.
|
|
60
|
+
function mutationOptions(params) {
|
|
61
|
+
const { claim, ...rest } = params;
|
|
62
|
+
return {
|
|
63
|
+
...rest,
|
|
64
|
+
...(claim !== undefined ? { claim } : {}),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function update(arg, updater, options) {
|
|
68
|
+
if (typeof arg === 'string') {
|
|
69
|
+
if (!updater) {
|
|
70
|
+
throw new AbloValidationError('Functional update requires an updater function.', { code: 'write_options_invalid' });
|
|
71
|
+
}
|
|
72
|
+
const receipt = await protocol.update(arg, updater, options);
|
|
73
|
+
return receipt === undefined ? undefined : requireUpdatedRow(arg);
|
|
74
|
+
}
|
|
75
|
+
await protocol.update({
|
|
76
|
+
...mutationOptions(arg),
|
|
77
|
+
data: arg.data,
|
|
78
|
+
});
|
|
79
|
+
return requireUpdatedRow(arg.id);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
async retrieve(params) {
|
|
83
|
+
const read = await protocol.retrieve(params);
|
|
84
|
+
return read.data;
|
|
85
|
+
},
|
|
86
|
+
list: (options) => protocol.list(options),
|
|
87
|
+
async create(params) {
|
|
88
|
+
const row = await protocol.create({
|
|
89
|
+
...mutationOptions(params),
|
|
90
|
+
data: params.data,
|
|
91
|
+
});
|
|
92
|
+
return row;
|
|
93
|
+
},
|
|
94
|
+
update,
|
|
95
|
+
async delete(params) {
|
|
96
|
+
await protocol.delete(mutationOptions(params));
|
|
97
|
+
},
|
|
98
|
+
claim: protocol.claim,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
40
101
|
/**
|
|
41
102
|
* Builds the stateless, typed HTTP client. Each `client.<model>` resolves to the
|
|
42
103
|
* protocol client's model accessor, while `commits`, `dispose`, and the other
|
|
43
104
|
* protocol members pass through unchanged. No socket is ever opened; the bearer
|
|
44
105
|
* credential is the identity.
|
|
45
106
|
*/
|
|
107
|
+
/** @internal Constructed only through the public `Ablo({ transport: 'http' })` factory. */
|
|
46
108
|
export function createAbloHttpClient(options) {
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
109
|
+
const { schema, ...rest } = options;
|
|
110
|
+
const modelTypenames = Object.fromEntries(Object.entries(schema.models).map(([key, definition]) => [
|
|
111
|
+
key,
|
|
112
|
+
definition.typename ?? key,
|
|
113
|
+
]));
|
|
114
|
+
const transport = createHttpTransport({
|
|
115
|
+
...rest,
|
|
116
|
+
modelTypenames,
|
|
117
|
+
});
|
|
118
|
+
const schemaModels = new Set(Object.keys(schema.models));
|
|
119
|
+
const models = new Map();
|
|
120
|
+
const model = (name) => {
|
|
121
|
+
const cached = models.get(name);
|
|
122
|
+
if (cached)
|
|
123
|
+
return cached;
|
|
124
|
+
const created = createHttpModelClient(transport.model(name));
|
|
125
|
+
models.set(name, created);
|
|
126
|
+
return created;
|
|
127
|
+
};
|
|
128
|
+
const facade = new Proxy({}, {
|
|
129
|
+
get(_target, prop) {
|
|
52
130
|
if (typeof prop !== 'string')
|
|
53
|
-
return
|
|
131
|
+
return undefined;
|
|
54
132
|
// Real protocol members pass through unchanged.
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
return
|
|
133
|
+
if (isProtocolMember(prop)) {
|
|
134
|
+
return transport[prop];
|
|
135
|
+
}
|
|
136
|
+
// Only schema models become model accessors. A typo or retired top-level
|
|
137
|
+
// member resolves to undefined instead of manufacturing a plausible client.
|
|
138
|
+
return schemaModels.has(prop) ? model(prop) : undefined;
|
|
61
139
|
},
|
|
62
140
|
});
|
|
63
141
|
// A single boundary cast. `AbloHttpClient<S>` declares only what the model
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Private HTTP protocol client behind `Ablo({ schema, transport: 'http' })`.
|
|
3
|
+
* It carries no object pool, local database, or WebSocket and maps Model,
|
|
4
|
+
* Claim, and Commit protocol shapes directly to server routes. The typed
|
|
5
|
+
* facade in `httpClient.ts` is the application boundary; this module owns
|
|
6
|
+
* transport envelopes, watermarks, replay, and route details.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|