@f0rbit/corpus 0.3.3 → 0.3.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/README.md +2 -2
- package/dist/backend/cloudflare.d.ts +5 -3
- package/dist/backend/cloudflare.d.ts.map +1 -1
- package/dist/backend/cloudflare.js +28 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/sst.d.ts +0 -18
- package/dist/sst.d.ts.map +1 -1
- package/dist/sst.js +0 -56
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,14 +5,14 @@ a functional snapshotting library for typescript. store versioned data with line
|
|
|
5
5
|
## install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
bun add corpus
|
|
8
|
+
bun add @f0rbit/corpus
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## usage
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { z } from 'zod'
|
|
15
|
-
import { create_corpus, create_memory_backend, define_store, json_codec } from 'corpus'
|
|
15
|
+
import { create_corpus, create_memory_backend, define_store, json_codec } from '@f0rbit/corpus'
|
|
16
16
|
|
|
17
17
|
const TimelineSchema = z.object({
|
|
18
18
|
items: z.array(z.object({ id: z.string(), text: z.string() })),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Backends
|
|
3
3
|
* @description Cloudflare Workers storage backend using D1 and R2.
|
|
4
4
|
*/
|
|
5
|
-
import type { Backend, EventHandler } from
|
|
5
|
+
import type { Backend, EventHandler } from "../types.js";
|
|
6
6
|
type D1Database = {
|
|
7
7
|
prepare: (sql: string) => unknown;
|
|
8
8
|
};
|
|
@@ -28,7 +28,8 @@ export type CloudflareBackendConfig = {
|
|
|
28
28
|
* @group Storage Backends
|
|
29
29
|
*
|
|
30
30
|
* Uses D1 (SQLite) for metadata storage and R2 (object storage) for binary data.
|
|
31
|
-
*
|
|
31
|
+
* Database migrations should be managed via Drizzle Kit using the exported
|
|
32
|
+
* `corpus_snapshots` and `corpus_observations` schemas.
|
|
32
33
|
*
|
|
33
34
|
* This backend is designed for production use in Cloudflare Workers environments,
|
|
34
35
|
* providing durable, globally distributed storage.
|
|
@@ -56,7 +57,8 @@ export type CloudflareBackendConfig = {
|
|
|
56
57
|
* }
|
|
57
58
|
* ```
|
|
58
59
|
*
|
|
59
|
-
* @see
|
|
60
|
+
* @see corpus_snapshots - Drizzle schema for snapshot metadata
|
|
61
|
+
* @see corpus_observations - Drizzle schema for observations
|
|
60
62
|
*/
|
|
61
63
|
export declare function create_cloudflare_backend(config: CloudflareBackendConfig): Backend;
|
|
62
64
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../backend/cloudflare.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../backend/cloudflare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,KAAK,EAAE,OAAO,EAA2B,YAAY,EAAwC,MAAM,aAAa,CAAC;AAIxH,KAAK,UAAU,GAAG;IAAE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,CAAC;AACxD,KAAK,QAAQ,GAAG;IACf,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;QAAC,WAAW,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IACpH,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnF,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACrC,EAAE,EAAE,UAAU,CAAC;IACf,EAAE,EAAE,QAAQ,CAAC;IACb,QAAQ,CAAC,EAAE,YAAY,CAAC;CACxB,CAAC;AAgIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CA2OlF"}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* @module Backends
|
|
3
3
|
* @description Cloudflare Workers storage backend using D1 and R2.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { and, desc, eq, gt, inArray, like, lt, sql } from "drizzle-orm";
|
|
6
6
|
import { drizzle } from "drizzle-orm/d1";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import { corpus_observations, create_observations_client } from "../observations/index.js";
|
|
8
|
+
import { first, to_fallback, to_nullable } from "../result.js";
|
|
9
|
+
import { corpus_snapshots } from "../schema.js";
|
|
10
|
+
import { err, ok } from "../types.js";
|
|
11
|
+
import { create_emitter, parse_snapshot_meta } from "../utils.js";
|
|
12
12
|
function create_cloudflare_storage(db) {
|
|
13
13
|
return {
|
|
14
14
|
async put_row(row) {
|
|
@@ -20,24 +20,20 @@ function create_cloudflare_storage(db) {
|
|
|
20
20
|
return err({
|
|
21
21
|
kind: "storage_error",
|
|
22
22
|
cause: cause,
|
|
23
|
-
operation: "observations.put"
|
|
23
|
+
operation: "observations.put",
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
async get_row(id) {
|
|
28
28
|
try {
|
|
29
|
-
const rows = await db
|
|
30
|
-
.select()
|
|
31
|
-
.from(corpus_observations)
|
|
32
|
-
.where(eq(corpus_observations.id, id))
|
|
33
|
-
.limit(1);
|
|
29
|
+
const rows = await db.select().from(corpus_observations).where(eq(corpus_observations.id, id)).limit(1);
|
|
34
30
|
return ok(to_nullable(first(rows)));
|
|
35
31
|
}
|
|
36
32
|
catch (cause) {
|
|
37
33
|
return err({
|
|
38
34
|
kind: "storage_error",
|
|
39
35
|
cause: cause,
|
|
40
|
-
operation: "observations.get"
|
|
36
|
+
operation: "observations.get",
|
|
41
37
|
});
|
|
42
38
|
}
|
|
43
39
|
},
|
|
@@ -87,11 +83,7 @@ function create_cloudflare_storage(db) {
|
|
|
87
83
|
},
|
|
88
84
|
async delete_row(id) {
|
|
89
85
|
try {
|
|
90
|
-
const existing = await db
|
|
91
|
-
.select()
|
|
92
|
-
.from(corpus_observations)
|
|
93
|
-
.where(eq(corpus_observations.id, id))
|
|
94
|
-
.limit(1);
|
|
86
|
+
const existing = await db.select().from(corpus_observations).where(eq(corpus_observations.id, id)).limit(1);
|
|
95
87
|
if (existing.length === 0) {
|
|
96
88
|
return ok(false);
|
|
97
89
|
}
|
|
@@ -102,16 +94,13 @@ function create_cloudflare_storage(db) {
|
|
|
102
94
|
return err({
|
|
103
95
|
kind: "storage_error",
|
|
104
96
|
cause: cause,
|
|
105
|
-
operation: "observations.delete"
|
|
97
|
+
operation: "observations.delete",
|
|
106
98
|
});
|
|
107
99
|
}
|
|
108
100
|
},
|
|
109
101
|
async delete_by_source(store_id, version, path) {
|
|
110
102
|
try {
|
|
111
|
-
const conditions = [
|
|
112
|
-
eq(corpus_observations.source_store_id, store_id),
|
|
113
|
-
eq(corpus_observations.source_version, version)
|
|
114
|
-
];
|
|
103
|
+
const conditions = [eq(corpus_observations.source_store_id, store_id), eq(corpus_observations.source_version, version)];
|
|
115
104
|
if (path !== undefined) {
|
|
116
105
|
conditions.push(eq(corpus_observations.source_path, path));
|
|
117
106
|
}
|
|
@@ -129,10 +118,10 @@ function create_cloudflare_storage(db) {
|
|
|
129
118
|
return err({
|
|
130
119
|
kind: "storage_error",
|
|
131
120
|
cause: cause,
|
|
132
|
-
operation: "observations.delete_by_source"
|
|
121
|
+
operation: "observations.delete_by_source",
|
|
133
122
|
});
|
|
134
123
|
}
|
|
135
|
-
}
|
|
124
|
+
},
|
|
136
125
|
};
|
|
137
126
|
}
|
|
138
127
|
/**
|
|
@@ -141,7 +130,8 @@ function create_cloudflare_storage(db) {
|
|
|
141
130
|
* @group Storage Backends
|
|
142
131
|
*
|
|
143
132
|
* Uses D1 (SQLite) for metadata storage and R2 (object storage) for binary data.
|
|
144
|
-
*
|
|
133
|
+
* Database migrations should be managed via Drizzle Kit using the exported
|
|
134
|
+
* `corpus_snapshots` and `corpus_observations` schemas.
|
|
145
135
|
*
|
|
146
136
|
* This backend is designed for production use in Cloudflare Workers environments,
|
|
147
137
|
* providing durable, globally distributed storage.
|
|
@@ -169,7 +159,8 @@ function create_cloudflare_storage(db) {
|
|
|
169
159
|
* }
|
|
170
160
|
* ```
|
|
171
161
|
*
|
|
172
|
-
* @see
|
|
162
|
+
* @see corpus_snapshots - Drizzle schema for snapshot metadata
|
|
163
|
+
* @see corpus_observations - Drizzle schema for observations
|
|
173
164
|
*/
|
|
174
165
|
export function create_cloudflare_backend(config) {
|
|
175
166
|
const db = drizzle(config.d1);
|
|
@@ -250,7 +241,7 @@ export function create_cloudflare_backend(config) {
|
|
|
250
241
|
}
|
|
251
242
|
},
|
|
252
243
|
async *list(store_id, opts) {
|
|
253
|
-
const conditions = [
|
|
244
|
+
const conditions = [eq(corpus_snapshots.store_id, store_id)];
|
|
254
245
|
if (opts?.before) {
|
|
255
246
|
conditions.push(lt(corpus_snapshots.created_at, opts.before.toISOString()));
|
|
256
247
|
}
|
|
@@ -265,7 +256,15 @@ export function create_cloudflare_backend(config) {
|
|
|
265
256
|
if (opts?.limit) {
|
|
266
257
|
query = query.limit(opts.limit);
|
|
267
258
|
}
|
|
268
|
-
|
|
259
|
+
let rows;
|
|
260
|
+
try {
|
|
261
|
+
rows = await query;
|
|
262
|
+
}
|
|
263
|
+
catch (cause) {
|
|
264
|
+
const error = { kind: "storage_error", cause: cause, operation: "metadata.list" };
|
|
265
|
+
emit({ type: "error", error });
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
269
268
|
let count = 0;
|
|
270
269
|
for (const row of rows) {
|
|
271
270
|
const meta = snapshot_row_to_meta(row);
|
package/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export { ok, err, define_store } from './types.js';
|
|
|
9
9
|
export { match, unwrap_or, unwrap, unwrap_err, try_catch, try_catch_async, fetch_result, pipe, to_nullable, to_fallback, null_on, fallback_on, format_error, at, first, last, merge_deep, type DeepPartial, type FetchError, type Pipe, } from './result.js';
|
|
10
10
|
export { Semaphore, parallel_map } from './concurrency.js';
|
|
11
11
|
export * from './observations/index.js';
|
|
12
|
-
export { createCorpusInfra,
|
|
12
|
+
export { createCorpusInfra, type CorpusInfra, type CorpusInfraConfig } from './sst.js';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE1F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAElG,OAAO,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAElG,YAAY,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,cAAc,EACd,UAAU,EACV,QAAQ,EACR,OAAO,EACP,KAAK,EACL,MAAM,EACN,KAAK,EACL,eAAe,EACf,eAAe,EACf,cAAc,EACd,OAAO,EACP,aAAa,EACb,MAAM,EACN,WAAW,EACX,MAAM,EACN,WAAW,EACX,YAAY,EACZ,kBAAkB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EACN,KAAK,EACL,SAAS,EACT,MAAM,EACN,UAAU,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,EAAE,EACF,KAAK,EACL,IAAI,EACJ,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,IAAI,GACT,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE3D,cAAc,yBAAyB,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE1F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAElG,OAAO,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAElG,YAAY,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,cAAc,EACd,UAAU,EACV,QAAQ,EACR,OAAO,EACP,KAAK,EACL,MAAM,EACN,KAAK,EACL,eAAe,EACf,eAAe,EACf,cAAc,EACd,OAAO,EACP,aAAa,EACb,MAAM,EACN,WAAW,EACX,MAAM,EACN,WAAW,EACX,YAAY,EACZ,kBAAkB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EACN,KAAK,EACL,SAAS,EACT,MAAM,EACN,UAAU,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,EAAE,EACF,KAAK,EACL,IAAI,EACJ,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,IAAI,GACT,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE3D,cAAc,yBAAyB,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,4 +8,4 @@ export { ok, err, define_store } from './types.js';
|
|
|
8
8
|
export { match, unwrap_or, unwrap, unwrap_err, try_catch, try_catch_async, fetch_result, pipe, to_nullable, to_fallback, null_on, fallback_on, format_error, at, first, last, merge_deep, } from './result.js';
|
|
9
9
|
export { Semaphore, parallel_map } from './concurrency.js';
|
|
10
10
|
export * from './observations/index.js';
|
|
11
|
-
export { createCorpusInfra
|
|
11
|
+
export { createCorpusInfra } from './sst.js';
|
package/dist/sst.d.ts
CHANGED
|
@@ -35,22 +35,4 @@ export type CorpusInfra = {
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export declare function createCorpusInfra(name: string, config?: Partial<CorpusInfraConfig>): CorpusInfra;
|
|
38
|
-
/**
|
|
39
|
-
* SQL migration script to create required D1 tables for the Cloudflare backend.
|
|
40
|
-
*
|
|
41
|
-
* Must be executed on the D1 database before using `create_cloudflare_backend()`.
|
|
42
|
-
* Creates the `corpus_snapshots` table and required indexes.
|
|
43
|
-
*
|
|
44
|
-
* Safe to run multiple times (uses IF NOT EXISTS).
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* // Run migration via wrangler
|
|
49
|
-
* // wrangler d1 execute <database-name> --command "$(cat migration.sql)"
|
|
50
|
-
*
|
|
51
|
-
* // Or programmatically in a Worker
|
|
52
|
-
* await env.CORPUS_DB.exec(CORPUS_MIGRATION_SQL)
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare const CORPUS_MIGRATION_SQL = "\nCREATE TABLE IF NOT EXISTS corpus_snapshots (\n store_id TEXT NOT NULL,\n version TEXT NOT NULL,\n parents TEXT NOT NULL,\n created_at TEXT NOT NULL,\n invoked_at TEXT,\n content_hash TEXT NOT NULL,\n content_type TEXT NOT NULL,\n size_bytes INTEGER NOT NULL,\n data_key TEXT NOT NULL,\n tags TEXT,\n PRIMARY KEY (store_id, version)\n);\n\nCREATE INDEX IF NOT EXISTS idx_store_created ON corpus_snapshots(store_id, created_at);\nCREATE INDEX IF NOT EXISTS idx_content_hash ON corpus_snapshots(store_id, content_hash);\nCREATE INDEX IF NOT EXISTS idx_data_key ON corpus_snapshots(data_key);\n\nCREATE TABLE IF NOT EXISTS corpus_observations (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n source_store_id TEXT NOT NULL,\n source_version TEXT NOT NULL,\n source_path TEXT,\n source_span_start TEXT,\n source_span_end TEXT,\n content TEXT NOT NULL,\n confidence REAL,\n observed_at TEXT,\n created_at TEXT NOT NULL,\n derived_from TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_obs_type ON corpus_observations(type);\nCREATE INDEX IF NOT EXISTS idx_obs_source ON corpus_observations(source_store_id, source_version);\nCREATE INDEX IF NOT EXISTS idx_obs_type_observed ON corpus_observations(type, observed_at);\nCREATE INDEX IF NOT EXISTS idx_obs_type_source ON corpus_observations(type, source_store_id);\n";
|
|
56
38
|
//# sourceMappingURL=sst.d.ts.map
|
package/dist/sst.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sst.d.ts","sourceRoot":"","sources":["../sst.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAClC,WAAW,CAUb
|
|
1
|
+
{"version":3,"file":"sst.d.ts","sourceRoot":"","sources":["../sst.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IAC1B,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAClC,WAAW,CAUb"}
|
package/dist/sst.js
CHANGED
|
@@ -29,59 +29,3 @@ export function createCorpusInfra(name, config) {
|
|
|
29
29
|
bucket_name,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* SQL migration script to create required D1 tables for the Cloudflare backend.
|
|
34
|
-
*
|
|
35
|
-
* Must be executed on the D1 database before using `create_cloudflare_backend()`.
|
|
36
|
-
* Creates the `corpus_snapshots` table and required indexes.
|
|
37
|
-
*
|
|
38
|
-
* Safe to run multiple times (uses IF NOT EXISTS).
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* // Run migration via wrangler
|
|
43
|
-
* // wrangler d1 execute <database-name> --command "$(cat migration.sql)"
|
|
44
|
-
*
|
|
45
|
-
* // Or programmatically in a Worker
|
|
46
|
-
* await env.CORPUS_DB.exec(CORPUS_MIGRATION_SQL)
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export const CORPUS_MIGRATION_SQL = `
|
|
50
|
-
CREATE TABLE IF NOT EXISTS corpus_snapshots (
|
|
51
|
-
store_id TEXT NOT NULL,
|
|
52
|
-
version TEXT NOT NULL,
|
|
53
|
-
parents TEXT NOT NULL,
|
|
54
|
-
created_at TEXT NOT NULL,
|
|
55
|
-
invoked_at TEXT,
|
|
56
|
-
content_hash TEXT NOT NULL,
|
|
57
|
-
content_type TEXT NOT NULL,
|
|
58
|
-
size_bytes INTEGER NOT NULL,
|
|
59
|
-
data_key TEXT NOT NULL,
|
|
60
|
-
tags TEXT,
|
|
61
|
-
PRIMARY KEY (store_id, version)
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
CREATE INDEX IF NOT EXISTS idx_store_created ON corpus_snapshots(store_id, created_at);
|
|
65
|
-
CREATE INDEX IF NOT EXISTS idx_content_hash ON corpus_snapshots(store_id, content_hash);
|
|
66
|
-
CREATE INDEX IF NOT EXISTS idx_data_key ON corpus_snapshots(data_key);
|
|
67
|
-
|
|
68
|
-
CREATE TABLE IF NOT EXISTS corpus_observations (
|
|
69
|
-
id TEXT PRIMARY KEY,
|
|
70
|
-
type TEXT NOT NULL,
|
|
71
|
-
source_store_id TEXT NOT NULL,
|
|
72
|
-
source_version TEXT NOT NULL,
|
|
73
|
-
source_path TEXT,
|
|
74
|
-
source_span_start TEXT,
|
|
75
|
-
source_span_end TEXT,
|
|
76
|
-
content TEXT NOT NULL,
|
|
77
|
-
confidence REAL,
|
|
78
|
-
observed_at TEXT,
|
|
79
|
-
created_at TEXT NOT NULL,
|
|
80
|
-
derived_from TEXT
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
CREATE INDEX IF NOT EXISTS idx_obs_type ON corpus_observations(type);
|
|
84
|
-
CREATE INDEX IF NOT EXISTS idx_obs_source ON corpus_observations(source_store_id, source_version);
|
|
85
|
-
CREATE INDEX IF NOT EXISTS idx_obs_type_observed ON corpus_observations(type, observed_at);
|
|
86
|
-
CREATE INDEX IF NOT EXISTS idx_obs_type_source ON corpus_observations(type, source_store_id);
|
|
87
|
-
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@f0rbit/corpus",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A functional snapshotting library for TypeScript with versioned data storage, lineage tracking, and multiple backend support",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,11 +36,12 @@
|
|
|
36
36
|
"files": ["dist"],
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsc -p tsconfig.build.json",
|
|
39
|
+
"build:llm": "node scripts/generate-llm-docs.js",
|
|
39
40
|
"test": "bun test",
|
|
40
41
|
"typecheck": "tsc --noEmit",
|
|
41
42
|
"prepublishOnly": "npm run build",
|
|
42
43
|
"docs:dev": "cd docs && bun run dev",
|
|
43
|
-
"docs:build": "cd docs && bun run build",
|
|
44
|
+
"docs:build": "npm run build:llm && cd docs && bun run build",
|
|
44
45
|
"docs:preview": "cd docs && bun run preview"
|
|
45
46
|
},
|
|
46
47
|
"repository": {
|