@dxos/echo-solid 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731

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.
@@ -104,7 +104,7 @@ var useObjects = (refs) => {
104
104
  const subscribeToTarget = (ref) => {
105
105
  const target = ref.target;
106
106
  if (target) {
107
- const key = ref.dxn.toString();
107
+ const key = ref.uri;
108
108
  if (!targetUnsubscribes.has(key)) {
109
109
  targetUnsubscribes.set(key, Obj.subscribe(target, triggerUpdate));
110
110
  }
@@ -168,43 +168,40 @@ var useQuery = (resource, queryOrFilter) => {
168
168
  return objects;
169
169
  };
170
170
 
171
- // src/useSchema.ts
171
+ // src/useType.ts
172
172
  import { createEffect as createEffect3, createMemo as createMemo3, createSignal as createSignal3, onCleanup as onCleanup3 } from "solid-js";
173
- var useSchema = (db, typename) => {
174
- const query = createMemo3(() => {
173
+ import { Filter as Filter2, Query as Query2, Scope, Type } from "@dxos/echo";
174
+ var useType = (db, typename) => {
175
+ const resolved = createMemo3(() => {
175
176
  const resolvedDb = typeof db === "function" ? db() : db;
176
177
  const resolvedTypename = typeof typename === "function" ? typename() : typename;
177
178
  if (!resolvedTypename || !resolvedDb) {
178
179
  return void 0;
179
180
  }
180
- return resolvedDb.schemaRegistry.query({
181
- typename: resolvedTypename,
182
- location: [
183
- "database",
184
- "runtime"
185
- ]
186
- });
181
+ return {
182
+ db: resolvedDb,
183
+ typename: resolvedTypename
184
+ };
187
185
  });
188
- const [schema, setSchema] = createSignal3(void 0);
186
+ const [type, setType] = createSignal3(void 0);
189
187
  createEffect3(() => {
190
- const q = query();
191
- if (!q) {
188
+ const r = resolved();
189
+ if (!r) {
192
190
  return;
193
191
  }
194
- const unsubscribe = q.subscribe(() => {
195
- const results = q.results;
196
- setSchema(() => results[0]);
197
- }, {
198
- fire: true
199
- });
192
+ const { db: resolvedDb, typename: resolvedTypename } = r;
193
+ const queryResult = resolvedDb.query(Query2.select(Filter2.type(Type.Type)).from(Scope.space(), Scope.registry()));
194
+ const update = () => setType(() => queryResult.results.find((type2) => Type.getTypename(type2) === resolvedTypename));
195
+ const unsubscribe = queryResult.subscribe(update);
196
+ update();
200
197
  onCleanup3(unsubscribe);
201
198
  });
202
- return schema;
199
+ return type;
203
200
  };
204
201
  export {
205
202
  useObject,
206
203
  useObjects,
207
204
  useQuery,
208
- useSchema
205
+ useType
209
206
  };
210
207
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/useObject.ts", "../../../src/useQuery.ts", "../../../src/useSchema.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 { AtomObj } from '@dxos/echo-atom';\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 // Get the live object for the callback (refs need to dereference).\n const liveObj = createMemo(() => {\n const input = resolvedInput();\n return isRef() ? (input as Ref.Ref<T>)?.target : (input as T | undefined);\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 // For property subscriptions on refs, we subscribe to trigger re-render on load.\n useObjectValue(registry, objOrRef);\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 * AtomObj.make 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 ? registry.get(AtomObj.make(initialInput)) : 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 = AtomObj.make(input);\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(AtomObj.makeProperty(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 = AtomObj.makeProperty(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.dxn.toString();\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, type Type } from '@dxos/echo';\n\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Subscribe to and retrieve schema changes from a database's schema registry.\n * Accepts either values or accessors for db and typename.\n *\n * @param db - The database instance (can be reactive)\n * @param typename - The schema typename to query (can be reactive)\n * @returns An accessor that returns the current schema or undefined\n */\nexport const useSchema = <T extends Type.AnyEntity = Type.AnyEntity>(\n db?: MaybeAccessor<Database.Database | undefined>,\n typename?: MaybeAccessor<string | undefined>,\n): Accessor<T | undefined> => {\n // Derive the schema query reactively\n const query = createMemo(() => {\n const resolvedDb = typeof db === 'function' ? db() : db;\n const resolvedTypename = typeof typename === 'function' ? typename() : typename;\n if (!resolvedTypename || !resolvedDb) {\n return undefined;\n }\n return resolvedDb.schemaRegistry.query({ typename: resolvedTypename, location: ['database', 'runtime'] });\n });\n\n // Store the current schema in a signal\n const [schema, setSchema] = createSignal<T | undefined>(undefined);\n\n // Subscribe to query changes\n createEffect(() => {\n const q = query();\n if (!q) {\n // Keep previous value during transitions to prevent flickering\n return;\n }\n\n // Subscribe to updates with immediate fire to get initial result and track changes\n // The subscription will automatically start the reactive query\n const unsubscribe = q.subscribe(\n () => {\n // Access results inside the callback to ensure query is running\n const results = q.results;\n setSchema(() => results[0] as T | undefined);\n },\n { fire: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return schema;\n};\n"],
5
- "mappings": ";AAIA,SAA6BA,cAAc;AAC3C,SAAwBC,cAAcC,YAAYC,cAAcC,iBAAiB;AAEjF,SAASC,KAAKC,WAAW;AACzB,SAASC,eAAe;AACxB,SAAwBC,mBAAmB;AA+HpC,SAASC,UACdC,UACAC,UAAY;AAEZ,QAAMC,WAAWJ,YAAAA;AAGjB,QAAMK,gBAAgBX,WAAW,MAAMF,OAA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C,MAAM;IAAK,CAAA;AAGfhB,IAAAA,WAAUa,WAAAA;EACZ,CAAA;AAEA,SAAOH;AACT;",
6
- "names": ["access", "createEffect", "createMemo", "createSignal", "onCleanup", "Obj", "Ref", "AtomObj", "useRegistry", "useObject", "objOrRef", "property", "registry", "resolvedInput", "isRef", "liveObj", "input", "target", "callback", "updateOrValue", "obj", "update", "returnValue", "undefined", "Error", "useObjectValue", "useObjectProperty", "initialInput", "initialValue", "get", "make", "value", "setValue", "atom", "currentValue", "unsubscribe", "subscribe", "immediate", "initialObj", "makeProperty", "currentObj", "useObjects", "refs", "version", "setVersion", "resolvedRefs", "currentRefs", "targetUnsubscribes", "Map", "triggerUpdate", "v", "subscribeToTarget", "ref", "key", "dxn", "toString", "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", "useSchema", "db", "typename", "query", "resolvedDb", "resolvedTypename", "undefined", "schemaRegistry", "location", "schema", "setSchema", "q", "unsubscribe", "subscribe", "results", "fire"]
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 { AtomObj } from '@dxos/echo-atom';\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 // Get the live object for the callback (refs need to dereference).\n const liveObj = createMemo(() => {\n const input = resolvedInput();\n return isRef() ? (input as Ref.Ref<T>)?.target : (input as T | undefined);\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 // For property subscriptions on refs, we subscribe to trigger re-render on load.\n useObjectValue(registry, objOrRef);\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 * AtomObj.make 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 ? registry.get(AtomObj.make(initialInput)) : 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 = AtomObj.make(input);\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(AtomObj.makeProperty(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 = AtomObj.makeProperty(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, Filter, Query, Scope, Type } from '@dxos/echo';\n\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Subscribe to and retrieve a type by typename from a space.\n * Accepts either values or accessors for db and typename.\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 typename - The typename 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 typename?: MaybeAccessor<string | 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 resolvedTypename = typeof typename === 'function' ? typename() : typename;\n if (!resolvedTypename || !resolvedDb) {\n return undefined;\n }\n return { db: resolvedDb, typename: resolvedTypename };\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 // Keep previous value during transitions to prevent flickering.\n return;\n }\n\n const { db: resolvedDb, typename: resolvedTypename } = r;\n\n const queryResult = resolvedDb.query(Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry()));\n const update = () => setType(() => queryResult.results.find((type) => Type.getTypename(type) === resolvedTypename));\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,SAASC,eAAe;AACxB,SAAwBC,mBAAmB;AA+HpC,SAASC,UACdC,UACAC,UAAY;AAEZ,QAAMC,WAAWJ,YAAAA;AAGjB,QAAMK,gBAAgBX,WAAW,MAAMF,OAAOU,QAAAA,CAAAA;AAG9C,QAAMI,QAAQZ,WAAW,MAAMI,IAAIQ,MAAMD,cAAAA,CAAAA,CAAAA;AAGzC,QAAME,UAAUb,WAAW,MAAA;AACzB,UAAMc,QAAQH,cAAAA;AACd,WAAOC,MAAAA,IAAWE,OAAsBC,SAAUD;EACpD,CAAA;AAGA,QAAME,WAAW,CAACC,kBAAAA;AAEhB,UAAMC,MAAMN,MAAAA,IAAWD,cAAAA,GAAgCI,SAASF,QAAAA;AAChE,QAAI,CAACK,KAAK;AACR;IACF;AAEAf,QAAIgB,OAAOD,KAAK,CAACA,SAAAA;AACf,UAAI,OAAOD,kBAAkB,YAAY;AACvC,cAAMG,cAAeH,cAA4CR,aAAaY,SAAYH,KAAIT,QAAAA,IAAYS,IAAAA;AAC1G,YAAIE,gBAAgBC,QAAW;AAC7B,cAAIZ,aAAaY,QAAW;AAC1B,kBAAM,IAAIC,MAAM,oCAAA;UAClB;AACAJ,UAAAA,KAAIT,QAAAA,IAAYW;QAClB;MACF,OAAO;AACL,YAAIX,aAAaY,Q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AAY;AAgBnD,IAAMC,UAAU,CACrBC,IACAC,aAAAA;AAGA,QAAMC,WAAWV,YAAW,MAAA;AAC1B,UAAMW,aAAa,OAAOH,OAAO,aAAaA,GAAAA,IAAOA;AACrD,UAAMI,mBAAmB,OAAOH,aAAa,aAAaA,SAAAA,IAAaA;AACvE,QAAI,CAACG,oBAAoB,CAACD,YAAY;AACpC,aAAOE;IACT;AACA,WAAO;MAAEL,IAAIG;MAAYF,UAAUG;IAAiB;EACtD,CAAA;AAGA,QAAM,CAACE,MAAMC,OAAAA,IAAWd,cAAyCY,MAAAA;AAGjEd,EAAAA,cAAa,MAAA;AACX,UAAMiB,IAAIN,SAAAA;AACV,QAAI,CAACM,GAAG;AAEN;IACF;AAEA,UAAM,EAAER,IAAIG,YAAYF,UAAUG,iBAAgB,IAAKI;AAEvD,UAAMC,cAAcN,WAAWO,MAAMd,OAAMe,OAAOhB,QAAOW,KAAKR,KAAKA,IAAI,CAAA,EAAGc,KAAKf,MAAMgB,MAAK,GAAIhB,MAAMiB,SAAQ,CAAA,CAAA;AAC5G,UAAMC,SAAS,MAAMR,QAAQ,MAAME,YAAYO,QAAQC,KAAK,CAACX,UAASR,KAAKoB,YAAYZ,KAAAA,MAAUF,gBAAAA,CAAAA;AAGjG,UAAMe,cAAcV,YAAYW,UAAUL,MAAAA;AAC1CA,WAAAA;AAEArB,IAAAA,WAAUyB,WAAAA;EACZ,CAAA;AAEA,SAAOb;AACT;",
6
+ "names": ["access", "createEffect", "createMemo", "createSignal", "onCleanup", "Obj", "Ref", "AtomObj", "useRegistry", "useObject", "objOrRef", "property", "registry", "resolvedInput", "isRef", "liveObj", "input", "target", "callback", "updateOrValue", "obj", "update", "returnValue", "undefined", "Error", "useObjectValue", "useObjectProperty", "initialInput", "initialValue", "get", "make", "value", "setValue", "atom", "currentValue", "unsubscribe", "subscribe", "immediate", "initialObj", "makeProperty", "currentObj", "useObjects", "refs", "version", "setVersion", "resolvedRefs", "currentRefs", "targetUnsubscribes", "Map", "triggerUpdate", "v", "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", "Filter", "Query", "Scope", "Type", "useType", "db", "typename", "resolved", "resolvedDb", "resolvedTypename", "undefined", "type", "setType", "r", "queryResult", "query", "select", "from", "space", "registry", "update", "results", "find", "getTypename", "unsubscribe", "subscribe"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/useObject.ts":{"bytes":28950,"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/echo-atom","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/useSchema.ts":{"bytes":5930,"imports":[{"path":"solid-js","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":558,"imports":[{"path":"src/useObject.ts","kind":"import-statement","original":"./useObject"},{"path":"src/useQuery.ts","kind":"import-statement","original":"./useQuery"},{"path":"src/useSchema.ts","kind":"import-statement","original":"./useSchema"}],"format":"esm"}},"outputs":{"dist/lib/neutral/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":22198},"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/echo-atom","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}],"exports":["useObject","useObjects","useQuery","useSchema"],"entryPoint":"src/index.ts","inputs":{"src/useObject.ts":{"bytesInOutput":4172},"src/index.ts":{"bytesInOutput":0},"src/useQuery.ts":{"bytesInOutput":986},"src/useSchema.ts":{"bytesInOutput":922}},"bytes":6239}}}
1
+ {"inputs":{"src/useObject.ts":{"bytes":28895,"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/echo-atom","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":6747,"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":22651},"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/echo-atom","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":4161},"src/index.ts":{"bytesInOutput":0},"src/useQuery.ts":{"bytesInOutput":986},"src/useType.ts":{"bytesInOutput":1150}},"bytes":6452}}}
@@ -1,4 +1,4 @@
1
1
  export * from './useObject';
2
2
  export * from './useQuery';
3
- export * from './useSchema';
3
+ export * from './useType';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type Accessor } from 'solid-js';
2
+ import { type Database, Type } from '@dxos/echo';
3
+ type MaybeAccessor<T> = T | Accessor<T>;
4
+ /**
5
+ * Subscribe to and retrieve a type by typename from a space.
6
+ * Accepts either values or accessors for db and typename.
7
+ *
8
+ * Fans across the owning space db (persisted custom types) and the shared
9
+ * registry (static/runtime plugin types). Persisted types live only in the db,
10
+ * so a registry-only lookup misses them.
11
+ *
12
+ * @param db - The database instance (can be reactive)
13
+ * @param typename - The typename to query (can be reactive)
14
+ * @returns An accessor that returns the current type or undefined
15
+ */
16
+ export declare const useType: (db?: MaybeAccessor<Database.Database | undefined>, typename?: MaybeAccessor<string | undefined>) => Accessor<Type.AnyEntity | undefined>;
17
+ export {};
18
+ //# sourceMappingURL=useType.d.ts.map
@@ -0,0 +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,EAAE,KAAK,QAAQ,EAAwB,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvE,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,QACb,aAAa,CAAC,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,aACtC,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,KAC3C,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAG,SAAS,CAmCrC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useType.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useType.test.d.ts","sourceRoot":"","sources":["../../../src/useType.test.tsx"],"names":[],"mappings":""}