@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha101

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 (158) hide show
  1. package/action/action.d.ts +37 -31
  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 +40 -16
  10. package/action/orchestrator.js +230 -62
  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 +49 -26
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +88 -7
  20. package/core/clause.js +355 -63
  21. package/core/config.d.ts +12 -1
  22. package/core/config.js +7 -1
  23. package/core/context.d.ts +5 -3
  24. package/core/context.js +20 -2
  25. package/core/convert.d.ts +1 -1
  26. package/core/date.js +1 -5
  27. package/core/db.d.ts +11 -8
  28. package/core/db.js +20 -8
  29. package/core/ent.d.ts +81 -25
  30. package/core/ent.js +636 -193
  31. package/core/loaders/assoc_count_loader.d.ts +3 -2
  32. package/core/loaders/assoc_count_loader.js +10 -2
  33. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  34. package/core/loaders/assoc_edge_loader.js +8 -11
  35. package/core/loaders/index.d.ts +1 -1
  36. package/core/loaders/index.js +1 -3
  37. package/core/loaders/index_loader.d.ts +2 -2
  38. package/core/loaders/loader.js +5 -5
  39. package/core/loaders/object_loader.d.ts +6 -5
  40. package/core/loaders/object_loader.js +67 -59
  41. package/core/loaders/query_loader.d.ts +6 -12
  42. package/core/loaders/query_loader.js +52 -11
  43. package/core/loaders/raw_count_loader.d.ts +2 -2
  44. package/core/loaders/raw_count_loader.js +5 -1
  45. package/core/logger.d.ts +1 -1
  46. package/core/logger.js +1 -0
  47. package/core/privacy.d.ts +25 -24
  48. package/core/privacy.js +21 -25
  49. package/core/query/assoc_query.d.ts +7 -6
  50. package/core/query/assoc_query.js +9 -1
  51. package/core/query/custom_clause_query.d.ts +26 -0
  52. package/core/query/custom_clause_query.js +78 -0
  53. package/core/query/custom_query.d.ts +20 -5
  54. package/core/query/custom_query.js +87 -12
  55. package/core/query/index.d.ts +1 -0
  56. package/core/query/index.js +3 -1
  57. package/core/query/query.d.ts +8 -4
  58. package/core/query/query.js +101 -53
  59. package/core/query/shared_assoc_test.d.ts +2 -1
  60. package/core/query/shared_assoc_test.js +35 -45
  61. package/core/query/shared_test.d.ts +8 -1
  62. package/core/query/shared_test.js +469 -236
  63. package/core/viewer.d.ts +3 -3
  64. package/core/viewer.js +1 -1
  65. package/graphql/graphql.d.ts +14 -7
  66. package/graphql/graphql.js +23 -7
  67. package/graphql/index.d.ts +0 -1
  68. package/graphql/index.js +1 -4
  69. package/graphql/query/connection_type.d.ts +9 -9
  70. package/graphql/query/edge_connection.d.ts +9 -9
  71. package/graphql/query/page_info.d.ts +1 -1
  72. package/graphql/query/shared_assoc_test.js +1 -1
  73. package/graphql/query/shared_edge_connection.js +1 -19
  74. package/imports/index.d.ts +6 -1
  75. package/imports/index.js +19 -4
  76. package/index.d.ts +12 -5
  77. package/index.js +20 -7
  78. package/package.json +17 -16
  79. package/parse_schema/parse.d.ts +29 -9
  80. package/parse_schema/parse.js +118 -11
  81. package/schema/base_schema.d.ts +5 -3
  82. package/schema/base_schema.js +5 -0
  83. package/schema/field.d.ts +74 -20
  84. package/schema/field.js +174 -69
  85. package/schema/index.d.ts +2 -2
  86. package/schema/index.js +5 -1
  87. package/schema/json_field.d.ts +13 -1
  88. package/schema/json_field.js +28 -1
  89. package/schema/schema.d.ts +81 -18
  90. package/schema/schema.js +24 -17
  91. package/schema/struct_field.d.ts +11 -1
  92. package/schema/struct_field.js +57 -21
  93. package/scripts/custom_compiler.js +10 -6
  94. package/scripts/custom_graphql.js +117 -30
  95. package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
  96. package/scripts/migrate_v0.1.js +36 -0
  97. package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -0
  98. package/scripts/move_types.js +117 -0
  99. package/scripts/read_schema.js +20 -5
  100. package/testutils/action/complex_schemas.d.ts +69 -0
  101. package/testutils/action/complex_schemas.js +398 -0
  102. package/testutils/builder.d.ts +46 -47
  103. package/testutils/builder.js +108 -65
  104. package/testutils/db/fixture.d.ts +10 -0
  105. package/testutils/db/fixture.js +26 -0
  106. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  107. package/testutils/db/{test_db.js → temp_db.js} +179 -44
  108. package/testutils/db/value.d.ts +7 -0
  109. package/testutils/db/value.js +251 -0
  110. package/testutils/db_mock.d.ts +16 -4
  111. package/testutils/db_mock.js +51 -6
  112. package/testutils/db_time_zone.d.ts +4 -0
  113. package/testutils/db_time_zone.js +41 -0
  114. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  115. package/testutils/ent-graphql-tests/index.js +27 -8
  116. package/testutils/fake_data/const.d.ts +2 -1
  117. package/testutils/fake_data/const.js +3 -0
  118. package/testutils/fake_data/fake_contact.d.ts +7 -3
  119. package/testutils/fake_data/fake_contact.js +15 -8
  120. package/testutils/fake_data/fake_event.d.ts +5 -2
  121. package/testutils/fake_data/fake_event.js +9 -7
  122. package/testutils/fake_data/fake_tag.d.ts +36 -0
  123. package/testutils/fake_data/fake_tag.js +89 -0
  124. package/testutils/fake_data/fake_user.d.ts +7 -4
  125. package/testutils/fake_data/fake_user.js +18 -16
  126. package/testutils/fake_data/index.js +5 -1
  127. package/testutils/fake_data/internal.d.ts +2 -0
  128. package/testutils/fake_data/internal.js +7 -1
  129. package/testutils/fake_data/tag_query.d.ts +13 -0
  130. package/testutils/fake_data/tag_query.js +43 -0
  131. package/testutils/fake_data/test_helpers.d.ts +11 -4
  132. package/testutils/fake_data/test_helpers.js +28 -12
  133. package/testutils/fake_data/user_query.d.ts +13 -6
  134. package/testutils/fake_data/user_query.js +54 -22
  135. package/testutils/fake_log.d.ts +3 -3
  136. package/testutils/parse_sql.d.ts +6 -0
  137. package/testutils/parse_sql.js +16 -2
  138. package/testutils/test_edge_global_schema.d.ts +15 -0
  139. package/testutils/test_edge_global_schema.js +62 -0
  140. package/testutils/write.d.ts +2 -2
  141. package/testutils/write.js +33 -7
  142. package/tsc/ast.d.ts +26 -2
  143. package/tsc/ast.js +163 -17
  144. package/tsc/compilerOptions.d.ts +2 -1
  145. package/tsc/compilerOptions.js +11 -2
  146. package/tsc/move_generated.d.ts +1 -0
  147. package/tsc/move_generated.js +164 -0
  148. package/tsc/transform.d.ts +22 -0
  149. package/tsc/transform.js +181 -0
  150. package/tsc/transform_action.d.ts +22 -0
  151. package/tsc/transform_action.js +183 -0
  152. package/tsc/transform_ent.d.ts +17 -0
  153. package/tsc/transform_ent.js +59 -0
  154. package/tsc/transform_schema.d.ts +27 -0
  155. package/{scripts → tsc}/transform_schema.js +145 -119
  156. package/graphql/enums.d.ts +0 -3
  157. package/graphql/enums.js +0 -25
  158. package/scripts/transform_code.js +0 -114
@@ -0,0 +1,62 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.testEdgeGlobalSchema = exports.EdgeWithDeletedAt = void 0;
27
+ const schema_1 = require("../schema");
28
+ const clause = __importStar(require("../core/clause"));
29
+ const ent_1 = require("../core/ent");
30
+ class EdgeWithDeletedAt extends ent_1.AssocEdge {
31
+ constructor(data) {
32
+ super(data);
33
+ this.deletedAt = data.deleted_at;
34
+ }
35
+ }
36
+ exports.EdgeWithDeletedAt = EdgeWithDeletedAt;
37
+ exports.testEdgeGlobalSchema = {
38
+ extraEdgeFields: {
39
+ // need this to be lowerCamelCase because we do this based on field name
40
+ // #510
41
+ deletedAt: (0, schema_1.TimestampType)({
42
+ nullable: true,
43
+ index: true,
44
+ defaultValueOnCreate: () => null,
45
+ }),
46
+ },
47
+ transformEdgeRead() {
48
+ return clause.Eq("deleted_at", null);
49
+ },
50
+ transformEdgeWrite(stmt) {
51
+ switch (stmt.op) {
52
+ case schema_1.SQLStatementOperation.Delete:
53
+ return {
54
+ op: schema_1.SQLStatementOperation.Update,
55
+ data: {
56
+ deleted_at: new Date(),
57
+ },
58
+ };
59
+ }
60
+ return null;
61
+ },
62
+ };
@@ -1,5 +1,5 @@
1
- import { EditRowOptions, Data, ID, DataOptions, CreateRowOptions } from "../core/base";
1
+ import { EditRowOptions, Data, DataOptions, CreateRowOptions } from "../core/base";
2
2
  import * as clause from "../core/clause";
3
3
  export declare function createRowForTest(options: CreateRowOptions, suffix?: string): Promise<Data | null>;
4
- export declare function editRowForTest(options: EditRowOptions, id: ID, suffix?: string): Promise<Data | null>;
4
+ export declare function editRowForTest(options: EditRowOptions, suffix?: string): Promise<Data | null>;
5
5
  export declare function deleteRowsForTest(options: DataOptions, cls: clause.Clause): Promise<void>;
@@ -1,16 +1,42 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.deleteRowsForTest = exports.editRowForTest = exports.createRowForTest = void 0;
7
27
  const ent_1 = require("../core/ent");
8
- const db_1 = __importDefault(require("../core/db"));
28
+ const db_1 = __importStar(require("../core/db"));
9
29
  function isSyncClient(client) {
10
30
  return client.execSync !== undefined;
11
31
  }
12
32
  async function createRowForTest(options, suffix) {
13
- const client = await db_1.default.getInstance().getNewClient();
33
+ let client;
34
+ if (db_1.Dialect.SQLite === db_1.default.getDialect()) {
35
+ client = db_1.default.getInstance().getSQLiteClient();
36
+ }
37
+ else {
38
+ client = await db_1.default.getInstance().getNewClient();
39
+ }
14
40
  try {
15
41
  if (isSyncClient(client)) {
16
42
  return (0, ent_1.createRowSync)(client, options, suffix || "");
@@ -22,13 +48,13 @@ async function createRowForTest(options, suffix) {
22
48
  }
23
49
  }
24
50
  exports.createRowForTest = createRowForTest;
25
- async function editRowForTest(options, id, suffix) {
51
+ async function editRowForTest(options, suffix) {
26
52
  const client = await db_1.default.getInstance().getNewClient();
27
53
  try {
28
54
  if (isSyncClient(client)) {
29
- return (0, ent_1.editRowSync)(client, options, id, suffix || "");
55
+ return (0, ent_1.editRowSync)(client, options, suffix || "");
30
56
  }
31
- return await (0, ent_1.editRow)(client, options, id, suffix);
57
+ return await (0, ent_1.editRow)(client, options, suffix);
32
58
  }
33
59
  finally {
34
60
  client.release();
package/tsc/ast.d.ts CHANGED
@@ -10,11 +10,35 @@ export interface ClassInfo {
10
10
  wrapClassContents(inner: string): string;
11
11
  }
12
12
  export declare function getClassInfo(fileContents: string, sourceFile: ts.SourceFile, node: ts.ClassDeclaration): ClassInfo | undefined;
13
- declare type transformImportFn = (imp: string) => string;
13
+ type transformImportFn = (imp: string) => string;
14
14
  interface transformOpts {
15
15
  removeImports?: string[];
16
16
  newImports?: string[];
17
17
  transform?: transformImportFn;
18
+ transformPath: string;
18
19
  }
19
- export declare function transformImport(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, opts?: transformOpts): string | undefined;
20
+ export declare function transformImport(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, opts: transformOpts): string | undefined;
21
+ export declare function updateImportPath(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, newPath: string): string | undefined;
22
+ export declare function isRelativeImport(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): boolean;
23
+ export declare function isRelativeGeneratedImport(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): boolean;
24
+ export declare function isSrcGeneratedImport(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): boolean;
25
+ interface importInfo {
26
+ imports: string[];
27
+ start: number;
28
+ end: number;
29
+ importText: string;
30
+ importPath: string;
31
+ default?: string;
32
+ }
33
+ export declare function getImportInfo(imp: ts.ImportDeclaration, sourceFile: ts.SourceFile): importInfo | undefined;
34
+ export declare function transformRelative(file: string, importPath: string, relative?: boolean): string;
35
+ export interface customInfo {
36
+ viewerInfo: {
37
+ path: string;
38
+ name: string;
39
+ };
40
+ relativeImports?: boolean;
41
+ globalSchemaPath?: string;
42
+ }
43
+ export declare function getCustomInfo(): customInfo;
20
44
  export {};
package/tsc/ast.js CHANGED
@@ -1,10 +1,36 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
29
+ exports.getCustomInfo = exports.transformRelative = exports.getImportInfo = exports.isSrcGeneratedImport = exports.isRelativeGeneratedImport = exports.isRelativeImport = exports.updateImportPath = exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
7
30
  const typescript_1 = __importDefault(require("typescript"));
31
+ const path = __importStar(require("path"));
32
+ const js_yaml_1 = require("js-yaml");
33
+ const fs = __importStar(require("fs"));
8
34
  function getPreText(fileContents, node, sourceFile) {
9
35
  return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
10
36
  }
@@ -31,8 +57,7 @@ function getClassInfo(fileContents, sourceFile, node) {
31
57
  }
32
58
  }
33
59
  }
34
- // we probably still don't need all of this...
35
- if (!className || !node.heritageClauses || !classExtends) {
60
+ if (!className) {
36
61
  return undefined;
37
62
  }
38
63
  let hasExport = false;
@@ -82,24 +107,22 @@ exports.getClassInfo = getClassInfo;
82
107
  function transformImport(fileContents, importNode, sourceFile, opts) {
83
108
  // remove quotes too
84
109
  const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
85
- if (text !== "@snowtop/ent" &&
86
- text !== "@snowtop/ent/schema" &&
87
- text !== "@snowtop/ent/schema/") {
110
+ if (text != opts.transformPath) {
88
111
  return;
89
112
  }
90
- const importText = importNode.importClause?.getText(sourceFile) || "";
91
- const start = importText.indexOf("{");
92
- const end = importText.lastIndexOf("}");
93
- if (start === -1 || end === -1) {
113
+ const impInfo = getImportInfo(importNode, sourceFile);
114
+ if (!impInfo) {
94
115
  return;
95
116
  }
96
- const imports = importText
97
- .substring(start + 1, end)
98
- // .trim()
99
- .split(",");
117
+ let { imports, start, end, importText, default: def } = impInfo;
100
118
  let removeImportsMap = {};
101
119
  if (opts?.removeImports) {
102
- opts.removeImports.forEach((imp) => (removeImportsMap[imp] = true));
120
+ opts.removeImports.forEach((imp) => {
121
+ removeImportsMap[imp] = true;
122
+ if (def === imp) {
123
+ def = "";
124
+ }
125
+ });
103
126
  }
104
127
  let finalImports = new Set();
105
128
  for (let i = 0; i < imports.length; i++) {
@@ -119,13 +142,136 @@ function transformImport(fileContents, importNode, sourceFile, opts) {
119
142
  opts.newImports.forEach((imp) => finalImports.add(imp));
120
143
  }
121
144
  const comment = getPreText(fileContents, importNode, sourceFile);
145
+ if (!finalImports.size) {
146
+ return;
147
+ }
122
148
  return (comment +
123
149
  "import " +
124
- importText.substring(0, start + 1) +
150
+ // add default
151
+ (def || "") +
152
+ // should probably always be "{" now that we support default
153
+ (start >= 0 ? importText.substring(0, start + 1) : "{") +
125
154
  Array.from(finalImports).join(", ") +
126
- importText.substring(end) +
155
+ // should probably always be "}"
156
+ (end >= 0 ? importText.substring(end) : "}") +
127
157
  ' from "' +
128
158
  text +
129
159
  '";');
130
160
  }
131
161
  exports.transformImport = transformImport;
162
+ function updateImportPath(fileContents, importNode, sourceFile, newPath) {
163
+ const comment = getPreText(fileContents, importNode, sourceFile);
164
+ // all this copied from above...
165
+ const importText = importNode.importClause?.getText(sourceFile) || "";
166
+ const start = importText.indexOf("{");
167
+ const end = importText.lastIndexOf("}");
168
+ if (start === -1 || end === -1) {
169
+ return;
170
+ }
171
+ const imports = importText
172
+ .substring(start + 1, end)
173
+ // .trim()
174
+ .split(",");
175
+ return (comment +
176
+ "import " +
177
+ importText.substring(0, start + 1) +
178
+ Array.from(imports).join(", ") +
179
+ importText.substring(end) +
180
+ ' from "' +
181
+ newPath +
182
+ '";');
183
+ }
184
+ exports.updateImportPath = updateImportPath;
185
+ function isRelativeImport(node, sourceFile) {
186
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
187
+ return text.startsWith("..") || text.startsWith("./");
188
+ }
189
+ exports.isRelativeImport = isRelativeImport;
190
+ function isRelativeGeneratedImport(node, sourceFile) {
191
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
192
+ return ((text.startsWith("..") || text.startsWith("./")) &&
193
+ text.indexOf("/generated") !== -1);
194
+ }
195
+ exports.isRelativeGeneratedImport = isRelativeGeneratedImport;
196
+ function isSrcGeneratedImport(node, sourceFile) {
197
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
198
+ return text.startsWith("src") && text.includes("/generated");
199
+ }
200
+ exports.isSrcGeneratedImport = isSrcGeneratedImport;
201
+ // TODO doesn't support default + {} yet
202
+ function getImportInfo(imp, sourceFile) {
203
+ const importText = imp.importClause?.getText(sourceFile) || "";
204
+ const start = importText.indexOf("{");
205
+ const end = importText.lastIndexOf("}");
206
+ const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
207
+ if ((start === -1 || end === -1) && !importText.length) {
208
+ return;
209
+ }
210
+ let imports = [];
211
+ let def;
212
+ if (start !== -1 && end !== -1) {
213
+ imports = importText
214
+ .substring(start + 1, end)
215
+ //.trim()
216
+ .split(",");
217
+ }
218
+ else {
219
+ def = importText;
220
+ }
221
+ return {
222
+ importPath: text,
223
+ importText,
224
+ start,
225
+ end,
226
+ imports,
227
+ default: def,
228
+ };
229
+ }
230
+ exports.getImportInfo = getImportInfo;
231
+ function transformRelative(file, importPath, relative) {
232
+ if (!relative || !importPath.startsWith("src")) {
233
+ return importPath;
234
+ }
235
+ const fileFullPath = path.join(process.cwd(), file);
236
+ const impFullPath = path.join(process.cwd(), importPath);
237
+ // relative path is from directory
238
+ return normalizePath(path.relative(path.dirname(fileFullPath), impFullPath));
239
+ }
240
+ exports.transformRelative = transformRelative;
241
+ function normalizePath(p) {
242
+ if (p.endsWith("..")) {
243
+ return p + "/";
244
+ }
245
+ if (!p.startsWith("..")) {
246
+ return "./" + p;
247
+ }
248
+ return p;
249
+ }
250
+ // also used in parse schema logic
251
+ function getCustomInfo() {
252
+ let yaml = {};
253
+ let relativeImports = false;
254
+ try {
255
+ yaml = (0, js_yaml_1.load)(fs.readFileSync(path.join(process.cwd(), "ent.yml"), {
256
+ encoding: "utf8",
257
+ }));
258
+ relativeImports = yaml?.codegen?.relativeImports || false;
259
+ if (yaml?.codegen?.templatizedViewer) {
260
+ return {
261
+ viewerInfo: yaml.codegen.templatizedViewer,
262
+ relativeImports,
263
+ globalSchemaPath: yaml.globalSchemaPath,
264
+ };
265
+ }
266
+ }
267
+ catch (e) { }
268
+ return {
269
+ viewerInfo: {
270
+ path: "@snowtop/ent",
271
+ name: "Viewer",
272
+ },
273
+ relativeImports,
274
+ globalSchemaPath: yaml.globalSchemaPath,
275
+ };
276
+ }
277
+ exports.getCustomInfo = getCustomInfo;
@@ -1,6 +1,7 @@
1
1
  import ts from "typescript";
2
2
  export declare function readCompilerOptions(filePath: string): ts.CompilerOptions;
3
- export declare function getTarget(target?: string): ts.ScriptTarget.ES3 | ts.ScriptTarget.ES5 | ts.ScriptTarget.ES2015 | ts.ScriptTarget.ES2016 | ts.ScriptTarget.ES2017 | ts.ScriptTarget.ES2018 | ts.ScriptTarget.ES2019 | ts.ScriptTarget.ES2020 | ts.ScriptTarget.ES2021 | ts.ScriptTarget.ESNext;
3
+ export declare function getTarget(target?: string): ts.ScriptTarget;
4
+ export declare function getTargetFromCurrentDir(): ts.ScriptTarget;
4
5
  export declare function createSourceFile(target: ts.ScriptTarget, file: string): {
5
6
  contents: string;
6
7
  sourceFile: ts.SourceFile;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.createSourceFile = exports.getTarget = exports.readCompilerOptions = void 0;
29
+ exports.createSourceFile = exports.getTargetFromCurrentDir = exports.getTarget = exports.readCompilerOptions = void 0;
26
30
  const fs = __importStar(require("fs"));
27
31
  const json5_1 = __importDefault(require("json5"));
28
32
  const typescript_1 = __importDefault(require("typescript"));
@@ -86,6 +90,11 @@ function getTarget(target) {
86
90
  }
87
91
  }
88
92
  exports.getTarget = getTarget;
93
+ function getTargetFromCurrentDir() {
94
+ const options = readCompilerOptions(".");
95
+ return getTarget(options.target?.toString());
96
+ }
97
+ exports.getTargetFromCurrentDir = getTargetFromCurrentDir;
89
98
  function createSourceFile(target, file) {
90
99
  let contents = fs.readFileSync(file).toString();
91
100
  // go through the file and print everything back if not starting immediately after other position
@@ -0,0 +1 @@
1
+ export declare function moveGenerated(relativeImports: boolean): void;
@@ -0,0 +1,164 @@
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.moveGenerated = void 0;
30
+ const glob_1 = require("glob");
31
+ const path = __importStar(require("path"));
32
+ const fs = __importStar(require("fs"));
33
+ const typescript_1 = __importDefault(require("typescript"));
34
+ const ast_1 = require("./ast");
35
+ const transform_1 = require("./transform");
36
+ class MoveFiles {
37
+ constructor(globPath) {
38
+ this.globPath = globPath;
39
+ }
40
+ move() {
41
+ const files = glob_1.glob.sync(this.globPath);
42
+ moveFiles(files);
43
+ }
44
+ }
45
+ class TransformImports {
46
+ constructor(glob, prettierGlob, relativeImports, checkRelativeImportsValid) {
47
+ this.glob = glob;
48
+ this.prettierGlob = prettierGlob;
49
+ this.relativeImports = relativeImports;
50
+ this.checkRelativeImportsValid = checkRelativeImportsValid;
51
+ this.globOptions = {
52
+ ignore: ["node_modules/**"],
53
+ };
54
+ this.cwd = process.cwd();
55
+ }
56
+ traverseChild(sourceFile, contents, file, node) {
57
+ if (!typescript_1.default.isImportDeclaration(node)) {
58
+ return { node };
59
+ }
60
+ let dirPath = path.join(this.cwd, file, "..");
61
+ const newImportPath = this.getNewImportPath(node, file, sourceFile, dirPath);
62
+ if (!newImportPath) {
63
+ return { node };
64
+ }
65
+ const v = (0, ast_1.updateImportPath)(contents, node, sourceFile, newImportPath);
66
+ return {
67
+ traversed: true,
68
+ rawString: v,
69
+ };
70
+ }
71
+ getNewImportPath(node, file, sourceFile, dirPath) {
72
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
73
+ // it's relative and has generated in there, continue
74
+ // do relative imports path regardless of if relative imports is on or not
75
+ if ((0, ast_1.isRelativeGeneratedImport)(node, sourceFile)) {
76
+ const oldPath = path.join(dirPath, text);
77
+ const relFromRoot = path.relative(".", oldPath);
78
+ const conv = transformPath(relFromRoot);
79
+ if (!conv || conv.newFile === relFromRoot) {
80
+ return;
81
+ }
82
+ return path.relative(dirPath, conv.newFile);
83
+ }
84
+ if (this.checkRelativeImportsValid && (0, ast_1.isRelativeImport)(node, sourceFile)) {
85
+ const parts = file.split(path.sep);
86
+ if (parts.length === 5 &&
87
+ parts.slice(0, 3).join(path.sep) ===
88
+ ["src", "graphql", "generated"].join(path.sep)) {
89
+ // we have custom graphql import paths
90
+ // src/graphql/generated/mutations|resolvers/foo_type.ts
91
+ // which used to be
92
+ // src/graphql/mutations|resolvers/generated/foo_type.ts
93
+ // we probably have a broken import.
94
+ // try and fix it...
95
+ let temp = parts[2];
96
+ parts[2] = parts[3];
97
+ parts[3] = temp;
98
+ const oldPath = parts.join(path.sep);
99
+ let oldDir = path.join(this.cwd, oldPath, "..");
100
+ let importPath = path.join(oldDir, text);
101
+ let exists = fs.statSync(importPath + ".ts", { throwIfNoEntry: false });
102
+ if (!exists) {
103
+ // doesn't exist. sadly has to be fixed manually. could theoretically also be a directory but we shouldn't have that
104
+ return;
105
+ }
106
+ return path.relative(dirPath, importPath);
107
+ }
108
+ }
109
+ // if relative imports, we done.
110
+ if (this.relativeImports) {
111
+ return;
112
+ }
113
+ // non relative, only transform src paths with generated
114
+ if ((0, ast_1.isSrcGeneratedImport)(node, sourceFile)) {
115
+ const conv = transformPath(text);
116
+ if (!conv || conv.newFile === text) {
117
+ return;
118
+ }
119
+ return conv.newFile;
120
+ }
121
+ return;
122
+ }
123
+ }
124
+ function transformPath(old) {
125
+ const parts = old.split(path.sep);
126
+ if (parts.length < 3) {
127
+ return;
128
+ }
129
+ const changedParts = parts
130
+ .slice(0, 2)
131
+ .concat("generated")
132
+ .concat(parts.slice(2).filter((v) => v !== "generated"));
133
+ const newFile = changedParts.join(path.sep);
134
+ return { changedParts, newFile };
135
+ }
136
+ function moveFiles(files) {
137
+ files.forEach((file) => {
138
+ const conv = transformPath(file);
139
+ if (!conv) {
140
+ return;
141
+ }
142
+ const { changedParts, newFile } = conv;
143
+ if (file === newFile) {
144
+ return;
145
+ }
146
+ // check if directory exists, if not, create recursive dir
147
+ const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
148
+ const statInfo = fs.statSync(p, { throwIfNoEntry: false });
149
+ if (!statInfo) {
150
+ fs.mkdirSync(p, {
151
+ recursive: true,
152
+ });
153
+ }
154
+ // move file to new location
155
+ fs.renameSync(file, newFile);
156
+ });
157
+ }
158
+ function moveGenerated(relativeImports) {
159
+ new MoveFiles("src/ent/**/generated/**/**.ts").move();
160
+ new MoveFiles("src/graphql/**/generated/**/**.ts").move();
161
+ (0, transform_1.transform)(new TransformImports("src/ent/**/*.ts", "src/ent/**/*.ts", relativeImports));
162
+ (0, transform_1.transform)(new TransformImports("src/graphql/**/*.ts", "src/graphql/**/*.ts", relativeImports, true));
163
+ }
164
+ exports.moveGenerated = moveGenerated;
@@ -0,0 +1,22 @@
1
+ import { IOptions } from "glob";
2
+ import ts from "typescript";
3
+ interface TraverseChildResponse {
4
+ node?: ts.Node;
5
+ rawString?: string;
6
+ traversed?: boolean;
7
+ imports?: Map<string, string[]>;
8
+ removeImports?: string[];
9
+ allowSeenImportsAdded?: boolean;
10
+ }
11
+ export interface TransformFile {
12
+ glob: string;
13
+ globOptions?: IOptions;
14
+ preprocessFile?: (contents: string, file: string, sourceFile: ts.SourceFile) => boolean;
15
+ traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): TraverseChildResponse | undefined;
16
+ filter?(files: string[]): string[];
17
+ fileToWrite?(file: string): string;
18
+ postProcess?(file: string): void;
19
+ prettierGlob?: string;
20
+ }
21
+ export declare function transform(transform: TransformFile): void;
22
+ export {};