@1-/scan 0.1.1 → 0.1.2

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  <a id="en"></a>
6
6
  # @1-/scan : Incrementally scan directory files and track metadata in SQLite
7
7
 
8
- Incrementally scans directory files, tracks file sizes and modification times, and synchronizes status into a SQLite database.
8
+ Incrementally scans directory files, tracks file sizes and modification times, and synchronizes status into an SQLite database using Bun's native SQLite driver (`bun:sqlite`), returning an array of updated relative paths.
9
9
 
10
10
  ## Features
11
11
 
@@ -14,6 +14,7 @@ Incrementally scans directory files, tracks file sizes and modification times, a
14
14
  - Smart Path Key: Stores relative paths not exceeding 16 bytes as raw binary to preserve readability, while hashing longer paths to 16-byte MD5 digests to optimize index performance.
15
15
  - Database Synchronization: Synchronizes updates and deletions in a single atomic transaction.
16
16
  - Ignore Pattern Support: Integrates ignore rules dynamically during traversal.
17
+ - Native SQLite: Leverages Bun's native, high-performance `bun:sqlite` engine, eliminating external build dependencies.
17
18
 
18
19
  ## Usage
19
20
 
@@ -35,18 +36,18 @@ Execution flow of modules:
35
36
  ```mermaid
36
37
  graph TD
37
38
  Entry["_.js (Main)"] -->|Open database| Sqlite[sqlite.js]
38
- Entry -->|Load existing records| FileAll[fileAll.js]
39
+ Entry -->|Load existing records| Load[load.js]
39
40
  Entry -->|Walk and compare| DirWalk[dirWalk.js]
40
41
  DirWalk -->|Traverse files| Walk["@1-/walk/walkRelIgnore"]
41
42
  DirWalk -->|Optimize keys| Hash[hash.js]
42
- Entry -->|Apply modifications| FileWrite[fileWrite.js]
43
- FileWrite -->|Wrap transaction| Trans[trans.js]
43
+ Entry -->|Apply modifications| Save[save.js]
44
+ Save -->|Wrap transaction| Trans[trans.js]
44
45
  ```
45
46
 
46
47
  ## Tech Stack
47
48
 
48
49
  - Bun: Runtime and test runner
49
- - SQLite: Local relational database engine
50
+ - Bun SQLite: Bun's built-in high-performance SQLite engine
50
51
  - `@1-/walk`: Directory walker with ignore support
51
52
  - `@3-/vb`: Variable-length byte encoder
52
53
  - `@3-/binmap` / `@3-/binset`: Efficient binary collection structures
@@ -58,8 +59,8 @@ graph TD
58
59
  ├── src
59
60
  │ ├── _.js # Entry point orchestrating the scanning and sync process
60
61
  │ ├── dirWalk.js # Recursively scans files and filters modified ones
61
- │ ├── fileAll.js # Retrieves database records and initializes schema
62
- │ ├── fileWrite.js # Performs bulk database inserts and deletes
62
+ │ ├── load.js # Retrieves database records and initializes schema
63
+ │ ├── save.js # Performs bulk database inserts and deletes
63
64
  │ ├── hash.js # Processes path keys into raw bytes or MD5 digests
64
65
  │ ├── sqlite.js # Manages SQLite database connection and disposal
65
66
  │ └── trans.js # Wraps operations inside an SQL transaction
@@ -78,7 +79,7 @@ To optimize space inside the database file, SQLite internally uses variable-leng
78
79
  <a id="zh"></a>
79
80
  # @1-/scan : 增量扫描目录文件并使用 SQLite 记录元数据
80
81
 
81
- 增量扫描目录,比对并同步文件大小与修改时间,记录存入 SQLite 数据库。
82
+ 基于 Bun 原生的高性能内置 SQLite 数据库(`bun:sqlite`)增量扫描目录,比对并同步文件大小与修改时间,并返回有变更的相对路径数组。
82
83
 
83
84
  ## 功能介绍
84
85
 
@@ -87,6 +88,7 @@ To optimize space inside the database file, SQLite internally uses variable-leng
87
88
  - 路径映射:相对路径长度不大于 16 字节时保留原始字节,大于 16 字节时计算为 16 字节 MD5,优化数据库索引。
88
89
  - 事务同步:更新与删除操作合并至单次数据库事务,确保一致性。
89
90
  - 规则过滤:基于 `@1-/walk` 的忽略规则过滤特定文件与目录。
91
+ - 原生数据库:使用 Bun 内置的 `bun:sqlite`,性能优异且无需安装或编译外部依赖。
90
92
 
91
93
  ## 使用演示
92
94
 
@@ -108,18 +110,18 @@ console.log(updatedPaths);
108
110
  ```mermaid
109
111
  graph TD
110
112
  Entry["_.js (主入口)"] -->|打开数据库| Sqlite[sqlite.js]
111
- Entry -->|载入已有记录| FileAll[fileAll.js]
113
+ Entry -->|载入已有记录| Load[load.js]
112
114
  Entry -->|遍历并比对| DirWalk[dirWalk.js]
113
115
  DirWalk -->|扫描文件系统| Walk["@1-/walk/walkRelIgnore"]
114
116
  DirWalk -->|计算路径哈希| Hash[hash.js]
115
- Entry -->|写入变更数据| FileWrite[fileWrite.js]
116
- FileWrite -->|执行事务控制| Trans[trans.js]
117
+ Entry -->|写入变更数据| Save[save.js]
118
+ Save -->|执行事务控制| Trans[trans.js]
117
119
  ```
118
120
 
119
121
  ## 技术栈
120
122
 
121
123
  - Bun:运行环境与测试工具
122
- - SQLite:本地关系型数据库
124
+ - Bun SQLite:Bun 内置的高性能 SQLite 模块
123
125
  - `@1-/walk`:支持忽略规则的目录遍历工具
124
126
  - `@3-/vb`:可变长度整型编码器
125
127
  - `@3-/binmap` / `@3-/binset`:二进制哈希键容器
@@ -131,8 +133,8 @@ graph TD
131
133
  ├── src
132
134
  │ ├── _.js # 主入口,统筹扫描与同步逻辑
133
135
  │ ├── dirWalk.js # 递归遍历目录,比对筛选出变更文件
134
- │ ├── fileAll.js # 读取数据库中全部记录,初始化数据表
135
- │ ├── fileWrite.js # 事务内执行批量插入与删除
136
+ │ ├── load.js # 读取数据库中全部记录,初始化数据表
137
+ │ ├── save.js # 事务内执行批量插入与删除
136
138
  │ ├── hash.js # 计算相对路径哈希值或保留原始字节
137
139
  │ ├── sqlite.js # 管理 SQLite 数据库连接及资源释放
138
140
  │ └── trans.js # 封装数据库事务控制
package/_.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { BinMap } from "@3-/binmap";
2
2
  import vbE from "@3-/vb/vbE.js";
3
3
  import sqlite from "./sqlite.js";
4
- import fileAll from "./fileAll.js";
4
+ import load from "./load.js";
5
5
  import dirWalk from "./dirWalk.js";
6
- import fileWrite from "./fileWrite.js";
6
+ import save from "./save.js";
7
7
 
8
8
  export default async (dir, db_path) => {
9
9
  using db = sqlite(db_path);
10
10
  const existing = new BinMap(),
11
- db_rows = fileAll(db);
11
+ db_rows = load(db);
12
12
 
13
13
  for (const row of db_rows) {
14
14
  existing.set(row.hash, vbE([row.size, row.mtime]));
@@ -22,6 +22,6 @@ export default async (dir, db_path) => {
22
22
  }
23
23
  }
24
24
 
25
- fileWrite(db, to_update, to_delete);
25
+ save(db, to_update, to_delete);
26
26
  return to_update.map(([rel_path]) => rel_path);
27
27
  };
@@ -4,7 +4,7 @@ export default (db) => {
4
4
  try {
5
5
  return db.prepare("SELECT hash,size,mtime FROM file").all();
6
6
  } catch (err) {
7
- if (err.errcode === SQLITE_ERROR) {
7
+ if (err.errno === SQLITE_ERROR) {
8
8
  db.exec("CREATE TABLE file(hash PRIMARY KEY,size INT UNSIGNED,mtime INT UNSIGNED)");
9
9
  return [];
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1-/scan",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Incrementally scan directory files and track metadata in SQLite / 增量扫描目录文件并使用 SQLite 记录元数据",
5
5
  "keywords": [
6
6
  "scan",
package/sqlite.js CHANGED
@@ -1,7 +1,7 @@
1
- const { DatabaseSync } = await import("node:sqlite");
1
+ import { Database } from "bun:sqlite";
2
2
 
3
3
  export default (db_path) => {
4
- const db = new DatabaseSync(db_path);
4
+ const db = new Database(db_path);
5
5
  db[Symbol.dispose] = () => db.close();
6
6
  return db;
7
7
  };
File without changes