import { ModelInstanceCreator } from './datastore/datastore'; import { PredicateAll } from './predicates'; import { GRAPHQL_AUTH_MODE } from 'nono-aws-amplify/api-graphql'; import { Adapter } from './storage/adapter'; export declare type Schema = UserSchema & { version: string; }; export declare type UserSchema = { models: SchemaModels; nonModels?: SchemaNonModels; relationships?: RelationshipType; keys?: ModelKeys; enums: SchemaEnums; modelTopologicalOrdering?: Map; }; export declare type InternalSchema = { namespaces: SchemaNamespaces; version: string; }; export declare type SchemaNamespaces = Record; export declare type SchemaNamespace = UserSchema & { name: string; }; export declare type SchemaModels = Record; export declare type SchemaModel = { name: string; pluralName: string; attributes?: ModelAttributes; fields: ModelFields; syncable?: boolean; }; export declare function isSchemaModel(obj: any): obj is SchemaModel; export declare type SchemaNonModels = Record; export declare type SchemaNonModel = { name: string; fields: ModelFields; }; declare type SchemaEnums = Record; declare type SchemaEnum = { name: string; values: string[]; }; export declare type ModelAssociation = AssociatedWith | TargetNameAssociation; declare type AssociatedWith = { connectionType: 'HAS_MANY' | 'HAS_ONE'; associatedWith: string; targetName?: string; }; export declare function isAssociatedWith(obj: any): obj is AssociatedWith; declare type TargetNameAssociation = { connectionType: 'BELONGS_TO'; targetName: string; }; export declare function isTargetNameAssociation(obj: any): obj is TargetNameAssociation; export declare type ModelAttributes = ModelAttribute[]; declare type ModelAttribute = { type: string; properties?: Record; }; export declare type ModelAuthRule = { allow: string; provider?: string; operations?: string[]; ownerField?: string; identityClaim?: string; groups?: string[]; groupClaim?: string; groupsField?: string; }; export declare type ModelAttributeAuth = { type: 'auth'; properties: { rules: ModelAuthRule[]; }; }; export declare function isModelAttributeAuth(attr: ModelAttribute): attr is ModelAttributeAuth; declare type ModelAttributeKey = { type: 'key'; properties: { name?: string; fields: string[]; }; }; declare type ModelAttributePrimaryKey = { type: 'key'; properties: { fields: string[]; }; }; declare type ModelAttributeCompositeKey = { type: 'key'; properties: { name: string; fields: [string, string, string, string?, string?]; }; }; export declare function isModelAttributeKey(attr: ModelAttribute): attr is ModelAttributeKey; export declare function isModelAttributePrimaryKey(attr: ModelAttribute): attr is ModelAttributePrimaryKey; export declare function isModelAttributeCompositeKey(attr: ModelAttribute): attr is ModelAttributeCompositeKey; export declare type ModelAttributeAuthProperty = { allow: ModelAttributeAuthAllow; identityClaim?: string; groupClaim?: string; groups?: string[]; operations?: string[]; ownerField?: string; provider?: ModelAttributeAuthProvider; }; export declare enum ModelAttributeAuthAllow { CUSTOM = "custom", OWNER = "owner", GROUPS = "groups", PRIVATE = "private", PUBLIC = "public" } export declare enum ModelAttributeAuthProvider { FUNCTION = "function", USER_POOLS = "userPools", OIDC = "oidc", IAM = "iam", API_KEY = "apiKey" } export declare type ModelFields = Record; export declare enum GraphQLScalarType { ID = 0, String = 1, Int = 2, Float = 3, Boolean = 4, AWSDate = 5, AWSTime = 6, AWSDateTime = 7, AWSTimestamp = 8, AWSEmail = 9, AWSJSON = 10, AWSURL = 11, AWSPhone = 12, AWSIPAddress = 13 } export declare namespace GraphQLScalarType { function getJSType(scalar: keyof Omit): 'string' | 'number' | 'boolean' | 'object'; function getValidationFunction(scalar: keyof Omit): ((val: string | number) => boolean) | undefined; } export declare type AuthorizationRule = { identityClaim: string; ownerField: string; provider: 'userPools' | 'oidc' | 'iam' | 'apiKey'; groupClaim: string; groups: [string]; authStrategy: 'owner' | 'groups' | 'private' | 'public'; areSubscriptionsPublic: boolean; }; export declare function isGraphQLScalarType(obj: any): obj is keyof Omit; export declare type ModelFieldType = { model: string; }; export declare function isModelFieldType(obj: any): obj is ModelFieldType; export declare type NonModelFieldType = { nonModel: string; }; export declare function isNonModelFieldType(obj: any): obj is NonModelFieldType; declare type EnumFieldType = { enum: string; }; export declare function isEnumFieldType(obj: any): obj is EnumFieldType; export declare type ModelField = { name: string; type: keyof Omit | ModelFieldType | NonModelFieldType | EnumFieldType; isArray: boolean; isRequired?: boolean; isReadOnly?: boolean; isArrayNullable?: boolean; association?: ModelAssociation; attributes?: ModelAttributes[]; }; export declare type NonModelTypeConstructor = { new (init: T): T; }; export declare type PersistentModelConstructor = { new (init: ModelInit): T; copyOf(src: T, mutator: (draft: MutableModel) => void): T; }; export declare type TypeConstructorMap = Record | NonModelTypeConstructor>; export declare type PersistentModelMetaData = { readOnlyFields: string; }; export declare type PersistentModel = Readonly<{ id: string; } & Record>; export declare type ModelInit = Omit; declare type DeepWritable = { -readonly [P in keyof T]: T[P] extends TypeName ? T[P] : DeepWritable; }; export declare type MutableModel, K extends PersistentModelMetaData = { readOnlyFields: 'createdAt' | 'updatedAt'; }> = DeepWritable> & Readonly>; export declare type ModelInstanceMetadata = { id: string; _version: number; _lastChangedAt: number; _deleted: boolean; }; export declare enum OpType { INSERT = "INSERT", UPDATE = "UPDATE", DELETE = "DELETE" } export declare type SubscriptionMessage = Pick, 'opType' | 'element' | 'model' | 'condition'>; export declare type InternalSubscriptionMessage = { opType: OpType; element: T; model: PersistentModelConstructor; condition: PredicatesGroup | null; savedElement?: T; }; export declare type DataStoreSnapshot = { items: T[]; isSynced: boolean; }; export declare type PredicateExpression = TypeName extends keyof MapTypeToOperands ? (operator: keyof MapTypeToOperands[TypeName], operand: MapTypeToOperands[TypeName][keyof MapTypeToOperands[TypeName]]) => ModelPredicate : never; declare type EqualityOperators = { ne: T; eq: T; }; declare type ScalarNumberOperators = EqualityOperators & { le: T; lt: T; ge: T; gt: T; }; declare type NumberOperators = ScalarNumberOperators & { between: [T, T]; }; declare type StringOperators = ScalarNumberOperators & { beginsWith: T; contains: T; notContains: T; }; declare type BooleanOperators = EqualityOperators; declare type ArrayOperators = { contains: T; notContains: T; }; export declare type AllOperators = NumberOperators & StringOperators & ArrayOperators; declare type MapTypeToOperands = { number: NumberOperators>; string: StringOperators>; boolean: BooleanOperators>; 'number[]': ArrayOperators; 'string[]': ArrayOperators; 'boolean[]': ArrayOperators; }; declare type TypeName = T extends string ? 'string' : T extends number ? 'number' : T extends boolean ? 'boolean' : T extends string[] ? 'string[]' : T extends number[] ? 'number[]' : T extends boolean[] ? 'boolean[]' : never; export declare type PredicateGroups = { and: (predicate: (predicate: ModelPredicate) => ModelPredicate) => ModelPredicate; or: (predicate: (predicate: ModelPredicate) => ModelPredicate) => ModelPredicate; not: (predicate: (predicate: ModelPredicate) => ModelPredicate) => ModelPredicate; }; export declare type ModelPredicate = { [K in keyof M]-?: PredicateExpression>; } & PredicateGroups; export declare type ProducerModelPredicate = (condition: ModelPredicate) => ModelPredicate; export declare type PredicatesGroup = { type: keyof PredicateGroups; predicates: (PredicateObject | PredicatesGroup)[]; }; export declare function isPredicateObj(obj: any): obj is PredicateObject; export declare function isPredicateGroup(obj: any): obj is PredicatesGroup; export declare type PredicateObject = { field: keyof T; operator: keyof AllOperators; operand: any; }; export declare enum QueryOne { FIRST = 0, LAST = 1 } export declare type GraphQLField = { [field: string]: { [operator: string]: string | number | [number, number]; }; }; export declare type GraphQLCondition = Partial; export declare type GraphQLFilter = Partial; export declare type ProducerPaginationInput = { sort?: ProducerSortPredicate; limit?: number; page?: number; }; export declare type ObserveQueryOptions = Pick, 'sort'>; export declare type PaginationInput = { sort?: SortPredicate; limit?: number; page?: number; }; export declare type ProducerSortPredicate = (condition: SortPredicate) => SortPredicate; export declare type SortPredicate = { [K in keyof T]-?: SortPredicateExpression>; }; export declare type SortPredicateExpression = TypeName extends keyof MapTypeToOperands ? (sortDirection: keyof typeof SortDirection) => SortPredicate : never; export declare enum SortDirection { ASCENDING = "ASCENDING", DESCENDING = "DESCENDING" } export declare type SortPredicatesGroup = SortPredicateObject[]; export declare type SortPredicateObject = { field: keyof T; sortDirection: keyof typeof SortDirection; }; export declare type SystemComponent = { setUp(schema: InternalSchema, namespaceResolver: NamespaceResolver, modelInstanceCreator: ModelInstanceCreator, getModelConstructorByModelName: (namsespaceName: string, modelName: string) => PersistentModelConstructor, appId: string): Promise; }; export declare type NamespaceResolver = (modelConstructor: PersistentModelConstructor) => string; export declare type ControlMessageType = { type: T; data?: any; }; export declare type RelationType = { fieldName: string; modelName: string; relationType: 'HAS_ONE' | 'HAS_MANY' | 'BELONGS_TO'; targetName?: string; associatedWith?: string; }; export declare type RelationshipType = { [modelName: string]: { indexes: string[]; relationTypes: RelationType[]; }; }; export declare type KeyType = { primaryKey?: string[]; compositeKeys?: Set[]; }; export declare type ModelKeys = { [modelName: string]: KeyType; }; export declare type DataStoreConfig = { DataStore?: { authModeStrategyType?: AuthModeStrategyType; conflictHandler?: ConflictHandler; errorHandler?: (error: SyncError) => void; maxRecordsToSync?: number; syncPageSize?: number; fullSyncInterval?: number; syncExpressions?: SyncExpression[]; authProviders?: AuthProviders; storageAdapter?: Adapter; }; authModeStrategyType?: AuthModeStrategyType; conflictHandler?: ConflictHandler; errorHandler?: (error: SyncError) => void; maxRecordsToSync?: number; syncPageSize?: number; fullSyncInterval?: number; syncExpressions?: SyncExpression[]; authProviders?: AuthProviders; storageAdapter?: Adapter; }; export declare type AuthProviders = { functionAuthProvider: () => { token: string; } | Promise<{ token: string; }>; }; export declare enum AuthModeStrategyType { DEFAULT = "DEFAULT", MULTI_AUTH = "MULTI_AUTH" } export declare type AuthModeStrategyReturn = GRAPHQL_AUTH_MODE | GRAPHQL_AUTH_MODE[] | undefined | null; export declare type AuthModeStrategyParams = { schema: InternalSchema; modelName: string; operation: ModelOperation; }; export declare type AuthModeStrategy = (authModeStrategyParams: AuthModeStrategyParams) => AuthModeStrategyReturn | Promise; export declare enum ModelOperation { CREATE = "CREATE", READ = "READ", UPDATE = "UPDATE", DELETE = "DELETE" } export declare type ModelAuthModes = Record; export declare type SyncExpression = Promise<{ modelConstructor: any; conditionProducer: (c?: any) => any; }>; declare type Option0 = []; declare type Option1 = [ModelPredicate | undefined]; declare type Option = Option0 | Option1; declare type Lookup = { 0: ProducerModelPredicate | Promise> | typeof PredicateAll; 1: ModelPredicate | undefined; }; declare type ConditionProducer> = (...args: A) => A['length'] extends keyof Lookup ? Lookup[A['length']] : never; export declare function syncExpression>(modelConstructor: PersistentModelConstructor, conditionProducer: ConditionProducer): Promise<{ modelConstructor: PersistentModelConstructor; conditionProducer: ConditionProducer; }>; export declare type SyncConflict = { modelConstructor: PersistentModelConstructor; localModel: PersistentModel; remoteModel: PersistentModel; operation: OpType; attempts: number; }; export declare type SyncError = { message: string; errorType: ErrorType; errorInfo?: string; recoverySuggestion?: string; model?: string; localModel: T; remoteModel: T; process: ProcessName; operation: string; cause?: Error; }; export declare type ErrorType = 'ConfigError' | 'BadModel' | 'BadRecord' | 'Unauthorized' | 'Transient' | 'Unknown'; export declare enum ProcessName { 'sync' = "sync", 'mutate' = "mutate", 'subscribe' = "subscribe" } export declare const DISCARD: unique symbol; export declare type ConflictHandler = (conflict: SyncConflict) => Promise | PersistentModel | typeof DISCARD; export declare type ErrorHandler = (error: SyncError) => void; export declare type DeferredCallbackResolverOptions = { callback: () => void; maxInterval?: number; errorHandler?: (error: string) => void; }; export declare enum LimitTimerRaceResolvedValues { LIMIT = "LIMIT", TIMER = "TIMER" } export {};