typeorm-hasura 0.0.21 → 0.0.23

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const typeorm_1 = require("typeorm");
4
+ const databaseUrl_1 = require("./databaseUrl");
5
+ describe('mappers', () => {
6
+ describe('databaseUrl', () => {
7
+ it('should return postgres for postgres', () => {
8
+ const dataSource = new typeorm_1.DataSource({
9
+ type: 'postgres',
10
+ host: 'localhost',
11
+ port: 5432,
12
+ username: 'test-user',
13
+ password: 'test-password',
14
+ database: 'test-database',
15
+ });
16
+ expect((0, databaseUrl_1.getDatabaseUrl)({
17
+ name: 'default',
18
+ dataSource
19
+ })).toEqual('postgres://test-user:test-password@localhost:5432/test-database');
20
+ });
21
+ it('should throw for unsupported type', () => {
22
+ const dataSource = new typeorm_1.DataSource({
23
+ type: 'sqljs',
24
+ driver: {}
25
+ });
26
+ expect(() => (0, databaseUrl_1.getDatabaseUrl)({
27
+ name: 'default',
28
+ dataSource
29
+ })).toThrow();
30
+ });
31
+ });
32
+ });
33
+ //# sourceMappingURL=databaseUrl.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"databaseUrl.spec.js","sourceRoot":"","sources":["../../../src/mappers/databaseUrl.spec.ts"],"names":[],"mappings":";;AACA,qCAAqC;AACrC,+CAA+C;AAE/C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;YAC3C,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC;gBAC9B,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,IAAI;gBACV,QAAQ,EAAE,WAAW;gBACrB,QAAQ,EAAE,eAAe;gBACzB,QAAQ,EAAE,eAAe;aAC5B,CAAC,CAAC;YACH,MAAM,CAAC,IAAA,4BAAc,EAAC;gBAClB,IAAI,EAAE,SAAS;gBACf,UAAU;aACb,CAAC,CAAC,CAAC,OAAO,CAAC,iEAAiE,CAAC,CAAC;QACnF,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YACzC,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC;gBAC9B,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,EAAE;aACb,CAAC,CAAC;YACH,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4BAAc,EAAC;gBACxB,IAAI,EAAE,SAAS;gBACf,UAAU;aACb,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_tag_1 = require("graphql-tag");
4
+ const graphql_1 = require("./graphql");
5
+ describe("convert graphql document to hasura defs", () => {
6
+ it("Base case", () => expect((0, graphql_1.getGraphQLDefinitions)((0, graphql_tag_1.default) `
7
+ type Query {
8
+ currencyConverter(CurrencyInfo: ConvertCurrencyInputParams!): ConvertedCurrency
9
+ }
10
+
11
+ input ConvertCurrencyInputParams {
12
+ from: String
13
+ to: String
14
+ amt: Int
15
+ }
16
+
17
+ type ConvertedCurrency {
18
+ date: String
19
+ info: ConvertedCurrencyInfo
20
+ query: ConvertedCurrencyQuery
21
+ result: Float
22
+ success: Boolean
23
+ }
24
+
25
+ type ConvertedCurrencyInfo {
26
+ rate: Float
27
+ }
28
+
29
+ type ConvertedCurrencyQuery {
30
+ amount: Int
31
+ from: String
32
+ to: String
33
+ }
34
+ `)).toEqual({
35
+ baseActions: [
36
+ {
37
+ name: "currencyConverter",
38
+ definition: {
39
+ "type": "query",
40
+ output_type: "ConvertedCurrency",
41
+ "arguments": [
42
+ {
43
+ "name": "CurrencyInfo",
44
+ "type": "ConvertCurrencyInputParams!"
45
+ }
46
+ ],
47
+ }
48
+ }
49
+ ],
50
+ "custom_types": {
51
+ "input_objects": [
52
+ {
53
+ "name": "ConvertCurrencyInputParams",
54
+ "fields": [
55
+ {
56
+ "name": "from",
57
+ "type": "String"
58
+ },
59
+ {
60
+ "name": "to",
61
+ "type": "String"
62
+ },
63
+ {
64
+ "name": "amt",
65
+ "type": "Int"
66
+ }
67
+ ]
68
+ }
69
+ ],
70
+ "objects": [
71
+ {
72
+ "name": "ConvertedCurrency",
73
+ "fields": [
74
+ {
75
+ "name": "date",
76
+ "type": "String"
77
+ },
78
+ {
79
+ "name": "info",
80
+ "type": "ConvertedCurrencyInfo"
81
+ },
82
+ {
83
+ "name": "query",
84
+ "type": "ConvertedCurrencyQuery"
85
+ },
86
+ {
87
+ "name": "result",
88
+ "type": "Float"
89
+ },
90
+ {
91
+ "name": "success",
92
+ "type": "Boolean"
93
+ }
94
+ ]
95
+ },
96
+ {
97
+ "name": "ConvertedCurrencyInfo",
98
+ "fields": [
99
+ {
100
+ "name": "rate",
101
+ "type": "Float"
102
+ }
103
+ ]
104
+ },
105
+ {
106
+ "name": "ConvertedCurrencyQuery",
107
+ "fields": [
108
+ {
109
+ "name": "amount",
110
+ "type": "Int"
111
+ },
112
+ {
113
+ "name": "from",
114
+ "type": "String"
115
+ },
116
+ {
117
+ "name": "to",
118
+ "type": "String"
119
+ }
120
+ ]
121
+ },
122
+ ],
123
+ "scalars": []
124
+ }
125
+ }));
126
+ });
127
+ //# sourceMappingURL=graphql.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.spec.js","sourceRoot":"","sources":["../../../src/mappers/graphql.spec.ts"],"names":[],"mappings":";;AAAA,6CAA6B;AAC7B,uCAAiD;AAEjD,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACrD,EAAE,CAAC,WAAW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AwB;oBAChC,QAAQ,EAAE;wBACN;4BACI,MAAM,EAAE,QAAQ;4BAChB,MAAM,EAAE,KAAK;yBAChB;wBACD;4BACI,MAAM,EAAE,MAAM;4BACd,MAAM,EAAE,QAAQ;yBACnB;wBACD;4BACI,MAAM,EAAE,IAAI;4BACZ,MAAM,EAAE,QAAQ;yBACnB;qBACJ;iBACJ;aACJ;YACD,SAAS,EAAE,EAAE;SAChB;KACJ,CAAC,CAAC,CAAA;AACP,CAAC,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const hasuraKind_1 = require("./hasuraKind");
4
+ describe('mappers', () => {
5
+ describe('hasuraKind', () => {
6
+ it('should return postgres for postgres', () => {
7
+ expect((0, hasuraKind_1.getHasuraKind)('postgres')).toEqual('postgres');
8
+ });
9
+ it('should throw for unsupported type', () => {
10
+ expect(() => (0, hasuraKind_1.getHasuraKind)('mysql')).toThrow();
11
+ });
12
+ });
13
+ });
14
+ //# sourceMappingURL=hasuraKind.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasuraKind.spec.js","sourceRoot":"","sources":["../../../src/mappers/hasuraKind.spec.ts"],"names":[],"mappings":";;AAAA,6CAA6C;AAE7C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QACxB,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;YAC3C,MAAM,CAAC,IAAA,0BAAa,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YACzC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,0BAAa,EAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACnD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const permissions_1 = require("./permissions");
4
+ const dataSourceOptions = {};
5
+ const table = {
6
+ columns: [
7
+ { databaseName: "id", type: 'uuid' },
8
+ { databaseName: "name", type: 'text' },
9
+ { databaseName: "orgId", type: 'uuid' },
10
+ { databaseName: "testJsonB", type: 'jsonb' }
11
+ ],
12
+ relations: [
13
+ {
14
+ propertyName: "org",
15
+ inverseEntityMetadata: {
16
+ columns: [
17
+ { databaseName: "id", type: 'uuid' },
18
+ { databaseName: "name", type: 'text' },
19
+ ],
20
+ relations: [{}]
21
+ }
22
+ },
23
+ {
24
+ propertyName: "products",
25
+ inverseEntityMetadata: {
26
+ columns: [
27
+ { databaseName: "id", type: 'uuid' },
28
+ { databaseName: "name", type: 'text' },
29
+ { databaseName: "orgId", type: 'uuid' },
30
+ { databaseName: "userId", type: 'uuid' },
31
+ ],
32
+ relations: [{}]
33
+ }
34
+ }
35
+ ]
36
+ };
37
+ let TestColumns = [
38
+ {
39
+ object: 1,
40
+ propertyName: "id",
41
+ options: {
42
+ permissions: {
43
+ user: ["select", "update"]
44
+ }
45
+ }
46
+ }
47
+ ];
48
+ const cases = [
49
+ {
50
+ input: {
51
+ permissions: {
52
+ user: {
53
+ where: {
54
+ id: "1"
55
+ },
56
+ select: true,
57
+ }
58
+ }
59
+ },
60
+ output: {
61
+ insert_permissions: [],
62
+ select_permissions: [{
63
+ role: "user",
64
+ permission: {
65
+ allow_aggregations: undefined,
66
+ columns: ["id"],
67
+ filter: {
68
+ id: { _eq: "1" }
69
+ },
70
+ limit: undefined
71
+ }
72
+ }],
73
+ update_permissions: [],
74
+ delete_permissions: [],
75
+ }
76
+ },
77
+ {
78
+ input: {
79
+ permissions: {
80
+ user: {
81
+ where: {
82
+ id: "1"
83
+ },
84
+ select: true,
85
+ update: true,
86
+ }
87
+ }
88
+ },
89
+ output: {
90
+ insert_permissions: [],
91
+ select_permissions: [{
92
+ role: "user",
93
+ permission: {
94
+ allow_aggregations: undefined,
95
+ columns: ["id"],
96
+ filter: {
97
+ id: { _eq: "1" }
98
+ },
99
+ limit: undefined
100
+ }
101
+ }],
102
+ update_permissions: [{
103
+ role: "user",
104
+ permission: {
105
+ check: {},
106
+ columns: ["id"],
107
+ filter: {
108
+ id: { _eq: "1" }
109
+ },
110
+ set: undefined
111
+ }
112
+ }],
113
+ delete_permissions: [],
114
+ }
115
+ },
116
+ {
117
+ input: {
118
+ permissions: {
119
+ user: {
120
+ where: {
121
+ id: "1"
122
+ },
123
+ select: true,
124
+ update: {
125
+ where: {
126
+ products: {
127
+ id: "1"
128
+ }
129
+ },
130
+ },
131
+ }
132
+ }
133
+ },
134
+ output: {
135
+ insert_permissions: [],
136
+ select_permissions: [{
137
+ role: "user",
138
+ permission: {
139
+ allow_aggregations: undefined,
140
+ columns: ["id"],
141
+ filter: {
142
+ id: { _eq: "1" }
143
+ },
144
+ limit: undefined
145
+ }
146
+ }],
147
+ update_permissions: [{
148
+ role: "user",
149
+ permission: {
150
+ check: {},
151
+ columns: ["id"],
152
+ filter: {
153
+ _and: [
154
+ { id: { _eq: "1" } },
155
+ {
156
+ products: {
157
+ id: { _eq: "1" }
158
+ }
159
+ }
160
+ ]
161
+ },
162
+ set: undefined
163
+ }
164
+ }],
165
+ delete_permissions: [],
166
+ }
167
+ }
168
+ ];
169
+ describe("convert whereTypeorm to hasuraObj", () => {
170
+ cases.forEach(({ input, output }) => it("input to Equal output", () => expect((0, permissions_1.generatePermissions)(dataSourceOptions, table, { entityOptions: input, columnMetadata: TestColumns }))
171
+ .toEqual(output)));
172
+ });
173
+ //# sourceMappingURL=permissions.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.spec.js","sourceRoot":"","sources":["../../../src/mappers/permissions.spec.ts"],"names":[],"mappings":";;AAEA,+CAAqE;AAQrE,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AAc,EAAE,WAAW,EAAE,CAAC,CAAC;SACvG,OAAO,CAAC,MAAM,CAAC,CAAC,CAC5B,CAAA;AACL,CAAC,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const typeorm_1 = require("typeorm");
4
+ const whereClause_1 = require("./whereClause");
5
+ const table = {
6
+ columns: [
7
+ { databaseName: "id", type: 'uuid' },
8
+ { databaseName: "name", type: 'text' },
9
+ { databaseName: "orgId", type: 'uuid' },
10
+ { databaseName: "testJsonB", type: 'jsonb' }
11
+ ],
12
+ relations: [
13
+ {
14
+ propertyName: "org",
15
+ inverseEntityMetadata: {
16
+ columns: [
17
+ { databaseName: "id", type: 'uuid' },
18
+ { databaseName: "name", type: 'text' },
19
+ ],
20
+ relations: [{}]
21
+ }
22
+ },
23
+ {
24
+ propertyName: "products",
25
+ inverseEntityMetadata: {
26
+ columns: [
27
+ { databaseName: "id", type: 'uuid' },
28
+ { databaseName: "name", type: 'text' },
29
+ { databaseName: "orgId", type: 'uuid' },
30
+ { databaseName: "userId", type: 'uuid' },
31
+ ],
32
+ relations: [{}]
33
+ }
34
+ }
35
+ ]
36
+ };
37
+ const cases = [
38
+ {
39
+ input: {
40
+ id: "1",
41
+ },
42
+ output: {
43
+ id: { _eq: "1" }
44
+ }
45
+ },
46
+ {
47
+ input: {
48
+ id: "1",
49
+ name: "test"
50
+ },
51
+ output: {
52
+ _and: [
53
+ { id: { _eq: "1" } },
54
+ { name: { _eq: "test" } }
55
+ ]
56
+ }
57
+ },
58
+ {
59
+ input: [
60
+ { id: "1", name: "test" },
61
+ { id: "2", name: "test" }
62
+ ],
63
+ output: {
64
+ _or: [
65
+ { _and: [{ id: { _eq: "1" } }, { name: { _eq: "test" } }] },
66
+ { _and: [{ id: { _eq: "2" } }, { name: { _eq: "test" } }] }
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ input: {
72
+ id: (0, typeorm_1.Not)("1")
73
+ },
74
+ output: {
75
+ id: { _neq: "1" }
76
+ }
77
+ },
78
+ {
79
+ input: [
80
+ { id: (0, typeorm_1.Not)("1"), name: "test" },
81
+ { id: "2", name: (0, typeorm_1.In)(["test"]) }
82
+ ],
83
+ output: {
84
+ _or: [
85
+ { _and: [{ id: { _neq: "1" } }, { name: { _eq: "test" } }] },
86
+ { _and: [{ id: { _eq: "2" } }, { name: { _in: ["test"] } }] }
87
+ ],
88
+ },
89
+ },
90
+ {
91
+ input: {
92
+ products: {
93
+ id: "1"
94
+ }
95
+ },
96
+ output: {
97
+ products: {
98
+ id: { _eq: "1" },
99
+ }
100
+ }
101
+ },
102
+ {
103
+ input: {
104
+ products: [
105
+ {
106
+ id: "1"
107
+ },
108
+ {
109
+ id: "2"
110
+ }
111
+ ]
112
+ },
113
+ output: {
114
+ products: {
115
+ _or: [
116
+ { id: { _eq: "1" } },
117
+ { id: { _eq: "2" } }
118
+ ]
119
+ }
120
+ }
121
+ },
122
+ {
123
+ input: {
124
+ products: {
125
+ id: (0, typeorm_1.Not)((0, typeorm_1.IsNull)())
126
+ }
127
+ },
128
+ output: {
129
+ products: {
130
+ id: { _is_null: false },
131
+ }
132
+ }
133
+ },
134
+ {
135
+ input: {
136
+ products: {
137
+ id: (0, typeorm_1.Not)("test")
138
+ }
139
+ },
140
+ output: {
141
+ products: {
142
+ id: { _neq: "test" },
143
+ }
144
+ }
145
+ },
146
+ {
147
+ input: {
148
+ products: {
149
+ id: (0, typeorm_1.IsNull)()
150
+ }
151
+ },
152
+ output: {
153
+ products: {
154
+ id: { _is_null: true },
155
+ }
156
+ }
157
+ },
158
+ {
159
+ input: {
160
+ testJsonB: {
161
+ name: "test"
162
+ }
163
+ },
164
+ output: {
165
+ testJsonB: {
166
+ _contains: {
167
+ name: "test"
168
+ }
169
+ }
170
+ }
171
+ },
172
+ {
173
+ input: {
174
+ testJsonB: (0, typeorm_1.Not)({
175
+ name: "test"
176
+ })
177
+ },
178
+ output: {
179
+ _not: {
180
+ testJsonB: {
181
+ _contains: {
182
+ name: "test"
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ ];
189
+ describe("convert whereTypeorm to hasuraObj", () => {
190
+ cases.forEach(({ input, output }) => it("input to Equal output", () => expect((0, whereClause_1.convertWhereClause)(table, input)).toEqual(output)));
191
+ });
192
+ //# sourceMappingURL=whereClause.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whereClause.spec.js","sourceRoot":"","sources":["../../../src/mappers/whereClause.spec.ts"],"names":[],"mappings":";;AAAA,qCAAqE;AAErE,+CAAkD;AAQlD,MAAM,KAAK,GAAG;IACV,OAAO,EAAE;QACL,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;QACpC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;QACtC,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;QACvC,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE;KAC/C;IACD,SAAS,EAAE;QACP;YACI,YAAY,EAAE,KAAK;YACnB,qBAAqB,EAAE;gBACnB,OAAO,EAAE;oBACL,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;oBACpC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;iBACzC;gBACD,SAAS,EAAE,CAAC,EAAE,CAAC;aAClB;SACJ;QACD;YACI,YAAY,EAAE,UAAU;YACxB,qBAAqB,EAAE;gBACnB,OAAO,EAAE;oBACL,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;oBACpC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;oBACtC,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;oBACvC,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE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  "keywords": [
6
6
  "hasura",
@@ -24,11 +24,10 @@
24
24
  "url": "https://github.com/utyfua/typeorm-hasura/issues"
25
25
  },
26
26
  "scripts": {
27
- "prepublish": "run-s build:tsc",
28
- "clean": "rimraf -g dist/*",
29
- "prebuild": "run-s clean",
30
- "build": "run-s build:tsc",
31
- "build:tsc": "tsc --module commonjs",
27
+ "prepublish": "run-s build",
28
+ "prebuild": "rimraf -g dist/*",
29
+ "build": "tsc --module commonjs",
30
+ "pretest": "run-s build",
32
31
  "test": "jest",
33
32
  "test:watch": "jest --watch",
34
33
  "play:gen": "npx env-cmd --silent npx typeorm-ts-node-commonjs migration:generate ./dev-playground/migration/next -d ./dev-playground/data-source.ts",
@@ -47,17 +46,17 @@
47
46
  "graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
48
47
  "graphql-tag": "^2.0.0",
49
48
  "hasura-metadata-types": "^2.22.1",
50
- "lodash.snakecase": "^4.1.1"
49
+ "lodash-es": "^4.18.1"
51
50
  },
52
51
  "peerDependencies": {
53
52
  "graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
54
53
  "graphql-tag": "^2.0.0",
55
54
  "hasura-metadata-types": "^2.22.1",
56
- "typeorm": "^0.3.0 || ^1.0.0 || master"
55
+ "typeorm": "^0.3.0 || ^1.0.0 || >=1.0.0-nightly.0 <1.0.1"
57
56
  },
58
57
  "devDependencies": {
59
58
  "@types/jest": "^29.5.0",
60
- "@types/lodash.snakecase": "^4.1.7",
59
+ "@types/lodash-es": "^4.17.12",
61
60
  "@types/node": "^18.14.0",
62
61
  "env-cmd": "^10.1.0",
63
62
  "jest": "^29.5.0",
@@ -67,6 +66,7 @@
67
66
  "rimraf": "^6.0.1",
68
67
  "ts-jest": "^29.0.5",
69
68
  "ts-node": "^10.9.1",
70
- "typeorm": "^0.3.14"
69
+ "typeorm": "^0.3.14",
70
+ "typescript": "^5.9.3"
71
71
  }
72
72
  }
package/readme.md CHANGED
@@ -16,7 +16,7 @@ making it easier to manage complex database schemas and permissions when using H
16
16
  > The library does not support ManyToMany relationships.
17
17
 
18
18
  > [!NOTE]
19
- > The library was tested with Hasura v2 and TypeORM v0.3/v1-nightly with PostgreSQL only.
19
+ > The library was tested with Hasura v2 and TypeORM v0.3/v1-nightly.20260426 with PostgreSQL only.
20
20
 
21
21
  ## Installation
22
22
 
@@ -1,5 +1,4 @@
1
- import axios, { AxiosError } from "axios";
2
- import { DocumentNode } from "graphql";
1
+ import type { DocumentNode } from "graphql";
3
2
  import type * as Hasura from "hasura-metadata-types";
4
3
  import { ActionBuildResult, DataSourceOptions, InheritedRoles } from "../types";
5
4
  import { generateSource } from "../mappers";
@@ -143,6 +142,7 @@ export class MetadataBuilder {
143
142
  */
144
143
  async applyMetadata({ hasuraUrl, adminSecret }: { hasuraUrl: string, adminSecret: string }) {
145
144
  const { metadata } = await this.getMetadata();
145
+ const { default: axios, AxiosError } = await import("axios");
146
146
  try {
147
147
  const { data } = await axios.post(`${hasuraUrl}/v1/metadata`, {
148
148
  type: "replace_metadata",
@@ -1,32 +1,31 @@
1
1
 
2
+ import { DataSource } from "typeorm";
2
3
  import { getDatabaseUrl } from "./databaseUrl";
3
4
 
4
5
  describe('mappers', () => {
5
6
  describe('databaseUrl', () => {
6
7
  it('should return postgres for postgres', () => {
8
+ const dataSource = new DataSource({
9
+ type: 'postgres',
10
+ host: 'localhost',
11
+ port: 5432,
12
+ username: 'test-user',
13
+ password: 'test-password',
14
+ database: 'test-database',
15
+ });
7
16
  expect(getDatabaseUrl({
8
- dataSource: {
9
- name: 'default',
10
- // @ts-ignore
11
- type: 'postgres',
12
- options: {
13
- type: 'postgres',
14
- host: 'localhost',
15
- port: 5432,
16
- username: 'test-user',
17
- password: 'test-password',
18
- database: 'test-database',
19
- }
20
- }
17
+ name: 'default',
18
+ dataSource
21
19
  })).toEqual('postgres://test-user:test-password@localhost:5432/test-database');
22
20
  });
23
21
  it('should throw for unsupported type', () => {
22
+ const dataSource = new DataSource({
23
+ type: 'sqljs',
24
+ driver: {}
25
+ });
24
26
  expect(() => getDatabaseUrl({
25
- dataSource: {
26
- name: 'default',
27
- // @ts-ignore
28
- type: 'mysql',
29
- }
27
+ name: 'default',
28
+ dataSource
30
29
  })).toThrow();
31
30
  });
32
31
  });
@@ -1,4 +1,4 @@
1
- import { DocumentNode, FieldDefinitionNode, InputValueDefinitionNode, TypeNode } from "graphql";
1
+ import type { DocumentNode, FieldDefinitionNode, InputValueDefinitionNode, TypeNode } from "graphql";
2
2
  import type * as Hasura from "hasura-metadata-types";
3
3
  import { GraphQlMetadataForAction } from "../types";
4
4
 
@@ -1,4 +1,4 @@
1
- import { FindOperator } from "typeorm"
1
+ import type { FindOperator } from "typeorm"
2
2
  import { ExclusiveParameters, Operators } from "../types"
3
3
 
4
4
  export function operatorMappers(operator: FindOperator<any>): ExclusiveParameters {
@@ -1,4 +1,4 @@
1
- import * as TypeORM from "typeorm";
1
+ import type { EntityMetadata } from "typeorm";
2
2
  import type * as Hasura from "hasura-metadata-types";
3
3
  import { ColumnMetadata, DataSourceOptions, EntityInternalStorageWorkspace, UserActionType } from "../types";
4
4
  import { convertWhereClause } from "./whereClause"
@@ -9,7 +9,7 @@ export type PermissionResult = Required<Pick<
9
9
 
10
10
  export function generatePermissions<Entity extends Object = Object>(
11
11
  dataSourceOptions: DataSourceOptions,
12
- table: TypeORM.EntityMetadata,
12
+ table: EntityMetadata,
13
13
  { entityOptions, columnMetadata }: EntityInternalStorageWorkspace<Entity>,
14
14
  ): PermissionResult {
15
15
 
@@ -1,4 +1,4 @@
1
- import * as TypeORM from "typeorm";
1
+ import type { EntityMetadata } from "typeorm";
2
2
  import type * as Hasura from "hasura-metadata-types";
3
3
 
4
4
  type RelationshipKind = 'object_relationships' | 'array_relationships'
@@ -7,7 +7,7 @@ type Relationship =
7
7
  | Hasura.SameTableObjectRelationship
8
8
  | Hasura.ManualObjectRelationship
9
9
 
10
- export function generateRelationship(relation: TypeORM.EntityMetadata['relations'][number]): Relationship {
10
+ export function generateRelationship(relation: EntityMetadata['relations'][number]): Relationship {
11
11
  const owningRelation = relation.isOwning ?
12
12
  relation : relation.inverseRelation;
13
13
 
@@ -62,7 +62,7 @@ export function generateRelationship(relation: TypeORM.EntityMetadata['relations
62
62
  throw new Error("Relation tableType is not available")
63
63
  }
64
64
 
65
- export function generateRelationships(relations: TypeORM.EntityMetadata['relations']):
65
+ export function generateRelationships(relations: EntityMetadata['relations']):
66
66
  Pick<Hasura.MetadataTable, RelationshipKind> {
67
67
  const result: Required<Pick<Hasura.MetadataTable, RelationshipKind>> = {
68
68
  object_relationships: [],
@@ -1,5 +1,5 @@
1
1
  import type * as Hasura from "hasura-metadata-types";
2
- import * as TypeORM from "typeorm";
2
+ import type { EntityMetadata } from "typeorm";
3
3
  import { generateRelationships } from "./relationships";
4
4
  import { generateTableConfiguration } from "./tableConfiguration";
5
5
  import { DataSourceOptions } from "../types";
@@ -8,7 +8,7 @@ import { internalStorage } from "../internalStorage";
8
8
 
9
9
  export function generateTable<Entity extends Object>(
10
10
  dataSourceOptions: DataSourceOptions,
11
- table: TypeORM.EntityMetadata
11
+ table: EntityMetadata
12
12
  ): Hasura.MetadataTable {
13
13
  const entityWorkspace = internalStorage.getEntityWorkspace<Entity>(table.target);
14
14
 
@@ -1,10 +1,10 @@
1
- import * as TypeORM from "typeorm";
1
+ import { EntityMetadata } from "typeorm";
2
2
  import type * as Hasura from "hasura-metadata-types";
3
3
  import { EntityInternalStorageWorkspace, EntityRootField } from "../types";
4
- import snakeCase from 'lodash.snakecase'
4
+ import snakeCase from 'lodash-es/snakeCase'
5
5
 
6
6
  export function generateTableConfiguration<Entity extends Object>(
7
- table: TypeORM.EntityMetadata,
7
+ table: EntityMetadata,
8
8
  { entityOptions, columnMetadata }: EntityInternalStorageWorkspace<Entity>,
9
9
  ): Hasura.MetadataTableConfig {
10
10
 
@@ -1,9 +1,10 @@
1
- import * as TypeORM from "typeorm";
1
+ import { InstanceChecker } from "typeorm";
2
+ import type { EntityMetadata, FindOptionsWhere } from "typeorm";
2
3
  import { Where, Filter, FilterAlt, ExclusiveParameters } from "../types";
3
4
  import { operatorMappers } from "./operators";
4
5
 
5
6
  export function convertWhereClause<Entity extends Object>(
6
- table: TypeORM.EntityMetadata,
7
+ table: EntityMetadata,
7
8
  ...wheres: (Where<Entity> | undefined)[]
8
9
  ): Filter<Entity> {
9
10
  wheres = wheres.filter(Boolean)
@@ -20,8 +21,8 @@ export function convertWhereClause<Entity extends Object>(
20
21
  }
21
22
 
22
23
  function parseParameters<Entity extends Object>(
23
- table: TypeORM.EntityMetadata,
24
- where: TypeORM.FindOptionsWhere<Entity> | TypeORM.FindOptionsWhere<Entity>[]
24
+ table: EntityMetadata,
25
+ where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]
25
26
  ): Filter<Entity> {
26
27
  if (Array.isArray(where)) {
27
28
  return { _or: where.map(i => parseParameters(table, i)) }
@@ -35,7 +36,7 @@ function parseParameters<Entity extends Object>(
35
36
 
36
37
  const isJsonb = column?.type === "jsonb" && typeof parameterValue == "object"
37
38
 
38
- if (TypeORM.InstanceChecker.isFindOperator(parameterValue) && !isJsonb) {
39
+ if (InstanceChecker.isFindOperator(parameterValue) && !isJsonb) {
39
40
  conditions.push({ [key]: operatorMappers(parameterValue) })
40
41
  } else if (
41
42
  typeof parameterValue === "string" ||
@@ -45,8 +46,8 @@ function parseParameters<Entity extends Object>(
45
46
  conditions.push({ [key]: { "_eq": parameterValue } })
46
47
  } else if (relation && parameterValue) {
47
48
  // this is a relation so we can parse it recursively
48
- conditions.push({ [key]: parseParameters(relation.inverseEntityMetadata, parameterValue as TypeORM.FindOptionsWhere<Entity>) })
49
- } else if (TypeORM.InstanceChecker.isFindOperator(parameterValue) && parameterValue.type == "not" && isJsonb) {
49
+ conditions.push({ [key]: parseParameters(relation.inverseEntityMetadata, parameterValue as FindOptionsWhere<Entity>) })
50
+ } else if (InstanceChecker.isFindOperator(parameterValue) && parameterValue.type == "not" && isJsonb) {
50
51
  conditions.push({ _not: { [key]: { "_contains": parameterValue.value } } })
51
52
  } else if (isJsonb) {
52
53
  conditions.push({ [key]: { "_contains": parameterValue } })
@@ -1,4 +1,4 @@
1
- import { DocumentNode } from "graphql"
1
+ import type { DocumentNode } from "graphql"
2
2
  import type * as Hasura from "hasura-metadata-types";
3
3
  import { UserRoleName } from "./base";
4
4
 
@@ -1,9 +1,9 @@
1
- import * as TypeORM from "typeorm";
1
+ import type { DataSource } from "typeorm";
2
2
  import type * as Hasura from "hasura-metadata-types";
3
3
 
4
4
  export interface DataSourceOptions {
5
5
  name: string;
6
- dataSource: TypeORM.DataSource;
6
+ dataSource: DataSource;
7
7
  customizationNative?: Hasura.SourceCustomization;
8
8
 
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { FindOptionsWhere, FindOperatorType, BaseEntity } from "typeorm";
1
+ import type { FindOptionsWhere, FindOperatorType, BaseEntity } from "typeorm";
2
2
 
3
3
  export type Where<Entity> = FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>
4
4