import { type CreatePropertyParams, Id as Grc20Id, type Op } from '@geoprotocol/geo-sdk'; import { Schema as EffectSchema } from 'effect'; /** * Mappings for a schema type and its properties/relations * * @since 0.2.0 */ export type MappingEntry = { /** * Array of the `Id` of the type in the Knowledge Graph. * Is an array because a type can belong to multiple spaces/extend multiple types. * * @since 0.2.0 */ typeIds: Array; /** * Record of property names to the `Id` of the type in the Knowledge Graph * * @since 0.2.0 */ properties?: { [key: string]: Grc20Id; } | undefined; /** * Record of relation properties to the `Id` of the type in the Knowledge Graph * * @since 0.2.0 */ relations?: { [key: string]: Grc20Id; } | undefined; }; /** * @example * ```ts * import { Id } from '@graphprotocol/hypergraph' * import type { Mapping } from '@graphprotocol/hypergraph/mapping' * * const mapping: Mapping = { * Account: { * typeIds: [Id('a5fd07b1120f46c6b46f387ef98396a6')], * properties: { * username: Id('994edcff69964a779797a13e5e3efad8'), * createdAt: Id('64bfba51a69b4746be4b213214a879fe') * } * }, * Event: { * typeIds: [Id('0349187b526f435fb2bb9e9caf23127a')], * properties: { * name: Id('3808e060fb4a4d08806935b8c8a1902b'), * description: Id('1f0d90078da24b28ab9f3bc0709f4837'), * }, * relations: { * speaker: Id('a5fd07b1120f46c6b46f387ef98396a6') * } * } * } * ``` * * @since 0.2.0 */ export type Mapping = { [key: string]: MappingEntry; }; /** * @since 0.2.0 */ export type DataTypeRelation = `Relation(${string})`; /** * @since 0.2.0 */ export declare function isDataTypeRelation(val: string): val is DataTypeRelation; /** * @since 0.2.0 */ export declare const SchemaDataTypeRelation: EffectSchema.refine<`Relation(${string})`, EffectSchema.Schema>; /** * @since 0.2.0 */ export type SchemaDataTypeRelation = typeof SchemaDataTypeRelation.Type; /** * @since 0.2.0 */ export declare const SchemaDataTypePrimitive: EffectSchema.Literal<["String", "Number", "Boolean", "Date", "Point"]>; /** * @since 0.2.0 */ export type SchemaDataTypePrimitive = typeof SchemaDataTypePrimitive.Type; /** * @since 0.4.0 */ export declare function isDataTypePrimitive(val: string): val is SchemaDataTypePrimitive; /** * @since 0.2.0 */ export declare const SchemaDataType: EffectSchema.Union<[EffectSchema.Literal<["String", "Number", "Boolean", "Date", "Point"]>, EffectSchema.refine<`Relation(${string})`, EffectSchema.Schema>]>; /** * @since 0.2.0 */ export type SchemaDataType = typeof SchemaDataType.Type; /** * @since 0.4.0 */ export declare function isDataType(val: string): val is SchemaDataType; /** * @since 0.4.0 */ export declare function getDataType(val: string): SchemaDataType; /** * @since 0.2.0 */ export declare const SchemaTypePropertyRelation: EffectSchema.Struct<{ dataType: EffectSchema.refine<`Relation(${string})`, EffectSchema.Schema>; relationType: EffectSchema.refine; name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; optional: EffectSchema.optional>; }>; /** * @since 0.2.0 */ export type SchemaTypePropertyRelation = typeof SchemaTypePropertyRelation.Type; /** * @since 0.2.0 */ export declare const SchemaTypePropertyPrimitive: EffectSchema.Struct<{ dataType: EffectSchema.Literal<["String", "Number", "Boolean", "Date", "Point"]>; name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; optional: EffectSchema.optional>; }>; /** * @since 0.2.0 */ export type SchemaTypePropertyPrimitive = typeof SchemaTypePropertyPrimitive.Type; /** * @since 0.2.0 */ export declare function propertyIsRelation(property: SchemaTypePropertyPrimitive | SchemaTypePropertyRelation): property is SchemaTypePropertyRelation; /** * @since 0.2.0 */ export declare const SchemaType: EffectSchema.Struct<{ name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; properties: EffectSchema.filter; name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; optional: EffectSchema.optional>; }>, EffectSchema.Struct<{ dataType: EffectSchema.refine<`Relation(${string})`, EffectSchema.Schema>; relationType: EffectSchema.refine; name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; optional: EffectSchema.optional>; }>]>>>>; }>; /** * @since 0.2.0 */ export type SchemaType = typeof SchemaType.Type; /** * Represents the user-built schema object to generate a `Mappings` definition for * * @since 0.2.0 */ export declare const Schema: EffectSchema.Struct<{ types: EffectSchema.filter>; properties: EffectSchema.filter; name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; optional: EffectSchema.optional>; }>, EffectSchema.Struct<{ dataType: EffectSchema.refine<`Relation(${string})`, EffectSchema.Schema>; relationType: EffectSchema.refine; name: typeof EffectSchema.NonEmptyTrimmedString; knowledgeGraphId: EffectSchema.NullOr>; optional: EffectSchema.optional>; }>]>>>>; }>>>>>; }>; /** * @since 0.2.0 */ export type Schema = typeof Schema.Type; /** * @since 0.2.0 */ export declare const SchemaKnownDecoder: (i: { readonly types: readonly { readonly name: string; readonly knowledgeGraphId: string | null; readonly properties: readonly ({ readonly name: string; readonly knowledgeGraphId: string | null; readonly dataType: string; readonly relationType: string; readonly optional?: boolean | null | undefined; } | { readonly name: string; readonly knowledgeGraphId: string | null; readonly dataType: "String" | "Number" | "Boolean" | "Date" | "Point"; readonly optional?: boolean | null | undefined; })[]; }[]; }, overrideOptions?: import("effect/SchemaAST").ParseOptions) => { readonly types: readonly { readonly name: string; readonly knowledgeGraphId: string | null; readonly properties: readonly ({ readonly name: string; readonly knowledgeGraphId: string | null; readonly optional?: boolean | null | undefined; readonly dataType: `Relation(${string})`; readonly relationType: string; } | { readonly name: string; readonly knowledgeGraphId: string | null; readonly optional?: boolean | null | undefined; readonly dataType: "String" | "Number" | "Boolean" | "Date" | "Point"; })[]; }[]; }; /** * @since 0.2.0 */ export declare const SchemaUnknownDecoder: (u: unknown, overrideOptions?: import("effect/SchemaAST").ParseOptions) => { readonly types: readonly { readonly name: string; readonly knowledgeGraphId: string | null; readonly properties: readonly ({ readonly name: string; readonly knowledgeGraphId: string | null; readonly optional?: boolean | null | undefined; readonly dataType: `Relation(${string})`; readonly relationType: string; } | { readonly name: string; readonly knowledgeGraphId: string | null; readonly optional?: boolean | null | undefined; readonly dataType: "String" | "Number" | "Boolean" | "Date" | "Point"; })[]; }[]; }; /** * Iterate through all properties in all types in the schema of `dataType` === `Relation(${string})` * and validate that the schema.types have a type for the existing relation * * @example All types exist * ```ts * import { allRelationPropertyTypesExist, type Mapping } from '@graphprotocol/hypergraph/mapping' * * const types: Mapping['types'] = [ * { * name: "Account", * knowledgeGraphId: null, * properties: [ * { * name: "username", * dataType: "String", * knowledgeGraphId: null * } * ] * }, * { * name: "Event", * knowledgeGraphId: null, * properties: [ * { * name: "speaker", * dataType: "Relation(Account)" * relationType: "Account", * knowledgeGraphId: null, * } * ] * } * ] * expect(allRelationPropertyTypesExist(types)).toEqual(true) * ``` * * @example Account type is missing * ```ts * import { allRelationPropertyTypesExist, type Mapping } from '@graphprotocol/hypergraph/mapping' * * const types: Mapping['types'] = [ * { * name: "Event", * knowledgeGraphId: null, * properties: [ * { * name: "speaker", * dataType: "Relation(Account)", * relationType: "Account", * knowledgeGraphId: null, * } * ] * } * ] * expect(allRelationPropertyTypesExist(types)).toEqual(false) * ``` * * @since 0.2.0 * * @param types the user-submitted schema types */ export declare function allRelationPropertyTypesExist(types: ReadonlyArray): boolean; export type GenerateMappingResult = [mapping: Mapping, ops: ReadonlyArray]; /** * Takes the user-submitted schema, validates it, and build the `Mapping` definition for the schema as well as the GRC-20 Ops needed to publish the schema/schema changes to the Knowledge Graph. * * @example * ```ts * import { Id } from "@geoprotocol/geo-sdk" * import { generateMapping } from "@graphprotocol/hypergraph" * * const schema: Schema = { * types: [ * { * name: "Account", * knowledgeGraphId: "a5fd07b1120f46c6b46f387ef98396a6", * properties: [ * { * name: "username", * dataType: "String", * knowledgeGraphId: "994edcff69964a779797a13e5e3efad8" * }, * { * name: "createdAt", * dataType: "Date", * knowledgeGraphId: null * } * ] * }, * { * name: "Event", * knowledgeGraphId: null, * properties: [ * { * name: "name", * dataType: "String", * knowledgeGraphId: "3808e060fb4a4d08806935b8c8a1902b" * }, * { * name: "description", * dataType: "String", * knowledgeGraphId: null * }, * { * name: "speaker", * dataType: "Relation(Account)", * relationType: "Account", * knowledgeGraphId: null * } * ] * } * ], * } * const [mapping, ops] = generateMapping(schema) * * expect(mapping).toEqual({ * Account: { * typeIds: [Id("a5fd07b1120f46c6b46f387ef98396a6")], // comes from input schema * properties: { * username: Id("994edcff69964a779797a13e5e3efad8"), // comes from input schema * createdAt: Id("8cd7d9aca87842878000e71e6f853117"), // generated from Graph.createProperty Op * } * }, * Event: { * typeIds: [Id("20b3fe398e6241a0b9cb92743fd760da")], // generated from Graph.createType Op * properties: { * name: Id("3808e060fb4a4d08806935b8c8a1902b"), // comes from input schema * description: Id("8fc4e17c75814d6ca712943385afc7b5"), // generated from Graph.createProperty Op * }, * relations: { * speaker: Id("651ce59f643b4931bf7a5dc0ca0f5a47"), // generated from Graph.createProperty Op * } * } * }) * expect(ops).toEqual([ * // Graph.createProperty Op for Account.createdAt property * { * type: "CREATE_PROPERTY", * property: { * id: Id("8cd7d9aca87842878000e71e6f853117"), * dataType: "String" * } * }, * // Graph.createProperty Op for Event.description property * { * type: "CREATE_PROPERTY", * property: { * id: Id("8fc4e17c75814d6ca712943385afc7b5"), * dataType: "String" * } * }, * // Graph.createProperty Op for Event.speaker property * { * type: "CREATE_PROPERTY", * property: { * id: Id("651ce59f643b4931bf7a5dc0ca0f5a47"), * dataType: "RELATION" * } * }, * // Graph.createType Op for Event type * { * type: "CREATE_PROPERTY", * property: { * id: Id("651ce59f643b4931bf7a5dc0ca0f5a47"), * dataType: "RELATION" * } * }, * ]) * ``` * * @since 0.2.0 * * @param input user-built and submitted schema * @returns the generated [Mapping] definition from the submitted schema as well as the GRC-20 Ops required to publish the schema to the Knowledge Graph */ export declare function generateMapping(input: Schema): GenerateMappingResult; declare const RelationValueTypeDoesNotExistError_base: new = {}>(args: import("effect/Types").Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "/typesync/errors/RelationValueTypeDoesNotExistError"; } & Readonly; export declare class RelationValueTypeDoesNotExistError extends RelationValueTypeDoesNotExistError_base<{ readonly message: string; readonly property: string; readonly relatedType: string; }> { } /** * @since 0.2.0 * * @param dataType the dataType from the user-submitted schema * @returns the mapped to GRC-20 dataType for the GRC-20 ops */ export declare function mapSchemaDataTypeToGRC20PropDataType(dataType: SchemaDataType): CreatePropertyParams['dataType']; export {}; //# sourceMappingURL=Mapping.d.ts.map