@restorecommerce/facade 0.3.20 → 0.5.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/CHANGELOG.md +44 -0
- package/codegen/index.d.ts +12 -0
- package/debug-run.ts +1 -0
- package/dist/gql/protos/graphql.d.ts +9 -9
- package/dist/gql/protos/graphql.js +142 -28
- package/dist/gql/protos/registry.d.ts +2 -2
- package/dist/gql/protos/registry.js +24 -9
- package/dist/gql/protos/types.d.ts +51 -6
- package/dist/modules/access-control/gql/types.d.ts +2 -2
- package/dist/modules/access-control/gql/types.js +5 -21
- package/dist/modules/catalog/gql/schema.generated.d.ts +85 -81
- package/dist/modules/catalog/gql/types.d.ts +2 -2
- package/dist/modules/catalog/gql/types.js +6 -26
- package/dist/modules/fulfillment/gql/schema.generated.d.ts +481 -468
- package/dist/modules/fulfillment/gql/schema.generated.js +11 -11
- package/dist/modules/fulfillment/gql/types.d.ts +2 -2
- package/dist/modules/fulfillment/gql/types.js +3 -11
- package/dist/modules/identity/gql/schema.generated.d.ts +193 -166
- package/dist/modules/identity/gql/types.d.ts +2 -2
- package/dist/modules/identity/gql/types.js +6 -26
- package/dist/modules/identity/oidc/in-memory-adapter.js +3 -3
- package/dist/modules/indexing/gql/federation.js +1 -1
- package/dist/modules/indexing/gql/schema.generated.d.ts +16 -16
- package/dist/modules/indexing/gql/schema.js +1 -1
- package/dist/modules/invoicing/gql/schema.generated.d.ts +482 -8
- package/dist/modules/invoicing/gql/schema.generated.js +8 -1
- package/dist/modules/invoicing/gql/types.d.ts +2 -2
- package/dist/modules/invoicing/gql/types.js +2 -6
- package/dist/modules/notification/gql/schema.generated.d.ts +64 -34
- package/dist/modules/notification/gql/types.d.ts +2 -2
- package/dist/modules/notification/gql/types.js +2 -6
- package/dist/modules/ordering/gql/schema.generated.d.ts +166 -0
- package/dist/modules/ordering/gql/types.d.ts +2 -2
- package/dist/modules/ordering/gql/types.js +2 -6
- package/dist/modules/ostorage/gql/types.d.ts +2 -2
- package/dist/modules/ostorage/gql/types.js +2 -6
- package/dist/modules/payment/gql/schema.generated.d.ts +18 -18
- package/dist/modules/payment/gql/types.d.ts +2 -2
- package/dist/modules/payment/gql/types.js +2 -6
- package/dist/modules/resource/gql/schema.generated.d.ts +404 -220
- package/dist/modules/resource/gql/schema.generated.js +8 -1
- package/dist/modules/resource/gql/types.d.ts +2 -2
- package/dist/modules/resource/gql/types.js +13 -61
- package/dist/modules/scheduling/gql/types.d.ts +2 -2
- package/dist/modules/scheduling/gql/types.js +2 -6
- package/package.json +43 -39
- package/tsconfig-base.json +4 -1
- package/tsconfig.lib.json +0 -3
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,50 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
# [0.5.0](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.4.1...@restorecommerce/facade@0.5.0) (2022-06-10)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* **facade:** fix building tests ([82485bf](https://github.com/restorecommerce/libs/commit/82485bfb7c6e19e0bc56f665538bf65d427a1178))
|
12
|
+
* fix merge issues ([cc37d83](https://github.com/restorecommerce/libs/commit/cc37d8356df3b494af8c6af9e39304a49073301c))
|
13
|
+
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* **facade:** support nested resolvers from proto options ([d319a5b](https://github.com/restorecommerce/libs/commit/d319a5bbf0066d9200d1c6bf38303461496bfa3a))
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
## [0.4.1](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.4.0...@restorecommerce/facade@0.4.1) (2022-05-16)
|
24
|
+
|
25
|
+
|
26
|
+
### Bug Fixes
|
27
|
+
|
28
|
+
* **facade:** force release ([9716dab](https://github.com/restorecommerce/libs/commit/9716dab905623b3204a7a9004887c0396234b7fd))
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
# [0.4.0](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.20...@restorecommerce/facade@0.4.0) (2022-05-16)
|
35
|
+
|
36
|
+
|
37
|
+
### Bug Fixes
|
38
|
+
|
39
|
+
* **facade:** fix build errors ([a0a4d62](https://github.com/restorecommerce/libs/commit/a0a4d6286f875419cff84555bd5f176e36661044))
|
40
|
+
|
41
|
+
|
42
|
+
### Features
|
43
|
+
|
44
|
+
* major version upgrades ([62461c1](https://github.com/restorecommerce/libs/commit/62461c1ef0eb5cd693dcca25b7f9c6f92e549818))
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
6
50
|
## [0.3.20](https://github.com/restorecommerce/libs/compare/@restorecommerce/facade@0.3.19...@restorecommerce/facade@0.3.20) (2022-05-09)
|
7
51
|
|
8
52
|
**Note:** Version bump only for package @restorecommerce/facade
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export interface GenerateSchemaTypingsArgs {
|
2
|
+
schema: any;
|
3
|
+
outputFile: string;
|
4
|
+
typescript?: {
|
5
|
+
[key: string]: any;
|
6
|
+
};
|
7
|
+
typescriptResolvers?: {
|
8
|
+
contextType?: string;
|
9
|
+
[key: string]: any;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
export declare function generateSchemaTypings({ schema, outputFile, typescript, typescriptResolvers }: GenerateSchemaTypingsArgs): Promise<void>;
|
package/debug-run.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { GraphQLInputField, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, ThunkObjMap } from
|
2
|
-
import { GraphQLEnumType, GraphQLFieldConfig, GraphQLFieldConfigMap, GraphQLInputObjectType, GraphQLInputType } from
|
3
|
-
import {
|
4
|
-
import { MethodDescriptorProto, ServiceDescriptorProto } from
|
1
|
+
import { GraphQLInputField, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, ThunkObjMap } from 'graphql';
|
2
|
+
import { GraphQLEnumType, GraphQLFieldConfig, GraphQLFieldConfigMap, GraphQLInputObjectType, GraphQLInputType } from 'graphql/type/definition';
|
3
|
+
import { ProtoMetadata, ServiceConfig, SubSpaceServiceConfig } from './types';
|
4
|
+
import { MethodDescriptorProto, ServiceDescriptorProto } from 'ts-proto-descriptors';
|
5
5
|
export declare const getGQLSchema: <TSource, TContext>(method: MethodDescriptorProto) => GraphQLFieldConfig<TSource, TContext, any>;
|
6
6
|
export declare const getGQLSchemas: <TSource, TContext>(service: ServiceDescriptorProto) => GraphQLFieldConfigMap<TSource, TContext>;
|
7
7
|
export declare const preprocessGQLInput: (data: any, model: GraphQLInputObjectType | GraphQLEnumType | GraphQLInputField | GraphQLInputType) => Promise<any>;
|
@@ -21,12 +21,12 @@ export declare const generateSchema: (setup: {
|
|
21
21
|
prefix: string;
|
22
22
|
namespace: string;
|
23
23
|
}[]) => GraphQLSchema;
|
24
|
-
export declare const getWhitelistBlacklistConfig: (metaService: ServiceDescriptorProto,
|
24
|
+
export declare const getWhitelistBlacklistConfig: (metaService: ServiceDescriptorProto, config: ServiceConfig, meta: ProtoMetadata, entity: string) => {
|
25
25
|
queries: Set<string>;
|
26
26
|
mutations: Set<string>;
|
27
27
|
};
|
28
|
-
export declare const getAndGenerateSchema: <TSource, TContext>(service: ServiceDescriptorProto, namespace: string, prefix: string, cfg: ServiceConfig,
|
29
|
-
export declare const getAndGenerateResolvers: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>, SRV = any, R = ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, NS extends keyof CTX = any>(service: ServiceDescriptorProto, namespace: NS, cfg: ServiceConfig,
|
30
|
-
export declare const generateSubServiceSchemas: (subServices:
|
31
|
-
export declare const generateSubServiceResolvers: <T, M extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, M>>(subServices:
|
28
|
+
export declare const getAndGenerateSchema: <TSource, TContext>(service: ServiceDescriptorProto, namespace: string, prefix: string, cfg: ServiceConfig, meta: ProtoMetadata) => GraphQLSchema;
|
29
|
+
export declare const getAndGenerateResolvers: <T extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, T>, SRV = any, R = ResolverFn<any, any, ServiceClient<CTX, keyof CTX, T>, any>, NS extends keyof CTX = any>(service: ServiceDescriptorProto, namespace: NS, cfg: ServiceConfig, meta: ProtoMetadata, subspace?: string | undefined, serviceKey?: string | undefined) => { [key in keyof SRV]: R; };
|
30
|
+
export declare const generateSubServiceSchemas: (subServices: ProtoMetadata[], config: SubSpaceServiceConfig, namespace: string, prefix: string) => GraphQLSchema;
|
31
|
+
export declare const generateSubServiceResolvers: <T, M extends Record<string, any>, CTX extends ServiceClient<CTX, keyof CTX, M>>(subServices: ProtoMetadata[], config: SubSpaceServiceConfig, namespace: string) => T;
|
32
32
|
export {};
|
@@ -8,6 +8,9 @@ const registry_1 = require("./registry");
|
|
8
8
|
const utils_1 = require("./utils");
|
9
9
|
const stream = require("stream");
|
10
10
|
const _ = require("lodash");
|
11
|
+
const rc_grpc_clients_1 = require("@restorecommerce/rc-grpc-clients");
|
12
|
+
const resource_base_1 = require("@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/resource_base");
|
13
|
+
const array_prototype_flat_1 = require("array.prototype.flat");
|
11
14
|
const typeCache = new Map();
|
12
15
|
const Mutate = ['Create', 'Update', 'Upsert'];
|
13
16
|
const inputMethodType = new Map();
|
@@ -19,14 +22,14 @@ const getGQLSchema = (method) => {
|
|
19
22
|
};
|
20
23
|
const responseTyping = (0, registry_1.getTyping)(method.outputType);
|
21
24
|
if (!responseTyping) {
|
22
|
-
throw Error(
|
25
|
+
throw Error('Method doesn\'t have registered typings: ' + method.outputType);
|
23
26
|
}
|
24
27
|
if (method.outputType !== '.google.protobuf.Empty') {
|
25
28
|
fields['details'] = {
|
26
29
|
type: responseTyping.output,
|
27
30
|
};
|
28
31
|
}
|
29
|
-
const outName =
|
32
|
+
const outName = 'Proto' + (0, utils_1.capitalizeProtoName)(method.outputType);
|
30
33
|
let out = typeCache.get(outName);
|
31
34
|
if (!out) {
|
32
35
|
out = new graphql_1.GraphQLObjectType({
|
@@ -37,7 +40,7 @@ const getGQLSchema = (method) => {
|
|
37
40
|
}
|
38
41
|
const typing = (0, registry_1.getTyping)(method.inputType);
|
39
42
|
if (!typing) {
|
40
|
-
throw Error(
|
43
|
+
throw Error('Method doesn\'t have registered typings: ' + method.inputType);
|
41
44
|
}
|
42
45
|
return {
|
43
46
|
type: out,
|
@@ -100,7 +103,7 @@ const preprocessGQLInput = async (data, model) => {
|
|
100
103
|
}
|
101
104
|
if (model instanceof definition_1.GraphQLScalarType) {
|
102
105
|
switch (model.name) {
|
103
|
-
case
|
106
|
+
case 'Upload':
|
104
107
|
if (typeof data !== 'object') {
|
105
108
|
return Buffer.from(data.toString(), 'utf8');
|
106
109
|
}
|
@@ -496,10 +499,19 @@ const generateSchema = (setup) => {
|
|
496
499
|
return new graphql_1.GraphQLSchema(config);
|
497
500
|
};
|
498
501
|
exports.generateSchema = generateSchema;
|
499
|
-
const getWhitelistBlacklistConfig = (metaService,
|
502
|
+
const getWhitelistBlacklistConfig = (metaService, config, meta, entity) => {
|
500
503
|
var _a, _b, _c, _d;
|
501
|
-
const
|
502
|
-
|
504
|
+
const queryList = [];
|
505
|
+
if (meta.options && meta.options.services && meta.options.services[metaService.name] && meta.options.services[metaService.name].methods) {
|
506
|
+
const methods = meta.options.services[metaService.name].methods;
|
507
|
+
for (const key of Object.keys(methods)) {
|
508
|
+
if ('is_query' in methods[key] && methods[key]['is_query']) {
|
509
|
+
queryList.push(key);
|
510
|
+
}
|
511
|
+
}
|
512
|
+
}
|
513
|
+
const mut = new Set(metaService.method.map(m => m.name).filter(key => queryList.indexOf(key) < 0));
|
514
|
+
const que = new Set(metaService.method.map(m => m.name).filter(key => queryList.indexOf(key) >= 0));
|
503
515
|
if (config[entity]) {
|
504
516
|
if ((_b = (_a = config[entity]) === null || _a === void 0 ? void 0 : _a.methods) === null || _b === void 0 ? void 0 : _b.whitelist) {
|
505
517
|
const whitelist = new Set(config[entity].methods.whitelist);
|
@@ -553,8 +565,8 @@ const getWhitelistBlacklistConfig = (metaService, queries, config, entity) => {
|
|
553
565
|
};
|
554
566
|
};
|
555
567
|
exports.getWhitelistBlacklistConfig = getWhitelistBlacklistConfig;
|
556
|
-
const getAndGenerateSchema = (service, namespace, prefix, cfg,
|
557
|
-
const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service,
|
568
|
+
const getAndGenerateSchema = (service, namespace, prefix, cfg, meta) => {
|
569
|
+
const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, cfg, meta, service.name);
|
558
570
|
const schemas = (0, exports.getGQLSchemas)(service);
|
559
571
|
Object.keys(schemas).forEach(key => {
|
560
572
|
(0, exports.registerResolverSchema)(namespace, key, schemas[key], !queries.has(key) && mutations.has(key), undefined, cfg);
|
@@ -562,8 +574,8 @@ const getAndGenerateSchema = (service, namespace, prefix, cfg, queryList) => {
|
|
562
574
|
return (0, exports.generateSchema)([{ prefix, namespace }]);
|
563
575
|
};
|
564
576
|
exports.getAndGenerateSchema = getAndGenerateSchema;
|
565
|
-
const getAndGenerateResolvers = (service, namespace, cfg,
|
566
|
-
const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service,
|
577
|
+
const getAndGenerateResolvers = (service, namespace, cfg, meta, subspace = undefined, serviceKey = undefined) => {
|
578
|
+
const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, cfg, meta, service.name);
|
567
579
|
const func = (0, exports.getGQLResolverFunctions)(service, namespace, serviceKey || subspace || namespace, cfg);
|
568
580
|
Object.keys(func).forEach(k => {
|
569
581
|
(0, exports.registerResolverFunction)(namespace, k, func[k], !queries.has(k) && mutations.has(k), subspace, service);
|
@@ -572,35 +584,137 @@ const getAndGenerateResolvers = (service, namespace, cfg, queryList, subspace =
|
|
572
584
|
};
|
573
585
|
exports.getAndGenerateResolvers = getAndGenerateResolvers;
|
574
586
|
const generateSubServiceSchemas = (subServices, config, namespace, prefix) => {
|
575
|
-
subServices.forEach((
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
587
|
+
subServices.forEach((meta) => {
|
588
|
+
meta.fileDescriptor.service.forEach(service => {
|
589
|
+
if (meta.options && meta.options.services && meta.options.services[service.name]) {
|
590
|
+
const subName = meta.options.services[service.name].options['service_name'];
|
591
|
+
const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, config, meta, subName);
|
592
|
+
const schemas = (0, exports.getGQLSchemas)(service);
|
593
|
+
Object.keys(schemas).forEach(key => {
|
594
|
+
(0, exports.registerResolverSchema)(config.root ? subName : namespace, key, schemas[key], !queries.has(key) && mutations.has(key), config.root ? undefined : subName, config);
|
595
|
+
});
|
596
|
+
}
|
580
597
|
});
|
581
598
|
});
|
582
599
|
if (config.root) {
|
583
|
-
return (0, exports.generateSchema)(subServices.map(
|
584
|
-
|
585
|
-
|
600
|
+
return (0, exports.generateSchema)((0, array_prototype_flat_1.default)(subServices.map(meta => {
|
601
|
+
return meta.fileDescriptor.service.map(service => {
|
602
|
+
if (meta.options && meta.options.services && meta.options.services[service.name]) {
|
603
|
+
const subName = meta.options.services[service.name].options['service_name'];
|
604
|
+
return {
|
605
|
+
prefix: prefix + subName.substr(0, 1).toUpperCase() + subName.substr(1).toLowerCase(),
|
606
|
+
namespace: subName
|
607
|
+
};
|
608
|
+
}
|
609
|
+
return null;
|
610
|
+
}).filter(s => s !== null);
|
586
611
|
})));
|
587
612
|
}
|
588
613
|
return (0, exports.generateSchema)([{ prefix, namespace }]);
|
589
614
|
};
|
590
615
|
exports.generateSubServiceSchemas = generateSubServiceSchemas;
|
591
616
|
const generateSubServiceResolvers = (subServices, config, namespace) => {
|
592
|
-
subServices.forEach((
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
617
|
+
subServices.forEach((meta) => {
|
618
|
+
meta.fileDescriptor.service.forEach(service => {
|
619
|
+
if (meta.options && meta.options.services && meta.options.services[service.name]) {
|
620
|
+
const subName = meta.options.services[service.name].options['service_name'];
|
621
|
+
const { mutations, queries } = (0, exports.getWhitelistBlacklistConfig)(service, config, meta, subName);
|
622
|
+
const func = (0, exports.getGQLResolverFunctions)(service, namespace, subName || namespace, config);
|
623
|
+
Object.keys(func).forEach(k => {
|
624
|
+
const regNamespace = config.root ? subName : namespace;
|
625
|
+
const regSubspace = config.root ? undefined : subName;
|
626
|
+
(0, exports.registerResolverFunction)(regNamespace, k, func[k], !queries.has(k) && mutations.has(k), regSubspace, service);
|
627
|
+
});
|
628
|
+
}
|
599
629
|
});
|
600
630
|
});
|
601
631
|
if (config.root) {
|
602
|
-
return (0, exports.generateResolver)(...subServices.map(
|
632
|
+
return (0, exports.generateResolver)(...(0, array_prototype_flat_1.default)(subServices.map(meta => {
|
633
|
+
return meta.fileDescriptor.service.map(service => {
|
634
|
+
if (meta.options && meta.options.services && meta.options.services[service.name]) {
|
635
|
+
return meta.options.services[service.name].options['service_name'];
|
636
|
+
}
|
637
|
+
return null;
|
638
|
+
}).filter(s => s !== null);
|
639
|
+
})));
|
603
640
|
}
|
604
|
-
|
641
|
+
const finalResolver = (0, exports.generateResolver)(namespace);
|
642
|
+
subServices.forEach((meta) => {
|
643
|
+
meta.fileDescriptor.service.forEach(service => {
|
644
|
+
if (meta.options && meta.options.messages) {
|
645
|
+
for (const key of Object.keys(meta.options.messages)) {
|
646
|
+
const message = meta.options.messages[key];
|
647
|
+
if (message.fields) {
|
648
|
+
const typing = (0, registry_1.getTyping)('.' + meta.fileDescriptor.package + '.' + key);
|
649
|
+
if (typing) {
|
650
|
+
const result = {};
|
651
|
+
for (const fieldName of Object.keys(message.fields)) {
|
652
|
+
const field = message.fields[fieldName];
|
653
|
+
if ('resolver' in field) {
|
654
|
+
const fieldJsonName = snakeToCamel(fieldName);
|
655
|
+
const resolver = field['resolver'];
|
656
|
+
// TODO This creates an N+1 problem!
|
657
|
+
result[resolver.fieldName] = async (parent, _, ctx) => {
|
658
|
+
if (!parent || !(fieldJsonName in parent) || parent[fieldJsonName] === undefined) {
|
659
|
+
return undefined;
|
660
|
+
}
|
661
|
+
const client = ctx[resolver.targetService].client;
|
662
|
+
const service = client[resolver.targetSubService];
|
663
|
+
const idList = Array.isArray(parent[fieldJsonName]) ? parent[fieldJsonName] : [parent[fieldJsonName]];
|
664
|
+
// TODO Support custom input messages
|
665
|
+
const req = rc_grpc_clients_1.ReadRequest.fromPartial({
|
666
|
+
filters: [{
|
667
|
+
filter: idList.map(id => ({
|
668
|
+
field: 'id',
|
669
|
+
operation: resource_base_1.Filter_Operation.eq,
|
670
|
+
value: id,
|
671
|
+
type: resource_base_1.Filter_ValueType.STRING
|
672
|
+
})),
|
673
|
+
operator: resource_base_1.FilterOp_Operator.or
|
674
|
+
}]
|
675
|
+
});
|
676
|
+
req.subject = (0, registry_1.getTyping)(types_1.authSubjectType).processor.fromPartial({});
|
677
|
+
const authToken = ctx.request.req.headers['authorization'];
|
678
|
+
if (authToken && authToken.startsWith('Bearer ')) {
|
679
|
+
req.subject.token = authToken.split(' ')[1];
|
680
|
+
}
|
681
|
+
const result = await service[resolver.targetMethod](req);
|
682
|
+
if (result && result.items && result.items.length) {
|
683
|
+
if (Array.isArray(parent[fieldJsonName])) {
|
684
|
+
return result.items.map((item) => item.payload);
|
685
|
+
}
|
686
|
+
else {
|
687
|
+
return result.items[0].payload;
|
688
|
+
}
|
689
|
+
}
|
690
|
+
return undefined;
|
691
|
+
};
|
692
|
+
}
|
693
|
+
}
|
694
|
+
finalResolver[typing.output.name] = result;
|
695
|
+
}
|
696
|
+
}
|
697
|
+
}
|
698
|
+
}
|
699
|
+
});
|
700
|
+
});
|
701
|
+
return finalResolver;
|
605
702
|
};
|
606
703
|
exports.generateSubServiceResolvers = generateSubServiceResolvers;
|
704
|
+
const snakeToCamel = (s) => {
|
705
|
+
return s
|
706
|
+
.split('_')
|
707
|
+
.map((word, i) => {
|
708
|
+
if (i === 0) {
|
709
|
+
// if first symbol is "_" then skip it
|
710
|
+
return word ? word[0] + word.substring(1).toLowerCase() : '';
|
711
|
+
}
|
712
|
+
else {
|
713
|
+
return capitalize(word.toLowerCase());
|
714
|
+
}
|
715
|
+
})
|
716
|
+
.join('');
|
717
|
+
};
|
718
|
+
const capitalize = (s) => {
|
719
|
+
return s.substring(0, 1).toUpperCase() + s.substring(1);
|
720
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { GraphQLEnumTypeConfig, GraphQLInputObjectTypeConfig, GraphQLObjectType, GraphQLObjectTypeConfig } from "graphql";
|
2
2
|
import { GraphQLEnumType, GraphQLInputObjectType, GraphQLScalarType } from "graphql/type/definition";
|
3
|
-
import { ProtoMetadata } from
|
3
|
+
import { ProtoMetadata, ProtoMetaMessageOptions } from './types';
|
4
4
|
import { DescriptorProto, EnumDescriptorProto, MethodDescriptorProto } from "ts-proto-descriptors";
|
5
5
|
export interface TypingData {
|
6
6
|
output: GraphQLObjectType | GraphQLEnumType | GraphQLScalarType;
|
@@ -16,7 +16,7 @@ export declare const registerPackagesRecursive: (...protoMetadata: ProtoMetadata
|
|
16
16
|
export declare const getRegisteredEnumTypings: () => string[];
|
17
17
|
export declare const getNameSpaceTypeName: (typeName: string) => string | undefined;
|
18
18
|
export declare const recursiveEnumCheck: (typeName: string, enumMap: Map<string, string>, prevFieldName: string, traversedFields: string[]) => Map<string, string>;
|
19
|
-
export declare const registerTyping: (protoPackage: string, message: DescriptorProto, methodDef: MethodDescriptorProto[], opts?: Omit<Readonly<GraphQLObjectTypeConfig<any, any>>, "fields"> | undefined, inputOpts?: Omit<Readonly<GraphQLInputObjectTypeConfig>, "fields"> | undefined) => void;
|
19
|
+
export declare const registerTyping: (protoPackage: string, message: DescriptorProto, methodDef: MethodDescriptorProto[], opts?: Omit<Readonly<GraphQLObjectTypeConfig<any, any>>, "fields"> | undefined, inputOpts?: Omit<Readonly<GraphQLInputObjectTypeConfig>, "fields"> | undefined, messageOptions?: ProtoMetaMessageOptions | undefined) => void;
|
20
20
|
export declare const registerEnumTyping: <T = {
|
21
21
|
[key: string]: any;
|
22
22
|
}>(protoPackage: string, message: EnumDescriptorProto, opts?: Omit<Readonly<GraphQLEnumTypeConfig>, "values"> | undefined) => void;
|
@@ -35,15 +35,15 @@ exports.IGoogleProtobufAny = new definition_1.GraphQLInputObjectType({
|
|
35
35
|
});
|
36
36
|
const DateTime = new definition_1.GraphQLScalarType({
|
37
37
|
name: 'DateTime',
|
38
|
-
description: `A date-time string at UTC, such as 2007-12-03T10:15:30Z,
|
39
|
-
compliant with the date-time format outlined in section 5.6 of
|
38
|
+
description: `A date-time string at UTC, such as 2007-12-03T10:15:30Z,
|
39
|
+
compliant with the date-time format outlined in section 5.6 of
|
40
40
|
the RFC 3339 profile of the ISO 8601 standard for representation
|
41
41
|
of dates and times using the Gregorian calendar.`,
|
42
42
|
});
|
43
43
|
const IDateTime = new definition_1.GraphQLScalarType({
|
44
44
|
name: 'IDateTime',
|
45
|
-
description: `A date-time string at UTC, such as 2007-12-03T10:15:30Z,
|
46
|
-
compliant with the date-time format outlined in section 5.6 of
|
45
|
+
description: `A date-time string at UTC, such as 2007-12-03T10:15:30Z,
|
46
|
+
compliant with the date-time format outlined in section 5.6 of
|
47
47
|
the RFC 3339 profile of the ISO 8601 standard for representation
|
48
48
|
of dates and times using the Gregorian calendar.`,
|
49
49
|
});
|
@@ -68,7 +68,7 @@ const registerPackagesRecursive = (...protoMetadata) => {
|
|
68
68
|
protoMetadata.forEach(meta => {
|
69
69
|
var _a, _b;
|
70
70
|
meta.dependencies && (0, exports.registerPackagesRecursive)(...meta.dependencies);
|
71
|
-
meta.fileDescriptor.messageType && registerMessageTypesRecursive(meta.fileDescriptor.package, (_a = meta.fileDescriptor.service[0]) === null || _a === void 0 ? void 0 : _a.method, ...meta.fileDescriptor.messageType);
|
71
|
+
meta.fileDescriptor.messageType && registerMessageTypesRecursive(meta.fileDescriptor.package, (_a = meta.fileDescriptor.service[0]) === null || _a === void 0 ? void 0 : _a.method, meta.options, ...meta.fileDescriptor.messageType);
|
72
72
|
(_b = meta.fileDescriptor.enumType) === null || _b === void 0 ? void 0 : _b.forEach((m) => {
|
73
73
|
(0, exports.registerEnumTyping)(meta.fileDescriptor.package, m);
|
74
74
|
});
|
@@ -126,16 +126,16 @@ const recursiveEnumCheck = (typeName, enumMap, prevFieldName, traversedFields) =
|
|
126
126
|
return enumMap;
|
127
127
|
};
|
128
128
|
exports.recursiveEnumCheck = recursiveEnumCheck;
|
129
|
-
const registerMessageTypesRecursive = (packageName, methodDef, ...types) => {
|
129
|
+
const registerMessageTypesRecursive = (packageName, methodDef, options, ...types) => {
|
130
130
|
types.forEach(m => {
|
131
|
-
(0, exports.registerTyping)(packageName, m, methodDef);
|
131
|
+
(0, exports.registerTyping)(packageName, m, methodDef, undefined, undefined, options && options.messages && options.messages[m.name]);
|
132
132
|
if (m.enumType) {
|
133
133
|
m.enumType.forEach((enumType) => {
|
134
134
|
(0, exports.registerEnumTyping)(packageName + '.' + m.name, enumType);
|
135
135
|
});
|
136
136
|
}
|
137
137
|
if (m.nestedType) {
|
138
|
-
registerMessageTypesRecursive(packageName + '.' + m.name, methodDef, ...m.nestedType);
|
138
|
+
registerMessageTypesRecursive(packageName + '.' + m.name, methodDef, options, ...m.nestedType);
|
139
139
|
}
|
140
140
|
});
|
141
141
|
};
|
@@ -153,7 +153,7 @@ const ModeType = new definition_1.GraphQLEnumType({
|
|
153
153
|
},
|
154
154
|
}
|
155
155
|
});
|
156
|
-
const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
156
|
+
const registerTyping = (protoPackage, message, methodDef, opts, inputOpts, messageOptions) => {
|
157
157
|
let insertMode = false;
|
158
158
|
let crudOperation = false;
|
159
159
|
const type = (protoPackage.startsWith('.') ? '' : '.') + protoPackage + '.' + message.name;
|
@@ -204,6 +204,21 @@ const registerTyping = (protoPackage, message, methodDef, opts, inputOpts) => {
|
|
204
204
|
type: resolvedMeta
|
205
205
|
};
|
206
206
|
}
|
207
|
+
if (messageOptions && messageOptions.fields) {
|
208
|
+
if (field.name in messageOptions.fields) {
|
209
|
+
const data = messageOptions.fields[field.name].resolver;
|
210
|
+
const resolved = resolveMeta(data.fieldName, {
|
211
|
+
type: ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_MESSAGE,
|
212
|
+
label: field.label,
|
213
|
+
typeName: data.targetType
|
214
|
+
}, type, name, false);
|
215
|
+
if (resolvedMeta !== null) {
|
216
|
+
result[data.fieldName] = {
|
217
|
+
type: resolved
|
218
|
+
};
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}
|
207
222
|
});
|
208
223
|
return result;
|
209
224
|
};
|
@@ -1,12 +1,62 @@
|
|
1
1
|
import { GrpcClientConfig } from "@restorecommerce/grpc-client";
|
2
|
-
import { FileDescriptorProto
|
2
|
+
import { FileDescriptorProto } from "ts-proto-descriptors";
|
3
3
|
export declare const authSubjectType = ".io.restorecommerce.auth.Subject";
|
4
|
+
export declare type ProtoMetaMessageOptions = {
|
5
|
+
options?: {
|
6
|
+
[key: string]: any;
|
7
|
+
};
|
8
|
+
fields?: {
|
9
|
+
[key: string]: {
|
10
|
+
[key: string]: any;
|
11
|
+
};
|
12
|
+
};
|
13
|
+
oneof?: {
|
14
|
+
[key: string]: {
|
15
|
+
[key: string]: any;
|
16
|
+
};
|
17
|
+
};
|
18
|
+
nested?: {
|
19
|
+
[key: string]: ProtoMetaMessageOptions;
|
20
|
+
};
|
21
|
+
};
|
4
22
|
export interface ProtoMetadata {
|
5
23
|
fileDescriptor: FileDescriptorProto;
|
6
24
|
references: {
|
7
25
|
[key: string]: any;
|
8
26
|
};
|
9
27
|
dependencies?: ProtoMetadata[];
|
28
|
+
options?: {
|
29
|
+
options?: {
|
30
|
+
[key: string]: any;
|
31
|
+
};
|
32
|
+
services?: {
|
33
|
+
[key: string]: {
|
34
|
+
options?: {
|
35
|
+
[key: string]: any;
|
36
|
+
};
|
37
|
+
methods?: {
|
38
|
+
[key: string]: {
|
39
|
+
[key: string]: any;
|
40
|
+
};
|
41
|
+
};
|
42
|
+
};
|
43
|
+
};
|
44
|
+
messages?: {
|
45
|
+
[key: string]: ProtoMetaMessageOptions;
|
46
|
+
};
|
47
|
+
enums?: {
|
48
|
+
[key: string]: {
|
49
|
+
options?: {
|
50
|
+
[key: string]: any;
|
51
|
+
};
|
52
|
+
values?: {
|
53
|
+
[key: string]: {
|
54
|
+
[key: string]: any;
|
55
|
+
};
|
56
|
+
};
|
57
|
+
};
|
58
|
+
};
|
59
|
+
};
|
10
60
|
}
|
11
61
|
export interface BlackListWhiteListConfig {
|
12
62
|
whitelist?: string[];
|
@@ -22,8 +72,3 @@ export interface ServiceConfig {
|
|
22
72
|
export interface SubSpaceServiceConfig extends ServiceConfig {
|
23
73
|
root: boolean;
|
24
74
|
}
|
25
|
-
export interface SubService {
|
26
|
-
service: ServiceDescriptorProto;
|
27
|
-
name: string;
|
28
|
-
queries: string[];
|
29
|
-
}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import {
|
1
|
+
import { ProtoMetadata } from '../../../gql/protos';
|
2
2
|
export declare function registerTypings(): void;
|
3
|
-
export declare const subServices:
|
3
|
+
export declare const subServices: ProtoMetadata[];
|
@@ -7,28 +7,12 @@ const policy_set_1 = require("@restorecommerce/rc-grpc-clients/dist/generated/io
|
|
7
7
|
const access_control_1 = require("@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/access_control");
|
8
8
|
const protos_1 = require("../../../gql/protos");
|
9
9
|
function registerTypings() {
|
10
|
-
(0, protos_1.registerPackagesRecursive)(
|
10
|
+
(0, protos_1.registerPackagesRecursive)(...exports.subServices);
|
11
11
|
}
|
12
12
|
exports.registerTypings = registerTypings;
|
13
13
|
exports.subServices = [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
},
|
19
|
-
{
|
20
|
-
name: 'policy',
|
21
|
-
service: policy_1.protoMetadata.fileDescriptor.service[0],
|
22
|
-
queries: ['Read']
|
23
|
-
},
|
24
|
-
{
|
25
|
-
name: 'rule',
|
26
|
-
service: rule_1.protoMetadata.fileDescriptor.service[0],
|
27
|
-
queries: ['Read']
|
28
|
-
},
|
29
|
-
{
|
30
|
-
name: 'policy_set',
|
31
|
-
service: policy_set_1.protoMetadata.fileDescriptor.service[0],
|
32
|
-
queries: ['Read']
|
33
|
-
},
|
14
|
+
access_control_1.protoMetadata,
|
15
|
+
policy_1.protoMetadata,
|
16
|
+
rule_1.protoMetadata,
|
17
|
+
policy_set_1.protoMetadata
|
34
18
|
];
|