@cedarjs/structure 0.0.4

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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -0
  3. package/dist/errors.d.ts +11 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/errors.js +19 -0
  6. package/dist/hosts.d.ts +23 -0
  7. package/dist/hosts.d.ts.map +1 -0
  8. package/dist/hosts.js +45 -0
  9. package/dist/ide.d.ts +122 -0
  10. package/dist/ide.d.ts.map +1 -0
  11. package/dist/ide.js +240 -0
  12. package/dist/index.d.ts +12 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +79 -0
  15. package/dist/interactive_cli/RedwoodCommandString.d.ts +20 -0
  16. package/dist/interactive_cli/RedwoodCommandString.d.ts.map +1 -0
  17. package/dist/interactive_cli/RedwoodCommandString.js +72 -0
  18. package/dist/interactive_cli/command_builder.d.ts +10 -0
  19. package/dist/interactive_cli/command_builder.d.ts.map +1 -0
  20. package/dist/interactive_cli/command_builder.js +196 -0
  21. package/dist/interactive_cli/dry_run.d.ts +28 -0
  22. package/dist/interactive_cli/dry_run.d.ts.map +1 -0
  23. package/dist/interactive_cli/dry_run.js +101 -0
  24. package/dist/interactive_cli/ui.d.ts +32 -0
  25. package/dist/interactive_cli/ui.d.ts.map +1 -0
  26. package/dist/interactive_cli/ui.js +84 -0
  27. package/dist/language_server/RWLanguageServer.d.ts +30 -0
  28. package/dist/language_server/RWLanguageServer.d.ts.map +1 -0
  29. package/dist/language_server/RWLanguageServer.js +201 -0
  30. package/dist/language_server/commands.d.ts +14 -0
  31. package/dist/language_server/commands.d.ts.map +1 -0
  32. package/dist/language_server/commands.js +122 -0
  33. package/dist/language_server/diagnostics.d.ts +10 -0
  34. package/dist/language_server/diagnostics.d.ts.map +1 -0
  35. package/dist/language_server/diagnostics.js +61 -0
  36. package/dist/language_server/outline.d.ts +7 -0
  37. package/dist/language_server/outline.d.ts.map +1 -0
  38. package/dist/language_server/outline.js +37 -0
  39. package/dist/language_server/start.d.ts +2 -0
  40. package/dist/language_server/start.d.ts.map +1 -0
  41. package/dist/language_server/start.js +4 -0
  42. package/dist/language_server/xmethods.d.ts +11 -0
  43. package/dist/language_server/xmethods.d.ts.map +1 -0
  44. package/dist/language_server/xmethods.js +42 -0
  45. package/dist/model/RWCell.d.ts +22 -0
  46. package/dist/model/RWCell.d.ts.map +1 -0
  47. package/dist/model/RWCell.js +111 -0
  48. package/dist/model/RWComponent.d.ts +11 -0
  49. package/dist/model/RWComponent.d.ts.map +1 -0
  50. package/dist/model/RWComponent.js +42 -0
  51. package/dist/model/RWEnvHelper.d.ts +64 -0
  52. package/dist/model/RWEnvHelper.d.ts.map +1 -0
  53. package/dist/model/RWEnvHelper.js +295 -0
  54. package/dist/model/RWFunction.d.ts +11 -0
  55. package/dist/model/RWFunction.d.ts.map +1 -0
  56. package/dist/model/RWFunction.js +19 -0
  57. package/dist/model/RWLayout.d.ts +11 -0
  58. package/dist/model/RWLayout.d.ts.map +1 -0
  59. package/dist/model/RWLayout.js +19 -0
  60. package/dist/model/RWPage.d.ts +13 -0
  61. package/dist/model/RWPage.d.ts.map +1 -0
  62. package/dist/model/RWPage.js +60 -0
  63. package/dist/model/RWProject.d.ts +61 -0
  64. package/dist/model/RWProject.d.ts.map +1 -0
  65. package/dist/model/RWProject.js +170 -0
  66. package/dist/model/RWRoute.d.ts +58 -0
  67. package/dist/model/RWRoute.d.ts.map +1 -0
  68. package/dist/model/RWRoute.js +416 -0
  69. package/dist/model/RWRouter.d.ts +30 -0
  70. package/dist/model/RWRouter.d.ts.map +1 -0
  71. package/dist/model/RWRouter.js +186 -0
  72. package/dist/model/RWSDL.d.ts +21 -0
  73. package/dist/model/RWSDL.d.ts.map +1 -0
  74. package/dist/model/RWSDL.js +89 -0
  75. package/dist/model/RWSDLField.d.ts +31 -0
  76. package/dist/model/RWSDLField.d.ts.map +1 -0
  77. package/dist/model/RWSDLField.js +132 -0
  78. package/dist/model/RWService.d.ts +26 -0
  79. package/dist/model/RWService.d.ts.map +1 -0
  80. package/dist/model/RWService.js +76 -0
  81. package/dist/model/RWServiceFunction.d.ts +20 -0
  82. package/dist/model/RWServiceFunction.d.ts.map +1 -0
  83. package/dist/model/RWServiceFunction.js +100 -0
  84. package/dist/model/RWTOML.d.ts +12 -0
  85. package/dist/model/RWTOML.d.ts.map +1 -0
  86. package/dist/model/RWTOML.js +56 -0
  87. package/dist/model/index.d.ts +2 -0
  88. package/dist/model/index.d.ts.map +1 -0
  89. package/dist/model/index.js +13 -0
  90. package/dist/model/util/advanced_path_parser.d.ts +12 -0
  91. package/dist/model/util/advanced_path_parser.d.ts.map +1 -0
  92. package/dist/model/util/advanced_path_parser.js +38 -0
  93. package/dist/model/util/process_env.d.ts +23 -0
  94. package/dist/model/util/process_env.d.ts.map +1 -0
  95. package/dist/model/util/process_env.js +76 -0
  96. package/dist/outline/index.d.ts +3 -0
  97. package/dist/outline/index.d.ts.map +1 -0
  98. package/dist/outline/index.js +31 -0
  99. package/dist/outline/outline.d.ts +4 -0
  100. package/dist/outline/outline.d.ts.map +1 -0
  101. package/dist/outline/outline.js +260 -0
  102. package/dist/outline/types.d.ts +88 -0
  103. package/dist/outline/types.d.ts.map +1 -0
  104. package/dist/outline/types.js +73 -0
  105. package/dist/util.d.ts +2 -0
  106. package/dist/util.d.ts.map +1 -0
  107. package/dist/util.js +34 -0
  108. package/dist/x/Array.d.ts +4 -0
  109. package/dist/x/Array.d.ts.map +1 -0
  110. package/dist/x/Array.js +26 -0
  111. package/dist/x/URL.d.ts +15 -0
  112. package/dist/x/URL.d.ts.map +1 -0
  113. package/dist/x/URL.js +99 -0
  114. package/dist/x/child_process.d.ts +15 -0
  115. package/dist/x/child_process.d.ts.map +1 -0
  116. package/dist/x/child_process.js +51 -0
  117. package/dist/x/decorators.d.ts +3 -0
  118. package/dist/x/decorators.d.ts.map +1 -0
  119. package/dist/x/decorators.js +26 -0
  120. package/dist/x/path.d.ts +6 -0
  121. package/dist/x/path.d.ts.map +1 -0
  122. package/dist/x/path.js +53 -0
  123. package/dist/x/prisma.d.ts +19 -0
  124. package/dist/x/prisma.d.ts.map +1 -0
  125. package/dist/x/prisma.js +65 -0
  126. package/dist/x/ts-morph.d.ts +10 -0
  127. package/dist/x/ts-morph.d.ts.map +1 -0
  128. package/dist/x/ts-morph.js +56 -0
  129. package/dist/x/vscode-languageserver-types.d.ts +93 -0
  130. package/dist/x/vscode-languageserver-types.d.ts.map +1 -0
  131. package/dist/x/vscode-languageserver-types.js +421 -0
  132. package/dist/x/vscode-languageserver.d.ts +12 -0
  133. package/dist/x/vscode-languageserver.d.ts.map +1 -0
  134. package/dist/x/vscode-languageserver.js +61 -0
  135. package/dist/x/vscode.d.ts +126 -0
  136. package/dist/x/vscode.d.ts.map +1 -0
  137. package/dist/x/vscode.js +294 -0
  138. package/package.json +67 -0
@@ -0,0 +1,416 @@
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.RWRoute = void 0;
10
+ require("core-js/modules/esnext.json.parse.js");
11
+ var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/starts-with"));
12
+ var _endsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/ends-with"));
13
+ var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/array/is-array"));
14
+ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/filter"));
15
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/map"));
16
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/includes"));
17
+ var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/find"));
18
+ var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/keys"));
19
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
20
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
21
+ var _path = require("path");
22
+ var tsm = _interopRequireWildcard(require("ts-morph"));
23
+ var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
24
+ var _errors = require("../errors");
25
+ var _ide = require("../ide");
26
+ var _util = require("../util");
27
+ var _decorators = require("../x/decorators");
28
+ var _vscodeLanguageserverTypes2 = require("../x/vscode-languageserver-types");
29
+ var _advanced_path_parser = require("./util/advanced_path_parser");
30
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _class;
31
+ let RWRoute = exports.RWRoute = (_dec = (0, _decorators.lazy)(), _dec2 = (0, _decorators.lazy)(), _dec3 = (0, _decorators.lazy)(), _dec4 = (0, _decorators.lazy)(), _dec5 = (0, _decorators.lazy)(), _dec6 = (0, _decorators.lazy)(), _dec7 = (0, _decorators.lazy)(), _dec8 = (0, _decorators.lazy)(), _dec9 = (0, _decorators.lazy)(), _dec10 = (0, _decorators.lazy)(), _dec11 = (0, _decorators.lazy)(), _dec12 = (0, _decorators.lazy)(), _dec13 = (0, _decorators.lazy)(), _dec14 = (0, _decorators.lazy)(), _dec15 = (0, _decorators.lazy)(), _dec16 = (0, _decorators.lazy)(), _dec17 = (0, _decorators.lazy)(), _dec18 = (0, _decorators.lazy)(), _dec19 = (0, _decorators.lazy)(), _dec20 = (0, _decorators.lazy)(), _dec21 = (0, _decorators.lazy)(), _dec22 = (0, _decorators.lazy)(), _dec23 = (0, _decorators.lazy)(), _dec24 = (0, _decorators.lazy)(), _class = class RWRoute extends _ide.BaseNode {
32
+ constructor(
33
+ /**
34
+ * the <Route> tag
35
+ */
36
+ jsxNode, parent) {
37
+ super();
38
+ this.jsxNode = jsxNode;
39
+ this.parent = parent;
40
+ }
41
+ get id() {
42
+ // we cannot rely on the "path" attribute of the node
43
+ // it might not be unique (which is an error state, but valid while editing)
44
+ return this.parent.id + ' ' + this.jsxNode.getStart();
45
+ }
46
+ get location() {
47
+ return (0, _vscodeLanguageserverTypes2.LocationLike_toLocation)(this.jsxNode);
48
+ }
49
+ get isPrivate() {
50
+ const tagText = this.jsxNode.getParentIfKind(tsm.SyntaxKind.JsxElement)?.getOpeningElement()?.getTagNameNode()?.getText();
51
+ return tagText === 'Private' || tagText === 'PrivateSet';
52
+ }
53
+ get unauthenticated() {
54
+ if (!this.isPrivate) {
55
+ return undefined;
56
+ }
57
+ const a = this.jsxNode.getParentIfKind(tsm.SyntaxKind.JsxElement)?.getOpeningElement().getAttribute('unauthenticated');
58
+ if (!a) {
59
+ return undefined;
60
+ }
61
+ if (tsm.Node.isJsxAttribute(a)) {
62
+ const init = a.getInitializer();
63
+ if (tsm.Node.isStringLiteral(init)) {
64
+ return init.getLiteralValue();
65
+ }
66
+ }
67
+ return undefined;
68
+ }
69
+ get roles() {
70
+ if (!this.isPrivate) {
71
+ return undefined;
72
+ }
73
+ const a = this.jsxNode.getParentIfKind(tsm.SyntaxKind.JsxElement)?.getOpeningElement().getAttribute('roles');
74
+ if (!a) {
75
+ return undefined;
76
+ }
77
+ if (tsm.Node.isJsxAttribute(a)) {
78
+ const init = a.getInitializer();
79
+
80
+ // Handle string literals
81
+ if (tsm.Node.isStringLiteral(init)) {
82
+ const literalValue = init.getLiteralValue();
83
+
84
+ // Check if the string looks like an array with single quotes
85
+ if ((0, _startsWith.default)(literalValue).call(literalValue, '[') && (0, _endsWith.default)(literalValue).call(literalValue, ']')) {
86
+ try {
87
+ // Unescape the string by replacing single quotes with double quotes
88
+ const correctedLiteralValue = literalValue.replace(/'/g, '"');
89
+ // Attempt to parse as JSON array
90
+ const parsedValue = JSON.parse(correctedLiteralValue);
91
+ if ((0, _isArray.default)(parsedValue)) {
92
+ return parsedValue;
93
+ }
94
+ } catch {
95
+ // If parsing fails, return undefined
96
+ return undefined;
97
+ }
98
+ }
99
+
100
+ // If not an array, return the string value
101
+ return literalValue;
102
+ }
103
+
104
+ // Handle JSX expressions with array literals
105
+ if (tsm.Node.isJsxExpression(init)) {
106
+ const expr = init.getExpression();
107
+ if (tsm.Node.isArrayLiteralExpression(expr)) {
108
+ var _context, _context2;
109
+ return (0, _filter.default)(_context = (0, _map.default)(_context2 = expr.getElements()).call(_context2, element => {
110
+ if (tsm.Node.isStringLiteral(element)) {
111
+ return element.getLiteralValue();
112
+ }
113
+ return undefined;
114
+ })).call(_context, val => val !== undefined);
115
+ }
116
+ }
117
+ }
118
+ return undefined;
119
+ }
120
+ get hasParameters() {
121
+ var _context3;
122
+ if (!this.path) {
123
+ return false;
124
+ }
125
+ // KLUDGE: we need a good path parsing library here
126
+ return (0, _includes.default)(_context3 = this.path).call(_context3, '{');
127
+ }
128
+ get hasPrerender() {
129
+ return this.prerender;
130
+ }
131
+ get outlineLabel() {
132
+ if (this.isNotFound) {
133
+ return '404';
134
+ }
135
+ return this.path ?? '';
136
+ }
137
+ get outlineDescription() {
138
+ const fp = this.page?.filePath;
139
+ if (!fp) {
140
+ return undefined;
141
+ }
142
+ return (0, _path.basename)(fp);
143
+ }
144
+ get outlineLink() {
145
+ return (0, _vscodeLanguageserverTypes2.LocationLike_toHashLink)(this.location);
146
+ //return LocationLike_toTerminalLink(this.location)
147
+ }
148
+
149
+ /**
150
+ * The associated Redwood Page node, if any
151
+ */
152
+
153
+ get page() {
154
+ var _context4;
155
+ if (!this.page_identifier_str) {
156
+ return undefined;
157
+ }
158
+ return (0, _find.default)(_context4 = this.parent.parent.pages).call(_context4, p => p.constName === this.page_identifier_str);
159
+ }
160
+ /**
161
+ * <Route path="" page={THIS_IDENTIFIER}/>
162
+ */
163
+ get page_identifier() {
164
+ const a = this.jsxNode.getAttribute('page');
165
+ if (!a) {
166
+ return undefined;
167
+ }
168
+ if (tsm.Node.isJsxAttribute(a)) {
169
+ const init = a.getInitializer();
170
+ if (tsm.Node.isJsxExpression(init)) {
171
+ const expr = init.getExpression();
172
+ if (tsm.Node.isIdentifier(expr)) {
173
+ return expr;
174
+ }
175
+ }
176
+ }
177
+ return undefined;
178
+ }
179
+ get page_identifier_str() {
180
+ return this.page_identifier?.getText();
181
+ }
182
+ get name() {
183
+ return this.getStringAttr('name');
184
+ }
185
+ get path_errorMessage() {
186
+ // TODO: path validation is not strong enough
187
+ if (typeof this.path === 'undefined') {
188
+ return undefined;
189
+ }
190
+ try {
191
+ (0, _util.validateRoutePath)(this.path);
192
+ return undefined;
193
+ } catch (e) {
194
+ return e.toString();
195
+ }
196
+ }
197
+ get path() {
198
+ return this.getStringAttr('path');
199
+ }
200
+ get prerender() {
201
+ return this.getBoolAttr('prerender');
202
+ }
203
+
204
+ // TODO (STREAMING) Remove this once we're sure we don't want to do Render Modes
205
+ get renderMode() {
206
+ return this.getStringAttr('renderMode') || 'stream';
207
+ }
208
+ get path_literal_node() {
209
+ const a = this.jsxNode.getAttribute('path');
210
+ if (!a) {
211
+ return undefined;
212
+ }
213
+ if (tsm.Node.isJsxAttribute(a)) {
214
+ const init = a.getInitializer();
215
+ if (tsm.Node.isStringLiteral(init)) {
216
+ return init;
217
+ }
218
+ }
219
+ return undefined;
220
+ }
221
+ get isNotFound() {
222
+ return typeof this.jsxNode.getAttribute('notfound') !== 'undefined';
223
+ }
224
+ get redirect() {
225
+ return this.getStringAttr('redirect');
226
+ }
227
+ *diagnostics() {
228
+ if (this.page_identifier && !this.page) {
229
+ // normally this would be caught by TypeScript
230
+ // but Redwood has some "magic" import behavior going on
231
+ yield (0, _vscodeLanguageserverTypes2.err)(this.page_identifier, 'Page component not found');
232
+ }
233
+ if (this.path_errorMessage && this.path_literal_node) {
234
+ yield (0, _vscodeLanguageserverTypes2.err)(this.path_literal_node, this.path_errorMessage, _errors.RWError.INVALID_ROUTE_PATH_SYNTAX);
235
+ }
236
+ if (this.hasPathCollision) {
237
+ yield (0, _vscodeLanguageserverTypes2.err)(this.path_literal_node, 'Duplicate Path');
238
+ }
239
+ if (this.isPrivate && this.isNotFound) {
240
+ yield (0, _vscodeLanguageserverTypes2.err)(this.jsxNode, "The 'Not Found' page cannot be within a <PrivateSet> or a <Private> tag");
241
+ }
242
+ if (this.isNotFound && this.path) {
243
+ yield (0, _vscodeLanguageserverTypes2.err)(this.path_literal_node, "The 'Not Found' page cannot have a path");
244
+ }
245
+ }
246
+ *ideInfo() {
247
+ // definition: page identifier --> page
248
+ if (this.page && this.page_identifier) {
249
+ yield {
250
+ kind: 'Definition',
251
+ location: (0, _vscodeLanguageserverTypes2.Location_fromNode)(this.page_identifier),
252
+ target: (0, _vscodeLanguageserverTypes2.Location_fromFilePath)(this.page.filePath)
253
+ };
254
+ }
255
+ if (this.path && this.page) {
256
+ // const location = Location_fromNode(this.jsxNode!)
257
+ // yield { kind: 'Hover', location, text: 'Open Preview' }
258
+ }
259
+ yield* this.decorations();
260
+ const {
261
+ sampleLocalPreviewURL
262
+ } = this;
263
+ if (sampleLocalPreviewURL) {
264
+ const range = (0, _vscodeLanguageserverTypes2.Range_fromNode)(this.jsxNode);
265
+ yield {
266
+ kind: 'Hover',
267
+ location: {
268
+ uri: this.parent.uri,
269
+ range
270
+ },
271
+ hover: {
272
+ range,
273
+ contents: `[Open Preview](${sampleLocalPreviewURL})`
274
+ }
275
+ };
276
+ const {
277
+ path_literal_node
278
+ } = this;
279
+ if (path_literal_node) {
280
+ const range = (0, _vscodeLanguageserverTypes2.Range_fromNode)(this.path_literal_node);
281
+ yield {
282
+ kind: 'DocumentLink',
283
+ location: {
284
+ uri: this.parent.uri,
285
+ range
286
+ },
287
+ link: {
288
+ range,
289
+ target: sampleLocalPreviewURL,
290
+ tooltip: sampleLocalPreviewURL
291
+ }
292
+ };
293
+ }
294
+ }
295
+ }
296
+ get hasPathCollision() {
297
+ if (!this.path) {
298
+ return false;
299
+ }
300
+ const pathWithNoParamNames = removeParamNames(this.path);
301
+ for (const route2 of this.parent.routes) {
302
+ if (route2 === this) {
303
+ continue;
304
+ }
305
+ if (!route2.path) {
306
+ continue;
307
+ }
308
+ if (removeParamNames(route2.path) === pathWithNoParamNames) {
309
+ return true;
310
+ }
311
+ }
312
+ return false;
313
+ function removeParamNames(p) {
314
+ // TODO: implement
315
+ // foo/{bar}/baz --> foo/{}/baz
316
+ return p;
317
+ }
318
+ }
319
+ getBoolAttr(name) {
320
+ const attr = this.jsxNode.getAttribute(name);
321
+ // No attribute
322
+ if (!attr) {
323
+ return false;
324
+ }
325
+
326
+ // Attribute exists
327
+ if (tsm.Node.isJsxAttribute(attr)) {
328
+ const init = attr.getInitializer();
329
+
330
+ // Bool attributes with no initializer are true
331
+ // e.g. <Route prerender />
332
+ if (!init) {
333
+ return true;
334
+ }
335
+ if (tsm.Node.isJsxExpression(init)) {
336
+ // If it is explicitly set to true
337
+ // e.g. <Route prerender={true} />
338
+ return tsm.Node.isTrueLiteral(init.getExpression());
339
+ } else if (tsm.Node.isStringLiteral(init)) {
340
+ // If its using the incorrect string form, we're accepting it as true
341
+ // e.g. <Route prerender="true" />
342
+ const literalValue = init.getLiteralValue();
343
+ return literalValue === 'true';
344
+ }
345
+ }
346
+ return false;
347
+ }
348
+ getStringAttr(name) {
349
+ const a = this.jsxNode.getAttribute(name);
350
+ if (!a) {
351
+ return undefined;
352
+ }
353
+ if (tsm.Node.isJsxAttribute(a)) {
354
+ const init = a.getInitializer();
355
+ if (tsm.Node.isStringLiteral(init)) {
356
+ return init.getLiteralValue();
357
+ }
358
+ }
359
+ return undefined;
360
+ }
361
+ get parsedPath() {
362
+ if (!this.path) {
363
+ return undefined;
364
+ }
365
+ return (0, _advanced_path_parser.advanced_path_parser)(this.path);
366
+ }
367
+ *decorations() {
368
+ const pp = this.parsedPath;
369
+ if (!pp) {
370
+ return;
371
+ }
372
+ const uri = this.parent.uri;
373
+ const pos = (0, _vscodeLanguageserverTypes2.Range_fromNode)(this.path_literal_node).start;
374
+ const xxx = {
375
+ path_punctuation: pp.punctuationIndexes,
376
+ path_slash: pp.slashIndexes,
377
+ path_parameter: pp.paramRanges,
378
+ path_parameter_type: pp.paramTypeRanges
379
+ };
380
+ for (const style of (0, _keys.default)(xxx)) {
381
+ for (const x of xxx[style]) {
382
+ yield {
383
+ kind: 'Decoration',
384
+ style: style,
385
+ location: loc(x)
386
+ };
387
+ }
388
+ }
389
+ function loc(x) {
390
+ if (typeof x === 'number') {
391
+ return loc([x, x + 1]);
392
+ } else {
393
+ const start = (0, _vscodeLanguageserverTypes2.Position_translate)(pos, 0, x[0] + 1);
394
+ const end = (0, _vscodeLanguageserverTypes2.Position_translate)(pos, 0, x[1] + 1);
395
+ return {
396
+ uri,
397
+ range: _vscodeLanguageserverTypes.Range.create(start, end)
398
+ };
399
+ }
400
+ }
401
+ }
402
+
403
+ // TODO: we should get the URL of the server dynamically
404
+ get sampleLocalPreviewURL() {
405
+ const {
406
+ path
407
+ } = this;
408
+ if (!path) {
409
+ return undefined;
410
+ }
411
+ if ((0, _includes.default)(path).call(path, '{')) {
412
+ return undefined;
413
+ }
414
+ return `http://localhost:8910${path}`;
415
+ }
416
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "id", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "id"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "location", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "location"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "isPrivate", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "isPrivate"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "unauthenticated", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "unauthenticated"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "roles", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "roles"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "hasParameters", [_dec6], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "hasParameters"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "hasPrerender", [_dec7], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "hasPrerender"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "outlineLabel", [_dec8], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "outlineLabel"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "outlineDescription", [_dec9], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "outlineDescription"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "outlineLink", [_dec10], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "outlineLink"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "page", [_dec11], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "page"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "page_identifier", [_dec12], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "page_identifier"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "page_identifier_str", [_dec13], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "page_identifier_str"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "name", [_dec14], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "name"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "path_errorMessage", [_dec15], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "path_errorMessage"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "path", [_dec16], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "path"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "prerender", [_dec17], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "prerender"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "renderMode", [_dec18], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "renderMode"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "path_literal_node", [_dec19], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "path_literal_node"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "isNotFound", [_dec20], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "isNotFound"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "redirect", [_dec21], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "redirect"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "hasPathCollision", [_dec22], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "hasPathCollision"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "parsedPath", [_dec23], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "parsedPath"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "sampleLocalPreviewURL", [_dec24], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "sampleLocalPreviewURL"), _class.prototype), _class);
@@ -0,0 +1,30 @@
1
+ import type { CodeAction } from 'vscode-languageserver-types';
2
+ import type { CodeLensX } from '../ide';
3
+ import { FileNode } from '../ide';
4
+ import type { ExtendedDiagnostic } from '../x/vscode-languageserver-types';
5
+ import type { RWProject } from './RWProject';
6
+ import { RWRoute } from './RWRoute';
7
+ /**
8
+ * one per Routes.js
9
+ */
10
+ export declare class RWRouter extends FileNode {
11
+ filePath: string;
12
+ parent: RWProject;
13
+ constructor(filePath: string, parent: RWProject);
14
+ getFilePathForRoutePath(routePath: string): string | undefined;
15
+ getRoutePathForFilePath(filePath: string): string | undefined;
16
+ /**
17
+ * the `<Router>` tag
18
+ */
19
+ private get jsxNode();
20
+ /**
21
+ * One per `<Route>`
22
+ */
23
+ get routes(): RWRoute[];
24
+ private get numNotFoundPages();
25
+ ideInfo(): Generator<CodeLensX, void, unknown>;
26
+ get quickFix_addNotFoundpage(): CodeAction | undefined;
27
+ diagnostics(): Generator<ExtendedDiagnostic, void, unknown>;
28
+ children(): RWRoute[];
29
+ }
30
+ //# sourceMappingURL=RWRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RWRouter.d.ts","sourceRoot":"","sources":["../../src/model/RWRouter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,6BAA6B,CAAA;AASvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAIjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAO1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;GAEG;AACH,qBAAa,QAAS,SAAQ,QAAQ;IAE3B,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,SAAS;gBADjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS;IAKlB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAK9D,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAUrE;;OAEG;IACK,OAAO,KAAK,OAAO,GAI1B;IAED;;OAEG;IACH,IAAY,MAAM,cA+CjB;IAEO,OAAO,KAAK,gBAAgB,GAEnC;IAEA,OAAO;IAoBR,IAAY,wBAAwB,2BAoCnC;IAEA,WAAW;IAkCZ,QAAQ;CAGT"}
@@ -0,0 +1,186 @@
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 _repeat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/repeat"));
15
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
16
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
17
+ var tsm = _interopRequireWildcard(require("ts-morph"));
18
+ var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
19
+ var _errors = require("../errors");
20
+ var _ide = require("../ide");
21
+ var _Array = require("../x/Array");
22
+ var _decorators = require("../x/decorators");
23
+ var _URL = require("../x/URL");
24
+ var _vscodeLanguageserverTypes2 = require("../x/vscode-languageserver-types");
25
+ var _RWRoute = require("./RWRoute");
26
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class;
27
+ /**
28
+ * one per Routes.js
29
+ */
30
+ let RWRouter = exports.RWRouter = (_dec = (0, _decorators.memo)(), _dec2 = (0, _decorators.memo)(), _dec3 = (0, _decorators.lazy)(), _dec4 = (0, _decorators.lazy)(), _dec5 = (0, _decorators.lazy)(), _dec6 = (0, _decorators.lazy)(), _class = class RWRouter extends _ide.FileNode {
31
+ constructor(filePath, parent) {
32
+ super();
33
+ this.filePath = filePath;
34
+ this.parent = parent;
35
+ }
36
+ // this is used by the live preview
37
+ getFilePathForRoutePath(routePath) {
38
+ var _context;
39
+ // TODO: params
40
+ return (0, _find.default)(_context = this.routes).call(_context, r => r.path === routePath)?.page?.filePath;
41
+ }
42
+ // this is used by the live preview
43
+ getRoutePathForFilePath(filePath) {
44
+ var _context2, _context3, _context4;
45
+ // TODO: params
46
+ const path = (0, _find.default)(_context2 = this.parent.pages).call(_context2, p => p.filePath === filePath)?.route?.path;
47
+ if (((_context3 = path) == null ? void 0 : (0, _bind.default)(_context4 = Function.call).call(_context4, (0, _includes.default)(_context3), _context3))?.('{')) {
48
+ return;
49
+ }
50
+ return path;
51
+ }
52
+
53
+ /**
54
+ * the `<Router>` tag
55
+ */
56
+ get jsxNode() {
57
+ var _context5;
58
+ return (0, _find.default)(_context5 = this.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxOpeningElement)).call(_context5, x => x.getTagNameNode().getText() === 'Router');
59
+ }
60
+
61
+ /**
62
+ * One per `<Route>`
63
+ */
64
+ get routes() {
65
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
66
+ const self = this;
67
+ return (0, _Array.iter)(function* () {
68
+ var _context6;
69
+ if (!self.jsxNode) {
70
+ return;
71
+ }
72
+ // TODO: make sure that they are nested within the <Router> tag
73
+ // we are not checking it right now
74
+
75
+ const sets = (0, _filter.default)(_context6 = self.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxElement)).call(_context6, x => {
76
+ const tagName = x.getOpeningElement().getTagNameNode().getText();
77
+ return tagName === 'Set' || tagName === 'Private' || tagName === 'PrivateSet';
78
+ });
79
+ const prerenderSets = (0, _filter.default)(sets).call(sets, set => set.getOpeningElement().getAttribute('prerender'));
80
+ for (const set of prerenderSets) {
81
+ for (const x of set.getDescendantsOfKind(tsm.SyntaxKind.JsxSelfClosingElement)) {
82
+ const tagName = x.getTagNameNode().getText();
83
+ // Add prerender prop from <Set> if not already present
84
+ if (tagName === 'Route' && !x.getAttribute('prerender')) {
85
+ x.insertAttribute(0, {
86
+ name: 'prerender'
87
+ });
88
+ }
89
+ }
90
+ }
91
+ for (const x of self.sf.getDescendantsOfKind(tsm.SyntaxKind.JsxSelfClosingElement)) {
92
+ const tagName = x.getTagNameNode().getText();
93
+ if (tagName === 'Route') {
94
+ yield new _RWRoute.RWRoute(x, self);
95
+ }
96
+ }
97
+ });
98
+ }
99
+ get numNotFoundPages() {
100
+ var _context7;
101
+ return (0, _filter.default)(_context7 = this.routes).call(_context7, r => r.isNotFound).length;
102
+ }
103
+ *ideInfo() {
104
+ if (this.jsxNode) {
105
+ const location = (0, _vscodeLanguageserverTypes2.Location_fromNode)(this.jsxNode);
106
+ const codeLens = {
107
+ range: location.range,
108
+ command: _vscodeLanguageserverTypes.Command.create('Create Page...', 'redwoodjs.cli', 'generate page...', this.parent.projectRoot)
109
+ };
110
+ yield {
111
+ kind: 'CodeLens',
112
+ location,
113
+ codeLens
114
+ };
115
+ }
116
+ }
117
+ get quickFix_addNotFoundpage() {
118
+ var _context8, _context9;
119
+ if (!this.jsxNode) {
120
+ return undefined;
121
+ }
122
+ const change = new _vscodeLanguageserverTypes.WorkspaceChange({
123
+ documentChanges: []
124
+ });
125
+ let uri = (0, _URL.URL_file)(this.parent.defaultNotFoundPageFilePath);
126
+ const p = (0, _find.default)(_context8 = this.parent.pages).call(_context8, p => p.basenameNoExt === 'NotFoundPage');
127
+ if (p) {
128
+ uri = p.uri;
129
+ // page already exists, we just need to add the <Route/>
130
+ } else {
131
+ change.createFile(uri);
132
+ change.getTextEditChange({
133
+ uri,
134
+ version: null
135
+ }).insert(_vscodeLanguageserverTypes.Position.create(0, 0), `export default () => <div>Not Found</div>`);
136
+ }
137
+ // add <Route/>
138
+ const loc = (0, _vscodeLanguageserverTypes2.LocationLike_toLocation)(this.jsxNode);
139
+ const lastRoute = this.routes[this.routes.length - 1];
140
+ const lastRouteLoc = (0, _vscodeLanguageserverTypes2.LocationLike_toLocation)(lastRoute.jsxNode);
141
+ const textEditChange = change.getTextEditChange({
142
+ uri: loc.uri,
143
+ version: null
144
+ });
145
+ const indent = (0, _repeat.default)(_context9 = ' ').call(_context9, lastRouteLoc.range.start.character);
146
+ textEditChange.insert(lastRouteLoc.range.end, `\n${indent}<Route notfound page={NotFoundPage}/>\n`);
147
+ return {
148
+ title: 'Create default Not Found Page',
149
+ edit: change.edit
150
+ };
151
+ }
152
+ *diagnostics() {
153
+ if (!this.fileExists) {
154
+ // should we assign this error to the project? to redwood.toml?
155
+ const uri = (0, _URL.URL_file)(this.parent.projectRoot, 'redwood.toml');
156
+ const message = `Routes.js does not exist`;
157
+ yield (0, _vscodeLanguageserverTypes2.err)(uri, message);
158
+ // TODO: add quickFix (create a simple Routes.js)
159
+ return; // stop checking for errors if the file doesn't exist
160
+ }
161
+ if (!this.jsxNode) {
162
+ return;
163
+ }
164
+ if (this.numNotFoundPages === 0) {
165
+ const {
166
+ uri,
167
+ range
168
+ } = (0, _vscodeLanguageserverTypes2.LocationLike_toLocation)(this.jsxNode);
169
+ yield {
170
+ uri,
171
+ diagnostic: {
172
+ range,
173
+ message: "You must specify a 'notfound' page",
174
+ severity: _vscodeLanguageserverTypes.DiagnosticSeverity.Error
175
+ },
176
+ quickFix: async () => this.quickFix_addNotFoundpage
177
+ };
178
+ } else if (this.numNotFoundPages > 1) {
179
+ const e = (0, _vscodeLanguageserverTypes2.err)(this.jsxNode, "You must specify exactly one 'notfound' page", _errors.RWError.NOTFOUND_PAGE_NOT_DEFINED);
180
+ yield e;
181
+ }
182
+ }
183
+ children() {
184
+ return [...this.routes];
185
+ }
186
+ }, (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), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "quickFix_addNotFoundpage", [_dec6], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "quickFix_addNotFoundpage"), _class.prototype), _class);
@@ -0,0 +1,21 @@
1
+ import * as tsm from 'ts-morph';
2
+ import { FileNode } from '../ide';
3
+ import type { RWProject } from './RWProject';
4
+ import { RWSDLField } from './RWSDLField';
5
+ export declare class RWSDL extends FileNode {
6
+ filePath: string;
7
+ parent: RWProject;
8
+ constructor(filePath: string, parent: RWProject);
9
+ /**
10
+ * The Template Literal node (string) that contains the schema
11
+ */
12
+ get schemaStringNode(): tsm.NoSubstitutionTemplateLiteral | undefined;
13
+ get schemaString(): string | undefined;
14
+ get serviceFilePath(): string;
15
+ get service(): import("./RWService").RWService | undefined;
16
+ get name(): string;
17
+ get implementableFields(): RWSDLField[];
18
+ children(): RWSDLField[];
19
+ diagnostics(): Generator<import("../x/vscode-languageserver-types").ExtendedDiagnostic, void, unknown>;
20
+ }
21
+ //# sourceMappingURL=RWSDL.d.ts.map
@@ -0,0 +1 @@
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,QAAQ,CAAA;AAKjC,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"}