@wild-framework/graph 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wild Framework contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @wild-framework/graph
2
+
3
+ Machine-readable **Project Graph** for [Wild Framework](https://github.com/KhandaSoftware/wild-framework) apps.
4
+
5
+ A single JSON-serializable model of a running application — providers, routes,
6
+ resources, request schemas, DI bindings, and migrations. It is the source of
7
+ truth that visual builders (Wild Studio) and AI agents render and manipulate.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @wild-framework/graph
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Register `GraphProvider` last (after all feature providers):
18
+
19
+ ```ts
20
+ import { GraphProvider } from "@wild-framework/graph";
21
+
22
+ GraphProvider.appName = "Shop API";
23
+ GraphProvider.appVersion = "1.0.0";
24
+
25
+ app.register(GraphProvider); // after feature providers, before/after OpenApi
26
+ ```
27
+
28
+ Then fetch the graph:
29
+
30
+ ```bash
31
+ curl http://localhost:3000/graph.json
32
+ ```
33
+
34
+ Or build it programmatically:
35
+
36
+ ```ts
37
+ import { buildProjectGraph } from "@wild-framework/graph";
38
+
39
+ const graph = buildProjectGraph(app, router, { name: "Shop API", version: "1.0.0" });
40
+ ```
41
+
42
+ ## Graph shape
43
+
44
+ ```jsonc
45
+ {
46
+ "name": "Shop API",
47
+ "version": "1.0.0",
48
+ "providers": [{ "name": "ProductProvider", "index": 8 }],
49
+ "routes": [{ "method": "get", "path": "/products", "controller": "ProductController", "action": "index", "validator": "CreateProductRequest" }],
50
+ "resources": [{ "name": "Product", "segment": "products", "routes": [] }],
51
+ "schemas": [{ "name": "CreateProductRequest", "fields": { "name": "string", "price": "number" } }],
52
+ "bindings": [{ "token": "ProductService" }],
53
+ "migrations": [{ "name": "20261010_add_order_index", "applied": true }]
54
+ }
55
+ ```
56
+
57
+ ## Design
58
+
59
+ - Derived from the **live app** (never hand-maintained) via
60
+ `Application.getRegisteredProviders()`, `Router.getRegisteredRoutes()`, and
61
+ `Container.listBindings()`.
62
+ - Resources are grouped by first path segment (`/products/:id` → `products`).
63
+ - The graph is **read-only introspection** — the visual builder renders it and
64
+ maps user actions back to CLI/engine operations (the GUI holds no logic).
65
+
66
+ ## License
67
+
68
+ MIT
@@ -0,0 +1,19 @@
1
+ import type { Application } from "@wild-framework/core";
2
+ import type { Router } from "@wild-framework/http";
3
+ import type { MigrationStatus } from "@wild-framework/database";
4
+ import type { ProjectGraph } from "./types.js";
5
+ /** Options for building a graph. */
6
+ export interface BuildGraphOptions {
7
+ name: string;
8
+ version: string;
9
+ migrations?: MigrationStatus[];
10
+ }
11
+ /**
12
+ * Build the Project Graph from a booted application.
13
+ *
14
+ * Reads providers (from `Application`), routes + validators (from `Router`),
15
+ * and bindings (from the `Container`). The result is a plain,
16
+ * JSON-serializable object.
17
+ */
18
+ export declare function buildProjectGraph(app: Application, router: Router, options: BuildGraphOptions): ProjectGraph;
19
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,YAAY,CAAC;AAwC5D,oCAAoC;AACpC,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC7B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,GAC3B,YAAY,CA4Bd"}
package/dist/build.js ADDED
@@ -0,0 +1,69 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { deriveResources } from "./resources.js";
3
+ /**
4
+ * Extract field names + simple types from a Zod validator class.
5
+ *
6
+ * A validator is a class with a `static schema` (a `z.object`). Reads the
7
+ * public `.shape` so no internal Zod APIs are used.
8
+ */
9
+ function schemaFromValidator(validatorName, validator) {
10
+ const shape = validator?.shape;
11
+ const fields = {};
12
+ if (shape && typeof shape === "object") {
13
+ for (const [key, def] of Object.entries(shape)) {
14
+ fields[key] = zodTypeName(def);
15
+ }
16
+ }
17
+ return { name: validatorName, fields };
18
+ }
19
+ /** Map a Zod type instance to a simple type name. */
20
+ function zodTypeName(def) {
21
+ const t = def;
22
+ const typeName = t?._def?.typeName;
23
+ switch (typeName) {
24
+ case "ZodString":
25
+ return "string";
26
+ case "ZodNumber":
27
+ return "number";
28
+ case "ZodBoolean":
29
+ return "boolean";
30
+ case "ZodArray":
31
+ return "array";
32
+ default:
33
+ return "unknown";
34
+ }
35
+ }
36
+ /**
37
+ * Build the Project Graph from a booted application.
38
+ *
39
+ * Reads providers (from `Application`), routes + validators (from `Router`),
40
+ * and bindings (from the `Container`). The result is a plain,
41
+ * JSON-serializable object.
42
+ */
43
+ export function buildProjectGraph(app, router, options) {
44
+ const registered = router.getRegisteredRoutes();
45
+ const container = app.resolve(Container);
46
+ const schemas = [];
47
+ for (const route of registered) {
48
+ if (route.validator && route.validatorName) {
49
+ schemas.push(schemaFromValidator(route.validatorName, route.validator));
50
+ }
51
+ }
52
+ return {
53
+ name: options.name,
54
+ version: options.version,
55
+ providers: app.getRegisteredProviders().map((name, index) => ({ name, index })),
56
+ routes: registered.map((r) => ({
57
+ method: r.method,
58
+ path: r.path,
59
+ controller: r.action?.controller?.name,
60
+ action: r.action?.method,
61
+ validator: r.validatorName,
62
+ })),
63
+ resources: deriveResources(registered),
64
+ schemas,
65
+ bindings: container.listBindings().map((token) => ({ token })),
66
+ migrations: options.migrations ?? [],
67
+ };
68
+ }
69
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAItD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,aAAqB,EAAE,SAAkB;IAClE,MAAM,KAAK,GAAI,SAAwD,EAAE,KAAK,CAAC;IAE/E,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,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,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/E,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3B,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,UAAU,EAAG,CAAC,CAAC,MAAM,EAAE,UAAuD,EAAE,IAAI;YACpF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM;YACxB,SAAS,EAAE,CAAC,CAAC,aAAa;SAC7B,CAAC,CAAC;QACH,SAAS,EAAE,eAAe,CAAC,UAAU,CAAC;QACtC,OAAO;QACP,QAAQ,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9D,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;KACvC,CAAC;AACN,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { buildProjectGraph, type BuildGraphOptions } from "./build.js";
2
+ export { deriveResources, singularize, toPascal, segmentOf } from "./resources.js";
3
+ export { GraphProvider, type GraphProviderOptions } from "./provider.js";
4
+ export type { ProjectGraph, GraphProviderEntry, GraphRoute, GraphResource, GraphSchema, GraphBinding, GraphMigration, } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EACR,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,WAAW,EACX,YAAY,EACZ,cAAc,GACjB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { buildProjectGraph } from "./build.js";
2
+ export { deriveResources, singularize, toPascal, segmentOf } from "./resources.js";
3
+ export { GraphProvider } from "./provider.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA0B,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,aAAa,EAA6B,MAAM,eAAe,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { Provider, Application } from "@wild-framework/core";
2
+ /**
3
+ * Options for GraphProvider.
4
+ */
5
+ export interface GraphProviderOptions {
6
+ /** Application name. Defaults to "Wild Framework". */
7
+ appName?: string;
8
+ /** Application version. Defaults to "0.1.0". */
9
+ appVersion?: string;
10
+ /** HTTP path where the graph JSON is served. Default "/graph.json". */
11
+ path?: string;
12
+ }
13
+ /**
14
+ * Builds the Project Graph at boot and serves it over HTTP.
15
+ *
16
+ * - `register()`: binds a lazy `ProjectGraph` accessor into the container.
17
+ * - `boot()`: builds the graph and serves `GET /graph.json` via the Router.
18
+ *
19
+ * Register this provider AFTER all feature providers (like OpenApiProvider),
20
+ * so the route list is complete.
21
+ *
22
+ * This is the single introspection endpoint the Wild Studio visual builder
23
+ * and AI agents read — the GUI never holds its own model.
24
+ */
25
+ export declare class GraphProvider implements Provider {
26
+ /** Application name. */
27
+ static appName: string;
28
+ /** Application version. */
29
+ static appVersion: string;
30
+ /** HTTP path where the graph JSON is served. Default "/graph.json". */
31
+ static path: string;
32
+ private app;
33
+ private graph;
34
+ register(app: Application): void;
35
+ boot(app: Application): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMlE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAC1C,wBAAwB;IACxB,MAAM,CAAC,OAAO,SAAoB;IAClC,2BAA2B;IAC3B,MAAM,CAAC,UAAU,SAAW;IAC5B,uEAAuE;IACvE,MAAM,CAAC,IAAI,SAAiB;IAE5B,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,KAAK,CAA2B;IAExC,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAO1B,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAU9C"}
@@ -0,0 +1,41 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { Router } from "@wild-framework/http";
3
+ import { buildProjectGraph } from "./build.js";
4
+ /**
5
+ * Builds the Project Graph at boot and serves it over HTTP.
6
+ *
7
+ * - `register()`: binds a lazy `ProjectGraph` accessor into the container.
8
+ * - `boot()`: builds the graph and serves `GET /graph.json` via the Router.
9
+ *
10
+ * Register this provider AFTER all feature providers (like OpenApiProvider),
11
+ * so the route list is complete.
12
+ *
13
+ * This is the single introspection endpoint the Wild Studio visual builder
14
+ * and AI agents read — the GUI never holds its own model.
15
+ */
16
+ export class GraphProvider {
17
+ /** Application name. */
18
+ static appName = "Wild Framework";
19
+ /** Application version. */
20
+ static appVersion = "0.1.0";
21
+ /** HTTP path where the graph JSON is served. Default "/graph.json". */
22
+ static path = "/graph.json";
23
+ app;
24
+ graph;
25
+ register(app) {
26
+ this.app = app;
27
+ const container = app.resolve(Container);
28
+ // Bind the graph lazily — built on first resolve (after boot).
29
+ container.singleton("ProjectGraph", () => this.graph);
30
+ }
31
+ async boot(app) {
32
+ const router = app.resolve(Router);
33
+ this.graph = buildProjectGraph(app, router, {
34
+ name: GraphProvider.appName,
35
+ version: GraphProvider.appVersion,
36
+ });
37
+ // Serve the graph over HTTP for visual builders / agents.
38
+ router.get(GraphProvider.path, (_req, res) => res.json(this.graph));
39
+ }
40
+ }
41
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAe/C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IACtB,wBAAwB;IACxB,MAAM,CAAC,OAAO,GAAG,gBAAgB,CAAC;IAClC,2BAA2B;IAC3B,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;IAC5B,uEAAuE;IACvE,MAAM,CAAC,IAAI,GAAG,aAAa,CAAC;IAEpB,GAAG,CAA0B;IAC7B,KAAK,CAA2B;IAExC,QAAQ,CAAC,GAAgB;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACzC,+DAA+D;QAC/D,SAAS,CAAC,SAAS,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAgB;QACvB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAS,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE;YACxC,IAAI,EAAE,aAAa,CAAC,OAAO;YAC3B,OAAO,EAAE,aAAa,CAAC,UAAU;SACpC,CAAC,CAAC;QAEH,0DAA0D;QAC1D,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { RegisteredRoute } from "@wild-framework/http";
2
+ import type { GraphResource } from "./types.js";
3
+ /** PascalCase a kebab/lowercase string: "products" → "Products"; "user" → "User". */
4
+ export declare function toPascal(value: string): string;
5
+ /** Singularize a simple plural ("products" → "product"). */
6
+ export declare function singularize(word: string): string;
7
+ /** First non-empty path segment of a route, or "root". */
8
+ export declare function segmentOf(path: string): string;
9
+ /**
10
+ * Derive resources from a route list by grouping on the first path segment.
11
+ *
12
+ * Dynamic segments (`:id`) are dropped from the group key so `/products` and
13
+ * `/products/:id` belong to the same resource. Infrastructure routes
14
+ * (docs, openapi.json, graph.json, health) are excluded — they are not
15
+ * domain resources.
16
+ */
17
+ export declare function deriveResources(routes: RegisteredRoute[]): GraphResource[];
18
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,YAAY,CAAC;AAE5D,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED,4DAA4D;AAC5D,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,0DAA0D;AAC1D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C;AAqBD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,aAAa,EAAE,CAgB1E"}
@@ -0,0 +1,63 @@
1
+ /** PascalCase a kebab/lowercase string: "products" → "Products"; "user" → "User". */
2
+ export function toPascal(value) {
3
+ return value
4
+ .split(/[^A-Za-z0-9]+/)
5
+ .filter(Boolean)
6
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
7
+ .join("");
8
+ }
9
+ /** Singularize a simple plural ("products" → "product"). */
10
+ export function singularize(word) {
11
+ if (word.endsWith("ies"))
12
+ return word.slice(0, -3) + "y";
13
+ if (word.endsWith("s") && !word.endsWith("ss"))
14
+ return word.slice(0, -1);
15
+ return word;
16
+ }
17
+ /** First non-empty path segment of a route, or "root". */
18
+ export function segmentOf(path) {
19
+ const parts = path.split("/").filter(Boolean);
20
+ return parts[0] ?? "root";
21
+ }
22
+ function toGraphRoute(route) {
23
+ const ctor = route.action?.controller;
24
+ return {
25
+ method: route.method,
26
+ path: route.path,
27
+ controller: ctor?.name,
28
+ action: route.action?.method,
29
+ validator: route.validatorName,
30
+ };
31
+ }
32
+ /** Well-known infrastructure paths that are not domain resources. */
33
+ const INFRA_SEGMENTS = new Set([
34
+ "docs",
35
+ "openapi.json",
36
+ "graph.json",
37
+ "health",
38
+ ]);
39
+ /**
40
+ * Derive resources from a route list by grouping on the first path segment.
41
+ *
42
+ * Dynamic segments (`:id`) are dropped from the group key so `/products` and
43
+ * `/products/:id` belong to the same resource. Infrastructure routes
44
+ * (docs, openapi.json, graph.json, health) are excluded — they are not
45
+ * domain resources.
46
+ */
47
+ export function deriveResources(routes) {
48
+ const groups = new Map();
49
+ for (const route of routes) {
50
+ const segment = segmentOf(route.path);
51
+ if (INFRA_SEGMENTS.has(segment))
52
+ continue;
53
+ const existing = groups.get(segment) ?? [];
54
+ existing.push(toGraphRoute(route));
55
+ groups.set(segment, existing);
56
+ }
57
+ return [...groups.entries()].map(([segment, groupRoutes]) => ({
58
+ name: toPascal(singularize(segment)),
59
+ segment,
60
+ routes: groupRoutes,
61
+ }));
62
+ }
63
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAGA,qFAAqF;AACrF,MAAM,UAAU,QAAQ,CAAC,KAAa;IAClC,OAAO,KAAK;SACP,KAAK,CAAC,eAAe,CAAC;SACtB,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC3D,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACzE,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,IAAY;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;AAC9B,CAAC;AA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
2
+ * The Wild Framework Project Graph — a machine-readable model of a running
3
+ * application.
4
+ *
5
+ * This is the single source of truth that visual builders (Wild Studio) and
6
+ * AI agents render and manipulate. It is JSON-serializable and always
7
+ * derived from the live app, never hand-maintained.
8
+ */
9
+ export interface ProjectGraph {
10
+ /** Application name. */
11
+ name: string;
12
+ /** Application version. */
13
+ version: string;
14
+ /** Providers, in registration order. */
15
+ providers: GraphProviderEntry[];
16
+ /** Every registered HTTP route. */
17
+ routes: GraphRoute[];
18
+ /** Resources derived from routes (grouped by first path segment). */
19
+ resources: GraphResource[];
20
+ /** Request schemas (from Zod validators), keyed by validator class name. */
21
+ schemas: GraphSchema[];
22
+ /** Container bindings. */
23
+ bindings: GraphBinding[];
24
+ /** Migrations and their applied state. */
25
+ migrations: GraphMigration[];
26
+ }
27
+ /** A registered provider. */
28
+ export interface GraphProviderEntry {
29
+ /** Class name, e.g. "ProductProvider". */
30
+ name: string;
31
+ /** Zero-based registration order. */
32
+ index: number;
33
+ }
34
+ /** A registered HTTP route. */
35
+ export interface GraphRoute {
36
+ method: "get" | "post" | "put" | "patch" | "delete";
37
+ path: string;
38
+ /** Controller class name (from `action()`), if any. */
39
+ controller?: string;
40
+ /** Controller method name, if any. */
41
+ action?: string;
42
+ /** Validator class name, if any. */
43
+ validator?: string;
44
+ }
45
+ /** A resource — a group of routes sharing a first path segment. */
46
+ export interface GraphResource {
47
+ /** PascalCase singular name, e.g. "Product". */
48
+ name: string;
49
+ /** URL segment, e.g. "products". */
50
+ segment: string;
51
+ /** Routes belonging to this resource. */
52
+ routes: GraphRoute[];
53
+ }
54
+ /** A request schema (from a Zod validator class). */
55
+ export interface GraphSchema {
56
+ /** Validator class name, e.g. "CreateProductRequest". */
57
+ name: string;
58
+ /** Field name → simple type. */
59
+ fields: Record<string, "string" | "number" | "boolean" | "array" | "unknown">;
60
+ }
61
+ /** A container binding. */
62
+ export interface GraphBinding {
63
+ /** Token name (class name, string, or symbol). */
64
+ token: string;
65
+ }
66
+ /** A migration + applied state. */
67
+ export interface GraphMigration {
68
+ name: string;
69
+ applied: boolean;
70
+ }
71
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IACzB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,mCAAmC;IACnC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,qEAAqE;IACrE,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,4EAA4E;IAC5E,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,0BAA0B;IAC1B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,0CAA0C;IAC1C,UAAU,EAAE,cAAc,EAAE,CAAC;CAChC;AAED,6BAA6B;AAC7B,MAAM,WAAW,kBAAkB;IAC/B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,+BAA+B;AAC/B,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC1B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,MAAM,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,qDAAqD;AACrD,MAAM,WAAW,WAAW;IACxB,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CACjF;AAED,2BAA2B;AAC3B,MAAM,WAAW,YAAY;IACzB,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CACpB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@wild-framework/graph",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sphah",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/KhandaSoftware/wild-framework.git"
24
+ },
25
+ "description": "Machine-readable project graph (introspection) for Wild Framework apps — for visual builders and AI agents.",
26
+ "keywords": [
27
+ "wild",
28
+ "framework",
29
+ "graph",
30
+ "introspection",
31
+ "visual-builder",
32
+ "agents"
33
+ ],
34
+ "dependencies": {
35
+ "@wild-framework/core": "0.2.0",
36
+ "@wild-framework/container": "0.2.0",
37
+ "@wild-framework/database": "0.2.0",
38
+ "@wild-framework/http": "0.2.0"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc",
42
+ "clean": "rm -rf dist",
43
+ "test": "vitest run"
44
+ }
45
+ }