@axinom/mosaic-graphql-common 0.33.0 → 0.34.0-rc.3

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 (253) hide show
  1. package/dist/cjs/common/checks.d.ts.map +1 -0
  2. package/dist/cjs/common/checks.js.map +1 -0
  3. package/dist/cjs/common/index.d.ts +3 -0
  4. package/dist/cjs/common/index.d.ts.map +1 -0
  5. package/dist/{common → cjs/common}/index.js +2 -2
  6. package/dist/cjs/common/index.js.map +1 -0
  7. package/dist/cjs/common/types.d.ts.map +1 -0
  8. package/dist/cjs/common/types.js.map +1 -0
  9. package/dist/cjs/index.d.ts +5 -0
  10. package/dist/cjs/index.d.ts.map +1 -0
  11. package/dist/{index.js → cjs/index.js} +4 -4
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/{middleware → cjs/middleware}/forward-to-graphiql.d.ts +1 -1
  14. package/dist/cjs/middleware/forward-to-graphiql.d.ts.map +1 -0
  15. package/dist/cjs/middleware/forward-to-graphiql.js.map +1 -0
  16. package/dist/cjs/middleware/index.d.ts +2 -0
  17. package/dist/cjs/middleware/index.d.ts.map +1 -0
  18. package/dist/{middleware → cjs/middleware}/index.js +1 -1
  19. package/dist/cjs/middleware/index.js.map +1 -0
  20. package/dist/cjs/package.json +1 -0
  21. package/dist/{plugins → cjs/plugins}/add-error-codes-enum-plugin.d.ts +2 -2
  22. package/dist/cjs/plugins/add-error-codes-enum-plugin.d.ts.map +1 -0
  23. package/dist/cjs/plugins/add-error-codes-enum-plugin.js.map +1 -0
  24. package/dist/{plugins → cjs/plugins}/annotate-types-with-permissions-plugin.d.ts +1 -1
  25. package/dist/cjs/plugins/annotate-types-with-permissions-plugin.d.ts.map +1 -0
  26. package/dist/{plugins → cjs/plugins}/annotate-types-with-permissions-plugin.js +5 -6
  27. package/dist/cjs/plugins/annotate-types-with-permissions-plugin.js.map +1 -0
  28. package/dist/{plugins → cjs/plugins}/bulk-edit/bulk-edit-async-plugin-factory.d.ts +4 -4
  29. package/dist/cjs/plugins/bulk-edit/bulk-edit-async-plugin-factory.d.ts.map +1 -0
  30. package/dist/{plugins → cjs/plugins}/bulk-edit/bulk-edit-async-plugin-factory.js +22 -15
  31. package/dist/cjs/plugins/bulk-edit/bulk-edit-async-plugin-factory.js.map +1 -0
  32. package/dist/{plugins → cjs/plugins}/bulk-edit/bulk-edit-item-change-handler-helpers.d.ts +5 -5
  33. package/dist/cjs/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.d.ts.map +1 -0
  34. package/dist/cjs/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.js.map +1 -0
  35. package/dist/{plugins → cjs/plugins}/deprecate-stray-node-id-fields-plugin.d.ts +1 -1
  36. package/dist/cjs/plugins/deprecate-stray-node-id-fields-plugin.d.ts.map +1 -0
  37. package/dist/{plugins → cjs/plugins}/deprecate-stray-node-id-fields-plugin.js +2 -2
  38. package/dist/cjs/plugins/deprecate-stray-node-id-fields-plugin.js.map +1 -0
  39. package/dist/{plugins → cjs/plugins}/generic-bulk-plugin-factory.d.ts +1 -1
  40. package/dist/cjs/plugins/generic-bulk-plugin-factory.d.ts.map +1 -0
  41. package/dist/{plugins → cjs/plugins}/generic-bulk-plugin-factory.js +21 -21
  42. package/dist/cjs/plugins/generic-bulk-plugin-factory.js.map +1 -0
  43. package/dist/{plugins → cjs/plugins}/graphiql-management-mode-plugin-hook.d.ts +1 -1
  44. package/dist/cjs/plugins/graphiql-management-mode-plugin-hook.d.ts.map +1 -0
  45. package/dist/cjs/plugins/graphiql-management-mode-plugin-hook.js.map +1 -0
  46. package/dist/cjs/plugins/index.d.ts +12 -0
  47. package/dist/cjs/plugins/index.d.ts.map +1 -0
  48. package/dist/{plugins → cjs/plugins}/index.js +11 -11
  49. package/dist/cjs/plugins/index.js.map +1 -0
  50. package/dist/{plugins → cjs/plugins}/omit-from-query-root-plugin.d.ts +1 -1
  51. package/dist/cjs/plugins/omit-from-query-root-plugin.d.ts.map +1 -0
  52. package/dist/{plugins → cjs/plugins}/omit-from-query-root-plugin.js +1 -1
  53. package/dist/cjs/plugins/omit-from-query-root-plugin.js.map +1 -0
  54. package/dist/{plugins → cjs/plugins}/operations-enum-generator-plugin-factory.d.ts +7 -1
  55. package/dist/cjs/plugins/operations-enum-generator-plugin-factory.d.ts.map +1 -0
  56. package/dist/{plugins → cjs/plugins}/operations-enum-generator-plugin-factory.js +15 -4
  57. package/dist/cjs/plugins/operations-enum-generator-plugin-factory.js.map +1 -0
  58. package/dist/{plugins → cjs/plugins}/subscriptions-plugin-factory.d.ts +1 -1
  59. package/dist/cjs/plugins/subscriptions-plugin-factory.d.ts.map +1 -0
  60. package/dist/{plugins → cjs/plugins}/subscriptions-plugin-factory.js +7 -14
  61. package/dist/cjs/plugins/subscriptions-plugin-factory.js.map +1 -0
  62. package/dist/{plugins → cjs/plugins}/validation-directives-plugin.d.ts +1 -1
  63. package/dist/cjs/plugins/validation-directives-plugin.d.ts.map +1 -0
  64. package/dist/{plugins → cjs/plugins}/validation-directives-plugin.js +3 -4
  65. package/dist/cjs/plugins/validation-directives-plugin.js.map +1 -0
  66. package/dist/{postgraphile → cjs/postgraphile}/enhance-graphql-errors.d.ts +3 -3
  67. package/dist/cjs/postgraphile/enhance-graphql-errors.d.ts.map +1 -0
  68. package/dist/{postgraphile → cjs/postgraphile}/enhance-graphql-errors.js +23 -19
  69. package/dist/cjs/postgraphile/enhance-graphql-errors.js.map +1 -0
  70. package/dist/cjs/postgraphile/index.d.ts +4 -0
  71. package/dist/cjs/postgraphile/index.d.ts.map +1 -0
  72. package/dist/{postgraphile → cjs/postgraphile}/index.js +3 -3
  73. package/dist/cjs/postgraphile/index.js.map +1 -0
  74. package/dist/{postgraphile → cjs/postgraphile}/postgraphile-options-builder.d.ts +4 -4
  75. package/dist/cjs/postgraphile/postgraphile-options-builder.d.ts.map +1 -0
  76. package/dist/{postgraphile → cjs/postgraphile}/postgraphile-options-builder.js +34 -25
  77. package/dist/cjs/postgraphile/postgraphile-options-builder.js.map +1 -0
  78. package/dist/{postgraphile → cjs/postgraphile}/websocket-utils.d.ts +2 -2
  79. package/dist/cjs/postgraphile/websocket-utils.d.ts.map +1 -0
  80. package/dist/cjs/postgraphile/websocket-utils.js.map +1 -0
  81. package/dist/esm/common/checks.d.ts +9 -0
  82. package/dist/esm/common/checks.d.ts.map +1 -0
  83. package/dist/esm/common/checks.js +16 -0
  84. package/dist/esm/common/checks.js.map +1 -0
  85. package/dist/esm/common/index.d.ts +3 -0
  86. package/dist/esm/common/index.d.ts.map +1 -0
  87. package/dist/esm/common/index.js +3 -0
  88. package/dist/esm/common/index.js.map +1 -0
  89. package/dist/esm/common/types.d.ts +13 -0
  90. package/dist/esm/common/types.d.ts.map +1 -0
  91. package/dist/esm/common/types.js +11 -0
  92. package/dist/esm/common/types.js.map +1 -0
  93. package/dist/esm/index.d.ts +5 -0
  94. package/dist/esm/index.d.ts.map +1 -0
  95. package/dist/esm/index.js +5 -0
  96. package/dist/esm/index.js.map +1 -0
  97. package/dist/esm/middleware/forward-to-graphiql.d.ts +8 -0
  98. package/dist/esm/middleware/forward-to-graphiql.d.ts.map +1 -0
  99. package/dist/esm/middleware/forward-to-graphiql.js +17 -0
  100. package/dist/esm/middleware/forward-to-graphiql.js.map +1 -0
  101. package/dist/esm/middleware/index.d.ts +2 -0
  102. package/dist/esm/middleware/index.d.ts.map +1 -0
  103. package/dist/esm/middleware/index.js +2 -0
  104. package/dist/esm/middleware/index.js.map +1 -0
  105. package/dist/esm/package.json +1 -0
  106. package/dist/esm/plugins/add-error-codes-enum-plugin.d.ts +27 -0
  107. package/dist/esm/plugins/add-error-codes-enum-plugin.d.ts.map +1 -0
  108. package/dist/esm/plugins/add-error-codes-enum-plugin.js +74 -0
  109. package/dist/esm/plugins/add-error-codes-enum-plugin.js.map +1 -0
  110. package/dist/esm/plugins/annotate-types-with-permissions-plugin.d.ts +22 -0
  111. package/dist/esm/plugins/annotate-types-with-permissions-plugin.d.ts.map +1 -0
  112. package/dist/esm/plugins/annotate-types-with-permissions-plugin.js +140 -0
  113. package/dist/esm/plugins/annotate-types-with-permissions-plugin.js.map +1 -0
  114. package/dist/esm/plugins/bulk-edit/bulk-edit-async-plugin-factory.d.ts +61 -0
  115. package/dist/esm/plugins/bulk-edit/bulk-edit-async-plugin-factory.d.ts.map +1 -0
  116. package/dist/esm/plugins/bulk-edit/bulk-edit-async-plugin-factory.js +397 -0
  117. package/dist/esm/plugins/bulk-edit/bulk-edit-async-plugin-factory.js.map +1 -0
  118. package/dist/esm/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.d.ts +15 -0
  119. package/dist/esm/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.d.ts.map +1 -0
  120. package/dist/esm/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.js +82 -0
  121. package/dist/esm/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.js.map +1 -0
  122. package/dist/esm/plugins/deprecate-stray-node-id-fields-plugin.d.ts +14 -0
  123. package/dist/esm/plugins/deprecate-stray-node-id-fields-plugin.d.ts.map +1 -0
  124. package/dist/esm/plugins/deprecate-stray-node-id-fields-plugin.js +33 -0
  125. package/dist/esm/plugins/deprecate-stray-node-id-fields-plugin.js.map +1 -0
  126. package/dist/esm/plugins/generic-bulk-plugin-factory.d.ts +51 -0
  127. package/dist/esm/plugins/generic-bulk-plugin-factory.d.ts.map +1 -0
  128. package/dist/esm/plugins/generic-bulk-plugin-factory.js +178 -0
  129. package/dist/esm/plugins/generic-bulk-plugin-factory.js.map +1 -0
  130. package/dist/esm/plugins/graphiql-management-mode-plugin-hook.d.ts +13 -0
  131. package/dist/esm/plugins/graphiql-management-mode-plugin-hook.d.ts.map +1 -0
  132. package/dist/esm/plugins/graphiql-management-mode-plugin-hook.js +41 -0
  133. package/dist/esm/plugins/graphiql-management-mode-plugin-hook.js.map +1 -0
  134. package/dist/esm/plugins/index.d.ts +12 -0
  135. package/dist/esm/plugins/index.d.ts.map +1 -0
  136. package/dist/esm/plugins/index.js +12 -0
  137. package/dist/esm/plugins/index.js.map +1 -0
  138. package/dist/esm/plugins/omit-from-query-root-plugin.d.ts +17 -0
  139. package/dist/esm/plugins/omit-from-query-root-plugin.d.ts.map +1 -0
  140. package/dist/esm/plugins/omit-from-query-root-plugin.js +39 -0
  141. package/dist/esm/plugins/omit-from-query-root-plugin.js.map +1 -0
  142. package/dist/esm/plugins/operations-enum-generator-plugin-factory.d.ts +21 -0
  143. package/dist/esm/plugins/operations-enum-generator-plugin-factory.d.ts.map +1 -0
  144. package/dist/esm/plugins/operations-enum-generator-plugin-factory.js +112 -0
  145. package/dist/esm/plugins/operations-enum-generator-plugin-factory.js.map +1 -0
  146. package/dist/esm/plugins/subscriptions-plugin-factory.d.ts +9 -0
  147. package/dist/esm/plugins/subscriptions-plugin-factory.d.ts.map +1 -0
  148. package/dist/esm/plugins/subscriptions-plugin-factory.js +103 -0
  149. package/dist/esm/plugins/subscriptions-plugin-factory.js.map +1 -0
  150. package/dist/esm/plugins/validation-directives-plugin.d.ts +6 -0
  151. package/dist/esm/plugins/validation-directives-plugin.d.ts.map +1 -0
  152. package/dist/esm/plugins/validation-directives-plugin.js +109 -0
  153. package/dist/esm/plugins/validation-directives-plugin.js.map +1 -0
  154. package/dist/esm/postgraphile/enhance-graphql-errors.d.ts +49 -0
  155. package/dist/esm/postgraphile/enhance-graphql-errors.d.ts.map +1 -0
  156. package/dist/esm/postgraphile/enhance-graphql-errors.js +77 -0
  157. package/dist/esm/postgraphile/enhance-graphql-errors.js.map +1 -0
  158. package/dist/esm/postgraphile/index.d.ts +4 -0
  159. package/dist/esm/postgraphile/index.d.ts.map +1 -0
  160. package/dist/esm/postgraphile/index.js +4 -0
  161. package/dist/esm/postgraphile/index.js.map +1 -0
  162. package/dist/esm/postgraphile/postgraphile-options-builder.d.ts +285 -0
  163. package/dist/esm/postgraphile/postgraphile-options-builder.d.ts.map +1 -0
  164. package/dist/esm/postgraphile/postgraphile-options-builder.js +436 -0
  165. package/dist/esm/postgraphile/postgraphile-options-builder.js.map +1 -0
  166. package/dist/esm/postgraphile/websocket-utils.d.ts +11 -0
  167. package/dist/esm/postgraphile/websocket-utils.d.ts.map +1 -0
  168. package/dist/esm/postgraphile/websocket-utils.js +13 -0
  169. package/dist/esm/postgraphile/websocket-utils.js.map +1 -0
  170. package/package.json +24 -15
  171. package/src/common/index.ts +2 -2
  172. package/src/index.ts +4 -4
  173. package/src/middleware/forward-to-graphiql.ts +1 -1
  174. package/src/middleware/index.ts +1 -1
  175. package/src/plugins/add-error-codes-enum-plugin.ts +2 -2
  176. package/src/plugins/annotate-types-with-permissions-plugin.spec.ts +1 -1
  177. package/src/plugins/annotate-types-with-permissions-plugin.ts +3 -3
  178. package/src/plugins/bulk-edit/bulk-edit-async-plugin-factory.spec.ts +4 -4
  179. package/src/plugins/bulk-edit/bulk-edit-async-plugin-factory.ts +9 -9
  180. package/src/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.spec.ts +3 -3
  181. package/src/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.ts +5 -5
  182. package/src/plugins/deprecate-stray-node-id-fields-plugin.ts +2 -2
  183. package/src/plugins/generic-bulk-plugin-factory.ts +3 -3
  184. package/src/plugins/graphiql-management-mode-plugin-hook.ts +1 -1
  185. package/src/plugins/index.ts +11 -11
  186. package/src/plugins/omit-from-query-root-plugin.ts +3 -3
  187. package/src/plugins/operations-enum-generator-plugin-factory.ts +28 -5
  188. package/src/plugins/subscriptions-plugin-factory.ts +4 -4
  189. package/src/plugins/validation-directives-plugin.ts +2 -2
  190. package/src/postgraphile/enhance-graphql-errors.spec.ts +2 -2
  191. package/src/postgraphile/enhance-graphql-errors.ts +5 -5
  192. package/src/postgraphile/index.ts +3 -3
  193. package/src/postgraphile/postgraphile-options-builder.spec.ts +10 -7
  194. package/src/postgraphile/postgraphile-options-builder.ts +20 -11
  195. package/src/postgraphile/websocket-utils.ts +2 -2
  196. package/dist/common/checks.d.ts.map +0 -1
  197. package/dist/common/checks.js.map +0 -1
  198. package/dist/common/index.d.ts +0 -3
  199. package/dist/common/index.d.ts.map +0 -1
  200. package/dist/common/index.js.map +0 -1
  201. package/dist/common/types.d.ts.map +0 -1
  202. package/dist/common/types.js.map +0 -1
  203. package/dist/index.d.ts +0 -5
  204. package/dist/index.d.ts.map +0 -1
  205. package/dist/index.js.map +0 -1
  206. package/dist/middleware/forward-to-graphiql.d.ts.map +0 -1
  207. package/dist/middleware/forward-to-graphiql.js.map +0 -1
  208. package/dist/middleware/index.d.ts +0 -2
  209. package/dist/middleware/index.d.ts.map +0 -1
  210. package/dist/middleware/index.js.map +0 -1
  211. package/dist/plugins/add-error-codes-enum-plugin.d.ts.map +0 -1
  212. package/dist/plugins/add-error-codes-enum-plugin.js.map +0 -1
  213. package/dist/plugins/annotate-types-with-permissions-plugin.d.ts.map +0 -1
  214. package/dist/plugins/annotate-types-with-permissions-plugin.js.map +0 -1
  215. package/dist/plugins/bulk-edit/bulk-edit-async-plugin-factory.d.ts.map +0 -1
  216. package/dist/plugins/bulk-edit/bulk-edit-async-plugin-factory.js.map +0 -1
  217. package/dist/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.d.ts.map +0 -1
  218. package/dist/plugins/bulk-edit/bulk-edit-item-change-handler-helpers.js.map +0 -1
  219. package/dist/plugins/deprecate-stray-node-id-fields-plugin.d.ts.map +0 -1
  220. package/dist/plugins/deprecate-stray-node-id-fields-plugin.js.map +0 -1
  221. package/dist/plugins/generic-bulk-plugin-factory.d.ts.map +0 -1
  222. package/dist/plugins/generic-bulk-plugin-factory.js.map +0 -1
  223. package/dist/plugins/graphiql-management-mode-plugin-hook.d.ts.map +0 -1
  224. package/dist/plugins/graphiql-management-mode-plugin-hook.js.map +0 -1
  225. package/dist/plugins/index.d.ts +0 -12
  226. package/dist/plugins/index.d.ts.map +0 -1
  227. package/dist/plugins/index.js.map +0 -1
  228. package/dist/plugins/omit-from-query-root-plugin.d.ts.map +0 -1
  229. package/dist/plugins/omit-from-query-root-plugin.js.map +0 -1
  230. package/dist/plugins/operations-enum-generator-plugin-factory.d.ts.map +0 -1
  231. package/dist/plugins/operations-enum-generator-plugin-factory.js.map +0 -1
  232. package/dist/plugins/subscriptions-plugin-factory.d.ts.map +0 -1
  233. package/dist/plugins/subscriptions-plugin-factory.js.map +0 -1
  234. package/dist/plugins/validation-directives-plugin.d.ts.map +0 -1
  235. package/dist/plugins/validation-directives-plugin.js.map +0 -1
  236. package/dist/postgraphile/enhance-graphql-errors.d.ts.map +0 -1
  237. package/dist/postgraphile/enhance-graphql-errors.js.map +0 -1
  238. package/dist/postgraphile/index.d.ts +0 -4
  239. package/dist/postgraphile/index.d.ts.map +0 -1
  240. package/dist/postgraphile/index.js.map +0 -1
  241. package/dist/postgraphile/postgraphile-options-builder.d.ts.map +0 -1
  242. package/dist/postgraphile/postgraphile-options-builder.js.map +0 -1
  243. package/dist/postgraphile/websocket-utils.d.ts.map +0 -1
  244. package/dist/postgraphile/websocket-utils.js.map +0 -1
  245. /package/dist/{common → cjs/common}/checks.d.ts +0 -0
  246. /package/dist/{common → cjs/common}/checks.js +0 -0
  247. /package/dist/{common → cjs/common}/types.d.ts +0 -0
  248. /package/dist/{common → cjs/common}/types.js +0 -0
  249. /package/dist/{middleware → cjs/middleware}/forward-to-graphiql.js +0 -0
  250. /package/dist/{plugins → cjs/plugins}/add-error-codes-enum-plugin.js +0 -0
  251. /package/dist/{plugins → cjs/plugins}/bulk-edit/bulk-edit-item-change-handler-helpers.js +0 -0
  252. /package/dist/{plugins → cjs/plugins}/graphiql-management-mode-plugin-hook.js +0 -0
  253. /package/dist/{postgraphile → cjs/postgraphile}/websocket-utils.js +0 -0
@@ -0,0 +1,436 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import _PgPubsub from '@graphile/pg-pubsub';
3
+ import { NodePlugin } from 'graphile-build';
4
+ import { GraphQLError } from 'graphql';
5
+ import { IncomingMessage } from 'http';
6
+ import { makePluginHook, } from 'postgraphile';
7
+ import { enhanceGraphqlErrors } from './enhance-graphql-errors.js';
8
+ // @graphile/pg-pubsub is a TypeScript-compiled CJS package that emits
9
+ // `module.exports = { __esModule: true, default: pluginObject }`.
10
+ // Node.js native ESM does not honour the __esModule sentinel, so the default
11
+ // import receives the whole module.exports wrapper object, not the plugin.
12
+ // `createRequire` cannot be used here because `import.meta.url` does not
13
+ // compile under `module: CommonJS` in the CJS build pass of this dual-publish
14
+ // library. The long-term fix is upgrading to PostGraphile v5, which replaces
15
+ // this plugin with a first-class ESM-compatible subscription API.
16
+ const PgPubsub = (_PgPubsub.default ?? _PgPubsub);
17
+ /**
18
+ * A builder class that allows construction of postgraphile options using multiple dedicated extension methods.
19
+ */
20
+ export class PostgraphileOptionsBuilder {
21
+ transformers = [];
22
+ headers = {};
23
+ pluginHooks = new Set();
24
+ hookFuncs = new Set();
25
+ /**
26
+ * Builds a postgraphile options object with previously used extension methods.
27
+ */
28
+ build() {
29
+ let options = {};
30
+ for (const transform of this.transformers) {
31
+ options = transform(options);
32
+ }
33
+ this.buildHeadersHookPlugin();
34
+ // Build plugin hooks from hook functions
35
+ [...this.hookFuncs].map((hookFunc) => {
36
+ this.pluginHooks.add(hookFunc(options));
37
+ });
38
+ if (this.pluginHooks.size > 0) {
39
+ options.pluginHook = makePluginHook([...this.pluginHooks]);
40
+ }
41
+ return options;
42
+ }
43
+ /**
44
+ * Builds a hook plugin that adds custom headers to http responses.
45
+ */
46
+ buildHeadersHookPlugin() {
47
+ if (Object.keys(this.headers).length > 0) {
48
+ this.pluginHooks.add({
49
+ 'postgraphile:http:handler': (req, { res }) => {
50
+ for (const key in this.headers) {
51
+ if (Object.prototype.hasOwnProperty.call(this.headers, key)) {
52
+ res.setHeader(key, this.headers[key]);
53
+ }
54
+ }
55
+ return req;
56
+ },
57
+ });
58
+ }
59
+ }
60
+ /**
61
+ * This builder option must be used if the Hook Plugin requires PostGraphileOptions in the logic.
62
+ * A function which returns a PostGraphilePlugin should be passed into this method.
63
+ * That function will use PostGraphileOptions created in the build() method and attach the plugin returned from the function as a Postgraphile Hook.
64
+ * @example
65
+ *
66
+ * ```ts
67
+ new PostgraphileOptionsBuilder()
68
+ .addHookPluginFactory(customHookFactory)
69
+ * ```
70
+ *
71
+ * @param hookFunction This is a function which takes an argument of type PostGraphileOptions<Request, Response> and returns a PostGraphilePlugin object.
72
+ * @returns
73
+ */
74
+ addHookPluginFactory(hookFunction) {
75
+ this.hookFuncs.add(hookFunction);
76
+ return this;
77
+ }
78
+ /**
79
+ * This function takes a PostGraphilePlugin object and attaches it as a Postgraphile Hook when build() is called.
80
+ * @example
81
+ *
82
+ * ```ts
83
+ new PostgraphileOptionsBuilder()
84
+ .addHookPluginFunction(subscriptionAuthorizationHook)
85
+ * ```
86
+ *
87
+ * @param hookPlugin This is a PostGraphilePlugin object.
88
+ * @returns
89
+ */
90
+ addHookPlugin(hookPlugin) {
91
+ this.pluginHooks.add(hookPlugin);
92
+ return this;
93
+ }
94
+ /**
95
+ * Sets `pgSettings` property of postgraphile options object.
96
+ * Example:
97
+ *
98
+ * ```ts
99
+ new PostgraphileOptionsBuilder()
100
+ .setPgSettings(async req => {
101
+ const { subject } = await getManagementAuthenticationContext(req, idServiceParams);
102
+ return buildPgSettings(subject, config.dbGqlRole, config.serviceId);
103
+ })
104
+ * ```
105
+ *
106
+ * @param pgSettings A plain object specifying custom config values to set in the PostgreSQL transaction (accessed via current_setting('my.custom.setting')) or an (optionally asynchronous) function which will return the same (or a Promise to the same) based on the incoming web request (e.g. to extract session data).
107
+ */
108
+ setPgSettings(pgSettings) {
109
+ this.transformers.push((options) => {
110
+ options.pgSettings = pgSettings;
111
+ return options;
112
+ });
113
+ return this;
114
+ }
115
+ /**
116
+ * Sets `handleErrors` property of postgraphile options object.
117
+ * Example:
118
+ *
119
+ * ```ts
120
+ new PostgraphileOptionsBuilder()
121
+ .setErrorsHandler((errors, req) => {
122
+ return enhanceGraphqlErrors(
123
+ result.errors,
124
+ req.body?.operationName,
125
+ customizeGraphQlErrorFields(defaultPgErrorMapper),
126
+ logGraphQlError(defaultWriteLogMapper, req.authContext?.subject, this.logger),
127
+ );
128
+ }
129
+ })
130
+ * ```
131
+ *
132
+ * @param handleErrors Enables ability to modify errors before sending them down to the client. Optionally can send down custom responses. If you use this then showErrorStack and extendedError may have no effect.
133
+ */
134
+ setErrorsHandler(handleErrors) {
135
+ this.transformers.push((options) => {
136
+ options.handleErrors = handleErrors;
137
+ return options;
138
+ });
139
+ return this;
140
+ }
141
+ /**
142
+ * Sets properties of postgraphile options object to be used in without any conditions. Additional calls will override and add properties.
143
+ * Example:
144
+ *
145
+ * ```ts
146
+ new PostgraphileOptionsBuilder()
147
+ .setProperties({
148
+ enableCors: true,
149
+ dynamicJson: true,
150
+ ignoreRBAC: false,
151
+ legacyRelations: 'omit',
152
+ setofFunctionsContainNulls: false,
153
+ })
154
+ * ```
155
+ * @param properties An object containing postgraphile options.
156
+ */
157
+ setProperties(properties) {
158
+ this.transformers.push((options) => {
159
+ return { ...options, ...properties };
160
+ });
161
+ return this;
162
+ }
163
+ /**
164
+ * Sets properties of postgraphile options object to be used based on some
165
+ * condition (use if true, omit if false). Additional calls will override and
166
+ * add properties.
167
+ * Example:
168
+ *
169
+ * ```ts
170
+ new PostgraphileOptionsBuilder()
171
+ .setConditionalProperties(config.isDev, {
172
+ exportGqlSchemaPath: './src/generated/schema.graphql',
173
+ watchPg: true,
174
+ graphiql: true,
175
+ enhanceGraphiql: true,
176
+ allowExplain: true,
177
+ })
178
+ * ```
179
+ * @param properties An object containing postgraphile options.
180
+ */
181
+ setConditionalProperties(condition, properties) {
182
+ if (condition) {
183
+ this.transformers.push((options) => {
184
+ return { ...options, ...properties };
185
+ });
186
+ }
187
+ return this;
188
+ }
189
+ /**
190
+ * Sets all necessary postgraphile properties to enable subscriptions.
191
+ * Example:
192
+ *
193
+ * ```ts
194
+ new PostgraphileOptionsBuilder()
195
+ .enableSubscriptions({
196
+ plugin: SubscriptionsPlugin,
197
+ websocketMiddlewares: middlewares,
198
+ hookFactory: subscriptionAuthorizationHookFactory
199
+ })
200
+ * ```
201
+ *
202
+ * Results in something like this:
203
+ *
204
+ * ```ts
205
+ import PgPubsub from '@graphile/pg-pubsub';
206
+ import { makePluginHook } from 'postgraphile';
207
+ //.........
208
+ {
209
+ appendPlugins: [SubscriptionsPlugin], // Other plugins will be included if they were added using other methods
210
+ pluginHook: makePluginHook([PgPubsub, subscriptionAuthorizationHook]),
211
+ subscriptions: true,
212
+ websocketMiddlewares, // Empty array if websocketMiddlewares are not specified
213
+ subscriptionEventEmitterMaxListeners: 0, // unlimited
214
+ }
215
+ * ```
216
+ *
217
+ * To make sure that Postgraphile is able to correctly establish WebSockets
218
+ * connection, additional changes should be done by using
219
+ * `enhanceHttpServerWithSubscriptions`.
220
+ *
221
+ * See more here: https://www.graphile.org/postgraphile/subscriptions/#advanced-setup
222
+ *
223
+ * To customize the maximum number of listeners use:
224
+ *
225
+ * ```ts
226
+ * import PgPubsub from '@graphile/pg-pubsub'; // must be imported to extend the PostGraphileOptions type with the pg-pubsub options.
227
+ * ...
228
+ * new PostgraphileOptionsBuilder()
229
+ * .setProperties({
230
+ * subscriptionEventEmitterMaxListeners: 42,
231
+ * })
232
+ * ```
233
+ *
234
+ * @param plugin Graphile engine plugin that adds one or multiple subscription
235
+ * endpoints. Can be added separately.
236
+ * @param websocketMiddlewares If you're using websockets (subscriptions ||
237
+ * live) then you may want to authenticate your users using sessions or
238
+ * similar. You can pass some simple middlewares here that will be executed
239
+ * against the websocket connection in order to perform authentication.
240
+ * @param hookFactory A factory function for a Postgraphile hook plugin.
241
+ */
242
+ enableSubscriptions({ plugin, websocketMiddlewares, hookFactory, }) {
243
+ this.transformers.push((options) => {
244
+ options.subscriptions = true;
245
+ options.appendPlugins = [
246
+ ...new Set([...(options.appendPlugins ?? []), plugin]),
247
+ ];
248
+ options.subscriptionEventEmitterMaxListeners = 0;
249
+ // Add the pub/sub realtime provider
250
+ // This is for PostGraphile server plugins: https://www.graphile.org/postgraphile/plugins/
251
+ this.pluginHooks.add(PgPubsub);
252
+ if (websocketMiddlewares) {
253
+ options.websocketMiddlewares = [
254
+ ...new Set([
255
+ ...(options.websocketMiddlewares ?? []),
256
+ ...websocketMiddlewares,
257
+ ]),
258
+ ];
259
+ }
260
+ else if (!options.websocketMiddlewares) {
261
+ options.websocketMiddlewares = [];
262
+ }
263
+ if (hookFactory) {
264
+ this.hookFuncs.add(hookFactory);
265
+ }
266
+ return options;
267
+ });
268
+ return this;
269
+ }
270
+ /**
271
+ * Adds multiple graphile engine plugins to `appendPlugins` array of postgraphile options object. `setAdditionalGraphQLContextFromRequest` and `addGraphileBuildOptions` methods can be used to pass parameters to said plugins.
272
+ * Example:
273
+ *
274
+ ```ts
275
+ new PostgraphileOptionsBuilder()
276
+ .addPlugins(
277
+ PgSimplifyInflectorPlugin,
278
+ ScalarTypesPlugin,
279
+ SmartTagsPlugin,
280
+ ValidationDirectivesPlugin,
281
+ )
282
+ ```
283
+ * @param plugins Comma-separated list of Graphile Engine schema plugins to load after the default plugins.
284
+ */
285
+ addPlugins(...plugins) {
286
+ this.transformers.push((options) => {
287
+ options.appendPlugins = [
288
+ ...new Set([...(options.appendPlugins ?? []), ...plugins]),
289
+ ];
290
+ return options;
291
+ });
292
+ return this;
293
+ }
294
+ /**
295
+ * Adds multiple graphile engine plugins to `appendPlugins` array of postgraphile options object.
296
+ * `setAdditionalGraphQLContextFromRequest` and `addGraphileBuildOptions` methods can be used to pass parameters to said plugins.
297
+ * Explicit condition parameter is used to make a decision if plugins should be used or not (use if true, omit if false).
298
+ * Example:
299
+ *
300
+ ```ts
301
+ new PostgraphileOptionsBuilder()
302
+ .addConditionalPlugins(config.isDev || config.enablePopulatePlugins, PopulateMoviesPlugin, PopulateTvshowsPlugin)
303
+ ```
304
+ * @param plugins Comma-separated list of Graphile Engine schema plugins to load after the default plugins.
305
+ */
306
+ addConditionalPlugins(condition, ...plugins) {
307
+ if (condition) {
308
+ this.addPlugins(...plugins);
309
+ }
310
+ return this;
311
+ }
312
+ /**
313
+ * Skips multiple default postgraphile plugins by adding them to `skipPlugins` array of postgraphile options object .
314
+ * Example:
315
+ *
316
+ ```ts
317
+ new PostgraphileOptionsBuilder()
318
+ .skipPlugins(NodePlugin, MutationPayloadQueryPlugin)
319
+ ```
320
+ * @param plugins Comma-separated list of Graphile Engine schema plugins to skip.
321
+ */
322
+ skipPlugins(...plugins) {
323
+ this.transformers.push((options) => {
324
+ options.skipPlugins = [
325
+ ...new Set([...(options.skipPlugins ?? []), ...plugins]),
326
+ ];
327
+ return options;
328
+ });
329
+ return this;
330
+ }
331
+ /**
332
+ * Adds properties to resulting `graphileBuildOptions` property of postgraphile options object. Useful for modifying default postgraphile plugin settings.
333
+ * Example:
334
+ *
335
+ ```ts
336
+ new PostgraphileOptionsBuilder()
337
+ .addGraphileBuildOptions({ pgSkipInstallingWatchFixtures: true })
338
+ ```
339
+ * @param graphileBuildOptions Additional Options to pass through into the graphile schema building system (received via the second argument of a plugin).
340
+ */
341
+ addGraphileBuildOptions(graphileBuildOptions) {
342
+ this.transformers.push((options) => {
343
+ options.graphileBuildOptions = {
344
+ ...(options.graphileBuildOptions ?? {}),
345
+ ...graphileBuildOptions,
346
+ };
347
+ return options;
348
+ });
349
+ return this;
350
+ }
351
+ /**
352
+ * Adds `additionalGraphQLContextFromRequest` property to postgraphile options object. Define only once. Multiple calls will not expand previous calls, but will override them.
353
+ *
354
+ * Example:
355
+ ```ts
356
+ new PostgraphileOptionsBuilder()
357
+ .setAdditionalGraphQLContextFromRequest(async req => {
358
+ const { subject } = await getManagementAuthenticationContext(req);
359
+ return { subject, serviceId: config.serviceId };
360
+ })
361
+ ```
362
+ * @param callback Some Graphile Engine schema plugins may need additional information available on the context argument to the resolver - you can use this function to provide such information based on the incoming request - you can even use this to change the response , e.g. setting cookies.
363
+ */
364
+ setAdditionalGraphQLContextFromRequest(callback) {
365
+ this.transformers.push((options) => {
366
+ options.additionalGraphQLContextFromRequest = callback;
367
+ return options;
368
+ });
369
+ return this;
370
+ }
371
+ /**
372
+ * Enables or disables graphiql GUI depending on a passed condition parameter. Enable if true, disable if false.
373
+ * Sets 3 postgraphile properties: `graphiql`, `enhanceGraphiql` and `allowExplain`.
374
+ * Example:
375
+ *
376
+ * ```ts
377
+ new PostgraphileOptionsBuilder()
378
+ .setGraphiql(config.graphqlGuiEnabled)
379
+ * ```
380
+ */
381
+ setGraphiql(condition) {
382
+ this.transformers.push((options) => {
383
+ return {
384
+ ...options,
385
+ ...{
386
+ graphiql: condition,
387
+ enhanceGraphiql: condition,
388
+ allowExplain: condition,
389
+ },
390
+ };
391
+ });
392
+ return this;
393
+ }
394
+ /**
395
+ * Sets a response header for each GraphQL request.
396
+ *
397
+ * @param name header name
398
+ * @param value header value
399
+ */
400
+ setHeader(name, value) {
401
+ this.headers[name] = value;
402
+ return this;
403
+ }
404
+ /**
405
+ * Sets default values for properties that we see as best practices which most
406
+ * services should start from. This includes the default GraphQL errors handler,
407
+ * suggested default properties, development properties in dev-environments,
408
+ * and excludes the 'NodePlugin'.
409
+ */
410
+ setDefaultSettings(isDev, graphqlGuiEnabled) {
411
+ this.setErrorsHandler((errors) => {
412
+ return enhanceGraphqlErrors(errors);
413
+ })
414
+ .setProperties({
415
+ enableCors: true,
416
+ dynamicJson: true,
417
+ ignoreRBAC: false,
418
+ legacyRelations: 'omit',
419
+ setofFunctionsContainNulls: false,
420
+ watchPg: false,
421
+ disableQueryLog: true,
422
+ retryOnInitFail: true,
423
+ })
424
+ .setConditionalProperties(isDev, {
425
+ exportGqlSchemaPath: './src/generated/graphql/schema.graphql',
426
+ watchPg: true,
427
+ disableQueryLog: false,
428
+ retryOnInitFail: false,
429
+ })
430
+ .setGraphiql(graphqlGuiEnabled)
431
+ // removes some nodeId and byNodeId endpoints, but still leaves support for cursor pagination
432
+ .skipPlugins(NodePlugin);
433
+ return this;
434
+ }
435
+ }
436
+ //# sourceMappingURL=postgraphile-options-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgraphile-options-builder.js","sourceRoot":"","sources":["../../../src/postgraphile/postgraphile-options-builder.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAe,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EACL,cAAc,GAOf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,sEAAsE;AACtE,kEAAkE;AAClE,6EAA6E;AAC7E,2EAA2E;AAC3E,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,kEAAkE;AAClE,MAAM,QAAQ,GAAG,CAAE,SAAiB,CAAC,OAAO,IAAI,SAAS,CAAqB,CAAC;AAoB/E;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAC7B,YAAY,GAE6B,EAAE,CAAC;IAE5C,OAAO,GAAqC,EAAE,CAAC;IAC/C,WAAW,GAA4B,IAAI,GAAG,EAAsB,CAAC;IACrE,SAAS,GAA2B,IAAI,GAAG,EAAqB,CAAC;IAEzE;;OAEG;IACI,KAAK;QACV,IAAI,OAAO,GAA2C,EAAE,CAAC;QACzD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1C,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAE9B,yCAAyC;QACzC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YACnC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,IAAI,IAA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;IACd,CAAC;IAED;;;;;OAKG;IACI,SAAS,CACd,IAAY,EACZ,KAAiC;QAEjC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,kBAAkB,CACvB,KAAc,EACd,iBAA0B;QAE1B,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,EAAE;YAC/B,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC,CAAC;aACC,aAAa,CAAC;YACb,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,KAAK;YACjB,eAAe,EAAE,MAAM;YACvB,0BAA0B,EAAE,KAAK;YAEjC,OAAO,EAAE,KAAK;YACd,eAAe,EAAE,IAAI;YACrB,eAAe,EAAE,IAAI;SACtB,CAAC;aACD,wBAAwB,CAAC,KAAK,EAAE;YAC/B,mBAAmB,EAAE,wCAAwC;YAC7D,OAAO,EAAE,IAAI;YACb,eAAe,EAAE,KAAK;YACtB,eAAe,EAAE,KAAK;SACvB,CAAC;aACD,WAAW,CAAC,iBAAiB,CAAC;YAC/B,6FAA6F;aAC5F,WAAW,CAAC,UAAU,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import type { Request } from 'express';
2
+ import type { WebSocket } from 'graphql-ws';
3
+ /**
4
+ * Extract the reference to web socket when given a request object that is coming
5
+ * from Postgraphile. The web socket reference is attached as a symbol.
6
+ *
7
+ * @param req A Postgraphile request.
8
+ * @returns
9
+ */
10
+ export declare const getWebsocketFromRequest: (req: Request) => WebSocket | undefined;
11
+ //# sourceMappingURL=websocket-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-utils.d.ts","sourceRoot":"","sources":["../../../src/postgraphile/websocket-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,OAAO,KACX,SAAS,GAAG,SAMd,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Extract the reference to web socket when given a request object that is coming
3
+ * from Postgraphile. The web socket reference is attached as a symbol.
4
+ *
5
+ * @param req A Postgraphile request.
6
+ * @returns
7
+ */
8
+ export const getWebsocketFromRequest = (req) => {
9
+ const websocketSymbol = Object.getOwnPropertySymbols(req.socket).filter((sym) => sym.description === 'websocket')[0];
10
+ const websocket = req.socket[websocketSymbol];
11
+ return websocket;
12
+ };
13
+ //# sourceMappingURL=websocket-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-utils.js","sourceRoot":"","sources":["../../../src/postgraphile/websocket-utils.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,GAAY,EACW,EAAE;IACzB,MAAM,eAAe,GAAG,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CACrE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,KAAK,WAAW,CACzC,CAAC,CAAC,CAAC,CAAC;IACL,MAAM,SAAS,GAAI,GAAW,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACvD,OAAO,SAAsB,CAAC;AAChC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-graphql-common",
3
- "version": "0.33.0",
3
+ "version": "0.34.0-rc.3",
4
4
  "description": "Common GraphQL and PostGraphile related functionality.",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -13,31 +13,41 @@
13
13
  "dist",
14
14
  "src"
15
15
  ],
16
- "main": "dist/index.js",
17
- "types": "dist/index.d.ts",
16
+ "main": "dist/cjs/index.js",
17
+ "module": "dist/esm/index.js",
18
+ "types": "dist/cjs/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/cjs/index.d.ts",
22
+ "import": "./dist/esm/index.js",
23
+ "require": "./dist/cjs/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
18
27
  "scripts": {
19
28
  "clean": "rimraf dist",
20
- "build": "yarn clean && tsc --project tsconfig.build.json",
21
- "ts:validate": "tsc",
29
+ "build": "yarn clean && tsc --project tsconfig.build.json && tsc --project tsconfig.build.esm.json && node ../../scripts/write-esm-markers.js",
30
+ "ts:validate": "tsc && yarn build && yarn check:esm-interop",
22
31
  "build:ci": "yarn workspaces focus && yarn build",
23
32
  "dev": "tsc -w --project tsconfig.build.json",
24
33
  "publish:latest": "npm run build && npm publish",
25
34
  "test": "vitest run --silent",
26
35
  "test:watch": "vitest watch",
27
36
  "test:cov": "vitest run --coverage --silent && yarn posttest:cov",
28
- "posttest:cov": "ts-node ../../scripts/open-test-coverage.ts -- libs/graphql-common",
37
+ "posttest:cov": "tsx ../../scripts/open-test-coverage.ts -- libs/graphql-common",
38
+ "check:esm-interop": "node ./scripts/check-esm-interop.mjs",
29
39
  "test:debug": "vitest run --inspect-brk --no-file-parallelism",
30
40
  "test:ci": "vitest run --reporter=default --reporter=junit --coverage --coverage.reporter=cobertura --coverage.reporter=html",
31
41
  "test:ui": "vitest --ui",
32
42
  "lint": "eslint . --ext .ts,.tsx,.js --color --cache"
33
43
  },
34
44
  "dependencies": {
35
- "@axinom/mosaic-db-common": "^0.57.0",
36
- "@axinom/mosaic-message-bus": "^0.50.0",
37
- "@axinom/mosaic-message-bus-abstractions": "^0.24.3",
38
- "@axinom/mosaic-messages": "^0.67.0",
39
- "@axinom/mosaic-service-common": "^0.69.0",
40
- "@axinom/mosaic-transactional-inbox-outbox": "^0.29.0",
45
+ "@axinom/mosaic-db-common": "^0.58.0-rc.3",
46
+ "@axinom/mosaic-message-bus": "^0.51.0-rc.3",
47
+ "@axinom/mosaic-message-bus-abstractions": "^0.24.4-rc.3",
48
+ "@axinom/mosaic-messages": "^0.68.0-rc.3",
49
+ "@axinom/mosaic-service-common": "^0.70.0-rc.3",
50
+ "@axinom/mosaic-transactional-inbox-outbox": "^0.30.0-rc.3",
41
51
  "@graphile/pg-pubsub": "^4.12.3",
42
52
  "endent": "^2.1.0",
43
53
  "express": "^4.17.1",
@@ -51,7 +61,7 @@
51
61
  "postgraphile": "^4.13.0"
52
62
  },
53
63
  "devDependencies": {
54
- "@axinom/mosaic-dev-be-common": "^0.18.0",
64
+ "@axinom/mosaic-dev-be-common": "^0.19.0-rc.3",
55
65
  "@types/express": "^4.17.17",
56
66
  "@types/inflection": "^1.5.28",
57
67
  "@types/node": "^22.0.0",
@@ -59,12 +69,11 @@
59
69
  "eslint": "^8.35.0",
60
70
  "jest-extended": "^7.0.0",
61
71
  "rimraf": "^3.0.2",
62
- "ts-node": "^10.9.1",
63
72
  "typescript": "^5.9.3",
64
73
  "vitest": "^4.0.18"
65
74
  },
66
75
  "publishConfig": {
67
76
  "access": "public"
68
77
  },
69
- "gitHead": "75dcfd9bf92de1ef72a28f073e43a7dfaa7b430b"
78
+ "gitHead": "9c7831acd6fcced9a09f97ffd4c9d67ee1b3b640"
70
79
  }
@@ -1,2 +1,2 @@
1
- export * from './checks';
2
- export * from './types';
1
+ export * from './checks.js';
2
+ export * from './types.js';
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './common';
2
- export * from './middleware';
3
- export * from './plugins';
4
- export * from './postgraphile';
1
+ export * from './common/index.js';
2
+ export * from './middleware/index.js';
3
+ export * from './plugins/index.js';
4
+ export * from './postgraphile/index.js';
@@ -1,4 +1,4 @@
1
- import { NextFunction, Request, Response } from 'express';
1
+ import type { NextFunction, Request, Response } from 'express';
2
2
 
3
3
  /**
4
4
  * Middleware that forwards requests that accept html to graphiql.
@@ -1 +1 @@
1
- export * from './forward-to-graphiql';
1
+ export * from './forward-to-graphiql.js';
@@ -1,6 +1,6 @@
1
1
  import { GraphQLEnumType } from 'graphql';
2
- import { Plugin } from 'postgraphile';
3
- import { Dict } from '../common';
2
+ import type { Plugin } from 'postgraphile';
3
+ import type { Dict } from '../common/index.js';
4
4
 
5
5
  type GraphQLEnumValues = Dict<{ value: string; description: string }>;
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { exportedForTestingAnnotatePlugin } from './annotate-types-with-permissions-plugin';
2
+ import { exportedForTestingAnnotatePlugin } from './annotate-types-with-permissions-plugin.js';
3
3
  const getPolicy = (
4
4
  overrides: {
5
5
  permissive?: string;
@@ -1,6 +1,6 @@
1
- import { Pool } from 'pg';
2
- import { Plugin } from 'postgraphile';
3
- import { isNullOrWhitespace } from '../common';
1
+ import type { Pool } from 'pg';
2
+ import type { Plugin } from 'postgraphile';
3
+ import { isNullOrWhitespace } from '../common/index.js';
4
4
 
5
5
  interface PolicyRow {
6
6
  schemaname: string;
@@ -21,10 +21,10 @@ vi.mock('@axinom/mosaic-db-common', async () => {
21
21
  };
22
22
  });
23
23
 
24
- import { PerformItemChangeCommand } from '@axinom/mosaic-messages';
25
- import { StoreInboxMessage } from '@axinom/mosaic-transactional-inbox-outbox';
26
- import { DatabaseClient } from 'pg-transactional-outbox';
27
- import { asyncResolverImplementation } from './bulk-edit-async-plugin-factory';
24
+ import type { PerformItemChangeCommand } from '@axinom/mosaic-messages';
25
+ import type { StoreInboxMessage } from '@axinom/mosaic-transactional-inbox-outbox';
26
+ import type { DatabaseClient } from 'pg-transactional-outbox';
27
+ import { asyncResolverImplementation } from './bulk-edit-async-plugin-factory.js';
28
28
 
29
29
  describe('bulk-edit-async-plugin-factory', () => {
30
30
  describe('asyncResolverImplementation', () => {