applesauce-common 0.0.0-next-20251209200210 → 0.0.0-next-20251220152312
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/blueprints/__register__.d.ts +6 -0
- package/dist/blueprints/__register__.js +7 -0
- package/dist/blueprints/group-mangement.d.ts +25 -0
- package/dist/blueprints/group-mangement.js +40 -0
- package/dist/blueprints/index.d.ts +1 -0
- package/dist/blueprints/index.js +1 -0
- package/dist/casts/article.d.ts +17 -0
- package/dist/casts/article.js +41 -0
- package/dist/casts/bookmarks.d.ts +35 -0
- package/dist/casts/bookmarks.js +79 -0
- package/dist/casts/cast.d.ts +30 -0
- package/dist/casts/cast.js +67 -0
- package/dist/casts/comment.d.ts +16 -0
- package/dist/casts/comment.js +49 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/mutes.d.ts +23 -0
- package/dist/casts/mutes.js +54 -0
- package/dist/casts/note.d.ts +17 -0
- package/dist/casts/note.js +46 -0
- package/dist/casts/profile.d.ts +16 -0
- package/dist/casts/profile.js +40 -0
- package/dist/casts/relay-lists.d.ts +33 -0
- package/dist/casts/relay-lists.js +72 -0
- package/dist/casts/share.d.ts +13 -0
- package/dist/casts/share.js +28 -0
- package/dist/casts/stream.d.ts +43 -0
- package/dist/casts/stream.js +116 -0
- package/dist/casts/user.d.ts +38 -0
- package/dist/casts/user.js +169 -0
- package/dist/casts/zap.d.ts +17 -0
- package/dist/casts/zap.js +47 -0
- package/dist/helpers/bookmark.d.ts +18 -17
- package/dist/helpers/bookmark.js +36 -49
- package/dist/helpers/encrypted-content-cache.js +23 -25
- package/dist/helpers/gift-wrap.js +11 -5
- package/dist/helpers/groups.d.ts +118 -6
- package/dist/helpers/groups.js +287 -10
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/lists.d.ts +0 -1
- package/dist/helpers/lists.js +4 -5
- package/dist/helpers/mute.d.ts +14 -11
- package/dist/helpers/mute.js +9 -4
- package/dist/helpers/relay-list.d.ts +14 -0
- package/dist/helpers/relay-list.js +18 -0
- package/dist/helpers/stream-chat.d.ts +4 -1
- package/dist/helpers/stream-chat.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/__register__.d.ts +5 -0
- package/dist/models/__register__.js +6 -0
- package/dist/models/bookmarks.d.ts +3 -5
- package/dist/models/bookmarks.js +2 -10
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.js +4 -1
- package/dist/models/mutes.d.ts +5 -5
- package/dist/models/{relays.js → relay-lists.js} +2 -1
- package/dist/models/shares.d.ts +3 -0
- package/dist/models/shares.js +5 -0
- package/dist/models/thread.js +30 -24
- package/dist/observable/cast-stream.d.ts +8 -0
- package/dist/observable/cast-stream.js +29 -0
- package/dist/observable/chainable.d.ts +50 -0
- package/dist/observable/chainable.js +79 -0
- package/dist/observable/index.d.ts +2 -0
- package/dist/observable/index.js +2 -0
- package/dist/operations/group.d.ts +14 -1
- package/dist/operations/group.js +42 -4
- package/dist/operations/index.d.ts +1 -1
- package/dist/operations/index.js +1 -1
- package/dist/operations/tag/bookmarks.d.ts +3 -2
- package/dist/operations/tag/bookmarks.js +34 -14
- package/dist/register.d.ts +2 -11
- package/dist/register.js +2 -11
- package/package.json +12 -2
- package/dist/helpers/mailboxes.d.ts +0 -7
- package/dist/helpers/mailboxes.js +0 -49
- /package/dist/models/{relays.d.ts → relay-lists.d.ts} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { kinds } from "applesauce-core/helpers/event";
|
|
2
2
|
import { watchEventUpdates } from "applesauce-core/observable";
|
|
3
3
|
import { identity, map } from "rxjs";
|
|
4
|
-
import {
|
|
4
|
+
import { getAddressPointersFromList, getRelaysFromList } from "../helpers/lists.js";
|
|
5
|
+
import { FAVORITE_RELAYS_KIND } from "../helpers/relay-list.js";
|
|
5
6
|
/**
|
|
6
7
|
* A model that returns all favorite relays for a pubkey
|
|
7
8
|
* @param pubkey - The pubkey to get the favorite relays for
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
2
|
+
import { buildCommonEventRelationFilters } from "applesauce-core/helpers/model";
|
|
3
|
+
export function SharesModel(event) {
|
|
4
|
+
return (events) => events.timeline(buildCommonEventRelationFilters({ kinds: [kinds.Repost, kinds.GenericRepost] }, event));
|
|
5
|
+
}
|
package/dist/models/thread.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { createReplaceableAddress, getEventUID, isEvent, kinds } from "applesauce-core/helpers/event";
|
|
2
|
-
import { getTagValue } from "applesauce-core/helpers/event";
|
|
3
|
-
import { getReplaceableAddressFromPointer, isAddressPointer, isEventPointer, } from "applesauce-core/helpers/pointers";
|
|
4
|
-
import { isAddressableKind } from "applesauce-core/helpers/event";
|
|
5
|
-
import { map } from "rxjs/operators";
|
|
6
|
-
import { COMMENT_KIND } from "../helpers/comment.js";
|
|
7
|
-
import { getNip10References, interpretThreadTags } from "../helpers/threading.js";
|
|
8
|
-
// Import EventModels as a value (class) to modify its prototype
|
|
9
1
|
import { EventModels } from "applesauce-core/event-store";
|
|
2
|
+
import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
|
|
3
|
+
import { getEventUID, kinds } from "applesauce-core/helpers/event";
|
|
4
|
+
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, } from "applesauce-core/helpers/pointers";
|
|
5
|
+
import { map } from "rxjs/operators";
|
|
6
|
+
import { COMMENT_KIND, getCommentReplyPointer } from "../helpers/comment.js";
|
|
7
|
+
import { getNip10References } from "../helpers/threading.js";
|
|
10
8
|
const defaultOptions = {
|
|
11
9
|
kinds: [kinds.ShortTextNote],
|
|
12
10
|
};
|
|
@@ -69,22 +67,30 @@ export function ThreadModel(root, opts) {
|
|
|
69
67
|
/** A model that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
70
68
|
export function RepliesModel(event, overrideKinds) {
|
|
71
69
|
return (events) => {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
const filter = { kinds: overrideKinds || event.kind === 1 ? [1, COMMENT_KIND] : [COMMENT_KIND] };
|
|
71
|
+
return events.timeline(buildCommonEventRelationFilters(filter, event)).pipe(map((events) =>
|
|
72
|
+
// Filter for direct replies
|
|
73
|
+
events.filter((reply) => {
|
|
74
|
+
if (reply.kind === kinds.ShortTextNote) {
|
|
75
|
+
// Check if a NIP-10 reply is a direct reply to this event
|
|
76
|
+
const refs = getNip10References(reply);
|
|
77
|
+
const pointer = refs.reply?.a || refs.reply?.e;
|
|
78
|
+
if (!pointer)
|
|
79
|
+
return false;
|
|
80
|
+
return eventMatchesPointer(event, pointer);
|
|
81
|
+
}
|
|
82
|
+
else if (reply.kind === COMMENT_KIND) {
|
|
83
|
+
// Check if a NIP-22 reply is a direct reply to this event
|
|
84
|
+
const pointer = getCommentReplyPointer(reply);
|
|
85
|
+
if (!pointer)
|
|
86
|
+
return false;
|
|
87
|
+
if (pointer.type === "address")
|
|
88
|
+
return eventMatchesPointer(event, pointer);
|
|
89
|
+
else if (pointer.type === "event")
|
|
90
|
+
return pointer.id === event.id;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
})));
|
|
88
94
|
};
|
|
89
95
|
}
|
|
90
96
|
// Register this model with EventModels
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { OperatorFunction } from "rxjs";
|
|
3
|
+
import type { CastConstructor, CastRefEventStore } from "../casts/cast.js";
|
|
4
|
+
import { EventCast } from "../casts/cast.js";
|
|
5
|
+
/** Casts an event to a specific type */
|
|
6
|
+
export declare function castEventStream<C extends EventCast>(cls: CastConstructor<C>, store?: CastRefEventStore): OperatorFunction<NostrEvent | undefined, C | undefined>;
|
|
7
|
+
/** Casts and array of events to an array of casted events and filters out undefined values */
|
|
8
|
+
export declare function castTimelineStream<C extends EventCast>(cls: CastConstructor<C>, store?: CastRefEventStore): OperatorFunction<NostrEvent[], C[]>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defined } from "applesauce-core/observable/defined";
|
|
2
|
+
import { map } from "rxjs";
|
|
3
|
+
import { castEvent } from "../casts/cast.js";
|
|
4
|
+
/** Casts an event to a specific type */
|
|
5
|
+
export function castEventStream(cls, store) {
|
|
6
|
+
return (source) => source.pipe(map((event) => {
|
|
7
|
+
if (!event)
|
|
8
|
+
return undefined;
|
|
9
|
+
try {
|
|
10
|
+
return castEvent(event, cls, store);
|
|
11
|
+
}
|
|
12
|
+
catch { }
|
|
13
|
+
return undefined;
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
/** Casts and array of events to an array of casted events and filters out undefined values */
|
|
17
|
+
export function castTimelineStream(cls, store) {
|
|
18
|
+
return (source) => source.pipe(map((events) => {
|
|
19
|
+
const castedEvents = [];
|
|
20
|
+
for (const event of events) {
|
|
21
|
+
try {
|
|
22
|
+
const casted = castEvent(event, cls, store);
|
|
23
|
+
castedEvents.push(casted);
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
}
|
|
27
|
+
return castedEvents;
|
|
28
|
+
}), defined());
|
|
29
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps an Observable in a Proxy that enables property chaining.
|
|
4
|
+
* When accessing a property ending with `$`, it uses switchMap to chain
|
|
5
|
+
* to that property's observable value.
|
|
6
|
+
* When accessing a non-observable property, it returns an Observable of that property's value.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const author$ = chainable(note.author$);
|
|
11
|
+
* const outboxes$ = author$.outboxes$; // Observable<string[] | undefined>
|
|
12
|
+
* const displayName$ = author$.displayName; // Observable<string | undefined>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function chainable<T>(observable: Observable<T>): ChainableObservable<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Helper type to extract nullable parts (undefined/null) from a type
|
|
18
|
+
*/
|
|
19
|
+
type NullableParts<T> = Extract<T, undefined | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Helper type to get the property type, preserving nullable parts from the parent type
|
|
22
|
+
*/
|
|
23
|
+
type PropChain<T, K extends keyof NonNullable<T>> = NonNullable<T>[K] | NullableParts<T>;
|
|
24
|
+
/**
|
|
25
|
+
* A chainable Observable type that allows property chaining.
|
|
26
|
+
* This type maps all properties to chainable observables:
|
|
27
|
+
* - Properties ending with $: extracts inner type from Observable<U> → ChainableObservable<U>
|
|
28
|
+
* - Other properties: uses property type directly → ChainableObservable<PropertyType>
|
|
29
|
+
*
|
|
30
|
+
* Note: TypeScript has limitations inferring through Proxy types. For better
|
|
31
|
+
* type inference, you may need to explicitly type the result:
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const inboxes$: Observable<string[] | undefined> = note?.author$.inboxes$;
|
|
36
|
+
* const displayName$: Observable<string | undefined> = note?.author$.displayName;
|
|
37
|
+
* const inboxes = useObservableMemo(() => inboxes$, [note]);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type ChainableObservable<T> = Observable<T> & Omit<{
|
|
41
|
+
[K in keyof NonNullable<T> as K extends string ? K : never]: K extends `${infer _}$` ? NonNullable<T>[K] extends Observable<infer U> ? ChainableObservable<U | NullableParts<T>> : never : ChainableObservable<PropChain<T, K>>;
|
|
42
|
+
}, "$first" | "$last"> & {
|
|
43
|
+
/** Returns a promise that resolves with the first value or rejects with a timeout error */
|
|
44
|
+
$first(first?: number): Promise<NonNullable<T>>;
|
|
45
|
+
$first<V>(first?: number, fallback?: V): Promise<NonNullable<T> | V>;
|
|
46
|
+
/** Returns a promise that resolves with the last value or rejects with a timeout error */
|
|
47
|
+
$last(max?: number): Promise<NonNullable<T>>;
|
|
48
|
+
$last<V>(max?: number, fallback?: V): Promise<NonNullable<T> | V>;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { filter, firstValueFrom, isObservable, lastValueFrom, map, of, switchMap, timeout } from "rxjs";
|
|
2
|
+
/**
|
|
3
|
+
* A symbol used to mark an Observable as chainable
|
|
4
|
+
*/
|
|
5
|
+
const CHAINABLE_CACHE_SYMBOL = Symbol.for("chainable-cache");
|
|
6
|
+
/**
|
|
7
|
+
* Wraps an Observable in a Proxy that enables property chaining.
|
|
8
|
+
* When accessing a property ending with `$`, it uses switchMap to chain
|
|
9
|
+
* to that property's observable value.
|
|
10
|
+
* When accessing a non-observable property, it returns an Observable of that property's value.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const author$ = chainable(note.author$);
|
|
15
|
+
* const outboxes$ = author$.outboxes$; // Observable<string[] | undefined>
|
|
16
|
+
* const displayName$ = author$.displayName; // Observable<string | undefined>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function chainable(observable) {
|
|
20
|
+
// Create a Proxy that intercepts property access
|
|
21
|
+
const proxy = new Proxy(observable, {
|
|
22
|
+
get(target$, prop) {
|
|
23
|
+
const cache = observable[CHAINABLE_CACHE_SYMBOL] ||
|
|
24
|
+
(observable[CHAINABLE_CACHE_SYMBOL] = {});
|
|
25
|
+
// Forward all Observable methods and properties
|
|
26
|
+
if (prop in target$ || typeof prop === "symbol") {
|
|
27
|
+
const value = target$[prop];
|
|
28
|
+
// If it's a function, bind it to the target
|
|
29
|
+
if (typeof value === "function")
|
|
30
|
+
return value.bind(target$);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
if (typeof prop === "string") {
|
|
34
|
+
// Return cached observable if it exists
|
|
35
|
+
const cached = cache[prop];
|
|
36
|
+
if (cached)
|
|
37
|
+
return cached;
|
|
38
|
+
// Otherwise, create a new observable
|
|
39
|
+
let prop$;
|
|
40
|
+
// Extra observalbe helpers to make it easier to work with observables
|
|
41
|
+
if (prop === "$first") {
|
|
42
|
+
return (...args) => firstValueFrom(target$.pipe(filter((v) => v !== undefined && v !== null), args.length === 2
|
|
43
|
+
? timeout({ first: args[0], with: () => of(args[1]) })
|
|
44
|
+
: timeout({ first: args[0] ?? 10_000 })));
|
|
45
|
+
}
|
|
46
|
+
else if (prop === "$last") {
|
|
47
|
+
return (...args) => lastValueFrom(target$.pipe(filter((v) => v !== undefined && v !== null), args.length === 2
|
|
48
|
+
? timeout({ first: args[0], with: () => of(args[1]) })
|
|
49
|
+
: timeout({ first: args[0] ?? 10_000 })));
|
|
50
|
+
}
|
|
51
|
+
// Handle property access for properties ending with $
|
|
52
|
+
else if (prop.endsWith("$")) {
|
|
53
|
+
// Use switchMap to chain to the nested observable
|
|
54
|
+
prop$ = target$.pipe(switchMap((target) => {
|
|
55
|
+
const value = target === undefined || target === null ? target : target[prop];
|
|
56
|
+
// If value is an observable, return it
|
|
57
|
+
if (isObservable(value))
|
|
58
|
+
return value;
|
|
59
|
+
// Otherwise wrap it in an observable
|
|
60
|
+
else
|
|
61
|
+
return of(value);
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
// For non-$ properties, return an Observable of the property value
|
|
65
|
+
else {
|
|
66
|
+
prop$ = target$.pipe(
|
|
67
|
+
// Access the property on the value if target is not undefined or null
|
|
68
|
+
map((target) => (target === undefined || target === null ? target : target[prop])));
|
|
69
|
+
}
|
|
70
|
+
// Make the chained observable chainable too
|
|
71
|
+
const observable = chainable(prop$);
|
|
72
|
+
cache[prop] = observable;
|
|
73
|
+
return observable;
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`Unable to access property "${prop}" on chainable observable`);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return proxy;
|
|
79
|
+
}
|
package/dist/observable/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventOperation } from "applesauce-core/event-factory";
|
|
2
|
+
import { EventPointer, ProfilePointer } from "applesauce-core/helpers";
|
|
2
3
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
-
import { GroupPointer } from "../helpers/groups.js";
|
|
4
|
+
import { GroupMetadata, GroupPointer } from "../helpers/groups.js";
|
|
4
5
|
/** Adds a "group" tag to a list */
|
|
5
6
|
export declare function addGroupTag(group: GroupPointer): EventOperation;
|
|
6
7
|
/** Removes a "group" tag from a list */
|
|
@@ -9,3 +10,15 @@ export declare function removeGroupTag(group: GroupPointer): EventOperation;
|
|
|
9
10
|
export declare function setGroupPointer(group: GroupPointer): EventOperation;
|
|
10
11
|
/** Adds "previous" tags for group messages */
|
|
11
12
|
export declare function addPreviousRefs(previous: NostrEvent[], count?: number): EventOperation;
|
|
13
|
+
/** Sets tags for a join request (kind 9021) */
|
|
14
|
+
export declare function setJoinRequestTags(group: GroupPointer, inviteCode?: string): EventOperation;
|
|
15
|
+
/** Sets tags for a leave request (kind 9022) */
|
|
16
|
+
export declare function setLeaveRequestTags(group: GroupPointer): EventOperation;
|
|
17
|
+
/** Sets tags for put user (kind 9000) */
|
|
18
|
+
export declare function setPutUserTags(user: string | ProfilePointer, roles?: string[]): EventOperation;
|
|
19
|
+
/** Sets tags for remove user (kind 9001) */
|
|
20
|
+
export declare function setRemoveUserTags(user: string | ProfilePointer): EventOperation;
|
|
21
|
+
/** Sets tags for edit metadata (kind 9002) */
|
|
22
|
+
export declare function setEditMetadataTags(fields: Partial<GroupMetadata>): EventOperation;
|
|
23
|
+
/** Sets tags for delete event (kind 9005) */
|
|
24
|
+
export declare function setDeleteEventTags(event: string | EventPointer | NostrEvent): EventOperation;
|
package/dist/operations/group.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { ensureNamedValueTag } from "applesauce-core/helpers";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ensureNamedValueTag, ensureWebSocketURL, fillAndTrimTag, } from "applesauce-core/helpers";
|
|
2
|
+
import { addEventPointerTag, addNameValueTag, addProfilePointerTag, setSingletonTag, } from "applesauce-core/operations/tag/common";
|
|
3
|
+
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
4
|
+
/** Creates a "h" tag for chat messages from a {@link GroupPointer} */
|
|
5
|
+
function createGroupHTagFromGroupPointer(group) {
|
|
6
|
+
return fillAndTrimTag(["h", group.id, ensureWebSocketURL(group.relay)]);
|
|
7
|
+
}
|
|
8
|
+
/** Creates a "group" tag from a {@link GroupPointer} */
|
|
9
|
+
function createGroupTagFromGroupPointer(group) {
|
|
10
|
+
return fillAndTrimTag(["group", group.id, ensureWebSocketURL(group.relay), group.name], 3);
|
|
11
|
+
}
|
|
12
|
+
/** A tag operation for setting the "h" tag for a group */
|
|
13
|
+
function setGroupHTag(group) {
|
|
14
|
+
return setSingletonTag(createGroupHTagFromGroupPointer(group));
|
|
15
|
+
}
|
|
4
16
|
/** Adds a "group" tag to a list */
|
|
5
17
|
export function addGroupTag(group) {
|
|
6
18
|
return modifyPublicTags((tags) => {
|
|
@@ -15,7 +27,7 @@ export function removeGroupTag(group) {
|
|
|
15
27
|
}
|
|
16
28
|
/** Sets the "h" tag for NIP-29 group messages or other events */
|
|
17
29
|
export function setGroupPointer(group) {
|
|
18
|
-
return
|
|
30
|
+
return modifyPublicTags(setGroupHTag(group));
|
|
19
31
|
}
|
|
20
32
|
/** Adds "previous" tags for group messages */
|
|
21
33
|
export function addPreviousRefs(previous, count = 6) {
|
|
@@ -32,3 +44,29 @@ export function addPreviousRefs(previous, count = 6) {
|
|
|
32
44
|
return { ...draft, tags };
|
|
33
45
|
};
|
|
34
46
|
}
|
|
47
|
+
/** Sets tags for a join request (kind 9021) */
|
|
48
|
+
export function setJoinRequestTags(group, inviteCode) {
|
|
49
|
+
return modifyPublicTags(setGroupHTag(group), inviteCode ? addNameValueTag(["code", inviteCode]) : undefined);
|
|
50
|
+
}
|
|
51
|
+
/** Sets tags for a leave request (kind 9022) */
|
|
52
|
+
export function setLeaveRequestTags(group) {
|
|
53
|
+
return modifyPublicTags(setGroupHTag(group));
|
|
54
|
+
}
|
|
55
|
+
/** Sets tags for put user (kind 9000) */
|
|
56
|
+
export function setPutUserTags(user, roles) {
|
|
57
|
+
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
58
|
+
const tag = roles && roles.length > 0 ? ["p", pubkey, ...roles] : ["p", pubkey];
|
|
59
|
+
return modifyPublicTags(addNameValueTag(tag));
|
|
60
|
+
}
|
|
61
|
+
/** Sets tags for remove user (kind 9001) */
|
|
62
|
+
export function setRemoveUserTags(user) {
|
|
63
|
+
return modifyPublicTags(addProfilePointerTag(user));
|
|
64
|
+
}
|
|
65
|
+
/** Sets tags for edit metadata (kind 9002) */
|
|
66
|
+
export function setEditMetadataTags(fields) {
|
|
67
|
+
return modifyPublicTags(fields.name !== undefined ? setSingletonTag(["name", fields.name]) : undefined, fields.picture !== undefined ? setSingletonTag(["picture", fields.picture]) : undefined, fields.about !== undefined ? setSingletonTag(["about", fields.about]) : undefined, fields.isPublic ? setSingletonTag(["public"]) : undefined, fields.isPrivate ? setSingletonTag(["private"]) : undefined, fields.isOpen ? setSingletonTag(["open"]) : undefined, fields.isClosed ? setSingletonTag(["closed"]) : undefined);
|
|
68
|
+
}
|
|
69
|
+
/** Sets tags for delete event (kind 9005) */
|
|
70
|
+
export function setDeleteEventTags(event) {
|
|
71
|
+
return modifyPublicTags(addEventPointerTag(event));
|
|
72
|
+
}
|
|
@@ -8,7 +8,7 @@ export * as Comment from "./comment.js";
|
|
|
8
8
|
export * as FileMetadata from "./file-metadata.js";
|
|
9
9
|
export * as Geohash from "./geohash.js";
|
|
10
10
|
export * as GiftWrap from "./gift-wrap.js";
|
|
11
|
-
export * as
|
|
11
|
+
export * as Group from "./group.js";
|
|
12
12
|
export * as Hashtags from "./hashtags.js";
|
|
13
13
|
export * as Highlight from "./highlight.js";
|
|
14
14
|
export * as LegacyMessage from "./legacy-message.js";
|
package/dist/operations/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export * as Comment from "./comment.js";
|
|
|
8
8
|
export * as FileMetadata from "./file-metadata.js";
|
|
9
9
|
export * as Geohash from "./geohash.js";
|
|
10
10
|
export * as GiftWrap from "./gift-wrap.js";
|
|
11
|
-
export * as
|
|
11
|
+
export * as Group from "./group.js";
|
|
12
12
|
export * as Hashtags from "./hashtags.js";
|
|
13
13
|
export * as Highlight from "./highlight.js";
|
|
14
14
|
export * as LegacyMessage from "./legacy-message.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TagOperation } from "applesauce-core/event-factory";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
3
4
|
/** Adds an "e" or "a" tag to a bookmark list or set */
|
|
4
|
-
export declare function addEventBookmarkTag(event: NostrEvent): TagOperation;
|
|
5
|
+
export declare function addEventBookmarkTag(event: NostrEvent | EventPointer | AddressPointer): TagOperation;
|
|
5
6
|
/** Removes an "e" or "a" tag from a bookmark list or set */
|
|
6
|
-
export declare function removeEventBookmarkTag(event: NostrEvent): TagOperation;
|
|
7
|
+
export declare function removeEventBookmarkTag(event: NostrEvent | EventPointer | AddressPointer): TagOperation;
|
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { getAddressPointerForEvent } from "applesauce-core/helpers/pointers";
|
|
1
|
+
import { isEvent, isReplaceable, kinds } from "applesauce-core/helpers/event";
|
|
2
|
+
import { isAddressPointer, isEventPointer } from "applesauce-core/helpers/pointers";
|
|
4
3
|
import { addAddressPointerTag, addEventPointerTag, removeAddressPointerTag, removeEventPointerTag, } from "applesauce-core/operations/tag/common";
|
|
5
4
|
/** Adds an "e" or "a" tag to a bookmark list or set */
|
|
6
5
|
export function addEventBookmarkTag(event) {
|
|
7
|
-
|
|
6
|
+
// Validate event kind if event or address pointer
|
|
7
|
+
if ((isEvent(event) || isAddressPointer(event)) &&
|
|
8
|
+
event.kind !== kinds.ShortTextNote &&
|
|
9
|
+
event.kind !== kinds.LongFormArticle)
|
|
8
10
|
throw new Error(`Event kind (${event.kind}) cant not be added to bookmarks`);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
if (isEvent(event)) {
|
|
12
|
+
// Add "a" tag for replaceable articles
|
|
13
|
+
if (isReplaceable(event.kind))
|
|
14
|
+
return addAddressPointerTag(event);
|
|
15
|
+
// Add "e" tag for non-replaceable notes
|
|
16
|
+
else
|
|
17
|
+
return addEventPointerTag(event);
|
|
18
|
+
}
|
|
19
|
+
// "e" tags for note event pointers
|
|
20
|
+
else if (isEventPointer(event))
|
|
21
|
+
return addEventPointerTag(event);
|
|
22
|
+
// "a" tags for address pointers
|
|
23
|
+
else
|
|
24
|
+
return addAddressPointerTag(event);
|
|
11
25
|
}
|
|
12
26
|
/** Removes an "e" or "a" tag from a bookmark list or set */
|
|
13
27
|
export function removeEventBookmarkTag(event) {
|
|
14
|
-
if (event
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
if (isEvent(event)) {
|
|
29
|
+
// Remove "a" tag for replaceable articles
|
|
30
|
+
if (isReplaceable(event.kind))
|
|
31
|
+
return removeAddressPointerTag(event);
|
|
32
|
+
// Remove "e" tag for non-replaceable notes
|
|
33
|
+
else
|
|
34
|
+
return removeEventPointerTag(event);
|
|
35
|
+
}
|
|
36
|
+
// "e" tags for note event pointers
|
|
37
|
+
else if (isEventPointer(event))
|
|
38
|
+
return removeEventPointerTag(event);
|
|
39
|
+
// "a" tags for address pointers
|
|
40
|
+
else
|
|
41
|
+
return removeAddressPointerTag(event);
|
|
22
42
|
}
|
package/dist/register.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
import "./models/
|
|
2
|
-
import "./
|
|
3
|
-
import "./models/reactions.js";
|
|
4
|
-
import "./models/comments.js";
|
|
5
|
-
import "./models/thread.js";
|
|
6
|
-
import "./blueprints/comment.js";
|
|
7
|
-
import "./blueprints/delete.js";
|
|
8
|
-
import "./blueprints/note.js";
|
|
9
|
-
import "./blueprints/reaction.js";
|
|
10
|
-
import "./blueprints/share.js";
|
|
11
|
-
import "./blueprints/poll.js";
|
|
1
|
+
import "./models/__register__.js";
|
|
2
|
+
import "./blueprints/__register__.js";
|
package/dist/register.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
// Import models that should register with the event store
|
|
2
|
-
import "./models/
|
|
3
|
-
import "./models/mutes.js";
|
|
4
|
-
import "./models/reactions.js";
|
|
5
|
-
import "./models/comments.js";
|
|
6
|
-
import "./models/thread.js";
|
|
2
|
+
import "./models/__register__.js";
|
|
7
3
|
// Import blueprints that should register with the event factory
|
|
8
|
-
import "./blueprints/
|
|
9
|
-
import "./blueprints/delete.js";
|
|
10
|
-
import "./blueprints/note.js";
|
|
11
|
-
import "./blueprints/reaction.js";
|
|
12
|
-
import "./blueprints/share.js";
|
|
13
|
-
import "./blueprints/poll.js";
|
|
4
|
+
import "./blueprints/__register__.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-common",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20251220152312",
|
|
4
4
|
"description": "Common NIP-specific helpers and models for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -69,11 +69,21 @@
|
|
|
69
69
|
"import": "./dist/observable/*.js",
|
|
70
70
|
"require": "./dist/observable/*.js",
|
|
71
71
|
"types": "./dist/observable/*.d.ts"
|
|
72
|
+
},
|
|
73
|
+
"./casts": {
|
|
74
|
+
"import": "./dist/casts/index.js",
|
|
75
|
+
"require": "./dist/casts/index.js",
|
|
76
|
+
"types": "./dist/casts/index.d.ts"
|
|
77
|
+
},
|
|
78
|
+
"./casts/*": {
|
|
79
|
+
"import": "./dist/casts/*.js",
|
|
80
|
+
"require": "./dist/casts/*.js",
|
|
81
|
+
"types": "./dist/casts/*.d.ts"
|
|
72
82
|
}
|
|
73
83
|
},
|
|
74
84
|
"dependencies": {
|
|
75
85
|
"@scure/base": "^1.2.4",
|
|
76
|
-
"applesauce-core": "0.0.0-next-
|
|
86
|
+
"applesauce-core": "0.0.0-next-20251220152312",
|
|
77
87
|
"hash-sum": "^2.0.0",
|
|
78
88
|
"light-bolt11-decoder": "^3.2.0",
|
|
79
89
|
"rxjs": "^7.8.1"
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
-
export declare const MailboxesInboxesSymbol: unique symbol;
|
|
3
|
-
export declare const MailboxesOutboxesSymbol: unique symbol;
|
|
4
|
-
/** Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol */
|
|
5
|
-
export declare function getInboxes(event: NostrEvent): string[];
|
|
6
|
-
/** Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol */
|
|
7
|
-
export declare function getOutboxes(event: NostrEvent): string[];
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
-
import { isSafeRelayURL } from "applesauce-core/helpers/relays";
|
|
3
|
-
import { isRTag } from "applesauce-core/helpers/tags";
|
|
4
|
-
import { normalizeURL } from "applesauce-core/helpers/url";
|
|
5
|
-
export const MailboxesInboxesSymbol = Symbol.for("mailboxes-inboxes");
|
|
6
|
-
export const MailboxesOutboxesSymbol = Symbol.for("mailboxes-outboxes");
|
|
7
|
-
/** Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol */
|
|
8
|
-
export function getInboxes(event) {
|
|
9
|
-
return getOrComputeCachedValue(event, MailboxesInboxesSymbol, () => {
|
|
10
|
-
const inboxes = [];
|
|
11
|
-
for (const tag of event.tags) {
|
|
12
|
-
if (!isRTag(tag))
|
|
13
|
-
continue;
|
|
14
|
-
try {
|
|
15
|
-
const [, url, mode] = tag;
|
|
16
|
-
if (url && isSafeRelayURL(url) && !inboxes.includes(url) && (mode === "read" || mode === undefined)) {
|
|
17
|
-
inboxes.push(normalizeURL(url));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// Ignore invalid url tags
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return inboxes;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/** Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol */
|
|
28
|
-
export function getOutboxes(event) {
|
|
29
|
-
return getOrComputeCachedValue(event, MailboxesOutboxesSymbol, () => {
|
|
30
|
-
const outboxes = [];
|
|
31
|
-
for (const tag of event.tags) {
|
|
32
|
-
if (!isRTag(tag))
|
|
33
|
-
continue;
|
|
34
|
-
try {
|
|
35
|
-
const [name, url, mode] = tag;
|
|
36
|
-
if (name === "r" &&
|
|
37
|
-
isSafeRelayURL(url) &&
|
|
38
|
-
!outboxes.includes(url) &&
|
|
39
|
-
(mode === "write" || mode === undefined)) {
|
|
40
|
-
outboxes.push(normalizeURL(url));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
// Ignore invalid url tags
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return outboxes;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
File without changes
|