@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha75
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 +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +43 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +82 -3
- package/core/clause.js +463 -27
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +71 -27
- package/core/ent.js +458 -97
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -5
- package/core/loaders/object_loader.js +70 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- 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 +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- 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/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +101 -2
- package/schema/schema.js +127 -5
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- 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 +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- 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 +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -288
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 = exports.DenyIfViewerInboundEdgeDoesNotExistRule =
|
|
28
|
+
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.setGlobalSchema = 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 = exports.DenyIfViewerInboundEdgeDoesNotExistRule = 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; } });
|
|
@@ -59,10 +57,11 @@ Object.defineProperty(exports, "loadRawEdgeCountX", { enumerable: true, get: fun
|
|
|
59
57
|
Object.defineProperty(exports, "loadEdgeForID2", { enumerable: true, get: function () { return ent_1.loadEdgeForID2; } });
|
|
60
58
|
Object.defineProperty(exports, "loadNodesByEdge", { enumerable: true, get: function () { return ent_1.loadNodesByEdge; } });
|
|
61
59
|
Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: function () { return ent_1.getEdgeTypeInGroup; } });
|
|
60
|
+
Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return ent_1.setGlobalSchema; } });
|
|
62
61
|
const db_1 = __importDefault(require("./core/db"));
|
|
63
62
|
exports.DB = db_1.default;
|
|
64
63
|
__exportStar(require("./core/loaders"), exports);
|
|
65
|
-
// TODO figure out if this should be its own
|
|
64
|
+
// TODO figure out if this should be its own import path e.g. @snowtop/ent/privacy
|
|
66
65
|
var privacy_1 = require("./core/privacy");
|
|
67
66
|
Object.defineProperty(exports, "EntPrivacyError", { enumerable: true, get: function () { return privacy_1.EntPrivacyError; } });
|
|
68
67
|
Object.defineProperty(exports, "AlwaysAllowRule", { enumerable: true, get: function () { return privacy_1.AlwaysAllowRule; } });
|
|
@@ -109,12 +108,32 @@ const query = {
|
|
|
109
108
|
Eq: q.Eq,
|
|
110
109
|
NotEq: q.NotEq,
|
|
111
110
|
And: q.And,
|
|
111
|
+
AndOptional: q.AndOptional,
|
|
112
112
|
Or: q.Or,
|
|
113
113
|
In: q.In,
|
|
114
114
|
Greater: q.Greater,
|
|
115
115
|
Less: q.Less,
|
|
116
116
|
GreaterEq: q.GreaterEq,
|
|
117
117
|
LessEq: q.LessEq,
|
|
118
|
+
ArrayEq: q.ArrayEq,
|
|
119
|
+
ArrayNotEq: q.ArrayNotEq,
|
|
120
|
+
PostgresArrayContainsValue: q.PostgresArrayContainsValue,
|
|
121
|
+
PostgresArrayContains: q.PostgresArrayContains,
|
|
122
|
+
PostgresArrayNotContainsValue: q.PostgresArrayNotContainsValue,
|
|
123
|
+
PostgresArrayNotContains: q.PostgresArrayNotContains,
|
|
124
|
+
PostgresArrayOverlaps: q.PostgresArrayOverlaps,
|
|
125
|
+
PostgresArrayNotOverlaps: q.PostgresArrayNotOverlaps,
|
|
126
|
+
JSONPathValuePredicate: q.JSONPathValuePredicate,
|
|
127
|
+
JSONObjectFieldKeyASJSON: q.JSONObjectFieldKeyASJSON,
|
|
128
|
+
JSONObjectFieldKeyAsText: q.JSONObjectFieldKeyAsText,
|
|
129
|
+
TsQuery: q.TsQuery,
|
|
130
|
+
PlainToTsQuery: q.PlainToTsQuery,
|
|
131
|
+
PhraseToTsQuery: q.PhraseToTsQuery,
|
|
132
|
+
WebsearchToTsQuery: q.WebsearchToTsQuery,
|
|
133
|
+
TsVectorColTsQuery: q.TsVectorColTsQuery,
|
|
134
|
+
TsVectorPlainToTsQuery: q.TsVectorPlainToTsQuery,
|
|
135
|
+
TsVectorPhraseToTsQuery: q.TsVectorPhraseToTsQuery,
|
|
136
|
+
TsVectorWebsearchToTsQuery: q.TsVectorWebsearchToTsQuery,
|
|
118
137
|
};
|
|
119
138
|
exports.query = query;
|
|
120
139
|
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-alpha75",
|
|
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
|
-
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action
|
|
2
|
-
import { ActionField } from "../schema/schema";
|
|
1
|
+
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
2
|
+
import { ActionField, Type, GlobalSchema } from "../schema/schema";
|
|
3
3
|
declare enum NullableResult {
|
|
4
4
|
CONTENTS = "contents",
|
|
5
5
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
@@ -12,11 +12,19 @@ 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;
|
|
27
|
+
patternNames?: string[];
|
|
20
28
|
};
|
|
21
29
|
declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
22
30
|
edgeAction?: OutputAction;
|
|
@@ -31,17 +39,19 @@ interface ProcessedPattern {
|
|
|
31
39
|
name: string;
|
|
32
40
|
assocEdges: ProcessedAssocEdge[];
|
|
33
41
|
fields: ProcessedField[];
|
|
42
|
+
disableMixin?: boolean;
|
|
34
43
|
}
|
|
35
44
|
declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
|
|
36
45
|
subFields?: ProcessedField[];
|
|
37
46
|
listElemType?: ProcessedType;
|
|
38
47
|
unionFields?: ProcessedField[];
|
|
39
48
|
};
|
|
40
|
-
declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "type"> & {
|
|
49
|
+
declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
|
|
41
50
|
name: string;
|
|
42
51
|
hasDefaultValueOnCreate?: boolean;
|
|
43
52
|
hasDefaultValueOnEdit?: boolean;
|
|
44
53
|
patternName?: string;
|
|
54
|
+
hasFieldPrivacy?: boolean;
|
|
45
55
|
derivedFields?: ProcessedField[];
|
|
46
56
|
type: ProcessedType;
|
|
47
57
|
};
|
|
@@ -51,6 +61,15 @@ interface patternsDict {
|
|
|
51
61
|
interface Result {
|
|
52
62
|
schemas: schemasDict;
|
|
53
63
|
patterns: patternsDict;
|
|
64
|
+
globalSchema?: ProcessedGlobalSchema;
|
|
65
|
+
}
|
|
66
|
+
declare type PotentialSchemas = {
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
};
|
|
69
|
+
export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Result;
|
|
70
|
+
interface ProcessedGlobalSchema {
|
|
71
|
+
globalEdges: ProcessedAssocEdge[];
|
|
72
|
+
extraEdgeFields: ProcessedField[];
|
|
73
|
+
initForEdges?: boolean;
|
|
54
74
|
}
|
|
55
|
-
export declare function parseSchema(potentialSchemas: {}): Result;
|
|
56
75
|
export {};
|
package/parse_schema/parse.js
CHANGED
|
@@ -22,6 +22,7 @@ function processFields(src, patternName) {
|
|
|
22
22
|
let f = { name, ...field };
|
|
23
23
|
f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
|
|
24
24
|
f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
|
|
25
|
+
f.hasFieldPrivacy = field.privacyPolicy !== undefined;
|
|
25
26
|
if (field.polymorphic) {
|
|
26
27
|
// convert boolean into object
|
|
27
28
|
// we keep boolean as an option to keep API simple
|
|
@@ -35,6 +36,19 @@ function processFields(src, patternName) {
|
|
|
35
36
|
else {
|
|
36
37
|
delete f.polymorphic;
|
|
37
38
|
}
|
|
39
|
+
if (field.private) {
|
|
40
|
+
// convert boolean into object
|
|
41
|
+
// we keep boolean as an option to keep API simple
|
|
42
|
+
if (typeof field.private === "boolean") {
|
|
43
|
+
f.private = {};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
f.private = field.private;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
delete f.private;
|
|
51
|
+
}
|
|
38
52
|
// convert string to object to make API consumed by go simple
|
|
39
53
|
if (f.fieldEdge && f.fieldEdge.inverseEdge) {
|
|
40
54
|
if (typeof f.fieldEdge.inverseEdge === "string") {
|
|
@@ -46,6 +60,7 @@ function processFields(src, patternName) {
|
|
|
46
60
|
if (patternName) {
|
|
47
61
|
f.patternName = patternName;
|
|
48
62
|
}
|
|
63
|
+
transformType(field.type);
|
|
49
64
|
if (field.getDerivedFields) {
|
|
50
65
|
f.derivedFields = processFields(field.getDerivedFields(name));
|
|
51
66
|
}
|
|
@@ -65,6 +80,24 @@ function processFields(src, patternName) {
|
|
|
65
80
|
}
|
|
66
81
|
return ret;
|
|
67
82
|
}
|
|
83
|
+
function transformImportType(typ) {
|
|
84
|
+
if (!typ.importType) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
typ.importType = {
|
|
88
|
+
...typ.importType,
|
|
89
|
+
// these 2 needed for forwards compatibility with new go schema
|
|
90
|
+
importPath: typ.importType.path,
|
|
91
|
+
import: typ.importType.type,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function transformType(typ) {
|
|
95
|
+
if (!typ) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
transformImportType(typ);
|
|
99
|
+
transformType(typ.listElemType);
|
|
100
|
+
}
|
|
68
101
|
function processEdges(src, patternName) {
|
|
69
102
|
const ret = [];
|
|
70
103
|
for (const edge of src) {
|
|
@@ -89,6 +122,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
89
122
|
}
|
|
90
123
|
}
|
|
91
124
|
function processPattern(patterns, pattern, processedSchema) {
|
|
125
|
+
let ret = {
|
|
126
|
+
...pattern,
|
|
127
|
+
};
|
|
92
128
|
const name = pattern.name;
|
|
93
129
|
const fields = processFields(pattern.fields, pattern.name);
|
|
94
130
|
processedSchema.fields.push(...fields);
|
|
@@ -96,6 +132,10 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
96
132
|
const edges = processEdges(pattern.edges, pattern.name);
|
|
97
133
|
processedSchema.assocEdges.push(...edges);
|
|
98
134
|
}
|
|
135
|
+
// flag transformsSelect
|
|
136
|
+
if (pattern.transformRead) {
|
|
137
|
+
ret.transformsSelect = true;
|
|
138
|
+
}
|
|
99
139
|
if (patterns[name] === undefined) {
|
|
100
140
|
// intentionally processing separately and not passing pattern.name
|
|
101
141
|
const edges = processEdges(pattern.edges || []);
|
|
@@ -103,12 +143,14 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
103
143
|
name: pattern.name,
|
|
104
144
|
assocEdges: edges,
|
|
105
145
|
fields: fields,
|
|
146
|
+
disableMixin: pattern.disableMixin,
|
|
106
147
|
};
|
|
107
148
|
}
|
|
108
149
|
else {
|
|
109
150
|
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
110
151
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
111
152
|
}
|
|
153
|
+
return ret;
|
|
112
154
|
}
|
|
113
155
|
var NullableResult;
|
|
114
156
|
(function (NullableResult) {
|
|
@@ -143,20 +185,29 @@ function processAction(action) {
|
|
|
143
185
|
ret.actionOnlyFields = actionOnlyFields;
|
|
144
186
|
return ret;
|
|
145
187
|
}
|
|
146
|
-
function parseSchema(potentialSchemas) {
|
|
188
|
+
function parseSchema(potentialSchemas, globalSchema) {
|
|
147
189
|
let schemas = {};
|
|
148
190
|
let patterns = {};
|
|
191
|
+
let parsedGlobalSchema;
|
|
192
|
+
if (globalSchema) {
|
|
193
|
+
parsedGlobalSchema = parseGlobalSchema(globalSchema);
|
|
194
|
+
}
|
|
149
195
|
for (const key in potentialSchemas) {
|
|
150
196
|
const value = potentialSchemas[key];
|
|
151
197
|
let schema;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
198
|
+
const name = value.constructor.name;
|
|
199
|
+
// named class e.g. new BaseEntSchema
|
|
200
|
+
switch (name) {
|
|
201
|
+
case "Function":
|
|
202
|
+
schema = new value();
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
// implicit schema or named class
|
|
206
|
+
schema = value;
|
|
157
207
|
}
|
|
158
208
|
let processedSchema = {
|
|
159
209
|
fields: [],
|
|
210
|
+
schemaPath: schema.schemaPath,
|
|
160
211
|
tableName: schema.tableName,
|
|
161
212
|
enumTable: schema.enumTable,
|
|
162
213
|
dbRows: schema.dbRows,
|
|
@@ -169,13 +220,28 @@ function parseSchema(potentialSchemas) {
|
|
|
169
220
|
};
|
|
170
221
|
// let's put patterns first just so we have id, created_at, updated_at first
|
|
171
222
|
// ¯\_(ツ)_/¯
|
|
223
|
+
let patternNames = [];
|
|
172
224
|
if (schema.patterns) {
|
|
173
225
|
for (const pattern of schema.patterns) {
|
|
174
|
-
processPattern(patterns, pattern, processedSchema);
|
|
226
|
+
const ret = processPattern(patterns, pattern, processedSchema);
|
|
227
|
+
patternNames.push(pattern.name);
|
|
228
|
+
if (ret.transformsSelect) {
|
|
229
|
+
if (processedSchema.transformsSelect) {
|
|
230
|
+
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
231
|
+
}
|
|
232
|
+
processedSchema.transformsSelect = true;
|
|
233
|
+
}
|
|
234
|
+
if (ret.transformsDelete) {
|
|
235
|
+
if (processedSchema.transformsDelete) {
|
|
236
|
+
throw new Error(`can only have one pattern which transforms default deletion behavior`);
|
|
237
|
+
}
|
|
238
|
+
processedSchema.transformsDelete = true;
|
|
239
|
+
}
|
|
175
240
|
}
|
|
176
241
|
}
|
|
177
242
|
const fields = processFields(schema.fields);
|
|
178
243
|
processedSchema.fields.push(...fields);
|
|
244
|
+
processedSchema.patternNames = patternNames;
|
|
179
245
|
if (schema.edges) {
|
|
180
246
|
const edges = processEdges(schema.edges);
|
|
181
247
|
processedSchema.assocEdges.push(...edges);
|
|
@@ -185,6 +251,22 @@ function parseSchema(potentialSchemas) {
|
|
|
185
251
|
}
|
|
186
252
|
schemas[key] = processedSchema;
|
|
187
253
|
}
|
|
188
|
-
return { schemas, patterns };
|
|
254
|
+
return { schemas, patterns, globalSchema: parsedGlobalSchema };
|
|
189
255
|
}
|
|
190
256
|
exports.parseSchema = parseSchema;
|
|
257
|
+
function parseGlobalSchema(s) {
|
|
258
|
+
const ret = {
|
|
259
|
+
globalEdges: [],
|
|
260
|
+
extraEdgeFields: [],
|
|
261
|
+
initForEdges: !!s.extraEdgeFields ||
|
|
262
|
+
s.transformEdgeRead !== undefined ||
|
|
263
|
+
s.transformEdgeWrite !== undefined,
|
|
264
|
+
};
|
|
265
|
+
if (s.extraEdgeFields) {
|
|
266
|
+
ret.extraEdgeFields = processFields(s.extraEdgeFields);
|
|
267
|
+
}
|
|
268
|
+
if (s.edges) {
|
|
269
|
+
ret.globalEdges = processEdges(s.edges);
|
|
270
|
+
}
|
|
271
|
+
return ret;
|
|
272
|
+
}
|
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,6 +1,6 @@
|
|
|
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
6
|
let tsFields = {
|
|
@@ -66,9 +66,56 @@ let nodeFieldsWithTZ = {
|
|
|
66
66
|
exports.Node = {
|
|
67
67
|
name: "node",
|
|
68
68
|
fields: nodeFields,
|
|
69
|
+
disableMixin: true,
|
|
69
70
|
};
|
|
70
|
-
//
|
|
71
|
+
// Ent schema. has Node Pattern by default.
|
|
71
72
|
// exists just to have less typing and easier for clients to implement
|
|
73
|
+
class EntSchema {
|
|
74
|
+
constructor(cfg) {
|
|
75
|
+
this.patterns = [exports.Node];
|
|
76
|
+
this.fields = cfg.fields;
|
|
77
|
+
this.tableName = cfg.tableName;
|
|
78
|
+
if (cfg.patterns) {
|
|
79
|
+
this.patterns.push(...cfg.patterns);
|
|
80
|
+
}
|
|
81
|
+
this.edges = cfg.edges;
|
|
82
|
+
this.edgeGroups = cfg.edgeGroups;
|
|
83
|
+
this.actions = cfg.actions;
|
|
84
|
+
this.enumTable = cfg.enumTable;
|
|
85
|
+
this.dbRows = cfg.dbRows;
|
|
86
|
+
this.constraints = cfg.constraints;
|
|
87
|
+
this.indices = cfg.indices;
|
|
88
|
+
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.EntSchema = EntSchema;
|
|
92
|
+
class EntSchemaWithTZ {
|
|
93
|
+
constructor(cfg) {
|
|
94
|
+
this.patterns = [
|
|
95
|
+
{
|
|
96
|
+
// default schema added
|
|
97
|
+
name: "nodeWithTZ",
|
|
98
|
+
fields: nodeFieldsWithTZ,
|
|
99
|
+
disableMixin: true,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
this.fields = cfg.fields;
|
|
103
|
+
this.tableName = cfg.tableName;
|
|
104
|
+
if (cfg.patterns) {
|
|
105
|
+
this.patterns.push(...cfg.patterns);
|
|
106
|
+
}
|
|
107
|
+
this.edges = cfg.edges;
|
|
108
|
+
this.edgeGroups = cfg.edgeGroups;
|
|
109
|
+
this.actions = cfg.actions;
|
|
110
|
+
this.enumTable = cfg.enumTable;
|
|
111
|
+
this.dbRows = cfg.dbRows;
|
|
112
|
+
this.constraints = cfg.constraints;
|
|
113
|
+
this.indices = cfg.indices;
|
|
114
|
+
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.EntSchemaWithTZ = EntSchemaWithTZ;
|
|
118
|
+
// @deprecated use EntSchema
|
|
72
119
|
class BaseEntSchema {
|
|
73
120
|
constructor() {
|
|
74
121
|
this.patterns = [exports.Node];
|
|
@@ -78,6 +125,7 @@ class BaseEntSchema {
|
|
|
78
125
|
}
|
|
79
126
|
}
|
|
80
127
|
exports.BaseEntSchema = BaseEntSchema;
|
|
128
|
+
// @deprecated use EntSchemaWithTZ
|
|
81
129
|
class BaseEntSchemaWithTZ {
|
|
82
130
|
constructor() {
|
|
83
131
|
this.patterns = [
|
|
@@ -85,6 +133,7 @@ class BaseEntSchemaWithTZ {
|
|
|
85
133
|
// default schema added
|
|
86
134
|
name: "nodeWithTZ",
|
|
87
135
|
fields: nodeFieldsWithTZ,
|
|
136
|
+
disableMixin: true,
|
|
88
137
|
},
|
|
89
138
|
];
|
|
90
139
|
}
|
package/schema/field.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare function IntegerType(options?: IntegerOptions): IntegerField;
|
|
|
44
44
|
export declare class BigIntegerField extends BaseField implements Field {
|
|
45
45
|
type: Type;
|
|
46
46
|
}
|
|
47
|
-
export declare function BigIntegerType(options
|
|
47
|
+
export declare function BigIntegerType(options?: FieldOptions): BigIntegerField;
|
|
48
48
|
export declare class FloatField extends BaseField implements Field {
|
|
49
49
|
type: Type;
|
|
50
50
|
}
|
|
@@ -118,26 +118,53 @@ export declare class DateField extends BaseField implements Field {
|
|
|
118
118
|
format(val: any): any;
|
|
119
119
|
}
|
|
120
120
|
export declare function DateType(options?: FieldOptions): DateField;
|
|
121
|
-
declare type
|
|
121
|
+
declare type StringEnumMap = {
|
|
122
122
|
[key: string]: string;
|
|
123
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* @deprecated use StringEnumOptions
|
|
126
|
+
*/
|
|
124
127
|
export interface EnumOptions extends FieldOptions {
|
|
125
128
|
values?: string[];
|
|
126
|
-
map?:
|
|
129
|
+
map?: StringEnumMap;
|
|
127
130
|
tsType?: string;
|
|
128
131
|
graphQLType?: string;
|
|
129
132
|
createEnumType?: boolean;
|
|
130
133
|
}
|
|
134
|
+
export interface StringEnumOptions extends EnumOptions {
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use StringEnumField
|
|
138
|
+
*/
|
|
131
139
|
export declare class EnumField extends BaseField implements Field {
|
|
132
140
|
type: Type;
|
|
133
141
|
private values?;
|
|
134
142
|
private map?;
|
|
135
|
-
constructor(options:
|
|
143
|
+
constructor(options: StringEnumOptions);
|
|
136
144
|
convertForGQL(value: string): string;
|
|
137
145
|
valid(val: any): boolean;
|
|
138
146
|
format(val: any): any;
|
|
139
147
|
}
|
|
140
|
-
export declare
|
|
148
|
+
export declare class StringEnumField extends EnumField {
|
|
149
|
+
}
|
|
150
|
+
export declare function EnumType(options: StringEnumOptions): EnumField;
|
|
151
|
+
declare type IntEnumMap = {
|
|
152
|
+
[key: string]: number;
|
|
153
|
+
};
|
|
154
|
+
export interface IntegerEnumOptions extends FieldOptions {
|
|
155
|
+
map: IntEnumMap;
|
|
156
|
+
deprecated?: IntEnumMap;
|
|
157
|
+
tsType?: string;
|
|
158
|
+
graphQLType?: string;
|
|
159
|
+
}
|
|
160
|
+
export declare class IntegerEnumField extends BaseField implements Field {
|
|
161
|
+
type: Type;
|
|
162
|
+
private map;
|
|
163
|
+
constructor(options: IntegerEnumOptions);
|
|
164
|
+
valid(val: any): boolean;
|
|
165
|
+
format(val: any): any;
|
|
166
|
+
}
|
|
167
|
+
export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
|
|
141
168
|
export declare class ListField extends BaseField {
|
|
142
169
|
private field;
|
|
143
170
|
type: Type;
|
|
@@ -163,6 +190,7 @@ export declare function TimestamptzListType(options?: TimestampOptions): ListFie
|
|
|
163
190
|
export declare function TimeListType(options?: TimeOptions): ListField;
|
|
164
191
|
export declare function TimetzListType(options: TimeOptions): ListField;
|
|
165
192
|
export declare function DateListType(options?: FieldOptions): ListField;
|
|
166
|
-
export declare function EnumListType(options:
|
|
193
|
+
export declare function EnumListType(options: StringEnumOptions): ListField;
|
|
194
|
+
export declare function IntegerEnumListType(options: IntegerEnumOptions): ListField;
|
|
167
195
|
export declare function UUIDListType(options?: FieldOptions): ListField;
|
|
168
196
|
export {};
|
package/schema/field.js
CHANGED
|
@@ -19,12 +19,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.UUIDListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.EnumType = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
22
|
+
exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
23
23
|
const luxon_1 = require("luxon");
|
|
24
24
|
const snake_case_1 = require("snake-case");
|
|
25
25
|
const db_1 = __importStar(require("../core/db"));
|
|
26
26
|
const schema_1 = require("./schema");
|
|
27
27
|
const util_1 = require("util");
|
|
28
|
+
const uuid_1 = require("uuid");
|
|
28
29
|
class BaseField {
|
|
29
30
|
logValue(val) {
|
|
30
31
|
if (this.sensitive) {
|
|
@@ -92,6 +93,9 @@ class UUIDField extends BaseField {
|
|
|
92
93
|
return val.placeholderID !== undefined;
|
|
93
94
|
}
|
|
94
95
|
async valid(val) {
|
|
96
|
+
if (typeof val === "string" && !(0, uuid_1.validate)(val)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
95
99
|
if (!this.options?.fieldEdge?.enforceSchema) {
|
|
96
100
|
return true;
|
|
97
101
|
}
|
|
@@ -444,6 +448,9 @@ function DateType(options) {
|
|
|
444
448
|
return Object.assign(result, options);
|
|
445
449
|
}
|
|
446
450
|
exports.DateType = DateType;
|
|
451
|
+
/**
|
|
452
|
+
* @deprecated Use StringEnumField
|
|
453
|
+
*/
|
|
447
454
|
class EnumField extends BaseField {
|
|
448
455
|
constructor(options) {
|
|
449
456
|
super();
|
|
@@ -546,11 +553,57 @@ class EnumField extends BaseField {
|
|
|
546
553
|
}
|
|
547
554
|
}
|
|
548
555
|
exports.EnumField = EnumField;
|
|
556
|
+
class StringEnumField extends EnumField {
|
|
557
|
+
}
|
|
558
|
+
exports.StringEnumField = StringEnumField;
|
|
549
559
|
function EnumType(options) {
|
|
550
|
-
let result = new
|
|
560
|
+
let result = new StringEnumField(options);
|
|
551
561
|
return Object.assign(result, options);
|
|
552
562
|
}
|
|
553
563
|
exports.EnumType = EnumType;
|
|
564
|
+
class IntegerEnumField extends BaseField {
|
|
565
|
+
constructor(options) {
|
|
566
|
+
super();
|
|
567
|
+
this.type = {
|
|
568
|
+
dbType: schema_1.DBType.IntEnum,
|
|
569
|
+
intEnumMap: options.map,
|
|
570
|
+
type: options.tsType,
|
|
571
|
+
graphQLType: options.graphQLType,
|
|
572
|
+
deprecatedIntEnumMap: options.deprecated,
|
|
573
|
+
};
|
|
574
|
+
let count = 0;
|
|
575
|
+
for (const k in options.map) {
|
|
576
|
+
count++;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
if (!count) {
|
|
580
|
+
throw new Error("need at least one entry in enum map");
|
|
581
|
+
}
|
|
582
|
+
if (options.foreignKey) {
|
|
583
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
584
|
+
}
|
|
585
|
+
this.map = options.map;
|
|
586
|
+
}
|
|
587
|
+
valid(val) {
|
|
588
|
+
// lookup table enum and indicated via presence of foreignKey
|
|
589
|
+
for (const k in this.map) {
|
|
590
|
+
const v = this.map[k];
|
|
591
|
+
if (v === val || v === parseInt(val)) {
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
format(val) {
|
|
598
|
+
return parseInt(val);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
exports.IntegerEnumField = IntegerEnumField;
|
|
602
|
+
function IntegerEnumType(options) {
|
|
603
|
+
let result = new IntegerEnumField(options);
|
|
604
|
+
return Object.assign(result, options);
|
|
605
|
+
}
|
|
606
|
+
exports.IntegerEnumType = IntegerEnumType;
|
|
554
607
|
class ListField extends BaseField {
|
|
555
608
|
constructor(field, options) {
|
|
556
609
|
super();
|
|
@@ -593,6 +646,10 @@ class ListField extends BaseField {
|
|
|
593
646
|
}
|
|
594
647
|
postgresVal(val, jsonType) {
|
|
595
648
|
if (!jsonType) {
|
|
649
|
+
// support empty strings in list
|
|
650
|
+
if (val === "") {
|
|
651
|
+
val = '"' + val + '"';
|
|
652
|
+
}
|
|
596
653
|
return val;
|
|
597
654
|
}
|
|
598
655
|
return JSON.stringify(val);
|
|
@@ -720,6 +777,14 @@ function EnumListType(options) {
|
|
|
720
777
|
return new ListField(EnumType(options), options);
|
|
721
778
|
}
|
|
722
779
|
exports.EnumListType = EnumListType;
|
|
780
|
+
function IntegerEnumListType(options) {
|
|
781
|
+
// not all of these will make sense in a list...
|
|
782
|
+
// can make it work eventually but involves work we're not currently trying to do
|
|
783
|
+
// developer can try to work around it by calling below on their own.
|
|
784
|
+
// unclear what the behavior is
|
|
785
|
+
return new ListField(IntegerEnumType(options), options);
|
|
786
|
+
}
|
|
787
|
+
exports.IntegerEnumListType = IntegerEnumListType;
|
|
723
788
|
function UUIDListType(options) {
|
|
724
789
|
return new ListField(UUIDType(options), options);
|
|
725
790
|
}
|
package/schema/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Schema from "./schema";
|
|
2
2
|
export { Schema };
|
|
3
|
-
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
|
|
4
|
-
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_schema";
|
|
3
|
+
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, EdgeUpdateOperation, TransformedEdgeUpdateOperation, getTransformedReadClause, getObjectLoaderProperties, GlobalSchema, } from "./schema";
|
|
4
|
+
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, SchemaConfig, } from "./base_schema";
|
|
5
5
|
export * from "./field";
|
|
6
6
|
export * from "./json_field";
|
|
7
7
|
export * from "./struct_field";
|