@cedarjs/structure 2.8.1-next.116 → 2.8.1-rc.3

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 (110) hide show
  1. package/README.md +1 -1
  2. package/dist/errors.js +15 -9
  3. package/dist/index.d.ts +7 -7
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +67 -40
  6. package/dist/model/RWCell.d.ts +4 -4
  7. package/dist/model/RWCell.d.ts.map +1 -1
  8. package/dist/model/RWCell.js +103 -111
  9. package/dist/model/RWComponent.d.ts +2 -2
  10. package/dist/model/RWComponent.d.ts.map +1 -1
  11. package/dist/model/RWComponent.js +41 -46
  12. package/dist/model/RWEnvHelper.d.ts +4 -4
  13. package/dist/model/RWEnvHelper.d.ts.map +1 -1
  14. package/dist/model/RWEnvHelper.js +205 -212
  15. package/dist/model/RWFunction.d.ts +2 -2
  16. package/dist/model/RWFunction.d.ts.map +1 -1
  17. package/dist/model/RWFunction.js +15 -10
  18. package/dist/model/RWLayout.d.ts +2 -2
  19. package/dist/model/RWLayout.d.ts.map +1 -1
  20. package/dist/model/RWLayout.js +15 -10
  21. package/dist/model/RWPage.d.ts +3 -3
  22. package/dist/model/RWPage.d.ts.map +1 -1
  23. package/dist/model/RWPage.js +57 -61
  24. package/dist/model/RWProject.d.ts +17 -11
  25. package/dist/model/RWProject.d.ts.map +1 -1
  26. package/dist/model/RWProject.js +164 -218
  27. package/dist/model/RWRoute.d.ts +5 -5
  28. package/dist/model/RWRoute.d.ts.map +1 -1
  29. package/dist/model/RWRoute.js +262 -312
  30. package/dist/model/RWRouter.d.ts +4 -4
  31. package/dist/model/RWRouter.d.ts.map +1 -1
  32. package/dist/model/RWRouter.js +126 -130
  33. package/dist/model/RWSDL.d.ts +5 -5
  34. package/dist/model/RWSDL.d.ts.map +1 -1
  35. package/dist/model/RWSDL.js +84 -96
  36. package/dist/model/RWSDLField.d.ts +6 -6
  37. package/dist/model/RWSDLField.d.ts.map +1 -1
  38. package/dist/model/RWSDLField.js +81 -79
  39. package/dist/model/RWService.d.ts +4 -4
  40. package/dist/model/RWService.d.ts.map +1 -1
  41. package/dist/model/RWService.js +76 -76
  42. package/dist/model/RWServiceFunction.d.ts +4 -4
  43. package/dist/model/RWServiceFunction.d.ts.map +1 -1
  44. package/dist/model/RWServiceFunction.js +97 -95
  45. package/dist/model/RWTOML.d.ts +3 -3
  46. package/dist/model/RWTOML.d.ts.map +1 -1
  47. package/dist/model/RWTOML.js +55 -53
  48. package/dist/model/index.d.ts +2 -2
  49. package/dist/model/index.d.ts.map +1 -1
  50. package/dist/model/index.js +20 -3
  51. package/dist/model/util/process_env.js +62 -44
  52. package/dist/nodes.d.ts +2 -2
  53. package/dist/nodes.d.ts.map +1 -1
  54. package/dist/nodes.js +164 -171
  55. package/dist/util.js +33 -23
  56. package/dist/x/Array.js +25 -15
  57. package/dist/x/Location.d.ts +1 -1
  58. package/dist/x/Location.d.ts.map +1 -1
  59. package/dist/x/Location.js +17 -11
  60. package/dist/x/Position.js +29 -18
  61. package/dist/x/Range.d.ts +1 -1
  62. package/dist/x/Range.d.ts.map +1 -1
  63. package/dist/x/Range.js +22 -17
  64. package/dist/x/URL.js +75 -59
  65. package/dist/x/child_process.d.ts +1 -1
  66. package/dist/x/child_process.d.ts.map +1 -1
  67. package/dist/x/child_process.js +49 -35
  68. package/dist/x/decorators.d.ts +2 -2
  69. package/dist/x/decorators.d.ts.map +1 -1
  70. package/dist/x/decorators.js +26 -46
  71. package/dist/x/diagnostics.d.ts +3 -3
  72. package/dist/x/diagnostics.d.ts.map +1 -1
  73. package/dist/x/diagnostics.js +259 -163
  74. package/dist/x/path.js +55 -36
  75. package/dist/x/prisma.d.ts +2 -2
  76. package/dist/x/prisma.d.ts.map +1 -1
  77. package/dist/x/prisma.js +55 -32
  78. package/dist/x/ts-morph.js +45 -34
  79. package/package.json +17 -38
  80. package/dist/errors.js.map +0 -1
  81. package/dist/index.js.map +0 -1
  82. package/dist/model/RWCell.js.map +0 -1
  83. package/dist/model/RWComponent.js.map +0 -1
  84. package/dist/model/RWEnvHelper.js.map +0 -1
  85. package/dist/model/RWFunction.js.map +0 -1
  86. package/dist/model/RWLayout.js.map +0 -1
  87. package/dist/model/RWPage.js.map +0 -1
  88. package/dist/model/RWProject.js.map +0 -1
  89. package/dist/model/RWRoute.js.map +0 -1
  90. package/dist/model/RWRouter.js.map +0 -1
  91. package/dist/model/RWSDL.js.map +0 -1
  92. package/dist/model/RWSDLField.js.map +0 -1
  93. package/dist/model/RWService.js.map +0 -1
  94. package/dist/model/RWServiceFunction.js.map +0 -1
  95. package/dist/model/RWTOML.js.map +0 -1
  96. package/dist/model/index.js.map +0 -1
  97. package/dist/model/util/process_env.js.map +0 -1
  98. package/dist/nodes.js.map +0 -1
  99. package/dist/util.js.map +0 -1
  100. package/dist/x/Array.js.map +0 -1
  101. package/dist/x/Location.js.map +0 -1
  102. package/dist/x/Position.js.map +0 -1
  103. package/dist/x/Range.js.map +0 -1
  104. package/dist/x/URL.js.map +0 -1
  105. package/dist/x/child_process.js.map +0 -1
  106. package/dist/x/decorators.js.map +0 -1
  107. package/dist/x/diagnostics.js.map +0 -1
  108. package/dist/x/path.js.map +0 -1
  109. package/dist/x/prisma.js.map +0 -1
  110. package/dist/x/ts-morph.js.map +0 -1
@@ -1,139 +1,135 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import * as tsm from 'ts-morph';
8
- import { getConfigPath } from '@cedarjs/project-config';
9
- import { RWError } from '../errors.js';
10
- import { FileNode } from '../nodes.js';
11
- import { iter } from '../x/Array.js';
12
- import { lazy, memo } from '../x/decorators.js';
13
- import { err, LocationLike_toLocation } from '../x/diagnostics.js';
14
- import { DiagnosticSeverity } from '../x/diagnostics.js';
15
- import { URL_file } from '../x/URL.js';
16
- import { RWRoute } from './RWRoute.js';
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
6
+ _Object$defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.RWRouter = void 0;
10
+ var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/find"));
11
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/includes"));
12
+ var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/bind"));
13
+ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/filter"));
14
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
15
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
16
+ var tsm = _interopRequireWildcard(require("ts-morph"));
17
+ var _projectConfig = require("@cedarjs/project-config");
18
+ var _errors = require("../errors");
19
+ var _nodes = require("../nodes");
20
+ var _Array = require("../x/Array");
21
+ var _decorators = require("../x/decorators");
22
+ var _diagnostics = require("../x/diagnostics");
23
+ var _URL = require("../x/URL");
24
+ var _RWRoute = require("./RWRoute");
25
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class;
17
26
  /**
18
27
  * one per Routes.js
19
28
  */
20
- export class RWRouter extends FileNode {
21
- filePath;
22
- parent;
23
- constructor(filePath, parent) {
24
- super();
25
- this.filePath = filePath;
26
- this.parent = parent;
29
+ let RWRouter = exports.RWRouter = (_dec = (0, _decorators.memo)(), _dec2 = (0, _decorators.memo)(), _dec3 = (0, _decorators.lazy)(), _dec4 = (0, _decorators.lazy)(), _dec5 = (0, _decorators.lazy)(), _class = class RWRouter extends _nodes.FileNode {
30
+ constructor(filePath, parent) {
31
+ super();
32
+ this.filePath = filePath;
33
+ this.parent = parent;
34
+ }
35
+ // this is used by the live preview
36
+ getFilePathForRoutePath(routePath) {
37
+ var _context;
38
+ // TODO: params
39
+ return (0, _find.default)(_context = this.routes).call(_context, r => r.path === routePath)?.page?.filePath;
40
+ }
41
+ // this is used by the live preview
42
+ getRoutePathForFilePath(filePath) {
43
+ var _context2, _context3, _context4;
44
+ // TODO: params
45
+ const path = (0, _find.default)(_context2 = this.parent.pages).call(_context2, p => p.filePath === filePath)?.route?.path;
46
+ if (((_context3 = path) == null ? void 0 : (0, _bind.default)(_context4 = Function.call).call(_context4, (0, _includes.default)(_context3), _context3))?.('{')) {
47
+ return;
27
48
  }
28
- // this is used by the live preview
29
- getFilePathForRoutePath(routePath) {
30
- // TODO: params
31
- return this.routes.find((r) => r.path === routePath)?.page?.filePath;
32
- }
33
- // this is used by the live preview
34
- getRoutePathForFilePath(filePath) {
35
- // TODO: params
36
- const path = this.parent.pages.find((p) => p.filePath === filePath)?.route
37
- ?.path;
38
- if (path?.includes('{')) {
39
- return;
40
- }
41
- return path;
42
- }
43
- /**
44
- * the `<Router>` tag
45
- */
46
- get jsxNode() {
47
- return this.sf
48
- .getDescendantsOfKind(tsm.SyntaxKind.JsxOpeningElement)
49
- .find((x) => x.getTagNameNode().getText() === 'Router');
50
- }
51
- /**
52
- * One per `<Route>`
53
- */
54
- get routes() {
55
- // eslint-disable-next-line @typescript-eslint/no-this-alias
56
- const self = this;
57
- return iter(function* () {
58
- if (!self.jsxNode) {
59
- return;
60
- }
61
- // TODO: make sure that they are nested within the <Router> tag
62
- // we are not checking it right now
63
- const sets = self.sf
64
- .getDescendantsOfKind(tsm.SyntaxKind.JsxElement)
65
- .filter((x) => {
66
- const tagName = x.getOpeningElement().getTagNameNode().getText();
67
- return (tagName === 'Set' ||
68
- tagName === 'Private' ||
69
- tagName === 'PrivateSet');
49
+ return path;
50
+ }
51
+
52
+ /**
53
+ * the `<Router>` tag
54
+ */
55
+ get jsxNode() {
56
+ var _context5;
57
+ return (0, _find.default)(_context5 = this.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxOpeningElement)).call(_context5, x => x.getTagNameNode().getText() === 'Router');
58
+ }
59
+
60
+ /**
61
+ * One per `<Route>`
62
+ */
63
+ get routes() {
64
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
65
+ const self = this;
66
+ return (0, _Array.iter)(function* () {
67
+ var _context6;
68
+ if (!self.jsxNode) {
69
+ return;
70
+ }
71
+ // TODO: make sure that they are nested within the <Router> tag
72
+ // we are not checking it right now
73
+
74
+ const sets = (0, _filter.default)(_context6 = self.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxElement)).call(_context6, x => {
75
+ const tagName = x.getOpeningElement().getTagNameNode().getText();
76
+ return tagName === 'Set' || tagName === 'Private' || tagName === 'PrivateSet';
77
+ });
78
+ const prerenderSets = (0, _filter.default)(sets).call(sets, set => set.getOpeningElement().getAttribute('prerender'));
79
+ for (const set of prerenderSets) {
80
+ for (const x of set.getDescendantsOfKind(tsm.SyntaxKind.JsxSelfClosingElement)) {
81
+ const tagName = x.getTagNameNode().getText();
82
+ // Add prerender prop from <Set> if not already present
83
+ if (tagName === 'Route' && !x.getAttribute('prerender')) {
84
+ x.insertAttribute(0, {
85
+ name: 'prerender'
70
86
  });
71
- const prerenderSets = sets.filter((set) => set.getOpeningElement().getAttribute('prerender'));
72
- for (const set of prerenderSets) {
73
- for (const x of set.getDescendantsOfKind(tsm.SyntaxKind.JsxSelfClosingElement)) {
74
- const tagName = x.getTagNameNode().getText();
75
- // Add prerender prop from <Set> if not already present
76
- if (tagName === 'Route' && !x.getAttribute('prerender')) {
77
- x.insertAttribute(0, { name: 'prerender' });
78
- }
79
- }
80
- }
81
- for (const x of self.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxSelfClosingElement)) {
82
- const tagName = x.getTagNameNode().getText();
83
- if (tagName === 'Route') {
84
- yield new RWRoute(x, self);
85
- }
86
- }
87
- });
88
- }
89
- get numNotFoundPages() {
90
- return this.routes.filter((r) => r.isNotFound).length;
91
- }
92
- *diagnostics() {
93
- if (!this.fileExists) {
94
- // should we assign this error to the project? to cedar.toml?
95
- const uri = URL_file(getConfigPath());
96
- const message = `Routes.js does not exist`;
97
- yield err(uri, message);
98
- // TODO: add quickFix (create a simple Routes.js)
99
- return; // stop checking for errors if the file doesn't exist
100
- }
101
- if (!this.jsxNode) {
102
- return;
103
- }
104
- if (this.numNotFoundPages === 0) {
105
- const { uri, range } = LocationLike_toLocation(this.jsxNode);
106
- yield {
107
- uri,
108
- diagnostic: {
109
- range,
110
- message: "You must specify a 'notfound' page",
111
- severity: DiagnosticSeverity.Error,
112
- },
113
- };
87
+ }
114
88
  }
115
- else if (this.numNotFoundPages > 1) {
116
- const e = err(this.jsxNode, "You must specify exactly one 'notfound' page", RWError.NOTFOUND_PAGE_NOT_DEFINED);
117
- yield e;
89
+ }
90
+ for (const x of self.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxSelfClosingElement)) {
91
+ const tagName = x.getTagNameNode().getText();
92
+ if (tagName === 'Route') {
93
+ yield new _RWRoute.RWRoute(x, self);
118
94
  }
95
+ }
96
+ });
97
+ }
98
+ get numNotFoundPages() {
99
+ var _context7;
100
+ return (0, _filter.default)(_context7 = this.routes).call(_context7, r => r.isNotFound).length;
101
+ }
102
+ *diagnostics() {
103
+ if (!this.fileExists) {
104
+ // should we assign this error to the project? to cedar.toml?
105
+ const uri = (0, _URL.URL_file)((0, _projectConfig.getConfigPath)(this.parent.projectRoot));
106
+ const message = `Routes.js does not exist`;
107
+ yield (0, _diagnostics.err)(uri, message);
108
+ // TODO: add quickFix (create a simple Routes.js)
109
+ return; // stop checking for errors if the file doesn't exist
119
110
  }
120
- children() {
121
- return [...this.routes];
111
+ if (!this.jsxNode) {
112
+ return;
113
+ }
114
+ if (this.numNotFoundPages === 0) {
115
+ const {
116
+ uri,
117
+ range
118
+ } = (0, _diagnostics.LocationLike_toLocation)(this.jsxNode);
119
+ yield {
120
+ uri,
121
+ diagnostic: {
122
+ range,
123
+ message: "You must specify a 'notfound' page",
124
+ severity: _diagnostics.DiagnosticSeverity.Error
125
+ }
126
+ };
127
+ } else if (this.numNotFoundPages > 1) {
128
+ const e = (0, _diagnostics.err)(this.jsxNode, "You must specify exactly one 'notfound' page", _errors.RWError.NOTFOUND_PAGE_NOT_DEFINED);
129
+ yield e;
122
130
  }
123
- }
124
- __decorate([
125
- memo()
126
- ], RWRouter.prototype, "getFilePathForRoutePath", null);
127
- __decorate([
128
- memo()
129
- ], RWRouter.prototype, "getRoutePathForFilePath", null);
130
- __decorate([
131
- lazy()
132
- ], RWRouter.prototype, "jsxNode", null);
133
- __decorate([
134
- lazy()
135
- ], RWRouter.prototype, "routes", null);
136
- __decorate([
137
- lazy()
138
- ], RWRouter.prototype, "numNotFoundPages", null);
139
- //# sourceMappingURL=RWRouter.js.map
131
+ }
132
+ children() {
133
+ return [...this.routes];
134
+ }
135
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "getFilePathForRoutePath", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "getFilePathForRoutePath"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "getRoutePathForFilePath", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "getRoutePathForFilePath"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "jsxNode", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "jsxNode"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "routes", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "routes"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "numNotFoundPages", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "numNotFoundPages"), _class.prototype), _class);
@@ -1,7 +1,7 @@
1
1
  import * as tsm from 'ts-morph';
2
- import { FileNode } from '../nodes.js';
3
- import type { RWProject } from './RWProject.js';
4
- import { RWSDLField } from './RWSDLField.js';
2
+ import { FileNode } from '../nodes';
3
+ import type { RWProject } from './RWProject';
4
+ import { RWSDLField } from './RWSDLField';
5
5
  export declare class RWSDL extends FileNode {
6
6
  filePath: string;
7
7
  parent: RWProject;
@@ -12,10 +12,10 @@ export declare class RWSDL extends FileNode {
12
12
  get schemaStringNode(): tsm.NoSubstitutionTemplateLiteral | undefined;
13
13
  get schemaString(): string | undefined;
14
14
  get serviceFilePath(): string;
15
- get service(): import("./RWService.js").RWService | undefined;
15
+ get service(): import("./RWService").RWService | undefined;
16
16
  get name(): string;
17
17
  get implementableFields(): RWSDLField[];
18
18
  children(): RWSDLField[];
19
- diagnostics(): Generator<import("../x/diagnostics.js").ExtendedDiagnostic, void, unknown>;
19
+ diagnostics(): Generator<import("../x/diagnostics").ExtendedDiagnostic, void, unknown>;
20
20
  }
21
21
  //# sourceMappingURL=RWSDL.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RWSDL.d.ts","sourceRoot":"","sources":["../../src/model/RWSDL.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAKtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,qBAAa,KAAM,SAAQ,QAAQ;IAExB,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,SAAS;gBADjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS;IAI1B;;OAEG;IACH,IAAY,gBAAgB,kDAa3B;IACD,IAAY,YAAY,IAAI,MAAM,GAAG,SAAS,CAE7C;IACD,IAAY,eAAe,WAE1B;IACD,IAAY,OAAO,mDAElB;IACD,IAAY,IAAI,WAIf;IACD,IAAY,mBAAmB,iBAkB9B;IAED,QAAQ;IAGP,WAAW;CASb"}
1
+ {"version":3,"file":"RWSDL.d.ts","sourceRoot":"","sources":["../../src/model/RWSDL.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAKnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,qBAAa,KAAM,SAAQ,QAAQ;IAExB,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,SAAS;gBADjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS;IAI1B;;OAEG;IACH,IAAY,gBAAgB,kDAa3B;IACD,IAAY,YAAY,IAAI,MAAM,GAAG,SAAS,CAE7C;IACD,IAAY,eAAe,WAE1B;IACD,IAAY,OAAO,gDAElB;IACD,IAAY,IAAI,WAIf;IACD,IAAY,mBAAmB,iBAkB9B;IAED,QAAQ;IAGP,WAAW;CASb"}
@@ -1,101 +1,89 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { basename } from 'node:path';
8
- import { Kind, parse as parseGraphQL } from 'graphql';
9
- import * as tsm from 'ts-morph';
10
- import { RWError } from '../errors.js';
11
- import { FileNode } from '../nodes.js';
12
- import { iter } from '../x/Array.js';
13
- import { lazy } from '../x/decorators.js';
14
- import { err } from '../x/diagnostics.js';
15
- import { RWSDLField } from './RWSDLField.js';
16
- export class RWSDL extends FileNode {
17
- filePath;
18
- parent;
19
- constructor(filePath, parent) {
20
- super();
21
- this.filePath = filePath;
22
- this.parent = parent;
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
6
+ _Object$defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.RWSDL = void 0;
10
+ var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/find"));
11
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
12
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
13
+ var _path = require("path");
14
+ var _graphql = require("graphql");
15
+ var _parser = require("graphql/language/parser");
16
+ var tsm = _interopRequireWildcard(require("ts-morph"));
17
+ var _errors = require("../errors");
18
+ var _nodes = require("../nodes");
19
+ var _Array = require("../x/Array");
20
+ var _decorators = require("../x/decorators");
21
+ var _diagnostics = require("../x/diagnostics");
22
+ var _RWSDLField = require("./RWSDLField");
23
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class;
24
+ let RWSDL = exports.RWSDL = (_dec = (0, _decorators.lazy)(), _dec2 = (0, _decorators.lazy)(), _dec3 = (0, _decorators.lazy)(), _dec4 = (0, _decorators.lazy)(), _dec5 = (0, _decorators.lazy)(), _dec6 = (0, _decorators.lazy)(), _class = class RWSDL extends _nodes.FileNode {
25
+ constructor(filePath, parent) {
26
+ super();
27
+ this.filePath = filePath;
28
+ this.parent = parent;
29
+ }
30
+ /**
31
+ * The Template Literal node (string) that contains the schema
32
+ */
33
+ get schemaStringNode() {
34
+ const i = this.sf.getVariableDeclaration('schema')?.getInitializer();
35
+ if (!i) {
36
+ return undefined;
23
37
  }
24
- /**
25
- * The Template Literal node (string) that contains the schema
26
- */
27
- get schemaStringNode() {
28
- const i = this.sf.getVariableDeclaration('schema')?.getInitializer();
29
- if (!i) {
30
- return undefined;
31
- }
32
- // TODO: do we allow other kinds of strings? or just tagged literals?
33
- if (tsm.Node.isTaggedTemplateExpression(i)) {
34
- const t = i.getTemplate(); //?
35
- if (tsm.Node.isNoSubstitutionTemplateLiteral(t)) {
36
- return t;
37
- }
38
- }
39
- return undefined;
40
- }
41
- get schemaString() {
42
- return this.schemaStringNode?.getLiteralText();
43
- }
44
- get serviceFilePath() {
45
- return this.parent.servicesFilePath(this.name);
38
+ // TODO: do we allow other kinds of strings? or just tagged literals?
39
+ if (tsm.Node.isTaggedTemplateExpression(i)) {
40
+ const t = i.getTemplate(); //?
41
+ if (tsm.Node.isNoSubstitutionTemplateLiteral(t)) {
42
+ return t;
43
+ }
46
44
  }
47
- get service() {
48
- return this.parent.services.find((s) => s.name === this.name);
49
- }
50
- get name() {
51
- // TODO: support TS
52
- const base = basename(this.filePath);
53
- return base.substr(0, base.length - '.sdl.js'.length);
54
- }
55
- get implementableFields() {
56
- // eslint-disable-next-line @typescript-eslint/no-this-alias
57
- const self = this;
58
- return iter(function* () {
59
- if (!self.schemaString) {
60
- return;
61
- } //?
62
- const ast = parseGraphQL(self.schemaString);
63
- for (const def of ast.definitions) {
64
- if (def.kind === Kind.OBJECT_TYPE_DEFINITION) {
65
- if (def.name.value === 'Query' || def.name.value === 'Mutation') {
66
- for (const field of def.fields ?? []) {
67
- yield new RWSDLField(def, field, self);
68
- }
69
- }
70
- }
45
+ return undefined;
46
+ }
47
+ get schemaString() {
48
+ return this.schemaStringNode?.getLiteralText();
49
+ }
50
+ get serviceFilePath() {
51
+ return this.parent.servicesFilePath(this.name);
52
+ }
53
+ get service() {
54
+ var _context;
55
+ return (0, _find.default)(_context = this.parent.services).call(_context, s => s.name === this.name);
56
+ }
57
+ get name() {
58
+ // TODO: support TS
59
+ const base = (0, _path.basename)(this.filePath);
60
+ return base.substr(0, base.length - '.sdl.js'.length);
61
+ }
62
+ get implementableFields() {
63
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
64
+ const self = this;
65
+ return (0, _Array.iter)(function* () {
66
+ if (!self.schemaString) {
67
+ return;
68
+ } //?
69
+ const ast = (0, _parser.parse)(self.schemaString);
70
+ for (const def of ast.definitions) {
71
+ if (def.kind === _graphql.Kind.OBJECT_TYPE_DEFINITION) {
72
+ if (def.name.value === 'Query' || def.name.value === 'Mutation') {
73
+ for (const field of def.fields ?? []) {
74
+ yield new _RWSDLField.RWSDLField(def, field, self);
71
75
  }
72
- });
73
- }
74
- children() {
75
- return [...this.implementableFields];
76
- }
77
- *diagnostics() {
78
- if (!this.schemaStringNode) {
79
- yield err(this.uri, "Each SDL file must export a variable named 'schema' with a GraphQL schema string", RWError.SCHEMA_NOT_DEFINED);
76
+ }
80
77
  }
78
+ }
79
+ });
80
+ }
81
+ children() {
82
+ return [...this.implementableFields];
83
+ }
84
+ *diagnostics() {
85
+ if (!this.schemaStringNode) {
86
+ yield (0, _diagnostics.err)(this.uri, "Each SDL file must export a variable named 'schema' with a GraphQL schema string", _errors.RWError.SCHEMA_NOT_DEFINED);
81
87
  }
82
- }
83
- __decorate([
84
- lazy()
85
- ], RWSDL.prototype, "schemaStringNode", null);
86
- __decorate([
87
- lazy()
88
- ], RWSDL.prototype, "schemaString", null);
89
- __decorate([
90
- lazy()
91
- ], RWSDL.prototype, "serviceFilePath", null);
92
- __decorate([
93
- lazy()
94
- ], RWSDL.prototype, "service", null);
95
- __decorate([
96
- lazy()
97
- ], RWSDL.prototype, "name", null);
98
- __decorate([
99
- lazy()
100
- ], RWSDL.prototype, "implementableFields", null);
101
- //# sourceMappingURL=RWSDL.js.map
88
+ }
89
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "schemaStringNode", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "schemaStringNode"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "schemaString", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "schemaString"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "serviceFilePath", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "serviceFilePath"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "service", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "service"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "name", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "name"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "implementableFields", [_dec6], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "implementableFields"), _class.prototype), _class);
@@ -1,9 +1,9 @@
1
- import type { FieldDefinitionNode, ObjectTypeDefinitionNode } from 'graphql';
2
- import { BaseNode } from '../nodes.js';
3
- import type { ExtendedDiagnostic } from '../x/diagnostics.js';
4
- import type { Location } from '../x/Location.js';
5
- import type { RWSDL } from './RWSDL.js';
6
- import type { RWServiceFunction } from './RWServiceFunction.js';
1
+ import type { FieldDefinitionNode, ObjectTypeDefinitionNode } from 'graphql/language/ast';
2
+ import { BaseNode } from '../nodes';
3
+ import type { ExtendedDiagnostic } from '../x/diagnostics';
4
+ import type { Location } from '../x/Location';
5
+ import type { RWSDL } from './RWSDL';
6
+ import type { RWServiceFunction } from './RWServiceFunction';
7
7
  export declare class RWSDLField extends BaseNode {
8
8
  objectTypeDef: ObjectTypeDefinitionNode;
9
9
  field: FieldDefinitionNode;
@@ -1 +1 @@
1
- {"version":3,"file":"RWSDLField.d.ts","sourceRoot":"","sources":["../../src/model/RWSDLField.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAG5E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAG7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEhD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,qBAAa,UAAW,SAAQ,QAAQ;IAE7B,aAAa,EAAE,wBAAwB;IACvC,KAAK,EAAE,mBAAmB;IAC1B,MAAM,EAAE,KAAK;gBAFb,aAAa,EAAE,wBAAwB,EACvC,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,KAAK;IAItB,IAAY,EAAE,WAIb;IACD;;;OAGG;IACH,IAAY,QAAQ,IAAI,QAAQ,CAQ/B;IACD,IAAY,IAAI,WAEf;IACD,IAAY,aAAa,aAExB;IAED;;;OAGG;IACH,IAAY,IAAI,IAAI,iBAAiB,GAAG,SAAS,CAEhD;IAEA,WAAW;CAcb"}
1
+ {"version":3,"file":"RWSDLField.d.ts","sourceRoot":"","sources":["../../src/model/RWSDLField.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAG1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D,qBAAa,UAAW,SAAQ,QAAQ;IAE7B,aAAa,EAAE,wBAAwB;IACvC,KAAK,EAAE,mBAAmB;IAC1B,MAAM,EAAE,KAAK;gBAFb,aAAa,EAAE,wBAAwB,EACvC,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,KAAK;IAItB,IAAY,EAAE,WAIb;IACD;;;OAGG;IACH,IAAY,QAAQ,IAAI,QAAQ,CAQ/B;IACD,IAAY,IAAI,WAEf;IACD,IAAY,aAAa,aAExB;IAED;;;OAGG;IACH,IAAY,IAAI,IAAI,iBAAiB,GAAG,SAAS,CAEhD;IAEA,WAAW;CAcb"}