@kubun/db 0.2.2 → 0.3.1
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/db.d.ts +29 -15
- package/lib/db.d.ts.map +1 -1
- package/lib/db.js +38 -9
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/query-builder.d.ts +2 -1
- package/lib/query-builder.d.ts.map +1 -1
- package/lib/query-builder.js +4 -6
- package/lib/types.d.ts +12 -62
- package/lib/types.d.ts.map +1 -1
- package/package.json +6 -6
package/lib/db.d.ts
CHANGED
|
@@ -1,29 +1,43 @@
|
|
|
1
1
|
import { EventEmitter } from '@enkaku/event';
|
|
2
|
-
import type { Adapter } from '@kubun/db-adapter';
|
|
2
|
+
import type { Adapter, AdapterTypes } from '@kubun/db-adapter';
|
|
3
3
|
import { type DocumentID, DocumentModelID } from '@kubun/id';
|
|
4
|
-
import type { DocumentModel, DocumentModelsRecord } from '@kubun/protocol';
|
|
4
|
+
import type { DocumentModel, DocumentModelsRecord, DocumentNode } from '@kubun/protocol';
|
|
5
5
|
import { Kysely, type Migration, type Transaction } from 'kysely';
|
|
6
|
-
import type { Database,
|
|
6
|
+
import type { Database, DocumentData, GraphModel, InsertDocumentAttachment, ListDocumentsParams, QueryDocumentsParams, QueryDocumentsResult } from './types.js';
|
|
7
7
|
export type Migrations = Record<string, Migration>;
|
|
8
|
+
export type DocumentCreatedEvent = {
|
|
9
|
+
type: 'create';
|
|
10
|
+
document: DocumentNode;
|
|
11
|
+
getCursor: () => string;
|
|
12
|
+
};
|
|
13
|
+
export type DocumentUpdatedEvent = {
|
|
14
|
+
type: 'update';
|
|
15
|
+
document: DocumentNode;
|
|
16
|
+
previous: DocumentNode;
|
|
17
|
+
getCursor: () => string;
|
|
18
|
+
};
|
|
19
|
+
export type DocumentSavedEvent = DocumentCreatedEvent | DocumentUpdatedEvent;
|
|
8
20
|
export type DBEvents = {
|
|
9
|
-
'document:
|
|
10
|
-
'document:saved': Document;
|
|
21
|
+
'document:saved': DocumentSavedEvent;
|
|
11
22
|
};
|
|
12
|
-
export type DBParams = {
|
|
13
|
-
adapter: Adapter
|
|
23
|
+
export type DBParams<T extends AdapterTypes = AdapterTypes> = {
|
|
24
|
+
adapter: Adapter<T>;
|
|
14
25
|
};
|
|
15
26
|
export type GraphModelWithRecord = GraphModel & {
|
|
16
27
|
record: DocumentModelsRecord;
|
|
17
28
|
};
|
|
18
|
-
export type
|
|
29
|
+
export type DocumentParams = {
|
|
19
30
|
id: DocumentID;
|
|
20
31
|
data: DocumentData | null;
|
|
21
32
|
state: Uint8Array | null;
|
|
22
33
|
};
|
|
23
|
-
export type CreateDocumentParams =
|
|
34
|
+
export type CreateDocumentParams = DocumentParams & {
|
|
24
35
|
owner: string;
|
|
25
36
|
unique: Uint8Array;
|
|
26
37
|
};
|
|
38
|
+
export type SaveDocumentParams = DocumentParams & {
|
|
39
|
+
existing: DocumentNode;
|
|
40
|
+
};
|
|
27
41
|
export type CreateGraphParams = {
|
|
28
42
|
aliases?: Record<string, string>;
|
|
29
43
|
id?: string;
|
|
@@ -36,9 +50,9 @@ export type AddDocumentModelParams = {
|
|
|
36
50
|
graphModelID: string;
|
|
37
51
|
model: DocumentModel;
|
|
38
52
|
};
|
|
39
|
-
export declare class KubunDB {
|
|
53
|
+
export declare class KubunDB<T extends AdapterTypes = AdapterTypes> {
|
|
40
54
|
#private;
|
|
41
|
-
constructor(params: DBParams);
|
|
55
|
+
constructor(params: DBParams<T>);
|
|
42
56
|
/** @internal */
|
|
43
57
|
get adapter(): Adapter;
|
|
44
58
|
get events(): EventEmitter<DBEvents>;
|
|
@@ -49,12 +63,12 @@ export declare class KubunDB {
|
|
|
49
63
|
createGraph(params: CreateGraphParams): Promise<string>;
|
|
50
64
|
getGraph(id: string): Promise<GraphModelWithRecord | null>;
|
|
51
65
|
getDocumentModel(id: DocumentModelID | string): Promise<DocumentModel>;
|
|
52
|
-
getDocument(id: DocumentID): Promise<
|
|
66
|
+
getDocument(id: DocumentID): Promise<DocumentNode | null>;
|
|
53
67
|
getDocumentStates(ids: Array<string>): Promise<Record<string, Uint8Array | null>>;
|
|
54
|
-
listDocuments(params: ListDocumentsParams): Promise<Array<
|
|
68
|
+
listDocuments(params: ListDocumentsParams): Promise<Array<DocumentNode>>;
|
|
55
69
|
queryDocuments(params: QueryDocumentsParams): Promise<QueryDocumentsResult>;
|
|
56
|
-
createDocument(params: CreateDocumentParams): Promise<
|
|
57
|
-
saveDocument(params: SaveDocumentParams): Promise<
|
|
70
|
+
createDocument(params: CreateDocumentParams): Promise<DocumentNode>;
|
|
71
|
+
saveDocument(params: SaveDocumentParams): Promise<DocumentNode>;
|
|
58
72
|
addAttachments(attachments: Array<InsertDocumentAttachment>): Promise<void>;
|
|
59
73
|
}
|
|
60
74
|
//# sourceMappingURL=db.d.ts.map
|
package/lib/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAmB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/E,OAAO,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACxF,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAoC,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAA;AAKnG,OAAO,KAAK,EACV,QAAQ,EAER,YAAY,EAEZ,UAAU,EACV,wBAAwB,EAExB,mB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C,YAAY,CAAC,CAAC;IAexE,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgD3E,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,YAAY,CAAC;IAyCnE,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAuC/D,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAQlF"}
|
package/lib/db.js
CHANGED
|
@@ -30,6 +30,16 @@ function documentModelToTable(id, model) {
|
|
|
30
30
|
fields_meta: JSON.stringify(model.fieldsMeta)
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
function documentNodeFromTable(adapter, doc) {
|
|
34
|
+
return {
|
|
35
|
+
id: doc.id,
|
|
36
|
+
model: doc.model,
|
|
37
|
+
owner: doc.owner,
|
|
38
|
+
data: doc.data,
|
|
39
|
+
createdAt: adapter.decodeTimestamp(doc.created_at),
|
|
40
|
+
updatedAt: doc.updated_at ? adapter.decodeTimestamp(doc.updated_at) : null
|
|
41
|
+
};
|
|
42
|
+
}
|
|
33
43
|
function toGlobalInterfaceID(modelID, interfaceID) {
|
|
34
44
|
const id = DocumentModelID.fromString(interfaceID);
|
|
35
45
|
return id.isLocal ? id.toGlobal(DocumentModelID.fromString(modelID)).toString() : interfaceID;
|
|
@@ -156,7 +166,7 @@ export class KubunDB {
|
|
|
156
166
|
async getDocument(id) {
|
|
157
167
|
await this.#ready;
|
|
158
168
|
const doc = await this.#db.selectFrom(`k_${id.model.toString()}`).selectAll().where('id', '=', id.toString()).executeTakeFirst();
|
|
159
|
-
return doc
|
|
169
|
+
return doc ? documentNodeFromTable(this.#adapter, doc) : null;
|
|
160
170
|
}
|
|
161
171
|
async getDocumentStates(ids) {
|
|
162
172
|
await this.#ready;
|
|
@@ -179,8 +189,10 @@ export class KubunDB {
|
|
|
179
189
|
return eb.selectFrom(`k_${model}`).selectAll().where('id', 'in', params.docIDs);
|
|
180
190
|
});
|
|
181
191
|
}
|
|
182
|
-
|
|
192
|
+
const rows = await query.execute();
|
|
193
|
+
return rows.map((row)=>documentNodeFromTable(this.#adapter, row));
|
|
183
194
|
}
|
|
195
|
+
// TODO: countDocuments() - how to handle it with unionAll?
|
|
184
196
|
async queryDocuments(params) {
|
|
185
197
|
const { filter, modelIDs, orderBy, owner, ...pagination } = params;
|
|
186
198
|
const isReverse = params.last != null;
|
|
@@ -222,7 +234,7 @@ export class KubunDB {
|
|
|
222
234
|
});
|
|
223
235
|
return {
|
|
224
236
|
cursor,
|
|
225
|
-
document
|
|
237
|
+
document: documentNodeFromTable(this.#adapter, document)
|
|
226
238
|
};
|
|
227
239
|
}) : docs.map((document)=>{
|
|
228
240
|
const cursor = serializeCursor({
|
|
@@ -231,7 +243,7 @@ export class KubunDB {
|
|
|
231
243
|
});
|
|
232
244
|
return {
|
|
233
245
|
cursor,
|
|
234
|
-
document
|
|
246
|
+
document: documentNodeFromTable(this.#adapter, document)
|
|
235
247
|
};
|
|
236
248
|
});
|
|
237
249
|
return {
|
|
@@ -257,8 +269,16 @@ export class KubunDB {
|
|
|
257
269
|
}).execute();
|
|
258
270
|
return doc;
|
|
259
271
|
});
|
|
260
|
-
this.#
|
|
261
|
-
|
|
272
|
+
const document = documentNodeFromTable(this.#adapter, doc);
|
|
273
|
+
this.#events.emit('document:saved', {
|
|
274
|
+
type: 'create',
|
|
275
|
+
document,
|
|
276
|
+
getCursor: ()=>serializeCursor({
|
|
277
|
+
id: doc.id,
|
|
278
|
+
ts: +doc.created_at
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
return document;
|
|
262
282
|
}
|
|
263
283
|
async saveDocument(params) {
|
|
264
284
|
await this.#ready;
|
|
@@ -266,15 +286,24 @@ export class KubunDB {
|
|
|
266
286
|
const doc = await this.#db.transaction().setIsolationLevel('read committed').execute(async (trx)=>{
|
|
267
287
|
const doc = await trx.updateTable(`k_${params.id.model.toString()}`).set({
|
|
268
288
|
data: params.data ? this.#adapter.encodeJSON(params.data) : null,
|
|
269
|
-
updated_at: new Date()
|
|
289
|
+
updated_at: this.#adapter.encodeTimestamp(new Date())
|
|
270
290
|
}).where('id', '=', id).returningAll().executeTakeFirst();
|
|
271
291
|
await trx.updateTable('kubun_document_states').set({
|
|
272
292
|
data: params.state ? this.#adapter.encodeBinary(params.state) : null
|
|
273
293
|
}).where('id', '=', id).execute();
|
|
274
294
|
return doc;
|
|
275
295
|
});
|
|
276
|
-
this.#
|
|
277
|
-
|
|
296
|
+
const document = documentNodeFromTable(this.#adapter, doc);
|
|
297
|
+
this.#events.emit('document:saved', {
|
|
298
|
+
type: 'update',
|
|
299
|
+
document,
|
|
300
|
+
previous: params.existing,
|
|
301
|
+
getCursor: ()=>serializeCursor({
|
|
302
|
+
id: doc.id,
|
|
303
|
+
ts: +doc.created_at
|
|
304
|
+
})
|
|
305
|
+
});
|
|
306
|
+
return document;
|
|
278
307
|
}
|
|
279
308
|
async addAttachments(attachments) {
|
|
280
309
|
await this.#ready;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { CreateGraphParams, DBEvents, DBParams, DocumentCreatedEvent, DocumentSavedEvent, GraphModelWithRecord, Migrations, } from './db.js';
|
|
2
|
+
export { KubunDB } from './db.js';
|
|
2
3
|
export type * from './types.js';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,GACX,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,mBAAmB,YAAY,CAAA"}
|
package/lib/query-builder.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { AnyValueFilter, DocumentFilter, DocumentOrderBy } from '@kubun/protocol';
|
|
1
2
|
import type { ExpressionBuilder, ExpressionWrapper, SelectQueryBuilder } from 'kysely';
|
|
2
|
-
import type {
|
|
3
|
+
import type { ConnectionArguments, Database, Document } from './types.js';
|
|
3
4
|
type DocumentExpressionBuilder = ExpressionBuilder<Database, 'k_document'>;
|
|
4
5
|
type DocumentExpressionWrapper = ExpressionWrapper<Database, 'k_document', any>;
|
|
5
6
|
export type DocumentQueryBuilder = SelectQueryBuilder<Database, 'k_document', Document>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAGtF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EAIhB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAGtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEzE,KAAK,yBAAyB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;AAE1E,KAAK,yBAAyB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;AAE/E,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,QAAQ,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAA;AAwCvF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,oBAAoB,EAC3B,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,eAAoB,GAC5B,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAYhC;AA6ED,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,yBAAyB,EAC7B,MAAM,EAAE,cAAc,EACtB,IAAI,GAAE,KAAK,CAAC,MAAM,CAAM,GACvB,yBAAyB,CA0B3B;AAeD,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,yBAAyB,EAC7B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EACnB,MAAM,EAAE,cAAc,GACrB,yBAAyB,CA+B3B;AAED,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,oBAAoB,EAClC,OAAO,GAAE,eAAoB,EAC7B,SAAS,UAAQ,GAChB,CAAC,oBAAoB,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAarD"}
|
package/lib/query-builder.js
CHANGED
|
@@ -57,11 +57,10 @@ function applyForwardPagination(queryBuilder, limit, after, orderBy) {
|
|
|
57
57
|
if (after != null) {
|
|
58
58
|
const { id, ts, values } = parseCursor(after);
|
|
59
59
|
if (ts != null) {
|
|
60
|
-
const date = new Date(ts);
|
|
61
60
|
query = query.where((eb)=>{
|
|
62
61
|
return eb.or([
|
|
63
|
-
eb('created_at', '>',
|
|
64
|
-
eb('created_at', '=',
|
|
62
|
+
eb('created_at', '>', ts),
|
|
63
|
+
eb('created_at', '=', ts).and('id', '>', id)
|
|
65
64
|
]);
|
|
66
65
|
});
|
|
67
66
|
} else if (values != null) {
|
|
@@ -90,11 +89,10 @@ function applyBackwardPagination(queryBuilder, limit, before, orderBy) {
|
|
|
90
89
|
if (before != null) {
|
|
91
90
|
const { id, ts, values } = parseCursor(before);
|
|
92
91
|
if (ts != null) {
|
|
93
|
-
const date = new Date(ts);
|
|
94
92
|
query = query.where((eb)=>{
|
|
95
93
|
return eb.or([
|
|
96
|
-
eb('created_at', '<',
|
|
97
|
-
eb('created_at', '=',
|
|
94
|
+
eb('created_at', '<', ts),
|
|
95
|
+
eb('created_at', '=', ts).and('id', '<', id)
|
|
98
96
|
]);
|
|
99
97
|
});
|
|
100
98
|
} else if (values != null) {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { DocumentFieldsMeta, DocumentModelSchema } from '@kubun/protocol';
|
|
1
|
+
import type { DocumentFieldsMeta, DocumentFilter, DocumentModelSchema, DocumentNode, DocumentOrderBy } from '@kubun/protocol';
|
|
2
2
|
import type { ColumnType, Insertable, JSONColumnType, Selectable, Updateable } from 'kysely';
|
|
3
|
+
type CreatedAtColumn = ColumnType<number, number | undefined, never>;
|
|
4
|
+
type UpdatedAtColumn = ColumnType<number, number | undefined, number | undefined>;
|
|
3
5
|
export type ConnectionArguments = {
|
|
4
6
|
before?: string | null;
|
|
5
7
|
after?: string | null;
|
|
@@ -13,8 +15,8 @@ export type DocumentTable<Data extends DocumentData = DocumentData> = {
|
|
|
13
15
|
model: string;
|
|
14
16
|
data: JSONColumnType<Data> | null;
|
|
15
17
|
unique: Uint8Array;
|
|
16
|
-
created_at:
|
|
17
|
-
updated_at:
|
|
18
|
+
created_at: CreatedAtColumn;
|
|
19
|
+
updated_at: UpdatedAtColumn;
|
|
18
20
|
};
|
|
19
21
|
export type Document<Data extends DocumentData = DocumentData> = Selectable<DocumentTable<Data>>;
|
|
20
22
|
export type InsertDocument<Data extends DocumentData = DocumentData> = Insertable<DocumentTable<Data>>;
|
|
@@ -22,7 +24,7 @@ export type UpdateDocument<Data extends DocumentData = DocumentData> = Updateabl
|
|
|
22
24
|
export type DocumentAttachmentTable = {
|
|
23
25
|
id: string;
|
|
24
26
|
data: Uint8Array;
|
|
25
|
-
created_at:
|
|
27
|
+
created_at: CreatedAtColumn;
|
|
26
28
|
};
|
|
27
29
|
export type DocumentAttachment = Selectable<DocumentAttachmentTable>;
|
|
28
30
|
export type InsertDocumentAttachment = Insertable<DocumentAttachmentTable>;
|
|
@@ -35,8 +37,8 @@ export type DocumentModelTable = {
|
|
|
35
37
|
interfaces: JSONColumnType<Array<string>>;
|
|
36
38
|
schema: JSONColumnType<DocumentModelSchema>;
|
|
37
39
|
fields_meta: JSONColumnType<DocumentFieldsMeta>;
|
|
38
|
-
created_at:
|
|
39
|
-
updated_at:
|
|
40
|
+
created_at: CreatedAtColumn;
|
|
41
|
+
updated_at: UpdatedAtColumn;
|
|
40
42
|
};
|
|
41
43
|
export type DocumentModel = Selectable<DocumentModelTable>;
|
|
42
44
|
export type InsertDocumentModel = Insertable<DocumentModelTable>;
|
|
@@ -57,8 +59,8 @@ export type GraphModelTable = {
|
|
|
57
59
|
id: string;
|
|
58
60
|
name: string;
|
|
59
61
|
aliases: JSONColumnType<Record<string, string>>;
|
|
60
|
-
created_at:
|
|
61
|
-
updated_at:
|
|
62
|
+
created_at: CreatedAtColumn;
|
|
63
|
+
updated_at: UpdatedAtColumn;
|
|
62
64
|
};
|
|
63
65
|
export type GraphModel = Selectable<GraphModelTable>;
|
|
64
66
|
export type InsertGraphModel = Insertable<GraphModelTable>;
|
|
@@ -81,62 +83,9 @@ export type Database = {
|
|
|
81
83
|
kubun_graph_models: GraphModelTable;
|
|
82
84
|
[key: `k_${string}`]: DocumentTable;
|
|
83
85
|
};
|
|
84
|
-
export type BooleanValueFilter = {
|
|
85
|
-
isNull: boolean;
|
|
86
|
-
} | {
|
|
87
|
-
equalTo: boolean;
|
|
88
|
-
};
|
|
89
|
-
export type EnumValueFilter = {
|
|
90
|
-
isNull: boolean;
|
|
91
|
-
} | {
|
|
92
|
-
equalTo: string;
|
|
93
|
-
} | {
|
|
94
|
-
notEqualTo: string;
|
|
95
|
-
} | {
|
|
96
|
-
in: Array<string>;
|
|
97
|
-
} | {
|
|
98
|
-
notIn: Array<string>;
|
|
99
|
-
};
|
|
100
|
-
export type ScalarValueFilter<T = string | number> = {
|
|
101
|
-
isNull: boolean;
|
|
102
|
-
} | {
|
|
103
|
-
equalTo: T;
|
|
104
|
-
} | {
|
|
105
|
-
notEqualTo: T;
|
|
106
|
-
} | {
|
|
107
|
-
in: Array<T>;
|
|
108
|
-
} | {
|
|
109
|
-
notIn: Array<T>;
|
|
110
|
-
} | {
|
|
111
|
-
lessThan: T;
|
|
112
|
-
} | {
|
|
113
|
-
lessThanOrEqualTo: T;
|
|
114
|
-
} | {
|
|
115
|
-
greaterThan: T;
|
|
116
|
-
} | {
|
|
117
|
-
greaterThanOrEqualTo: T;
|
|
118
|
-
};
|
|
119
|
-
export type AnyValueFilter = BooleanValueFilter | EnumValueFilter | ScalarValueFilter;
|
|
120
|
-
export type ObjectValuesFilter = {
|
|
121
|
-
[key: string]: AnyValueFilter | ObjectValuesFilter;
|
|
122
|
-
};
|
|
123
|
-
export type DocumentFilter = {
|
|
124
|
-
where: ObjectValuesFilter;
|
|
125
|
-
} | {
|
|
126
|
-
and: Array<DocumentFilter>;
|
|
127
|
-
} | {
|
|
128
|
-
or: Array<DocumentFilter>;
|
|
129
|
-
} | {
|
|
130
|
-
not: DocumentFilter;
|
|
131
|
-
};
|
|
132
|
-
export type OrderByDirection = 'asc' | 'desc';
|
|
133
|
-
export type OrderByField = {
|
|
134
|
-
[field: string]: OrderByDirection | OrderByField;
|
|
135
|
-
};
|
|
136
|
-
export type DocumentOrderBy = Array<OrderByField>;
|
|
137
86
|
export type CursorDocument = {
|
|
138
87
|
cursor: string;
|
|
139
|
-
document:
|
|
88
|
+
document: DocumentNode;
|
|
140
89
|
};
|
|
141
90
|
export type ListDocumentsParams = {
|
|
142
91
|
modelIDs: Array<string>;
|
|
@@ -152,4 +101,5 @@ export type QueryDocumentsResult = {
|
|
|
152
101
|
entries: Array<CursorDocument>;
|
|
153
102
|
hasMore: boolean;
|
|
154
103
|
};
|
|
104
|
+
export {};
|
|
155
105
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,eAAe,EAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAE5F,KAAK,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,CAAC,CAAA;AACpE,KAAK,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEjF,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAElD,MAAM,MAAM,aAAa,CAAC,IAAI,SAAS,YAAY,GAAG,YAAY,IAAI;IACpE,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACjC,MAAM,EAAE,UAAU,CAAA;IAClB,UAAU,EAAE,eAAe,CAAA;IAC3B,U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
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@enkaku/codec": "^0.
|
|
19
|
-
"@enkaku/event": "^0.
|
|
18
|
+
"@enkaku/codec": "^0.12.0",
|
|
19
|
+
"@enkaku/event": "^0.12.0",
|
|
20
20
|
"kysely": "^0.27.6"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@kubun/db-adapter": "^0.
|
|
24
|
-
"@kubun/id": "^0.
|
|
25
|
-
"@kubun/protocol": "^0.
|
|
23
|
+
"@kubun/db-adapter": "^0.3.1",
|
|
24
|
+
"@kubun/id": "^0.3.0",
|
|
25
|
+
"@kubun/protocol": "^0.3.1"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build:clean": "del lib",
|