@snowtop/ent 0.1.0-alpha160-test7 → 0.1.0-alpha161-test1
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/{dist/core → core}/query/assoc_query.d.ts +3 -0
- package/{dist/core → core}/query/assoc_query.js +71 -0
- package/{dist/core → core}/query/query.d.ts +3 -0
- package/{dist/core → core}/query/query.js +20 -6
- package/core/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +1089 -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 +8 -53
- package/{dist/testutils → testutils}/fake_data/test_helpers.js +2 -1
- 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/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_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_compiler.js +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.js +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/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,234 +0,0 @@
|
|
|
1
|
-
import { camelCase } from "camel-case";
|
|
2
|
-
import { BaseField, ListField } from "./field";
|
|
3
|
-
import {
|
|
4
|
-
FieldOptions,
|
|
5
|
-
Field,
|
|
6
|
-
Type,
|
|
7
|
-
DBType,
|
|
8
|
-
FieldMap,
|
|
9
|
-
getStorageKey,
|
|
10
|
-
} from "./schema";
|
|
11
|
-
import {
|
|
12
|
-
__getGlobalSchemaField,
|
|
13
|
-
__getGlobalSchemaFields,
|
|
14
|
-
} from "../core/global_schema";
|
|
15
|
-
import { log } from "../core/logger";
|
|
16
|
-
|
|
17
|
-
interface structFieldOptions extends FieldOptions {
|
|
18
|
-
// required.
|
|
19
|
-
// how does that jive with https://github.com/lolopinto/ent/issues/609 though??
|
|
20
|
-
tsType: string;
|
|
21
|
-
fields: FieldMap;
|
|
22
|
-
// if not provided, defaults to tsType
|
|
23
|
-
graphQLType?: string;
|
|
24
|
-
jsonNotJSONB?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface GlobalStructOptions extends FieldOptions {
|
|
28
|
-
globalType: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type StructOptions = structFieldOptions | GlobalStructOptions;
|
|
32
|
-
|
|
33
|
-
export class StructField extends BaseField implements Field {
|
|
34
|
-
type: Type = {
|
|
35
|
-
dbType: DBType.JSONB,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
constructor(private options: StructOptions, private jsonAsList?: boolean) {
|
|
39
|
-
super();
|
|
40
|
-
this.type.subFields = options.fields;
|
|
41
|
-
this.type.type = options.tsType;
|
|
42
|
-
this.type.graphQLType = options.graphQLType || options.tsType;
|
|
43
|
-
this.type.globalType = this.options.globalType;
|
|
44
|
-
if (options.jsonNotJSONB) {
|
|
45
|
-
this.type.dbType = DBType.JSON;
|
|
46
|
-
}
|
|
47
|
-
if (jsonAsList) {
|
|
48
|
-
this.type.listElemType = {
|
|
49
|
-
dbType: DBType.JSONB,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
formatImpl(obj: any, nested?: boolean) {
|
|
55
|
-
if (!(obj instanceof Object)) {
|
|
56
|
-
throw new Error("valid was not called");
|
|
57
|
-
}
|
|
58
|
-
let ret: Object = {};
|
|
59
|
-
for (const k in this.options.fields) {
|
|
60
|
-
const field = this.options.fields[k];
|
|
61
|
-
|
|
62
|
-
// check two values
|
|
63
|
-
// store in dbKey format
|
|
64
|
-
|
|
65
|
-
// TODO more #510
|
|
66
|
-
let dbKey = getStorageKey(field, k);
|
|
67
|
-
let camelKey = camelCase(k);
|
|
68
|
-
let val = obj[camelKey];
|
|
69
|
-
|
|
70
|
-
if (val === undefined && obj[dbKey] !== undefined) {
|
|
71
|
-
val = obj[dbKey];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (val === undefined) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (field.format) {
|
|
78
|
-
// indicate nested so this isn't JSON stringified
|
|
79
|
-
ret[dbKey] = field.format(val, true);
|
|
80
|
-
} else {
|
|
81
|
-
ret[dbKey] = val;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// don't json.stringify if nested or list
|
|
85
|
-
if (nested) {
|
|
86
|
-
return ret;
|
|
87
|
-
}
|
|
88
|
-
return JSON.stringify(ret);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
format(obj: any, nested?: boolean) {
|
|
92
|
-
if (this.type.globalType) {
|
|
93
|
-
const f = __getGlobalSchemaField(this.type.globalType);
|
|
94
|
-
if (f && f.format) {
|
|
95
|
-
if (
|
|
96
|
-
JSON.stringify(this.type.listElemType) !==
|
|
97
|
-
JSON.stringify(f?.type.listElemType)
|
|
98
|
-
) {
|
|
99
|
-
if (this.jsonAsList) {
|
|
100
|
-
// handle as nested
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
const formatted = obj.map((v: any) => f.format(v, true));
|
|
103
|
-
if (nested) {
|
|
104
|
-
return formatted;
|
|
105
|
-
} else {
|
|
106
|
-
return JSON.stringify(formatted);
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
const formatted = f.format([obj], true);
|
|
110
|
-
if (nested) {
|
|
111
|
-
return formatted[0];
|
|
112
|
-
} else {
|
|
113
|
-
return JSON.stringify(formatted[0]);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// TODO handle format code
|
|
119
|
-
return f.format(obj);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (Array.isArray(obj) && this.jsonAsList) {
|
|
123
|
-
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
124
|
-
if (nested) {
|
|
125
|
-
return ret;
|
|
126
|
-
}
|
|
127
|
-
return JSON.stringify(ret);
|
|
128
|
-
}
|
|
129
|
-
return this.formatImpl(obj, nested);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private async validImpl(obj: any) {
|
|
133
|
-
if (!(obj instanceof Object)) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let promises: (boolean | Promise<boolean>)[] = [];
|
|
138
|
-
// TODO probably need to support optional fields...
|
|
139
|
-
let valid = true;
|
|
140
|
-
for (const k in this.options.fields) {
|
|
141
|
-
const field = this.options.fields[k];
|
|
142
|
-
// TODO more #510
|
|
143
|
-
let dbKey = getStorageKey(field, k);
|
|
144
|
-
let camelKey = camelCase(k);
|
|
145
|
-
let val = obj[camelKey];
|
|
146
|
-
|
|
147
|
-
if (val === undefined && obj[dbKey] !== undefined) {
|
|
148
|
-
val = obj[dbKey];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (val === undefined || val === null) {
|
|
152
|
-
// nullable, nothing to do here
|
|
153
|
-
if (field.nullable) {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
valid = false;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
if (!field.valid) {
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
promises.push(field.valid(val));
|
|
163
|
-
}
|
|
164
|
-
if (!valid) {
|
|
165
|
-
return valid;
|
|
166
|
-
}
|
|
167
|
-
const ret = await Promise.all(promises);
|
|
168
|
-
return ret.every((v) => v);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async valid(obj: any): Promise<boolean> {
|
|
172
|
-
if (this.type.globalType) {
|
|
173
|
-
const f = __getGlobalSchemaField(this.type.globalType);
|
|
174
|
-
// list and global type is not valid.
|
|
175
|
-
if (f) {
|
|
176
|
-
if (f.valid) {
|
|
177
|
-
if (
|
|
178
|
-
JSON.stringify(this.type.listElemType) !==
|
|
179
|
-
JSON.stringify(f?.type.listElemType)
|
|
180
|
-
) {
|
|
181
|
-
if (this.jsonAsList) {
|
|
182
|
-
if (!Array.isArray(obj)) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
// @ts-ignore
|
|
186
|
-
const valid = await Promise.all(obj.map((v) => f.valid(v)));
|
|
187
|
-
return valid.every((b) => b);
|
|
188
|
-
} else {
|
|
189
|
-
return f.valid([obj]);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return f.valid(obj);
|
|
194
|
-
}
|
|
195
|
-
return true;
|
|
196
|
-
} else {
|
|
197
|
-
log(
|
|
198
|
-
"error",
|
|
199
|
-
`globalType ${this.type.globalType} not found in global schema`,
|
|
200
|
-
);
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (this.jsonAsList) {
|
|
205
|
-
if (!Array.isArray(obj)) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
209
|
-
return valid.every((b) => b);
|
|
210
|
-
}
|
|
211
|
-
if (!(obj instanceof Object)) {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return this.validImpl(obj);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export function StructType(options: StructOptions) {
|
|
220
|
-
let result = new StructField(options);
|
|
221
|
-
return Object.assign(result, options);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @deprecated use StructTypeAsList
|
|
226
|
-
*/
|
|
227
|
-
export function StructListType(options: StructOptions) {
|
|
228
|
-
return new ListField(StructType(options), options);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export function StructTypeAsList(options: StructOptions) {
|
|
232
|
-
let result = new StructField(options, true);
|
|
233
|
-
return Object.assign(result, options);
|
|
234
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { StructField } from "./struct_field";
|
|
2
|
-
import { FieldOptions, DBType, Type } from "./schema";
|
|
3
|
-
import { BaseField, ListField } from "./field";
|
|
4
|
-
|
|
5
|
-
export declare type StructMap = {
|
|
6
|
-
[key: string]: StructField;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
// used to know which key in the union is valid.
|
|
10
|
-
// maybe there's a better way of doing this eventually
|
|
11
|
-
const KEY = "___valid___key___";
|
|
12
|
-
|
|
13
|
-
export interface UnionOptions extends FieldOptions {
|
|
14
|
-
// required.
|
|
15
|
-
// how does that jive with https://github.com/lolopinto/ent/issues/609 though??
|
|
16
|
-
tsType: string;
|
|
17
|
-
// StructMap enforced in TS here but FieldMap in Type
|
|
18
|
-
// we want keys because of GraphQL oneOf type
|
|
19
|
-
fields: StructMap;
|
|
20
|
-
// if not provided, defaults to tsType
|
|
21
|
-
graphQLType?: string;
|
|
22
|
-
jsonNotJSONB?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface validResult {
|
|
26
|
-
valid: boolean;
|
|
27
|
-
key: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class UnionField extends BaseField implements FieldOptions {
|
|
31
|
-
type: Type = {
|
|
32
|
-
dbType: DBType.JSONB,
|
|
33
|
-
};
|
|
34
|
-
m: Map<Object, string> = new Map();
|
|
35
|
-
|
|
36
|
-
constructor(private options: UnionOptions) {
|
|
37
|
-
super();
|
|
38
|
-
this.type.unionFields = options.fields;
|
|
39
|
-
this.type.type = options.tsType;
|
|
40
|
-
this.type.graphQLType = options.graphQLType || options.tsType;
|
|
41
|
-
// TODO should throw if not nested?
|
|
42
|
-
if (options.jsonNotJSONB) {
|
|
43
|
-
this.type.dbType = DBType.JSON;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
format(obj: any) {
|
|
48
|
-
if (!(obj instanceof Object)) {
|
|
49
|
-
throw new Error("valid was not called");
|
|
50
|
-
}
|
|
51
|
-
const k = obj[KEY];
|
|
52
|
-
if (k === undefined) {
|
|
53
|
-
throw new Error(`need to call valid first`);
|
|
54
|
-
}
|
|
55
|
-
// now delete it since we don't need it anymore
|
|
56
|
-
delete obj[KEY];
|
|
57
|
-
|
|
58
|
-
const field = this.options.fields[k];
|
|
59
|
-
// always nested for now so pass through
|
|
60
|
-
return field.format(obj, true);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private async validField(k: string, f: StructField, obj: Object) {
|
|
64
|
-
const valid = await f.valid(obj);
|
|
65
|
-
return {
|
|
66
|
-
valid,
|
|
67
|
-
key: k,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async valid(obj: any): Promise<boolean> {
|
|
72
|
-
if (!(obj instanceof Object)) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
let promises: Promise<validResult>[] = [];
|
|
76
|
-
|
|
77
|
-
for (const k in this.options.fields) {
|
|
78
|
-
const field = this.options.fields[k];
|
|
79
|
-
promises.push(this.validField(k, field, obj));
|
|
80
|
-
}
|
|
81
|
-
let lastKey: string | undefined;
|
|
82
|
-
let validCt = 0;
|
|
83
|
-
const ret = await Promise.all(promises);
|
|
84
|
-
for (const v of ret) {
|
|
85
|
-
if (v.valid) {
|
|
86
|
-
validCt++;
|
|
87
|
-
lastKey = v.key;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (lastKey !== undefined) {
|
|
91
|
-
obj[KEY] = lastKey;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return validCt == 1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function UnionType(options: UnionOptions) {
|
|
99
|
-
let result = new UnionField(options);
|
|
100
|
-
return Object.assign(result, options);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function UnionListType(options: UnionOptions) {
|
|
104
|
-
return new ListField(UnionType(options), options);
|
|
105
|
-
}
|
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import * as glob from "glob";
|
|
6
|
-
import { readCompilerOptions } from "../tsc/compilerOptions";
|
|
7
|
-
|
|
8
|
-
// TODO this should probably be its own package but for now it's here
|
|
9
|
-
|
|
10
|
-
class Compiler {
|
|
11
|
-
private options: ts.CompilerOptions;
|
|
12
|
-
private regexMap: Map<string, RegExp> = new Map();
|
|
13
|
-
private cwd: string;
|
|
14
|
-
|
|
15
|
-
private resolvers: ((
|
|
16
|
-
moduleName: string,
|
|
17
|
-
containingFile: string,
|
|
18
|
-
) => ts.ResolvedModule | undefined | null)[] = [];
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
private sourceFiles: string[],
|
|
22
|
-
private moduleSearchLocations: string[],
|
|
23
|
-
) {
|
|
24
|
-
this.options = readCompilerOptions(".");
|
|
25
|
-
if (this.options.paths) {
|
|
26
|
-
for (let key in this.options.paths) {
|
|
27
|
-
if (key === "*") {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
// always make sure it starts at the beginning...
|
|
31
|
-
this.regexMap.set(key, new RegExp("^" + key, "i"));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// TODO should be taking baseUrl and using that instead of using cwd and assuming baseUrl == "."
|
|
35
|
-
this.cwd = process.cwd();
|
|
36
|
-
|
|
37
|
-
// set resolvers
|
|
38
|
-
this.resolvers = [
|
|
39
|
-
// standard
|
|
40
|
-
this.standardModules.bind(this),
|
|
41
|
-
|
|
42
|
-
// resolvePaths based on tsconfig's paths
|
|
43
|
-
this.resolvePaths.bind(this),
|
|
44
|
-
|
|
45
|
-
// use node or other location paths
|
|
46
|
-
this.otherLocations.bind(this),
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private standardModules(moduleName: string, containingFile: string) {
|
|
51
|
-
let result = ts.resolveModuleName(
|
|
52
|
-
moduleName,
|
|
53
|
-
containingFile,
|
|
54
|
-
this.options,
|
|
55
|
-
{
|
|
56
|
-
fileExists: ts.sys.fileExists,
|
|
57
|
-
readFile: ts.sys.readFile,
|
|
58
|
-
},
|
|
59
|
-
);
|
|
60
|
-
return result.resolvedModule;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private resolvePaths(
|
|
64
|
-
moduleName: string,
|
|
65
|
-
_containingFile: string,
|
|
66
|
-
): ts.ResolvedModule | undefined {
|
|
67
|
-
// console.log("resolvePaths", moduleName);
|
|
68
|
-
if (!this.options.paths) {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let paths = this.options.paths;
|
|
73
|
-
for (let key in paths) {
|
|
74
|
-
let r = this.regexMap.get(key);
|
|
75
|
-
if (!r) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
let value = paths[key];
|
|
79
|
-
|
|
80
|
-
if (r.test(moduleName)) {
|
|
81
|
-
// substitute...
|
|
82
|
-
// can this be more than one?
|
|
83
|
-
// not for now...
|
|
84
|
-
let str = value[0];
|
|
85
|
-
let lastIdx = value[0].lastIndexOf("*");
|
|
86
|
-
if (lastIdx === -1) {
|
|
87
|
-
console.error("incorrectly formatted regex");
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
str = str.substr(0, lastIdx);
|
|
91
|
-
let resolvedFileName =
|
|
92
|
-
path.join(this.cwd, moduleName.replace(r, str)) + ".ts";
|
|
93
|
-
// console.log(resolvedFileName);
|
|
94
|
-
return {
|
|
95
|
-
resolvedFileName,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private otherLocations(moduleName: string, _containingFile: string) {
|
|
103
|
-
for (const location of this.moduleSearchLocations) {
|
|
104
|
-
const modulePath = path.join(location, moduleName + ".d.ts");
|
|
105
|
-
if (ts.sys.fileExists(modulePath)) {
|
|
106
|
-
return { resolvedFileName: modulePath };
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private createCompilerHost(): ts.CompilerHost {
|
|
113
|
-
return {
|
|
114
|
-
getSourceFile: this.getSourceFile,
|
|
115
|
-
getDefaultLibFileName: () => "lib.d.ts",
|
|
116
|
-
writeFile: (fileName, content) => ts.sys.writeFile(fileName, content),
|
|
117
|
-
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
118
|
-
getDirectories: (path) => ts.sys.getDirectories(path),
|
|
119
|
-
getCanonicalFileName: (fileName) =>
|
|
120
|
-
ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
121
|
-
getNewLine: () => ts.sys.newLine,
|
|
122
|
-
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
123
|
-
fileExists: ts.sys.fileExists,
|
|
124
|
-
readFile: ts.sys.readFile,
|
|
125
|
-
resolveModuleNames: (
|
|
126
|
-
moduleNames: string[],
|
|
127
|
-
containingFile: string,
|
|
128
|
-
_reusedNames: string[] | undefined,
|
|
129
|
-
_redirectedReference: ts.ResolvedProjectReference | undefined,
|
|
130
|
-
_options: ts.CompilerOptions,
|
|
131
|
-
) => {
|
|
132
|
-
return this.resolveModuleNames(moduleNames, containingFile);
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private getSourceFile(
|
|
138
|
-
fileName: string,
|
|
139
|
-
languageVersion: ts.ScriptTarget,
|
|
140
|
-
onError?: (message: string) => void,
|
|
141
|
-
) {
|
|
142
|
-
const sourceText = ts.sys.readFile(fileName);
|
|
143
|
-
return sourceText !== undefined
|
|
144
|
-
? ts.createSourceFile(fileName, sourceText, languageVersion)
|
|
145
|
-
: undefined;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// this is not enough because it doesn't solve the outputted file?
|
|
149
|
-
private resolveModuleNames(
|
|
150
|
-
moduleNames: string[],
|
|
151
|
-
containingFile: string,
|
|
152
|
-
): (ts.ResolvedModule | undefined)[] {
|
|
153
|
-
// go through each moduleName and resolvers in order to see if we find what we're looking for
|
|
154
|
-
let resolvedModules: (ts.ResolvedModule | undefined)[] = [];
|
|
155
|
-
for (const moduleName of moduleNames) {
|
|
156
|
-
// undefined is valid
|
|
157
|
-
let resolved: ts.ResolvedModule | undefined;
|
|
158
|
-
for (const resolver of this.resolvers) {
|
|
159
|
-
let result = resolver(moduleName, containingFile);
|
|
160
|
-
// yay!
|
|
161
|
-
if (result) {
|
|
162
|
-
resolved = result;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
resolvedModules.push(resolved);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return resolvedModules;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private transformer(context: ts.TransformationContext) {
|
|
173
|
-
let cwd = this.cwd;
|
|
174
|
-
let paths = this.options.paths;
|
|
175
|
-
let regexMap = this.regexMap;
|
|
176
|
-
return function (node: ts.SourceFile) {
|
|
177
|
-
// don't do anything with declaration files
|
|
178
|
-
// nothing to do here
|
|
179
|
-
if (node.isDeclarationFile) {
|
|
180
|
-
return node;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// no paths, nothing to do heree
|
|
184
|
-
if (!paths) {
|
|
185
|
-
return node;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let fullPath: string;
|
|
189
|
-
if (path.isAbsolute(node.fileName)) {
|
|
190
|
-
fullPath = node.fileName;
|
|
191
|
-
} else {
|
|
192
|
-
fullPath = path.join(cwd, node.fileName);
|
|
193
|
-
}
|
|
194
|
-
// don't care about paths not relative to cwd since we can't handle that...
|
|
195
|
-
let relativePath = path.relative(cwd, fullPath);
|
|
196
|
-
if (relativePath.startsWith("..")) {
|
|
197
|
-
return node;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function checkPath(
|
|
201
|
-
paths: ts.MapLike<string[]> | undefined,
|
|
202
|
-
text: string,
|
|
203
|
-
): string | undefined {
|
|
204
|
-
// remove quotes
|
|
205
|
-
text = text.slice(1, -1);
|
|
206
|
-
let relPath: string | undefined;
|
|
207
|
-
|
|
208
|
-
for (const key in paths) {
|
|
209
|
-
let r = regexMap.get(key);
|
|
210
|
-
if (!r) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
let value = paths[key];
|
|
214
|
-
let str = value[0];
|
|
215
|
-
|
|
216
|
-
if (!r.test(text)) {
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
let idx = text.indexOf("/");
|
|
220
|
-
let strIdx = str.indexOf("*");
|
|
221
|
-
if (idx === -1 || strIdx === -1) {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
relPath = path.relative(
|
|
225
|
-
// just because of how imports work. it's relative from directory not current path
|
|
226
|
-
path.dirname(fullPath),
|
|
227
|
-
path.join(
|
|
228
|
-
text.substring(0, idx).replace(r, str.substring(0, strIdx)),
|
|
229
|
-
text.substring(idx),
|
|
230
|
-
),
|
|
231
|
-
);
|
|
232
|
-
// if file ends with "..", we've reached a case where we're trying to
|
|
233
|
-
// import something like foo/contact(.ts) from within foo/contact/bar/baz/page.ts
|
|
234
|
-
// and we're confused about it so we need to detect that case and handle it
|
|
235
|
-
if (relPath.endsWith("..")) {
|
|
236
|
-
// there's an actual local file here not root of directory, try that instead
|
|
237
|
-
// (if root of directory and there's ambiguity, we should use "contact/")
|
|
238
|
-
if (ts.sys.fileExists(text + ".ts")) {
|
|
239
|
-
let text2 = text + ".ts";
|
|
240
|
-
relPath = path.relative(
|
|
241
|
-
// just because of how imports work. it's relative from directory not current path
|
|
242
|
-
path.dirname(fullPath),
|
|
243
|
-
path.join(
|
|
244
|
-
text2.substring(0, idx).replace(r, str.substring(0, strIdx)),
|
|
245
|
-
text2.substring(idx),
|
|
246
|
-
),
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (!relPath.startsWith("..")) {
|
|
251
|
-
relPath = "./" + relPath;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// tsc removes this by default so we need to also do it
|
|
255
|
-
let tsIdx = relPath.indexOf(".ts");
|
|
256
|
-
if (tsIdx !== -1) {
|
|
257
|
-
relPath = relPath.substring(0, tsIdx);
|
|
258
|
-
}
|
|
259
|
-
return relPath;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function visitor(node: ts.Node) {
|
|
264
|
-
if (node.kind === ts.SyntaxKind.ImportDeclaration) {
|
|
265
|
-
let importNode = node as ts.ImportDeclaration;
|
|
266
|
-
|
|
267
|
-
let text = importNode.moduleSpecifier.getText();
|
|
268
|
-
let relPath = checkPath(paths, text);
|
|
269
|
-
if (relPath) {
|
|
270
|
-
// update the node...
|
|
271
|
-
return ts.factory.updateImportDeclaration(
|
|
272
|
-
importNode,
|
|
273
|
-
importNode.modifiers,
|
|
274
|
-
importNode.importClause,
|
|
275
|
-
ts.factory.createStringLiteral(relPath),
|
|
276
|
-
importNode.assertClause,
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (node.kind === ts.SyntaxKind.ExportDeclaration) {
|
|
281
|
-
let exportNode = node as ts.ExportDeclaration;
|
|
282
|
-
|
|
283
|
-
let text = exportNode.moduleSpecifier?.getText();
|
|
284
|
-
|
|
285
|
-
if (text) {
|
|
286
|
-
let relPath = checkPath(paths, text);
|
|
287
|
-
if (relPath) {
|
|
288
|
-
// update the node...
|
|
289
|
-
return ts.factory.updateExportDeclaration(
|
|
290
|
-
exportNode,
|
|
291
|
-
exportNode.modifiers,
|
|
292
|
-
exportNode.isTypeOnly,
|
|
293
|
-
exportNode.exportClause,
|
|
294
|
-
ts.factory.createStringLiteral(relPath),
|
|
295
|
-
exportNode.assertClause,
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return node;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return ts.visitEachChild(node, visitor, context);
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
compile(): void {
|
|
308
|
-
const host = this.createCompilerHost();
|
|
309
|
-
const program = ts.createProgram(this.sourceFiles, this.options, host);
|
|
310
|
-
let emitResult = program.emit(undefined, undefined, undefined, undefined, {
|
|
311
|
-
before: [this.transformer.bind(this)],
|
|
312
|
-
});
|
|
313
|
-
if (emitResult.emitSkipped) {
|
|
314
|
-
console.error("error emitting code");
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
let exitCode = emitResult.emitSkipped ? 1 : 0;
|
|
318
|
-
process.exit(exitCode);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// let's use a glob from current directory
|
|
323
|
-
// todo this should be configurable
|
|
324
|
-
// TODO this should be broken into its own repo and npm module
|
|
325
|
-
// TODO use includes and exclude in tsconfig.json if it exists
|
|
326
|
-
new Compiler(
|
|
327
|
-
glob.sync("**/*.ts", {
|
|
328
|
-
ignore: ["node_modules/**", "tests/**", "**/*.test.ts"],
|
|
329
|
-
}),
|
|
330
|
-
["node_modules/@types/node"],
|
|
331
|
-
).compile();
|