@dxos/echo-solid 0.8.4-main.e00bdcdb52 → 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.e00bdcdb52",
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",
@@ -27,16 +27,16 @@
27
27
  "dependencies": {
28
28
  "@effect-atom/atom": "^0.5.1",
29
29
  "@solid-primitives/utils": "^6.3.2",
30
- "@dxos/echo-atom": "0.8.4-main.e00bdcdb52",
31
- "@dxos/echo": "0.8.4-main.e00bdcdb52",
32
- "@dxos/effect-atom-solid": "0.8.4-main.e00bdcdb52"
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"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@solidjs/testing-library": "^0.8.10",
36
36
  "solid-js": "^1.9.11",
37
37
  "vite-plugin-solid": "^2.11.12",
38
- "vitest": "4.1.5",
39
- "@dxos/echo-db": "0.8.4-main.e00bdcdb52"
38
+ "vitest": "4.1.7",
39
+ "@dxos/echo-db": "0.8.4-main.effb148878"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "solid-js": "^1.9.11"
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';
package/src/useObject.ts CHANGED
@@ -302,7 +302,7 @@ export const useObjects = <T extends Obj.Unknown>(refs: MaybeAccessor<readonly R
302
302
  const subscribeToTarget = (ref: Ref.Ref<T>) => {
303
303
  const target = ref.target;
304
304
  if (target) {
305
- const key = ref.dxn.toString();
305
+ const key = ref.uri;
306
306
  if (!targetUnsubscribes.has(key)) {
307
307
  targetUnsubscribes.set(key, Obj.subscribe(target, triggerUpdate));
308
308
  }
@@ -10,9 +10,9 @@ import { Type } from '@dxos/echo';
10
10
  import { EchoTestBuilder } from '@dxos/echo-db/testing';
11
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 () => {
@@ -103,7 +103,7 @@ describe('useSchema', () => {
103
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.AnyEntity = Type.AnyEntity>(
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.AnyEntity = Type.AnyEntity>(
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.AnyEntity = Type.AnyEntity>(
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.AnyEntity = Type.AnyEntity>(
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.AnyEntity = Type.AnyEntity>(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,SAAS,GAAG,IAAI,CAAC,SAAS,OAC5D,aAAa,CAAC,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,aACtC,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":""}