@hamur/i18n 0.0.2 → 0.0.4

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/src/cli.js CHANGED
@@ -961,6 +961,7 @@ import { relative } from "path";
961
961
  import {
962
962
  DiagnosticError as DiagnosticError4,
963
963
  addAppPlugin,
964
+ addRouteRules,
964
965
  addRouteMiddleware,
965
966
  addTemplate,
966
967
  createResolver,
@@ -968,6 +969,77 @@ import {
968
969
  extendPages,
969
970
  useLogger
970
971
  } from "hamur/kit";
972
+
973
+ // packages/i18n/src/build/access.ts
974
+ import { createRouteRules } from "hamur/kit";
975
+ var KEYS = ["basicAuth", "ipRestriction"];
976
+ function accessOf(value) {
977
+ const access = {};
978
+ for (const key of KEYS) {
979
+ const found = Array.isArray(value) ? value.find((entry) => entry[key] !== undefined)?.[key] : value?.[key];
980
+ if (found !== undefined)
981
+ Object.assign(access, { [key]: found });
982
+ }
983
+ return access;
984
+ }
985
+ var prefixed = (code, path) => `/${code}${path === "/" ? "" : path}`;
986
+ var flatten2 = (records) => records.flatMap((record) => [record, ...flatten2(record.children)]);
987
+ function localeAccessRules(rules, originals, table, defaultLocale) {
988
+ const picked = Object.entries(rules).flatMap(([key, value]) => {
989
+ const access = accessOf(value);
990
+ return Object.keys(access).length ? [[key, access]] : [];
991
+ });
992
+ const out = {};
993
+ if (!picked.length)
994
+ return out;
995
+ const add = (key, access) => {
996
+ const own = accessOf(rules[key]);
997
+ for (const name of KEYS)
998
+ if (access[name] !== undefined && own[name] === undefined && out[key]?.[name] === undefined)
999
+ Object.assign(out[key] ??= {}, { [name]: access[name] });
1000
+ };
1001
+ const split = (key) => ({ method: key.slice(0, key.indexOf("/")), path: key.slice(key.indexOf("/")) });
1002
+ for (const [key, access] of picked) {
1003
+ const { method, path } = split(key);
1004
+ for (const code of table.copies)
1005
+ add(`${method}${prefixed(code, path)}`, access);
1006
+ }
1007
+ const records = flatten2(originals);
1008
+ const own = (path, code, localized) => localized === path || localized === prefixed(code, path);
1009
+ const lists = [table.routes, table.aliases ?? {}];
1010
+ const compiled = createRouteRules(Object.fromEntries(picked));
1011
+ for (const record of records) {
1012
+ const access = accessOf(compiled.match(record.path).rule);
1013
+ if (!Object.keys(access).length)
1014
+ continue;
1015
+ for (const list of lists)
1016
+ for (const [code, localized] of Object.entries(list[record.name] ?? {}))
1017
+ if (!table.missing?.[record.name]?.includes(code) && !own(record.path, code, localized))
1018
+ add(localized, access);
1019
+ }
1020
+ const source = createMatcher({
1021
+ copies: [],
1022
+ routes: Object.fromEntries(records.map((record) => [record.name, { [defaultLocale]: record.path }]))
1023
+ });
1024
+ const builders = lists.map((routes) => createMatcher({ copies: [], routes }));
1025
+ for (const [key, access] of picked) {
1026
+ const { method, path } = split(key);
1027
+ const found = /[:*]/.test(path) ? undefined : source.matchPath(path);
1028
+ if (!found)
1029
+ continue;
1030
+ for (const [index, builder] of builders.entries())
1031
+ for (const code of Object.keys(lists[index][found.name] ?? {})) {
1032
+ if (table.missing?.[found.name]?.includes(code))
1033
+ continue;
1034
+ const localized = builder.buildPath(found.name, code, found.params);
1035
+ if (!own(path, code, localized))
1036
+ add(`${method}${localized}`, access);
1037
+ }
1038
+ }
1039
+ return out;
1040
+ }
1041
+
1042
+ // packages/i18n/src/build/routes.ts
971
1043
  var SEPARATOR = "___";
972
1044
  function paramsOf(segments) {
973
1045
  return segments.flatMap((segment) => {
@@ -989,12 +1061,12 @@ function shapeOf(path) {
989
1061
  });
990
1062
  return `/${parts.join("/")}`;
991
1063
  }
992
- function flatten2(records, ancestors = []) {
993
- return records.flatMap((record) => [...flatten2(record.children, [...ancestors, record.name]), { record, ancestors }]);
1064
+ function flatten3(records, ancestors = []) {
1065
+ return records.flatMap((record) => [...flatten3(record.children, [...ancestors, record.name]), { record, ancestors }]);
994
1066
  }
995
1067
  function tableOf(records, options, copies) {
996
1068
  const table = { copies, routes: {}, aliases: {} };
997
- for (const { record } of flatten2(records)) {
1069
+ for (const { record } of flatten3(records)) {
998
1070
  const index = record.name.indexOf(SEPARATOR);
999
1071
  const base = index === -1 ? record.name : record.name.slice(0, index);
1000
1072
  const code = index === -1 ? options.defaultLocale : record.name.slice(index + SEPARATOR.length);
@@ -1007,7 +1079,7 @@ function localizeRoutes(routes, options, rootDir = "") {
1007
1079
  if (options.strategy === "no_prefix")
1008
1080
  return { routes, table: tableOf(routes, options, []) };
1009
1081
  const shown = (file) => rootDir ? relative(rootDir, file) : file;
1010
- const originals = flatten2(routes);
1082
+ const originals = flatten3(routes);
1011
1083
  for (const { record } of originals) {
1012
1084
  if (record.name.includes(SEPARATOR))
1013
1085
  throw new DiagnosticError4("HAMUR_E5816", `i18n: route name "${record.name}" (${shown(record.file)}) contains "___", which route copies use`);
@@ -1068,7 +1140,7 @@ function localizeRoutes(routes, options, rootDir = "") {
1068
1140
  return true;
1069
1141
  if (!differs(record, code))
1070
1142
  return false;
1071
- const paths = flatten2([copy(record, code)]).map((entry) => entry.record.path).join(`
1143
+ const paths = flatten3([copy(record, code)]).map((entry) => entry.record.path).join(`
1072
1144
  `);
1073
1145
  let seen = made.get(record);
1074
1146
  if (!seen)
@@ -1099,7 +1171,7 @@ function localizeRoutes(routes, options, rootDir = "") {
1099
1171
  }
1100
1172
  }
1101
1173
  }
1102
- const all = flatten2(result);
1174
+ const all = flatten3(result);
1103
1175
  const seen = new Map;
1104
1176
  for (const entry of [
1105
1177
  ...all.filter((item) => !item.record.name.includes(SEPARATOR)),
@@ -1123,11 +1195,18 @@ var PRERENDER_WARNING = 'i18n: "/" is prerendered, so detect.redirect "root" nev
1123
1195
  function setupRoutes(options, hamur) {
1124
1196
  const r = createResolver(new URL("../../src/build/routes.ts", import.meta.url).href);
1125
1197
  let table = { copies: [], routes: {} };
1198
+ let made = new Set;
1126
1199
  extendPages((routes) => {
1200
+ const originals = [...routes];
1127
1201
  const localized = localizeRoutes(routes, options, hamur.options.rootDir);
1128
1202
  routes.splice(0, routes.length, ...localized.routes);
1129
1203
  table = localized.table;
1130
1204
  rememberRouteTable(hamur, table);
1205
+ const own = Object.fromEntries(Object.entries(hamur.routeRules).filter(([key]) => !made.has(key)));
1206
+ const access = localeAccessRules(own, originals, table, options.defaultLocale);
1207
+ made = new Set(Object.keys(access));
1208
+ if (made.size)
1209
+ addRouteRules(access);
1131
1210
  });
1132
1211
  const exports = (values) => Object.entries(values).map(([name, value]) => `export const ${name} = ${JSON.stringify(value) ?? "undefined"};
1133
1212
  `).join("");
@@ -1406,6 +1485,7 @@ export const routes = import.meta.server ? {} : ` + routes + `;
1406
1485
  throw: false
1407
1486
  };
1408
1487
  delete probe.outdir;
1488
+ delete probe.minChunkSize;
1409
1489
  const result = await Bun.build(probe);
1410
1490
  if (!result.success)
1411
1491
  return;
package/dist/src/index.js CHANGED
@@ -1524,6 +1524,7 @@ import { relative as relative2 } from "node:path";
1524
1524
  import {
1525
1525
  DiagnosticError as DiagnosticError5,
1526
1526
  addAppPlugin,
1527
+ addRouteRules,
1527
1528
  addRouteMiddleware,
1528
1529
  addTemplate as addTemplate2,
1529
1530
  createResolver as createResolver2,
@@ -1817,6 +1818,75 @@ function createMatcher(table) {
1817
1818
  };
1818
1819
  }
1819
1820
 
1821
+ // packages/i18n/src/build/access.ts
1822
+ import { createRouteRules } from "hamur/kit";
1823
+ var KEYS = ["basicAuth", "ipRestriction"];
1824
+ function accessOf(value) {
1825
+ const access = {};
1826
+ for (const key of KEYS) {
1827
+ const found = Array.isArray(value) ? value.find((entry) => entry[key] !== undefined)?.[key] : value?.[key];
1828
+ if (found !== undefined)
1829
+ Object.assign(access, { [key]: found });
1830
+ }
1831
+ return access;
1832
+ }
1833
+ var prefixed = (code, path) => `/${code}${path === "/" ? "" : path}`;
1834
+ var flatten = (records) => records.flatMap((record) => [record, ...flatten(record.children)]);
1835
+ function localeAccessRules(rules, originals, table, defaultLocale) {
1836
+ const picked = Object.entries(rules).flatMap(([key, value]) => {
1837
+ const access = accessOf(value);
1838
+ return Object.keys(access).length ? [[key, access]] : [];
1839
+ });
1840
+ const out = {};
1841
+ if (!picked.length)
1842
+ return out;
1843
+ const add = (key, access) => {
1844
+ const own = accessOf(rules[key]);
1845
+ for (const name of KEYS)
1846
+ if (access[name] !== undefined && own[name] === undefined && out[key]?.[name] === undefined)
1847
+ Object.assign(out[key] ??= {}, { [name]: access[name] });
1848
+ };
1849
+ const split = (key) => ({ method: key.slice(0, key.indexOf("/")), path: key.slice(key.indexOf("/")) });
1850
+ for (const [key, access] of picked) {
1851
+ const { method, path } = split(key);
1852
+ for (const code of table.copies)
1853
+ add(`${method}${prefixed(code, path)}`, access);
1854
+ }
1855
+ const records = flatten(originals);
1856
+ const own = (path, code, localized) => localized === path || localized === prefixed(code, path);
1857
+ const lists = [table.routes, table.aliases ?? {}];
1858
+ const compiled = createRouteRules(Object.fromEntries(picked));
1859
+ for (const record of records) {
1860
+ const access = accessOf(compiled.match(record.path).rule);
1861
+ if (!Object.keys(access).length)
1862
+ continue;
1863
+ for (const list of lists)
1864
+ for (const [code, localized] of Object.entries(list[record.name] ?? {}))
1865
+ if (!table.missing?.[record.name]?.includes(code) && !own(record.path, code, localized))
1866
+ add(localized, access);
1867
+ }
1868
+ const source = createMatcher({
1869
+ copies: [],
1870
+ routes: Object.fromEntries(records.map((record) => [record.name, { [defaultLocale]: record.path }]))
1871
+ });
1872
+ const builders = lists.map((routes) => createMatcher({ copies: [], routes }));
1873
+ for (const [key, access] of picked) {
1874
+ const { method, path } = split(key);
1875
+ const found = /[:*]/.test(path) ? undefined : source.matchPath(path);
1876
+ if (!found)
1877
+ continue;
1878
+ for (const [index, builder] of builders.entries())
1879
+ for (const code of Object.keys(lists[index][found.name] ?? {})) {
1880
+ if (table.missing?.[found.name]?.includes(code))
1881
+ continue;
1882
+ const localized = builder.buildPath(found.name, code, found.params);
1883
+ if (!own(path, code, localized))
1884
+ add(`${method}${localized}`, access);
1885
+ }
1886
+ }
1887
+ return out;
1888
+ }
1889
+
1820
1890
  // packages/i18n/src/build/routes.ts
1821
1891
  var SEPARATOR = "___";
1822
1892
  function paramsOf2(segments) {
@@ -1839,12 +1909,12 @@ function shapeOf(path) {
1839
1909
  });
1840
1910
  return `/${parts.join("/")}`;
1841
1911
  }
1842
- function flatten(records, ancestors = []) {
1843
- return records.flatMap((record) => [...flatten(record.children, [...ancestors, record.name]), { record, ancestors }]);
1912
+ function flatten2(records, ancestors = []) {
1913
+ return records.flatMap((record) => [...flatten2(record.children, [...ancestors, record.name]), { record, ancestors }]);
1844
1914
  }
1845
1915
  function tableOf(records, options, copies) {
1846
1916
  const table = { copies, routes: {}, aliases: {} };
1847
- for (const { record } of flatten(records)) {
1917
+ for (const { record } of flatten2(records)) {
1848
1918
  const index = record.name.indexOf(SEPARATOR);
1849
1919
  const base = index === -1 ? record.name : record.name.slice(0, index);
1850
1920
  const code = index === -1 ? options.defaultLocale : record.name.slice(index + SEPARATOR.length);
@@ -1857,7 +1927,7 @@ function localizeRoutes(routes, options, rootDir = "") {
1857
1927
  if (options.strategy === "no_prefix")
1858
1928
  return { routes, table: tableOf(routes, options, []) };
1859
1929
  const shown = (file) => rootDir ? relative2(rootDir, file) : file;
1860
- const originals = flatten(routes);
1930
+ const originals = flatten2(routes);
1861
1931
  for (const { record } of originals) {
1862
1932
  if (record.name.includes(SEPARATOR))
1863
1933
  throw new DiagnosticError5("HAMUR_E5816", `i18n: route name "${record.name}" (${shown(record.file)}) contains "___", which route copies use`);
@@ -1918,7 +1988,7 @@ function localizeRoutes(routes, options, rootDir = "") {
1918
1988
  return true;
1919
1989
  if (!differs(record, code))
1920
1990
  return false;
1921
- const paths = flatten([copy(record, code)]).map((entry) => entry.record.path).join(`
1991
+ const paths = flatten2([copy(record, code)]).map((entry) => entry.record.path).join(`
1922
1992
  `);
1923
1993
  let seen = made.get(record);
1924
1994
  if (!seen)
@@ -1949,7 +2019,7 @@ function localizeRoutes(routes, options, rootDir = "") {
1949
2019
  }
1950
2020
  }
1951
2021
  }
1952
- const all = flatten(result);
2022
+ const all = flatten2(result);
1953
2023
  const seen = new Map;
1954
2024
  for (const entry of [
1955
2025
  ...all.filter((item) => !item.record.name.includes(SEPARATOR)),
@@ -1973,11 +2043,18 @@ var PRERENDER_WARNING = 'i18n: "/" is prerendered, so detect.redirect "root" nev
1973
2043
  function setupRoutes(options, hamur) {
1974
2044
  const r = createResolver2(new URL("../../src/build/routes.ts", import.meta.url).href);
1975
2045
  let table = { copies: [], routes: {} };
2046
+ let made = new Set;
1976
2047
  extendPages((routes) => {
2048
+ const originals = [...routes];
1977
2049
  const localized = localizeRoutes(routes, options, hamur.options.rootDir);
1978
2050
  routes.splice(0, routes.length, ...localized.routes);
1979
2051
  table = localized.table;
1980
2052
  rememberRouteTable(hamur, table);
2053
+ const own = Object.fromEntries(Object.entries(hamur.routeRules).filter(([key]) => !made.has(key)));
2054
+ const access = localeAccessRules(own, originals, table, options.defaultLocale);
2055
+ made = new Set(Object.keys(access));
2056
+ if (made.size)
2057
+ addRouteRules(access);
1981
2058
  });
1982
2059
  const exports = (values) => Object.entries(values).map(([name, value]) => `export const ${name} = ${JSON.stringify(value) ?? "undefined"};
1983
2060
  `).join("");
@@ -2172,15 +2249,15 @@ function createSplitReader(roots) {
2172
2249
  }
2173
2250
  };
2174
2251
  }
2175
- function flatten2(records, ancestors = []) {
2252
+ function flatten3(records, ancestors = []) {
2176
2253
  return records.flatMap((record) => [
2177
2254
  { record, chain: [...ancestors, record] },
2178
- ...flatten2(record.children, [...ancestors, record])
2255
+ ...flatten3(record.children, [...ancestors, record])
2179
2256
  ]);
2180
2257
  }
2181
2258
  var slotFiles = (record) => Object.values(record.slots ?? {}).flatMap((slot) => [
2182
2259
  ...slot.default ? [slot.default] : [],
2183
- ...flatten2(slot.routes).map((entry) => entry.record.file)
2260
+ ...flatten3(slot.routes).map((entry) => entry.record.file)
2184
2261
  ]);
2185
2262
  var filesOf = (chain) => chain.flatMap((record) => [
2186
2263
  record.file,
@@ -2208,7 +2285,7 @@ async function planSplit(hamur) {
2208
2285
  ];
2209
2286
  const shared = await reader.read(sharedFiles);
2210
2287
  const routes = new Map;
2211
- for (const { record, chain } of flatten2(hamur.routes)) {
2288
+ for (const { record, chain } of flatten3(hamur.routes)) {
2212
2289
  const base = baseOf(record.name);
2213
2290
  if (routes.has(base))
2214
2291
  continue;
@@ -2482,6 +2559,7 @@ export const routes = import.meta.server ? {} : ` + routes + `;
2482
2559
  throw: false
2483
2560
  };
2484
2561
  delete probe.outdir;
2562
+ delete probe.minChunkSize;
2485
2563
  const result = await Bun.build(probe);
2486
2564
  if (!result.success)
2487
2565
  return;
@@ -0,0 +1,8 @@
1
+ import { type HamurContext, type RouteRecord, type RouteRule } from "hamur/kit";
2
+ import { type RouteTable } from "../runtime/match.ts";
3
+ /**
4
+ * The `basicAuth` and `ipRestriction` rules of each locale's address of a page, from the rules of its own path: a rule on `/admin`
5
+ * also holds for `/de/admin`, the default locale's `/en/admin` and a path of `i18n.pages` such as `/de/verwaltung`. A key that
6
+ * sets the rule itself keeps its own.
7
+ */
8
+ export declare function localeAccessRules(rules: HamurContext["routeRules"], originals: RouteRecord[], table: RouteTable, defaultLocale: string): Record<string, RouteRule>;
@@ -158,6 +158,6 @@ declare module "hamur" {
158
158
  declare module "hamur/app" {
159
159
  interface HamurLinkProps {
160
160
  /** The locale of the link's path, the page's by default; `false` keeps `to` as written. */
161
- locale?: HamurLocale | false;
161
+ locale?: import("@hamur/i18n").HamurLocale | false;
162
162
  }
163
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamur/i18n",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -94,14 +94,14 @@
94
94
  ],
95
95
  "dependencies": {},
96
96
  "peerDependencies": {
97
- "hamur": "^0.0.2",
98
- "@hamur/adapter-react": "^0.0.2",
99
- "@hamur/adapter-vue": "^0.0.2",
100
- "@hamur/adapter-preact": "^0.0.2",
101
- "@hamur/adapter-svelte": "^0.0.2",
102
- "@hamur/adapter-solid": "^0.0.2",
103
- "@hamur/adapter-html": "^0.0.2",
104
- "@hamur/adapter-angular": "^0.0.2",
97
+ "hamur": ">=0.0.4 <0.1.0",
98
+ "@hamur/adapter-react": ">=0.0.4 <0.1.0",
99
+ "@hamur/adapter-vue": ">=0.0.4 <0.1.0",
100
+ "@hamur/adapter-preact": ">=0.0.4 <0.1.0",
101
+ "@hamur/adapter-svelte": ">=0.0.4 <0.1.0",
102
+ "@hamur/adapter-solid": ">=0.0.4 <0.1.0",
103
+ "@hamur/adapter-html": ">=0.0.4 <0.1.0",
104
+ "@hamur/adapter-angular": ">=0.0.4 <0.1.0",
105
105
  "react": "^19.3.1",
106
106
  "preact": "^11.0.2",
107
107
  "vue": "^3.5.44",
@@ -14,6 +14,10 @@ const container = {
14
14
  childNodes: [],
15
15
  }
16
16
  const settle = () => new Promise((resolve) => setTimeout(resolve, 30))
17
+ const rendered = async (count: number) => {
18
+ for (const end = Date.now() + 5000; texts.length < count && Date.now() < end;) await settle()
19
+ await settle()
20
+ }
17
21
  const context = (route: typeof routes.fr, runtime: unknown = i18n) =>
18
22
  ({
19
23
  url: new URL(`http://localhost${route.path}`),
@@ -31,13 +35,13 @@ if (process.argv[2] === "set-locale") {
31
35
  async () => void (await update(context(routes.about, runtime))),
32
36
  )
33
37
  await mount(context(routes.about, runtime))
34
- await settle()
38
+ await rendered(1)
35
39
  await runtime.setLocale("fr")
36
- await settle()
40
+ await rendered(2)
37
41
  } else {
38
42
  await mount(context(routes.fr))
39
- await settle()
43
+ await rendered(1)
40
44
  await update(context(routes.home))
41
- await settle()
45
+ await rendered(2)
42
46
  }
43
47
  console.log(JSON.stringify({ mounts: mounts.length, texts }))
@@ -0,0 +1,81 @@
1
+ import { createRouteRules, type HamurContext, type RouteRecord, type RouteRule } from "hamur/kit"
2
+ import { createMatcher, type RouteTable } from "../runtime/match.ts"
3
+
4
+ const KEYS = ["basicAuth", "ipRestriction"] as const
5
+
6
+ type Access = Pick<RouteRule, (typeof KEYS)[number]>
7
+
8
+ function accessOf(value: HamurContext["routeRules"][string] | undefined): Access {
9
+ const access: Access = {}
10
+ for (const key of KEYS) {
11
+ const found = Array.isArray(value) ? value.find((entry) => entry[key] !== undefined)?.[key] : value?.[key]
12
+ if (found !== undefined) Object.assign(access, { [key]: found })
13
+ }
14
+ return access
15
+ }
16
+
17
+ const prefixed = (code: string, path: string) => `/${code}${path === "/" ? "" : path}`
18
+
19
+ const flatten = (records: RouteRecord[]): RouteRecord[] =>
20
+ records.flatMap((record) => [record, ...flatten(record.children)])
21
+
22
+ /**
23
+ * The `basicAuth` and `ipRestriction` rules of each locale's address of a page, from the rules of its own path: a rule on `/admin`
24
+ * also holds for `/de/admin`, the default locale's `/en/admin` and a path of `i18n.pages` such as `/de/verwaltung`. A key that
25
+ * sets the rule itself keeps its own.
26
+ */
27
+ export function localeAccessRules(
28
+ rules: HamurContext["routeRules"],
29
+ originals: RouteRecord[],
30
+ table: RouteTable,
31
+ defaultLocale: string,
32
+ ): Record<string, RouteRule> {
33
+ const picked = Object.entries(rules).flatMap(([key, value]) => {
34
+ const access = accessOf(value)
35
+ return Object.keys(access).length ? [[key, access] as const] : []
36
+ })
37
+ const out: Record<string, RouteRule> = {}
38
+ if (!picked.length) return out
39
+ const add = (key: string, access: Access) => {
40
+ const own = accessOf(rules[key])
41
+ for (const name of KEYS)
42
+ if (access[name] !== undefined && own[name] === undefined && out[key]?.[name] === undefined)
43
+ Object.assign((out[key] ??= {}), { [name]: access[name] })
44
+ }
45
+ const split = (key: string) => ({ method: key.slice(0, key.indexOf("/")), path: key.slice(key.indexOf("/")) })
46
+ for (const [key, access] of picked) {
47
+ const { method, path } = split(key)
48
+ for (const code of table.copies) add(`${method}${prefixed(code, path)}`, access)
49
+ }
50
+
51
+ const records = flatten(originals)
52
+ const own = (path: string, code: string, localized: string) =>
53
+ localized === path || localized === prefixed(code, path)
54
+ const lists = [table.routes, table.aliases ?? {}]
55
+ const compiled = createRouteRules(Object.fromEntries(picked))
56
+ for (const record of records) {
57
+ const access = accessOf(compiled.match(record.path).rule)
58
+ if (!Object.keys(access).length) continue
59
+ for (const list of lists)
60
+ for (const [code, localized] of Object.entries(list[record.name] ?? {}))
61
+ if (!table.missing?.[record.name]?.includes(code) && !own(record.path, code, localized)) add(localized, access)
62
+ }
63
+
64
+ const source = createMatcher({
65
+ copies: [],
66
+ routes: Object.fromEntries(records.map((record) => [record.name, { [defaultLocale]: record.path }])),
67
+ })
68
+ const builders = lists.map((routes) => createMatcher({ copies: [], routes }))
69
+ for (const [key, access] of picked) {
70
+ const { method, path } = split(key)
71
+ const found = /[:*]/.test(path) ? undefined : source.matchPath(path)
72
+ if (!found) continue
73
+ for (const [index, builder] of builders.entries())
74
+ for (const code of Object.keys(lists[index]![found.name] ?? {})) {
75
+ if (table.missing?.[found.name]?.includes(code)) continue
76
+ const localized = builder.buildPath(found.name, code, found.params)
77
+ if (!own(path, code, localized)) add(`${method}${localized}`, access)
78
+ }
79
+ }
80
+ return out
81
+ }
@@ -292,6 +292,7 @@ export const setupMessages: I18nSetup = async (options: ResolvedI18nOptions, ham
292
292
  throw: false,
293
293
  }
294
294
  delete probe.outdir
295
+ delete probe.minChunkSize
295
296
  const result = await Bun.build(probe)
296
297
  if (!result.success) return
297
298
  inputs = Object.keys(result.metafile?.inputs ?? {})
@@ -2,6 +2,7 @@ import { relative } from "node:path"
2
2
  import {
3
3
  DiagnosticError,
4
4
  addAppPlugin,
5
+ addRouteRules,
5
6
  addRouteMiddleware,
6
7
  addTemplate,
7
8
  createResolver,
@@ -13,6 +14,7 @@ import {
13
14
  } from "hamur/kit"
14
15
  import { parsePattern, type RouteTable, type Segment } from "../runtime/match.ts"
15
16
  import type { ResolvedI18nOptions } from "../types.ts"
17
+ import { localeAccessRules } from "./access.ts"
16
18
 
17
19
  const SEPARATOR = "___"
18
20
 
@@ -215,11 +217,17 @@ const PRERENDER_WARNING = 'i18n: "/" is prerendered, so detect.redirect "root" n
215
217
  export function setupRoutes(options: ResolvedI18nOptions, hamur: HamurContext): void {
216
218
  const r = createResolver(import.meta.url)
217
219
  let table: RouteTable = { copies: [], routes: {} }
220
+ let made = new Set<string>()
218
221
  extendPages((routes) => {
222
+ const originals = [...routes]
219
223
  const localized = localizeRoutes(routes, options, hamur.options.rootDir)
220
224
  routes.splice(0, routes.length, ...localized.routes)
221
225
  table = localized.table
222
226
  rememberRouteTable(hamur, table)
227
+ const own = Object.fromEntries(Object.entries(hamur.routeRules).filter(([key]) => !made.has(key)))
228
+ const access = localeAccessRules(own, originals, table, options.defaultLocale)
229
+ made = new Set(Object.keys(access))
230
+ if (made.size) addRouteRules(access)
223
231
  })
224
232
  const exports = (values: Record<string, unknown>) =>
225
233
  Object.entries(values)
package/src/types.ts CHANGED
@@ -176,7 +176,8 @@ declare module "hamur" {
176
176
 
177
177
  declare module "hamur/app" {
178
178
  interface HamurLinkProps {
179
+ // By the package's name: an installed app's program has this file and its declaration, which must declare one type.
179
180
  /** The locale of the link's path, the page's by default; `false` keeps `to` as written. */
180
- locale?: HamurLocale | false
181
+ locale?: import("@hamur/i18n").HamurLocale | false
181
182
  }
182
183
  }