@sixb/pg 0.1.5 → 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
@@ -6936,7 +6936,12 @@ class PgMaterializationStateReader {
6936
6936
  return stored ? [stored] : [];
6937
6937
  });
6938
6938
  }
6939
- async linkScopes(scopes) {
6939
+ async linkScopeRevisions(scopes) {
6940
+ if (scopes.length === 0)
6941
+ return [];
6942
+ return (await this.readEffectiveLinkScopes(scopes)).revisions;
6943
+ }
6944
+ async linkSlotStates(scopes) {
6940
6945
  if (scopes.length === 0)
6941
6946
  return [];
6942
6947
  const requested = scopes.map(({ source, linkId }) => ({
@@ -6945,10 +6950,6 @@ class PgMaterializationStateReader {
6945
6950
  source_id: source.primaryId,
6946
6951
  link_id: linkId
6947
6952
  }));
6948
- const accumulators = new Map(scopes.map(({ source, linkId }) => {
6949
- const key = linkScopeSortKey(source, linkId);
6950
- return [key, startScopeAccumulator(source, linkId)];
6951
- }));
6952
6953
  const requestedParameter = jsonParameter2(this.sql, requested);
6953
6954
  const [sourceRows, slotOverrideRows] = await Promise.all([
6954
6955
  this.sql`
@@ -6994,6 +6995,29 @@ class PgMaterializationStateReader {
6994
6995
  const stored = storedLinkSlotOverride(row);
6995
6996
  return [linkScopeSortKey(stored.ref.source, stored.ref.linkId), stored];
6996
6997
  }));
6998
+ const { revisions, effective } = await this.readEffectiveLinkScopes(scopes);
6999
+ return scopes.map(({ source, linkId }, index) => {
7000
+ const key = linkScopeSortKey(source, linkId);
7001
+ return {
7002
+ ...revisions[index],
7003
+ sourceAssertion: sources.get(key) ?? null,
7004
+ override: overrides.get(key) ?? null,
7005
+ effective: effective.get(key) ?? null
7006
+ };
7007
+ });
7008
+ }
7009
+ async readEffectiveLinkScopes(scopes) {
7010
+ const requested = scopes.map(({ source, linkId }) => ({
7011
+ scope_sort_key: linkScopeSortKey(source, linkId),
7012
+ source_type_id: source.objectTypeId,
7013
+ source_id: source.primaryId,
7014
+ link_id: linkId
7015
+ }));
7016
+ const requestedParameter = jsonParameter2(this.sql, requested);
7017
+ const accumulators = new Map(scopes.map(({ source, linkId }) => {
7018
+ const key = linkScopeSortKey(source, linkId);
7019
+ return [key, startScopeAccumulator(source, linkId)];
7020
+ }));
6997
7021
  const effective = new Map;
6998
7022
  let scopeCursor = null;
6999
7023
  let linkCursor = null;
@@ -7032,22 +7056,10 @@ class PgMaterializationStateReader {
7032
7056
  scopeCursor = last.scope_sort_key;
7033
7057
  linkCursor = last.link_sort_key;
7034
7058
  }
7035
- return scopes.map(({ source, linkId }) => {
7036
- const key = linkScopeSortKey(source, linkId);
7037
- return {
7038
- ...finishScopeAccumulator(accumulators.get(key)),
7039
- sourceAssertion: sources.get(key) ?? null,
7040
- override: overrides.get(key) ?? null,
7041
- effective: effective.get(key) ?? null
7042
- };
7043
- });
7044
- }
7045
- async linkScope(source, linkId) {
7046
- const [scope] = await this.linkScopes([{ source, linkId }]);
7047
- if (!scope) {
7048
- throw new MaterializationConflictError2("effective-state", "Link scope lookup returned no row.");
7049
- }
7050
- return scope;
7059
+ return {
7060
+ revisions: scopes.map(({ source, linkId }) => finishScopeAccumulator(accumulators.get(linkScopeSortKey(source, linkId)))),
7061
+ effective
7062
+ };
7051
7063
  }
7052
7064
  async* incidentLinks(objects, pageRows) {
7053
7065
  if (objects.length === 0)
@@ -8453,9 +8465,9 @@ class PgOntologyMaterializationStorage {
8453
8465
  for (const expected of input.expected.links) {
8454
8466
  this.assertLink(linkRevisions.get(linkRefKey3(expected.ref)), expected);
8455
8467
  }
8456
- const linkScopes = await reader.linkScopes(input.expected.linkScopes);
8468
+ const linkScopeRevisions = await reader.linkScopeRevisions(input.expected.linkScopes);
8457
8469
  for (const [index, expected] of input.expected.linkScopes.entries()) {
8458
- if (linkScopes[index]?.fingerprint !== expected.fingerprint) {
8470
+ if (linkScopeRevisions[index]?.fingerprint !== expected.fingerprint) {
8459
8471
  throw new MaterializationConflictError5("effective-state", `Expected link scope changed for ${expected.source.objectTypeId}:${expected.source.primaryId}.${expected.linkId}.`);
8460
8472
  }
8461
8473
  }
@@ -8502,7 +8514,7 @@ class PgOntologyMaterializationStorage {
8502
8514
  yield {
8503
8515
  objects: [],
8504
8516
  links: [],
8505
- linkScopes: await reader.linkScopes(scopes.slice(offset, offset + input.pageRows)),
8517
+ linkScopes: await reader.linkSlotStates(scopes.slice(offset, offset + input.pageRows)),
8506
8518
  points: []
8507
8519
  };
8508
8520
  }
@@ -15346,4 +15358,4 @@ export {
15346
15358
  PostgresStorage
15347
15359
  };
15348
15360
 
15349
- //# debugId=0531F72AD7BC178764756E2164756E21
15361
+ //# debugId=C3F03A4D1D49552764756E2164756E21