@dxos/echo 0.9.0 → 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 +30 -8
- package/dist/lib/neutral/Database.mjs +7 -3
- package/dist/lib/neutral/Entity.mjs +15 -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 +19 -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-QQIYS74I.mjs → chunk-3KTE2Y7Q.mjs} +20 -20
- package/dist/lib/neutral/chunk-3KTE2Y7Q.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-R5W6DXR4.mjs → chunk-3TN2VMI4.mjs} +72 -36
- package/dist/lib/neutral/chunk-3TN2VMI4.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-5SMDBFVB.mjs → chunk-42L4HJ3Z.mjs} +11 -15
- package/dist/lib/neutral/chunk-42L4HJ3Z.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-7PI7C4EF.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-SBVFRTST.mjs → chunk-BEFR7LEA.mjs} +20 -10
- package/dist/lib/neutral/chunk-BEFR7LEA.mjs.map +7 -0
- 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-UUP46KUQ.mjs → chunk-C57XMMBY.mjs} +21 -20
- package/dist/lib/neutral/chunk-C57XMMBY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-C62JYFAD.mjs +183 -0
- package/dist/lib/neutral/chunk-C62JYFAD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-MZ7K3MLL.mjs → chunk-FSGX2R62.mjs} +3 -3
- package/dist/lib/neutral/chunk-FSGX2R62.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TYGKCRMK.mjs → chunk-HBXT3GSB.mjs} +37 -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-WTQJHC75.mjs → chunk-L3E5IXAE.mjs} +225 -45
- 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-6YDI3J37.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-RIVWNMSF.mjs → chunk-U53LSQQA.mjs} +3 -3
- package/dist/lib/neutral/{chunk-RIVWNMSF.mjs.map → chunk-U53LSQQA.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-IGK6FN65.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-LWXVKPPW.mjs → chunk-UZHCQ6NI.mjs} +13 -11
- package/dist/lib/neutral/{chunk-LWXVKPPW.mjs.map → chunk-UZHCQ6NI.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-5SUJPHAE.mjs → chunk-WKIT2YY5.mjs} +2 -2
- package/dist/lib/neutral/{chunk-T6E37YIP.mjs → chunk-XB6ISRAO.mjs} +38 -18
- 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-ZGNNFYHS.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 +111 -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 +38 -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/Entity.d.ts +2 -0
- package/dist/types/src/Entity.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 +59 -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 +33 -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 +10 -6
- 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 +38 -21
- 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 +50 -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 +12 -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/index.d.ts +1 -0
- package/dist/types/src/internal/Ref/index.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref.d.ts +79 -8
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/strong-deps.d.ts +35 -0
- package/dist/types/src/internal/Ref/strong-deps.d.ts.map +1 -0
- 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 +58 -4
- package/src/Collection.ts +10 -12
- package/src/Database.ts +55 -21
- package/src/Entity.ts +3 -1
- package/src/Err.ts +22 -0
- package/src/Feed.ts +117 -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 +38 -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 +14 -6
- package/src/Registry.ts +1 -1
- package/src/Relation.ts +1 -1
- package/src/Tag.ts +13 -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 +85 -33
- package/src/View.ts +22 -30
- package/src/index.ts +1 -1
- package/src/internal/Annotation/annotations.ts +71 -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 +62 -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 +4 -4
- 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/index.ts +1 -0
- package/src/internal/Ref/ref.test.ts +8 -8
- package/src/internal/Ref/ref.ts +122 -39
- package/src/internal/Ref/strong-deps.ts +107 -0
- 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-3PBP4V4O.mjs +0 -101
- package/dist/lib/neutral/chunk-3PBP4V4O.mjs.map +0 -7
- package/dist/lib/neutral/chunk-4ZUHOTCG.mjs +0 -184
- package/dist/lib/neutral/chunk-4ZUHOTCG.mjs.map +0 -7
- package/dist/lib/neutral/chunk-5SMDBFVB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-6YDI3J37.mjs.map +0 -7
- package/dist/lib/neutral/chunk-7FPIAJIV.mjs +0 -2279
- package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +0 -7
- package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +0 -7
- package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +0 -7
- package/dist/lib/neutral/chunk-QQIYS74I.mjs.map +0 -7
- package/dist/lib/neutral/chunk-R5W6DXR4.mjs.map +0 -7
- package/dist/lib/neutral/chunk-SBVFRTST.mjs.map +0 -7
- package/dist/lib/neutral/chunk-T6E37YIP.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TYGKCRMK.mjs.map +0 -7
- package/dist/lib/neutral/chunk-UUP46KUQ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-WTQJHC75.mjs.map +0 -7
- package/dist/lib/neutral/chunk-WU3GIANS.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ZGNNFYHS.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-7PI7C4EF.mjs.map → chunk-4A2NWKRJ.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-IGK6FN65.mjs.map → chunk-UGFFV2FR.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-5SUJPHAE.mjs.map → chunk-WKIT2YY5.mjs.map} +0 -0
|
@@ -41,13 +41,21 @@ export type SnapshotKindId = typeof SnapshotKindId;
|
|
|
41
41
|
export const StaticTypeSchemaSlot = '~@dxos/echo/Type.StaticSchema' as const;
|
|
42
42
|
export type StaticTypeSchemaSlot = typeof StaticTypeSchemaSlot;
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Whether a value can carry an entity brand/slot. Class-declared types
|
|
46
|
+
* Class-declared types (`Type.makeObject`) are functions whose prototype chain reaches the entity,
|
|
47
|
+
* so brand/slot lookups must accept functions as well as plain objects.
|
|
48
|
+
*/
|
|
49
|
+
const isBrandCarrier = (value: unknown): boolean =>
|
|
50
|
+
value != null && (typeof value === 'object' || typeof value === 'function');
|
|
51
|
+
|
|
44
52
|
/**
|
|
45
53
|
* Read the hidden `StaticTypeSchemaSlot` off any value that may carry one.
|
|
46
|
-
* Returns `undefined` for raw schemas (no slot) and
|
|
54
|
+
* Returns `undefined` for raw schemas (no slot) and inputs that cannot carry a brand.
|
|
47
55
|
* Single point-of-cast for the slot lookup.
|
|
48
56
|
*/
|
|
49
57
|
export const getStaticTypeSchema = (value: unknown): Schema.Schema.AnyNoContext | undefined => {
|
|
50
|
-
if (value
|
|
58
|
+
if (!isBrandCarrier(value)) {
|
|
51
59
|
return undefined;
|
|
52
60
|
}
|
|
53
61
|
return (value as { [StaticTypeSchemaSlot]?: Schema.Schema.AnyNoContext })[StaticTypeSchemaSlot];
|
|
@@ -55,11 +63,11 @@ export const getStaticTypeSchema = (value: unknown): Schema.Schema.AnyNoContext
|
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
65
|
* Read the `[SchemaKindId]` brand off a value. Returns `undefined` for raw
|
|
58
|
-
* schemas (which don't carry the brand on their static type) and
|
|
59
|
-
*
|
|
66
|
+
* schemas (which don't carry the brand on their static type) and inputs that
|
|
67
|
+
* cannot carry a brand. Single point-of-cast for the brand lookup.
|
|
60
68
|
*/
|
|
61
69
|
export const getSchemaKind = (value: unknown): EntityKind | undefined => {
|
|
62
|
-
if (value
|
|
70
|
+
if (!isBrandCarrier(value)) {
|
|
63
71
|
return undefined;
|
|
64
72
|
}
|
|
65
73
|
return (value as { [SchemaKindId]?: EntityKind })[SchemaKindId];
|
|
@@ -67,10 +75,10 @@ export const getSchemaKind = (value: unknown): EntityKind | undefined => {
|
|
|
67
75
|
|
|
68
76
|
/**
|
|
69
77
|
* Read the `[KindId]` brand off a value. Returns `undefined` for raw schemas
|
|
70
|
-
* and
|
|
78
|
+
* and inputs that cannot carry a brand. Companion to {@link getSchemaKind}.
|
|
71
79
|
*/
|
|
72
80
|
export const getEntityKindBrand = (value: unknown): EntityKind | undefined => {
|
|
73
|
-
if (value
|
|
81
|
+
if (!isBrandCarrier(value)) {
|
|
74
82
|
return undefined;
|
|
75
83
|
}
|
|
76
84
|
return (value as { [KindId]?: EntityKind })[KindId];
|
package/src/internal/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export * from './Annotation';
|
|
6
6
|
export * from './common';
|
|
7
7
|
export * from './Entity';
|
|
8
|
+
export * from './Filter';
|
|
8
9
|
export * from './Format';
|
|
9
10
|
export * from './JsonSchema';
|
|
10
11
|
// TODO(wittjosiah): Required to ensure types are portable (need to export all types required for downstream inference).
|
|
@@ -19,11 +19,9 @@ export namespace TestSchema {
|
|
|
19
19
|
* Expando object is an object with an arbitrary set of properties.
|
|
20
20
|
* This is the test variant with example.com namespace.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
export type Expando = Type.InstanceType<typeof Expando>;
|
|
22
|
+
export class Expando extends Type.makeObject<Expando>(DXN.make('com.example.type.expando', '0.1.0'))(
|
|
23
|
+
Schema.Struct({}, { key: Schema.String, value: Schema.Any }),
|
|
24
|
+
) {}
|
|
27
25
|
|
|
28
26
|
//
|
|
29
27
|
// Example
|
|
@@ -62,10 +60,7 @@ export namespace TestSchema {
|
|
|
62
60
|
export interface ExampleSchema extends Schema.Schema.Type<typeof ExampleSchema> {}
|
|
63
61
|
|
|
64
62
|
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
68
|
-
export interface Example extends Type.InstanceType<typeof Example> {}
|
|
63
|
+
export class Example extends Type.makeObject<Example>(DXN.make('com.example.type.example', '0.1.0'))(ExampleSchema) {}
|
|
69
64
|
|
|
70
65
|
//
|
|
71
66
|
// Message
|
|
@@ -81,100 +76,90 @@ export namespace TestSchema {
|
|
|
81
76
|
),
|
|
82
77
|
});
|
|
83
78
|
|
|
84
|
-
export
|
|
85
|
-
|
|
86
|
-
export type Message = Type.InstanceType<typeof Message>;
|
|
79
|
+
export class Message extends Type.makeObject<Message>(DXN.make('com.example.type.message', '0.1.0'))(MessageStruct) {}
|
|
87
80
|
|
|
88
81
|
//
|
|
89
82
|
// Organization
|
|
90
83
|
//
|
|
91
84
|
|
|
92
|
-
export
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Schema.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
export class Organization extends Type.makeObject<Organization>(DXN.make('com.example.type.organization', '0.1.0'))(
|
|
86
|
+
Schema.Struct({
|
|
87
|
+
name: Schema.String,
|
|
88
|
+
properties: Schema.optional(
|
|
89
|
+
Schema.Record({
|
|
90
|
+
key: Schema.String,
|
|
91
|
+
value: Schema.String,
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
}),
|
|
95
|
+
) {}
|
|
103
96
|
|
|
104
97
|
//
|
|
105
98
|
// Person
|
|
106
99
|
//
|
|
107
100
|
|
|
108
|
-
export
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
101
|
+
export class Person extends Type.makeObject<Person>(DXN.make('com.example.type.person', '0.1.0'))(
|
|
102
|
+
Schema.Struct({
|
|
103
|
+
name: Schema.String,
|
|
104
|
+
username: Schema.String,
|
|
105
|
+
email: Schema.String,
|
|
106
|
+
age: Schema.Number.pipe(Schema.optional),
|
|
107
|
+
tasks: Schema.Array(Schema.suspend((): Ref.RefSchema<Task> => Ref.Ref(Task))),
|
|
108
|
+
employer: Schema.optional(Ref.Ref(Organization)),
|
|
109
|
+
address: Schema.Struct({
|
|
110
|
+
city: Schema.optional(Schema.String),
|
|
111
|
+
state: Schema.optional(Schema.String),
|
|
112
|
+
zip: Schema.optional(Schema.String),
|
|
113
|
+
coordinates: Schema.Struct({
|
|
114
|
+
lat: Schema.optional(Schema.Number),
|
|
115
|
+
lng: Schema.optional(Schema.Number),
|
|
116
|
+
}),
|
|
122
117
|
}),
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}).pipe(Schema.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
export interface Person extends Type.InstanceType<typeof Person> {}
|
|
118
|
+
fields: Schema.Struct({
|
|
119
|
+
label: Schema.String,
|
|
120
|
+
value: Schema.String,
|
|
121
|
+
}).pipe(Schema.Array, Schema.optional),
|
|
122
|
+
}).pipe(Schema.partial),
|
|
123
|
+
) {}
|
|
131
124
|
|
|
132
125
|
//
|
|
133
126
|
// Task
|
|
134
127
|
//
|
|
135
128
|
|
|
136
|
-
export
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
129
|
+
export class Task extends Type.makeObject<Task>(DXN.make('com.example.type.task', '0.1.0'))(
|
|
130
|
+
Schema.Struct({
|
|
131
|
+
title: Schema.optional(Schema.String),
|
|
132
|
+
deadline: Schema.optional(Schema.String),
|
|
133
|
+
completed: Schema.optional(Schema.Boolean),
|
|
134
|
+
assignee: Schema.optional(Ref.Ref(Person)),
|
|
135
|
+
previous: Schema.optional(Schema.suspend((): Ref.RefSchema<Task> => Ref.Ref(Task))),
|
|
136
|
+
subTasks: Schema.optional(Schema.Array(Schema.suspend((): Ref.RefSchema<Task> => Ref.Ref(Task)))),
|
|
137
|
+
description: Schema.optional(Schema.String),
|
|
138
|
+
}).pipe(Schema.partial),
|
|
139
|
+
) {}
|
|
147
140
|
|
|
148
141
|
//
|
|
149
142
|
// HasManager
|
|
150
143
|
//
|
|
151
144
|
|
|
152
|
-
export
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
target: Person,
|
|
157
|
-
}),
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
export type HasManager = Type.InstanceType<typeof HasManager>;
|
|
145
|
+
export class HasManager extends Type.makeRelation<HasManager>(DXN.make('com.example.type.hasManager', '0.1.0'))({
|
|
146
|
+
source: Person,
|
|
147
|
+
target: Person,
|
|
148
|
+
})(Schema.Struct({})) {}
|
|
161
149
|
|
|
162
150
|
//
|
|
163
151
|
// EmployedBy
|
|
164
152
|
//
|
|
165
153
|
|
|
166
|
-
export
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
target: Organization,
|
|
154
|
+
export class EmployedBy extends Type.makeRelation<EmployedBy>(DXN.make('com.example.type.employedBy', '0.1.0'))({
|
|
155
|
+
source: Person,
|
|
156
|
+
target: Organization,
|
|
157
|
+
})(
|
|
158
|
+
Schema.Struct({
|
|
159
|
+
role: Schema.String,
|
|
160
|
+
since: Schema.optional(Schema.String),
|
|
174
161
|
}),
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
export type EmployedBy = Type.InstanceType<typeof EmployedBy>;
|
|
162
|
+
) {}
|
|
178
163
|
|
|
179
164
|
//
|
|
180
165
|
// RecordType
|
|
@@ -186,19 +171,19 @@ export namespace TestSchema {
|
|
|
186
171
|
WORK = 2,
|
|
187
172
|
}
|
|
188
173
|
|
|
189
|
-
export
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Schema.
|
|
193
|
-
Schema.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
174
|
+
export class Container extends Type.makeObject<Container>(DXN.make('com.example.type.container', '0.1.0'))(
|
|
175
|
+
Schema.Struct({
|
|
176
|
+
objects: Schema.Array(Ref.Ref(Obj.Unknown)),
|
|
177
|
+
records: Schema.Array(
|
|
178
|
+
Schema.partial(
|
|
179
|
+
Schema.Struct({
|
|
180
|
+
title: Schema.String,
|
|
181
|
+
description: Schema.String,
|
|
182
|
+
contacts: Schema.Array(Ref.Ref(Person)),
|
|
183
|
+
type: Schema.Enums(RecordType),
|
|
184
|
+
}),
|
|
185
|
+
),
|
|
199
186
|
),
|
|
200
|
-
),
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
export type Container = Type.InstanceType<typeof Container>;
|
|
187
|
+
}).pipe(Schema.partial),
|
|
188
|
+
) {}
|
|
204
189
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/QueryResult.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\n\nimport { type CleanupFn } from '@dxos/async';\n\nimport type * as Entity from './Entity';\n\n/**\n * Individual query result entry.\n */\nexport type Entry<T> = {\n id: string;\n\n /**\n * May not be present for remote results.\n */\n result?: T;\n\n match?: {\n // TODO(dmaretskyi): text positional info.\n\n /**\n * Higher means better match.\n */\n rank: number;\n };\n\n /**\n * Query resolution metadata.\n */\n // TODO(dmaretskyi): Rename to meta?\n resolution?: {\n // TODO(dmaretskyi): Make this more generic.\n source: 'remote' | 'local' | 'index';\n\n /**\n * Query resolution time in milliseconds.\n */\n time: number;\n };\n};\n\n/**\n * Invidual query result entry for a database Entity.\n */\nexport type EntityEntry<T extends Entity.Unknown = Entity.Unknown> = Entry<T>;\n\nexport type RunOptions = {\n timeout?: number;\n};\n\nexport type SubscriptionOptions = {\n /**\n * Fire the callback immediately.\n */\n fire?: boolean;\n};\n\n// TODO(burdon): Should T be constrained to Entity.Any?\nexport interface QueryResult<T> {\n /**\n * Currently available results along with their match metadata.\n */\n readonly entries: Entry<T>[];\n\n /**\n * Currently available results.\n */\n readonly results: T[];\n\n /**\n * Returns all known results.\n */\n run(opts?: RunOptions): Promise<T[]>;\n\n /**\n * Returns all known results along with their match metadata.\n */\n runEntries(opts?: RunOptions): Promise<Entry<T>[]>;\n\n /**\n * Returns currently available results synchronously.\n */\n runSync(): T[];\n\n /**\n * Returns currently available results synchronously along with their match metadata.\n */\n runSyncEntries(): Entry<T>[];\n\n /**\n * Returns first result.\n */\n first(opts?: RunOptions): Promise<T>;\n\n /**\n * Returns first result if there is one.\n */\n firstOrUndefined(opts?: RunOptions): Promise<T | undefined>;\n\n /**\n * Subscribes to changes in query results.\n */\n subscribe(callback?: (query: QueryResult<T>) => void, opts?: SubscriptionOptions): CleanupFn;\n\n /**\n * Self-updating atom. Updates automatically when query results change.\n *\n * Memoized per QueryResult instance — repeated accesses on the same instance return the same\n * Atom. Safe only when the QueryResult is itself held stable across re-renders (e.g. behind a\n * `useMemo`). It must NOT be used in graph-builder connectors/actions or other atom computes,\n * where `db.query(...)` is called fresh on each re-evaluation: every run constructs a new\n * QueryResult and so a new atom + subscription, leaking the previous ones. Use the memoized\n * {@link atom} family there instead.\n */\n readonly atom: Atom.Atom<T[]>;\n}\n\n/**\n * Effect that returns a QueryResult when evaluated, but also has shorthand methods for running the query or getting the first result.\n */\nexport interface QueryResultEffect<T, E, R> extends Effect.Effect<QueryResult<T>, E, R> {\n run: Effect.Effect<T[], E, R>;\n first: Effect.Effect<Option.Option<T>, E, R>;\n\n // TODO(dmaretskyi): Considering adding `atom`, but since `Database.query` is used in imperative code only, I dont think it will be useful.\n}\n"],
|
|
5
|
-
"mappings": ";AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
get,
|
|
3
|
-
set
|
|
4
|
-
} from "./chunk-4ZUHOTCG.mjs";
|
|
5
|
-
import {
|
|
6
|
-
DescriptionAnnotation,
|
|
7
|
-
Dictionary,
|
|
8
|
-
FieldLookupAnnotationId,
|
|
9
|
-
FormInlineAnnotation,
|
|
10
|
-
FormInputAnnotation,
|
|
11
|
-
GeneratorAnnotation,
|
|
12
|
-
GeneratorAnnotationId,
|
|
13
|
-
HiddenAnnotation,
|
|
14
|
-
IconAnnotation,
|
|
15
|
-
IconFromRefAnnotation,
|
|
16
|
-
Key,
|
|
17
|
-
LabelAnnotation,
|
|
18
|
-
ReferenceAnnotation,
|
|
19
|
-
ReferenceAnnotationId,
|
|
20
|
-
TypeAnnotation,
|
|
21
|
-
getDescriptionWithSchema,
|
|
22
|
-
getDictionary,
|
|
23
|
-
getFromAst,
|
|
24
|
-
getLabelWithSchema,
|
|
25
|
-
getTypeAnnotation,
|
|
26
|
-
getTypeIdentifierAnnotation,
|
|
27
|
-
makeUserAnnotation,
|
|
28
|
-
setDescriptionWithSchema,
|
|
29
|
-
setDictionary,
|
|
30
|
-
setLabelWithSchema
|
|
31
|
-
} from "./chunk-R5W6DXR4.mjs";
|
|
32
|
-
import {
|
|
33
|
-
__export
|
|
34
|
-
} from "./chunk-J5LGTIGS.mjs";
|
|
35
|
-
|
|
36
|
-
// src/Annotation.ts
|
|
37
|
-
var Annotation_exports = {};
|
|
38
|
-
__export(Annotation_exports, {
|
|
39
|
-
DescriptionAnnotation: () => DescriptionAnnotation,
|
|
40
|
-
Dictionary: () => Dictionary2,
|
|
41
|
-
FieldLookupAnnotationId: () => FieldLookupAnnotationId,
|
|
42
|
-
FormInlineAnnotation: () => FormInlineAnnotation,
|
|
43
|
-
FormInputAnnotation: () => FormInputAnnotation,
|
|
44
|
-
GeneratorAnnotation: () => GeneratorAnnotation,
|
|
45
|
-
GeneratorAnnotationId: () => GeneratorAnnotationId,
|
|
46
|
-
HiddenAnnotation: () => HiddenAnnotation,
|
|
47
|
-
IconAnnotation: () => IconAnnotation,
|
|
48
|
-
IconFromRefAnnotation: () => IconFromRefAnnotation,
|
|
49
|
-
Key: () => Key2,
|
|
50
|
-
LabelAnnotation: () => LabelAnnotation,
|
|
51
|
-
ReferenceAnnotation: () => ReferenceAnnotation,
|
|
52
|
-
ReferenceAnnotationId: () => ReferenceAnnotationId,
|
|
53
|
-
TypeAnnotation: () => TypeAnnotation,
|
|
54
|
-
TypeId: () => TypeId,
|
|
55
|
-
get: () => get2,
|
|
56
|
-
getDescriptionWithSchema: () => getDescriptionWithSchema,
|
|
57
|
-
getDictionary: () => getDictionary2,
|
|
58
|
-
getFromAst: () => getFromAst2,
|
|
59
|
-
getLabelWithSchema: () => getLabelWithSchema,
|
|
60
|
-
getTypeAnnotation: () => getTypeAnnotation,
|
|
61
|
-
getTypeIdentifierAnnotation: () => getTypeIdentifierAnnotation,
|
|
62
|
-
make: () => make,
|
|
63
|
-
set: () => set2,
|
|
64
|
-
setDescriptionWithSchema: () => setDescriptionWithSchema,
|
|
65
|
-
setDictionary: () => setDictionary2,
|
|
66
|
-
setLabelWithSchema: () => setLabelWithSchema
|
|
67
|
-
});
|
|
68
|
-
import * as Function from "effect/Function";
|
|
69
|
-
var TypeId = "~@dxos/echo/Annotation";
|
|
70
|
-
var Key2 = Key;
|
|
71
|
-
var make = makeUserAnnotation;
|
|
72
|
-
var get2 = Function.dual(2, (target, annotation) => {
|
|
73
|
-
return get(target, annotation);
|
|
74
|
-
});
|
|
75
|
-
var set2 = Function.dual(3, (target, annotation, value) => {
|
|
76
|
-
return set(target, annotation, value);
|
|
77
|
-
});
|
|
78
|
-
var getFromAst2 = Function.dual(2, (ast, annotation) => {
|
|
79
|
-
return getFromAst(ast, annotation);
|
|
80
|
-
});
|
|
81
|
-
var Dictionary2 = Dictionary;
|
|
82
|
-
var getDictionary2 = Function.dual(2, (values, annotation) => {
|
|
83
|
-
return getDictionary(values, annotation);
|
|
84
|
-
});
|
|
85
|
-
var setDictionary2 = Function.dual(3, (values, annotation, value) => {
|
|
86
|
-
return setDictionary(values, annotation, value);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
export {
|
|
90
|
-
TypeId,
|
|
91
|
-
Key2 as Key,
|
|
92
|
-
make,
|
|
93
|
-
get2 as get,
|
|
94
|
-
set2 as set,
|
|
95
|
-
getFromAst2 as getFromAst,
|
|
96
|
-
Dictionary2 as Dictionary,
|
|
97
|
-
getDictionary2 as getDictionary,
|
|
98
|
-
setDictionary2 as setDictionary,
|
|
99
|
-
Annotation_exports
|
|
100
|
-
};
|
|
101
|
-
//# sourceMappingURL=chunk-3PBP4V4O.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/Annotation.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nexport {\n DescriptionAnnotation,\n FieldLookupAnnotationId,\n FormInputAnnotation,\n FormInlineAnnotation,\n GeneratorAnnotation,\n GeneratorAnnotationId,\n type GeneratorAnnotationValue,\n LabelAnnotation,\n ReferenceAnnotation,\n ReferenceAnnotationId,\n type ReferenceAnnotationValue,\n HiddenAnnotation,\n TypeAnnotation,\n getDescriptionWithSchema,\n getLabelWithSchema,\n getTypeAnnotation,\n getTypeIdentifierAnnotation,\n setDescriptionWithSchema,\n setLabelWithSchema,\n IconAnnotation,\n IconFromRefAnnotation,\n} from './internal/Annotation';\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport * as Types from 'effect/Types';\n\nimport * as Entity from './Entity';\nimport * as internalAnnotations from './internal/Annotation';\n\nexport const TypeId = '~@dxos/echo/Annotation' as const;\nexport type TypeId = typeof TypeId;\n\n// TODO(dmaretskyi): Reconcile different get/set styles: mutate in-place, return.\n// TODO(dmaretskyi): Reconcile Annotation methods vs static functions.\n// TODO(dmaretskyi): Reconcile Annotation.Key vs DXN -- work-out approach to versioning.\n\n/**\n * Annotation is a typed property that can be assigned to a schema or an entity instance.\n */\nexport interface Annotation<T> {\n [TypeId]: {\n _Type: T;\n };\n\n // TODO(dmaretskyi): Make this a DXN?\n /**\n * Unique fully-qualified identifier for the annotation.\n * @example \"org.dxos.annotation.color\"\n */\n readonly key: Key;\n\n /**\n * Schema of the annotation value.\n */\n readonly schema: Schema.Schema<T, unknown, never>;\n\n /**\n * Get the annotation value from an Effect schema.\n *\n * Only accepts `Schema.Schema.Any` — to read an annotation off a `Type.Type`\n * entity, unwrap it first with `Type.getSchema(entity)`. This keeps the\n * annotation pipeline single-shaped and forces annotations to live on the\n * source schema, not on the post-construction Type entity.\n */\n get: (schema: Schema.Schema.Any) => Option.Option<T>;\n /**\n * Get the annotation value from the AST.\n */\n getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;\n /**\n * Set the annotation on an Effect schema.\n *\n * Only accepts `Schema.Schema.Any` — annotations must be applied to the\n * source schema BEFORE wrapping it with `Type.makeObject` / `Type.makeRelation`.\n * In a pipe, place every `Annotation.X.set(...)` before the `Type.make...` step.\n */\n set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;\n}\n\nexport const Key = internalAnnotations.Key;\nexport type Key = Schema.Schema.Type<typeof Key>;\n\ninterface MakeProps<T> {\n id: string;\n schema: Schema.Schema<T, any, never>;\n}\n\n/**\n * Create a new schema annotation.\n * Annotation can be assigned both to fields and to the schema itself.\n * Annotation is serialized with the schema.\n *\n * @example\n * ```ts\n * const ColorAnnotation = Annotation.make({\n * id: 'org.dxos.annotation.color',\n * schema: Schema.String,\n * });\n *\n * const schema = Schema.String.annotations(ColorAnnotation.set('red'));\n * ```\n */\nexport const make: <T>(props: MakeProps<T>) => Annotation<T> = internalAnnotations.makeUserAnnotation;\n\n/**\n * Get the value of an annotation from an entity instance or snapshot.\n * For schema-level reads use the annotation instance method (e.g. `ColorAnnotation.get(schema)`).\n * For getting an annotation value from a dictionary, use `getDictionary`.\n */\nexport const get: {\n <T>(annotation: Annotation<T>): (target: Entity.Unknown | Entity.Snapshot) => Option.Option<T>;\n <T>(target: Entity.Unknown | Entity.Snapshot, annotation: Annotation<T>): Option.Option<T>;\n} = Function.dual<\n <T>(annotation: Annotation<T>) => (target: Entity.Unknown | Entity.Snapshot) => Option.Option<T>,\n <T>(target: Entity.Unknown | Entity.Snapshot, annotation: Annotation<T>) => Option.Option<T>\n>(2, (target, annotation) => {\n return internalAnnotations.get(target, annotation);\n});\n\n/**\n * Set the value of an annotation on an entity instance.\n * For schema-level writes use the annotation instance method (e.g. `ColorAnnotation.set('red')`).\n * For setting an annotation value on a dictionary, use `setDictionary`.\n */\nexport const set: {\n <T>(annotation: Annotation<T>, value: T): (target: Entity.Mutable<Entity.Unknown>) => void;\n <T>(target: Entity.Mutable<Entity.Unknown>, annotation: Annotation<T>, value: T): void;\n} = Function.dual<\n <T>(annotation: Annotation<T>, value: T) => (target: Entity.Mutable<Entity.Unknown>) => void,\n <T>(target: Entity.Mutable<Entity.Unknown>, annotation: Annotation<T>, value: T) => void\n>(3, (target, annotation, value) => {\n return internalAnnotations.set(target, annotation, value);\n});\n\nexport const getFromAst: {\n <T>(annotation: Annotation<T>): (ast: SchemaAST.AST) => Option.Option<T>;\n <T>(ast: SchemaAST.AST, annotation: Annotation<T>): Option.Option<T>;\n} = Function.dual<\n <T>(annotation: Annotation<T>) => (ast: SchemaAST.AST) => Option.Option<T>,\n <T>(ast: SchemaAST.AST, annotation: Annotation<T>) => Option.Option<T>\n>(2, (ast, annotation) => {\n return internalAnnotations.getFromAst(ast, annotation);\n});\n\n/**\n * Set of annotation values.\n *\n * Can be used inside an object/relation schema:\n *\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * extensions: Annotation.Dictionary,\n * });\n * ```\n */\nexport const Dictionary = internalAnnotations.Dictionary;\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a Dictionary.\n */\nexport const getDictionary: {\n <T>(annotation: Annotation<T>): (values: Dictionary) => Option.Option<T>;\n <T>(values: Dictionary, annotation: Annotation<T>): Option.Option<T>;\n} = Function.dual<\n <T>(annotation: Annotation<T>) => (values: Dictionary) => Option.Option<T>,\n <T>(values: Dictionary, annotation: Annotation<T>) => Option.Option<T>\n>(2, (values, annotation) => {\n return internalAnnotations.getDictionary(values, annotation);\n});\n\n/**\n * Set the value of an annotation in a Dictionary.\n *\n * Can also be used within Obj.update callback:\n *\n * ```ts\n * Obj.update(obj, (obj) => {\n * Annotation.setDictionary(obj.annotations, ColorAnnotation, 'red');\n * });\n * ```\n */\nexport const setDictionary: {\n <T>(annotation: Annotation<T>, value: T): (values: Dictionary) => void;\n <T>(values: Types.Mutable<Dictionary>, annotation: Annotation<T>, value: T): void;\n} = Function.dual<\n <T>(annotation: Annotation<T>, value: T) => (values: Dictionary) => void,\n <T>(values: Types.Mutable<Dictionary>, annotation: Annotation<T>, value: T) => void\n>(3, (values, annotation, value) => {\n return internalAnnotations.setDictionary(values, annotation, value);\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;oBAAAA;EAAA;;;;;;;;aAAAC;EAAA;;;;;aAAAC;EAAA;uBAAAC;EAAA,kBAAAC;EAAA;;;;aAAAC;EAAA;uBAAAC;EAAA;;AA8BA,YAAYC,cAAc;AASnB,IAAMC,SAAS;AAkDf,IAAMC,OAA0BA;AAuBhC,IAAMC,OAAsEC;AAO5E,IAAMC,OAGAC,cAGX,GAAG,CAACC,QAAQC,eAAAA;AACZ,SAA2BH,IAAIE,QAAQC,UAAAA;AACzC,CAAA;AAOO,IAAMC,OAGAH,cAGX,GAAG,CAACC,QAAQC,YAAYE,UAAAA;AACxB,SAA2BD,IAAIF,QAAQC,YAAYE,KAAAA;AACrD,CAAA;AAEO,IAAMC,cAGAL,cAGX,GAAG,CAACM,KAAKJ,eAAAA;AACT,SAA2BG,WAAWC,KAAKJ,UAAAA;AAC7C,CAAA;AAcO,IAAMK,cAAiCA;AAMvC,IAAMC,iBAGAR,cAGX,GAAG,CAACS,QAAQP,eAAAA;AACZ,SAA2BM,cAAcC,QAAQP,UAAAA;AACnD,CAAA;AAaO,IAAMQ,iBAGAV,cAGX,GAAG,CAACS,QAAQP,YAAYE,UAAAA;AACxB,SAA2BM,cAAcD,QAAQP,YAAYE,KAAAA;AAC/D,CAAA;",
|
|
6
|
-
"names": ["Dictionary", "Key", "get", "getDictionary", "getFromAst", "set", "setDictionary", "Function", "TypeId", "Key", "make", "makeUserAnnotation", "get", "dual", "target", "annotation", "set", "value", "getFromAst", "ast", "Dictionary", "getDictionary", "values", "setDictionary"]
|
|
7
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Ref,
|
|
3
|
-
createEchoReferenceSchema,
|
|
4
|
-
getRefSavedTarget
|
|
5
|
-
} from "./chunk-WTQJHC75.mjs";
|
|
6
|
-
import {
|
|
7
|
-
Dictionary,
|
|
8
|
-
MetaId,
|
|
9
|
-
getDatabase,
|
|
10
|
-
getDictionary,
|
|
11
|
-
setDictionary
|
|
12
|
-
} from "./chunk-R5W6DXR4.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-4ZUHOTCG.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": "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",
|
|
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
|
-
}
|