@storecraft/database-turso 1.0.21 → 1.0.23
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/README.md +2 -2
- package/index.js +16 -2
- package/package.json +3 -3
- package/tests/runner.test.js +2 -2
- package/types.public.d.ts +2 -1
- package/vector-store/index.js +9 -2
- package/vector-store/types.d.ts +2 -1
package/README.md
CHANGED
@@ -20,7 +20,7 @@ import http from "node:http";
|
|
20
20
|
import { App } from '@storecraft/core'
|
21
21
|
import { NodePlatform } from '@storecraft/core/platform/node';
|
22
22
|
import { NodeLocalStorage } from '@storecraft/core/storage/node'
|
23
|
-
import {
|
23
|
+
import { LibSQL, LibSQLVectorStore } from '@storecraft/database-turso'
|
24
24
|
import { migrateToLatest } from '@storecraft/database-turso/migrate.js'
|
25
25
|
|
26
26
|
const app = new App(
|
@@ -30,7 +30,7 @@ const app = new App(
|
|
30
30
|
)
|
31
31
|
.withPlatform(new NodePlatform())
|
32
32
|
.withDatabase(
|
33
|
-
new
|
33
|
+
new LibSQL(
|
34
34
|
{
|
35
35
|
url: 'file:local.db',
|
36
36
|
}
|
package/index.js
CHANGED
@@ -14,7 +14,7 @@ export { LibSQLVectorStore } from './vector-store/index.js'
|
|
14
14
|
export class Turso extends SQL {
|
15
15
|
|
16
16
|
/** @satisfies {ENV<Config>} */
|
17
|
-
static EnvConfig = /** @type{const} */ ({
|
17
|
+
static EnvConfig = /** @type {const} */ ({
|
18
18
|
authToken: 'LIBSQL_AUTH_TOKEN',
|
19
19
|
url: 'LIBSQL_URL'
|
20
20
|
});
|
@@ -43,9 +43,23 @@ export class Turso extends SQL {
|
|
43
43
|
const dialect = /** @type {LibsqlDialect}*/ (this.config.dialect);
|
44
44
|
const dconfig = dialect.config;
|
45
45
|
|
46
|
+
// optional
|
46
47
|
dconfig.authToken ??= app.platform.env[Turso.EnvConfig.authToken];
|
47
|
-
|
48
|
+
// mandatory
|
49
|
+
dconfig.url ??= (app.platform.env[Turso.EnvConfig.url] ?? 'file:data.db');
|
50
|
+
|
51
|
+
if (!dconfig.url) {
|
52
|
+
console.warn(
|
53
|
+
'LibSQL URL is missing. Please set the LIBSQL_URL environment variable \
|
54
|
+
or programatically in the constructor config. \
|
55
|
+
url was set to local file `file:data.db` instead'
|
56
|
+
);
|
57
|
+
dconfig.url = 'file:data.db';
|
58
|
+
}
|
48
59
|
|
49
60
|
super.init(app);
|
50
61
|
}
|
51
62
|
}
|
63
|
+
|
64
|
+
|
65
|
+
export const LibSQL = Turso;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storecraft/database-turso",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.23",
|
4
4
|
"description": "`Storecraft` database driver for `Turso` (cloud sqlite)",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "Tomer Shalev (https://github.com/store-craft)",
|
@@ -36,10 +36,10 @@
|
|
36
36
|
"database-turso:test": "node ./tests/runner.test.js",
|
37
37
|
"test": "npm run database-turso:test",
|
38
38
|
"prepublishOnly": "npm version patch --force",
|
39
|
-
"sc-publish": "npm publish --access public"
|
39
|
+
"sc-publish": "npm test && npm publish --access public"
|
40
40
|
},
|
41
41
|
"dependencies": {
|
42
|
-
"@libsql/client": "^0.
|
42
|
+
"@libsql/client": "^0.15.4",
|
43
43
|
"@storecraft/core": "^1.0.0",
|
44
44
|
"@storecraft/database-sql-base": "^1.0.0"
|
45
45
|
},
|
package/tests/runner.test.js
CHANGED
@@ -2,7 +2,7 @@ import 'dotenv/config';
|
|
2
2
|
import { App } from '@storecraft/core';
|
3
3
|
import { NodePlatform } from '@storecraft/core/platform/node';
|
4
4
|
import { api } from '@storecraft/core/test-runner'
|
5
|
-
import {
|
5
|
+
import { LibSQL } from '../index.js';
|
6
6
|
import { migrateToLatest } from '../migrate.js';
|
7
7
|
|
8
8
|
export const create_app = async () => {
|
@@ -18,7 +18,7 @@ export const create_app = async () => {
|
|
18
18
|
)
|
19
19
|
.withPlatform(new NodePlatform())
|
20
20
|
.withDatabase(
|
21
|
-
new
|
21
|
+
new LibSQL(
|
22
22
|
{
|
23
23
|
url: ':memory:',
|
24
24
|
prefers_batch_over_transactions: true,
|
package/types.public.d.ts
CHANGED
@@ -10,7 +10,8 @@ export type Config = Partial<Omit<LibSqlConfig, 'url' | 'authToken'>> & {
|
|
10
10
|
*
|
11
11
|
* https://github.com/libsql/libsql-client-ts#supported-urls
|
12
12
|
*
|
13
|
-
* If missing, it will be inferred by env variable `LIBSQL_URL`
|
13
|
+
* If missing, it will be inferred by env variable `LIBSQL_URL` or
|
14
|
+
* will settle to `file:data.db` if `LIBSQL_URL` is not set.
|
14
15
|
*/
|
15
16
|
url?: string;
|
16
17
|
/**
|
package/vector-store/index.js
CHANGED
@@ -47,7 +47,7 @@ const parse_json_safely = json => {
|
|
47
47
|
export class LibSQLVectorStore {
|
48
48
|
|
49
49
|
/** @satisfies {ENV<Config>} */
|
50
|
-
static EnvConfig = /** @type{const} */ ({
|
50
|
+
static EnvConfig = /** @type {const} */ ({
|
51
51
|
authToken: 'LIBSQL_VECTOR_AUTH_TOKEN',
|
52
52
|
url: 'LIBSQL_VECTOR_URL',
|
53
53
|
});
|
@@ -106,7 +106,7 @@ export class LibSQLVectorStore {
|
|
106
106
|
?? app.platform.env['LIBSQL_AUTH_TOKEN'];
|
107
107
|
|
108
108
|
this.config.url ??= app.platform.env[LibSQLVectorStore.EnvConfig.url]
|
109
|
-
?? app.platform.env['LIBSQL_URL'];
|
109
|
+
?? app.platform.env['LIBSQL_URL'] ?? 'file:data.db';
|
110
110
|
}
|
111
111
|
|
112
112
|
/** @type {VectorStore["embedder"]} */
|
@@ -181,6 +181,13 @@ export class LibSQLVectorStore {
|
|
181
181
|
}
|
182
182
|
);
|
183
183
|
|
184
|
+
if(!result) {
|
185
|
+
console.warn(
|
186
|
+
'LibSQLVectorStore::upsertDocuments() - no result from embedder'
|
187
|
+
);
|
188
|
+
return;
|
189
|
+
}
|
190
|
+
|
184
191
|
const vectors = result.content;
|
185
192
|
|
186
193
|
// console.log(vectors)
|
package/vector-store/types.d.ts
CHANGED
@@ -11,7 +11,8 @@ export type Config = {
|
|
11
11
|
*
|
12
12
|
* https://github.com/libsql/libsql-client-ts#supported-urls
|
13
13
|
*
|
14
|
-
* If missing, it will be inferred by env variable `LIBSQL_VECTOR_URL` or `LIBSQL_URL
|
14
|
+
* If missing, it will be inferred by env variable `LIBSQL_VECTOR_URL` or `LIBSQL_URL`,
|
15
|
+
* or will settle to `file:data.db` if none are set.
|
15
16
|
*/
|
16
17
|
url?: string;
|
17
18
|
/**
|