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

176
server/node_modules/@ucast/core/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

13
server/node_modules/@ucast/core/NOTICE generated vendored Normal file
View File

@@ -0,0 +1,13 @@
Copyright 2020 Sergii Stotskyi <sergiy.stotskiy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

68
server/node_modules/@ucast/core/README.md generated vendored Normal file
View File

@@ -0,0 +1,68 @@
# Universal Conditions AST
[![@ucast/core NPM version](https://badge.fury.io/js/%40ucast%2Fcore.svg)](https://badge.fury.io/js/%40ucast%2Fcore)
[![](https://img.shields.io/npm/dm/%40ucast%2Fcore.svg)](https://www.npmjs.com/package/%40ucast%2Fcore)
[![UCAST join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-ucast/community)
This package contains classes and functions that helps to create parsers, conditions AST, interpreters and translators.
## Installation
```sh
npm i @ucast/core
# or
yarn add @ucast/core
# or
pnpm add @ucast/core
```
## Getting Started
### Parser
Parser is a function that translates conditions from any language into conditions AST. For example, `MongoQueryParser` parses MongoQuery into AST which then can be interpreted by `JavaScriptInterpreter` that returns a boolean value based on passed in object.
### Conditions AST
Abstract Syntax Tree of any condition. **What is condition?**
`x > 4` is a condition, `x === 4` is a condition as well, `{ x: { $eq: 4 } }` is a [MongoQuery](http://docs.mongodb.org/manual/reference/operator/query/) condition.
There are few types of AST nodes that allow us to represent any condition:
* **FieldCondition**. \
Depends on a field, operator and its value. For example, in condition `x > 4`, `x` is a field, `4` is a value and `>` is operator
* **DocumentCondition**. \
Any condition that test a document (or a row) as whole (e.g., in MongoDB Query, it's `$where` operator and in SQL it's `EXISTS`).
* **CompoundCondition**. \
Combines other conditions using logical operations like "and", "or", "not".
### Interpreter
An interpreter is a function that interprets conditions AST in a specific way. For example, it can:
* interpret conditions in JavaScript runtime to return a boolean result
* or it can convert conditions into SQL `WHERE` statement
* or MongoDB query,
* or HTTP/REST query
* or GraphQL input
* or anything else you can imagine
### Translator
Combines Parser and Interpreter and returns a factory function:
```js
const parse = (query) => /* to conditions AST */
const interpreter = createInterpreter({ /* condition interpreters */ });
const translate = (query, ...args) => interpreter.bind(null, parse(query));
```
## Want to help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for [contributing]
## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
[contributing]: https://github.com/stalniy/ucast/blob/master/CONTRIBUTING.md

2
server/node_modules/@ucast/core/dist/es5m/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
server/node_modules/@ucast/core/dist/es6c/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{constructor(t,e){this.operator=t,this.value=e,Object.defineProperty(this,"t",{writable:!0})}get notes(){return this.t}addNote(t){this.t=this.t||[],this.t.push(t)}}class e extends t{}class r extends e{constructor(t,e){if(!Array.isArray(e))throw new Error(`"${t}" operator expects to receive an array of conditions`);super(t,e)}}class o extends t{constructor(t,e,r){super(t,r),this.field=e}}const s=new e("__null__",null),n=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);function i(t,e){return e instanceof r&&e.operator===t}function c(t,e){return 1===e.length?e[0]:new r(t,function t(e,r,o){const s=o||[];for(let o=0,n=r.length;o<n;o++){const n=r[o];i(e,n)?t(e,n.value,s):s.push(n)}return s}(t,e))}const u=t=>t,a=()=>Object.create(null),h=Object.defineProperty(a(),"__@type@__",{value:"ignore value"});function p(t,e,r=!1){if(!t||t&&t.constructor!==Object)return!1;for(const o in t){if(n(t,o)&&n(e,o)&&(!r||t[o]!==h))return!0}return!1}function f(t){const e=[];for(const r in t)n(t,r)&&t[r]!==h&&e.push(r);return e}function l(t,e){e!==s&&t.push(e)}const d=t=>c("and",t),x={compound(t,e,o){const s=(Array.isArray(e)?e:[e]).map(t=>o.parse(t));return new r(t.name,s)},field:(t,e,r)=>new o(t.name,r.field,e),document:(t,r)=>new e(t.name,r)};class b{constructor(t,e=a()){this.o=void 0,this.s=void 0,this.i=void 0,this.u=void 0,this.h=void 0,this.parse=this.parse.bind(this),this.u={operatorToConditionName:e.operatorToConditionName||u,defaultOperatorName:e.defaultOperatorName||"eq",mergeFinalConditions:e.mergeFinalConditions||d},this.o=Object.keys(t).reduce((e,r)=>(e[r]=Object.assign({name:this.u.operatorToConditionName(r)},t[r]),e),{}),this.s=Object.assign({},e.fieldContext,{field:"",query:{},parse:this.parse,hasOperators:t=>p(t,this.o,e.useIgnoreValue)}),this.i=Object.assign({},e.documentContext,{parse:this.parse,query:{}}),this.h=e.useIgnoreValue?f:Object.keys}setParse(t){this.parse=t,this.s.parse=t,this.i.parse=t}parseField(t,e,r,o){const s=this.o[e];if(!s)throw new Error(`Unsupported operator "${e}"`);if("field"!==s.type)throw new Error(`Unexpected ${s.type} operator "${e}" at field level`);return this.s.field=t,this.s.query=o,this.parseInstruction(s,r,this.s)}parseInstruction(t,e,r){"function"==typeof t.validate&&t.validate(t,e);return(t.parse||x[t.type])(t,e,r)}parseFieldOperators(t,e){const r=[],o=this.h(e);for(let s=0,n=o.length;s<n;s++){const n=o[s];if(!this.o[n])throw new Error(`Field query for "${t}" may contain only operators or a plain object as a value`);l(r,this.parseField(t,n,e[n],e))}return r}parse(t){const e=[],r=this.h(t);this.i.query=t;for(let o=0,s=r.length;o<s;o++){const s=r[o],n=t[s],i=this.o[s];if(i){if("document"!==i.type&&"compound"!==i.type)throw new Error(`Cannot use parsing instruction for operator "${s}" in "document" context as it is supposed to be used in "${i.type}" context`);l(e,this.parseInstruction(i,n,this.i))}else this.s.hasOperators(n)?e.push(...this.parseFieldOperators(s,n)):l(e,this.parseField(s,this.u.defaultOperatorName,n,t))}return this.u.mergeFinalConditions(e)}}function w(t,e){const r=t[e];if("function"!=typeof r)throw new Error(`Unable to interpret "${e}" condition. Did you forget to register interpreter for it?`);return r}function O(t){return t.operator}const _=b.prototype.parseInstruction;exports.CompoundCondition=r,exports.Condition=t,exports.DocumentCondition=e,exports.FieldCondition=o,exports.ITSELF="__itself__",exports.NULL_CONDITION=s,exports.ObjectQueryParser=b,exports.buildAnd=d,exports.buildOr=t=>c("or",t),exports.createInterpreter=function(t,e){const r=e,o=r&&r.getInterpreterName||O;let s;switch(r?r.numberOfArguments:0){case 1:s=e=>{const s=o(e,r);return w(t,s)(e,n)};break;case 3:s=(e,s,i)=>{const c=o(e,r);return w(t,c)(e,s,i,n)};break;default:s=(e,s)=>{const i=o(e,r);return w(t,i)(e,s,n)}}const n=Object.assign({},r,{interpret:s});return n.interpret},exports.createTranslatorFactory=function(t,e){return(r,...o)=>{const s=t(r,...o),n=e.bind(null,s);return n.ast=s,n}},exports.defaultInstructionParsers=x,exports.hasOperators=p,exports.identity=u,exports.ignoreValue=h,exports.isCompound=i,exports.object=a,exports.optimizedCompoundCondition=c,exports.parseInstruction=_;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

2
server/node_modules/@ucast/core/dist/es6m/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
class t{constructor(t,e){this.operator=t,this.value=e,Object.defineProperty(this,"t",{writable:!0})}get notes(){return this.t}addNote(t){this.t=this.t||[],this.t.push(t)}}class e extends t{}class r extends e{constructor(t,e){if(!Array.isArray(e))throw new Error(`"${t}" operator expects to receive an array of conditions`);super(t,e)}}const n="__itself__";class o extends t{constructor(t,e,r){super(t,r),this.field=e}}const s=new e("__null__",null),i=Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);function c(t,e){return e instanceof r&&e.operator===t}function u(t,e){return 1===e.length?e[0]:new r(t,function t(e,r,n){const o=n||[];for(let n=0,s=r.length;n<s;n++){const s=r[n];c(e,s)?t(e,s.value,o):o.push(s)}return o}(t,e))}const a=t=>t,h=()=>Object.create(null),f=Object.defineProperty(h(),"__@type@__",{value:"ignore value"});function l(t,e,r=!1){if(!t||t&&t.constructor!==Object)return!1;for(const n in t){if(i(t,n)&&i(e,n)&&(!r||t[n]!==f))return!0}return!1}function d(t){const e=[];for(const r in t)i(t,r)&&t[r]!==f&&e.push(r);return e}function p(t,e){e!==s&&t.push(e)}const w=t=>u("and",t),b=t=>u("or",t),O={compound(t,e,n){const o=(Array.isArray(e)?e:[e]).map(t=>n.parse(t));return new r(t.name,o)},field:(t,e,r)=>new o(t.name,r.field,e),document:(t,r)=>new e(t.name,r)};class j{constructor(t,e=h()){this.o=void 0,this.s=void 0,this.i=void 0,this.u=void 0,this.h=void 0,this.parse=this.parse.bind(this),this.u={operatorToConditionName:e.operatorToConditionName||a,defaultOperatorName:e.defaultOperatorName||"eq",mergeFinalConditions:e.mergeFinalConditions||w},this.o=Object.keys(t).reduce((e,r)=>(e[r]=Object.assign({name:this.u.operatorToConditionName(r)},t[r]),e),{}),this.s=Object.assign({},e.fieldContext,{field:"",query:{},parse:this.parse,hasOperators:t=>l(t,this.o,e.useIgnoreValue)}),this.i=Object.assign({},e.documentContext,{parse:this.parse,query:{}}),this.h=e.useIgnoreValue?d:Object.keys}setParse(t){this.parse=t,this.s.parse=t,this.i.parse=t}parseField(t,e,r,n){const o=this.o[e];if(!o)throw new Error(`Unsupported operator "${e}"`);if("field"!==o.type)throw new Error(`Unexpected ${o.type} operator "${e}" at field level`);return this.s.field=t,this.s.query=n,this.parseInstruction(o,r,this.s)}parseInstruction(t,e,r){"function"==typeof t.validate&&t.validate(t,e);return(t.parse||O[t.type])(t,e,r)}parseFieldOperators(t,e){const r=[],n=this.h(e);for(let o=0,s=n.length;o<s;o++){const s=n[o];if(!this.o[s])throw new Error(`Field query for "${t}" may contain only operators or a plain object as a value`);p(r,this.parseField(t,s,e[s],e))}return r}parse(t){const e=[],r=this.h(t);this.i.query=t;for(let n=0,o=r.length;n<o;n++){const o=r[n],s=t[o],i=this.o[o];if(i){if("document"!==i.type&&"compound"!==i.type)throw new Error(`Cannot use parsing instruction for operator "${o}" in "document" context as it is supposed to be used in "${i.type}" context`);p(e,this.parseInstruction(i,s,this.i))}else this.s.hasOperators(s)?e.push(...this.parseFieldOperators(o,s)):p(e,this.parseField(o,this.u.defaultOperatorName,s,t))}return this.u.mergeFinalConditions(e)}}function _(t,e){const r=t[e];if("function"!=typeof r)throw new Error(`Unable to interpret "${e}" condition. Did you forget to register interpreter for it?`);return r}function y(t){return t.operator}function m(t,e){const r=e,n=r&&r.getInterpreterName||y;let o;switch(r?r.numberOfArguments:0){case 1:o=e=>{const o=n(e,r);return _(t,o)(e,s)};break;case 3:o=(e,o,i)=>{const c=n(e,r);return _(t,c)(e,o,i,s)};break;default:o=(e,o)=>{const i=n(e,r);return _(t,i)(e,o,s)}}const s=Object.assign({},r,{interpret:o});return s.interpret}function v(t,e){return(r,...n)=>{const o=t(r,...n),s=e.bind(null,o);return s.ast=o,s}}const x=j.prototype.parseInstruction;export{r as CompoundCondition,t as Condition,e as DocumentCondition,o as FieldCondition,n as ITSELF,s as NULL_CONDITION,j as ObjectQueryParser,w as buildAnd,b as buildOr,m as createInterpreter,v as createTranslatorFactory,O as defaultInstructionParsers,l as hasOperators,a as identity,f as ignoreValue,c as isCompound,h as object,u as optimizedCompoundCondition,x as parseInstruction};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,25 @@
export interface Note<T> {
type: string;
message?: string;
originalValue?: T;
}
export declare abstract class Condition<T = unknown> {
readonly operator: string;
readonly value: T;
private _notes;
constructor(operator: string, value: T);
get notes(): ReadonlyArray<Note<T>> | undefined;
addNote(note: Note<T>): void;
}
export declare class DocumentCondition<T> extends Condition<T> {
}
export declare class CompoundCondition<T extends Condition = Condition> extends DocumentCondition<T[]> {
constructor(operator: string, conditions: T[]);
}
export declare const ITSELF = "__itself__";
export declare class FieldCondition<T = unknown> extends Condition<T> {
readonly field: string | typeof ITSELF;
constructor(operator: string, field: string | typeof ITSELF, value: T);
}
export declare const NULL_CONDITION: DocumentCondition<null>;
export declare type ConditionValue<T> = T extends Condition<infer V> ? V : unknown;

View File

@@ -0,0 +1,3 @@
import { Condition } from './Condition';
export declare const buildAnd: (conditions: Condition[]) => Condition<unknown> | import("./Condition").CompoundCondition<Condition<unknown>>;
export declare const buildOr: (conditions: Condition[]) => Condition<unknown> | import("./Condition").CompoundCondition<Condition<unknown>>;

14
server/node_modules/@ucast/core/dist/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
export * from './Condition';
export * from './types';
export * from './interpreter';
export * from './translator';
export * from './builder';
export { isCompound, hasOperators, identity, object, optimizedCompoundCondition, ignoreValue, } from './utils';
export type { IgnoreValue } from './utils';
export * from './parsers/ObjectQueryParser';
export * from './parsers/defaultInstructionParsers';
/**
* @deprecated use `ObjectQueryParser#parseInstruction` instead
* TODO(major): remove
*/
export declare const parseInstruction: any;

View File

@@ -0,0 +1,13 @@
import { Condition } from './Condition';
declare type ArgsExceptLast<F extends (...args: any[]) => any> = F extends (a: any, c: any) => any ? Parameters<(condition: Condition) => 0> : F extends (a: any, b: any, c: any) => any ? Parameters<(condition: Condition, value: Parameters<F>[1]) => 0> : Parameters<(condition: Condition, value: Parameters<F>[1], options: Parameters<F>[2], ...args: unknown[]) => 0>;
export declare type Interpreter<T extends Condition, R> = (condition: T, ...args: any[]) => R;
export declare type AnyInterpreter = Interpreter<any, any>;
export interface InterpretationContext<T extends AnyInterpreter> {
interpret(...args: ArgsExceptLast<T>): ReturnType<T>;
}
export interface InterpreterOptions {
numberOfArguments?: 1 | 2 | 3;
getInterpreterName?(condition: Condition, context: this): string;
}
export declare function createInterpreter<T extends AnyInterpreter, U extends {} = {}>(interpreters: Record<string, T>, rawOptions?: U): (...args: ArgsExceptLast<T>) => ReturnType<T>;
export {};

View File

@@ -0,0 +1,30 @@
import { Condition } from '../Condition';
import { NamedInstruction, ParsingInstruction, FieldParsingContext, ParsingContext } from '../types';
export declare type FieldQueryOperators<T extends {}> = {
[K in keyof T]: T[K] extends {} ? T[K] : never;
}[keyof T];
export interface QueryOptions {
operatorToConditionName?(name: string): string;
defaultOperatorName?: string;
fieldContext?: Record<string, unknown>;
documentContext?: Record<string, unknown>;
useIgnoreValue?: boolean;
mergeFinalConditions?(conditions: Condition[]): Condition;
}
export declare type ObjectQueryFieldParsingContext = ParsingContext<FieldParsingContext & {
query: {};
hasOperators<T>(value: unknown): value is T;
}>;
export declare class ObjectQueryParser<T extends Record<any, any>, U extends FieldQueryOperators<T> = FieldQueryOperators<T>> {
private readonly _instructions;
private _fieldInstructionContext;
private _documentInstructionContext;
private readonly _options;
private readonly _objectKeys;
constructor(instructions: Record<string, ParsingInstruction>, options?: QueryOptions);
setParse(parse: this['parse']): void;
protected parseField(field: string, operator: string, value: unknown, parentQuery: {}): Condition<unknown>;
protected parseInstruction(instruction: NamedInstruction, value: unknown, context: ParsingContext<{}>): Condition<unknown>;
protected parseFieldOperators(field: string, value: U): Condition<unknown>[];
parse<Q extends T>(query: Q): Condition;
}

View File

@@ -0,0 +1,8 @@
import { DocumentInstruction, CompoundInstruction, FieldInstruction } from '../types';
interface DefaultParsers {
compound: Exclude<CompoundInstruction['parse'], undefined>;
field: Exclude<FieldInstruction['parse'], undefined>;
document: Exclude<DocumentInstruction['parse'], undefined>;
}
export declare const defaultInstructionParsers: DefaultParsers;
export {};

View File

@@ -0,0 +1,9 @@
import { Condition } from './Condition';
import { Parse } from './types';
import { AnyInterpreter } from './interpreter';
declare type Bound<T> = T extends (first: Condition, ...args: infer A) => any ? {
(...args: A): ReturnType<T>;
ast: Condition;
} : never;
export declare function createTranslatorFactory<Lang, Interpreter extends AnyInterpreter>(parse: Parse<Lang>, interpret: Interpreter): (query: Lang, ...args: unknown[]) => Bound<Interpreter>;
export {};

27
server/node_modules/@ucast/core/dist/types/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,27 @@
import { Condition } from './Condition';
export declare type Named<T, Name extends string = string> = T & {
name: Name;
};
export declare type Parse<T = any> = (query: T, ...args: any[]) => Condition;
export declare type ParsingContext<T extends {}> = T & {
parse: Parse;
};
export interface ParsingInstruction<T = unknown, Context extends {} = {}> {
type: string;
validate?(instruction: Named<this>, value: T): void;
parse?(instruction: Named<this>, value: T, context: ParsingContext<Context>): Condition;
}
export interface CompoundInstruction<T = unknown, C extends {} = {}> extends ParsingInstruction<T, C> {
type: 'compound';
}
export interface DocumentInstruction<T = unknown, C extends {} = {}> extends ParsingInstruction<T, C> {
type: 'document';
}
export interface FieldParsingContext {
field: string;
}
export interface FieldInstruction<T = unknown, C extends FieldParsingContext = FieldParsingContext> extends ParsingInstruction<T, C> {
type: 'field';
}
export declare type NamedInstruction<T extends string = string> = Named<ParsingInstruction, T>;
export declare type Comparable = number | string | Date;

12
server/node_modules/@ucast/core/dist/types/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { Condition, CompoundCondition } from './Condition';
export declare function isCompound(operator: string, condition: Condition): condition is CompoundCondition;
export declare function optimizedCompoundCondition<T extends Condition>(operator: string, conditions: T[]): T | CompoundCondition<T>;
export declare const identity: <T>(x: T) => T;
export declare const object: () => any;
export declare const ignoreValue: IgnoreValue;
export interface IgnoreValue {
readonly ['__@type@__']: 'ignore value';
}
export declare function hasOperators<T>(value: any, instructions: Record<string, unknown>, skipIgnore?: boolean): value is T;
export declare function objectKeysSkipIgnore(anyObject: Record<string, unknown>): string[];
export declare function pushIfNonNullCondition(conditions: Condition[], condition: Condition): void;

2
server/node_modules/@ucast/core/dist/umd/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

88
server/node_modules/@ucast/core/package.json generated vendored Normal file
View File

@@ -0,0 +1,88 @@
{
"name": "@ucast/core",
"version": "1.10.2",
"description": "git@github.com:stalniy/ucast.git",
"sideEffects": false,
"main": "dist/es6c/index.js",
"module": "dist/es5m/index.js",
"es2015": "dist/es6m/index.mjs",
"legacy": "dist/umd/index.js",
"typings": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/es6m/index.mjs",
"require": "./dist/es6c/index.js"
}
},
"scripts": {
"build.types": "tsc",
"prebuild": "rm -rf dist/* && npm run build.types",
"build": "rollup -c ../../rollup.config.js -n ucast.core",
"lint": "eslint --ext .js,.ts src/ spec/",
"test": "mocha -r ts-node/register spec/*",
"coverage": "nyc -n src npm run test && nyc report --reporter=lcov",
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
"release": "semantic-release -e ../../semantic-release.js"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"NOTICE",
"*.d.ts"
],
"repository": {
"type": "git",
"url": "https://github.com/stalniy/ucast.git",
"directory": "packages/core"
},
"keywords": [
"where",
"sql",
"mongo",
"conditions",
"query",
"builder",
"ast"
],
"author": "Sergii Stotskyi <sergiy.stotskiy@freaksidea.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/stalniy/ucast/issues"
},
"homepage": "https://github.com/stalniy/ucast#readme",
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",
"@babel/plugin-transform-typescript": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@rollup/plugin-babel": "^5.0.3",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.7",
"@semantic-release/npm": "^7.0.5",
"@types/chai": "^4.2.11",
"@types/chai-spies": "^1.0.1",
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"babel-register": "^6.26.0",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"eslint": "^7.4.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.22.0",
"mocha": "^8.0.1",
"nyc": "^15.1.0",
"rollup": "^2.15.0",
"rollup-plugin-terser": "^6.1.0",
"semantic-release": "^17.4.7",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
}
}

176
server/node_modules/@ucast/js/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

13
server/node_modules/@ucast/js/NOTICE generated vendored Normal file
View File

@@ -0,0 +1,13 @@
Copyright 2020 Sergii Stotskyi <sergiy.stotskiy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

142
server/node_modules/@ucast/js/README.md generated vendored Normal file
View File

@@ -0,0 +1,142 @@
# UCAST JavaScript
[![@ucast/js NPM version](https://badge.fury.io/js/%40ucast%2Fjs.svg)](https://badge.fury.io/js/%40ucast%2Fjs)
[![](https://img.shields.io/npm/dm/%40ucast%2Fjs.svg)](https://www.npmjs.com/package/%40ucast%2Fjs)
[![UCAST join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-ucast/community)
This package is a part of [ucast] ecosystem. It provides interpreter that can execute conditions AST in JavaScript against any JavaScript object.
[ucast]: https://github.com/stalniy/ucast
## Installation
```sh
npm i @ucast/js
# or
yarn add @ucast/js
# or
pnpm add @ucast/js
```
## Getting Started
### Interpret conditions AST
First of all, you need AST to interpret it. For the sake of an example, we will create it manually:
```js
import { CompoundCondition, FieldCondition } from '@ucast/core';
import { interpret } from '@ucast/js';
// x > 5 && y < 10
const condition = new CompoundCondition('and', [
new FieldCondition('gt', 'x', 5),
new FieldCondition('lt', 'y', 10),
]);
interpret(condition, { x: 2, y: 1 }); // false
interpret(condition, { x: 6, y: 7 }); // true
```
The default `interpret` function:
* supports the next operators, implemented according to [MongoDB query language](https://docs.mongodb.com/manual/reference/operator/query/):
* `eq`, `ne`
* `lt`, `lte`
* `gt`, `gte`
* `within` (the same as `in` but `in` is a reserved word in JavaScript), `nin`
* `all`
* `regex`
* `or`, `nor`, `and`, `not`
* `exists`
* `size`
* `mod`
* `where`,
* `elemMatch`
* supports dot notation to access nested object property values in conditions:
```js
const condition = new FieldCondition('eq', 'address.street', 'some street');
interpret(condition, { address: { street: 'another street' } }); // false
```
* compare values by strict equality, so variables that reference objects are equal only if they are references to the same object:
```js
const address = { street: 'test' };
const condition = new FieldCondition('eq', 'address', address);
interpret(condition, { address }) // true
interpret(condition, { address: { street: 'test' } }) // false, objects are compared by strict equality
```
### Custom interpreter
Sometimes you may want to reduce (or restrict) amount of supported operators (e.g., to utilize tree-shaking and reduce bundle size). To do this you can create a custom interpreter manually:
```js
import { FieldCondition } from '@ucast/core';
import { createJsInterpreter, eq, lt, gt } from '@ucast/js';
// supports only $eq, $lt and $gt operators
const interpret = createJsInterpreter({ eq, lt, gt });
const condition = new FieldCondition('in', 'x', [1, 2]);
interpret(condition, { x: 1 }) // throws Error, `$in` is not supported
```
### Custom object matching
You can also provide a custom `get` or `compare` function. So, you can implement custom logic to get object's property or to compare values. `compare` is used everywhere equality or comparison is required (e.g., in `$in`, `$lt`, `$gt`). This function must return `1` if `a > b`, `-1` if `a < b` and `0` if `a === b`.
Let's enhance our interpreter to support deep object comparison using [lodash]:
```js
import isEqual from 'lodash/isEqual';
import { createJsInterpreter, allInterpreters, compare } from '@ucast/js';
const interpret = createJsInterpreter(allInterpreters, {
compare(a, b) {
if (typeof a === typeof b && typeof a === 'object' && isEqual(a, b)) {
return 0;
}
return compare(a, b);
}
});
const condition = new FieldCondition('eq', 'x', { active: true });
interpret(condition, { x: { active: true } }); // true
```
### Custom Operator Interpreter
Any operator is just a function that accepts 3 parameters and returns boolean result. To see how to implement this function let's create `$type` interpreter that checks object property type using `typeof` operator:
```js
import { createJsInterpreter } from '@ucast/js';
function type(condition, object, { get }) {
return typeof get(object, condition.field) === condition.value;
}
const interpret = createJsInterpreter({ type });
const condition = new FieldCondition('type', 'x', 'number');
interpret(condition, { x: 1 }); // true
```
**Pay attention** that object property is got by using `get` function. Make sure that you always use `get` function in custom operators to get object's property value, otherwise your operator will not support dot notation.
## Want to help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for [contributing]
## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
[contributing]: https://github.com/stalniy/ucast/blob/master/CONTRIBUTING.md

2
server/node_modules/@ucast/js/dist/es5m/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import{ITSELF as r,createInterpreter as n}from"@ucast/core";function t(r,n,t){for(var u=0,e=r.length;u<e;u++)if(0===t(r[u],n))return!0;return!1}function u(r,n){return Array.isArray(r)&&Number.isNaN(Number(n))}function e(r,n,t){if(!u(r,n))return t(r,n);for(var e=[],o=0;o<r.length;o++){var i=t(r[o],n);void 0!==i&&(e=e.concat(i))}return e}function o(r){return function(n,t,u){var e=u.get(t,n.field);return Array.isArray(e)?e.some((function(t){return r(n,t,u)})):r(n,e,u)}}function i(){return(i=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var u in t)Object.prototype.hasOwnProperty.call(t,u)&&(r[u]=t[u])}return r}).apply(this,arguments)}var f=function(r,n){return r[n]};function c(r,n,t){var u=n.lastIndexOf(".");return-1===u?[r,n]:[t(r,n.slice(0,u)),n.slice(u+1)]}function a(n,t,u){if(void 0===u&&(u=f),t===r)return n;if(!n)throw new Error('Unable to get field "'+t+'" out of '+String(n)+".");return function(r,n,t){if(-1===n.indexOf("."))return e(r,n,t);for(var u=n.split("."),o=r,i=0,f=u.length;i<f;i++)if(!(o=e(o,u[i],t))||"object"!=typeof o)return o;return o}(n,t,u)}function v(r){return function(n,t){return a(n,t,r)}}function l(r,n){return r===n?0:r>n?1:-1}function y(r,t){return void 0===t&&(t={}),n(r,i({get:a,compare:l},t))}var b=function(r,n,t){var u=t.interpret;return r.value.some((function(r){return u(r,n)}))},m=function(r,n,t){return!b(r,n,t)},d=function(r,n,t){var u=t.interpret;return r.value.every((function(r){return u(r,n)}))},g=function(r,n,t){return!(0,t.interpret)(r.value[0],n)},p=function(r,n,u){var e=u.compare,o=(0,u.get)(n,r.field);return Array.isArray(o)&&!Array.isArray(r.value)?t(o,r.value,e):0===e(o,r.value)},A=function(r,n,t){return!p(r,n,t)},s=o((function(r,n,t){var u=t.compare(n,r.value);return 0===u||-1===u})),h=o((function(r,n,t){return-1===t.compare(n,r.value)})),j=o((function(r,n,t){return 1===t.compare(n,r.value)})),w=o((function(r,n,t){var u=t.compare(n,r.value);return 0===u||1===u})),_=function(n,t,e){var o=e.get;if(n.field===r)return void 0!==t;var i=c(t,n.field,o),f=i[0],a=i[1],v=function(r){return null==r?Boolean(r)===n.value:r.hasOwnProperty(a)===n.value};return u(f,a)?f.some(v):v(f)},x=o((function(r,n){return"number"==typeof n&&n%r.value[0]===r.value[1]})),O=function(n,t,e){var o=e.get,i=c(t,n.field,o),f=i[0],a=i[1],v=function(r){var t=o(r,a);return Array.isArray(t)&&t.length===n.value};return n.field!==r&&u(f,a)?f.some(v):v(f)},N=o((function(r,n){return"string"==typeof n&&r.value.test(n)})),q=o((function(r,n,u){var e=u.compare;return t(r.value,n,e)})),z=function(r,n,t){return!q(r,n,t)},B=function(r,n,u){var e=u.compare,o=(0,u.get)(n,r.field);return Array.isArray(o)&&r.value.every((function(r){return t(o,r,e)}))},E=function(r,n,t){var u=t.interpret,e=(0,t.get)(n,r.field);return Array.isArray(e)&&e.some((function(n){return u(r.value,n)}))},M=function(r,n){return r.value.call(n)},S=i({},Object.freeze({__proto__:null,or:b,nor:m,and:d,not:g,eq:p,ne:A,lte:s,lt:h,gt:j,gte:w,exists:_,mod:x,size:O,regex:N,within:q,nin:z,all:B,elemMatch:E,where:M}),{in:q}),U=y(S);export{B as all,S as allInterpreters,d as and,l as compare,v as createGetter,y as createJsInterpreter,E as elemMatch,p as eq,_ as exists,a as getObjectField,c as getObjectFieldCursor,j as gt,w as gte,U as interpret,h as lt,s as lte,x as mod,A as ne,z as nin,m as nor,g as not,b as or,N as regex,O as size,M as where,q as within};
//# sourceMappingURL=index.js.map

1
server/node_modules/@ucast/js/dist/es5m/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2
server/node_modules/@ucast/js/dist/es6c/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@ucast/core");function t(r,t,e){for(let n=0,o=r.length;n<o;n++)if(0===e(r[n],t))return!0;return!1}function e(r,t){return Array.isArray(r)&&Number.isNaN(Number(t))}function n(r,t,n){if(!e(r,t))return n(r,t);let o=[];for(let e=0;e<r.length;e++){const s=n(r[e],t);void 0!==s&&(o=o.concat(s))}return o}function o(r){return(t,e,n)=>{const o=n.get(e,t.field);return Array.isArray(o)?o.some(e=>r(t,e,n)):r(t,o,n)}}const s=(r,t)=>r[t];function u(r,t,e){const n=t.lastIndexOf(".");return-1===n?[r,t]:[e(r,t.slice(0,n)),t.slice(n+1)]}function p(t,e,o=s){if(e===r.ITSELF)return t;if(!t)throw new Error(`Unable to get field "${e}" out of ${String(t)}.`);return function(r,t,e){if(-1===t.indexOf("."))return n(r,t,e);const o=t.split(".");let s=r;for(let r=0,t=o.length;r<t;r++)if(s=n(s,o[r],e),!s||"object"!=typeof s)return s;return s}(t,e,o)}function c(r,t){return r===t?0:r>t?1:-1}function i(t,e={}){return r.createInterpreter(t,Object.assign({get:p,compare:c},e))}const x=(r,t,{interpret:e})=>r.value.some(r=>e(r,t)),f=(r,t,e)=>!x(r,t,e),a=(r,t,{interpret:e})=>r.value.every(r=>e(r,t)),l=(r,t,{interpret:e})=>!e(r.value[0],t),g=(r,e,{compare:n,get:o})=>{const s=o(e,r.field);return Array.isArray(s)&&!Array.isArray(r.value)?t(s,r.value,n):0===n(s,r.value)},y=(r,t,e)=>!g(r,t,e),b=o((r,t,e)=>{const n=e.compare(t,r.value);return 0===n||-1===n}),m=o((r,t,e)=>-1===e.compare(t,r.value)),A=o((r,t,e)=>1===e.compare(t,r.value)),d=o((r,t,e)=>{const n=e.compare(t,r.value);return 0===n||1===n}),_=(t,n,{get:o})=>{if(t.field===r.ITSELF)return void 0!==n;const[s,p]=u(n,t.field,o),c=r=>null==r?Boolean(r)===t.value:r.hasOwnProperty(p)===t.value;return e(s,p)?s.some(c):c(s)},j=o((r,t)=>"number"==typeof t&&t%r.value[0]===r.value[1]),v=(t,n,{get:o})=>{const[s,p]=u(n,t.field,o),c=r=>{const e=o(r,p);return Array.isArray(e)&&e.length===t.value};return t.field!==r.ITSELF&&e(s,p)?s.some(c):c(s)},h=o((r,t)=>"string"==typeof t&&r.value.test(t)),w=o((r,e,{compare:n})=>t(r.value,e,n)),O=(r,t,e)=>!w(r,t,e),q=(r,e,{compare:n,get:o})=>{const s=o(e,r.field);return Array.isArray(s)&&r.value.every(r=>t(s,r,n))},M=(r,t,{interpret:e,get:n})=>{const o=n(t,r.field);return Array.isArray(o)&&o.some(t=>e(r.value,t))},N=(r,t)=>r.value.call(t);var $=Object.freeze({__proto__:null,or:x,nor:f,and:a,not:l,eq:g,ne:y,lte:b,lt:m,gt:A,gte:d,exists:_,mod:j,size:v,regex:h,within:w,nin:O,all:q,elemMatch:M,where:N});const z=Object.assign({},$,{in:w}),B=i(z);exports.all=q,exports.allInterpreters=z,exports.and=a,exports.compare=c,exports.createGetter=function(r){return(t,e)=>p(t,e,r)},exports.createJsInterpreter=i,exports.elemMatch=M,exports.eq=g,exports.exists=_,exports.getObjectField=p,exports.getObjectFieldCursor=u,exports.gt=A,exports.gte=d,exports.interpret=B,exports.lt=m,exports.lte=b,exports.mod=j,exports.ne=y,exports.nin=O,exports.nor=f,exports.not=l,exports.or=x,exports.regex=h,exports.size=v,exports.where=N,exports.within=w;
//# sourceMappingURL=index.js.map

1
server/node_modules/@ucast/js/dist/es6c/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2
server/node_modules/@ucast/js/dist/es6m/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import{ITSELF as r,createInterpreter as t}from"@ucast/core";function n(r,t,n){for(let e=0,o=r.length;e<o;e++)if(0===n(r[e],t))return!0;return!1}function e(r,t){return Array.isArray(r)&&Number.isNaN(Number(t))}function o(r,t,n){if(!e(r,t))return n(r,t);let o=[];for(let e=0;e<r.length;e++){const u=n(r[e],t);void 0!==u&&(o=o.concat(u))}return o}function u(r){return(t,n,e)=>{const o=e.get(n,t.field);return Array.isArray(o)?o.some(n=>r(t,n,e)):r(t,o,e)}}const c=(r,t)=>r[t];function i(r,t,n){const e=t.lastIndexOf(".");return-1===e?[r,t]:[n(r,t.slice(0,e)),t.slice(e+1)]}function f(t,n,e=c){if(n===r)return t;if(!t)throw new Error(`Unable to get field "${n}" out of ${String(t)}.`);return function(r,t,n){if(-1===t.indexOf("."))return o(r,t,n);const e=t.split(".");let u=r;for(let r=0,t=e.length;r<t;r++)if(u=o(u,e[r],n),!u||"object"!=typeof u)return u;return u}(t,n,e)}function s(r){return(t,n)=>f(t,n,r)}function a(r,t){return r===t?0:r>t?1:-1}function l(r,n={}){return t(r,Object.assign({get:f,compare:a},n))}const p=(r,t,{interpret:n})=>r.value.some(r=>n(r,t)),g=(r,t,n)=>!p(r,t,n),m=(r,t,{interpret:n})=>r.value.every(r=>n(r,t)),y=(r,t,{interpret:n})=>!n(r.value[0],t),b=(r,t,{compare:e,get:o})=>{const u=o(t,r.field);return Array.isArray(u)&&!Array.isArray(r.value)?n(u,r.value,e):0===e(u,r.value)},A=(r,t,n)=>!b(r,t,n),d=u((r,t,n)=>{const e=n.compare(t,r.value);return 0===e||-1===e}),h=u((r,t,n)=>-1===n.compare(t,r.value)),j=u((r,t,n)=>1===n.compare(t,r.value)),w=u((r,t,n)=>{const e=n.compare(t,r.value);return 0===e||1===e}),_=(t,n,{get:o})=>{if(t.field===r)return void 0!==n;const[u,c]=i(n,t.field,o),f=r=>null==r?Boolean(r)===t.value:r.hasOwnProperty(c)===t.value;return e(u,c)?u.some(f):f(u)},v=u((r,t)=>"number"==typeof t&&t%r.value[0]===r.value[1]),x=(t,n,{get:o})=>{const[u,c]=i(n,t.field,o),f=r=>{const n=o(r,c);return Array.isArray(n)&&n.length===t.value};return t.field!==r&&e(u,c)?u.some(f):f(u)},O=u((r,t)=>"string"==typeof t&&r.value.test(t)),N=u((r,t,{compare:e})=>n(r.value,t,e)),$=(r,t,n)=>!N(r,t,n),q=(r,t,{compare:e,get:o})=>{const u=o(t,r.field);return Array.isArray(u)&&r.value.every(r=>n(u,r,e))},z=(r,t,{interpret:n,get:e})=>{const o=e(t,r.field);return Array.isArray(o)&&o.some(t=>n(r.value,t))},B=(r,t)=>r.value.call(t);var E=Object.freeze({__proto__:null,or:p,nor:g,and:m,not:y,eq:b,ne:A,lte:d,lt:h,gt:j,gte:w,exists:_,mod:v,size:x,regex:O,within:N,nin:$,all:q,elemMatch:z,where:B});const M=Object.assign({},E,{in:N}),S=l(M);export{q as all,M as allInterpreters,m as and,a as compare,s as createGetter,l as createJsInterpreter,z as elemMatch,b as eq,_ as exists,f as getObjectField,i as getObjectFieldCursor,j as gt,w as gte,S as interpret,h as lt,d as lte,v as mod,A as ne,$ as nin,g as nor,y as not,p as or,O as regex,x as size,B as where,N as within};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

23
server/node_modules/@ucast/js/dist/types/defaults.d.ts generated vendored Normal file
View File

@@ -0,0 +1,23 @@
export declare const allInterpreters: {
in: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<unknown[]>, unknown>;
or: import("./types").JsInterpreter<import("@ucast/core").CompoundCondition<import("@ucast/core").Condition<unknown>>, any>;
nor: import("./types").JsInterpreter<import("@ucast/core").CompoundCondition<import("@ucast/core").Condition<unknown>>, any>;
and: import("./types").JsInterpreter<import("@ucast/core").CompoundCondition<import("@ucast/core").Condition<unknown>>, any>;
not: import("./types").JsInterpreter<import("@ucast/core").CompoundCondition<import("@ucast/core").Condition<unknown>>, any>;
eq: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<unknown>, any>;
ne: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<unknown>, any>;
lte: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
lt: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
gt: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
gte: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
exists: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<boolean>, any>;
mod: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<[number, number]>, number | Record<string | number | symbol, unknown>>;
size: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<number>, unknown[] | Record<string | number | symbol, unknown>>;
regex: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<RegExp>, string | Record<string | number | symbol, unknown>>;
within: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<unknown[]>, unknown>;
nin: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<unknown[]>, unknown>;
all: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<unknown[]>, any>;
elemMatch: import("./types").JsInterpreter<import("@ucast/core").FieldCondition<import("@ucast/core").Condition<unknown>>, any>;
where: import("./types").JsInterpreter<import("@ucast/core").DocumentCondition<(this: Record<string | number | symbol, unknown>) => boolean>, Record<string | number | symbol, unknown>>;
};
export declare const interpret: (...args: [import("@ucast/core").Condition<unknown>, any] | [import("@ucast/core").Condition<unknown>, string | number | Date | Record<string | number | symbol, unknown>] | [import("@ucast/core").Condition<unknown>, number | Record<string | number | symbol, unknown>] | [import("@ucast/core").Condition<unknown>, unknown[] | Record<string | number | symbol, unknown>] | [import("@ucast/core").Condition<unknown>, string | Record<string | number | symbol, unknown>] | [import("@ucast/core").Condition<unknown>, unknown] | [import("@ucast/core").Condition<unknown>, Record<string | number | symbol, unknown>]) => boolean;

4
server/node_modules/@ucast/js/dist/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export * from './interpreters';
export * from './interpreter';
export * from './defaults';
export type { JsInterpretationOptions, JsInterpreter } from './types';

View File

@@ -0,0 +1,10 @@
import { ITSELF } from '@ucast/core';
import { GetField } from './utils';
import { JsInterpretationOptions, JsInterpreter } from './types';
declare type Field = string | typeof ITSELF;
export declare function getObjectFieldCursor<T extends {}>(object: T, path: string, get: GetField): readonly [T, string];
export declare function getObjectField(object: unknown, field: Field, get?: GetField): any;
export declare function createGetter<T extends GetField>(get: T): (object: Parameters<T>[0], field: Parameters<T>[1]) => any;
export declare function compare<T>(a: T, b: T): 0 | 1 | -1;
export declare function createJsInterpreter<T extends JsInterpreter<any>, O extends Partial<JsInterpretationOptions>>(operators: Record<string, T>, options?: O): (...args: T extends (a: any, c: any) => any ? [import("@ucast/core").Condition<unknown>] : T extends (a: any, b: any, c: any) => any ? [import("@ucast/core").Condition<unknown>, Parameters<T>[1]] : [import("@ucast/core").Condition<unknown>, Parameters<T>[1], Parameters<T>[2], ...unknown[]]) => ReturnType<T>;
export {};

View File

@@ -0,0 +1,24 @@
import { CompoundCondition as Compound, FieldCondition as Field, DocumentCondition as Document, Condition } from '@ucast/core';
import { JsInterpreter as Interpret } from './types';
import { AnyObject } from './utils';
export declare const or: Interpret<Compound>;
export declare const nor: typeof or;
export declare const and: Interpret<Compound>;
export declare const not: Interpret<Compound>;
export declare const eq: Interpret<Field>;
export declare const ne: typeof eq;
export declare const lte: Interpret<Field<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
export declare const lt: Interpret<Field<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
export declare const gt: Interpret<Field<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
export declare const gte: Interpret<Field<string | number | Date>, string | number | Date | Record<string | number | symbol, unknown>>;
export declare const exists: Interpret<Field<boolean>>;
export declare const mod: Interpret<Field<[number, number]>, number | Record<string | number | symbol, unknown>>;
export declare const size: Interpret<Field<number>, AnyObject | unknown[]>;
export declare const regex: Interpret<Field<RegExp>, string | Record<string | number | symbol, unknown>>;
export declare const within: Interpret<Field<unknown[]>, unknown>;
export declare const nin: typeof within;
export declare const all: Interpret<Field<unknown[]>>;
export declare const elemMatch: Interpret<Field<Condition>>;
declare type WhereFunction = (this: AnyObject) => boolean;
export declare const where: Interpret<Document<WhereFunction>, AnyObject>;
export {};

6
server/node_modules/@ucast/js/dist/types/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import { Condition, ITSELF, InterpretationContext } from '@ucast/core';
export interface JsInterpretationOptions {
get(object: any, field: string | typeof ITSELF): any;
compare<T>(a: T, b: T): 1 | -1 | 0;
}
export declare type JsInterpreter<N extends Condition, Value = any> = (node: N, value: Value, context: InterpretationContext<JsInterpreter<N, Value>> & JsInterpretationOptions) => boolean;

8
server/node_modules/@ucast/js/dist/types/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
import { FieldCondition } from '@ucast/core';
import { JsInterpretationOptions, JsInterpreter } from './types';
export declare type AnyObject = Record<PropertyKey, unknown>;
export declare type GetField = (object: any, field: string) => any;
export declare function includes<T>(items: T[], value: T, compare: JsInterpretationOptions['compare']): boolean;
export declare function isArrayAndNotNumericField<T>(object: T | T[], field: string): object is T[];
export declare function getValueByPath(object: AnyObject, field: string, get: GetField): any;
export declare function testValueOrArray<T, U = T>(test: JsInterpreter<FieldCondition<T>, U>): JsInterpreter<FieldCondition<T>, Record<string | number | symbol, unknown> | U>;

2
server/node_modules/@ucast/js/dist/umd/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@ucast/core")):"function"==typeof define&&define.amd?define(["exports","@ucast/core"],n):n(((r=r||self).ucast=r.ucast||{},r.ucast.js={}),r.ucast.core)}(this,(function(r,n){"use strict";function t(r,n,t){for(var u=0,e=r.length;u<e;u++)if(0===t(r[u],n))return!0;return!1}function u(r,n){return Array.isArray(r)&&Number.isNaN(Number(n))}function e(r,n,t){if(!u(r,n))return t(r,n);for(var e=[],o=0;o<r.length;o++){var i=t(r[o],n);void 0!==i&&(e=e.concat(i))}return e}function o(r){return function(n,t,u){var e=u.get(t,n.field);return Array.isArray(e)?e.some((function(t){return r(n,t,u)})):r(n,e,u)}}function i(){return(i=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var u in t)Object.prototype.hasOwnProperty.call(t,u)&&(r[u]=t[u])}return r}).apply(this,arguments)}var f=function(r,n){return r[n]};function c(r,n,t){var u=n.lastIndexOf(".");return-1===u?[r,n]:[t(r,n.slice(0,u)),n.slice(u+1)]}function a(r,t,u){if(void 0===u&&(u=f),t===n.ITSELF)return r;if(!r)throw new Error('Unable to get field "'+t+'" out of '+String(r)+".");return function(r,n,t){if(-1===n.indexOf("."))return e(r,n,t);for(var u=n.split("."),o=r,i=0,f=u.length;i<f;i++)if(!(o=e(o,u[i],t))||"object"!=typeof o)return o;return o}(r,t,u)}function v(r,n){return r===n?0:r>n?1:-1}function l(r,t){return void 0===t&&(t={}),n.createInterpreter(r,i({get:a,compare:v},t))}var s=function(r,n,t){var u=t.interpret;return r.value.some((function(r){return u(r,n)}))},d=function(r,n,t){return!s(r,n,t)},y=function(r,n,t){var u=t.interpret;return r.value.every((function(r){return u(r,n)}))},p=function(r,n,t){return!(0,t.interpret)(r.value[0],n)},b=function(r,n,u){var e=u.compare,o=(0,u.get)(n,r.field);return Array.isArray(o)&&!Array.isArray(r.value)?t(o,r.value,e):0===e(o,r.value)},g=function(r,n,t){return!b(r,n,t)},m=o((function(r,n,t){var u=t.compare(n,r.value);return 0===u||-1===u})),A=o((function(r,n,t){return-1===t.compare(n,r.value)})),h=o((function(r,n,t){return 1===t.compare(n,r.value)})),j=o((function(r,n,t){var u=t.compare(n,r.value);return 0===u||1===u})),_=function(r,t,e){var o=e.get;if(r.field===n.ITSELF)return void 0!==t;var i=c(t,r.field,o),f=i[0],a=i[1],v=function(n){return null==n?Boolean(n)===r.value:n.hasOwnProperty(a)===r.value};return u(f,a)?f.some(v):v(f)},x=o((function(r,n){return"number"==typeof n&&n%r.value[0]===r.value[1]})),w=function(r,t,e){var o=e.get,i=c(t,r.field,o),f=i[0],a=i[1],v=function(n){var t=o(n,a);return Array.isArray(t)&&t.length===r.value};return r.field!==n.ITSELF&&u(f,a)?f.some(v):v(f)},O=o((function(r,n){return"string"==typeof n&&r.value.test(n)})),q=o((function(r,n,u){var e=u.compare;return t(r.value,n,e)})),M=function(r,n,t){return!q(r,n,t)},N=function(r,n,u){var e=u.compare,o=(0,u.get)(n,r.field);return Array.isArray(o)&&r.value.every((function(r){return t(o,r,e)}))},z=function(r,n,t){var u=t.interpret,e=(0,t.get)(n,r.field);return Array.isArray(e)&&e.some((function(n){return u(r.value,n)}))},B=function(r,n){return r.value.call(n)},E=i({},Object.freeze({__proto__:null,or:s,nor:d,and:y,not:p,eq:b,ne:g,lte:m,lt:A,gt:h,gte:j,exists:_,mod:x,size:w,regex:O,within:q,nin:M,all:N,elemMatch:z,where:B}),{in:q}),S=l(E);r.all=N,r.allInterpreters=E,r.and=y,r.compare=v,r.createGetter=function(r){return function(n,t){return a(n,t,r)}},r.createJsInterpreter=l,r.elemMatch=z,r.eq=b,r.exists=_,r.getObjectField=a,r.getObjectFieldCursor=c,r.gt=h,r.gte=j,r.interpret=S,r.lt=A,r.lte=m,r.mod=x,r.ne=g,r.nin=M,r.nor=d,r.not=p,r.or=s,r.regex=O,r.size=w,r.where=B,r.within=q,Object.defineProperty(r,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map

1
server/node_modules/@ucast/js/dist/umd/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

87
server/node_modules/@ucast/js/package.json generated vendored Normal file
View File

@@ -0,0 +1,87 @@
{
"name": "@ucast/js",
"version": "3.0.4",
"description": "git@github.com:stalniy/ucast.git",
"sideEffects": false,
"main": "dist/es6c/index.js",
"module": "dist/es5m/index.js",
"es2015": "dist/es6m/index.mjs",
"legacy": "dist/umd/index.js",
"typings": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/es6m/index.mjs",
"require": "./dist/es6c/index.js"
}
},
"scripts": {
"build.types": "tsc",
"prebuild": "rm -rf dist/* && npm run build.types",
"build": "rollup -c ../../rollup.config.js -n ucast.js -g @ucast/core:ucast.core",
"lint": "eslint --ext .js,.ts src/ spec/",
"test": "mocha -r ts-node/register spec/*",
"coverage": "nyc -n src npm run test && nyc report --reporter=lcov",
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
"release": "semantic-release -e ../../semantic-release.js"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"NOTICE",
"*.d.ts"
],
"repository": {
"type": "git",
"url": "git+https://github.com/stalniy/ucast.git"
},
"keywords": [
"ast",
"interpreter",
"conditions",
"query",
"builder"
],
"author": "Sergii Stotskyi <sergiy.stotskiy@freaksidea.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/stalniy/ucast/issues"
},
"homepage": "https://github.com/stalniy/ucast#readme",
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",
"@babel/plugin-transform-typescript": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@rollup/plugin-babel": "^5.0.3",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.7",
"@semantic-release/npm": "^7.0.5",
"@types/chai": "^4.2.11",
"@types/chai-spies": "^1.0.1",
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"eslint": "^7.4.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.22.0",
"mocha": "^8.0.1",
"nyc": "^15.1.0",
"rollup": "^2.15.0",
"rollup-plugin-terser": "^6.1.0",
"semantic-release": "^17.4.7",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
},
"dependencies": {
"@ucast/core": "^1.0.0"
}
}

176
server/node_modules/@ucast/mongo/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

13
server/node_modules/@ucast/mongo/NOTICE generated vendored Normal file
View File

@@ -0,0 +1,13 @@
Copyright 2020 Sergii Stotskyi <sergiy.stotskiy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

161
server/node_modules/@ucast/mongo/README.md generated vendored Normal file
View File

@@ -0,0 +1,161 @@
# UCAST Mongo
[![@ucast/mongo NPM version](https://badge.fury.io/js/%40ucast%2Fmongo.svg)](https://badge.fury.io/js/%40ucast%2Fmongo)
[![](https://img.shields.io/npm/dm/%40ucast%2Fmongo.svg)](https://www.npmjs.com/package/%40ucast%2Fmongo)
[![UCAST join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-ucast/community)
This package is a part of [ucast] ecosystem. It provides a parser that can parse [MongoDB query](https://docs.mongodb.com/manual/reference/operator/query/) into conditions AST.
[ucast]: https://github.com/stalniy/ucast
## Installation
```sh
npm i @ucast/mongo
# or
yarn add @ucast/mongo
# or
pnpm add @ucast/mongo
```
## Getting Started
To parse MongoDB query into conditions AST, you need to create a `MongoQueryParser` instance:
```js
import { MongoQueryParser, allParsingInstructions } from '@ucast/mongo';
const parser = new MongoQueryParser(allParsingInstructions);
const ast = parser.parse({
id: 1,
active: true
});
```
To create a parser you need to pass in it parsing instruction. Parsing instruction is an object that defines how a particular operator should be parsed. There are 3 types of `ParsingInstruction`, one for each AST node type:
* `field` represents an instruction for an operator which operates in a field context only. For example, operators `$eq`, `$lt`, `$not`, `$regex`
* `compound` represents an instruction for an operator that aggregates nested queries. For example, operators `$and`, `$or`, `$nor`
* `document` represents an instruction for an operator which operates in a document context only. For example, `$where` or `$jsonSchema`
It's important to understand that it's not required that parsing instruction with type `field` should be parsed into `FieldCondition`. It can be parsed into `CompoundCondition` as it's done for `$not` operator.
### Parsing instruction
A parsing instruction is an object of 3 fields:
```ts
const parsingInstruction = {
type: 'field' | 'document' | 'compound',
validate?(instruction, value) { // optional
// throw exception if something is wrong
},
parse?(instruction, schema, context) { // optional
/*
* custom logic to parse operator,
* returns FieldCondition | DocumentCondition | CompoundCondition
*/
}
}
```
### Optimization logic
Some operators like `$and` and `$or` optimize their parsing logic, so if one of that operators contain a single condition it will be resolved to that condition without additional wrapping. They also recursively collapse conditions from nested operators with the same name. Let's see an example to understand what this means:
```js
const ast = parser.parse({
a: 1
$and: [
{ b: 2 },
{ c: 3 }
]
});
console.dir(ast, { depth: null })
/*
CompoundCondition {
operator: "and",
value: [
FieldCondition { operator: "eq", field: "a", value: 1 },
FieldCondition { operator: "eq", field: "b", value: 2 },
FieldCondition { operator: "eq", field: "c", value: 3 },
]
}
*/
```
This optimization logic helps to speed up interpreter's execution time, instead of going deeply over tree-like structure we have a plain structure of all conditions under a single compound condition.
**Pay attention**: parser removes `$` prefix from operator names
### Custom Operator
In order for an operator to be parsed, it needs to define a parsing instruction. Let's implement a custom instruction which checks that object corresponds to a particular [json schema](https://json-schema.org/).
First of all, we need to understand on which level this operator operates (field or document). In this case, `$jsonSchema` clearly operates on document level. It doesn't contain nested MongoDB queries, so it's not a `compound` instruction. So, we are left only with `document` one.
To test that document corresponds to provided json schema, we use [ajv](https://ajv.js.org/) but it's also possible to use a library of your preference.
```js
// operators/jsonSchema.js
import { DocumentInstruction, DocumentCondition } from '@ucast/core';
import Ajv from 'ajv';
export const $jsonSchema: DocumentInstruction = {
type: 'document',
validate(instruction, value) {
if (!value || typeof value !== 'object') {
throw new Error(`"${instruction.name}" expects to receive an object`)
}
},
parse(instruction, schema) {
const ajv = new Ajv();
return new DocumentCondition(instruction.name, ajv.compile(schema));
}
};
```
In order to use this operator, we need to pass this instruction into `MongoQueryParser` constructor:
```js
import { MongoQueryParser, allParsingInstructions } from '@ucast/core';
import { $jsonSchema } from './operators/jsonSchema';
const parser = new MongoQueryParser({
...allParsingInstructions,
$jsonSchema
});
const ast = parser.parse({
$jsonSchema: {
type: 'object',
properties: {
firstName: { type: 'string' },
lastName: { type: 'string' },
},
additionalProperties: false,
}
});
console.dir(ast, { depth: null });
/*
DocumentCondition { operator: "jsonSchema", value: [Function: validate] }
*/
```
The only thing which is left is to implement a corresponding JavaScript interpreter:
```js
function jsonSchema(condition, object) { // interpreter
return condition.value(object);
}
```
## Want to help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for [contributing]
## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
[contributing]: https://github.com/stalniy/ucast/blob/master/CONTRIBUTING.md

2
server/node_modules/@ucast/mongo/dist/es5m/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import{optimizedCompoundCondition as e,FieldCondition as t,CompoundCondition as r,ITSELF as n,NULL_CONDITION as o,buildAnd as a,ObjectQueryParser as i}from"@ucast/core";export{defaultInstructionParsers as defaultParsers}from"@ucast/core";function f(e,t){if(!Array.isArray(t))throw new Error('"'+e.name+'" expects value to be an array')}function u(e,t){if(f(e,t),!t.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var c=function(e){return function(t,r){if(typeof r!==e)throw new Error('"'+t.name+'" expects value to be a "'+e+'"')}},p={type:"compound",validate:u,parse:function(t,r,n){var o=n.parse,a=r.map((function(e){return o(e)}));return e(t.name,a)}},s=p,l={type:"compound",validate:u},d={type:"field",validate:function(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error('"'+e.name+'" expects to receive either regular expression or object of field operators')},parse:function(e,n,o){var a=n instanceof RegExp?new t("regex",o.field,n):o.parse(n,o);return new r(e.name,[a])}},v={type:"field",validate:function(e,t){if(!t||t.constructor!==Object)throw new Error('"'+e.name+'" expects to receive an object with nested query or field level operators')},parse:function(e,r,o){var a=o.parse,i=o.field,f=(0,o.hasOperators)(r)?a(r,{field:n}):a(r);return new t(e.name,i,f)}},w={type:"field",validate:c("number")},y={type:"field",validate:f},$=y,x=y,h={type:"field",validate:function(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error('"'+e.name+'" expects an array with 2 numeric elements')}},m={type:"field",validate:c("boolean")},g={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error('"'+e.name+'" expects value to be comparable (i.e., string, number or date)')}},b=g,E=b,j=b,O={type:"field"},R=O,_={type:"field",validate:function(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error('"'+e.name+'" expects value to be a regular expression or a string that represents regular expression')},parse:function(e,r,n){var o="string"==typeof r?new RegExp(r,n.query.$options||""):r;return new t(e.name,n.field,o)}},q={type:"field",parse:function(){return o}},A={type:"document",validate:c("function")},N=Object.freeze({__proto__:null,$and:p,$or:s,$nor:l,$not:d,$elemMatch:v,$size:w,$in:y,$nin:$,$all:x,$mod:h,$exists:m,$gte:g,$gt:b,$lt:E,$lte:j,$eq:O,$ne:R,$regex:_,$options:q,$where:A});var P=function(e){var t,r;function n(t){return e.call(this,t,{defaultOperatorName:"$eq",operatorToConditionName:function(e){return e.slice(1)}})||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n.prototype.parse=function(t,r){return r&&r.field?a(this.parseFieldOperators(r.field,t)):e.prototype.parse.call(this,t)},n}(i),z=N;export{x as $all,p as $and,v as $elemMatch,O as $eq,m as $exists,b as $gt,g as $gte,y as $in,E as $lt,j as $lte,h as $mod,R as $ne,$ as $nin,l as $nor,d as $not,q as $options,s as $or,_ as $regex,w as $size,A as $where,P as MongoQueryParser,z as allParsingInstructions};
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

2
server/node_modules/@ucast/mongo/dist/es6c/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ucast/core");function t(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function r(e,r){if(t(e,r),!r.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const o=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},s={type:"compound",validate:r,parse(t,r,{parse:o}){const s=r.map(e=>o(e));return e.optimizedCompoundCondition(t.name,s)}},a=s,n={type:"compound",validate:r},p={type:"field",validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(t,r,o){const s=r instanceof RegExp?new e.FieldCondition("regex",o.field,r):o.parse(r,o);return new e.CompoundCondition(t.name,[s])}},i={type:"field",validate(e,t){if(!t||t.constructor!==Object)throw new Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(t,r,{parse:o,field:s,hasOperators:a}){const n=a(r)?o(r,{field:e.ITSELF}):o(r);return new e.FieldCondition(t.name,s,n)}},l={type:"field",validate:o("number")},c={type:"field",validate:t},x=c,f=c,u={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},d={type:"field",validate:o("boolean")},$={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}},w=$,y=w,v=w,b={type:"field"},g=b,h={type:"field",validate(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,r,o){const s="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new e.FieldCondition(t.name,o.field,s)}},m={type:"field",parse:()=>e.NULL_CONDITION},E={type:"document",validate:o("function")};var j=Object.freeze({__proto__:null,$and:s,$or:a,$nor:n,$not:p,$elemMatch:i,$size:l,$in:c,$nin:x,$all:f,$mod:u,$exists:d,$gte:$,$gt:w,$lt:y,$lte:v,$eq:b,$ne:g,$regex:h,$options:m,$where:E});class O extends e.ObjectQueryParser{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:e=>e.slice(1)})}parse(t,r){return r&&r.field?e.buildAnd(this.parseFieldOperators(r.field,t)):super.parse(t)}}const _=j;Object.defineProperty(exports,"defaultParsers",{enumerable:!0,get:function(){return e.defaultInstructionParsers}}),exports.$all=f,exports.$and=s,exports.$elemMatch=i,exports.$eq=b,exports.$exists=d,exports.$gt=w,exports.$gte=$,exports.$in=c,exports.$lt=y,exports.$lte=v,exports.$mod=u,exports.$ne=g,exports.$nin=x,exports.$nor=n,exports.$not=p,exports.$options=m,exports.$or=a,exports.$regex=h,exports.$size=l,exports.$where=E,exports.MongoQueryParser=O,exports.allParsingInstructions=_;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

2
server/node_modules/@ucast/mongo/dist/es6m/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import{optimizedCompoundCondition as e,FieldCondition as t,CompoundCondition as r,ITSELF as o,NULL_CONDITION as a,ObjectQueryParser as n,buildAnd as i}from"@ucast/core";export{defaultInstructionParsers as defaultParsers}from"@ucast/core";function s(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function p(e,t){if(s(e,t),!t.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const l=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},c={type:"compound",validate:p,parse(t,r,{parse:o}){const a=r.map(e=>o(e));return e(t.name,a)}},f=c,d={type:"compound",validate:p},u={type:"field",validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(e,o,a){const n=o instanceof RegExp?new t("regex",a.field,o):a.parse(o,a);return new r(e.name,[n])}},$={type:"field",validate(e,t){if(!t||t.constructor!==Object)throw new Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(e,r,{parse:a,field:n,hasOperators:i}){const s=i(r)?a(r,{field:o}):a(r);return new t(e.name,n,s)}},w={type:"field",validate:l("number")},y={type:"field",validate:s},x=y,v=y,h={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},m={type:"field",validate:l("boolean")},g={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}},b=g,E=b,j=b,O={type:"field"},R=O,_={type:"field",validate(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(e,r,o){const a="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new t(e.name,o.field,a)}},q={type:"field",parse:()=>a},A={type:"document",validate:l("function")};var N=Object.freeze({__proto__:null,$and:c,$or:f,$nor:d,$not:u,$elemMatch:$,$size:w,$in:y,$nin:x,$all:v,$mod:h,$exists:m,$gte:g,$gt:b,$lt:E,$lte:j,$eq:O,$ne:R,$regex:_,$options:q,$where:A});class P extends n{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:e=>e.slice(1)})}parse(e,t){return t&&t.field?i(this.parseFieldOperators(t.field,e)):super.parse(e)}}const z=N;export{v as $all,c as $and,$ as $elemMatch,O as $eq,m as $exists,b as $gt,g as $gte,y as $in,E as $lt,j as $lte,h as $mod,R as $ne,x as $nin,d as $nor,u as $not,q as $options,f as $or,_ as $regex,w as $size,A as $where,P as MongoQueryParser,z as allParsingInstructions};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
import { Condition, ParsingInstruction, ObjectQueryParser, FieldQueryOperators } from '@ucast/core';
import { MongoQuery } from './types';
export interface ParseOptions {
field: string;
}
export declare class MongoQueryParser extends ObjectQueryParser<MongoQuery<any>> {
constructor(instructions: Record<string, ParsingInstruction>);
parse<Q extends MongoQuery<any>, FQ extends FieldQueryOperators<Q> = FieldQueryOperators<Q>>(query: Q | FQ, options?: ParseOptions): Condition;
}

View File

@@ -0,0 +1,6 @@
import * as instructions from './instructions';
export declare const allParsingInstructions: typeof instructions;
export * from './instructions';
export * from './MongoQueryParser';
export * from './types';
export { defaultInstructionParsers as defaultParsers } from '@ucast/core';

View File

@@ -0,0 +1,29 @@
import { CompoundInstruction, FieldInstruction, DocumentInstruction, Comparable, FieldParsingContext, ObjectQueryFieldParsingContext } from '@ucast/core';
import { MongoQuery } from './types';
export declare const $and: CompoundInstruction<MongoQuery<any>[]>;
export declare const $or: CompoundInstruction<(import("./types").MongoQueryOperators<any> | ({
[x: string]: any;
} & import("./types").MongoQueryTopLevelOperators<any>))[], {}>;
export declare const $nor: CompoundInstruction<MongoQuery<any>[]>;
export declare const $not: FieldInstruction<MongoQuery<any> | RegExp>;
export declare const $elemMatch: FieldInstruction<MongoQuery<any>, ObjectQueryFieldParsingContext>;
export declare const $size: FieldInstruction<number>;
export declare const $in: FieldInstruction<unknown[]>;
export declare const $nin: FieldInstruction<unknown[], FieldParsingContext>;
export declare const $all: FieldInstruction<unknown[], FieldParsingContext>;
export declare const $mod: FieldInstruction<[number, number]>;
export declare const $exists: FieldInstruction<boolean>;
export declare const $gte: FieldInstruction<Comparable>;
export declare const $gt: FieldInstruction<string | number | Date, FieldParsingContext>;
export declare const $lt: FieldInstruction<string | number | Date, FieldParsingContext>;
export declare const $lte: FieldInstruction<string | number | Date, FieldParsingContext>;
export declare const $eq: FieldInstruction;
export declare const $ne: FieldInstruction<unknown, FieldParsingContext>;
export interface RegExpFieldContext extends FieldParsingContext {
query: {
$options?: string;
};
}
export declare const $regex: FieldInstruction<string | RegExp, RegExpFieldContext>;
export declare const $options: FieldInstruction;
export declare const $where: DocumentInstruction<() => boolean>;

43
server/node_modules/@ucast/mongo/dist/types/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,43 @@
import { Comparable } from '@ucast/core';
export interface MongoQueryTopLevelOperators<Value> {
$and?: MongoQuery<Value>[];
$or?: MongoQuery<Value>[];
$nor?: MongoQuery<Value>[];
$where?: (this: Value) => boolean;
}
export interface MongoQueryFieldOperators<Value = any> {
$eq?: Value;
$ne?: Value;
$lt?: Extract<Comparable, Value>;
$lte?: Extract<Comparable, Value>;
$gt?: Extract<Comparable, Value>;
$gte?: Extract<Comparable, Value>;
$in?: Value[];
$nin?: Value[];
$all?: Value[];
/** checks by array length */
$size?: number;
$regex?: RegExp | string;
$options?: 'i' | 'g' | 'm' | 'u';
/** checks the shape of array item */
$elemMatch?: MongoQuery<Value>;
$exists?: boolean;
$not?: Omit<MongoQueryFieldOperators<Value>, '$not'>;
}
export declare type MongoQueryOperators<Value = any> = MongoQueryFieldOperators<Value> & MongoQueryTopLevelOperators<Value>;
export interface CustomOperators {
toplevel?: {};
field?: {};
}
declare type ItemOf<T, AdditionalArrayTypes = never> = T extends any[] ? T[number] | AdditionalArrayTypes : T;
declare type OperatorValues<T> = null | T | Partial<ItemOf<T, []>> | MongoQueryFieldOperators<ItemOf<T>>;
declare type Query<T extends Record<PropertyKey, any>, FieldOperators> = {
[K in keyof T]?: OperatorValues<T[K]> | FieldOperators;
};
export interface DefaultOperators<T> {
toplevel: MongoQueryTopLevelOperators<T>;
field: MongoQueryOperators<T>;
}
export declare type BuildMongoQuery<T = Record<PropertyKey, any>, O extends CustomOperators = DefaultOperators<T>> = T extends Record<PropertyKey, any> ? Query<T, O['field']> & O['toplevel'] : O['field'] & O['toplevel'];
export declare type MongoQuery<T = Record<PropertyKey, any>, O extends CustomOperators = CustomOperators> = BuildMongoQuery<T, DefaultOperators<T> & O>;
export {};

View File

@@ -0,0 +1,2 @@
import { MongoQueryOperators } from './types';
export declare function hasOperators(value: any): value is MongoQueryOperators;

2
server/node_modules/@ucast/mongo/dist/umd/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ucast/core")):"function"==typeof define&&define.amd?define(["exports","@ucast/core"],t):t(((e=e||self).ucast=e.ucast||{},e.ucast.mongo={}),e.ucast.core)}(this,(function(e,t){"use strict";function r(e,t){if(!Array.isArray(t))throw new Error('"'+e.name+'" expects value to be an array')}function n(e,t){if(r(e,t),!t.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var o=function(e){return function(t,r){if(typeof r!==e)throw new Error('"'+t.name+'" expects value to be a "'+e+'"')}},i={type:"compound",validate:n,parse:function(e,r,n){var o=n.parse,i=r.map((function(e){return o(e)}));return t.optimizedCompoundCondition(e.name,i)}},a=i,f={type:"compound",validate:n},u={type:"field",validate:function(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error('"'+e.name+'" expects to receive either regular expression or object of field operators')},parse:function(e,r,n){var o=r instanceof RegExp?new t.FieldCondition("regex",n.field,r):n.parse(r,n);return new t.CompoundCondition(e.name,[o])}},c={type:"field",validate:function(e,t){if(!t||t.constructor!==Object)throw new Error('"'+e.name+'" expects to receive an object with nested query or field level operators')},parse:function(e,r,n){var o=n.parse,i=n.field,a=(0,n.hasOperators)(r)?o(r,{field:t.ITSELF}):o(r);return new t.FieldCondition(e.name,i,a)}},s={type:"field",validate:o("number")},p={type:"field",validate:r},l=p,d=p,v={type:"field",validate:function(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error('"'+e.name+'" expects an array with 2 numeric elements')}},y={type:"field",validate:o("boolean")},w={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error('"'+e.name+'" expects value to be comparable (i.e., string, number or date)')}},x=w,$=x,h=x,b={type:"field"},g=b,m={type:"field",validate:function(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error('"'+e.name+'" expects value to be a regular expression or a string that represents regular expression')},parse:function(e,r,n){var o="string"==typeof r?new RegExp(r,n.query.$options||""):r;return new t.FieldCondition(e.name,n.field,o)}},E={type:"field",parse:function(){return t.NULL_CONDITION}},j={type:"document",validate:o("function")},O=Object.freeze({__proto__:null,$and:i,$or:a,$nor:f,$not:u,$elemMatch:c,$size:s,$in:p,$nin:l,$all:d,$mod:v,$exists:y,$gte:w,$gt:x,$lt:$,$lte:h,$eq:b,$ne:g,$regex:m,$options:E,$where:j});var _=function(e){var r,n;function o(t){return e.call(this,t,{defaultOperatorName:"$eq",operatorToConditionName:function(e){return e.slice(1)}})||this}return n=e,(r=o).prototype=Object.create(n.prototype),r.prototype.constructor=r,r.__proto__=n,o.prototype.parse=function(r,n){return n&&n.field?t.buildAnd(this.parseFieldOperators(n.field,r)):e.prototype.parse.call(this,r)},o}(t.ObjectQueryParser),q=O;Object.defineProperty(e,"defaultParsers",{enumerable:!0,get:function(){return t.defaultInstructionParsers}}),e.$all=d,e.$and=i,e.$elemMatch=c,e.$eq=b,e.$exists=y,e.$gt=x,e.$gte=w,e.$in=p,e.$lt=$,e.$lte=h,e.$mod=v,e.$ne=g,e.$nin=l,e.$nor=f,e.$not=u,e.$options=E,e.$or=a,e.$regex=m,e.$size=s,e.$where=j,e.MongoQueryParser=_,e.allParsingInstructions=q,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

87
server/node_modules/@ucast/mongo/package.json generated vendored Normal file
View File

@@ -0,0 +1,87 @@
{
"name": "@ucast/mongo",
"version": "2.4.3",
"description": "git@github.com:stalniy/ucast.git",
"sideEffects": false,
"main": "dist/es6c/index.js",
"module": "dist/es5m/index.js",
"es2015": "dist/es6m/index.mjs",
"legacy": "dist/umd/index.js",
"typings": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/es6m/index.mjs",
"require": "./dist/es6c/index.js"
}
},
"scripts": {
"build.types": "tsc",
"prebuild": "rm -rf dist/* && npm run build.types",
"build": "rollup -c ../../rollup.config.js -n ucast.mongo -g @ucast/core:ucast.core",
"lint": "eslint --ext .js,.ts src/ spec/",
"test": "mocha -r ts-node/register spec/*",
"coverage": "nyc -n src npm run test && nyc report --reporter=lcov",
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
"release": "semantic-release -e ../../semantic-release.js"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"NOTICE",
"*.d.ts"
],
"repository": {
"type": "git",
"url": "git+https://github.com/stalniy/ucast.git"
},
"keywords": [
"mongo",
"conditions",
"query",
"builder",
"ast"
],
"author": "Sergii Stotskyi <sergiy.stotskiy@freaksidea.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/stalniy/ucast/issues"
},
"homepage": "https://github.com/stalniy/ucast#readme",
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.10.4",
"@babel/plugin-transform-typescript": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@rollup/plugin-babel": "^5.0.3",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.7",
"@semantic-release/npm": "^7.0.5",
"@types/chai": "^4.2.11",
"@types/chai-spies": "^1.0.1",
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"eslint": "^7.4.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.22.0",
"mocha": "^8.0.1",
"nyc": "^15.1.0",
"rollup": "^2.15.0",
"rollup-plugin-terser": "^6.1.0",
"semantic-release": "^17.4.7",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
},
"dependencies": {
"@ucast/core": "^1.4.1"
}
}

176
server/node_modules/@ucast/mongo2js/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

13
server/node_modules/@ucast/mongo2js/NOTICE generated vendored Normal file
View File

@@ -0,0 +1,13 @@
Copyright 2020 Sergii Stotskyi <sergiy.stotskiy@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

187
server/node_modules/@ucast/mongo2js/README.md generated vendored Normal file
View File

@@ -0,0 +1,187 @@
# UCAST Mongo Query to JavaScript Translator
[![@ucast/mongo NPM version](https://badge.fury.io/js/%40ucast%2Fmongo2js.svg)](https://badge.fury.io/js/%40ucast%2Fmongo2js)
[![](https://img.shields.io/npm/dm/%40ucast%2Fmongo2js.svg)](https://www.npmjs.com/package/%40ucast%2Fmongo2js)
[![UCAST join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/stalniy-ucast/community)
This package is a part of [ucast] ecosystem. It combines [@ucast/mongo] and [@ucast/js] into a package that allows to evaluate [MongoDB query](https://docs.mongodb.com/manual/reference/operator/query/) conditions in JavaScript runtime.
[ucast]: https://github.com/stalniy/ucast
[@ucast/mongo]: https://github.com/stalniy/ucast/tree/master/packages/mongo
[@ucast/js]: https://github.com/stalniy/ucast/tree/master/packages/js
## Installation
```sh
npm i @ucast/mongo2js
# or
yarn add @ucast/mongo2js
# or
pnpm add @ucast/mongo2js
```
## Getting Started
To check that POJO can be matched by Mongo Query:
```js
import { guard } from '@ucast/mongo2js';
const test = guard({
lastName: 'Doe',
age: { $gt: 18 }
});
console.log(test({
firstName: 'John',
lastName: 'Doe',
age: 19
})); // true
```
You can also get access to parsed Mongo Query AST:
```js
console.log(test.ast); /*
{
operator: 'and',
value: [
{ operator: 'eq', field: 'lastName', value: 'Doe' },
{ operator: 'gt', field: 'age', value: 18 }
]
}
*/
```
### Testing primitives
For cases, when you need to test primitive elements, you can use `squire` function:
```js
import { squire } from '@ucast/mongo2js';
const test = squire({
$lt: 10,
$gt: 18
});
test(11) // true
test(9) // false
```
### Custom Operator
In order to implement a custom operator, you need to create a [custom parsing instruction for `MongoQueryParser`](https://github.com/stalniy/ucast/tree/master/packages/mongo#custom-operator) and [custom `JsInterpreter`](https://github.com/stalniy/ucast/tree/master/packages/js#custom-operator-interpreter) to interpret this operator in JavaScript runtime.
This package re-exports all symbols from `@ucast/mongo` and `@ucast/js`, so you don't need to install them separately. For example, to add support for [json-schema](https://json-schema.org/) operator:
```ts
import {
createFactory,
DocumentCondition,
ParsingInstruction,
JsInterpreter,
} from '@ucast/mongo2js';
import Ajv from 'ajv';
type JSONSchema = object;
const ajv = new Ajv();
const $jsonSchema: ParsingInstruction<JSONSchema> = {
type: 'document',
validate(instruction, value) {
if (!value || typeof value !== 'object') {
throw new Error(`"${instruction.name}" expects to receive an object`)
}
},
parse(instruction, schema) {
return new DocumentCondition(instruction.name, ajv.compile(schema));
}
};
const jsonSchema: JsInterpreter<DocumentCondition<Ajv.ValidateFunction>> = (
condition,
object
) => condition.value(object) as boolean;
const customGuard = createFactory({
$jsonSchema,
}, {
jsonSchema
});
const test = customGuard({
$jsonSchema: {
type: 'object',
properties: {
firstName: { type: 'string' },
lastName: { type: 'string' },
},
required: ['firstName', 'lastName'],
}
});
console.log(test({ firstName: 'John' })); // false, `lastName` is not defined
```
To create a custom operator which tests primitives (as `squire` does), use the
`forPrimitives` option:
```ts
const customSquire = createFactory({
$custom: {
type: 'field',
}
}, {
custom: (condition, value) => value === (condition.value ? 'on' : 'off')
}, {
forPrimitives: true
});
const test = customGuard({ $custom: true });
console.log(test('on')) // true
```
## TypeScript support
This package is written in TypeScript and supports type inference for MongoQuery:
```ts
import { guard } from '@ucast/mongo2js';
interface Person {
firstName: string
lastName: string
age: number
}
const test = guard<Person>({ lastName: 'Doe' });
```
You can also use dot notation to set conditions on deeply nested fields:
```ts
import { guard } from '@ucast/mongo2js';
interface Person {
firstName: string
lastName: string
age: number
address: {
city: string
country: string
}
}
type ExtendedPerson = Person & {
'address.city': Person['address']['city']
}
const test = guard<ExtendedPerson>({ lastName: 'Doe' });
```
## Want to help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on guidelines for [contributing]
## License
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
[contributing]: https://github.com/stalniy/ucast/blob/master/CONTRIBUTING.md

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

89
server/node_modules/@ucast/mongo2js/package.json generated vendored Normal file
View File

@@ -0,0 +1,89 @@
{
"name": "@ucast/mongo2js",
"version": "1.4.0",
"description": "git@github.com:stalniy/ucast.git",
"sideEffects": false,
"main": "dist/es6c/index.js",
"module": "dist/es5m/index.js",
"es2015": "dist/es6m/index.mjs",
"legacy": "dist/umd/index.js",
"typings": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/es6m/index.mjs",
"require": "./dist/es6c/index.js"
}
},
"scripts": {
"build.types": "tsc",
"prebuild": "rm -rf dist/* && npm run build.types",
"build": "rollup -c ../../rollup.config.js -n ucast.mongo2js -g @ucast/core:ucast.core,@ucast/js:ucast.js,@ucast/mongo:ucast.mongo",
"lint": "eslint --ext .js,.ts src/",
"test": "mocha -r ts-node/register spec/*",
"coverage": "nyc -n src npm run test && nyc report --reporter=lcov",
"prerelease": "npm run lint && npm test && NODE_ENV=production npm run build",
"release": "semantic-release -e ../../semantic-release.js"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"NOTICE",
"*.d.ts"
],
"repository": {
"type": "git",
"url": "git+https://github.com/stalniy/ucast.git"
},
"keywords": [
"mongo",
"conditions",
"query",
"builder",
"ast"
],
"author": "Sergii Stotskyi <sergiy.stotskiy@gmail.com>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/stalniy/ucast/issues"
},
"homepage": "https://github.com/stalniy/ucast/tree/master/packages/mongo2js#readme",
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-transform-typescript": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.1.1",
"@semantic-release/npm": "^7.0.6",
"@types/chai": "^4.2.14",
"@types/chai-spies": "^1.0.2",
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
"eslint": "^7.12.1",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.22.1",
"mocha": "^8.2.0",
"nyc": "^15.1.0",
"rollup": "^2.33.1",
"rollup-plugin-terser": "^6.1.0",
"semantic-release": "^17.4.7",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
},
"dependencies": {
"@ucast/core": "^1.6.1",
"@ucast/js": "^3.0.0",
"@ucast/mongo": "^2.4.0"
}
}