{
  "version": 3,
  "sources": ["../../../src/Annotation.ts"],
  "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nexport {\n  DescriptionAnnotation,\n  FieldLookupAnnotationId,\n  FormInputAnnotation,\n  FormInlineAnnotation,\n  GeneratorAnnotation,\n  GeneratorAnnotationId,\n  type GeneratorAnnotationValue,\n  LabelAnnotation,\n  ReferenceAnnotation,\n  ReferenceAnnotationId,\n  type ReferenceAnnotationValue,\n  HiddenAnnotation,\n  TypeAnnotation,\n  getDescriptionWithSchema,\n  getLabelWithSchema,\n  getTypeAnnotation,\n  getTypeIdentifierAnnotation,\n  setDescriptionWithSchema,\n  setLabelWithSchema,\n  IconAnnotation,\n  IconFromRefAnnotation,\n} from './internal/Annotation';\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport * as Types from 'effect/Types';\n\nimport * as Entity from './Entity';\nimport * as internalAnnotations from './internal/Annotation';\n\nexport const TypeId = '~@dxos/echo/Annotation' as const;\nexport type TypeId = typeof TypeId;\n\n// TODO(dmaretskyi): Reconcile different get/set styles: mutate in-place, return.\n// TODO(dmaretskyi): Reconcile Annotation methods vs static functions.\n// TODO(dmaretskyi): Reconcile Annotation.Key vs DXN -- work-out approach to versioning.\n\n/**\n * Annotation is a typed property that can be assigned to a schema or an entity instance.\n */\nexport interface Annotation<T> {\n  [TypeId]: {\n    _Type: T;\n  };\n\n  // TODO(dmaretskyi): Make this a DXN?\n  /**\n   * Unique fully-qualified identifier for the annotation.\n   * @example \"org.dxos.annotation.color\"\n   */\n  readonly key: Key;\n\n  /**\n   * Schema of the annotation value.\n   */\n  readonly schema: Schema.Schema<T, unknown, never>;\n\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\nexport const Key = internalAnnotations.Key;\nexport type Key = Schema.Schema.Type<typeof Key>;\n\ninterface MakeProps<T> {\n  id: string;\n  schema: Schema.Schema<T, any, never>;\n}\n\n/**\n * Create a new schema annotation.\n * Annotation can be assigned both to fields and to the schema itself.\n * Annotation is serialized with the schema.\n *\n * @example\n * ```ts\n * const ColorAnnotation = Annotation.make({\n *   id: 'org.dxos.annotation.color',\n *   schema: Schema.String,\n * });\n *\n * const schema = Schema.String.annotations(ColorAnnotation.set('red'));\n * ```\n */\nexport const make: <T>(props: MakeProps<T>) => Annotation<T> = internalAnnotations.makeUserAnnotation;\n\n/**\n * Get the value of an annotation from an entity instance or snapshot.\n * For schema-level reads use the annotation instance method (e.g. `ColorAnnotation.get(schema)`).\n * For getting an annotation value from a dictionary, use `getDictionary`.\n */\nexport const get: {\n  <T>(annotation: Annotation<T>): (target: Entity.Unknown | Entity.Snapshot) => Option.Option<T>;\n  <T>(target: Entity.Unknown | Entity.Snapshot, annotation: Annotation<T>): Option.Option<T>;\n} = Function.dual<\n  <T>(annotation: Annotation<T>) => (target: Entity.Unknown | Entity.Snapshot) => Option.Option<T>,\n  <T>(target: Entity.Unknown | Entity.Snapshot, annotation: Annotation<T>) => Option.Option<T>\n>(2, (target, annotation) => {\n  return internalAnnotations.get(target, annotation);\n});\n\n/**\n * Set the value of an annotation on an entity instance.\n * For schema-level writes use the annotation instance method (e.g. `ColorAnnotation.set('red')`).\n * For setting an annotation value on a dictionary, use `setDictionary`.\n */\nexport const set: {\n  <T>(annotation: Annotation<T>, value: T): (target: Entity.Mutable<Entity.Unknown>) => void;\n  <T>(target: Entity.Mutable<Entity.Unknown>, annotation: Annotation<T>, value: T): void;\n} = Function.dual<\n  <T>(annotation: Annotation<T>, value: T) => (target: Entity.Mutable<Entity.Unknown>) => void,\n  <T>(target: Entity.Mutable<Entity.Unknown>, annotation: Annotation<T>, value: T) => void\n>(3, (target, annotation, value) => {\n  return internalAnnotations.set(target, annotation, value);\n});\n\nexport const getFromAst: {\n  <T>(annotation: Annotation<T>): (ast: SchemaAST.AST) => Option.Option<T>;\n  <T>(ast: SchemaAST.AST, annotation: Annotation<T>): Option.Option<T>;\n} = Function.dual<\n  <T>(annotation: Annotation<T>) => (ast: SchemaAST.AST) => Option.Option<T>,\n  <T>(ast: SchemaAST.AST, annotation: Annotation<T>) => Option.Option<T>\n>(2, (ast, annotation) => {\n  return internalAnnotations.getFromAst(ast, annotation);\n});\n\n/**\n * Set of annotation values.\n *\n * Can be used inside an object/relation schema:\n *\n * ```ts\n * const Person = Schema.Struct({\n *   name: Schema.String,\n *   extensions: Annotation.Dictionary,\n * });\n * ```\n */\nexport const Dictionary = internalAnnotations.Dictionary;\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a Dictionary.\n */\nexport const getDictionary: {\n  <T>(annotation: Annotation<T>): (values: Dictionary) => Option.Option<T>;\n  <T>(values: Dictionary, annotation: Annotation<T>): Option.Option<T>;\n} = Function.dual<\n  <T>(annotation: Annotation<T>) => (values: Dictionary) => Option.Option<T>,\n  <T>(values: Dictionary, annotation: Annotation<T>) => Option.Option<T>\n>(2, (values, annotation) => {\n  return internalAnnotations.getDictionary(values, annotation);\n});\n\n/**\n * Set the value of an annotation in a Dictionary.\n *\n * Can also be used within Obj.update callback:\n *\n * ```ts\n * Obj.update(obj, (obj) => {\n *   Annotation.setDictionary(obj.annotations, ColorAnnotation, 'red');\n * });\n * ```\n */\nexport const setDictionary: {\n  <T>(annotation: Annotation<T>, value: T): (values: Dictionary) => void;\n  <T>(values: Types.Mutable<Dictionary>, annotation: Annotation<T>, value: T): void;\n} = Function.dual<\n  <T>(annotation: Annotation<T>, value: T) => (values: Dictionary) => void,\n  <T>(values: Types.Mutable<Dictionary>, annotation: Annotation<T>, value: T) => void\n>(3, (values, annotation, value) => {\n  return internalAnnotations.setDictionary(values, annotation, value);\n});\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;oBAAAA;EAAA;;;;;;;;aAAAC;EAAA;;;;;aAAAC;EAAA;uBAAAC;EAAA,kBAAAC;EAAA;;;;aAAAC;EAAA;uBAAAC;EAAA;;AA8BA,YAAYC,cAAc;AASnB,IAAMC,SAAS;AAkDf,IAAMC,OAA0BA;AAuBhC,IAAMC,OAAsEC;AAO5E,IAAMC,OAGAC,cAGX,GAAG,CAACC,QAAQC,eAAAA;AACZ,SAA2BH,IAAIE,QAAQC,UAAAA;AACzC,CAAA;AAOO,IAAMC,OAGAH,cAGX,GAAG,CAACC,QAAQC,YAAYE,UAAAA;AACxB,SAA2BD,IAAIF,QAAQC,YAAYE,KAAAA;AACrD,CAAA;AAEO,IAAMC,cAGAL,cAGX,GAAG,CAACM,KAAKJ,eAAAA;AACT,SAA2BG,WAAWC,KAAKJ,UAAAA;AAC7C,CAAA;AAcO,IAAMK,cAAiCA;AAMvC,IAAMC,iBAGAR,cAGX,GAAG,CAACS,QAAQP,eAAAA;AACZ,SAA2BM,cAAcC,QAAQP,UAAAA;AACnD,CAAA;AAaO,IAAMQ,iBAGAV,cAGX,GAAG,CAACS,QAAQP,YAAYE,UAAAA;AACxB,SAA2BM,cAAcD,QAAQP,YAAYE,KAAAA;AAC/D,CAAA;",
  "names": ["Dictionary", "Key", "get", "getDictionary", "getFromAst", "set", "setDictionary", "Function", "TypeId", "Key", "make", "makeUserAnnotation", "get", "dual", "target", "annotation", "set", "value", "getFromAst", "ast", "Dictionary", "getDictionary", "values", "setDictionary"]
}
