@1amageek/document-propagator
TypeScript icon, indicating that this package has built-in type declarations

0.12.1 • Public • Published

document-propagator.ts

Cloud Firestore does not have Join Query. However, there are many use cases that require data joins. This library is designed to resolve CloudFirestore's Document dependencies.

Usage

The following code shows the Shop, Product, and Catalog dependencies of an EC.

スクリーンショット 2022-12-13 22 02 10

Catalog depends on Product and Shop. Product depends on SKU.

スクリーンショット 2022-12-13 22 02 15

export const dependency = propagator.resolve(getFirestore(app),
  { regions: ["asia-northeast1"] },
  [
    {
      from: "/EC/{version}/shopDrafts/{shopID}",
      to: "/EC/{version}/shops/{shopID}",
      resources: [],
    },
    {
      from: "/EC/{version}/shops/{shopID}/productDrafts/{productID}",
      to: "/EC/{version}/shops/{shopID}/products/{productID}",
      resources: [
        { documentID: "SKUIDs", field: "skus", resource: "/EC/{version}/shops/{shopID}/products/{productID}/SKUs/{skuID}" },
      ],
    },
    {
      from: "/EC/{version}/shops/{shopID}/products/{productID}/SKUDrafts/{skuID}",
      to: "/EC/{version}/shops/{shopID}/products/{productID}/SKUs/{skuID}",
      resources: [],
    },
    {
      from: "/EC/{version}/shops/{shopID}/catalogDrafts/{catalogID}",
      to: "/EC/{version}/shops/{shopID}/catalog/{catalogID}",
      resources: [
        { documentID: "shopID", field: "shop", resource: "/EC/{version}/shops" },
        { documentID: "productIDs", field: "products", resource: "/EC/{version}/shop/{shopID}/products" },
      ],
    },
  ]
)

When the Draft is updated, Cloud Functions is triggered to retrieve the dependent data and merge the data. After the merged data is updated, the update is propagated to the data with dependencies.

Package Sidebar

Install

npm i @1amageek/document-propagator

Weekly Downloads

1

Version

0.12.1

License

none

Unpacked Size

70.7 kB

Total Files

20

Last publish

Collaborators

  • 1amageek