@subsquid/openreader 4.6.0 → 5.0.0-beta.b87ffb
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/lib/context.d.ts +2 -2
- package/lib/context.d.ts.map +1 -1
- package/lib/db.d.ts +3 -3
- package/lib/db.d.ts.map +1 -1
- package/lib/db.js +2 -2
- package/lib/db.js.map +1 -1
- package/lib/dialect/common.d.ts +19 -0
- package/lib/dialect/common.d.ts.map +1 -0
- package/lib/dialect/common.js +42 -0
- package/lib/dialect/common.js.map +1 -0
- package/lib/dialect/index.d.ts +6 -0
- package/lib/dialect/index.d.ts.map +1 -0
- package/lib/dialect/index.js +49 -0
- package/lib/dialect/index.js.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/orderBy.d.ts +2 -3
- package/lib/dialect/opencrud/orderBy.d.ts.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/orderBy.js +4 -21
- package/lib/dialect/opencrud/orderBy.js.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/schema.d.ts +2 -6
- package/lib/dialect/opencrud/schema.d.ts.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/schema.js +21 -34
- package/lib/dialect/opencrud/schema.js.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/tree.d.ts +3 -3
- package/lib/dialect/opencrud/tree.d.ts.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/tree.js +3 -3
- package/lib/dialect/opencrud/tree.js.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/where.d.ts +1 -1
- package/lib/dialect/opencrud/where.d.ts.map +1 -0
- package/lib/{opencrud → dialect/opencrud}/where.js +4 -13
- package/lib/dialect/opencrud/where.js.map +1 -0
- package/lib/dialect/thegraph/locale.d.ts +2 -0
- package/lib/dialect/thegraph/locale.d.ts.map +1 -0
- package/lib/dialect/thegraph/locale.js +49 -0
- package/lib/dialect/thegraph/locale.js.map +1 -0
- package/lib/dialect/thegraph/orderBy.d.ts +11 -0
- package/lib/dialect/thegraph/orderBy.d.ts.map +1 -0
- package/lib/dialect/thegraph/orderBy.js +71 -0
- package/lib/dialect/thegraph/orderBy.js.map +1 -0
- package/lib/dialect/thegraph/schema.d.ts +25 -0
- package/lib/dialect/thegraph/schema.d.ts.map +1 -0
- package/lib/dialect/thegraph/schema.js +429 -0
- package/lib/dialect/thegraph/schema.js.map +1 -0
- package/lib/dialect/thegraph/tree.d.ts +10 -0
- package/lib/dialect/thegraph/tree.d.ts.map +1 -0
- package/lib/dialect/thegraph/tree.js +148 -0
- package/lib/dialect/thegraph/tree.js.map +1 -0
- package/lib/dialect/thegraph/where.d.ts +9 -0
- package/lib/dialect/thegraph/where.d.ts.map +1 -0
- package/lib/dialect/thegraph/where.js +188 -0
- package/lib/dialect/thegraph/where.js.map +1 -0
- package/lib/ir/args.d.ts +1 -1
- package/lib/ir/args.d.ts.map +1 -1
- package/lib/main.js +1 -1
- package/lib/main.js.map +1 -1
- package/lib/model.d.ts +2 -0
- package/lib/model.d.ts.map +1 -1
- package/lib/model.schema.d.ts.map +1 -1
- package/lib/model.schema.js +31 -2
- package/lib/model.schema.js.map +1 -1
- package/lib/server.d.ts +3 -1
- package/lib/server.d.ts.map +1 -1
- package/lib/server.js +7 -6
- package/lib/server.js.map +1 -1
- package/lib/sql/cursor.d.ts +2 -2
- package/lib/sql/cursor.d.ts.map +1 -1
- package/lib/sql/cursor.js +2 -2
- package/lib/sql/cursor.js.map +1 -1
- package/lib/sql/printer.d.ts +3 -3
- package/lib/sql/printer.d.ts.map +1 -1
- package/lib/sql/printer.js +17 -15
- package/lib/sql/printer.js.map +1 -1
- package/lib/sql/query.d.ts +5 -5
- package/lib/sql/query.d.ts.map +1 -1
- package/lib/sql/query.js.map +1 -1
- package/lib/sql/util.d.ts +2 -2
- package/lib/sql/util.d.ts.map +1 -1
- package/lib/sql/util.js.map +1 -1
- package/lib/test/basic.test.js +471 -229
- package/lib/test/basic.test.js.map +1 -1
- package/lib/test/isNull.test.js +87 -36
- package/lib/test/isNull.test.js.map +1 -1
- package/lib/test/limits.test.js +206 -94
- package/lib/test/limits.test.js.map +1 -1
- package/lib/test/lookup.test.js +184 -81
- package/lib/test/lookup.test.js.map +1 -1
- package/lib/test/setup.js +2 -2
- package/lib/test/setup.js.map +1 -1
- package/lib/test/where.test.js +216 -99
- package/lib/test/where.test.js.map +1 -1
- package/package.json +5 -3
- package/src/context.ts +2 -2
- package/src/db.ts +4 -2
- package/src/dialect/common.ts +49 -0
- package/src/dialect/index.ts +20 -0
- package/src/{opencrud → dialect/opencrud}/orderBy.ts +4 -21
- package/src/{opencrud → dialect/opencrud}/schema.ts +30 -55
- package/src/{opencrud → dialect/opencrud}/tree.ts +6 -7
- package/src/{opencrud → dialect/opencrud}/where.ts +4 -16
- package/src/dialect/thegraph/locale.ts +284 -0
- package/src/dialect/thegraph/orderBy.ts +75 -0
- package/src/dialect/thegraph/schema.ts +484 -0
- package/src/dialect/thegraph/tree.ts +162 -0
- package/src/dialect/thegraph/where.ts +184 -0
- package/src/ir/args.ts +2 -0
- package/src/main.ts +3 -3
- package/src/model.schema.ts +37 -4
- package/src/model.ts +2 -0
- package/src/server.ts +21 -19
- package/src/sql/cursor.ts +4 -4
- package/src/sql/printer.ts +22 -18
- package/src/sql/query.ts +5 -5
- package/src/sql/util.ts +2 -2
- package/src/test/basic.test.ts +570 -282
- package/src/test/isNull.test.ts +95 -38
- package/src/test/limits.test.ts +212 -91
- package/src/test/lookup.test.ts +190 -83
- package/src/test/setup.ts +2 -2
- package/src/test/where.test.ts +235 -108
- package/lib/dialect.d.ts +0 -2
- package/lib/dialect.d.ts.map +0 -1
- package/lib/dialect.js +0 -3
- package/lib/dialect.js.map +0 -1
- package/lib/opencrud/orderBy.d.ts.map +0 -1
- package/lib/opencrud/orderBy.js.map +0 -1
- package/lib/opencrud/schema.d.ts.map +0 -1
- package/lib/opencrud/schema.js.map +0 -1
- package/lib/opencrud/tree.d.ts.map +0 -1
- package/lib/opencrud/tree.js.map +0 -1
- package/lib/opencrud/where.d.ts.map +0 -1
- package/lib/opencrud/where.js.map +0 -1
- package/src/dialect.ts +0 -2
package/lib/test/where.test.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dialect_1 = require("../dialect");
|
|
3
4
|
const setup_1 = require("./setup");
|
|
4
5
|
describe('AND, OR on entity filters', function () {
|
|
5
6
|
(0, setup_1.useDatabase)([
|
|
@@ -11,116 +12,232 @@ describe('AND, OR on entity filters', function () {
|
|
|
11
12
|
`insert into item (id, a, b) values ('5', 5, 4)`,
|
|
12
13
|
`insert into item (id, a, b) values ('6', 5, 6)`,
|
|
13
14
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`);
|
|
21
|
-
it('{c, and: {c}}', function () {
|
|
22
|
-
return client.test(`
|
|
23
|
-
query {
|
|
24
|
-
items(where: {a_eq: 1, AND: {b_eq: 1}} orderBy: id_ASC) { id }
|
|
15
|
+
describe('opencrud', function () {
|
|
16
|
+
const client = (0, setup_1.useServer)(`
|
|
17
|
+
type Item @entity {
|
|
18
|
+
id: ID!
|
|
19
|
+
a: Int
|
|
20
|
+
b: Int
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
`);
|
|
23
|
+
it('{c, and: {c}}', function () {
|
|
24
|
+
return client.test(`
|
|
25
|
+
query {
|
|
26
|
+
items(where: {a_eq: 1, AND: {b_eq: 1}} orderBy: id_ASC) { id }
|
|
27
|
+
}
|
|
28
|
+
`, {
|
|
29
|
+
items: [
|
|
30
|
+
{ id: '1' }
|
|
31
|
+
]
|
|
32
|
+
});
|
|
30
33
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
it('{and: {and: {c}, c}}', function () {
|
|
35
|
+
return client.test(`
|
|
36
|
+
query {
|
|
37
|
+
items(where: {AND: {b_eq: 2, AND: {a_eq: 3}}} orderBy: id_ASC) { id }
|
|
38
|
+
}
|
|
39
|
+
`, {
|
|
40
|
+
items: [
|
|
41
|
+
{ id: '3' }
|
|
42
|
+
]
|
|
43
|
+
});
|
|
41
44
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
it('{and: [{c}, {c}]}', function () {
|
|
46
|
+
return client.test(`
|
|
47
|
+
query {
|
|
48
|
+
items(where: {AND: [{a_eq: 2}, {b_eq: 2}]} orderBy: id_ASC) { id }
|
|
49
|
+
}
|
|
50
|
+
`, {
|
|
51
|
+
items: [
|
|
52
|
+
{ id: '2' }
|
|
53
|
+
]
|
|
54
|
+
});
|
|
52
55
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
it('{c, {or: {c}}}', function () {
|
|
57
|
+
return client.test(`
|
|
58
|
+
query {
|
|
59
|
+
items(where: {a_eq: 1, OR: {a_eq: 2}} orderBy: id_ASC) { id }
|
|
60
|
+
}
|
|
61
|
+
`, {
|
|
62
|
+
items: [
|
|
63
|
+
{ id: '1' },
|
|
64
|
+
{ id: '2' }
|
|
65
|
+
]
|
|
66
|
+
});
|
|
64
67
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
it('{or: [{c}, {c}]}', function () {
|
|
69
|
+
return client.test(`
|
|
70
|
+
query {
|
|
71
|
+
items(where: {OR: [{a_eq: 2}, {a_eq: 3}]} orderBy: id_ASC) { id }
|
|
72
|
+
}
|
|
73
|
+
`, {
|
|
74
|
+
items: [
|
|
75
|
+
{ id: '2' },
|
|
76
|
+
{ id: '3' }
|
|
77
|
+
]
|
|
78
|
+
});
|
|
76
79
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
it('{or: {or: {c}, c}}', function () {
|
|
81
|
+
return client.test(`
|
|
82
|
+
query {
|
|
83
|
+
items(where: {OR: {a_eq: 1, OR: {b_eq: 2}}} orderBy: id_ASC) { id }
|
|
84
|
+
}
|
|
85
|
+
`, {
|
|
86
|
+
items: [
|
|
87
|
+
{ id: '1' },
|
|
88
|
+
{ id: '2' },
|
|
89
|
+
{ id: '3' }
|
|
90
|
+
]
|
|
91
|
+
});
|
|
89
92
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
it('{and: [{or: {c}, c}, {or: {c}, c}]}', function () {
|
|
94
|
+
return client.test(`
|
|
95
|
+
query {
|
|
96
|
+
items(where: {AND: [{OR: {a_eq: 5}, a_eq: 4}, {OR: {b_eq: 2}, b_eq: 4}]} orderBy: id_ASC) { id }
|
|
97
|
+
}
|
|
98
|
+
`, {
|
|
99
|
+
items: [
|
|
100
|
+
{ id: '4' },
|
|
101
|
+
{ id: '5' }
|
|
102
|
+
]
|
|
103
|
+
});
|
|
101
104
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
it('{c, and: {c}, or: {c}}', function () {
|
|
106
|
+
return client.test(`
|
|
107
|
+
query {
|
|
108
|
+
items(where: { a_eq: 4, AND: {b_eq: 4}, OR: {b_eq: 6} } orderBy: id_ASC) { id }
|
|
109
|
+
}
|
|
110
|
+
`, {
|
|
111
|
+
items: [
|
|
112
|
+
{ id: '4' },
|
|
113
|
+
{ id: '6' }
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it('handles empty wheres', function () {
|
|
118
|
+
return client.test(`
|
|
119
|
+
query {
|
|
120
|
+
items(where: { a_eq: 4, AND: { OR: {}, AND: {} }, OR: { OR: {AND: {} } } } orderBy: id_ASC) { id }
|
|
121
|
+
}
|
|
122
|
+
`, {
|
|
123
|
+
items: [
|
|
124
|
+
{ id: '4' }
|
|
125
|
+
]
|
|
126
|
+
});
|
|
113
127
|
});
|
|
114
128
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
describe('thegraph', function () {
|
|
130
|
+
const client = (0, setup_1.useServer)(`
|
|
131
|
+
type Item @entity {
|
|
132
|
+
id: ID!
|
|
133
|
+
a: Int
|
|
134
|
+
b: Int
|
|
119
135
|
}
|
|
120
|
-
`, {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
136
|
+
`, { dialect: dialect_1.Dialect.TheGraph });
|
|
137
|
+
it('{c, and: {c}}', function () {
|
|
138
|
+
return client.test(`
|
|
139
|
+
query {
|
|
140
|
+
items(where: {a: 1, and: {b: 1}}, orderBy: id, orderDirection: asc) { id }
|
|
141
|
+
}
|
|
142
|
+
`, {
|
|
143
|
+
items: [
|
|
144
|
+
{ id: '1' }
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
it('{and: {and: {c}, c}}', function () {
|
|
149
|
+
return client.test(`
|
|
150
|
+
query {
|
|
151
|
+
items(where: {and: {b: 2, and: {a: 3}}}, orderBy: id, orderDirection: asc) { id }
|
|
152
|
+
}
|
|
153
|
+
`, {
|
|
154
|
+
items: [
|
|
155
|
+
{ id: '3' }
|
|
156
|
+
]
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it('{and: [{c}, {c}]}', function () {
|
|
160
|
+
return client.test(`
|
|
161
|
+
query {
|
|
162
|
+
items(where: {and: [{a: 2}, {b: 2}]}, orderBy: id, orderDirection: asc) { id }
|
|
163
|
+
}
|
|
164
|
+
`, {
|
|
165
|
+
items: [
|
|
166
|
+
{ id: '2' }
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
it('{c, {or: {c}}}', function () {
|
|
171
|
+
return client.test(`
|
|
172
|
+
query {
|
|
173
|
+
items(where: {a: 1, or: {a: 2}}, orderBy: id, orderDirection: asc) { id }
|
|
174
|
+
}
|
|
175
|
+
`, {
|
|
176
|
+
items: [
|
|
177
|
+
{ id: '1' },
|
|
178
|
+
{ id: '2' }
|
|
179
|
+
]
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
it('{or: [{c}, {c}]}', function () {
|
|
183
|
+
return client.test(`
|
|
184
|
+
query {
|
|
185
|
+
items(where: {or: [{a: 2}, {a: 3}]}, orderBy: id, orderDirection: asc) { id }
|
|
186
|
+
}
|
|
187
|
+
`, {
|
|
188
|
+
items: [
|
|
189
|
+
{ id: '2' },
|
|
190
|
+
{ id: '3' }
|
|
191
|
+
]
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
it('{or: {or: {c}, c}}', function () {
|
|
195
|
+
return client.test(`
|
|
196
|
+
query {
|
|
197
|
+
items(where: {or: {a: 1, or: {b: 2}}}, orderBy: id, orderDirection: asc) { id }
|
|
198
|
+
}
|
|
199
|
+
`, {
|
|
200
|
+
items: [
|
|
201
|
+
{ id: '1' },
|
|
202
|
+
{ id: '2' },
|
|
203
|
+
{ id: '3' }
|
|
204
|
+
]
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
it('{and: [{or: {c}, c}, {or: {c}, c}]}', function () {
|
|
208
|
+
return client.test(`
|
|
209
|
+
query {
|
|
210
|
+
items(where: {and: [{or: {a: 5}, a: 4}, {or: {b: 2}, b: 4}]}, orderBy: id, orderDirection: asc) { id }
|
|
211
|
+
}
|
|
212
|
+
`, {
|
|
213
|
+
items: [
|
|
214
|
+
{ id: '4' },
|
|
215
|
+
{ id: '5' }
|
|
216
|
+
]
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
it('{c, and: {c}, or: {c}}', function () {
|
|
220
|
+
return client.test(`
|
|
221
|
+
query {
|
|
222
|
+
items(where: { a: 4, and: {b: 4}, or: {b: 6} }, orderBy: id, orderDirection: asc) { id }
|
|
223
|
+
}
|
|
224
|
+
`, {
|
|
225
|
+
items: [
|
|
226
|
+
{ id: '4' },
|
|
227
|
+
{ id: '6' }
|
|
228
|
+
]
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
it('handles empty wheres', function () {
|
|
232
|
+
return client.test(`
|
|
233
|
+
query {
|
|
234
|
+
items(where: { a: 4, and: { or: {}, and: {} }, or: { or: {and: {} } } }, orderBy: id, orderDirection: asc) { id }
|
|
235
|
+
}
|
|
236
|
+
`, {
|
|
237
|
+
items: [
|
|
238
|
+
{ id: '4' }
|
|
239
|
+
]
|
|
240
|
+
});
|
|
124
241
|
});
|
|
125
242
|
});
|
|
126
243
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"where.test.js","sourceRoot":"","sources":["../../src/test/where.test.ts"],"names":[],"mappings":";;AAAA,mCAA8C;AAE9C,QAAQ,CAAC,2BAA2B,EAAE;IAClC,IAAA,mBAAW,EAAC;QACR,uDAAuD;QACvD,gDAAgD;QAChD,gDAAgD;QAChD,gDAAgD;QAChD,gDAAgD;QAChD,gDAAgD;QAChD,gDAAgD;KACnD,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,IAAA,iBAAS,EAAC;;;;;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,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,qCAAqC,EAAE;YACtC,OAAO,MAAM,CAAC,IAAI,CAAC;;;;aAIlB,EAAE;gBACC,KAAK,EAAE;oBACH,EAAC,EAAE,EAAE,GAAG,EAAC;oBACT,EAAC,EAAE,EAAE,GAAG,EAAC;iBACZ;aACJ,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,wBAAwB,EAAE;YACzB,OAAO,MAAM,CAAC,IAAI,CAAC;;;;aAIlB,EAAE;gBACC,KAAK,EAAE;oBACH,EAAC,EAAE,EAAE,GAAG,EAAC;oBACT,EAAC,EAAE,EAAE,GAAG,EAAC;iBACZ;aACJ,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,sBAAsB,EAAE;YACvB,OAAO,MAAM,CAAC,IAAI,CAAC;;;;aAIlB,EAAE;gBACC,KAAK,EAAE;oBACH,EAAC,EAAE,EAAE,GAAG,EAAC;iBACZ;aACJ,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subsquid/openreader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.b87ffb",
|
|
4
4
|
"description": "GraphQL server for postgres-compatible databases",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"graphql-parse-resolve-info": "^4.14.0",
|
|
39
39
|
"graphql-ws": "^5.14.2",
|
|
40
40
|
"pg": "^8.11.3",
|
|
41
|
-
"ws": "^8.14.2"
|
|
41
|
+
"ws": "^8.14.2",
|
|
42
|
+
"inflected": "^2.1.0"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"@subsquid/big-decimal": "^1.0.0"
|
|
@@ -59,7 +60,8 @@
|
|
|
59
60
|
"expect": "^29.7.0",
|
|
60
61
|
"gql-test-client": "^0.0.0",
|
|
61
62
|
"mocha": "^10.2.0",
|
|
62
|
-
"typescript": "~5.3.2"
|
|
63
|
+
"typescript": "~5.3.2",
|
|
64
|
+
"@types/inflected": "^2.1.3"
|
|
63
65
|
},
|
|
64
66
|
"scripts": {
|
|
65
67
|
"build": "rm -rf lib && tsc",
|
package/src/context.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {Logger} from '@subsquid/logger'
|
|
2
|
-
import type {
|
|
2
|
+
import type {DbType} from './db'
|
|
3
3
|
import type {Query} from './sql/query'
|
|
4
4
|
import type {Limit} from './util/limit'
|
|
5
5
|
|
|
@@ -11,7 +11,7 @@ export interface Context {
|
|
|
11
11
|
|
|
12
12
|
export interface OpenreaderContext {
|
|
13
13
|
id: number
|
|
14
|
-
|
|
14
|
+
dbType: DbType
|
|
15
15
|
executeQuery<T>(query: Query<T>): Promise<T>
|
|
16
16
|
subscription<T>(query: Query<T>): AsyncIterable<T>
|
|
17
17
|
responseSizeLimit?: Limit
|
package/src/db.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {addErrorContext} from '@subsquid/util-internal'
|
|
|
3
3
|
import type {ClientBase, Pool} from 'pg'
|
|
4
4
|
import {QueryResult} from 'pg'
|
|
5
5
|
import {OpenreaderContext} from './context'
|
|
6
|
-
import {Dialect} from './dialect'
|
|
7
6
|
import {Query} from './sql/query'
|
|
8
7
|
import {Subscription} from './subscription'
|
|
9
8
|
import {LazyTransaction} from './util/lazy-transaction'
|
|
@@ -12,6 +11,9 @@ import {LazyTransaction} from './util/lazy-transaction'
|
|
|
12
11
|
let CTX_COUNTER = 0
|
|
13
12
|
|
|
14
13
|
|
|
14
|
+
export type DbType = 'postgres' | 'cockroach'
|
|
15
|
+
|
|
16
|
+
|
|
15
17
|
export class PoolOpenreaderContext implements OpenreaderContext {
|
|
16
18
|
public id = (CTX_COUNTER = (CTX_COUNTER + 1) % Number.MAX_SAFE_INTEGER)
|
|
17
19
|
public log?: Logger
|
|
@@ -20,7 +22,7 @@ export class PoolOpenreaderContext implements OpenreaderContext {
|
|
|
20
22
|
private queryCounter = 0
|
|
21
23
|
|
|
22
24
|
constructor(
|
|
23
|
-
public readonly
|
|
25
|
+
public readonly dbType: DbType,
|
|
24
26
|
pool: Pool,
|
|
25
27
|
subscriptionPool?: Pool,
|
|
26
28
|
private subscriptionPollInterval: number = 1000,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {GraphQLFieldConfigMap, GraphQLSchema} from 'graphql'
|
|
2
|
+
import {Model} from '../model'
|
|
3
|
+
import {Context} from '../context'
|
|
4
|
+
import {OrderBy, Where} from '../ir/args'
|
|
5
|
+
import assert from 'assert'
|
|
6
|
+
|
|
7
|
+
export enum Dialect {
|
|
8
|
+
OpenCrud = 'opencrud',
|
|
9
|
+
TheGraph = 'thegraph',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SchemaBuilder {
|
|
13
|
+
build(): GraphQLSchema
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SchemaOptions {
|
|
17
|
+
model: Model
|
|
18
|
+
subscriptions?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type GqlFieldMap = GraphQLFieldConfigMap<unknown, Context>
|
|
22
|
+
|
|
23
|
+
export function mergeOrderBy(list: OrderBy[]): OrderBy {
|
|
24
|
+
let result: OrderBy = {}
|
|
25
|
+
list.forEach((item) => {
|
|
26
|
+
for (let key in item) {
|
|
27
|
+
let current = result[key]
|
|
28
|
+
if (current == null) {
|
|
29
|
+
result[key] = item[key]
|
|
30
|
+
} else if (typeof current != 'string') {
|
|
31
|
+
let it = item[key]
|
|
32
|
+
assert(typeof it == 'object')
|
|
33
|
+
result[key] = mergeOrderBy([current, it])
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function toCondition(op: 'AND' | 'OR', operands: Where[]): Where | undefined {
|
|
41
|
+
switch(operands.length) {
|
|
42
|
+
case 0:
|
|
43
|
+
return undefined
|
|
44
|
+
case 1:
|
|
45
|
+
return operands[0]
|
|
46
|
+
default:
|
|
47
|
+
return {op, args: operands}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {unexpectedCase} from '@subsquid/util-internal'
|
|
2
|
+
import {Dialect, SchemaBuilder, SchemaOptions} from './common'
|
|
3
|
+
|
|
4
|
+
export * from './common'
|
|
5
|
+
|
|
6
|
+
export async function getSchemaBuilder(options: SchemaOptions & {dialect?: Dialect}): Promise<SchemaBuilder> {
|
|
7
|
+
switch (options.dialect) {
|
|
8
|
+
case undefined:
|
|
9
|
+
case Dialect.OpenCrud: {
|
|
10
|
+
const {SchemaBuilder} = await import('./opencrud/schema')
|
|
11
|
+
return new SchemaBuilder(options)
|
|
12
|
+
}
|
|
13
|
+
case Dialect.TheGraph: {
|
|
14
|
+
const {SchemaBuilder} = await import('./thegraph/schema')
|
|
15
|
+
return new SchemaBuilder(options)
|
|
16
|
+
}
|
|
17
|
+
default:
|
|
18
|
+
throw unexpectedCase(options.dialect)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import assert from "assert"
|
|
2
|
-
import type { Model } from "
|
|
3
|
-
import { getUniversalProperties } from '
|
|
4
|
-
import { OrderBy } from "
|
|
2
|
+
import type { Model } from "../../model"
|
|
3
|
+
import { getUniversalProperties } from '../../model.tools'
|
|
4
|
+
import { OrderBy } from "../../ir/args"
|
|
5
|
+
import {mergeOrderBy} from '../common'
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -80,21 +81,3 @@ export function parseOrderBy(model: Model, typeName: string, input: OpenCrudOrde
|
|
|
80
81
|
})
|
|
81
82
|
)
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export function mergeOrderBy(list: OrderBy[]): OrderBy {
|
|
86
|
-
let result: OrderBy = {}
|
|
87
|
-
list.forEach(item => {
|
|
88
|
-
for (let key in item) {
|
|
89
|
-
let current = result[key]
|
|
90
|
-
if (current == null) {
|
|
91
|
-
result[key] = item[key]
|
|
92
|
-
} else if (typeof current != 'string') {
|
|
93
|
-
let it = item[key]
|
|
94
|
-
assert(typeof it == 'object')
|
|
95
|
-
result[key] = mergeOrderBy([current, it])
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
return result
|
|
100
|
-
}
|