@kubun/server 0.1.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.
Files changed (51) hide show
  1. package/LICENSE.md +57 -0
  2. package/README.md +11 -0
  3. package/lib/data/cursor.d.ts +8 -0
  4. package/lib/data/cursor.d.ts.map +1 -0
  5. package/lib/data/cursor.js +7 -0
  6. package/lib/data/db.d.ts +31 -0
  7. package/lib/data/db.d.ts.map +1 -0
  8. package/lib/data/db.js +192 -0
  9. package/lib/data/engines/engine.d.ts +6 -0
  10. package/lib/data/engines/engine.d.ts.map +1 -0
  11. package/lib/data/engines/engine.js +12 -0
  12. package/lib/data/engines/postgres.d.ts +25 -0
  13. package/lib/data/engines/postgres.d.ts.map +1 -0
  14. package/lib/data/engines/postgres.js +30 -0
  15. package/lib/data/engines/sqlite.d.ts +24 -0
  16. package/lib/data/engines/sqlite.d.ts.map +1 -0
  17. package/lib/data/engines/sqlite.js +29 -0
  18. package/lib/data/engines/types.d.ts +19 -0
  19. package/lib/data/engines/types.d.ts.map +1 -0
  20. package/lib/data/engines/types.js +1 -0
  21. package/lib/data/graphql.d.ts +24 -0
  22. package/lib/data/graphql.d.ts.map +1 -0
  23. package/lib/data/graphql.js +106 -0
  24. package/lib/data/migrations/0-init.d.ts +4 -0
  25. package/lib/data/migrations/0-init.d.ts.map +1 -0
  26. package/lib/data/migrations/0-init.js +22 -0
  27. package/lib/data/migrations/migrations.d.ts +4 -0
  28. package/lib/data/migrations/migrations.d.ts.map +1 -0
  29. package/lib/data/migrations/migrations.js +6 -0
  30. package/lib/data/mutations.d.ts +4 -0
  31. package/lib/data/mutations.d.ts.map +1 -0
  32. package/lib/data/mutations.js +66 -0
  33. package/lib/data/query-builder.d.ts +12 -0
  34. package/lib/data/query-builder.d.ts.map +1 -0
  35. package/lib/data/query-builder.js +218 -0
  36. package/lib/data/types.d.ts +134 -0
  37. package/lib/data/types.d.ts.map +1 -0
  38. package/lib/data/types.js +1 -0
  39. package/lib/handlers/graph.d.ts +8 -0
  40. package/lib/handlers/graph.d.ts.map +1 -0
  41. package/lib/handlers/graph.js +174 -0
  42. package/lib/handlers/index.d.ts +9 -0
  43. package/lib/handlers/index.d.ts.map +1 -0
  44. package/lib/handlers/index.js +4 -0
  45. package/lib/index.d.ts +3 -0
  46. package/lib/index.d.ts.map +1 -0
  47. package/lib/index.js +2 -0
  48. package/lib/server.d.ts +18 -0
  49. package/lib/server.d.ts.map +1 -0
  50. package/lib/server.js +45 -0
  51. package/package.json +49 -0
@@ -0,0 +1,22 @@
1
+ export function getMigration(engine) {
2
+ const t = engine.types;
3
+ async function up(db) {
4
+ await db.schema.createTable('document_attachments').addColumn('id', t.text, (col)=>col.notNull().primaryKey()).addColumn('data', t.binary, (col)=>col.notNull()).addColumn('created_at', t.timestamp, (col)=>col.defaultTo(engine.functions.now).notNull()).execute();
5
+ await db.schema.createTable('document_models').addColumn('id', t.text, (col)=>col.notNull().primaryKey()).addColumn('version', t.text, (col)=>col.notNull()).addColumn('name', t.text, (col)=>col.notNull()).addColumn('behavior', t.text, (col)=>col.notNull()).addColumn('set_fields', t.json).addColumn('interfaces', t.json, (col)=>col.notNull()).addColumn('schema', t.json, (col)=>col.notNull()).addColumn('fields_meta', t.json, (col)=>col.notNull()).addColumn('created_at', t.timestamp, (col)=>col.defaultTo(engine.functions.now).notNull()).execute();
6
+ await db.schema.createTable('graph_models').addColumn('id', t.uuid, (col)=>col.notNull().primaryKey()).addColumn('name', t.text, (col)=>col.notNull()).addColumn('aliases', t.json, (col)=>col.defaultTo('{}').notNull()).addColumn('created_at', t.timestamp, (col)=>col.defaultTo(engine.functions.now).notNull()).addColumn('updated_at', t.timestamp).execute();
7
+ await db.schema.createTable('graph_document_models').addColumn('graph_model_id', t.uuid, (col)=>col.notNull().references('graph_models.id')).addColumn('document_model_id', t.text, (col)=>col.notNull().references('document_models.id')).addUniqueConstraint('graph_document_models_pkey', [
8
+ 'graph_model_id',
9
+ 'document_model_id'
10
+ ]).execute();
11
+ }
12
+ async function down(db) {
13
+ await db.schema.dropTable('graph_document_models').execute();
14
+ await db.schema.dropTable('graph_models').execute();
15
+ await db.schema.dropTable('document_models').execute();
16
+ await db.schema.dropTable('document_attachments').execute();
17
+ }
18
+ return {
19
+ up,
20
+ down
21
+ };
22
+ }
@@ -0,0 +1,4 @@
1
+ import type { Migration } from 'kysely';
2
+ import type { Engine } from '../engines/types.js';
3
+ export declare function getMigrations(engine: Engine): Record<string, Migration>;
4
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/data/migrations/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAIjD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAEvE"}
@@ -0,0 +1,6 @@
1
+ import { getMigration as migration0 } from './0-init.js';
2
+ export function getMigrations(engine) {
3
+ return {
4
+ migration0: migration0(engine)
5
+ };
6
+ }
@@ -0,0 +1,4 @@
1
+ import type { KubunDB } from './db.js';
2
+ import type { Document } from './types.js';
3
+ export declare function applyMutation(db: KubunDB, token: string): Promise<Document>;
4
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/data/mutations.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAoB1C,wBAAsB,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqDjF"}
@@ -0,0 +1,66 @@
1
+ import * as A from '@automerge/automerge';
2
+ import { fromB64 } from '@enkaku/codec';
3
+ import { verifyToken } from '@enkaku/jwt';
4
+ import { createSchemaType } from '@enkaku/schema';
5
+ import { DocumentID } from '@kubun/id';
6
+ import { documentMutation } from '@kubun/protocol';
7
+ function automergeToData(doc) {
8
+ return JSON.parse(JSON.stringify(doc));
9
+ }
10
+ function createFromAutomerge(bytes) {
11
+ return automergeToData(A.load(bytes));
12
+ }
13
+ function mergeChanges(doc, changes, incremental = false) {
14
+ const current = A.from(doc);
15
+ const updated = incremental ? A.loadIncremental(current, changes) : A.merge(current, A.load(changes));
16
+ return automergeToData(updated);
17
+ }
18
+ const mutationType = createSchemaType(documentMutation);
19
+ export async function applyMutation(db, token) {
20
+ const verified = await verifyToken(token);
21
+ const mutation = mutationType.cast(verified.payload);
22
+ switch(mutation.typ){
23
+ case 'change':
24
+ {
25
+ const id = DocumentID.fromString(mutation.sub);
26
+ const doc = await db.getDocument(id);
27
+ if (doc == null) {
28
+ throw new Error(`Document not found: ${id.toString()}`);
29
+ }
30
+ if (mutation.iss !== doc.owner) {
31
+ // TODO: verify capabilities if issuer is not owner
32
+ throw new Error('Invalid mutation issuer');
33
+ }
34
+ if (mutation.data === null) {
35
+ return await db.saveDocument(id, null);
36
+ }
37
+ if (doc.data === null) {
38
+ throw new Error(`Cannot apply changes to empty document: ${id.toString()}`);
39
+ }
40
+ const data = mergeChanges(doc.data, fromB64(mutation.data), mutation.inc);
41
+ // TODO: content validation using model's schema
42
+ return await db.saveDocument(id, data);
43
+ }
44
+ case 'set':
45
+ {
46
+ const owner = mutation.aud ?? mutation.iss;
47
+ if (mutation.iss !== owner) {
48
+ // TODO: verify capabilities if issuer is not owner
49
+ throw new Error('Invalid mutation issuer');
50
+ }
51
+ const id = DocumentID.fromString(mutation.sub);
52
+ const data = mutation.data === null ? null : createFromAutomerge(fromB64(mutation.data));
53
+ const doc = await db.getDocument(id);
54
+ if (doc === null) {
55
+ return await db.createDocument(id, owner, data, fromB64(mutation.unq));
56
+ }
57
+ if (doc.owner !== owner) {
58
+ throw new Error(`Cannot change owner from ${doc.owner} to ${owner} in document: ${id.toString()}`);
59
+ }
60
+ // TODO: content validation using model's schema
61
+ return await db.saveDocument(id, data);
62
+ }
63
+ default:
64
+ throw new Error('Unsupported mutation type');
65
+ }
66
+ }
@@ -0,0 +1,12 @@
1
+ import type { ConnectionArguments } from 'graphql-relay';
2
+ import type { ExpressionBuilder, ExpressionWrapper, SelectQueryBuilder } from 'kysely';
3
+ import type { AnyValueFilter, Database, DocumentFilter, DocumentOrderBy } from './types.js';
4
+ type DocumentExpressionBuilder = ExpressionBuilder<Database, 'document'>;
5
+ type DocumentExpressionWrapper = ExpressionWrapper<Database, 'document', any>;
6
+ export type DocumentQueryBuilder = SelectQueryBuilder<Database, 'document', Document>;
7
+ export declare function applyPagination(query: DocumentQueryBuilder, args: ConnectionArguments, orderBy?: DocumentOrderBy): [DocumentQueryBuilder, number];
8
+ export declare function applyDocumentFilter(eb: DocumentExpressionBuilder, filter: DocumentFilter, path?: Array<string>): DocumentExpressionWrapper;
9
+ export declare function applyValueFilter(eb: DocumentExpressionBuilder, keys: Array<string>, filter: AnyValueFilter): DocumentExpressionWrapper;
10
+ export declare function applyDocumentOrderBy(queryBuilder: DocumentQueryBuilder, orderBy?: DocumentOrderBy, isReverse?: boolean): [DocumentQueryBuilder, Array<Array<string>> | null];
11
+ export {};
12
+ //# sourceMappingURL=query-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/data/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAGtF,OAAO,KAAK,EACV,cAAc,EACd,QAAQ,EACR,cAAc,EACd,eAAe,EAIhB,MAAM,YAAY,CAAA;AAEnB,KAAK,yBAAyB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AAExE,KAAK,yBAAyB,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAA;AAE7E,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;AAwCrF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,oBAAoB,EAC3B,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,eAAoB,GAC5B,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAYhC;AA+ED,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"}
@@ -0,0 +1,218 @@
1
+ import { parseCursor } from './cursor.js';
2
+ const DEFAULT_LIMIT = 50;
3
+ const MAX_LIMIT = 100;
4
+ function getLimit(value = DEFAULT_LIMIT) {
5
+ return Math.min(value, MAX_LIMIT);
6
+ }
7
+ function getKeyPath(eb, keys) {
8
+ let keyPath = eb.ref('data', '->>');
9
+ for (const key of keys){
10
+ keyPath = keyPath.key(key);
11
+ }
12
+ return keyPath;
13
+ }
14
+ function getOrderByFieldEntry(field) {
15
+ const keys = [];
16
+ let current = field;
17
+ do {
18
+ const [key, value] = Object.entries(current)[0];
19
+ keys.push(key);
20
+ if (typeof value === 'string') {
21
+ return {
22
+ keys,
23
+ direction: value
24
+ };
25
+ }
26
+ current = value;
27
+ }while (current != null)
28
+ throw new Error('Could not extract field entry');
29
+ }
30
+ function orderByDirection(direction, isReversed = false) {
31
+ return isReversed ? direction === 'asc' ? 'desc' : 'asc' : direction;
32
+ }
33
+ export function applyPagination(query, args, orderBy = []) {
34
+ const { first, last, before, after } = args;
35
+ if (first != null) {
36
+ const limit = getLimit(first);
37
+ return [
38
+ applyForwardPagination(query, limit + 1, after, orderBy),
39
+ limit
40
+ ];
41
+ }
42
+ if (last != null) {
43
+ const limit = getLimit(last);
44
+ return [
45
+ applyBackwardPagination(query, limit + 1, before, orderBy),
46
+ limit
47
+ ];
48
+ }
49
+ const limit = getLimit();
50
+ return [
51
+ query.orderBy('created_at', 'asc').limit(limit + 1),
52
+ limit
53
+ ];
54
+ }
55
+ function applyForwardPagination(queryBuilder, limit, after, orderBy) {
56
+ let query = queryBuilder;
57
+ if (after != null) {
58
+ const { id, ts, values } = parseCursor(after);
59
+ if (ts != null) {
60
+ const date = new Date(ts);
61
+ query = query.where((eb)=>{
62
+ return eb.or([
63
+ eb('created_at', '>', date),
64
+ eb('created_at', '=', date).and('id', '>', id)
65
+ ]);
66
+ });
67
+ } else if (values != null) {
68
+ query = query.where((eb)=>{
69
+ const entries = [];
70
+ for (const orderByField of orderBy){
71
+ const entry = getOrderByFieldEntry(orderByField);
72
+ const value = values[entry.keys.join('.')];
73
+ if (value == null) {
74
+ continue;
75
+ }
76
+ const keyPath = getKeyPath(eb, entry.keys);
77
+ entries.push(eb.or([
78
+ eb(keyPath, entry.direction === 'asc' ? '>' : '<', value),
79
+ eb(keyPath, '=', value).and('id', '>', id)
80
+ ]));
81
+ }
82
+ return eb.and(entries);
83
+ });
84
+ }
85
+ }
86
+ return query.orderBy('created_at', 'asc').limit(limit);
87
+ }
88
+ function applyBackwardPagination(queryBuilder, limit, before, orderBy) {
89
+ let query = queryBuilder;
90
+ if (before != null) {
91
+ const { id, ts, values } = parseCursor(before);
92
+ if (ts != null) {
93
+ const date = new Date(ts);
94
+ query = query.where((eb)=>{
95
+ return eb.or([
96
+ eb('created_at', '<', date),
97
+ eb('created_at', '=', date).and('id', '<', id)
98
+ ]);
99
+ });
100
+ } else if (values != null) {
101
+ query = query.where((eb)=>{
102
+ const entries = [];
103
+ for (const orderByField of orderBy){
104
+ const entry = getOrderByFieldEntry(orderByField);
105
+ const value = values[entry.keys.join('.')];
106
+ if (value == null) {
107
+ continue;
108
+ }
109
+ const keyPath = getKeyPath(eb, entry.keys);
110
+ entries.push(eb.or([
111
+ eb(keyPath, entry.direction === 'asc' ? '<' : '>', value),
112
+ eb(keyPath, '=', value).and('id', '>', id)
113
+ ]));
114
+ }
115
+ return eb.and(entries);
116
+ });
117
+ }
118
+ }
119
+ return query.orderBy('created_at', 'desc').limit(limit);
120
+ }
121
+ export function applyDocumentFilter(eb, filter, path = []) {
122
+ const entries = Object.entries(filter);
123
+ if (entries.length !== 1) {
124
+ throw new Error('Invalid document filter');
125
+ }
126
+ const [type, value] = entries[0];
127
+ switch(type){
128
+ case 'where':
129
+ return applyObjectFilter(eb, value, path);
130
+ case 'and':
131
+ return eb.and(value.map((filter)=>{
132
+ return applyDocumentFilter(eb, filter, path);
133
+ }));
134
+ case 'or':
135
+ return eb.or(value.map((filter)=>{
136
+ return applyDocumentFilter(eb, filter, path);
137
+ }));
138
+ case 'not':
139
+ return eb.not(applyDocumentFilter(eb, value, path));
140
+ default:
141
+ throw new Error(`Invalid document filter type: ${type}`);
142
+ }
143
+ }
144
+ function applyObjectFilter(eb, filter, path) {
145
+ const criteria = Object.entries(filter).map(([fieldName, valueFilter])=>{
146
+ // TODO: check if value filter or nested object filter should be applied
147
+ // for nested object, check if embedded or related object
148
+ return applyValueFilter(eb, [
149
+ ...path,
150
+ fieldName
151
+ ], valueFilter);
152
+ });
153
+ return eb.and(criteria);
154
+ }
155
+ export function applyValueFilter(eb, keys, filter) {
156
+ const entries = Object.entries(filter);
157
+ if (entries.length !== 1) {
158
+ throw new Error('Invalid value filter');
159
+ }
160
+ const fieldName = getKeyPath(eb, keys);
161
+ const [type, value] = entries[0];
162
+ switch(type){
163
+ case 'isNull':
164
+ return eb(fieldName, value === true ? 'is' : 'is not', null);
165
+ case 'equalTo':
166
+ return eb(fieldName, '=', value);
167
+ case 'notEqualTo':
168
+ return eb(fieldName, '!=', value);
169
+ case 'in':
170
+ return eb(fieldName, 'in', value);
171
+ case 'notIn':
172
+ return eb(fieldName, 'not in', value);
173
+ case 'lessThan':
174
+ return eb(fieldName, '<', value);
175
+ case 'lessThanOrEqualTo':
176
+ return eb(fieldName, '<=', value);
177
+ case 'greaterThan':
178
+ return eb(fieldName, '>', value);
179
+ case 'greaterThanOrEqualTo':
180
+ return eb(fieldName, '>=', value);
181
+ default:
182
+ throw new Error(`Invalid value filter type: ${type}`);
183
+ }
184
+ }
185
+ export function applyDocumentOrderBy(queryBuilder, orderBy = [], isReverse = false) {
186
+ if (orderBy.length === 0) {
187
+ return [
188
+ queryBuilder.orderBy('created_at', orderByDirection('asc', isReverse)),
189
+ null
190
+ ];
191
+ }
192
+ let query = queryBuilder;
193
+ const paths = [];
194
+ for (const entry of orderBy){
195
+ const [newQuery, path] = applyOrderByField(query, entry, isReverse);
196
+ query = newQuery;
197
+ paths.push(path);
198
+ }
199
+ return [
200
+ query,
201
+ paths
202
+ ];
203
+ }
204
+ function applyOrderByField(query, orderBy, isReverse, path = []) {
205
+ const entries = Object.entries(orderBy);
206
+ if (entries.length !== 1) {
207
+ throw new Error('Invalid order by field');
208
+ }
209
+ const [key, value] = entries[0];
210
+ const keys = [
211
+ ...path,
212
+ key
213
+ ];
214
+ return typeof value === 'string' ? [
215
+ query.orderBy((eb)=>getKeyPath(eb, keys), orderByDirection(value, isReverse)),
216
+ keys
217
+ ] : applyOrderByField(query, value, isReverse, keys);
218
+ }
@@ -0,0 +1,134 @@
1
+ import type { DocumentFieldsMeta, DocumentModelSchema } from '@kubun/protocol';
2
+ import type { ConnectionArguments } from 'graphql-relay';
3
+ import type { ColumnType, Generated, Insertable, JSONColumnType, Selectable, Updateable } from 'kysely';
4
+ export type DocumentData = Record<string, unknown>;
5
+ export type DocumentTable<Data extends DocumentData = DocumentData> = {
6
+ id: string;
7
+ owner: string;
8
+ model: string;
9
+ data: JSONColumnType<Data> | null;
10
+ unique: Uint8Array;
11
+ created_at: ColumnType<Date, string | undefined, never>;
12
+ updated_at: ColumnType<Date, string | undefined, string | undefined>;
13
+ };
14
+ export type Document<Data extends DocumentData = DocumentData> = Selectable<DocumentTable<Data>>;
15
+ export type InsertDocument<Data extends DocumentData = DocumentData> = Insertable<DocumentTable<Data>>;
16
+ export type UpdateDocument<Data extends DocumentData = DocumentData> = Updateable<DocumentTable<Data>>;
17
+ export type DocumentAttachmentTable = {
18
+ id: string;
19
+ data: Uint8Array;
20
+ created_at: ColumnType<Date, string | undefined, never>;
21
+ };
22
+ export type DocumentAttachment = Selectable<DocumentAttachmentTable>;
23
+ export type InsertDocumentAttachment = Insertable<DocumentAttachmentTable>;
24
+ export type DocumentModelTable = {
25
+ id: string;
26
+ version: string;
27
+ name: string;
28
+ behavior: string;
29
+ set_fields: JSONColumnType<Array<string>> | null;
30
+ interfaces: JSONColumnType<Array<string>>;
31
+ schema: JSONColumnType<DocumentModelSchema>;
32
+ fields_meta: JSONColumnType<DocumentFieldsMeta>;
33
+ created_at: ColumnType<Date, string | undefined, never>;
34
+ updated_at: ColumnType<Date, string | undefined, string | undefined>;
35
+ };
36
+ export type DocumentModel = Selectable<DocumentModelTable>;
37
+ export type InsertDocumentModel = Insertable<DocumentModelTable>;
38
+ export type UpdateDocumentModel = Updateable<DocumentModelTable>;
39
+ export type GraphModelTable = {
40
+ id: Generated<string>;
41
+ name: string;
42
+ created_at: ColumnType<Date, string | undefined, never>;
43
+ updated_at: ColumnType<Date, string | undefined, string | undefined>;
44
+ };
45
+ export type GraphModel = Selectable<GraphModelTable>;
46
+ export type InsertGraphModel = Insertable<GraphModelTable>;
47
+ export type UpdateGraphModel = Updateable<GraphModelTable>;
48
+ export type GraphDocumentModelTable = {
49
+ graph_model_id: string;
50
+ document_model_id: string;
51
+ };
52
+ export type GraphDocumentModel = Selectable<GraphDocumentModelTable>;
53
+ export type InsertGraphDocumentModel = Insertable<GraphDocumentModelTable>;
54
+ export type DocumentTables<Models extends Record<string, DocumentData> = Record<string, DocumentData>, Keys = keyof Models> = {
55
+ [K in string & Keys]: DocumentTable<Models[K]>;
56
+ };
57
+ export type Database = {
58
+ document: DocumentTable;
59
+ document_attachments: DocumentAttachmentTable;
60
+ document_models: DocumentModelTable;
61
+ graph_document_models: GraphDocumentModelTable;
62
+ graph_models: GraphModelTable;
63
+ };
64
+ export type BooleanValueFilter = {
65
+ isNull: boolean;
66
+ } | {
67
+ equalTo: boolean;
68
+ };
69
+ export type EnumValueFilter = {
70
+ isNull: boolean;
71
+ } | {
72
+ equalTo: string;
73
+ } | {
74
+ notEqualTo: string;
75
+ } | {
76
+ in: Array<string>;
77
+ } | {
78
+ notIn: Array<string>;
79
+ };
80
+ export type ScalarValueFilter<T = string | number> = {
81
+ isNull: boolean;
82
+ } | {
83
+ equalTo: T;
84
+ } | {
85
+ notEqualTo: T;
86
+ } | {
87
+ in: Array<T>;
88
+ } | {
89
+ notIn: Array<T>;
90
+ } | {
91
+ lessThan: T;
92
+ } | {
93
+ lessThanOrEqualTo: T;
94
+ } | {
95
+ greaterThan: T;
96
+ } | {
97
+ greaterThanOrEqualTo: T;
98
+ };
99
+ export type AnyValueFilter = BooleanValueFilter | EnumValueFilter | ScalarValueFilter;
100
+ export type ObjectValuesFilter = {
101
+ [key: string]: AnyValueFilter | ObjectValuesFilter;
102
+ };
103
+ export type DocumentFilter = {
104
+ where: ObjectValuesFilter;
105
+ } | {
106
+ and: Array<DocumentFilter>;
107
+ } | {
108
+ or: Array<DocumentFilter>;
109
+ } | {
110
+ not: DocumentFilter;
111
+ };
112
+ export type OrderByDirection = 'asc' | 'desc';
113
+ export type OrderByField = {
114
+ [field: string]: OrderByDirection | OrderByField;
115
+ };
116
+ export type DocumentOrderBy = Array<OrderByField>;
117
+ export type CursorDocument = {
118
+ cursor: string;
119
+ document: Document;
120
+ };
121
+ export type ListDocumentsParams = {
122
+ modelIDs: Array<string>;
123
+ docIDS: Array<string>;
124
+ };
125
+ export type QueryDocumentsParams = ConnectionArguments & {
126
+ model: string | null;
127
+ filter?: DocumentFilter;
128
+ orderBy?: DocumentOrderBy;
129
+ };
130
+ export type QueryDocumentsResult = {
131
+ entries: Array<CursorDocument>;
132
+ hasMore: boolean;
133
+ };
134
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/data/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACX,MAAM,QAAQ,CAAA;AAEf,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,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,CAAC,CAAA;IACvD,UAAU,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAA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B,CAAA;CAAE,CAAA;AAEvF,MAAM,MAAM,cAAc,GACtB;IAAE,KAAK,EAAE,kBAAkB,CAAA;CAAE,GAC7B;IAAE,GAAG,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CAAE,GAC9B;IAAE,EAAE,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;CAAE,GAC7B;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA;AAE3B,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,MAAM,CAAA;AAE7C,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,YAAY,CAAA;CAAE,CAAA;AAE/E,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,YAAY,CAAC,CAAA;AAEjD,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACvB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CACtB,CAAA;AAGD,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG;IACvD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,OAAO,CAAC,EAAE,eAAe,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,8 @@
1
+ import type { CommandHandlers } from '@enkaku/server';
2
+ import { type GraphCommands } from '@kubun/protocol';
3
+ import type { KubunDB } from '../data/db.js';
4
+ export type CreateHandlersParams = {
5
+ db: KubunDB;
6
+ };
7
+ export declare function createHandlers(handlersParams: CreateHandlersParams): CommandHandlers<GraphCommands>;
8
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/handlers/graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,iBAAiB,CAAA;AAKxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAc5C,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,OAAO,CAAA;CACZ,CAAA;AAcD,wBAAgB,cAAc,CAC5B,cAAc,EAAE,oBAAoB,GACnC,eAAe,CAAC,aAAa,CAAC,CAwKhC"}