@dxos/echo 0.8.4-main.8360d9e660 → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/README.md +3 -3
- package/dist/lib/neutral/Annotation.mjs +5 -3
- package/dist/lib/neutral/Database.mjs +8 -4
- package/dist/lib/neutral/Entity.mjs +16 -14
- package/dist/lib/neutral/Err.mjs +1 -1
- package/dist/lib/neutral/Extension.mjs +18 -0
- package/dist/lib/neutral/Extension.mjs.map +7 -0
- package/dist/lib/neutral/Feed.mjs +23 -18
- package/dist/lib/neutral/Filter.mjs +23 -13
- package/dist/lib/neutral/Format.mjs +3 -3
- package/dist/lib/neutral/JsonSchema.mjs +8 -8
- package/dist/lib/neutral/Key.mjs +1 -1
- package/dist/lib/neutral/Migration.mjs +17 -0
- package/dist/lib/neutral/Migration.mjs.map +7 -0
- package/dist/lib/neutral/Obj.mjs +16 -13
- package/dist/lib/neutral/Order.mjs +1 -1
- package/dist/lib/neutral/Query.mjs +19 -17
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +9 -7
- package/dist/lib/neutral/Relation.mjs +15 -14
- package/dist/lib/neutral/SchemaRegistry.mjs +1 -1
- package/dist/lib/neutral/Tag.mjs +14 -13
- package/dist/lib/neutral/Type.mjs +10 -10
- package/dist/lib/neutral/{chunk-FZO7LQO7.mjs → chunk-44HT3MEC.mjs} +2 -2
- package/dist/lib/neutral/{chunk-ROAGDPV7.mjs → chunk-4A2GS5LQ.mjs} +12 -8
- package/dist/lib/neutral/chunk-4A2GS5LQ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OENWMTE6.mjs → chunk-5SL5LDLD.mjs} +4 -2
- package/dist/lib/neutral/chunk-5SL5LDLD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-7RVZT53K.mjs} +1 -1
- package/dist/lib/neutral/{chunk-YWXWXIE5.mjs → chunk-APHSOTIX.mjs} +2 -2
- package/dist/lib/neutral/{chunk-YWXWXIE5.mjs.map → chunk-APHSOTIX.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-6DNYDXCV.mjs → chunk-B2P7IVG3.mjs} +61 -14
- package/dist/lib/neutral/chunk-B2P7IVG3.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-BNCCGLJN.mjs → chunk-BICZKPQG.mjs} +1 -1
- package/dist/lib/neutral/{chunk-43Y5DOS6.mjs → chunk-BMB7IHGB.mjs} +16 -66
- package/dist/lib/neutral/chunk-BMB7IHGB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-6K2MVI2O.mjs → chunk-BUBEC474.mjs} +4 -4
- package/dist/lib/neutral/{chunk-YMNSMKKW.mjs → chunk-C4PSESGN.mjs} +6 -22
- package/dist/lib/neutral/{chunk-YMNSMKKW.mjs.map → chunk-C4PSESGN.mjs.map} +3 -3
- package/dist/lib/neutral/chunk-FIWO2FZK.mjs +36 -0
- package/dist/lib/neutral/chunk-FIWO2FZK.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GWFFC34K.mjs +50 -0
- package/dist/lib/neutral/chunk-GWFFC34K.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-NXMFBIT5.mjs → chunk-HKETO4L4.mjs} +72 -6
- package/dist/lib/neutral/chunk-HKETO4L4.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-NEGC54NE.mjs → chunk-I2DARWPX.mjs} +17 -19
- package/dist/lib/neutral/chunk-I2DARWPX.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-7VNVH63N.mjs → chunk-IVSI7QO6.mjs} +50 -20
- package/dist/lib/neutral/chunk-IVSI7QO6.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-BOZZPUXE.mjs → chunk-MLS7U7AT.mjs} +12 -65
- package/dist/lib/neutral/chunk-MLS7U7AT.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-WYOKA6AE.mjs → chunk-N4B7FHQT.mjs} +2 -2
- package/dist/lib/neutral/{chunk-WYOKA6AE.mjs.map → chunk-N4B7FHQT.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-FXEG7EOK.mjs → chunk-N7VOEPSV.mjs} +6 -3
- package/dist/lib/neutral/{chunk-FXEG7EOK.mjs.map → chunk-N7VOEPSV.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-UTBRYVQC.mjs → chunk-QRZ2I3ZM.mjs} +2 -2
- package/dist/lib/neutral/{chunk-SEMVAGBM.mjs → chunk-TNBK56IN.mjs} +19 -24
- package/dist/lib/neutral/chunk-TNBK56IN.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-B5OXLWZL.mjs → chunk-TRPZU2HV.mjs} +2 -2
- package/dist/lib/neutral/{chunk-UI6MWK5W.mjs → chunk-TTCSATUD.mjs} +1 -1
- package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-V72DY6LU.mjs} +1 -1
- package/dist/lib/neutral/{chunk-6GPU7XC3.mjs → chunk-VW42HESL.mjs} +54 -17
- package/dist/lib/neutral/chunk-VW42HESL.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-4JRI2ZJI.mjs → chunk-X3356HPV.mjs} +120 -12
- package/dist/lib/neutral/chunk-X3356HPV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-W47JKR3X.mjs → chunk-XEXM5HWQ.mjs} +18 -46
- package/dist/lib/neutral/chunk-XEXM5HWQ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-C4JZK4J7.mjs → chunk-Z5GKP74O.mjs} +231 -479
- package/dist/lib/neutral/chunk-Z5GKP74O.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-UBEZSGXY.mjs → chunk-ZISMEVKD.mjs} +1 -1
- package/dist/lib/neutral/{chunk-UBEZSGXY.mjs.map → chunk-ZISMEVKD.mjs.map} +2 -2
- package/dist/lib/neutral/index.mjs +38 -28
- package/dist/lib/neutral/internal/index.mjs +15 -9
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +185 -129
- package/dist/lib/neutral/testing/index.mjs.map +3 -3
- package/dist/types/src/Annotation.d.ts +1 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Collection.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +14 -2
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Dataset.d.ts +2 -1
- package/dist/types/src/Dataset.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +17 -11
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +18 -18
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Extension.d.ts +80 -0
- package/dist/types/src/Extension.d.ts.map +1 -0
- package/dist/types/src/Extension.test.d.ts +2 -0
- package/dist/types/src/Extension.test.d.ts.map +1 -0
- package/dist/types/src/Feed.d.ts +62 -21
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +54 -4
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Filter.test.d.ts +2 -0
- package/dist/types/src/Filter.test.d.ts.map +1 -0
- package/dist/types/src/Hypergraph.d.ts +3 -3
- package/dist/types/src/Hypergraph.d.ts.map +1 -1
- package/dist/types/src/Json.d.ts +33 -0
- package/dist/types/src/Json.d.ts.map +1 -0
- package/dist/types/src/Json.test.d.ts +2 -0
- package/dist/types/src/Json.test.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +1 -1
- package/dist/types/src/Migration.d.ts +69 -0
- package/dist/types/src/Migration.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +42 -28
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +13 -2
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +1 -0
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +17 -18
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +2 -2
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +3 -3
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/View.d.ts +1 -1
- package/dist/types/src/View.d.ts.map +1 -1
- package/dist/types/src/exemplars.test.d.ts +2 -0
- package/dist/types/src/exemplars.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +12 -2
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/util.d.ts +1 -1
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/model.d.ts +2 -0
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/relation.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/version.d.ts.map +1 -1
- package/dist/types/src/internal/Format/date.d.ts.map +1 -1
- package/dist/types/src/internal/Format/format.d.ts.map +1 -1
- package/dist/types/src/internal/Format/number.d.ts.map +1 -1
- package/dist/types/src/internal/Format/object.d.ts.map +1 -1
- package/dist/types/src/internal/Format/types.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +28 -28
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/common.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/ids.d.ts +1 -1
- package/dist/types/src/internal/Obj/ids.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/json-serializer.d.ts +4 -3
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/set-value.d.ts +1 -1
- package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -1
- package/dist/types/src/internal/Query.d.ts +10 -0
- package/dist/types/src/internal/Query.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref.d.ts +14 -1
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Type/compose.d.ts.map +1 -1
- package/dist/types/src/internal/Type/echo-schema.d.ts +2 -2
- package/dist/types/src/internal/Type/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -1
- package/dist/types/src/internal/common/api/meta.d.ts +3 -3
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/base.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/entity.d.ts +4 -4
- package/dist/types/src/internal/common/types/entity.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/meta.d.ts +10 -0
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/version.d.ts +1 -1
- package/dist/types/src/internal/index.d.ts +1 -0
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +8 -8
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +53 -53
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -15
- package/src/Annotation.ts +1 -0
- package/src/Collection.ts +2 -2
- package/src/Database.ts +50 -15
- package/src/Entity.ts +18 -12
- package/src/Extension.test.ts +235 -0
- package/src/Extension.ts +122 -0
- package/src/Feed.ts +107 -34
- package/src/Filter.test.ts +90 -0
- package/src/Filter.ts +97 -3
- package/src/Hypergraph.ts +3 -3
- package/src/Json.test.ts +175 -0
- package/src/Json.ts +102 -0
- package/src/Migration.ts +106 -0
- package/src/Obj.test.ts +105 -13
- package/src/Obj.ts +154 -33
- package/src/Query.test.ts +199 -9
- package/src/Query.ts +58 -8
- package/src/Ref.ts +2 -0
- package/src/Relation.ts +24 -20
- package/src/Type.ts +1 -1
- package/src/View.ts +1 -1
- package/src/exemplars.test.ts +21 -0
- package/src/index.ts +4 -0
- package/src/internal/Annotation/annotations.test.ts +51 -2
- package/src/internal/Annotation/annotations.ts +33 -14
- package/src/internal/Annotation/sorting.ts +0 -1
- package/src/internal/Entity/api.ts +0 -1
- package/src/internal/Entity/model.ts +2 -0
- package/src/internal/Entity/object.ts +0 -1
- package/src/internal/Entity/version.ts +0 -1
- package/src/internal/Format/date.test.ts +0 -1
- package/src/internal/Format/format.test.ts +0 -1
- package/src/internal/JsonSchema/json-schema-type.ts +1 -1
- package/src/internal/JsonSchema/json-schema.test.ts +1 -2
- package/src/internal/JsonSchema/json-schema.ts +1 -2
- package/src/internal/Obj/clone.ts +1 -1
- package/src/internal/Obj/create-object.test.ts +2 -4
- package/src/internal/Obj/create-object.ts +2 -3
- package/src/internal/Obj/deleted.ts +1 -1
- package/src/internal/Obj/ids.ts +1 -1
- package/src/internal/Obj/json-serializer.test.ts +49 -5
- package/src/internal/Obj/json-serializer.ts +47 -25
- package/src/internal/Obj/set-value.test.ts +24 -24
- package/src/internal/Obj/set-value.ts +1 -1
- package/src/internal/Query.ts +156 -0
- package/src/internal/Ref/ref-array.ts +0 -1
- package/src/internal/Ref/ref.test.ts +0 -1
- package/src/internal/Ref/ref.ts +18 -1
- package/src/internal/Type/compose.test.ts +0 -1
- package/src/internal/Type/echo-schema.ts +3 -4
- package/src/internal/common/README.md +1 -1
- package/src/internal/common/api/meta.ts +3 -3
- package/src/internal/common/proxy/change-context.ts +1 -1
- package/src/internal/common/proxy/change.test.ts +94 -94
- package/src/internal/common/proxy/errors.ts +2 -2
- package/src/internal/common/proxy/handler.test.ts +0 -2
- package/src/internal/common/proxy/json-serializer.ts +4 -1
- package/src/internal/common/proxy/make-object.ts +0 -1
- package/src/internal/common/proxy/ownership.ts +0 -1
- package/src/internal/common/proxy/reactive-array.ts +1 -1
- package/src/internal/common/proxy/reactive.test.ts +54 -0
- package/src/internal/common/proxy/reactive.ts +11 -3
- package/src/internal/common/proxy/typed-handler.test.ts +0 -1
- package/src/internal/common/proxy/typed-handler.ts +8 -10
- package/src/internal/common/proxy/typed-object.test.ts +2 -3
- package/src/internal/common/types/entity.ts +1 -1
- package/src/internal/common/types/meta.ts +12 -1
- package/src/internal/index.ts +1 -0
- package/src/testing/api.test.ts +0 -1
- package/src/testing/test-data.ts +157 -98
- package/dist/lib/neutral/chunk-43Y5DOS6.mjs.map +0 -7
- package/dist/lib/neutral/chunk-4JRI2ZJI.mjs.map +0 -7
- package/dist/lib/neutral/chunk-6DNYDXCV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-6GPU7XC3.mjs.map +0 -7
- package/dist/lib/neutral/chunk-7VNVH63N.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BOZZPUXE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-C4JZK4J7.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NEGC54NE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-NXMFBIT5.mjs.map +0 -7
- package/dist/lib/neutral/chunk-OENWMTE6.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ROAGDPV7.mjs.map +0 -7
- package/dist/lib/neutral/chunk-SEMVAGBM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-W47JKR3X.mjs.map +0 -7
- /package/dist/lib/neutral/{chunk-FZO7LQO7.mjs.map → chunk-44HT3MEC.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-ANHVGJI4.mjs.map → chunk-7RVZT53K.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-BNCCGLJN.mjs.map → chunk-BICZKPQG.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-6K2MVI2O.mjs.map → chunk-BUBEC474.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-UTBRYVQC.mjs.map → chunk-QRZ2I3ZM.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-B5OXLWZL.mjs.map → chunk-TRPZU2HV.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-UI6MWK5W.mjs.map → chunk-TTCSATUD.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-OMUPQMLR.mjs.map → chunk-V72DY6LU.mjs.map} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/JsonSchema/annotations.ts", "../../../src/internal/JsonSchema/json-schema-type.ts", "../../../src/internal/JsonSchema/json-schema.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { GeneratorAnnotationId, LabelAnnotationId, PropertyMetaAnnotationId } from '../Annotation';\nimport { CurrencyAnnotationId, FormatAnnotationId } from '../Format';\nimport { type JsonSchemaEchoAnnotations, type JsonSchemaType } from '../JsonSchema';\n\n//\n// This file configures annotations for JSON encoding/decoding.\n//\n\n// Go on the root level.\ntype RootJsonSchemaProperty = keyof JsonSchemaType;\n\n// Go on the namespaced `annotations` property.\ntype NamespacedJsonSchemaProperty = keyof JsonSchemaEchoAnnotations;\n\n/**\n * List of annotations for JSON encoding/decoding.\n * Omits default effect-schema annotations since they are encoded with default serializer.\n */\n// TODO(burdon): Reconcile with `EchoAnnotations`.\nexport const CustomAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {\n format: FormatAnnotationId,\n currency: CurrencyAnnotationId,\n};\n\n/**\n * List of annotations for JSON decoding only.\n * Includes default effect annotations.\n */\nexport const DecodedAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {\n title: SchemaAST.TitleAnnotationId,\n description: SchemaAST.DescriptionAnnotationId,\n};\n\n/**\n * Annotations that go into ECHO namespace in json-schema.\n */\n// TODO(dmaretskyi): Consider removing ECHO namespace and putting them at the top level.\n// TODO(dmaretskyi): Move to format.ts when circular imports are solved\nexport const EchoAnnotations: Partial<Record<NamespacedJsonSchemaProperty, symbol>> = {\n // TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.\n meta: PropertyMetaAnnotationId,\n generator: GeneratorAnnotationId,\n labelProp: LabelAnnotationId,\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { JsonPath, type JsonProp } from '@dxos/effect';\n\nimport { type Mutable } from '../common/proxy';\nimport { EntityKindSchema } from '../common/types';\nimport { FormatAnnotation, TypeFormat } from '../Format';\n\n//\n// JSON Schema\n//\n\n// TODO(burdon): Reuse/reconcile with ScalarTypeEnum (handle arrays).\nconst SimpleTypes = Schema.Literal('array', 'boolean', 'integer', 'null', 'number', 'object', 'string');\n\nconst NonNegativeInteger = Schema.Number.pipe(Schema.greaterThanOrEqualTo(0));\n\nconst StringArray = Schema.Array(Schema.String);\n\nconst JsonSchemaOrBoolean = Schema.Union(\n Schema.suspend(() => JsonSchemaType),\n Schema.Boolean,\n);\n\n/**\n * Go under the `annotations` property.\n */\nexport const JsonSchemaEchoAnnotations = Schema.Struct({\n /**\n * Label for this schema.\n * Mapped from {@link LabelAnnotationId}.\n */\n labelProp: Schema.optional(Schema.Union(JsonPath, Schema.Array(JsonPath))),\n\n /**\n * Generator function for this schema.\n * Mapped from {@link GeneratorAnnotationId}.\n */\n generator: Schema.optional(Schema.Union(Schema.String, Schema.Tuple(Schema.String, Schema.Number))),\n\n /**\n * {@link PropertyMeta} annotations get serialized here.\n */\n meta: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.Any,\n }),\n ),\n\n /**\n * @deprecated\n */\n // TODO(dmaretskyi): We risk old schema not passing validation due to the extra fields. Remove when we are sure this is safe.\n type: Schema.optional(\n Schema.Struct({\n typename: Schema.String,\n version: Schema.String,\n\n // Not used.\n schemaId: Schema.optional(Schema.String),\n }),\n ),\n\n /**\n * @deprecated Superseded by `meta`.\n */\n annotations: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.Any,\n }),\n ),\n});\nexport type JsonSchemaEchoAnnotations = Schema.Schema.Type<typeof JsonSchemaEchoAnnotations>;\n\n/**\n * Describes a schema for the JSON-schema objects stored in ECHO.\n * Contains extensions for ECHO (e.g., references).\n * Ref: https://json-schema.org/draft-07/schema\n */\n// TODO(burdon): Integrate with Effect Serializable?\n// TODO(dmaretskyi): Update to latest draft: https://json-schema.org/draft/2020-12\nconst _JsonSchemaType = Schema.Struct({\n /**\n * Identifier for this schema.\n * This schema might be referenced by $ref clause in other schemas.\n */\n // TODO(dmaretskyi): Specify how the ids are generated.\n // TODO(dmaretskyi): For type dxns, should this include the version?\n $id: Schema.optional(Schema.String),\n\n /**\n * Schema of this schema.\n * Set to \"https://json-schema.org/draft-07/schema\".\n */\n $schema: Schema.optional(Schema.String),\n\n /**\n * Reference to another schema.\n */\n $ref: Schema.optional(Schema.String),\n\n /**\n * Comments are ignored when interpreting the schema.\n */\n $comment: Schema.optional(Schema.String),\n\n /**\n * Defines whether this schema is an object schema or a relation schema.\n */\n entityKind: Schema.optional(EntityKindSchema),\n\n /**\n * Typename of this schema.\n * Only on schema representing an ECHO object.\n *\n * @example 'com.example.type.my-type'\n */\n typename: Schema.optional(Schema.String),\n\n /**\n * Version of this schema.\n * Custom dialect for ECHO.\n */\n version: Schema.optional(Schema.String),\n\n /**\n * Target of this relation.\n * Only for relation schemas.\n * The referenced schema must be an object schema.\n */\n relationTarget: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n /**\n * Source of this relation.\n * Only for relation schemas.\n * The referenced schema must be an object schema.\n */\n relationSource: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n /**\n * Title of this schema.\n */\n title: Schema.optional(Schema.String),\n\n /**\n * Description of this schema.\n */\n description: Schema.optional(Schema.String),\n\n /**\n * Whether this schema is read-only.\n */\n readOnly: Schema.optional(Schema.Boolean),\n\n /**\n * Whether this schema is write-only.\n */\n writeOnly: Schema.optional(Schema.Boolean),\n\n /**\n * Examples of instances of this schema.\n */\n examples: Schema.optional(Schema.Array(Schema.Any)),\n\n /**\n * Default value for this schema.\n */\n default: Schema.optional(Schema.Any),\n\n /**\n * This schema only matches values that are equal to this value.\n */\n const: Schema.optional(Schema.Any),\n\n /**\n * This schema only matches one of the values in this array.\n */\n enum: Schema.optional(Schema.Array(Schema.Any)),\n\n /**\n * Base type of the schema.\n */\n type: Schema.optional(Schema.Union(SimpleTypes, Schema.Array(SimpleTypes))),\n\n //\n // Numbers.\n //\n\n multipleOf: Schema.optional(Schema.Number.pipe(Schema.greaterThan(0))),\n maximum: Schema.optional(Schema.Number),\n exclusiveMaximum: Schema.optional(Schema.Number),\n minimum: Schema.optional(Schema.Number),\n exclusiveMinimum: Schema.optional(Schema.Number),\n\n //\n // Strings.\n //\n\n maxLength: Schema.optional(NonNegativeInteger),\n\n /**\n * Regex pattern for strings.\n */\n pattern: Schema.optional(Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex))),\n\n /**\n * Serialized from {@link FormatAnnotationId}.\n */\n format: Schema.optional(Schema.String),\n\n //\n // Arrays\n //\n\n minLength: Schema.optional(NonNegativeInteger),\n items: Schema.optional(\n Schema.Union(\n Schema.suspend(() => JsonSchemaType),\n Schema.Array(Schema.suspend(() => JsonSchemaType)),\n ),\n ),\n additionalItems: Schema.optional(\n Schema.Union(\n Schema.suspend(() => JsonSchemaType),\n Schema.Boolean,\n ),\n ),\n maxItems: Schema.optional(NonNegativeInteger),\n minItems: Schema.optional(NonNegativeInteger),\n uniqueItems: Schema.optional(Schema.Boolean),\n contains: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n //\n // Objects\n //\n\n maxProperties: Schema.optional(NonNegativeInteger),\n minProperties: Schema.optional(NonNegativeInteger),\n required: Schema.optional(StringArray),\n\n /**\n * Non-standard JSON Schema extension.\n * Defines the order of properties in the object.\n * The unmentioned properties are placed at the end.\n *\n * Related: https://github.com/json-schema/json-schema/issues/119\n */\n propertyOrder: Schema.optional(StringArray),\n\n additionalProperties: Schema.optional(JsonSchemaOrBoolean),\n properties: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n patternProperties: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n propertyNames: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n\n definitions: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n dependencies: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => Schema.Union(Schema.String, StringArray, JsonSchemaType)).annotations({\n identifier: 'dependency',\n description: 'Dependency',\n }),\n }),\n ),\n\n contentMediaType: Schema.optional(Schema.String),\n contentEncoding: Schema.optional(Schema.String),\n\n if: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n then: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n else: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n allOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n anyOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n oneOf: Schema.optional(Schema.Array(Schema.suspend(() => JsonSchemaType))),\n not: Schema.optional(Schema.suspend(() => JsonSchemaType)),\n $defs: Schema.optional(\n Schema.Record({\n key: Schema.String,\n value: Schema.suspend(() => JsonSchemaType),\n }),\n ),\n\n //\n // ECHO extensions.\n //\n\n currency: Schema.optional(Schema.String),\n\n reference: Schema.optional(\n Schema.Struct({\n schema: Schema.suspend(() => JsonSchemaType),\n schemaVersion: Schema.optional(Schema.String),\n schemaObject: Schema.optional(Schema.String),\n }),\n ),\n\n /**\n * ECHO-specific annotations.\n */\n // TODO(dmaretskyi): Since we are adding a lot of new extensions to the JSON Schema, it is safer to namespace them here.\n annotations: Schema.optional(JsonSchemaEchoAnnotations),\n\n /**\n * @deprecated Use `annotations` instead.\n */\n echo: Schema.optional(JsonSchemaEchoAnnotations),\n}).annotations({ identifier: 'jsonSchema', description: 'JSON Schema' });\n\nexport const JsonSchemaFields = Object.keys(_JsonSchemaType.fields);\n\n/**\n * https://json-schema.org/draft-07/schema\n */\n// TODO(burdon): Reconcile with @effect/Schema/JSONSchema\nexport interface JsonSchemaType extends Schema.Schema.Type<typeof _JsonSchemaType> {}\n\nexport const JsonSchemaType: Schema.Schema<JsonSchemaType> = _JsonSchemaType;\n\n// TODO(burdon): Factor out JSON schema utils.\n\nexport const getSchemaProperty = (schema: JsonSchemaType, property: JsonProp): JsonSchemaType | undefined => {\n return schema.properties?.[property];\n};\n\n// TODO(burdon): Properties should be ordered.\nexport const setSchemaProperty = (\n schema: Mutable<JsonSchemaType>,\n property: JsonProp,\n value: Mutable<JsonSchemaType>,\n) => {\n schema.properties ??= {};\n schema.properties[property] = value;\n return schema;\n};\n\n/**\n * @internal\n */\nexport const ECHO_ANNOTATIONS_NS_DEPRECATED_KEY: keyof JsonSchemaType = 'echo';\n\n/**\n * @internal\n */\nexport const ECHO_ANNOTATIONS_NS_KEY = 'annotations';\n\n/**\n * @internal\n * @returns ECHO annotations namespace object in its normalized form.\n *\n * `meta` holds PropertyMeta annotations.\n * `annotations` holds other annotations.\n */\nexport const getNormalizedEchoAnnotations = (obj: JsonSchemaType): JsonSchemaEchoAnnotations | undefined => {\n if (obj[ECHO_ANNOTATIONS_NS_KEY] != null && obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {\n return normalizeEchoAnnotations({\n ...obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY],\n ...obj[ECHO_ANNOTATIONS_NS_KEY],\n });\n } else if (obj[ECHO_ANNOTATIONS_NS_KEY] != null) {\n return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_KEY]!);\n } else if (obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {\n return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY]!);\n } else {\n return undefined;\n }\n};\n\nconst normalizeEchoAnnotations = (obj: JsonSchemaEchoAnnotations): JsonSchemaEchoAnnotations => {\n if (!obj.annotations) {\n return obj;\n } else {\n const res = {\n ...obj,\n meta: {\n ...obj.annotations,\n ...(obj.meta ?? {}),\n },\n };\n delete res.annotations;\n return res;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Array from 'effect/Array';\nimport * as Function from 'effect/Function';\nimport * as JSONSchema from 'effect/JSONSchema';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport type * as Types from 'effect/Types';\n\nimport { raise } from '@dxos/debug';\nimport { mapAst } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, ObjectId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { clearUndefined, orderKeys, removeProperties } from '@dxos/util';\n\nimport {\n type TypeAnnotation,\n TypeAnnotationId,\n TypeIdentifierAnnotationId,\n makeTypeJsonSchemaAnnotation,\n} from '../Annotation';\nimport { ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION, EntityKind, EntityKindSchema } from '../common/types';\nimport { type JsonSchemaReferenceInfo, createEchoReferenceSchema } from '../Ref';\nimport { CustomAnnotations, DecodedAnnotations, EchoAnnotations } from './annotations';\nimport {\n ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,\n ECHO_ANNOTATIONS_NS_KEY,\n type JsonSchemaEchoAnnotations,\n type JsonSchemaType,\n getNormalizedEchoAnnotations,\n} from './json-schema-type';\n\n// TODO(burdon): Are these values stored (can they be changed?)\nexport enum PropType {\n NONE = 0,\n STRING = 1, // TODO(burdon): vs TEXT?\n NUMBER = 2,\n BOOLEAN = 3,\n DATE = 4,\n REF = 5,\n RECORD = 6,\n ENUM = 7,\n}\n\n// TODO(burdon): Reconcile with @dxos/schema.\nexport const toPropType = (type?: PropType): string => {\n switch (type) {\n case PropType.STRING:\n return 'string';\n case PropType.NUMBER:\n return 'number';\n case PropType.BOOLEAN:\n return 'boolean';\n case PropType.DATE:\n return 'date';\n case PropType.REF:\n return 'ref';\n case PropType.RECORD:\n return 'object';\n default:\n throw new Error(`Invalid type: ${type}`);\n }\n};\n\nconst JSON_SCHEMA_URL = 'http://json-schema.org/draft-07/schema#';\n\nexport type JsonSchemaOptions = {\n strict?: boolean;\n};\n\n/**\n * Convert effect schema to JSON Schema.\n * NOTE: This handles custom annotations.\n * @param schema\n */\n// TODO(burdon): Reconcile with possibly extending @effect/Schema/JSONSchema\n// We add additional propertyOrder (but the object properties ARE ordered); and type \"string\" for literals.\n// TODO(wittjosiah): This is mutable because its a pojo, perhaps should be left as readonly at type level though?\nexport const toJsonSchema = (\n schema: Schema.Schema.All,\n options: JsonSchemaOptions = {},\n): Types.DeepMutable<JsonSchemaType> => {\n assertArgument(Schema.isSchema(schema), 'schema');\n let jsonSchema = _toJsonSchemaAST(schema.ast);\n if (options.strict) {\n // TOOD(burdon): Workaround to ensure JSON schema is valid (for agv parsing).\n jsonSchema = removeProperties(jsonSchema, (key, value) => {\n if (key === '$id' && value === '/schemas/any') {\n return true;\n }\n if (key === '$ref' && value === '#/$defs/dependency') {\n return true;\n }\n if (key === '$ref' && value === '#/$defs/jsonSchema') {\n return true;\n }\n\n return false;\n });\n }\n\n return jsonSchema;\n};\n\nconst _toJsonSchemaAST = (ast: SchemaAST.AST): Types.DeepMutable<JsonSchemaType> => {\n const withRefinements = withEchoRefinements(ast, '#');\n const jsonSchema = JSONSchema.fromAST(withRefinements, {\n definitions: {},\n }) as Types.DeepMutable<JsonSchemaType>;\n\n return normalizeJsonSchema(jsonSchema);\n};\n\nconst withEchoRefinements = (\n ast: SchemaAST.AST,\n path: string | undefined,\n suspendCache = new Map<SchemaAST.AST, string>(),\n): SchemaAST.AST => {\n if (path) {\n suspendCache.set(ast, path);\n }\n\n let recursiveResult: SchemaAST.AST;\n if (SchemaAST.isSuspend(ast)) {\n // Precompute JSON schema for suspended AST since effect serializer does not support it.\n const suspendedAst = ast.f();\n const cachedPath = suspendCache.get(suspendedAst);\n if (cachedPath) {\n recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {\n [SchemaAST.JSONSchemaAnnotationId]: {\n $ref: cachedPath,\n },\n });\n } else {\n const jsonSchema = _toJsonSchemaAST(suspendedAst);\n recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {\n [SchemaAST.JSONSchemaAnnotationId]: jsonSchema,\n });\n }\n } else if (SchemaAST.isTypeLiteral(ast)) {\n // Add property order annotations\n recursiveResult = mapAst(ast, (ast, key) =>\n withEchoRefinements(ast, path && typeof key === 'string' ? `${path}/${key}` : undefined, suspendCache),\n );\n recursiveResult = addJsonSchemaFields(recursiveResult, {\n propertyOrder: [...ast.propertySignatures.map((p) => p.name)] as string[],\n });\n } else if (SchemaAST.isUndefinedKeyword(ast)) {\n // Ignore undefined keyword that appears in the optional fields.\n return ast;\n } else {\n recursiveResult = mapAst(ast, (ast, key) =>\n withEchoRefinements(\n ast,\n path && (typeof key === 'string' || typeof key === 'number') ? `${path}/${key}` : undefined,\n suspendCache,\n ),\n );\n }\n\n const annotationFields = annotations_toJsonSchemaFields(ast.annotations);\n if (Object.keys(annotationFields).length === 0) {\n return recursiveResult;\n } else {\n return addJsonSchemaFields(recursiveResult, annotationFields);\n }\n};\n\n/**\n * Convert JSON schema to effect schema.\n * @param root\n * @param definitions\n */\nexport const toEffectSchema = (root: JsonSchemaType, _defs?: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {\n const defs = root.$defs ? { ..._defs, ...root.$defs } : (_defs ?? {});\n if ('type' in root && root.type === 'object') {\n return objectToEffectSchema(root, defs);\n }\n\n let result: Schema.Schema.AnyNoContext = Schema.Unknown;\n if ('$ref' in root) {\n switch (root.$ref) {\n case '/schemas/echo/ref': {\n result = refToEffectSchema(root);\n break;\n }\n }\n } else if ('$id' in root) {\n switch (root.$id as string) {\n case '/schemas/any': {\n result = anyToEffectSchema(root as JSONSchema.JsonSchema7Any);\n break;\n }\n case '/schemas/unknown': {\n result = Schema.Unknown;\n break;\n }\n case '/schemas/{}':\n case '/schemas/object': {\n result = Schema.Object;\n break;\n }\n // Custom ECHO object reference.\n case '/schemas/echo/ref': {\n result = refToEffectSchema(root);\n break;\n }\n }\n } else if ('enum' in root) {\n result = Schema.Union(...root.enum!.map((e) => Schema.Literal(e)));\n } else if ('oneOf' in root) {\n result = Schema.Union(...root.oneOf!.map((v) => toEffectSchema(v, defs)));\n } else if ('anyOf' in root) {\n result = Schema.Union(...root.anyOf!.map((v) => toEffectSchema(v, defs)));\n } else if ('allOf' in root) {\n if (root.allOf!.length === 1) {\n result = toEffectSchema(root.allOf![0], defs);\n } else {\n log.warn('allOf with multiple schemas is not supported');\n result = Schema.Unknown;\n }\n } else if ('type' in root) {\n switch (root.type) {\n case 'string': {\n result = Schema.String;\n if (root.pattern) {\n result = result.pipe(Schema.pattern(new RegExp(root.pattern)));\n }\n break;\n }\n case 'number': {\n result = Schema.Number;\n break;\n }\n case 'integer': {\n result = Schema.Number.pipe(Schema.int());\n break;\n }\n case 'boolean': {\n result = Schema.Boolean;\n break;\n }\n case 'array': {\n if (Array.isArray(root.items)) {\n const [required, optional] = Function.pipe(\n root.items,\n Array.map((v) => toEffectSchema(v as JsonSchemaType, defs)),\n Array.splitAt(root.minItems ?? root.items.length),\n );\n result = Schema.Tuple(...required, ...optional.map(Schema.optionalElement));\n } else {\n invariant(root.items);\n const items = root.items;\n result = Array.isArray(items)\n ? Schema.Tuple(...items.map((v) => toEffectSchema(v as JsonSchemaType, defs)))\n : Schema.Array(toEffectSchema(items as JsonSchemaType, defs));\n }\n break;\n }\n case 'null': {\n result = Schema.Null;\n break;\n }\n }\n } else if ('$ref' in root) {\n const refSegments = root.$ref!.split('/');\n const jsonSchema = defs[refSegments[refSegments.length - 1]];\n invariant(jsonSchema, `missing definition for ${root.$ref}`);\n result = toEffectSchema(jsonSchema, defs).pipe(\n Schema.annotations({ identifier: refSegments[refSegments.length - 1] }),\n );\n }\n\n const annotations = jsonSchemaFieldsToAnnotations(root);\n\n // log.info('toEffectSchema', { root, annotations });\n result = result.annotations(annotations);\n\n return result;\n};\n\nconst objectToEffectSchema = (root: JsonSchemaType, defs: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {\n invariant('type' in root && root.type === 'object', `not an object: ${root}`);\n\n const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];\n const isEchoObject =\n echoRefinement != null || ('$id' in root && typeof root.$id === 'string' && root.$id.startsWith('dxn:'));\n\n let fields: Schema.Struct.Fields = {};\n const propertyList = Object.entries(root.properties ?? {});\n let immutableIdField: Schema.Schema.AnyNoContext | undefined;\n for (const [key, value] of propertyList) {\n if (isEchoObject && key === 'id') {\n immutableIdField = toEffectSchema(value, defs);\n } else {\n // TODO(burdon): Mutable cast.\n (fields as any)[key] = root.required?.includes(key)\n ? toEffectSchema(value, defs)\n : Schema.optional(toEffectSchema(value, defs));\n }\n }\n\n if (root.propertyOrder) {\n fields = orderKeys(fields, root.propertyOrder as any);\n }\n\n let schema: Schema.Schema<any, any, unknown>;\n if (root.patternProperties) {\n invariant(propertyList.length === 0, 'pattern properties mixed with regular properties are not supported');\n invariant(\n Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === '',\n 'only one pattern property is supported',\n );\n\n schema = Schema.Record({ key: Schema.String, value: toEffectSchema(root.patternProperties[''], defs) });\n } else if (typeof root.additionalProperties !== 'object') {\n schema = Schema.Struct(fields);\n } else {\n const indexValue = toEffectSchema(root.additionalProperties, defs);\n if (propertyList.length > 0) {\n schema = Schema.Struct(fields, { key: Schema.String, value: indexValue });\n } else {\n schema = Schema.Record({ key: Schema.String, value: indexValue });\n }\n }\n\n if (immutableIdField) {\n schema = Schema.extend(schema, Schema.Struct({ id: immutableIdField }));\n }\n\n const annotations = jsonSchemaFieldsToAnnotations(root);\n return schema.annotations(annotations) as any;\n};\n\nconst anyToEffectSchema = (root: JSONSchema.JsonSchema7Any): Schema.Schema.AnyNoContext => {\n const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];\n // TODO(dmaretskyi): Is this branch still taken?\n if ((echoRefinement as any)?.reference != null) {\n const echoId = root.$id.startsWith('dxn:echo:') ? root.$id : undefined;\n return createEchoReferenceSchema(\n echoId,\n (echoRefinement as any).reference.typename,\n (echoRefinement as any).reference.version,\n );\n }\n\n return Schema.Any;\n};\n\n// TODO(dmaretskyi): Types.\nconst refToEffectSchema = (root: any): Schema.Schema.AnyNoContext => {\n if (!('reference' in root)) {\n // Fallback to generic object ref when no reference info is provided.\n return createEchoReferenceSchema(undefined, ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION);\n }\n\n const reference: JsonSchemaReferenceInfo = root.reference;\n if (typeof reference !== 'object') {\n throw new Error('Invalid reference field in ref schema');\n }\n\n const targetSchemaDXN = DXN.parse(reference.schema.$ref);\n invariant(targetSchemaDXN.kind === DXN.kind.TYPE);\n\n return createEchoReferenceSchema(\n targetSchemaDXN.toString(),\n targetSchemaDXN.kind === DXN.kind.TYPE ? targetSchemaDXN.parts[0] : undefined,\n reference.schemaVersion,\n );\n};\n\n//\n// Annotations\n//\n\nconst annotations_toJsonSchemaFields = (annotations: SchemaAST.Annotations): Record<symbol, any> => {\n const schemaFields: Record<string, any> = {};\n\n const echoAnnotations: Types.Mutable<JsonSchemaEchoAnnotations> = {};\n for (const [key, annotationId] of Object.entries(EchoAnnotations)) {\n if (annotations[annotationId] != null) {\n echoAnnotations[key as keyof JsonSchemaEchoAnnotations] = annotations[annotationId] as any;\n }\n }\n if (Object.keys(echoAnnotations).length > 0) {\n // TODO(dmaretskyi): use new namespace.\n schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;\n }\n\n const echoIdentifier = annotations[TypeIdentifierAnnotationId];\n if (echoIdentifier) {\n schemaFields[ECHO_ANNOTATIONS_NS_KEY] ??= {};\n schemaFields[ECHO_ANNOTATIONS_NS_KEY].schemaId = echoIdentifier;\n }\n\n // Custom (at end).\n for (const [key, annotationId] of Object.entries(CustomAnnotations)) {\n const value = annotations[annotationId];\n if (value != null) {\n schemaFields[key] = value;\n }\n }\n\n return schemaFields;\n};\n\nconst decodeTypeIdentifierAnnotation = (schema: JsonSchemaType): string | undefined => {\n // Limit to dxn:echo: URIs.\n if (schema.$id && schema.$id.startsWith('dxn:echo:')) {\n return schema.$id;\n } else if (schema.$id && schema.$id.startsWith('dxn:type:') && schema?.echo?.type?.schemaId) {\n const id = schema?.echo?.type?.schemaId;\n if (ObjectId.isValid(id)) {\n return DXN.fromLocalObjectId(id).toString();\n }\n }\n return undefined;\n};\n\nconst decodeTypeAnnotation = (schema: JsonSchemaType): TypeAnnotation | undefined => {\n if (schema.typename) {\n const annotation: Types.Mutable<TypeAnnotation> = {\n // TODO(dmaretskyi): Decoding default.\n kind: schema.entityKind ? Schema.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,\n typename: schema.typename,\n version: schema.version ?? '0.1.0',\n };\n\n if (annotation.kind === EntityKind.Relation) {\n const source = schema.relationSource?.$ref ?? raise(new Error('Relation source not set'));\n const target = schema.relationTarget?.$ref ?? raise(new Error('Relation target not set'));\n annotation.sourceSchema = DXN.parse(source).toString();\n annotation.targetSchema = DXN.parse(target).toString();\n }\n\n return annotation;\n }\n\n // Decode legacy schema.\n if (!schema.typename && schema?.echo?.type) {\n return {\n kind: EntityKind.Object,\n typename: schema.echo.type.typename,\n version: schema.echo.type.version,\n };\n }\n\n return undefined;\n};\n\nconst jsonSchemaFieldsToAnnotations = (schema: JsonSchemaType): SchemaAST.Annotations => {\n const annotations: Types.Mutable<Schema.Annotations.Schema<any>> = {};\n\n const echoAnnotations: JsonSchemaEchoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};\n if (echoAnnotations) {\n for (const [key, annotationId] of Object.entries(EchoAnnotations)) {\n if (echoAnnotations[key as keyof JsonSchemaEchoAnnotations]) {\n annotations[annotationId] = echoAnnotations[key as keyof JsonSchemaEchoAnnotations];\n }\n }\n }\n\n const typeIdentifier = decodeTypeIdentifierAnnotation(schema);\n annotations[TypeIdentifierAnnotationId] = typeIdentifier;\n const typeAnnotation = decodeTypeAnnotation(schema);\n if (typeAnnotation) {\n annotations[TypeAnnotationId] = typeAnnotation;\n annotations[SchemaAST.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({\n identifier: typeIdentifier,\n kind: typeAnnotation.kind,\n typename: typeAnnotation.typename,\n version: typeAnnotation.version,\n relationSource: typeAnnotation.sourceSchema,\n relationTarget: typeAnnotation.targetSchema,\n });\n }\n\n // Custom (at end).\n for (const [key, annotationId] of Object.entries({ ...CustomAnnotations, ...DecodedAnnotations })) {\n if (key in schema) {\n annotations[annotationId] = (schema as any)[key];\n }\n }\n\n return clearUndefined(annotations);\n};\n\nconst makeAnnotatedRefinement = (ast: SchemaAST.AST, annotations: SchemaAST.Annotations): SchemaAST.Refinement => {\n return new SchemaAST.Refinement(ast, () => Option.none(), annotations);\n};\n\nconst addJsonSchemaFields = (ast: SchemaAST.AST, schema: JsonSchemaType): SchemaAST.AST =>\n makeAnnotatedRefinement(ast, { [SchemaAST.JSONSchemaAnnotationId]: schema });\n\n/**\n * Fixes field order.\n * Sets `$schema` prop.\n */\nconst normalizeJsonSchema = (jsonSchema: Types.DeepMutable<JsonSchemaType>): Types.DeepMutable<JsonSchemaType> => {\n if (jsonSchema.properties && 'id' in jsonSchema.properties) {\n jsonSchema.properties = orderKeys(jsonSchema.properties, ['id']); // Put id first.\n }\n\n // TODO(dmaretskyi): Makes sure undefined is not left on optional fields for the resulting object.\n jsonSchema.$schema = JSON_SCHEMA_URL;\n jsonSchema = orderKeys(jsonSchema, [\n '$schema',\n '$id',\n\n 'entityKind',\n 'typename',\n 'version',\n 'relationTarget',\n 'relationSource',\n\n 'type',\n 'enum',\n\n 'properties',\n 'required',\n 'propertyOrder', // Custom.\n 'items',\n 'additionalProperties',\n\n 'anyOf',\n 'oneOf',\n ]);\n return jsonSchema;\n};\n"],
|
|
5
|
+
"mappings":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AA,wBAAA,KAAA;EAE5E,CAAA,iCAAA,GAAA;;IAMIF,sBAAwBwG,CAAAA,eAAUxG;iBAAwB,cAAA,QAAA,WAAA,YAAA;eAAQ,aAAgB,UAAA,WAAA,YAAA;MACpF;IAEA,CAAA;EACAA;aAEE,UAAA;eACA,UAAA,YAAA;IAEA;IACA;IACA;IACA;IACA;IAEA;IACA;IAEA;IACA;IACA;IACA;IACA;IAEA;IACA;IACD;IACD;EACF,CAAA;;;",
|
|
6
|
+
"names": ["SchemaAST", "CustomAnnotations", "format", "FormatAnnotationId", "currency", "CurrencyAnnotationId", "DecodedAnnotations", "title", "TitleAnnotationId", "description", "DescriptionAnnotationId", "EchoAnnotations", "meta", "PropertyMetaAnnotationId", "generator", "GeneratorAnnotationId", "labelProp", "LabelAnnotationId", "Schema", "JsonPath", "SimpleTypes", "Literal", "NonNegativeInteger", "Number", "pipe", "greaterThanOrEqualTo", "StringArray", "Array", "String", "JsonSchemaOrBoolean", "Union", "suspend", "JsonSchemaType", "Boolean", "JsonSchemaEchoAnnotations", "Struct", "labelProp", "optional", "JsonPath", "generator", "Tuple", "meta", "Record", "key", "value", "Any", "type", "typename", "version", "schemaId", "annotations", "_JsonSchemaType", "$id", "$schema", "$ref", "$comment", "entityKind", "EntityKindSchema", "relationTarget", "relationSource", "title", "description", "readOnly", "writeOnly", "examples", "default", "const", "enum", "multipleOf", "greaterThan", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "pattern", "FormatAnnotation", "set", "TypeFormat", "Regex", "format", "minLength", "items", "additionalItems", "maxItems", "minItems", "uniqueItems", "contains", "maxProperties", "minProperties", "required", "propertyOrder", "additionalProperties", "properties", "patternProperties", "propertyNames", "definitions", "dependencies", "identifier", "contentMediaType", "contentEncoding", "if", "then", "else", "allOf", "anyOf", "oneOf", "not", "$defs", "currency", "reference", "schema", "schemaVersion", "schemaObject", "echo", "JsonSchemaFields", "Object", "keys", "fields", "getSchemaProperty", "property", "setSchemaProperty", "ECHO_ANNOTATIONS_NS_DEPRECATED_KEY", "ECHO_ANNOTATIONS_NS_KEY", "getNormalizedEchoAnnotations", "obj", "normalizeEchoAnnotations", "undefined", "res", "Array", "Function", "JSONSchema", "Option", "Schema", "SchemaAST", "raise", "mapAst", "assertArgument", "invariant", "DXN", "ObjectId", "log", "clearUndefined", "orderKeys", "removeProperties", "PropType", "jsonSchema", "_toJsonSchemaAST", "ast", "removeProperties", "key", "JSONSchema", "definitions", "normalizeJsonSchema", "withEchoRefinements", "suspendCache", "path", "recursiveResult", "suspendedAst", "cachedPath", "SchemaAST", "Suspend", "JSONSchemaAnnotationId", "propertyOrder", "propertySignatures", "annotationFields", "annotations_toJsonSchemaFields", "annotations", "addJsonSchemaFields", "_defs", "$defs", "objectToEffectSchema", "result", "root", "Union", "oneOf", "toEffectSchema", "v", "anyOf", "map", "defs", "length", "log", "Schema", "Tuple", "required", "optional", "invariant", "items", "Array", "isArray", "identifier", "refSegments", "ECHO_ANNOTATIONS_NS_DEPRECATED_KEY", "isEchoObject", "echoRefinement", "$id", "fields", "propertyList", "Object", "properties", "immutableIdField", "value", "schema", "String", "additionalProperties", "indexValue", "anyToEffectSchema", "reference", "createEchoReferenceSchema", "echoId", "Error", "targetSchemaDXN", "toString", "annotationId", "echoAnnotations", "schemaFields", "ECHO_ANNOTATIONS_NS_KEY", "echoIdentifier", "TypeIdentifierAnnotationId", "decodeTypeIdentifierAnnotation", "startsWith", "id", "ObjectId", "isValid", "DXN", "fromLocalObjectId", "decodeTypeAnnotation", "kind", "entityKind", "version", "annotation", "EntityKind", "target", "relationTarget", "$ref", "sourceSchema", "source", "targetSchema", "typename", "echo", "jsonSchemaFieldsToAnnotations", "getNormalizedEchoAnnotations", "EchoAnnotations", "typeAnnotation", "TypeAnnotationId", "typeIdentifier", "relationSource", "DecodedAnnotations", "makeAnnotatedRefinement", "orderKeys"]
|
|
7
|
+
}
|
|
@@ -9,7 +9,7 @@ var EntityKind = /* @__PURE__ */ (function(EntityKind2) {
|
|
|
9
9
|
return EntityKind2;
|
|
10
10
|
})({});
|
|
11
11
|
var EntityKindSchema = Schema.Enums(EntityKind);
|
|
12
|
-
var ANY_OBJECT_TYPENAME = "org.dxos.schema.
|
|
12
|
+
var ANY_OBJECT_TYPENAME = "org.dxos.schema.anyObject";
|
|
13
13
|
var ANY_OBJECT_VERSION = "0.0.0";
|
|
14
14
|
|
|
15
15
|
// src/internal/Annotation/util.ts
|
|
@@ -64,4 +64,4 @@ export {
|
|
|
64
64
|
unwrapOptional,
|
|
65
65
|
makeTypeJsonSchemaAnnotation
|
|
66
66
|
};
|
|
67
|
-
//# sourceMappingURL=chunk-
|
|
67
|
+
//# sourceMappingURL=chunk-N4B7FHQT.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/common/types/entity.ts", "../../../src/internal/Annotation/util.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.\n// Unique symbols cause TS4023 \"cannot be named\" errors when external packages\n// try to export types that reference this key (e.g., `export const Graph = ...`).\n// TypeScript cannot emit declaration files that reference unique symbols from\n// external modules. Using a string literal allows the type to be inlined in\n// declaration files, making the API portable across package boundaries.\n\n/**\n * String key used to identify the kind of an entity instance (object or relation).\n */\nexport const KindId = '~@dxos/echo/Kind' as const;\nexport type KindId = typeof KindId;\n\n/**\n * String key used to identify the kind of a schema (object schema or relation schema).\n * Parallels KindId which identifies instance kinds.\n */\nexport const SchemaKindId = '~@dxos/echo/SchemaKind' as const;\nexport type SchemaKindId = typeof SchemaKindId;\n\n/**\n * String key used to brand snapshot types.\n * Snapshots have SnapshotKindId instead of KindId, making them\n * distinguishable from reactive objects at the type level.\n */\nexport const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;\nexport type SnapshotKindId = typeof SnapshotKindId;\n\n/**\n * Kinds of entities stored in ECHO: objects and relations.\n */\nexport enum EntityKind {\n Object = 'object',\n Relation = 'relation',\n}\n\nexport const EntityKindSchema = Schema.Enums(EntityKind);\n\n/**\n * Typename for generic object references (Type.Obj / Ref.Ref(Obj.Unknown)).\n * Used when referencing any object without a specific schema.\n */\nexport const ANY_OBJECT_TYPENAME = 'org.dxos.schema.
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\n// NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.\n// Unique symbols cause TS4023 \"cannot be named\" errors when external packages\n// try to export types that reference this key (e.g., `export const Graph = ...`).\n// TypeScript cannot emit declaration files that reference unique symbols from\n// external modules. Using a string literal allows the type to be inlined in\n// declaration files, making the API portable across package boundaries.\n\n/**\n * String key used to identify the kind of an entity instance (object or relation).\n */\nexport const KindId = '~@dxos/echo/Kind' as const;\nexport type KindId = typeof KindId;\n\n/**\n * String key used to identify the kind of a schema (object schema or relation schema).\n * Parallels KindId which identifies instance kinds.\n */\nexport const SchemaKindId = '~@dxos/echo/SchemaKind' as const;\nexport type SchemaKindId = typeof SchemaKindId;\n\n/**\n * String key used to brand snapshot types.\n * Snapshots have SnapshotKindId instead of KindId, making them\n * distinguishable from reactive objects at the type level.\n */\nexport const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;\nexport type SnapshotKindId = typeof SnapshotKindId;\n\n/**\n * Kinds of entities stored in ECHO: objects and relations.\n */\nexport enum EntityKind {\n Object = 'object',\n Relation = 'relation',\n}\n\nexport const EntityKindSchema = Schema.Enums(EntityKind);\n\n/**\n * Typename for generic object references (Type.Obj / Ref.Ref(Obj.Unknown)).\n * Used when referencing any object without a specific schema.\n */\nexport const ANY_OBJECT_TYPENAME = 'org.dxos.schema.anyObject';\n\n/**\n * Version for generic object references.\n */\nexport const ANY_OBJECT_VERSION = '0.0.0';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN } from '@dxos/keys';\n\nimport { EntityKind } from '../common/types';\n\nexport interface AnnotationHelper<T> {\n /**\n * Get the annotation value from the schema.\n */\n get: (schema: Schema.Schema.Any) => Option.Option<T>;\n /**\n * Get the annotation value from the AST.\n */\n getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;\n /**\n * Set the annotation value on the schema.\n */\n set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;\n}\n\n/**\n * Note: only for system annotations.\n */\n// TODO(dmaretskyi): Rename to createSystemAnnotationHelper.\nexport const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {\n return {\n get: (schema) => SchemaAST.getAnnotation(schema.ast, id),\n getFromAst: (ast) => SchemaAST.getAnnotation(ast, id),\n set:\n (value) =>\n <S extends Schema.Schema.Any>(schema: S) =>\n schema.annotations({ [id]: value }) as S,\n };\n};\n\n/**\n * If property is optional returns the nested property, otherwise returns the property.\n */\n// TODO(wittjosiah): Is there a way to do this as a generic?\nexport const unwrapOptional = (property: SchemaAST.PropertySignature) => {\n if (!property.isOptional || !SchemaAST.isUnion(property.type)) {\n return property;\n }\n\n return property.type.types[0];\n};\n\n/**\n * @see JSONSchemaAnnotationId\n * @returns JSON-schema annotation so that the schema can be serialized with correct parameters.\n */\n// TODO(burdon): Required type.\nexport const makeTypeJsonSchemaAnnotation = (options: {\n identifier?: string;\n kind: EntityKind;\n typename: string;\n version: string;\n relationSource?: string;\n relationTarget?: string;\n}) => {\n assertArgument(!!options.relationSource === (options.kind === EntityKind.Relation), 'relationSource');\n assertArgument(!!options.relationTarget === (options.kind === EntityKind.Relation), 'relationTarget');\n\n const obj = {\n // TODO(dmaretskyi): Should this include the version?\n $id: options.identifier ?? DXN.fromTypename(options.typename).toString(),\n entityKind: options.kind,\n version: options.version,\n typename: options.typename,\n } as any;\n if (options.kind === EntityKind.Relation) {\n obj.relationSource = { $ref: options.relationSource };\n obj.relationTarget = { $ref: options.relationTarget };\n }\n\n return obj;\n};\n"],
|
|
5
5
|
"mappings": ";AAIA,YAAYA,YAAY;AAYjB,IAAMC,SAAS;AAOf,IAAMC,eAAe;AAQrB,IAAMC,iBAAiB;AAMvB,IAAKC,aAAAA,0BAAAA,aAAAA;;;SAAAA;;AAKL,IAAMC,mBAA0BC,aAAMF,UAAAA;AAMtC,IAAMG,sBAAsB;AAK5B,IAAMC,qBAAqB;;;AC/ClC,YAAYC,eAAe;AAE3B,SAASC,sBAAsB;AAC/B,SAASC,WAAW;AAuBb,IAAMC,yBAAyB,CAAIC,OAAAA;AACxC,SAAO;IACLC,KAAK,CAACC,WAAqBC,wBAAcD,OAAOE,KAAKJ,EAAAA;IACrDK,YAAY,CAACD,QAAkBD,wBAAcC,KAAKJ,EAAAA;IAClDM,KACE,CAACC,UACD,CAA8BL,WAC5BA,OAAOM,YAAY;MAAE,CAACR,EAAAA,GAAKO;IAAM,CAAA;EACvC;AACF;AAMO,IAAME,iBAAiB,CAACC,aAAAA;AAC7B,MAAI,CAACA,SAASC,cAAc,CAAWC,kBAAQF,SAASG,IAAI,GAAG;AAC7D,WAAOH;EACT;AAEA,SAAOA,SAASG,KAAKC,MAAM,CAAA;AAC7B;AAOO,IAAMC,+BAA+B,CAACC,YAAAA;AAQ3CC,iBAAe,CAAC,CAACD,QAAQE,oBAAoBF,QAAQG,SAASC,WAAWC,WAAW,gBAAA;AACpFJ,iBAAe,CAAC,CAACD,QAAQM,oBAAoBN,QAAQG,SAASC,WAAWC,WAAW,gBAAA;AAEpF,QAAME,MAAM;;IAEVC,KAAKR,QAAQS,cAAcC,IAAIC,aAAaX,QAAQY,QAAQ,EAAEC,SAAQ;IACtEC,YAAYd,QAAQG;IACpBY,SAASf,QAAQe;IACjBH,UAAUZ,QAAQY;EACpB;AACA,MAAIZ,QAAQG,SAASC,WAAWC,UAAU;AACxCE,QAAIL,iBAAiB;MAAEc,MAAMhB,QAAQE;IAAe;AACpDK,QAAID,iBAAiB;MAAEU,MAAMhB,QAAQM;IAAe;EACtD;AAEA,SAAOC;AACT;",
|
|
6
6
|
"names": ["Schema", "KindId", "SchemaKindId", "SnapshotKindId", "EntityKind", "EntityKindSchema", "Enums", "ANY_OBJECT_TYPENAME", "ANY_OBJECT_VERSION", "SchemaAST", "assertArgument", "DXN", "createAnnotationHelper", "id", "get", "schema", "getAnnotation", "ast", "getFromAst", "set", "value", "annotations", "unwrapOptional", "property", "isOptional", "isUnion", "type", "types", "makeTypeJsonSchemaAnnotation", "options", "assertArgument", "relationSource", "kind", "EntityKind", "Relation", "relationTarget", "obj", "$id", "identifier", "DXN", "fromTypename", "typename", "toString", "entityKind", "version", "$ref"]
|
|
7
7
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RefArray
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-APHSOTIX.mjs";
|
|
4
4
|
import {
|
|
5
5
|
Ref,
|
|
6
6
|
getSchemaReference
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-BMB7IHGB.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -15,6 +15,7 @@ __export(Ref_exports, {
|
|
|
15
15
|
Array: () => Array,
|
|
16
16
|
Ref: () => Ref2,
|
|
17
17
|
fromDXN: () => fromDXN,
|
|
18
|
+
hasObjectId: () => hasObjectId,
|
|
18
19
|
isRef: () => isRef,
|
|
19
20
|
isRefType: () => isRefType,
|
|
20
21
|
make: () => make
|
|
@@ -26,6 +27,7 @@ var Array = RefArray;
|
|
|
26
27
|
var isRef = Ref.isRef;
|
|
27
28
|
var make = Ref.make;
|
|
28
29
|
var fromDXN = Ref.fromDXN;
|
|
30
|
+
var hasObjectId = Ref.hasObjectId;
|
|
29
31
|
var isRefType = (ast) => {
|
|
30
32
|
return SchemaAST.getAnnotation(ast, SchemaAST.JSONSchemaAnnotationId).pipe(Option.flatMap((jsonSchema) => "$id" in jsonSchema ? Option.some(jsonSchema) : Option.none()), Option.flatMap((jsonSchema) => {
|
|
31
33
|
const { typename } = getSchemaReference(jsonSchema) ?? {};
|
|
@@ -39,7 +41,8 @@ export {
|
|
|
39
41
|
isRef,
|
|
40
42
|
make,
|
|
41
43
|
fromDXN,
|
|
44
|
+
hasObjectId,
|
|
42
45
|
isRefType,
|
|
43
46
|
Ref_exports
|
|
44
47
|
};
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-N7VOEPSV.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Ref.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport type * as Entity from './Entity';\nimport * as refInternal from './internal/Ref';\nimport type * as JsonSchema from './JsonSchema';\nimport type * as Obj from './Obj';\n\n/**\n * Instance type for a reference.\n *\n * Reference can point to any object or relation.\n * References are lazy loaded.\n *\n * `ref.dxn` is the DXN of the referenced object.\n *\n * @example\n * ```ts\n * const taskRef: Ref<Task> = Ref.make(task);\n *\n * await taskRef.load(); // Returns Promise<Task>\n * yield* Database.load(taskRef); // Effectful version.\n *\n * database.makeRef(dxn); // Create a ref from a DXN.\n * ```\n */\nexport type Ref<T> = refInternal.Ref<T>;\nexport type Unknown = refInternal.Ref<Obj.Unknown>;\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: Ref.Ref(Person), // Creates a Ref schema\n * }).pipe(Type.object({ typename: 'Task', version: '0.1.0' }));\n * ```\n */\nexport const Ref: <S extends Schema.Schema.Any>(schema: S) => RefSchema<Schema.Schema.Type<S>> = refInternal.Ref;\n\nexport const Array = refInternal.RefArray;\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: Ref.RefSchema<typeof Task> = Ref.Ref(Task);\n *\n * // Instance type annotation (use Ref.Ref instead):\n * const refInstance: Ref.Ref<Task> = Ref.make(task);\n * ```\n */\n// TODO(dmaretskyi): Investigate if we can remove this type.\n// Post DX-836 it will become just `Schema.Schema<Ref.Ref<T>>`.\n// NOTE: This could be Type.Ref<T> instead, but since it going to be removed, it's better to keep it here, self-contained.\nexport interface RefSchema<T extends Entity.Unknown> extends refInternal.RefSchema<T> {}\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Unknown> = R extends refInternal.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = refInternal.RefResolver;\n\nexport const isRef: (value: unknown) => value is Unknown = refInternal.Ref.isRef;\n\nexport const make = refInternal.Ref.make;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = refInternal.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 } = refInternal.getSchemaReference(jsonSchema) ?? {};\n return typename ? Option.some(true) : Option.some(false);\n }),\n Option.getOrElse(() => false),\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAAA;;;aAAAA;EAAA
|
|
6
|
-
"names": ["Ref", "Option", "SchemaAST", "Ref", "Array", "RefArray", "isRef", "make", "fromDXN", "isRefType", "ast", "getAnnotation", "JSONSchemaAnnotationId", "pipe", "flatMap", "jsonSchema", "some", "none", "typename", "getSchemaReference", "getOrElse"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport type * as Entity from './Entity';\nimport * as refInternal from './internal/Ref';\nimport type * as JsonSchema from './JsonSchema';\nimport type * as Obj from './Obj';\n\n/**\n * Instance type for a reference.\n *\n * Reference can point to any object or relation.\n * References are lazy loaded.\n *\n * `ref.dxn` is the DXN of the referenced object.\n *\n * @example\n * ```ts\n * const taskRef: Ref<Task> = Ref.make(task);\n *\n * await taskRef.load(); // Returns Promise<Task>\n * yield* Database.load(taskRef); // Effectful version.\n *\n * database.makeRef(dxn); // Create a ref from a DXN.\n * ```\n */\nexport type Ref<T> = refInternal.Ref<T>;\nexport type Unknown = refInternal.Ref<Obj.Unknown>;\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: Ref.Ref(Person), // Creates a Ref schema\n * }).pipe(Type.object({ typename: 'Task', version: '0.1.0' }));\n * ```\n */\nexport const Ref: <S extends Schema.Schema.Any>(schema: S) => RefSchema<Schema.Schema.Type<S>> = refInternal.Ref;\n\nexport const Array = refInternal.RefArray;\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: Ref.RefSchema<typeof Task> = Ref.Ref(Task);\n *\n * // Instance type annotation (use Ref.Ref instead):\n * const refInstance: Ref.Ref<Task> = Ref.make(task);\n * ```\n */\n// TODO(dmaretskyi): Investigate if we can remove this type.\n// Post DX-836 it will become just `Schema.Schema<Ref.Ref<T>>`.\n// NOTE: This could be Type.Ref<T> instead, but since it going to be removed, it's better to keep it here, self-contained.\nexport interface RefSchema<T extends Entity.Unknown> extends refInternal.RefSchema<T> {}\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Unknown> = R extends refInternal.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = refInternal.RefResolver;\n\nexport const isRef: (value: unknown) => value is Unknown = refInternal.Ref.isRef;\n\nexport const make = refInternal.Ref.make;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept DXN.\nexport const fromDXN = refInternal.Ref.fromDXN;\n\nexport const hasObjectId = refInternal.Ref.hasObjectId;\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 } = refInternal.getSchemaReference(jsonSchema) ?? {};\n return typename ? Option.some(true) : Option.some(false);\n }),\n Option.getOrElse(() => false),\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAAA;;;aAAAA;EAAA;;;;;;AAMA,YAAYC,YAAY;AAExB,YAAYC,eAAe;AAuCpB,IAAMC,OAAgGA;AAEtG,IAAMC,QAAoBC;AA+B1B,IAAMC,QAA0DH,IAAIG;AAEpE,IAAMC,OAAmBJ,IAAII;AAG7B,IAAMC,UAAsBL,IAAIK;AAEhC,IAAMC,cAA0BN,IAAIM;AAGpC,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,IAAiBC,mBAAmBJ,UAAAA,KAAe,CAAC;AACpE,WAAOG,WAAkBF,YAAK,IAAA,IAAeA,YAAK,KAAA;EACpD,CAAA,GACOI,iBAAU,MAAM,KAAA,CAAA;AAE3B;",
|
|
6
|
+
"names": ["Ref", "Option", "SchemaAST", "Ref", "Array", "RefArray", "isRef", "make", "fromDXN", "hasObjectId", "isRefType", "ast", "getAnnotation", "JSONSchemaAnnotationId", "pipe", "flatMap", "jsonSchema", "some", "none", "typename", "getSchemaReference", "getOrElse"]
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
JsonSchemaType,
|
|
3
3
|
toEffectSchema,
|
|
4
4
|
toJsonSchema
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MLS7U7AT.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__export
|
|
8
8
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -24,4 +24,4 @@ export {
|
|
|
24
24
|
JsonSchema,
|
|
25
25
|
JsonSchema_exports
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-QRZ2I3ZM.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EntityKind,
|
|
3
3
|
createAnnotationHelper
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-N4B7FHQT.mjs";
|
|
5
5
|
|
|
6
6
|
// src/internal/common/types/typename.ts
|
|
7
7
|
var ATTR_TYPE = "@type";
|
|
@@ -58,8 +58,8 @@ var getTypeDXNFromSpecifier = (input) => {
|
|
|
58
58
|
return DXN.fromTypename(input);
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
var TypenameSchema = Schema.String.pipe(Schema.pattern(/^[a-
|
|
62
|
-
description: "Fully qualified globally unique typename in
|
|
61
|
+
var TypenameSchema = Schema.String.pipe(Schema.pattern(/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/)).annotations({
|
|
62
|
+
description: "Fully qualified globally unique typename in reverse-DNS form.",
|
|
63
63
|
example: "org.dxos.type.message"
|
|
64
64
|
});
|
|
65
65
|
var VersionSchema = Schema.String.pipe(Schema.pattern(/^\d+.\d+.\d+$/)).annotations({
|
|
@@ -101,15 +101,7 @@ var getTypename = (obj) => {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
var setTypename = (obj, typename) => {
|
|
104
|
-
invariant(typename instanceof DXN, "Invalid type.", {
|
|
105
|
-
F: __dxlog_file,
|
|
106
|
-
L: 199,
|
|
107
|
-
S: void 0,
|
|
108
|
-
A: [
|
|
109
|
-
"typename instanceof DXN",
|
|
110
|
-
"'Invalid type.'"
|
|
111
|
-
]
|
|
112
|
-
});
|
|
104
|
+
invariant(typename instanceof DXN, "Invalid type.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 136, S: void 0, A: ["typename instanceof DXN", "'Invalid type.'"] });
|
|
113
105
|
Object.defineProperty(obj, TypeId, {
|
|
114
106
|
value: typename,
|
|
115
107
|
writable: false,
|
|
@@ -125,15 +117,7 @@ var getTypeDXN = (obj) => {
|
|
|
125
117
|
if (!type) {
|
|
126
118
|
return void 0;
|
|
127
119
|
}
|
|
128
|
-
invariant(type instanceof DXN, "Invalid object.", {
|
|
129
|
-
F: __dxlog_file,
|
|
130
|
-
L: 226,
|
|
131
|
-
S: void 0,
|
|
132
|
-
A: [
|
|
133
|
-
"type instanceof DXN",
|
|
134
|
-
"'Invalid object.'"
|
|
135
|
-
]
|
|
136
|
-
});
|
|
120
|
+
invariant(type instanceof DXN, "Invalid object.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 159, S: void 0, A: ["type instanceof DXN", "'Invalid object.'"] });
|
|
137
121
|
return type;
|
|
138
122
|
};
|
|
139
123
|
var isInstanceOf = (schema, object) => {
|
|
@@ -186,7 +170,13 @@ var getLabelWithSchema = (schema, object) => {
|
|
|
186
170
|
assertArgument(typeof accessor === "string", "accessor", "Label annotation must be a string or an array of strings");
|
|
187
171
|
const value = getField(object, accessor);
|
|
188
172
|
switch (typeof value) {
|
|
189
|
-
case "string":
|
|
173
|
+
case "string": {
|
|
174
|
+
const trimmed = value.trim();
|
|
175
|
+
if (trimmed.length > 0) {
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
190
180
|
case "number":
|
|
191
181
|
case "boolean":
|
|
192
182
|
case "bigint":
|
|
@@ -235,7 +225,7 @@ var GeneratorAnnotationId = /* @__PURE__ */ Symbol.for("@dxos/schema/annotation/
|
|
|
235
225
|
var GeneratorAnnotation = createAnnotationHelper(GeneratorAnnotationId);
|
|
236
226
|
var makeUserAnnotation = (props) => {
|
|
237
227
|
assertArgument(/^[a-z][a-z0-9]*(\.[a-z][a-z0-9-]*){2,}$/.test(props.id), "id", "Annotation id must be in the FQN format (org.dxos.annotation.example).");
|
|
238
|
-
const getFromAst = (ast) => SchemaAST.getAnnotation(PropertyMetaAnnotationId)(ast).pipe(Option.
|
|
228
|
+
const getFromAst = (ast) => SchemaAST.getAnnotation(PropertyMetaAnnotationId)(ast).pipe(Option.flatMap((meta) => Option.fromNullable(meta[props.id])), Option.map(Schema.decodeUnknownSync(props.schema)));
|
|
239
229
|
return {
|
|
240
230
|
get: (schema) => getFromAst(schema.ast),
|
|
241
231
|
getFromAst: (ast) => getFromAst(ast),
|
|
@@ -272,6 +262,10 @@ var IconAnnotation = makeUserAnnotation({
|
|
|
272
262
|
id: "org.dxos.annotation.icon",
|
|
273
263
|
schema: IconAnnotationSchema
|
|
274
264
|
});
|
|
265
|
+
var IconFromRefAnnotation = makeUserAnnotation({
|
|
266
|
+
id: "org.dxos.annotation.icon.from-ref",
|
|
267
|
+
schema: Schema.String
|
|
268
|
+
});
|
|
275
269
|
var getLabel = (entity) => {
|
|
276
270
|
const schema = getSchema(entity);
|
|
277
271
|
if (schema != null) {
|
|
@@ -347,9 +341,10 @@ export {
|
|
|
347
341
|
GeneratorAnnotation,
|
|
348
342
|
makeUserAnnotation,
|
|
349
343
|
IconAnnotation,
|
|
344
|
+
IconFromRefAnnotation,
|
|
350
345
|
getLabel,
|
|
351
346
|
setLabel,
|
|
352
347
|
getDescription,
|
|
353
348
|
setDescription
|
|
354
349
|
};
|
|
355
|
-
//# sourceMappingURL=chunk-
|
|
350
|
+
//# sourceMappingURL=chunk-TNBK56IN.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/common/types/typename.ts", "../../../src/internal/Annotation/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 Mutable } from '../common/proxy';\nimport { type AnyProperties, EntityKind, TypeId, getSchema } from '../common/types';\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: `org.dxos.type.message`\n */\n// TODO(wittjosiah): Factor out to DXN spec.\nexport const TypenameSchema = Schema.String.pipe(\n Schema.pattern(\n /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/,\n ),\n).annotations({\n description: 'Fully qualified globally unique typename in reverse-DNS form.',\n example: 'org.dxos.type.message',\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 \"org.example.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:com.example.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 * Skips empty strings and whitespace-only strings, continuing to the next field.\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 const trimmed = value.trim();\n if (trimmed.length > 0) {\n return value;\n }\n continue;\n }\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 */\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-z][a-z0-9]*(\\.[a-z][a-z0-9-]*){2,}$/.test(props.id),\n 'id',\n 'Annotation id must be in the FQN format (org.dxos.annotation.example).',\n );\n\n const getFromAst = (ast: SchemaAST.AST) =>\n SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(\n Option.flatMap((meta) => Option.fromNullable(meta[props.id])),\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) => S,\n };\n};\n\nconst IconAnnotationSchema = Schema.Struct({\n /**\n * Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)\n */\n icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),\n\n /**\n * Color name.\n *\n * List of colors:\n * - 'red'\n * - 'orange'\n * - 'amber'\n * - 'yellow'\n * - 'lime'\n * - 'green'\n * - 'emerald'\n * - 'teal'\n * - 'cyan'\n * - 'violet'\n * - 'purple'\n * - 'fuchsia'\n * - 'pink'\n * - 'rose'\n */\n\n hue: Schema.optional(Schema.String),\n});\n\nexport interface IconAnnotation extends Schema.Schema.Type<typeof IconAnnotationSchema> {}\n\n/**\n * Icon to render in the UI.\n */\nexport const IconAnnotation = makeUserAnnotation<IconAnnotation>({\n id: 'org.dxos.annotation.icon',\n schema: IconAnnotationSchema,\n});\n\n/**\n * Indicates that this entity's icon should be resolved from a property whose value is a `Ref`\n * to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that\n * target's schema `IconAnnotation` in place of the static one declared on this schema.\n *\n * Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity\n * (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).\n */\nexport const IconFromRefAnnotation = makeUserAnnotation<string>({\n id: 'org.dxos.annotation.icon.from-ref',\n schema: Schema.String,\n});\n\n/**\n * Get the label of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getLabel = (entity: AnyProperties): string | undefined => {\n const schema = getSchema(entity);\n if (schema != null) {\n return getLabelWithSchema(schema, entity);\n }\n};\n\n/**\n * Set the label of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setLabel = (entity: Mutable<AnyProperties>, label: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setLabelWithSchema(schema, entity, label);\n }\n};\n\n/**\n * Get the description of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDescription = (entity: AnyProperties): string | undefined => {\n const schema = getSchema(entity);\n if (schema != null) {\n return getDescriptionWithSchema(schema, entity);\n }\n};\n\n/**\n * Set the description of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setDescription = (entity: Mutable<AnyProperties>, description: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setDescriptionWithSchema(schema, entity, description);\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;AASO,IAAMA,YAAY;AAKlB,IAAMC,SAASC,uBAAOC,IAAI,iBAAA;AAK1B,IAAMC,WAAWF,uBAAOC,IAAI,mBAAA;AAK5B,IAAME,cAAc;AAKpB,IAAMC,WAAWJ,uBAAOC,IAAI,mBAAA;AAS5B,IAAMI,YAAY,CAACC,QAAAA;AACxB,MAAIA,KAAK;AACP,WAAQA,IAAYJ,QAAAA;EACtB;AACF;AAKO,IAAM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AQmC,iBAAAA,mBAAAA;EACP,IAAA;EAEH,QAAA;;AAUEnC,IAAQoC,wBAAa,mBAAA;EACpB,IAAA;EAEH,QAAA;;AAMMpC,IAAAA,WAAgB,CAAA,WAAA;QAClB,SAAOqC,UAAAA,MAAmBrC;AAC5B,MAAA,UAAA,MAAA;AACA,WAAA,mBAAA,QAAA,MAAA;EAEF;;AAMMA,IAAAA,WAAgB,CAAA,QAAA,UAAA;QAClBsC,SAAAA,UAAmBtC,MAAQuC;AAC7B,MAAA,UAAA,MAAA;AACA,uBAAA,QAAA,QAAA,KAAA;EAEF;;AAMMvC,IAAAA,iBAAgB,CAAA,WAAA;QAClB,SAAOwC,UAAAA,MAAAA;AACT,MAAA,UAAA,MAAA;AACA,WAAA,yBAAA,QAAA,MAAA;EAEF;;AAMMxC,IAAAA,iBAAgB,CAAA,QAAA,gBAAA;QAClByC,SAAAA,UAAAA,MAAyBzC;AAC3B,MAAA,UAAA,MAAA;AACA,6BAAA,QAAA,QAAA,WAAA;;;",
|
|
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", "id", "getTypeIdentifierAnnotation", "DXN", "undefined", "fromTypenameAndVersion", "getSchemaDXN", "raise", "TypeError", "assertArgument", "input", "fromTypename", "example", "TypeMeta", "version", "VersionSchema", "Function", "getAnnotation", "schema", "getSchemaTypename", "type", "obj", "Object", "defineProperty", "TypeId", "value", "typename", "writable", "enumerable", "configurable", "invariant", "schemaDXN", "Error", "getTypeDXN", "object", "typeDXN", "existingMeta", "self", "ast", "annotations", "PropertyMetaAnnotationId", "getField", "annotation", "label", "accessor", "description", "makeUserAnnotation", "props", "getFromAst", "SchemaAST", "get", "set", "PropertyMeta", "IconAnnotationSchema", "Schema", "getLabelWithSchema", "setLabelWithSchema", "entity", "getDescriptionWithSchema", "setDescriptionWithSchema"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAnnotationHelper
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-N4B7FHQT.mjs";
|
|
4
4
|
|
|
5
5
|
// src/internal/Format/types.ts
|
|
6
6
|
import * as Function from "effect/Function";
|
|
@@ -399,4 +399,4 @@ export {
|
|
|
399
399
|
Format,
|
|
400
400
|
SelectOption
|
|
401
401
|
};
|
|
402
|
-
//# sourceMappingURL=chunk-
|
|
402
|
+
//# sourceMappingURL=chunk-TRPZU2HV.mjs.map
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Feed,
|
|
2
3
|
getQueueDxn
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IVSI7QO6.mjs";
|
|
4
5
|
import {
|
|
5
6
|
everything,
|
|
6
7
|
is,
|
|
7
8
|
props,
|
|
8
9
|
type
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HKETO4L4.mjs";
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
getDXN,
|
|
13
|
+
getTypename,
|
|
14
|
+
instanceOf
|
|
15
|
+
} from "./chunk-X3356HPV.mjs";
|
|
16
|
+
import {
|
|
17
|
+
prettyQuery
|
|
18
|
+
} from "./chunk-Z5GKP74O.mjs";
|
|
13
19
|
import {
|
|
14
20
|
isDatabase
|
|
15
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-I2DARWPX.mjs";
|
|
16
22
|
import {
|
|
17
23
|
getTypeDXNFromSpecifier
|
|
18
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-TNBK56IN.mjs";
|
|
19
25
|
import {
|
|
20
26
|
__export
|
|
21
27
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -27,6 +33,7 @@ __export(Query_exports, {
|
|
|
27
33
|
from: () => from,
|
|
28
34
|
fromAst: () => fromAst,
|
|
29
35
|
is: () => is2,
|
|
36
|
+
pretty: () => pretty,
|
|
30
37
|
select: () => select,
|
|
31
38
|
type: () => type2,
|
|
32
39
|
without: () => without
|
|
@@ -128,6 +135,9 @@ var QueryClass = class _QueryClass {
|
|
|
128
135
|
});
|
|
129
136
|
}
|
|
130
137
|
from(arg, options) {
|
|
138
|
+
if (arg == null) {
|
|
139
|
+
throw new TypeError('Query.from() requires a valid data source argument (database, feed, query, scope, or "all-accessible-spaces").');
|
|
140
|
+
}
|
|
131
141
|
if (is2(arg)) {
|
|
132
142
|
return new _QueryClass({
|
|
133
143
|
type: "from",
|
|
@@ -146,7 +156,7 @@ var QueryClass = class _QueryClass {
|
|
|
146
156
|
_tag: "scope",
|
|
147
157
|
scope: {
|
|
148
158
|
...options?.includeFeeds ? {
|
|
149
|
-
|
|
159
|
+
allFeedsFromSpaces: true
|
|
150
160
|
} : {}
|
|
151
161
|
}
|
|
152
162
|
}
|
|
@@ -175,7 +185,7 @@ var QueryClass = class _QueryClass {
|
|
|
175
185
|
scope: {
|
|
176
186
|
spaceIds: databases.map((db) => db.spaceId),
|
|
177
187
|
...options?.includeFeeds ? {
|
|
178
|
-
|
|
188
|
+
allFeedsFromSpaces: true
|
|
179
189
|
} : {}
|
|
180
190
|
}
|
|
181
191
|
}
|
|
@@ -189,13 +199,19 @@ var QueryClass = class _QueryClass {
|
|
|
189
199
|
if (typename === "org.dxos.type.collection") {
|
|
190
200
|
throw new Error("Query.from(collection) is not yet supported.");
|
|
191
201
|
}
|
|
202
|
+
for (const item of items) {
|
|
203
|
+
if (!instanceOf(Feed, item)) {
|
|
204
|
+
throw new TypeError(`Query.from() expects Feed objects (org.dxos.type.feed), but received an object with typename '${typename ?? "unknown"}'.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
192
207
|
}
|
|
193
|
-
const
|
|
194
|
-
const
|
|
208
|
+
const feedItems = items;
|
|
209
|
+
const feedDXNs = feedItems.map((feed) => {
|
|
195
210
|
const dxn = getQueueDxn(feed);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
211
|
+
if (!dxn) {
|
|
212
|
+
throw new TypeError(`Query.from() expects persisted Feed objects with a queue DXN; got feed without a space (id=${getDXN(feed).toString()}).`);
|
|
213
|
+
}
|
|
214
|
+
return dxn.toString();
|
|
199
215
|
});
|
|
200
216
|
return new _QueryClass({
|
|
201
217
|
type: "from",
|
|
@@ -203,7 +219,7 @@ var QueryClass = class _QueryClass {
|
|
|
203
219
|
from: {
|
|
204
220
|
_tag: "scope",
|
|
205
221
|
scope: {
|
|
206
|
-
|
|
222
|
+
feeds: feedDXNs
|
|
207
223
|
}
|
|
208
224
|
}
|
|
209
225
|
});
|
|
@@ -215,6 +231,25 @@ var QueryClass = class _QueryClass {
|
|
|
215
231
|
options
|
|
216
232
|
});
|
|
217
233
|
}
|
|
234
|
+
debugLabel(label) {
|
|
235
|
+
if (this.ast.type === "options") {
|
|
236
|
+
return new _QueryClass({
|
|
237
|
+
type: "options",
|
|
238
|
+
query: this.ast.query,
|
|
239
|
+
options: {
|
|
240
|
+
...this.ast.options,
|
|
241
|
+
debugLabel: label
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return new _QueryClass({
|
|
246
|
+
type: "options",
|
|
247
|
+
query: this.ast,
|
|
248
|
+
options: {
|
|
249
|
+
debugLabel: label
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
218
253
|
};
|
|
219
254
|
var is2 = (value) => {
|
|
220
255
|
return typeof value === "object" && value !== null && "~Query" in value;
|
|
@@ -260,8 +295,8 @@ var from = (source, options) => {
|
|
|
260
295
|
};
|
|
261
296
|
var SCOPE_KEYS = /* @__PURE__ */ new Set([
|
|
262
297
|
"spaceIds",
|
|
263
|
-
"
|
|
264
|
-
"
|
|
298
|
+
"feeds",
|
|
299
|
+
"allFeedsFromSpaces"
|
|
265
300
|
]);
|
|
266
301
|
var _isScope = (value) => {
|
|
267
302
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
@@ -269,6 +304,7 @@ var _isScope = (value) => {
|
|
|
269
304
|
}
|
|
270
305
|
return Object.keys(value).every((key) => SCOPE_KEYS.has(key));
|
|
271
306
|
};
|
|
307
|
+
var pretty = (query) => prettyQuery(query.ast);
|
|
272
308
|
|
|
273
309
|
export {
|
|
274
310
|
is2 as is,
|
|
@@ -278,6 +314,7 @@ export {
|
|
|
278
314
|
all,
|
|
279
315
|
without,
|
|
280
316
|
from,
|
|
317
|
+
pretty,
|
|
281
318
|
Query_exports
|
|
282
319
|
};
|
|
283
|
-
//# sourceMappingURL=chunk-
|
|
320
|
+
//# sourceMappingURL=chunk-VW42HESL.mjs.map
|