@kubun/server 0.1.0 → 0.2.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.
Files changed (55) hide show
  1. package/lib/data/automerge.d.ts +5 -0
  2. package/lib/data/automerge.d.ts.map +1 -0
  3. package/lib/data/automerge.js +8 -0
  4. package/lib/data/graphql.d.ts +4 -4
  5. package/lib/data/graphql.d.ts.map +1 -1
  6. package/lib/data/graphql.js +7 -4
  7. package/lib/data/mutations.d.ts +12 -3
  8. package/lib/data/mutations.d.ts.map +1 -1
  9. package/lib/data/mutations.js +65 -29
  10. package/lib/handlers/document.d.ts +8 -0
  11. package/lib/handlers/document.d.ts.map +1 -0
  12. package/lib/handlers/document.js +30 -0
  13. package/lib/handlers/graph.d.ts +4 -4
  14. package/lib/handlers/graph.d.ts.map +1 -1
  15. package/lib/handlers/graph.js +46 -22
  16. package/lib/handlers/index.d.ts +4 -4
  17. package/lib/handlers/index.d.ts.map +1 -1
  18. package/lib/handlers/index.js +5 -1
  19. package/lib/index.d.ts +2 -2
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +1 -1
  22. package/lib/server.d.ts +11 -9
  23. package/lib/server.d.ts.map +1 -1
  24. package/lib/server.js +15 -16
  25. package/package.json +16 -16
  26. package/lib/data/cursor.d.ts +0 -8
  27. package/lib/data/cursor.d.ts.map +0 -1
  28. package/lib/data/cursor.js +0 -7
  29. package/lib/data/db.d.ts +0 -31
  30. package/lib/data/db.d.ts.map +0 -1
  31. package/lib/data/db.js +0 -192
  32. package/lib/data/engines/engine.d.ts +0 -6
  33. package/lib/data/engines/engine.d.ts.map +0 -1
  34. package/lib/data/engines/engine.js +0 -12
  35. package/lib/data/engines/postgres.d.ts +0 -25
  36. package/lib/data/engines/postgres.d.ts.map +0 -1
  37. package/lib/data/engines/postgres.js +0 -30
  38. package/lib/data/engines/sqlite.d.ts +0 -24
  39. package/lib/data/engines/sqlite.d.ts.map +0 -1
  40. package/lib/data/engines/sqlite.js +0 -29
  41. package/lib/data/engines/types.d.ts +0 -19
  42. package/lib/data/engines/types.d.ts.map +0 -1
  43. package/lib/data/engines/types.js +0 -1
  44. package/lib/data/migrations/0-init.d.ts +0 -4
  45. package/lib/data/migrations/0-init.d.ts.map +0 -1
  46. package/lib/data/migrations/0-init.js +0 -22
  47. package/lib/data/migrations/migrations.d.ts +0 -4
  48. package/lib/data/migrations/migrations.d.ts.map +0 -1
  49. package/lib/data/migrations/migrations.js +0 -6
  50. package/lib/data/query-builder.d.ts +0 -12
  51. package/lib/data/query-builder.d.ts.map +0 -1
  52. package/lib/data/query-builder.js +0 -218
  53. package/lib/data/types.d.ts +0 -134
  54. package/lib/data/types.d.ts.map +0 -1
  55. package/lib/data/types.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/server",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -16,25 +16,24 @@
16
16
  "sideEffects": false,
17
17
  "dependencies": {
18
18
  "@automerge/automerge": "^2.2.8",
19
- "@enkaku/codec": "^0.2.0",
20
- "@enkaku/jwt": "^0.2.3",
21
- "@enkaku/schema": "^0.2.0",
22
- "@enkaku/server": "^0.2.1",
23
- "@enkaku/transport": "^0.2.0",
24
- "better-sqlite3": "^11.4.0",
19
+ "@enkaku/async": "^0.11.0",
20
+ "@enkaku/codec": "^0.11.0",
21
+ "@enkaku/schema": "^0.11.0",
22
+ "@enkaku/server": "^0.11.0",
23
+ "@enkaku/token": "^0.11.0",
24
+ "@enkaku/transport": "^0.11.0",
25
25
  "graphql": "^16.9.0",
26
26
  "graphql-relay": "^0.10.2",
27
- "kysely": "^0.27.4",
28
- "pg": "^8.13.0",
29
- "@kubun/client": "^0.1.0",
30
- "@kubun/id": "^0.1.0",
31
- "@kubun/protocol": "^0.1.0",
32
- "@kubun/graphql": "^0.1.0"
27
+ "@kubun/client": "^0.2.0",
28
+ "@kubun/graphql": "^0.2.0",
29
+ "@kubun/db": "^0.2.1",
30
+ "@kubun/id": "^0.2.0",
31
+ "@kubun/protocol": "^0.2.1"
33
32
  },
34
33
  "devDependencies": {
35
34
  "@databases/pg-test": "^3.1.2",
36
- "@types/better-sqlite3": "^7.6.11",
37
- "@types/pg": "^8.11.10"
35
+ "@kubun/db-postgres": "^0.2.0",
36
+ "@kubun/db-sqlite": "^0.2.0"
38
37
  },
39
38
  "scripts": {
40
39
  "build:clean": "del lib",
@@ -43,7 +42,8 @@
43
42
  "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
44
43
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
45
44
  "test:types": "tsc --noEmit --skipLibCheck",
46
- "test:unit": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
45
+ "test:jest": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
46
+ "test:unit": "pnpm rebuild && pnpm run test:jest",
47
47
  "test": "pnpm run test:types && pnpm run test:unit"
48
48
  }
49
49
  }
@@ -1,8 +0,0 @@
1
- export type CursorData = {
2
- id: string;
3
- ts?: number;
4
- values?: Record<string, unknown>;
5
- };
6
- export declare function parseCursor(cursor: string): CursorData;
7
- export declare function serializeCursor(data: CursorData): string;
8
- //# sourceMappingURL=cursor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../../src/data/cursor.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAEtD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAExD"}
@@ -1,7 +0,0 @@
1
- import { b64uFromJSON, b64uToJSON } from '@enkaku/codec';
2
- export function parseCursor(cursor) {
3
- return b64uToJSON(cursor);
4
- }
5
- export function serializeCursor(data) {
6
- return b64uFromJSON(data);
7
- }
package/lib/data/db.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import type { DocumentID } from '@kubun/id';
2
- import type { DocumentModel, DocumentModelsRecord } from '@kubun/protocol';
3
- import { type Transaction } from 'kysely';
4
- import { type SupportedEngineParams } from './engines/engine.js';
5
- import type { Database, Document, DocumentData, InsertDocumentAttachment, ListDocumentsParams, QueryDocumentsParams, QueryDocumentsResult } from './types.js';
6
- export type KubunDBParams = SupportedEngineParams;
7
- export type CreateGraphParams = {
8
- name: string;
9
- record: DocumentModelsRecord;
10
- };
11
- export type AddDocumentModelParams = {
12
- transaction: Transaction<Database>;
13
- id: string;
14
- graphModelID: string;
15
- model: DocumentModel;
16
- };
17
- export declare class KubunDB {
18
- #private;
19
- constructor(params: KubunDBParams);
20
- close(): Promise<void>;
21
- createGraph(params: CreateGraphParams): Promise<string>;
22
- _addDocumentModel(params: AddDocumentModelParams): Promise<void>;
23
- getGraph(id: string): Promise<DocumentModelsRecord>;
24
- getDocument(id: DocumentID): Promise<Document | null>;
25
- listDocuments(params: ListDocumentsParams): Promise<Array<Document>>;
26
- queryDocuments(params: QueryDocumentsParams): Promise<QueryDocumentsResult>;
27
- createDocument(id: DocumentID, owner: string, data: DocumentData | null, unique: Uint8Array): Promise<Document>;
28
- saveDocument(id: DocumentID, data: DocumentData | null): Promise<Document>;
29
- addAttachments(attachments: Array<InsertDocumentAttachment>): Promise<void>;
30
- }
31
- //# sourceMappingURL=db.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/data/db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAA4C,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGnF,OAAO,EAAE,KAAK,qBAAqB,EAAa,MAAM,qBAAqB,CAAA;AAS3E,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,aAAa,GAAG,qBAAqB,CAAA;AAEjD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,oBAAoB,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,aAAa,CAAA;CACrB,CAAA;AAED,qBAAa,OAAO;;gBAKN,MAAM,EAAE,aAAa;IAsB3B,KAAK;IAIL,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BvD,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyChE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA4BnD,WAAW,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAWrD,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAiBpE,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6C3E,cAAc,CAClB,EAAE,EAAE,UAAU,EACd,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,YAAY,GAAG,IAAI,EACzB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,QAAQ,CAAC;IAiBd,YAAY,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;IAY1E,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAQlF"}
package/lib/data/db.js DELETED
@@ -1,192 +0,0 @@
1
- import { Kysely, Migrator, ParseJSONResultsPlugin } from 'kysely';
2
- import { serializeCursor } from './cursor.js';
3
- import { getEngine } from './engines/engine.js';
4
- import { getMigrations } from './migrations/migrations.js';
5
- import { applyDocumentFilter, applyDocumentOrderBy, applyPagination } from './query-builder.js';
6
- export class KubunDB {
7
- #db;
8
- #engine;
9
- #ready;
10
- constructor(params){
11
- this.#engine = getEngine(params);
12
- this.#db = new Kysely({
13
- dialect: this.#engine.getDialect(),
14
- plugins: [
15
- new ParseJSONResultsPlugin()
16
- ]
17
- });
18
- this.#ready = this.#runMigrations();
19
- }
20
- async #runMigrations() {
21
- const migrator = new Migrator({
22
- db: this.#db,
23
- provider: {
24
- getMigrations: ()=>Promise.resolve(getMigrations(this.#engine))
25
- }
26
- });
27
- const result = await migrator.migrateToLatest();
28
- if (result.error != null) {
29
- throw result.error;
30
- }
31
- }
32
- async close() {
33
- await this.#db.destroy();
34
- }
35
- async createGraph(params) {
36
- await this.#ready;
37
- const graphModelID = globalThis.crypto.randomUUID();
38
- return await this.#db.transaction().setIsolationLevel('read committed').execute(async (trx)=>{
39
- await trx.insertInto('graph_models').values({
40
- id: graphModelID,
41
- name: params.name
42
- }).execute();
43
- await Promise.all(Object.entries(params.record).map(async ([id, model])=>{
44
- await this._addDocumentModel({
45
- id,
46
- graphModelID,
47
- model,
48
- transaction: trx
49
- });
50
- }));
51
- return graphModelID;
52
- });
53
- }
54
- async _addDocumentModel(params) {
55
- const { id, graphModelID, model, transaction } = params;
56
- const t = this.#engine.types;
57
- await this.#ready;
58
- await transaction.schema.createTable(`doc_${id}`).ifNotExists().addColumn('id', t.text, (col)=>col.notNull().primaryKey()).addColumn('owner', t.text, (col)=>col.notNull()).addColumn('model', t.text, (col)=>col.notNull()).addColumn('data', t.json).addColumn('unique', t.binary, (col)=>col.notNull()).addColumn('created_at', t.timestamp, (col)=>{
59
- return col.defaultTo(this.#engine.functions.now).notNull();
60
- }).addColumn('updated_at', t.timestamp).execute();
61
- await transaction.insertInto('document_models').values({
62
- id,
63
- version: model.version,
64
- name: model.name,
65
- behavior: model.behavior,
66
- set_fields: model.behavior === 'set' ? JSON.stringify(model.setFields) : null,
67
- interfaces: JSON.stringify(model.interfaces),
68
- schema: JSON.stringify(model.schema),
69
- fields_meta: JSON.stringify(model.fieldsMeta)
70
- }).onConflict((oc)=>oc.doNothing()).execute();
71
- await transaction.insertInto('graph_document_models').values({
72
- graph_model_id: graphModelID,
73
- document_model_id: id
74
- }).onConflict((oc)=>oc.doNothing()).execute();
75
- }
76
- async getGraph(id) {
77
- await this.#ready;
78
- const record = {};
79
- const rows = await this.#db.selectFrom('graph_document_models').innerJoin('document_models', 'graph_document_models.document_model_id', 'document_models.id').selectAll('document_models').where('graph_document_models.graph_model_id', '=', id).execute();
80
- for (const row of rows){
81
- const model = {
82
- version: row.version,
83
- name: row.name,
84
- behavior: row.behavior,
85
- interfaces: row.interfaces,
86
- schema: row.schema,
87
- fieldsMeta: row.fields_meta
88
- };
89
- if (model.behavior === 'set') {
90
- model.setFields = row.set_fields;
91
- }
92
- record[row.id] = model;
93
- }
94
- return record;
95
- }
96
- async getDocument(id) {
97
- await this.#ready;
98
- const doc = await this.#db// @ts-ignore unknown table by Kysely
99
- .selectFrom(`doc_${id.model.toString()}`).selectAll().where('id', '=', id.toString()).executeTakeFirst();
100
- return doc ?? null;
101
- }
102
- async listDocuments(params) {
103
- await this.#ready;
104
- const [first, ...rest] = params.modelIDs;
105
- let query = this.#db// @ts-ignore unknown table by Kysely
106
- .selectFrom(`doc_${first}`).selectAll().where('id', 'in', params.docIDS);
107
- for (const model of rest){
108
- query = query.unionAll((eb)=>{
109
- // @ts-ignore unknown table by Kysely
110
- return eb.selectFrom(`doc_${model}`).selectAll().where('id', 'in', params.docIDS);
111
- });
112
- }
113
- return await query.execute();
114
- }
115
- async queryDocuments(params) {
116
- const { filter, orderBy, ...pagination } = params;
117
- const isReverse = params.last != null;
118
- await this.#ready;
119
- let query = this.#db// @ts-ignore unknown table by Kysely
120
- .selectFrom(`doc_${params.model}`).selectAll();
121
- if (filter != null) {
122
- query = query.where((eb)=>applyDocumentFilter(eb, filter));
123
- }
124
- const [orderedQuery, orderedFieldsPaths] = applyDocumentOrderBy(query, orderBy, isReverse);
125
- const [paginatedQuery, limit] = applyPagination(orderedQuery, pagination, orderBy);
126
- const results = await paginatedQuery.execute();
127
- const docs = isReverse ? results.slice(0, limit).reverse() : results.slice(0, limit);
128
- const entries = orderedFieldsPaths ? docs.map((document)=>{
129
- const values = {};
130
- // Iterate through all the fields that we order by
131
- for (const path of orderedFieldsPaths){
132
- let value = document.data;
133
- // Iterate through all the keys in the path
134
- for (const key of path){
135
- if (value != null) {
136
- value = value[key];
137
- }
138
- }
139
- // Add the value if set
140
- if (value != null) {
141
- values[path.join('.')] = value;
142
- }
143
- }
144
- const cursor = serializeCursor({
145
- id: document.id,
146
- values
147
- });
148
- return {
149
- cursor,
150
- document
151
- };
152
- }) : docs.map((document)=>{
153
- const cursor = serializeCursor({
154
- id: document.id,
155
- ts: document.created_at.getTime()
156
- });
157
- return {
158
- cursor,
159
- document
160
- };
161
- });
162
- return {
163
- entries,
164
- hasMore: docs.length > limit
165
- };
166
- }
167
- async createDocument(id, owner, data, unique) {
168
- await this.#ready;
169
- const doc = await this.#db// @ts-ignore unknown table by Kysely
170
- .insertInto(`doc_${id.model.toString()}`).values({
171
- id: id.toString(),
172
- owner,
173
- model: id.model.toString(),
174
- data: this.#engine.encodeJSON(data),
175
- unique: this.#engine.encodeBinary(unique)
176
- }).returningAll().executeTakeFirst();
177
- return doc;
178
- }
179
- async saveDocument(id, data) {
180
- await this.#ready;
181
- const doc = await this.#db// @ts-ignore unknown table by Kysely
182
- .updateTable(`doc_${id.model.toString()}`).set({
183
- data: this.#engine.encodeJSON(data),
184
- updated_at: new Date().toISOString()
185
- }).where('id', '=', id.toString()).returningAll().executeTakeFirst();
186
- return doc;
187
- }
188
- async addAttachments(attachments) {
189
- await this.#ready;
190
- await this.#db.insertInto('document_attachments').values(attachments).onConflict((oc)=>oc.doNothing()).execute();
191
- }
192
- }
@@ -1,6 +0,0 @@
1
- import { type PostgresEngineParams } from './postgres.js';
2
- import { type SQLiteEngineParams } from './sqlite.js';
3
- import type { Engine } from './types.js';
4
- export type SupportedEngineParams = PostgresEngineParams | SQLiteEngineParams;
5
- export declare function getEngine(params: SupportedEngineParams): Engine;
6
- //# sourceMappingURL=engine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/data/engines/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG,kBAAkB,CAAA;AAE7E,wBAAgB,SAAS,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAS/D"}
@@ -1,12 +0,0 @@
1
- import { PostgresEngine } from './postgres.js';
2
- import { SQLiteEngine } from './sqlite.js';
3
- export function getEngine(params) {
4
- switch(params.type){
5
- case 'postgres':
6
- return new PostgresEngine(params);
7
- case 'sqlite':
8
- return new SQLiteEngine(params);
9
- default:
10
- throw new Error(`Unsupported engine type ${params.type}`);
11
- }
12
- }
@@ -1,25 +0,0 @@
1
- import { PostgresDialect } from 'kysely';
2
- import type { PoolConfig } from 'pg';
3
- import type { Engine } from './types.js';
4
- export type PostgresEngineParams = {
5
- type: 'postgres';
6
- config: PoolConfig;
7
- };
8
- export declare class PostgresEngine implements Engine {
9
- #private;
10
- functions: {
11
- readonly now: "now()";
12
- };
13
- types: {
14
- readonly binary: "bytea";
15
- readonly json: "jsonb";
16
- readonly text: "text";
17
- readonly timestamp: "timestamptz(3)";
18
- readonly uuid: "uuid";
19
- };
20
- constructor(params: PostgresEngineParams);
21
- getDialect(): PostgresDialect;
22
- encodeBinary(value: Uint8Array): Uint8Array;
23
- encodeJSON(value: unknown): unknown;
24
- }
25
- //# sourceMappingURL=postgres.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../src/data/engines/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAEpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,qBAAa,cAAe,YAAW,MAAM;;IAG3C,SAAS;;MAEC;IAEV,KAAK;;;;;;MAOK;gBAEE,MAAM,EAAE,oBAAoB;IAIxC,UAAU;IAIV,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAI3C,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAGpC"}
@@ -1,30 +0,0 @@
1
- import { PostgresDialect } from 'kysely';
2
- import pg from 'pg';
3
- export class PostgresEngine {
4
- #params;
5
- functions = {
6
- now: 'now()'
7
- };
8
- types = {
9
- binary: 'bytea',
10
- json: 'jsonb',
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
- constructor(params){
17
- this.#params = params;
18
- }
19
- getDialect() {
20
- return new PostgresDialect({
21
- pool: new pg.Pool(this.#params.config)
22
- });
23
- }
24
- encodeBinary(value) {
25
- return value;
26
- }
27
- encodeJSON(value) {
28
- return value;
29
- }
30
- }
@@ -1,24 +0,0 @@
1
- import { SqliteDialect } from 'kysely';
2
- import type { Engine } from './types.js';
3
- export type SQLiteEngineParams = {
4
- type: 'sqlite';
5
- database: string;
6
- };
7
- export declare class SQLiteEngine implements Engine {
8
- #private;
9
- functions: {
10
- readonly now: import("kysely").RawBuilder<string>;
11
- };
12
- types: {
13
- readonly binary: "blob";
14
- readonly json: "jsonb";
15
- readonly text: "text";
16
- readonly timestamp: "integer";
17
- readonly uuid: "text";
18
- };
19
- constructor(params: SQLiteEngineParams);
20
- getDialect(): SqliteDialect;
21
- encodeBinary(value: Uint8Array): Buffer;
22
- encodeJSON(value: unknown): string;
23
- }
24
- //# sourceMappingURL=sqlite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../../src/data/engines/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAO,MAAM,QAAQ,CAAA;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,qBAAa,YAAa,YAAW,MAAM;;IAGzC,SAAS;;MAEC;IAEV,KAAK;;;;;;MAMK;gBAEE,MAAM,EAAE,kBAAkB;IAItC,UAAU;IAIV,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAIvC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAGnC"}
@@ -1,29 +0,0 @@
1
- import SQLite from 'better-sqlite3';
2
- import { SqliteDialect, sql } from 'kysely';
3
- export class SQLiteEngine {
4
- #params;
5
- functions = {
6
- now: sql`(unixepoch())`
7
- };
8
- types = {
9
- binary: 'blob',
10
- json: 'jsonb',
11
- text: 'text',
12
- timestamp: 'integer',
13
- uuid: 'text'
14
- };
15
- constructor(params){
16
- this.#params = params;
17
- }
18
- getDialect() {
19
- return new SqliteDialect({
20
- database: new SQLite(this.#params.database)
21
- });
22
- }
23
- encodeBinary(value) {
24
- return Buffer.from(value);
25
- }
26
- encodeJSON(value) {
27
- return JSON.stringify(value);
28
- }
29
- }
@@ -1,19 +0,0 @@
1
- import type { ColumnDataType, Dialect, RawBuilder } from 'kysely';
2
- export type ColumnTypes = {
3
- binary: ColumnDataType;
4
- json: ColumnDataType;
5
- text: ColumnDataType;
6
- timestamp: ColumnDataType;
7
- uuid: ColumnDataType;
8
- };
9
- export type Functions = {
10
- now: string | RawBuilder<string>;
11
- };
12
- export type Engine = {
13
- functions: Functions;
14
- types: ColumnTypes;
15
- getDialect(): Dialect;
16
- encodeBinary(value: Uint8Array): unknown;
17
- encodeJSON(value: unknown): unknown;
18
- };
19
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/data/engines/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEjE,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,cAAc,CAAA;IACtB,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,cAAc,CAAA;IACpB,SAAS,EAAE,cAAc,CAAA;IACzB,IAAI,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,SAAS,EAAE,SAAS,CAAA;IACpB,KAAK,EAAE,WAAW,CAAA;IAClB,UAAU,IAAI,OAAO,CAAA;IACrB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAA;IACxC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAA;CACpC,CAAA"}
@@ -1 +0,0 @@
1
- export { };
@@ -1,4 +0,0 @@
1
- import type { Migration } from 'kysely';
2
- import type { Engine } from '../engines/types.js';
3
- export declare function getMigration(engine: Engine): Migration;
4
- //# sourceMappingURL=0-init.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"0-init.d.ts","sourceRoot":"","sources":["../../../src/data/migrations/0-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,SAAS,EAAE,MAAM,QAAQ,CAAA;AAE/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAGjD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAmDtD"}
@@ -1,22 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,6 +0,0 @@
1
- import { getMigration as migration0 } from './0-init.js';
2
- export function getMigrations(engine) {
3
- return {
4
- migration0: migration0(engine)
5
- };
6
- }
@@ -1,12 +0,0 @@
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
@@ -1 +0,0 @@
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"}