@tanstack/eslint-plugin-router 1.66.1 → 1.70.0
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/cjs/rules/create-route-property-order/constants.cjs +9 -2
- package/dist/cjs/rules/create-route-property-order/constants.cjs.map +1 -1
- package/dist/cjs/rules/create-route-property-order/constants.d.cts +3 -2
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs +4 -0
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs.map +1 -1
- package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.d.cts +1 -0
- package/dist/esm/rules/create-route-property-order/constants.d.ts +3 -2
- package/dist/esm/rules/create-route-property-order/constants.js +9 -2
- package/dist/esm/rules/create-route-property-order/constants.js.map +1 -1
- package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.d.ts +1 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.js +4 -0
- package/dist/esm/rules/create-route-property-order/create-route-property-order.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/create-route-property-order.rule.test.ts +17 -4
- package/src/__tests__/create-route-property-order.utils.test.ts +101 -1
- package/src/rules/create-route-property-order/constants.ts +11 -10
- package/src/rules/create-route-property-order/create-route-property-order.utils.ts +6 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createRoutePropertyOrder_utils = require("./create-route-property-order.utils.cjs");
|
|
3
4
|
const createRouteFunctionsIndirect = [
|
|
4
5
|
"createFileRoute",
|
|
5
6
|
"createRootRouteWithContext"
|
|
@@ -13,11 +14,17 @@ const createRouteFunctions = [
|
|
|
13
14
|
...createRouteFunctionsIndirect
|
|
14
15
|
];
|
|
15
16
|
const sortRules = [
|
|
16
|
-
[["params", "validateSearch"], ["
|
|
17
|
+
[["params", "validateSearch"], ["search"]],
|
|
18
|
+
[["search"], ["loaderDeps"]],
|
|
17
19
|
[["loaderDeps"], ["context"]],
|
|
18
20
|
[["context"], ["beforeLoad"]],
|
|
19
|
-
[["beforeLoad"], ["loader"]]
|
|
21
|
+
[["beforeLoad"], ["loader"]],
|
|
22
|
+
[
|
|
23
|
+
["loader"],
|
|
24
|
+
["onEnter", "onStay", "onLeave", "meta", "links", "scripts", "headers"]
|
|
25
|
+
]
|
|
20
26
|
];
|
|
27
|
+
createRoutePropertyOrder_utils.getCheckedProperties(sortRules);
|
|
21
28
|
exports.createRouteFunctions = createRouteFunctions;
|
|
22
29
|
exports.createRouteFunctionsDirect = createRouteFunctionsDirect;
|
|
23
30
|
exports.createRouteFunctionsIndirect = createRouteFunctionsIndirect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sources":["../../../../src/rules/create-route-property-order/constants.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../../../src/rules/create-route-property-order/constants.ts"],"sourcesContent":["import { getCheckedProperties } from './create-route-property-order.utils'\n\nexport const createRouteFunctionsIndirect = [\n 'createFileRoute',\n 'createRootRouteWithContext',\n] as const\nexport const createRouteFunctionsDirect = [\n 'createRootRoute',\n 'createRoute',\n] as const\n\nexport const createRouteFunctions = [\n ...createRouteFunctionsDirect,\n ...createRouteFunctionsIndirect,\n] as const\n\nexport type CreateRouteFunction = (typeof createRouteFunctions)[number]\n\nexport const sortRules = [\n [['params', 'validateSearch'], ['search']],\n [['search'], ['loaderDeps']],\n [['loaderDeps'], ['context']],\n [['context'], ['beforeLoad']],\n [['beforeLoad'], ['loader']],\n [\n ['loader'],\n ['onEnter', 'onStay', 'onLeave', 'meta', 'links', 'scripts', 'headers'],\n ],\n] as const\n\nexport type CheckedProperties = (typeof sortRules)[number][number][number]\nexport const checkedProperties = getCheckedProperties(sortRules)\n"],"names":["getCheckedProperties"],"mappings":";;;AAEO,MAAM,+BAA+B;AAAA,EAC1C;AAAA,EACA;AACF;AACO,MAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AACF;AAEO,MAAM,uBAAuB;AAAA,EAClC,GAAG;AAAA,EACH,GAAG;AACL;AAIO,MAAM,YAAY;AAAA,EACvB,CAAC,CAAC,UAAU,gBAAgB,GAAG,CAAC,QAAQ,CAAC;AAAA,EACzC,CAAC,CAAC,QAAQ,GAAG,CAAC,YAAY,CAAC;AAAA,EAC3B,CAAC,CAAC,YAAY,GAAG,CAAC,SAAS,CAAC;AAAA,EAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,YAAY,CAAC;AAAA,EAC5B,CAAC,CAAC,YAAY,GAAG,CAAC,QAAQ,CAAC;AAAA,EAC3B;AAAA,IACE,CAAC,QAAQ;AAAA,IACT,CAAC,WAAW,UAAU,WAAW,QAAQ,SAAS,WAAW,SAAS;AAAA,EACxE;AACF;AAGiCA,+BAAAA,qBAAqB,SAAS;;;;;"}
|
|
@@ -2,5 +2,6 @@ export declare const createRouteFunctionsIndirect: readonly ["createFileRoute",
|
|
|
2
2
|
export declare const createRouteFunctionsDirect: readonly ["createRootRoute", "createRoute"];
|
|
3
3
|
export declare const createRouteFunctions: readonly ["createRootRoute", "createRoute", "createFileRoute", "createRootRouteWithContext"];
|
|
4
4
|
export type CreateRouteFunction = (typeof createRouteFunctions)[number];
|
|
5
|
-
export declare const
|
|
6
|
-
export
|
|
5
|
+
export declare const sortRules: readonly [readonly [readonly ["params", "validateSearch"], readonly ["search"]], readonly [readonly ["search"], readonly ["loaderDeps"]], readonly [readonly ["loaderDeps"], readonly ["context"]], readonly [readonly ["context"], readonly ["beforeLoad"]], readonly [readonly ["beforeLoad"], readonly ["loader"]], readonly [readonly ["loader"], readonly ["onEnter", "onStay", "onLeave", "meta", "links", "scripts", "headers"]]];
|
|
6
|
+
export type CheckedProperties = (typeof sortRules)[number][number][number];
|
|
7
|
+
export declare const checkedProperties: readonly ("meta" | "search" | "params" | "validateSearch" | "loaderDeps" | "context" | "beforeLoad" | "loader" | "onEnter" | "onStay" | "onLeave" | "links" | "scripts" | "headers")[];
|
|
@@ -43,5 +43,9 @@ function sortDataByOrder(data, orderRules, key) {
|
|
|
43
43
|
}
|
|
44
44
|
return result;
|
|
45
45
|
}
|
|
46
|
+
function getCheckedProperties(orderRules) {
|
|
47
|
+
return [...new Set(orderRules.flat(2))];
|
|
48
|
+
}
|
|
49
|
+
exports.getCheckedProperties = getCheckedProperties;
|
|
46
50
|
exports.sortDataByOrder = sortDataByOrder;
|
|
47
51
|
//# sourceMappingURL=create-route-property-order.utils.cjs.map
|
package/dist/cjs/rules/create-route-property-order/create-route-property-order.utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-route-property-order.utils.cjs","sources":["../../../../src/rules/create-route-property-order/create-route-property-order.utils.ts"],"sourcesContent":["export function sortDataByOrder<T, TKey extends keyof T>(\n data: Array<T> | ReadonlyArray<T>,\n orderRules: ReadonlyArray<\n Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>\n >,\n key: TKey,\n): Array<T> | null {\n const getSubsetIndex = (\n item: T[TKey],\n subsets: ReadonlyArray<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n ): number | null => {\n for (let i = 0; i < subsets.length; i++) {\n if (subsets[i]?.includes(item)) {\n return i\n }\n }\n return null\n }\n\n const orderSets = orderRules.reduce(\n (sets, [A, B]) => [...sets, A, B],\n [] as Array<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n )\n\n const inOrderArray = data.filter(\n (item) => getSubsetIndex(item[key], orderSets) !== null,\n )\n\n let wasResorted = false as boolean\n\n // Sort by the relative order defined by the rules\n const sortedArray = inOrderArray.sort((a, b) => {\n const aKey = a[key],\n bKey = b[key]\n const aSubsetIndex = getSubsetIndex(aKey, orderSets)\n const bSubsetIndex = getSubsetIndex(bKey, orderSets)\n\n // If both items belong to different subsets, sort by their subset order\n if (\n aSubsetIndex !== null &&\n bSubsetIndex !== null &&\n aSubsetIndex !== bSubsetIndex\n ) {\n return aSubsetIndex - bSubsetIndex\n }\n\n // If both items belong to the same subset or neither is in the subset, keep their relative order\n return 0\n })\n\n const inOrderIterator = sortedArray.values()\n const result = data.map((item) => {\n if (getSubsetIndex(item[key], orderSets) !== null) {\n const sortedItem = inOrderIterator.next().value!\n if (sortedItem[key] !== item[key]) {\n wasResorted = true\n }\n return sortedItem\n }\n return item\n })\n\n if (!wasResorted) {\n return null\n }\n return result\n}\n"],"names":[],"mappings":";;AAAgB,SAAA,gBACd,MACA,YAGA,KACiB;AACX,QAAA,iBAAiB,CACrB,MACA,YACkB;;AAClB,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,WAAI,aAAQ,CAAC,MAAT,mBAAY,SAAS,OAAO;AACvB,eAAA;AAAA,MACT;AAAA,IACF;AACO,WAAA;AAAA,EAAA;AAGT,QAAM,YAAY,WAAW;AAAA,IAC3B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,IAChC,CAAC;AAAA,EAAA;AAGH,QAAM,eAAe,KAAK;AAAA,IACxB,CAAC,SAAS,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM;AAAA,EAAA;AAGrD,MAAI,cAAc;AAGlB,QAAM,cAAc,aAAa,KAAK,CAAC,GAAG,MAAM;AAC9C,UAAM,OAAO,EAAE,GAAG,GAChB,OAAO,EAAE,GAAG;AACR,UAAA,eAAe,eAAe,MAAM,SAAS;AAC7C,UAAA,eAAe,eAAe,MAAM,SAAS;AAGnD,QACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,cACjB;AACA,aAAO,eAAe;AAAA,IACxB;AAGO,WAAA;AAAA,EAAA,CACR;AAEK,QAAA,kBAAkB,YAAY;AACpC,QAAM,SAAS,KAAK,IAAI,CAAC,SAAS;AAChC,QAAI,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM,MAAM;AAC3C,YAAA,aAAa,gBAAgB,KAAA,EAAO;AAC1C,UAAI,WAAW,GAAG,MAAM,KAAK,GAAG,GAAG;AACnB,sBAAA;AAAA,MAChB;AACO,aAAA;AAAA,IACT;AACO,WAAA;AAAA,EAAA,CACR;AAED,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,EACT;AACO,SAAA;AACT
|
|
1
|
+
{"version":3,"file":"create-route-property-order.utils.cjs","sources":["../../../../src/rules/create-route-property-order/create-route-property-order.utils.ts"],"sourcesContent":["export function sortDataByOrder<T, TKey extends keyof T>(\n data: Array<T> | ReadonlyArray<T>,\n orderRules: ReadonlyArray<\n Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>\n >,\n key: TKey,\n): Array<T> | null {\n const getSubsetIndex = (\n item: T[TKey],\n subsets: ReadonlyArray<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n ): number | null => {\n for (let i = 0; i < subsets.length; i++) {\n if (subsets[i]?.includes(item)) {\n return i\n }\n }\n return null\n }\n\n const orderSets = orderRules.reduce(\n (sets, [A, B]) => [...sets, A, B],\n [] as Array<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n )\n\n const inOrderArray = data.filter(\n (item) => getSubsetIndex(item[key], orderSets) !== null,\n )\n\n let wasResorted = false as boolean\n\n // Sort by the relative order defined by the rules\n const sortedArray = inOrderArray.sort((a, b) => {\n const aKey = a[key],\n bKey = b[key]\n const aSubsetIndex = getSubsetIndex(aKey, orderSets)\n const bSubsetIndex = getSubsetIndex(bKey, orderSets)\n\n // If both items belong to different subsets, sort by their subset order\n if (\n aSubsetIndex !== null &&\n bSubsetIndex !== null &&\n aSubsetIndex !== bSubsetIndex\n ) {\n return aSubsetIndex - bSubsetIndex\n }\n\n // If both items belong to the same subset or neither is in the subset, keep their relative order\n return 0\n })\n\n const inOrderIterator = sortedArray.values()\n const result = data.map((item) => {\n if (getSubsetIndex(item[key], orderSets) !== null) {\n const sortedItem = inOrderIterator.next().value!\n if (sortedItem[key] !== item[key]) {\n wasResorted = true\n }\n return sortedItem\n }\n return item\n })\n\n if (!wasResorted) {\n return null\n }\n return result\n}\n\nexport function getCheckedProperties<T>(\n orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>,\n): ReadonlyArray<T> {\n return [...new Set<T>(orderRules.flat(2))]\n}\n"],"names":[],"mappings":";;AAAgB,SAAA,gBACd,MACA,YAGA,KACiB;AACX,QAAA,iBAAiB,CACrB,MACA,YACkB;;AAClB,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,WAAI,aAAQ,CAAC,MAAT,mBAAY,SAAS,OAAO;AACvB,eAAA;AAAA,MACT;AAAA,IACF;AACO,WAAA;AAAA,EAAA;AAGT,QAAM,YAAY,WAAW;AAAA,IAC3B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,IAChC,CAAC;AAAA,EAAA;AAGH,QAAM,eAAe,KAAK;AAAA,IACxB,CAAC,SAAS,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM;AAAA,EAAA;AAGrD,MAAI,cAAc;AAGlB,QAAM,cAAc,aAAa,KAAK,CAAC,GAAG,MAAM;AAC9C,UAAM,OAAO,EAAE,GAAG,GAChB,OAAO,EAAE,GAAG;AACR,UAAA,eAAe,eAAe,MAAM,SAAS;AAC7C,UAAA,eAAe,eAAe,MAAM,SAAS;AAGnD,QACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,cACjB;AACA,aAAO,eAAe;AAAA,IACxB;AAGO,WAAA;AAAA,EAAA,CACR;AAEK,QAAA,kBAAkB,YAAY;AACpC,QAAM,SAAS,KAAK,IAAI,CAAC,SAAS;AAChC,QAAI,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM,MAAM;AAC3C,YAAA,aAAa,gBAAgB,KAAA,EAAO;AAC1C,UAAI,WAAW,GAAG,MAAM,KAAK,GAAG,GAAG;AACnB,sBAAA;AAAA,MAChB;AACO,aAAA;AAAA,IACT;AACO,WAAA;AAAA,EAAA,CACR;AAED,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEO,SAAS,qBACd,YACkB;AACX,SAAA,CAAC,GAAG,IAAI,IAAO,WAAW,KAAK,CAAC,CAAC,CAAC;AAC3C;;;"}
|
|
@@ -1 +1,2 @@
|
|
|
1
1
|
export declare function sortDataByOrder<T, TKey extends keyof T>(data: Array<T> | ReadonlyArray<T>, orderRules: ReadonlyArray<Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>>, key: TKey): Array<T> | null;
|
|
2
|
+
export declare function getCheckedProperties<T>(orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>): ReadonlyArray<T>;
|
|
@@ -2,5 +2,6 @@ export declare const createRouteFunctionsIndirect: readonly ["createFileRoute",
|
|
|
2
2
|
export declare const createRouteFunctionsDirect: readonly ["createRootRoute", "createRoute"];
|
|
3
3
|
export declare const createRouteFunctions: readonly ["createRootRoute", "createRoute", "createFileRoute", "createRootRouteWithContext"];
|
|
4
4
|
export type CreateRouteFunction = (typeof createRouteFunctions)[number];
|
|
5
|
-
export declare const
|
|
6
|
-
export
|
|
5
|
+
export declare const sortRules: readonly [readonly [readonly ["params", "validateSearch"], readonly ["search"]], readonly [readonly ["search"], readonly ["loaderDeps"]], readonly [readonly ["loaderDeps"], readonly ["context"]], readonly [readonly ["context"], readonly ["beforeLoad"]], readonly [readonly ["beforeLoad"], readonly ["loader"]], readonly [readonly ["loader"], readonly ["onEnter", "onStay", "onLeave", "meta", "links", "scripts", "headers"]]];
|
|
6
|
+
export type CheckedProperties = (typeof sortRules)[number][number][number];
|
|
7
|
+
export declare const checkedProperties: readonly ("meta" | "search" | "params" | "validateSearch" | "loaderDeps" | "context" | "beforeLoad" | "loader" | "onEnter" | "onStay" | "onLeave" | "links" | "scripts" | "headers")[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getCheckedProperties } from "./create-route-property-order.utils.js";
|
|
1
2
|
const createRouteFunctionsIndirect = [
|
|
2
3
|
"createFileRoute",
|
|
3
4
|
"createRootRouteWithContext"
|
|
@@ -11,11 +12,17 @@ const createRouteFunctions = [
|
|
|
11
12
|
...createRouteFunctionsIndirect
|
|
12
13
|
];
|
|
13
14
|
const sortRules = [
|
|
14
|
-
[["params", "validateSearch"], ["
|
|
15
|
+
[["params", "validateSearch"], ["search"]],
|
|
16
|
+
[["search"], ["loaderDeps"]],
|
|
15
17
|
[["loaderDeps"], ["context"]],
|
|
16
18
|
[["context"], ["beforeLoad"]],
|
|
17
|
-
[["beforeLoad"], ["loader"]]
|
|
19
|
+
[["beforeLoad"], ["loader"]],
|
|
20
|
+
[
|
|
21
|
+
["loader"],
|
|
22
|
+
["onEnter", "onStay", "onLeave", "meta", "links", "scripts", "headers"]
|
|
23
|
+
]
|
|
18
24
|
];
|
|
25
|
+
getCheckedProperties(sortRules);
|
|
19
26
|
export {
|
|
20
27
|
createRouteFunctions,
|
|
21
28
|
createRouteFunctionsDirect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/rules/create-route-property-order/constants.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/rules/create-route-property-order/constants.ts"],"sourcesContent":["import { getCheckedProperties } from './create-route-property-order.utils'\n\nexport const createRouteFunctionsIndirect = [\n 'createFileRoute',\n 'createRootRouteWithContext',\n] as const\nexport const createRouteFunctionsDirect = [\n 'createRootRoute',\n 'createRoute',\n] as const\n\nexport const createRouteFunctions = [\n ...createRouteFunctionsDirect,\n ...createRouteFunctionsIndirect,\n] as const\n\nexport type CreateRouteFunction = (typeof createRouteFunctions)[number]\n\nexport const sortRules = [\n [['params', 'validateSearch'], ['search']],\n [['search'], ['loaderDeps']],\n [['loaderDeps'], ['context']],\n [['context'], ['beforeLoad']],\n [['beforeLoad'], ['loader']],\n [\n ['loader'],\n ['onEnter', 'onStay', 'onLeave', 'meta', 'links', 'scripts', 'headers'],\n ],\n] as const\n\nexport type CheckedProperties = (typeof sortRules)[number][number][number]\nexport const checkedProperties = getCheckedProperties(sortRules)\n"],"names":[],"mappings":";AAEO,MAAM,+BAA+B;AAAA,EAC1C;AAAA,EACA;AACF;AACO,MAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AACF;AAEO,MAAM,uBAAuB;AAAA,EAClC,GAAG;AAAA,EACH,GAAG;AACL;AAIO,MAAM,YAAY;AAAA,EACvB,CAAC,CAAC,UAAU,gBAAgB,GAAG,CAAC,QAAQ,CAAC;AAAA,EACzC,CAAC,CAAC,QAAQ,GAAG,CAAC,YAAY,CAAC;AAAA,EAC3B,CAAC,CAAC,YAAY,GAAG,CAAC,SAAS,CAAC;AAAA,EAC5B,CAAC,CAAC,SAAS,GAAG,CAAC,YAAY,CAAC;AAAA,EAC5B,CAAC,CAAC,YAAY,GAAG,CAAC,QAAQ,CAAC;AAAA,EAC3B;AAAA,IACE,CAAC,QAAQ;AAAA,IACT,CAAC,WAAW,UAAU,WAAW,QAAQ,SAAS,WAAW,SAAS;AAAA,EACxE;AACF;AAGiC,qBAAqB,SAAS;"}
|
|
@@ -1 +1,2 @@
|
|
|
1
1
|
export declare function sortDataByOrder<T, TKey extends keyof T>(data: Array<T> | ReadonlyArray<T>, orderRules: ReadonlyArray<Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>>, key: TKey): Array<T> | null;
|
|
2
|
+
export declare function getCheckedProperties<T>(orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>): ReadonlyArray<T>;
|
|
@@ -41,7 +41,11 @@ function sortDataByOrder(data, orderRules, key) {
|
|
|
41
41
|
}
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
|
+
function getCheckedProperties(orderRules) {
|
|
45
|
+
return [...new Set(orderRules.flat(2))];
|
|
46
|
+
}
|
|
44
47
|
export {
|
|
48
|
+
getCheckedProperties,
|
|
45
49
|
sortDataByOrder
|
|
46
50
|
};
|
|
47
51
|
//# sourceMappingURL=create-route-property-order.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-route-property-order.utils.js","sources":["../../../../src/rules/create-route-property-order/create-route-property-order.utils.ts"],"sourcesContent":["export function sortDataByOrder<T, TKey extends keyof T>(\n data: Array<T> | ReadonlyArray<T>,\n orderRules: ReadonlyArray<\n Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>\n >,\n key: TKey,\n): Array<T> | null {\n const getSubsetIndex = (\n item: T[TKey],\n subsets: ReadonlyArray<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n ): number | null => {\n for (let i = 0; i < subsets.length; i++) {\n if (subsets[i]?.includes(item)) {\n return i\n }\n }\n return null\n }\n\n const orderSets = orderRules.reduce(\n (sets, [A, B]) => [...sets, A, B],\n [] as Array<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n )\n\n const inOrderArray = data.filter(\n (item) => getSubsetIndex(item[key], orderSets) !== null,\n )\n\n let wasResorted = false as boolean\n\n // Sort by the relative order defined by the rules\n const sortedArray = inOrderArray.sort((a, b) => {\n const aKey = a[key],\n bKey = b[key]\n const aSubsetIndex = getSubsetIndex(aKey, orderSets)\n const bSubsetIndex = getSubsetIndex(bKey, orderSets)\n\n // If both items belong to different subsets, sort by their subset order\n if (\n aSubsetIndex !== null &&\n bSubsetIndex !== null &&\n aSubsetIndex !== bSubsetIndex\n ) {\n return aSubsetIndex - bSubsetIndex\n }\n\n // If both items belong to the same subset or neither is in the subset, keep their relative order\n return 0\n })\n\n const inOrderIterator = sortedArray.values()\n const result = data.map((item) => {\n if (getSubsetIndex(item[key], orderSets) !== null) {\n const sortedItem = inOrderIterator.next().value!\n if (sortedItem[key] !== item[key]) {\n wasResorted = true\n }\n return sortedItem\n }\n return item\n })\n\n if (!wasResorted) {\n return null\n }\n return result\n}\n"],"names":[],"mappings":"AAAgB,SAAA,gBACd,MACA,YAGA,KACiB;AACX,QAAA,iBAAiB,CACrB,MACA,YACkB;AAVN;AAWZ,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,WAAI,aAAQ,CAAC,MAAT,mBAAY,SAAS,OAAO;AACvB,eAAA;AAAA,MACT;AAAA,IACF;AACO,WAAA;AAAA,EAAA;AAGT,QAAM,YAAY,WAAW;AAAA,IAC3B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,IAChC,CAAC;AAAA,EAAA;AAGH,QAAM,eAAe,KAAK;AAAA,IACxB,CAAC,SAAS,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM;AAAA,EAAA;AAGrD,MAAI,cAAc;AAGlB,QAAM,cAAc,aAAa,KAAK,CAAC,GAAG,MAAM;AAC9C,UAAM,OAAO,EAAE,GAAG,GAChB,OAAO,EAAE,GAAG;AACR,UAAA,eAAe,eAAe,MAAM,SAAS;AAC7C,UAAA,eAAe,eAAe,MAAM,SAAS;AAGnD,QACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,cACjB;AACA,aAAO,eAAe;AAAA,IACxB;AAGO,WAAA;AAAA,EAAA,CACR;AAEK,QAAA,kBAAkB,YAAY;AACpC,QAAM,SAAS,KAAK,IAAI,CAAC,SAAS;AAChC,QAAI,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM,MAAM;AAC3C,YAAA,aAAa,gBAAgB,KAAA,EAAO;AAC1C,UAAI,WAAW,GAAG,MAAM,KAAK,GAAG,GAAG;AACnB,sBAAA;AAAA,MAChB;AACO,aAAA;AAAA,IACT;AACO,WAAA;AAAA,EAAA,CACR;AAED,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,EACT;AACO,SAAA;AACT;"}
|
|
1
|
+
{"version":3,"file":"create-route-property-order.utils.js","sources":["../../../../src/rules/create-route-property-order/create-route-property-order.utils.ts"],"sourcesContent":["export function sortDataByOrder<T, TKey extends keyof T>(\n data: Array<T> | ReadonlyArray<T>,\n orderRules: ReadonlyArray<\n Readonly<[ReadonlyArray<T[TKey]>, ReadonlyArray<T[TKey]>]>\n >,\n key: TKey,\n): Array<T> | null {\n const getSubsetIndex = (\n item: T[TKey],\n subsets: ReadonlyArray<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n ): number | null => {\n for (let i = 0; i < subsets.length; i++) {\n if (subsets[i]?.includes(item)) {\n return i\n }\n }\n return null\n }\n\n const orderSets = orderRules.reduce(\n (sets, [A, B]) => [...sets, A, B],\n [] as Array<ReadonlyArray<T[TKey]> | Array<T[TKey]>>,\n )\n\n const inOrderArray = data.filter(\n (item) => getSubsetIndex(item[key], orderSets) !== null,\n )\n\n let wasResorted = false as boolean\n\n // Sort by the relative order defined by the rules\n const sortedArray = inOrderArray.sort((a, b) => {\n const aKey = a[key],\n bKey = b[key]\n const aSubsetIndex = getSubsetIndex(aKey, orderSets)\n const bSubsetIndex = getSubsetIndex(bKey, orderSets)\n\n // If both items belong to different subsets, sort by their subset order\n if (\n aSubsetIndex !== null &&\n bSubsetIndex !== null &&\n aSubsetIndex !== bSubsetIndex\n ) {\n return aSubsetIndex - bSubsetIndex\n }\n\n // If both items belong to the same subset or neither is in the subset, keep their relative order\n return 0\n })\n\n const inOrderIterator = sortedArray.values()\n const result = data.map((item) => {\n if (getSubsetIndex(item[key], orderSets) !== null) {\n const sortedItem = inOrderIterator.next().value!\n if (sortedItem[key] !== item[key]) {\n wasResorted = true\n }\n return sortedItem\n }\n return item\n })\n\n if (!wasResorted) {\n return null\n }\n return result\n}\n\nexport function getCheckedProperties<T>(\n orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>,\n): ReadonlyArray<T> {\n return [...new Set<T>(orderRules.flat(2))]\n}\n"],"names":[],"mappings":"AAAgB,SAAA,gBACd,MACA,YAGA,KACiB;AACX,QAAA,iBAAiB,CACrB,MACA,YACkB;AAVN;AAWZ,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,WAAI,aAAQ,CAAC,MAAT,mBAAY,SAAS,OAAO;AACvB,eAAA;AAAA,MACT;AAAA,IACF;AACO,WAAA;AAAA,EAAA;AAGT,QAAM,YAAY,WAAW;AAAA,IAC3B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC;AAAA,IAChC,CAAC;AAAA,EAAA;AAGH,QAAM,eAAe,KAAK;AAAA,IACxB,CAAC,SAAS,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM;AAAA,EAAA;AAGrD,MAAI,cAAc;AAGlB,QAAM,cAAc,aAAa,KAAK,CAAC,GAAG,MAAM;AAC9C,UAAM,OAAO,EAAE,GAAG,GAChB,OAAO,EAAE,GAAG;AACR,UAAA,eAAe,eAAe,MAAM,SAAS;AAC7C,UAAA,eAAe,eAAe,MAAM,SAAS;AAGnD,QACE,iBAAiB,QACjB,iBAAiB,QACjB,iBAAiB,cACjB;AACA,aAAO,eAAe;AAAA,IACxB;AAGO,WAAA;AAAA,EAAA,CACR;AAEK,QAAA,kBAAkB,YAAY;AACpC,QAAM,SAAS,KAAK,IAAI,CAAC,SAAS;AAChC,QAAI,eAAe,KAAK,GAAG,GAAG,SAAS,MAAM,MAAM;AAC3C,YAAA,aAAa,gBAAgB,KAAA,EAAO;AAC1C,UAAI,WAAW,GAAG,MAAM,KAAK,GAAG,GAAG;AACnB,sBAAA;AAAA,MAChB;AACO,aAAA;AAAA,IACT;AACO,WAAA;AAAA,EAAA,CACR;AAED,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEO,SAAS,qBACd,YACkB;AACX,SAAA,CAAC,GAAG,IAAI,IAAO,WAAW,KAAK,CAAC,CAAC,CAAC;AAC3C;"}
|
package/package.json
CHANGED
|
@@ -21,10 +21,10 @@ const ruleTester = new RuleTester()
|
|
|
21
21
|
|
|
22
22
|
// reduce the number of test cases by only testing a subset of the checked properties
|
|
23
23
|
const testedCheckedProperties = [
|
|
24
|
-
checkedProperties[0]
|
|
25
|
-
checkedProperties[1]
|
|
26
|
-
checkedProperties[2]
|
|
27
|
-
checkedProperties[3]
|
|
24
|
+
checkedProperties[0]!,
|
|
25
|
+
checkedProperties[1]!,
|
|
26
|
+
checkedProperties[2]!,
|
|
27
|
+
checkedProperties[3]!,
|
|
28
28
|
]
|
|
29
29
|
type TestedCheckedProperties = (typeof testedCheckedProperties)[number]
|
|
30
30
|
const orderIndependentProps = ['gcTime', '...foo'] as const
|
|
@@ -165,6 +165,19 @@ const validTestCases = validTestMatrix.map(
|
|
|
165
165
|
}),
|
|
166
166
|
)
|
|
167
167
|
|
|
168
|
+
invalidTestMatrix.push({
|
|
169
|
+
createRouteFunction: 'createFileRoute',
|
|
170
|
+
properties: {
|
|
171
|
+
invalid: ['loader', 'loaderDeps'],
|
|
172
|
+
valid: ['loaderDeps', 'loader'],
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
invalidTestMatrix.push({
|
|
177
|
+
createRouteFunction: 'createFileRoute',
|
|
178
|
+
properties: { invalid: ['meta', 'loader'], valid: ['loader', 'meta'] },
|
|
179
|
+
})
|
|
180
|
+
|
|
168
181
|
const invalidTestCases = invalidTestMatrix.map(
|
|
169
182
|
({ createRouteFunction, properties }) => ({
|
|
170
183
|
name: `incorrect property order is detected for ${createRouteFunction} with order: ${properties.invalid.join(', ')}`,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getCheckedProperties,
|
|
4
|
+
sortDataByOrder,
|
|
5
|
+
} from '../rules/create-route-property-order/create-route-property-order.utils'
|
|
3
6
|
|
|
4
7
|
describe('create-route-property-order utils', () => {
|
|
5
8
|
describe('sortDataByOrder', () => {
|
|
@@ -67,6 +70,63 @@ describe('create-route-property-order utils', () => {
|
|
|
67
70
|
key: 'key',
|
|
68
71
|
expected: [{ key: 'd' }, { key: 'a' }, { key: 'b' }, { key: 'c' }],
|
|
69
72
|
},
|
|
73
|
+
{
|
|
74
|
+
data: [{ key: 'd' }, { key: 'b' }, { key: 'a' }, { key: 'c' }],
|
|
75
|
+
orderArray: [
|
|
76
|
+
[['a', 'b'], ['d']],
|
|
77
|
+
[['d'], ['c']],
|
|
78
|
+
],
|
|
79
|
+
key: 'key',
|
|
80
|
+
expected: [{ key: 'b' }, { key: 'a' }, { key: 'd' }, { key: 'c' }],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
data: [
|
|
84
|
+
{ key: 'd' },
|
|
85
|
+
{ key: 'b' },
|
|
86
|
+
{ key: 'a' },
|
|
87
|
+
{ key: 'c' },
|
|
88
|
+
{ key: 'f' },
|
|
89
|
+
],
|
|
90
|
+
orderArray: [
|
|
91
|
+
[
|
|
92
|
+
['a', 'b'],
|
|
93
|
+
['d', 'f'],
|
|
94
|
+
],
|
|
95
|
+
[['d'], ['c']],
|
|
96
|
+
],
|
|
97
|
+
key: 'key',
|
|
98
|
+
expected: [
|
|
99
|
+
{ key: 'b' },
|
|
100
|
+
{ key: 'a' },
|
|
101
|
+
{ key: 'd' },
|
|
102
|
+
{ key: 'f' },
|
|
103
|
+
{ key: 'c' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
data: [
|
|
108
|
+
{ key: 'd' },
|
|
109
|
+
{ key: 'b' },
|
|
110
|
+
{ key: 'a' },
|
|
111
|
+
{ key: 'c' },
|
|
112
|
+
{ key: 'f' },
|
|
113
|
+
],
|
|
114
|
+
orderArray: [
|
|
115
|
+
[
|
|
116
|
+
['a', 'b'],
|
|
117
|
+
['d', 'f'],
|
|
118
|
+
],
|
|
119
|
+
[['d', 'f'], ['c']],
|
|
120
|
+
],
|
|
121
|
+
key: 'key',
|
|
122
|
+
expected: [
|
|
123
|
+
{ key: 'b' },
|
|
124
|
+
{ key: 'a' },
|
|
125
|
+
{ key: 'd' },
|
|
126
|
+
{ key: 'f' },
|
|
127
|
+
{ key: 'c' },
|
|
128
|
+
],
|
|
129
|
+
},
|
|
70
130
|
] as const
|
|
71
131
|
test.each(testCases)(
|
|
72
132
|
'$data $orderArray $key $expected',
|
|
@@ -77,3 +137,43 @@ describe('create-route-property-order utils', () => {
|
|
|
77
137
|
)
|
|
78
138
|
})
|
|
79
139
|
})
|
|
140
|
+
|
|
141
|
+
describe('getCheckedProperties', () => {
|
|
142
|
+
const testCases = [
|
|
143
|
+
{
|
|
144
|
+
orderRules: [
|
|
145
|
+
[['a', 'b'], ['c']],
|
|
146
|
+
[['c'], ['d']],
|
|
147
|
+
],
|
|
148
|
+
expected: ['a', 'b', 'c', 'd'],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
orderRules: [
|
|
152
|
+
[['a', 'b'], ['c']],
|
|
153
|
+
[['d'], ['e']],
|
|
154
|
+
],
|
|
155
|
+
expected: ['a', 'b', 'c', 'd', 'e'],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
orderRules: [
|
|
159
|
+
[['a', 'b'], ['c']],
|
|
160
|
+
[['d'], ['e']],
|
|
161
|
+
[['c'], ['f']],
|
|
162
|
+
],
|
|
163
|
+
expected: ['a', 'b', 'c', 'd', 'e', 'f'],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
orderRules: [
|
|
167
|
+
[['a', 'b'], ['c']],
|
|
168
|
+
[['d'], ['e']],
|
|
169
|
+
[['c'], ['f']],
|
|
170
|
+
[['f'], ['g']],
|
|
171
|
+
],
|
|
172
|
+
expected: ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
|
173
|
+
},
|
|
174
|
+
] as const
|
|
175
|
+
test.each(testCases)('$orderRules $expected', ({ orderRules, expected }) => {
|
|
176
|
+
const checkedProperties = getCheckedProperties(orderRules)
|
|
177
|
+
expect(checkedProperties).toEqual(expected)
|
|
178
|
+
})
|
|
179
|
+
})
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getCheckedProperties } from './create-route-property-order.utils'
|
|
2
|
+
|
|
1
3
|
export const createRouteFunctionsIndirect = [
|
|
2
4
|
'createFileRoute',
|
|
3
5
|
'createRootRouteWithContext',
|
|
@@ -14,18 +16,17 @@ export const createRouteFunctions = [
|
|
|
14
16
|
|
|
15
17
|
export type CreateRouteFunction = (typeof createRouteFunctions)[number]
|
|
16
18
|
|
|
17
|
-
export const checkedProperties = [
|
|
18
|
-
'params',
|
|
19
|
-
'validateSearch',
|
|
20
|
-
'loaderDeps',
|
|
21
|
-
'context',
|
|
22
|
-
'beforeLoad',
|
|
23
|
-
'loader',
|
|
24
|
-
] as const
|
|
25
|
-
|
|
26
19
|
export const sortRules = [
|
|
27
|
-
[['params', 'validateSearch'], ['
|
|
20
|
+
[['params', 'validateSearch'], ['search']],
|
|
21
|
+
[['search'], ['loaderDeps']],
|
|
28
22
|
[['loaderDeps'], ['context']],
|
|
29
23
|
[['context'], ['beforeLoad']],
|
|
30
24
|
[['beforeLoad'], ['loader']],
|
|
25
|
+
[
|
|
26
|
+
['loader'],
|
|
27
|
+
['onEnter', 'onStay', 'onLeave', 'meta', 'links', 'scripts', 'headers'],
|
|
28
|
+
],
|
|
31
29
|
] as const
|
|
30
|
+
|
|
31
|
+
export type CheckedProperties = (typeof sortRules)[number][number][number]
|
|
32
|
+
export const checkedProperties = getCheckedProperties(sortRules)
|
|
@@ -65,3 +65,9 @@ export function sortDataByOrder<T, TKey extends keyof T>(
|
|
|
65
65
|
}
|
|
66
66
|
return result
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
export function getCheckedProperties<T>(
|
|
70
|
+
orderRules: ReadonlyArray<ReadonlyArray<ReadonlyArray<T>>>,
|
|
71
|
+
): ReadonlyArray<T> {
|
|
72
|
+
return [...new Set<T>(orderRules.flat(2))]
|
|
73
|
+
}
|