{
  "version": 3,
  "sources": ["../../../src/index.ts", "../../../src/Hypergraph.ts", "../../../src/Json.ts", "../../../src/Collection.ts", "../../../src/View.ts", "../../../src/Dataset.ts"],
  "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport { QueryAST } from '@dxos/echo-protocol';\nexport { DXN, EID, URI } from '@dxos/keys';\n\nexport * as Annotation from './Annotation';\nexport * as Database from './Database';\nexport * as Entity from './Entity';\n// TODO(burdon): Rename to Error (less problematic than Obj/Object).\nexport * as Err from './Err';\nexport * as Feed from './Feed';\nexport * as Filter from './Filter';\nexport * as Format from './Format';\nexport * as Hypergraph from './Hypergraph';\nexport * as Json from './Json';\nexport * as JsonSchema from './JsonSchema';\nexport * as Key from './Key';\nexport * as Migration from './Migration';\nexport * as Obj from './Obj';\nexport * as Order from './Order';\nexport * as Query from './Query';\nexport * as QueryResult from './QueryResult';\nexport * as Ref from './Ref';\nexport * as Registry from './Registry';\nexport * as Relation from './Relation';\nexport * as Scope from './Scope';\nexport * as Tag from './Tag';\nexport * as Type from './Type';\nexport * as Collection from './Collection';\nexport * as View from './View';\nexport * as Dataset from './Dataset';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type URI } from '@dxos/keys';\n\nimport type * as Database from './Database';\nimport type * as Entity from './Entity';\nimport type * as internal from './internal';\nimport type * as Key from './Key';\nimport type * as Ref from './Ref';\nimport type * as Registry from './Registry';\n\n/**\n * Resolution context.\n * Affects how non-absolute DXNs are resolved.\n */\nexport interface RefResolutionContext {\n  /**\n   * Space that the resolution is happening from.\n   */\n  space?: Key.SpaceId;\n\n  /**\n   * Feed that the resolution is happening from.\n   * This feed will be searched first, and then the space it belongs to.\n   */\n  feed?: URI.URI;\n}\n\nexport interface RefResolverOptions {\n  /**\n   * Resolution context.\n   * Affects how non-absolute DXNs are resolved.\n   */\n  context?: RefResolutionContext;\n\n  /**\n   * Middleware to change the resolved object before returning it.\n   * @deprecated On track to be removed.\n   */\n  middleware?: (obj: internal.AnyProperties) => internal.AnyProperties;\n}\n\n/**\n * Manages cross-space database interactions.\n */\nexport interface Hypergraph extends Database.Queryable {\n  /**\n   * In-process registry of keyed objects and static schema types.\n   * Populated at startup via `registry.add(objects)` / `registry.add(schemas)`.\n   * Queries that include no explicit from() clause will fan out to this registry automatically.\n   */\n  get registry(): Registry.Registry;\n\n  /**\n   * Query objects.\n   */\n  query: Database.QueryFn;\n\n  /**\n   * Creates a reference to an existing object in the database.\n   *\n   * NOTE: The reference may be dangling if the object is not present in the database.\n   * NOTE: Difference from `Ref.fromURI`\n   * `Ref.fromURI(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n   * `db.makeRef(dxn)` is preferable in cases with access to the database.\n   */\n  makeRef<T extends Entity.Unknown = Entity.Unknown>(uri: URI.URI): Ref.Ref<T>;\n\n  /**\n   * @param hostDb Host database for reference resolution.\n   * @param middleware Called with the loaded object. The caller may change the object.\n   * @returns Result of `onLoad`.\n   */\n  // TODO(dmaretskyi): Restructure API: Remove middleware.\n  createRefResolver(options: RefResolverOptions): Ref.Resolver;\n\n  /**\n   * Get a database by space ID.\n   * @returns The database for the given space ID, or undefined if not found.\n   */\n  getDatabase(spaceId: Key.SpaceId): Database.Database | undefined;\n}\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport { EID } from '@dxos/keys';\n\nimport * as Database from './Database';\nimport * as Obj from './Obj';\n\n/**\n * `JSON.stringify` replacer signature.\n *\n * Defined here (rather than re-imported from a UI package) so other ECHO-aware utilities can\n * share a stable signature without creating a dependency edge into the UI tree.\n */\nexport type JsonReplacer = (key: string, value: any) => any;\n\nexport type CreateRefReplacerOptions = {\n  db: Database.Database;\n  /** How many ref hops to follow. `0` leaves all refs as-is. Default: `1`. */\n  depth?: number;\n};\n\nconst isEncodedRef = (value: unknown): value is { '/': string } =>\n  typeof value === 'object' &&\n  value !== null &&\n  Object.keys(value as object).length === 1 &&\n  typeof (value as { '/': unknown })['/'] === 'string';\n\nconst toJson = (obj: Obj.Any): unknown => (typeof (obj as any).toJSON === 'function' ? (obj as any).toJSON() : obj);\n\n/**\n * Returns a {@link JsonReplacer} that inlines ECHO ref objects (`{ \"/\": \"echo:...\" }`) up to\n * `depth` ref hops. Beyond that depth refs are left in their encoded form.\n *\n * Implemented as a per-call `JSON.stringify` replacer (not a one-shot tree walk at root) so it\n * composes with wrappers like `safeStringify` that intercept the root call. JSON.stringify\n * already drives the recursion; we only need to (a) detect a ref at the current callback,\n * (b) resolve and return the target if hop budget remains, and (c) tag the returned object\n * with its hop count so children know how far in they are.\n *\n * The hop count is tracked per-object via a `WeakMap`: a ref-resolved target's children inherit\n * `parentHops + 1`; a regular intermediate object's children inherit `parentHops`. This makes the\n * budget count *ref hops*, not tree depth — a ref deep in a tree still resolves once when\n * `depth >= 1`.\n *\n * Note: ECHO objects' `toJSON` runs before the replacer is invoked, so by the time we see a\n * value refs are already encoded as `{ \"/\": \"dxn:...\" }`.\n */\nexport const createRefReplacer = ({ db, depth = 1 }: CreateRefReplacerOptions): JsonReplacer => {\n  // Per-object hop count. Set when we return an object (via ref resolution or pass-through) so\n  // the child callbacks (which carry that object as `this`) can read it.\n  const hops = new WeakMap<object, number>();\n\n  return function (this: any, key: string, value: any) {\n    // Hop count for this call: hops at the parent, or 0 for the root.\n    const parentHops = this && typeof this === 'object' ? (hops.get(this) ?? 0) : 0;\n    if (isEncodedRef(value)) {\n      if (parentHops >= depth) {\n        return value;\n      }\n\n      // The `{ '/': string }` shape is shared with non-DXN IPLD-style refs (e.g. CIDs);\n      // an unparseable string would otherwise crash the whole `JSON.stringify`.\n      // Treat any parse miss as \"leave as-is\" rather than propagating.\n      const dxnString = value['/'];\n      if (!dxnString.startsWith('dxn:') && !dxnString.startsWith('echo:')) {\n        return value;\n      }\n\n      let echoUri: string | undefined;\n      try {\n        const parsed = EID.tryParse(dxnString);\n        echoUri = parsed ? EID.getEntityId(parsed) : undefined;\n      } catch {\n        return value;\n      }\n\n      if (!echoUri) {\n        return value;\n      }\n      const target = db.getObjectById(echoUri);\n      if (!target) {\n        return value;\n      }\n\n      const encoded = toJson(target);\n      if (encoded != null && typeof encoded === 'object') {\n        // Children of the resolved target are one hop deeper.\n        hops.set(encoded as object, parentHops + 1);\n      }\n      return encoded;\n    }\n\n    // Pass-through object: children inherit the parent's hop count (this branch doesn't burn\n    // budget).\n    if (value != null && typeof value === 'object') {\n      hops.set(value, parentHops);\n    }\n\n    return value;\n  };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { DXN } from '@dxos/keys';\n\nimport * as Annotation from './Annotation';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Ref from './Ref';\nimport * as Type from './Type';\n\n/**\n * A an ordered set of objects.\n */\nexport const Collection = Schema.Struct({\n  name: Schema.String.pipe(Schema.optional),\n  objects: Schema.Array(Ref.Ref(Obj.Unknown)).pipe(internal.FormInputAnnotation.set(false)),\n}).pipe(\n  Annotation.IconAnnotation.set({ icon: 'ph--folder--regular', hue: 'amber' }),\n  Type.makeObject(DXN.make('org.dxos.type.collection', '0.1.0')),\n);\n\nexport type Collection = Type.InstanceType<typeof Collection>;\n\nexport const make = (props: Partial<Obj.MakeProps<typeof Collection>> = {}): Collection =>\n  Obj.make(Collection, { objects: [], ...props });\n\nexport const isCollection: (value: unknown) => value is Collection = Obj.instanceOf(Collection);\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { QueryAST } from '@dxos/echo-protocol';\nimport { SchemaEx } from '@dxos/effect';\nimport { DXN, PublicKey } from '@dxos/keys';\n\nimport * as Annotation from './Annotation';\nimport * as Filter from './Filter';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Query from './Query';\nimport * as Type from './Type';\n\n/**\n * Stored field metadata (e.g., for UX).\n */\nexport const FieldSchema = Schema.Struct({\n  id: Schema.String,\n  path: SchemaEx.JsonPath,\n  visible: Schema.optional(Schema.Boolean),\n\n  // TODO(wittjosiah): Presentation-specific?\n  referencePath: Schema.optional(SchemaEx.JsonPath),\n});\n\nexport type FieldType = Schema.Schema.Type<typeof FieldSchema>;\n\nexport const KeyValueProps = Schema.Record({ key: Schema.String, value: Schema.Any });\n\nexport const createFieldId = () => PublicKey.random().truncate();\n\nexport const Projection = Schema.Struct({\n  /**\n   * Optional schema override used to customize the underlying schema.\n   */\n  schema: internal.JsonSchemaType.pipe(Schema.optional),\n\n  /**\n   * UX metadata associated with displayed fields (in table, form, etc.)\n   */\n  // TODO(wittjosiah): Should this just be an array of SchemaEx.JsonPath?\n  fields: Schema.Array(FieldSchema),\n\n  /**\n   * The id for the field used to pivot the view.\n   * E.g., the field to use for kanban columns or the field to use for map coordinates.\n   */\n  pivotFieldId: Schema.String.pipe(Schema.optional),\n});\n\nexport type Projection = Schema.Schema.Type<typeof Projection>;\n\n/**\n * Views are generated or user-defined projections of a schema's properties.\n * They are used to configure the visual representation of the data.\n */\nconst ViewSchema = Schema.Struct({\n  /**\n   * Query used to retrieve data.\n   * Can be a user-provided query grammar string or a query AST.\n   */\n  query: Schema.Struct({\n    raw: Schema.optional(Schema.String),\n    ast: QueryAST.Query,\n  }),\n\n  /**\n   * Projection of the data returned from the query.\n   */\n  projection: Projection,\n}).pipe(\n  internal.HiddenAnnotation.set(true),\n  Annotation.IconAnnotation.set({ icon: 'ph--funnel--regular', hue: 'green' }),\n  Type.makeObject(DXN.make('org.dxos.type.view', '0.1.0')),\n);\n\n// NOTE: Declared as a named interface and the `View` const is annotated `Type.Obj<View>` so\n//   downstream consumers see a named `View` type instead of the inlined `QueryAST.Query` union.\n//   Without the named interface, embedding `Type.getSchema(View.View)` in a downstream\n//   `Schema.Struct` triggers TS2742 portability errors (e.g. plugin-kanban, plugin-table).\n// TODO(wittjosiah): Find a better solution that doesn't require manually keeping the interface in sync.\nexport interface View extends Type.InstanceType<typeof ViewSchema> {}\n\nexport const View: Type.Obj<View> = ViewSchema as any;\n\nexport const make = (props: Partial<Obj.MakeProps<typeof View>>): View => {\n  return Obj.make(View, {\n    query: { ast: Query.select(Filter.nothing()).ast },\n    projection: { fields: [] },\n    ...props,\n  });\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { pipe } from 'effect/Function';\nimport * as Predicate from 'effect/Predicate';\nimport * as Schema from 'effect/Schema';\n\nimport * as Collection from './Collection';\nimport * as Feed from './Feed';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\nimport * as View from './View';\n\n/**\n * Abstract set of objects, represented by a view, feed, or collection.\n * Schema-level union of the underlying type entities (rebuilt via\n * `Type.getSchema`) so this can still be consumed by Schema-side APIs such\n * as `Filter.type(...)` on a union.\n */\nexport type Dataset = Feed.Feed | Collection.Collection | View.View;\nexport const Dataset = Schema.Union(\n  Type.getSchema(Feed.Feed),\n  Type.getSchema(Collection.Collection),\n  Type.getSchema(View.View),\n);\n\nexport const isDataset: (value: unknown) => value is Dataset = pipe(\n  Obj.instanceOf(Feed.Feed),\n  Predicate.or(Obj.instanceOf(Collection.Collection)),\n  Predicate.or(Obj.instanceOf(View.View)),\n);\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,YAAAA,iBAAgB;AACzB,SAASC,OAAAA,MAAKC,OAAAA,MAAKC,WAAW;;;ACL9B;;;ACAA;;;;AAIA,SAASC,WAAW;AAmBpB,IAAMC,eAAe,CAACC,UACpB,OAAOA,UAAU,YACjBA,UAAU,QACVC,OAAOC,KAAKF,KAAAA,EAAiBG,WAAW,KACxC,OAAQH,MAA2B,GAAA,MAAS;AAE9C,IAAMI,SAAS,CAACC,QAA2B,OAAQA,IAAYC,WAAW,aAAcD,IAAYC,OAAM,IAAKD;AAoBxG,IAAME,oBAAoB,CAAC,EAAEC,IAAIC,QAAQ,EAAC,MAA4B;AAG3E,QAAMC,OAAO,oBAAIC,QAAAA;AAEjB,SAAO,SAAqBC,KAAaZ,OAAU;AAE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Y;AAejB,IAAMC,UAAiBC,cACvBC,UAAeC,IAAI,GACnBD,UAAqBE,UAAU,GAC/BF,UAAeG,IAAI,CAAA;AAGnB,IAAMC,YAAkDC,KACzDC,WAAgBL,IAAI,GACdM,aAAOD,WAAsBJ,UAAU,CAAA,GACvCK,aAAOD,WAAgBH,IAAI,CAAA,CAAA;",
  "names": ["QueryAST", "DXN", "EID", "URI", "EID", "isEncodedRef", "value", "Object", "keys", "length", "toJson", "obj", "toJSON", "createRefReplacer", "db", "depth", "hops", "WeakMap", "key", "parentHops", "get", "dxnString", "startsWith", "echoUri", "parsed", "tryParse", "getEntityId", "undefined", "target", "getObjectById", "encoded", "set", "make", "Schema", "DXN", "Collection", "Struct", "name", "String", "pipe", "optional", "objects", "Array", "Ref", "Unknown", "FormInputAnnotation", "set", "IconAnnotation", "icon", "hue", "makeObject", "DXN", "make", "props", "isCollection", "instanceOf", "make", "Schema", "QueryAST", "SchemaEx", "DXN", "PublicKey", "FieldSchema", "Struct", "id", "String", "path", "SchemaEx", "JsonPath", "visible", "optional", "Boolean", "referencePath", "KeyValueProps", "Record", "key", "value", "Any", "createFieldId", "PublicKey", "random", "truncate", "Projection", "schema", "JsonSchemaType", "pipe", "fields", "Array", "pivotFieldId", "ViewSchema", "query", "raw", "ast", "QueryAST", "Query", "projection", "HiddenAnnotation", "set", "IconAnnotation", "icon", "hue", "makeObject", "DXN", "make", "View", "props", "select", "nothing", "pipe", "Predicate", "Schema", "Dataset", "Union", "getSchema", "Feed", "Collection", "View", "isDataset", "pipe", "instanceOf", "or"]
}
