applesauce-sqlite 0.0.0-next-20250915145415 → 0.0.0-next-20250916120818
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/dist/better-sqlite3/event-database.d.ts +4 -12
- package/dist/better-sqlite3/event-database.js +6 -15
- package/dist/better-sqlite3/methods.d.ts +1 -1
- package/dist/better-sqlite3/methods.js +3 -7
- package/dist/bun/event-database.d.ts +4 -12
- package/dist/bun/event-database.js +7 -16
- package/dist/bun/methods.d.ts +1 -1
- package/dist/bun/methods.js +4 -8
- package/dist/libsql/event-database.d.ts +5 -13
- package/dist/libsql/event-database.js +8 -17
- package/dist/libsql/methods.d.ts +1 -1
- package/dist/libsql/methods.js +5 -6
- package/dist/native/event-database.d.ts +4 -12
- package/dist/native/event-database.js +6 -15
- package/dist/native/methods.d.ts +1 -1
- package/dist/native/methods.js +3 -7
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IEventDatabase } from "applesauce-core";
|
|
2
|
-
import {
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers";
|
|
3
3
|
import { type Database as TDatabase } from "better-sqlite3";
|
|
4
|
-
import { SearchContentFormatter } from "../helpers/search.js";
|
|
4
|
+
import { FilterWithSearch, SearchContentFormatter } from "../helpers/search.js";
|
|
5
5
|
/** Options for the {@link BetterSqlite3EventDatabase} */
|
|
6
6
|
export type BetterSqlite3EventDatabaseOptions = {
|
|
7
7
|
search?: boolean;
|
|
@@ -29,17 +29,9 @@ export declare class BetterSqlite3EventDatabase implements IEventDatabase {
|
|
|
29
29
|
/** Returns all the versions of a replaceable event */
|
|
30
30
|
getReplaceableHistory(kind: number, pubkey: string, identifier?: string): NostrEvent[];
|
|
31
31
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
32
|
-
getByFilters(filters:
|
|
33
|
-
search?: string;
|
|
34
|
-
}) | (Filter & {
|
|
35
|
-
search?: string;
|
|
36
|
-
})[]): Set<NostrEvent>;
|
|
32
|
+
getByFilters(filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
37
33
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
38
|
-
getTimeline(filters:
|
|
39
|
-
search?: string;
|
|
40
|
-
}) | (Filter & {
|
|
41
|
-
search?: string;
|
|
42
|
-
})[]): NostrEvent[];
|
|
34
|
+
getTimeline(filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
43
35
|
/** Set the search content formatter */
|
|
44
36
|
setSearchContentFormatter(formatter: SearchContentFormatter): void;
|
|
45
37
|
/** Get the current search content formatter */
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
|
-
import { insertEventIntoDescendingList } from "applesauce-core/helpers";
|
|
3
2
|
import Database from "better-sqlite3";
|
|
4
3
|
import { createTables, deleteEvent, getEvent, getEventsByFilters, getReplaceable, getReplaceableHistory, hasEvent, hasReplaceable, insertEvent, rebuildSearchIndex, } from "../better-sqlite3/methods.js";
|
|
5
4
|
import { enhancedSearchContentFormatter } from "../helpers/search.js";
|
|
@@ -60,23 +59,15 @@ export class BetterSqlite3EventDatabase {
|
|
|
60
59
|
}
|
|
61
60
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
62
61
|
getByFilters(filters) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return getEventsByFilters(this.db, filters);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
return new Set();
|
|
71
|
-
}
|
|
62
|
+
// If search is disabled, remove the search field from the filters
|
|
63
|
+
if (!this.search && (Array.isArray(filters) ? filters.some((f) => "search" in f) : "search" in filters))
|
|
64
|
+
throw new Error("Search is disabled");
|
|
65
|
+
return getEventsByFilters(this.db, filters);
|
|
72
66
|
}
|
|
73
67
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
74
68
|
getTimeline(filters) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (const event of events)
|
|
78
|
-
insertEventIntoDescendingList(timeline, event);
|
|
79
|
-
return timeline;
|
|
69
|
+
// No need to sort since query defaults to created_at descending order
|
|
70
|
+
return this.getByFilters(filters);
|
|
80
71
|
}
|
|
81
72
|
/** Set the search content formatter */
|
|
82
73
|
setSearchContentFormatter(formatter) {
|
|
@@ -24,7 +24,7 @@ export declare function getReplaceableHistory(db: Database, kind: number, pubkey
|
|
|
24
24
|
/** Checks if a replaceable event exists in a database */
|
|
25
25
|
export declare function hasReplaceable(db: Database, kind: number, pubkey: string, identifier?: string): boolean;
|
|
26
26
|
/** Get all events that match the filters (includes NIP-50 search support) */
|
|
27
|
-
export declare function getEventsByFilters(db: Database, filters: FilterWithSearch | FilterWithSearch[]):
|
|
27
|
+
export declare function getEventsByFilters(db: Database, filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
28
28
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
29
29
|
export declare function searchEvents(db: Database, search: string, options?: Filter): NostrEvent[];
|
|
30
30
|
/** Rebuild the FTS5 search index for all events */
|
|
@@ -112,14 +112,11 @@ export function hasReplaceable(db, kind, pubkey, identifier = "") {
|
|
|
112
112
|
export function getEventsByFilters(db, filters) {
|
|
113
113
|
const query = buildFiltersQuery(filters);
|
|
114
114
|
if (!query)
|
|
115
|
-
return
|
|
116
|
-
const eventSet = new Set();
|
|
115
|
+
return [];
|
|
117
116
|
const stmt = db.prepare(query.sql);
|
|
118
117
|
const rows = stmt.all(...query.params);
|
|
119
118
|
// Convert rows to events and add to set
|
|
120
|
-
|
|
121
|
-
eventSet.add(rowToEvent(row));
|
|
122
|
-
return eventSet;
|
|
119
|
+
return rows.map(rowToEvent);
|
|
123
120
|
}
|
|
124
121
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
125
122
|
export function searchEvents(db, search, options) {
|
|
@@ -131,8 +128,7 @@ export function searchEvents(db, search, options) {
|
|
|
131
128
|
...options,
|
|
132
129
|
};
|
|
133
130
|
// Use the main filter system which now supports search
|
|
134
|
-
|
|
135
|
-
return Array.from(results);
|
|
131
|
+
return getEventsByFilters(db, filter);
|
|
136
132
|
}
|
|
137
133
|
/** Rebuild the FTS5 search index for all events */
|
|
138
134
|
export function rebuildSearchIndex(db, contentFormatter) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IEventDatabase } from "applesauce-core";
|
|
2
|
-
import {
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers";
|
|
3
3
|
import { Database } from "bun:sqlite";
|
|
4
|
-
import { SearchContentFormatter } from "../helpers/search.js";
|
|
4
|
+
import { FilterWithSearch, SearchContentFormatter } from "../helpers/search.js";
|
|
5
5
|
/** Options for the {@link BunSqliteEventDatabase} */
|
|
6
6
|
export type BunSqliteEventDatabaseOptions = {
|
|
7
7
|
search?: boolean;
|
|
@@ -29,17 +29,9 @@ export declare class BunSqliteEventDatabase implements IEventDatabase {
|
|
|
29
29
|
/** Returns all the versions of a replaceable event */
|
|
30
30
|
getReplaceableHistory(kind: number, pubkey: string, identifier?: string): NostrEvent[];
|
|
31
31
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
32
|
-
getByFilters(filters:
|
|
33
|
-
search?: string;
|
|
34
|
-
}) | (Filter & {
|
|
35
|
-
search?: string;
|
|
36
|
-
})[]): Set<NostrEvent>;
|
|
32
|
+
getByFilters(filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
37
33
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
38
|
-
getTimeline(filters:
|
|
39
|
-
search?: string;
|
|
40
|
-
}) | (Filter & {
|
|
41
|
-
search?: string;
|
|
42
|
-
})[]): NostrEvent[];
|
|
34
|
+
getTimeline(filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
43
35
|
/** Set the search content formatter */
|
|
44
36
|
setSearchContentFormatter(formatter: SearchContentFormatter): void;
|
|
45
37
|
/** Get the current search content formatter */
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
|
-
import { insertEventIntoDescendingList } from "applesauce-core/helpers";
|
|
3
2
|
// @ts-ignore - bun:sqlite is a built-in module in Bun
|
|
4
3
|
import { Database } from "bun:sqlite";
|
|
5
|
-
import { createTables, deleteEvent, getEvent, getEventsByFilters, getReplaceable, getReplaceableHistory, hasEvent, hasReplaceable, insertEvent, rebuildSearchIndex, } from "./methods.js";
|
|
6
4
|
import { enhancedSearchContentFormatter } from "../helpers/search.js";
|
|
5
|
+
import { createTables, deleteEvent, getEvent, getEventsByFilters, getReplaceable, getReplaceableHistory, hasEvent, hasReplaceable, insertEvent, rebuildSearchIndex, } from "./methods.js";
|
|
7
6
|
const log = logger.extend("BunSqliteEventDatabase");
|
|
8
7
|
export class BunSqliteEventDatabase {
|
|
9
8
|
db;
|
|
@@ -61,23 +60,15 @@ export class BunSqliteEventDatabase {
|
|
|
61
60
|
}
|
|
62
61
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
63
62
|
getByFilters(filters) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return getEventsByFilters(this.db, filters);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
return new Set();
|
|
72
|
-
}
|
|
63
|
+
// If search is disabled, remove the search field from the filters
|
|
64
|
+
if (!this.search && (Array.isArray(filters) ? filters.some((f) => "search" in f) : "search" in filters))
|
|
65
|
+
throw new Error("Search is disabled");
|
|
66
|
+
return getEventsByFilters(this.db, filters);
|
|
73
67
|
}
|
|
74
68
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
75
69
|
getTimeline(filters) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (const event of events)
|
|
79
|
-
insertEventIntoDescendingList(timeline, event);
|
|
80
|
-
return timeline;
|
|
70
|
+
// No need to sort since query defaults to created_at descending order
|
|
71
|
+
return this.getByFilters(filters);
|
|
81
72
|
}
|
|
82
73
|
/** Set the search content formatter */
|
|
83
74
|
setSearchContentFormatter(formatter) {
|
package/dist/bun/methods.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function getReplaceableHistory(db: Database, kind: number, pubkey
|
|
|
24
24
|
/** Checks if a replaceable event exists in a database */
|
|
25
25
|
export declare function hasReplaceable(db: Database, kind: number, pubkey: string, identifier?: string): boolean;
|
|
26
26
|
/** Get all events that match the filters (includes NIP-50 search support) */
|
|
27
|
-
export declare function getEventsByFilters(db: Database, filters: FilterWithSearch | FilterWithSearch[]):
|
|
27
|
+
export declare function getEventsByFilters(db: Database, filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
28
28
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
29
29
|
export declare function searchEvents(db: Database, search: string, options?: Filter): NostrEvent[];
|
|
30
30
|
/** Rebuild the FTS5 search index for all events */
|
package/dist/bun/methods.js
CHANGED
|
@@ -114,14 +114,11 @@ export function hasReplaceable(db, kind, pubkey, identifier = "") {
|
|
|
114
114
|
export function getEventsByFilters(db, filters) {
|
|
115
115
|
const query = buildFiltersQuery(filters);
|
|
116
116
|
if (!query)
|
|
117
|
-
return
|
|
118
|
-
const eventSet = new Set();
|
|
117
|
+
return [];
|
|
119
118
|
const stmt = db.query(query.sql);
|
|
120
119
|
const rows = stmt.all(...query.params);
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
eventSet.add(rowToEvent(row));
|
|
124
|
-
return eventSet;
|
|
120
|
+
// Map rows to events
|
|
121
|
+
return rows.map(rowToEvent);
|
|
125
122
|
}
|
|
126
123
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
127
124
|
export function searchEvents(db, search, options) {
|
|
@@ -133,8 +130,7 @@ export function searchEvents(db, search, options) {
|
|
|
133
130
|
...options,
|
|
134
131
|
};
|
|
135
132
|
// Use the main filter system which now supports search
|
|
136
|
-
|
|
137
|
-
return Array.from(results);
|
|
133
|
+
return getEventsByFilters(db, filter);
|
|
138
134
|
}
|
|
139
135
|
/** Rebuild the FTS5 search index for all events */
|
|
140
136
|
export function rebuildSearchIndex(db, contentFormatter) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IAsyncEventDatabase } from "applesauce-core";
|
|
2
|
-
import { Filter, NostrEvent } from "applesauce-core/helpers";
|
|
3
1
|
import { Client } from "@libsql/client";
|
|
4
|
-
import {
|
|
2
|
+
import { IAsyncEventDatabase } from "applesauce-core";
|
|
3
|
+
import { NostrEvent } from "applesauce-core/helpers";
|
|
4
|
+
import { FilterWithSearch, SearchContentFormatter } from "../helpers/search.js";
|
|
5
5
|
/** Options for the {@link LibsqlEventDatabase} */
|
|
6
6
|
export type LibsqlEventDatabaseOptions = {
|
|
7
7
|
search?: boolean;
|
|
@@ -31,17 +31,9 @@ export declare class LibsqlEventDatabase implements IAsyncEventDatabase {
|
|
|
31
31
|
/** Returns all the versions of a replaceable event */
|
|
32
32
|
getReplaceableHistory(kind: number, pubkey: string, identifier?: string): Promise<NostrEvent[] | undefined>;
|
|
33
33
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
34
|
-
getByFilters(filters:
|
|
35
|
-
search?: string;
|
|
36
|
-
}) | (Filter & {
|
|
37
|
-
search?: string;
|
|
38
|
-
})[]): Promise<Set<NostrEvent>>;
|
|
34
|
+
getByFilters(filters: FilterWithSearch | FilterWithSearch[]): Promise<NostrEvent[]>;
|
|
39
35
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
40
|
-
getTimeline(filters:
|
|
41
|
-
search?: string;
|
|
42
|
-
}) | (Filter & {
|
|
43
|
-
search?: string;
|
|
44
|
-
})[]): Promise<NostrEvent[]>;
|
|
36
|
+
getTimeline(filters: FilterWithSearch | FilterWithSearch[]): Promise<NostrEvent[]>;
|
|
45
37
|
/** Set the search content formatter */
|
|
46
38
|
setSearchContentFormatter(formatter: SearchContentFormatter): void;
|
|
47
39
|
/** Get the current search content formatter */
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { logger } from "applesauce-core";
|
|
2
|
-
import { insertEventIntoDescendingList } from "applesauce-core/helpers";
|
|
3
1
|
import { createClient } from "@libsql/client";
|
|
4
|
-
import {
|
|
2
|
+
import { logger } from "applesauce-core";
|
|
5
3
|
import { enhancedSearchContentFormatter } from "../helpers/search.js";
|
|
4
|
+
import { createTables, deleteEvent, getEvent, getEventsByFilters, getReplaceable, getReplaceableHistory, hasEvent, hasReplaceable, insertEvent, rebuildSearchIndex, } from "./methods.js";
|
|
6
5
|
const log = logger.extend("LibsqlEventDatabase");
|
|
7
6
|
export class LibsqlEventDatabase {
|
|
8
7
|
db;
|
|
@@ -62,23 +61,15 @@ export class LibsqlEventDatabase {
|
|
|
62
61
|
}
|
|
63
62
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
64
63
|
async getByFilters(filters) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return await getEventsByFilters(this.db, filters);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
return new Set();
|
|
73
|
-
}
|
|
64
|
+
// If search is disabled, remove the search field from the filters
|
|
65
|
+
if (!this.search && (Array.isArray(filters) ? filters.some((f) => "search" in f) : "search" in filters))
|
|
66
|
+
throw new Error("Search is disabled");
|
|
67
|
+
return await getEventsByFilters(this.db, filters);
|
|
74
68
|
}
|
|
75
69
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
76
70
|
async getTimeline(filters) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (const event of events)
|
|
80
|
-
insertEventIntoDescendingList(timeline, event);
|
|
81
|
-
return timeline;
|
|
71
|
+
// No need to sort since query defaults to created_at descending order
|
|
72
|
+
return await this.getByFilters(filters);
|
|
82
73
|
}
|
|
83
74
|
/** Set the search content formatter */
|
|
84
75
|
setSearchContentFormatter(formatter) {
|
package/dist/libsql/methods.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function getReplaceableHistory(db: Client, kind: number, pubkey:
|
|
|
24
24
|
/** Checks if a replaceable event exists in a database */
|
|
25
25
|
export declare function hasReplaceable(db: Client, kind: number, pubkey: string, identifier?: string): Promise<boolean>;
|
|
26
26
|
/** Get all events that match the filters (includes NIP-50 search support) */
|
|
27
|
-
export declare function getEventsByFilters(db: Client, filters: FilterWithSearch | FilterWithSearch[]): Promise<
|
|
27
|
+
export declare function getEventsByFilters(db: Client, filters: FilterWithSearch | FilterWithSearch[]): Promise<NostrEvent[]>;
|
|
28
28
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
29
29
|
export declare function searchEvents(db: Client, search: string, options?: Filter): Promise<NostrEvent[]>;
|
|
30
30
|
/** Rebuild the FTS5 search index for all events */
|
package/dist/libsql/methods.js
CHANGED
|
@@ -187,15 +187,15 @@ export async function hasReplaceable(db, kind, pubkey, identifier = "") {
|
|
|
187
187
|
export async function getEventsByFilters(db, filters) {
|
|
188
188
|
const query = buildFiltersQuery(filters);
|
|
189
189
|
if (!query)
|
|
190
|
-
return
|
|
191
|
-
const
|
|
190
|
+
return [];
|
|
191
|
+
const events = [];
|
|
192
192
|
const result = await db.execute({
|
|
193
193
|
sql: query.sql,
|
|
194
194
|
args: query.params,
|
|
195
195
|
});
|
|
196
196
|
// Convert rows to events and add to set
|
|
197
197
|
for (const row of result.rows) {
|
|
198
|
-
|
|
198
|
+
events.push(rowToEvent({
|
|
199
199
|
id: row[0],
|
|
200
200
|
kind: row[1],
|
|
201
201
|
pubkey: row[2],
|
|
@@ -205,7 +205,7 @@ export async function getEventsByFilters(db, filters) {
|
|
|
205
205
|
sig: row[6],
|
|
206
206
|
}));
|
|
207
207
|
}
|
|
208
|
-
return
|
|
208
|
+
return events;
|
|
209
209
|
}
|
|
210
210
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
211
211
|
export async function searchEvents(db, search, options) {
|
|
@@ -217,8 +217,7 @@ export async function searchEvents(db, search, options) {
|
|
|
217
217
|
...options,
|
|
218
218
|
};
|
|
219
219
|
// Use the main filter system which now supports search
|
|
220
|
-
|
|
221
|
-
return Array.from(results);
|
|
220
|
+
return await getEventsByFilters(db, filter);
|
|
222
221
|
}
|
|
223
222
|
/** Rebuild the FTS5 search index for all events */
|
|
224
223
|
export async function rebuildSearchIndex(db, contentFormatter) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IEventDatabase } from "applesauce-core";
|
|
2
|
-
import {
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers";
|
|
3
3
|
import { DatabaseSync } from "node:sqlite";
|
|
4
|
-
import { SearchContentFormatter } from "../helpers/search.js";
|
|
4
|
+
import { FilterWithSearch, SearchContentFormatter } from "../helpers/search.js";
|
|
5
5
|
/** Options for the {@link NativeSqliteEventDatabase} */
|
|
6
6
|
export type NativeSqliteEventDatabaseOptions = {
|
|
7
7
|
search?: boolean;
|
|
@@ -29,17 +29,9 @@ export declare class NativeSqliteEventDatabase implements IEventDatabase {
|
|
|
29
29
|
/** Returns all the versions of a replaceable event */
|
|
30
30
|
getReplaceableHistory(kind: number, pubkey: string, identifier?: string): NostrEvent[];
|
|
31
31
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
32
|
-
getByFilters(filters:
|
|
33
|
-
search?: string;
|
|
34
|
-
}) | (Filter & {
|
|
35
|
-
search?: string;
|
|
36
|
-
})[]): Set<NostrEvent>;
|
|
32
|
+
getByFilters(filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
37
33
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
38
|
-
getTimeline(filters:
|
|
39
|
-
search?: string;
|
|
40
|
-
}) | (Filter & {
|
|
41
|
-
search?: string;
|
|
42
|
-
})[]): NostrEvent[];
|
|
34
|
+
getTimeline(filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
43
35
|
/** Set the search content formatter */
|
|
44
36
|
setSearchContentFormatter(formatter: SearchContentFormatter): void;
|
|
45
37
|
/** Get the current search content formatter */
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { logger } from "applesauce-core";
|
|
2
|
-
import { insertEventIntoDescendingList } from "applesauce-core/helpers";
|
|
3
2
|
import { DatabaseSync } from "node:sqlite";
|
|
4
3
|
import { enhancedSearchContentFormatter } from "../helpers/search.js";
|
|
5
4
|
import { createTables, deleteEvent, getEvent, getEventsByFilters, getReplaceable, getReplaceableHistory, hasEvent, hasReplaceable, insertEvent, rebuildSearchIndex, } from "./methods.js";
|
|
@@ -60,23 +59,15 @@ export class NativeSqliteEventDatabase {
|
|
|
60
59
|
}
|
|
61
60
|
/** Get all events that match the filters (supports NIP-50 search field) */
|
|
62
61
|
getByFilters(filters) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return getEventsByFilters(this.db, filters);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
return new Set();
|
|
71
|
-
}
|
|
62
|
+
// If search is disabled, remove the search field from the filters
|
|
63
|
+
if (!this.search && (Array.isArray(filters) ? filters.some((f) => "search" in f) : "search" in filters))
|
|
64
|
+
throw new Error("Search is disabled");
|
|
65
|
+
return getEventsByFilters(this.db, filters);
|
|
72
66
|
}
|
|
73
67
|
/** Get a timeline of events that match the filters (returns array in chronological order, supports NIP-50 search) */
|
|
74
68
|
getTimeline(filters) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (const event of events)
|
|
78
|
-
insertEventIntoDescendingList(timeline, event);
|
|
79
|
-
return timeline;
|
|
69
|
+
// No need to sort since query defaults to created_at descending order
|
|
70
|
+
return this.getByFilters(filters);
|
|
80
71
|
}
|
|
81
72
|
/** Set the search content formatter */
|
|
82
73
|
setSearchContentFormatter(formatter) {
|
package/dist/native/methods.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function getReplaceableHistory(db: DatabaseSync, kind: number, pu
|
|
|
24
24
|
/** Checks if a replaceable event exists in a database */
|
|
25
25
|
export declare function hasReplaceable(db: DatabaseSync, kind: number, pubkey: string, identifier?: string): boolean;
|
|
26
26
|
/** Get all events that match the filters (includes NIP-50 search support) */
|
|
27
|
-
export declare function getEventsByFilters(db: DatabaseSync, filters: FilterWithSearch | FilterWithSearch[]):
|
|
27
|
+
export declare function getEventsByFilters(db: DatabaseSync, filters: FilterWithSearch | FilterWithSearch[]): NostrEvent[];
|
|
28
28
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
29
29
|
export declare function searchEvents(db: DatabaseSync, search: string, options?: Filter): NostrEvent[];
|
|
30
30
|
/** Rebuild the FTS5 search index for all events */
|
package/dist/native/methods.js
CHANGED
|
@@ -131,14 +131,11 @@ export function hasReplaceable(db, kind, pubkey, identifier = "") {
|
|
|
131
131
|
export function getEventsByFilters(db, filters) {
|
|
132
132
|
const query = buildFiltersQuery(filters);
|
|
133
133
|
if (!query)
|
|
134
|
-
return
|
|
135
|
-
const eventSet = new Set();
|
|
134
|
+
return [];
|
|
136
135
|
const stmt = db.prepare(query.sql);
|
|
137
136
|
const rows = stmt.all(...query.params);
|
|
138
137
|
// Convert rows to events and add to set
|
|
139
|
-
|
|
140
|
-
eventSet.add(rowToEvent(row));
|
|
141
|
-
return eventSet;
|
|
138
|
+
return rows.map(rowToEvent);
|
|
142
139
|
}
|
|
143
140
|
/** Search events using FTS5 full-text search (convenience wrapper around getEventsByFilters) */
|
|
144
141
|
export function searchEvents(db, search, options) {
|
|
@@ -150,8 +147,7 @@ export function searchEvents(db, search, options) {
|
|
|
150
147
|
...options,
|
|
151
148
|
};
|
|
152
149
|
// Use the main filter system which now supports search
|
|
153
|
-
|
|
154
|
-
return Array.from(results);
|
|
150
|
+
return getEventsByFilters(db, filter);
|
|
155
151
|
}
|
|
156
152
|
/** Rebuild the FTS5 search index for all events */
|
|
157
153
|
export function rebuildSearchIndex(db, contentFormatter) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-sqlite",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250916120818",
|
|
4
4
|
"description": "sqlite event databases for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"applesauce-core": "0.0.0-next-
|
|
85
|
+
"applesauce-core": "0.0.0-next-20250916120818"
|
|
86
86
|
},
|
|
87
87
|
"optionalDependencies": {
|
|
88
88
|
"better-sqlite3": "^12.2.0",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@types/better-sqlite3": "^7.6.13",
|
|
94
94
|
"@types/bun": "^1.2.22",
|
|
95
95
|
"@types/ws": "^8.5.13",
|
|
96
|
-
"applesauce-signers": "0.0.0-next-
|
|
96
|
+
"applesauce-signers": "0.0.0-next-20250916120818",
|
|
97
97
|
"typescript": "^5.7.3",
|
|
98
98
|
"vitest": "^3.2.4",
|
|
99
99
|
"vitest-websocket-mock": "^0.5.0",
|