@snowtop/ent 0.1.0-alpha96-2a5ea200-82e5-11ed-8c55-4da1cd949242 → 0.1.0-alpha97
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 +3 -3
- package/action/executor.js +6 -1
- package/action/experimental_action.d.ts +5 -2
- package/action/experimental_action.js +15 -12
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +4 -2
- package/action/orchestrator.js +6 -0
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +4 -2
- package/core/clause.d.ts +6 -1
- package/core/clause.js +25 -4
- package/core/config.d.ts +2 -1
- package/core/config.js +2 -0
- package/core/date.js +1 -5
- package/core/db.d.ts +9 -6
- package/core/db.js +14 -6
- package/core/ent.d.ts +3 -1
- package/core/ent.js +76 -26
- package/core/logger.d.ts +1 -1
- package/core/query/assoc_query.d.ts +2 -2
- package/core/query/shared_assoc_test.js +1 -2
- package/core/query/shared_test.js +0 -1
- package/graphql/graphql.d.ts +6 -6
- package/graphql/graphql.js +1 -0
- package/graphql/query/connection_type.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +0 -4
- package/imports/index.d.ts +6 -1
- package/imports/index.js +14 -3
- package/index.d.ts +1 -0
- package/package.json +16 -16
- package/parse_schema/parse.d.ts +7 -7
- package/schema/base_schema.d.ts +3 -3
- package/schema/field.d.ts +17 -12
- package/schema/field.js +18 -8
- package/schema/schema.d.ts +10 -10
- package/schema/schema.js +0 -16
- package/scripts/custom_graphql.js +30 -4
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +21 -36
- package/testutils/builder.js +39 -45
- package/testutils/db/temp_db.d.ts +6 -3
- package/testutils/db/temp_db.js +79 -7
- package/testutils/db/value.d.ts +1 -0
- package/testutils/db/value.js +2 -2
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +48 -5
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +17 -5
- package/testutils/fake_data/fake_contact.d.ts +1 -0
- package/testutils/fake_data/fake_contact.js +6 -5
- package/testutils/fake_data/fake_event.d.ts +1 -0
- package/testutils/fake_data/fake_event.js +4 -3
- package/testutils/fake_data/fake_tag.d.ts +2 -1
- package/testutils/fake_data/fake_tag.js +6 -5
- package/testutils/fake_data/fake_user.d.ts +2 -1
- package/testutils/fake_data/fake_user.js +14 -13
- package/tsc/ast.d.ts +1 -1
package/schema/field.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
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.PolymorphicStringField = 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;
|
|
26
|
+
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.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.NumberField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
27
27
|
const luxon_1 = require("luxon");
|
|
28
28
|
const camel_case_1 = require("camel-case");
|
|
29
29
|
const util_1 = require("util");
|
|
@@ -119,9 +119,10 @@ function UUIDType(options) {
|
|
|
119
119
|
return Object.assign(result, options);
|
|
120
120
|
}
|
|
121
121
|
exports.UUIDType = UUIDType;
|
|
122
|
-
class
|
|
122
|
+
class NumberField extends BaseField {
|
|
123
123
|
constructor(options) {
|
|
124
124
|
super();
|
|
125
|
+
// to be overriden as needed
|
|
125
126
|
this.type = { dbType: schema_1.DBType.Int };
|
|
126
127
|
this.validators = [];
|
|
127
128
|
this.options = {};
|
|
@@ -145,9 +146,11 @@ class IntegerField extends BaseField {
|
|
|
145
146
|
this.options = options;
|
|
146
147
|
}
|
|
147
148
|
min(l) {
|
|
149
|
+
// @ts-ignore Operator '>=' cannot be applied to types 'number' and 'T'.
|
|
148
150
|
return this.validate((val) => val >= l);
|
|
149
151
|
}
|
|
150
152
|
max(l) {
|
|
153
|
+
// @ts-ignore Operator '<=' cannot be applied to types 'number' and 'T'.
|
|
151
154
|
return this.validate((val) => val <= l);
|
|
152
155
|
}
|
|
153
156
|
valid(val) {
|
|
@@ -163,13 +166,20 @@ class IntegerField extends BaseField {
|
|
|
163
166
|
return this;
|
|
164
167
|
}
|
|
165
168
|
}
|
|
169
|
+
exports.NumberField = NumberField;
|
|
170
|
+
class IntegerField extends NumberField {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(...arguments);
|
|
173
|
+
this.type = { dbType: schema_1.DBType.Int };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
166
176
|
exports.IntegerField = IntegerField;
|
|
167
177
|
function IntegerType(options) {
|
|
168
178
|
let result = new IntegerField(options);
|
|
169
179
|
return Object.assign(result, options);
|
|
170
180
|
}
|
|
171
181
|
exports.IntegerType = IntegerType;
|
|
172
|
-
class BigIntegerField extends
|
|
182
|
+
class BigIntegerField extends NumberField {
|
|
173
183
|
constructor() {
|
|
174
184
|
super(...arguments);
|
|
175
185
|
this.type = { dbType: schema_1.DBType.BigInt };
|
|
@@ -177,11 +187,11 @@ class BigIntegerField extends BaseField {
|
|
|
177
187
|
}
|
|
178
188
|
exports.BigIntegerField = BigIntegerField;
|
|
179
189
|
function BigIntegerType(options) {
|
|
180
|
-
let result = new BigIntegerField();
|
|
190
|
+
let result = new BigIntegerField(options);
|
|
181
191
|
return Object.assign(result, options);
|
|
182
192
|
}
|
|
183
193
|
exports.BigIntegerType = BigIntegerType;
|
|
184
|
-
class FloatField extends
|
|
194
|
+
class FloatField extends NumberField {
|
|
185
195
|
constructor() {
|
|
186
196
|
super(...arguments);
|
|
187
197
|
this.type = { dbType: schema_1.DBType.Float };
|
|
@@ -189,7 +199,7 @@ class FloatField extends BaseField {
|
|
|
189
199
|
}
|
|
190
200
|
exports.FloatField = FloatField;
|
|
191
201
|
function FloatType(options) {
|
|
192
|
-
let result = new FloatField();
|
|
202
|
+
let result = new FloatField(options);
|
|
193
203
|
return Object.assign(result, options);
|
|
194
204
|
}
|
|
195
205
|
exports.FloatType = FloatType;
|
|
@@ -527,7 +537,7 @@ class EnumField extends BaseField {
|
|
|
527
537
|
}
|
|
528
538
|
if (options.map) {
|
|
529
539
|
let count = 0;
|
|
530
|
-
for (const
|
|
540
|
+
for (const _ in options.map) {
|
|
531
541
|
count++;
|
|
532
542
|
break;
|
|
533
543
|
}
|
|
@@ -594,7 +604,7 @@ class IntegerEnumField extends BaseField {
|
|
|
594
604
|
deprecatedIntEnumMap: options.deprecated,
|
|
595
605
|
};
|
|
596
606
|
let count = 0;
|
|
597
|
-
for (const
|
|
607
|
+
for (const _ in options.map) {
|
|
598
608
|
count++;
|
|
599
609
|
break;
|
|
600
610
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface FieldInfo {
|
|
|
9
9
|
dbCol: string;
|
|
10
10
|
inputKey: string;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type FieldInfoMap = {
|
|
13
13
|
[key: string]: FieldInfo;
|
|
14
14
|
};
|
|
15
15
|
export interface GlobalSchema {
|
|
@@ -18,12 +18,12 @@ export interface GlobalSchema {
|
|
|
18
18
|
transformEdgeRead?: () => Clause;
|
|
19
19
|
transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
export
|
|
21
|
+
type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
|
|
22
|
+
export type FieldOverrideMap = {
|
|
23
23
|
[key: string]: FieldOverride;
|
|
24
24
|
};
|
|
25
25
|
export default interface Schema {
|
|
26
|
-
fields: FieldMap
|
|
26
|
+
fields: FieldMap;
|
|
27
27
|
fieldOverrides?: FieldOverrideMap;
|
|
28
28
|
tableName?: string;
|
|
29
29
|
patterns?: Pattern[];
|
|
@@ -78,10 +78,10 @@ export interface AssocEdgeGroup {
|
|
|
78
78
|
nullStateFn?: string;
|
|
79
79
|
edgeAction?: EdgeGroupAction;
|
|
80
80
|
}
|
|
81
|
-
export
|
|
81
|
+
export type Edge = AssocEdge;
|
|
82
82
|
export interface Pattern {
|
|
83
83
|
name: string;
|
|
84
|
-
fields: FieldMap
|
|
84
|
+
fields: FieldMap;
|
|
85
85
|
disableMixin?: boolean;
|
|
86
86
|
edges?: Edge[];
|
|
87
87
|
transformRead?: () => Clause;
|
|
@@ -173,7 +173,7 @@ export interface ForeignKey {
|
|
|
173
173
|
disableBuilderType?: boolean;
|
|
174
174
|
[x: string]: any;
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
177
177
|
export interface InverseFieldEdge {
|
|
178
178
|
name: string;
|
|
179
179
|
edgeConstName?: string;
|
|
@@ -234,7 +234,7 @@ export interface Field extends FieldOptions {
|
|
|
234
234
|
export interface SchemaConstructor {
|
|
235
235
|
new (): Schema;
|
|
236
236
|
}
|
|
237
|
-
export
|
|
237
|
+
export type SchemaInputType = Schema | SchemaConstructor;
|
|
238
238
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
239
239
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
240
240
|
/**
|
|
@@ -258,8 +258,8 @@ export declare enum ActionOperation {
|
|
|
258
258
|
RemoveEdge = 32,
|
|
259
259
|
EdgeGroup = 64
|
|
260
260
|
}
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "Object";
|
|
262
|
+
type NullableListOptions = "contents" | "contentsAndList";
|
|
263
263
|
export interface ActionField {
|
|
264
264
|
name: string;
|
|
265
265
|
type: actionFieldType;
|
package/schema/schema.js
CHANGED
|
@@ -56,22 +56,6 @@ exports.getSchema = getSchema;
|
|
|
56
56
|
function getFields(value) {
|
|
57
57
|
const schema = getSchema(value);
|
|
58
58
|
function addFields(fields) {
|
|
59
|
-
if (Array.isArray(fields)) {
|
|
60
|
-
for (const field of fields) {
|
|
61
|
-
if (field.dbOnly) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const name = field.name;
|
|
65
|
-
if (!name) {
|
|
66
|
-
throw new Error(`name required`);
|
|
67
|
-
}
|
|
68
|
-
if (field.getDerivedFields !== undefined) {
|
|
69
|
-
addFields(field.getDerivedFields(name));
|
|
70
|
-
}
|
|
71
|
-
m.set(name, field);
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
59
|
for (const name in fields) {
|
|
76
60
|
const field = fields[name];
|
|
77
61
|
if (field.dbOnly) {
|
|
@@ -114,6 +114,7 @@ function processTopLevel(l, l2) {
|
|
|
114
114
|
fieldType: custom.fieldType,
|
|
115
115
|
args: transformArgs(custom),
|
|
116
116
|
results: transformResultType(custom),
|
|
117
|
+
description: custom.description,
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
}
|
|
@@ -128,6 +129,7 @@ function processCustomFields(fields, gqlCapture, nodeName) {
|
|
|
128
129
|
fieldType: f.fieldType,
|
|
129
130
|
args: transformArgs(f),
|
|
130
131
|
results: transformResultType(f),
|
|
132
|
+
description: f.description,
|
|
131
133
|
});
|
|
132
134
|
}
|
|
133
135
|
m.set(nodeName, results);
|
|
@@ -213,11 +215,27 @@ async function requireFiles(files) {
|
|
|
213
215
|
throw new Error(err);
|
|
214
216
|
});
|
|
215
217
|
}
|
|
218
|
+
// filePath is path-to-src
|
|
216
219
|
async function parseImports(filePath) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
220
|
+
return (0, imports_1.parseCustomImports)(filePath, [
|
|
221
|
+
{
|
|
222
|
+
// graphql files
|
|
223
|
+
root: path.join(filePath, "graphql"),
|
|
224
|
+
opts: {
|
|
225
|
+
ignore: ["**/generated/**", "**/tests/**"],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
// can't just use top level ent files but have to check for all (non-generated) files
|
|
230
|
+
// in src/ent/* because custom edges (or other things) could have @gqlField etc
|
|
231
|
+
// and then have to look for these imports etc
|
|
232
|
+
root: path.join(filePath, "ent"),
|
|
233
|
+
opts: {
|
|
234
|
+
// not in action files since we can't customize payloads (yet?)
|
|
235
|
+
ignore: ["**/generated/**", "**/tests/**", "**/actions/**"],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
]);
|
|
221
239
|
}
|
|
222
240
|
function findGraphQLPath(filePath) {
|
|
223
241
|
while (filePath !== "/") {
|
|
@@ -232,6 +250,10 @@ function findGraphQLPath(filePath) {
|
|
|
232
250
|
}
|
|
233
251
|
return undefined;
|
|
234
252
|
}
|
|
253
|
+
// test as follows:
|
|
254
|
+
// there should be an easier way to do this...
|
|
255
|
+
// also, there should be a way to get the list of objects here that's not manual
|
|
256
|
+
//echo "User\nContact\nContactEmail\nComment" | ts-node-script --log-error --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/custom_graphql.ts --path ~/code/ent/examples/simple/src/
|
|
235
257
|
async function main() {
|
|
236
258
|
// known custom types that are not required
|
|
237
259
|
// if not in the schema, will be ignored
|
|
@@ -345,6 +367,10 @@ async function main() {
|
|
|
345
367
|
};
|
|
346
368
|
buildClasses(mutations);
|
|
347
369
|
buildClasses(queries);
|
|
370
|
+
// call for every field in a node
|
|
371
|
+
for (const k in fields) {
|
|
372
|
+
buildClasses(fields[k]);
|
|
373
|
+
}
|
|
348
374
|
console.log(JSON.stringify({
|
|
349
375
|
args,
|
|
350
376
|
inputs,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Ent, ID, Viewer, Data } from "../../core/base";
|
|
2
|
+
import { DataOperation } from "../../core/ent";
|
|
3
|
+
import { Action, Builder, Executor, WriteOperation, Trigger, Observer, TriggerReturn } from "../../action/action";
|
|
4
|
+
import { EdgeInputData } from "../../action/orchestrator";
|
|
5
|
+
import { User, Group, Message, Contact, SimpleBuilder, BuilderSchema, SimpleAction, BaseEnt } from "../../testutils/builder";
|
|
6
|
+
import { MockLogs } from "../../testutils/mock_log";
|
|
7
|
+
import { Table } from "../db/temp_db";
|
|
8
|
+
export declare function setupTest(): void;
|
|
9
|
+
export declare function getML(): MockLogs;
|
|
10
|
+
export declare function getOperations(): DataOperation<Ent<Viewer<Ent<any> | null, ID | null>>>[];
|
|
11
|
+
export declare const UserSchema: BuilderSchema<User>;
|
|
12
|
+
export declare class UserWithBalance extends User {
|
|
13
|
+
}
|
|
14
|
+
export declare const UserBalanceSchema: BuilderSchema<UserWithBalance>;
|
|
15
|
+
export declare class UserWithBalanceWithCheck extends UserWithBalance {
|
|
16
|
+
}
|
|
17
|
+
export declare const UserBalanceWithCheckSchema: BuilderSchema<UserWithBalanceWithCheck>;
|
|
18
|
+
export declare class Account extends BaseEnt {
|
|
19
|
+
accountID: string;
|
|
20
|
+
nodeType: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const AccountSchema: BuilderSchema<Account>;
|
|
23
|
+
export declare const ContactSchema: BuilderSchema<Contact>;
|
|
24
|
+
export declare const GroupSchema: BuilderSchema<Group>;
|
|
25
|
+
export declare class GroupMembership extends BaseEnt {
|
|
26
|
+
nodeType: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const GroupMembershipSchema: BuilderSchema<GroupMembership>;
|
|
29
|
+
export declare class Changelog extends BaseEnt {
|
|
30
|
+
nodeType: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const ChangelogSchema: BuilderSchema<Changelog>;
|
|
33
|
+
export declare const MessageSchema: BuilderSchema<Message>;
|
|
34
|
+
export declare function executeAction<T extends Ent, E = any>(action: Action<T, Builder<T>>, name?: E): Promise<Executor>;
|
|
35
|
+
export declare function createGroup(): Promise<Group>;
|
|
36
|
+
export declare function createUser(): Promise<User>;
|
|
37
|
+
export declare class MessageAction extends SimpleAction<Message> {
|
|
38
|
+
constructor(viewer: Viewer, fields: Map<string, any>, operation: WriteOperation, existingEnt: Message | null);
|
|
39
|
+
getTriggers(): Trigger<Message, SimpleBuilder<Message, Message | null>>[];
|
|
40
|
+
getObservers(): Observer<Message, SimpleBuilder<Message>>[];
|
|
41
|
+
}
|
|
42
|
+
export declare class UserAction extends SimpleAction<User> {
|
|
43
|
+
contactAction: SimpleAction<Contact> | undefined;
|
|
44
|
+
constructor(viewer: Viewer, fields: Map<string, any>, operation: WriteOperation, existingEnt: User | null);
|
|
45
|
+
getTriggers(): Trigger<User, SimpleBuilder<User>>[];
|
|
46
|
+
getObservers(): Observer<User, SimpleBuilder<User>>[];
|
|
47
|
+
}
|
|
48
|
+
type getMembershipFunction = (viewer: Viewer, edge: EdgeInputData) => SimpleAction<Ent>;
|
|
49
|
+
export declare class GroupMembershipTrigger implements Trigger<Group, SimpleBuilder<Group>> {
|
|
50
|
+
private getter;
|
|
51
|
+
constructor(getter: getMembershipFunction);
|
|
52
|
+
changeset(builder: SimpleBuilder<Group>, input: Data): TriggerReturn;
|
|
53
|
+
}
|
|
54
|
+
export declare class EditGroupAction extends SimpleAction<Group> {
|
|
55
|
+
viewer: Viewer;
|
|
56
|
+
private getter;
|
|
57
|
+
constructor(viewer: Viewer, schema: BuilderSchema<Group>, fields: Map<string, any>, existingEnt: Group, getter: getMembershipFunction);
|
|
58
|
+
getTriggers: () => GroupMembershipTrigger[];
|
|
59
|
+
}
|
|
60
|
+
export declare function verifyGroupMembers(group: Group, members: User[]): Promise<ID[]>;
|
|
61
|
+
export declare function loadMemberships(viewer: Viewer, membershipids: ID[]): Promise<GroupMembership[]>;
|
|
62
|
+
export declare function loadChangelogs(viewer: Viewer, clids: ID[]): Promise<Changelog[]>;
|
|
63
|
+
export declare function verifyChangelogFromMeberships(user: User, memberships: GroupMembership[]): Promise<void>;
|
|
64
|
+
export declare class GroupMemberOf extends BaseEnt {
|
|
65
|
+
nodeType: string;
|
|
66
|
+
}
|
|
67
|
+
export declare const GroupMemberOfSchema: BuilderSchema<GroupMemberOf>;
|
|
68
|
+
export declare const getTables: () => Table[];
|
|
69
|
+
export {};
|