/** * Common types used by ComposeDB packages. * * @module types */ import type { FieldsIndex } from '@ceramicnetwork/common'; import type { Ceramic } from '@ceramicnetwork/core'; import type { CeramicClient } from '@ceramicnetwork/http-client'; import type { ModelAccountRelationV2, ModelDefinition, ModelViewsDefinitionV2 } from '@ceramicnetwork/stream-model'; import type { DagJWSResult, JWSSignature } from 'dids'; export type { FieldsIndex } from '@ceramicnetwork/common'; export type { Model, ModelDefinition } from '@ceramicnetwork/stream-model'; export type { ModelInstanceDocument } from '@ceramicnetwork/stream-model-instance'; export type { JSONSchema } from 'json-schema-typed/draft-2020-12'; export type CeramicAPI = Ceramic | CeramicClient; /** JSON-encoded DAG-JWS. */ export type EncodedDagJWS = { payload: string; signatures: Array; link?: string; }; /** JSON-encoded DAG-JWS result representing a Ceramic stream commit. */ export type EncodedDagJWSResult = { jws: EncodedDagJWS; linkedBlock: string; }; /** Ceramic stream commits for a given stream. */ export type StreamCommits = Array; /** JSON-encoded Ceramic stream commits for a given stream. */ export type EncodedStreamCommits = Array; /** Composite-level views definition. */ export type CompositeViewsDefinition = { account?: Record; root?: Record; models?: Record; }; /** * Composite definition type factory, used both for encoded and internal composites definitions. */ export type CompositeDefinitionType = { /** * Version of the composite format. */ version: string; /** * Models defined in the composite, keyed by stream ID. */ models: Record; /** * Optional mapping of model stream ID to alias name. */ aliases?: Record; /** * Optional composite-level views. */ views?: CompositeViewsDefinition; /** * Optional composite-level indices */ indices?: Record>; /** * Optional common embeds (enums and objects) shared by models in the composite. */ commonEmbeds?: Array; }; /** * Composite definition used internally by the {@linkcode devtools.Composite Composite} * development tools. */ export type InternalCompositeDefinition = CompositeDefinitionType; /** JSON-encoded composite definition. */ export type EncodedCompositeDefinition = CompositeDefinitionType; /** Common runtime scalar properties. */ export type RuntimeScalarCommon = { required: boolean; indexed?: boolean; immutable?: boolean; }; /** Runtime scalar representation for a boolean. */ export type RuntimeBooleanScalar = RuntimeScalarCommon & { type: 'boolean'; }; /** Runtime scalar representation for an integer. */ export type RuntimeIntegerScalar = RuntimeScalarCommon & { type: 'integer'; }; /** Runtime scalar representation for a float. */ export type RuntimeFloatScalar = RuntimeScalarCommon & { type: 'float'; }; /** Runtime scalar representation for a string. */ export type RuntimeStringScalar = RuntimeScalarCommon & { type: 'string'; maxLength?: number; }; /** Ceramic-specific runtime scalar types. */ export type CustomRuntimeScalarType = 'accountid' | 'chainid' | 'cid' | 'commitid' | 'countrycode' | 'date' | 'datetime' | 'did' | 'duration' | 'id' | 'latitude' | 'localdate' | 'locale' | 'localtime' | 'longitude' | 'streamid' | 'time' | 'timezone' | 'uri' | 'utcoffset'; type RuntimeStringScalarType = RuntimeScalarCommon & { type: Type; maxLength?: number; }; /** Runtime scalar representations. */ export type RuntimeScalar = RuntimeBooleanScalar | RuntimeIntegerScalar | RuntimeFloatScalar | RuntimeStringScalar | RuntimeStringScalarType; /** Runtime scalar types. */ export type RuntimeScalarType = RuntimeScalar['type']; /** Runtime references types. */ export type RuntimeReferenceType = 'connection' | 'enum' | 'node' | 'object'; /** Runtime reference representation. */ export type RuntimeReference = RuntimeScalarCommon & { type: 'reference'; refType: T; refName: string; }; /** Runtime list representation. */ export type RuntimeList = RuntimeScalarCommon & { type: 'list'; item: RuntimeScalar | RuntimeReference<'enum' | 'object'>; }; /** Runtime meta types. */ export type RuntimeMetaType = 'objectType'; /** Runtime meta field representation. */ export type RuntimeMetaField = { type: 'meta'; metaType: RuntimeMetaType; }; /** Runtime relation source. */ export type RuntimeRelationSource = 'document' | 'queryConnection' | 'queryCount' | 'set'; /** Runtime relation field representation. */ export type RuntimeRelation = { source: RuntimeRelationSource; model: string | null; property: string; }; /** Runtime view types. */ export type RuntimeViewType = 'documentAccount' | 'documentVersion'; /** Runtime view field representation. */ export type RuntimeViewField = { type: 'view'; viewType: 'relation'; relation: RuntimeRelation; } | { type: 'view'; viewType: RuntimeViewType; }; /**Runtime object fields representations. */ export type RuntimeObjectField = RuntimeScalar | RuntimeList | RuntimeReference | RuntimeMetaField | RuntimeViewField; /** Runtime object property name to field representation mapping. */ export type RuntimeObjectFields = Record; /** Runtime views account reference types. */ export type RuntimeViewAccountReferenceType = 'account' | 'account-set'; /** Runtime views document reference types. */ export type RuntimeViewDocumentReferenceType = 'connection' | 'node' | 'set'; /** Runtime view reference representation. */ export type RuntimeViewReference = { type: RuntimeViewAccountReferenceType; name: string; property: string; } | { type: RuntimeViewDocumentReferenceType; name: string; }; /** Runtime model information. */ export type RuntimeModel = { id: string; interface: boolean; implements: Array; accountRelation: ModelAccountRelationV2; }; /** * Runtime composite definition, used by the {@linkcode client.ComposeClient ComposeClient class} to * create a GraphQL schema to interact with. */ export type RuntimeCompositeDefinition = { /** * Models names to runtime models mapping. */ models: Record; /** * Objects structures, keyed by name. */ objects: Record; /** * String enums, keyed by name. */ enums: Record>; /** * Account-based relations. */ accountData: Record; /** * Optional query-level entry-points. */ query?: Record; };