@getplumb/core 0.1.2 → 0.1.4
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 +6 -5
- package/dist/extraction-queue.d.ts +62 -0
- package/dist/extraction-queue.d.ts.map +1 -0
- package/dist/extraction-queue.js +84 -0
- package/dist/extraction-queue.js.map +1 -0
- package/dist/fact-search.d.ts +4 -4
- package/dist/fact-search.d.ts.map +1 -1
- package/dist/fact-search.js +33 -23
- package/dist/fact-search.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/local-store.d.ts +18 -4
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-store.js +180 -76
- package/dist/local-store.js.map +1 -1
- package/dist/raw-log-search.d.ts +4 -4
- package/dist/raw-log-search.d.ts.map +1 -1
- package/dist/raw-log-search.js +31 -25
- package/dist/raw-log-search.js.map +1 -1
- package/dist/schema.d.ts +7 -8
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +25 -12
- package/dist/schema.js.map +1 -1
- package/dist/vector-search.d.ts +38 -0
- package/dist/vector-search.d.ts.map +1 -0
- package/dist/vector-search.js +59 -0
- package/dist/vector-search.js.map +1 -0
- package/dist/wasm-db.d.ts +14 -0
- package/dist/wasm-db.d.ts.map +1 -0
- package/dist/wasm-db.js +40 -0
- package/dist/wasm-db.js.map +1 -0
- package/package.json +10 -13
package/dist/schema.js
CHANGED
|
@@ -55,22 +55,23 @@ export const CREATE_RAW_LOG_INDEXES = [
|
|
|
55
55
|
`CREATE INDEX IF NOT EXISTS idx_raw_log_timestamp ON raw_log (timestamp)`,
|
|
56
56
|
];
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* FLOAT[384] matches BAAI/bge-small-en-v1.5 output dimension.
|
|
58
|
+
* Embeddings table for vector search over raw_log chunks.
|
|
59
|
+
* Stores embeddings as JSON arrays (WASM-compatible, no native extension needed).
|
|
61
60
|
*/
|
|
62
61
|
export const CREATE_VEC_RAW_LOG = `
|
|
63
|
-
CREATE
|
|
64
|
-
|
|
62
|
+
CREATE TABLE IF NOT EXISTS vec_raw_log (
|
|
63
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
64
|
+
embedding TEXT NOT NULL
|
|
65
65
|
)
|
|
66
66
|
`;
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* Embeddings table for vector search over facts.
|
|
69
|
+
* Stores embeddings as JSON arrays (WASM-compatible, no native extension needed).
|
|
70
70
|
*/
|
|
71
71
|
export const CREATE_VEC_FACTS = `
|
|
72
|
-
CREATE
|
|
73
|
-
|
|
72
|
+
CREATE TABLE IF NOT EXISTS vec_facts (
|
|
73
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
74
|
+
embedding TEXT NOT NULL
|
|
74
75
|
)
|
|
75
76
|
`;
|
|
76
77
|
/**
|
|
@@ -96,13 +97,21 @@ export function applySchema(db) {
|
|
|
96
97
|
db.exec(CREATE_VEC_RAW_LOG);
|
|
97
98
|
db.exec(CREATE_VEC_FACTS);
|
|
98
99
|
// Conditional migration: add vec_rowid column to facts if it doesn't exist yet.
|
|
99
|
-
const factsColumns = db.
|
|
100
|
+
const factsColumns = db.exec({
|
|
101
|
+
sql: 'PRAGMA table_info(facts)',
|
|
102
|
+
rowMode: 'object',
|
|
103
|
+
returnValue: 'resultRows',
|
|
104
|
+
});
|
|
100
105
|
const hasVecRowid = factsColumns.some((c) => c.name === 'vec_rowid');
|
|
101
106
|
if (!hasVecRowid) {
|
|
102
107
|
db.exec('ALTER TABLE facts ADD COLUMN vec_rowid INTEGER');
|
|
103
108
|
}
|
|
104
109
|
// Conditional migration: add content_hash column to raw_log if it doesn't exist yet.
|
|
105
|
-
const rawLogColumns = db.
|
|
110
|
+
const rawLogColumns = db.exec({
|
|
111
|
+
sql: 'PRAGMA table_info(raw_log)',
|
|
112
|
+
rowMode: 'object',
|
|
113
|
+
returnValue: 'resultRows',
|
|
114
|
+
});
|
|
106
115
|
const hasContentHash = rawLogColumns.some((c) => c.name === 'content_hash');
|
|
107
116
|
if (!hasContentHash) {
|
|
108
117
|
db.exec('ALTER TABLE raw_log ADD COLUMN content_hash TEXT');
|
|
@@ -111,7 +120,11 @@ export function applySchema(db) {
|
|
|
111
120
|
db.exec('CREATE UNIQUE INDEX IF NOT EXISTS idx_raw_log_content_hash ON raw_log(user_id, content_hash)');
|
|
112
121
|
}
|
|
113
122
|
// Conditional migration: create nudge_log table if it doesn't exist yet.
|
|
114
|
-
const tables = db.
|
|
123
|
+
const tables = db.exec({
|
|
124
|
+
sql: `SELECT name FROM sqlite_master WHERE type='table' AND name='nudge_log'`,
|
|
125
|
+
rowMode: 'object',
|
|
126
|
+
returnValue: 'resultRows',
|
|
127
|
+
});
|
|
115
128
|
if (tables.length === 0) {
|
|
116
129
|
db.exec(CREATE_NUDGE_LOG_TABLE);
|
|
117
130
|
}
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;CAejC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,iEAAiE;IACjE,8EAA8E;IAC9E,qEAAqE;IACrE,uEAAuE;CACxE,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;CAgBnC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,qEAAqE;IACrE,2EAA2E;IAC3E,yEAAyE;CAC1E,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,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,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IACrE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,EAAE,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;IAC5D,CAAC;IAED,qFAAqF;IACrF,MAAM,aAAa,GAAG,EAAE,CAAC,IAAI,CAAC;QAC5B,GAAG,EAAE,4BAA4B;QACjC,OAAO,EAAE,QAAQ;QACjB,WAAW,EAAE,YAAY;KAC1B,CAA4B,CAAC;IAC9B,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;IAC5E,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,EAAE,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;QAC5D,uDAAuD;QACvD,2FAA2F;QAC3F,EAAE,CAAC,IAAI,CAAC,8FAA8F,CAAC,CAAC;IAC1G,CAAC;IAED,yEAAyE;IACzE,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC;QACrB,GAAG,EAAE,wEAAwE;QAC7E,OAAO,EAAE,QAAQ;QACjB,WAAW,EAAE,YAAY;KAC1B,CAA4B,CAAC;IAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript-based vector similarity search.
|
|
3
|
+
*
|
|
4
|
+
* Replaces sqlite-vec native extension with pure JS cosine similarity.
|
|
5
|
+
* For current Plumb scale (thousands of facts, not millions), computing
|
|
6
|
+
* cosine similarity in-memory is acceptable.
|
|
7
|
+
*/
|
|
8
|
+
export interface VectorSearchResult {
|
|
9
|
+
readonly id: number;
|
|
10
|
+
readonly distance: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Compute cosine distance between two vectors.
|
|
14
|
+
* Returns distance in [0, 2] where 0 = identical, 2 = opposite.
|
|
15
|
+
* For normalized vectors, similarity = 1 - distance.
|
|
16
|
+
*/
|
|
17
|
+
export declare function cosineDistance(a: Float32Array, b: Float32Array): number;
|
|
18
|
+
/**
|
|
19
|
+
* Find k-nearest neighbors in a vector corpus.
|
|
20
|
+
*
|
|
21
|
+
* @param queryVec Query embedding
|
|
22
|
+
* @param corpus Array of [id, embedding] pairs
|
|
23
|
+
* @param k Number of results to return
|
|
24
|
+
* @returns Top-k results ordered by distance (ascending)
|
|
25
|
+
*/
|
|
26
|
+
export declare function knnSearch(queryVec: Float32Array, corpus: Array<{
|
|
27
|
+
id: number;
|
|
28
|
+
embedding: Float32Array;
|
|
29
|
+
}>, k: number): VectorSearchResult[];
|
|
30
|
+
/**
|
|
31
|
+
* Serialize embedding to JSON string for storage.
|
|
32
|
+
*/
|
|
33
|
+
export declare function serializeEmbedding(embedding: Float32Array): string;
|
|
34
|
+
/**
|
|
35
|
+
* Deserialize embedding from JSON string.
|
|
36
|
+
*/
|
|
37
|
+
export declare function deserializeEmbedding(json: string): Float32Array;
|
|
38
|
+
//# sourceMappingURL=vector-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-search.d.ts","sourceRoot":"","sources":["../src/vector-search.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAkBvE;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,YAAY,CAAA;CAAE,CAAC,EACtD,CAAC,EAAE,MAAM,GACR,kBAAkB,EAAE,CAUtB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,YAAY,GAAG,MAAM,CAElE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAE/D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript-based vector similarity search.
|
|
3
|
+
*
|
|
4
|
+
* Replaces sqlite-vec native extension with pure JS cosine similarity.
|
|
5
|
+
* For current Plumb scale (thousands of facts, not millions), computing
|
|
6
|
+
* cosine similarity in-memory is acceptable.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Compute cosine distance between two vectors.
|
|
10
|
+
* Returns distance in [0, 2] where 0 = identical, 2 = opposite.
|
|
11
|
+
* For normalized vectors, similarity = 1 - distance.
|
|
12
|
+
*/
|
|
13
|
+
export function cosineDistance(a, b) {
|
|
14
|
+
if (a.length !== b.length) {
|
|
15
|
+
throw new Error('Vectors must have the same dimension');
|
|
16
|
+
}
|
|
17
|
+
let dotProduct = 0;
|
|
18
|
+
let normA = 0;
|
|
19
|
+
let normB = 0;
|
|
20
|
+
for (let i = 0; i < a.length; i++) {
|
|
21
|
+
dotProduct += a[i] * b[i];
|
|
22
|
+
normA += a[i] * a[i];
|
|
23
|
+
normB += b[i] * b[i];
|
|
24
|
+
}
|
|
25
|
+
const similarity = dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
26
|
+
// Distance = 1 - similarity, scaled to [0, 2]
|
|
27
|
+
return 1 - similarity;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Find k-nearest neighbors in a vector corpus.
|
|
31
|
+
*
|
|
32
|
+
* @param queryVec Query embedding
|
|
33
|
+
* @param corpus Array of [id, embedding] pairs
|
|
34
|
+
* @param k Number of results to return
|
|
35
|
+
* @returns Top-k results ordered by distance (ascending)
|
|
36
|
+
*/
|
|
37
|
+
export function knnSearch(queryVec, corpus, k) {
|
|
38
|
+
// Compute distances for all vectors
|
|
39
|
+
const distances = corpus.map(({ id, embedding }) => ({
|
|
40
|
+
id,
|
|
41
|
+
distance: cosineDistance(queryVec, embedding),
|
|
42
|
+
}));
|
|
43
|
+
// Sort by distance (ascending) and take top k
|
|
44
|
+
distances.sort((a, b) => a.distance - b.distance);
|
|
45
|
+
return distances.slice(0, k);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Serialize embedding to JSON string for storage.
|
|
49
|
+
*/
|
|
50
|
+
export function serializeEmbedding(embedding) {
|
|
51
|
+
return JSON.stringify(Array.from(embedding));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Deserialize embedding from JSON string.
|
|
55
|
+
*/
|
|
56
|
+
export function deserializeEmbedding(json) {
|
|
57
|
+
return new Float32Array(JSON.parse(json));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=vector-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-search.js","sourceRoot":"","sources":["../src/vector-search.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,CAAe,EAAE,CAAe;IAC7D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,UAAU,IAAI,CAAC,CAAC,CAAC,CAAE,GAAG,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
|
1
|
+
/**
|
|
2
|
+
* WASM SQLite database wrapper.
|
|
3
|
+
* Provides the WasmDb type for use across the codebase.
|
|
4
|
+
* The @sqlite.org/sqlite-wasm oo1 API is used directly - this file only exports types.
|
|
5
|
+
*/
|
|
6
|
+
declare const sqlite3InitModule: typeof import("@sqlite.org/sqlite-wasm").default;
|
|
7
|
+
export type WasmDb = InstanceType<Awaited<ReturnType<typeof sqlite3InitModule>>['oo1']['DB']>;
|
|
8
|
+
/**
|
|
9
|
+
* Open a WASM SQLite database.
|
|
10
|
+
* @param path Absolute path to the database file
|
|
11
|
+
*/
|
|
12
|
+
export declare function openDb(path: string): Promise<WasmDb>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=wasm-db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-db.d.ts","sourceRoot":"","sources":["../src/wasm-db.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,QAAA,MAAM,iBAAiB,EAA8C,cAAc,yBAAyB,EAAE,OAAO,CAAC;AAYtH,MAAM,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAE9F;;;GAGG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK1D"}
|
package/dist/wasm-db.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM SQLite database wrapper.
|
|
3
|
+
* Provides the WasmDb type for use across the codebase.
|
|
4
|
+
* The @sqlite.org/sqlite-wasm oo1 API is used directly - this file only exports types.
|
|
5
|
+
*/
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
// Load sqlite3-node.mjs using require to bypass package.json exports restriction
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
// Find node_modules path by resolving the package directory
|
|
14
|
+
// We need to use a file that IS exported (sqlite3.wasm) to find the package root
|
|
15
|
+
const wasmFilePath = require.resolve('@sqlite.org/sqlite-wasm/sqlite3.wasm');
|
|
16
|
+
// wasmFilePath = /node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3.wasm
|
|
17
|
+
// Go up from jswasm/ to sqlite-wasm/ to package root (3 levels up)
|
|
18
|
+
const packageDir = dirname(dirname(dirname(wasmFilePath)));
|
|
19
|
+
const sqlite3NodePath = join(packageDir, 'sqlite-wasm', 'jswasm', 'sqlite3-node.mjs');
|
|
20
|
+
// Dynamic import the Node.js-specific WASM module
|
|
21
|
+
const sqlite3InitModule = (await import(sqlite3NodePath)).default;
|
|
22
|
+
// Global WASM module singleton (initialized once per process)
|
|
23
|
+
let wasmModule = null;
|
|
24
|
+
async function initWasmModule() {
|
|
25
|
+
if (!wasmModule) {
|
|
26
|
+
wasmModule = await sqlite3InitModule();
|
|
27
|
+
}
|
|
28
|
+
return wasmModule;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Open a WASM SQLite database.
|
|
32
|
+
* @param path Absolute path to the database file
|
|
33
|
+
*/
|
|
34
|
+
export async function openDb(path) {
|
|
35
|
+
const sqlite3 = await initWasmModule();
|
|
36
|
+
// 'ct' flags: create if not exists, throw on error
|
|
37
|
+
const db = new sqlite3.oo1.DB(path, 'ct');
|
|
38
|
+
return db;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=wasm-db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-db.js","sourceRoot":"","sources":["../src/wasm-db.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getplumb/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Plumb memory engine — storage abstraction, types, and local SQLite driver",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,25 +20,22 @@
|
|
|
20
20
|
"types": "./dist/index.d.ts"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "tsc",
|
|
25
|
-
"test": "node --import tsx/esm --test src/**/*.test.ts",
|
|
26
|
-
"lint": "echo \"No lint yet\" && exit 0",
|
|
27
|
-
"clean": "rm -rf dist *.tsbuildinfo",
|
|
28
|
-
"prepublishOnly": "pnpm build"
|
|
29
|
-
},
|
|
30
23
|
"devDependencies": {
|
|
31
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
32
24
|
"tsx": "^4.0.0",
|
|
33
25
|
"typescript": "^5.4.0"
|
|
34
26
|
},
|
|
35
27
|
"dependencies": {
|
|
36
|
-
"
|
|
37
|
-
"openai": "^4.80.0"
|
|
38
|
-
"sqlite-vec": "0.1.7-alpha.2"
|
|
28
|
+
"@sqlite.org/sqlite-wasm": "3.47.2-build1",
|
|
29
|
+
"openai": "^4.80.0"
|
|
39
30
|
},
|
|
40
31
|
"optionalDependencies": {
|
|
41
32
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
42
33
|
"@xenova/transformers": "^2.17.2"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"test": "node --import tsx/esm --test src/**/*.test.ts",
|
|
38
|
+
"lint": "echo \"No lint yet\" && exit 0",
|
|
39
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
43
40
|
}
|
|
44
|
-
}
|
|
41
|
+
}
|