/* eslint-disable @typescript-eslint/no-namespace */ /** * Sort-of-Minimalistic types used to allow `@aws-amplify/api-graphql` to call into * `@aws-amplify/data-schema` without forcing `@aws-amplify/data-schema` to become the * bucket for ALL of those types. * * In other words, types that relate to GraphQL category operations apart from the * gen2/modeled operations should continue to live in `@aws-amplify/api-graphql`. And, * `@aws-amplify/data-schema` should ideally only define those types/interfaces that are * necessary to safely extend a graphql client. */ import { Observable } from 'rxjs'; import { CustomHeaders, ModelSortDirection } from './client'; import { AiAction, AiCategory } from './internals/ai/getCustomUserAgentDetails'; import { CustomType } from '../CustomType'; import { RefType } from '../RefType'; export declare namespace AmplifyServer { export interface ContextToken { readonly value: symbol; } export interface ContextSpec { readonly token: ContextToken; } } export interface AmplifyClass { getConfig(): Readonly; // truncated } export interface ResourcesConfig { API?: APIConfig; // truncated. } interface APIRestConfig { /** * Required REST endpoint, must be a valid URL string. */ endpoint: string; /** * Optional region string used to sign the request with IAM credentials. If Omitted, region will be extracted from * the endpoint. * * @default 'us-east-1' */ region?: string; /** * Optional service name string to sign the request with IAM credentials. *s * @default 'execute-api' */ service?: string; } export interface RESTProviderConfig { REST: Record; } export type AtLeastOne }> = Partial & U[keyof U]; export type APIConfig = AtLeastOne; export interface GraphQLProviderConfig { readonly GraphQL: { modelIntrospection?: ModelIntrospectionSchema; }; } /** * * TODO: Have @aws-amplify/core import these types from here? * */ /** * Root model instrospection schema shape. * * Borrowed from: https://github.com/aws-amplify/samsara-cli/pull/377/commits/c08ea2c1a43f36aafe63b6d14d03f884e9c0c671#diff-21ae6faa2f22c15bb25ff9b272eaab7846c0650e2d267ab720546c19559583d0R4-R108 */ export interface ModelIntrospectionSchema { version: 1; models: SchemaModels; nonModels: SchemaNonModels; enums: SchemaEnums; queries?: CustomOperations; mutations?: CustomOperations; subscriptions?: CustomOperations; conversations?: SchemaConversationRoutes; generations?: SchemaGenerationRoutes; } /** * Top-level Entities on a Schema */ export type SchemaModels = Record; export type SchemaNonModels = Record; export type SchemaEnums = Record; export type CustomOperations = Record; export type SchemaConversationRoutes = Record; export type SchemaGenerationRoutes = Record; export type SchemaConversationRoute = { name: string; models: SchemaModels; nonModels: SchemaNonModels; enums: SchemaEnums; conversation: SchemaConversation; message: SchemaConversationMessage; }; export type SchemaConversation = { modelName: string; }; export type SchemaConversationMessage = { modelName: string; subscribe: CustomOperation; send: CustomOperation; }; export interface SchemaModel { name: string; attributes?: ModelAttribute[]; fields: Fields; pluralName: string; syncable?: boolean; primaryKeyInfo: PrimaryKeyInfo; } export interface SchemaNonModel { name: string; fields: Fields; } export interface SchemaEnum { name: string; values: string[]; } export interface ModelAttribute { type: string; properties?: Record; } export interface SecondaryIndexAttribute { type: 'key'; properties: { name: string; queryField: string; fields: string[]; }; } export interface CustomOperation { name: string; type: FieldType; isArray: boolean; isRequired: boolean; arguments?: CustomOperationArguments; } export type CustomOperationArguments = Record; export interface CustomOperationArgument { name: string; type: InputFieldType; isArray: boolean; isRequired: boolean; isArrayNullable?: boolean; } /** * Field Definition */ export type Fields = Record; export interface Field { name: string; type: FieldType; isArray: boolean; isRequired: boolean; isReadOnly?: boolean; isArrayNullable?: boolean; attributes?: FieldAttribute[]; association?: AssociationType; } export type DocumentType = | null | boolean | number | string | DocumentType[] | { [prop: string]: DocumentType }; export type GraphQLAuthMode = | 'apiKey' | 'oidc' | 'userPool' | 'iam' | 'identityPool' | 'lambda' | 'none'; export interface ModelFieldType { model: string; } export interface NonModelFieldType { nonModel: string; } export interface EnumType { enum: string; } export interface InputType { input: string; } type ScalarType = | 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime' | 'AWSDateTime' | 'AWSTimestamp' | 'AWSEmail' | 'AWSURL' | 'AWSIPAddress' | 'Boolean' | 'AWSJSON' | 'AWSPhone'; export type FieldType = | ScalarType | EnumType | ModelFieldType | NonModelFieldType; export type InputFieldType = | ScalarType | EnumType | InputType | CustomType | RefType; export type FieldAttribute = ModelAttribute; /** * Field-level Relationship Definitions */ export enum CodeGenConnectionType { HAS_ONE = 'HAS_ONE', BELONGS_TO = 'BELONGS_TO', HAS_MANY = 'HAS_MANY', } export interface AssociationBaseType { connectionType: CodeGenConnectionType; } export type AssociationHasMany = AssociationBaseType & { connectionType: CodeGenConnectionType.HAS_MANY; associatedWith: string[]; }; export type AssociationHasOne = AssociationBaseType & { connectionType: CodeGenConnectionType.HAS_ONE; associatedWith: string[]; targetNames: string[]; }; export type AssociationBelongsTo = AssociationBaseType & { connectionType: CodeGenConnectionType.BELONGS_TO; targetNames: string[]; }; export type AssociationType = | AssociationHasMany | AssociationHasOne | AssociationBelongsTo; export interface PrimaryKeyInfo { isCustomPrimaryKey: boolean; primaryKeyFieldName: string; sortKeyFieldNames: string[]; } /** * HUB */ export type IListener< Channel extends string = AmplifyChannel | string, EventData extends EventDataMap = EventDataMap, > = { name: string; callback: HubCallback; }[]; export interface EventDataMap { event: string; data?: unknown; } export interface AmplifyEventData { auth: any; // edited: generalized for bridge type [key: string]: EventDataMap; } export type AmplifyChannel = 'auth'; export type StopListenerCallback = () => void; export interface HubCapsule< Channel extends string, EventData extends EventDataMap, > { channel: Channel; payload: HubPayload; source?: string; patternInfo?: string[]; } export type HubCallback< Channel extends string = string, EventData extends EventDataMap = EventDataMap, > = (capsule: HubCapsule) => void; export type HubPayload = EventData & { message?: string; }; export interface AmplifyHubCallbackMap { auth: HubCallback; } /** * Loose/Unknown options for raw GraphQLAPICategory `graphql()`. */ export interface GraphQLOptions { query: string; variables?: Record; authMode?: GraphQLAuthMode; authToken?: string; /** * @deprecated This property should not be used */ userAgentSuffix?: string; } export interface GraphQLResult { data: any; errors?: Record[]; extensions?: Record; } export type GraphqlSubscriptionResult = Observable<{ data: Record; }>; /** * @private * * The knobs available for configuring `server/generateClient` internally. */ export interface ServerClientGenerationParams { amplify: | null // null expected when used with `generateServerClient` // closure expected with `generateServerClientUsingCookies` | ((fn: (amplify: AmplifyClass) => Promise) => Promise); // global env-sourced config use for retrieving modelIntro config: ResourcesConfig; } export type QueryArgs = Record; export interface ListArgs extends Record { selectionSet?: string[]; filter?: Record; sortDirection?: ModelSortDirection; headers?: CustomHeaders; } export interface AuthModeParams extends Record { authMode?: GraphQLAuthMode; authToken?: string; } export interface GenerateServerClientParams { config: ResourcesConfig; authMode?: GraphQLAuthMode; authToken?: string; } export type ClientInternals = { amplify: AmplifyClass; authMode: GraphQLAuthMode | undefined; authToken: string | undefined; headers: CustomHeaders | undefined; }; export type ClientInternalsGetter = (client: BaseClient) => ClientInternals; export type BaseClient = BaseBrowserClient | BaseSSRClient; export type BaseBrowserClient = { graphql: GraphQLMethod; cancel(promise: Promise, message?: string): boolean; isCancelError(error: any): boolean; }; export type BaseSSRClient = { graphql: GraphQLMethodSSR; cancel(promise: Promise, message?: string): boolean; isCancelError(error: any): boolean; }; export interface CustomUserAgentDetails { category: AiCategory; action: AiAction; } export type GraphQLMethod = ( options: GraphQLOptions, additionalHeaders?: CustomHeaders | undefined, customUserAgentDetails?: CustomUserAgentDetails, ) => Promise | GraphqlSubscriptionResult; export type GraphQLMethodSSR = ( contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptions, additionalHeaders?: CustomHeaders | undefined, ) => Promise | GraphqlSubscriptionResult;