pastoria 1.1.0 → 1.2.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.
@@ -1,61 +1,58 @@
1
1
  /**
2
2
  * @fileoverview Router Code Generator
3
3
  *
4
- * This script generates type-safe router configuration files by scanning TypeScript
5
- * source code for JSDoc annotations. It's part of the "Pastoria" routing framework.
6
- *
7
- * How it works:
8
- * 1. Scans all TypeScript files in the project for exported functions/classes
9
- * 2. Looks for JSDoc tags: @route, @resource, @appRoot, and @param
10
- * 3. Looks for exported classes that extend PastoriaRootContext for GraphQL context
11
- * 4. Generates files from templates:
12
- * - js_resource.ts: Resource configuration for lazy loading
13
- * - router.tsx: Client-side router with type-safe routes
14
- * - app_root.ts: Re-export of the app root component (if @appRoot is found)
15
- * - context.ts: Re-export of user's context class, or generate a default one
16
- *
17
- * Usage:
18
- * - Add @route <route-name> to functions to create routes
19
- * - Add @param <name> <type> to document route parameters
20
- * - Add @resource <resource-name> to exports for lazy loading
21
- * - Add @appRoot to a component to designate it as the application root wrapper
22
- * - Add @gqlContext to a class extending PastoriaRootContext to provide a custom GraphQL context
23
- * - Add @serverRoute to functions to add an express handler
24
- *
25
- * The generator automatically creates Zod schemas for route parameters based on
26
- * TypeScript types, enabling runtime validation and type safety.
4
+ * This script generates type-safe router configuration files using filesystem-based
5
+ * routing, similar to Next.js App Router.
6
+ *
7
+ * ## Filesystem Routing Convention
8
+ *
9
+ * Routes are defined by the directory structure under `pastoria/`:
10
+ * - `pastoria/page.tsx` Route `/`
11
+ * - `pastoria/about/page.tsx` Route `/about`
12
+ * - `pastoria/post/[slug]/page.tsx` Route `/post/:slug`
13
+ * - `pastoria/app.tsx` Root layout component
14
+ * - `pastoria/api/.../route.ts` API route handlers
15
+ * - `pastoria/*.page.tsx` Nested entry points
16
+ * - `pastoria/entrypoint.ts` → Manual entry point definitions
17
+ *
18
+ * ## Page Files
19
+ *
20
+ * Each `page.tsx` should:
21
+ * - Default export a React component
22
+ * - Optionally export `queries` object mapping query refs to Relay query types
23
+ *
24
+ * ## Generated Files
25
+ *
26
+ * Output is placed in `__generated__/router/`:
27
+ * - `js_resource.ts` - Resource configuration for lazy loading
28
+ * - `router.tsx` - Client-side router with type-safe routes
29
+ * - `app_root.ts` - Re-export of the app root component
30
+ * - `environment.ts` - Re-export of the user's PastoriaEnvironment
31
+ * - `server_handler.ts` - API route handlers
32
+ * - `types.ts` - PageProps and other type definitions
27
33
  */
28
- import { Project, SourceFile, Symbol, ts } from 'ts-morph';
29
- type RouterResource = {
30
- sourceFile: SourceFile;
31
- symbol: Symbol;
32
- queries: Map<string, string>;
33
- entryPoints: Map<string, string>;
34
- };
35
- type RouterRoute = {
36
- sourceFile: SourceFile;
37
- symbol: Symbol;
38
- params: Map<string, ts.Type>;
39
- };
40
- type ExportedSymbol = {
41
- sourceFile: SourceFile;
42
- symbol: Symbol;
43
- };
44
- export interface PastoriaMetadata {
45
- resources: Map<string, RouterResource>;
46
- routes: Map<string, RouterRoute>;
47
- serverHandlers: Map<string, ExportedSymbol>;
48
- appRoot: ExportedSymbol | null;
49
- gqlContext: ExportedSymbol | null;
50
- }
51
- export declare const PASTORIA_TAG_REGEX: RegExp;
52
- export declare function generatePastoriaExports(project: Project): Promise<PastoriaMetadata>;
53
- export declare function generatePastoriaArtifacts(project: Project, metadata?: PastoriaMetadata): Promise<void>;
34
+ import { Project } from 'ts-morph';
35
+ import { type FilesystemMetadata } from './filesystem.js';
36
+ /**
37
+ * Generates all Pastoria artifacts from the filesystem.
38
+ *
39
+ * This is the main entry point for code generation.
40
+ */
41
+ export declare function generatePastoriaArtifacts(project: Project): Promise<FilesystemMetadata>;
54
42
  export interface PastoriaCapabilities {
55
43
  hasAppRoot: boolean;
56
44
  hasServerHandler: boolean;
57
45
  }
46
+ /**
47
+ * Detects what capabilities are available based on source files.
48
+ */
49
+ export declare function detectCapabilities(): Promise<PastoriaCapabilities>;
50
+ /**
51
+ * Generates the client entry point code.
52
+ */
58
53
  export declare function generateClientEntry({ hasAppRoot, }: PastoriaCapabilities): string;
54
+ /**
55
+ * Generates the server entry point code.
56
+ */
59
57
  export declare function generateServerEntry({ hasAppRoot, hasServerHandler, }: PastoriaCapabilities): string;
60
- export {};
61
58
  //# sourceMappingURL=generate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,OAAO,EAEL,OAAO,EACP,UAAU,EACV,MAAM,EAEN,EAAE,EAEH,MAAM,UAAU,CAAC;AAsBlB,KAAK,cAAc,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/B,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;CACnC;AAGD,eAAO,MAAM,kBAAkB,QAC6B,CAAC;AAgtB7D,wBAAsB,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