@edge.app/drupe
Advanced tools
+145
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var index_exports = {}; | ||
| __export(index_exports, { | ||
| asMangoSelector: () => asMangoSelector, | ||
| drupe: () => drupe | ||
| }); | ||
| module.exports = __toCommonJS(index_exports); | ||
| var import_pouchdb_selector_core = require("pouchdb-selector-core"); | ||
| // src/cleaners.ts | ||
| var import_cleaners = require("cleaners"); | ||
| // src/util/locateError.ts | ||
| function locateError(error, step, offset) { | ||
| if (isErrorWithInsertStepAt(error)) { | ||
| if (error.insertStepAt == null) { | ||
| error.message += " at "; | ||
| error.insertStepAt = error.message.length; | ||
| } | ||
| error.message = error.message.slice(0, error.insertStepAt) + step + error.message.slice(error.insertStepAt); | ||
| error.insertStepAt += offset; | ||
| } | ||
| return error; | ||
| } | ||
| function isErrorWithInsertStepAt(error) { | ||
| if (error instanceof Error) { | ||
| if (!("insertStepAt" in error)) { | ||
| error.insertStepAt = null; | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| // src/cleaners.ts | ||
| var asMangoSelector = (raw) => { | ||
| if (typeof raw !== "object" || raw == null || Array.isArray(raw)) { | ||
| throw new TypeError("Expected a Mango selector object"); | ||
| } | ||
| const source = raw; | ||
| const result = {}; | ||
| for (const key of Object.keys(source)) { | ||
| try { | ||
| if (key === "__proto__") continue; | ||
| const value = source[key]; | ||
| if (value === void 0) { | ||
| result[key] = void 0; | ||
| continue; | ||
| } | ||
| if (key === "$and" || key === "$or" || key === "$nor") { | ||
| result[key] = asMangoSelectorArray(value); | ||
| continue; | ||
| } | ||
| if (key === "$not") { | ||
| result[key] = asMangoSelector(value); | ||
| continue; | ||
| } | ||
| result[key] = (0, import_cleaners.asEither)(asMangoFieldSelector, asMangoSelectorArray)(value); | ||
| } catch (error) { | ||
| throw locateError(error, "." + key, 0); | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| var asMangoSelectorArray = (0, import_cleaners.asArray)(asMangoSelector); | ||
| var asMangoPrimitive = (0, import_cleaners.asEither)( | ||
| import_cleaners.asNull, | ||
| import_cleaners.asBoolean, | ||
| import_cleaners.asNumber, | ||
| import_cleaners.asString | ||
| ); | ||
| var asMangoValue = (0, import_cleaners.asEither)( | ||
| asMangoPrimitive, | ||
| (0, import_cleaners.asArray)((raw) => asMangoValue(raw)), | ||
| (0, import_cleaners.asObject)((raw) => asMangoValue(raw)) | ||
| ); | ||
| var asMangoValueArray = (0, import_cleaners.asArray)(asMangoValue); | ||
| var asMangoType = (0, import_cleaners.asValue)( | ||
| "null", | ||
| "boolean", | ||
| "number", | ||
| "string", | ||
| "array", | ||
| "object" | ||
| ); | ||
| var asMangoKeyMapMatch = (0, import_cleaners.asObject)( | ||
| (raw) => raw === void 0 ? void 0 : asMangoSelector(raw) | ||
| ); | ||
| var asNumberPair = (0, import_cleaners.asTuple)(import_cleaners.asNumber, import_cleaners.asNumber); | ||
| var asRegex = (0, import_cleaners.asEither)(import_cleaners.asString, (0, import_cleaners.asArray)(import_cleaners.asString)); | ||
| var asMangoFieldMatcher = (0, import_cleaners.asObject)({ | ||
| $eq: (0, import_cleaners.asOptional)(asMangoValue), | ||
| $ne: (0, import_cleaners.asOptional)((0, import_cleaners.asEither)(asMangoValue, asMangoValueArray)), | ||
| $gt: (0, import_cleaners.asOptional)(asMangoValue), | ||
| $gte: (0, import_cleaners.asOptional)(asMangoValue), | ||
| $lt: (0, import_cleaners.asOptional)(asMangoValue), | ||
| $lte: (0, import_cleaners.asOptional)(asMangoValue), | ||
| $exists: (0, import_cleaners.asOptional)(import_cleaners.asBoolean), | ||
| $type: (0, import_cleaners.asOptional)(asMangoType), | ||
| $in: (0, import_cleaners.asOptional)(asMangoValueArray), | ||
| $nin: (0, import_cleaners.asOptional)(asMangoValueArray), | ||
| $size: (0, import_cleaners.asOptional)(import_cleaners.asNumber), | ||
| $mod: (0, import_cleaners.asOptional)(asNumberPair), | ||
| $regex: (0, import_cleaners.asOptional)(asRegex), | ||
| $options: (0, import_cleaners.asOptional)(import_cleaners.asString), | ||
| $all: (0, import_cleaners.asOptional)(asMangoValueArray), | ||
| $elemMatch: (0, import_cleaners.asOptional)(asMangoSelector), | ||
| $allMatch: (0, import_cleaners.asOptional)(asMangoSelector), | ||
| $keyMapMatch: (0, import_cleaners.asOptional)(asMangoKeyMapMatch), | ||
| $not: (0, import_cleaners.asOptional)((raw) => asMangoFieldSelector(raw)) | ||
| }); | ||
| var asMangoFieldSelector = (0, import_cleaners.asEither)( | ||
| asMangoValue, | ||
| asMangoFieldMatcher, | ||
| asMangoSelector | ||
| ); | ||
| // src/index.ts | ||
| var drupe = (selector) => (subject) => { | ||
| return (0, import_pouchdb_selector_core.matchesSelector)(subject, selector); | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| asMangoSelector, | ||
| drupe | ||
| }); |
| import { Cleaner } from 'cleaners'; | ||
| type Drupe = (selector: MangoSelector) => DrupeQuery; | ||
| type DrupeQuery = (subject: unknown) => boolean; | ||
| type MangoPrimitive = null | boolean | number | string; | ||
| type MangoValue = MangoPrimitive | MangoValue[] | { | ||
| [key: string]: MangoValue; | ||
| }; | ||
| type MangoDocument = { | ||
| [field: string]: MangoValue; | ||
| }; | ||
| type MangoType = "null" | "boolean" | "number" | "string" | "array" | "object"; | ||
| interface MangoKeyMapMatch { | ||
| [key: string]: MangoSelector | undefined; | ||
| $default?: MangoSelector; | ||
| } | ||
| interface MangoFieldMatcher { | ||
| $eq?: MangoValue; | ||
| $ne?: MangoValue | MangoValue[]; | ||
| $gt?: MangoValue; | ||
| $gte?: MangoValue; | ||
| $lt?: MangoValue; | ||
| $lte?: MangoValue; | ||
| $exists?: boolean; | ||
| $type?: MangoType; | ||
| $in?: MangoValue[]; | ||
| $nin?: MangoValue[]; | ||
| $size?: number; | ||
| $mod?: [number, number]; | ||
| $regex?: string | string[]; | ||
| $options?: string; | ||
| $all?: MangoValue[]; | ||
| $elemMatch?: MangoSelector; | ||
| $allMatch?: MangoSelector; | ||
| $keyMapMatch?: MangoKeyMapMatch; | ||
| $not?: MangoFieldSelector; | ||
| } | ||
| type MangoFieldSelector = MangoValue | MangoFieldMatcher | MangoSelector | (MangoFieldMatcher & MangoSelector); | ||
| interface MangoSelector { | ||
| [field: string]: MangoFieldSelector | MangoSelector[] | MangoSelector | undefined; | ||
| $and?: MangoSelector[]; | ||
| $or?: MangoSelector[]; | ||
| $nor?: MangoSelector[]; | ||
| $not?: MangoSelector; | ||
| } | ||
| declare const asMangoSelector: Cleaner<MangoSelector>; | ||
| declare const drupe: Drupe; | ||
| export { type Drupe, type DrupeQuery, type MangoDocument, type MangoFieldMatcher, type MangoFieldSelector, type MangoKeyMapMatch, type MangoPrimitive, type MangoSelector, type MangoType, type MangoValue, asMangoSelector, drupe }; |
+130
| // src/index.ts | ||
| import { matchesSelector } from "pouchdb-selector-core"; | ||
| // src/cleaners.ts | ||
| import { | ||
| asArray, | ||
| asBoolean, | ||
| asEither, | ||
| asNull, | ||
| asNumber, | ||
| asObject, | ||
| asOptional, | ||
| asString, | ||
| asTuple, | ||
| asValue | ||
| } from "cleaners"; | ||
| // src/util/locateError.ts | ||
| function locateError(error, step, offset) { | ||
| if (isErrorWithInsertStepAt(error)) { | ||
| if (error.insertStepAt == null) { | ||
| error.message += " at "; | ||
| error.insertStepAt = error.message.length; | ||
| } | ||
| error.message = error.message.slice(0, error.insertStepAt) + step + error.message.slice(error.insertStepAt); | ||
| error.insertStepAt += offset; | ||
| } | ||
| return error; | ||
| } | ||
| function isErrorWithInsertStepAt(error) { | ||
| if (error instanceof Error) { | ||
| if (!("insertStepAt" in error)) { | ||
| error.insertStepAt = null; | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| // src/cleaners.ts | ||
| var asMangoSelector = (raw) => { | ||
| if (typeof raw !== "object" || raw == null || Array.isArray(raw)) { | ||
| throw new TypeError("Expected a Mango selector object"); | ||
| } | ||
| const source = raw; | ||
| const result = {}; | ||
| for (const key of Object.keys(source)) { | ||
| try { | ||
| if (key === "__proto__") continue; | ||
| const value = source[key]; | ||
| if (value === void 0) { | ||
| result[key] = void 0; | ||
| continue; | ||
| } | ||
| if (key === "$and" || key === "$or" || key === "$nor") { | ||
| result[key] = asMangoSelectorArray(value); | ||
| continue; | ||
| } | ||
| if (key === "$not") { | ||
| result[key] = asMangoSelector(value); | ||
| continue; | ||
| } | ||
| result[key] = asEither(asMangoFieldSelector, asMangoSelectorArray)(value); | ||
| } catch (error) { | ||
| throw locateError(error, "." + key, 0); | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| var asMangoSelectorArray = asArray(asMangoSelector); | ||
| var asMangoPrimitive = asEither( | ||
| asNull, | ||
| asBoolean, | ||
| asNumber, | ||
| asString | ||
| ); | ||
| var asMangoValue = asEither( | ||
| asMangoPrimitive, | ||
| asArray((raw) => asMangoValue(raw)), | ||
| asObject((raw) => asMangoValue(raw)) | ||
| ); | ||
| var asMangoValueArray = asArray(asMangoValue); | ||
| var asMangoType = asValue( | ||
| "null", | ||
| "boolean", | ||
| "number", | ||
| "string", | ||
| "array", | ||
| "object" | ||
| ); | ||
| var asMangoKeyMapMatch = asObject( | ||
| (raw) => raw === void 0 ? void 0 : asMangoSelector(raw) | ||
| ); | ||
| var asNumberPair = asTuple(asNumber, asNumber); | ||
| var asRegex = asEither(asString, asArray(asString)); | ||
| var asMangoFieldMatcher = asObject({ | ||
| $eq: asOptional(asMangoValue), | ||
| $ne: asOptional(asEither(asMangoValue, asMangoValueArray)), | ||
| $gt: asOptional(asMangoValue), | ||
| $gte: asOptional(asMangoValue), | ||
| $lt: asOptional(asMangoValue), | ||
| $lte: asOptional(asMangoValue), | ||
| $exists: asOptional(asBoolean), | ||
| $type: asOptional(asMangoType), | ||
| $in: asOptional(asMangoValueArray), | ||
| $nin: asOptional(asMangoValueArray), | ||
| $size: asOptional(asNumber), | ||
| $mod: asOptional(asNumberPair), | ||
| $regex: asOptional(asRegex), | ||
| $options: asOptional(asString), | ||
| $all: asOptional(asMangoValueArray), | ||
| $elemMatch: asOptional(asMangoSelector), | ||
| $allMatch: asOptional(asMangoSelector), | ||
| $keyMapMatch: asOptional(asMangoKeyMapMatch), | ||
| $not: asOptional((raw) => asMangoFieldSelector(raw)) | ||
| }); | ||
| var asMangoFieldSelector = asEither( | ||
| asMangoValue, | ||
| asMangoFieldMatcher, | ||
| asMangoSelector | ||
| ); | ||
| // src/index.ts | ||
| var drupe = (selector) => (subject) => { | ||
| return matchesSelector(subject, selector); | ||
| }; | ||
| export { | ||
| asMangoSelector, | ||
| drupe | ||
| }; |
+51
-4
@@ -1,4 +0,51 @@ | ||
| import type { Drupe } from "./types"; | ||
| export declare const drupe: Drupe; | ||
| export type * from "./types"; | ||
| export * from "./cleaners"; | ||
| import { Cleaner } from 'cleaners'; | ||
| type Drupe = (selector: MangoSelector) => DrupeQuery; | ||
| type DrupeQuery = (subject: unknown) => boolean; | ||
| type MangoPrimitive = null | boolean | number | string; | ||
| type MangoValue = MangoPrimitive | MangoValue[] | { | ||
| [key: string]: MangoValue; | ||
| }; | ||
| type MangoDocument = { | ||
| [field: string]: MangoValue; | ||
| }; | ||
| type MangoType = "null" | "boolean" | "number" | "string" | "array" | "object"; | ||
| interface MangoKeyMapMatch { | ||
| [key: string]: MangoSelector | undefined; | ||
| $default?: MangoSelector; | ||
| } | ||
| interface MangoFieldMatcher { | ||
| $eq?: MangoValue; | ||
| $ne?: MangoValue | MangoValue[]; | ||
| $gt?: MangoValue; | ||
| $gte?: MangoValue; | ||
| $lt?: MangoValue; | ||
| $lte?: MangoValue; | ||
| $exists?: boolean; | ||
| $type?: MangoType; | ||
| $in?: MangoValue[]; | ||
| $nin?: MangoValue[]; | ||
| $size?: number; | ||
| $mod?: [number, number]; | ||
| $regex?: string | string[]; | ||
| $options?: string; | ||
| $all?: MangoValue[]; | ||
| $elemMatch?: MangoSelector; | ||
| $allMatch?: MangoSelector; | ||
| $keyMapMatch?: MangoKeyMapMatch; | ||
| $not?: MangoFieldSelector; | ||
| } | ||
| type MangoFieldSelector = MangoValue | MangoFieldMatcher | MangoSelector | (MangoFieldMatcher & MangoSelector); | ||
| interface MangoSelector { | ||
| [field: string]: MangoFieldSelector | MangoSelector[] | MangoSelector | undefined; | ||
| $and?: MangoSelector[]; | ||
| $or?: MangoSelector[]; | ||
| $nor?: MangoSelector[]; | ||
| $not?: MangoSelector; | ||
| } | ||
| declare const asMangoSelector: Cleaner<MangoSelector>; | ||
| declare const drupe: Drupe; | ||
| export { type Drupe, type DrupeQuery, type MangoDocument, type MangoFieldMatcher, type MangoFieldSelector, type MangoKeyMapMatch, type MangoPrimitive, type MangoSelector, type MangoType, type MangoValue, asMangoSelector, drupe }; |
+26
-17
| { | ||
| "name": "@edge.app/drupe", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "repository": "https://github.com/EdgeApp/drupe", | ||
@@ -12,10 +12,15 @@ "author": "Edge (Airbitz Inc.)", | ||
| "source": "./src/index.ts", | ||
| "main": "./dist/cjs/index.js", | ||
| "module": "./dist/esm/index.js", | ||
| "main": "./dist/index.cjs", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/esm/index.js", | ||
| "require": "./dist/cjs/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| "import": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
@@ -28,18 +33,22 @@ }, | ||
| "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true});\"", | ||
| "build:esm": "bun build ./src/index.ts --outdir ./dist/esm --format esm --packages external", | ||
| "build:cjs": "bun build ./src/index.ts --outdir ./dist/cjs --format cjs --packages external && cp cjs-package.json ./dist/cjs/package.json", | ||
| "build:types": "bunx tsc --project tsconfig.build.json", | ||
| "build:copy-types": "node -e \"const fs=require('fs');fs.mkdirSync('dist',{recursive:true});fs.copyFileSync('src/pouchdb-selector-core.d.ts','dist/pouchdb-selector-core.d.ts');\"", | ||
| "build": "bun run clean && bun run build:esm && bun run build:cjs && bun run build:types && bun run build:copy-types", | ||
| "prepare": "bun run build", | ||
| "release": "bun run prepare && bunx jsr publish && npm publish", | ||
| "test": "bun test", | ||
| "build": "tsup", | ||
| "typecheck": "tsc --noEmit", | ||
| "prepare": "npm run build", | ||
| "release": "npm run prepare && npx jsr publish && npm publish", | ||
| "test": "vitest run", | ||
| "version-bump": "tsx scripts/version-bump.ts", | ||
| "format": "prettier --write ." | ||
| }, | ||
| "devDependencies": { | ||
| "@types/bun": "latest", | ||
| "bun-promptx": "0.2.0", | ||
| "@inquirer/select": "^3.0.0", | ||
| "@types/node": "^20.0.0", | ||
| "prettier": "^3.6.2", | ||
| "tsup": "^8.3.0", | ||
| "tsx": "^4.19.0", | ||
| "typescript": "^5.6.3", | ||
| "prettier": "^3.6.2" | ||
| "vitest": "^4.0.0" | ||
| }, | ||
| "overrides": { | ||
| "uuid": "^11.0.0" | ||
| }, | ||
| "peerDependencies": { | ||
@@ -46,0 +55,0 @@ "typescript": "^5" |
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __moduleCache = /* @__PURE__ */ new WeakMap; | ||
| var __toCommonJS = (from) => { | ||
| var entry = __moduleCache.get(from), desc; | ||
| if (entry) | ||
| return entry; | ||
| entry = __defProp({}, "__esModule", { value: true }); | ||
| if (from && typeof from === "object" || typeof from === "function") | ||
| __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, { | ||
| get: () => from[key], | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable | ||
| })); | ||
| __moduleCache.set(from, entry); | ||
| return entry; | ||
| }; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { | ||
| get: all[name], | ||
| enumerable: true, | ||
| configurable: true, | ||
| set: (newValue) => all[name] = () => newValue | ||
| }); | ||
| }; | ||
| // src/index.ts | ||
| var exports_src = {}; | ||
| __export(exports_src, { | ||
| drupe: () => drupe, | ||
| asMangoSelector: () => asMangoSelector | ||
| }); | ||
| module.exports = __toCommonJS(exports_src); | ||
| var import_pouchdb_selector_core = require("pouchdb-selector-core"); | ||
| // src/cleaners.ts | ||
| var import_cleaners = require("cleaners"); | ||
| // src/util/locateError.ts | ||
| function locateError(error, step, offset) { | ||
| if (isErrorWithInsertStepAt(error)) { | ||
| if (error.insertStepAt == null) { | ||
| error.message += " at "; | ||
| error.insertStepAt = error.message.length; | ||
| } | ||
| error.message = error.message.slice(0, error.insertStepAt) + step + error.message.slice(error.insertStepAt); | ||
| error.insertStepAt += offset; | ||
| } | ||
| return error; | ||
| } | ||
| function isErrorWithInsertStepAt(error) { | ||
| if (error instanceof Error) { | ||
| if (!("insertStepAt" in error)) { | ||
| error.insertStepAt = null; | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| // src/cleaners.ts | ||
| var asMangoSelector = (raw) => { | ||
| if (typeof raw !== "object" || raw == null || Array.isArray(raw)) { | ||
| throw new TypeError("Expected a Mango selector object"); | ||
| } | ||
| const source = raw; | ||
| const result = {}; | ||
| for (const key of Object.keys(source)) { | ||
| try { | ||
| if (key === "__proto__") | ||
| continue; | ||
| const value = source[key]; | ||
| if (value === undefined) { | ||
| result[key] = undefined; | ||
| continue; | ||
| } | ||
| if (key === "$and" || key === "$or" || key === "$nor") { | ||
| result[key] = asMangoSelectorArray(value); | ||
| continue; | ||
| } | ||
| if (key === "$not") { | ||
| result[key] = asMangoSelector(value); | ||
| continue; | ||
| } | ||
| result[key] = import_cleaners.asEither(asMangoFieldSelector, asMangoSelectorArray)(value); | ||
| } catch (error) { | ||
| throw locateError(error, "." + key, 0); | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| var asMangoSelectorArray = import_cleaners.asArray(asMangoSelector); | ||
| var asMangoPrimitive = import_cleaners.asEither(import_cleaners.asNull, import_cleaners.asBoolean, import_cleaners.asNumber, import_cleaners.asString); | ||
| var asMangoValue = import_cleaners.asEither(asMangoPrimitive, import_cleaners.asArray((raw) => asMangoValue(raw)), import_cleaners.asObject((raw) => asMangoValue(raw))); | ||
| var asMangoValueArray = import_cleaners.asArray(asMangoValue); | ||
| var asMangoType = import_cleaners.asValue("null", "boolean", "number", "string", "array", "object"); | ||
| var asMangoKeyMapMatch = import_cleaners.asObject((raw) => raw === undefined ? undefined : asMangoSelector(raw)); | ||
| var asNumberPair = import_cleaners.asTuple(import_cleaners.asNumber, import_cleaners.asNumber); | ||
| var asRegex = import_cleaners.asEither(import_cleaners.asString, import_cleaners.asArray(import_cleaners.asString)); | ||
| var asMangoFieldMatcher = import_cleaners.asObject({ | ||
| $eq: import_cleaners.asOptional(asMangoValue), | ||
| $ne: import_cleaners.asOptional(import_cleaners.asEither(asMangoValue, asMangoValueArray)), | ||
| $gt: import_cleaners.asOptional(asMangoValue), | ||
| $gte: import_cleaners.asOptional(asMangoValue), | ||
| $lt: import_cleaners.asOptional(asMangoValue), | ||
| $lte: import_cleaners.asOptional(asMangoValue), | ||
| $exists: import_cleaners.asOptional(import_cleaners.asBoolean), | ||
| $type: import_cleaners.asOptional(asMangoType), | ||
| $in: import_cleaners.asOptional(asMangoValueArray), | ||
| $nin: import_cleaners.asOptional(asMangoValueArray), | ||
| $size: import_cleaners.asOptional(import_cleaners.asNumber), | ||
| $mod: import_cleaners.asOptional(asNumberPair), | ||
| $regex: import_cleaners.asOptional(asRegex), | ||
| $options: import_cleaners.asOptional(import_cleaners.asString), | ||
| $all: import_cleaners.asOptional(asMangoValueArray), | ||
| $elemMatch: import_cleaners.asOptional(asMangoSelector), | ||
| $allMatch: import_cleaners.asOptional(asMangoSelector), | ||
| $keyMapMatch: import_cleaners.asOptional(asMangoKeyMapMatch), | ||
| $not: import_cleaners.asOptional((raw) => asMangoFieldSelector(raw)) | ||
| }); | ||
| var asMangoFieldSelector = import_cleaners.asEither(asMangoValue, asMangoFieldMatcher, asMangoSelector); | ||
| // src/index.ts | ||
| var drupe = (selector) => (subject) => { | ||
| return import_pouchdb_selector_core.matchesSelector(subject, selector); | ||
| }; |
| { "type": "commonjs" } |
| import { type Cleaner } from "cleaners"; | ||
| import type { MangoSelector } from "./types"; | ||
| export declare const asMangoSelector: Cleaner<MangoSelector>; |
| // src/index.ts | ||
| import { matchesSelector } from "pouchdb-selector-core"; | ||
| // src/cleaners.ts | ||
| import { | ||
| asArray, | ||
| asBoolean, | ||
| asEither, | ||
| asNull, | ||
| asNumber, | ||
| asObject, | ||
| asOptional, | ||
| asString, | ||
| asTuple, | ||
| asValue | ||
| } from "cleaners"; | ||
| // src/util/locateError.ts | ||
| function locateError(error, step, offset) { | ||
| if (isErrorWithInsertStepAt(error)) { | ||
| if (error.insertStepAt == null) { | ||
| error.message += " at "; | ||
| error.insertStepAt = error.message.length; | ||
| } | ||
| error.message = error.message.slice(0, error.insertStepAt) + step + error.message.slice(error.insertStepAt); | ||
| error.insertStepAt += offset; | ||
| } | ||
| return error; | ||
| } | ||
| function isErrorWithInsertStepAt(error) { | ||
| if (error instanceof Error) { | ||
| if (!("insertStepAt" in error)) { | ||
| error.insertStepAt = null; | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| // src/cleaners.ts | ||
| var asMangoSelector = (raw) => { | ||
| if (typeof raw !== "object" || raw == null || Array.isArray(raw)) { | ||
| throw new TypeError("Expected a Mango selector object"); | ||
| } | ||
| const source = raw; | ||
| const result = {}; | ||
| for (const key of Object.keys(source)) { | ||
| try { | ||
| if (key === "__proto__") | ||
| continue; | ||
| const value = source[key]; | ||
| if (value === undefined) { | ||
| result[key] = undefined; | ||
| continue; | ||
| } | ||
| if (key === "$and" || key === "$or" || key === "$nor") { | ||
| result[key] = asMangoSelectorArray(value); | ||
| continue; | ||
| } | ||
| if (key === "$not") { | ||
| result[key] = asMangoSelector(value); | ||
| continue; | ||
| } | ||
| result[key] = asEither(asMangoFieldSelector, asMangoSelectorArray)(value); | ||
| } catch (error) { | ||
| throw locateError(error, "." + key, 0); | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
| var asMangoSelectorArray = asArray(asMangoSelector); | ||
| var asMangoPrimitive = asEither(asNull, asBoolean, asNumber, asString); | ||
| var asMangoValue = asEither(asMangoPrimitive, asArray((raw) => asMangoValue(raw)), asObject((raw) => asMangoValue(raw))); | ||
| var asMangoValueArray = asArray(asMangoValue); | ||
| var asMangoType = asValue("null", "boolean", "number", "string", "array", "object"); | ||
| var asMangoKeyMapMatch = asObject((raw) => raw === undefined ? undefined : asMangoSelector(raw)); | ||
| var asNumberPair = asTuple(asNumber, asNumber); | ||
| var asRegex = asEither(asString, asArray(asString)); | ||
| var asMangoFieldMatcher = asObject({ | ||
| $eq: asOptional(asMangoValue), | ||
| $ne: asOptional(asEither(asMangoValue, asMangoValueArray)), | ||
| $gt: asOptional(asMangoValue), | ||
| $gte: asOptional(asMangoValue), | ||
| $lt: asOptional(asMangoValue), | ||
| $lte: asOptional(asMangoValue), | ||
| $exists: asOptional(asBoolean), | ||
| $type: asOptional(asMangoType), | ||
| $in: asOptional(asMangoValueArray), | ||
| $nin: asOptional(asMangoValueArray), | ||
| $size: asOptional(asNumber), | ||
| $mod: asOptional(asNumberPair), | ||
| $regex: asOptional(asRegex), | ||
| $options: asOptional(asString), | ||
| $all: asOptional(asMangoValueArray), | ||
| $elemMatch: asOptional(asMangoSelector), | ||
| $allMatch: asOptional(asMangoSelector), | ||
| $keyMapMatch: asOptional(asMangoKeyMapMatch), | ||
| $not: asOptional((raw) => asMangoFieldSelector(raw)) | ||
| }); | ||
| var asMangoFieldSelector = asEither(asMangoValue, asMangoFieldMatcher, asMangoSelector); | ||
| // src/index.ts | ||
| var drupe = (selector) => (subject) => { | ||
| return matchesSelector(subject, selector); | ||
| }; | ||
| export { | ||
| drupe, | ||
| asMangoSelector | ||
| }; |
| declare module "pouchdb-selector-core" { | ||
| export function matchesSelector( | ||
| subject: unknown, | ||
| selector: import("./types").MangoSelector, | ||
| ): boolean; | ||
| } |
| export type Drupe = (selector: MangoSelector) => DrupeQuery; | ||
| export type DrupeQuery = (subject: unknown) => boolean; | ||
| export type MangoPrimitive = null | boolean | number | string; | ||
| export type MangoValue = MangoPrimitive | MangoValue[] | { | ||
| [key: string]: MangoValue; | ||
| }; | ||
| export type MangoDocument = { | ||
| [field: string]: MangoValue; | ||
| }; | ||
| export type MangoType = "null" | "boolean" | "number" | "string" | "array" | "object"; | ||
| export interface MangoKeyMapMatch { | ||
| [key: string]: MangoSelector | undefined; | ||
| $default?: MangoSelector; | ||
| } | ||
| export interface MangoFieldMatcher { | ||
| $eq?: MangoValue; | ||
| $ne?: MangoValue | MangoValue[]; | ||
| $gt?: MangoValue; | ||
| $gte?: MangoValue; | ||
| $lt?: MangoValue; | ||
| $lte?: MangoValue; | ||
| $exists?: boolean; | ||
| $type?: MangoType; | ||
| $in?: MangoValue[]; | ||
| $nin?: MangoValue[]; | ||
| $size?: number; | ||
| $mod?: [number, number]; | ||
| $regex?: string | string[]; | ||
| $options?: string; | ||
| $all?: MangoValue[]; | ||
| $elemMatch?: MangoSelector; | ||
| $allMatch?: MangoSelector; | ||
| $keyMapMatch?: MangoKeyMapMatch; | ||
| $not?: MangoFieldSelector; | ||
| } | ||
| export type MangoFieldSelector = MangoValue | MangoFieldMatcher | MangoSelector | (MangoFieldMatcher & MangoSelector); | ||
| export interface MangoSelector { | ||
| [field: string]: MangoFieldSelector | MangoSelector[] | MangoSelector | undefined; | ||
| $and?: MangoSelector[]; | ||
| $or?: MangoSelector[]; | ||
| $nor?: MangoSelector[]; | ||
| $not?: MangoSelector; | ||
| } |
| /** | ||
| * Adds location information to an error message. | ||
| * | ||
| * Errors can occur inside deeply-nested cleaners, | ||
| * such as "TypeError: Expected a string at .array[0].some.property". | ||
| * To build this information, each cleaner along the path | ||
| * should add its own location information as the stack unwinds. | ||
| * | ||
| * If the error has a `insertStepAt` property, that is the character offset | ||
| * where the next step will go in the error message. Otherwise, | ||
| * the next step just goes on the end of the string with the word "at". | ||
| */ | ||
| export declare function locateError(error: unknown, step: string, offset: number): unknown; |
Unstable ownership
Supply chain riskA new collaborator has begun publishing package versions. Package stability and security risk may be elevated.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17370
4.83%313
5.39%7
75%6
-40%1
Infinity%2
100%