pastoria 1.0.8 → 1.0.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # pastoria
2
2
 
3
+ ## 1.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 1ae49d3: Update router generator to automatically create an entrypoint and
8
+ resource
9
+ - 4ed4588: Don't duplicate JSResource import when generating code
10
+ - e7e5519: Detect queries and entrypoints from type annotations
11
+
12
+ ## 1.0.9
13
+
14
+ ### Patch Changes
15
+
16
+ - 60ab948: Add support for routing shorthands
17
+ - 37afd6c: Add support for @serverRoute
18
+
3
19
  ## 1.0.8
4
20
 
5
21
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,YAAY,EACZ,KAAK,uBAAuB,EAE7B,MAAM,MAAM,CAAC;AA0Gd,eAAO,MAAM,YAAY,EAAE,uBAK1B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,uBAM1B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,uBAAuB,GAChC,YAAY,CAyBd;AAED,wBAAsB,WAAW,kBAUhC"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,YAAY,EACZ,KAAK,uBAAuB,EAE7B,MAAM,MAAM,CAAC;AA8Id,eAAO,MAAM,YAAY,EAAE,uBAK1B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,uBAM1B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,uBAAuB,GAChC,YAAY,CAyBd;AAED,wBAAsB,WAAW,kBAUhC"}
package/dist/build.js CHANGED
@@ -1,10 +1,9 @@
1
- import react from '@vitejs/plugin-react';
2
1
  import tailwindcss from '@tailwindcss/vite';
2
+ import react from '@vitejs/plugin-react';
3
3
  import { access } from 'node:fs/promises';
4
- import * as path from 'node:path';
5
- import { cjsInterop } from 'vite-plugin-cjs-interop';
6
4
  import { build, } from 'vite';
7
- function generateClientEntry(hasAppRoot) {
5
+ import { cjsInterop } from 'vite-plugin-cjs-interop';
6
+ function generateClientEntry({ hasAppRoot }) {
8
7
  const appImport = hasAppRoot
9
8
  ? `import {App} from '#genfiles/router/app_root';`
10
9
  : '';
@@ -22,11 +21,17 @@ async function main() {
22
21
  main();
23
22
  `;
24
23
  }
25
- function generateServerEntry(hasAppRoot) {
24
+ function generateServerEntry({ hasAppRoot, hasServerHandler, }) {
26
25
  const appImport = hasAppRoot
27
26
  ? `import {App} from '#genfiles/router/app_root';`
28
27
  : '';
29
28
  const appValue = hasAppRoot ? 'App' : 'null';
29
+ const serverHandlerImport = hasServerHandler
30
+ ? `import {router as serverHandler} from '#genfiles/router/server_handler';`
31
+ : '';
32
+ const serverHandlerUse = hasServerHandler
33
+ ? ' router.use(serverHandler)'
34
+ : '';
30
35
  return `// Generated by Pastoria.
31
36
  import {JSResource} from '#genfiles/router/js_resource';
32
37
  import {
@@ -37,6 +42,8 @@ import {
37
42
  import {getSchema} from '#genfiles/schema/schema';
38
43
  import {Context} from '#genfiles/router/context';
39
44
  ${appImport}
45
+ ${serverHandlerImport}
46
+ import express from 'express';
40
47
  import {GraphQLSchema, specifiedDirectives} from 'graphql';
41
48
  import {PastoriaConfig} from 'pastoria-config';
42
49
  import {createRouterHandler} from 'pastoria-runtime/server';
@@ -53,7 +60,7 @@ export function createHandler(
53
60
  config: Required<PastoriaConfig>,
54
61
  manifest?: Manifest,
55
62
  ) {
56
- return createRouterHandler(
63
+ const routeHandler = createRouterHandler(
57
64
  listRoutes(),
58
65
  JSResource.srcOfModuleId,
59
66
  router__loadEntryPoint,
@@ -65,9 +72,37 @@ export function createHandler(
65
72
  config,
66
73
  manifest,
67
74
  );
75
+
76
+ const router = express.Router();
77
+ router.use(routeHandler);
78
+ ${serverHandlerUse}
79
+
80
+ return router;
68
81
  }
69
82
  `;
70
83
  }
84
+ async function determineCapabilities() {
85
+ const capabilities = {
86
+ hasAppRoot: false,
87
+ hasServerHandler: false,
88
+ };
89
+ async function hasAppRoot() {
90
+ try {
91
+ await access('__generated__/router/app_root.ts');
92
+ capabilities.hasAppRoot = true;
93
+ }
94
+ catch { }
95
+ }
96
+ async function hasServerHandler() {
97
+ try {
98
+ await access('__generated__/router/server_handler.ts');
99
+ capabilities.hasServerHandler = true;
100
+ }
101
+ catch { }
102
+ }
103
+ await Promise.all([hasAppRoot(), hasServerHandler()]);
104
+ return capabilities;
105
+ }
71
106
  function pastoriaEntryPlugin() {
72
107
  const clientEntryModuleId = 'virtual:pastoria-entry-client.tsx';
73
108
  const serverEntryModuleId = 'virtual:pastoria-entry-server.tsx';
@@ -82,20 +117,12 @@ function pastoriaEntryPlugin() {
82
117
  }
83
118
  },
84
119
  async load(id) {
85
- const appRootPath = path.join(process.cwd(), '__generated__/router/app_root.ts');
86
- let hasAppRoot = false;
87
- try {
88
- await access(appRootPath);
89
- hasAppRoot = true;
90
- }
91
- catch {
92
- hasAppRoot = false;
93
- }
120
+ const capabilities = await determineCapabilities();
94
121
  if (id === clientEntryModuleId) {
95
- return generateClientEntry(hasAppRoot);
122
+ return generateClientEntry(capabilities);
96
123
  }
97
124
  else if (id === serverEntryModuleId) {
98
- return generateServerEntry(hasAppRoot);
125
+ return generateServerEntry(capabilities);
99
126
  }
100
127
  },
101
128
  };
package/dist/build.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAy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QAC9B,GAAG,iBAAiB,CAAC,YAAY,CAAC;QAClC,UAAU,EAAE,KAAK;KAClB,CAAC,CAAC;AACL,CAAC"}
@@ -20,6 +20,7 @@
20
20
  * - Add @resource <resource-name> to exports for lazy loading
21
21
  * - Add @appRoot to a component to designate it as the application root wrapper
22
22
  * - Add @gqlContext to a class extending PastoriaRootContext to provide a custom GraphQL context
23
+ * - Add @serverRoute to functions to add an express handler
23
24
  *
24
25
  * The generator automatically creates Zod schemas for route parameters based on
25
26
  * TypeScript types, enabling runtime validation and type safety.
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AA6OH,wBAAsB,yBAAyB,kBA6L9C"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAotBH,wBAAsB,yBAAyB,kBAgB9C"}