@snowtop/ent 0.1.0-alpha13 → 0.1.0-alpha131

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 (173) hide show
  1. package/action/action.d.ts +33 -29
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +3 -3
  4. package/action/executor.js +8 -3
  5. package/action/experimental_action.d.ts +32 -22
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +2 -0
  8. package/action/index.js +7 -1
  9. package/action/orchestrator.d.ts +32 -15
  10. package/action/orchestrator.js +249 -53
  11. package/action/privacy.d.ts +2 -2
  12. package/action/relative_value.d.ts +47 -0
  13. package/action/relative_value.js +125 -0
  14. package/action/transaction.d.ts +10 -0
  15. package/action/transaction.js +23 -0
  16. package/auth/auth.d.ts +1 -1
  17. package/core/base.d.ts +61 -37
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +85 -40
  20. package/core/clause.js +375 -64
  21. package/core/config.d.ts +12 -1
  22. package/core/config.js +7 -1
  23. package/core/const.d.ts +3 -0
  24. package/core/const.js +6 -0
  25. package/core/context.d.ts +6 -4
  26. package/core/context.js +20 -2
  27. package/core/convert.d.ts +1 -1
  28. package/core/date.js +1 -5
  29. package/core/db.d.ts +11 -8
  30. package/core/db.js +20 -8
  31. package/core/ent.d.ts +86 -30
  32. package/core/ent.js +626 -197
  33. package/core/global_schema.d.ts +7 -0
  34. package/core/global_schema.js +51 -0
  35. package/core/loaders/assoc_count_loader.d.ts +3 -2
  36. package/core/loaders/assoc_count_loader.js +10 -2
  37. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  38. package/core/loaders/assoc_edge_loader.js +8 -11
  39. package/core/loaders/index.d.ts +1 -1
  40. package/core/loaders/index.js +1 -3
  41. package/core/loaders/index_loader.d.ts +3 -3
  42. package/core/loaders/loader.d.ts +2 -2
  43. package/core/loaders/loader.js +5 -5
  44. package/core/loaders/object_loader.d.ts +32 -11
  45. package/core/loaders/object_loader.js +225 -78
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +52 -11
  48. package/core/loaders/raw_count_loader.d.ts +2 -2
  49. package/core/loaders/raw_count_loader.js +5 -1
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +25 -24
  53. package/core/privacy.js +21 -25
  54. package/core/query/assoc_query.d.ts +7 -6
  55. package/core/query/assoc_query.js +9 -1
  56. package/core/query/custom_clause_query.d.ts +27 -0
  57. package/core/query/custom_clause_query.js +84 -0
  58. package/core/query/custom_query.d.ts +20 -5
  59. package/core/query/custom_query.js +87 -12
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +8 -4
  63. package/core/query/query.js +101 -53
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +35 -45
  66. package/core/query/shared_test.d.ts +8 -1
  67. package/core/query/shared_test.js +470 -236
  68. package/core/viewer.d.ts +3 -3
  69. package/core/viewer.js +1 -1
  70. package/graphql/graphql.d.ts +51 -19
  71. package/graphql/graphql.js +160 -136
  72. package/graphql/graphql_field_helpers.d.ts +7 -1
  73. package/graphql/graphql_field_helpers.js +21 -1
  74. package/graphql/index.d.ts +2 -2
  75. package/graphql/index.js +3 -5
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/edge_connection.d.ts +9 -9
  78. package/graphql/query/page_info.d.ts +1 -1
  79. package/graphql/query/shared_assoc_test.js +1 -1
  80. package/graphql/query/shared_edge_connection.js +1 -19
  81. package/graphql/scalars/orderby_direction.d.ts +2 -0
  82. package/graphql/scalars/orderby_direction.js +15 -0
  83. package/imports/dataz/example1/_auth.js +128 -47
  84. package/imports/dataz/example1/_viewer.js +87 -39
  85. package/imports/index.d.ts +6 -1
  86. package/imports/index.js +19 -4
  87. package/index.d.ts +13 -5
  88. package/index.js +21 -7
  89. package/package.json +17 -17
  90. package/parse_schema/parse.d.ts +31 -9
  91. package/parse_schema/parse.js +155 -13
  92. package/schema/base_schema.d.ts +7 -3
  93. package/schema/base_schema.js +10 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +231 -71
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +5 -1
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +89 -19
  101. package/schema/schema.js +11 -13
  102. package/schema/struct_field.d.ts +15 -3
  103. package/schema/struct_field.js +117 -22
  104. package/schema/union_field.d.ts +1 -1
  105. package/scripts/custom_compiler.js +10 -6
  106. package/scripts/custom_graphql.js +128 -31
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +20 -5
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +398 -0
  112. package/testutils/builder.d.ts +41 -47
  113. package/testutils/builder.js +76 -49
  114. package/testutils/db/fixture.d.ts +10 -0
  115. package/testutils/db/fixture.js +26 -0
  116. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +182 -45
  118. package/testutils/db/value.d.ts +7 -0
  119. package/testutils/db/value.js +251 -0
  120. package/testutils/db_mock.d.ts +16 -4
  121. package/testutils/db_mock.js +52 -7
  122. package/testutils/db_time_zone.d.ts +4 -0
  123. package/testutils/db_time_zone.js +41 -0
  124. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  125. package/testutils/ent-graphql-tests/index.js +52 -23
  126. package/testutils/fake_comms.js +1 -1
  127. package/testutils/fake_data/const.d.ts +2 -1
  128. package/testutils/fake_data/const.js +3 -0
  129. package/testutils/fake_data/fake_contact.d.ts +7 -3
  130. package/testutils/fake_data/fake_contact.js +13 -7
  131. package/testutils/fake_data/fake_event.d.ts +4 -1
  132. package/testutils/fake_data/fake_event.js +7 -6
  133. package/testutils/fake_data/fake_tag.d.ts +36 -0
  134. package/testutils/fake_data/fake_tag.js +89 -0
  135. package/testutils/fake_data/fake_user.d.ts +8 -5
  136. package/testutils/fake_data/fake_user.js +16 -15
  137. package/testutils/fake_data/index.js +5 -1
  138. package/testutils/fake_data/internal.d.ts +2 -0
  139. package/testutils/fake_data/internal.js +7 -1
  140. package/testutils/fake_data/tag_query.d.ts +13 -0
  141. package/testutils/fake_data/tag_query.js +43 -0
  142. package/testutils/fake_data/test_helpers.d.ts +11 -4
  143. package/testutils/fake_data/test_helpers.js +28 -12
  144. package/testutils/fake_data/user_query.d.ts +13 -6
  145. package/testutils/fake_data/user_query.js +54 -22
  146. package/testutils/fake_log.d.ts +3 -3
  147. package/testutils/fake_log.js +1 -1
  148. package/testutils/parse_sql.d.ts +6 -0
  149. package/testutils/parse_sql.js +16 -2
  150. package/testutils/test_edge_global_schema.d.ts +15 -0
  151. package/testutils/test_edge_global_schema.js +62 -0
  152. package/testutils/write.d.ts +2 -2
  153. package/testutils/write.js +33 -7
  154. package/tsc/ast.d.ts +25 -2
  155. package/tsc/ast.js +141 -17
  156. package/tsc/compilerOptions.js +5 -1
  157. package/tsc/move_generated.d.ts +1 -0
  158. package/tsc/move_generated.js +164 -0
  159. package/tsc/transform.d.ts +22 -0
  160. package/tsc/transform.js +181 -0
  161. package/tsc/transform_action.d.ts +22 -0
  162. package/tsc/transform_action.js +183 -0
  163. package/tsc/transform_ent.d.ts +17 -0
  164. package/tsc/transform_ent.js +60 -0
  165. package/tsc/transform_schema.d.ts +27 -0
  166. package/{scripts → tsc}/transform_schema.js +146 -117
  167. package/graphql/enums.d.ts +0 -3
  168. package/graphql/enums.js +0 -25
  169. package/scripts/move_generated.js +0 -142
  170. package/scripts/transform_code.js +0 -113
  171. package/scripts/transform_schema.d.ts +0 -1
  172. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  173. /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.transform = void 0;
30
+ const glob_1 = require("glob");
31
+ const typescript_1 = __importDefault(require("typescript"));
32
+ const child_process_1 = require("child_process");
33
+ const fs = __importStar(require("fs"));
34
+ const ast_1 = require("./ast");
35
+ const compilerOptions_1 = require("./compilerOptions");
36
+ function normalizePath(p) {
37
+ if (p.endsWith("..")) {
38
+ return p + "/";
39
+ }
40
+ return p;
41
+ }
42
+ function transform(transform) {
43
+ let files = glob_1.glob.sync(transform.glob, transform.globOptions);
44
+ const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
45
+ if (transform.filter) {
46
+ files = transform.filter(files);
47
+ }
48
+ files.forEach((file) => {
49
+ let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
50
+ let nodes = [];
51
+ let imports = new Map();
52
+ let removeImports = [];
53
+ let traversed = false;
54
+ let allowSeenImportsAdded = false;
55
+ let seenImports = new Map();
56
+ typescript_1.default.forEachChild(sourceFile, function (node) {
57
+ if (typescript_1.default.isImportDeclaration(node)) {
58
+ const imp = (0, ast_1.getImportInfo)(node, sourceFile);
59
+ if (imp) {
60
+ imp.imports.forEach((v) => {
61
+ v = v.trim();
62
+ v && seenImports.set(v, true);
63
+ });
64
+ }
65
+ }
66
+ const ret = transform.traverseChild(sourceFile, contents, file, node);
67
+ if (!ret) {
68
+ return;
69
+ }
70
+ if (ret.node || ret.rawString) {
71
+ nodes.push(ret);
72
+ }
73
+ if (ret.imports) {
74
+ for (const [k, v] of ret.imports) {
75
+ imports.set(k, v);
76
+ }
77
+ }
78
+ if (ret.traversed) {
79
+ traversed = ret.traversed;
80
+ }
81
+ if (ret.removeImports?.length) {
82
+ removeImports.push(...ret.removeImports);
83
+ }
84
+ if (ret.allowSeenImportsAdded) {
85
+ allowSeenImportsAdded = ret.allowSeenImportsAdded;
86
+ }
87
+ });
88
+ if (!traversed) {
89
+ return;
90
+ }
91
+ let newContents = "";
92
+ let afterProcessed = false;
93
+ let seen = new Map();
94
+ const processAfterImport = () => {
95
+ // do this for the first non-import node we see
96
+ // we want to add new imports to end of imports and there's an assumption that imports are ordered
97
+ // at top of file
98
+ // TODO account for placement after first comment
99
+ if (!afterProcessed) {
100
+ for (const [imp, list] of imports) {
101
+ if (seen.has(imp)) {
102
+ continue;
103
+ }
104
+ // this says only add things you haven't seen
105
+ // we want to add something we've seen in this case
106
+ let final = list;
107
+ if (!allowSeenImportsAdded) {
108
+ final = list.filter((v) => !seenImports.has(v));
109
+ }
110
+ if (final.length) {
111
+ newContents += `\nimport { ${final.join(", ")} } from "${imp}";\n`;
112
+ }
113
+ }
114
+ afterProcessed = true;
115
+ }
116
+ };
117
+ for (const node of nodes) {
118
+ if (node.node) {
119
+ if (typescript_1.default.isImportDeclaration(node.node)) {
120
+ const impInfo = (0, ast_1.getImportInfo)(node.node, sourceFile);
121
+ // console.debug(impInfo);
122
+ if (impInfo) {
123
+ const impPath = normalizePath(impInfo.importPath);
124
+ const list = imports.get(impPath);
125
+ // path exists, we care about it
126
+ if (list !== undefined) {
127
+ let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
128
+ // if we've done this path before, don't try and add
129
+ // but still try and do any removals since we don't know which of the imports
130
+ // has it
131
+ newImports: seen.has(impPath) ? undefined : list,
132
+ removeImports,
133
+ // don't use normalized path here, we wanna use the path that's in code...
134
+ transformPath: impInfo.importPath,
135
+ });
136
+ if (transformed) {
137
+ newContents += transformed;
138
+ seen.set(impPath, true);
139
+ continue;
140
+ }
141
+ }
142
+ }
143
+ }
144
+ else {
145
+ if (!typescript_1.default.isExportDeclaration(node.node) &&
146
+ !isRequireStatement(node.node, sourceFile)) {
147
+ processAfterImport();
148
+ }
149
+ }
150
+ newContents += node.node.getFullText(sourceFile);
151
+ }
152
+ else if (node.rawString) {
153
+ processAfterImport();
154
+ newContents += node.rawString;
155
+ }
156
+ else {
157
+ throw new Error(`malformed node with no node or rawString`);
158
+ }
159
+ }
160
+ let writeFile = file;
161
+ if (transform.fileToWrite) {
162
+ writeFile = transform.fileToWrite(file);
163
+ }
164
+ fs.writeFileSync(writeFile, newContents);
165
+ if (transform.postProcess) {
166
+ transform.postProcess(file);
167
+ }
168
+ });
169
+ if (transform.prettierGlob) {
170
+ (0, child_process_1.execSync)(`prettier ${transform.prettierGlob} --write`);
171
+ }
172
+ }
173
+ exports.transform = transform;
174
+ function isRequireStatement(node, sourceFile) {
175
+ if (node.kind !== typescript_1.default.SyntaxKind.VariableStatement) {
176
+ return false;
177
+ }
178
+ const v = node;
179
+ const text = v.declarationList.declarations[0].getFullText(sourceFile);
180
+ return text.includes("require(");
181
+ }
@@ -0,0 +1,22 @@
1
+ import ts from "typescript";
2
+ import { customInfo } from "../tsc/ast";
3
+ import { TransformFile } from "./transform";
4
+ export declare class TransformAction implements TransformFile {
5
+ private customInfo;
6
+ glob: string;
7
+ prettierGlob: string;
8
+ constructor(customInfo: customInfo);
9
+ traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
10
+ node: ts.Node;
11
+ rawString?: undefined;
12
+ traversed?: undefined;
13
+ imports?: undefined;
14
+ removeImports?: undefined;
15
+ } | {
16
+ rawString: string;
17
+ traversed: boolean;
18
+ imports: Map<string, string[]>;
19
+ removeImports: string[];
20
+ node?: undefined;
21
+ } | undefined;
22
+ }
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.TransformAction = void 0;
30
+ const typescript_1 = __importDefault(require("typescript"));
31
+ const ast_1 = require("../tsc/ast");
32
+ const viewer_1 = require("../core/viewer");
33
+ const path = __importStar(require("path"));
34
+ const snake_case_1 = require("snake-case");
35
+ // returns input and importPath
36
+ function getBaseFileInfo(file, classInfo, sourceFile) {
37
+ // @ts-ignore
38
+ const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
39
+ for (const imp of importStatements) {
40
+ const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
41
+ if ((0, ast_1.isSrcGeneratedImport)(imp, sourceFile) ||
42
+ (0, ast_1.isRelativeGeneratedImport)(imp, sourceFile)) {
43
+ // base file and we're importing from it
44
+ // e.g. in create_user_action, we're importing from create_user_action_base
45
+ if (path.basename(file).slice(0, -3) + "_base" !== path.basename(text)) {
46
+ continue;
47
+ }
48
+ const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
49
+ if (!impInfo) {
50
+ continue;
51
+ }
52
+ let inputs = impInfo.imports
53
+ .filter((imp) => imp.trim() && imp.endsWith("Input"))
54
+ .map((v) => v.trim());
55
+ if (inputs.length === 1) {
56
+ return {
57
+ input: inputs[0],
58
+ importPath: impInfo.importPath,
59
+ };
60
+ }
61
+ if (inputs.length && classInfo.name.endsWith("Action")) {
62
+ const prefix = classInfo.name.slice(0, classInfo.name.length - 6);
63
+ inputs = inputs.filter((imp) => imp.slice(0, imp.length - 5) === prefix);
64
+ if (inputs.length === 1) {
65
+ return {
66
+ input: inputs[0],
67
+ importPath: impInfo.importPath,
68
+ };
69
+ }
70
+ }
71
+ }
72
+ }
73
+ return null;
74
+ }
75
+ let m = {
76
+ triggers: {
77
+ m: "getTriggers",
78
+ i: "Trigger",
79
+ suffix: "Triggers",
80
+ },
81
+ observers: {
82
+ m: "getObservers",
83
+ i: "Observer",
84
+ suffix: "Observers",
85
+ },
86
+ validators: {
87
+ m: "getValidators",
88
+ i: "Validator",
89
+ suffix: "Validators",
90
+ },
91
+ };
92
+ function getConversionInfo(mm, actionName) {
93
+ if (mm.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
94
+ return null;
95
+ }
96
+ const text = mm.name.escapedText;
97
+ const v = m[text];
98
+ if (v === undefined) {
99
+ return null;
100
+ }
101
+ return {
102
+ text,
103
+ method: v.m,
104
+ interface: v.i,
105
+ // CreateFooActionTriggers etc
106
+ methodType: actionName + v.suffix,
107
+ };
108
+ }
109
+ class TransformAction {
110
+ constructor(customInfo) {
111
+ this.customInfo = customInfo;
112
+ this.glob = "src/ent/**/actions/**/*_action.ts";
113
+ this.prettierGlob = "src/ent/**/actions/**.ts";
114
+ }
115
+ traverseChild(sourceFile, contents, file, node) {
116
+ if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
117
+ return { node };
118
+ }
119
+ let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
120
+ // only do classes
121
+ if (!classInfo || !classInfo.default) {
122
+ return;
123
+ }
124
+ // require action
125
+ const p = require(path.join(process.cwd(), "./" + file.slice(0, -3)));
126
+ const action = new p.default(new viewer_1.LoggedOutViewer(), {});
127
+ const actionName = action.constructor.name;
128
+ const builder = action.builder.constructor.name;
129
+ const nodeName = action.builder.ent.name;
130
+ const viewer = this.customInfo.viewerInfo.name;
131
+ const baseInfo = getBaseFileInfo(file, classInfo, sourceFile);
132
+ if (!baseInfo) {
133
+ return;
134
+ }
135
+ let klassContents = "";
136
+ let traversed = false;
137
+ let newImports = [];
138
+ for (const mm of node.members) {
139
+ const conv = getConversionInfo(mm, actionName);
140
+ if (conv !== null) {
141
+ const property = mm;
142
+ // if invalid, bounce
143
+ if (!property.initializer) {
144
+ return;
145
+ }
146
+ traversed = true;
147
+ const pp = property.initializer.getFullText(sourceFile).trim();
148
+ const code = `${conv.method}(): ${conv.methodType} {
149
+ return ${pp}
150
+ }`;
151
+ newImports.push(conv.methodType);
152
+ klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
153
+ }
154
+ else {
155
+ klassContents += mm.getFullText(sourceFile);
156
+ }
157
+ }
158
+ const builderPath = `src/ent/generated/${(0, snake_case_1.snakeCase)(nodeName)}/actions/${(0, snake_case_1.snakeCase)(builder)}`;
159
+ let imports = new Map([
160
+ [
161
+ (0, ast_1.transformRelative)(file, this.customInfo.viewerInfo.path, this.customInfo.relativeImports),
162
+ [viewer],
163
+ ],
164
+ [
165
+ (0, ast_1.transformRelative)(file, baseInfo.importPath, this.customInfo.relativeImports),
166
+ newImports,
167
+ ],
168
+ [
169
+ (0, ast_1.transformRelative)(file, builderPath, this.customInfo.relativeImports),
170
+ [builder],
171
+ ],
172
+ ]);
173
+ // wrap comments and transform to export class Foo extends Bar { ${inner} }
174
+ return {
175
+ rawString: classInfo.wrapClassContents(klassContents),
176
+ traversed,
177
+ imports,
178
+ removeImports: ["Trigger", "Observer", "Validator"],
179
+ // not removing FooBuilder incase it's still somehow used in type of inline builders
180
+ };
181
+ }
182
+ }
183
+ exports.TransformAction = TransformAction;
@@ -0,0 +1,17 @@
1
+ import ts from "typescript";
2
+ import { TransformFile } from "./transform";
3
+ export declare class TransformEnt implements TransformFile {
4
+ glob: string;
5
+ traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
6
+ node: ts.Node;
7
+ rawString?: undefined;
8
+ traversed?: undefined;
9
+ imports?: undefined;
10
+ } | {
11
+ rawString: string;
12
+ traversed: boolean;
13
+ imports: Map<string, string[]>;
14
+ node?: undefined;
15
+ } | undefined;
16
+ prettierGlob: string;
17
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TransformEnt = void 0;
7
+ const const_1 = require("../core/const");
8
+ const typescript_1 = __importDefault(require("typescript"));
9
+ const ast_1 = require("./ast");
10
+ function isPrivacyPolicy(mm) {
11
+ return (mm.kind === typescript_1.default.SyntaxKind.PropertyDeclaration &&
12
+ mm.name.escapedText === "privacyPolicy");
13
+ }
14
+ class TransformEnt {
15
+ constructor() {
16
+ this.glob = "src/ent/*.ts";
17
+ this.prettierGlob = "src/ent/*.ts";
18
+ }
19
+ traverseChild(sourceFile, contents, file, node) {
20
+ if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
21
+ return { node };
22
+ }
23
+ let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
24
+ if (!classInfo) {
25
+ return;
26
+ }
27
+ // different class. ignore
28
+ // only do classes which extend a base class e.g. User extends UserBase
29
+ // if different class (e.g. privacy rule), just return it
30
+ if (classInfo.extends !== classInfo.name + "Base") {
31
+ return { node };
32
+ }
33
+ let klassContents = "";
34
+ let traversed = false;
35
+ for (const mm of node.members) {
36
+ if (isPrivacyPolicy(mm)) {
37
+ const property = mm;
38
+ // if invalid privacy policy, bounce
39
+ if (!property.initializer) {
40
+ return;
41
+ }
42
+ const pp = property.initializer.getFullText(sourceFile);
43
+ const code = `getPrivacyPolicy(): PrivacyPolicy<this> {
44
+ return ${pp}
45
+ }`;
46
+ klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
47
+ traversed = true;
48
+ }
49
+ else {
50
+ klassContents += mm.getFullText(sourceFile);
51
+ }
52
+ }
53
+ return {
54
+ rawString: classInfo.wrapClassContents(klassContents),
55
+ traversed,
56
+ imports: new Map([[const_1.PACKAGE, ["PrivacyPolicy"]]]),
57
+ };
58
+ }
59
+ }
60
+ exports.TransformEnt = TransformEnt;
@@ -0,0 +1,27 @@
1
+ import ts from "typescript";
2
+ import { TransformFile } from "./transform";
3
+ export declare class TransformSchema implements TransformFile {
4
+ private relativeImports;
5
+ private oldBaseClass?;
6
+ private newSchemaClass?;
7
+ private transformPath?;
8
+ constructor(relativeImports: boolean, oldBaseClass?: string | undefined, newSchemaClass?: string | undefined, transformPath?: string | undefined);
9
+ glob: string;
10
+ private transformSchema;
11
+ traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
12
+ node: ts.Node;
13
+ traversed?: undefined;
14
+ rawString?: undefined;
15
+ removeImports?: undefined;
16
+ imports?: undefined;
17
+ } | {
18
+ traversed: boolean;
19
+ rawString: string;
20
+ removeImports: string[];
21
+ imports: Map<string, string[]>;
22
+ node?: undefined;
23
+ } | undefined;
24
+ fileToWrite(file: string): string;
25
+ postProcess(file: string): void;
26
+ prettierGlob: string;
27
+ }