@dxos/echo 0.9.0 → 0.9.1-main.c7dcc2e112

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.
Files changed (103) hide show
  1. package/dist/lib/neutral/Annotation.mjs +12 -4
  2. package/dist/lib/neutral/Database.mjs +5 -1
  3. package/dist/lib/neutral/Entity.mjs +12 -8
  4. package/dist/lib/neutral/Feed.mjs +12 -12
  5. package/dist/lib/neutral/Filter.mjs +8 -8
  6. package/dist/lib/neutral/JsonSchema.mjs +4 -4
  7. package/dist/lib/neutral/Migration.mjs +8 -8
  8. package/dist/lib/neutral/Obj.mjs +14 -10
  9. package/dist/lib/neutral/Query.mjs +14 -14
  10. package/dist/lib/neutral/Ref.mjs +4 -4
  11. package/dist/lib/neutral/Relation.mjs +9 -9
  12. package/dist/lib/neutral/Tag.mjs +12 -12
  13. package/dist/lib/neutral/Type.mjs +7 -7
  14. package/dist/lib/neutral/{chunk-UUP46KUQ.mjs → chunk-3JXQUMUI.mjs} +9 -9
  15. package/dist/lib/neutral/{chunk-WTQJHC75.mjs → chunk-4TPQZPLY.mjs} +37 -25
  16. package/dist/lib/neutral/chunk-4TPQZPLY.mjs.map +7 -0
  17. package/dist/lib/neutral/{chunk-ZGNNFYHS.mjs → chunk-5GAIWRQB.mjs} +4 -4
  18. package/dist/lib/neutral/{chunk-ZGNNFYHS.mjs.map → chunk-5GAIWRQB.mjs.map} +2 -2
  19. package/dist/lib/neutral/{chunk-TYGKCRMK.mjs → chunk-6CEISA3V.mjs} +15 -7
  20. package/dist/lib/neutral/{chunk-TYGKCRMK.mjs.map → chunk-6CEISA3V.mjs.map} +3 -3
  21. package/dist/lib/neutral/{chunk-RIVWNMSF.mjs → chunk-A53NTBHE.mjs} +3 -3
  22. package/dist/lib/neutral/{chunk-QQIYS74I.mjs → chunk-AFANXSGV.mjs} +6 -6
  23. package/dist/lib/neutral/{chunk-5SMDBFVB.mjs → chunk-E7IOTOZD.mjs} +6 -6
  24. package/dist/lib/neutral/{chunk-5SMDBFVB.mjs.map → chunk-E7IOTOZD.mjs.map} +2 -2
  25. package/dist/lib/neutral/{chunk-T6E37YIP.mjs → chunk-HGWQR5KH.mjs} +18 -10
  26. package/dist/lib/neutral/chunk-HGWQR5KH.mjs.map +7 -0
  27. package/dist/lib/neutral/{chunk-3PBP4V4O.mjs → chunk-JZ6LFQU5.mjs} +11 -3
  28. package/dist/lib/neutral/chunk-JZ6LFQU5.mjs.map +7 -0
  29. package/dist/lib/neutral/{chunk-7PI7C4EF.mjs → chunk-K3S7D5PR.mjs} +3 -3
  30. package/dist/lib/neutral/{chunk-5SUJPHAE.mjs → chunk-L3OBWBV2.mjs} +2 -2
  31. package/dist/lib/neutral/{chunk-6YDI3J37.mjs → chunk-NOL7O3BL.mjs} +4 -4
  32. package/dist/lib/neutral/{chunk-IGK6FN65.mjs → chunk-PLDMJJJC.mjs} +2 -2
  33. package/dist/lib/neutral/{chunk-LWXVKPPW.mjs → chunk-SZ5WB6HF.mjs} +6 -6
  34. package/dist/lib/neutral/{chunk-MZ7K3MLL.mjs → chunk-TF5BSLF6.mjs} +3 -3
  35. package/dist/lib/neutral/chunk-TF5BSLF6.mjs.map +7 -0
  36. package/dist/lib/neutral/{chunk-7FPIAJIV.mjs → chunk-VQYL2OQF.mjs} +89 -15
  37. package/dist/lib/neutral/chunk-VQYL2OQF.mjs.map +7 -0
  38. package/dist/lib/neutral/{chunk-R5W6DXR4.mjs → chunk-WZ32BF53.mjs} +26 -2
  39. package/dist/lib/neutral/chunk-WZ32BF53.mjs.map +7 -0
  40. package/dist/lib/neutral/{chunk-4ZUHOTCG.mjs → chunk-X3NUUON4.mjs} +3 -3
  41. package/dist/lib/neutral/{chunk-SBVFRTST.mjs → chunk-Z3WMRRAZ.mjs} +14 -6
  42. package/dist/lib/neutral/chunk-Z3WMRRAZ.mjs.map +7 -0
  43. package/dist/lib/neutral/index.mjs +19 -19
  44. package/dist/lib/neutral/internal/index.mjs +26 -6
  45. package/dist/lib/neutral/meta.json +1 -1
  46. package/dist/lib/neutral/testing/index.mjs +19 -19
  47. package/dist/types/src/Annotation.d.ts +1 -1
  48. package/dist/types/src/Annotation.d.ts.map +1 -1
  49. package/dist/types/src/Database.d.ts +22 -0
  50. package/dist/types/src/Database.d.ts.map +1 -1
  51. package/dist/types/src/Entity.d.ts +2 -0
  52. package/dist/types/src/Entity.d.ts.map +1 -1
  53. package/dist/types/src/Feed.d.ts +3 -0
  54. package/dist/types/src/Feed.d.ts.map +1 -1
  55. package/dist/types/src/Obj.d.ts +2 -0
  56. package/dist/types/src/Obj.d.ts.map +1 -1
  57. package/dist/types/src/Ref.d.ts +3 -3
  58. package/dist/types/src/Ref.d.ts.map +1 -1
  59. package/dist/types/src/Tag.d.ts.map +1 -1
  60. package/dist/types/src/Type.d.ts +5 -1
  61. package/dist/types/src/Type.d.ts.map +1 -1
  62. package/dist/types/src/internal/Annotation/annotations.d.ts +41 -0
  63. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
  64. package/dist/types/src/internal/Obj/atoms.d.ts +5 -0
  65. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
  66. package/dist/types/src/internal/Ref/index.d.ts +1 -0
  67. package/dist/types/src/internal/Ref/index.d.ts.map +1 -1
  68. package/dist/types/src/internal/Ref/ref.d.ts +66 -2
  69. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
  70. package/dist/types/src/internal/Ref/strong-deps.d.ts +35 -0
  71. package/dist/types/src/internal/Ref/strong-deps.d.ts.map +1 -0
  72. package/dist/types/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +11 -11
  74. package/src/Annotation.ts +5 -0
  75. package/src/Database.ts +33 -1
  76. package/src/Entity.ts +3 -1
  77. package/src/Feed.ts +3 -0
  78. package/src/Obj.ts +2 -0
  79. package/src/Ref.ts +3 -3
  80. package/src/Tag.ts +1 -0
  81. package/src/Type.ts +16 -2
  82. package/src/internal/Annotation/annotations.ts +56 -0
  83. package/src/internal/Obj/atoms.ts +31 -0
  84. package/src/internal/Obj/json-serializer.ts +3 -3
  85. package/src/internal/Ref/index.ts +1 -0
  86. package/src/internal/Ref/ref.ts +96 -19
  87. package/src/internal/Ref/strong-deps.ts +107 -0
  88. package/dist/lib/neutral/chunk-3PBP4V4O.mjs.map +0 -7
  89. package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +0 -7
  90. package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +0 -7
  91. package/dist/lib/neutral/chunk-R5W6DXR4.mjs.map +0 -7
  92. package/dist/lib/neutral/chunk-SBVFRTST.mjs.map +0 -7
  93. package/dist/lib/neutral/chunk-T6E37YIP.mjs.map +0 -7
  94. package/dist/lib/neutral/chunk-WTQJHC75.mjs.map +0 -7
  95. /package/dist/lib/neutral/{chunk-UUP46KUQ.mjs.map → chunk-3JXQUMUI.mjs.map} +0 -0
  96. /package/dist/lib/neutral/{chunk-RIVWNMSF.mjs.map → chunk-A53NTBHE.mjs.map} +0 -0
  97. /package/dist/lib/neutral/{chunk-QQIYS74I.mjs.map → chunk-AFANXSGV.mjs.map} +0 -0
  98. /package/dist/lib/neutral/{chunk-7PI7C4EF.mjs.map → chunk-K3S7D5PR.mjs.map} +0 -0
  99. /package/dist/lib/neutral/{chunk-5SUJPHAE.mjs.map → chunk-L3OBWBV2.mjs.map} +0 -0
  100. /package/dist/lib/neutral/{chunk-6YDI3J37.mjs.map → chunk-NOL7O3BL.mjs.map} +0 -0
  101. /package/dist/lib/neutral/{chunk-IGK6FN65.mjs.map → chunk-PLDMJJJC.mjs.map} +0 -0
  102. /package/dist/lib/neutral/{chunk-LWXVKPPW.mjs.map → chunk-SZ5WB6HF.mjs.map} +0 -0
  103. /package/dist/lib/neutral/{chunk-4ZUHOTCG.mjs.map → chunk-X3NUUON4.mjs.map} +0 -0
@@ -9,21 +9,21 @@ import {
9
9
  updateFieldNameInSchema,
10
10
  updateFieldsInSchema,
11
11
  version
12
- } from "./chunk-7FPIAJIV.mjs";
12
+ } from "./chunk-VQYL2OQF.mjs";
13
13
  import {
14
14
  toEffectSchema,
15
15
  toJsonSchema
16
- } from "./chunk-7PI7C4EF.mjs";
16
+ } from "./chunk-K3S7D5PR.mjs";
17
17
  import {
18
18
  getMetaChecked
19
- } from "./chunk-4ZUHOTCG.mjs";
19
+ } from "./chunk-X3NUUON4.mjs";
20
20
  import {
21
21
  TypeIdentifierAnnotationId,
22
22
  getDatabase,
23
23
  getLabel,
24
24
  getSchemaURI,
25
25
  getTypeURIFromSpecifier
26
- } from "./chunk-R5W6DXR4.mjs";
26
+ } from "./chunk-WZ32BF53.mjs";
27
27
  import {
28
28
  EntityKind,
29
29
  InstancePhantomId,
@@ -66,7 +66,7 @@ __export(Type_exports, {
66
66
  });
67
67
  import { raise } from "@dxos/debug";
68
68
  import { assertArgument, invariant } from "@dxos/invariant";
69
- import { EID } from "@dxos/keys";
69
+ import { DXN, EID } from "@dxos/keys";
70
70
  var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Type.ts";
71
71
  var makeObject2 = EchoObjectSchema;
72
72
  var Type = TypeSchema;
@@ -124,9 +124,17 @@ var expectTypeKind = (entity) => {
124
124
  assertArgument(isTypeKind(entity), "entity", "Expected a type-kind Type entity.");
125
125
  return entity;
126
126
  };
127
- var getURI = (input) => {
127
+ var getURI = (input, options) => {
128
128
  if (isType(input)) {
129
- return getTypeURIFromSpecifier(input);
129
+ const uri = getTypeURIFromSpecifier(input);
130
+ if (options?.prefer === "named" && !DXN.isDXN(uri)) {
131
+ const typename = getTypename(input);
132
+ const version2 = getMeta(input).version;
133
+ if (typename && version2) {
134
+ return DXN.make(typename, version2);
135
+ }
136
+ }
137
+ return uri;
130
138
  }
131
139
  return getSchemaURI(getSchema(input)) ?? raise(new TypeError("Type entity has no URI"));
132
140
  };
@@ -138,13 +146,13 @@ var getTypename = (input) => {
138
146
  }
139
147
  typename ??= input.id;
140
148
  typename = stripTypenamePrefix(typename);
141
- invariant(typeof typename === "string" && typename.length > 0, "Invalid typename", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 205, S: void 0, A: ["typeof typename === 'string' && typename.length > 0", "'Invalid typename'"] });
149
+ invariant(typeof typename === "string" && typename.length > 0, "Invalid typename", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 219, S: void 0, A: ["typeof typename === 'string' && typename.length > 0", "'Invalid typename'"] });
142
150
  return typename;
143
151
  };
144
152
  var getVersion = (input) => {
145
153
  const meta = getMetaChecked(input);
146
154
  const semver = meta.version ?? input.jsonSchema?.version ?? DRAFT_VERSION;
147
- invariant(typeof semver === "string" && semver.match(/^\d+\.\d+\.\d+$/), "Invalid version", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 226, S: void 0, A: ["typeof semver === 'string' && semver.match(/^\\d+\\.\\d+\\.\\d+$/)", "'Invalid version'"] });
155
+ invariant(typeof semver === "string" && semver.match(/^\d+\.\d+\.\d+$/), "Invalid version", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 240, S: void 0, A: ["typeof semver === 'string' && semver.match(/^\\d+\\.\\d+\\.\\d+$/)", "'Invalid version'"] });
148
156
  const heads = version(input).automergeHeads;
149
157
  if (heads != null && heads.length > 0) {
150
158
  return `${semver}-${[
@@ -248,4 +256,4 @@ export {
248
256
  removeFields,
249
257
  Type_exports
250
258
  };
251
- //# sourceMappingURL=chunk-T6E37YIP.mjs.map
259
+ //# sourceMappingURL=chunk-HGWQR5KH.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/Type.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { raise } from '@dxos/debug';\nimport { type EncodedReference } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, type EntityId, type URI } from '@dxos/keys';\n\nimport type * as Database from './Database';\nimport type * as EntityModule from './Entity';\nimport * as internal from './internal';\nimport * as typeInternal from './internal/Type';\nimport type * as RelationModule from './Relation';\n\n//\n// Internal types (not exported)\n//\n\n/**\n * Structural base shared by the three sibling type-entity interfaces\n * ({@link Obj}, {@link Relation}, {@link Type}). NOT exported — callers\n * should constrain on {@link AnyEntity} when they want \"any of the three\"\n * and on the specific kind interface otherwise.\n */\ninterface BaseTypeEntity<A> {\n /**\n * Entity-kind brand of the type-entity value itself — always `EntityKind.Type`.\n * The kind of instance the type *describes* lives on `[SchemaKindId]`\n * (Object / Relation / Type). Lets `Obj.isObject` / `Relation.isRelation`\n * reject type entities by a single `[KindId]` check.\n */\n readonly [internal.KindId]: internal.EntityKind.Type;\n\n /**\n * Object id. Like all ECHO entities, type entities always carry an id —\n * stamped at construction for in-memory (static) declarations and assigned by\n * the database once persisted. The id does NOT determine the entity's URI:\n * static types resolve to their typename DXN, persisted types to `echo:/<id>`\n * (see `getTypeURIFromSpecifier`).\n */\n readonly id: EntityId;\n\n readonly name?: string;\n // NOTE: `typename` / `version` are intentionally NOT fields on any type-entity\n // interface. Both static and persisted entities carry them in `EntityMeta`\n // (`key` / `version`); read them via `Type.getTypename(self)` /\n // `Type.getVersion(self)` — never as a direct property.\n readonly jsonSchema: internal.JsonSchemaType;\n readonly [InstancePhantomId]?: A;\n}\n\n//\n// Obj — `Type.Type` value for an ECHO object schema.\n//\n\n/**\n * TypeScript type for an ECHO object type — a `Type.Type<A>` entity.\n *\n * `T` is the instance type produced by `Obj.make(Foo, props)`. `Fields` is\n * retained as a structural hint (the runtime value still carries `.fields`),\n * but consumers should derive instance/encoded types via `Type.InstanceType`.\n *\n * **Not a `Schema.Schema`.** `Foo.ast` / `Schema.Schema.Type<typeof Foo>` /\n * `Schema.extend(Foo)` no longer typecheck — extract the Effect Schema via\n * `Type.getSchema(Foo)` first, or derive instance types via\n * `Type.InstanceType<typeof Foo>`.\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));\n *\n * type Person = Type.InstanceType<typeof Person>;\n * ```\n */\nexport interface Obj<T, Fields extends Schema.Struct.Fields = Schema.Struct.Fields> extends BaseTypeEntity<\n T & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n> {\n /** Schema-kind brand (object). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Object;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Type that represents any ECHO object type — a `Type.Type` entity branded\n * with the object entity kind, i.e. what `Type.makeObject(dxn)` produces.\n */\nexport type AnyObj = Obj<unknown>;\n\n/**\n * Factory function to create an ECHO object type.\n *\n * Returns a `Type.Type` entity — a live, in-memory `TypeSchema` instance,\n * NOT a `Schema.Schema`. Use `Type.InstanceType<typeof Foo>` for the instance\n * type and `Type.getSchema(Foo)` to obtain the underlying Effect Schema.\n *\n * The entity's id defaults to `EntityId.deterministic(typename, version)` so\n * constructing a type never reaches `crypto.getRandomValues()` — required for\n * Cloudflare workerd, which forbids RNG calls in global (module-evaluation)\n * scope. Pass `{ id }` to override (e.g. with `EntityId.random()` from a\n * request handler).\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));\n * ```\n */\nexport const makeObject: {\n (\n dxn: DXN.DXN,\n options?: { id?: EntityId },\n ): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;\n} = internal.EchoObjectSchema as any;\n\n//\n// Type — the ECHO entity that holds a schema and metadata.\n// Persisted via `db.addType()`; subscribed to via `Filter.type(Type.Type)`.\n//\n\n/**\n * ECHO meta-schema entity — stores `{ name?, typename, version, jsonSchema }`.\n * Type-kind sibling of `Type.makeObject(...)` / `Type.makeRelation(...)` outputs.\n * Stored types live under this entity; filter via `Filter.type(Type.Type)`.\n */\nexport const Type: Type<typeInternal.TypeSchema> = typeInternal.TypeSchema as any;\n\n/**\n * Default version stamped on draft (unnamed) types created via\n * {@link makeObjectFromJsonSchema} / {@link makeRelationFromJsonSchema} when\n * the caller does not supply one. Pure dynamic drafts surface as `'0.0.0'`\n * until they are persisted, at which point automerge-heads suffix the version.\n */\nconst DRAFT_VERSION = '0.0.0';\n\n/**\n * Common props shared by the type-kind factories. Typename and version are\n * optional — drafts omit typename and default version to {@link DRAFT_VERSION}.\n */\ntype MakeTypeProps = {\n jsonSchema: internal.JsonSchemaType;\n typename?: string;\n version?: string;\n name?: string;\n id?: EntityId;\n};\n\n/**\n * Construct a new object-kind type entity from raw metadata — for cases where\n * an Effect Schema isn't available (e.g. JSON-Schema arriving over the network\n * or from a UI editor). Parallel to {@link makeObject} but takes pre-built\n * `jsonSchema` instead of piping through an Effect schema.\n *\n * The returned entity is in-memory; persist it with `db.addType(entity)`.\n */\nexport const makeObjectFromJsonSchema = (props: MakeTypeProps): Type<typeInternal.TypeSchema> => {\n const { typename, version, ...data } = props;\n // `typename` / `version` are routed through `EntityMeta` (`key` / `version`)\n // — the canonical registry-provenance pair — not data fields. Drafts default\n // to `'0.0.0'`; the version is omitted from meta entirely when the caller\n // doesn't supply one so the proxy projection can apply its own default.\n return internal.makeObject(\n internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,\n data as any,\n {\n keys: [],\n key: typename,\n version: version ?? DRAFT_VERSION,\n },\n typeInternal.TypeSchema,\n ) as unknown as Type<typeInternal.TypeSchema>;\n};\n\n/**\n * Construct a new relation-kind type entity from raw metadata. Parallel to\n * {@link makeRelation} but takes pre-built `jsonSchema` instead of piping\n * through an Effect schema. `source` / `target` accept either a static\n * `Type.Obj` entity or the well-known `Obj.Unknown` schema.\n *\n * The returned entity is in-memory; persist it with `db.addType(entity)`.\n */\nexport const makeRelationFromJsonSchema = (\n props: MakeTypeProps & {\n source: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;\n target: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;\n },\n): Type<typeInternal.TypeSchema> => {\n const { source, target, jsonSchema, typename, version, ...rest } = props;\n // Embed source/target DXNs + relation entity-kind into the jsonSchema so the\n // entity round-trips correctly through `toEffectSchema` / queries / refs.\n const sourceURI = internal.getTypeURIFromSpecifier(source);\n const targetURI = internal.getTypeURIFromSpecifier(target);\n const enrichedJsonSchema: internal.JsonSchemaType = {\n ...jsonSchema,\n entityKind: internal.EntityKind.Relation,\n relationSource: { $ref: sourceURI },\n relationTarget: { $ref: targetURI },\n };\n // `typename` / `version` route through `EntityMeta` (see\n // {@link makeObjectFromJsonSchema}); drafts default version to `'0.0.0'`.\n return internal.makeObject(\n internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,\n { ...rest, jsonSchema: enrichedJsonSchema } as any,\n {\n keys: [],\n key: typename,\n version: version ?? DRAFT_VERSION,\n },\n typeInternal.TypeSchema,\n ) as unknown as Type<typeInternal.TypeSchema>;\n};\n\n/**\n * TypeScript type for an ECHO relation type — a `Type.Type<A>` entity.\n *\n * `T` is the instance-property type produced by `Relation.make(...)` (excluding\n * source/target endpoints). `Source` and `Target` are the endpoint types.\n *\n * **Not a `Schema.Schema`.** See {@link Obj}'s note.\n */\nexport interface Relation<\n T,\n Source,\n Target,\n Fields extends Schema.Struct.Fields = Schema.Struct.Fields,\n> extends BaseTypeEntity<\n RelationModule.Endpoints<Source, Target> & T & EntityModule.OfKind<typeof EntityModule.Kind.Relation>\n> {\n /** Schema-kind brand (relation). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Relation;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Type that represents any ECHO relation type — a `Type.Type` entity branded\n * with the relation entity kind, i.e. what `Type.makeRelation(...)` produces.\n */\nexport type AnyRelation = Relation<unknown, unknown, unknown>;\n\n/**\n * Factory function to create an ECHO relation schema.\n * Adds relation metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const WorksFor = Schema.Struct({\n * role: Schema.String,\n * }).pipe(Type.makeRelation({\n * dxn: DXN.make('com.example.type.worksFor', '0.1.0'),\n * source: Person,\n * target: Company,\n * }));\n * ```\n */\nexport const makeRelation: {\n <SourceInstance, TargetInstance>(opts: {\n dxn: DXN.DXN;\n source: Obj<SourceInstance, any> | internal.UnknownTypeSchema<SourceInstance, typeof EntityModule.Kind.Object>;\n target: Obj<TargetInstance, any> | internal.UnknownTypeSchema<TargetInstance, typeof EntityModule.Kind.Object>;\n /**\n * Override the entity id. Defaults to `EntityId.deterministic(typename, version)`;\n * see `Type.makeObject` for the workerd motivation.\n */\n id?: EntityId;\n }): <Self extends Schema.Schema.Any>(\n self: Self,\n ) => Relation<\n Schema.Schema.Type<Self>,\n SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,\n TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n >;\n} = internal.EchoRelationSchema as any;\n\n/**\n * Type that represents any ECHO type-kind entity — a `Type.Type` meta-schema\n * value (static `Type.Type` or a persisted draft from `db.addType(...)`).\n * Mirrors {@link AnyObj} / {@link AnyRelation} for the third sibling kind.\n */\nexport type AnyType = Type<unknown>;\n\n/**\n * Any ECHO type-entity — one of the three sibling kinds: object-kind, relation-kind,\n * or type-kind (the meta-schema). APIs that want \"any ECHO type\" use this union;\n * the underlying Effect Schema is retrieved via `Type.getSchema`.\n */\nexport type AnyEntity = AnyObj | AnyRelation | AnyType;\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to an object-kind entity. Checks\n * ENTITIES, not instances — use `Obj.isObject` for instances. Raw\n * `Schema.Schema` values (including the branded `Obj.Unknown` companion)\n * are intentionally not accepted; inspect their `TypeAnnotation` directly.\n */\nexport const isObject = (entity: AnyEntity): entity is AnyObj => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Object;\n};\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to a relation-kind entity. Checks\n * ENTITIES, not instances — use `Relation.isRelation` for instances.\n */\nexport const isRelation = (entity: AnyEntity): entity is AnyRelation => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Relation;\n};\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to the type-kind meta-schema\n * (e.g. `Type.Type`). Mirrors {@link isObject} / {@link isRelation}.\n */\nexport const isTypeKind = (entity: AnyEntity): entity is Type => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Type;\n};\n\n/**\n * Narrow a `Type.AnyEntity` (e.g. one returned from `schemaRegistry.query(...)`)\n * to `AnyObj`, throwing if it describes a relation or the type-kind\n * meta-schema. Use at call sites that need to pass the value to `Obj.make`,\n * `Filter.type`, or other object-only APIs.\n */\nexport const assertObject = (entity: AnyEntity): AnyObj => {\n assertArgument(isObject(entity), 'entity', 'Expected an object-kind Type entity.');\n return entity;\n};\n\n/** Narrow a `Type.AnyEntity` to `AnyRelation`, throwing otherwise. */\nexport const expectRelation = (entity: AnyEntity): AnyRelation => {\n assertArgument(isRelation(entity), 'entity', 'Expected a relation-kind Type entity.');\n return entity;\n};\n\n/** Narrow a `Type.AnyEntity` to the `Type.Type` meta-schema, throwing otherwise. */\nexport const expectTypeKind = (entity: AnyEntity): Type => {\n assertArgument(isTypeKind(entity), 'entity', 'Expected a type-kind Type entity.');\n return entity;\n};\n\n/**\n * Type that represents any Ref schema (with unknown target type).\n * This is a schema type, not an instance type.\n */\nexport type AnyRef = Schema.Schema<internal.Ref<any>, EncodedReference>;\n\n//\n// Schema utility functions\n//\n\n/**\n * Returns the URI identifying a type entity. Always defined.\n *\n * - Static `Type.Obj` / `Type.Relation` → typename DXN (e.g. `dxn:com.example.type.person:0.1.0`).\n * - Persisted `Type.Type` instance (has `id`) → local `EID` (`echo:/<objectId>`).\n * - In-memory `Type.Type` draft (has `id`, no typename) → local `EID`.\n *\n * When `options.prefer === 'named'` the result is forced to a DXN — for\n * persisted type entities the typename + version from meta are used to\n * construct the DXN; static types already return a DXN by default.\n *\n * Only accepts `Type.AnyEntity` entities. Raw `Schema.Schema` values and the\n * branded `Obj.Unknown` / `Relation.Unknown` schemas are intentionally not\n * supported — use `internal.getSchemaURI` or the schema's typename annotation\n * directly when working at the schema level.\n */\nexport const getURI = (input: AnyEntity, options?: internal.GetURIOptions): URI.URI => {\n // For Type entities, route through `getTypeURIFromSpecifier` (id → EID,\n // typename/version → DXN). For Obj/Relation entities, unwrap to the source\n // Effect Schema first and read its annotations.\n if (isType(input)) {\n const uri = internal.getTypeURIFromSpecifier(input);\n if (options?.prefer === 'named' && !DXN.isDXN(uri)) {\n // Persisted type — the auto-detected URI is an EID, but caller wants a\n // DXN. Construct from typename + version (both live in EntityMeta).\n const typename = getTypename(input);\n const version = getMeta(input).version;\n if (typename && version) {\n return DXN.make(typename, version);\n }\n }\n return uri;\n }\n return internal.getSchemaURI(getSchema(input)) ?? raise(new TypeError('Type entity has no URI'));\n};\n\n/**\n * @returns The typename. Example: `com.example.type.person`.\n *\n * Persisted `Type.Type` entities carry typename in `EntityMeta.key` (the\n * canonical registry-provenance field); unnamed drafts fall back to the\n * entity's object id so the helper always returns a string. Any `dxn:` or\n * `echo:/` prefix is stripped — typename is a bare identifier, not a URI.\n */\n// TODO(wittjosiah): For in-database types this should return the object id once the registry\n// has more robust options for shadowing types (so callers can disambiguate db-stored copies).\nexport const getTypename = (input: AnyEntity): string => {\n // Both in-memory and in-database entities carry typename in `EntityMeta.key`\n // — the canonical registry-provenance field. In-memory entities attach meta\n // eagerly (see `makeEchoTypeSchema`), so a single meta-backed read covers\n // both forms.\n const meta = internal.getMetaChecked(input);\n let typename: string | undefined = meta.key as string | undefined;\n // `meta.key` is a denormalized copy of the typename. The authoritative source\n // for a type entity is its `jsonSchema.typename` (`getSchema` rebuilds the\n // Effect Schema from `jsonSchema`). A type loaded from a snapshot can arrive\n // with `meta.key` absent (the meta round-trip dropped the denormalized copy)\n // while `jsonSchema.typename` is always present — consult it before the\n // last-resort id fallback so callers never receive a bare object id where a\n // typename is expected (e.g. `Filter.typename`, which rejects non-typenames).\n if (typename == null) {\n typename = input.jsonSchema?.typename;\n }\n // Unnamed drafts (no meta.key, no jsonSchema typename) fall back to the id.\n typename ??= input.id as string;\n // Typename is a bare identifier — strip URI prefixes if a caller seeded\n // meta.key with one accidentally (or if a static entity carries a DXN-\n // style typename).\n typename = stripTypenamePrefix(typename);\n invariant(typeof typename === 'string' && typename.length > 0, 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version.\n * @example 0.1.0\n * @example 0.1.0-<heads> (in-database, versioned by automerge heads)\n *\n * The registry-provenance semver lives in `EntityMeta.version`; unversioned\n * drafts default to {@link DRAFT_VERSION} (`'0.0.0'`). In-database entities are\n * additionally versioned by their automerge heads, which are exposed as the\n * semver pre-release tag (`<semver>-<heads>`). In-memory declarations have no\n * heads and surface the bare semver. Read the registry semver alone via\n * `Type.getMeta(input).version`.\n */\nexport const getVersion = (input: AnyEntity): string => {\n const meta = internal.getMetaChecked(input);\n // As with `getTypename`: `meta.version` is a denormalized copy; the\n // authoritative semver lives in `jsonSchema.version`. Prefer meta, fall back\n // to jsonSchema (always present on persisted types, survives serialization),\n // then to `DRAFT_VERSION` for unversioned drafts.\n const semver = (meta.version as string | undefined) ?? input.jsonSchema?.version ?? DRAFT_VERSION;\n invariant(typeof semver === 'string' && semver.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n // In-database entities are versioned by their automerge heads; expose them as\n // the semver pre-release tag. In-memory drafts carry no heads → bare semver.\n const heads = internal.version(input).automergeHeads;\n if (heads != null && heads.length > 0) {\n return `${semver}-${[...heads].sort().join('.')}`;\n }\n return semver;\n};\n\n/**\n * Strip URI prefixes (`dxn:`, `echo:/`, `echo://`) from a typename string.\n * Typename is a bare identifier — callers reading from meta or from a\n * caller-supplied seed value shouldn't propagate URI prefixes downstream.\n */\nconst stripTypenamePrefix = (value: string): string => {\n if (value.startsWith('dxn:')) {\n return value.slice('dxn:'.length);\n }\n if (value.startsWith('echo://')) {\n return value.slice('echo://'.length);\n }\n if (value.startsWith('echo:/')) {\n return value.slice('echo:/'.length);\n }\n return value;\n};\n\n/**\n * Type predicate: true iff the value is any type-kind ECHO entity — a static\n * `Type.Obj` / `Type.Relation` produced by `Type.makeObject` / `Type.makeRelation`, a\n * static meta `Type.Type`, or a persisted `Type.Type` returned by the database.\n *\n * All three branches stamp `[KindId] = Type`, so this is a single brand check.\n * Use {@link isObject} / {@link isRelation} / {@link isTypeKind}\n * when you need to discriminate further; use {@link getDatabase} when you mean\n * \"is this a db-attached type\" (vs. an in-memory declaration).\n */\nexport const isType = (value: unknown): value is AnyEntity =>\n internal.getEntityKindBrand(value) === internal.EntityKind.Type;\n\n/**\n * Get the database the type entity belongs to, or `undefined` if it is an\n * in-memory declaration (`Type.makeObject` / `Type.makeRelation` result) not\n * yet attached to a database. Mirrors `Obj.getDatabase` / `Relation.getDatabase`.\n *\n * Database attachment is the canonical discriminator between in-memory and\n * in-database type entities — both are live reactive `TypeSchema` instances and\n * are otherwise indistinguishable.\n */\nexport const getDatabase = (input: AnyEntity): Database.Database | undefined => internal.getDatabase(input);\n\n/**\n * Mutable meta type returned by `Type.getMeta` inside a `Type.update` callback.\n * Mirrors `Obj.Meta` / `Relation.Meta` — `Type.Type` is an Entity like its\n * siblings, so its meta is the same `EntityMeta` record:\n * `{ keys, tags?, key?, version? }`.\n *\n * `key` / `version` here are the canonical registry-provenance pair\n * (typename + semver) on persisted Type.Type entities; they are absent on\n * unnamed drafts. Use {@link getTypename} / {@link getVersion} when you want\n * a non-`undefined` value with id / {@link DRAFT_VERSION} fallbacks.\n */\nexport type Meta = internal.Meta;\n\n/**\n * Deeply read-only version of {@link Meta}.\n * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TS error).\n */\nexport type ReadonlyMeta = internal.ReadonlyMeta;\n\n/**\n * Returns the entity's `EntityMeta`. Same semantics as `Obj.getMeta` /\n * `Relation.getMeta` — `Type.Type` is an Entity and carries the canonical\n * `EntityMeta` directly. Returns mutable meta when passed a mutable type\n * (inside a `Type.update` callback), read-only meta otherwise.\n *\n * For persisted Type entities, `meta.key` holds the typename and\n * `meta.version` holds the semver. Use {@link getTypename} / {@link getVersion}\n * if you want the helpers' id / {@link DRAFT_VERSION} fallbacks for drafts.\n *\n * Both persisted and in-memory type entities (`Type.makeObject` /\n * `Type.makeRelation` results) carry their `EntityMeta` via `[MetaId]`, so the\n * lookup is uniform.\n */\nexport function getMeta(entity: internal.Mutable<AnyEntity>): Meta;\nexport function getMeta(entity: Mutable): Meta;\nexport function getMeta(entity: AnyEntity): ReadonlyMeta;\nexport function getMeta(entity: AnyEntity | internal.Mutable<AnyEntity> | Mutable): ReadonlyMeta | Meta {\n // The `Mutable` overload accepts the narrowed view passed to `Type.update`\n // callbacks; at runtime that draft IS the underlying persisted Type entity,\n // so the same `MetaId` lookup works.\n assertArgument(isType(entity), 'entity', 'Expected a Type entity.');\n // Both persisted and in-memory type entities carry runtime `EntityMeta` via\n // `[MetaId]`, so the lookup is uniform.\n return internal.getMetaChecked(entity);\n}\n\n/**\n * Get the display label of a type entity.\n * Reads the field(s) nominated by the type's {@link LabelAnnotation} (e.g. `name` on persisted schemas).\n * Returns `undefined` if no label field is populated.\n */\nexport const getLabel = (entity: AnyEntity, options?: internal.GetLabelOptions): string | undefined =>\n internal.getLabel(entity, options);\n\n/**\n * String key used to phantom-carry the instance type produced by a `Type.Type`.\n * Used by `Type.InstanceType<typeof Foo>` to recover the schema instance type\n * since `Type.makeObject(dxn)` does not return a `Schema.Schema`.\n *\n * Re-exported from the internal types layer so both `Type.ts` and internal\n * helpers (`makeObject`, `createObject`) reference the same phantom key.\n */\nexport const InstancePhantomId = internal.InstancePhantomId;\nexport type InstancePhantomId = internal.InstancePhantomId;\n\n/**\n * Sibling of {@link Obj} / {@link Relation} for the third ECHO entity kind:\n * **type-kind** entities (meta-schemas). The singleton {@link Type} const is\n * the canonical example — it describes stored type definitions themselves.\n *\n * Not a `Schema.Schema`. Use `Type.getSchema(value)` to obtain the underlying\n * Effect Schema and `Type.update(value, draft => ...)` to mutate.\n *\n * `A` is the instance-type phantom — what `Obj.make(value, ...)` would produce.\n * Merged with the `Type` const value via TypeScript declaration merging.\n */\nexport interface Type<A = unknown> extends BaseTypeEntity<A & EntityModule.OfKind<typeof EntityModule.Kind.Type>> {\n /** Schema-kind brand (type — the meta-schema kind). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Type;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n}\n\n/**\n * Instance type produced by a Type entity.\n *\n * Accepts ONLY {@link AnyEntity} inputs — `Type.Obj`, `Type.Relation`, or\n * `Type.Type`. Raw Effect `Schema.Schema` values are rejected: for those, use\n * `Schema.Schema.Type<typeof Foo>` directly. This separation keeps the type\n * system honest about which values represent ECHO entities versus plain\n * Effect schemas.\n *\n * Dispatches on the entity kind:\n * - `Relation<Props, S, T>` → `Endpoints<S,T> & Props & OfKind<Relation>`\n * - `Obj<A>` → `A & OfKind<Object>`\n * - `Type<A>` → `A & OfKind<Type>`\n */\nexport type InstanceType<T extends AnyEntity> =\n T extends Relation<infer Props, infer Source, infer Target, any>\n ? RelationModule.Endpoints<Source, Target> & Props & EntityModule.OfKind<typeof EntityModule.Kind.Relation>\n : T extends Obj<infer A, any>\n ? A & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n : T extends Type<infer A>\n ? A & EntityModule.OfKind<typeof EntityModule.Kind.Type>\n : never;\n\n/**\n * Returns the Effect Schema for a type entity.\n *\n * - For static `Type.Obj` / `Type.Relation` entities the source Effect Schema is\n * read from a hidden slot — these overloads preserve the instance type.\n * - For `Type.Type` entities (the meta-schema kind) the schema is rebuilt from\n * `type.jsonSchema`; the instance type isn't statically knowable so the wide\n * `AnyEntity` overload widens to `Schema.Schema.AnyNoContext`.\n *\n * Always call this when you need to interact with the Effect Schema API\n * (e.g. before passing to Effect.Schema functions). For ECHO-side APIs\n * (`Obj.make`, `Filter.type`, `Ref`) pass the type entity directly.\n *\n * Only accepts `Type.AnyEntity` — raw `Schema.Schema` values can be used\n * directly without unwrapping.\n */\nexport function getSchema<T extends AnyObj>(type: T): Schema.Schema<InstanceType<T>>;\nexport function getSchema<T extends AnyRelation>(type: T): Schema.Schema<InstanceType<T>>;\nexport function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext;\nexport function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext {\n // Static `Type.Type` entities carry the source Effect Schema on a hidden\n // slot so we can return it without round-tripping through JsonSchema.\n const staticSchema = internal.getStaticTypeSchema(type);\n if (staticSchema != null) {\n return staticSchema;\n }\n assertArgument(isType(type), 'type', 'Expected a Type entity.');\n // Persisted `Type.Type` entity — build the Effect Schema from its stored\n // jsonSchema and re-attach the TypeIdentifierAnnotation so the rebuilt\n // schema's URI (via getSchemaURI) matches the entity's local EID.\n const rebuilt = internal.toEffectSchema(type.jsonSchema);\n if (typeof type.id === 'string') {\n return rebuilt.annotations({\n [internal.TypeIdentifierAnnotationId]: EID.make({ entityId: type.id }),\n });\n }\n return rebuilt;\n}\n\n/**\n * Mutable view of a `Type.Type` — the shape passed to the `Type.update` callback.\n * Outside `Type.update`, `Type.Type` fields are read-only (both at the type level\n * and at runtime — direct assignment throws). Use this to constrain mutation to\n * the change context, analogous to `Obj.update(obj, (draft) => ...)`.\n *\n * NOTE: `typename` and `version` are intentionally absent — they live in\n * `EntityMeta` (`key` / `version` — the canonical registry-provenance pair).\n * Read them via {@link getTypename} / {@link getVersion} / {@link getMeta};\n * `typename` is treated as immutable on persisted entities.\n *\n * Unlike `Obj.update` — whose mutable view is inferred as `Mutable<A>` over the\n * whole instance type because every data field is editable — a `Type.Type`\n * exposes only `name` and `jsonSchema` for mutation. The rest of its shape\n * (`id`, the `[KindId]` / `[SchemaKindId]` brands, and `typename` / `version`\n * in meta) is immutable, so this view is declared explicitly rather than\n * derived from `InstanceType<Type.Type>`.\n */\nexport interface Mutable {\n name?: string;\n // Deep-mutable within the change context — `Type.update`'s purpose is to allow\n // mutation, so the draft exposes `jsonSchema` as writable (the readonly\n // `JsonSchemaType` would force callers to cast).\n jsonSchema: Types.DeepMutable<internal.JsonSchemaType>;\n}\n\n/**\n * Perform mutations on a `Type.Type` within a change context.\n *\n * The callback receives a {@link Mutable} view of the type — direct mutation of\n * a `Type.Type` outside `Type.update` throws at runtime, mirroring `Obj.update`.\n * Delegates to the same automerge-transaction primitive `Obj.update(obj, cb)` uses.\n */\nexport const update = (type: AnyEntity, callback: (mutable: Mutable) => void): void => {\n // `Type.Type` is an ECHO object; the change machinery is the same as `Obj.update`.\n internal.change(type, callback as internal.ChangeCallback<AnyEntity>);\n};\n\n//\n// Field-level helpers for mutating persisted types.\n// These are thin wrappers over `Type.update` plus the JsonSchema manipulation\n// utilities. Callers pass a persisted `Type.Type` (e.g. one returned by\n// `db.addType(schemaEntity)`) and the helper drives the change context.\n//\n\n/**\n * Add fields to a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const addFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {\n const extended = typeInternal.addFieldsToSchema(getSchema(type), fields);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(extended);\n });\n};\n\n/**\n * Replace existing fields on a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const updateFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {\n const updated = typeInternal.updateFieldsInSchema(getSchema(type), fields);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(updated);\n });\n};\n\n/**\n * Rename a field on a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const updateFieldPropertyName = (\n type: Type,\n { before, after }: { before: PropertyKey; after: PropertyKey },\n): void => {\n const renamed = typeInternal.updateFieldNameInSchema(getSchema(type), { before, after });\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(renamed);\n });\n};\n\n/**\n * Remove fields from a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const removeFields = (type: AnyEntity, fieldNames: string[]): void => {\n const removed = typeInternal.removeFieldsFromSchema(getSchema(type), fieldNames);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(removed);\n });\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;2BAAAA;EAAA;;;;;qBAAAC;EAAA,gBAAAC;EAAA;;;;;;;;;oBAAAC;EAAA;;;;;;;;AASA,SAASC,aAAa;AAEtB,SAASC,gBAAgBC,iBAAiB;AAC1C,SAASC,KAAKC,WAAoC;AA4FlD,IAAA,eAAA;AA4BA,IAAAC,cAAA;;;AAyCE,IAAA,2BAAA,CAAA,UAAA;AACA,QAAA,EAAA,UAAA,SAAAC,UAAA,GAAA,KAAA,IAAA;SAQSC,WAAAA,oBAAAA,UAAAA,GAAAA,MAAAA;IACLD,MAAAA,CAAAA;IAEFE,KAAAA;IAEF,SAAAF,YAAA;EAEF,GAAA,UAAA;;AAeE,IAAA,6BAAA,CAAA,UAAA;AACA,QAAA,EAAA,QAAA,QAAA,YAAA,UAAA,SAAAA,UAAA,GAAA,KAAA,IAAA;AAGA,QAAMG,YAA8C,wBAAA,MAAA;QAClD,YAAa,wBAAA,MAAA;QACbC,qBAAqBC;IACrBC,GAAAA;gBAAwBC,WAAAA;IAAU,gBAAA;MAClCC,MAAAA;;IAAkC,gBAAA;MACpC,MAAA;IACA;EACA;SAGyBL,WAAAA,oBAAAA,UAAAA,GAAAA;IACvB,GAAA;IACEM,YAAQ;;IAERT,MAAAA,CAAAA;IAEFE,KAAAA;IAEF,SAAAF,YAAA;EAqCF,GAAA,UAAA;;;AAwDE,IAAA,WAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAME,IAAA,aAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAME,IAAA,aAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAQSU,IAAAA,eAAAA,CAAAA,WAAAA;AACP,iBAAA,SAAA,MAAA,GAAA,UAAA,sCAAA;AAEF,SAAA;;AAGSA,IAAAA,iBAAAA,CAAAA,WAAAA;AACP,iBAAA,WAAA,MAAA,GAAA,UAAA,uCAAA;AAEF,SAAA;;AAGSA,IAAAA,iBAAAA,CAAAA,WAAAA;AACP,iBAAA,WAAA,MAAA,GAAA,UAAA,mCAAA;AAQA,SAAA;AACF;AAqBE,IAAA,SAAA,CAAA,OAAA,YAAA;MAIE,OAAIC,KAAAA,GAASC;UACX,MAAA,wBAAA,KAAA;QACA,SAAA,WAAA,WAAA,CAAA,IAAA,MAAA,GAAA,GAAA;AAGA,YAAIX,WAAYD,YAAS,KAAA;YACvBA,WAAWa,QAAKZ,KAAAA,EAAUD;AAC5B,UAAA,YAAAA,UAAA;AACF,eAAA,IAAA,KAAA,UAAAA,QAAA;MACA;IACF;AACA,WAAOc;EACP;AAEF,SAAA,aAAA,UAAA,KAAA,CAAA,KAAA,MAAA,IAAA,UAAA,wBAAA,CAAA;;AAYE,IAAA,cAAA,CAAA,UAAA;AAKA,QAAA,OAAA,eAAA,KAAA;AACA,MAAA,WAAA,KAAA;AAQA,MAAA,YAAA,MAAA;AACA,eAAA,MAAA,YAAA;EACAb;AAEA,eAAA,MAAA;AAIA,aAAOA,oBAAAA,QAAAA;AACP,YAAA,OAAA,aAAA,YAAA,SAAA,SAAA,GAAA,oBAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,KAAA,GAAA,QAAA,GAAA,CAAA,uDAAA,oBAAA,EAAA,CAAA;AAEF,SAAA;;AAcE,IAAA,aAAA,CAAA,UAAA;AACA,QAAA,OAAA,eAAA,KAAA;AAKA,QAAA,SAAA,KAAA,WAAA,MAAA,YAAA,WAAA;AACA,YAAA,OAAA,WAAA,YAAA,OAAA,MAAA,iBAAA,GAAA,mBAA6E,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,KAAA,GAAA,QAAA,GAAA,CAAA,sEAAA,mBAAA,EAAA,CAAA;QAG3E,QAAkB,QAAE,KAAA,EAAA;eAAIc,QAAAA,MAAAA,SAAAA,GAAAA;WAAW,GAAGC,MAAK,IAAM;MACnD,GAAA;IACA,EAAA,KAAOC,EAAAA,KAAAA,GAAAA,CAAAA;EACP;AAEF,SAAA;;IAOI,sBAAmB,CAAA,UAAa;AAClC,MAAA,MAAA,WAAA,MAAA,GAAA;AACIC,WAAMC,MAAAA,MAAW,OAAA,MAAY;;AAEjC,MAAA,MAAA,WAAA,SAAA,GAAA;AACID,WAAMC,MAAAA,MAAW,UAAW,MAAA;;AAEhC,MAAA,MAAA,WAAA,QAAA,GAAA;AACA,WAAOD,MAAAA,MAAAA,SAAAA,MAAAA;EACT;AAEA,SAAA;;;AA6DE,IAAAE,eAAA,CAAA,UAAA,YAAA,KAAA;AACA,SAAA,QAAA,QAAA;AAIA,iBAAA,OAAA,MAAA,GAAA,UAAwC,yBAAA;AAI1C,SAAA,eAAA,MAAA;;;AAiFE,IAAAC,qBAAA;AACA,SAAA,UAAA,MAAA;QAGE,eAAOC,oBAAAA,IAAAA;AACT,MAAA,gBAAA,MAAA;AACAC,WAAAA;EACA;AACA,iBAAA,OAAA,IAAA,GAAA,QAAA,yBAAA;QAIE,UAAeC,eAAY,KAAA,UAAA;aACxBV,KAAAA,OAASW,UAAAA;mBAAwCC,YAAiB;MAAC,CAAA,0BAAA,GAAA,IAAA,KAAA;QACtE,UAAA,KAAA;MACF,CAAA;IACA,CAAA;EACF;AA4BA,SAAA;;AASEZ,IAASa,SAAaC,CAAAA,MAAAA,aAAAA;AAGtB,EAAA,OAAA,MAAA,QAAA;AACF;AAYSC,IAAM,YAACC,CAAAA,MAAAA,WAAAA;QACZA,WAAmBhB,kBAAsBiB,UAAAA,IAAAA,GAAAA,MAAAA;AAC3C,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,QAAA;EAEF,CAAA;;AAMSF,IAAM,eAACC,CAAAA,MAAAA,WAAAA;QACZA,UAAmBhB,qBAAsBkB,UAAAA,IAAAA,GAAAA,MAAAA;AAC3C,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;EAEF,CAAA;;AAQ0EC,IAAAA,0BAAAA,CAAAA,MAAAA,EAAAA,QAAAA,MAAAA,MAAAA;QAAQC,UAAAA,wBAAAA,UAAAA,IAAAA,GAAAA;IAAM;IACtFC;;AAEA,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;EAEF,CAAA;;AAMSN,IAAM,eAACC,CAAAA,MAAAA,eAAAA;QACZA,UAAmBhB,uBAAsBsB,UAAAA,IAAAA,GAAAA,UAAAA;AAC3C,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;;;",
6
+ "names": ["InstancePhantomId", "getDatabase", "getLabel", "makeObject", "raise", "assertArgument", "invariant", "DXN", "EID", "makeObject", "version", "typename", "typeInternal", "enrichedJsonSchema", "entityKind", "EntityKind", "relationSource", "sourceURI", "relationTarget", "keys", "entity", "options", "prefer", "make", "internal", "heads", "join", "semver", "value", "startsWith", "getDatabase", "InstancePhantomId", "staticSchema", "assertArgument", "annotations", "TypeIdentifierAnnotationId", "entityId", "change", "callback", "type", "draft", "extended", "updated", "before", "after", "update", "removed"]
7
+ }
@@ -1,13 +1,17 @@
1
1
  import {
2
2
  get,
3
3
  set
4
- } from "./chunk-4ZUHOTCG.mjs";
4
+ } from "./chunk-X3NUUON4.mjs";
5
5
  import {
6
+ DEFAULT_LAYOUT_NAME,
6
7
  DescriptionAnnotation,
7
8
  Dictionary,
8
9
  FieldLookupAnnotationId,
9
10
  FormInlineAnnotation,
10
11
  FormInputAnnotation,
12
+ FormLayoutAnnotation,
13
+ FormLayoutAnnotationId,
14
+ FormOrderedAnnotation,
11
15
  GeneratorAnnotation,
12
16
  GeneratorAnnotationId,
13
17
  HiddenAnnotation,
@@ -28,7 +32,7 @@ import {
28
32
  setDescriptionWithSchema,
29
33
  setDictionary,
30
34
  setLabelWithSchema
31
- } from "./chunk-R5W6DXR4.mjs";
35
+ } from "./chunk-WZ32BF53.mjs";
32
36
  import {
33
37
  __export
34
38
  } from "./chunk-J5LGTIGS.mjs";
@@ -36,11 +40,15 @@ import {
36
40
  // src/Annotation.ts
37
41
  var Annotation_exports = {};
38
42
  __export(Annotation_exports, {
43
+ DEFAULT_LAYOUT_NAME: () => DEFAULT_LAYOUT_NAME,
39
44
  DescriptionAnnotation: () => DescriptionAnnotation,
40
45
  Dictionary: () => Dictionary2,
41
46
  FieldLookupAnnotationId: () => FieldLookupAnnotationId,
42
47
  FormInlineAnnotation: () => FormInlineAnnotation,
43
48
  FormInputAnnotation: () => FormInputAnnotation,
49
+ FormLayoutAnnotation: () => FormLayoutAnnotation,
50
+ FormLayoutAnnotationId: () => FormLayoutAnnotationId,
51
+ FormOrderedAnnotation: () => FormOrderedAnnotation,
44
52
  GeneratorAnnotation: () => GeneratorAnnotation,
45
53
  GeneratorAnnotationId: () => GeneratorAnnotationId,
46
54
  HiddenAnnotation: () => HiddenAnnotation,
@@ -98,4 +106,4 @@ export {
98
106
  setDictionary2 as setDictionary,
99
107
  Annotation_exports
100
108
  };
101
- //# sourceMappingURL=chunk-3PBP4V4O.mjs.map
109
+ //# sourceMappingURL=chunk-JZ6LFQU5.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/Annotation.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nexport {\n DescriptionAnnotation,\n FieldLookupAnnotationId,\n FormInputAnnotation,\n FormInlineAnnotation,\n FormOrderedAnnotation,\n FormLayoutAnnotation,\n FormLayoutAnnotationId,\n type FormLayoutMap,\n DEFAULT_LAYOUT_NAME,\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;oBAAAA;EAAA;;;;;;;;;;;aAAAC;EAAA;;;;;aAAAC;EAAA;uBAAAC;EAAA,kBAAAC;EAAA;;;;aAAAC;EAAA;uBAAAC;EAAA;;AAmCA,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;",
6
+ "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"]
7
+ }
@@ -6,14 +6,14 @@ import {
6
6
  } from "./chunk-TFEWTY5A.mjs";
7
7
  import {
8
8
  createEchoReferenceSchema
9
- } from "./chunk-WTQJHC75.mjs";
9
+ } from "./chunk-4TPQZPLY.mjs";
10
10
  import {
11
11
  GeneratorAnnotationId,
12
12
  LabelAnnotationId,
13
13
  PropertyMetaAnnotationId,
14
14
  TypeAnnotationId,
15
15
  TypeIdentifierAnnotationId
16
- } from "./chunk-R5W6DXR4.mjs";
16
+ } from "./chunk-WZ32BF53.mjs";
17
17
  import {
18
18
  ANY_OBJECT_TYPENAME,
19
19
  ANY_OBJECT_VERSION,
@@ -744,4 +744,4 @@ export {
744
744
  toJsonSchema,
745
745
  toEffectSchema
746
746
  };
747
- //# sourceMappingURL=chunk-7PI7C4EF.mjs.map
747
+ //# sourceMappingURL=chunk-K3S7D5PR.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Ref
3
- } from "./chunk-WTQJHC75.mjs";
3
+ } from "./chunk-4TPQZPLY.mjs";
4
4
 
5
5
  // src/internal/Ref/ref-array.ts
6
6
  import { isNonNullable } from "@dxos/util";
@@ -31,4 +31,4 @@ var RefArray = Object.freeze({
31
31
  export {
32
32
  RefArray
33
33
  };
34
- //# sourceMappingURL=chunk-5SUJPHAE.mjs.map
34
+ //# sourceMappingURL=chunk-L3OBWBV2.mjs.map
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  isRef
3
- } from "./chunk-MZ7K3MLL.mjs";
3
+ } from "./chunk-TF5BSLF6.mjs";
4
4
  import {
5
5
  prettyFilter
6
- } from "./chunk-7FPIAJIV.mjs";
6
+ } from "./chunk-VQYL2OQF.mjs";
7
7
  import {
8
8
  getTypeURIFromSpecifier,
9
9
  getUri
10
- } from "./chunk-R5W6DXR4.mjs";
10
+ } from "./chunk-WZ32BF53.mjs";
11
11
  import {
12
12
  __export
13
13
  } from "./chunk-J5LGTIGS.mjs";
@@ -343,4 +343,4 @@ export {
343
343
  pretty,
344
344
  Filter_exports
345
345
  };
346
- //# sourceMappingURL=chunk-6YDI3J37.mjs.map
346
+ //# sourceMappingURL=chunk-NOL7O3BL.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  JsonSchemaType,
3
3
  toEffectSchema,
4
4
  toJsonSchema
5
- } from "./chunk-7PI7C4EF.mjs";
5
+ } from "./chunk-K3S7D5PR.mjs";
6
6
  import {
7
7
  __export
8
8
  } from "./chunk-J5LGTIGS.mjs";
@@ -24,4 +24,4 @@ export {
24
24
  JsonSchema,
25
25
  JsonSchema_exports
26
26
  };
27
- //# sourceMappingURL=chunk-IGK6FN65.mjs.map
27
+ //# sourceMappingURL=chunk-PLDMJJJC.mjs.map
@@ -2,10 +2,10 @@ import {
2
2
  Kind,
3
3
  KindId,
4
4
  SnapshotKindId
5
- } from "./chunk-SBVFRTST.mjs";
5
+ } from "./chunk-Z3WMRRAZ.mjs";
6
6
  import {
7
7
  getSchema
8
- } from "./chunk-T6E37YIP.mjs";
8
+ } from "./chunk-HGWQR5KH.mjs";
9
9
  import {
10
10
  VersionTypeId,
11
11
  change,
@@ -21,14 +21,14 @@ import {
21
21
  sortByTypename,
22
22
  subscribe,
23
23
  version
24
- } from "./chunk-7FPIAJIV.mjs";
24
+ } from "./chunk-VQYL2OQF.mjs";
25
25
  import {
26
26
  addTag,
27
27
  deleteKeys,
28
28
  getKeys,
29
29
  getMetaChecked,
30
30
  removeTag
31
- } from "./chunk-4ZUHOTCG.mjs";
31
+ } from "./chunk-X3NUUON4.mjs";
32
32
  import {
33
33
  ATTR_RELATION_SOURCE,
34
34
  ATTR_RELATION_TARGET,
@@ -51,7 +51,7 @@ import {
51
51
  isInstanceOf,
52
52
  setDescription,
53
53
  setLabel
54
- } from "./chunk-R5W6DXR4.mjs";
54
+ } from "./chunk-WZ32BF53.mjs";
55
55
  import {
56
56
  ANY_OBJECT_TYPENAME,
57
57
  ANY_OBJECT_VERSION,
@@ -278,4 +278,4 @@ export {
278
278
  atom,
279
279
  Relation_exports
280
280
  };
281
- //# sourceMappingURL=chunk-LWXVKPPW.mjs.map
281
+ //# sourceMappingURL=chunk-SZ5WB6HF.mjs.map
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  RefArray
3
- } from "./chunk-5SUJPHAE.mjs";
3
+ } from "./chunk-L3OBWBV2.mjs";
4
4
  import {
5
5
  Ref,
6
6
  getSchemaReference
7
- } from "./chunk-WTQJHC75.mjs";
7
+ } from "./chunk-4TPQZPLY.mjs";
8
8
  import {
9
9
  __export
10
10
  } from "./chunk-J5LGTIGS.mjs";
@@ -45,4 +45,4 @@ export {
45
45
  isRefType,
46
46
  Ref_exports
47
47
  };
48
- //# sourceMappingURL=chunk-MZ7K3MLL.mjs.map
48
+ //# sourceMappingURL=chunk-TF5BSLF6.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/Ref.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport type * as internal from './internal';\nimport * as refInternal from './internal/Ref';\nimport type * as JsonSchema from './JsonSchema';\nimport type * as Obj from './Obj';\n// eslint-disable-next-line @dxos/rules/import-as-namespace\nimport type * as Type$ from './Type';\n\n/**\n * Instance type for a reference.\n *\n * Reference can point to any object or relation.\n * References are lazy loaded.\n *\n * `ref.dxn` is the DXN of the referenced object.\n *\n * @example\n * ```ts\n * const taskRef: Ref<Task> = Ref.make(task);\n *\n * await taskRef.load(); // Returns Promise<Task>\n * yield* Database.load(taskRef); // Effectful version.\n *\n * database.makeRef(dxn); // Create a ref from a DXN.\n * ```\n */\nexport type Ref<T> = refInternal.Ref<T>;\nexport type Unknown = refInternal.Ref<Obj.Unknown>;\n\n/**\n * Factory function to create a Ref schema for the given target schema.\n * Use this in schema definitions to declare reference fields.\n *\n * @example\n * ```ts\n * const Task = Schema.Struct({\n * assignee: Ref.Ref(Person), // Creates a Ref schema\n * }).pipe(Type.makeObject(DXN.make('com.example.type.task', '0.1.0')));\n * ```\n */\nexport const Ref: {\n <S extends Type$.AnyObj | Type$.AnyRelation>(type: S): RefSchema<Type$.InstanceType<S> & Obj.Unknown>;\n\n // `Type.Type` entities (the meta-schema kind) can be referenced too — e.g. a\n // trigger that points to a stored function/workflow definition.\n <T extends Type$.Type<any>>(type: T): RefSchema<Type$.InstanceType<T>>;\n\n // Schema-side overload for the well-known \"any object\" / \"any relation\" schemas.\n // Other raw `Schema.Schema` values are intentionally rejected — callers should\n // pass a `Type.Type` entity instead.\n <S extends internal.UnknownTypeSchema<any, any>>(schema: S): RefSchema<Schema.Schema.Type<S> & Obj.Unknown>;\n} = refInternal.Ref as any;\n\nexport const Array = refInternal.RefArray;\n\n/**\n * TypeScript type for a Ref schema.\n * This is the type of the SCHEMA itself, not the runtime ref instance.\n * For the instance type, use `Ref.Ref<T>` from the Ref module.\n *\n * @example\n * ```ts\n * // Schema type annotation (rarely needed, usually inferred):\n * const refSchema: Ref.RefSchema<typeof Task> = Ref.Ref(Task);\n *\n * // Instance type annotation (use Ref.Ref instead):\n * const refInstance: Ref.Ref<Task> = Ref.make(task);\n * ```\n */\n// TODO(dmaretskyi): Investigate if we can remove this type.\n// Post DX-836 it will become just `Schema.Schema<Ref.Ref<T>>`.\n// NOTE: This could be Type.Ref<T> instead, but since it going to be removed, it's better to keep it here, self-contained.\nexport interface RefSchema<T extends Entity.Unknown> extends refInternal.RefSchema<T> {}\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Unknown> = R extends refInternal.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = refInternal.RefResolver;\n\nexport const isRef: (value: unknown) => value is Unknown = refInternal.Ref.isRef;\n\nexport const make = refInternal.Ref.make;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept URI.\nexport const fromURI = (uri: URI.URI): refInternal.Ref<any> => refInternal.Ref.fromURI(uri);\n\nexport const hasEntityId = refInternal.Ref.hasEntityId;\n\n// TODO(wittjosiah): Factor out?\nexport const isRefType = (ast: SchemaAST.AST): boolean => {\n return SchemaAST.getAnnotation<JsonSchema.JsonSchema>(ast, SchemaAST.JSONSchemaAnnotationId).pipe(\n Option.flatMap((jsonSchema) => ('$id' in jsonSchema ? Option.some(jsonSchema) : Option.none())),\n Option.flatMap((jsonSchema) => {\n const { typename } = refInternal.getSchemaReference(jsonSchema) ?? {};\n return typename ? Option.some(true) : Option.some(false);\n }),\n Option.getOrElse(() => false),\n );\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;AAAA;;;aAAAA;EAAA;;;;;;AAMA,YAAYC,YAAY;AAExB,YAAYC,eAAe;AA4CpB,IAAMC,OAWGA;AAET,IAAMC,QAAoBC;AA+B1B,IAAMC,QAA0DH,IAAIG;AAEpE,IAAMC,OAAmBJ,IAAII;AAG7B,IAAMC,UAAU,CAACC,QAAmDN,IAAIK,QAAQC,GAAAA;AAEhF,IAAMC,cAA0BP,IAAIO;AAGpC,IAAMC,YAAY,CAACC,QAAAA;AACxB,SAAiBC,wBAAqCD,KAAeE,gCAAsB,EAAEC,KACpFC,eAAQ,CAACC,eAAgB,SAASA,aAAoBC,YAAKD,UAAAA,IAAqBE,YAAI,CAAA,GACpFH,eAAQ,CAACC,eAAAA;AACd,UAAM,EAAEG,SAAQ,IAAiBC,mBAAmBJ,UAAAA,KAAe,CAAC;AACpE,WAAOG,WAAkBF,YAAK,IAAA,IAAeA,YAAK,KAAA;EACpD,CAAA,GACOI,iBAAU,MAAM,KAAA,CAAA;AAE3B;",
6
+ "names": ["Ref", "Option", "SchemaAST", "Ref", "Array", "RefArray", "isRef", "make", "fromURI", "uri", "hasEntityId", "isRefType", "ast", "getAnnotation", "JSONSchemaAnnotationId", "pipe", "flatMap", "jsonSchema", "some", "none", "typename", "getSchemaReference", "getOrElse"]
7
+ }
@@ -3,20 +3,20 @@ import {
3
3
  JsonSchemaType,
4
4
  toEffectSchema,
5
5
  toJsonSchema
6
- } from "./chunk-7PI7C4EF.mjs";
6
+ } from "./chunk-K3S7D5PR.mjs";
7
7
  import {
8
8
  ATTR_META,
9
9
  EntityMetaSchema,
10
10
  getMeta,
11
11
  isEntity
12
- } from "./chunk-4ZUHOTCG.mjs";
12
+ } from "./chunk-X3NUUON4.mjs";
13
13
  import {
14
14
  Ref,
15
15
  RefTypeId,
16
16
  loadRefTarget,
17
17
  refFromEncodedReference,
18
18
  setRefResolver
19
- } from "./chunk-WTQJHC75.mjs";
19
+ } from "./chunk-4TPQZPLY.mjs";
20
20
  import {
21
21
  ATTR_DELETED,
22
22
  ATTR_PARENT,
@@ -57,7 +57,7 @@ import {
57
57
  setSchema,
58
58
  setType,
59
59
  setTypename
60
- } from "./chunk-R5W6DXR4.mjs";
60
+ } from "./chunk-WZ32BF53.mjs";
61
61
  import {
62
62
  EntityKind,
63
63
  KindId,
@@ -104,6 +104,59 @@ var sort = (...comparators) => {
104
104
  };
105
105
  };
106
106
 
107
+ // src/internal/Ref/strong-deps.ts
108
+ import { EID } from "@dxos/keys";
109
+ var getStrongDependencyUris = (refs, owningSpaceId) => {
110
+ const res = [];
111
+ if (refs.type != null && EID.tryParse(refs.type) != null) {
112
+ res.push(qualifyToSpace(refs.type, owningSpaceId));
113
+ }
114
+ if (refs.kind === EntityKind.Relation) {
115
+ if (refs.source != null) {
116
+ res.push(qualifyToSpace(refs.source, owningSpaceId));
117
+ }
118
+ if (refs.target != null) {
119
+ res.push(qualifyToSpace(refs.target, owningSpaceId));
120
+ }
121
+ }
122
+ if (refs.parent != null) {
123
+ res.push(qualifyToSpace(refs.parent, owningSpaceId));
124
+ }
125
+ return res;
126
+ };
127
+ var qualifyToSpace = (uri, owningSpaceId) => {
128
+ if (owningSpaceId == null) {
129
+ return uri;
130
+ }
131
+ const eid = EID.tryParse(uri);
132
+ if (eid == null || !EID.isLocal(eid)) {
133
+ return uri;
134
+ }
135
+ const entityId = EID.getEntityId(eid);
136
+ return entityId != null ? EID.make({
137
+ spaceId: owningSpaceId,
138
+ entityId
139
+ }) : uri;
140
+ };
141
+ var getStrongDependencies = (entity) => {
142
+ if (entity == null || typeof entity !== "object") {
143
+ return [];
144
+ }
145
+ const props = entity;
146
+ const kind = props[RelationSourceDXNId] != null || props[RelationTargetDXNId] != null ? EntityKind.Relation : EntityKind.Object;
147
+ const parent = props[ParentId];
148
+ const selfUri = getObjectEchoUri(entity);
149
+ const owningSpaceId = selfUri != null ? EID.getSpaceId(selfUri) : void 0;
150
+ return getStrongDependencyUris({
151
+ kind,
152
+ type: typeof props[TypeId] === "string" ? props[TypeId] : void 0,
153
+ source: props[RelationSourceDXNId],
154
+ target: props[RelationTargetDXNId],
155
+ // A parent is held as the resolved entity; derive its absolute URI for the dependency edge.
156
+ parent: parent != null ? getObjectEchoUri(parent) : void 0
157
+ }, owningSpaceId);
158
+ };
159
+
107
160
  // src/internal/common/proxy/symbols.ts
108
161
  var EventId = /* @__PURE__ */ Symbol.for("@dxos/live-object/EventId");
109
162
  var ChangeId = /* @__PURE__ */ Symbol.for("@dxos/live-object/ChangeId");
@@ -209,7 +262,7 @@ var createArrayMethodError = (method) => {
209
262
 
210
263
  // src/internal/common/proxy/json-serializer.ts
211
264
  import { invariant } from "@dxos/invariant";
212
- import { EID } from "@dxos/keys";
265
+ import { EID as EID2 } from "@dxos/keys";
213
266
  import { deepMapValues, encodeUint8ArrayToJson } from "@dxos/util";
214
267
  var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/json-serializer.ts";
215
268
  var attachTypedJsonSerializer = (obj) => {
@@ -241,12 +294,12 @@ var typedJsonSerializer = function() {
241
294
  }
242
295
  if (this[RelationSourceDXNId]) {
243
296
  const sourceDXN = this[RelationSourceDXNId];
244
- invariant(EID.isEID(sourceDXN), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 44, S: this, A: ["EID.isEID(sourceDXN)", ""] });
297
+ invariant(EID2.isEID(sourceDXN), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 44, S: this, A: ["EID.isEID(sourceDXN)", ""] });
245
298
  result[ATTR_RELATION_SOURCE] = sourceDXN;
246
299
  }
247
300
  if (this[RelationTargetDXNId]) {
248
301
  const targetDXN = this[RelationTargetDXNId];
249
- invariant(EID.isEID(targetDXN), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 49, S: this, A: ["EID.isEID(targetDXN)", ""] });
302
+ invariant(EID2.isEID(targetDXN), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 49, S: this, A: ["EID.isEID(targetDXN)", ""] });
250
303
  result[ATTR_RELATION_TARGET] = targetDXN;
251
304
  }
252
305
  Object.assign(result, serializeData(rest));
@@ -1491,7 +1544,7 @@ import * as Schema9 from "effect/Schema";
1491
1544
  import { raise as raise2 } from "@dxos/debug";
1492
1545
  import { EntityStructure, isEncodedReference } from "@dxos/echo-protocol";
1493
1546
  import { assertArgument as assertArgument4, invariant as invariant9 } from "@dxos/invariant";
1494
- import { EID as EID2, EntityId as EntityId3, URI } from "@dxos/keys";
1547
+ import { EID as EID3, EntityId as EntityId3, URI } from "@dxos/keys";
1495
1548
  import { assumeType, decodeUint8ArrayFromJson, deepMapValues as deepMapValues2, isEncodedUint8Array, visitValues } from "@dxos/util";
1496
1549
  var __dxlog_file9 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/json-serializer.ts";
1497
1550
  var objectToJSON = (obj) => {
@@ -1534,8 +1587,8 @@ var objectFromJSON = async (jsonData, { refResolver, uri, database, parent } = {
1534
1587
  if (isRelation) {
1535
1588
  const sourceDxn = jsonData[ATTR_RELATION_SOURCE] ?? raise2(new TypeError("Missing relation source"));
1536
1589
  const targetDxn = jsonData[ATTR_RELATION_TARGET] ?? raise2(new TypeError("Missing relation target"));
1537
- const source = await refResolver?.resolve(sourceDxn);
1538
- const target = await refResolver?.resolve(targetDxn);
1590
+ const source = await refResolver?.resolveLegacy(sourceDxn);
1591
+ const target = await refResolver?.resolveLegacy(targetDxn);
1539
1592
  defineHiddenProperty(obj, KindId, EntityKind.Relation);
1540
1593
  defineHiddenProperty(obj, RelationSourceDXNId, sourceDxn);
1541
1594
  defineHiddenProperty(obj, RelationTargetDXNId, targetDxn);
@@ -1558,7 +1611,7 @@ var objectFromJSON = async (jsonData, { refResolver, uri, database, parent } = {
1558
1611
  }
1559
1612
  if (jsonData[ATTR_PARENT]) {
1560
1613
  const parentDxn = jsonData[ATTR_PARENT];
1561
- const resolvedParent = await refResolver?.resolve(parentDxn);
1614
+ const resolvedParent = await refResolver?.resolveLegacy(parentDxn);
1562
1615
  defineHiddenProperty(obj, ParentId, resolvedParent);
1563
1616
  } else if (parent) {
1564
1617
  defineHiddenProperty(obj, ParentId, parent);
@@ -1632,9 +1685,9 @@ var objectStructureToJson = (objectId, structure) => {
1632
1685
  id: objectId,
1633
1686
  [ATTR_TYPE]: typeRef ? URI.make(typeRef) : void 0,
1634
1687
  [ATTR_DELETED]: EntityStructure.isDeleted(structure),
1635
- [ATTR_PARENT]: parent !== void 0 ? EID2.tryParse(parent) : void 0,
1636
- [ATTR_RELATION_SOURCE]: source !== void 0 ? EID2.tryParse(source) : void 0,
1637
- [ATTR_RELATION_TARGET]: target !== void 0 ? EID2.tryParse(target) : void 0
1688
+ [ATTR_PARENT]: parent !== void 0 ? EID3.tryParse(parent) : void 0,
1689
+ [ATTR_RELATION_SOURCE]: source !== void 0 ? EID3.tryParse(source) : void 0,
1690
+ [ATTR_RELATION_TARGET]: target !== void 0 ? EID3.tryParse(target) : void 0
1638
1691
  };
1639
1692
  };
1640
1693
 
@@ -1983,6 +2036,24 @@ var makeRelation = (relation) => {
1983
2036
  assertArgument7(isEntity(relation), "relation", "Must be a reactive ECHO relation");
1984
2037
  return relationFamily(relation);
1985
2038
  };
2039
+ var labelAtomFamily = Atom.family((entity) => {
2040
+ return Atom.make((get) => {
2041
+ let previous = getLabel(entity);
2042
+ const unsubscribe = subscribe(entity, () => {
2043
+ const next = getLabel(entity);
2044
+ if (next !== previous) {
2045
+ previous = next;
2046
+ get.setSelf(next);
2047
+ }
2048
+ });
2049
+ get.addFinalizer(() => unsubscribe());
2050
+ return previous;
2051
+ }).pipe(Atom.keepAlive);
2052
+ });
2053
+ var makeLabelAtom = (entity) => {
2054
+ assertArgument7(isEntity(entity), "entity", "Must be a reactive ECHO entity");
2055
+ return labelAtomFamily(entity);
2056
+ };
1986
2057
 
1987
2058
  // src/internal/Obj/clone.ts
1988
2059
  import { invariant as invariant11 } from "@dxos/invariant";
@@ -2203,6 +2274,8 @@ export {
2203
2274
  sortByLabel,
2204
2275
  sortByTypename,
2205
2276
  sort,
2277
+ getStrongDependencyUris,
2278
+ getStrongDependencies,
2206
2279
  EventId,
2207
2280
  ChangeId,
2208
2281
  batchEvents,
@@ -2267,6 +2340,7 @@ export {
2267
2340
  makeWithReactive,
2268
2341
  makeEntity,
2269
2342
  makeRelation,
2343
+ makeLabelAtom,
2270
2344
  clone,
2271
2345
  prettyFilter,
2272
2346
  prettyQuery,
@@ -2276,4 +2350,4 @@ export {
2276
2350
  updateFieldNameInSchema,
2277
2351
  TypeSchema
2278
2352
  };
2279
- //# sourceMappingURL=chunk-7FPIAJIV.mjs.map
2353
+ //# sourceMappingURL=chunk-VQYL2OQF.mjs.map