import { $NonMaybeType, $Exact, $Call } from '../types' import type { Observable } from '../utils/rx' import type Model from '../Model' import type { RecordId } from '../Model' import type { ColumnName, TableName } from '../Schema' type ExtractRecordIdNonOptional = (value: T) => RecordId type ExtractRecordIdOptional = (value: T) => RecordId type ExtractRecordId = ExtractRecordIdNonOptional & ExtractRecordIdOptional export type Options = $Exact<{ isImmutable: boolean }> // Defines a one-to-one relation between two Models (two tables in db) // Do not create this object directly! Use `relation` or `immutableRelation` decorators instead export default class Relation { // Used by withObservables to differentiate between object types static _wmelonTag: string _model: Model _columnName: ColumnName _relationTableName: TableName<$NonMaybeType> _isImmutable: boolean // TODO: FIX TS // @lazy _cachedObservable: Observable constructor( model: Model, relationTableName: TableName<$NonMaybeType>, columnName: ColumnName, options: Options, ) get id(): $Call set id(newId: $Call) fetch(): Promise then( onFulfill?: (value: T) => Promise | U, onReject?: (error: any) => Promise | U, ): Promise set(record: T): void observe(): Observable }