UNPKG

firesage

Version:

🔥 Extremely High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience

38 lines (37 loc) • 1.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.where = void 0; var firestore_1 = require("firebase/firestore"); var crypto_1 = __importDefault(require("crypto")); /** * Creates a {@link QueryConstraint} that enforces that documents must contain the * specified field and that the value should satisfy the relation constraint * provided. * * @param fieldPath - The path to compare * @param opStr - The operation string (e.g "<", "<=", "==", "<", * "<=", "!="). * @param value - The value for comparison * @returns The created {@link Query}. */ var where = function (fieldPath, opStr, value) { var newValue = value; if (Array.isArray(newValue) && (opStr === 'in' || opStr === 'array-contains-any' || opStr === 'not-in') && newValue.length === 0) { newValue = [ crypto_1.default.randomUUID() + crypto_1.default.randomUUID() + crypto_1.default.randomUUID(), ]; } return { type: 'where', fieldPath: fieldPath, opStr: opStr, value: value, ref: (0, firestore_1.where)(fieldPath, opStr, newValue), }; }; exports.where = where;