@constructive-io/graphql-codegen 2.31.0 → 3.0.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.
Files changed (270) hide show
  1. package/README.md +429 -1691
  2. package/cli/index.d.ts +5 -2
  3. package/cli/index.js +98 -581
  4. package/cli/shared.d.ts +35 -0
  5. package/cli/shared.js +106 -0
  6. package/{esm/cli → core}/codegen/barrel.d.ts +1 -1
  7. package/{cli → core}/codegen/barrel.js +1 -4
  8. package/{esm/cli → core}/codegen/index.d.ts +15 -5
  9. package/{cli → core}/codegen/index.js +44 -24
  10. package/{cli → core}/codegen/invalidation.d.ts +2 -2
  11. package/{esm/cli → core}/codegen/mutation-keys.d.ts +2 -2
  12. package/{cli → core}/codegen/orm/client-generator.js +2 -3
  13. package/{esm/cli → core}/codegen/orm/index.d.ts +9 -2
  14. package/{cli → core}/codegen/orm/index.js +3 -2
  15. package/{cli → core}/codegen/query-keys.d.ts +2 -2
  16. package/core/codegen/shared/index.d.ts +39 -0
  17. package/core/codegen/shared/index.js +118 -0
  18. package/core/config/index.d.ts +5 -0
  19. package/core/config/index.js +13 -0
  20. package/core/config/loader.d.ts +18 -0
  21. package/{cli/commands/init.js → core/config/loader.js} +7 -94
  22. package/core/config/resolver.d.ts +46 -0
  23. package/core/config/resolver.js +104 -0
  24. package/core/database/index.d.ts +43 -0
  25. package/core/database/index.js +85 -0
  26. package/core/generate.d.ts +22 -0
  27. package/core/generate.js +192 -0
  28. package/core/index.d.ts +13 -1
  29. package/core/index.js +22 -2
  30. package/{cli → core}/introspect/fetch-schema.js +58 -9
  31. package/core/introspect/source/api-schemas.d.ts +44 -0
  32. package/core/introspect/source/api-schemas.js +122 -0
  33. package/core/introspect/source/database.d.ts +32 -0
  34. package/core/introspect/source/database.js +91 -0
  35. package/core/introspect/source/index.d.ts +112 -0
  36. package/core/introspect/source/index.js +173 -0
  37. package/core/introspect/source/pgpm-module.d.ts +83 -0
  38. package/core/introspect/source/pgpm-module.js +200 -0
  39. package/core/output/index.d.ts +4 -0
  40. package/core/output/index.js +9 -0
  41. package/core/output/writer.d.ts +38 -0
  42. package/core/output/writer.js +156 -0
  43. package/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
  44. package/{cli/commands/shared.js → core/pipeline/index.js} +12 -5
  45. package/{cli → core}/watch/orchestrator.d.ts +25 -3
  46. package/{cli → core}/watch/orchestrator.js +35 -27
  47. package/{cli → core}/watch/types.d.ts +1 -1
  48. package/esm/cli/index.d.ts +5 -2
  49. package/esm/cli/index.js +97 -547
  50. package/esm/cli/shared.d.ts +35 -0
  51. package/esm/cli/shared.js +101 -0
  52. package/{cli → esm/core}/codegen/barrel.d.ts +1 -1
  53. package/esm/{cli → core}/codegen/barrel.js +1 -4
  54. package/{cli → esm/core}/codegen/index.d.ts +15 -5
  55. package/esm/{cli → core}/codegen/index.js +44 -24
  56. package/esm/{cli → core}/codegen/invalidation.d.ts +2 -2
  57. package/{cli → esm/core}/codegen/mutation-keys.d.ts +2 -2
  58. package/esm/{cli → core}/codegen/orm/client-generator.js +2 -3
  59. package/{cli → esm/core}/codegen/orm/index.d.ts +9 -2
  60. package/esm/{cli → core}/codegen/orm/index.js +3 -2
  61. package/esm/{cli → core}/codegen/query-keys.d.ts +2 -2
  62. package/esm/core/codegen/shared/index.d.ts +39 -0
  63. package/esm/core/codegen/shared/index.js +79 -0
  64. package/esm/core/config/index.d.ts +5 -0
  65. package/esm/core/config/index.js +5 -0
  66. package/esm/core/config/loader.d.ts +18 -0
  67. package/esm/core/config/loader.js +71 -0
  68. package/esm/core/config/resolver.d.ts +46 -0
  69. package/esm/core/config/resolver.js +100 -0
  70. package/esm/core/database/index.d.ts +43 -0
  71. package/esm/core/database/index.js +48 -0
  72. package/esm/core/generate.d.ts +22 -0
  73. package/esm/core/generate.js +186 -0
  74. package/esm/core/index.d.ts +13 -1
  75. package/esm/core/index.js +20 -1
  76. package/esm/{cli → core}/introspect/fetch-schema.js +55 -9
  77. package/esm/core/introspect/source/api-schemas.d.ts +44 -0
  78. package/esm/core/introspect/source/api-schemas.js +117 -0
  79. package/esm/core/introspect/source/database.d.ts +32 -0
  80. package/esm/core/introspect/source/database.js +87 -0
  81. package/esm/core/introspect/source/index.d.ts +112 -0
  82. package/esm/core/introspect/source/index.js +154 -0
  83. package/esm/core/introspect/source/pgpm-module.d.ts +83 -0
  84. package/esm/core/introspect/source/pgpm-module.js +194 -0
  85. package/esm/core/output/index.d.ts +4 -0
  86. package/esm/core/output/index.js +4 -0
  87. package/esm/core/output/writer.d.ts +38 -0
  88. package/esm/core/output/writer.js +119 -0
  89. package/esm/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
  90. package/esm/{cli/commands/shared.js → core/pipeline/index.js} +9 -5
  91. package/esm/{cli → core}/watch/orchestrator.d.ts +25 -3
  92. package/esm/{cli → core}/watch/orchestrator.js +35 -27
  93. package/esm/{cli → core}/watch/types.d.ts +1 -1
  94. package/esm/index.d.ts +8 -3
  95. package/esm/index.js +9 -3
  96. package/esm/types/config.d.ts +110 -136
  97. package/esm/types/config.js +23 -148
  98. package/esm/types/index.d.ts +2 -2
  99. package/esm/types/index.js +1 -1
  100. package/index.d.ts +8 -3
  101. package/index.js +18 -8
  102. package/package.json +19 -11
  103. package/types/config.d.ts +110 -136
  104. package/types/config.js +28 -152
  105. package/types/index.d.ts +2 -2
  106. package/types/index.js +3 -3
  107. package/cli/commands/generate-orm.d.ts +0 -53
  108. package/cli/commands/generate-orm.js +0 -292
  109. package/cli/commands/generate.d.ts +0 -66
  110. package/cli/commands/generate.js +0 -431
  111. package/cli/commands/index.d.ts +0 -9
  112. package/cli/commands/index.js +0 -14
  113. package/cli/commands/init.d.ts +0 -35
  114. package/cli/introspect/source/index.d.ts +0 -48
  115. package/cli/introspect/source/index.js +0 -72
  116. package/esm/cli/commands/generate-orm.d.ts +0 -53
  117. package/esm/cli/commands/generate-orm.js +0 -289
  118. package/esm/cli/commands/generate.d.ts +0 -66
  119. package/esm/cli/commands/generate.js +0 -393
  120. package/esm/cli/commands/index.d.ts +0 -9
  121. package/esm/cli/commands/index.js +0 -6
  122. package/esm/cli/commands/init.d.ts +0 -35
  123. package/esm/cli/commands/init.js +0 -158
  124. package/esm/cli/introspect/source/index.d.ts +0 -48
  125. package/esm/cli/introspect/source/index.js +0 -54
  126. /package/{cli → core}/codegen/babel-ast.d.ts +0 -0
  127. /package/{cli → core}/codegen/babel-ast.js +0 -0
  128. /package/{cli → core}/codegen/client.d.ts +0 -0
  129. /package/{cli → core}/codegen/client.js +0 -0
  130. /package/{cli → core}/codegen/custom-mutations.d.ts +0 -0
  131. /package/{cli → core}/codegen/custom-mutations.js +0 -0
  132. /package/{cli → core}/codegen/custom-queries.d.ts +0 -0
  133. /package/{cli → core}/codegen/custom-queries.js +0 -0
  134. /package/{cli → core}/codegen/gql-ast.d.ts +0 -0
  135. /package/{cli → core}/codegen/gql-ast.js +0 -0
  136. /package/{cli → core}/codegen/invalidation.js +0 -0
  137. /package/{cli → core}/codegen/mutation-keys.js +0 -0
  138. /package/{cli → core}/codegen/mutations.d.ts +0 -0
  139. /package/{cli → core}/codegen/mutations.js +0 -0
  140. /package/{cli → core}/codegen/orm/barrel.d.ts +0 -0
  141. /package/{cli → core}/codegen/orm/barrel.js +0 -0
  142. /package/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
  143. /package/{cli → core}/codegen/orm/client.d.ts +0 -0
  144. /package/{cli → core}/codegen/orm/client.js +0 -0
  145. /package/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
  146. /package/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
  147. /package/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
  148. /package/{cli → core}/codegen/orm/input-types-generator.js +0 -0
  149. /package/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
  150. /package/{cli → core}/codegen/orm/model-generator.js +0 -0
  151. /package/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
  152. /package/{cli → core}/codegen/orm/query-builder.js +0 -0
  153. /package/{cli → core}/codegen/orm/query-builder.ts +0 -0
  154. /package/{cli → core}/codegen/orm/select-types.d.ts +0 -0
  155. /package/{cli → core}/codegen/orm/select-types.js +0 -0
  156. /package/{cli → core}/codegen/queries.d.ts +0 -0
  157. /package/{cli → core}/codegen/queries.js +0 -0
  158. /package/{cli → core}/codegen/query-keys.js +0 -0
  159. /package/{cli → core}/codegen/scalars.d.ts +0 -0
  160. /package/{cli → core}/codegen/scalars.js +0 -0
  161. /package/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
  162. /package/{cli → core}/codegen/schema-gql-ast.js +0 -0
  163. /package/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
  164. /package/{cli → core}/codegen/schema-types-generator.js +0 -0
  165. /package/{cli → core}/codegen/type-resolver.d.ts +0 -0
  166. /package/{cli → core}/codegen/type-resolver.js +0 -0
  167. /package/{cli → core}/codegen/types.d.ts +0 -0
  168. /package/{cli → core}/codegen/types.js +0 -0
  169. /package/{cli → core}/codegen/utils.d.ts +0 -0
  170. /package/{cli → core}/codegen/utils.js +0 -0
  171. /package/{cli → core}/introspect/fetch-schema.d.ts +0 -0
  172. /package/{cli → core}/introspect/index.d.ts +0 -0
  173. /package/{cli → core}/introspect/index.js +0 -0
  174. /package/{cli → core}/introspect/infer-tables.d.ts +0 -0
  175. /package/{cli → core}/introspect/infer-tables.js +0 -0
  176. /package/{cli → core}/introspect/schema-query.d.ts +0 -0
  177. /package/{cli → core}/introspect/schema-query.js +0 -0
  178. /package/{cli → core}/introspect/source/endpoint.d.ts +0 -0
  179. /package/{cli → core}/introspect/source/endpoint.js +0 -0
  180. /package/{cli → core}/introspect/source/file.d.ts +0 -0
  181. /package/{cli → core}/introspect/source/file.js +0 -0
  182. /package/{cli → core}/introspect/source/types.d.ts +0 -0
  183. /package/{cli → core}/introspect/source/types.js +0 -0
  184. /package/{cli → core}/introspect/transform-schema.d.ts +0 -0
  185. /package/{cli → core}/introspect/transform-schema.js +0 -0
  186. /package/{cli → core}/introspect/transform.d.ts +0 -0
  187. /package/{cli → core}/introspect/transform.js +0 -0
  188. /package/{cli → core}/watch/cache.d.ts +0 -0
  189. /package/{cli → core}/watch/cache.js +0 -0
  190. /package/{cli → core}/watch/debounce.d.ts +0 -0
  191. /package/{cli → core}/watch/debounce.js +0 -0
  192. /package/{cli → core}/watch/hash.d.ts +0 -0
  193. /package/{cli → core}/watch/hash.js +0 -0
  194. /package/{cli → core}/watch/index.d.ts +0 -0
  195. /package/{cli → core}/watch/index.js +0 -0
  196. /package/{cli → core}/watch/poller.d.ts +0 -0
  197. /package/{cli → core}/watch/poller.js +0 -0
  198. /package/{cli → core}/watch/types.js +0 -0
  199. /package/esm/{cli → core}/codegen/babel-ast.d.ts +0 -0
  200. /package/esm/{cli → core}/codegen/babel-ast.js +0 -0
  201. /package/esm/{cli → core}/codegen/client.d.ts +0 -0
  202. /package/esm/{cli → core}/codegen/client.js +0 -0
  203. /package/esm/{cli → core}/codegen/custom-mutations.d.ts +0 -0
  204. /package/esm/{cli → core}/codegen/custom-mutations.js +0 -0
  205. /package/esm/{cli → core}/codegen/custom-queries.d.ts +0 -0
  206. /package/esm/{cli → core}/codegen/custom-queries.js +0 -0
  207. /package/esm/{cli → core}/codegen/gql-ast.d.ts +0 -0
  208. /package/esm/{cli → core}/codegen/gql-ast.js +0 -0
  209. /package/esm/{cli → core}/codegen/invalidation.js +0 -0
  210. /package/esm/{cli → core}/codegen/mutation-keys.js +0 -0
  211. /package/esm/{cli → core}/codegen/mutations.d.ts +0 -0
  212. /package/esm/{cli → core}/codegen/mutations.js +0 -0
  213. /package/esm/{cli → core}/codegen/orm/barrel.d.ts +0 -0
  214. /package/esm/{cli → core}/codegen/orm/barrel.js +0 -0
  215. /package/esm/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
  216. /package/esm/{cli → core}/codegen/orm/client.d.ts +0 -0
  217. /package/esm/{cli → core}/codegen/orm/client.js +0 -0
  218. /package/esm/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
  219. /package/esm/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
  220. /package/esm/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
  221. /package/esm/{cli → core}/codegen/orm/input-types-generator.js +0 -0
  222. /package/esm/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
  223. /package/esm/{cli → core}/codegen/orm/model-generator.js +0 -0
  224. /package/esm/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
  225. /package/esm/{cli → core}/codegen/orm/query-builder.js +0 -0
  226. /package/esm/{cli → core}/codegen/orm/select-types.d.ts +0 -0
  227. /package/esm/{cli → core}/codegen/orm/select-types.js +0 -0
  228. /package/esm/{cli → core}/codegen/queries.d.ts +0 -0
  229. /package/esm/{cli → core}/codegen/queries.js +0 -0
  230. /package/esm/{cli → core}/codegen/query-keys.js +0 -0
  231. /package/esm/{cli → core}/codegen/scalars.d.ts +0 -0
  232. /package/esm/{cli → core}/codegen/scalars.js +0 -0
  233. /package/esm/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
  234. /package/esm/{cli → core}/codegen/schema-gql-ast.js +0 -0
  235. /package/esm/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
  236. /package/esm/{cli → core}/codegen/schema-types-generator.js +0 -0
  237. /package/esm/{cli → core}/codegen/type-resolver.d.ts +0 -0
  238. /package/esm/{cli → core}/codegen/type-resolver.js +0 -0
  239. /package/esm/{cli → core}/codegen/types.d.ts +0 -0
  240. /package/esm/{cli → core}/codegen/types.js +0 -0
  241. /package/esm/{cli → core}/codegen/utils.d.ts +0 -0
  242. /package/esm/{cli → core}/codegen/utils.js +0 -0
  243. /package/esm/{cli → core}/introspect/fetch-schema.d.ts +0 -0
  244. /package/esm/{cli → core}/introspect/index.d.ts +0 -0
  245. /package/esm/{cli → core}/introspect/index.js +0 -0
  246. /package/esm/{cli → core}/introspect/infer-tables.d.ts +0 -0
  247. /package/esm/{cli → core}/introspect/infer-tables.js +0 -0
  248. /package/esm/{cli → core}/introspect/schema-query.d.ts +0 -0
  249. /package/esm/{cli → core}/introspect/schema-query.js +0 -0
  250. /package/esm/{cli → core}/introspect/source/endpoint.d.ts +0 -0
  251. /package/esm/{cli → core}/introspect/source/endpoint.js +0 -0
  252. /package/esm/{cli → core}/introspect/source/file.d.ts +0 -0
  253. /package/esm/{cli → core}/introspect/source/file.js +0 -0
  254. /package/esm/{cli → core}/introspect/source/types.d.ts +0 -0
  255. /package/esm/{cli → core}/introspect/source/types.js +0 -0
  256. /package/esm/{cli → core}/introspect/transform-schema.d.ts +0 -0
  257. /package/esm/{cli → core}/introspect/transform-schema.js +0 -0
  258. /package/esm/{cli → core}/introspect/transform.d.ts +0 -0
  259. /package/esm/{cli → core}/introspect/transform.js +0 -0
  260. /package/esm/{cli → core}/watch/cache.d.ts +0 -0
  261. /package/esm/{cli → core}/watch/cache.js +0 -0
  262. /package/esm/{cli → core}/watch/debounce.d.ts +0 -0
  263. /package/esm/{cli → core}/watch/debounce.js +0 -0
  264. /package/esm/{cli → core}/watch/hash.d.ts +0 -0
  265. /package/esm/{cli → core}/watch/hash.js +0 -0
  266. /package/esm/{cli → core}/watch/index.d.ts +0 -0
  267. /package/esm/{cli → core}/watch/index.js +0 -0
  268. /package/esm/{cli → core}/watch/poller.d.ts +0 -0
  269. /package/esm/{cli → core}/watch/poller.js +0 -0
  270. /package/esm/{cli → core}/watch/types.js +0 -0
@@ -0,0 +1,83 @@
1
+ import type { SchemaSource, SchemaSourceResult } from './types';
2
+ /**
3
+ * Options for PGPM module schema source using direct module path
4
+ */
5
+ export interface PgpmModulePathOptions {
6
+ /**
7
+ * Path to the PGPM module directory
8
+ * The directory should contain a pgpm.plan file and .control file
9
+ */
10
+ pgpmModulePath: string;
11
+ /**
12
+ * PostgreSQL schemas to include in introspection
13
+ * Mutually exclusive with apiNames
14
+ */
15
+ schemas?: string[];
16
+ /**
17
+ * API names to resolve schemas from
18
+ * Queries services_public.api_schemas to get schema names
19
+ * Mutually exclusive with schemas
20
+ */
21
+ apiNames?: string[];
22
+ /**
23
+ * If true, keeps the ephemeral database after introspection (useful for debugging)
24
+ * @default false
25
+ */
26
+ keepDb?: boolean;
27
+ }
28
+ /**
29
+ * Options for PGPM module schema source using workspace + module name
30
+ */
31
+ export interface PgpmWorkspaceOptions {
32
+ /**
33
+ * Path to the PGPM workspace directory
34
+ * The directory should contain a pgpm.config.yaml or similar workspace config
35
+ */
36
+ pgpmWorkspacePath: string;
37
+ /**
38
+ * Name of the module within the workspace
39
+ */
40
+ pgpmModuleName: string;
41
+ /**
42
+ * PostgreSQL schemas to include in introspection
43
+ * Mutually exclusive with apiNames
44
+ */
45
+ schemas?: string[];
46
+ /**
47
+ * API names to resolve schemas from
48
+ * Queries services_public.api_schemas to get schema names
49
+ * Mutually exclusive with schemas
50
+ */
51
+ apiNames?: string[];
52
+ /**
53
+ * If true, keeps the ephemeral database after introspection (useful for debugging)
54
+ * @default false
55
+ */
56
+ keepDb?: boolean;
57
+ }
58
+ export type PgpmModuleSchemaSourceOptions = PgpmModulePathOptions | PgpmWorkspaceOptions;
59
+ /**
60
+ * Type guard to check if options use direct module path
61
+ */
62
+ export declare function isPgpmModulePathOptions(options: PgpmModuleSchemaSourceOptions): options is PgpmModulePathOptions;
63
+ /**
64
+ * Type guard to check if options use workspace + module name
65
+ */
66
+ export declare function isPgpmWorkspaceOptions(options: PgpmModuleSchemaSourceOptions): options is PgpmWorkspaceOptions;
67
+ /**
68
+ * Schema source that loads from a PGPM module
69
+ *
70
+ * Creates an ephemeral database, deploys the module, introspects the schema,
71
+ * and cleans up. Supports both direct module path and workspace + module name modes.
72
+ */
73
+ export declare class PgpmModuleSchemaSource implements SchemaSource {
74
+ private readonly options;
75
+ private ephemeralDb;
76
+ constructor(options: PgpmModuleSchemaSourceOptions);
77
+ fetch(): Promise<SchemaSourceResult>;
78
+ describe(): string;
79
+ private resolveModulePath;
80
+ private getSchemas;
81
+ private getApiNames;
82
+ private getKeepDb;
83
+ }
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PgpmModuleSchemaSource = void 0;
4
+ exports.isPgpmModulePathOptions = isPgpmModulePathOptions;
5
+ exports.isPgpmWorkspaceOptions = isPgpmWorkspaceOptions;
6
+ /**
7
+ * PGPM Module Schema Source
8
+ *
9
+ * Loads GraphQL schema from a PGPM module by:
10
+ * 1. Creating an ephemeral database
11
+ * 2. Deploying the module to the database
12
+ * 3. Introspecting the database with PostGraphile
13
+ * 4. Cleaning up the ephemeral database (unless keepDb is true)
14
+ */
15
+ const graphql_1 = require("graphql");
16
+ const core_1 = require("@pgpmjs/core");
17
+ const pgsql_client_1 = require("pgsql-client");
18
+ const pgsql_seed_1 = require("pgsql-seed");
19
+ const pg_cache_1 = require("pg-cache");
20
+ const types_1 = require("./types");
21
+ const database_1 = require("../../database");
22
+ const api_schemas_1 = require("./api-schemas");
23
+ /**
24
+ * Type guard to check if options use direct module path
25
+ */
26
+ function isPgpmModulePathOptions(options) {
27
+ return 'pgpmModulePath' in options;
28
+ }
29
+ /**
30
+ * Type guard to check if options use workspace + module name
31
+ */
32
+ function isPgpmWorkspaceOptions(options) {
33
+ return 'pgpmWorkspacePath' in options && 'pgpmModuleName' in options;
34
+ }
35
+ /**
36
+ * Schema source that loads from a PGPM module
37
+ *
38
+ * Creates an ephemeral database, deploys the module, introspects the schema,
39
+ * and cleans up. Supports both direct module path and workspace + module name modes.
40
+ */
41
+ class PgpmModuleSchemaSource {
42
+ options;
43
+ ephemeralDb = null;
44
+ constructor(options) {
45
+ this.options = options;
46
+ }
47
+ async fetch() {
48
+ const keepDb = this.getKeepDb();
49
+ const apiNames = this.getApiNames();
50
+ // Resolve the module path
51
+ let modulePath;
52
+ try {
53
+ modulePath = this.resolveModulePath();
54
+ }
55
+ catch (err) {
56
+ throw new types_1.SchemaSourceError(`Failed to resolve module path: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
57
+ }
58
+ // Validate the module exists
59
+ const pkg = new core_1.PgpmPackage(modulePath);
60
+ if (!pkg.isInModule()) {
61
+ throw new types_1.SchemaSourceError(`Not a valid PGPM module: ${modulePath}. Directory must contain pgpm.plan and .control files.`, this.describe());
62
+ }
63
+ // Create ephemeral database
64
+ try {
65
+ this.ephemeralDb = (0, pgsql_client_1.createEphemeralDb)({
66
+ prefix: 'codegen_pgpm_',
67
+ verbose: false,
68
+ });
69
+ }
70
+ catch (err) {
71
+ throw new types_1.SchemaSourceError(`Failed to create ephemeral database: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
72
+ }
73
+ const { config: dbConfig, teardown } = this.ephemeralDb;
74
+ try {
75
+ // Deploy the module to the ephemeral database
76
+ try {
77
+ await (0, pgsql_seed_1.deployPgpm)(dbConfig, modulePath, false);
78
+ }
79
+ catch (err) {
80
+ throw new types_1.SchemaSourceError(`Failed to deploy PGPM module: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
81
+ }
82
+ // Resolve schemas - either from explicit schemas option or from apiNames (after deployment)
83
+ let schemas;
84
+ if (apiNames && apiNames.length > 0) {
85
+ // For PGPM mode, validate services schemas AFTER migration
86
+ const pool = (0, pg_cache_1.getPgPool)(dbConfig);
87
+ try {
88
+ const validation = await (0, api_schemas_1.validateServicesSchemas)(pool);
89
+ if (!validation.valid) {
90
+ throw new types_1.SchemaSourceError(validation.error, this.describe());
91
+ }
92
+ schemas = await (0, api_schemas_1.resolveApiSchemas)(pool, apiNames);
93
+ }
94
+ catch (err) {
95
+ if (err instanceof types_1.SchemaSourceError)
96
+ throw err;
97
+ throw new types_1.SchemaSourceError(`Failed to resolve API schemas: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
98
+ }
99
+ }
100
+ else {
101
+ schemas = this.getSchemas();
102
+ }
103
+ // Build SDL from the deployed database
104
+ let sdl;
105
+ try {
106
+ sdl = await (0, database_1.buildSchemaSDLFromDatabase)({
107
+ database: dbConfig.database,
108
+ schemas,
109
+ });
110
+ }
111
+ catch (err) {
112
+ throw new types_1.SchemaSourceError(`Failed to introspect database: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
113
+ }
114
+ // Validate non-empty
115
+ if (!sdl.trim()) {
116
+ throw new types_1.SchemaSourceError('Database introspection returned empty schema', this.describe());
117
+ }
118
+ // Parse SDL to GraphQL schema
119
+ let schema;
120
+ try {
121
+ schema = (0, graphql_1.buildSchema)(sdl);
122
+ }
123
+ catch (err) {
124
+ throw new types_1.SchemaSourceError(`Invalid GraphQL SDL from database: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
125
+ }
126
+ // Convert to introspection format
127
+ let introspectionResult;
128
+ try {
129
+ introspectionResult = (0, graphql_1.introspectionFromSchema)(schema);
130
+ }
131
+ catch (err) {
132
+ throw new types_1.SchemaSourceError(`Failed to generate introspection: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
133
+ }
134
+ // Convert graphql-js introspection result to our mutable type
135
+ const introspection = JSON.parse(JSON.stringify(introspectionResult));
136
+ return { introspection };
137
+ }
138
+ finally {
139
+ // Clean up the ephemeral database
140
+ teardown({ keepDb });
141
+ if (keepDb) {
142
+ console.log(`[pgpm-module] Kept ephemeral database: ${dbConfig.database}`);
143
+ }
144
+ }
145
+ }
146
+ describe() {
147
+ const apiNames = this.getApiNames();
148
+ if (isPgpmModulePathOptions(this.options)) {
149
+ if (apiNames && apiNames.length > 0) {
150
+ return `pgpm module: ${this.options.pgpmModulePath} (apiNames: ${apiNames.join(', ')})`;
151
+ }
152
+ const schemas = this.options.schemas ?? ['public'];
153
+ return `pgpm module: ${this.options.pgpmModulePath} (schemas: ${schemas.join(', ')})`;
154
+ }
155
+ else {
156
+ if (apiNames && apiNames.length > 0) {
157
+ return `pgpm workspace: ${this.options.pgpmWorkspacePath}, module: ${this.options.pgpmModuleName} (apiNames: ${apiNames.join(', ')})`;
158
+ }
159
+ const schemas = this.options.schemas ?? ['public'];
160
+ return `pgpm workspace: ${this.options.pgpmWorkspacePath}, module: ${this.options.pgpmModuleName} (schemas: ${schemas.join(', ')})`;
161
+ }
162
+ }
163
+ resolveModulePath() {
164
+ if (isPgpmModulePathOptions(this.options)) {
165
+ return this.options.pgpmModulePath;
166
+ }
167
+ // Workspace + module name mode
168
+ const { pgpmWorkspacePath, pgpmModuleName } = this.options;
169
+ const workspace = new core_1.PgpmPackage(pgpmWorkspacePath);
170
+ if (!workspace.workspacePath) {
171
+ throw new Error(`Not a valid PGPM workspace: ${pgpmWorkspacePath}`);
172
+ }
173
+ // Get the module from the workspace
174
+ const moduleProject = workspace.getModuleProject(pgpmModuleName);
175
+ const modulePath = moduleProject.getModulePath();
176
+ if (!modulePath) {
177
+ throw new Error(`Module "${pgpmModuleName}" not found in workspace`);
178
+ }
179
+ return modulePath;
180
+ }
181
+ getSchemas() {
182
+ if (isPgpmModulePathOptions(this.options)) {
183
+ return this.options.schemas ?? ['public'];
184
+ }
185
+ return this.options.schemas ?? ['public'];
186
+ }
187
+ getApiNames() {
188
+ if (isPgpmModulePathOptions(this.options)) {
189
+ return this.options.apiNames;
190
+ }
191
+ return this.options.apiNames;
192
+ }
193
+ getKeepDb() {
194
+ if (isPgpmModulePathOptions(this.options)) {
195
+ return this.options.keepDb ?? false;
196
+ }
197
+ return this.options.keepDb ?? false;
198
+ }
199
+ }
200
+ exports.PgpmModuleSchemaSource = PgpmModuleSchemaSource;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Output module exports
3
+ */
4
+ export { writeGeneratedFiles, formatOutput, type GeneratedFile, type WriteResult, type WriteOptions, } from './writer';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Output module exports
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatOutput = exports.writeGeneratedFiles = void 0;
7
+ var writer_1 = require("./writer");
8
+ Object.defineProperty(exports, "writeGeneratedFiles", { enumerable: true, get: function () { return writer_1.writeGeneratedFiles; } });
9
+ Object.defineProperty(exports, "formatOutput", { enumerable: true, get: function () { return writer_1.formatOutput; } });
@@ -0,0 +1,38 @@
1
+ import type { GeneratedFile } from '../codegen';
2
+ export type { GeneratedFile };
3
+ /**
4
+ * Result of writing files
5
+ */
6
+ export interface WriteResult {
7
+ success: boolean;
8
+ filesWritten?: string[];
9
+ errors?: string[];
10
+ }
11
+ /**
12
+ * Options for writing files
13
+ */
14
+ export interface WriteOptions {
15
+ /** Show progress output (default: true) */
16
+ showProgress?: boolean;
17
+ /** Format files with oxfmt after writing (default: true) */
18
+ formatFiles?: boolean;
19
+ }
20
+ /**
21
+ * Write generated files to disk
22
+ *
23
+ * @param files - Array of files to write
24
+ * @param outputDir - Base output directory
25
+ * @param subdirs - Subdirectories to create
26
+ * @param options - Write options
27
+ */
28
+ export declare function writeGeneratedFiles(files: GeneratedFile[], outputDir: string, subdirs: string[], options?: WriteOptions): Promise<WriteResult>;
29
+ /**
30
+ * Format generated files using oxfmt
31
+ *
32
+ * Runs oxfmt on the output directory after all files are written.
33
+ * Uses the same formatting options as prettier: single quotes, trailing commas, 2-space tabs, semicolons.
34
+ */
35
+ export declare function formatOutput(outputDir: string): {
36
+ success: boolean;
37
+ error?: string;
38
+ };
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.writeGeneratedFiles = writeGeneratedFiles;
37
+ exports.formatOutput = formatOutput;
38
+ /**
39
+ * File writing utilities
40
+ *
41
+ * Pure functions for writing generated files to disk and formatting them.
42
+ * These are core utilities that can be used programmatically or by the CLI.
43
+ */
44
+ const fs = __importStar(require("node:fs"));
45
+ const path = __importStar(require("node:path"));
46
+ const node_child_process_1 = require("node:child_process");
47
+ /**
48
+ * Write generated files to disk
49
+ *
50
+ * @param files - Array of files to write
51
+ * @param outputDir - Base output directory
52
+ * @param subdirs - Subdirectories to create
53
+ * @param options - Write options
54
+ */
55
+ async function writeGeneratedFiles(files, outputDir, subdirs, options = {}) {
56
+ const { showProgress = true, formatFiles = true } = options;
57
+ const errors = [];
58
+ const written = [];
59
+ const total = files.length;
60
+ const isTTY = process.stdout.isTTY;
61
+ // Ensure output directory exists
62
+ try {
63
+ fs.mkdirSync(outputDir, { recursive: true });
64
+ }
65
+ catch (err) {
66
+ const message = err instanceof Error ? err.message : 'Unknown error';
67
+ return {
68
+ success: false,
69
+ errors: [`Failed to create output directory: ${message}`],
70
+ };
71
+ }
72
+ // Create subdirectories
73
+ for (const subdir of subdirs) {
74
+ const subdirPath = path.join(outputDir, subdir);
75
+ try {
76
+ fs.mkdirSync(subdirPath, { recursive: true });
77
+ }
78
+ catch (err) {
79
+ const message = err instanceof Error ? err.message : 'Unknown error';
80
+ errors.push(`Failed to create directory ${subdirPath}: ${message}`);
81
+ }
82
+ }
83
+ if (errors.length > 0) {
84
+ return { success: false, errors };
85
+ }
86
+ for (let i = 0; i < files.length; i++) {
87
+ const file = files[i];
88
+ const filePath = path.join(outputDir, file.path);
89
+ // Show progress
90
+ if (showProgress) {
91
+ const progress = Math.round(((i + 1) / total) * 100);
92
+ if (isTTY) {
93
+ process.stdout.write(`\rWriting files: ${i + 1}/${total} (${progress}%)`);
94
+ }
95
+ else if (i % 100 === 0 || i === total - 1) {
96
+ // Non-TTY: periodic updates for CI/CD
97
+ console.log(`Writing files: ${i + 1}/${total}`);
98
+ }
99
+ }
100
+ // Ensure parent directory exists
101
+ const parentDir = path.dirname(filePath);
102
+ try {
103
+ fs.mkdirSync(parentDir, { recursive: true });
104
+ }
105
+ catch {
106
+ // Ignore if already exists
107
+ }
108
+ try {
109
+ fs.writeFileSync(filePath, file.content, 'utf-8');
110
+ written.push(filePath);
111
+ }
112
+ catch (err) {
113
+ const message = err instanceof Error ? err.message : 'Unknown error';
114
+ errors.push(`Failed to write ${filePath}: ${message}`);
115
+ }
116
+ }
117
+ // Clear progress line
118
+ if (showProgress && isTTY) {
119
+ process.stdout.write('\r' + ' '.repeat(40) + '\r');
120
+ }
121
+ // Format all generated files with oxfmt
122
+ if (formatFiles && errors.length === 0) {
123
+ if (showProgress) {
124
+ console.log('Formatting generated files...');
125
+ }
126
+ const formatResult = formatOutput(outputDir);
127
+ if (!formatResult.success && showProgress) {
128
+ console.warn('Warning: Failed to format generated files:', formatResult.error);
129
+ }
130
+ }
131
+ return {
132
+ success: errors.length === 0,
133
+ filesWritten: written,
134
+ errors: errors.length > 0 ? errors : undefined,
135
+ };
136
+ }
137
+ /**
138
+ * Format generated files using oxfmt
139
+ *
140
+ * Runs oxfmt on the output directory after all files are written.
141
+ * Uses the same formatting options as prettier: single quotes, trailing commas, 2-space tabs, semicolons.
142
+ */
143
+ function formatOutput(outputDir) {
144
+ const absoluteOutputDir = path.resolve(outputDir);
145
+ try {
146
+ (0, node_child_process_1.execSync)(`npx oxfmt --write "${absoluteOutputDir}"`, {
147
+ stdio: 'pipe',
148
+ encoding: 'utf-8',
149
+ });
150
+ return { success: true };
151
+ }
152
+ catch (err) {
153
+ const message = err instanceof Error ? err.message : String(err);
154
+ return { success: false, error: message };
155
+ }
156
+ }
@@ -8,18 +8,20 @@
8
8
  * - Operation transformation
9
9
  * - Filtering
10
10
  */
11
- import type { ResolvedConfig } from '../../types/config';
11
+ import type { GraphQLSDKConfigTarget } from '../../types/config';
12
12
  import type { CleanTable, CleanOperation, TypeRegistry } from '../../types/schema';
13
13
  import type { SchemaSource } from '../introspect/source';
14
+ export type { SchemaSource } from '../introspect/source';
15
+ export { createSchemaSource, validateSourceOptions } from '../introspect/source';
14
16
  export interface CodegenPipelineOptions {
15
17
  /**
16
18
  * Schema source (endpoint or file)
17
19
  */
18
20
  source: SchemaSource;
19
21
  /**
20
- * Resolved configuration
22
+ * Configuration
21
23
  */
22
- config: ResolvedConfig;
24
+ config: GraphQLSDKConfigTarget;
23
25
  /**
24
26
  * Enable verbose logging
25
27
  */
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateSourceOptions = exports.createSchemaSource = void 0;
3
4
  exports.runCodegenPipeline = runCodegenPipeline;
4
5
  exports.validateTablesFound = validateTablesFound;
5
6
  const infer_tables_1 = require("../introspect/infer-tables");
6
7
  const transform_1 = require("../introspect/transform");
7
8
  const transform_schema_1 = require("../introspect/transform-schema");
9
+ var source_1 = require("../introspect/source");
10
+ Object.defineProperty(exports, "createSchemaSource", { enumerable: true, get: function () { return source_1.createSchemaSource; } });
11
+ Object.defineProperty(exports, "validateSourceOptions", { enumerable: true, get: function () { return source_1.validateSourceOptions; } });
8
12
  // ============================================================================
9
13
  // Main Pipeline
10
14
  // ============================================================================
@@ -29,8 +33,11 @@ async function runCodegenPipeline(options) {
29
33
  let tables = (0, infer_tables_1.inferTablesFromIntrospection)(introspection);
30
34
  const totalTables = tables.length;
31
35
  log(` Found ${totalTables} tables`);
32
- // 3. Filter tables by config
33
- tables = (0, transform_1.filterTables)(tables, config.tables.include, config.tables.exclude);
36
+ // 3. Filter tables by config (combine exclude and systemExclude)
37
+ tables = (0, transform_1.filterTables)(tables, config.tables.include, [
38
+ ...config.tables.exclude,
39
+ ...config.tables.systemExclude,
40
+ ]);
34
41
  const filteredTables = tables.length;
35
42
  log(` After filtering: ${filteredTables} tables`);
36
43
  // 4. Transform introspection to operations
@@ -45,9 +52,9 @@ async function runCodegenPipeline(options) {
45
52
  let customQueries = [];
46
53
  let customMutations = [];
47
54
  if (!skipCustomOperations) {
48
- // Filter by config include/exclude
49
- const filteredQueries = (0, transform_schema_1.filterOperations)(allQueries, config.queries.include, config.queries.exclude);
50
- const filteredMutations = (0, transform_schema_1.filterOperations)(allMutations, config.mutations.include, config.mutations.exclude);
55
+ // Filter by config include/exclude (combine exclude and systemExclude)
56
+ const filteredQueries = (0, transform_schema_1.filterOperations)(allQueries, config.queries.include, [...config.queries.exclude, ...config.queries.systemExclude]);
57
+ const filteredMutations = (0, transform_schema_1.filterOperations)(allMutations, config.mutations.include, [...config.mutations.exclude, ...config.mutations.systemExclude]);
51
58
  log(` After config filtering: ${filteredQueries.length} queries, ${filteredMutations.length} mutations`);
52
59
  // Remove table operations (already handled by table generators)
53
60
  customQueries = (0, transform_schema_1.getCustomOperations)(filteredQueries, tableOperationNames);
@@ -3,10 +3,28 @@
3
3
  *
4
4
  * Coordinates schema polling, change detection, and code regeneration
5
5
  */
6
- import type { ResolvedConfig } from '../../types/config';
6
+ import type { GraphQLSDKConfigTarget } from '../../types/config';
7
7
  import type { GeneratorType } from './types';
8
+ export interface GenerateFunction {
9
+ (options: {
10
+ config?: string;
11
+ target?: string;
12
+ endpoint?: string;
13
+ output?: string;
14
+ authorization?: string;
15
+ verbose?: boolean;
16
+ skipCustomOperations?: boolean;
17
+ }): Promise<GenerateResult>;
18
+ }
19
+ export interface GenerateResult {
20
+ success: boolean;
21
+ message: string;
22
+ tables?: string[];
23
+ filesWritten?: string[];
24
+ errors?: string[];
25
+ }
8
26
  export interface WatchOrchestratorOptions {
9
- config: ResolvedConfig;
27
+ config: GraphQLSDKConfigTarget;
10
28
  generatorType: GeneratorType;
11
29
  verbose: boolean;
12
30
  authorization?: string;
@@ -14,10 +32,14 @@ export interface WatchOrchestratorOptions {
14
32
  configPath?: string;
15
33
  /** Target name for multi-target configs */
16
34
  target?: string;
17
- /** Override output directory (for ORM) */
35
+ /** Override output directory */
18
36
  outputDir?: string;
19
37
  /** Skip custom operations flag */
20
38
  skipCustomOperations?: boolean;
39
+ /** Generator function for React Query SDK */
40
+ generateReactQuery: GenerateFunction;
41
+ /** Generator function for ORM client */
42
+ generateOrm: GenerateFunction;
21
43
  }
22
44
  export interface WatchStatus {
23
45
  isRunning: boolean;