@dxos/echo 0.8.2 → 0.8.3-main.672df60

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.
package/README.md CHANGED
@@ -117,18 +117,22 @@ Obj.fromJSON(json, { graph, db });
117
117
 
118
118
  Defines attributes and encoding placed on objects.
119
119
 
120
- | | Optional | Runtime prop | Runtime type | JSON prop | JSON type | Description |
121
- | ---------------- | ---------------------- | ----------------------------------- | ---------------------- | --------------------------- | --------- | ------------------------------------ |
122
- | Id | No | `id` | `ObjectID` ULID string | `id` | string | Unique object ID |
123
- | Self DXN | Yes | `Symbol(@dxos/echo/Self)` | `DXN` | `@self` | string | DXN to the object itself |
124
- | Typename | No | `Symbol(@dxos/echo/Typename)` | `DXN` | `@type` | string | DXN to the object type |
125
- | Tombstone marker | Yes | `Symbol(@dxos/echo/Deleted)` | `boolean` | `@deleted` | boolean | Deletion marker |
126
- | Metadata | Yes | `Symbol(@dxos/echo/Meta)` | Metadata object | `@meta` | object | Metadata section |
127
- | Entity kind | No | `Symbol(@dxos/echo/EntityKind)` | `EntityKind` | (inferred from other props) | string | Obj vs Relation |
128
- | Relation Source | No (only on relations) | `Symbol(@dxos/echo/RelationSource)` | `DXN` | `@relationSource` | string | Relation source DXN |
129
- | Relation Target | No (only on relations) | `Symbol(@dxos/echo/RelationTarget)` | `DXN` | `@relationTarget` | string | Relation target DXN |
130
- | Hypergraph | Yes | `Symbol(@dxos/echo/Hypergraph)` | `Hypergraph` | - | - | Pointer to runtime hypergraph object |
131
- | Database | Yes | `Symbol(@dxos/echo/Database)` | `Database` | - | - | Pointer to runtime database object |
120
+ | | Optional | Runtime prop | Runtime type | JSON prop | JSON type | Description |
121
+ | ------------------- | ----------------------- | -------------------------------------- | ---------------------- | --------------------------- | ---------- | ------------------------------ |
122
+ | Id | No | `id` | `ObjectID` ULID string | `id` | string | Unique object ID |
123
+ | Self DXN | Yes | `Symbol(@dxos/echo/Self)` | `DXN` | `@self` | string | DXN to the object itself |
124
+ | Type | No | `Symbol(@dxos/echo/Type)` | `DXN` | `@type` | string | DXN to the object type |
125
+ | Schema | Yes | `Symbol(@dxos/echo/Schema)` | Effect-Schema | - | | Reference to the object schema |
126
+ | Tombstone marker | Yes | `Symbol(@dxos/echo/Deleted)` | `boolean` | `@deleted` | boolean | Deletion marker |
127
+ | Metadata | Yes | `Symbol(@dxos/echo/Meta)` | Metadata object | `@meta` | object | Metadata section |
128
+ | Entity kind | No | `Symbol(@dxos/echo/EntityKind)` | `EntityKind` | (inferred from other props) | string | Obj vs Relation |
129
+ | Relation Source DXN | No (only on relations) | `Symbol(@dxos/echo/RelationSourceDXN)` | `DXN` | `@relationSource` | DXN string | Relation source DXN |
130
+ | Relation Target DXN | No (only on relations) | `Symbol(@dxos/echo/RelationTargetDXN)` | `DXN` | `@relationTarget` | DXN string | Relation target DXN |
131
+ | Relation Source | Yes (only on relations) | `Symbol(@dxos/echo/RelationSource)` | `Object` | - | | Relation source object |
132
+ | Relation Target | Yes (only on relations) | `Symbol(@dxos/echo/RelationTarget)` | `Object` | - | | Relation target object |
133
+
134
+ > NOTE: All of the API functions can return `undefined` since they are also designed to work with objects outside of the database.
135
+ > TODO: Consider how Database, Hypergraph, and RefResolver are attached to the object.
132
136
 
133
137
  ### Value representation
134
138
 
@@ -78,15 +78,18 @@ var isMutable2 = (schema) => {
78
78
  // packages/core/echo/echo/src/Obj.ts
79
79
  var Obj_exports = {};
80
80
  __export(Obj_exports, {
81
- getDXN: () => getDXN3,
81
+ fromJSON: () => fromJSON,
82
+ getDXN: () => getDXN2,
83
+ getLabel: () => getLabel2,
82
84
  getMeta: () => getMeta3,
83
85
  getSchema: () => getSchema2,
84
86
  getSchemaDXN: () => getSchemaDXN2,
85
- getTypename: () => getTypename3,
87
+ getTypename: () => getTypename2,
86
88
  instanceOf: () => instanceOf,
87
89
  isDeleted: () => isDeleted2,
88
90
  isObject: () => isObject,
89
- make: () => make
91
+ make: () => make,
92
+ toJSON: () => toJSON
90
93
  });
91
94
  import { Schema } from "effect";
92
95
  import * as EchoSchema2 from "@dxos/echo-schema";
@@ -104,12 +107,12 @@ var instanceOf = (...args) => {
104
107
  return EchoSchema2.isInstanceOf(args[0], args[1]);
105
108
  };
106
109
  var getSchema2 = EchoSchema2.getSchema;
107
- var getDXN3 = (obj) => {
110
+ var getDXN2 = (obj) => {
108
111
  assertArgument(!Schema.isSchema(obj), "Object should not be a schema.");
109
- const dxn = EchoSchema2.getDXN(obj);
112
+ const dxn = EchoSchema2.getObjectDXN(obj);
110
113
  invariant2(dxn != null, "Invalid object.", {
111
114
  F: __dxlog_file2,
112
- L: 48,
115
+ L: 50,
113
116
  S: void 0,
114
117
  A: [
115
118
  "dxn != null",
@@ -122,7 +125,7 @@ var getSchemaDXN2 = (obj) => {
122
125
  const type = EchoSchema2.getType(obj);
123
126
  invariant2(type != null, "Invalid object.", {
124
127
  F: __dxlog_file2,
125
- L: 58,
128
+ L: 61,
126
129
  S: void 0,
127
130
  A: [
128
131
  "type != null",
@@ -131,18 +134,18 @@ var getSchemaDXN2 = (obj) => {
131
134
  });
132
135
  return type;
133
136
  };
134
- var getTypename3 = (obj) => {
137
+ var getTypename2 = (obj) => {
135
138
  const schema = getSchema2(obj);
136
139
  if (schema == null) {
137
140
  return getSchemaDXN2(obj)?.asTypeDXN()?.type;
138
141
  }
139
- return EchoSchema2.getTypename(schema);
142
+ return EchoSchema2.getSchemaTypename(schema);
140
143
  };
141
144
  var getMeta3 = (obj) => {
142
145
  const meta = EchoSchema2.getMeta(obj);
143
146
  invariant2(meta != null, "Invalid object.", {
144
147
  F: __dxlog_file2,
145
- L: 78,
148
+ L: 82,
146
149
  S: void 0,
147
150
  A: [
148
151
  "meta != null",
@@ -155,7 +158,7 @@ var isDeleted2 = (obj) => {
155
158
  const deleted = EchoSchema2.isDeleted(obj);
156
159
  invariant2(typeof deleted === "boolean", "Invalid object.", {
157
160
  F: __dxlog_file2,
158
- L: 84,
161
+ L: 89,
159
162
  S: void 0,
160
163
  A: [
161
164
  "typeof deleted === 'boolean'",
@@ -164,19 +167,35 @@ var isDeleted2 = (obj) => {
164
167
  });
165
168
  return deleted;
166
169
  };
170
+ var getLabel2 = (obj) => {
171
+ const schema = getSchema2(obj);
172
+ if (schema != null) {
173
+ return EchoSchema2.getLabel(schema, obj);
174
+ }
175
+ };
176
+ var toJSON = (obj) => EchoSchema2.objectToJSON(obj);
177
+ var fromJSON = EchoSchema2.objectFromJSON;
167
178
 
168
179
  // packages/core/echo/echo/src/Relation.ts
169
180
  var Relation_exports = {};
170
181
  __export(Relation_exports, {
182
+ Source: () => Source,
183
+ Target: () => Target,
171
184
  getSource: () => getSource,
185
+ getSourceDXN: () => getSourceDXN,
172
186
  getTarget: () => getTarget,
187
+ getTargetDXN: () => getTargetDXN,
173
188
  isRelation: () => isRelation,
174
189
  make: () => make2
175
190
  });
176
191
  import * as EchoSchema3 from "@dxos/echo-schema";
177
- import { invariant as invariant3 } from "@dxos/invariant";
192
+ import { assertArgument as assertArgument2, invariant as invariant3 } from "@dxos/invariant";
193
+ import { DXN as DXN2 } from "@dxos/keys";
178
194
  import * as LiveObject2 from "@dxos/live-object";
195
+ import { assumeType } from "@dxos/util";
179
196
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Relation.ts";
197
+ var Source = EchoSchema3.RelationSourceId;
198
+ var Target = EchoSchema3.RelationTargetId;
180
199
  var make2 = LiveObject2.live;
181
200
  var isRelation = (value) => {
182
201
  if (typeof value !== "object" || value === null) {
@@ -185,23 +204,45 @@ var isRelation = (value) => {
185
204
  if (EchoSchema3.ATTR_RELATION_SOURCE in value || EchoSchema3.ATTR_RELATION_TARGET in value) {
186
205
  return true;
187
206
  }
188
- const kind = value[EchoSchema3.EntityKindPropertyId];
207
+ const kind = value[EchoSchema3.EntityKindId];
189
208
  return kind === EchoSchema3.EntityKind.Relation;
190
209
  };
191
- var getSource = (relation) => {
192
- invariant3(isRelation(relation), void 0, {
210
+ var getSourceDXN = (value) => {
211
+ assertArgument2(isRelation(value), "Expected a relation");
212
+ assumeType(value);
213
+ const dxn = value[EchoSchema3.RelationSourceDXNId];
214
+ invariant3(dxn instanceof DXN2, void 0, {
215
+ F: __dxlog_file3,
216
+ L: 38,
217
+ S: void 0,
218
+ A: [
219
+ "dxn instanceof DXN",
220
+ ""
221
+ ]
222
+ });
223
+ return dxn;
224
+ };
225
+ var getTargetDXN = (value) => {
226
+ assertArgument2(isRelation(value), "Expected a relation");
227
+ assumeType(value);
228
+ const dxn = value[EchoSchema3.RelationTargetDXNId];
229
+ invariant3(dxn instanceof DXN2, void 0, {
193
230
  F: __dxlog_file3,
194
- L: 30,
231
+ L: 50,
195
232
  S: void 0,
196
233
  A: [
197
- "isRelation(relation)",
234
+ "dxn instanceof DXN",
198
235
  ""
199
236
  ]
200
237
  });
238
+ return dxn;
239
+ };
240
+ var getSource = (relation) => {
241
+ assertArgument2(isRelation(relation), "Expected a relation");
201
242
  const obj = relation[EchoSchema3.RelationSourceId];
202
243
  invariant3(obj !== void 0, `Invalid source: ${relation.id}`, {
203
244
  F: __dxlog_file3,
204
- L: 32,
245
+ L: 61,
205
246
  S: void 0,
206
247
  A: [
207
248
  "obj !== undefined",
@@ -211,19 +252,11 @@ var getSource = (relation) => {
211
252
  return obj;
212
253
  };
213
254
  var getTarget = (relation) => {
214
- invariant3(isRelation(relation), void 0, {
215
- F: __dxlog_file3,
216
- L: 41,
217
- S: void 0,
218
- A: [
219
- "isRelation(relation)",
220
- ""
221
- ]
222
- });
255
+ assertArgument2(isRelation(relation), "Expected a relation");
223
256
  const obj = relation[EchoSchema3.RelationTargetId];
224
257
  invariant3(obj !== void 0, `Invalid target: ${relation.id}`, {
225
258
  F: __dxlog_file3,
226
- L: 43,
259
+ L: 72,
227
260
  S: void 0,
228
261
  A: [
229
262
  "obj !== undefined",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/Type.ts", "../../../src/Obj.ts", "../../../src/Relation.ts", "../../../src/Ref.ts", "../../../src/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getTypename(schema);\n};\n\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport * as LiveObject from '@dxos/live-object';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindPropertyId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
5
- "mappings": ";;;;;;;;AAAA;;;;;;;;;aAAAA;EAAA;;;;;;mBAAAC;EAAA;;AAOA,YAAYC,gBAAgB;AAC5B,SAASC,iBAAiB;AAqG1B,SAAuBC,kBAAY;AASnC,SAASC,SAASC,UAAUC,WAAW;AAEvC;EAEEC;EACkBC;EAClBC;EACAC;OACK;;AA3GA,IAAMC,MAAiBC;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W,mBAAmBH,SAASI,EAAE,IAAE;;;;;;;;;AAC7D,SAAOH;AACT;AAMO,IAAMI,YAAY,CAAgBL,aAAAA;AACvCZ,EAAAA,WAAUG,WAAWS,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMC,MAAMD,SAAoBM,4BAAgB;AAChDlB,EAAAA,WAAUa,QAAQE,QAAW,mBAAmBH,SAASI,EAAE,IAAE;;;;;;;;;AAC7D,SAAOH;AACT;;;AC5CA;;;;cAAAM;;AAIA,YAAYC,iBAAgB;AAMrB,IAAMC,QAAkBC,gBAAID;AAE5B,IAAME,QAAqDD,gBAAIC;AAG/D,IAAMC,UAAqBF,gBAAIE;;;ACLtC,SAASC,QAAQC,aAAa;",
6
- "names": ["Ref", "isMutable", "EchoSchema", "invariant", "Kind", "SpaceId", "ObjectId", "DXN", "Expando", "JsonSchema", "toJsonSchema", "Format", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getDXN", "getMeta", "getSchema", "getSchemaDXN", "getTypename", "isDeleted", "Schema", "EchoSchema", "assertArgument", "invariant", "LiveObject", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "isSchema", "dxn", "type", "getType", "schema", "asTypeDXN", "meta", "deleted", "make", "EchoSchema", "invariant", "LiveObject", "live", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindPropertyId", "EntityKind", "Relation", "getSource", "relation", "obj", "RelationSourceId", "undefined", "id", "getTarget", "RelationTargetId", "make", "EchoSchema", "make", "Ref", "isRef", "fromDXN", "Filter", "Query"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Ref from './Ref';\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getObjectDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getSchemaTypename(schema);\n};\n\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\n// TODO(dmaretskyi): Default to `false`.\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n\nexport const getLabel = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n return EchoSchema.getLabel(schema, obj);\n }\n};\n\n/**\n * JSON representation of an object.\n */\nexport type JSON = EchoSchema.ObjectJSON;\n\n/**\n * Converts object to it's JSON representation.\n *\n * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.\n */\nexport const toJSON = (obj: Any): JSON => EchoSchema.objectToJSON(obj);\n\n/**\n * Creates an object from it's json representation.\n * Performs schema validation.\n * References and schema will be resolvable if the `refResolver` is provided.\n *\n * The function need to be async to support resolving the schema as well as the relation endpoints.\n */\nexport const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver }) => Promise<Any> =\n EchoSchema.objectFromJSON;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\nimport { assumeType } from '@dxos/util';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const Source = EchoSchema.RelationSourceId;\nexport const Target = EchoSchema.RelationTargetId;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source DXN.\n * @throws If the object is not a relation.\n */\nexport const getSourceDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = value[EchoSchema.RelationSourceDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation target DXN.\n * @throws If the object is not a relation.\n */\nexport const getTargetDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = value[EchoSchema.RelationTargetDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = EchoSchema.RefResolver;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
5
+ "mappings": ";;;;;;;;AAAA;;;;;;;;;aAAAA;EAAA;;;;;;mBAAAC;EAAA;;AAOA,YAAYC,gBAAgB;AAC5B,SAASC,iBAAiB;AAqG1B,SAAuBC,kBAAY;AASnC,SAASC,SAASC,UAAUC,WAAW;AAEvC;EAEEC;EACkBC;EAClBC;EACAC;OACK;;AA3GA,IAAMC,MAAiBC;AAKvB,IAAMC,WAAsBC;AAK5B,IAAMf,OAA2FA;AA4CjG,IAAMgB,SAAS,CAACC,WAAAA;AACrB,SAAkBC,wBAAaD,MAAAA;AACjC;AAMO,IAAME,cAAc,CAACF,WAAAA;AAC1B,QAAMG,WAAsBC,6BAAkBJ,MAAAA;AAC9Cd,YAAU,OAAOiB,aAAa,YAAY,CAACA,SAASE,WAAW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AAA,GAAQ,qBAAA;AAClCP,aAA2CO,KAAAA;AAC3C,QAAMQ,MAAMR,MAAiBS,+BAAmB;AAChDnB,EAAAA,WAAUkB,eAAejB,MAAAA,QAAAA;;;;;;;;;AACzB,SAAOiB;AACT;AAMO,IAAME,eAAe,CAACV,UAAAA;AAC3BX,EAAAA,gBAAeU,WAAWC,KAAAA,GAAQ,qBAAA;AAClCP,aAA2CO,KAAAA;AAC3C,QAAMQ,MAAMR,MAAiBW,+BAAmB;AAChDrB,EAAAA,WAAUkB,eAAejB,MAAAA,QAAAA;;;;;;;;;AACzB,SAAOiB;AACT;AAMO,IAAMI,YAAY,CAAgBC,aAAAA;AACvCxB,EAAAA,gBAAeU,WAAWc,QAAAA,GAAW,qBAAA;AACrC,QAAMC,MAAMD,SAAoBlB,4BAAgB;AAChDL,EAAAA,WAAUwB,QAAQC,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAOF;AACT;AAMO,IAAMG,YAAY,CAAgBJ,aAAAA;AACvCxB,EAAAA,gBAAeU,WAAWc,QAAAA,GAAW,qBAAA;AACrC,QAAMC,MAAMD,SAAoBhB,4BAAgB;AAChDP,EAAAA,WAAUwB,QAAQC,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAOF;AACT;;;ACzEA;;;;cAAAI;;AAIA,YAAYC,iBAAgB;AAMrB,IAAMC,QAAkBC,gBAAID;AAE5B,IAAME,QAAqDD,gBAAIC;AAG/D,IAAMC,UAAqBF,gBAAIE;;;ACLtC,SAASC,QAAQC,aAAa;",
6
+ "names": ["Ref", "isMutable", "EchoSchema", "invariant", "Kind", "SpaceId", "ObjectId", "DXN", "Expando", "JsonSchema", "toJsonSchema", "Format", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getDXN", "getLabel", "getMeta", "getSchema", "getSchemaDXN", "getTypename", "isDeleted", "Schema", "EchoSchema", "assertArgument", "invariant", "LiveObject", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "isSchema", "dxn", "getObjectDXN", "type", "getType", "schema", "asTypeDXN", "getSchemaTypename", "meta", "deleted", "toJSON", "objectToJSON", "fromJSON", "objectFromJSON", "make", "EchoSchema", "assertArgument", "invariant", "DXN", "LiveObject", "assumeType", "Source", "RelationSourceId", "Target", "RelationTargetId", "live", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindId", "EntityKind", "Relation", "getSourceDXN", "dxn", "RelationSourceDXNId", "getTargetDXN", "RelationTargetDXNId", "getSource", "relation", "obj", "undefined", "id", "getTarget", "make", "EchoSchema", "make", "Ref", "isRef", "fromDXN", "Filter", "Query"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":8124,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":5369,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1595,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12154},"packages/core/echo/echo/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2226},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":1700},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":6748}}}
1
+ {"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":11074,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":8382,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1707,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15270},"packages/core/echo/echo/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2553},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":2508},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":7883}}}
@@ -47,7 +47,9 @@ var import_invariant2 = require("@dxos/invariant");
47
47
  var LiveObject = __toESM(require("@dxos/live-object"));
48
48
  var EchoSchema3 = __toESM(require("@dxos/echo-schema"));
49
49
  var import_invariant3 = require("@dxos/invariant");
50
+ var import_keys2 = require("@dxos/keys");
50
51
  var LiveObject2 = __toESM(require("@dxos/live-object"));
52
+ var import_util = require("@dxos/util");
51
53
  var EchoSchema4 = __toESM(require("@dxos/echo-schema"));
52
54
  var import_echo_schema3 = require("@dxos/echo-schema");
53
55
  var __defProp2 = Object.defineProperty;
@@ -115,15 +117,18 @@ var isMutable2 = (schema) => {
115
117
  };
116
118
  var Obj_exports = {};
117
119
  __export2(Obj_exports, {
118
- getDXN: () => getDXN3,
120
+ fromJSON: () => fromJSON,
121
+ getDXN: () => getDXN2,
122
+ getLabel: () => getLabel2,
119
123
  getMeta: () => getMeta3,
120
124
  getSchema: () => getSchema2,
121
125
  getSchemaDXN: () => getSchemaDXN2,
122
- getTypename: () => getTypename3,
126
+ getTypename: () => getTypename2,
123
127
  instanceOf: () => instanceOf,
124
128
  isDeleted: () => isDeleted2,
125
129
  isObject: () => isObject,
126
- make: () => make
130
+ make: () => make,
131
+ toJSON: () => toJSON
127
132
  });
128
133
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Obj.ts";
129
134
  var make = LiveObject.live;
@@ -137,12 +142,12 @@ var instanceOf = (...args) => {
137
142
  return EchoSchema2.isInstanceOf(args[0], args[1]);
138
143
  };
139
144
  var getSchema2 = EchoSchema2.getSchema;
140
- var getDXN3 = (obj) => {
145
+ var getDXN2 = (obj) => {
141
146
  (0, import_invariant2.assertArgument)(!import_effect.Schema.isSchema(obj), "Object should not be a schema.");
142
- const dxn = EchoSchema2.getDXN(obj);
147
+ const dxn = EchoSchema2.getObjectDXN(obj);
143
148
  (0, import_invariant2.invariant)(dxn != null, "Invalid object.", {
144
149
  F: __dxlog_file2,
145
- L: 48,
150
+ L: 50,
146
151
  S: void 0,
147
152
  A: [
148
153
  "dxn != null",
@@ -155,7 +160,7 @@ var getSchemaDXN2 = (obj) => {
155
160
  const type = EchoSchema2.getType(obj);
156
161
  (0, import_invariant2.invariant)(type != null, "Invalid object.", {
157
162
  F: __dxlog_file2,
158
- L: 58,
163
+ L: 61,
159
164
  S: void 0,
160
165
  A: [
161
166
  "type != null",
@@ -164,18 +169,18 @@ var getSchemaDXN2 = (obj) => {
164
169
  });
165
170
  return type;
166
171
  };
167
- var getTypename3 = (obj) => {
172
+ var getTypename2 = (obj) => {
168
173
  const schema = getSchema2(obj);
169
174
  if (schema == null) {
170
175
  return getSchemaDXN2(obj)?.asTypeDXN()?.type;
171
176
  }
172
- return EchoSchema2.getTypename(schema);
177
+ return EchoSchema2.getSchemaTypename(schema);
173
178
  };
174
179
  var getMeta3 = (obj) => {
175
180
  const meta = EchoSchema2.getMeta(obj);
176
181
  (0, import_invariant2.invariant)(meta != null, "Invalid object.", {
177
182
  F: __dxlog_file2,
178
- L: 78,
183
+ L: 82,
179
184
  S: void 0,
180
185
  A: [
181
186
  "meta != null",
@@ -188,7 +193,7 @@ var isDeleted2 = (obj) => {
188
193
  const deleted = EchoSchema2.isDeleted(obj);
189
194
  (0, import_invariant2.invariant)(typeof deleted === "boolean", "Invalid object.", {
190
195
  F: __dxlog_file2,
191
- L: 84,
196
+ L: 89,
192
197
  S: void 0,
193
198
  A: [
194
199
  "typeof deleted === 'boolean'",
@@ -197,14 +202,28 @@ var isDeleted2 = (obj) => {
197
202
  });
198
203
  return deleted;
199
204
  };
205
+ var getLabel2 = (obj) => {
206
+ const schema = getSchema2(obj);
207
+ if (schema != null) {
208
+ return EchoSchema2.getLabel(schema, obj);
209
+ }
210
+ };
211
+ var toJSON = (obj) => EchoSchema2.objectToJSON(obj);
212
+ var fromJSON = EchoSchema2.objectFromJSON;
200
213
  var Relation_exports = {};
201
214
  __export2(Relation_exports, {
215
+ Source: () => Source,
216
+ Target: () => Target,
202
217
  getSource: () => getSource,
218
+ getSourceDXN: () => getSourceDXN,
203
219
  getTarget: () => getTarget,
220
+ getTargetDXN: () => getTargetDXN,
204
221
  isRelation: () => isRelation,
205
222
  make: () => make2
206
223
  });
207
224
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Relation.ts";
225
+ var Source = EchoSchema3.RelationSourceId;
226
+ var Target = EchoSchema3.RelationTargetId;
208
227
  var make2 = LiveObject2.live;
209
228
  var isRelation = (value) => {
210
229
  if (typeof value !== "object" || value === null) {
@@ -213,23 +232,45 @@ var isRelation = (value) => {
213
232
  if (EchoSchema3.ATTR_RELATION_SOURCE in value || EchoSchema3.ATTR_RELATION_TARGET in value) {
214
233
  return true;
215
234
  }
216
- const kind = value[EchoSchema3.EntityKindPropertyId];
235
+ const kind = value[EchoSchema3.EntityKindId];
217
236
  return kind === EchoSchema3.EntityKind.Relation;
218
237
  };
219
- var getSource = (relation) => {
220
- (0, import_invariant3.invariant)(isRelation(relation), void 0, {
238
+ var getSourceDXN = (value) => {
239
+ (0, import_invariant3.assertArgument)(isRelation(value), "Expected a relation");
240
+ (0, import_util.assumeType)(value);
241
+ const dxn = value[EchoSchema3.RelationSourceDXNId];
242
+ (0, import_invariant3.invariant)(dxn instanceof import_keys2.DXN, void 0, {
243
+ F: __dxlog_file3,
244
+ L: 38,
245
+ S: void 0,
246
+ A: [
247
+ "dxn instanceof DXN",
248
+ ""
249
+ ]
250
+ });
251
+ return dxn;
252
+ };
253
+ var getTargetDXN = (value) => {
254
+ (0, import_invariant3.assertArgument)(isRelation(value), "Expected a relation");
255
+ (0, import_util.assumeType)(value);
256
+ const dxn = value[EchoSchema3.RelationTargetDXNId];
257
+ (0, import_invariant3.invariant)(dxn instanceof import_keys2.DXN, void 0, {
221
258
  F: __dxlog_file3,
222
- L: 30,
259
+ L: 50,
223
260
  S: void 0,
224
261
  A: [
225
- "isRelation(relation)",
262
+ "dxn instanceof DXN",
226
263
  ""
227
264
  ]
228
265
  });
266
+ return dxn;
267
+ };
268
+ var getSource = (relation) => {
269
+ (0, import_invariant3.assertArgument)(isRelation(relation), "Expected a relation");
229
270
  const obj = relation[EchoSchema3.RelationSourceId];
230
271
  (0, import_invariant3.invariant)(obj !== void 0, `Invalid source: ${relation.id}`, {
231
272
  F: __dxlog_file3,
232
- L: 32,
273
+ L: 61,
233
274
  S: void 0,
234
275
  A: [
235
276
  "obj !== undefined",
@@ -239,19 +280,11 @@ var getSource = (relation) => {
239
280
  return obj;
240
281
  };
241
282
  var getTarget = (relation) => {
242
- (0, import_invariant3.invariant)(isRelation(relation), void 0, {
243
- F: __dxlog_file3,
244
- L: 41,
245
- S: void 0,
246
- A: [
247
- "isRelation(relation)",
248
- ""
249
- ]
250
- });
283
+ (0, import_invariant3.assertArgument)(isRelation(relation), "Expected a relation");
251
284
  const obj = relation[EchoSchema3.RelationTargetId];
252
285
  (0, import_invariant3.invariant)(obj !== void 0, `Invalid target: ${relation.id}`, {
253
286
  F: __dxlog_file3,
254
- L: 43,
287
+ L: 72,
255
288
  S: void 0,
256
289
  A: [
257
290
  "obj !== undefined",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/Type.ts", "../../../src/Obj.ts", "../../../src/Relation.ts", "../../../src/Ref.ts", "../../../src/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getTypename(schema);\n};\n\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport * as LiveObject from '@dxos/live-object';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindPropertyId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,iBAA4B;AAC5B,uBAA0B;AAqG1B,yBAAmC;AASnC,kB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UAAU,YAAYA,UAAU,MAAM;AAC/C,WAAO;EACT;AACA,MAAeC,YAAAA,wBAAwBD,SAAoBE,YAAAA,wBAAwBF,OAAO;AACxF,WAAO;EACT;AAEA,QAAMG,OAAQH,MAAyBI,YAAAA,oBAAoB;AAC3D,SAAOD,SAAoBE,YAAAA,WAAW1C;AACxC;AAMO,IAAM2C,YAAY,CAAgBC,aAAAA;AACvCpC,wBAAAA,WAAU4B,WAAWQ,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMvB,MAAMuB,SAAoBC,YAAAA,gBAAgB;AAChDrC,wBAAAA,WAAUa,QAAQyB,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAO1B;AACT;AAMO,IAAM2B,YAAY,CAAgBJ,aAAAA;AACvCpC,wBAAAA,WAAU4B,WAAWQ,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMvB,MAAMuB,SAAoBK,YAAAA,gBAAgB;AAChDzC,wBAAAA,WAAUa,QAAQyB,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAO1B;AACT;AC5CA,IAAA,cAAA,CAAA;;;;cAAAH;;AAUO,IAAMA,QAAkBtB,YAAAA,IAAIsB;AAE5B,IAAMgC,QAAqDtD,YAAAA,IAAIsD;AAG/D,IAAMC,UAAqBvD,YAAAA,IAAIuD;",
6
- "names": ["import_echo_schema", "import_invariant", "Ref", "isMutable", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "invariant", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getSchema", "isDeleted", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "assertArgument", "Schema", "isSchema", "dxn", "type", "getType", "asTypeDXN", "meta", "deleted", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindPropertyId", "EntityKind", "getSource", "relation", "RelationSourceId", "undefined", "id", "getTarget", "RelationTargetId", "isRef", "fromDXN"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Ref from './Ref';\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getObjectDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getSchemaTypename(schema);\n};\n\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\n// TODO(dmaretskyi): Default to `false`.\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n\nexport const getLabel = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n return EchoSchema.getLabel(schema, obj);\n }\n};\n\n/**\n * JSON representation of an object.\n */\nexport type JSON = EchoSchema.ObjectJSON;\n\n/**\n * Converts object to it's JSON representation.\n *\n * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.\n */\nexport const toJSON = (obj: Any): JSON => EchoSchema.objectToJSON(obj);\n\n/**\n * Creates an object from it's json representation.\n * Performs schema validation.\n * References and schema will be resolvable if the `refResolver` is provided.\n *\n * The function need to be async to support resolving the schema as well as the relation endpoints.\n */\nexport const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver }) => Promise<Any> =\n EchoSchema.objectFromJSON;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\nimport { assumeType } from '@dxos/util';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const Source = EchoSchema.RelationSourceId;\nexport const Target = EchoSchema.RelationTargetId;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source DXN.\n * @throws If the object is not a relation.\n */\nexport const getSourceDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = value[EchoSchema.RelationSourceDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation target DXN.\n * @throws If the object is not a relation.\n */\nexport const getTargetDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = value[EchoSchema.RelationTargetDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = EchoSchema.RefResolver;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,iBAA4B;AAC5B,uBAA0B;AAqG1B,yBAAmC;AASnC,kBAAuC;AAEvC,IAAAA,sBAMO;AC1HP,oBAAuB;AAEvB,kBAA4B;AAC5B,IAAAC,oBAA0C;AAE1C,iBAA4B;ACL5B,kBAA4B;AAC5B,IAAAA,oBAA0C;AAC1C,IAA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;AACrC,QAAMtC,MAAMsC,SAAoBf,YAAAA,gBAAgB;AAChDrC,wBAAAA,WAAUc,QAAQuC,QAAW,mBAAmBD,SAASE,EAAE,IAAE;;;;;;;;;AAC7D,SAAOxC;AACT;ACzEA,IAAA,cAAA,CAAA;;;;cAAAH;;AAUO,IAAMA,QAAkBvB,YAAAA,IAAIuB;AAE5B,IAAM6C,QAAqDpE,YAAAA,IAAIoE;AAG/D,IAAMC,UAAqBrE,YAAAA,IAAIqE;",
6
+ "names": ["import_echo_schema", "import_invariant", "import_keys", "Ref", "isMutable", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "invariant", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getLabel", "getSchema", "isDeleted", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "assertArgument", "Schema", "isSchema", "dxn", "getObjectDXN", "type", "getType", "asTypeDXN", "meta", "deleted", "toJSON", "objectToJSON", "fromJSON", "objectFromJSON", "Source", "RelationSourceId", "Target", "RelationTargetId", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindId", "EntityKind", "getSourceDXN", "assumeType", "RelationSourceDXNId", "DXN", "getTargetDXN", "RelationTargetDXNId", "getSource", "relation", "undefined", "id", "getTarget", "isRef", "fromDXN"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":8124,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":5369,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1595,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12153},"packages/core/echo/echo/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2226},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":1700},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":6715}}}
1
+ {"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":11074,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":8382,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1707,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15269},"packages/core/echo/echo/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2553},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":2508},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":7850}}}
@@ -78,15 +78,18 @@ var isMutable2 = (schema) => {
78
78
  // packages/core/echo/echo/src/Obj.ts
79
79
  var Obj_exports = {};
80
80
  __export(Obj_exports, {
81
- getDXN: () => getDXN3,
81
+ fromJSON: () => fromJSON,
82
+ getDXN: () => getDXN2,
83
+ getLabel: () => getLabel2,
82
84
  getMeta: () => getMeta3,
83
85
  getSchema: () => getSchema2,
84
86
  getSchemaDXN: () => getSchemaDXN2,
85
- getTypename: () => getTypename3,
87
+ getTypename: () => getTypename2,
86
88
  instanceOf: () => instanceOf,
87
89
  isDeleted: () => isDeleted2,
88
90
  isObject: () => isObject,
89
- make: () => make
91
+ make: () => make,
92
+ toJSON: () => toJSON
90
93
  });
91
94
  import { Schema } from "effect";
92
95
  import * as EchoSchema2 from "@dxos/echo-schema";
@@ -104,12 +107,12 @@ var instanceOf = (...args) => {
104
107
  return EchoSchema2.isInstanceOf(args[0], args[1]);
105
108
  };
106
109
  var getSchema2 = EchoSchema2.getSchema;
107
- var getDXN3 = (obj) => {
110
+ var getDXN2 = (obj) => {
108
111
  assertArgument(!Schema.isSchema(obj), "Object should not be a schema.");
109
- const dxn = EchoSchema2.getDXN(obj);
112
+ const dxn = EchoSchema2.getObjectDXN(obj);
110
113
  invariant2(dxn != null, "Invalid object.", {
111
114
  F: __dxlog_file2,
112
- L: 48,
115
+ L: 50,
113
116
  S: void 0,
114
117
  A: [
115
118
  "dxn != null",
@@ -122,7 +125,7 @@ var getSchemaDXN2 = (obj) => {
122
125
  const type = EchoSchema2.getType(obj);
123
126
  invariant2(type != null, "Invalid object.", {
124
127
  F: __dxlog_file2,
125
- L: 58,
128
+ L: 61,
126
129
  S: void 0,
127
130
  A: [
128
131
  "type != null",
@@ -131,18 +134,18 @@ var getSchemaDXN2 = (obj) => {
131
134
  });
132
135
  return type;
133
136
  };
134
- var getTypename3 = (obj) => {
137
+ var getTypename2 = (obj) => {
135
138
  const schema = getSchema2(obj);
136
139
  if (schema == null) {
137
140
  return getSchemaDXN2(obj)?.asTypeDXN()?.type;
138
141
  }
139
- return EchoSchema2.getTypename(schema);
142
+ return EchoSchema2.getSchemaTypename(schema);
140
143
  };
141
144
  var getMeta3 = (obj) => {
142
145
  const meta = EchoSchema2.getMeta(obj);
143
146
  invariant2(meta != null, "Invalid object.", {
144
147
  F: __dxlog_file2,
145
- L: 78,
148
+ L: 82,
146
149
  S: void 0,
147
150
  A: [
148
151
  "meta != null",
@@ -155,7 +158,7 @@ var isDeleted2 = (obj) => {
155
158
  const deleted = EchoSchema2.isDeleted(obj);
156
159
  invariant2(typeof deleted === "boolean", "Invalid object.", {
157
160
  F: __dxlog_file2,
158
- L: 84,
161
+ L: 89,
159
162
  S: void 0,
160
163
  A: [
161
164
  "typeof deleted === 'boolean'",
@@ -164,19 +167,35 @@ var isDeleted2 = (obj) => {
164
167
  });
165
168
  return deleted;
166
169
  };
170
+ var getLabel2 = (obj) => {
171
+ const schema = getSchema2(obj);
172
+ if (schema != null) {
173
+ return EchoSchema2.getLabel(schema, obj);
174
+ }
175
+ };
176
+ var toJSON = (obj) => EchoSchema2.objectToJSON(obj);
177
+ var fromJSON = EchoSchema2.objectFromJSON;
167
178
 
168
179
  // packages/core/echo/echo/src/Relation.ts
169
180
  var Relation_exports = {};
170
181
  __export(Relation_exports, {
182
+ Source: () => Source,
183
+ Target: () => Target,
171
184
  getSource: () => getSource,
185
+ getSourceDXN: () => getSourceDXN,
172
186
  getTarget: () => getTarget,
187
+ getTargetDXN: () => getTargetDXN,
173
188
  isRelation: () => isRelation,
174
189
  make: () => make2
175
190
  });
176
191
  import * as EchoSchema3 from "@dxos/echo-schema";
177
- import { invariant as invariant3 } from "@dxos/invariant";
192
+ import { assertArgument as assertArgument2, invariant as invariant3 } from "@dxos/invariant";
193
+ import { DXN as DXN2 } from "@dxos/keys";
178
194
  import * as LiveObject2 from "@dxos/live-object";
195
+ import { assumeType } from "@dxos/util";
179
196
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Relation.ts";
197
+ var Source = EchoSchema3.RelationSourceId;
198
+ var Target = EchoSchema3.RelationTargetId;
180
199
  var make2 = LiveObject2.live;
181
200
  var isRelation = (value) => {
182
201
  if (typeof value !== "object" || value === null) {
@@ -185,23 +204,45 @@ var isRelation = (value) => {
185
204
  if (EchoSchema3.ATTR_RELATION_SOURCE in value || EchoSchema3.ATTR_RELATION_TARGET in value) {
186
205
  return true;
187
206
  }
188
- const kind = value[EchoSchema3.EntityKindPropertyId];
207
+ const kind = value[EchoSchema3.EntityKindId];
189
208
  return kind === EchoSchema3.EntityKind.Relation;
190
209
  };
191
- var getSource = (relation) => {
192
- invariant3(isRelation(relation), void 0, {
210
+ var getSourceDXN = (value) => {
211
+ assertArgument2(isRelation(value), "Expected a relation");
212
+ assumeType(value);
213
+ const dxn = value[EchoSchema3.RelationSourceDXNId];
214
+ invariant3(dxn instanceof DXN2, void 0, {
215
+ F: __dxlog_file3,
216
+ L: 38,
217
+ S: void 0,
218
+ A: [
219
+ "dxn instanceof DXN",
220
+ ""
221
+ ]
222
+ });
223
+ return dxn;
224
+ };
225
+ var getTargetDXN = (value) => {
226
+ assertArgument2(isRelation(value), "Expected a relation");
227
+ assumeType(value);
228
+ const dxn = value[EchoSchema3.RelationTargetDXNId];
229
+ invariant3(dxn instanceof DXN2, void 0, {
193
230
  F: __dxlog_file3,
194
- L: 30,
231
+ L: 50,
195
232
  S: void 0,
196
233
  A: [
197
- "isRelation(relation)",
234
+ "dxn instanceof DXN",
198
235
  ""
199
236
  ]
200
237
  });
238
+ return dxn;
239
+ };
240
+ var getSource = (relation) => {
241
+ assertArgument2(isRelation(relation), "Expected a relation");
201
242
  const obj = relation[EchoSchema3.RelationSourceId];
202
243
  invariant3(obj !== void 0, `Invalid source: ${relation.id}`, {
203
244
  F: __dxlog_file3,
204
- L: 32,
245
+ L: 61,
205
246
  S: void 0,
206
247
  A: [
207
248
  "obj !== undefined",
@@ -211,19 +252,11 @@ var getSource = (relation) => {
211
252
  return obj;
212
253
  };
213
254
  var getTarget = (relation) => {
214
- invariant3(isRelation(relation), void 0, {
215
- F: __dxlog_file3,
216
- L: 41,
217
- S: void 0,
218
- A: [
219
- "isRelation(relation)",
220
- ""
221
- ]
222
- });
255
+ assertArgument2(isRelation(relation), "Expected a relation");
223
256
  const obj = relation[EchoSchema3.RelationTargetId];
224
257
  invariant3(obj !== void 0, `Invalid target: ${relation.id}`, {
225
258
  F: __dxlog_file3,
226
- L: 43,
259
+ L: 72,
227
260
  S: void 0,
228
261
  A: [
229
262
  "obj !== undefined",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/Type.ts", "../../../src/Obj.ts", "../../../src/Relation.ts", "../../../src/Ref.ts", "../../../src/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getTypename(schema);\n};\n\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport * as LiveObject from '@dxos/live-object';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindPropertyId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n invariant(isRelation(relation));\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
5
- "mappings": ";;;;;;;;AAAA;;;;;;;;;aAAAA;EAAA;;;;;;mBAAAC;EAAA;;AAOA,YAAYC,gBAAgB;AAC5B,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A;AACvCZ,EAAAA,WAAUG,WAAWS,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMC,MAAMD,SAAoBE,4BAAgB;AAChDd,EAAAA,WAAUa,QAAQE,QAAW,mBAAmBH,SAASI,EAAE,IAAE;;;;;;;;;AAC7D,SAAOH;AACT;AAMO,IAAMI,YAAY,CAAgBL,aAAAA;AACvCZ,EAAAA,WAAUG,WAAWS,QAAAA,GAAAA,QAAAA;;;;;;;;;AACrB,QAAMC,MAAMD,SAAoBM,4BAAgB;AAChDlB,EAAAA,WAAUa,QAAQE,QAAW,mBAAmBH,SAASI,EAAE,IAAE;;;;;;;;;AAC7D,SAAOH;AACT;;;AC5CA;;;;cAAAM;;AAIA,YAAYC,iBAAgB;AAMrB,IAAMC,QAAkBC,gBAAID;AAE5B,IAAME,QAAqDD,gBAAIC;AAG/D,IAAMC,UAAqBF,gBAAIE;;;ACLtC,SAASC,QAAQC,aAAa;",
6
- "names": ["Ref", "isMutable", "EchoSchema", "invariant", "Kind", "SpaceId", "ObjectId", "DXN", "Expando", "JsonSchema", "toJsonSchema", "Format", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getDXN", "getMeta", "getSchema", "getSchemaDXN", "getTypename", "isDeleted", "Schema", "EchoSchema", "assertArgument", "invariant", "LiveObject", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "isSchema", "dxn", "type", "getType", "schema", "asTypeDXN", "meta", "deleted", "make", "EchoSchema", "invariant", "LiveObject", "live", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindPropertyId", "EntityKind", "Relation", "getSource", "relation", "obj", "RelationSourceId", "undefined", "id", "getTarget", "RelationTargetId", "make", "EchoSchema", "make", "Ref", "isRef", "fromDXN", "Filter", "Query"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport type { EncodedReference } from '@dxos/echo-protocol';\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport type * as Keys from '@dxos/keys';\n\n/**\n * ECHO schema.\n */\nexport type Schema = EchoSchema.EchoSchema;\n\n/**\n * EchoObject schema.\n */\nexport const Obj = EchoSchema.EchoObject;\n\n/**\n * EchoRelation schema.\n */\nexport const Relation = EchoSchema.EchoRelation;\n\n/**\n * Ref schema.\n */\nexport const Ref: <S extends Obj.Any>(schema: S) => EchoSchema.Ref$<Schema.Schema.Type<S>> = EchoSchema.Ref;\n\nexport namespace Obj {\n /**\n * Type that represents an arbitrary schema type of an object.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n}\n\nexport namespace Relation {\n /**\n * Type that represents an arbitrary schema type of a relation.\n * NOTE: This is not an instance type.\n */\n // TODO(dmaretskyi): If schema was covariant, we could specify props in here, like `id: ObjectId`.\n export type Any = Schema.Schema.AnyNoContext;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends EchoSchema.RelationSourceTargetRefs<infer T, infer _S> ? T : never;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends EchoSchema.RelationSourceTargetRefs<infer _T, infer S> ? S : never;\n}\n\nexport namespace Ref {\n /**\n * Type that represents an arbitrary schema type of a reference.\n * NOTE: This is not an instance type.\n */\n export type Any = Schema.Schema<EchoSchema.Ref<any>, EncodedReference>;\n}\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Obj.Any | Relation.Any): Keys.DXN | undefined => {\n return EchoSchema.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Obj.Any | Relation.Any): string => {\n const typename = EchoSchema.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Obj.Any | Relation.Any): string => {\n const version = EchoSchema.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = EchoSchema.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Obj.Any | Relation.Any): Meta | undefined => {\n return EchoSchema.getTypeAnnotation(schema);\n};\n\nexport { EntityKind as Kind } from '@dxos/echo-schema';\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = (schema: Obj.Any | Relation.Any): boolean => {\n return EchoSchema.isMutable(schema);\n};\n\nexport { SpaceId, ObjectId, DXN } from '@dxos/keys';\n\nexport {\n //\n Expando,\n JsonSchemaType as JsonSchema,\n toJsonSchema,\n Format,\n} from '@dxos/echo-schema';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\n\nimport type * as Ref from './Ref';\nimport type * as Type from './Type';\n\nexport type Any = EchoSchema.AnyEchoObject;\n\nexport const make = LiveObject.live;\n\n// TODO(dmaretskyi): Currently broken\nexport const isObject = (obj: unknown): obj is Any => {\n return LiveObject.isLiveObject(obj);\n};\n\n/**\n * Check that object or relation is an instance of a schema.\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * isPerson(person); // true\n * ```\n */\nexport const instanceOf: {\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is S;\n <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is S;\n} = ((...args: any[]) => {\n if (args.length === 1) {\n return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);\n }\n\n return EchoSchema.isInstanceOf(args[0], args[1]);\n}) as any;\n\nexport const getSchema = EchoSchema.getSchema;\n\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getDXN = (obj: Any): DXN => {\n assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');\n const dxn = EchoSchema.getObjectDXN(obj);\n invariant(dxn != null, 'Invalid object.');\n return dxn;\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Contact:1.0.0\n */\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getSchemaDXN = (obj: Any): DXN => {\n const type = EchoSchema.getType(obj);\n invariant(type != null, 'Invalid object.');\n return type;\n};\n\n/**\n * @returns The typename of the object's type.\n * @example `example.com/type/Contact`\n */\nexport const getTypename = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema == null) {\n // Try to extract typename from DXN.\n return getSchemaDXN(obj)?.asTypeDXN()?.type;\n }\n\n return EchoSchema.getSchemaTypename(schema);\n};\n\n// TODO(dmaretskyi): Allow returning undefined.\nexport const getMeta = (obj: Any): EchoSchema.ObjectMeta => {\n const meta = EchoSchema.getMeta(obj);\n invariant(meta != null, 'Invalid object.');\n return meta;\n};\n\n// TODO(dmaretskyi): Default to `false`.\nexport const isDeleted = (obj: Any): boolean => {\n const deleted = EchoSchema.isDeleted(obj);\n invariant(typeof deleted === 'boolean', 'Invalid object.');\n return deleted;\n};\n\nexport const getLabel = (obj: Any): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n return EchoSchema.getLabel(schema, obj);\n }\n};\n\n/**\n * JSON representation of an object.\n */\nexport type JSON = EchoSchema.ObjectJSON;\n\n/**\n * Converts object to it's JSON representation.\n *\n * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.\n */\nexport const toJSON = (obj: Any): JSON => EchoSchema.objectToJSON(obj);\n\n/**\n * Creates an object from it's json representation.\n * Performs schema validation.\n * References and schema will be resolvable if the `refResolver` is provided.\n *\n * The function need to be async to support resolving the schema as well as the relation endpoints.\n */\nexport const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver }) => Promise<Any> =\n EchoSchema.objectFromJSON;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport * as LiveObject from '@dxos/live-object';\nimport { assumeType } from '@dxos/util';\n\nexport type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;\n\nexport const Source = EchoSchema.RelationSourceId;\nexport const Target = EchoSchema.RelationTargetId;\n\nexport const make = LiveObject.live;\n\nexport const isRelation = (value: unknown): value is Any => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n const kind = (value as any)[EchoSchema.EntityKindId];\n return kind === EchoSchema.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source DXN.\n * @throws If the object is not a relation.\n */\nexport const getSourceDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = value[EchoSchema.RelationSourceDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation target DXN.\n * @throws If the object is not a relation.\n */\nexport const getTargetDXN = (value: Any): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<EchoSchema.InternalObjectProps>(value);\n const dxn = value[EchoSchema.RelationTargetDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation source.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n const obj = relation[EchoSchema.RelationSourceId];\n invariant(obj !== undefined, `Invalid source: ${relation.id}`);\n return obj;\n};\n\n/**\n * @returns Relation target.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n const obj = relation[EchoSchema.RelationTargetId];\n invariant(obj !== undefined, `Invalid target: ${relation.id}`);\n return obj;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as EchoSchema from '@dxos/echo-schema';\n\nimport type * as Obj from './Obj';\n\nexport type Any = EchoSchema.Ref<Obj.Any>;\n\nexport const make = EchoSchema.Ref.make;\n\nexport const isRef: (value: unknown) => value is Any = EchoSchema.Ref.isRef;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = EchoSchema.Ref.fromDXN;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = EchoSchema.RefResolver;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Type from './Type';\nexport * as Obj from './Obj';\nexport * as Relation from './Relation';\nexport * as Ref from './Ref';\n\nexport { type Live } from '@dxos/live-object';\nexport { Filter, Query } from '@dxos/echo-schema';\n"],
5
+ "mappings": ";;;;;;;;AAAA;;;;;;;;;aAAAA;EAAA;;;;;;mBAAAC;EAAA;;AAOA,YAAYC,gBAAgB;AAC5B,SAASC,iBAAiB;AAqG1B,SAAuBC,kBAAY;AASnC,SAASC,SAASC,UAAUC,WAAW;AAEvC;EAEEC;EACkBC;EAClBC;EACAC;OACK;;AA3GA,IAAMC,MAAiBC;AAKvB,IAAMC,WAAsBC;AAK5B,IAAMf,OAA2FA;AA4CjG,IAAMgB,SAAS,CAACC,WAAAA;AACrB,SAAkBC,wBAAaD,MAAA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,QAAMG,OAAQH,MAAyBI,wBAAY;AACnD,SAAOD,SAAoBE,uBAAWC;AACxC;AAMO,IAAMC,eAAe,CAACP,UAAAA;AAC3BX,EAAAA,gBAAeU,WAAWC,KAAAA,GAAQ,qBAAA;AAClCP,aAA2CO,KAAAA;AAC3C,QAAMQ,MAAMR,MAAiBS,+BAAmB;AAChDnB,EAAAA,WAAUkB,eAAejB,MAAAA,QAAAA;;;;;;;;;AACzB,SAAOiB;AACT;AAMO,IAAME,eAAe,CAACV,UAAAA;AAC3BX,EAAAA,gBAAeU,WAAWC,KAAAA,GAAQ,qBAAA;AAClCP,aAA2CO,KAAAA;AAC3C,QAAMQ,MAAMR,MAAiBW,+BAAmB;AAChDrB,EAAAA,WAAUkB,eAAejB,MAAAA,QAAAA;;;;;;;;;AACzB,SAAOiB;AACT;AAMO,IAAMI,YAAY,CAAgBC,aAAAA;AACvCxB,EAAAA,gBAAeU,WAAWc,QAAAA,GAAW,qBAAA;AACrC,QAAMC,MAAMD,SAAoBlB,4BAAgB;AAChDL,EAAAA,WAAUwB,QAAQC,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAOF;AACT;AAMO,IAAMG,YAAY,CAAgBJ,aAAAA;AACvCxB,EAAAA,gBAAeU,WAAWc,QAAAA,GAAW,qBAAA;AACrC,QAAMC,MAAMD,SAAoBhB,4BAAgB;AAChDP,EAAAA,WAAUwB,QAAQC,QAAW,mBAAmBF,SAASG,EAAE,IAAE;;;;;;;;;AAC7D,SAAOF;AACT;;;ACzEA;;;;cAAAI;;AAIA,YAAYC,iBAAgB;AAMrB,IAAMC,QAAkBC,gBAAID;AAE5B,IAAME,QAAqDD,gBAAIC;AAG/D,IAAMC,UAAqBF,gBAAIE;;;ACLtC,SAASC,QAAQC,aAAa;",
6
+ "names": ["Ref", "isMutable", "EchoSchema", "invariant", "Kind", "SpaceId", "ObjectId", "DXN", "Expando", "JsonSchema", "toJsonSchema", "Format", "Obj", "EchoObject", "Relation", "EchoRelation", "getDXN", "schema", "getSchemaDXN", "getTypename", "typename", "getSchemaTypename", "startsWith", "getVersion", "version", "getSchemaVersion", "match", "getMeta", "getTypeAnnotation", "getDXN", "getLabel", "getMeta", "getSchema", "getSchemaDXN", "getTypename", "isDeleted", "Schema", "EchoSchema", "assertArgument", "invariant", "LiveObject", "make", "live", "isObject", "obj", "isLiveObject", "instanceOf", "args", "length", "isInstanceOf", "isSchema", "dxn", "getObjectDXN", "type", "getType", "schema", "asTypeDXN", "getSchemaTypename", "meta", "deleted", "toJSON", "objectToJSON", "fromJSON", "objectFromJSON", "make", "EchoSchema", "assertArgument", "invariant", "DXN", "LiveObject", "assumeType", "Source", "RelationSourceId", "Target", "RelationTargetId", "live", "isRelation", "value", "ATTR_RELATION_SOURCE", "ATTR_RELATION_TARGET", "kind", "EntityKindId", "EntityKind", "Relation", "getSourceDXN", "dxn", "RelationSourceDXNId", "getTargetDXN", "RelationTargetDXNId", "getSource", "relation", "obj", "undefined", "id", "getTarget", "make", "EchoSchema", "make", "Ref", "isRef", "fromDXN", "Filter", "Query"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":8124,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":5369,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1595,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12154},"packages/core/echo/echo/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2226},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":1700},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":6807}}}
1
+ {"inputs":{"packages/core/echo/echo/src/Type.ts":{"bytes":8839,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Obj.ts":{"bytes":11074,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Relation.ts":{"bytes":8382,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/Ref.ts":{"bytes":1707,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1162,"imports":[{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"},{"path":"packages/core/echo/echo/src/Obj.ts","kind":"import-statement","original":"./Obj"},{"path":"packages/core/echo/echo/src/Relation.ts","kind":"import-statement","original":"./Relation"},{"path":"packages/core/echo/echo/src/Ref.ts","kind":"import-statement","original":"./Ref"},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":15270},"packages/core/echo/echo/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["Filter","Obj","Query","Ref","Relation","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":1927},"packages/core/echo/echo/src/index.ts":{"bytesInOutput":51},"packages/core/echo/echo/src/Obj.ts":{"bytesInOutput":2553},"packages/core/echo/echo/src/Relation.ts":{"bytesInOutput":2508},"packages/core/echo/echo/src/Ref.ts":{"bytesInOutput":276}},"bytes":7942}}}
@@ -2,6 +2,7 @@ import { Schema } from 'effect';
2
2
  import * as EchoSchema from '@dxos/echo-schema';
3
3
  import type { DXN } from '@dxos/keys';
4
4
  import * as LiveObject from '@dxos/live-object';
5
+ import type * as Ref from './Ref';
5
6
  import type * as Type from './Type';
6
7
  export type Any = EchoSchema.AnyEchoObject;
7
8
  export declare const make: {
@@ -36,4 +37,25 @@ export declare const getSchemaDXN: (obj: Any) => DXN;
36
37
  export declare const getTypename: (obj: Any) => string | undefined;
37
38
  export declare const getMeta: (obj: Any) => EchoSchema.ObjectMeta;
38
39
  export declare const isDeleted: (obj: Any) => boolean;
40
+ export declare const getLabel: (obj: Any) => string | undefined;
41
+ /**
42
+ * JSON representation of an object.
43
+ */
44
+ export type JSON = EchoSchema.ObjectJSON;
45
+ /**
46
+ * Converts object to it's JSON representation.
47
+ *
48
+ * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
49
+ */
50
+ export declare const toJSON: (obj: Any) => JSON;
51
+ /**
52
+ * Creates an object from it's json representation.
53
+ * Performs schema validation.
54
+ * References and schema will be resolvable if the `refResolver` is provided.
55
+ *
56
+ * The function need to be async to support resolving the schema as well as the relation endpoints.
57
+ */
58
+ export declare const fromJSON: (json: unknown, options?: {
59
+ refResolver?: Ref.Resolver;
60
+ }) => Promise<Any>;
39
61
  //# sourceMappingURL=Obj.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Obj.d.ts","sourceRoot":"","sources":["../../../src/Obj.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AAEpC,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC;AAE3C,eAAO,MAAM,IAAI;;;CAAkB,CAAC;AAGpC,eAAO,MAAM,QAAQ,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,GAE9C,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,EAAE;IACvB,CAAC,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;IACxF,CAAC,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,I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AQ,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC;CAO7E,CAAC;AAEV,eAAO,MAAM,SAAS,sEAAuB,CAAC;AAG9C,eAAO,MAAM,MAAM,GAAI,KAAK,GAAG,KAAG,GAKjC,CAAC;AAEF;;;GAGG;AAEH,eAAO,MAAM,YAAY,GAAI,KAAK,GAAG,KAAG,GAIvC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,GAAG,KAAG,MAAM,GAAG,SAQ/C,CAAC;AAGF,eAAO,MAAM,OAAO,GAAI,KAAK,GAAG,KAAG,UAAU,CAAC,UAI7C,CAAC;AAGF,eAAO,MAAM,SAAS,GAAI,KAAK,GAAG,KAAG,OAIpC,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,GAAG,KAAG,MAAM,GAAG,SAK5C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,GAAG,KAAG,IAAoC,CAAC;AAEvE;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAA;CAAE,KAAK,OAAO,CAAC,GAAG,CACpE,CAAC"}
@@ -8,4 +8,8 @@ export declare const fromDXN: (dxn: import("@dxos/keys").DXN) => EchoSchema.Ref<
8
8
  * Extract reference target.
9
9
  */
10
10
  export type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;
11
+ /**
12
+ * Reference resolver.
13
+ */
14
+ export type Resolver = EchoSchema.RefResolver;
11
15
  //# sourceMappingURL=Ref.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/Ref.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,KAAK,GAAG,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE1C,eAAO,MAAM,IAAI,+DAAsB,CAAC;AAExC,eAAO,MAAM,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,GAA0B,CAAC;AAG5E,eAAO,MAAM,OAAO,wDAAyB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
1
+ {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/Ref.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,KAAK,GAAG,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE1C,eAAO,MAAM,IAAI,+DAAsB,CAAC;AAExC,eAAO,MAAM,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,GAA0B,CAAC;AAG5E,eAAO,MAAM,OAAO,wDAAyB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC"}
@@ -1,11 +1,24 @@
1
1
  import * as EchoSchema from '@dxos/echo-schema';
2
+ import { DXN } from '@dxos/keys';
2
3
  import * as LiveObject from '@dxos/live-object';
3
4
  export type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;
5
+ export declare const Source: symbol;
6
+ export declare const Target: symbol;
4
7
  export declare const make: {
5
8
  <T extends EchoSchema.BaseObject>(obj: T): LiveObject.Live<T>;
6
9
  <T extends EchoSchema.BaseObject>(schema: import("effect/Schema").Schema<T, any, never>, obj: NoInfer<EchoSchema.ExcludeId<T>>, meta?: EchoSchema.ObjectMeta): LiveObject.Live<T>;
7
10
  };
8
11
  export declare const isRelation: (value: unknown) => value is Any;
12
+ /**
13
+ * @returns Relation source DXN.
14
+ * @throws If the object is not a relation.
15
+ */
16
+ export declare const getSourceDXN: (value: Any) => DXN;
17
+ /**
18
+ * @returns Relation target DXN.
19
+ * @throws If the object is not a relation.
20
+ */
21
+ export declare const getTargetDXN: (value: Any) => DXN;
9
22
  /**
10
23
  * @returns Relation source.
11
24
  * @throws If the object is not a relation.
@@ -1 +1 @@
1
- {"version":3,"file":"Relation.d.ts","sourceRoot":"","sources":["../../../src/Relation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,GAAG,UAAU,CAAC,wBAAwB,CAAC;AAEjF,eAAO,MAAM,IAAI;;;CAAkB,CAAC;AAEpC,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,GAUpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,GAAG,EAAE,UAAU,CAAC,KAAG,UAAU,CAAC,cAAc,CAAC,CAAC,CAKjF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,GAAG,EAAE,UAAU,CAAC,KAAG,UAAU,CAAC,cAAc,CAAC,CAAC,CAKjF,CAAC"}
1
+ {"version":3,"file":"Relation.d.ts","sourceRoot":"","sources":["../../../src/Relation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAGhD,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,GAAG,UAAU,CAAC,wBAAwB,CAAC;AAEjF,eAAO,MAAM,MAAM,QAA8B,CAAC;AAClD,eAAO,MAAM,MAAM,QAA8B,CAAC;AAElD,eAAO,MAAM,IAAI;;;CAAkB,CAAC;AAEpC,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,GAUpD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,GAAG,KAAG,GAMzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,GAAG,KAAG,GAMzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,GAAG,EAAE,UAAU,CAAC,KAAG,UAAU,CAAC,cAAc,CAAC,CAAC,CAKjF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,GAAG,EAAE,UAAU,CAAC,KAAG,UAAU,CAAC,cAAc,CAAC,CAAC,CAKjF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo",
3
- "version": "0.8.2",
3
+ "version": "0.8.3-main.672df60",
4
4
  "description": "ECHO API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -23,17 +23,17 @@
23
23
  "dependencies": {
24
24
  "@preact/signals-core": "^1.9.0",
25
25
  "effect": "3.14.21",
26
- "@dxos/echo-schema": "0.8.2",
27
- "@dxos/debug": "0.8.2",
28
- "@dxos/echo-signals": "0.8.2",
29
- "@dxos/echo-protocol": "0.8.2",
30
- "@dxos/invariant": "0.8.2",
31
- "@dxos/effect": "0.8.2",
32
- "@dxos/live-object": "0.8.2",
33
- "@dxos/keys": "0.8.2",
34
- "@dxos/log": "0.8.2",
35
- "@dxos/node-std": "0.8.2",
36
- "@dxos/util": "0.8.2"
26
+ "@dxos/debug": "0.8.3-main.672df60",
27
+ "@dxos/echo-protocol": "0.8.3-main.672df60",
28
+ "@dxos/echo-schema": "0.8.3-main.672df60",
29
+ "@dxos/echo-signals": "0.8.3-main.672df60",
30
+ "@dxos/effect": "0.8.3-main.672df60",
31
+ "@dxos/invariant": "0.8.3-main.672df60",
32
+ "@dxos/keys": "0.8.3-main.672df60",
33
+ "@dxos/live-object": "0.8.3-main.672df60",
34
+ "@dxos/node-std": "0.8.3-main.672df60",
35
+ "@dxos/log": "0.8.3-main.672df60",
36
+ "@dxos/util": "0.8.3-main.672df60"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public"
package/src/Obj.ts CHANGED
@@ -9,6 +9,7 @@ import { assertArgument, invariant } from '@dxos/invariant';
9
9
  import type { DXN } from '@dxos/keys';
10
10
  import * as LiveObject from '@dxos/live-object';
11
11
 
12
+ import type * as Ref from './Ref';
12
13
  import type * as Type from './Type';
13
14
 
14
15
  export type Any = EchoSchema.AnyEchoObject;
@@ -42,9 +43,10 @@ export const instanceOf: {
42
43
 
43
44
  export const getSchema = EchoSchema.getSchema;
44
45
 
46
+ // TODO(dmaretskyi): Allow returning undefined.
45
47
  export const getDXN = (obj: Any): DXN => {
46
48
  assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');
47
- const dxn = EchoSchema.getDXN(obj);
49
+ const dxn = EchoSchema.getObjectDXN(obj);
48
50
  invariant(dxn != null, 'Invalid object.');
49
51
  return dxn;
50
52
  };
@@ -53,6 +55,7 @@ export const getDXN = (obj: Any): DXN => {
53
55
  * @returns The DXN of the object's type.
54
56
  * @example dxn:example.com/type/Contact:1.0.0
55
57
  */
58
+ // TODO(dmaretskyi): Allow returning undefined.
56
59
  export const getSchemaDXN = (obj: Any): DXN => {
57
60
  const type = EchoSchema.getType(obj);
58
61
  invariant(type != null, 'Invalid object.');
@@ -70,17 +73,48 @@ export const getTypename = (obj: Any): string | undefined => {
70
73
  return getSchemaDXN(obj)?.asTypeDXN()?.type;
71
74
  }
72
75
 
73
- return EchoSchema.getTypename(schema);
76
+ return EchoSchema.getSchemaTypename(schema);
74
77
  };
75
78
 
79
+ // TODO(dmaretskyi): Allow returning undefined.
76
80
  export const getMeta = (obj: Any): EchoSchema.ObjectMeta => {
77
81
  const meta = EchoSchema.getMeta(obj);
78
82
  invariant(meta != null, 'Invalid object.');
79
83
  return meta;
80
84
  };
81
85
 
86
+ // TODO(dmaretskyi): Default to `false`.
82
87
  export const isDeleted = (obj: Any): boolean => {
83
88
  const deleted = EchoSchema.isDeleted(obj);
84
89
  invariant(typeof deleted === 'boolean', 'Invalid object.');
85
90
  return deleted;
86
91
  };
92
+
93
+ export const getLabel = (obj: Any): string | undefined => {
94
+ const schema = getSchema(obj);
95
+ if (schema != null) {
96
+ return EchoSchema.getLabel(schema, obj);
97
+ }
98
+ };
99
+
100
+ /**
101
+ * JSON representation of an object.
102
+ */
103
+ export type JSON = EchoSchema.ObjectJSON;
104
+
105
+ /**
106
+ * Converts object to it's JSON representation.
107
+ *
108
+ * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
109
+ */
110
+ export const toJSON = (obj: Any): JSON => EchoSchema.objectToJSON(obj);
111
+
112
+ /**
113
+ * Creates an object from it's json representation.
114
+ * Performs schema validation.
115
+ * References and schema will be resolvable if the `refResolver` is provided.
116
+ *
117
+ * The function need to be async to support resolving the schema as well as the relation endpoints.
118
+ */
119
+ export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver }) => Promise<Any> =
120
+ EchoSchema.objectFromJSON;
package/src/Ref.ts CHANGED
@@ -19,3 +19,8 @@ export const fromDXN = EchoSchema.Ref.fromDXN;
19
19
  * Extract reference target.
20
20
  */
21
21
  export type Target<R extends Any> = R extends EchoSchema.Ref<infer T> ? T : never;
22
+
23
+ /**
24
+ * Reference resolver.
25
+ */
26
+ export type Resolver = EchoSchema.RefResolver;
package/src/Relation.ts CHANGED
@@ -3,11 +3,16 @@
3
3
  //
4
4
 
5
5
  import * as EchoSchema from '@dxos/echo-schema';
6
- import { invariant } from '@dxos/invariant';
6
+ import { assertArgument, invariant } from '@dxos/invariant';
7
+ import { DXN } from '@dxos/keys';
7
8
  import * as LiveObject from '@dxos/live-object';
9
+ import { assumeType } from '@dxos/util';
8
10
 
9
11
  export type Any = EchoSchema.AnyEchoObject & EchoSchema.RelationSourceTargetRefs;
10
12
 
13
+ export const Source = EchoSchema.RelationSourceId;
14
+ export const Target = EchoSchema.RelationTargetId;
15
+
11
16
  export const make = LiveObject.live;
12
17
 
13
18
  export const isRelation = (value: unknown): value is Any => {
@@ -18,16 +23,40 @@ export const isRelation = (value: unknown): value is Any => {
18
23
  return true;
19
24
  }
20
25
 
21
- const kind = (value as any)[EchoSchema.EntityKindPropertyId];
26
+ const kind = (value as any)[EchoSchema.EntityKindId];
22
27
  return kind === EchoSchema.EntityKind.Relation;
23
28
  };
24
29
 
30
+ /**
31
+ * @returns Relation source DXN.
32
+ * @throws If the object is not a relation.
33
+ */
34
+ export const getSourceDXN = (value: Any): DXN => {
35
+ assertArgument(isRelation(value), 'Expected a relation');
36
+ assumeType<EchoSchema.InternalObjectProps>(value);
37
+ const dxn = value[EchoSchema.RelationSourceDXNId];
38
+ invariant(dxn instanceof DXN);
39
+ return dxn;
40
+ };
41
+
42
+ /**
43
+ * @returns Relation target DXN.
44
+ * @throws If the object is not a relation.
45
+ */
46
+ export const getTargetDXN = (value: Any): DXN => {
47
+ assertArgument(isRelation(value), 'Expected a relation');
48
+ assumeType<EchoSchema.InternalObjectProps>(value);
49
+ const dxn = value[EchoSchema.RelationTargetDXNId];
50
+ invariant(dxn instanceof DXN);
51
+ return dxn;
52
+ };
53
+
25
54
  /**
26
55
  * @returns Relation source.
27
56
  * @throws If the object is not a relation.
28
57
  */
29
58
  export const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource<T> => {
30
- invariant(isRelation(relation));
59
+ assertArgument(isRelation(relation), 'Expected a relation');
31
60
  const obj = relation[EchoSchema.RelationSourceId];
32
61
  invariant(obj !== undefined, `Invalid source: ${relation.id}`);
33
62
  return obj;
@@ -38,7 +67,7 @@ export const getSource = <T extends Any>(relation: T): EchoSchema.RelationSource
38
67
  * @throws If the object is not a relation.
39
68
  */
40
69
  export const getTarget = <T extends Any>(relation: T): EchoSchema.RelationTarget<T> => {
41
- invariant(isRelation(relation));
70
+ assertArgument(isRelation(relation), 'Expected a relation');
42
71
  const obj = relation[EchoSchema.RelationTargetId];
43
72
  invariant(obj !== undefined, `Invalid target: ${relation.id}`);
44
73
  return obj;