@routier/core 0.2.0 → 0.2.1
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 +30 -0
- package/dist/assertions/index.js +88 -4
- package/dist/assertions/index.js.map +1 -1
- package/dist/capabilities/index.js +25 -16
- package/dist/capabilities/index.js.map +1 -1
- package/dist/codegen/blocks.test.d.ts +1 -0
- package/dist/codegen/handlers/SetHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/index.d.ts +1 -0
- package/dist/codegen/handlers/serialize/SerializeComputedHandler.d.ts +6 -0
- package/dist/codegen/handlers/set/SetComplexHandler.d.ts +6 -0
- package/dist/codegen/index.js +1 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/utils.test.d.ts +1 -0
- package/dist/collections/Changes.d.ts +2 -2
- package/dist/collections/IdSet.test.d.ts +1 -0
- package/dist/collections/TagCollection.contract.test.d.ts +1 -0
- package/dist/collections/TagCollection.d.ts +7 -7
- package/dist/collections/index.js +1 -1
- package/dist/collections/index.js.map +1 -1
- package/dist/expressions/constants.d.ts +2 -0
- package/dist/expressions/index.d.ts +2 -0
- package/dist/expressions/index.js +401 -34
- package/dist/expressions/index.js.map +1 -1
- package/dist/expressions/sql.d.ts +28 -0
- package/dist/expressions/sql.test.d.ts +1 -0
- package/dist/expressions/utils.d.ts +1 -2
- package/dist/index.js +1669 -610
- package/dist/index.js.map +1 -1
- package/dist/performance/index.js +18 -7
- package/dist/performance/index.js.map +1 -1
- package/dist/pipeline/index.js +18 -7
- package/dist/pipeline/index.js.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.js +126 -694
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/query/Query.test.d.ts +1 -0
- package/dist/plugins/query/QueryOptionsCollection.d.ts +1 -0
- package/dist/plugins/translators/SqlTranslator.test.d.ts +1 -0
- package/dist/plugins/translators/TranslatedArrayValue.d.ts +3 -1
- package/dist/plugins/translators/TranslatedGroupValue.d.ts +3 -1
- package/dist/plugins/translators/TranslatedSingleValue.d.ts +3 -1
- package/dist/plugins/translators/TranslatedValues.test.d.ts +1 -0
- package/dist/plugins/translators/types.d.ts +8 -1
- package/dist/plugins/types.d.ts +6 -10
- package/dist/results/Result.d.ts +2 -2
- package/dist/results/Result.test.d.ts +1 -0
- package/dist/results/index.js.map +1 -1
- package/dist/results/utils.test.d.ts +1 -0
- package/dist/schema/PropertyInfo.d.ts +5 -1
- package/dist/schema/SchemaDefinition.d.ts +29 -1
- package/dist/schema/communication/broadcast.test.d.ts +1 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +1151 -132
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/property/base/SchemaBase.d.ts +3 -1
- package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +5 -1
- package/dist/schema/property/modifiers/SchemaForeignKey.d.ts +15 -0
- package/dist/schema/property/modifiers/SchemaKey.d.ts +2 -0
- package/dist/schema/property/modifiers/SchemaNullable.d.ts +5 -1
- package/dist/schema/property/modifiers/SchemaOptional.d.ts +3 -1
- package/dist/schema/property/modifiers/SchemaTag.d.ts +27 -0
- package/dist/schema/property/modifiers/SchemaTracked.d.ts +5 -1
- package/dist/schema/property/modifiers/index.d.ts +2 -0
- package/dist/schema/property/types/SchemaArray.d.ts +2 -0
- package/dist/schema/property/types/SchemaBoolean.d.ts +2 -0
- package/dist/schema/property/types/SchemaDate.d.ts +2 -0
- package/dist/schema/property/types/SchemaNumber.d.ts +5 -1
- package/dist/schema/property/types/SchemaObject.d.ts +2 -0
- package/dist/schema/property/types/SchemaString.d.ts +5 -1
- package/dist/schema/types.d.ts +37 -27
- package/dist/schema/utils/standardJsonSchema.d.ts +90 -0
- package/dist/schema/utils/standardJsonSchema.test.d.ts +1 -0
- package/dist/utilities/functions.d.ts +1 -1
- package/dist/utilities/index.js +153 -15
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/runtime.test.d.ts +1 -0
- package/dist/utilities/uuid.test.d.ts +1 -0
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +0 -23
- package/dist/plugins/replication/ReplicationDbPlugin.d.ts +0 -22
- package/dist/plugins/replication/index.d.ts +0 -3
- package/dist/plugins/replication/types.d.ts +0 -5
- package/dist/schema/testSchemas.test.d.ts +0 -314
- /package/dist/{pipeline/WorkPipeline.test.d.ts → codegen/SlotPath.test.d.ts} +0 -0
|
@@ -6,10 +6,20 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
6
6
|
assertInstanceOf: () => (assertInstanceOf),
|
|
7
7
|
assertIsArray: () => (assertIsArray),
|
|
8
8
|
assertIsNotNull: () => (assertIsNotNull),
|
|
9
|
-
|
|
9
|
+
assertIsNumber: () => (assertIsNumber),
|
|
10
|
+
assertString: () => (assertString),
|
|
11
|
+
isComparatorExpression: () => (isComparatorExpression),
|
|
12
|
+
isEmptyExpression: () => (isEmptyExpression),
|
|
13
|
+
isExpression: () => (isExpression),
|
|
14
|
+
isNotParsableExpression: () => (isNotParsableExpression),
|
|
15
|
+
isOperatorExpression: () => (isOperatorExpression),
|
|
16
|
+
isPropertyExpression: () => (isPropertyExpression),
|
|
17
|
+
isValueExpression: () => (isValueExpression)
|
|
10
18
|
});
|
|
19
|
+
/* import */ var _expressions_constants__rspack_import_1 = __webpack_require__("./src/expressions/constants.ts");
|
|
11
20
|
/* import */ var _utilities__rspack_import_0 = __webpack_require__("./src/utilities/dates.ts");
|
|
12
21
|
|
|
22
|
+
|
|
13
23
|
function assertDate(data) {
|
|
14
24
|
if ((0,_utilities__rspack_import_0.isDate)(data) === false) {
|
|
15
25
|
throw new TypeError('Value is not a Date');
|
|
@@ -41,12 +51,78 @@ function assertInstanceOf(value, Instance) {
|
|
|
41
51
|
return;
|
|
42
52
|
}
|
|
43
53
|
if (value != null && typeof value === "object" && "constructor" in value) {
|
|
44
|
-
throw new TypeError(`
|
|
54
|
+
throw new TypeError(`value is not instance of type. Type: ${value.constructor.name}`);
|
|
55
|
+
}
|
|
56
|
+
throw new TypeError(`value is not instance of type`);
|
|
57
|
+
}
|
|
58
|
+
function assertIsNumber(value) {
|
|
59
|
+
if (typeof value !== "number") {
|
|
60
|
+
throw new TypeError("value is not of type `number`");
|
|
45
61
|
}
|
|
46
|
-
|
|
62
|
+
}
|
|
63
|
+
function isObjectWithType(value) {
|
|
64
|
+
return typeof value === "object" && value !== null && "type" in value;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Type guard: narrows `value` to `Expression` when it is an object with a valid `type` property.
|
|
68
|
+
*/
|
|
69
|
+
function isExpression(value) {
|
|
70
|
+
return isObjectWithType(value) && _expressions_constants__rspack_import_1.EXPRESSION_TYPES.includes(value.type);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Type guard: narrows `value` to `OperatorExpression` when it is an object with `type === "operator"`.
|
|
74
|
+
*/
|
|
75
|
+
function isOperatorExpression(value) {
|
|
76
|
+
return isObjectWithType(value) && value.type === "operator";
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Type guard: narrows `value` to `ComparatorExpression` when it is an object with `type === "comparator"`.
|
|
80
|
+
*/
|
|
81
|
+
function isComparatorExpression(value) {
|
|
82
|
+
return isObjectWithType(value) && value.type === "comparator";
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Type guard: narrows `value` to `PropertyExpression` when it is an object with `type === "property"`.
|
|
86
|
+
*/
|
|
87
|
+
function isPropertyExpression(value) {
|
|
88
|
+
return isObjectWithType(value) && value.type === "property";
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type guard: narrows `value` to `ValueExpression` when it is an object with `type === "value"`.
|
|
92
|
+
*/
|
|
93
|
+
function isValueExpression(value) {
|
|
94
|
+
return isObjectWithType(value) && value.type === "value";
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Type guard: narrows `value` to `EmptyExpression` when it is an object with `type === "empty"`.
|
|
98
|
+
*/
|
|
99
|
+
function isEmptyExpression(value) {
|
|
100
|
+
return isObjectWithType(value) && value.type === "empty";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Type guard: narrows `value` to `NotParsableExpression` when it is an object with `type === "not-parsable"`.
|
|
104
|
+
*/
|
|
105
|
+
function isNotParsableExpression(value) {
|
|
106
|
+
return isObjectWithType(value) && value.type === "not-parsable";
|
|
47
107
|
}
|
|
48
108
|
|
|
49
109
|
|
|
110
|
+
},
|
|
111
|
+
"./src/expressions/constants.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
112
|
+
__webpack_require__.r(__webpack_exports__);
|
|
113
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
114
|
+
EXPRESSION_TYPES: () => (EXPRESSION_TYPES)
|
|
115
|
+
});
|
|
116
|
+
const EXPRESSION_TYPES = [
|
|
117
|
+
"operator",
|
|
118
|
+
"comparator",
|
|
119
|
+
"property",
|
|
120
|
+
"value",
|
|
121
|
+
"empty",
|
|
122
|
+
"not-parsable",
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
|
|
50
126
|
},
|
|
51
127
|
"./src/expressions/parser.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
52
128
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -600,9 +676,9 @@ const getComparator = (value) => {
|
|
|
600
676
|
};
|
|
601
677
|
const getValue = (value, params) => {
|
|
602
678
|
// Early return for string literals
|
|
603
|
-
if (value.startsWith("
|
|
679
|
+
if (value.startsWith("'") || value.startsWith("\"")) {
|
|
604
680
|
return new _types__rspack_import_0.ValueExpression({
|
|
605
|
-
value: value.replace(
|
|
681
|
+
value: value.replace(/"|'/g, "")
|
|
606
682
|
});
|
|
607
683
|
}
|
|
608
684
|
// Early return for null/undefined
|
|
@@ -635,7 +711,7 @@ const getValue = (value, params) => {
|
|
|
635
711
|
const paramValue = getValueFromParams(`${params.name}.${potentialParamPath}`, params);
|
|
636
712
|
return new _types__rspack_import_0.ValueExpression({ value: paramValue });
|
|
637
713
|
}
|
|
638
|
-
catch
|
|
714
|
+
catch {
|
|
639
715
|
// Not a parameter path, continue with normal parsing
|
|
640
716
|
}
|
|
641
717
|
}
|
|
@@ -722,7 +798,7 @@ const getProperty = (schema, value, params) => {
|
|
|
722
798
|
throw new Error(ERROR_MESSAGES.PROPERTY_NOT_FOUND(value));
|
|
723
799
|
}
|
|
724
800
|
}
|
|
725
|
-
catch
|
|
801
|
+
catch {
|
|
726
802
|
// Not a valid parameter path, continue to error
|
|
727
803
|
throw new Error(ERROR_MESSAGES.PROPERTY_NOT_FOUND(value));
|
|
728
804
|
}
|
|
@@ -760,6 +836,282 @@ const getProperty = (schema, value, params) => {
|
|
|
760
836
|
};
|
|
761
837
|
|
|
762
838
|
|
|
839
|
+
},
|
|
840
|
+
"./src/expressions/sql.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
841
|
+
__webpack_require__.r(__webpack_exports__);
|
|
842
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
843
|
+
getDialect: () => (getDialect),
|
|
844
|
+
toSql: () => (toSql)
|
|
845
|
+
});
|
|
846
|
+
/* import */ var _assertions__rspack_import_0 = __webpack_require__("./src/assertions/index.ts");
|
|
847
|
+
|
|
848
|
+
const DIALECTS = {
|
|
849
|
+
sqlite: {
|
|
850
|
+
quoteIdentifier(name) {
|
|
851
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
852
|
+
},
|
|
853
|
+
getPlaceholder(_i) {
|
|
854
|
+
return "?";
|
|
855
|
+
},
|
|
856
|
+
stringMatchKind: "GLOB",
|
|
857
|
+
likeEscapeClause() {
|
|
858
|
+
return "";
|
|
859
|
+
},
|
|
860
|
+
},
|
|
861
|
+
postgresql: {
|
|
862
|
+
quoteIdentifier(name) {
|
|
863
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
864
|
+
},
|
|
865
|
+
getPlaceholder(i) {
|
|
866
|
+
return `$${i + 1}`;
|
|
867
|
+
},
|
|
868
|
+
stringMatchKind: "LIKE",
|
|
869
|
+
likeEscapeClause() {
|
|
870
|
+
return " ESCAPE E'\\\\'";
|
|
871
|
+
},
|
|
872
|
+
},
|
|
873
|
+
mysql: {
|
|
874
|
+
quoteIdentifier(name) {
|
|
875
|
+
return "`" + name.replace(/`/g, "``") + "`";
|
|
876
|
+
},
|
|
877
|
+
getPlaceholder(_i) {
|
|
878
|
+
return "?";
|
|
879
|
+
},
|
|
880
|
+
stringMatchKind: "LIKE",
|
|
881
|
+
likeEscapeClause() {
|
|
882
|
+
return " ESCAPE '\\\\'";
|
|
883
|
+
},
|
|
884
|
+
},
|
|
885
|
+
mssql: {
|
|
886
|
+
quoteIdentifier(name) {
|
|
887
|
+
return "[" + name.replace(/]/g, "]]") + "]";
|
|
888
|
+
},
|
|
889
|
+
getPlaceholder(i) {
|
|
890
|
+
return `@p${i + 1}`;
|
|
891
|
+
},
|
|
892
|
+
stringMatchKind: "LIKE",
|
|
893
|
+
likeEscapeClause() {
|
|
894
|
+
return " ESCAPE '\\\\'";
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
};
|
|
898
|
+
function getDialect(name) {
|
|
899
|
+
const d = DIALECTS[name];
|
|
900
|
+
if (!d)
|
|
901
|
+
throw new Error(`Unknown SQL dialect: ${name}`);
|
|
902
|
+
return d;
|
|
903
|
+
}
|
|
904
|
+
function escapeLikeLiteral(value) {
|
|
905
|
+
return value.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
906
|
+
}
|
|
907
|
+
function escapeGlobLiteral(value) {
|
|
908
|
+
return value.replace(/\\/g, "\\\\").replace(/\*/g, "\\*").replace(/\?/g, "\\?");
|
|
909
|
+
}
|
|
910
|
+
function escapeForPattern(value, kind) {
|
|
911
|
+
return kind === "LIKE" ? escapeLikeLiteral(value) : escapeGlobLiteral(value);
|
|
912
|
+
}
|
|
913
|
+
function buildPattern(escapedValue, match, kind) {
|
|
914
|
+
if (kind === "LIKE") {
|
|
915
|
+
switch (match) {
|
|
916
|
+
case "contains":
|
|
917
|
+
return `%${escapedValue}%`;
|
|
918
|
+
case "starts-with":
|
|
919
|
+
return `${escapedValue}%`;
|
|
920
|
+
case "ends-with":
|
|
921
|
+
return `%${escapedValue}`;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
switch (match) {
|
|
925
|
+
case "contains":
|
|
926
|
+
return `*${escapedValue}*`;
|
|
927
|
+
case "starts-with":
|
|
928
|
+
return `${escapedValue}*`;
|
|
929
|
+
case "ends-with":
|
|
930
|
+
return `*${escapedValue}`;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function getPropertyValueSides(cmp) {
|
|
934
|
+
const propLeft = cmp.left && (0,_assertions__rspack_import_0.isPropertyExpression)(cmp.left) ? cmp.left : null;
|
|
935
|
+
const propRight = cmp.right && (0,_assertions__rspack_import_0.isPropertyExpression)(cmp.right) ? cmp.right : null;
|
|
936
|
+
const valLeft = cmp.left && (0,_assertions__rspack_import_0.isValueExpression)(cmp.left) ? cmp.left.value : null;
|
|
937
|
+
const valRight = cmp.right && (0,_assertions__rspack_import_0.isValueExpression)(cmp.right) ? cmp.right.value : null;
|
|
938
|
+
return { propLeft, propRight, valLeft, valRight };
|
|
939
|
+
}
|
|
940
|
+
function getEqualsCase(value, columnOnLeft, columnOnRight) {
|
|
941
|
+
if (value === null && columnOnLeft)
|
|
942
|
+
return "null-column-left";
|
|
943
|
+
if (value === null && columnOnRight)
|
|
944
|
+
return "null-column-right";
|
|
945
|
+
if (value !== null && columnOnLeft)
|
|
946
|
+
return "value-column-left";
|
|
947
|
+
if (value !== null && columnOnRight)
|
|
948
|
+
return "value-column-right";
|
|
949
|
+
return null;
|
|
950
|
+
}
|
|
951
|
+
function equalsNullColumnLeft(ctx) {
|
|
952
|
+
return ctx.negated ? `${ctx.col} IS NOT NULL` : `${ctx.col} IS NULL`;
|
|
953
|
+
}
|
|
954
|
+
function equalsNullColumnRight(ctx) {
|
|
955
|
+
ctx.params.push(null);
|
|
956
|
+
const ph = ctx.placeholder();
|
|
957
|
+
return ctx.negated ? `${ph} IS NOT NULL` : `${ph} IS NULL`;
|
|
958
|
+
}
|
|
959
|
+
function equalsValueColumnLeft(ctx) {
|
|
960
|
+
ctx.params.push(ctx.value);
|
|
961
|
+
const ph = ctx.placeholder();
|
|
962
|
+
return ctx.negated ? `${ctx.col} != ${ph}` : `${ctx.col} = ${ph}`;
|
|
963
|
+
}
|
|
964
|
+
function equalsValueColumnRight(ctx) {
|
|
965
|
+
ctx.params.push(ctx.value);
|
|
966
|
+
const ph = ctx.placeholder();
|
|
967
|
+
return ctx.negated ? `${ph} != ${ctx.col}` : `${ph} = ${ctx.col}`;
|
|
968
|
+
}
|
|
969
|
+
const EQUALS_STRATEGIES = {
|
|
970
|
+
"null-column-left": equalsNullColumnLeft,
|
|
971
|
+
"null-column-right": equalsNullColumnRight,
|
|
972
|
+
"value-column-left": equalsValueColumnLeft,
|
|
973
|
+
"value-column-right": equalsValueColumnRight,
|
|
974
|
+
};
|
|
975
|
+
// --- String-pattern comparison (includes / starts-with / ends-with) ---
|
|
976
|
+
function renderStringPatternComparison(cmp, d, params, placeholder) {
|
|
977
|
+
const { propLeft, propRight, valLeft, valRight } = getPropertyValueSides(cmp);
|
|
978
|
+
const kind = d.stringMatchKind;
|
|
979
|
+
if (cmp.comparator === "includes") {
|
|
980
|
+
const col = propLeft && valRight !== null
|
|
981
|
+
? d.quoteIdentifier(propLeft.property.name)
|
|
982
|
+
: propRight && valLeft !== null
|
|
983
|
+
? d.quoteIdentifier(propRight.property.name)
|
|
984
|
+
: null;
|
|
985
|
+
const value = valRight !== null ? valRight : valLeft;
|
|
986
|
+
if (col === null) {
|
|
987
|
+
throw new Error("Complex expressions not supported for includes operations");
|
|
988
|
+
}
|
|
989
|
+
if (Array.isArray(value)) {
|
|
990
|
+
const placeholders = value.map(() => placeholder()).join(", ");
|
|
991
|
+
params.push(...value);
|
|
992
|
+
return cmp.negated ? `${col} NOT IN (${placeholders})` : `${col} IN (${placeholders})`;
|
|
993
|
+
}
|
|
994
|
+
const escaped = escapeForPattern(String(value), kind);
|
|
995
|
+
const pattern = buildPattern(escaped, "contains", kind);
|
|
996
|
+
params.push(pattern);
|
|
997
|
+
const ph = placeholder();
|
|
998
|
+
const op = kind === "GLOB" ? "GLOB" : "LIKE";
|
|
999
|
+
const escape = kind === "LIKE" ? d.likeEscapeClause() : "";
|
|
1000
|
+
if (propLeft && valRight !== null) {
|
|
1001
|
+
return cmp.negated ? `${col} NOT ${op} ${ph}${escape}` : `${col} ${op} ${ph}${escape}`;
|
|
1002
|
+
}
|
|
1003
|
+
return cmp.negated ? `${ph} NOT ${op} ${col}${escape}` : `${ph} ${op} ${col}${escape}`;
|
|
1004
|
+
}
|
|
1005
|
+
const col = propLeft && valRight !== null
|
|
1006
|
+
? d.quoteIdentifier(propLeft.property.name)
|
|
1007
|
+
: propRight && valLeft !== null
|
|
1008
|
+
? d.quoteIdentifier(propRight.property.name)
|
|
1009
|
+
: null;
|
|
1010
|
+
const value = valRight !== null ? String(valRight) : valLeft !== null ? String(valLeft) : null;
|
|
1011
|
+
if (col === null || value === null) {
|
|
1012
|
+
throw new Error(`Complex expressions not supported for ${cmp.comparator} operations`);
|
|
1013
|
+
}
|
|
1014
|
+
const escaped = escapeForPattern(value, kind);
|
|
1015
|
+
const pattern = buildPattern(escaped, cmp.comparator === "starts-with" ? "starts-with" : "ends-with", kind);
|
|
1016
|
+
params.push(pattern);
|
|
1017
|
+
const ph = placeholder();
|
|
1018
|
+
const op = kind === "GLOB" ? "GLOB" : "LIKE";
|
|
1019
|
+
const escape = kind === "LIKE" ? d.likeEscapeClause() : "";
|
|
1020
|
+
if (propLeft && valRight !== null) {
|
|
1021
|
+
return cmp.negated ? `${col} NOT ${op} ${ph}${escape}` : `${col} ${op} ${ph}${escape}`;
|
|
1022
|
+
}
|
|
1023
|
+
return cmp.negated ? `${ph} NOT ${op} ${col}${escape}` : `${ph} ${op} ${col}${escape}`;
|
|
1024
|
+
}
|
|
1025
|
+
// --- Generic comparison ---
|
|
1026
|
+
function renderGenericComparison(cmp, walk) {
|
|
1027
|
+
const leftExpr = walk(cmp.left);
|
|
1028
|
+
const rightExpr = walk(cmp.right);
|
|
1029
|
+
switch (cmp.comparator) {
|
|
1030
|
+
case "equals":
|
|
1031
|
+
return cmp.negated ? `${leftExpr} != ${rightExpr}` : `${leftExpr} = ${rightExpr}`;
|
|
1032
|
+
case "greater-than":
|
|
1033
|
+
return cmp.negated ? `${leftExpr} <= ${rightExpr}` : `${leftExpr} > ${rightExpr}`;
|
|
1034
|
+
case "greater-than-equals":
|
|
1035
|
+
return cmp.negated ? `${leftExpr} < ${rightExpr}` : `${leftExpr} >= ${rightExpr}`;
|
|
1036
|
+
case "less-than":
|
|
1037
|
+
return cmp.negated ? `${leftExpr} >= ${rightExpr}` : `${leftExpr} < ${rightExpr}`;
|
|
1038
|
+
case "less-than-equals":
|
|
1039
|
+
return cmp.negated ? `${leftExpr} > ${rightExpr}` : `${leftExpr} <= ${rightExpr}`;
|
|
1040
|
+
default:
|
|
1041
|
+
throw new Error(`Unsupported comparator: ${cmp.comparator}`);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Converts an Expression to a SQL WHERE clause and bound parameters for the given dialect.
|
|
1046
|
+
*/
|
|
1047
|
+
function toSql(expr, dialect) {
|
|
1048
|
+
const d = typeof dialect === "string" ? getDialect(dialect) : dialect;
|
|
1049
|
+
const params = [];
|
|
1050
|
+
let paramIndex = 0;
|
|
1051
|
+
function placeholder() {
|
|
1052
|
+
const p = d.getPlaceholder(paramIndex);
|
|
1053
|
+
paramIndex += 1;
|
|
1054
|
+
return p;
|
|
1055
|
+
}
|
|
1056
|
+
/** Visitor: map each expression node type to a SQL fragment. */
|
|
1057
|
+
function walk(e) {
|
|
1058
|
+
if ((0,_assertions__rspack_import_0.isOperatorExpression)(e)) {
|
|
1059
|
+
const left = e.left ? walk(e.left) : "";
|
|
1060
|
+
const right = e.right ? walk(e.right) : "";
|
|
1061
|
+
const sqlOp = e.operator === "&&" ? "AND" : e.operator === "||" ? "OR" : e.operator;
|
|
1062
|
+
return `(${left} ${sqlOp} ${right})`;
|
|
1063
|
+
}
|
|
1064
|
+
if ((0,_assertions__rspack_import_0.isComparatorExpression)(e)) {
|
|
1065
|
+
const cmp = e;
|
|
1066
|
+
const isStringPattern = cmp.comparator === "starts-with" ||
|
|
1067
|
+
cmp.comparator === "ends-with" ||
|
|
1068
|
+
cmp.comparator === "includes";
|
|
1069
|
+
if (isStringPattern) {
|
|
1070
|
+
/* String pattern: includes / starts-with / ends-with → one renderer. */
|
|
1071
|
+
return renderStringPatternComparison(cmp, d, params, placeholder);
|
|
1072
|
+
}
|
|
1073
|
+
if (cmp.comparator === "equals") {
|
|
1074
|
+
/* Equals: Strategy per (column-side, null vs value) case. */
|
|
1075
|
+
const { propLeft, propRight, valLeft, valRight } = getPropertyValueSides(cmp);
|
|
1076
|
+
const col = propLeft && (valRight !== undefined || propRight)
|
|
1077
|
+
? d.quoteIdentifier(propLeft.property.name)
|
|
1078
|
+
: propRight && (valLeft !== undefined || propLeft)
|
|
1079
|
+
? d.quoteIdentifier(propRight.property.name)
|
|
1080
|
+
: null;
|
|
1081
|
+
const value = valRight !== undefined ? valRight : valLeft;
|
|
1082
|
+
const columnOnLeft = Boolean(propLeft && cmp.right && (0,_assertions__rspack_import_0.isValueExpression)(cmp.right));
|
|
1083
|
+
const columnOnRight = Boolean(propRight && cmp.left && (0,_assertions__rspack_import_0.isValueExpression)(cmp.left));
|
|
1084
|
+
if (col !== null && value !== undefined) {
|
|
1085
|
+
const caseKey = getEqualsCase(value, columnOnLeft, columnOnRight);
|
|
1086
|
+
if (caseKey !== null) {
|
|
1087
|
+
const strategy = EQUALS_STRATEGIES[caseKey];
|
|
1088
|
+
return strategy({
|
|
1089
|
+
col,
|
|
1090
|
+
value,
|
|
1091
|
+
negated: cmp.negated,
|
|
1092
|
+
params,
|
|
1093
|
+
placeholder,
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
/* Generic: walk both sides and emit comparison operator. */
|
|
1099
|
+
return renderGenericComparison(cmp, walk);
|
|
1100
|
+
}
|
|
1101
|
+
if ((0,_assertions__rspack_import_0.isPropertyExpression)(e)) {
|
|
1102
|
+
return d.quoteIdentifier(e.property.name);
|
|
1103
|
+
}
|
|
1104
|
+
if ((0,_assertions__rspack_import_0.isValueExpression)(e)) {
|
|
1105
|
+
params.push(e.value);
|
|
1106
|
+
return placeholder();
|
|
1107
|
+
}
|
|
1108
|
+
throw new Error(`Unknown expression type: ${e.type}`);
|
|
1109
|
+
}
|
|
1110
|
+
const where = walk(expr);
|
|
1111
|
+
return { where, params };
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
|
|
763
1115
|
},
|
|
764
1116
|
"./src/expressions/types.ts"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
765
1117
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -872,8 +1224,7 @@ class ValueExpression extends Expression {
|
|
|
872
1224
|
__webpack_require__.r(__webpack_exports__);
|
|
873
1225
|
__webpack_require__.d(__webpack_exports__, {
|
|
874
1226
|
forEach: () => (forEach),
|
|
875
|
-
getProperties: () => (getProperties)
|
|
876
|
-
isPropertyExpression: () => (isPropertyExpression)
|
|
1227
|
+
getProperties: () => (getProperties)
|
|
877
1228
|
});
|
|
878
1229
|
/**
|
|
879
1230
|
* Extracts all properties referenced in an expression
|
|
@@ -898,9 +1249,6 @@ function getProperties(expression) {
|
|
|
898
1249
|
traverse(expression);
|
|
899
1250
|
return properties;
|
|
900
1251
|
}
|
|
901
|
-
function isPropertyExpression(expression) {
|
|
902
|
-
return expression.type === "property";
|
|
903
|
-
}
|
|
904
1252
|
function forEach(expression, callback) {
|
|
905
1253
|
function traverse(expr) {
|
|
906
1254
|
// Call the callback for this expression
|
|
@@ -948,16 +1296,27 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
948
1296
|
__webpack_require__.d(__webpack_exports__, {
|
|
949
1297
|
logger: () => (logger)
|
|
950
1298
|
});
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1299
|
+
/**
|
|
1300
|
+
* Enable logging by setting `globalThis.__ROUTIER_DEBUG__ = true` before any routier code runs.
|
|
1301
|
+
*/
|
|
1302
|
+
const shouldLog = () => {
|
|
1303
|
+
if (typeof globalThis !== 'undefined') {
|
|
1304
|
+
const g = globalThis;
|
|
1305
|
+
if (g.__ROUTIER_DEBUG__ === true)
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
if (typeof process !== 'undefined' && process.env != null) {
|
|
1309
|
+
const debug = process.env.DEBUG;
|
|
1310
|
+
if (debug === 'routier' || debug === '*')
|
|
1311
|
+
return true;
|
|
1312
|
+
const env = "development"?.toLowerCase();
|
|
1313
|
+
if (env === 'dev' || env === 'development' || env === 'test')
|
|
1314
|
+
return true;
|
|
954
1315
|
}
|
|
955
|
-
|
|
956
|
-
return env === 'dev' || env === 'development' || env === 'test';
|
|
1316
|
+
return false;
|
|
957
1317
|
};
|
|
958
|
-
const shouldLog = isDevelopment();
|
|
959
1318
|
const tryLog = (type, ...args) => {
|
|
960
|
-
if (shouldLog) {
|
|
1319
|
+
if (shouldLog()) {
|
|
961
1320
|
console[type](...args);
|
|
962
1321
|
}
|
|
963
1322
|
};
|
|
@@ -1038,22 +1397,28 @@ var __webpack_exports__ = {};
|
|
|
1038
1397
|
(() => {
|
|
1039
1398
|
__webpack_require__.r(__webpack_exports__);
|
|
1040
1399
|
__webpack_require__.d(__webpack_exports__, {
|
|
1041
|
-
ComparatorExpression: () => (/* reexport safe */
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1400
|
+
ComparatorExpression: () => (/* reexport safe */ _types__rspack_import_2.ComparatorExpression),
|
|
1401
|
+
EXPRESSION_TYPES: () => (/* reexport safe */ _constants__rspack_import_4.EXPRESSION_TYPES),
|
|
1402
|
+
EmptyExpression: () => (/* reexport safe */ _types__rspack_import_2.EmptyExpression),
|
|
1403
|
+
Expression: () => (/* reexport safe */ _types__rspack_import_2.Expression),
|
|
1404
|
+
NotParsableExpression: () => (/* reexport safe */ _types__rspack_import_2.NotParsableExpression),
|
|
1405
|
+
OperatorExpression: () => (/* reexport safe */ _types__rspack_import_2.OperatorExpression),
|
|
1406
|
+
PropertyExpression: () => (/* reexport safe */ _types__rspack_import_2.PropertyExpression),
|
|
1407
|
+
ValueExpression: () => (/* reexport safe */ _types__rspack_import_2.ValueExpression),
|
|
1048
1408
|
combineExpressions: () => (/* reexport safe */ _parser__rspack_import_0.combineExpressions),
|
|
1049
|
-
forEach: () => (/* reexport safe */
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
toExpression: () => (/* reexport safe */ _parser__rspack_import_0.toExpression)
|
|
1409
|
+
forEach: () => (/* reexport safe */ _utils__rspack_import_3.forEach),
|
|
1410
|
+
getDialect: () => (/* reexport safe */ _sql__rspack_import_1.getDialect),
|
|
1411
|
+
getProperties: () => (/* reexport safe */ _utils__rspack_import_3.getProperties),
|
|
1412
|
+
toExpression: () => (/* reexport safe */ _parser__rspack_import_0.toExpression),
|
|
1413
|
+
toSql: () => (/* reexport safe */ _sql__rspack_import_1.toSql)
|
|
1053
1414
|
});
|
|
1054
1415
|
/* import */ var _parser__rspack_import_0 = __webpack_require__("./src/expressions/parser.ts");
|
|
1055
|
-
/* import */ var
|
|
1056
|
-
/* import */ var
|
|
1416
|
+
/* import */ var _sql__rspack_import_1 = __webpack_require__("./src/expressions/sql.ts");
|
|
1417
|
+
/* import */ var _types__rspack_import_2 = __webpack_require__("./src/expressions/types.ts");
|
|
1418
|
+
/* import */ var _utils__rspack_import_3 = __webpack_require__("./src/expressions/utils.ts");
|
|
1419
|
+
/* import */ var _constants__rspack_import_4 = __webpack_require__("./src/expressions/constants.ts");
|
|
1420
|
+
|
|
1421
|
+
|
|
1057
1422
|
|
|
1058
1423
|
|
|
1059
1424
|
|
|
@@ -1061,6 +1426,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
1061
1426
|
})();
|
|
1062
1427
|
|
|
1063
1428
|
var __webpack_exports__ComparatorExpression = __webpack_exports__.ComparatorExpression;
|
|
1429
|
+
var __webpack_exports__EXPRESSION_TYPES = __webpack_exports__.EXPRESSION_TYPES;
|
|
1064
1430
|
var __webpack_exports__EmptyExpression = __webpack_exports__.EmptyExpression;
|
|
1065
1431
|
var __webpack_exports__Expression = __webpack_exports__.Expression;
|
|
1066
1432
|
var __webpack_exports__NotParsableExpression = __webpack_exports__.NotParsableExpression;
|
|
@@ -1069,9 +1435,10 @@ var __webpack_exports__PropertyExpression = __webpack_exports__.PropertyExpressi
|
|
|
1069
1435
|
var __webpack_exports__ValueExpression = __webpack_exports__.ValueExpression;
|
|
1070
1436
|
var __webpack_exports__combineExpressions = __webpack_exports__.combineExpressions;
|
|
1071
1437
|
var __webpack_exports__forEach = __webpack_exports__.forEach;
|
|
1438
|
+
var __webpack_exports__getDialect = __webpack_exports__.getDialect;
|
|
1072
1439
|
var __webpack_exports__getProperties = __webpack_exports__.getProperties;
|
|
1073
|
-
var __webpack_exports__isPropertyExpression = __webpack_exports__.isPropertyExpression;
|
|
1074
1440
|
var __webpack_exports__toExpression = __webpack_exports__.toExpression;
|
|
1075
|
-
|
|
1441
|
+
var __webpack_exports__toSql = __webpack_exports__.toSql;
|
|
1442
|
+
export { __webpack_exports__ComparatorExpression as ComparatorExpression, __webpack_exports__EXPRESSION_TYPES as EXPRESSION_TYPES, __webpack_exports__EmptyExpression as EmptyExpression, __webpack_exports__Expression as Expression, __webpack_exports__NotParsableExpression as NotParsableExpression, __webpack_exports__OperatorExpression as OperatorExpression, __webpack_exports__PropertyExpression as PropertyExpression, __webpack_exports__ValueExpression as ValueExpression, __webpack_exports__combineExpressions as combineExpressions, __webpack_exports__forEach as forEach, __webpack_exports__getDialect as getDialect, __webpack_exports__getProperties as getProperties, __webpack_exports__toExpression as toExpression, __webpack_exports__toSql as toSql };
|
|
1076
1443
|
|
|
1077
1444
|
//# sourceMappingURL=index.js.map
|