@dxos/echo-solid 0.0.0 → 0.8.4-main.69d29f4
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/dist/lib/browser/index.mjs +209 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +211 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/useObject.d.ts +101 -0
- package/dist/types/src/useObject.d.ts.map +1 -0
- package/dist/types/src/useObject.test.d.ts +2 -0
- package/dist/types/src/useObject.test.d.ts.map +1 -0
- package/dist/types/src/useQuery.d.ts +14 -0
- package/dist/types/src/useQuery.d.ts.map +1 -0
- package/dist/types/src/useQuery.test.d.ts +2 -0
- package/dist/types/src/useQuery.test.d.ts.map +1 -0
- package/dist/types/src/useSchema.d.ts +14 -0
- package/dist/types/src/useSchema.d.ts.map +1 -0
- package/dist/types/src/useSchema.test.d.ts +2 -0
- package/dist/types/src/useSchema.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +10 -5
- package/src/index.ts +0 -1
- package/src/useObject.test.tsx +2 -2
- package/src/useObject.ts +218 -73
- package/src/useQuery.test.tsx +17 -17
- package/src/useRef.test.tsx +0 -247
- package/src/useRef.ts +0 -48
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type MaybeAccessor } from '@solid-primitives/utils';
|
|
2
|
+
import { type Accessor } from 'solid-js';
|
|
3
|
+
import { Obj, Ref } from '@dxos/echo';
|
|
4
|
+
export interface ObjectUpdateCallback<T> {
|
|
5
|
+
(update: (obj: Obj.Mutable<T>) => void): void;
|
|
6
|
+
(update: (obj: Obj.Mutable<T>) => Obj.Mutable<T>): void;
|
|
7
|
+
}
|
|
8
|
+
export interface ObjectPropUpdateCallback<T> {
|
|
9
|
+
(update: (value: Obj.Mutable<T>) => void): void;
|
|
10
|
+
(update: (value: Obj.Mutable<T>) => Obj.Mutable<T>): void;
|
|
11
|
+
(newValue: T): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Helper type to conditionally include undefined in return type only if input includes undefined.
|
|
15
|
+
* Only adds undefined if T includes undefined AND R doesn't already include undefined.
|
|
16
|
+
*/
|
|
17
|
+
type ConditionalUndefined<T, R> = [T] extends [Exclude<T, undefined>] ? R : [R] extends [Exclude<R, undefined>] ? R | undefined : R;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to a Ref's target object.
|
|
20
|
+
* Automatically dereferences the ref and handles async loading.
|
|
21
|
+
* Returns undefined if the ref hasn't loaded yet.
|
|
22
|
+
*
|
|
23
|
+
* @param ref - The Ref to dereference and subscribe to (can be reactive)
|
|
24
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
25
|
+
*/
|
|
26
|
+
export declare function useObject<T>(ref: MaybeAccessor<Ref.Ref<T>>): [Accessor<T | undefined>, ObjectUpdateCallback<T>];
|
|
27
|
+
/**
|
|
28
|
+
* Subscribe to a Ref's target object that may be undefined.
|
|
29
|
+
* Returns undefined if the ref is undefined or hasn't loaded yet.
|
|
30
|
+
*
|
|
31
|
+
* @param ref - The Ref to dereference and subscribe to (can be undefined/reactive)
|
|
32
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
33
|
+
*/
|
|
34
|
+
export declare function useObject<T>(ref: MaybeAccessor<Ref.Ref<T> | undefined>): [Accessor<T | undefined>, ObjectUpdateCallback<T>];
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to an entire Echo object.
|
|
37
|
+
* Returns the current object value accessor and an update callback.
|
|
38
|
+
*
|
|
39
|
+
* @param obj - The Echo object to subscribe to (can be reactive)
|
|
40
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
41
|
+
*/
|
|
42
|
+
export declare function useObject<T extends Obj.Unknown>(obj: MaybeAccessor<T>): [Accessor<ConditionalUndefined<T, T>>, ObjectUpdateCallback<T>];
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to an entire Echo object that may be undefined.
|
|
45
|
+
* Returns undefined if the object is undefined.
|
|
46
|
+
*
|
|
47
|
+
* @param obj - The Echo object to subscribe to (can be undefined/reactive)
|
|
48
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
49
|
+
*/
|
|
50
|
+
export declare function useObject<T extends Obj.Unknown>(obj: MaybeAccessor<T | undefined>): [Accessor<ConditionalUndefined<T, T>>, ObjectUpdateCallback<T>];
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to a specific property of an Echo object.
|
|
53
|
+
* Returns the current property value accessor and an update callback.
|
|
54
|
+
*
|
|
55
|
+
* @param obj - The Echo object to subscribe to (can be reactive)
|
|
56
|
+
* @param property - Property key to subscribe to
|
|
57
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
58
|
+
*/
|
|
59
|
+
export declare function useObject<T extends Obj.Unknown, K extends keyof T>(obj: MaybeAccessor<T>, property: K): [Accessor<T[K]>, ObjectPropUpdateCallback<T[K]>];
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to a specific property of an Echo object that may be undefined.
|
|
62
|
+
* Returns undefined if the object is undefined.
|
|
63
|
+
*
|
|
64
|
+
* @param obj - The Echo object to subscribe to (can be undefined/reactive)
|
|
65
|
+
* @param property - Property key to subscribe to
|
|
66
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
67
|
+
*/
|
|
68
|
+
export declare function useObject<T extends Obj.Unknown, K extends keyof T>(obj: MaybeAccessor<T | undefined>, property: K): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];
|
|
69
|
+
/**
|
|
70
|
+
* Subscribe to a specific property of a Ref's target object.
|
|
71
|
+
* Automatically dereferences the ref and handles async loading.
|
|
72
|
+
* Returns undefined if the ref hasn't loaded yet.
|
|
73
|
+
*
|
|
74
|
+
* @param ref - The Ref to dereference and subscribe to (can be reactive)
|
|
75
|
+
* @param property - Property key to subscribe to
|
|
76
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
77
|
+
*/
|
|
78
|
+
export declare function useObject<T, K extends keyof T>(ref: MaybeAccessor<Ref.Ref<T>>, property: K): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];
|
|
79
|
+
/**
|
|
80
|
+
* Subscribe to a specific property of a Ref's target object that may be undefined.
|
|
81
|
+
* Returns undefined if the ref is undefined or hasn't loaded yet.
|
|
82
|
+
*
|
|
83
|
+
* @param ref - The Ref to dereference and subscribe to (can be undefined/reactive)
|
|
84
|
+
* @param property - Property key to subscribe to
|
|
85
|
+
* @returns A tuple of [accessor, updateCallback]
|
|
86
|
+
*/
|
|
87
|
+
export declare function useObject<T, K extends keyof T>(ref: MaybeAccessor<Ref.Ref<T> | undefined>, property: K): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];
|
|
88
|
+
/**
|
|
89
|
+
* Subscribe to multiple Refs' target objects.
|
|
90
|
+
* Automatically dereferences each ref and handles async loading.
|
|
91
|
+
* Returns an accessor to an array of loaded snapshots (filtering out undefined values).
|
|
92
|
+
*
|
|
93
|
+
* This hook is useful for aggregate computations like counts or filtering
|
|
94
|
+
* across multiple refs without using .target directly.
|
|
95
|
+
*
|
|
96
|
+
* @param refs - Array of Refs to dereference and subscribe to (can be reactive)
|
|
97
|
+
* @returns Accessor to array of loaded target snapshots (excludes unloaded refs)
|
|
98
|
+
*/
|
|
99
|
+
export declare const useObjects: <T extends Obj.Unknown>(refs: MaybeAccessor<readonly Ref.Ref<T>[]>) => Accessor<T[]>;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=useObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObject.d.ts","sourceRoot":"","sources":["../../../src/useObject.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,KA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BAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhE;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC5C,GAAG,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAC9B,QAAQ,EAAE,CAAC,GACV,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC5C,GAAG,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAC1C,QAAQ,EAAE,CAAC,GACV,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAiJhE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAG,QAAQ,CAAC,CAAC,EAAE,CAmE1G,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObject.test.d.ts","sourceRoot":"","sources":["../../../src/useObject.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import { type Database, type Entity, Filter, Query } from '@dxos/echo';
|
|
3
|
+
type MaybeAccessor<T> = T | Accessor<T>;
|
|
4
|
+
/**
|
|
5
|
+
* Create a reactive query subscription.
|
|
6
|
+
* Accepts either values or accessors for resource and query/filter.
|
|
7
|
+
*
|
|
8
|
+
* @param resource - The database or queryable resource (can be reactive)
|
|
9
|
+
* @param queryOrFilter - The query or filter to apply (can be reactive)
|
|
10
|
+
* @returns An accessor that returns the current query results
|
|
11
|
+
*/
|
|
12
|
+
export declare const useQuery: <T extends Entity.Any = Entity.Any>(resource: MaybeAccessor<Database.Queryable | undefined>, queryOrFilter: MaybeAccessor<Query.Any | Filter.Any>) => Accessor<T[]>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/useQuery.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAqD,MAAM,UAAU,CAAC;AAE5F,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAIvE,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,EACxD,UAAU,aAAa,CAAC,QAAQ,CAAC,SAAS,GAAG,SAAS,CAAC,EACvD,eAAe,aAAa,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,KACnD,QAAQ,CAAC,CAAC,EAAE,CAqCd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.test.d.ts","sourceRoot":"","sources":["../../../src/useQuery.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchema.test.d.ts","sourceRoot":"","sources":["../../../src/useSchema.test.tsx"],"names":[],"mappings":""}
|