/* * Copyright 2024 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ import type { ValidationError } from '../../errors'; export interface MultiStatusCreateResult { createdItems: T[], errorItems: { item: object, error: ValidationError }[], } export interface BaseModel { _remove(): Promise; getCreatedAt(): string; getId(): string; getRecordExpiresAt(): string; getUpdatedAt(): string; getUpdatedBy(): string; remove(): Promise; save(): Promise; toJSON(): object; } export interface QueryOptions { index?: string; limit?: number; order?: string; attributes?: string[]; cursor?: string; /** * Whether to automatically fetch all pages of results. * - `true`: Always paginate through all results * - `false`: Only fetch first page * - `undefined`: Auto-paginate when no limit specified, respect limits otherwise */ fetchAllPages?: boolean; /** * Whether to return cursor information for manual pagination. * - `true`: Returns { data, cursor } for paginated results * - `false` or `undefined`: Returns data array directly (default) */ returnCursor?: boolean; } export interface PaginatedResult { data: T[]; cursor: string | null; } export interface BatchGetOptions { attributes?: string[]; } export interface BaseCollection { _onCreate(item: T): void; _onCreateMany(items: MultiStatusCreateResult): void; _saveMany(items: T[]): Promise; saveMany(items: T[], options?: { chunkSize?: number }): Promise; all(sortKeys?: object, options?: QueryOptions): Promise>; allByIndexKeys(keys: object, options?: QueryOptions): Promise>; batchGetByKeys(keys: object[], options?: BatchGetOptions): Promise<{ data: T[]; unprocessed: object[] }>; create(item: object): Promise; createMany(items: object[], parent?: T): Promise>; existsById(id: string): Promise; findByAll(sortKeys?: object, options?: QueryOptions): Promise | null; findById(id: string): Promise | null; findByIndexKeys(indexKeys: object): Promise; removeByIds(ids: string[]): Promise; } export interface EntityRegistry { getCollection(collectionName: string): BaseCollection; getCollections(): BaseCollection[]; getEntities(): object; registerEntity(schema: object, collection: BaseCollection): void; } export interface Reference { getSortKeys(): string[]; getTarget(): string; getType(): string; isRemoveDependents(): boolean; toAccessorConfigs(): object[]; } export interface IndexAccessor { indexName: string; keySets: string[][]; } export interface Schema { allowsRemove(): boolean; allowsUpdates(): boolean; findIndexBySortKeys(sortKeys: string[]): object | null; findIndexByType(type: string): object | null; findIndexNameByKeys(keys: object): string; getAttribute(name: string): object; getAttributes(): object; getCollectionName(): string; getEntityName(): string; getIdName(): string; getIndexAccessors(): Array; getIndexByName(indexName: string): object; getIndexKeys(indexName: string): string[]; getIndexTypes(): string[]; getIndexes(): object; getModelClass(): object; getModelName(): string; getReciprocalReference(registry: EntityRegistry, reference: Reference): Reference | null; getReferenceByTypeAndTarget(referenceType: string, target: string): Reference | undefined; getReferences(): Reference[]; getReferencesByType(referenceType: string): Reference[]; getServiceName(): string; getVersion(): number; toAccessorConfigs(): object[]; toSchema(): object; } export interface SchemaBuilder { addAllIndex(sortKeys: string[]): SchemaBuilder; addAttribute(name: string, data: object): SchemaBuilder; addIndex(name: string, partitionKey: object, sortKey: object): SchemaBuilder; addReference(referenceType: string, entityName: string, sortKeys?: string[]): SchemaBuilder; allowRemove(allow: boolean): SchemaBuilder; allowUpdate(allow: boolean): SchemaBuilder; build(): Schema; withPrimaryPartitionKeys(partitionKeys: string[]): SchemaBuilder withPrimarySortKeys(sortKeys: string[]): SchemaBuilder; }