@veap/plugins 0.0.0-stage → 0.1.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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -2
  3. package/dist/actions/index.d.ts +1 -0
  4. package/dist/actions/index.js +1 -0
  5. package/dist/actions/plugin.actions.d.ts +6 -0
  6. package/dist/actions/plugin.actions.js +60 -0
  7. package/dist/actions.d.ts +1 -0
  8. package/dist/actions.js +1 -0
  9. package/dist/cli/add.d.ts +4 -0
  10. package/dist/cli/add.js +191 -0
  11. package/dist/cli/eject.d.ts +2 -0
  12. package/dist/cli/eject.js +136 -0
  13. package/dist/cli/generate-plugin.d.ts +3 -0
  14. package/dist/cli/generate-plugin.js +48 -0
  15. package/dist/cli/index.d.ts +6 -0
  16. package/dist/cli/index.js +6 -0
  17. package/dist/cli/package-manager.d.ts +14 -0
  18. package/dist/cli/package-manager.js +62 -0
  19. package/dist/cli/stubs.d.ts +16 -0
  20. package/dist/cli/stubs.js +42 -0
  21. package/dist/cli/utils.d.ts +3 -0
  22. package/dist/cli/utils.js +164 -0
  23. package/dist/client.d.ts +6 -0
  24. package/dist/client.js +8 -0
  25. package/dist/common/context.d.ts +26 -0
  26. package/dist/common/context.js +26 -0
  27. package/dist/common/events.d.ts +19 -0
  28. package/dist/common/events.js +26 -0
  29. package/dist/common/index.d.ts +4 -0
  30. package/dist/common/index.js +4 -0
  31. package/dist/common/tokens.d.ts +14 -0
  32. package/dist/common/tokens.js +12 -0
  33. package/dist/common/types.d.ts +202 -0
  34. package/dist/common/types.js +39 -0
  35. package/dist/composition.d.ts +15 -0
  36. package/dist/composition.js +20 -0
  37. package/dist/index.d.ts +6 -0
  38. package/dist/index.js +6 -0
  39. package/dist/migrations/0001_create_plugins_tables.d.ts +4 -0
  40. package/dist/migrations/0001_create_plugins_tables.js +29 -0
  41. package/dist/migrations/index.d.ts +4 -0
  42. package/dist/migrations/index.js +7 -0
  43. package/dist/models/SystemPlugin.d.ts +19 -0
  44. package/dist/models/SystemPlugin.js +14 -0
  45. package/dist/models/SystemUserWidget.d.ts +19 -0
  46. package/dist/models/SystemUserWidget.js +17 -0
  47. package/dist/models/index.d.ts +2 -0
  48. package/dist/models/index.js +2 -0
  49. package/dist/models.d.ts +1 -0
  50. package/dist/models.js +1 -0
  51. package/dist/navigation/breadcrumbs.d.ts +2 -0
  52. package/dist/navigation/breadcrumbs.js +84 -0
  53. package/dist/navigation/index.d.ts +2 -0
  54. package/dist/navigation/index.js +2 -0
  55. package/dist/navigation/navigation.service.d.ts +27 -0
  56. package/dist/navigation/navigation.service.js +183 -0
  57. package/dist/providers/index.d.ts +1 -0
  58. package/dist/providers/index.js +1 -0
  59. package/dist/providers/plugins.provider.d.ts +20 -0
  60. package/dist/providers/plugins.provider.js +143 -0
  61. package/dist/registry/contracts.d.ts +72 -0
  62. package/dist/registry/contracts.js +4 -0
  63. package/dist/registry/facade.d.ts +45 -0
  64. package/dist/registry/facade.js +49 -0
  65. package/dist/registry/index.d.ts +5 -0
  66. package/dist/registry/index.js +5 -0
  67. package/dist/registry/migration-runner.d.ts +8 -0
  68. package/dist/registry/migration-runner.js +12 -0
  69. package/dist/registry/plugin.repository.d.ts +19 -0
  70. package/dist/registry/plugin.repository.js +74 -0
  71. package/dist/registry/registry.service.d.ts +69 -0
  72. package/dist/registry/registry.service.js +535 -0
  73. package/dist/router/discovery.d.ts +27 -0
  74. package/dist/router/discovery.js +37 -0
  75. package/dist/router/handler.d.ts +6 -0
  76. package/dist/router/handler.js +40 -0
  77. package/dist/router/index.d.ts +14 -0
  78. package/dist/router/index.js +14 -0
  79. package/dist/router/matcher.d.ts +5 -0
  80. package/dist/router/matcher.js +32 -0
  81. package/dist/router/middlewares.d.ts +25 -0
  82. package/dist/router/middlewares.js +119 -0
  83. package/dist/router/react/error-boundary.d.ts +30 -0
  84. package/dist/router/react/error-boundary.js +68 -0
  85. package/dist/router/react/index.d.ts +4 -0
  86. package/dist/router/react/index.js +4 -0
  87. package/dist/router/react/renderer.d.ts +13 -0
  88. package/dist/router/react/renderer.js +159 -0
  89. package/dist/router/react/soft-navigation.d.ts +4 -0
  90. package/dist/router/react/soft-navigation.js +34 -0
  91. package/dist/router/react/with-router.d.ts +22 -0
  92. package/dist/router/react/with-router.js +19 -0
  93. package/dist/router/route-tree.d.ts +177 -0
  94. package/dist/router/route-tree.js +639 -0
  95. package/dist/router/router.service.d.ts +25 -0
  96. package/dist/router/router.service.js +127 -0
  97. package/dist/router/scanner.d.ts +4 -0
  98. package/dist/router/scanner.js +337 -0
  99. package/dist/router/utils.d.ts +10 -0
  100. package/dist/router/utils.js +48 -0
  101. package/dist/router.d.ts +6 -0
  102. package/dist/router.js +6 -0
  103. package/dist/server.d.ts +11 -0
  104. package/dist/server.js +17 -0
  105. package/dist/widgets/index.d.ts +8 -0
  106. package/dist/widgets/index.js +8 -0
  107. package/dist/widgets/path-prefix-context.d.ts +5 -0
  108. package/dist/widgets/path-prefix-context.js +9 -0
  109. package/dist/widgets/plugin-extension-point-client.d.ts +15 -0
  110. package/dist/widgets/plugin-extension-point-client.js +44 -0
  111. package/dist/widgets/plugin-extension-point.d.ts +14 -0
  112. package/dist/widgets/plugin-extension-point.js +51 -0
  113. package/dist/widgets/plugin-widget-area-client.d.ts +11 -0
  114. package/dist/widgets/plugin-widget-area-client.js +31 -0
  115. package/dist/widgets/plugin-widget-area.d.ts +10 -0
  116. package/dist/widgets/plugin-widget-area.js +19 -0
  117. package/dist/widgets/use-confirm-action.d.ts +19 -0
  118. package/dist/widgets/use-confirm-action.js +68 -0
  119. package/dist/widgets/widget-composer-client.d.ts +21 -0
  120. package/dist/widgets/widget-composer-client.js +281 -0
  121. package/dist/widgets/widget-composer.d.ts +8 -0
  122. package/dist/widgets/widget-composer.js +28 -0
  123. package/package.json +115 -4
@@ -0,0 +1,177 @@
1
+ /**
2
+ * @module route-tree
3
+ * @description Core route tree engine for the Veap unstable custom router.
4
+ *
5
+ * Implements a tree-based routing structure that mirrors Next.js App Router
6
+ * file conventions. Supports static, dynamic, catch-all, optional catch-all,
7
+ * route group, and parallel route segments.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const tree = new RouteTree();
12
+ * tree.addTree({
13
+ * segment: "",
14
+ * layout: RootLayout,
15
+ * children: [
16
+ * { segment: "blog", page: BlogPage, children: [
17
+ * { segment: "[slug]", page: BlogPostPage },
18
+ * ]},
19
+ * ],
20
+ * });
21
+ *
22
+ * const result = tree.match("/blog/hello-world");
23
+ * // result.params => { slug: "hello-world" }
24
+ * ```
25
+ */
26
+ import type { UserPermission, UserRole } from "@veap/auth";
27
+ import type { Metadata } from "next";
28
+ import type * as React from "react";
29
+ import type { ApiMiddleware, BreadcrumbValue, VeapMiddleware } from "../common/types";
30
+ /**
31
+ * A single node in the route tree. Mirrors Next.js App Router file conventions.
32
+ * Each node represents a URL segment and can contain page/layout/loading/error
33
+ * components, metadata generators, middleware pipelines, and auth constraints.
34
+ */
35
+ export interface RouteNode {
36
+ /**
37
+ * Segment of the path.
38
+ * - Regular: `"blog"`, `"about"`
39
+ * - Dynamic: `"[id]"`, `"[slug]"`
40
+ * - Catch-all: `"[...path]"`
41
+ * - Optional catch-all: `"[[...path]]"`
42
+ * - Route group: `"(marketing)"` - transparent in URL
43
+ * - Empty string `""` for root/index
44
+ */
45
+ segment: string;
46
+ /** Page component - equivalent to `page.tsx`. */
47
+ page?: React.ComponentType<any>;
48
+ /** Layout wrapping children - equivalent to `layout.tsx`. */
49
+ layout?: React.ComponentType<{
50
+ children: React.ReactNode;
51
+ params?: any;
52
+ [slotName: string]: any;
53
+ }>;
54
+ /** Loading component - equivalent to `loading.tsx`. */
55
+ loading?: React.ComponentType;
56
+ /** Error component - equivalent to `error.tsx` (client component). */
57
+ error?: React.ComponentType<{
58
+ error: Error;
59
+ reset: () => void;
60
+ }>;
61
+ /** Not-found component - equivalent to `not-found.tsx`. */
62
+ notFound?: React.ComponentType;
63
+ /** Default component for parallel route slots - equivalent to `default.tsx`. */
64
+ default?: React.ComponentType<any>;
65
+ /** API route handlers - equivalent to `route.ts`. Contains exported HTTP methods like GET, POST, etc. */
66
+ route?: {
67
+ GET?: Function;
68
+ POST?: Function;
69
+ PUT?: Function;
70
+ DELETE?: Function;
71
+ PATCH?: Function;
72
+ OPTIONS?: Function;
73
+ HEAD?: Function;
74
+ [key: string]: any;
75
+ };
76
+ /**
77
+ * Metadata generator for this route node.
78
+ * Called with params and searchParams to produce `<head>` metadata.
79
+ */
80
+ generateMetadata?: (props: {
81
+ params: Record<string, string>;
82
+ searchParams: Record<string, string>;
83
+ }) => Promise<Metadata> | Metadata;
84
+ /** Middleware pipeline applied when this node is part of the matched chain. */
85
+ middlewares?: (VeapMiddleware | ApiMiddleware)[] | any[];
86
+ /** Whether authentication is required to access this route. */
87
+ auth?: boolean;
88
+ /** Roles required to access this route (RBAC). */
89
+ roles?: UserRole[];
90
+ /** Permissions required to access this route (RBAC). */
91
+ permissions?: UserPermission[];
92
+ /** Breadcrumb configuration for this route node. */
93
+ breadcrumb?: BreadcrumbValue;
94
+ /** Route ID for template overrides and programmatic identification. */
95
+ id?: string;
96
+ /** Child route nodes. */
97
+ children?: RouteNode[];
98
+ /**
99
+ * Parallel route slots: `@slotName` → subtree.
100
+ * Parallel routes are resolved independently against the same URL path.
101
+ */
102
+ parallelRoutes?: Record<string, RouteNode>;
103
+ }
104
+ /**
105
+ * Represents a single entry in the layout chain collected during route matching.
106
+ * Each entry captures the layout, loading, error, middleware, and auth config
107
+ * from one level of the tree as we walk from root to the matched leaf.
108
+ */
109
+ export interface LayoutChainEntry {
110
+ /** Layout component at this level. */
111
+ layout?: React.ComponentType<any>;
112
+ /** Loading component at this level. */
113
+ loading?: React.ComponentType;
114
+ /** Error component at this level. */
115
+ error?: React.ComponentType<{
116
+ error: Error;
117
+ reset: () => void;
118
+ }>;
119
+ /** NotFound component at this level. */
120
+ notFound?: React.ComponentType;
121
+ /** Middleware pipeline at this level. */
122
+ middlewares?: (VeapMiddleware | ApiMiddleware)[] | any[];
123
+ /** Whether authentication is required at this level. */
124
+ auth?: boolean;
125
+ /** Roles required at this level. */
126
+ roles?: UserRole[];
127
+ /** Permissions required at this level. */
128
+ permissions?: UserPermission[];
129
+ /** Resolved parallel slot contents for this layout level. */
130
+ parallelSlots?: Record<string, RouteNode>;
131
+ /** The path segments consumed up to this layout level. Used for parallel route matching. */
132
+ consumedPath?: string;
133
+ /** Route ID for template overrides. */
134
+ id?: string;
135
+ }
136
+ /**
137
+ * Result of matching a URL path against the route tree.
138
+ */
139
+ export interface MatchResult {
140
+ /** The matched leaf node (has a `page` component). */
141
+ node: RouteNode;
142
+ /** Extracted URL parameters (dynamic segments, catch-all, etc.). */
143
+ params: Record<string, string>;
144
+ /** Chain of layouts from root to the matched node. */
145
+ layoutChain: LayoutChainEntry[];
146
+ /** Path segments that were matched (for debugging/breadcrumbs). */
147
+ matchedSegments: string[];
148
+ /** True if the path was fully consumed and matched a leaf node (page). False for partial matches. */
149
+ isExact: boolean;
150
+ }
151
+ export declare function isGroupSegment(segment: string): boolean;
152
+ export declare function isDynamicSegment(segment: string): boolean;
153
+ export declare function isCatchAllSegment(segment: string): boolean;
154
+ export declare function isOptionalCatchAllSegment(segment: string): boolean;
155
+ export declare function isParallelSlot(segment: string): boolean;
156
+ export declare function extractParamName(segment: string): string;
157
+ export declare function segmentMatchesUrlPart(segment: string, urlPart: string): boolean;
158
+ export declare function resolveMagicPrefix(node: RouteNode, prefixPath: string): RouteNode;
159
+ export declare class RouteTree {
160
+ private root;
161
+ private rewrites;
162
+ constructor(initialRoot?: RouteNode, initialRewrites?: Map<string, string> | Record<string, string>);
163
+ private normalizeRewritePath;
164
+ addRewrite(from: string, to: string): this;
165
+ setRewrites(rewrites: Map<string, string> | Record<string, string>): this;
166
+ getRewrites(): Map<string, string>;
167
+ resolveRewrite(path: string): string;
168
+ private matchRewritePattern;
169
+ private applyRewritePattern;
170
+ getRoot(): RouteNode;
171
+ addTree(source: RouteNode | RouteTree, prefix?: string): void;
172
+ mergeNode(target: RouteNode, source: RouteNode): void;
173
+ match(path: string): MatchResult | null;
174
+ generateMetadata(path: string, searchParams?: Record<string, string>): Promise<Metadata>;
175
+ private collectMetadataGenerators;
176
+ private collectGeneratorsRecursive;
177
+ }