API Referansı

Aşağıda, TypeScript tanımları ve ayrıntılı açıklamalar da dahil olmak üzere Bundle Builder API'nin özelliklerine ilişkin genel bir bakış yer almaktadır.

BundleDocument Arayüzü

Yapılandırılmış koleksiyondaki tek bir dokümanın spesifikasyonu:

type BundleDocument = {
  // A list of document IDs to serve in the bundle.
  docs?: Array<string>;
  // A map containing individual named queries and their definitions.
  queries?: Map<string, QueryDefinition[]>;
  // A map of parameters and their definitions, which can be provided to a query definition.
  params?: Map<string, ParamDefinition>;
  // Specifies how long to keep the bundle in the client's cache, in seconds. If not defined, client-side cache is disabled.
  clientCache?: string;
  // Only used in combination with Firebase Hosting. Specifies how long to keep the bundle in Firebase Hosting CDN cache, in seconds.
  serverCache: string;
  // Specifies how long (in seconds) to keep the bundle in a Cloud Storage bucket, in seconds. If not defined, Cloud Storage bucket is not accessed.
  fileCache?: string;
  // If a 'File Cache' is specified, bundles created before this timestamp will not be file cached.
  notBefore?: Timestamp;
};

ParamDefinition Interface

BundleDocument içinde tanımlanan tek bir parametrenin spesifikasyonu.

type ParamDefinition = {
  // Whether this parameter is required. If not provided as a query string, an error will be thrown.
  required: boolean;
  // The type of value which will be parsed, defaults to 'string'.
  type?:
    | "string"
    | "integer"
    | "float"
    | "boolean"
    | "string-array"
    | "integer-array"
    | "float-array";
};

Örneğin, aşağıdaki parametre verildiğinde:

params: {
  name: {
    required: true,
    type: 'string',
  }
}

Paket HTTP uç noktasına istekte bulunurken parametre, sorgu parametresi aracılığıyla sağlanabilir (ör. ?name=david). Parametre, paketleri dinamik olarak oluşturmak için QueryDefinition (aşağıya bakın) değeri ($name) içinde kullanılabilir.

QueryDefinition Arayüzü

Pakette adlandırılmış sorgular oluşturmak için bir sorgu tanımı kullanılır. queries haritasındaki her nesne, nesne anahtarını ad olarak kullanarak yeni bir adlandırılmış sorgu oluşturur. Her sorgu bir koleksiyonu ve isteğe bağlı olarak gerçekleştirilecek sorgu koşulları listesini belirtmelidir.

type QueryDefinition = {
  // The collection to perform the query on.
  collection: string;
  // An optional list of conditions to perform on the specified collection.
  conditions?: QueryCondition[];
};

conditions parametresi, QueryCondition arayüzlerinin bir dizisini içerebilir. Dizideki her öğe yalnızca tek bir koşul içermelidir.

type QueryCondition = {
  // Performs a `where` filter on the collection on a given FieldPath, operator and value.
  where?: [
    string,
    (
      | "<"
      | "<="
      | "=="
      | ">="
      | ">"
      | "!="
      | "array-contains"
      | "in"
      | "not-in"
      | "array-contains-any"
    ),
    any
  ];
  orderBy?: [string, ("asc" | "desc")?];
  limit?: number;
  limitToLast?: number;
  offset?: number;
  startAt?: string;
  startAfter?: string;
  endAt?: string;
  endBefore?: string;
};

Örneğin, bir where ve limit koşulu içeren products koleksiyonunda "products" adlı bir sorgu oluşturmak için veri yapısı çıkışı aşağıdakilerle eşleşmelidir:

queries: {
  products: {
    collection: 'products',
    conditions: [
      { where: ['type', '==', 'featured'] },
      { limit: 10 },
    ],
  }
}

in, not-in veya array-contains-any filtrelerine dizi değerleri sağlarken virgülle ayrılmış bir değer sağlamanız gerekir. İç içe dizi değerleri Firestore'da desteklenmez. Örneğin:

{ where: ['category', 'in', 'womens,shorts'] }, // ['womens', 'shorts']

Tüm sayı değerleri sayı olarak ayrıştırılır. Ancak dize sayı değeri gerekiyorsa parantez içine alınmalıdır:

{ where: ['price', 'in', '1,2.5'] }, // [1, 2.5]
{ where: ['price', 'in', '"1","2.5"'] }, // ['1', '2.5']

Koşullar, parametrelerle birlikte de kullanılabilir. Örneğin, bir type parametresi tanımlanmışsa (yukarıya bakın) $ söz dizimi aracılığıyla dinamik veri paketleri sağlamak için bu parametre bir koşul değerine sağlanabilir:

// ?type=featured


    conditions: [
      { where: ['type', '==', '$type'] },