@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test2
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/action/action.d.ts +25 -14
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +89 -28
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +34 -14
- package/action/index.d.ts +4 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +43 -12
- package/action/orchestrator.js +461 -101
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +56 -23
- package/core/base.js +7 -1
- package/core/clause.d.ts +103 -39
- package/core/clause.js +430 -66
- package/core/config.d.ts +13 -3
- package/core/config.js +10 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -3
- package/core/context.js +22 -3
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +21 -9
- package/core/ent.d.ts +99 -95
- package/core/ent.js +550 -602
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +5 -2
- package/core/loaders/assoc_count_loader.js +19 -3
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +23 -17
- package/core/loaders/index.d.ts +1 -2
- package/core/loaders/index.js +1 -5
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +4 -21
- package/core/loaders/object_loader.d.ts +30 -9
- package/core/loaders/object_loader.js +226 -79
- package/core/loaders/query_loader.d.ts +7 -13
- package/core/loaders/query_loader.js +60 -24
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +8 -3
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -16
- package/core/privacy.js +68 -51
- package/core/query/assoc_query.d.ts +3 -2
- package/core/query/assoc_query.js +10 -2
- package/core/query/custom_clause_query.d.ts +29 -0
- package/core/query/custom_clause_query.js +105 -0
- package/core/query/custom_query.d.ts +19 -2
- package/core/query/custom_query.js +111 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +18 -4
- package/core/query/query.js +135 -58
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +186 -55
- package/core/query/shared_test.d.ts +9 -2
- package/core/query/shared_test.js +529 -236
- package/core/query_impl.d.ts +8 -0
- package/core/query_impl.js +28 -0
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -1
- package/graphql/graphql.d.ts +108 -22
- package/graphql/graphql.js +183 -137
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -5
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/orderby_direction.d.ts +2 -0
- package/graphql/scalars/orderby_direction.js +15 -0
- package/imports/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/imports/index.d.ts +7 -2
- package/imports/index.js +20 -5
- package/index.d.ts +23 -5
- package/index.js +35 -10
- package/package.json +20 -19
- package/parse_schema/parse.d.ts +33 -9
- package/parse_schema/parse.js +182 -33
- package/schema/base_schema.d.ts +13 -3
- package/schema/base_schema.js +13 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +232 -72
- package/schema/index.d.ts +2 -2
- package/schema/index.js +7 -2
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +109 -20
- package/schema/schema.js +42 -53
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +117 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +12 -8
- package/scripts/custom_graphql.js +167 -64
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +22 -7
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +405 -0
- package/testutils/builder.d.ts +37 -41
- package/testutils/builder.js +66 -46
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
- package/testutils/db/{test_db.js → temp_db.js} +251 -48
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +52 -9
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +56 -26
- package/testutils/fake_comms.js +1 -1
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +7 -3
- package/testutils/fake_data/fake_contact.js +13 -7
- package/testutils/fake_data/fake_event.d.ts +4 -1
- package/testutils/fake_data/fake_event.js +7 -6
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +8 -5
- package/testutils/fake_data/fake_user.js +31 -19
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +48 -0
- package/testutils/fake_data/test_helpers.d.ts +14 -6
- package/testutils/fake_data/test_helpers.js +31 -15
- package/testutils/fake_data/user_query.d.ts +16 -6
- package/testutils/fake_data/user_query.js +72 -23
- package/testutils/fake_log.js +1 -1
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +15 -3
- package/tsc/ast.js +114 -23
- package/tsc/compilerOptions.js +5 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +182 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +60 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +146 -117
- package/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -141
- package/scripts/transform_actions.js +0 -266
- package/scripts/transform_code.d.ts +0 -1
- package/scripts/transform_code.js +0 -111
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_actions.d.ts → move_types.d.ts} +0 -0
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IndexLoaderFactory = void 0;
|
|
4
|
-
const query_loader_1 = require("./query_loader");
|
|
5
|
-
// we're keeping this for legacy reasons so as to not break existing callers
|
|
6
|
-
// and to decouple the change here but all callers can safely be changed here to use QueryLoaderFactory
|
|
7
|
-
// @deprecated use QueryLoaderFactory
|
|
8
|
-
class IndexLoaderFactory {
|
|
9
|
-
constructor(options, col, opts) {
|
|
10
|
-
this.factory = new query_loader_1.QueryLoaderFactory({
|
|
11
|
-
fields: options.fields,
|
|
12
|
-
tableName: options.tableName,
|
|
13
|
-
groupCol: col,
|
|
14
|
-
clause: opts?.extraClause,
|
|
15
|
-
sortColumn: opts?.sortColumn,
|
|
16
|
-
toPrime: opts?.toPrime,
|
|
17
|
-
});
|
|
18
|
-
this.name = `indexLoader:${options.tableName}:${col}`;
|
|
19
|
-
}
|
|
20
|
-
createLoader(context) {
|
|
21
|
-
return this.factory.createLoader(context);
|
|
22
|
-
}
|
|
23
|
-
createConfigurableLoader(options, context) {
|
|
24
|
-
return this.factory.createConfigurableLoader(options, context);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.IndexLoaderFactory = IndexLoaderFactory;
|
package/graphql/enums.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { GraphQLEnumValue } from "graphql";
|
|
2
|
-
export declare function convertToGQLEnum(val: string | null, tsValues: string[], gqlValues: GraphQLEnumValue[]): any;
|
|
3
|
-
export declare function convertFromGQLEnum(val: string, tsValues: string[], gqlValues: GraphQLEnumValue[]): string;
|
package/graphql/enums.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFromGQLEnum = exports.convertToGQLEnum = void 0;
|
|
4
|
-
function convertToGQLEnum(val, tsValues, gqlValues) {
|
|
5
|
-
for (let i = 0; i < tsValues.length; i++) {
|
|
6
|
-
let tsVal = tsValues[i];
|
|
7
|
-
let gqlValue = gqlValues[i];
|
|
8
|
-
if (val === tsVal) {
|
|
9
|
-
return gqlValue.value;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return val;
|
|
13
|
-
}
|
|
14
|
-
exports.convertToGQLEnum = convertToGQLEnum;
|
|
15
|
-
function convertFromGQLEnum(val, tsValues, gqlValues) {
|
|
16
|
-
for (let i = 0; i < tsValues.length; i++) {
|
|
17
|
-
let tsVal = tsValues[i];
|
|
18
|
-
let gqlValue = gqlValues[i];
|
|
19
|
-
if (val === gqlValue.value) {
|
|
20
|
-
return tsVal;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return val;
|
|
24
|
-
}
|
|
25
|
-
exports.convertFromGQLEnum = convertFromGQLEnum;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const glob_1 = require("glob");
|
|
26
|
-
const path = __importStar(require("path"));
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
29
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
30
|
-
const ast_1 = require("../tsc/ast");
|
|
31
|
-
const child_process_1 = require("child_process");
|
|
32
|
-
// src/ent/generated and src/graphql/generated
|
|
33
|
-
function transformPath(old) {
|
|
34
|
-
const parts = old.split(path.sep);
|
|
35
|
-
if (parts.length < 3) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const changedParts = parts
|
|
39
|
-
.slice(0, 2)
|
|
40
|
-
.concat("generated")
|
|
41
|
-
.concat(parts.slice(2).filter((v) => v !== "generated"));
|
|
42
|
-
const newFile = changedParts.join(path.sep);
|
|
43
|
-
return { changedParts, newFile };
|
|
44
|
-
}
|
|
45
|
-
function moveFiles(files) {
|
|
46
|
-
files.forEach((file) => {
|
|
47
|
-
const conv = transformPath(file);
|
|
48
|
-
if (!conv) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const { changedParts, newFile } = conv;
|
|
52
|
-
if (file === newFile) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// check if directory exists, if not, create recursive dir
|
|
56
|
-
const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
|
|
57
|
-
const statInfo = fs.statSync(p, { throwIfNoEntry: false });
|
|
58
|
-
if (!statInfo) {
|
|
59
|
-
fs.mkdirSync(p, {
|
|
60
|
-
recursive: true,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
// move file to new location
|
|
64
|
-
fs.renameSync(file, newFile);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function updateImports(files, target, cwd) {
|
|
68
|
-
files.forEach((file) => {
|
|
69
|
-
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
70
|
-
let nodes = [];
|
|
71
|
-
let updated = false;
|
|
72
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
73
|
-
let dirPath = path.join(cwd, file, "..");
|
|
74
|
-
if (typescript_1.default.isImportDeclaration(node)) {
|
|
75
|
-
const conv = isGeneratedPath(node, sourceFile, dirPath);
|
|
76
|
-
if (!conv) {
|
|
77
|
-
nodes.push({ node });
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
updated = true;
|
|
81
|
-
const newImportPath = path.relative(dirPath, conv.newFile);
|
|
82
|
-
const v = (0, ast_1.updateImportPath)(contents, node, sourceFile, newImportPath);
|
|
83
|
-
nodes.push({ rawString: v });
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
nodes.push({ node });
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
let newContents = "";
|
|
90
|
-
for (const node of nodes) {
|
|
91
|
-
if (node.node) {
|
|
92
|
-
newContents += node.node.getFullText(sourceFile);
|
|
93
|
-
}
|
|
94
|
-
else if (node.rawString) {
|
|
95
|
-
newContents += node.rawString;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
throw new Error(`malformed node with no node or rawString`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (updated) {
|
|
102
|
-
fs.writeFileSync(file, newContents);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function main() {
|
|
107
|
-
const entFiles = glob_1.glob.sync("src/ent/**/generated/**/**.ts");
|
|
108
|
-
const graphqlFiles = glob_1.glob.sync("src/graphql/**/generated/**/**.ts");
|
|
109
|
-
moveFiles(entFiles);
|
|
110
|
-
moveFiles(graphqlFiles);
|
|
111
|
-
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
112
|
-
const entImportFiles = glob_1.glob.sync("src/ent/**/*.ts", {
|
|
113
|
-
ignore: ["**/generated/**", "node_modules/**"],
|
|
114
|
-
});
|
|
115
|
-
const graphqlImportFiles = glob_1.glob.sync("src/graphql/**/*.ts", {
|
|
116
|
-
ignore: ["**/generated/**", "node_modules/**"],
|
|
117
|
-
});
|
|
118
|
-
const cwd = process.cwd();
|
|
119
|
-
updateImports(entImportFiles, target, cwd);
|
|
120
|
-
updateImports(graphqlImportFiles, target, cwd);
|
|
121
|
-
(0, child_process_1.execSync)("prettier src/ent/*.ts --write");
|
|
122
|
-
(0, child_process_1.execSync)("prettier src/graphql/*.ts --write");
|
|
123
|
-
}
|
|
124
|
-
function isGeneratedPath(node, sourceFile, dirPath) {
|
|
125
|
-
// it's relative and has generated in there, continue
|
|
126
|
-
if (!(0, ast_1.isRelativeGeneratedImport)(node, sourceFile)) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
130
|
-
const oldPath = path.join(dirPath, text);
|
|
131
|
-
const relFromRoot = path.relative(".", oldPath);
|
|
132
|
-
const conv = transformPath(relFromRoot);
|
|
133
|
-
if (!conv) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (relFromRoot === conv.newFile) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
return conv;
|
|
140
|
-
}
|
|
141
|
-
main();
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const glob_1 = require("glob");
|
|
26
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
27
|
-
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
28
|
-
const ast_1 = require("../tsc/ast");
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
|
-
const action_1 = require("../action");
|
|
32
|
-
const viewer_1 = require("../core/viewer");
|
|
33
|
-
const path = __importStar(require("path"));
|
|
34
|
-
const js_yaml_1 = require("js-yaml");
|
|
35
|
-
function transformRelative(file, importPath, relative) {
|
|
36
|
-
if (!relative || !importPath.startsWith("src")) {
|
|
37
|
-
return importPath;
|
|
38
|
-
}
|
|
39
|
-
const fileFullPath = path.join(process.cwd(), file);
|
|
40
|
-
const impFullPath = path.join(process.cwd(), importPath);
|
|
41
|
-
// relative path is from directory
|
|
42
|
-
return normalizePath(path.relative(path.dirname(fileFullPath), impFullPath));
|
|
43
|
-
}
|
|
44
|
-
function normalizePath(p) {
|
|
45
|
-
if (p.endsWith("..")) {
|
|
46
|
-
return p + "/";
|
|
47
|
-
}
|
|
48
|
-
return p;
|
|
49
|
-
}
|
|
50
|
-
function findInput(file, sourceFile) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|
|
53
|
-
for (const imp of importStatements) {
|
|
54
|
-
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
55
|
-
if ((0, ast_1.isRelativeGeneratedImport)(imp, sourceFile)) {
|
|
56
|
-
// base file and we're importing from it
|
|
57
|
-
// e.g. in create_user_action, we're importing from create_user_action_base
|
|
58
|
-
if (path.basename(file).slice(0, -3) + "_base" !== path.basename(text)) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
|
|
62
|
-
if (!impInfo) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const inputs = impInfo.imports
|
|
66
|
-
.filter((imp) => imp.trim() && imp.endsWith("Input"))
|
|
67
|
-
.map((v) => v.trim());
|
|
68
|
-
if (inputs.length === 1) {
|
|
69
|
-
return inputs[0];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
function getCustomInfo() {
|
|
76
|
-
let yaml = {};
|
|
77
|
-
let relativeImports = false;
|
|
78
|
-
try {
|
|
79
|
-
yaml = (0, js_yaml_1.load)(fs.readFileSync(path.join(process.cwd(), "ent.yml"), {
|
|
80
|
-
encoding: "utf8",
|
|
81
|
-
}));
|
|
82
|
-
relativeImports = yaml?.codegen?.relativeImports || false;
|
|
83
|
-
if (yaml?.codegen?.templatizedViewer) {
|
|
84
|
-
return {
|
|
85
|
-
viewerInfo: yaml.codegen.templatizedViewer,
|
|
86
|
-
relativeImports,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (e) { }
|
|
91
|
-
return {
|
|
92
|
-
viewerInfo: {
|
|
93
|
-
path: "@snowtop/ent",
|
|
94
|
-
name: "Viewer",
|
|
95
|
-
},
|
|
96
|
-
relativeImports,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
async function main() {
|
|
100
|
-
let files = glob_1.glob.sync("src/ent/**/actions/**/*_action.ts");
|
|
101
|
-
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
102
|
-
const customInfo = getCustomInfo();
|
|
103
|
-
const viewerInfo = customInfo.viewerInfo;
|
|
104
|
-
files.forEach((file) => {
|
|
105
|
-
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
106
|
-
let traversed = false;
|
|
107
|
-
let nodes = [];
|
|
108
|
-
// require action
|
|
109
|
-
const p = require(path.join(process.cwd(), "./" + file.slice(0, -3)));
|
|
110
|
-
const action = new p.default(new viewer_1.LoggedOutViewer(), {});
|
|
111
|
-
const builder = action.builder.constructor.name;
|
|
112
|
-
const nodeName = action.builder.ent.name;
|
|
113
|
-
const existingEnt = action.builder.operation === action_1.WriteOperation.Insert
|
|
114
|
-
? `${nodeName} | null`
|
|
115
|
-
: nodeName;
|
|
116
|
-
const viewer = customInfo.viewerInfo.name;
|
|
117
|
-
const input = findInput(file, sourceFile);
|
|
118
|
-
if (!input) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
let newImports = [];
|
|
122
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
123
|
-
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
124
|
-
nodes.push({ node });
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
128
|
-
// only do classes
|
|
129
|
-
if (!classInfo) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
let klassContents = "";
|
|
133
|
-
for (const mm of node.members) {
|
|
134
|
-
const conv = getConversionInfo(mm);
|
|
135
|
-
if (conv !== null) {
|
|
136
|
-
const property = mm;
|
|
137
|
-
// if invalid, bounce
|
|
138
|
-
if (!property.initializer) {
|
|
139
|
-
traversed = false;
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
traversed = true;
|
|
143
|
-
const pp = property.initializer.getFullText(sourceFile).trim();
|
|
144
|
-
const code = `${conv.method}(): ${conv.interface}<${nodeName}, ${builder}<${input}, ${existingEnt}>, ${viewer}, ${input}, ${existingEnt}>[] {
|
|
145
|
-
return ${pp}
|
|
146
|
-
}`;
|
|
147
|
-
newImports.push(conv.interface);
|
|
148
|
-
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
klassContents += mm.getFullText(sourceFile);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// wrap comments and transform to export class Foo extends Bar { ${inner} }
|
|
155
|
-
nodes.push({ rawString: classInfo.wrapClassContents(klassContents) });
|
|
156
|
-
});
|
|
157
|
-
// if traversed, overwrite.
|
|
158
|
-
if (!traversed) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
let newContents = "";
|
|
162
|
-
let afterProcessed = false;
|
|
163
|
-
let imports = new Map([
|
|
164
|
-
[
|
|
165
|
-
transformRelative(file, viewerInfo.path, customInfo.relativeImports),
|
|
166
|
-
[viewer],
|
|
167
|
-
],
|
|
168
|
-
[
|
|
169
|
-
transformRelative(file, "src/ent", customInfo.relativeImports),
|
|
170
|
-
[nodeName],
|
|
171
|
-
],
|
|
172
|
-
["@snowtop/ent/action", newImports],
|
|
173
|
-
]);
|
|
174
|
-
let seen = new Map();
|
|
175
|
-
const processAfterImport = () => {
|
|
176
|
-
// do this for the first non-import node we see
|
|
177
|
-
// we want to add new imports to end of imports and there's an assumption that imports are ordered
|
|
178
|
-
// at top of file
|
|
179
|
-
if (!afterProcessed) {
|
|
180
|
-
for (const [imp, list] of imports) {
|
|
181
|
-
if (seen.has(imp)) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
newContents += `\nimport { ${list.join(", ")} } from "${imp}"`;
|
|
185
|
-
}
|
|
186
|
-
afterProcessed = true;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
for (const node of nodes) {
|
|
190
|
-
if (node.node) {
|
|
191
|
-
if (typescript_1.default.isImportDeclaration(node.node)) {
|
|
192
|
-
const impInfo = (0, ast_1.getImportInfo)(node.node, sourceFile);
|
|
193
|
-
if (impInfo) {
|
|
194
|
-
const impPath = normalizePath(impInfo.importPath);
|
|
195
|
-
// normalize paths...
|
|
196
|
-
const list = imports.get(impPath);
|
|
197
|
-
if (list) {
|
|
198
|
-
let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
|
|
199
|
-
newImports: list,
|
|
200
|
-
// don't use normalized path here, we wanna use the path that's in code...
|
|
201
|
-
transformPath: impInfo.importPath,
|
|
202
|
-
});
|
|
203
|
-
if (transformed) {
|
|
204
|
-
newContents += transformed;
|
|
205
|
-
seen.set(impPath, true);
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
if (!typescript_1.default.isExportDeclaration(node.node)) {
|
|
213
|
-
processAfterImport();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
newContents += node.node.getFullText(sourceFile);
|
|
217
|
-
}
|
|
218
|
-
else if (node.rawString) {
|
|
219
|
-
processAfterImport();
|
|
220
|
-
newContents += node.rawString;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
throw new Error(`malformed node with no node or rawString`);
|
|
224
|
-
}
|
|
225
|
-
fs.writeFileSync(file, newContents);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
(0, child_process_1.execSync)("prettier src/ent/**/actions/**/*.ts --write");
|
|
229
|
-
}
|
|
230
|
-
let m = {
|
|
231
|
-
triggers: {
|
|
232
|
-
m: "getTriggers",
|
|
233
|
-
i: "Trigger",
|
|
234
|
-
},
|
|
235
|
-
observers: {
|
|
236
|
-
m: "getObservers",
|
|
237
|
-
i: "Observer",
|
|
238
|
-
},
|
|
239
|
-
validators: {
|
|
240
|
-
m: "getValidators",
|
|
241
|
-
i: "Validator",
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
function getConversionInfo(mm) {
|
|
245
|
-
if (mm.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
const text = mm.name.escapedText;
|
|
249
|
-
const v = m[text];
|
|
250
|
-
if (v === undefined) {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
text,
|
|
255
|
-
method: v.m,
|
|
256
|
-
interface: v.i,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
main()
|
|
260
|
-
.then(() => {
|
|
261
|
-
process.exit(0);
|
|
262
|
-
})
|
|
263
|
-
.catch((err) => {
|
|
264
|
-
console.error(err);
|
|
265
|
-
process.exit(1);
|
|
266
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const glob_1 = require("glob");
|
|
26
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
27
|
-
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
28
|
-
const ast_1 = require("../tsc/ast");
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
|
-
async function main() {
|
|
32
|
-
let files = glob_1.glob.sync("src/ent/*.ts");
|
|
33
|
-
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
34
|
-
files.forEach((file) => {
|
|
35
|
-
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
36
|
-
let traversed = false;
|
|
37
|
-
let nodes = [];
|
|
38
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
39
|
-
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
40
|
-
nodes.push({ node });
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
44
|
-
// only do classes which extend a base class e.g. User extends UserBase
|
|
45
|
-
if (!classInfo || classInfo.extends !== classInfo.name + "Base") {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
traversed = true;
|
|
49
|
-
let klassContents = "";
|
|
50
|
-
for (const mm of node.members) {
|
|
51
|
-
if (isPrivacyPolicy(mm)) {
|
|
52
|
-
const property = mm;
|
|
53
|
-
// if invalid privacy policy, bounce
|
|
54
|
-
if (!property.initializer) {
|
|
55
|
-
traversed = false;
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const pp = property.initializer.getFullText(sourceFile);
|
|
59
|
-
const code = `getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
60
|
-
return ${pp}
|
|
61
|
-
}`;
|
|
62
|
-
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
klassContents += mm.getFullText(sourceFile);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// wrap comments and transform to export class Foo extends Bar { ${inner} }
|
|
69
|
-
nodes.push({ rawString: classInfo.wrapClassContents(klassContents) });
|
|
70
|
-
});
|
|
71
|
-
// if traversed, overwrite.
|
|
72
|
-
if (!traversed) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
let newContents = "";
|
|
76
|
-
for (const node of nodes) {
|
|
77
|
-
if (node.node) {
|
|
78
|
-
if (typescript_1.default.isImportDeclaration(node.node)) {
|
|
79
|
-
let transformed = (0, ast_1.transformImport)(contents, node.node, sourceFile, {
|
|
80
|
-
newImports: ["PrivacyPolicy"],
|
|
81
|
-
});
|
|
82
|
-
if (transformed) {
|
|
83
|
-
newContents += transformed;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
newContents += node.node.getFullText(sourceFile);
|
|
88
|
-
}
|
|
89
|
-
else if (node.rawString) {
|
|
90
|
-
newContents += node.rawString;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
throw new Error(`malformed node with no node or rawString`);
|
|
94
|
-
}
|
|
95
|
-
fs.writeFileSync(file, newContents);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
(0, child_process_1.execSync)("prettier src/ent/*.ts --write");
|
|
99
|
-
}
|
|
100
|
-
function isPrivacyPolicy(mm) {
|
|
101
|
-
return (mm.kind === typescript_1.default.SyntaxKind.PropertyDeclaration &&
|
|
102
|
-
mm.name.escapedText === "privacyPolicy");
|
|
103
|
-
}
|
|
104
|
-
main()
|
|
105
|
-
.then(() => {
|
|
106
|
-
process.exit(0);
|
|
107
|
-
})
|
|
108
|
-
.catch((err) => {
|
|
109
|
-
console.error(err);
|
|
110
|
-
process.exit(1);
|
|
111
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|