@dxos/echo 0.8.4-main.21d9917 → 0.8.4-main.2244d791bb
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/{browser → neutral}/Annotation.mjs +7 -5
- package/dist/lib/neutral/Database.mjs +45 -0
- package/dist/lib/{browser → neutral}/Entity.mjs +8 -9
- package/dist/lib/{browser → neutral}/Err.mjs +4 -3
- package/dist/lib/{browser → neutral}/Filter.mjs +9 -10
- package/dist/lib/{browser → neutral}/Format.mjs +4 -5
- package/dist/lib/neutral/JsonSchema.mjs +19 -0
- package/dist/lib/{browser → neutral}/Key.mjs +2 -3
- package/dist/lib/{node-esm → neutral}/Obj.mjs +23 -10
- package/dist/lib/{browser → neutral}/Order.mjs +2 -3
- package/dist/lib/neutral/Query.mjs +26 -0
- package/dist/lib/neutral/QueryResult.mjs +2 -0
- package/dist/lib/neutral/Ref.mjs +22 -0
- package/dist/lib/{browser → neutral}/Relation.mjs +9 -10
- package/dist/lib/neutral/SchemaRegistry.mjs +2 -0
- package/dist/lib/neutral/Tag.mjs +25 -0
- package/dist/lib/{browser → neutral}/Type.mjs +8 -9
- package/dist/lib/{browser/chunk-W5D2GWAW.mjs → neutral/chunk-36GDMODZ.mjs} +5 -6
- package/dist/lib/{browser/chunk-W5D2GWAW.mjs.map → neutral/chunk-36GDMODZ.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-ZHXZGIXD.mjs → neutral/chunk-4L6DOFXP.mjs} +1 -3
- package/dist/lib/{browser/chunk-ZHXZGIXD.mjs.map → neutral/chunk-4L6DOFXP.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-NOPVNWPT.mjs → neutral/chunk-5MGEVDUW.mjs} +73 -8
- package/dist/lib/neutral/chunk-5MGEVDUW.mjs.map +7 -0
- package/dist/lib/{browser/chunk-FRDT7RA4.mjs → neutral/chunk-7WE7SBA2.mjs} +4 -5
- package/dist/lib/neutral/chunk-7WE7SBA2.mjs.map +7 -0
- package/dist/lib/{browser/chunk-INHXFXY5.mjs → neutral/chunk-ANHVGJI4.mjs} +2 -3
- package/dist/lib/{node-esm/chunk-AJEMYSIR.mjs.map → neutral/chunk-ANHVGJI4.mjs.map} +1 -1
- package/dist/lib/neutral/chunk-B4FLOYG7.mjs +130 -0
- package/dist/lib/neutral/chunk-B4FLOYG7.mjs.map +7 -0
- package/dist/lib/{browser/chunk-U2J7TA7K.mjs → neutral/chunk-BHR4XVJK.mjs} +5 -6
- package/dist/lib/{node-esm/chunk-DMR7OAFK.mjs.map → neutral/chunk-BHR4XVJK.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-ZAGAOZVY.mjs → neutral/chunk-CH3HX4Z5.mjs} +4 -5
- package/dist/lib/{node-esm/chunk-QYR67VBV.mjs.map → neutral/chunk-CH3HX4Z5.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-CGS2ULMK.mjs → neutral/chunk-J5LGTIGS.mjs} +1 -2
- package/dist/lib/{browser/chunk-YKTSSMDS.mjs → neutral/chunk-KB7RIVLK.mjs} +1 -3
- package/dist/lib/neutral/chunk-KB7RIVLK.mjs.map +7 -0
- package/dist/lib/{browser/chunk-2SBB7OWV.mjs → neutral/chunk-KSFI2POM.mjs} +11 -10
- package/dist/lib/neutral/chunk-KSFI2POM.mjs.map +7 -0
- package/dist/lib/{browser/chunk-6L5HHUVU.mjs → neutral/chunk-LKQBTRJX.mjs} +18 -5
- package/dist/lib/neutral/chunk-LKQBTRJX.mjs.map +7 -0
- package/dist/lib/{browser/chunk-CJ5YELTO.mjs → neutral/chunk-MXQJZCPY.mjs} +15 -3
- package/dist/lib/neutral/chunk-MXQJZCPY.mjs.map +7 -0
- package/dist/lib/{browser/chunk-PQZW3S6L.mjs → neutral/chunk-N2QNHMT5.mjs} +3 -4
- package/dist/lib/{node-esm/chunk-Y75VU7LB.mjs.map → neutral/chunk-N2QNHMT5.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-IXVWLTG7.mjs → neutral/chunk-OMUPQMLR.mjs} +1 -3
- package/dist/lib/{browser/chunk-IXVWLTG7.mjs.map → neutral/chunk-OMUPQMLR.mjs.map} +1 -1
- package/dist/lib/{node-esm/chunk-YOLH5KS4.mjs → neutral/chunk-RIMHNJ3E.mjs} +17 -4
- package/dist/lib/neutral/chunk-RIMHNJ3E.mjs.map +7 -0
- package/dist/lib/{browser/chunk-JMKVF2YQ.mjs → neutral/chunk-ROKO4RKJ.mjs} +2 -3
- package/dist/lib/{node-esm/chunk-K37NA7PO.mjs.map → neutral/chunk-ROKO4RKJ.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-KQQGVHFN.mjs → neutral/chunk-SHLKRGRB.mjs} +5 -6
- package/dist/lib/{node-esm/chunk-NRN3ZW2T.mjs.map → neutral/chunk-SHLKRGRB.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-22JMFST2.mjs → neutral/chunk-UW4T7PAL.mjs} +3 -4
- package/dist/lib/{browser/chunk-22JMFST2.mjs.map → neutral/chunk-UW4T7PAL.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-XDIUHAAX.mjs → neutral/chunk-WSPASOLU.mjs} +3 -4
- package/dist/lib/{node-esm/chunk-QLI2EIJ2.mjs.map → neutral/chunk-WSPASOLU.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-MYCCGG2T.mjs → neutral/chunk-X2MPMYYN.mjs} +1 -3
- package/dist/lib/{node-esm/chunk-MOWUEW5P.mjs.map → neutral/chunk-X2MPMYYN.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-FPOISFQK.mjs → neutral/chunk-XAJMXQ4H.mjs} +7 -4
- package/dist/lib/neutral/chunk-XAJMXQ4H.mjs.map +7 -0
- package/dist/lib/{browser/chunk-BJPE6CIC.mjs → neutral/chunk-ZUG3PNXU.mjs} +146 -83
- package/dist/lib/neutral/chunk-ZUG3PNXU.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +23 -24
- package/dist/lib/{browser → neutral}/internal/index.mjs +13 -8
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +23 -24
- package/dist/lib/{node-esm → neutral}/testing/index.mjs.map +1 -1
- package/dist/types/src/Annotation.d.ts +22 -0
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +72 -50
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +43 -0
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +84 -4
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +10 -0
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +2 -2
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/hierarchy.test.d.ts +2 -0
- package/dist/types/src/hierarchy.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.d.ts +13 -6
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/util.d.ts +12 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -1
- package/dist/types/src/internal/api/meta.d.ts +2 -2
- package/dist/types/src/internal/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/entities/model.d.ts +3 -1
- package/dist/types/src/internal/entities/model.d.ts.map +1 -1
- package/dist/types/src/internal/entities/object.d.ts.map +1 -1
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -1
- package/dist/types/src/internal/formats/select.d.ts +2 -2
- package/dist/types/src/internal/formats/select.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts +130 -29
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema.d.ts +2 -1
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/object/snapshot.d.ts.map +1 -1
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -1
- package/dist/types/src/internal/proxy/typed-handler.d.ts +2 -1
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref.d.ts +16 -2
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/schema/compose.d.ts +2 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -1
- package/dist/types/src/internal/schema/echo-schema.d.ts +2 -1
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -1
- package/dist/types/src/internal/types/meta.d.ts +5 -5
- package/dist/types/src/internal/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/types/typename.d.ts +8 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -113
- package/src/Annotation.ts +27 -0
- package/src/Database.ts +141 -124
- package/src/Err.ts +20 -0
- package/src/Obj.test.ts +56 -0
- package/src/Obj.ts +140 -11
- package/src/Query.ts +28 -0
- package/src/Relation.ts +5 -3
- package/src/hierarchy.test.ts +33 -0
- package/src/internal/annotations/annotations.ts +28 -1
- package/src/internal/annotations/util.ts +13 -0
- package/src/internal/api/meta.ts +3 -3
- package/src/internal/entities/model.ts +4 -0
- package/src/internal/entities/object.ts +1 -3
- package/src/internal/entities/relation.ts +1 -3
- package/src/internal/formats/format.test.ts +1 -1
- package/src/internal/formats/select.ts +1 -1
- package/src/internal/formats/types.ts +1 -1
- package/src/internal/json-schema/json-schema-normalize.ts +4 -2
- package/src/internal/json-schema/json-schema-type.ts +30 -31
- package/src/internal/json-schema/json-schema.ts +10 -6
- package/src/internal/object/json-serializer.test.ts +26 -2
- package/src/internal/object/json-serializer.ts +25 -9
- package/src/internal/object/schema-validator.test.ts +3 -7
- package/src/internal/object/set-value.test.ts +9 -9
- package/src/internal/object/snapshot.ts +29 -6
- package/src/internal/proxy/make-object.ts +12 -2
- package/src/internal/proxy/typed-handler.test.ts +8 -12
- package/src/internal/proxy/typed-handler.ts +9 -1
- package/src/internal/proxy/typed-object.test.ts +11 -11
- package/src/internal/ref/ref.test.ts +1 -1
- package/src/internal/ref/ref.ts +26 -2
- package/src/internal/schema/compose.ts +13 -8
- package/src/internal/schema/echo-schema.ts +3 -2
- package/src/internal/schema/persistent-schema.ts +2 -1
- package/src/internal/types/meta.ts +12 -13
- package/src/internal/types/typename.ts +10 -0
- package/dist/lib/browser/Database.mjs +0 -18
- package/dist/lib/browser/JsonSchema.mjs +0 -20
- package/dist/lib/browser/Obj.mjs +0 -91
- package/dist/lib/browser/Query.mjs +0 -27
- package/dist/lib/browser/QueryResult.mjs +0 -3
- package/dist/lib/browser/Ref.mjs +0 -23
- package/dist/lib/browser/SchemaRegistry.mjs +0 -3
- package/dist/lib/browser/Tag.mjs +0 -26
- package/dist/lib/browser/chunk-2SBB7OWV.mjs.map +0 -7
- package/dist/lib/browser/chunk-6L5HHUVU.mjs.map +0 -7
- package/dist/lib/browser/chunk-7STIBCP7.mjs +0 -133
- package/dist/lib/browser/chunk-7STIBCP7.mjs.map +0 -7
- package/dist/lib/browser/chunk-BJPE6CIC.mjs.map +0 -7
- package/dist/lib/browser/chunk-CJ5YELTO.mjs.map +0 -7
- package/dist/lib/browser/chunk-FPOISFQK.mjs.map +0 -7
- package/dist/lib/browser/chunk-FRDT7RA4.mjs.map +0 -7
- package/dist/lib/browser/chunk-INHXFXY5.mjs.map +0 -7
- package/dist/lib/browser/chunk-JMKVF2YQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-KQQGVHFN.mjs.map +0 -7
- package/dist/lib/browser/chunk-MYCCGG2T.mjs.map +0 -7
- package/dist/lib/browser/chunk-NOPVNWPT.mjs.map +0 -7
- package/dist/lib/browser/chunk-PQZW3S6L.mjs.map +0 -7
- package/dist/lib/browser/chunk-RK4Z4JUZ.mjs +0 -283
- package/dist/lib/browser/chunk-RK4Z4JUZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-U2J7TA7K.mjs.map +0 -7
- package/dist/lib/browser/chunk-XDIUHAAX.mjs.map +0 -7
- package/dist/lib/browser/chunk-YKTSSMDS.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZAGAOZVY.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/Annotation.mjs +0 -33
- package/dist/lib/node-esm/Annotation.mjs.map +0 -7
- package/dist/lib/node-esm/Database.mjs +0 -18
- package/dist/lib/node-esm/Database.mjs.map +0 -7
- package/dist/lib/node-esm/Entity.mjs +0 -52
- package/dist/lib/node-esm/Entity.mjs.map +0 -7
- package/dist/lib/node-esm/Err.mjs +0 -11
- package/dist/lib/node-esm/Err.mjs.map +0 -7
- package/dist/lib/node-esm/Filter.mjs +0 -62
- package/dist/lib/node-esm/Filter.mjs.map +0 -7
- package/dist/lib/node-esm/Format.mjs +0 -67
- package/dist/lib/node-esm/Format.mjs.map +0 -7
- package/dist/lib/node-esm/JsonSchema.mjs +0 -20
- package/dist/lib/node-esm/JsonSchema.mjs.map +0 -7
- package/dist/lib/node-esm/Key.mjs +0 -13
- package/dist/lib/node-esm/Key.mjs.map +0 -7
- package/dist/lib/node-esm/Obj.mjs.map +0 -7
- package/dist/lib/node-esm/Order.mjs +0 -13
- package/dist/lib/node-esm/Order.mjs.map +0 -7
- package/dist/lib/node-esm/Query.mjs +0 -27
- package/dist/lib/node-esm/Query.mjs.map +0 -7
- package/dist/lib/node-esm/QueryResult.mjs +0 -3
- package/dist/lib/node-esm/QueryResult.mjs.map +0 -7
- package/dist/lib/node-esm/Ref.mjs +0 -23
- package/dist/lib/node-esm/Ref.mjs.map +0 -7
- package/dist/lib/node-esm/Relation.mjs +0 -85
- package/dist/lib/node-esm/Relation.mjs.map +0 -7
- package/dist/lib/node-esm/SchemaRegistry.mjs +0 -3
- package/dist/lib/node-esm/SchemaRegistry.mjs.map +0 -7
- package/dist/lib/node-esm/Tag.mjs +0 -26
- package/dist/lib/node-esm/Tag.mjs.map +0 -7
- package/dist/lib/node-esm/Type.mjs +0 -48
- package/dist/lib/node-esm/Type.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4PNXQA64.mjs +0 -250
- package/dist/lib/node-esm/chunk-4PNXQA64.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5OBN7GZW.mjs +0 -158
- package/dist/lib/node-esm/chunk-5OBN7GZW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +0 -22
- package/dist/lib/node-esm/chunk-ANLVLWME.mjs +0 -98
- package/dist/lib/node-esm/chunk-ANLVLWME.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DMR7OAFK.mjs +0 -57
- package/dist/lib/node-esm/chunk-FWTSPIFF.mjs +0 -133
- package/dist/lib/node-esm/chunk-FWTSPIFF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ILMLLM4R.mjs +0 -204
- package/dist/lib/node-esm/chunk-ILMLLM4R.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K37NA7PO.mjs +0 -43
- package/dist/lib/node-esm/chunk-LT3H4JOX.mjs +0 -3847
- package/dist/lib/node-esm/chunk-LT3H4JOX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MOLNWFNL.mjs +0 -9
- package/dist/lib/node-esm/chunk-MOLNWFNL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +0 -15
- package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs +0 -40
- package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NRN3ZW2T.mjs +0 -143
- package/dist/lib/node-esm/chunk-QLI2EIJ2.mjs +0 -41
- package/dist/lib/node-esm/chunk-QYR67VBV.mjs +0 -288
- package/dist/lib/node-esm/chunk-UKGVOINP.mjs +0 -9
- package/dist/lib/node-esm/chunk-UKGVOINP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-W6QIEBTQ.mjs +0 -403
- package/dist/lib/node-esm/chunk-W6QIEBTQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XHJRMQZD.mjs +0 -69
- package/dist/lib/node-esm/chunk-XHJRMQZD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y75VU7LB.mjs +0 -74
- package/dist/lib/node-esm/chunk-YOLH5KS4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs +0 -39
- package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZBB67AKD.mjs +0 -24
- package/dist/lib/node-esm/chunk-ZBB67AKD.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -85
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/internal/index.mjs +0 -457
- package/dist/lib/node-esm/internal/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -367
- /package/dist/lib/{browser → neutral}/Annotation.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Database.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Entity.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Err.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Filter.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Format.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/JsonSchema.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Key.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Obj.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Order.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Query.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/QueryResult.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Ref.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Relation.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/SchemaRegistry.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Tag.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Type.mjs.map +0 -0
- /package/dist/lib/{browser/chunk-CGS2ULMK.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{browser → neutral}/index.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/internal/index.mjs.map +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
Kind
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-36GDMODZ.mjs";
|
|
5
4
|
import {
|
|
6
5
|
MetaId,
|
|
7
6
|
VersionTypeId,
|
|
@@ -34,26 +33,32 @@ import {
|
|
|
34
33
|
subscribe,
|
|
35
34
|
version,
|
|
36
35
|
versionValid
|
|
37
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-ZUG3PNXU.mjs";
|
|
38
37
|
import {
|
|
38
|
+
ParentId,
|
|
39
39
|
getSchema,
|
|
40
40
|
getTypeAnnotation,
|
|
41
41
|
getTypeDXN,
|
|
42
42
|
getTypename,
|
|
43
43
|
isInstanceOf
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-RIMHNJ3E.mjs";
|
|
45
45
|
import {
|
|
46
|
-
KindId
|
|
47
|
-
|
|
46
|
+
KindId,
|
|
47
|
+
SnapshotKindId
|
|
48
|
+
} from "./chunk-KB7RIVLK.mjs";
|
|
49
|
+
import {
|
|
50
|
+
GetReactiveError
|
|
51
|
+
} from "./chunk-MXQJZCPY.mjs";
|
|
48
52
|
import {
|
|
49
53
|
__export
|
|
50
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
51
55
|
|
|
52
56
|
// src/Obj.ts
|
|
53
57
|
var Obj_exports = {};
|
|
54
58
|
__export(Obj_exports, {
|
|
55
59
|
ID: () => ID,
|
|
56
60
|
Meta: () => Meta,
|
|
61
|
+
Parent: () => Parent,
|
|
57
62
|
VersionTypeId: () => VersionTypeId,
|
|
58
63
|
addTag: () => addTag2,
|
|
59
64
|
change: () => change2,
|
|
@@ -69,6 +74,10 @@ __export(Obj_exports, {
|
|
|
69
74
|
getKeys: () => getKeys2,
|
|
70
75
|
getLabel: () => getLabel2,
|
|
71
76
|
getMeta: () => getMeta,
|
|
77
|
+
getParent: () => getParent,
|
|
78
|
+
getReactive: () => getReactive,
|
|
79
|
+
getReactiveOption: () => getReactiveOption,
|
|
80
|
+
getReactiveOrThrow: () => getReactiveOrThrow,
|
|
72
81
|
getSchema: () => getSchema2,
|
|
73
82
|
getSnapshot: () => getSnapshot2,
|
|
74
83
|
getTypeDXN: () => getTypeDXN2,
|
|
@@ -82,7 +91,9 @@ __export(Obj_exports, {
|
|
|
82
91
|
removeTag: () => removeTag2,
|
|
83
92
|
setDescription: () => setDescription2,
|
|
84
93
|
setLabel: () => setLabel2,
|
|
94
|
+
setParent: () => setParent,
|
|
85
95
|
setValue: () => setValue2,
|
|
96
|
+
snapshotOf: () => snapshotOf,
|
|
86
97
|
sort: () => sort2,
|
|
87
98
|
sortByLabel: () => sortByLabel2,
|
|
88
99
|
sortByTypename: () => sortByTypename2,
|
|
@@ -91,7 +102,9 @@ __export(Obj_exports, {
|
|
|
91
102
|
version: () => version2,
|
|
92
103
|
versionValid: () => versionValid
|
|
93
104
|
});
|
|
105
|
+
import * as Effect from "effect/Effect";
|
|
94
106
|
import * as Function from "effect/Function";
|
|
107
|
+
import * as Option from "effect/Option";
|
|
95
108
|
import * as Schema from "effect/Schema";
|
|
96
109
|
import { createJsonPath, getValue as getValue$ } from "@dxos/effect";
|
|
97
110
|
import { assertArgument } from "@dxos/invariant";
|
|
@@ -110,6 +123,12 @@ var make = (schema, props, meta) => {
|
|
|
110
123
|
delete props[MetaId];
|
|
111
124
|
}
|
|
112
125
|
const filterUndefined = Object.fromEntries(Object.entries(props).filter(([_, v]) => v !== void 0));
|
|
126
|
+
for (const sym of Object.getOwnPropertySymbols(props)) {
|
|
127
|
+
const value = props[sym];
|
|
128
|
+
if (value !== void 0) {
|
|
129
|
+
filterUndefined[sym] = value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
113
132
|
return makeObject(schema, filterUndefined, {
|
|
114
133
|
...defaultMeta,
|
|
115
134
|
...meta
|
|
@@ -123,6 +142,25 @@ var subscribe2 = (obj, callback) => {
|
|
|
123
142
|
return subscribe(obj, callback);
|
|
124
143
|
};
|
|
125
144
|
var getSnapshot2 = getSnapshot;
|
|
145
|
+
var getReactive = (snapshot) => Effect.gen(function* () {
|
|
146
|
+
const db = getDatabase(snapshot);
|
|
147
|
+
if (!db) {
|
|
148
|
+
return yield* Effect.fail(new GetReactiveError({
|
|
149
|
+
reason: "no-database",
|
|
150
|
+
snapshotId: snapshot.id
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
const obj = db.getObjectById(snapshot.id);
|
|
154
|
+
if (!obj) {
|
|
155
|
+
return yield* Effect.fail(new GetReactiveError({
|
|
156
|
+
reason: "object-not-found",
|
|
157
|
+
snapshotId: snapshot.id
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
return obj;
|
|
161
|
+
});
|
|
162
|
+
var getReactiveOption = (snapshot) => getReactive(snapshot).pipe(Effect.map(Option.some), Effect.catchAll(() => Effect.succeed(Option.none())));
|
|
163
|
+
var getReactiveOrThrow = (snapshot) => Effect.runSync(getReactive(snapshot));
|
|
126
164
|
var clone2 = clone;
|
|
127
165
|
var change2 = (obj, callback) => {
|
|
128
166
|
change(obj, callback);
|
|
@@ -138,6 +176,13 @@ var instanceOf = (...args) => {
|
|
|
138
176
|
}
|
|
139
177
|
return isInstanceOf(args[0], args[1]);
|
|
140
178
|
};
|
|
179
|
+
var snapshotOf = (...args) => {
|
|
180
|
+
const check = (entity) => entity != null && typeof entity === "object" && SnapshotKindId in entity && isInstanceOf(args[0], entity);
|
|
181
|
+
if (args.length === 1) {
|
|
182
|
+
return (entity) => check(entity);
|
|
183
|
+
}
|
|
184
|
+
return check(args[1]);
|
|
185
|
+
};
|
|
141
186
|
var getDXN2 = (entity) => {
|
|
142
187
|
assertArgument(!Schema.isSchema(entity), "obj", "Object should not be a schema.");
|
|
143
188
|
return getDXN(entity);
|
|
@@ -159,6 +204,19 @@ var getLabel2 = (entity) => getLabel(entity);
|
|
|
159
204
|
var setLabel2 = (entity, label) => setLabel(entity, label);
|
|
160
205
|
var getDescription2 = (entity) => getDescription(entity);
|
|
161
206
|
var setDescription2 = (entity, description) => setDescription(entity, description);
|
|
207
|
+
var Parent = ParentId;
|
|
208
|
+
var getParent = (entity) => {
|
|
209
|
+
assertArgument(isObject(entity), "Expected an object");
|
|
210
|
+
assumeType(entity);
|
|
211
|
+
return entity[ParentId];
|
|
212
|
+
};
|
|
213
|
+
var setParent = (entity, parent) => {
|
|
214
|
+
assertArgument(isObject(entity), "Expected an object");
|
|
215
|
+
assertArgument(parent === void 0 || isObject(parent), "Expected an object");
|
|
216
|
+
assumeType(entity);
|
|
217
|
+
assumeType(parent);
|
|
218
|
+
entity[ParentId] = parent;
|
|
219
|
+
};
|
|
162
220
|
var toJSON = (entity) => objectToJSON(entity);
|
|
163
221
|
var fromJSON = objectFromJSON;
|
|
164
222
|
var sortByLabel2 = sortByLabel;
|
|
@@ -171,12 +229,16 @@ export {
|
|
|
171
229
|
isObject,
|
|
172
230
|
subscribe2 as subscribe,
|
|
173
231
|
getSnapshot2 as getSnapshot,
|
|
232
|
+
getReactive,
|
|
233
|
+
getReactiveOption,
|
|
234
|
+
getReactiveOrThrow,
|
|
174
235
|
clone2 as clone,
|
|
175
236
|
change2 as change,
|
|
176
237
|
getValue,
|
|
177
238
|
setValue2 as setValue,
|
|
178
239
|
ID,
|
|
179
240
|
instanceOf,
|
|
241
|
+
snapshotOf,
|
|
180
242
|
getDXN2 as getDXN,
|
|
181
243
|
getTypeDXN2 as getTypeDXN,
|
|
182
244
|
getSchema2 as getSchema,
|
|
@@ -193,6 +255,9 @@ export {
|
|
|
193
255
|
setLabel2 as setLabel,
|
|
194
256
|
getDescription2 as getDescription,
|
|
195
257
|
setDescription2 as setDescription,
|
|
258
|
+
Parent,
|
|
259
|
+
getParent,
|
|
260
|
+
setParent,
|
|
196
261
|
toJSON,
|
|
197
262
|
fromJSON,
|
|
198
263
|
sortByLabel2 as sortByLabel,
|
|
@@ -201,4 +266,4 @@ export {
|
|
|
201
266
|
version2 as version,
|
|
202
267
|
Obj_exports
|
|
203
268
|
};
|
|
204
|
-
//# sourceMappingURL=chunk-
|
|
269
|
+
//# sourceMappingURL=chunk-5MGEVDUW.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Obj.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { createJsonPath, getValue as getValue$ } from '@dxos/effect';\nimport { assertArgument } from '@dxos/invariant';\nimport { type DXN, ObjectId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from './Database';\nimport * as Entity from './Entity';\nimport * as Err from './Err';\nimport {\n type ObjectJSON as APIJSON,\n type AnyEntity,\n type AnyProperties,\n type Comparator as ApiComparator,\n type Meta as ApiMeta,\n type ReadonlyMeta as ApiReadonlyMeta,\n type EntityVersion as ApiVersion,\n type ChangeCallback,\n type InternalObjectProps,\n type KindId,\n MetaId,\n type Mutable,\n type ObjectMeta,\n // TODO(dmaretskyi): Export ParentId?\n ParentId,\n SnapshotKindId,\n type VersionCompareResult,\n VersionTypeId,\n addTag as addTag$,\n change as change$,\n clone as clone$,\n compareVersions,\n decodeVersion,\n deleteKeys as deleteKeys$,\n encodeVersion,\n getDXN as getDXN$,\n getDatabase as getDatabase$,\n getDescription as getDescription$,\n getKeys as getKeys$,\n getLabel as getLabel$,\n getMetaChecked as getMeta$,\n getSchema as getSchema$,\n getSnapshot as getSnapshot$,\n getTypeAnnotation,\n getTypeDXN as getTypeDXN$,\n getTypename as getTypename$,\n isDeleted as isDeleted$,\n isInstanceOf,\n isVersion,\n makeObject,\n objectFromJSON,\n removeTag as removeTag$,\n setDescription as setDescription$,\n setLabel as setLabel$,\n setValue as setValue$,\n sort as sort$,\n sortByLabel as sortByLabel$,\n sortByTypename as sortByTypename$,\n subscribe as subscribe$,\n objectToJSON as toJSON$,\n version as version$,\n versionValid,\n} from './internal';\nimport type * as Ref from './Ref';\nimport type * as Type from './Type';\n\n/**\n * Base type for all ECHO objects.\n */\ninterface BaseObj extends AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}\n\n/**\n * Object type with specific properties.\n */\nexport type Obj<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 * 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, AnyProperties {}\n\n/**\n * Base type for snapshot objects (has SnapshotKindId instead of KindId).\n */\ninterface BaseSnapshot extends AnyEntity {\n readonly [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, KindId> & BaseSnapshot;\n\nconst defaultMeta: ObjectMeta = {\n keys: [],\n};\n\ntype Props<T = any> = {\n id?: ObjectId;\n [Meta]?: Partial<ObjectMeta>;\n} & Type.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<ObjectMeta>;\n [Parent]?: Unknown;\n} & NoInfer<Props<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: {\n <S extends Type.Obj.Any>(schema: S, props: MakeProps<S>): Obj<Schema.Schema.Type<S>>;\n /**\n * @deprecated Pass meta as in the example: `Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' })`.\n */\n <S extends Type.Obj.Any>(schema: S, props: MakeProps<S>, meta: Partial<ObjectMeta>): Obj<Schema.Schema.Type<S>>;\n} = <S extends Type.Obj.Any>(\n schema: S,\n props: MakeProps<S>,\n meta?: Partial<ObjectMeta>,\n): Obj<Schema.Schema.Type<S>> => {\n assertArgument(getTypeAnnotation(schema)?.kind === Entity.Kind.Object, 'schema', 'Expected an object schema');\n\n // Set default fields on meta on creation.\n if (props[MetaId] != null) {\n meta = { ...structuredClone(defaultMeta), ...props[MetaId] };\n delete props[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 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<InternalObjectProps>(obj);\n return typeof obj === 'object' && obj !== null && obj[Entity.KindId] === 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 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> = 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 = 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 = 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.change`.\n */\nexport type { Mutable };\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.change` 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.change` 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.change\n * Obj.change(person, (p) => {\n * p.name = 'Jane';\n * p.age = 30;\n * });\n * // ONE notification fires here\n *\n * // Direct mutation throws\n * person.name = 'Bob'; // Error: Cannot modify outside Obj.change()\n * ```\n *\n * Note: Only accepts objects. Use `Relation.change` for relations.\n */\nexport const change = <T extends Unknown>(obj: T, callback: ChangeCallback<T>): void => {\n 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 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.change` 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.change(person, (p) => {\n * Obj.setValue(p, ['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 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.Entity.Any>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;\n <S extends Type.Entity.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;\n} = ((...args: [schema: Type.Entity.Any, value: unknown] | [schema: Type.Entity.Any]) => {\n if (args.length === 1) {\n return (entity: unknown) => isInstanceOf(args[0], entity);\n }\n\n return 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.Entity.Any>(schema: S): (value: unknown) => value is Snapshot<Schema.Schema.Type<S>>;\n <S extends Type.Entity.Any>(schema: S, value: unknown): value is Snapshot<Schema.Schema.Type<S>>;\n} = ((...args: [schema: Type.Entity.Any, value: unknown] | [schema: Type.Entity.Any]) => {\n const check = (entity: unknown) =>\n entity != null && typeof entity === 'object' && SnapshotKindId in entity && 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 getDXN$(entity);\n};\n\n/**\n * @returns The DXN of the object's type.\n * @example dxn:example.com/type/Person:1.0.0\n */\n// TODO(wittjosiah): Narrow types.\nexport const getTypeDXN: (obj: unknown | undefined) => DXN | undefined = getTypeDXN$ as any;\n\n/**\n * Get the schema of the object.\n * Returns the branded ECHO schema used to create the object.\n */\n// TODO(wittjosiah): Narrow types.\nexport const getSchema: (obj: unknown | undefined) => Type.Entity.Any | undefined = getSchema$ as any;\n\n/**\n * @returns The typename of the object's type.\n * Accepts both reactive objects and snapshots.\n * @example `example.com/type/Person`\n */\nexport const getTypename = (entity: Unknown | Snapshot): string | undefined => 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 getDatabase$(entity);\n\n//\n// Meta\n//\n\nexport const Meta: unique symbol = MetaId as any;\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 = ApiReadonlyMeta;\n\n/**\n * Mutable meta type returned by `Obj.getMeta` inside an `Obj.change` callback.\n */\nexport type Meta = ApiMeta;\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.change` 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.change(person, (p) => {\n * const meta = Obj.getMeta(p); // 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 getMeta$(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[] => getKeys$(entity, source!));\n\n/**\n * Delete all keys from the object for the specified source.\n * Must be called within an `Obj.change` 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 => deleteKeys$(entity, source);\n\n/**\n * Add a tag to the object.\n * Must be called within an `Obj.change` 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 => addTag$(entity, tag);\n\n/**\n * Remove a tag from the object.\n * Must be called within an `Obj.change` 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 => 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 => 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 => getLabel$(entity);\n\n/**\n * Set the label of the object.\n * Must be called within an `Obj.change` 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 => 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 => getDescription$(entity);\n\n/**\n * Set the description of the object.\n * Must be called within an `Obj.change` 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 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 = 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<InternalObjectProps>(entity);\n return entity[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<InternalObjectProps>(entity);\n assumeType<InternalObjectProps | undefined>(parent);\n entity[ParentId] = parent;\n};\n\n//\n// JSON\n//\n\n/**\n * JSON representation of an object.\n */\nexport type JSON = APIJSON;\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 => toJSON$(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 */\nexport const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<Unknown> =\n objectFromJSON as any;\n\n/**\n * Comparator function type for sorting objects.\n * Accepts both reactive objects and snapshots.\n */\nexport type Comparator = ApiComparator<Unknown | Snapshot>;\n\nexport const sortByLabel: Comparator = sortByLabel$ as Comparator;\nexport const sortByTypename: Comparator = sortByTypename$ as Comparator;\nexport const sort = (...comparators: Comparator[]): Comparator => sort$(...comparators) as Comparator;\n\n//\n// Version\n//\n\nexport { VersionTypeId };\nexport type { 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 = ApiVersion;\n\nexport { isVersion, versionValid, compareVersions, encodeVersion, 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 => version$(entity);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;gBAAAA;EAAA,cAAAC;EAAA,aAAAC;EAAA;;oBAAAC;EAAA;;gBAAAC;EAAA,mBAAAC;EAAA,sBAAAC;EAAA,eAAAC;EAAA,gBAAAC;EAAA;;;;;mBAAAC;EAAA,mBAAAC;EAAA,kBAAAC;EAAA,mBAAAC;EAAA;;mBAAAC;EAAA;;;mBAAAC;EAAA,sBAAAC;EAAA,gBAAAC;EAAA;kBAAAC;EAAA;cAAAC;EAAA,mBAAAC;EAAA,sBAAAC;EAAA,iBAAAC;EAAA;iBAAAC;EAAA;;AAIA,YAAYC,YAAY;AACxB,YAAYC,cAAc;AAC1B,YAA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MAAAA;AAChC1C,aAA4CuF,MAAAA;AAC5C7C,SAAO0C,QAAAA,IAAYG;AACrB;AAiBO,IAAMC,SAAS,CAAC9C,WAAqC+C,aAAQ/C,MAAAA;AAW7D,IAAMgD,WACXC;AAQK,IAAMC,eAA0BC;AAChC,IAAMC,kBAA6BC;AACnC,IAAMC,QAAO,IAAIC,gBAA0CC,KAAAA,GAASD,WAAAA;AAsBpE,IAAME,WAAU,CAACC,WAAwCC,QAASD,MAAAA;",
|
|
6
|
+
"names": ["addTag", "change", "clone", "deleteKeys", "getDXN", "getDatabase", "getDescription", "getKeys", "getLabel", "getSchema", "getSnapshot", "getTypeDXN", "getTypename", "isDeleted", "removeTag", "setDescription", "setLabel", "setValue", "sort", "sortByLabel", "sortByTypename", "subscribe", "version", "Effect", "Function", "Option", "Schema", "createJsonPath", "getValue", "getValue$", "assertArgument", "ObjectId", "assumeType", "defaultMeta", "keys", "make", "schema", "props", "meta", "assertArgument", "getTypeAnnotation", "kind", "Kind", "Object", "MetaId", "structuredClone", "filterUndefined", "fromEntries", "entries", "filter", "_", "v", "undefined", "sym", "getOwnPropertySymbols", "value", "makeObject", "isObject", "obj", "assumeType", "KindId", "subscribe", "callback", "subscribe$", "getSnapshot", "getSnapshot$", "getReactive", "snapshot", "gen", "db", "getDatabase$", "fail", "GetReactiveError", "reason", "snapshotId", "id", "getObjectById", "getReactiveOption", "pipe", "map", "some", "catchAll", "succeed", "none", "getReactiveOrThrow", "runSync", "clone", "clone$", "change", "change$", "getValue", "path", "getValue$", "createJsonPath", "setValue", "setValue$", "ID", "ObjectId", "instanceOf", "args", "length", "entity", "isInstanceOf", "snapshotOf", "check", "SnapshotKindId", "getDXN", "isSchema", "getDXN$", "getTypeDXN", "getTypeDXN$", "getSchema", "getSchema$", "getTypename", "getTypename$", "getDatabase", "Meta", "getMeta", "getMeta$", "getKeys", "dual", "source", "getKeys$", "deleteKeys", "deleteKeys$", "addTag", "tag", "addTag$", "removeTag", "removeTag$", "isDeleted", "isDeleted$", "getLabel", "getLabel$", "setLabel", "label", "setLabel$", "getDescription", "getDescription$", "setDescription", "description", "setDescription$", "Parent", "ParentId", "getParent", "setParent", "parent", "toJSON", "toJSON$", "fromJSON", "objectFromJSON", "sortByLabel", "sortByLabel$", "sortByTypename", "sortByTypename$", "sort", "comparators", "sort$", "version", "entity", "version$"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
createAnnotationHelper
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KB7RIVLK.mjs";
|
|
5
4
|
|
|
6
5
|
// src/internal/formats/types.ts
|
|
7
6
|
import * as Function from "effect/Function";
|
|
@@ -76,7 +75,7 @@ var typeToFormat = {
|
|
|
76
75
|
["boolean"]: "boolean"
|
|
77
76
|
};
|
|
78
77
|
var formatToType = {
|
|
79
|
-
["none"]:
|
|
78
|
+
["none"]: "string",
|
|
80
79
|
["string"]: "string",
|
|
81
80
|
["number"]: "number",
|
|
82
81
|
["boolean"]: "boolean",
|
|
@@ -367,7 +366,7 @@ var SelectOption = Schema6.Struct({
|
|
|
367
366
|
title: Schema6.String,
|
|
368
367
|
/** Color palette used for visual styling. */
|
|
369
368
|
color: Schema6.String
|
|
370
|
-
})
|
|
369
|
+
});
|
|
371
370
|
|
|
372
371
|
export {
|
|
373
372
|
TypeEnum,
|
|
@@ -400,4 +399,4 @@ export {
|
|
|
400
399
|
Format,
|
|
401
400
|
SelectOption
|
|
402
401
|
};
|
|
403
|
-
//# sourceMappingURL=chunk-
|
|
402
|
+
//# sourceMappingURL=chunk-7WE7SBA2.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/formats/types.ts", "../../../src/internal/formats/number.ts", "../../../src/internal/formats/object.ts", "../../../src/internal/formats/string.ts", "../../../src/internal/formats/format.ts", "../../../src/internal/formats/date.ts", "../../../src/internal/formats/select.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport type * as JSONSchema from 'effect/JSONSchema';\nimport * as Option from 'effect/Option';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { createAnnotationHelper } from '../annotations';\nimport { type JsonSchemaType } from '../json-schema';\n\n// TODO(burdon): Rename PropertyType.\nexport type ScalarType =\n | JSONSchema.JsonSchema7Object\n | JSONSchema.JsonSchema7String\n | JSONSchema.JsonSchema7Number\n | JSONSchema.JsonSchema7Boolean\n | JSONSchema.JsonSchema7Ref;\n\n// TODO(burdon): Rename ValueType and change to disciminated union.\n// export type ValueType = 'array' | 'object' | 'string' | 'number' | 'boolean' | 'ref';\nexport enum TypeEnum {\n Array = 'array', // TODO(burdon): Remove?\n Object = 'object',\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Ref = 'ref',\n}\n\n// TODO(burdon): Ref?\nexport const getTypeEnum = (property: JsonSchemaType): TypeEnum | undefined => {\n switch (property.type) {\n case 'array':\n return TypeEnum.Array;\n case 'object':\n return TypeEnum.Object;\n case 'string':\n return TypeEnum.String;\n case 'number':\n return TypeEnum.Number;\n case 'boolean':\n return TypeEnum.Boolean;\n default:\n return undefined;\n }\n};\n\n/**\n * https://json-schema.org/understanding-json-schema/reference/schema\n * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats\n */\nexport const FormatAnnotationId = Symbol.for('@dxos/schema/annotation/Format');\n\nexport const FormatAnnotation = createAnnotationHelper<TypeFormat>(FormatAnnotationId);\n\n/** @deprecated */\nexport const getFormatAnnotation = (node: SchemaAST.AST): TypeFormat | undefined =>\n Function.pipe(SchemaAST.getAnnotation<TypeFormat>(FormatAnnotationId)(node), Option.getOrUndefined);\n\n// TODO(burdon): Rename Format; Change to discriminated union?\nexport enum TypeFormat {\n None = 'none',\n\n //\n // Scalar\n //\n\n String = 'string',\n Number = 'number',\n Boolean = 'boolean',\n Ref = 'ref',\n\n //\n // { type: 'string' }\n //\n\n DID = 'did', // Users, etc.\n DXN = 'dxn',\n Email = 'email',\n Formula = 'formula', // Spreadsheet formula.\n Hostname = 'hostname',\n JSON = 'json',\n Markdown = 'markdown',\n Regex = 'regex',\n SingleSelect = 'single-select',\n Text = 'text',\n MultiSelect = 'multi-select',\n URL = 'url',\n UUID = 'uuid',\n\n //\n // { type: 'number' }\n //\n\n Currency = 'currency',\n Integer = 'integer',\n Percent = 'percent',\n Timestamp = 'timestamp',\n\n //\n // { type: 'date' }\n //\n\n DateTime = 'date-time',\n Date = 'date',\n Time = 'time',\n Duration = 'duration',\n\n //\n // { type: 'object' }\n //\n\n GeoPoint = 'lnglat',\n}\n\nexport const FormatEnums = Object.values(TypeFormat).sort();\n\nexport const PropertyKind = {\n type: TypeEnum,\n format: TypeFormat,\n};\n\n/**\n * Default formats\n */\nexport const typeToFormat: Partial<Record<TypeEnum, TypeFormat>> = {\n [TypeEnum.String]: TypeFormat.String,\n [TypeEnum.Number]: TypeFormat.Number,\n [TypeEnum.Boolean]: TypeFormat.Boolean,\n};\n\n/**\n * Map of format to type.\n */\nexport const formatToType: Record<TypeFormat, TypeEnum> = {\n [TypeFormat.None]: TypeEnum.String,\n [TypeFormat.String]: TypeEnum.String,\n [TypeFormat.Number]: TypeEnum.Number,\n [TypeFormat.Boolean]: TypeEnum.Boolean,\n [TypeFormat.Ref]: TypeEnum.Ref,\n\n // Strings\n [TypeFormat.DID]: TypeEnum.String,\n [TypeFormat.DXN]: TypeEnum.String,\n [TypeFormat.Email]: TypeEnum.String,\n [TypeFormat.Formula]: TypeEnum.String,\n [TypeFormat.Hostname]: TypeEnum.String,\n [TypeFormat.JSON]: TypeEnum.String,\n [TypeFormat.Markdown]: TypeEnum.String,\n [TypeFormat.Regex]: TypeEnum.String,\n [TypeFormat.URL]: TypeEnum.String,\n [TypeFormat.UUID]: TypeEnum.String,\n [TypeFormat.SingleSelect]: TypeEnum.String,\n [TypeFormat.Text]: TypeEnum.String,\n [TypeFormat.MultiSelect]: TypeEnum.Object,\n\n // Dates\n [TypeFormat.Date]: TypeEnum.String,\n [TypeFormat.DateTime]: TypeEnum.String,\n [TypeFormat.Duration]: TypeEnum.String,\n [TypeFormat.Time]: TypeEnum.String,\n\n // Numbers\n [TypeFormat.Currency]: TypeEnum.Number,\n [TypeFormat.Integer]: TypeEnum.Number,\n [TypeFormat.Percent]: TypeEnum.Number,\n [TypeFormat.Timestamp]: TypeEnum.Number,\n\n // Objects\n [TypeFormat.GeoPoint]: TypeEnum.Array,\n};\n\n/**\n * Allowed value options for select.\n */\nexport const OptionsAnnotationId = Symbol.for('@dxos/schema/annotation/Options');\n\n// TODO(wittjosiah): Reconcile with `SelectOption`.\nexport type Options = string | number;\nexport const OptionsAnnotation = createAnnotationHelper<Options[]>(OptionsAnnotationId);\n\n/** @deprecated */\nexport const getOptionsAnnotation = (node: SchemaAST.AST): Options[] | undefined =>\n Function.pipe(SchemaAST.getAnnotation<Options[]>(OptionsAnnotationId)(node), Option.getOrUndefined);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\nconst encodeMultipleOf = (divisor: number) => 1 / Math.pow(10, divisor);\n\nconst encodeMultiple =\n <A extends number>(divisor?: number) =>\n <I, R>(self: Schema.Schema<A, I, R>) =>\n divisor === undefined || divisor === 0 ? self : self.pipe(Schema.multipleOf(encodeMultipleOf(divisor)));\n\n/**\n * Convert number of digits to multipleOf annotation.\n */\nexport const DecimalPrecision = Schema.transform(Schema.Number, Schema.Number, {\n strict: true,\n encode: (value) => encodeMultipleOf(value),\n decode: (value) => Math.log10(1 / value),\n}).annotations({\n title: 'Number of digits',\n});\n\nexport const CurrencyAnnotationId = Symbol.for('@dxos/schema/annotation/Currency');\n\nexport type CurrencyAnnotation = {\n decimals?: number;\n code?: string;\n};\n\n/**\n * ISO 4217 currency code.\n */\nexport const Currency = ({ decimals, code }: CurrencyAnnotation = { decimals: 2 }) =>\n Schema.Number.pipe(\n encodeMultiple(decimals),\n FormatAnnotation.set(TypeFormat.Currency),\n Schema.annotations({\n title: 'Currency',\n description: 'Currency value',\n ...(code ? { [CurrencyAnnotationId]: code.toUpperCase() } : {}),\n }),\n );\n\nexport type PercentAnnotation = {\n decimals?: number;\n};\n\n/**\n * Integer.\n */\nexport const Integer = () =>\n Schema.Number.pipe(\n Schema.int(),\n FormatAnnotation.set(TypeFormat.Integer),\n Schema.annotations({\n title: 'Integer',\n description: 'Integer value',\n }),\n );\n\n/**\n * Percent.\n */\n// TODO(burdon): Define min/max (e.g., 0, 1).\nexport const Percent = ({ decimals }: PercentAnnotation = { decimals: 2 }) =>\n Schema.Number.pipe(\n encodeMultiple(decimals),\n FormatAnnotation.set(TypeFormat.Percent),\n Schema.annotations({\n title: 'Percent',\n description: 'Percentage value',\n }),\n );\n\n/**\n * Unix timestamp.\n * https://en.wikipedia.org/wiki/Unix_time\n */\nexport const Timestamp = Schema.Number.pipe(\n FormatAnnotation.set(TypeFormat.Timestamp),\n Schema.annotations({\n title: 'Timestamp',\n description: 'Unix timestamp',\n }),\n);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { clamp } from '@dxos/util';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\n/**\n * GeoJSON Format\n * https://datatracker.ietf.org/doc/html/rfc7946\n * https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1\n * https://en.wikipedia.org/wiki/Geographic_coordinate_system\n * https://geojson.org\n * {\n * \"type\": \"Point\",\n * \"coordinates\": [0, 51.47] // [longitude, latitude]\n * }\n * Note: optional third element for altitude.\n */\nexport const GeoPoint = Schema.Tuple(\n Schema.Number.pipe(Schema.annotations({ title: 'Longitude' }), Schema.clamp(-180, 180), Schema.multipleOf(0.000001)),\n Schema.Number.pipe(Schema.annotations({ title: 'Latitude' }), Schema.clamp(-90, 90), Schema.multipleOf(0.000001)),\n Schema.optionalElement(Schema.Number).annotations({\n title: 'Height ASL (m)',\n }),\n).pipe(\n FormatAnnotation.set(TypeFormat.GeoPoint),\n Schema.annotations({\n title: 'GeoPoint',\n description: 'GeoJSON Position',\n }),\n);\n\nexport type GeoPoint = Schema.Schema.Type<typeof GeoPoint>;\n\nexport type GeoLocation = {\n longitude: number;\n latitude: number;\n height?: number;\n};\n\n/**\n * Geolocation utilities for working with GeoPoint format.\n */\nexport namespace GeoLocation {\n /**\n * Convert latitude and longitude to GeoPoint (GeoJSON format [longitude, latitude, height?]).\n * Clamps values to valid ranges: latitude [-90, 90], longitude [-180, 180].\n */\n export const toGeoPoint = ({ longitude, latitude, height }: GeoLocation): GeoPoint => {\n // TODO(ZaymonFC): Use schema validation instead of doing this manually.\n const clampedLongitude = clamp(longitude, -180, 180);\n const clampedLatitude = clamp(latitude, -90, 90);\n return height !== undefined ? [clampedLongitude, clampedLatitude, height] : [clampedLongitude, clampedLatitude];\n };\n\n /**\n * Extract latitude and longitude from GeoPoint (GeoJSON format [longitude, latitude, height?]).\n */\n export const fromGeoPoint = (geoPoint: GeoPoint | undefined): GeoLocation => {\n if (!geoPoint) {\n return { longitude: 0, latitude: 0 };\n }\n\n const result: GeoLocation = {\n longitude: geoPoint[0],\n latitude: geoPoint[1],\n };\n\n // Add height if defined.\n if (geoPoint[2] !== undefined) {\n result.height = geoPoint[2];\n }\n\n return result;\n };\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\n/**\n * Email address (RFC 5321)\n * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2\n */\nexport const Email = Schema.String.pipe(\n Schema.pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/),\n FormatAnnotation.set(TypeFormat.Email),\n Schema.annotations({\n title: 'Email',\n description: 'Email address',\n }),\n);\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const Formula = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Formula));\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const Hostname = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Hostname));\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const JSON = Schema.String.pipe(FormatAnnotation.set(TypeFormat.JSON));\n\n/**\n *\n */\n// TODO(burdon): Implement.\nexport const Markdown = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Markdown));\n\n/**\n * Regex\n * https://json-schema.org/understanding-json-schema/reference/regular_expressions\n * https://ecma-international.org/publications-and-standards/standards/ecma-262\n */\n// TODO(burdon): Implement.\nexport const Regex = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex));\n\n/**\n * Multi-line text.\n */\nexport const Text = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Text));\n\n/**\n * https://datatracker.ietf.org/doc/html/rfc3986#section-1.1.3\n */\nexport const URL = Schema.String.pipe(\n Schema.pattern(/^(\\w+?:\\/\\/)?([\\da-z.-]+)\\.([a-z.]{2,6})([/\\w .-]*)*\\/?$/i),\n FormatAnnotation.set(TypeFormat.URL),\n Schema.annotations({\n title: 'URL',\n description: 'URL',\n }),\n);\n\n/**\n * UUID (RFC 4122)\n * https://datatracker.ietf.org/doc/html/rfc4122\n */\nexport const UUID = Schema.UUID.pipe(\n FormatAnnotation.set(TypeFormat.UUID),\n Schema.annotations({\n [SchemaAST.ExamplesAnnotationId]: ['3e4666bf-d5e5-4aa7-b8ce-cefe41c7568a'],\n }),\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport * as Keys from '@dxos/keys';\n\nimport * as DateUtil from './date';\nimport * as NumberUtil from './number';\nimport * as ObjectUtil from './object';\nimport * as StringUtil from './string';\nimport { TypeFormat as TypeFormat$ } from './types';\n\n// TODO(burdon): Media encoding.\n// - https://json-schema.org/understanding-json-schema/reference/non_json_data\n\n/**\n * Formats.\n * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats\n * NOTE: A JSON Schema validator will ignore any format type that it does not understand.\n */\n// TODO(burdon): Add fields for `examples`, `message`, etc.\nexport namespace Format {\n export import TypeFormat = TypeFormat$;\n\n // String\n export const DXN = Keys.DXN.Schema;\n export const Email = StringUtil.Email;\n export const Formula = StringUtil.Formula;\n export const Hostname = StringUtil.Hostname;\n export const JSON = StringUtil.JSON;\n export const Markdown = StringUtil.Markdown;\n export const Regex = StringUtil.Regex;\n export const URL = StringUtil.URL;\n export const UUID = Schema.UUID;\n\n // Numbers\n // TODO(burdon): BigInt.\n export const Currency = NumberUtil.Currency;\n export const Integer = NumberUtil.Integer;\n export const Percent = NumberUtil.Percent;\n export const Timestamp = NumberUtil.Timestamp;\n\n // Dates and times\n export const Date = DateUtil.DateOnly;\n export const DateTime = DateUtil.DateTime;\n export const Duration = DateUtil.Duration;\n export const Time = DateUtil.TimeOnly;\n\n // Objects\n export const GeoPoint = ObjectUtil.GeoPoint;\n export type GeoPoint = ObjectUtil.GeoPoint; // TODO(burdon): Export types.\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { FormatAnnotation, TypeFormat } from './types';\n\n/**\n * Datetime values should be stored as ISO strings or unix numbers (ms) in UTC.\n *\n * NOTE: HyperFormula uses Excel's time format (null date 1900/01/01)\n * It can be configured to use a different parser via `parseDateTime`.\n * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#date-and-time-handling\n * https://github.com/handsontable/hyperformula/blob/master/src/DateTimeHelper.ts\n */\n\n// TODO(burdon): Annotations not present in JSON.\n// TODO(burdon): Timezone.\n// TODO(burdon): Format for timestamp (Unix UTC or ISO 8601)?\n// TODO(burdon): Refs\n// - https://www.npmjs.com/package/numfmt\n// - https://date-fns.org/docs/Getting-Started\n// - https://github.com/date-fns/tz\n\n/**\n * Simple date compatible with HF.\n */\nexport const SimpleDate = Schema.Struct({\n year: Schema.Number.pipe(Schema.between(1900, 9999)),\n month: Schema.Number.pipe(Schema.between(1, 12)),\n day: Schema.Number.pipe(Schema.between(1, 31)),\n});\n\nexport type SimpleDate = Schema.Schema.Type<typeof SimpleDate>;\n\nexport const toSimpleDate = (date: Date): SimpleDate => ({\n year: date.getUTCFullYear(),\n month: date.getUTCMonth() + 1,\n day: date.getUTCDate(),\n});\n\n/**\n * Simple time compatible with HF.\n */\nexport const SimpleTime = Schema.Struct({\n hours: Schema.Number.pipe(Schema.between(0, 23)),\n minutes: Schema.Number.pipe(Schema.between(0, 59)),\n seconds: Schema.Number.pipe(Schema.between(0, 59)),\n});\n\nexport type SimpleTime = Schema.Schema.Type<typeof SimpleTime>;\n\nexport const toSimpleTime = (date: Date): SimpleTime => ({\n hours: date.getUTCHours(),\n minutes: date.getUTCSeconds(),\n seconds: date.getUTCSeconds(),\n});\n\n/**\n * Simple date-time compatible with HF.\n */\nexport const SimpleDateTime = Schema.extend(SimpleDate, SimpleTime);\n\nexport type SimpleDateTime = Schema.Schema.Type<typeof SimpleDateTime>;\n\nexport const toSimpleDateTime = (date: Date): SimpleDateTime => ({\n ...toSimpleDate(date),\n ...toSimpleTime(date),\n});\n\n/**\n * https://effect.website/docs/guides/schema/transformations#date-transformations\n */\n\n// TODO(burdon): Consider if transformations should be supported with Automerge.\n\n/**\n * Format: 2018-11-13\n */\nexport const DateOnly = /* Schema.transformOrFail(Schema.String, SimpleDate, {\n strict: true,\n decode: (str, _, ast) => {\n if (!isValidDateFormat(str)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected YYYY-MM-DD format'));\n }\n if (!isValidDate(str)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Invalid date'));\n }\n\n const [year, month, day] = str.split('-').map(Number);\n return ParseResult.succeed({ year, month, day });\n },\n encode: (date) => {\n return ParseResult.succeed(\n [\n date.year.toString().padStart(4, '0'),\n date.month.toString().padStart(2, '0'),\n date.day.toString().padStart(2, '0'),\n ].join('-'),\n );\n },\n}) */ Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.Date),\n Schema.annotations({\n title: 'Date',\n description: 'Valid date in ISO format',\n }),\n);\n\n/**\n * Format: 20:20:39+00:00\n */\nexport const TimeOnly = /* Schema.transformOrFail(Schema.String, SimpleTime, {\n strict: true,\n decode: (str, _, ast) => {\n if (!isValidTimeFormat(str)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));\n }\n\n const [hours, minutes, seconds] = str.split(':').map(Number);\n return ParseResult.succeed({ hours, minutes, seconds });\n },\n encode: (time) => {\n return ParseResult.succeed(\n [\n time.hours.toString().padStart(2, '0'),\n time.minutes.toString().padStart(2, '0'),\n time.seconds.toString().padStart(2, '0'),\n ].join(':'),\n );\n },\n}) */ Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.Time),\n Schema.annotations({\n title: 'Time',\n description: 'Valid time in ISO format',\n }),\n);\n\n/**\n * Format: 2018-11-13T20:20:39+00:00\n */\nexport const DateTime = /* Schema.transformOrFail(Schema.String, SimpleDateTime, {\n strict: false,\n decode: (str, _, ast) => {\n const [date, time] = str.split('T');\n if (!isValidDateFormat(date)) {\n return ParseResult.fail(new ParseResult.Type(ast, date, 'Expected YYYY-MM-DD format'));\n }\n if (!isValidDate(date)) {\n return ParseResult.fail(new ParseResult.Type(ast, date, 'Invalid date'));\n }\n if (!isValidTimeFormat(time)) {\n return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));\n }\n\n const [year, month, day] = date.split('-').map(Number);\n const [hours, minutes, seconds] = time.split(':').map(Number);\n return ParseResult.succeed({ year, month, day, hours, minutes, seconds });\n },\n encode: (datetime) => {\n return ParseResult.succeed(\n [\n [\n datetime.year.toString().padStart(4, '0'),\n datetime.month.toString().padStart(2, '0'),\n datetime.day.toString().padStart(2, '0'),\n ].join('-'),\n [\n datetime.hours.toString().padStart(2, '0'),\n datetime.minutes.toString().padStart(2, '0'),\n datetime.seconds.toString().padStart(2, '0'),\n ].join(':'),\n ].join('T'),\n );\n },\n}) */ Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.DateTime),\n Schema.annotations({\n title: 'DateTime',\n description: 'Valid date and time in ISO format',\n }),\n);\n\n/**\n * https://datatracker.ietf.org/doc/html/rfc3339#appendix-A\n */\n// TODO(burdon): Define duration type.\nexport const Duration = Schema.String.pipe(\n FormatAnnotation.set(TypeFormat.Duration),\n Schema.annotations({\n title: 'Duration',\n description: 'Duration in ISO 8601 format',\n [SchemaAST.ExamplesAnnotationId]: ['1h', '3D'],\n }),\n);\n\n//\n// Utils\n//\n\n// YYYY-MM-DD\nconst DATE_REGEX = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nconst _isValidDateFormat = (str: string) => DATE_REGEX.test(str);\n\nconst _isValidDate = (str: string) => {\n const date = new Date(str);\n return !isNaN(date.getTime()) && date.toISOString().startsWith(str);\n};\n\n// HH:mm:ss\nconst TIME_REGEX = /^([01]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)$/;\n\nconst _isValidTimeFormat = (str: string) => TIME_REGEX.test(str);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n/**\n * Schema for a single select option. Used to define choices in a {single|multi}-select field.\n */\nexport const SelectOption = Schema.Struct({\n /** Stable identifier for the option. */\n id: Schema.NonEmptyString,\n title: Schema.String,\n /** Color palette used for visual styling. */\n color: Schema.String,\n});\n\nexport type SelectOption = Schema.Schema.Type<typeof SelectOption>;\n"],
|
|
5
|
+
"mappings": ";;;;;AAIA,YAAYA,cAAc;AAE1B,YAAYC,YAAY;AACxB,YAAYC,eAAe;AAepB,IAAKC,WAAAA,0BAAAA,WAAAA;;;;;;;SAAAA;;AAUL,IAAMC,cAAc,CAACC,aAAAA;AAC1B,UAAQA,SAASC,MAAI;IACnB,KAAK;AACH,aAAA;IACF,KAAK;AACH,aAAA;IACF,KAAK;AACH,aAAA;IACF,KA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BjB,YAAYuB,aAAY;AAKjB,IAAMC,eAAsBC,eAAO;;EAExCC,IAAWC;EACXC,OAAcC;;EAEdC,OAAcD;AAChB,CAAA;",
|
|
6
|
+
"names": ["Function", "Option", "SchemaAST", "TypeEnum", "getTypeEnum", "property", "type", "undefined", "FormatAnnotationId", "Symbol", "for", "FormatAnnotation", "createAnnotationHelper", "getFormatAnnotation", "node", "pipe", "getAnnotation", "getOrUndefined", "TypeFormat", "FormatEnums", "Object", "values", "sort", "PropertyKind", "format", "typeToFormat", "formatToType", "OptionsAnnotationId", "OptionsAnnotation", "getOptionsAnnotation", "Schema", "encodeMultipleOf", "divisor", "Math", "pow", "encodeMultiple", "self", "undefined", "pipe", "multipleOf", "DecimalPrecision", "transform", "Number", "strict", "encode", "value", "decode", "log10", "annotations", "title", "CurrencyAnnotationId", "Symbol", "for", "Currency", "decimals", "code", "FormatAnnotation", "set", "TypeFormat", "description", "toUpperCase", "Integer", "int", "Percent", "Timestamp", "Schema", "clamp", "GeoPoint", "Tuple", "Number", "pipe", "annotations", "title", "clamp", "multipleOf", "optionalElement", "FormatAnnotation", "set", "TypeFormat", "description", "GeoLocation", "toGeoPoint", "longitude", "latitude", "height", "clampedLongitude", "clampedLatitude", "undefined", "fromGeoPoint", "geoPoint", "result", "Schema", "SchemaAST", "Email", "String", "pipe", "pattern", "FormatAnnotation", "set", "TypeFormat", "annotations", "title", "description", "Formula", "Hostname", "JSON", "Markdown", "Regex", "Text", "URL", "UUID", "ExamplesAnnotationId", "Schema", "Keys", "Schema", "SchemaAST", "SimpleDate", "Struct", "year", "Number", "pipe", "between", "month", "day", "SimpleTime", "Struct", "hours", "Number", "pipe", "between", "minutes", "seconds", "SimpleDateTime", "extend", "SimpleDate", "SimpleTime", "DateOnly", "String", "pipe", "FormatAnnotation", "set", "TypeFormat", "Date", "annotations", "title", "description", "TimeOnly", "Time", "DateTime", "Duration", "ExamplesAnnotationId", "Format", "TypeFormat", "DXN", "Schema", "Email", "Formula", "Hostname", "JSON", "Markdown", "Regex", "URL", "UUID", "Currency", "Integer", "Percent", "Timestamp", "Date", "DateOnly", "DateTime", "Duration", "Time", "TimeOnly", "GeoPoint", "Schema", "SelectOption", "Struct", "id", "NonEmptyString", "title", "String", "color"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
__export
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
5
4
|
|
|
6
5
|
// src/Key.ts
|
|
7
6
|
var Key_exports = {};
|
|
@@ -19,4 +18,4 @@ export {
|
|
|
19
18
|
SpaceId,
|
|
20
19
|
ObjectId
|
|
21
20
|
};
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-ANHVGJI4.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Key.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(wittjosiah): Should this be a subset of Type?\n\nexport { ForeignKey } from '@dxos/echo-protocol';\nexport { SpaceId, ObjectId } from '@dxos/keys';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;AAMA,SAASA,kBAAkB;AAC3B,SAASC,SAASC,gBAAgB;",
|
|
6
6
|
"names": ["ForeignKey", "SpaceId", "ObjectId"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isInstanceOf
|
|
3
|
+
} from "./chunk-RIMHNJ3E.mjs";
|
|
4
|
+
import {
|
|
5
|
+
ObjectNotFoundError
|
|
6
|
+
} from "./chunk-MXQJZCPY.mjs";
|
|
7
|
+
import {
|
|
8
|
+
__export
|
|
9
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
10
|
+
|
|
11
|
+
// src/Database.ts
|
|
12
|
+
var Database_exports = {};
|
|
13
|
+
__export(Database_exports, {
|
|
14
|
+
Database: () => Database,
|
|
15
|
+
Service: () => Service,
|
|
16
|
+
TypeId: () => TypeId,
|
|
17
|
+
add: () => add,
|
|
18
|
+
flush: () => flush,
|
|
19
|
+
isDatabase: () => isDatabase,
|
|
20
|
+
layer: () => layer,
|
|
21
|
+
load: () => load,
|
|
22
|
+
loadOption: () => loadOption,
|
|
23
|
+
makeService: () => makeService,
|
|
24
|
+
notAvailable: () => notAvailable,
|
|
25
|
+
query: () => query,
|
|
26
|
+
remove: () => remove,
|
|
27
|
+
resolve: () => resolve,
|
|
28
|
+
runQuery: () => runQuery,
|
|
29
|
+
runSchemaQuery: () => runSchemaQuery,
|
|
30
|
+
schemaQuery: () => schemaQuery,
|
|
31
|
+
spaceId: () => spaceId
|
|
32
|
+
});
|
|
33
|
+
import * as Context from "effect/Context";
|
|
34
|
+
import * as Effect from "effect/Effect";
|
|
35
|
+
import * as Layer from "effect/Layer";
|
|
36
|
+
import * as Option from "effect/Option";
|
|
37
|
+
import * as Schema from "effect/Schema";
|
|
38
|
+
import { promiseWithCauseCapture } from "@dxos/effect";
|
|
39
|
+
import { invariant } from "@dxos/invariant";
|
|
40
|
+
import { DXN } from "@dxos/keys";
|
|
41
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Database.ts";
|
|
42
|
+
var TypeId = Symbol.for("@dxos/echo/Database");
|
|
43
|
+
var isDatabase = (obj) => {
|
|
44
|
+
return obj ? typeof obj === "object" && TypeId in obj && obj[TypeId] === TypeId : false;
|
|
45
|
+
};
|
|
46
|
+
var Database = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));
|
|
47
|
+
var Service = class extends Context.Tag("@dxos/echo/Database/Service")() {
|
|
48
|
+
};
|
|
49
|
+
var notAvailable = Layer.succeed(Service, {
|
|
50
|
+
get db() {
|
|
51
|
+
throw new Error("Database not available");
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
var makeService = (db) => {
|
|
55
|
+
return {
|
|
56
|
+
get db() {
|
|
57
|
+
return db;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
var layer = (db) => {
|
|
62
|
+
return Layer.succeed(Service, makeService(db));
|
|
63
|
+
};
|
|
64
|
+
var spaceId = Effect.gen(function* () {
|
|
65
|
+
const { db } = yield* Service;
|
|
66
|
+
return db.spaceId;
|
|
67
|
+
});
|
|
68
|
+
var resolve = (ref, schema) => Effect.gen(function* () {
|
|
69
|
+
const { db } = yield* Service;
|
|
70
|
+
const dxn = ref instanceof DXN ? ref : ref.dxn;
|
|
71
|
+
const object = yield* promiseWithCauseCapture(() => db.graph.createRefResolver({
|
|
72
|
+
context: {
|
|
73
|
+
space: db.spaceId
|
|
74
|
+
}
|
|
75
|
+
}).resolve(dxn));
|
|
76
|
+
if (!object) {
|
|
77
|
+
return yield* Effect.fail(new ObjectNotFoundError(dxn));
|
|
78
|
+
}
|
|
79
|
+
invariant(!schema || isInstanceOf(schema, object), "Object type mismatch.", {
|
|
80
|
+
F: __dxlog_file,
|
|
81
|
+
L: 266,
|
|
82
|
+
S: this,
|
|
83
|
+
A: [
|
|
84
|
+
"!schema || isInstanceOf(schema, object)",
|
|
85
|
+
"'Object type mismatch.'"
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
return object;
|
|
89
|
+
});
|
|
90
|
+
var load = Effect.fn(function* (ref) {
|
|
91
|
+
const object = yield* promiseWithCauseCapture(() => ref.tryLoad());
|
|
92
|
+
if (!object) {
|
|
93
|
+
return yield* Effect.fail(new ObjectNotFoundError(ref.dxn));
|
|
94
|
+
}
|
|
95
|
+
return object;
|
|
96
|
+
});
|
|
97
|
+
var loadOption = Effect.fn(function* (ref) {
|
|
98
|
+
const object = yield* load(ref).pipe(Effect.catchTag("ObjectNotFoundError", () => Effect.succeed(void 0)));
|
|
99
|
+
return Option.fromNullable(object);
|
|
100
|
+
});
|
|
101
|
+
var add = (obj) => Service.pipe(Effect.map(({ db }) => db.add(obj)));
|
|
102
|
+
var remove = (obj) => Service.pipe(Effect.map(({ db }) => db.remove(obj)));
|
|
103
|
+
var flush = (opts) => Service.pipe(Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.flush(opts))));
|
|
104
|
+
var query = (queryOrFilter) => Service.pipe(Effect.map(({ db }) => db.query(queryOrFilter)), Effect.withSpan("Database.query"));
|
|
105
|
+
var runQuery = (queryOrFilter) => query(queryOrFilter).pipe(Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())));
|
|
106
|
+
var schemaQuery = (schemaQueryOptions) => Service.pipe(Effect.map(({ db }) => db.schemaRegistry.query(schemaQueryOptions)), Effect.withSpan("Database.schemaQuery"));
|
|
107
|
+
var runSchemaQuery = (schemaQueryOptions) => schemaQuery(schemaQueryOptions).pipe(Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())));
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
TypeId,
|
|
111
|
+
isDatabase,
|
|
112
|
+
Database,
|
|
113
|
+
Service,
|
|
114
|
+
notAvailable,
|
|
115
|
+
makeService,
|
|
116
|
+
layer,
|
|
117
|
+
spaceId,
|
|
118
|
+
resolve,
|
|
119
|
+
load,
|
|
120
|
+
loadOption,
|
|
121
|
+
add,
|
|
122
|
+
remove,
|
|
123
|
+
flush,
|
|
124
|
+
query,
|
|
125
|
+
runQuery,
|
|
126
|
+
schemaQuery,
|
|
127
|
+
runSchemaQuery,
|
|
128
|
+
Database_exports
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=chunk-B4FLOYG7.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Database.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { type QueryAST } from '@dxos/echo-protocol';\nimport { promiseWithCauseCapture } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { DXN, type PublicKey, type SpaceId } from '@dxos/keys';\nimport { type QueryOptions as QueryOptionsProto } from '@dxos/protocols/proto/dxos/echo/filter';\n\nimport type * as Entity from './Entity';\nimport * as Err from './Err';\nimport type * as Filter from './Filter';\nimport type * as Hypergraph from './Hypergraph';\nimport { isInstanceOf } from './internal/annotations';\nimport type { Ref } from './internal/ref/ref';\nimport { type AnyProperties } from './internal/types';\nimport type * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport type * as SchemaRegistry from './SchemaRegistry';\nimport type * as Type from './Type';\n\n/**\n * @deprecated Use `QueryAST.QueryOptions` instead.\n */\nexport type QueryOptions = {\n /**\n * @deprecated Use `spaceIds` instead.\n */\n spaces?: PublicKey[];\n\n /**\n * Query only in specific spaces.\n */\n // TODO(dmaretskyi): Change this to SpaceId.\n spaceIds?: string[];\n\n /**\n * Return only the first `limit` results.\n */\n limit?: number;\n\n /**\n * Query only local spaces, or remote on agent.\n * @default `QueryOptions.DataLocation.LOCAL`\n *\n * Options:\n * - proto3_optional = true\n */\n // TODO(burdon): Remove?\n dataLocation?: QueryOptionsProto.DataLocation;\n};\n\n/**\n * `query` API function declaration.\n */\n// TODO(burdon): Reconcile Query and Filter (should only have one root type).\n// TODO(dmaretskyi): Remove query options.\nexport interface QueryFn {\n <Q extends Query.Any>(\n query: Q,\n options?: (QueryAST.QueryOptions & QueryOptions) | undefined,\n ): QueryResult.QueryResult<Query.Type<Q>>;\n\n <F extends Filter.Any>(\n filter: F,\n options?: (QueryAST.QueryOptions & QueryOptions) | undefined,\n ): QueryResult.QueryResult<Filter.Type<F>>;\n}\n\n/**\n * Common interface for Database and Queue.\n */\nexport interface Queryable {\n query: QueryFn;\n}\n\nexport type GetObjectByIdOptions = {\n deleted?: boolean;\n};\n\nexport type ObjectPlacement = 'root-doc' | 'linked-doc';\n\nexport type AddOptions = {\n /**\n * Where to place the object in the Automerge document tree.\n * Root document is always loaded with the space.\n * Linked documents are loaded lazily.\n * Placing large number of objects in the root document may slow down the initial load.\n *\n * @default 'linked-doc'\n */\n placeIn?: ObjectPlacement;\n};\n\nexport type FlushOptions = {\n /**\n * Write any pending changes to disk.\n * @default true\n */\n disk?: boolean;\n\n /**\n * Wait for pending index updates.\n * @default false\n */\n indexes?: boolean;\n\n /**\n * Flush pending updates to objects and queries.\n * @default false\n */\n updates?: boolean;\n};\n\n/**\n * Identifier denoting an ECHO Database.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Database');\nexport type TypeId = typeof TypeId;\n\n/**\n * ECHO Database interface.\n */\nexport interface Database extends Queryable {\n readonly [TypeId]: TypeId;\n\n get spaceId(): SpaceId;\n\n // TODO(burdon): Can we move this into graph?\n get schemaRegistry(): SchemaRegistry.SchemaRegistry;\n\n get graph(): Hypergraph.Hypergraph;\n\n toJSON(): object;\n\n /**\n * Return object by local ID.\n */\n getObjectById<T extends Obj.Unknown = Obj.Obj<AnyProperties>>(id: string, opts?: GetObjectByIdOptions): T | undefined;\n\n /**\n * Query objects.\n */\n query: QueryFn;\n\n /**\n * Creates a reference to an existing object in the database.\n *\n * NOTE: The reference may be dangling if the object is not present in the database.\n * NOTE: Difference from `Ref.fromDXN`\n * `Ref.fromDXN(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n * `db.makeRef(dxn)` is preferable in cases with access to the database.\n */\n makeRef<T extends Entity.Unknown = Entity.Unknown>(dxn: DXN): Ref<T>;\n\n /**\n * Adds object to the database.\n */\n add<T extends Entity.Unknown = Entity.Unknown>(obj: T, opts?: AddOptions): T;\n\n /**\n * Removes object from the database.\n */\n // TODO(burdon): Return true if removed (currently throws if not present).\n remove(obj: Entity.Unknown): void;\n\n /**\n * Wait for all pending changes to be saved to disk.\n * Optionaly waits for changes to be propagated to indexes and event handlers.\n */\n flush(opts?: FlushOptions): Promise<void>;\n}\n\nexport const isDatabase = (obj: unknown): obj is Database => {\n return obj ? typeof obj === 'object' && TypeId in obj && obj[TypeId] === TypeId : false;\n};\n\nexport const Database: Schema.Schema<Database> = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));\n\n/**\n * Effect service tag for Database dependency injection.\n */\nexport class Service extends Context.Tag('@dxos/echo/Database/Service')<\n Service,\n {\n readonly db: Database;\n }\n>() {}\n\n/**\n * Layer that provides a Database service that throws when accessed.\n * Useful as a default layer when no database is available.\n */\nexport const notAvailable = Layer.succeed(Service, {\n get db(): Database {\n throw new Error('Database not available');\n },\n});\n\n/**\n * Creates a Database service instance from a Database.\n */\nexport const makeService = (db: Database): Context.Tag.Service<Service> => {\n return {\n get db() {\n return db;\n },\n };\n};\n\n/**\n * Creates a Layer that provides the Database service.\n */\nexport const layer = (db: Database): Layer.Layer<Service> => {\n return Layer.succeed(Service, makeService(db));\n};\n\n/**\n * Returns the space ID of the database.\n */\nexport const spaceId = Effect.gen(function* () {\n const { db } = yield* Service;\n return db.spaceId;\n});\n\n/**\n * Resolves an object by its DXN.\n */\nexport const resolve: {\n // No type check.\n (ref: DXN | Ref<any>): Effect.Effect<Entity.Unknown, never, Service>;\n // Check matches schema.\n <S extends Type.Entity.Any>(\n ref: DXN | Ref<any>,\n schema: S,\n ): Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Service>;\n} = (<S extends Type.Entity.Any>(\n ref: DXN | Ref<any>,\n schema?: S,\n): Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Service> =>\n Effect.gen(function* () {\n const { db } = yield* Service;\n const dxn = ref instanceof DXN ? ref : ref.dxn;\n const object = yield* promiseWithCauseCapture(() =>\n db.graph\n .createRefResolver({\n context: {\n space: db.spaceId,\n },\n })\n .resolve(dxn),\n );\n\n if (!object) {\n return yield* Effect.fail(new Err.ObjectNotFoundError(dxn));\n }\n invariant(!schema || isInstanceOf(schema, object), 'Object type mismatch.');\n return object as any;\n })) as any;\n\n/**\n * Loads an object reference.\n */\nexport const load: <T>(ref: Ref<T>) => Effect.Effect<T, Err.ObjectNotFoundError, never> = Effect.fn(function* (ref) {\n const object = yield* promiseWithCauseCapture(() => ref.tryLoad());\n if (!object) {\n return yield* Effect.fail(new Err.ObjectNotFoundError(ref.dxn));\n }\n return object;\n});\n\n/**\n * Loads an object reference option.\n */\n// TODO(dmaretskyi): Do we need this -- you can just use `Effect.catchTag` in calling code instead.\nexport const loadOption: <T>(ref: Ref<T>) => Effect.Effect<Option.Option<T>, never, never> = Effect.fn(function* (ref) {\n const object = yield* load(ref).pipe(Effect.catchTag('ObjectNotFoundError', () => Effect.succeed(undefined)));\n\n return Option.fromNullable(object);\n});\n\n/**\n * Adds an object to the database.\n * @see {@link Database.add}\n */\nexport const add = <T extends Entity.Unknown>(obj: T): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.add(obj)));\n\n/**\n * Removes an object from the database.\n * @see {@link Database.remove}\n */\nexport const remove = <T extends Entity.Unknown>(obj: T): Effect.Effect<void, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.remove(obj)));\n\n/**\n * Flushes pending changes to disk.\n * @see {@link Database.flush}\n */\nexport const flush = (opts?: FlushOptions) =>\n Service.pipe(Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.flush(opts))));\n\n/**\n * Creates a `QueryResult` object that can be subscribed to.\n */\nexport const query: {\n <Q extends Query.Any>(query: Q): Effect.Effect<QueryResult.QueryResult<Query.Type<Q>>, never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<QueryResult.QueryResult<Filter.Type<F>>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n Service.pipe(\n Effect.map(({ db }) => db.query(queryOrFilter as any) as QueryResult.QueryResult<any>),\n Effect.withSpan('Database.query'),\n );\n\n/**\n * Executes the query once and returns the results.\n */\nexport const runQuery: {\n <Q extends Query.Any>(query: Q): Effect.Effect<Query.Type<Q>[], never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<Filter.Type<F>[], never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n query(queryOrFilter as any).pipe(Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())));\n\n/**\n * Creates a schema query result that can be subscribed to.\n */\n// TODO(dmaretskyi): Change API to `yield* Database.querySchema(...).first` and `yield* Database.querySchema(...).schema`.\nexport const schemaQuery = <Q extends Types.NoExcessProperties<SchemaRegistry.Query, Q>>(\n schemaQueryOptions?: Q & SchemaRegistry.Query,\n): Effect.Effect<QueryResult.QueryResult<SchemaRegistry.ExtractQueryResult<Q>>, never, Service> =>\n Service.pipe(\n Effect.map(({ db }) => db.schemaRegistry.query(schemaQueryOptions)),\n Effect.withSpan('Database.schemaQuery'),\n );\n\n/**\n * Executes a schema query once and returns the results.\n */\nexport const runSchemaQuery = <Q extends Types.NoExcessProperties<SchemaRegistry.Query, Q>>(\n schemaQueryOptions?: Q & SchemaRegistry.Query,\n): Effect.Effect<SchemaRegistry.ExtractQueryResult<Q>[], never, Service> =>\n schemaQuery(schemaQueryOptions).pipe(\n Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())),\n );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,YAAY;AACxB,YAAYC,YAAY;AAIxB,SAASC,+BAA+B;AACxC,SAASC,iBAAiB;AAC1B,SAASC,WAAyC;;AAgH3C,IAAMC,SAASC,OAAOC,IAAI,qBAAA;AAwD1B,IAAMC,aAAa,CAACC,QAAAA;AACzB,SAAOA,MAAM,OAAOA,QAAQ,YAAYJ,UAAUI,OAAOA,IAAIJ,MAAAA,MAAYA,SAAS;AACpF;AAEO,IAAMK,WAA2CC,WAAIC,KAAYC,cA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e", "filter", "space", "Service", "Tag", "notAvailable", "succeed", "db", "Error", "makeService", "layer", "spaceId", "gen", "resolve", "ref", "schema", "dxn", "DXN", "object", "promiseWithCauseCapture", "graph", "createRefResolver", "context", "fail", "ObjectNotFoundError", "invariant", "isInstanceOf", "load", "fn", "tryLoad", "loadOption", "catchTag", "undefined", "fromNullable", "add", "map", "remove", "flush", "opts", "flatMap", "query", "queryOrFilter", "withSpan", "runQuery", "queryResult", "run", "schemaQuery", "schemaQueryOptions", "schemaRegistry", "runSchemaQuery"]
|
|
7
|
+
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
object
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SHLKRGRB.mjs";
|
|
5
4
|
import {
|
|
6
5
|
make
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5MGEVDUW.mjs";
|
|
8
7
|
import {
|
|
9
8
|
LabelAnnotation,
|
|
10
9
|
SystemTypeAnnotation
|
|
11
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-RIMHNJ3E.mjs";
|
|
12
11
|
import {
|
|
13
12
|
__export
|
|
14
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
15
14
|
|
|
16
15
|
// src/Tag.ts
|
|
17
16
|
var Tag_exports = {};
|
|
@@ -54,4 +53,4 @@ export {
|
|
|
54
53
|
findTagByLabel,
|
|
55
54
|
Tag_exports
|
|
56
55
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
56
|
+
//# sourceMappingURL=chunk-BHR4XVJK.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Tag.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { LabelAnnotation, SystemTypeAnnotation } from './internal';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\n\nexport const Tag = Schema.Struct({\n label: Schema.String,\n hue: Schema.optional(Schema.String), // TODO(burdon): Color name?\n}).pipe(\n Type.object({\n typename: 'dxos.org/type/Tag',\n version: '0.1.0',\n }),\n LabelAnnotation.set(['label']),\n SystemTypeAnnotation.set(true),\n);\n\nexport type Tag = Schema.Schema.Type<typeof Tag>;\n\nexport const make = (props: Obj.MakeProps<typeof Tag>) => Obj.make(Tag, props);\n\n// TODO(burdon): Rename Map.\nexport type Map = Record<string, Tag>;\n\nexport const sortTags = ({ label: a }: Tag, { label: b }: Tag) => a.localeCompare(b);\n\nexport const createTagList = (tags: Map): Tag[] =>\n Object.entries(tags)\n .map(([id, tag]) => ({ ...tag, id }))\n .sort(sortTags);\n\nexport const findTagByLabel = (tags: Map | undefined, name: string): Tag | undefined => {\n const entry = Object.entries(tags ?? {}).find(([_, tag]) => tag.label.toLowerCase() === name.toLowerCase());\n return entry ? { ...entry[1], id: entry[0] } : undefined;\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;;;;;cAAAA;EAAA;;AAIA,YAAYC,YAAY;AAMjB,IAAMC,MAAaC,cAAO;EAC/BC,OAAcC;EACdC,KAAYC,gBAAgBF,aAAM;AACpC,CAAA,EAAGG,KACIC,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,gBAAgBC,IAAI;EAAC;CAAQ,GAC7BC,qBAAqBD,IAAI,IAAA,CAAA;AAKpB,IAAME,QAAO,CAACC,UAAyCD,KAAKb,KAAKc,KAAAA;AAKjE,IAAMC,WAAW,CAAC,EAAEb,OAAOc,EAAC,GAAS,EAAEd,OAAOe,EAAC,MAAYD,EAAEE,cAAcD,CAAAA;AAE3E,IAAME,gBAAgB,CAACC,SAC5BC,OAAOC,QAAQF,IAAAA,EACZG,IAAI,CAAC,CAACC,IAAIC,GAAAA,OAAU;EAAE,GAAGA;EAAKD;AAAG,EAAA,EACjCE,KAAKX,QAAAA;AAEH,IAAMY,iBAAiB,CAACP,MAAuBQ,SAAAA;AACpD,QAAMC,QAAQR,OAAOC,QAAQF,QAAQ,CAAC,CAAA,EAAGU,KAAK,CAAC,CAACC,GAAGN,GAAAA,MAASA,IAAIvB,MAAM8B,YAAW,MAAOJ,KAAKI,YAAW,CAAA;AACxG,SAAOH,QAAQ;IAAE,GAAGA,MAAM,CAAA;IAAIL,IAAIK,MAAM,CAAA;EAAG,IAAII;AACjD;",
|
|
6
6
|
"names": ["make", "Schema", "Tag", "Struct", "label", "String", "hue", "optional", "pipe", "object", "typename", "version", "LabelAnnotation", "set", "SystemTypeAnnotation", "make", "props", "sortTags", "a", "b", "localeCompare", "createTagList", "tags", "Object", "entries", "map", "id", "tag", "sort", "findTagByLabel", "name", "entry", "find", "_", "toLowerCase", "undefined"]
|
|
7
7
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
isRef
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WSPASOLU.mjs";
|
|
5
4
|
import {
|
|
6
5
|
getTypeDXNFromSpecifier
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RIMHNJ3E.mjs";
|
|
8
7
|
import {
|
|
9
8
|
__export
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
11
10
|
|
|
12
11
|
// src/Filter.ts
|
|
13
12
|
var Filter_exports = {};
|
|
@@ -285,4 +284,4 @@ export {
|
|
|
285
284
|
or,
|
|
286
285
|
Filter_exports
|
|
287
286
|
};
|
|
288
|
-
//# sourceMappingURL=chunk-
|
|
287
|
+
//# sourceMappingURL=chunk-CH3HX4Z5.mjs.map
|