{
  "version": 3,
  "sources": ["../../../src/internal/JsonSchema/annotations.ts", "../../../src/internal/JsonSchema/json-schema-type.ts", "../../../src/internal/JsonSchema/json-schema.ts"],
  "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { GeneratorAnnotationId, LabelAnnotationId, PropertyMetaAnnotationId } from '../Annotation/annotations';\nimport { CurrencyAnnotationId, FormatAnnotationId } from '../Format';\nimport { type JsonSchemaEchoAnnotations, type JsonSchemaType } from '../JsonSchema';\n\n//\n// This file configures annotations for JSON encoding/decoding.\n//\n\n// Go on the root level.\ntype RootJsonSchemaProperty = keyof JsonSchemaType;\n\n// Go on the namespaced `annotations` property.\ntype NamespacedJsonSchemaProperty = keyof JsonSchemaEchoAnnotations;\n\n/**\n * List of annotations for JSON encoding/decoding.\n * Omits default effect-schema annotations since they are encoded with default serializer.\n */\n// TODO(burdon): Reconcile with `EchoAnnotations`.\nexport const CustomAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {\n  format: FormatAnnotationId,\n  currency: CurrencyAnnotationId,\n};\n\n/**\n * List of annotations for JSON decoding only.\n * Includes default effect annotations.\n */\nexport const DecodedAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {\n  title: SchemaAST.TitleAnnotationId,\n  description: SchemaAST.DescriptionAnnotationId,\n};\n\n/**\n * Annotations that go into ECHO namespace in json-schema.\n */\n// TODO(dmaretskyi): Consider removing ECHO namespace and putting them at the top level.\n// TODO(dmaretskyi): Move to format.ts when circular imports are solved\nexport const EchoAnnotations: Partial<Record<NamespacedJsonSchemaProperty, symbol>> = {\n  // TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.\n  meta: PropertyMetaAnnotationId,\n  generator: GeneratorAnnotationId,\n  labelProp: LabelAnnotationId,\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { SchemaEx } from '@dxos/effect';\n\nimport { type Mutable } from '../common/proxy';\nimport { EntityKindSchema } from '../common/types';\nimport { FormatAnnotation, TypeFormat } from '../Format';\n\n//\n// JSON Schema\n//\n\n// TODO(burdon): Reuse/reconcile with ScalarTypeEnum (handle arrays).\nconst SimpleTypes = Schema.Literal('array', 'boolean', 'integer', 'null', 'number', 'object', 'string');\n\nconst NonNegativeInteger = Schema.Number.pipe(Schema.greaterThanOrEqualTo(0));\n\nconst StringArray = Schema.Array(Schema.String);\n\nconst JsonSchemaOrBoolean = Schema.Union(\n  Schema.suspend(() => JsonSchemaType),\n  Schema.Boolean,\n);\n\n/**\n * Go under the `annotations` property.\n */\nexport const JsonSchemaEchoAnnotations = Schema.Struct({\n  /**\n   * Label for this schema.\n   * Mapped from {@link LabelAnnotationId}.\n   */\n  labelProp: Schema.optional(Schema.Union(SchemaEx.JsonPath, Schema.Array(SchemaEx.JsonPath))),\n\n  /**\n   * Generator function for this schema.\n   * Mapped from {@link GeneratorAnnotationId}.\n   */\n  generator: Schema.optional(Schema.Union(Schema.String, Schema.Tuple(Schema.String, Schema.Number))),\n\n  /**\n   * {@link PropertyMeta} annotations get serialized here.\n   */\n  meta: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.Any,\n    }),\n  ),\n\n  /**\n   * @deprecated\n   */\n  // TODO(dmaretskyi): We risk old schema not passing validation due to the extra fields. Remove when we are sure this is safe.\n  type: Schema.optional(\n    Schema.Struct({\n      typename: Schema.String,\n      version: Schema.String,\n\n      // Not used.\n      schemaId: Schema.optional(Schema.String),\n    }),\n  ),\n\n  /**\n   * @deprecated Superseded by `meta`.\n   */\n  annotations: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.Any,\n    }),\n  ),\n});\nexport type JsonSchemaEchoAnnotations = Schema.Schema.Type<typeof JsonSchemaEchoAnnotations>;\n\n/**\n * Describes a schema for the JSON-schema objects stored in ECHO.\n * Contains extensions for ECHO (e.g., references).\n * Ref: https://json-schema.org/draft-07/schema\n */\n// TODO(burdon): Integrate with Effect Serializable?\n// TODO(dmaretskyi): Update to latest draft: https://json-schema.org/draft/2020-12\nconst _JsonSchemaType = Schema.Struct({\n  /**\n   * Identifier for this schema.\n   * This schema might be referenced by $ref clause in other schemas.\n   */\n  // TODO(dmaretskyi): Specify how the ids are generated.\n  // TODO(dmaretskyi): For type dxns, should this include the version?\n  $id: Schema.optional(Schema.String),\n\n  /**\n   * Schema of this schema.\n   * Set to \"https://json-schema.org/draft-07/schema\".\n   */\n  $schema: Schema.optional(Schema.String),\n\n  /**\n   * Reference to another schema.\n   */\n  $ref: Schema.optional(Schema.String),\n\n  /**\n   * Comments are ignored when interpreting the schema.\n   */\n  $comment: Schema.optional(Schema.String),\n\n  /**\n   * Defines whether this schema is an object schema or a relation schema.\n   */\n  entityKind: Schema.optional(EntityKindSchema),\n\n  /**\n   * Typename of this schema.\n   * Only on schema representing an ECHO object.\n   *\n   * @example 'com.example.type.my-type'\n   */\n  typename: Schema.optional(Schema.String),\n\n  /**\n   * Version of this schema.\n   * Custom dialect for ECHO.\n   */\n  version: Schema.optional(Schema.String),\n\n  /**\n   * Target of this relation.\n   * Only for relation schemas.\n   * The referenced schema must be an object schema.\n   */\n  relationTarget: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n  /**\n   * Source of this relation.\n   * Only for relation schemas.\n   * The referenced schema must be an object schema.\n   */\n  relationSource: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n  /**\n   * Title of this schema.\n   */\n  title: Schema.optional(Schema.String),\n\n  /**\n   * Description of this schema.\n   */\n  description: Schema.optional(Schema.String),\n\n  /**\n   * Whether this schema is read-only.\n   */\n  readOnly: Schema.optional(Schema.Boolean),\n\n  /**\n   * Whether this schema is write-only.\n   */\n  writeOnly: Schema.optional(Schema.Boolean),\n\n  /**\n   * Examples of instances of this schema.\n   */\n  examples: Schema.optional(Schema.Array(Schema.Any)),\n\n  /**\n   * Default value for this schema.\n   */\n  default: Schema.optional(Schema.Any),\n\n  /**\n   * This schema only matches values that are equal to this value.\n   */\n  const: Schema.optional(Schema.Any),\n\n  /**\n   * This schema only matches one of the values in this array.\n   */\n  enum: Schema.optional(Schema.Array(Schema.Any)),\n\n  /**\n   * Base type of the schema.\n   */\n  type: Schema.optional(Schema.Union(SimpleTypes, Schema.Array(SimpleTypes))),\n\n  //\n  // Numbers.\n  //\n\n  multipleOf: Schema.optional(Schema.Number.pipe(Schema.greaterThan(0))),\n  maximum: Schema.optional(Schema.Number),\n  exclusiveMaximum: Schema.optional(Schema.Number),\n  minimum: Schema.optional(Schema.Number),\n  exclusiveMinimum: Schema.optional(Schema.Number),\n\n  //\n  // Strings.\n  //\n\n  maxLength: Schema.optional(NonNegativeInteger),\n\n  /**\n   * Regex pattern for strings.\n   */\n  pattern: Schema.optional(Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex))),\n\n  /**\n   * Serialized from {@link FormatAnnotationId}.\n   */\n  format: Schema.optional(Schema.String),\n\n  //\n  // Arrays\n  //\n\n  minLength: Schema.optional(NonNegativeInteger),\n  items: Schema.optional(\n    Schema.Union(\n      Schema.suspend(() => JsonSchemaType),\n      Schema.Array(Schema.suspend(() => JsonSchemaType)),\n    ),\n  ),\n  additionalItems: Schema.optional(\n    Schema.Union(\n      Schema.suspend(() => JsonSchemaType),\n      Schema.Boolean,\n    ),\n  ),\n  maxItems: Schema.optional(NonNegativeInteger),\n  minItems: Schema.optional(NonNegativeInteger),\n  uniqueItems: Schema.optional(Schema.Boolean),\n  contains: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n  //\n  // Objects\n  //\n\n  maxProperties: Schema.optional(NonNegativeInteger),\n  minProperties: Schema.optional(NonNegativeInteger),\n  required: Schema.optional(StringArray),\n\n  /**\n   * Non-standard JSON Schema extension.\n   * Defines the order of properties in the object.\n   * The unmentioned properties are placed at the end.\n   *\n   * Related: https://github.com/json-schema/json-schema/issues/119\n   */\n  propertyOrder: Schema.optional(StringArray),\n\n  additionalProperties: Schema.optional(JsonSchemaOrBoolean),\n  properties: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.suspend(() => JsonSchemaType),\n    }),\n  ),\n  patternProperties: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.suspend(() => JsonSchemaType),\n    }),\n  ),\n  propertyNames: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n  definitions: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.suspend(() => JsonSchemaType),\n    }),\n  ),\n  dependencies: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.suspend(() => Schema.Union(Schema.String, StringArray, JsonSchemaType)).annotations({\n        identifier: 'dependency',\n        description: 'Dependency',\n      }),\n    }),\n  ),\n\n  contentMediaType: Schema.optional(Schema.String),\n  contentEncoding: Schema.optional(Schema.String),\n\n  if: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n  then: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n  else: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n  allOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n  anyOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n  oneOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n  not: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n  $defs: Schema.optional(\n    Schema.Record({\n      key: Schema.String,\n      value: Schema.suspend(() => JsonSchemaType),\n    }),\n  ),\n\n  //\n  // ECHO extensions.\n  //\n\n  currency: Schema.optional(Schema.String),\n\n  reference: Schema.optional(\n    Schema.Struct({\n      schema: Schema.suspend(() => JsonSchemaType),\n      schemaVersion: Schema.optional(Schema.String),\n      schemaObject: Schema.optional(Schema.String),\n    }),\n  ),\n\n  /**\n   * ECHO-specific annotations.\n   */\n  // TODO(dmaretskyi): Since we are adding a lot of new extensions to the JSON Schema, it is safer to namespace them here.\n  annotations: Schema.optional(JsonSchemaEchoAnnotations),\n\n  /**\n   * @deprecated Use `annotations` instead.\n   */\n  echo: Schema.optional(JsonSchemaEchoAnnotations),\n}).annotations({ identifier: 'jsonSchema', description: 'JSON Schema' });\n\nexport const JsonSchemaFields = Object.keys(_JsonSchemaType.fields);\n\n/**\n * https://json-schema.org/draft-07/schema\n */\n// TODO(burdon): Reconcile with @effect/Schema/JSONSchema\nexport interface JsonSchemaType extends Schema.Schema.Type<typeof _JsonSchemaType> {}\n\nexport const JsonSchemaType: Schema.Schema<JsonSchemaType> = _JsonSchemaType;\n\n// TODO(burdon): Factor out JSON schema utils.\n\nexport const getSchemaProperty = (schema: JsonSchemaType, property: SchemaEx.JsonProp): JsonSchemaType | undefined => {\n  return schema.properties?.[property];\n};\n\n// TODO(burdon): Properties should be ordered.\nexport const setSchemaProperty = (\n  schema: Mutable<JsonSchemaType>,\n  property: SchemaEx.JsonProp,\n  value: Mutable<JsonSchemaType>,\n) => {\n  schema.properties ??= {};\n  schema.properties[property] = value;\n  return schema;\n};\n\n/**\n * @internal\n */\nexport const ECHO_ANNOTATIONS_NS_DEPRECATED_KEY: keyof JsonSchemaType = 'echo';\n\n/**\n * @internal\n */\nexport const ECHO_ANNOTATIONS_NS_KEY = 'annotations';\n\n/**\n * @internal\n * @returns ECHO annotations namespace object in its normalized form.\n *\n * `meta` holds PropertyMeta annotations.\n * `annotations` holds other annotations.\n */\nexport const getNormalizedEchoAnnotations = (obj: JsonSchemaType): JsonSchemaEchoAnnotations | undefined => {\n  if (obj[ECHO_ANNOTATIONS_NS_KEY] != null && obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {\n    return normalizeEchoAnnotations({\n      ...obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY],\n      ...obj[ECHO_ANNOTATIONS_NS_KEY],\n    });\n  } else if (obj[ECHO_ANNOTATIONS_NS_KEY] != null) {\n    return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_KEY]!);\n  } else if (obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {\n    return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY]!);\n  } else {\n    return undefined;\n  }\n};\n\nconst normalizeEchoAnnotations = (obj: JsonSchemaEchoAnnotations): JsonSchemaEchoAnnotations => {\n  if (!obj.annotations) {\n    return obj;\n  } else {\n    const res = {\n      ...obj,\n      meta: {\n        ...obj.annotations,\n        ...(obj.meta ?? {}),\n      },\n    };\n    delete res.annotations;\n    return res;\n  }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Array from 'effect/Array';\nimport * as Function from 'effect/Function';\nimport * as JSONSchema from 'effect/JSONSchema';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport type * as Types from 'effect/Types';\n\nimport { raise } from '@dxos/debug';\nimport { SchemaEx } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, EntityId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { clearUndefined, orderKeys, removeProperties } from '@dxos/util';\n\nimport type * as Type from '../../Type';\nimport { type TypeAnnotation, TypeAnnotationId, TypeIdentifierAnnotationId } from '../Annotation/annotations';\nimport { makeTypeJsonSchemaAnnotation } from '../Annotation/util';\nimport {\n  ANY_OBJECT_TYPENAME,\n  ANY_OBJECT_VERSION,\n  EntityKind,\n  EntityKindSchema,\n  getStaticTypeSchema,\n} from '../common/types';\nimport { type JsonSchemaReferenceInfo, createEchoReferenceSchema } from '../Ref';\nimport { CustomAnnotations, DecodedAnnotations, EchoAnnotations } from './annotations';\nimport {\n  ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,\n  ECHO_ANNOTATIONS_NS_KEY,\n  type JsonSchemaEchoAnnotations,\n  type JsonSchemaType,\n  getNormalizedEchoAnnotations,\n} from './json-schema-type';\n\n// TODO(burdon): Are these values stored (can they be changed?)\nexport enum PropType {\n  NONE = 0,\n  STRING = 1, // TODO(burdon): vs TEXT?\n  NUMBER = 2,\n  BOOLEAN = 3,\n  DATE = 4,\n  REF = 5,\n  RECORD = 6,\n  ENUM = 7,\n}\n\n// TODO(burdon): Reconcile with @dxos/schema.\nexport const toPropType = (type?: PropType): string => {\n  switch (type) {\n    case PropType.STRING:\n      return 'string';\n    case PropType.NUMBER:\n      return 'number';\n    case PropType.BOOLEAN:\n      return 'boolean';\n    case PropType.DATE:\n      return 'date';\n    case PropType.REF:\n      return 'ref';\n    case PropType.RECORD:\n      return 'object';\n    default:\n      throw new Error(`Invalid type: ${type}`);\n  }\n};\n\nconst JSON_SCHEMA_URL = 'http://json-schema.org/draft-07/schema#';\n\nexport type JsonSchemaOptions = {\n  strict?: boolean;\n};\n\n/**\n * Convert effect schema to JSON Schema.\n * NOTE: This handles custom annotations.\n * @param schema\n */\n// TODO(burdon): Reconcile with possibly extending @effect/Schema/JSONSchema\n//  We add additional propertyOrder (but the object properties ARE ordered); and type \"string\" for literals.\n// TODO(wittjosiah): This is mutable because its a pojo, perhaps should be left as readonly at type level though?\nexport const toJsonSchema = (\n  schema: Schema.Schema.All | Type.AnyEntity,\n  options: JsonSchemaOptions = {},\n): Types.DeepMutable<JsonSchemaType> => {\n  // Allow passing a `Type.Type` entity — use its hidden source schema (or its\n  // already-built jsonSchema as a fallback).\n  const slot = getStaticTypeSchema(schema);\n  if (slot != null) {\n    schema = slot;\n  } else if (!Schema.isSchema(schema)) {\n    const entityJsonSchema = (schema as { jsonSchema?: JsonSchemaType }).jsonSchema;\n    if (entityJsonSchema != null) {\n      return entityJsonSchema as Types.DeepMutable<JsonSchemaType>;\n    }\n  }\n  assertArgument(Schema.isSchema(schema), 'schema');\n  let jsonSchema = _toJsonSchemaAST((schema as Schema.Schema.All).ast);\n  if (options.strict) {\n    // TOOD(burdon): Workaround to ensure JSON schema is valid (for agv parsing).\n    jsonSchema = removeProperties(jsonSchema, (key, value) => {\n      if (key === '$id' && value === '/schemas/any') {\n        return true;\n      }\n      if (key === '$ref' && value === '#/$defs/dependency') {\n        return true;\n      }\n      if (key === '$ref' && value === '#/$defs/jsonSchema') {\n        return true;\n      }\n\n      return false;\n    });\n  }\n\n  return jsonSchema;\n};\n\nconst _toJsonSchemaAST = (ast: SchemaAST.AST): Types.DeepMutable<JsonSchemaType> => {\n  const withRefinements = withEchoRefinements(ast, '#');\n  const jsonSchema = JSONSchema.fromAST(withRefinements, {\n    definitions: {},\n  }) as Types.DeepMutable<JsonSchemaType>;\n\n  return normalizeJsonSchema(jsonSchema);\n};\n\nconst withEchoRefinements = (\n  ast: SchemaAST.AST,\n  path: string | undefined,\n  suspendCache = new Map<SchemaAST.AST, string>(),\n): SchemaAST.AST => {\n  if (path) {\n    suspendCache.set(ast, path);\n  }\n\n  let recursiveResult: SchemaAST.AST;\n  if (SchemaAST.isSuspend(ast)) {\n    // Precompute JSON schema for suspended AST since effect serializer does not support it.\n    const suspendedAst = ast.f();\n    const cachedPath = suspendCache.get(suspendedAst);\n    if (cachedPath) {\n      recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {\n        [SchemaAST.JSONSchemaAnnotationId]: {\n          $ref: cachedPath,\n        },\n      });\n    } else {\n      const jsonSchema = _toJsonSchemaAST(suspendedAst);\n      recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {\n        [SchemaAST.JSONSchemaAnnotationId]: jsonSchema,\n      });\n    }\n  } else if (SchemaAST.isTypeLiteral(ast)) {\n    // Add property order annotations\n    recursiveResult = SchemaEx.mapAst(ast, (ast, key) =>\n      withEchoRefinements(ast, path && typeof key === 'string' ? `${path}/${key}` : undefined, suspendCache),\n    );\n    recursiveResult = addJsonSchemaFields(recursiveResult, {\n      propertyOrder: [...ast.propertySignatures.map((p) => p.name)] as string[],\n    });\n  } else if (SchemaAST.isUndefinedKeyword(ast)) {\n    // Ignore undefined keyword that appears in the optional fields.\n    return ast;\n  } else {\n    recursiveResult = SchemaEx.mapAst(ast, (ast, key) =>\n      withEchoRefinements(\n        ast,\n        path && (typeof key === 'string' || typeof key === 'number') ? `${path}/${key}` : undefined,\n        suspendCache,\n      ),\n    );\n  }\n\n  const annotationFields = annotations_toJsonSchemaFields(ast.annotations);\n  if (Object.keys(annotationFields).length === 0) {\n    return recursiveResult;\n  } else {\n    return addJsonSchemaFields(recursiveResult, annotationFields);\n  }\n};\n\n/**\n * Convert JSON schema to effect schema.\n * @param root\n * @param definitions\n */\nexport const toEffectSchema = (root: JsonSchemaType, _defs?: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {\n  const defs = root.$defs ? { ..._defs, ...root.$defs } : (_defs ?? {});\n  if ('type' in root && root.type === 'object') {\n    return objectToEffectSchema(root, defs);\n  }\n\n  let result: Schema.Schema.AnyNoContext = Schema.Unknown;\n  if ('$ref' in root) {\n    switch (root.$ref) {\n      case '/schemas/echo/ref': {\n        result = refToEffectSchema(root);\n        break;\n      }\n    }\n  } else if ('$id' in root) {\n    switch (decodeURIComponent(root.$id as string)) {\n      case '/schemas/any': {\n        result = anyToEffectSchema(root as JSONSchema.JsonSchema7Any);\n        break;\n      }\n      case '/schemas/unknown': {\n        result = Schema.Unknown;\n        break;\n      }\n      case '/schemas/{}':\n      case '/schemas/object': {\n        result = Schema.Struct({});\n        break;\n      }\n      // Custom ECHO object reference.\n      case '/schemas/echo/ref': {\n        result = refToEffectSchema(root);\n        break;\n      }\n    }\n  } else if ('enum' in root) {\n    result = Schema.Union(...root.enum!.map((e) => Schema.Literal(e)));\n  } else if ('oneOf' in root) {\n    result = Schema.Union(...root.oneOf!.map((v) => toEffectSchema(v, defs)));\n  } else if ('anyOf' in root) {\n    result = Schema.Union(...root.anyOf!.map((v) => toEffectSchema(v, defs)));\n  } else if ('allOf' in root) {\n    if (root.allOf!.length === 1) {\n      result = toEffectSchema(root.allOf![0], defs);\n    } else {\n      log.warn('allOf with multiple schemas is not supported');\n      result = Schema.Unknown;\n    }\n  } else if ('type' in root) {\n    switch (root.type) {\n      case 'string': {\n        result = Schema.String;\n        if (root.pattern) {\n          result = result.pipe(Schema.pattern(new RegExp(root.pattern)));\n        }\n        break;\n      }\n      case 'number': {\n        result = Schema.Number;\n        break;\n      }\n      case 'integer': {\n        result = Schema.Number.pipe(Schema.int());\n        break;\n      }\n      case 'boolean': {\n        result = Schema.Boolean;\n        break;\n      }\n      case 'array': {\n        if (Array.isArray(root.items)) {\n          const [required, optional] = Function.pipe(\n            root.items,\n            Array.map((v) => toEffectSchema(v as JsonSchemaType, defs)),\n            Array.splitAt(root.minItems ?? root.items.length),\n          );\n          result = Schema.Tuple(...required, ...optional.map(Schema.optionalElement));\n        } else {\n          invariant(root.items);\n          const items = root.items;\n          result = Array.isArray(items)\n            ? Schema.Tuple(...items.map((v) => toEffectSchema(v as JsonSchemaType, defs)))\n            : Schema.Array(toEffectSchema(items as JsonSchemaType, defs));\n        }\n        break;\n      }\n      case 'null': {\n        result = Schema.Null;\n        break;\n      }\n    }\n  } else if ('$ref' in root) {\n    const refSegments = root.$ref!.split('/');\n    const jsonSchema = defs[refSegments[refSegments.length - 1]];\n    invariant(jsonSchema, `missing definition for ${root.$ref}`);\n    result = toEffectSchema(jsonSchema, defs).pipe(\n      Schema.annotations({ identifier: refSegments[refSegments.length - 1] }),\n    );\n  }\n\n  const annotations = jsonSchemaFieldsToAnnotations(root);\n\n  // log.info('toEffectSchema', { root, annotations });\n  result = result.annotations(annotations);\n\n  return result;\n};\n\nconst objectToEffectSchema = (root: JsonSchemaType, defs: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {\n  invariant('type' in root && root.type === 'object', `not an object: ${root}`);\n\n  const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];\n  const isEchoObject =\n    echoRefinement != null || ('$id' in root && typeof root.$id === 'string' && root.$id.startsWith('dxn:'));\n\n  let fields: Schema.Struct.Fields = {};\n  const propertyList = Object.entries(root.properties ?? {});\n  let immutableIdField: Schema.Schema.AnyNoContext | undefined;\n  for (const [key, value] of propertyList) {\n    if (isEchoObject && key === 'id') {\n      immutableIdField = toEffectSchema(value, defs);\n    } else {\n      // TODO(burdon): Mutable cast.\n      (fields as any)[key] = root.required?.includes(key)\n        ? toEffectSchema(value, defs)\n        : Schema.optional(toEffectSchema(value, defs));\n    }\n  }\n\n  if (root.propertyOrder) {\n    fields = orderKeys(fields, root.propertyOrder as any);\n  }\n\n  let schema: Schema.Schema<any, any, unknown>;\n  if (root.patternProperties) {\n    invariant(propertyList.length === 0, 'pattern properties mixed with regular properties are not supported');\n    invariant(\n      Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === '',\n      'only one pattern property is supported',\n    );\n\n    schema = Schema.Record({ key: Schema.String, value: toEffectSchema(root.patternProperties[''], defs) });\n  } else if (typeof root.additionalProperties !== 'object') {\n    schema = Schema.Struct(fields);\n  } else {\n    const indexValue = toEffectSchema(root.additionalProperties, defs);\n    if (propertyList.length > 0) {\n      schema = Schema.Struct(fields, { key: Schema.String, value: indexValue });\n    } else {\n      schema = Schema.Record({ key: Schema.String, value: indexValue });\n    }\n  }\n\n  if (immutableIdField) {\n    schema = Schema.extend(schema, Schema.Struct({ id: immutableIdField }));\n  }\n\n  const annotations = jsonSchemaFieldsToAnnotations(root);\n  return schema.annotations(annotations) as any;\n};\n\nconst anyToEffectSchema = (root: JSONSchema.JsonSchema7Any): Schema.Schema.AnyNoContext => {\n  const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];\n  // TODO(dmaretskyi): Is this branch still taken?\n  if ((echoRefinement as any)?.reference != null) {\n    const echoUri = root.$id.startsWith('echo:') ? root.$id : undefined;\n    return createEchoReferenceSchema(\n      echoUri,\n      (echoRefinement as any).reference.typename,\n      (echoRefinement as any).reference.version,\n    );\n  }\n\n  return Schema.Any;\n};\n\n// TODO(dmaretskyi): Types.\nconst refToEffectSchema = (root: any): Schema.Schema.AnyNoContext => {\n  if (!('reference' in root)) {\n    // Fallback to generic object ref when no reference info is provided.\n    return createEchoReferenceSchema(undefined, ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION);\n  }\n\n  const reference: JsonSchemaReferenceInfo = root.reference;\n  if (typeof reference !== 'object') {\n    throw new Error('Invalid reference field in ref schema');\n  }\n\n  const ref = reference.schema.$ref;\n  const targetSchemaDXN = DXN.tryMake(ref);\n  invariant(targetSchemaDXN, `Expected a type DXN, got: ${ref}`);\n\n  return createEchoReferenceSchema(ref, DXN.getName(targetSchemaDXN), reference.schemaVersion);\n};\n\n//\n// Annotations\n//\n\nconst annotations_toJsonSchemaFields = (annotations: SchemaAST.Annotations): Record<symbol, any> => {\n  const schemaFields: Record<string, any> = {};\n\n  const echoAnnotations: Types.Mutable<JsonSchemaEchoAnnotations> = {};\n  for (const [key, annotationId] of Object.entries(EchoAnnotations)) {\n    if (annotations[annotationId] != null) {\n      echoAnnotations[key as keyof JsonSchemaEchoAnnotations] = annotations[annotationId] as any;\n    }\n  }\n  if (Object.keys(echoAnnotations).length > 0) {\n    // TODO(dmaretskyi): use new namespace.\n    schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;\n  }\n\n  // For stored schemas the storage URI is the definitive identifier — it overrides\n  // the typename `$id` written above.\n  const echoIdentifier = annotations[TypeIdentifierAnnotationId];\n  if (echoIdentifier) {\n    schemaFields.$id = echoIdentifier;\n  }\n\n  // Custom (at end).\n  for (const [key, annotationId] of Object.entries(CustomAnnotations)) {\n    const value = annotations[annotationId];\n    if (value != null) {\n      schemaFields[key] = value;\n    }\n  }\n\n  return schemaFields;\n};\n\nconst decodeTypeIdentifierAnnotation = (schema: JsonSchemaType): string | undefined => {\n  // For stored schemas `$id` IS the storage URI (echo:/<id>).\n  if (schema.$id && schema.$id.startsWith('echo:')) {\n    return schema.$id;\n  }\n  // Older serializations stored the EID on echo.type.schemaId.\n  const legacySchemaId = schema.echo?.type?.schemaId;\n  if (legacySchemaId) {\n    return EntityId.isValid(legacySchemaId) ? EID.make({ entityId: legacySchemaId }) : legacySchemaId;\n  }\n  return undefined;\n};\n\nconst decodeTypeAnnotation = (schema: JsonSchemaType): TypeAnnotation | undefined => {\n  if (schema.typename) {\n    const annotation: Types.Mutable<TypeAnnotation> = {\n      // TODO(dmaretskyi): Decoding default.\n      kind: schema.entityKind ? Schema.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,\n      typename: schema.typename,\n      version: schema.version ?? '0.1.0',\n    };\n\n    if (annotation.kind === EntityKind.Relation) {\n      const source = schema.relationSource?.$ref ?? raise(new Error('Relation source not set'));\n      const target = schema.relationTarget?.$ref ?? raise(new Error('Relation target not set'));\n      annotation.sourceSchema = DXN.tryMake(source) ?? raise(new Error(`Invalid relation source: ${source}`));\n      annotation.targetSchema = DXN.tryMake(target) ?? raise(new Error(`Invalid relation target: ${target}`));\n    }\n\n    return annotation;\n  }\n\n  // Decode legacy schema.\n  if (!schema.typename && schema?.echo?.type) {\n    return {\n      kind: EntityKind.Object,\n      typename: schema.echo.type.typename,\n      version: schema.echo.type.version,\n    };\n  }\n\n  return undefined;\n};\n\nconst jsonSchemaFieldsToAnnotations = (schema: JsonSchemaType): SchemaAST.Annotations => {\n  const annotations: Types.Mutable<Schema.Annotations.Schema<any>> = {};\n\n  const echoAnnotations: JsonSchemaEchoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};\n  if (echoAnnotations) {\n    for (const [key, annotationId] of Object.entries(EchoAnnotations)) {\n      if (echoAnnotations[key as keyof JsonSchemaEchoAnnotations]) {\n        annotations[annotationId] = echoAnnotations[key as keyof JsonSchemaEchoAnnotations];\n      }\n    }\n  }\n\n  const typeIdentifier = decodeTypeIdentifierAnnotation(schema);\n  annotations[TypeIdentifierAnnotationId] = typeIdentifier;\n  const typeAnnotation = decodeTypeAnnotation(schema);\n  if (typeAnnotation) {\n    annotations[TypeAnnotationId] = typeAnnotation;\n    annotations[SchemaAST.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({\n      // $id is the typename DXN — the schema's type identity. The storage EID (if any)\n      // is preserved separately on TypeIdentifierAnnotation / echo.schemaId.\n      identifier: DXN.make(typeAnnotation.typename, typeAnnotation.version),\n      kind: typeAnnotation.kind,\n      typename: typeAnnotation.typename,\n      version: typeAnnotation.version,\n      relationSource: typeAnnotation.sourceSchema,\n      relationTarget: typeAnnotation.targetSchema,\n    });\n  }\n\n  // Custom (at end).\n  for (const [key, annotationId] of Object.entries({ ...CustomAnnotations, ...DecodedAnnotations })) {\n    if (key in schema) {\n      annotations[annotationId] = (schema as any)[key];\n    }\n  }\n\n  return clearUndefined(annotations);\n};\n\nconst makeAnnotatedRefinement = (ast: SchemaAST.AST, annotations: SchemaAST.Annotations): SchemaAST.Refinement => {\n  return new SchemaAST.Refinement(ast, () => Option.none(), annotations);\n};\n\nconst addJsonSchemaFields = (ast: SchemaAST.AST, schema: JsonSchemaType): SchemaAST.AST =>\n  makeAnnotatedRefinement(ast, { [SchemaAST.JSONSchemaAnnotationId]: schema });\n\n/**\n * Fixes field order.\n * Sets `$schema` prop.\n */\nconst normalizeJsonSchema = (jsonSchema: Types.DeepMutable<JsonSchemaType>): Types.DeepMutable<JsonSchemaType> => {\n  if (jsonSchema.properties && 'id' in jsonSchema.properties) {\n    jsonSchema.properties = orderKeys(jsonSchema.properties, ['id']); // Put id first.\n  }\n\n  // TODO(dmaretskyi): Makes sure undefined is not left on optional fields for the resulting object.\n  jsonSchema.$schema = JSON_SCHEMA_URL;\n  jsonSchema = orderKeys(jsonSchema, [\n    '$schema',\n    '$id',\n\n    'entityKind',\n    'typename',\n    'version',\n    'relationTarget',\n    'relationSource',\n\n    'type',\n    'enum',\n\n    'properties',\n    'required',\n    'propertyOrder', // Custom.\n    'items',\n    'additionalProperties',\n\n    'anyOf',\n    'oneOf',\n  ]);\n  return jsonSchema;\n};\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,YAAYA,eAAe;AAqBpB,IAAMC,oBAAqE;EAChFC,QAAQC;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A,CAAA,KAAAoC,iBAAA;AAEA,SAAMtB,IAAAA,sBAA2C3B,KAAAA,MAC/CyG,YAAAA,GAAAA,YAAwB5F;;IAAkD,sBAAA,CAAA,KAAA,WAAA,wBAAA,KAAA;EAE5E,CAAA,iCAAA,GAAA;;IAMIR,sBAAwBqG,CAAAA,eAAUrG;iBAAwB,cAAA,QAAA,WAAA,YAAA;eAAQ,aAAgB,UAAA,WAAA,YAAA;MACpF;IAEA,CAAA;EACAA;aAEE,UAAA;eACA,UAAA,YAAA;IAEA;IACA;IACA;IACA;IACA;IAEA;IACA;IAEA;IACA;IACA;IACA;IACA;IAEA;IACA;IACD;IACD;EACF,CAAA;;;",
  "names": ["SchemaAST", "CustomAnnotations", "format", "FormatAnnotationId", "currency", "CurrencyAnnotationId", "DecodedAnnotations", "title", "TitleAnnotationId", "description", "DescriptionAnnotationId", "EchoAnnotations", "meta", "PropertyMetaAnnotationId", "generator", "GeneratorAnnotationId", "labelProp", "LabelAnnotationId", "Schema", "SchemaEx", "SimpleTypes", "Literal", "NonNegativeInteger", "Number", "pipe", "greaterThanOrEqualTo", "StringArray", "Array", "String", "JsonSchemaOrBoolean", "Union", "suspend", "JsonSchemaType", "Boolean", "JsonSchemaEchoAnnotations", "Struct", "labelProp", "optional", "SchemaEx", "JsonPath", "generator", "Tuple", "meta", "Record", "key", "value", "Any", "type", "typename", "version", "schemaId", "annotations", "_JsonSchemaType", "$id", "$schema", "$ref", "$comment", "entityKind", "EntityKindSchema", "relationTarget", "relationSource", "title", "description", "readOnly", "writeOnly", "examples", "default", "const", "enum", "multipleOf", "greaterThan", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "pattern", "FormatAnnotation", "set", "TypeFormat", "Regex", "format", "minLength", "items", "additionalItems", "maxItems", "minItems", "uniqueItems", "contains", "maxProperties", "minProperties", "required", "propertyOrder", "additionalProperties", "properties", "patternProperties", "propertyNames", "definitions", "dependencies", "identifier", "contentMediaType", "contentEncoding", "if", "then", "else", "allOf", "anyOf", "oneOf", "not", "$defs", "currency", "reference", "schema", "schemaVersion", "schemaObject", "echo", "JsonSchemaFields", "Object", "keys", "fields", "getSchemaProperty", "property", "setSchemaProperty", "ECHO_ANNOTATIONS_NS_DEPRECATED_KEY", "ECHO_ANNOTATIONS_NS_KEY", "getNormalizedEchoAnnotations", "obj", "normalizeEchoAnnotations", "undefined", "res", "Array", "Function", "JSONSchema", "Option", "Schema", "SchemaAST", "raise", "SchemaEx", "assertArgument", "invariant", "DXN", "EID", "EntityId", "log", "clearUndefined", "orderKeys", "removeProperties", "PropType", "schema", "slot", "Schema", "entityJsonSchema", "assertArgument", "jsonSchema", "removeProperties", "key", "_toJsonSchemaAST", "JSONSchema", "definitions", "normalizeJsonSchema", "withEchoRefinements", "ast", "suspendCache", "path", "recursiveResult", "suspendedAst", "cachedPath", "SchemaAST", "Suspend", "JSONSchemaAnnotationId", "mapAst", "propertyOrder", "propertySignatures", "annotationFields", "annotations_toJsonSchemaFields", "addJsonSchemaFields", "_defs", "$defs", "objectToEffectSchema", "result", "root", "Union", "oneOf", "toEffectSchema", "v", "anyOf", "map", "defs", "length", "log", "Tuple", "required", "optional", "invariant", "items", "Array", "isArray", "annotations", "identifier", "refSegments", "ECHO_ANNOTATIONS_NS_DEPRECATED_KEY", "isEchoObject", "echoRefinement", "$id", "fields", "propertyList", "Object", "properties", "immutableIdField", "value", "String", "additionalProperties", "indexValue", "anyToEffectSchema", "reference", "createEchoReferenceSchema", "echoUri", "Error", "ref", "targetSchemaDXN", "DXN", "annotationId", "echoAnnotations", "schemaFields", "ECHO_ANNOTATIONS_NS_KEY", "echoIdentifier", "decodeTypeIdentifierAnnotation", "startsWith", "isValid", "legacySchemaId", "undefined", "decodeTypeAnnotation", "kind", "entityKind", "version", "annotation", "EntityKind", "target", "relationTarget", "$ref", "sourceSchema", "source", "raise", "targetSchema", "typename", "echo", "jsonSchemaFieldsToAnnotations", "getNormalizedEchoAnnotations", "EchoAnnotations", "typeAnnotation", "TypeAnnotationId", "relationSource", "DecodedAnnotations", "makeAnnotatedRefinement", "orderKeys"]
}
