@dxos/echo 0.8.4-main.d05673bc65 → 0.8.4-main.e00bdcdb52
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 +3 -3
- package/dist/lib/neutral/Database.mjs +8 -4
- package/dist/lib/neutral/Entity.mjs +16 -14
- package/dist/lib/neutral/Err.mjs +1 -1
- package/dist/lib/neutral/Extension.mjs +18 -0
- package/dist/lib/neutral/Extension.mjs.map +7 -0
- package/dist/lib/neutral/Feed.mjs +21 -17
- package/dist/lib/neutral/Filter.mjs +21 -13
- package/dist/lib/neutral/Format.mjs +3 -3
- package/dist/lib/neutral/JsonSchema.mjs +8 -8
- package/dist/lib/neutral/Key.mjs +1 -1
- package/dist/lib/neutral/Migration.mjs +17 -0
- package/dist/lib/neutral/Migration.mjs.map +7 -0
- package/dist/lib/neutral/Obj.mjs +16 -13
- package/dist/lib/neutral/Order.mjs +1 -1
- package/dist/lib/neutral/Query.mjs +19 -16
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +7 -7
- package/dist/lib/neutral/Relation.mjs +15 -14
- package/dist/lib/neutral/SchemaRegistry.mjs +1 -1
- package/dist/lib/neutral/Tag.mjs +14 -13
- package/dist/lib/neutral/Type.mjs +10 -10
- package/dist/lib/neutral/{chunk-VA2F47ZC.mjs → chunk-2T22UGGN.mjs} +68 -14
- package/dist/lib/neutral/chunk-2T22UGGN.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-FZO7LQO7.mjs → chunk-44HT3MEC.mjs} +2 -2
- package/dist/lib/neutral/{chunk-UFDK26FO.mjs → chunk-6VC3FI5E.mjs} +12 -8
- package/dist/lib/neutral/chunk-6VC3FI5E.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-DYDJBZEG.mjs → chunk-7JFW72MX.mjs} +51 -21
- package/dist/lib/neutral/chunk-7JFW72MX.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-7RVZT53K.mjs} +1 -1
- package/dist/lib/neutral/{chunk-BNCCGLJN.mjs → chunk-BICZKPQG.mjs} +1 -1
- package/dist/lib/neutral/chunk-CIWZ5MHQ.mjs +36 -0
- package/dist/lib/neutral/chunk-CIWZ5MHQ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-724GQYEN.mjs → chunk-DUNXPKAC.mjs} +4 -4
- package/dist/lib/neutral/{chunk-YWXWXIE5.mjs → chunk-FAW7PJRO.mjs} +2 -2
- package/dist/lib/neutral/{chunk-YWXWXIE5.mjs.map → chunk-FAW7PJRO.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-UTBRYVQC.mjs → chunk-FAYW32CW.mjs} +2 -2
- package/dist/lib/neutral/chunk-GWFFC34K.mjs +50 -0
- package/dist/lib/neutral/chunk-GWFFC34K.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-NXMFBIT5.mjs → chunk-I2MFJ76N.mjs} +59 -4
- package/dist/lib/neutral/chunk-I2MFJ76N.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-SEMVAGBM.mjs → chunk-JALF2CVV.mjs} +13 -23
- package/dist/lib/neutral/chunk-JALF2CVV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-NEGC54NE.mjs → chunk-KQUQZ3CB.mjs} +17 -19
- package/dist/lib/neutral/chunk-KQUQZ3CB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-NQRLRYJM.mjs → chunk-LOTZLYHB.mjs} +119 -12
- package/dist/lib/neutral/chunk-LOTZLYHB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-WYOKA6AE.mjs → chunk-N4B7FHQT.mjs} +2 -2
- package/dist/lib/neutral/{chunk-WYOKA6AE.mjs.map → chunk-N4B7FHQT.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-RMLF7JOZ.mjs → chunk-NKXEKBP5.mjs} +6 -22
- package/dist/lib/neutral/{chunk-RMLF7JOZ.mjs.map → chunk-NKXEKBP5.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-CIRHIEMW.mjs → chunk-NSMLBSFS.mjs} +18 -46
- package/dist/lib/neutral/chunk-NSMLBSFS.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OENWMTE6.mjs → chunk-QBIGOSRF.mjs} +2 -2
- package/dist/lib/neutral/{chunk-BOZZPUXE.mjs → chunk-QBLYZ4IV.mjs} +12 -65
- package/dist/lib/neutral/chunk-QBLYZ4IV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-KTAWP7GI.mjs → chunk-QEVM3JUP.mjs} +42 -7
- package/dist/lib/neutral/chunk-QEVM3JUP.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-43Y5DOS6.mjs → chunk-REP7WWAQ.mjs} +16 -66
- package/dist/lib/neutral/chunk-REP7WWAQ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-B5OXLWZL.mjs → chunk-TRPZU2HV.mjs} +2 -2
- package/dist/lib/neutral/{chunk-UI6MWK5W.mjs → chunk-TTCSATUD.mjs} +1 -1
- package/dist/lib/neutral/{chunk-FXEG7EOK.mjs → chunk-TW76K7H5.mjs} +3 -3
- package/dist/lib/neutral/{chunk-TQQZLKB7.mjs → chunk-UYJYDSD7.mjs} +193 -469
- package/dist/lib/neutral/chunk-UYJYDSD7.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-V72DY6LU.mjs} +1 -1
- package/dist/lib/neutral/{chunk-UBEZSGXY.mjs → chunk-ZISMEVKD.mjs} +1 -1
- package/dist/lib/neutral/{chunk-UBEZSGXY.mjs.map → chunk-ZISMEVKD.mjs.map} +2 -2
- package/dist/lib/neutral/index.mjs +38 -28
- package/dist/lib/neutral/internal/index.mjs +13 -9
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +30 -28
- package/dist/lib/neutral/testing/index.mjs.map +2 -2
- package/dist/types/src/Collection.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +13 -1
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Dataset.d.ts +2 -1
- package/dist/types/src/Dataset.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +17 -11
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +18 -18
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Extension.d.ts +80 -0
- package/dist/types/src/Extension.d.ts.map +1 -0
- package/dist/types/src/Extension.test.d.ts +2 -0
- package/dist/types/src/Extension.test.d.ts.map +1 -0
- package/dist/types/src/Feed.d.ts +37 -20
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +33 -4
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Filter.test.d.ts +2 -0
- package/dist/types/src/Filter.test.d.ts.map +1 -0
- package/dist/types/src/Json.d.ts +33 -0
- package/dist/types/src/Json.d.ts.map +1 -0
- package/dist/types/src/Json.test.d.ts +2 -0
- package/dist/types/src/Json.test.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +1 -1
- package/dist/types/src/Migration.d.ts +57 -0
- package/dist/types/src/Migration.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +41 -27
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +13 -2
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +17 -18
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +2 -2
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +3 -3
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/View.d.ts +1 -1
- package/dist/types/src/View.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +3 -2
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/util.d.ts +1 -1
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/relation.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/version.d.ts.map +1 -1
- package/dist/types/src/internal/Format/date.d.ts.map +1 -1
- package/dist/types/src/internal/Format/format.d.ts.map +1 -1
- package/dist/types/src/internal/Format/number.d.ts.map +1 -1
- package/dist/types/src/internal/Format/object.d.ts.map +1 -1
- package/dist/types/src/internal/Format/types.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +28 -28
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/common.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/ids.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/json-serializer.d.ts +4 -3
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/set-value.d.ts +1 -1
- package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -1
- package/dist/types/src/internal/Query.d.ts +10 -0
- package/dist/types/src/internal/Query.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref.d.ts +14 -1
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Type/compose.d.ts.map +1 -1
- package/dist/types/src/internal/Type/echo-schema.d.ts +2 -2
- package/dist/types/src/internal/Type/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -1
- package/dist/types/src/internal/common/api/meta.d.ts +3 -3
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -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.map +1 -1
- package/dist/types/src/internal/common/types/base.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.map +1 -1
- package/dist/types/src/internal/common/types/version.d.ts +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-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +53 -53
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/src/Collection.ts +5 -0
- package/src/Database.ts +49 -14
- package/src/Entity.ts +18 -12
- package/src/Extension.test.ts +235 -0
- package/src/Extension.ts +122 -0
- package/src/Feed.ts +79 -32
- package/src/Filter.test.ts +90 -0
- package/src/Filter.ts +66 -3
- package/src/Json.test.ts +175 -0
- package/src/Json.ts +102 -0
- package/src/Migration.ts +94 -0
- package/src/Obj.test.ts +105 -13
- package/src/Obj.ts +153 -33
- package/src/Query.test.ts +198 -8
- package/src/Query.ts +46 -1
- package/src/Relation.ts +24 -20
- package/src/Type.ts +1 -1
- package/src/View.ts +5 -0
- package/src/index.ts +4 -0
- package/src/internal/Annotation/annotations.test.ts +51 -2
- package/src/internal/Annotation/annotations.ts +19 -13
- package/src/internal/Annotation/sorting.ts +0 -1
- package/src/internal/Entity/api.ts +0 -1
- package/src/internal/Entity/object.ts +0 -1
- package/src/internal/Entity/version.ts +0 -1
- package/src/internal/Format/date.test.ts +0 -1
- package/src/internal/Format/format.test.ts +0 -1
- package/src/internal/JsonSchema/json-schema-type.ts +1 -1
- package/src/internal/JsonSchema/json-schema.test.ts +1 -2
- package/src/internal/JsonSchema/json-schema.ts +1 -2
- package/src/internal/Obj/clone.ts +1 -1
- package/src/internal/Obj/create-object.test.ts +2 -4
- package/src/internal/Obj/create-object.ts +2 -3
- package/src/internal/Obj/deleted.ts +1 -1
- package/src/internal/Obj/json-serializer.test.ts +4 -5
- package/src/internal/Obj/json-serializer.ts +22 -15
- package/src/internal/Obj/set-value.test.ts +24 -24
- package/src/internal/Obj/set-value.ts +1 -1
- package/src/internal/Query.ts +137 -0
- package/src/internal/Ref/ref-array.ts +0 -1
- package/src/internal/Ref/ref.test.ts +0 -1
- package/src/internal/Ref/ref.ts +18 -1
- package/src/internal/Type/compose.test.ts +0 -1
- package/src/internal/Type/echo-schema.ts +3 -4
- package/src/internal/Type/persistent-schema.ts +2 -2
- package/src/internal/common/README.md +1 -1
- package/src/internal/common/api/meta.ts +3 -3
- package/src/internal/common/proxy/change-context.ts +1 -1
- package/src/internal/common/proxy/change.test.ts +94 -94
- package/src/internal/common/proxy/errors.ts +2 -2
- package/src/internal/common/proxy/handler.test.ts +0 -2
- package/src/internal/common/proxy/make-object.ts +0 -1
- package/src/internal/common/proxy/ownership.ts +0 -1
- package/src/internal/common/proxy/reactive-array.ts +1 -1
- package/src/internal/common/proxy/reactive.test.ts +54 -0
- package/src/internal/common/proxy/reactive.ts +11 -3
- package/src/internal/common/proxy/typed-handler.test.ts +0 -1
- package/src/internal/common/proxy/typed-handler.ts +8 -10
- package/src/internal/common/proxy/typed-object.test.ts +2 -3
- package/src/internal/common/types/entity.ts +1 -1
- package/src/internal/common/types/meta.ts +0 -1
- package/src/internal/index.ts +1 -0
- package/src/testing/api.test.ts +0 -1
- package/src/testing/test-data.ts +0 -1
- package/dist/lib/neutral/chunk-43Y5DOS6.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BOZZPUXE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-CIRHIEMW.mjs.map +0 -7
- package/dist/lib/neutral/chunk-DYDJBZEG.mjs.map +0 -7
- package/dist/lib/neutral/chunk-KTAWP7GI.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NEGC54NE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NQRLRYJM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NXMFBIT5.mjs.map +0 -7
- package/dist/lib/neutral/chunk-SEMVAGBM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TQQZLKB7.mjs.map +0 -7
- package/dist/lib/neutral/chunk-UFDK26FO.mjs.map +0 -7
- package/dist/lib/neutral/chunk-VA2F47ZC.mjs.map +0 -7
- /package/dist/lib/neutral/{chunk-FZO7LQO7.mjs.map → chunk-44HT3MEC.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-ANHVGJI4.mjs.map → chunk-7RVZT53K.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-BNCCGLJN.mjs.map → chunk-BICZKPQG.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-724GQYEN.mjs.map → chunk-DUNXPKAC.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-UTBRYVQC.mjs.map → chunk-FAYW32CW.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-OENWMTE6.mjs.map → chunk-QBIGOSRF.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-B5OXLWZL.mjs.map → chunk-TRPZU2HV.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-UI6MWK5W.mjs.map → chunk-TTCSATUD.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-FXEG7EOK.mjs.map → chunk-TW76K7H5.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-OMUPQMLR.mjs.map → chunk-V72DY6LU.mjs.map} +0 -0
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isRef
|
|
3
|
+
} from "./chunk-TW76K7H5.mjs";
|
|
1
4
|
import {
|
|
2
5
|
Kind,
|
|
3
6
|
KindId,
|
|
4
7
|
SnapshotKindId
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-6VC3FI5E.mjs";
|
|
6
9
|
import {
|
|
7
10
|
EchoObjectSchema,
|
|
8
11
|
MetaId,
|
|
@@ -18,9 +21,11 @@ import {
|
|
|
18
21
|
getDatabase,
|
|
19
22
|
getKeys,
|
|
20
23
|
getMetaChecked,
|
|
24
|
+
getProxyTarget,
|
|
21
25
|
getSnapshot,
|
|
22
26
|
getValue,
|
|
23
27
|
isDeleted,
|
|
28
|
+
isProxy,
|
|
24
29
|
isVersion,
|
|
25
30
|
makeObject,
|
|
26
31
|
objectFromJSON,
|
|
@@ -33,7 +38,7 @@ import {
|
|
|
33
38
|
subscribe,
|
|
34
39
|
version,
|
|
35
40
|
versionValid
|
|
36
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-UYJYDSD7.mjs";
|
|
37
42
|
import {
|
|
38
43
|
ParentId,
|
|
39
44
|
getDescription,
|
|
@@ -45,15 +50,15 @@ import {
|
|
|
45
50
|
isInstanceOf,
|
|
46
51
|
setDescription,
|
|
47
52
|
setLabel
|
|
48
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-JALF2CVV.mjs";
|
|
49
54
|
import {
|
|
50
55
|
ANY_OBJECT_TYPENAME,
|
|
51
56
|
ANY_OBJECT_VERSION,
|
|
52
57
|
SchemaKindId
|
|
53
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-N4B7FHQT.mjs";
|
|
54
59
|
import {
|
|
55
60
|
GetReactiveError
|
|
56
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-ZISMEVKD.mjs";
|
|
57
62
|
import {
|
|
58
63
|
__export
|
|
59
64
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -67,7 +72,6 @@ __export(Obj_exports, {
|
|
|
67
72
|
Unknown: () => Unknown2,
|
|
68
73
|
VersionTypeId: () => VersionTypeId2,
|
|
69
74
|
addTag: () => addTag2,
|
|
70
|
-
change: () => change2,
|
|
71
75
|
clone: () => clone2,
|
|
72
76
|
compareVersions: () => compareVersions2,
|
|
73
77
|
decodeVersion: () => decodeVersion2,
|
|
@@ -106,17 +110,22 @@ __export(Obj_exports, {
|
|
|
106
110
|
sortByTypename: () => sortByTypename2,
|
|
107
111
|
subscribe: () => subscribe2,
|
|
108
112
|
toJSON: () => toJSON,
|
|
113
|
+
update: () => update,
|
|
114
|
+
updateFrom: () => updateFrom,
|
|
109
115
|
version: () => version2,
|
|
110
116
|
versionValid: () => versionValid2
|
|
111
117
|
});
|
|
112
118
|
import * as Effect from "effect/Effect";
|
|
119
|
+
import * as Equal from "effect/Equal";
|
|
113
120
|
import * as Function from "effect/Function";
|
|
114
121
|
import * as Option from "effect/Option";
|
|
115
122
|
import * as Schema from "effect/Schema";
|
|
123
|
+
import * as Utils from "effect/Utils";
|
|
116
124
|
import { createJsonPath } from "@dxos/effect";
|
|
117
|
-
import { assertArgument } from "@dxos/invariant";
|
|
125
|
+
import { assertArgument, invariant } from "@dxos/invariant";
|
|
118
126
|
import { ObjectId } from "@dxos/keys";
|
|
119
|
-
import { assumeType } from "@dxos/util";
|
|
127
|
+
import { assumeType, deepMapValues } from "@dxos/util";
|
|
128
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Obj.ts";
|
|
120
129
|
var Unknown2 = Schema.Struct({
|
|
121
130
|
id: Schema.String
|
|
122
131
|
}).pipe(
|
|
@@ -192,7 +201,7 @@ var getReactive = (snapshot) => Effect.gen(function* () {
|
|
|
192
201
|
var getReactiveOption = (snapshot) => getReactive(snapshot).pipe(Effect.map(Option.some), Effect.catchAll(() => Effect.succeed(Option.none())));
|
|
193
202
|
var getReactiveOrThrow = (snapshot) => Effect.runSync(getReactive(snapshot));
|
|
194
203
|
var clone2 = clone;
|
|
195
|
-
var
|
|
204
|
+
var update = (obj, callback) => {
|
|
196
205
|
change(obj, callback);
|
|
197
206
|
};
|
|
198
207
|
var getValue2 = (obj, path) => {
|
|
@@ -217,7 +226,11 @@ var getDXN2 = (entity) => {
|
|
|
217
226
|
assertArgument(!Schema.isSchema(entity), "obj", "Object should not be a schema.");
|
|
218
227
|
return getDXN(entity);
|
|
219
228
|
};
|
|
220
|
-
var getTypeDXN2 =
|
|
229
|
+
var getTypeDXN2 = (obj) => {
|
|
230
|
+
const type = getTypeDXN(obj);
|
|
231
|
+
invariant(type != null, "Corrupted object: missing type.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 315, S: void 0, A: ["type != null", "'Corrupted object: missing type.'"] });
|
|
232
|
+
return type;
|
|
233
|
+
};
|
|
221
234
|
var getSchema2 = getSchema;
|
|
222
235
|
var getTypename2 = (entity) => getTypename(entity);
|
|
223
236
|
var getDatabase2 = (entity) => getDatabase(entity);
|
|
@@ -247,6 +260,99 @@ var setParent = (entity, parent) => {
|
|
|
247
260
|
assumeType(parent);
|
|
248
261
|
entity[ParentId] = parent;
|
|
249
262
|
};
|
|
263
|
+
var valuesEqual = (left, right) => {
|
|
264
|
+
if (left === right) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
if (left === null || right === null) {
|
|
268
|
+
return left === right;
|
|
269
|
+
}
|
|
270
|
+
if (typeof left !== "object" || typeof right !== "object") {
|
|
271
|
+
return Utils.structuralRegion(() => Equal.equals(left, right));
|
|
272
|
+
}
|
|
273
|
+
if (isRef(left) && isRef(right)) {
|
|
274
|
+
return left.dxn.toString() === right.dxn.toString();
|
|
275
|
+
}
|
|
276
|
+
if (isRef(left) || isRef(right)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
280
|
+
if (left.length !== right.length) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
for (let index = 0; index < left.length; index++) {
|
|
284
|
+
if (!valuesEqual(left[index], right[index])) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
const leftRecord = left;
|
|
294
|
+
const rightRecord = right;
|
|
295
|
+
const keys = /* @__PURE__ */ new Set([
|
|
296
|
+
...Object.keys(leftRecord).filter((key) => key !== "id"),
|
|
297
|
+
...Object.keys(rightRecord).filter((key) => key !== "id")
|
|
298
|
+
]);
|
|
299
|
+
for (const key of keys) {
|
|
300
|
+
const leftHas = Object.hasOwn(leftRecord, key);
|
|
301
|
+
const rightHas = Object.hasOwn(rightRecord, key);
|
|
302
|
+
const leftValue = leftHas ? leftRecord[key] : void 0;
|
|
303
|
+
const rightValue = rightHas ? rightRecord[key] : void 0;
|
|
304
|
+
if (!valuesEqual(leftValue, rightValue)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
};
|
|
310
|
+
var prepareAssignValue = (value) => deepMapValues(value, (nested, recurse) => {
|
|
311
|
+
if (nested === null || typeof nested !== "object") {
|
|
312
|
+
return nested;
|
|
313
|
+
}
|
|
314
|
+
if (isRef(nested)) {
|
|
315
|
+
return nested;
|
|
316
|
+
}
|
|
317
|
+
if (Array.isArray(nested)) {
|
|
318
|
+
return recurse(nested);
|
|
319
|
+
}
|
|
320
|
+
if (isProxy(nested)) {
|
|
321
|
+
return recurse({
|
|
322
|
+
...getProxyTarget(nested)
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return recurse(nested);
|
|
326
|
+
});
|
|
327
|
+
var updateFrom = (target, source, options) => {
|
|
328
|
+
assertArgument(isObject(target), "Expected an echo object target.");
|
|
329
|
+
assertArgument(isObject(source), "Expected an echo object source.");
|
|
330
|
+
let keys = Object.keys(source).filter((key) => key !== "id");
|
|
331
|
+
if (options?.include !== void 0) {
|
|
332
|
+
const include = new Set(options.include.map((key) => String(key)));
|
|
333
|
+
keys = keys.filter((key) => include.has(key));
|
|
334
|
+
}
|
|
335
|
+
if (options?.exclude !== void 0) {
|
|
336
|
+
const exclude = new Set(options.exclude.map((key) => String(key)));
|
|
337
|
+
keys = keys.filter((key) => !exclude.has(key));
|
|
338
|
+
}
|
|
339
|
+
let updated = false;
|
|
340
|
+
const sourceRecord = source;
|
|
341
|
+
const targetRecord = target;
|
|
342
|
+
for (const key of keys) {
|
|
343
|
+
if (!Object.hasOwn(sourceRecord, key)) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const nextValue = sourceRecord[key];
|
|
347
|
+
const prevValue = Object.hasOwn(targetRecord, key) ? targetRecord[key] : void 0;
|
|
348
|
+
if (valuesEqual(prevValue, nextValue)) {
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
targetRecord[key] = prepareAssignValue(nextValue);
|
|
352
|
+
updated = true;
|
|
353
|
+
}
|
|
354
|
+
return updated;
|
|
355
|
+
};
|
|
250
356
|
var toJSON = (entity) => objectToJSON(entity);
|
|
251
357
|
var fromJSON = objectFromJSON;
|
|
252
358
|
var sortByLabel2 = sortByLabel;
|
|
@@ -271,7 +377,7 @@ export {
|
|
|
271
377
|
getReactiveOption,
|
|
272
378
|
getReactiveOrThrow,
|
|
273
379
|
clone2 as clone,
|
|
274
|
-
|
|
380
|
+
update,
|
|
275
381
|
getValue2 as getValue,
|
|
276
382
|
setValue2 as setValue,
|
|
277
383
|
ID,
|
|
@@ -296,6 +402,7 @@ export {
|
|
|
296
402
|
Parent,
|
|
297
403
|
getParent,
|
|
298
404
|
setParent,
|
|
405
|
+
updateFrom,
|
|
299
406
|
toJSON,
|
|
300
407
|
fromJSON,
|
|
301
408
|
sortByLabel2 as sortByLabel,
|
|
@@ -310,4 +417,4 @@ export {
|
|
|
310
417
|
version2 as version,
|
|
311
418
|
Obj_exports
|
|
312
419
|
};
|
|
313
|
-
//# sourceMappingURL=chunk-
|
|
420
|
+
//# sourceMappingURL=chunk-LOTZLYHB.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Obj.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Effect from 'effect/Effect';\nimport * as Equal from 'effect/Equal';\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as Utils from 'effect/Utils';\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { createJsonPath } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { type DXN, ObjectId } from '@dxos/keys';\nimport { assumeType, deepMapValues } from '@dxos/util';\n\nimport type * as Database from './Database';\nimport * as Entity from './Entity';\nimport * as Err from './Err';\nimport * as internal from './internal';\nimport { getProxyTarget, isProxy } from './internal/common/proxy/proxy-utils';\nimport * as objInternal from './internal/Obj';\nimport * as Ref from './Ref';\nimport type * as Type from './Type';\n\n/**\n * Base type for all ECHO objects.\n */\ninterface BaseObj extends internal.AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}\n\n/**\n * Object type with specific properties.\n */\nexport type OfShape<Props> = BaseObj & Props;\n\n/**\n * Object with no known properties beyond id and kind.\n * Use this when the object's schema/properties are not known.\n * For objects with arbitrary properties, use `Obj.AnyProps`.\n *\n * NOTE: This is a TypeScript type only, not a schema.\n * To validate that a value is an ECHO object, use `Schema.is(Type.Obj)`.\n */\nexport interface Unknown extends BaseObj {}\n\n/**\n * Runtime Effect schema for any ECHO object.\n * Use for validation, parsing, or as a reference target for collections.\n *\n * NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).\n * Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.\n *\n * @example\n * ```ts\n * // Structural type guard (accepts any object with id field)\n * if (Schema.is(Type.Obj)(unknownValue)) { ... }\n *\n * // ECHO instance type guard (checks KindId brand)\n * if (Obj.isObject(unknownValue)) { ... }\n *\n * // Reference to any object type\n * const Collection = Schema.Struct({\n * objects: Schema.Array(Ref.Ref(Obj.Unknown)),\n * }).pipe(Type.object({ typename: 'Collection', version: '0.1.0' }));\n * ```\n */\n// TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.\n// Effect Schema normalizes proxy objects to plain objects before calling filter predicates.\n// Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.\nexport const Unknown: Type.Obj<Unknown> = Schema.Struct({\n id: Schema.String,\n}).pipe(\n Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n // TODO(dmaretskyi): Clean this up.\n // NOTE: The EchoObjectSchema annotation is required for Ref.Ref(Obj.Unknown) to work.\n // The typename/version only satisfy ECHO schema machinery for reference targets.\n internal.EchoObjectSchema({ typename: internal.ANY_OBJECT_TYPENAME, version: internal.ANY_OBJECT_VERSION }),\n (schema) =>\n Object.assign(schema, {\n [internal.SchemaKindId]: (schema as any)[internal.SchemaKindId],\n }) as unknown as Type.Obj<Unknown>,\n);\n\n/**\n * Object with arbitrary properties.\n *\n * NOTE: Due to how TypeScript works, this type is not assignable to a specific schema type.\n * In that case, use `Obj.instanceOf` to check if an object is of a specific type.\n *\n * Prefer using `Obj.Unknown` when you don't need to access arbitrary properties.\n */\nexport interface Any extends BaseObj, internal.AnyProperties {}\n\n/**\n * Base type for snapshot objects (has SnapshotKindId instead of KindId).\n */\ninterface BaseSnapshot extends internal.AnyEntity {\n readonly [Entity.SnapshotKindId]: typeof Entity.Kind.Object;\n readonly id: ObjectId;\n}\n\n/**\n * Immutable snapshot of an ECHO object.\n * Branded with SnapshotKindId (not KindId).\n * Property values are frozen at the time the snapshot was created.\n * Returned by getSnapshot() and hooks like useObject().\n *\n * Snapshots are structurally identical to reactive objects but have a different brand,\n * making them distinguishable at the TypeScript level. Neither is assignable to the other.\n */\nexport type Snapshot<T extends Unknown = Unknown> = Omit<T, Entity.KindId> & BaseSnapshot;\n\n/**\n * JSON-encoded properties for objects.\n */\nexport interface BaseObjJson {\n id: string;\n}\n\nconst defaultMeta: internal.ObjectMeta = {\n keys: [],\n};\n\ntype MakePropsInternal<T extends Unknown> = {\n id?: ObjectId;\n [Meta]?: Partial<internal.ObjectMeta>;\n} & Entity.Properties<T>;\n\n// TODO(burdon): Should we allow the caller to set the id?\n/**\n * Props type for object creation with a given schema.\n */\nexport type MakeProps<S extends Schema.Schema.AnyNoContext> = {\n id?: ObjectId;\n [Meta]?: Partial<internal.ObjectMeta>;\n [Parent]?: Unknown;\n} & MakePropsInternal<Schema.Schema.Type<S>>;\n\n/**\n * Creates a new echo object of the given schema.\n * @param schema - Object schema.\n * @param props - Object properties.\n * @param meta - Object metadata (deprecated) -- pass with Obj.Meta.\n *\n * Meta can be passed as a symbol in `props`.\n *\n * Example:\n * ```ts\n * const obj = Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' });\n * ```\n *\n * Note: Only accepts object schemas, not relation schemas. Use `Relation.make` for relations.\n */\nexport const make = <S extends Type.AnyObj>(\n schema: S,\n props: NoInfer<MakeProps<S>>,\n): OfShape<Schema.Schema.Type<S>> => {\n assertArgument(\n internal.getTypeAnnotation(schema)?.kind === Entity.Kind.Object,\n 'schema',\n 'Expected an object schema',\n );\n\n let meta: internal.ObjectMeta | undefined = undefined;\n\n // Set default fields on meta on creation.\n if (props[internal.MetaId] != null) {\n meta = { ...structuredClone(defaultMeta), ...props[internal.MetaId] };\n delete props[internal.MetaId];\n }\n\n // Filter undefined values (Object.entries only returns string-keyed properties).\n const filterUndefined: any = Object.fromEntries(Object.entries(props).filter(([_, v]) => v !== undefined));\n\n // Copy symbol properties (like ParentId) that Object.entries doesn't include.\n for (const sym of Object.getOwnPropertySymbols(props)) {\n const value = (props as any)[sym];\n if (value !== undefined) {\n filterUndefined[sym] = value;\n }\n }\n\n return internal.makeObject<Schema.Schema.Type<S>>(schema, filterUndefined as any, {\n ...defaultMeta,\n ...meta,\n });\n};\n\n/**\n * Determine if object is an ECHO object.\n */\nexport const isObject = (obj: unknown): obj is Unknown => {\n assumeType<internal.InternalObjectProps>(obj);\n return typeof obj === 'object' && obj !== null && obj[Entity.KindId] === Entity.Kind.Object;\n};\n\nexport const isSnapshot = (obj: unknown): obj is Snapshot => {\n assumeType<internal.InternalObjectProps>(obj);\n return typeof obj === 'object' && obj !== null && (obj as any)[Entity.SnapshotKindId] === Entity.Kind.Object;\n};\n\n/**\n * Subscribe to object updates.\n * The callback is called synchronously when the object is modified.\n * Only accepts reactive objects (not snapshots).\n * @returns Unsubscribe function.\n */\nexport const subscribe = (obj: Unknown, callback: () => void): (() => void) => {\n return internal.subscribe(obj, callback);\n};\n\n//\n// Snapshot\n//\n\n/**\n * Returns an immutable snapshot of an object.\n * The snapshot is branded with SnapshotKindId instead of KindId,\n * making it distinguishable from the reactive object at the type level.\n */\nexport const getSnapshot: <T extends Unknown>(obj: T) => Snapshot<T> = objInternal.getSnapshot as any;\n\n/**\n * Returns the reactive version of an object from the database, given its snapshot.\n * Inverse of `Obj.getSnapshot`.\n *\n * Uses `Obj.getDatabase` internally to get the database from the snapshot,\n * then resolves the reactive object by ID.\n *\n * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).\n * @returns Effect that succeeds with the reactive object, or fails with `GetReactiveError`.\n * @example\n * ```ts\n * const snapshot = Obj.getSnapshot(obj);\n * const reactive = Obj.getReactive(snapshot).pipe(\n * Effect.runSync\n * );\n * ```\n */\nexport const getReactive = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<T, Err.GetReactiveError> =>\n Effect.gen(function* () {\n const db = internal.getDatabase(snapshot);\n if (!db) {\n return yield* Effect.fail(new Err.GetReactiveError({ reason: 'no-database', snapshotId: snapshot.id }));\n }\n const obj = db.getObjectById(snapshot.id);\n if (!obj) {\n return yield* Effect.fail(new Err.GetReactiveError({ reason: 'object-not-found', snapshotId: snapshot.id }));\n }\n return obj as T;\n });\n\n/**\n * Like `Obj.getReactive` but returns `Option.none()` instead of failing when the object\n * cannot be resolved (no database, object not found).\n *\n * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).\n * @returns Effect that succeeds with `Option.some(reactive)` or `Option.none()`.\n */\nexport const getReactiveOption = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<Option.Option<T>, never> =>\n getReactive(snapshot).pipe(\n Effect.map(Option.some),\n Effect.catchAll(() => Effect.succeed(Option.none())),\n );\n\n/**\n * Synchronous version of `Obj.getReactive`. Returns the reactive object or throws\n * `GetReactiveError` when the object cannot be resolved (no database, object not found).\n *\n * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).\n * @returns The reactive object.\n * @throws {Err.GetReactiveError} When the object cannot be resolved.\n */\nexport const getReactiveOrThrow = <T extends Unknown>(snapshot: Snapshot<T>): T =>\n Effect.runSync(getReactive(snapshot));\n\nexport type CloneOptions = {\n /**\n * Retain the original object's ID.\n * @default false\n */\n retainId?: boolean;\n\n /**\n * Recursively clone referenced objects.\n * @default false\n */\n deep?: boolean;\n};\n\n/**\n * Clones an object or relation.\n * This does not clone referenced objects, only the properties in the object.\n * @returns A new object with the same schema and properties.\n */\nexport const clone: <T extends Unknown>(obj: T, opts?: CloneOptions) => T = objInternal.clone;\n\n//\n// Change\n//\n\n/**\n * Makes all properties mutable recursively.\n * Used to provide a mutable view of an object within `Obj.update`.\n */\nexport type Mutable<T> = internal.Mutable<T>;\n\n/**\n * Perform mutations on an echo object within a controlled context.\n *\n * All mutations within the callback are batched and trigger a single notification\n * when the callback completes. Direct mutations outside of `Obj.update` will throw\n * an error for echo objects.\n *\n * This function also works with nested objects within echo objects (e.g., Template structs)\n * that are reactive at runtime.\n *\n * @param obj - The echo object to mutate. Use `Relation.update` for relations.\n * @param callback - The callback that performs mutations on the object.\n *\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John', age: 25 });\n *\n * // Mutate within Obj.update\n * Obj.update(person, (obj) => {\n * obj.name = 'Jane';\n * obj.age = 30;\n * });\n * // ONE notification fires here\n *\n * // Direct mutation throws\n * person.name = 'Bob'; // Error: Cannot modify outside Obj.update()\n * ```\n *\n * Note: Only accepts objects. Use `Relation.update` for relations.\n */\nexport const update = <T extends Unknown>(obj: T, callback: internal.ChangeCallback<T>): void => {\n internal.change(obj, callback);\n};\n\n/**\n * Get a deeply nested property from an object.\n *\n * Similar to lodash.get and getDeep from @dxos/util.\n * This is the complementary function to setValue.\n * Accepts both reactive objects and snapshots.\n *\n * @param obj - The ECHO object to get the property from.\n * @param path - Path to the property (array of keys).\n * @returns The value at the path, or undefined if not found.\n *\n * @example\n * ```ts\n * const person = Obj.make(Person, {\n * name: 'John',\n * addresses: [{ street: '123 Main St' }]\n * });\n *\n * Obj.getValue(person, ['addresses', 0, 'street']); // '123 Main St'\n * Obj.getValue(person, ['addresses', 1, 'street']); // undefined\n * ```\n */\nexport const getValue = (obj: Unknown | Snapshot, path: readonly (string | number)[]): any => {\n return internal.getValue(obj, createJsonPath(path));\n};\n\n/**\n * Set a deeply nested property on an object, using the object's schema to determine\n * whether to initialize nested data as an empty object or array.\n *\n * Similar to lodash.set and setDeep from @dxos/util, but schema-aware.\n * Must be called within an `Obj.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n *\n * @param obj - The mutable ECHO object to set the property on.\n * @param path - Path to the property (array of keys).\n * @param value - Value to set.\n * @returns The value that was set.\n *\n * @example\n * ```ts\n * const person = Obj.make(Person, { name: 'John' });\n * // Person schema has: addresses: Schema.Array(Address)\n * Obj.update(person, (obj) => {\n * Obj.setValue(obj, ['addresses', 0, 'street'], '123 Main St');\n * });\n * // Creates: person.addresses = [{ street: '123 Main St' }]\n * ```\n */\n// TODO(wittjosiah): Compute possible path values + type value based on generic object type.\nexport const setValue: (obj: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =\n objInternal.setValue as any;\n\n//\n// Type\n//\n\n// TODO(burdon): To discuss: prefer over ObjectId or Key.ObjectId or Type.ID?\nexport const ID = ObjectId;\nexport type ID = ObjectId;\n\n/**\n * Test if object or relation is an instance of a schema.\n * @example\n * ```ts\n * const john = Obj.make(Person, { name: 'John' });\n * const isPerson = Obj.instanceOf(Person);\n * if (isPerson(john)) {\n * // john is Person\n * }\n * ```\n */\nexport const instanceOf: {\n <S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;\n <S extends Type.AnyEntity>(schema: S, value: unknown): value is Schema.Schema.Type<S>;\n} = ((...args: [schema: Type.AnyEntity, value: unknown] | [schema: Type.AnyEntity]) => {\n if (args.length === 1) {\n return (entity: unknown) => internal.isInstanceOf(args[0], entity);\n }\n\n return internal.isInstanceOf(args[0], args[1]);\n}) as any;\n\n/**\n * Test if a snapshot is an instance of a schema.\n * Mirrors `instanceOf` but only accepts values branded with SnapshotKindId.\n * Use when the value is known to be a snapshot (e.g. from `getSnapshot` or `useObject`).\n *\n * @example\n * ```ts\n * const snapshot = Obj.getSnapshot(person);\n * if (Obj.snapshotOf(Person, snapshot)) {\n * // snapshot is Obj.Snapshot<Person>\n * }\n * ```\n */\nexport const snapshotOf: {\n <S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Snapshot<Schema.Schema.Type<S>>;\n <S extends Type.AnyEntity>(schema: S, value: unknown): value is Snapshot<Schema.Schema.Type<S>>;\n} = ((...args: [schema: Type.AnyEntity, value: unknown] | [schema: Type.AnyEntity]) => {\n const check = (entity: unknown) =>\n entity != null &&\n typeof entity === 'object' &&\n Entity.SnapshotKindId in entity &&\n internal.isInstanceOf(args[0], entity);\n\n if (args.length === 1) {\n return (entity: unknown) => check(entity);\n }\n\n return check(args[1]);\n}) as any;\n\n// TODO(dmaretskyi): Allow returning undefined.\n/**\n * Get the DXN of the object.\n * Accepts both reactive objects and snapshots.\n */\nexport const getDXN = (entity: Unknown | Snapshot): DXN => {\n assertArgument(!Schema.isSchema(entity), 'obj', 'Object should not be a schema.');\n return internal.getDXN(entity);\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:com.example.type.person:1.0.0\n * @throws If the object is missing its type (corrupted object).\n */\nexport const getTypeDXN = (obj: Unknown | Snapshot): DXN => {\n const type = internal.getTypeDXN(obj);\n invariant(type != null, 'Corrupted object: missing type.');\n return type;\n};\n\n/**\n * Get the schema of the object.\n * Returns the branded ECHO schema used to create the object.\n */\nexport const getSchema: (obj: Unknown | Snapshot) => Type.AnyEntity | undefined = internal.getSchema as any;\n\n/**\n * @returns The typename of the object's type.\n * Accepts both reactive objects and snapshots.\n * @example `com.example.type.person`\n */\nexport const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);\n\n//\n// Database\n//\n\n/**\n * Get the database the object belongs to.\n * Accepts both reactive objects and snapshots.\n */\nexport const getDatabase = (entity: Entity.Unknown | Entity.Snapshot): Database.Database | undefined =>\n internal.getDatabase(entity);\n\n//\n// Meta\n//\n\n/**\n * Property that accesses metadata for an entity.\n *\n * Alias for `Entity.Meta`.\n */\nexport const Meta = internal.MetaId;\n\n/**\n * Deeply read-only version of ObjectMeta.\n * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TypeScript error).\n */\nexport type ReadonlyMeta = internal.ReadonlyMeta;\n\n/**\n * Mutable meta type returned by `Obj.getMeta` inside an `Obj.update` callback.\n */\nexport type Meta = internal.Meta;\n\n// TODO(burdon): Narrow type.\n// TODO(dmaretskyi): Allow returning undefined.\n/**\n * Get the metadata for an object.\n * Returns mutable meta when passed a mutable object (inside `Obj.update` callback).\n * Returns read-only meta when passed a regular object or snapshot.\n *\n * @example\n * ```ts\n * // Read-only access outside change callback\n * const meta = Obj.getMeta(person); // ReadonlyMeta\n *\n * // Mutable access inside change callback\n * Obj.update(person, (obj) => {\n * const meta = Obj.getMeta(obj); // ObjectMeta (mutable)\n * meta.tags ??= [];\n * meta.tags.push('important');\n * });\n * ```\n */\n// TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\nexport function getMeta(entity: Mutable<Unknown>): Meta;\nexport function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;\nexport function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | ReadonlyMeta {\n return internal.getMetaChecked(entity);\n}\n\n/**\n * @returns Foreign keys for the object from the specified source.\n * Accepts both reactive objects and snapshots.\n */\nexport const getKeys: {\n (entity: Unknown | Snapshot, source: string): ForeignKey[];\n (source: string): (entity: Unknown | Snapshot) => ForeignKey[];\n} = Function.dual(2, (entity: Unknown | Snapshot, source?: string): ForeignKey[] => internal.getKeys(entity, source!));\n\n/**\n * Delete all keys from the object for the specified source.\n * Must be called within an `Obj.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const deleteKeys = (entity: Mutable<Unknown>, source: string): void => internal.deleteKeys(entity, source);\n\n/**\n * Add a tag to the object.\n * Must be called within an `Obj.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const addTag = (entity: Mutable<Unknown>, tag: string): void => internal.addTag(entity, tag);\n\n/**\n * Remove a tag from the object.\n * Must be called within an `Obj.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const removeTag = (entity: Mutable<Unknown>, tag: string): void => internal.removeTag(entity, tag);\n\n/**\n * Check if the object is deleted.\n * Accepts both reactive objects and snapshots.\n */\n// TODO(dmaretskyi): Default to `false`.\nexport const isDeleted = (entity: Unknown | Snapshot): boolean => objInternal.isDeleted(entity);\n\n//\n// Annotations\n//\n\n/**\n * Get the label of the object.\n * Accepts both reactive objects and snapshots.\n */\nexport const getLabel = (entity: Unknown | Snapshot): string | undefined => internal.getLabel(entity);\n\n/**\n * Set the label of the object.\n * Must be called within an `Obj.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);\n\n/**\n * Get the description of the object.\n * Accepts both reactive objects and snapshots.\n */\nexport const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);\n\n/**\n * Set the description of the object.\n * Must be called within an `Obj.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setDescription = (entity: Mutable<Unknown>, description: string): void =>\n internal.setDescription(entity, description);\n\n/**\n * Symbol to set parent when creating objects with `Obj.make`.\n * @example\n * ```ts\n * Obj.make(TestSchema.Person, {\n * [Obj.Parent]: parentObject,\n * name: 'John',\n * })\n * ```\n */\nexport const Parent: unique symbol = internal.ParentId as any;\n\n/**\n * Get the parent of an object.\n * The parent is always loaded together with the object.\n * Only objects are allowed to have a parent\n * @returns The parent object, or undefined if the object has no parent.\n */\nexport const getParent = (entity: Unknown | Snapshot): Unknown | undefined => {\n assertArgument(isObject(entity), 'Expected an object');\n assumeType<internal.InternalObjectProps>(entity);\n return entity[internal.ParentId] as Unknown | undefined;\n};\n\n/**\n * Sets the parent of an object.\n * If a parent (or any transitive parent) is deleted, the object will be deleted.\n * Only objects are allowed to have a parent.\n */\nexport const setParent = (entity: Unknown, parent: Any | undefined) => {\n assertArgument(isObject(entity), 'Expected an object');\n assertArgument(parent === undefined || isObject(parent), 'Expected an object');\n assumeType<internal.InternalObjectProps>(entity);\n assumeType<internal.InternalObjectProps | undefined>(parent);\n entity[internal.ParentId] = parent;\n};\n\ninterface UpdateFromOptions<T> {\n exclude?: (keyof T)[];\n include?: (keyof T)[];\n}\n\nconst valuesEqual = (left: unknown, right: unknown): boolean => {\n if (left === right) {\n return true;\n }\n if (left === null || right === null) {\n return left === right;\n }\n if (typeof left !== 'object' || typeof right !== 'object') {\n return Utils.structuralRegion(() => Equal.equals(left, right));\n }\n if (Ref.isRef(left) && Ref.isRef(right)) {\n return left.dxn.toString() === right.dxn.toString();\n }\n if (Ref.isRef(left) || Ref.isRef(right)) {\n return false;\n }\n if (Array.isArray(left) && Array.isArray(right)) {\n if (left.length !== right.length) {\n return false;\n }\n for (let index = 0; index < left.length; index++) {\n if (!valuesEqual(left[index], right[index])) {\n return false;\n }\n }\n return true;\n }\n if (Array.isArray(left) || Array.isArray(right)) {\n return false;\n }\n const leftRecord = left as Record<string, unknown>;\n const rightRecord = right as Record<string, unknown>;\n const keys = new Set([\n ...Object.keys(leftRecord).filter((key) => key !== 'id'),\n ...Object.keys(rightRecord).filter((key) => key !== 'id'),\n ]);\n for (const key of keys) {\n const leftHas = Object.hasOwn(leftRecord, key);\n const rightHas = Object.hasOwn(rightRecord, key);\n const leftValue = leftHas ? leftRecord[key] : undefined;\n const rightValue = rightHas ? rightRecord[key] : undefined;\n if (!valuesEqual(leftValue, rightValue)) {\n return false;\n }\n }\n return true;\n};\n\n/**\n * Breaks reactive proxies on assigned values so echo-db assignment accepts nested structs (same idea as link assignment).\n */\nconst prepareAssignValue = (value: unknown): unknown =>\n deepMapValues(value, (nested, recurse) => {\n if (nested === null || typeof nested !== 'object') {\n return nested;\n }\n if (Ref.isRef(nested)) {\n return nested;\n }\n if (Array.isArray(nested)) {\n return recurse(nested);\n }\n if (isProxy(nested)) {\n return recurse({ ...getProxyTarget(nested) });\n }\n return recurse(nested);\n });\n\n/**\n * For each key present on `source` (except `id`), assigns `target[key]` when the current value differs.\n * References are compared by target DXN; other values use Effect `Equal.equals` inside a structural region,\n * with recursive comparison for arrays and plain object-shaped property bags (excluding `id`).\n *\n * Must be called within an `Obj.update` callback.\n *\n * @returns Whether any property was updated.\n */\nexport const updateFrom = <T extends Unknown>(\n target: Mutable<T>,\n source: T,\n options?: UpdateFromOptions<T>,\n): boolean => {\n assertArgument(isObject(target), 'Expected an echo object target.');\n assertArgument(isObject(source), 'Expected an echo object source.');\n let keys = Object.keys(source as Record<string, unknown>).filter((key) => key !== 'id');\n if (options?.include !== undefined) {\n const include = new Set(options.include.map((key) => String(key)));\n keys = keys.filter((key) => include.has(key));\n }\n if (options?.exclude !== undefined) {\n const exclude = new Set(options.exclude.map((key) => String(key)));\n keys = keys.filter((key) => !exclude.has(key));\n }\n let updated = false;\n const sourceRecord = source as Record<string, unknown>;\n const targetRecord = target as Record<string, unknown>;\n for (const key of keys) {\n if (!Object.hasOwn(sourceRecord, key)) {\n continue;\n }\n const nextValue = sourceRecord[key];\n const prevValue = Object.hasOwn(targetRecord, key) ? targetRecord[key] : undefined;\n if (valuesEqual(prevValue, nextValue)) {\n continue;\n }\n targetRecord[key] = prepareAssignValue(nextValue) as never;\n updated = true;\n }\n return updated;\n};\n\n//\n// JSON\n//\n\n/**\n * JSON representation of an object.\n */\nexport type JSON = internal.ObjectJSON;\n\n/**\n * Converts object to its JSON representation.\n * Accepts both reactive objects and snapshots.\n *\n * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.\n */\nexport const toJSON = (entity: Unknown | Snapshot): JSON => objInternal.objectToJSON(entity);\n\n/**\n * Creates an object from its json representation, performing schema validation.\n * References and schemas will be resolvable if the `refResolver` is provided.\n *\n * The function must be async to support resolving the schema as well as the relation endpoints.\n *\n * @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.\n * @param options.dxn - Override object DXN. Changes the result of `Obj.getDXN`.\n * @param options.database - Database to associate with the object.\n */\nexport const fromJSON: (\n json: unknown,\n options?: { refResolver?: Ref.Resolver; dxn?: DXN; database?: Database.Database; parent?: Unknown },\n) => Promise<Unknown> = objInternal.objectFromJSON as any;\n\n/**\n * Comparator function type for sorting objects.\n * Accepts both reactive objects and snapshots.\n */\nexport type Comparator = internal.Comparator<Unknown | Snapshot>;\n\nexport const sortByLabel: Comparator = internal.sortByLabel as Comparator;\nexport const sortByTypename: Comparator = internal.sortByTypename as Comparator;\nexport const sort = (...comparators: Comparator[]): Comparator => internal.sort(...comparators) as Comparator;\n\n//\n// Version\n//\n\nexport const VersionTypeId = internal.VersionTypeId;\nexport type VersionCompareResult = internal.VersionCompareResult;\n\n/**\n * Represent object version.\n * May be backed by Automerge.\n * Objects with no history are not versioned.\n */\nexport type Version = internal.EntityVersion;\n\nexport const isVersion = internal.isVersion;\nexport const versionValid = internal.versionValid;\nexport const compareVersions = internal.compareVersions;\nexport const encodeVersion = internal.encodeVersion;\nexport const decodeVersion = internal.decodeVersion;\n\n/**\n * Returns the version of the object.\n * Accepts both reactive objects and snapshots.\n */\nexport const version = (entity: Unknown | Snapshot): Version => internal.version(entity);\n"],
|
|
5
|
+
"mappings": ";;;;;;;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ACA,cAAOA;EACP;AAWF,SAAA;;;AA8BO,IAAMK,WAAsCA;AAC5C,IAAMC,eAAWC;AAEtB,IAAAF,kBAAA;AACF,IAAUC,QAAA,IAAA,gBAAA,KAAA,GAAA,WAAA;AAcH,IAAME,iBAAwBA;AAC9B,IAAMC,aAAkBrE;AACxB,IAAMsE,gBAAgBtE;AACtB,IAAMuE,mBAAyBA;AAEtC,IAAAD,iBAAA;;;",
|
|
6
|
+
"names": ["Unknown", "VersionTypeId", "addTag", "clone", "compareVersions", "decodeVersion", "deleteKeys", "encodeVersion", "getDXN", "getDatabase", "getDescription", "getKeys", "getLabel", "getSchema", "getSnapshot", "getTypeDXN", "getTypename", "getValue", "isDeleted", "isVersion", "removeTag", "setDescription", "setLabel", "setValue", "sort", "sortByLabel", "sortByTypename", "subscribe", "version", "versionValid", "Effect", "Equal", "Function", "Option", "Schema", "Utils", "createJsonPath", "assertArgument", "invariant", "ObjectId", "assumeType", "deepMapValues", "Schema", "Record", "key", "version", "ANY_OBJECT_VERSION", "assign", "SchemaKindId", "defaultMeta", "keys", "meta", "undefined", "props", "internal", "structuredClone", "MetaId", "Object", "getOwnPropertySymbols", "value", "filterUndefined", "sym", "isSnapshot", "obj", "subscribe", "Effect", "GetReactiveError", "reason", "snapshotId", "snapshot", "id", "getValue", "setValue", "entity", "isInstanceOf", "args", "length", "check", "invariant", "type", "getTypename", "getDatabase", "getMetaChecked", "isDeleted", "assumeType", "ParentId", "assertArgument", "parent", "isObject", "right", "left", "Ref", "isRef", "Array", "isArray", "index", "leftRecord", "Set", "rightRecord", "rightHas", "leftValue", "leftHas", "rightValue", "valuesEqual", "nested", "isProxy", "getProxyTarget", "source", "filter", "include", "options", "map", "String", "exclude", "updated", "targetRecord", "hasOwn", "prevValue", "nextValue", "sortByTypename", "sort", "comparators", "versionValid", "compareVersions", "encodeVersion", "decodeVersion"]
|
|
7
|
+
}
|
|
@@ -9,7 +9,7 @@ var EntityKind = /* @__PURE__ */ (function(EntityKind2) {
|
|
|
9
9
|
return EntityKind2;
|
|
10
10
|
})({});
|
|
11
11
|
var EntityKindSchema = Schema.Enums(EntityKind);
|
|
12
|
-
var ANY_OBJECT_TYPENAME = "org.dxos.schema.
|
|
12
|
+
var ANY_OBJECT_TYPENAME = "org.dxos.schema.anyObject";
|
|
13
13
|
var ANY_OBJECT_VERSION = "0.0.0";
|
|
14
14
|
|
|
15
15
|
// src/internal/Annotation/util.ts
|
|
@@ -64,4 +64,4 @@ export {
|
|
|
64
64
|
unwrapOptional,
|
|
65
65
|
makeTypeJsonSchemaAnnotation
|
|
66
66
|
};
|
|
67
|
-
//# sourceMappingURL=chunk-
|
|
67
|
+
//# sourceMappingURL=chunk-N4B7FHQT.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/common/types/entity.ts", "../../../src/internal/Annotation/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.\n// Unique symbols cause TS4023 \"cannot be named\" errors when external packages\n// try to export types that reference this key (e.g., `export const Graph = ...`).\n// TypeScript cannot emit declaration files that reference unique symbols from\n// external modules. Using a string literal allows the type to be inlined in\n// declaration files, making the API portable across package boundaries.\n\n/**\n * String key used to identify the kind of an entity instance (object or relation).\n */\nexport const KindId = '~@dxos/echo/Kind' as const;\nexport type KindId = typeof KindId;\n\n/**\n * String key used to identify the kind of a schema (object schema or relation schema).\n * Parallels KindId which identifies instance kinds.\n */\nexport const SchemaKindId = '~@dxos/echo/SchemaKind' as const;\nexport type SchemaKindId = typeof SchemaKindId;\n\n/**\n * String key used to brand snapshot types.\n * Snapshots have SnapshotKindId instead of KindId, making them\n * distinguishable from reactive objects at the type level.\n */\nexport const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;\nexport type SnapshotKindId = typeof SnapshotKindId;\n\n/**\n * Kinds of entities stored in ECHO: objects and relations.\n */\nexport enum EntityKind {\n Object = 'object',\n Relation = 'relation',\n}\n\nexport const EntityKindSchema = Schema.Enums(EntityKind);\n\n/**\n * Typename for generic object references (Type.Obj / Ref.Ref(Obj.Unknown)).\n * Used when referencing any object without a specific schema.\n */\nexport const ANY_OBJECT_TYPENAME = 'org.dxos.schema.
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.\n// Unique symbols cause TS4023 \"cannot be named\" errors when external packages\n// try to export types that reference this key (e.g., `export const Graph = ...`).\n// TypeScript cannot emit declaration files that reference unique symbols from\n// external modules. Using a string literal allows the type to be inlined in\n// declaration files, making the API portable across package boundaries.\n\n/**\n * String key used to identify the kind of an entity instance (object or relation).\n */\nexport const KindId = '~@dxos/echo/Kind' as const;\nexport type KindId = typeof KindId;\n\n/**\n * String key used to identify the kind of a schema (object schema or relation schema).\n * Parallels KindId which identifies instance kinds.\n */\nexport const SchemaKindId = '~@dxos/echo/SchemaKind' as const;\nexport type SchemaKindId = typeof SchemaKindId;\n\n/**\n * String key used to brand snapshot types.\n * Snapshots have SnapshotKindId instead of KindId, making them\n * distinguishable from reactive objects at the type level.\n */\nexport const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;\nexport type SnapshotKindId = typeof SnapshotKindId;\n\n/**\n * Kinds of entities stored in ECHO: objects and relations.\n */\nexport enum EntityKind {\n Object = 'object',\n Relation = 'relation',\n}\n\nexport const EntityKindSchema = Schema.Enums(EntityKind);\n\n/**\n * Typename for generic object references (Type.Obj / Ref.Ref(Obj.Unknown)).\n * Used when referencing any object without a specific schema.\n */\nexport const ANY_OBJECT_TYPENAME = 'org.dxos.schema.anyObject';\n\n/**\n * Version for generic object references.\n */\nexport const ANY_OBJECT_VERSION = '0.0.0';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\n\nimport { EntityKind } from '../common/types';\n\nexport interface AnnotationHelper<T> {\n /**\n * Get the annotation value from the schema.\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 value on the schema.\n */\n set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;\n}\n\n/**\n * Note: only for system annotations.\n */\n// TODO(dmaretskyi): Rename to createSystemAnnotationHelper.\nexport const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {\n return {\n get: (schema) => SchemaAST.getAnnotation(schema.ast, id),\n getFromAst: (ast) => SchemaAST.getAnnotation(ast, id),\n set:\n (value) =>\n <S extends Schema.Schema.Any>(schema: S) =>\n schema.annotations({ [id]: value }) as S,\n };\n};\n\n/**\n * If property is optional returns the nested property, otherwise returns the property.\n */\n// TODO(wittjosiah): Is there a way to do this as a generic?\nexport const unwrapOptional = (property: SchemaAST.PropertySignature) => {\n if (!property.isOptional || !SchemaAST.isUnion(property.type)) {\n return property;\n }\n\n return property.type.types[0];\n};\n\n/**\n * @see JSONSchemaAnnotationId\n * @returns JSON-schema annotation so that the schema can be serialized with correct parameters.\n */\n// TODO(burdon): Required type.\nexport const makeTypeJsonSchemaAnnotation = (options: {\n identifier?: string;\n kind: EntityKind;\n typename: string;\n version: string;\n relationSource?: string;\n relationTarget?: string;\n}) => {\n assertArgument(!!options.relationSource === (options.kind === EntityKind.Relation), 'relationSource');\n assertArgument(!!options.relationTarget === (options.kind === EntityKind.Relation), 'relationTarget');\n\n const obj = {\n // TODO(dmaretskyi): Should this include the version?\n $id: options.identifier ?? DXN.fromTypename(options.typename).toString(),\n entityKind: options.kind,\n version: options.version,\n typename: options.typename,\n } as any;\n if (options.kind === EntityKind.Relation) {\n obj.relationSource = { $ref: options.relationSource };\n obj.relationTarget = { $ref: options.relationTarget };\n }\n\n return obj;\n};\n"],
|
|
5
5
|
"mappings": ";AAIA,YAAYA,YAAY;AAYjB,IAAMC,SAAS;AAOf,IAAMC,eAAe;AAQrB,IAAMC,iBAAiB;AAMvB,IAAKC,aAAAA,0BAAAA,aAAAA;;;SAAAA;;AAKL,IAAMC,mBAA0BC,aAAMF,UAAAA;AAMtC,IAAMG,sBAAsB;AAK5B,IAAMC,qBAAqB;;;AC/ClC,YAAYC,eAAe;AAE3B,SAASC,sBAAsB;AAC/B,SAASC,WAAW;AAuBb,IAAMC,yBAAyB,CAAIC,OAAAA;AACxC,SAAO;IACLC,KAAK,CAACC,WAAqBC,wBAAcD,OAAOE,KAAKJ,EAAAA;IACrDK,YAAY,CAACD,QAAkBD,wBAAcC,KAAKJ,EAAAA;IAClDM,KACE,CAACC,UACD,CAA8BL,WAC5BA,OAAOM,YAAY;MAAE,CAACR,EAAAA,GAAKO;IAAM,CAAA;EACvC;AACF;AAMO,IAAME,iBAAiB,CAACC,aAAAA;AAC7B,MAAI,CAACA,SAASC,cAAc,CAAWC,kBAAQF,SAASG,IAAI,GAAG;AAC7D,WAAOH;EACT;AAEA,SAAOA,SAASG,KAAKC,MAAM,CAAA;AAC7B;AAOO,IAAMC,+BAA+B,CAACC,YAAAA;AAQ3CC,iBAAe,CAAC,CAACD,QAAQE,oBAAoBF,QAAQG,SAASC,WAAWC,WAAW,gBAAA;AACpFJ,iBAAe,CAAC,CAACD,QAAQM,oBAAoBN,QAAQG,SAASC,WAAWC,WAAW,gBAAA;AAEpF,QAAME,MAAM;;IAEVC,KAAKR,QAAQS,cAAcC,IAAIC,aAAaX,QAAQY,QAAQ,EAAEC,SAAQ;IACtEC,YAAYd,QAAQG;IACpBY,SAASf,QAAQe;IACjBH,UAAUZ,QAAQY;EACpB;AACA,MAAIZ,QAAQG,SAASC,WAAWC,UAAU;AACxCE,QAAIL,iBAAiB;MAAEc,MAAMhB,QAAQE;IAAe;AACpDK,QAAID,iBAAiB;MAAEU,MAAMhB,QAAQM;IAAe;EACtD;AAEA,SAAOC;AACT;",
|
|
6
6
|
"names": ["Schema", "KindId", "SchemaKindId", "SnapshotKindId", "EntityKind", "EntityKindSchema", "Enums", "ANY_OBJECT_TYPENAME", "ANY_OBJECT_VERSION", "SchemaAST", "assertArgument", "DXN", "createAnnotationHelper", "id", "get", "schema", "getAnnotation", "ast", "getFromAst", "set", "value", "annotations", "unwrapOptional", "property", "isOptional", "isUnion", "type", "types", "makeTypeJsonSchemaAnnotation", "options", "assertArgument", "relationSource", "kind", "EntityKind", "Relation", "relationTarget", "obj", "$id", "identifier", "DXN", "fromTypename", "typename", "toString", "entityKind", "version", "$ref"]
|
|
7
7
|
}
|
|
@@ -4,17 +4,17 @@ import {
|
|
|
4
4
|
EchoSchema,
|
|
5
5
|
PersistentSchema,
|
|
6
6
|
isMutable
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-UYJYDSD7.mjs";
|
|
8
8
|
import {
|
|
9
9
|
getSchemaDXN,
|
|
10
10
|
getSchemaTypename,
|
|
11
11
|
getSchemaVersion,
|
|
12
12
|
getTypeAnnotation
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-JALF2CVV.mjs";
|
|
14
14
|
import {
|
|
15
15
|
EntityKind,
|
|
16
16
|
SchemaKindId
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-N4B7FHQT.mjs";
|
|
18
18
|
import {
|
|
19
19
|
__export
|
|
20
20
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -51,28 +51,12 @@ var getDXN = (schema) => {
|
|
|
51
51
|
};
|
|
52
52
|
var getTypename = (schema) => {
|
|
53
53
|
const typename = getSchemaTypename(schema);
|
|
54
|
-
invariant(typeof typename === "string" && !typename.startsWith("dxn:"), "Invalid typename", {
|
|
55
|
-
F: __dxlog_file,
|
|
56
|
-
L: 230,
|
|
57
|
-
S: void 0,
|
|
58
|
-
A: [
|
|
59
|
-
"typeof typename === 'string' && !typename.startsWith('dxn:')",
|
|
60
|
-
"'Invalid typename'"
|
|
61
|
-
]
|
|
62
|
-
});
|
|
54
|
+
invariant(typeof typename === "string" && !typename.startsWith("dxn:"), "Invalid typename", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 70, S: void 0, A: ["typeof typename === 'string' && !typename.startsWith('dxn:')", "'Invalid typename'"] });
|
|
63
55
|
return typename;
|
|
64
56
|
};
|
|
65
57
|
var getVersion = (schema) => {
|
|
66
58
|
const version = getSchemaVersion(schema);
|
|
67
|
-
invariant(typeof version === "string" && version.match(/^\d+\.\d+\.\d+$/), "Invalid version", {
|
|
68
|
-
F: __dxlog_file,
|
|
69
|
-
L: 240,
|
|
70
|
-
S: void 0,
|
|
71
|
-
A: [
|
|
72
|
-
"typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/)",
|
|
73
|
-
"'Invalid version'"
|
|
74
|
-
]
|
|
75
|
-
});
|
|
59
|
+
invariant(typeof version === "string" && version.match(/^\d+\.\d+\.\d+$/), "Invalid version", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 78, S: void 0, A: ["typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/)", "'Invalid version'"] });
|
|
76
60
|
return version;
|
|
77
61
|
};
|
|
78
62
|
var isMutable2 = isMutable;
|
|
@@ -94,4 +78,4 @@ export {
|
|
|
94
78
|
getMeta,
|
|
95
79
|
Type_exports
|
|
96
80
|
};
|
|
97
|
-
//# sourceMappingURL=chunk-
|
|
81
|
+
//# sourceMappingURL=chunk-NKXEKBP5.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Type.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport type * as Schema from 'effect/Schema';\n\nimport { type EncodedReference } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { type DXN } from '@dxos/keys';\nimport { type ToMutable } from '@dxos/util';\n\nimport type * as Entity from './Entity';\nimport * as
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;mBAAAA;EAAA;;;;;AASA,SAASC,iBAAiB;;
|
|
6
|
-
"names": ["isMutable", "invariant", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport type * as Schema from 'effect/Schema';\n\nimport { type EncodedReference } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { type DXN } from '@dxos/keys';\nimport { type ToMutable } from '@dxos/util';\n\nimport type * as Entity from './Entity';\nimport * as internal from './internal';\nimport * as typeInternal from './internal/Type';\nimport type * as ObjModule from './Obj';\nimport type * as RelationModule from './Relation';\n\n/**\n * Dynamic type that can be constructed, mutated, and persisted in the ECHO database.\n */\nexport const RuntimeType = typeInternal.EchoSchema;\n\n/**\n * Dynamic type that can be constructed, mutated, and persisted in the ECHO database.\n */\nexport type RuntimeType = typeInternal.EchoSchema;\n\n//\n// Internal types (not exported)\n//\n\n/**\n * Type that marks a schema as an ECHO schema.\n * The value indicates the entity kind (Object or Relation).\n */\ntype EchoSchemaKind<K extends internal.EntityKind = internal.EntityKind> = {\n readonly [internal.SchemaKindId]: K;\n};\n\n//\n// Obj - Runtime schema for any ECHO object\n//\n\n/**\n * TypeScript type for an ECHO object schema.\n * `T` is the instance type produced by the schema.\n * `Fields` is the optional struct fields type for introspection.\n *\n * @example\n * ```ts\n * const PersonSchema: Type.Obj<Person> = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.object({ typename: 'Person', version: '0.1.0' }));\n *\n * // Access fields for introspection:\n * Object.keys(PersonSchema.fields); // ['name']\n * ```\n */\nexport interface Obj<T, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>\n extends\n internal.TypeMeta,\n EchoSchemaKind<internal.EntityKind.Object>,\n Schema.AnnotableClass<\n Obj<T, Fields>,\n Entity.OfKind<typeof Entity.Kind.Object> & T,\n Schema.Simplify<ObjModule.BaseObjJson & ToMutable<T>>,\n never\n > {\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Structural base type for any ECHO object schema.\n * Accepts both static schemas (created with Type.object()) and EchoSchema.\n * NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.\n * Use Type.isObjectSchema() for runtime type guards.\n */\ntype ObjectSchemaBase = Schema.Schema.AnyNoContext & {\n readonly typename: string;\n readonly version: string;\n};\n\n/**\n * Type that represents any ECHO object schema.\n * Accepts both static schemas (Type.object()) and mutable schemas (EchoSchema).\n */\nexport type AnyObj = ObjectSchemaBase;\n\n/**\n * Factory function to create an ECHO object schema.\n * Adds object metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.object({ typename: 'com.example.type.person', version: '0.1.0' }));\n * ```\n */\nexport const object: {\n (opts: internal.TypeMeta): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;\n} = internal.EchoObjectSchema as any;\n\n//\n// PersistentType (Schema stored in database)\n//\n\nexport const PersistentType: Obj<typeInternal.PersistentSchema> = typeInternal.PersistentSchema as any;\n\nexport interface PersistentType extends Schema.Schema.Type<typeof PersistentType> {}\n\n/**\n * TypeScript type for an ECHO relation schema.\n * `T` is the instance type produced by the schema (excluding source/target).\n * `Source` and `Target` are the endpoint types.\n * `Fields` is the optional struct fields type for introspection.\n */\nexport interface Relation<T, Source, Target, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>\n extends\n internal.TypeMeta,\n EchoSchemaKind<internal.EntityKind.Relation>,\n Schema.AnnotableClass<\n Relation<T, Source, Target, Fields>,\n Entity.OfKind<typeof Entity.Kind.Relation> & RelationModule.Endpoints<Source, Target> & T,\n Schema.Simplify<RelationModule.BaseRelationJson & ToMutable<T>>,\n never\n > {\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Structural base type for any ECHO relation schema.\n * Accepts static schemas (created with Type.relation()).\n * NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.\n * Use Type.isRelationSchema() for runtime type guards.\n */\ntype RelationSchemaBase = Schema.Schema.AnyNoContext & {\n readonly typename: string;\n readonly version: string;\n};\n\n/**\n * Type that represents any ECHO relation schema.\n * Accepts static schemas (Type.relation()).\n */\nexport type AnyRelation = RelationSchemaBase;\n\n/**\n * Factory function to create an ECHO relation schema.\n * Adds relation metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const WorksFor = Schema.Struct({\n * role: Schema.String,\n * }).pipe(Type.relation({\n * typename: 'com.example.type.works-for',\n * version: '0.1.0',\n * source: Person,\n * target: Company,\n * }));\n * ```\n */\nexport const relation: {\n <SourceSchema extends Schema.Schema.AnyNoContext, TargetSchema extends Schema.Schema.AnyNoContext>(\n opts: internal.EchoRelationSchemaOptions<SourceSchema, TargetSchema>,\n ): <Self extends Schema.Schema.Any>(\n self: Self,\n ) => Relation<Schema.Schema.Type<Self>, Schema.Schema.Type<SourceSchema>, Schema.Schema.Type<TargetSchema>>;\n} = internal.EchoRelationSchema as any;\n\n/**\n * Type alias for any ECHO entity schema (object or relation).\n * Use this in type annotations for schema parameters.\n */\nexport type AnyEntity = AnyObj | AnyRelation;\n\n/**\n * Type guard to check if a schema is an object schema.\n * NOTE: This checks SCHEMAS, not instances. Use Obj.isObject for instances.\n */\nexport const isObjectSchema = (schema: AnyEntity): schema is AnyObj => {\n return (schema as any)[internal.SchemaKindId] === internal.EntityKind.Object;\n};\n\n/**\n * Type guard to check if a schema is a relation schema.\n * NOTE: This checks SCHEMAS, not instances. Use Relation.isRelation for instances.\n */\nexport const isRelationSchema = (schema: AnyEntity): schema is AnyRelation => {\n return (schema as any)[internal.SchemaKindId] === internal.EntityKind.Relation;\n};\n\n/**\n * Type that represents any Ref schema (with unknown target type).\n * This is a schema type, not an instance type.\n */\nexport type AnyRef = Schema.Schema<internal.Ref<any>, EncodedReference>;\n\n//\n// Schema utility functions\n//\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:com.example.type.person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: AnyEntity): DXN | undefined => {\n return internal.getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `com.example.type.person`.\n */\nexport const getTypename = (schema: AnyEntity): string => {\n const typename = internal.getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: AnyEntity): string => {\n const version = internal.getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = typeInternal.isMutable;\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = internal.TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: AnyEntity): Meta | undefined => {\n return internal.getTypeAnnotation(schema);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;mBAAAA;EAAA;;;;;AASA,SAASC,iBAAiB;AAU1B,IAAA,eAAA;;AA2FA,IAAA,SAAA;;;AAmFE,IAAA,iBAAA,CAAA,WAAA;AAEF,SAAA,OAAA,YAAA,MAAA,WAAA;;AAME,IAAA,mBAAA,CAAA,WAAA;AAQA,SAAA,OAAA,YAAA,MAAA,WAAA;AACF;AAWE,IAAA,SAAA,CAAA,WAAA;AAEF,SAAA,aAAA,MAAA;;AAMEC,IAAU,cAAOC,CAAAA,WAAa;AAC9B,QAAA,WAAOA,kBAAAA,MAAAA;AACP,YAAA,OAAA,aAAA,YAAA,CAAA,SAAA,WAAA,MAAA,GAAA,oBAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,QAAA,GAAA,CAAA,gEAAA,oBAAA,EAAA,CAAA;AAEF,SAAA;;AAMED,IAAU,aAAOE,CAAAA,WAAY;AAC7B,QAAA,UAAOA,iBAAAA,MAAAA;AACP,YAAA,OAAA,YAAA,YAAA,QAAA,MAAA,iBAAA,GAAA,mBAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,QAAA,GAAA,CAAA,wEAAA,mBAAA,EAAA,CAAA;AAEF,SAAA;;;AAeE,IAAA,UAAA,CAAA,WAAA;;;",
|
|
6
|
+
"names": ["isMutable", "invariant", "invariant", "typename", "version"]
|
|
7
7
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Unknown
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LOTZLYHB.mjs";
|
|
4
4
|
import {
|
|
5
5
|
KindId,
|
|
6
6
|
SnapshotKindId
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-6VC3FI5E.mjs";
|
|
8
8
|
import {
|
|
9
9
|
ATTR_RELATION_SOURCE,
|
|
10
10
|
ATTR_RELATION_TARGET,
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
sortByTypename,
|
|
37
37
|
subscribe,
|
|
38
38
|
version
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-UYJYDSD7.mjs";
|
|
40
40
|
import {
|
|
41
41
|
ParentId,
|
|
42
42
|
getDescription,
|
|
@@ -47,11 +47,11 @@ import {
|
|
|
47
47
|
getTypename,
|
|
48
48
|
setDescription,
|
|
49
49
|
setLabel
|
|
50
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-JALF2CVV.mjs";
|
|
51
51
|
import {
|
|
52
52
|
EntityKind,
|
|
53
53
|
SchemaKindId
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-N4B7FHQT.mjs";
|
|
55
55
|
import {
|
|
56
56
|
__export
|
|
57
57
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -65,7 +65,6 @@ __export(Relation_exports, {
|
|
|
65
65
|
Unknown: () => Unknown3,
|
|
66
66
|
VersionTypeId: () => VersionTypeId2,
|
|
67
67
|
addTag: () => addTag2,
|
|
68
|
-
change: () => change2,
|
|
69
68
|
deleteKeys: () => deleteKeys2,
|
|
70
69
|
getDXN: () => getDXN2,
|
|
71
70
|
getDatabase: () => getDatabase2,
|
|
@@ -96,6 +95,7 @@ __export(Relation_exports, {
|
|
|
96
95
|
sortByTypename: () => sortByTypename2,
|
|
97
96
|
subscribe: () => subscribe2,
|
|
98
97
|
toJSON: () => toJSON,
|
|
98
|
+
update: () => update,
|
|
99
99
|
version: () => version2
|
|
100
100
|
});
|
|
101
101
|
import * as Schema from "effect/Schema";
|
|
@@ -116,7 +116,7 @@ var Unknown3 = Schema.Struct({
|
|
|
116
116
|
// NOTE: The EchoRelationSchema annotation is required for Ref.Ref(Relation.Unknown) to work.
|
|
117
117
|
// The typename/version/source/target only satisfy ECHO schema machinery for reference targets.
|
|
118
118
|
EchoRelationSchema({
|
|
119
|
-
typename: "org.dxos.schema.
|
|
119
|
+
typename: "org.dxos.schema.anyRelation",
|
|
120
120
|
version: "0.0.0",
|
|
121
121
|
source: Unknown,
|
|
122
122
|
target: Unknown
|
|
@@ -161,63 +161,35 @@ var getSourceDXN = (value) => {
|
|
|
161
161
|
assertArgument(isRelation(value), "Expected a relation");
|
|
162
162
|
assumeType(value);
|
|
163
163
|
const dxn = value[RelationSourceDXNId];
|
|
164
|
-
invariant(dxn instanceof DXN, void 0, {
|
|
165
|
-
F: __dxlog_file,
|
|
166
|
-
L: 214,
|
|
167
|
-
S: void 0,
|
|
168
|
-
A: [
|
|
169
|
-
"dxn instanceof DXN",
|
|
170
|
-
""
|
|
171
|
-
]
|
|
172
|
-
});
|
|
164
|
+
invariant(dxn instanceof DXN, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 100, S: void 0, A: ["dxn instanceof DXN", ""] });
|
|
173
165
|
return dxn;
|
|
174
166
|
};
|
|
175
167
|
var getTargetDXN = (value) => {
|
|
176
168
|
assertArgument(isRelation(value), "Expected a relation");
|
|
177
169
|
assumeType(value);
|
|
178
170
|
const dxn = value[RelationTargetDXNId];
|
|
179
|
-
invariant(dxn instanceof DXN, void 0, {
|
|
180
|
-
F: __dxlog_file,
|
|
181
|
-
L: 227,
|
|
182
|
-
S: void 0,
|
|
183
|
-
A: [
|
|
184
|
-
"dxn instanceof DXN",
|
|
185
|
-
""
|
|
186
|
-
]
|
|
187
|
-
});
|
|
171
|
+
invariant(dxn instanceof DXN, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 111, S: void 0, A: ["dxn instanceof DXN", ""] });
|
|
188
172
|
return dxn;
|
|
189
173
|
};
|
|
190
174
|
var getSource = (relation) => {
|
|
191
175
|
assertArgument(isRelation(relation), "Expected a relation");
|
|
192
176
|
assumeType(relation);
|
|
193
177
|
const obj = relation[RelationSourceId];
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
S: void 0,
|
|
198
|
-
A: [
|
|
199
|
-
"obj !== undefined",
|
|
200
|
-
"`Invalid source: ${relation.id}`"
|
|
201
|
-
]
|
|
202
|
-
});
|
|
178
|
+
if (obj === void 0) {
|
|
179
|
+
throw new Error(`Relation source could not be resolved.`);
|
|
180
|
+
}
|
|
203
181
|
return obj;
|
|
204
182
|
};
|
|
205
183
|
var getTarget = (relation) => {
|
|
206
184
|
assertArgument(isRelation(relation), "Expected a relation");
|
|
207
185
|
assumeType(relation);
|
|
208
186
|
const obj = relation[RelationTargetId];
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
S: void 0,
|
|
213
|
-
A: [
|
|
214
|
-
"obj !== undefined",
|
|
215
|
-
"`Invalid target: ${relation.id}`"
|
|
216
|
-
]
|
|
217
|
-
});
|
|
187
|
+
if (obj === void 0) {
|
|
188
|
+
throw new Error(`Relation target could not be resolved.`);
|
|
189
|
+
}
|
|
218
190
|
return obj;
|
|
219
191
|
};
|
|
220
|
-
var
|
|
192
|
+
var update = (relation, callback) => {
|
|
221
193
|
change(relation, callback);
|
|
222
194
|
};
|
|
223
195
|
var getSnapshot2 = getSnapshot;
|
|
@@ -265,7 +237,7 @@ export {
|
|
|
265
237
|
getTargetDXN,
|
|
266
238
|
getSource,
|
|
267
239
|
getTarget,
|
|
268
|
-
|
|
240
|
+
update,
|
|
269
241
|
getSnapshot2 as getSnapshot,
|
|
270
242
|
subscribe2 as subscribe,
|
|
271
243
|
getValue2 as getValue,
|
|
@@ -295,4 +267,4 @@ export {
|
|
|
295
267
|
version2 as version,
|
|
296
268
|
Relation_exports
|
|
297
269
|
};
|
|
298
|
-
//# sourceMappingURL=chunk-
|
|
270
|
+
//# sourceMappingURL=chunk-NSMLBSFS.mjs.map
|