@snowtop/ent 0.1.0-alpha95 → 0.1.0-alpha96
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.js +2 -2
- package/schema/schema.d.ts +11 -10
- package/schema/schema.js +3 -13
- 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/core/db.js
CHANGED
|
@@ -39,13 +39,16 @@ var Dialect;
|
|
|
39
39
|
Dialect["Postgres"] = "postgres";
|
|
40
40
|
Dialect["SQLite"] = "sqlite";
|
|
41
41
|
})(Dialect = exports.Dialect || (exports.Dialect = {}));
|
|
42
|
-
function parseConnectionString(str) {
|
|
42
|
+
function parseConnectionString(str, args) {
|
|
43
43
|
if (str.startsWith("sqlite:///")) {
|
|
44
44
|
let filePath = str.substr(10);
|
|
45
45
|
return {
|
|
46
46
|
dialect: Dialect.SQLite,
|
|
47
47
|
config: {
|
|
48
48
|
connectionString: str,
|
|
49
|
+
// TODO would like to do this for other args e.g. max being set but would have to update tests
|
|
50
|
+
// e.g. src/core/config.test.ts which tests this
|
|
51
|
+
// ...args?.db,
|
|
49
52
|
},
|
|
50
53
|
filePath,
|
|
51
54
|
};
|
|
@@ -54,6 +57,9 @@ function parseConnectionString(str) {
|
|
|
54
57
|
dialect: Dialect.Postgres,
|
|
55
58
|
config: {
|
|
56
59
|
connectionString: str,
|
|
60
|
+
// TODO would like to do this for other args e.g. max being set but would have to update tests
|
|
61
|
+
// e.g. src/core/config.test.ts which tests this
|
|
62
|
+
// ...args?.db,
|
|
57
63
|
},
|
|
58
64
|
};
|
|
59
65
|
}
|
|
@@ -67,12 +73,12 @@ function getClientConfig(args) {
|
|
|
67
73
|
// if there's a db connection string, use that first
|
|
68
74
|
const str = process.env.DB_CONNECTION_STRING;
|
|
69
75
|
if (str) {
|
|
70
|
-
return parseConnectionString(str);
|
|
76
|
+
return parseConnectionString(str, args);
|
|
71
77
|
}
|
|
72
78
|
let file = "config/database.yml";
|
|
73
79
|
if (args) {
|
|
74
80
|
if (args.connectionString) {
|
|
75
|
-
return parseConnectionString(args.connectionString);
|
|
81
|
+
return parseConnectionString(args.connectionString, args);
|
|
76
82
|
}
|
|
77
83
|
if (args.db) {
|
|
78
84
|
let db;
|
|
@@ -162,6 +168,10 @@ class DB {
|
|
|
162
168
|
async endPool() {
|
|
163
169
|
return this.q.close();
|
|
164
170
|
}
|
|
171
|
+
emitsExplicitTransactionStatements() {
|
|
172
|
+
const instance = DB.getInstance();
|
|
173
|
+
return instance.q.runInTransaction === undefined;
|
|
174
|
+
}
|
|
165
175
|
// throws if invalid
|
|
166
176
|
static getInstance() {
|
|
167
177
|
if (DB.instance) {
|
|
@@ -196,8 +206,6 @@ exports.defaultTimestampParser = pg_1.default.types.getTypeParser(pg_1.default.t
|
|
|
196
206
|
// it's parsed as UTC time as opposed to the local time
|
|
197
207
|
pg_1.default.types.setTypeParser(pg_1.default.types.builtins.TIMESTAMP, function (val) {
|
|
198
208
|
return luxon_1.DateTime.fromSQL(val + "Z").toJSDate();
|
|
199
|
-
// let d = new Date(val + "Z");
|
|
200
|
-
// return d;
|
|
201
209
|
});
|
|
202
210
|
class Sqlite {
|
|
203
211
|
constructor(db) {
|
|
@@ -316,7 +324,7 @@ class Postgres {
|
|
|
316
324
|
};
|
|
317
325
|
}
|
|
318
326
|
async close() {
|
|
319
|
-
return this.pool.end();
|
|
327
|
+
return await this.pool.end();
|
|
320
328
|
}
|
|
321
329
|
}
|
|
322
330
|
exports.Postgres = Postgres;
|
package/core/ent.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ interface parameterizedQueryOptions {
|
|
|
30
30
|
values?: any[];
|
|
31
31
|
logValues?: any[];
|
|
32
32
|
}
|
|
33
|
-
export
|
|
33
|
+
export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | QueryDataOptions;
|
|
34
34
|
/**
|
|
35
35
|
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
36
36
|
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
@@ -61,8 +61,10 @@ interface CustomCountOptions extends DataOptions {
|
|
|
61
61
|
export declare function loadCustomCount(options: CustomCountOptions, query: CustomQuery, context: Context | undefined): Promise<number>;
|
|
62
62
|
export declare function loadDerivedEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt | null>;
|
|
63
63
|
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
64
|
+
export declare function logQuery(query: string, logValues: any[]): void;
|
|
64
65
|
export declare function loadRowX(options: LoadRowOptions): Promise<Data>;
|
|
65
66
|
export declare function loadRow(options: LoadRowOptions): Promise<Data | null>;
|
|
67
|
+
export declare function ___setLogQueryErrorWithError(val: boolean | undefined): void;
|
|
66
68
|
export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
|
|
67
69
|
export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
|
|
68
70
|
export declare function buildQuery(options: QueryableDataOptions): string;
|
package/core/ent.js
CHANGED
|
@@ -26,8 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = void 0;
|
|
29
|
+
exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.DefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.DeleteNodeOperation = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.EdgeOperation = exports.__hasGlobalSchema = exports.clearGlobalSchema = exports.setGlobalSchema = exports.EditNodeOperation = exports.RawQueryOperation = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.___setLogQueryErrorWithError = exports.loadRow = exports.loadRowX = exports.logQuery = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
|
|
30
|
+
exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = void 0;
|
|
31
31
|
const db_1 = __importStar(require("./db"));
|
|
32
32
|
const privacy_1 = require("./privacy");
|
|
33
33
|
const clause = __importStar(require("./clause"));
|
|
@@ -517,6 +517,9 @@ async function doFieldPrivacy(viewer, ent, data, options) {
|
|
|
517
517
|
}
|
|
518
518
|
const promises = [];
|
|
519
519
|
let somethingChanged = false;
|
|
520
|
+
const origData = {
|
|
521
|
+
...data,
|
|
522
|
+
};
|
|
520
523
|
for (const [k, policy] of options.fieldPrivacy) {
|
|
521
524
|
const curr = data[k];
|
|
522
525
|
if (curr === null || curr === undefined) {
|
|
@@ -534,8 +537,11 @@ async function doFieldPrivacy(viewer, ent, data, options) {
|
|
|
534
537
|
await Promise.all(promises);
|
|
535
538
|
if (somethingChanged) {
|
|
536
539
|
// have to create new instance
|
|
537
|
-
|
|
540
|
+
const ent = new options.ent(viewer, data);
|
|
541
|
+
ent.__setRawDBData(origData);
|
|
542
|
+
return ent;
|
|
538
543
|
}
|
|
544
|
+
ent.__setRawDBData(origData);
|
|
539
545
|
return ent;
|
|
540
546
|
}
|
|
541
547
|
function logQuery(query, logValues) {
|
|
@@ -545,6 +551,7 @@ function logQuery(query, logValues) {
|
|
|
545
551
|
});
|
|
546
552
|
(0, logger_1.logTrace)();
|
|
547
553
|
}
|
|
554
|
+
exports.logQuery = logQuery;
|
|
548
555
|
// TODO long term figure out if this API should be exposed
|
|
549
556
|
async function loadRowX(options) {
|
|
550
557
|
const result = await loadRow(options);
|
|
@@ -582,12 +589,26 @@ async function loadRow(options) {
|
|
|
582
589
|
return res.rows[0];
|
|
583
590
|
}
|
|
584
591
|
exports.loadRow = loadRow;
|
|
592
|
+
var _logQueryWithError = false;
|
|
593
|
+
function ___setLogQueryErrorWithError(val) {
|
|
594
|
+
_logQueryWithError = val || false;
|
|
595
|
+
}
|
|
596
|
+
exports.___setLogQueryErrorWithError = ___setLogQueryErrorWithError;
|
|
585
597
|
// this always goes to the db, no cache, nothing
|
|
586
598
|
async function performRawQuery(query, values, logValues) {
|
|
587
599
|
const pool = db_1.default.getInstance().getPool();
|
|
588
600
|
logQuery(query, logValues || []);
|
|
589
|
-
|
|
590
|
-
|
|
601
|
+
try {
|
|
602
|
+
const res = await pool.queryAll(query, values);
|
|
603
|
+
return res.rows;
|
|
604
|
+
}
|
|
605
|
+
catch (e) {
|
|
606
|
+
if (_logQueryWithError) {
|
|
607
|
+
const msg = e.message;
|
|
608
|
+
throw new Error(`error \`${msg}\` running query: \`${query}\``);
|
|
609
|
+
}
|
|
610
|
+
throw e;
|
|
611
|
+
}
|
|
591
612
|
}
|
|
592
613
|
exports.performRawQuery = performRawQuery;
|
|
593
614
|
// TODO this should throw, we can't be hiding errors here
|
|
@@ -1145,11 +1166,20 @@ async function mutateRow(queryer, query, values, logValues, options) {
|
|
|
1145
1166
|
logQuery(query, logValues);
|
|
1146
1167
|
let cache = options.context?.cache;
|
|
1147
1168
|
let res;
|
|
1148
|
-
|
|
1149
|
-
|
|
1169
|
+
try {
|
|
1170
|
+
if (isSyncQueryer(queryer)) {
|
|
1171
|
+
res = queryer.execSync(query, values);
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
res = await queryer.exec(query, values);
|
|
1175
|
+
}
|
|
1150
1176
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1177
|
+
catch (e) {
|
|
1178
|
+
if (_logQueryWithError) {
|
|
1179
|
+
const msg = e.message;
|
|
1180
|
+
throw new Error(`error \`${msg}\` running query: \`${query}\``);
|
|
1181
|
+
}
|
|
1182
|
+
throw e;
|
|
1153
1183
|
}
|
|
1154
1184
|
if (cache) {
|
|
1155
1185
|
cache.clearCache();
|
|
@@ -1159,11 +1189,20 @@ async function mutateRow(queryer, query, values, logValues, options) {
|
|
|
1159
1189
|
function mutateRowSync(queryer, query, values, logValues, options) {
|
|
1160
1190
|
logQuery(query, logValues);
|
|
1161
1191
|
let cache = options.context?.cache;
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
cache
|
|
1192
|
+
try {
|
|
1193
|
+
const res = queryer.execSync(query, values);
|
|
1194
|
+
if (cache) {
|
|
1195
|
+
cache.clearCache();
|
|
1196
|
+
}
|
|
1197
|
+
return res;
|
|
1198
|
+
}
|
|
1199
|
+
catch (e) {
|
|
1200
|
+
if (_logQueryWithError) {
|
|
1201
|
+
const msg = e.message;
|
|
1202
|
+
throw new Error(`error \`${msg}\` running query: \`${query}\``);
|
|
1203
|
+
}
|
|
1204
|
+
throw e;
|
|
1165
1205
|
}
|
|
1166
|
-
return res;
|
|
1167
1206
|
}
|
|
1168
1207
|
function buildInsertQuery(options, suffix) {
|
|
1169
1208
|
let fields = [];
|
|
@@ -1222,22 +1261,33 @@ function buildUpdateQuery(options, suffix) {
|
|
|
1222
1261
|
const dialect = db_1.default.getDialect();
|
|
1223
1262
|
let idx = 1;
|
|
1224
1263
|
for (const key in options.fields) {
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
// valsString.push(clause.Eq(key, val).clause(idx));
|
|
1234
|
-
if (dialect === db_1.Dialect.Postgres) {
|
|
1235
|
-
valsString.push(`${key} = $${idx}`);
|
|
1264
|
+
if (options.expressions && options.expressions.has(key)) {
|
|
1265
|
+
const cls = options.expressions.get(key);
|
|
1266
|
+
valsString.push(`${key} = ${cls.clause(idx)}`);
|
|
1267
|
+
// TODO need to test a clause with more than one value...
|
|
1268
|
+
const newVals = cls.values();
|
|
1269
|
+
idx += newVals.length;
|
|
1270
|
+
values.push(...newVals);
|
|
1271
|
+
logValues.push(...cls.logValues());
|
|
1236
1272
|
}
|
|
1237
1273
|
else {
|
|
1238
|
-
|
|
1274
|
+
const val = options.fields[key];
|
|
1275
|
+
values.push(val);
|
|
1276
|
+
if (options.fieldsToLog) {
|
|
1277
|
+
logValues.push(options.fieldsToLog[key]);
|
|
1278
|
+
}
|
|
1279
|
+
// TODO would be nice to use clause here. need update version of the queries so that
|
|
1280
|
+
// we don't have to handle dialect specifics here
|
|
1281
|
+
// can't use clause because of IS NULL
|
|
1282
|
+
// valsString.push(clause.Eq(key, val).clause(idx));
|
|
1283
|
+
if (dialect === db_1.Dialect.Postgres) {
|
|
1284
|
+
valsString.push(`${key} = $${idx}`);
|
|
1285
|
+
}
|
|
1286
|
+
else {
|
|
1287
|
+
valsString.push(`${key} = ?`);
|
|
1288
|
+
}
|
|
1289
|
+
idx++;
|
|
1239
1290
|
}
|
|
1240
|
-
idx++;
|
|
1241
1291
|
}
|
|
1242
1292
|
const vals = valsString.join(", ");
|
|
1243
1293
|
let query = `UPDATE ${options.tableName} SET ${vals} WHERE `;
|
package/core/logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type logType = "query" | "warn" | "info" | "error" | "debug" | "cache";
|
|
2
2
|
export declare function setLogLevels(levels: logType | logType[]): void;
|
|
3
3
|
export declare function clearLogLevels(): void;
|
|
4
4
|
export declare function log(level: logType, msg: any): void;
|
|
@@ -3,8 +3,8 @@ import { AssocEdge } from "../ent";
|
|
|
3
3
|
import { AssocEdgeCountLoaderFactory } from "../loaders/assoc_count_loader";
|
|
4
4
|
import { AssocEdgeLoaderFactory } from "../loaders/assoc_edge_loader";
|
|
5
5
|
import { EdgeQuery, BaseEdgeQuery, IDInfo } from "./query";
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export type EdgeQuerySource<TSource extends Ent<TViewer>, TDest extends Ent<TViewer> = Ent<any>, TViewer extends Viewer = Viewer> = TSource | TSource[] | ID | ID[] | EdgeQuery<TDest, Ent, AssocEdge>;
|
|
7
|
+
type loaderOptionsFunc<TViewer extends Viewer> = (type: string) => LoadEntOptions<Ent, TViewer>;
|
|
8
8
|
export declare abstract class AssocEdgeQueryBase<TSource extends Ent<TViewer>, TDest extends Ent<TViewer>, TEdge extends AssocEdge, TViewer extends Viewer = Viewer> extends BaseEdgeQuery<TSource, TDest, TEdge> implements EdgeQuery<TSource, TDest, TEdge> {
|
|
9
9
|
viewer: TViewer;
|
|
10
10
|
src: EdgeQuerySource<TSource, TDest, TViewer>;
|
|
@@ -610,10 +610,9 @@ function assocTests(ml, global = false) {
|
|
|
610
610
|
let user;
|
|
611
611
|
let friendRequests;
|
|
612
612
|
let user2;
|
|
613
|
-
let friendRequests2;
|
|
614
613
|
beforeEach(async () => {
|
|
615
614
|
[user, friendRequests] = await (0, test_helpers_1.createUserPlusFriendRequests)();
|
|
616
|
-
[user2
|
|
615
|
+
[user2] = await (0, test_helpers_1.createUserPlusFriendRequests)();
|
|
617
616
|
});
|
|
618
617
|
function getQuery(viewer) {
|
|
619
618
|
return index_1.UserToIncomingFriendRequestsQuery.query(viewer || user.viewer, [
|
|
@@ -80,7 +80,6 @@ const commonTests = (opts) => {
|
|
|
80
80
|
this.verifyEdges(edges);
|
|
81
81
|
}
|
|
82
82
|
verifyEdges(edges) {
|
|
83
|
-
const q = this.getQuery();
|
|
84
83
|
// TODO sad not generic enough
|
|
85
84
|
if (this.customQuery) {
|
|
86
85
|
(0, test_helpers_1.verifyUserToContactRawData)(this.user, edges, this.filteredContacts);
|
package/graphql/graphql.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export interface CustomType {
|
|
|
10
10
|
tsImportPath?: string;
|
|
11
11
|
[x: string]: any;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
export
|
|
13
|
+
type Type = GraphQLScalarType | ClassType | string | CustomType;
|
|
14
|
+
export type GraphQLConnection<T> = {
|
|
15
15
|
node: T;
|
|
16
16
|
};
|
|
17
17
|
export interface gqlFieldOptions {
|
|
@@ -24,7 +24,7 @@ export interface gqlObjectOptions {
|
|
|
24
24
|
name?: string;
|
|
25
25
|
description?: string;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
type gqlTopLevelOptions = Exclude<gqlFieldOptions, "nullable">;
|
|
28
28
|
export declare enum CustomFieldType {
|
|
29
29
|
Accessor = "ACCESSOR",
|
|
30
30
|
Field = "FIELD",
|
|
@@ -51,15 +51,15 @@ export interface ProcessedCustomField extends CustomFieldImpl {
|
|
|
51
51
|
args: ProcessedField[];
|
|
52
52
|
results: ProcessedField[];
|
|
53
53
|
}
|
|
54
|
-
export
|
|
55
|
-
[key: string]: ProcessedCustomField;
|
|
54
|
+
export type ProcessCustomFieldMap = {
|
|
55
|
+
[key: string]: ProcessedCustomField[];
|
|
56
56
|
};
|
|
57
57
|
export interface CustomObject {
|
|
58
58
|
nodeName: string;
|
|
59
59
|
className: string;
|
|
60
60
|
description?: string;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
type NullableListOptions = "contents" | "contentsAndList";
|
|
63
63
|
interface FieldImpl {
|
|
64
64
|
type: string;
|
|
65
65
|
tsType?: string;
|
package/graphql/graphql.js
CHANGED
|
@@ -443,6 +443,7 @@ class GQLCapture {
|
|
|
443
443
|
this.customInputObjects.forEach((_val, key) => baseArgs.set(key, true));
|
|
444
444
|
baseArgs.set("Context", true);
|
|
445
445
|
this.customTypes.forEach((_val, key) => baseArgs.set(key, true));
|
|
446
|
+
// TODO this should be aware of knownCustomTypes
|
|
446
447
|
const resolveFields = (fields) => {
|
|
447
448
|
fields.forEach((field) => {
|
|
448
449
|
// we have a check earlier that *should* make this path impossible
|
|
@@ -2,7 +2,7 @@ import { GraphQLFieldConfigMap, GraphQLObjectType, GraphQLInterfaceType } from "
|
|
|
2
2
|
import { RequestContext } from "../../core/context";
|
|
3
3
|
import { GraphQLEdge } from "./edge_connection";
|
|
4
4
|
import { Data } from "../../core/base";
|
|
5
|
-
|
|
5
|
+
type nodeType = GraphQLObjectType | GraphQLInterfaceType;
|
|
6
6
|
export declare class GraphQLEdgeType<TNode extends nodeType, TEdge extends Data> extends GraphQLObjectType {
|
|
7
7
|
constructor(name: string, nodeType: TNode, optionalFields?: () => GraphQLFieldConfigMap<GraphQLEdge<TEdge>, RequestContext>);
|
|
8
8
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commonTests = void 0;
|
|
4
|
-
const pg_1 = require("pg");
|
|
5
4
|
const viewer_1 = require("../../core/viewer");
|
|
6
5
|
const ent_1 = require("../../core/ent");
|
|
7
|
-
const db_mock_1 = require("../../testutils/db_mock");
|
|
8
6
|
const edge_connection_1 = require("./edge_connection");
|
|
9
7
|
const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
|
|
10
|
-
jest.mock("pg");
|
|
11
|
-
db_mock_1.QueryRecorder.mockPool(pg_1.Pool);
|
|
12
8
|
class TestConnection {
|
|
13
9
|
constructor(getQuery, ents, filter) {
|
|
14
10
|
this.getQuery = getQuery;
|
package/imports/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface Options {
|
|
2
2
|
filter?: (file: string, index: number, array: string[]) => boolean;
|
|
3
|
+
justCurrentDir?: boolean;
|
|
3
4
|
ignore?: string | Readonly<string[]> | undefined;
|
|
4
5
|
}
|
|
5
6
|
export interface PathResult {
|
|
@@ -10,7 +11,11 @@ interface classResult {
|
|
|
10
11
|
class: classInfo;
|
|
11
12
|
file: file;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
interface ParseInput {
|
|
15
|
+
root: string;
|
|
16
|
+
opts?: Options;
|
|
17
|
+
}
|
|
18
|
+
export declare function parseCustomImports(filePath: string, inputs: ParseInput[]): PathResult;
|
|
14
19
|
export interface importInfo {
|
|
15
20
|
name: string;
|
|
16
21
|
importPath: string;
|
package/imports/index.js
CHANGED
|
@@ -38,7 +38,11 @@ function getFiles(filePath, opts) {
|
|
|
38
38
|
}
|
|
39
39
|
// graphql path should be passed to this
|
|
40
40
|
// this is more agnostic about what it expect here
|
|
41
|
-
let
|
|
41
|
+
let pattern = `${filePath}/**/*.ts`;
|
|
42
|
+
if (opts?.justCurrentDir) {
|
|
43
|
+
pattern = `${filePath}/**.ts`;
|
|
44
|
+
}
|
|
45
|
+
let files = glob_1.default.sync(pattern, {
|
|
42
46
|
ignore: opts?.ignore,
|
|
43
47
|
});
|
|
44
48
|
if (opts?.filter) {
|
|
@@ -46,8 +50,15 @@ function getFiles(filePath, opts) {
|
|
|
46
50
|
}
|
|
47
51
|
return files;
|
|
48
52
|
}
|
|
49
|
-
function parseCustomImports(filePath,
|
|
50
|
-
const files =
|
|
53
|
+
function parseCustomImports(filePath, inputs) {
|
|
54
|
+
const files = [];
|
|
55
|
+
// simplifies tests and other simple callsites
|
|
56
|
+
if (inputs.length === 0) {
|
|
57
|
+
inputs.push({ root: filePath });
|
|
58
|
+
}
|
|
59
|
+
for (const input of inputs) {
|
|
60
|
+
files.push(...getFiles(input.root, input.opts));
|
|
61
|
+
}
|
|
51
62
|
const options = (0, compilerOptions_1.readCompilerOptions)(filePath);
|
|
52
63
|
let classMap = new Map();
|
|
53
64
|
files.forEach((file) => {
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { EntPrivacyError, AlwaysAllowRule, AlwaysDenyRule, DenyIfLoggedInRule, D
|
|
|
7
7
|
export * from "./core/query";
|
|
8
8
|
export * from "./schema/";
|
|
9
9
|
import * as q from "./core/clause";
|
|
10
|
+
export { Clause } from "./core/clause";
|
|
10
11
|
declare const query: {
|
|
11
12
|
Eq: typeof q.Eq;
|
|
12
13
|
NotEq: typeof q.NotEq;
|
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-alpha96",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,27 +8,27 @@
|
|
|
8
8
|
"example": "examples"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@types/node": "^
|
|
11
|
+
"@types/node": "^18.11.18",
|
|
12
12
|
"camel-case": "^4.1.2",
|
|
13
|
-
"cosmiconfig": "^
|
|
14
|
-
"dataloader": "^2.
|
|
13
|
+
"cosmiconfig": "^8.0.0",
|
|
14
|
+
"dataloader": "^2.1.0",
|
|
15
15
|
"glob": "^8.0.3",
|
|
16
|
-
"graph-data-structure": "^
|
|
16
|
+
"graph-data-structure": "^2.0.0",
|
|
17
17
|
"js-yaml": "^4.1.0",
|
|
18
|
-
"json5": "^2.
|
|
19
|
-
"luxon": "^1.
|
|
18
|
+
"json5": "^2.2.2",
|
|
19
|
+
"luxon": "^3.1.1",
|
|
20
20
|
"memoizee": "^0.4.15",
|
|
21
|
-
"minimist": "^1.2.
|
|
21
|
+
"minimist": "^1.2.7",
|
|
22
22
|
"pascal-case": "^3.1.2",
|
|
23
|
-
"pg": "^8.0
|
|
24
|
-
"prettier": "^2.
|
|
23
|
+
"pg": "^8.8.0",
|
|
24
|
+
"prettier": "^2.8.1",
|
|
25
25
|
"reflect-metadata": "^0.1.13",
|
|
26
|
-
"snake-case": "^3.0.
|
|
27
|
-
"ts-node": "^10.
|
|
28
|
-
"tsconfig-paths": "^
|
|
29
|
-
"tslib": "^2.
|
|
30
|
-
"typescript": "^4.4
|
|
31
|
-
"uuid": "^
|
|
26
|
+
"snake-case": "^3.0.4",
|
|
27
|
+
"ts-node": "^10.9.1",
|
|
28
|
+
"tsconfig-paths": "^4.1.1",
|
|
29
|
+
"tslib": "^2.4.1",
|
|
30
|
+
"typescript": "^4.9.4",
|
|
31
|
+
"uuid": "^9.0.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"better-sqlite3": "^7.4.1",
|
package/parse_schema/parse.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ declare enum NullableResult {
|
|
|
5
5
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
6
6
|
ITEM = "true"
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type ProcessedActionField = Omit<ActionField, "nullable"> & {
|
|
9
9
|
nullable?: NullableResult;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActions"> & {
|
|
12
12
|
patternName?: string;
|
|
13
13
|
edgeActions?: OutputAction[];
|
|
14
14
|
};
|
|
@@ -18,7 +18,7 @@ interface TransformFlags {
|
|
|
18
18
|
transformsInsert?: boolean;
|
|
19
19
|
transformsUpdate?: boolean;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
|
|
22
22
|
actions: OutputAction[];
|
|
23
23
|
assocEdges: ProcessedAssocEdge[];
|
|
24
24
|
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
|
@@ -26,10 +26,10 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
|
|
|
26
26
|
schemaPath?: string;
|
|
27
27
|
patternNames?: string[];
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
30
30
|
edgeAction?: OutputAction;
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
type OutputAction = Omit<Action, "actionOnlyFields"> & {
|
|
33
33
|
actionOnlyFields?: ProcessedActionField[];
|
|
34
34
|
};
|
|
35
35
|
interface schemasDict {
|
|
@@ -41,12 +41,12 @@ interface ProcessedPattern {
|
|
|
41
41
|
fields: ProcessedField[];
|
|
42
42
|
disableMixin?: boolean;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
|
|
45
45
|
subFields?: ProcessedField[];
|
|
46
46
|
listElemType?: ProcessedType;
|
|
47
47
|
unionFields?: ProcessedField[];
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
|
|
50
50
|
name: string;
|
|
51
51
|
hasDefaultValueOnCreate?: boolean;
|
|
52
52
|
hasDefaultValueOnEdit?: boolean;
|
package/schema/base_schema.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldMap, Pattern, FieldOverrideMap } from "./schema";
|
|
2
2
|
import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
|
|
3
3
|
export declare const Timestamps: Pattern;
|
|
4
4
|
export declare const Node: Pattern;
|
|
5
5
|
export interface SchemaConfig extends Schema {
|
|
6
6
|
}
|
|
7
7
|
export declare class EntSchema implements Schema {
|
|
8
|
-
fields: FieldMap
|
|
8
|
+
fields: FieldMap;
|
|
9
9
|
fieldOverrides: FieldOverrideMap | undefined;
|
|
10
10
|
tableName: string | undefined;
|
|
11
11
|
patterns: Pattern[];
|
|
@@ -22,7 +22,7 @@ export declare class EntSchema implements Schema {
|
|
|
22
22
|
constructor(cfg: SchemaConfig);
|
|
23
23
|
}
|
|
24
24
|
export declare class EntSchemaWithTZ implements Schema {
|
|
25
|
-
fields: FieldMap
|
|
25
|
+
fields: FieldMap;
|
|
26
26
|
fieldOverrides: FieldOverrideMap | undefined;
|
|
27
27
|
tableName: string | undefined;
|
|
28
28
|
patterns: Pattern[];
|
package/schema/field.js
CHANGED
|
@@ -527,7 +527,7 @@ class EnumField extends BaseField {
|
|
|
527
527
|
}
|
|
528
528
|
if (options.map) {
|
|
529
529
|
let count = 0;
|
|
530
|
-
for (const
|
|
530
|
+
for (const _ in options.map) {
|
|
531
531
|
count++;
|
|
532
532
|
break;
|
|
533
533
|
}
|
|
@@ -594,7 +594,7 @@ class IntegerEnumField extends BaseField {
|
|
|
594
594
|
deprecatedIntEnumMap: options.deprecated,
|
|
595
595
|
};
|
|
596
596
|
let count = 0;
|
|
597
|
-
for (const
|
|
597
|
+
for (const _ in options.map) {
|
|
598
598
|
count++;
|
|
599
599
|
break;
|
|
600
600
|
}
|