/// A declarative query API in the shape of a server-side Firestore gateway: /// filters are value objects, not chained calls, so only an adapter config can /// tell pipe what each argument means. class WhereEquals { const WhereEquals(this.field, this.value); final String field; final Object? value; } class WhereIn { const WhereIn(this.field, this.values); final String field; final List values; } class WhereArrayContains { const WhereArrayContains(this.field, this.value); final String field; final Object? value; } class WhereRange { const WhereRange(this.field, {this.gte, this.gt, this.lte, this.lt}); final String field; final Object? gte; final Object? gt; final Object? lte; final Object? lt; } enum Cmp { lessThan, greaterThan } /// An operator carried as an enum argument rather than a named bound. class WhereCmp { const WhereCmp(this.field, this.cmp, this.value); final String field; final Cmp cmp; final Object? value; } class OrderBy { const OrderBy(this.field, {this.descending = false}); final String field; final bool descending; } abstract class Transaction { Future> queryCollection( String collectionPath, { List filters = const [], int? limit, }); } abstract class Gateway { Future> queryCollection( String collectionPath, { List filters = const [], WhereArrayContains? arrayContains, List ranges = const [], List orderBy = const [], String? startAfterId, int? limit, }); Future> queryCollectionGroup( String collectionId, { List filters = const [], WhereIn? inFilter, List ranges = const [], List orderBy = const [], int? limit, }); Future getDocument(String path); Future runTransaction(Future Function(Transaction txn) action); } class InMemoryGateway implements Gateway { @override Future> queryCollection( String collectionPath, { List filters = const [], WhereArrayContains? arrayContains, List ranges = const [], List orderBy = const [], String? startAfterId, int? limit, }) async => const []; @override Future> queryCollectionGroup( String collectionId, { List filters = const [], WhereIn? inFilter, List ranges = const [], List orderBy = const [], int? limit, }) async => const []; @override Future getDocument(String path) async => null; @override Future runTransaction(Future Function(Transaction txn) action) => throw UnimplementedError(); }