2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import AndExp from "../../src/services/search/expressions/and.js";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import AttributeExistsExp from "../../src/services/search/expressions/attribute_exists.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-13 23:18:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import type Expression from "../../src/services/search/expressions/expression.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import LabelComparisonExp from "../../src/services/search/expressions/label_comparison.js";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import NotExp from "../../src/services/search/expressions/not.js";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import NoteContentFulltextExp from "../../src/services/search/expressions/note_content_fulltext.js";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import NoteFlatTextExp from "../../src/services/search/expressions/note_flat_text.js";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import OrExp from "../../src/services/search/expressions/or.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 20:10:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import OrderByAndLimitExp from "../../src/services/search/expressions/order_by_and_limit.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import PropertyComparisonExp from "../../src/services/search/expressions/property_comparison.js";
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-18 21:35:17 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import SearchContext from "../../src/services/search/search_context.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { default as parseInternal, type ParseOpts } from "../../src/services/search/services/parse.js";
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								describe("Parser", () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("fulltext parser without content", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: tokens(["hello", "hi"]),
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expectExpression(rootExp.subExpressions[0], PropertyComparisonExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const orExp = expectExpression(rootExp.subExpressions[2], OrExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const flatTextExp = expectExpression(orExp.subExpressions[0], NoteFlatTextExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(flatTextExp.tokens).toEqual(["hello", "hi"]);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("fulltext parser with content", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: tokens(["hello", "hi"]),
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const orExp = expectExpression(rootExp.subExpressions[2], OrExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const firstSub = expectExpression(orExp.subExpressions[0], NoteFlatTextExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.tokens).toEqual(["hello", "hi"]);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const secondSub = expectExpression(orExp.subExpressions[1], NoteContentFulltextExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(secondSub.tokens).toEqual(["hello", "hi"]);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("simple label comparison", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#mylabel", "=", "text"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const labelComparisonExp = expectExpression(rootExp.subExpressions[2], LabelComparisonExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(labelComparisonExp.attributeType).toEqual("label");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(labelComparisonExp.attributeName).toEqual("mylabel");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(labelComparisonExp.comparator).toBeTruthy();
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("simple attribute negation", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#!mylabel"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        let notExp = expectExpression(rootExp.subExpressions[2], NotExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let attributeExistsExp = expectExpression(notExp.subExpression, AttributeExistsExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(attributeExistsExp.attributeType).toEqual("label");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(attributeExistsExp.attributeName).toEqual("mylabel");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["~!myrelation"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        notExp = expectExpression(rootExp.subExpressions[2], NotExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        attributeExistsExp = expectExpression(notExp.subExpression, AttributeExistsExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(attributeExistsExp.attributeType).toEqual("relation");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(attributeExistsExp.attributeName).toEqual("myrelation");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("simple label AND", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "=", "text", "and", "#second", "=", "text"]),
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const andExp = expectExpression(rootExp.subExpressions[2], AndExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const [firstSub, secondSub] = expectSubexpressions(andExp, LabelComparisonExp, LabelComparisonExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.attributeName).toEqual("first");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(secondSub.attributeName).toEqual("second");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("simple label AND without explicit AND", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "=", "text", "#second", "=", "text"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const andExp = expectExpression(rootExp.subExpressions[2], AndExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const [firstSub, secondSub] = expectSubexpressions(andExp, LabelComparisonExp, LabelComparisonExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.attributeName).toEqual("first");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(secondSub.attributeName).toEqual("second");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("simple label OR", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "=", "text", "or", "#second", "=", "text"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const orExp = expectExpression(rootExp.subExpressions[2], OrExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const [firstSub, secondSub] = expectSubexpressions(orExp, LabelComparisonExp, LabelComparisonExp);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.attributeName).toEqual("first");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(secondSub.attributeName).toEqual("second");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("fulltext and simple label", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: tokens(["hello"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#mylabel", "=", "text"]),
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const [firstSub, _, thirdSub, fourth] = expectSubexpressions(rootExp, PropertyComparisonExp, undefined, OrExp, LabelComparisonExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.propertyName).toEqual("isArchived");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const noteFlatTextExp = expectExpression(thirdSub.subExpressions[0], NoteFlatTextExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(noteFlatTextExp.tokens).toEqual(["hello"]);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(fourth.attributeName).toEqual("mylabel");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("label sub-expression", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "=", "text", "or", ["#second", "=", "text", "and", "#third", "=", "text"]]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const orExp = expectExpression(rootExp.subExpressions[2], OrExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const [firstSub, secondSub] = expectSubexpressions(orExp, LabelComparisonExp, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.attributeName).toEqual("first");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const [firstSubSub, secondSubSub] = expectSubexpressions(secondSub, LabelComparisonExp, LabelComparisonExp);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSubSub.attributeName).toEqual("second");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(secondSubSub.attributeName).toEqual("third");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("label sub-expression without explicit operator", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", ["#second", "or", "#third"], "#fourth"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const andExp = expectExpression(rootExp.subExpressions[2], AndExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const [firstSub, secondSub, thirdSub] = expectSubexpressions(andExp, AttributeExistsExp, OrExp, AttributeExistsExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSub.attributeName).toEqual("first");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const [firstSubSub, secondSubSub] = expectSubexpressions(secondSub, AttributeExistsExp, AttributeExistsExp);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(firstSubSub.attributeName).toEqual("second");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(secondSubSub.attributeName).toEqual("third");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(thirdSub.attributeName).toEqual("fourth");
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 20:10:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("parses limit without order by", () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: tokens(["hello", "hi"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext({ limit: 2 })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }, OrderByAndLimitExp);
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 20:10:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(rootExp.limit).toBe(2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(rootExp.subExpression).toBeInstanceOf(AndExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								describe("Invalid expressions", () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("incomplete comparison", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const searchContext = new SearchContext();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        parseInternal({
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "="]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(searchContext.error).toEqual('Misplaced or incomplete expression "="');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("comparison between labels is impossible", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let searchContext = new SearchContext();
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        searchContext.originalQuery = "#first = #second";
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        parseInternal({
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "=", "#second"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(searchContext.error).toEqual(`Error near token "#second" in "#first = #second", it's possible to compare with constant only.`);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        searchContext = new SearchContext();
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        searchContext.originalQuery = "#first = note.relations.second";
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        parseInternal({
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["#first", "=", "note", ".", "relations", "second"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(searchContext.error).toEqual(`Error near token "note" in "#first = note.relations.second", it's possible to compare with constant only.`);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootExp = parse({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: [
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                { token: "#first", inQuotes: false },
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                { token: "=", inQuotes: false },
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                { token: "#second", inQuotes: true }
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            searchContext: new SearchContext()
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }, AndExp);
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        assertIsArchived(rootExp.subExpressions[0]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const labelComparisonExp = expectExpression(rootExp.subExpressions[2], LabelComparisonExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(labelComparisonExp.attributeType).toEqual("label");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(labelComparisonExp.attributeName).toEqual("first");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(labelComparisonExp.comparator).toBeTruthy();
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it("searching by relation without note property", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const searchContext = new SearchContext();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        parseInternal({
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fulltextTokens: [],
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            expressionTokens: tokens(["~first", "=", "text", "-", "abc"]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            searchContext
							 | 
						
					
						
							
								
									
										
										
										
											2024-05-08 23:59:11 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(searchContext.error).toEqual('Relation can be compared only with property, e.g. ~relation.title=hello in ""');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							
								
									
										
										
										
											2025-01-10 21:20:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								type ClassType<T extends Expression> = new (...args: any[]) => T;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function tokens(toks: (string | string[])[], cur = 0): Array<any> {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return toks.map((arg) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (Array.isArray(arg)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return tokens(arg, cur);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            cur += arg.length;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                token: arg,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                inQuotes: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                startIndex: cur - arg.length,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                endIndex: cur - 1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function assertIsArchived(_exp: Expression) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const exp = expectExpression(_exp, PropertyComparisonExp);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    expect(exp.propertyName).toEqual("isArchived");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    expect(exp.operator).toEqual("=");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    expect(exp.comparedValue).toEqual("false");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Parses the corresponding {@link Expression} from plain text, while also expecting the resulting expression to be of the given type.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param opts the options for parsing.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param type the expected type of the expression.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @returns the expression typecasted to the expected type.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function parse<T extends Expression>(opts: ParseOpts, type: ClassType<T>) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return expectExpression(parseInternal(opts), type);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Expects the given {@link Expression} to be of the given type.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param exp an instance of an {@link Expression}.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param type a type class such as {@link AndExp}, {@link OrExp}, etc.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @returns the same expression typecasted to the expected type.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function expectExpression<T extends Expression>(exp: Expression, type: ClassType<T>) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    expect(exp).toBeInstanceOf(type);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return exp as T;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * For an {@link AndExp}, it goes through all its subexpressions (up to fourth) and checks their type and returns them as a typecasted array.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Each subexpression can have their own type.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param exp the expression containing one or more subexpressions.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param firstType the type of the first subexpression.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param secondType the type of the second subexpression.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param thirdType the type of the third subexpression.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param fourthType the type of the fourth subexpression.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @returns an array of all the subexpressions (in order) typecasted to their expected type.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function expectSubexpressions<FirstT extends Expression,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                              SecondT extends Expression,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                              ThirdT extends Expression,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                              FourthT extends Expression>(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                exp: AndExp,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                firstType: ClassType<FirstT>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                secondType?: ClassType<SecondT>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                thirdType?: ClassType<ThirdT>,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                fourthType?: ClassType<FourthT>): [ FirstT, SecondT, ThirdT, FourthT ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    expectExpression(exp.subExpressions[0], firstType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (secondType) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expectExpression(exp.subExpressions[1], secondType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (thirdType) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expectExpression(exp.subExpressions[2], thirdType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (fourthType) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expectExpression(exp.subExpressions[3], fourthType);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        exp.subExpressions[0] as FirstT,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        exp.subExpressions[1] as SecondT,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        exp.subExpressions[2] as ThirdT,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        exp.subExpressions[3] as FourthT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |