@constructive-io/graphql-codegen 2.18.0 → 2.20.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 (301) hide show
  1. package/README.md +1818 -113
  2. package/__tests__/codegen/input-types-generator.test.d.ts +1 -0
  3. package/__tests__/codegen/input-types-generator.test.js +635 -0
  4. package/cli/codegen/barrel.d.ts +27 -0
  5. package/cli/codegen/barrel.js +163 -0
  6. package/cli/codegen/client.d.ts +4 -0
  7. package/cli/codegen/client.js +170 -0
  8. package/cli/codegen/custom-mutations.d.ts +38 -0
  9. package/cli/codegen/custom-mutations.js +149 -0
  10. package/cli/codegen/custom-queries.d.ts +38 -0
  11. package/cli/codegen/custom-queries.js +358 -0
  12. package/cli/codegen/filters.d.ts +27 -0
  13. package/cli/codegen/filters.js +357 -0
  14. package/cli/codegen/gql-ast.d.ts +41 -0
  15. package/cli/codegen/gql-ast.js +329 -0
  16. package/cli/codegen/index.d.ts +71 -0
  17. package/cli/codegen/index.js +147 -0
  18. package/cli/codegen/mutations.d.ts +30 -0
  19. package/cli/codegen/mutations.js +410 -0
  20. package/cli/codegen/orm/barrel.d.ts +18 -0
  21. package/cli/codegen/orm/barrel.js +48 -0
  22. package/cli/codegen/orm/client-generator.d.ts +45 -0
  23. package/cli/codegen/orm/client-generator.js +646 -0
  24. package/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
  25. package/cli/codegen/orm/custom-ops-generator.js +350 -0
  26. package/cli/codegen/orm/index.d.ts +38 -0
  27. package/cli/codegen/orm/index.js +88 -0
  28. package/cli/codegen/orm/input-types-generator.d.ts +21 -0
  29. package/cli/codegen/orm/input-types-generator.js +705 -0
  30. package/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
  31. package/cli/codegen/orm/input-types-generator.test.js +75 -0
  32. package/cli/codegen/orm/model-generator.d.ts +32 -0
  33. package/cli/codegen/orm/model-generator.js +264 -0
  34. package/cli/codegen/orm/query-builder.d.ts +161 -0
  35. package/cli/codegen/orm/query-builder.js +366 -0
  36. package/cli/codegen/orm/select-types.d.ts +169 -0
  37. package/cli/codegen/orm/select-types.js +16 -0
  38. package/cli/codegen/orm/select-types.test.d.ts +11 -0
  39. package/cli/codegen/orm/select-types.test.js +22 -0
  40. package/cli/codegen/queries.d.ts +25 -0
  41. package/cli/codegen/queries.js +438 -0
  42. package/cli/codegen/scalars.d.ts +12 -0
  43. package/cli/codegen/scalars.js +71 -0
  44. package/cli/codegen/schema-gql-ast.d.ts +51 -0
  45. package/cli/codegen/schema-gql-ast.js +385 -0
  46. package/cli/codegen/ts-ast.d.ts +122 -0
  47. package/cli/codegen/ts-ast.js +280 -0
  48. package/cli/codegen/type-resolver.d.ts +96 -0
  49. package/cli/codegen/type-resolver.js +246 -0
  50. package/cli/codegen/types.d.ts +12 -0
  51. package/cli/codegen/types.js +69 -0
  52. package/cli/codegen/utils.d.ts +163 -0
  53. package/cli/codegen/utils.js +326 -0
  54. package/cli/commands/generate-orm.d.ts +37 -0
  55. package/cli/commands/generate-orm.js +195 -0
  56. package/cli/commands/generate.d.ts +39 -0
  57. package/cli/commands/generate.js +299 -0
  58. package/cli/commands/index.d.ts +7 -0
  59. package/cli/commands/index.js +12 -0
  60. package/cli/commands/init.d.ts +35 -0
  61. package/cli/commands/init.js +176 -0
  62. package/cli/index.d.ts +4 -0
  63. package/cli/index.js +291 -0
  64. package/cli/introspect/fetch-meta.d.ts +31 -0
  65. package/cli/introspect/fetch-meta.js +108 -0
  66. package/cli/introspect/fetch-schema.d.ts +21 -0
  67. package/cli/introspect/fetch-schema.js +86 -0
  68. package/cli/introspect/index.d.ts +8 -0
  69. package/cli/introspect/index.js +16 -0
  70. package/cli/introspect/meta-query.d.ts +111 -0
  71. package/cli/introspect/meta-query.js +191 -0
  72. package/cli/introspect/schema-query.d.ts +20 -0
  73. package/cli/introspect/schema-query.js +123 -0
  74. package/cli/introspect/transform-schema.d.ts +74 -0
  75. package/cli/introspect/transform-schema.js +269 -0
  76. package/cli/introspect/transform-schema.test.d.ts +1 -0
  77. package/cli/introspect/transform-schema.test.js +67 -0
  78. package/cli/introspect/transform.d.ts +21 -0
  79. package/cli/introspect/transform.js +216 -0
  80. package/cli/watch/cache.d.ts +45 -0
  81. package/cli/watch/cache.js +111 -0
  82. package/cli/watch/debounce.d.ts +19 -0
  83. package/cli/watch/debounce.js +89 -0
  84. package/cli/watch/hash.d.ts +17 -0
  85. package/cli/watch/hash.js +48 -0
  86. package/cli/watch/index.d.ts +10 -0
  87. package/cli/watch/index.js +22 -0
  88. package/cli/watch/orchestrator.d.ts +63 -0
  89. package/cli/watch/orchestrator.js +228 -0
  90. package/cli/watch/poller.d.ts +65 -0
  91. package/cli/watch/poller.js +203 -0
  92. package/cli/watch/types.d.ts +67 -0
  93. package/cli/watch/types.js +5 -0
  94. package/client/error.d.ts +95 -0
  95. package/client/error.js +255 -0
  96. package/client/execute.d.ts +57 -0
  97. package/client/execute.js +124 -0
  98. package/client/index.d.ts +6 -0
  99. package/client/index.js +18 -0
  100. package/client/typed-document.d.ts +31 -0
  101. package/client/typed-document.js +44 -0
  102. package/core/ast.d.ts +10 -0
  103. package/core/ast.js +593 -0
  104. package/core/custom-ast.d.ts +35 -0
  105. package/core/custom-ast.js +204 -0
  106. package/core/index.d.ts +8 -0
  107. package/core/index.js +33 -0
  108. package/core/meta-object/convert.d.ts +65 -0
  109. package/core/meta-object/convert.js +63 -0
  110. package/core/meta-object/format.json +93 -0
  111. package/core/meta-object/index.d.ts +2 -0
  112. package/core/meta-object/index.js +18 -0
  113. package/core/meta-object/validate.d.ts +9 -0
  114. package/core/meta-object/validate.js +34 -0
  115. package/core/query-builder.d.ts +46 -0
  116. package/core/query-builder.js +412 -0
  117. package/core/types.d.ts +139 -0
  118. package/core/types.js +28 -0
  119. package/esm/__tests__/codegen/input-types-generator.test.d.ts +1 -0
  120. package/esm/__tests__/codegen/input-types-generator.test.js +633 -0
  121. package/esm/cli/codegen/barrel.d.ts +27 -0
  122. package/esm/cli/codegen/barrel.js +156 -0
  123. package/esm/cli/codegen/client.d.ts +4 -0
  124. package/esm/cli/codegen/client.js +167 -0
  125. package/esm/cli/codegen/custom-mutations.d.ts +38 -0
  126. package/esm/cli/codegen/custom-mutations.js +145 -0
  127. package/esm/cli/codegen/custom-queries.d.ts +38 -0
  128. package/esm/cli/codegen/custom-queries.js +354 -0
  129. package/esm/cli/codegen/filters.d.ts +27 -0
  130. package/esm/cli/codegen/filters.js +351 -0
  131. package/esm/cli/codegen/gql-ast.d.ts +41 -0
  132. package/esm/cli/codegen/gql-ast.js +288 -0
  133. package/esm/cli/codegen/index.d.ts +71 -0
  134. package/esm/cli/codegen/index.js +124 -0
  135. package/esm/cli/codegen/mutations.d.ts +30 -0
  136. package/esm/cli/codegen/mutations.js +404 -0
  137. package/esm/cli/codegen/orm/barrel.d.ts +18 -0
  138. package/esm/cli/codegen/orm/barrel.js +44 -0
  139. package/esm/cli/codegen/orm/client-generator.d.ts +45 -0
  140. package/esm/cli/codegen/orm/client-generator.js +640 -0
  141. package/esm/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
  142. package/esm/cli/codegen/orm/custom-ops-generator.js +346 -0
  143. package/esm/cli/codegen/orm/index.d.ts +38 -0
  144. package/esm/cli/codegen/orm/index.js +75 -0
  145. package/esm/cli/codegen/orm/input-types-generator.d.ts +21 -0
  146. package/esm/cli/codegen/orm/input-types-generator.js +700 -0
  147. package/esm/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
  148. package/esm/cli/codegen/orm/input-types-generator.test.js +73 -0
  149. package/esm/cli/codegen/orm/model-generator.d.ts +32 -0
  150. package/esm/cli/codegen/orm/model-generator.js +260 -0
  151. package/esm/cli/codegen/orm/query-builder.d.ts +161 -0
  152. package/esm/cli/codegen/orm/query-builder.js +353 -0
  153. package/esm/cli/codegen/orm/select-types.d.ts +169 -0
  154. package/esm/cli/codegen/orm/select-types.js +15 -0
  155. package/esm/cli/codegen/orm/select-types.test.d.ts +11 -0
  156. package/esm/cli/codegen/orm/select-types.test.js +21 -0
  157. package/esm/cli/codegen/queries.d.ts +25 -0
  158. package/esm/cli/codegen/queries.js +433 -0
  159. package/esm/cli/codegen/scalars.d.ts +12 -0
  160. package/esm/cli/codegen/scalars.js +66 -0
  161. package/esm/cli/codegen/schema-gql-ast.d.ts +51 -0
  162. package/esm/cli/codegen/schema-gql-ast.js +343 -0
  163. package/esm/cli/codegen/ts-ast.d.ts +122 -0
  164. package/esm/cli/codegen/ts-ast.js +260 -0
  165. package/esm/cli/codegen/type-resolver.d.ts +96 -0
  166. package/esm/cli/codegen/type-resolver.js +224 -0
  167. package/esm/cli/codegen/types.d.ts +12 -0
  168. package/esm/cli/codegen/types.js +65 -0
  169. package/esm/cli/codegen/utils.d.ts +163 -0
  170. package/esm/cli/codegen/utils.js +288 -0
  171. package/esm/cli/commands/generate-orm.d.ts +37 -0
  172. package/esm/cli/commands/generate-orm.js +192 -0
  173. package/esm/cli/commands/generate.d.ts +39 -0
  174. package/esm/cli/commands/generate.js +262 -0
  175. package/esm/cli/commands/index.d.ts +7 -0
  176. package/esm/cli/commands/index.js +5 -0
  177. package/esm/cli/commands/init.d.ts +35 -0
  178. package/esm/cli/commands/init.js +138 -0
  179. package/esm/cli/index.d.ts +4 -0
  180. package/esm/cli/index.js +256 -0
  181. package/esm/cli/introspect/fetch-meta.d.ts +31 -0
  182. package/esm/cli/introspect/fetch-meta.js +104 -0
  183. package/esm/cli/introspect/fetch-schema.d.ts +21 -0
  184. package/esm/cli/introspect/fetch-schema.js +83 -0
  185. package/esm/cli/introspect/index.d.ts +8 -0
  186. package/esm/cli/introspect/index.js +6 -0
  187. package/esm/cli/introspect/meta-query.d.ts +111 -0
  188. package/esm/cli/introspect/meta-query.js +188 -0
  189. package/esm/cli/introspect/schema-query.d.ts +20 -0
  190. package/esm/cli/introspect/schema-query.js +120 -0
  191. package/esm/cli/introspect/transform-schema.d.ts +74 -0
  192. package/esm/cli/introspect/transform-schema.js +259 -0
  193. package/esm/cli/introspect/transform-schema.test.d.ts +1 -0
  194. package/esm/cli/introspect/transform-schema.test.js +65 -0
  195. package/esm/cli/introspect/transform.d.ts +21 -0
  196. package/esm/cli/introspect/transform.js +210 -0
  197. package/esm/cli/watch/cache.d.ts +45 -0
  198. package/esm/cli/watch/cache.js +73 -0
  199. package/esm/cli/watch/debounce.d.ts +19 -0
  200. package/esm/cli/watch/debounce.js +85 -0
  201. package/esm/cli/watch/hash.d.ts +17 -0
  202. package/esm/cli/watch/hash.js +43 -0
  203. package/esm/cli/watch/index.d.ts +10 -0
  204. package/esm/cli/watch/index.js +8 -0
  205. package/esm/cli/watch/orchestrator.d.ts +63 -0
  206. package/esm/cli/watch/orchestrator.js +223 -0
  207. package/esm/cli/watch/poller.d.ts +65 -0
  208. package/esm/cli/watch/poller.js +198 -0
  209. package/esm/cli/watch/types.d.ts +67 -0
  210. package/esm/cli/watch/types.js +4 -0
  211. package/esm/client/error.d.ts +95 -0
  212. package/esm/client/error.js +249 -0
  213. package/esm/client/execute.d.ts +57 -0
  214. package/esm/client/execute.js +120 -0
  215. package/esm/client/index.d.ts +6 -0
  216. package/esm/client/index.js +6 -0
  217. package/esm/client/typed-document.d.ts +31 -0
  218. package/esm/client/typed-document.js +40 -0
  219. package/esm/core/ast.d.ts +10 -0
  220. package/esm/core/ast.js +549 -0
  221. package/esm/core/custom-ast.d.ts +35 -0
  222. package/esm/core/custom-ast.js +161 -0
  223. package/esm/core/index.d.ts +8 -0
  224. package/esm/core/index.js +12 -0
  225. package/esm/core/meta-object/convert.d.ts +65 -0
  226. package/esm/core/meta-object/convert.js +60 -0
  227. package/esm/core/meta-object/format.json +93 -0
  228. package/esm/core/meta-object/index.d.ts +2 -0
  229. package/esm/core/meta-object/index.js +2 -0
  230. package/esm/core/meta-object/validate.d.ts +9 -0
  231. package/esm/core/meta-object/validate.js +28 -0
  232. package/esm/core/query-builder.d.ts +46 -0
  233. package/esm/core/query-builder.js +375 -0
  234. package/esm/core/types.d.ts +139 -0
  235. package/esm/core/types.js +24 -0
  236. package/esm/generators/field-selector.d.ts +30 -0
  237. package/esm/generators/field-selector.js +355 -0
  238. package/esm/generators/index.d.ts +6 -0
  239. package/esm/generators/index.js +9 -0
  240. package/esm/generators/mutations.d.ts +31 -0
  241. package/esm/generators/mutations.js +197 -0
  242. package/esm/generators/select.d.ts +50 -0
  243. package/esm/generators/select.js +636 -0
  244. package/esm/index.d.ts +12 -0
  245. package/esm/index.js +17 -3
  246. package/esm/react/index.d.ts +5 -0
  247. package/esm/react/index.js +6 -0
  248. package/esm/types/config.d.ts +199 -0
  249. package/esm/types/config.js +106 -0
  250. package/esm/types/index.d.ts +9 -0
  251. package/esm/types/index.js +4 -0
  252. package/esm/types/introspection.d.ts +121 -0
  253. package/esm/types/introspection.js +54 -0
  254. package/esm/types/mutation.d.ts +45 -0
  255. package/esm/types/mutation.js +4 -0
  256. package/esm/types/query.d.ts +82 -0
  257. package/esm/types/query.js +4 -0
  258. package/esm/types/schema.d.ts +253 -0
  259. package/esm/types/schema.js +5 -0
  260. package/esm/types/selection.d.ts +43 -0
  261. package/esm/types/selection.js +4 -0
  262. package/esm/utils/index.d.ts +4 -0
  263. package/esm/utils/index.js +4 -0
  264. package/generators/field-selector.d.ts +30 -0
  265. package/generators/field-selector.js +361 -0
  266. package/generators/index.d.ts +6 -0
  267. package/generators/index.js +27 -0
  268. package/generators/mutations.d.ts +31 -0
  269. package/generators/mutations.js +235 -0
  270. package/generators/select.d.ts +50 -0
  271. package/generators/select.js +679 -0
  272. package/index.d.ts +12 -3
  273. package/index.js +19 -3
  274. package/package.json +59 -38
  275. package/react/index.d.ts +5 -0
  276. package/react/index.js +9 -0
  277. package/types/config.d.ts +199 -0
  278. package/types/config.js +111 -0
  279. package/types/index.d.ts +9 -0
  280. package/types/index.js +10 -0
  281. package/types/introspection.d.ts +121 -0
  282. package/types/introspection.js +62 -0
  283. package/types/mutation.d.ts +45 -0
  284. package/types/mutation.js +5 -0
  285. package/types/query.d.ts +82 -0
  286. package/types/query.js +5 -0
  287. package/types/schema.d.ts +253 -0
  288. package/types/schema.js +6 -0
  289. package/types/selection.d.ts +43 -0
  290. package/types/selection.js +5 -0
  291. package/utils/index.d.ts +4 -0
  292. package/utils/index.js +7 -0
  293. package/codegen.d.ts +0 -13
  294. package/codegen.js +0 -293
  295. package/esm/codegen.js +0 -253
  296. package/esm/gql.js +0 -939
  297. package/esm/options.js +0 -27
  298. package/gql.d.ts +0 -188
  299. package/gql.js +0 -992
  300. package/options.d.ts +0 -45
  301. package/options.js +0 -31
@@ -0,0 +1,65 @@
1
+ // Jest globals - no import needed
2
+ import { getTableOperationNames, getCustomOperations, isTableOperation, } from './transform-schema';
3
+ describe('transform-schema table operation filtering', () => {
4
+ const dummyReturnType = { kind: 'SCALAR', name: 'String' };
5
+ it('detects table operations and update/delete patterns', () => {
6
+ const tableOps = getTableOperationNames([
7
+ {
8
+ name: 'User',
9
+ query: {
10
+ all: 'users',
11
+ one: 'user',
12
+ create: 'createUser',
13
+ update: 'updateUser',
14
+ delete: 'deleteUser',
15
+ },
16
+ inflection: { tableType: 'User' },
17
+ },
18
+ ]);
19
+ const updateByEmail = {
20
+ name: 'updateUserByEmail',
21
+ kind: 'mutation',
22
+ args: [],
23
+ returnType: dummyReturnType,
24
+ };
25
+ const login = {
26
+ name: 'login',
27
+ kind: 'mutation',
28
+ args: [],
29
+ returnType: dummyReturnType,
30
+ };
31
+ expect(isTableOperation(updateByEmail, tableOps)).toBe(true);
32
+ expect(isTableOperation(login, tableOps)).toBe(false);
33
+ });
34
+ it('filters out table operations from custom list', () => {
35
+ const tableOps = getTableOperationNames([
36
+ {
37
+ name: 'User',
38
+ query: {
39
+ all: 'users',
40
+ one: 'user',
41
+ create: 'createUser',
42
+ update: 'updateUser',
43
+ delete: 'deleteUser',
44
+ },
45
+ inflection: { tableType: 'User' },
46
+ },
47
+ ]);
48
+ const operations = [
49
+ {
50
+ name: 'users',
51
+ kind: 'query',
52
+ args: [],
53
+ returnType: dummyReturnType,
54
+ },
55
+ {
56
+ name: 'login',
57
+ kind: 'mutation',
58
+ args: [],
59
+ returnType: dummyReturnType,
60
+ },
61
+ ];
62
+ const customOps = getCustomOperations(operations, tableOps);
63
+ expect(customOps.map((op) => op.name)).toEqual(['login']);
64
+ });
65
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Transform _meta query response to CleanTable[] format
3
+ */
4
+ import type { CleanTable } from '../../types/schema';
5
+ import type { MetaQueryResponse } from './meta-query';
6
+ /**
7
+ * Transform _meta response to CleanTable array
8
+ */
9
+ export declare function transformMetaToCleanTables(metaResponse: MetaQueryResponse): CleanTable[];
10
+ /**
11
+ * Get table names from CleanTable array
12
+ */
13
+ export declare function getTableNames(tables: CleanTable[]): string[];
14
+ /**
15
+ * Find a table by name
16
+ */
17
+ export declare function findTable(tables: CleanTable[], name: string): CleanTable | undefined;
18
+ /**
19
+ * Filter tables by name pattern (glob-like)
20
+ */
21
+ export declare function filterTables(tables: CleanTable[], include?: string[], exclude?: string[]): CleanTable[];
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Transform _meta response to CleanTable array
3
+ */
4
+ export function transformMetaToCleanTables(metaResponse) {
5
+ const { tables } = metaResponse._meta;
6
+ return tables.map((table) => transformTable(table));
7
+ }
8
+ /**
9
+ * Transform a single MetaTable to CleanTable
10
+ */
11
+ function transformTable(table) {
12
+ return {
13
+ name: table.name,
14
+ fields: transformFields(table.fields),
15
+ relations: transformRelations(table.relations),
16
+ inflection: transformInflection(table.inflection),
17
+ query: transformQuery(table.query),
18
+ constraints: transformConstraints(table),
19
+ };
20
+ }
21
+ /**
22
+ * Transform MetaField[] to CleanField[]
23
+ */
24
+ function transformFields(fields) {
25
+ return fields.map((field) => ({
26
+ name: field.name,
27
+ type: transformFieldType(field.type),
28
+ }));
29
+ }
30
+ /**
31
+ * Transform MetaFieldType to CleanFieldType
32
+ */
33
+ function transformFieldType(type) {
34
+ return {
35
+ gqlType: type.gqlType,
36
+ isArray: type.isArray,
37
+ modifier: type.modifier,
38
+ pgAlias: type.pgAlias,
39
+ pgType: type.pgType,
40
+ subtype: type.subtype,
41
+ typmod: type.typmod,
42
+ };
43
+ }
44
+ /**
45
+ * Transform table relations
46
+ */
47
+ function transformRelations(relations) {
48
+ return {
49
+ belongsTo: relations.belongsTo.map(transformBelongsTo),
50
+ hasOne: relations.hasOne.map(transformHasOne),
51
+ hasMany: relations.hasMany.map(transformHasMany),
52
+ manyToMany: relations.manyToMany.map(transformManyToMany),
53
+ };
54
+ }
55
+ /**
56
+ * Transform belongsTo relation
57
+ */
58
+ function transformBelongsTo(rel) {
59
+ return {
60
+ fieldName: rel.fieldName,
61
+ isUnique: rel.isUnique,
62
+ referencesTable: rel.references.name,
63
+ type: rel.type,
64
+ keys: transformFields(rel.keys),
65
+ };
66
+ }
67
+ /**
68
+ * Transform hasOne relation
69
+ */
70
+ function transformHasOne(rel) {
71
+ return {
72
+ fieldName: rel.fieldName,
73
+ isUnique: rel.isUnique,
74
+ referencedByTable: rel.referencedBy.name,
75
+ type: rel.type,
76
+ keys: transformFields(rel.keys),
77
+ };
78
+ }
79
+ /**
80
+ * Transform hasMany relation
81
+ */
82
+ function transformHasMany(rel) {
83
+ return {
84
+ fieldName: rel.fieldName,
85
+ isUnique: rel.isUnique,
86
+ referencedByTable: rel.referencedBy.name,
87
+ type: rel.type,
88
+ keys: transformFields(rel.keys),
89
+ };
90
+ }
91
+ /**
92
+ * Transform manyToMany relation
93
+ */
94
+ function transformManyToMany(rel) {
95
+ return {
96
+ fieldName: rel.fieldName,
97
+ rightTable: rel.rightTable.name,
98
+ junctionTable: rel.junctionTable.name,
99
+ type: rel.type,
100
+ };
101
+ }
102
+ /**
103
+ * Transform inflection data
104
+ */
105
+ function transformInflection(inflection) {
106
+ return {
107
+ allRows: inflection.allRows,
108
+ allRowsSimple: inflection.allRowsSimple,
109
+ conditionType: inflection.conditionType,
110
+ connection: inflection.connection,
111
+ createField: inflection.createField,
112
+ createInputType: inflection.createInputType,
113
+ createPayloadType: inflection.createPayloadType,
114
+ deleteByPrimaryKey: inflection.deleteByPrimaryKey,
115
+ deletePayloadType: inflection.deletePayloadType,
116
+ edge: inflection.edge,
117
+ edgeField: inflection.edgeField,
118
+ enumType: inflection.enumType,
119
+ filterType: inflection.filterType,
120
+ inputType: inflection.inputType,
121
+ orderByType: inflection.orderByType,
122
+ patchField: inflection.patchField,
123
+ patchType: inflection.patchType,
124
+ tableFieldName: inflection.tableFieldName,
125
+ tableType: inflection.tableType,
126
+ typeName: inflection.typeName,
127
+ updateByPrimaryKey: inflection.updateByPrimaryKey,
128
+ updatePayloadType: inflection.updatePayloadType,
129
+ };
130
+ }
131
+ /**
132
+ * Transform query names
133
+ */
134
+ function transformQuery(query) {
135
+ return {
136
+ all: query.all,
137
+ one: query.one,
138
+ create: query.create,
139
+ update: query.update,
140
+ delete: query.delete,
141
+ };
142
+ }
143
+ /**
144
+ * Transform constraints
145
+ */
146
+ function transformConstraints(table) {
147
+ return {
148
+ primaryKey: table.primaryKeyConstraints.map(transformConstraint),
149
+ foreignKey: table.foreignKeyConstraints.map(transformForeignKeyConstraint),
150
+ unique: table.uniqueConstraints.map(transformConstraint),
151
+ };
152
+ }
153
+ /**
154
+ * Transform a basic constraint
155
+ */
156
+ function transformConstraint(constraint) {
157
+ return {
158
+ name: constraint.name,
159
+ fields: transformFields(constraint.fields),
160
+ };
161
+ }
162
+ /**
163
+ * Transform a foreign key constraint
164
+ */
165
+ function transformForeignKeyConstraint(constraint) {
166
+ return {
167
+ name: constraint.name,
168
+ fields: transformFields(constraint.fields),
169
+ refTable: constraint.refTable.name,
170
+ refFields: transformFields(constraint.refFields),
171
+ };
172
+ }
173
+ /**
174
+ * Get table names from CleanTable array
175
+ */
176
+ export function getTableNames(tables) {
177
+ return tables.map((t) => t.name);
178
+ }
179
+ /**
180
+ * Find a table by name
181
+ */
182
+ export function findTable(tables, name) {
183
+ return tables.find((t) => t.name === name);
184
+ }
185
+ /**
186
+ * Filter tables by name pattern (glob-like)
187
+ */
188
+ export function filterTables(tables, include, exclude) {
189
+ let result = tables;
190
+ if (include && include.length > 0) {
191
+ result = result.filter((t) => matchesPatterns(t.name, include));
192
+ }
193
+ if (exclude && exclude.length > 0) {
194
+ result = result.filter((t) => !matchesPatterns(t.name, exclude));
195
+ }
196
+ return result;
197
+ }
198
+ /**
199
+ * Check if a name matches any of the patterns
200
+ * Supports simple glob patterns with * wildcard
201
+ */
202
+ function matchesPatterns(name, patterns) {
203
+ return patterns.some((pattern) => {
204
+ if (pattern.includes('*')) {
205
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
206
+ return regex.test(name);
207
+ }
208
+ return name === pattern;
209
+ });
210
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * In-memory schema cache for watch mode
3
+ *
4
+ * Only stores the hash in memory - no file I/O during normal operation.
5
+ * Touch file feature is optional and only writes when explicitly configured.
6
+ */
7
+ import type { MetaQueryResponse } from '../introspect/meta-query';
8
+ import type { IntrospectionQueryResponse } from '../../types/introspection';
9
+ /**
10
+ * Lightweight in-memory schema cache
11
+ * Only stores the combined hash string to detect changes
12
+ */
13
+ export declare class SchemaCache {
14
+ /** Current schema hash (in-memory only) */
15
+ private currentHash;
16
+ /**
17
+ * Check if schema has changed by comparing hashes
18
+ * This is the hot path - must be efficient
19
+ */
20
+ hasChanged(meta: MetaQueryResponse, schema: IntrospectionQueryResponse): Promise<{
21
+ changed: boolean;
22
+ newHash: string;
23
+ }>;
24
+ /**
25
+ * Update the cached hash (call after successful regeneration)
26
+ */
27
+ updateHash(hash: string): void;
28
+ /**
29
+ * Get the current cached hash
30
+ */
31
+ getHash(): string | null;
32
+ /**
33
+ * Clear the cached hash
34
+ */
35
+ clear(): void;
36
+ /**
37
+ * Compute hash from meta and schema responses
38
+ */
39
+ private computeHash;
40
+ }
41
+ /**
42
+ * Touch a file to signal schema change (for external tools like tsc/webpack)
43
+ * This is the only file I/O in watch mode, and it's optional.
44
+ */
45
+ export declare function touchFile(filePath: string): void;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * In-memory schema cache for watch mode
3
+ *
4
+ * Only stores the hash in memory - no file I/O during normal operation.
5
+ * Touch file feature is optional and only writes when explicitly configured.
6
+ */
7
+ import * as fs from 'node:fs';
8
+ import * as path from 'node:path';
9
+ import { hashObject, combineHashes } from './hash';
10
+ /**
11
+ * Lightweight in-memory schema cache
12
+ * Only stores the combined hash string to detect changes
13
+ */
14
+ export class SchemaCache {
15
+ /** Current schema hash (in-memory only) */
16
+ currentHash = null;
17
+ /**
18
+ * Check if schema has changed by comparing hashes
19
+ * This is the hot path - must be efficient
20
+ */
21
+ async hasChanged(meta, schema) {
22
+ const newHash = await this.computeHash(meta, schema);
23
+ const changed = this.currentHash === null || this.currentHash !== newHash;
24
+ return { changed, newHash };
25
+ }
26
+ /**
27
+ * Update the cached hash (call after successful regeneration)
28
+ */
29
+ updateHash(hash) {
30
+ this.currentHash = hash;
31
+ }
32
+ /**
33
+ * Get the current cached hash
34
+ */
35
+ getHash() {
36
+ return this.currentHash;
37
+ }
38
+ /**
39
+ * Clear the cached hash
40
+ */
41
+ clear() {
42
+ this.currentHash = null;
43
+ }
44
+ /**
45
+ * Compute hash from meta and schema responses
46
+ */
47
+ async computeHash(meta, schema) {
48
+ // Hash each response separately then combine
49
+ // This is more efficient than stringifying both together
50
+ const metaHash = await hashObject(meta);
51
+ const schemaHash = await hashObject(schema);
52
+ return combineHashes(metaHash, schemaHash);
53
+ }
54
+ }
55
+ /**
56
+ * Touch a file to signal schema change (for external tools like tsc/webpack)
57
+ * This is the only file I/O in watch mode, and it's optional.
58
+ */
59
+ export function touchFile(filePath) {
60
+ // Ensure parent directory exists
61
+ const dir = path.dirname(filePath);
62
+ if (!fs.existsSync(dir)) {
63
+ fs.mkdirSync(dir, { recursive: true });
64
+ }
65
+ // Touch the file (create if doesn't exist, update mtime if it does)
66
+ const time = new Date();
67
+ try {
68
+ fs.utimesSync(filePath, time, time);
69
+ }
70
+ catch {
71
+ fs.closeSync(fs.openSync(filePath, 'w'));
72
+ }
73
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Debounce utility for regeneration
3
+ */
4
+ /**
5
+ * Creates a debounced function that delays invoking func until after wait milliseconds
6
+ * have elapsed since the last time the debounced function was invoked.
7
+ */
8
+ export declare function debounce<T extends (...args: unknown[]) => unknown>(func: T, wait: number): {
9
+ (...args: Parameters<T>): void;
10
+ cancel: () => void;
11
+ flush: () => void;
12
+ };
13
+ /**
14
+ * Creates an async debounced function
15
+ */
16
+ export declare function debounceAsync<T extends (...args: unknown[]) => Promise<unknown>>(func: T, wait: number): {
17
+ (...args: Parameters<T>): Promise<void>;
18
+ cancel: () => void;
19
+ };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Debounce utility for regeneration
3
+ */
4
+ /**
5
+ * Creates a debounced function that delays invoking func until after wait milliseconds
6
+ * have elapsed since the last time the debounced function was invoked.
7
+ */
8
+ export function debounce(func, wait) {
9
+ let timeoutId = null;
10
+ let lastArgs = null;
11
+ const debounced = (...args) => {
12
+ lastArgs = args;
13
+ if (timeoutId) {
14
+ clearTimeout(timeoutId);
15
+ }
16
+ timeoutId = setTimeout(() => {
17
+ timeoutId = null;
18
+ if (lastArgs) {
19
+ func(...lastArgs);
20
+ lastArgs = null;
21
+ }
22
+ }, wait);
23
+ };
24
+ debounced.cancel = () => {
25
+ if (timeoutId) {
26
+ clearTimeout(timeoutId);
27
+ timeoutId = null;
28
+ lastArgs = null;
29
+ }
30
+ };
31
+ debounced.flush = () => {
32
+ if (timeoutId && lastArgs) {
33
+ clearTimeout(timeoutId);
34
+ timeoutId = null;
35
+ func(...lastArgs);
36
+ lastArgs = null;
37
+ }
38
+ };
39
+ return debounced;
40
+ }
41
+ /**
42
+ * Creates an async debounced function
43
+ */
44
+ export function debounceAsync(func, wait) {
45
+ let timeoutId = null;
46
+ let pendingPromise = null;
47
+ let pendingResolve = null;
48
+ const debounced = (...args) => {
49
+ if (timeoutId) {
50
+ clearTimeout(timeoutId);
51
+ }
52
+ // If there's already a pending promise, reuse it
53
+ if (!pendingPromise) {
54
+ pendingPromise = new Promise((resolve) => {
55
+ pendingResolve = resolve;
56
+ });
57
+ }
58
+ timeoutId = setTimeout(async () => {
59
+ timeoutId = null;
60
+ try {
61
+ await func(...args);
62
+ }
63
+ finally {
64
+ if (pendingResolve) {
65
+ pendingResolve();
66
+ pendingResolve = null;
67
+ pendingPromise = null;
68
+ }
69
+ }
70
+ }, wait);
71
+ return pendingPromise;
72
+ };
73
+ debounced.cancel = () => {
74
+ if (timeoutId) {
75
+ clearTimeout(timeoutId);
76
+ timeoutId = null;
77
+ }
78
+ if (pendingResolve) {
79
+ pendingResolve();
80
+ pendingResolve = null;
81
+ pendingPromise = null;
82
+ }
83
+ };
84
+ return debounced;
85
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Schema hashing utilities using Node.js crypto.subtle (Node 22+)
3
+ */
4
+ /**
5
+ * Compute SHA-256 hash of a string using Web Crypto API
6
+ * Uses crypto.subtle available in Node.js 22+
7
+ */
8
+ export declare function sha256(data: string): Promise<string>;
9
+ /**
10
+ * Compute hash of an object by JSON-stringifying it
11
+ * Objects are sorted by keys for consistent hashing
12
+ */
13
+ export declare function hashObject(obj: unknown): Promise<string>;
14
+ /**
15
+ * Combine multiple hashes into a single hash
16
+ */
17
+ export declare function combineHashes(...hashes: string[]): Promise<string>;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Schema hashing utilities using Node.js crypto.subtle (Node 22+)
3
+ */
4
+ import { webcrypto } from 'node:crypto';
5
+ /**
6
+ * Compute SHA-256 hash of a string using Web Crypto API
7
+ * Uses crypto.subtle available in Node.js 22+
8
+ */
9
+ export async function sha256(data) {
10
+ const encoder = new TextEncoder();
11
+ const dataBuffer = encoder.encode(data);
12
+ const hashBuffer = await webcrypto.subtle.digest('SHA-256', dataBuffer);
13
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
14
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
15
+ }
16
+ /**
17
+ * Compute hash of an object by JSON-stringifying it
18
+ * Objects are sorted by keys for consistent hashing
19
+ */
20
+ export async function hashObject(obj) {
21
+ const json = JSON.stringify(obj, sortReplacer);
22
+ return sha256(json);
23
+ }
24
+ /**
25
+ * JSON.stringify replacer that sorts object keys for deterministic output
26
+ */
27
+ function sortReplacer(_key, value) {
28
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
29
+ return Object.keys(value)
30
+ .sort()
31
+ .reduce((sorted, key) => {
32
+ sorted[key] = value[key];
33
+ return sorted;
34
+ }, {});
35
+ }
36
+ return value;
37
+ }
38
+ /**
39
+ * Combine multiple hashes into a single hash
40
+ */
41
+ export async function combineHashes(...hashes) {
42
+ return sha256(hashes.join(':'));
43
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Watch mode module exports
3
+ */
4
+ export { SchemaPoller, computeSchemaHash } from './poller';
5
+ export { SchemaCache, touchFile } from './cache';
6
+ export { sha256, hashObject, combineHashes } from './hash';
7
+ export { debounce, debounceAsync } from './debounce';
8
+ export { WatchOrchestrator, startWatch } from './orchestrator';
9
+ export type { PollResult, WatchOptions, PollEventType, PollEventHandler, PollEvent, GeneratorType, } from './types';
10
+ export type { WatchOrchestratorOptions, WatchStatus } from './orchestrator';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Watch mode module exports
3
+ */
4
+ export { SchemaPoller, computeSchemaHash } from './poller';
5
+ export { SchemaCache, touchFile } from './cache';
6
+ export { sha256, hashObject, combineHashes } from './hash';
7
+ export { debounce, debounceAsync } from './debounce';
8
+ export { WatchOrchestrator, startWatch } from './orchestrator';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Watch mode orchestrator
3
+ *
4
+ * Coordinates schema polling, change detection, and code regeneration
5
+ */
6
+ import type { ResolvedConfig } from '../../types/config';
7
+ import type { GeneratorType } from './types';
8
+ export interface WatchOrchestratorOptions {
9
+ config: ResolvedConfig;
10
+ generatorType: GeneratorType;
11
+ verbose: boolean;
12
+ authorization?: string;
13
+ /** Override output directory (for ORM) */
14
+ outputDir?: string;
15
+ /** Skip custom operations flag */
16
+ skipCustomOperations?: boolean;
17
+ }
18
+ export interface WatchStatus {
19
+ isRunning: boolean;
20
+ pollCount: number;
21
+ regenerateCount: number;
22
+ lastPollTime: number | null;
23
+ lastRegenTime: number | null;
24
+ lastError: string | null;
25
+ currentHash: string | null;
26
+ }
27
+ /**
28
+ * Main watch orchestrator class
29
+ */
30
+ export declare class WatchOrchestrator {
31
+ private options;
32
+ private watchOptions;
33
+ private poller;
34
+ private status;
35
+ private debouncedRegenerate;
36
+ private isShuttingDown;
37
+ constructor(options: WatchOrchestratorOptions);
38
+ private buildWatchOptions;
39
+ private setupEventHandlers;
40
+ /**
41
+ * Start watch mode
42
+ */
43
+ start(): Promise<void>;
44
+ /**
45
+ * Stop watch mode
46
+ */
47
+ stop(): Promise<void>;
48
+ /**
49
+ * Get current watch status
50
+ */
51
+ getStatus(): WatchStatus;
52
+ private regenerate;
53
+ private setupSignalHandlers;
54
+ private clearScreen;
55
+ private logHeader;
56
+ private log;
57
+ private logSuccess;
58
+ private logError;
59
+ }
60
+ /**
61
+ * Start watch mode for a generator
62
+ */
63
+ export declare function startWatch(options: WatchOrchestratorOptions): Promise<void>;