@dxos/app-graph 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f

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/src/graph.ts CHANGED
@@ -389,7 +389,7 @@ export class Graph implements WritableGraph {
389
389
  // }
390
390
  // }
391
391
 
392
- expand(id: string, relation: Relation = 'outbound') {
392
+ expand(id: string, relation: Relation = 'outbound'): void {
393
393
  const key = `${id}$${relation}`;
394
394
  const expanded = Record.get(this._expanded, key).pipe(Option.getOrElse(() => false));
395
395
  log('expand', { key, expanded });
@@ -399,13 +399,13 @@ export class Graph implements WritableGraph {
399
399
  }
400
400
  }
401
401
 
402
- addNodes(nodes: NodeArg<any, Record<string, any>>[]) {
402
+ addNodes(nodes: NodeArg<any, Record<string, any>>[]): void {
403
403
  Rx.batch(() => {
404
404
  nodes.map((node) => this.addNode(node));
405
405
  });
406
406
  }
407
407
 
408
- addNode({ nodes, edges, ...nodeArg }: NodeArg<any, Record<string, any>>) {
408
+ addNode({ nodes, edges, ...nodeArg }: NodeArg<any, Record<string, any>>): void {
409
409
  const { id, type, data = null, properties = {} } = nodeArg;
410
410
  const nodeRx = this._node(id);
411
411
  const node = this._registry.get(nodeRx);
@@ -414,7 +414,7 @@ export class Graph implements WritableGraph {
414
414
  const typeChanged = node.type !== type;
415
415
  const dataChanged = node.data !== data;
416
416
  const propertiesChanged = Object.keys(properties).some((key) => node.properties[key] !== properties[key]);
417
- log('existing node', { typeChanged, dataChanged, propertiesChanged });
417
+ log('existing node', { id, typeChanged, dataChanged, propertiesChanged });
418
418
  if (typeChanged || dataChanged || propertiesChanged) {
419
419
  log('updating node', { id, type, data, properties });
420
420
  const newNode = Option.some({ ...node, type, data, properties: { ...node.properties, ...properties } });
@@ -443,13 +443,13 @@ export class Graph implements WritableGraph {
443
443
  }
444
444
  }
445
445
 
446
- removeNodes(ids: string[], edges = false) {
446
+ removeNodes(ids: string[], edges = false): void {
447
447
  Rx.batch(() => {
448
448
  ids.map((id) => this.removeNode(id, edges));
449
449
  });
450
450
  }
451
451
 
452
- removeNode(id: string, edges = false) {
452
+ removeNode(id: string, edges = false): void {
453
453
  const nodeRx = this._node(id);
454
454
  // TODO(wittjosiah): Is there a way to mark these rx values for garbage collection?
455
455
  this._registry.set(nodeRx, Option.none());
@@ -468,13 +468,13 @@ export class Graph implements WritableGraph {
468
468
  this._onRemoveNode?.(id);
469
469
  }
470
470
 
471
- addEdges(edges: Edge[]) {
471
+ addEdges(edges: Edge[]): void {
472
472
  Rx.batch(() => {
473
473
  edges.map((edge) => this.addEdge(edge));
474
474
  });
475
475
  }
476
476
 
477
- addEdge(edgeArg: Edge) {
477
+ addEdge(edgeArg: Edge): void {
478
478
  const sourceRx = this._edges(edgeArg.source);
479
479
  const source = this._registry.get(sourceRx);
480
480
  if (!source.outbound.includes(edgeArg.target)) {
@@ -490,13 +490,13 @@ export class Graph implements WritableGraph {
490
490
  }
491
491
  }
492
492
 
493
- removeEdges(edges: Edge[], removeOrphans = false) {
493
+ removeEdges(edges: Edge[], removeOrphans = false): void {
494
494
  Rx.batch(() => {
495
495
  edges.map((edge) => this.removeEdge(edge, removeOrphans));
496
496
  });
497
497
  }
498
498
 
499
- removeEdge(edgeArg: Edge, removeOrphans = false) {
499
+ removeEdge(edgeArg: Edge, removeOrphans = false): void {
500
500
  const sourceRx = this._edges(edgeArg.source);
501
501
  const source = this._registry.get(sourceRx);
502
502
  if (source.outbound.includes(edgeArg.target)) {
@@ -527,7 +527,7 @@ export class Graph implements WritableGraph {
527
527
  }
528
528
  }
529
529
 
530
- sortEdges(id: string, relation: Relation, order: string[]) {
530
+ sortEdges(id: string, relation: Relation, order: string[]): void {
531
531
  const edgesRx = this._edges(id);
532
532
  const edges = this._registry.get(edgesRx);
533
533
  const unsorted = edges[relation].filter((id) => !order.includes(id)) ?? [];
@@ -579,7 +579,7 @@ export class Graph implements WritableGraph {
579
579
  async waitForPath(
580
580
  params: { source?: string; target: string },
581
581
  { timeout = 5_000, interval = 500 }: { timeout?: number; interval?: number } = {},
582
- ) {
582
+ ): Promise<string[]> {
583
583
  const path = this.getPath(params);
584
584
  if (Option.isSome(path)) {
585
585
  return path.value;
@@ -88,7 +88,7 @@ describe('signals integration', () => {
88
88
  await peer.reload();
89
89
  {
90
90
  await using db = await peer.openLastDatabase();
91
- const outer = (await db.query({ id: outerId }).first()) as any;
91
+ const outer = (await db.query(Filter.ids(outerId)).first()) as any;
92
92
  const innerRx = rxFromSignal(() => outer.inner.target);
93
93
 
94
94
  const loaded = new Trigger();
@@ -128,7 +128,7 @@ describe('signals integration', () => {
128
128
 
129
129
  {
130
130
  await using db = await peer.openLastDatabase();
131
- const outer = (await db.query({ id: outerId }).first()) as any;
131
+ const outer = (await db.query(Filter.ids(outerId)).first()) as any;
132
132
  const innerRx = rxFromSignal(() => outer.inner.target);
133
133
  const inner = registry.get(innerRx);
134
134
  expect(inner).to.eq(undefined);
@@ -9,7 +9,17 @@ import { Pause, Play, Plus, Timer } from '@phosphor-icons/react';
9
9
  import { Option, pipe } from 'effect';
10
10
  import React, { useEffect, useMemo, useState } from 'react';
11
11
 
12
- import { live, isSpace, Query, type QueryResult, type Space, SpaceState, Expando, type Live } from '@dxos/client/echo';
12
+ import {
13
+ live,
14
+ isSpace,
15
+ Query,
16
+ type QueryResult,
17
+ type Space,
18
+ SpaceState,
19
+ Expando,
20
+ type Live,
21
+ Filter,
22
+ } from '@dxos/client/echo';
13
23
  import { faker } from '@dxos/random';
14
24
  import { type Client, useClient } from '@dxos/react-client';
15
25
  import { withClientProvider } from '@dxos/react-client/testing';
@@ -117,7 +127,9 @@ const getRandomSpace = (client: Client): Space | undefined => {
117
127
 
118
128
  const getSpaceWithObjects = async (client: Client): Promise<Space | undefined> => {
119
129
  const readySpaces = client.spaces.get().filter((space) => space.state.get() === SpaceState.SPACE_READY);
120
- const spaceQueries = await Promise.all(readySpaces.map((space) => space.db.query({ type: 'test' }).run()));
130
+ const spaceQueries = await Promise.all(
131
+ readySpaces.map((space) => space.db.query(Filter.type(Expando, { type: 'test' })).run()),
132
+ );
121
133
  const spaces = readySpaces.filter((space, index) => spaceQueries[index].objects.length > 0);
122
134
  return spaces[Math.floor(Math.random() * spaces.length)];
123
135
  };
@@ -147,7 +159,7 @@ const runAction = async (client: Client, action: Action) => {
147
159
  case Action.REMOVE_OBJECT: {
148
160
  const space = await getSpaceWithObjects(client);
149
161
  if (space) {
150
- const { objects } = await space.db.query({ type: 'test' }).run();
162
+ const { objects } = await space.db.query(Filter.type(Expando, { type: 'test' })).run();
151
163
  space.db.remove(objects[Math.floor(Math.random() * objects.length)]);
152
164
  }
153
165
  break;
@@ -156,7 +168,7 @@ const runAction = async (client: Client, action: Action) => {
156
168
  case Action.RENAME_OBJECT: {
157
169
  const space = await getSpaceWithObjects(client);
158
170
  if (space) {
159
- const { objects } = await space.db.query({ type: 'test' }).run();
171
+ const { objects } = await space.db.query(Filter.type(Expando, { type: 'test' })).run();
160
172
  objects[Math.floor(Math.random() * objects.length)].name = faker.commerce.productName();
161
173
  }
162
174
  break;