@revisium/endpoint 1.2.0 → 1.3.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.
Files changed (96) hide show
  1. package/dist/app.module.js +1 -1
  2. package/dist/app.module.js.map +1 -1
  3. package/dist/endpoint-microservice/app-options.module.d.ts +5 -0
  4. package/dist/endpoint-microservice/app-options.module.js +27 -0
  5. package/dist/endpoint-microservice/app-options.module.js.map +1 -0
  6. package/dist/endpoint-microservice/core-api/generated/api.d.ts +26 -23
  7. package/dist/endpoint-microservice/core-api/generated/api.js +5 -4
  8. package/dist/endpoint-microservice/core-api/generated/api.js.map +1 -1
  9. package/dist/endpoint-microservice/core-api/internal-core-api.service.d.ts +3 -1
  10. package/dist/endpoint-microservice/core-api/internal-core-api.service.js +12 -6
  11. package/dist/endpoint-microservice/core-api/internal-core-api.service.js.map +1 -1
  12. package/dist/endpoint-microservice/core-api/utils/transformFromPrismaToRowModel.d.ts +2 -2
  13. package/dist/endpoint-microservice/endpoint-microservice.module.d.ts +3 -1
  14. package/dist/endpoint-microservice/endpoint-microservice.module.js +24 -16
  15. package/dist/endpoint-microservice/endpoint-microservice.module.js.map +1 -1
  16. package/dist/endpoint-microservice/{endpoint-listener.controller.d.ts → events/endpoint-event.handler.d.ts} +4 -4
  17. package/dist/endpoint-microservice/events/endpoint-event.handler.js +35 -0
  18. package/dist/endpoint-microservice/events/endpoint-event.handler.js.map +1 -0
  19. package/dist/endpoint-microservice/events/endpoint-events.module.d.ts +2 -0
  20. package/dist/endpoint-microservice/events/endpoint-events.module.js +25 -0
  21. package/dist/endpoint-microservice/events/endpoint-events.module.js.map +1 -0
  22. package/dist/endpoint-microservice/events/endpoint-listener.controller.d.ts +12 -0
  23. package/dist/endpoint-microservice/{endpoint-listener.controller.js → events/endpoint-listener.controller.js} +17 -18
  24. package/dist/endpoint-microservice/events/endpoint-listener.controller.js.map +1 -0
  25. package/dist/endpoint-microservice/events/in-process-endpoint.listener.d.ts +12 -0
  26. package/dist/endpoint-microservice/events/in-process-endpoint.listener.js +53 -0
  27. package/dist/endpoint-microservice/events/in-process-endpoint.listener.js.map +1 -0
  28. package/dist/endpoint-microservice/graphql/graphql-endpoint.controller.d.ts +4 -2
  29. package/dist/endpoint-microservice/graphql/graphql-endpoint.controller.js +44 -12
  30. package/dist/endpoint-microservice/graphql/graphql-endpoint.controller.js.map +1 -1
  31. package/dist/endpoint-microservice/graphql/graphql-endpoint.service.d.ts +23 -7
  32. package/dist/endpoint-microservice/graphql/graphql-endpoint.service.js +61 -59
  33. package/dist/endpoint-microservice/graphql/graphql-endpoint.service.js.map +1 -1
  34. package/dist/endpoint-microservice/graphql/graphql-schema-converter/graphql-schema.converter.d.ts +3 -2
  35. package/dist/endpoint-microservice/graphql/graphql-schema-converter/graphql-schema.converter.js +26 -5
  36. package/dist/endpoint-microservice/graphql/graphql-schema-converter/graphql-schema.converter.js.map +1 -1
  37. package/dist/endpoint-microservice/graphql/graphql-schema-converter/types.d.ts +6 -1
  38. package/dist/endpoint-microservice/graphql/graphql-schema-converter/types.js +16 -1
  39. package/dist/endpoint-microservice/graphql/graphql-schema-converter/types.js.map +1 -1
  40. package/dist/endpoint-microservice/graphql/queries/handlers/get-graphql-schema.handler.js +6 -4
  41. package/dist/endpoint-microservice/graphql/queries/handlers/get-graphql-schema.handler.js.map +1 -1
  42. package/dist/endpoint-microservice/health/database-check.service.d.ts +1 -1
  43. package/dist/endpoint-microservice/health/notification.check.d.ts +1 -1
  44. package/dist/endpoint-microservice/metrics/utils.js +1 -2
  45. package/dist/endpoint-microservice/metrics/utils.js.map +1 -1
  46. package/dist/endpoint-microservice/restapi/queries/handlers/get-open-api-schema.handler.d.ts +1 -0
  47. package/dist/endpoint-microservice/restapi/queries/handlers/get-open-api-schema.handler.js +28 -324
  48. package/dist/endpoint-microservice/restapi/queries/handlers/get-open-api-schema.handler.js.map +1 -1
  49. package/dist/endpoint-microservice/restapi/queries/handlers/open-api-shema.utils.d.ts +7 -0
  50. package/dist/endpoint-microservice/restapi/queries/handlers/open-api-shema.utils.js +141 -0
  51. package/dist/endpoint-microservice/restapi/queries/handlers/open-api-shema.utils.js.map +1 -0
  52. package/dist/endpoint-microservice/restapi/restapi-endpoint.service.js +1 -3
  53. package/dist/endpoint-microservice/restapi/restapi-endpoint.service.js.map +1 -1
  54. package/dist/endpoint-microservice/shared/app-mode.d.ts +4 -0
  55. package/dist/endpoint-microservice/shared/app-mode.js +5 -0
  56. package/dist/endpoint-microservice/shared/app-mode.js.map +1 -0
  57. package/dist/endpoint-microservice/shared/schema/lib/resolveRefs.js +8 -0
  58. package/dist/endpoint-microservice/shared/schema/lib/resolveRefs.js.map +1 -1
  59. package/dist/endpoint-microservice/shared/schema/model/schema/json-boolean.store.d.ts +0 -1
  60. package/dist/endpoint-microservice/shared/schema/model/schema/json-number.store.d.ts +0 -1
  61. package/dist/endpoint-microservice/shared/schema/model/schema/json-string.store.d.ts +0 -1
  62. package/dist/endpoint-microservice/shared/schema/plugins/index.d.ts +7 -0
  63. package/dist/endpoint-microservice/shared/schema/plugins/index.js +7 -0
  64. package/dist/endpoint-microservice/shared/schema/plugins/index.js.map +1 -1
  65. package/dist/endpoint-microservice/shared/schema/plugins/row-created-at.schema.d.ts +4 -0
  66. package/dist/endpoint-microservice/shared/schema/plugins/row-created-at.schema.js +15 -0
  67. package/dist/endpoint-microservice/shared/schema/plugins/row-created-at.schema.js.map +1 -0
  68. package/dist/endpoint-microservice/shared/schema/plugins/row-created-id.schema.d.ts +4 -0
  69. package/dist/endpoint-microservice/shared/schema/plugins/row-created-id.schema.js +15 -0
  70. package/dist/endpoint-microservice/shared/schema/plugins/row-created-id.schema.js.map +1 -0
  71. package/dist/endpoint-microservice/shared/schema/plugins/row-hash.schema.d.ts +4 -0
  72. package/dist/endpoint-microservice/shared/schema/plugins/row-hash.schema.js +15 -0
  73. package/dist/endpoint-microservice/shared/schema/plugins/row-hash.schema.js.map +1 -0
  74. package/dist/endpoint-microservice/shared/schema/plugins/row-id.schema.d.ts +4 -0
  75. package/dist/endpoint-microservice/shared/schema/plugins/row-id.schema.js +15 -0
  76. package/dist/endpoint-microservice/shared/schema/plugins/row-id.schema.js.map +1 -0
  77. package/dist/endpoint-microservice/shared/schema/plugins/row-schema-hash.schema.d.ts +4 -0
  78. package/dist/endpoint-microservice/shared/schema/plugins/row-schema-hash.schema.js +15 -0
  79. package/dist/endpoint-microservice/shared/schema/plugins/row-schema-hash.schema.js.map +1 -0
  80. package/dist/endpoint-microservice/shared/schema/plugins/row-updated-at.schema.d.ts +4 -0
  81. package/dist/endpoint-microservice/shared/schema/plugins/row-updated-at.schema.js +15 -0
  82. package/dist/endpoint-microservice/shared/schema/plugins/row-updated-at.schema.js.map +1 -0
  83. package/dist/endpoint-microservice/shared/schema/plugins/row-version-id.schema.d.ts +4 -0
  84. package/dist/endpoint-microservice/shared/schema/plugins/row-version-id.schema.js +15 -0
  85. package/dist/endpoint-microservice/shared/schema/plugins/row-version-id.schema.js.map +1 -0
  86. package/dist/endpoint-microservice/shared/schema-ids.consts.d.ts +7 -0
  87. package/dist/endpoint-microservice/shared/schema-ids.consts.js +7 -0
  88. package/dist/endpoint-microservice/shared/schema-ids.consts.js.map +1 -1
  89. package/dist/endpoint-microservice/shared/utils/getOffsetPagination.js +1 -2
  90. package/dist/endpoint-microservice/shared/utils/getOffsetPagination.js.map +1 -1
  91. package/dist/endpoint-microservice/shared/utils/parseHeaders.d.ts +0 -1
  92. package/dist/main.js +8 -1
  93. package/dist/main.js.map +1 -1
  94. package/dist/tsconfig.build.tsbuildinfo +1 -1
  95. package/package.json +50 -42
  96. package/dist/endpoint-microservice/endpoint-listener.controller.js.map +0 -1
@@ -11,21 +11,20 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EndpointListenerController = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
- const cqrs_1 = require("@nestjs/cqrs");
15
14
  const microservices_1 = require("@nestjs/microservices");
16
- const impl_1 = require("./commands/impl");
15
+ const endpoint_event_handler_1 = require("./endpoint-event.handler");
17
16
  let EndpointListenerController = class EndpointListenerController {
18
- constructor(commandBus) {
19
- this.commandBus = commandBus;
17
+ constructor(handler) {
18
+ this.handler = handler;
20
19
  }
21
- handleEndpointCreated(endpointId) {
22
- return this.commandBus.execute(new impl_1.CreateEndpointCommand(endpointId));
20
+ handleCreated(id) {
21
+ return this.handler.handleCreated(id);
23
22
  }
24
- handleEndpointDeleted({ endpointId, endpointType, }) {
25
- return this.commandBus.execute(new impl_1.DeleteEndpointCommand(endpointId, endpointType));
23
+ handleUpdated(id) {
24
+ return this.handler.handleUpdated(id);
26
25
  }
27
- handleEndpointUpdated(endpointId) {
28
- return this.commandBus.execute(new impl_1.UpdateEndpointCommand(endpointId));
26
+ handleDeleted(payload) {
27
+ return this.handler.handleDeleted(payload);
29
28
  }
30
29
  };
31
30
  exports.EndpointListenerController = EndpointListenerController;
@@ -34,21 +33,21 @@ __decorate([
34
33
  __metadata("design:type", Function),
35
34
  __metadata("design:paramtypes", [String]),
36
35
  __metadata("design:returntype", void 0)
37
- ], EndpointListenerController.prototype, "handleEndpointCreated", null);
36
+ ], EndpointListenerController.prototype, "handleCreated", null);
38
37
  __decorate([
39
- (0, microservices_1.EventPattern)('endpoint_deleted'),
38
+ (0, microservices_1.EventPattern)('endpoint_updated'),
40
39
  __metadata("design:type", Function),
41
- __metadata("design:paramtypes", [Object]),
40
+ __metadata("design:paramtypes", [String]),
42
41
  __metadata("design:returntype", void 0)
43
- ], EndpointListenerController.prototype, "handleEndpointDeleted", null);
42
+ ], EndpointListenerController.prototype, "handleUpdated", null);
44
43
  __decorate([
45
- (0, microservices_1.EventPattern)('endpoint_updated'),
44
+ (0, microservices_1.EventPattern)('endpoint_deleted'),
46
45
  __metadata("design:type", Function),
47
- __metadata("design:paramtypes", [String]),
46
+ __metadata("design:paramtypes", [Object]),
48
47
  __metadata("design:returntype", void 0)
49
- ], EndpointListenerController.prototype, "handleEndpointUpdated", null);
48
+ ], EndpointListenerController.prototype, "handleDeleted", null);
50
49
  exports.EndpointListenerController = EndpointListenerController = __decorate([
51
50
  (0, common_1.Controller)(),
52
- __metadata("design:paramtypes", [cqrs_1.CommandBus])
51
+ __metadata("design:paramtypes", [endpoint_event_handler_1.EndpointEventHandler])
53
52
  ], EndpointListenerController);
54
53
  //# sourceMappingURL=endpoint-listener.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-listener.controller.js","sourceRoot":"","sources":["../../../src/endpoint-microservice/events/endpoint-listener.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAqD;AAErD,qEAA+F;AAGxF,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACrC,YAA6B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAE5B,aAAa,CAAC,EAAU;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAEiC,aAAa,CAAC,EAAU;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAEiC,aAAa,CAAC,OAG/C;QACC,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAjBY,gEAA0B;AAGH;IAAjC,IAAA,4BAAY,EAAC,kBAAkB,CAAC;;;;+DAEhC;AAEiC;IAAjC,IAAA,4BAAY,EAAC,kBAAkB,CAAC;;;;+DAEhC;AAEiC;IAAjC,IAAA,4BAAY,EAAC,kBAAkB,CAAC;;;;+DAKhC;qCAhBU,0BAA0B;IADtC,IAAA,mBAAU,GAAE;qCAE2B,6CAAoB;GAD/C,0BAA0B,CAiBtC"}
@@ -0,0 +1,12 @@
1
+ import { EndpointType } from '@prisma/client';
2
+ import { EndpointEventHandler } from '../../endpoint-microservice/events/endpoint-event.handler';
3
+ export declare class InProcessEndpointListener {
4
+ private readonly handler;
5
+ constructor(handler: EndpointEventHandler);
6
+ onCreate(id: string): Promise<any>;
7
+ onUpdate(id: string): Promise<any>;
8
+ onDelete(payload: {
9
+ endpointId: string;
10
+ endpointType: EndpointType;
11
+ }): Promise<any>;
12
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InProcessEndpointListener = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const event_emitter_1 = require("@nestjs/event-emitter");
15
+ const endpoint_event_handler_1 = require("./endpoint-event.handler");
16
+ let InProcessEndpointListener = class InProcessEndpointListener {
17
+ constructor(handler) {
18
+ this.handler = handler;
19
+ }
20
+ onCreate(id) {
21
+ return this.handler.handleCreated(id);
22
+ }
23
+ onUpdate(id) {
24
+ return this.handler.handleUpdated(id);
25
+ }
26
+ onDelete(payload) {
27
+ return this.handler.handleDeleted(payload);
28
+ }
29
+ };
30
+ exports.InProcessEndpointListener = InProcessEndpointListener;
31
+ __decorate([
32
+ (0, event_emitter_1.OnEvent)('endpoint_created'),
33
+ __metadata("design:type", Function),
34
+ __metadata("design:paramtypes", [String]),
35
+ __metadata("design:returntype", void 0)
36
+ ], InProcessEndpointListener.prototype, "onCreate", null);
37
+ __decorate([
38
+ (0, event_emitter_1.OnEvent)('endpoint_updated'),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", [String]),
41
+ __metadata("design:returntype", void 0)
42
+ ], InProcessEndpointListener.prototype, "onUpdate", null);
43
+ __decorate([
44
+ (0, event_emitter_1.OnEvent)('endpoint_deleted'),
45
+ __metadata("design:type", Function),
46
+ __metadata("design:paramtypes", [Object]),
47
+ __metadata("design:returntype", void 0)
48
+ ], InProcessEndpointListener.prototype, "onDelete", null);
49
+ exports.InProcessEndpointListener = InProcessEndpointListener = __decorate([
50
+ (0, common_1.Injectable)(),
51
+ __metadata("design:paramtypes", [endpoint_event_handler_1.EndpointEventHandler])
52
+ ], InProcessEndpointListener);
53
+ //# sourceMappingURL=in-process-endpoint.listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-process-endpoint.listener.js","sourceRoot":"","sources":["../../../src/endpoint-microservice/events/in-process-endpoint.listener.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yDAAgD;AAEhD,qEAA+F;AAGxF,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAEjC,QAAQ,CAAC,EAAU;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAE4B,QAAQ,CAAC,EAAU;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAE4B,QAAQ,CAAC,OAGrC;QACC,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAjBY,8DAAyB;AAGP;IAA5B,IAAA,uBAAO,EAAC,kBAAkB,CAAC;;;;yDAE3B;AAE4B;IAA5B,IAAA,uBAAO,EAAC,kBAAkB,CAAC;;;;yDAE3B;AAE4B;IAA5B,IAAA,uBAAO,EAAC,kBAAkB,CAAC;;;;yDAK3B;oCAhBU,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAE2B,6CAAoB;GAD/C,yBAAyB,CAiBrC"}
@@ -3,7 +3,9 @@ import { GraphqlEndpointService } from '../../endpoint-microservice/graphql/grap
3
3
  export declare class GraphqlEndpointController {
4
4
  private readonly endpointService;
5
5
  constructor(endpointService: GraphqlEndpointService);
6
- get(organizationId: string, projectName: string, branchName: string, postfix: string, req: Request, res: Response, next: NextFunction): void;
6
+ get(organizationId: string, projectName: string, branchName: string, postfix: string, req: Request, res: Response): void | Response<any, Record<string, any>>;
7
7
  post(organizationId: string, projectName: string, branchName: string, postfix: string | undefined, req: Request, res: Response, next: NextFunction): void;
8
- private run;
8
+ private handleRequest;
9
+ private buildExplorerUrl;
10
+ private buildExampleQuery;
9
11
  }
@@ -21,19 +21,22 @@ let GraphqlEndpointController = class GraphqlEndpointController {
21
21
  constructor(endpointService) {
22
22
  this.endpointService = endpointService;
23
23
  }
24
- get(organizationId, projectName, branchName, postfix, req, res, next) {
25
- this.run({
24
+ get(organizationId, projectName, branchName, postfix, req, res) {
25
+ const endpoint = this.endpointService.getEndpoint({
26
26
  organizationId,
27
27
  projectName,
28
28
  branchName,
29
29
  postfix,
30
- req,
31
- res,
32
- next,
33
30
  });
31
+ if (!endpoint) {
32
+ return res.status(common_1.HttpStatus.NOT_FOUND).send();
33
+ }
34
+ const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
35
+ const explorerUrl = this.buildExplorerUrl(fullUrl, endpoint.table);
36
+ return res.redirect(explorerUrl);
34
37
  }
35
38
  post(organizationId, projectName, branchName, postfix, req, res, next) {
36
- this.run({
39
+ this.handleRequest({
37
40
  organizationId,
38
41
  projectName,
39
42
  branchName,
@@ -43,12 +46,42 @@ let GraphqlEndpointController = class GraphqlEndpointController {
43
46
  next,
44
47
  });
45
48
  }
46
- run({ organizationId, projectName, branchName, postfix, req, res, next, }) {
47
- const endpointMiddleware = this.endpointService.getEndpointMiddleware(organizationId, projectName, branchName, postfix);
48
- if (!endpointMiddleware) {
49
+ handleRequest({ organizationId, projectName, branchName, postfix, req, res, next, }) {
50
+ const endpoint = this.endpointService.getEndpoint({
51
+ organizationId,
52
+ projectName,
53
+ branchName,
54
+ postfix,
55
+ });
56
+ if (!endpoint) {
49
57
  return res.status(common_1.HttpStatus.NOT_FOUND).send();
50
58
  }
51
- endpointMiddleware(req, res, next);
59
+ endpoint.middleware(req, res, next);
60
+ }
61
+ buildExplorerUrl(endpointUrl, table) {
62
+ const url = new URL('https://studio.apollographql.com/sandbox/explorer');
63
+ url.searchParams.set('endpoint', endpointUrl);
64
+ url.searchParams.set('document', this.buildExampleQuery(table));
65
+ url.searchParams.set('headers', JSON.stringify({ 'Cache-Control': 'no-cache' }));
66
+ return url.toString();
67
+ }
68
+ buildExampleQuery(table) {
69
+ return `query ExampleQuery {
70
+ ${table} {
71
+ edges {
72
+ node {
73
+ id
74
+ }
75
+ }
76
+ pageInfo {
77
+ startCursor
78
+ endCursor
79
+ hasPreviousPage
80
+ hasNextPage
81
+ }
82
+ totalCount
83
+ }
84
+ }`;
52
85
  }
53
86
  };
54
87
  exports.GraphqlEndpointController = GraphqlEndpointController;
@@ -60,9 +93,8 @@ __decorate([
60
93
  __param(3, (0, common_1.Param)('postfix')),
61
94
  __param(4, (0, common_1.Req)()),
62
95
  __param(5, (0, common_1.Res)()),
63
- __param(6, (0, common_1.Next)()),
64
96
  __metadata("design:type", Function),
65
- __metadata("design:paramtypes", [String, String, String, String, Object, Object, Function]),
97
+ __metadata("design:paramtypes", [String, String, String, String, Object, Object]),
66
98
  __metadata("design:returntype", void 0)
67
99
  ], GraphqlEndpointController.prototype, "get", null);
68
100
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-endpoint.controller.js","sourceRoot":"","sources":["../../../src/endpoint-microservice/graphql/graphql-endpoint.controller.ts"],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aAAa,CAAC,CAAA;IACpB,WAAA,IAAA,cAAK,EAAC,YAAY,CAAC,CAAA;IACnB,WAAA,IAAA,cAAK,EAAC,SAAS,CAAC,CAAA;IAEhB,WAAA,IAAA,YAAG,GAAE,CAAA;IAEL,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,aAAI,GAAE,CAAA;;;;oDAWR;AAGD;IADC,IAAA,aAAI,GAAE;IAEJ,WAAA,IAAA,cAAK,EAAC,gBAAgB,CAAC,CAAA;IACvB,WAAA,IAAA,cAAK,EAAC,aAAa,CAAC,CAAA;IACpB,WAAA,IAAA,cAAK,EAAC,YAAY,CAAC,CAAA;IACnB,WAAA,IAAA,cAAK,EAAC,SAAS,CAAC,CAAA;IAEhB,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,aAAI,GAAE,CAAA;;;;qDAWR;oCA9CU,yBAAyB;IALrC,IAAA,wBAAe,EAAC,iDAAsB,CAAC;IACvC,IAAA,8BAAoB,GAAE;IACtB,IAAA,mBAAU,EACT,oEAAoE,CACrE;qCAE+C,iDAAsB;GADzD,yBAAyB,CA8ErC"}
1
+ {"version":3,"file":"graphql-endpoint.controller.js","sourceRoot":"","sources":["../../../src/endpoint-microservice/graphql/graphql-endpoint.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,6CAAuD;AAEvD,yEAAoG;AACpG,uFAAyG;AAOlG,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,eAAuC;QAAvC,oBAAe,GAAf,eAAe,CAAwB;IAAG,CAAC;IAGxE,GAAG,CACwB,cAAsB,EACzB,WAAmB,EACpB,UAAkB,EACrB,OAAe,EAC1B,GAAY,EACZ,GAAa;QAEpB,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC;YAChD,cAAc;YACd,WAAW;YACX,UAAU;YACV,OAAO;SACR,C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C,iDAAsB;GADzD,yBAAyB,CAgHrC"}
@@ -1,22 +1,38 @@
1
- /// <reference types="qs" />
1
+ import { ApolloServer } from '@apollo/server';
2
2
  import { QueryBus } from '@nestjs/cqrs';
3
3
  import { RequestHandler } from 'express';
4
4
  import { PrismaService } from '../../endpoint-microservice/database/prisma.service';
5
5
  import { GraphqlMetricsPlugin } from '../../endpoint-microservice/metrics/graphql/graphql-metrics.plugin';
6
+ interface RouteKey {
7
+ organizationId: string;
8
+ projectName: string;
9
+ branchName: string;
10
+ postfix: string;
11
+ }
6
12
  export declare class GraphqlEndpointService {
7
13
  private readonly prisma;
8
14
  private readonly queryBus;
9
15
  private readonly graphqlMetricsPlugin;
10
16
  private readonly logger;
11
- private readonly map;
17
+ private readonly endpointMap;
12
18
  private startedEndpointIds;
13
19
  constructor(prisma: PrismaService, queryBus: QueryBus, graphqlMetricsPlugin: GraphqlMetricsPlugin);
14
- getEndpointMiddleware(organizationId: string, projectName: string, branchName: string, postfix: string): RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
20
+ getEndpoint(routeKey: RouteKey): {
21
+ middleware: RequestHandler;
22
+ apollo: ApolloServer;
23
+ endpointId: string;
24
+ table?: string;
25
+ };
15
26
  existEndpoint(endpointId: string): boolean;
16
27
  stopEndpoint(endpointId: string): Promise<void>;
17
28
  runEndpoint(endpointId: string): Promise<void>;
18
- private _run;
19
- private getPostfix;
20
- private getUrl;
21
- private getDbEndpoint;
29
+ private createApolloServerWithSchema;
30
+ private getSchemaAndDefaultTable;
31
+ private buildApolloServer;
32
+ private createMiddleware;
33
+ private getEndpointRouteKey;
34
+ private getRevisionPostfix;
35
+ private buildUrl;
36
+ private fetchDbEndpoint;
22
37
  }
38
+ export {};
@@ -12,7 +12,6 @@ var GraphqlEndpointService_1;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.GraphqlEndpointService = void 0;
14
14
  const server_1 = require("@apollo/server");
15
- const default_1 = require("@apollo/server/plugin/landingPage/default");
16
15
  const express4_1 = require("@apollo/server/express4");
17
16
  const common_1 = require("@nestjs/common");
18
17
  const cqrs_1 = require("@nestjs/cqrs");
@@ -26,106 +25,109 @@ let GraphqlEndpointService = GraphqlEndpointService_1 = class GraphqlEndpointSer
26
25
  this.queryBus = queryBus;
27
26
  this.graphqlMetricsPlugin = graphqlMetricsPlugin;
28
27
  this.logger = new common_1.Logger(GraphqlEndpointService_1.name);
29
- this.map = new Map();
28
+ this.endpointMap = new Map();
30
29
  this.startedEndpointIds = [];
31
30
  }
32
- getEndpointMiddleware(organizationId, projectName, branchName, postfix) {
33
- const item = this.map.get(this.getUrl(organizationId, projectName, branchName, postfix));
34
- return item?.middleware;
31
+ getEndpoint(routeKey) {
32
+ const url = this.buildUrl(routeKey);
33
+ return this.endpointMap.get(url);
35
34
  }
36
35
  existEndpoint(endpointId) {
37
36
  return this.startedEndpointIds.includes(endpointId);
38
37
  }
39
38
  async stopEndpoint(endpointId) {
40
- if (!this.startedEndpointIds.includes(endpointId)) {
39
+ if (!this.existEndpoint(endpointId)) {
41
40
  throw new Error(`${endpointId} is not started`);
42
41
  }
43
- const [url, item] = [...this.map.entries()].find(([_, mapValue]) => mapValue.endpointId === endpointId);
44
- if (item) {
45
- await item.apollo.stop();
46
- this.map.delete(url);
42
+ const [url, endpoint] = [...this.endpointMap.entries()].find(([, value]) => value.endpointId === endpointId) ?? [];
43
+ if (endpoint) {
44
+ await endpoint.apollo.stop();
45
+ this.endpointMap.delete(url);
46
+ this.startedEndpointIds = this.startedEndpointIds.filter((id) => id !== endpointId);
47
+ this.logger.log(`stopped endpoint name=${url} endpointId=${endpointId}`);
47
48
  }
48
- this.startedEndpointIds = this.startedEndpointIds.filter((id) => id !== endpointId);
49
- this.logger.log(`stopped endpoint name=${url} endpointId=${endpointId}`);
50
49
  }
51
50
  async runEndpoint(endpointId) {
52
- if (this.startedEndpointIds.includes(endpointId)) {
51
+ if (this.existEndpoint(endpointId)) {
53
52
  throw new Error(`${endpointId} already started`);
54
53
  }
55
- const dbEndpoint = await this.getDbEndpoint(endpointId);
56
- const { revision: { branch, ...revision }, } = dbEndpoint;
57
- const url = this.getUrl(branch.project.organizationId, branch.project.name, branch.name, this.getPostfix(revision));
58
- const apollo = await this._run({
54
+ const dbEndpoint = await this.fetchDbEndpoint(endpointId);
55
+ const revision = dbEndpoint.revision;
56
+ const branch = dbEndpoint.revision.branch;
57
+ const url = this.getEndpointRouteKey({
58
+ revision,
59
+ project: branch.project,
60
+ branchName: branch.name,
61
+ });
62
+ const { apollo, table } = await this.createApolloServerWithSchema({
59
63
  projectId: branch.projectId,
60
64
  projectName: branch.project.name,
61
65
  endpointId,
62
66
  isDraft: revision.isDraft,
63
67
  revisionId: revision.id,
64
68
  });
65
- this.startedEndpointIds.push(endpointId);
66
- this.map.set(url, {
67
- middleware: (0, express4_1.expressMiddleware)(apollo, {
68
- context: async ({ req }) => {
69
- return { headers: (0, parseHeaders_1.parseHeaders)(req.headers) };
70
- },
71
- }),
69
+ this.endpointMap.set(url, {
70
+ middleware: this.createMiddleware(apollo),
72
71
  apollo,
72
+ table,
73
73
  endpointId,
74
74
  });
75
+ this.startedEndpointIds.push(endpointId);
75
76
  this.logger.log(`started endpoint name=${url} endpointId=${endpointId}`);
76
77
  }
77
- async _run(options) {
78
- const graphqlSchema = await this.queryBus.execute(new impl_1.GetGraphqlSchemaQuery(options));
79
- const tables = Object.keys(graphqlSchema.getQueryType().getFields()).filter((field) => field !== '_service');
80
- const table = tables[0] || 'Table';
81
- const server = new server_1.ApolloServer({
82
- schema: graphqlSchema,
78
+ async createApolloServerWithSchema(context) {
79
+ const { schema, defaultTable } = await this.getSchemaAndDefaultTable(context);
80
+ const apollo = await this.buildApolloServer(schema);
81
+ return { apollo, table: defaultTable };
82
+ }
83
+ async getSchemaAndDefaultTable(context) {
84
+ const schema = await this.queryBus.execute(new impl_1.GetGraphqlSchemaQuery(context));
85
+ const fields = Object.keys(schema.getQueryType().getFields()).filter((name) => name !== '_service');
86
+ const defaultTable = fields[2] ?? 'Table';
87
+ return { schema, defaultTable };
88
+ }
89
+ async buildApolloServer(schema) {
90
+ const apollo = new server_1.ApolloServer({
91
+ schema,
83
92
  introspection: true,
93
+ plugins: [this.graphqlMetricsPlugin],
84
94
  formatError: (error) => {
85
95
  if (error.extensions?.stacktrace) {
86
96
  error.extensions.stacktrace = [];
87
97
  }
88
98
  return error;
89
99
  },
90
- plugins: [
91
- this.graphqlMetricsPlugin,
92
- (0, default_1.ApolloServerPluginLandingPageLocalDefault)({
93
- document: `query ExampleQuery {
94
- ${table} {
95
- edges {
96
- node {
97
- id
98
- }
100
+ });
101
+ await apollo.start();
102
+ return apollo;
99
103
  }
100
- pageInfo {
101
- startCursor
102
- endCursor
103
- hasPreviousPage
104
- hasNextPage
104
+ createMiddleware(apollo) {
105
+ return (0, express4_1.expressMiddleware)(apollo, {
106
+ context: async ({ req }) => ({
107
+ headers: (0, parseHeaders_1.parseHeaders)(req.headers),
108
+ }),
109
+ });
105
110
  }
106
- totalCount
107
- }
108
- }
109
- `,
110
- }),
111
- ],
111
+ getEndpointRouteKey(context) {
112
+ const postfix = this.getRevisionPostfix(context.revision);
113
+ return this.buildUrl({
114
+ organizationId: context.project.organizationId,
115
+ projectName: context.project.name,
116
+ branchName: context.branchName,
117
+ postfix,
112
118
  });
113
- await server.start();
114
- return server;
115
119
  }
116
- getPostfix(revision) {
117
- if (revision.isHead) {
120
+ getRevisionPostfix(revision) {
121
+ if (revision.isHead)
118
122
  return 'head';
119
- }
120
- if (revision.isDraft) {
123
+ if (revision.isDraft)
121
124
  return 'draft';
122
- }
123
125
  return revision.id;
124
126
  }
125
- getUrl(organizationId, projectName, branchName, postfix) {
127
+ buildUrl({ organizationId, projectName, branchName, postfix, }) {
126
128
  return `${organizationId}/${projectName}/${branchName}/${postfix}`;
127
129
  }
128
- getDbEndpoint(endpointId) {
130
+ fetchDbEndpoint(endpointId) {
129
131
  return this.prisma.endpoint.findUniqueOrThrow({
130
132
  where: { id: endpointId },
131
133
  include: {
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-endpoint.service.js","sourceRoot":"","sources":["../../../src/endpoint-microservice/graphql/graphql-endpoint.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA8C;AAC9C,uEAAsG;AACtG,sDAA4D;AAC5D,2CAAoD;AACpD,uCAAwC;AAGxC,+DAAkF;AAClF,yCAAuF;AACvF,sFAAwG;AACxG,+DAAmF;AAG5E,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IASjC,YACmB,MAAqB,EACrB,QAAkB,EAClB,oBAA0C;QAF1C,WAAM,GAAN,MAAM,CAAe;QACrB,aAAQ,GAAR,QAAQ,CAAU;QAClB,yBAAoB,GAApB,oBAAoB,CAAsB;QAX5C,WAAM,GAAG,IAAI,eAAM,CAAC,wBAAsB,CAAC,IAAI,CAAC,CAAC;QAEjD,QAAG,GAAG,IAAI,GAAG,EAG3B,CAAC;QACI,uBAAkB,GAAa,EAAE,CAAC;IAMvC,CAAC;IAEG,qBAAqB,CAC1B,cAAsB,EACtB,WAAmB,EACnB,UAAkB,EAClB,OAAe;QAEf,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CACvB,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,CAC9D,CAAC;QACF,OAAO,IAAI,EAAE,UAAU,CAAC;IAC1B,CAAC;IAEM,aAAa,CAAC,UAAkB;QACrC,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,UAAkB;QAC1C,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,iBAAiB,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,CAAC,G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AAC,UAAU,GAAG,EAAE,CAAC;gBACnC,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,EAAE;gBACP,IAAI,CAAC,oBAAoB;gBACzB,IAAA,mDAAyC,EAAC;oBACxC,QAAQ,EAAE;IAChB,KAAK;;;;;;;;;;;;;;;SAeA;iBACA,CAAC;aACH;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,UAAU,CAAC,QAIlB;QACC,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;IAEO,MAAM,CACZ,cAAsB,EACtB,WAAmB,EACnB,UAAkB,EAClB,OAAe;QAEf,OAAO,GAAG,cAAc,IAAI,WAAW,IAAI,UAAU,IAAI,OAAO,EAAE,CAAC;IACrE,CAAC;IAEO,aAAa,CAAC,UAAkB;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAC5C,KAAK,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE;YACzB,OAAO,EAAE;gBACP,QAAQ,EAAE;oBACR,OAAO,EAAE;wBACP,MAAM,EAAE;4BACN,OAAO,EAAE;gCACP,OAAO,EAAE,IAAI;6BACd;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA3LY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAWgB,8BAAa;QACX,eAAQ;QACI,6CAAoB;GAZlD,sBAAsB,CA2LlC"}
1
+ {"version":3,"file":"graphql-endpoint.service.js","sourceRoot":"","sources":["../../../src/endpoint-microservice/graphql/graphql-endpoint.service.ts"],"names":[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EAAE;YACzB,OAAO,EAAE;gBACP,QAAQ,EAAE;oBACR,OAAO,EAAE;wBACP,MAAM,EAAE;4BACN,OAAO,EAAE;gCACP,OAAO,EAAE,IAAI;6BACd;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArLY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAiBgB,8BAAa;QACX,eAAQ;QACI,6CAAoB;GAlBlD,sBAAsB,CAqLlC"}
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
1
  import { AsyncLocalStorage } from 'async_hooks';
3
- import { GraphQLObjectType, GraphQLSchema } from 'graphql/type';
2
+ import { GraphQLEnumType, GraphQLObjectType, GraphQLSchema } from 'graphql/type';
4
3
  import { GraphQLFieldConfig } from 'graphql/type/definition';
5
4
  import { RowModel } from '../../../endpoint-microservice/core-api/generated/api';
6
5
  import { ProxyCoreApiService } from '../../../endpoint-microservice/core-api/proxy-core-api.service';
@@ -28,6 +27,7 @@ interface ValidTableType {
28
27
  }
29
28
  interface GraphQLSchemaConverterContext extends ConverterContextType {
30
29
  pageInfo: GraphQLObjectType;
30
+ sortOrder: GraphQLEnumType;
31
31
  nodes: Record<string, CacheNode>;
32
32
  validTables: Record<string, ValidTableType>;
33
33
  }
@@ -50,6 +50,7 @@ export declare class GraphQLSchemaConverter implements Converter<GraphQLSchema>
50
50
  private getListResolver;
51
51
  private getListConnection;
52
52
  private getListArgs;
53
+ private generateOrderByType;
53
54
  private getEdgeType;
54
55
  private buildNodeCache;
55
56
  private getCachedNodeType;
@@ -34,6 +34,7 @@ let GraphQLSchemaConverter = GraphQLSchemaConverter_1 = class GraphQLSchemaConve
34
34
  const graphQLSchemaConverterContext = {
35
35
  ...context,
36
36
  pageInfo: (0, types_1.getPageInfoType)((0, utils_1.getProjectName)(context.projectName)),
37
+ sortOrder: (0, types_1.getSortOrder)((0, utils_1.getProjectName)(context.projectName)),
37
38
  nodes: {},
38
39
  validTables: {},
39
40
  };
@@ -163,12 +164,11 @@ let GraphQLSchemaConverter = GraphQLSchemaConverter_1 = class GraphQLSchemaConve
163
164
  }
164
165
  getListResolver(table) {
165
166
  const revisionId = this.context.revisionId;
166
- return async (_, { data }, ctx) => {
167
- const { data: response, error } = await this.proxyCoreApi.api.rows({
168
- revisionId,
169
- tableId: table.id,
167
+ return async (_, { data, }, ctx) => {
168
+ const { data: response, error } = await this.proxyCoreApi.api.rows(revisionId, table.id, {
170
169
  first: data?.first || constants_1.DEFAULT_FIRST,
171
170
  after: data?.after ?? undefined,
171
+ orderBy: data?.orderBy ?? undefined,
172
172
  }, { headers: ctx.headers });
173
173
  if (error)
174
174
  throw this.toGraphQLError(error);
@@ -191,10 +191,31 @@ let GraphQLSchemaConverter = GraphQLSchemaConverter_1 = class GraphQLSchemaConve
191
191
  return new type_1.GraphQLInputObjectType({
192
192
  name: `${this.projectName}Get${name}Input`,
193
193
  fields: {
194
- first: { type: type_1.GraphQLFloat },
194
+ first: { type: type_1.GraphQLInt },
195
195
  after: { type: type_1.GraphQLString },
196
+ orderBy: {
197
+ type: this.generateOrderByType(`${this.projectName}Get${name}`),
198
+ },
199
+ },
200
+ });
201
+ }
202
+ generateOrderByType(prefix) {
203
+ const OrderByFieldEnum = new type_1.GraphQLEnumType({
204
+ name: `${prefix}OrderByField`,
205
+ values: {
206
+ createdAt: { value: 'createdAt' },
207
+ updatedAt: { value: 'updatedAt' },
208
+ id: { value: 'id' },
209
+ },
210
+ });
211
+ const OrderByFieldInput = new type_1.GraphQLInputObjectType({
212
+ name: `${prefix}OrderByInput`,
213
+ fields: {
214
+ field: { type: new type_1.GraphQLNonNull(OrderByFieldEnum) },
215
+ direction: { type: new type_1.GraphQLNonNull(this.context.sortOrder) },
196
216
  },
197
217
  });
218
+ return new type_1.GraphQLList(OrderByFieldInput);
198
219
  }
199
220
  getEdgeType(options) {
200
221
  return new type_1.GraphQLObjectType({