@kubun/db-adapter 0.10.0 → 0.11.0
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/lib/index.js +2 -1
- package/lib/postgres.d.ts +2 -1
- package/lib/postgres.js +124 -25
- package/lib/sqlite.d.ts +2 -1
- package/lib/sqlite.js +123 -14
- package/lib/types.d.ts +9 -0
- package/lib/types.js +1 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export{AbstractPostgresAdapter}from
|
|
1
|
+
export { AbstractPostgresAdapter } from './postgres.js';
|
|
2
|
+
export { AbstractSQLiteAdapter } from './sqlite.js';
|
package/lib/postgres.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Expression, Kysely, RawBuilder } from 'kysely';
|
|
2
|
-
import type { AbstractAdapter, AdapterTypes, ColumnTypes, Functions, SearchHit, SearchIndexConfig, SearchQuery } from './types.js';
|
|
2
|
+
import type { AbstractAdapter, AdapterTypes, ColumnTypes, Functions, NullOrderingTerm, OrderDirection, SearchHit, SearchIndexConfig, SearchQuery } from './types.js';
|
|
3
3
|
export type PostgresTypes = {
|
|
4
4
|
Binary: Uint8Array;
|
|
5
5
|
JSON: unknown;
|
|
@@ -14,6 +14,7 @@ export declare class AbstractPostgresAdapter<T extends AdapterTypes = PostgresTy
|
|
|
14
14
|
decodeTimestamp(value: string): Date;
|
|
15
15
|
coerceFilterValue(value: unknown): unknown;
|
|
16
16
|
numericCast(expression: Expression<unknown>): Expression<number>;
|
|
17
|
+
nullOrdering(_expression: Expression<unknown>, _direction: OrderDirection): NullOrderingTerm;
|
|
17
18
|
readAccessPredicate(params: {
|
|
18
19
|
viewerDID: string;
|
|
19
20
|
groupIDs: Array<string>;
|
package/lib/postgres.js
CHANGED
|
@@ -1,37 +1,136 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
export class AbstractPostgresAdapter {
|
|
3
|
+
functions = {
|
|
4
|
+
now: 'now()'
|
|
5
|
+
};
|
|
6
|
+
types = {
|
|
7
|
+
bigint: 'bigint',
|
|
8
|
+
binary: 'bytea',
|
|
9
|
+
json: 'jsonb',
|
|
10
|
+
serial: 'serial',
|
|
11
|
+
text: 'text',
|
|
12
|
+
// Use 3 digits for timestamps to have millisecond precision, same as JS dates
|
|
13
|
+
timestamp: 'timestamptz(3)',
|
|
14
|
+
uuid: 'uuid'
|
|
15
|
+
};
|
|
16
|
+
encodeBinary(value) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
encodeJSON(value) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
encodeTimestamp(value) {
|
|
23
|
+
return value.toISOString();
|
|
24
|
+
}
|
|
25
|
+
decodeTimestamp(value) {
|
|
26
|
+
return new Date(value);
|
|
27
|
+
}
|
|
28
|
+
coerceFilterValue(value) {
|
|
29
|
+
if (typeof value === 'boolean') {
|
|
30
|
+
return value ? 'true' : 'false';
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
numericCast(expression) {
|
|
35
|
+
return sql`(${expression})::numeric`;
|
|
36
|
+
}
|
|
37
|
+
nullOrdering(_expression, _direction) {
|
|
38
|
+
// Postgres applies SQL-standard null position natively (NULLS LAST on asc, NULLS
|
|
39
|
+
// FIRST on desc) via the dialect's own clause on the field's order-by item.
|
|
40
|
+
return {
|
|
41
|
+
kind: 'native'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
readAccessPredicate(params, modelID) {
|
|
45
|
+
const { viewerDID, groupIDs, circleIDs, serverDefault } = params;
|
|
46
|
+
const docRestrictedParts = [
|
|
47
|
+
sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(data -> 'accessPermissions' -> 'read' -> 'allowedDIDs', '[]'::jsonb)) AS _t WHERE _t = ${viewerDID})`
|
|
48
|
+
];
|
|
49
|
+
if (groupIDs.length > 0) {
|
|
50
|
+
docRestrictedParts.push(sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(data -> 'accessPermissions' -> 'read' -> 'allowedGroups', '[]'::jsonb)) AS _t WHERE _t IN (${sql.join(groupIDs.map((id)=>sql`${id}`))}))`);
|
|
51
|
+
}
|
|
52
|
+
if (circleIDs.length > 0) {
|
|
53
|
+
docRestrictedParts.push(sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(data -> 'accessPermissions' -> 'read' -> 'allowedCircles', '[]'::jsonb)) AS _t WHERE _t IN (${sql.join(circleIDs.map((id)=>sql`${id}`))}))`);
|
|
54
|
+
}
|
|
55
|
+
const docRestricted = docRestrictedParts.reduce((a, b)=>sql`${a} OR ${b}`);
|
|
56
|
+
const madRestrictedParts = [
|
|
57
|
+
sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(_mad.allowed_dids, '[]'::jsonb)) AS _t WHERE _t = ${viewerDID})`
|
|
58
|
+
];
|
|
59
|
+
if (groupIDs.length > 0) {
|
|
60
|
+
madRestrictedParts.push(sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(_mad.allowed_groups, '[]'::jsonb)) AS _t WHERE _t IN (${sql.join(groupIDs.map((id)=>sql`${id}`))}))`);
|
|
61
|
+
}
|
|
62
|
+
if (circleIDs.length > 0) {
|
|
63
|
+
madRestrictedParts.push(sql`EXISTS (SELECT 1 FROM jsonb_array_elements_text(COALESCE(_mad.allowed_circles, '[]'::jsonb)) AS _t WHERE _t IN (${sql.join(circleIDs.map((id)=>sql`${id}`))}))`);
|
|
64
|
+
}
|
|
65
|
+
const madRestricted = madRestrictedParts.reduce((a, b)=>sql`${a} OR ${b}`);
|
|
66
|
+
const serverDefaultCond = serverDefault === 'anyone' ? sql`true` : serverDefault === 'only_owner' ? sql`owner = ${viewerDID}` : sql`false`;
|
|
67
|
+
return sql`(
|
|
68
|
+
owner = ${viewerDID}
|
|
3
69
|
OR (data -> 'accessPermissions' -> 'read' ->> 'level') = 'anyone'
|
|
4
|
-
OR ((data -> 'accessPermissions' -> 'read' ->> 'level') = 'only_owner' AND owner = ${
|
|
5
|
-
OR ((data -> 'accessPermissions' -> 'read' ->> 'level') = 'restricted' AND (${
|
|
70
|
+
OR ((data -> 'accessPermissions' -> 'read' ->> 'level') = 'only_owner' AND owner = ${viewerDID})
|
|
71
|
+
OR ((data -> 'accessPermissions' -> 'read' ->> 'level') = 'restricted' AND (${docRestricted}))
|
|
6
72
|
OR ((data -> 'accessPermissions' -> 'read' ->> 'level') IS NULL AND EXISTS (
|
|
7
73
|
SELECT 1 FROM kubun_graph_user_model_access_defaults AS _mad
|
|
8
|
-
WHERE _mad.owner_did = owner AND _mad.model_id = ${
|
|
74
|
+
WHERE _mad.owner_did = owner AND _mad.model_id = ${modelID} AND _mad.permission_type = 'read'
|
|
9
75
|
AND (
|
|
10
76
|
_mad.access_level = 'anyone'
|
|
11
|
-
OR (_mad.access_level = 'only_owner' AND owner = ${
|
|
12
|
-
OR (_mad.access_level = 'restricted' AND (${
|
|
77
|
+
OR (_mad.access_level = 'only_owner' AND owner = ${viewerDID})
|
|
78
|
+
OR (_mad.access_level = 'restricted' AND (${madRestricted}))
|
|
13
79
|
)
|
|
14
80
|
))
|
|
15
81
|
OR ((data -> 'accessPermissions' -> 'read' ->> 'level') IS NULL AND NOT EXISTS (
|
|
16
82
|
SELECT 1 FROM kubun_graph_user_model_access_defaults AS _mad2
|
|
17
|
-
WHERE _mad2.owner_did = owner AND _mad2.model_id = ${
|
|
18
|
-
) AND (${
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
83
|
+
WHERE _mad2.owner_did = owner AND _mad2.model_id = ${modelID} AND _mad2.permission_type = 'read'
|
|
84
|
+
) AND (${serverDefaultCond}))
|
|
85
|
+
)`;
|
|
86
|
+
}
|
|
87
|
+
async createSearchIndex(db, config) {
|
|
88
|
+
const tableName = `fts_${config.modelID}`;
|
|
89
|
+
const docTableName = `k_${config.modelID}`;
|
|
90
|
+
await sql`
|
|
91
|
+
CREATE TABLE IF NOT EXISTS ${sql.ref(tableName)} (
|
|
92
|
+
document_id TEXT PRIMARY KEY REFERENCES ${sql.ref(docTableName)}(id) ON DELETE CASCADE,
|
|
22
93
|
search_vector tsvector
|
|
23
94
|
)
|
|
24
|
-
`.execute(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
95
|
+
`.execute(db);
|
|
96
|
+
await sql`
|
|
97
|
+
CREATE INDEX IF NOT EXISTS ${sql.ref(`ftsi_${config.modelID}`)}
|
|
98
|
+
ON ${sql.ref(tableName)} USING GIN(search_vector)
|
|
99
|
+
`.execute(db);
|
|
100
|
+
}
|
|
101
|
+
async dropSearchIndex(db, modelID) {
|
|
102
|
+
const tableName = `fts_${modelID}`;
|
|
103
|
+
await sql`DROP TABLE IF EXISTS ${sql.ref(tableName)} CASCADE`.execute(db);
|
|
104
|
+
}
|
|
105
|
+
async updateSearchEntry(db, modelID, documentID, fields, fieldNames) {
|
|
106
|
+
const tableName = `fts_${modelID}`;
|
|
107
|
+
const tsvectorParts = fieldNames.map((f)=>{
|
|
108
|
+
const value = fields[f] ?? '';
|
|
109
|
+
return sql`to_tsvector('simple', ${value})`;
|
|
110
|
+
});
|
|
111
|
+
const tsvectorExpr = tsvectorParts.reduce((acc, part)=>sql`${acc} || ${part}`);
|
|
112
|
+
await sql`
|
|
113
|
+
INSERT INTO ${sql.ref(tableName)} (document_id, search_vector)
|
|
114
|
+
VALUES (${documentID}, ${tsvectorExpr})
|
|
115
|
+
ON CONFLICT (document_id) DO UPDATE SET search_vector = ${tsvectorExpr}
|
|
116
|
+
`.execute(db);
|
|
117
|
+
}
|
|
118
|
+
async removeSearchEntry(db, modelID, documentID) {
|
|
119
|
+
const tableName = `fts_${modelID}`;
|
|
120
|
+
await sql`DELETE FROM ${sql.ref(tableName)} WHERE document_id = ${documentID}`.execute(db);
|
|
121
|
+
}
|
|
122
|
+
async searchIndex(db, params) {
|
|
123
|
+
const tableName = `fts_${params.modelID}`;
|
|
124
|
+
const results = await sql`
|
|
125
|
+
SELECT document_id, ts_rank(search_vector, plainto_tsquery('simple', ${params.query})) AS rank
|
|
126
|
+
FROM ${sql.ref(tableName)}
|
|
127
|
+
WHERE search_vector @@ plainto_tsquery('simple', ${params.query})
|
|
35
128
|
ORDER BY rank DESC
|
|
36
|
-
LIMIT ${
|
|
37
|
-
`.execute(
|
|
129
|
+
LIMIT ${params.limit}
|
|
130
|
+
`.execute(db);
|
|
131
|
+
return results.rows.map((row)=>({
|
|
132
|
+
documentID: row.document_id,
|
|
133
|
+
rank: row.rank
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
}
|
package/lib/sqlite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Expression, Kysely, RawBuilder } from 'kysely';
|
|
2
|
-
import type { AbstractAdapter, AdapterTypes, ColumnTypes, Functions, SearchHit, SearchIndexConfig, SearchQuery } from './types.js';
|
|
2
|
+
import type { AbstractAdapter, AdapterTypes, ColumnTypes, Functions, NullOrderingTerm, OrderDirection, SearchHit, SearchIndexConfig, SearchQuery } from './types.js';
|
|
3
3
|
export type SQLiteTypes = {
|
|
4
4
|
Binary: Uint8Array;
|
|
5
5
|
JSON: string;
|
|
@@ -14,6 +14,7 @@ export declare class AbstractSQLiteAdapter<T extends AdapterTypes = SQLiteTypes>
|
|
|
14
14
|
decodeTimestamp(value: number): Date;
|
|
15
15
|
coerceFilterValue(value: unknown): unknown;
|
|
16
16
|
numericCast(expression: Expression<unknown>): Expression<number>;
|
|
17
|
+
nullOrdering(expression: Expression<unknown>, direction: OrderDirection): NullOrderingTerm;
|
|
17
18
|
readAccessPredicate(params: {
|
|
18
19
|
viewerDID: string;
|
|
19
20
|
groupIDs: Array<string>;
|
package/lib/sqlite.js
CHANGED
|
@@ -1,24 +1,133 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
export class AbstractSQLiteAdapter {
|
|
3
|
+
functions = {
|
|
4
|
+
now: sql`(unixepoch())`
|
|
5
|
+
};
|
|
6
|
+
types = {
|
|
7
|
+
bigint: 'integer',
|
|
8
|
+
binary: 'blob',
|
|
9
|
+
json: 'jsonb',
|
|
10
|
+
serial: 'integer',
|
|
11
|
+
text: 'text',
|
|
12
|
+
timestamp: 'integer',
|
|
13
|
+
uuid: 'text'
|
|
14
|
+
};
|
|
15
|
+
encodeBinary(value) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
encodeJSON(value) {
|
|
19
|
+
return JSON.stringify(value);
|
|
20
|
+
}
|
|
21
|
+
encodeTimestamp(value) {
|
|
22
|
+
// SQLite timestamps are stored in seconds
|
|
23
|
+
return Math.floor(value.getTime() / 1000);
|
|
24
|
+
}
|
|
25
|
+
decodeTimestamp(value) {
|
|
26
|
+
// SQLite timestamps are stored in seconds
|
|
27
|
+
return new Date(value * 1000);
|
|
28
|
+
}
|
|
29
|
+
coerceFilterValue(value) {
|
|
30
|
+
if (typeof value === 'boolean') {
|
|
31
|
+
return value ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
numericCast(expression) {
|
|
36
|
+
return sql`CAST(${expression} AS REAL)`;
|
|
37
|
+
}
|
|
38
|
+
nullOrdering(expression, direction) {
|
|
39
|
+
// SQLite has no NULLS LAST/FIRST clause, so prepend an ascending rank column that
|
|
40
|
+
// buckets nulls last on ascending (rank 1 > 0) and first on descending (rank 0 < 1).
|
|
41
|
+
const nullRank = direction === 'asc' ? 1 : 0;
|
|
42
|
+
const valueRank = direction === 'asc' ? 0 : 1;
|
|
43
|
+
return {
|
|
44
|
+
kind: 'lead',
|
|
45
|
+
expression: sql`CASE WHEN ${expression} IS NULL THEN ${sql.lit(nullRank)} ELSE ${sql.lit(valueRank)} END`
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
readAccessPredicate(params, modelID) {
|
|
49
|
+
const { viewerDID, groupIDs, circleIDs, serverDefault } = params;
|
|
50
|
+
const docRestrictedParts = [
|
|
51
|
+
sql`EXISTS (SELECT 1 FROM json_each(COALESCE(json_extract(data, '$.accessPermissions.read.allowedDIDs'), '[]')) WHERE value = ${viewerDID})`
|
|
52
|
+
];
|
|
53
|
+
if (groupIDs.length > 0) {
|
|
54
|
+
docRestrictedParts.push(sql`EXISTS (SELECT 1 FROM json_each(COALESCE(json_extract(data, '$.accessPermissions.read.allowedGroups'), '[]')) WHERE value IN (${sql.join(groupIDs.map((id)=>sql`${id}`))}))`);
|
|
55
|
+
}
|
|
56
|
+
if (circleIDs.length > 0) {
|
|
57
|
+
docRestrictedParts.push(sql`EXISTS (SELECT 1 FROM json_each(COALESCE(json_extract(data, '$.accessPermissions.read.allowedCircles'), '[]')) WHERE value IN (${sql.join(circleIDs.map((id)=>sql`${id}`))}))`);
|
|
58
|
+
}
|
|
59
|
+
const docRestricted = docRestrictedParts.reduce((a, b)=>sql`${a} OR ${b}`);
|
|
60
|
+
const madRestrictedParts = [
|
|
61
|
+
sql`EXISTS (SELECT 1 FROM json_each(COALESCE(_mad.allowed_dids, '[]')) WHERE value = ${viewerDID})`
|
|
62
|
+
];
|
|
63
|
+
if (groupIDs.length > 0) {
|
|
64
|
+
madRestrictedParts.push(sql`EXISTS (SELECT 1 FROM json_each(COALESCE(_mad.allowed_groups, '[]')) WHERE value IN (${sql.join(groupIDs.map((id)=>sql`${id}`))}))`);
|
|
65
|
+
}
|
|
66
|
+
if (circleIDs.length > 0) {
|
|
67
|
+
madRestrictedParts.push(sql`EXISTS (SELECT 1 FROM json_each(COALESCE(_mad.allowed_circles, '[]')) WHERE value IN (${sql.join(circleIDs.map((id)=>sql`${id}`))}))`);
|
|
68
|
+
}
|
|
69
|
+
const madRestricted = madRestrictedParts.reduce((a, b)=>sql`${a} OR ${b}`);
|
|
70
|
+
const serverDefaultCond = serverDefault === 'anyone' ? sql`1 = 1` : serverDefault === 'only_owner' ? sql`owner = ${viewerDID}` : sql`1 = 0`;
|
|
71
|
+
return sql`(
|
|
72
|
+
owner = ${viewerDID}
|
|
3
73
|
OR json_extract(data, '$.accessPermissions.read.level') = 'anyone'
|
|
4
|
-
OR (json_extract(data, '$.accessPermissions.read.level') = 'only_owner' AND owner = ${
|
|
5
|
-
OR (json_extract(data, '$.accessPermissions.read.level') = 'restricted' AND (${
|
|
74
|
+
OR (json_extract(data, '$.accessPermissions.read.level') = 'only_owner' AND owner = ${viewerDID})
|
|
75
|
+
OR (json_extract(data, '$.accessPermissions.read.level') = 'restricted' AND (${docRestricted}))
|
|
6
76
|
OR (json_extract(data, '$.accessPermissions.read.level') IS NULL AND EXISTS (
|
|
7
77
|
SELECT 1 FROM kubun_graph_user_model_access_defaults AS _mad
|
|
8
|
-
WHERE _mad.owner_did = owner AND _mad.model_id = ${
|
|
78
|
+
WHERE _mad.owner_did = owner AND _mad.model_id = ${modelID} AND _mad.permission_type = 'read'
|
|
9
79
|
AND (
|
|
10
80
|
_mad.access_level = 'anyone'
|
|
11
|
-
OR (_mad.access_level = 'only_owner' AND owner = ${
|
|
12
|
-
OR (_mad.access_level = 'restricted' AND (${
|
|
81
|
+
OR (_mad.access_level = 'only_owner' AND owner = ${viewerDID})
|
|
82
|
+
OR (_mad.access_level = 'restricted' AND (${madRestricted}))
|
|
13
83
|
)
|
|
14
84
|
))
|
|
15
85
|
OR (json_extract(data, '$.accessPermissions.read.level') IS NULL AND NOT EXISTS (
|
|
16
86
|
SELECT 1 FROM kubun_graph_user_model_access_defaults AS _mad2
|
|
17
|
-
WHERE _mad2.owner_did = owner AND _mad2.model_id = ${
|
|
18
|
-
) AND (${
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
87
|
+
WHERE _mad2.owner_did = owner AND _mad2.model_id = ${modelID} AND _mad2.permission_type = 'read'
|
|
88
|
+
) AND (${serverDefaultCond}))
|
|
89
|
+
)`;
|
|
90
|
+
}
|
|
91
|
+
async createSearchIndex(db, config) {
|
|
92
|
+
const tableName = `fts_${config.modelID}`;
|
|
93
|
+
const columns = [
|
|
94
|
+
'document_id UNINDEXED',
|
|
95
|
+
...config.fields
|
|
96
|
+
].join(', ');
|
|
97
|
+
await sql`CREATE VIRTUAL TABLE IF NOT EXISTS ${sql.ref(tableName)} USING fts5(${sql.raw(columns)})`.execute(db);
|
|
98
|
+
}
|
|
99
|
+
async dropSearchIndex(db, modelID) {
|
|
100
|
+
const tableName = `fts_${modelID}`;
|
|
101
|
+
await sql`DROP TABLE IF EXISTS ${sql.ref(tableName)}`.execute(db);
|
|
102
|
+
}
|
|
103
|
+
async updateSearchEntry(db, modelID, documentID, fields, fieldNames) {
|
|
104
|
+
const tableName = `fts_${modelID}`;
|
|
105
|
+
await sql`DELETE FROM ${sql.ref(tableName)} WHERE document_id = ${documentID}`.execute(db);
|
|
106
|
+
const columns = [
|
|
107
|
+
'document_id',
|
|
108
|
+
...fieldNames
|
|
109
|
+
].join(', ');
|
|
110
|
+
const values = [
|
|
111
|
+
documentID,
|
|
112
|
+
...fieldNames.map((f)=>fields[f] ?? '')
|
|
113
|
+
].map((v)=>sql.lit(v));
|
|
114
|
+
await sql`INSERT INTO ${sql.ref(tableName)} (${sql.raw(columns)}) VALUES (${sql.join(values)})`.execute(db);
|
|
115
|
+
}
|
|
116
|
+
async removeSearchEntry(db, modelID, documentID) {
|
|
117
|
+
const tableName = `fts_${modelID}`;
|
|
118
|
+
await sql`DELETE FROM ${sql.ref(tableName)} WHERE document_id = ${documentID}`.execute(db);
|
|
119
|
+
}
|
|
120
|
+
async searchIndex(db, params) {
|
|
121
|
+
const tableName = `fts_${params.modelID}`;
|
|
122
|
+
const results = await sql`
|
|
123
|
+
SELECT document_id, rank FROM ${sql.ref(tableName)}
|
|
124
|
+
WHERE ${sql.ref(tableName)} MATCH ${params.query}
|
|
22
125
|
ORDER BY rank
|
|
23
|
-
LIMIT ${
|
|
24
|
-
`.execute(
|
|
126
|
+
LIMIT ${params.limit}
|
|
127
|
+
`.execute(db);
|
|
128
|
+
return results.rows.map((row)=>({
|
|
129
|
+
documentID: row.document_id,
|
|
130
|
+
rank: row.rank
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { ColumnDataType, ColumnType, Dialect, Expression, Kysely, RawBuilder } from 'kysely';
|
|
2
|
+
export type OrderDirection = 'asc' | 'desc';
|
|
3
|
+
export type NullOrderingTerm = {
|
|
4
|
+
kind: 'lead';
|
|
5
|
+
expression: Expression<number>;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'native';
|
|
8
|
+
};
|
|
2
9
|
export type CreatedAtColumn = ColumnType<number, number | undefined, never>;
|
|
3
10
|
export type UpdatedAtColumn = ColumnType<number, number | undefined, number | undefined>;
|
|
4
11
|
export type ColumnTypes = {
|
|
12
|
+
bigint: ColumnDataType;
|
|
5
13
|
binary: ColumnDataType;
|
|
6
14
|
json: ColumnDataType;
|
|
7
15
|
serial: ColumnDataType;
|
|
@@ -44,6 +52,7 @@ export type AbstractAdapter<T extends AdapterTypes = AdapterTypes> = {
|
|
|
44
52
|
searchIndex(db: Kysely<unknown>, params: SearchQuery): Promise<Array<SearchHit>>;
|
|
45
53
|
coerceFilterValue(value: unknown): unknown;
|
|
46
54
|
numericCast(expression: Expression<unknown>): Expression<number>;
|
|
55
|
+
nullOrdering(expression: Expression<unknown>, direction: OrderDirection): NullOrderingTerm;
|
|
47
56
|
readAccessPredicate(params: {
|
|
48
57
|
viewerDID: string;
|
|
49
58
|
groupIDs: Array<string>;
|
package/lib/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/db-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build:clean": "del lib",
|
|
22
|
-
"build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
|
|
22
|
+
"build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
23
23
|
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
24
24
|
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
25
25
|
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|