@dxos/echo-solid 0.9.1-main.c7dcc2e112 → 0.10.0
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/useObject.ts", "../../../src/useQuery.ts", "../../../src/useType.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type MaybeAccessor, access } from '@solid-primitives/utils';\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { Obj, Ref } from '@dxos/echo';\nimport { type Registry, useRegistry } from '@dxos/effect-atom-solid';\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\n/**\n * Helper type to conditionally include undefined in return type only if input includes undefined.\n * Only adds undefined if T includes undefined AND R doesn't already include undefined.\n */\ntype ConditionalUndefined<T, R> = [T] extends [Exclude<T, undefined>]\n ? R // T doesn't include undefined, return R as-is\n : [R] extends [Exclude<R, undefined>]\n ? R | undefined // T includes undefined but R doesn't, add undefined\n : R; // Both T and R include undefined, return R as-is (no double undefined)\n\n/**\n * Subscribe to 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 (can be reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T>(ref: MaybeAccessor<Ref.Ref<T>>): [Accessor<T | undefined>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to 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/reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T>(\n ref: MaybeAccessor<Ref.Ref<T> | undefined>,\n): [Accessor<T | undefined>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to an entire Echo object.\n * Returns the current object value accessor and an update callback.\n *\n * @param obj - The Echo object to subscribe to (can be reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown>(\n obj: MaybeAccessor<T>,\n): [Accessor<ConditionalUndefined<T, T>>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to an entire 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/reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown>(\n obj: MaybeAccessor<T | undefined>,\n): [Accessor<ConditionalUndefined<T, T>>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to a specific property of an Echo object.\n * Returns the current property value accessor and an update callback.\n *\n * @param obj - The Echo object to subscribe to (can be reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown, K extends keyof T>(\n obj: MaybeAccessor<T>,\n property: K,\n): [Accessor<T[K]>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * 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/reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown, K extends keyof T>(\n obj: MaybeAccessor<T | undefined>,\n property: K,\n): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * 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 (can be reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T, K extends keyof T>(\n ref: MaybeAccessor<Ref.Ref<T>>,\n property: K,\n): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * 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/reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T, K extends keyof T>(\n ref: MaybeAccessor<Ref.Ref<T> | undefined>,\n property: K,\n): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * Subscribe to an Echo object or Ref (entire object or specific property).\n * Returns the current value accessor and an update callback.\n *\n * @param objOrRef - The Echo object or Ref to subscribe to (can be reactive)\n * @param property - Optional property key to subscribe to a specific property\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown, K extends keyof T>(\n objOrRef: MaybeAccessor<T | Ref.Ref<T> | undefined>,\n property?: K,\n): [Accessor<any>, ObjectUpdateCallback<T> | ObjectPropUpdateCallback<T[K]>] {\n const registry = useRegistry();\n\n // Memoize the resolved input to track changes.\n const resolvedInput = createMemo(() => access(objOrRef));\n\n // Determine if input is a ref.\n const isRef = createMemo(() => Ref.isRef(resolvedInput()));\n\n // Signal to notify when a ref's target loads.\n // Incremented by the ref.atom subscription below so that liveObj re-evaluates.\n const [refLoadVersion, setRefLoadVersion] = createSignal(0, { equals: false });\n\n // Subscribe to ref.atom (load-only) to detect when the ref target becomes available.\n // This drives liveObj reactivity for the property-subscription case.\n createEffect(() => {\n const input = resolvedInput();\n if (!input || !Ref.isRef(input)) {\n return;\n }\n const unsubscribe = registry.subscribe(\n input.atom,\n () => {\n setRefLoadVersion((v) => v + 1);\n },\n { immediate: false },\n );\n onCleanup(unsubscribe);\n });\n\n // Get the live object for the callback (refs need to dereference).\n // For refs, depends on refLoadVersion so it re-evaluates when the target loads.\n const liveObj = createMemo(() => {\n const input = resolvedInput();\n if (!isRef()) {\n return input as T | undefined;\n }\n refLoadVersion();\n return (input as Ref.Ref<T>)?.target;\n });\n\n // Create a stable callback that handles both object and property updates.\n const callback = (updateOrValue: unknown | ((obj: unknown) => unknown)) => {\n // Get current target for refs (may have loaded since render).\n const obj = isRef() ? (resolvedInput() as Ref.Ref<T>)?.target : liveObj();\n if (!obj) {\n return;\n }\n\n Obj.update(obj, (obj: any) => {\n if (typeof updateOrValue === 'function') {\n const returnValue = (updateOrValue as (obj: unknown) => unknown)(property !== undefined ? obj[property] : obj);\n if (returnValue !== undefined) {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n obj[property] = returnValue;\n }\n } else {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n obj[property] = updateOrValue;\n }\n });\n };\n\n if (property !== undefined) {\n return [useObjectProperty(registry, liveObj, property), callback as ObjectPropUpdateCallback<T[K]>];\n } else {\n return [useObjectValue(registry, objOrRef), callback as ObjectUpdateCallback<T>];\n }\n}\n\n/**\n * Internal function for subscribing to an Echo object or Ref.\n * Obj.atom handles both objects and refs, returning snapshots.\n */\nfunction useObjectValue<T extends Obj.Unknown>(\n registry: Registry.Registry,\n objOrRef: MaybeAccessor<T | Ref.Ref<T> | undefined>,\n): Accessor<T | undefined> {\n // Memoize the resolved input to track changes.\n const resolvedInput = createMemo(() => access(objOrRef));\n\n // Initialize with the current value (if available).\n const initialInput = resolvedInput();\n const initialValue = initialInput\n ? registry.get(Ref.isRef(initialInput) ? Obj.atom(initialInput) : Obj.atom(initialInput as T))\n : undefined;\n const [value, setValue] = createSignal<T | undefined>(initialValue as T | undefined);\n\n // Subscribe to atom updates.\n createEffect(() => {\n const input = resolvedInput();\n\n if (!input) {\n setValue(() => undefined);\n return;\n }\n\n const atom = Ref.isRef(input) ? Obj.atom(input) : Obj.atom(input as T);\n const currentValue = registry.get(atom);\n setValue(() => currentValue as unknown as T);\n\n const unsubscribe = registry.subscribe(\n atom,\n () => {\n setValue(() => registry.get(atom) as unknown as T);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return value;\n}\n\n/**\n * Internal function for subscribing to a specific property of an Echo object.\n */\nfunction useObjectProperty<T extends Obj.Unknown, K extends keyof T>(\n registry: Registry.Registry,\n obj: Accessor<T | undefined>,\n property: K,\n): Accessor<T[K] | undefined> {\n // Initialize with the current value (if available).\n const initialObj = obj();\n const initialValue = initialObj ? registry.get(Obj.atomProperty(initialObj, property)) : undefined;\n const [value, setValue] = createSignal<T[K] | undefined>(initialValue);\n\n // Subscribe to atom updates.\n createEffect(() => {\n const currentObj = obj();\n\n if (!currentObj) {\n setValue(() => undefined);\n return;\n }\n\n const atom = Obj.atomProperty(currentObj, property);\n const currentValue = registry.get(atom);\n setValue(() => currentValue);\n\n const unsubscribe = registry.subscribe(\n atom,\n () => {\n setValue(() => registry.get(atom) as T[K]);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return value;\n}\n\n/**\n * Subscribe to multiple Refs' target objects.\n * Automatically dereferences each ref and handles async loading.\n * Returns an accessor to 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 (can be reactive)\n * @returns Accessor to array of loaded target snapshots (excludes unloaded refs)\n */\nexport const useObjects = <T extends Obj.Unknown>(refs: MaybeAccessor<readonly Ref.Ref<T>[]>): Accessor<T[]> => {\n // Track version to trigger re-renders when any ref or target changes.\n const [version, setVersion] = createSignal(0);\n\n // Memoize the refs array to track changes.\n const resolvedRefs = createMemo(() => access(refs));\n\n // Subscribe to all refs and their targets.\n createEffect(() => {\n const currentRefs = resolvedRefs();\n const targetUnsubscribes = new Map<string, () => void>();\n\n // Function to trigger re-render.\n const triggerUpdate = () => {\n setVersion((v) => v + 1);\n };\n\n // Function to set up subscription for a target.\n const subscribeToTarget = (ref: Ref.Ref<T>) => {\n const target = ref.target;\n if (target) {\n const key = ref.uri;\n if (!targetUnsubscribes.has(key)) {\n targetUnsubscribes.set(key, Obj.subscribe(target, triggerUpdate));\n }\n }\n };\n\n // Try to load all refs and subscribe to targets.\n for (const ref of currentRefs) {\n // Subscribe to existing target if available.\n subscribeToTarget(ref);\n\n // Trigger async load if not already loaded.\n if (!ref.target) {\n void ref\n .load()\n .then(() => {\n subscribeToTarget(ref);\n triggerUpdate();\n })\n .catch(() => {\n // Ignore load errors.\n });\n }\n }\n\n onCleanup(() => {\n targetUnsubscribes.forEach((u) => u());\n });\n });\n\n // Compute current snapshots by reading each ref's target.\n return createMemo(() => {\n // Depend on version to re-compute when targets change.\n version();\n\n const currentRefs = resolvedRefs();\n const snapshots: T[] = [];\n for (const ref of currentRefs) {\n const target = ref.target;\n if (target !== undefined) {\n snapshots.push(target as T);\n }\n }\n return snapshots;\n });\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { type Database, type Entity, Filter, Query } from '@dxos/echo';\n\nconst EMPTY_ARRAY: never[] = [];\n\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Create a reactive query subscription.\n * Accepts either values or accessors for resource and query/filter.\n *\n * @param resource - The database or queryable resource (can be reactive)\n * @param queryOrFilter - The query or filter to apply (can be reactive)\n * @returns An accessor that returns the current query results\n */\nexport const useQuery = <T extends Entity.Any = Entity.Any>(\n resource: MaybeAccessor<Database.Queryable | undefined>,\n queryOrFilter: MaybeAccessor<Query.Any | Filter.Any>,\n): Accessor<T[]> => {\n // Derive the normalized query from the input\n const query = createMemo(() => {\n const resolved = typeof queryOrFilter === 'function' ? queryOrFilter() : queryOrFilter;\n return Filter.is(resolved) ? Query.select(resolved) : resolved;\n });\n\n // Derive the query result object reactively\n const queryResult = createMemo(() => {\n const q = query();\n const resolvedResource = typeof resource === 'function' ? resource() : resource;\n return resolvedResource?.query(q);\n });\n\n // Store the current results in a signal\n const [objects, setObjects] = createSignal<T[]>(EMPTY_ARRAY as T[]);\n\n // Subscribe to query result changes\n createEffect(() => {\n const result = queryResult();\n if (!result) {\n // Keep previous value during transitions to prevent flickering\n return;\n }\n\n // Subscribe with immediate fire to get initial results\n const unsubscribe = result.subscribe(\n () => {\n setObjects(() => result.results as T[]);\n },\n { fire: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return objects;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { DXN, EID, URI, type Database, Filter, Query, Scope, Type } from '@dxos/echo';\n\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Subscribe to and retrieve a type by its URI from a space: a static schema's typename DXN, or a\n * persisted (database) schema's `echo:` EID (what `Type.getURI` / `getTypeURIFromQuery` produce).\n * Accepts either values or accessors for db and typeUri.\n *\n * Fans across the owning space db (persisted custom types) and the shared\n * registry (static/runtime plugin types). Persisted types live only in the db,\n * so a registry-only lookup misses them.\n *\n * @param db - The database instance (can be reactive)\n * @param typeUri - The type URI to query (can be reactive)\n * @returns An accessor that returns the current type or undefined\n */\nexport const useType = (\n db?: MaybeAccessor<Database.Database | undefined>,\n typeUri?: MaybeAccessor<URI.URI | undefined>,\n): Accessor<Type.AnyEntity | undefined> => {\n // Derive resolved values reactively.\n const resolved = createMemo(() => {\n const resolvedDb = typeof db === 'function' ? db() : db;\n const resolvedTypeUri = typeof typeUri === 'function' ? typeUri() : typeUri;\n if (!resolvedTypeUri || !resolvedDb) {\n return undefined;\n }\n return { db: resolvedDb, typeUri: resolvedTypeUri };\n });\n\n // Store the current type in a signal.\n const [type, setType] = createSignal<Type.AnyEntity | undefined>(undefined);\n\n // Subscribe to registry changes.\n createEffect(() => {\n const r = resolved();\n if (!r) {\n setType(() => undefined);\n return;\n }\n\n const { db: resolvedDb, typeUri: resolvedTypeUri } = r;\n\n const searchEid = EID.isEID(resolvedTypeUri) ? EID.tryParse(resolvedTypeUri) : undefined;\n const searchDxn = DXN.isDXN(resolvedTypeUri) ? DXN.tryMake(resolvedTypeUri) : undefined;\n const queryResult = resolvedDb.query(Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry()));\n const update = () =>\n setType(() =>\n queryResult.results.find((type) => {\n const uri = Type.getURI(type);\n if (uri === resolvedTypeUri) {\n return true;\n }\n // EID matching is space-agnostic: echo:/<id> matches echo://<space>/<id>.\n if (searchEid && EID.isEID(uri)) {\n const typeEid = EID.tryParse(uri);\n return typeEid != null && EID.getEntityId(typeEid) === EID.getEntityId(searchEid);\n }\n // DXN matching is version-agnostic so callers may pass an unversioned DXN.\n if (searchDxn && DXN.isDXN(uri)) {\n const typeDxn = DXN.tryMake(uri);\n return typeDxn != null && DXN.getName(typeDxn) === DXN.getName(searchDxn);\n }\n return false;\n }),\n );\n\n // Subscribe before reading `.results` — the query requires at least one subscriber.\n const unsubscribe = queryResult.subscribe(update);\n update();\n\n onCleanup(unsubscribe);\n });\n\n return type;\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAA6BA,cAAc;AAC3C,SAAwBC,cAAcC,YAAYC,cAAcC,iBAAiB;AAEjF,SAASC,KAAKC,WAAW;AACzB,SAAwBC,mBAAmB;AA+HpC,SAASC,UACdC,UACAC,UAAY;AAEZ,QAAMC,WAAWJ,YAAAA;AAGjB,QAAMK,gBAAgBV,WAAW,MAAMF,OAAOS,QAAAA,CAAAA;AAG9C,QAAMI,QAAQX,WAAW,MAAMI,IAAIO,MAAMD,cAAAA,CAAAA,CAAAA;AAIzC,QAAM,CAACE,gBAAgBC,iBAAAA,IAAqBZ,aAAa,GAAG;IAAEa,QAAQ;EAAM,CAAA;AAI5Ef,eAAa,MAAA;AACX,UAAMgB,QAAQL,cAAAA;AACd,QAAI,CAACK,SAAS,CAACX,IAAIO,MAAMI,KAAAA,GAAQ;AAC/B;IACF;AACA,UAAMC,cAAcP,SAASQ,UAC3BF,MAA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C,QAAQC,aAAa;AAE1D,IAAMC,cAAuB,CAAA;AAYtB,IAAMC,WAAW,CACtBC,UACAC,kBAAAA;AAGA,QAAMC,QAAQT,YAAW,MAAA;AACvB,UAAMU,WAAW,OAAOF,kBAAkB,aAAaA,cAAAA,IAAkBA;AACzE,WAAOL,OAAOQ,GAAGD,QAAAA,IAAYN,MAAMQ,OAAOF,QAAAA,IAAYA;EACxD,CAAA;AAGA,QAAMG,cAAcb,YAAW,MAAA;AAC7B,UAAMc,IAAIL,MAAAA;AACV,UAAMM,mBAAmB,OAAOR,aAAa,aAAaA,SAAAA,IAAaA;AACvE,WAAOQ,kBAAkBN,MAAMK,CAAAA;EACjC,CAAA;AAGA,QAAM,CAACE,SAASC,UAAAA,IAAchB,cAAkBI,WAAAA;AAGhDN,EAAAA,cAAa,MAAA;AACX,UAAMmB,SAASL,YAAAA;AACf,QAAI,CAACK,QAAQ;AAEX;IACF;AAGA,UAAMC,cAAcD,OAAOE,UACzB,MAAA;AACEH,iBAAW,MAAMC,OAAOG,OAAO;IACjC,GACA;MAAEC,MAAM;IAAK,CAAA;AAGfpB,IAAAA,WAAUiB,WAAAA;EACZ,CAAA;AAEA,SAAOH;AACT;;;ACxDA,SAAwBO,gBAAAA,eAAcC,cAAAA,aAAYC,gBAAAA,eAAcC,aAAAA,kBAAiB;AAEjF,
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type MaybeAccessor, access } from '@solid-primitives/utils';\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { Obj, Ref } from '@dxos/echo';\nimport { type Registry, useRegistry } from '@dxos/effect-atom-solid';\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\n/**\n * Helper type to conditionally include undefined in return type only if input includes undefined.\n * Only adds undefined if T includes undefined AND R doesn't already include undefined.\n */\ntype ConditionalUndefined<T, R> = [T] extends [Exclude<T, undefined>]\n ? R // T doesn't include undefined, return R as-is\n : [R] extends [Exclude<R, undefined>]\n ? R | undefined // T includes undefined but R doesn't, add undefined\n : R; // Both T and R include undefined, return R as-is (no double undefined)\n\n/**\n * Subscribe to 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 (can be reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T>(ref: MaybeAccessor<Ref.Ref<T>>): [Accessor<T | undefined>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to 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/reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T>(\n ref: MaybeAccessor<Ref.Ref<T> | undefined>,\n): [Accessor<T | undefined>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to an entire Echo object.\n * Returns the current object value accessor and an update callback.\n *\n * @param obj - The Echo object to subscribe to (can be reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown>(\n obj: MaybeAccessor<T>,\n): [Accessor<ConditionalUndefined<T, T>>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to an entire 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/reactive)\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown>(\n obj: MaybeAccessor<T | undefined>,\n): [Accessor<ConditionalUndefined<T, T>>, ObjectUpdateCallback<T>];\n\n/**\n * Subscribe to a specific property of an Echo object.\n * Returns the current property value accessor and an update callback.\n *\n * @param obj - The Echo object to subscribe to (can be reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown, K extends keyof T>(\n obj: MaybeAccessor<T>,\n property: K,\n): [Accessor<T[K]>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * 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/reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown, K extends keyof T>(\n obj: MaybeAccessor<T | undefined>,\n property: K,\n): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * 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 (can be reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T, K extends keyof T>(\n ref: MaybeAccessor<Ref.Ref<T>>,\n property: K,\n): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * 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/reactive)\n * @param property - Property key to subscribe to\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T, K extends keyof T>(\n ref: MaybeAccessor<Ref.Ref<T> | undefined>,\n property: K,\n): [Accessor<T[K] | undefined>, ObjectPropUpdateCallback<T[K]>];\n\n/**\n * Subscribe to an Echo object or Ref (entire object or specific property).\n * Returns the current value accessor and an update callback.\n *\n * @param objOrRef - The Echo object or Ref to subscribe to (can be reactive)\n * @param property - Optional property key to subscribe to a specific property\n * @returns A tuple of [accessor, updateCallback]\n */\nexport function useObject<T extends Obj.Unknown, K extends keyof T>(\n objOrRef: MaybeAccessor<T | Ref.Ref<T> | undefined>,\n property?: K,\n): [Accessor<any>, ObjectUpdateCallback<T> | ObjectPropUpdateCallback<T[K]>] {\n const registry = useRegistry();\n\n // Memoize the resolved input to track changes.\n const resolvedInput = createMemo(() => access(objOrRef));\n\n // Determine if input is a ref.\n const isRef = createMemo(() => Ref.isRef(resolvedInput()));\n\n // Signal to notify when a ref's target loads.\n // Incremented by the ref.atom subscription below so that liveObj re-evaluates.\n const [refLoadVersion, setRefLoadVersion] = createSignal(0, { equals: false });\n\n // Subscribe to ref.atom (load-only) to detect when the ref target becomes available.\n // This drives liveObj reactivity for the property-subscription case.\n createEffect(() => {\n const input = resolvedInput();\n if (!input || !Ref.isRef(input)) {\n return;\n }\n const unsubscribe = registry.subscribe(\n input.atom,\n () => {\n setRefLoadVersion((v) => v + 1);\n },\n { immediate: false },\n );\n onCleanup(unsubscribe);\n });\n\n // Get the live object for the callback (refs need to dereference).\n // For refs, depends on refLoadVersion so it re-evaluates when the target loads.\n const liveObj = createMemo(() => {\n const input = resolvedInput();\n if (!isRef()) {\n return input as T | undefined;\n }\n refLoadVersion();\n return (input as Ref.Ref<T>)?.target;\n });\n\n // Create a stable callback that handles both object and property updates.\n const callback = (updateOrValue: unknown | ((obj: unknown) => unknown)) => {\n // Get current target for refs (may have loaded since render).\n const obj = isRef() ? (resolvedInput() as Ref.Ref<T>)?.target : liveObj();\n if (!obj) {\n return;\n }\n\n Obj.update(obj, (obj: any) => {\n if (typeof updateOrValue === 'function') {\n const returnValue = (updateOrValue as (obj: unknown) => unknown)(property !== undefined ? obj[property] : obj);\n if (returnValue !== undefined) {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n obj[property] = returnValue;\n }\n } else {\n if (property === undefined) {\n throw new Error('Cannot re-assign the entire object');\n }\n obj[property] = updateOrValue;\n }\n });\n };\n\n if (property !== undefined) {\n return [useObjectProperty(registry, liveObj, property), callback as ObjectPropUpdateCallback<T[K]>];\n } else {\n return [useObjectValue(registry, objOrRef), callback as ObjectUpdateCallback<T>];\n }\n}\n\n/**\n * Internal function for subscribing to an Echo object or Ref.\n * Obj.atom handles both objects and refs, returning snapshots.\n */\nfunction useObjectValue<T extends Obj.Unknown>(\n registry: Registry.Registry,\n objOrRef: MaybeAccessor<T | Ref.Ref<T> | undefined>,\n): Accessor<T | undefined> {\n // Memoize the resolved input to track changes.\n const resolvedInput = createMemo(() => access(objOrRef));\n\n // Initialize with the current value (if available).\n const initialInput = resolvedInput();\n const initialValue = initialInput\n ? registry.get(Ref.isRef(initialInput) ? Obj.atom(initialInput) : Obj.atom(initialInput as T))\n : undefined;\n const [value, setValue] = createSignal<T | undefined>(initialValue as T | undefined);\n\n // Subscribe to atom updates.\n createEffect(() => {\n const input = resolvedInput();\n\n if (!input) {\n setValue(() => undefined);\n return;\n }\n\n const atom = Ref.isRef(input) ? Obj.atom(input) : Obj.atom(input as T);\n const currentValue = registry.get(atom);\n setValue(() => currentValue as unknown as T);\n\n const unsubscribe = registry.subscribe(\n atom,\n () => {\n setValue(() => registry.get(atom) as unknown as T);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return value;\n}\n\n/**\n * Internal function for subscribing to a specific property of an Echo object.\n */\nfunction useObjectProperty<T extends Obj.Unknown, K extends keyof T>(\n registry: Registry.Registry,\n obj: Accessor<T | undefined>,\n property: K,\n): Accessor<T[K] | undefined> {\n // Initialize with the current value (if available).\n const initialObj = obj();\n const initialValue = initialObj ? registry.get(Obj.atomProperty(initialObj, property)) : undefined;\n const [value, setValue] = createSignal<T[K] | undefined>(initialValue);\n\n // Subscribe to atom updates.\n createEffect(() => {\n const currentObj = obj();\n\n if (!currentObj) {\n setValue(() => undefined);\n return;\n }\n\n const atom = Obj.atomProperty(currentObj, property);\n const currentValue = registry.get(atom);\n setValue(() => currentValue);\n\n const unsubscribe = registry.subscribe(\n atom,\n () => {\n setValue(() => registry.get(atom) as T[K]);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return value;\n}\n\n/**\n * Subscribe to multiple Refs' target objects.\n * Automatically dereferences each ref and handles async loading.\n * Returns an accessor to 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 (can be reactive)\n * @returns Accessor to array of loaded target snapshots (excludes unloaded refs)\n */\nexport const useObjects = <T extends Obj.Unknown>(refs: MaybeAccessor<readonly Ref.Ref<T>[]>): Accessor<T[]> => {\n // Track version to trigger re-renders when any ref or target changes.\n const [version, setVersion] = createSignal(0);\n\n // Memoize the refs array to track changes.\n const resolvedRefs = createMemo(() => access(refs));\n\n // Subscribe to all refs and their targets.\n createEffect(() => {\n const currentRefs = resolvedRefs();\n const targetUnsubscribes = new Map<string, () => void>();\n\n // Function to trigger re-render.\n const triggerUpdate = () => {\n setVersion((v) => v + 1);\n };\n\n // Function to set up subscription for a target.\n const subscribeToTarget = (ref: Ref.Ref<T>) => {\n const target = ref.target;\n if (target) {\n const key = ref.uri;\n if (!targetUnsubscribes.has(key)) {\n targetUnsubscribes.set(key, Obj.subscribe(target, triggerUpdate));\n }\n }\n };\n\n // Try to load all refs and subscribe to targets.\n for (const ref of currentRefs) {\n // Subscribe to existing target if available.\n subscribeToTarget(ref);\n\n // Trigger async load if not already loaded.\n if (!ref.target) {\n void ref\n .load()\n .then(() => {\n subscribeToTarget(ref);\n triggerUpdate();\n })\n .catch(() => {\n // Ignore load errors.\n });\n }\n }\n\n onCleanup(() => {\n targetUnsubscribes.forEach((u) => u());\n });\n });\n\n // Compute current snapshots by reading each ref's target.\n return createMemo(() => {\n // Depend on version to re-compute when targets change.\n version();\n\n const currentRefs = resolvedRefs();\n const snapshots: T[] = [];\n for (const ref of currentRefs) {\n const target = ref.target;\n if (target !== undefined) {\n snapshots.push(target as T);\n }\n }\n return snapshots;\n });\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { type Database, type Entity, Filter, Query } from '@dxos/echo';\n\nconst EMPTY_ARRAY: never[] = [];\n\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Create a reactive query subscription.\n * Accepts either values or accessors for resource and query/filter.\n *\n * @param resource - The database or queryable resource (can be reactive)\n * @param queryOrFilter - The query or filter to apply (can be reactive)\n * @returns An accessor that returns the current query results\n */\nexport const useQuery = <T extends Entity.Any = Entity.Any>(\n resource: MaybeAccessor<Database.Queryable | undefined>,\n queryOrFilter: MaybeAccessor<Query.Any | Filter.Any>,\n): Accessor<T[]> => {\n // Derive the normalized query from the input\n const query = createMemo(() => {\n const resolved = typeof queryOrFilter === 'function' ? queryOrFilter() : queryOrFilter;\n return Filter.is(resolved) ? Query.select(resolved) : resolved;\n });\n\n // Derive the query result object reactively\n const queryResult = createMemo(() => {\n const q = query();\n const resolvedResource = typeof resource === 'function' ? resource() : resource;\n return resolvedResource?.query(q);\n });\n\n // Store the current results in a signal\n const [objects, setObjects] = createSignal<T[]>(EMPTY_ARRAY as T[]);\n\n // Subscribe to query result changes\n createEffect(() => {\n const result = queryResult();\n if (!result) {\n // Keep previous value during transitions to prevent flickering\n return;\n }\n\n // Subscribe with immediate fire to get initial results\n const unsubscribe = result.subscribe(\n () => {\n setObjects(() => result.results as T[]);\n },\n { fire: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return objects;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { type Database, DXN, EID, Filter, Query, Scope, Type, URI } from '@dxos/echo';\n\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Subscribe to and retrieve a type by its URI from a space: a static schema's typename DXN, or a\n * persisted (database) schema's `echo:` EID (what `Type.getURI` / `getTypeURIFromQuery` produce).\n * Accepts either values or accessors for db and typeUri.\n *\n * Fans across the owning space db (persisted custom types) and the shared\n * registry (static/runtime plugin types). Persisted types live only in the db,\n * so a registry-only lookup misses them.\n *\n * @param db - The database instance (can be reactive)\n * @param typeUri - The type URI to query (can be reactive)\n * @returns An accessor that returns the current type or undefined\n */\nexport const useType = (\n db?: MaybeAccessor<Database.Database | undefined>,\n typeUri?: MaybeAccessor<URI.URI | undefined>,\n): Accessor<Type.AnyEntity | undefined> => {\n // Derive resolved values reactively.\n const resolved = createMemo(() => {\n const resolvedDb = typeof db === 'function' ? db() : db;\n const resolvedTypeUri = typeof typeUri === 'function' ? typeUri() : typeUri;\n if (!resolvedTypeUri || !resolvedDb) {\n return undefined;\n }\n return { db: resolvedDb, typeUri: resolvedTypeUri };\n });\n\n // Store the current type in a signal.\n const [type, setType] = createSignal<Type.AnyEntity | undefined>(undefined);\n\n // Subscribe to registry changes.\n createEffect(() => {\n const r = resolved();\n if (!r) {\n setType(() => undefined);\n return;\n }\n\n const { db: resolvedDb, typeUri: resolvedTypeUri } = r;\n\n const searchEid = EID.isEID(resolvedTypeUri) ? EID.tryParse(resolvedTypeUri) : undefined;\n const searchDxn = DXN.isDXN(resolvedTypeUri) ? DXN.tryMake(resolvedTypeUri) : undefined;\n const queryResult = resolvedDb.query(Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry()));\n const update = () =>\n setType(() =>\n queryResult.results.find((type) => {\n const uri = Type.getURI(type);\n if (uri === resolvedTypeUri) {\n return true;\n }\n // EID matching is space-agnostic: echo:/<id> matches echo://<space>/<id>.\n if (searchEid && EID.isEID(uri)) {\n const typeEid = EID.tryParse(uri);\n return typeEid != null && EID.getEntityId(typeEid) === EID.getEntityId(searchEid);\n }\n // DXN matching is version-agnostic so callers may pass an unversioned DXN.\n if (searchDxn && DXN.isDXN(uri)) {\n const typeDxn = DXN.tryMake(uri);\n return typeDxn != null && DXN.getName(typeDxn) === DXN.getName(searchDxn);\n }\n return false;\n }),\n );\n\n // Subscribe before reading `.results` — the query requires at least one subscriber.\n const unsubscribe = queryResult.subscribe(update);\n update();\n\n onCleanup(unsubscribe);\n });\n\n return type;\n};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QpB,iBAAiB;AAC3B,eAAO;MACT;AAEA,UAAIK,aAAaf,IAAIgB,MAAMc,GAAAA,GAAM;AAC/B,cAAME,UAAUhC,IAAIiB,SAASa,GAAAA;AAC7B,eAAOE,WAAW,QAAQhC,IAAIiC,YAAYD,OAAAA,MAAahC,IAAIiC,YAAYlB,SAAAA;MACzE;AAEA,UAAIG,aAAanB,IAAIoB,MAAMW,GAAAA,GAAM;AAC/B,cAAMI,UAAUnC,IAAIqB,QAAQU,GAAAA;AAC5B,eAAOI,WAAW,QAAQnC,IAAIoC,QAAQD,OAAAA,MAAanC,IAAIoC,QAAQjB,SAAAA;MACjE;AACA,aAAO;IACT,CAAA,CAAA;AAIJ,UAAMkB,cAAcf,YAAYgB,UAAUV,MAAAA;AAC1CA,WAAAA;AAEA7B,IAAAA,WAAUsC,WAAAA;EACZ,CAAA;AAEA,SAAOxB;AACT;",
|
|
6
6
|
"names": ["access", "createEffect", "createMemo", "createSignal", "onCleanup", "Obj", "Ref", "useRegistry", "useObject", "objOrRef", "property", "registry", "resolvedInput", "isRef", "refLoadVersion", "setRefLoadVersion", "equals", "input", "unsubscribe", "subscribe", "atom", "v", "immediate", "liveObj", "target", "callback", "updateOrValue", "obj", "update", "returnValue", "undefined", "Error", "useObjectProperty", "useObjectValue", "initialInput", "initialValue", "get", "value", "setValue", "currentValue", "initialObj", "atomProperty", "currentObj", "useObjects", "refs", "version", "setVersion", "resolvedRefs", "currentRefs", "targetUnsubscribes", "Map", "triggerUpdate", "subscribeToTarget", "ref", "key", "uri", "has", "set", "load", "then", "catch", "forEach", "u", "snapshots", "push", "createEffect", "createMemo", "createSignal", "onCleanup", "Filter", "Query", "EMPTY_ARRAY", "useQuery", "resource", "queryOrFilter", "query", "resolved", "is", "select", "queryResult", "q", "resolvedResource", "objects", "setObjects", "result", "unsubscribe", "subscribe", "results", "fire", "createEffect", "createMemo", "createSignal", "onCleanup", "DXN", "EID", "Filter", "Query", "Scope", "Type", "useType", "db", "typeUri", "resolved", "resolvedDb", "resolvedTypeUri", "undefined", "type", "setType", "r", "searchEid", "isEID", "tryParse", "searchDxn", "isDXN", "tryMake", "queryResult", "query", "select", "from", "space", "registry", "update", "results", "find", "uri", "getURI", "typeEid", "getEntityId", "typeDxn", "getName", "unsubscribe", "subscribe"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/useObject.ts":{"bytes":31307,"imports":[{"path":"@solid-primitives/utils","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/effect-atom-solid","kind":"import-statement","external":true}],"format":"esm"},"src/useQuery.ts":{"bytes":5807,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"format":"esm"},"src/useType.ts":{"bytes":10145,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":552,"imports":[{"path":"src/useObject.ts","kind":"import-statement","original":"./useObject"},{"path":"src/useQuery.ts","kind":"import-statement","original":"./useQuery"},{"path":"src/useType.ts","kind":"import-statement","original":"./useType"}],"format":"esm"}},"outputs":{"dist/lib/neutral/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":
|
|
1
|
+
{"inputs":{"src/useObject.ts":{"bytes":31307,"imports":[{"path":"@solid-primitives/utils","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/effect-atom-solid","kind":"import-statement","external":true}],"format":"esm"},"src/useQuery.ts":{"bytes":5807,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"format":"esm"},"src/useType.ts":{"bytes":10145,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":552,"imports":[{"path":"src/useObject.ts","kind":"import-statement","original":"./useObject"},{"path":"src/useQuery.ts","kind":"import-statement","original":"./useQuery"},{"path":"src/useType.ts","kind":"import-statement","original":"./useType"}],"format":"esm"}},"outputs":{"dist/lib/neutral/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25574},"dist/lib/neutral/index.mjs":{"imports":[{"path":"@solid-primitives/utils","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/effect-atom-solid","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true}],"exports":["useObject","useObjects","useQuery","useType"],"entryPoint":"src/index.ts","inputs":{"src/useObject.ts":{"bytesInOutput":4581},"src/index.ts":{"bytesInOutput":0},"src/useQuery.ts":{"bytesInOutput":986},"src/useType.ts":{"bytesInOutput":1804}},"bytes":7526}}}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Accessor } from 'solid-js';
|
|
2
|
-
import {
|
|
2
|
+
import { type Database, Type, URI } from '@dxos/echo';
|
|
3
3
|
type MaybeAccessor<T> = T | Accessor<T>;
|
|
4
4
|
/**
|
|
5
5
|
* Subscribe to and retrieve a type by its URI from a space: a static schema's typename DXN, or a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useType.d.ts","sourceRoot":"","sources":["../../../src/useType.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAqD,MAAM,UAAU,CAAC;AAE5F,OAAO,
|
|
1
|
+
{"version":3,"file":"useType.d.ts","sourceRoot":"","sources":["../../../src/useType.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAqD,MAAM,UAAU,CAAC;AAE5F,OAAO,EAAE,KAAK,QAAQ,EAAkC,IAAI,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtF,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,QACb,aAAa,CAAC,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,YACvC,aAAa,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,KAC3C,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAwDrC,CAAC"}
|