@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
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.TransformAction = void 0;
|
|
30
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
31
|
+
const ast_1 = require("../tsc/ast");
|
|
32
|
+
const viewer_1 = require("../core/viewer");
|
|
33
|
+
const path = __importStar(require("path"));
|
|
34
|
+
const snake_case_1 = require("snake-case");
|
|
35
|
+
// returns input and importPath
|
|
36
|
+
function getBaseFileInfo(file, classInfo, sourceFile) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|
|
39
|
+
for (const imp of importStatements) {
|
|
40
|
+
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
41
|
+
if ((0, ast_1.isSrcGeneratedImport)(imp, sourceFile) ||
|
|
42
|
+
(0, ast_1.isRelativeGeneratedImport)(imp, sourceFile)) {
|
|
43
|
+
// base file and we're importing from it
|
|
44
|
+
// e.g. in create_user_action, we're importing from create_user_action_base
|
|
45
|
+
if (path.basename(file).slice(0, -3) + "_base" !== path.basename(text)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
|
|
49
|
+
if (!impInfo) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
let inputs = impInfo.imports
|
|
53
|
+
.filter((imp) => imp.trim() && imp.endsWith("Input"))
|
|
54
|
+
.map((v) => v.trim());
|
|
55
|
+
if (inputs.length === 1) {
|
|
56
|
+
return {
|
|
57
|
+
input: inputs[0],
|
|
58
|
+
importPath: impInfo.importPath,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (inputs.length && classInfo.name.endsWith("Action")) {
|
|
62
|
+
const prefix = classInfo.name.slice(0, classInfo.name.length - 6);
|
|
63
|
+
inputs = inputs.filter((imp) => imp.slice(0, imp.length - 5) === prefix);
|
|
64
|
+
if (inputs.length === 1) {
|
|
65
|
+
return {
|
|
66
|
+
input: inputs[0],
|
|
67
|
+
importPath: impInfo.importPath,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
let m = {
|
|
76
|
+
triggers: {
|
|
77
|
+
m: "getTriggers",
|
|
78
|
+
i: "Trigger",
|
|
79
|
+
suffix: "Triggers",
|
|
80
|
+
},
|
|
81
|
+
observers: {
|
|
82
|
+
m: "getObservers",
|
|
83
|
+
i: "Observer",
|
|
84
|
+
suffix: "Observers",
|
|
85
|
+
},
|
|
86
|
+
validators: {
|
|
87
|
+
m: "getValidators",
|
|
88
|
+
i: "Validator",
|
|
89
|
+
suffix: "Validators",
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
function getConversionInfo(mm, actionName) {
|
|
93
|
+
if (mm.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const text = mm.name.escapedText;
|
|
97
|
+
const v = m[text];
|
|
98
|
+
if (v === undefined) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
text,
|
|
103
|
+
method: v.m,
|
|
104
|
+
interface: v.i,
|
|
105
|
+
// CreateFooActionTriggers etc
|
|
106
|
+
methodType: actionName + v.suffix,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
class TransformAction {
|
|
110
|
+
constructor(customInfo) {
|
|
111
|
+
this.customInfo = customInfo;
|
|
112
|
+
this.glob = "src/ent/**/actions/**/*_action.ts";
|
|
113
|
+
this.prettierGlob = "src/ent/**/actions/**.ts";
|
|
114
|
+
}
|
|
115
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
116
|
+
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
117
|
+
return { node };
|
|
118
|
+
}
|
|
119
|
+
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
120
|
+
// only do classes
|
|
121
|
+
if (!classInfo || !classInfo.default) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// require action
|
|
125
|
+
const p = require(path.join(process.cwd(), "./" + file.slice(0, -3)));
|
|
126
|
+
const action = new p.default(new viewer_1.LoggedOutViewer(), {});
|
|
127
|
+
const actionName = action.constructor.name;
|
|
128
|
+
const builder = action.builder.constructor.name;
|
|
129
|
+
const nodeName = action.builder.ent.name;
|
|
130
|
+
const viewer = this.customInfo.viewerInfo.name;
|
|
131
|
+
const baseInfo = getBaseFileInfo(file, classInfo, sourceFile);
|
|
132
|
+
if (!baseInfo) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let klassContents = "";
|
|
136
|
+
let traversed = false;
|
|
137
|
+
let newImports = [];
|
|
138
|
+
for (const mm of node.members) {
|
|
139
|
+
const conv = getConversionInfo(mm, actionName);
|
|
140
|
+
if (conv !== null) {
|
|
141
|
+
const property = mm;
|
|
142
|
+
// if invalid, bounce
|
|
143
|
+
if (!property.initializer) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
traversed = true;
|
|
147
|
+
const pp = property.initializer.getFullText(sourceFile).trim();
|
|
148
|
+
const code = `${conv.method}(): ${conv.methodType} {
|
|
149
|
+
return ${pp}
|
|
150
|
+
}`;
|
|
151
|
+
newImports.push(conv.methodType);
|
|
152
|
+
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
klassContents += mm.getFullText(sourceFile);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const builderPath = `src/ent/generated/${(0, snake_case_1.snakeCase)(nodeName)}/actions/${(0, snake_case_1.snakeCase)(builder)}`;
|
|
159
|
+
let imports = new Map([
|
|
160
|
+
[
|
|
161
|
+
(0, ast_1.transformRelative)(file, this.customInfo.viewerInfo.path, this.customInfo.relativeImports),
|
|
162
|
+
[viewer],
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
(0, ast_1.transformRelative)(file, baseInfo.importPath, this.customInfo.relativeImports),
|
|
166
|
+
newImports,
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
(0, ast_1.transformRelative)(file, builderPath, this.customInfo.relativeImports),
|
|
170
|
+
[builder],
|
|
171
|
+
],
|
|
172
|
+
]);
|
|
173
|
+
// wrap comments and transform to export class Foo extends Bar { ${inner} }
|
|
174
|
+
return {
|
|
175
|
+
rawString: classInfo.wrapClassContents(klassContents),
|
|
176
|
+
traversed,
|
|
177
|
+
imports,
|
|
178
|
+
removeImports: ["Trigger", "Observer", "Validator"],
|
|
179
|
+
// not removing FooBuilder incase it's still somehow used in type of inline builders
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.TransformAction = TransformAction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformFile } from "./transform";
|
|
3
|
+
export declare class TransformEnt implements TransformFile {
|
|
4
|
+
glob: string;
|
|
5
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
6
|
+
node: ts.Node;
|
|
7
|
+
rawString?: undefined;
|
|
8
|
+
traversed?: undefined;
|
|
9
|
+
imports?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
rawString: string;
|
|
12
|
+
traversed: boolean;
|
|
13
|
+
imports: Map<string, string[]>;
|
|
14
|
+
node?: undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
prettierGlob: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TransformEnt = void 0;
|
|
7
|
+
const const_1 = require("../core/const");
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
const ast_1 = require("./ast");
|
|
10
|
+
function isPrivacyPolicy(mm) {
|
|
11
|
+
return (mm.kind === typescript_1.default.SyntaxKind.PropertyDeclaration &&
|
|
12
|
+
mm.name.escapedText === "privacyPolicy");
|
|
13
|
+
}
|
|
14
|
+
class TransformEnt {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.glob = "src/ent/*.ts";
|
|
17
|
+
this.prettierGlob = "src/ent/*.ts";
|
|
18
|
+
}
|
|
19
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
20
|
+
if (!typescript_1.default.isClassDeclaration(node) || !node.heritageClauses) {
|
|
21
|
+
return { node };
|
|
22
|
+
}
|
|
23
|
+
let classInfo = (0, ast_1.getClassInfo)(contents, sourceFile, node);
|
|
24
|
+
if (!classInfo) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// different class. ignore
|
|
28
|
+
// only do classes which extend a base class e.g. User extends UserBase
|
|
29
|
+
// if different class (e.g. privacy rule), just return it
|
|
30
|
+
if (classInfo.extends !== classInfo.name + "Base") {
|
|
31
|
+
return { node };
|
|
32
|
+
}
|
|
33
|
+
let klassContents = "";
|
|
34
|
+
let traversed = false;
|
|
35
|
+
for (const mm of node.members) {
|
|
36
|
+
if (isPrivacyPolicy(mm)) {
|
|
37
|
+
const property = mm;
|
|
38
|
+
// if invalid privacy policy, bounce
|
|
39
|
+
if (!property.initializer) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const pp = property.initializer.getFullText(sourceFile);
|
|
43
|
+
const code = `getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
44
|
+
return ${pp}
|
|
45
|
+
}`;
|
|
46
|
+
klassContents += (0, ast_1.getPreText)(contents, mm, sourceFile) + code;
|
|
47
|
+
traversed = true;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
klassContents += mm.getFullText(sourceFile);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
rawString: classInfo.wrapClassContents(klassContents),
|
|
55
|
+
traversed,
|
|
56
|
+
imports: new Map([[const_1.PACKAGE, ["PrivacyPolicy"]]]),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.TransformEnt = TransformEnt;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { TransformFile } from "./transform";
|
|
3
|
+
export declare class TransformSchema implements TransformFile {
|
|
4
|
+
private relativeImports;
|
|
5
|
+
private oldBaseClass?;
|
|
6
|
+
private newSchemaClass?;
|
|
7
|
+
private transformPath?;
|
|
8
|
+
constructor(relativeImports: boolean, oldBaseClass?: string | undefined, newSchemaClass?: string | undefined, transformPath?: string | undefined);
|
|
9
|
+
glob: string;
|
|
10
|
+
private transformSchema;
|
|
11
|
+
traverseChild(sourceFile: ts.SourceFile, contents: string, file: string, node: ts.Node): {
|
|
12
|
+
node: ts.Node;
|
|
13
|
+
traversed?: undefined;
|
|
14
|
+
rawString?: undefined;
|
|
15
|
+
removeImports?: undefined;
|
|
16
|
+
imports?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
traversed: boolean;
|
|
19
|
+
rawString: string;
|
|
20
|
+
removeImports: string[];
|
|
21
|
+
imports: Map<string, string[]>;
|
|
22
|
+
node?: undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
fileToWrite(file: string): string;
|
|
25
|
+
postProcess(file: string): void;
|
|
26
|
+
prettierGlob: string;
|
|
27
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,109 +26,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
|
|
29
|
+
exports.TransformSchema = void 0;
|
|
26
30
|
const typescript_1 = __importDefault(require("typescript"));
|
|
27
31
|
const fs = __importStar(require("fs"));
|
|
28
|
-
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
32
|
const path_1 = __importDefault(require("path"));
|
|
31
33
|
const ast_1 = require("../tsc/ast");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
// filter to only event.ts e.g. for comments and whitespace...
|
|
36
|
-
// files = files.filter((f) => f.endsWith("event.ts"));
|
|
37
|
-
files.forEach((file) => {
|
|
38
|
-
// assume valid file since we do glob above
|
|
39
|
-
// const idx = file.lastIndexOf(".ts");
|
|
40
|
-
// const writeFile = file.substring(0, idx) + "2" + ".ts";
|
|
41
|
-
// console.debug(file);
|
|
42
|
-
const writeFile = "src/schema/" + path_1.default.basename(file).slice(0, -3) + "_schema.ts";
|
|
43
|
-
// const writeFile = file;
|
|
44
|
-
// console.debug(file, writeFile);
|
|
45
|
-
// go through the file and print everything back if not starting immediately after other position
|
|
46
|
-
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
47
|
-
const nodes = [];
|
|
48
|
-
let updateImport = false;
|
|
49
|
-
let removeImports = [];
|
|
50
|
-
const f = {
|
|
51
|
-
trackNode: function (tni) {
|
|
52
|
-
nodes.push({
|
|
53
|
-
node: tni.node,
|
|
54
|
-
importNode: tni.node && typescript_1.default.isImportDeclaration(tni.node),
|
|
55
|
-
rawString: tni.rawString,
|
|
56
|
-
});
|
|
57
|
-
if (tni.removeImports) {
|
|
58
|
-
removeImports.push(...tni.removeImports);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
flagUpdateImport() {
|
|
62
|
-
updateImport = true;
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
if (!traverse(contents, sourceFile, f)) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
let newContents = "";
|
|
69
|
-
for (const node of nodes) {
|
|
70
|
-
if (updateImport && node.importNode) {
|
|
71
|
-
const importNode = node.node;
|
|
72
|
-
const transformedImport = (0, ast_1.transformImport)(contents, importNode, sourceFile, {
|
|
73
|
-
removeImports,
|
|
74
|
-
transform: transformSchema,
|
|
75
|
-
});
|
|
76
|
-
if (transformedImport) {
|
|
77
|
-
newContents += transformedImport;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (node.node) {
|
|
82
|
-
newContents += node.node.getFullText(sourceFile);
|
|
83
|
-
}
|
|
84
|
-
else if (node.rawString) {
|
|
85
|
-
newContents += node.rawString;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
console.error("invalid node");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// console.debug(newContents);
|
|
92
|
-
// ideally there's a flag that indicates if we write
|
|
93
|
-
fs.writeFileSync(writeFile, newContents);
|
|
94
|
-
fs.rmSync(file);
|
|
95
|
-
});
|
|
96
|
-
(0, child_process_1.execSync)("prettier src/schema/*.ts --write");
|
|
97
|
-
}
|
|
98
|
-
function traverse(fileContents, sourceFile, f) {
|
|
99
|
-
let traversed = false;
|
|
100
|
-
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
101
|
-
if (typescript_1.default.isClassDeclaration(node)) {
|
|
102
|
-
traversed = true;
|
|
103
|
-
// TODO address implicit schema doesn't work here...
|
|
104
|
-
// console.debug(sourceFile.fileName, node.kind);
|
|
105
|
-
if (traverseClass(fileContents, sourceFile, node, f)) {
|
|
106
|
-
f.flagUpdateImport();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
f.trackNode({ node });
|
|
111
|
-
});
|
|
112
|
-
return traversed;
|
|
113
|
-
}
|
|
114
|
-
function traverseClass(fileContents, sourceFile, node, f) {
|
|
115
|
-
const ci = getTransformClassInfo(fileContents, sourceFile, node);
|
|
34
|
+
const const_1 = require("../core/const");
|
|
35
|
+
function traverseClass(fileContents, sourceFile, node, transformSchema) {
|
|
36
|
+
const ci = getTransformClassInfo(fileContents, sourceFile, node, transformSchema);
|
|
116
37
|
if (!ci) {
|
|
117
|
-
return
|
|
38
|
+
return;
|
|
118
39
|
}
|
|
119
|
-
let klassContents = `${ci.comment}const ${ci.name} = new ${ci.class}({\n`;
|
|
40
|
+
let klassContents = `${ci.comment}const ${ci.name} = new ${transformSchema(ci.class)}({\n`;
|
|
120
41
|
let removeImports = [];
|
|
121
42
|
if (ci.implementsSchema) {
|
|
122
43
|
removeImports.push("Schema");
|
|
123
44
|
}
|
|
45
|
+
removeImports.push(ci.class);
|
|
46
|
+
let newImports = [transformSchema(ci.class)];
|
|
124
47
|
for (let member of node.members) {
|
|
125
48
|
const fInfo = getClassElementInfo(fileContents, member, sourceFile);
|
|
126
49
|
if (!fInfo) {
|
|
127
|
-
return
|
|
50
|
+
return;
|
|
128
51
|
}
|
|
129
52
|
klassContents += `${fInfo.comment}${fInfo.key}:${fInfo.value},\n`;
|
|
130
53
|
if (fInfo.type) {
|
|
@@ -139,20 +62,13 @@ function traverseClass(fileContents, sourceFile, node, f) {
|
|
|
139
62
|
klassContents = "export " + klassContents;
|
|
140
63
|
}
|
|
141
64
|
// console.debug(klassContents);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (str === "BaseEntSchema" || str === "BaseEntSchemaWithTZ") {
|
|
148
|
-
return str.substring(4);
|
|
149
|
-
}
|
|
150
|
-
return str;
|
|
65
|
+
return {
|
|
66
|
+
rawString: klassContents,
|
|
67
|
+
removeImports: removeImports,
|
|
68
|
+
newImports,
|
|
69
|
+
};
|
|
151
70
|
}
|
|
152
|
-
|
|
153
|
-
// and then have a schema specific version
|
|
154
|
-
// may make sense to just duplicate this logic...
|
|
155
|
-
function getTransformClassInfo(fileContents, sourceFile, node) {
|
|
71
|
+
function getTransformClassInfo(fileContents, sourceFile, node, transformSchema) {
|
|
156
72
|
const generic = (0, ast_1.getClassInfo)(fileContents, sourceFile, node);
|
|
157
73
|
if (!generic) {
|
|
158
74
|
return;
|
|
@@ -163,6 +79,7 @@ function getTransformClassInfo(fileContents, sourceFile, node) {
|
|
|
163
79
|
}
|
|
164
80
|
let implementsSchema = generic.implements?.some((v) => v == "Schema");
|
|
165
81
|
let classExtends = generic.extends;
|
|
82
|
+
// nothing transformed here, so nothing to do here
|
|
166
83
|
if (classExtends && classExtends === transformSchema(classExtends)) {
|
|
167
84
|
return undefined;
|
|
168
85
|
}
|
|
@@ -179,7 +96,7 @@ function getTransformClassInfo(fileContents, sourceFile, node) {
|
|
|
179
96
|
}
|
|
180
97
|
// intentionally doesn't parse decorators since we don't need it
|
|
181
98
|
function getClassElementInfo(fileContents, member, sourceFile) {
|
|
182
|
-
if (isFieldElement(member, sourceFile)) {
|
|
99
|
+
if (isFieldElement(fileContents, member, sourceFile)) {
|
|
183
100
|
return getFieldElementInfo(fileContents, member, sourceFile);
|
|
184
101
|
}
|
|
185
102
|
if (member.kind === typescript_1.default.SyntaxKind.Constructor) {
|
|
@@ -222,7 +139,7 @@ function getFieldElementInfo(fileContents, member, sourceFile) {
|
|
|
222
139
|
if (parsed === null) {
|
|
223
140
|
return;
|
|
224
141
|
}
|
|
225
|
-
const { callEx, name, nameComment, properties } = parsed;
|
|
142
|
+
const { callEx, name, nameComment, properties, suffix } = parsed;
|
|
226
143
|
let property = "";
|
|
227
144
|
const fieldComment = (0, ast_1.getPreText)(fileContents, element, sourceFile).trim();
|
|
228
145
|
if (fieldComment) {
|
|
@@ -237,7 +154,7 @@ function getFieldElementInfo(fileContents, member, sourceFile) {
|
|
|
237
154
|
if (properties.length) {
|
|
238
155
|
fnCall = `{${properties.join(",")}}`;
|
|
239
156
|
}
|
|
240
|
-
property += `${name}:${call}(${fnCall}),`;
|
|
157
|
+
property += `${name}:${call}(${fnCall})${suffix || ""},`;
|
|
241
158
|
fieldMap += property;
|
|
242
159
|
}
|
|
243
160
|
fieldMap += "}";
|
|
@@ -289,7 +206,7 @@ function getConstructorElementInfo(fileContents, member, sourceFile) {
|
|
|
289
206
|
comment: "",
|
|
290
207
|
};
|
|
291
208
|
}
|
|
292
|
-
function isFieldElement(member, sourceFile) {
|
|
209
|
+
function isFieldElement(fileContents, member, sourceFile) {
|
|
293
210
|
if (member.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
|
|
294
211
|
return false;
|
|
295
212
|
}
|
|
@@ -303,24 +220,60 @@ function isFieldElement(member, sourceFile) {
|
|
|
303
220
|
return false;
|
|
304
221
|
}
|
|
305
222
|
if (property.initializer?.kind !== typescript_1.default.SyntaxKind.ArrayLiteralExpression) {
|
|
306
|
-
|
|
223
|
+
throwErr(fileContents, member, "invalid array type");
|
|
307
224
|
return false;
|
|
308
225
|
}
|
|
309
226
|
return true;
|
|
310
227
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
228
|
+
// if there's an error transforming any of the schemas, we should stop...
|
|
229
|
+
function throwErr(fileContents, node, error) {
|
|
230
|
+
console.error(error);
|
|
231
|
+
throw new Error(`error transforming this field ${fileContents.substring(node.getFullStart(), node.getEnd())}`);
|
|
232
|
+
}
|
|
233
|
+
function parseFieldElement(element, sourceFile, fileContents, nested) {
|
|
234
|
+
if (element.kind !== typescript_1.default.SyntaxKind.CallExpression &&
|
|
235
|
+
element.kind !== typescript_1.default.SyntaxKind.PropertyAccessExpression) {
|
|
236
|
+
throwErr(fileContents, element, `skipped unknown (non-call|non-property) expression ${element.kind}`);
|
|
314
237
|
return null;
|
|
315
238
|
}
|
|
239
|
+
if (element.kind === typescript_1.default.SyntaxKind.PropertyAccessExpression) {
|
|
240
|
+
const ret = parseFieldElement(element.expression, sourceFile, fileContents, true);
|
|
241
|
+
if (ret !== null) {
|
|
242
|
+
if (!nested) {
|
|
243
|
+
ret.suffix = fileContents.substring(ret.callEx.getEnd(), element.getEnd());
|
|
244
|
+
}
|
|
245
|
+
return ret;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
316
248
|
let callEx = element;
|
|
317
249
|
if (callEx.arguments.length !== 1) {
|
|
318
|
-
|
|
319
|
-
|
|
250
|
+
// have a situation like: StringType({ name: "canonicalName" }).trim().toLowerCase(),
|
|
251
|
+
// need to keep calling this until we find what we want and then get the suffix we should just add to the end of the transformed code
|
|
252
|
+
if (callEx.expression.kind === typescript_1.default.SyntaxKind.PropertyAccessExpression) {
|
|
253
|
+
const ret = parseFieldElement(callEx.expression.expression, sourceFile, fileContents, true);
|
|
254
|
+
if (ret !== null) {
|
|
255
|
+
if (!nested) {
|
|
256
|
+
ret.suffix = fileContents.substring(ret.callEx.getEnd(), callEx.getEnd());
|
|
257
|
+
}
|
|
258
|
+
return ret;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
throwErr(fileContents, element, "callExpression with arguments not of length 1");
|
|
320
262
|
}
|
|
321
263
|
let arg = callEx.arguments[0];
|
|
322
264
|
if (arg.kind !== typescript_1.default.SyntaxKind.ObjectLiteralExpression) {
|
|
323
|
-
|
|
265
|
+
// this and the check above for PropertyAccessExpression are to handle things like
|
|
266
|
+
// FooType({
|
|
267
|
+
/// ...
|
|
268
|
+
// }).function(blah)
|
|
269
|
+
const ret = parseFieldElement(callEx.expression, sourceFile, fileContents, true);
|
|
270
|
+
if (ret !== null) {
|
|
271
|
+
if (!nested) {
|
|
272
|
+
ret.suffix = fileContents.substring(ret.callEx.getEnd(), callEx.getEnd());
|
|
273
|
+
}
|
|
274
|
+
return ret;
|
|
275
|
+
}
|
|
276
|
+
throwErr(fileContents, element, `not objectLiteralExpression. kind ${arg.kind}`);
|
|
324
277
|
return null;
|
|
325
278
|
}
|
|
326
279
|
let expr = arg;
|
|
@@ -340,7 +293,7 @@ function parseFieldElement(element, sourceFile, fileContents) {
|
|
|
340
293
|
}
|
|
341
294
|
}
|
|
342
295
|
if (!name) {
|
|
343
|
-
|
|
296
|
+
throwErr(fileContents, element, `couldn't find name property`);
|
|
344
297
|
return null;
|
|
345
298
|
}
|
|
346
299
|
// remove quotes
|
|
@@ -352,4 +305,80 @@ function parseFieldElement(element, sourceFile, fileContents) {
|
|
|
352
305
|
nameComment: propertyComment,
|
|
353
306
|
};
|
|
354
307
|
}
|
|
355
|
-
|
|
308
|
+
// find which of these importPaths is being used and use that to replace
|
|
309
|
+
function findSchemaImportPath(sourceFile) {
|
|
310
|
+
const paths = {
|
|
311
|
+
[const_1.PACKAGE]: true,
|
|
312
|
+
[const_1.SCHEMA_PATH]: true,
|
|
313
|
+
[`${const_1.SCHEMA_PATH}/`]: true,
|
|
314
|
+
};
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|
|
317
|
+
for (const imp of importStatements) {
|
|
318
|
+
const impInfo = (0, ast_1.getImportInfo)(imp, sourceFile);
|
|
319
|
+
if (!impInfo) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (paths[impInfo.importPath] !== undefined) {
|
|
323
|
+
return impInfo.importPath;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
class TransformSchema {
|
|
328
|
+
// we only end up doing this once because we change the schema representation
|
|
329
|
+
// so safe to run this multiple times
|
|
330
|
+
constructor(relativeImports, oldBaseClass, newSchemaClass, transformPath) {
|
|
331
|
+
this.relativeImports = relativeImports;
|
|
332
|
+
this.oldBaseClass = oldBaseClass;
|
|
333
|
+
this.newSchemaClass = newSchemaClass;
|
|
334
|
+
this.transformPath = transformPath;
|
|
335
|
+
this.glob = "src/schema/*.ts";
|
|
336
|
+
this.prettierGlob = "src/schema/*.ts";
|
|
337
|
+
}
|
|
338
|
+
transformSchema(className) {
|
|
339
|
+
if (className === "BaseEntSchema" || className === "BaseEntSchemaWithTZ") {
|
|
340
|
+
return className.substring(4);
|
|
341
|
+
}
|
|
342
|
+
if (className === this.oldBaseClass && this.newSchemaClass) {
|
|
343
|
+
return this.newSchemaClass;
|
|
344
|
+
}
|
|
345
|
+
return className;
|
|
346
|
+
}
|
|
347
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
348
|
+
if (!typescript_1.default.isClassDeclaration(node)) {
|
|
349
|
+
return { node };
|
|
350
|
+
}
|
|
351
|
+
// TODO address implicit schema doesn't work here...
|
|
352
|
+
const ret = traverseClass(contents, sourceFile, node, this.transformSchema.bind(this));
|
|
353
|
+
if (ret === undefined) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
let imports = new Map();
|
|
357
|
+
const imp = findSchemaImportPath(sourceFile);
|
|
358
|
+
if (imp) {
|
|
359
|
+
if (this.transformPath) {
|
|
360
|
+
imports.set(imp, []);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
imports.set(imp, ret.newImports);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (this.transformPath) {
|
|
367
|
+
// add new imports to this path
|
|
368
|
+
imports.set((0, ast_1.transformRelative)(file, this.transformPath, this.relativeImports), ret.newImports);
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
traversed: true,
|
|
372
|
+
rawString: ret.rawString,
|
|
373
|
+
removeImports: ret.removeImports,
|
|
374
|
+
imports: imports,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
fileToWrite(file) {
|
|
378
|
+
return "src/schema/" + path_1.default.basename(file).slice(0, -3) + "_schema.ts";
|
|
379
|
+
}
|
|
380
|
+
postProcess(file) {
|
|
381
|
+
fs.rmSync(file);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
exports.TransformSchema = TransformSchema;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ID, SelectBaseDataOptions, Context, Data, LoaderFactory, EdgeQueryableDataOptions } from "../base";
|
|
2
|
-
import * as clause from "../clause";
|
|
3
|
-
import { ObjectLoaderFactory } from "./object_loader";
|
|
4
|
-
export declare class IndexLoaderFactory implements LoaderFactory<ID, Data[]> {
|
|
5
|
-
name: string;
|
|
6
|
-
private factory;
|
|
7
|
-
constructor(options: SelectBaseDataOptions, col: string, opts?: {
|
|
8
|
-
extraClause?: clause.Clause;
|
|
9
|
-
sortColumn?: string;
|
|
10
|
-
toPrime?: ObjectLoaderFactory<ID>[];
|
|
11
|
-
});
|
|
12
|
-
createLoader(context?: Context): any;
|
|
13
|
-
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): import("../base").Loader<unknown, Data[]> | import("./query_loader").QueryDirectLoader<unknown>;
|
|
14
|
-
}
|