@subsquid/openreader 4.5.1 → 5.0.0-beta.62d187

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 (131) hide show
  1. package/lib/context.d.ts +2 -2
  2. package/lib/context.d.ts.map +1 -1
  3. package/lib/db.d.ts +3 -3
  4. package/lib/db.d.ts.map +1 -1
  5. package/lib/db.js +2 -2
  6. package/lib/db.js.map +1 -1
  7. package/lib/dialect/common.d.ts +19 -0
  8. package/lib/dialect/common.d.ts.map +1 -0
  9. package/lib/dialect/common.js +42 -0
  10. package/lib/dialect/common.js.map +1 -0
  11. package/lib/dialect/index.d.ts +6 -0
  12. package/lib/dialect/index.d.ts.map +1 -0
  13. package/lib/dialect/index.js +49 -0
  14. package/lib/dialect/index.js.map +1 -0
  15. package/lib/{opencrud → dialect/opencrud}/orderBy.d.ts +2 -3
  16. package/lib/dialect/opencrud/orderBy.d.ts.map +1 -0
  17. package/lib/{opencrud → dialect/opencrud}/orderBy.js +6 -21
  18. package/lib/dialect/opencrud/orderBy.js.map +1 -0
  19. package/lib/{opencrud → dialect/opencrud}/schema.d.ts +2 -6
  20. package/lib/dialect/opencrud/schema.d.ts.map +1 -0
  21. package/lib/{opencrud → dialect/opencrud}/schema.js +21 -34
  22. package/lib/dialect/opencrud/schema.js.map +1 -0
  23. package/lib/{opencrud → dialect/opencrud}/tree.d.ts +3 -3
  24. package/lib/dialect/opencrud/tree.d.ts.map +1 -0
  25. package/lib/{opencrud → dialect/opencrud}/tree.js +3 -3
  26. package/lib/dialect/opencrud/tree.js.map +1 -0
  27. package/lib/{opencrud → dialect/opencrud}/where.d.ts +1 -1
  28. package/lib/dialect/opencrud/where.d.ts.map +1 -0
  29. package/lib/{opencrud → dialect/opencrud}/where.js +4 -13
  30. package/lib/dialect/opencrud/where.js.map +1 -0
  31. package/lib/dialect/thegraph/locale.d.ts +2 -0
  32. package/lib/dialect/thegraph/locale.d.ts.map +1 -0
  33. package/lib/dialect/thegraph/locale.js +49 -0
  34. package/lib/dialect/thegraph/locale.js.map +1 -0
  35. package/lib/dialect/thegraph/orderBy.d.ts +11 -0
  36. package/lib/dialect/thegraph/orderBy.d.ts.map +1 -0
  37. package/lib/dialect/thegraph/orderBy.js +71 -0
  38. package/lib/dialect/thegraph/orderBy.js.map +1 -0
  39. package/lib/dialect/thegraph/schema.d.ts +25 -0
  40. package/lib/dialect/thegraph/schema.d.ts.map +1 -0
  41. package/lib/dialect/thegraph/schema.js +429 -0
  42. package/lib/dialect/thegraph/schema.js.map +1 -0
  43. package/lib/dialect/thegraph/tree.d.ts +10 -0
  44. package/lib/dialect/thegraph/tree.d.ts.map +1 -0
  45. package/lib/dialect/thegraph/tree.js +148 -0
  46. package/lib/dialect/thegraph/tree.js.map +1 -0
  47. package/lib/dialect/thegraph/where.d.ts +9 -0
  48. package/lib/dialect/thegraph/where.d.ts.map +1 -0
  49. package/lib/dialect/thegraph/where.js +188 -0
  50. package/lib/dialect/thegraph/where.js.map +1 -0
  51. package/lib/ir/args.d.ts +2 -2
  52. package/lib/ir/args.d.ts.map +1 -1
  53. package/lib/main.js +1 -1
  54. package/lib/main.js.map +1 -1
  55. package/lib/model.d.ts +2 -0
  56. package/lib/model.d.ts.map +1 -1
  57. package/lib/model.schema.d.ts.map +1 -1
  58. package/lib/model.schema.js +31 -2
  59. package/lib/model.schema.js.map +1 -1
  60. package/lib/server.d.ts +3 -1
  61. package/lib/server.d.ts.map +1 -1
  62. package/lib/server.js +7 -6
  63. package/lib/server.js.map +1 -1
  64. package/lib/sql/cursor.d.ts +2 -2
  65. package/lib/sql/cursor.d.ts.map +1 -1
  66. package/lib/sql/cursor.js +2 -2
  67. package/lib/sql/cursor.js.map +1 -1
  68. package/lib/sql/printer.d.ts +3 -3
  69. package/lib/sql/printer.d.ts.map +1 -1
  70. package/lib/sql/printer.js +17 -15
  71. package/lib/sql/printer.js.map +1 -1
  72. package/lib/sql/query.d.ts +5 -5
  73. package/lib/sql/query.d.ts.map +1 -1
  74. package/lib/sql/query.js.map +1 -1
  75. package/lib/sql/util.d.ts +2 -2
  76. package/lib/sql/util.d.ts.map +1 -1
  77. package/lib/sql/util.js.map +1 -1
  78. package/lib/test/basic.test.js +471 -229
  79. package/lib/test/basic.test.js.map +1 -1
  80. package/lib/test/isNull.test.js +87 -36
  81. package/lib/test/isNull.test.js.map +1 -1
  82. package/lib/test/limits.test.js +206 -94
  83. package/lib/test/limits.test.js.map +1 -1
  84. package/lib/test/lookup.test.js +184 -81
  85. package/lib/test/lookup.test.js.map +1 -1
  86. package/lib/test/setup.js +2 -2
  87. package/lib/test/setup.js.map +1 -1
  88. package/lib/test/where.test.js +216 -99
  89. package/lib/test/where.test.js.map +1 -1
  90. package/package.json +8 -6
  91. package/src/context.ts +2 -2
  92. package/src/db.ts +4 -2
  93. package/src/dialect/common.ts +49 -0
  94. package/src/dialect/index.ts +20 -0
  95. package/src/{opencrud → dialect/opencrud}/orderBy.ts +6 -22
  96. package/src/{opencrud → dialect/opencrud}/schema.ts +30 -55
  97. package/src/{opencrud → dialect/opencrud}/tree.ts +6 -7
  98. package/src/{opencrud → dialect/opencrud}/where.ts +4 -16
  99. package/src/dialect/thegraph/locale.ts +284 -0
  100. package/src/dialect/thegraph/orderBy.ts +75 -0
  101. package/src/dialect/thegraph/schema.ts +484 -0
  102. package/src/dialect/thegraph/tree.ts +162 -0
  103. package/src/dialect/thegraph/where.ts +184 -0
  104. package/src/ir/args.ts +3 -1
  105. package/src/main.ts +3 -3
  106. package/src/model.schema.ts +37 -4
  107. package/src/model.ts +2 -0
  108. package/src/server.ts +21 -19
  109. package/src/sql/cursor.ts +4 -4
  110. package/src/sql/printer.ts +22 -18
  111. package/src/sql/query.ts +5 -5
  112. package/src/sql/util.ts +2 -2
  113. package/src/test/basic.test.ts +570 -282
  114. package/src/test/isNull.test.ts +95 -38
  115. package/src/test/limits.test.ts +212 -91
  116. package/src/test/lookup.test.ts +190 -83
  117. package/src/test/setup.ts +2 -2
  118. package/src/test/where.test.ts +235 -108
  119. package/lib/dialect.d.ts +0 -2
  120. package/lib/dialect.d.ts.map +0 -1
  121. package/lib/dialect.js +0 -3
  122. package/lib/dialect.js.map +0 -1
  123. package/lib/opencrud/orderBy.d.ts.map +0 -1
  124. package/lib/opencrud/orderBy.js.map +0 -1
  125. package/lib/opencrud/schema.d.ts.map +0 -1
  126. package/lib/opencrud/schema.js.map +0 -1
  127. package/lib/opencrud/tree.d.ts.map +0 -1
  128. package/lib/opencrud/tree.js.map +0 -1
  129. package/lib/opencrud/where.d.ts.map +0 -1
  130. package/lib/opencrud/where.js.map +0 -1
  131. package/src/dialect.ts +0 -2
@@ -1,3 +1,4 @@
1
+ import {Dialect} from '../dialect'
1
2
  import {useDatabase, useServer} from "./setup"
2
3
 
3
4
 
@@ -12,7 +13,7 @@ describe('isNull operator', function() {
12
13
  `insert into entity (id, scalar, json, meta_id) values ('4', 'foo', '{}', '1')`,
13
14
  ])
14
15
 
15
- const client = useServer(`
16
+ const schema = `
16
17
  type Meta @entity {
17
18
  id: ID!
18
19
  }
@@ -27,53 +28,109 @@ describe('isNull operator', function() {
27
28
  type JsonObject {
28
29
  a: Int
29
30
  }
30
- `)
31
+ `
31
32
 
32
- it("on scalar", function() {
33
- return client.test(`
34
- query {
35
- entities(where: {scalar_isNull: true}) {
36
- id
33
+ describe(Dialect.OpenCrud, function() {
34
+ const client = useServer(schema)
35
+
36
+ it("on scalar", function() {
37
+ return client.test(`
38
+ query {
39
+ entities(where: {scalar_isNull: true}) {
40
+ id
41
+ }
37
42
  }
38
- }
39
- `, {
40
- entities: [{id: '1'}]
43
+ `, {
44
+ entities: [{id: '1'}]
45
+ })
41
46
  })
42
- })
43
-
44
- it("on json", function() {
45
- return client.test(`
46
- query {
47
- entities(where: {json_isNull: true}) {
48
- id
47
+
48
+ it("on json", function() {
49
+ return client.test(`
50
+ query {
51
+ entities(where: {json_isNull: true}) {
52
+ id
53
+ }
49
54
  }
50
- }
51
- `, {
52
- entities: [{id: '2'}]
55
+ `, {
56
+ entities: [{id: '2'}]
57
+ })
53
58
  })
54
- })
55
-
56
- it("on nested json prop", function() {
57
- return client.test(`
58
- query {
59
- entities(where: {json: {a_isNull: true}} orderBy: id_ASC) {
60
- id
59
+
60
+ it("on nested json prop", function() {
61
+ return client.test(`
62
+ query {
63
+ entities(where: {json: {a_isNull: true}} orderBy: id_ASC) {
64
+ id
65
+ }
66
+ }
67
+ `, {
68
+ entities: [{id: '2'}, {id: '4'}]
69
+ })
70
+ })
71
+
72
+ it("on fk", function() {
73
+ return client.test(`
74
+ query {
75
+ entities(where: {meta_isNull: true}) {
76
+ id
77
+ }
61
78
  }
62
- }
63
- `, {
64
- entities: [{id: '2'}, {id: '4'}]
79
+ `, {
80
+ entities: [{id: '3'}]
81
+ })
65
82
  })
66
83
  })
67
84
 
68
- it("on fk", function() {
69
- return client.test(`
70
- query {
71
- entities(where: {meta_isNull: true}) {
72
- id
85
+ describe(Dialect.TheGraph, function() {
86
+ const client = useServer(schema, {dialect: Dialect.TheGraph})
87
+
88
+ it("on scalar", function() {
89
+ return client.test(`
90
+ query {
91
+ entities(where: {scalar_is_null: true}) {
92
+ id
93
+ }
94
+ }
95
+ `, {
96
+ entities: [{id: '1'}]
97
+ })
98
+ })
99
+
100
+ it("on json", function() {
101
+ return client.test(`
102
+ query {
103
+ entities(where: {json_is_null: true}) {
104
+ id
105
+ }
106
+ }
107
+ `, {
108
+ entities: [{id: '2'}]
109
+ })
110
+ })
111
+
112
+ it("on nested json prop", function() {
113
+ return client.test(`
114
+ query {
115
+ entities(where: {json_: {a_is_null: true}} orderBy: id, orderDirection: asc) {
116
+ id
117
+ }
118
+ }
119
+ `, {
120
+ entities: [{id: '2'}, {id: '4'}]
121
+ })
122
+ })
123
+
124
+ it("on fk", function() {
125
+ return client.test(`
126
+ query {
127
+ entities(where: {meta_is_null: true}) {
128
+ id
129
+ }
73
130
  }
74
- }
75
- `, {
76
- entities: [{id: '3'}]
131
+ `, {
132
+ entities: [{id: '3'}]
133
+ })
77
134
  })
78
135
  })
79
136
  })
@@ -1,5 +1,6 @@
1
1
  import expect from 'expect'
2
2
  import {useDatabase, useServer} from './setup'
3
+ import {Dialect} from '../dialect'
3
4
 
4
5
 
5
6
  describe('response size limits', function() {
@@ -12,7 +13,7 @@ describe('response size limits', function() {
12
13
  `create table item3 (id text primary key, order_id text, name text)`,
13
14
  ])
14
15
 
15
- const client = useServer(`
16
+ let schema = `
16
17
  type Order1 @entity {
17
18
  id: ID!
18
19
  items: [Item1!]! @derivedFrom(field: "order")
@@ -45,119 +46,239 @@ describe('response size limits', function() {
45
46
  order: Order3!
46
47
  name: String @byteWeight(value: 10.0)
47
48
  }
48
- `, {
49
+ `
50
+ let opts = {
49
51
  maxResponseNodes: 50,
50
52
  maxRootFields: 3
51
- })
53
+ }
54
+
55
+ describe(Dialect.OpenCrud, function() {
56
+ const client = useServer(schema, opts)
52
57
 
53
- it('unlimited requests fail', async function() {
54
- let result = await client.query(`
55
- query {
56
- order1s {
57
- id
58
- }
59
- }
60
- `)
61
- expect(result).toMatchObject({
62
- data: null,
63
- errors: [
64
- expect.objectContaining({message: 'response might exceed the size limit', path: ['order1s']})
65
- ]
58
+ it('unlimited requests fail', async function() {
59
+ let result = await client.query(`
60
+ query {
61
+ order1s {
62
+ id
63
+ }
64
+ }
65
+ `)
66
+ expect(result).toMatchObject({
67
+ data: null,
68
+ errors: [
69
+ expect.objectContaining({message: 'response might exceed the size limit', path: ['order1s']})
70
+ ]
71
+ })
66
72
  })
67
- })
68
73
 
69
- it('limited requests work', function() {
70
- return client.test(`
71
- query {
72
- order1s(limit: 10) {
73
- items(limit: 2) {
74
+ it('limited requests work', function() {
75
+ return client.test(`
76
+ query {
77
+ order1s(limit: 10) {
78
+ items(limit: 2) {
79
+ id
80
+ }
81
+ }
82
+ }
83
+ `, {
84
+ order1s: []
85
+ })
86
+ })
87
+
88
+ it('entity level cardinalities are respected', function() {
89
+ return client.test(`
90
+ query {
91
+ order2s {
74
92
  id
75
93
  }
76
94
  }
77
- }
78
- `, {
79
- order1s: []
95
+ `, {
96
+ order2s: []
97
+ })
80
98
  })
81
- })
82
99
 
83
- it('entity level cardinalities are respected', function() {
84
- return client.test(`
85
- query {
86
- order2s {
87
- id
100
+ it('item cardinalities are respected', function() {
101
+ return client.test(`
102
+ query {
103
+ order3s(limit: 1) {
104
+ items { id }
105
+ }
88
106
  }
89
- }
90
- `, {
91
- order2s: []
107
+ `, {
108
+ order3s: []
109
+ })
92
110
  })
93
- })
94
111
 
95
- it('item cardinalities are respected', function() {
96
- return client.test(`
97
- query {
98
- order3s(limit: 1) {
99
- items { id }
112
+ it('@byteWeight annotations are respected', async function() {
113
+ let result = await client.query(`
114
+ query {
115
+ order3s(limit: 1) {
116
+ items(limit: 8) { name }
117
+ }
118
+ }
119
+ `)
120
+ expect(result).toEqual({
121
+ data: null,
122
+ errors: [
123
+ expect.objectContaining({
124
+ message: 'response might exceed the size limit',
125
+ path: ['order3s']
126
+ })
127
+ ]
128
+ })
129
+ await client.test(`
130
+ query {
131
+ order3s(limit: 1) {
132
+ items(limit: 4) { name }
133
+ }
100
134
  }
101
- }
102
- `, {
103
- order3s: []
135
+ `, {
136
+ order3s: []
137
+ })
104
138
  })
105
- })
106
139
 
107
- it('@byteWeight annotations are respected', async function() {
108
- let result = await client.query(`
109
- query {
110
- order3s(limit: 1) {
111
- items(limit: 8) { name }
112
- }
113
- }
114
- `)
115
- expect(result).toEqual({
116
- data: null,
117
- errors: [
118
- expect.objectContaining({
119
- message: 'response might exceed the size limit',
120
- path: ['order3s']
121
- })
122
- ]
140
+ it('id_in conditions are understood', function() {
141
+ return client.test(`
142
+ query {
143
+ order1s(where: {id_in: ["1", "2", "3"]}) {
144
+ id
145
+ }
146
+ }
147
+ `, {
148
+ order1s: []
149
+ })
123
150
  })
124
- await client.test(`
125
- query {
126
- order3s(limit: 1) {
127
- items(limit: 4) { name }
128
- }
129
- }
130
- `, {
131
- order3s: []
151
+
152
+ it('root query fields limit', async function() {
153
+ return client.httpErrorTest(`
154
+ query {
155
+ a: order1ById(id: "1") { id }
156
+ b: order1ById(id: "1") { id }
157
+ c: order1ById(id: "1") { id }
158
+ d: order1ById(id: "1") { id }
159
+ }
160
+ `, {
161
+ errors: [
162
+ expect.objectContaining({
163
+ message: 'only 3 root fields allowed, but got 4'
164
+ })
165
+ ]
166
+ })
132
167
  })
133
168
  })
134
169
 
135
- it('id_in conditions are understood', function() {
136
- return client.test(`
137
- query {
138
- order1s(where: {id_in: ["1", "2", "3"]}) {
139
- id
170
+ describe(Dialect.TheGraph, function() {
171
+ const client = useServer(schema, {...opts, dialect: Dialect.TheGraph})
172
+
173
+ it('unlimited requests fail', async function() {
174
+ let result = await client.query(`
175
+ query {
176
+ order1s {
177
+ id
178
+ }
140
179
  }
141
- }
142
- `, {
143
- order1s: []
180
+ `)
181
+ expect(result).toMatchObject({
182
+ data: null,
183
+ errors: [
184
+ expect.objectContaining({message: 'response might exceed the size limit', path: ['order1s']})
185
+ ]
186
+ })
144
187
  })
145
- })
146
188
 
147
- it('root query fields limit', async function() {
148
- return client.httpErrorTest(`
149
- query {
150
- a: order1ById(id: "1") { id }
151
- b: order1ById(id: "1") { id }
152
- c: order1ById(id: "1") { id }
153
- d: order1ById(id: "1") { id }
154
- }
155
- `, {
156
- errors: [
157
- expect.objectContaining({
158
- message: 'only 3 root fields allowed, but got 4'
159
- })
160
- ]
189
+ it('limited requests work', function() {
190
+ return client.test(`
191
+ query {
192
+ order1s(first: 10) {
193
+ items(first: 2) {
194
+ id
195
+ }
196
+ }
197
+ }
198
+ `, {
199
+ order1s: []
200
+ })
201
+ })
202
+
203
+ it('entity level cardinalities are respected', function() {
204
+ return client.test(`
205
+ query {
206
+ order2s {
207
+ id
208
+ }
209
+ }
210
+ `, {
211
+ order2s: []
212
+ })
213
+ })
214
+
215
+ it('item cardinalities are respected', function() {
216
+ return client.test(`
217
+ query {
218
+ order3s(first: 1) {
219
+ items { id }
220
+ }
221
+ }
222
+ `, {
223
+ order3s: []
224
+ })
225
+ })
226
+
227
+ it('@byteWeight annotations are respected', async function() {
228
+ let result = await client.query(`
229
+ query {
230
+ order3s(first: 1) {
231
+ items(first: 8) { name }
232
+ }
233
+ }
234
+ `)
235
+ expect(result).toEqual({
236
+ data: null,
237
+ errors: [
238
+ expect.objectContaining({
239
+ message: 'response might exceed the size limit',
240
+ path: ['order3s']
241
+ })
242
+ ]
243
+ })
244
+ await client.test(`
245
+ query {
246
+ order3s(first: 1) {
247
+ items(first: 4) { name }
248
+ }
249
+ }
250
+ `, {
251
+ order3s: []
252
+ })
253
+ })
254
+
255
+ it('id_in conditions are understood', function() {
256
+ return client.test(`
257
+ query {
258
+ order1s(where: {id_in: ["1", "2", "3"]}) {
259
+ id
260
+ }
261
+ }
262
+ `, {
263
+ order1s: []
264
+ })
265
+ })
266
+
267
+ it('root query fields limit', async function() {
268
+ return client.httpErrorTest(`
269
+ query {
270
+ a: order1(id: "1") { id }
271
+ b: order1(id: "1") { id }
272
+ c: order1(id: "1") { id }
273
+ d: order1(id: "1") { id }
274
+ }
275
+ `, {
276
+ errors: [
277
+ expect.objectContaining({
278
+ message: 'only 3 root fields allowed, but got 4'
279
+ })
280
+ ]
281
+ })
161
282
  })
162
283
  })
163
284
  })