import type { PostgrestFilterBuilder } from '@supabase/postgrest-js';
import type { StoreState } from './response_builder';
-export function collection<T> (query: PostgrestFilterBuilder<T>, initialValue: T[]): Readable<StoreState<T[]>> {
-
- return readable(initialResponse<T[]>(initialValue), (set) => {
-
- (async function() {
- const { data, error } = await query;
-
- if (error) {
- return set(errorResponse<T[]>(error));
- }
-
- set(response<T[]>(data));
- })()
- });
+export function collection<T>(
+ query: PostgrestFilterBuilder<T>,
+ initialValue: T[]
+): Readable<StoreState<T[]>> {
+ return readable(initialResponse<T[]>(initialValue), (set) => {
+ (async function () {
+ const { data, error } = await query;
+
+ if (error) {
+ return set(errorResponse<T[]>(error));
+ }
+
+ set(response<T[]>(data));
+ })();
+ });
}
-export function single<T> (query: PostgrestFilterBuilder<T>, initialValue: T): Readable<StoreState<T>> {
-
- return readable(initialResponse<T>(initialValue), (set) => {
-
- (async function() {
- const { data, error } = await query.single();
-
- if (error) {
- return set(errorResponse<T>(error));
- }
-
- set(response<T>(data));
- })()
- });
+export function single<T>(
+ query: PostgrestFilterBuilder<T>,
+ initialValue: T
+): Readable<StoreState<T>> {
+ return readable(initialResponse<T>(initialValue), (set) => {
+ (async function () {
+ const { data, error } = await query.single();
+
+ if (error) {
+ return set(errorResponse<T>(error));
+ }
+
+ set(response<T>(data));
+ })();
+ });
}