@restorecommerce/facade 1.3.6 → 1.3.7
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/.eslintrc.cjs +1 -11
- package/CHANGELOG.md +12 -0
- package/codegen/tsconfig.codegen.tsbuildinfo +1 -0
- package/debug-run.ts +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +5 -4
- package/tsconfig-base.json +8 -19
- package/tsconfig.codegen.json +0 -1
- package/tsconfig.debug.json +1 -5
- package/tsconfig.generate.json +0 -3
- package/tsconfig.lib.json +1 -2
- package/tsconfig.test.json +1 -22
- package/codegen/index.d.ts +0 -12
- package/codegen/index.js +0 -43
- package/dist/gql/index.d.ts +0 -1
- package/dist/gql/index.js +0 -1
- package/dist/gql/protos/federation.d.ts +0 -6
- package/dist/gql/protos/federation.js +0 -46
- package/dist/gql/protos/graphql.d.ts +0 -11
- package/dist/gql/protos/graphql.js +0 -158
- package/dist/gql/protos/index.d.ts +0 -6
- package/dist/gql/protos/index.js +0 -6
- package/dist/gql/protos/registry.d.ts +0 -23
- package/dist/gql/protos/registry.js +0 -366
- package/dist/gql/protos/resolvers.d.ts +0 -9
- package/dist/gql/protos/resolvers.js +0 -479
- package/dist/gql/protos/schema.d.ts +0 -14
- package/dist/gql/protos/schema.js +0 -224
- package/dist/gql/protos/stream-to-async-iterator.d.ts +0 -50
- package/dist/gql/protos/stream-to-async-iterator.js +0 -190
- package/dist/gql/protos/types.d.ts +0 -96
- package/dist/gql/protos/types.js +0 -1
- package/dist/gql/protos/utils.d.ts +0 -18
- package/dist/gql/protos/utils.js +0 -133
- package/dist/gql/types/AccessControlTypes.d.ts +0 -6
- package/dist/gql/types/AccessControlTypes.js +0 -97
- package/dist/gql/types/DateType.d.ts +0 -2
- package/dist/gql/types/DateType.js +0 -29
- package/dist/gql/types/FilterType.d.ts +0 -2
- package/dist/gql/types/FilterType.js +0 -72
- package/dist/gql/types/MetaType.d.ts +0 -2
- package/dist/gql/types/MetaType.js +0 -25
- package/dist/gql/types/ScopeType.d.ts +0 -2
- package/dist/gql/types/ScopeType.js +0 -13
- package/dist/gql/types/SortType.d.ts +0 -3
- package/dist/gql/types/SortType.js +0 -30
- package/dist/gql/types/StatusType.d.ts +0 -2
- package/dist/gql/types/StatusType.js +0 -15
- package/dist/gql/types/index.d.ts +0 -7
- package/dist/gql/types/index.js +0 -7
- package/dist/index.d.ts +0 -66
- package/dist/index.js +0 -312
- package/dist/interfaces.d.ts +0 -54
- package/dist/interfaces.js +0 -6
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/middlewares/req-res-logger/index.d.ts +0 -14
- package/dist/middlewares/req-res-logger/index.js +0 -90
- package/dist/modules/access-control/gql/federation.d.ts +0 -2
- package/dist/modules/access-control/gql/federation.js +0 -13
- package/dist/modules/access-control/gql/schema.d.ts +0 -2
- package/dist/modules/access-control/gql/schema.generated.d.ts +0 -1124
- package/dist/modules/access-control/gql/schema.generated.js +0 -80
- package/dist/modules/access-control/gql/schema.js +0 -5
- package/dist/modules/access-control/gql/types.d.ts +0 -3
- package/dist/modules/access-control/gql/types.js +0 -14
- package/dist/modules/access-control/grpc/index.d.ts +0 -13
- package/dist/modules/access-control/grpc/index.js +0 -14
- package/dist/modules/access-control/index.d.ts +0 -2
- package/dist/modules/access-control/index.js +0 -26
- package/dist/modules/access-control/interfaces.d.ts +0 -15
- package/dist/modules/access-control/interfaces.js +0 -1
- package/dist/modules/catalog/gql/federation.d.ts +0 -2
- package/dist/modules/catalog/gql/federation.js +0 -13
- package/dist/modules/catalog/gql/schema.d.ts +0 -2
- package/dist/modules/catalog/gql/schema.generated.d.ts +0 -1503
- package/dist/modules/catalog/gql/schema.generated.js +0 -74
- package/dist/modules/catalog/gql/schema.js +0 -5
- package/dist/modules/catalog/gql/types.d.ts +0 -3
- package/dist/modules/catalog/gql/types.js +0 -16
- package/dist/modules/catalog/grpc/index.d.ts +0 -15
- package/dist/modules/catalog/grpc/index.js +0 -16
- package/dist/modules/catalog/index.d.ts +0 -2
- package/dist/modules/catalog/index.js +0 -26
- package/dist/modules/catalog/interfaces.d.ts +0 -16
- package/dist/modules/catalog/interfaces.js +0 -1
- package/dist/modules/facade-status/gql/index.d.ts +0 -1
- package/dist/modules/facade-status/gql/index.js +0 -11
- package/dist/modules/facade-status/gql/resolvers.d.ts +0 -2
- package/dist/modules/facade-status/gql/resolvers.js +0 -18
- package/dist/modules/facade-status/gql/schema.d.ts +0 -3
- package/dist/modules/facade-status/gql/schema.generated.d.ts +0 -109
- package/dist/modules/facade-status/gql/schema.generated.js +0 -1
- package/dist/modules/facade-status/gql/schema.js +0 -14
- package/dist/modules/facade-status/gql/types.d.ts +0 -2
- package/dist/modules/facade-status/gql/types.js +0 -10
- package/dist/modules/facade-status/index.d.ts +0 -2
- package/dist/modules/facade-status/index.js +0 -8
- package/dist/modules/facade-status/interfaces.d.ts +0 -4
- package/dist/modules/facade-status/interfaces.js +0 -1
- package/dist/modules/fulfillment/gql/federation.d.ts +0 -2
- package/dist/modules/fulfillment/gql/federation.js +0 -13
- package/dist/modules/fulfillment/gql/schema.d.ts +0 -2
- package/dist/modules/fulfillment/gql/schema.generated.d.ts +0 -1539
- package/dist/modules/fulfillment/gql/schema.generated.js +0 -79
- package/dist/modules/fulfillment/gql/schema.js +0 -5
- package/dist/modules/fulfillment/gql/types.d.ts +0 -3
- package/dist/modules/fulfillment/gql/types.js +0 -12
- package/dist/modules/fulfillment/grpc/index.d.ts +0 -9
- package/dist/modules/fulfillment/grpc/index.js +0 -10
- package/dist/modules/fulfillment/index.d.ts +0 -2
- package/dist/modules/fulfillment/index.js +0 -26
- package/dist/modules/fulfillment/interfaces.d.ts +0 -16
- package/dist/modules/fulfillment/interfaces.js +0 -1
- package/dist/modules/identity/api-key/api-key.d.ts +0 -11
- package/dist/modules/identity/api-key/api-key.js +0 -137
- package/dist/modules/identity/gql/federation.d.ts +0 -2
- package/dist/modules/identity/gql/federation.js +0 -5
- package/dist/modules/identity/gql/schema.d.ts +0 -2
- package/dist/modules/identity/gql/schema.generated.d.ts +0 -1661
- package/dist/modules/identity/gql/schema.generated.js +0 -75
- package/dist/modules/identity/gql/schema.js +0 -5
- package/dist/modules/identity/gql/types.d.ts +0 -3
- package/dist/modules/identity/gql/types.js +0 -18
- package/dist/modules/identity/grpc/index.d.ts +0 -15
- package/dist/modules/identity/grpc/index.js +0 -16
- package/dist/modules/identity/index.d.ts +0 -4
- package/dist/modules/identity/index.js +0 -54
- package/dist/modules/identity/interfaces.d.ts +0 -22
- package/dist/modules/identity/interfaces.js +0 -1
- package/dist/modules/identity/oauth/oauth.d.ts +0 -11
- package/dist/modules/identity/oauth/oauth.js +0 -170
- package/dist/modules/identity/oidc/adapter.d.ts +0 -4
- package/dist/modules/identity/oidc/adapter.js +0 -135
- package/dist/modules/identity/oidc/in-memory-adapter.d.ts +0 -16
- package/dist/modules/identity/oidc/in-memory-adapter.js +0 -85
- package/dist/modules/identity/oidc/index.d.ts +0 -18
- package/dist/modules/identity/oidc/index.js +0 -147
- package/dist/modules/identity/oidc/interfaces.d.ts +0 -73
- package/dist/modules/identity/oidc/interfaces.js +0 -7
- package/dist/modules/identity/oidc/password-grant.d.ts +0 -2
- package/dist/modules/identity/oidc/password-grant.js +0 -163
- package/dist/modules/identity/oidc/router.d.ts +0 -13
- package/dist/modules/identity/oidc/router.js +0 -164
- package/dist/modules/identity/oidc/templates.d.ts +0 -36
- package/dist/modules/identity/oidc/templates.js +0 -60
- package/dist/modules/identity/oidc/user.d.ts +0 -6
- package/dist/modules/identity/oidc/user.js +0 -91
- package/dist/modules/identity/oidc/utils.d.ts +0 -6
- package/dist/modules/identity/oidc/utils.js +0 -15
- package/dist/modules/index.d.ts +0 -13
- package/dist/modules/index.js +0 -13
- package/dist/modules/indexing/gql/federation.d.ts +0 -2
- package/dist/modules/indexing/gql/federation.js +0 -13
- package/dist/modules/indexing/gql/schema.d.ts +0 -2
- package/dist/modules/indexing/gql/schema.generated.d.ts +0 -226
- package/dist/modules/indexing/gql/schema.generated.js +0 -6
- package/dist/modules/indexing/gql/schema.js +0 -5
- package/dist/modules/indexing/gql/types.d.ts +0 -3
- package/dist/modules/indexing/gql/types.js +0 -8
- package/dist/modules/indexing/grpc/index.d.ts +0 -7
- package/dist/modules/indexing/grpc/index.js +0 -8
- package/dist/modules/indexing/index.d.ts +0 -2
- package/dist/modules/indexing/index.js +0 -26
- package/dist/modules/indexing/interfaces.d.ts +0 -13
- package/dist/modules/indexing/interfaces.js +0 -1
- package/dist/modules/invoicing/gql/federation.d.ts +0 -2
- package/dist/modules/invoicing/gql/federation.js +0 -13
- package/dist/modules/invoicing/gql/schema.d.ts +0 -2
- package/dist/modules/invoicing/gql/schema.generated.d.ts +0 -1150
- package/dist/modules/invoicing/gql/schema.generated.js +0 -75
- package/dist/modules/invoicing/gql/schema.js +0 -5
- package/dist/modules/invoicing/gql/types.d.ts +0 -3
- package/dist/modules/invoicing/gql/types.js +0 -8
- package/dist/modules/invoicing/grpc/index.d.ts +0 -7
- package/dist/modules/invoicing/grpc/index.js +0 -8
- package/dist/modules/invoicing/index.d.ts +0 -2
- package/dist/modules/invoicing/index.js +0 -26
- package/dist/modules/invoicing/interfaces.d.ts +0 -16
- package/dist/modules/invoicing/interfaces.js +0 -1
- package/dist/modules/master_data/gql/federation.d.ts +0 -2
- package/dist/modules/master_data/gql/federation.js +0 -13
- package/dist/modules/master_data/gql/schema.d.ts +0 -2
- package/dist/modules/master_data/gql/schema.generated.d.ts +0 -2520
- package/dist/modules/master_data/gql/schema.generated.js +0 -114
- package/dist/modules/master_data/gql/schema.js +0 -5
- package/dist/modules/master_data/gql/types.d.ts +0 -3
- package/dist/modules/master_data/gql/types.js +0 -32
- package/dist/modules/master_data/grpc/index.d.ts +0 -30
- package/dist/modules/master_data/grpc/index.js +0 -32
- package/dist/modules/master_data/index.d.ts +0 -2
- package/dist/modules/master_data/index.js +0 -26
- package/dist/modules/master_data/interfaces.d.ts +0 -16
- package/dist/modules/master_data/interfaces.js +0 -1
- package/dist/modules/notification/gql/federation.d.ts +0 -2
- package/dist/modules/notification/gql/federation.js +0 -13
- package/dist/modules/notification/gql/schema.d.ts +0 -2
- package/dist/modules/notification/gql/schema.generated.d.ts +0 -632
- package/dist/modules/notification/gql/schema.generated.js +0 -68
- package/dist/modules/notification/gql/schema.js +0 -5
- package/dist/modules/notification/gql/types.d.ts +0 -3
- package/dist/modules/notification/gql/types.js +0 -8
- package/dist/modules/notification/grpc/index.d.ts +0 -7
- package/dist/modules/notification/grpc/index.js +0 -8
- package/dist/modules/notification/index.d.ts +0 -2
- package/dist/modules/notification/index.js +0 -26
- package/dist/modules/notification/interfaces.d.ts +0 -16
- package/dist/modules/notification/interfaces.js +0 -1
- package/dist/modules/ordering/gql/federation.d.ts +0 -2
- package/dist/modules/ordering/gql/federation.js +0 -13
- package/dist/modules/ordering/gql/schema.d.ts +0 -2
- package/dist/modules/ordering/gql/schema.generated.d.ts +0 -1407
- package/dist/modules/ordering/gql/schema.generated.js +0 -91
- package/dist/modules/ordering/gql/schema.js +0 -5
- package/dist/modules/ordering/gql/types.d.ts +0 -3
- package/dist/modules/ordering/gql/types.js +0 -8
- package/dist/modules/ordering/grpc/index.d.ts +0 -7
- package/dist/modules/ordering/grpc/index.js +0 -8
- package/dist/modules/ordering/index.d.ts +0 -2
- package/dist/modules/ordering/index.js +0 -26
- package/dist/modules/ordering/interfaces.d.ts +0 -16
- package/dist/modules/ordering/interfaces.js +0 -1
- package/dist/modules/ostorage/gql/federation.d.ts +0 -2
- package/dist/modules/ostorage/gql/federation.js +0 -13
- package/dist/modules/ostorage/gql/schema.d.ts +0 -2
- package/dist/modules/ostorage/gql/schema.generated.d.ts +0 -846
- package/dist/modules/ostorage/gql/schema.generated.js +0 -31
- package/dist/modules/ostorage/gql/schema.js +0 -5
- package/dist/modules/ostorage/gql/types.d.ts +0 -3
- package/dist/modules/ostorage/gql/types.js +0 -8
- package/dist/modules/ostorage/grpc/index.d.ts +0 -7
- package/dist/modules/ostorage/grpc/index.js +0 -8
- package/dist/modules/ostorage/index.d.ts +0 -2
- package/dist/modules/ostorage/index.js +0 -46
- package/dist/modules/ostorage/interfaces.d.ts +0 -16
- package/dist/modules/ostorage/interfaces.js +0 -1
- package/dist/modules/ostorage/objectDownloadReqHandler.d.ts +0 -1
- package/dist/modules/ostorage/objectDownloadReqHandler.js +0 -134
- package/dist/modules/payment/gql/federation.d.ts +0 -2
- package/dist/modules/payment/gql/federation.js +0 -13
- package/dist/modules/payment/gql/schema.d.ts +0 -2
- package/dist/modules/payment/gql/schema.generated.d.ts +0 -647
- package/dist/modules/payment/gql/schema.generated.js +0 -156
- package/dist/modules/payment/gql/schema.js +0 -5
- package/dist/modules/payment/gql/types.d.ts +0 -3
- package/dist/modules/payment/gql/types.js +0 -8
- package/dist/modules/payment/grpc/index.d.ts +0 -7
- package/dist/modules/payment/grpc/index.js +0 -8
- package/dist/modules/payment/index.d.ts +0 -2
- package/dist/modules/payment/index.js +0 -26
- package/dist/modules/payment/interfaces.d.ts +0 -16
- package/dist/modules/payment/interfaces.js +0 -1
- package/dist/modules/scheduling/gql/federation.d.ts +0 -2
- package/dist/modules/scheduling/gql/federation.js +0 -13
- package/dist/modules/scheduling/gql/schema.d.ts +0 -2
- package/dist/modules/scheduling/gql/schema.generated.d.ts +0 -626
- package/dist/modules/scheduling/gql/schema.generated.js +0 -31
- package/dist/modules/scheduling/gql/schema.js +0 -5
- package/dist/modules/scheduling/gql/types.d.ts +0 -3
- package/dist/modules/scheduling/gql/types.js +0 -8
- package/dist/modules/scheduling/grpc/index.d.ts +0 -7
- package/dist/modules/scheduling/grpc/index.js +0 -8
- package/dist/modules/scheduling/index.d.ts +0 -2
- package/dist/modules/scheduling/index.js +0 -26
- package/dist/modules/scheduling/interfaces.d.ts +0 -16
- package/dist/modules/scheduling/interfaces.js +0 -1
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -14
@@ -1,479 +0,0 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
11
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
12
|
-
var m = o[Symbol.asyncIterator], i;
|
13
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
14
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
15
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
16
|
-
};
|
17
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
18
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
19
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
20
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
21
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
22
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
23
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
24
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
25
|
-
function fulfill(value) { resume("next", value); }
|
26
|
-
function reject(value) { resume("throw", value); }
|
27
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
28
|
-
};
|
29
|
-
import { authSubjectType } from './types.js';
|
30
|
-
import flat from 'array.prototype.flat';
|
31
|
-
import { getTyping } from './registry.js';
|
32
|
-
import { getWhitelistBlacklistConfig, Mutate, postProcessGQLValue, preprocessGQLInput, } from './graphql.js';
|
33
|
-
import { camelCase, capitalize, convertEnumToInt, decodeBufferFields, getKeys, snakeToCamel, useSubscriptions, getServiceName } from './utils.js';
|
34
|
-
import { ReadRequest } from '@restorecommerce/rc-grpc-clients';
|
35
|
-
import { Filter_Operation, Filter_ValueType, FilterOp_Operator } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/resource_base.js';
|
36
|
-
import * as stream from 'node:stream';
|
37
|
-
import _ from 'lodash';
|
38
|
-
import { Events } from '@restorecommerce/kafka-client';
|
39
|
-
import S2A from './stream-to-async-iterator.js';
|
40
|
-
const inputMethodType = new Map();
|
41
|
-
const streamToAsyncIterable = function (request, readableStreamKey) {
|
42
|
-
return __asyncGenerator(this, arguments, function* () {
|
43
|
-
var _a, e_1, _b, _c;
|
44
|
-
const readStream = _.clone(request[readableStreamKey]);
|
45
|
-
try {
|
46
|
-
for (var _d = true, _e = __asyncValues(new S2A(readStream)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
47
|
-
_c = _f.value;
|
48
|
-
_d = false;
|
49
|
-
const chunk = _c;
|
50
|
-
yield yield __await(Object.assign({}, request, { [readableStreamKey]: chunk }));
|
51
|
-
}
|
52
|
-
}
|
53
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
54
|
-
finally {
|
55
|
-
try {
|
56
|
-
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
|
57
|
-
}
|
58
|
-
finally { if (e_1) throw e_1.error; }
|
59
|
-
}
|
60
|
-
});
|
61
|
-
};
|
62
|
-
export const getGQLResolverFunctions = (service, key, serviceKey, cfg) => {
|
63
|
-
if (!service.method) {
|
64
|
-
return {};
|
65
|
-
}
|
66
|
-
return service.method.reduce((obj, method) => {
|
67
|
-
var _a, _b, _c, _d;
|
68
|
-
if ((_b = (_a = cfg[serviceKey]) === null || _a === void 0 ? void 0 : _a.methods) === null || _b === void 0 ? void 0 : _b.blacklist) {
|
69
|
-
const blacklistMethods = (_d = (_c = cfg[serviceKey]) === null || _c === void 0 ? void 0 : _c.methods) === null || _d === void 0 ? void 0 : _d.blacklist;
|
70
|
-
if (blacklistMethods.includes(method.name)) {
|
71
|
-
return {};
|
72
|
-
}
|
73
|
-
}
|
74
|
-
const typing = getTyping(method.inputType);
|
75
|
-
const outputTyping = getTyping(method.outputType);
|
76
|
-
if (!typing) {
|
77
|
-
throw Error(`Method '${method.name}' could not find input type: ${method.inputType}`);
|
78
|
-
}
|
79
|
-
if (!outputTyping) {
|
80
|
-
throw Error(`Method '${method.name}' could not find output type: ${method.outputType}`);
|
81
|
-
}
|
82
|
-
if (!('fromPartial' in typing.processor)) {
|
83
|
-
throw Error(`Method ${method.name} input type '${method.inputType}' does not contain 'fromPartial' function`);
|
84
|
-
}
|
85
|
-
let subjectField = null;
|
86
|
-
if (typing) {
|
87
|
-
for (let field of typing.meta.field) {
|
88
|
-
if (field.typeName === authSubjectType) {
|
89
|
-
subjectField = field.name;
|
90
|
-
break;
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
let methodName = method.name;
|
95
|
-
if (Mutate.indexOf(method.name) > -1) {
|
96
|
-
methodName = 'Mutate';
|
97
|
-
}
|
98
|
-
if (methodName in obj) {
|
99
|
-
return obj;
|
100
|
-
}
|
101
|
-
obj[methodName] = (args, context) => __awaiter(void 0, void 0, void 0, function* () {
|
102
|
-
var _e, _f;
|
103
|
-
const client = context[key].client;
|
104
|
-
const service = client[key];
|
105
|
-
try {
|
106
|
-
const converted = yield preprocessGQLInput(args.input, typing.input);
|
107
|
-
const scope = (_e = args === null || args === void 0 ? void 0 : args.input) === null || _e === void 0 ? void 0 : _e.scope;
|
108
|
-
let req = typing.processor.fromPartial(converted);
|
109
|
-
// convert enum strings to integers
|
110
|
-
req = convertEnumToInt(typing, req);
|
111
|
-
if (subjectField !== null) {
|
112
|
-
req.subject = getTyping(authSubjectType).processor.fromPartial({});
|
113
|
-
const authToken = context.request.req.headers['authorization'];
|
114
|
-
if (authToken && authToken.startsWith('Bearer ')) {
|
115
|
-
req.subject.token = authToken.split(' ')[1];
|
116
|
-
}
|
117
|
-
if (scope) {
|
118
|
-
req.subject.scope = scope;
|
119
|
-
}
|
120
|
-
}
|
121
|
-
let realMethod = method.name;
|
122
|
-
if (Mutate.indexOf(method.name) > -1) {
|
123
|
-
const mode = (_f = args === null || args === void 0 ? void 0 : args.input) === null || _f === void 0 ? void 0 : _f.mode;
|
124
|
-
if (!mode) {
|
125
|
-
throw new Error('Please specify mode');
|
126
|
-
}
|
127
|
-
if (mode === 'CREATE') {
|
128
|
-
realMethod = 'Create';
|
129
|
-
}
|
130
|
-
else if (mode === 'UPDATE') {
|
131
|
-
realMethod = 'Update';
|
132
|
-
}
|
133
|
-
else if (mode === 'UPSERT') {
|
134
|
-
realMethod = 'Upsert';
|
135
|
-
}
|
136
|
-
}
|
137
|
-
const methodFunc = service[camelCase(realMethod)] || service[realMethod];
|
138
|
-
if (method.clientStreaming) {
|
139
|
-
const readableStreamKey = Object.keys(req).filter((key) => {
|
140
|
-
if (req[key] instanceof stream.Stream.Readable) {
|
141
|
-
return key;
|
142
|
-
}
|
143
|
-
});
|
144
|
-
if (readableStreamKey.length > 0) {
|
145
|
-
req = streamToAsyncIterable(req, readableStreamKey[0]);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
const rawResult = yield methodFunc(req);
|
149
|
-
const result = postProcessGQLValue(rawResult, outputTyping.output);
|
150
|
-
const grpcClientConfig = cfg.client;
|
151
|
-
const bufferFields = getKeys(grpcClientConfig === null || grpcClientConfig === void 0 ? void 0 : grpcClientConfig.bufferFields);
|
152
|
-
if (result instanceof stream.Readable) {
|
153
|
-
let operationStatus = { code: 0, message: '' };
|
154
|
-
let aggregatedResponse = yield new Promise((resolve, reject) => {
|
155
|
-
let response = {};
|
156
|
-
let combinedChunks = {};
|
157
|
-
result.on('data', (chunk) => {
|
158
|
-
const chunkObj = _.cloneDeep(chunk);
|
159
|
-
if (!combinedChunks) {
|
160
|
-
combinedChunks = chunk;
|
161
|
-
}
|
162
|
-
else {
|
163
|
-
Object.assign(combinedChunks, chunk);
|
164
|
-
}
|
165
|
-
const existingBufferFields = _.intersection(Object.keys(chunk), bufferFields);
|
166
|
-
for (let bufferField of existingBufferFields) {
|
167
|
-
if (chunkObj[bufferField] && chunkObj[bufferField].value) {
|
168
|
-
if (!response[bufferField]) {
|
169
|
-
response[bufferField] = { value: [] };
|
170
|
-
}
|
171
|
-
if (response[bufferField] && response[bufferField].value && !_.isArray(response[bufferField].value)) {
|
172
|
-
response[bufferField].value = [];
|
173
|
-
}
|
174
|
-
let data = JSON.parse(chunkObj[bufferField].value.toString());
|
175
|
-
if (_.isArray(data)) {
|
176
|
-
for (let dataObj of data) {
|
177
|
-
response[bufferField].value.push(dataObj);
|
178
|
-
}
|
179
|
-
}
|
180
|
-
else {
|
181
|
-
response[bufferField].value.push(data);
|
182
|
-
}
|
183
|
-
}
|
184
|
-
}
|
185
|
-
});
|
186
|
-
result.on('error', (err) => {
|
187
|
-
console.error(err);
|
188
|
-
operationStatus.code = err.code ? err.code : 500;
|
189
|
-
operationStatus.message = err.message;
|
190
|
-
});
|
191
|
-
result.on('end', () => {
|
192
|
-
if (_.isEmpty(operationStatus.message)) {
|
193
|
-
operationStatus.code = 200;
|
194
|
-
operationStatus.message = 'success';
|
195
|
-
}
|
196
|
-
if (!_.isEmpty(response)) {
|
197
|
-
resolve(response);
|
198
|
-
}
|
199
|
-
else if (!_.isEmpty(combinedChunks)) {
|
200
|
-
resolve(combinedChunks);
|
201
|
-
}
|
202
|
-
});
|
203
|
-
});
|
204
|
-
return { details: aggregatedResponse, operationStatus };
|
205
|
-
}
|
206
|
-
if ('items' in result) {
|
207
|
-
let items = decodeBufferFields(result.items, bufferFields);
|
208
|
-
return {
|
209
|
-
details: {
|
210
|
-
items,
|
211
|
-
operationStatus: result.operationStatus // overall status
|
212
|
-
},
|
213
|
-
};
|
214
|
-
}
|
215
|
-
else {
|
216
|
-
return {
|
217
|
-
details: decodeBufferFields([result], bufferFields)[0]
|
218
|
-
};
|
219
|
-
}
|
220
|
-
}
|
221
|
-
catch (error) {
|
222
|
-
console.error(error);
|
223
|
-
return {
|
224
|
-
details: {
|
225
|
-
items: [],
|
226
|
-
operationStatus: {
|
227
|
-
code: error.code,
|
228
|
-
message: error.message
|
229
|
-
}
|
230
|
-
}
|
231
|
-
};
|
232
|
-
}
|
233
|
-
});
|
234
|
-
return obj;
|
235
|
-
}, {});
|
236
|
-
};
|
237
|
-
const namespaceResolverRegistry = new Map();
|
238
|
-
const subscriptionResolvers = {};
|
239
|
-
export const registerResolverFunction = (namespace, name, func, mutation = false, subspace = undefined, service) => {
|
240
|
-
if (!namespaceResolverRegistry.has(namespace)) {
|
241
|
-
namespaceResolverRegistry.set(namespace, new Map());
|
242
|
-
}
|
243
|
-
if (!namespaceResolverRegistry.get(namespace).has(mutation)) {
|
244
|
-
namespaceResolverRegistry.get(namespace).set(mutation, new Map());
|
245
|
-
}
|
246
|
-
let space = namespaceResolverRegistry.get(namespace).get(mutation);
|
247
|
-
if (subspace) {
|
248
|
-
if (!space.has(subspace)) {
|
249
|
-
space.set(subspace, new Map());
|
250
|
-
}
|
251
|
-
space = space.get(subspace);
|
252
|
-
}
|
253
|
-
if (space.has(name)) {
|
254
|
-
if (subspace) {
|
255
|
-
throw new Error(`Namespace "${namespace}"."${subspace}" already contains a function: ${name} (mutation: ${mutation})`);
|
256
|
-
}
|
257
|
-
else {
|
258
|
-
throw new Error(`Namespace "${namespace}" already contains a function: ${name} (mutation: ${mutation})`);
|
259
|
-
}
|
260
|
-
}
|
261
|
-
if (service) {
|
262
|
-
const key = (namespace === null || namespace === void 0 ? void 0 : namespace.toLocaleLowerCase()) + '.' + (subspace === null || subspace === void 0 ? void 0 : subspace.toLocaleLowerCase()) + '.' + (name === null || name === void 0 ? void 0 : name.toLocaleLowerCase());
|
263
|
-
const value = service.method.find((m) => m.name === name);
|
264
|
-
if (key && (value === null || value === void 0 ? void 0 : value.inputType)) {
|
265
|
-
inputMethodType.set(key, value.inputType);
|
266
|
-
}
|
267
|
-
}
|
268
|
-
space.set(name, func);
|
269
|
-
};
|
270
|
-
export const generateResolver = (...namespaces) => {
|
271
|
-
const queryResolvers = {};
|
272
|
-
const mutationResolvers = {};
|
273
|
-
namespaces.forEach(ns => {
|
274
|
-
if (!namespaceResolverRegistry.has(ns)) {
|
275
|
-
throw new Error(`Namespace "${ns}" has no registered functions`);
|
276
|
-
}
|
277
|
-
if (namespaceResolverRegistry.get(ns).has(false)) {
|
278
|
-
const res = {};
|
279
|
-
namespaceResolverRegistry.get(ns).get(false).forEach((value, key) => {
|
280
|
-
if (value instanceof Map) {
|
281
|
-
res[key] = Object.fromEntries(value);
|
282
|
-
}
|
283
|
-
else {
|
284
|
-
res[key] = value;
|
285
|
-
}
|
286
|
-
});
|
287
|
-
queryResolvers[ns] = () => res;
|
288
|
-
}
|
289
|
-
if (namespaceResolverRegistry.get(ns).has(true)) {
|
290
|
-
const res = {};
|
291
|
-
namespaceResolverRegistry.get(ns).get(true).forEach((value, key) => {
|
292
|
-
if (value instanceof Map) {
|
293
|
-
res[key] = Object.fromEntries(value);
|
294
|
-
}
|
295
|
-
else {
|
296
|
-
res[key] = value;
|
297
|
-
}
|
298
|
-
});
|
299
|
-
mutationResolvers[ns] = () => res;
|
300
|
-
}
|
301
|
-
});
|
302
|
-
const resolvers = {};
|
303
|
-
if (Object.keys(queryResolvers).length > 0) {
|
304
|
-
resolvers.Query = queryResolvers;
|
305
|
-
}
|
306
|
-
if (Object.keys(mutationResolvers).length > 0) {
|
307
|
-
resolvers.Mutation = mutationResolvers;
|
308
|
-
}
|
309
|
-
if (Object.keys(subscriptionResolvers).length > 0) {
|
310
|
-
resolvers.Subscription = subscriptionResolvers;
|
311
|
-
}
|
312
|
-
return resolvers;
|
313
|
-
};
|
314
|
-
export const generateSubServiceResolvers = (subServices, config, namespace) => {
|
315
|
-
subServices.forEach((meta) => {
|
316
|
-
var _a;
|
317
|
-
meta.fileDescriptor.service.forEach(service => {
|
318
|
-
if (service.name) {
|
319
|
-
// strip Service from end of String for sub service name
|
320
|
-
const subName = getServiceName(service.name);
|
321
|
-
const { mutations, queries } = getWhitelistBlacklistConfig(service, config, meta, subName);
|
322
|
-
const func = getGQLResolverFunctions(service, namespace, subName || namespace, config);
|
323
|
-
Object.keys(func).forEach(k => {
|
324
|
-
const regNamespace = config.root ? subName : namespace;
|
325
|
-
const regSubspace = config.root ? undefined : subName;
|
326
|
-
registerResolverFunction(regNamespace, k, func[k], !queries.has(k) && mutations.has(k), regSubspace, service);
|
327
|
-
});
|
328
|
-
}
|
329
|
-
});
|
330
|
-
if (useSubscriptions) {
|
331
|
-
Object.entries(((_a = meta.options) === null || _a === void 0 ? void 0 : _a.messages) || {}).forEach(([messageName, option]) => {
|
332
|
-
if (option.options && 'kafka_subscriber' in option.options) {
|
333
|
-
const kafkaSubscriber = option.options.kafka_subscriber;
|
334
|
-
const fieldName = namespace + capitalize(kafkaSubscriber.plural);
|
335
|
-
const baseMessageName = meta.fileDescriptor.package + '.' + messageName;
|
336
|
-
const typing = getTyping('.' + baseMessageName);
|
337
|
-
if (typing) {
|
338
|
-
subscriptionResolvers[fieldName] = {
|
339
|
-
// resolve: (parent, args, context, info) => {
|
340
|
-
// const obj = parent[fieldName];
|
341
|
-
// let missing = false;
|
342
|
-
// for (const selection of info.operation.selectionSet.selections) {
|
343
|
-
// if ('name' in selection && !(selection.name.value in obj)) {
|
344
|
-
// missing = true;
|
345
|
-
// break;
|
346
|
-
// }
|
347
|
-
// }
|
348
|
-
// if (!missing) {
|
349
|
-
// return obj;
|
350
|
-
// }
|
351
|
-
// // TODO Implement user lookup
|
352
|
-
// return obj;
|
353
|
-
// },
|
354
|
-
subscribe: (parent, args, context, info) => __awaiter(void 0, void 0, void 0, function* () {
|
355
|
-
const action = args.action || 'CREATED';
|
356
|
-
let event = kafkaSubscriber.created;
|
357
|
-
switch (action) {
|
358
|
-
case 'UPDATED':
|
359
|
-
event = kafkaSubscriber.updated;
|
360
|
-
break;
|
361
|
-
case 'DELETED':
|
362
|
-
event = kafkaSubscriber.deleted;
|
363
|
-
break;
|
364
|
-
}
|
365
|
-
const events = new Events({
|
366
|
-
provider: 'kafka',
|
367
|
-
kafka: Object.assign({}, context.kafkaConfig),
|
368
|
-
[event]: {
|
369
|
-
messageObject: baseMessageName
|
370
|
-
}
|
371
|
-
}, context.logger);
|
372
|
-
yield events.start();
|
373
|
-
const commandTopic = yield events.topic(kafkaSubscriber.topic);
|
374
|
-
let deferred = null;
|
375
|
-
const pending = [];
|
376
|
-
commandTopic.on(event, (message) => {
|
377
|
-
pending.push({ id: message.id });
|
378
|
-
deferred === null || deferred === void 0 ? void 0 : deferred.resolve(false);
|
379
|
-
});
|
380
|
-
return {
|
381
|
-
[Symbol.asyncIterator]() {
|
382
|
-
return this;
|
383
|
-
},
|
384
|
-
next: () => __awaiter(void 0, void 0, void 0, function* () {
|
385
|
-
if (pending.length) {
|
386
|
-
return { value: { [fieldName]: pending.shift() } };
|
387
|
-
}
|
388
|
-
return (yield new Promise((resolve, reject) => (deferred = { resolve, reject })))
|
389
|
-
? { done: true, value: undefined }
|
390
|
-
: { value: { [fieldName]: pending.shift() } };
|
391
|
-
}),
|
392
|
-
throw: (err) => __awaiter(void 0, void 0, void 0, function* () {
|
393
|
-
throw err;
|
394
|
-
}),
|
395
|
-
return: () => __awaiter(void 0, void 0, void 0, function* () {
|
396
|
-
yield events.stop();
|
397
|
-
return { done: true, value: undefined };
|
398
|
-
}),
|
399
|
-
};
|
400
|
-
})
|
401
|
-
};
|
402
|
-
}
|
403
|
-
}
|
404
|
-
});
|
405
|
-
}
|
406
|
-
});
|
407
|
-
if (config.root) {
|
408
|
-
return generateResolver(...flat(subServices.map(meta => {
|
409
|
-
return meta.fileDescriptor.service.map(service => {
|
410
|
-
if (service.name) {
|
411
|
-
return getServiceName(service.name);
|
412
|
-
}
|
413
|
-
return '';
|
414
|
-
}).filter(s => s !== '');
|
415
|
-
})));
|
416
|
-
}
|
417
|
-
const finalResolver = generateResolver(namespace);
|
418
|
-
subServices.forEach((meta) => {
|
419
|
-
meta.fileDescriptor.service.forEach(service => {
|
420
|
-
if (meta.options && meta.options.messages) {
|
421
|
-
for (const key of Object.keys(meta.options.messages)) {
|
422
|
-
const message = meta.options.messages[key];
|
423
|
-
if (message.fields) {
|
424
|
-
const typing = getTyping('.' + meta.fileDescriptor.package + '.' + key);
|
425
|
-
if (typing) {
|
426
|
-
const result = {};
|
427
|
-
for (const fieldName of Object.keys(message.fields)) {
|
428
|
-
const field = message.fields[fieldName];
|
429
|
-
if ('resolver' in field) {
|
430
|
-
const fieldJsonName = snakeToCamel(fieldName);
|
431
|
-
const resolver = field['resolver'];
|
432
|
-
// TODO This creates an N+1 problem!
|
433
|
-
result[resolver.fieldName] = (parent, _, ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
434
|
-
if (!parent || !(fieldJsonName in parent) || parent[fieldJsonName] === undefined) {
|
435
|
-
return undefined;
|
436
|
-
}
|
437
|
-
const client = ctx[resolver.targetService].client;
|
438
|
-
const service = client[resolver.targetSubService];
|
439
|
-
const idList = Array.isArray(parent[fieldJsonName]) ? parent[fieldJsonName] : [parent[fieldJsonName]];
|
440
|
-
// TODO Support custom input messages
|
441
|
-
const req = ReadRequest.fromPartial({
|
442
|
-
filters: [{
|
443
|
-
filter: idList.map(id => ({
|
444
|
-
field: 'id',
|
445
|
-
operation: Filter_Operation.eq,
|
446
|
-
value: id,
|
447
|
-
type: Filter_ValueType.STRING
|
448
|
-
})),
|
449
|
-
operator: FilterOp_Operator.or
|
450
|
-
}]
|
451
|
-
});
|
452
|
-
req.subject = getTyping(authSubjectType).processor.fromPartial({});
|
453
|
-
const authToken = ctx.request.req.headers['authorization'];
|
454
|
-
if (authToken && authToken.startsWith('Bearer ')) {
|
455
|
-
req.subject.token = authToken.split(' ')[1];
|
456
|
-
}
|
457
|
-
const methodFunc = service[camelCase(resolver.targetMethod)] || service[resolver.targetMethod];
|
458
|
-
const result = yield methodFunc(req);
|
459
|
-
if (result && result.items && result.items.length) {
|
460
|
-
if (Array.isArray(parent[fieldJsonName])) {
|
461
|
-
return result.items.map((item) => item.payload);
|
462
|
-
}
|
463
|
-
else {
|
464
|
-
return result.items[0].payload;
|
465
|
-
}
|
466
|
-
}
|
467
|
-
return undefined;
|
468
|
-
});
|
469
|
-
}
|
470
|
-
}
|
471
|
-
finalResolver[typing.output.name] = result;
|
472
|
-
}
|
473
|
-
}
|
474
|
-
}
|
475
|
-
}
|
476
|
-
});
|
477
|
-
});
|
478
|
-
return finalResolver;
|
479
|
-
};
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { type MethodDescriptorProto, type ServiceDescriptorProto } from 'ts-proto-descriptors';
|
2
|
-
import { type ProtoMetadata, type ServiceConfig, type SubSpaceServiceConfig } from './types.js';
|
3
|
-
import { GraphQLSchema, type ThunkObjMap } from 'graphql';
|
4
|
-
import { type GraphQLFieldConfig, type GraphQLFieldConfigMap } from 'graphql/type/definition.js';
|
5
|
-
export declare const getGQLSchema: <TSource, TContext>(method: MethodDescriptorProto) => GraphQLFieldConfig<TSource, TContext, any>;
|
6
|
-
export declare const getGQLSchemas: <TSource, TContext>(service: ServiceDescriptorProto) => GraphQLFieldConfigMap<TSource, TContext>;
|
7
|
-
type SchemaBaseOrSub = ThunkObjMap<GraphQLFieldConfig<any, any>> | Map<string, ThunkObjMap<GraphQLFieldConfig<any, any>>>;
|
8
|
-
export declare const registerResolverSchema: (namespace: string, name: string, schema: SchemaBaseOrSub, mutation: boolean | undefined, subspace: string | undefined, config: ServiceConfig) => void;
|
9
|
-
export declare const generateSchema: (setup: {
|
10
|
-
prefix: string;
|
11
|
-
namespace: string;
|
12
|
-
}[]) => GraphQLSchema;
|
13
|
-
export declare const generateSubServiceSchemas: (subServices: ProtoMetadata[], config: SubSpaceServiceConfig, namespace: string, prefix: string) => GraphQLSchema;
|
14
|
-
export {};
|