@snowtop/ent 0.1.0-alpha160-test4 → 0.1.0-alpha160-test6
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/package.json +64 -0
- package/{scripts → dist/scripts}/custom_compiler.js +0 -0
- package/{scripts → dist/scripts}/custom_graphql.js +0 -0
- package/package.json +48 -6
- package/src/action/action.ts +330 -0
- package/src/action/executor.ts +453 -0
- package/src/action/experimental_action.ts +277 -0
- package/src/action/index.ts +31 -0
- package/src/action/operations.ts +967 -0
- package/src/action/orchestrator.ts +1527 -0
- package/src/action/privacy.ts +37 -0
- package/src/action/relative_value.ts +242 -0
- package/src/action/transaction.ts +38 -0
- package/src/auth/auth.ts +77 -0
- package/src/auth/index.ts +8 -0
- package/src/core/base.ts +367 -0
- package/src/core/clause.ts +1065 -0
- package/src/core/config.ts +219 -0
- package/src/core/const.ts +5 -0
- package/src/core/context.ts +135 -0
- package/src/core/convert.ts +106 -0
- package/src/core/date.ts +23 -0
- package/src/core/db.ts +498 -0
- package/src/core/ent.ts +1740 -0
- package/src/core/global_schema.ts +49 -0
- package/src/core/loaders/assoc_count_loader.ts +99 -0
- package/src/core/loaders/assoc_edge_loader.ts +250 -0
- package/src/core/loaders/index.ts +12 -0
- package/src/core/loaders/loader.ts +66 -0
- package/src/core/loaders/object_loader.ts +489 -0
- package/src/core/loaders/query_loader.ts +314 -0
- package/src/core/loaders/raw_count_loader.ts +175 -0
- package/src/core/logger.ts +49 -0
- package/src/core/privacy.ts +660 -0
- package/src/core/query/assoc_query.ts +240 -0
- package/src/core/query/custom_clause_query.ts +174 -0
- package/src/core/query/custom_query.ts +302 -0
- package/src/core/query/index.ts +9 -0
- package/src/core/query/query.ts +674 -0
- package/src/core/query_impl.ts +32 -0
- package/src/core/viewer.ts +52 -0
- package/src/ent.code-workspace +73 -0
- package/src/graphql/builtins/connection.ts +25 -0
- package/src/graphql/builtins/edge.ts +16 -0
- package/src/graphql/builtins/node.ts +12 -0
- package/src/graphql/graphql.ts +891 -0
- package/src/graphql/graphql_field_helpers.ts +221 -0
- package/src/graphql/index.ts +42 -0
- package/src/graphql/mutations/union.ts +39 -0
- package/src/graphql/node_resolver.ts +122 -0
- package/src/graphql/query/connection_type.ts +113 -0
- package/src/graphql/query/edge_connection.ts +171 -0
- package/src/graphql/query/page_info.ts +34 -0
- package/src/graphql/query/shared_edge_connection.ts +287 -0
- package/src/graphql/scalars/orderby_direction.ts +13 -0
- package/src/graphql/scalars/time.ts +38 -0
- package/src/imports/dataz/example1/_auth.ts +51 -0
- package/src/imports/dataz/example1/_viewer.ts +35 -0
- package/src/imports/index.ts +213 -0
- package/src/index.ts +145 -0
- package/src/parse_schema/parse.ts +585 -0
- package/src/schema/base_schema.ts +224 -0
- package/src/schema/field.ts +1087 -0
- package/src/schema/index.ts +53 -0
- package/src/schema/json_field.ts +94 -0
- package/src/schema/schema.ts +1028 -0
- package/src/schema/struct_field.ts +234 -0
- package/src/schema/union_field.ts +105 -0
- package/src/scripts/custom_compiler.ts +331 -0
- package/src/scripts/custom_graphql.ts +550 -0
- package/src/scripts/migrate_v0.1.ts +41 -0
- package/src/scripts/move_types.ts +131 -0
- package/src/scripts/read_schema.ts +67 -0
- package/src/setupPackage.js +42 -0
- package/src/testutils/action/complex_schemas.ts +517 -0
- package/src/testutils/builder.ts +422 -0
- package/src/testutils/context/test_context.ts +25 -0
- package/src/testutils/db/fixture.ts +32 -0
- package/src/testutils/db/temp_db.ts +941 -0
- package/src/testutils/db/value.ts +294 -0
- package/src/testutils/db_mock.ts +351 -0
- package/src/testutils/db_time_zone.ts +40 -0
- package/src/testutils/ent-graphql-tests/index.ts +653 -0
- package/src/testutils/fake_comms.ts +50 -0
- package/src/testutils/fake_data/const.ts +64 -0
- package/src/testutils/fake_data/events_query.ts +145 -0
- package/src/testutils/fake_data/fake_contact.ts +150 -0
- package/src/testutils/fake_data/fake_event.ts +150 -0
- package/src/testutils/fake_data/fake_tag.ts +139 -0
- package/src/testutils/fake_data/fake_user.ts +232 -0
- package/src/testutils/fake_data/index.ts +1 -0
- package/src/testutils/fake_data/internal.ts +8 -0
- package/src/testutils/fake_data/tag_query.ts +56 -0
- package/src/testutils/fake_data/test_helpers.ts +388 -0
- package/src/testutils/fake_data/user_query.ts +524 -0
- package/src/testutils/fake_log.ts +52 -0
- package/src/testutils/mock_date.ts +10 -0
- package/src/testutils/mock_log.ts +39 -0
- package/src/testutils/parse_sql.ts +685 -0
- package/src/testutils/test_edge_global_schema.ts +49 -0
- package/src/testutils/write.ts +70 -0
- package/src/tsc/ast.ts +351 -0
- package/src/tsc/compilerOptions.ts +85 -0
- package/src/tsc/move_generated.ts +191 -0
- package/src/tsc/transform.ts +226 -0
- package/src/tsc/transform_action.ts +224 -0
- package/src/tsc/transform_ent.ts +66 -0
- package/src/tsc/transform_schema.ts +546 -0
- package/tsconfig.json +20 -0
- package/core/query/shared_assoc_test.d.ts +0 -2
- package/core/query/shared_assoc_test.js +0 -804
- package/core/query/shared_test.d.ts +0 -21
- package/core/query/shared_test.js +0 -736
- package/graphql/query/shared_assoc_test.d.ts +0 -1
- package/graphql/query/shared_assoc_test.js +0 -203
- /package/{action → dist/action}/action.d.ts +0 -0
- /package/{action → dist/action}/action.js +0 -0
- /package/{action → dist/action}/executor.d.ts +0 -0
- /package/{action → dist/action}/executor.js +0 -0
- /package/{action → dist/action}/experimental_action.d.ts +0 -0
- /package/{action → dist/action}/experimental_action.js +0 -0
- /package/{action → dist/action}/index.d.ts +0 -0
- /package/{action → dist/action}/index.js +0 -0
- /package/{action → dist/action}/operations.d.ts +0 -0
- /package/{action → dist/action}/operations.js +0 -0
- /package/{action → dist/action}/orchestrator.d.ts +0 -0
- /package/{action → dist/action}/orchestrator.js +0 -0
- /package/{action → dist/action}/privacy.d.ts +0 -0
- /package/{action → dist/action}/privacy.js +0 -0
- /package/{action → dist/action}/relative_value.d.ts +0 -0
- /package/{action → dist/action}/relative_value.js +0 -0
- /package/{action → dist/action}/transaction.d.ts +0 -0
- /package/{action → dist/action}/transaction.js +0 -0
- /package/{auth → dist/auth}/auth.d.ts +0 -0
- /package/{auth → dist/auth}/auth.js +0 -0
- /package/{auth → dist/auth}/index.d.ts +0 -0
- /package/{auth → dist/auth}/index.js +0 -0
- /package/{core → dist/core}/base.d.ts +0 -0
- /package/{core → dist/core}/base.js +0 -0
- /package/{core → dist/core}/clause.d.ts +0 -0
- /package/{core → dist/core}/clause.js +0 -0
- /package/{core → dist/core}/config.d.ts +0 -0
- /package/{core → dist/core}/config.js +0 -0
- /package/{core → dist/core}/const.d.ts +0 -0
- /package/{core → dist/core}/const.js +0 -0
- /package/{core → dist/core}/context.d.ts +0 -0
- /package/{core → dist/core}/context.js +0 -0
- /package/{core → dist/core}/convert.d.ts +0 -0
- /package/{core → dist/core}/convert.js +0 -0
- /package/{core → dist/core}/date.d.ts +0 -0
- /package/{core → dist/core}/date.js +0 -0
- /package/{core → dist/core}/db.d.ts +0 -0
- /package/{core → dist/core}/db.js +0 -0
- /package/{core → dist/core}/ent.d.ts +0 -0
- /package/{core → dist/core}/ent.js +0 -0
- /package/{core → dist/core}/global_schema.d.ts +0 -0
- /package/{core → dist/core}/global_schema.js +0 -0
- /package/{core → dist/core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/assoc_count_loader.js +0 -0
- /package/{core → dist/core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/assoc_edge_loader.js +0 -0
- /package/{core → dist/core}/loaders/index.d.ts +0 -0
- /package/{core → dist/core}/loaders/index.js +0 -0
- /package/{core → dist/core}/loaders/loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/loader.js +0 -0
- /package/{core → dist/core}/loaders/object_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/object_loader.js +0 -0
- /package/{core → dist/core}/loaders/query_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/query_loader.js +0 -0
- /package/{core → dist/core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/raw_count_loader.js +0 -0
- /package/{core → dist/core}/logger.d.ts +0 -0
- /package/{core → dist/core}/logger.js +0 -0
- /package/{core → dist/core}/privacy.d.ts +0 -0
- /package/{core → dist/core}/privacy.js +0 -0
- /package/{core → dist/core}/query/assoc_query.d.ts +0 -0
- /package/{core → dist/core}/query/assoc_query.js +0 -0
- /package/{core → dist/core}/query/custom_clause_query.d.ts +0 -0
- /package/{core → dist/core}/query/custom_clause_query.js +0 -0
- /package/{core → dist/core}/query/custom_query.d.ts +0 -0
- /package/{core → dist/core}/query/custom_query.js +0 -0
- /package/{core → dist/core}/query/index.d.ts +0 -0
- /package/{core → dist/core}/query/index.js +0 -0
- /package/{core → dist/core}/query/query.d.ts +0 -0
- /package/{core → dist/core}/query/query.js +0 -0
- /package/{core → dist/core}/query_impl.d.ts +0 -0
- /package/{core → dist/core}/query_impl.js +0 -0
- /package/{core → dist/core}/viewer.d.ts +0 -0
- /package/{core → dist/core}/viewer.js +0 -0
- /package/{graphql → dist/graphql}/builtins/connection.d.ts +0 -0
- /package/{graphql → dist/graphql}/builtins/connection.js +0 -0
- /package/{graphql → dist/graphql}/builtins/edge.d.ts +0 -0
- /package/{graphql → dist/graphql}/builtins/edge.js +0 -0
- /package/{graphql → dist/graphql}/builtins/node.d.ts +0 -0
- /package/{graphql → dist/graphql}/builtins/node.js +0 -0
- /package/{graphql → dist/graphql}/graphql.d.ts +0 -0
- /package/{graphql → dist/graphql}/graphql.js +0 -0
- /package/{graphql → dist/graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{graphql → dist/graphql}/graphql_field_helpers.js +0 -0
- /package/{graphql → dist/graphql}/index.d.ts +0 -0
- /package/{graphql → dist/graphql}/index.js +0 -0
- /package/{graphql → dist/graphql}/mutations/union.d.ts +0 -0
- /package/{graphql → dist/graphql}/mutations/union.js +0 -0
- /package/{graphql → dist/graphql}/node_resolver.d.ts +0 -0
- /package/{graphql → dist/graphql}/node_resolver.js +0 -0
- /package/{graphql → dist/graphql}/query/connection_type.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/connection_type.js +0 -0
- /package/{graphql → dist/graphql}/query/edge_connection.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/edge_connection.js +0 -0
- /package/{graphql → dist/graphql}/query/page_info.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/page_info.js +0 -0
- /package/{graphql → dist/graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/shared_edge_connection.js +0 -0
- /package/{graphql → dist/graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{graphql → dist/graphql}/scalars/orderby_direction.js +0 -0
- /package/{graphql → dist/graphql}/scalars/time.d.ts +0 -0
- /package/{graphql → dist/graphql}/scalars/time.js +0 -0
- /package/{imports → dist/imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{imports → dist/imports}/dataz/example1/_auth.js +0 -0
- /package/{imports → dist/imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{imports → dist/imports}/dataz/example1/_viewer.js +0 -0
- /package/{imports → dist/imports}/index.d.ts +0 -0
- /package/{imports → dist/imports}/index.js +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{parse_schema → dist/parse_schema}/parse.d.ts +0 -0
- /package/{parse_schema → dist/parse_schema}/parse.js +0 -0
- /package/{schema → dist/schema}/base_schema.d.ts +0 -0
- /package/{schema → dist/schema}/base_schema.js +0 -0
- /package/{schema → dist/schema}/field.d.ts +0 -0
- /package/{schema → dist/schema}/field.js +0 -0
- /package/{schema → dist/schema}/index.d.ts +0 -0
- /package/{schema → dist/schema}/index.js +0 -0
- /package/{schema → dist/schema}/json_field.d.ts +0 -0
- /package/{schema → dist/schema}/json_field.js +0 -0
- /package/{schema → dist/schema}/schema.d.ts +0 -0
- /package/{schema → dist/schema}/schema.js +0 -0
- /package/{schema → dist/schema}/struct_field.d.ts +0 -0
- /package/{schema → dist/schema}/struct_field.js +0 -0
- /package/{schema → dist/schema}/union_field.d.ts +0 -0
- /package/{schema → dist/schema}/union_field.js +0 -0
- /package/{scripts → dist/scripts}/custom_compiler.d.ts +0 -0
- /package/{scripts → dist/scripts}/custom_graphql.d.ts +0 -0
- /package/{scripts → dist/scripts}/migrate_v0.1.d.ts +0 -0
- /package/{scripts → dist/scripts}/migrate_v0.1.js +0 -0
- /package/{scripts → dist/scripts}/move_types.d.ts +0 -0
- /package/{scripts → dist/scripts}/move_types.js +0 -0
- /package/{scripts → dist/scripts}/read_schema.d.ts +0 -0
- /package/{scripts → dist/scripts}/read_schema.js +0 -0
- /package/{testutils → dist/testutils}/action/complex_schemas.d.ts +0 -0
- /package/{testutils → dist/testutils}/action/complex_schemas.js +0 -0
- /package/{testutils → dist/testutils}/builder.d.ts +0 -0
- /package/{testutils → dist/testutils}/builder.js +0 -0
- /package/{testutils → dist/testutils}/context/test_context.d.ts +0 -0
- /package/{testutils → dist/testutils}/context/test_context.js +0 -0
- /package/{testutils → dist/testutils}/db/fixture.d.ts +0 -0
- /package/{testutils → dist/testutils}/db/fixture.js +0 -0
- /package/{testutils → dist/testutils}/db/temp_db.d.ts +0 -0
- /package/{testutils → dist/testutils}/db/temp_db.js +0 -0
- /package/{testutils → dist/testutils}/db/value.d.ts +0 -0
- /package/{testutils → dist/testutils}/db/value.js +0 -0
- /package/{testutils → dist/testutils}/db_mock.d.ts +0 -0
- /package/{testutils → dist/testutils}/db_mock.js +0 -0
- /package/{testutils → dist/testutils}/db_time_zone.d.ts +0 -0
- /package/{testutils → dist/testutils}/db_time_zone.js +0 -0
- /package/{testutils → dist/testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{testutils → dist/testutils}/ent-graphql-tests/index.js +0 -0
- /package/{testutils → dist/testutils}/fake_comms.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_comms.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/const.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/const.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/events_query.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/events_query.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_contact.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_event.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_tag.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_user.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/index.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/index.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/internal.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/internal.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/tag_query.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/test_helpers.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/user_query.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/user_query.js +0 -0
- /package/{testutils → dist/testutils}/fake_log.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_log.js +0 -0
- /package/{testutils → dist/testutils}/mock_date.d.ts +0 -0
- /package/{testutils → dist/testutils}/mock_date.js +0 -0
- /package/{testutils → dist/testutils}/mock_log.d.ts +0 -0
- /package/{testutils → dist/testutils}/mock_log.js +0 -0
- /package/{testutils → dist/testutils}/parse_sql.d.ts +0 -0
- /package/{testutils → dist/testutils}/parse_sql.js +0 -0
- /package/{testutils → dist/testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{testutils → dist/testutils}/test_edge_global_schema.js +0 -0
- /package/{testutils → dist/testutils}/write.d.ts +0 -0
- /package/{testutils → dist/testutils}/write.js +0 -0
- /package/{tsc → dist/tsc}/ast.d.ts +0 -0
- /package/{tsc → dist/tsc}/ast.js +0 -0
- /package/{tsc → dist/tsc}/compilerOptions.d.ts +0 -0
- /package/{tsc → dist/tsc}/compilerOptions.js +0 -0
- /package/{tsc → dist/tsc}/move_generated.d.ts +0 -0
- /package/{tsc → dist/tsc}/move_generated.js +0 -0
- /package/{tsc → dist/tsc}/transform.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform.js +0 -0
- /package/{tsc → dist/tsc}/transform_action.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform_action.js +0 -0
- /package/{tsc → dist/tsc}/transform_ent.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform_ent.js +0 -0
- /package/{tsc → dist/tsc}/transform_schema.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform_schema.js +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SQLStatementOperation,
|
|
3
|
+
TimestampType,
|
|
4
|
+
EdgeUpdateOperation,
|
|
5
|
+
TransformedEdgeUpdateOperation,
|
|
6
|
+
} from "../schema";
|
|
7
|
+
import * as clause from "../core/clause";
|
|
8
|
+
import { AssocEdge } from "../core/ent";
|
|
9
|
+
import { Data } from "../core/base";
|
|
10
|
+
|
|
11
|
+
export class EdgeWithDeletedAt extends AssocEdge {
|
|
12
|
+
deletedAt: Date | null;
|
|
13
|
+
|
|
14
|
+
constructor(data: Data) {
|
|
15
|
+
super(data);
|
|
16
|
+
this.deletedAt = data.deleted_at;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const testEdgeGlobalSchema = {
|
|
21
|
+
extraEdgeFields: {
|
|
22
|
+
// need this to be lowerCamelCase because we do this based on field name
|
|
23
|
+
// #510
|
|
24
|
+
deletedAt: TimestampType({
|
|
25
|
+
nullable: true,
|
|
26
|
+
index: true,
|
|
27
|
+
defaultValueOnCreate: () => null,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
transformEdgeRead(): clause.Clause {
|
|
32
|
+
return clause.Eq("deleted_at", null);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
transformEdgeWrite(
|
|
36
|
+
stmt: EdgeUpdateOperation,
|
|
37
|
+
): TransformedEdgeUpdateOperation | null {
|
|
38
|
+
switch (stmt.op) {
|
|
39
|
+
case SQLStatementOperation.Delete:
|
|
40
|
+
return {
|
|
41
|
+
op: SQLStatementOperation.Update,
|
|
42
|
+
data: {
|
|
43
|
+
deleted_at: new Date(),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EditRowOptions,
|
|
3
|
+
Data,
|
|
4
|
+
DataOptions,
|
|
5
|
+
CreateRowOptions,
|
|
6
|
+
} from "../core/base";
|
|
7
|
+
import {
|
|
8
|
+
createRow,
|
|
9
|
+
editRow,
|
|
10
|
+
deleteRows,
|
|
11
|
+
createRowSync,
|
|
12
|
+
editRowSync,
|
|
13
|
+
deleteRowsSync,
|
|
14
|
+
} from "../core/ent";
|
|
15
|
+
import * as clause from "../core/clause";
|
|
16
|
+
import DB, { Client, Dialect, SyncClient } from "../core/db";
|
|
17
|
+
|
|
18
|
+
function isSyncClient(client: Client): client is SyncClient {
|
|
19
|
+
return (client as SyncClient).execSync !== undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function createRowForTest(
|
|
23
|
+
options: CreateRowOptions,
|
|
24
|
+
suffix?: string,
|
|
25
|
+
): Promise<Data | null> {
|
|
26
|
+
let client: Client;
|
|
27
|
+
if (Dialect.SQLite === DB.getDialect()) {
|
|
28
|
+
client = DB.getInstance().getSQLiteClient();
|
|
29
|
+
} else {
|
|
30
|
+
client = await DB.getInstance().getNewClient();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
if (isSyncClient(client)) {
|
|
35
|
+
return createRowSync(client, options, suffix || "");
|
|
36
|
+
}
|
|
37
|
+
return await createRow(client, options, suffix || "");
|
|
38
|
+
} finally {
|
|
39
|
+
client.release();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function editRowForTest(options: EditRowOptions, suffix?: string) {
|
|
44
|
+
const client = await DB.getInstance().getNewClient();
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
if (isSyncClient(client)) {
|
|
48
|
+
return editRowSync(client, options, suffix || "");
|
|
49
|
+
}
|
|
50
|
+
return await editRow(client, options, suffix);
|
|
51
|
+
} finally {
|
|
52
|
+
client.release();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function deleteRowsForTest(
|
|
57
|
+
options: DataOptions,
|
|
58
|
+
cls: clause.Clause,
|
|
59
|
+
) {
|
|
60
|
+
const client = await DB.getInstance().getNewClient();
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
if (isSyncClient(client)) {
|
|
64
|
+
return deleteRowsSync(client, options, cls);
|
|
65
|
+
}
|
|
66
|
+
return await deleteRows(client, options, cls);
|
|
67
|
+
} finally {
|
|
68
|
+
client.release();
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/tsc/ast.ts
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { Data } from "../core/base";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { load } from "js-yaml";
|
|
5
|
+
import { ConfigWithCodegen } from "../core/config";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import { PACKAGE } from "../core/const";
|
|
8
|
+
|
|
9
|
+
export function getPreText(
|
|
10
|
+
fileContents: string,
|
|
11
|
+
node: ts.Node,
|
|
12
|
+
sourceFile: ts.SourceFile,
|
|
13
|
+
): string {
|
|
14
|
+
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ClassInfo {
|
|
18
|
+
extends?: string;
|
|
19
|
+
comment: string;
|
|
20
|
+
name: string;
|
|
21
|
+
export?: boolean;
|
|
22
|
+
default?: boolean;
|
|
23
|
+
// implementsSchema?: boolean;
|
|
24
|
+
implements?: string[];
|
|
25
|
+
wrapClassContents(inner: string): string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getClassInfo(
|
|
29
|
+
fileContents: string,
|
|
30
|
+
sourceFile: ts.SourceFile,
|
|
31
|
+
node: ts.ClassDeclaration,
|
|
32
|
+
): ClassInfo | undefined {
|
|
33
|
+
let className = node.name?.text;
|
|
34
|
+
|
|
35
|
+
let classExtends: string | undefined;
|
|
36
|
+
let impl: string[] = [];
|
|
37
|
+
if (node.heritageClauses) {
|
|
38
|
+
for (const hc of node.heritageClauses) {
|
|
39
|
+
switch (hc.token) {
|
|
40
|
+
case ts.SyntaxKind.ImplementsKeyword:
|
|
41
|
+
for (const type of hc.types) {
|
|
42
|
+
impl.push(type.expression.getText(sourceFile));
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
case ts.SyntaxKind.ExtendsKeyword:
|
|
47
|
+
// can only extend one class
|
|
48
|
+
for (const type of hc.types) {
|
|
49
|
+
const text = type.expression.getText(sourceFile);
|
|
50
|
+
classExtends = text;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!className) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let hasExport = false;
|
|
62
|
+
let hasDefault = false;
|
|
63
|
+
let comment = getPreText(fileContents, node, sourceFile);
|
|
64
|
+
|
|
65
|
+
const wrapClassContents = (inner: string) => {
|
|
66
|
+
let ret = `${comment}`;
|
|
67
|
+
if (hasExport) {
|
|
68
|
+
ret += "export ";
|
|
69
|
+
}
|
|
70
|
+
if (hasDefault) {
|
|
71
|
+
ret += "default ";
|
|
72
|
+
}
|
|
73
|
+
ret += `class ${className} `;
|
|
74
|
+
if (classExtends) {
|
|
75
|
+
ret += `extends ${classExtends} `;
|
|
76
|
+
}
|
|
77
|
+
if (impl.length) {
|
|
78
|
+
ret += `implements ${impl.join(", ")}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return `${ret}{
|
|
82
|
+
${inner}
|
|
83
|
+
}`;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (node.modifiers) {
|
|
87
|
+
for (const mod of node.modifiers) {
|
|
88
|
+
const text = mod.getText(sourceFile);
|
|
89
|
+
if (text === "export") {
|
|
90
|
+
hasExport = true;
|
|
91
|
+
} else if (text === "default") {
|
|
92
|
+
hasDefault = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
name: className,
|
|
99
|
+
extends: classExtends,
|
|
100
|
+
comment,
|
|
101
|
+
implements: impl,
|
|
102
|
+
wrapClassContents,
|
|
103
|
+
export: hasExport,
|
|
104
|
+
default: hasDefault,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type transformImportFn = (imp: string) => string;
|
|
109
|
+
|
|
110
|
+
interface transformOpts {
|
|
111
|
+
removeImports?: string[];
|
|
112
|
+
newImports?: string[];
|
|
113
|
+
transform?: transformImportFn;
|
|
114
|
+
transformPath: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function transformImport(
|
|
118
|
+
fileContents: string,
|
|
119
|
+
importNode: ts.ImportDeclaration,
|
|
120
|
+
sourceFile: ts.SourceFile,
|
|
121
|
+
opts: transformOpts,
|
|
122
|
+
): string | undefined {
|
|
123
|
+
// remove quotes too
|
|
124
|
+
const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
125
|
+
if (text != opts.transformPath) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const impInfo = getImportInfo(importNode, sourceFile);
|
|
130
|
+
if (!impInfo) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
let { imports, start, end, importText, default: def } = impInfo;
|
|
134
|
+
|
|
135
|
+
let removeImportsMap: Data = {};
|
|
136
|
+
if (opts?.removeImports) {
|
|
137
|
+
opts.removeImports.forEach((imp) => {
|
|
138
|
+
removeImportsMap[imp] = true;
|
|
139
|
+
if (def === imp) {
|
|
140
|
+
def = "";
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
let finalImports = new Set<string>();
|
|
145
|
+
|
|
146
|
+
for (let i = 0; i < imports.length; i++) {
|
|
147
|
+
let imp = imports[i].trim();
|
|
148
|
+
if (imp === "") {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (opts?.transform) {
|
|
152
|
+
imp = opts.transform(imp);
|
|
153
|
+
}
|
|
154
|
+
if (removeImportsMap[imp]) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
finalImports.add(imp);
|
|
158
|
+
}
|
|
159
|
+
if (opts?.newImports) {
|
|
160
|
+
opts.newImports.forEach((imp) => finalImports.add(imp));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const comment = getPreText(fileContents, importNode, sourceFile);
|
|
164
|
+
|
|
165
|
+
if (!finalImports.size) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
comment +
|
|
171
|
+
"import " +
|
|
172
|
+
// add default
|
|
173
|
+
(def || "") +
|
|
174
|
+
// should probably always be "{" now that we support default
|
|
175
|
+
(start >= 0 ? importText.substring(0, start + 1) : "{") +
|
|
176
|
+
Array.from(finalImports).join(", ") +
|
|
177
|
+
// should probably always be "}"
|
|
178
|
+
(end >= 0 ? importText.substring(end) : "}") +
|
|
179
|
+
' from "' +
|
|
180
|
+
text +
|
|
181
|
+
'";'
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function updateImportPath(
|
|
186
|
+
fileContents: string,
|
|
187
|
+
importNode: ts.ImportDeclaration,
|
|
188
|
+
sourceFile: ts.SourceFile,
|
|
189
|
+
newPath: string,
|
|
190
|
+
) {
|
|
191
|
+
const comment = getPreText(fileContents, importNode, sourceFile);
|
|
192
|
+
|
|
193
|
+
// all this copied from above...
|
|
194
|
+
const importText = importNode.importClause?.getText(sourceFile) || "";
|
|
195
|
+
const start = importText.indexOf("{");
|
|
196
|
+
const end = importText.lastIndexOf("}");
|
|
197
|
+
if (start === -1 || end === -1) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const imports = importText
|
|
201
|
+
.substring(start + 1, end)
|
|
202
|
+
// .trim()
|
|
203
|
+
.split(",");
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
comment +
|
|
207
|
+
"import " +
|
|
208
|
+
importText.substring(0, start + 1) +
|
|
209
|
+
Array.from(imports).join(", ") +
|
|
210
|
+
importText.substring(end) +
|
|
211
|
+
' from "' +
|
|
212
|
+
newPath +
|
|
213
|
+
'";'
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function isRelativeImport(
|
|
218
|
+
node: ts.ImportDeclaration,
|
|
219
|
+
sourceFile: ts.SourceFile,
|
|
220
|
+
) {
|
|
221
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
222
|
+
return text.startsWith("..") || text.startsWith("./");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function isRelativeGeneratedImport(
|
|
226
|
+
node: ts.ImportDeclaration,
|
|
227
|
+
sourceFile: ts.SourceFile,
|
|
228
|
+
) {
|
|
229
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
230
|
+
return (
|
|
231
|
+
(text.startsWith("..") || text.startsWith("./")) &&
|
|
232
|
+
text.indexOf("/generated") !== -1
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function isSrcGeneratedImport(
|
|
237
|
+
node: ts.ImportDeclaration,
|
|
238
|
+
sourceFile: ts.SourceFile,
|
|
239
|
+
) {
|
|
240
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
241
|
+
return text.startsWith("src") && text.includes("/generated");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface importInfo {
|
|
245
|
+
imports: string[];
|
|
246
|
+
start: number;
|
|
247
|
+
end: number;
|
|
248
|
+
importText: string;
|
|
249
|
+
importPath: string;
|
|
250
|
+
default?: string;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// TODO doesn't support default + {} yet
|
|
254
|
+
export function getImportInfo(
|
|
255
|
+
imp: ts.ImportDeclaration,
|
|
256
|
+
sourceFile: ts.SourceFile,
|
|
257
|
+
): importInfo | undefined {
|
|
258
|
+
const importText = imp.importClause?.getText(sourceFile) || "";
|
|
259
|
+
const start = importText.indexOf("{");
|
|
260
|
+
const end = importText.lastIndexOf("}");
|
|
261
|
+
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
262
|
+
|
|
263
|
+
if ((start === -1 || end === -1) && !importText.length) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
let imports: string[] = [];
|
|
267
|
+
let def: string | undefined;
|
|
268
|
+
if (start !== -1 && end !== -1) {
|
|
269
|
+
imports = importText
|
|
270
|
+
.substring(start + 1, end)
|
|
271
|
+
//.trim()
|
|
272
|
+
.split(",");
|
|
273
|
+
} else {
|
|
274
|
+
def = importText;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
importPath: text,
|
|
279
|
+
importText,
|
|
280
|
+
start,
|
|
281
|
+
end,
|
|
282
|
+
imports,
|
|
283
|
+
default: def,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function transformRelative(
|
|
288
|
+
file: string,
|
|
289
|
+
importPath: string,
|
|
290
|
+
relative?: boolean,
|
|
291
|
+
): string {
|
|
292
|
+
if (!relative || !importPath.startsWith("src")) {
|
|
293
|
+
return importPath;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const fileFullPath = path.join(process.cwd(), file);
|
|
297
|
+
const impFullPath = path.join(process.cwd(), importPath);
|
|
298
|
+
// relative path is from directory
|
|
299
|
+
return normalizePath(path.relative(path.dirname(fileFullPath), impFullPath));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function normalizePath(p: string) {
|
|
303
|
+
if (p.endsWith("..")) {
|
|
304
|
+
return p + "/";
|
|
305
|
+
}
|
|
306
|
+
if (!p.startsWith("..")) {
|
|
307
|
+
return "./" + p;
|
|
308
|
+
}
|
|
309
|
+
return p;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface customInfo {
|
|
313
|
+
viewerInfo: {
|
|
314
|
+
path: string;
|
|
315
|
+
name: string;
|
|
316
|
+
};
|
|
317
|
+
relativeImports?: boolean;
|
|
318
|
+
globalSchemaPath?: string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// also used in parse schema logic
|
|
322
|
+
export function getCustomInfo(): customInfo {
|
|
323
|
+
let yaml: ConfigWithCodegen | undefined = {};
|
|
324
|
+
|
|
325
|
+
let relativeImports = false;
|
|
326
|
+
try {
|
|
327
|
+
yaml = load(
|
|
328
|
+
fs.readFileSync(path.join(process.cwd(), "ent.yml"), {
|
|
329
|
+
encoding: "utf8",
|
|
330
|
+
}),
|
|
331
|
+
) as ConfigWithCodegen;
|
|
332
|
+
|
|
333
|
+
relativeImports = yaml?.codegen?.relativeImports || false;
|
|
334
|
+
|
|
335
|
+
if (yaml?.codegen?.templatizedViewer) {
|
|
336
|
+
return {
|
|
337
|
+
viewerInfo: yaml.codegen.templatizedViewer,
|
|
338
|
+
relativeImports,
|
|
339
|
+
globalSchemaPath: yaml.globalSchemaPath,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
} catch (e) {}
|
|
343
|
+
return {
|
|
344
|
+
viewerInfo: {
|
|
345
|
+
path: PACKAGE,
|
|
346
|
+
name: "Viewer",
|
|
347
|
+
},
|
|
348
|
+
relativeImports,
|
|
349
|
+
globalSchemaPath: yaml.globalSchemaPath,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import JSON5 from "json5";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
|
|
6
|
+
function findTSConfigFile(filePath: string): string | null {
|
|
7
|
+
while (filePath != "/") {
|
|
8
|
+
let configPath = `${filePath}/tsconfig.json`;
|
|
9
|
+
if (fs.existsSync(configPath)) {
|
|
10
|
+
return configPath;
|
|
11
|
+
}
|
|
12
|
+
filePath = path.join(filePath, "..");
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function readCompilerOptions(filePath: string) {
|
|
18
|
+
let configPath = findTSConfigFile(filePath);
|
|
19
|
+
if (!configPath) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let json: any = {};
|
|
24
|
+
try {
|
|
25
|
+
json = JSON5.parse(
|
|
26
|
+
fs.readFileSync(configPath, {
|
|
27
|
+
encoding: "utf8",
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.error("couldn't read tsconfig.json file");
|
|
32
|
+
}
|
|
33
|
+
let options: ts.CompilerOptions = json["compilerOptions"] || {};
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
if (options.moduleResolution === "node") {
|
|
36
|
+
options.moduleResolution = ts.ModuleResolutionKind.NodeJs;
|
|
37
|
+
}
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getTarget(target?: string): ts.ScriptTarget {
|
|
42
|
+
switch (target?.toLowerCase()) {
|
|
43
|
+
case "es2015":
|
|
44
|
+
return ts.ScriptTarget.ES2015;
|
|
45
|
+
case "es2016":
|
|
46
|
+
return ts.ScriptTarget.ES2016;
|
|
47
|
+
case "es2017":
|
|
48
|
+
return ts.ScriptTarget.ES2017;
|
|
49
|
+
case "es2018":
|
|
50
|
+
return ts.ScriptTarget.ES2018;
|
|
51
|
+
case "es2019":
|
|
52
|
+
return ts.ScriptTarget.ES2019;
|
|
53
|
+
case "es2020":
|
|
54
|
+
return ts.ScriptTarget.ES2020;
|
|
55
|
+
case "es2021":
|
|
56
|
+
return ts.ScriptTarget.ES2021;
|
|
57
|
+
case "es3":
|
|
58
|
+
return ts.ScriptTarget.ES3;
|
|
59
|
+
case "es5":
|
|
60
|
+
return ts.ScriptTarget.ES5;
|
|
61
|
+
case "esnext":
|
|
62
|
+
return ts.ScriptTarget.ESNext;
|
|
63
|
+
default:
|
|
64
|
+
return ts.ScriptTarget.ESNext;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getTargetFromCurrentDir(): ts.ScriptTarget {
|
|
69
|
+
const options = readCompilerOptions(".");
|
|
70
|
+
return getTarget(options.target?.toString());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function createSourceFile(target: ts.ScriptTarget, file: string) {
|
|
74
|
+
let contents = fs.readFileSync(file).toString();
|
|
75
|
+
|
|
76
|
+
// go through the file and print everything back if not starting immediately after other position
|
|
77
|
+
const sourceFile = ts.createSourceFile(
|
|
78
|
+
file,
|
|
79
|
+
contents,
|
|
80
|
+
target,
|
|
81
|
+
false,
|
|
82
|
+
ts.ScriptKind.TS,
|
|
83
|
+
);
|
|
84
|
+
return { contents, sourceFile };
|
|
85
|
+
}
|