@dxos/echo 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203
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 +1 -2
- package/dist/lib/neutral/Annotation.mjs +35 -0
- package/dist/lib/neutral/Database.mjs +45 -0
- package/dist/lib/neutral/Entity.mjs +51 -0
- package/dist/lib/{browser → neutral}/Err.mjs +4 -3
- package/dist/lib/{browser → neutral}/Filter.mjs +9 -8
- 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 +40 -19
- package/dist/lib/neutral/Order.mjs +12 -0
- 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/neutral/Relation.mjs +84 -0
- package/dist/lib/neutral/SchemaRegistry.mjs +2 -0
- package/dist/lib/neutral/Tag.mjs +25 -0
- package/dist/lib/neutral/Type.mjs +47 -0
- package/dist/lib/{browser/chunk-FGFQWIZE.mjs → neutral/chunk-4L6DOFXP.mjs} +1 -3
- package/dist/lib/neutral/chunk-4L6DOFXP.mjs.map +7 -0
- package/dist/lib/{browser/chunk-RP4JV7FD.mjs → neutral/chunk-7WE7SBA2.mjs} +4 -5
- package/dist/lib/neutral/chunk-7WE7SBA2.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7YWDDFPH.mjs +251 -0
- package/dist/lib/neutral/chunk-7YWDDFPH.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-O6FOICWT.mjs → neutral/chunk-EXAYCLIM.mjs} +8 -9
- package/dist/lib/neutral/chunk-EXAYCLIM.mjs.map +7 -0
- package/dist/lib/{browser/chunk-V7TON6BX.mjs → neutral/chunk-F6BTBXL7.mjs} +28 -8
- package/dist/lib/neutral/chunk-F6BTBXL7.mjs.map +7 -0
- package/dist/lib/neutral/chunk-HQXQWXLH.mjs +269 -0
- package/dist/lib/neutral/chunk-HQXQWXLH.mjs.map +7 -0
- package/dist/lib/{browser/chunk-CGS2ULMK.mjs → neutral/chunk-J5LGTIGS.mjs} +1 -2
- package/dist/lib/{node-esm/chunk-NHYOREKX.mjs → neutral/chunk-KB7RIVLK.mjs} +11 -6
- package/dist/lib/neutral/chunk-KB7RIVLK.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/{browser/chunk-3B2G6BW4.mjs → neutral/chunk-N2QNHMT5.mjs} +3 -4
- package/dist/lib/{browser/chunk-3B2G6BW4.mjs.map → neutral/chunk-N2QNHMT5.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-JG4GH6LN.mjs → neutral/chunk-OMUPQMLR.mjs} +1 -3
- package/dist/lib/neutral/chunk-OMUPQMLR.mjs.map +7 -0
- package/dist/lib/{browser/chunk-AGOWBKY6.mjs → neutral/chunk-RCBBZLVM.mjs} +61 -13
- package/dist/lib/neutral/chunk-RCBBZLVM.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-6OTQZKHX.mjs → neutral/chunk-RIMHNJ3E.mjs} +30 -37
- package/dist/lib/neutral/chunk-RIMHNJ3E.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-BYL2NPEA.mjs → neutral/chunk-ROKO4RKJ.mjs} +9 -4
- package/dist/lib/{node-esm/chunk-BYL2NPEA.mjs.map → neutral/chunk-ROKO4RKJ.mjs.map} +3 -3
- package/dist/lib/{browser/chunk-ESLW4N7S.mjs → neutral/chunk-TMLVKIMX.mjs} +3 -4
- package/dist/lib/neutral/chunk-TMLVKIMX.mjs.map +7 -0
- package/dist/lib/{browser/chunk-P2B4BASR.mjs → neutral/chunk-UMECVTXM.mjs} +4 -5
- package/dist/lib/{node-esm/chunk-LDXRA5TC.mjs.map → neutral/chunk-UMECVTXM.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-6XVZF5VJ.mjs → neutral/chunk-VJ2H5MOJ.mjs} +1991 -1010
- package/dist/lib/neutral/chunk-VJ2H5MOJ.mjs.map +7 -0
- package/dist/lib/{browser/chunk-5IN7XBIQ.mjs → neutral/chunk-VYEWMV5U.mjs} +3 -4
- package/dist/lib/{browser/chunk-5IN7XBIQ.mjs.map → neutral/chunk-VYEWMV5U.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-MYCCGG2T.mjs → neutral/chunk-X2MPMYYN.mjs} +1 -3
- package/dist/lib/{browser/chunk-MYCCGG2T.mjs.map → neutral/chunk-X2MPMYYN.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-ZIM3Y4ZK.mjs → neutral/chunk-XAJMXQ4H.mjs} +17 -12
- package/dist/lib/neutral/chunk-XAJMXQ4H.mjs.map +7 -0
- package/dist/lib/neutral/chunk-YPIP3WGI.mjs +97 -0
- package/dist/lib/neutral/chunk-YPIP3WGI.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +27 -28
- package/dist/lib/{node-esm → neutral}/internal/index.mjs +141 -26
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +67 -61
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Annotation.d.ts +23 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +90 -53
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +111 -5
- package/dist/types/src/Entity.d.ts.map +1 -1
- 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 +55 -16
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +348 -76
- 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 +5 -0
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +21 -3
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/QueryResult.d.ts +0 -4
- package/dist/types/src/QueryResult.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +7 -7
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +236 -19
- 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 +11 -0
- package/dist/types/src/SchemaRegistry.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +6 -6
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +213 -50
- 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/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 +24 -26
- 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/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 +13 -3
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -1
- package/dist/types/src/internal/entities/index.d.ts +1 -1
- package/dist/types/src/internal/entities/index.d.ts.map +1 -1
- package/dist/types/src/internal/entities/model.d.ts +17 -8
- package/dist/types/src/internal/entities/model.d.ts.map +1 -1
- package/dist/types/src/internal/entities/object.d.ts +8 -1
- package/dist/types/src/internal/entities/object.d.ts.map +1 -1
- package/dist/types/src/internal/entities/relation.d.ts +8 -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/index.d.ts +2 -1
- package/dist/types/src/internal/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-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/clone.d.ts +8 -0
- package/dist/types/src/internal/object/clone.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.d.ts +1 -1
- package/dist/types/src/internal/object/index.d.ts +3 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts +13 -7
- 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 +7 -13
- 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 +11 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -1
- 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 +2 -4
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -1
- 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 +30 -8
- 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 +16 -3
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/index.d.ts +0 -1
- package/dist/types/src/internal/schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts +9 -7
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -1
- package/dist/types/src/internal/types/base.d.ts +5 -16
- package/dist/types/src/internal/types/base.d.ts.map +1 -1
- package/dist/types/src/internal/types/entity.d.ts +27 -2
- package/dist/types/src/internal/types/entity.d.ts.map +1 -1
- package/dist/types/src/internal/types/meta.d.ts +6 -14
- 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/src/testing/test-schema.d.ts +101 -205
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +6 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -115
- package/src/Annotation.ts +32 -4
- package/src/Database.ts +170 -125
- package/src/Entity.test.ts +22 -0
- package/src/Entity.ts +173 -7
- package/src/Err.ts +22 -2
- package/src/Obj.test.ts +442 -0
- package/src/Obj.ts +471 -254
- package/src/Order.ts +10 -0
- package/src/Query.test.ts +120 -1
- package/src/Query.ts +53 -8
- package/src/QueryResult.ts +1 -4
- package/src/Ref.ts +3 -3
- package/src/Relation.test.ts +82 -0
- package/src/Relation.ts +367 -28
- package/src/SchemaRegistry.ts +13 -0
- package/src/Tag.ts +1 -1
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +322 -88
- package/src/hierarchy.test.ts +33 -0
- package/src/internal/README.md +31 -16
- package/src/internal/annotations/annotations.test.ts +6 -6
- package/src/internal/annotations/annotations.ts +48 -49
- package/src/internal/annotations/util.ts +13 -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 +36 -19
- package/src/internal/entities/index.ts +1 -1
- package/src/internal/entities/model.ts +21 -12
- package/src/internal/entities/object.ts +21 -8
- package/src/internal/entities/relation.ts +23 -7
- 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/index.ts +2 -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.test.ts +17 -17
- package/src/internal/json-schema/json-schema.ts +14 -10
- package/src/internal/object/clone.ts +48 -0
- package/src/internal/object/create-object.ts +2 -2
- package/src/internal/object/index.ts +3 -0
- package/src/internal/object/inspect.ts +3 -3
- package/src/internal/object/json-serializer.test.ts +6 -2
- package/src/internal/object/json-serializer.ts +37 -70
- package/src/internal/object/schema-validator.test.ts +3 -7
- package/src/internal/object/schema-validator.ts +2 -240
- 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 +93 -0
- package/src/internal/object/typed-object.test.ts +11 -11
- package/src/internal/object/typed-object.ts +8 -72
- 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 +30 -80
- package/src/internal/proxy/index.ts +11 -0
- package/src/internal/proxy/json-serializer.ts +87 -0
- package/src/internal/proxy/make-object.ts +44 -51
- 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 +23 -15
- package/src/internal/proxy/symbols.ts +7 -0
- package/src/internal/proxy/typed-handler.test.ts +247 -35
- package/src/internal/proxy/typed-handler.ts +274 -57
- package/src/internal/proxy/typed-object.test.ts +37 -26
- package/src/internal/ref/ref-array.ts +4 -4
- package/src/internal/ref/ref.test.ts +1 -1
- package/src/internal/ref/ref.ts +88 -41
- package/src/internal/schema/compose.test.ts +3 -3
- package/src/internal/schema/compose.ts +13 -9
- package/src/internal/schema/echo-schema.ts +51 -12
- package/src/internal/schema/index.ts +0 -1
- package/src/internal/schema/persistent-schema.ts +5 -5
- package/src/internal/types/base.ts +6 -20
- package/src/internal/types/entity.ts +35 -4
- package/src/internal/types/meta.ts +13 -24
- package/src/internal/types/typename.ts +10 -0
- package/src/testing/api.test.ts +31 -5
- package/src/testing/test-schema.ts +44 -30
- package/src/testing/util.ts +22 -15
- package/dist/lib/browser/Annotation.mjs +0 -31
- package/dist/lib/browser/Database.mjs +0 -14
- package/dist/lib/browser/Entity.mjs +0 -20
- package/dist/lib/browser/JsonSchema.mjs +0 -18
- package/dist/lib/browser/Obj.mjs +0 -83
- package/dist/lib/browser/Order.mjs +0 -11
- package/dist/lib/browser/Query.mjs +0 -25
- package/dist/lib/browser/QueryResult.mjs +0 -3
- package/dist/lib/browser/Ref.mjs +0 -21
- package/dist/lib/browser/Relation.mjs +0 -33
- package/dist/lib/browser/SchemaRegistry.mjs +0 -3
- package/dist/lib/browser/Tag.mjs +0 -25
- package/dist/lib/browser/Type.mjs +0 -38
- package/dist/lib/browser/chunk-6XVZF5VJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-AGOWBKY6.mjs.map +0 -7
- package/dist/lib/browser/chunk-BD6MRI4M.mjs +0 -113
- package/dist/lib/browser/chunk-BD6MRI4M.mjs.map +0 -7
- package/dist/lib/browser/chunk-DOPKE2FQ.mjs +0 -32
- package/dist/lib/browser/chunk-DOPKE2FQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-ESLW4N7S.mjs.map +0 -7
- package/dist/lib/browser/chunk-F4YF6C3O.mjs +0 -363
- package/dist/lib/browser/chunk-F4YF6C3O.mjs.map +0 -7
- package/dist/lib/browser/chunk-FGFQWIZE.mjs.map +0 -7
- package/dist/lib/browser/chunk-INHXFXY5.mjs.map +0 -7
- package/dist/lib/browser/chunk-JG4GH6LN.mjs.map +0 -7
- package/dist/lib/browser/chunk-NFH3POTD.mjs +0 -37
- package/dist/lib/browser/chunk-NFH3POTD.mjs.map +0 -7
- package/dist/lib/browser/chunk-O6FOICWT.mjs.map +0 -7
- package/dist/lib/browser/chunk-P2B4BASR.mjs.map +0 -7
- package/dist/lib/browser/chunk-QHC3ZYNC.mjs +0 -152
- package/dist/lib/browser/chunk-QHC3ZYNC.mjs.map +0 -7
- package/dist/lib/browser/chunk-QU7PWSZD.mjs +0 -62
- package/dist/lib/browser/chunk-QU7PWSZD.mjs.map +0 -7
- package/dist/lib/browser/chunk-RP4JV7FD.mjs.map +0 -7
- package/dist/lib/browser/chunk-V7TON6BX.mjs.map +0 -7
- package/dist/lib/browser/chunk-WABSVOOX.mjs +0 -303
- package/dist/lib/browser/chunk-WABSVOOX.mjs.map +0 -7
- package/dist/lib/browser/chunk-XRHHSMHJ.mjs +0 -39
- package/dist/lib/browser/chunk-XRHHSMHJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZIM3Y4ZK.mjs.map +0 -7
- package/dist/lib/browser/internal/index.mjs +0 -347
- 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 -31
- package/dist/lib/node-esm/Annotation.mjs.map +0 -7
- package/dist/lib/node-esm/Database.mjs +0 -14
- package/dist/lib/node-esm/Database.mjs.map +0 -7
- package/dist/lib/node-esm/Entity.mjs +0 -20
- 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 -60
- 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 -18
- 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 -11
- package/dist/lib/node-esm/Order.mjs.map +0 -7
- package/dist/lib/node-esm/Query.mjs +0 -25
- 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 -21
- package/dist/lib/node-esm/Ref.mjs.map +0 -7
- package/dist/lib/node-esm/Relation.mjs +0 -33
- 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 -25
- package/dist/lib/node-esm/Tag.mjs.map +0 -7
- package/dist/lib/node-esm/Type.mjs +0 -38
- package/dist/lib/node-esm/Type.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5M5P2DCR.mjs +0 -32
- package/dist/lib/node-esm/chunk-5M5P2DCR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6OTQZKHX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-76LEDWHO.mjs +0 -152
- package/dist/lib/node-esm/chunk-76LEDWHO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AGHZH33D.mjs +0 -9
- package/dist/lib/node-esm/chunk-AGHZH33D.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +0 -22
- package/dist/lib/node-esm/chunk-BJACR7QG.mjs +0 -363
- package/dist/lib/node-esm/chunk-BJACR7QG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CCMFPJUT.mjs +0 -74
- package/dist/lib/node-esm/chunk-CCMFPJUT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-D5BW7KHR.mjs +0 -39
- package/dist/lib/node-esm/chunk-D5BW7KHR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DJX53IQ3.mjs +0 -2924
- package/dist/lib/node-esm/chunk-DJX53IQ3.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-FWTPV5QD.mjs +0 -94
- package/dist/lib/node-esm/chunk-FWTPV5QD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HLUDHPFO.mjs +0 -403
- package/dist/lib/node-esm/chunk-HLUDHPFO.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-JYZSF62S.mjs +0 -113
- package/dist/lib/node-esm/chunk-JYZSF62S.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KUX5JEL2.mjs +0 -57
- package/dist/lib/node-esm/chunk-KUX5JEL2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LDXRA5TC.mjs +0 -288
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +0 -15
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NHYOREKX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QVZZHCDS.mjs +0 -9
- package/dist/lib/node-esm/chunk-QVZZHCDS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-W3OLV7MG.mjs +0 -41
- package/dist/lib/node-esm/chunk-W3OLV7MG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-W5AQXKVF.mjs +0 -38
- package/dist/lib/node-esm/chunk-W5AQXKVF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YNBFXTDG.mjs +0 -24
- package/dist/lib/node-esm/chunk-YNBFXTDG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Z53QIBP2.mjs +0 -151
- package/dist/lib/node-esm/chunk-Z53QIBP2.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.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -360
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/internal/entities/expando.d.ts +0 -16
- package/dist/types/src/internal/entities/expando.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/src/internal/entities/expando.ts +0 -23
- package/src/internal/schema/snapshot.ts +0 -25
- /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,29 +1,33 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
EchoObjectSchema,
|
|
4
3
|
EchoRelationSchema,
|
|
5
4
|
EchoSchema,
|
|
6
|
-
Expando,
|
|
7
5
|
PersistentSchema,
|
|
8
6
|
Ref,
|
|
9
7
|
isMutable,
|
|
10
8
|
toEffectSchema,
|
|
11
9
|
toJsonSchema
|
|
12
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-VJ2H5MOJ.mjs";
|
|
13
11
|
import {
|
|
14
12
|
getSchemaDXN,
|
|
15
13
|
getSchemaTypename,
|
|
16
14
|
getSchemaVersion,
|
|
17
15
|
getTypeAnnotation
|
|
18
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-RIMHNJ3E.mjs";
|
|
17
|
+
import {
|
|
18
|
+
ANY_OBJECT_TYPENAME,
|
|
19
|
+
ANY_OBJECT_VERSION,
|
|
20
|
+
EntityKind,
|
|
21
|
+
SchemaKindId
|
|
22
|
+
} from "./chunk-KB7RIVLK.mjs";
|
|
19
23
|
import {
|
|
20
24
|
__export
|
|
21
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
22
26
|
|
|
23
27
|
// src/Type.ts
|
|
24
28
|
var Type_exports = {};
|
|
25
29
|
__export(Type_exports, {
|
|
26
|
-
|
|
30
|
+
Entity: () => Entity,
|
|
27
31
|
Obj: () => Obj,
|
|
28
32
|
PersistentType: () => PersistentType,
|
|
29
33
|
Ref: () => Ref2,
|
|
@@ -34,15 +38,54 @@ __export(Type_exports, {
|
|
|
34
38
|
getTypename: () => getTypename,
|
|
35
39
|
getVersion: () => getVersion,
|
|
36
40
|
isMutable: () => isMutable2,
|
|
41
|
+
isObjectSchema: () => isObjectSchema,
|
|
42
|
+
isRelationSchema: () => isRelationSchema,
|
|
43
|
+
object: () => object,
|
|
44
|
+
relation: () => relation,
|
|
37
45
|
toEffectSchema: () => toEffectSchema,
|
|
38
46
|
toJsonSchema: () => toJsonSchema
|
|
39
47
|
});
|
|
48
|
+
import * as Schema from "effect/Schema";
|
|
40
49
|
import { invariant } from "@dxos/invariant";
|
|
41
50
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Type.ts";
|
|
42
|
-
var
|
|
43
|
-
|
|
51
|
+
var ObjSchema = Schema.Struct({
|
|
52
|
+
id: Schema.String
|
|
53
|
+
}).pipe(Schema.extend(Schema.Record({
|
|
54
|
+
key: Schema.String,
|
|
55
|
+
value: Schema.Unknown
|
|
56
|
+
})), EchoObjectSchema({
|
|
57
|
+
typename: ANY_OBJECT_TYPENAME,
|
|
58
|
+
version: ANY_OBJECT_VERSION
|
|
59
|
+
}));
|
|
60
|
+
var Obj = Object.assign(ObjSchema, {
|
|
61
|
+
[SchemaKindId]: ObjSchema[SchemaKindId]
|
|
62
|
+
});
|
|
63
|
+
var object = EchoObjectSchema;
|
|
44
64
|
var PersistentType = PersistentSchema;
|
|
45
|
-
var
|
|
65
|
+
var RelationSchema = Schema.Struct({
|
|
66
|
+
id: Schema.String
|
|
67
|
+
}).pipe(Schema.extend(Schema.Record({
|
|
68
|
+
key: Schema.String,
|
|
69
|
+
value: Schema.Unknown
|
|
70
|
+
})), EchoRelationSchema({
|
|
71
|
+
typename: "dxos.org/schema/AnyRelation",
|
|
72
|
+
version: "0.0.0",
|
|
73
|
+
source: ObjSchema,
|
|
74
|
+
target: ObjSchema
|
|
75
|
+
}));
|
|
76
|
+
var Relation = Object.assign(RelationSchema, {
|
|
77
|
+
[SchemaKindId]: RelationSchema[SchemaKindId]
|
|
78
|
+
});
|
|
79
|
+
var relation = EchoRelationSchema;
|
|
80
|
+
(function(Entity2) {
|
|
81
|
+
Entity2.Any = Schema.Union(Obj, Relation);
|
|
82
|
+
})(Entity || (Entity = {}));
|
|
83
|
+
var isObjectSchema = (schema) => {
|
|
84
|
+
return schema[SchemaKindId] === EntityKind.Object;
|
|
85
|
+
};
|
|
86
|
+
var isRelationSchema = (schema) => {
|
|
87
|
+
return schema[SchemaKindId] === EntityKind.Relation;
|
|
88
|
+
};
|
|
46
89
|
var Ref2 = Ref;
|
|
47
90
|
var getDXN = (schema) => {
|
|
48
91
|
return getSchemaDXN(schema);
|
|
@@ -51,7 +94,7 @@ var getTypename = (schema) => {
|
|
|
51
94
|
const typename = getSchemaTypename(schema);
|
|
52
95
|
invariant(typeof typename === "string" && !typename.startsWith("dxn:"), "Invalid typename", {
|
|
53
96
|
F: __dxlog_file,
|
|
54
|
-
L:
|
|
97
|
+
L: 463,
|
|
55
98
|
S: void 0,
|
|
56
99
|
A: [
|
|
57
100
|
"typeof typename === 'string' && !typename.startsWith('dxn:')",
|
|
@@ -64,7 +107,7 @@ var getVersion = (schema) => {
|
|
|
64
107
|
const version = getSchemaVersion(schema);
|
|
65
108
|
invariant(typeof version === "string" && version.match(/^\d+\.\d+\.\d+$/), "Invalid version", {
|
|
66
109
|
F: __dxlog_file,
|
|
67
|
-
L:
|
|
110
|
+
L: 473,
|
|
68
111
|
S: void 0,
|
|
69
112
|
A: [
|
|
70
113
|
"typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/)",
|
|
@@ -77,18 +120,23 @@ var isMutable2 = isMutable;
|
|
|
77
120
|
var getMeta = (schema) => {
|
|
78
121
|
return getTypeAnnotation(schema);
|
|
79
122
|
};
|
|
123
|
+
var Entity;
|
|
80
124
|
|
|
81
125
|
export {
|
|
82
126
|
Obj,
|
|
83
|
-
|
|
127
|
+
object,
|
|
84
128
|
PersistentType,
|
|
85
129
|
Relation,
|
|
130
|
+
relation,
|
|
131
|
+
isObjectSchema,
|
|
132
|
+
isRelationSchema,
|
|
86
133
|
Ref2 as Ref,
|
|
87
134
|
getDXN,
|
|
88
135
|
getTypename,
|
|
89
136
|
getVersion,
|
|
90
137
|
isMutable2 as isMutable,
|
|
91
138
|
getMeta,
|
|
139
|
+
Entity,
|
|
92
140
|
Type_exports
|
|
93
141
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
142
|
+
//# sourceMappingURL=chunk-RCBBZLVM.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Type.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type EncodedReference } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { type DXN, type ObjectId } from '@dxos/keys';\nimport { type ToMutable } from '@dxos/util';\n\nimport type * as Entity$ from './Entity';\nimport {\n ANY_OBJECT_TYPENAME,\n ANY_OBJECT_VERSION,\n type ATTR_RELATION_SOURCE,\n type ATTR_RELATION_TARGET,\n type AnyEntity,\n type AnyProperties,\n EchoObjectSchema,\n EchoRelationSchema,\n type EchoRelationSchemaOptions,\n EchoSchema,\n EntityKind,\n PersistentSchema,\n Ref as Ref$,\n type RefFn,\n type RefSchema,\n SchemaKindId,\n type TypeAnnotation,\n type TypeMeta,\n getSchemaDXN,\n getSchemaTypename,\n getSchemaVersion,\n getTypeAnnotation,\n isMutable as isMutable$,\n toEffectSchema,\n toJsonSchema,\n} from './internal';\nimport type * as Relation$ from './Relation';\n\n// TODO(burdon): Remove toEffectSchema, toJsonSchema (moved to JsonSchema export).\nexport { toEffectSchema, toJsonSchema };\n\n/**\n * Returns all properties of an object or relation except for the id and kind.\n */\nexport type Properties<T = any> = Omit<T, 'id' | Entity$.KindId | Relation$.Source | Relation$.Target>;\n\n//\n// Internal types (not exported)\n//\n\n/**\n * Type that marks a schema as an ECHO schema.\n * The value indicates the entity kind (Object or Relation).\n */\ntype EchoSchemaKind<K extends EntityKind = EntityKind> = {\n readonly [SchemaKindId]: K;\n};\n\n/**\n * JSON-encoded properties for objects.\n */\ninterface ObjJsonProps {\n id: string;\n}\n\n/**\n * JSON-encoded properties for relations.\n */\ninterface RelationJsonProps {\n id: string;\n [ATTR_RELATION_SOURCE]: string;\n [ATTR_RELATION_TARGET]: string;\n}\n\n//\n// Obj - Runtime schema for any ECHO object\n//\n\n// Internal type for the Obj schema constant.\n// NOTE: The `any` in the type intersection is intentional - it makes this type bidirectionally\n// assignable with specific object types (e.g., Type.Obj can be assigned to/from Meeting.Meeting).\n// This is needed because operation schemas erase type information.\n// TODO(wittjosiah): Consider alternatives to the `any` intersection hack:\n// - Generic operation schemas that preserve input type in output\n// - Branded types that specific schemas also carry\n// - Accept the limitation and require explicit type narrowing at call sites\ntype ObjSchemaType = Schema.Schema<\n any & AnyEntity & Entity$.OfKind<typeof Entity$.Kind.Object> & AnyProperties,\n { id: string } & AnyProperties\n> &\n EchoSchemaKind<EntityKind.Object> &\n TypeMeta;\n\n// Internal schema definition.\n// NOTE: The EchoObjectSchema annotation is required for Type.Ref(Type.Obj) to work.\n// The typename/version only satisfy ECHO schema machinery for reference targets.\nconst ObjSchema = Schema.Struct({\n id: Schema.String,\n}).pipe(\n Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n EchoObjectSchema({ typename: ANY_OBJECT_TYPENAME, version: ANY_OBJECT_VERSION }),\n);\n\n/**\n * Runtime Effect schema for any ECHO object.\n * Use for validation, parsing, or as a reference target for collections.\n *\n * NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).\n * Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.\n *\n * @example\n * ```ts\n * // Structural type guard (accepts any object with id field)\n * if (Schema.is(Type.Obj)(unknownValue)) { ... }\n *\n * // ECHO instance type guard (checks KindId brand)\n * if (Obj.isObject(unknownValue)) { ... }\n *\n * // Reference to any object type\n * const Collection = Schema.Struct({\n * objects: Schema.Array(Type.Ref(Type.Obj)),\n * }).pipe(Type.object({ typename: 'Collection', version: '0.1.0' }));\n * ```\n */\n// TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.\n// Effect Schema normalizes proxy objects to plain objects before calling filter predicates.\n// Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.\nexport const Obj: ObjSchemaType = Object.assign(ObjSchema, {\n [SchemaKindId]: (ObjSchema as any)[SchemaKindId],\n}) as unknown as ObjSchemaType;\n\n/**\n * TypeScript type for an ECHO object schema.\n * `T` is the instance type produced by the schema.\n * `Fields` is the optional struct fields type for introspection.\n *\n * @example\n * ```ts\n * const PersonSchema: Type.Obj<Person> = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.object({ typename: 'Person', version: '0.1.0' }));\n *\n * // Access fields for introspection:\n * Object.keys(PersonSchema.fields); // ['name']\n * ```\n */\nexport interface Obj<T = any, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>\n extends TypeMeta,\n EchoSchemaKind<EntityKind.Object>,\n Schema.AnnotableClass<\n Obj<T, Fields>,\n Entity$.OfKind<typeof Entity$.Kind.Object> & T,\n Schema.Simplify<ObjJsonProps & ToMutable<T>>,\n never\n > {\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Structural base type for any ECHO object schema.\n * Accepts both static schemas (created with Type.object()) and EchoSchema.\n * NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.\n * Use Type.isObjectSchema() for runtime type guards.\n */\ntype ObjectSchemaBase = Schema.Schema.AnyNoContext & {\n readonly typename: string;\n readonly version: string;\n};\n\nexport namespace Obj {\n /**\n * Type that represents any ECHO object schema.\n * Accepts both static schemas (Type.object()) and mutable schemas (EchoSchema).\n */\n export type Any = ObjectSchemaBase;\n}\n\n/**\n * Factory function to create an ECHO object schema.\n * Adds object metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.object({ typename: 'example.com/type/Person', version: '0.1.0' }));\n * ```\n */\nexport const object: {\n (opts: TypeMeta): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;\n} = EchoObjectSchema as any;\n\n//\n// PersistentType (Schema stored in database)\n//\n\nexport const PersistentType: Obj<PersistentSchema> = PersistentSchema as any;\n\nexport interface PersistentType extends Schema.Schema.Type<typeof PersistentType> {}\n\nexport { EchoSchema as RuntimeType };\n\n//\n// Relation - Runtime schema for any ECHO relation\n//\n\n// Internal type for the Relation schema constant.\ntype RelationSchemaType = Schema.Schema<\n { id: ObjectId } & Record<string, unknown>,\n { id: string } & Record<string, unknown>\n> &\n EchoSchemaKind<EntityKind.Relation> &\n TypeMeta;\n\n// Internal schema definition.\n// NOTE: The EchoRelationSchema annotation is required for Type.Ref(Type.Relation) to work.\n// The typename/version/source/target only satisfy ECHO schema machinery for reference targets.\nconst RelationSchema = Schema.Struct({\n id: Schema.String,\n}).pipe(\n Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n EchoRelationSchema({\n typename: 'dxos.org/schema/AnyRelation',\n version: '0.0.0',\n source: ObjSchema,\n target: ObjSchema,\n }),\n);\n\n/**\n * Runtime Effect schema for any ECHO relation.\n * Use for validation, parsing, or as a reference target for collections.\n * A relation has `id`, source, and target fields plus any additional properties.\n *\n * NOTE: `Schema.is(Type.Relation)` does STRUCTURAL validation only (checks for `id` field).\n * Use `Relation.isRelation()` for proper ECHO instance type guards that check the KindId brand.\n *\n * @example\n * ```ts\n * // Structural type guard (accepts any object with id field)\n * if (Schema.is(Type.Relation)(unknownValue)) { ... }\n *\n * // ECHO instance type guard (checks KindId brand)\n * if (Relation.isRelation(unknownValue)) { ... }\n * ```\n */\nexport const Relation: RelationSchemaType = Object.assign(RelationSchema, {\n [SchemaKindId]: (RelationSchema as any)[SchemaKindId],\n}) as unknown as RelationSchemaType;\n\n/**\n * TypeScript type for an ECHO relation schema.\n * `T` is the instance type produced by the schema (excluding source/target).\n * `Source` and `Target` are the endpoint types.\n * `Fields` is the optional struct fields type for introspection.\n */\nexport interface Relation<\n T = any,\n Source = any,\n Target = any,\n Fields extends Schema.Struct.Fields = Schema.Struct.Fields,\n> extends TypeMeta,\n EchoSchemaKind<EntityKind.Relation>,\n Schema.AnnotableClass<\n Relation<T, Source, Target, Fields>,\n Entity$.OfKind<typeof Entity$.Kind.Relation> & Relation.Endpoints<Source, Target> & T,\n Schema.Simplify<RelationJsonProps & ToMutable<T>>,\n never\n > {\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Structural base type for any ECHO relation schema.\n * Accepts static schemas (created with Type.relation()).\n * NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.\n * Use Type.isRelationSchema() for runtime type guards.\n */\ntype RelationSchemaBase = Schema.Schema.AnyNoContext & {\n readonly typename: string;\n readonly version: string;\n};\n\nexport namespace Relation {\n /**\n * Type that represents any ECHO relation schema.\n * Accepts static schemas (Type.relation()).\n */\n export type Any = RelationSchemaBase;\n\n /**\n * Get relation source type.\n */\n export type Source<A> = A extends Relation.Endpoints<infer S, infer _T> ? S : never;\n\n /**\n * Get relation target type.\n */\n export type Target<A> = A extends Relation.Endpoints<infer _S, infer T> ? T : never;\n\n export type Endpoints<Source, Target> = {\n [Relation$.Source]: Source;\n [Relation$.Target]: Target;\n };\n}\n\n/**\n * Factory function to create an ECHO relation schema.\n * Adds relation metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const WorksFor = Schema.Struct({\n * role: Schema.String,\n * }).pipe(Type.relation({\n * typename: 'example.com/type/WorksFor',\n * version: '0.1.0',\n * source: Person,\n * target: Company,\n * }));\n * ```\n */\nexport const relation: {\n <SourceSchema extends Schema.Schema.AnyNoContext, TargetSchema extends Schema.Schema.AnyNoContext>(\n opts: EchoRelationSchemaOptions<SourceSchema, TargetSchema>,\n ): <Self extends Schema.Schema.Any>(\n self: Self,\n ) => Relation<Schema.Schema.Type<Self>, Schema.Schema.Type<SourceSchema>, Schema.Schema.Type<TargetSchema>>;\n} = EchoRelationSchema as any;\n\n//\n// Entity - Entity schema types (union of Object | Relation)\n//\n\nexport namespace Entity {\n /**\n * Runtime Effect schema for any ECHO entity (object or relation).\n * Use for validation, parsing, or type guards on unknown values.\n *\n * @example\n * ```ts\n * if (Schema.is(Type.Entity.Any)(unknownValue)) {\n * // unknownValue is an ECHO entity\n * }\n * ```\n */\n export const Any: Schema.Schema<\n { id: ObjectId } & Record<string, unknown>,\n { id: string } & Record<string, unknown>\n > = Schema.Union(Obj, Relation);\n\n /**\n * Type alias for any ECHO entity schema (object or relation).\n * Use this in type annotations for schema parameters.\n */\n export type Any = Obj.Any | Relation.Any;\n}\n\n/**\n * Type guard to check if a schema is an object schema.\n * NOTE: This checks SCHEMAS, not instances. Use Obj.isObject for instances.\n */\nexport const isObjectSchema = (schema: Entity.Any): schema is Obj.Any => {\n return (schema as any)[SchemaKindId] === EntityKind.Object;\n};\n\n/**\n * Type guard to check if a schema is a relation schema.\n * NOTE: This checks SCHEMAS, not instances. Use Relation.isRelation for instances.\n */\nexport const isRelationSchema = (schema: Entity.Any): schema is Relation.Any => {\n return (schema as any)[SchemaKindId] === EntityKind.Relation;\n};\n\n//\n// Ref\n//\n// NOTE: `Type.Ref` vs `Ref.Ref`:\n// - `Type.Ref<T>` is the SCHEMA type - a schema that produces `Ref.Ref<T>` instances.\n// - `Ref.Ref<T>` is the INSTANCE type - the actual runtime ref object.\n//\n// Example:\n// const taskRef: Ref.Ref<Task> = Ref.make(task); // Instance\n// const schema: Type.Ref<Task> = Type.Ref(Task); // Schema\n//\n\n/**\n * Return type of the `Ref` schema constructor.\n *\n * This typedef avoids `TS4023` error (name from external module cannot be used named).\n * See Effect's note on interface types.\n */\nexport interface ref<TargetSchema extends Schema.Schema.Any> extends RefSchema<Schema.Schema.Type<TargetSchema>> {}\n\n/**\n * Factory function to create a Ref schema for the given target schema.\n * Use this in schema definitions to declare reference fields.\n *\n * @example\n * ```ts\n * const Task = Schema.Struct({\n * assignee: Type.Ref(Person), // Creates a Ref schema\n * }).pipe(Type.object({ typename: 'Task', version: '0.1.0' }));\n * ```\n */\nexport const Ref: RefFn = Ref$;\n\n/**\n * TypeScript type for a Ref schema.\n * This is the type of the SCHEMA itself, not the runtime ref instance.\n * For the instance type, use `Ref.Ref<T>` from the Ref module.\n *\n * @example\n * ```ts\n * // Schema type annotation (rarely needed, usually inferred):\n * const refSchema: Type.Ref<Task> = Type.Ref(Task);\n *\n * // Instance type annotation (use Ref.Ref instead):\n * const refInstance: Ref.Ref<Task> = Ref.make(task);\n * ```\n */\nexport interface Ref<T> extends Schema.SchemaClass<Ref$<T>, EncodedReference> {}\n\nexport namespace Ref {\n /**\n * Type that represents any Ref schema (with unknown target type).\n * This is a schema type, not an instance type.\n */\n export type Any = Schema.Schema<Ref$<any>, EncodedReference>;\n}\n\n//\n// Schema utility functions\n//\n\n/**\n * Gets the full DXN of the schema.\n * Will include the version if it's a `type` DXN.\n * @example \"dxn:example.com/type/Person:0.1.0\"\n * @example \"dxn:echo:SSSSSSSSSS:XXXXXXXXXXXXX\"\n */\nexport const getDXN = (schema: Entity.Any): DXN | undefined => {\n return getSchemaDXN(schema);\n};\n\n/**\n * @param schema - Schema to get the typename from.\n * @returns The typename of the schema. Example: `example.com/type/Person`.\n */\nexport const getTypename = (schema: Entity.Any): string => {\n const typename = getSchemaTypename(schema);\n invariant(typeof typename === 'string' && !typename.startsWith('dxn:'), 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version of the schema.\n * @example 0.1.0\n */\nexport const getVersion = (schema: Entity.Any): string => {\n const version = getSchemaVersion(schema);\n invariant(typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n return version;\n};\n\n/**\n * @returns True if the schema is mutable.\n */\nexport const isMutable = isMutable$;\n\n/**\n * ECHO type metadata.\n */\nexport type Meta = TypeAnnotation;\n\n/**\n * Gets the meta data of the schema.\n */\nexport const getMeta = (schema: Entity.Any): Meta | undefined => {\n return getTypeAnnotation(schema);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;aAAAA;EAAA;;;;;;mBAAAC;EAAA;;;;;;;AAIA,YAAYC,YAAY;AAGxB,SAASC,iBAAiB;A;AA4F1B,IAAMC,YAAmBC,cAAO;EAC9BC,IAAWC;AACb,CAAA,EAAGC,KACMC,cAAcC,cAAO;EAAEC,KAAYJ;EAAQK,OAAcC;AAAQ,CAAA,CAAA,GACxEC,iBAAiB;EAAEC,UAAUC;EAAqBC,SAASC;AAAmB,CAAA,CAAA;AA2BzE,IAAMC,MAAqBC,OAAOC,OAAOjB,WAAW;EACzD,CAACkB,YAAAA,GAAgBlB,UAAkBkB,YAAAA;AACrC,CAAA;AA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invariant", "ObjSchema", "Struct", "id", "String", "pipe", "extend", "Record", "key", "value", "Unknown", "EchoObjectSchema", "typename", "ANY_OBJECT_TYPENAME", "version", "ANY_OBJECT_VERSION", "Obj", "Object", "assign", "SchemaKindId", "object", "PersistentType", "PersistentSchema", "RelationSchema", "Struct", "id", "String", "pipe", "extend", "Record", "key", "value", "Unknown", "EchoRelationSchema", "typename", "version", "source", "ObjSchema", "target", "Relation", "Object", "assign", "SchemaKindId", "relation", "Entity", "Any", "Union", "Obj", "isObjectSchema", "schema", "EntityKind", "isRelationSchema", "Ref", "Ref$", "getDXN", "getSchemaDXN", "getTypename", "getSchemaTypename", "invariant", "startsWith", "getVersion", "getSchemaVersion", "match", "isMutable", "isMutable$", "getMeta", "getTypeAnnotation"]
|
|
7
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
1
|
import {
|
|
3
2
|
EntityKind,
|
|
4
3
|
createAnnotationHelper
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KB7RIVLK.mjs";
|
|
6
5
|
|
|
7
6
|
// src/internal/types/typename.ts
|
|
8
7
|
var ATTR_TYPE = "@type";
|
|
9
8
|
var TypeId = Symbol.for("@dxos/echo/Type");
|
|
10
9
|
var SchemaId = Symbol.for("@dxos/echo/Schema");
|
|
10
|
+
var ATTR_PARENT = "@parent";
|
|
11
|
+
var ParentId = Symbol.for("@dxos/echo/Parent");
|
|
11
12
|
var getSchema = (obj) => {
|
|
12
13
|
if (obj) {
|
|
13
14
|
return obj[SchemaId];
|
|
@@ -28,7 +29,6 @@ import * as Option from "effect/Option";
|
|
|
28
29
|
import * as Schema from "effect/Schema";
|
|
29
30
|
import * as SchemaAST from "effect/SchemaAST";
|
|
30
31
|
import { raise } from "@dxos/debug";
|
|
31
|
-
import { Reference } from "@dxos/echo-protocol";
|
|
32
32
|
import { getField } from "@dxos/effect";
|
|
33
33
|
import { assertArgument, invariant } from "@dxos/invariant";
|
|
34
34
|
import { DXN } from "@dxos/keys";
|
|
@@ -49,26 +49,9 @@ var getSchemaDXN = (schema) => {
|
|
|
49
49
|
}
|
|
50
50
|
return DXN.fromTypenameAndVersion(objectAnnotation.typename, objectAnnotation.version);
|
|
51
51
|
};
|
|
52
|
-
var getTypeReference = (schema) => {
|
|
53
|
-
if (!schema) {
|
|
54
|
-
return void 0;
|
|
55
|
-
}
|
|
56
|
-
const schemaDXN = getSchemaDXN(schema);
|
|
57
|
-
if (!schemaDXN) {
|
|
58
|
-
return void 0;
|
|
59
|
-
}
|
|
60
|
-
return Reference.fromDXN(schemaDXN);
|
|
61
|
-
};
|
|
62
|
-
var requireTypeReference = (schema) => {
|
|
63
|
-
const typeReference = getTypeReference(schema);
|
|
64
|
-
if (typeReference == null) {
|
|
65
|
-
throw new Error("Schema must be defined via TypedObject.");
|
|
66
|
-
}
|
|
67
|
-
return typeReference;
|
|
68
|
-
};
|
|
69
52
|
var getTypeDXNFromSpecifier = (input) => {
|
|
70
53
|
if (Schema.isSchema(input)) {
|
|
71
|
-
return
|
|
54
|
+
return getSchemaDXN(input) ?? raise(new TypeError("Schema has no DXN"));
|
|
72
55
|
} else {
|
|
73
56
|
assertArgument(typeof input === "string", "input");
|
|
74
57
|
assertArgument(!input.startsWith("dxn:"), "input");
|
|
@@ -120,7 +103,7 @@ var getTypename = (obj) => {
|
|
|
120
103
|
var setTypename = (obj, typename) => {
|
|
121
104
|
invariant(typename instanceof DXN, "Invalid type.", {
|
|
122
105
|
F: __dxlog_file,
|
|
123
|
-
L:
|
|
106
|
+
L: 198,
|
|
124
107
|
S: void 0,
|
|
125
108
|
A: [
|
|
126
109
|
"typename instanceof DXN",
|
|
@@ -144,7 +127,7 @@ var getTypeDXN = (obj) => {
|
|
|
144
127
|
}
|
|
145
128
|
invariant(type instanceof DXN, "Invalid object.", {
|
|
146
129
|
F: __dxlog_file,
|
|
147
|
-
L:
|
|
130
|
+
L: 225,
|
|
148
131
|
S: void 0,
|
|
149
132
|
A: [
|
|
150
133
|
"type instanceof DXN",
|
|
@@ -189,13 +172,13 @@ var PropertyMeta = (name, value) => {
|
|
|
189
172
|
};
|
|
190
173
|
var getPropertyMetaAnnotation = (prop, name) => Function.pipe(SchemaAST.getAnnotation(PropertyMetaAnnotationId)(prop.type), Option.map((meta) => meta[name]), Option.getOrElse(() => void 0));
|
|
191
174
|
var ReferenceAnnotationId = Symbol.for("@dxos/schema/annotation/Reference");
|
|
192
|
-
var
|
|
175
|
+
var ReferenceAnnotation = createAnnotationHelper(ReferenceAnnotationId);
|
|
193
176
|
var SchemaMetaSymbol = Symbol.for("@dxos/schema/SchemaMeta");
|
|
194
177
|
var SystemTypeAnnotationId = Symbol.for("@dxos/schema/annotation/SystemType");
|
|
195
178
|
var SystemTypeAnnotation = createAnnotationHelper(SystemTypeAnnotationId);
|
|
196
179
|
var LabelAnnotationId = Symbol.for("@dxos/schema/annotation/Label");
|
|
197
180
|
var LabelAnnotation = createAnnotationHelper(LabelAnnotationId);
|
|
198
|
-
var
|
|
181
|
+
var getLabelWithSchema = (schema, object) => {
|
|
199
182
|
const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => [
|
|
200
183
|
"name"
|
|
201
184
|
]));
|
|
@@ -217,13 +200,13 @@ var getLabel = (schema, object) => {
|
|
|
217
200
|
}
|
|
218
201
|
return void 0;
|
|
219
202
|
};
|
|
220
|
-
var
|
|
203
|
+
var setLabelWithSchema = (schema, object, label) => {
|
|
221
204
|
const annotation = LabelAnnotation.get(schema).pipe(Option.map((field) => field[0]), Option.getOrElse(() => "name"));
|
|
222
205
|
object[annotation] = label;
|
|
223
206
|
};
|
|
224
207
|
var DescriptionAnnotationId = Symbol.for("@dxos/schema/annotation/Description");
|
|
225
208
|
var DescriptionAnnotation = createAnnotationHelper(DescriptionAnnotationId);
|
|
226
|
-
var
|
|
209
|
+
var getDescriptionWithSchema = (schema, object) => {
|
|
227
210
|
const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => "description"));
|
|
228
211
|
assertArgument(typeof accessor === "string", "accessor", "Description annotation must be a string");
|
|
229
212
|
const value = getField(object, accessor);
|
|
@@ -241,7 +224,7 @@ var getDescription = (schema, object) => {
|
|
|
241
224
|
return void 0;
|
|
242
225
|
}
|
|
243
226
|
};
|
|
244
|
-
var
|
|
227
|
+
var setDescriptionWithSchema = (schema, object, description) => {
|
|
245
228
|
const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => "description"));
|
|
246
229
|
object[accessor] = description;
|
|
247
230
|
};
|
|
@@ -250,11 +233,22 @@ var FormInputAnnotation = createAnnotationHelper(FormInputAnnotationId);
|
|
|
250
233
|
var FieldLookupAnnotationId = Symbol.for("@dxos/schema/annotation/FieldLookup");
|
|
251
234
|
var GeneratorAnnotationId = Symbol.for("@dxos/schema/annotation/Generator");
|
|
252
235
|
var GeneratorAnnotation = createAnnotationHelper(GeneratorAnnotationId);
|
|
236
|
+
var makeUserAnnotation = (props) => {
|
|
237
|
+
assertArgument(/[a-zA-Z0-9]+\.[a-zA-Z.]+\/[a-zA-Z/]+/.test(props.id), "id", "Annotation id must be in the FQN format (dxos.org/annotation/Example).");
|
|
238
|
+
const getFromAst = (ast) => SchemaAST.getAnnotation(PropertyMetaAnnotationId)(ast).pipe(Option.map((meta) => meta[props.id]), Option.map(Schema.decodeUnknownSync(props.schema)));
|
|
239
|
+
return {
|
|
240
|
+
get: (schema) => getFromAst(schema.ast),
|
|
241
|
+
getFromAst: (ast) => getFromAst(ast),
|
|
242
|
+
set: (value) => PropertyMeta(props.id, Schema.encodeSync(props.schema)(value))
|
|
243
|
+
};
|
|
244
|
+
};
|
|
253
245
|
|
|
254
246
|
export {
|
|
255
247
|
ATTR_TYPE,
|
|
256
248
|
TypeId,
|
|
257
249
|
SchemaId,
|
|
250
|
+
ATTR_PARENT,
|
|
251
|
+
ParentId,
|
|
258
252
|
getSchema,
|
|
259
253
|
setSchema,
|
|
260
254
|
FIELD_PATH_ANNOTATION,
|
|
@@ -262,8 +256,6 @@ export {
|
|
|
262
256
|
TypeIdentifierAnnotationId,
|
|
263
257
|
getTypeIdentifierAnnotation,
|
|
264
258
|
getSchemaDXN,
|
|
265
|
-
getTypeReference,
|
|
266
|
-
requireTypeReference,
|
|
267
259
|
getTypeDXNFromSpecifier,
|
|
268
260
|
TypenameSchema,
|
|
269
261
|
VersionSchema,
|
|
@@ -282,22 +274,23 @@ export {
|
|
|
282
274
|
PropertyMeta,
|
|
283
275
|
getPropertyMetaAnnotation,
|
|
284
276
|
ReferenceAnnotationId,
|
|
285
|
-
|
|
277
|
+
ReferenceAnnotation,
|
|
286
278
|
SchemaMetaSymbol,
|
|
287
279
|
SystemTypeAnnotationId,
|
|
288
280
|
SystemTypeAnnotation,
|
|
289
281
|
LabelAnnotationId,
|
|
290
282
|
LabelAnnotation,
|
|
291
|
-
|
|
292
|
-
|
|
283
|
+
getLabelWithSchema,
|
|
284
|
+
setLabelWithSchema,
|
|
293
285
|
DescriptionAnnotationId,
|
|
294
286
|
DescriptionAnnotation,
|
|
295
|
-
|
|
296
|
-
|
|
287
|
+
getDescriptionWithSchema,
|
|
288
|
+
setDescriptionWithSchema,
|
|
297
289
|
FormInputAnnotationId,
|
|
298
290
|
FormInputAnnotation,
|
|
299
291
|
FieldLookupAnnotationId,
|
|
300
292
|
GeneratorAnnotationId,
|
|
301
|
-
GeneratorAnnotation
|
|
293
|
+
GeneratorAnnotation,
|
|
294
|
+
makeUserAnnotation
|
|
302
295
|
};
|
|
303
|
-
//# sourceMappingURL=chunk-
|
|
296
|
+
//# sourceMappingURL=chunk-RIMHNJ3E.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/types/typename.ts", "../../../src/internal/annotations/annotations.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\n/**\n * Property name for typename when object is serialized to JSON.\n */\nexport const ATTR_TYPE = '@type';\n\n/**\n * DXN to the object type.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Type');\n\n/**\n * Reference to the object schema.\n */\nexport const SchemaId = Symbol.for('@dxos/echo/Schema');\n\n/**\n * Property name for parent when object is serialized to JSON.\n */\nexport const ATTR_PARENT = '@parent';\n\n/**\n * Reference to the object parent.\n */\nexport const ParentId = Symbol.for('@dxos/echo/Parent');\n\n/**\n * Returns the schema for the given object if one is defined.\n *\n * @internal (Use Obj.getSchema)\n */\n// TODO(burdon): Narrow type.\n// TODO(dmaretskyi): For echo objects, this always returns the root schema.\nexport const getSchema = (obj: unknown | undefined): Schema.Schema.AnyNoContext | undefined => {\n if (obj) {\n return (obj as any)[SchemaId];\n }\n};\n\n/**\n * @internal\n */\nexport const setSchema = (obj: any, schema: Schema.Schema.AnyNoContext): void => {\n Object.defineProperty(obj, SchemaId, {\n value: schema,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { raise } from '@dxos/debug';\nimport { type JsonPath, getField } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\nimport { type Primitive } from '@dxos/util';\n\nimport { type AnyProperties, EntityKind, TypeId, getSchema } from '../types';\n\nimport { type AnnotationHelper, createAnnotationHelper } from './util';\n\n/**\n * @internal\n */\nexport const FIELD_PATH_ANNOTATION = 'path';\n\n/**\n * Sets the path for the field.\n * @param path Data source path in the json path format. This is the field path in the source object.\n */\n// TODO(burdon): Field, vs. path vs. property.\nexport const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);\n\n//\n// Type\n//\n\n/**\n * ECHO identifier (for a stored schema).\n * Must be a `dxn:echo:` URI.\n */\nexport const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');\n\nexport const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>\n Function.flow(\n SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n\n/**\n * @returns DXN of the schema.\n *\n * For non-stored schema returns `dxn:type:`.\n * For stored schema returns `dxn:echo:`.\n */\nexport const getSchemaDXN = (schema: Schema.Schema.All): DXN | undefined => {\n assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');\n const id = getTypeIdentifierAnnotation(schema);\n if (id) {\n return DXN.parse(id);\n }\n\n // TODO(dmaretskyi): Add support for dynamic schema.\n const objectAnnotation = getTypeAnnotation(schema);\n if (!objectAnnotation) {\n return undefined;\n }\n\n return DXN.fromTypenameAndVersion(objectAnnotation.typename, objectAnnotation.version);\n};\n\n/**\n * @param input schema or a typename string.\n * @return type DXN.\n */\nexport const getTypeDXNFromSpecifier = (input: Schema.Schema.All | string): DXN => {\n if (Schema.isSchema(input)) {\n return getSchemaDXN(input) ?? raise(new TypeError('Schema has no DXN'));\n } else {\n assertArgument(typeof input === 'string', 'input');\n assertArgument(!input.startsWith('dxn:'), 'input');\n return DXN.fromTypename(input);\n }\n};\n\n//\n// TypeAnnotation\n//\n\n/**\n * Fully qualified globally unique typename.\n * Example: `dxos.org/type/Message`\n */\n// TODO(burdon): Reconcile with short DXN format.\n// TODO(burdon): Change \"/type\" => \"/schema\" throughout.\nexport const TypenameSchema = Schema.String.pipe(Schema.pattern(/^[a-zA-Z]\\w+\\.[a-zA-Z]\\w{1,}\\/[\\w/_-]+$/)).annotations(\n {\n description: 'Fully qualified globally unique typename',\n example: 'dxos.org/type/Message',\n },\n);\n\n/**\n * Semantic version format: `major.minor.patch`\n * Example: `1.0.0`\n */\nexport const VersionSchema = Schema.String.pipe(Schema.pattern(/^\\d+.\\d+.\\d+$/)).annotations({\n description: 'Semantic version format: `major.minor.patch`',\n example: '1.0.0',\n});\n\nexport const TypeMeta = Schema.Struct({\n typename: TypenameSchema,\n version: VersionSchema,\n});\n\nexport interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}\n\n/**\n * Entity type.\n */\nexport const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');\n\n/**\n * Payload stored under {@link TypeAnnotationId}.\n */\nexport const TypeAnnotation = Schema.extend(\n TypeMeta,\n Schema.Struct({\n kind: Schema.Enums(EntityKind),\n\n /**\n * If this is a relation, the schema of the source object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n sourceSchema: Schema.optional(DXN.Schema),\n\n /**\n * If this is a relation, the schema of the target object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n targetSchema: Schema.optional(DXN.Schema),\n }),\n);\n\nexport interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}\n\n/**\n * @returns {@link TypeAnnotation} from a schema.\n * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.\n */\nexport const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {\n assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');\n return Function.flow(\n SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n};\n\n/**\n * @returns {@link EntityKind} from a schema.\n */\nexport const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;\n\n/**\n * @internal\n * @returns Schema typename (without dxn: prefix or version number).\n */\nexport const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;\n\n/**\n * @internal\n * @returns Schema version in semver format.\n */\nexport const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;\n\n/**\n * Gets the typename of the object without the version.\n * Returns only the name portion, not the DXN.\n * @example \"example.org/type/Contact\"\n *\n * @internal (use Obj.getTypename)\n */\nexport const getTypename = (obj: AnyProperties): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n // Try to extract typename from DXN.\n return getSchemaTypename(schema);\n } else {\n const type = getTypeDXN(obj);\n return type?.asTypeDXN()?.type;\n }\n};\n\n/**\n * @internal (use Type.setTypename)\n */\n// TODO(dmaretskyi): Rename setTypeDXN.\nexport const setTypename = (obj: any, typename: DXN): void => {\n invariant(typename instanceof DXN, 'Invalid type.');\n Object.defineProperty(obj, TypeId, {\n value: typename,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * @returns Object type as {@link DXN}.\n * @returns undefined if the object doesn't have a type.\n * @example `dxn:example.com/type/Person:1.0.0`\n *\n * @internal (use Obj.getTypeDXN)\n */\n// TODO(burdon): Narrow type.\nexport const getTypeDXN = (obj: AnyProperties): DXN | undefined => {\n if (!obj) {\n return undefined;\n }\n\n const type = (obj as any)[TypeId];\n if (!type) {\n return undefined;\n }\n\n invariant(type instanceof DXN, 'Invalid object.');\n return type;\n};\n\n/**\n * Checks if the object is an instance of the schema.\n * Only typename is compared, the schema version is ignored.\n *\n * The following cases are considered to mean that the object is an instance of the schema:\n * - Object was created with this exact schema.\n * - Object was created with a different version of this schema.\n * - Object was created with a different schema (maybe dynamic) that has the same typename.\n */\n// TODO(burdon): Can we use `Schema.is`?\nexport const isInstanceOf = <Schema extends Schema.Schema.AnyNoContext>(\n schema: Schema,\n object: any,\n): object is Schema.Schema.Type<Schema> => {\n if (object == null) {\n return false;\n }\n\n const schemaDXN = getSchemaDXN(schema);\n if (!schemaDXN) {\n throw new Error('Schema must have an object annotation.');\n }\n\n const type = getTypeDXN(object);\n if (type && DXN.equals(type, schemaDXN)) {\n return true;\n }\n\n const typename = getTypename(object);\n if (!typename) {\n return false;\n }\n\n const typeDXN = schemaDXN.asTypeDXN();\n if (!typeDXN) {\n return false;\n }\n\n return typeDXN.type === typename;\n};\n\n//\n// PropertyMeta\n//\n\n/**\n * PropertyMeta (metadata for dynamic schema properties).\n * For user-defined annotations.\n */\nexport const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');\n\nexport type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];\n\nexport type PropertyMetaAnnotation = {\n [name: string]: PropertyMetaValue;\n};\n\n// TODO(wittjosiah): Align with other annotations.\n// TODO(wittjosiah): Why is this separate from FormatAnnotation?\nexport const PropertyMeta = (name: string, value: PropertyMetaValue) => {\n return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {\n const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;\n return self.annotations({\n [PropertyMetaAnnotationId]: {\n ...existingMeta,\n [name]: value,\n },\n });\n };\n};\n\nexport const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>\n Function.pipe(\n SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),\n Option.map((meta) => meta[name] as T),\n Option.getOrElse(() => undefined),\n );\n\n//\n// Reference\n//\n\n/**\n * Schema reference.\n */\nexport const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');\nexport type ReferenceAnnotationValue = TypeAnnotation;\nexport const ReferenceAnnotation = createAnnotationHelper<ReferenceAnnotationValue>(ReferenceAnnotationId);\n\n/**\n * SchemaMeta.\n */\nexport const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');\nexport type SchemaMeta = TypeMeta & { id: string };\n\n/**\n * Identifies a schema as a schema for a hidden system type.\n */\nexport const SystemTypeAnnotationId = Symbol.for('@dxos/schema/annotation/SystemType');\nexport const SystemTypeAnnotation = createAnnotationHelper<boolean>(SystemTypeAnnotationId);\n\n/**\n * Identifies label property or JSON path expression.\n * Either a string or an array of strings representing field accessors each matched in priority order.\n */\nexport const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');\nexport const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);\n\n/**\n * Returns the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\n// TODO(burdon): Convert to JsonPath?\nexport const getLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));\n for (const accessor of annotation) {\n assertArgument(\n typeof accessor === 'string',\n 'accessor',\n 'Label annotation must be a string or an array of strings',\n );\n const value = getField(object, accessor as JsonPath);\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n continue;\n }\n }\n\n return undefined;\n};\n\n/**\n * Sets the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n label: string,\n) => {\n const annotation = LabelAnnotation.get(schema).pipe(\n Option.map((field) => field[0]),\n Option.getOrElse(() => 'name'),\n );\n object[annotation] = label;\n};\n\n/**\n * Identifies description property or JSON path expression.\n * A string representing field accessor.\n */\nexport const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');\nexport const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);\n\n/**\n * Returns the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\n// TODO(burdon): Convert to JsonPath?\nexport const getDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');\n const value = getField(object, accessor as JsonPath);\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n default:\n return undefined;\n }\n};\n\n/**\n * Sets the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n description: string,\n) => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n object[accessor] = description;\n};\n\n/**\n * Identifies if a property should be included in a form or not.\n * By default, all properties are included in forms, so this is opt-out.\n */\n// TODO(burdon): UI concern.\nexport const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');\nexport const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);\n\n/**\n * Default field to be used on referenced schema to lookup the value.\n */\nexport const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');\n\n/**\n * Generate test data.\n */\nexport const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');\n\nexport type GeneratorAnnotationValue =\n | string\n | {\n generator: string;\n args?: any[];\n probability?: number;\n };\n\nexport const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);\n\ninterface MakeAnnoationsProps<T> {\n id: string;\n schema: Schema.Schema<T, any, never>;\n}\n\n// TODO(wittjosiah): Comment.\nexport const makeUserAnnotation = <T>(props: MakeAnnoationsProps<T>): AnnotationHelper<T> => {\n assertArgument(\n /[a-zA-Z0-9]+\\.[a-zA-Z.]+\\/[a-zA-Z/]+/.test(props.id),\n 'id',\n 'Annotation id must be in the FQN format (dxos.org/annotation/Example).',\n );\n\n const getFromAst = (ast: SchemaAST.AST) =>\n SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(\n Option.map((meta) => meta[props.id] as unknown),\n Option.map(Schema.decodeUnknownSync(props.schema)),\n );\n\n return {\n get: (schema) => getFromAst(schema.ast),\n getFromAst: (ast) => getFromAst(ast),\n set: (value) =>\n PropertyMeta(props.id, Schema.encodeSync(props.schema)(value)) as <S extends Schema.Schema.Any>(schema: S) =>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AA,CAAA;AAGpD,SAAO;IACLqF,KAAK,CAACrF,WAAWwG,WAAWxG,OAAOK,GAAG;IACtCmG,YAAY,CAACnG,QAAQmG,WAAWnG,GAAAA;IAChCqG,KAAK,CAACjD,UACJ9D,aAAa2G,MAAM7F,IAAWkG,kBAAWL,MAAMtG,MAAM,EAAEyD,KAAAA,CAAAA;EAC3D;AACF;",
|
|
6
|
+
"names": ["ATTR_TYPE", "TypeId", "Symbol", "for", "SchemaId", "ATTR_PARENT", "ParentId", "getSchema", "obj", "setSchema", "schema", "Object", "defineProperty", "value", "writable", "enumerable", "configurable", "Function", "Option", "Schema", "SchemaAST", "raise", "getField", "assertArgument", "invariant", "DXN", "FIELD_PATH_ANNOTATION", "FieldPath", "path", "PropertyMeta", "TypeIdentifierAnnotationId", "Symbol", "for", "getTypeIdentifierAnnotation", "schema", "flow", "getAnnotation", "getOrElse", "undefined", "ast", "getSchemaDXN", "assertArgument", "isSchema", "id", "DXN", "parse", "objectAnnotation", "getTypeAnnotation", "fromTypenameAndVersion", "typename", "version", "getTypeDXNFromSpecifier", "input", "raise", "TypeError", "startsWith", "fromTypename", "TypenameSchema", "String", "pipe", "pattern", "annotations", "description", "example", "VersionSchema", "TypeMeta", "Struct", "TypeAnnotationId", "TypeAnnotation", "extend", "kind", "Enums", "EntityKind", "sourceSchema", "optional", "Schema", "targetSchema", "getEntityKind", "getSchemaTypename", "getSchemaVersion", "getTypename", "obj", "getSchema", "type", "getTypeDXN", "asTypeDXN", "setTypename", "invariant", "Object", "defineProperty", "TypeId", "value", "writable", "enumerable", "configurable", "isInstanceOf", "object", "schemaDXN", "Error", "equals", "typeDXN", "PropertyMetaAnnotationId", "name", "self", "existingMeta", "getPropertyMetaAnnotation", "prop", "map", "meta", "ReferenceAnnotationId", "ReferenceAnnotation", "createAnnotationHelper", "SchemaMetaSymbol", "SystemTypeAnnotationId", "SystemTypeAnnotation", "LabelAnnotationId", "LabelAnnotation", "getLabelWithSchema", "annotation", "get", "accessor", "getField", "toString", "setLabelWithSchema", "label", "field", "DescriptionAnnotationId", "DescriptionAnnotation", "getDescriptionWithSchema", "setDescriptionWithSchema", "FormInputAnnotationId", "FormInputAnnotation", "FieldLookupAnnotationId", "GeneratorAnnotationId", "GeneratorAnnotation", "makeUserAnnotation", "props", "test", "getFromAst", "decodeUnknownSync", "set", "encodeSync"]
|
|
7
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
1
|
import {
|
|
3
2
|
__export
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
5
4
|
|
|
6
5
|
// src/Order.ts
|
|
7
6
|
var Order_exports = {};
|
|
8
7
|
__export(Order_exports, {
|
|
9
8
|
natural: () => natural,
|
|
10
|
-
property: () => property
|
|
9
|
+
property: () => property,
|
|
10
|
+
rank: () => rank
|
|
11
11
|
});
|
|
12
12
|
var OrderClass = class _OrderClass {
|
|
13
13
|
ast;
|
|
@@ -28,10 +28,15 @@ var property = (property2, direction) => new OrderClass({
|
|
|
28
28
|
property: property2,
|
|
29
29
|
direction
|
|
30
30
|
});
|
|
31
|
+
var rank = (direction = "desc") => new OrderClass({
|
|
32
|
+
kind: "rank",
|
|
33
|
+
direction
|
|
34
|
+
});
|
|
31
35
|
|
|
32
36
|
export {
|
|
33
37
|
natural,
|
|
34
38
|
property,
|
|
39
|
+
rank,
|
|
35
40
|
Order_exports
|
|
36
41
|
};
|
|
37
|
-
//# sourceMappingURL=chunk-
|
|
42
|
+
//# sourceMappingURL=chunk-ROKO4RKJ.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Order.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type QueryAST } from '@dxos/echo-protocol';\n\nexport interface Order<T> {\n // TODO(dmaretskyi): See new effect-schema approach to variance.\n '~Order': { value: T };\n\n ast: QueryAST.Order;\n}\n\nexport type Any = Order<any>;\n\nclass OrderClass implements Order<any> {\n private static variance: Order<any>['~Order'] = {} as Order<any>['~Order'];\n\n static is(value: unknown): value is Order<any> {\n return typeof value === 'object' && value !== null && '~Order' in value;\n }\n\n constructor(public readonly ast: QueryAST.Order) {}\n\n '~Order' = OrderClass.variance;\n}\n\nexport const natural: Order<any> = new OrderClass({ kind: 'natural' });\nexport const property = <T>(property: keyof T & string, direction: QueryAST.OrderDirection): Order<T> =>\n new OrderClass({\n kind: 'property',\n property,\n direction,\n });\n"],
|
|
5
|
-
"mappings": ";;;;;;
|
|
6
|
-
"names": ["OrderClass", "variance", "is", "value", "ast", "natural", "kind", "property", "direction"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { type QueryAST } from '@dxos/echo-protocol';\n\nexport interface Order<T> {\n // TODO(dmaretskyi): See new effect-schema approach to variance.\n '~Order': { value: T };\n\n ast: QueryAST.Order;\n}\n\nexport type Any = Order<any>;\n\nclass OrderClass implements Order<any> {\n private static variance: Order<any>['~Order'] = {} as Order<any>['~Order'];\n\n static is(value: unknown): value is Order<any> {\n return typeof value === 'object' && value !== null && '~Order' in value;\n }\n\n constructor(public readonly ast: QueryAST.Order) {}\n\n '~Order' = OrderClass.variance;\n}\n\nexport const natural: Order<any> = new OrderClass({ kind: 'natural' });\nexport const property = <T>(property: keyof T & string, direction: QueryAST.OrderDirection): Order<T> =>\n new OrderClass({\n kind: 'property',\n property,\n direction,\n });\n\n/**\n * Order by relevance rank (for FTS/vector search results).\n * Higher rank = better match. Default direction is 'desc' (best matches first).\n */\nexport const rank = <T>(direction: QueryAST.OrderDirection = 'desc'): Order<T> =>\n new OrderClass({\n kind: 'rank',\n direction,\n });\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;AAeA,IAAMA,aAAN,MAAMA,YAAAA;;EACJ,OAAeC,WAAiC,CAAC;EAEjD,OAAOC,GAAGC,OAAqC;AAC7C,WAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,YAAYA;EACpE;EAEA,YAA4BC,KAAqB;SAArBA,MAAAA;EAAsB;EAElD,WAAWJ,YAAWC;AACxB;AAEO,IAAMI,UAAsB,IAAIL,WAAW;EAAEM,MAAM;AAAU,CAAA;AAC7D,IAAMC,WAAW,CAAIA,WAA4BC,cACtD,IAAIR,WAAW;EACbM,MAAM;EACNC,UAAAA;EACAC;AACF,CAAA;AAMK,IAAMC,OAAO,CAAID,YAAqC,WAC3D,IAAIR,WAAW;EACbM,MAAM;EACNE;AACF,CAAA;",
|
|
6
|
+
"names": ["OrderClass", "variance", "is", "value", "ast", "natural", "kind", "property", "direction", "rank"]
|
|
7
7
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
Ref,
|
|
4
3
|
RefArray,
|
|
5
4
|
getSchemaReference
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-VJ2H5MOJ.mjs";
|
|
7
6
|
import {
|
|
8
7
|
__export
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
10
9
|
|
|
11
10
|
// src/Ref.ts
|
|
12
11
|
var Ref_exports = {};
|
|
@@ -38,4 +37,4 @@ export {
|
|
|
38
37
|
isRefType,
|
|
39
38
|
Ref_exports
|
|
40
39
|
};
|
|
41
|
-
//# sourceMappingURL=chunk-
|
|
40
|
+
//# sourceMappingURL=chunk-TMLVKIMX.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Ref.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Option from 'effect/Option';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { Ref as Ref$, RefArray, type RefResolver } from './internal';\nimport { getSchemaReference } from './internal';\nimport type * as JsonSchema from './JsonSchema';\nimport type * as Obj from './Obj';\n\nexport type Ref<T> = Ref$<T>;\nexport type Unknown = Ref$<Obj.Unknown>;\n\nexport const Array = RefArray;\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Unknown> = R extends Ref$<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = RefResolver;\n\nexport const isRef: (value: unknown) => value is Unknown = Ref$.isRef;\n\nexport const make = Ref$.make;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = Ref$.fromDXN;\n\n// TODO(wittjosiah): Factor out?\nexport const isRefType = (ast: SchemaAST.AST): boolean => {\n return SchemaAST.getAnnotation<JsonSchema.JsonSchema>(ast, SchemaAST.JSONSchemaAnnotationId).pipe(\n Option.flatMap((jsonSchema) => ('$id' in jsonSchema ? Option.some(jsonSchema) : Option.none())),\n Option.flatMap((jsonSchema) => {\n const { typename } = getSchemaReference(jsonSchema) ?? {};\n return typename ? Option.some(true) : Option.some(false);\n }),\n Option.getOrElse(() => false),\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAAA;;;;;;;;AAIA,YAAYA,YAAY;AACxB,YAAYC,eAAe;AAUpB,IAAMC,QAAQC;AAYd,IAAMC,QAA8CC,IAAKD;AAEzD,IAAME,OAAOD,IAAKC;AAGlB,IAAMC,UAAUF,IAAKE;AAGrB,IAAMC,YAAY,CAACC,QAAAA;AACxB,SAAiBC,wBAAqCD,KAAeE,gCAAsB,EAAEC,KACpFC,eAAQ,CAACC,eAAgB,SAASA,aAAoBC,YAAKD,UAAAA,IAAqBE,YAAI,CAAA,GACpFH,eAAQ,CAACC,eAAAA;AACd,UAAM,EAAEG,SAAQ,IAAKC,mBAAmBJ,UAAAA,KAAe,CAAC;AACxD,WAAOG,WAAkBF,YAAK,IAAA,IAAeA,YAAK,KAAA;EACpD,CAAA,GACOI,iBAAU,MAAM,KAAA,CAAA;AAE3B;",
|
|
6
|
+
"names": ["Option", "SchemaAST", "Array", "RefArray", "isRef", "Ref$", "make", "fromDXN", "isRefType", "ast", "getAnnotation", "JSONSchemaAnnotationId", "pipe", "flatMap", "jsonSchema", "some", "none", "typename", "getSchemaReference", "getOrElse"]
|
|
7
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
1
|
import {
|
|
3
2
|
isRef
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TMLVKIMX.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-UMECVTXM.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Filter.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { type ForeignKey, type QueryAST } from '@dxos/echo-protocol';\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN, ObjectId } from '@dxos/keys';\n\nimport { getTypeDXNFromSpecifier } from './internal';\nimport * as Ref from './Ref';\n\nexport interface Filter<T> {\n // TODO(dmaretskyi): See new effect-schema approach to variance.\n '~Filter': { value: Types.Contravariant<T> };\n\n ast: QueryAST.Filter;\n}\n\nexport type Props<T> = {\n // Predicate or a value as a shorthand for `eq`.\n [K in keyof T & string]?: Filter<T[K]> | T[K];\n};\n\nexport type Any = Filter<any>;\n\nexport type Type<F extends Any> = F extends Filter<infer T> ? T : never;\n\nclass FilterClass implements Any {\n private static variance: Any['~Filter'] = {} as Any['~Filter'];\n\n constructor(public readonly ast: QueryAST.Filter) {}\n\n '~Filter' = FilterClass.variance;\n}\n\nexport const is = (value: unknown): value is Any => {\n return typeof value === 'object' && value !== null && '~Filter' in value;\n};\n\n/** Construct a filter from an ast. */\nexport const fromAst = (ast: QueryAST.Filter): Any => {\n return new FilterClass(ast);\n};\n\n/**\n * Filter that matches all objects.\n */\n// TODO(dmaretskyi): `Entity.Any` would be more type-safe, but causes annoying errors in existing code\nexport const everything = (): FilterClass => {\n return new FilterClass({\n type: 'object',\n typename: null,\n props: {},\n });\n};\n\n/**\n * Filter that matches no objects.\n */\nexport const nothing = (): FilterClass => {\n return new FilterClass({\n type: 'not',\n filter: {\n type: 'object',\n typename: null,\n props: {},\n },\n });\n};\n\n/*\n * Filter by ObjectId.\n */\nexport const id = (...ids: ObjectId[]): Any => {\n assertArgument(\n ids.every((id) => ObjectId.isValid(id)),\n 'ids',\n 'ids must be valid',\n );\n\n if (ids.length === 0) {\n return nothing();\n }\n\n return new FilterClass({\n type: 'object',\n typename: null,\n id: ids,\n props: {},\n });\n};\n\n/**\n * Filter by type.\n */\nexport const type = <S extends Schema.Schema.All>(\n schema: S | string,\n props?: Props<Schema.Schema.Type<S>>,\n): Filter<Schema.Schema.Type<S>> => {\n const dxn = getTypeDXNFromSpecifier(schema);\n return new FilterClass({\n type: 'object',\n typename: dxn.toString(),\n ...propsFilterToAst(props ?? {}),\n });\n};\n\n/**\n * Filter by non-qualified typename.\n */\nexport const typename = (typename: string): Any => {\n assertArgument(!typename.startsWith('dxn:'), 'typename', 'Typename must no be qualified');\n return new FilterClass({\n type: 'object',\n typename: DXN.fromTypename(typename).toString(),\n props: {},\n });\n};\n\n/**\n * Filter by fully qualified type DXN.\n */\nexport const typeDXN = (dxn: DXN): Any => {\n return new FilterClass({\n type: 'object',\n typename: dxn.toString(),\n props: {},\n });\n};\n\n/**\n * Filter by tag.\n */\nexport const tag = (tag: string): Any => {\n return new FilterClass({\n type: 'tag',\n tag,\n });\n};\n\n/**\n * Filter by properties.\n */\nexport const props = <T>(props: Props<T>): Filter<T> => {\n return new FilterClass({\n type: 'object',\n typename: null,\n ...propsFilterToAst(props),\n });\n};\n\nexport type TextSearchOptions = {\n // TODO(dmaretskyi): Hybrid search.\n type?: 'full-text' | 'vector';\n};\n\n/**\n * Full-text or vector search.\n */\nexport const text = (\n // TODO(dmaretskyi): Consider passing a vector here, but really the embedding should be done on the query-executor side.\n text: string,\n options?: TextSearchOptions,\n): Any => {\n return new FilterClass({\n type: 'text-search',\n text,\n searchKind: options?.type,\n });\n};\n\n/**\n * Filter by foreign keys.\n */\nexport const foreignKeys = <S extends Schema.Schema.All>(\n schema: S | string,\n keys: ForeignKey[],\n): Filter<Schema.Schema.Type<S>> => {\n const dxn = getTypeDXNFromSpecifier(schema);\n return new FilterClass({\n type: 'object',\n typename: dxn.toString(),\n props: {},\n foreignKeys: keys,\n });\n};\n\n/**\n * Predicate for property to be equal to the provided value.\n */\nexport const eq = <T>(value: T): Filter<T | undefined> => {\n if (!Ref.isRef(value) && typeof value === 'object' && value !== null) {\n throw new TypeError('Cannot use object as a value for eq filter');\n }\n\n return new FilterClass({\n type: 'compare',\n operator: 'eq',\n value: Ref.isRef(value) ? value.noInline().encode() : value,\n });\n};\n\n/**\n * Predicate for property to be not equal to the provided value.\n */\nexport const neq = <T>(value: T): Filter<T | undefined> => {\n return new FilterClass({\n type: 'compare',\n operator: 'neq',\n value,\n });\n};\n\n/**\n * Predicate for property to be greater than the provided value.\n */\nexport const gt = <T>(value: T): Filter<T | undefined> => {\n return new FilterClass({\n type: 'compare',\n operator: 'gt',\n value,\n });\n};\n\n/**\n * Predicate for property to be greater than or equal to the provided value.\n */\nexport const gte = <T>(value: T): Filter<T | undefined> => {\n return new FilterClass({\n type: 'compare',\n operator: 'gte',\n value,\n });\n};\n\n/**\n * Predicate for property to be less than the provided value.\n */\nexport const lt = <T>(value: T): Filter<T | undefined> => {\n return new FilterClass({\n type: 'compare',\n operator: 'lt',\n value,\n });\n};\n\n/**\n * Predicate for property to be less than or equal to the provided value.\n */\nexport const lte = <T>(value: T): Filter<T | undefined> => {\n return new FilterClass({\n type: 'compare',\n operator: 'lte',\n value,\n });\n};\n\n/**\n * Predicate for property to be in the provided array.\n * @param values - Values to check against.\n */\nconst in$ = <T>(...values: T[]): Filter<T | undefined> => {\n return new FilterClass({\n type: 'in',\n values,\n });\n};\nexport { in$ as in };\n\n/**\n * Predicate for an array property to contain the provided value.\n * @param value - Value to check against.\n */\nexport const contains = <T>(value: T): Filter<readonly T[] | undefined> => {\n return new FilterClass({\n type: 'contains',\n value,\n });\n};\n\n/**\n * Predicate for property to be in the provided range.\n * @param from - Start of the range (inclusive).\n * @param to - End of the range (exclusive).\n */\nexport const between = <T>(from: T, to: T): Filter<unknown> => {\n return new FilterClass({\n type: 'range',\n from,\n to,\n });\n};\n\n/**\n * Negate the filter.\n */\nexport const not = <F extends Any>(filter: F): Filter<Type<F>> => {\n return new FilterClass({\n type: 'not',\n filter: filter.ast,\n });\n};\n\n/**\n * Combine filters with a logical AND.\n */\nexport const and = <Filters extends readonly Any[]>(...filters: Filters): Filter<Type<Filters[number]>> => {\n return new FilterClass({\n type: 'and',\n filters: filters.map((f) => f.ast),\n });\n};\n\n/**\n * Combine filters with a logical OR.\n */\nexport const or = <Filters extends readonly Any[]>(...filters: Filters): Filter<Type<Filters[number]>> => {\n return new FilterClass({\n type: 'or',\n filters: filters.map((f) => f.ast),\n });\n};\n\n// TODO(dmaretskyi): Add `Filter.match` to support pattern matching on string props.\n\nconst propsFilterToAst = (predicates: Props<any>): Pick<QueryAST.FilterObject, 'id' | 'props'> => {\n let idFilter: readonly ObjectId[] | undefined;\n if ('id' in predicates) {\n assertArgument(\n typeof predicates.id === 'string' || Array.isArray(predicates.id),\n 'predicates.id',\n 'invalid id filter',\n );\n idFilter = typeof predicates.id === 'string' ? [predicates.id] : predicates.id;\n Schema.Array(ObjectId).pipe(Schema.validateSync)(idFilter);\n }\n\n return {\n id: idFilter,\n props: Object.fromEntries(\n Object.entries(predicates)\n .filter(([prop, _value]) => prop !== 'id')\n .map(([prop, predicate]) => [prop, processPredicate(predicate)]),\n ) as Record<string, QueryAST.Filter>,\n };\n};\n\nconst processPredicate = (predicate: any): QueryAST.Filter => {\n return Match.value(predicate).pipe(\n Match.withReturnType<QueryAST.Filter>(),\n Match.when(is, (predicate) => predicate.ast),\n // TODO(wittjosiah): Add support for array predicates.\n Match.when(Array.isArray, (_predicate) => {\n throw new Error('Array predicates are not yet supported.');\n }),\n Match.when(\n (predicate: any) => !Ref.isRef(predicate) && typeof predicate === 'object' && predicate !== null,\n (predicate) => {\n const nestedProps = Object.fromEntries(\n Object.entries(predicate).map(([key, value]) => [key, processPredicate(value)]),\n );\n\n return {\n type: 'object',\n typename: null,\n props: nestedProps,\n };\n },\n ),\n Match.orElse((value) => eq(value).ast),\n );\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,YAAY;AAIxB,SAASC,sBAAsB;AAC/B,SAASC,KAAKC,gBAAgB;AAqB9B,IAAMC,cAAN,MAAMA,aAAAA;;EACJ,OAAeC,WAA2B,CAAC;EAE3C,YAA4BC,KAAsB;SAAtBA,MAAAA;EAAuB;EAEnD,YAAYF,aAAYC;AAC1B;AAEO,IAAME,KAAK,CAACC,WAAAA;AACjB,SAAO,OAAOA,WAAU,YAAYA,WAAU,QAAQ,aAAaA;AACrE;AAGO,IAAMC,UAAU,CAACH,QAAAA;AACtB,SAAO,IAAIF,YAAYE,GAAAA;AACzB;AAMO,IAAMI,aAAa,MAAA;AACxB,SAAO,IAAIN,Y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AA;KAAW,CAAA;EAErE;AACF;AAEA,IAAMC,mBAAmB,CAACD,cAAAA;AACxB,SAAa/B,YAAM+B,SAAAA,EAAWR;IACtBU,qBAAc;IACdC,WAAKC,IAAI,CAACJ,eAAcA,WAAUvB,GAAG;;IAErC0B,WAAKf,MAAMC,SAAS,CAACgB,eAAAA;AACzB,YAAM,IAAIC,MAAM,yCAAA;IAClB,CAAA;IACMH,WACJ,CAACH,eAAmB,CAAKO,MAAMP,UAAAA,KAAc,OAAOA,eAAc,YAAYA,eAAc,MAC5F,CAACA,eAAAA;AACC,YAAMQ,cAAcb,OAAOC,YACzBD,OAAOE,QAAQG,UAAAA,EAAWpB,IAAI,CAAC,CAAC6B,KAAKxC,MAAAA,MAAW;QAACwC;QAAKR,iBAAiBhC,MAAAA;OAAO,CAAA;AAGhF,aAAO;QACLE,MAAM;QACNuC,UAAU;QACVhB,OAAOc;MACT;IACF,CAAA;IAEIG,aAAO,CAAC1C,WAAU2C,GAAG3C,MAAAA,EAAOQ,GAAG;EAAA;AAEzC;",
|
|
6
6
|
"names": ["Match", "Schema", "assertArgument", "DXN", "ObjectId", "FilterClass", "variance", "ast", "is", "value", "fromAst", "everything", "type", "typename", "props", "nothing", "filter", "id", "ids", "assertArgument", "every", "ObjectId", "isValid", "length", "schema", "dxn", "getTypeDXNFromSpecifier", "toString", "propsFilterToAst", "startsWith", "DXN", "fromTypename", "typeDXN", "tag", "text", "options", "searchKind", "foreignKeys", "keys", "eq", "isRef", "TypeError", "operator", "noInline", "encode", "neq", "gt", "gte", "lt", "lte", "in$", "values", "contains", "value", "FilterClass", "type", "between", "from", "to", "not", "filter", "ast", "and", "filters", "map", "f", "or", "propsFilterToAst", "predicates", "idFilter", "assertArgument", "id", "Array", "isArray", "Schema", "ObjectId", "pipe", "validateSync", "props", "Object", "fromEntries", "entries", "prop", "_value", "predicate", "processPredicate", "withReturnType", "when", "is", "_predicate", "Error", "isRef", "nestedProps", "key", "typename", "orElse", "eq"]
|
|
7
7
|
}
|