@visorcraft/mongreldb-kit 0.63.0 → 0.64.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/db.d.ts +29 -12
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +35 -19
- package/dist/db.js.map +1 -1
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +34 -20
- package/dist/migrate.js.map +1 -1
- package/dist/remote.d.ts +49 -0
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +193 -19
- package/dist/remote.js.map +1 -1
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/remote.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,KAAK,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,KAAK,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,KAAK,EACX,aAAa,EAEb,UAAU,EACV,QAAQ,EACR,cAAc,EACd,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAiB,KAAK,oBAAoB,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9F,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAGN,KAAK,gBAAgB,EACrB,MAAM,eAAe,CAAC;AAiMv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a,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQjC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,oBAAyB,GAAG,OAAO;IAarE,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO;IAWzC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO;IAWxD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ/B,QAAQ,IAAI,OAAO;IAInB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAI/D,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAInD;mCAC+B;IAC/B,OAAO,IAAI;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAIjD;0DACsD;IACtD,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGpC"}
|
package/dist/remote.js
CHANGED
|
@@ -440,6 +440,68 @@ const COMMITTED_QUERY_STATUSES = new Set([
|
|
|
440
440
|
function sameOptional(left, right) {
|
|
441
441
|
return (left ?? null) === (right ?? null);
|
|
442
442
|
}
|
|
443
|
+
const OUTCOME_ALLOWED_KEYS = [
|
|
444
|
+
'committed', 'committed_statements', 'last_commit_epoch', 'last_commit_epoch_text',
|
|
445
|
+
'last_commit_hlc', 'first_commit_statement_index', 'last_commit_statement_index',
|
|
446
|
+
'completed_statements', 'statement_index', 'serialization', 'serialization_state',
|
|
447
|
+
'terminal_state'
|
|
448
|
+
];
|
|
449
|
+
const OUTCOME_REQUIRED_KEYS = [
|
|
450
|
+
'committed', 'committed_statements', 'last_commit_epoch', 'last_commit_epoch_text',
|
|
451
|
+
'first_commit_statement_index', 'last_commit_statement_index', 'completed_statements',
|
|
452
|
+
'statement_index', 'serialization'
|
|
453
|
+
];
|
|
454
|
+
function isRemoteCommitHlc(value) {
|
|
455
|
+
if (value === null || value === undefined)
|
|
456
|
+
return true;
|
|
457
|
+
if (value === null || typeof value !== 'object')
|
|
458
|
+
return false;
|
|
459
|
+
const hlc = value;
|
|
460
|
+
if (!hasOnlyKeys(hlc, ['physical_micros', 'logical', 'node_tiebreaker']))
|
|
461
|
+
return false;
|
|
462
|
+
if (typeof hlc.physical_micros !== 'number'
|
|
463
|
+
|| !Number.isSafeInteger(hlc.physical_micros)
|
|
464
|
+
|| hlc.physical_micros < 0)
|
|
465
|
+
return false;
|
|
466
|
+
if (hlc.logical !== undefined
|
|
467
|
+
&& (typeof hlc.logical !== 'number' || !Number.isSafeInteger(hlc.logical) || hlc.logical < 0)) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
if (hlc.node_tiebreaker !== undefined
|
|
471
|
+
&& (typeof hlc.node_tiebreaker !== 'number'
|
|
472
|
+
|| !Number.isSafeInteger(hlc.node_tiebreaker)
|
|
473
|
+
|| hlc.node_tiebreaker < 0)) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
478
|
+
function parseRemoteCommitHlc(value) {
|
|
479
|
+
if (value === null || value === undefined || typeof value !== 'object')
|
|
480
|
+
return undefined;
|
|
481
|
+
const hlc = value;
|
|
482
|
+
return {
|
|
483
|
+
physicalMicros: hlc.physical_micros,
|
|
484
|
+
logical: hlc.logical ?? 0,
|
|
485
|
+
nodeTiebreaker: hlc.node_tiebreaker ?? 0
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function pickCommitHlc(...sources) {
|
|
489
|
+
for (const source of sources) {
|
|
490
|
+
if (!source)
|
|
491
|
+
continue;
|
|
492
|
+
const parsed = parseRemoteCommitHlc('last_commit_hlc' in source ? source.last_commit_hlc : undefined);
|
|
493
|
+
if (parsed !== undefined)
|
|
494
|
+
return parsed;
|
|
495
|
+
}
|
|
496
|
+
return undefined;
|
|
497
|
+
}
|
|
498
|
+
function pickSerializationState(outcome, durable) {
|
|
499
|
+
const state = durable?.serialization_state
|
|
500
|
+
?? outcome?.serialization_state
|
|
501
|
+
?? durable?.serialization
|
|
502
|
+
?? outcome?.serialization;
|
|
503
|
+
return state === undefined || state === null ? undefined : state;
|
|
504
|
+
}
|
|
443
505
|
function isRemoteQueryStatus(value, queryId) {
|
|
444
506
|
if (value === null || typeof value !== 'object')
|
|
445
507
|
return false;
|
|
@@ -449,24 +511,31 @@ function isRemoteQueryStatus(value, queryId) {
|
|
|
449
511
|
: undefined;
|
|
450
512
|
if (outcome === undefined)
|
|
451
513
|
return false;
|
|
514
|
+
const durable = body.durable === undefined || body.durable === null
|
|
515
|
+
? undefined
|
|
516
|
+
: typeof body.durable === 'object'
|
|
517
|
+
? body.durable
|
|
518
|
+
: undefined;
|
|
519
|
+
if (body.durable !== undefined && body.durable !== null && durable === undefined)
|
|
520
|
+
return false;
|
|
452
521
|
const serverState = body.server_state ?? '';
|
|
453
522
|
const terminal = body.terminal_error;
|
|
454
523
|
if (!hasOnlyKeys(body, [
|
|
455
524
|
'query_id', 'status', 'state', 'server_state', 'terminal_state', 'detail', 'operation',
|
|
456
525
|
'started_ms_ago', 'deadline_ms_remaining', 'session_id',
|
|
457
526
|
'committed', 'committed_statements', 'last_commit_epoch', 'last_commit_epoch_text',
|
|
527
|
+
'last_commit_hlc',
|
|
458
528
|
'first_commit_statement_index', 'last_commit_statement_index', 'completed_statements',
|
|
459
529
|
'statement_index', 'cancel_outcome', 'retryable', 'terminal_error',
|
|
460
|
-
'cancellation_reason', 'outcome', 'trace'
|
|
461
|
-
]) || !hasOnlyKeys(outcome,
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
]))
|
|
530
|
+
'cancellation_reason', 'outcome', 'durable', 'trace'
|
|
531
|
+
]) || !hasOnlyKeys(outcome, OUTCOME_ALLOWED_KEYS)
|
|
532
|
+
|| !hasAllKeys(outcome, OUTCOME_REQUIRED_KEYS)
|
|
533
|
+
|| (durable !== undefined && (!hasOnlyKeys(durable, OUTCOME_ALLOWED_KEYS)
|
|
534
|
+
|| !hasAllKeys(durable, OUTCOME_REQUIRED_KEYS))))
|
|
535
|
+
return false;
|
|
536
|
+
if (!isRemoteCommitHlc(body.last_commit_hlc)
|
|
537
|
+
|| !isRemoteCommitHlc(outcome.last_commit_hlc)
|
|
538
|
+
|| (durable !== undefined && !isRemoteCommitHlc(durable.last_commit_hlc)))
|
|
470
539
|
return false;
|
|
471
540
|
if (terminal !== undefined && terminal !== null
|
|
472
541
|
&& (typeof terminal !== 'object'
|
|
@@ -826,19 +895,16 @@ function validateCancelResponse(value, queryId, httpStatus) {
|
|
|
826
895
|
if (!hasOnlyKeys(body, [
|
|
827
896
|
'query_id', 'state', 'cancel_outcome', 'status', 'terminal_state', 'code',
|
|
828
897
|
'committed', 'committed_statements', 'last_commit_epoch', 'last_commit_epoch_text',
|
|
898
|
+
'last_commit_hlc',
|
|
829
899
|
'first_commit_statement_index', 'last_commit_statement_index', 'completed_statements',
|
|
830
|
-
'statement_index', 'cancellation_reason', 'retryable', 'server_state', 'outcome', '
|
|
831
|
-
'terminal_error'
|
|
900
|
+
'statement_index', 'cancellation_reason', 'retryable', 'server_state', 'outcome', 'durable',
|
|
901
|
+
'error', 'terminal_error'
|
|
832
902
|
])) {
|
|
833
903
|
throw new KitError('SQL cancellation response has unknown fields', 'REMOTE_PROTOCOL');
|
|
834
904
|
}
|
|
835
905
|
if (body.outcome !== undefined && body.outcome !== null
|
|
836
906
|
&& (typeof body.outcome !== 'object'
|
|
837
|
-
|| !hasOnlyKeys(body.outcome,
|
|
838
|
-
'committed', 'committed_statements', 'last_commit_epoch', 'last_commit_epoch_text',
|
|
839
|
-
'first_commit_statement_index', 'last_commit_statement_index', 'completed_statements',
|
|
840
|
-
'statement_index', 'serialization'
|
|
841
|
-
]))) {
|
|
907
|
+
|| !hasOnlyKeys(body.outcome, OUTCOME_ALLOWED_KEYS))) {
|
|
842
908
|
throw new KitError('SQL cancellation outcome has unknown fields', 'REMOTE_PROTOCOL');
|
|
843
909
|
}
|
|
844
910
|
if (body.error !== undefined && body.error !== null
|
|
@@ -1342,6 +1408,7 @@ export class RemoteDatabase {
|
|
|
1342
1408
|
queryId = normalizeQueryId(queryId);
|
|
1343
1409
|
const status = await this.rawQueryStatus(queryId);
|
|
1344
1410
|
const committed = mergedCommitState(status.outcome?.committed, status.committed);
|
|
1411
|
+
const durable = status.durable ?? undefined;
|
|
1345
1412
|
return {
|
|
1346
1413
|
queryId: status.query_id,
|
|
1347
1414
|
phase: status.server_state || status.state,
|
|
@@ -1353,10 +1420,12 @@ export class RemoteDatabase {
|
|
|
1353
1420
|
committed,
|
|
1354
1421
|
committedStatements: maxKnown(status.outcome?.committed_statements, status.committed_statements) ?? null,
|
|
1355
1422
|
lastCommitEpoch: remoteEpoch(status.outcome?.last_commit_epoch_text ?? status.last_commit_epoch_text, status.outcome?.last_commit_epoch ?? status.last_commit_epoch),
|
|
1423
|
+
lastCommitHlc: pickCommitHlc(durable, status.outcome, status),
|
|
1356
1424
|
firstCommitStatementIndex: status.outcome?.first_commit_statement_index
|
|
1357
1425
|
?? status.first_commit_statement_index ?? undefined,
|
|
1358
1426
|
lastCommitStatementIndex: status.outcome?.last_commit_statement_index
|
|
1359
|
-
?? status.last_commit_statement_index ?? undefined
|
|
1427
|
+
?? status.last_commit_statement_index ?? undefined,
|
|
1428
|
+
serializationState: pickSerializationState(status.outcome, durable)
|
|
1360
1429
|
},
|
|
1361
1430
|
terminalErrorCode: status.terminal_error?.code,
|
|
1362
1431
|
terminalErrorCategory: status.terminal_error?.category,
|
|
@@ -1367,6 +1436,108 @@ export class RemoteDatabase {
|
|
|
1367
1436
|
retryable: status.retryable
|
|
1368
1437
|
};
|
|
1369
1438
|
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Text → embed under the active semantic identity → ANN retrieve
|
|
1441
|
+
* (`POST /kit/retrieve_text`, 0.64+).
|
|
1442
|
+
*/
|
|
1443
|
+
async retrieveText(table, embeddingColumn, text, options = {}) {
|
|
1444
|
+
if (!Number.isInteger(embeddingColumn) || embeddingColumn < 0 || embeddingColumn > 0xffff) {
|
|
1445
|
+
throw new RangeError('embeddingColumn must be a u16 column id');
|
|
1446
|
+
}
|
|
1447
|
+
if (options.k !== undefined && (!Number.isSafeInteger(options.k) || options.k <= 0)) {
|
|
1448
|
+
throw new RangeError('k must be a positive safe integer');
|
|
1449
|
+
}
|
|
1450
|
+
const body = {
|
|
1451
|
+
table,
|
|
1452
|
+
embedding_column: embeddingColumn,
|
|
1453
|
+
text
|
|
1454
|
+
};
|
|
1455
|
+
if (options.k !== undefined)
|
|
1456
|
+
body.k = options.k;
|
|
1457
|
+
if (options.deadlineMs !== undefined)
|
|
1458
|
+
body.deadline_ms = options.deadlineMs;
|
|
1459
|
+
if (options.maxWork !== undefined)
|
|
1460
|
+
body.max_work = options.maxWork;
|
|
1461
|
+
const response = await this.request('/kit/retrieve_text', {
|
|
1462
|
+
method: 'POST',
|
|
1463
|
+
headers: { 'content-type': 'application/json' },
|
|
1464
|
+
body: JSON.stringify(body)
|
|
1465
|
+
});
|
|
1466
|
+
if (!response.ok) {
|
|
1467
|
+
throw new KitError(`retrieve_text failed with HTTP ${response.status}`, 'REMOTE_PROTOCOL');
|
|
1468
|
+
}
|
|
1469
|
+
const payload = await responseJsonStrict(response);
|
|
1470
|
+
if (payload === null || typeof payload !== 'object') {
|
|
1471
|
+
throw new KitError('retrieve_text response was not an object', 'REMOTE_PROTOCOL');
|
|
1472
|
+
}
|
|
1473
|
+
const env = payload;
|
|
1474
|
+
if (!Array.isArray(env.hits) || env.provenance === null || typeof env.provenance !== 'object') {
|
|
1475
|
+
throw new KitError('retrieve_text response missing hits/provenance', 'REMOTE_PROTOCOL');
|
|
1476
|
+
}
|
|
1477
|
+
const provenance = env.provenance;
|
|
1478
|
+
return {
|
|
1479
|
+
hits: env.hits.map((hit) => ({
|
|
1480
|
+
rowId: String(hit.row_id),
|
|
1481
|
+
rank: hit.rank,
|
|
1482
|
+
score: hit.score
|
|
1483
|
+
})),
|
|
1484
|
+
provenance: {
|
|
1485
|
+
embeddingColumn: provenance.embedding_column,
|
|
1486
|
+
providerRegistryGeneration: provenance.provider_registry_generation,
|
|
1487
|
+
querySourceFingerprint: String(provenance.query_source_fingerprint ?? ''),
|
|
1488
|
+
semanticIdentity: (provenance.semantic_identity ?? {})
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Build a multi-retriever hybrid search body for `POST /kit/search`.
|
|
1494
|
+
* Exposed for wire tests and callers that need the payload without executing.
|
|
1495
|
+
*/
|
|
1496
|
+
static buildKitSearchBody(input) {
|
|
1497
|
+
if (!input.table)
|
|
1498
|
+
throw new TypeError('table is required');
|
|
1499
|
+
if (!input.retrievers || input.retrievers.length === 0) {
|
|
1500
|
+
throw new RangeError('search requires at least one retriever');
|
|
1501
|
+
}
|
|
1502
|
+
const limit = input.limit ?? 10;
|
|
1503
|
+
if (!Number.isSafeInteger(limit) || limit <= 0) {
|
|
1504
|
+
throw new RangeError('limit must be a positive safe integer');
|
|
1505
|
+
}
|
|
1506
|
+
const body = {
|
|
1507
|
+
table: input.table,
|
|
1508
|
+
retrievers: input.retrievers,
|
|
1509
|
+
fusion: { reciprocal_rank: { constant: input.fusionConstant ?? 60 } },
|
|
1510
|
+
limit
|
|
1511
|
+
};
|
|
1512
|
+
if (input.must && input.must.length > 0)
|
|
1513
|
+
body.must = input.must;
|
|
1514
|
+
if (input.rerank)
|
|
1515
|
+
body.rerank = input.rerank;
|
|
1516
|
+
if (input.projection)
|
|
1517
|
+
body.projection = input.projection;
|
|
1518
|
+
return body;
|
|
1519
|
+
}
|
|
1520
|
+
/** Multi-retriever hybrid search (`POST /kit/search`). */
|
|
1521
|
+
async kitSearch(body) {
|
|
1522
|
+
const response = await this.request('/kit/search', {
|
|
1523
|
+
method: 'POST',
|
|
1524
|
+
headers: { 'content-type': 'application/json' },
|
|
1525
|
+
body: JSON.stringify(body)
|
|
1526
|
+
});
|
|
1527
|
+
if (!response.ok) {
|
|
1528
|
+
throw new KitError(`kit search failed with HTTP ${response.status}`, 'REMOTE_PROTOCOL');
|
|
1529
|
+
}
|
|
1530
|
+
const payload = await responseJsonStrict(response);
|
|
1531
|
+
if (payload === null || typeof payload !== 'object') {
|
|
1532
|
+
throw new KitError('kit search response was not an object', 'REMOTE_PROTOCOL');
|
|
1533
|
+
}
|
|
1534
|
+
const env = payload;
|
|
1535
|
+
return {
|
|
1536
|
+
hits: Array.isArray(env.hits) ? env.hits : [],
|
|
1537
|
+
trace: env.trace,
|
|
1538
|
+
nextCursor: typeof env.next_cursor === 'string' ? env.next_cursor : undefined
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1370
1541
|
async sqlPage(sql, options) {
|
|
1371
1542
|
await this.requireSqlPagination();
|
|
1372
1543
|
if (options.projection.length === 0 || options.projection.length > 128
|
|
@@ -1657,16 +1828,19 @@ export class RemoteDatabase {
|
|
|
1657
1828
|
if (committed === null) {
|
|
1658
1829
|
throw new QueryOutcomeUnknownError(queryId, message, metadata);
|
|
1659
1830
|
}
|
|
1831
|
+
const durable = status.durable ?? undefined;
|
|
1660
1832
|
const durableOutcome = {
|
|
1661
1833
|
committed,
|
|
1662
1834
|
committedStatements: maxKnown(outcome?.committed_statements, status.committed_statements),
|
|
1663
1835
|
lastCommitEpoch: remoteEpoch(outcome?.last_commit_epoch_text ?? status.last_commit_epoch_text, outcome?.last_commit_epoch ?? status.last_commit_epoch),
|
|
1836
|
+
lastCommitHlc: pickCommitHlc(durable, outcome, status),
|
|
1664
1837
|
firstCommitStatementIndex: outcome?.first_commit_statement_index
|
|
1665
1838
|
?? status.first_commit_statement_index ?? undefined,
|
|
1666
1839
|
lastCommitStatementIndex: outcome?.last_commit_statement_index
|
|
1667
1840
|
?? status.last_commit_statement_index ?? undefined,
|
|
1668
1841
|
completedStatements: outcome?.completed_statements ?? status.completed_statements ?? undefined,
|
|
1669
|
-
statementIndex: outcome?.statement_index ?? status.statement_index ?? undefined
|
|
1842
|
+
statementIndex: outcome?.statement_index ?? status.statement_index ?? undefined,
|
|
1843
|
+
serializationState: pickSerializationState(outcome, durable)
|
|
1670
1844
|
};
|
|
1671
1845
|
switch (status.terminal_error?.code) {
|
|
1672
1846
|
case 'QUERY_CANCELLED':
|