applesauce-core 5.1.0 → 6.0.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.
Files changed (80) hide show
  1. package/dist/casts/cast.d.ts +31 -0
  2. package/dist/casts/cast.js +67 -0
  3. package/dist/casts/index.d.ts +3 -0
  4. package/dist/casts/index.js +3 -0
  5. package/dist/casts/pubkey.d.ts +27 -0
  6. package/dist/casts/pubkey.js +49 -0
  7. package/dist/casts/user.d.ts +19 -0
  8. package/dist/casts/user.js +25 -0
  9. package/dist/factories/delete.d.ts +18 -0
  10. package/dist/factories/delete.js +23 -0
  11. package/dist/factories/event.d.ts +61 -0
  12. package/dist/factories/event.js +164 -0
  13. package/dist/factories/index.d.ts +5 -0
  14. package/dist/factories/index.js +5 -0
  15. package/dist/factories/mailboxes.d.ts +33 -0
  16. package/dist/factories/mailboxes.js +57 -0
  17. package/dist/factories/profile.d.ts +46 -0
  18. package/dist/factories/profile.js +80 -0
  19. package/dist/factories/types.d.ts +56 -0
  20. package/dist/helpers/event.d.ts +11 -2
  21. package/dist/helpers/event.js +2 -1
  22. package/dist/helpers/mailboxes.d.ts +5 -1
  23. package/dist/helpers/mailboxes.js +5 -0
  24. package/dist/helpers/pipeline.d.ts +14 -1
  25. package/dist/helpers/pipeline.js +17 -2
  26. package/dist/helpers/pointers.d.ts +25 -21
  27. package/dist/helpers/pointers.js +33 -18
  28. package/dist/helpers/profile.d.ts +2 -2
  29. package/dist/helpers/regexp.d.ts +2 -0
  30. package/dist/helpers/regexp.js +8 -2
  31. package/dist/helpers/relays.d.ts +3 -1
  32. package/dist/helpers/relays.js +8 -10
  33. package/dist/helpers/url.d.ts +1 -4
  34. package/dist/helpers/url.js +1 -4
  35. package/dist/index.d.ts +3 -1
  36. package/dist/index.js +4 -1
  37. package/dist/observable/catch-error-inline.d.ts +3 -0
  38. package/dist/observable/catch-error-inline.js +5 -0
  39. package/dist/observable/chainable.d.ts +36 -0
  40. package/dist/observable/chainable.js +72 -0
  41. package/dist/observable/combine-latest-by-index.d.ts +10 -0
  42. package/dist/observable/combine-latest-by-index.js +121 -0
  43. package/dist/observable/combine-latest-by-key.d.ts +10 -0
  44. package/dist/observable/combine-latest-by-key.js +136 -0
  45. package/dist/observable/combine-latest-by-value.d.ts +10 -0
  46. package/dist/observable/combine-latest-by-value.js +117 -0
  47. package/dist/observable/combine-latest-by.d.ts +16 -0
  48. package/dist/observable/combine-latest-by.js +12 -0
  49. package/dist/observable/index.d.ts +10 -4
  50. package/dist/observable/index.js +10 -4
  51. package/dist/observable/timeout-with-ignore.d.ts +24 -0
  52. package/dist/observable/timeout-with-ignore.js +33 -0
  53. package/dist/operations/client.d.ts +1 -1
  54. package/dist/operations/client.js +2 -2
  55. package/dist/operations/content.d.ts +5 -2
  56. package/dist/operations/content.js +13 -9
  57. package/dist/operations/delete.d.ts +1 -1
  58. package/dist/operations/encrypted-content.d.ts +9 -3
  59. package/dist/operations/encrypted-content.js +9 -3
  60. package/dist/operations/event.d.ts +6 -4
  61. package/dist/operations/event.js +20 -12
  62. package/dist/operations/hidden-content.d.ts +8 -3
  63. package/dist/operations/hidden-content.js +11 -6
  64. package/dist/operations/mailboxes.d.ts +5 -1
  65. package/dist/operations/mailboxes.js +76 -0
  66. package/dist/operations/profile.d.ts +1 -1
  67. package/dist/operations/tag/common.d.ts +22 -7
  68. package/dist/operations/tag/common.js +33 -18
  69. package/dist/operations/tag/relay.d.ts +1 -1
  70. package/dist/operations/tags.d.ts +10 -4
  71. package/dist/operations/tags.js +19 -13
  72. package/package.json +20 -5
  73. package/dist/event-factory/event-factory.d.ts +0 -57
  74. package/dist/event-factory/event-factory.js +0 -94
  75. package/dist/event-factory/index.d.ts +0 -3
  76. package/dist/event-factory/index.js +0 -3
  77. package/dist/event-factory/methods.d.ts +0 -17
  78. package/dist/event-factory/methods.js +0 -44
  79. package/dist/event-factory/types.d.ts +0 -76
  80. /package/dist/{event-factory → factories}/types.js +0 -0
@@ -12,21 +12,23 @@ export function includeNameValueTag(tag, replace = true) {
12
12
  }
13
13
  /** An event operation that modifies the public tags with {@link TagOperation}s */
14
14
  export function modifyPublicTags(...operations) {
15
- return async (draft, ctx) => {
16
- return { ...draft, tags: await tagPipe(...operations)(Array.from(draft.tags), ctx) };
15
+ return async (draft) => {
16
+ return { ...draft, tags: await tagPipe(...operations)(Array.from(draft.tags)) };
17
17
  };
18
18
  }
19
19
  /**
20
20
  * Creates an event operation that modifies the hidden tags on an event with {@link TagOperation}s
21
+ * @param signer - EventSigner for encrypting/decrypting hidden tags
22
+ * @param operations - Tag operations to apply to hidden tags
21
23
  * @throws {Error} if no signer is provided
22
24
  * @throws {Error} if the event kind does not support hidden tags
23
25
  */
24
- export function modifyHiddenTags(...operations) {
26
+ export function modifyHiddenTags(signer, ...operations) {
25
27
  operations = operations.filter((o) => !!o);
26
28
  if (operations.length === 0)
27
29
  return skip();
28
- return async (draft, ctx) => {
29
- if (!ctx.signer)
30
+ return async (draft) => {
31
+ if (!signer)
30
32
  throw new Error("Missing signer for hidden tags");
31
33
  if (!canHaveHiddenTags(draft.kind))
32
34
  throw new Error("Event kind does not support hidden tags");
@@ -41,8 +43,8 @@ export function modifyHiddenTags(...operations) {
41
43
  if (hidden === undefined) {
42
44
  if (hasHiddenTags(draft)) {
43
45
  // draft is an existing event, attempt to unlock tags
44
- pubkey = await ctx.signer.getPublicKey();
45
- hidden = await unlockHiddenTags({ ...draft, pubkey }, ctx.signer);
46
+ pubkey = await signer.getPublicKey();
47
+ hidden = await unlockHiddenTags({ ...draft, pubkey }, signer);
46
48
  }
47
49
  // create a new array of hidden tags
48
50
  else
@@ -56,19 +58,23 @@ export function modifyHiddenTags(...operations) {
56
58
  if (hidden === undefined)
57
59
  throw new Error("Failed to find hidden tags");
58
60
  // Create the new hidden tags
59
- const tags = await tagPipe(...operations)(hidden, ctx);
61
+ const tags = await tagPipe(...operations)(hidden);
60
62
  // Encrypt new hidden tags
61
- const methods = getHiddenTagsEncryptionMethods(draft.kind, ctx.signer);
63
+ const methods = getHiddenTagsEncryptionMethods(draft.kind, signer);
62
64
  if (!pubkey)
63
- pubkey = await ctx.signer.getPublicKey();
65
+ pubkey = await signer.getPublicKey();
64
66
  const plaintext = JSON.stringify(tags);
65
67
  const content = await methods.encrypt(pubkey, plaintext);
66
68
  // add the plaintext content on the draft so it can be carried forward
67
69
  return { ...draft, content, [EncryptedContentSymbol]: plaintext };
68
70
  };
69
71
  }
70
- /** A flexible method for creating an event operation that modifies the tags */
71
- export function modifyTags(tagOperations) {
72
+ /**
73
+ * A flexible method for creating an event operation that modifies the tags
74
+ * @param tagOperations - Tag operations for public and/or hidden tags
75
+ * @param signer - Optional signer (required if modifying hidden tags)
76
+ */
77
+ export function modifyTags(tagOperations, signer) {
72
78
  let publicOperations = [];
73
79
  let hiddenOperations = [];
74
80
  // normalize tag operation arg
@@ -89,5 +95,5 @@ export function modifyTags(tagOperations) {
89
95
  hiddenOperations = tagOperations.hidden;
90
96
  }
91
97
  // return a new event operation that modifies the tags
92
- return eventPipe(publicOperations.length > 0 ? modifyPublicTags(...publicOperations) : undefined, hiddenOperations.length > 0 ? modifyHiddenTags(...hiddenOperations) : undefined);
98
+ return eventPipe(publicOperations.length > 0 ? modifyPublicTags(...publicOperations) : undefined, hiddenOperations.length > 0 ? modifyHiddenTags(signer, ...hiddenOperations) : undefined);
93
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "5.1.0",
3
+ "version": "6.0.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -60,10 +60,15 @@
60
60
  "require": "./dist/event-store/index.js",
61
61
  "types": "./dist/event-store/index.d.ts"
62
62
  },
63
- "./event-factory": {
64
- "import": "./dist/event-factory/index.js",
65
- "require": "./dist/event-factory/index.js",
66
- "types": "./dist/event-factory/index.d.ts"
63
+ "./factories": {
64
+ "import": "./dist/factories/index.js",
65
+ "require": "./dist/factories/index.js",
66
+ "types": "./dist/factories/index.d.ts"
67
+ },
68
+ "./factories/*": {
69
+ "import": "./dist/factories/*.js",
70
+ "require": "./dist/factories/*.js",
71
+ "types": "./dist/factories/*.d.ts"
67
72
  },
68
73
  "./operations": {
69
74
  "import": "./dist/operations/index.js",
@@ -74,6 +79,16 @@
74
79
  "import": "./dist/operations/*.js",
75
80
  "require": "./dist/operations/*.js",
76
81
  "types": "./dist/operations/*.d.ts"
82
+ },
83
+ "./casts": {
84
+ "import": "./dist/casts/index.js",
85
+ "require": "./dist/casts/index.js",
86
+ "types": "./dist/casts/index.d.ts"
87
+ },
88
+ "./casts/*": {
89
+ "import": "./dist/casts/*.js",
90
+ "require": "./dist/casts/*.js",
91
+ "types": "./dist/casts/*.d.ts"
77
92
  }
78
93
  },
79
94
  "dependencies": {
@@ -1,57 +0,0 @@
1
- import { EventTemplate, NostrEvent, UnsignedEvent } from "../helpers/event.js";
2
- import { ModifyTagsOptions } from "../operations/tags.js";
3
- import { EventFactoryTemplate } from "./methods.js";
4
- import { EventBlueprint, EventFactoryContext, EventOperation, IEventFactory } from "./types.js";
5
- /**
6
- * Base class that provides event creation functionality.
7
- * This class can be extended by other packages to add additional helpful event creation methods.
8
- *
9
- * @example
10
- * ```ts
11
- * // In another package (e.g., applesauce-common)
12
- * import { EventFactory } from "applesauce-core/event-factory";
13
- * import { NoteBlueprint, ReactionBlueprint } from "applesauce-common/blueprints";
14
- *
15
- * // Add methods to the prototype
16
- * EventFactory.prototype.note = function(content, options) {
17
- * return this.create(NoteBlueprint, content, options);
18
- * };
19
- *
20
- * EventFactory.prototype.reaction = function(event, emoji) {
21
- * return this.create(ReactionBlueprint, event, emoji);
22
- * };
23
- *
24
- * // Extend the type via module augmentation
25
- * declare module "applesauce-core/event-factory" {
26
- * interface EventFactory {
27
- * note(content: string, options?: NoteBlueprintOptions): Promise<EventTemplate>;
28
- * reaction(event: NostrEvent, emoji?: string): Promise<EventTemplate>;
29
- * }
30
- * }
31
- * ```
32
- */
33
- export declare class EventFactory implements IEventFactory {
34
- context: EventFactoryContext;
35
- constructor(context?: EventFactoryContext);
36
- /** Build an event template with operations */
37
- build(template: EventFactoryTemplate, ...operations: (EventOperation | undefined)[]): Promise<EventTemplate>;
38
- /** Create an event from a blueprint */
39
- create<T extends EventTemplate | UnsignedEvent | NostrEvent>(blueprint: EventBlueprint<T>): Promise<T>;
40
- create<T extends EventTemplate | UnsignedEvent | NostrEvent, Args extends Array<any>>(blueprint: (...args: Args) => EventBlueprint<T>, ...args: Args): Promise<T>;
41
- /** Modify an existing event with operations and updated the created_at */
42
- modify(draft: EventTemplate | UnsignedEvent | NostrEvent, ...operations: (EventOperation | undefined)[]): Promise<EventTemplate>;
43
- /** Modify a lists public and hidden tags and updated the created_at */
44
- modifyTags(event: EventTemplate | UnsignedEvent | NostrEvent, tagOperations?: ModifyTagsOptions, eventOperations?: EventOperation | (EventOperation | undefined)[]): Promise<EventTemplate>;
45
- /** Attaches the signers pubkey to an event template */
46
- stamp(draft: EventTemplate | UnsignedEvent): Promise<UnsignedEvent>;
47
- /** Signs a event template with the signer */
48
- sign(draft: EventTemplate | UnsignedEvent): Promise<NostrEvent>;
49
- /** Sets the signer in the context */
50
- setSigner(signer: EventFactoryContext["signer"]): void;
51
- /** clears the signer in the context */
52
- clearSigner(): void;
53
- /** sets the client in the context */
54
- setClient(client: EventFactoryContext["client"]): void;
55
- /** clears the client in the context */
56
- clearClient(): void;
57
- }
@@ -1,94 +0,0 @@
1
- import { sign, stamp } from "../operations/event.js";
2
- import { modifyTags } from "../operations/tags.js";
3
- import { buildEvent, modifyEvent } from "./methods.js";
4
- /**
5
- * Base class that provides event creation functionality.
6
- * This class can be extended by other packages to add additional helpful event creation methods.
7
- *
8
- * @example
9
- * ```ts
10
- * // In another package (e.g., applesauce-common)
11
- * import { EventFactory } from "applesauce-core/event-factory";
12
- * import { NoteBlueprint, ReactionBlueprint } from "applesauce-common/blueprints";
13
- *
14
- * // Add methods to the prototype
15
- * EventFactory.prototype.note = function(content, options) {
16
- * return this.create(NoteBlueprint, content, options);
17
- * };
18
- *
19
- * EventFactory.prototype.reaction = function(event, emoji) {
20
- * return this.create(ReactionBlueprint, event, emoji);
21
- * };
22
- *
23
- * // Extend the type via module augmentation
24
- * declare module "applesauce-core/event-factory" {
25
- * interface EventFactory {
26
- * note(content: string, options?: NoteBlueprintOptions): Promise<EventTemplate>;
27
- * reaction(event: NostrEvent, emoji?: string): Promise<EventTemplate>;
28
- * }
29
- * }
30
- * ```
31
- */
32
- export class EventFactory {
33
- context;
34
- constructor(context = {}) {
35
- this.context = context;
36
- }
37
- /** Build an event template with operations */
38
- async build(template, ...operations) {
39
- return await buildEvent(template, this.context, ...operations);
40
- }
41
- async create(blueprint, ...args) {
42
- // Context, blueprint(context)
43
- if (arguments.length === 1) {
44
- return (await blueprint(this.context));
45
- }
46
- // Context, blueprintConstructor(...args)(context), ...args
47
- else {
48
- const constructor = blueprint;
49
- return await constructor(...args)(this.context);
50
- }
51
- }
52
- /** Modify an existing event with operations and updated the created_at */
53
- async modify(draft, ...operations) {
54
- return await modifyEvent(draft, this.context, ...operations);
55
- }
56
- /** Modify a lists public and hidden tags and updated the created_at */
57
- async modifyTags(event, tagOperations, eventOperations) {
58
- let eventOperationsArr = [];
59
- // normalize event operation arg
60
- if (eventOperations === undefined)
61
- eventOperationsArr = [];
62
- else if (typeof eventOperations === "function")
63
- eventOperationsArr = [eventOperations];
64
- else if (Array.isArray(eventOperations))
65
- eventOperationsArr = eventOperations.filter((e) => !!e);
66
- // modify event
67
- return await this.modify(event, modifyTags(tagOperations), ...eventOperationsArr);
68
- }
69
- /** Attaches the signers pubkey to an event template */
70
- async stamp(draft) {
71
- return await stamp()(draft, this.context);
72
- }
73
- /** Signs a event template with the signer */
74
- async sign(draft) {
75
- return await sign()(draft, this.context);
76
- }
77
- // Helpers
78
- /** Sets the signer in the context */
79
- setSigner(signer) {
80
- this.context.signer = signer;
81
- }
82
- /** clears the signer in the context */
83
- clearSigner() {
84
- this.context.signer = undefined;
85
- }
86
- /** sets the client in the context */
87
- setClient(client) {
88
- this.context.client = client;
89
- }
90
- /** clears the client in the context */
91
- clearClient() {
92
- this.context.client = undefined;
93
- }
94
- }
@@ -1,3 +0,0 @@
1
- export * from "./types.js";
2
- export * from "./event-factory.js";
3
- export * from "./methods.js";
@@ -1,3 +0,0 @@
1
- export * from "./types.js";
2
- export * from "./event-factory.js";
3
- export * from "./methods.js";
@@ -1,17 +0,0 @@
1
- import { EventTemplate, NostrEvent, UnsignedEvent } from "../helpers/event.js";
2
- import { EventBlueprint, EventFactoryContext, EventOperation } from "./types.js";
3
- export type EventFactoryTemplate = {
4
- kind: number;
5
- content?: string;
6
- tags?: string[][];
7
- created_at?: number;
8
- };
9
- /** Creates an event using a template, context, and a set of operations */
10
- export declare function buildEvent(template: EventFactoryTemplate, context: EventFactoryContext, ...operations: (EventOperation | undefined)[]): Promise<EventTemplate>;
11
- /** Creates a blueprint function with operations */
12
- export declare function blueprint(kind: number, ...operations: (EventOperation | undefined)[]): EventBlueprint;
13
- /** Creates an event from a context and a blueprint */
14
- export declare function createEvent<T extends EventTemplate | UnsignedEvent | NostrEvent>(context: EventFactoryContext, blueprint: EventBlueprint<T>): Promise<T>;
15
- export declare function createEvent<T extends EventTemplate | UnsignedEvent | NostrEvent, Args extends Array<any>>(context: EventFactoryContext, blueprintConstructor: (...args: Args) => EventBlueprint<T>, ...args: Args): Promise<T>;
16
- /** Modifies an event using a context and a set of operations */
17
- export declare function modifyEvent(event: EventTemplate | UnsignedEvent | NostrEvent, context: EventFactoryContext, ...operations: (EventOperation | undefined)[]): Promise<EventTemplate>;
@@ -1,44 +0,0 @@
1
- import { EncryptedContentSymbol } from "../helpers/encrypted-content.js";
2
- import { isEvent } from "../helpers/event.js";
3
- import { eventPipe } from "../helpers/pipeline.js";
4
- import { unixNow } from "../helpers/time.js";
5
- import { setClient } from "../operations/client.js";
6
- import { includeReplaceableIdentifier, stripSignature, stripStamp, stripSymbols, updateCreatedAt, } from "../operations/event.js";
7
- /** Wraps a set of operations with common event operations */
8
- function wrapCommon(...operations) {
9
- return eventPipe(
10
- // Remove all symbols from the event except for the encrypted content symbol
11
- stripSymbols([EncryptedContentSymbol]),
12
- // Ensure all addressable events have "d" tags
13
- includeReplaceableIdentifier(),
14
- // Apply operations
15
- ...operations,
16
- // Include client tag if its set in the context
17
- (draft, ctx) => (ctx.client ? setClient(ctx.client.name, ctx.client.address)(draft, ctx) : draft));
18
- }
19
- /** Creates an event using a template, context, and a set of operations */
20
- export async function buildEvent(template, context, ...operations) {
21
- return await wrapCommon(stripSignature(), stripStamp(), ...operations)({ created_at: unixNow(), tags: [], content: "", ...template }, context);
22
- }
23
- /** Creates a blueprint function with operations */
24
- export function blueprint(kind, ...operations) {
25
- return async (context) => await buildEvent({ kind }, context, ...operations);
26
- }
27
- export async function createEvent(context, blueprint, ...args) {
28
- // Context, blueprint(context)
29
- if (arguments.length === 2) {
30
- return (await blueprint(context));
31
- }
32
- // Context, blueprintConstructor(...args)(context), ...args
33
- else {
34
- const constructor = blueprint;
35
- return await constructor(...args)(context);
36
- }
37
- }
38
- /** Modifies an event using a context and a set of operations */
39
- export async function modifyEvent(event, context, ...operations) {
40
- // NOTE: Unwrapping evnet object in order to handle cast events from applesauce-common
41
- if ("event" in event && isEvent(event.event))
42
- event = event.event;
43
- return await wrapCommon(stripSignature(), stripStamp(), updateCreatedAt(), ...operations)(event, context);
44
- }
@@ -1,76 +0,0 @@
1
- import { EventTemplate, NostrEvent, UnsignedEvent } from "../helpers/event.js";
2
- import { AddressPointer } from "../helpers/pointers.js";
3
- import { ModifyTagsOptions } from "../operations/tags.js";
4
- import { EventFactoryTemplate } from "./methods.js";
5
- /** Nostr event signer */
6
- export interface EventSigner {
7
- getPublicKey: () => Promise<string> | string;
8
- signEvent: (draft: EventTemplate | UnsignedEvent) => Promise<NostrEvent> | NostrEvent;
9
- nip04?: {
10
- encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
11
- decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
12
- };
13
- nip44?: {
14
- encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
15
- decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
16
- };
17
- }
18
- /** A context with optional methods for getting relay hints */
19
- export interface RelayHintContext {
20
- getEventRelayHint?: (event: string) => string | undefined | Promise<string> | Promise<undefined>;
21
- getPubkeyRelayHint?: (pubkey: string) => string | undefined | Promise<string> | Promise<undefined>;
22
- }
23
- /** A context with an optional signer */
24
- export interface EventSignerContext {
25
- signer?: EventSigner;
26
- }
27
- export interface EventFactoryClient {
28
- name: string;
29
- address?: Omit<AddressPointer, "kind" | "relays">;
30
- }
31
- /** A context with an optional NIP-89 app pointer */
32
- export interface ClientPointerContext {
33
- client?: EventFactoryClient;
34
- }
35
- /** NIP-30 emoji type. this should be moved out of the core package to common */
36
- export type Emoji = {
37
- /** The emoji shortcode (without the ::) */
38
- shortcode: string;
39
- /** The URL to the emoji image */
40
- url: string;
41
- };
42
- export interface EmojiContext {
43
- /** An array of custom emojis that will be used for text notes */
44
- emojis?: Emoji[];
45
- }
46
- /** All options that can be passed when building an event */
47
- export interface EventFactoryContext extends ClientPointerContext, EventSignerContext, RelayHintContext, EmojiContext {
48
- }
49
- /** A single operation that modifies an events public or hidden tags array */
50
- export type Operation<I extends unknown = unknown, R extends unknown = unknown> = (value: I, context: EventFactoryContext) => R | Promise<R>;
51
- /** A single operation that modifies an events public or hidden tags array */
52
- export type TagOperation = Operation<string[][], string[][]>;
53
- /** A single operation that modifies an event */
54
- export type EventOperation<I extends EventTemplate | UnsignedEvent | NostrEvent = EventTemplate, R extends EventTemplate | UnsignedEvent | NostrEvent = EventTemplate> = Operation<I, R>;
55
- /** A method that creates a new event based on a set of operations */
56
- export type EventBlueprint<T extends EventTemplate | UnsignedEvent | NostrEvent = EventTemplate> = (context: EventFactoryContext) => Promise<T>;
57
- /**
58
- * Core helpful event creation interface.
59
- * Contains only methods that use blueprints from the core package.
60
- * Other packages (like applesauce-common) can extend this interface via module augmentation.
61
- */
62
- export interface IEventFactory {
63
- /** Build an event template with operations */
64
- build(template: EventFactoryTemplate, ...operations: (EventOperation | undefined)[]): Promise<EventTemplate>;
65
- /** Create an event from a blueprint */
66
- create<T extends EventTemplate | UnsignedEvent | NostrEvent>(blueprint: EventBlueprint<T>): Promise<T>;
67
- create<T extends EventTemplate | UnsignedEvent | NostrEvent, Args extends Array<any>>(blueprint: (...args: Args) => EventBlueprint<T>, ...args: Args): Promise<T>;
68
- /** Modify an existing event with operations and updated the created_at */
69
- modify(draft: EventTemplate | UnsignedEvent | NostrEvent, ...operations: (EventOperation | undefined)[]): Promise<EventTemplate>;
70
- /** Modify a lists public and hidden tags and updated the created_at */
71
- modifyTags(event: EventTemplate | UnsignedEvent | NostrEvent, tagOperations?: ModifyTagsOptions, eventOperations?: EventOperation | (EventOperation | undefined)[]): Promise<EventTemplate>;
72
- /** Attaches the signers pubkey to an event template */
73
- stamp(draft: EventTemplate | UnsignedEvent): Promise<UnsignedEvent>;
74
- /** Signs a event template with the signer */
75
- sign(draft: EventTemplate | UnsignedEvent): Promise<NostrEvent>;
76
- }
File without changes