@snowtop/ent 0.1.25 → 0.1.27
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/operations.d.ts +3 -3
- package/action/operations.js +11 -4
- package/core/base.d.ts +4 -1
- package/core/context.d.ts +1 -1
- package/core/context.js +8 -1
- package/core/ent.d.ts +6 -3
- package/core/ent.js +15 -4
- package/core/loaders/query_loader.d.ts +6 -3
- package/core/loaders/query_loader.js +2 -2
- package/core/query/custom_clause_query.js +7 -7
- package/core/query_impl.js +14 -3
- package/package.json +1 -1
- package/schema/schema.d.ts +1 -0
package/action/operations.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Viewer, Ent, ID, Data, DataOptions, EditRowOptions, LoadEntOptions, Context, CreateRowOptions } from "../core/base";
|
|
1
|
+
import { Builder, WriteOperation } from "../action";
|
|
3
2
|
import { Executor } from "../action/action";
|
|
4
|
-
import {
|
|
3
|
+
import { Context, CreateRowOptions, Data, DataOptions, EditRowOptions, Ent, ID, LoadEntOptions, Viewer } from "../core/base";
|
|
4
|
+
import { Queryer, SyncQueryer } from "../core/db";
|
|
5
5
|
import { AssocEdgeData, parameterizedQueryOptions } from "../core/ent";
|
|
6
6
|
export interface UpdatedOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
7
7
|
operation: WriteOperation;
|
package/action/operations.js
CHANGED
|
@@ -24,12 +24,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ConditionalNodeOperation = exports.ConditionalOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.NoOperation = exports.RawQueryOperation = exports.DeleteNodeOperation = void 0;
|
|
27
|
-
const clause = __importStar(require("../core/clause"));
|
|
28
27
|
const action_1 = require("../action");
|
|
29
|
-
const
|
|
30
|
-
const global_schema_1 = require("../core/global_schema");
|
|
28
|
+
const clause = __importStar(require("../core/clause"));
|
|
31
29
|
const ent_1 = require("../core/ent");
|
|
30
|
+
const global_schema_1 = require("../core/global_schema");
|
|
32
31
|
const query_impl_1 = require("../core/query_impl");
|
|
32
|
+
const schema_1 = require("../schema/schema");
|
|
33
33
|
class DeleteNodeOperation {
|
|
34
34
|
constructor(id, builder, options) {
|
|
35
35
|
this.id = id;
|
|
@@ -224,7 +224,14 @@ class EditNodeOperation {
|
|
|
224
224
|
}
|
|
225
225
|
getReturning() {
|
|
226
226
|
if (this.options.loadEntOptions.fields.length) {
|
|
227
|
-
return `RETURNING ${this.options.loadEntOptions.fields
|
|
227
|
+
return `RETURNING ${this.options.loadEntOptions.fields
|
|
228
|
+
.map((f) => {
|
|
229
|
+
if (typeof f === "object") {
|
|
230
|
+
return `${f.alias}.${f.column}`;
|
|
231
|
+
}
|
|
232
|
+
return f;
|
|
233
|
+
})
|
|
234
|
+
.join(",")}`;
|
|
228
235
|
}
|
|
229
236
|
return `RETURNING *`;
|
|
230
237
|
}
|
package/core/base.d.ts
CHANGED
|
@@ -67,7 +67,10 @@ export interface DataOptions {
|
|
|
67
67
|
context?: Context;
|
|
68
68
|
}
|
|
69
69
|
export interface SelectBaseDataOptions extends DataOptions {
|
|
70
|
-
fields: string
|
|
70
|
+
fields: (string | {
|
|
71
|
+
alias: string;
|
|
72
|
+
column: string;
|
|
73
|
+
})[];
|
|
71
74
|
fieldsAlias?: string;
|
|
72
75
|
disableFieldsAlias?: boolean;
|
|
73
76
|
disableDefaultOrderByAlias?: boolean;
|
package/core/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Viewer, Data, Loader, LoaderWithLoadMany, QueryOptions } from "./base";
|
|
3
2
|
import { IncomingMessage, ServerResponse } from "http";
|
|
3
|
+
import { Data, Loader, LoaderWithLoadMany, QueryOptions, Viewer } from "./base";
|
|
4
4
|
import { Context } from "./base";
|
|
5
5
|
export interface RequestContext<TViewer extends Viewer = Viewer> extends Context<TViewer> {
|
|
6
6
|
authViewer(viewer: TViewer): Promise<void>;
|
package/core/context.js
CHANGED
|
@@ -39,7 +39,14 @@ class ContextCache {
|
|
|
39
39
|
// maybe we just want to store sql queries???
|
|
40
40
|
getkey(options) {
|
|
41
41
|
let parts = [
|
|
42
|
-
options.fields
|
|
42
|
+
options.fields
|
|
43
|
+
.map((f) => {
|
|
44
|
+
if (typeof f === "object") {
|
|
45
|
+
return `${f.alias}.${f.column}`;
|
|
46
|
+
}
|
|
47
|
+
return f;
|
|
48
|
+
})
|
|
49
|
+
.join(","),
|
|
43
50
|
options.clause.instanceKey(),
|
|
44
51
|
];
|
|
45
52
|
if (options.orderby) {
|
package/core/ent.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Context, CreateRowOptions, Data, DataOptions, EdgeQueryableDataOptions, EditRowOptions, Ent, ID, LoadCustomEntOptions, LoadEntOptions, LoadRowOptions, LoadRowsOptions, LoaderWithLoadMany, QueryDataOptions, SelectCustomDataOptions, Viewer } from "./base";
|
|
1
2
|
import { Queryer, SyncQueryer } from "./db";
|
|
2
|
-
import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context, CreateRowOptions, QueryDataOptions, SelectCustomDataOptions, LoaderWithLoadMany } from "./base";
|
|
3
|
-
import * as clause from "./clause";
|
|
4
3
|
import DataLoader from "dataloader";
|
|
4
|
+
import * as clause from "./clause";
|
|
5
5
|
import { OrderBy } from "./query_impl";
|
|
6
6
|
declare class entCacheMap<TViewer extends Viewer, TEnt extends Ent<TViewer>> {
|
|
7
7
|
private viewer;
|
|
@@ -103,7 +103,10 @@ interface GroupQueryOptions<T extends Data, K = keyof T> {
|
|
|
103
103
|
tableName: string;
|
|
104
104
|
clause?: clause.Clause<T, K>;
|
|
105
105
|
groupColumn: K;
|
|
106
|
-
fields: K
|
|
106
|
+
fields: (K | {
|
|
107
|
+
alias: string;
|
|
108
|
+
column: K;
|
|
109
|
+
})[];
|
|
107
110
|
values: any[];
|
|
108
111
|
orderby?: OrderBy;
|
|
109
112
|
limit: number;
|
package/core/ent.js
CHANGED
|
@@ -30,12 +30,12 @@ exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadTwoWayE
|
|
|
30
30
|
exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = void 0;
|
|
31
31
|
const db_1 = __importStar(require("./db"));
|
|
32
32
|
const privacy_1 = require("./privacy");
|
|
33
|
-
const clause = __importStar(require("./clause"));
|
|
34
|
-
const logger_1 = require("./logger");
|
|
35
33
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
34
|
+
const clause = __importStar(require("./clause"));
|
|
36
35
|
const global_schema_1 = require("./global_schema");
|
|
37
|
-
const query_impl_1 = require("./query_impl");
|
|
38
36
|
const loader_1 = require("./loaders/loader");
|
|
37
|
+
const logger_1 = require("./logger");
|
|
38
|
+
const query_impl_1 = require("./query_impl");
|
|
39
39
|
class entCacheMap {
|
|
40
40
|
constructor(viewer, options) {
|
|
41
41
|
this.viewer = viewer;
|
|
@@ -638,8 +638,19 @@ function buildGroupQuery(options) {
|
|
|
638
638
|
}
|
|
639
639
|
// window functions work in sqlite!
|
|
640
640
|
// https://www.sqlite.org/windowfunctions.html
|
|
641
|
+
const fieldString = fields
|
|
642
|
+
.map((f) => {
|
|
643
|
+
if (typeof f === "object") {
|
|
644
|
+
// TS doesn't understand that K can only be a string, so we need
|
|
645
|
+
// for it to treat f as the object we know it is.
|
|
646
|
+
const fObj = f;
|
|
647
|
+
return `${fObj.alias}.${fObj.column}`;
|
|
648
|
+
}
|
|
649
|
+
return f;
|
|
650
|
+
})
|
|
651
|
+
.join(",");
|
|
641
652
|
return [
|
|
642
|
-
`SELECT * FROM (SELECT ${
|
|
653
|
+
`SELECT * FROM (SELECT ${fieldString} OVER (PARTITION BY ${options.groupColumn} ${orderby}) as row_num FROM ${options.tableName} WHERE ${cls.clause(1)}) t WHERE row_num <= ${options.limit}`,
|
|
643
654
|
cls,
|
|
644
655
|
];
|
|
645
656
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Context, EdgeQueryableDataOptions, Loader, LoaderFactory
|
|
1
|
+
import { Context, Data, EdgeQueryableDataOptions, Loader, LoaderFactory } from "../base";
|
|
2
2
|
import * as clause from "../clause";
|
|
3
|
-
import { ObjectLoaderFactory } from "./object_loader";
|
|
4
3
|
import { OrderBy } from "../query_impl";
|
|
4
|
+
import { ObjectLoaderFactory } from "./object_loader";
|
|
5
5
|
declare class QueryDirectLoader<K extends any> implements Loader<K, Data[]> {
|
|
6
6
|
private options;
|
|
7
7
|
private queryOptions?;
|
|
@@ -14,7 +14,10 @@ declare class QueryDirectLoader<K extends any> implements Loader<K, Data[]> {
|
|
|
14
14
|
clearAll(): void;
|
|
15
15
|
}
|
|
16
16
|
interface QueryOptions {
|
|
17
|
-
fields: string
|
|
17
|
+
fields: (string | {
|
|
18
|
+
alias: string;
|
|
19
|
+
column: string;
|
|
20
|
+
})[];
|
|
18
21
|
tableName: string;
|
|
19
22
|
groupCol?: string;
|
|
20
23
|
clause?: clause.Clause;
|
|
@@ -28,11 +28,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.QueryLoaderFactory = void 0;
|
|
30
30
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
31
|
-
const
|
|
31
|
+
const memoizee_1 = __importDefault(require("memoizee"));
|
|
32
32
|
const clause = __importStar(require("../clause"));
|
|
33
|
+
const ent_1 = require("../ent");
|
|
33
34
|
const logger_1 = require("../logger");
|
|
34
35
|
const loader_1 = require("./loader");
|
|
35
|
-
const memoizee_1 = __importDefault(require("memoizee"));
|
|
36
36
|
function getOrderByLocal(options, queryOptions) {
|
|
37
37
|
return (options.orderby ??
|
|
38
38
|
queryOptions?.orderby ?? [
|
|
@@ -67,15 +67,15 @@ class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
|
67
67
|
// sqlite needs as count otherwise it returns count(1)
|
|
68
68
|
let fields = ["count(1) as count"];
|
|
69
69
|
if (this.options.joinBETA) {
|
|
70
|
-
const
|
|
70
|
+
const firstRequestedField = this.options.loadEntOptions.fields[0];
|
|
71
71
|
const alias = this.options.loadEntOptions.fieldsAlias ??
|
|
72
72
|
this.options.loadEntOptions.alias;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
73
|
+
const fieldString = typeof firstRequestedField === "object"
|
|
74
|
+
? `${firstRequestedField.alias}.${firstRequestedField.column}`
|
|
75
|
+
: alias
|
|
76
|
+
? `${alias}.${firstRequestedField}`
|
|
77
|
+
: firstRequestedField;
|
|
78
|
+
fields = [`count(distinct ${fieldString}) as count`];
|
|
79
79
|
}
|
|
80
80
|
const row = await (0, ent_1.loadRow)({
|
|
81
81
|
...this.options.loadEntOptions,
|
package/core/query_impl.js
CHANGED
|
@@ -47,9 +47,20 @@ function getJoinInfo(join, clauseIdx = 1) {
|
|
|
47
47
|
exports.getJoinInfo = getJoinInfo;
|
|
48
48
|
function buildQuery(options) {
|
|
49
49
|
const fieldsAlias = options.fieldsAlias ?? options.alias;
|
|
50
|
-
const fields =
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const fields = options.fields
|
|
51
|
+
.map((f) => {
|
|
52
|
+
if (typeof f === "object") {
|
|
53
|
+
if (!options.disableFieldsAlias) {
|
|
54
|
+
return `${f.alias}.${f.column}`;
|
|
55
|
+
}
|
|
56
|
+
return f.column;
|
|
57
|
+
}
|
|
58
|
+
if (fieldsAlias && !options.disableFieldsAlias) {
|
|
59
|
+
return `${fieldsAlias}.${f}`;
|
|
60
|
+
}
|
|
61
|
+
return f;
|
|
62
|
+
})
|
|
63
|
+
.join(", ");
|
|
53
64
|
// always start at 1
|
|
54
65
|
const parts = [];
|
|
55
66
|
const tableName = options.alias
|
package/package.json
CHANGED