@powerhousedao/connect 6.0.0-dev.88 → 6.0.0-dev.89

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.
@@ -4499,7 +4499,7 @@ var init_package = __esm(() => {
4499
4499
  package_default = {
4500
4500
  name: "@powerhousedao/connect",
4501
4501
  productName: "Powerhouse-Connect",
4502
- version: "6.0.0-dev.87",
4502
+ version: "6.0.0-dev.88",
4503
4503
  description: "Powerhouse Connect",
4504
4504
  main: "dist/index.html",
4505
4505
  type: "module",
@@ -4638,6 +4638,7 @@ import { isUndoRedo } from "document-model/core";
4638
4638
  import { deriveOperationId as deriveOperationId2 } from "document-model/core";
4639
4639
  import { ConsoleLogger } from "document-model/core";
4640
4640
  import { AbortError } from "document-drive/utils/errors";
4641
+ import { hashDocumentStateForScope } from "document-model/core";
4641
4642
  function createDocumentAction(input) {
4642
4643
  return {
4643
4644
  id: generateId(),
@@ -11932,6 +11933,10 @@ class RingBuffer {
11932
11933
  return this.size;
11933
11934
  }
11934
11935
  }
11936
+ function extractModuleVersion(doc) {
11937
+ const v = doc.state.document.version;
11938
+ return v === 0 ? undefined : v;
11939
+ }
11935
11940
 
11936
11941
  class KyselyWriteCache {
11937
11942
  streams;
@@ -12096,7 +12101,7 @@ class KyselyWriteCache {
12096
12101
  throw new Error(`Failed to rebuild document ${documentId}: CREATE_DOCUMENT action missing model in input`);
12097
12102
  }
12098
12103
  document2 = createDocumentFromAction(documentCreateAction);
12099
- const docModule = this.registry.getModule(documentType);
12104
+ let docModule = this.registry.getModule(documentType, extractModuleVersion(document2));
12100
12105
  const docScopeOps = await this.operationStore.getSince(documentId, "document", branch, 0, undefined, undefined, signal);
12101
12106
  for (const operation of docScopeOps.results) {
12102
12107
  if (operation.index === 0) {
@@ -12105,6 +12110,7 @@ class KyselyWriteCache {
12105
12110
  if (operation.action.type === "UPGRADE_DOCUMENT") {
12106
12111
  const upgradeAction = operation.action;
12107
12112
  document2 = applyUpgradeDocumentAction(document2, upgradeAction);
12113
+ docModule = this.registry.getModule(documentType, extractModuleVersion(document2));
12108
12114
  } else if (operation.action.type === "DELETE_DOCUMENT") {
12109
12115
  applyDeleteDocumentAction(document2, operation.action);
12110
12116
  } else {
@@ -12116,7 +12122,7 @@ class KyselyWriteCache {
12116
12122
  }
12117
12123
  }
12118
12124
  }
12119
- const module = this.registry.getModule(documentType);
12125
+ const module = this.registry.getModule(documentType, extractModuleVersion(document2));
12120
12126
  let cursor = undefined;
12121
12127
  const pageSize = 100;
12122
12128
  let hasMorePages;
@@ -14554,6 +14560,25 @@ class KyselyKeyframeStore {
14554
14560
  document: row.document
14555
14561
  };
14556
14562
  }
14563
+ async listKeyframes(documentId, scope, branch, signal) {
14564
+ if (signal?.aborted) {
14565
+ throw new Error("Operation aborted");
14566
+ }
14567
+ let query = this.queryExecutor.selectFrom("Keyframe").selectAll().where("documentId", "=", documentId).orderBy("revision", "asc");
14568
+ if (scope !== undefined) {
14569
+ query = query.where("scope", "=", scope);
14570
+ }
14571
+ if (branch !== undefined) {
14572
+ query = query.where("branch", "=", branch);
14573
+ }
14574
+ const rows = await query.execute();
14575
+ return rows.map((row) => ({
14576
+ scope: row.scope,
14577
+ branch: row.branch,
14578
+ revision: row.revision,
14579
+ document: row.document
14580
+ }));
14581
+ }
14557
14582
  async deleteKeyframes(documentId, scope, branch, signal) {
14558
14583
  if (signal?.aborted) {
14559
14584
  throw new Error("Operation aborted");
@@ -18817,6 +18842,118 @@ function relationalDbToQueryBuilder(query) {
18817
18842
  withSchema: (schema) => relationalDbToQueryBuilder(query.withSchema(schema))
18818
18843
  };
18819
18844
  }
18845
+
18846
+ class DocumentIntegrityService {
18847
+ keyframeStore;
18848
+ operationStore;
18849
+ writeCache;
18850
+ documentView;
18851
+ documentModelRegistry;
18852
+ constructor(keyframeStore, operationStore, writeCache, documentView, documentModelRegistry) {
18853
+ this.keyframeStore = keyframeStore;
18854
+ this.operationStore = operationStore;
18855
+ this.writeCache = writeCache;
18856
+ this.documentView = documentView;
18857
+ this.documentModelRegistry = documentModelRegistry;
18858
+ }
18859
+ async validateDocument(documentId, branch = "main", signal) {
18860
+ const keyframeIssues = [];
18861
+ const snapshotIssues = [];
18862
+ const replayCache = new KyselyWriteCache(nullKeyframeStore, this.operationStore, this.documentModelRegistry, {
18863
+ maxDocuments: 1,
18864
+ ringBufferSize: 1,
18865
+ keyframeInterval: Number.MAX_SAFE_INTEGER
18866
+ });
18867
+ const keyframes = await this.keyframeStore.listKeyframes(documentId, undefined, branch, signal);
18868
+ for (const keyframe of keyframes) {
18869
+ if (signal?.aborted) {
18870
+ throw new Error("Operation aborted");
18871
+ }
18872
+ replayCache.invalidate(documentId, keyframe.scope, branch);
18873
+ const replayedDoc = await replayCache.getState(documentId, keyframe.scope, branch, keyframe.revision, signal);
18874
+ const kfHash = hashDocumentStateForScope(keyframe.document, keyframe.scope);
18875
+ const replayHash = hashDocumentStateForScope(replayedDoc, keyframe.scope);
18876
+ if (kfHash !== replayHash) {
18877
+ keyframeIssues.push({
18878
+ scope: keyframe.scope,
18879
+ branch,
18880
+ revision: keyframe.revision,
18881
+ keyframeHash: kfHash,
18882
+ replayedHash: replayHash
18883
+ });
18884
+ }
18885
+ }
18886
+ let currentDoc;
18887
+ try {
18888
+ currentDoc = await this.documentView.get(documentId);
18889
+ } catch {
18890
+ return {
18891
+ documentId,
18892
+ isConsistent: keyframeIssues.length === 0,
18893
+ keyframeIssues,
18894
+ snapshotIssues
18895
+ };
18896
+ }
18897
+ const revisions = await this.operationStore.getRevisions(documentId, branch, signal);
18898
+ const allScopes = Object.keys(revisions.revision);
18899
+ for (const scope of allScopes) {
18900
+ if (scope === "document")
18901
+ continue;
18902
+ replayCache.invalidate(documentId, scope, branch);
18903
+ let replayedDoc;
18904
+ try {
18905
+ replayedDoc = await replayCache.getState(documentId, scope, branch, undefined, signal);
18906
+ } catch {
18907
+ if (signal?.aborted) {
18908
+ throw new Error("Operation aborted");
18909
+ }
18910
+ continue;
18911
+ }
18912
+ const snapshotHash = hashDocumentStateForScope(currentDoc, scope);
18913
+ const replayHash = hashDocumentStateForScope(replayedDoc, scope);
18914
+ if (snapshotHash !== replayHash) {
18915
+ snapshotIssues.push({
18916
+ scope,
18917
+ branch,
18918
+ snapshotHash,
18919
+ replayedHash: replayHash
18920
+ });
18921
+ }
18922
+ }
18923
+ return {
18924
+ documentId,
18925
+ isConsistent: keyframeIssues.length === 0 && snapshotIssues.length === 0,
18926
+ keyframeIssues,
18927
+ snapshotIssues
18928
+ };
18929
+ }
18930
+ async rebuildKeyframes(documentId, branch = "main", signal) {
18931
+ const deleted = await this.keyframeStore.deleteKeyframes(documentId, undefined, branch, signal);
18932
+ return {
18933
+ documentId,
18934
+ keyframesDeleted: deleted,
18935
+ scopesInvalidated: 0
18936
+ };
18937
+ }
18938
+ async rebuildSnapshots(documentId, branch = "main", signal) {
18939
+ const scopes = await this.discoverScopes(documentId, branch, signal);
18940
+ for (const scope of scopes) {
18941
+ if (signal?.aborted) {
18942
+ throw new Error("Operation aborted");
18943
+ }
18944
+ this.writeCache.invalidate(documentId, scope, branch);
18945
+ }
18946
+ return {
18947
+ documentId,
18948
+ keyframesDeleted: 0,
18949
+ scopesInvalidated: scopes.length
18950
+ };
18951
+ }
18952
+ async discoverScopes(documentId, branch, signal) {
18953
+ const revisions = await this.operationStore.getRevisions(documentId, branch, signal);
18954
+ return Object.keys(revisions.revision);
18955
+ }
18956
+ }
18820
18957
  var __defProp2, __export2 = (target, all) => {
18821
18958
  for (var name in all)
18822
18959
  __defProp2(target, name, {
@@ -18959,7 +19096,7 @@ var __defProp2, __export2 = (target, all) => {
18959
19096
  }
18960
19097
  }
18961
19098
  return maxOrdinal;
18962
- }, SyncStatus, cachedEncoder, LOG2_26, IS_RELATIONAL_DB_PROCESSOR, RelationalDbProcessor;
19099
+ }, SyncStatus, cachedEncoder, LOG2_26, IS_RELATIONAL_DB_PROCESSOR, RelationalDbProcessor, nullKeyframeStore;
18963
19100
  var init_src = __esm(() => {
18964
19101
  __defProp2 = Object.defineProperty;
18965
19102
  byteToHex = [];
@@ -24219,6 +24356,12 @@ var init_src = __esm(() => {
24219
24356
  return relationalDbToQueryBuilder(this.relationalDb);
24220
24357
  }
24221
24358
  };
24359
+ nullKeyframeStore = {
24360
+ putKeyframe: () => Promise.resolve(),
24361
+ findNearestKeyframe: () => Promise.resolve(undefined),
24362
+ listKeyframes: () => Promise.resolve([]),
24363
+ deleteKeyframes: () => Promise.resolve(0)
24364
+ };
24222
24365
  });
24223
24366
 
24224
24367
  // ../../packages/reactor-browser/dist/src/index.js
@@ -24433,6 +24576,7 @@ __export(exports_src, {
24433
24576
  InMemoryQueue: () => InMemoryQueue,
24434
24577
  ISSUER_TYPE: () => ISSUER_TYPE,
24435
24578
  GqlRequestChannel: () => GqlRequestChannel,
24579
+ DocumentIntegrityService: () => DocumentIntegrityService,
24436
24580
  DocumentChangeType: () => DocumentChangeType,
24437
24581
  DocumentCache: () => DocumentCache,
24438
24582
  DisconnectIcon: () => DisconnectIcon,
package/dist/style.css CHANGED
@@ -2882,6 +2882,9 @@
2882
2882
  .border-black {
2883
2883
  border-color: var(--color-black);
2884
2884
  }
2885
+ .border-blue-300 {
2886
+ border-color: var(--color-blue-300);
2887
+ }
2885
2888
  .border-blue-500 {
2886
2889
  border-color: var(--color-blue-500);
2887
2890
  }
@@ -2942,6 +2945,9 @@
2942
2945
  .border-yellow-300 {
2943
2946
  border-color: var(--color-yellow-300);
2944
2947
  }
2948
+ .border-yellow-400 {
2949
+ border-color: var(--color-yellow-400);
2950
+ }
2945
2951
  .border-zinc-200 {
2946
2952
  border-color: var(--color-zinc-200);
2947
2953
  }
@@ -3098,6 +3104,9 @@
3098
3104
  .bg-yellow-500 {
3099
3105
  background-color: var(--color-yellow-500);
3100
3106
  }
3107
+ .bg-yellow-600 {
3108
+ background-color: var(--color-yellow-600);
3109
+ }
3101
3110
  .bg-zinc-50 {
3102
3111
  background-color: var(--color-zinc-50);
3103
3112
  }
@@ -4280,6 +4289,13 @@
4280
4289
  }
4281
4290
  }
4282
4291
  }
4292
+ .hover\:bg-yellow-700 {
4293
+ &:hover {
4294
+ @media (hover: hover) {
4295
+ background-color: var(--color-yellow-700);
4296
+ }
4297
+ }
4298
+ }
4283
4299
  .hover\:text-\[\#9896FF\] {
4284
4300
  &:hover {
4285
4301
  @media (hover: hover) {
@@ -4365,6 +4381,11 @@
4365
4381
  }
4366
4382
  }
4367
4383
  }
4384
+ .focus\:border-blue-400 {
4385
+ &:focus {
4386
+ border-color: var(--color-blue-400);
4387
+ }
4388
+ }
4368
4389
  .focus\:bg-gray-50 {
4369
4390
  &:focus {
4370
4391
  background-color: var(--color-gray-50);