@kuratchi/js 0.0.14 → 0.0.16

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.
Files changed (65) hide show
  1. package/README.md +135 -68
  2. package/dist/cli.js +80 -47
  3. package/dist/compiler/api-route-pipeline.d.ts +8 -0
  4. package/dist/compiler/api-route-pipeline.js +23 -0
  5. package/dist/compiler/asset-pipeline.d.ts +7 -0
  6. package/dist/compiler/asset-pipeline.js +33 -0
  7. package/dist/compiler/client-module-pipeline.d.ts +25 -0
  8. package/dist/compiler/client-module-pipeline.js +257 -0
  9. package/dist/compiler/compiler-shared.d.ts +55 -0
  10. package/dist/compiler/compiler-shared.js +4 -0
  11. package/dist/compiler/component-pipeline.d.ts +15 -0
  12. package/dist/compiler/component-pipeline.js +163 -0
  13. package/dist/compiler/config-reading.d.ts +11 -0
  14. package/dist/compiler/config-reading.js +323 -0
  15. package/dist/compiler/convention-discovery.d.ts +9 -0
  16. package/dist/compiler/convention-discovery.js +83 -0
  17. package/dist/compiler/durable-object-pipeline.d.ts +9 -0
  18. package/dist/compiler/durable-object-pipeline.js +255 -0
  19. package/dist/compiler/error-page-pipeline.d.ts +1 -0
  20. package/dist/compiler/error-page-pipeline.js +16 -0
  21. package/dist/compiler/import-linking.d.ts +36 -0
  22. package/dist/compiler/import-linking.js +139 -0
  23. package/dist/compiler/index.d.ts +3 -3
  24. package/dist/compiler/index.js +137 -3265
  25. package/dist/compiler/layout-pipeline.d.ts +31 -0
  26. package/dist/compiler/layout-pipeline.js +155 -0
  27. package/dist/compiler/page-route-pipeline.d.ts +16 -0
  28. package/dist/compiler/page-route-pipeline.js +62 -0
  29. package/dist/compiler/parser.d.ts +4 -0
  30. package/dist/compiler/parser.js +433 -51
  31. package/dist/compiler/root-layout-pipeline.d.ts +10 -0
  32. package/dist/compiler/root-layout-pipeline.js +517 -0
  33. package/dist/compiler/route-discovery.d.ts +7 -0
  34. package/dist/compiler/route-discovery.js +87 -0
  35. package/dist/compiler/route-pipeline.d.ts +57 -0
  36. package/dist/compiler/route-pipeline.js +296 -0
  37. package/dist/compiler/route-state-pipeline.d.ts +25 -0
  38. package/dist/compiler/route-state-pipeline.js +139 -0
  39. package/dist/compiler/routes-module-feature-blocks.d.ts +2 -0
  40. package/dist/compiler/routes-module-feature-blocks.js +330 -0
  41. package/dist/compiler/routes-module-pipeline.d.ts +2 -0
  42. package/dist/compiler/routes-module-pipeline.js +6 -0
  43. package/dist/compiler/routes-module-runtime-shell.d.ts +2 -0
  44. package/dist/compiler/routes-module-runtime-shell.js +81 -0
  45. package/dist/compiler/routes-module-types.d.ts +44 -0
  46. package/dist/compiler/routes-module-types.js +1 -0
  47. package/dist/compiler/script-transform.d.ts +16 -0
  48. package/dist/compiler/script-transform.js +218 -0
  49. package/dist/compiler/server-module-pipeline.d.ts +13 -0
  50. package/dist/compiler/server-module-pipeline.js +124 -0
  51. package/dist/compiler/template.d.ts +13 -1
  52. package/dist/compiler/template.js +323 -60
  53. package/dist/compiler/worker-output-pipeline.d.ts +13 -0
  54. package/dist/compiler/worker-output-pipeline.js +37 -0
  55. package/dist/compiler/wrangler-sync.d.ts +14 -0
  56. package/dist/compiler/wrangler-sync.js +185 -0
  57. package/dist/runtime/app.js +15 -3
  58. package/dist/runtime/generated-worker.d.ts +33 -0
  59. package/dist/runtime/generated-worker.js +412 -0
  60. package/dist/runtime/index.d.ts +2 -1
  61. package/dist/runtime/index.js +1 -0
  62. package/dist/runtime/router.d.ts +2 -1
  63. package/dist/runtime/router.js +12 -3
  64. package/dist/runtime/types.d.ts +8 -2
  65. package/package.json +5 -1
@@ -11,7 +11,8 @@ export interface MatchResult {
11
11
  index: number;
12
12
  }
13
13
  export declare class Router {
14
- private routes;
14
+ private staticRoutes;
15
+ private dynamicRoutes;
15
16
  /** Register a pattern (e.g. '/blog/:slug') and associate it with an index. */
16
17
  add(pattern: string, index: number): void;
17
18
  /** Match a pathname against registered routes. Returns null if no match. */
@@ -7,9 +7,14 @@
7
7
  * /files/*rest → catch-all
8
8
  */
9
9
  export class Router {
10
- routes = [];
10
+ staticRoutes = new Map();
11
+ dynamicRoutes = [];
11
12
  /** Register a pattern (e.g. '/blog/:slug') and associate it with an index. */
12
13
  add(pattern, index) {
14
+ if (!pattern.includes(':') && !pattern.includes('*')) {
15
+ this.staticRoutes.set(pattern, index);
16
+ return;
17
+ }
13
18
  const paramNames = [];
14
19
  // Convert pattern to regex
15
20
  // :param → named capture group
@@ -27,7 +32,7 @@ export class Router {
27
32
  });
28
33
  // Anchor
29
34
  regexStr = `^${regexStr}$`;
30
- this.routes.push({
35
+ this.dynamicRoutes.push({
31
36
  regex: new RegExp(regexStr),
32
37
  paramNames,
33
38
  index,
@@ -37,7 +42,11 @@ export class Router {
37
42
  match(pathname) {
38
43
  // Normalize: strip trailing slash (except root)
39
44
  const normalized = pathname === '/' ? '/' : pathname.replace(/\/$/, '');
40
- for (const route of this.routes) {
45
+ const staticIdx = this.staticRoutes.get(normalized);
46
+ if (staticIdx !== undefined) {
47
+ return { params: {}, index: staticIdx };
48
+ }
49
+ for (const route of this.dynamicRoutes) {
41
50
  const m = normalized.match(route.regex);
42
51
  if (m) {
43
52
  const params = {};
@@ -18,6 +18,12 @@ export interface RouteContext<E extends Env = Env> {
18
18
  /** Parsed URL */
19
19
  url: URL;
20
20
  }
21
+ export interface PageRenderResult {
22
+ html: string;
23
+ head?: string;
24
+ fragments?: Record<string, string>;
25
+ }
26
+ export type PageRenderOutput = string | PageRenderResult;
21
27
  /** A compiled route module */
22
28
  export interface RouteModule {
23
29
  /** Pattern string (e.g., '/todos', '/blog/:slug') */
@@ -28,8 +34,8 @@ export interface RouteModule {
28
34
  actions?: Record<string, (formData: FormData, env: Env, ctx: RouteContext) => Promise<any>>;
29
35
  /** RPC functions â€" callable from client via fetch */
30
36
  rpc?: Record<string, (args: any[], env: Env, ctx: RouteContext) => Promise<any>>;
31
- /** Render function â€" returns HTML string from data */
32
- render: (data: Record<string, any>) => string;
37
+ /** Render function â€" returns route HTML and optional head content from data */
38
+ render: (data: Record<string, any>) => PageRenderOutput;
33
39
  /** Layout name (default: 'default') */
34
40
  layout?: string;
35
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuratchi/js",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "A thin, Cloudflare Workers-native web framework with Svelte-inspired syntax",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,6 +38,10 @@
38
38
  "types": "./dist/runtime/do.d.ts",
39
39
  "import": "./dist/runtime/do.js"
40
40
  },
41
+ "./runtime/generated-worker.js": {
42
+ "types": "./dist/runtime/generated-worker.d.ts",
43
+ "import": "./dist/runtime/generated-worker.js"
44
+ },
41
45
  "./compiler": {
42
46
  "types": "./dist/compiler/index.d.ts",
43
47
  "import": "./dist/compiler/index.js"