@dxos/echo 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/lib/neutral/Annotation.mjs +37 -0
- package/dist/lib/neutral/Database.mjs +45 -0
- package/dist/lib/neutral/Entity.mjs +56 -0
- package/dist/lib/neutral/Err.mjs +12 -0
- package/dist/lib/neutral/Feed.mjs +43 -0
- package/dist/lib/neutral/Filter.mjs +61 -0
- package/dist/lib/neutral/Format.mjs +66 -0
- package/dist/lib/neutral/Format.mjs.map +7 -0
- package/dist/lib/neutral/JsonSchema.mjs +18 -0
- package/dist/lib/neutral/JsonSchema.mjs.map +7 -0
- package/dist/lib/neutral/Key.mjs +12 -0
- package/dist/lib/neutral/Key.mjs.map +7 -0
- package/dist/lib/neutral/Obj.mjs +107 -0
- package/dist/lib/neutral/Obj.mjs.map +7 -0
- package/dist/lib/neutral/Order.mjs +12 -0
- package/dist/lib/neutral/Order.mjs.map +7 -0
- package/dist/lib/neutral/Query.mjs +32 -0
- package/dist/lib/neutral/Query.mjs.map +7 -0
- package/dist/lib/neutral/QueryResult.mjs +2 -0
- package/dist/lib/neutral/QueryResult.mjs.map +7 -0
- package/dist/lib/neutral/Ref.mjs +24 -0
- package/dist/lib/neutral/Ref.mjs.map +7 -0
- package/dist/lib/neutral/Relation.mjs +90 -0
- package/dist/lib/neutral/Relation.mjs.map +7 -0
- package/dist/lib/neutral/SchemaRegistry.mjs +2 -0
- package/dist/lib/neutral/SchemaRegistry.mjs.map +7 -0
- package/dist/lib/neutral/Tag.mjs +25 -0
- package/dist/lib/neutral/Tag.mjs.map +7 -0
- package/dist/lib/neutral/Type.mjs +34 -0
- package/dist/lib/neutral/Type.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4KG6IGL4.mjs +67 -0
- package/dist/lib/neutral/chunk-4KG6IGL4.mjs.map +7 -0
- package/dist/lib/neutral/chunk-5ELDDYWE.mjs +130 -0
- package/dist/lib/neutral/chunk-5ELDDYWE.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ALOGSVBP.mjs +299 -0
- package/dist/lib/neutral/chunk-ALOGSVBP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ANHVGJI4.mjs +21 -0
- package/dist/lib/neutral/chunk-ANHVGJI4.mjs.map +7 -0
- package/dist/lib/neutral/chunk-AQP4QKYP.mjs +283 -0
- package/dist/lib/neutral/chunk-AQP4QKYP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-BRJSLACP.mjs +152 -0
- package/dist/lib/neutral/chunk-BRJSLACP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DZQSL6RW.mjs +73 -0
- package/dist/lib/neutral/chunk-DZQSL6RW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-F7KMHDPJ.mjs +327 -0
- package/dist/lib/neutral/chunk-F7KMHDPJ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GAWKQ5DZ.mjs +56 -0
- package/dist/lib/neutral/chunk-GAWKQ5DZ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GFNCSK7F.mjs +101 -0
- package/dist/lib/neutral/chunk-GFNCSK7F.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-KGV3QIRX.mjs +313 -0
- package/dist/lib/neutral/chunk-KGV3QIRX.mjs.map +7 -0
- package/dist/lib/neutral/chunk-M2KVTHZM.mjs +402 -0
- package/dist/lib/neutral/chunk-M2KVTHZM.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MXQJZCPY.mjs +51 -0
- package/dist/lib/neutral/chunk-MXQJZCPY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-O3TZFQCT.mjs +27 -0
- package/dist/lib/neutral/chunk-O3TZFQCT.mjs.map +7 -0
- package/dist/lib/neutral/chunk-OMUPQMLR.mjs +7 -0
- package/dist/lib/neutral/chunk-OMUPQMLR.mjs.map +7 -0
- package/dist/lib/neutral/chunk-OVUBTQLT.mjs +45 -0
- package/dist/lib/neutral/chunk-OVUBTQLT.mjs.map +7 -0
- package/dist/lib/neutral/chunk-PP4DNUZU.mjs +3919 -0
- package/dist/lib/neutral/chunk-PP4DNUZU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QXF3LGN2.mjs +43 -0
- package/dist/lib/neutral/chunk-QXF3LGN2.mjs.map +7 -0
- package/dist/lib/neutral/chunk-T4MPQJ7X.mjs +97 -0
- package/dist/lib/neutral/chunk-T4MPQJ7X.mjs.map +7 -0
- package/dist/lib/neutral/chunk-T6JEFNP6.mjs +7 -0
- package/dist/lib/neutral/chunk-T6JEFNP6.mjs.map +7 -0
- package/dist/lib/neutral/chunk-W7OP5HGZ.mjs +121 -0
- package/dist/lib/neutral/chunk-W7OP5HGZ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ZTUBYOGB.mjs +42 -0
- package/dist/lib/neutral/chunk-ZTUBYOGB.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ZWKJ4LZJ.mjs +298 -0
- package/dist/lib/neutral/chunk-ZWKJ4LZJ.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +94 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/{node-esm → neutral}/internal/index.mjs +260 -122
- package/dist/lib/neutral/internal/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +369 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Annotation.d.ts +24 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Collection.d.ts +16 -0
- package/dist/types/src/Collection.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +189 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Dataset.d.ts +18 -0
- package/dist/types/src/Dataset.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +168 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Entity.test.d.ts +2 -0
- package/dist/types/src/Entity.test.d.ts.map +1 -0
- package/dist/types/src/Err.d.ts +107 -0
- package/dist/types/src/Err.d.ts.map +1 -0
- package/dist/types/src/Feed.d.ts +165 -0
- package/dist/types/src/Feed.d.ts.map +1 -0
- package/dist/types/src/Filter.d.ts +120 -0
- package/dist/types/src/Filter.d.ts.map +1 -0
- package/dist/types/src/Format.d.ts +4 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/Hypergraph.d.ts +60 -0
- package/dist/types/src/Hypergraph.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +16 -0
- package/dist/types/src/JsonSchema.d.ts.map +1 -0
- package/dist/types/src/Key.d.ts +1 -0
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +423 -95
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Obj.test.d.ts +2 -0
- package/dist/types/src/Obj.test.d.ts.map +1 -0
- package/dist/types/src/Order.d.ts +16 -0
- package/dist/types/src/Order.d.ts.map +1 -0
- package/dist/types/src/Query.d.ts +202 -0
- package/dist/types/src/Query.d.ts.map +1 -0
- package/dist/types/src/Query.test.d.ts +2 -0
- package/dist/types/src/Query.test.d.ts.map +1 -0
- package/dist/types/src/QueryResult.d.ts +80 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -0
- package/dist/types/src/Ref.d.ts +61 -11
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +287 -21
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Relation.test.d.ts +2 -0
- package/dist/types/src/Relation.test.d.ts.map +1 -0
- package/dist/types/src/SchemaRegistry.d.ts +84 -0
- package/dist/types/src/SchemaRegistry.d.ts.map +1 -0
- package/dist/types/src/Tag.d.ts +18 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +120 -97
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/Type.test.d.ts +2 -0
- package/dist/types/src/Type.test.d.ts.map +1 -0
- package/dist/types/src/View.d.ts +68 -0
- package/dist/types/src/View.d.ts.map +1 -0
- 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/index.d.ts +19 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +209 -0
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/index.d.ts +3 -0
- package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/util.d.ts +39 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
- package/dist/types/src/internal/api/annotations.d.ts +23 -0
- package/dist/types/src/internal/api/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/api/entity.d.ts +13 -0
- package/dist/types/src/internal/api/entity.d.ts.map +1 -0
- package/dist/types/src/internal/api/index.d.ts +15 -0
- package/dist/types/src/internal/api/index.d.ts.map +1 -0
- package/dist/types/src/internal/api/meta.d.ts +42 -0
- package/dist/types/src/internal/api/meta.d.ts.map +1 -0
- package/dist/types/src/internal/api/sorting.d.ts +24 -0
- package/dist/types/src/internal/api/sorting.d.ts.map +1 -0
- package/dist/types/src/internal/api/version.d.ts +42 -0
- package/dist/types/src/internal/api/version.d.ts.map +1 -0
- package/dist/types/src/internal/entities/entity.d.ts +20 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/entities/index.d.ts +6 -0
- package/dist/types/src/internal/entities/index.d.ts.map +1 -0
- package/dist/types/src/internal/entities/model.d.ts +79 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +18 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +62 -0
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
- package/dist/types/src/internal/entities/util.d.ts +2 -0
- package/dist/types/src/internal/entities/util.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +4 -2
- package/dist/types/src/internal/formats/format.d.ts.map +1 -1
- package/dist/types/src/internal/formats/select.d.ts +6 -4
- package/dist/types/src/internal/formats/select.d.ts.map +1 -1
- package/dist/types/src/internal/formats/string.d.ts +4 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -1
- package/dist/types/src/internal/formats/types.d.ts +13 -9
- package/dist/types/src/internal/formats/types.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +7 -10
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +2 -0
- package/dist/types/src/internal/json-schema/index.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 → json-schema}/json-schema.d.ts +4 -6
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/clone.d.ts +8 -0
- package/dist/types/src/internal/object/clone.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -1
- package/dist/types/src/internal/object/{create.d.ts → create-object.d.ts} +10 -11
- package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +2 -2
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/object/ids.d.ts.map +1 -1
- package/dist/types/src/internal/object/index.d.ts +6 -12
- package/dist/types/src/internal/object/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts +14 -9
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/object/schema-validator.d.ts +1 -14
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/object/set-value.d.ts +7 -0
- package/dist/types/src/internal/object/set-value.d.ts.map +1 -0
- package/dist/types/src/internal/object/set-value.test.d.ts +2 -0
- package/dist/types/src/internal/object/set-value.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/snapshot.d.ts +6 -0
- package/dist/types/src/internal/object/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.d.ts +8 -14
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -1
- package/dist/types/src/internal/proxy/change-context.d.ts +55 -0
- package/dist/types/src/internal/proxy/change-context.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/change.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/change.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts +5 -0
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/errors.d.ts +19 -0
- package/dist/types/src/internal/proxy/errors.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/event-batch.d.ts +10 -0
- package/dist/types/src/internal/proxy/event-batch.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/index.d.ts +14 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/json-serializer.d.ts +6 -0
- package/dist/types/src/internal/proxy/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +14 -0
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/ownership.d.ts +57 -0
- package/dist/types/src/internal/proxy/ownership.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/proxy-types.d.ts +18 -0
- package/dist/types/src/internal/proxy/proxy-types.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/proxy-utils.d.ts +47 -0
- package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive-array.d.ts +8 -0
- package/dist/types/src/internal/proxy/reactive-array.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive.d.ts +39 -0
- package/dist/types/src/internal/proxy/reactive.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema-validator.d.ts +15 -0
- package/dist/types/src/internal/proxy/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/symbols.d.ts +3 -0
- package/dist/types/src/internal/proxy/symbols.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +16 -12
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref-array.d.ts +4 -4
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref.d.ts +43 -18
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/schema/compose.d.ts +7 -0
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +25 -12
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/index.d.ts +1 -4
- package/dist/types/src/internal/schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts +20 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/types/base.d.ts +27 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/types/entity.d.ts +37 -0
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +5 -2
- package/dist/types/src/internal/types/index.d.ts.map +1 -1
- package/dist/types/src/internal/{object → types}/meta.d.ts +16 -14
- package/dist/types/src/internal/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/types/typename.d.ts +21 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/types/version.d.ts +15 -0
- package/dist/types/src/internal/types/version.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -3
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +304 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +21 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +106 -65
- package/src/Annotation.ts +46 -0
- package/src/Collection.ts +30 -0
- package/src/Database.ts +315 -0
- package/src/Dataset.ts +24 -0
- package/src/Entity.test.ts +22 -0
- package/src/Entity.ts +234 -0
- package/src/Err.ts +38 -0
- package/src/Feed.ts +254 -0
- package/src/Filter.ts +389 -0
- package/src/Format.ts +9 -0
- package/src/Hypergraph.ts +74 -0
- package/src/JsonSchema.ts +24 -0
- package/src/Key.ts +3 -0
- package/src/Obj.test.ts +447 -0
- package/src/Obj.ts +588 -248
- package/src/Order.ts +44 -0
- package/src/Query.test.ts +632 -0
- package/src/Query.ts +520 -0
- package/src/QueryResult.ts +106 -0
- package/src/Ref.ts +77 -9
- package/src/Relation.test.ts +88 -0
- package/src/Relation.ts +440 -58
- package/src/SchemaRegistry.ts +106 -0
- package/src/Tag.ts +39 -0
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +162 -151
- package/src/View.ts +100 -0
- package/src/hierarchy.test.ts +33 -0
- package/src/index.ts +20 -6
- package/src/internal/README.md +102 -0
- package/src/internal/{ast → annotations}/annotations.test.ts +18 -20
- package/src/internal/annotations/annotations.ts +526 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +85 -0
- package/src/internal/api/annotations.ts +60 -0
- package/src/internal/api/entity.ts +29 -0
- package/src/internal/api/index.ts +19 -0
- package/src/internal/api/meta.ts +88 -0
- package/src/internal/api/sorting.ts +53 -0
- package/src/internal/api/version.ts +96 -0
- package/src/internal/entities/entity.ts +128 -0
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/entities/model.ts +138 -0
- package/src/internal/entities/object.ts +58 -0
- package/src/internal/entities/relation.ts +171 -0
- package/src/internal/entities/util.ts +33 -0
- package/src/internal/formats/date.test.ts +1 -1
- package/src/internal/formats/date.ts +5 -5
- package/src/internal/formats/format.test.ts +6 -6
- package/src/internal/formats/format.ts +8 -6
- package/src/internal/formats/number.ts +5 -5
- package/src/internal/formats/object.ts +4 -4
- package/src/internal/formats/select.ts +6 -4
- package/src/internal/formats/string.ts +14 -9
- package/src/internal/formats/types.ts +53 -42
- package/src/internal/index.ts +30 -13
- package/src/internal/{json → json-schema}/annotations.ts +1 -1
- package/src/internal/json-schema/index.ts +2 -0
- package/src/internal/json-schema/json-schema-normalize.ts +4 -2
- package/src/internal/json-schema/json-schema-type.ts +35 -35
- package/src/internal/{json → json-schema}/json-schema.test.ts +232 -97
- package/src/internal/{json → json-schema}/json-schema.ts +79 -93
- package/src/internal/object/clone.ts +48 -0
- package/src/internal/object/common.ts +3 -4
- package/src/internal/object/{create.test.ts → create-object.test.ts} +31 -33
- package/src/internal/object/{create.ts → create-object.ts} +36 -37
- package/src/internal/object/deleted.ts +6 -6
- package/src/internal/object/ids.ts +1 -1
- package/src/internal/object/index.ts +6 -12
- package/src/internal/object/inspect.ts +5 -7
- package/src/internal/object/json-serializer.test.ts +59 -37
- package/src/internal/object/json-serializer.ts +87 -108
- package/src/internal/object/schema-validator.test.ts +3 -7
- package/src/internal/object/schema-validator.ts +2 -237
- package/src/internal/object/set-value.test.ts +281 -0
- package/src/internal/object/set-value.ts +165 -0
- package/src/internal/object/snapshot.ts +96 -0
- package/src/internal/object/typed-object.test.ts +11 -11
- package/src/internal/object/typed-object.ts +8 -59
- package/src/internal/proxy/change-context.ts +138 -0
- package/src/internal/proxy/change.test.ts +519 -0
- package/src/internal/proxy/define-hidden-property.ts +14 -0
- package/src/internal/proxy/errors.ts +42 -0
- package/src/internal/proxy/event-batch.ts +44 -0
- package/src/internal/proxy/handler.test.ts +51 -91
- package/src/internal/proxy/index.ts +17 -0
- package/src/internal/proxy/json-serializer.ts +87 -0
- package/src/internal/proxy/make-object.ts +106 -0
- package/src/internal/proxy/ownership.ts +253 -0
- package/src/internal/proxy/proxy-types.ts +23 -0
- package/src/internal/proxy/proxy-utils.ts +150 -0
- package/src/internal/proxy/reactive-array.ts +71 -0
- package/src/internal/proxy/reactive.ts +69 -0
- package/src/internal/proxy/schema-validator.ts +244 -0
- package/src/internal/proxy/schema.test.ts +27 -18
- package/src/internal/proxy/symbols.ts +7 -0
- package/src/internal/proxy/typed-handler.test.ts +260 -48
- package/src/internal/proxy/typed-handler.ts +283 -61
- package/src/internal/proxy/typed-object.test.ts +54 -38
- package/src/internal/ref/ref-array.ts +4 -4
- package/src/internal/ref/ref.test.ts +10 -9
- package/src/internal/ref/ref.ts +107 -56
- package/src/internal/{projection → schema}/compose.test.ts +8 -9
- package/src/internal/{projection → schema}/compose.ts +13 -8
- package/src/internal/schema/echo-schema.ts +74 -33
- package/src/internal/schema/index.ts +1 -4
- package/src/internal/schema/manipulation.ts +7 -1
- package/src/internal/schema/persistent-schema.ts +33 -0
- package/src/internal/types/base.ts +43 -0
- package/src/internal/types/entity.ts +54 -0
- package/src/internal/types/index.ts +5 -2
- package/src/internal/types/meta.ts +68 -0
- package/src/internal/types/typename.ts +55 -0
- package/src/internal/types/version.ts +19 -0
- package/src/testing/api.test.ts +126 -0
- package/src/testing/index.ts +3 -3
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +240 -0
- package/src/testing/util.ts +85 -0
- package/dist/lib/browser/chunk-MWLA34S5.mjs +0 -3843
- package/dist/lib/browser/chunk-MWLA34S5.mjs.map +0 -7
- package/dist/lib/browser/chunk-OAZJQHVO.mjs +0 -453
- package/dist/lib/browser/chunk-OAZJQHVO.mjs.map +0 -7
- package/dist/lib/browser/chunk-ORIE2FMS.mjs +0 -514
- package/dist/lib/browser/chunk-ORIE2FMS.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -43
- package/dist/lib/browser/internal/index.mjs +0 -326
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/query/index.mjs +0 -23
- package/dist/lib/browser/testing/index.mjs +0 -298
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs +0 -453
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs +0 -514
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YTNLFBIK.mjs +0 -3843
- package/dist/lib/node-esm/chunk-YTNLFBIK.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -43
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/query/index.mjs +0 -23
- package/dist/lib/node-esm/testing/index.mjs +0 -298
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/errors.d.ts +0 -72
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotation-helper.d.ts +0 -8
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.d.ts +0 -119
- package/dist/types/src/internal/ast/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/ast/entity-kind.d.ts +0 -10
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +0 -1
- package/dist/types/src/internal/ast/index.d.ts +0 -5
- package/dist/types/src/internal/ast/index.d.ts.map +0 -1
- package/dist/types/src/internal/ast/types.d.ts +0 -6
- package/dist/types/src/internal/ast/types.d.ts.map +0 -1
- package/dist/types/src/internal/json/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json/index.d.ts +0 -2
- package/dist/types/src/internal/json/index.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/accessors.d.ts +0 -29
- package/dist/types/src/internal/object/accessors.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.test.d.ts +0 -2
- package/dist/types/src/internal/object/create.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/entity.d.ts +0 -22
- package/dist/types/src/internal/object/entity.d.ts.map +0 -1
- package/dist/types/src/internal/object/expando.d.ts +0 -14
- package/dist/types/src/internal/object/expando.d.ts.map +0 -1
- package/dist/types/src/internal/object/meta.d.ts.map +0 -1
- package/dist/types/src/internal/object/model.d.ts +0 -117
- package/dist/types/src/internal/object/model.d.ts.map +0 -1
- package/dist/types/src/internal/object/relation.d.ts +0 -17
- package/dist/types/src/internal/object/relation.d.ts.map +0 -1
- package/dist/types/src/internal/object/typed-relation.d.ts +0 -32
- package/dist/types/src/internal/object/typed-relation.d.ts.map +0 -1
- package/dist/types/src/internal/object/typename.d.ts +0 -15
- package/dist/types/src/internal/object/typename.d.ts.map +0 -1
- package/dist/types/src/internal/object/version.d.ts +0 -14
- package/dist/types/src/internal/object/version.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.d.ts +0 -6
- package/dist/types/src/internal/projection/compose.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/projection/index.d.ts +0 -2
- package/dist/types/src/internal/projection/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-object.d.ts +0 -15
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +0 -1
- package/dist/types/src/internal/query/index.d.ts +0 -2
- package/dist/types/src/internal/query/index.d.ts.map +0 -1
- package/dist/types/src/internal/query/query.d.ts +0 -17
- package/dist/types/src/internal/query/query.d.ts.map +0 -1
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +0 -18
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +0 -1
- package/dist/types/src/internal/schema/snapshot.d.ts +0 -6
- package/dist/types/src/internal/schema/snapshot.d.ts.map +0 -1
- package/dist/types/src/internal/schema/stored-schema.d.ts +0 -13
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +0 -1
- package/dist/types/src/internal/testing/index.d.ts +0 -3
- package/dist/types/src/internal/testing/index.d.ts.map +0 -1
- package/dist/types/src/internal/testing/types.d.ts +0 -455
- package/dist/types/src/internal/testing/types.d.ts.map +0 -1
- package/dist/types/src/internal/testing/utils.d.ts +0 -10
- package/dist/types/src/internal/testing/utils.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.d.ts +0 -79
- package/dist/types/src/internal/types/types.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.test.d.ts +0 -2
- package/dist/types/src/internal/types/types.test.d.ts.map +0 -1
- package/dist/types/src/internal/types/util.d.ts +0 -5
- package/dist/types/src/internal/types/util.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -3
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/query/query.d.ts +0 -247
- package/dist/types/src/query/query.d.ts.map +0 -1
- package/dist/types/src/query/query.test.d.ts +0 -2
- package/dist/types/src/query/query.test.d.ts.map +0 -1
- package/dist/types/src/query/tag.d.ts +0 -18
- package/dist/types/src/query/tag.d.ts.map +0 -1
- package/dist/types/src/testing/echo-schema.d.ts +0 -7
- package/dist/types/src/testing/echo-schema.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/errors.ts +0 -18
- package/src/internal/ast/annotation-helper.ts +0 -22
- package/src/internal/ast/annotations.ts +0 -212
- package/src/internal/ast/entity-kind.ts +0 -15
- package/src/internal/ast/index.ts +0 -8
- package/src/internal/ast/types.ts +0 -17
- package/src/internal/json/index.ts +0 -5
- package/src/internal/object/accessors.ts +0 -115
- package/src/internal/object/entity.ts +0 -204
- package/src/internal/object/expando.ts +0 -21
- package/src/internal/object/meta.ts +0 -62
- package/src/internal/object/model.ts +0 -170
- package/src/internal/object/relation.ts +0 -24
- package/src/internal/object/typed-relation.ts +0 -85
- package/src/internal/object/typename.ts +0 -61
- package/src/internal/object/version.ts +0 -22
- package/src/internal/projection/index.ts +0 -5
- package/src/internal/proxy/reactive-object.ts +0 -108
- package/src/internal/query/index.ts +0 -5
- package/src/internal/query/query.ts +0 -23
- package/src/internal/schema/runtime-schema-registry.ts +0 -78
- package/src/internal/schema/snapshot.ts +0 -25
- package/src/internal/schema/stored-schema.ts +0 -26
- package/src/internal/testing/index.ts +0 -6
- package/src/internal/testing/types.ts +0 -211
- package/src/internal/testing/utils.ts +0 -54
- package/src/internal/types/types.test.ts +0 -48
- package/src/internal/types/types.ts +0 -176
- package/src/internal/types/util.ts +0 -9
- package/src/query/index.ts +0 -6
- package/src/query/query.test.ts +0 -362
- package/src/query/query.ts +0 -784
- package/src/query/tag.ts +0 -35
- package/src/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -91
- /package/dist/lib/{browser/index.mjs.map → neutral/Annotation.mjs.map} +0 -0
- /package/dist/lib/{browser/internal/index.mjs.map → neutral/Database.mjs.map} +0 -0
- /package/dist/lib/{browser/query/index.mjs.map → neutral/Entity.mjs.map} +0 -0
- /package/dist/lib/{node-esm/index.mjs.map → neutral/Err.mjs.map} +0 -0
- /package/dist/lib/{node-esm/internal/index.mjs.map → neutral/Feed.mjs.map} +0 -0
- /package/dist/lib/{node-esm/query/index.mjs.map → neutral/Filter.mjs.map} +0 -0
- /package/dist/types/src/internal/{ast → annotations}/annotations.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/annotations.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/effect-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.test.d.ts +0 -0
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
- /package/src/internal/{json → json-schema}/effect-schema.test.ts +0 -0
package/src/Obj.ts
CHANGED
|
@@ -2,56 +2,141 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
5
6
|
import * as Function from 'effect/Function';
|
|
7
|
+
import * as Option from 'effect/Option';
|
|
6
8
|
import * as Schema from 'effect/Schema';
|
|
7
9
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
10
|
+
import type { ForeignKey } from '@dxos/echo-protocol';
|
|
11
|
+
import { createJsonPath } from '@dxos/effect';
|
|
12
|
+
import { assertArgument } from '@dxos/invariant';
|
|
13
|
+
import { type DXN, ObjectId } from '@dxos/keys';
|
|
14
|
+
import { assumeType } from '@dxos/util';
|
|
12
15
|
|
|
13
|
-
import
|
|
14
|
-
import * as
|
|
16
|
+
import type * as Database from './Database';
|
|
17
|
+
import * as Entity from './Entity';
|
|
18
|
+
import * as Err from './Err';
|
|
19
|
+
import * as internal from './internal';
|
|
15
20
|
import type * as Ref from './Ref';
|
|
16
|
-
import type * as
|
|
17
|
-
import * as Type from './Type';
|
|
21
|
+
import type * as Type from './Type';
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
|
-
*
|
|
24
|
+
* Base type for all ECHO objects.
|
|
21
25
|
*/
|
|
22
|
-
interface BaseObj extends
|
|
26
|
+
interface BaseObj extends internal.AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
* Object type with specific properties.
|
|
26
30
|
*/
|
|
27
|
-
export type
|
|
31
|
+
export type OfShape<Props> = BaseObj & Props;
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* Object with no known properties beyond id and kind.
|
|
35
|
+
* Use this when the object's schema/properties are not known.
|
|
36
|
+
* For objects with arbitrary properties, use `Obj.AnyProps`.
|
|
37
|
+
*
|
|
38
|
+
* NOTE: This is a TypeScript type only, not a schema.
|
|
39
|
+
* To validate that a value is an ECHO object, use `Schema.is(Type.Obj)`.
|
|
31
40
|
*/
|
|
32
|
-
export interface
|
|
41
|
+
export interface Unknown extends BaseObj {}
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Runtime Effect schema for any ECHO object.
|
|
45
|
+
* Use for validation, parsing, or as a reference target for collections.
|
|
46
|
+
*
|
|
47
|
+
* NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).
|
|
48
|
+
* Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // Structural type guard (accepts any object with id field)
|
|
53
|
+
* if (Schema.is(Type.Obj)(unknownValue)) { ... }
|
|
54
|
+
*
|
|
55
|
+
* // ECHO instance type guard (checks KindId brand)
|
|
56
|
+
* if (Obj.isObject(unknownValue)) { ... }
|
|
57
|
+
*
|
|
58
|
+
* // Reference to any object type
|
|
59
|
+
* const Collection = Schema.Struct({
|
|
60
|
+
* objects: Schema.Array(Ref.Ref(Obj.Unknown)),
|
|
61
|
+
* }).pipe(Type.object({ typename: 'Collection', version: '0.1.0' }));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
// TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.
|
|
65
|
+
// Effect Schema normalizes proxy objects to plain objects before calling filter predicates.
|
|
66
|
+
// Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.
|
|
67
|
+
export const Unknown: Type.Obj<Unknown> = Schema.Struct({
|
|
68
|
+
id: Schema.String,
|
|
69
|
+
}).pipe(
|
|
70
|
+
Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
|
|
71
|
+
// TODO(dmaretskyi): Clean this up.
|
|
72
|
+
// NOTE: The EchoObjectSchema annotation is required for Ref.Ref(Obj.Unknown) to work.
|
|
73
|
+
// The typename/version only satisfy ECHO schema machinery for reference targets.
|
|
74
|
+
internal.EchoObjectSchema({ typename: internal.ANY_OBJECT_TYPENAME, version: internal.ANY_OBJECT_VERSION }),
|
|
75
|
+
(schema) =>
|
|
76
|
+
Object.assign(schema, {
|
|
77
|
+
[internal.SchemaKindId]: (schema as any)[internal.SchemaKindId],
|
|
78
|
+
}) as unknown as Type.Obj<Unknown>,
|
|
39
79
|
);
|
|
40
80
|
|
|
41
|
-
|
|
81
|
+
/**
|
|
42
82
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Object with arbitrary properties.
|
|
85
|
+
*
|
|
86
|
+
* NOTE: Due to how TypeScript works, this type is not assignable to a specific schema type.
|
|
87
|
+
* In that case, use `Obj.instanceOf` to check if an object is of a specific type.
|
|
88
|
+
*
|
|
89
|
+
* Prefer using `Obj.Unknown` when you don't need to access arbitrary properties.
|
|
90
|
+
*/
|
|
91
|
+
export interface Any extends BaseObj, internal.AnyProperties {}
|
|
46
92
|
|
|
47
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Base type for snapshot objects (has SnapshotKindId instead of KindId).
|
|
95
|
+
*/
|
|
96
|
+
interface BaseSnapshot extends internal.AnyEntity {
|
|
97
|
+
readonly [Entity.SnapshotKindId]: typeof Entity.Kind.Object;
|
|
98
|
+
readonly id: ObjectId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Immutable snapshot of an ECHO object.
|
|
103
|
+
* Branded with SnapshotKindId (not KindId).
|
|
104
|
+
* Property values are frozen at the time the snapshot was created.
|
|
105
|
+
* Returned by getSnapshot() and hooks like useObject().
|
|
106
|
+
*
|
|
107
|
+
* Snapshots are structurally identical to reactive objects but have a different brand,
|
|
108
|
+
* making them distinguishable at the TypeScript level. Neither is assignable to the other.
|
|
109
|
+
*/
|
|
110
|
+
export type Snapshot<T extends Unknown = Unknown> = Omit<T, Entity.KindId> & BaseSnapshot;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* JSON-encoded properties for objects.
|
|
114
|
+
*/
|
|
115
|
+
export interface BaseObjJson {
|
|
116
|
+
id: string;
|
|
117
|
+
}
|
|
48
118
|
|
|
49
|
-
const
|
|
119
|
+
const defaultMeta: internal.ObjectMeta = {
|
|
50
120
|
keys: [],
|
|
51
121
|
};
|
|
52
122
|
|
|
123
|
+
type MakePropsInternal<T extends Unknown> = {
|
|
124
|
+
id?: ObjectId;
|
|
125
|
+
[Meta]?: Partial<internal.ObjectMeta>;
|
|
126
|
+
} & Entity.Properties<T>;
|
|
127
|
+
|
|
128
|
+
// TODO(burdon): Should we allow the caller to set the id?
|
|
129
|
+
/**
|
|
130
|
+
* Props type for object creation with a given schema.
|
|
131
|
+
*/
|
|
132
|
+
export type MakeProps<S extends Schema.Schema.AnyNoContext> = {
|
|
133
|
+
id?: ObjectId;
|
|
134
|
+
[Meta]?: Partial<internal.ObjectMeta>;
|
|
135
|
+
[Parent]?: Unknown;
|
|
136
|
+
} & MakePropsInternal<Schema.Schema.Type<S>>;
|
|
137
|
+
|
|
53
138
|
/**
|
|
54
|
-
* Creates new object.
|
|
139
|
+
* Creates a new echo object of the given schema.
|
|
55
140
|
* @param schema - Object schema.
|
|
56
141
|
* @param props - Object properties.
|
|
57
142
|
* @param meta - Object metadata (deprecated) -- pass with Obj.Meta.
|
|
@@ -62,39 +147,265 @@ const DEFAULT_META: EchoSchema.ObjectMeta = {
|
|
|
62
147
|
* ```ts
|
|
63
148
|
* const obj = Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' });
|
|
64
149
|
* ```
|
|
150
|
+
*
|
|
151
|
+
* Note: Only accepts object schemas, not relation schemas. Use `Relation.make` for relations.
|
|
65
152
|
*/
|
|
66
|
-
export const make = <S extends Type.
|
|
153
|
+
export const make = <S extends Type.AnyObj>(
|
|
67
154
|
schema: S,
|
|
68
|
-
props: MakeProps<S
|
|
69
|
-
|
|
70
|
-
): LiveObject.Live<Schema.Schema.Type<S>> => {
|
|
155
|
+
props: NoInfer<MakeProps<S>>,
|
|
156
|
+
): OfShape<Schema.Schema.Type<S>> => {
|
|
71
157
|
assertArgument(
|
|
72
|
-
|
|
158
|
+
internal.getTypeAnnotation(schema)?.kind === Entity.Kind.Object,
|
|
73
159
|
'schema',
|
|
74
160
|
'Expected an object schema',
|
|
75
161
|
);
|
|
76
162
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
163
|
+
let meta: internal.ObjectMeta | undefined = undefined;
|
|
164
|
+
|
|
165
|
+
// Set default fields on meta on creation.
|
|
166
|
+
if (props[internal.MetaId] != null) {
|
|
167
|
+
meta = { ...structuredClone(defaultMeta), ...props[internal.MetaId] };
|
|
168
|
+
delete props[internal.MetaId];
|
|
81
169
|
}
|
|
82
170
|
|
|
83
|
-
|
|
171
|
+
// Filter undefined values (Object.entries only returns string-keyed properties).
|
|
172
|
+
const filterUndefined: any = Object.fromEntries(Object.entries(props).filter(([_, v]) => v !== undefined));
|
|
173
|
+
|
|
174
|
+
// Copy symbol properties (like ParentId) that Object.entries doesn't include.
|
|
175
|
+
for (const sym of Object.getOwnPropertySymbols(props)) {
|
|
176
|
+
const value = (props as any)[sym];
|
|
177
|
+
if (value !== undefined) {
|
|
178
|
+
filterUndefined[sym] = value;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return internal.makeObject<Schema.Schema.Type<S>>(schema, filterUndefined as any, {
|
|
183
|
+
...defaultMeta,
|
|
184
|
+
...meta,
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Determine if object is an ECHO object.
|
|
190
|
+
*/
|
|
191
|
+
export const isObject = (obj: unknown): obj is Unknown => {
|
|
192
|
+
assumeType<internal.InternalObjectProps>(obj);
|
|
193
|
+
return typeof obj === 'object' && obj !== null && obj[Entity.KindId] === Entity.Kind.Object;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const isSnapshot = (obj: unknown): obj is Snapshot => {
|
|
197
|
+
assumeType<internal.InternalObjectProps>(obj);
|
|
198
|
+
return typeof obj === 'object' && obj !== null && (obj as any)[Entity.SnapshotKindId] === Entity.Kind.Object;
|
|
84
199
|
};
|
|
85
200
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Subscribe to object updates.
|
|
203
|
+
* The callback is called synchronously when the object is modified.
|
|
204
|
+
* Only accepts reactive objects (not snapshots).
|
|
205
|
+
* @returns Unsubscribe function.
|
|
206
|
+
*/
|
|
207
|
+
export const subscribe = (obj: Unknown, callback: () => void): (() => void) => {
|
|
208
|
+
return internal.subscribe(obj, callback);
|
|
89
209
|
};
|
|
90
210
|
|
|
211
|
+
//
|
|
212
|
+
// Snapshot
|
|
213
|
+
//
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Returns an immutable snapshot of an object.
|
|
217
|
+
* The snapshot is branded with SnapshotKindId instead of KindId,
|
|
218
|
+
* making it distinguishable from the reactive object at the type level.
|
|
219
|
+
*/
|
|
220
|
+
export const getSnapshot: <T extends Unknown>(obj: T) => Snapshot<T> = internal.getSnapshot as any;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Returns the reactive version of an object from the database, given its snapshot.
|
|
224
|
+
* Inverse of `Obj.getSnapshot`.
|
|
225
|
+
*
|
|
226
|
+
* Uses `Obj.getDatabase` internally to get the database from the snapshot,
|
|
227
|
+
* then resolves the reactive object by ID.
|
|
228
|
+
*
|
|
229
|
+
* @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
|
|
230
|
+
* @returns Effect that succeeds with the reactive object, or fails with `GetReactiveError`.
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* const snapshot = Obj.getSnapshot(obj);
|
|
234
|
+
* const reactive = Obj.getReactive(snapshot).pipe(
|
|
235
|
+
* Effect.runSync
|
|
236
|
+
* );
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export const getReactive = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<T, Err.GetReactiveError> =>
|
|
240
|
+
Effect.gen(function* () {
|
|
241
|
+
const db = internal.getDatabase(snapshot);
|
|
242
|
+
if (!db) {
|
|
243
|
+
return yield* Effect.fail(new Err.GetReactiveError({ reason: 'no-database', snapshotId: snapshot.id }));
|
|
244
|
+
}
|
|
245
|
+
const obj = db.getObjectById(snapshot.id);
|
|
246
|
+
if (!obj) {
|
|
247
|
+
return yield* Effect.fail(new Err.GetReactiveError({ reason: 'object-not-found', snapshotId: snapshot.id }));
|
|
248
|
+
}
|
|
249
|
+
return obj as T;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Like `Obj.getReactive` but returns `Option.none()` instead of failing when the object
|
|
254
|
+
* cannot be resolved (no database, object not found).
|
|
255
|
+
*
|
|
256
|
+
* @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
|
|
257
|
+
* @returns Effect that succeeds with `Option.some(reactive)` or `Option.none()`.
|
|
258
|
+
*/
|
|
259
|
+
export const getReactiveOption = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<Option.Option<T>, never> =>
|
|
260
|
+
getReactive(snapshot).pipe(
|
|
261
|
+
Effect.map(Option.some),
|
|
262
|
+
Effect.catchAll(() => Effect.succeed(Option.none())),
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Synchronous version of `Obj.getReactive`. Returns the reactive object or throws
|
|
267
|
+
* `GetReactiveError` when the object cannot be resolved (no database, object not found).
|
|
268
|
+
*
|
|
269
|
+
* @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
|
|
270
|
+
* @returns The reactive object.
|
|
271
|
+
* @throws {Err.GetReactiveError} When the object cannot be resolved.
|
|
272
|
+
*/
|
|
273
|
+
export const getReactiveOrThrow = <T extends Unknown>(snapshot: Snapshot<T>): T =>
|
|
274
|
+
Effect.runSync(getReactive(snapshot));
|
|
275
|
+
|
|
276
|
+
export type CloneOptions = {
|
|
277
|
+
/**
|
|
278
|
+
* Retain the original object's ID.
|
|
279
|
+
* @default false
|
|
280
|
+
*/
|
|
281
|
+
retainId?: boolean;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Recursively clone referenced objects.
|
|
285
|
+
* @default false
|
|
286
|
+
*/
|
|
287
|
+
deep?: boolean;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Clones an object or relation.
|
|
292
|
+
* This does not clone referenced objects, only the properties in the object.
|
|
293
|
+
* @returns A new object with the same schema and properties.
|
|
294
|
+
*/
|
|
295
|
+
export const clone: <T extends Unknown>(obj: T, opts?: CloneOptions) => T = internal.clone;
|
|
296
|
+
|
|
297
|
+
//
|
|
298
|
+
// Change
|
|
299
|
+
//
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Makes all properties mutable recursively.
|
|
303
|
+
* Used to provide a mutable view of an object within `Obj.change`.
|
|
304
|
+
*/
|
|
305
|
+
export type Mutable<T> = internal.Mutable<T>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Perform mutations on an echo object within a controlled context.
|
|
309
|
+
*
|
|
310
|
+
* All mutations within the callback are batched and trigger a single notification
|
|
311
|
+
* when the callback completes. Direct mutations outside of `Obj.change` will throw
|
|
312
|
+
* an error for echo objects.
|
|
313
|
+
*
|
|
314
|
+
* This function also works with nested objects within echo objects (e.g., Template structs)
|
|
315
|
+
* that are reactive at runtime.
|
|
316
|
+
*
|
|
317
|
+
* @param obj - The echo object to mutate. Use `Relation.change` for relations.
|
|
318
|
+
* @param callback - The callback that performs mutations on the object.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* const person = Obj.make(Person, { name: 'John', age: 25 });
|
|
323
|
+
*
|
|
324
|
+
* // Mutate within Obj.change
|
|
325
|
+
* Obj.change(person, (p) => {
|
|
326
|
+
* p.name = 'Jane';
|
|
327
|
+
* p.age = 30;
|
|
328
|
+
* });
|
|
329
|
+
* // ONE notification fires here
|
|
330
|
+
*
|
|
331
|
+
* // Direct mutation throws
|
|
332
|
+
* person.name = 'Bob'; // Error: Cannot modify outside Obj.change()
|
|
333
|
+
* ```
|
|
334
|
+
*
|
|
335
|
+
* Note: Only accepts objects. Use `Relation.change` for relations.
|
|
336
|
+
*/
|
|
337
|
+
export const change = <T extends Unknown>(obj: T, callback: internal.ChangeCallback<T>): void => {
|
|
338
|
+
internal.change(obj, callback);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Get a deeply nested property from an object.
|
|
343
|
+
*
|
|
344
|
+
* Similar to lodash.get and getDeep from @dxos/util.
|
|
345
|
+
* This is the complementary function to setValue.
|
|
346
|
+
* Accepts both reactive objects and snapshots.
|
|
347
|
+
*
|
|
348
|
+
* @param obj - The ECHO object to get the property from.
|
|
349
|
+
* @param path - Path to the property (array of keys).
|
|
350
|
+
* @returns The value at the path, or undefined if not found.
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```ts
|
|
354
|
+
* const person = Obj.make(Person, {
|
|
355
|
+
* name: 'John',
|
|
356
|
+
* addresses: [{ street: '123 Main St' }]
|
|
357
|
+
* });
|
|
358
|
+
*
|
|
359
|
+
* Obj.getValue(person, ['addresses', 0, 'street']); // '123 Main St'
|
|
360
|
+
* Obj.getValue(person, ['addresses', 1, 'street']); // undefined
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
export const getValue = (obj: Unknown | Snapshot, path: readonly (string | number)[]): any => {
|
|
364
|
+
return internal.getValue(obj, createJsonPath(path));
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Set a deeply nested property on an object, using the object's schema to determine
|
|
369
|
+
* whether to initialize nested data as an empty object or array.
|
|
370
|
+
*
|
|
371
|
+
* Similar to lodash.set and setDeep from @dxos/util, but schema-aware.
|
|
372
|
+
* Must be called within an `Obj.change` callback.
|
|
373
|
+
*
|
|
374
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
375
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
376
|
+
*
|
|
377
|
+
* @param obj - The mutable ECHO object to set the property on.
|
|
378
|
+
* @param path - Path to the property (array of keys).
|
|
379
|
+
* @param value - Value to set.
|
|
380
|
+
* @returns The value that was set.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const person = Obj.make(Person, { name: 'John' });
|
|
385
|
+
* // Person schema has: addresses: Schema.Array(Address)
|
|
386
|
+
* Obj.change(person, (p) => {
|
|
387
|
+
* Obj.setValue(p, ['addresses', 0, 'street'], '123 Main St');
|
|
388
|
+
* });
|
|
389
|
+
* // Creates: person.addresses = [{ street: '123 Main St' }]
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
// TODO(wittjosiah): Compute possible path values + type value based on generic object type.
|
|
393
|
+
export const setValue: (obj: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =
|
|
394
|
+
internal.setValue as any;
|
|
395
|
+
|
|
396
|
+
//
|
|
397
|
+
// Type
|
|
398
|
+
//
|
|
399
|
+
|
|
400
|
+
// TODO(burdon): To discuss: prefer over ObjectId or Key.ObjectId or Type.ID?
|
|
401
|
+
export const ID = ObjectId;
|
|
402
|
+
export type ID = ObjectId;
|
|
403
|
+
|
|
91
404
|
/**
|
|
92
405
|
* Test if object or relation is an instance of a schema.
|
|
93
406
|
* @example
|
|
94
407
|
* ```ts
|
|
95
408
|
* const john = Obj.make(Person, { name: 'John' });
|
|
96
|
-
* const johnIsPerson = Obj.instanceOf(Person)(john);
|
|
97
|
-
*
|
|
98
409
|
* const isPerson = Obj.instanceOf(Person);
|
|
99
410
|
* if (isPerson(john)) {
|
|
100
411
|
* // john is Person
|
|
@@ -102,284 +413,313 @@ export const isObject = (obj: unknown): obj is Any => {
|
|
|
102
413
|
* ```
|
|
103
414
|
*/
|
|
104
415
|
export const instanceOf: {
|
|
105
|
-
<S extends Type.
|
|
106
|
-
<S extends Type.
|
|
107
|
-
} = ((
|
|
108
|
-
...args: [schema: Type.Relation.Any | Type.Obj.Any, value: unknown] | [schema: Type.Relation.Any | Type.Obj.Any]
|
|
109
|
-
) => {
|
|
416
|
+
<S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
|
|
417
|
+
<S extends Type.AnyEntity>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
|
|
418
|
+
} = ((...args: [schema: Type.AnyEntity, value: unknown] | [schema: Type.AnyEntity]) => {
|
|
110
419
|
if (args.length === 1) {
|
|
111
|
-
return (
|
|
420
|
+
return (entity: unknown) => internal.isInstanceOf(args[0], entity);
|
|
112
421
|
}
|
|
113
422
|
|
|
114
|
-
return
|
|
423
|
+
return internal.isInstanceOf(args[0], args[1]);
|
|
115
424
|
}) as any;
|
|
116
425
|
|
|
117
|
-
|
|
426
|
+
/**
|
|
427
|
+
* Test if a snapshot is an instance of a schema.
|
|
428
|
+
* Mirrors `instanceOf` but only accepts values branded with SnapshotKindId.
|
|
429
|
+
* Use when the value is known to be a snapshot (e.g. from `getSnapshot` or `useObject`).
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* const snapshot = Obj.getSnapshot(person);
|
|
434
|
+
* if (Obj.snapshotOf(Person, snapshot)) {
|
|
435
|
+
* // snapshot is Obj.Snapshot<Person>
|
|
436
|
+
* }
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
export const snapshotOf: {
|
|
440
|
+
<S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Snapshot<Schema.Schema.Type<S>>;
|
|
441
|
+
<S extends Type.AnyEntity>(schema: S, value: unknown): value is Snapshot<Schema.Schema.Type<S>>;
|
|
442
|
+
} = ((...args: [schema: Type.AnyEntity, value: unknown] | [schema: Type.AnyEntity]) => {
|
|
443
|
+
const check = (entity: unknown) =>
|
|
444
|
+
entity != null &&
|
|
445
|
+
typeof entity === 'object' &&
|
|
446
|
+
Entity.SnapshotKindId in entity &&
|
|
447
|
+
internal.isInstanceOf(args[0], entity);
|
|
448
|
+
|
|
449
|
+
if (args.length === 1) {
|
|
450
|
+
return (entity: unknown) => check(entity);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return check(args[1]);
|
|
454
|
+
}) as any;
|
|
118
455
|
|
|
119
456
|
// TODO(dmaretskyi): Allow returning undefined.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
457
|
+
/**
|
|
458
|
+
* Get the DXN of the object.
|
|
459
|
+
* Accepts both reactive objects and snapshots.
|
|
460
|
+
*/
|
|
461
|
+
export const getDXN = (entity: Unknown | Snapshot): DXN => {
|
|
462
|
+
assertArgument(!Schema.isSchema(entity), 'obj', 'Object should not be a schema.');
|
|
463
|
+
return internal.getDXN(entity);
|
|
125
464
|
};
|
|
126
465
|
|
|
127
466
|
/**
|
|
128
467
|
* @returns The DXN of the object's type.
|
|
129
|
-
* @example dxn:example.com/type/
|
|
468
|
+
* @example dxn:example.com/type/Person:1.0.0
|
|
469
|
+
*/
|
|
470
|
+
// TODO(wittjosiah): Narrow types.
|
|
471
|
+
export const getTypeDXN: (obj: unknown | undefined) => DXN | undefined = internal.getTypeDXN as any;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Get the schema of the object.
|
|
475
|
+
* Returns the branded ECHO schema used to create the object.
|
|
130
476
|
*/
|
|
131
|
-
// TODO(
|
|
132
|
-
export const
|
|
477
|
+
// TODO(wittjosiah): Narrow types.
|
|
478
|
+
export const getSchema: (obj: unknown | undefined) => Type.AnyEntity | undefined = internal.getSchema as any;
|
|
133
479
|
|
|
134
480
|
/**
|
|
135
481
|
* @returns The typename of the object's type.
|
|
136
|
-
*
|
|
482
|
+
* Accepts both reactive objects and snapshots.
|
|
483
|
+
* @example `example.com/type/Person`
|
|
137
484
|
*/
|
|
138
|
-
export const getTypename = (
|
|
139
|
-
const schema = getSchema(obj);
|
|
140
|
-
if (schema == null) {
|
|
141
|
-
// Try to extract typename from DXN.
|
|
142
|
-
return EchoSchema.getType(obj)?.asTypeDXN()?.type;
|
|
143
|
-
}
|
|
485
|
+
export const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);
|
|
144
486
|
|
|
145
|
-
|
|
146
|
-
|
|
487
|
+
//
|
|
488
|
+
// Database
|
|
489
|
+
//
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Get the database the object belongs to.
|
|
493
|
+
* Accepts both reactive objects and snapshots.
|
|
494
|
+
*/
|
|
495
|
+
export const getDatabase = (entity: Entity.Unknown | Entity.Snapshot): Database.Database | undefined =>
|
|
496
|
+
internal.getDatabase(entity);
|
|
147
497
|
|
|
498
|
+
//
|
|
499
|
+
// Meta
|
|
500
|
+
//
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Property that accesses metadata for an entity.
|
|
504
|
+
*
|
|
505
|
+
* Alias for `Entity.Meta`.
|
|
506
|
+
*/
|
|
507
|
+
export const Meta = internal.MetaId;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Deeply read-only version of ObjectMeta.
|
|
511
|
+
* Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TypeScript error).
|
|
512
|
+
*/
|
|
513
|
+
export type ReadonlyMeta = internal.ReadonlyMeta;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Mutable meta type returned by `Obj.getMeta` inside an `Obj.change` callback.
|
|
517
|
+
*/
|
|
518
|
+
export type Meta = internal.Meta;
|
|
519
|
+
|
|
520
|
+
// TODO(burdon): Narrow type.
|
|
148
521
|
// TODO(dmaretskyi): Allow returning undefined.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
522
|
+
/**
|
|
523
|
+
* Get the metadata for an object.
|
|
524
|
+
* Returns mutable meta when passed a mutable object (inside `Obj.change` callback).
|
|
525
|
+
* Returns read-only meta when passed a regular object or snapshot.
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* // Read-only access outside change callback
|
|
530
|
+
* const meta = Obj.getMeta(person); // ReadonlyMeta
|
|
531
|
+
*
|
|
532
|
+
* // Mutable access inside change callback
|
|
533
|
+
* Obj.change(person, (p) => {
|
|
534
|
+
* const meta = Obj.getMeta(p); // ObjectMeta (mutable)
|
|
535
|
+
* meta.tags ??= [];
|
|
536
|
+
* meta.tags.push('important');
|
|
537
|
+
* });
|
|
538
|
+
* ```
|
|
539
|
+
*/
|
|
540
|
+
// TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.
|
|
541
|
+
export function getMeta(entity: Mutable<Unknown>): Meta;
|
|
542
|
+
export function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;
|
|
543
|
+
export function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | ReadonlyMeta {
|
|
544
|
+
return internal.getMetaChecked(entity);
|
|
545
|
+
}
|
|
154
546
|
|
|
155
547
|
/**
|
|
156
548
|
* @returns Foreign keys for the object from the specified source.
|
|
549
|
+
* Accepts both reactive objects and snapshots.
|
|
157
550
|
*/
|
|
158
551
|
export const getKeys: {
|
|
159
|
-
(
|
|
160
|
-
(source: string): (
|
|
161
|
-
} = Function.dual(2, (
|
|
162
|
-
const meta = EchoSchema.getMeta(obj);
|
|
163
|
-
invariant(meta != null, 'Invalid object.');
|
|
164
|
-
return meta.keys.filter((key) => key.source === source);
|
|
165
|
-
});
|
|
552
|
+
(entity: Unknown | Snapshot, source: string): ForeignKey[];
|
|
553
|
+
(source: string): (entity: Unknown | Snapshot) => ForeignKey[];
|
|
554
|
+
} = Function.dual(2, (entity: Unknown | Snapshot, source?: string): ForeignKey[] => internal.getKeys(entity, source!));
|
|
166
555
|
|
|
167
556
|
/**
|
|
168
557
|
* Delete all keys from the object for the specified source.
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (meta.keys[i].source === source) {
|
|
176
|
-
meta.keys.splice(i, 1);
|
|
177
|
-
i--;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
558
|
+
* Must be called within an `Obj.change` callback.
|
|
559
|
+
*
|
|
560
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
561
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
562
|
+
*/
|
|
563
|
+
export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => internal.deleteKeys(entity, source);
|
|
181
564
|
|
|
565
|
+
/**
|
|
566
|
+
* Add a tag to the object.
|
|
567
|
+
* Must be called within an `Obj.change` callback.
|
|
568
|
+
*
|
|
569
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
570
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
571
|
+
*/
|
|
572
|
+
export const addTag = (entity: Mutable<Unknown>, tag: string): void => internal.addTag(entity, tag);
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Remove a tag from the object.
|
|
576
|
+
* Must be called within an `Obj.change` callback.
|
|
577
|
+
*
|
|
578
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
579
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
580
|
+
*/
|
|
581
|
+
export const removeTag = (entity: Mutable<Unknown>, tag: string): void => internal.removeTag(entity, tag);
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Check if the object is deleted.
|
|
585
|
+
* Accepts both reactive objects and snapshots.
|
|
586
|
+
*/
|
|
182
587
|
// TODO(dmaretskyi): Default to `false`.
|
|
183
|
-
export const isDeleted = (
|
|
184
|
-
const deleted = EchoSchema.isDeleted(obj);
|
|
185
|
-
invariant(typeof deleted === 'boolean', 'Invalid object.');
|
|
186
|
-
return deleted;
|
|
187
|
-
};
|
|
588
|
+
export const isDeleted = (entity: Unknown | Snapshot): boolean => internal.isDeleted(entity);
|
|
188
589
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return EchoSchema.getLabel(schema, obj);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
590
|
+
//
|
|
591
|
+
// Annotations
|
|
592
|
+
//
|
|
195
593
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
594
|
+
/**
|
|
595
|
+
* Get the label of the object.
|
|
596
|
+
* Accepts both reactive objects and snapshots.
|
|
597
|
+
*/
|
|
598
|
+
export const getLabel = (entity: Unknown | Snapshot): string | undefined => internal.getLabel(entity);
|
|
202
599
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
600
|
+
/**
|
|
601
|
+
* Set the label of the object.
|
|
602
|
+
* Must be called within an `Obj.change` callback.
|
|
603
|
+
*
|
|
604
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
605
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
606
|
+
*/
|
|
607
|
+
export const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);
|
|
207
608
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
609
|
+
/**
|
|
610
|
+
* Get the description of the object.
|
|
611
|
+
* Accepts both reactive objects and snapshots.
|
|
612
|
+
*/
|
|
613
|
+
export const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);
|
|
211
614
|
|
|
212
|
-
|
|
213
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Set the description of the object.
|
|
617
|
+
* Must be called within an `Obj.change` callback.
|
|
618
|
+
*
|
|
619
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
620
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
621
|
+
*/
|
|
622
|
+
export const setDescription = (entity: Mutable<Unknown>, description: string): void =>
|
|
623
|
+
internal.setDescription(entity, description);
|
|
214
624
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
625
|
+
/**
|
|
626
|
+
* Symbol to set parent when creating objects with `Obj.make`.
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* Obj.make(TestSchema.Person, {
|
|
630
|
+
* [Obj.Parent]: parentObject,
|
|
631
|
+
* name: 'John',
|
|
632
|
+
* })
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
export const Parent: unique symbol = internal.ParentId as any;
|
|
227
636
|
|
|
228
|
-
|
|
229
|
-
|
|
637
|
+
/**
|
|
638
|
+
* Get the parent of an object.
|
|
639
|
+
* The parent is always loaded together with the object.
|
|
640
|
+
* Only objects are allowed to have a parent
|
|
641
|
+
* @returns The parent object, or undefined if the object has no parent.
|
|
642
|
+
*/
|
|
643
|
+
export const getParent = (entity: Unknown | Snapshot): Unknown | undefined => {
|
|
644
|
+
assertArgument(isObject(entity), 'Expected an object');
|
|
645
|
+
assumeType<internal.InternalObjectProps>(entity);
|
|
646
|
+
return entity[internal.ParentId] as Unknown | undefined;
|
|
230
647
|
};
|
|
231
648
|
|
|
649
|
+
/**
|
|
650
|
+
* Sets the parent of an object.
|
|
651
|
+
* If a parent (or any transitive parent) is deleted, the object will be deleted.
|
|
652
|
+
* Only objects are allowed to have a parent.
|
|
653
|
+
*/
|
|
654
|
+
export const setParent = (entity: Unknown, parent: Any | undefined) => {
|
|
655
|
+
assertArgument(isObject(entity), 'Expected an object');
|
|
656
|
+
assertArgument(parent === undefined || isObject(parent), 'Expected an object');
|
|
657
|
+
assumeType<internal.InternalObjectProps>(entity);
|
|
658
|
+
assumeType<internal.InternalObjectProps | undefined>(parent);
|
|
659
|
+
entity[internal.ParentId] = parent;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
//
|
|
663
|
+
// JSON
|
|
664
|
+
//
|
|
665
|
+
|
|
232
666
|
/**
|
|
233
667
|
* JSON representation of an object.
|
|
234
668
|
*/
|
|
235
|
-
export type JSON =
|
|
669
|
+
export type JSON = internal.ObjectJSON;
|
|
236
670
|
|
|
237
671
|
/**
|
|
238
672
|
* Converts object to its JSON representation.
|
|
673
|
+
* Accepts both reactive objects and snapshots.
|
|
239
674
|
*
|
|
240
675
|
* The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
|
|
241
676
|
*/
|
|
242
|
-
|
|
243
|
-
export const toJSON = (obj: Any | Relation.Any): JSON => EchoSchema.objectToJSON(obj);
|
|
677
|
+
export const toJSON = (entity: Unknown | Snapshot): JSON => internal.objectToJSON(entity);
|
|
244
678
|
|
|
245
679
|
/**
|
|
246
680
|
* Creates an object from its json representation, performing schema validation.
|
|
247
681
|
* References and schemas will be resolvable if the `refResolver` is provided.
|
|
248
682
|
*
|
|
249
|
-
* The function
|
|
683
|
+
* The function must be async to support resolving the schema as well as the relation endpoints.
|
|
250
684
|
*
|
|
251
685
|
* @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.
|
|
252
686
|
* @param options.dxn - Override object DXN. Changes the result of `Obj.getDXN`.
|
|
253
687
|
*/
|
|
254
|
-
export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<
|
|
255
|
-
|
|
688
|
+
export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<Unknown> =
|
|
689
|
+
internal.objectFromJSON as any;
|
|
256
690
|
|
|
257
691
|
/**
|
|
258
|
-
*
|
|
692
|
+
* Comparator function type for sorting objects.
|
|
693
|
+
* Accepts both reactive objects and snapshots.
|
|
259
694
|
*/
|
|
260
|
-
export
|
|
695
|
+
export type Comparator = internal.Comparator<Unknown | Snapshot>;
|
|
261
696
|
|
|
262
|
-
export
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
* @default false
|
|
266
|
-
*/
|
|
267
|
-
retainId?: boolean;
|
|
268
|
-
};
|
|
697
|
+
export const sortByLabel: Comparator = internal.sortByLabel as Comparator;
|
|
698
|
+
export const sortByTypename: Comparator = internal.sortByTypename as Comparator;
|
|
699
|
+
export const sort = (...comparators: Comparator[]): Comparator => internal.sort(...comparators) as Comparator;
|
|
269
700
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
* @returns A new object with the same schema and properties.
|
|
274
|
-
*/
|
|
275
|
-
export const clone = <T extends Any | Relation.Any>(obj: T, opts?: CloneOptions): T => {
|
|
276
|
-
const { id, ...data } = obj;
|
|
277
|
-
const schema = getSchema(obj);
|
|
278
|
-
invariant(schema != null, 'Object should have a schema');
|
|
279
|
-
const props: any = deepMapValues(data, (value, recurse) => {
|
|
280
|
-
if (EchoSchema.Ref.isRef(value)) {
|
|
281
|
-
return value;
|
|
282
|
-
}
|
|
283
|
-
return recurse(value);
|
|
284
|
-
});
|
|
285
|
-
if (opts?.retainId) {
|
|
286
|
-
props.id = id;
|
|
287
|
-
}
|
|
288
|
-
const meta = getMeta(obj);
|
|
289
|
-
props[EchoSchema.MetaId] = deepMapValues(meta, (value, recurse) => {
|
|
290
|
-
if (EchoSchema.Ref.isRef(value)) {
|
|
291
|
-
return value;
|
|
292
|
-
}
|
|
293
|
-
return recurse(value);
|
|
294
|
-
});
|
|
295
|
-
return make(schema, props);
|
|
296
|
-
};
|
|
701
|
+
//
|
|
702
|
+
// Version
|
|
703
|
+
//
|
|
297
704
|
|
|
298
|
-
export const VersionTypeId =
|
|
299
|
-
export type
|
|
705
|
+
export const VersionTypeId = internal.VersionTypeId;
|
|
706
|
+
export type VersionCompareResult = internal.VersionCompareResult;
|
|
300
707
|
|
|
301
708
|
/**
|
|
302
709
|
* Represent object version.
|
|
303
710
|
* May be backed by Automerge.
|
|
304
711
|
* Objects with no history are not versioned.
|
|
305
712
|
*/
|
|
306
|
-
export
|
|
307
|
-
[VersionTypeId]: {};
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Whether the object is versioned.
|
|
311
|
-
*/
|
|
312
|
-
versioned: boolean;
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Automerge heads.
|
|
316
|
-
*/
|
|
317
|
-
automergeHeads?: string[];
|
|
318
|
-
}
|
|
713
|
+
export type Version = internal.EntityVersion;
|
|
319
714
|
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Checks that `obj` is a version object.
|
|
327
|
-
*/
|
|
328
|
-
export const isVersion = (obj: unknown): obj is Version => {
|
|
329
|
-
return obj != null && typeof obj === 'object' && VersionTypeId in obj;
|
|
330
|
-
};
|
|
715
|
+
export const isVersion = internal.isVersion;
|
|
716
|
+
export const versionValid = internal.versionValid;
|
|
717
|
+
export const compareVersions = internal.compareVersions;
|
|
718
|
+
export const encodeVersion = internal.encodeVersion;
|
|
719
|
+
export const decodeVersion = internal.decodeVersion;
|
|
331
720
|
|
|
332
721
|
/**
|
|
333
722
|
* Returns the version of the object.
|
|
723
|
+
* Accepts both reactive objects and snapshots.
|
|
334
724
|
*/
|
|
335
|
-
export const version = (
|
|
336
|
-
const version = (obj as any)[EchoSchema.ObjectVersionId];
|
|
337
|
-
if (version === undefined) {
|
|
338
|
-
return unversioned;
|
|
339
|
-
}
|
|
340
|
-
return version;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Checks that `version` is a valid version object.
|
|
345
|
-
*/
|
|
346
|
-
export const versionValid = (version: Version): boolean => {
|
|
347
|
-
assertArgument(isVersion(version), 'version', 'Invalid version object');
|
|
348
|
-
return !!version.versioned;
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
export type VersionCompareResult = 'unversioned' | 'equal' | 'different';
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Compares two versions.
|
|
355
|
-
* @param version1
|
|
356
|
-
* @param version2
|
|
357
|
-
* @returns 'unversioned' if either object is unversioned, 'equal' if the versions are equal, 'different' if the versions are different.
|
|
358
|
-
*/
|
|
359
|
-
export const compareVersions = (version1: Version, version2: Version): VersionCompareResult => {
|
|
360
|
-
assertArgument(isVersion(version1), 'version1', 'Invalid version object');
|
|
361
|
-
assertArgument(isVersion(version2), 'version2', 'Invalid version object');
|
|
362
|
-
|
|
363
|
-
if (!versionValid(version1) || !versionValid(version2)) {
|
|
364
|
-
return 'unversioned';
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (version1.automergeHeads?.length !== version2.automergeHeads?.length) {
|
|
368
|
-
return 'different';
|
|
369
|
-
}
|
|
370
|
-
if (version1.automergeHeads?.some((head) => !version2.automergeHeads?.includes(head))) {
|
|
371
|
-
return 'different';
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return 'equal';
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
export const encodeVersion = (version: Version): string => {
|
|
378
|
-
return JSON.stringify(version);
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
export const decodeVersion = (version: string): Version => {
|
|
382
|
-
const parsed = JSON.parse(version);
|
|
383
|
-
parsed[VersionTypeId] = {};
|
|
384
|
-
return parsed;
|
|
385
|
-
};
|
|
725
|
+
export const version = (entity: Unknown | Snapshot): Version => internal.version(entity);
|