एपीआई का संदर्भ

नीचे टाइपस्क्रिप्ट परिभाषाओं और विस्तृत विवरणों सहित बंडल बिल्डर एपीआई के विनिर्देशों का अवलोकन दिया गया है।

बंडल दस्तावेज़ इंटरफ़ेस

कॉन्फ़िगर किए गए संग्रह के भीतर एकल दस्तावेज़ के लिए विशिष्टता:

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;
};

परमपरिभाषा इंटरफ़ेस

BundleDocument में परिभाषित एकल पैरामीटर का विनिर्देश।

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";
};

उदाहरण के लिए, निम्नलिखित पैरामीटर दिया गया है:

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

बंडल HTTP एंडपॉइंट के लिए अनुरोध करते समय, पैरामीटर एक क्वेरी पैरामीटर के माध्यम से प्रदान किया जा सकता है, उदाहरण के लिए ?name=david । गतिशील रूप से बंडल बनाने के लिए पैरामीटर का उपयोग QueryDefinition (नीचे देखें) मान ( $name ) के भीतर किया जा सकता है।

क्वेरीपरिभाषा इंटरफ़ेस

बंडल पर नामित क्वेरी बनाने के लिए क्वेरी परिभाषा का उपयोग किया जाता है। queries मैप के भीतर प्रत्येक ऑब्जेक्ट नाम के रूप में ऑब्जेक्ट कुंजी का उपयोग करके एक नई नामित क्वेरी बनाएगा। प्रत्येक क्वेरी को एक संग्रह और वैकल्पिक रूप से निष्पादित करने के लिए क्वेरी शर्तों की एक सूची निर्दिष्ट करनी होगी।

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 पैरामीटर में QueryCondition इंटरफ़ेस की एक सरणी हो सकती है। सरणी के प्रत्येक आइटम में केवल एक ही शर्त शामिल होनी चाहिए।

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;
};

उदाहरण के लिए, products संग्रह पर "उत्पाद" नामक क्वेरी बनाने के लिए जहां और सीमा की स्थिति के साथ, डेटा संरचना आउटपुट निम्नलिखित से मेल खाना चाहिए:

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

in , not-in , या array-contains-any फ़िल्टर के लिए सरणी मान प्रदान करते समय, आपको अल्पविराम से अलग किया गया मान प्रदान करना होगा क्योंकि नेस्टेड सरणी मान Firestore में समर्थित नहीं हैं। उदाहरण के लिए:

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

किसी भी संख्या मान को एक संख्या के रूप में पार्स किया जाएगा, हालांकि यदि स्ट्रिंग संख्या मान की आवश्यकता है तो इसे कोष्ठक में लपेटा जाना चाहिए:

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

शर्तों का उपयोग मापदंडों के साथ भी किया जा सकता है। उदाहरण के लिए, यदि एक पैरामीटर type परिभाषित किया गया है (ऊपर देखें), तो इसे $ सिंटैक्स के माध्यम से गतिशील डेटा बंडल प्रदान करने के लिए एक शर्त मान प्रदान किया जा सकता है:

// ?type=featured


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