@byok-sdk/core 0.10.2 → 0.12.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/dist/errors.d.ts +1 -0
- package/dist/in-memory/mailbox.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/mailbox.d.ts +14 -2
- package/package.json +1 -1
package/dist/errors.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare const CORE_ERROR_CODES: {
|
|
|
39
39
|
readonly assertion_envelope_invalid: 'assertion_envelope_invalid';
|
|
40
40
|
readonly mailbox_message_not_found: 'mailbox_message_not_found';
|
|
41
41
|
readonly mailbox_cursor_regression: 'mailbox_cursor_regression';
|
|
42
|
+
readonly mailbox_cursor_ahead_of_delivery: 'mailbox_cursor_ahead_of_delivery';
|
|
42
43
|
readonly board_item_not_found: 'board_item_not_found';
|
|
43
44
|
readonly board_item_exists: 'board_item_exists';
|
|
44
45
|
readonly board_transition_invalid: 'board_transition_invalid';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MailboxAdvanceCursorInput, MailboxAppendInput, MailboxCursorState, MailboxMessage, MailboxPage, MailboxReadQuery, MailboxRetentionInput, MailboxRetentionResult, MailboxStore } from '../mailbox';
|
|
1
|
+
import type { MailboxAdvanceCursorInput, MailboxAppendInput, MailboxCursorState, MailboxMessage, MailboxPage, MailboxReadQuery, MailboxRecordDeliveryInput, MailboxRetentionInput, MailboxRetentionResult, MailboxStore } from '../mailbox';
|
|
2
2
|
import type { Clock } from '../stores';
|
|
3
3
|
import { type TenantId } from '../tenant';
|
|
4
4
|
export declare class InMemoryMailboxStore implements MailboxStore {
|
|
@@ -7,6 +7,7 @@ export declare class InMemoryMailboxStore implements MailboxStore {
|
|
|
7
7
|
append(tenant: TenantId, input: MailboxAppendInput): Promise<MailboxMessage>;
|
|
8
8
|
readAfter(tenant: TenantId, query: MailboxReadQuery): Promise<MailboxPage>;
|
|
9
9
|
advanceCursor(tenant: TenantId, input: MailboxAdvanceCursorInput): Promise<MailboxCursorState>;
|
|
10
|
+
recordDelivery(tenant: TenantId, input: MailboxRecordDeliveryInput): Promise<MailboxCursorState>;
|
|
10
11
|
readCursor(tenant: TenantId, deviceId: string): Promise<MailboxCursorState>;
|
|
11
12
|
collectRetired(tenant: TenantId, input: MailboxRetentionInput): Promise<MailboxRetentionResult>;
|
|
12
13
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { ByokCoreError, CoreConflictError, CORE_ERROR_CODES, isCoreError, isCore
|
|
|
18
18
|
export type { CoreErrorCode } from './errors';
|
|
19
19
|
export { CANONICAL_TIMESTAMP_PATTERN, assertCanonicalTimestamp, isCanonicalTimestamp, } from './time';
|
|
20
20
|
export { MAILBOX_MESSAGE_STATES } from './mailbox';
|
|
21
|
-
export type { MailboxAdvanceCursorInput, MailboxAppendInput, MailboxBody, MailboxCursorState, MailboxMessage, MailboxMessageState, MailboxPage, MailboxReadQuery, MailboxRetentionInput, MailboxRetentionResult, MailboxStore, } from './mailbox';
|
|
21
|
+
export type { MailboxAdvanceCursorInput, MailboxAppendInput, MailboxBody, MailboxCursorState, MailboxMessage, MailboxMessageState, MailboxPage, MailboxReadQuery, MailboxRecordDeliveryInput, MailboxRetentionInput, MailboxRetentionResult, MailboxStore, } from './mailbox';
|
|
22
22
|
export { BOARD_STATUSES, BOARD_TRANSITIONS, isLegalBoardTransition } from './board';
|
|
23
23
|
export type { BoardAssignee, BoardClaimInput, BoardItem, BoardItemInput, BoardListQuery, BoardPage, BoardStatus, BoardStatusUpdateInput, BoardStore, BoardUnclaimInput, } from './board';
|
|
24
24
|
export { TRUTH_RECORD_KINDS } from './truth';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var CORE_ERROR_CODES = {
|
|
|
22
22
|
// mailbox (§12.7.3)
|
|
23
23
|
mailbox_message_not_found: "mailbox_message_not_found",
|
|
24
24
|
mailbox_cursor_regression: "mailbox_cursor_regression",
|
|
25
|
+
mailbox_cursor_ahead_of_delivery: "mailbox_cursor_ahead_of_delivery",
|
|
25
26
|
// board coordination (§12.3)
|
|
26
27
|
board_item_not_found: "board_item_not_found",
|
|
27
28
|
board_item_exists: "board_item_exists",
|
|
@@ -536,7 +537,7 @@ var CORE_STORE_NAMES = [
|
|
|
536
537
|
// src/ports-contract.ts
|
|
537
538
|
var CORE_NON_COMPOSITION_PORT_NAMES = [];
|
|
538
539
|
var CORE_PORT_METHODS = {
|
|
539
|
-
mailbox: ["append", "readAfter", "advanceCursor", "readCursor", "collectRetired"],
|
|
540
|
+
mailbox: ["append", "readAfter", "recordDelivery", "advanceCursor", "readCursor", "collectRetired"],
|
|
540
541
|
board: ["create", "get", "list", "claim", "unclaim", "updateStatus"],
|
|
541
542
|
truth: ["writeTerminal", "writeSnapshot", "getRecord", "listManifest"],
|
|
542
543
|
presence: ["publish", "read", "list"],
|
|
@@ -1252,6 +1253,14 @@ var InMemoryMailboxStore = class {
|
|
|
1252
1253
|
this.#now()
|
|
1253
1254
|
);
|
|
1254
1255
|
}
|
|
1256
|
+
if (input.ackedSeq > device.deliveredSeq) {
|
|
1257
|
+
throw new CoreConflictError(
|
|
1258
|
+
"mailbox_cursor_ahead_of_delivery",
|
|
1259
|
+
`Cursor for device ${input.deviceId} was delivered through ${device.deliveredSeq}; refusing to acknowledge future cursor ${input.ackedSeq}.`,
|
|
1260
|
+
this.#cursorState(tenant, input.deviceId, device),
|
|
1261
|
+
this.#now()
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1255
1264
|
device.ackedSeq = input.ackedSeq;
|
|
1256
1265
|
device.cursorUpdatedAt = this.#now();
|
|
1257
1266
|
for (const [index, message] of device.messages.entries()) {
|
|
@@ -1268,10 +1277,24 @@ var InMemoryMailboxStore = class {
|
|
|
1268
1277
|
);
|
|
1269
1278
|
return advanced;
|
|
1270
1279
|
}
|
|
1280
|
+
async recordDelivery(tenant, input) {
|
|
1281
|
+
const device = this.#device(tenant, input.deviceId);
|
|
1282
|
+
const recorded = device.mutationTail.then(() => {
|
|
1283
|
+
if (input.deliveredSeq > device.deliveredSeq) {
|
|
1284
|
+
device.deliveredSeq = input.deliveredSeq;
|
|
1285
|
+
}
|
|
1286
|
+
return this.#cursorState(tenant, input.deviceId, device);
|
|
1287
|
+
});
|
|
1288
|
+
device.mutationTail = recorded.then(
|
|
1289
|
+
() => void 0,
|
|
1290
|
+
() => void 0
|
|
1291
|
+
);
|
|
1292
|
+
return recorded;
|
|
1293
|
+
}
|
|
1271
1294
|
async readCursor(tenant, deviceId) {
|
|
1272
1295
|
const device = this.#devices.get(tenantKey(tenant, deviceId));
|
|
1273
1296
|
if (device === void 0) {
|
|
1274
|
-
return { tenantId: tenant, deviceId, ackedSeq: 0, updatedAt: this.#now() };
|
|
1297
|
+
return { tenantId: tenant, deviceId, deliveredSeq: 0, ackedSeq: 0, updatedAt: this.#now() };
|
|
1275
1298
|
}
|
|
1276
1299
|
return this.#cursorState(tenant, deviceId, device);
|
|
1277
1300
|
}
|
|
@@ -1312,6 +1335,7 @@ var InMemoryMailboxStore = class {
|
|
|
1312
1335
|
if (existing !== void 0) return existing;
|
|
1313
1336
|
const created = {
|
|
1314
1337
|
nextSeq: 1,
|
|
1338
|
+
deliveredSeq: 0,
|
|
1315
1339
|
ackedSeq: 0,
|
|
1316
1340
|
cursorUpdatedAt: this.#now(),
|
|
1317
1341
|
mutationTail: Promise.resolve(),
|
|
@@ -1325,6 +1349,7 @@ var InMemoryMailboxStore = class {
|
|
|
1325
1349
|
return {
|
|
1326
1350
|
tenantId: tenant,
|
|
1327
1351
|
deviceId,
|
|
1352
|
+
deliveredSeq: device.deliveredSeq,
|
|
1328
1353
|
ackedSeq: device.ackedSeq,
|
|
1329
1354
|
updatedAt: device.cursorUpdatedAt
|
|
1330
1355
|
};
|