Skip to content

Commit 2e15fc8

Browse files
seefeldbubik2
andauthored
feat(runner): call sync directly when not in shim; allow URIs in .sync calls (#1463)
* feat(runner): call sync directly when not in shim; allow URIs in .sync calls - Update storage.ts to call sync directly when not running in a shim environment. - Allow either EntityId or URIs on sync call (eventually we'll deprecate the former) * cleaner return value * Changes to use URI instead of EntityId in internal APIs (#1464) * Minor tweaks - Use await instead of a promise chain in Storage.syncCell. - Use URI isntead of Entity, since we also define this in memory/interface.ts. * Change IStorageProvider API to be URI based instead of EntityId as well as the BaseStorageProvider implementation and the Storage class. Moved BaseStorageProvider.toEntity into Storage.toURI, since this is the only place it's needed. Changed IStorageProvider to use URI instead of EntityId, as well as the ProviderConnection and Provider classes. Updated tests to use cell.getAsNormalizedFullLink to get the URI instead of EntityId. --------- Co-authored-by: ubik2 <ubik2@users.noreply.github.com>
1 parent aa96b0b commit 2e15fc8

File tree

11 files changed

+172
-192
lines changed

11 files changed

+172
-192
lines changed

packages/runner/integration/reconnection.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { Identity } from "@commontools/identity";
99
import { StorageManager } from "../src/storage/cache.ts";
10-
import type { SchemaContext } from "@commontools/memory/interface";
10+
import type { SchemaContext, URI } from "@commontools/memory/interface";
1111

1212
const TOOLSHED_URL = Deno.env.get("TOOLSHED_API_URL") ||
1313
"http://localhost:8000";
@@ -72,30 +72,30 @@ const storageManager3 = StorageManager.open({
7272
});
7373
const provider3 = storageManager3.open(signer.did());
7474
console.log(`Provider3 (control) connected to memory server`);
75-
75+
const uri: URI = `of:${TEST_DOC_ID}`;
7676
// Listen for updates on the test-reconnection-counter document
7777
// Note: this is not the schema subscription, its just a client-side listener
78-
provider1.sink({ "/": TEST_DOC_ID }, (value) => {
78+
provider1.sink(uri, (value) => {
7979
updateCount1++;
8080
updates1.push(value.value);
8181
console.log(`Provider1 Update #${updateCount1}:`, value.value);
8282
});
8383

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

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

9595
// Send initial value to server
9696
console.log("Sending initial value...");
9797
await provider1.send([{
98-
entityId: { "/": TEST_DOC_ID },
98+
uri,
9999
value: {
100100
value: {
101101
value: 1,
@@ -155,7 +155,7 @@ console.log(`Connected to memory server as second client`);
155155

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

160160
// Send test updates and check if subscription still works
161161
console.log("Sending test updates after disconnection...");
@@ -164,7 +164,7 @@ const intervalId = setInterval(async () => {
164164
try {
165165
// Send an update as the second
166166
const result = await provider2.send([{
167-
entityId: { "/": TEST_DOC_ID },
167+
uri,
168168
value: {
169169
value: {
170170
value: testValue++,

packages/runner/src/doc-map.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { refer } from "merkle-reference/json";
22
import { isRecord } from "@commontools/utils/types";
3+
import { URI } from "@commontools/memory/interface";
34
import { isOpaqueRef } from "./builder/types.ts";
45
import { createDoc, type DocImpl, isDoc } from "./doc.ts";
56
import {
@@ -118,19 +119,19 @@ export class DocumentMap implements IDocumentMap {
118119

119120
getDocByEntityId<T = any>(
120121
space: MemorySpace,
121-
entityId: EntityId | string,
122+
entityId: EntityId | URI,
122123
createIfNotFound?: true,
123124
sourceIfCreated?: DocImpl<any>,
124125
): DocImpl<T>;
125126
getDocByEntityId<T = any>(
126127
space: MemorySpace,
127-
entityId: EntityId | string,
128+
entityId: EntityId | URI,
128129
createIfNotFound: false,
129130
sourceIfCreated?: DocImpl<any>,
130131
): DocImpl<T> | undefined;
131132
getDocByEntityId<T = any>(
132133
space: MemorySpace,
133-
entityId: EntityId | string,
134+
entityId: EntityId | URI,
134135
createIfNotFound = true,
135136
sourceIfCreated?: DocImpl<any>,
136137
): DocImpl<T> | undefined {

0 commit comments

Comments
 (0)