/** * Copyright 2022 Google LLC * * Licensed 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 CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Clock, Logger, PersistentStorage, PersistentStorageUpdateType, TransactionType, Transaction, TimelineEntry, Interval, OfferVersionPair, OfferProducerMetadata, JsonValue } from 'opr-core'; import { DecodedReshareChain, Offer, OfferHistory, ReshareChain } from 'opr-models'; import { DataSource, DataSourceOptions, EntityManager } from 'typeorm'; export { DataSourceOptions } from 'typeorm'; export interface SqlOprPersistentStorageOptions { clock?: Clock; dsOptions: DataSourceOptions; enableInternalChecks?: boolean; logger?: Logger; selectPageSize?: number; } export declare class SqlTransaction implements Transaction { private commitCallbackFn; private rejectCallbackFn; private completionPromise; private entityManager; private db; private isolationLevel; private type; constructor(db: DataSource, type: TransactionType); startInternal(): Promise; get em(): EntityManager; commit(): Promise; fail(): Promise; } export declare class SqlOprPersistentStorage implements PersistentStorage { readonly type = "storage"; private readonly db; private initialized; private initializingPromise; private logger; private selectPageSize; constructor(options: SqlOprPersistentStorageOptions); initialize(): Promise; /** * Synchronizes database tables to match current datamodels. This method can * be called to set up new databases. It should NOT be exposed in production. */ synchronize(dropBeforeSync?: boolean): Promise; shutdown(): Promise; createTransaction(type?: TransactionType): Promise; /** * Stores a key-value pair for the given host. If a value already exists at * the given key, it will be replaced and the old value returned. */ storeValue(t: SqlTransaction, hostOrgUrl: string, key: string, value: JsonValue): Promise; /** * Clears all values for the given host where the key starts with the given * prefix. It is very important to namespace keys correctly, since this can * easily erase many values. Returns the number of values deleted. */ clearAllValues(t: SqlTransaction, hostOrgUrl: string, keyPrefix: string): Promise; /** * Returns all values for the given host where the key starts with the given * prefix. */ getValues(t: SqlTransaction, hostOrgUrl: string, keyPrefix: string): AsyncIterable; getOfferFromCorpus(t: SqlTransaction, hostOrgUrl: string, corpusOrgUrl: string, postingOrgUrl: string, offerId: string): Promise; getOffer(t: SqlTransaction, hostOrgUrl: string, offerId: string, postingOrgUrl: string, updateTimestampUTC?: number): Promise; getOfferSources(t: SqlTransaction, hostOrgUrl: string, offerId: string, postingOrgUrl: string, updateTimestampUTC?: number): Promise>; insertOrUpdateOfferInCorpus(t: SqlTransaction, hostOrgUrl: string, corpusOrgUrl: string, offer: Offer): Promise; private getNewestSnapshotTimestamp; getBestReshareChainRoot(t: SqlTransaction, offerId: string, postingOrgUrl: string): Promise; getBestAcceptChain(t: SqlTransaction, offerId: string, postingOrgUrl: string): Promise; deleteOfferInCorpus(t: SqlTransaction, hostOrgUrl: string, corpusOrgUrl: string, offerId: string, offeringOrgUrl: string): Promise; getCorpusOffers(t: SqlTransaction, hostOrgUrl: string, corpusOrgUrl: string, skipCount?: number): AsyncGenerator; getTimelineForOffer(t: SqlTransaction, hostOrgUrl: string, offerId: string, postingOrgUrl: string, queryInterval?: Interval, targetOrgUrl?: string): AsyncGenerator; addTimelineEntries(t: SqlTransaction, hostOrgUrl: string, timelineEntries: AsyncIterable): Promise; truncateFutureTimelineForOffer(t: SqlTransaction, hostOrgUrl: string, offerId: string, postingOrgUrl: string, timestampUTC: number): Promise; getChangedOffers(t: SqlTransaction, hostOrgUrl: string, viewingOrgUrl: string, oldTimestampUTC: number, newTimestampUTC: number, skipCount?: number): AsyncGenerator; getOffersAtTime(t: SqlTransaction, hostOrgUrl: string, viewingOrgUrl: string, timestampUTC: number, skipCount?: number, pageSize?: number): AsyncGenerator; getOfferAtTime(t: SqlTransaction, hostOrgUrl: string, viewingOrgUrl: string, offerId: string, postingOrgUrl: string, timestampUTC: number): Promise; writeAccept(t: SqlTransaction, hostOrgUrl: string, acceptingOrgUrl: string, offerId: string, offerUpdateTimestampUTC: number, atTimeUTC: number, decodedReshareChain?: DecodedReshareChain | undefined): Promise; getHistory(t: SqlTransaction, hostOrgUrl: string, viewingOrgUrl: string, sinceTimestampUTC?: number | undefined, skipCount?: number): AsyncIterable; writeReject(t: SqlTransaction, hostOrgUrl: string, rejectingOrgUrl: string, offerId: string, postingOrgUrl: string, atTimeUTC: number): Promise; getAllRejections(t: SqlTransaction, hostOrgUrl: string, offerId: string, postingOrgUrl: string): Promise; getKnownOfferingOrgs(t: SqlTransaction, hostOrgUrl: string, sinceTimestampUTC?: number | undefined): AsyncGenerator; writeOfferProducerMetadata(t: SqlTransaction, metadata: OfferProducerMetadata): Promise; getOfferProducerMetadata(t: SqlTransaction, orgUrl: string): Promise; debugQuery(t: SqlTransaction, sql: string): Promise; } //# sourceMappingURL=sqloprpersistentstorage.d.ts.map