@snowtop/ent 0.0.38 → 0.0.39-alpha10
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/orchestrator.d.ts +6 -0
- package/action/orchestrator.js +98 -20
- package/core/base.d.ts +1 -0
- package/core/clause.d.ts +24 -3
- package/core/clause.js +244 -5
- package/core/config.d.ts +3 -0
- package/core/ent.d.ts +2 -2
- package/core/ent.js +15 -6
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/object_loader.d.ts +1 -0
- package/core/loaders/object_loader.js +22 -4
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +22 -21
- package/graphql/node_resolver.d.ts +0 -1
- package/index.d.ts +15 -0
- package/index.js +15 -0
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +7 -1
- package/parse_schema/parse.js +21 -1
- package/schema/index.d.ts +1 -1
- package/schema/index.js +3 -1
- package/schema/schema.d.ts +40 -1
- package/schema/schema.js +49 -5
- package/scripts/custom_graphql.js +122 -15
- package/testutils/builder.js +5 -0
package/core/ent.js
CHANGED
|
@@ -434,6 +434,8 @@ class EditNodeOperation {
|
|
|
434
434
|
};
|
|
435
435
|
if (this.existingEnt) {
|
|
436
436
|
if (this.hasData(options.fields)) {
|
|
437
|
+
// even this with returning * may not always work if transformed...
|
|
438
|
+
// we can have a transformed flag to see if it should be returned?
|
|
437
439
|
this.row = await editRow(queryer, options, this.existingEnt.id, "RETURNING *");
|
|
438
440
|
}
|
|
439
441
|
else {
|
|
@@ -445,20 +447,27 @@ class EditNodeOperation {
|
|
|
445
447
|
}
|
|
446
448
|
}
|
|
447
449
|
reloadRow(queryer, id, options) {
|
|
450
|
+
// TODO this isn't always an ObjectLoader. should throw or figure out a way to get query
|
|
451
|
+
// and run this on its own...
|
|
452
|
+
const loader = this.options.loadEntOptions.loaderFactory.createLoader(options.context);
|
|
453
|
+
const opts = loader.getOptions();
|
|
454
|
+
let cls = clause.Eq(options.key, id);
|
|
455
|
+
if (opts.clause) {
|
|
456
|
+
cls = clause.And(opts.clause, cls);
|
|
457
|
+
}
|
|
448
458
|
const query = buildQuery({
|
|
449
|
-
fields: ["*"],
|
|
459
|
+
fields: opts.fields.length ? opts.fields : ["*"],
|
|
450
460
|
tableName: options.tableName,
|
|
451
|
-
clause:
|
|
461
|
+
clause: cls,
|
|
452
462
|
});
|
|
453
463
|
// special case log here because we're not going through any of the normal
|
|
454
464
|
// methods here because those are async and this is sync
|
|
455
465
|
// this is the only place we're doing this so only handling here
|
|
456
466
|
logQuery(query, [id]);
|
|
457
467
|
const r = queryer.querySync(query, [id]);
|
|
458
|
-
if (r.rows.length
|
|
459
|
-
|
|
468
|
+
if (r.rows.length === 1) {
|
|
469
|
+
this.row = r.rows[0];
|
|
460
470
|
}
|
|
461
|
-
this.row = r.rows[0];
|
|
462
471
|
}
|
|
463
472
|
performWriteSync(queryer, context) {
|
|
464
473
|
let options = {
|
|
@@ -487,7 +496,7 @@ class EditNodeOperation {
|
|
|
487
496
|
if (!this.row) {
|
|
488
497
|
return null;
|
|
489
498
|
}
|
|
490
|
-
return new this.options.ent(viewer, this.row);
|
|
499
|
+
return new this.options.loadEntOptions.ent(viewer, this.row);
|
|
491
500
|
}
|
|
492
501
|
}
|
|
493
502
|
exports.EditNodeOperation = EditNodeOperation;
|
|
@@ -4,6 +4,7 @@ exports.IndexLoaderFactory = void 0;
|
|
|
4
4
|
const query_loader_1 = require("./query_loader");
|
|
5
5
|
// we're keeping this for legacy reasons so as to not break existing callers
|
|
6
6
|
// and to decouple the change here but all callers can safely be changed here to use QueryLoaderFactory
|
|
7
|
+
// @deprecated use QueryLoaderFactory
|
|
7
8
|
class IndexLoaderFactory {
|
|
8
9
|
constructor(options, col, opts) {
|
|
9
10
|
this.factory = new query_loader_1.QueryLoaderFactory({
|
|
@@ -7,6 +7,7 @@ export declare class ObjectLoader<T> implements Loader<T, Data | null> {
|
|
|
7
7
|
private primedLoaders;
|
|
8
8
|
private memoizedInitPrime;
|
|
9
9
|
constructor(options: SelectDataOptions, context?: Context | undefined, toPrime?: ObjectLoaderFactory<T>[] | undefined);
|
|
10
|
+
getOptions(): SelectDataOptions;
|
|
10
11
|
private initPrime;
|
|
11
12
|
load(key: T): Promise<Data | null>;
|
|
12
13
|
clearAll(): void;
|
|
@@ -29,6 +29,9 @@ const clause = __importStar(require("../clause"));
|
|
|
29
29
|
const logger_1 = require("../logger");
|
|
30
30
|
const loader_1 = require("./loader");
|
|
31
31
|
const memoizee_1 = __importDefault(require("memoizee"));
|
|
32
|
+
// optional clause...
|
|
33
|
+
// so ObjectLoaderFactory and createDataLoader need to take a new optional field which is a clause that's always added here
|
|
34
|
+
// and we need a disableTransform which skips loader completely and uses loadRow...
|
|
32
35
|
function createDataLoader(options) {
|
|
33
36
|
const loaderOptions = {};
|
|
34
37
|
// if query logging is enabled, we should log what's happening with loader
|
|
@@ -40,9 +43,13 @@ function createDataLoader(options) {
|
|
|
40
43
|
return [];
|
|
41
44
|
}
|
|
42
45
|
let col = options.key;
|
|
46
|
+
let cls = clause.In(col, ...ids);
|
|
47
|
+
if (options.clause) {
|
|
48
|
+
cls = clause.And(options.clause, cls);
|
|
49
|
+
}
|
|
43
50
|
const rowOptions = {
|
|
44
51
|
...options,
|
|
45
|
-
clause:
|
|
52
|
+
clause: cls,
|
|
46
53
|
};
|
|
47
54
|
let m = new Map();
|
|
48
55
|
let result = [];
|
|
@@ -77,6 +84,9 @@ class ObjectLoader {
|
|
|
77
84
|
}
|
|
78
85
|
this.memoizedInitPrime = (0, memoizee_1.default)(this.initPrime.bind(this));
|
|
79
86
|
}
|
|
87
|
+
getOptions() {
|
|
88
|
+
return this.options;
|
|
89
|
+
}
|
|
80
90
|
initPrime() {
|
|
81
91
|
if (!this.context || !this.toPrime) {
|
|
82
92
|
return;
|
|
@@ -107,9 +117,13 @@ class ObjectLoader {
|
|
|
107
117
|
}
|
|
108
118
|
return result;
|
|
109
119
|
}
|
|
120
|
+
let cls = clause.Eq(this.options.key, key);
|
|
121
|
+
if (this.options.clause) {
|
|
122
|
+
cls = clause.And(this.options.clause, cls);
|
|
123
|
+
}
|
|
110
124
|
const rowOptions = {
|
|
111
125
|
...this.options,
|
|
112
|
-
clause:
|
|
126
|
+
clause: cls,
|
|
113
127
|
context: this.context,
|
|
114
128
|
};
|
|
115
129
|
return await (0, ent_1.loadRow)(rowOptions);
|
|
@@ -121,9 +135,13 @@ class ObjectLoader {
|
|
|
121
135
|
if (this.loader) {
|
|
122
136
|
return await this.loader.loadMany(keys);
|
|
123
137
|
}
|
|
138
|
+
let cls = clause.In(this.options.key, ...keys);
|
|
139
|
+
if (this.options.clause) {
|
|
140
|
+
cls = clause.And(this.options.clause, cls);
|
|
141
|
+
}
|
|
124
142
|
const rowOptions = {
|
|
125
143
|
...this.options,
|
|
126
|
-
clause:
|
|
144
|
+
clause: cls,
|
|
127
145
|
context: this.context,
|
|
128
146
|
};
|
|
129
147
|
return await (0, ent_1.loadRows)(rowOptions);
|
|
@@ -142,7 +160,7 @@ class ObjectLoaderFactory {
|
|
|
142
160
|
constructor(options) {
|
|
143
161
|
this.options = options;
|
|
144
162
|
this.toPrime = [];
|
|
145
|
-
this.name = `${options.tableName}:${options.key}`;
|
|
163
|
+
this.name = `${options.tableName}:${options.key}:${options.clause?.instanceKey() || ""}`;
|
|
146
164
|
}
|
|
147
165
|
createLoader(context) {
|
|
148
166
|
return (0, loader_1.getLoader)(this, () => {
|
package/graphql/graphql.d.ts
CHANGED
|
@@ -82,6 +82,9 @@ declare enum NullableResult {
|
|
|
82
82
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
83
83
|
ITEM = "true"
|
|
84
84
|
}
|
|
85
|
+
export declare const knownAllowedNames: Map<string, string>;
|
|
86
|
+
export declare const knownDisAllowedNames: Map<string, boolean>;
|
|
87
|
+
export declare const isCustomType: (type: Type) => type is CustomType;
|
|
85
88
|
export declare const addCustomType: (type: CustomType) => void;
|
|
86
89
|
export declare class GQLCapture {
|
|
87
90
|
private static enabled;
|
|
@@ -107,8 +110,6 @@ export declare class GQLCapture {
|
|
|
107
110
|
static getProcessedCustomMutations(): ProcessedCustomField[];
|
|
108
111
|
static getProcessedCustomQueries(): ProcessedCustomField[];
|
|
109
112
|
private static getProcessedCustomFieldsImpl;
|
|
110
|
-
private static knownAllowedNames;
|
|
111
|
-
private static knownDisAllowedNames;
|
|
112
113
|
private static getResultFromMetadata;
|
|
113
114
|
static gqlField(options?: gqlFieldOptions): any;
|
|
114
115
|
private static getCustomField;
|
package/graphql/graphql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.CustomFieldType = void 0;
|
|
3
|
+
exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
// export interface gqlTopLevelOptions
|
|
6
6
|
// name?: string;
|
|
@@ -20,6 +20,22 @@ var NullableResult;
|
|
|
20
20
|
NullableResult["CONTENTS_AND_LIST"] = "contentsAndList";
|
|
21
21
|
NullableResult["ITEM"] = "true";
|
|
22
22
|
})(NullableResult || (NullableResult = {}));
|
|
23
|
+
exports.knownAllowedNames = new Map([
|
|
24
|
+
["Date", "Date"],
|
|
25
|
+
["Boolean", "boolean"],
|
|
26
|
+
["Number", "number"],
|
|
27
|
+
["String", "string"],
|
|
28
|
+
// TODO not right to have this and Number
|
|
29
|
+
["Int", "number"],
|
|
30
|
+
["Float", "number"],
|
|
31
|
+
["ID", "ID"],
|
|
32
|
+
]);
|
|
33
|
+
exports.knownDisAllowedNames = new Map([
|
|
34
|
+
["Function", true],
|
|
35
|
+
["Object", true],
|
|
36
|
+
["Array", true],
|
|
37
|
+
["Promise", true],
|
|
38
|
+
]);
|
|
23
39
|
const isArray = (type) => {
|
|
24
40
|
if (typeof type === "function") {
|
|
25
41
|
return false;
|
|
@@ -41,6 +57,7 @@ const isString = (type) => {
|
|
|
41
57
|
const isCustomType = (type) => {
|
|
42
58
|
return type.importPath !== undefined;
|
|
43
59
|
};
|
|
60
|
+
exports.isCustomType = isCustomType;
|
|
44
61
|
const isGraphQLScalarType = (type) => {
|
|
45
62
|
return type.serialize !== undefined;
|
|
46
63
|
};
|
|
@@ -92,7 +109,7 @@ const getType = (typ, result) => {
|
|
|
92
109
|
}
|
|
93
110
|
return;
|
|
94
111
|
}
|
|
95
|
-
if (isCustomType(typ)) {
|
|
112
|
+
if ((0, exports.isCustomType)(typ)) {
|
|
96
113
|
result.type = typ.type;
|
|
97
114
|
(0, exports.addCustomType)(typ);
|
|
98
115
|
return;
|
|
@@ -197,20 +214,20 @@ class GQLCapture {
|
|
|
197
214
|
connection = r.connection;
|
|
198
215
|
type = r.type;
|
|
199
216
|
}
|
|
200
|
-
if (
|
|
217
|
+
if (exports.knownDisAllowedNames.has(type)) {
|
|
201
218
|
throw new Error(`${type} isn't a valid type for accessor/function/property`);
|
|
202
219
|
}
|
|
203
220
|
let result = {
|
|
204
221
|
name: metadata.paramName || "",
|
|
205
222
|
type,
|
|
206
|
-
tsType:
|
|
223
|
+
tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
|
|
207
224
|
nullable: options?.nullable,
|
|
208
225
|
list: list,
|
|
209
226
|
connection: connection,
|
|
210
227
|
isContextArg: metadata.isContextArg,
|
|
211
228
|
};
|
|
212
229
|
// unknown type. we need to flag that this field needs to eventually be resolved
|
|
213
|
-
if (!
|
|
230
|
+
if (!exports.knownAllowedNames.has(type)) {
|
|
214
231
|
if (scalarType) {
|
|
215
232
|
throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
|
|
216
233
|
}
|
|
@@ -461,22 +478,6 @@ GQLCapture.customArgs = new Map();
|
|
|
461
478
|
GQLCapture.customInputObjects = new Map();
|
|
462
479
|
GQLCapture.customObjects = new Map();
|
|
463
480
|
GQLCapture.customTypes = new Map();
|
|
464
|
-
GQLCapture.knownAllowedNames = new Map([
|
|
465
|
-
["Date", "Date"],
|
|
466
|
-
["Boolean", "boolean"],
|
|
467
|
-
["Number", "number"],
|
|
468
|
-
["String", "string"],
|
|
469
|
-
// TODO not right to have this and Number
|
|
470
|
-
["Int", "number"],
|
|
471
|
-
["Float", "number"],
|
|
472
|
-
["ID", "ID"],
|
|
473
|
-
]);
|
|
474
|
-
GQLCapture.knownDisAllowedNames = new Map([
|
|
475
|
-
["Function", true],
|
|
476
|
-
["Object", true],
|
|
477
|
-
["Array", true],
|
|
478
|
-
["Promise", true],
|
|
479
|
-
]);
|
|
480
481
|
// User -> add -> [{name, options}, {}, {}]
|
|
481
482
|
GQLCapture.argMap = new Map();
|
|
482
483
|
// why is this a static class lol?
|
package/index.d.ts
CHANGED
|
@@ -11,12 +11,27 @@ declare const query: {
|
|
|
11
11
|
Eq: typeof q.Eq;
|
|
12
12
|
NotEq: typeof q.NotEq;
|
|
13
13
|
And: typeof q.And;
|
|
14
|
+
AndOptional: typeof q.AndOptional;
|
|
14
15
|
Or: typeof q.Or;
|
|
15
16
|
In: typeof q.In;
|
|
16
17
|
Greater: typeof q.Greater;
|
|
17
18
|
Less: typeof q.Less;
|
|
18
19
|
GreaterEq: typeof q.GreaterEq;
|
|
19
20
|
LessEq: typeof q.LessEq;
|
|
21
|
+
ArrayEq: typeof q.ArrayEq;
|
|
22
|
+
ArrayNotEq: typeof q.ArrayNotEq;
|
|
23
|
+
ArrayGreater: typeof q.ArrayGreater;
|
|
24
|
+
ArrayLess: typeof q.ArrayLess;
|
|
25
|
+
ArrayGreaterEq: typeof q.ArrayGreaterEq;
|
|
26
|
+
ArrayLessEq: typeof q.ArrayLessEq;
|
|
27
|
+
TsQuery: typeof q.TsQuery;
|
|
28
|
+
PlainToTsQuery: typeof q.PlainToTsQuery;
|
|
29
|
+
PhraseToTsQuery: typeof q.PhraseToTsQuery;
|
|
30
|
+
WebsearchToTsQuery: typeof q.WebsearchToTsQuery;
|
|
31
|
+
TsVectorColTsQuery: typeof q.TsVectorColTsQuery;
|
|
32
|
+
TsVectorPlainToTsQuery: typeof q.TsVectorPlainToTsQuery;
|
|
33
|
+
TsVectorPhraseToTsQuery: typeof q.TsVectorPhraseToTsQuery;
|
|
34
|
+
TsVectorWebsearchToTsQuery: typeof q.TsVectorWebsearchToTsQuery;
|
|
20
35
|
};
|
|
21
36
|
export { query };
|
|
22
37
|
export { RequestContext, ContextCache } from "./core/context";
|
package/index.js
CHANGED
|
@@ -109,12 +109,27 @@ const query = {
|
|
|
109
109
|
Eq: q.Eq,
|
|
110
110
|
NotEq: q.NotEq,
|
|
111
111
|
And: q.And,
|
|
112
|
+
AndOptional: q.AndOptional,
|
|
112
113
|
Or: q.Or,
|
|
113
114
|
In: q.In,
|
|
114
115
|
Greater: q.Greater,
|
|
115
116
|
Less: q.Less,
|
|
116
117
|
GreaterEq: q.GreaterEq,
|
|
117
118
|
LessEq: q.LessEq,
|
|
119
|
+
ArrayEq: q.ArrayEq,
|
|
120
|
+
ArrayNotEq: q.ArrayNotEq,
|
|
121
|
+
ArrayGreater: q.ArrayGreater,
|
|
122
|
+
ArrayLess: q.ArrayLess,
|
|
123
|
+
ArrayGreaterEq: q.ArrayGreaterEq,
|
|
124
|
+
ArrayLessEq: q.ArrayLessEq,
|
|
125
|
+
TsQuery: q.TsQuery,
|
|
126
|
+
PlainToTsQuery: q.PlainToTsQuery,
|
|
127
|
+
PhraseToTsQuery: q.PhraseToTsQuery,
|
|
128
|
+
WebsearchToTsQuery: q.WebsearchToTsQuery,
|
|
129
|
+
TsVectorColTsQuery: q.TsVectorColTsQuery,
|
|
130
|
+
TsVectorPlainToTsQuery: q.TsVectorPlainToTsQuery,
|
|
131
|
+
TsVectorPhraseToTsQuery: q.TsVectorPhraseToTsQuery,
|
|
132
|
+
TsVectorWebsearchToTsQuery: q.TsVectorWebsearchToTsQuery,
|
|
118
133
|
};
|
|
119
134
|
exports.query = query;
|
|
120
135
|
var context_1 = require("./core/context");
|
package/package.json
CHANGED
package/parse_schema/parse.d.ts
CHANGED
|
@@ -12,7 +12,13 @@ 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[];
|
package/parse_schema/parse.js
CHANGED
|
@@ -78,6 +78,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
function processPattern(patterns, pattern, processedSchema) {
|
|
81
|
+
let ret = {
|
|
82
|
+
...pattern,
|
|
83
|
+
};
|
|
81
84
|
const name = pattern.name;
|
|
82
85
|
const fields = processFields(pattern.fields, pattern.name);
|
|
83
86
|
processedSchema.fields.push(...fields);
|
|
@@ -85,6 +88,10 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
85
88
|
const edges = processEdges(pattern.edges, pattern.name);
|
|
86
89
|
processedSchema.assocEdges.push(...edges);
|
|
87
90
|
}
|
|
91
|
+
// flag transformsSelect
|
|
92
|
+
if (pattern.transformRead) {
|
|
93
|
+
ret.transformsSelect = true;
|
|
94
|
+
}
|
|
88
95
|
if (patterns[name] === undefined) {
|
|
89
96
|
// intentionally processing separately and not passing pattern.name
|
|
90
97
|
const edges = processEdges(pattern.edges || []);
|
|
@@ -98,6 +105,7 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
98
105
|
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
99
106
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
100
107
|
}
|
|
108
|
+
return ret;
|
|
101
109
|
}
|
|
102
110
|
var NullableResult;
|
|
103
111
|
(function (NullableResult) {
|
|
@@ -160,7 +168,19 @@ function parseSchema(potentialSchemas) {
|
|
|
160
168
|
// ¯\_(ツ)_/¯
|
|
161
169
|
if (schema.patterns) {
|
|
162
170
|
for (const pattern of schema.patterns) {
|
|
163
|
-
processPattern(patterns, pattern, processedSchema);
|
|
171
|
+
const ret = processPattern(patterns, pattern, processedSchema);
|
|
172
|
+
if (ret.transformsSelect) {
|
|
173
|
+
if (processedSchema.transformsSelect) {
|
|
174
|
+
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
175
|
+
}
|
|
176
|
+
processedSchema.transformsSelect = true;
|
|
177
|
+
}
|
|
178
|
+
if (ret.transformsDelete) {
|
|
179
|
+
if (processedSchema.transformsDelete) {
|
|
180
|
+
throw new Error(`can only have one pattern which transforms default deletion behavior`);
|
|
181
|
+
}
|
|
182
|
+
processedSchema.transformsDelete = true;
|
|
183
|
+
}
|
|
164
184
|
}
|
|
165
185
|
}
|
|
166
186
|
const fields = processFields(schema.fields);
|
package/schema/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
|
|
3
|
+
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, getTransformedReadClause, } from "./schema";
|
|
4
4
|
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_schema";
|
|
5
5
|
export * from "./field";
|
|
6
6
|
export * from "./json_field";
|
package/schema/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
13
|
+
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
14
14
|
var schema_1 = require("./schema");
|
|
15
15
|
Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
|
|
16
16
|
Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
|
|
@@ -19,6 +19,8 @@ Object.defineProperty(exports, "NoFields", { enumerable: true, get: function ()
|
|
|
19
19
|
Object.defineProperty(exports, "ConstraintType", { enumerable: true, get: function () { return schema_1.ConstraintType; } });
|
|
20
20
|
Object.defineProperty(exports, "requiredField", { enumerable: true, get: function () { return schema_1.requiredField; } });
|
|
21
21
|
Object.defineProperty(exports, "optionalField", { enumerable: true, get: function () { return schema_1.optionalField; } });
|
|
22
|
+
Object.defineProperty(exports, "SQLStatementOperation", { enumerable: true, get: function () { return schema_1.SQLStatementOperation; } });
|
|
23
|
+
Object.defineProperty(exports, "getTransformedReadClause", { enumerable: true, get: function () { return schema_1.getTransformedReadClause; } });
|
|
22
24
|
var base_schema_1 = require("./base_schema");
|
|
23
25
|
Object.defineProperty(exports, "Timestamps", { enumerable: true, get: function () { return base_schema_1.Timestamps; } });
|
|
24
26
|
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return base_schema_1.Node; } });
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Data, Ent, LoaderInfo } from "../core/base";
|
|
1
|
+
import { Data, Ent, LoaderInfo, Viewer } from "../core/base";
|
|
2
2
|
import { Builder } from "../action/action";
|
|
3
|
+
import { Clause } from "../core/clause";
|
|
3
4
|
export default interface Schema {
|
|
4
5
|
fields: Field[];
|
|
5
6
|
tableName?: string;
|
|
@@ -59,6 +60,27 @@ export interface Pattern {
|
|
|
59
60
|
name: string;
|
|
60
61
|
fields: Field[];
|
|
61
62
|
edges?: Edge[];
|
|
63
|
+
transformRead?: () => Clause;
|
|
64
|
+
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | undefined;
|
|
65
|
+
transformsDelete?: boolean;
|
|
66
|
+
transformsInsert?: boolean;
|
|
67
|
+
transformsUpdate?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export declare enum SQLStatementOperation {
|
|
70
|
+
Insert = "insert",
|
|
71
|
+
Update = "update",
|
|
72
|
+
Delete = "delete"
|
|
73
|
+
}
|
|
74
|
+
export interface UpdateOperation<T extends Ent> {
|
|
75
|
+
op: SQLStatementOperation;
|
|
76
|
+
existingEnt?: T;
|
|
77
|
+
viewer: Viewer;
|
|
78
|
+
data?: Map<string, any>;
|
|
79
|
+
}
|
|
80
|
+
export interface TransformedUpdateOperation<T extends Ent> {
|
|
81
|
+
op: SQLStatementOperation;
|
|
82
|
+
data?: Data;
|
|
83
|
+
existingEnt?: T;
|
|
62
84
|
}
|
|
63
85
|
export declare enum DBType {
|
|
64
86
|
UUID = "UUID",
|
|
@@ -155,7 +177,10 @@ export interface SchemaConstructor {
|
|
|
155
177
|
new (): Schema;
|
|
156
178
|
}
|
|
157
179
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
180
|
+
export declare function getSchema(value: SchemaInputType): Schema;
|
|
158
181
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
182
|
+
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
183
|
+
export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | undefined;
|
|
159
184
|
export declare enum ActionOperation {
|
|
160
185
|
Create = 1,
|
|
161
186
|
Edit = 2,
|
|
@@ -198,10 +223,24 @@ export interface Constraint {
|
|
|
198
223
|
fkey?: ForeignKeyInfo;
|
|
199
224
|
condition?: string;
|
|
200
225
|
}
|
|
226
|
+
export interface FullTextWeight {
|
|
227
|
+
A?: string[];
|
|
228
|
+
B?: string[];
|
|
229
|
+
C?: string[];
|
|
230
|
+
D?: string[];
|
|
231
|
+
}
|
|
232
|
+
export interface FullText {
|
|
233
|
+
generatedColumnName?: string;
|
|
234
|
+
language?: "english" | "french" | "german" | "simple";
|
|
235
|
+
languageColumn?: string;
|
|
236
|
+
indexType?: "gin" | "gist";
|
|
237
|
+
weights?: FullTextWeight;
|
|
238
|
+
}
|
|
201
239
|
export interface Index {
|
|
202
240
|
name: string;
|
|
203
241
|
columns: string[];
|
|
204
242
|
unique?: boolean;
|
|
243
|
+
fulltext?: FullText;
|
|
205
244
|
}
|
|
206
245
|
export interface ForeignKeyInfo {
|
|
207
246
|
tableName: string;
|
package/schema/schema.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
3
|
+
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getTransformedReadClause = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
|
+
// we also want this transformation to exist on a per-action basis
|
|
5
|
+
// if it exists on an action, we don't do the global schema transformation
|
|
6
|
+
var SQLStatementOperation;
|
|
7
|
+
(function (SQLStatementOperation) {
|
|
8
|
+
// transform insert e.g. to an update based on whatever logic
|
|
9
|
+
SQLStatementOperation["Insert"] = "insert";
|
|
10
|
+
// // transform select e.g. deleted_at. can't change from select to different query type
|
|
11
|
+
// // but can change the query
|
|
12
|
+
// Select = "select",
|
|
13
|
+
// e.g. change updated value
|
|
14
|
+
SQLStatementOperation["Update"] = "update";
|
|
15
|
+
// delete -> update theoretically e.g. deleted_at
|
|
16
|
+
SQLStatementOperation["Delete"] = "delete";
|
|
17
|
+
})(SQLStatementOperation = exports.SQLStatementOperation || (exports.SQLStatementOperation = {}));
|
|
4
18
|
// we want --strictNullChecks flag so nullable is used to type graphql, ts, db
|
|
5
19
|
// should eventually generate (boolean | null) etc
|
|
6
20
|
// supported db types
|
|
@@ -28,14 +42,17 @@ var DBType;
|
|
|
28
42
|
function isSchema(value) {
|
|
29
43
|
return value.fields !== undefined;
|
|
30
44
|
}
|
|
31
|
-
function
|
|
32
|
-
let schema;
|
|
45
|
+
function getSchema(value) {
|
|
33
46
|
if (isSchema(value)) {
|
|
34
|
-
|
|
47
|
+
return value;
|
|
35
48
|
}
|
|
36
49
|
else {
|
|
37
|
-
|
|
50
|
+
return new value();
|
|
38
51
|
}
|
|
52
|
+
}
|
|
53
|
+
exports.getSchema = getSchema;
|
|
54
|
+
function getFields(value) {
|
|
55
|
+
const schema = getSchema(value);
|
|
39
56
|
function addFields(fields) {
|
|
40
57
|
for (const field of fields) {
|
|
41
58
|
const derivedFields = field.derivedFields;
|
|
@@ -55,6 +72,33 @@ function getFields(value) {
|
|
|
55
72
|
return m;
|
|
56
73
|
}
|
|
57
74
|
exports.getFields = getFields;
|
|
75
|
+
function getTransformedReadClause(value) {
|
|
76
|
+
const schema = getSchema(value);
|
|
77
|
+
if (!schema.patterns) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const p of schema.patterns) {
|
|
81
|
+
// e.g. discarded_at, deleted_at, etc
|
|
82
|
+
if (p.transformRead) {
|
|
83
|
+
// return clause.Eq('deleted_at', null);
|
|
84
|
+
return p.transformRead();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
exports.getTransformedReadClause = getTransformedReadClause;
|
|
90
|
+
function getTransformedUpdateOp(value, stmt) {
|
|
91
|
+
const schema = getSchema(value);
|
|
92
|
+
if (!schema.patterns) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
for (const p of schema.patterns) {
|
|
96
|
+
if (p.transformWrite) {
|
|
97
|
+
return p.transformWrite(stmt);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
58
102
|
// this maps to ActionOperation in ent/action.go
|
|
59
103
|
var ActionOperation;
|
|
60
104
|
(function (ActionOperation) {
|