@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,111 @@
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.RWCell = void 0;
10
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
11
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
12
+ var _graphql = require("graphql");
13
+ var tsm = _interopRequireWildcard(require("ts-morph"));
14
+ var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
15
+ var _decorators = require("../x/decorators");
16
+ var _vscodeLanguageserverTypes2 = require("../x/vscode-languageserver-types");
17
+ var _RWComponent = require("./RWComponent");
18
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class;
19
+ let RWCell = exports.RWCell = (_dec = (0, _decorators.lazy)(), _dec2 = (0, _decorators.lazy)(), _dec3 = (0, _decorators.lazy)(), _dec4 = (0, _decorators.lazy)(), _dec5 = (0, _decorators.lazy)(), _class = class RWCell extends _RWComponent.RWComponent {
20
+ /**
21
+ * A "Cell" is a component that ends in `Cell.{js, jsx, tsx}`, has no
22
+ * default export AND exports `QUERY`
23
+ **/
24
+ get isCell() {
25
+ return !this.hasDefaultExport && this.exportedSymbols.has('QUERY');
26
+ }
27
+
28
+ // TODO: Move to RWCellQuery
29
+ get queryStringNode() {
30
+ const i = this.sf.getVariableDeclaration('QUERY')?.getInitializer();
31
+ if (!i) {
32
+ return undefined;
33
+ }
34
+ // TODO: do we allow other kinds of strings? or just tagged literals?
35
+ if (tsm.Node.isTaggedTemplateExpression(i)) {
36
+ const t = i.getTemplate();
37
+ if (tsm.Node.isNoSubstitutionTemplateLiteral(t)) {
38
+ return t;
39
+ }
40
+ }
41
+ return undefined;
42
+ }
43
+
44
+ // TODO: Move to RWCellQuery
45
+ get queryString() {
46
+ return this.queryStringNode?.getLiteralText();
47
+ }
48
+
49
+ // TODO: Move to RWCellQuery
50
+ get queryAst() {
51
+ const qs = this.queryString;
52
+ if (!qs) {
53
+ return undefined;
54
+ }
55
+ try {
56
+ return (0, _graphql.parse)(qs);
57
+ } catch (e) {
58
+ console.error("Can't parse the graphql query string in", this.filePath);
59
+ console.error(e);
60
+ return undefined;
61
+ }
62
+ }
63
+
64
+ // TODO: Move to RWCellQuery
65
+ get queryOperationName() {
66
+ const ast = this.queryAst;
67
+ if (!ast) {
68
+ return undefined;
69
+ }
70
+ for (const def of ast.definitions) {
71
+ if (def.kind == _graphql.Kind.OPERATION_DEFINITION) {
72
+ return def?.name?.value;
73
+ }
74
+ }
75
+ return undefined;
76
+ }
77
+ *diagnostics() {
78
+ // check that QUERY and Success are exported
79
+ if (!this.exportedSymbols.has('QUERY')) {
80
+ yield (0, _vscodeLanguageserverTypes2.err)(this.uri, 'Every Cell MUST export a QUERY variable (GraphQL query string)');
81
+ }
82
+ try {
83
+ if (!this.queryOperationName) {
84
+ yield {
85
+ uri: this.uri,
86
+ diagnostic: {
87
+ range: (0, _vscodeLanguageserverTypes2.Range_fromNode)(this.queryStringNode),
88
+ message: 'We recommend that you name your query operation',
89
+ severity: _vscodeLanguageserverTypes.DiagnosticSeverity.Warning
90
+ }
91
+ };
92
+ }
93
+ } catch (e) {
94
+ // Maybe the AST has a syntax error...
95
+ yield {
96
+ uri: this.uri,
97
+ diagnostic: {
98
+ // TODO: Try to figure out if we can point directly to the syntax error.
99
+ range: (0, _vscodeLanguageserverTypes2.Range_fromNode)(this.sf.getVariableDeclaration('QUERY')),
100
+ message: e.message,
101
+ severity: _vscodeLanguageserverTypes.DiagnosticSeverity.Error
102
+ }
103
+ };
104
+ }
105
+
106
+ // TODO: check that exported QUERY is semantically valid GraphQL (fields exist)
107
+ if (!this.exportedSymbols.has('Success')) {
108
+ yield (0, _vscodeLanguageserverTypes2.err)(this.uri, 'Every Cell MUST export a Success variable (React Component)');
109
+ }
110
+ }
111
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "isCell", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "isCell"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "queryStringNode", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "queryStringNode"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "queryString", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "queryString"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "queryAst", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "queryAst"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "queryOperationName", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "queryOperationName"), _class.prototype), _class);
@@ -0,0 +1,11 @@
1
+ import { FileNode } from '../ide';
2
+ import type { RWProject } from './RWProject';
3
+ export declare class RWComponent extends FileNode {
4
+ filePath: string;
5
+ parent: RWProject;
6
+ constructor(filePath: string, parent: RWProject);
7
+ get hasDefaultExport(): boolean;
8
+ get stories(): never[];
9
+ get exportedSymbols(): Set<string>;
10
+ }
11
+ //# sourceMappingURL=RWComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RWComponent.d.ts","sourceRoot":"","sources":["../../src/model/RWComponent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAGjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,qBAAa,WAAY,SAAQ,QAAQ;IAE9B,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,SAAS;gBADjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS;IAK1B,IAAY,gBAAgB,IAAI,OAAO,CAKtC;IAED,IAAY,OAAO,YAIlB;IAED,IAAY,eAAe,gBAW1B;CACF"}
@@ -0,0 +1,42 @@
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.RWComponent = void 0;
10
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/set"));
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 tsm = _interopRequireWildcard(require("ts-morph"));
14
+ var _ide = require("../ide");
15
+ var _decorators = require("../x/decorators");
16
+ var _dec, _dec2, _dec3, _class;
17
+ let RWComponent = exports.RWComponent = (_dec = (0, _decorators.lazy)(), _dec2 = (0, _decorators.lazy)(), _dec3 = (0, _decorators.lazy)(), _class = class RWComponent extends _ide.FileNode {
18
+ constructor(filePath, parent) {
19
+ super();
20
+ this.filePath = filePath;
21
+ this.parent = parent;
22
+ }
23
+ get hasDefaultExport() {
24
+ // TODO: Is this enough to test a default export?
25
+ return this.sf.getDescendantsOfKind(tsm.SyntaxKind.ExportAssignment).length > 0;
26
+ }
27
+ get stories() {
28
+ // TODO: this is a placeholder
29
+ // we could list all the (storybook) stories related to this component here
30
+ return [];
31
+ }
32
+ get exportedSymbols() {
33
+ // KLUDGE!
34
+ const ss = new _set.default();
35
+ for (const d of this.sf.getDescendantsOfKind(tsm.SyntaxKind.VariableDeclaration)) {
36
+ if (d.isExported()) {
37
+ ss.add(d.getName());
38
+ }
39
+ }
40
+ return ss;
41
+ }
42
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "hasDefaultExport", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "hasDefaultExport"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "stories", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "stories"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "exportedSymbols", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "exportedSymbols"), _class.prototype), _class);
@@ -0,0 +1,64 @@
1
+ import type * as tsm from 'ts-morph';
2
+ import type { Location } from 'vscode-languageserver';
3
+ import type { CodeLensX, Definition, HoverX, Reference } from '../ide';
4
+ import { BaseNode } from '../ide';
5
+ import type { ExtendedDiagnostic } from '../x/vscode-languageserver-types';
6
+ import type { RWProject } from './RWProject';
7
+ type EnvVarMap = Record<string, string>;
8
+ export declare class RWEnvHelper extends BaseNode {
9
+ parent: RWProject;
10
+ constructor(parent: RWProject);
11
+ get id(): string;
12
+ bailOutOnCollection(): boolean;
13
+ /**
14
+ * parse .env
15
+ * return undefined if not present
16
+ * NOTE: It does not apply defaults (see env_merged)
17
+ */
18
+ get env(): EnvVarMap | undefined;
19
+ /**
20
+ * .env.defaults
21
+ * return undefined if not present
22
+ */
23
+ get env_defaults(): EnvVarMap | undefined;
24
+ get api_prisma_env(): import("dotenv").DotenvParseOutput | undefined;
25
+ /**
26
+ * .env.defaults + .env
27
+ * uses the same algorithm that env-defaults does (Object.assign(), which is equivalent to object spread addition)
28
+ */
29
+ get env_default_merged(): EnvVarMap;
30
+ /**
31
+ * - starts with .env + .env.defaults
32
+ * - allows any variables prefixed with 'REDWOOD_ENV_'
33
+ * - applies the "include" rule on the rest
34
+ * @param include
35
+ */
36
+ private env_default_merged_filtered;
37
+ private _dotenv;
38
+ get env_available_to_api(): EnvVarMap;
39
+ get env_available_to_web(): EnvVarMap;
40
+ children(): ProcessDotEnvExpression[];
41
+ get process_env_expressions(): ProcessDotEnvExpression[];
42
+ }
43
+ /**
44
+ * An occurrence of process.env somewhere in the codebase
45
+ */
46
+ declare class ProcessDotEnvExpression extends BaseNode {
47
+ parent: RWEnvHelper;
48
+ kind: 'api' | 'web' | 'prisma';
49
+ key: string;
50
+ node: tsm.Node | Location;
51
+ constructor(parent: RWEnvHelper, kind: 'api' | 'web' | 'prisma', key: string, node: tsm.Node | Location);
52
+ bailOutOnCollection(uri: string): boolean;
53
+ get id(): string;
54
+ get side(): "api" | "web";
55
+ get location(): Location;
56
+ ideInfo(): Generator<Definition | Reference | CodeLensX | HoverX, void, unknown>;
57
+ diagnostics(): Generator<ExtendedDiagnostic, void, unknown>;
58
+ get value_definition_file_basename(): ".env" | ".env.defaults" | undefined;
59
+ get value_definition_location(): Location | undefined;
60
+ get value_as_available(): string;
61
+ private render;
62
+ }
63
+ export {};
64
+ //# sourceMappingURL=RWEnvHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RWEnvHelper.d.ts","sourceRoot":"","sources":["../../src/model/RWEnvHelper.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,GAAG,MAAM,UAAU,CAAA;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAKjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAO1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEvC,qBAAa,WAAY,SAAQ,QAAQ;IACpB,MAAM,EAAE,SAAS;gBAAjB,MAAM,EAAE,SAAS;IAIpC,IAAY,EAAE,WAGb;IAED,mBAAmB;IAMnB;;;;OAIG;IACH,IAAY,GAAG,IAAI,SAAS,GAAG,SAAS,CAEvC;IAED;;;OAGG;IACH,IAAY,YAAY,IAAI,SAAS,GAAG,SAAS,CAEhD;IAED,IAAY,cAAc,mDAEzB;IAED;;;OAGG;IACH,IAAY,kBAAkB,IAAI,SAAS,CAE1C;IAED;;;;;OAKG;IACH,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,OAAO;IAQf,IAAY,oBAAoB,cAM/B;IAED,IAAY,oBAAoB,cAI/B;IAED,QAAQ;IAIR,IAAY,uBAAuB,8BAgBlC;CACF;AAED;;GAEG;AACH,cAAM,uBAAwB,SAAQ,QAAQ;IAEnC,MAAM,EAAE,WAAW;IACnB,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ;IAC9B,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,QAAQ;gBAHzB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,EAC9B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,QAAQ;IAKlC,mBAAmB,CAAC,GAAG,EAAE,MAAM;IAO/B,IAAY,EAAE,WAIb;IAED,IAAY,IAAI,kBAEf;IAED,IAAY,QAAQ,aAEnB;IAEA,OAAO;IAQP,WAAW;IAQZ,IAAY,8BAA8B,yCAYzC;IAED,IAAY,yBAAyB,IAAI,QAAQ,GAAG,SAAS,CAa5D;IAED,IAAY,kBAAkB,WAM7B;IAED,OAAO,CAAE,MAAM;CA+FhB"}
@@ -0,0 +1,295 @@
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.RWEnvHelper = void 0;
10
+ var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/starts-with"));
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 _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/map"));
14
+ var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/array/from"));
15
+ var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
16
+ var _findIndex = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/find-index"));
17
+ var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
18
+ var _path = require("path");
19
+ var dotenv = _interopRequireWildcard(require("dotenv-defaults"));
20
+ var _fsExtra = require("fs-extra");
21
+ var _lodash = require("lodash");
22
+ var _vscodeLanguageserver = require("vscode-languageserver");
23
+ var _ide = require("../ide");
24
+ var _decorators = require("../x/decorators");
25
+ var _prisma = require("../x/prisma");
26
+ var _URL = require("../x/URL");
27
+ var _vscode = require("../x/vscode");
28
+ var _vscodeLanguageserverTypes = require("../x/vscode-languageserver-types");
29
+ var _process_env = require("./util/process_env");
30
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _class2;
31
+ let RWEnvHelper = exports.RWEnvHelper = (_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)(), _class = class RWEnvHelper extends _ide.BaseNode {
32
+ constructor(parent) {
33
+ super();
34
+ this.parent = parent;
35
+ }
36
+ get id() {
37
+ // this is an internal node. it is not associated to any particular file
38
+ return this.parent.id + ' envHelper';
39
+ }
40
+ bailOutOnCollection() {
41
+ // we need this node to participate in all collection requests
42
+ // because it will emit info and diagnostics for files all over the codebase
43
+ return false;
44
+ }
45
+
46
+ /**
47
+ * parse .env
48
+ * return undefined if not present
49
+ * NOTE: It does not apply defaults (see env_merged)
50
+ */
51
+ get env() {
52
+ return this._dotenv('.env');
53
+ }
54
+
55
+ /**
56
+ * .env.defaults
57
+ * return undefined if not present
58
+ */
59
+ get env_defaults() {
60
+ return this._dotenv('.env.defaults');
61
+ }
62
+ get api_prisma_env() {
63
+ return this._dotenv('api/prisma/.env');
64
+ }
65
+
66
+ /**
67
+ * .env.defaults + .env
68
+ * uses the same algorithm that env-defaults does (Object.assign(), which is equivalent to object spread addition)
69
+ */
70
+ get env_default_merged() {
71
+ return {
72
+ ...(this.env_defaults ?? {}),
73
+ ...(this.env ?? {})
74
+ };
75
+ }
76
+
77
+ /**
78
+ * - starts with .env + .env.defaults
79
+ * - allows any variables prefixed with 'REDWOOD_ENV_'
80
+ * - applies the "include" rule on the rest
81
+ * @param include
82
+ */
83
+ env_default_merged_filtered(include) {
84
+ return (0, _lodash.pickBy)(this.env_default_merged, (_v, k) => {
85
+ var _context, _context2;
86
+ return (0, _startsWith.default)(k).call(k, 'REDWOOD_ENV_') || ((_context = include) == null ? void 0 : (0, _bind.default)(_context2 = Function.call).call(_context2, (0, _includes.default)(_context), _context))?.(k);
87
+ });
88
+ }
89
+ _dotenv(f) {
90
+ const file = (0, _path.join)(this.parent.projectRoot, f);
91
+ if (!(0, _fsExtra.existsSync)(file)) {
92
+ return undefined;
93
+ }
94
+ return dotenv.parse((0, _fsExtra.readFileSync)(file, 'utf-8'));
95
+ }
96
+ get env_available_to_api() {
97
+ // in the API side, all variables are visible
98
+ return this.env_default_merged;
99
+ // return this.env_merged_filter(
100
+ // this.parent.redwoodTOML.api_includeEnvironmentVariables ?? []
101
+ // )
102
+ }
103
+ get env_available_to_web() {
104
+ return this.env_default_merged_filtered(this.parent.redwoodTOML.web_includeEnvironmentVariables ?? []);
105
+ }
106
+ children() {
107
+ return [...this.process_env_expressions];
108
+ }
109
+ get process_env_expressions() {
110
+ var _context3, _context4;
111
+ // TODO: make this async (this is globbing around quite a bit)
112
+ const {
113
+ pathHelper
114
+ } = this.parent;
115
+ const api = (0, _map.default)(_context3 = (0, _process_env.process_env_findAll)(pathHelper.api.base)).call(_context3, x => new ProcessDotEnvExpression(this, 'api', x.key, x.node));
116
+ const web = (0, _map.default)(_context4 = (0, _process_env.process_env_findAll)(pathHelper.web.base)).call(_context4, x => new ProcessDotEnvExpression(this, 'web', x.key, x.node));
117
+ const prisma = (0, _from.default)((0, _prisma.prisma_parseEnvExpressionsInFile)(pathHelper.api.dbSchema));
118
+ const pp = (0, _map.default)(prisma).call(prisma, x => new ProcessDotEnvExpression(this, 'prisma', x.key, x.location));
119
+ return [...api, ...web, ...pp];
120
+ }
121
+ }, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "id", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "id"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "env", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "env"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "env_defaults", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "env_defaults"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "api_prisma_env", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "api_prisma_env"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "env_default_merged", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "env_default_merged"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "env_available_to_api", [_dec6], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "env_available_to_api"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "env_available_to_web", [_dec7], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "env_available_to_web"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "process_env_expressions", [_dec8], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "process_env_expressions"), _class.prototype), _class);
122
+ /**
123
+ * An occurrence of process.env somewhere in the codebase
124
+ */
125
+ let ProcessDotEnvExpression = (_dec9 = (0, _decorators.lazy)(), _dec10 = (0, _decorators.lazy)(), _dec11 = (0, _decorators.lazy)(), _dec12 = (0, _decorators.lazy)(), _dec13 = (0, _decorators.lazy)(), _dec14 = (0, _decorators.lazy)(), _class2 = class ProcessDotEnvExpression extends _ide.BaseNode {
126
+ constructor(parent, kind, key, node) {
127
+ super();
128
+ this.parent = parent;
129
+ this.kind = kind;
130
+ this.key = key;
131
+ this.node = node;
132
+ }
133
+ bailOutOnCollection(uri) {
134
+ if (this.location.uri !== uri) {
135
+ return true;
136
+ }
137
+ return false;
138
+ }
139
+ get id() {
140
+ // this is an internal node. it is not associated to any particular file
141
+ // we just need to make sure the ID is unique and correctly nested
142
+ return this.parent.id + ' ' + (0, _vscodeLanguageserverTypes.LocationLike_toHashLink)(this.location);
143
+ }
144
+ get side() {
145
+ return this.kind === 'web' ? 'web' : 'api';
146
+ }
147
+ get location() {
148
+ return (0, _vscodeLanguageserverTypes.LocationLike_toLocation)(this.node);
149
+ }
150
+ *ideInfo() {
151
+ for (const x of this.render()) {
152
+ if (!(0, _vscodeLanguageserverTypes.ExtendedDiagnostic_is)(x)) {
153
+ yield x;
154
+ }
155
+ }
156
+ }
157
+ *diagnostics() {
158
+ for (const x of this.render()) {
159
+ if ((0, _vscodeLanguageserverTypes.ExtendedDiagnostic_is)(x)) {
160
+ yield x;
161
+ }
162
+ }
163
+ }
164
+ get value_definition_file_basename() {
165
+ const {
166
+ key,
167
+ parent: {
168
+ env,
169
+ env_defaults
170
+ }
171
+ } = this;
172
+ if (env?.[key]) {
173
+ return '.env';
174
+ }
175
+ if (env_defaults?.[key]) {
176
+ return '.env.defaults';
177
+ }
178
+ return undefined;
179
+ }
180
+ get value_definition_location() {
181
+ const x = this.value_definition_file_basename;
182
+ if (!x) {
183
+ return undefined;
184
+ }
185
+ const file = (0, _path.join)(this.parent.parent.projectRoot, x);
186
+ const content = (0, _fsExtra.readFileSync)(file).toString();
187
+ const lines = content.split('\n');
188
+ const index = (0, _findIndex.default)(lines).call(lines, l => (0, _startsWith.default)(l).call(l, this.key + '='));
189
+ return {
190
+ uri: (0, _URL.URL_file)(file),
191
+ range: _vscodeLanguageserver.Range.create(index, 0, index, lines[index].length)
192
+ };
193
+ }
194
+ get value_as_available() {
195
+ if (this.side === 'web') {
196
+ return this.parent.env_available_to_web[this.key];
197
+ }
198
+ const v = this.parent.env_available_to_api[this.key];
199
+ return v;
200
+ }
201
+ *render() {
202
+ const {
203
+ key,
204
+ location,
205
+ value_as_available
206
+ } = this;
207
+ const {
208
+ uri,
209
+ range
210
+ } = location;
211
+
212
+ // show reference to value definition
213
+ if (this.value_definition_location) {
214
+ yield {
215
+ kind: 'Reference',
216
+ location,
217
+ target: this.value_definition_location
218
+ };
219
+ yield {
220
+ kind: 'Definition',
221
+ location,
222
+ target: this.value_definition_location
223
+ };
224
+ }
225
+ // show hover with the actual value, if present
226
+ if (typeof value_as_available !== 'undefined') {
227
+ yield {
228
+ kind: 'Hover',
229
+ location,
230
+ hover: {
231
+ range: location.range,
232
+ contents: `${key}=${value_as_available} (${this.value_definition_file_basename ?? ''})`
233
+ }
234
+ };
235
+ if (typeof value_as_available !== 'undefined' && this.value_definition_location) {
236
+ const title = `${key}=${value_as_available}`;
237
+ const command = {
238
+ ...(0, _vscode.Command_open)(this.value_definition_location),
239
+ title
240
+ };
241
+ const codelens = {
242
+ kind: 'CodeLens',
243
+ location,
244
+ codeLens: {
245
+ range,
246
+ command
247
+ }
248
+ };
249
+ // TODO: we need to add middleware to the LSP client
250
+ // so the uri (string) is converted to a vscode.Uri
251
+ // https://github.com/microsoft/vscode-languageserver-node/issues/495
252
+ // eslint-disable-next-line no-constant-condition
253
+ if (false) {
254
+ yield codelens;
255
+ }
256
+ }
257
+ }
258
+ if (typeof value_as_available === 'undefined') {
259
+ // the value is not available
260
+ // there are a few scenarios here...
261
+ if (this.parent.env_default_merged[key]) {
262
+ // value is actually in the merged env, but it is not visible here
263
+ // this is probably because the user forgot to add an includeEnvironmentVariables rule
264
+ const snippet = `
265
+ [${this.side}]
266
+ includeEnvironmentVariables = ['${this.key}']`;
267
+ yield {
268
+ uri,
269
+ diagnostic: {
270
+ range,
271
+ message: `
272
+ This env variable is present in '${this.value_definition_file_basename}',
273
+ but it won't be available to your app in production *unless* you add it to includeEnvironmentVariables.
274
+ Tip: add the following to your redwood.toml:
275
+ ${snippet}
276
+ `,
277
+ severity: _vscodeLanguageserver.DiagnosticSeverity.Warning
278
+ // TODO: quickFix
279
+ }
280
+ };
281
+ } else {
282
+ // the value is simply not visible
283
+ yield {
284
+ uri,
285
+ diagnostic: {
286
+ range,
287
+ message: `env value ${key} is not available. add it to your .env file`,
288
+ severity: _vscodeLanguageserver.DiagnosticSeverity.Warning
289
+ // TODO: add a quickfix?
290
+ }
291
+ };
292
+ }
293
+ }
294
+ }
295
+ }, (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "id", [_dec9], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "id"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "side", [_dec10], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "side"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "location", [_dec11], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "location"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "value_definition_file_basename", [_dec12], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "value_definition_file_basename"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "value_definition_location", [_dec13], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "value_definition_location"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "value_as_available", [_dec14], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "value_as_available"), _class2.prototype), _class2);
@@ -0,0 +1,11 @@
1
+ import { FileNode } from '../ide';
2
+ import type { RWProject } from './RWProject';
3
+ /**
4
+ * functions exist in the /functions folder
5
+ */
6
+ export declare class RWFunction extends FileNode {
7
+ filePath: string;
8
+ parent: RWProject;
9
+ constructor(filePath: string, parent: RWProject);
10
+ }
11
+ //# sourceMappingURL=RWFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RWFunction.d.ts","sourceRoot":"","sources":["../../src/model/RWFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C;;GAEG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IAE7B,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,SAAS;gBADjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS;CAI3B"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.RWFunction = void 0;
8
+ var _ide = require("../ide");
9
+ /**
10
+ * functions exist in the /functions folder
11
+ */
12
+ class RWFunction extends _ide.FileNode {
13
+ constructor(filePath, parent) {
14
+ super();
15
+ this.filePath = filePath;
16
+ this.parent = parent;
17
+ }
18
+ }
19
+ exports.RWFunction = RWFunction;
@@ -0,0 +1,11 @@
1
+ import { FileNode } from '../ide';
2
+ import type { RWProject } from './RWProject';
3
+ /**
4
+ * layouts live in the src/layouts folder
5
+ */
6
+ export declare class RWLayout extends FileNode {
7
+ filePath: string;
8
+ parent: RWProject;
9
+ constructor(filePath: string, parent: RWProject);
10
+ }
11
+ //# sourceMappingURL=RWLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RWLayout.d.ts","sourceRoot":"","sources":["../../src/model/RWLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C;;GAEG;AACH,qBAAa,QAAS,SAAQ,QAAQ;IAE3B,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,SAAS;gBADjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS;CAI3B"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.RWLayout = void 0;
8
+ var _ide = require("../ide");
9
+ /**
10
+ * layouts live in the src/layouts folder
11
+ */
12
+ class RWLayout extends _ide.FileNode {
13
+ constructor(filePath, parent) {
14
+ super();
15
+ this.filePath = filePath;
16
+ this.parent = parent;
17
+ }
18
+ }
19
+ exports.RWLayout = RWLayout;
@@ -0,0 +1,13 @@
1
+ import { FileNode } from '../ide';
2
+ import type { RWProject } from './RWProject';
3
+ export declare class RWPage extends FileNode {
4
+ constName: string;
5
+ path: string;
6
+ parent: RWProject;
7
+ constructor(constName: string, path: string, parent: RWProject);
8
+ get filePath(): string;
9
+ get route(): import("./RWRoute").RWRoute | undefined;
10
+ get layoutName(): string | undefined;
11
+ get actionRemove(): Map<any, any>;
12
+ }
13
+ //# sourceMappingURL=RWPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RWPage.d.ts","sourceRoot":"","sources":["../../src/model/RWPage.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAGjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,qBAAa,MAAO,SAAQ,QAAQ;IAEzB,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,SAAS;gBAFjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,SAAS;IAI1B,IAAY,QAAQ,WAEnB;IACD,IAAY,KAAK,4CAIhB;IACD,IAAY,UAAU,IAAI,MAAM,GAAG,SAAS,CAc3C;IACD,IAAY,YAAY,kBAUvB;CACF"}