@dxos/echo-react 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 +153 -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 +155 -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 +104 -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.__test.d.ts +1 -0
- package/dist/types/src/useQuery.__test.d.ts.map +1 -0
- package/dist/types/src/useQuery.d.ts +11 -0
- package/dist/types/src/useQuery.d.ts.map +1 -0
- package/dist/types/src/useSchema.d.ts +6 -0
- package/dist/types/src/useSchema.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +10 -6
- package/src/useObject.ts +79 -91
- package/src/useQuery.__test.tsx +7 -6
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// src/useQuery.ts
|
|
2
|
+
import { useMemo, useSyncExternalStore } from "react";
|
|
3
|
+
import { Filter, Query } from "@dxos/echo";
|
|
4
|
+
var EMPTY_ARRAY = [];
|
|
5
|
+
var noop = () => {
|
|
6
|
+
};
|
|
7
|
+
var useQuery = (resource, queryOrFilter) => {
|
|
8
|
+
const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;
|
|
9
|
+
const { getObjects, subscribe } = useMemo(() => {
|
|
10
|
+
let queryResult = void 0;
|
|
11
|
+
if (resource) {
|
|
12
|
+
queryResult = resource.query(query);
|
|
13
|
+
}
|
|
14
|
+
let subscribed = false;
|
|
15
|
+
return {
|
|
16
|
+
getObjects: () => subscribed && queryResult ? queryResult.results : EMPTY_ARRAY,
|
|
17
|
+
subscribe: (cb) => {
|
|
18
|
+
subscribed = true;
|
|
19
|
+
const unsubscribe = queryResult?.subscribe(cb) ?? noop;
|
|
20
|
+
return () => {
|
|
21
|
+
unsubscribe?.();
|
|
22
|
+
subscribed = false;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}, [
|
|
27
|
+
resource,
|
|
28
|
+
JSON.stringify(query.ast)
|
|
29
|
+
]);
|
|
30
|
+
const objects = useSyncExternalStore(subscribe, getObjects);
|
|
31
|
+
return objects;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/useSchema.ts
|
|
35
|
+
import { useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
36
|
+
var useSchema = (db, typename) => {
|
|
37
|
+
const { subscribe, getSchema } = useMemo2(() => {
|
|
38
|
+
if (!typename || !db) {
|
|
39
|
+
return {
|
|
40
|
+
subscribe: () => () => {
|
|
41
|
+
},
|
|
42
|
+
getSchema: () => void 0
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const query = db.schemaRegistry.query({
|
|
46
|
+
typename,
|
|
47
|
+
location: [
|
|
48
|
+
"database",
|
|
49
|
+
"runtime"
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
const initialResult = query.runSync()[0];
|
|
53
|
+
let currentSchema = initialResult;
|
|
54
|
+
return {
|
|
55
|
+
subscribe: (onStoreChange) => {
|
|
56
|
+
const unsubscribe = query.subscribe(() => {
|
|
57
|
+
currentSchema = query.results[0];
|
|
58
|
+
onStoreChange();
|
|
59
|
+
});
|
|
60
|
+
return unsubscribe;
|
|
61
|
+
},
|
|
62
|
+
getSchema: () => currentSchema
|
|
63
|
+
};
|
|
64
|
+
}, [
|
|
65
|
+
typename,
|
|
66
|
+
db
|
|
67
|
+
]);
|
|
68
|
+
return useSyncExternalStore2(subscribe, getSchema);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/useObject.ts
|
|
72
|
+
import * as Atom from "@effect-atom/atom/Atom";
|
|
73
|
+
import { useAtomValue } from "@effect-atom/atom-react";
|
|
74
|
+
import { useCallback, useMemo as useMemo3 } from "react";
|
|
75
|
+
import { Obj, Ref } from "@dxos/echo";
|
|
76
|
+
import { AtomObj } from "@dxos/echo-atom";
|
|
77
|
+
var useObject = (objOrRef, property) => {
|
|
78
|
+
const isRef = Ref.isRef(objOrRef);
|
|
79
|
+
const liveObj = isRef ? objOrRef?.target : objOrRef;
|
|
80
|
+
const callback = useCallback((updateOrValue) => {
|
|
81
|
+
const obj = isRef ? objOrRef?.target : liveObj;
|
|
82
|
+
if (obj === void 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
Obj.change(obj, (o) => {
|
|
86
|
+
if (typeof updateOrValue === "function") {
|
|
87
|
+
const returnValue = updateOrValue(property !== void 0 ? o[property] : o);
|
|
88
|
+
if (returnValue !== void 0) {
|
|
89
|
+
if (property === void 0) {
|
|
90
|
+
throw new Error("Cannot re-assign the entire object");
|
|
91
|
+
}
|
|
92
|
+
o[property] = returnValue;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
if (property === void 0) {
|
|
96
|
+
throw new Error("Cannot re-assign the entire object");
|
|
97
|
+
}
|
|
98
|
+
o[property] = updateOrValue;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}, [
|
|
102
|
+
objOrRef,
|
|
103
|
+
property,
|
|
104
|
+
isRef,
|
|
105
|
+
liveObj
|
|
106
|
+
]);
|
|
107
|
+
if (property !== void 0) {
|
|
108
|
+
useObjectValue(objOrRef);
|
|
109
|
+
return [
|
|
110
|
+
useObjectProperty(liveObj, property),
|
|
111
|
+
callback
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
return [
|
|
115
|
+
useObjectValue(objOrRef),
|
|
116
|
+
callback
|
|
117
|
+
];
|
|
118
|
+
};
|
|
119
|
+
var useObjectValue = (objOrRef) => {
|
|
120
|
+
const atom = useMemo3(() => AtomObj.make(objOrRef), [
|
|
121
|
+
objOrRef
|
|
122
|
+
]);
|
|
123
|
+
return useAtomValue(atom);
|
|
124
|
+
};
|
|
125
|
+
var useObjectProperty = (obj, property) => {
|
|
126
|
+
const atom = useMemo3(() => AtomObj.makeProperty(obj, property), [
|
|
127
|
+
obj,
|
|
128
|
+
property
|
|
129
|
+
]);
|
|
130
|
+
return useAtomValue(atom);
|
|
131
|
+
};
|
|
132
|
+
var useObjects = (refs) => {
|
|
133
|
+
const atom = useMemo3(() => Atom.make((get) => {
|
|
134
|
+
const results = [];
|
|
135
|
+
for (const ref of refs) {
|
|
136
|
+
const value = get(AtomObj.make(ref));
|
|
137
|
+
if (value !== void 0) {
|
|
138
|
+
results.push(value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return results;
|
|
142
|
+
}), [
|
|
143
|
+
refs
|
|
144
|
+
]);
|
|
145
|
+
return useAtomValue(atom);
|
|
146
|
+
};
|
|
147
|
+
export {
|
|
148
|
+
useObject,
|
|
149
|
+
useObjects,
|
|
150
|
+
useQuery,
|
|
151
|
+
useSchema
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useQuery.ts", "../../../src/useSchema.ts", "../../../src/useObject.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Database, type Entity, Filter, Query } from '@dxos/echo';\n\nconst EMPTY_ARRAY: never[] = [];\n\nconst noop = () => {};\n\ninterface UseQueryFn {\n <Q extends Query.Any, O extends Entity.Entity<Query.Type<Q>> = Entity.Entity<Query.Type<Q>>>(\n resource: Database.Queryable | undefined,\n query: Q,\n ): O[];\n\n <F extends Filter.Any, O extends Entity.Entity<Filter.Type<F>> = Entity.Entity<Filter.Type<F>>>(\n resource: Database.Queryable | undefined,\n filter: F,\n ): O[];\n}\n\n/**\n * Create subscription.\n */\nexport const useQuery: UseQueryFn = (\n resource: Database.Queryable | undefined,\n queryOrFilter: Query.Any | Filter.Any,\n): Entity.Any[] => {\n const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;\n\n const { getObjects, subscribe } = useMemo(() => {\n let queryResult = undefined;\n if (resource) {\n queryResult = resource.query(query);\n }\n\n let subscribed = false;\n return {\n getObjects: () => (subscribed && queryResult ? queryResult.results : EMPTY_ARRAY),\n subscribe: (cb: () => void) => {\n subscribed = true;\n const unsubscribe = queryResult?.subscribe(cb) ?? noop;\n return () => {\n unsubscribe?.();\n subscribed = false;\n };\n },\n };\n }, [resource, JSON.stringify(query.ast)]);\n\n // https://beta.reactjs.org/reference/react/useSyncExternalStore\n // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes; make sure it is stable.\n const objects = useSyncExternalStore<Entity.Any[]>(subscribe, getObjects);\n return objects;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Database, type Type } from '@dxos/echo';\n\n/**\n * Subscribe to and retrieve schema changes from a space's schema registry.\n */\nexport const useSchema = <T extends Type.Entity.Any = Type.Entity.Any>(\n db?: Database.Database,\n typename?: string,\n): T | undefined => {\n const { subscribe, getSchema } = useMemo(() => {\n if (!typename || !db) {\n return {\n subscribe: () => () => {},\n getSchema: () => undefined,\n };\n }\n\n const query = db.schemaRegistry.query({ typename, location: ['database', 'runtime'] });\n const initialResult = query.runSync()[0];\n let currentSchema = initialResult;\n\n return {\n subscribe: (onStoreChange: () => void) => {\n const unsubscribe = query.subscribe(() => {\n currentSchema = query.results[0];\n onStoreChange();\n });\n\n return unsubscribe;\n },\n getSchema: () => currentSchema,\n };\n }, [typename, db]);\n\n return useSyncExternalStore(subscribe, getSchema) as T;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Atom from '@effect-atom/atom/Atom';\nimport { useAtomValue } from '@effect-atom/atom-react';\nimport { useCallback, useMemo } from 'react';\n\nimport { Obj, Ref } from '@dxos/echo';\nimport { AtomObj } from '@dxos/echo-atom';\n\nexport interface ObjectUpdateCallback<T> {\n (update: (obj: Obj.Mutable<T>) => void): void;\n (update: (obj: Obj.Mutable<T>) => Obj.Mutable<T>): void;\n}\n\nexport interface ObjectPropUpdateCallback<T> {\n (update: (value: Obj.Mutable<T>) => void): void;\n (update: (value: Obj.Mutable<T>) => Obj.Mutable<T>): void;\n (newValue: T): void;\n}\n\nexport const useObject: {\n /**\n * Hook to subscribe to a Ref's target object.\n * Automatically dereferences the ref and handles async loading.\n * Returns a snapshot (undefined if the ref hasn't loaded yet).\n *\n * @param ref - The Ref to dereference and subscribe to\n * @returns The current target snapshot (or undefined if not loaded) and update callback\n */\n <T extends Obj.Unknown>(ref: Ref.Ref<T>): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to a Ref's target object that may be undefined.\n * Returns a snapshot (undefined if the ref is undefined or hasn't loaded yet).\n *\n * @param ref - The Ref to dereference and subscribe to (can be undefined)\n * @returns The current target snapshot (or undefined) and update callback\n */\n <T extends Obj.Unknown>(ref: Ref.Ref<T> | undefined): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to an entire Echo object.\n * Returns a snapshot of the current object value and automatically re-renders when the object changes.\n *\n * @param obj - The Echo object to subscribe to (objects only, not relations)\n * @returns The current object snapshot and update callback\n */\n <T extends Obj.Unknown>(obj: T): [Obj.Snapshot<T>, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to an entire Echo object that may be undefined.\n * Returns a snapshot (undefined if the object is undefined).\n *\n * @param obj - The Echo object to subscribe to (can be undefined, objects only)\n * @returns The current object snapshot (or undefined) and update callback\n */\n <T extends Obj.Unknown>(obj: T | undefined): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to an Echo object or Ref.\n * Handles both cases - if passed a Ref, dereferences it and subscribes to the target.\n * Returns a snapshot (undefined if ref hasn't loaded).\n *\n * @param objOrRef - The Echo object or Ref to subscribe to\n * @returns The current object snapshot (or undefined) and update callback\n */\n <T extends Obj.Unknown>(objOrRef: T | Ref.Ref<T>): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to a specific property of an Echo object.\n * Returns the current property value and automatically re-renders when the property changes.\n *\n * @param obj - The Echo object to subscribe to (objects only, not relations)\n * @param property - Property key to subscribe to\n * @returns The current property value and update callback\n */\n <T extends Obj.Unknown, K extends keyof T>(obj: T, property: K): [T[K], ObjectPropUpdateCallback<T[K]>];\n\n /**\n * Hook to subscribe to a specific property of an Echo object that may be undefined.\n * Returns undefined if the object is undefined.\n *\n * @param obj - The Echo object to subscribe to (can be undefined, objects only)\n * @param property - Property key to subscribe to\n * @returns The current property value (or undefined) and update callback\n */\n <T extends Obj.Unknown, K extends keyof T>(\n obj: T | undefined,\n property: K,\n ): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];\n\n /**\n * Hook to subscribe to a specific property of a Ref's target object.\n * Automatically dereferences the ref and handles async loading.\n * Returns undefined if the ref hasn't loaded yet.\n *\n * @param ref - The Ref to dereference and subscribe to\n * @param property - Property key to subscribe to\n * @returns The current property value (or undefined if not loaded) and update callback\n */\n <T, K extends keyof T>(ref: Ref.Ref<T>, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];\n\n /**\n * Hook to subscribe to a specific property of a Ref's target object that may be undefined.\n * Returns undefined if the ref is undefined or hasn't loaded yet.\n *\n * @param ref - The Ref to dereference and subscribe to (can be undefined)\n * @param property - Property key to subscribe to\n * @returns The current property value (or undefined) and update callback\n */\n <T, K extends keyof T>(ref: Ref.Ref<T> | undefined, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];\n} = (<T extends Obj.Unknown, K extends keyof T>(objOrRef: T | Ref.Ref<T> | undefined, property?: K): any => {\n // Get the live object for the callback (refs need to dereference).\n const isRef = Ref.isRef(objOrRef);\n const liveObj = isRef ? (objOrRef as Ref.Ref<T>)?.target : (objOrRef as T | undefined);\n\n const callback: ObjectPropUpdateCallback<unknown> = useCallback(\n (updateOrValue: unknown | ((obj: unknown) => unknown)) => {\n // Get current target for refs (may have loaded since render).\n const obj = isRef ? (objOrRef as Ref.Ref<T>)?.target : liveObj;\n if (obj === undefined) {\n return;\n }\n Obj.change(obj, (o: any) => {\n if (typeof updateOrValue === 'function') {\n const returnValue = updateOrValue(property !== undefined ? o[property] : o);\n if (returnValue !== undefined) {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n o[property] = returnValue;\n }\n } else {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n o[property] = updateOrValue;\n }\n });\n },\n [objOrRef, property, isRef, liveObj],\n );\n\n if (property !== undefined) {\n // For property subscriptions on refs, we subscribe to trigger re-render on load.\n // TODO(dxos): Property subscriptions on refs may not update correctly until the ref loads.\n useObjectValue(objOrRef);\n return [useObjectProperty(liveObj, property as any), callback];\n }\n return [useObjectValue(objOrRef), callback];\n}) as any;\n\n/**\n * Internal hook for subscribing to an Echo object or Ref.\n * AtomObj.make handles both objects and refs, returning snapshots.\n */\nconst useObjectValue = <T extends Obj.Unknown>(objOrRef: T | Ref.Ref<T> | undefined): Obj.Snapshot<T> | undefined => {\n const atom = useMemo(() => AtomObj.make(objOrRef), [objOrRef]);\n return useAtomValue(atom) as Obj.Snapshot<T> | undefined;\n};\n\n/**\n * Internal hook for subscribing to a specific property of an Echo object.\n * Uses useAtomValue directly since makeProperty returns the value directly.\n */\nconst useObjectProperty = <T extends Obj.Unknown, K extends keyof T>(\n obj: T | undefined,\n property: K,\n): T[K] | undefined => {\n const atom = useMemo(() => AtomObj.makeProperty(obj, property), [obj, property]);\n return useAtomValue(atom);\n};\n\n/**\n * Hook to subscribe to multiple Refs' target objects.\n * Automatically dereferences each ref and handles async loading.\n * Returns an array of loaded snapshots (filtering out undefined values).\n *\n * This hook is useful for aggregate computations like counts or filtering\n * across multiple refs without using .target directly.\n *\n * @param refs - Array of Refs to dereference and subscribe to\n * @returns Array of loaded target snapshots (excludes unloaded refs)\n */\nexport const useObjects = <T extends Obj.Unknown>(refs: readonly Ref.Ref<T>[]): Obj.Snapshot<T>[] => {\n const atom = useMemo(\n () =>\n Atom.make((get) => {\n const results: Obj.Snapshot<T>[] = [];\n for (const ref of refs) {\n const value = get(AtomObj.make(ref));\n if (value !== undefined) {\n results.push(value as Obj.Snapshot<T>);\n }\n }\n return results;\n }),\n [refs],\n );\n return useAtomValue(atom);\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,SAASC,4BAA4B;AAE9C,SAAqCC,QAAQC,aAAa;AAE1D,IAAMC,cAAuB,CAAA;AAE7B,IAAMC,OAAO,MAAA;AAAO;AAiBb,IAAMC,WAAuB,CAClCC,UACAC,kBAAAA;AAEA,QAAMC,QAAQC,OAAOC,GAAGH,aAAAA,IAAiBI,MAAMC,OAAOL,aAAAA,IAAiBA;AAEvE,QAAM,EAAEM,YAAYC,UAAS,IAAKC,QAAQ,MAAA;AACxC,QAAIC,cAAcC;AAClB,QAAIX,UAAU;AACZU,oBAAcV,SAASE,MAAMA,KAAAA;IAC/B;AAEA,QAAIU,aAAa;AACjB,WAAO;MACLL,YAAY,MAAOK,cAAcF,cAAcA,YAAYG,UAAUhB;MACrEW,WAAW,CAACM,OAAAA;AACVF,qBAAa;AACb,cAAMG,cAAcL,aAAaF,UAAUM,EAAAA,KAAOhB;AAClD,eAAO,MAAA;AACLiB,wBAAAA;AACAH,uBAAa;QACf;MACF;IACF;EACF,GAAG;IAACZ;IAAUgB,KAAKC,UAAUf,MAAMgB,GAAG;GAAE;AAIxC,QAAMC,UAAUC,qBAAmCZ,WAAWD,UAAAA;AAC9D,SAAOY;AACT;;;ACrDA,SAASE,WA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,kBAAM,IAAIK,MAAM,oCAAA;UAClB;AACAF,YAAEZ,QAAAA,IAAYa;QAChB;MACF,OAAO;AACL,YAAIb,aAAaS,QAAW;AAC1B,gBAAM,IAAIK,MAAM,oCAAA;QAClB;AACAF,UAAEZ,QAAAA,IAAYO;MAChB;IACF,CAAA;EACF,GACA;IAACR;IAAUC;IAAUC;IAAOE;GAAQ;AAGtC,MAAIH,aAAaS,QAAW;AAG1BM,mBAAehB,QAAAA;AACf,WAAO;MAACiB,kBAAkBb,SAASH,QAAAA;MAAkBK;;EACvD;AACA,SAAO;IAACU,eAAehB,QAAAA;IAAWM;;AACpC;AAMA,IAAMU,iBAAiB,CAAwBhB,aAAAA;AAC7C,QAAMkB,OAAOC,SAAQ,MAAMC,QAAQC,KAAKrB,QAAAA,GAAW;IAACA;GAAS;AAC7D,SAAOsB,aAAaJ,IAAAA;AACtB;AAMA,IAAMD,oBAAoB,CACxBR,KACAR,aAAAA;AAEA,QAAMiB,OAAOC,SAAQ,MAAMC,QAAQG,aAAad,KAAKR,QAAAA,GAAW;IAACQ;IAAKR;GAAS;AAC/E,SAAOqB,aAAaJ,IAAAA;AACtB;AAaO,IAAMM,aAAa,CAAwBC,SAAAA;AAChD,QAAMP,OAAOC,SACX,MACOE,UAAK,CAACK,QAAAA;AACT,UAAMC,UAA6B,CAAA;AACnC,eAAWC,OAAOH,MAAM;AACtB,YAAMI,QAAQH,IAAIN,QAAQC,KAAKO,GAAAA,CAAAA;AAC/B,UAAIC,UAAUnB,QAAW;AACvBiB,gBAAQG,KAAKD,KAAAA;MACf;IACF;AACA,WAAOF;EACT,CAAA,GACF;IAACF;GAAK;AAER,SAAOH,aAAaJ,IAAAA;AACtB;",
|
|
6
|
+
"names": ["useMemo", "useSyncExternalStore", "Filter", "Query", "EMPTY_ARRAY", "noop", "useQuery", "resource", "queryOrFilter", "query", "Filter", "is", "Query", "select", "getObjects", "subscribe", "useMemo", "queryResult", "undefined", "subscribed", "results", "cb", "unsubscribe", "JSON", "stringify", "ast", "objects", "useSyncExternalStore", "useMemo", "useSyncExternalStore", "useSchema", "db", "typename", "subscribe", "getSchema", "useMemo", "undefined", "query", "schemaRegistry", "location", "initialResult", "runSync", "currentSchema", "onStoreChange", "unsubscribe", "results", "useSyncExternalStore", "Atom", "useAtomValue", "useCallback", "useMemo", "Obj", "Ref", "AtomObj", "useObject", "objOrRef", "property", "isRef", "Ref", "liveObj", "target", "callback", "useCallback", "updateOrValue", "obj", "undefined", "Obj", "change", "o", "returnValue", "Error", "useObjectValue", "useObjectProperty", "atom", "useMemo", "AtomObj", "make", "useAtomValue", "makeProperty", "useObjects", "refs", "get", "results", "ref", "value", "push"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/useQuery.ts":{"bytes":5192,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"format":"esm"},"src/useSchema.ts":{"bytes":4017,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/useObject.ts":{"bytes":17411,"imports":[{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-atom","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":638,"imports":[{"path":"src/useQuery.ts","kind":"import-statement","original":"./useQuery"},{"path":"src/useSchema.ts","kind":"import-statement","original":"./useSchema"},{"path":"src/useObject.ts","kind":"import-statement","original":"./useObject"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15152},"dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-atom","kind":"import-statement","external":true}],"exports":["useObject","useObjects","useQuery","useSchema"],"entryPoint":"src/index.ts","inputs":{"src/useQuery.ts":{"bytesInOutput":921},"src/index.ts":{"bytesInOutput":0},"src/useSchema.ts":{"bytesInOutput":889},"src/useObject.ts":{"bytesInOutput":1979}},"bytes":3948}}}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/useQuery.ts
|
|
4
|
+
import { useMemo, useSyncExternalStore } from "react";
|
|
5
|
+
import { Filter, Query } from "@dxos/echo";
|
|
6
|
+
var EMPTY_ARRAY = [];
|
|
7
|
+
var noop = () => {
|
|
8
|
+
};
|
|
9
|
+
var useQuery = (resource, queryOrFilter) => {
|
|
10
|
+
const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;
|
|
11
|
+
const { getObjects, subscribe } = useMemo(() => {
|
|
12
|
+
let queryResult = void 0;
|
|
13
|
+
if (resource) {
|
|
14
|
+
queryResult = resource.query(query);
|
|
15
|
+
}
|
|
16
|
+
let subscribed = false;
|
|
17
|
+
return {
|
|
18
|
+
getObjects: () => subscribed && queryResult ? queryResult.results : EMPTY_ARRAY,
|
|
19
|
+
subscribe: (cb) => {
|
|
20
|
+
subscribed = true;
|
|
21
|
+
const unsubscribe = queryResult?.subscribe(cb) ?? noop;
|
|
22
|
+
return () => {
|
|
23
|
+
unsubscribe?.();
|
|
24
|
+
subscribed = false;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, [
|
|
29
|
+
resource,
|
|
30
|
+
JSON.stringify(query.ast)
|
|
31
|
+
]);
|
|
32
|
+
const objects = useSyncExternalStore(subscribe, getObjects);
|
|
33
|
+
return objects;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/useSchema.ts
|
|
37
|
+
import { useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
38
|
+
var useSchema = (db, typename) => {
|
|
39
|
+
const { subscribe, getSchema } = useMemo2(() => {
|
|
40
|
+
if (!typename || !db) {
|
|
41
|
+
return {
|
|
42
|
+
subscribe: () => () => {
|
|
43
|
+
},
|
|
44
|
+
getSchema: () => void 0
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const query = db.schemaRegistry.query({
|
|
48
|
+
typename,
|
|
49
|
+
location: [
|
|
50
|
+
"database",
|
|
51
|
+
"runtime"
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
const initialResult = query.runSync()[0];
|
|
55
|
+
let currentSchema = initialResult;
|
|
56
|
+
return {
|
|
57
|
+
subscribe: (onStoreChange) => {
|
|
58
|
+
const unsubscribe = query.subscribe(() => {
|
|
59
|
+
currentSchema = query.results[0];
|
|
60
|
+
onStoreChange();
|
|
61
|
+
});
|
|
62
|
+
return unsubscribe;
|
|
63
|
+
},
|
|
64
|
+
getSchema: () => currentSchema
|
|
65
|
+
};
|
|
66
|
+
}, [
|
|
67
|
+
typename,
|
|
68
|
+
db
|
|
69
|
+
]);
|
|
70
|
+
return useSyncExternalStore2(subscribe, getSchema);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/useObject.ts
|
|
74
|
+
import * as Atom from "@effect-atom/atom/Atom";
|
|
75
|
+
import { useAtomValue } from "@effect-atom/atom-react";
|
|
76
|
+
import { useCallback, useMemo as useMemo3 } from "react";
|
|
77
|
+
import { Obj, Ref } from "@dxos/echo";
|
|
78
|
+
import { AtomObj } from "@dxos/echo-atom";
|
|
79
|
+
var useObject = (objOrRef, property) => {
|
|
80
|
+
const isRef = Ref.isRef(objOrRef);
|
|
81
|
+
const liveObj = isRef ? objOrRef?.target : objOrRef;
|
|
82
|
+
const callback = useCallback((updateOrValue) => {
|
|
83
|
+
const obj = isRef ? objOrRef?.target : liveObj;
|
|
84
|
+
if (obj === void 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
Obj.change(obj, (o) => {
|
|
88
|
+
if (typeof updateOrValue === "function") {
|
|
89
|
+
const returnValue = updateOrValue(property !== void 0 ? o[property] : o);
|
|
90
|
+
if (returnValue !== void 0) {
|
|
91
|
+
if (property === void 0) {
|
|
92
|
+
throw new Error("Cannot re-assign the entire object");
|
|
93
|
+
}
|
|
94
|
+
o[property] = returnValue;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (property === void 0) {
|
|
98
|
+
throw new Error("Cannot re-assign the entire object");
|
|
99
|
+
}
|
|
100
|
+
o[property] = updateOrValue;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}, [
|
|
104
|
+
objOrRef,
|
|
105
|
+
property,
|
|
106
|
+
isRef,
|
|
107
|
+
liveObj
|
|
108
|
+
]);
|
|
109
|
+
if (property !== void 0) {
|
|
110
|
+
useObjectValue(objOrRef);
|
|
111
|
+
return [
|
|
112
|
+
useObjectProperty(liveObj, property),
|
|
113
|
+
callback
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
return [
|
|
117
|
+
useObjectValue(objOrRef),
|
|
118
|
+
callback
|
|
119
|
+
];
|
|
120
|
+
};
|
|
121
|
+
var useObjectValue = (objOrRef) => {
|
|
122
|
+
const atom = useMemo3(() => AtomObj.make(objOrRef), [
|
|
123
|
+
objOrRef
|
|
124
|
+
]);
|
|
125
|
+
return useAtomValue(atom);
|
|
126
|
+
};
|
|
127
|
+
var useObjectProperty = (obj, property) => {
|
|
128
|
+
const atom = useMemo3(() => AtomObj.makeProperty(obj, property), [
|
|
129
|
+
obj,
|
|
130
|
+
property
|
|
131
|
+
]);
|
|
132
|
+
return useAtomValue(atom);
|
|
133
|
+
};
|
|
134
|
+
var useObjects = (refs) => {
|
|
135
|
+
const atom = useMemo3(() => Atom.make((get) => {
|
|
136
|
+
const results = [];
|
|
137
|
+
for (const ref of refs) {
|
|
138
|
+
const value = get(AtomObj.make(ref));
|
|
139
|
+
if (value !== void 0) {
|
|
140
|
+
results.push(value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return results;
|
|
144
|
+
}), [
|
|
145
|
+
refs
|
|
146
|
+
]);
|
|
147
|
+
return useAtomValue(atom);
|
|
148
|
+
};
|
|
149
|
+
export {
|
|
150
|
+
useObject,
|
|
151
|
+
useObjects,
|
|
152
|
+
useQuery,
|
|
153
|
+
useSchema
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useQuery.ts", "../../../src/useSchema.ts", "../../../src/useObject.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Database, type Entity, Filter, Query } from '@dxos/echo';\n\nconst EMPTY_ARRAY: never[] = [];\n\nconst noop = () => {};\n\ninterface UseQueryFn {\n <Q extends Query.Any, O extends Entity.Entity<Query.Type<Q>> = Entity.Entity<Query.Type<Q>>>(\n resource: Database.Queryable | undefined,\n query: Q,\n ): O[];\n\n <F extends Filter.Any, O extends Entity.Entity<Filter.Type<F>> = Entity.Entity<Filter.Type<F>>>(\n resource: Database.Queryable | undefined,\n filter: F,\n ): O[];\n}\n\n/**\n * Create subscription.\n */\nexport const useQuery: UseQueryFn = (\n resource: Database.Queryable | undefined,\n queryOrFilter: Query.Any | Filter.Any,\n): Entity.Any[] => {\n const query = Filter.is(queryOrFilter) ? Query.select(queryOrFilter) : queryOrFilter;\n\n const { getObjects, subscribe } = useMemo(() => {\n let queryResult = undefined;\n if (resource) {\n queryResult = resource.query(query);\n }\n\n let subscribed = false;\n return {\n getObjects: () => (subscribed && queryResult ? queryResult.results : EMPTY_ARRAY),\n subscribe: (cb: () => void) => {\n subscribed = true;\n const unsubscribe = queryResult?.subscribe(cb) ?? noop;\n return () => {\n unsubscribe?.();\n subscribed = false;\n };\n },\n };\n }, [resource, JSON.stringify(query.ast)]);\n\n // https://beta.reactjs.org/reference/react/useSyncExternalStore\n // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes; make sure it is stable.\n const objects = useSyncExternalStore<Entity.Any[]>(subscribe, getObjects);\n return objects;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport { type Database, type Type } from '@dxos/echo';\n\n/**\n * Subscribe to and retrieve schema changes from a space's schema registry.\n */\nexport const useSchema = <T extends Type.Entity.Any = Type.Entity.Any>(\n db?: Database.Database,\n typename?: string,\n): T | undefined => {\n const { subscribe, getSchema } = useMemo(() => {\n if (!typename || !db) {\n return {\n subscribe: () => () => {},\n getSchema: () => undefined,\n };\n }\n\n const query = db.schemaRegistry.query({ typename, location: ['database', 'runtime'] });\n const initialResult = query.runSync()[0];\n let currentSchema = initialResult;\n\n return {\n subscribe: (onStoreChange: () => void) => {\n const unsubscribe = query.subscribe(() => {\n currentSchema = query.results[0];\n onStoreChange();\n });\n\n return unsubscribe;\n },\n getSchema: () => currentSchema,\n };\n }, [typename, db]);\n\n return useSyncExternalStore(subscribe, getSchema) as T;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Atom from '@effect-atom/atom/Atom';\nimport { useAtomValue } from '@effect-atom/atom-react';\nimport { useCallback, useMemo } from 'react';\n\nimport { Obj, Ref } from '@dxos/echo';\nimport { AtomObj } from '@dxos/echo-atom';\n\nexport interface ObjectUpdateCallback<T> {\n (update: (obj: Obj.Mutable<T>) => void): void;\n (update: (obj: Obj.Mutable<T>) => Obj.Mutable<T>): void;\n}\n\nexport interface ObjectPropUpdateCallback<T> {\n (update: (value: Obj.Mutable<T>) => void): void;\n (update: (value: Obj.Mutable<T>) => Obj.Mutable<T>): void;\n (newValue: T): void;\n}\n\nexport const useObject: {\n /**\n * Hook to subscribe to a Ref's target object.\n * Automatically dereferences the ref and handles async loading.\n * Returns a snapshot (undefined if the ref hasn't loaded yet).\n *\n * @param ref - The Ref to dereference and subscribe to\n * @returns The current target snapshot (or undefined if not loaded) and update callback\n */\n <T extends Obj.Unknown>(ref: Ref.Ref<T>): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to a Ref's target object that may be undefined.\n * Returns a snapshot (undefined if the ref is undefined or hasn't loaded yet).\n *\n * @param ref - The Ref to dereference and subscribe to (can be undefined)\n * @returns The current target snapshot (or undefined) and update callback\n */\n <T extends Obj.Unknown>(ref: Ref.Ref<T> | undefined): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to an entire Echo object.\n * Returns a snapshot of the current object value and automatically re-renders when the object changes.\n *\n * @param obj - The Echo object to subscribe to (objects only, not relations)\n * @returns The current object snapshot and update callback\n */\n <T extends Obj.Unknown>(obj: T): [Obj.Snapshot<T>, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to an entire Echo object that may be undefined.\n * Returns a snapshot (undefined if the object is undefined).\n *\n * @param obj - The Echo object to subscribe to (can be undefined, objects only)\n * @returns The current object snapshot (or undefined) and update callback\n */\n <T extends Obj.Unknown>(obj: T | undefined): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to an Echo object or Ref.\n * Handles both cases - if passed a Ref, dereferences it and subscribes to the target.\n * Returns a snapshot (undefined if ref hasn't loaded).\n *\n * @param objOrRef - The Echo object or Ref to subscribe to\n * @returns The current object snapshot (or undefined) and update callback\n */\n <T extends Obj.Unknown>(objOrRef: T | Ref.Ref<T>): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];\n\n /**\n * Hook to subscribe to a specific property of an Echo object.\n * Returns the current property value and automatically re-renders when the property changes.\n *\n * @param obj - The Echo object to subscribe to (objects only, not relations)\n * @param property - Property key to subscribe to\n * @returns The current property value and update callback\n */\n <T extends Obj.Unknown, K extends keyof T>(obj: T, property: K): [T[K], ObjectPropUpdateCallback<T[K]>];\n\n /**\n * Hook to subscribe to a specific property of an Echo object that may be undefined.\n * Returns undefined if the object is undefined.\n *\n * @param obj - The Echo object to subscribe to (can be undefined, objects only)\n * @param property - Property key to subscribe to\n * @returns The current property value (or undefined) and update callback\n */\n <T extends Obj.Unknown, K extends keyof T>(\n obj: T | undefined,\n property: K,\n ): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];\n\n /**\n * Hook to subscribe to a specific property of a Ref's target object.\n * Automatically dereferences the ref and handles async loading.\n * Returns undefined if the ref hasn't loaded yet.\n *\n * @param ref - The Ref to dereference and subscribe to\n * @param property - Property key to subscribe to\n * @returns The current property value (or undefined if not loaded) and update callback\n */\n <T, K extends keyof T>(ref: Ref.Ref<T>, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];\n\n /**\n * Hook to subscribe to a specific property of a Ref's target object that may be undefined.\n * Returns undefined if the ref is undefined or hasn't loaded yet.\n *\n * @param ref - The Ref to dereference and subscribe to (can be undefined)\n * @param property - Property key to subscribe to\n * @returns The current property value (or undefined) and update callback\n */\n <T, K extends keyof T>(ref: Ref.Ref<T> | undefined, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];\n} = (<T extends Obj.Unknown, K extends keyof T>(objOrRef: T | Ref.Ref<T> | undefined, property?: K): any => {\n // Get the live object for the callback (refs need to dereference).\n const isRef = Ref.isRef(objOrRef);\n const liveObj = isRef ? (objOrRef as Ref.Ref<T>)?.target : (objOrRef as T | undefined);\n\n const callback: ObjectPropUpdateCallback<unknown> = useCallback(\n (updateOrValue: unknown | ((obj: unknown) => unknown)) => {\n // Get current target for refs (may have loaded since render).\n const obj = isRef ? (objOrRef as Ref.Ref<T>)?.target : liveObj;\n if (obj === undefined) {\n return;\n }\n Obj.change(obj, (o: any) => {\n if (typeof updateOrValue === 'function') {\n const returnValue = updateOrValue(property !== undefined ? o[property] : o);\n if (returnValue !== undefined) {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n o[property] = returnValue;\n }\n } else {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n o[property] = updateOrValue;\n }\n });\n },\n [objOrRef, property, isRef, liveObj],\n );\n\n if (property !== undefined) {\n // For property subscriptions on refs, we subscribe to trigger re-render on load.\n // TODO(dxos): Property subscriptions on refs may not update correctly until the ref loads.\n useObjectValue(objOrRef);\n return [useObjectProperty(liveObj, property as any), callback];\n }\n return [useObjectValue(objOrRef), callback];\n}) as any;\n\n/**\n * Internal hook for subscribing to an Echo object or Ref.\n * AtomObj.make handles both objects and refs, returning snapshots.\n */\nconst useObjectValue = <T extends Obj.Unknown>(objOrRef: T | Ref.Ref<T> | undefined): Obj.Snapshot<T> | undefined => {\n const atom = useMemo(() => AtomObj.make(objOrRef), [objOrRef]);\n return useAtomValue(atom) as Obj.Snapshot<T> | undefined;\n};\n\n/**\n * Internal hook for subscribing to a specific property of an Echo object.\n * Uses useAtomValue directly since makeProperty returns the value directly.\n */\nconst useObjectProperty = <T extends Obj.Unknown, K extends keyof T>(\n obj: T | undefined,\n property: K,\n): T[K] | undefined => {\n const atom = useMemo(() => AtomObj.makeProperty(obj, property), [obj, property]);\n return useAtomValue(atom);\n};\n\n/**\n * Hook to subscribe to multiple Refs' target objects.\n * Automatically dereferences each ref and handles async loading.\n * Returns an array of loaded snapshots (filtering out undefined values).\n *\n * This hook is useful for aggregate computations like counts or filtering\n * across multiple refs without using .target directly.\n *\n * @param refs - Array of Refs to dereference and subscribe to\n * @returns Array of loaded target snapshots (excludes unloaded refs)\n */\nexport const useObjects = <T extends Obj.Unknown>(refs: readonly Ref.Ref<T>[]): Obj.Snapshot<T>[] => {\n const atom = useMemo(\n () =>\n Atom.make((get) => {\n const results: Obj.Snapshot<T>[] = [];\n for (const ref of refs) {\n const value = get(AtomObj.make(ref));\n if (value !== undefined) {\n results.push(value as Obj.Snapshot<T>);\n }\n }\n return results;\n }),\n [refs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A;AAC7C,QAAMkB,OAAOC,SAAQ,MAAMC,QAAQC,KAAKrB,QAAAA,GAAW;IAACA;GAAS;AAC7D,SAAOsB,aAAaJ,IAAAA;AACtB;AAMA,IAAMD,oBAAoB,CACxBR,KACAR,aAAAA;AAEA,QAAMiB,OAAOC,SAAQ,MAAMC,QAAQG,aAAad,KAAKR,QAAAA,GAAW;IAACQ;IAAKR;GAAS;AAC/E,SAAOqB,aAAaJ,IAAAA;AACtB;AAaO,IAAMM,aAAa,CAAwBC,SAAAA;AAChD,QAAMP,OAAOC,SACX,MACOE,UAAK,CAACK,QAAAA;AACT,UAAMC,UAA6B,CAAA;AACnC,eAAWC,OAAOH,MAAM;AACtB,YAAMI,QAAQH,IAAIN,QAAQC,KAAKO,GAAAA,CAAAA;AAC/B,UAAIC,UAAUnB,QAAW;AACvBiB,gBAAQG,KAAKD,KAAAA;MACf;IACF;AACA,WAAOF;EACT,CAAA,GACF;IAACF;GAAK;AAER,SAAOH,aAAaJ,IAAAA;AACtB;",
|
|
6
|
+
"names": ["useMemo", "useSyncExternalStore", "Filter", "Query", "EMPTY_ARRAY", "noop", "useQuery", "resource", "queryOrFilter", "query", "Filter", "is", "Query", "select", "getObjects", "subscribe", "useMemo", "queryResult", "undefined", "subscribed", "results", "cb", "unsubscribe", "JSON", "stringify", "ast", "objects", "useSyncExternalStore", "useMemo", "useSyncExternalStore", "useSchema", "db", "typename", "subscribe", "getSchema", "useMemo", "undefined", "query", "schemaRegistry", "location", "initialResult", "runSync", "currentSchema", "onStoreChange", "unsubscribe", "results", "useSyncExternalStore", "Atom", "useAtomValue", "useCallback", "useMemo", "Obj", "Ref", "AtomObj", "useObject", "objOrRef", "property", "isRef", "Ref", "liveObj", "target", "callback", "useCallback", "updateOrValue", "obj", "undefined", "Obj", "change", "o", "returnValue", "Error", "useObjectValue", "useObjectProperty", "atom", "useMemo", "AtomObj", "make", "useAtomValue", "makeProperty", "useObjects", "refs", "get", "results", "ref", "value", "push"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/useQuery.ts":{"bytes":5192,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"format":"esm"},"src/useSchema.ts":{"bytes":4017,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/useObject.ts":{"bytes":17411,"imports":[{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-atom","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":638,"imports":[{"path":"src/useQuery.ts","kind":"import-statement","original":"./useQuery"},{"path":"src/useSchema.ts","kind":"import-statement","original":"./useSchema"},{"path":"src/useObject.ts","kind":"import-statement","original":"./useObject"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15154},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom-react","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-atom","kind":"import-statement","external":true}],"exports":["useObject","useObjects","useQuery","useSchema"],"entryPoint":"src/index.ts","inputs":{"src/useQuery.ts":{"bytesInOutput":921},"src/index.ts":{"bytesInOutput":0},"src/useSchema.ts":{"bytesInOutput":889},"src/useObject.ts":{"bytesInOutput":1979}},"bytes":4041}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Obj, Ref } from '@dxos/echo';
|
|
2
|
+
export interface ObjectUpdateCallback<T> {
|
|
3
|
+
(update: (obj: Obj.Mutable<T>) => void): void;
|
|
4
|
+
(update: (obj: Obj.Mutable<T>) => Obj.Mutable<T>): void;
|
|
5
|
+
}
|
|
6
|
+
export interface ObjectPropUpdateCallback<T> {
|
|
7
|
+
(update: (value: Obj.Mutable<T>) => void): void;
|
|
8
|
+
(update: (value: Obj.Mutable<T>) => Obj.Mutable<T>): void;
|
|
9
|
+
(newValue: T): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const useObject: {
|
|
12
|
+
/**
|
|
13
|
+
* Hook to subscribe to a Ref's target object.
|
|
14
|
+
* Automatically dereferences the ref and handles async loading.
|
|
15
|
+
* Returns a snapshot (undefined if the ref hasn't loaded yet).
|
|
16
|
+
*
|
|
17
|
+
* @param ref - The Ref to dereference and subscribe to
|
|
18
|
+
* @returns The current target snapshot (or undefined if not loaded) and update callback
|
|
19
|
+
*/
|
|
20
|
+
<T extends Obj.Unknown>(ref: Ref.Ref<T>): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];
|
|
21
|
+
/**
|
|
22
|
+
* Hook to subscribe to a Ref's target object that may be undefined.
|
|
23
|
+
* Returns a snapshot (undefined if the ref is undefined or hasn't loaded yet).
|
|
24
|
+
*
|
|
25
|
+
* @param ref - The Ref to dereference and subscribe to (can be undefined)
|
|
26
|
+
* @returns The current target snapshot (or undefined) and update callback
|
|
27
|
+
*/
|
|
28
|
+
<T extends Obj.Unknown>(ref: Ref.Ref<T> | undefined): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];
|
|
29
|
+
/**
|
|
30
|
+
* Hook to subscribe to an entire Echo object.
|
|
31
|
+
* Returns a snapshot of the current object value and automatically re-renders when the object changes.
|
|
32
|
+
*
|
|
33
|
+
* @param obj - The Echo object to subscribe to (objects only, not relations)
|
|
34
|
+
* @returns The current object snapshot and update callback
|
|
35
|
+
*/
|
|
36
|
+
<T extends Obj.Unknown>(obj: T): [Obj.Snapshot<T>, ObjectUpdateCallback<T>];
|
|
37
|
+
/**
|
|
38
|
+
* Hook to subscribe to an entire Echo object that may be undefined.
|
|
39
|
+
* Returns a snapshot (undefined if the object is undefined).
|
|
40
|
+
*
|
|
41
|
+
* @param obj - The Echo object to subscribe to (can be undefined, objects only)
|
|
42
|
+
* @returns The current object snapshot (or undefined) and update callback
|
|
43
|
+
*/
|
|
44
|
+
<T extends Obj.Unknown>(obj: T | undefined): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];
|
|
45
|
+
/**
|
|
46
|
+
* Hook to subscribe to an Echo object or Ref.
|
|
47
|
+
* Handles both cases - if passed a Ref, dereferences it and subscribes to the target.
|
|
48
|
+
* Returns a snapshot (undefined if ref hasn't loaded).
|
|
49
|
+
*
|
|
50
|
+
* @param objOrRef - The Echo object or Ref to subscribe to
|
|
51
|
+
* @returns The current object snapshot (or undefined) and update callback
|
|
52
|
+
*/
|
|
53
|
+
<T extends Obj.Unknown>(objOrRef: T | Ref.Ref<T>): [Obj.Snapshot<T> | undefined, ObjectUpdateCallback<T>];
|
|
54
|
+
/**
|
|
55
|
+
* Hook to subscribe to a specific property of an Echo object.
|
|
56
|
+
* Returns the current property value and automatically re-renders when the property changes.
|
|
57
|
+
*
|
|
58
|
+
* @param obj - The Echo object to subscribe to (objects only, not relations)
|
|
59
|
+
* @param property - Property key to subscribe to
|
|
60
|
+
* @returns The current property value and update callback
|
|
61
|
+
*/
|
|
62
|
+
<T extends Obj.Unknown, K extends keyof T>(obj: T, property: K): [T[K], ObjectPropUpdateCallback<T[K]>];
|
|
63
|
+
/**
|
|
64
|
+
* Hook to subscribe to a specific property of an Echo object that may be undefined.
|
|
65
|
+
* Returns undefined if the object is undefined.
|
|
66
|
+
*
|
|
67
|
+
* @param obj - The Echo object to subscribe to (can be undefined, objects only)
|
|
68
|
+
* @param property - Property key to subscribe to
|
|
69
|
+
* @returns The current property value (or undefined) and update callback
|
|
70
|
+
*/
|
|
71
|
+
<T extends Obj.Unknown, K extends keyof T>(obj: T | undefined, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];
|
|
72
|
+
/**
|
|
73
|
+
* Hook to subscribe to a specific property of a Ref's target object.
|
|
74
|
+
* Automatically dereferences the ref and handles async loading.
|
|
75
|
+
* Returns undefined if the ref hasn't loaded yet.
|
|
76
|
+
*
|
|
77
|
+
* @param ref - The Ref to dereference and subscribe to
|
|
78
|
+
* @param property - Property key to subscribe to
|
|
79
|
+
* @returns The current property value (or undefined if not loaded) and update callback
|
|
80
|
+
*/
|
|
81
|
+
<T, K extends keyof T>(ref: Ref.Ref<T>, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];
|
|
82
|
+
/**
|
|
83
|
+
* Hook to subscribe to a specific property of a Ref's target object that may be undefined.
|
|
84
|
+
* Returns undefined if the ref is undefined or hasn't loaded yet.
|
|
85
|
+
*
|
|
86
|
+
* @param ref - The Ref to dereference and subscribe to (can be undefined)
|
|
87
|
+
* @param property - Property key to subscribe to
|
|
88
|
+
* @returns The current property value (or undefined) and update callback
|
|
89
|
+
*/
|
|
90
|
+
<T, K extends keyof T>(ref: Ref.Ref<T> | undefined, property: K): [T[K] | undefined, ObjectPropUpdateCallback<T[K]>];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Hook to subscribe to multiple Refs' target objects.
|
|
94
|
+
* Automatically dereferences each ref and handles async loading.
|
|
95
|
+
* Returns an array of loaded snapshots (filtering out undefined values).
|
|
96
|
+
*
|
|
97
|
+
* This hook is useful for aggregate computations like counts or filtering
|
|
98
|
+
* across multiple refs without using .target directly.
|
|
99
|
+
*
|
|
100
|
+
* @param refs - Array of Refs to dereference and subscribe to
|
|
101
|
+
* @returns Array of loaded target snapshots (excludes unloaded refs)
|
|
102
|
+
*/
|
|
103
|
+
export declare const useObjects: <T extends Obj.Unknown>(refs: readonly Ref.Ref<T>[]) => Obj.Snapshot<T>[];
|
|
104
|
+
//# sourceMappingURL=useObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObject.d.ts","sourceRoot":"","sources":["../../../src/useObject.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IAC9C,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACzD;AAED,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IAChD,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC1D,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,SAAS,EAAE;IACtB;;;;;;;OAOG;IACH,CAAC,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjG;;;;;;OAMG;IACH,CAAC,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,C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CAAC,CAAC,CAAC;IAEtD;;;;;;;;OAQG;IACH,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzG;;;;;;;OAOG;IACH,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAwC9G,CAAC;AAuBV;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAgB9F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useObject.test.d.ts","sourceRoot":"","sources":["../../../src/useObject.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=useQuery.__test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.__test.d.ts","sourceRoot":"","sources":["../../../src/useQuery.__test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Database, type Entity, Filter, Query } from '@dxos/echo';
|
|
2
|
+
interface UseQueryFn {
|
|
3
|
+
<Q extends Query.Any, O extends Entity.Entity<Query.Type<Q>> = Entity.Entity<Query.Type<Q>>>(resource: Database.Queryable | undefined, query: Q): O[];
|
|
4
|
+
<F extends Filter.Any, O extends Entity.Entity<Filter.Type<F>> = Entity.Entity<Filter.Type<F>>>(resource: Database.Queryable | undefined, filter: F): O[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create subscription.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useQuery: UseQueryFn;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/useQuery.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMvE,UAAU,UAAU;IAClB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACzF,QAAQ,EAAE,QAAQ,CAAC,SAAS,GAAG,SAAS,EACxC,KAAK,EAAE,CAAC,GACP,CAAC,EAAE,CAAC;IAEP,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAC5F,QAAQ,EAAE,QAAQ,CAAC,SAAS,GAAG,SAAS,EACxC,MAAM,EAAE,CAAC,GACR,CAAC,EAAE,CAAC;CACR;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UA8BtB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Database, type Type } from '@dxos/echo';
|
|
2
|
+
/**
|
|
3
|
+
* Subscribe to and retrieve schema changes from a space's schema registry.
|
|
4
|
+
*/
|
|
5
|
+
export declare const useSchema: <T extends Type.Entity.Any = Type.Entity.Any>(db?: Database.Database, typename?: string) => T | undefined;
|
|
6
|
+
//# sourceMappingURL=useSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchema.d.ts","sourceRoot":"","sources":["../../../src/useSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EACnE,KAAK,QAAQ,CAAC,QAAQ,EACtB,WAAW,MAAM,KAChB,CAAC,GAAG,SA2BN,CAAC"}
|