node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
import{createTranslatorFactory as r,ITSELF as t}from"@ucast/core";export*from"@ucast/core";import{MongoQueryParser as o,allParsingInstructions as n,defaultParsers as e}from"@ucast/mongo";export*from"@ucast/mongo";import{createJsInterpreter as f,allInterpreters as u,compare as c}from"@ucast/js";export*from"@ucast/js";function i(){return(i=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(r[n]=o[n])}return r}).apply(this,arguments)}function a(r){return null===r||"object"!=typeof r?r:r instanceof Date?r.getTime():r&&"function"==typeof r.toJSON?r.toJSON():r}var m=function(r,t){return c(a(r),a(t))};function p(n,e,u){var c=new o(n),a=f(e,i({compare:m},u));if(u&&u.forPrimitives){var p={field:t},s=c.parse;c.setParse((function(r){return s(r,p)}))}return r(c.parse,a)}var s=p(n,u),v=p(["$and","$or"].reduce((function(r,t){return r[t]=i({},r[t],{type:"field"}),r}),i({},n,{$nor:i({},n.$nor,{type:"field",parse:e.compound})})),u,{forPrimitives:!0}),j=s;export{p as createFactory,j as filter,s as guard,v as squire};
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../src/factory.ts"],"sourcesContent":["import { createTranslatorFactory, ParsingInstruction, Condition, ITSELF } from '@ucast/core';\nimport {\n MongoQuery,\n MongoQueryParser,\n MongoQueryFieldOperators,\n allParsingInstructions,\n defaultParsers\n} from '@ucast/mongo';\nimport {\n createJsInterpreter,\n allInterpreters,\n JsInterpreter,\n JsInterpretationOptions,\n compare\n} from '@ucast/js';\n\ntype ThingFilter<T> = {\n (object: T): boolean\n ast: Condition\n};\n\ninterface HasToJSON {\n toJSON(): unknown\n}\n\nfunction toPrimitive(value: unknown) {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n if (value instanceof Date) {\n return value.getTime();\n }\n\n if (value && typeof (value as HasToJSON).toJSON === 'function') {\n return (value as HasToJSON).toJSON();\n }\n\n return value;\n}\n\nconst comparePrimitives: typeof compare = (a, b) => compare(toPrimitive(a), toPrimitive(b));\n\nexport interface FactoryOptions extends JsInterpretationOptions {\n forPrimitives: boolean\n}\n\nexport type Filter = <\n T = Record<string, unknown>,\n Q extends MongoQuery<T> = MongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\nexport type PrimitiveMongoQuery<T> = MongoQueryFieldOperators<T> & Partial<{\n $and: MongoQueryFieldOperators<T>[],\n $or: MongoQueryFieldOperators<T>[],\n $nor: MongoQueryFieldOperators<T>[]\n}>;\nexport type PrimitiveFilter = <\n T,\n Q extends PrimitiveMongoQuery<T> = PrimitiveMongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\ntype FilterType<T extends { forPrimitives?: true }> = T['forPrimitives'] extends true\n ? PrimitiveFilter\n : Filter;\n\nexport function createFactory<\n T extends Record<string, ParsingInstruction<any, any>>,\n I extends Record<string, JsInterpreter<any>>,\n P extends { forPrimitives?: true }\n>(instructions: T, interpreters: I, options?: Partial<FactoryOptions> & P): FilterType<P> {\n const parser = new MongoQueryParser(instructions);\n const interpret = createJsInterpreter(interpreters, {\n compare: comparePrimitives,\n ...options\n });\n\n if (options && options.forPrimitives) {\n const params = { field: ITSELF };\n const parse = parser.parse;\n parser.setParse(query => parse(query, params));\n }\n\n return createTranslatorFactory(parser.parse, interpret) as any;\n}\n\nexport const guard = createFactory(allParsingInstructions, allInterpreters);\n\nconst compoundOperators = ['$and', '$or'] as const;\nconst allPrimitiveParsingInstructions = compoundOperators.reduce((instructions, name) => {\n instructions[name] = { ...instructions[name], type: 'field' } as any;\n return instructions;\n}, {\n ...allParsingInstructions,\n $nor: {\n ...allParsingInstructions.$nor,\n type: 'field',\n parse: defaultParsers.compound\n }\n});\n\nexport const squire = createFactory(allPrimitiveParsingInstructions, allInterpreters, {\n forPrimitives: true\n});\nexport const filter = guard; // TODO: remove in next major version\n"],"names":["toPrimitive","value","Date","getTime","toJSON","comparePrimitives","a","b","compare","createFactory","instructions","interpreters","options","parser","MongoQueryParser","interpret","createJsInterpreter","forPrimitives","params","field","ITSELF","parse","setParse","query","createTranslatorFactory","guard","allParsingInstructions","allInterpreters","squire","reduce","name","type","$nor","defaultParsers","compound","filter"],"mappings":"6gBAyBA,SAASA,EAAYC,UACL,OAAVA,GAAmC,iBAAVA,EACpBA,EAGLA,aAAiBC,KACZD,EAAME,UAGXF,GAAgD,mBAA/BA,EAAoBG,OAC/BH,EAAoBG,SAGvBH,EAGT,IAAMI,EAAoC,SAACC,EAAGC,UAAMC,EAAQR,EAAYM,GAAIN,EAAYO,KAyBjF,SAASE,EAIdC,EAAiBC,EAAiBC,OAC5BC,EAAS,IAAIC,EAAiBJ,GAC9BK,EAAYC,EAAoBL,KACpCH,QAASH,GACNO,OAGDA,GAAWA,EAAQK,cAAe,KAC9BC,EAAS,CAAEC,MAAOC,GAClBC,EAAQR,EAAOQ,MACrBR,EAAOS,UAAS,SAAAC,UAASF,EAAME,EAAOL,aAGjCM,EAAwBX,EAAOQ,MAAON,OAGlCU,EAAQhB,EAAciB,EAAwBC,GAe9CC,EAASnB,EAbI,CAAC,OAAQ,OACuBoB,QAAO,SAACnB,EAAcoB,UAC9EpB,EAAaoB,QAAapB,EAAaoB,IAAOC,KAAM,UAC7CrB,SAEJgB,GACHM,UACKN,EAAuBM,MAC1BD,KAAM,QACNV,MAAOY,EAAeC,cAI2CP,EAAiB,CACpFV,eAAe,IAEJkB,EAASV"}

View File

@@ -0,0 +1,2 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ucast/core"),t=require("@ucast/mongo"),n=require("@ucast/js");function r(e){return null===e||"object"!=typeof e?e:e instanceof Date?e.getTime():e&&"function"==typeof e.toJSON?e.toJSON():e}const o=(e,t)=>n.compare(r(e),r(t));function c(r,c,u){const s=new t.MongoQueryParser(r),i=n.createJsInterpreter(c,Object.assign({compare:o},u));if(u&&u.forPrimitives){const t={field:e.ITSELF},n=s.parse;s.setParse(e=>n(e,t))}return e.createTranslatorFactory(s.parse,i)}const u=c(t.allParsingInstructions,n.allInterpreters),s=c(["$and","$or"].reduce((e,t)=>(e[t]=Object.assign({},e[t],{type:"field"}),e),Object.assign({},t.allParsingInstructions,{$nor:Object.assign({},t.allParsingInstructions.$nor,{type:"field",parse:t.defaultParsers.compound})})),n.allInterpreters,{forPrimitives:!0}),i=u;Object.keys(e).forEach((function(t){"default"!==t&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})})),Object.keys(t).forEach((function(e){"default"!==e&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})),Object.keys(n).forEach((function(e){"default"!==e&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})})),exports.createFactory=c,exports.filter=i,exports.guard=u,exports.squire=s;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../src/factory.ts"],"sourcesContent":["import { createTranslatorFactory, ParsingInstruction, Condition, ITSELF } from '@ucast/core';\nimport {\n MongoQuery,\n MongoQueryParser,\n MongoQueryFieldOperators,\n allParsingInstructions,\n defaultParsers\n} from '@ucast/mongo';\nimport {\n createJsInterpreter,\n allInterpreters,\n JsInterpreter,\n JsInterpretationOptions,\n compare\n} from '@ucast/js';\n\ntype ThingFilter<T> = {\n (object: T): boolean\n ast: Condition\n};\n\ninterface HasToJSON {\n toJSON(): unknown\n}\n\nfunction toPrimitive(value: unknown) {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n if (value instanceof Date) {\n return value.getTime();\n }\n\n if (value && typeof (value as HasToJSON).toJSON === 'function') {\n return (value as HasToJSON).toJSON();\n }\n\n return value;\n}\n\nconst comparePrimitives: typeof compare = (a, b) => compare(toPrimitive(a), toPrimitive(b));\n\nexport interface FactoryOptions extends JsInterpretationOptions {\n forPrimitives: boolean\n}\n\nexport type Filter = <\n T = Record<string, unknown>,\n Q extends MongoQuery<T> = MongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\nexport type PrimitiveMongoQuery<T> = MongoQueryFieldOperators<T> & Partial<{\n $and: MongoQueryFieldOperators<T>[],\n $or: MongoQueryFieldOperators<T>[],\n $nor: MongoQueryFieldOperators<T>[]\n}>;\nexport type PrimitiveFilter = <\n T,\n Q extends PrimitiveMongoQuery<T> = PrimitiveMongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\ntype FilterType<T extends { forPrimitives?: true }> = T['forPrimitives'] extends true\n ? PrimitiveFilter\n : Filter;\n\nexport function createFactory<\n T extends Record<string, ParsingInstruction<any, any>>,\n I extends Record<string, JsInterpreter<any>>,\n P extends { forPrimitives?: true }\n>(instructions: T, interpreters: I, options?: Partial<FactoryOptions> & P): FilterType<P> {\n const parser = new MongoQueryParser(instructions);\n const interpret = createJsInterpreter(interpreters, {\n compare: comparePrimitives,\n ...options\n });\n\n if (options && options.forPrimitives) {\n const params = { field: ITSELF };\n const parse = parser.parse;\n parser.setParse(query => parse(query, params));\n }\n\n return createTranslatorFactory(parser.parse, interpret) as any;\n}\n\nexport const guard = createFactory(allParsingInstructions, allInterpreters);\n\nconst compoundOperators = ['$and', '$or'] as const;\nconst allPrimitiveParsingInstructions = compoundOperators.reduce((instructions, name) => {\n instructions[name] = { ...instructions[name], type: 'field' } as any;\n return instructions;\n}, {\n ...allParsingInstructions,\n $nor: {\n ...allParsingInstructions.$nor,\n type: 'field',\n parse: defaultParsers.compound\n }\n});\n\nexport const squire = createFactory(allPrimitiveParsingInstructions, allInterpreters, {\n forPrimitives: true\n});\nexport const filter = guard; // TODO: remove in next major version\n"],"names":["toPrimitive","value","Date","getTime","toJSON","comparePrimitives","a","b","compare","createFactory","instructions","interpreters","options","parser","MongoQueryParser","interpret","createJsInterpreter","forPrimitives","params","field","ITSELF","parse","setParse","query","createTranslatorFactory","guard","allParsingInstructions","allInterpreters","squire","reduce","name","type","$nor","defaultParsers","compound","filter"],"mappings":"kJAyBA,SAASA,EAAYC,UACL,OAAVA,GAAmC,iBAAVA,EACpBA,EAGLA,aAAiBC,KACZD,EAAME,UAGXF,GAAgD,mBAA/BA,EAAoBG,OAC/BH,EAAoBG,SAGvBH,EAGT,MAAMI,EAAoC,CAACC,EAAGC,IAAMC,UAAQR,EAAYM,GAAIN,EAAYO,IAyBjF,SAASE,EAIdC,EAAiBC,EAAiBC,SAC5BC,EAAS,IAAIC,mBAAiBJ,GAC9BK,EAAYC,sBAAoBL,iBACpCH,QAASH,GACNO,OAGDA,GAAWA,EAAQK,cAAe,OAC9BC,EAAS,CAAEC,MAAOC,UAClBC,EAAQR,EAAOQ,MACrBR,EAAOS,SAASC,GAASF,EAAME,EAAOL,WAGjCM,0BAAwBX,EAAOQ,MAAON,SAGlCU,EAAQhB,EAAciB,yBAAwBC,mBAe9CC,EAASnB,EAbI,CAAC,OAAQ,OACuBoB,OAAO,CAACnB,EAAcoB,KAC9EpB,EAAaoB,oBAAapB,EAAaoB,IAAOC,KAAM,UAC7CrB,oBAEJgB,0BACHM,sBACKN,yBAAuBM,MAC1BD,KAAM,QACNV,MAAOY,iBAAeC,cAI2CP,kBAAiB,CACpFV,eAAe,IAEJkB,EAASV"}

View File

@@ -0,0 +1,2 @@
import{createTranslatorFactory as o,ITSELF as t}from"@ucast/core";export*from"@ucast/core";import{MongoQueryParser as e,allParsingInstructions as r,defaultParsers as c}from"@ucast/mongo";export*from"@ucast/mongo";import{createJsInterpreter as n,allInterpreters as f,compare as s}from"@ucast/js";export*from"@ucast/js";function i(o){return null===o||"object"!=typeof o?o:o instanceof Date?o.getTime():o&&"function"==typeof o.toJSON?o.toJSON():o}const m=(o,t)=>s(i(o),i(t));function p(r,c,f){const s=new e(r),i=n(c,Object.assign({compare:m},f));if(f&&f.forPrimitives){const o={field:t},e=s.parse;s.setParse(t=>e(t,o))}return o(s.parse,i)}const u=p(r,f),a=p(["$and","$or"].reduce((o,t)=>(o[t]=Object.assign({},o[t],{type:"field"}),o),Object.assign({},r,{$nor:Object.assign({},r.$nor,{type:"field",parse:c.compound})})),f,{forPrimitives:!0}),j=u;export{p as createFactory,j as filter,u as guard,a as squire};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../src/factory.ts"],"sourcesContent":["import { createTranslatorFactory, ParsingInstruction, Condition, ITSELF } from '@ucast/core';\nimport {\n MongoQuery,\n MongoQueryParser,\n MongoQueryFieldOperators,\n allParsingInstructions,\n defaultParsers\n} from '@ucast/mongo';\nimport {\n createJsInterpreter,\n allInterpreters,\n JsInterpreter,\n JsInterpretationOptions,\n compare\n} from '@ucast/js';\n\ntype ThingFilter<T> = {\n (object: T): boolean\n ast: Condition\n};\n\ninterface HasToJSON {\n toJSON(): unknown\n}\n\nfunction toPrimitive(value: unknown) {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n if (value instanceof Date) {\n return value.getTime();\n }\n\n if (value && typeof (value as HasToJSON).toJSON === 'function') {\n return (value as HasToJSON).toJSON();\n }\n\n return value;\n}\n\nconst comparePrimitives: typeof compare = (a, b) => compare(toPrimitive(a), toPrimitive(b));\n\nexport interface FactoryOptions extends JsInterpretationOptions {\n forPrimitives: boolean\n}\n\nexport type Filter = <\n T = Record<string, unknown>,\n Q extends MongoQuery<T> = MongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\nexport type PrimitiveMongoQuery<T> = MongoQueryFieldOperators<T> & Partial<{\n $and: MongoQueryFieldOperators<T>[],\n $or: MongoQueryFieldOperators<T>[],\n $nor: MongoQueryFieldOperators<T>[]\n}>;\nexport type PrimitiveFilter = <\n T,\n Q extends PrimitiveMongoQuery<T> = PrimitiveMongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\ntype FilterType<T extends { forPrimitives?: true }> = T['forPrimitives'] extends true\n ? PrimitiveFilter\n : Filter;\n\nexport function createFactory<\n T extends Record<string, ParsingInstruction<any, any>>,\n I extends Record<string, JsInterpreter<any>>,\n P extends { forPrimitives?: true }\n>(instructions: T, interpreters: I, options?: Partial<FactoryOptions> & P): FilterType<P> {\n const parser = new MongoQueryParser(instructions);\n const interpret = createJsInterpreter(interpreters, {\n compare: comparePrimitives,\n ...options\n });\n\n if (options && options.forPrimitives) {\n const params = { field: ITSELF };\n const parse = parser.parse;\n parser.setParse(query => parse(query, params));\n }\n\n return createTranslatorFactory(parser.parse, interpret) as any;\n}\n\nexport const guard = createFactory(allParsingInstructions, allInterpreters);\n\nconst compoundOperators = ['$and', '$or'] as const;\nconst allPrimitiveParsingInstructions = compoundOperators.reduce((instructions, name) => {\n instructions[name] = { ...instructions[name], type: 'field' } as any;\n return instructions;\n}, {\n ...allParsingInstructions,\n $nor: {\n ...allParsingInstructions.$nor,\n type: 'field',\n parse: defaultParsers.compound\n }\n});\n\nexport const squire = createFactory(allPrimitiveParsingInstructions, allInterpreters, {\n forPrimitives: true\n});\nexport const filter = guard; // TODO: remove in next major version\n"],"names":["toPrimitive","value","Date","getTime","toJSON","comparePrimitives","a","b","compare","createFactory","instructions","interpreters","options","parser","MongoQueryParser","interpret","createJsInterpreter","forPrimitives","params","field","ITSELF","parse","setParse","query","createTranslatorFactory","guard","allParsingInstructions","allInterpreters","squire","reduce","name","type","$nor","defaultParsers","compound","filter"],"mappings":"8TAyBA,SAASA,EAAYC,UACL,OAAVA,GAAmC,iBAAVA,EACpBA,EAGLA,aAAiBC,KACZD,EAAME,UAGXF,GAAgD,mBAA/BA,EAAoBG,OAC/BH,EAAoBG,SAGvBH,EAGT,MAAMI,EAAoC,CAACC,EAAGC,IAAMC,EAAQR,EAAYM,GAAIN,EAAYO,IAyBjF,SAASE,EAIdC,EAAiBC,EAAiBC,SAC5BC,EAAS,IAAIC,EAAiBJ,GAC9BK,EAAYC,EAAoBL,iBACpCH,QAASH,GACNO,OAGDA,GAAWA,EAAQK,cAAe,OAC9BC,EAAS,CAAEC,MAAOC,GAClBC,EAAQR,EAAOQ,MACrBR,EAAOS,SAASC,GAASF,EAAME,EAAOL,WAGjCM,EAAwBX,EAAOQ,MAAON,SAGlCU,EAAQhB,EAAciB,EAAwBC,GAe9CC,EAASnB,EAbI,CAAC,OAAQ,OACuBoB,OAAO,CAACnB,EAAcoB,KAC9EpB,EAAaoB,oBAAapB,EAAaoB,IAAOC,KAAM,UAC7CrB,oBAEJgB,GACHM,sBACKN,EAAuBM,MAC1BD,KAAM,QACNV,MAAOY,EAAeC,cAI2CP,EAAiB,CACpFV,eAAe,IAEJkB,EAASV"}

View File

@@ -0,0 +1,27 @@
import { ParsingInstruction, Condition } from '@ucast/core';
import { MongoQuery, MongoQueryFieldOperators } from '@ucast/mongo';
import { JsInterpreter, JsInterpretationOptions } from '@ucast/js';
declare type ThingFilter<T> = {
(object: T): boolean;
ast: Condition;
};
export interface FactoryOptions extends JsInterpretationOptions {
forPrimitives: boolean;
}
export declare type Filter = <T = Record<string, unknown>, Q extends MongoQuery<T> = MongoQuery<T>>(query: Q) => ThingFilter<T>;
export declare type PrimitiveMongoQuery<T> = MongoQueryFieldOperators<T> & Partial<{
$and: MongoQueryFieldOperators<T>[];
$or: MongoQueryFieldOperators<T>[];
$nor: MongoQueryFieldOperators<T>[];
}>;
export declare type PrimitiveFilter = <T, Q extends PrimitiveMongoQuery<T> = PrimitiveMongoQuery<T>>(query: Q) => ThingFilter<T>;
declare type FilterType<T extends {
forPrimitives?: true;
}> = T['forPrimitives'] extends true ? PrimitiveFilter : Filter;
export declare function createFactory<T extends Record<string, ParsingInstruction<any, any>>, I extends Record<string, JsInterpreter<any>>, P extends {
forPrimitives?: true;
}>(instructions: T, interpreters: I, options?: Partial<FactoryOptions> & P): FilterType<P>;
export declare const guard: Filter;
export declare const squire: PrimitiveFilter;
export declare const filter: Filter;
export {};

View File

@@ -0,0 +1,4 @@
export * from './factory';
export * from '@ucast/js';
export * from '@ucast/mongo';
export * from '@ucast/core';

View File

@@ -0,0 +1,2 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ucast/core"),require("@ucast/mongo"),require("@ucast/js")):"function"==typeof define&&define.amd?define(["exports","@ucast/core","@ucast/mongo","@ucast/js"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ucast=e.ucast||{},e.ucast.mongo2js={}),e.ucast.core,e.ucast.mongo,e.ucast.js)}(this,(function(e,t,n,r){"use strict";function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e){return null===e||"object"!=typeof e?e:e instanceof Date?e.getTime():e&&"function"==typeof e.toJSON?e.toJSON():e}var f=function(e,t){return r.compare(o(e),o(t))};function c(e,o,c){var i=new n.MongoQueryParser(e),a=r.createJsInterpreter(o,u({compare:f},c));if(c&&c.forPrimitives){var s={field:t.ITSELF},l=i.parse;i.setParse((function(e){return l(e,s)}))}return t.createTranslatorFactory(i.parse,a)}var i=c(n.allParsingInstructions,r.allInterpreters),a=c(["$and","$or"].reduce((function(e,t){return e[t]=u({},e[t],{type:"field"}),e}),u({},n.allParsingInstructions,{$nor:u({},n.allParsingInstructions.$nor,{type:"field",parse:n.defaultParsers.compound})})),r.allInterpreters,{forPrimitives:!0}),s=i;Object.keys(t).forEach((function(n){"default"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),Object.keys(n).forEach((function(t){"default"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})})),Object.keys(r).forEach((function(t){"default"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),e.createFactory=c,e.filter=s,e.guard=i,e.squire=a,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../src/factory.ts"],"sourcesContent":["import { createTranslatorFactory, ParsingInstruction, Condition, ITSELF } from '@ucast/core';\nimport {\n MongoQuery,\n MongoQueryParser,\n MongoQueryFieldOperators,\n allParsingInstructions,\n defaultParsers\n} from '@ucast/mongo';\nimport {\n createJsInterpreter,\n allInterpreters,\n JsInterpreter,\n JsInterpretationOptions,\n compare\n} from '@ucast/js';\n\ntype ThingFilter<T> = {\n (object: T): boolean\n ast: Condition\n};\n\ninterface HasToJSON {\n toJSON(): unknown\n}\n\nfunction toPrimitive(value: unknown) {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n if (value instanceof Date) {\n return value.getTime();\n }\n\n if (value && typeof (value as HasToJSON).toJSON === 'function') {\n return (value as HasToJSON).toJSON();\n }\n\n return value;\n}\n\nconst comparePrimitives: typeof compare = (a, b) => compare(toPrimitive(a), toPrimitive(b));\n\nexport interface FactoryOptions extends JsInterpretationOptions {\n forPrimitives: boolean\n}\n\nexport type Filter = <\n T = Record<string, unknown>,\n Q extends MongoQuery<T> = MongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\nexport type PrimitiveMongoQuery<T> = MongoQueryFieldOperators<T> & Partial<{\n $and: MongoQueryFieldOperators<T>[],\n $or: MongoQueryFieldOperators<T>[],\n $nor: MongoQueryFieldOperators<T>[]\n}>;\nexport type PrimitiveFilter = <\n T,\n Q extends PrimitiveMongoQuery<T> = PrimitiveMongoQuery<T>\n>(query: Q) => ThingFilter<T>;\n\ntype FilterType<T extends { forPrimitives?: true }> = T['forPrimitives'] extends true\n ? PrimitiveFilter\n : Filter;\n\nexport function createFactory<\n T extends Record<string, ParsingInstruction<any, any>>,\n I extends Record<string, JsInterpreter<any>>,\n P extends { forPrimitives?: true }\n>(instructions: T, interpreters: I, options?: Partial<FactoryOptions> & P): FilterType<P> {\n const parser = new MongoQueryParser(instructions);\n const interpret = createJsInterpreter(interpreters, {\n compare: comparePrimitives,\n ...options\n });\n\n if (options && options.forPrimitives) {\n const params = { field: ITSELF };\n const parse = parser.parse;\n parser.setParse(query => parse(query, params));\n }\n\n return createTranslatorFactory(parser.parse, interpret) as any;\n}\n\nexport const guard = createFactory(allParsingInstructions, allInterpreters);\n\nconst compoundOperators = ['$and', '$or'] as const;\nconst allPrimitiveParsingInstructions = compoundOperators.reduce((instructions, name) => {\n instructions[name] = { ...instructions[name], type: 'field' } as any;\n return instructions;\n}, {\n ...allParsingInstructions,\n $nor: {\n ...allParsingInstructions.$nor,\n type: 'field',\n parse: defaultParsers.compound\n }\n});\n\nexport const squire = createFactory(allPrimitiveParsingInstructions, allInterpreters, {\n forPrimitives: true\n});\nexport const filter = guard; // TODO: remove in next major version\n"],"names":["toPrimitive","value","Date","getTime","toJSON","comparePrimitives","a","b","compare","createFactory","instructions","interpreters","options","parser","MongoQueryParser","interpret","createJsInterpreter","forPrimitives","params","field","ITSELF","parse","setParse","query","createTranslatorFactory","guard","allParsingInstructions","allInterpreters","squire","reduce","name","type","$nor","defaultParsers","compound","filter"],"mappings":"onBAyBA,SAASA,EAAYC,UACL,OAAVA,GAAmC,iBAAVA,EACpBA,EAGLA,aAAiBC,KACZD,EAAME,UAGXF,GAAgD,mBAA/BA,EAAoBG,OAC/BH,EAAoBG,SAGvBH,EAGT,IAAMI,EAAoC,SAACC,EAAGC,UAAMC,UAAQR,EAAYM,GAAIN,EAAYO,KAyBjF,SAASE,EAIdC,EAAiBC,EAAiBC,OAC5BC,EAAS,IAAIC,mBAAiBJ,GAC9BK,EAAYC,sBAAoBL,KACpCH,QAASH,GACNO,OAGDA,GAAWA,EAAQK,cAAe,KAC9BC,EAAS,CAAEC,MAAOC,UAClBC,EAAQR,EAAOQ,MACrBR,EAAOS,UAAS,SAAAC,UAASF,EAAME,EAAOL,aAGjCM,0BAAwBX,EAAOQ,MAAON,OAGlCU,EAAQhB,EAAciB,yBAAwBC,mBAe9CC,EAASnB,EAbI,CAAC,OAAQ,OACuBoB,QAAO,SAACnB,EAAcoB,UAC9EpB,EAAaoB,QAAapB,EAAaoB,IAAOC,KAAM,UAC7CrB,SAEJgB,0BACHM,UACKN,yBAAuBM,MAC1BD,KAAM,QACNV,MAAOY,iBAAeC,cAI2CP,kBAAiB,CACpFV,eAAe,IAEJkB,EAASV"}