{
  "version": 3,
  "sources": ["../../../src/internal/common/types/entity.ts", "../../../src/internal/Annotation/util.ts"],
  "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.\n//   Unique symbols cause TS4023 \"cannot be named\" errors when external packages\n//   try to export types that reference this key (e.g., `export const Graph = ...`).\n//   TypeScript cannot emit declaration files that reference unique symbols from\n//   external modules. Using a string literal allows the type to be inlined in\n//   declaration files, making the API portable across package boundaries.\n\n/**\n * String key used to identify the kind of an entity instance (object or relation).\n */\nexport const KindId = '~@dxos/echo/Kind' as const;\nexport type KindId = typeof KindId;\n\n/**\n * String key used to identify the kind of a schema (object schema or relation schema).\n * Parallels KindId which identifies instance kinds.\n */\nexport const SchemaKindId = '~@dxos/echo/SchemaKind' as const;\nexport type SchemaKindId = typeof SchemaKindId;\n\n/**\n * String key used to brand snapshot types.\n * Snapshots have SnapshotKindId instead of KindId, making them\n * distinguishable from reactive objects at the type level.\n */\nexport const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;\nexport type SnapshotKindId = typeof SnapshotKindId;\n\n/**\n * Hidden slot on a static `Type.Type` entity that holds the source Effect\n * Schema. `Type.getSchema(...)` reads this for static types; persisted types\n * rebuild from `jsonSchema` instead. Stored as a string key for declaration\n * portability (see KindId comment above).\n */\nexport const StaticTypeSchemaSlot = '~@dxos/echo/Type.StaticSchema' as const;\nexport type StaticTypeSchemaSlot = typeof StaticTypeSchemaSlot;\n\n/**\n * Read the hidden `StaticTypeSchemaSlot` off any value that may carry one.\n * Returns `undefined` for raw schemas (no slot) and non-object inputs.\n * Single point-of-cast for the slot lookup.\n */\nexport const getStaticTypeSchema = (value: unknown): Schema.Schema.AnyNoContext | undefined => {\n  if (value == null || typeof value !== 'object') {\n    return undefined;\n  }\n  return (value as { [StaticTypeSchemaSlot]?: Schema.Schema.AnyNoContext })[StaticTypeSchemaSlot];\n};\n\n/**\n * Read the `[SchemaKindId]` brand off a value. Returns `undefined` for raw\n * schemas (which don't carry the brand on their static type) and non-object\n * inputs. Single point-of-cast for the brand lookup.\n */\nexport const getSchemaKind = (value: unknown): EntityKind | undefined => {\n  if (value == null || typeof value !== 'object') {\n    return undefined;\n  }\n  return (value as { [SchemaKindId]?: EntityKind })[SchemaKindId];\n};\n\n/**\n * Read the `[KindId]` brand off a value. Returns `undefined` for raw schemas\n * and non-object inputs. Companion to {@link getSchemaKind}.\n */\nexport const getEntityKindBrand = (value: unknown): EntityKind | undefined => {\n  if (value == null || typeof value !== 'object') {\n    return undefined;\n  }\n  return (value as { [KindId]?: EntityKind })[KindId];\n};\n\n/**\n * Phantom string key on `Type<A>` entities that carries the instance type `A`.\n * Lets internal helpers (`makeObject`, `createObject`, etc.) pattern-match the\n * instance type from an entity input without importing from the top-level\n * `Type` module. Mirrors `Type.InstancePhantomId` (declared in `Type.ts`).\n *\n * Stored as a string key so declarations remain portable across packages\n * (see KindId comment above).\n */\nexport const InstancePhantomId = '~@dxos/echo/Type.Instance' as const;\nexport type InstancePhantomId = typeof InstancePhantomId;\n\n/**\n * Nominal brand carried by the well-known \"any object\" / \"any relation\"\n * schemas (`Obj.Unknown`, `Relation.Unknown`). The brand lets `Ref.Ref`,\n * `Filter.type`, and `Query.type` accept these schemas in addition to\n * `Type.Type` entities, without opening the door to arbitrary raw schemas.\n *\n * Stored as a string key so declarations remain portable across packages\n * (see KindId comment above).\n */\nexport const UnknownTypeSchemaBrandId = '~@dxos/echo/UnknownTypeSchemaBrand' as const;\nexport type UnknownTypeSchemaBrandId = typeof UnknownTypeSchemaBrandId;\n\n/**\n * Schema-side companion to `Type.Type` entities for the \"any object\" /\n * \"any relation\" cases. Branded so `Ref.Ref` / `Filter.type` / `Query.type`\n * can pattern-match on it; arbitrary `Schema.Schema` values do not satisfy\n * this shape.\n */\nexport interface UnknownTypeSchema<A, K extends EntityKind> extends Schema.Schema<A, any, never> {\n  readonly [UnknownTypeSchemaBrandId]: K;\n}\n\n/**\n * Kinds of entities stored in ECHO: objects, relations, and types.\n */\nexport enum EntityKind {\n  Object = 'object',\n  Relation = 'relation',\n  Type = 'type',\n}\n\nexport const EntityKindSchema = Schema.Enums(EntityKind);\n\n/**\n * Typename for generic object references (Type.Obj / Ref.Ref(Obj.Unknown)).\n * Used when referencing any object without a specific schema.\n */\nexport const ANY_OBJECT_TYPENAME = 'org.dxos.schema.anyObject';\n\n/**\n * Version for generic object references.\n */\nexport const ANY_OBJECT_VERSION = '0.0.0';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\n\nimport { EntityKind } from '../common/types';\n\nexport interface AnnotationHelper<T> {\n  /**\n   * Get the annotation value from an Effect schema.\n   *\n   * Only accepts `Schema.Schema.Any` — to read an annotation off a `Type.Type`\n   * entity, unwrap it first with `Type.getSchema(entity)`. This keeps the\n   * annotation pipeline single-shaped and forces annotations to live on the\n   * source schema, not on the post-construction Type entity.\n   */\n  get: (schema: Schema.Schema.Any) => Option.Option<T>;\n  /**\n   * Get the annotation value from the AST.\n   */\n  getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;\n  /**\n   * Set the annotation on an Effect schema.\n   *\n   * Only accepts `Schema.Schema.Any` — annotations must be applied to the\n   * source schema BEFORE wrapping it with `Type.makeObject` / `Type.makeRelation`.\n   * In a pipe, place every `Annotation.X.set(...)` before the `Type.make...` step.\n   */\n  set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;\n}\n\n/**\n * Note: only for system annotations.\n */\n// TODO(dmaretskyi): Rename to createSystemAnnotationHelper.\n// TODO(dmaretskyi): REconcile with Annotation.make.\nexport const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {\n  return {\n    get: (schema) => SchemaAST.getAnnotation(schema.ast, id),\n    getFromAst: (ast) => SchemaAST.getAnnotation(ast, id),\n    set:\n      (value) =>\n      <S extends Schema.Schema.Any>(schema: S): S =>\n        schema.annotations({ [id]: value }) as S,\n  };\n};\n\n/**\n * If property is optional returns the nested property, otherwise returns the property.\n */\n// TODO(wittjosiah): Is there a way to do this as a generic?\nexport const unwrapOptional = (property: SchemaAST.PropertySignature) => {\n  if (!property.isOptional || !SchemaAST.isUnion(property.type)) {\n    return property;\n  }\n\n  return property.type.types[0];\n};\n\n/**\n * @see JSONSchemaAnnotationId\n * @returns JSON-schema annotation so that the schema can be serialized with correct parameters.\n */\n// TODO(burdon): Required type.\nexport const makeTypeJsonSchemaAnnotation = (options: {\n  identifier?: string;\n  kind: EntityKind;\n  typename: string;\n  version: string;\n  relationSource?: string;\n  relationTarget?: string;\n}) => {\n  assertArgument(!!options.relationSource === (options.kind === EntityKind.Relation), 'relationSource');\n  assertArgument(!!options.relationTarget === (options.kind === EntityKind.Relation), 'relationTarget');\n\n  const obj: Record<string, unknown> = {\n    $id: options.identifier ?? DXN.make(options.typename, options.version),\n    entityKind: options.kind,\n    version: options.version,\n    typename: options.typename,\n  };\n  if (options.kind === EntityKind.Relation) {\n    obj.relationSource = { $ref: options.relationSource };\n    obj.relationTarget = { $ref: options.relationTarget };\n  }\n\n  return obj;\n};\n"],
  "mappings": ";AAIA,YAAYA,YAAY;AAYjB,IAAMC,SAAS;AAOf,IAAMC,eAAe;AAQrB,IAAMC,iBAAiB;AASvB,IAAMC,uBAAuB;AAQ7B,IAAMC,sBAAsB,CAACC,UAAAA;AAClC,MAAIA,SAAS,QAAQ,OAAOA,UAAU,UAAU;AAC9C,WAAOC;EACT;AACA,SAAQD,MAAkEF,oBAAAA;AAC5E;AAOO,IAAMI,gBAAgB,CAACF,UAAAA;AAC5B,MAAIA,SAAS,QAAQ,OAAOA,UAAU,UAAU;AAC9C,WAAOC;EACT;AACA,SAAQD,MAA0CJ,YAAAA;AACpD;AAMO,IAAMO,qBAAqB,CAACH,UAAAA;AACjC,MAAIA,SA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QAAQM;IAAe;EACtD;AAEA,SAAOC;AACT;",
  "names": ["Schema", "KindId", "SchemaKindId", "SnapshotKindId", "StaticTypeSchemaSlot", "getStaticTypeSchema", "value", "undefined", "getSchemaKind", "getEntityKindBrand", "InstancePhantomId", "UnknownTypeSchemaBrandId", "EntityKind", "EntityKindSchema", "Enums", "ANY_OBJECT_TYPENAME", "ANY_OBJECT_VERSION", "SchemaAST", "assertArgument", "DXN", "createAnnotationHelper", "id", "get", "schema", "getAnnotation", "ast", "getFromAst", "set", "value", "annotations", "unwrapOptional", "property", "isOptional", "isUnion", "type", "types", "makeTypeJsonSchemaAnnotation", "options", "assertArgument", "relationSource", "kind", "EntityKind", "Relation", "relationTarget", "obj", "$id", "identifier", "DXN", "make", "typename", "version", "entityKind", "$ref"]
}
