@dxos/echo 0.9.1-main.c7dcc2e112 → 0.9.1-staging.ee54ba693a
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/dist/lib/neutral/Annotation.mjs +22 -8
- package/dist/lib/neutral/Database.mjs +3 -3
- package/dist/lib/neutral/Entity.mjs +11 -11
- package/dist/lib/neutral/Err.mjs +7 -3
- package/dist/lib/neutral/Feed.mjs +15 -19
- package/dist/lib/neutral/Filter.mjs +13 -11
- package/dist/lib/neutral/Format.mjs +3 -7
- package/dist/lib/neutral/JsonSchema.mjs +7 -7
- package/dist/lib/neutral/Migration.mjs +11 -11
- package/dist/lib/neutral/Obj.mjs +15 -13
- package/dist/lib/neutral/Order.mjs +1 -1
- package/dist/lib/neutral/Query.mjs +17 -17
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +6 -6
- package/dist/lib/neutral/Registry.mjs +1 -1
- package/dist/lib/neutral/Relation.mjs +12 -12
- package/dist/lib/neutral/Tag.mjs +15 -15
- package/dist/lib/neutral/Text.mjs +25 -0
- package/dist/lib/neutral/Text.mjs.map +7 -0
- package/dist/lib/neutral/Type.mjs +10 -10
- package/dist/lib/neutral/chunk-2HKGAQM4.mjs +1394 -0
- package/dist/lib/neutral/chunk-2HKGAQM4.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-O6BH7EPN.mjs → chunk-2ZHECXUR.mjs} +5 -4
- package/dist/lib/neutral/chunk-2ZHECXUR.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-AFANXSGV.mjs → chunk-3KTE2Y7Q.mjs} +20 -20
- package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-WZ32BF53.mjs → chunk-3TN2VMI4.mjs} +49 -37
- package/dist/lib/neutral/chunk-3TN2VMI4.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-E7IOTOZD.mjs → chunk-42L4HJ3Z.mjs} +11 -15
- package/dist/lib/neutral/chunk-42L4HJ3Z.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-K3S7D5PR.mjs → chunk-4A2NWKRJ.mjs} +5 -5
- package/dist/lib/neutral/chunk-ACFAOTKJ.mjs +1531 -0
- package/dist/lib/neutral/chunk-ACFAOTKJ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-Z3WMRRAZ.mjs → chunk-BEFR7LEA.mjs} +11 -9
- package/dist/lib/neutral/{chunk-Z3WMRRAZ.mjs.map → chunk-BEFR7LEA.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-6M2Z6WBH.mjs → chunk-BXIKXT7Q.mjs} +2 -6
- package/dist/lib/neutral/{chunk-6M2Z6WBH.mjs.map → chunk-BXIKXT7Q.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-3JXQUMUI.mjs → chunk-C57XMMBY.mjs} +21 -20
- package/dist/lib/neutral/chunk-C57XMMBY.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-JZ6LFQU5.mjs → chunk-C62JYFAD.mjs} +82 -8
- package/dist/lib/neutral/chunk-C62JYFAD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TF5BSLF6.mjs → chunk-FSGX2R62.mjs} +3 -3
- package/dist/lib/neutral/chunk-FSGX2R62.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-6CEISA3V.mjs → chunk-HBXT3GSB.mjs} +29 -15
- package/dist/lib/neutral/chunk-HBXT3GSB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-WU3GIANS.mjs → chunk-IQR45HAD.mjs} +1 -1
- package/dist/lib/neutral/chunk-IQR45HAD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TFEWTY5A.mjs → chunk-KCBW4BR6.mjs} +4 -8
- package/dist/lib/neutral/chunk-KCBW4BR6.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-4TPQZPLY.mjs → chunk-L3E5IXAE.mjs} +198 -30
- package/dist/lib/neutral/chunk-L3E5IXAE.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-EVK6XBXO.mjs → chunk-PRC4FEKJ.mjs} +2 -2
- package/dist/lib/neutral/chunk-PRC4FEKJ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-NOL7O3BL.mjs → chunk-SCT6FFCR.mjs} +9 -4
- package/dist/lib/neutral/chunk-SCT6FFCR.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-BBFJWWAV.mjs → chunk-TOCVVFK2.mjs} +26 -2
- package/dist/lib/neutral/chunk-TOCVVFK2.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-A53NTBHE.mjs → chunk-U53LSQQA.mjs} +3 -3
- package/dist/lib/neutral/{chunk-A53NTBHE.mjs.map → chunk-U53LSQQA.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-PLDMJJJC.mjs → chunk-UGFFV2FR.mjs} +2 -2
- package/dist/lib/neutral/{chunk-35INCYOE.mjs → chunk-UWLP4RFM.mjs} +1 -1
- package/dist/lib/neutral/chunk-UWLP4RFM.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-SZ5WB6HF.mjs → chunk-UZHCQ6NI.mjs} +13 -11
- package/dist/lib/neutral/{chunk-SZ5WB6HF.mjs.map → chunk-UZHCQ6NI.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-L3OBWBV2.mjs → chunk-WKIT2YY5.mjs} +2 -2
- package/dist/lib/neutral/{chunk-HGWQR5KH.mjs → chunk-XB6ISRAO.mjs} +27 -15
- package/dist/lib/neutral/chunk-XB6ISRAO.mjs.map +7 -0
- package/dist/lib/neutral/chunk-XXL42WCB.mjs +84 -0
- package/dist/lib/neutral/chunk-XXL42WCB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-5GAIWRQB.mjs → chunk-XXWK4J53.mjs} +27 -42
- package/dist/lib/neutral/chunk-XXWK4J53.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +30 -26
- package/dist/lib/neutral/internal/index.mjs +91 -69
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +79 -60
- package/dist/lib/neutral/testing/index.mjs.map +3 -3
- package/dist/types/src/Annotation.d.ts +35 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Collection.d.ts +9 -8
- package/dist/types/src/Collection.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +16 -0
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Dataset.d.ts +1 -16
- package/dist/types/src/Dataset.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +67 -0
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +56 -80
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +9 -1
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +2 -9
- package/dist/types/src/Hypergraph.d.ts.map +1 -1
- package/dist/types/src/Migration.d.ts +1 -1
- package/dist/types/src/Migration.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +31 -6
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts +1 -1
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +1 -1
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/QueryResult.d.ts +2 -2
- package/dist/types/src/QueryResult.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +8 -4
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Registry.d.ts +1 -1
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +11 -13
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Text.d.ts +41 -0
- package/dist/types/src/Text.d.ts.map +1 -0
- package/dist/types/src/Text.test.d.ts +2 -0
- package/dist/types/src/Text.test.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +33 -20
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/View.d.ts +8 -9
- package/dist/types/src/View.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +9 -0
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/atoms.d.ts +14 -0
- package/dist/types/src/internal/Annotation/atoms.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/entity-dictionary.d.ts +13 -0
- package/dist/types/src/internal/Annotation/entity-dictionary.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/guard.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/model.d.ts +1 -1
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/object.d.ts +5 -1
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/relation.d.ts +7 -0
- package/dist/types/src/internal/Entity/relation.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -1
- package/dist/types/src/internal/Filter/index.d.ts +2 -0
- package/dist/types/src/internal/Filter/index.d.ts.map +1 -0
- package/dist/types/src/internal/Filter/match.d.ts +22 -0
- package/dist/types/src/internal/Filter/match.d.ts.map +1 -0
- package/dist/types/src/internal/Format/format.d.ts +0 -2
- package/dist/types/src/internal/Format/format.d.ts.map +1 -1
- package/dist/types/src/internal/Format/index.d.ts +2 -2
- package/dist/types/src/internal/Format/index.d.ts.map +1 -1
- package/dist/types/src/internal/Format/string.d.ts +0 -8
- package/dist/types/src/internal/Format/string.d.ts.map +1 -1
- package/dist/types/src/internal/Format/types.d.ts +2 -1
- package/dist/types/src/internal/Format/types.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/atoms.d.ts +7 -3
- package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/clone.d.ts +2 -1
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/create-object.d.ts +3 -4
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/Query/index.d.ts +1 -0
- package/dist/types/src/internal/Query/index.d.ts.map +1 -1
- package/dist/types/src/internal/Query/query-result-effect.d.ts +9 -0
- package/dist/types/src/internal/Query/query-result-effect.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/atoms.d.ts +1 -2
- package/dist/types/src/internal/Ref/atoms.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref.d.ts +13 -6
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/common/atom-snapshot.d.ts +8 -0
- package/dist/types/src/internal/common/atom-snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-types.d.ts +12 -0
- package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts +25 -0
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts +5 -0
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts +17 -0
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/entity.d.ts +4 -4
- package/dist/types/src/internal/common/types/entity.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/meta.d.ts +2 -4
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +1 -0
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +42 -171
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -13
- package/src/Annotation.test.ts +257 -10
- package/src/Annotation.ts +55 -6
- package/src/Collection.ts +10 -12
- package/src/Database.ts +22 -20
- package/src/Err.ts +22 -0
- package/src/Feed.ts +114 -141
- package/src/Filter.test.ts +38 -0
- package/src/Filter.ts +17 -3
- package/src/Hypergraph.ts +2 -11
- package/src/Migration.ts +1 -1
- package/src/Obj.test.ts +92 -12
- package/src/Obj.ts +36 -5
- package/src/Order.ts +3 -3
- package/src/Query.test.ts +2 -2
- package/src/Query.ts +16 -16
- package/src/QueryResult.ts +2 -2
- package/src/Ref.ts +12 -4
- package/src/Registry.ts +1 -1
- package/src/Relation.ts +1 -1
- package/src/Tag.ts +12 -16
- package/src/Text.test.ts +186 -0
- package/src/Text.ts +116 -0
- package/src/Type.test.ts +52 -24
- package/src/Type.ts +69 -31
- package/src/View.ts +22 -30
- package/src/index.ts +1 -1
- package/src/internal/Annotation/annotations.ts +15 -2
- package/src/internal/Annotation/atoms.ts +107 -0
- package/src/internal/Annotation/entity-dictionary.ts +40 -37
- package/src/internal/Entity/api.ts +1 -1
- package/src/internal/Entity/guard.ts +2 -1
- package/src/internal/Entity/model.ts +2 -2
- package/src/internal/Entity/object.ts +14 -1
- package/src/internal/Entity/relation.ts +19 -0
- package/src/internal/Entity/type-uri.ts +3 -1
- package/src/internal/Filter/index.ts +5 -0
- package/src/internal/Filter/match.ts +284 -0
- package/src/internal/Format/format.ts +0 -2
- package/src/internal/Format/index.ts +2 -2
- package/src/internal/Format/string.ts +0 -12
- package/src/internal/Format/types.ts +4 -2
- package/src/internal/JsonSchema/json-schema.test.ts +82 -54
- package/src/internal/Obj/atoms.ts +31 -18
- package/src/internal/Obj/clone.ts +61 -20
- package/src/internal/Obj/create-object.test.ts +3 -3
- package/src/internal/Obj/create-object.ts +3 -4
- package/src/internal/Obj/inspect.ts +1 -1
- package/src/internal/Obj/json-serializer.test.ts +7 -5
- package/src/internal/Obj/json-serializer.ts +1 -1
- package/src/internal/Obj/schema-validator.test.ts +53 -0
- package/src/internal/Obj/set-value.test.ts +29 -19
- package/src/internal/Query/index.ts +1 -0
- package/src/internal/Query/query-result-effect.ts +35 -0
- package/src/internal/Ref/atoms.ts +23 -3
- package/src/internal/Ref/ref.test.ts +8 -8
- package/src/internal/Ref/ref.ts +26 -20
- package/src/internal/common/atom-snapshot.ts +19 -0
- package/src/internal/common/proxy/make-object.ts +1 -1
- package/src/internal/common/proxy/proxy-types.ts +20 -0
- package/src/internal/common/proxy/proxy-utils.ts +37 -1
- package/src/internal/common/proxy/reactive-array.ts +3 -3
- package/src/internal/common/proxy/reactive.test.ts +1 -1
- package/src/internal/common/proxy/schema-validator.ts +181 -8
- package/src/internal/common/proxy/typed-handler.ts +254 -76
- package/src/internal/common/types/entity.ts +15 -7
- package/src/internal/index.ts +1 -0
- package/src/testing/test-schema.ts +75 -90
- package/dist/lib/neutral/chunk-35INCYOE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-3JXQUMUI.mjs.map +0 -7
- package/dist/lib/neutral/chunk-4TPQZPLY.mjs.map +0 -7
- package/dist/lib/neutral/chunk-5GAIWRQB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-6CEISA3V.mjs.map +0 -7
- package/dist/lib/neutral/chunk-AFANXSGV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-E7IOTOZD.mjs.map +0 -7
- package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +0 -7
- package/dist/lib/neutral/chunk-HGWQR5KH.mjs.map +0 -7
- package/dist/lib/neutral/chunk-JZ6LFQU5.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NOL7O3BL.mjs.map +0 -7
- package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TF5BSLF6.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +0 -7
- package/dist/lib/neutral/chunk-VQYL2OQF.mjs +0 -2353
- package/dist/lib/neutral/chunk-VQYL2OQF.mjs.map +0 -7
- package/dist/lib/neutral/chunk-WU3GIANS.mjs.map +0 -7
- package/dist/lib/neutral/chunk-WZ32BF53.mjs.map +0 -7
- package/dist/lib/neutral/chunk-X3NUUON4.mjs +0 -184
- package/dist/lib/neutral/chunk-X3NUUON4.mjs.map +0 -7
- package/dist/types/src/exemplars.test.d.ts +0 -2
- package/dist/types/src/exemplars.test.d.ts.map +0 -1
- package/dist/types/src/hierarchy.test.d.ts +0 -2
- package/dist/types/src/hierarchy.test.d.ts.map +0 -1
- package/src/exemplars.test.ts +0 -21
- package/src/hierarchy.test.ts +0 -33
- /package/dist/lib/neutral/{chunk-K3S7D5PR.mjs.map → chunk-4A2NWKRJ.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-PLDMJJJC.mjs.map → chunk-UGFFV2FR.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-L3OBWBV2.mjs.map → chunk-WKIT2YY5.mjs.map} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Registry.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright 2026 DXOS.org\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\n\nimport { type ReadOnlyEvent } from '@dxos/async';\n\nimport type * as Database from './Database';\nimport * as Entity from './Entity';\nimport type * as Filter from './Filter';\nimport type * as Query from './Query';\n\n/**\n * Identifier denoting an ECHO Registry.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Registry');\nexport type TypeId = typeof TypeId;\n\n/**\n * Composable, in-memory registry of keyed ECHO entities.\n *\n * Entities are stored by id and queried via the standard ECHO Query API.\n * A registry may delegate to an optional upstream registry: results from the local\n * registry take precedence and upstream results fill in anything not found locally.\n *\n * Intended use cases include caches of schemas, operations, blueprints, routines, plugins,\n * etc., sourced from 3rd-party plugins, local code, or local space objects.\n *\n * Types (schema-definition entities produced by `Type.makeObject` / `Type.makeRelation`) are\n * stored the same way as any other entity — via `add()`. Use `list().filter(Type.isType)` to\n * retrieve them.\n *\n * Scope: a Registry is independent of any ECHO space or Hypergraph — it is a process-local,\n * in-memory cache. Wire one per space (e.g. as a Layer scoped to the space's Effect runtime)\n * or share a single instance across spaces depending on the use case.\n *\n * The concrete implementation (and the `makeRegistry` / `registryLayer` factories) lives in\n * `@dxos/echo-client`; this module declares only the interface so that the `@dxos/echo` API surface\n * stays free of query-matching dependencies.\n */\nexport interface Registry {\n readonly [TypeId]: TypeId;\n\n /**\n * Stable per-instance identifier. Used to key process-local resources (e.g. memoized\n * reactive atoms) to a specific registry instance, analogous to {@link Database.spaceId}.\n */\n readonly id: string;\n\n /**\n * Fires whenever local registry contents change (add, remove, or clear).\n */\n readonly changed: ReadOnlyEvent<void>;\n\n /**\n * All locally-stored entities.\n * Does not include upstream entities — use {@link list} for that.\n */\n readonly local: readonly Entity.Unknown[];\n\n /**\n * Add or replace one or more entities in the local registry.\n * Existing entries with the same id are replaced.\n * Also indexes type entities by DXN for fast lookup.\n */\n add(entities: readonly Entity.Unknown[]): void;\n\n /**\n * Remove an entity by id from the local registry.\n * @returns true if an entity was removed, false if it was not found.\n */\n remove(id: string): boolean;\n\n /**\n * Remove all locally-stored entities.\n * Does not affect the upstream registry.\n */\n clear(): void;\n\n /**\n * Get an entity by id.\n * Searches the local registry first, then falls back to the upstream registry.\n */\n get(id: string): Entity.Unknown | undefined;\n\n /**\n * Get an entity by one of its addressing URIs — a type entity by its typename DXN (or, when\n * persisted, its identifier EID), a keyed entity by its `dxn:<key>[:<version>]`. Accepts legacy\n * DXN forms (normalized internally). Searches the local registry first, then falls back to the\n * upstream registry. Narrow the result with `Type.isType` when a type entity is required.\n */\n getByURI(uri: string): Entity.Unknown | undefined;\n\n /**\n * List all entities.\n * Local entities take precedence over upstream entities with the same id.\n */\n list(): Entity.Unknown[];\n\n /**\n * Run an ECHO query against the registry's entities (implements {@link Database.Queryable}).\n *\n * Matching happens in-memory over {@link list}. Scope (`from`) clauses are unwrapped and\n * ignored — a direct registry query always targets the registry's own entities. The primary\n * way to query registry contents is still through the database (`db.query(...).from(Scope.registry())`),\n * which fans the database and registry together; this method is for querying a registry directly.\n *\n * Only locally-evaluable AST nodes are supported: `select`, `filter`, `limit`, `from`, `options`,\n * and boolean combinators. Server-side concerns (order, traversal, text/timestamp filters) throw.\n */\n query: Database.QueryFn;\n}\n\n/**\n * Type guard for {@link Registry}.\n */\nexport const isRegistry = (obj: unknown): obj is Registry =>\n obj != null && typeof obj === 'object' && TypeId in obj && (obj as { [TypeId]?: unknown })[TypeId] === TypeId;\n\n/**\n * Options for the registry factory (`makeRegistry` in `@dxos/echo-client`).\n */\nexport type Options = {\n /**\n * Optional upstream registry. Queries fall back to upstream when an entity\n * is not present in the local registry.\n */\n upstream?: Registry;\n\n /**\n * Initial set of entities to seed the local registry with.\n */\n initial?: readonly Entity.Unknown[];\n};\n\n/**\n * Effect Context tag for {@link Registry}.\n * Use this to inject a registry into Effect-based code.\n */\nexport class Service extends Context.Tag('@dxos/echo/Registry/Service')<Service, Registry>() {}\n\n/**\n * Executes a query against the registry and returns the results.\n * Analogous to {@link Database.query} `.run` for the in-process registry.\n */\nexport const runQuery: {\n <Q extends Query.Any>(query: Q): Effect.Effect<Query.Type<Q>[], never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<Filter.Type<F>[], never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n Effect.gen(function* () {\n const registry = yield* Service;\n return (yield* Effect.promise(() => registry.query(queryOrFilter as any).run())) as any;\n });\n"],
|
|
5
|
-
"mappings": ";;;;;AAAA;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AAYjB,IAAMC,SAASC,uBAAOC,IAAI,qBAAA;AAqG1B,IAAMC,aAAa,CAACC,QACzBA,OAAO,QAAQ,OAAOA,QAAQ,YAAYJ,UAAUI,OAAQA,IAA+BJ,MAAAA,MAAYA;AAsBlG,IAAMK,UAAN,cAA8BC,YAAI,6BAAA,EAAA,EAAA;AAAqD;AAMvF,IAAMC,WAGT,CAACC,kBACIC,WAAI,aAAA;AACT,QAAMC,WAAW,OAAOL;AACxB,SAAQ,OAAcM,eAAQ,MAAMD,SAASE,MAAMJ,aAAAA,EAAsBK,IAAG,CAAA;AAC9E,CAAA;",
|
|
6
|
-
"names": ["Context", "Effect", "TypeId", "Symbol", "for", "isRegistry", "obj", "Service", "Tag", "runQuery", "queryOrFilter", "gen", "registry", "promise", "query", "run"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Database.ts", "../../../src/internal/Entity/type-uri.ts", "../../../src/internal/Annotation/annotations.ts", "../../../src/internal/common/types/model-symbols.ts", "../../../src/internal/common/types/typename.ts", "../../../src/internal/Annotation/dictionary.ts", "../../../src/internal/Entity/api.ts", "../../../src/internal/Entity/model.ts", "../../../src/internal/Entity/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Effectable from 'effect/Effectable';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { EffectEx } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId, type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport * as Err from './Err';\nimport type * as Feed from './Feed';\nimport type * as Filter from './Filter';\nimport type * as Hypergraph from './Hypergraph';\nimport { type AnyProperties, EntityKind, KindId } from './internal/common/types';\n// Deep import (not the `./internal/Entity` barrel) to avoid a cycle:\n// Database → internal/Entity → entity → JsonSchema → Ref → Database.\nimport { isInstanceOf } from './internal/Entity/type-uri';\nimport type { Ref } from './internal/Ref/ref';\nimport type * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport type * as Registry from './Registry';\nimport type * as Type from './Type';\n\n/**\n * `query` API function declaration.\n */\n// TODO(burdon): Reconcile Query and Filter (should only have one root type).\nexport interface QueryFn {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResult<Query.Type<Q>>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResult<Filter.Type<F>>;\n}\n\n/**\n * Common interface for Database, Feed, and Hypergraph.\n */\nexport interface Queryable {\n query: QueryFn;\n}\n\nexport type GetObjectByIdOptions = {\n deleted?: boolean;\n};\n\nexport type ObjectPlacement = 'root-doc' | 'linked-doc';\n\nexport type AddOptions = {\n /**\n * Where to place the object in the Automerge document tree.\n * Root document is always loaded with the space.\n * Linked documents are loaded lazily.\n * Placing large number of objects in the root document may slow down the initial load.\n *\n * @default 'linked-doc'\n */\n placeIn?: ObjectPlacement;\n};\n\n/**\n * Rejects Type entities from {@link Database.add} at compile time via their `[KindId]` brand. Used\n * as `T & RejectTypeEntity<T>` to preserve inference of `T`. Bounding `add` on\n * `Obj.Unknown | Relation.Unknown` instead would reject broadly-typed instance adds (e.g.\n * `Entity.Any`, `Obj.OfShape<T>`), forcing casts repo-wide.\n */\nexport type RejectTypeEntity<T> = T extends { readonly [KindId]: EntityKind.Type }\n ? { __error: 'Type entities must be persisted via db.addType(), not db.add().' }\n : T;\n\nexport type FlushOptions = {\n /**\n * Write any pending changes to disk.\n * @default true\n */\n disk?: boolean;\n\n /**\n * Wait for pending index updates.\n * @default true\n */\n indexes?: boolean;\n\n /**\n * Flush pending updates to objects and queries.\n * @default false\n */\n updates?: boolean;\n};\n\n/**\n * Identifier denoting an ECHO Database.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Database');\nexport type TypeId = typeof TypeId;\n\n/**\n * ECHO Database interface.\n */\nexport interface Database extends Queryable {\n readonly [TypeId]: TypeId;\n\n get spaceId(): SpaceId;\n\n get graph(): Hypergraph.Hypergraph;\n\n /**\n * Registry for this database. Delegates type lookups to the shared hypergraph registry.\n * To persist a schema so it replicates to other clients, add the type entity with\n * {@link addType} (e.g. `await db.addType(Type.makeObjectFromJsonSchema(...))`).\n */\n readonly registry: Registry.Registry;\n\n toJSON(): object;\n\n /**\n * Return object by local ID.\n * @deprecated Use `db.query(Filter.id(id)).runSync()[0]` for a working-set lookup, or resolve via a {@link Ref}.\n */\n getObjectById<T extends Obj.Unknown = Obj.OfShape<AnyProperties>>(\n id: string,\n opts?: GetObjectByIdOptions,\n ): T | undefined;\n\n /**\n * Query objects.\n */\n query: QueryFn;\n\n /**\n * Creates a reference to an existing object in the database.\n *\n * NOTE: The reference may be dangling if the object is not present in the database.\n * NOTE: Difference from `Ref.fromURI`\n * `Ref.fromURI(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n * `db.makeRef(dxn)` is preferable in cases with access to the database.\n */\n makeRef<T extends Entity.Unknown = Entity.Unknown>(uri: URI.URI): Ref<T>;\n\n /**\n * Adds an object or relation to the database.\n *\n * Only Object and Relation entities are accepted. To persist a Type definition use\n * {@link addType} — passing a Type entity is rejected at compile time (and at runtime).\n */\n add<T extends Entity.Unknown = Entity.Unknown>(obj: T & RejectTypeEntity<T>, opts?: AddOptions): T;\n\n /**\n * Persists a Type definition (clones/forks the entity) so it replicates to other peers.\n *\n * Runs a conflict query first: if a type with the same typename + version already exists in\n * this space, the existing persisted entity is returned and no duplicate is created. This is\n * the only supported way to add Type entities — {@link add} rejects them.\n */\n addType<T extends Type.AnyEntity>(type: T): Promise<T>;\n\n /**\n * Removes object from the database.\n */\n // TODO(burdon): Return true if removed (currently throws if not present).\n remove(obj: Entity.Unknown): void;\n\n /**\n * Appends entities to a feed.\n *\n * The feed must already be stored in the database (added via {@link add}); its underlying\n * queue is addressed by the feed object's URI.\n */\n appendToFeed(feed: Feed.Feed, entities: Entity.Unknown[]): Promise<void>;\n\n /**\n * Removes entities from a feed.\n */\n deleteFromFeed(feed: Feed.Feed, entities: Entity.Unknown[]): Promise<void>;\n\n /**\n * Wait for all pending changes to be saved to disk.\n * Optionaly waits for changes to be propagated to indexes and event handlers.\n */\n flush(opts?: FlushOptions): Promise<void>;\n}\n\nexport const isDatabase = (obj: unknown): obj is Database => {\n return obj ? typeof obj === 'object' && TypeId in obj && obj[TypeId] === TypeId : false;\n};\n\nexport const Database: Schema.Schema<Database> = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));\n\n/**\n * Effect service tag for Database dependency injection.\n */\nexport class Service extends Context.Tag('@dxos/echo/Database/Service')<\n Service,\n {\n readonly db: Database;\n }\n>() {}\n\n/**\n * Layer that provides a Database service that throws when accessed.\n * Useful as a default layer when no database is available.\n */\nexport const notAvailable = Layer.succeed(Service, {\n get db(): Database {\n throw new Error('Database not available');\n },\n});\n\n/**\n * Creates a Database service instance from a Database.\n */\nexport const makeService = (db: Database): Context.Tag.Service<Service> => {\n return {\n get db() {\n return db;\n },\n };\n};\n\n/**\n * Creates a Layer that provides the Database service.\n */\nexport const layer = (db: Database): Layer.Layer<Service> => {\n return Layer.succeed(Service, makeService(db));\n};\n\n/**\n * Returns the space ID of the database.\n */\nexport const spaceId = Effect.gen(function* () {\n const { db } = yield* Service;\n return db.spaceId;\n});\n\n/**\n * Resolves an object by its DXN.\n */\nexport const resolve: {\n // No type check.\n (ref: URI.URI | Ref<any>): Effect.Effect<Entity.Unknown, never, Service>;\n // Check matches schema.\n <S extends Type.AnyEntity>(\n ref: URI.URI | Ref<any>,\n schema: S,\n ): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service>;\n} = (<S extends Type.AnyEntity>(\n ref: URI.URI | Ref<any>,\n schema?: S,\n): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service> =>\n Effect.gen(function* () {\n const { db } = yield* Service;\n const dxn = typeof ref === 'string' ? ref : ref.uri;\n const object = yield* EffectEx.promiseWithCauseCapture(() =>\n db.graph\n .createRefResolver({\n context: {\n space: db.spaceId,\n },\n })\n .resolveLegacy(dxn),\n );\n\n if (!object) {\n return yield* Effect.fail(new Err.EntityNotFoundError(dxn));\n }\n // `isInstanceOf` uses a conditional generic that TS can't resolve through\n // the local `S extends Type.AnyEntity` parameter — runtime accepts it fine.\n invariant(!schema || isInstanceOf(schema as any, object), 'Object type mismatch.');\n return object as any;\n }).pipe(Effect.withSpan('Database.resolve'))) as any;\n\n/**\n * Loads an object reference.\n *\n * Catching not found error:\n *\n * ```ts\n * yield* load(ref).pipe(Effect.catchTag('EntityNotFoundError', () => Effect.succeed(undefined)));\n * ```\n *\n */\nexport const load: <T>(ref: Ref<T>) => Effect.Effect<T, Err.EntityNotFoundError, never> = Effect.fn('Database.load')(\n function* (ref) {\n const object = yield* EffectEx.promiseWithCauseCapture(() => ref.tryLoad());\n if (!object) {\n return yield* Effect.fail(new Err.EntityNotFoundError(ref.uri));\n }\n return object;\n },\n);\n\n/**\n * Adds an object or relation to the database.\n * @see {@link Database.add}\n */\nexport const add = <T extends Entity.Unknown>(obj: T & RejectTypeEntity<T>): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.add<T>(obj))).pipe(Effect.withSpan('Database.add'));\n\n/**\n * Persists a Type definition to the database.\n * @see {@link Database.addType}\n */\nexport const addType = <T extends Type.AnyEntity>(type: T): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.addType(type)))).pipe(\n Effect.withSpan('Database.addType'),\n );\n\n/**\n * Removes an object from the database.\n * @see {@link Database.remove}\n */\nexport const remove = <T extends Entity.Unknown>(obj: T): Effect.Effect<void, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.remove(obj))).pipe(Effect.withSpan('Database.remove'));\n\n/**\n * Appends entities to a feed.\n * @see {@link Database.appendToFeed}\n */\nexport const appendToFeed = (feed: Feed.Feed, entities: Entity.Unknown[]): Effect.Effect<void, never, Service> =>\n Service.pipe(\n Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.appendToFeed(feed, entities))),\n ).pipe(Effect.withSpan('Database.appendToFeed'));\n\n/**\n * Removes entities from a feed.\n * @see {@link Database.deleteFromFeed}\n */\nexport const deleteFromFeed = (feed: Feed.Feed, entities: Entity.Unknown[]): Effect.Effect<void, never, Service> =>\n Service.pipe(\n Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.deleteFromFeed(feed, entities))),\n ).pipe(Effect.withSpan('Database.deleteFromFeed'));\n\n/**\n * Flushes pending changes to disk.\n * @see {@link Database.flush}\n */\nexport const flush = (opts?: FlushOptions) =>\n Service.pipe(Effect.flatMap(({ db }) => EffectEx.promiseWithCauseCapture(() => db.flush(opts)))).pipe(\n Effect.withSpan('Database.flush'),\n );\n\n/**\n * Creates a `QueryResult` object that can be subscribed to.\n */\nexport const query: {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResultEffect<Query.Type<Q>, never, Service>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResultEffect<Filter.Type<F>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n Service.pipe(\n Effect.map(({ db }) => db.query(queryOrFilter as any) as QueryResult.QueryResult<any>),\n Effect.withSpan('Database.query'),\n makeQueryResultEffect,\n );\n\nconst makeQueryResultEffect = <T>(\n eff: Effect.Effect<QueryResult.QueryResult<T>, never, Service>,\n): QueryResult.QueryResultEffect<T, never, Service> => {\n return {\n run: Effect.flatMap(eff, (result) => EffectEx.promiseWithCauseCapture(() => result.run())),\n first: Effect.flatMap(eff, (result) =>\n EffectEx.promiseWithCauseCapture(async () => Option.fromNullable(await result.firstOrUndefined())),\n ),\n\n // Effect internals\n ...Effectable.CommitPrototype,\n commit() {\n return eff;\n },\n } as any;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN, EID, URI } from '@dxos/keys';\n\nimport { getSchemaURI, getTypename } from '../Annotation/annotations';\nimport { type AnyEntity, InstancePhantomId, KindId, TypeId, getStaticTypeSchema } from '../common/types';\nimport { getUri as getUriFromEntity } from './api';\n\n/**\n * @param input schema, `Type.Type` entity, or a type URI (an `echo:` EID or a `dxn:` DXN).\n * @return type identifier URI — see {@link getSchemaURI}. A URI is returned verbatim. For a\n * `Type.Type` entity, the URI of the schema it declares, symmetric with what\n * `Obj.make(typeEntity, ...)` stamps on `system.type`: a static declaration resolves to its\n * typename DXN, a persisted entity to its local `echo:/<objectId>`.\n */\nexport const getTypeURIFromSpecifier = (input: Schema.Schema.All | AnyEntity | URI.URI): URI.URI => {\n if (Schema.isSchema(input)) {\n return getSchemaURI(input) ?? raise(new TypeError('Schema has no URI'));\n }\n if (typeof input === 'object' && input !== null && KindId in input) {\n // `Type.Type` entity. Both in-memory and persisted forms expose the schema\n // they declare via `StaticTypeSchemaSlot`, whose URI is exactly what\n // `Obj.make` stamps on `system.type` — a static declaration carries\n // `TypeAnnotation` (→ typename DXN), a persisted entity's rebuilt schema\n // carries `TypeIdentifierAnnotation` (→ local `echo:/<objectId>`).\n const schema = getStaticTypeSchema(input);\n if (schema != null) {\n // Static types carry TypeAnnotation → DXN; persisted db types carry\n // TypeIdentifierAnnotation → echo EID. In-memory makeObjectFromJsonSchema\n // entities have neither (plain JSON Schema), so fall through to the EID path.\n const uri = getSchemaURI(schema);\n if (uri != null) {\n return uri;\n }\n }\n return getUriFromEntity(input as AnyEntity);\n }\n // A string specifier is already a branded URI — an `echo:` EID or a `dxn:` DXN.\n assertArgument(EID.isEID(input) || DXN.isDXN(input), 'input', 'expected a type URI (EID or DXN)');\n return input;\n};\n\n/**\n * Checks if the object is an instance of the schema.\n * Only typename is compared, the schema version is ignored.\n *\n * The following cases are considered to mean that the object is an instance of the schema:\n * - Object was created with this exact schema.\n * - Object was created with a different version of this schema.\n * - Object was created with a different schema (maybe dynamic) that has the same typename.\n */\n// TODO(burdon): Can we use `Schema.is`?\nexport const isInstanceOf = <S>(\n schemaOrType: S extends Schema.Schema.AnyNoContext ? S : Schema.Schema.AnyNoContext | AnyEntity,\n object: any,\n): object is S extends Schema.Schema.AnyNoContext\n ? Schema.Schema.Type<S>\n : S extends { readonly [InstancePhantomId]?: infer A }\n ? A\n : unknown => {\n if (object == null) {\n return false;\n }\n\n const schemaURI = getTypeURIFromSpecifier(schemaOrType);\n\n // `object` is arbitrary input — read TypeId directly (it may be missing on\n // non-entities) rather than via `getTypeURI` which asserts the URI is set.\n const type = (object as any)[TypeId];\n if (URI.isURI(type) && type === schemaURI) {\n return true;\n }\n\n const typename = getTypename(object);\n if (!typename) {\n return false;\n }\n\n if (!DXN.isDXN(schemaURI)) {\n // EID-based schema URI — no typename match possible.\n return false;\n }\n\n const parsed = DXN.tryMake(schemaURI);\n return parsed != null && DXN.getName(parsed) === typename;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { SchemaEx } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, URI } from '@dxos/keys';\nimport { type Primitive } from '@dxos/util';\n\nimport type * as Annotation from '../../Annotation';\nimport { type Mutable } from '../common/proxy';\nimport { type AnyProperties, EntityKind, TypeId, getSchema } from '../common/types';\nimport { createAnnotationHelper } from './util';\n\nconst ANNOTATION_TYPE_ID: Annotation.TypeId = '~@dxos/echo/Annotation' as const;\n\n/**\n * @internal\n */\nexport const FIELD_PATH_ANNOTATION = 'path';\n\n/**\n * Sets the path for the field.\n * @param path Data source path in the json path format. This is the field path in the source object.\n */\n// TODO(burdon): Field, vs. path vs. property.\nexport const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);\n\n//\n// Type\n//\n\n/**\n * ECHO identifier (for a stored schema).\n * Must be an `echo:` URI.\n */\nexport const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');\n\nexport const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>\n Function.flow(\n SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n\n/**\n * @returns The schema's type identifier URI — whichever URI fits.\n *\n * - Stored (dynamic) schemas: the schema-as-object's EID, so loaded objects ride\n * along with their schema as a strong dependency.\n * - Non-stored (static) schemas: the typename DXN built from `TypeAnnotation`.\n *\n * This URI is what gets written to an object's `system.type`; queries that filter by\n * type also use it (see `Filter.type` / `getTypeURIFromSpecifier`), so both sides\n * stay symmetric without per-schema branching.\n */\nexport const getSchemaURI = (schema: Schema.Schema.All): URI.URI | undefined => {\n assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');\n const id = getTypeIdentifierAnnotation(schema);\n if (id) {\n return URI.make(id);\n }\n const objectAnnotation = getTypeAnnotation(schema);\n if (objectAnnotation) {\n return DXN.make(objectAnnotation.typename, objectAnnotation.version);\n }\n return undefined;\n};\n\n//\n// TypeAnnotation\n//\n\n/**\n * Fully qualified globally unique typename.\n * Example: `org.dxos.type.message`\n */\n// TODO(wittjosiah): Factor out to DXN spec.\nexport const TypenameSchema = Schema.String.pipe(\n Schema.pattern(\n /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/,\n ),\n).annotations({\n description: 'Fully qualified globally unique typename in reverse-DNS form.',\n example: 'org.dxos.type.message',\n});\n\n/**\n * Semantic version format: `major.minor.patch`\n * Example: `1.0.0`\n */\nexport const VersionSchema = Schema.String.pipe(Schema.pattern(/^\\d+.\\d+.\\d+$/)).annotations({\n description: 'Semantic version format: `major.minor.patch`',\n example: '1.0.0',\n});\n\nexport const TypeMeta = Schema.Struct({\n typename: TypenameSchema,\n version: VersionSchema,\n});\n\nexport interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}\n\n/**\n * Entity type.\n */\nexport const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');\n\n/**\n * Payload stored under {@link TypeAnnotationId}.\n */\nexport const TypeAnnotation = Schema.extend(\n TypeMeta,\n Schema.Struct({\n kind: Schema.Enums(EntityKind),\n\n /**\n * If this is a relation, the schema of the source object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n sourceSchema: Schema.optional(DXN.Schema),\n\n /**\n * If this is a relation, the schema of the target object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n targetSchema: Schema.optional(DXN.Schema),\n }),\n);\n\nexport interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}\n\n/**\n * @returns {@link TypeAnnotation} from a schema.\n * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.\n */\nexport const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {\n assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');\n return Function.flow(\n SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n};\n\n/**\n * @returns {@link EntityKind} from a schema.\n */\nexport const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;\n\n/**\n * @internal\n * @returns Schema typename (without dxn: prefix or version number).\n */\nexport const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;\n\n/**\n * @internal\n * @returns Schema version in semver format.\n */\nexport const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;\n\n/**\n * Gets the typename of the object without the version.\n * Returns only the name portion, not the DXN.\n * @example \"org.example.type.contact\"\n *\n * @internal (use Obj.getTypename)\n */\nexport const getTypename = (obj: AnyProperties): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n // Try to extract typename from DXN.\n return getSchemaTypename(schema);\n } else {\n // `obj` may be an arbitrary value (e.g. from `isInstanceOf`); read TypeId\n // directly so we return undefined for non-entities instead of throwing.\n const type = (obj as any)?.[TypeId];\n // Parse the URI string to extract typename.\n if (DXN.isDXN(type)) {\n const parsed = DXN.tryMake(type);\n return parsed && DXN.getName(parsed);\n }\n return undefined;\n }\n};\n\n/**\n * @internal (use Type.setTypename)\n */\n// TODO(dmaretskyi): Rename setTypeDXN.\nexport const setTypename = (obj: any, typename: URI.URI): void => {\n assertArgument(typeof typename === 'string', 'typename', 'Invalid type.');\n Object.defineProperty(obj, TypeId, {\n value: typename,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * @returns Object type URI — either a typename {@link DXN} or an `echo:` reference to a stored Schema object.\n * @returns undefined if the object has no registered type URI (e.g. unresolved query result).\n * @example `dxn:com.example.type.person:1.0.0`\n * @example `echo:/01KKKG2FHWCMTR0BY00GJSVT1X` (stored schema)\n *\n * @internal (use Obj.getTypeURI)\n */\nexport const getTypeURI = (obj: AnyProperties): URI.URI | undefined => {\n if (obj == null) {\n return undefined;\n }\n const type = (obj as any)[TypeId];\n if (type == null) {\n return undefined;\n }\n invariant(URI.isURI(type), 'Invalid object.');\n return type;\n};\n\n//\n// PropertyMeta\n//\n\n/**\n * PropertyMeta (metadata for dynamic schema properties).\n * For user-defined annotations.\n */\nexport const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');\n\nexport type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];\n\nexport type PropertyMetaAnnotation = {\n [name: string]: PropertyMetaValue;\n};\n\n// TODO(wittjosiah): Align with other annotations.\n// TODO(wittjosiah): Why is this separate from FormatAnnotation?\n/**\n * Apply property-level metadata to an Effect schema. Only accepts\n * `Schema.Schema.Any` — apply BEFORE wrapping the schema with\n * `Type.makeObject` / `Type.makeRelation`. To read property meta off a\n * `Type.Type` entity, unwrap it first with `Type.getSchema(entity)`.\n */\nexport const PropertyMeta = (name: string, value: PropertyMetaValue) => {\n return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {\n const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;\n return self.annotations({\n [PropertyMetaAnnotationId]: {\n ...existingMeta,\n [name]: value,\n },\n });\n };\n};\n\nexport const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>\n Function.pipe(\n SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),\n Option.map((meta) => meta[name] as T),\n Option.getOrElse(() => undefined),\n );\n\n//\n// Reference\n//\n\n/**\n * Schema reference.\n */\nexport const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');\nexport type ReferenceAnnotationValue = TypeAnnotation;\nexport const ReferenceAnnotation = createAnnotationHelper<ReferenceAnnotationValue>(ReferenceAnnotationId);\n\n/**\n * SchemaMeta.\n */\nexport const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');\nexport type SchemaMeta = TypeMeta & { id: string };\n\n/**\n * Identifies a schema as hidden from user-facing surfaces (like dotfiles — visible only via an advanced setting).\n */\nexport const HiddenAnnotationId = Symbol.for('@dxos/schema/annotation/Hidden');\nexport const HiddenAnnotation = createAnnotationHelper<boolean>(HiddenAnnotationId);\n\n/**\n * Identifies label property or JSON path expression.\n * Either a string or an array of strings representing field accessors each matched in priority order.\n */\nexport const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');\nexport const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);\n\n/**\n * Returns the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n * Skips empty strings and whitespace-only strings, continuing to the next field.\n */\n// TODO(burdon): Convert to SchemaEx.JsonPath?\nexport const getLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));\n for (const accessor of annotation) {\n assertArgument(\n typeof accessor === 'string',\n 'accessor',\n 'Label annotation must be a string or an array of strings',\n );\n const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);\n switch (typeof value) {\n case 'string': {\n const trimmed = value.trim();\n if (trimmed.length > 0) {\n return value;\n }\n continue;\n }\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n continue;\n }\n }\n\n return undefined;\n};\n\n/**\n * Sets the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n label: string,\n) => {\n const annotation = LabelAnnotation.get(schema).pipe(\n Option.map((field) => field[0]),\n Option.getOrElse(() => 'name'),\n );\n object[annotation] = label;\n};\n\n/**\n * Identifies description property or JSON path expression.\n * A string representing field accessor.\n */\nexport const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');\nexport const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);\n\n/**\n * Returns the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\n// TODO(burdon): Convert to SchemaEx.JsonPath?\nexport const getDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');\n const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n default:\n return undefined;\n }\n};\n\n/**\n * Sets the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n description: string,\n) => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n object[accessor] = description;\n};\n\n/**\n * Identifies if a property should be included in a form or not.\n * By default, all properties are included in forms, so this is opt-out.\n */\nexport const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');\nexport const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);\n\n/**\n * When set on a `Ref` property, the form renders the referenced object's own\n * fields inline (a nested form bound to the target) instead of a picker.\n */\nexport const FormInlineAnnotationId = Symbol.for('@dxos/schema/annotation/FormInline');\nexport const FormInlineAnnotation = createAnnotationHelper<boolean>(FormInlineAnnotationId);\n\n/**\n * When set on an array property, the form renders it as an ordered,\n * drag-to-reorder list (drag handles per row). Element order is meaningful and\n * user-controllable; reordering rewrites the array.\n */\nexport const FormOrderedAnnotationId = Symbol.for('@dxos/schema/annotation/FormOrdered');\nexport const FormOrderedAnnotation = createAnnotationHelper<boolean>(FormOrderedAnnotationId);\n\n/**\n * Annotation carrying one or more named layout DSL templates that control how a\n * form arranges a schema's fields (consumed by `@dxos/react-ui-form`'s\n * `Form.Layout` / `Form.FieldSet`). Callers select a variant by name; the\n * implicit name is `DEFAULT_LAYOUT_NAME` (`'default'`).\n *\n * Templates use a minimal XML grammar. Example:\n *\n * FormLayoutAnnotation.set({\n * default: `\n * <grid cols=\"2\">\n * <field name=\"origin\"/>\n * <field name=\"destination\"/>\n * <field name=\"provider\" span=\"2\"/>\n * </grid>\n * `,\n * card: `\n * <grid cols=\"1\">\n * <field name=\"provider\"/>\n * <field name=\"number\"/>\n * </grid>\n * `,\n * })\n */\nexport const FormLayoutAnnotationId = Symbol.for('@dxos/react-ui-form/annotation/Layout');\n\nexport type FormLayoutMap = Record<string, string>;\n\nexport const FormLayoutAnnotation = createAnnotationHelper<FormLayoutMap>(FormLayoutAnnotationId);\n\n/** Name used when no explicit form-layout variant is requested. */\nexport const DEFAULT_LAYOUT_NAME = 'default';\n\n/**\n * Default field to be used on referenced schema to lookup the value.\n */\nexport const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');\n\n/**\n * Generate test data.\n */\nexport const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');\n\nexport type GeneratorAnnotationValue =\n | string\n | {\n generator: string;\n args?: any[];\n probability?: number;\n };\n\nexport const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);\n\ninterface MakeAnnoationsProps<T> {\n id: string;\n schema: Schema.Schema<T, any, never>;\n}\n\n// Annotation ids use the same NSID / reverse-DNS format as TypenameSchema —\n// dot-separated segments, middle segments may be hyphenated, final segment may be camelCase.\n// At least 3 segments are required (e.g. org.dxos.annotation.example).\nexport const makeUserAnnotation = <T>(props: MakeAnnoationsProps<T>): Annotation.Annotation<T> => {\n assertArgument(\n /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){2,}(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)?$/.test(\n props.id,\n ),\n 'id',\n 'Annotation id must be in the FQN format (org.dxos.annotation.example or org.dxos.space.rootCollection).',\n );\n\n const annotation: Annotation.Annotation<T> = {\n [ANNOTATION_TYPE_ID]: { _Type: {} as T },\n key: props.id as Annotation.Key,\n schema: props.schema,\n get: (schema) => getFromAst(schema.ast, annotation),\n getFromAst: (ast) => getFromAst(ast, annotation),\n set: (value) =>\n PropertyMeta(props.id, Schema.encodeSync(props.schema)(value)) as <S extends Schema.Schema.Any>(schema: S) => S,\n };\n\n return annotation;\n};\n\nconst IconAnnotationSchema = Schema.Struct({\n /**\n * Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)\n */\n icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),\n\n /**\n * Color name.\n *\n * List of colors:\n * - 'red'\n * - 'orange'\n * - 'amber'\n * - 'yellow'\n * - 'lime'\n * - 'green'\n * - 'emerald'\n * - 'teal'\n * - 'cyan'\n * - 'violet'\n * - 'purple'\n * - 'fuchsia'\n * - 'pink'\n * - 'rose'\n */\n hue: Schema.optional(Schema.String),\n});\n\nexport interface IconAnnotation extends Schema.Schema.Type<typeof IconAnnotationSchema> {}\n\n/**\n * Icon to render in the UI.\n */\nexport const IconAnnotation = makeUserAnnotation<IconAnnotation>({\n id: 'org.dxos.annotation.icon',\n schema: IconAnnotationSchema,\n});\n\n/**\n * Indicates that this entity's icon should be resolved from a property whose value is a `Ref`\n * to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that\n * target's schema `IconAnnotation` in place of the static one declared on this schema.\n *\n * Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity\n * (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).\n */\nexport const IconFromRefAnnotation = makeUserAnnotation<string>({\n id: 'org.dxos.annotation.icon.from-ref',\n schema: Schema.String,\n});\n\n/**\n * Options for {@link getLabel}.\n */\nexport type GetLabelOptions = {\n /**\n * Strategy for deriving a label when the entity has no `LabelAnnotation` value.\n * - `'typename'`: use the entity's typename (e.g. `org.dxos.type.table`).\n * Useful for Card.Title chrome that must always display something, even\n * for unlabeled objects.\n */\n fallback?: 'typename';\n};\n\n/**\n * Get the label of an entity.\n * Accepts both reactive entities and snapshots.\n *\n * If `options.fallback === 'typename'` and no label is set, returns the\n * entity's typename instead.\n */\nexport const getLabel = (entity: AnyProperties, options?: GetLabelOptions): string | undefined => {\n const schema = getSchema(entity);\n const label = schema != null ? getLabelWithSchema(schema, entity) : undefined;\n if (label != null) {\n return label;\n }\n if (options?.fallback === 'typename') {\n return getTypename(entity);\n }\n return undefined;\n};\n\n/**\n * Set the label of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setLabel = (entity: Mutable<AnyProperties>, label: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setLabelWithSchema(schema, entity, label);\n }\n};\n\n/**\n * Returns the primary label property key for an entity.\n * Reads the first accessor from {@link LabelAnnotation}, defaulting to 'name'.\n */\nexport const getLabelProperty = (entity: AnyProperties): string => {\n const schema = getSchema(entity);\n if (schema == null) {\n return 'name';\n }\n return LabelAnnotation.get(schema).pipe(\n Option.flatMap((fields) => Option.fromNullable(fields[0])),\n Option.getOrElse(() => 'name'),\n );\n};\n\n/**\n * Get the description of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDescription = (entity: AnyProperties): string | undefined => {\n const schema = getSchema(entity);\n if (schema != null) {\n return getDescriptionWithSchema(schema, entity);\n }\n};\n\n/**\n * Get the icon annotation for an entity, resolved via its type-level `IconAnnotation`.\n * Accepts both reactive entities and snapshots.\n *\n * Returns the full `{ icon, hue }` annotation so callers can use both the phosphor icon\n * name and the suggested colour. Callers wanting just the icon name typically write\n * `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.\n *\n * Note: this is the \"static\" icon from the object's own schema. It does not follow\n * `IconFromRefAnnotation` delegation — call sites needing that (e.g. app-graph node\n * builders) should resolve the ref themselves.\n */\nexport const getIcon = (entity: AnyProperties): IconAnnotation | undefined => {\n const schema = getSchema(entity);\n if (schema == null) {\n return undefined;\n }\n return Option.getOrUndefined(IconAnnotation.get(schema));\n};\n\n/**\n * Set the description of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setDescription = (entity: Mutable<AnyProperties>, description: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setDescriptionWithSchema(schema, entity, description);\n }\n};\n\nexport { Dictionary, Key, getDictionary, setDictionary } from './dictionary';\n\nexport const getFromAst = <T>(ast: SchemaAST.AST, annotation: Annotation.Annotation<T>): Option.Option<T> => {\n return SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(\n Option.flatMap((meta) => Option.fromNullable(meta[annotation.key])),\n Option.map(Schema.decodeUnknownSync(annotation.schema)),\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(rename): These internal entity-wide symbols/types still use the `Object*` prefix but apply\n// to all entities (objects AND relations). Rename to `Entity*` in a follow-up pass (deferred from the\n// EchoURI→EID / ObjectId→EntityId / ObjectMeta→EntityMeta rename, which covered only public SDK API):\n// ObjectCore, ObjectInternals, ObjectVersion, ObjectVersionId, ObjectDeletedId, ObjectDatabaseId,\n// ObjectLoader, ObjectDocumentLoaded, ObjectUnavailable.\n// (ObjectMigration / ObjectMigrationContext intentionally excluded — object-only, not entity-wide.)\n\n/**\n * Internal symbol/string constants for the echo object model.\n * Defined in common/ so proxy/ can use them without importing from Entity/.\n * Entity/ re-exports these for external consumers.\n */\n\n/**\n * Property name for the object's own URI when serialized to JSON.\n */\nexport const ATTR_SELF_URI = '@uri';\n\n/**\n * @deprecated Legacy JSON property name accepted on read for backward compat.\n */\nexport const ATTR_SELF_URI_LEGACY = '@dxn';\n\n/**\n * Symbol carrying the object's own URI on live entities.\n */\nexport const SelfURIId = Symbol.for('@dxos/echo/URI');\n\n/**\n * Property name for deleted when object is serialized to JSON.\n */\nexport const ATTR_DELETED = '@deleted';\n\n/**\n * Deletion marker.\n */\nexport const ObjectDeletedId = Symbol.for('@dxos/echo/Deleted');\n\n/**\n * Object version accessor symbol.\n */\nexport const ObjectVersionId: unique symbol = Symbol.for('@dxos/echo/Version');\n\n/**\n * Object database accessor symbol.\n */\nexport const ObjectDatabaseId = Symbol.for('@dxos/echo/Database');\n\n/**\n * Property name for relation source when object is serialized to JSON.\n */\nexport const ATTR_RELATION_SOURCE = '@relationSource';\n\n/**\n * Used to access relation source ref on live ECHO objects.\n */\nexport const RelationSourceId: unique symbol = Symbol.for('@dxos/echo/RelationSource');\n\n/**\n * Used to access relation source DXN on live ECHO objects.\n */\nexport const RelationSourceDXNId: unique symbol = Symbol.for('@dxos/echo/RelationSourceDXN');\n\n/**\n * Property name for relation target when object is serialized to JSON.\n */\nexport const ATTR_RELATION_TARGET = '@relationTarget';\n\n/**\n * Used to access relation target ref on live ECHO objects.\n */\nexport const RelationTargetId: unique symbol = Symbol.for('@dxos/echo/RelationTarget');\n\n/**\n * Used to access relation target DXN on live ECHO objects.\n */\nexport const RelationTargetDXNId: unique symbol = Symbol.for('@dxos/echo/RelationTargetDXN');\n\n/**\n * Symbol carrying the entity metadata (EntityMeta) on live ECHO entities.\n * Must be importable by both meta.ts (which depends on the Ref schema) and\n * Entity/api.ts (which is transitively imported by the Ref schema), so it\n * cannot live in either of those files without creating an import cycle.\n */\nexport const MetaId = Symbol.for('@dxos/echo/Meta');\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\n/**\n * Property name for typename when object is serialized to JSON.\n */\nexport const ATTR_TYPE = '@type';\n\n/**\n * DXN to the object type.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Type');\n\n/**\n * Reference to the object schema.\n */\nexport const SchemaId = Symbol.for('@dxos/echo/Schema');\n\n/**\n * Property name for parent when object is serialized to JSON.\n */\nexport const ATTR_PARENT = '@parent';\n\n/**\n * Reference to the object parent.\n */\nexport const ParentId = Symbol.for('@dxos/echo/Parent');\n\n/**\n * Reference to the object's type entity (`Type.Obj`, `Type.Relation`, or\n * `Type.Type`). Set at instance creation by `createObject` / `makeObject`\n * when the entity is known. Public read-back via `Obj.getType` / `Relation.getType`\n * / `Entity.getType`.\n */\nexport const TypeEntityId = Symbol.for('@dxos/echo/TypeEntity');\n\n/**\n * Returns the Effect Schema for the given object if one is defined.\n *\n * @internal\n * Internal callers needing schema-side validation read from `SchemaId`.\n * Public callers should use `Type.getSchema(Obj.getType(obj))` instead.\n */\n// TODO(dmaretskyi): For echo objects, this always returns the root schema.\nexport const getSchema = (obj: unknown | undefined): Schema.Schema.AnyNoContext | undefined => {\n if (obj) {\n return (obj as any)[SchemaId];\n }\n};\n\n/**\n * @internal\n */\nexport const setSchema = (obj: any, schema: Schema.Schema.AnyNoContext): void => {\n Object.defineProperty(obj, SchemaId, {\n value: schema,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * Returns the type entity (`Type.AnyEntity`) for the given instance.\n * Set at instance creation; every entity has a type. Defensive: returns\n * undefined for null/undefined input so callers can safely probe arbitrary\n * values via this helper.\n *\n * @internal Re-exported via `Obj.getType` / `Relation.getType` / `Entity.getType`.\n */\nexport const getType = (obj: unknown): unknown => {\n if (obj == null) {\n return undefined;\n }\n return (obj as any)[TypeEntityId];\n};\n\n/**\n * @internal\n */\nexport const setType = (obj: any, type: unknown): void => {\n Object.defineProperty(obj, TypeEntityId, {\n value: type,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as Types from 'effect/Types';\n\nimport type * as Annotation from '../../Annotation';\n\n/**\n * Unique identifier for an annotation.\n */\nexport const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/AnnotationKey'));\nexport type Key = Schema.Schema.Type<typeof Key>;\n\n/**\n * Set of annotation values stored on entity meta or nested in schemas.\n */\nexport const Dictionary = Schema.Record({ key: Key, value: Schema.Unknown });\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a dictionary.\n */\nexport const getDictionary = <T>(\n values: Annotation.Dictionary,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (!(annotation.key in values)) {\n return Option.none();\n }\n\n return Function.pipe(values[annotation.key], Schema.decodeUnknownSync(annotation.schema), Option.some);\n};\n\n/**\n * Set the value of an annotation in a dictionary.\n */\nexport const setDictionary = <T>(\n values: Types.Mutable<Annotation.Dictionary>,\n annotation: Annotation.Annotation<T>,\n value: T,\n): void => {\n values[annotation.key] = Schema.encodeSync(annotation.schema)(value);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { DXN, EID, URI, type SpaceId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type { AnyEntity } from '../common/types';\nimport { MetaId } from '../common/types/model-symbols';\nimport { type InternalObjectProps, ObjectDatabaseId } from './model';\nimport { getObjectEchoUri } from './util';\n\n/**\n * Controls the URI form returned by `getUri` and the public `*.getURI` helpers.\n *\n * - `'named'` — Registry key URI (`dxn:<meta.key>`) when the entity has a key in its meta;\n * falls back to the default EID.\n * - `'absolute'` — Fully-qualified EID with space id (`echo://<spaceId>/<entityId>`);\n * falls back when no space is available.\n * - `'relative'` — Local EID without space id (`echo:/<entityId>`).\n *\n * Omitting `prefer` preserves the existing behaviour.\n */\nexport type GetURIOptions = {\n prefer?: 'named' | 'absolute' | 'relative';\n};\n\n/**\n * Get the URI of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getUri = (entity: AnyEntity, options?: GetURIOptions): URI.URI => {\n const prefer = options?.prefer;\n\n if (prefer === 'named') {\n const key = (entity as any)[MetaId]?.key;\n if (key) {\n return (DXN.tryMake(`dxn:${key}`) ?? URI.make(key)) as URI.URI;\n }\n const uri = getObjectEchoUri(entity);\n invariant(uri != null, 'Invalid entity.');\n return uri;\n }\n\n if (prefer === 'relative') {\n const eid = getObjectEchoUri(entity);\n invariant(eid != null, 'Invalid entity.');\n const entityId = EID.getEntityId(eid);\n return entityId ? EID.make({ entityId }) : eid;\n }\n\n if (prefer === 'absolute') {\n const eid = getObjectEchoUri(entity);\n invariant(eid != null, 'Invalid entity.');\n const entityId = EID.getEntityId(eid);\n if (!entityId) {\n return eid;\n }\n assumeType<InternalObjectProps>(entity);\n const spaceId: SpaceId | undefined = entity[ObjectDatabaseId]?.spaceId ?? EID.getSpaceId(eid);\n return spaceId ? EID.make({ spaceId, entityId }) : eid;\n }\n\n const uri = getObjectEchoUri(entity);\n invariant(uri != null, 'Invalid entity.');\n return uri;\n};\n\n/**\n * Get the database the entity belongs to.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDatabase = (entity: AnyEntity): any | undefined => {\n assumeType<InternalObjectProps>(entity);\n return entity[ObjectDatabaseId];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\nimport { type ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { EID, EntityId, type URI } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from '../../Database';\nimport {\n type ATTR_PARENT,\n type ATTR_TYPE,\n ATTR_DELETED,\n ATTR_RELATION_SOURCE,\n ATTR_RELATION_TARGET,\n ATTR_SELF_URI,\n ATTR_SELF_URI_LEGACY,\n EntityKind,\n KindId,\n ObjectDatabaseId,\n ObjectDeletedId,\n ObjectVersionId,\n type ParentId,\n RelationSourceDXNId,\n RelationSourceId,\n RelationTargetDXNId,\n RelationTargetId,\n type SchemaId,\n SelfURIId,\n TypeId,\n type Version,\n} from '../common/types';\nimport { type ATTR_META, type EntityMeta } from '../common/types/meta';\nimport { type MetaId } from '../common/types/model-symbols';\n\nexport {\n ATTR_DELETED,\n ATTR_SELF_URI,\n ATTR_SELF_URI_LEGACY,\n ObjectDatabaseId,\n ObjectDeletedId,\n ObjectVersionId,\n SelfURIId,\n};\n\n/**\n * Internal runtime representation of an object.\n * The fields are accessed through getter functions.\n */\n// NOTE: Each symbol has a jsdoc describing its purpose.\nexport interface InternalObjectProps {\n readonly id: EntityId;\n readonly [SelfURIId]: EID.EID;\n readonly [KindId]: EntityKind;\n readonly [SchemaId]: Schema.Schema.AnyNoContext;\n readonly [TypeId]: URI.URI;\n readonly [MetaId]?: EntityMeta;\n [ParentId]?: InternalObjectProps;\n readonly [ObjectDatabaseId]?: Database.Database;\n readonly [ObjectDeletedId]?: boolean;\n readonly [ObjectVersionId]?: Version;\n readonly [RelationSourceDXNId]?: EID.EID;\n readonly [RelationTargetDXNId]?: EID.EID;\n readonly [RelationSourceId]?: InternalObjectProps;\n readonly [RelationTargetId]?: InternalObjectProps;\n}\n\n/**\n * Entity metadata.\n */\nexport interface EntityMetaJSON {\n keys: ForeignKey[];\n tags?: string[];\n key?: string;\n version?: string;\n}\n\n/**\n * JSON representation of an object or relation metadata.\n */\nexport interface ObjectJSON {\n id: EntityId;\n [ATTR_TYPE]?: URI.URI;\n [ATTR_SELF_URI]?: EID.EID;\n [ATTR_PARENT]?: EID.EID; // Encoded reference\n [ATTR_DELETED]?: boolean;\n [ATTR_META]?: EntityMetaJSON;\n [ATTR_RELATION_SOURCE]?: EID.EID;\n [ATTR_RELATION_TARGET]?: EID.EID;\n\n /**\n * Application-specific properties.\n */\n [key: string]: unknown;\n}\n\n/**\n * NOTE: Keep as `function` to avoid type inference issues.\n */\nexport function assertObjectModel(obj: unknown): asserts obj is InternalObjectProps {\n invariant(typeof obj === 'object' && obj !== null, 'Invalid object model: not an object');\n assumeType<InternalObjectProps>(obj);\n invariant(EntityId.isValid(obj.id), 'Invalid object model: invalid id');\n invariant(obj[TypeId] === undefined || typeof obj[TypeId] === 'string', 'Invalid object model: invalid type');\n invariant(\n obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation || obj[KindId] === EntityKind.Type,\n 'Invalid object model: invalid entity kind',\n );\n\n if (obj[KindId] === EntityKind.Relation) {\n invariant(EID.isEID(obj[RelationSourceDXNId]), 'Invalid object model: invalid relation source');\n invariant(EID.isEID(obj[RelationTargetDXNId]), 'Invalid object model: invalid relation target');\n invariant(!EID.isEID(obj[RelationSourceId]), 'Invalid object model: source pointer is a DXN');\n invariant(!EID.isEID(obj[RelationTargetId]), 'Invalid object model: target pointer is a DXN');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { EID, EntityId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport { type InternalObjectProps, SelfURIId } from './model';\n\n/**\n * Returns the EID of an object.\n *\n * @internal\n */\nexport const getObjectEchoUri = (object: any): EID.EID | undefined => {\n invariant(!Schema.isSchema(object), 'schema not allowed in this function');\n assertArgument(typeof object === 'object' && object != null, 'object', 'expected object');\n assumeType<InternalObjectProps>(object);\n\n if (object[SelfURIId]) {\n invariant(EID.isEID(object[SelfURIId]), 'Invalid object model: invalid self dxn');\n return EID.parse(object[SelfURIId]);\n }\n\n if (!EntityId.isValid(object.id)) {\n throw new TypeError('Object id is not valid.');\n }\n\n return EID.make({ entityId: object.id });\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;;;;gBAAAA;EAAA;;;;;;;;;;;;;;;AAMA,YAAYC,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,gBAAgB;AAC5B,YAAYC,WAAW;AACvB,YAAYC,aAAY;AACxB,YAAYC,aAAY;AAExB,SAASC,gBAAgB;AACzB,SAASC,aAAAA,kBAAiB;;;ACV1B,YAAYC,aAAY;AAExB,SAASC,aAAa;AACtB,SAASC,kBAAAA,uBAAsB;AAC/B,SAASC,OAAAA,MAAKC,OAAAA,MAAKC,OAAAA,YAAW;;;ACJ9B,YAAYC,eAAc;AAC1B,YAAYC,aAAY;AACxB,YAAYC,aAAY;AACxB,YAAYC,eAAe;AAE3B,SAASC,gBAAgB;AACzB,SAASC,gBAAgBC,iBAAiB;AAC1C,SAASC,KAAKC,WAAW;;;ACSlB,IAAMC,gBAAgB;AAKtB,IAAMC,uBAAuB;AAK7B,IAAMC,YAAYC,uBAAOC,IAAI,gBAAA;AAK7B,IAAMC,eAAe;AAKrB,IAAMC,kBAAkBH,uBAAOC,IAAI,oBAAA;AAKnC,IAAMG,kBAAiCJ,uBAAOC,IAAI,oBAAA;AAKlD,IAAMI,mBAAmBL,uBAAOC,IAAI,qBAAA;AAKpC,IAAMK,uBAAuB;AAK7B,IAAMC,mBAAkCP,uBAAOC,IAAI,2BAAA;AAKnD,IAAMO,sBAAqCR,uBAAOC,IAAI,8BAAA;AAKtD,IAAMQ,uBAAuB;AAK7B,IAAMC,mBAAkCV,uBAAOC,IAAI,2BAAA;AAKnD,IAAMU,sBAAqCX,uBAAOC,IAAI,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CAAOG,UAAS,aAAA,QAA6B,MAAA,GAAA,yBAAA,EAAA,YAAA,YAAA,GAAAnB,eAAA,GAAA,IAAA,GAAA,MAAA,GAAA,CAAA,2CAAA,yBAAA,EAAA,CAAA;AAEvD,SAAA;;AAaSY,IAAQ,OAAA,UAAA,eAAA,EAAA,WAAA,KAAA;QACX,SAAO,OAAOI,SAAY,wBAAQI,MAAoBT,IAAIU,QAAG,CAAA;AAC/D,MAAA,CAAA,QAAA;AACA,WAAOT,OAAAA,YAAAA,IAAAA,oBAAAA,IAAAA,GAAAA,CAAAA;EAET;AAEF,SAAA;;;;;;;;AAkES,IAAA,QAAA,CAAA,kBAAA,QAAA,KAAA,WAAA,CAAA,EAAA,GAAA,MAAA,GAAA,MAAA,aAAA,CAAA,GAAA,gBAAA,gBAAA,GAAA,qBAAA;4BACeU,CAAAA,QAAMC;SAC1BC;IAIA,KAAA,eAAmB,KAAA,CAAA,WAAA,SAAA,wBAAA,MAAA,OAAA,IAAA,CAAA,CAAA;IACnB,OAAcC,eAAAA,KAAAA,CAAAA,WAAe,SAAA,wBAAA,YAAA,qBAAA,MAAA,OAAA,iBAAA,CAAA,CAAA,CAAA;;OAEpBH;IACT,SAAA;AACF,aAAA;IACF;;;",
|
|
6
|
-
"names": ["TypeId", "Context", "Effect", "Effectable", "Layer", "Option", "Schema", "EffectEx", "invariant", "Schema", "raise", "assertArgument", "DXN", "EID", "URI", "Function", "Option", "Schema", "SchemaAST", "SchemaEx", "assertArgument", "invariant", "DXN", "URI", "ATTR_SELF_URI", "ATTR_SELF_URI_LEGACY", "SelfURIId", "Symbol", "for", "ATTR_DELETED", "ObjectDeletedId", "ObjectVersionId", "ObjectDatabaseId", "ATTR_RELATION_SOURCE", "RelationSourceId", "RelationSourceDXNId", "ATTR_RELATION_TARGET", "RelationTargetId", "RelationTargetDXNId", "MetaId", "ATTR_TYPE", "TypeId", "Symbol", "for", "SchemaId", "ATTR_PARENT", "ParentId", "TypeEntityId", "getSchema", "obj", "setSchema", "schema", "Object", "defineProperty", "value", "writable", "enumerable", "configurable", "getType", "undefined", "setType", "type", "Function", "Option", "Schema", "Key", "String", "pipe", "brand", "Dictionary", "Record", "key", "value", "Unknown", "getDictionary", "values", "annotation", "none", "decodeUnknownSync", "schema", "some", "setDictionary", "encodeSync", "ANNOTATION_TYPE_ID", "id", "getTypeIdentifierAnnotation", "URI", "objectAnnotation", "typename", "undefined", "example", "TypeMeta", "version", "VersionSchema", "Function", "getAnnotation", "schema", "getSchemaTypename", "DXN", "type", "parsed", "Object", "defineProperty", "obj", "TypeId", "writable", "enumerable", "configurable", "invariant", "existingMeta", "self", "annotations", "PropertyMetaAnnotationId", "value", "assertArgument", "SchemaEx", "getField", "annotation", "label", "object", "accessor", "description", "DEFAULT_LAYOUT_NAME", "key", "get", "getFromAst", "ast", "set", "PropertyMeta", "Schema", "encodeSync", "IconAnnotationSchema", "getLabelWithSchema", "options", "setLabelWithSchema", "entity", "LabelAnnotation", "getDescriptionWithSchema", "Option", "setDescriptionWithSchema", "invariant", "DXN", "EID", "URI", "assumeType", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "ATTR_DELETED", "assumeType", "obj", "invariant", "EntityId", "isValid", "__dxlog_file", "TypeId", "KindId", "EntityKind", "Type", "EID", "isEID", "RelationSourceDXNId", "RelationTargetDXNId", "Schema", "assertArgument", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "assertArgument", "object", "assumeType", "SelfURIId", "invariant", "EID", "EntityId", "isValid", "make", "__dxlog_file", "prefer", "key", "MetaId", "DXN", "tryMake", "uri", "getObjectEchoUri", "entity", "invariant", "eid", "entityId", "getEntityId", "make", "assumeType", "spaceId", "EID", "ObjectDatabaseId", "getTypeURIFromSpecifier", "input", "isSchema", "getSchemaURI", "raise", "TypeError", "KindId", "schema", "getStaticTypeSchema", "uri", "getUriFromEntity", "assertArgument", "EID", "isEID", "DXN", "isDXN", "isInstanceOf", "schemaOrType", "object", "schemaURI", "type", "TypeId", "URI", "isURI", "typename", "getTypename", "parsed", "tryMake", "getName", "__dxlog_file", "obj", "TypeId", "Database", "Schema", "Any", "space", "isDatabase", "db", "spaceId", "dxn", "ref", "object", "EffectEx", "context", "resolveLegacy", "Effect", "fail", "pipe", "withSpan", "EntityNotFoundError", "uri", "eff", "result", "first", "CommitPrototype"]
|
|
7
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Ref,
|
|
3
|
-
createEchoReferenceSchema,
|
|
4
|
-
getRefSavedTarget
|
|
5
|
-
} from "./chunk-4TPQZPLY.mjs";
|
|
6
|
-
import {
|
|
7
|
-
Dictionary,
|
|
8
|
-
MetaId,
|
|
9
|
-
getDatabase,
|
|
10
|
-
getDictionary,
|
|
11
|
-
setDictionary
|
|
12
|
-
} from "./chunk-WZ32BF53.mjs";
|
|
13
|
-
import {
|
|
14
|
-
KindId,
|
|
15
|
-
SnapshotKindId
|
|
16
|
-
} from "./chunk-O6BH7EPN.mjs";
|
|
17
|
-
|
|
18
|
-
// src/internal/common/types/well-known-types.ts
|
|
19
|
-
import { DXN } from "@dxos/keys";
|
|
20
|
-
var TagTypeDXN = DXN.make("org.dxos.type.tag", "0.1.0");
|
|
21
|
-
|
|
22
|
-
// src/internal/common/types/meta.ts
|
|
23
|
-
import * as Schema from "effect/Schema";
|
|
24
|
-
import { ForeignKey } from "@dxos/echo-protocol";
|
|
25
|
-
import { invariant } from "@dxos/invariant";
|
|
26
|
-
import { DXN as DXN2 } from "@dxos/keys";
|
|
27
|
-
import { intersection } from "@dxos/util";
|
|
28
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/types/meta.ts";
|
|
29
|
-
var ATTR_META = "@meta";
|
|
30
|
-
var TagRefSchema = Schema.suspend(() => (
|
|
31
|
-
// The factory yields a loosely-typed `Ref<any>` schema; narrow it to the Tag-typed ref.
|
|
32
|
-
createEchoReferenceSchema(void 0, DXN2.getName(TagTypeDXN), DXN2.getVersion(TagTypeDXN))
|
|
33
|
-
));
|
|
34
|
-
var EntityMetaSchema = Schema.Struct({
|
|
35
|
-
keys: Schema.Array(ForeignKey),
|
|
36
|
-
/**
|
|
37
|
-
* Tags applied to this entity, as references to {@link Tag} objects.
|
|
38
|
-
*/
|
|
39
|
-
tags: Schema.Array(TagRefSchema),
|
|
40
|
-
/**
|
|
41
|
-
* Fully-qualified registry key for the object (FQN format, e.g. `org.example.type.foo`).
|
|
42
|
-
* Identifies the canonical registry entry the object instance was created from.
|
|
43
|
-
*/
|
|
44
|
-
key: Schema.optional(Schema.String),
|
|
45
|
-
/**
|
|
46
|
-
* Semantic version of the registry entry the object was created from.
|
|
47
|
-
* Must be a valid semver string (e.g. `1.2.3`).
|
|
48
|
-
*/
|
|
49
|
-
version: Schema.optional(Schema.String),
|
|
50
|
-
/**
|
|
51
|
-
* Dictionary of annotations to this entity.
|
|
52
|
-
*/
|
|
53
|
-
annotations: Dictionary,
|
|
54
|
-
/**
|
|
55
|
-
* Unix ms timestamp when this entity was created.
|
|
56
|
-
* Read-only; sourced from the system section of the automerge document — not stored in meta.
|
|
57
|
-
*/
|
|
58
|
-
createdAt: Schema.optional(Schema.Number),
|
|
59
|
-
/**
|
|
60
|
-
* Unix ms timestamp of the last automerge change on this entity's document.
|
|
61
|
-
* Read-only; derived from the automerge change graph — not stored in meta.
|
|
62
|
-
*/
|
|
63
|
-
updatedAt: Schema.optional(Schema.Number)
|
|
64
|
-
});
|
|
65
|
-
var getMeta = (obj) => {
|
|
66
|
-
const metadata = obj[MetaId];
|
|
67
|
-
invariant(metadata, "EntityMeta not found.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 63, S: void 0, A: ["metadata", "'EntityMeta not found.'"] });
|
|
68
|
-
return metadata;
|
|
69
|
-
};
|
|
70
|
-
var foreignKey = (source, id) => ({
|
|
71
|
-
source,
|
|
72
|
-
id
|
|
73
|
-
});
|
|
74
|
-
var foreignKeyEquals = (a, b) => a.source === b.source && a.id === b.id;
|
|
75
|
-
var compareForeignKeys = (a, b) => intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;
|
|
76
|
-
|
|
77
|
-
// src/internal/common/api/meta.ts
|
|
78
|
-
import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
|
|
79
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/api/meta.ts";
|
|
80
|
-
function getMetaChecked(entity) {
|
|
81
|
-
assertArgument(entity, "entity", "Should be an entity.");
|
|
82
|
-
const meta = getMeta(entity);
|
|
83
|
-
invariant2(meta != null, "Invalid entity.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 9, S: this, A: ["meta != null", "'Invalid entity.'"] });
|
|
84
|
-
return meta;
|
|
85
|
-
}
|
|
86
|
-
var getKeys = (entity, source) => {
|
|
87
|
-
assertArgument(entity, "entity", "Should be an entity.");
|
|
88
|
-
const meta = getMetaChecked(entity);
|
|
89
|
-
invariant2(meta != null, "Invalid entity.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 18, S: void 0, A: ["meta != null", "'Invalid entity.'"] });
|
|
90
|
-
return meta.keys.filter((key) => key.source === source);
|
|
91
|
-
};
|
|
92
|
-
var deleteKeys = (entity, source) => {
|
|
93
|
-
const meta = getMetaChecked(entity);
|
|
94
|
-
for (let i = 0; i < meta.keys.length; i++) {
|
|
95
|
-
if (meta.keys[i].source === source) {
|
|
96
|
-
meta.keys.splice(i, 1);
|
|
97
|
-
i--;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var addTag = (entity, tag) => {
|
|
102
|
-
const meta = getMetaChecked(entity);
|
|
103
|
-
if (!meta.tags.some((existing) => existing.uri === tag.uri)) {
|
|
104
|
-
meta.tags.push(tag);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var removeTag = (entity, tag) => {
|
|
108
|
-
const meta = getMetaChecked(entity);
|
|
109
|
-
for (let i = 0; i < meta.tags.length; i++) {
|
|
110
|
-
if (meta.tags[i].uri === tag.uri) {
|
|
111
|
-
meta.tags.splice(i, 1);
|
|
112
|
-
i--;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// src/internal/Entity/guard.ts
|
|
118
|
-
var isEntity = (value) => {
|
|
119
|
-
if (typeof value !== "object" || value === null) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
return value[KindId] !== void 0;
|
|
123
|
-
};
|
|
124
|
-
var isSnapshot = (value) => {
|
|
125
|
-
if (typeof value !== "object" || value === null) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return value[SnapshotKindId] !== void 0;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// src/internal/Annotation/entity-dictionary.ts
|
|
132
|
-
import { deepMapValues } from "@dxos/util";
|
|
133
|
-
var get = (target, annotation) => {
|
|
134
|
-
if (isEntity(target) || isSnapshot(target)) {
|
|
135
|
-
const meta = getMetaChecked(target);
|
|
136
|
-
return getDictionary(meta.annotations, annotation);
|
|
137
|
-
} else {
|
|
138
|
-
throw new TypeError("Target is not an annotation target.");
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
var set = (target, annotation, value) => {
|
|
142
|
-
if (isEntity(target)) {
|
|
143
|
-
const meta = getMetaChecked(target);
|
|
144
|
-
persistRefTargets(target, value);
|
|
145
|
-
setDictionary(meta.annotations, annotation, value);
|
|
146
|
-
} else {
|
|
147
|
-
throw new TypeError("Target is not an annotation target.");
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
var persistRefTargets = (host, value) => {
|
|
151
|
-
const database = getDatabase(host);
|
|
152
|
-
if (database == null) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
deepMapValues(value, (current, recurse) => {
|
|
156
|
-
if (Ref.isRef(current)) {
|
|
157
|
-
const refTarget = getRefSavedTarget(current);
|
|
158
|
-
if (refTarget != null && isEntity(refTarget) && getDatabase(refTarget) == null) {
|
|
159
|
-
database.add(refTarget);
|
|
160
|
-
}
|
|
161
|
-
return current;
|
|
162
|
-
}
|
|
163
|
-
return recurse(current);
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
export {
|
|
168
|
-
TagTypeDXN,
|
|
169
|
-
ATTR_META,
|
|
170
|
-
EntityMetaSchema,
|
|
171
|
-
getMeta,
|
|
172
|
-
foreignKey,
|
|
173
|
-
foreignKeyEquals,
|
|
174
|
-
compareForeignKeys,
|
|
175
|
-
getMetaChecked,
|
|
176
|
-
getKeys,
|
|
177
|
-
deleteKeys,
|
|
178
|
-
addTag,
|
|
179
|
-
removeTag,
|
|
180
|
-
isEntity,
|
|
181
|
-
get,
|
|
182
|
-
set
|
|
183
|
-
};
|
|
184
|
-
//# sourceMappingURL=chunk-X3NUUON4.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/internal/common/types/well-known-types.ts", "../../../src/internal/common/types/meta.ts", "../../../src/internal/common/api/meta.ts", "../../../src/internal/Entity/guard.ts", "../../../src/internal/Annotation/entity-dictionary.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport { DXN } from '@dxos/keys';\n\n/**\n * DXN identity of the system {@link Tag} type.\n *\n * Defined in this low-level leaf so it can be shared by the public `Tag` type (which brands the\n * schema with this DXN) and by `EntityMetaSchema.tags` (which builds a `Ref<Tag>` schema from it)\n * without either importing the other — `Tag` is top-level and `meta` is deep-internal, so a direct\n * dependency between them would form an eval-order cycle.\n */\nexport const TagTypeDXN = DXN.make('org.dxos.type.tag', '0.1.0');\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type EncodedReference, ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport { type Comparator, intersection } from '@dxos/util';\n\nimport type * as Tag from '../../../Tag';\nimport { Dictionary } from '../../Annotation/dictionary';\n// `meta` is no longer re-exported from the `common/types` barrel (see ./index.ts), so importing the\n// Ref schema builder here no longer forms an eval-order cycle with `Annotation`/`Database`.\nimport { type Ref, createEchoReferenceSchema } from '../../Ref/ref';\nimport { type AnyProperties } from './base';\nimport { MetaId } from './model-symbols';\nimport { TagTypeDXN } from './well-known-types';\n\n/**\n * Property name for meta when object is serialized to JSON.\n */\nexport const ATTR_META = '@meta';\n\n//\n// EntityMeta\n//\n\n/**\n * Schema for references to {@link Tag} objects stored in {@link EntityMetaSchema.tags}.\n *\n * Built from the shared {@link createEchoReferenceSchema} (the same builder `Ref.Ref` uses) via\n * `Schema.suspend`, so it reuses the canonical ref codec rather than duplicating it. The Tag type\n * identity comes from the shared {@link TagTypeDXN} constant; `suspend` defers construction until\n * first use, and `Tag` is referenced type-only, so no `Tag` value import is needed.\n */\nconst TagRefSchema = Schema.suspend(\n (): Schema.Schema<Ref<Tag.Tag>, EncodedReference> =>\n // The factory yields a loosely-typed `Ref<any>` schema; narrow it to the Tag-typed ref.\n createEchoReferenceSchema(undefined, DXN.getName(TagTypeDXN), DXN.getVersion(TagTypeDXN)) as Schema.Schema<\n Ref<Tag.Tag>,\n EncodedReference\n >,\n);\n\nexport const EntityMetaSchema = Schema.Struct({\n keys: Schema.Array(ForeignKey),\n\n /**\n * Tags applied to this entity, as references to {@link Tag} objects.\n */\n tags: Schema.Array(TagRefSchema),\n\n /**\n * Fully-qualified registry key for the object (FQN format, e.g. `org.example.type.foo`).\n * Identifies the canonical registry entry the object instance was created from.\n */\n key: Schema.optional(Schema.String),\n\n /**\n * Semantic version of the registry entry the object was created from.\n * Must be a valid semver string (e.g. `1.2.3`).\n */\n version: Schema.optional(Schema.String),\n\n /**\n * Dictionary of annotations to this entity.\n */\n annotations: Dictionary,\n\n /**\n * Unix ms timestamp when this entity was created.\n * Read-only; sourced from the system section of the automerge document — not stored in meta.\n */\n createdAt: Schema.optional(Schema.Number),\n\n /**\n * Unix ms timestamp of the last automerge change on this entity's document.\n * Read-only; derived from the automerge change graph — not stored in meta.\n */\n updatedAt: Schema.optional(Schema.Number),\n});\n\nexport type EntityMeta = Schema.Schema.Type<typeof EntityMetaSchema>;\n\n/*\n * Get metadata from object.\n * Only callable on the object root.\n *\n * @internal (use Obj.getMeta or Relation.getMeta)\n */\n// TODO(burdon): Refine type to BaseObj.\nexport const getMeta = (obj: AnyProperties): EntityMeta => {\n const metadata = (obj as any)[MetaId];\n invariant(metadata, 'EntityMeta not found.');\n return metadata;\n};\n\n//\n// Foreign keys\n//\n\nexport const foreignKey = (source: string, id: string): ForeignKey => ({ source, id });\nexport const foreignKeyEquals = (a: ForeignKey, b: ForeignKey) => a.source === b.source && a.id === b.id;\n\n// TODO(dmaretskyi): Move to echo-schema.\nexport const compareForeignKeys: Comparator<AnyProperties> = (a: AnyProperties, b: AnyProperties) =>\n intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport type { DeepReadonly } from '@dxos/util';\n\nimport type * as Tag from '../../../Tag';\nimport type { Ref } from '../../Ref/ref';\nimport { type Mutable } from '../proxy';\nimport { type AnyProperties } from '../types';\nimport { type EntityMeta, getMeta as getMeta$ } from '../types/meta';\n\n/**\n * Deeply read-only version of EntityMeta.\n */\nexport type ReadonlyMeta = DeepReadonly<EntityMeta>;\n\n/**\n * Mutable meta type received in meta mutation callbacks.\n */\nexport type Meta = Mutable<EntityMeta>;\n\n/**\n * Get the metadata for an entity with validation.\n * Returns mutable meta when passed a mutable entity (inside change callback).\n * Returns read-only meta when passed a regular entity or snapshot.\n *\n * TODO(burdon): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\n */\nexport function getMetaChecked(entity: Mutable<AnyProperties>): Meta;\nexport function getMetaChecked(entity: AnyProperties): ReadonlyMeta;\nexport function getMetaChecked(entity: AnyProperties): Meta | ReadonlyMeta {\n assertArgument(entity, 'entity', 'Should be an entity.');\n const meta = getMeta$(entity);\n invariant(meta != null, 'Invalid entity.');\n return meta;\n}\n\n/**\n * @returns Foreign keys for the entity from the specified source.\n * Accepts both reactive entities and snapshots.\n */\nexport const getKeys = (entity: AnyProperties, source: string): ForeignKey[] => {\n assertArgument(entity, 'entity', 'Should be an entity.');\n const meta = getMetaChecked(entity);\n invariant(meta != null, 'Invalid entity.');\n return meta.keys.filter((key) => key.source === source);\n};\n\n/**\n * Delete all keys from the entity for the specified source.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const deleteKeys = (entity: Mutable<AnyProperties>, source: string) => {\n const meta = getMetaChecked(entity);\n for (let i = 0; i < meta.keys.length; i++) {\n if (meta.keys[i].source === source) {\n meta.keys.splice(i, 1);\n i--;\n }\n }\n};\n\n/**\n * Add a tag (a reference to a {@link Tag} object) to the entity. Idempotent.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const addTag = (entity: Mutable<AnyProperties>, tag: Ref<Tag.Tag>) => {\n const meta = getMetaChecked(entity);\n // Two refs to the same target are not `===`; dedupe by URI.\n if (!meta.tags.some((existing) => existing.uri === tag.uri)) {\n meta.tags.push(tag);\n }\n};\n\n/**\n * Remove a tag (a reference to a {@link Tag} object) from the entity. No-op when not present.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const removeTag = (entity: Mutable<AnyProperties>, tag: Ref<Tag.Tag>) => {\n const meta = getMetaChecked(entity);\n for (let i = 0; i < meta.tags.length; i++) {\n if (meta.tags[i].uri === tag.uri) {\n meta.tags.splice(i, 1);\n i--;\n }\n }\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport type * as Entity from '../../Entity';\nimport { KindId, SnapshotKindId } from '../common/types';\n\n/**\n * Returns true if the value is an ECHO entity instance (object or relation).\n */\nexport const isEntity = (value: unknown): value is Entity.Unknown => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[KindId] !== undefined;\n};\n\n/**\n * Returns true if the value is an ECHO entity snapshot.\n */\nexport const isSnapshot = (value: unknown): value is Entity.Snapshot => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[SnapshotKindId] !== undefined;\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\n\nimport { deepMapValues } from '@dxos/util';\n\nimport type * as Annotation from '../../Annotation';\nimport type * as Entity from '../../Entity';\nimport { getMetaChecked } from '../common/api/meta';\nimport { type Mutable } from '../common/proxy/reactive';\nimport { getDatabase } from '../Entity/api';\nimport { isEntity, isSnapshot } from '../Entity/guard';\nimport { Ref, getRefSavedTarget } from '../Ref';\nimport { getDictionary, setDictionary } from './dictionary';\n\n/**\n * Get the value of an annotation from an entity instance or snapshot.\n */\nexport const get = <T>(\n target: Entity.Unknown | Entity.Snapshot,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (isEntity(target) || isSnapshot(target)) {\n const meta = getMetaChecked(target);\n return getDictionary(meta.annotations, annotation);\n } else {\n throw new TypeError('Target is not an annotation target.');\n }\n};\n\n/**\n * Set the value of an annotation on an entity instance.\n * Must be called with a mutable entity — i.e. inside an `Obj.update` callback.\n */\nexport const set = <T>(target: Mutable<Entity.Unknown>, annotation: Annotation.Annotation<T>, value: T): void => {\n if (isEntity(target)) {\n const meta = getMetaChecked(target);\n // Persist any unsaved Ref targets in the value into the entity's database so\n // the encoded DXN resolves on read. This mirrors normal property assignment,\n // where the reactive proxy links unsaved ref targets via `createRef` →\n // `database.add`. `setDictionary` pre-encodes the value (`Schema.encodeSync`),\n // so the live Ref never reaches the proxy's link handling and would otherwise\n // be stored as a dangling reference.\n persistRefTargets(target, value);\n setDictionary(meta.annotations, annotation, value);\n } else {\n throw new TypeError('Target is not an annotation target.');\n }\n};\n\n/**\n * Add any unsaved Ref targets found in `value` to the host entity's database, matching the\n * auto-persistence applied to refs assigned to ordinary entity properties. Refs whose target\n * already lives in a database (the host's or a foreign one) are left untouched.\n */\nconst persistRefTargets = (host: Entity.Unknown, value: unknown): void => {\n const database = getDatabase(host);\n if (database == null) {\n return;\n }\n\n deepMapValues(value, (current, recurse) => {\n if (Ref.isRef(current)) {\n const refTarget = getRefSavedTarget(current);\n if (refTarget != null && isEntity(refTarget) && getDatabase(refTarget) == null) {\n database.add(refTarget);\n }\n return current;\n }\n return recurse(current);\n });\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAIA,SAASA,WAAW;AAUb,IAAMC,aAAaD,IAAIE,KAAK,qBAAqB,OAAA;;;ACVxD,YAAYC,YAAY;AAExB,SAAgCC,kBAAkB;AAClD,SAASC,iBAAiB;AAC1B,SAASC,OAAAA,YAAW;AACpB,SAA0BC,oBAAoB;AAW9C,IAAA,eAAA;AAMA,IAAa,YAAA;AAoBb,IAAO,eAAyBC,eAAOC;;EACrCC,0BAAmBC,QAAAA,KAAAA,QAAAA,UAAAA,GAAAA,KAAAA,WAAAA,UAAAA,CAAAA;CAAAA;AAEnB,IAAA,mBAAA,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCF,WAAA,gBAAA,aAAA;;AASEC,IAAAA,UAAUC,CAAU,QAAA;AACpB,QAAA,WAAOA,IAAAA,MAAAA;AACP,YAAA,UAAA,yBAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,QAAA,GAAA,CAAA,YAAA,yBAAA,EAAA,CAAA;AAEA,SAAA;AACF;IAGiFC,aAAAA,CAAAA,QAAAA,QAAAA;EAAM;EAChF;AAEP;AACO,IAAMC,mBAAAA,CAAAA,GAAiDC,MAAkBC,EAC9EC,WAAAA,EAAaC,UAAQH,EAAGN,OAAMS,EAAAA;;;;ACvGhC,SAASC,gBAAgBC,aAAAA,kBAAiB;AA4B1C,IAAAC,gBAAgBC;AAEd,SAAMC,eAAgBC,QAAAA;AACtBC,iBAAUF,QAAQ,UAAM,sBAAA;AACxB,QA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AAA,MAAYC;AACpC;AAKO,IAAMC,aAAa,CAACH,UAAAA;AACzB,MAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM;AAC/C,WAAO;EACT;AACA,SAAQA,MAAcI,cAAAA,MAAoBF;AAC5C;;;ACnBA,SAASG,qBAAqB;AAcvB,IAAMC,MAAM,CACjBC,QACAC,eAAAA;AAEA,MAAIC,SAASF,MAAAA,KAAWG,WAAWH,MAAAA,GAAS;AAC1C,UAAMI,OAAOC,eAAeL,MAAAA;AAC5B,WAAOM,cAAcF,KAAKG,aAAaN,UAAAA;EACzC,OAAO;AACL,UAAM,IAAIO,UAAU,qCAAA;EACtB;AACF;AAMO,IAAMC,MAAM,CAAIT,QAAiCC,YAAsCS,UAAAA;AAC5F,MAAIR,SAASF,MAAAA,GAAS;AACpB,UAAMI,OAAOC,eAAeL,MAAAA;AAO5BW,sBAAkBX,QAAQU,KAAAA;AAC1BE,kBAAcR,KAAKG,aAAaN,YAAYS,KAAAA;EAC9C,OAAO;AACL,UAAM,IAAIF,UAAU,qCAAA;EACtB;AACF;AAOA,IAAMG,oBAAoB,CAACE,MAAsBH,UAAAA;AAC/C,QAAMI,WAAWC,YAAYF,IAAAA;AAC7B,MAAIC,YAAY,MAAM;AACpB;EACF;AAEAE,gBAAcN,OAAO,CAACO,SAASC,YAAAA;AAC7B,QAAIC,IAAIC,MAAMH,OAAAA,GAAU;AACtB,YAAMI,YAAYC,kBAAkBL,OAAAA;AACpC,UAAII,aAAa,QAAQnB,SAASmB,SAAAA,KAAcN,YAAYM,SAAAA,KAAc,MAAM;AAC9EP,iBAASS,IAAIF,SAAAA;MACf;AACA,aAAOJ;IACT;AACA,WAAOC,QAAQD,OAAAA;EACjB,CAAA;AACF;",
|
|
6
|
-
"names": ["DXN", "TagTypeDXN", "make", "Schema", "ForeignKey", "invariant", "DXN", "intersection", "Schema", "Struct", "keys", "ForeignKey", "invariant", "metadata", "id", "compareForeignKeys", "a", "b", "intersection", "getMeta", "assertArgument", "invariant", "__dxlog_file", "getMetaChecked", "meta", "entity", "invariant", "keys", "key", "source", "splice", "i", "tags", "existing", "length", "uri", "isEntity", "value", "KindId", "undefined", "isSnapshot", "SnapshotKindId", "deepMapValues", "get", "target", "annotation", "isEntity", "isSnapshot", "meta", "getMetaChecked", "getDictionary", "annotations", "TypeError", "set", "value", "persistRefTargets", "setDictionary", "host", "database", "getDatabase", "deepMapValues", "current", "recurse", "Ref", "isRef", "refTarget", "getRefSavedTarget", "add"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exemplars.test.d.ts","sourceRoot":"","sources":["../../../src/exemplars.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hierarchy.test.d.ts","sourceRoot":"","sources":["../../../src/hierarchy.test.ts"],"names":[],"mappings":""}
|
package/src/exemplars.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2026 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { describe, test } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import * as Obj from './Obj';
|
|
8
|
-
import { TestSchema } from './testing';
|
|
9
|
-
import type * as Type from './Type';
|
|
10
|
-
|
|
11
|
-
describe('Exemplars', () => {
|
|
12
|
-
test('factory', ({ expect }) => {
|
|
13
|
-
const factory = <S extends Type.AnyObj>(schema: S) => {
|
|
14
|
-
return (props: Obj.MakeProps<S>) => Obj.make(schema, props);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const makePerson = factory(TestSchema.Person);
|
|
18
|
-
const person = makePerson({ name: 'John Doe' });
|
|
19
|
-
expect(person.name).toBe('John Doe');
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/hierarchy.test.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { describe, expect, test } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import * as Obj from './Obj';
|
|
8
|
-
import { TestSchema } from './testing';
|
|
9
|
-
|
|
10
|
-
describe('Hierarchy', () => {
|
|
11
|
-
test('setParent and getParent', async () => {
|
|
12
|
-
const parent = Obj.make(TestSchema.Organization, { name: 'parent' });
|
|
13
|
-
const child = Obj.make(TestSchema.Person, { name: 'child' });
|
|
14
|
-
expect(Obj.getParent(child)).toBeUndefined();
|
|
15
|
-
|
|
16
|
-
Obj.setParent(child, parent);
|
|
17
|
-
expect(Obj.getParent(child)).toBe(parent);
|
|
18
|
-
|
|
19
|
-
Obj.setParent(child, undefined);
|
|
20
|
-
expect(Obj.getParent(child)).toBeUndefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('create object with Obj.Parent in props', () => {
|
|
24
|
-
const parent = Obj.make(TestSchema.Organization, { name: 'DXOS' });
|
|
25
|
-
const child = Obj.make(TestSchema.Person, {
|
|
26
|
-
[Obj.Parent]: parent,
|
|
27
|
-
name: 'John',
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
expect(child.name).toBe('John');
|
|
31
|
-
expect(Obj.getParent(child)).toBe(parent);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|