applesauce-core 0.0.0-next-20251220152312 → 0.0.0-next-20251231055351
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/event-memory.js +12 -4
- 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/package.json +1 -1
- package/dist/helpers/external-id.d.ts +0 -29
- package/dist/helpers/external-id.js +0 -20
|
@@ -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];
|
|
@@ -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/package.json
CHANGED
|
@@ -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
|
-
}
|