@outfitter/index 0.2.4 → 0.2.5
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/dist/fts5.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
DEFAULT_LIMIT,
|
|
4
|
+
DEFAULT_OFFSET,
|
|
5
|
+
DEFAULT_TABLE_NAME,
|
|
6
|
+
DEFAULT_TOKENIZER,
|
|
7
|
+
DEFAULT_TOOL,
|
|
8
|
+
DEFAULT_TOOL_VERSION,
|
|
9
|
+
assertValidTableName,
|
|
10
|
+
assertValidTokenizer,
|
|
11
|
+
createStorageError,
|
|
12
|
+
getUserVersion,
|
|
13
|
+
readIndexMetadata,
|
|
14
|
+
setUserVersion,
|
|
15
|
+
writeIndexMetadata
|
|
16
|
+
} from "./shared/@outfitter/index-p03atd2s.js";
|
|
17
|
+
import {
|
|
5
18
|
INDEX_VERSION
|
|
6
19
|
} from "./shared/@outfitter/index-bbzmc40h.js";
|
|
7
20
|
|
|
@@ -10,65 +23,6 @@ import { Database } from "bun:sqlite";
|
|
|
10
23
|
import { existsSync, mkdirSync } from "fs";
|
|
11
24
|
import { dirname } from "path";
|
|
12
25
|
import { Result } from "@outfitter/contracts";
|
|
13
|
-
var DEFAULT_TABLE_NAME = "documents";
|
|
14
|
-
var DEFAULT_TOKENIZER = "unicode61";
|
|
15
|
-
var DEFAULT_LIMIT = 25;
|
|
16
|
-
var DEFAULT_OFFSET = 0;
|
|
17
|
-
var VALID_TOKENIZERS = {
|
|
18
|
-
unicode61: true,
|
|
19
|
-
porter: true,
|
|
20
|
-
trigram: true
|
|
21
|
-
};
|
|
22
|
-
var TABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
23
|
-
var DEFAULT_TOOL = "outfitter-index";
|
|
24
|
-
var DEFAULT_TOOL_VERSION = "0.0.0";
|
|
25
|
-
function createStorageError(message, cause) {
|
|
26
|
-
return {
|
|
27
|
-
_tag: "StorageError",
|
|
28
|
-
message,
|
|
29
|
-
cause
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function assertValidTableName(tableName) {
|
|
33
|
-
if (!TABLE_NAME_PATTERN.test(tableName)) {
|
|
34
|
-
throw new Error(`Invalid table name: ${tableName}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function assertValidTokenizer(tokenizer) {
|
|
38
|
-
if (!Object.hasOwn(VALID_TOKENIZERS, tokenizer)) {
|
|
39
|
-
throw new Error(`Invalid tokenizer: ${tokenizer}`);
|
|
40
|
-
}
|
|
41
|
-
return tokenizer;
|
|
42
|
-
}
|
|
43
|
-
function getUserVersion(db) {
|
|
44
|
-
const row = db.query("PRAGMA user_version").get();
|
|
45
|
-
return row?.user_version ?? 0;
|
|
46
|
-
}
|
|
47
|
-
function setUserVersion(db, version) {
|
|
48
|
-
if (!Number.isInteger(version) || version < 0) {
|
|
49
|
-
throw new Error(`Invalid user_version: ${version}`);
|
|
50
|
-
}
|
|
51
|
-
db.run(`PRAGMA user_version = ${version}`);
|
|
52
|
-
}
|
|
53
|
-
function ensureMetaTable(db) {
|
|
54
|
-
db.run(`CREATE TABLE IF NOT EXISTS ${INDEX_META_TABLE} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
|
|
55
|
-
}
|
|
56
|
-
function readIndexMetadata(db) {
|
|
57
|
-
try {
|
|
58
|
-
const row = db.query(`SELECT value FROM ${INDEX_META_TABLE} WHERE key = ?`).get(INDEX_META_KEY);
|
|
59
|
-
if (!row) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
const parsed = JSON.parse(row.value);
|
|
63
|
-
return parsed;
|
|
64
|
-
} catch {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function writeIndexMetadata(db, metadata) {
|
|
69
|
-
ensureMetaTable(db);
|
|
70
|
-
db.run(`INSERT OR REPLACE INTO ${INDEX_META_TABLE} (key, value) VALUES (?, ?)`, [INDEX_META_KEY, JSON.stringify(metadata)]);
|
|
71
|
-
}
|
|
72
26
|
function createIndex(options) {
|
|
73
27
|
const tableName = options.tableName ?? DEFAULT_TABLE_NAME;
|
|
74
28
|
assertValidTableName(tableName);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createIndex } from "./shared/@outfitter/index-ykxa3yhb.js";
|
|
2
|
-
import { Index, IndexDocument, IndexMetadata, IndexOptions, SearchQuery, SearchResult, TokenizerType } from "./shared/@outfitter/index-011azjav.js";
|
|
3
2
|
import { INDEX_VERSION } from "./shared/@outfitter/index-3xe3cd6r.js";
|
|
3
|
+
import { Index, IndexDocument, IndexMetadata, IndexOptions, SearchQuery, SearchResult, TokenizerType } from "./shared/@outfitter/index-011azjav.js";
|
|
4
4
|
import { IndexMigrationRegistry, createMigrationRegistry } from "./shared/@outfitter/index-dxk50kvh.js";
|
|
5
5
|
export { createMigrationRegistry, createIndex, TokenizerType, SearchResult, SearchQuery, IndexOptions, IndexMigrationRegistry, IndexMetadata, IndexDocument, Index, INDEX_VERSION };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IndexMetadata, TokenizerType } from "../shared/@outfitter/index-011azjav.js";
|
|
2
|
+
import "../shared/@outfitter/index-dxk50kvh.js";
|
|
3
|
+
import { Database } from "bun:sqlite";
|
|
4
|
+
import { StorageError } from "@outfitter/contracts";
|
|
5
|
+
/** Default table name for the FTS5 index */
|
|
6
|
+
declare const DEFAULT_TABLE_NAME = "documents";
|
|
7
|
+
/** Default tokenizer for the FTS5 index */
|
|
8
|
+
declare const DEFAULT_TOKENIZER: TokenizerType;
|
|
9
|
+
/** Default limit for search results */
|
|
10
|
+
declare const DEFAULT_LIMIT = 25;
|
|
11
|
+
/** Default offset for search results */
|
|
12
|
+
declare const DEFAULT_OFFSET = 0;
|
|
13
|
+
/** Default tool metadata when not provided */
|
|
14
|
+
declare const DEFAULT_TOOL = "outfitter-index";
|
|
15
|
+
/** Default tool version when not provided */
|
|
16
|
+
declare const DEFAULT_TOOL_VERSION = "0.0.0";
|
|
17
|
+
declare function assertValidTableName(tableName: string): void;
|
|
18
|
+
declare function assertValidTokenizer(tokenizer: string): TokenizerType;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a StorageError with the given message and optional cause.
|
|
21
|
+
*/
|
|
22
|
+
declare function createStorageError(message: string, cause?: unknown): StorageError;
|
|
23
|
+
declare function getUserVersion(db: Database): number;
|
|
24
|
+
declare function setUserVersion(db: Database, version: number): void;
|
|
25
|
+
declare function readIndexMetadata(db: Database): IndexMetadata | null;
|
|
26
|
+
declare function writeIndexMetadata(db: Database, metadata: IndexMetadata): void;
|
|
27
|
+
export { writeIndexMetadata, setUserVersion, readIndexMetadata, getUserVersion, createStorageError, assertValidTokenizer, assertValidTableName, DEFAULT_TOOL_VERSION, DEFAULT_TOOL, DEFAULT_TOKENIZER, DEFAULT_TABLE_NAME, DEFAULT_OFFSET, DEFAULT_LIMIT };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_LIMIT,
|
|
4
|
+
DEFAULT_OFFSET,
|
|
5
|
+
DEFAULT_TABLE_NAME,
|
|
6
|
+
DEFAULT_TOKENIZER,
|
|
7
|
+
DEFAULT_TOOL,
|
|
8
|
+
DEFAULT_TOOL_VERSION,
|
|
9
|
+
assertValidTableName,
|
|
10
|
+
assertValidTokenizer,
|
|
11
|
+
createStorageError,
|
|
12
|
+
getUserVersion,
|
|
13
|
+
readIndexMetadata,
|
|
14
|
+
setUserVersion,
|
|
15
|
+
writeIndexMetadata
|
|
16
|
+
} from "../shared/@outfitter/index-p03atd2s.js";
|
|
17
|
+
import"../shared/@outfitter/index-bbzmc40h.js";
|
|
18
|
+
export {
|
|
19
|
+
writeIndexMetadata,
|
|
20
|
+
setUserVersion,
|
|
21
|
+
readIndexMetadata,
|
|
22
|
+
getUserVersion,
|
|
23
|
+
createStorageError,
|
|
24
|
+
assertValidTokenizer,
|
|
25
|
+
assertValidTableName,
|
|
26
|
+
DEFAULT_TOOL_VERSION,
|
|
27
|
+
DEFAULT_TOOL,
|
|
28
|
+
DEFAULT_TOKENIZER,
|
|
29
|
+
DEFAULT_TABLE_NAME,
|
|
30
|
+
DEFAULT_OFFSET,
|
|
31
|
+
DEFAULT_LIMIT
|
|
32
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
INDEX_META_KEY,
|
|
4
|
+
INDEX_META_TABLE
|
|
5
|
+
} from "./index-bbzmc40h.js";
|
|
6
|
+
|
|
7
|
+
// packages/index/src/internal/fts5-helpers.ts
|
|
8
|
+
var DEFAULT_TABLE_NAME = "documents";
|
|
9
|
+
var DEFAULT_TOKENIZER = "unicode61";
|
|
10
|
+
var DEFAULT_LIMIT = 25;
|
|
11
|
+
var DEFAULT_OFFSET = 0;
|
|
12
|
+
var VALID_TOKENIZERS = {
|
|
13
|
+
unicode61: true,
|
|
14
|
+
porter: true,
|
|
15
|
+
trigram: true
|
|
16
|
+
};
|
|
17
|
+
var TABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
18
|
+
var DEFAULT_TOOL = "outfitter-index";
|
|
19
|
+
var DEFAULT_TOOL_VERSION = "0.0.0";
|
|
20
|
+
function assertValidTableName(tableName) {
|
|
21
|
+
if (!TABLE_NAME_PATTERN.test(tableName)) {
|
|
22
|
+
throw new Error(`Invalid table name: ${tableName}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function assertValidTokenizer(tokenizer) {
|
|
26
|
+
if (!Object.hasOwn(VALID_TOKENIZERS, tokenizer)) {
|
|
27
|
+
throw new Error(`Invalid tokenizer: ${tokenizer}`);
|
|
28
|
+
}
|
|
29
|
+
return tokenizer;
|
|
30
|
+
}
|
|
31
|
+
function createStorageError(message, cause) {
|
|
32
|
+
return {
|
|
33
|
+
_tag: "StorageError",
|
|
34
|
+
message,
|
|
35
|
+
cause
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getUserVersion(db) {
|
|
39
|
+
const row = db.query("PRAGMA user_version").get();
|
|
40
|
+
return row?.user_version ?? 0;
|
|
41
|
+
}
|
|
42
|
+
function setUserVersion(db, version) {
|
|
43
|
+
if (!Number.isInteger(version) || version < 0) {
|
|
44
|
+
throw new Error(`Invalid user_version: ${version}`);
|
|
45
|
+
}
|
|
46
|
+
db.run(`PRAGMA user_version = ${version}`);
|
|
47
|
+
}
|
|
48
|
+
function ensureMetaTable(db) {
|
|
49
|
+
db.run(`CREATE TABLE IF NOT EXISTS ${INDEX_META_TABLE} (key TEXT PRIMARY KEY, value TEXT NOT NULL)`);
|
|
50
|
+
}
|
|
51
|
+
function readIndexMetadata(db) {
|
|
52
|
+
try {
|
|
53
|
+
const row = db.query(`SELECT value FROM ${INDEX_META_TABLE} WHERE key = ?`).get(INDEX_META_KEY);
|
|
54
|
+
if (!row) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const parsed = JSON.parse(row.value);
|
|
58
|
+
return parsed;
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function writeIndexMetadata(db, metadata) {
|
|
64
|
+
ensureMetaTable(db);
|
|
65
|
+
db.run(`INSERT OR REPLACE INTO ${INDEX_META_TABLE} (key, value) VALUES (?, ?)`, [INDEX_META_KEY, JSON.stringify(metadata)]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { DEFAULT_TABLE_NAME, DEFAULT_TOKENIZER, DEFAULT_LIMIT, DEFAULT_OFFSET, DEFAULT_TOOL, DEFAULT_TOOL_VERSION, assertValidTableName, assertValidTokenizer, createStorageError, getUserVersion, setUserVersion, readIndexMetadata, writeIndexMetadata };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outfitter/index",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "SQLite FTS5 full-text search indexing for Outfitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fts5",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "cd ../.. && bunup --filter @outfitter/index",
|
|
63
|
+
"build": "cd ../.. && bash ./scripts/run-bunup-with-lock.sh bunup --filter @outfitter/index",
|
|
64
64
|
"lint": "oxlint ./src",
|
|
65
65
|
"lint:fix": "oxlint --fix ./src",
|
|
66
66
|
"test": "bun test",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"prepublishOnly": "bun ../../scripts/check-publish-manifest.ts"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@outfitter/contracts": "0.
|
|
73
|
-
"@outfitter/file-ops": "0.2.
|
|
72
|
+
"@outfitter/contracts": "0.5.0",
|
|
73
|
+
"@outfitter/file-ops": "0.2.5"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/bun": "^1.3.9",
|