@ubean/routing 0.1.2 → 0.1.3

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.
@@ -0,0 +1,157 @@
1
+ import { PageHead, RouteMeta } from "@ubean/types";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * HTTP methods supported by ubean API routes.
5
+ * Aligned with Hono's built-in methods (excludes TRACE).
6
+ */
7
+ declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
8
+ type HttpMethod = (typeof HTTP_METHODS)[number];
9
+ interface ScannedFile {
10
+ fullPath: string;
11
+ relativePath: string;
12
+ dirname: string;
13
+ basename: string;
14
+ }
15
+ interface ScannedApiRoute extends ScannedFile {
16
+ route: string;
17
+ method?: HttpMethod | Lowercase<HttpMethod>;
18
+ env?: 'dev' | 'prod' | 'prerender';
19
+ exports: string[];
20
+ hasMeta: boolean;
21
+ fileMeta?: RouteMeta;
22
+ }
23
+ interface ScannedMiddleware extends ScannedFile {
24
+ order: number;
25
+ global: boolean;
26
+ }
27
+ interface ScannedPageRoute extends ScannedFile {
28
+ name: string;
29
+ route: string;
30
+ path: string;
31
+ layout?: string | false;
32
+ cache?: boolean;
33
+ isReuse: boolean;
34
+ isMarkdown: boolean;
35
+ reuseTarget?: string;
36
+ pageMeta?: PageMeta;
37
+ frontmatter?: Record<string, unknown>;
38
+ }
39
+ interface ScannedLayout extends ScannedFile {
40
+ name: string;
41
+ path: string;
42
+ isDefault: boolean;
43
+ }
44
+ interface ScannedPlugin extends ScannedFile {
45
+ order: number;
46
+ }
47
+ interface ScannedCronTask extends ScannedFile {
48
+ name: string;
49
+ }
50
+ interface ScannedQueue extends ScannedFile {
51
+ name: string;
52
+ }
53
+ interface ScannedLocale extends ScannedFile {
54
+ code: string;
55
+ namespace?: string;
56
+ isDefault?: boolean;
57
+ name?: string;
58
+ dir?: 'ltr' | 'rtl';
59
+ }
60
+ interface AppEntry {
61
+ exists: boolean;
62
+ fullPath?: string;
63
+ relativePath?: string;
64
+ }
65
+ interface ScannedAppEntry {
66
+ shared: AppEntry;
67
+ server: AppEntry;
68
+ client: AppEntry;
69
+ }
70
+ interface ScannedServerEntry {
71
+ shared: AppEntry;
72
+ dev: AppEntry;
73
+ prod: AppEntry;
74
+ }
75
+ interface ScanOptions {
76
+ cwd: string;
77
+ srcDir: string;
78
+ dirs?: {
79
+ routes?: string | string[];
80
+ middleware?: string | string[];
81
+ pages?: string | string[];
82
+ layouts?: string | string[];
83
+ plugins?: string | string[];
84
+ crons?: string | string[];
85
+ queues?: string | string[];
86
+ locales?: string | string[];
87
+ };
88
+ ignore?: string[];
89
+ }
90
+ interface ScanResult {
91
+ apiRoutes: ScannedApiRoute[];
92
+ middlewares: ScannedMiddleware[];
93
+ pages: ScannedPageRoute[];
94
+ layouts: ScannedLayout[];
95
+ plugins: ScannedPlugin[];
96
+ crons: ScannedCronTask[];
97
+ queues: ScannedQueue[];
98
+ locales: ScannedLocale[];
99
+ defaultLocale?: string;
100
+ appEntry: ScannedAppEntry;
101
+ serverEntry: ScannedServerEntry;
102
+ }
103
+ declare const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
104
+ declare const GLOB_VUE_PATTERN = "**/*.{vue,ts,md,mdx}";
105
+ declare const GLOB_LAYOUT_PATTERN = "**/*.{vue,ts}";
106
+ /**
107
+ * Page-level head configuration (SEO title, meta, link, etc.).
108
+ * Used by Markdown frontmatter; Vue pages use `useHead()` at runtime instead.
109
+ *
110
+ * `PageHead` itself is imported from `@ubean/types` to avoid a
111
+ * routing ↔ pages circular dependency.
112
+ */
113
+ /**
114
+ * Page-level route metadata extracted from `definePage()` macro calls.
115
+ *
116
+ * `meta` is typed against the local `RouteMeta` (re-exported from
117
+ * `@ubean/types`). When the consumer augments `vue-router`'s
118
+ * `RouteMeta` interface, the augmented members flow through here via
119
+ * the `@ubean/types` re-export.
120
+ *
121
+ * NOTE: The `declare module 'vue-router' { interface RouteMeta { ... } }`
122
+ * augmentation is owned by `@ubean/runtime` to keep this package
123
+ * decoupled from the Vue runtime.
124
+ */
125
+ interface PageMeta {
126
+ name?: string;
127
+ path?: string;
128
+ layout?: string | false;
129
+ reuse?: string;
130
+ /**
131
+ * Route metadata. Extends vue-router's `RouteMeta` so projects can
132
+ * augment it via `declare module 'vue-router' { interface RouteMeta { ... } }`
133
+ * and get full type-safety inside `definePage({ meta: { ... } })`.
134
+ */
135
+ meta?: RouteMeta;
136
+ middleware?: string | string[];
137
+ requiresAuth?: boolean;
138
+ /**
139
+ * Enable `<keep-alive>` caching for this page.
140
+ * When `true`, the page component instance is preserved (not destroyed)
141
+ * when navigating away, and restored when navigating back.
142
+ * The page's route name is used as the cache key (component name).
143
+ * Can be toggled at runtime via `enablePageCache(name)` / `disablePageCache(name)`.
144
+ */
145
+ cache?: boolean;
146
+ /**
147
+ * Page-level head configuration (SEO title, meta, link, etc.).
148
+ * Used by Markdown frontmatter; Vue pages use `useHead()` at runtime instead.
149
+ */
150
+ head?: PageHead;
151
+ }
152
+ interface DefineMetaResult {
153
+ meta?: Record<string, unknown>;
154
+ requiresAuth?: boolean;
155
+ }
156
+ //#endregion
157
+ export { AppEntry, DefineMetaResult, GLOB_LAYOUT_PATTERN, GLOB_SCAN_PATTERN, GLOB_VUE_PATTERN, HTTP_METHODS, HttpMethod, type PageHead, PageMeta, type RouteMeta, ScanOptions, ScanResult, ScannedApiRoute, ScannedAppEntry, ScannedCronTask, ScannedFile, ScannedLayout, ScannedLocale, ScannedMiddleware, ScannedPageRoute, ScannedPlugin, ScannedQueue, ScannedServerEntry };
package/dist/types.js ADDED
@@ -0,0 +1,19 @@
1
+ //#region src/types.ts
2
+ /**
3
+ * HTTP methods supported by ubean API routes.
4
+ * Aligned with Hono's built-in methods (excludes TRACE).
5
+ */
6
+ const HTTP_METHODS = [
7
+ "GET",
8
+ "POST",
9
+ "PUT",
10
+ "PATCH",
11
+ "DELETE",
12
+ "HEAD",
13
+ "OPTIONS"
14
+ ];
15
+ const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
16
+ const GLOB_VUE_PATTERN = "**/*.{vue,ts,md,mdx}";
17
+ const GLOB_LAYOUT_PATTERN = "**/*.{vue,ts}";
18
+ //#endregion
19
+ export { GLOB_LAYOUT_PATTERN, GLOB_SCAN_PATTERN, GLOB_VUE_PATTERN, HTTP_METHODS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/routing",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "File-based routing core for ubean (scanner, rou3 matcher, route name generator, define-page AST extractor, file generator)",
5
5
  "files": [
6
6
  "dist"
@@ -30,8 +30,8 @@
30
30
  "scule": "^1.3.0",
31
31
  "tinyglobby": "^0.2.17",
32
32
  "ufo": "1.6.4",
33
- "@ubean/types": "0.1.2",
34
- "@ubean/utils": "0.1.2"
33
+ "@ubean/types": "0.1.3",
34
+ "@ubean/utils": "0.1.3"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^26.1.1",
@@ -39,11 +39,11 @@
39
39
  "vite-plus": "0.2.6",
40
40
  "vue": "^3.5.40",
41
41
  "vue-router": "^5.2.0",
42
- "@ubean/markdown": "0.1.2"
42
+ "@ubean/markdown": "0.1.3"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vue-router": "^4.0.0",
46
- "@ubean/markdown": "0.1.2"
46
+ "@ubean/markdown": "0.1.3"
47
47
  },
48
48
  "peerDependenciesMeta": {
49
49
  "@ubean/markdown": {