@kedem/okdb 2.1.2 → 2.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kedem/okdb",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
4
4
  "description": "A fast, type-oriented database — strong consistency and rich indexing at the core, with sync, vector embeddings, full-text search, and AI tooling built in. Designed for the AI era.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "engines": {
@@ -4,6 +4,7 @@ import type {
4
4
  OKDBFilter,
5
5
  OKDBRangeOptions,
6
6
  OKDBQueryOptions,
7
+ OKDBIndexRangeOptions,
7
8
  OKDBGeoQueryOptions,
8
9
  OKDBFtsQueryOptions,
9
10
  OKDBWriteOptions,
@@ -81,8 +82,9 @@ export interface OKDBEnvironment {
81
82
  getByPrefix<T = unknown>(type: string, prefix: OKDBPrimaryKey, options?: OKDBRangeOptions): Iterable<OKDBEntry<T>>;
82
83
 
83
84
  // ── Index queries ─────────────────────────────────────────────────────────
84
- getIndex<T = unknown>(type: string, index: string[], options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
85
- byIndex<T = unknown>(type: string, index: string[], options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
85
+ getIndex<T = unknown>(type: string, index: string[], options?: OKDBIndexRangeOptions): Iterable<OKDBIndexEntry<T>>;
86
+ byIndex<T = unknown>(type: string, index: string[], options?: OKDBIndexRangeOptions): Iterable<OKDBIndexEntry<T>>;
87
+ countByIndex(type: string, index: string[], options?: OKDBIndexRangeOptions): number;
86
88
  query<T = unknown>(type: string, filter: OKDBFilter, options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
87
89
  geoQuery<T = unknown>(type: string, field: string, options: OKDBGeoQueryOptions): Iterable<OKDBEntry<T>>;
88
90
  ftsQuery<T = unknown>(
@@ -73,6 +73,8 @@ export interface OKDBBucketRangeOptions {
73
73
  granularity?: string;
74
74
  /** When true, includes the bucket containing Date.now(). Default false. */
75
75
  includePartial?: boolean;
76
+ /** Pagination controls applied to any grouped ($countBy) reducer in the result. */
77
+ preview?: OKDBViewPreviewOptions;
76
78
  }
77
79
 
78
80
  /** A single entry in the array returned by views.range() */
@@ -80,7 +82,7 @@ export interface OKDBBucketRangeEntry {
80
82
  /** Canonical string key for this bucket (ISO date string for preset:'time'). */
81
83
  bucketKey: string;
82
84
  granularity: string;
83
- /** Per-reducer aggregated values. Scalar → { value: N }; $countBy → { [groupKey]: { value: N } }. */
85
+ /** Per-reducer aggregated values. Scalar → { value: N }; $countBy → { totalGroups, preview, hasMore, cursor }. */
84
86
  reducers: Record<string, OKDBScalarResult | OKDBCountByResult>;
85
87
  /** Per-$ref sub-view aggregated values. */
86
88
  refs: Record<string, Record<string, OKDBScalarResult | OKDBCountByResult>>;
@@ -131,8 +133,40 @@ export interface OKDBScalarResult {
131
133
  items?: () => unknown[];
132
134
  }
133
135
 
134
- /** Shape returned for a $countBy reducer output */
135
- export type OKDBCountByResult = Record<string, OKDBScalarResult>;
136
+ /** Pagination controls for a grouped ($countBy) reducer's preview page */
137
+ export interface OKDBViewPreviewOptions {
138
+ /** Max groups per page. Default 50. */
139
+ limit?: number;
140
+ /** Sort direction. Default 'desc' for $countBy (by count). */
141
+ order?: 'asc' | 'desc';
142
+ /** Sort axis. Default 'count' for $countBy. */
143
+ axis?: string;
144
+ /** Opaque cursor from a previous page's `cursor` field. */
145
+ cursor?: string;
146
+ /** Per-reducer override, keyed by the reduce field name. */
147
+ perReducer?: Record<string, { limit?: number; order?: 'asc' | 'desc'; axis?: string; cursor?: string }>;
148
+ }
149
+
150
+ /** A single group entry within a $countBy preview page */
151
+ export interface OKDBCountByPreviewEntry {
152
+ key: string;
153
+ value: number;
154
+ /** Present when items:true was set — returns the live source docs for this group */
155
+ items?: () => unknown[];
156
+ }
157
+
158
+ /**
159
+ * Shape returned for a $countBy reducer output.
160
+ * Paginated — `preview` holds at most `limit` groups (default 50), sorted by
161
+ * count descending. Pass `{ preview: { limit, order, axis, cursor } }` to
162
+ * views.get()/range() to page through the rest via `hasMore`/`cursor`.
163
+ */
164
+ export interface OKDBCountByResult {
165
+ totalGroups: number;
166
+ preview: OKDBCountByPreviewEntry[];
167
+ hasMore: boolean;
168
+ cursor: string | null;
169
+ }
136
170
 
137
171
  /** Shape returned for a $ref slot */
138
172
  export type OKDBRefResult = Record<string, OKDBScalarResult | OKDBCountByResult>;
@@ -180,7 +214,7 @@ export declare class OKDBViews {
180
214
  * Read the current view output. Synchronous and O(1).
181
215
  * Returns null if the view does not exist.
182
216
  */
183
- get(name: string): OKDBViewOutput | null;
217
+ get(name: string, options?: { preview?: OKDBViewPreviewOptions }): OKDBViewOutput | null;
184
218
 
185
219
  /**
186
220
  * Get view lifecycle meta (state, clock, error).
package/types/index.d.ts CHANGED
@@ -38,6 +38,7 @@ import type {
38
38
  OKDBFilter,
39
39
  OKDBRangeOptions,
40
40
  OKDBQueryOptions,
41
+ OKDBIndexRangeOptions,
41
42
  OKDBGeoQueryOptions,
42
43
  OKDBFtsQueryOptions,
43
44
  OKDBWriteOptions,
@@ -169,8 +170,9 @@ export declare class OKDB {
169
170
  getByPrefix<T = unknown>(type: string, prefix: OKDBPrimaryKey, options?: OKDBRangeOptions): Iterable<OKDBEntry<T>>;
170
171
 
171
172
  // ── Index queries ─────────────────────────────────────────────────────────
172
- getIndex<T = unknown>(type: string, index: string[], options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
173
- byIndex<T = unknown>(type: string, index: string[], options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
173
+ getIndex<T = unknown>(type: string, index: string[], options?: OKDBIndexRangeOptions): Iterable<OKDBIndexEntry<T>>;
174
+ byIndex<T = unknown>(type: string, index: string[], options?: OKDBIndexRangeOptions): Iterable<OKDBIndexEntry<T>>;
175
+ countByIndex(type: string, index: string[], options?: OKDBIndexRangeOptions): number;
174
176
  query<T = unknown>(type: string, filter: OKDBFilter, options?: OKDBQueryOptions): Iterable<OKDBIndexEntry<T>>;
175
177
  geoQuery<T = unknown>(type: string, field: string, options: OKDBGeoQueryOptions): Iterable<OKDBEntry<T>>;
176
178
  ftsQuery<T = unknown>(
@@ -120,16 +120,38 @@ export interface OKDBRangeOptions {
120
120
  }
121
121
 
122
122
  export interface OKDBQueryOptions {
123
- index?: string[];
123
+ index?: string[] | { fields: string[]; prefix?: OKDBIndexKey; start?: OKDBIndexKey; end?: OKDBIndexKey };
124
124
  prefix?: OKDBIndexKey;
125
- start?: OKDBIndexKey;
126
- end?: OKDBIndexKey;
125
+ /** Inclusive index-key lower/upper bound. NOT `start`/`end` — those are byIndex/getRange
126
+ * names and are not implemented by query(); passing them throws. */
127
127
  startIndex?: OKDBIndexKey;
128
+ endIndex?: OKDBIndexKey;
129
+ /** Primary-key page-boundary hint (cursor-style pagination), as an alternative to startIndex/endIndex. */
130
+ startKey?: OKDBPrimaryKey;
131
+ endKey?: OKDBPrimaryKey;
128
132
  limit?: number;
129
133
  reverse?: boolean;
130
134
  offset?: number;
131
135
  }
132
136
 
137
+ /**
138
+ * Options for byIndex/getIndex/countByIndex. Distinct from OKDBQueryOptions: these forward
139
+ * directly to lmdb-js's own range scan, so `start`/`end` ARE the real (direction-independent)
140
+ * index-key bounds here — unlike query(), which uses startIndex/endIndex instead.
141
+ */
142
+ export interface OKDBIndexRangeOptions {
143
+ prefix?: OKDBIndexKey;
144
+ start?: OKDBIndexKey;
145
+ end?: OKDBIndexKey;
146
+ reverse?: boolean;
147
+ limit?: number;
148
+ offset?: number;
149
+ snapshot?: boolean;
150
+ transaction?: unknown;
151
+ /** byIndex only: include all entries violating a unique index instead of just the winner. */
152
+ includeViolations?: boolean;
153
+ }
154
+
133
155
  export interface OKDBGeoQueryOptions {
134
156
  lat: number;
135
157
  lon: number;