@graffy/pg 0.19.1-alpha.1 → 0.19.1-alpha.3
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/Db.d.ts +3 -2
- package/filter/getAst.js +3 -1
- package/filter/index.d.ts +0 -1
- package/filter/index.js +0 -1
- package/index.d.ts +1 -1
- package/index.js +11 -8
- package/package.json +5 -14
- package/sql/clauses.d.ts +0 -1
- package/sql/clauses.js +2 -2
- package/filter/filterObject.d.ts +0 -1
- package/filter/filterObject.js +0 -39
package/Db.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export default class Db {
|
|
2
|
+
client: any;
|
|
2
3
|
constructor(connection: any);
|
|
3
|
-
query(sql: any, tableOptions
|
|
4
|
+
query(sql: any, tableOptions?: any): Promise<any>;
|
|
4
5
|
readSql(sql: any, tableOptions: any): Promise<any>;
|
|
5
6
|
writeSql(sql: any, tableOptions: any): Promise<any>;
|
|
6
|
-
ensureSchema(tableOptions: any, typeOids
|
|
7
|
+
ensureSchema(tableOptions: any, typeOids?: any): Promise<void>;
|
|
7
8
|
read(rootQuery: any, tableOptions: any): Promise<{
|
|
8
9
|
key: Uint8Array<ArrayBuffer>;
|
|
9
10
|
end: Uint8Array<ArrayBuffer>;
|
package/filter/getAst.js
CHANGED
|
@@ -134,7 +134,9 @@ function simplify(node) {
|
|
|
134
134
|
if (change) {
|
|
135
135
|
node[1] = [
|
|
136
136
|
...noneq,
|
|
137
|
-
...Object.entries(eqmap).map(([prop, val]) => val.length > 1
|
|
137
|
+
...Object.entries(eqmap).map(([prop, val]) => val.length > 1
|
|
138
|
+
? ['$in', prop, val]
|
|
139
|
+
: ['$eq', prop, val[0]]),
|
|
138
140
|
];
|
|
139
141
|
}
|
|
140
142
|
}
|
package/filter/index.d.ts
CHANGED
package/filter/index.js
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -16,19 +16,22 @@ import Db from "./Db.js";
|
|
|
16
16
|
* @param {string} parentName
|
|
17
17
|
* @returns {TableOpts}
|
|
18
18
|
*/
|
|
19
|
-
function getTableOpts(name, { table, idCol, verCol, joins, schema, verDefault } = {}, parentName = null) {
|
|
19
|
+
function getTableOpts(name, { table, idCol, verCol, joins, schema, verDefault, } = {}, parentName = null) {
|
|
20
20
|
const tableName = table || name;
|
|
21
21
|
return {
|
|
22
22
|
table: table || name,
|
|
23
23
|
idCol: idCol || 'id',
|
|
24
24
|
verCol: verCol || 'updatedAt',
|
|
25
|
-
joins: Object.fromEntries(Object.entries(joins || {}).map(([joinName,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
joins: Object.fromEntries(Object.entries(joins || {}).map(([joinName, joinVal]) => {
|
|
26
|
+
const { refCol = parentName, ...joinOptions } = joinVal;
|
|
27
|
+
return [
|
|
28
|
+
joinName,
|
|
29
|
+
{
|
|
30
|
+
refCol,
|
|
31
|
+
...getTableOpts(joinName, joinOptions, tableName),
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
})),
|
|
32
35
|
schema,
|
|
33
36
|
verDefault,
|
|
34
37
|
};
|
package/package.json
CHANGED
|
@@ -2,18 +2,9 @@
|
|
|
2
2
|
"name": "@graffy/pg",
|
|
3
3
|
"description": "The standard Postgres module for Graffy. Each instance this module mounts a Postgres table as a Graffy subtree.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.19.1-alpha.
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
".": {
|
|
9
|
-
"import": "./index.js",
|
|
10
|
-
"types": "./index.d.ts"
|
|
11
|
-
},
|
|
12
|
-
"./*": {
|
|
13
|
-
"import": "./*.js",
|
|
14
|
-
"types": "./*.d.ts"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
5
|
+
"version": "0.19.1-alpha.3",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./index.js",
|
|
17
8
|
"types": "./index.d.ts",
|
|
18
9
|
"repository": {
|
|
19
10
|
"type": "git",
|
|
@@ -21,8 +12,8 @@
|
|
|
21
12
|
},
|
|
22
13
|
"license": "Apache-2.0",
|
|
23
14
|
"dependencies": {
|
|
24
|
-
"sql-formatter": "^15.7.
|
|
25
|
-
"@graffy/common": "0.19.1-alpha.
|
|
15
|
+
"sql-formatter": "^15.7.4",
|
|
16
|
+
"@graffy/common": "0.19.1-alpha.3",
|
|
26
17
|
"sql-template-tag": "^5.2.1",
|
|
27
18
|
"debug": "^4.4.3"
|
|
28
19
|
},
|
package/sql/clauses.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Sql } from 'sql-template-tag';
|
|
2
2
|
export declare const getJsonBuildTrusted: (variadic: any) => Sql;
|
|
3
3
|
export declare const lookup: (prop: any, options: any) => Sql;
|
|
4
|
-
export declare const lookupNumeric: (prop: any) => Sql;
|
|
5
4
|
export declare const getSelectCols: (options: any, projection?: any) => Sql;
|
|
6
5
|
export declare function cubeLiteralSql(value: any): Sql;
|
|
7
6
|
export declare const getInsert: (rows: any, options: any) => {
|
package/sql/clauses.js
CHANGED
|
@@ -35,7 +35,7 @@ export const lookup = (prop, options) => {
|
|
|
35
35
|
}
|
|
36
36
|
throw Error(`pg.cannot_lookup ${prop}`);
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
const lookupNumeric = (prop) => {
|
|
39
39
|
const [prefix, ...suffix] = prop.split('.');
|
|
40
40
|
return suffix.length
|
|
41
41
|
? sql `CASE WHEN "${raw(prefix)}" #> ${suffix} = 'null'::jsonb
|
|
@@ -213,7 +213,7 @@ function stripAttributes(object) {
|
|
|
213
213
|
if (Array.isArray(object)) {
|
|
214
214
|
return object.map((item) => stripAttributes(item));
|
|
215
215
|
}
|
|
216
|
-
return Object.entries(object).reduce((
|
|
216
|
+
return Object.entries(object).reduce((out, [key, val]) => {
|
|
217
217
|
if (key === '$put' || val === null)
|
|
218
218
|
return out;
|
|
219
219
|
if (out === null)
|
package/filter/filterObject.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function filterObject(filter: any, object: any): boolean;
|
package/filter/filterObject.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { encodePath, unwrapObject } from '@graffy/common';
|
|
2
|
-
import getAst from "./getAst.js";
|
|
3
|
-
export default function filterObject(filter, object) {
|
|
4
|
-
function lookup(path) {
|
|
5
|
-
return unwrapObject(object, encodePath(path));
|
|
6
|
-
}
|
|
7
|
-
function checkNode(ast) {
|
|
8
|
-
switch (ast[0]) {
|
|
9
|
-
case '$eq':
|
|
10
|
-
return lookup(ast[1]) === ast[2];
|
|
11
|
-
case '$ne':
|
|
12
|
-
return lookup(ast[1]) !== ast[2];
|
|
13
|
-
case '$lt':
|
|
14
|
-
return lookup(ast[1]) < ast[2];
|
|
15
|
-
case '$lte':
|
|
16
|
-
return lookup(ast[1]) <= ast[2];
|
|
17
|
-
case '$gt':
|
|
18
|
-
return lookup(ast[1]) > ast[2];
|
|
19
|
-
case '$gte':
|
|
20
|
-
return lookup(ast[1]) >= ast[2];
|
|
21
|
-
case '$in':
|
|
22
|
-
return Array.isArray(ast[2]) && ast[2].includes(lookup(ast[1]));
|
|
23
|
-
case '$nin':
|
|
24
|
-
return !(Array.isArray(ast[2]) && ast[2].includes(lookup(ast[1])));
|
|
25
|
-
case '$cts':
|
|
26
|
-
case '$ctd':
|
|
27
|
-
case '$ovp':
|
|
28
|
-
case '$and':
|
|
29
|
-
case '$or':
|
|
30
|
-
case '$not':
|
|
31
|
-
case '$any':
|
|
32
|
-
case '$all':
|
|
33
|
-
case '$has':
|
|
34
|
-
throw Error('pgfilter.unimplemented');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const rootAst = getAst(filter);
|
|
38
|
-
return checkNode(rootAst);
|
|
39
|
-
}
|