@kubator/sdk v0.0.1
    Preparing search index...

    Interface Collection<T>

    A collection supplied by the compatible Kubator host. The open surface retains its generic item type so Kubator can recover model schemas.

    interface Collection<T extends object> {
        autoPermissions?: Record<string, string>;
        excludeFromAutoMenu?: boolean;
        excludeFromGlobalSearch?: boolean;
        menuIndex?: number;
        menuParent?: Collection<object>;
        addIndex(
            name: string,
            expression: (item: T) => unknown,
            options?: IndexOptions<T>,
        ): void;
        addUniqueConstraint(
            name: string,
            expression: (item: T) => unknown,
            options?: UniqueConstraintOptions<T>,
        ): void;
        canUpdate(oldDocument?: T, newDocument?: T): boolean;
        count(predicate?: FilterPredicate<T>): number;
        countAsync(): Promise<number>;
        filter(predicate?: FilterPredicate<T>): Query<T>;
        filterAsync(predicate?: FilterPredicate<T>): Promise<T[]>;
        findAsync(predicate: FilterPredicate<T>): Promise<T>;
        findAsync<TResult>(
            predicate: FilterPredicate<T>,
            mapper: (item: T) => TResult,
        ): Promise<TResult>;
        flatMap<TOut extends object>(
            mapper: (item: T) => Iterable<TOut>,
        ): Query<TOut>;
        insertAsync(doc: T): Promise<T>;
        insertManyAsync(docs: T[], options?: InsertManyOptions): Promise<T[]>;
        join<TJoin extends object, TResult extends object>(
            other: Query<TJoin>,
            predicate: (left: T, right: TJoin) => boolean,
            selector: (left: T, right: TJoin) => TResult,
        ): Query<TResult>;
        join<TJoin extends object, TResult extends object>(
            other: Query<TJoin>,
            predicate: (left: T, right: TJoin) => boolean,
            selector: (left: T, right: TJoin) => TResult,
            joinType: "INNER",
        ): Query<TResult>;
        join<TJoin extends object, TResult extends object>(
            other: Query<TJoin>,
            predicate: (left: T, right: TJoin) => boolean,
            selector: (left: T, right: TJoin) => TResult,
            joinType: "LEFT",
        ): Query<TResult>;
        join<TJoin extends object, TResult extends object>(
            other: Query<TJoin>,
            predicate: (left: T, right: TJoin) => boolean,
            selector: (left: T, right: TJoin) => TResult,
            joinType: "RIGHT",
        ): Query<TResult>;
        join<TJoin extends object, TResult extends object>(
            other: Query<TJoin>,
            predicate: (left: T, right: TJoin) => boolean,
            selector: (left: T, right: TJoin) => TResult,
            joinType: "OUTER",
        ): Query<TResult>;
        map<TOut extends object>(mapper: (item: T) => TOut): Query<TOut>;
        orderBy(
            selector: keyof T | ((item: T) => unknown),
            mode?: "ascending" | "descending",
        ): Query<T>;
        reset(mode?: "fast" | "full"): Promise<void>;
        skip(count: number): Query<T>;
        someAsync(filter?: FilterPredicate<T>): Promise<boolean>;
        sumAsync(
            selector: (item: T) => number,
            defaultValue?: number,
        ): Promise<number>;
        take(count: number): Query<T>;
        toArray(): T[];
        toArrayAsync(): Promise<T[]>;
        tryDeleteOneAsync(filter: FilterPredicate<T>): Promise<boolean>;
        tryFindAsync(predicate: FilterPredicate<T>): Promise<T>;
        tryFirst(): T;
        tryFirstAsync(): Promise<T>;
        tryInsertAsync(doc: T): Promise<T>;
        updateAllAsync(
            filter: FilterPredicate<T>,
            update: (entry: T) => void,
            options: UpdateOptions & { returning: true },
        ): Promise<T[]>;
        updateAllAsync(
            filter: FilterPredicate<T>,
            update: (entry: T) => void,
            options?: UpdateOptions,
        ): Promise<number>;
        updateOneAsync(
            filter: FilterPredicate<T>,
            update: (entry: T) => void,
            options?: UpdateOptions,
        ): Promise<void>;
    }

    Type Parameters

    • T extends object

    Hierarchy (View Summary)

    Index
    • Adds an expression-based index to the collection.

      Parameters

      • name: string
      • expression: (item: T) => unknown
      • Optionaloptions: IndexOptions<T>

      Returns void

    • Adds a uniqueness constraint derived from a document expression.

      Parameters

      Returns void

    • Checks whether the current caller may update a document.

      Parameters

      • OptionaloldDocument: T
      • OptionalnewDocument: T

      Returns boolean

    • Counts documents in this query.

      Returns Promise<number>

    • Projects each document to zero or more output documents.

      Type Parameters

      • TOut extends object

      Parameters

      • mapper: (item: T) => Iterable<TOut>

      Returns Query<TOut>

    • Inserts a document and returns it, including generated values.

      Parameters

      • doc: T

      Returns Promise<T>

    • Combines matching rows from this query and another query.

      Type Parameters

      • TJoin extends object
      • TResult extends object

      Parameters

      Returns Query<TResult>

    • Explicitly combines only rows that match in both queries.

      Type Parameters

      • TJoin extends object
      • TResult extends object

      Parameters

      Returns Query<TResult>

    • Includes unmatched rows from this query, with an undefined right row.

      Type Parameters

      • TJoin extends object
      • TResult extends object

      Parameters

      Returns Query<TResult>

    • Includes unmatched rows from the other query, with an undefined left row.

      Type Parameters

      • TJoin extends object
      • TResult extends object

      Parameters

      Returns Query<TResult>

    • Includes unmatched rows from either query, with the missing row undefined.

      Type Parameters

      • TJoin extends object
      • TResult extends object

      Parameters

      Returns Query<TResult>

    • Projects each document to a new object shape.

      Type Parameters

      • TOut extends object

      Parameters

      • mapper: (item: T) => TOut

      Returns Query<TOut>

    • Sorts documents by a property or selector.

      Parameters

      • selector: keyof T | ((item: T) => unknown)
      • Optionalmode: "ascending" | "descending"

      Returns Query<T>

    • Clears collection documents; available in test environments.

      Parameters

      • Optionalmode: "fast" | "full"

      Returns Promise<void>

    • Skips the first count documents.

      Parameters

      • count: number

      Returns Query<T>

    • Returns whether any document matches a filter or predicate.

      Parameters

      Returns Promise<boolean>

    • Sums values projected from matching documents.

      Parameters

      • selector: (item: T) => number
      • OptionaldefaultValue: number

      Returns Promise<number>

    • Limits this query to the first count documents.

      Parameters

      • count: number

      Returns Query<T>

    • Materializes this query synchronously.

      Returns T[]

    • Materializes this query as an array.

      Returns Promise<T[]>

    • Deletes one matching document, returning whether a document was deleted.

      Parameters

      Returns Promise<boolean>

    • Returns the first document, if present.

      Returns T

    • Returns the first document asynchronously, if present.

      Returns Promise<T>

    • Inserts a document, returning undefined on a uniqueness conflict.

      Parameters

      • doc: T

      Returns Promise<T>

    • Updates matching documents and returns the modified documents.

      Parameters

      Returns Promise<T[]>

    • Updates matching documents and returns the number of modified documents.

      Parameters

      Returns Promise<number>

    • Updates one matching document, rejecting when none exists.

      Parameters

      Returns Promise<void>

    autoPermissions?: Record<string, string>

    Automatically grants the named permissions for this collection.

    excludeFromAutoMenu?: boolean

    Omits this collection from automatically generated Studio menus.

    excludeFromGlobalSearch?: boolean

    Omits this collection from Studio's global search.

    menuIndex?: number

    Controls this collection's position in Studio menus.

    menuParent?: Collection<object>

    Places this collection beneath another collection in Studio menus.