@f0rbit/corpus 0.1.8 → 0.1.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../observations/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAuB,cAAc,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAExF,OAAO,KAAK,EAAE,mBAAmB,EAAoB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../observations/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAuB,cAAc,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAExF,OAAO,KAAK,EAAE,mBAAmB,EAAoB,MAAM,WAAW,CAAC;AA6BvE;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,cAAc,GAAG,kBAAkB,CAiGrH"}
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
import { row_to_observation, row_to_meta, create_observation_row } from "./storage";
|
|
6
6
|
import { generate_observation_id } from "./utils";
|
|
7
7
|
import { ok, err } from "../types";
|
|
8
|
+
async function apply_version_filter(filter, store_id, version) {
|
|
9
|
+
if (typeof filter === "function")
|
|
10
|
+
return filter(store_id, version);
|
|
11
|
+
if (filter instanceof Set)
|
|
12
|
+
return filter.has(version);
|
|
13
|
+
return filter.includes(version);
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
16
|
* Convert client query opts to storage query opts.
|
|
10
17
|
* Handles Date -> ISO string conversion.
|
|
@@ -31,14 +38,6 @@ export function create_observations_client(storage, metadata) {
|
|
|
31
38
|
const result = await metadata.get_latest(store_id);
|
|
32
39
|
return result.ok ? result.value.version : null;
|
|
33
40
|
}
|
|
34
|
-
async function resolve_version(store_id, resolver) {
|
|
35
|
-
if (resolver) {
|
|
36
|
-
const resolved = await resolver(store_id);
|
|
37
|
-
if (resolved !== null)
|
|
38
|
-
return resolved;
|
|
39
|
-
}
|
|
40
|
-
return get_latest_version(store_id);
|
|
41
|
-
}
|
|
42
41
|
return {
|
|
43
42
|
async put(type, opts) {
|
|
44
43
|
const validation = type.schema.safeParse(opts.content);
|
|
@@ -81,15 +80,10 @@ export function create_observations_client(storage, metadata) {
|
|
|
81
80
|
},
|
|
82
81
|
async *query(opts = {}) {
|
|
83
82
|
const storageOpts = to_storage_opts(opts);
|
|
84
|
-
const version_cache = new Map();
|
|
85
83
|
for await (const row of storage.query_rows(storageOpts)) {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
canonical_version = await resolve_version(row.source_store_id, opts.version_resolver);
|
|
90
|
-
version_cache.set(row.source_store_id, canonical_version);
|
|
91
|
-
}
|
|
92
|
-
if (canonical_version && row.source_version !== canonical_version)
|
|
84
|
+
if (opts.version_filter !== undefined) {
|
|
85
|
+
const included = await apply_version_filter(opts.version_filter, row.source_store_id, row.source_version);
|
|
86
|
+
if (!included)
|
|
93
87
|
continue;
|
|
94
88
|
}
|
|
95
89
|
yield row_to_observation(row);
|
|
@@ -97,15 +91,10 @@ export function create_observations_client(storage, metadata) {
|
|
|
97
91
|
},
|
|
98
92
|
async *query_meta(opts = {}) {
|
|
99
93
|
const storageOpts = to_storage_opts(opts);
|
|
100
|
-
const version_cache = new Map();
|
|
101
94
|
for await (const row of storage.query_rows(storageOpts)) {
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
canonical_version = await resolve_version(row.source_store_id, opts.version_resolver);
|
|
106
|
-
version_cache.set(row.source_store_id, canonical_version);
|
|
107
|
-
}
|
|
108
|
-
if (canonical_version && row.source_version !== canonical_version)
|
|
95
|
+
if (opts.version_filter !== undefined) {
|
|
96
|
+
const included = await apply_version_filter(opts.version_filter, row.source_store_id, row.source_version);
|
|
97
|
+
if (!included)
|
|
109
98
|
continue;
|
|
110
99
|
}
|
|
111
100
|
yield row_to_meta(row);
|
|
@@ -120,23 +120,31 @@ export type ObservationPutOpts<T> = {
|
|
|
120
120
|
derived_from?: SnapshotPointer[];
|
|
121
121
|
};
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
123
|
+
* Filter for version-based observation filtering.
|
|
124
|
+
* - Set<string> or string[]: Include if version is in the collection
|
|
125
|
+
* - Function: Called with (store_id, version), return true to include
|
|
125
126
|
*
|
|
126
127
|
* @category Types
|
|
127
128
|
* @group Observation Types
|
|
128
129
|
*
|
|
129
130
|
* @example
|
|
130
131
|
* ```ts
|
|
131
|
-
*
|
|
132
|
+
* // Filter to specific versions
|
|
133
|
+
* const filter: VersionFilter = new Set(['v1', 'v2', 'v3'])
|
|
134
|
+
*
|
|
135
|
+
* // Or use an array
|
|
136
|
+
* const filter: VersionFilter = ['v1', 'v2', 'v3']
|
|
137
|
+
*
|
|
138
|
+
* // Or use a function for dynamic filtering
|
|
139
|
+
* const filter: VersionFilter = async (store_id, version) => {
|
|
132
140
|
* const published = await db.query.published_reports.findFirst({
|
|
133
|
-
* where: eq(published_reports.
|
|
141
|
+
* where: eq(published_reports.version, version)
|
|
134
142
|
* });
|
|
135
|
-
* return published
|
|
143
|
+
* return published !== null;
|
|
136
144
|
* };
|
|
137
145
|
* ```
|
|
138
146
|
*/
|
|
139
|
-
export type
|
|
147
|
+
export type VersionFilter = Set<string> | string[] | ((store_id: string, version: string) => boolean | Promise<boolean>);
|
|
140
148
|
/**
|
|
141
149
|
* Query options for filtering observations.
|
|
142
150
|
*
|
|
@@ -153,11 +161,10 @@ export type VersionResolver = (store_id: string) => Promise<string | null>;
|
|
|
153
161
|
* limit: 100
|
|
154
162
|
* }
|
|
155
163
|
*
|
|
156
|
-
* //
|
|
164
|
+
* // Filter to only published versions
|
|
157
165
|
* const versionOpts: ObservationQueryOpts = {
|
|
158
166
|
* source_store: 'hansard',
|
|
159
|
-
*
|
|
160
|
-
* include_stale: true
|
|
167
|
+
* version_filter: new Set(['v1', 'v2'])
|
|
161
168
|
* }
|
|
162
169
|
* ```
|
|
163
170
|
*/
|
|
@@ -170,17 +177,16 @@ export type ObservationQueryOpts = {
|
|
|
170
177
|
before?: Date;
|
|
171
178
|
created_after?: Date;
|
|
172
179
|
created_before?: Date;
|
|
173
|
-
include_stale?: boolean;
|
|
174
180
|
limit?: number;
|
|
175
181
|
cursor?: string;
|
|
176
182
|
/**
|
|
177
|
-
*
|
|
178
|
-
* When provided
|
|
179
|
-
* the default "most recent by created_at" staleness logic.
|
|
183
|
+
* Filter observations by version.
|
|
184
|
+
* When provided, only observations whose source version passes the filter are included.
|
|
180
185
|
*
|
|
181
|
-
*
|
|
186
|
+
* - Set<string> or string[]: Include if version is in the collection
|
|
187
|
+
* - Function: Called with (store_id, version), return true to include
|
|
182
188
|
*/
|
|
183
|
-
|
|
189
|
+
version_filter?: VersionFilter;
|
|
184
190
|
};
|
|
185
191
|
/**
|
|
186
192
|
* Utility type to extract the content type from an ObservationTypeDef.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../observations/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACZ,CAAC;CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;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,GAAG,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,CAAC,SAAS,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAElG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@f0rbit/corpus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|