@routier/core 0.0.1-alpha.1 → 0.0.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assertions/index.d.ts +5 -0
- package/dist/assertions/index.js +131 -0
- package/dist/assertions/index.js.map +1 -0
- package/dist/codegen/SlotPath.d.ts +7 -0
- package/dist/codegen/blocks.d.ts +130 -0
- package/dist/codegen/handlers/CloneHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/CompareHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/DeserializeHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/EnableChangeTrackingHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/EnrichmentHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/FreezeHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/HashHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/HashTypeHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/IdSelectorHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/MergeHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/PrepareHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/SerializeHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/StripHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/clone/CloneObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/clone/CloneValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/compare/CompareObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/compare/CompareValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/deserialize/DeserializeComputedValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/deserialize/DeserializeDateHandler.d.ts +9 -0
- package/dist/codegen/handlers/deserialize/DeserializeFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/deserialize/DeserializeObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/deserialize/DeserializeValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/enableChangeTracking/EnableChangeTrackingObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/enableChangeTracking/EnableChangeTrackingPrimitiveValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentComputedValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentDefaultFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentDefaultValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentNullableObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentObjectIdentityHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentPrimitiveHandler.d.ts +6 -0
- package/dist/codegen/handlers/enrichment/EnrichmentPrimitiveIdentityHandler.d.ts +6 -0
- package/dist/codegen/handlers/freeze/FreezeObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/freeze/FreezePrimitiveValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/hash/HashComputedValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/hash/HashDateHandler.d.ts +6 -0
- package/dist/codegen/handlers/hash/HashFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/hash/HashIdentityHandler.d.ts +6 -0
- package/dist/codegen/handlers/hash/HashKeyHandler.d.ts +6 -0
- package/dist/codegen/handlers/hash/HashValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/hashType/HashTypeValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/idSelector/IdSelectorValueHandler.d.ts +6 -0
- package/{src/codegen/handlers/index.ts → dist/codegen/handlers/index.d.ts} +1 -1
- package/dist/codegen/handlers/merge/MergeComputedValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/merge/MergeDefaultFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/merge/MergeDefaultValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/merge/MergeFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/merge/MergePrimitiveHandler.d.ts +6 -0
- package/dist/codegen/handlers/prepare/PrepareComputedValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/prepare/PrepareFunctionHandler.d.ts +6 -0
- package/dist/codegen/handlers/prepare/PrepareIdentityHandler.d.ts +6 -0
- package/dist/codegen/handlers/prepare/PrepareKeyHandler.d.ts +6 -0
- package/dist/codegen/handlers/prepare/PrepareObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/prepare/PrepareValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/serialize/SerializeDateHandler.d.ts +9 -0
- package/dist/codegen/handlers/serialize/SerializeObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/serialize/SerializeValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/strip/StripIdentityHandler.d.ts +6 -0
- package/dist/codegen/handlers/strip/StripKeyHandler.d.ts +6 -0
- package/dist/codegen/handlers/strip/StripObjectHandler.d.ts +6 -0
- package/dist/codegen/handlers/strip/StripValueHandler.d.ts +6 -0
- package/dist/codegen/handlers/types.d.ts +18 -0
- package/{src/codegen/index.ts → dist/codegen/index.d.ts} +1 -1
- package/dist/codegen/types.d.ts +9 -0
- package/dist/codegen/utils.d.ts +22 -0
- package/dist/collections/Changes.d.ts +51 -0
- package/dist/collections/Changes.test.d.ts +1 -0
- package/dist/collections/IdSet.d.ts +7 -0
- package/dist/collections/MemoryDataCollection.d.ts +22 -0
- package/dist/collections/MemoryDataCollection.test.d.ts +1 -0
- package/dist/collections/SchemaCollection.d.ts +8 -0
- package/dist/collections/TagCollection.d.ts +15 -0
- package/dist/collections/TagCollection.test.d.ts +1 -0
- package/{src/collections/index.ts → dist/collections/index.d.ts} +1 -1
- package/dist/collections/index.js +659 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/errors/SchemaError.d.ts +3 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +90 -0
- package/dist/errors/index.js.map +1 -0
- package/{src/expressions/index.ts → dist/expressions/index.d.ts} +1 -1
- package/{src/expressions/parser.ts → dist/expressions/index.js} +387 -205
- package/dist/expressions/index.js.map +1 -0
- package/dist/expressions/parser.d.ts +4 -0
- package/dist/expressions/parser.test.d.ts +1 -0
- package/{src/expressions/types.ts → dist/expressions/types.d.ts} +42 -99
- package/dist/expressions/utils.d.ts +10 -0
- package/dist/expressions/utils.test.d.ts +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -1
- package/dist/index.js +8434 -0
- package/dist/index.js.map +1 -0
- package/dist/performance/index.d.ts +5 -0
- package/dist/performance/index.js +65 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/pipeline/SyncronousQueue.d.ts +7 -0
- package/dist/pipeline/SyncronousQueue.test.d.ts +1 -0
- package/dist/pipeline/TrampolinePipeline.d.ts +36 -0
- package/dist/pipeline/TrampolinePipeline.test.d.ts +1 -0
- package/dist/pipeline/index.d.ts +2 -0
- package/{src/pipeline/TrampolinePipeline.ts → dist/pipeline/index.js} +297 -140
- package/dist/pipeline/index.js.map +1 -0
- package/dist/plugins/EphemeralDataPlugin.d.ts +13 -0
- package/dist/plugins/capabilities/DbPluginCapability.d.ts +23 -0
- package/{src/plugins/capabilities/index.ts → dist/plugins/capabilities/index.d.ts} +1 -1
- package/dist/plugins/capabilities/logging/DbPluginLoggingCapability.d.ts +28 -0
- package/dist/plugins/capabilities/logging/index.d.ts +1 -0
- package/{src/plugins/index.ts → dist/plugins/index.d.ts} +1 -1
- package/dist/plugins/index.js +2328 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/query/Query.d.ts +13 -0
- package/dist/plugins/query/QueryOptionsCollection.d.ts +27 -0
- package/dist/plugins/query/QueryOptionsCollection.test.d.ts +1 -0
- package/{src/plugins/query/index.ts → dist/plugins/query/index.d.ts} +1 -1
- package/{src/plugins/query/types.ts → dist/plugins/query/types.d.ts} +29 -20
- package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +21 -0
- package/dist/plugins/replication/ReplicationDbPlugin.d.ts +21 -0
- package/{src/plugins/replication/index.ts → dist/plugins/replication/index.d.ts} +1 -1
- package/{src/plugins/replication/types.ts → dist/plugins/replication/types.d.ts} +1 -2
- package/dist/plugins/translators/DataTranslator.d.ts +18 -0
- package/dist/plugins/translators/JsonTranslator.d.ts +17 -0
- package/dist/plugins/translators/JsonTranslator.test.d.ts +1 -0
- package/dist/plugins/translators/SqlTranslator.d.ts +14 -0
- package/{src/plugins/translators/index.ts → dist/plugins/translators/index.d.ts} +1 -1
- package/{src/plugins/types.ts → dist/plugins/types.d.ts} +11 -26
- package/dist/results/Result.d.ts +29 -0
- package/{src/results/index.ts → dist/results/index.d.ts} +1 -1
- package/dist/results/index.js +192 -0
- package/dist/results/index.js.map +1 -0
- package/{src/results/types.ts → dist/results/types.d.ts} +18 -7
- package/dist/results/utils.d.ts +2 -0
- package/dist/schema/PropertyInfo.d.ts +132 -0
- package/dist/schema/PropertyInfo.test.d.ts +1 -0
- package/dist/schema/SchemaDefinition.d.ts +17 -0
- package/dist/schema/builder.d.ts +17 -0
- package/{src/schema/index.ts → dist/schema/index.d.ts} +1 -1
- package/dist/schema/index.js +4822 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/property/base/SchemaBase.d.ts +23 -0
- package/dist/schema/property/base/index.d.ts +1 -0
- package/dist/schema/property/modifiers/SchemaDefault.d.ts +13 -0
- package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +11 -0
- package/dist/schema/property/modifiers/SchemaDistinct.d.ts +7 -0
- package/dist/schema/property/modifiers/SchemaFrom.d.ts +23 -0
- package/dist/schema/property/modifiers/SchemaIdentity.d.ts +7 -0
- package/dist/schema/property/modifiers/SchemaIndex.d.ts +23 -0
- package/dist/schema/property/modifiers/SchemaKey.d.ts +13 -0
- package/dist/schema/property/modifiers/SchemaNullable.d.ts +9 -0
- package/dist/schema/property/modifiers/SchemaOptional.d.ts +9 -0
- package/dist/schema/property/modifiers/SchemaReadonly.d.ts +15 -0
- package/dist/schema/property/modifiers/SchemaSerialize.d.ts +9 -0
- package/dist/schema/property/modifiers/SchemaTracked.d.ts +7 -0
- package/{src/schema/property/modifiers/index.ts → dist/schema/property/modifiers/index.d.ts} +1 -1
- package/dist/schema/property/types/SchemaArray.d.ts +23 -0
- package/dist/schema/property/types/SchemaBoolean.d.ts +27 -0
- package/dist/schema/property/types/SchemaDate.d.ts +27 -0
- package/dist/schema/property/types/SchemaNumber.d.ts +31 -0
- package/dist/schema/property/types/SchemaObject.d.ts +20 -0
- package/dist/schema/property/types/SchemaString.d.ts +31 -0
- package/{src/schema/property/types/index.ts → dist/schema/property/types/index.d.ts} +1 -1
- package/dist/schema/table/SchemaComputed.d.ts +10 -0
- package/dist/schema/table/SchemaFunction.d.ts +8 -0
- package/{src/schema/table/index.ts → dist/schema/table/index.d.ts} +1 -1
- package/{src/schema/types.ts → dist/schema/types.d.ts} +59 -99
- package/{src/types/index.ts → dist/types/index.d.ts} +1 -2
- package/dist/types/index.js +25 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utilities/arrays.d.ts +1 -0
- package/dist/utilities/arrays.test.d.ts +1 -0
- package/dist/utilities/dates.d.ts +1 -0
- package/dist/utilities/dates.test.d.ts +1 -0
- package/dist/utilities/dbPluginEventUtils.d.ts +14 -0
- package/{src/utilities/index.ts → dist/utilities/index.d.ts} +1 -1
- package/dist/utilities/index.js +554 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/objects.d.ts +2 -0
- package/dist/utilities/queryOptionsCollection.d.ts +2 -0
- package/dist/utilities/replication.d.ts +3 -0
- package/dist/utilities/runtime.d.ts +1 -0
- package/dist/utilities/strings.d.ts +1 -0
- package/dist/utilities/types.d.ts +1 -0
- package/dist/utilities/uuid.d.ts +2 -0
- package/package.json +6 -1
- package/readme.md +95 -0
- package/CHANGELOG.md +0 -8
- package/rspack.config.mjs +0 -65
- package/src/assertions/index.ts +0 -37
- package/src/codegen/SlotPath.ts +0 -20
- package/src/codegen/blocks.ts +0 -578
- package/src/codegen/handlers/CloneHandlerBuilder.ts +0 -13
- package/src/codegen/handlers/CompareHandlerBuilder.ts +0 -13
- package/src/codegen/handlers/DeserializeHandlerBuilder.ts +0 -20
- package/src/codegen/handlers/EnableChangeTrackingHandlerBuilder.ts +0 -13
- package/src/codegen/handlers/EnrichmentHandlerBuilder.ts +0 -28
- package/src/codegen/handlers/FreezeHandlerBuilder.ts +0 -13
- package/src/codegen/handlers/HashHandlerBuilder.ts +0 -25
- package/src/codegen/handlers/HashTypeHandlerBuilder.ts +0 -11
- package/src/codegen/handlers/IdSelectorHandlerBuilder.ts +0 -10
- package/src/codegen/handlers/MergeHandlerBuilder.ts +0 -19
- package/src/codegen/handlers/PrepareHandlerBuilder.ts +0 -23
- package/src/codegen/handlers/SerializeHandlerBuilder.ts +0 -15
- package/src/codegen/handlers/StripHandlerBuilder.ts +0 -18
- package/src/codegen/handlers/clone/CloneObjectHandler.ts +0 -29
- package/src/codegen/handlers/clone/CloneValueHandler.ts +0 -33
- package/src/codegen/handlers/compare/CompareObjectHandler.ts +0 -15
- package/src/codegen/handlers/compare/CompareValueHandler.ts +0 -27
- package/src/codegen/handlers/deserialize/DeserializeComputedValueHandler.ts +0 -16
- package/src/codegen/handlers/deserialize/DeserializeDateHandler.ts +0 -45
- package/src/codegen/handlers/deserialize/DeserializeFunctionHandler.ts +0 -16
- package/src/codegen/handlers/deserialize/DeserializeObjectHandler.ts +0 -29
- package/src/codegen/handlers/deserialize/DeserializeValueHandler.ts +0 -33
- package/src/codegen/handlers/enableChangeTracking/EnableChangeTrackingObjectHandler.ts +0 -20
- package/src/codegen/handlers/enableChangeTracking/EnableChangeTrackingPrimitiveValueHandler.ts +0 -15
- package/src/codegen/handlers/enrichment/EnrichmentComputedValueHandler.ts +0 -37
- package/src/codegen/handlers/enrichment/EnrichmentDefaultFunctionHandler.ts +0 -50
- package/src/codegen/handlers/enrichment/EnrichmentDefaultValueHandler.ts +0 -18
- package/src/codegen/handlers/enrichment/EnrichmentFunctionHandler.ts +0 -38
- package/src/codegen/handlers/enrichment/EnrichmentNullableObjectHandler.ts +0 -44
- package/src/codegen/handlers/enrichment/EnrichmentObjectHandler.ts +0 -29
- package/src/codegen/handlers/enrichment/EnrichmentObjectIdentityHandler.ts +0 -16
- package/src/codegen/handlers/enrichment/EnrichmentPrimitiveHandler.ts +0 -13
- package/src/codegen/handlers/enrichment/EnrichmentPrimitiveIdentityHandler.ts +0 -21
- package/src/codegen/handlers/freeze/FreezeObjectHandler.ts +0 -20
- package/src/codegen/handlers/freeze/FreezePrimitiveValueHandler.ts +0 -15
- package/src/codegen/handlers/hash/HashComputedValueHandler.ts +0 -15
- package/src/codegen/handlers/hash/HashDateHandler.ts +0 -26
- package/src/codegen/handlers/hash/HashFunctionHandler.ts +0 -16
- package/src/codegen/handlers/hash/HashIdentityHandler.ts +0 -15
- package/src/codegen/handlers/hash/HashKeyHandler.ts +0 -26
- package/src/codegen/handlers/hash/HashValueHandler.ts +0 -26
- package/src/codegen/handlers/hashType/HashTypeValueHandler.ts +0 -20
- package/src/codegen/handlers/idSelector/IdSelectorValueHandler.ts +0 -28
- package/src/codegen/handlers/merge/MergeComputedValueHandler.ts +0 -37
- package/src/codegen/handlers/merge/MergeDefaultFunctionHandler.ts +0 -40
- package/src/codegen/handlers/merge/MergeDefaultValueHandler.ts +0 -32
- package/src/codegen/handlers/merge/MergeFunctionHandler.ts +0 -16
- package/src/codegen/handlers/merge/MergePrimitiveHandler.ts +0 -21
- package/src/codegen/handlers/prepare/PrepareComputedValueHandler.ts +0 -16
- package/src/codegen/handlers/prepare/PrepareFunctionHandler.ts +0 -16
- package/src/codegen/handlers/prepare/PrepareIdentityHandler.ts +0 -21
- package/src/codegen/handlers/prepare/PrepareKeyHandler.ts +0 -21
- package/src/codegen/handlers/prepare/PrepareObjectHandler.ts +0 -38
- package/src/codegen/handlers/prepare/PrepareValueHandler.ts +0 -36
- package/src/codegen/handlers/serialize/SerializeDateHandler.ts +0 -45
- package/src/codegen/handlers/serialize/SerializeObjectHandler.ts +0 -28
- package/src/codegen/handlers/serialize/SerializeValueHandler.ts +0 -33
- package/src/codegen/handlers/strip/StripIdentityHandler.ts +0 -15
- package/src/codegen/handlers/strip/StripKeyHandler.ts +0 -15
- package/src/codegen/handlers/strip/StripObjectHandler.ts +0 -35
- package/src/codegen/handlers/strip/StripValueHandler.ts +0 -36
- package/src/codegen/handlers/types.ts +0 -119
- package/src/codegen/types.ts +0 -2
- package/src/codegen/utils.ts +0 -74
- package/src/collections/Changes.test.ts +0 -337
- package/src/collections/Changes.ts +0 -177
- package/src/collections/IdSet.ts +0 -28
- package/src/collections/MemoryDataCollection.test.ts +0 -424
- package/src/collections/MemoryDataCollection.ts +0 -134
- package/src/collections/SchemaCollection.ts +0 -22
- package/src/collections/TagCollection.test.ts +0 -443
- package/src/collections/TagCollection.ts +0 -62
- package/src/errors/SchemaError.ts +0 -6
- package/src/errors/index.ts +0 -1
- package/src/expressions/parser.test.ts +0 -913
- package/src/expressions/utils.test.ts +0 -346
- package/src/expressions/utils.ts +0 -59
- package/src/performance/index.ts +0 -26
- package/src/pipeline/SyncronousQueue.test.ts +0 -269
- package/src/pipeline/SyncronousQueue.ts +0 -30
- package/src/pipeline/TrampolinePipeline.test.ts +0 -374
- package/src/pipeline/index.ts +0 -2
- package/src/plugins/EphemeralDataPlugin.ts +0 -132
- package/src/plugins/capabilities/DbPluginCapability.ts +0 -111
- package/src/plugins/capabilities/logging/DbPluginLoggingCapability.ts +0 -261
- package/src/plugins/capabilities/logging/index.ts +0 -1
- package/src/plugins/query/Query.ts +0 -67
- package/src/plugins/query/QueryOptionsCollection.test.ts +0 -86
- package/src/plugins/query/QueryOptionsCollection.ts +0 -154
- package/src/plugins/replication/OptimisticReplicationDbPlugin.ts +0 -202
- package/src/plugins/replication/ReplicationDbPlugin.ts +0 -137
- package/src/plugins/translators/DataTranslator.ts +0 -46
- package/src/plugins/translators/JsonTranslator.test.ts +0 -618
- package/src/plugins/translators/JsonTranslator.ts +0 -211
- package/src/plugins/translators/SqlTranslator.ts +0 -45
- package/src/results/Result.ts +0 -91
- package/src/results/utils.ts +0 -15
- package/src/schema/PropertyInfo.test.ts +0 -479
- package/src/schema/PropertyInfo.ts +0 -374
- package/src/schema/SchemaDefinition.ts +0 -626
- package/src/schema/builder.ts +0 -18
- package/src/schema/property/base/SchemaBase.ts +0 -49
- package/src/schema/property/base/index.ts +0 -1
- package/src/schema/property/modifiers/SchemaDefault.ts +0 -29
- package/src/schema/property/modifiers/SchemaDeserialize.ts +0 -23
- package/src/schema/property/modifiers/SchemaDistinct.ts +0 -14
- package/src/schema/property/modifiers/SchemaFrom.ts +0 -54
- package/src/schema/property/modifiers/SchemaIdentity.ts +0 -13
- package/src/schema/property/modifiers/SchemaIndex.ts +0 -60
- package/src/schema/property/modifiers/SchemaKey.ts +0 -28
- package/src/schema/property/modifiers/SchemaNullable.ts +0 -18
- package/src/schema/property/modifiers/SchemaOptional.ts +0 -19
- package/src/schema/property/modifiers/SchemaReadonly.ts +0 -34
- package/src/schema/property/modifiers/SchemaSerialize.ts +0 -18
- package/src/schema/property/modifiers/SchemaTracked.ts +0 -14
- package/src/schema/property/types/SchemaArray.ts +0 -50
- package/src/schema/property/types/SchemaBoolean.ts +0 -59
- package/src/schema/property/types/SchemaDate.ts +0 -58
- package/src/schema/property/types/SchemaNumber.ts +0 -69
- package/src/schema/property/types/SchemaObject.ts +0 -44
- package/src/schema/property/types/SchemaString.ts +0 -69
- package/src/schema/table/SchemaComputed.ts +0 -20
- package/src/schema/table/SchemaFunction.ts +0 -15
- package/src/utilities/arrays.test.ts +0 -312
- package/src/utilities/arrays.ts +0 -12
- package/src/utilities/dates.test.ts +0 -388
- package/src/utilities/dates.ts +0 -11
- package/src/utilities/dbPluginEventUtils.ts +0 -44
- package/src/utilities/objects.ts +0 -7
- package/src/utilities/queryOptionsCollection.ts +0 -16
- package/src/utilities/replication.ts +0 -23
- package/src/utilities/runtime.ts +0 -3
- package/src/utilities/strings.ts +0 -18
- package/src/utilities/types.ts +0 -1
- package/src/utilities/uuid.ts +0 -56
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -11
|
@@ -1,913 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { toExpression, combineExpressions } from './parser';
|
|
3
|
-
import { CompiledSchema, SchemaTypes } from '../schema';
|
|
4
|
-
import { Expression, ComparatorExpression, OperatorExpression, PropertyExpression, ValueExpression } from './types';
|
|
5
|
-
|
|
6
|
-
describe('Parser', () => {
|
|
7
|
-
const mockSchema = {
|
|
8
|
-
properties: [
|
|
9
|
-
{
|
|
10
|
-
getAssignmentPath: () => 'name',
|
|
11
|
-
type: SchemaTypes.String
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
getAssignmentPath: () => 'age',
|
|
15
|
-
type: SchemaTypes.Number
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
getAssignmentPath: () => 'price',
|
|
19
|
-
type: SchemaTypes.Number
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
getAssignmentPath: () => 'isActive',
|
|
23
|
-
type: SchemaTypes.Boolean
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
getAssignmentPath: () => 'isVerified',
|
|
27
|
-
type: SchemaTypes.Boolean
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
getAssignmentPath: () => 'rating',
|
|
31
|
-
type: SchemaTypes.Number
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
getAssignmentPath: () => 'reviewCount',
|
|
35
|
-
type: SchemaTypes.Number
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
getAssignmentPath: () => 'category',
|
|
39
|
-
type: SchemaTypes.String
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
getAssignmentPath: () => 'description',
|
|
43
|
-
type: SchemaTypes.String
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
getAssignmentPath: () => 'features',
|
|
47
|
-
type: SchemaTypes.Array
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
getAssignmentPath: () => 'specifications',
|
|
51
|
-
type: SchemaTypes.Object
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
getAssignmentPath: () => 'brand',
|
|
55
|
-
type: SchemaTypes.String
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
getAssignmentPath: () => 'id',
|
|
59
|
-
type: SchemaTypes.Number
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
getAssignmentPath: () => 'tags',
|
|
63
|
-
type: SchemaTypes.Array
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
getAssignmentPath: () => 'profile',
|
|
67
|
-
type: SchemaTypes.Object
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
getAssignmentPath: () => 'createdAt',
|
|
71
|
-
type: SchemaTypes.Date
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
getAssignmentPath: () => 'playerId',
|
|
75
|
-
type: SchemaTypes.String
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
} as CompiledSchema<any>;
|
|
79
|
-
|
|
80
|
-
// const matches = await dataStore.playerMatches.where(([x, p]) => p.distinctPlayers.includes(x.playerId), { distinctPlayers }).toArrayAsync();
|
|
81
|
-
|
|
82
|
-
describe('toExpression', () => {
|
|
83
|
-
describe('basic comparisons', () => {
|
|
84
|
-
it('should parse equality comparison with ==', () => {
|
|
85
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test');
|
|
86
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
87
|
-
const comp = expression as ComparatorExpression;
|
|
88
|
-
expect(comp.comparator).toBe('equals');
|
|
89
|
-
expect(comp.negated).toBe(false);
|
|
90
|
-
expect(comp.strict).toBe(false);
|
|
91
|
-
expect(comp.left).toBeInstanceOf(PropertyExpression);
|
|
92
|
-
expect(comp.right).toBeInstanceOf(ValueExpression);
|
|
93
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should parse strict equality comparison with ===', () => {
|
|
97
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name === 'test');
|
|
98
|
-
|
|
99
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
100
|
-
const comp = expression as ComparatorExpression;
|
|
101
|
-
expect(comp.comparator).toBe('equals');
|
|
102
|
-
expect(comp.negated).toBe(false);
|
|
103
|
-
expect(comp.strict).toBe(true);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should parse inequality comparison with !=', () => {
|
|
107
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name != 'test');
|
|
108
|
-
|
|
109
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
110
|
-
const comp = expression as ComparatorExpression;
|
|
111
|
-
expect(comp.comparator).toBe('equals');
|
|
112
|
-
expect(comp.negated).toBe(true);
|
|
113
|
-
expect(comp.strict).toBe(false);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should parse strict inequality comparison with !==', () => {
|
|
117
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name !== 'test');
|
|
118
|
-
|
|
119
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
120
|
-
const comp = expression as ComparatorExpression;
|
|
121
|
-
expect(comp.comparator).toBe('equals');
|
|
122
|
-
expect(comp.negated).toBe(true);
|
|
123
|
-
expect(comp.strict).toBe(true);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('numeric comparisons', () => {
|
|
128
|
-
it('should parse greater than comparison', () => {
|
|
129
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age > 18);
|
|
130
|
-
|
|
131
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
132
|
-
const comp = expression as ComparatorExpression;
|
|
133
|
-
expect(comp.comparator).toBe('greater-than');
|
|
134
|
-
expect(comp.negated).toBe(false);
|
|
135
|
-
expect(comp.strict).toBe(false);
|
|
136
|
-
expect((comp.right as ValueExpression).value).toBe(18);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should parse less than comparison', () => {
|
|
140
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age < 65);
|
|
141
|
-
|
|
142
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
143
|
-
const comp = expression as ComparatorExpression;
|
|
144
|
-
expect(comp.comparator).toBe('less-than');
|
|
145
|
-
expect(comp.negated).toBe(false);
|
|
146
|
-
expect(comp.strict).toBe(false);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should parse greater than or equal comparison', () => {
|
|
150
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age >= 18);
|
|
151
|
-
|
|
152
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
153
|
-
const comp = expression as ComparatorExpression;
|
|
154
|
-
expect(comp.comparator).toBe('greater-than-equals');
|
|
155
|
-
expect(comp.negated).toBe(false);
|
|
156
|
-
expect(comp.strict).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should parse less than or equal comparison', () => {
|
|
160
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age <= 65);
|
|
161
|
-
|
|
162
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
163
|
-
const comp = expression as ComparatorExpression;
|
|
164
|
-
expect(comp.comparator).toBe('less-than-equals');
|
|
165
|
-
expect(comp.negated).toBe(false);
|
|
166
|
-
expect(comp.strict).toBe(false);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should parse between comparison', () => {
|
|
170
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age <= 65 && entity.age >= 35);
|
|
171
|
-
|
|
172
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
173
|
-
const operatorExpression = expression as OperatorExpression;
|
|
174
|
-
expect(operatorExpression.operator).toBe("&&");
|
|
175
|
-
|
|
176
|
-
const comp1 = operatorExpression.left as ComparatorExpression;
|
|
177
|
-
const comp2 = operatorExpression.right as ComparatorExpression;
|
|
178
|
-
|
|
179
|
-
expect(comp1.comparator).toBe('less-than-equals');
|
|
180
|
-
expect(comp1.negated).toBe(false);
|
|
181
|
-
expect(comp1.strict).toBe(false);
|
|
182
|
-
|
|
183
|
-
expect(comp2.comparator).toBe('greater-than-equals');
|
|
184
|
-
expect(comp2.negated).toBe(false);
|
|
185
|
-
expect(comp2.strict).toBe(false);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe('string methods', () => {
|
|
190
|
-
it('should parse startsWith method', () => {
|
|
191
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.startsWith('test'));
|
|
192
|
-
|
|
193
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
194
|
-
const comp = expression as ComparatorExpression;
|
|
195
|
-
expect(comp.comparator).toBe('starts-with');
|
|
196
|
-
expect(comp.negated).toBe(false);
|
|
197
|
-
expect(comp.strict).toBe(false);
|
|
198
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('should parse endsWith method', () => {
|
|
202
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.endsWith('test'));
|
|
203
|
-
|
|
204
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
205
|
-
const comp = expression as ComparatorExpression;
|
|
206
|
-
expect(comp.comparator).toBe('ends-with');
|
|
207
|
-
expect(comp.negated).toBe(false);
|
|
208
|
-
expect(comp.strict).toBe(false);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('should parse includes method', () => {
|
|
212
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.includes('test'));
|
|
213
|
-
|
|
214
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
215
|
-
const comp = expression as ComparatorExpression;
|
|
216
|
-
expect(comp.comparator).toBe('includes');
|
|
217
|
-
expect(comp.negated).toBe(false);
|
|
218
|
-
expect(comp.strict).toBe(false);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('should parse negated startsWith method', () => {
|
|
222
|
-
const expression = toExpression(mockSchema, (entity: any) => !entity.name.startsWith('test'));
|
|
223
|
-
|
|
224
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
225
|
-
const comp = expression as ComparatorExpression;
|
|
226
|
-
expect(comp.comparator).toBe('starts-with');
|
|
227
|
-
expect(comp.negated).toBe(true);
|
|
228
|
-
expect(comp.strict).toBe(false);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('should parse startsWith method compared to false', () => {
|
|
232
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.startsWith('test') === false);
|
|
233
|
-
|
|
234
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
235
|
-
const comp = expression as ComparatorExpression;
|
|
236
|
-
expect(comp.comparator).toBe('starts-with');
|
|
237
|
-
expect(comp.negated).toBe(true);
|
|
238
|
-
expect(comp.strict).toBe(false);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('should handle to lower case', () => {
|
|
242
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.toLowerCase().startsWith('test'));
|
|
243
|
-
|
|
244
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
245
|
-
const comp = expression as ComparatorExpression;
|
|
246
|
-
expect(comp.comparator).toBe('starts-with');
|
|
247
|
-
expect(comp.negated).toBe(false);
|
|
248
|
-
expect(comp.strict).toBe(false);
|
|
249
|
-
expect((comp.left as PropertyExpression).transformer).toBe('to-lower-case');
|
|
250
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
251
|
-
expect((comp.right as ValueExpression).transformer).toBeNull()
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should handle to lower case for value and property', () => {
|
|
255
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.toLowerCase().startsWith('test'.toLowerCase()));
|
|
256
|
-
|
|
257
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
258
|
-
const comp = expression as ComparatorExpression;
|
|
259
|
-
expect(comp.comparator).toBe('starts-with');
|
|
260
|
-
expect(comp.negated).toBe(false);
|
|
261
|
-
expect(comp.strict).toBe(false);
|
|
262
|
-
expect((comp.left as PropertyExpression).transformer).toBe('to-lower-case');
|
|
263
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
264
|
-
expect((comp.right as ValueExpression).transformer).toBe('to-lower-case');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('should handle value-side toLowerCase', () => {
|
|
268
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name === 'TEST'.toLowerCase());
|
|
269
|
-
|
|
270
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
271
|
-
const comp = expression as ComparatorExpression;
|
|
272
|
-
expect(comp.comparator).toBe('equals');
|
|
273
|
-
expect(comp.negated).toBe(false);
|
|
274
|
-
expect(comp.strict).toBe(true);
|
|
275
|
-
expect((comp.left as PropertyExpression).transformer).toBeNull();
|
|
276
|
-
expect((comp.right as ValueExpression).transformer).toBe('to-lower-case');
|
|
277
|
-
expect((comp.right as ValueExpression).value).toBe('TEST');
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('should handle toLocaleLowerCase', () => {
|
|
281
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.toLocaleLowerCase().startsWith('test'));
|
|
282
|
-
|
|
283
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
284
|
-
const comp = expression as ComparatorExpression;
|
|
285
|
-
expect(comp.comparator).toBe('starts-with');
|
|
286
|
-
expect(comp.negated).toBe(false);
|
|
287
|
-
expect(comp.strict).toBe(false);
|
|
288
|
-
expect((comp.left as PropertyExpression).transformer).toBe('to-lower-case');
|
|
289
|
-
expect((comp.left as PropertyExpression).locale).toBe('en-US');
|
|
290
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
291
|
-
expect((comp.right as ValueExpression).transformer).toBeNull();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('should handle toLocaleUpperCase', () => {
|
|
295
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.toLocaleUpperCase().includes('TEST'));
|
|
296
|
-
|
|
297
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
298
|
-
const comp = expression as ComparatorExpression;
|
|
299
|
-
expect(comp.comparator).toBe('includes');
|
|
300
|
-
expect(comp.negated).toBe(false);
|
|
301
|
-
expect(comp.strict).toBe(false);
|
|
302
|
-
expect((comp.left as PropertyExpression).transformer).toBe('to-upper-case');
|
|
303
|
-
expect((comp.left as PropertyExpression).locale).toBe('en-US');
|
|
304
|
-
expect((comp.right as ValueExpression).value).toBe('TEST');
|
|
305
|
-
expect((comp.right as ValueExpression).transformer).toBeNull();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('should handle value-side toLocaleLowerCase', () => {
|
|
309
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name === 'TEST'.toLocaleLowerCase());
|
|
310
|
-
|
|
311
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
312
|
-
const comp = expression as ComparatorExpression;
|
|
313
|
-
expect(comp.comparator).toBe('equals');
|
|
314
|
-
expect(comp.negated).toBe(false);
|
|
315
|
-
expect(comp.strict).toBe(true);
|
|
316
|
-
expect((comp.left as PropertyExpression).transformer).toBeNull();
|
|
317
|
-
expect((comp.right as ValueExpression).transformer).toBe('to-lower-case');
|
|
318
|
-
expect((comp.right as ValueExpression).locale).toBe('en-US');
|
|
319
|
-
expect((comp.right as ValueExpression).value).toBe('TEST');
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it('should handle combined locale transformations', () => {
|
|
323
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name.toLocaleLowerCase().startsWith('test'.toLocaleLowerCase()));
|
|
324
|
-
|
|
325
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
326
|
-
const comp = expression as ComparatorExpression;
|
|
327
|
-
expect(comp.comparator).toBe('starts-with');
|
|
328
|
-
expect(comp.negated).toBe(false);
|
|
329
|
-
expect(comp.strict).toBe(false);
|
|
330
|
-
expect((comp.left as PropertyExpression).transformer).toBe('to-lower-case');
|
|
331
|
-
expect((comp.left as PropertyExpression).locale).toBe('en-US');
|
|
332
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
333
|
-
expect((comp.right as ValueExpression).transformer).toBe('to-lower-case');
|
|
334
|
-
expect((comp.right as ValueExpression).locale).toBe('en-US');
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
describe('boolean values', () => {
|
|
339
|
-
it('should parse boolean true comparison', () => {
|
|
340
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.isActive == true);
|
|
341
|
-
|
|
342
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
343
|
-
const comp = expression as ComparatorExpression;
|
|
344
|
-
expect(comp.comparator).toBe('equals');
|
|
345
|
-
expect((comp.right as ValueExpression).value).toBe(true);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
it('should parse boolean false comparison', () => {
|
|
349
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.isActive == false);
|
|
350
|
-
|
|
351
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
352
|
-
const comp = expression as ComparatorExpression;
|
|
353
|
-
expect(comp.comparator).toBe('equals');
|
|
354
|
-
// The parser treats "false" as a string and converts it to Boolean("false") = true
|
|
355
|
-
expect((comp.right as ValueExpression).value).toBe(true);
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
describe('array methods', () => {
|
|
360
|
-
it('should parse boolean false comparison', () => {
|
|
361
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.tags.includes("test"));
|
|
362
|
-
|
|
363
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
364
|
-
const comp = expression as ComparatorExpression;
|
|
365
|
-
expect(comp.comparator).toBe('includes');
|
|
366
|
-
// The parser treats "false" as a string and converts it to Boolean("false") = true
|
|
367
|
-
expect((comp.right as ValueExpression).value).toBe("test");
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
describe('parameterized filters', () => {
|
|
372
|
-
it('should parse parameterized filter with string parameter', () => {
|
|
373
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { searchTerm: string }]) => entity.name == params.searchTerm, { searchTerm: 'test' });
|
|
374
|
-
|
|
375
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
376
|
-
const comp = expression as ComparatorExpression;
|
|
377
|
-
expect(comp.comparator).toBe('equals');
|
|
378
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('should parse parameterized filter with number parameter', () => {
|
|
382
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { minAge: number }]) => entity.age >= params.minAge, { minAge: 18 });
|
|
383
|
-
|
|
384
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
385
|
-
const comp = expression as ComparatorExpression;
|
|
386
|
-
expect(comp.comparator).toBe('greater-than-equals');
|
|
387
|
-
expect((comp.right as ValueExpression).value).toBe(18);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it('should parse parameterized filter with nested parameter', () => {
|
|
391
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { filters: { searchTerm: string } }]) => entity.name == params.filters.searchTerm, { filters: { searchTerm: 'test' } });
|
|
392
|
-
|
|
393
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
394
|
-
const comp = expression as ComparatorExpression;
|
|
395
|
-
expect(comp.comparator).toBe('equals');
|
|
396
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it('should return NOT_PARSABLE for invalid parameter path', () => {
|
|
400
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { searchTerm: string }]) => entity.name == (params as any).invalidPath, { searchTerm: 'test' });
|
|
401
|
-
|
|
402
|
-
expect(expression).toStrictEqual(Expression.NOT_PARSABLE);
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it('should return NOT_PARSABLE for invalid parameter usage', () => {
|
|
406
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { searchTerm: string }]) => entity.name == params as any, { searchTerm: 'test' });
|
|
407
|
-
|
|
408
|
-
expect(expression).toStrictEqual(Expression.NOT_PARSABLE);
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
it('should parse parameterized filter with includes method', () => {
|
|
412
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { distinctPlayers: string[] }]) => params.distinctPlayers.includes(entity.playerId), { distinctPlayers: ['player1', 'player2'] });
|
|
413
|
-
|
|
414
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
415
|
-
const comp = expression as ComparatorExpression;
|
|
416
|
-
expect(comp.comparator).toBe('includes');
|
|
417
|
-
expect(comp.negated).toBe(false);
|
|
418
|
-
expect(comp.strict).toBe(false);
|
|
419
|
-
expect((comp.left as ValueExpression).value).toEqual(['player1', 'player2']);
|
|
420
|
-
expect((comp.right as PropertyExpression).property.getAssignmentPath()).toBe('playerId');
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
describe('null/undefined comparisons', () => {
|
|
425
|
-
it('should parse null comparison', () => {
|
|
426
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == null);
|
|
427
|
-
|
|
428
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
429
|
-
const comp = expression as ComparatorExpression;
|
|
430
|
-
expect(comp.comparator).toBe('equals');
|
|
431
|
-
expect(comp.strict).toBe(false);
|
|
432
|
-
expect((comp.right as ValueExpression).value).toBeNull();
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('should parse null comparison', () => {
|
|
436
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == undefined);
|
|
437
|
-
|
|
438
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
439
|
-
const comp = expression as ComparatorExpression;
|
|
440
|
-
expect(comp.comparator).toBe('equals');
|
|
441
|
-
expect(comp.strict).toBe(false);
|
|
442
|
-
expect((comp.right as ValueExpression).value).toBeUndefined();
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
describe('logical operators', () => {
|
|
447
|
-
it('should parse AND operator', () => {
|
|
448
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test' && entity.age > 18);
|
|
449
|
-
|
|
450
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
451
|
-
const op = expression as OperatorExpression;
|
|
452
|
-
expect(op.operator).toBe('&&');
|
|
453
|
-
expect(op.left).toBeInstanceOf(ComparatorExpression);
|
|
454
|
-
expect(op.right).toBeInstanceOf(ComparatorExpression);
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
it('should parse OR operator', () => {
|
|
458
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test' || entity.age > 18);
|
|
459
|
-
|
|
460
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
461
|
-
const op = expression as OperatorExpression;
|
|
462
|
-
expect(op.operator).toBe('||');
|
|
463
|
-
expect(op.left).toBeInstanceOf(ComparatorExpression);
|
|
464
|
-
expect(op.right).toBeInstanceOf(ComparatorExpression);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it('should parse complex logical expression with precedence', () => {
|
|
468
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test' && entity.age > 18 || entity.isActive == true);
|
|
469
|
-
|
|
470
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
471
|
-
const op = expression as OperatorExpression;
|
|
472
|
-
expect(op.operator).toBe('&&');
|
|
473
|
-
expect(op.left).toBeInstanceOf(ComparatorExpression);
|
|
474
|
-
expect(op.right).toBeInstanceOf(OperatorExpression);
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
describe('parentheses', () => {
|
|
479
|
-
it('should parse expression with parentheses', () => {
|
|
480
|
-
const expression = toExpression(mockSchema, (entity: any) => (entity.name == 'test') && (entity.age > 18));
|
|
481
|
-
|
|
482
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
483
|
-
const op = expression as OperatorExpression;
|
|
484
|
-
expect(op.operator).toBe('&&');
|
|
485
|
-
expect(op.left).toBeInstanceOf(ComparatorExpression);
|
|
486
|
-
expect(op.right).toBeInstanceOf(ComparatorExpression);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
it('should parse nested parentheses', () => {
|
|
490
|
-
const expression = toExpression(mockSchema, (entity: any) => ((entity.name == 'test')));
|
|
491
|
-
|
|
492
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
493
|
-
const comp = expression as ComparatorExpression;
|
|
494
|
-
expect(comp.comparator).toBe('equals');
|
|
495
|
-
});
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
describe('error handling', () => {
|
|
499
|
-
it('should return NOT_PARSABLE for invalid function format', () => {
|
|
500
|
-
const expression = toExpression(mockSchema, (() => 'invalid') as any);
|
|
501
|
-
|
|
502
|
-
expect(expression).toStrictEqual(Expression.NOT_PARSABLE);
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it('should return NOT_PARSABLE for unsupported expression format', () => {
|
|
506
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name + 'test' as any);
|
|
507
|
-
|
|
508
|
-
expect(expression).toStrictEqual(Expression.NOT_PARSABLE);
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it('should return NOT_PARSABLE for unknown property', () => {
|
|
512
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.unknownProperty == 'test');
|
|
513
|
-
|
|
514
|
-
expect(expression).toStrictEqual(Expression.NOT_PARSABLE);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
it('should return NOT_PARSABLE for invalid parameter usage', () => {
|
|
518
|
-
const expression = toExpression(mockSchema, ([entity, params]: [any, { searchTerm: string }]) => entity.name == params as any, { searchTerm: 'test' });
|
|
519
|
-
|
|
520
|
-
expect(expression).toStrictEqual(Expression.NOT_PARSABLE);
|
|
521
|
-
});
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
describe('type conversion', () => {
|
|
525
|
-
it('should convert string values for string properties', () => {
|
|
526
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test');
|
|
527
|
-
|
|
528
|
-
const comp = expression as ComparatorExpression;
|
|
529
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
it('should convert number values for number properties', () => {
|
|
533
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age == 25);
|
|
534
|
-
|
|
535
|
-
const comp = expression as ComparatorExpression;
|
|
536
|
-
expect((comp.right as ValueExpression).value).toBe(25);
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
it('should convert boolean values for boolean properties', () => {
|
|
540
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.isActive == true);
|
|
541
|
-
|
|
542
|
-
const comp = expression as ComparatorExpression;
|
|
543
|
-
expect((comp.right as ValueExpression).value).toBe(true);
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
it('should handle numeric string values', () => {
|
|
547
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age == '25');
|
|
548
|
-
|
|
549
|
-
const comp = expression as ComparatorExpression;
|
|
550
|
-
expect((comp.right as ValueExpression).value).toBe(25);
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
it('should handle boolean string values', () => {
|
|
554
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.isActive == 'true');
|
|
555
|
-
|
|
556
|
-
const comp = expression as ComparatorExpression;
|
|
557
|
-
expect((comp.right as ValueExpression).value).toBe(true);
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
describe('edge cases', () => {
|
|
562
|
-
it('should handle expressions with extra whitespace', () => {
|
|
563
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test' && entity.age > 18);
|
|
564
|
-
|
|
565
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
566
|
-
const op = expression as OperatorExpression;
|
|
567
|
-
expect(op.operator).toBe('&&');
|
|
568
|
-
expect(op.left).toBeInstanceOf(ComparatorExpression);
|
|
569
|
-
expect(op.right).toBeInstanceOf(ComparatorExpression);
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it('should handle expressions with multiple parentheses levels', () => {
|
|
573
|
-
const expression = toExpression(mockSchema, (entity: any) => ((entity.name == 'test')));
|
|
574
|
-
|
|
575
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
576
|
-
const comp = expression as ComparatorExpression;
|
|
577
|
-
expect(comp.comparator).toBe('equals');
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
it('should handle expressions with complex parentheses grouping', () => {
|
|
581
|
-
const expression = toExpression(mockSchema, (entity: any) => (entity.name == 'test' && entity.age > 18) || entity.isActive == true);
|
|
582
|
-
|
|
583
|
-
expect(expression).toBeInstanceOf(OperatorExpression);
|
|
584
|
-
const op = expression as OperatorExpression;
|
|
585
|
-
expect(op.operator).toBe('&&');
|
|
586
|
-
expect(op.left).toBeInstanceOf(ComparatorExpression);
|
|
587
|
-
expect(op.right).toBeInstanceOf(OperatorExpression);
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
it('should handle expressions with string values containing spaces', () => {
|
|
591
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name == 'test value');
|
|
592
|
-
|
|
593
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
594
|
-
const comp = expression as ComparatorExpression;
|
|
595
|
-
expect((comp.right as ValueExpression).value).toBe('test value');
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
it('should handle expressions with numeric comparisons to string numbers', () => {
|
|
599
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.age > '18');
|
|
600
|
-
|
|
601
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
602
|
-
const comp = expression as ComparatorExpression;
|
|
603
|
-
expect(comp.comparator).toBe('greater-than');
|
|
604
|
-
expect((comp.right as ValueExpression).value).toBe(18);
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
describe('reversed comparisons', () => {
|
|
609
|
-
it('should handle reversed equality comparison', () => {
|
|
610
|
-
const expression = toExpression(mockSchema, (entity: any) => "test" === entity.name);
|
|
611
|
-
|
|
612
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
613
|
-
const comp = expression as ComparatorExpression;
|
|
614
|
-
expect(comp.comparator).toBe('equals');
|
|
615
|
-
expect(comp.negated).toBe(false);
|
|
616
|
-
expect(comp.strict).toBe(true);
|
|
617
|
-
expect(comp.left).toBeInstanceOf(PropertyExpression);
|
|
618
|
-
expect(comp.right).toBeInstanceOf(ValueExpression);
|
|
619
|
-
expect((comp.right as ValueExpression).value).toBe('test');
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
it('should handle reversed numeric comparison', () => {
|
|
623
|
-
const expression = toExpression(mockSchema, (entity: any) => 18 <= entity.age);
|
|
624
|
-
|
|
625
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
626
|
-
const comp = expression as ComparatorExpression;
|
|
627
|
-
expect(comp.comparator).toBe('greater-than-equals');
|
|
628
|
-
expect(comp.negated).toBe(false);
|
|
629
|
-
expect(comp.strict).toBe(false);
|
|
630
|
-
expect(comp.left).toBeInstanceOf(PropertyExpression);
|
|
631
|
-
expect(comp.right).toBeInstanceOf(ValueExpression);
|
|
632
|
-
expect((comp.right as ValueExpression).value).toBe(18);
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
describe.skip('todo', () => {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
// it('should parse multiple complex expressions efficiently', () => {
|
|
641
|
-
// const params = {
|
|
642
|
-
// filters: {
|
|
643
|
-
// categories: ['electronics', 'books'],
|
|
644
|
-
// priceRange: { min: 10, max: 500 },
|
|
645
|
-
// searchTerm: 'javascript'
|
|
646
|
-
// }
|
|
647
|
-
// };
|
|
648
|
-
|
|
649
|
-
// const expressions = [
|
|
650
|
-
// // Expression 1: Product search with category and price filtering
|
|
651
|
-
// ([entity, params]: [any, { filters: { categories: string[], priceRange: { min: number, max: number }, searchTerm: string } }]) =>
|
|
652
|
-
// entity.category === params.filters.categories[0] &&
|
|
653
|
-
// entity.price >= params.filters.priceRange.min &&
|
|
654
|
-
// entity.price <= params.filters.priceRange.max &&
|
|
655
|
-
// entity.name.toLowerCase().includes(params.filters.searchTerm.toLowerCase()) &&
|
|
656
|
-
// entity.isActive === true &&
|
|
657
|
-
// entity.rating >= 4.0,
|
|
658
|
-
|
|
659
|
-
// // Expression 2: User preference based filtering
|
|
660
|
-
// ([entity, params]: [any, { filters: { categories: string[], priceRange: { min: number, max: number }, searchTerm: string } }]) =>
|
|
661
|
-
// (entity.category === params.filters.categories[0] || entity.category === params.filters.categories[1]) &&
|
|
662
|
-
// entity.price <= params.filters.priceRange.max &&
|
|
663
|
-
// entity.description.toLowerCase().includes(params.filters.searchTerm.toLowerCase()) &&
|
|
664
|
-
// entity.reviewCount > 5 &&
|
|
665
|
-
// entity.isVerified === true,
|
|
666
|
-
|
|
667
|
-
// // Expression 3: Advanced filtering with multiple conditions
|
|
668
|
-
// ([entity, params]: [any, { filters: { categories: string[], priceRange: { min: number, max: number }, searchTerm: string } }]) =>
|
|
669
|
-
// entity.price >= params.filters.priceRange.min &&
|
|
670
|
-
// entity.price <= params.filters.priceRange.max &&
|
|
671
|
-
// (entity.name.startsWith('Pro') || entity.name.endsWith('Plus')) &&
|
|
672
|
-
// entity.tags && entity.tags.length > 0 &&
|
|
673
|
-
// !entity.tags.includes('deprecated') &&
|
|
674
|
-
// entity.createdAt >= '2023-01-01' &&
|
|
675
|
-
// entity.createdAt <= '2023-12-31',
|
|
676
|
-
|
|
677
|
-
// // Expression 4: Complex nested logical operations
|
|
678
|
-
// ([entity, params]: [any, { filters: { categories: string[], priceRange: { min: number, max: number }, searchTerm: string } }]) =>
|
|
679
|
-
// ((entity.category === 'electronics' && entity.price > 100) ||
|
|
680
|
-
// (entity.category === 'books' && entity.price < 50) ||
|
|
681
|
-
// (entity.category === 'clothing' && entity.price >= 20 && entity.price <= 200)) &&
|
|
682
|
-
// entity.name.toLowerCase().includes(params.filters.searchTerm.toLowerCase()) &&
|
|
683
|
-
// entity.isActive === true &&
|
|
684
|
-
// entity.rating >= 3.5,
|
|
685
|
-
|
|
686
|
-
// // Expression 5: Multi-field search with validation
|
|
687
|
-
// ([entity, params]: [any, { filters: { categories: string[], priceRange: { min: number, max: number }, searchTerm: string } }]) =>
|
|
688
|
-
// entity.price >= params.filters.priceRange.min &&
|
|
689
|
-
// entity.price <= params.filters.priceRange.max &&
|
|
690
|
-
// (entity.name.toLowerCase().includes(params.filters.searchTerm.toLowerCase()) ||
|
|
691
|
-
// entity.description.toLowerCase().includes(params.filters.searchTerm.toLowerCase()) ||
|
|
692
|
-
// entity.brand.toLowerCase().includes(params.filters.searchTerm.toLowerCase())) &&
|
|
693
|
-
// entity.isVerified === true &&
|
|
694
|
-
// entity.reviewCount >= 3
|
|
695
|
-
// ];
|
|
696
|
-
|
|
697
|
-
// const start = performance.now();
|
|
698
|
-
|
|
699
|
-
// const parsedExpressions = expressions.map(expr =>
|
|
700
|
-
// toExpression(mockSchema, expr, params)
|
|
701
|
-
// );
|
|
702
|
-
|
|
703
|
-
// const end = performance.now();
|
|
704
|
-
// const duration = end - start;
|
|
705
|
-
|
|
706
|
-
// console.log(`Parsed ${expressions.length} complex expressions in: ${duration.toFixed(2)}ms`);
|
|
707
|
-
// console.log(`Average time per expression: ${(duration / expressions.length).toFixed(2)}ms`);
|
|
708
|
-
|
|
709
|
-
// parsedExpressions.forEach((expression, index) => {
|
|
710
|
-
// expect(expression).not.toBeNull();
|
|
711
|
-
// expect(expression).not.toStrictEqual(Expression.NOT_PARSABLE);
|
|
712
|
-
// });
|
|
713
|
-
|
|
714
|
-
// expect(duration).toBeLessThan(200); // Should complete in under 200ms
|
|
715
|
-
// });
|
|
716
|
-
});
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
describe('combineExpressions', () => {
|
|
720
|
-
it('should throw error for empty expressions array', () => {
|
|
721
|
-
expect(() => {
|
|
722
|
-
combineExpressions();
|
|
723
|
-
}).toThrow('combineExpressions requires at least 1 expression');
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
it('should return single expression when only one provided', () => {
|
|
727
|
-
const expression = new ComparatorExpression({
|
|
728
|
-
comparator: 'equals',
|
|
729
|
-
negated: false,
|
|
730
|
-
strict: false
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
const result = combineExpressions(expression);
|
|
734
|
-
expect(result).toBe(expression);
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
it('should combine two expressions with AND operator', () => {
|
|
738
|
-
const expr1 = new ComparatorExpression({
|
|
739
|
-
comparator: 'equals',
|
|
740
|
-
negated: false,
|
|
741
|
-
strict: false
|
|
742
|
-
});
|
|
743
|
-
const expr2 = new ComparatorExpression({
|
|
744
|
-
comparator: 'greater-than',
|
|
745
|
-
negated: false,
|
|
746
|
-
strict: false
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
const result = combineExpressions(expr1, expr2);
|
|
750
|
-
expect(result).toBeInstanceOf(OperatorExpression);
|
|
751
|
-
const op = result as OperatorExpression;
|
|
752
|
-
expect(op.operator).toBe('&&');
|
|
753
|
-
expect(op.left).toBe(expr1);
|
|
754
|
-
expect(op.right).toBe(expr2);
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
it('should combine multiple expressions with AND operators', () => {
|
|
758
|
-
const expr1 = new ComparatorExpression({
|
|
759
|
-
comparator: 'equals',
|
|
760
|
-
negated: false,
|
|
761
|
-
strict: false
|
|
762
|
-
});
|
|
763
|
-
const expr2 = new ComparatorExpression({
|
|
764
|
-
comparator: 'greater-than',
|
|
765
|
-
negated: false,
|
|
766
|
-
strict: false
|
|
767
|
-
});
|
|
768
|
-
const expr3 = new ComparatorExpression({
|
|
769
|
-
comparator: 'less-than',
|
|
770
|
-
negated: false,
|
|
771
|
-
strict: false
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
const result = combineExpressions(expr1, expr2, expr3);
|
|
775
|
-
expect(result).toBeInstanceOf(OperatorExpression);
|
|
776
|
-
const op = result as OperatorExpression;
|
|
777
|
-
expect(op.operator).toBe('&&');
|
|
778
|
-
expect(op.left).toBeInstanceOf(OperatorExpression);
|
|
779
|
-
expect(op.right).toBe(expr3);
|
|
780
|
-
});
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
describe("performance", () => {
|
|
784
|
-
it('should parse simple expression under .05 ms', () => {
|
|
785
|
-
|
|
786
|
-
// Warm Up
|
|
787
|
-
for (let i = 0; i < 50; i++) {
|
|
788
|
-
toExpression(mockSchema, (entity: any) => entity.name === 'test');
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
const start = performance.now();
|
|
792
|
-
const expression = toExpression(mockSchema, (entity: any) => entity.name === 'test');
|
|
793
|
-
const delta = performance.now() - start;
|
|
794
|
-
console.log(`Took ${delta}ms`)
|
|
795
|
-
expect(delta).toBeLessThan(.05);
|
|
796
|
-
expect(expression).toBeInstanceOf(ComparatorExpression);
|
|
797
|
-
const comp = expression as ComparatorExpression;
|
|
798
|
-
expect(comp.comparator).toBe('equals');
|
|
799
|
-
expect(comp.negated).toBe(false);
|
|
800
|
-
expect(comp.strict).toBe(true);
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
it('should parse slightly complex real-world expression under .5ms', () => {
|
|
804
|
-
const complexParams = {
|
|
805
|
-
userFilters: {
|
|
806
|
-
ageRange: { min: 18, max: 65 },
|
|
807
|
-
categories: ['electronics', 'books', 'clothing'],
|
|
808
|
-
priceRange: { min: 10, max: 1000 },
|
|
809
|
-
searchTerms: ['javascript', 'react', 'typescript'],
|
|
810
|
-
excludeTags: ['deprecated', 'legacy'],
|
|
811
|
-
dateRange: { start: '2023-01-01', end: '2023-12-31' }
|
|
812
|
-
},
|
|
813
|
-
userPreferences: {
|
|
814
|
-
preferredCategories: ['electronics', 'books'],
|
|
815
|
-
maxPrice: 500,
|
|
816
|
-
requireReviews: true,
|
|
817
|
-
minRating: 4.0
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
|
|
821
|
-
// Warm Up
|
|
822
|
-
for (let i = 0; i < 50; i++) {
|
|
823
|
-
toExpression(mockSchema,
|
|
824
|
-
([entity, params]: [any, typeof complexParams]) =>
|
|
825
|
-
// User age and category preferences
|
|
826
|
-
(entity.age >= params.userFilters.ageRange.min && entity.age <= params.userFilters.ageRange.max) &&
|
|
827
|
-
|
|
828
|
-
// Price filtering with user preferences
|
|
829
|
-
(entity.price >= params.userFilters.priceRange.min && entity.price <= params.userFilters.priceRange.max) &&
|
|
830
|
-
(entity.price <= params.userPreferences.maxPrice) &&
|
|
831
|
-
|
|
832
|
-
// Date range filtering
|
|
833
|
-
(entity.createdAt >= params.userFilters.dateRange.start && entity.createdAt <= params.userFilters.dateRange.end) &&
|
|
834
|
-
|
|
835
|
-
// Quality filters
|
|
836
|
-
(entity.isActive === true) &&
|
|
837
|
-
(entity.isVerified === true) &&
|
|
838
|
-
(entity.rating >= params.userPreferences.minRating) &&
|
|
839
|
-
(entity.reviewCount > 0) &&
|
|
840
|
-
|
|
841
|
-
// Complex nested conditions
|
|
842
|
-
((entity.category === 'electronics' && entity.price > 100) ||
|
|
843
|
-
(entity.category === 'books' && entity.price < 50) ||
|
|
844
|
-
(entity.category === 'clothing' && entity.price >= 20 && entity.price <= 200)) &&
|
|
845
|
-
|
|
846
|
-
// Advanced string matching
|
|
847
|
-
(entity.name.startsWith('Premium') || entity.name.endsWith('Pro') || entity.name.includes('Advanced')) &&
|
|
848
|
-
|
|
849
|
-
// Multiple OR conditions with AND combinations
|
|
850
|
-
((entity.brand === 'Apple' && entity.price > 200) ||
|
|
851
|
-
(entity.brand === 'Samsung' && entity.price > 150) ||
|
|
852
|
-
(entity.brand === 'Sony' && entity.price > 100) ||
|
|
853
|
-
(entity.brand !== 'Apple' && entity.brand !== 'Samsung' && entity.brand !== 'Sony' && entity.price < 100)) &&
|
|
854
|
-
|
|
855
|
-
// Final validation checks
|
|
856
|
-
(entity.id > 0) &&
|
|
857
|
-
(entity.name !== '') &&
|
|
858
|
-
(entity.category !== '') &&
|
|
859
|
-
(entity.price > 0)
|
|
860
|
-
, complexParams);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
const start = performance.now();
|
|
864
|
-
const expression = toExpression(mockSchema,
|
|
865
|
-
([entity, params]: [any, typeof complexParams]) =>
|
|
866
|
-
// User age and category preferences
|
|
867
|
-
(entity.age >= params.userFilters.ageRange.min && entity.age <= params.userFilters.ageRange.max) &&
|
|
868
|
-
|
|
869
|
-
// Price filtering with user preferences
|
|
870
|
-
(entity.price >= params.userFilters.priceRange.min && entity.price <= params.userFilters.priceRange.max) &&
|
|
871
|
-
(entity.price <= params.userPreferences.maxPrice) &&
|
|
872
|
-
|
|
873
|
-
// Date range filtering
|
|
874
|
-
(entity.createdAt >= params.userFilters.dateRange.start && entity.createdAt <= params.userFilters.dateRange.end) &&
|
|
875
|
-
|
|
876
|
-
// Quality filters
|
|
877
|
-
(entity.isActive === true) &&
|
|
878
|
-
(entity.isVerified === true) &&
|
|
879
|
-
(entity.rating >= params.userPreferences.minRating) &&
|
|
880
|
-
(entity.reviewCount > 0) &&
|
|
881
|
-
|
|
882
|
-
// Complex nested conditions
|
|
883
|
-
((entity.category === 'electronics' && entity.price > 100) ||
|
|
884
|
-
(entity.category === 'books' && entity.price < 50) ||
|
|
885
|
-
(entity.category === 'clothing' && entity.price >= 20 && entity.price <= 200)) &&
|
|
886
|
-
|
|
887
|
-
// Advanced string matching
|
|
888
|
-
(entity.name.startsWith('Premium') || entity.name.endsWith('Pro') || entity.name.includes('Advanced')) &&
|
|
889
|
-
|
|
890
|
-
// Multiple OR conditions with AND combinations
|
|
891
|
-
((entity.brand === 'Apple' && entity.price > 200) ||
|
|
892
|
-
(entity.brand === 'Samsung' && entity.price > 150) ||
|
|
893
|
-
(entity.brand === 'Sony' && entity.price > 100) ||
|
|
894
|
-
(entity.brand !== 'Apple' && entity.brand !== 'Samsung' && entity.brand !== 'Sony' && entity.price < 100)) &&
|
|
895
|
-
|
|
896
|
-
// Final validation checks
|
|
897
|
-
(entity.id > 0) &&
|
|
898
|
-
(entity.name !== '') &&
|
|
899
|
-
(entity.category !== '') &&
|
|
900
|
-
(entity.price > 0)
|
|
901
|
-
, complexParams);
|
|
902
|
-
|
|
903
|
-
const end = performance.now();
|
|
904
|
-
const duration = end - start;
|
|
905
|
-
|
|
906
|
-
console.log(`Complex expression parsing took: ${duration.toFixed(2)}ms`);
|
|
907
|
-
|
|
908
|
-
expect(expression).not.toBeNull();
|
|
909
|
-
expect(expression).not.toStrictEqual(Expression.NOT_PARSABLE); // Parser can handle this expression
|
|
910
|
-
expect(duration).toBeLessThan(.5); // Should complete in under 100ms
|
|
911
|
-
});
|
|
912
|
-
})
|
|
913
|
-
});
|