@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/LICENSE +102 -5
- package/dist/lib/neutral/index.mjs +7 -7
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useType.d.ts +14 -0
- package/dist/types/src/useType.d.ts.map +1 -0
- package/dist/types/src/useType.test.d.ts +2 -0
- package/dist/types/src/useType.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/index.ts +1 -1
- package/src/useObject.ts +1 -1
- package/src/{useSchema.test.tsx → useType.test.tsx} +18 -18
- package/src/{useSchema.ts → useType.ts} +10 -10
- package/dist/types/src/useSchema.d.ts +0 -14
- package/dist/types/src/useSchema.d.ts.map +0 -1
- package/dist/types/src/useSchema.test.d.ts +0 -2
- package/dist/types/src/useSchema.test.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-solid",
|
|
3
|
-
"version": "0.8.4-main.
|
|
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": "
|
|
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
|
|
31
|
-
"@dxos/echo": "0.8.4-main.
|
|
32
|
-
"@dxos/effect-atom-solid": "0.8.4-main.
|
|
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.
|
|
39
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
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
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.
|
|
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 {
|
|
13
|
+
import { useType } from './useType';
|
|
14
14
|
|
|
15
|
-
describe('
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
175
|
+
let typename: string | undefined = Type.getTypename(registeredSchema)!;
|
|
176
176
|
|
|
177
177
|
function TestComponent() {
|
|
178
|
-
const schema =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
17
|
-
* @returns An accessor that returns the current
|
|
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
|
|
19
|
+
export const useType = (
|
|
20
20
|
db?: MaybeAccessor<Database.Database | undefined>,
|
|
21
21
|
typename?: MaybeAccessor<string | undefined>,
|
|
22
|
-
): Accessor<
|
|
23
|
-
// Derive the
|
|
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
|
|
34
|
-
const [
|
|
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
|
-
|
|
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
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSchema.test.d.ts","sourceRoot":"","sources":["../../../src/useSchema.test.tsx"],"names":[],"mappings":""}
|