@dxos/echo 0.8.4-main.422d1c7879 → 0.8.4-main.4f23b4e393
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/lib/neutral/Annotation.mjs +5 -3
- package/dist/lib/neutral/Database.mjs +4 -4
- package/dist/lib/neutral/Entity.mjs +14 -14
- package/dist/lib/neutral/Err.mjs +1 -1
- package/dist/lib/neutral/Extension.mjs +1 -1
- package/dist/lib/neutral/Feed.mjs +19 -17
- package/dist/lib/neutral/Filter.mjs +11 -11
- 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 +10 -10
- package/dist/lib/neutral/Obj.mjs +14 -14
- package/dist/lib/neutral/Order.mjs +1 -1
- package/dist/lib/neutral/Query.mjs +17 -17
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +9 -7
- package/dist/lib/neutral/Relation.mjs +15 -15
- package/dist/lib/neutral/SchemaRegistry.mjs +1 -1
- package/dist/lib/neutral/Tag.mjs +14 -14
- package/dist/lib/neutral/Type.mjs +10 -10
- package/dist/lib/neutral/{chunk-GZQTCRJB.mjs → chunk-44HT3MEC.mjs} +2 -2
- package/dist/lib/neutral/{chunk-4P3IXBLT.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-A2WIDONZ.mjs → chunk-AHWSAJHU.mjs} +6 -22
- package/dist/lib/neutral/{chunk-A2WIDONZ.mjs.map → chunk-AHWSAJHU.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-XEU2Q5CI.mjs → chunk-APHSOTIX.mjs} +2 -2
- package/dist/lib/neutral/{chunk-BNCCGLJN.mjs → chunk-BICZKPQG.mjs} +1 -1
- package/dist/lib/neutral/{chunk-JPWH3QJD.mjs → chunk-BMB7IHGB.mjs} +10 -66
- package/dist/lib/neutral/{chunk-JPWH3QJD.mjs.map → chunk-BMB7IHGB.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-EJJFH3XB.mjs → chunk-C6LDQTNO.mjs} +10 -10
- package/dist/lib/neutral/chunk-C6LDQTNO.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-GMYNDEMT.mjs → chunk-GKBXQFQK.mjs} +11 -27
- package/dist/lib/neutral/{chunk-GMYNDEMT.mjs.map → chunk-GKBXQFQK.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-YS6Q3XAD.mjs → chunk-GWFFC34K.mjs} +1 -1
- package/dist/lib/neutral/{chunk-YS6Q3XAD.mjs.map → chunk-GWFFC34K.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-PHU22NLC.mjs → chunk-I2DARWPX.mjs} +4 -12
- package/dist/lib/neutral/chunk-I2DARWPX.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-RP37BQF7.mjs → chunk-KBZ4RAXR.mjs} +20 -16
- package/dist/lib/neutral/chunk-KBZ4RAXR.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-QW7YUKSA.mjs → chunk-MLS7U7AT.mjs} +12 -65
- package/dist/lib/neutral/{chunk-QW7YUKSA.mjs.map → chunk-MLS7U7AT.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-TBKX6JQO.mjs → chunk-N4B7FHQT.mjs} +1 -1
- package/dist/lib/neutral/{chunk-H5F7C2UO.mjs → chunk-N7VOEPSV.mjs} +6 -3
- package/dist/lib/neutral/{chunk-H5F7C2UO.mjs.map → chunk-N7VOEPSV.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-ZUGFUCUK.mjs → chunk-NWXJZVWD.mjs} +8 -8
- package/dist/lib/neutral/{chunk-ZUGFUCUK.mjs.map → chunk-NWXJZVWD.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-JIN4EVUK.mjs → chunk-OMJN6VCR.mjs} +4 -4
- package/dist/lib/neutral/{chunk-EULNZHTP.mjs → chunk-PHOHAIEE.mjs} +4 -4
- package/dist/lib/neutral/{chunk-7I3YIAT2.mjs → chunk-QRZ2I3ZM.mjs} +2 -2
- package/dist/lib/neutral/{chunk-6ASBHRDG.mjs → chunk-SRX3EZY3.mjs} +38 -17
- package/dist/lib/neutral/chunk-SRX3EZY3.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-WAK4DMFV.mjs → chunk-SUZMWP3Y.mjs} +2 -2
- package/dist/lib/neutral/{chunk-2KHZ36F5.mjs → chunk-TNBK56IN.mjs} +10 -21
- package/dist/lib/neutral/{chunk-2KHZ36F5.mjs.map → chunk-TNBK56IN.mjs.map} +3 -3
- package/dist/lib/neutral/{chunk-DQYLD2RB.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-O26EPPBW.mjs → chunk-W7U2XGZ3.mjs} +11 -19
- package/dist/lib/neutral/{chunk-O26EPPBW.mjs.map → chunk-W7U2XGZ3.mjs.map} +3 -3
- 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/{chunk-BQN7EDPH.mjs → chunk-ZVQ26DCR.mjs} +76 -478
- package/dist/lib/neutral/{chunk-BQN7EDPH.mjs.map → chunk-ZVQ26DCR.mjs.map} +3 -3
- package/dist/lib/neutral/index.mjs +28 -28
- package/dist/lib/neutral/internal/index.mjs +11 -9
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +183 -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 +1 -1
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Dataset.d.ts +1 -1
- package/dist/types/src/Entity.d.ts +9 -9
- 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 +4 -4
- package/dist/types/src/Extension.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +37 -13
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/JsonSchema.d.ts +1 -1
- package/dist/types/src/Migration.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +19 -19
- 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 +5 -1
- 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 +15 -15
- 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.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/internal/Annotation/annotations.d.ts +11 -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/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.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.map +1 -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 +1 -1
- 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/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/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 +3 -3
- 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/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 +13 -13
- package/src/Annotation.ts +1 -0
- package/src/Collection.ts +1 -1
- package/src/Database.ts +1 -1
- package/src/Entity.ts +9 -9
- package/src/Extension.ts +3 -3
- package/src/Feed.ts +55 -24
- package/src/Hypergraph.ts +3 -3
- package/src/Obj.test.ts +12 -12
- package/src/Obj.ts +19 -19
- package/src/Query.test.ts +32 -16
- package/src/Query.ts +32 -7
- package/src/Ref.ts +2 -0
- package/src/Relation.ts +15 -15
- package/src/exemplars.test.ts +21 -0
- package/src/internal/Annotation/annotations.ts +16 -3
- package/src/internal/Obj/ids.ts +1 -1
- package/src/internal/Obj/json-serializer.test.ts +1 -1
- package/src/internal/Obj/json-serializer.ts +9 -9
- package/src/internal/Obj/set-value.test.ts +15 -15
- package/src/internal/Obj/set-value.ts +1 -1
- package/src/internal/Query.ts +7 -4
- package/src/internal/Type/echo-schema.ts +1 -1
- 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 +59 -59
- package/src/internal/common/proxy/errors.ts +2 -2
- package/src/internal/common/proxy/reactive-array.ts +1 -1
- package/src/internal/common/proxy/reactive.test.ts +3 -3
- package/src/internal/common/proxy/reactive.ts +1 -1
- package/src/internal/common/proxy/typed-handler.ts +7 -7
- package/src/internal/common/proxy/typed-object.test.ts +1 -1
- package/src/testing/test-data.ts +157 -97
- package/dist/lib/neutral/chunk-4P3IXBLT.mjs.map +0 -7
- package/dist/lib/neutral/chunk-6ASBHRDG.mjs.map +0 -7
- package/dist/lib/neutral/chunk-EJJFH3XB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-PHU22NLC.mjs.map +0 -7
- package/dist/lib/neutral/chunk-RP37BQF7.mjs.map +0 -7
- /package/dist/lib/neutral/{chunk-GZQTCRJB.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-XEU2Q5CI.mjs.map → chunk-APHSOTIX.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-BNCCGLJN.mjs.map → chunk-BICZKPQG.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-TBKX6JQO.mjs.map → chunk-N4B7FHQT.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-JIN4EVUK.mjs.map → chunk-OMJN6VCR.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-EULNZHTP.mjs.map → chunk-PHOHAIEE.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-7I3YIAT2.mjs.map → chunk-QRZ2I3ZM.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-WAK4DMFV.mjs.map → chunk-SUZMWP3Y.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-DQYLD2RB.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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Relation.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { createJsonPath } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, type ObjectId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from './Database';\nimport * as Entity from './Entity';\nimport * as internal from './internal';\nimport * as entityInternal from './internal/Entity';\nimport * as Obj from './Obj';\nimport type * as Type from './Type';\n\nexport type Endpoints<Source, Target> = {\n [Source]: Source;\n [Target]: Target;\n};\n\n/**\n * Base type for all ECHO relations.\n * @private\n */\ninterface BaseRelation<Source, Target>\n extends internal.AnyEntity, Endpoints<Source, Target>, Entity.OfKind<internal.EntityKind.Relation> {}\n\n/**\n * Relation with no known properties beyond id, kind, source, and target.\n * Use this when the relation's schema/properties are not known.\n *\n * NOTE: This is a TypeScript type only, not a schema.\n * To validate that a value is an ECHO relation, use `Relation.isRelation`.\n */\nexport interface Unknown extends BaseRelation<Obj.Unknown, Obj.Unknown> {}\n\n/**\n * Runtime Effect schema for any ECHO relation.\n * Use for validation, parsing, or as a reference target for collections.\n * A relation has `id`, source, and target fields plus any additional properties.\n *\n * NOTE: `Schema.is(Type.Relation)` does STRUCTURAL validation only (checks for `id` field).\n * Use `Relation.isRelation()` for proper ECHO instance type guards that check the KindId brand.\n *\n * @example\n * ```ts\n * // Structural type guard (accepts any object with id field)\n * if (Schema.is(Type.Relation)(unknownValue)) { ... }\n *\n * // ECHO instance type guard (checks KindId brand)\n * if (Relation.isRelation(unknownValue)) { ... }\n * ```\n */\n// TODO(dmaretskyi): Change ObjModule.Any to ObjModule.Unknown to have stricter types.\nexport const Unknown: Type.Relation<Unknown, Obj.Any, Obj.Any> = Schema.Struct({\n id: Schema.String,\n}).pipe(\n Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n // TODO(dmaretskyi): Clean this up.\n // NOTE: The EchoRelationSchema annotation is required for Ref.Ref(Relation.Unknown) to work.\n // The typename/version/source/target only satisfy ECHO schema machinery for reference targets.\n internal.EchoRelationSchema({\n typename: 'org.dxos.schema.anyRelation',\n version: '0.0.0',\n source: Obj.Unknown,\n target: Obj.Unknown,\n }),\n (schema) =>\n Object.assign(schema, {\n [internal.SchemaKindId]: (schema as any)[internal.SchemaKindId],\n }) as unknown as Type.Relation<Unknown, Obj.Any, Obj.Any>,\n);\n\n/**\n * Relation type with specific source and target types.\n */\nexport type OfShape<Source extends Obj.Unknown, Target extends Obj.Unknown, Props> = BaseRelation<Source, Target> &\n Props;\n\n/**\n * Base type for snapshot relations (has SnapshotKindId instead of KindId).\n */\ninterface BaseRelationSnapshot<Source, Target> extends internal.AnyEntity, Endpoints<Source, Target> {\n readonly [Entity.SnapshotKindId]: internal.EntityKind.Relation;\n readonly id: ObjectId;\n}\n\n/**\n * JSON-encoded properties for relations.\n */\nexport interface BaseRelationJson {\n id: string;\n [internal.ATTR_RELATION_SOURCE]: string;\n [internal.ATTR_RELATION_TARGET]: string;\n}\n\n/**\n * Immutable snapshot of an ECHO relation.\n * Branded with SnapshotKindId (not KindId).\n * Property values are frozen at the time the snapshot was created.\n * Returned by getSnapshot() and hooks.\n */\nexport type Snapshot<T extends Unknown = Unknown> = Omit<T, Entity.KindId> &\n BaseRelationSnapshot<Obj.Unknown, Obj.Unknown>;\n\nexport const Source: unique symbol = entityInternal.RelationSourceId as any;\nexport type Source = typeof Source;\n\nexport const Target: unique symbol = entityInternal.RelationTargetId as any;\nexport type Target = typeof Target;\n\n/**\n * Get relation source type.\n */\nexport type SourceOf<A> = A extends Endpoints<infer S, infer _T> ? S : never;\n\n/**\n * Get relation target type.\n */\nexport type TargetOf<A> = A extends Endpoints<infer _S, infer T> ? T : never;\n\n/**\n * Internal props type for relation instance creation.\n */\ntype MakePropsInternal<T extends Unknown> = {\n id?: ObjectId;\n [Meta]?: internal.ObjectMeta;\n [Source]: T[Source];\n [Target]: T[Target];\n} & Entity.Properties<T>;\n\n/**\n * Props type for relation creation with a given schema.\n * Takes a schema type (created with Type.Relation) and extracts the props type.\n */\nexport type MakeProps<S extends Type.AnyRelation> = MakePropsInternal<Schema.Schema.Type<S>>;\n\n/**\n * Creates new relation.\n * @param schema - Relation schema.\n * @param props - Relation properties. Endpoints are passed as [Relation.Source] and [Relation.Target] keys.\n * @param meta - Relation metadata. (deprecated; use [Obj.Meta] instead)\n * @returns\n */\n// NOTE: Writing the definition this way (with generic over schema) makes typescript perfer to infer the type from the first param (this schema) rather than the second param (the props).\n// TODO(dmaretskyi): Move meta into props.\nexport const make = <S extends Type.AnyRelation>(\n schema: S,\n props: NoInfer<MakeProps<S>>,\n): Schema.Schema.Type<S> & Entity.OfKind<typeof Entity.Kind.Relation> => {\n assertArgument(\n internal.getTypeAnnotation(schema)?.kind === internal.EntityKind.Relation,\n 'schema',\n 'Expected a relation schema',\n );\n assertArgument(props[internal.ParentId] === undefined, 'props', 'Parent is not allowed for relations');\n\n let meta: internal.ObjectMeta | undefined = undefined;\n\n if (props[internal.MetaId] != null) {\n meta = props[internal.MetaId] as any;\n delete props[internal.MetaId];\n }\n\n const sourceDXN = internal.getObjectDXN(props[Source]) ?? raise(new Error('Unresolved relation source'));\n const targetDXN = internal.getObjectDXN(props[Target]) ?? raise(new Error('Unresolved relation target'));\n\n (props as any)[internal.RelationSourceDXNId] = sourceDXN;\n (props as any)[internal.RelationTargetDXNId] = targetDXN;\n\n return internal.makeObject<Schema.Schema.Type<S>>(schema, props as any, meta);\n};\n\n/**\n * Type guard for relations.\n * Returns true for both reactive relations and relation snapshots.\n */\nexport const isRelation = (value: unknown): value is Unknown => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (internal.ATTR_RELATION_SOURCE in value || internal.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n // Check for reactive relation (KindId) or snapshot (SnapshotKindId).\n const kind = (value as any)[Entity.KindId] ?? (value as any)[Entity.SnapshotKindId];\n return kind === internal.EntityKind.Relation;\n};\n\nexport const isSnapshot = (value: unknown): value is Snapshot => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[Entity.SnapshotKindId] === internal.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source DXN.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getSourceDXN = (value: Unknown | Snapshot): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(value);\n const dxn = (value as internal.InternalObjectProps)[internal.RelationSourceDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation target DXN.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getTargetDXN = (value: Unknown | Snapshot): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(value);\n const dxn = (value as internal.InternalObjectProps)[internal.RelationTargetDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation source.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Unknown | Snapshot>(relation: T): SourceOf<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(relation);\n const obj = (relation as internal.InternalObjectProps)[internal.RelationSourceId];\n if (obj === undefined) {\n throw new Error(`Relation source could not be resolved.`);\n }\n return obj as SourceOf<T>;\n};\n\n/**\n * @returns Relation target.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Unknown | Snapshot>(relation: T): TargetOf<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(relation);\n const obj = (relation as internal.InternalObjectProps)[internal.RelationTargetId];\n if (obj === undefined) {\n throw new Error(`Relation target could not be resolved.`);\n }\n return obj as TargetOf<T>;\n};\n\n//\n// Change\n//\n\n/**\n * Makes all properties mutable recursively.\n * Used to provide a mutable view of a relation within `Relation.change`.\n */\nexport type Mutable<T> = internal.Mutable<T>;\n\n/**\n * Perform mutations on an echo relation within a controlled context.\n *\n * All mutations within the callback are batched and trigger a single notification\n * when the callback completes. Direct mutations outside of `Relation.change` will throw\n * an error for echo relations.\n *\n * @param relation - The echo relation to mutate. Use `Obj.change` for objects.\n * @param callback - The callback that performs mutations on the relation.\n *\n * @example\n * ```ts\n * const worksFor = Relation.make(EmployedBy, {\n * [Relation.Source]: person,\n * [Relation.Target]: company,\n * role: 'Engineer',\n * });\n *\n * // Mutate within Relation.change\n * Relation.change(worksFor, (obj) => {\n * obj.role = 'Senior Engineer';\n * });\n * ```\n *\n * Note: Only accepts relations. Use `Obj.change` for objects.\n */\nexport const change = <T extends Unknown>(relation: T, callback: internal.ChangeCallback<T>): void => {\n internal.change(relation, callback);\n};\n\n//\n// Snapshot\n//\n\n/**\n * Returns an immutable snapshot of a relation.\n * The snapshot is branded with SnapshotKindId instead of KindId,\n * making it distinguishable from the reactive relation at the type level.\n */\nexport const getSnapshot: <T extends Unknown>(rel: T) => Snapshot<T> = internal.getSnapshot as any;\n\n//\n// Subscribe\n//\n\n/**\n * Subscribe to relation updates.\n * The callback is called synchronously when the relation is modified.\n * Only accepts reactive relations (not snapshots).\n * @returns Unsubscribe function.\n */\nexport const subscribe = (rel: Unknown, callback: () => void): (() => void) => {\n return internal.subscribe(rel, callback);\n};\n\n//\n// Property Access\n//\n\n/**\n * Get a deeply nested property from a relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getValue = (rel: Unknown | Snapshot, path: readonly (string | number)[]): any => {\n return internal.getValue(rel, createJsonPath(path));\n};\n\n/**\n * Set a deeply nested property on a relation.\n * Must be called within a `Relation.change` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setValue: (rel: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =\n internal.setValue as any;\n\n//\n// Type\n//\n\n/**\n * Get the DXN of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getDXN = (entity: Unknown | Snapshot): DXN => internal.getDXN(entity);\n\n/**\n * @returns The DXN of the relation's type.\n */\nexport const getTypeDXN = internal.getTypeDXN;\n\n/**\n * Get the schema of the relation.\n * Returns the branded ECHO schema used to create the relation.\n */\nexport const getSchema: (rel: unknown | undefined) => Type.AnyEntity | undefined = internal.getSchema as any;\n\n/**\n * @returns The typename of the relation's type.\n * Accepts both reactive relations and snapshots.\n */\nexport const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);\n\n//\n// Database\n//\n\n/**\n * Get the database the relation belongs to.\n * Accepts both reactive relations and snapshots.\n */\nexport const getDatabase = (entity: Unknown | Snapshot): Database.Database | undefined => internal.getDatabase(entity);\n\n//\n// Meta\n//\n\n/**\n * Property that accesses metadata for an entity.\n *\n * Alias for `Entity.Meta`.\n */\nexport const Meta = internal.MetaId;\n\n/**\n * Deeply read-only version of ObjectMeta.\n */\nexport type ReadonlyMeta = internal.ReadonlyMeta;\n\n/**\n * Mutable meta type returned by `Relation.getMeta` inside a `Relation.change` callback.\n */\nexport type Meta = internal.Meta;\n\n/**\n * Get the metadata for a relation.\n * Returns mutable meta when passed a mutable relation (inside `Relation.change` callback).\n * Returns read-only meta when passed a regular relation or snapshot.\n */\n// TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\nexport function getMeta(entity: Mutable<Unknown>): Meta;\nexport function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;\nexport function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | ReadonlyMeta {\n return internal.getMetaChecked(entity);\n}\n\n/**\n * @returns Foreign keys for the relation from the specified source.\n * Accepts both reactive relations and snapshots.\n */\nexport const getKeys = (entity: Unknown | Snapshot, source: string): ForeignKey[] => internal.getKeys(entity, source);\n\n/**\n * Delete all keys from the relation for the specified source.\n * Must be called within a `Relation.change` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const deleteKeys = (entity: Mutable<Unknown>, source: string): void => internal.deleteKeys(entity, source);\n\n/**\n * Add a tag to the relation.\n * Must be called within a `Relation.change` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const addTag = (entity: Mutable<Unknown>, tag: string): void => internal.addTag(entity, tag);\n\n/**\n * Remove a tag from the relation.\n * Must be called within a `Relation.change` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const removeTag = (entity: Mutable<Unknown>, tag: string): void => internal.removeTag(entity, tag);\n\n/**\n * Check if the relation is deleted.\n * Accepts both reactive relations and snapshots.\n */\nexport const isDeleted = (entity: Unknown | Snapshot): boolean => internal.isDeleted(entity);\n\n//\n// Annotations\n//\n\n/**\n * Get the label of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getLabel = (entity: Unknown | Snapshot): string | undefined => internal.getLabel(entity);\n\n/**\n * Set the label of the relation.\n * Must be called within a `Relation.change` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);\n\n/**\n * Get the description of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);\n\n/**\n * Set the description of the relation.\n * Must be called within a `Relation.change` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setDescription = (entity: Mutable<Unknown>, description: string): void =>\n internal.setDescription(entity, description);\n\n//\n// JSON\n//\n\n/**\n * JSON representation of a relation.\n */\nexport type JSON = internal.ObjectJSON;\n\n/**\n * Converts relation to its JSON representation.\n * Accepts both reactive relations and snapshots.\n */\nexport const toJSON = (entity: Unknown | Snapshot): JSON => internal.objectToJSON(entity);\n\n//\n// Sorting\n//\n\n/**\n * Comparator function type for sorting relations.\n * Accepts both reactive relations and snapshots.\n */\nexport type Comparator = internal.Comparator<Unknown | Snapshot>;\n\nexport const sortByLabel: Comparator = internal.sortByLabel as Comparator;\nexport const sortByTypename: Comparator = internal.sortByTypename as Comparator;\nexport const sort = (...comparators: Comparator[]): Comparator => internal.sort(...comparators) as Comparator;\n\n//\n// Version\n//\n\nexport const VersionTypeId = internal.VersionTypeId;\nexport const isVersion = internal.isVersion;\n\n/**\n * Represent relation version.\n */\nexport type Version = internal.EntityVersion;\n\n/**\n * Returns the version of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const version = (entity: Unknown | Snapshot): Version => internal.version(entity);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;iBAAAA;EAAA,qBAAAC;EAAA,cAAAC;EAAA,
|
|
6
|
-
"names": ["Unknown", "VersionTypeId", "addTag", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport type { ForeignKey } from '@dxos/echo-protocol';\nimport { createJsonPath } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, type ObjectId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from './Database';\nimport * as Entity from './Entity';\nimport * as internal from './internal';\nimport * as entityInternal from './internal/Entity';\nimport * as Obj from './Obj';\nimport type * as Type from './Type';\n\nexport type Endpoints<Source, Target> = {\n [Source]: Source;\n [Target]: Target;\n};\n\n/**\n * Base type for all ECHO relations.\n * @private\n */\ninterface BaseRelation<Source, Target>\n extends internal.AnyEntity, Endpoints<Source, Target>, Entity.OfKind<internal.EntityKind.Relation> {}\n\n/**\n * Relation with no known properties beyond id, kind, source, and target.\n * Use this when the relation's schema/properties are not known.\n *\n * NOTE: This is a TypeScript type only, not a schema.\n * To validate that a value is an ECHO relation, use `Relation.isRelation`.\n */\nexport interface Unknown extends BaseRelation<Obj.Unknown, Obj.Unknown> {}\n\n/**\n * Runtime Effect schema for any ECHO relation.\n * Use for validation, parsing, or as a reference target for collections.\n * A relation has `id`, source, and target fields plus any additional properties.\n *\n * NOTE: `Schema.is(Type.Relation)` does STRUCTURAL validation only (checks for `id` field).\n * Use `Relation.isRelation()` for proper ECHO instance type guards that check the KindId brand.\n *\n * @example\n * ```ts\n * // Structural type guard (accepts any object with id field)\n * if (Schema.is(Type.Relation)(unknownValue)) { ... }\n *\n * // ECHO instance type guard (checks KindId brand)\n * if (Relation.isRelation(unknownValue)) { ... }\n * ```\n */\n// TODO(dmaretskyi): Change ObjModule.Any to ObjModule.Unknown to have stricter types.\nexport const Unknown: Type.Relation<Unknown, Obj.Any, Obj.Any> = Schema.Struct({\n id: Schema.String,\n}).pipe(\n Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),\n // TODO(dmaretskyi): Clean this up.\n // NOTE: The EchoRelationSchema annotation is required for Ref.Ref(Relation.Unknown) to work.\n // The typename/version/source/target only satisfy ECHO schema machinery for reference targets.\n internal.EchoRelationSchema({\n typename: 'org.dxos.schema.anyRelation',\n version: '0.0.0',\n source: Obj.Unknown,\n target: Obj.Unknown,\n }),\n (schema) =>\n Object.assign(schema, {\n [internal.SchemaKindId]: (schema as any)[internal.SchemaKindId],\n }) as unknown as Type.Relation<Unknown, Obj.Any, Obj.Any>,\n);\n\n/**\n * Relation type with specific source and target types.\n */\nexport type OfShape<Source extends Obj.Unknown, Target extends Obj.Unknown, Props> = BaseRelation<Source, Target> &\n Props;\n\n/**\n * Base type for snapshot relations (has SnapshotKindId instead of KindId).\n */\ninterface BaseRelationSnapshot<Source, Target> extends internal.AnyEntity, Endpoints<Source, Target> {\n readonly [Entity.SnapshotKindId]: internal.EntityKind.Relation;\n readonly id: ObjectId;\n}\n\n/**\n * JSON-encoded properties for relations.\n */\nexport interface BaseRelationJson {\n id: string;\n [internal.ATTR_RELATION_SOURCE]: string;\n [internal.ATTR_RELATION_TARGET]: string;\n}\n\n/**\n * Immutable snapshot of an ECHO relation.\n * Branded with SnapshotKindId (not KindId).\n * Property values are frozen at the time the snapshot was created.\n * Returned by getSnapshot() and hooks.\n */\nexport type Snapshot<T extends Unknown = Unknown> = Omit<T, Entity.KindId> &\n BaseRelationSnapshot<Obj.Unknown, Obj.Unknown>;\n\nexport const Source: unique symbol = entityInternal.RelationSourceId as any;\nexport type Source = typeof Source;\n\nexport const Target: unique symbol = entityInternal.RelationTargetId as any;\nexport type Target = typeof Target;\n\n/**\n * Get relation source type.\n */\nexport type SourceOf<A> = A extends Endpoints<infer S, infer _T> ? S : never;\n\n/**\n * Get relation target type.\n */\nexport type TargetOf<A> = A extends Endpoints<infer _S, infer T> ? T : never;\n\n/**\n * Internal props type for relation instance creation.\n */\ntype MakePropsInternal<T extends Unknown> = {\n id?: ObjectId;\n [Meta]?: internal.ObjectMeta;\n [Source]: T[Source];\n [Target]: T[Target];\n} & Entity.Properties<T>;\n\n/**\n * Props type for relation creation with a given schema.\n * Takes a schema type (created with Type.Relation) and extracts the props type.\n */\nexport type MakeProps<S extends Type.AnyRelation> = MakePropsInternal<Schema.Schema.Type<S>>;\n\n/**\n * Creates new relation.\n * @param schema - Relation schema.\n * @param props - Relation properties. Endpoints are passed as [Relation.Source] and [Relation.Target] keys.\n * @param meta - Relation metadata. (deprecated; use [Obj.Meta] instead)\n * @returns\n */\n// NOTE: Writing the definition this way (with generic over schema) makes typescript perfer to infer the type from the first param (this schema) rather than the second param (the props).\n// TODO(dmaretskyi): Move meta into props.\nexport const make = <S extends Type.AnyRelation>(\n schema: S,\n props: NoInfer<MakeProps<S>>,\n): Schema.Schema.Type<S> & Entity.OfKind<typeof Entity.Kind.Relation> => {\n assertArgument(\n internal.getTypeAnnotation(schema)?.kind === internal.EntityKind.Relation,\n 'schema',\n 'Expected a relation schema',\n );\n assertArgument(props[internal.ParentId] === undefined, 'props', 'Parent is not allowed for relations');\n\n let meta: internal.ObjectMeta | undefined = undefined;\n\n if (props[internal.MetaId] != null) {\n meta = props[internal.MetaId] as any;\n delete props[internal.MetaId];\n }\n\n const sourceDXN = internal.getObjectDXN(props[Source]) ?? raise(new Error('Unresolved relation source'));\n const targetDXN = internal.getObjectDXN(props[Target]) ?? raise(new Error('Unresolved relation target'));\n\n (props as any)[internal.RelationSourceDXNId] = sourceDXN;\n (props as any)[internal.RelationTargetDXNId] = targetDXN;\n\n return internal.makeObject<Schema.Schema.Type<S>>(schema, props as any, meta);\n};\n\n/**\n * Type guard for relations.\n * Returns true for both reactive relations and relation snapshots.\n */\nexport const isRelation = (value: unknown): value is Unknown => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n if (internal.ATTR_RELATION_SOURCE in value || internal.ATTR_RELATION_TARGET in value) {\n return true;\n }\n\n // Check for reactive relation (KindId) or snapshot (SnapshotKindId).\n const kind = (value as any)[Entity.KindId] ?? (value as any)[Entity.SnapshotKindId];\n return kind === internal.EntityKind.Relation;\n};\n\nexport const isSnapshot = (value: unknown): value is Snapshot => {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n return (value as any)[Entity.SnapshotKindId] === internal.EntityKind.Relation;\n};\n\n/**\n * @returns Relation source DXN.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getSourceDXN = (value: Unknown | Snapshot): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(value);\n const dxn = (value as internal.InternalObjectProps)[internal.RelationSourceDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation target DXN.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getTargetDXN = (value: Unknown | Snapshot): DXN => {\n assertArgument(isRelation(value), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(value);\n const dxn = (value as internal.InternalObjectProps)[internal.RelationTargetDXNId];\n invariant(dxn instanceof DXN);\n return dxn;\n};\n\n/**\n * @returns Relation source.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getSource = <T extends Unknown | Snapshot>(relation: T): SourceOf<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(relation);\n const obj = (relation as internal.InternalObjectProps)[internal.RelationSourceId];\n if (obj === undefined) {\n throw new Error(`Relation source could not be resolved.`);\n }\n return obj as SourceOf<T>;\n};\n\n/**\n * @returns Relation target.\n * Accepts both reactive relations and snapshots.\n * @throws If the object is not a relation.\n */\nexport const getTarget = <T extends Unknown | Snapshot>(relation: T): TargetOf<T> => {\n assertArgument(isRelation(relation), 'Expected a relation');\n assumeType<internal.InternalObjectProps>(relation);\n const obj = (relation as internal.InternalObjectProps)[internal.RelationTargetId];\n if (obj === undefined) {\n throw new Error(`Relation target could not be resolved.`);\n }\n return obj as TargetOf<T>;\n};\n\n//\n// Change\n//\n\n/**\n * Makes all properties mutable recursively.\n * Used to provide a mutable view of a relation within `Relation.update`.\n */\nexport type Mutable<T> = internal.Mutable<T>;\n\n/**\n * Perform mutations on an echo relation within a controlled context.\n *\n * All mutations within the callback are batched and trigger a single notification\n * when the callback completes. Direct mutations outside of `Relation.update` will throw\n * an error for echo relations.\n *\n * @param relation - The echo relation to mutate. Use `Obj.update` for objects.\n * @param callback - The callback that performs mutations on the relation.\n *\n * @example\n * ```ts\n * const worksFor = Relation.make(EmployedBy, {\n * [Relation.Source]: person,\n * [Relation.Target]: company,\n * role: 'Engineer',\n * });\n *\n * // Mutate within Relation.update\n * Relation.update(worksFor, (obj) => {\n * obj.role = 'Senior Engineer';\n * });\n * ```\n *\n * Note: Only accepts relations. Use `Obj.update` for objects.\n */\nexport const update = <T extends Unknown>(relation: T, callback: internal.ChangeCallback<T>): void => {\n internal.change(relation, callback);\n};\n\n//\n// Snapshot\n//\n\n/**\n * Returns an immutable snapshot of a relation.\n * The snapshot is branded with SnapshotKindId instead of KindId,\n * making it distinguishable from the reactive relation at the type level.\n */\nexport const getSnapshot: <T extends Unknown>(rel: T) => Snapshot<T> = internal.getSnapshot as any;\n\n//\n// Subscribe\n//\n\n/**\n * Subscribe to relation updates.\n * The callback is called synchronously when the relation is modified.\n * Only accepts reactive relations (not snapshots).\n * @returns Unsubscribe function.\n */\nexport const subscribe = (rel: Unknown, callback: () => void): (() => void) => {\n return internal.subscribe(rel, callback);\n};\n\n//\n// Property Access\n//\n\n/**\n * Get a deeply nested property from a relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getValue = (rel: Unknown | Snapshot, path: readonly (string | number)[]): any => {\n return internal.getValue(rel, createJsonPath(path));\n};\n\n/**\n * Set a deeply nested property on a relation.\n * Must be called within a `Relation.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setValue: (rel: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =\n internal.setValue as any;\n\n//\n// Type\n//\n\n/**\n * Get the DXN of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getDXN = (entity: Unknown | Snapshot): DXN => internal.getDXN(entity);\n\n/**\n * @returns The DXN of the relation's type.\n */\nexport const getTypeDXN = internal.getTypeDXN;\n\n/**\n * Get the schema of the relation.\n * Returns the branded ECHO schema used to create the relation.\n */\nexport const getSchema: (rel: unknown | undefined) => Type.AnyEntity | undefined = internal.getSchema as any;\n\n/**\n * @returns The typename of the relation's type.\n * Accepts both reactive relations and snapshots.\n */\nexport const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);\n\n//\n// Database\n//\n\n/**\n * Get the database the relation belongs to.\n * Accepts both reactive relations and snapshots.\n */\nexport const getDatabase = (entity: Unknown | Snapshot): Database.Database | undefined => internal.getDatabase(entity);\n\n//\n// Meta\n//\n\n/**\n * Property that accesses metadata for an entity.\n *\n * Alias for `Entity.Meta`.\n */\nexport const Meta = internal.MetaId;\n\n/**\n * Deeply read-only version of ObjectMeta.\n */\nexport type ReadonlyMeta = internal.ReadonlyMeta;\n\n/**\n * Mutable meta type returned by `Relation.getMeta` inside a `Relation.update` callback.\n */\nexport type Meta = internal.Meta;\n\n/**\n * Get the metadata for a relation.\n * Returns mutable meta when passed a mutable relation (inside `Relation.update` callback).\n * Returns read-only meta when passed a regular relation or snapshot.\n */\n// TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.\nexport function getMeta(entity: Mutable<Unknown>): Meta;\nexport function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;\nexport function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | ReadonlyMeta {\n return internal.getMetaChecked(entity);\n}\n\n/**\n * @returns Foreign keys for the relation from the specified source.\n * Accepts both reactive relations and snapshots.\n */\nexport const getKeys = (entity: Unknown | Snapshot, source: string): ForeignKey[] => internal.getKeys(entity, source);\n\n/**\n * Delete all keys from the relation for the specified source.\n * Must be called within a `Relation.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const deleteKeys = (entity: Mutable<Unknown>, source: string): void => internal.deleteKeys(entity, source);\n\n/**\n * Add a tag to the relation.\n * Must be called within a `Relation.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const addTag = (entity: Mutable<Unknown>, tag: string): void => internal.addTag(entity, tag);\n\n/**\n * Remove a tag from the relation.\n * Must be called within a `Relation.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const removeTag = (entity: Mutable<Unknown>, tag: string): void => internal.removeTag(entity, tag);\n\n/**\n * Check if the relation is deleted.\n * Accepts both reactive relations and snapshots.\n */\nexport const isDeleted = (entity: Unknown | Snapshot): boolean => internal.isDeleted(entity);\n\n//\n// Annotations\n//\n\n/**\n * Get the label of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getLabel = (entity: Unknown | Snapshot): string | undefined => internal.getLabel(entity);\n\n/**\n * Set the label of the relation.\n * Must be called within a `Relation.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);\n\n/**\n * Get the description of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);\n\n/**\n * Set the description of the relation.\n * Must be called within a `Relation.update` callback.\n *\n * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`\n * parameters, so there is no compile-time error. Enforcement is runtime-only.\n */\nexport const setDescription = (entity: Mutable<Unknown>, description: string): void =>\n internal.setDescription(entity, description);\n\n//\n// JSON\n//\n\n/**\n * JSON representation of a relation.\n */\nexport type JSON = internal.ObjectJSON;\n\n/**\n * Converts relation to its JSON representation.\n * Accepts both reactive relations and snapshots.\n */\nexport const toJSON = (entity: Unknown | Snapshot): JSON => internal.objectToJSON(entity);\n\n//\n// Sorting\n//\n\n/**\n * Comparator function type for sorting relations.\n * Accepts both reactive relations and snapshots.\n */\nexport type Comparator = internal.Comparator<Unknown | Snapshot>;\n\nexport const sortByLabel: Comparator = internal.sortByLabel as Comparator;\nexport const sortByTypename: Comparator = internal.sortByTypename as Comparator;\nexport const sort = (...comparators: Comparator[]): Comparator => internal.sort(...comparators) as Comparator;\n\n//\n// Version\n//\n\nexport const VersionTypeId = internal.VersionTypeId;\nexport const isVersion = internal.isVersion;\n\n/**\n * Represent relation version.\n */\nexport type Version = internal.EntityVersion;\n\n/**\n * Returns the version of the relation.\n * Accepts both reactive relations and snapshots.\n */\nexport const version = (entity: Unknown | Snapshot): Version => internal.version(entity);\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["Unknown", "VersionTypeId", "addTag", "deleteKeys", "getDXN", "getDatabase", "getDescription", "getKeys", "getLabel", "getSchema", "getSnapshot", "getTypeDXN", "getTypename", "getValue", "isDeleted", "isVersion", "removeTag", "setDescription", "setLabel", "setValue", "sort", "sortByLabel", "sortByTypename", "subscribe", "version", "Schema", "raise", "createJsonPath", "assertArgument", "invariant", "DXN", "assumeType", "Schema", "Record", "key", "version", "source", "Obj", "target", "Object", "internal", "Source", "entityInternal", "RelationSourceId", "assertArgument", "props", "ParentId", "undefined", "meta", "MetaId", "sourceDXN", "getObjectDXN", "RelationSourceDXNId", "RelationTargetDXNId", "targetDXN", "schema", "value", "assumeType", "invariant", "dxn", "relation", "obj", "RelationTargetId", "getSnapshot", "subscribe", "getValue", "setValue", "getTypename", "getDatabase", "getMetaChecked", "isDeleted", "sortByTypename", "sort", "comparators", "VersionTypeId"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Extension.ts"],
|
|
4
|
-
"sourcesContent": ["// @import-as-namespace\n//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\n// @import-as-namespace\n\n/**\n * Extensions allow objects to contain typed properties that are not part of the schema.\n */\n\nexport const TypeId = '~@dxos/echo/Extension' as const;\nexport type TypeId = typeof TypeId;\n\nexport interface Extension<T> extends Record<\n TypeId,\n {\n _Type: T;\n }\n> {\n readonly [TypeId]: {\n _Type: T;\n };\n\n readonly key: Key;\n readonly valueSchema: Schema.Schema<T>;\n}\n\n/**\n * Create a new typed extension.\n *\n * ```ts\n * const ColorExtension = Extension.make('color', Schema.String);\n *\n * const obj = Obj.make(Person, {\n * [Obj.Meta]: { keys: [{ source: 'external', id: '123' }] },\n * name: 'John',\n * email: 'john@example.com',\n * });\n *\n * Obj.
|
|
4
|
+
"sourcesContent": ["// @import-as-namespace\n//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\n// @import-as-namespace\n\n/**\n * Extensions allow objects to contain typed properties that are not part of the schema.\n */\n\nexport const TypeId = '~@dxos/echo/Extension' as const;\nexport type TypeId = typeof TypeId;\n\nexport interface Extension<T> extends Record<\n TypeId,\n {\n _Type: T;\n }\n> {\n readonly [TypeId]: {\n _Type: T;\n };\n\n readonly key: Key;\n readonly valueSchema: Schema.Schema<T>;\n}\n\n/**\n * Create a new typed extension.\n *\n * ```ts\n * const ColorExtension = Extension.make('color', Schema.String);\n *\n * const obj = Obj.make(Person, {\n * [Obj.Meta]: { keys: [{ source: 'external', id: '123' }] },\n * name: 'John',\n * email: 'john@example.com',\n * });\n *\n * Obj.update(obj, (obj) => {\n * Extension.set(obj.extensions, ColorExtension, 'red');\n * });\n *\n * console.log(Extension.get(obj.extensions, ColorExtension)); // 'red'\n * ```\n */\nexport const make = <S extends Schema.Schema.AnyNoContext>(\n key: string,\n valueSchema: S,\n): Extension<Schema.Schema.Type<S>> => {\n return {\n [TypeId]: {} as any,\n key: Key.make(key),\n valueSchema,\n };\n};\n\n/**\n * Unique identifier for an extension.\n */\n// TODO(dmaretskyi): filter to be fully qualified: (e.g., org.dxos.extension.color)\nexport const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/ExtensionKey'));\nexport type Key = Schema.Schema.Type<typeof Key>;\n\n/**\n * Set of extension values.\n *\n * Can be used inside an object/relation schema:\n *\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * extensions: Extension.Values,\n * });\n * ```\n */\nexport const Values = Schema.Record({ key: Key, value: Schema.Unknown });\nexport interface Values extends Schema.Schema.Type<typeof Values> {}\n\n/**\n * Get the value of an extension from a set of values.\n */\nexport const get: {\n <T>(extension: Extension<T>): (values: Values) => Option.Option<T>;\n <T>(values: Values, extension: Extension<T>): Option.Option<T>;\n} = Function.dual<\n <T>(extension: Extension<T>) => (values: Values) => Option.Option<T>,\n <T>(values: Values, extension: Extension<T>) => Option.Option<T>\n>(2, (values, extension) => {\n if (!(extension.key in values)) {\n return Option.none();\n }\n\n return Function.pipe(values[extension.key], Schema.decodeUnknownSync(extension.valueSchema), Option.some);\n});\n\n/**\n * Set the value of an extension in a set of values.\n *\n * Can also be used within Obj.update callback:\n *\n * ```ts\n * Obj.update(obj, (obj) => {\n * Extension.set(obj.extensions, ColorExtension, 'red');\n * });\n * ```\n */\nexport const set: {\n <T>(extension: Extension<T>, value: T): (values: Values) => void;\n <T>(values: Types.Mutable<Values>, extension: Extension<T>, value: T): void;\n} = Function.dual<\n <T>(extension: Extension<T>, value: T) => (values: Values) => void,\n <T>(values: Types.Mutable<Values>, extension: Extension<T>, value: T) => void\n>(3, (values, extension, value) => {\n values[extension.key] = Schema.encodeSync(extension.valueSchema)(value);\n});\n"],
|
|
5
5
|
"mappings": ";;;;;AAAA;;;;;;;;;AAKA,YAAYA,cAAc;AAC1B,YAAYC,YAAY;AACxB,YAAYC,YAAY;AASjB,IAAMC,SAAS;AAoCf,IAAMC,OAAO,CAClBC,KACAC,gBAAAA;AAEA,SAAO;IACL,CAACH,MAAAA,GAAS,CAAC;IACXE,KAAKE,IAAIH,KAAKC,GAAAA;IACdC;EACF;AACF;AAMO,IAAMC,MAAaC,cAAOC,KAAYC,aAAM,0BAAA,CAAA;AAe5C,IAAMC,SAAgBC,cAAO;EAAEP,KAAKE;EAAKM,OAAcC;AAAQ,CAAA;AAM/D,IAAMC,MAGAC,cAGX,GAAG,CAACC,QAAQC,cAAAA;AACZ,MAAI,EAAEA,UAAUb,OAAOY,SAAS;AAC9B,WAAcE,YAAI;EACpB;AAEA,SAAgBV,cAAKQ,OAAOC,UAAUb,GAAG,GAAUe,yBAAkBF,UAAUZ,WAAW,GAAUe,WAAI;AAC1G,CAAA;AAaO,IAAMC,MAGAN,cAGX,GAAG,CAACC,QAAQC,WAAWL,UAAAA;AACvBI,SAAOC,UAAUb,GAAG,IAAWkB,kBAAWL,UAAUZ,WAAW,EAAEO,KAAAA;AACnE,CAAA;",
|
|
6
6
|
"names": ["Function", "Option", "Schema", "TypeId", "make", "key", "valueSchema", "Key", "String", "pipe", "brand", "Values", "Record", "value", "Unknown", "get", "dual", "values", "extension", "none", "decodeUnknownSync", "some", "set", "encodeSync"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isInstanceOf
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TNBK56IN.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ObjectNotFoundError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZISMEVKD.mjs";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
9
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -78,15 +78,7 @@ var resolve = (ref, schema) => Effect.gen(function* () {
|
|
|
78
78
|
if (!object) {
|
|
79
79
|
return yield* Effect.fail(new ObjectNotFoundError(dxn));
|
|
80
80
|
}
|
|
81
|
-
invariant(!schema || isInstanceOf(schema, object), "Object type mismatch.", {
|
|
82
|
-
F: __dxlog_file,
|
|
83
|
-
L: 230,
|
|
84
|
-
S: this,
|
|
85
|
-
A: [
|
|
86
|
-
"!schema || isInstanceOf(schema, object)",
|
|
87
|
-
"'Object type mismatch.'"
|
|
88
|
-
]
|
|
89
|
-
});
|
|
81
|
+
invariant(!schema || isInstanceOf(schema, object), "Object type mismatch.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 67, S: this, A: ["!schema || isInstanceOf(schema, object)", "'Object type mismatch.'"] });
|
|
90
82
|
return object;
|
|
91
83
|
}).pipe(Effect.withSpan("Database.resolve"));
|
|
92
84
|
var load = Effect.fn("Database.load")(function* (ref) {
|
|
@@ -133,4 +125,4 @@ export {
|
|
|
133
125
|
runSchemaQuery,
|
|
134
126
|
Database_exports
|
|
135
127
|
};
|
|
136
|
-
//# sourceMappingURL=chunk-
|
|
128
|
+
//# sourceMappingURL=chunk-I2DARWPX.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Database.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { promiseWithCauseCapture } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { DXN, type SpaceId } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport * as Err from './Err';\nimport type * as Filter from './Filter';\nimport type * as Hypergraph from './Hypergraph';\nimport { isInstanceOf } from './internal/Annotation';\nimport { type AnyProperties } from './internal/common/types';\nimport type { Ref } from './internal/Ref/ref';\nimport type * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport type * as SchemaRegistry from './SchemaRegistry';\nimport type * as Type from './Type';\n\n/**\n * `query` API function declaration.\n */\n// TODO(burdon): Reconcile Query and Filter (should only have one root type).\nexport interface QueryFn {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResult<Query.Type<Q>>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResult<Filter.Type<F>>;\n}\n\n/**\n * Common interface for Database, Feed, and Hypergraph.\n */\nexport interface Queryable {\n query: QueryFn;\n}\n\nexport type GetObjectByIdOptions = {\n deleted?: boolean;\n};\n\nexport type ObjectPlacement = 'root-doc' | 'linked-doc';\n\nexport type AddOptions = {\n /**\n * Where to place the object in the Automerge document tree.\n * Root document is always loaded with the space.\n * Linked documents are loaded lazily.\n * Placing large number of objects in the root document may slow down the initial load.\n *\n * @default 'linked-doc'\n */\n placeIn?: ObjectPlacement;\n};\n\nexport type FlushOptions = {\n /**\n * Write any pending changes to disk.\n * @default true\n */\n disk?: boolean;\n\n /**\n * Wait for pending index updates.\n * @default true\n */\n indexes?: boolean;\n\n /**\n * Flush pending updates to objects and queries.\n * @default false\n */\n updates?: boolean;\n};\n\n/**\n * Identifier denoting an ECHO Database.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Database');\nexport type TypeId = typeof TypeId;\n\n/**\n * ECHO Database interface.\n */\nexport interface Database extends Queryable {\n readonly [TypeId]: TypeId;\n\n get spaceId(): SpaceId;\n\n // TODO(burdon): Can we move this into graph?\n get schemaRegistry(): SchemaRegistry.SchemaRegistry;\n\n get graph(): Hypergraph.Hypergraph;\n\n toJSON(): object;\n\n /**\n * Return object by local ID.\n */\n getObjectById<T extends Obj.Unknown = Obj.OfShape<AnyProperties>>(\n id: string,\n opts?: GetObjectByIdOptions,\n ): T | undefined;\n\n /**\n * Query objects.\n */\n query: QueryFn;\n\n /**\n * Creates a reference to an existing object in the database.\n *\n * NOTE: The reference may be dangling if the object is not present in the database.\n * NOTE: Difference from `Ref.fromDXN`\n * `Ref.fromDXN(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n * `db.makeRef(dxn)` is preferable in cases with access to the database.\n */\n makeRef<T extends Entity.Unknown = Entity.Unknown>(dxn: DXN): Ref<T>;\n\n /**\n * Adds object to the database.\n */\n add<T extends Entity.Unknown = Entity.Unknown>(obj: T, opts?: AddOptions): T;\n\n /**\n * Removes object from the database.\n */\n // TODO(burdon): Return true if removed (currently throws if not present).\n remove(obj: Entity.Unknown): void;\n\n /**\n * Wait for all pending changes to be saved to disk.\n * Optionaly waits for changes to be propagated to indexes and event handlers.\n */\n flush(opts?: FlushOptions): Promise<void>;\n}\n\nexport const isDatabase = (obj: unknown): obj is Database => {\n return obj ? typeof obj === 'object' && TypeId in obj && obj[TypeId] === TypeId : false;\n};\n\nexport const Database: Schema.Schema<Database> = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));\n\n/**\n * Effect service tag for Database dependency injection.\n */\nexport class Service extends Context.Tag('@dxos/echo/Database/Service')<\n Service,\n {\n readonly db: Database;\n }\n>() {}\n\n/**\n * Layer that provides a Database service that throws when accessed.\n * Useful as a default layer when no database is available.\n */\nexport const notAvailable = Layer.succeed(Service, {\n get db(): Database {\n throw new Error('Database not available');\n },\n});\n\n/**\n * Creates a Database service instance from a Database.\n */\nexport const makeService = (db: Database): Context.Tag.Service<Service> => {\n return {\n get db() {\n return db;\n },\n };\n};\n\n/**\n * Creates a Layer that provides the Database service.\n */\nexport const layer = (db: Database): Layer.Layer<Service> => {\n return Layer.succeed(Service, makeService(db));\n};\n\n/**\n * Returns the space ID of the database.\n */\nexport const spaceId = Effect.gen(function* () {\n const { db } = yield* Service;\n return db.spaceId;\n});\n\n/**\n * Resolves an object by its DXN.\n */\nexport const resolve: {\n // No type check.\n (ref: DXN | Ref<any>): Effect.Effect<Entity.Unknown, never, Service>;\n // Check matches schema.\n <S extends Type.AnyEntity>(\n ref: DXN | Ref<any>,\n schema: S,\n ): Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Service>;\n} = (<S extends Type.AnyEntity>(\n ref: DXN | Ref<any>,\n schema?: S,\n): Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Service> =>\n Effect.gen(function* () {\n const { db } = yield* Service;\n const dxn = ref instanceof DXN ? ref : ref.dxn;\n const object = yield* promiseWithCauseCapture(() =>\n db.graph\n .createRefResolver({\n context: {\n space: db.spaceId,\n },\n })\n .resolve(dxn),\n );\n\n if (!object) {\n return yield* Effect.fail(new Err.ObjectNotFoundError(dxn));\n }\n invariant(!schema || isInstanceOf(schema, object), 'Object type mismatch.');\n return object as any;\n }).pipe(Effect.withSpan('Database.resolve'))) as any;\n\n/**\n * Loads an object reference.\n */\nexport const load: <T>(ref: Ref<T>) => Effect.Effect<T, Err.ObjectNotFoundError, never> = Effect.fn('Database.load')(\n function* (ref) {\n const object = yield* promiseWithCauseCapture(() => ref.tryLoad());\n if (!object) {\n return yield* Effect.fail(new Err.ObjectNotFoundError(ref.dxn));\n }\n return object;\n },\n);\n\n/**\n * Loads an object reference option.\n */\n// TODO(dmaretskyi): Do we need this -- you can just use `Effect.catchTag` in calling code instead.\nexport const loadOption: <T>(ref: Ref<T>) => Effect.Effect<Option.Option<T>, never, never> = Effect.fn(\n 'Database.loadOption',\n)(function* (ref) {\n const object = yield* load(ref).pipe(Effect.catchTag('ObjectNotFoundError', () => Effect.succeed(undefined)));\n\n return Option.fromNullable(object);\n});\n\n/**\n * Adds an object to the database.\n * @see {@link Database.add}\n */\nexport const add = <T extends Entity.Unknown>(obj: T): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.add(obj))).pipe(Effect.withSpan('Database.add'));\n\n/**\n * Removes an object from the database.\n * @see {@link Database.remove}\n */\nexport const remove = <T extends Entity.Unknown>(obj: T): Effect.Effect<void, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.remove(obj))).pipe(Effect.withSpan('Database.remove'));\n\n/**\n * Flushes pending changes to disk.\n * @see {@link Database.flush}\n */\nexport const flush = (opts?: FlushOptions) =>\n Service.pipe(Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.flush(opts)))).pipe(\n Effect.withSpan('Database.flush'),\n );\n\n/**\n * Creates a `QueryResult` object that can be subscribed to.\n */\nexport const query: {\n <Q extends Query.Any>(query: Q): Effect.Effect<QueryResult.QueryResult<Query.Type<Q>>, never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<QueryResult.QueryResult<Filter.Type<F>>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n Service.pipe(\n Effect.map(({ db }) => db.query(queryOrFilter as any) as QueryResult.QueryResult<any>),\n Effect.withSpan('Database.query'),\n );\n\n/**\n * Executes the query once and returns the results.\n */\nexport const runQuery: {\n <Q extends Query.Any>(query: Q): Effect.Effect<Query.Type<Q>[], never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<Filter.Type<F>[], never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n query(queryOrFilter as any).pipe(\n Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())),\n Effect.withSpan('Database.runQuery'),\n );\n\n/**\n * Executes the query once and returns the first result as or None.\n */\nexport const runQueryFirst: {\n <Q extends Query.Any>(query: Q): Effect.Effect<Option.Option<Query.Type<Q>>, never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<Option.Option<Filter.Type<F>>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n query(queryOrFilter as any).pipe(\n Effect.flatMap((queryResult) =>\n promiseWithCauseCapture(async () => Option.fromNullable(await queryResult.firstOrUndefined())),\n ),\n Effect.withSpan('Database.runQueryFirst'),\n );\n\n/**\n * Persists schemas in the database so they replicate to other clients.\n * @see {@link SchemaRegistry.SchemaRegistry.register}\n */\nexport const registerSchema = (\n input: SchemaRegistry.RegisterSchemaInput[],\n): Effect.Effect<Type.RuntimeType[], never, Service> =>\n Service.pipe(\n Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.schemaRegistry.register(input))),\n Effect.withSpan('Database.registerSchema'),\n );\n\n/**\n * Creates a schema query result that can be subscribed to.\n */\n// TODO(dmaretskyi): Change API to `yield* Database.querySchema(...).first` and `yield* Database.querySchema(...).schema`.\nexport const schemaQuery = <Q extends Types.NoExcessProperties<SchemaRegistry.Query, Q>>(\n schemaQueryOptions?: Q & SchemaRegistry.Query,\n): Effect.Effect<QueryResult.QueryResult<SchemaRegistry.ExtractQueryResult<Q>>, never, Service> =>\n Service.pipe(\n Effect.map(({ db }) => db.schemaRegistry.query(schemaQueryOptions)),\n Effect.withSpan('Database.schemaQuery'),\n );\n\n/**\n * Executes a schema query once and returns the results.\n */\nexport const runSchemaQuery = <Q extends Types.NoExcessProperties<SchemaRegistry.Query, Q>>(\n schemaQueryOptions?: Q & SchemaRegistry.Query,\n): Effect.Effect<SchemaRegistry.ExtractQueryResult<Q>[], never, Service> =>\n schemaQuery(schemaQueryOptions).pipe(\n Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())),\n );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;AAMA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,YAAY;AACxB,YAAYC,YAAY;AAGxB,SAASC,+BAA+B;AACxC,SAASC,iBAAiB;AAC1B,SAASC,WAAyB;AAqElC,IAAA,eAAA;AA+DSC,IAAM,SAAOA,uBAAQ,IAAA,qBAAsBA;AAClD,IAAA,aAAA,CAAA,QAAA;AAEF,SAAO,MAAMC,OAAoCC,QAAOC,YAASD,UAAc,OAACE,IAAUC,MAAAA,MAAWD,SAAS;AAE9G;;AAUA,IAAA,UAAA,cAAA,YAAA,6BAAA,EAAA,EAAA;;AAMI,IAAM,eAAU,cAAA,SAAA;EAClB,IAAA,KAAA;AACC,UAAA,IAAA,MAAA,wBAAA;EAEH;;AAKI,IAAIE,cAAK,CAAA,OAAA;;IAET,IAAA,KAAA;AACF,aAAA;IACA;EAEF;;AAKE,IAAA,QAAA,CAAA,OAAA;AAEF,SAAA,cAAA,SAAA,YAAA,EAAA,CAAA;;AAKSA,IAAGC,UAAO,WAAA,aAAA;AAChB,QAAA,EAAA,GAAA,IAAA,OAAA;AAEH,SAAA,GAAA;;AAiBI,IAAMC,UAAMC,CAAAA,KAAAA,WAA2BA,WAAID,aAAG;AAC9C,QAAME,EAAAA,GAAAA,IAAS,OAAOC;cAGhBC,eAAS,MAAA,MAAA,IAAA;iBACPR,OAAUG,wBAAO,MAAA,GAAA,MAAA,kBAAA;IACnB,SAAA;MAEDM,OAAQL,GAAAA;IAGRE;EACH,CAAA,EAAA,QAAO,GAAOI,CAAAA;AAChB,MAAA,CAAA,QAAA;AACAC,WAAWC,OAAUC,YAAAA,IAAaD,oBAAiB,GAAA,CAAA;EACnD;AACCE,YAAKJ,CAAOK,UAAS,aAAA,QAA6B,MAAA,GAAA,yBAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,IAAA,GAAA,MAAA,GAAA,CAAA,2CAAA,yBAAA,EAAA,CAAA;AAEvD,SAAA;;AAMST,IAAQ,OAAA,UAAA,eAAA,EAAA,WAAA,KAAA;QACX,SAAO,OAAOI,wBAAoBM,MAAAA,IAAAA,QAAwBZ,CAAAA;AAC5D,MAAA,CAAA,QAAA;AACA,WAAOE,OAAAA,YAAAA,IAAAA,oBAAAA,IAAAA,GAAAA,CAAAA;EAET;AAEF,SAAA;;AASE,IAAOW,aAAoBX,UAAAA,qBAAAA,EAAAA,WAAAA,KAAAA;AAC1B,QAAA,SAAA,OAAA,KAAA,GAAA,EAAA,KAAA,gBAAA,uBAAA,MAAA,eAAA,MAAA,CAAA,CAAA;AAEH,SAAA,oBAAA,MAAA;;;;;;;;;;;",
|
|
6
|
+
"names": ["Context", "Effect", "Layer", "Option", "Schema", "promiseWithCauseCapture", "invariant", "DXN", "obj", "Database", "Schema", "Any", "space", "isDatabase", "db", "spaceId", "dxn", "ref", "object", "promiseWithCauseCapture", "context", "resolve", "Effect", "invariant", "schema", "isInstanceOf", "pipe", "withSpan", "ObjectNotFoundError", "Option"]
|
|
7
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
object
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AHWSAJHU.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getDXN,
|
|
6
6
|
make
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-W7U2XGZ3.mjs";
|
|
8
8
|
import {
|
|
9
9
|
FormInputAnnotation,
|
|
10
10
|
IconAnnotation,
|
|
11
11
|
SystemTypeAnnotation
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-TNBK56IN.mjs";
|
|
13
13
|
import {
|
|
14
14
|
__export
|
|
15
15
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
// src/Feed.ts
|
|
18
18
|
var Feed_exports = {};
|
|
19
19
|
__export(Feed_exports, {
|
|
20
|
+
ContextFeedService: () => ContextFeedService,
|
|
20
21
|
Feed: () => Feed,
|
|
21
22
|
FeedService: () => FeedService,
|
|
22
23
|
Service: () => Service,
|
|
@@ -31,7 +32,7 @@ __export(Feed_exports, {
|
|
|
31
32
|
remove: () => remove,
|
|
32
33
|
runQuery: () => runQuery,
|
|
33
34
|
setRetention: () => setRetention,
|
|
34
|
-
|
|
35
|
+
sync: () => sync
|
|
35
36
|
});
|
|
36
37
|
import * as Context from "effect/Context";
|
|
37
38
|
import * as Effect from "effect/Effect";
|
|
@@ -69,16 +70,6 @@ var getQueueDxn = (feed) => {
|
|
|
69
70
|
self.echoId
|
|
70
71
|
]);
|
|
71
72
|
};
|
|
72
|
-
var unsafeFromQueueDXN = (queueDxn) => {
|
|
73
|
-
const parts = queueDxn.asQueueDXN();
|
|
74
|
-
if (!parts) {
|
|
75
|
-
throw new Error(`Expected a queue DXN, got: ${queueDxn.toString()}`);
|
|
76
|
-
}
|
|
77
|
-
return make(Feed, {
|
|
78
|
-
id: parts.queueId,
|
|
79
|
-
namespace: parts.subspaceTag === "trace" ? "trace" : void 0
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
73
|
var FeedService = class extends Context.Tag("@dxos/echo/Feed/FeedService")() {
|
|
83
74
|
};
|
|
84
75
|
var Service = FeedService;
|
|
@@ -91,8 +82,16 @@ var notAvailable = Layer.succeed(FeedService, {
|
|
|
91
82
|
},
|
|
92
83
|
query: () => {
|
|
93
84
|
throw new Error("Feed.FeedService not available");
|
|
85
|
+
},
|
|
86
|
+
sync: () => {
|
|
87
|
+
throw new Error("Feed.FeedService not available");
|
|
94
88
|
}
|
|
95
89
|
});
|
|
90
|
+
var ContextFeedService = class _ContextFeedService extends Context.Tag("@dxos/echo/Feed/ContextFeedService")() {
|
|
91
|
+
static layer = (feed) => Layer.succeed(_ContextFeedService, {
|
|
92
|
+
feed
|
|
93
|
+
});
|
|
94
|
+
};
|
|
96
95
|
var append = (feed, items) => Effect.gen(function* () {
|
|
97
96
|
const service = yield* FeedService;
|
|
98
97
|
yield* Effect.promise(() => service.append(feed, items));
|
|
@@ -104,6 +103,10 @@ var remove = (feed, items) => Effect.gen(function* () {
|
|
|
104
103
|
});
|
|
105
104
|
var query = (feed, queryOrFilter) => FeedService.pipe(Effect.map((service) => service.query(feed, queryOrFilter)));
|
|
106
105
|
var runQuery = (feed, queryOrFilter) => query(feed, queryOrFilter).pipe(Effect.flatMap((queryResult) => Effect.promise(() => queryResult.run())));
|
|
106
|
+
var sync = (feed, options) => Effect.gen(function* () {
|
|
107
|
+
const service = yield* FeedService;
|
|
108
|
+
yield* Effect.promise(() => service.sync(feed, options));
|
|
109
|
+
});
|
|
107
110
|
var cursor = (_feed) => Effect.succeed({
|
|
108
111
|
_tag: "Cursor"
|
|
109
112
|
});
|
|
@@ -115,18 +118,19 @@ export {
|
|
|
115
118
|
Feed,
|
|
116
119
|
make2 as make,
|
|
117
120
|
getQueueDxn,
|
|
118
|
-
unsafeFromQueueDXN,
|
|
119
121
|
FeedService,
|
|
120
122
|
Service,
|
|
121
123
|
notAvailable,
|
|
124
|
+
ContextFeedService,
|
|
122
125
|
append,
|
|
123
126
|
remove,
|
|
124
127
|
query,
|
|
125
128
|
runQuery,
|
|
129
|
+
sync,
|
|
126
130
|
cursor,
|
|
127
131
|
next,
|
|
128
132
|
nextOption,
|
|
129
133
|
setRetention,
|
|
130
134
|
Feed_exports
|
|
131
135
|
};
|
|
132
|
-
//# sourceMappingURL=chunk-
|
|
136
|
+
//# sourceMappingURL=chunk-KBZ4RAXR.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Feed.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport type * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { DXN } from '@dxos/keys';\n\nimport * as Annotation from './Annotation';\nimport type * as Entity from './Entity';\nimport type * as Filter from './Filter';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport * as Type from './Type';\n\n/**\n * Runtime schema for a Feed object.\n *\n * @example\n * ```ts\n * const feed = Obj.make(Feed.Feed, { name: 'notifications', kind: 'org.dxos.plugin.notifications.v1' });\n * ```\n */\nexport const Feed = Schema.Struct({\n /** User-facing display name. */\n name: Schema.String.pipe(Schema.optional),\n /** Identifier for the feed's kind (e.g., plugin id). */\n kind: Schema.String.pipe(internal.FormInputAnnotation.set(false), Schema.optional),\n\n /**\n * Feed namespace.\n * Controls how feed data is stored and replicated.\n * - `data`: Data feed (default).\n * - `trace`: Trace feed.\n */\n namespace: Schema.optional(Schema.Literal('data', 'trace')),\n}).pipe(\n Type.object({\n typename: 'org.dxos.type.feed',\n version: '0.1.0',\n }),\n internal.SystemTypeAnnotation.set(true),\n Annotation.IconAnnotation.set({\n icon: 'ph--rows--regular',\n hue: 'yellow',\n }),\n);\n\n/**\n * TypeScript instance type for a Feed object.\n */\nexport interface Feed extends Schema.Schema.Type<typeof Feed> {}\n\n//\n// Types\n//\n\n/**\n * Opaque cursor for iterating over feed items.\n */\n// TODO(dmaretskyi): T needs to be referenced in the type structure for typescript to respect it during inference and type-checking.\nexport interface Cursor<T = Obj.Snapshot> {\n readonly _tag: 'Cursor';\n}\n\n/**\n * Retention options for a feed.\n */\nexport interface RetentionOptions {\n /** Retain items after this cursor position. */\n // TODO(wittjosiah): Use FeedCursor from @dxos/feed?\n cursor?: string;\n}\n\n/**\n * Sync options for a feed.\n */\nexport interface SyncOptions {\n /** Push local changes to the server. Defaults to true. */\n shouldPush?: boolean;\n /** Pull remote changes from the server. Defaults to true. */\n shouldPull?: boolean;\n}\n\n//\n// Factory\n//\n\n/**\n * Creates a new feed object.\n *\n * @example\n * ```ts\n * const feed = Feed.make({ name: 'notifications', kind: 'org.dxos.plugin.notifications.v1' });\n * ```\n */\n// TODO(wittjosiah): How to control the feed namespace (data/trace)? Why do feeds have namespaces?\nexport const make = (props: Obj.MakeProps<typeof Feed> = {}): Feed => Obj.make(Feed, props);\n\n/**\n * Derives the queue DXN from the feed object's DXN.\n * Returns `undefined` when the feed is not stored in a space yet.\n *\n * Used internally by the feed service layer.\n */\nexport const getQueueDxn = (feed: Feed): DXN | undefined => {\n const self = Obj.getDXN(feed).asEchoDXN();\n if (!self || !self.spaceId) {\n return undefined;\n }\n return new DXN(DXN.kind.QUEUE, [feed.namespace ?? 'data', self.spaceId, self.echoId]);\n};\n\n//\n// Service\n//\n\n/**\n * Effect service for feed operations.\n * Provides the bridge to the underlying storage implementation.\n * Must be provided by the application layer (e.g., echo-db).\n */\nexport class FeedService extends Context.Tag('@dxos/echo/Feed/FeedService')<\n FeedService,\n {\n /**\n * Appends items to a feed.\n */\n append(feed: Feed, items: Entity.Unknown[]): Promise<void>;\n\n /**\n * Removes items from a feed by ID.\n */\n // TODO(dmaretskyi): Change type to ObjectId.\n remove(feed: Feed, ids: string[]): Promise<void>;\n\n /**\n * Queries items in a feed.\n */\n query: {\n <Q extends Query.Any>(feed: Feed, query: Q): QueryResult.QueryResult<Query.Type<Q>>;\n <F extends Filter.Any>(feed: Feed, filter: F): QueryResult.QueryResult<Filter.Type<F>>;\n };\n\n /**\n * Syncs the feed with the server.\n */\n sync(feed: Feed, options?: SyncOptions): Promise<void>;\n }\n>() {}\n\n/**\n * @deprecated Use `FeedService` instead.\n */\nexport type Service = FeedService;\n\n/**\n * @deprecated Use `FeedService` instead.\n */\nexport const Service = FeedService;\n\n/**\n * Layer that provides a Feed service that throws when accessed.\n * Useful as a default layer when no feed service is available.\n */\nexport const notAvailable: Layer.Layer<FeedService> = Layer.succeed(FeedService, {\n append: () => {\n throw new Error('Feed.FeedService not available');\n },\n remove: () => {\n throw new Error('Feed.FeedService not available');\n },\n query: () => {\n throw new Error('Feed.FeedService not available');\n },\n sync: () => {\n throw new Error('Feed.FeedService not available');\n },\n} as Context.Tag.Service<FeedService>);\n\n//\n// Context (per-call) service\n//\n\n/**\n * Effect service exposing a single `Feed.Feed` as the \"current\" feed for a call site.\n *\n * @deprecated Prefer threading a `Feed.Feed` explicitly through function signatures\n * over hiding it behind a context service.\n */\nexport class ContextFeedService extends Context.Tag('@dxos/echo/Feed/ContextFeedService')<\n ContextFeedService,\n {\n readonly feed: Feed;\n }\n>() {\n static layer = (feed: Feed): Layer.Layer<ContextFeedService> => Layer.succeed(ContextFeedService, { feed });\n}\n\n//\n// Operations\n//\n\n/**\n * Appends items to a feed.\n *\n * @example\n * ```ts\n * yield* Feed.append(feed, [Obj.make(Notification, { title: 'Hello' })]);\n * ```\n */\nexport const append = (feed: Feed, items: Entity.Unknown[]): Effect.Effect<void, never, FeedService> =>\n Effect.gen(function* () {\n const service = yield* FeedService;\n yield* Effect.promise(() => service.append(feed, items));\n });\n\n/**\n * Removes items from a feed.\n *\n * @example\n * ```ts\n * yield* Feed.remove(feed, [item]);\n * ```\n */\n// TODO(dmaretskyi): Should we allow snapshots here? - what does it mean to remove a snapshot?\nexport const remove = (feed: Feed, items: (Entity.Unknown | Obj.Snapshot)[]): Effect.Effect<void, never, FeedService> =>\n Effect.gen(function* () {\n const service = yield* FeedService;\n const ids = items.map((item) => item.id);\n yield* Effect.promise(() => service.remove(feed, ids));\n });\n\n/**\n * Creates a reactive query over items in a feed.\n *\n * @example\n * ```ts\n * const result = yield* Feed.query(feed, Filter.type(Person));\n * ```\n */\n// TODO(dmaretskyi): Suport chained queries:\n// const result = yield* feed.pipe(Feed.query(Filter.type(Person))); result.subscribe(...)\n// const objects = yield* feed.pipe(Feed.query(Filter.type(Person))).run;\n// const object = yield* feed.pipe(Feed.query(Filter.type(Person))).first;\n// ... unify for Database and schema queries.\nexport const query: {\n <Q extends Query.Any>(\n feed: Feed,\n query: Q,\n ): Effect.Effect<QueryResult.QueryResult<Query.Type<Q>>, never, FeedService>;\n <F extends Filter.Any>(\n feed: Feed,\n filter: F,\n ): Effect.Effect<QueryResult.QueryResult<Filter.Type<F>>, never, FeedService>;\n} = (feed: Feed, queryOrFilter: Query.Any | Filter.Any) =>\n FeedService.pipe(Effect.map((service) => service.query(feed, queryOrFilter as any) as QueryResult.QueryResult<any>));\n\n/**\n * Executes a feed query once and returns the results.\n *\n * @example\n * ```ts\n * const items = yield* Feed.runQuery(feed, Filter.type(Person));\n * ```\n */\nexport const runQuery: {\n <Q extends Query.Any>(feed: Feed, query: Q): Effect.Effect<Query.Type<Q>[], never, FeedService>;\n <F extends Filter.Any>(feed: Feed, filter: F): Effect.Effect<Filter.Type<F>[], never, FeedService>;\n} = (feed: Feed, queryOrFilter: Query.Any | Filter.Any) =>\n query(feed, queryOrFilter as any).pipe(Effect.flatMap((queryResult) => Effect.promise(() => queryResult.run())));\n\n/**\n * Syncs the feed with the server.\n *\n * @example\n * ```ts\n * yield* Feed.sync(feed);\n * yield* Feed.sync(feed, { shouldPush: false });\n * ```\n */\nexport const sync = (feed: Feed, options?: SyncOptions): Effect.Effect<void, never, FeedService> =>\n Effect.gen(function* () {\n const service = yield* FeedService;\n yield* Effect.promise(() => service.sync(feed, options));\n });\n\n/**\n * Creates a cursor for iterating over feed items.\n * Currently stubbed — cursor operations are not yet implemented.\n *\n * @example\n * ```ts\n * const cursor = yield* Feed.cursor<Person>(feed);\n * const item = yield* Feed.next(cursor);\n * ```\n */\n// TODO(wittjosiah): Implement cursor operations. Use Effect streams?\nexport const cursor = <T = Obj.Snapshot>(_feed: Feed): Effect.Effect<Cursor<T>, never, FeedService> =>\n Effect.succeed({ _tag: 'Cursor' } as Cursor<T>);\n\n/**\n * Returns the next item from a feed cursor.\n * Currently stubbed — cursor operations are not yet implemented.\n */\nexport const next = <T = Obj.Snapshot>(_cursor: Cursor<T>): Effect.Effect<T, never, FeedService> =>\n Effect.die('Feed.next is not yet implemented');\n\n/**\n * Returns the next item from a feed cursor as an Option.\n * Currently stubbed — cursor operations are not yet implemented.\n */\nexport const nextOption = <T = Obj.Snapshot>(_cursor: Cursor<T>): Effect.Effect<Option.Option<T>, never, FeedService> =>\n Effect.die('Feed.nextOption is not yet implemented');\n\n/**\n * Sets the local retention policy for a feed.\n * Currently stubbed — feeds do not yet support retention.\n *\n * @example\n * ```ts\n * yield* Feed.setRetention(feed, { count: 1000 });\n * ```\n */\n// TODO(dmaretskyi): Implement when feed retention is supported.\nexport const setRetention = (_feed: Feed, _options: RetentionOptions): Effect.Effect<void, never, FeedService> =>\n Effect.void;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["make", "Context", "Effect", "Layer", "Schema", "DXN", "Feed", "Struct", "name", "String", "pipe", "optional", "kind", "FormInputAnnotation", "set", "namespace", "Literal", "object", "typename", "version", "SystemTypeAnnotation", "IconAnnotation", "icon", "hue", "make", "props", "getQueueDxn", "feed", "self", "getDXN", "asEchoDXN", "spaceId", "undefined", "DXN", "QUEUE", "echoId", "FeedService", "Tag", "Service", "notAvailable", "succeed", "append", "Error", "remove", "query", "sync", "ContextFeedService", "layer", "items", "gen", "service", "promise", "ids", "map", "item", "id", "queryOrFilter", "runQuery", "flatMap", "queryResult", "run", "options", "cursor", "_feed", "_tag", "next", "_cursor", "die", "nextOption", "setRetention", "_options", "void"]
|
|
7
|
+
}
|
|
@@ -3,24 +3,24 @@ import {
|
|
|
3
3
|
FormatAnnotation,
|
|
4
4
|
FormatAnnotationId,
|
|
5
5
|
TypeFormat
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TRPZU2HV.mjs";
|
|
7
7
|
import {
|
|
8
8
|
createEchoReferenceSchema
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-BMB7IHGB.mjs";
|
|
10
10
|
import {
|
|
11
11
|
GeneratorAnnotationId,
|
|
12
12
|
LabelAnnotationId,
|
|
13
13
|
PropertyMetaAnnotationId,
|
|
14
14
|
TypeAnnotationId,
|
|
15
15
|
TypeIdentifierAnnotationId
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-TNBK56IN.mjs";
|
|
17
17
|
import {
|
|
18
18
|
ANY_OBJECT_TYPENAME,
|
|
19
19
|
ANY_OBJECT_VERSION,
|
|
20
20
|
EntityKind,
|
|
21
21
|
EntityKindSchema,
|
|
22
22
|
makeTypeJsonSchemaAnnotation
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-N4B7FHQT.mjs";
|
|
24
24
|
|
|
25
25
|
// src/internal/JsonSchema/annotations.ts
|
|
26
26
|
import * as SchemaAST from "effect/SchemaAST";
|
|
@@ -465,12 +465,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
465
465
|
if (root.allOf.length === 1) {
|
|
466
466
|
result = toEffectSchema(root.allOf[0], defs);
|
|
467
467
|
} else {
|
|
468
|
-
log.warn("allOf with multiple schemas is not supported", void 0, {
|
|
469
|
-
F: __dxlog_file,
|
|
470
|
-
L: 223,
|
|
471
|
-
S: void 0,
|
|
472
|
-
C: (f, a) => f(...a)
|
|
473
|
-
});
|
|
468
|
+
log.warn("allOf with multiple schemas is not supported", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 185, S: void 0 });
|
|
474
469
|
result = Schema2.Unknown;
|
|
475
470
|
}
|
|
476
471
|
} else if ("type" in root) {
|
|
@@ -499,15 +494,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
499
494
|
const [required, optional3] = Function.pipe(root.items, Array2.map((v) => toEffectSchema(v, defs)), Array2.splitAt(root.minItems ?? root.items.length));
|
|
500
495
|
result = Schema2.Tuple(...required, ...optional3.map(Schema2.optionalElement));
|
|
501
496
|
} else {
|
|
502
|
-
invariant(root.items, void 0, {
|
|
503
|
-
F: __dxlog_file,
|
|
504
|
-
L: 256,
|
|
505
|
-
S: void 0,
|
|
506
|
-
A: [
|
|
507
|
-
"root.items",
|
|
508
|
-
""
|
|
509
|
-
]
|
|
510
|
-
});
|
|
497
|
+
invariant(root.items, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 219, S: void 0, A: ["root.items", ""] });
|
|
511
498
|
const items = root.items;
|
|
512
499
|
result = Array2.isArray(items) ? Schema2.Tuple(...items.map((v) => toEffectSchema(v, defs))) : Schema2.Array(toEffectSchema(items, defs));
|
|
513
500
|
}
|
|
@@ -521,15 +508,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
521
508
|
} else if ("$ref" in root) {
|
|
522
509
|
const refSegments = root.$ref.split("/");
|
|
523
510
|
const jsonSchema = defs[refSegments[refSegments.length - 1]];
|
|
524
|
-
invariant(jsonSchema, `missing definition for ${root.$ref}`, {
|
|
525
|
-
F: __dxlog_file,
|
|
526
|
-
L: 272,
|
|
527
|
-
S: void 0,
|
|
528
|
-
A: [
|
|
529
|
-
"jsonSchema",
|
|
530
|
-
"`missing definition for ${root.$ref}`"
|
|
531
|
-
]
|
|
532
|
-
});
|
|
511
|
+
invariant(jsonSchema, `missing definition for ${root.$ref}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 234, S: void 0, A: ["jsonSchema", "`missing definition for ${root.$ref}`"] });
|
|
533
512
|
result = toEffectSchema(jsonSchema, defs).pipe(Schema2.annotations({
|
|
534
513
|
identifier: refSegments[refSegments.length - 1]
|
|
535
514
|
}));
|
|
@@ -539,15 +518,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
539
518
|
return result;
|
|
540
519
|
};
|
|
541
520
|
var objectToEffectSchema = (root, defs) => {
|
|
542
|
-
invariant("type" in root && root.type === "object", `not an object: ${root}`, {
|
|
543
|
-
F: __dxlog_file,
|
|
544
|
-
L: 287,
|
|
545
|
-
S: void 0,
|
|
546
|
-
A: [
|
|
547
|
-
"'type' in root && root.type === 'object'",
|
|
548
|
-
"`not an object: ${root}`"
|
|
549
|
-
]
|
|
550
|
-
});
|
|
521
|
+
invariant("type" in root && root.type === "object", `not an object: ${root}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 245, S: void 0, A: ["'type' in root && root.type === 'object'", "`not an object: ${root}`"] });
|
|
551
522
|
const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
552
523
|
const isEchoObject = echoRefinement != null || "$id" in root && typeof root.$id === "string" && root.$id.startsWith("dxn:");
|
|
553
524
|
let fields = {};
|
|
@@ -565,24 +536,8 @@ var objectToEffectSchema = (root, defs) => {
|
|
|
565
536
|
}
|
|
566
537
|
let schema;
|
|
567
538
|
if (root.patternProperties) {
|
|
568
|
-
invariant(propertyList.length === 0, "pattern properties mixed with regular properties are not supported", {
|
|
569
|
-
|
|
570
|
-
L: 313,
|
|
571
|
-
S: void 0,
|
|
572
|
-
A: [
|
|
573
|
-
"propertyList.length === 0",
|
|
574
|
-
"'pattern properties mixed with regular properties are not supported'"
|
|
575
|
-
]
|
|
576
|
-
});
|
|
577
|
-
invariant(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", {
|
|
578
|
-
F: __dxlog_file,
|
|
579
|
-
L: 314,
|
|
580
|
-
S: void 0,
|
|
581
|
-
A: [
|
|
582
|
-
"Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === ''",
|
|
583
|
-
"'only one pattern property is supported'"
|
|
584
|
-
]
|
|
585
|
-
});
|
|
539
|
+
invariant(propertyList.length === 0, "pattern properties mixed with regular properties are not supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 264, S: void 0, A: ["propertyList.length === 0", "'pattern properties mixed with regular properties are not supported'"] });
|
|
540
|
+
invariant(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 265, S: void 0, A: ["Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === ''", "'only one pattern property is supported'"] });
|
|
586
541
|
schema = Schema2.Record({
|
|
587
542
|
key: Schema2.String,
|
|
588
543
|
value: toEffectSchema(root.patternProperties[""], defs)
|
|
@@ -628,15 +583,7 @@ var refToEffectSchema = (root) => {
|
|
|
628
583
|
throw new Error("Invalid reference field in ref schema");
|
|
629
584
|
}
|
|
630
585
|
const targetSchemaDXN = DXN.parse(reference.schema.$ref);
|
|
631
|
-
invariant(targetSchemaDXN.kind === DXN.kind.TYPE, void 0, {
|
|
632
|
-
F: __dxlog_file,
|
|
633
|
-
L: 367,
|
|
634
|
-
S: void 0,
|
|
635
|
-
A: [
|
|
636
|
-
"targetSchemaDXN.kind === DXN.kind.TYPE",
|
|
637
|
-
""
|
|
638
|
-
]
|
|
639
|
-
});
|
|
586
|
+
invariant(targetSchemaDXN.kind === DXN.kind.TYPE, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 314, S: void 0, A: ["targetSchemaDXN.kind === DXN.kind.TYPE", ""] });
|
|
640
587
|
return createEchoReferenceSchema(targetSchemaDXN.toString(), targetSchemaDXN.kind === DXN.kind.TYPE ? targetSchemaDXN.parts[0] : void 0, reference.schemaVersion);
|
|
641
588
|
};
|
|
642
589
|
var annotations_toJsonSchemaFields = (annotations2) => {
|
|
@@ -784,4 +731,4 @@ export {
|
|
|
784
731
|
toJsonSchema,
|
|
785
732
|
toEffectSchema
|
|
786
733
|
};
|
|
787
|
-
//# sourceMappingURL=chunk-
|
|
734
|
+
//# sourceMappingURL=chunk-MLS7U7AT.mjs.map
|