@snowtop/ent 0.0.2 → 0.0.3-5.alpha.2
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 +6 -6
- package/action/action.js +2 -2
- package/action/executor.d.ts +7 -12
- package/action/executor.js +39 -33
- package/action/experimental_action.d.ts +4 -2
- package/action/experimental_action.js +27 -2
- package/action/index.d.ts +1 -1
- package/action/orchestrator.d.ts +14 -6
- package/action/orchestrator.js +188 -99
- package/action/privacy.js +4 -4
- package/auth/auth.js +2 -2
- package/core/base.d.ts +6 -0
- package/core/base.js +12 -9
- package/core/clause.d.ts +1 -0
- package/core/clause.js +6 -2
- package/core/config.d.ts +20 -0
- package/core/config.js +2 -2
- package/core/context.js +3 -3
- package/core/convert.d.ts +4 -0
- package/core/convert.js +25 -2
- package/core/db.d.ts +18 -1
- package/core/db.js +4 -7
- package/core/ent.d.ts +17 -10
- package/core/ent.js +38 -15
- package/core/loaders/assoc_count_loader.js +5 -5
- package/core/loaders/assoc_edge_loader.js +10 -10
- package/core/loaders/loader.js +3 -3
- package/core/loaders/object_loader.js +6 -6
- package/core/loaders/query_loader.js +7 -7
- package/core/loaders/raw_count_loader.js +4 -4
- package/core/logger.js +2 -2
- package/core/privacy.d.ts +21 -1
- package/core/privacy.js +91 -47
- package/core/query/assoc_query.d.ts +12 -12
- package/core/query/assoc_query.js +86 -51
- package/core/query/custom_query.d.ts +10 -7
- package/core/query/custom_query.js +29 -3
- package/core/query/query.d.ts +24 -8
- package/core/query/query.js +41 -4
- package/core/query/shared_assoc_test.js +257 -13
- package/core/query/shared_test.d.ts +1 -1
- package/core/query/shared_test.js +11 -11
- package/core/viewer.js +1 -0
- package/graphql/builtins/connection.js +4 -3
- package/graphql/builtins/edge.js +3 -2
- package/graphql/builtins/node.js +2 -1
- package/graphql/graphql.d.ts +2 -0
- package/graphql/graphql.js +83 -61
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +2 -1
- package/graphql/node_resolver.d.ts +1 -0
- package/graphql/node_resolver.js +14 -1
- package/graphql/query/connection_type.d.ts +5 -4
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +7 -7
- package/graphql/query/page_info.js +5 -4
- package/graphql/query/shared_assoc_test.js +9 -9
- package/graphql/query/shared_edge_connection.d.ts +1 -1
- package/graphql/query/shared_edge_connection.js +4 -4
- package/graphql/scalars/time.js +1 -1
- package/imports/dataz/example1/_auth.js +8 -8
- package/imports/dataz/example1/_viewer.js +4 -4
- package/imports/index.d.ts +1 -1
- package/imports/index.js +3 -5
- package/index.d.ts +2 -1
- package/index.js +6 -2
- package/package.json +17 -10
- package/parse_schema/parse.d.ts +48 -0
- package/parse_schema/parse.js +160 -0
- package/schema/base_schema.d.ts +2 -0
- package/schema/base_schema.js +17 -7
- package/schema/field.d.ts +52 -15
- package/schema/field.js +234 -47
- package/schema/index.d.ts +1 -0
- package/schema/index.js +1 -0
- package/schema/json_field.d.ts +17 -0
- package/schema/json_field.js +48 -0
- package/schema/schema.d.ts +39 -4
- package/schema/schema.js +2 -0
- package/scripts/custom_compiler.js +8 -10
- package/scripts/custom_graphql.js +45 -10
- package/scripts/read_schema.js +6 -108
- package/testutils/builder.d.ts +6 -3
- package/testutils/builder.js +31 -15
- package/testutils/db/test_db.d.ts +16 -8
- package/testutils/db/test_db.js +65 -9
- package/testutils/db_mock.js +5 -5
- package/testutils/ent-graphql-tests/index.d.ts +1 -0
- package/testutils/ent-graphql-tests/index.js +13 -13
- package/testutils/fake_comms.d.ts +1 -0
- package/testutils/fake_comms.js +4 -0
- package/testutils/fake_data/const.d.ts +5 -1
- package/testutils/fake_data/const.js +19 -1
- package/testutils/fake_data/events_query.d.ts +16 -11
- package/testutils/fake_data/events_query.js +15 -0
- package/testutils/fake_data/fake_contact.js +9 -9
- package/testutils/fake_data/fake_event.js +14 -14
- package/testutils/fake_data/fake_user.js +12 -10
- package/testutils/fake_data/test_helpers.d.ts +5 -1
- package/testutils/fake_data/test_helpers.js +49 -16
- package/testutils/fake_data/user_query.d.ts +25 -9
- package/testutils/fake_data/user_query.js +52 -5
- package/testutils/parse_sql.js +19 -3
- package/testutils/write.js +6 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.0.2",
|
|
3
|
+
"version": "0.0.35.alpha.2",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@types/node": "^15.0.2",
|
|
12
|
-
"
|
|
12
|
+
"camel-case": "^4.1.2",
|
|
13
13
|
"dataloader": "^2.0.0",
|
|
14
14
|
"glob": "^7.1.6",
|
|
15
15
|
"graph-data-structure": "^1.12.0",
|
|
@@ -20,16 +20,26 @@
|
|
|
20
20
|
"minimist": "^1.2.5",
|
|
21
21
|
"pascal-case": "^3.1.2",
|
|
22
22
|
"pg": "^8.0.3",
|
|
23
|
-
"prettier": "^2.3.
|
|
23
|
+
"prettier": "^2.3.2",
|
|
24
24
|
"reflect-metadata": "^0.1.13",
|
|
25
25
|
"snake-case": "^3.0.3",
|
|
26
|
-
"ts-node": "^
|
|
27
|
-
"tsconfig-paths": "^3.
|
|
28
|
-
"
|
|
26
|
+
"ts-node": "^10.2.1",
|
|
27
|
+
"tsconfig-paths": "^3.11.0",
|
|
28
|
+
"tslib": "^2.3.1",
|
|
29
|
+
"typescript": "^4.4.2",
|
|
29
30
|
"uuid": "^8.3.2"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"
|
|
33
|
+
"better-sqlite3": "^7.4.1",
|
|
34
|
+
"graphql": "^15.5"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"better-sqlite3": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=14.0"
|
|
33
43
|
},
|
|
34
44
|
"devDependencies": {},
|
|
35
45
|
"scripts": {},
|
|
@@ -43,9 +53,6 @@
|
|
|
43
53
|
"type": "git",
|
|
44
54
|
"url": "git+ssh://git@github.com/lolopinto/ent.git"
|
|
45
55
|
},
|
|
46
|
-
"resolutions": {
|
|
47
|
-
"graphql": "^15.3.0"
|
|
48
|
-
},
|
|
49
56
|
"bugs": {
|
|
50
57
|
"url": "https://github.com/lolopinto/ent/issues"
|
|
51
58
|
},
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
2
|
+
import { ActionField } from "../schema/schema";
|
|
3
|
+
declare enum NullableResult {
|
|
4
|
+
CONTENTS = "contents",
|
|
5
|
+
CONTENTS_AND_LIST = "contentsAndList",
|
|
6
|
+
ITEM = "true"
|
|
7
|
+
}
|
|
8
|
+
declare type ProcessedActionField = Omit<ActionField, "nullable"> & {
|
|
9
|
+
nullable?: NullableResult;
|
|
10
|
+
};
|
|
11
|
+
declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActions"> & {
|
|
12
|
+
patternName?: string;
|
|
13
|
+
edgeActions?: OutputAction[];
|
|
14
|
+
};
|
|
15
|
+
declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & {
|
|
16
|
+
actions: OutputAction[];
|
|
17
|
+
assocEdges: ProcessedAssocEdge[];
|
|
18
|
+
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
|
19
|
+
fields: ProcessedField[];
|
|
20
|
+
};
|
|
21
|
+
declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
22
|
+
edgeAction?: OutputAction;
|
|
23
|
+
};
|
|
24
|
+
declare type OutputAction = Omit<Action, "actionOnlyFields"> & {
|
|
25
|
+
actionOnlyFields?: ProcessedActionField[];
|
|
26
|
+
};
|
|
27
|
+
interface schemasDict {
|
|
28
|
+
[key: string]: ProcessedSchema;
|
|
29
|
+
}
|
|
30
|
+
interface ProcessedPattern {
|
|
31
|
+
name: string;
|
|
32
|
+
assocEdges: ProcessedAssocEdge[];
|
|
33
|
+
fields: ProcessedField[];
|
|
34
|
+
}
|
|
35
|
+
declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate"> & {
|
|
36
|
+
hasDefaultValueOnCreate?: boolean;
|
|
37
|
+
hasDefaultValueOnEdit?: boolean;
|
|
38
|
+
patternName?: string;
|
|
39
|
+
};
|
|
40
|
+
interface patternsDict {
|
|
41
|
+
[key: string]: ProcessedPattern;
|
|
42
|
+
}
|
|
43
|
+
interface Result {
|
|
44
|
+
schemas: schemasDict;
|
|
45
|
+
patterns: patternsDict;
|
|
46
|
+
}
|
|
47
|
+
export declare function parseSchema(potentialSchemas: {}): Result;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSchema = void 0;
|
|
4
|
+
function processFields(src, patternName) {
|
|
5
|
+
const ret = [];
|
|
6
|
+
for (const field of src) {
|
|
7
|
+
let f = { ...field };
|
|
8
|
+
f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
|
|
9
|
+
f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
|
|
10
|
+
if (field.polymorphic) {
|
|
11
|
+
// convert boolean into object
|
|
12
|
+
// we keep boolean as an option to keep API simple
|
|
13
|
+
if (typeof field.polymorphic === "boolean") {
|
|
14
|
+
f.polymorphic = {};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
f.polymorphic = field.polymorphic;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
delete f.polymorphic;
|
|
22
|
+
}
|
|
23
|
+
// convert string to object to make API consumed by go simple
|
|
24
|
+
if (f.fieldEdge && f.fieldEdge.inverseEdge) {
|
|
25
|
+
if (typeof f.fieldEdge.inverseEdge === "string") {
|
|
26
|
+
f.fieldEdge.inverseEdge = {
|
|
27
|
+
name: f.fieldEdge.inverseEdge,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (patternName) {
|
|
32
|
+
f.patternName = patternName;
|
|
33
|
+
}
|
|
34
|
+
ret.push(f);
|
|
35
|
+
}
|
|
36
|
+
return ret;
|
|
37
|
+
}
|
|
38
|
+
function processEdges(src, patternName) {
|
|
39
|
+
const ret = [];
|
|
40
|
+
for (const edge of src) {
|
|
41
|
+
let edge2 = { ...edge };
|
|
42
|
+
edge2.edgeActions = edge.edgeActions?.map((action) => processAction(action));
|
|
43
|
+
edge2.patternName = patternName;
|
|
44
|
+
ret.push(edge2);
|
|
45
|
+
}
|
|
46
|
+
return ret;
|
|
47
|
+
}
|
|
48
|
+
function processEdgeGroups(processedSchema, edgeGroups) {
|
|
49
|
+
// array-ify this
|
|
50
|
+
for (const group of edgeGroups) {
|
|
51
|
+
if (group.nullStates && !Array.isArray(group.nullStates)) {
|
|
52
|
+
group.nullStates = [group.nullStates];
|
|
53
|
+
}
|
|
54
|
+
let group2 = { ...group };
|
|
55
|
+
if (group.edgeAction) {
|
|
56
|
+
group2.edgeAction = processAction(group.edgeAction);
|
|
57
|
+
}
|
|
58
|
+
processedSchema.assocEdgeGroups.push(group2);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function processPattern(patterns, pattern, processedSchema) {
|
|
62
|
+
const name = pattern.name;
|
|
63
|
+
const fields = processFields(pattern.fields, pattern.name);
|
|
64
|
+
processedSchema.fields.push(...fields);
|
|
65
|
+
if (pattern.edges) {
|
|
66
|
+
const edges = processEdges(pattern.edges, pattern.name);
|
|
67
|
+
processedSchema.assocEdges.push(...edges);
|
|
68
|
+
}
|
|
69
|
+
if (patterns[name] === undefined) {
|
|
70
|
+
// intentionally processing separately and not passing pattern.name
|
|
71
|
+
const edges = processEdges(pattern.edges || []);
|
|
72
|
+
patterns[name] = {
|
|
73
|
+
name: pattern.name,
|
|
74
|
+
assocEdges: edges,
|
|
75
|
+
fields: fields,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
80
|
+
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
var NullableResult;
|
|
84
|
+
(function (NullableResult) {
|
|
85
|
+
NullableResult["CONTENTS"] = "contents";
|
|
86
|
+
NullableResult["CONTENTS_AND_LIST"] = "contentsAndList";
|
|
87
|
+
NullableResult["ITEM"] = "true";
|
|
88
|
+
})(NullableResult || (NullableResult = {}));
|
|
89
|
+
function processAction(action) {
|
|
90
|
+
if (!action.actionOnlyFields) {
|
|
91
|
+
return { ...action };
|
|
92
|
+
}
|
|
93
|
+
let ret = { ...action };
|
|
94
|
+
let actionOnlyFields = action.actionOnlyFields.map((f) => {
|
|
95
|
+
let f2 = f;
|
|
96
|
+
if (!f.nullable) {
|
|
97
|
+
delete f2.nullable;
|
|
98
|
+
return f2;
|
|
99
|
+
}
|
|
100
|
+
if (typeof f.nullable === "boolean") {
|
|
101
|
+
f2.nullable = NullableResult.ITEM;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (f.nullable === "contentsAndList") {
|
|
105
|
+
f2.nullable = NullableResult.CONTENTS_AND_LIST;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
f2.nullable = NullableResult.CONTENTS;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return f2;
|
|
112
|
+
});
|
|
113
|
+
ret.actionOnlyFields = actionOnlyFields;
|
|
114
|
+
return ret;
|
|
115
|
+
}
|
|
116
|
+
function parseSchema(potentialSchemas) {
|
|
117
|
+
let schemas = {};
|
|
118
|
+
let patterns = {};
|
|
119
|
+
for (const key in potentialSchemas) {
|
|
120
|
+
const value = potentialSchemas[key];
|
|
121
|
+
let schema;
|
|
122
|
+
if (value.constructor == Object) {
|
|
123
|
+
schema = value;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
schema = new value();
|
|
127
|
+
}
|
|
128
|
+
let processedSchema = {
|
|
129
|
+
fields: [],
|
|
130
|
+
tableName: schema.tableName,
|
|
131
|
+
enumTable: schema.enumTable,
|
|
132
|
+
dbRows: schema.dbRows,
|
|
133
|
+
constraints: schema.constraints,
|
|
134
|
+
indices: schema.indices,
|
|
135
|
+
hideFromGraphQL: schema.hideFromGraphQL,
|
|
136
|
+
actions: schema.actions?.map((action) => processAction(action)) || [],
|
|
137
|
+
assocEdges: [],
|
|
138
|
+
assocEdgeGroups: [],
|
|
139
|
+
};
|
|
140
|
+
// let's put patterns first just so we have id, created_at, updated_at first
|
|
141
|
+
// ¯\_(ツ)_/¯
|
|
142
|
+
if (schema.patterns) {
|
|
143
|
+
for (const pattern of schema.patterns) {
|
|
144
|
+
processPattern(patterns, pattern, processedSchema);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const fields = processFields(schema.fields);
|
|
148
|
+
processedSchema.fields.push(...fields);
|
|
149
|
+
if (schema.edges) {
|
|
150
|
+
const edges = processEdges(schema.edges);
|
|
151
|
+
processedSchema.assocEdges.push(...edges);
|
|
152
|
+
}
|
|
153
|
+
if (schema.edgeGroups) {
|
|
154
|
+
processEdgeGroups(processedSchema, schema.edgeGroups);
|
|
155
|
+
}
|
|
156
|
+
schemas[key] = processedSchema;
|
|
157
|
+
}
|
|
158
|
+
return { schemas, patterns };
|
|
159
|
+
}
|
|
160
|
+
exports.parseSchema = parseSchema;
|
package/schema/base_schema.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ import { Pattern } from "./schema";
|
|
|
2
2
|
export declare const Timestamps: Pattern;
|
|
3
3
|
export declare const Node: Pattern;
|
|
4
4
|
export declare abstract class BaseEntSchema {
|
|
5
|
+
addPatterns(...patterns: Pattern[]): void;
|
|
5
6
|
patterns: Pattern[];
|
|
6
7
|
}
|
|
7
8
|
export declare abstract class BaseEntSchemaWithTZ {
|
|
9
|
+
addPatterns(...patterns: Pattern[]): void;
|
|
8
10
|
patterns: Pattern[];
|
|
9
11
|
}
|
package/schema/base_schema.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Tim
|
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
6
|
let tsFields = [
|
|
7
|
-
field_1.TimestampType({
|
|
7
|
+
(0, field_1.TimestampType)({
|
|
8
8
|
name: "createdAt",
|
|
9
9
|
hideFromGraphQL: true,
|
|
10
10
|
disableUserEditable: true,
|
|
@@ -12,7 +12,7 @@ let tsFields = [
|
|
|
12
12
|
return new Date();
|
|
13
13
|
},
|
|
14
14
|
}),
|
|
15
|
-
field_1.TimestampType({
|
|
15
|
+
(0, field_1.TimestampType)({
|
|
16
16
|
name: "updatedAt",
|
|
17
17
|
hideFromGraphQL: true,
|
|
18
18
|
disableUserEditable: true,
|
|
@@ -26,20 +26,21 @@ let tsFields = [
|
|
|
26
26
|
];
|
|
27
27
|
// Timestamps is a Pattern that adds a createdAt and updatedAt timestamp fields to the ent
|
|
28
28
|
exports.Timestamps = {
|
|
29
|
+
name: "timestamps",
|
|
29
30
|
fields: tsFields,
|
|
30
31
|
};
|
|
31
|
-
let nodeField = field_1.UUIDType({
|
|
32
|
+
let nodeField = (0, field_1.UUIDType)({
|
|
32
33
|
name: "ID",
|
|
33
34
|
primaryKey: true,
|
|
34
35
|
disableUserEditable: true,
|
|
35
36
|
defaultValueOnCreate: () => {
|
|
36
|
-
return uuid_1.v4();
|
|
37
|
+
return (0, uuid_1.v4)();
|
|
37
38
|
},
|
|
38
39
|
});
|
|
39
|
-
let nodeFields = [nodeField]
|
|
40
|
+
let nodeFields = [nodeField, ...tsFields];
|
|
40
41
|
let nodeFieldsWithTZ = [
|
|
41
42
|
nodeField,
|
|
42
|
-
field_1.TimestampType({
|
|
43
|
+
(0, field_1.TimestampType)({
|
|
43
44
|
name: "createdAt",
|
|
44
45
|
hideFromGraphQL: true,
|
|
45
46
|
disableUserEditable: true,
|
|
@@ -48,7 +49,7 @@ let nodeFieldsWithTZ = [
|
|
|
48
49
|
},
|
|
49
50
|
withTimezone: true,
|
|
50
51
|
}),
|
|
51
|
-
field_1.TimestampType({
|
|
52
|
+
(0, field_1.TimestampType)({
|
|
52
53
|
name: "updatedAt",
|
|
53
54
|
hideFromGraphQL: true,
|
|
54
55
|
disableUserEditable: true,
|
|
@@ -63,6 +64,7 @@ let nodeFieldsWithTZ = [
|
|
|
63
64
|
];
|
|
64
65
|
// Node is a Pattern that adds 3 fields to the ent: (id, createdAt, and updatedAt timestamps)
|
|
65
66
|
exports.Node = {
|
|
67
|
+
name: "node",
|
|
66
68
|
fields: nodeFields,
|
|
67
69
|
};
|
|
68
70
|
// Base ent schema. has Node Pattern by default.
|
|
@@ -71,15 +73,23 @@ class BaseEntSchema {
|
|
|
71
73
|
constructor() {
|
|
72
74
|
this.patterns = [exports.Node];
|
|
73
75
|
}
|
|
76
|
+
addPatterns(...patterns) {
|
|
77
|
+
this.patterns.push(...patterns);
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
exports.BaseEntSchema = BaseEntSchema;
|
|
76
81
|
class BaseEntSchemaWithTZ {
|
|
77
82
|
constructor() {
|
|
78
83
|
this.patterns = [
|
|
79
84
|
{
|
|
85
|
+
// default schema added
|
|
86
|
+
name: "nodeWithTZ",
|
|
80
87
|
fields: nodeFieldsWithTZ,
|
|
81
88
|
},
|
|
82
89
|
];
|
|
83
90
|
}
|
|
91
|
+
addPatterns(...patterns) {
|
|
92
|
+
this.patterns.push(...patterns);
|
|
93
|
+
}
|
|
84
94
|
}
|
|
85
95
|
exports.BaseEntSchemaWithTZ = BaseEntSchemaWithTZ;
|
package/schema/field.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Field, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
|
|
2
2
|
export declare abstract class BaseField {
|
|
3
3
|
name: string;
|
|
4
4
|
nullable?: boolean;
|
|
@@ -17,14 +17,34 @@ export declare abstract class BaseField {
|
|
|
17
17
|
logValue(val: any): any;
|
|
18
18
|
}
|
|
19
19
|
export declare class UUIDField extends BaseField implements Field {
|
|
20
|
+
private options;
|
|
20
21
|
type: Type;
|
|
21
22
|
constructor(options: FieldOptions);
|
|
23
|
+
private isBuilder;
|
|
24
|
+
valid(val: any): Promise<boolean>;
|
|
22
25
|
}
|
|
23
26
|
export declare function UUIDType(options: FieldOptions): UUIDField;
|
|
27
|
+
export interface IntegerOptions extends FieldOptions {
|
|
28
|
+
min?: number;
|
|
29
|
+
max?: number;
|
|
30
|
+
}
|
|
24
31
|
export declare class IntegerField extends BaseField implements Field {
|
|
25
32
|
type: Type;
|
|
33
|
+
private validators;
|
|
34
|
+
private options;
|
|
35
|
+
constructor(options?: IntegerOptions);
|
|
36
|
+
getOptions(): IntegerOptions;
|
|
37
|
+
private handleOptions;
|
|
38
|
+
min(l: number): this;
|
|
39
|
+
max(l: number): this;
|
|
40
|
+
valid(val: any): boolean;
|
|
41
|
+
validate(validator: (str: number) => boolean): this;
|
|
42
|
+
}
|
|
43
|
+
export declare function IntegerType(options: IntegerOptions): IntegerField;
|
|
44
|
+
export declare class BigIntegerField extends BaseField implements Field {
|
|
45
|
+
type: Type;
|
|
26
46
|
}
|
|
27
|
-
export declare function
|
|
47
|
+
export declare function BigIntegerType(options: FieldOptions): BigIntegerField;
|
|
28
48
|
export declare class FloatField extends BaseField implements Field {
|
|
29
49
|
type: Type;
|
|
30
50
|
}
|
|
@@ -49,23 +69,24 @@ export declare class StringField extends BaseField implements Field {
|
|
|
49
69
|
type: Type;
|
|
50
70
|
private validators;
|
|
51
71
|
private formatters;
|
|
72
|
+
private options;
|
|
52
73
|
constructor(options?: StringOptions);
|
|
53
74
|
getOptions(): StringOptions;
|
|
54
75
|
private handleOptions;
|
|
55
|
-
minLen(l: number):
|
|
56
|
-
maxLen(l: number):
|
|
57
|
-
length(l: number):
|
|
76
|
+
minLen(l: number): this;
|
|
77
|
+
maxLen(l: number): this;
|
|
78
|
+
length(l: number): this;
|
|
58
79
|
valid(val: any): boolean;
|
|
59
80
|
format(val: any): any;
|
|
60
|
-
validate(validator: (str: string) => boolean):
|
|
61
|
-
formatter(formatter: (str: string) => string):
|
|
62
|
-
match(pattern: string | RegExp):
|
|
63
|
-
doesNotMatch(pattern: string | RegExp):
|
|
64
|
-
toLowerCase():
|
|
65
|
-
toUpperCase():
|
|
66
|
-
trim():
|
|
67
|
-
trimLeft():
|
|
68
|
-
trimRight():
|
|
81
|
+
validate(validator: (str: string) => boolean): this;
|
|
82
|
+
formatter(formatter: (str: string) => string): this;
|
|
83
|
+
match(pattern: string | RegExp): this;
|
|
84
|
+
doesNotMatch(pattern: string | RegExp): this;
|
|
85
|
+
toLowerCase(): this;
|
|
86
|
+
toUpperCase(): this;
|
|
87
|
+
trim(): this;
|
|
88
|
+
trimLeft(): this;
|
|
89
|
+
trimRight(): this;
|
|
69
90
|
}
|
|
70
91
|
export declare function StringType(options: StringOptions): StringField;
|
|
71
92
|
export interface TimestampOptions extends FieldOptions {
|
|
@@ -97,8 +118,12 @@ export declare class DateField extends BaseField implements Field {
|
|
|
97
118
|
format(val: any): any;
|
|
98
119
|
}
|
|
99
120
|
export declare function DateType(options: FieldOptions): DateField;
|
|
121
|
+
declare type EnumMap = {
|
|
122
|
+
[key: string]: string;
|
|
123
|
+
};
|
|
100
124
|
export interface EnumOptions extends FieldOptions {
|
|
101
125
|
values?: string[];
|
|
126
|
+
map?: EnumMap;
|
|
102
127
|
tsType?: string;
|
|
103
128
|
graphQLType?: string;
|
|
104
129
|
createEnumType?: boolean;
|
|
@@ -106,6 +131,7 @@ export interface EnumOptions extends FieldOptions {
|
|
|
106
131
|
export declare class EnumField extends BaseField implements Field {
|
|
107
132
|
type: Type;
|
|
108
133
|
private values?;
|
|
134
|
+
private map?;
|
|
109
135
|
constructor(options: EnumOptions);
|
|
110
136
|
convertForGQL(value: string): string;
|
|
111
137
|
valid(val: any): boolean;
|
|
@@ -115,13 +141,22 @@ export declare function EnumType(options: EnumOptions): EnumField;
|
|
|
115
141
|
export declare class ListField extends BaseField {
|
|
116
142
|
private field;
|
|
117
143
|
type: Type;
|
|
144
|
+
private validators;
|
|
118
145
|
constructor(field: Field, options: FieldOptions);
|
|
119
|
-
|
|
146
|
+
validate(validator: (val: any[]) => boolean): this;
|
|
147
|
+
valid(val: any): Promise<boolean>;
|
|
148
|
+
private postgresVal;
|
|
120
149
|
format(val: any): any;
|
|
150
|
+
minLen(l: number): this;
|
|
151
|
+
maxLen(l: number): this;
|
|
152
|
+
length(l: number): this;
|
|
153
|
+
range(start: any, stop: any): this;
|
|
121
154
|
}
|
|
122
155
|
export declare function StringListType(options: StringOptions): ListField;
|
|
123
156
|
export declare function IntListType(options: FieldOptions): ListField;
|
|
157
|
+
export declare function IntegerListType(options: FieldOptions): ListField;
|
|
124
158
|
export declare function FloatListType(options: FieldOptions): ListField;
|
|
159
|
+
export declare function BigIntegerListType(options: FieldOptions): ListField;
|
|
125
160
|
export declare function BooleanListType(options: FieldOptions): ListField;
|
|
126
161
|
export declare function TimestampListType(options: TimestampOptions): ListField;
|
|
127
162
|
export declare function TimestamptzListType(options: TimestampOptions): ListField;
|
|
@@ -129,3 +164,5 @@ export declare function TimeListType(options: TimeOptions): ListField;
|
|
|
129
164
|
export declare function TimetzListType(options: TimeOptions): ListField;
|
|
130
165
|
export declare function DateListType(options: FieldOptions): ListField;
|
|
131
166
|
export declare function EnumListType(options: EnumOptions): ListField;
|
|
167
|
+
export declare function UUIDListType(options: FieldOptions): ListField;
|
|
168
|
+
export {};
|