@sixb/sqlite 0.1.4 → 0.1.6

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/index.js CHANGED
@@ -9181,6 +9181,14 @@ import {
9181
9181
  } from "@sixb/core/internal/ontology-storage-provider";
9182
9182
  var SQLITE_MATERIALIZATION_WORK_TABLE = "ontology_materialization_work";
9183
9183
  var SQLITE_REPLACEMENT_WORK_TABLE = "ontology_replacement_work";
9184
+ function linkScopeRequestJson(scopes) {
9185
+ return canonicalJson(scopes.map(({ source, linkId }) => ({
9186
+ scopeSortKey: linkScopeSortKey(source, linkId),
9187
+ sourceTypeId: source.objectTypeId,
9188
+ sourceId: source.primaryId,
9189
+ linkId
9190
+ })));
9191
+ }
9184
9192
 
9185
9193
  class SqliteMaterializationStateReader {
9186
9194
  db;
@@ -9389,20 +9397,15 @@ class SqliteMaterializationStateReader {
9389
9397
  return stored ? [stored] : [];
9390
9398
  });
9391
9399
  }
9392
- linkScopes(scopes) {
9400
+ linkScopeRevisions(scopes) {
9393
9401
  if (scopes.length === 0)
9394
9402
  return [];
9395
- const requested = scopes.map(({ source, linkId }) => ({
9396
- scopeSortKey: linkScopeSortKey(source, linkId),
9397
- sourceTypeId: source.objectTypeId,
9398
- sourceId: source.primaryId,
9399
- linkId
9400
- }));
9401
- const accumulators = new Map(scopes.map(({ source, linkId }) => {
9402
- const key = linkScopeSortKey(source, linkId);
9403
- return [key, startScopeAccumulator(source, linkId)];
9404
- }));
9405
- const requestedJson = canonicalJson(requested);
9403
+ return this.readEffectiveLinkScopes(scopes, linkScopeRequestJson(scopes)).revisions;
9404
+ }
9405
+ linkSlotStates(scopes) {
9406
+ if (scopes.length === 0)
9407
+ return [];
9408
+ const requestedJson = linkScopeRequestJson(scopes);
9406
9409
  const sourceRows = this.db.query(`WITH requested AS (
9407
9410
  SELECT DISTINCT
9408
9411
  json_extract(value, '$.sourceTypeId') AS source_type_id,
@@ -9441,6 +9444,22 @@ class SqliteMaterializationStateReader {
9441
9444
  const stored = storedLinkSlotOverride(row);
9442
9445
  return [linkScopeSortKey(stored.ref.source, stored.ref.linkId), stored];
9443
9446
  }));
9447
+ const { revisions, effective } = this.readEffectiveLinkScopes(scopes, requestedJson);
9448
+ return scopes.map(({ source, linkId }, index) => {
9449
+ const key = linkScopeSortKey(source, linkId);
9450
+ return {
9451
+ ...revisions[index],
9452
+ sourceAssertion: sources.get(key) ?? null,
9453
+ override: overrides.get(key) ?? null,
9454
+ effective: effective.get(key) ?? null
9455
+ };
9456
+ });
9457
+ }
9458
+ readEffectiveLinkScopes(scopes, requestedJson) {
9459
+ const accumulators = new Map(scopes.map(({ source, linkId }) => {
9460
+ const key = linkScopeSortKey(source, linkId);
9461
+ return [key, startScopeAccumulator(source, linkId)];
9462
+ }));
9444
9463
  const effective = new Map;
9445
9464
  const rows = this.db.query(`
9446
9465
  WITH requested AS (
@@ -9469,22 +9488,10 @@ class SqliteMaterializationStateReader {
9469
9488
  appendScopeSnapshot(accumulator2, snapshot);
9470
9489
  effective.set(row.scope_sort_key, accumulator2.effectiveCount === 1 ? snapshot : null);
9471
9490
  }
9472
- return scopes.map(({ source, linkId }) => {
9473
- const key = linkScopeSortKey(source, linkId);
9474
- return {
9475
- ...finishScopeAccumulator(accumulators.get(key)),
9476
- sourceAssertion: sources.get(key) ?? null,
9477
- override: overrides.get(key) ?? null,
9478
- effective: effective.get(key) ?? null
9479
- };
9480
- });
9481
- }
9482
- linkScope(source, linkId) {
9483
- const [scope] = this.linkScopes([{ source, linkId }]);
9484
- if (!scope) {
9485
- throw new MaterializationConflictError2("effective-state", "Link scope lookup returned no row.");
9486
- }
9487
- return scope;
9491
+ return {
9492
+ revisions: scopes.map(({ source, linkId }) => finishScopeAccumulator(accumulators.get(linkScopeSortKey(source, linkId)))),
9493
+ effective
9494
+ };
9488
9495
  }
9489
9496
  *incidentLinks(objects, pageRows) {
9490
9497
  if (objects.length === 0)
@@ -10520,8 +10527,9 @@ class SqliteOntologyMaterializationStorage {
10520
10527
  this.assertObject(reader, expected);
10521
10528
  for (const expected of input.expected.links)
10522
10529
  this.assertLink(reader, expected);
10523
- for (const expected of input.expected.linkScopes) {
10524
- if (reader.linkScope(expected.source, expected.linkId).fingerprint !== expected.fingerprint) {
10530
+ const linkScopeRevisions = reader.linkScopeRevisions(input.expected.linkScopes);
10531
+ for (const [index, expected] of input.expected.linkScopes.entries()) {
10532
+ if (linkScopeRevisions[index]?.fingerprint !== expected.fingerprint) {
10525
10533
  throw new MaterializationConflictError5("effective-state", `Expected link scope changed for ${expected.source.objectTypeId}:${expected.source.primaryId}.${expected.linkId}.`);
10526
10534
  }
10527
10535
  }
@@ -10567,7 +10575,7 @@ class SqliteOntologyMaterializationStorage {
10567
10575
  yield {
10568
10576
  objects: [],
10569
10577
  links: [],
10570
- linkScopes: reader.linkScopes(scopes.slice(offset, offset + input.pageRows)),
10578
+ linkScopes: reader.linkSlotStates(scopes.slice(offset, offset + input.pageRows)),
10571
10579
  points: []
10572
10580
  };
10573
10581
  }
@@ -14071,4 +14079,4 @@ export {
14071
14079
  SqliteStorage
14072
14080
  };
14073
14081
 
14074
- //# debugId=2D24EFD822513C9E64756E2164756E21
14082
+ //# debugId=65891EE349DAB6B764756E2164756E21