@dxos/echo-solid 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-solid",
3
- "version": "0.8.4-main.ef1bc66f44",
3
+ "version": "0.8.4-main.effb148878",
4
4
  "description": "Solid.js integration for ECHO.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/dxos/dxos"
10
10
  },
11
- "license": "MIT",
11
+ "license": "FSL-1.1-Apache-2.0",
12
12
  "author": "DXOS.org",
13
13
  "sideEffects": false,
14
14
  "type": "module",
@@ -20,9 +20,6 @@
20
20
  }
21
21
  },
22
22
  "types": "dist/types/src/index.d.ts",
23
- "typesVersions": {
24
- "*": {}
25
- },
26
23
  "files": [
27
24
  "dist",
28
25
  "src"
@@ -30,19 +27,19 @@
30
27
  "dependencies": {
31
28
  "@effect-atom/atom": "^0.5.1",
32
29
  "@solid-primitives/utils": "^6.3.2",
33
- "@dxos/echo": "0.8.4-main.ef1bc66f44",
34
- "@dxos/echo-atom": "0.8.4-main.ef1bc66f44",
35
- "@dxos/effect-atom-solid": "0.8.4-main.ef1bc66f44"
30
+ "@dxos/echo": "0.8.4-main.effb148878",
31
+ "@dxos/echo-atom": "0.8.4-main.effb148878",
32
+ "@dxos/effect-atom-solid": "0.8.4-main.effb148878"
36
33
  },
37
34
  "devDependencies": {
38
35
  "@solidjs/testing-library": "^0.8.10",
39
- "solid-js": "^1.9.9",
40
- "vite-plugin-solid": "^2.11.10",
41
- "vitest": "3.2.4",
42
- "@dxos/echo-db": "0.8.4-main.ef1bc66f44"
36
+ "solid-js": "^1.9.11",
37
+ "vite-plugin-solid": "^2.11.12",
38
+ "vitest": "4.1.7",
39
+ "@dxos/echo-db": "0.8.4-main.effb148878"
43
40
  },
44
41
  "peerDependencies": {
45
- "solid-js": "^1.9.9"
42
+ "solid-js": "^1.9.11"
46
43
  },
47
44
  "publishConfig": {
48
45
  "access": "public"
package/src/index.ts CHANGED
@@ -4,4 +4,4 @@
4
4
 
5
5
  export * from './useObject';
6
6
  export * from './useQuery';
7
- export * from './useSchema';
7
+ export * from './useType';
@@ -8,8 +8,8 @@ import { describe, expect, test } from 'vitest';
8
8
 
9
9
  import type { Entity } from '@dxos/echo';
10
10
  import { Obj } from '@dxos/echo';
11
- import { TestSchema } from '@dxos/echo/testing';
12
11
  import { createObject } from '@dxos/echo-db';
12
+ import { TestSchema } from '@dxos/echo/testing';
13
13
  import { Registry } from '@dxos/effect-atom-solid';
14
14
  import { RegistryProvider } from '@dxos/effect-atom-solid';
15
15
 
@@ -86,9 +86,9 @@ describe('useObject', () => {
86
86
  expect(result).toBe('Test');
87
87
  expect(getByTestId('value').textContent).toBe('Test');
88
88
 
89
- // Update the property via Obj.change.
90
- Obj.change(obj, (o) => {
91
- o.name = 'Updated';
89
+ // Update the property via Obj.update.
90
+ Obj.update(obj, (obj) => {
91
+ obj.name = 'Updated';
92
92
  });
93
93
 
94
94
  // Wait for reactivity to update.
@@ -118,9 +118,9 @@ describe('useObject', () => {
118
118
  expect(valueAccessor?.()?.name).toBe('Test');
119
119
  expect(getByTestId('name').textContent).toBe('Test');
120
120
 
121
- // Update a property via Obj.change.
122
- Obj.change(obj, (o) => {
123
- o.name = 'Updated';
121
+ // Update a property via Obj.update.
122
+ Obj.update(obj, (obj) => {
123
+ obj.name = 'Updated';
124
124
  });
125
125
 
126
126
  // Wait for reactivity to update.
@@ -149,9 +149,9 @@ describe('useObject', () => {
149
149
 
150
150
  expect(result).toBe('Test');
151
151
 
152
- // Update a different property via Obj.change.
153
- Obj.change(obj, (o) => {
154
- o.email = 'newemail@example.com';
152
+ // Update a different property via Obj.update.
153
+ Obj.update(obj, (obj) => {
154
+ obj.email = 'newemail@example.com';
155
155
  });
156
156
 
157
157
  // Name should still be 'Test'.
package/src/useObject.ts CHANGED
@@ -160,20 +160,20 @@ export function useObject<T extends Obj.Unknown, K extends keyof T>(
160
160
  return;
161
161
  }
162
162
 
163
- Obj.change(obj, (o: any) => {
163
+ Obj.update(obj, (obj: any) => {
164
164
  if (typeof updateOrValue === 'function') {
165
- const returnValue = (updateOrValue as (obj: unknown) => unknown)(property !== undefined ? o[property] : o);
165
+ const returnValue = (updateOrValue as (obj: unknown) => unknown)(property !== undefined ? obj[property] : obj);
166
166
  if (returnValue !== undefined) {
167
167
  if (property === undefined) {
168
168
  throw new Error('Cannot re-assign the entire object');
169
169
  }
170
- o[property] = returnValue;
170
+ obj[property] = returnValue;
171
171
  }
172
172
  } else {
173
173
  if (property === undefined) {
174
174
  throw new Error('Cannot re-assign the entire object');
175
175
  }
176
- o[property] = updateOrValue;
176
+ obj[property] = updateOrValue;
177
177
  }
178
178
  });
179
179
  };
@@ -182,8 +182,9 @@ export function useObject<T extends Obj.Unknown, K extends keyof T>(
182
182
  // For property subscriptions on refs, we subscribe to trigger re-render on load.
183
183
  useObjectValue(registry, objOrRef);
184
184
  return [useObjectProperty(registry, liveObj, property), callback as ObjectPropUpdateCallback<T[K]>];
185
+ } else {
186
+ return [useObjectValue(registry, objOrRef), callback as ObjectUpdateCallback<T>];
185
187
  }
186
- return [useObjectValue(registry, objOrRef), callback as ObjectUpdateCallback<T>];
187
188
  }
188
189
 
189
190
  /**
@@ -301,7 +302,7 @@ export const useObjects = <T extends Obj.Unknown>(refs: MaybeAccessor<readonly R
301
302
  const subscribeToTarget = (ref: Ref.Ref<T>) => {
302
303
  const target = ref.target;
303
304
  if (target) {
304
- const key = ref.dxn.toString();
305
+ const key = ref.uri;
305
306
  if (!targetUnsubscribes.has(key)) {
306
307
  targetUnsubscribes.set(key, Obj.subscribe(target, triggerUpdate));
307
308
  }
@@ -7,8 +7,8 @@ import { type JSX, createSignal } from 'solid-js';
7
7
  import { afterEach, beforeEach, describe, expect, test } from 'vitest';
8
8
 
9
9
  import { Filter, Obj, Query } from '@dxos/echo';
10
- import { TestSchema } from '@dxos/echo/testing';
11
10
  import { EchoTestBuilder } from '@dxos/echo-db/testing';
11
+ import { TestSchema } from '@dxos/echo/testing';
12
12
 
13
13
  import { useQuery } from './useQuery';
14
14
 
@@ -7,12 +7,12 @@ import { type JSX, createMemo } from 'solid-js';
7
7
  import { afterEach, beforeEach, describe, expect, test } from 'vitest';
8
8
 
9
9
  import { Type } from '@dxos/echo';
10
- import { TestSchema } from '@dxos/echo/testing';
11
10
  import { EchoTestBuilder } from '@dxos/echo-db/testing';
11
+ import { TestSchema } from '@dxos/echo/testing';
12
12
 
13
- import { useSchema } from './useSchema';
13
+ import { useType } from './useType';
14
14
 
15
- describe('useSchema', () => {
15
+ describe('useType', () => {
16
16
  let testBuilder: EchoTestBuilder;
17
17
  let db: any;
18
18
 
@@ -30,7 +30,7 @@ describe('useSchema', () => {
30
30
  let result: any;
31
31
 
32
32
  render(() => {
33
- const schema = useSchema(undefined, 'dxos.test.Person');
33
+ const schema = useType(undefined, 'dxos.test.Person');
34
34
  result = schema();
35
35
  return (<div>test</div>) as JSX.Element;
36
36
  });
@@ -42,7 +42,7 @@ describe('useSchema', () => {
42
42
  let result: any;
43
43
 
44
44
  render(() => {
45
- const schema = useSchema(db, undefined);
45
+ const schema = useType(db, undefined);
46
46
  result = schema();
47
47
  return (<div>test</div>) as JSX.Element;
48
48
  });
@@ -54,7 +54,7 @@ describe('useSchema', () => {
54
54
  let result: any;
55
55
 
56
56
  render(() => {
57
- const schema = useSchema(db, 'dxos.test.NonExistent');
57
+ const schema = useType(db, 'dxos.test.NonExistent');
58
58
  result = schema();
59
59
  return (<div>test</div>) as JSX.Element;
60
60
  });
@@ -72,7 +72,7 @@ describe('useSchema', () => {
72
72
  let schemaAccessor: (() => any) | undefined;
73
73
 
74
74
  function TestComponent() {
75
- const schema = useSchema(db, registeredSchema.typename);
75
+ const schema = useType(db, Type.getTypename(registeredSchema)!);
76
76
  schemaAccessor = schema;
77
77
  const t = createMemo(() => {
78
78
  const s = schema();
@@ -84,13 +84,13 @@ describe('useSchema', () => {
84
84
  const { getByTestId } = render(() => <TestComponent />);
85
85
 
86
86
  await waitFor(() => {
87
- expect(getByTestId('typename').textContent).toBe(registeredSchema.typename);
87
+ expect(getByTestId('typename').textContent).toBe(Type.getTypename(registeredSchema)!);
88
88
  });
89
89
 
90
90
  // Get the actual result from the accessor
91
91
  const result = schemaAccessor?.();
92
92
  expect(result).toBeDefined();
93
- expect(result?.typename).toBe(registeredSchema.typename);
93
+ expect(Type.getTypename(result!)).toBe(Type.getTypename(registeredSchema)!);
94
94
  });
95
95
 
96
96
  test.skip('updates when schema is added', async () => {
@@ -100,10 +100,10 @@ describe('useSchema', () => {
100
100
  // The runtime registry query subscription doesn't fire when schemas are registered.
101
101
  // See: packages/core/echo/echo-db/src/proxy-db/runtime-schema-registry.ts:57
102
102
  let schemaAccessor: (() => any) | undefined;
103
- const typename = 'example.com/type/Person';
103
+ const typename = 'com.example.type.person';
104
104
 
105
105
  function TestComponent() {
106
- const schema = useSchema(db, typename);
106
+ const schema = useType(db, typename);
107
107
  schemaAccessor = schema;
108
108
  const t = createMemo(() => {
109
109
  const s = schema();
@@ -125,13 +125,13 @@ describe('useSchema', () => {
125
125
  // The schema registry query should pick up the new schema
126
126
  // It reads from db.graph.schemaRegistry.schemas which should include the newly registered schema
127
127
  await waitFor(() => {
128
- expect(getByTestId('typename').textContent).toBe(registeredSchema.typename);
128
+ expect(getByTestId('typename').textContent).toBe(Type.getTypename(registeredSchema)!);
129
129
  });
130
130
 
131
131
  // Get the actual result from the accessor
132
132
  const result = schemaAccessor?.();
133
133
  expect(result).toBeDefined();
134
- expect(result?.typename).toBe(registeredSchema.typename);
134
+ expect(Type.getTypename(result!)).toBe(Type.getTypename(registeredSchema)!);
135
135
  });
136
136
 
137
137
  test('accepts reactive database accessor', async () => {
@@ -141,7 +141,7 @@ describe('useSchema', () => {
141
141
  let dbAccessor: any = db;
142
142
 
143
143
  function TestComponent() {
144
- const schema = useSchema(() => dbAccessor, registeredSchema.typename);
144
+ const schema = useType(() => dbAccessor, Type.getTypename(registeredSchema)!);
145
145
  schemaAccessor = schema;
146
146
  const t = createMemo(() => {
147
147
  const s = schema();
@@ -153,7 +153,7 @@ describe('useSchema', () => {
153
153
  const { getByTestId } = render(() => <TestComponent />);
154
154
 
155
155
  await waitFor(() => {
156
- expect(getByTestId('typename').textContent).toBe(registeredSchema.typename);
156
+ expect(getByTestId('typename').textContent).toBe(Type.getTypename(registeredSchema)!);
157
157
  });
158
158
 
159
159
  // Get the actual result from the accessor
@@ -172,10 +172,10 @@ describe('useSchema', () => {
172
172
  const [registeredSchema] = await db.schemaRegistry.register([TestSchema.Person]);
173
173
 
174
174
  let schemaAccessor: (() => any) | undefined;
175
- let typename: string | undefined = registeredSchema.typename;
175
+ let typename: string | undefined = Type.getTypename(registeredSchema)!;
176
176
 
177
177
  function TestComponent() {
178
- const schema = useSchema(db, () => typename);
178
+ const schema = useType(db, () => typename);
179
179
  schemaAccessor = schema;
180
180
  const t = createMemo(() => {
181
181
  const s = schema();
@@ -187,20 +187,20 @@ describe('useSchema', () => {
187
187
  const { getByTestId } = render(() => <TestComponent />);
188
188
 
189
189
  await waitFor(() => {
190
- expect(getByTestId('typename').textContent).toBe(registeredSchema.typename);
190
+ expect(getByTestId('typename').textContent).toBe(Type.getTypename(registeredSchema)!);
191
191
  });
192
192
 
193
193
  // Get the actual result from the accessor
194
194
  let result = schemaAccessor?.();
195
195
  expect(result).toBeDefined();
196
- expect(result?.typename).toBe(registeredSchema.typename);
196
+ expect(Type.getTypename(result!)).toBe(Type.getTypename(registeredSchema)!);
197
197
 
198
198
  // Change typename
199
199
  typename = undefined;
200
200
 
201
201
  await waitFor(() => {
202
202
  // Should keep previous value when typename becomes undefined
203
- expect(getByTestId('typename').textContent).toBe(registeredSchema.typename);
203
+ expect(getByTestId('typename').textContent).toBe(Type.getTypename(registeredSchema)!);
204
204
  });
205
205
  result = schemaAccessor?.();
206
206
  expect(result).toBeDefined();
@@ -9,18 +9,18 @@ import { type Database, type Type } from '@dxos/echo';
9
9
  type MaybeAccessor<T> = T | Accessor<T>;
10
10
 
11
11
  /**
12
- * Subscribe to and retrieve schema changes from a database's schema registry.
12
+ * Subscribe to and retrieve type changes from a database's schema registry.
13
13
  * Accepts either values or accessors for db and typename.
14
14
  *
15
15
  * @param db - The database instance (can be reactive)
16
- * @param typename - The schema typename to query (can be reactive)
17
- * @returns An accessor that returns the current schema or undefined
16
+ * @param typename - The typename to query (can be reactive)
17
+ * @returns An accessor that returns the current type or undefined
18
18
  */
19
- export const useSchema = <T extends Type.Entity.Any = Type.Entity.Any>(
19
+ export const useType = (
20
20
  db?: MaybeAccessor<Database.Database | undefined>,
21
21
  typename?: MaybeAccessor<string | undefined>,
22
- ): Accessor<T | undefined> => {
23
- // Derive the schema query reactively
22
+ ): Accessor<Type.Type | undefined> => {
23
+ // Derive the type query reactively
24
24
  const query = createMemo(() => {
25
25
  const resolvedDb = typeof db === 'function' ? db() : db;
26
26
  const resolvedTypename = typeof typename === 'function' ? typename() : typename;
@@ -30,8 +30,8 @@ export const useSchema = <T extends Type.Entity.Any = Type.Entity.Any>(
30
30
  return resolvedDb.schemaRegistry.query({ typename: resolvedTypename, location: ['database', 'runtime'] });
31
31
  });
32
32
 
33
- // Store the current schema in a signal
34
- const [schema, setSchema] = createSignal<T | undefined>(undefined);
33
+ // Store the current type in a signal
34
+ const [type, setType] = createSignal<Type.Type | undefined>(undefined);
35
35
 
36
36
  // Subscribe to query changes
37
37
  createEffect(() => {
@@ -47,7 +47,7 @@ export const useSchema = <T extends Type.Entity.Any = Type.Entity.Any>(
47
47
  () => {
48
48
  // Access results inside the callback to ensure query is running
49
49
  const results = q.results;
50
- setSchema(() => results[0] as T | undefined);
50
+ setType(() => results[0]);
51
51
  },
52
52
  { fire: true },
53
53
  );
@@ -55,5 +55,5 @@ export const useSchema = <T extends Type.Entity.Any = Type.Entity.Any>(
55
55
  onCleanup(unsubscribe);
56
56
  });
57
57
 
58
- return schema;
58
+ return type;
59
59
  };
@@ -1,14 +0,0 @@
1
- import { type Accessor } from 'solid-js';
2
- import { type Database, type Type } from '@dxos/echo';
3
- type MaybeAccessor<T> = T | Accessor<T>;
4
- /**
5
- * Subscribe to and retrieve schema changes from a database's schema registry.
6
- * Accepts either values or accessors for db and typename.
7
- *
8
- * @param db - The database instance (can be reactive)
9
- * @param typename - The schema typename to query (can be reactive)
10
- * @returns An accessor that returns the current schema or undefined
11
- */
12
- export declare const useSchema: <T extends Type.Entity.Any = Type.Entity.Any>(db?: MaybeAccessor<Database.Database | undefined>, typename?: MaybeAccessor<string | undefined>) => Accessor<T | undefined>;
13
- export {};
14
- //# sourceMappingURL=useSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSchema.d.ts","sourceRoot":"","sources":["../../../src/useSchema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAqD,MAAM,UAAU,CAAC;AAE5F,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEtD,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExC;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EACnE,KAAK,aAAa,CAAC,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,EACjD,WAAW,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,KAC3C,QAAQ,CAAC,CAAC,GAAG,SAAS,CAqCxB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=useSchema.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useSchema.test.d.ts","sourceRoot":"","sources":["../../../src/useSchema.test.tsx"],"names":[],"mappings":""}