@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha151
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 +27 -16
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +90 -23
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +3 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +125 -0
- package/action/operations.js +684 -0
- package/action/orchestrator.d.ts +38 -12
- package/action/orchestrator.js +427 -102
- 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 +52 -21
- package/core/base.js +7 -1
- package/core/clause.d.ts +95 -40
- package/core/clause.js +395 -64
- package/core/config.d.ts +15 -1
- package/core/config.js +10 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +4 -2
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +18 -8
- package/core/ent.d.ts +68 -94
- package/core/ent.js +538 -587
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +1 -0
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/assoc_edge_loader.js +10 -13
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +3 -3
- package/core/loaders/loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +30 -9
- package/core/loaders/object_loader.js +225 -78
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +54 -13
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +7 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +7 -6
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +3 -2
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +27 -0
- package/core/query/custom_clause_query.js +88 -0
- package/core/query/custom_query.d.ts +17 -2
- package/core/query/custom_query.js +88 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +15 -3
- package/core/query/query.js +128 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +44 -54
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +532 -236
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -1
- package/graphql/graphql.d.ts +52 -19
- package/graphql/graphql.js +174 -136
- package/graphql/graphql_field_helpers.d.ts +7 -1
- package/graphql/graphql_field_helpers.js +21 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +3 -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 +18 -5
- package/index.js +30 -10
- package/package.json +18 -17
- package/parse_schema/parse.d.ts +31 -9
- package/parse_schema/parse.js +179 -32
- 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 +231 -71
- 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 +145 -34
- 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 +39 -43
- package/testutils/builder.js +75 -49
- 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} +244 -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 +16 -15
- 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 +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +29 -13
- package/testutils/fake_data/user_query.d.ts +11 -4
- package/testutils/fake_data/user_query.js +54 -22
- 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 +25 -2
- package/tsc/ast.js +141 -17
- 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/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -142
- package/scripts/transform_code.js +0 -113
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha151",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,26 +8,27 @@
|
|
|
8
8
|
"example": "examples"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@
|
|
11
|
+
"@swc-node/register": "^1.6.5",
|
|
12
|
+
"@types/node": "^20.2.5",
|
|
12
13
|
"camel-case": "^4.1.2",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"cosmiconfig": "^8.1.3",
|
|
15
|
+
"dataloader": "^2.2.2",
|
|
16
|
+
"glob": "^10.2.6",
|
|
17
|
+
"graph-data-structure": "^3.3.0",
|
|
16
18
|
"js-yaml": "^4.1.0",
|
|
17
|
-
"json5": "^2.
|
|
18
|
-
"luxon": "^
|
|
19
|
+
"json5": "^2.2.3",
|
|
20
|
+
"luxon": "^3.3.0",
|
|
19
21
|
"memoizee": "^0.4.15",
|
|
20
|
-
"minimist": "^1.2.
|
|
22
|
+
"minimist": "^1.2.8",
|
|
21
23
|
"pascal-case": "^3.1.2",
|
|
22
|
-
"pg": "^8.0
|
|
23
|
-
"prettier": "^2.
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"uuid": "^8.3.2"
|
|
24
|
+
"pg": "^8.11.0",
|
|
25
|
+
"prettier": "^2.8.8",
|
|
26
|
+
"snake-case": "^3.0.4",
|
|
27
|
+
"ts-node": "^10.9.1",
|
|
28
|
+
"tsconfig-paths": "^4.2.0",
|
|
29
|
+
"tslib": "^2.5.2",
|
|
30
|
+
"typescript": "^5.0.4",
|
|
31
|
+
"uuid": "^9.0.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"better-sqlite3": "^7.4.1",
|
package/parse_schema/parse.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
2
|
-
import { ActionField, Type } from "../schema/schema";
|
|
2
|
+
import { ActionField, Type, GlobalSchema, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
|
|
3
3
|
declare enum NullableResult {
|
|
4
4
|
CONTENTS = "contents",
|
|
5
5
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
6
6
|
ITEM = "true"
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type ProcessedActionField = Omit<ActionField, "nullable"> & {
|
|
9
9
|
nullable?: NullableResult;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActions"> & {
|
|
12
12
|
patternName?: string;
|
|
13
13
|
edgeActions?: OutputAction[];
|
|
14
14
|
};
|
|
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
|
}
|
|
21
|
-
|
|
22
|
+
type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
|
|
22
23
|
actions: OutputAction[];
|
|
23
24
|
assocEdges: ProcessedAssocEdge[];
|
|
24
25
|
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
|
@@ -26,11 +27,12 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
|
|
|
26
27
|
schemaPath?: string;
|
|
27
28
|
patternNames?: string[];
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
+
type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
30
31
|
edgeAction?: OutputAction;
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
+
type OutputAction = Omit<Action, "actionOnlyFields" | "canViewerDo"> & {
|
|
33
34
|
actionOnlyFields?: ProcessedActionField[];
|
|
35
|
+
canViewerDo?: CanViewerDo;
|
|
34
36
|
};
|
|
35
37
|
interface schemasDict {
|
|
36
38
|
[key: string]: ProcessedSchema;
|
|
@@ -41,19 +43,21 @@ interface ProcessedPattern {
|
|
|
41
43
|
fields: ProcessedField[];
|
|
42
44
|
disableMixin?: boolean;
|
|
43
45
|
}
|
|
44
|
-
|
|
46
|
+
type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
|
|
45
47
|
subFields?: ProcessedField[];
|
|
46
48
|
listElemType?: ProcessedType;
|
|
47
49
|
unionFields?: ProcessedField[];
|
|
48
50
|
};
|
|
49
|
-
|
|
51
|
+
type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
|
|
50
52
|
name: string;
|
|
51
53
|
hasDefaultValueOnCreate?: boolean;
|
|
52
54
|
hasDefaultValueOnEdit?: boolean;
|
|
53
55
|
patternName?: string;
|
|
54
56
|
hasFieldPrivacy?: boolean;
|
|
57
|
+
hasEditFieldPrivacy?: boolean;
|
|
55
58
|
derivedFields?: ProcessedField[];
|
|
56
59
|
type: ProcessedType;
|
|
60
|
+
serverDefault?: string;
|
|
57
61
|
};
|
|
58
62
|
interface patternsDict {
|
|
59
63
|
[key: string]: ProcessedPattern;
|
|
@@ -61,9 +65,27 @@ interface patternsDict {
|
|
|
61
65
|
interface Result {
|
|
62
66
|
schemas: schemasDict;
|
|
63
67
|
patterns: patternsDict;
|
|
68
|
+
globalSchema?: ProcessedGlobalSchema;
|
|
69
|
+
config?: {
|
|
70
|
+
rome?: RomeConfig;
|
|
71
|
+
};
|
|
64
72
|
}
|
|
65
73
|
declare type PotentialSchemas = {
|
|
66
74
|
[key: string]: any;
|
|
67
75
|
};
|
|
68
|
-
export declare function parseSchema(potentialSchemas: PotentialSchemas): Result
|
|
76
|
+
export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Promise<Result>;
|
|
77
|
+
interface RomeConfig {
|
|
78
|
+
indentStyle?: string;
|
|
79
|
+
lineWidth?: number;
|
|
80
|
+
indentSize?: number;
|
|
81
|
+
quoteStyle?: string;
|
|
82
|
+
quoteProperties?: string;
|
|
83
|
+
trailingComma?: string;
|
|
84
|
+
}
|
|
85
|
+
interface ProcessedGlobalSchema {
|
|
86
|
+
globalEdges: ProcessedAssocEdge[];
|
|
87
|
+
extraEdgeFields: ProcessedField[];
|
|
88
|
+
init?: boolean;
|
|
89
|
+
globalFields?: ProcessedField[];
|
|
90
|
+
}
|
|
69
91
|
export {};
|
package/parse_schema/parse.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
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");
|
|
6
|
+
const global_schema_1 = require("../core/global_schema");
|
|
7
|
+
async function processFields(src, patternName) {
|
|
5
8
|
const ret = [];
|
|
6
9
|
let m = {};
|
|
7
10
|
if (Array.isArray(src)) {
|
|
@@ -19,10 +22,11 @@ function processFields(src, patternName) {
|
|
|
19
22
|
for (const name in m) {
|
|
20
23
|
const field = m[name];
|
|
21
24
|
//@ts-ignore type and other changed fields with different type in ProcessedField vs Field
|
|
22
|
-
let f = {
|
|
25
|
+
let f = { ...field, name };
|
|
23
26
|
f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
|
|
24
27
|
f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
|
|
25
28
|
f.hasFieldPrivacy = field.privacyPolicy !== undefined;
|
|
29
|
+
f.hasEditFieldPrivacy = field.editPrivacyPolicy !== undefined;
|
|
26
30
|
if (field.polymorphic) {
|
|
27
31
|
// convert boolean into object
|
|
28
32
|
// we keep boolean as an option to keep API simple
|
|
@@ -36,6 +40,19 @@ function processFields(src, patternName) {
|
|
|
36
40
|
else {
|
|
37
41
|
delete f.polymorphic;
|
|
38
42
|
}
|
|
43
|
+
if (field.private) {
|
|
44
|
+
// convert boolean into object
|
|
45
|
+
// we keep boolean as an option to keep API simple
|
|
46
|
+
if (typeof field.private === "boolean") {
|
|
47
|
+
f.private = {};
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
f.private = field.private;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
delete f.private;
|
|
55
|
+
}
|
|
39
56
|
// convert string to object to make API consumed by go simple
|
|
40
57
|
if (f.fieldEdge && f.fieldEdge.inverseEdge) {
|
|
41
58
|
if (typeof f.fieldEdge.inverseEdge === "string") {
|
|
@@ -47,26 +64,48 @@ function processFields(src, patternName) {
|
|
|
47
64
|
if (patternName) {
|
|
48
65
|
f.patternName = patternName;
|
|
49
66
|
}
|
|
67
|
+
if (field.serverDefault !== undefined) {
|
|
68
|
+
f.serverDefault = await transformServerDefault(name, field, field.serverDefault);
|
|
69
|
+
}
|
|
50
70
|
transformType(field.type);
|
|
51
71
|
if (field.getDerivedFields) {
|
|
52
|
-
f.derivedFields = processFields(field.getDerivedFields(name));
|
|
72
|
+
f.derivedFields = await processFields(field.getDerivedFields(name));
|
|
53
73
|
}
|
|
54
74
|
if (field.type.subFields) {
|
|
55
|
-
f.type.subFields = processFields(field.type.subFields);
|
|
75
|
+
f.type.subFields = await processFields(field.type.subFields);
|
|
56
76
|
}
|
|
57
77
|
if (field.type.unionFields) {
|
|
58
|
-
f.type.unionFields = processFields(field.type.unionFields);
|
|
78
|
+
f.type.unionFields = await processFields(field.type.unionFields);
|
|
59
79
|
}
|
|
60
80
|
if (field.type.listElemType &&
|
|
61
81
|
field.type.listElemType.subFields &&
|
|
62
82
|
// check to avoid ts-ignore below. exists just for tsc
|
|
63
83
|
f.type.listElemType) {
|
|
64
|
-
f.type.listElemType.subFields = processFields(field.type.listElemType.subFields);
|
|
84
|
+
f.type.listElemType.subFields = await processFields(field.type.listElemType.subFields);
|
|
65
85
|
}
|
|
66
86
|
ret.push(f);
|
|
67
87
|
}
|
|
68
88
|
return ret;
|
|
69
89
|
}
|
|
90
|
+
async function transformServerDefault(name, f, value) {
|
|
91
|
+
if (f.valid) {
|
|
92
|
+
if (!(await f.valid(value))) {
|
|
93
|
+
throw new Error(`invalid value ${value} passed to field ${name}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (f.format) {
|
|
97
|
+
value = await f.format(value);
|
|
98
|
+
}
|
|
99
|
+
switch (typeof value) {
|
|
100
|
+
case "boolean":
|
|
101
|
+
case "number":
|
|
102
|
+
case "bigint":
|
|
103
|
+
case "string":
|
|
104
|
+
return `${value}`;
|
|
105
|
+
default:
|
|
106
|
+
throw new Error(`invalid value ${value} passed to field ${name}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
70
109
|
function transformImportType(typ) {
|
|
71
110
|
if (!typ.importType) {
|
|
72
111
|
return;
|
|
@@ -108,12 +147,12 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
108
147
|
processedSchema.assocEdgeGroups.push(group2);
|
|
109
148
|
}
|
|
110
149
|
}
|
|
111
|
-
function processPattern(patterns, pattern, processedSchema) {
|
|
150
|
+
async function processPattern(patterns, pattern, processedSchema) {
|
|
112
151
|
let ret = {
|
|
113
152
|
...pattern,
|
|
114
153
|
};
|
|
115
154
|
const name = pattern.name;
|
|
116
|
-
const fields = processFields(pattern.fields, pattern.name);
|
|
155
|
+
const fields = await processFields(pattern.fields, pattern.name);
|
|
117
156
|
processedSchema.fields.push(...fields);
|
|
118
157
|
if (pattern.edges) {
|
|
119
158
|
const edges = processEdges(pattern.edges, pattern.name);
|
|
@@ -122,6 +161,23 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
122
161
|
// flag transformsSelect
|
|
123
162
|
if (pattern.transformRead) {
|
|
124
163
|
ret.transformsSelect = true;
|
|
164
|
+
if (pattern.transformReadCodegen_BETA) {
|
|
165
|
+
const r = pattern.transformReadCodegen_BETA();
|
|
166
|
+
if (typeof r === "string") {
|
|
167
|
+
ret.transformsLoaderCodegen = {
|
|
168
|
+
code: r,
|
|
169
|
+
imports: [
|
|
170
|
+
{
|
|
171
|
+
importPath: const_1.PACKAGE,
|
|
172
|
+
import: "query",
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
ret.transformsLoaderCodegen = r;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
125
181
|
}
|
|
126
182
|
if (patterns[name] === undefined) {
|
|
127
183
|
// intentionally processing separately and not passing pattern.name
|
|
@@ -146,35 +202,51 @@ var NullableResult;
|
|
|
146
202
|
NullableResult["ITEM"] = "true";
|
|
147
203
|
})(NullableResult || (NullableResult = {}));
|
|
148
204
|
function processAction(action) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (typeof f.nullable === "boolean") {
|
|
160
|
-
f2.nullable = NullableResult.ITEM;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
if (f.nullable === "contentsAndList") {
|
|
164
|
-
f2.nullable = NullableResult.CONTENTS_AND_LIST;
|
|
205
|
+
const ret = { ...action };
|
|
206
|
+
if (action.actionOnlyFields !== undefined) {
|
|
207
|
+
let actionOnlyFields = action.actionOnlyFields.map((f) => {
|
|
208
|
+
let f2 = f;
|
|
209
|
+
if (!f.nullable) {
|
|
210
|
+
delete f2.nullable;
|
|
211
|
+
return f2;
|
|
212
|
+
}
|
|
213
|
+
if (typeof f.nullable === "boolean") {
|
|
214
|
+
f2.nullable = NullableResult.ITEM;
|
|
165
215
|
}
|
|
166
216
|
else {
|
|
167
|
-
|
|
217
|
+
if (f.nullable === "contentsAndList") {
|
|
218
|
+
f2.nullable = NullableResult.CONTENTS_AND_LIST;
|
|
219
|
+
}
|
|
220
|
+
else if (f.nullable === "contents") {
|
|
221
|
+
f2.nullable = NullableResult.CONTENTS;
|
|
222
|
+
}
|
|
223
|
+
else if (f.nullable === "true") {
|
|
224
|
+
// shouldn't happen but ran into weirdness where it did...
|
|
225
|
+
f2.nullable = NullableResult.ITEM;
|
|
226
|
+
}
|
|
168
227
|
}
|
|
228
|
+
return f2;
|
|
229
|
+
});
|
|
230
|
+
ret.actionOnlyFields = actionOnlyFields;
|
|
231
|
+
}
|
|
232
|
+
if (action.canViewerDo !== undefined) {
|
|
233
|
+
if (typeof action.canViewerDo !== "object") {
|
|
234
|
+
delete ret.canViewerDo;
|
|
235
|
+
ret.canViewerDo = {};
|
|
169
236
|
}
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
ret.actionOnlyFields = actionOnlyFields;
|
|
237
|
+
}
|
|
173
238
|
return ret;
|
|
174
239
|
}
|
|
175
|
-
function parseSchema(potentialSchemas) {
|
|
240
|
+
async function parseSchema(potentialSchemas, globalSchema) {
|
|
176
241
|
let schemas = {};
|
|
177
242
|
let patterns = {};
|
|
243
|
+
let parsedGlobalSchema;
|
|
244
|
+
if (globalSchema) {
|
|
245
|
+
parsedGlobalSchema = await parseGlobalSchema(globalSchema);
|
|
246
|
+
// set this so that we can use it, if we're trying to process server default or anything
|
|
247
|
+
// that ends up parsing,validating and formatting fields
|
|
248
|
+
(0, global_schema_1.setGlobalSchema)(globalSchema);
|
|
249
|
+
}
|
|
178
250
|
for (const key in potentialSchemas) {
|
|
179
251
|
const value = potentialSchemas[key];
|
|
180
252
|
let schema;
|
|
@@ -190,6 +262,7 @@ function parseSchema(potentialSchemas) {
|
|
|
190
262
|
}
|
|
191
263
|
let processedSchema = {
|
|
192
264
|
fields: [],
|
|
265
|
+
fieldOverrides: schema.fieldOverrides,
|
|
193
266
|
schemaPath: schema.schemaPath,
|
|
194
267
|
tableName: schema.tableName,
|
|
195
268
|
enumTable: schema.enumTable,
|
|
@@ -200,19 +273,27 @@ function parseSchema(potentialSchemas) {
|
|
|
200
273
|
actions: schema.actions?.map((action) => processAction(action)) || [],
|
|
201
274
|
assocEdges: [],
|
|
202
275
|
assocEdgeGroups: [],
|
|
276
|
+
customGraphQLInterfaces: schema.customGraphQLInterfaces,
|
|
277
|
+
supportUpsert: schema.supportUpsert,
|
|
278
|
+
showCanViewerSee: schema.showCanViewerSee,
|
|
279
|
+
showCanViewerEdit: schema.showCanViewerEdit,
|
|
203
280
|
};
|
|
204
281
|
// let's put patterns first just so we have id, created_at, updated_at first
|
|
205
282
|
// ¯\_(ツ)_/¯
|
|
206
283
|
let patternNames = [];
|
|
207
284
|
if (schema.patterns) {
|
|
208
285
|
for (const pattern of schema.patterns) {
|
|
209
|
-
const ret = processPattern(patterns, pattern, processedSchema);
|
|
286
|
+
const ret = await processPattern(patterns, pattern, processedSchema);
|
|
210
287
|
patternNames.push(pattern.name);
|
|
211
288
|
if (ret.transformsSelect) {
|
|
212
289
|
if (processedSchema.transformsSelect) {
|
|
213
290
|
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
214
291
|
}
|
|
215
292
|
processedSchema.transformsSelect = true;
|
|
293
|
+
if (ret.transformsLoaderCodegen) {
|
|
294
|
+
processedSchema.transformsLoaderCodegen =
|
|
295
|
+
ret.transformsLoaderCodegen;
|
|
296
|
+
}
|
|
216
297
|
}
|
|
217
298
|
if (ret.transformsDelete) {
|
|
218
299
|
if (processedSchema.transformsDelete) {
|
|
@@ -222,7 +303,7 @@ function parseSchema(potentialSchemas) {
|
|
|
222
303
|
}
|
|
223
304
|
}
|
|
224
305
|
}
|
|
225
|
-
const fields = processFields(schema.fields);
|
|
306
|
+
const fields = await processFields(schema.fields);
|
|
226
307
|
processedSchema.fields.push(...fields);
|
|
227
308
|
processedSchema.patternNames = patternNames;
|
|
228
309
|
if (schema.edges) {
|
|
@@ -234,6 +315,72 @@ function parseSchema(potentialSchemas) {
|
|
|
234
315
|
}
|
|
235
316
|
schemas[key] = processedSchema;
|
|
236
317
|
}
|
|
237
|
-
|
|
318
|
+
const rome = translatePrettier();
|
|
319
|
+
return {
|
|
320
|
+
schemas,
|
|
321
|
+
patterns,
|
|
322
|
+
globalSchema: parsedGlobalSchema,
|
|
323
|
+
config: {
|
|
324
|
+
rome,
|
|
325
|
+
},
|
|
326
|
+
};
|
|
238
327
|
}
|
|
239
328
|
exports.parseSchema = parseSchema;
|
|
329
|
+
function translatePrettier() {
|
|
330
|
+
const r = (0, cosmiconfig_1.cosmiconfigSync)("prettier").search();
|
|
331
|
+
if (!r) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const ret = {};
|
|
335
|
+
if (r.config.printWidth !== undefined) {
|
|
336
|
+
ret.lineWidth = parseInt(r.config.printWidth);
|
|
337
|
+
}
|
|
338
|
+
if (r.config.useTabs) {
|
|
339
|
+
ret.indentStyle = "tab";
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
ret.indentStyle = "space";
|
|
343
|
+
}
|
|
344
|
+
if (r.config.tabWidth !== undefined) {
|
|
345
|
+
ret.indentSize = parseInt(r.config.tabWidth);
|
|
346
|
+
}
|
|
347
|
+
if (r.config.singleQuote) {
|
|
348
|
+
ret.quoteStyle = "single";
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
ret.quoteStyle = "double";
|
|
352
|
+
}
|
|
353
|
+
if (r.config.quoteProps !== undefined) {
|
|
354
|
+
if (r.config.quoteProps === "consistent") {
|
|
355
|
+
// rome doesn't support this
|
|
356
|
+
ret.quoteProperties = "as-needed";
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
ret.quoteProperties = r.config.quoteProps;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (r.config.trailingComma !== undefined) {
|
|
363
|
+
ret.trailingComma = r.config.trailingComma;
|
|
364
|
+
}
|
|
365
|
+
return ret;
|
|
366
|
+
}
|
|
367
|
+
async function parseGlobalSchema(s) {
|
|
368
|
+
const ret = {
|
|
369
|
+
globalEdges: [],
|
|
370
|
+
extraEdgeFields: [],
|
|
371
|
+
init: !!s.extraEdgeFields ||
|
|
372
|
+
s.transformEdgeRead !== undefined ||
|
|
373
|
+
s.transformEdgeWrite !== undefined ||
|
|
374
|
+
s.fields !== undefined,
|
|
375
|
+
};
|
|
376
|
+
if (s.extraEdgeFields) {
|
|
377
|
+
ret.extraEdgeFields = await processFields(s.extraEdgeFields);
|
|
378
|
+
}
|
|
379
|
+
if (s.edges) {
|
|
380
|
+
ret.globalEdges = processEdges(s.edges);
|
|
381
|
+
}
|
|
382
|
+
if (s.fields) {
|
|
383
|
+
ret.globalFields = await processFields(s.fields);
|
|
384
|
+
}
|
|
385
|
+
return ret;
|
|
386
|
+
}
|
package/schema/base_schema.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldMap, Pattern, FieldOverrideMap } from "./schema";
|
|
2
2
|
import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
|
|
3
3
|
export declare const Timestamps: Pattern;
|
|
4
4
|
export declare const Node: Pattern;
|
|
5
5
|
export interface SchemaConfig extends Schema {
|
|
6
6
|
}
|
|
7
7
|
export declare class EntSchema implements Schema {
|
|
8
|
-
fields: FieldMap
|
|
8
|
+
fields: FieldMap;
|
|
9
|
+
fieldOverrides: FieldOverrideMap | undefined;
|
|
9
10
|
tableName: string | undefined;
|
|
10
11
|
patterns: Pattern[];
|
|
11
12
|
edges: Edge[] | undefined;
|
|
@@ -18,10 +19,15 @@ export declare class EntSchema implements Schema {
|
|
|
18
19
|
constraints: Constraint[] | undefined;
|
|
19
20
|
indices: Index[] | undefined;
|
|
20
21
|
hideFromGraphQL?: boolean;
|
|
22
|
+
customGraphQLInterfaces?: string[] | undefined;
|
|
23
|
+
supportUpsert?: boolean | undefined;
|
|
24
|
+
showCanViewerSee?: boolean | undefined;
|
|
25
|
+
showCanViewerEdit?: boolean | undefined;
|
|
21
26
|
constructor(cfg: SchemaConfig);
|
|
22
27
|
}
|
|
23
28
|
export declare class EntSchemaWithTZ implements Schema {
|
|
24
|
-
fields: FieldMap
|
|
29
|
+
fields: FieldMap;
|
|
30
|
+
fieldOverrides: FieldOverrideMap | undefined;
|
|
25
31
|
tableName: string | undefined;
|
|
26
32
|
patterns: Pattern[];
|
|
27
33
|
edges: Edge[] | undefined;
|
|
@@ -34,6 +40,10 @@ export declare class EntSchemaWithTZ implements Schema {
|
|
|
34
40
|
constraints: Constraint[] | undefined;
|
|
35
41
|
indices: Index[] | undefined;
|
|
36
42
|
hideFromGraphQL?: boolean;
|
|
43
|
+
customGraphQLInterfaces?: string[] | undefined;
|
|
44
|
+
supportUpsert?: boolean | undefined;
|
|
45
|
+
showCanViewerSee?: boolean | undefined;
|
|
46
|
+
showCanViewerEdit?: boolean | undefined;
|
|
37
47
|
constructor(cfg: SchemaConfig);
|
|
38
48
|
}
|
|
39
49
|
export declare abstract class BaseEntSchema {
|
package/schema/base_schema.js
CHANGED
|
@@ -17,6 +17,7 @@ let tsFields = {
|
|
|
17
17
|
defaultValueOnCreate: () => {
|
|
18
18
|
return new Date();
|
|
19
19
|
},
|
|
20
|
+
onlyUpdateIfOtherFieldsBeingSet_BETA: true,
|
|
20
21
|
defaultValueOnEdit: () => {
|
|
21
22
|
return new Date();
|
|
22
23
|
},
|
|
@@ -74,6 +75,7 @@ class EntSchema {
|
|
|
74
75
|
constructor(cfg) {
|
|
75
76
|
this.patterns = [exports.Node];
|
|
76
77
|
this.fields = cfg.fields;
|
|
78
|
+
this.fieldOverrides = cfg.fieldOverrides;
|
|
77
79
|
this.tableName = cfg.tableName;
|
|
78
80
|
if (cfg.patterns) {
|
|
79
81
|
this.patterns.push(...cfg.patterns);
|
|
@@ -86,6 +88,11 @@ class EntSchema {
|
|
|
86
88
|
this.constraints = cfg.constraints;
|
|
87
89
|
this.indices = cfg.indices;
|
|
88
90
|
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
91
|
+
// TODO annoying that have to list these...
|
|
92
|
+
this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
|
|
93
|
+
this.supportUpsert = cfg.supportUpsert;
|
|
94
|
+
this.showCanViewerSee = cfg.showCanViewerSee;
|
|
95
|
+
this.showCanViewerEdit = cfg.showCanViewerEdit;
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
exports.EntSchema = EntSchema;
|
|
@@ -100,6 +107,7 @@ class EntSchemaWithTZ {
|
|
|
100
107
|
},
|
|
101
108
|
];
|
|
102
109
|
this.fields = cfg.fields;
|
|
110
|
+
this.fieldOverrides = cfg.fieldOverrides;
|
|
103
111
|
this.tableName = cfg.tableName;
|
|
104
112
|
if (cfg.patterns) {
|
|
105
113
|
this.patterns.push(...cfg.patterns);
|
|
@@ -112,6 +120,11 @@ class EntSchemaWithTZ {
|
|
|
112
120
|
this.constraints = cfg.constraints;
|
|
113
121
|
this.indices = cfg.indices;
|
|
114
122
|
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
123
|
+
// TODO annoying that have to list these...
|
|
124
|
+
this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
|
|
125
|
+
this.supportUpsert = cfg.supportUpsert;
|
|
126
|
+
this.showCanViewerSee = cfg.showCanViewerSee;
|
|
127
|
+
this.showCanViewerEdit = cfg.showCanViewerEdit;
|
|
115
128
|
}
|
|
116
129
|
}
|
|
117
130
|
exports.EntSchemaWithTZ = EntSchemaWithTZ;
|