applesauce-core 0.6.0 → 0.7.0
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/database.d.ts +3 -2
- package/dist/event-store/database.js +4 -1
- package/dist/helpers/emoji.d.ts +2 -0
- package/dist/helpers/emoji.js +4 -0
- package/dist/helpers/hashtag.d.ts +2 -0
- package/dist/helpers/hashtag.js +7 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/string.d.ts +2 -0
- package/dist/helpers/string.js +3 -0
- package/dist/helpers/url.d.ts +11 -0
- package/dist/helpers/url.js +29 -0
- package/dist/observable/getValue.d.ts +2 -0
- package/dist/observable/getValue.js +11 -0
- package/dist/observable/index.d.ts +1 -0
- package/dist/observable/index.js +1 -0
- package/dist/query-store/index.d.ts +3 -2
- package/dist/query-store/index.js +1 -1
- package/package.json +1 -1
- /package/dist/{utils → helpers}/lru.d.ts +0 -0
- /package/dist/{utils → helpers}/lru.js +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="debug" />
|
|
2
2
|
/// <reference types="zen-observable" />
|
|
3
3
|
import { Filter, NostrEvent } from "nostr-tools";
|
|
4
|
-
import { LRU } from "../
|
|
4
|
+
import { LRU } from "../helpers/lru.js";
|
|
5
5
|
/**
|
|
6
6
|
* An in-memory database for nostr events
|
|
7
7
|
*/
|
|
8
8
|
export declare class Database {
|
|
9
|
-
log: import("debug").Debugger;
|
|
9
|
+
protected log: import("debug").Debugger;
|
|
10
10
|
/** Indexes */
|
|
11
11
|
protected kinds: Map<number, Set<import("nostr-tools").Event>>;
|
|
12
12
|
protected authors: Map<string, Set<import("nostr-tools").Event>>;
|
|
@@ -56,6 +56,7 @@ export declare class Database {
|
|
|
56
56
|
flatMap<R_2>(callback: (value: import("nostr-tools").Event) => ZenObservable.ObservableLike<R_2>): import("zen-observable")<R_2>;
|
|
57
57
|
concat<R_3>(...observable: import("zen-observable")<R_3>[]): import("zen-observable")<R_3>;
|
|
58
58
|
};
|
|
59
|
+
get size(): number;
|
|
59
60
|
protected claims: WeakMap<import("nostr-tools").Event, any>;
|
|
60
61
|
/** Index helper methods */
|
|
61
62
|
protected getKindIndex(kind: number): Set<import("nostr-tools").Event>;
|
|
@@ -3,7 +3,7 @@ import PushStream from "zen-push";
|
|
|
3
3
|
import { getEventUID, getIndexableTags, getReplaceableUID } from "../helpers/event.js";
|
|
4
4
|
import { INDEXABLE_TAGS } from "./common.js";
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
|
-
import { LRU } from "../
|
|
6
|
+
import { LRU } from "../helpers/lru.js";
|
|
7
7
|
/**
|
|
8
8
|
* An in-memory database for nostr events
|
|
9
9
|
*/
|
|
@@ -25,6 +25,9 @@ export class Database {
|
|
|
25
25
|
updated = this.updatedSignal.observable;
|
|
26
26
|
/** A stream of events removed of the database */
|
|
27
27
|
deleted = this.deletedSignal.observable;
|
|
28
|
+
get size() {
|
|
29
|
+
return this.events.size;
|
|
30
|
+
}
|
|
28
31
|
claims = new WeakMap();
|
|
29
32
|
/** Index helper methods */
|
|
30
33
|
getKindIndex(kind) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { stripInvisibleChar } from "./string.js";
|
|
2
|
+
export function getHashtagTag(event, hashtag) {
|
|
3
|
+
hashtag = stripInvisibleChar(hashtag.replace(/^#/, "").toLocaleLowerCase());
|
|
4
|
+
return event.tags
|
|
5
|
+
.filter((t) => t[0] === "t" && t[1])
|
|
6
|
+
.find((t) => stripInvisibleChar(t[1].toLowerCase()) === hashtag);
|
|
7
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
package/dist/helpers/string.d.ts
CHANGED
package/dist/helpers/string.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const convertToUrl: (url: string | URL) => URL;
|
|
2
|
+
export declare const getURLFilename: (url: URL) => string | undefined;
|
|
3
|
+
export declare const IMAGE_EXT: string[];
|
|
4
|
+
export declare const VIDEO_EXT: string[];
|
|
5
|
+
export declare const STREAM_EXT: string[];
|
|
6
|
+
export declare const AUDIO_EXT: string[];
|
|
7
|
+
export declare function isVisualMediaURL(url: string | URL): boolean;
|
|
8
|
+
export declare function isImageURL(url: string | URL): boolean;
|
|
9
|
+
export declare function isVideoURL(url: string | URL): boolean;
|
|
10
|
+
export declare function isStreamURL(url: string | URL): boolean;
|
|
11
|
+
export declare function isAudioURL(url: string | URL): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const convertToUrl = (url) => (url instanceof URL ? url : new URL(url));
|
|
2
|
+
export const getURLFilename = (url) => url.pathname.split("/").pop()?.toLocaleLowerCase() || url.searchParams.get("filename")?.toLocaleLowerCase();
|
|
3
|
+
export const IMAGE_EXT = [".svg", ".gif", ".png", ".jpg", ".jpeg", ".webp", ".avif"];
|
|
4
|
+
export const VIDEO_EXT = [".mp4", ".mkv", ".webm", ".mov"];
|
|
5
|
+
export const STREAM_EXT = [".m3u8"];
|
|
6
|
+
export const AUDIO_EXT = [".mp3", ".wav", ".ogg", ".aac"];
|
|
7
|
+
export function isVisualMediaURL(url) {
|
|
8
|
+
return isImageURL(url) || isVideoURL(url) || isStreamURL(url);
|
|
9
|
+
}
|
|
10
|
+
export function isImageURL(url) {
|
|
11
|
+
url = convertToUrl(url);
|
|
12
|
+
const filename = getURLFilename(url);
|
|
13
|
+
return !!filename && IMAGE_EXT.some((ext) => filename.endsWith(ext));
|
|
14
|
+
}
|
|
15
|
+
export function isVideoURL(url) {
|
|
16
|
+
url = convertToUrl(url);
|
|
17
|
+
const filename = getURLFilename(url);
|
|
18
|
+
return !!filename && VIDEO_EXT.some((ext) => filename.endsWith(ext));
|
|
19
|
+
}
|
|
20
|
+
export function isStreamURL(url) {
|
|
21
|
+
url = convertToUrl(url);
|
|
22
|
+
const filename = getURLFilename(url);
|
|
23
|
+
return !!filename && STREAM_EXT.some((ext) => filename.endsWith(ext));
|
|
24
|
+
}
|
|
25
|
+
export function isAudioURL(url) {
|
|
26
|
+
url = convertToUrl(url);
|
|
27
|
+
const filename = getURLFilename(url);
|
|
28
|
+
return !!filename && AUDIO_EXT.some((ext) => filename.endsWith(ext));
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isStateful } from "./stateful.js";
|
|
2
|
+
export function getValue(observable) {
|
|
3
|
+
if (isStateful(observable) && observable.value !== undefined)
|
|
4
|
+
return observable.value;
|
|
5
|
+
return new Promise((res) => {
|
|
6
|
+
const sub = observable.subscribe((v) => {
|
|
7
|
+
res(v);
|
|
8
|
+
sub.unsubscribe();
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
}
|
package/dist/observable/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Observable from "zen-observable";
|
|
2
2
|
import { Filter, NostrEvent } from "nostr-tools";
|
|
3
3
|
import { EventStore } from "../event-store/event-store.js";
|
|
4
|
-
import {
|
|
4
|
+
import { StatefulObservable } from "../observable/stateful.js";
|
|
5
|
+
import { LRU } from "../helpers/lru.js";
|
|
5
6
|
import * as Queries from "../queries/index.js";
|
|
6
7
|
import { AddressPointer, EventPointer } from "nostr-tools/nip19";
|
|
7
8
|
export type Query<T extends unknown> = {
|
|
@@ -13,7 +14,7 @@ export declare class QueryStore {
|
|
|
13
14
|
static Queries: typeof Queries;
|
|
14
15
|
store: EventStore;
|
|
15
16
|
constructor(store: EventStore);
|
|
16
|
-
queries: LRU<
|
|
17
|
+
queries: LRU<StatefulObservable<any>>;
|
|
17
18
|
/** Creates a cached query */
|
|
18
19
|
runQuery<T extends unknown, Args extends Array<any>>(queryConstructor: (...args: Args) => {
|
|
19
20
|
key: string;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|