@snowtop/ent 0.1.0-alpha112 → 0.1.0-alpha113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +2 -1
- package/parse_schema/parse.js +22 -0
- package/schema/json_field.d.ts +2 -2
- package/schema/schema.d.ts +13 -2
- package/scripts/custom_graphql.js +2 -1
- package/tsc/ast.js +2 -1
- package/tsc/transform_ent.js +2 -1
- package/tsc/transform_schema.js +4 -3
package/core/const.d.ts
ADDED
package/core/const.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCHEMA_PATH = exports.GRAPHQL_PATH = exports.PACKAGE = void 0;
|
|
4
|
+
exports.PACKAGE = "@snowtop/ent";
|
|
5
|
+
exports.GRAPHQL_PATH = "@snowtop/ent/graphql";
|
|
6
|
+
exports.SCHEMA_PATH = "@snowtop/ent/schema";
|
package/package.json
CHANGED
package/parse_schema/parse.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
2
|
-
import { ActionField, Type, GlobalSchema } from "../schema/schema";
|
|
2
|
+
import { ActionField, Type, GlobalSchema, TransformReadBetaResult } from "../schema/schema";
|
|
3
3
|
declare enum NullableResult {
|
|
4
4
|
CONTENTS = "contents",
|
|
5
5
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
@@ -15,6 +15,7 @@ type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActions"> &
|
|
|
15
15
|
interface TransformFlags {
|
|
16
16
|
transformsSelect?: boolean;
|
|
17
17
|
transformsDelete?: boolean;
|
|
18
|
+
transformsLoaderCodegen?: TransformReadBetaResult;
|
|
18
19
|
transformsInsert?: boolean;
|
|
19
20
|
transformsUpdate?: boolean;
|
|
20
21
|
}
|
package/parse_schema/parse.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSchema = void 0;
|
|
4
4
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
5
|
+
const const_1 = require("../core/const");
|
|
5
6
|
async function processFields(src, patternName) {
|
|
6
7
|
const ret = [];
|
|
7
8
|
let m = {};
|
|
@@ -158,6 +159,23 @@ async function processPattern(patterns, pattern, processedSchema) {
|
|
|
158
159
|
// flag transformsSelect
|
|
159
160
|
if (pattern.transformRead) {
|
|
160
161
|
ret.transformsSelect = true;
|
|
162
|
+
if (pattern.transformReadCodegen_BETA) {
|
|
163
|
+
const r = pattern.transformReadCodegen_BETA();
|
|
164
|
+
if (typeof r === "string") {
|
|
165
|
+
ret.transformsLoaderCodegen = {
|
|
166
|
+
code: r,
|
|
167
|
+
imports: [
|
|
168
|
+
{
|
|
169
|
+
importPath: const_1.PACKAGE,
|
|
170
|
+
import: "query",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
ret.transformsLoaderCodegen = r;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
161
179
|
}
|
|
162
180
|
if (patterns[name] === undefined) {
|
|
163
181
|
// intentionally processing separately and not passing pattern.name
|
|
@@ -258,6 +276,10 @@ async function parseSchema(potentialSchemas, globalSchema) {
|
|
|
258
276
|
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
259
277
|
}
|
|
260
278
|
processedSchema.transformsSelect = true;
|
|
279
|
+
if (ret.transformsLoaderCodegen) {
|
|
280
|
+
processedSchema.transformsLoaderCodegen =
|
|
281
|
+
ret.transformsLoaderCodegen;
|
|
282
|
+
}
|
|
261
283
|
}
|
|
262
284
|
if (ret.transformsDelete) {
|
|
263
285
|
if (processedSchema.transformsDelete) {
|
package/schema/json_field.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FieldOptions, Type, Field,
|
|
1
|
+
import { FieldOptions, Type, Field, DeprecatedImportType } from "./schema";
|
|
2
2
|
import { BaseField, ListField } from "./field";
|
|
3
3
|
export interface JSONOptions extends FieldOptions {
|
|
4
4
|
validator?: (val: any) => boolean;
|
|
5
|
-
importType?:
|
|
5
|
+
importType?: DeprecatedImportType;
|
|
6
6
|
}
|
|
7
7
|
interface allJSONOptions extends JSONOptions {
|
|
8
8
|
jsonAsList?: boolean;
|
package/schema/schema.d.ts
CHANGED
|
@@ -79,12 +79,23 @@ export interface AssocEdgeGroup {
|
|
|
79
79
|
edgeAction?: EdgeGroupAction;
|
|
80
80
|
}
|
|
81
81
|
export type Edge = AssocEdge;
|
|
82
|
+
interface ImportPath {
|
|
83
|
+
importPath: string;
|
|
84
|
+
import: string;
|
|
85
|
+
defaultImport?: boolean;
|
|
86
|
+
originalImport?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface TransformReadBetaResult {
|
|
89
|
+
code: string;
|
|
90
|
+
imports: ImportPath[];
|
|
91
|
+
}
|
|
82
92
|
export interface Pattern {
|
|
83
93
|
name: string;
|
|
84
94
|
fields: FieldMap;
|
|
85
95
|
disableMixin?: boolean;
|
|
86
96
|
edges?: Edge[];
|
|
87
97
|
transformRead?: () => Clause;
|
|
98
|
+
transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
|
|
88
99
|
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
89
100
|
transformsDelete?: boolean;
|
|
90
101
|
transformsInsert?: boolean;
|
|
@@ -135,7 +146,7 @@ export declare enum DBType {
|
|
|
135
146
|
Timetz = "Timetz",
|
|
136
147
|
List = "List"
|
|
137
148
|
}
|
|
138
|
-
export interface
|
|
149
|
+
export interface DeprecatedImportType {
|
|
139
150
|
path: string;
|
|
140
151
|
type: string;
|
|
141
152
|
[x: string]: any;
|
|
@@ -160,7 +171,7 @@ export interface Type {
|
|
|
160
171
|
intEnumMap?: IntEnumMap;
|
|
161
172
|
deprecatedIntEnumMap?: IntEnumMap;
|
|
162
173
|
disableUnknownType?: boolean;
|
|
163
|
-
importType?:
|
|
174
|
+
importType?: DeprecatedImportType;
|
|
164
175
|
subFields?: FieldMap;
|
|
165
176
|
unionFields?: FieldMap;
|
|
166
177
|
[x: string]: any;
|
|
@@ -37,10 +37,11 @@ const readline = __importStar(require("readline"));
|
|
|
37
37
|
const imports_1 = require("../imports");
|
|
38
38
|
const process_1 = require("process");
|
|
39
39
|
const child_process_1 = require("child_process");
|
|
40
|
+
const const_1 = require("../core/const");
|
|
40
41
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
41
42
|
// we're affecting the local paths as opposed to a different instance
|
|
42
43
|
// life is hard
|
|
43
|
-
const MODULE_PATH =
|
|
44
|
+
const MODULE_PATH = const_1.GRAPHQL_PATH;
|
|
44
45
|
async function readInputs() {
|
|
45
46
|
return await new Promise((resolve) => {
|
|
46
47
|
const rl = readline.createInterface({
|
package/tsc/ast.js
CHANGED
|
@@ -31,6 +31,7 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const js_yaml_1 = require("js-yaml");
|
|
33
33
|
const fs = __importStar(require("fs"));
|
|
34
|
+
const const_1 = require("../core/const");
|
|
34
35
|
function getPreText(fileContents, node, sourceFile) {
|
|
35
36
|
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
36
37
|
}
|
|
@@ -267,7 +268,7 @@ function getCustomInfo() {
|
|
|
267
268
|
catch (e) { }
|
|
268
269
|
return {
|
|
269
270
|
viewerInfo: {
|
|
270
|
-
path:
|
|
271
|
+
path: const_1.PACKAGE,
|
|
271
272
|
name: "Viewer",
|
|
272
273
|
},
|
|
273
274
|
relativeImports,
|
package/tsc/transform_ent.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TransformEnt = void 0;
|
|
7
|
+
const const_1 = require("../core/const");
|
|
7
8
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
9
|
const ast_1 = require("./ast");
|
|
9
10
|
function isPrivacyPolicy(mm) {
|
|
@@ -52,7 +53,7 @@ class TransformEnt {
|
|
|
52
53
|
return {
|
|
53
54
|
rawString: classInfo.wrapClassContents(klassContents),
|
|
54
55
|
traversed,
|
|
55
|
-
imports: new Map([[
|
|
56
|
+
imports: new Map([[const_1.PACKAGE, ["PrivacyPolicy"]]]),
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
}
|
package/tsc/transform_schema.js
CHANGED
|
@@ -31,6 +31,7 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
31
31
|
const fs = __importStar(require("fs"));
|
|
32
32
|
const path_1 = __importDefault(require("path"));
|
|
33
33
|
const ast_1 = require("../tsc/ast");
|
|
34
|
+
const const_1 = require("../core/const");
|
|
34
35
|
function traverseClass(fileContents, sourceFile, node, transformSchema) {
|
|
35
36
|
const ci = getTransformClassInfo(fileContents, sourceFile, node, transformSchema);
|
|
36
37
|
if (!ci) {
|
|
@@ -307,9 +308,9 @@ function parseFieldElement(element, sourceFile, fileContents, nested) {
|
|
|
307
308
|
// find which of these importPaths is being used and use that to replace
|
|
308
309
|
function findSchemaImportPath(sourceFile) {
|
|
309
310
|
const paths = {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
311
|
+
[const_1.PACKAGE]: true,
|
|
312
|
+
[const_1.SCHEMA_PATH]: true,
|
|
313
|
+
[`${const_1.SCHEMA_PATH}/`]: true,
|
|
313
314
|
};
|
|
314
315
|
// @ts-ignore
|
|
315
316
|
const importStatements = sourceFile.statements.filter((stmt) => typescript_1.default.isImportDeclaration(stmt));
|