UNPKG

@energica-city/shared-amplify-utils

Version:

Shared utilities for AWS Amplify projects

136 lines 4.19 kB
/** * Constraint to ensure the types object has the expected structure for AWS Amplify models. * Each model in the types object must have these properties for the QueryFactory to work correctly. * @internal */ export type AmplifyModelType = { type: unknown; createType: unknown; updateType: unknown; deleteType: unknown; identifier: unknown; }; /** * Extracts the model type from the provided types. * @template T - The model name. * @template Types - The types object provided by the consumer. */ export type ModelType<T extends string, Types extends Record<T, AmplifyModelType>> = Types[T]['type']; /** * Extracts the create input type from the provided types. * @template T - The model name. * @template Types - The types object provided by the consumer. */ export type CreateInput<T extends string, Types extends Record<T, AmplifyModelType>> = Types[T]['createType']; /** * Extracts the update input type from the provided types. * @template T - The model name. * @template Types - The types object provided by the consumer. */ export type UpdateInput<T extends string, Types extends Record<T, AmplifyModelType>> = Types[T]['updateType']; /** * Extracts the delete input type from the provided types. * @template T - The model name. * @template Types - The types object provided by the consumer. */ export type DeleteInput<T extends string, Types extends Record<T, AmplifyModelType>> = Types[T]['deleteType']; /** * Extracts the identifier type from the provided types. * @template T - The model name. * @template Types - The types object provided by the consumer. */ export type Identifier<T extends string, Types extends Record<T, AmplifyModelType>> = Types[T]['identifier']; /** * Standard response structure for database operations */ export type DatabaseResponse<T> = { data: T | null; errors?: Array<{ message: string; }>; }; /** * Valid operation types for the QueryFactory */ export type OperationType = 'create' | 'update' | 'delete' | 'get' | 'list'; /** * Shape of operations returned by QueryFactory */ export interface ModelOperations<T> { create: (props: { input: unknown; }) => Promise<T>; update: (props: { input: unknown; }) => Promise<T>; delete: (props: { input: unknown; }) => Promise<T>; get: (props: { input: unknown; }) => Promise<T>; list: () => Promise<T[]>; } /** * Validation parameters structure */ export interface ValidationParams<T = unknown> { validationProps?: { input?: T; }; operationType?: OperationType; modelName?: string; } /** * Return type of the QueryFactory function */ export interface QueryFactoryResult<T extends string, Types extends Record<T, AmplifyModelType>> { create: (props: { input: CreateInput<T, Types>; }) => Promise<ModelType<T, Types>>; update: (props: { input: UpdateInput<T, Types>; }) => Promise<ModelType<T, Types>>; delete: (props: { input: DeleteInput<T, Types>; }) => Promise<ModelType<T, Types>>; get: (props: { input: Identifier<T, Types>; }) => Promise<ModelType<T, Types>>; list: () => Promise<ModelType<T, Types>[]>; } /** * Valid AWS Amplify authorization types */ export type AmplifyAuthMode = 'iam' | 'userPool' | 'oidc' | 'lambda' | 'apiKey'; /** * AWS Amplify outputs configuration */ export interface AmplifyOutputs { data: { url: string; aws_region: string; default_authorization_type: AmplifyAuthMode; authorization_types?: AmplifyAuthMode[]; api_id?: string; }; } /** * Configuration object for QueryFactory */ export interface QueryFactoryConfig<T extends string> { /** The name of the model from the consumer's schema */ name: T; /** * AWS Amplify outputs configuration. * Can be provided here or globally via initializeQueries() */ amplifyOutputs?: AmplifyOutputs; /** * Unique identifier for the client instance. * Used with singleton client management via ClientManager. * @default 'default' */ clientKey?: string; } //# sourceMappingURL=types.d.ts.map