@smartive/graphql-magic 17.2.0 → 17.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- # [17.2.0](https://github.com/smartive/graphql-magic/compare/v17.1.0...v17.2.0) (2025-03-05)
1
+ ## [17.2.2](https://github.com/smartive/graphql-magic/compare/v17.2.1...v17.2.2) (2025-04-09)
2
2
 
3
3
 
4
- ### Features
4
+ ### Bug Fixes
5
5
 
6
- * Add indices to foreign keys ([#249](https://github.com/smartive/graphql-magic/issues/249)) ([652e612](https://github.com/smartive/graphql-magic/commit/652e612b2ecceec62830b8b6b3d0b4b15b09b6c7))
6
+ * allow void as return type for mutation hook ([#264](https://github.com/smartive/graphql-magic/issues/264)) ([2b2dbef](https://github.com/smartive/graphql-magic/commit/2b2dbefbec79505a2889bb67b9c88361459b905d))
package/dist/bin/gqm.cjs CHANGED
@@ -2040,6 +2040,14 @@ var VISITOR = {
2040
2040
  return Symbol;
2041
2041
  case "Models":
2042
2042
  return Models;
2043
+ case "Object":
2044
+ return Object;
2045
+ case "Array":
2046
+ return Array;
2047
+ case "Boolean":
2048
+ return Boolean;
2049
+ case "Number":
2050
+ return Number;
2043
2051
  }
2044
2052
  const definitionNodes = node.getDefinitionNodes();
2045
2053
  if (!definitionNodes.length) {
@@ -2081,6 +2089,18 @@ var VISITOR = {
2081
2089
  case "toLowerCase":
2082
2090
  return target[name2].bind(target);
2083
2091
  }
2092
+ } else if (typeof target === "function") {
2093
+ const name2 = node.getName();
2094
+ if (target === Object) {
2095
+ switch (name2) {
2096
+ case "keys":
2097
+ case "values":
2098
+ case "entries":
2099
+ case "assign":
2100
+ case "hasOwnProperty":
2101
+ return target[name2].bind(target);
2102
+ }
2103
+ }
2084
2104
  }
2085
2105
  throw new Error(`Cannot handle method ${node.getName()} on type ${typeof target}`);
2086
2106
  }
@@ -7,4 +7,4 @@ export type MutationHook<DateType extends AnyDateType = AnyDateType> = (model: E
7
7
  input: Entity;
8
8
  normalizedInput: Entity;
9
9
  next: Entity;
10
- }, ctx: Context<DateType>) => Promise<void>;
10
+ }, ctx: Context<DateType>) => Promise<void> | void;
@@ -0,0 +1,56 @@
1
+ # Migration Guides
2
+
3
+ ## Upgrading to v17.2.0
4
+
5
+ From now on, foreign keys will be indexed by default. For existing projects, you'll need to add indices manually to your existing foreign keys.
6
+
7
+ Here's a sample script to generate the migration:
8
+
9
+ ```ts
10
+ import { execSync } from 'child_process';
11
+ import { writeFileSync } from 'fs';
12
+ import { models } from '../../../src/config/models';
13
+
14
+ const start = async () => {
15
+ const instructions: string[] = [];
16
+
17
+ instructions.push(`import { Knex } from 'knex';
18
+
19
+ export const up = async (knex: Knex) => {`);
20
+
21
+ for (const model of models.entities) {
22
+ if (model.fields.some((field) => field.kind === 'relation')) {
23
+ instructions.push(`await knex.schema.alterTable('${model.name}', (table) => {`);
24
+ for (const field of model.fields) {
25
+ if (field.kind === 'relation') {
26
+ instructions.push(`table.index('${field.foreignKey || field.name + 'Id'}');`);
27
+ }
28
+ }
29
+ instructions.push(`});`);
30
+ }
31
+ }
32
+
33
+ instructions.push(`};`);
34
+
35
+ instructions.push(`export const down = async (knex: Knex) => {`);
36
+
37
+ for (const model of models.entities) {
38
+ if (model.fields.some((field) => field.kind === 'relation')) {
39
+ instructions.push(`await knex.schema.alterTable('${model.name}', (table) => {`);
40
+ for (const field of model.fields) {
41
+ if (field.kind === 'relation') {
42
+ instructions.push(`table.dropIndex('${field.foreignKey || field.name + 'Id'}');`);
43
+ }
44
+ }
45
+ instructions.push(`});`);
46
+ }
47
+ }
48
+
49
+ instructions.push(`};`);
50
+
51
+ writeFileSync('migrations/20250305130109_create-foreign-key-indices.ts', instructions.join('\n'));
52
+ execSync('npx eslint --fix migrations/20250305130109_create-foreign-key-indices.ts');
53
+ };
54
+
55
+ void start();
56
+ ```
@@ -20,7 +20,7 @@
20
20
  "@docusaurus/module-type-aliases": "3.7.0",
21
21
  "@docusaurus/tsconfig": "3.7.0",
22
22
  "@docusaurus/types": "3.7.0",
23
- "typescript": "5.8.2"
23
+ "typescript": "5.8.3"
24
24
  },
25
25
  "engines": {
26
26
  "node": ">=22.0"
@@ -16466,9 +16466,9 @@
16466
16466
  }
16467
16467
  },
16468
16468
  "node_modules/typescript": {
16469
- "version": "5.8.2",
16470
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz",
16471
- "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==",
16469
+ "version": "5.8.3",
16470
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
16471
+ "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
16472
16472
  "license": "Apache-2.0",
16473
16473
  "bin": {
16474
16474
  "tsc": "bin/tsc",
package/docs/package.json CHANGED
@@ -27,7 +27,7 @@
27
27
  "@docusaurus/module-type-aliases": "3.7.0",
28
28
  "@docusaurus/tsconfig": "3.7.0",
29
29
  "@docusaurus/types": "3.7.0",
30
- "typescript": "5.8.2"
30
+ "typescript": "5.8.3"
31
31
  },
32
32
  "browserslist": {
33
33
  "production": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartive/graphql-magic",
3
- "version": "17.2.0",
3
+ "version": "17.2.2",
4
4
  "description": "",
5
5
  "source": "src/index.ts",
6
6
  "type": "module",
@@ -69,18 +69,18 @@
69
69
  "@smartive/prettier-config": "3.1.2",
70
70
  "@types/jest": "29.5.14",
71
71
  "@types/lodash": "4.17.16",
72
- "@types/luxon": "3.4.2",
72
+ "@types/luxon": "3.6.2",
73
73
  "@types/pg": "8.11.11",
74
74
  "@types/uuid": "10.0.0",
75
75
  "create-ts-index": "1.14.0",
76
76
  "del-cli": "6.0.0",
77
- "esbuild": "0.25.0",
78
- "eslint": "9.21.0",
77
+ "esbuild": "0.25.2",
78
+ "eslint": "9.24.0",
79
79
  "jest": "29.7.0",
80
80
  "mock-knex": "0.4.13",
81
81
  "prettier": "3.5.3",
82
- "ts-jest": "29.2.6",
82
+ "ts-jest": "29.3.1",
83
83
  "ts-node": "10.9.2",
84
- "typescript": "5.8.2"
84
+ "typescript": "5.8.3"
85
85
  }
86
86
  }
@@ -57,6 +57,14 @@ const VISITOR: Visitor<unknown, Dictionary<unknown>> = {
57
57
  return Symbol;
58
58
  case 'Models':
59
59
  return Models;
60
+ case 'Object':
61
+ return Object;
62
+ case 'Array':
63
+ return Array;
64
+ case 'Boolean':
65
+ return Boolean;
66
+ case 'Number':
67
+ return Number;
60
68
  }
61
69
  const definitionNodes = node.getDefinitionNodes();
62
70
  if (!definitionNodes.length) {
@@ -101,6 +109,18 @@ const VISITOR: Visitor<unknown, Dictionary<unknown>> = {
101
109
  case 'toLowerCase':
102
110
  return target[name].bind(target);
103
111
  }
112
+ } else if (typeof target === 'function') {
113
+ const name = node.getName();
114
+ if (target === Object) {
115
+ switch (name) {
116
+ case 'keys':
117
+ case 'values':
118
+ case 'entries':
119
+ case 'assign':
120
+ case 'hasOwnProperty':
121
+ return target[name].bind(target);
122
+ }
123
+ }
104
124
  }
105
125
  throw new Error(`Cannot handle method ${node.getName()} on type ${typeof target}`);
106
126
  }
@@ -11,4 +11,4 @@ export type MutationHook<DateType extends AnyDateType = AnyDateType> = (
11
11
  when: 'before' | 'after',
12
12
  data: { prev: Entity; input: Entity; normalizedInput: Entity; next: Entity },
13
13
  ctx: Context<DateType>,
14
- ) => Promise<void>;
14
+ ) => Promise<void> | void;