@subsquid/openreader 1.0.2 → 2.1.0
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/bin/main.js +1 -1
- package/lib/context.d.ts +14 -0
- package/lib/context.d.ts.map +1 -0
- package/lib/context.js +3 -0
- package/lib/context.js.map +1 -0
- package/lib/db.d.ts +23 -0
- package/lib/db.d.ts.map +1 -0
- package/lib/db.js +57 -0
- package/lib/db.js.map +1 -0
- package/{dist → lib}/dialect.d.ts +0 -0
- package/{dist → lib}/dialect.d.ts.map +0 -0
- package/{dist → lib}/dialect.js +0 -0
- package/{dist → lib}/dialect.js.map +0 -0
- package/lib/ir/args.d.ts +47 -0
- package/lib/ir/args.d.ts.map +1 -0
- package/lib/ir/args.js +3 -0
- package/lib/ir/args.js.map +1 -0
- package/lib/ir/connection.d.ts +30 -0
- package/lib/ir/connection.d.ts.map +1 -0
- package/lib/ir/connection.js +17 -0
- package/lib/ir/connection.js.map +1 -0
- package/lib/ir/fields.d.ts +22 -0
- package/lib/ir/fields.d.ts.map +1 -0
- package/lib/ir/fields.js +3 -0
- package/lib/ir/fields.js.map +1 -0
- package/lib/limit.size.d.ts +8 -0
- package/lib/limit.size.d.ts.map +1 -0
- package/lib/limit.size.js +107 -0
- package/lib/limit.size.js.map +1 -0
- package/{dist → lib}/main.d.ts +0 -0
- package/{dist → lib}/main.d.ts.map +0 -0
- package/lib/main.js +59 -0
- package/lib/main.js.map +1 -0
- package/{dist → lib}/model.d.ts +11 -1
- package/lib/model.d.ts.map +1 -0
- package/{dist → lib}/model.js +0 -0
- package/{dist → lib}/model.js.map +0 -0
- package/{dist/gql/schema.d.ts → lib/model.schema.d.ts} +2 -2
- package/lib/model.schema.d.ts.map +1 -0
- package/{dist/gql/schema.js → lib/model.schema.js} +62 -8
- package/lib/model.schema.js.map +1 -0
- package/{dist → lib}/model.tools.d.ts +0 -0
- package/{dist → lib}/model.tools.d.ts.map +0 -0
- package/{dist → lib}/model.tools.js +0 -0
- package/{dist → lib}/model.tools.js.map +0 -0
- package/{dist → lib/opencrud}/orderBy.d.ts +2 -5
- package/lib/opencrud/orderBy.d.ts.map +1 -0
- package/{dist → lib/opencrud}/orderBy.js +1 -1
- package/lib/opencrud/orderBy.js.map +1 -0
- package/lib/opencrud/schema.d.ts +31 -0
- package/lib/opencrud/schema.d.ts.map +1 -0
- package/lib/opencrud/schema.js +527 -0
- package/lib/opencrud/schema.js.map +1 -0
- package/lib/opencrud/tree.d.ts +8 -0
- package/lib/opencrud/tree.d.ts.map +1 -0
- package/lib/opencrud/tree.js +131 -0
- package/lib/opencrud/tree.js.map +1 -0
- package/lib/opencrud/where.d.ts +7 -0
- package/lib/opencrud/where.d.ts.map +1 -0
- package/lib/opencrud/where.js +141 -0
- package/lib/opencrud/where.js.map +1 -0
- package/{dist/gql → lib}/scalars/BigInt.d.ts +0 -0
- package/lib/scalars/BigInt.d.ts.map +1 -0
- package/{dist/gql → lib}/scalars/BigInt.js +1 -1
- package/lib/scalars/BigInt.js.map +1 -0
- package/{dist/gql → lib}/scalars/Bytes.d.ts +0 -0
- package/lib/scalars/Bytes.d.ts.map +1 -0
- package/{dist/gql → lib}/scalars/Bytes.js +2 -2
- package/lib/scalars/Bytes.js.map +1 -0
- package/{dist/gql → lib}/scalars/DateTime.d.ts +0 -0
- package/lib/scalars/DateTime.d.ts.map +1 -0
- package/{dist/gql → lib}/scalars/DateTime.js +1 -1
- package/lib/scalars/DateTime.js.map +1 -0
- package/{dist/gql → lib}/scalars/JSON.d.ts +0 -0
- package/lib/scalars/JSON.d.ts.map +1 -0
- package/{dist/gql → lib}/scalars/JSON.js +0 -0
- package/lib/scalars/JSON.js.map +1 -0
- package/{dist/gql → lib}/scalars/index.d.ts +0 -0
- package/lib/scalars/index.d.ts.map +1 -0
- package/{dist/gql → lib}/scalars/index.js +0 -0
- package/lib/scalars/index.js.map +1 -0
- package/lib/server.d.ts +42 -0
- package/lib/server.d.ts.map +1 -0
- package/lib/server.js +171 -0
- package/lib/server.js.map +1 -0
- package/lib/sql/cursor.d.ts +52 -0
- package/lib/sql/cursor.d.ts.map +1 -0
- package/lib/sql/cursor.js +234 -0
- package/lib/sql/cursor.js.map +1 -0
- package/lib/sql/mapping.d.ts +4 -0
- package/lib/sql/mapping.d.ts.map +1 -0
- package/lib/sql/mapping.js +71 -0
- package/lib/sql/mapping.js.map +1 -0
- package/lib/sql/printer.d.ts +37 -0
- package/lib/sql/printer.d.ts.map +1 -0
- package/lib/sql/printer.js +311 -0
- package/lib/sql/printer.js.map +1 -0
- package/lib/sql/query.d.ts +46 -0
- package/lib/sql/query.d.ts.map +1 -0
- package/lib/sql/query.js +134 -0
- package/lib/sql/query.js.map +1 -0
- package/lib/sql/util.d.ts +30 -0
- package/lib/sql/util.d.ts.map +1 -0
- package/lib/sql/util.js +75 -0
- package/lib/sql/util.js.map +1 -0
- package/lib/subscription.d.ts +18 -0
- package/lib/subscription.d.ts.map +1 -0
- package/lib/subscription.js +47 -0
- package/lib/subscription.js.map +1 -0
- package/{dist → lib}/test/basic.test.d.ts +0 -0
- package/{dist → lib}/test/basic.test.d.ts.map +0 -0
- package/{dist → lib}/test/basic.test.js +0 -0
- package/{dist → lib}/test/basic.test.js.map +0 -0
- package/{dist → lib}/test/connection.test.d.ts +0 -0
- package/{dist → lib}/test/connection.test.d.ts.map +0 -0
- package/{dist → lib}/test/connection.test.js +0 -0
- package/{dist → lib}/test/connection.test.js.map +0 -0
- package/{dist → lib}/test/fts.test.d.ts +0 -0
- package/{dist → lib}/test/fts.test.d.ts.map +0 -0
- package/{dist → lib}/test/fts.test.js +1 -1
- package/lib/test/fts.test.js.map +1 -0
- package/{dist → lib}/test/isNull.test.d.ts +0 -0
- package/{dist → lib}/test/isNull.test.d.ts.map +0 -0
- package/{dist → lib}/test/isNull.test.js +0 -0
- package/{dist → lib}/test/isNull.test.js.map +0 -0
- package/lib/test/limits.test.d.ts +2 -0
- package/lib/test/limits.test.d.ts.map +1 -0
- package/lib/test/limits.test.js +159 -0
- package/lib/test/limits.test.js.map +1 -0
- package/{dist → lib}/test/lists.test.d.ts +0 -0
- package/{dist → lib}/test/lists.test.d.ts.map +0 -0
- package/{dist → lib}/test/lists.test.js +0 -0
- package/{dist → lib}/test/lists.test.js.map +0 -0
- package/{dist → lib}/test/lookup.test.d.ts +0 -0
- package/{dist → lib}/test/lookup.test.d.ts.map +0 -0
- package/{dist → lib}/test/lookup.test.js +0 -0
- package/{dist → lib}/test/lookup.test.js.map +0 -0
- package/{dist → lib}/test/regressions.test.d.ts +0 -0
- package/{dist → lib}/test/regressions.test.d.ts.map +0 -0
- package/{dist → lib}/test/regressions.test.js +0 -0
- package/{dist → lib}/test/regressions.test.js.map +0 -0
- package/{dist → lib}/test/scalars.test.d.ts +0 -0
- package/{dist → lib}/test/scalars.test.d.ts.map +0 -0
- package/{dist → lib}/test/scalars.test.js +0 -0
- package/{dist → lib}/test/scalars.test.js.map +0 -0
- package/lib/test/setup.d.ts +17 -0
- package/lib/test/setup.d.ts.map +1 -0
- package/{dist → lib}/test/setup.js +18 -13
- package/lib/test/setup.js.map +1 -0
- package/lib/test/subscription.test.d.ts +2 -0
- package/lib/test/subscription.test.d.ts.map +1 -0
- package/lib/test/subscription.test.js +99 -0
- package/lib/test/subscription.test.js.map +1 -0
- package/{dist → lib}/test/tools.test.d.ts +0 -0
- package/{dist → lib}/test/tools.test.d.ts.map +0 -0
- package/{dist → lib}/test/tools.test.js +0 -0
- package/{dist → lib}/test/tools.test.js.map +0 -0
- package/{dist → lib}/test/typed-json.test.d.ts +0 -0
- package/{dist → lib}/test/typed-json.test.d.ts.map +0 -0
- package/{dist → lib}/test/typed-json.test.js +0 -0
- package/{dist → lib}/test/typed-json.test.js.map +0 -0
- package/{dist → lib}/test/unions.test.d.ts +0 -0
- package/{dist → lib}/test/unions.test.d.ts.map +0 -0
- package/{dist → lib}/test/unions.test.js +0 -0
- package/{dist → lib}/test/unions.test.js.map +0 -0
- package/{dist → lib}/test/where.test.d.ts +0 -0
- package/{dist → lib}/test/where.test.d.ts.map +0 -0
- package/{dist → lib}/test/where.test.js +0 -0
- package/{dist → lib}/test/where.test.js.map +0 -0
- package/{dist → lib}/tools.d.ts +0 -0
- package/{dist → lib}/tools.d.ts.map +0 -0
- package/{dist → lib}/tools.js +3 -3
- package/{dist → lib}/tools.js.map +1 -1
- package/lib/util/error-handling.d.ts +11 -0
- package/lib/util/error-handling.d.ts.map +1 -0
- package/lib/util/error-handling.js +42 -0
- package/lib/util/error-handling.js.map +1 -0
- package/lib/util/execute.d.ts +5 -0
- package/lib/util/execute.d.ts.map +1 -0
- package/lib/util/execute.js +28 -0
- package/lib/util/execute.js.map +1 -0
- package/lib/util/lazy-transaction.d.ts +10 -0
- package/lib/util/lazy-transaction.d.ts.map +1 -0
- package/lib/util/lazy-transaction.js +43 -0
- package/lib/util/lazy-transaction.js.map +1 -0
- package/lib/util/limit.d.ts +11 -0
- package/lib/util/limit.d.ts.map +1 -0
- package/lib/util/limit.js +39 -0
- package/lib/util/limit.js.map +1 -0
- package/lib/util/resolve-tree.d.ts +14 -0
- package/lib/util/resolve-tree.d.ts.map +1 -0
- package/lib/util/resolve-tree.js +52 -0
- package/lib/util/resolve-tree.js.map +1 -0
- package/{dist → lib/util}/util.d.ts +2 -3
- package/lib/util/util.d.ts.map +1 -0
- package/{dist → lib/util}/util.js +9 -13
- package/lib/util/util.js.map +1 -0
- package/package.json +18 -10
- package/src/context.ts +17 -0
- package/src/db.ts +46 -57
- package/src/ir/args.ts +85 -0
- package/src/ir/connection.ts +48 -0
- package/src/ir/fields.ts +40 -0
- package/src/limit.size.ts +130 -0
- package/src/main.ts +74 -42
- package/src/{gql/schema.ts → model.schema.ts} +72 -9
- package/src/model.ts +13 -1
- package/src/{orderBy.ts → opencrud/orderBy.ts} +3 -10
- package/src/opencrud/schema.ts +639 -0
- package/src/opencrud/tree.ts +144 -0
- package/src/opencrud/where.ts +141 -0
- package/src/{gql/scalars → scalars}/BigInt.ts +1 -1
- package/src/{gql/scalars → scalars}/Bytes.ts +4 -4
- package/src/{gql/scalars → scalars}/DateTime.ts +1 -1
- package/src/{gql/scalars → scalars}/JSON.ts +0 -0
- package/src/{gql/scalars → scalars}/index.ts +0 -0
- package/src/server.ts +175 -55
- package/src/sql/cursor.ts +291 -0
- package/src/sql/mapping.ts +66 -0
- package/src/sql/printer.ts +328 -0
- package/src/sql/query.ts +194 -0
- package/src/sql/util.ts +89 -0
- package/src/subscription.ts +46 -0
- package/src/test/fts.test.ts +1 -1
- package/src/test/limits.test.ts +163 -0
- package/src/test/setup.ts +16 -11
- package/src/test/subscription.test.ts +98 -0
- package/src/tools.ts +1 -1
- package/src/util/error-handling.ts +40 -0
- package/src/util/execute.ts +53 -0
- package/src/util/lazy-transaction.ts +49 -0
- package/src/util/limit.ts +34 -0
- package/src/util/resolve-tree.ts +65 -0
- package/src/{util.ts → util/util.ts} +9 -14
- package/dist/db.d.ts +0 -28
- package/dist/db.d.ts.map +0 -1
- package/dist/db.js +0 -69
- package/dist/db.js.map +0 -1
- package/dist/gql/opencrud.d.ts +0 -6
- package/dist/gql/opencrud.d.ts.map +0 -1
- package/dist/gql/opencrud.js +0 -326
- package/dist/gql/opencrud.js.map +0 -1
- package/dist/gql/scalars/BigInt.d.ts.map +0 -1
- package/dist/gql/scalars/BigInt.js.map +0 -1
- package/dist/gql/scalars/Bytes.d.ts.map +0 -1
- package/dist/gql/scalars/Bytes.js.map +0 -1
- package/dist/gql/scalars/DateTime.d.ts.map +0 -1
- package/dist/gql/scalars/DateTime.js.map +0 -1
- package/dist/gql/scalars/JSON.d.ts.map +0 -1
- package/dist/gql/scalars/JSON.js.map +0 -1
- package/dist/gql/scalars/index.d.ts.map +0 -1
- package/dist/gql/scalars/index.js.map +0 -1
- package/dist/gql/schema.d.ts.map +0 -1
- package/dist/gql/schema.js.map +0 -1
- package/dist/main.js +0 -44
- package/dist/main.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/orderBy.d.ts.map +0 -1
- package/dist/orderBy.js.map +0 -1
- package/dist/queryBuilder.d.ts +0 -56
- package/dist/queryBuilder.d.ts.map +0 -1
- package/dist/queryBuilder.js +0 -733
- package/dist/queryBuilder.js.map +0 -1
- package/dist/relayConnection.d.ts +0 -37
- package/dist/relayConnection.d.ts.map +0 -1
- package/dist/relayConnection.js +0 -43
- package/dist/relayConnection.js.map +0 -1
- package/dist/requestedFields.d.ts +0 -33
- package/dist/requestedFields.d.ts.map +0 -1
- package/dist/requestedFields.js +0 -179
- package/dist/requestedFields.js.map +0 -1
- package/dist/resolver.d.ts +0 -9
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolver.js +0 -158
- package/dist/resolver.js.map +0 -1
- package/dist/server.d.ts +0 -22
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -96
- package/dist/server.js.map +0 -1
- package/dist/test/fts.test.js.map +0 -1
- package/dist/test/setup.d.ts +0 -14
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/test/setup.js.map +0 -1
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js.map +0 -1
- package/dist/where.d.ts +0 -9
- package/dist/where.d.ts.map +0 -1
- package/dist/where.js +0 -101
- package/dist/where.js.map +0 -1
- package/src/gql/opencrud.ts +0 -350
- package/src/queryBuilder.ts +0 -891
- package/src/relayConnection.ts +0 -80
- package/src/requestedFields.ts +0 -246
- package/src/resolver.ts +0 -201
- package/src/where.ts +0 -119
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NonErrorThrown = exports.ensureError = exports.addErrorContext = exports.withErrorContext = exports.logGraphQLError = void 0;
|
|
4
|
+
const logger_1 = require("@subsquid/logger");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
function logGraphQLError(log, err, level = logger_1.LogLevel.ERROR) {
|
|
7
|
+
if (log.level > level)
|
|
8
|
+
return;
|
|
9
|
+
let msg = (0, graphql_1.printError)(err) + '\n';
|
|
10
|
+
log.write(level, {
|
|
11
|
+
graphqlOriginalError: err.originalError,
|
|
12
|
+
graphqlPath: err.path?.join('.'),
|
|
13
|
+
graphqlQuery: err.source?.body,
|
|
14
|
+
}, msg);
|
|
15
|
+
}
|
|
16
|
+
exports.logGraphQLError = logGraphQLError;
|
|
17
|
+
function withErrorContext(ctx) {
|
|
18
|
+
return function (err) {
|
|
19
|
+
throw addErrorContext(err, ctx);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.withErrorContext = withErrorContext;
|
|
23
|
+
function addErrorContext(error, ctx) {
|
|
24
|
+
let e = ensureError(error);
|
|
25
|
+
Object.assign(e, ctx);
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
exports.addErrorContext = addErrorContext;
|
|
29
|
+
function ensureError(err) {
|
|
30
|
+
if (err instanceof Error)
|
|
31
|
+
return err;
|
|
32
|
+
return new NonErrorThrown(err);
|
|
33
|
+
}
|
|
34
|
+
exports.ensureError = ensureError;
|
|
35
|
+
class NonErrorThrown extends Error {
|
|
36
|
+
constructor(value) {
|
|
37
|
+
super('Non error object thrown');
|
|
38
|
+
this.value = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.NonErrorThrown = NonErrorThrown;
|
|
42
|
+
//# sourceMappingURL=error-handling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handling.js","sourceRoot":"","sources":["../../src/util/error-handling.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AACjD,qCAAgD;AAGhD,SAAgB,eAAe,CAAC,GAAW,EAAE,GAAiB,EAAE,QAAkB,iBAAQ,CAAC,KAAK;IAC5F,IAAI,GAAG,CAAC,KAAK,GAAG,KAAK;QAAE,OAAM;IAC7B,IAAI,GAAG,GAAG,IAAA,oBAAU,EAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAChC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE;QACb,oBAAoB,EAAE,GAAG,CAAC,aAAa;QACvC,WAAW,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;QAChC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI;KACjC,EAAE,GAAG,CAAC,CAAA;AACX,CAAC;AARD,0CAQC;AAGD,SAAgB,gBAAgB,CAAC,GAAW;IACxC,OAAO,UAAS,GAAG;QACf,MAAM,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACnC,CAAC,CAAA;AACL,CAAC;AAJD,4CAIC;AAGD,SAAgB,eAAe,CAAC,KAAc,EAAE,GAAW;IACvD,IAAI,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACrB,OAAO,CAAC,CAAA;AACZ,CAAC;AAJD,0CAIC;AAGD,SAAgB,WAAW,CAAC,GAAY;IACpC,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAA;IACpC,OAAO,IAAI,cAAc,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC;AAHD,kCAGC;AAGD,MAAa,cAAe,SAAQ,KAAK;IACrC,YAA4B,KAAc;QACtC,KAAK,CAAC,yBAAyB,CAAC,CAAA;QADR,UAAK,GAAL,KAAK,CAAS;IAE1C,CAAC;CACJ;AAJD,wCAIC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExecutionResult } from 'graphql-ws';
|
|
2
|
+
import { ExecutionArgs } from 'graphql/execution/execute';
|
|
3
|
+
import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue';
|
|
4
|
+
export declare function executeWithLimit(maxQueries: number, args: ExecutionArgs): PromiseOrValue<ExecutionResult>;
|
|
5
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/util/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAA;AAC1C,OAAO,EAKH,aAAa,EAEhB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAC,cAAc,EAAC,MAAM,gCAAgC,CAAA;AAG7D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,cAAc,CAAC,eAAe,CAAC,CAuCzG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeWithLimit = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const execute_1 = require("graphql/execution/execute");
|
|
6
|
+
function executeWithLimit(maxQueries, args) {
|
|
7
|
+
(0, execute_1.assertValidExecutionArguments)(args.schema, args.document, args.variableValues);
|
|
8
|
+
let xtx = (0, execute_1.buildExecutionContext)(args.schema, args.document, args.rootValue, args.contextValue, args.variableValues, args.operationName, args.fieldResolver, args.typeResolver);
|
|
9
|
+
if (Array.isArray(xtx)) {
|
|
10
|
+
return { errors: xtx };
|
|
11
|
+
}
|
|
12
|
+
let etx = xtx;
|
|
13
|
+
if (etx.operation.operation == 'query') {
|
|
14
|
+
let query = (0, graphql_1.getOperationRootType)(etx.schema, etx.operation);
|
|
15
|
+
let fields = (0, execute_1.collectFields)(etx, query, etx.operation.selectionSet, Object.create(null), Object.create(null));
|
|
16
|
+
let fieldsCount = Object.keys(fields).length;
|
|
17
|
+
if (fieldsCount > maxQueries) {
|
|
18
|
+
return {
|
|
19
|
+
errors: [
|
|
20
|
+
new graphql_1.GraphQLError(`only ${maxQueries} root query fields allowed, but got ${fieldsCount}`)
|
|
21
|
+
]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return (0, execute_1.execute)(args);
|
|
26
|
+
}
|
|
27
|
+
exports.executeWithLimit = executeWithLimit;
|
|
28
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/util/execute.ts"],"names":[],"mappings":";;;AAAA,qCAA0D;AAE1D,uDAOkC;AAIlC,SAAgB,gBAAgB,CAAC,UAAkB,EAAE,IAAmB;IACpE,IAAA,uCAA6B,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IAE9E,IAAI,GAAG,GAAG,IAAA,+BAAqB,EAC3B,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,YAAY,CACpB,CAAA;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACpB,OAAO,EAAC,MAAM,EAAE,GAAG,EAAC,CAAA;KACvB;IAED,IAAI,GAAG,GAAG,GAAuB,CAAA;IACjC,IAAI,GAAG,CAAC,SAAS,CAAC,SAAS,IAAI,OAAO,EAAE;QACpC,IAAI,KAAK,GAAG,IAAA,8BAAoB,EAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;QAC3D,IAAI,MAAM,GAAG,IAAA,uBAAa,EACtB,GAAG,EACH,KAAK,EACL,GAAG,CAAC,SAAS,CAAC,YAAY,EAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EACnB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CACtB,CAAA;QACD,IAAI,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAA;QAC5C,IAAI,WAAW,GAAG,UAAU,EAAE;YAC1B,OAAO;gBACH,MAAM,EAAE;oBACJ,IAAI,sBAAY,CAAC,QAAQ,UAAU,uCAAuC,WAAW,EAAE,CAAC;iBAC3F;aACJ,CAAA;SACJ;KACJ;IAED,OAAO,IAAA,iBAAc,EAAC,IAAI,CAAC,CAAA;AAC/B,CAAC;AAvCD,4CAuCC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class LazyTransaction<T> {
|
|
2
|
+
private transact;
|
|
3
|
+
private closed;
|
|
4
|
+
private tx?;
|
|
5
|
+
constructor(transact: (f: (ctx: T) => Promise<void>) => Promise<void>);
|
|
6
|
+
get(): Promise<T>;
|
|
7
|
+
private startTransaction;
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=lazy-transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-transaction.d.ts","sourceRoot":"","sources":["../../src/util/lazy-transaction.ts"],"names":[],"mappings":"AAMA,qBAAa,eAAe,CAAC,CAAC;IAKd,OAAO,CAAC,QAAQ;IAJ5B,OAAO,CAAC,MAAM,CAAQ;IAEtB,OAAO,CAAC,EAAE,CAAC,CAAgB;gBAEP,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;IAGvE,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;YAST,gBAAgB;IAiBxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ/B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LazyTransaction = void 0;
|
|
4
|
+
class LazyTransaction {
|
|
5
|
+
constructor(transact) {
|
|
6
|
+
this.transact = transact;
|
|
7
|
+
this.closed = false;
|
|
8
|
+
}
|
|
9
|
+
async get() {
|
|
10
|
+
if (this.closed) {
|
|
11
|
+
throw new Error("Too late to request transaction");
|
|
12
|
+
}
|
|
13
|
+
this.tx = this.tx || this.startTransaction();
|
|
14
|
+
let { ctx } = await this.tx;
|
|
15
|
+
return ctx;
|
|
16
|
+
}
|
|
17
|
+
async startTransaction() {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
let promise = this.transact(ctx => {
|
|
20
|
+
return new Promise(close => {
|
|
21
|
+
resolve({
|
|
22
|
+
ctx,
|
|
23
|
+
close: () => {
|
|
24
|
+
close();
|
|
25
|
+
return promise;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
promise.catch(err => reject(err));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async close() {
|
|
34
|
+
this.closed = true;
|
|
35
|
+
if (this.tx) {
|
|
36
|
+
let tx = this.tx;
|
|
37
|
+
this.tx = undefined;
|
|
38
|
+
await tx.then(tx => tx.close());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.LazyTransaction = LazyTransaction;
|
|
43
|
+
//# sourceMappingURL=lazy-transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-transaction.js","sourceRoot":"","sources":["../../src/util/lazy-transaction.ts"],"names":[],"mappings":";;;AAMA,MAAa,eAAe;IAKxB,YAAoB,QAAyD;QAAzD,aAAQ,GAAR,QAAQ,CAAiD;QAJrE,WAAM,GAAG,KAAK,CAAA;IAKtB,CAAC;IAED,KAAK,CAAC,GAAG;QACL,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;SACrD;QACD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAA;QAC5C,IAAI,EAAC,GAAG,EAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAA;QACzB,OAAO,GAAG,CAAA;IACd,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAC9B,OAAO,IAAI,OAAO,CAAO,KAAK,CAAC,EAAE;oBAC7B,OAAO,CAAC;wBACJ,GAAG;wBACH,KAAK,EAAE,GAAG,EAAE;4BACR,KAAK,EAAE,CAAA;4BACP,OAAO,OAAO,CAAA;wBAClB,CAAC;qBACJ,CAAC,CAAA;gBACN,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;YACF,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,KAAK;QACP,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,IAAI,CAAC,EAAE,EAAE;YACT,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;YAChB,IAAI,CAAC,EAAE,GAAG,SAAS,CAAA;YACnB,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAA;SAClC;IACL,CAAC;CACJ;AA1CD,0CA0CC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Limit {
|
|
2
|
+
private error;
|
|
3
|
+
private value;
|
|
4
|
+
constructor(error: Error, value: number);
|
|
5
|
+
get left(): number;
|
|
6
|
+
check(cb: (left: number) => number): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class ResponseSizeLimit extends Limit {
|
|
9
|
+
constructor(maxNodes: number);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit.d.ts","sourceRoot":"","sources":["../../src/util/limit.ts"],"names":[],"mappings":"AAIA,qBAAa,KAAK;IACF,OAAO,CAAC,KAAK;IAAS,OAAO,CAAC,KAAK;gBAA3B,KAAK,EAAE,KAAK,EAAU,KAAK,EAAE,MAAM;IAIvD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI;CAS5C;AAOD,qBAAa,iBAAkB,SAAQ,KAAK;gBAC5B,QAAQ,EAAE,MAAM;CAG/B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ResponseSizeLimit = exports.Limit = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const graphql_1 = require("graphql");
|
|
9
|
+
class Limit {
|
|
10
|
+
constructor(error, value) {
|
|
11
|
+
this.error = error;
|
|
12
|
+
this.value = value;
|
|
13
|
+
(0, assert_1.default)(this.value > 0);
|
|
14
|
+
}
|
|
15
|
+
get left() {
|
|
16
|
+
return Math.max(this.value, 0);
|
|
17
|
+
}
|
|
18
|
+
check(cb) {
|
|
19
|
+
if (this.value < 0)
|
|
20
|
+
throw this.error;
|
|
21
|
+
let left = this.value - cb(this.value);
|
|
22
|
+
if (left < 0) {
|
|
23
|
+
throw this.error;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.value = left;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Limit = Limit;
|
|
31
|
+
const SIZE_LIMIT = new graphql_1.GraphQLError('response might exceed the size limit');
|
|
32
|
+
SIZE_LIMIT.stack = undefined;
|
|
33
|
+
class ResponseSizeLimit extends Limit {
|
|
34
|
+
constructor(maxNodes) {
|
|
35
|
+
super(SIZE_LIMIT, maxNodes);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ResponseSizeLimit = ResponseSizeLimit;
|
|
39
|
+
//# sourceMappingURL=limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit.js","sourceRoot":"","sources":["../../src/util/limit.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,qCAAoC;AAGpC,MAAa,KAAK;IACd,YAAoB,KAAY,EAAU,KAAa;QAAnC,UAAK,GAAL,KAAK,CAAO;QAAU,UAAK,GAAL,KAAK,CAAQ;QACnD,IAAA,gBAAM,EAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;IAC1B,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAClC,CAAC;IAED,KAAK,CAAC,EAA4B;QAC9B,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC;YAAE,MAAM,IAAI,CAAC,KAAK,CAAA;QACpC,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACtC,IAAI,IAAI,GAAG,CAAC,EAAE;YACV,MAAM,IAAI,CAAC,KAAK,CAAA;SACnB;aAAM;YACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;SACpB;IACL,CAAC;CACJ;AAlBD,sBAkBC;AAGD,MAAM,UAAU,GAAG,IAAI,sBAAY,CAAC,sCAAsC,CAAC,CAAA;AAC3E,UAAU,CAAC,KAAK,GAAG,SAAS,CAAA;AAG5B,MAAa,iBAAkB,SAAQ,KAAK;IACxC,YAAY,QAAgB;QACxB,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/B,CAAC;CACJ;AAJD,8CAIC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GraphQLResolveInfo, GraphQLSchema } from "graphql";
|
|
2
|
+
import { ResolveTree } from "graphql-parse-resolve-info";
|
|
3
|
+
export declare type ResolveTreeFields = {
|
|
4
|
+
[alias: string]: ResolveTree;
|
|
5
|
+
};
|
|
6
|
+
export interface ResolveTreeWithFields extends ResolveTree {
|
|
7
|
+
fields: ResolveTreeFields;
|
|
8
|
+
}
|
|
9
|
+
export declare function simplifyResolveTree(schema: GraphQLSchema, tree: ResolveTree, typeName: string): ResolveTreeWithFields;
|
|
10
|
+
export declare function getResolveTree(info: GraphQLResolveInfo): ResolveTree;
|
|
11
|
+
export declare function getResolveTree(info: GraphQLResolveInfo, typeName: string): ResolveTreeWithFields;
|
|
12
|
+
export declare function getTreeRequest(treeFields: ResolveTreeFields, fieldName: string): ResolveTree | undefined;
|
|
13
|
+
export declare function hasTreeRequest(treeFields: ResolveTreeFields, fieldName: string): boolean;
|
|
14
|
+
//# sourceMappingURL=resolve-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-tree.d.ts","sourceRoot":"","sources":["../../src/util/resolve-tree.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,kBAAkB,EAAE,aAAa,EAAC,MAAM,SAAS,CAAA;AACzD,OAAO,EAGH,WAAW,EAEd,MAAM,4BAA4B,CAAA;AAGnC,oBAAY,iBAAiB,GAAG;IAC5B,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAA;CAC/B,CAAA;AAGD,MAAM,WAAW,qBAAsB,SAAQ,WAAW;IACtD,MAAM,EAAE,iBAAiB,CAAA;CAC5B;AAGD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CAIrH;AAGD,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,WAAW,CAAA;AACrE,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CAAA;AAiBjG,wBAAgB,cAAc,CAAC,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CASxG;AAGD,wBAAgB,cAAc,CAAC,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAMxF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hasTreeRequest = exports.getTreeRequest = exports.getResolveTree = exports.simplifyResolveTree = void 0;
|
|
7
|
+
const apollo_server_core_1 = require("apollo-server-core");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const graphql_parse_resolve_info_1 = require("graphql-parse-resolve-info");
|
|
10
|
+
function simplifyResolveTree(schema, tree, typeName) {
|
|
11
|
+
let type = schema.getType(typeName);
|
|
12
|
+
(0, assert_1.default)(type != null);
|
|
13
|
+
return (0, graphql_parse_resolve_info_1.simplifyParsedResolveInfoFragmentWithType)(tree, type);
|
|
14
|
+
}
|
|
15
|
+
exports.simplifyResolveTree = simplifyResolveTree;
|
|
16
|
+
function getResolveTree(info, typeName) {
|
|
17
|
+
let tree = (0, graphql_parse_resolve_info_1.parseResolveInfo)(info);
|
|
18
|
+
(0, assert_1.default)(isResolveTree(tree));
|
|
19
|
+
if (typeName) {
|
|
20
|
+
return simplifyResolveTree(info.schema, tree, typeName);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return tree;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.getResolveTree = getResolveTree;
|
|
27
|
+
function isResolveTree(resolveInfo) {
|
|
28
|
+
return resolveInfo != null && resolveInfo.fieldsByTypeName != null;
|
|
29
|
+
}
|
|
30
|
+
function getTreeRequest(treeFields, fieldName) {
|
|
31
|
+
let req;
|
|
32
|
+
for (let alias in treeFields) {
|
|
33
|
+
let e = treeFields[alias];
|
|
34
|
+
if (e.name != fieldName)
|
|
35
|
+
continue;
|
|
36
|
+
if (req != null)
|
|
37
|
+
throw new apollo_server_core_1.UserInputError(`multiple aliases for field '${fieldName}' are not supported`);
|
|
38
|
+
req = e;
|
|
39
|
+
}
|
|
40
|
+
return req;
|
|
41
|
+
}
|
|
42
|
+
exports.getTreeRequest = getTreeRequest;
|
|
43
|
+
function hasTreeRequest(treeFields, fieldName) {
|
|
44
|
+
for (let alias in treeFields) {
|
|
45
|
+
let e = treeFields[alias];
|
|
46
|
+
if (e.name == fieldName)
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
exports.hasTreeRequest = hasTreeRequest;
|
|
52
|
+
//# sourceMappingURL=resolve-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-tree.js","sourceRoot":"","sources":["../../src/util/resolve-tree.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAiD;AACjD,oDAA2B;AAE3B,2EAKmC;AAanC,SAAgB,mBAAmB,CAAC,MAAqB,EAAE,IAAiB,EAAE,QAAgB;IAC1F,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACnC,IAAA,gBAAM,EAAC,IAAI,IAAI,IAAI,CAAC,CAAA;IACpB,OAAO,IAAA,sEAAyC,EAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAChE,CAAC;AAJD,kDAIC;AAKD,SAAgB,cAAc,CAAC,IAAwB,EAAE,QAAiB;IACtE,IAAI,IAAI,GAAG,IAAA,6CAAgB,EAAC,IAAI,CAAC,CAAA;IACjC,IAAA,gBAAM,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;IAC3B,IAAI,QAAQ,EAAE;QACV,OAAO,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;KAC1D;SAAM;QACH,OAAO,IAAI,CAAA;KACd;AACL,CAAC;AARD,wCAQC;AAGD,SAAS,aAAa,CAAC,WAA8D;IACjF,OAAO,WAAW,IAAI,IAAI,IAAI,WAAW,CAAC,gBAAgB,IAAI,IAAI,CAAA;AACtE,CAAC;AAGD,SAAgB,cAAc,CAAC,UAA6B,EAAE,SAAiB;IAC3E,IAAI,GAA4B,CAAA;IAChC,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;QAC1B,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QACzB,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS;YAAE,SAAQ;QACjC,IAAI,GAAG,IAAI,IAAI;YAAE,MAAM,IAAI,mCAAc,CAAC,+BAA+B,SAAS,qBAAqB,CAAC,CAAA;QACxG,GAAG,GAAG,CAAC,CAAA;KACV;IACD,OAAO,GAAG,CAAA;AACd,CAAC;AATD,wCASC;AAGD,SAAgB,cAAc,CAAC,UAA6B,EAAE,SAAiB;IAC3E,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;QAC1B,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QACzB,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS;YAAE,OAAO,IAAI,CAAA;KACvC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAND,wCAMC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export declare function toQueryListField(entityName: string): string;
|
|
2
1
|
export declare function toColumn(gqlFieldName: string): string;
|
|
3
2
|
export declare function toFkColumn(gqlFieldName: string): string;
|
|
4
3
|
export declare function toTable(entityName: string): string;
|
|
5
4
|
export declare function ensureArray<T>(item: T | T[]): T[];
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function toInt(val: number | string): number;
|
|
5
|
+
export declare function toSafeInteger(s: number | string): number;
|
|
8
6
|
export declare function invalidFormat(type: string, value: string): Error;
|
|
7
|
+
export declare function identity<T>(x: T): T;
|
|
9
8
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util/util.ts"],"names":[],"mappings":"AAIA,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAErD;AAGD,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEvD;AAGD,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAElD;AAGD,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAEjD;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIxD;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAEhE;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAEnC"}
|
|
@@ -3,13 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.identity = exports.invalidFormat = exports.toSafeInteger = exports.ensureArray = exports.toTable = exports.toFkColumn = exports.toColumn = void 0;
|
|
7
7
|
const util_naming_1 = require("@subsquid/util-naming");
|
|
8
8
|
const assert_1 = __importDefault(require("assert"));
|
|
9
|
-
function toQueryListField(entityName) {
|
|
10
|
-
return (0, util_naming_1.toPlural)((0, util_naming_1.toCamelCase)(entityName));
|
|
11
|
-
}
|
|
12
|
-
exports.toQueryListField = toQueryListField;
|
|
13
9
|
function toColumn(gqlFieldName) {
|
|
14
10
|
return (0, util_naming_1.toSnakeCase)(gqlFieldName);
|
|
15
11
|
}
|
|
@@ -26,18 +22,18 @@ function ensureArray(item) {
|
|
|
26
22
|
return Array.isArray(item) ? item : [item];
|
|
27
23
|
}
|
|
28
24
|
exports.ensureArray = ensureArray;
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
exports.unsupportedCase = unsupportedCase;
|
|
33
|
-
function toInt(val) {
|
|
34
|
-
let i = parseInt(val);
|
|
35
|
-
(0, assert_1.default)(!isNaN(i) && isFinite(i));
|
|
25
|
+
function toSafeInteger(s) {
|
|
26
|
+
let i = parseInt(s, 10);
|
|
27
|
+
(0, assert_1.default)(Number.isSafeInteger(i));
|
|
36
28
|
return i;
|
|
37
29
|
}
|
|
38
|
-
exports.
|
|
30
|
+
exports.toSafeInteger = toSafeInteger;
|
|
39
31
|
function invalidFormat(type, value) {
|
|
40
32
|
return new TypeError(`Not a ${type}: ${value}`);
|
|
41
33
|
}
|
|
42
34
|
exports.invalidFormat = invalidFormat;
|
|
35
|
+
function identity(x) {
|
|
36
|
+
return x;
|
|
37
|
+
}
|
|
38
|
+
exports.identity = identity;
|
|
43
39
|
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util/util.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAiD;AACjD,oDAA2B;AAG3B,SAAgB,QAAQ,CAAC,YAAoB;IACzC,OAAO,IAAA,yBAAW,EAAC,YAAY,CAAC,CAAA;AACpC,CAAC;AAFD,4BAEC;AAGD,SAAgB,UAAU,CAAC,YAAoB;IAC3C,OAAO,IAAA,yBAAW,EAAC,YAAY,CAAC,GAAG,KAAK,CAAA;AAC5C,CAAC;AAFD,gCAEC;AAGD,SAAgB,OAAO,CAAC,UAAkB;IACtC,OAAO,IAAA,yBAAW,EAAC,UAAU,CAAC,CAAA;AAClC,CAAC;AAFD,0BAEC;AAGD,SAAgB,WAAW,CAAI,IAAa;IACxC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAC9C,CAAC;AAFD,kCAEC;AAGD,SAAgB,aAAa,CAAC,CAAkB;IAC5C,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAW,EAAE,EAAE,CAAC,CAAA;IACjC,IAAA,gBAAM,EAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/B,OAAO,CAAC,CAAA;AACZ,CAAC;AAJD,sCAIC;AAGD,SAAgB,aAAa,CAAC,IAAY,EAAE,KAAa;IACrD,OAAO,IAAI,SAAS,CAAC,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAA;AACnD,CAAC;AAFD,sCAEC;AAGD,SAAgB,QAAQ,CAAI,CAAI;IAC5B,OAAO,CAAC,CAAA;AACZ,CAAC;AAFD,4BAEC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subsquid/openreader",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "GraphQL server for
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "GraphQL server for postgres-compatible databases",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
|
-
"opencrud"
|
|
7
|
+
"opencrud",
|
|
8
|
+
"postgres"
|
|
8
9
|
],
|
|
9
10
|
"license": "GPL-3.0-or-later",
|
|
10
11
|
"repository": "git@github.com:subsquid/squid.git",
|
|
@@ -16,29 +17,36 @@
|
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
18
19
|
"bin",
|
|
19
|
-
"
|
|
20
|
+
"lib",
|
|
20
21
|
"src"
|
|
21
22
|
],
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@graphql-tools/merge": "^8",
|
|
24
|
-
"@
|
|
25
|
-
"@subsquid/
|
|
25
|
+
"@subsquid/graphiql-console": "^0.3.0",
|
|
26
|
+
"@subsquid/logger": "^0.1.0",
|
|
26
27
|
"@subsquid/util-internal": "^0.0.1",
|
|
27
|
-
"@subsquid/util-internal-
|
|
28
|
-
"@subsquid/util-naming": "^0.0.1",
|
|
28
|
+
"@subsquid/util-internal-commander": "^0.0.0",
|
|
29
29
|
"@subsquid/util-internal-hex": "^0.0.1",
|
|
30
|
+
"@subsquid/util-internal-http-server": "^0.1.0",
|
|
31
|
+
"@subsquid/util-naming": "^0.0.1",
|
|
30
32
|
"apollo-server-core": "^3.9.0",
|
|
31
33
|
"apollo-server-express": "^3.9.0",
|
|
34
|
+
"commander": "^9.3.0",
|
|
35
|
+
"deep-equal": "^2.0.5",
|
|
32
36
|
"express": "^4.18.1",
|
|
33
37
|
"graphql": "^15.8.0",
|
|
34
38
|
"graphql-parse-resolve-info": "^4.12.3",
|
|
35
|
-
"
|
|
39
|
+
"graphql-ws": "^5.9.1",
|
|
40
|
+
"pg": "^8.7.3",
|
|
41
|
+
"ws": "^8.8.1"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
44
|
+
"@types/deep-equal": "^1.0.1",
|
|
38
45
|
"@types/express": "^4.17.13",
|
|
39
46
|
"@types/mocha": "^9.1.1",
|
|
40
47
|
"@types/node": "^16.11.41",
|
|
41
|
-
"@types/pg": "8.6.5",
|
|
48
|
+
"@types/pg": "^8.6.5",
|
|
49
|
+
"@types/ws": "^8.5.3",
|
|
42
50
|
"dotenv": "^10.0.0",
|
|
43
51
|
"expect": "^27.5.1",
|
|
44
52
|
"gql-test-client": "^0.0.0",
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {Dialect} from './dialect'
|
|
2
|
+
import {Query} from './sql/query'
|
|
3
|
+
import {Limit} from './util/limit'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface Context {
|
|
7
|
+
openreader: OpenreaderContext
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export interface OpenreaderContext {
|
|
12
|
+
dialect: Dialect
|
|
13
|
+
executeQuery<T>(query: Query<T>): Promise<T>
|
|
14
|
+
subscription<T>(query: Query<T>): AsyncIterable<T>
|
|
15
|
+
responseSizeLimit?: Limit
|
|
16
|
+
subscriptionResponseSizeLimit?: Limit
|
|
17
|
+
}
|
package/src/db.ts
CHANGED
|
@@ -1,83 +1,72 @@
|
|
|
1
|
-
import type {ClientBase, Pool
|
|
1
|
+
import type {ClientBase, Pool} from "pg"
|
|
2
|
+
import {OpenreaderContext} from "./context"
|
|
3
|
+
import {Dialect} from "./dialect"
|
|
4
|
+
import {Query} from "./sql/query"
|
|
5
|
+
import {Subscription} from "./subscription"
|
|
6
|
+
import {withErrorContext} from "./util/error-handling"
|
|
7
|
+
import {LazyTransaction} from "./util/lazy-transaction"
|
|
2
8
|
|
|
3
9
|
|
|
4
10
|
export interface Database {
|
|
5
11
|
query(sql: string, parameters?: any[]): Promise<any[][]>
|
|
6
|
-
escapeIdentifier(name: string): string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* This is an interface OpenReader uses to interact with underling database.
|
|
12
|
-
*/
|
|
13
|
-
export interface Transaction {
|
|
14
|
-
get(): Promise<Database>
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
|
|
18
15
|
export class PgDatabase implements Database {
|
|
19
16
|
constructor(private client: ClientBase) {}
|
|
20
17
|
|
|
21
|
-
query(sql: string, parameters?: any[]): Promise<any[]> {
|
|
22
|
-
return this.client.query({text: sql, rowMode: 'array'}, parameters)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
escapeIdentifier(name: string): string {
|
|
26
|
-
return this.client.escapeIdentifier(name)
|
|
18
|
+
query(sql: string, parameters?: any[]): Promise<any[][]> {
|
|
19
|
+
return this.client.query({text: sql, rowMode: 'array'}, parameters)
|
|
20
|
+
.then(result => result.rows)
|
|
21
|
+
.catch(withErrorContext({sql, parameters}))
|
|
27
22
|
}
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
|
|
31
|
-
export class
|
|
32
|
-
private tx:
|
|
33
|
-
private
|
|
26
|
+
export class PoolOpenreaderContext implements OpenreaderContext {
|
|
27
|
+
private tx: LazyTransaction<Database>
|
|
28
|
+
private subscriptionPool: Pool
|
|
34
29
|
|
|
35
|
-
constructor(
|
|
30
|
+
constructor(
|
|
31
|
+
public readonly dialect: Dialect,
|
|
32
|
+
pool: Pool,
|
|
33
|
+
subscriptionPool?: Pool,
|
|
34
|
+
private subscriptionPollInterval: number = 1000
|
|
35
|
+
) {
|
|
36
|
+
this.tx = new LazyTransaction(cb => transact(pool, cb))
|
|
37
|
+
this.subscriptionPool = subscriptionPool || pool
|
|
38
|
+
}
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error('Too late to request transaction')
|
|
40
|
-
}
|
|
41
|
-
this.tx = this.tx || this.startTransaction()
|
|
42
|
-
let {db} = await this.tx
|
|
43
|
-
return db
|
|
40
|
+
close(): Promise<void> {
|
|
41
|
+
return this.tx.close()
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
client,
|
|
52
|
-
db: new PgDatabase(client)
|
|
53
|
-
}
|
|
54
|
-
} catch(e: any) {
|
|
55
|
-
client.release()
|
|
56
|
-
throw e
|
|
57
|
-
}
|
|
44
|
+
async executeQuery<T>(query: Query<T>): Promise<T> {
|
|
45
|
+
let db = await this.tx.get()
|
|
46
|
+
let result = await db.query(query.sql, query.params)
|
|
47
|
+
return query.map(result)
|
|
58
48
|
}
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} catch(e: any) {
|
|
66
|
-
// ignore
|
|
67
|
-
} finally {
|
|
68
|
-
client.release()
|
|
69
|
-
}
|
|
70
|
-
}) || Promise.resolve()
|
|
50
|
+
subscription<T>(query: Query<T>): AsyncIterable<T> {
|
|
51
|
+
return new Subscription(this.subscriptionPollInterval, () => transact(this.subscriptionPool, async db => {
|
|
52
|
+
let result = await db.query(query.sql, query.params)
|
|
53
|
+
return query.map(result)
|
|
54
|
+
}))
|
|
71
55
|
}
|
|
72
56
|
}
|
|
73
57
|
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
59
|
+
async function transact<T>(pool: Pool, cb: (db: Database) => Promise<T>): Promise<T> {
|
|
60
|
+
let client = await pool.connect()
|
|
61
|
+
try {
|
|
62
|
+
await client.query('START TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY')
|
|
63
|
+
try {
|
|
64
|
+
let db = new PgDatabase(client)
|
|
65
|
+
return await cb(db)
|
|
66
|
+
} finally {
|
|
67
|
+
await client.query('COMMIT').catch(() => {})
|
|
68
|
+
}
|
|
69
|
+
} finally {
|
|
70
|
+
client.release()
|
|
82
71
|
}
|
|
83
72
|
}
|
package/src/ir/args.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export interface EntityListArguments {
|
|
2
|
+
offset?: number
|
|
3
|
+
limit?: number
|
|
4
|
+
orderBy?: OrderBy
|
|
5
|
+
where?: Where
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export type Where = AndCondition | OrCondition | InCondition | SetCondition | RefCondition | BinaryCondition | UnaryCondition
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export interface AndCondition {
|
|
13
|
+
op: 'AND'
|
|
14
|
+
args: Where[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export interface OrCondition {
|
|
19
|
+
op: 'OR'
|
|
20
|
+
args: Where[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export interface SetCondition {
|
|
25
|
+
op: 'some' | 'every' | 'none'
|
|
26
|
+
field: string
|
|
27
|
+
where?: Where
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export interface RefCondition {
|
|
32
|
+
op: 'REF'
|
|
33
|
+
field: string
|
|
34
|
+
where: Where
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export interface InCondition {
|
|
39
|
+
op: 'in' | 'not_in'
|
|
40
|
+
field: string
|
|
41
|
+
values: unknown[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export interface BinaryCondition {
|
|
46
|
+
op: BinaryOp
|
|
47
|
+
field: string
|
|
48
|
+
value: unknown
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export interface UnaryCondition {
|
|
53
|
+
op: UnaryOp
|
|
54
|
+
field: string
|
|
55
|
+
yes: boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export type BinaryOp =
|
|
60
|
+
'eq' |
|
|
61
|
+
'not_eq' |
|
|
62
|
+
'gt' |
|
|
63
|
+
'gte' |
|
|
64
|
+
'lt' |
|
|
65
|
+
'lte' |
|
|
66
|
+
'contains' | 'not_contains' |
|
|
67
|
+
'containsInsensitive' | 'not_containsInsensitive' |
|
|
68
|
+
'startsWith' | 'not_startsWith' |
|
|
69
|
+
'endsWith' | 'not_endsWith' |
|
|
70
|
+
'containsAll' |
|
|
71
|
+
'containsAny' |
|
|
72
|
+
'containsNone' |
|
|
73
|
+
'jsonContains' |
|
|
74
|
+
'jsonHasKey'
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
export type UnaryOp = 'isNull'
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export interface OrderBy {
|
|
81
|
+
[field: string]: SortOrder | OrderBy
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
export type SortOrder = "ASC" | "DESC"
|