applesauce-core 0.0.0-next-20251220152312 → 0.0.0-next-20251231062646
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/event-store/async-event-store.d.ts +3 -3
- package/dist/event-store/event-memory.d.ts +11 -11
- package/dist/event-store/event-memory.js +12 -4
- package/dist/event-store/event-store.d.ts +3 -3
- package/dist/helpers/event-cache.d.ts +1 -1
- package/dist/helpers/pointers.d.ts +4 -0
- package/dist/helpers/pointers.js +21 -0
- package/dist/helpers/profile.d.ts +22 -0
- package/dist/helpers/relays.d.ts +0 -5
- package/dist/observable/map-events-to-store.d.ts +1 -1
- package/package.json +2 -2
- package/dist/helpers/external-id.d.ts +0 -29
- package/dist/helpers/external-id.js +0 -20
|
@@ -43,11 +43,11 @@ export declare class AsyncEventStore extends EventModels implements IAsyncEventS
|
|
|
43
43
|
/** Sets the method used to verify events */
|
|
44
44
|
set verifyEvent(method: undefined | ((event: NostrEvent) => boolean));
|
|
45
45
|
/** A stream of new events added to the store */
|
|
46
|
-
insert$: Subject<
|
|
46
|
+
insert$: Subject<NostrEvent>;
|
|
47
47
|
/** A stream of events that have been updated (Warning: this is a very noisy stream, use with caution) */
|
|
48
|
-
update$: Subject<
|
|
48
|
+
update$: Subject<NostrEvent>;
|
|
49
49
|
/** A stream of events that have been removed */
|
|
50
|
-
remove$: Subject<
|
|
50
|
+
remove$: Subject<NostrEvent>;
|
|
51
51
|
/**
|
|
52
52
|
* A method that will be called when an event isn't found in the store
|
|
53
53
|
*/
|
|
@@ -6,16 +6,16 @@ import { IEventMemory } from "./interface.js";
|
|
|
6
6
|
export declare class EventMemory implements IEventMemory {
|
|
7
7
|
protected log: import("debug").Debugger;
|
|
8
8
|
/** Indexes */
|
|
9
|
-
protected kinds: Map<number, Set<
|
|
10
|
-
protected authors: Map<string, Set<
|
|
11
|
-
protected tags: LRU<Set<
|
|
9
|
+
protected kinds: Map<number, Set<NostrEvent>>;
|
|
10
|
+
protected authors: Map<string, Set<NostrEvent>>;
|
|
11
|
+
protected tags: LRU<Set<NostrEvent>>;
|
|
12
12
|
protected created_at: NostrEvent[];
|
|
13
13
|
/** Composite index for kind+author queries (common pattern) */
|
|
14
|
-
protected kindAuthor: Map<string, Set<
|
|
14
|
+
protected kindAuthor: Map<string, Set<NostrEvent>>;
|
|
15
15
|
/** LRU cache of last events touched */
|
|
16
|
-
events: LRU<
|
|
16
|
+
events: LRU<NostrEvent>;
|
|
17
17
|
/** A sorted array of replaceable events by address */
|
|
18
|
-
protected replaceable: Map<string,
|
|
18
|
+
protected replaceable: Map<string, NostrEvent[]>;
|
|
19
19
|
/** The number of events in the database */
|
|
20
20
|
get size(): number;
|
|
21
21
|
/** Checks if the database contains an event without touching it */
|
|
@@ -41,7 +41,7 @@ export declare class EventMemory implements IEventMemory {
|
|
|
41
41
|
/** Notify the database that an event has updated */
|
|
42
42
|
update(_event: NostrEvent): void;
|
|
43
43
|
/** A weak map of events to claim reference counts */
|
|
44
|
-
protected claims: WeakMap<
|
|
44
|
+
protected claims: WeakMap<NostrEvent, number>;
|
|
45
45
|
/** Moves an event to the top of the LRU cache */
|
|
46
46
|
touch(event: NostrEvent): void;
|
|
47
47
|
/** Increments the claim count on the event and touches it */
|
|
@@ -57,10 +57,10 @@ export declare class EventMemory implements IEventMemory {
|
|
|
57
57
|
/** Removes events that are not claimed (free up memory) */
|
|
58
58
|
prune(limit?: number): number;
|
|
59
59
|
/** Index helper methods */
|
|
60
|
-
protected getKindIndex(kind: number): Set<
|
|
61
|
-
protected getAuthorsIndex(author: string): Set<
|
|
62
|
-
protected getKindAuthorIndex(kind: number, pubkey: string): Set<
|
|
63
|
-
protected getTagIndex(tagAndValue: string): Set<
|
|
60
|
+
protected getKindIndex(kind: number): Set<NostrEvent>;
|
|
61
|
+
protected getAuthorsIndex(author: string): Set<NostrEvent>;
|
|
62
|
+
protected getKindAuthorIndex(kind: number, pubkey: string): Set<NostrEvent>;
|
|
63
|
+
protected getTagIndex(tagAndValue: string): Set<NostrEvent>;
|
|
64
64
|
/**
|
|
65
65
|
* Helper method to remove an event from a sorted array using binary search.
|
|
66
66
|
* Falls back to indexOf if binary search doesn't find exact match.
|
|
@@ -312,6 +312,9 @@ export class EventMemory {
|
|
|
312
312
|
}
|
|
313
313
|
/** Iterates over all events by time */
|
|
314
314
|
*iterateTime(since, until) {
|
|
315
|
+
// Early return if array is empty
|
|
316
|
+
if (this.created_at.length === 0)
|
|
317
|
+
return;
|
|
315
318
|
let startIndex = 0;
|
|
316
319
|
let endIndex = this.created_at.length - 1;
|
|
317
320
|
// If until is set, use binary search to find better start index
|
|
@@ -320,16 +323,21 @@ export class EventMemory {
|
|
|
320
323
|
return mid.created_at - until;
|
|
321
324
|
})
|
|
322
325
|
: undefined;
|
|
323
|
-
if (start)
|
|
324
|
-
startIndex = start[0];
|
|
326
|
+
if (start) {
|
|
327
|
+
startIndex = Math.max(0, Math.min(start[0], this.created_at.length - 1));
|
|
328
|
+
}
|
|
325
329
|
// If since is set, use binary search to find better end index
|
|
326
330
|
const end = since
|
|
327
331
|
? binarySearch(this.created_at, (mid) => {
|
|
328
332
|
return mid.created_at - since;
|
|
329
333
|
})
|
|
330
334
|
: undefined;
|
|
331
|
-
if (end)
|
|
332
|
-
endIndex = end[0];
|
|
335
|
+
if (end) {
|
|
336
|
+
endIndex = Math.max(0, Math.min(end[0], this.created_at.length - 1));
|
|
337
|
+
}
|
|
338
|
+
// Ensure startIndex <= endIndex
|
|
339
|
+
if (startIndex > endIndex)
|
|
340
|
+
return;
|
|
333
341
|
// Yield events in the range, filtering by exact bounds
|
|
334
342
|
for (let i = startIndex; i <= endIndex; i++) {
|
|
335
343
|
const event = this.created_at[i];
|
|
@@ -43,11 +43,11 @@ export declare class EventStore extends EventModels implements IEventStore {
|
|
|
43
43
|
/** Sets the method used to verify events */
|
|
44
44
|
set verifyEvent(method: undefined | ((event: NostrEvent) => boolean));
|
|
45
45
|
/** A stream of new events added to the store */
|
|
46
|
-
insert$: Subject<
|
|
46
|
+
insert$: Subject<NostrEvent>;
|
|
47
47
|
/** A stream of events that have been updated (Warning: this is a very noisy stream, use with caution) */
|
|
48
|
-
update$: Subject<
|
|
48
|
+
update$: Subject<NostrEvent>;
|
|
49
49
|
/** A stream of events that have been removed */
|
|
50
|
-
remove$: Subject<
|
|
50
|
+
remove$: Subject<NostrEvent>;
|
|
51
51
|
/** A method that will be called when an event isn't found in the store */
|
|
52
52
|
eventLoader?: (pointer: EventPointer | AddressPointer | AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
|
|
53
53
|
constructor(options?: EventStoreOptions);
|
|
@@ -9,7 +9,7 @@ import { IEventStoreStreams } from "../event-store/interface.js";
|
|
|
9
9
|
* @param opts.maxBatchSize - The maximum number of events to write in a batch
|
|
10
10
|
* @returns A function to stop the process
|
|
11
11
|
*/
|
|
12
|
-
export declare function persistEventsToCache(eventStore: IEventStoreStreams, write: (events: NostrEvent[]) => Promise<
|
|
12
|
+
export declare function persistEventsToCache(eventStore: IEventStoreStreams, write: (events: NostrEvent[]) => Promise<any>, opts?: {
|
|
13
13
|
maxBatchSize?: number;
|
|
14
14
|
batchTime?: number;
|
|
15
15
|
}): () => void;
|
|
@@ -20,6 +20,8 @@ export declare function getPubkeyFromDecodeResult(result?: DecodeResult): string
|
|
|
20
20
|
export declare function getRelaysFromDecodeResult(result?: DecodeResult): string[] | undefined;
|
|
21
21
|
/** Encodes the result of nip19.decode */
|
|
22
22
|
export declare function encodeDecodeResult(result: DecodeResult): "" | `nevent1${string}` | `nprofile1${string}` | `naddr1${string}` | `nsec1${string}` | `npub1${string}` | `note1${string}`;
|
|
23
|
+
/** Encodes a pointer to a NIP-19 string */
|
|
24
|
+
export declare function encodePointer(pointer: AddressPointer | EventPointer | ProfilePointer): string;
|
|
23
25
|
/** Gets an EventPointer form a common "e" tag */
|
|
24
26
|
export declare function getEventPointerFromETag(tag: string[]): EventPointer | null;
|
|
25
27
|
/** Gets an EventPointer form a common "q" tag */
|
|
@@ -30,6 +32,8 @@ export declare function getAddressPointerFromATag(tag: string[]): AddressPointer
|
|
|
30
32
|
export declare function getProfilePointerFromPTag(tag: string[]): ProfilePointer | null;
|
|
31
33
|
/** Checks if a pointer is an AddressPointer */
|
|
32
34
|
export declare function isAddressPointer(pointer: any): pointer is AddressPointer;
|
|
35
|
+
/** Checks if a pointer is a ProfilePointer */
|
|
36
|
+
export declare function isProfilePointer(pointer: any): pointer is ProfilePointer;
|
|
33
37
|
/** Checks if a pointer is an EventPointer */
|
|
34
38
|
export declare function isEventPointer(pointer: any): pointer is EventPointer;
|
|
35
39
|
/** Returns the stringified address pointer */
|
package/dist/helpers/pointers.js
CHANGED
|
@@ -106,6 +106,17 @@ export function encodeDecodeResult(result) {
|
|
|
106
106
|
}
|
|
107
107
|
return "";
|
|
108
108
|
}
|
|
109
|
+
/** Encodes a pointer to a NIP-19 string */
|
|
110
|
+
export function encodePointer(pointer) {
|
|
111
|
+
if (isAddressPointer(pointer))
|
|
112
|
+
return naddrEncode(pointer);
|
|
113
|
+
else if (isEventPointer(pointer))
|
|
114
|
+
return neventEncode(pointer);
|
|
115
|
+
else if (isProfilePointer(pointer))
|
|
116
|
+
return nprofileEncode(pointer);
|
|
117
|
+
else
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
109
120
|
/** Gets an EventPointer form a common "e" tag */
|
|
110
121
|
export function getEventPointerFromETag(tag) {
|
|
111
122
|
const id = tag[1];
|
|
@@ -160,6 +171,16 @@ export function isAddressPointer(pointer) {
|
|
|
160
171
|
typeof pointer.pubkey === "string" &&
|
|
161
172
|
typeof pointer.kind === "number");
|
|
162
173
|
}
|
|
174
|
+
/** Checks if a pointer is a ProfilePointer */
|
|
175
|
+
export function isProfilePointer(pointer) {
|
|
176
|
+
return (typeof pointer === "object" &&
|
|
177
|
+
pointer !== null &&
|
|
178
|
+
"pubkey" in pointer &&
|
|
179
|
+
typeof pointer.pubkey === "string" &&
|
|
180
|
+
// Ensure its not an event or address pointer since they both have a pubkey fields
|
|
181
|
+
!isEventPointer(pointer) &&
|
|
182
|
+
!isAddressPointer(pointer));
|
|
183
|
+
}
|
|
163
184
|
/** Checks if a pointer is an EventPointer */
|
|
164
185
|
export function isEventPointer(pointer) {
|
|
165
186
|
return typeof pointer === "object" && pointer !== null && "id" in pointer && typeof pointer.id === "string";
|
|
@@ -1,21 +1,43 @@
|
|
|
1
1
|
import { KnownEvent, NostrEvent, kinds } from "./event.js";
|
|
2
2
|
export declare const ProfileContentSymbol: unique symbol;
|
|
3
3
|
export type ProfileContent = {
|
|
4
|
+
/** Nickname or full name of the user */
|
|
4
5
|
name?: string;
|
|
5
6
|
/** @deprecated use name instead */
|
|
6
7
|
username?: string;
|
|
8
|
+
/** An alternative, bigger name with richer characters than `name`. `name` should always be set regardless of the presence of `display_name`. */
|
|
7
9
|
display_name?: string;
|
|
8
10
|
/** @deprecated use display_name instead */
|
|
9
11
|
displayName?: string;
|
|
12
|
+
/** Short bio or description of the user */
|
|
10
13
|
about?: string;
|
|
11
14
|
/** @deprecated use picture instead */
|
|
12
15
|
image?: string;
|
|
16
|
+
/** URL of the profile picture image */
|
|
13
17
|
picture?: string;
|
|
18
|
+
/** URL to a wide (~1024x768) picture to be optionally displayed in the background of a profile screen */
|
|
14
19
|
banner?: string;
|
|
20
|
+
/** A web URL related in any way to the event author */
|
|
15
21
|
website?: string;
|
|
22
|
+
/** Lightning address in the format `user@domain.com` (LUD-16 format) */
|
|
16
23
|
lud16?: string;
|
|
24
|
+
/** Lightning address in the format `user@domain.com` (LUD-06 format) */
|
|
17
25
|
lud06?: string;
|
|
26
|
+
/** DNS-based verification identifier in the format `_@domain.com` or `user@domain.com` */
|
|
18
27
|
nip05?: string;
|
|
28
|
+
/** Boolean to clarify that the content is entirely or partially the result of automation, such as with chatbots or newsfeeds */
|
|
29
|
+
bot?: boolean;
|
|
30
|
+
/** Object representing the author's birth date. Each field may be omitted. */
|
|
31
|
+
birthday?: {
|
|
32
|
+
/** Birth year */
|
|
33
|
+
year?: number;
|
|
34
|
+
/** Birth month (1-12) */
|
|
35
|
+
month?: number;
|
|
36
|
+
/** Birth day (1-31) */
|
|
37
|
+
day?: number;
|
|
38
|
+
};
|
|
39
|
+
/** An array of strings representing the author's preferred languages (in order of preference), each in IETF BCP 47 format (e.g., ["en", "ja"], ["es-AR", "en-US"]). The first element is the primary language. */
|
|
40
|
+
languages?: string[];
|
|
19
41
|
};
|
|
20
42
|
/** Type for validated profile events */
|
|
21
43
|
export type ProfileEvent = KnownEvent<kinds.Metadata>;
|
package/dist/helpers/relays.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { NostrEvent } from "./event.js";
|
|
2
2
|
export declare const SeenRelaysSymbol: unique symbol;
|
|
3
|
-
declare module "nostr-tools" {
|
|
4
|
-
interface Event {
|
|
5
|
-
[SeenRelaysSymbol]?: Set<string>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
/** Marks an event as being seen on a relay */
|
|
9
4
|
export declare function addSeenRelay(event: NostrEvent, relay: string): Set<string>;
|
|
10
5
|
/** Returns the set of relays this event was seen on */
|
|
@@ -4,4 +4,4 @@ import { IAsyncEventStoreActions, IEventStoreActions } from "../event-store/inte
|
|
|
4
4
|
/** Saves all events to an event store and filters out invalid events */
|
|
5
5
|
export declare function mapEventsToStore(store: IEventStoreActions | IAsyncEventStoreActions, removeDuplicates?: boolean): MonoTypeOperatorFunction<NostrEvent>;
|
|
6
6
|
/** Alias for {@link mapEventsToStore} */
|
|
7
|
-
export declare const filterDuplicateEvents: (store: IEventStoreActions | IAsyncEventStoreActions) => MonoTypeOperatorFunction<
|
|
7
|
+
export declare const filterDuplicateEvents: (store: IEventStoreActions | IAsyncEventStoreActions) => MonoTypeOperatorFunction<NostrEvent>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-core",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20251231062646",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"fast-deep-equal": "^3.1.3",
|
|
82
82
|
"hash-sum": "^2.0.0",
|
|
83
83
|
"nanoid": "^5.0.9",
|
|
84
|
-
"nostr-tools": "~2.
|
|
84
|
+
"nostr-tools": "~2.19",
|
|
85
85
|
"rxjs": "^7.8.1"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type ExternalIdentifiers = {
|
|
2
|
-
"#": `#${string}`;
|
|
3
|
-
geo: `geo:${string}`;
|
|
4
|
-
isbn: `isbn:${string}`;
|
|
5
|
-
"podcast:guid": `podcast:guid:${string}`;
|
|
6
|
-
"podcast:item:guid": `podcast:item:guid:${string}`;
|
|
7
|
-
"podcast:publisher:guid": `podcast:publisher:guid:${string}`;
|
|
8
|
-
isan: `isan:${string}`;
|
|
9
|
-
doi: `doi:${string}`;
|
|
10
|
-
};
|
|
11
|
-
export type ExternalPointer<Prefix extends keyof ExternalIdentifiers> = {
|
|
12
|
-
kind: Prefix;
|
|
13
|
-
identifier: ExternalIdentifiers[Prefix];
|
|
14
|
-
};
|
|
15
|
-
export type ParseResult = {
|
|
16
|
-
[P in keyof ExternalIdentifiers]: ExternalPointer<P>;
|
|
17
|
-
}[keyof ExternalIdentifiers];
|
|
18
|
-
/**
|
|
19
|
-
* Parses a NIP-73 external identifier
|
|
20
|
-
* @throws
|
|
21
|
-
*/
|
|
22
|
-
export declare function parseExternalPointer<Prefix extends keyof ExternalIdentifiers>(identifier: `${Prefix}1${string}`): ExternalPointer<Prefix>;
|
|
23
|
-
export declare function parseExternalPointer(identifier: string): ParseResult;
|
|
24
|
-
/**
|
|
25
|
-
* Gets an ExternalPointer for a "i" tag
|
|
26
|
-
* @throws
|
|
27
|
-
*/
|
|
28
|
-
export declare function getExternalPointerFromTag<Prefix extends keyof ExternalIdentifiers>(tag: string[]): ExternalPointer<Prefix>;
|
|
29
|
-
export declare function getExternalPointerFromTag(tag: string[]): ParseResult;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function parseExternalPointer(identifier) {
|
|
2
|
-
if (identifier.startsWith("#"))
|
|
3
|
-
return { kind: "#", identifier: identifier };
|
|
4
|
-
if (identifier.startsWith("geo:"))
|
|
5
|
-
return { kind: "geo", identifier: identifier };
|
|
6
|
-
if (identifier.startsWith("podcast:guid:"))
|
|
7
|
-
return { kind: "podcast:guid", identifier: identifier };
|
|
8
|
-
if (identifier.startsWith("podcast:item:guid:"))
|
|
9
|
-
return { kind: "podcast:item:guid", identifier: identifier };
|
|
10
|
-
if (identifier.startsWith("podcast:publisher:guid:"))
|
|
11
|
-
return { kind: "podcast:publisher:guid", identifier: identifier };
|
|
12
|
-
if (identifier.startsWith("isan:"))
|
|
13
|
-
return { kind: "isan", identifier: identifier };
|
|
14
|
-
if (identifier.startsWith("doi:"))
|
|
15
|
-
return { kind: "doi", identifier: identifier };
|
|
16
|
-
throw new Error("Failed to parse external identifier");
|
|
17
|
-
}
|
|
18
|
-
export function getExternalPointerFromTag(tag) {
|
|
19
|
-
return parseExternalPointer(tag[1]);
|
|
20
|
-
}
|