@snowtop/ent 0.1.0-alpha → 0.1.0-alpha12
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 +2 -0
- package/action/executor.d.ts +1 -1
- package/action/orchestrator.d.ts +16 -3
- package/action/orchestrator.js +157 -47
- package/core/base.d.ts +6 -2
- package/core/base.js +16 -0
- package/core/clause.d.ts +24 -3
- package/core/clause.js +246 -5
- package/core/config.d.ts +18 -0
- package/core/config.js +17 -0
- package/core/db.d.ts +3 -3
- package/core/db.js +2 -0
- package/core/ent.d.ts +2 -4
- package/core/ent.js +72 -25
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/object_loader.d.ts +7 -2
- package/core/loaders/object_loader.js +59 -4
- package/core/privacy.d.ts +1 -1
- package/core/privacy.js +3 -0
- package/core/viewer.d.ts +1 -0
- package/core/viewer.js +4 -0
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +24 -23
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +3 -1
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/imports/index.d.ts +0 -1
- package/imports/index.js +3 -36
- package/index.d.ts +16 -1
- package/index.js +18 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +23 -4
- package/parse_schema/parse.js +87 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +63 -17
- package/schema/field.d.ts +25 -25
- package/schema/field.js +42 -33
- package/schema/index.d.ts +4 -2
- package/schema/index.js +10 -1
- package/schema/json_field.d.ts +6 -6
- package/schema/json_field.js +2 -2
- package/schema/schema.d.ts +70 -6
- package/schema/schema.js +142 -10
- package/schema/struct_field.d.ts +17 -0
- package/schema/struct_field.js +102 -0
- package/schema/union_field.d.ts +23 -0
- package/schema/union_field.js +79 -0
- package/scripts/custom_compiler.js +2 -19
- package/scripts/custom_graphql.js +122 -15
- package/scripts/move_generated.d.ts +1 -0
- package/scripts/move_generated.js +142 -0
- package/scripts/read_schema.js +15 -1
- package/scripts/transform_code.d.ts +1 -0
- package/scripts/transform_code.js +113 -0
- package/scripts/transform_schema.d.ts +1 -0
- package/scripts/transform_schema.js +355 -0
- package/testutils/builder.d.ts +16 -9
- package/testutils/builder.js +80 -8
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/test_db.d.ts +2 -1
- package/testutils/db/test_db.js +22 -13
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +3 -7
- package/testutils/fake_data/fake_contact.js +14 -26
- package/testutils/fake_data/fake_event.d.ts +3 -7
- package/testutils/fake_data/fake_event.js +20 -33
- package/testutils/fake_data/fake_user.d.ts +3 -7
- package/testutils/fake_data/fake_user.js +22 -36
- package/testutils/fake_data/test_helpers.js +1 -1
- package/tsc/ast.d.ts +21 -0
- package/tsc/ast.js +154 -0
- package/tsc/compilerOptions.d.ts +8 -0
- package/tsc/compilerOptions.js +100 -0
package/index.js
CHANGED
|
@@ -25,8 +25,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.DenyIfViewerOutboundEdgeExistsRule = exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.
|
|
29
|
-
exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule =
|
|
28
|
+
exports.DenyIfViewerInboundEdgeDoesNotExistRule = exports.DenyIfEdgeDoesNotExistRule = exports.DenyIfViewerOutboundEdgeExistsRule = exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
|
|
29
|
+
exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = void 0;
|
|
30
30
|
__exportStar(require("./core/base"), exports);
|
|
31
31
|
var ent_1 = require("./core/ent");
|
|
32
32
|
Object.defineProperty(exports, "loadEnt", { enumerable: true, get: function () { return ent_1.loadEnt; } });
|
|
@@ -38,8 +38,6 @@ Object.defineProperty(exports, "loadDerivedEnt", { enumerable: true, get: functi
|
|
|
38
38
|
Object.defineProperty(exports, "loadDerivedEntX", { enumerable: true, get: function () { return ent_1.loadDerivedEntX; } });
|
|
39
39
|
Object.defineProperty(exports, "loadEntViaKey", { enumerable: true, get: function () { return ent_1.loadEntViaKey; } });
|
|
40
40
|
Object.defineProperty(exports, "loadEntXViaKey", { enumerable: true, get: function () { return ent_1.loadEntXViaKey; } });
|
|
41
|
-
Object.defineProperty(exports, "applyPrivacyPolicyForEnt", { enumerable: true, get: function () { return ent_1.applyPrivacyPolicyForEnt; } });
|
|
42
|
-
Object.defineProperty(exports, "applyPrivacyPolicyForEntX", { enumerable: true, get: function () { return ent_1.applyPrivacyPolicyForEntX; } });
|
|
43
41
|
Object.defineProperty(exports, "performRawQuery", { enumerable: true, get: function () { return ent_1.performRawQuery; } });
|
|
44
42
|
// even these 3 need to change...
|
|
45
43
|
Object.defineProperty(exports, "loadRowX", { enumerable: true, get: function () { return ent_1.loadRowX; } });
|
|
@@ -62,7 +60,7 @@ Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: fu
|
|
|
62
60
|
const db_1 = __importDefault(require("./core/db"));
|
|
63
61
|
exports.DB = db_1.default;
|
|
64
62
|
__exportStar(require("./core/loaders"), exports);
|
|
65
|
-
// TODO figure out if this should be its own
|
|
63
|
+
// TODO figure out if this should be its own import path e.g. @snowtop/ent/privacy
|
|
66
64
|
var privacy_1 = require("./core/privacy");
|
|
67
65
|
Object.defineProperty(exports, "EntPrivacyError", { enumerable: true, get: function () { return privacy_1.EntPrivacyError; } });
|
|
68
66
|
Object.defineProperty(exports, "AlwaysAllowRule", { enumerable: true, get: function () { return privacy_1.AlwaysAllowRule; } });
|
|
@@ -109,12 +107,27 @@ const query = {
|
|
|
109
107
|
Eq: q.Eq,
|
|
110
108
|
NotEq: q.NotEq,
|
|
111
109
|
And: q.And,
|
|
110
|
+
AndOptional: q.AndOptional,
|
|
112
111
|
Or: q.Or,
|
|
113
112
|
In: q.In,
|
|
114
113
|
Greater: q.Greater,
|
|
115
114
|
Less: q.Less,
|
|
116
115
|
GreaterEq: q.GreaterEq,
|
|
117
116
|
LessEq: q.LessEq,
|
|
117
|
+
ArrayEq: q.ArrayEq,
|
|
118
|
+
ArrayNotEq: q.ArrayNotEq,
|
|
119
|
+
ArrayGreater: q.ArrayGreater,
|
|
120
|
+
ArrayLess: q.ArrayLess,
|
|
121
|
+
ArrayGreaterEq: q.ArrayGreaterEq,
|
|
122
|
+
ArrayLessEq: q.ArrayLessEq,
|
|
123
|
+
TsQuery: q.TsQuery,
|
|
124
|
+
PlainToTsQuery: q.PlainToTsQuery,
|
|
125
|
+
PhraseToTsQuery: q.PhraseToTsQuery,
|
|
126
|
+
WebsearchToTsQuery: q.WebsearchToTsQuery,
|
|
127
|
+
TsVectorColTsQuery: q.TsVectorColTsQuery,
|
|
128
|
+
TsVectorPlainToTsQuery: q.TsVectorPlainToTsQuery,
|
|
129
|
+
TsVectorPhraseToTsQuery: q.TsVectorPhraseToTsQuery,
|
|
130
|
+
TsVectorWebsearchToTsQuery: q.TsVectorWebsearchToTsQuery,
|
|
118
131
|
};
|
|
119
132
|
exports.query = query;
|
|
120
133
|
var context_1 = require("./core/context");
|
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-alpha12",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"json5": "^2.1.3",
|
|
18
18
|
"luxon": "^1.25.0",
|
|
19
19
|
"memoizee": "^0.4.15",
|
|
20
|
-
"minimist": "^1.2.
|
|
20
|
+
"minimist": "^1.2.6",
|
|
21
21
|
"pascal-case": "^3.1.2",
|
|
22
22
|
"pg": "^8.0.3",
|
|
23
23
|
"prettier": "^2.3.2",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"better-sqlite3": "^7.4.1",
|
|
34
|
-
"graphql": "^
|
|
34
|
+
"graphql": "^16.5.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"better-sqlite3": {
|
package/parse_schema/parse.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
2
|
-
import { ActionField } from "../schema/schema";
|
|
2
|
+
import { ActionField, Type } from "../schema/schema";
|
|
3
3
|
declare enum NullableResult {
|
|
4
4
|
CONTENTS = "contents",
|
|
5
5
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
@@ -12,11 +12,18 @@ declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActi
|
|
|
12
12
|
patternName?: string;
|
|
13
13
|
edgeActions?: OutputAction[];
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
interface TransformFlags {
|
|
16
|
+
transformsSelect?: boolean;
|
|
17
|
+
transformsDelete?: boolean;
|
|
18
|
+
transformsInsert?: boolean;
|
|
19
|
+
transformsUpdate?: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
|
|
16
22
|
actions: OutputAction[];
|
|
17
23
|
assocEdges: ProcessedAssocEdge[];
|
|
18
24
|
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
|
19
25
|
fields: ProcessedField[];
|
|
26
|
+
schemaPath?: string;
|
|
20
27
|
};
|
|
21
28
|
declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
22
29
|
edgeAction?: OutputAction;
|
|
@@ -32,10 +39,19 @@ interface ProcessedPattern {
|
|
|
32
39
|
assocEdges: ProcessedAssocEdge[];
|
|
33
40
|
fields: ProcessedField[];
|
|
34
41
|
}
|
|
35
|
-
declare type
|
|
42
|
+
declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
|
|
43
|
+
subFields?: ProcessedField[];
|
|
44
|
+
listElemType?: ProcessedType;
|
|
45
|
+
unionFields?: ProcessedField[];
|
|
46
|
+
};
|
|
47
|
+
declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
|
|
48
|
+
name: string;
|
|
36
49
|
hasDefaultValueOnCreate?: boolean;
|
|
37
50
|
hasDefaultValueOnEdit?: boolean;
|
|
38
51
|
patternName?: string;
|
|
52
|
+
hasFieldPrivacy?: boolean;
|
|
53
|
+
derivedFields?: ProcessedField[];
|
|
54
|
+
type: ProcessedType;
|
|
39
55
|
};
|
|
40
56
|
interface patternsDict {
|
|
41
57
|
[key: string]: ProcessedPattern;
|
|
@@ -44,5 +60,8 @@ interface Result {
|
|
|
44
60
|
schemas: schemasDict;
|
|
45
61
|
patterns: patternsDict;
|
|
46
62
|
}
|
|
47
|
-
|
|
63
|
+
declare type PotentialSchemas = {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
|
|
48
67
|
export {};
|
package/parse_schema/parse.js
CHANGED
|
@@ -3,10 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseSchema = void 0;
|
|
4
4
|
function processFields(src, patternName) {
|
|
5
5
|
const ret = [];
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
let m = {};
|
|
7
|
+
if (Array.isArray(src)) {
|
|
8
|
+
for (const field of src) {
|
|
9
|
+
const name = field.name;
|
|
10
|
+
if (!name) {
|
|
11
|
+
throw new Error(`name is required`);
|
|
12
|
+
}
|
|
13
|
+
m[name] = field;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
m = src;
|
|
18
|
+
}
|
|
19
|
+
for (const name in m) {
|
|
20
|
+
const field = m[name];
|
|
21
|
+
//@ts-ignore type and other changed fields with different type in ProcessedField vs Field
|
|
22
|
+
let f = { name, ...field };
|
|
8
23
|
f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
|
|
9
24
|
f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
|
|
25
|
+
f.hasFieldPrivacy = field.privacyPolicy !== undefined;
|
|
10
26
|
if (field.polymorphic) {
|
|
11
27
|
// convert boolean into object
|
|
12
28
|
// we keep boolean as an option to keep API simple
|
|
@@ -17,6 +33,9 @@ function processFields(src, patternName) {
|
|
|
17
33
|
f.polymorphic = field.polymorphic;
|
|
18
34
|
}
|
|
19
35
|
}
|
|
36
|
+
else {
|
|
37
|
+
delete f.polymorphic;
|
|
38
|
+
}
|
|
20
39
|
// convert string to object to make API consumed by go simple
|
|
21
40
|
if (f.fieldEdge && f.fieldEdge.inverseEdge) {
|
|
22
41
|
if (typeof f.fieldEdge.inverseEdge === "string") {
|
|
@@ -28,10 +47,44 @@ function processFields(src, patternName) {
|
|
|
28
47
|
if (patternName) {
|
|
29
48
|
f.patternName = patternName;
|
|
30
49
|
}
|
|
50
|
+
transformType(field.type);
|
|
51
|
+
if (field.getDerivedFields) {
|
|
52
|
+
f.derivedFields = processFields(field.getDerivedFields(name));
|
|
53
|
+
}
|
|
54
|
+
if (field.type.subFields) {
|
|
55
|
+
f.type.subFields = processFields(field.type.subFields);
|
|
56
|
+
}
|
|
57
|
+
if (field.type.unionFields) {
|
|
58
|
+
f.type.unionFields = processFields(field.type.unionFields);
|
|
59
|
+
}
|
|
60
|
+
if (field.type.listElemType &&
|
|
61
|
+
field.type.listElemType.subFields &&
|
|
62
|
+
// check to avoid ts-ignore below. exists just for tsc
|
|
63
|
+
f.type.listElemType) {
|
|
64
|
+
f.type.listElemType.subFields = processFields(field.type.listElemType.subFields);
|
|
65
|
+
}
|
|
31
66
|
ret.push(f);
|
|
32
67
|
}
|
|
33
68
|
return ret;
|
|
34
69
|
}
|
|
70
|
+
function transformImportType(typ) {
|
|
71
|
+
if (!typ.importType) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
typ.importType = {
|
|
75
|
+
...typ.importType,
|
|
76
|
+
// these 2 needed for forwards compatibility with new go schema
|
|
77
|
+
importPath: typ.importType.path,
|
|
78
|
+
import: typ.importType.type,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function transformType(typ) {
|
|
82
|
+
if (!typ) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
transformImportType(typ);
|
|
86
|
+
transformType(typ.listElemType);
|
|
87
|
+
}
|
|
35
88
|
function processEdges(src, patternName) {
|
|
36
89
|
const ret = [];
|
|
37
90
|
for (const edge of src) {
|
|
@@ -56,6 +109,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
56
109
|
}
|
|
57
110
|
}
|
|
58
111
|
function processPattern(patterns, pattern, processedSchema) {
|
|
112
|
+
let ret = {
|
|
113
|
+
...pattern,
|
|
114
|
+
};
|
|
59
115
|
const name = pattern.name;
|
|
60
116
|
const fields = processFields(pattern.fields, pattern.name);
|
|
61
117
|
processedSchema.fields.push(...fields);
|
|
@@ -63,6 +119,10 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
63
119
|
const edges = processEdges(pattern.edges, pattern.name);
|
|
64
120
|
processedSchema.assocEdges.push(...edges);
|
|
65
121
|
}
|
|
122
|
+
// flag transformsSelect
|
|
123
|
+
if (pattern.transformRead) {
|
|
124
|
+
ret.transformsSelect = true;
|
|
125
|
+
}
|
|
66
126
|
if (patterns[name] === undefined) {
|
|
67
127
|
// intentionally processing separately and not passing pattern.name
|
|
68
128
|
const edges = processEdges(pattern.edges || []);
|
|
@@ -76,6 +136,7 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
76
136
|
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
77
137
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
78
138
|
}
|
|
139
|
+
return ret;
|
|
79
140
|
}
|
|
80
141
|
var NullableResult;
|
|
81
142
|
(function (NullableResult) {
|
|
@@ -91,6 +152,7 @@ function processAction(action) {
|
|
|
91
152
|
let actionOnlyFields = action.actionOnlyFields.map((f) => {
|
|
92
153
|
let f2 = f;
|
|
93
154
|
if (!f.nullable) {
|
|
155
|
+
delete f2.nullable;
|
|
94
156
|
return f2;
|
|
95
157
|
}
|
|
96
158
|
if (typeof f.nullable === "boolean") {
|
|
@@ -115,14 +177,19 @@ function parseSchema(potentialSchemas) {
|
|
|
115
177
|
for (const key in potentialSchemas) {
|
|
116
178
|
const value = potentialSchemas[key];
|
|
117
179
|
let schema;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
180
|
+
const name = value.constructor.name;
|
|
181
|
+
// named class e.g. new BaseEntSchema
|
|
182
|
+
switch (name) {
|
|
183
|
+
case "Function":
|
|
184
|
+
schema = new value();
|
|
185
|
+
break;
|
|
186
|
+
default:
|
|
187
|
+
// implicit schema or named class
|
|
188
|
+
schema = value;
|
|
123
189
|
}
|
|
124
190
|
let processedSchema = {
|
|
125
191
|
fields: [],
|
|
192
|
+
schemaPath: schema.schemaPath,
|
|
126
193
|
tableName: schema.tableName,
|
|
127
194
|
enumTable: schema.enumTable,
|
|
128
195
|
dbRows: schema.dbRows,
|
|
@@ -137,7 +204,19 @@ function parseSchema(potentialSchemas) {
|
|
|
137
204
|
// ¯\_(ツ)_/¯
|
|
138
205
|
if (schema.patterns) {
|
|
139
206
|
for (const pattern of schema.patterns) {
|
|
140
|
-
processPattern(patterns, pattern, processedSchema);
|
|
207
|
+
const ret = processPattern(patterns, pattern, processedSchema);
|
|
208
|
+
if (ret.transformsSelect) {
|
|
209
|
+
if (processedSchema.transformsSelect) {
|
|
210
|
+
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
211
|
+
}
|
|
212
|
+
processedSchema.transformsSelect = true;
|
|
213
|
+
}
|
|
214
|
+
if (ret.transformsDelete) {
|
|
215
|
+
if (processedSchema.transformsDelete) {
|
|
216
|
+
throw new Error(`can only have one pattern which transforms default deletion behavior`);
|
|
217
|
+
}
|
|
218
|
+
processedSchema.transformsDelete = true;
|
|
219
|
+
}
|
|
141
220
|
}
|
|
142
221
|
}
|
|
143
222
|
const fields = processFields(schema.fields);
|
package/schema/base_schema.d.ts
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
|
-
import { Pattern } from "./schema";
|
|
1
|
+
import { Field, FieldMap, Pattern } from "./schema";
|
|
2
|
+
import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
|
|
2
3
|
export declare const Timestamps: Pattern;
|
|
3
4
|
export declare const Node: Pattern;
|
|
5
|
+
export interface SchemaConfig extends Schema {
|
|
6
|
+
}
|
|
7
|
+
export declare class EntSchema implements Schema {
|
|
8
|
+
fields: FieldMap | Field[];
|
|
9
|
+
tableName: string | undefined;
|
|
10
|
+
patterns: Pattern[];
|
|
11
|
+
edges: Edge[] | undefined;
|
|
12
|
+
edgeGroups: AssocEdgeGroup[] | undefined;
|
|
13
|
+
actions: Action[] | undefined;
|
|
14
|
+
enumTable: boolean | undefined;
|
|
15
|
+
dbRows: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}[] | undefined;
|
|
18
|
+
constraints: Constraint[] | undefined;
|
|
19
|
+
indices: Index[] | undefined;
|
|
20
|
+
hideFromGraphQL?: boolean;
|
|
21
|
+
constructor(cfg: SchemaConfig);
|
|
22
|
+
}
|
|
23
|
+
export declare class EntSchemaWithTZ implements Schema {
|
|
24
|
+
fields: FieldMap | Field[];
|
|
25
|
+
tableName: string | undefined;
|
|
26
|
+
patterns: Pattern[];
|
|
27
|
+
edges: Edge[] | undefined;
|
|
28
|
+
edgeGroups: AssocEdgeGroup[] | undefined;
|
|
29
|
+
actions: Action[] | undefined;
|
|
30
|
+
enumTable: boolean | undefined;
|
|
31
|
+
dbRows: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}[] | undefined;
|
|
34
|
+
constraints: Constraint[] | undefined;
|
|
35
|
+
indices: Index[] | undefined;
|
|
36
|
+
hideFromGraphQL?: boolean;
|
|
37
|
+
constructor(cfg: SchemaConfig);
|
|
38
|
+
}
|
|
4
39
|
export declare abstract class BaseEntSchema {
|
|
5
40
|
addPatterns(...patterns: Pattern[]): void;
|
|
6
41
|
patterns: Pattern[];
|
package/schema/base_schema.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = void 0;
|
|
3
|
+
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.EntSchemaWithTZ = exports.EntSchema = exports.Node = exports.Timestamps = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
|
-
let tsFields =
|
|
7
|
-
(0, field_1.TimestampType)({
|
|
8
|
-
name: "createdAt",
|
|
6
|
+
let tsFields = {
|
|
7
|
+
createdAt: (0, field_1.TimestampType)({
|
|
9
8
|
hideFromGraphQL: true,
|
|
10
9
|
disableUserEditable: true,
|
|
11
10
|
defaultValueOnCreate: () => {
|
|
12
11
|
return new Date();
|
|
13
12
|
},
|
|
14
13
|
}),
|
|
15
|
-
(0, field_1.TimestampType)({
|
|
16
|
-
name: "updatedAt",
|
|
14
|
+
updatedAt: (0, field_1.TimestampType)({
|
|
17
15
|
hideFromGraphQL: true,
|
|
18
16
|
disableUserEditable: true,
|
|
19
17
|
defaultValueOnCreate: () => {
|
|
@@ -23,25 +21,28 @@ let tsFields = [
|
|
|
23
21
|
return new Date();
|
|
24
22
|
},
|
|
25
23
|
}),
|
|
26
|
-
|
|
24
|
+
};
|
|
27
25
|
// Timestamps is a Pattern that adds a createdAt and updatedAt timestamp fields to the ent
|
|
28
26
|
exports.Timestamps = {
|
|
29
27
|
name: "timestamps",
|
|
30
28
|
fields: tsFields,
|
|
31
29
|
};
|
|
32
30
|
let nodeField = (0, field_1.UUIDType)({
|
|
33
|
-
name: "ID",
|
|
34
31
|
primaryKey: true,
|
|
35
32
|
disableUserEditable: true,
|
|
36
33
|
defaultValueOnCreate: () => {
|
|
37
34
|
return (0, uuid_1.v4)();
|
|
38
35
|
},
|
|
39
36
|
});
|
|
40
|
-
let nodeFields =
|
|
41
|
-
|
|
42
|
-
nodeField,
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
let nodeFields = {
|
|
38
|
+
// inconsistent naming :(
|
|
39
|
+
ID: nodeField,
|
|
40
|
+
...tsFields,
|
|
41
|
+
};
|
|
42
|
+
let nodeFieldsWithTZ = {
|
|
43
|
+
// inconsistent naming :(
|
|
44
|
+
ID: nodeField,
|
|
45
|
+
createdAt: (0, field_1.TimestampType)({
|
|
45
46
|
hideFromGraphQL: true,
|
|
46
47
|
disableUserEditable: true,
|
|
47
48
|
defaultValueOnCreate: () => {
|
|
@@ -49,8 +50,7 @@ let nodeFieldsWithTZ = [
|
|
|
49
50
|
},
|
|
50
51
|
withTimezone: true,
|
|
51
52
|
}),
|
|
52
|
-
(0, field_1.TimestampType)({
|
|
53
|
-
name: "updatedAt",
|
|
53
|
+
updatedAt: (0, field_1.TimestampType)({
|
|
54
54
|
hideFromGraphQL: true,
|
|
55
55
|
disableUserEditable: true,
|
|
56
56
|
defaultValueOnCreate: () => {
|
|
@@ -61,14 +61,59 @@ let nodeFieldsWithTZ = [
|
|
|
61
61
|
},
|
|
62
62
|
withTimezone: true,
|
|
63
63
|
}),
|
|
64
|
-
|
|
64
|
+
};
|
|
65
65
|
// Node is a Pattern that adds 3 fields to the ent: (id, createdAt, and updatedAt timestamps)
|
|
66
66
|
exports.Node = {
|
|
67
67
|
name: "node",
|
|
68
68
|
fields: nodeFields,
|
|
69
69
|
};
|
|
70
|
-
//
|
|
70
|
+
// Ent schema. has Node Pattern by default.
|
|
71
71
|
// exists just to have less typing and easier for clients to implement
|
|
72
|
+
class EntSchema {
|
|
73
|
+
constructor(cfg) {
|
|
74
|
+
this.patterns = [exports.Node];
|
|
75
|
+
this.fields = cfg.fields;
|
|
76
|
+
this.tableName = cfg.tableName;
|
|
77
|
+
if (cfg.patterns) {
|
|
78
|
+
this.patterns.push(...cfg.patterns);
|
|
79
|
+
}
|
|
80
|
+
this.edges = cfg.edges;
|
|
81
|
+
this.edgeGroups = cfg.edgeGroups;
|
|
82
|
+
this.actions = cfg.actions;
|
|
83
|
+
this.enumTable = cfg.enumTable;
|
|
84
|
+
this.dbRows = cfg.dbRows;
|
|
85
|
+
this.constraints = cfg.constraints;
|
|
86
|
+
this.indices = cfg.indices;
|
|
87
|
+
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.EntSchema = EntSchema;
|
|
91
|
+
class EntSchemaWithTZ {
|
|
92
|
+
constructor(cfg) {
|
|
93
|
+
this.patterns = [
|
|
94
|
+
{
|
|
95
|
+
// default schema added
|
|
96
|
+
name: "nodeWithTZ",
|
|
97
|
+
fields: nodeFieldsWithTZ,
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
this.fields = cfg.fields;
|
|
101
|
+
this.tableName = cfg.tableName;
|
|
102
|
+
if (cfg.patterns) {
|
|
103
|
+
this.patterns.push(...cfg.patterns);
|
|
104
|
+
}
|
|
105
|
+
this.edges = cfg.edges;
|
|
106
|
+
this.edgeGroups = cfg.edgeGroups;
|
|
107
|
+
this.actions = cfg.actions;
|
|
108
|
+
this.enumTable = cfg.enumTable;
|
|
109
|
+
this.dbRows = cfg.dbRows;
|
|
110
|
+
this.constraints = cfg.constraints;
|
|
111
|
+
this.indices = cfg.indices;
|
|
112
|
+
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.EntSchemaWithTZ = EntSchemaWithTZ;
|
|
116
|
+
// @deprecated use EntSchema
|
|
72
117
|
class BaseEntSchema {
|
|
73
118
|
constructor() {
|
|
74
119
|
this.patterns = [exports.Node];
|
|
@@ -78,6 +123,7 @@ class BaseEntSchema {
|
|
|
78
123
|
}
|
|
79
124
|
}
|
|
80
125
|
exports.BaseEntSchema = BaseEntSchema;
|
|
126
|
+
// @deprecated use EntSchemaWithTZ
|
|
81
127
|
class BaseEntSchemaWithTZ {
|
|
82
128
|
constructor() {
|
|
83
129
|
this.patterns = [
|
package/schema/field.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
|
|
1
|
+
import { Field, FieldMap, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
|
|
2
2
|
export declare abstract class BaseField {
|
|
3
3
|
name: string;
|
|
4
4
|
nullable?: boolean;
|
|
@@ -12,18 +12,18 @@ export declare abstract class BaseField {
|
|
|
12
12
|
index?: boolean;
|
|
13
13
|
foreignKey?: ForeignKey;
|
|
14
14
|
polymorphic?: boolean | PolymorphicOptions;
|
|
15
|
-
derivedFields?: Field[];
|
|
16
15
|
derivedWhenEmbedded?: boolean;
|
|
17
16
|
logValue(val: any): any;
|
|
18
17
|
}
|
|
19
18
|
export declare class UUIDField extends BaseField implements Field {
|
|
20
|
-
private options
|
|
19
|
+
private options?;
|
|
21
20
|
type: Type;
|
|
22
|
-
constructor(options
|
|
21
|
+
constructor(options?: FieldOptions | undefined);
|
|
22
|
+
getDerivedFields(fieldName: string): FieldMap;
|
|
23
23
|
private isBuilder;
|
|
24
24
|
valid(val: any): Promise<boolean>;
|
|
25
25
|
}
|
|
26
|
-
export declare function UUIDType(options
|
|
26
|
+
export declare function UUIDType(options?: FieldOptions): UUIDField;
|
|
27
27
|
export interface IntegerOptions extends FieldOptions {
|
|
28
28
|
min?: number;
|
|
29
29
|
max?: number;
|
|
@@ -40,7 +40,7 @@ export declare class IntegerField extends BaseField implements Field {
|
|
|
40
40
|
valid(val: any): boolean;
|
|
41
41
|
validate(validator: (str: number) => boolean): this;
|
|
42
42
|
}
|
|
43
|
-
export declare function IntegerType(options
|
|
43
|
+
export declare function IntegerType(options?: IntegerOptions): IntegerField;
|
|
44
44
|
export declare class BigIntegerField extends BaseField implements Field {
|
|
45
45
|
type: Type;
|
|
46
46
|
}
|
|
@@ -48,11 +48,11 @@ export declare function BigIntegerType(options: FieldOptions): BigIntegerField;
|
|
|
48
48
|
export declare class FloatField extends BaseField implements Field {
|
|
49
49
|
type: Type;
|
|
50
50
|
}
|
|
51
|
-
export declare function FloatType(options
|
|
51
|
+
export declare function FloatType(options?: FieldOptions): FloatField;
|
|
52
52
|
export declare class BooleanField extends BaseField implements Field {
|
|
53
53
|
type: Type;
|
|
54
54
|
}
|
|
55
|
-
export declare function BooleanType(options
|
|
55
|
+
export declare function BooleanType(options?: FieldOptions): BooleanField;
|
|
56
56
|
export interface StringOptions extends FieldOptions {
|
|
57
57
|
minLen?: number;
|
|
58
58
|
maxLen?: number;
|
|
@@ -88,7 +88,7 @@ export declare class StringField extends BaseField implements Field {
|
|
|
88
88
|
trimLeft(): this;
|
|
89
89
|
trimRight(): this;
|
|
90
90
|
}
|
|
91
|
-
export declare function StringType(options
|
|
91
|
+
export declare function StringType(options?: StringOptions): StringField;
|
|
92
92
|
export interface TimestampOptions extends FieldOptions {
|
|
93
93
|
withTimezone?: boolean;
|
|
94
94
|
}
|
|
@@ -98,8 +98,8 @@ export declare class TimestampField extends BaseField implements Field {
|
|
|
98
98
|
constructor(options: TimestampOptions);
|
|
99
99
|
format(val: Date): any;
|
|
100
100
|
}
|
|
101
|
-
export declare function TimestampType(options
|
|
102
|
-
export declare function TimestamptzType(options
|
|
101
|
+
export declare function TimestampType(options?: TimestampOptions): TimestampField;
|
|
102
|
+
export declare function TimestamptzType(options?: FieldOptions): TimestampField;
|
|
103
103
|
export interface TimeOptions extends FieldOptions {
|
|
104
104
|
withTimezone?: boolean;
|
|
105
105
|
precision?: number;
|
|
@@ -108,16 +108,16 @@ export declare const leftPad: (val: number) => string;
|
|
|
108
108
|
export declare class TimeField extends BaseField implements Field {
|
|
109
109
|
type: Type;
|
|
110
110
|
withTimezone?: boolean;
|
|
111
|
-
constructor(options
|
|
111
|
+
constructor(options?: TimeOptions);
|
|
112
112
|
format(val: any): any;
|
|
113
113
|
}
|
|
114
|
-
export declare function TimeType(options
|
|
115
|
-
export declare function TimetzType(options
|
|
114
|
+
export declare function TimeType(options?: TimeOptions): TimeField;
|
|
115
|
+
export declare function TimetzType(options?: FieldOptions): TimeField;
|
|
116
116
|
export declare class DateField extends BaseField implements Field {
|
|
117
117
|
type: Type;
|
|
118
118
|
format(val: any): any;
|
|
119
119
|
}
|
|
120
|
-
export declare function DateType(options
|
|
120
|
+
export declare function DateType(options?: FieldOptions): DateField;
|
|
121
121
|
declare type EnumMap = {
|
|
122
122
|
[key: string]: string;
|
|
123
123
|
};
|
|
@@ -142,27 +142,27 @@ export declare class ListField extends BaseField {
|
|
|
142
142
|
private field;
|
|
143
143
|
type: Type;
|
|
144
144
|
private validators;
|
|
145
|
-
constructor(field: Field, options
|
|
145
|
+
constructor(field: Field, options?: FieldOptions);
|
|
146
146
|
validate(validator: (val: any[]) => boolean): this;
|
|
147
147
|
valid(val: any): Promise<boolean>;
|
|
148
148
|
private postgresVal;
|
|
149
|
-
format(val: any): any;
|
|
149
|
+
format(val: any, nested?: boolean): any;
|
|
150
150
|
minLen(l: number): this;
|
|
151
151
|
maxLen(l: number): this;
|
|
152
152
|
length(l: number): this;
|
|
153
153
|
range(start: any, stop: any): this;
|
|
154
154
|
}
|
|
155
|
-
export declare function StringListType(options
|
|
155
|
+
export declare function StringListType(options?: StringOptions): ListField;
|
|
156
156
|
export declare function IntListType(options: FieldOptions): ListField;
|
|
157
|
-
export declare function IntegerListType(options
|
|
158
|
-
export declare function FloatListType(options
|
|
157
|
+
export declare function IntegerListType(options?: FieldOptions): ListField;
|
|
158
|
+
export declare function FloatListType(options?: FieldOptions): ListField;
|
|
159
159
|
export declare function BigIntegerListType(options: FieldOptions): ListField;
|
|
160
|
-
export declare function BooleanListType(options
|
|
160
|
+
export declare function BooleanListType(options?: FieldOptions): ListField;
|
|
161
161
|
export declare function TimestampListType(options: TimestampOptions): ListField;
|
|
162
|
-
export declare function TimestamptzListType(options
|
|
163
|
-
export declare function TimeListType(options
|
|
162
|
+
export declare function TimestamptzListType(options?: TimestampOptions): ListField;
|
|
163
|
+
export declare function TimeListType(options?: TimeOptions): ListField;
|
|
164
164
|
export declare function TimetzListType(options: TimeOptions): ListField;
|
|
165
|
-
export declare function DateListType(options
|
|
165
|
+
export declare function DateListType(options?: FieldOptions): ListField;
|
|
166
166
|
export declare function EnumListType(options: EnumOptions): ListField;
|
|
167
|
-
export declare function UUIDListType(options
|
|
167
|
+
export declare function UUIDListType(options?: FieldOptions): ListField;
|
|
168
168
|
export {};
|