@snowtop/ent 0.1.0-alpha160-test6 → 0.1.0-alpha160
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.
- package/core/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +804 -0
- package/core/query/shared_test.d.ts +21 -0
- package/core/query/shared_test.js +736 -0
- package/graphql/query/shared_assoc_test.d.ts +1 -0
- package/graphql/query/shared_assoc_test.js +203 -0
- package/package.json +6 -48
- package/{dist/scripts → scripts}/custom_compiler.js +0 -0
- package/{dist/scripts → scripts}/custom_graphql.js +0 -0
- package/dist/package.json +0 -64
- package/src/action/action.ts +0 -330
- package/src/action/executor.ts +0 -453
- package/src/action/experimental_action.ts +0 -277
- package/src/action/index.ts +0 -31
- package/src/action/operations.ts +0 -967
- package/src/action/orchestrator.ts +0 -1527
- package/src/action/privacy.ts +0 -37
- package/src/action/relative_value.ts +0 -242
- package/src/action/transaction.ts +0 -38
- package/src/auth/auth.ts +0 -77
- package/src/auth/index.ts +0 -8
- package/src/core/base.ts +0 -367
- package/src/core/clause.ts +0 -1065
- package/src/core/config.ts +0 -219
- package/src/core/const.ts +0 -5
- package/src/core/context.ts +0 -135
- package/src/core/convert.ts +0 -106
- package/src/core/date.ts +0 -23
- package/src/core/db.ts +0 -498
- package/src/core/ent.ts +0 -1740
- package/src/core/global_schema.ts +0 -49
- package/src/core/loaders/assoc_count_loader.ts +0 -99
- package/src/core/loaders/assoc_edge_loader.ts +0 -250
- package/src/core/loaders/index.ts +0 -12
- package/src/core/loaders/loader.ts +0 -66
- package/src/core/loaders/object_loader.ts +0 -489
- package/src/core/loaders/query_loader.ts +0 -314
- package/src/core/loaders/raw_count_loader.ts +0 -175
- package/src/core/logger.ts +0 -49
- package/src/core/privacy.ts +0 -660
- package/src/core/query/assoc_query.ts +0 -240
- package/src/core/query/custom_clause_query.ts +0 -174
- package/src/core/query/custom_query.ts +0 -302
- package/src/core/query/index.ts +0 -9
- package/src/core/query/query.ts +0 -674
- package/src/core/query_impl.ts +0 -32
- package/src/core/viewer.ts +0 -52
- package/src/ent.code-workspace +0 -73
- package/src/graphql/builtins/connection.ts +0 -25
- package/src/graphql/builtins/edge.ts +0 -16
- package/src/graphql/builtins/node.ts +0 -12
- package/src/graphql/graphql.ts +0 -891
- package/src/graphql/graphql_field_helpers.ts +0 -221
- package/src/graphql/index.ts +0 -42
- package/src/graphql/mutations/union.ts +0 -39
- package/src/graphql/node_resolver.ts +0 -122
- package/src/graphql/query/connection_type.ts +0 -113
- package/src/graphql/query/edge_connection.ts +0 -171
- package/src/graphql/query/page_info.ts +0 -34
- package/src/graphql/query/shared_edge_connection.ts +0 -287
- package/src/graphql/scalars/orderby_direction.ts +0 -13
- package/src/graphql/scalars/time.ts +0 -38
- package/src/imports/dataz/example1/_auth.ts +0 -51
- package/src/imports/dataz/example1/_viewer.ts +0 -35
- package/src/imports/index.ts +0 -213
- package/src/index.ts +0 -145
- package/src/parse_schema/parse.ts +0 -585
- package/src/schema/base_schema.ts +0 -224
- package/src/schema/field.ts +0 -1087
- package/src/schema/index.ts +0 -53
- package/src/schema/json_field.ts +0 -94
- package/src/schema/schema.ts +0 -1028
- package/src/schema/struct_field.ts +0 -234
- package/src/schema/union_field.ts +0 -105
- package/src/scripts/custom_compiler.ts +0 -331
- package/src/scripts/custom_graphql.ts +0 -550
- package/src/scripts/migrate_v0.1.ts +0 -41
- package/src/scripts/move_types.ts +0 -131
- package/src/scripts/read_schema.ts +0 -67
- package/src/setupPackage.js +0 -42
- package/src/testutils/action/complex_schemas.ts +0 -517
- package/src/testutils/builder.ts +0 -422
- package/src/testutils/context/test_context.ts +0 -25
- package/src/testutils/db/fixture.ts +0 -32
- package/src/testutils/db/temp_db.ts +0 -941
- package/src/testutils/db/value.ts +0 -294
- package/src/testutils/db_mock.ts +0 -351
- package/src/testutils/db_time_zone.ts +0 -40
- package/src/testutils/ent-graphql-tests/index.ts +0 -653
- package/src/testutils/fake_comms.ts +0 -50
- package/src/testutils/fake_data/const.ts +0 -64
- package/src/testutils/fake_data/events_query.ts +0 -145
- package/src/testutils/fake_data/fake_contact.ts +0 -150
- package/src/testutils/fake_data/fake_event.ts +0 -150
- package/src/testutils/fake_data/fake_tag.ts +0 -139
- package/src/testutils/fake_data/fake_user.ts +0 -232
- package/src/testutils/fake_data/index.ts +0 -1
- package/src/testutils/fake_data/internal.ts +0 -8
- package/src/testutils/fake_data/tag_query.ts +0 -56
- package/src/testutils/fake_data/test_helpers.ts +0 -388
- package/src/testutils/fake_data/user_query.ts +0 -524
- package/src/testutils/fake_log.ts +0 -52
- package/src/testutils/mock_date.ts +0 -10
- package/src/testutils/mock_log.ts +0 -39
- package/src/testutils/parse_sql.ts +0 -685
- package/src/testutils/test_edge_global_schema.ts +0 -49
- package/src/testutils/write.ts +0 -70
- package/src/tsc/ast.ts +0 -351
- package/src/tsc/compilerOptions.ts +0 -85
- package/src/tsc/move_generated.ts +0 -191
- package/src/tsc/transform.ts +0 -226
- package/src/tsc/transform_action.ts +0 -224
- package/src/tsc/transform_ent.ts +0 -66
- package/src/tsc/transform_schema.ts +0 -546
- package/tsconfig.json +0 -20
- /package/{dist/action → action}/action.d.ts +0 -0
- /package/{dist/action → action}/action.js +0 -0
- /package/{dist/action → action}/executor.d.ts +0 -0
- /package/{dist/action → action}/executor.js +0 -0
- /package/{dist/action → action}/experimental_action.d.ts +0 -0
- /package/{dist/action → action}/experimental_action.js +0 -0
- /package/{dist/action → action}/index.d.ts +0 -0
- /package/{dist/action → action}/index.js +0 -0
- /package/{dist/action → action}/operations.d.ts +0 -0
- /package/{dist/action → action}/operations.js +0 -0
- /package/{dist/action → action}/orchestrator.d.ts +0 -0
- /package/{dist/action → action}/orchestrator.js +0 -0
- /package/{dist/action → action}/privacy.d.ts +0 -0
- /package/{dist/action → action}/privacy.js +0 -0
- /package/{dist/action → action}/relative_value.d.ts +0 -0
- /package/{dist/action → action}/relative_value.js +0 -0
- /package/{dist/action → action}/transaction.d.ts +0 -0
- /package/{dist/action → action}/transaction.js +0 -0
- /package/{dist/auth → auth}/auth.d.ts +0 -0
- /package/{dist/auth → auth}/auth.js +0 -0
- /package/{dist/auth → auth}/index.d.ts +0 -0
- /package/{dist/auth → auth}/index.js +0 -0
- /package/{dist/core → core}/base.d.ts +0 -0
- /package/{dist/core → core}/base.js +0 -0
- /package/{dist/core → core}/clause.d.ts +0 -0
- /package/{dist/core → core}/clause.js +0 -0
- /package/{dist/core → core}/config.d.ts +0 -0
- /package/{dist/core → core}/config.js +0 -0
- /package/{dist/core → core}/const.d.ts +0 -0
- /package/{dist/core → core}/const.js +0 -0
- /package/{dist/core → core}/context.d.ts +0 -0
- /package/{dist/core → core}/context.js +0 -0
- /package/{dist/core → core}/convert.d.ts +0 -0
- /package/{dist/core → core}/convert.js +0 -0
- /package/{dist/core → core}/date.d.ts +0 -0
- /package/{dist/core → core}/date.js +0 -0
- /package/{dist/core → core}/db.d.ts +0 -0
- /package/{dist/core → core}/db.js +0 -0
- /package/{dist/core → core}/ent.d.ts +0 -0
- /package/{dist/core → core}/ent.js +0 -0
- /package/{dist/core → core}/global_schema.d.ts +0 -0
- /package/{dist/core → core}/global_schema.js +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
- /package/{dist/core → core}/loaders/index.d.ts +0 -0
- /package/{dist/core → core}/loaders/index.js +0 -0
- /package/{dist/core → core}/loaders/loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/loader.js +0 -0
- /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/object_loader.js +0 -0
- /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/query_loader.js +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
- /package/{dist/core → core}/logger.d.ts +0 -0
- /package/{dist/core → core}/logger.js +0 -0
- /package/{dist/core → core}/privacy.d.ts +0 -0
- /package/{dist/core → core}/privacy.js +0 -0
- /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
- /package/{dist/core → core}/query/assoc_query.js +0 -0
- /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_clause_query.js +0 -0
- /package/{dist/core → core}/query/custom_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_query.js +0 -0
- /package/{dist/core → core}/query/index.d.ts +0 -0
- /package/{dist/core → core}/query/index.js +0 -0
- /package/{dist/core → core}/query/query.d.ts +0 -0
- /package/{dist/core → core}/query/query.js +0 -0
- /package/{dist/core → core}/query_impl.d.ts +0 -0
- /package/{dist/core → core}/query_impl.js +0 -0
- /package/{dist/core → core}/viewer.d.ts +0 -0
- /package/{dist/core → core}/viewer.js +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
- /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/node.js +0 -0
- /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql.js +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
- /package/{dist/graphql → graphql}/index.d.ts +0 -0
- /package/{dist/graphql → graphql}/index.js +0 -0
- /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
- /package/{dist/graphql → graphql}/mutations/union.js +0 -0
- /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
- /package/{dist/graphql → graphql}/node_resolver.js +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/page_info.js +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
- /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/time.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
- /package/{dist/imports → imports}/index.d.ts +0 -0
- /package/{dist/imports → imports}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
- /package/{dist/schema → schema}/base_schema.d.ts +0 -0
- /package/{dist/schema → schema}/base_schema.js +0 -0
- /package/{dist/schema → schema}/field.d.ts +0 -0
- /package/{dist/schema → schema}/field.js +0 -0
- /package/{dist/schema → schema}/index.d.ts +0 -0
- /package/{dist/schema → schema}/index.js +0 -0
- /package/{dist/schema → schema}/json_field.d.ts +0 -0
- /package/{dist/schema → schema}/json_field.js +0 -0
- /package/{dist/schema → schema}/schema.d.ts +0 -0
- /package/{dist/schema → schema}/schema.js +0 -0
- /package/{dist/schema → schema}/struct_field.d.ts +0 -0
- /package/{dist/schema → schema}/struct_field.js +0 -0
- /package/{dist/schema → schema}/union_field.d.ts +0 -0
- /package/{dist/schema → schema}/union_field.js +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
- /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
- /package/{dist/scripts → scripts}/move_types.js +0 -0
- /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
- /package/{dist/scripts → scripts}/read_schema.js +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
- /package/{dist/testutils → testutils}/builder.d.ts +0 -0
- /package/{dist/testutils → testutils}/builder.js +0 -0
- /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
- /package/{dist/testutils → testutils}/context/test_context.js +0 -0
- /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/fixture.js +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
- /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/value.js +0 -0
- /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_mock.js +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_comms.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_log.js +0 -0
- /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_date.js +0 -0
- /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_log.js +0 -0
- /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
- /package/{dist/testutils → testutils}/parse_sql.js +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
- /package/{dist/testutils → testutils}/write.d.ts +0 -0
- /package/{dist/testutils → testutils}/write.js +0 -0
- /package/{dist/tsc → tsc}/ast.d.ts +0 -0
- /package/{dist/tsc → tsc}/ast.js +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
- /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
- /package/{dist/tsc → tsc}/move_generated.js +0 -0
- /package/{dist/tsc → tsc}/transform.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform.js +0 -0
- /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_action.js +0 -0
- /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_ent.js +0 -0
- /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_schema.js +0 -0
|
@@ -1,546 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import {
|
|
5
|
-
getClassInfo,
|
|
6
|
-
getImportInfo,
|
|
7
|
-
getPreText,
|
|
8
|
-
transformRelative,
|
|
9
|
-
} from "../tsc/ast";
|
|
10
|
-
import { TransformFile } from "./transform";
|
|
11
|
-
import { Data } from "../core/base";
|
|
12
|
-
import { PACKAGE, SCHEMA_PATH } from "../core/const";
|
|
13
|
-
|
|
14
|
-
interface traverseInfo {
|
|
15
|
-
rawString: string;
|
|
16
|
-
removeImports: string[];
|
|
17
|
-
newImports: string[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function traverseClass(
|
|
21
|
-
fileContents: string,
|
|
22
|
-
sourceFile: ts.SourceFile,
|
|
23
|
-
node: ts.ClassDeclaration,
|
|
24
|
-
transformSchema: (s: string) => string,
|
|
25
|
-
): traverseInfo | undefined {
|
|
26
|
-
const ci = getTransformClassInfo(
|
|
27
|
-
fileContents,
|
|
28
|
-
sourceFile,
|
|
29
|
-
node,
|
|
30
|
-
transformSchema,
|
|
31
|
-
);
|
|
32
|
-
if (!ci) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let klassContents = `${ci.comment}const ${ci.name} = new ${transformSchema(
|
|
37
|
-
ci.class,
|
|
38
|
-
)}({\n`;
|
|
39
|
-
let removeImports: string[] = [];
|
|
40
|
-
if (ci.implementsSchema) {
|
|
41
|
-
removeImports.push("Schema");
|
|
42
|
-
}
|
|
43
|
-
removeImports.push(ci.class);
|
|
44
|
-
let newImports: string[] = [transformSchema(ci.class)];
|
|
45
|
-
|
|
46
|
-
for (let member of node.members) {
|
|
47
|
-
const fInfo = getClassElementInfo(fileContents, member, sourceFile);
|
|
48
|
-
if (!fInfo) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
klassContents += `${fInfo.comment}${fInfo.key}:${fInfo.value},\n`;
|
|
52
|
-
if (fInfo.type) {
|
|
53
|
-
removeImports.push(fInfo.type);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
klassContents += "\n})";
|
|
58
|
-
if (ci.export && ci.default) {
|
|
59
|
-
klassContents += `\n export default ${ci.name};`;
|
|
60
|
-
} else if (ci.export) {
|
|
61
|
-
klassContents = "export " + klassContents;
|
|
62
|
-
}
|
|
63
|
-
// console.debug(klassContents);
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
rawString: klassContents,
|
|
67
|
-
removeImports: removeImports,
|
|
68
|
-
newImports,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface classInfo {
|
|
73
|
-
class: string;
|
|
74
|
-
comment: string;
|
|
75
|
-
name: string;
|
|
76
|
-
export?: boolean;
|
|
77
|
-
default?: boolean;
|
|
78
|
-
implementsSchema?: boolean;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getTransformClassInfo(
|
|
82
|
-
fileContents: string,
|
|
83
|
-
sourceFile: ts.SourceFile,
|
|
84
|
-
node: ts.ClassDeclaration,
|
|
85
|
-
transformSchema: (s: string) => string,
|
|
86
|
-
): classInfo | undefined {
|
|
87
|
-
const generic = getClassInfo(fileContents, sourceFile, node);
|
|
88
|
-
if (!generic) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let className = generic.name;
|
|
93
|
-
if (!className?.endsWith("Schema")) {
|
|
94
|
-
className += "Schema";
|
|
95
|
-
}
|
|
96
|
-
let implementsSchema = generic.implements?.some((v) => v == "Schema");
|
|
97
|
-
let classExtends = generic.extends;
|
|
98
|
-
// nothing transformed here, so nothing to do here
|
|
99
|
-
if (classExtends && classExtends === transformSchema(classExtends)) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!className || !node.heritageClauses || !classExtends) {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
let ci: classInfo = {
|
|
108
|
-
...generic,
|
|
109
|
-
name: className,
|
|
110
|
-
class: classExtends,
|
|
111
|
-
implementsSchema,
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return ci;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
interface propertyInfo {
|
|
118
|
-
key: string;
|
|
119
|
-
value: string;
|
|
120
|
-
comment: string;
|
|
121
|
-
type?: string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// intentionally doesn't parse decorators since we don't need it
|
|
125
|
-
function getClassElementInfo(
|
|
126
|
-
fileContents: string,
|
|
127
|
-
member: ts.ClassElement,
|
|
128
|
-
sourceFile: ts.SourceFile,
|
|
129
|
-
): propertyInfo | undefined {
|
|
130
|
-
if (isFieldElement(fileContents, member, sourceFile)) {
|
|
131
|
-
return getFieldElementInfo(fileContents, member, sourceFile);
|
|
132
|
-
}
|
|
133
|
-
if (member.kind === ts.SyntaxKind.Constructor) {
|
|
134
|
-
return getConstructorElementInfo(fileContents, member, sourceFile);
|
|
135
|
-
}
|
|
136
|
-
if (member.kind !== ts.SyntaxKind.PropertyDeclaration) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
// other properties
|
|
140
|
-
const property = member as ts.PropertyDeclaration;
|
|
141
|
-
if (!property.initializer) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const token = property.name as ts.Identifier;
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
key: token.escapedText.toString(),
|
|
148
|
-
value: property.initializer?.getFullText(sourceFile),
|
|
149
|
-
comment: getPreText(fileContents, member, sourceFile),
|
|
150
|
-
type: getType(property, sourceFile),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function getType(
|
|
155
|
-
property: ts.PropertyDeclaration,
|
|
156
|
-
sourceFile: ts.SourceFile,
|
|
157
|
-
): string {
|
|
158
|
-
let propertytype = property.type?.getText(sourceFile) || "";
|
|
159
|
-
let ends = ["| null", "[]"];
|
|
160
|
-
for (const end of ends) {
|
|
161
|
-
if (propertytype.endsWith(end)) {
|
|
162
|
-
propertytype = propertytype.slice(0, -1 * end.length);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return propertytype;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function getFieldElementInfo(
|
|
169
|
-
fileContents: string,
|
|
170
|
-
member: ts.ClassElement,
|
|
171
|
-
sourceFile: ts.SourceFile,
|
|
172
|
-
): propertyInfo | undefined {
|
|
173
|
-
let fieldMap = "";
|
|
174
|
-
|
|
175
|
-
// need to change to fields: {code: StringType()};
|
|
176
|
-
const property = member as ts.PropertyDeclaration;
|
|
177
|
-
const initializer = property.initializer as ts.ArrayLiteralExpression;
|
|
178
|
-
|
|
179
|
-
fieldMap += "{";
|
|
180
|
-
for (const element of initializer.elements) {
|
|
181
|
-
const parsed = parseFieldElement(element, sourceFile, fileContents);
|
|
182
|
-
if (parsed === null) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const { callEx, name, nameComment, properties, suffix } = parsed;
|
|
186
|
-
|
|
187
|
-
let property = "";
|
|
188
|
-
const fieldComment = getPreText(fileContents, element, sourceFile).trim();
|
|
189
|
-
if (fieldComment) {
|
|
190
|
-
property += "\n" + fieldComment + "\n";
|
|
191
|
-
}
|
|
192
|
-
if (nameComment) {
|
|
193
|
-
property += nameComment + "\n";
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// e.g. UUIDType, StringType etc
|
|
197
|
-
let call = callEx.expression.getText(sourceFile);
|
|
198
|
-
let fnCall = "";
|
|
199
|
-
if (properties.length) {
|
|
200
|
-
fnCall = `{${properties.join(",")}}`;
|
|
201
|
-
}
|
|
202
|
-
property += `${name}:${call}(${fnCall})${suffix || ""},`;
|
|
203
|
-
|
|
204
|
-
fieldMap += property;
|
|
205
|
-
}
|
|
206
|
-
fieldMap += "}";
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
key: "fields",
|
|
210
|
-
value: fieldMap,
|
|
211
|
-
comment: getPreText(fileContents, member, sourceFile),
|
|
212
|
-
type: getType(property, sourceFile),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function getConstructorElementInfo(
|
|
217
|
-
fileContents: string,
|
|
218
|
-
member: ts.ClassElement,
|
|
219
|
-
sourceFile: ts.SourceFile,
|
|
220
|
-
): propertyInfo | undefined {
|
|
221
|
-
const c = member as ts.ConstructorDeclaration;
|
|
222
|
-
//remove {}
|
|
223
|
-
let fullText = c.body?.getFullText(sourceFile) || "";
|
|
224
|
-
fullText = fullText.trim().slice(1, -1).trim();
|
|
225
|
-
|
|
226
|
-
// convert something like
|
|
227
|
-
/*
|
|
228
|
-
constructor() {
|
|
229
|
-
super();
|
|
230
|
-
this.addPatterns(
|
|
231
|
-
new Feedback(),
|
|
232
|
-
new DayOfWeek(),
|
|
233
|
-
new Feedback(),
|
|
234
|
-
new DayOfWeek(),
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
*/
|
|
238
|
-
// into this.addPatterns(new Feedback(),new DayOfWeek(),new Feedback(),new DayOfWeek(),)
|
|
239
|
-
const lines = fullText
|
|
240
|
-
.split("\n")
|
|
241
|
-
.map((line) => line.trim())
|
|
242
|
-
.join("")
|
|
243
|
-
.split(";")
|
|
244
|
-
.filter((f) => f != "super()" && f != "");
|
|
245
|
-
// at this point there should be only line for what we handle
|
|
246
|
-
if (lines.length != 1) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const line = lines[0];
|
|
250
|
-
const addPatterns = "this.addPatterns(";
|
|
251
|
-
if (!line.startsWith(addPatterns)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return {
|
|
256
|
-
key: "patterns",
|
|
257
|
-
// remove this.addPatterns at the front, remove trailing ) at the end
|
|
258
|
-
// if there's a trailing comma, it'll be handled by prettier
|
|
259
|
-
value: `[${line.slice(addPatterns.length, -1)}]`,
|
|
260
|
-
comment: "",
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function isFieldElement(
|
|
265
|
-
fileContents: string,
|
|
266
|
-
member: ts.ClassElement,
|
|
267
|
-
sourceFile: ts.SourceFile,
|
|
268
|
-
): boolean {
|
|
269
|
-
if (member.kind !== ts.SyntaxKind.PropertyDeclaration) {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
const property = member as ts.PropertyDeclaration;
|
|
273
|
-
const token = property.name as ts.Identifier;
|
|
274
|
-
if (token.escapedText !== "fields") {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const propertytype = property.type?.getText(sourceFile);
|
|
279
|
-
if (propertytype !== "Field[]") {
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (property.initializer?.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
|
|
284
|
-
throwErr(fileContents, member, "invalid array type");
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return true;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
interface ParsedFieldElement {
|
|
292
|
-
// parsedCallExpression
|
|
293
|
-
callEx: ts.CallExpression;
|
|
294
|
-
// name of field
|
|
295
|
-
name: string;
|
|
296
|
-
// any comment associated with just the name
|
|
297
|
-
nameComment?: string;
|
|
298
|
-
// other properties (and their comments) e.g. nullable: true
|
|
299
|
-
properties: string[];
|
|
300
|
-
// e.g. trim().toLowerCase()
|
|
301
|
-
suffix?: string;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// if there's an error transforming any of the schemas, we should stop...
|
|
305
|
-
function throwErr(fileContents: string, node: ts.Node, error: string) {
|
|
306
|
-
console.error(error);
|
|
307
|
-
throw new Error(
|
|
308
|
-
`error transforming this field ${fileContents.substring(
|
|
309
|
-
node.getFullStart(),
|
|
310
|
-
node.getEnd(),
|
|
311
|
-
)}`,
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
function parseFieldElement(
|
|
316
|
-
element: ts.Expression,
|
|
317
|
-
sourceFile: ts.SourceFile,
|
|
318
|
-
fileContents: string,
|
|
319
|
-
nested?: boolean,
|
|
320
|
-
): ParsedFieldElement | null {
|
|
321
|
-
if (
|
|
322
|
-
element.kind !== ts.SyntaxKind.CallExpression &&
|
|
323
|
-
element.kind !== ts.SyntaxKind.PropertyAccessExpression
|
|
324
|
-
) {
|
|
325
|
-
throwErr(
|
|
326
|
-
fileContents,
|
|
327
|
-
element,
|
|
328
|
-
`skipped unknown (non-call|non-property) expression ${element.kind}`,
|
|
329
|
-
);
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (element.kind === ts.SyntaxKind.PropertyAccessExpression) {
|
|
334
|
-
const ret = parseFieldElement(
|
|
335
|
-
(element as ts.PropertyAccessExpression).expression,
|
|
336
|
-
sourceFile,
|
|
337
|
-
fileContents,
|
|
338
|
-
true,
|
|
339
|
-
);
|
|
340
|
-
if (ret !== null) {
|
|
341
|
-
if (!nested) {
|
|
342
|
-
ret.suffix = fileContents.substring(
|
|
343
|
-
ret.callEx.getEnd(),
|
|
344
|
-
element.getEnd(),
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
return ret;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
let callEx = element as ts.CallExpression;
|
|
351
|
-
if (callEx.arguments.length !== 1) {
|
|
352
|
-
// have a situation like: StringType({ name: "canonicalName" }).trim().toLowerCase(),
|
|
353
|
-
// need to keep calling this until we find what we want and then get the suffix we should just add to the end of the transformed code
|
|
354
|
-
if (callEx.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
|
|
355
|
-
const ret = parseFieldElement(
|
|
356
|
-
(callEx.expression as ts.PropertyAccessExpression).expression,
|
|
357
|
-
sourceFile,
|
|
358
|
-
fileContents,
|
|
359
|
-
true,
|
|
360
|
-
);
|
|
361
|
-
if (ret !== null) {
|
|
362
|
-
if (!nested) {
|
|
363
|
-
ret.suffix = fileContents.substring(
|
|
364
|
-
ret.callEx.getEnd(),
|
|
365
|
-
callEx.getEnd(),
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
return ret;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
throwErr(
|
|
373
|
-
fileContents,
|
|
374
|
-
element,
|
|
375
|
-
"callExpression with arguments not of length 1",
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
let arg = callEx.arguments[0];
|
|
380
|
-
if (arg.kind !== ts.SyntaxKind.ObjectLiteralExpression) {
|
|
381
|
-
// this and the check above for PropertyAccessExpression are to handle things like
|
|
382
|
-
// FooType({
|
|
383
|
-
/// ...
|
|
384
|
-
// }).function(blah)
|
|
385
|
-
const ret = parseFieldElement(
|
|
386
|
-
callEx.expression,
|
|
387
|
-
sourceFile,
|
|
388
|
-
fileContents,
|
|
389
|
-
true,
|
|
390
|
-
);
|
|
391
|
-
if (ret !== null) {
|
|
392
|
-
if (!nested) {
|
|
393
|
-
ret.suffix = fileContents.substring(
|
|
394
|
-
ret.callEx.getEnd(),
|
|
395
|
-
callEx.getEnd(),
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
return ret;
|
|
399
|
-
}
|
|
400
|
-
throwErr(
|
|
401
|
-
fileContents,
|
|
402
|
-
element,
|
|
403
|
-
`not objectLiteralExpression. kind ${arg.kind}`,
|
|
404
|
-
);
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
let expr = arg as ts.ObjectLiteralExpression;
|
|
409
|
-
let name = "";
|
|
410
|
-
let propertyComment: string | undefined;
|
|
411
|
-
let properties: string[] = [];
|
|
412
|
-
|
|
413
|
-
for (const p of expr.properties) {
|
|
414
|
-
const p2 = p as ts.PropertyAssignment;
|
|
415
|
-
|
|
416
|
-
// found name property
|
|
417
|
-
if ((p2.name as ts.Identifier).escapedText === "name") {
|
|
418
|
-
name = p2.initializer.getText(sourceFile);
|
|
419
|
-
// check for any comment associated with name: "fooo"
|
|
420
|
-
propertyComment = getPreText(fileContents, p, sourceFile).trim();
|
|
421
|
-
} else {
|
|
422
|
-
properties.push(p.getFullText(sourceFile));
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (!name) {
|
|
427
|
-
throwErr(fileContents, element, `couldn't find name property`);
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
// remove quotes
|
|
431
|
-
name = name.slice(1, -1);
|
|
432
|
-
|
|
433
|
-
return {
|
|
434
|
-
callEx,
|
|
435
|
-
name,
|
|
436
|
-
properties,
|
|
437
|
-
nameComment: propertyComment,
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// find which of these importPaths is being used and use that to replace
|
|
442
|
-
function findSchemaImportPath(sourceFile: ts.SourceFile) {
|
|
443
|
-
const paths: Data = {
|
|
444
|
-
[PACKAGE]: true,
|
|
445
|
-
[SCHEMA_PATH]: true,
|
|
446
|
-
[`${SCHEMA_PATH}/`]: true,
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
// @ts-ignore
|
|
450
|
-
const importStatements: ts.ImportDeclaration[] = sourceFile.statements.filter(
|
|
451
|
-
(stmt) => ts.isImportDeclaration(stmt),
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
for (const imp of importStatements) {
|
|
455
|
-
const impInfo = getImportInfo(imp, sourceFile);
|
|
456
|
-
if (!impInfo) {
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
if (paths[impInfo.importPath] !== undefined) {
|
|
460
|
-
return impInfo.importPath;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
export class TransformSchema implements TransformFile {
|
|
466
|
-
// we only end up doing this once because we change the schema representation
|
|
467
|
-
// so safe to run this multiple times
|
|
468
|
-
|
|
469
|
-
constructor(
|
|
470
|
-
private relativeImports: boolean,
|
|
471
|
-
private oldBaseClass?: string,
|
|
472
|
-
private newSchemaClass?: string,
|
|
473
|
-
private transformPath?: string,
|
|
474
|
-
) {}
|
|
475
|
-
|
|
476
|
-
glob = "src/schema/*.ts";
|
|
477
|
-
|
|
478
|
-
private transformSchema(className: string) {
|
|
479
|
-
if (className === "BaseEntSchema" || className === "BaseEntSchemaWithTZ") {
|
|
480
|
-
return className.substring(4);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (className === this.oldBaseClass && this.newSchemaClass) {
|
|
484
|
-
return this.newSchemaClass;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
return className;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
traverseChild(
|
|
491
|
-
sourceFile: ts.SourceFile,
|
|
492
|
-
contents: string,
|
|
493
|
-
file: string,
|
|
494
|
-
node: ts.Node,
|
|
495
|
-
) {
|
|
496
|
-
if (!ts.isClassDeclaration(node)) {
|
|
497
|
-
return { node };
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// TODO address implicit schema doesn't work here...
|
|
501
|
-
const ret = traverseClass(
|
|
502
|
-
contents,
|
|
503
|
-
sourceFile,
|
|
504
|
-
node,
|
|
505
|
-
this.transformSchema.bind(this),
|
|
506
|
-
);
|
|
507
|
-
if (ret === undefined) {
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
let imports = new Map<string, string[]>();
|
|
512
|
-
|
|
513
|
-
const imp = findSchemaImportPath(sourceFile);
|
|
514
|
-
if (imp) {
|
|
515
|
-
if (this.transformPath) {
|
|
516
|
-
imports.set(imp, []);
|
|
517
|
-
} else {
|
|
518
|
-
imports.set(imp, ret.newImports);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (this.transformPath) {
|
|
522
|
-
// add new imports to this path
|
|
523
|
-
imports.set(
|
|
524
|
-
transformRelative(file, this.transformPath, this.relativeImports),
|
|
525
|
-
ret.newImports,
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return {
|
|
530
|
-
traversed: true,
|
|
531
|
-
rawString: ret.rawString,
|
|
532
|
-
removeImports: ret.removeImports,
|
|
533
|
-
imports: imports,
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
fileToWrite(file: string) {
|
|
538
|
-
return "src/schema/" + path.basename(file).slice(0, -3) + "_schema.ts";
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
postProcess(file: string) {
|
|
542
|
-
fs.rmSync(file);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
prettierGlob = "src/schema/*.ts";
|
|
546
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// TODO
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"lib": ["es2018", "esnext.asynciterable", "ES2020.String"],
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"target": "es2020",
|
|
9
|
-
"strictNullChecks": true,
|
|
10
|
-
"downlevelIteration": true,
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
"baseUrl": ".",
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
"skipLibCheck": true
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*"],
|
|
18
|
-
"exclude": ["./examples", "tests/**/*"],
|
|
19
|
-
"files": ["node_modules/jest-expect-message/types/index.d.ts"]
|
|
20
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|