@kubun/db 0.2.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/LICENSE.md ADDED
@@ -0,0 +1,57 @@
1
+ # The Prosperity Public License 3.0.0
2
+
3
+ Contributor: Paul Le Cam
4
+
5
+ Source Code: https://github.com/PaulLeCam/kubun
6
+
7
+ ## Purpose
8
+
9
+ This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
10
+
11
+ ## Agreement
12
+
13
+ In order to receive this license, you have to agree to its rules. Those rules are both obligations under that agreement and conditions to your license. Don't do anything with this software that triggers a rule you can't or won't follow.
14
+
15
+ ## Notices
16
+
17
+ Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
18
+
19
+ ## Commercial Trial
20
+
21
+ Limit your use of this software for commercial purposes to a thirty-day trial period. If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
22
+
23
+ ## Contributions Back
24
+
25
+ Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
26
+
27
+ ## Personal Uses
28
+
29
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
30
+
31
+ ## Noncommercial Organizations
32
+
33
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
34
+
35
+ ## Defense
36
+
37
+ Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
38
+
39
+ ## Copyright
40
+
41
+ The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
42
+
43
+ ## Patent
44
+
45
+ The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
46
+
47
+ ## Reliability
48
+
49
+ The contributor can't revoke this license.
50
+
51
+ ## Excuse
52
+
53
+ You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
54
+
55
+ ## No Liability
56
+
57
+ ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Kubun DB
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ npm install @kubun/db
7
+ ```
8
+
9
+ ## License
10
+
11
+ [Prosperity Public License 3.0.0](LICENSE.md)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../src/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"}
package/lib/cursor.js ADDED
@@ -0,0 +1,7 @@
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/db.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { Adapter } from '@kubun/db-adapter';
2
+ import type { DocumentID, DocumentModelID } from '@kubun/id';
3
+ import type { DocumentModel, DocumentModelsRecord } from '@kubun/protocol';
4
+ import { Kysely, type Migration, type Transaction } from 'kysely';
5
+ import type { Database, Document, DocumentData, GraphModel, InsertDocumentAttachment, ListDocumentsParams, QueryDocumentsParams, QueryDocumentsResult } from './types.js';
6
+ export type Migrations = Record<string, Migration>;
7
+ export type DBParams = {
8
+ adapter: Adapter;
9
+ };
10
+ export type GraphModelWithRecord = GraphModel & {
11
+ record: DocumentModelsRecord;
12
+ };
13
+ export type SaveDocumentParams = {
14
+ id: DocumentID;
15
+ data: DocumentData | null;
16
+ state: Uint8Array | null;
17
+ };
18
+ export type CreateDocumentParams = SaveDocumentParams & {
19
+ owner: string;
20
+ unique: Uint8Array;
21
+ };
22
+ export type CreateGraphParams = {
23
+ aliases?: Record<string, string>;
24
+ id?: string;
25
+ name?: string;
26
+ record: DocumentModelsRecord;
27
+ };
28
+ export type AddDocumentModelParams = {
29
+ transaction: Transaction<Database>;
30
+ id: string;
31
+ graphModelID: string;
32
+ model: DocumentModel;
33
+ };
34
+ export declare class KubunDB {
35
+ #private;
36
+ constructor(params: DBParams);
37
+ /** @internal */
38
+ get adapter(): Adapter;
39
+ getDB<T extends Database>(): Promise<Kysely<T>>;
40
+ getMigrations(): Migrations;
41
+ close(): Promise<void>;
42
+ listGraphs(): Promise<Array<GraphModel>>;
43
+ createGraph(params: CreateGraphParams): Promise<string>;
44
+ getGraph(id: string): Promise<GraphModelWithRecord | null>;
45
+ getDocumentModel(id: DocumentModelID | string): Promise<DocumentModel>;
46
+ getDocument(id: DocumentID): Promise<Document | null>;
47
+ getDocumentStates(ids: Array<string>): Promise<Record<string, Uint8Array | null>>;
48
+ listDocuments(params: ListDocumentsParams): Promise<Array<Document>>;
49
+ queryDocuments(params: QueryDocumentsParams): Promise<QueryDocumentsResult>;
50
+ createDocument(params: CreateDocumentParams): Promise<Document>;
51
+ saveDocument(params: SaveDocumentParams): Promise<Document>;
52
+ addAttachments(attachments: Array<InsertDocumentAttachment>): Promise<void>;
53
+ }
54
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAoC,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAA;AAKnG,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EAEZ,UAAU,EACV,wBAAwB,EAExB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,YAAY,CAAA;AA8BnB,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAElD,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG;IAAE,MAAM,EAAE,oBAAoB,CAAA;CAAE,CAAA;AAEhF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,UAAU,CAAA;IACd,IAAI,EAAE,YAAY,GAAG,IAAI,CAAA;IACzB,KAAK,EAAE,UAAU,GAAG,IAAI,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,GAAG;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM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3E,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IA8B/D,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4B3D,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAQlF"}
package/lib/db.js ADDED
@@ -0,0 +1,255 @@
1
+ import { Kysely, Migrator, ParseJSONResultsPlugin } from 'kysely';
2
+ import { serializeCursor } from './cursor.js';
3
+ import { getMigrations } from './migrations/migrations.js';
4
+ import { applyDocumentFilter, applyDocumentOrderBy, applyPagination } from './query-builder.js';
5
+ function documentModelFromTable(row) {
6
+ const model = {
7
+ version: row.version,
8
+ name: row.name,
9
+ behavior: row.behavior,
10
+ interfaces: row.interfaces,
11
+ schema: row.schema,
12
+ fieldsMeta: row.fields_meta
13
+ };
14
+ if (model.behavior === 'unique') {
15
+ model.uniqueFields = row.unique_fields;
16
+ }
17
+ return model;
18
+ }
19
+ function documentModelToTable(id, model) {
20
+ return {
21
+ id,
22
+ version: model.version,
23
+ name: model.name,
24
+ behavior: model.behavior,
25
+ unique_fields: model.behavior === 'unique' ? JSON.stringify(model.uniqueFields) : null,
26
+ interfaces: JSON.stringify(model.interfaces),
27
+ schema: JSON.stringify(model.schema),
28
+ fields_meta: JSON.stringify(model.fieldsMeta)
29
+ };
30
+ }
31
+ export class KubunDB {
32
+ #adapter;
33
+ #db;
34
+ #ready;
35
+ constructor(params){
36
+ this.#adapter = params.adapter;
37
+ this.#db = new Kysely({
38
+ dialect: this.#adapter.dialect,
39
+ plugins: [
40
+ new ParseJSONResultsPlugin()
41
+ ]
42
+ });
43
+ this.#ready = this.#runMigrations();
44
+ }
45
+ /** @internal */ get adapter() {
46
+ return this.#adapter;
47
+ }
48
+ getDB() {
49
+ return this.#ready.then(()=>this.#db);
50
+ }
51
+ async #runMigrations() {
52
+ const migrator = new Migrator({
53
+ db: this.#db,
54
+ provider: {
55
+ getMigrations: ()=>Promise.resolve(this.getMigrations())
56
+ }
57
+ });
58
+ const result = await migrator.migrateToLatest();
59
+ if (result.error != null) {
60
+ throw result.error;
61
+ }
62
+ }
63
+ getMigrations() {
64
+ return getMigrations(this.#adapter);
65
+ }
66
+ async close() {
67
+ await this.#db.destroy();
68
+ }
69
+ async listGraphs() {
70
+ await this.#ready;
71
+ return await this.#db.selectFrom('kubun_graph_models').selectAll().execute();
72
+ }
73
+ async createGraph(params) {
74
+ await this.#ready;
75
+ const graphModelID = params.id ?? globalThis.crypto.randomUUID();
76
+ const name = params.name ?? graphModelID;
77
+ return await this.#db.transaction().setIsolationLevel('read committed').execute(async (trx)=>{
78
+ await trx.insertInto('kubun_graph_models').values({
79
+ aliases: JSON.stringify(params.aliases ?? {}),
80
+ id: graphModelID,
81
+ name
82
+ }).onConflict((oc)=>oc.doNothing()).execute();
83
+ await Promise.all(Object.entries(params.record).map(async ([id, model])=>{
84
+ await this.#addDocumentModel({
85
+ id,
86
+ graphModelID,
87
+ model,
88
+ transaction: trx
89
+ });
90
+ }));
91
+ return graphModelID;
92
+ });
93
+ }
94
+ async #addDocumentModel(params) {
95
+ const { id, graphModelID, model, transaction } = params;
96
+ const t = this.#adapter.types;
97
+ await this.#ready;
98
+ await transaction.schema.createTable(`k_${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)=>{
99
+ return col.defaultTo(this.#adapter.functions.now).notNull();
100
+ }).addColumn('updated_at', t.timestamp).execute();
101
+ await transaction.insertInto('kubun_document_models').values(documentModelToTable(id, model)).onConflict((oc)=>oc.doNothing()).execute();
102
+ for (const interfaceID of model.interfaces){
103
+ await transaction.insertInto('kubun_document_model_interfaces').values({
104
+ interface_id: interfaceID,
105
+ implementation_id: id
106
+ }).onConflict((oc)=>oc.doNothing()).execute();
107
+ }
108
+ await transaction.insertInto('kubun_graph_document_models').values({
109
+ graph_model_id: graphModelID,
110
+ document_model_id: id
111
+ }).onConflict((oc)=>oc.doNothing()).execute();
112
+ }
113
+ async getGraph(id) {
114
+ await this.#ready;
115
+ const graph = await this.#db.selectFrom('kubun_graph_models').selectAll().where('id', '=', id).executeTakeFirst();
116
+ if (graph == null) {
117
+ return null;
118
+ }
119
+ const record = {};
120
+ const rows = await this.#db.selectFrom('kubun_graph_document_models').innerJoin('kubun_document_models', 'kubun_graph_document_models.document_model_id', 'kubun_document_models.id').selectAll('kubun_document_models').where('kubun_graph_document_models.graph_model_id', '=', id).execute();
121
+ for (const row of rows){
122
+ record[row.id] = documentModelFromTable(row);
123
+ }
124
+ return {
125
+ ...graph,
126
+ record
127
+ };
128
+ }
129
+ async getDocumentModel(id) {
130
+ await this.#ready;
131
+ const row = await this.#db.selectFrom('kubun_document_models').selectAll().where('id', '=', id.toString()).executeTakeFirstOrThrow();
132
+ return documentModelFromTable(row);
133
+ }
134
+ async getDocument(id) {
135
+ await this.#ready;
136
+ const doc = await this.#db.selectFrom(`k_${id.model.toString()}`).selectAll().where('id', '=', id.toString()).executeTakeFirst();
137
+ return doc ?? null;
138
+ }
139
+ async getDocumentStates(ids) {
140
+ await this.#ready;
141
+ const docStates = await this.#db.selectFrom('kubun_document_states').selectAll().where('id', 'in', ids).execute();
142
+ const loaded = {};
143
+ for (const docState of docStates){
144
+ loaded[docState.id] = docState.data;
145
+ }
146
+ return ids.reduce((acc, id)=>{
147
+ acc[id] = loaded[id] ?? null;
148
+ return acc;
149
+ }, {});
150
+ }
151
+ async listDocuments(params) {
152
+ await this.#ready;
153
+ const [first, ...rest] = params.modelIDs;
154
+ let query = this.#db// @ts-ignore unknown table by Kysely
155
+ .selectFrom(`k_${first}`).selectAll().where('id', 'in', params.docIDS);
156
+ for (const model of rest){
157
+ query = query.unionAll((eb)=>{
158
+ // @ts-ignore unknown table by Kysely
159
+ return eb.selectFrom(`k_${model}`).selectAll().where('id', 'in', params.docIDS);
160
+ });
161
+ }
162
+ return await query.execute();
163
+ }
164
+ async queryDocuments(params) {
165
+ const { filter, orderBy, owner, ...pagination } = params;
166
+ const isReverse = params.last != null;
167
+ await this.#ready;
168
+ let query = this.#db.selectFrom(`k_${params.model}`).selectAll();
169
+ if (owner != null) {
170
+ query = query.where('owner', '=', owner);
171
+ }
172
+ if (filter != null) {
173
+ query = query.where((eb)=>applyDocumentFilter(eb, filter));
174
+ }
175
+ const [orderedQuery, orderedFieldsPaths] = applyDocumentOrderBy(query, orderBy, isReverse);
176
+ const [paginatedQuery, limit] = applyPagination(orderedQuery, pagination, orderBy);
177
+ const results = await paginatedQuery.execute();
178
+ const docs = isReverse ? results.slice(0, limit).reverse() : results.slice(0, limit);
179
+ const entries = orderedFieldsPaths ? docs.map((document)=>{
180
+ const values = {};
181
+ // Iterate through all the fields that we order by
182
+ for (const path of orderedFieldsPaths){
183
+ let value = document.data;
184
+ // Iterate through all the keys in the path
185
+ for (const key of path){
186
+ if (value != null) {
187
+ value = value[key];
188
+ }
189
+ }
190
+ // Add the value if set
191
+ if (value != null) {
192
+ values[path.join('.')] = value;
193
+ }
194
+ }
195
+ const cursor = serializeCursor({
196
+ id: document.id,
197
+ values
198
+ });
199
+ return {
200
+ cursor,
201
+ document
202
+ };
203
+ }) : docs.map((document)=>{
204
+ const cursor = serializeCursor({
205
+ id: document.id,
206
+ ts: +document.created_at
207
+ });
208
+ return {
209
+ cursor,
210
+ document
211
+ };
212
+ });
213
+ return {
214
+ entries,
215
+ hasMore: docs.length > limit
216
+ };
217
+ }
218
+ async createDocument(params) {
219
+ await this.#ready;
220
+ const id = params.id.toString();
221
+ const model = params.id.model.toString();
222
+ return await this.#db.transaction().setIsolationLevel('read committed').execute(async (trx)=>{
223
+ const doc = await trx.insertInto(`k_${model}`).values({
224
+ id,
225
+ owner: params.owner,
226
+ model,
227
+ data: this.#adapter.encodeJSON(params.data),
228
+ unique: this.#adapter.encodeBinary(params.unique)
229
+ }).returningAll().executeTakeFirst();
230
+ await trx.insertInto('kubun_document_states').values({
231
+ id,
232
+ data: params.state ? this.#adapter.encodeBinary(params.state) : null
233
+ }).execute();
234
+ return doc;
235
+ });
236
+ }
237
+ async saveDocument(params) {
238
+ await this.#ready;
239
+ const id = params.id.toString();
240
+ return await this.#db.transaction().setIsolationLevel('read committed').execute(async (trx)=>{
241
+ const doc = await trx.updateTable(`k_${params.id.model.toString()}`).set({
242
+ data: params.data ? this.#adapter.encodeJSON(params.data) : null,
243
+ updated_at: new Date().toISOString()
244
+ }).where('id', '=', id).returningAll().executeTakeFirst();
245
+ await trx.updateTable('kubun_document_states').set({
246
+ data: params.state ? this.#adapter.encodeBinary(params.state) : null
247
+ }).where('id', '=', id).execute();
248
+ return doc;
249
+ });
250
+ }
251
+ async addAttachments(attachments) {
252
+ await this.#ready;
253
+ await this.#db.insertInto('kubun_document_attachments').values(attachments).onConflict((oc)=>oc.doNothing()).execute();
254
+ }
255
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { type CreateGraphParams, type DBParams, type GraphModelWithRecord, KubunDB, type Migrations, } from './db.js';
2
+ export type * from './types.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,OAAO,EACP,KAAK,UAAU,GAChB,MAAM,SAAS,CAAA;AAChB,mBAAmB,YAAY,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export { KubunDB } from './db.js';
@@ -0,0 +1,4 @@
1
+ import type { Adapter } from '@kubun/db-adapter';
2
+ import type { Migration } from 'kysely';
3
+ export declare function getMigration(adapter: Adapter): Migration;
4
+ //# sourceMappingURL=0-init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0-init.d.ts","sourceRoot":"","sources":["../../src/migrations/0-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAU,SAAS,EAAE,MAAM,QAAQ,CAAA;AAI/C,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAoFxD"}
@@ -0,0 +1,29 @@
1
+ export function getMigration(adapter) {
2
+ const t = adapter.types;
3
+ async function up(db) {
4
+ await db.schema.createTable('kubun_document_attachments').ifNotExists().addColumn('id', t.text, (col)=>col.notNull().primaryKey()).addColumn('data', t.binary, (col)=>col.notNull()).addColumn('created_at', t.timestamp, (col)=>col.defaultTo(adapter.functions.now).notNull()).execute();
5
+ await db.schema.createTable('kubun_document_models').ifNotExists().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('unique_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(adapter.functions.now).notNull()).execute();
6
+ await db.schema.createTable('kubun_document_model_interfaces').ifNotExists().addColumn('interface_id', t.text, (col)=>col.notNull().references('kubun_document_models.id')).addColumn('implementation_id', t.text, (col)=>col.notNull().references('kubun_document_models.id')).addUniqueConstraint('kubun_document_model_interfaces_pkey', [
7
+ 'interface_id',
8
+ 'implementation_id'
9
+ ]).execute();
10
+ await db.schema.createTable('kubun_document_states').ifNotExists().addColumn('id', t.text, (col)=>col.notNull().primaryKey()).addColumn('data', t.binary).execute();
11
+ await db.schema.createTable('kubun_graph_models').ifNotExists().addColumn('id', t.text, (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(adapter.functions.now).notNull()).addColumn('updated_at', t.timestamp).execute();
12
+ await db.schema.createTable('kubun_graph_document_models').ifNotExists().addColumn('graph_model_id', t.text, (col)=>col.notNull().references('kubun_graph_models.id')).addColumn('document_model_id', t.text, (col)=>col.notNull().references('kubun_document_models.id')).addUniqueConstraint('kubun_graph_document_models_pkey', [
13
+ 'graph_model_id',
14
+ 'document_model_id'
15
+ ]).execute();
16
+ }
17
+ async function down(db) {
18
+ await db.schema.dropTable('kubun_graph_document_models').execute();
19
+ await db.schema.dropTable('kubun_graph_models').execute();
20
+ await db.schema.dropTable('kubun_document_states').execute();
21
+ await db.schema.dropTable('kubun_document_model_interfaces').execute();
22
+ await db.schema.dropTable('kubun_document_models').execute();
23
+ await db.schema.dropTable('kubun_document_attachments').execute();
24
+ }
25
+ return {
26
+ up,
27
+ down
28
+ };
29
+ }
@@ -0,0 +1,4 @@
1
+ import type { Adapter } from '@kubun/db-adapter';
2
+ import type { Migration } from 'kysely';
3
+ export declare function getMigrations(adapter: Adapter): Record<string, Migration>;
4
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/migrations/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAIvC,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAEzE"}
@@ -0,0 +1,6 @@
1
+ import { getMigration as migration0 } from './0-init.js';
2
+ export function getMigrations(adapter) {
3
+ return {
4
+ kubunMigration0: migration0(adapter)
5
+ };
6
+ }
@@ -0,0 +1,11 @@
1
+ import type { ExpressionBuilder, ExpressionWrapper, SelectQueryBuilder } from 'kysely';
2
+ import type { AnyValueFilter, ConnectionArguments, Database, Document, DocumentFilter, DocumentOrderBy } from './types.js';
3
+ type DocumentExpressionBuilder = ExpressionBuilder<Database, 'k_document'>;
4
+ type DocumentExpressionWrapper = ExpressionWrapper<Database, 'k_document', any>;
5
+ export type DocumentQueryBuilder = SelectQueryBuilder<Database, 'k_document', Document>;
6
+ export declare function applyPagination(query: DocumentQueryBuilder, args: ConnectionArguments, orderBy?: DocumentOrderBy): [DocumentQueryBuilder, number];
7
+ export declare function applyDocumentFilter(eb: DocumentExpressionBuilder, filter: DocumentFilter, path?: Array<string>): DocumentExpressionWrapper;
8
+ export declare function applyValueFilter(eb: DocumentExpressionBuilder, keys: Array<string>, filter: AnyValueFilter): DocumentExpressionWrapper;
9
+ export declare function applyDocumentOrderBy(queryBuilder: DocumentQueryBuilder, orderBy?: DocumentOrderBy, isReverse?: boolean): [DocumentQueryBuilder, Array<Array<string>> | null];
10
+ export {};
11
+ //# sourceMappingURL=query-builder.d.ts.map
@@ -0,0 +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,EACV,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,eAAe,EAIhB,MAAM,YAAY,CAAA;AAEnB,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;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
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,155 @@
1
+ import type { DocumentFieldsMeta, DocumentModelSchema } from '@kubun/protocol';
2
+ import type { ColumnType, Insertable, JSONColumnType, Selectable, Updateable } from 'kysely';
3
+ export type ConnectionArguments = {
4
+ before?: string | null;
5
+ after?: string | null;
6
+ first?: number | null;
7
+ last?: number | null;
8
+ };
9
+ export type DocumentData = Record<string, unknown>;
10
+ export type DocumentTable<Data extends DocumentData = DocumentData> = {
11
+ id: string;
12
+ owner: string;
13
+ model: string;
14
+ data: JSONColumnType<Data> | null;
15
+ unique: Uint8Array;
16
+ created_at: ColumnType<Date, string | undefined, never>;
17
+ updated_at: ColumnType<Date, string | undefined, string | undefined>;
18
+ };
19
+ export type Document<Data extends DocumentData = DocumentData> = Selectable<DocumentTable<Data>>;
20
+ export type InsertDocument<Data extends DocumentData = DocumentData> = Insertable<DocumentTable<Data>>;
21
+ export type UpdateDocument<Data extends DocumentData = DocumentData> = Updateable<DocumentTable<Data>>;
22
+ export type DocumentAttachmentTable = {
23
+ id: string;
24
+ data: Uint8Array;
25
+ created_at: ColumnType<Date, string | undefined, never>;
26
+ };
27
+ export type DocumentAttachment = Selectable<DocumentAttachmentTable>;
28
+ export type InsertDocumentAttachment = Insertable<DocumentAttachmentTable>;
29
+ export type DocumentModelTable = {
30
+ id: string;
31
+ version: string;
32
+ name: string;
33
+ behavior: string;
34
+ unique_fields: JSONColumnType<Array<string>> | null;
35
+ interfaces: JSONColumnType<Array<string>>;
36
+ schema: JSONColumnType<DocumentModelSchema>;
37
+ fields_meta: JSONColumnType<DocumentFieldsMeta>;
38
+ created_at: ColumnType<Date, string | undefined, never>;
39
+ updated_at: ColumnType<Date, string | undefined, string | undefined>;
40
+ };
41
+ export type DocumentModel = Selectable<DocumentModelTable>;
42
+ export type InsertDocumentModel = Insertable<DocumentModelTable>;
43
+ export type UpdateDocumentModel = Updateable<DocumentModelTable>;
44
+ export type DocumentModelInterfaceTable = {
45
+ interface_id: string;
46
+ implementation_id: string;
47
+ };
48
+ export type DocumentModelInterface = Selectable<DocumentModelInterfaceTable>;
49
+ export type InsertDocumentModelInterface = Insertable<DocumentModelInterfaceTable>;
50
+ export type DocumentStateTable = {
51
+ id: string;
52
+ data: Uint8Array | null;
53
+ };
54
+ export type DocumentState = Selectable<DocumentStateTable>;
55
+ export type InsertDocumentState = Insertable<DocumentStateTable>;
56
+ export type GraphModelTable = {
57
+ id: string;
58
+ name: string;
59
+ aliases: JSONColumnType<Record<string, string>>;
60
+ created_at: ColumnType<Date, string | undefined, never>;
61
+ updated_at: ColumnType<Date, string | undefined, string | undefined>;
62
+ };
63
+ export type GraphModel = Selectable<GraphModelTable>;
64
+ export type InsertGraphModel = Insertable<GraphModelTable>;
65
+ export type UpdateGraphModel = Updateable<GraphModelTable>;
66
+ export type GraphDocumentModelTable = {
67
+ graph_model_id: string;
68
+ document_model_id: string;
69
+ };
70
+ export type GraphDocumentModel = Selectable<GraphDocumentModelTable>;
71
+ export type InsertGraphDocumentModel = Insertable<GraphDocumentModelTable>;
72
+ export type DocumentTables<Models extends Record<string, DocumentData> = Record<string, DocumentData>, Keys = keyof Models> = {
73
+ [K in string & Keys]: DocumentTable<Models[K]>;
74
+ };
75
+ export type Database = {
76
+ kubun_document_attachments: DocumentAttachmentTable;
77
+ kubun_document_models: DocumentModelTable;
78
+ kubun_document_model_interfaces: DocumentModelInterfaceTable;
79
+ kubun_document_states: DocumentStateTable;
80
+ kubun_graph_document_models: GraphDocumentModelTable;
81
+ kubun_graph_models: GraphModelTable;
82
+ [key: `k_${string}`]: DocumentTable;
83
+ };
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
+ export type CursorDocument = {
138
+ cursor: string;
139
+ document: Document;
140
+ };
141
+ export type ListDocumentsParams = {
142
+ modelIDs: Array<string>;
143
+ docIDS: Array<string>;
144
+ };
145
+ export type QueryDocumentsParams = ConnectionArguments & {
146
+ model: string | null;
147
+ filter?: DocumentFilter;
148
+ orderBy?: DocumentOrderBy;
149
+ owner?: string;
150
+ };
151
+ export type QueryDocumentsResult = {
152
+ entries: Array<CursorDocument>;
153
+ hasMore: boolean;
154
+ };
155
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAE5F,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,EAA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c,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;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA"}
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export { };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@kubun/db",
3
+ "version": "0.2.0",
4
+ "license": "see LICENSE.md",
5
+ "keywords": [],
6
+ "type": "module",
7
+ "main": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "exports": {
10
+ ".": "./lib/index.js"
11
+ },
12
+ "files": [
13
+ "lib/*",
14
+ "LICENSE.md"
15
+ ],
16
+ "sideEffects": false,
17
+ "dependencies": {
18
+ "@enkaku/codec": "^0.11.0",
19
+ "kysely": "^0.27.6"
20
+ },
21
+ "devDependencies": {
22
+ "@kubun/db-adapter": "^0.2.0",
23
+ "@kubun/id": "^0.2.0",
24
+ "@kubun/protocol": "^0.2.0"
25
+ },
26
+ "scripts": {
27
+ "build:clean": "del lib",
28
+ "build:js": "swc src -d ./lib --config-file ../../swc.json --strip-leading-paths",
29
+ "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
30
+ "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
31
+ "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
32
+ "test:types": "tsc --noEmit --skipLibCheck",
33
+ "test:jest": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
34
+ "test:unit": "pnpm rebuild && pnpm run test:jest",
35
+ "test": "pnpm run test:types && pnpm run test:unit"
36
+ }
37
+ }