Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/runner/integration/reconnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Identity } from "@commontools/identity";
import { StorageManager } from "../src/storage/cache.ts";
import type { SchemaContext } from "@commontools/memory/interface";
import type { SchemaContext, URI } from "@commontools/memory/interface";

const TOOLSHED_URL = Deno.env.get("TOOLSHED_API_URL") ||
"http://localhost:8000";
Expand Down Expand Up @@ -72,30 +72,30 @@ const storageManager3 = StorageManager.open({
});
const provider3 = storageManager3.open(signer.did());
console.log(`Provider3 (control) connected to memory server`);

const uri: URI = `of:${TEST_DOC_ID}`;
// Listen for updates on the test-reconnection-counter document
// Note: this is not the schema subscription, its just a client-side listener
provider1.sink({ "/": TEST_DOC_ID }, (value) => {
provider1.sink(uri, (value) => {
updateCount1++;
updates1.push(value.value);
console.log(`Provider1 Update #${updateCount1}:`, value.value);
});

provider3.sink({ "/": TEST_DOC_ID }, (value) => {
provider3.sink(uri, (value) => {
updateCount3++;
updates3.push(value.value);
console.log(`Provider3 Update #${updateCount3}:`, value.value);
});

// Establish server-side subscription with schema
console.log("Establishing subscriptions...");
await provider1.sync({ "/": TEST_DOC_ID }, true, testSchema);
await provider3.sync({ "/": TEST_DOC_ID }, true, testSchema);
await provider1.sync(uri, true, testSchema);
await provider3.sync(uri, true, testSchema);

// Send initial value to server
console.log("Sending initial value...");
await provider1.send([{
entityId: { "/": TEST_DOC_ID },
uri,
value: {
value: {
value: 1,
Expand Down Expand Up @@ -155,7 +155,7 @@ console.log(`Connected to memory server as second client`);

// Establish server-side subscription with schema
console.log("Establishing subscription as second client...");
await provider2.sync({ "/": TEST_DOC_ID }, true, testSchema);
await provider2.sync(uri, true, testSchema);

// Send test updates and check if subscription still works
console.log("Sending test updates after disconnection...");
Expand All @@ -164,7 +164,7 @@ const intervalId = setInterval(async () => {
try {
// Send an update as the second
const result = await provider2.send([{
entityId: { "/": TEST_DOC_ID },
uri,
value: {
value: {
value: testValue++,
Expand Down
7 changes: 4 additions & 3 deletions packages/runner/src/doc-map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { refer } from "merkle-reference/json";
import { isRecord } from "@commontools/utils/types";
import { URI } from "@commontools/memory/interface";
import { isOpaqueRef } from "./builder/types.ts";
import { createDoc, type DocImpl, isDoc } from "./doc.ts";
import {
Expand Down Expand Up @@ -118,19 +119,19 @@ export class DocumentMap implements IDocumentMap {

getDocByEntityId<T = any>(
space: MemorySpace,
entityId: EntityId | string,
entityId: EntityId | URI,
createIfNotFound?: true,
sourceIfCreated?: DocImpl<any>,
): DocImpl<T>;
getDocByEntityId<T = any>(
space: MemorySpace,
entityId: EntityId | string,
entityId: EntityId | URI,
createIfNotFound: false,
sourceIfCreated?: DocImpl<any>,
): DocImpl<T> | undefined;
getDocByEntityId<T = any>(
space: MemorySpace,
entityId: EntityId | string,
entityId: EntityId | URI,
createIfNotFound = true,
sourceIfCreated?: DocImpl<any>,
): DocImpl<T> | undefined {
Expand Down
Loading