applesauce-core 0.0.0-next-20251203172109 → 0.0.0-next-20251205152544

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.
@@ -28,19 +28,8 @@ export declare class AsyncEventStore extends EventModels implements IAsyncEventS
28
28
  remove$: Subject<import("nostr-tools/core").Event>;
29
29
  /**
30
30
  * A method that will be called when an event isn't found in the store
31
- * @experimental
32
31
  */
33
- eventLoader?: (pointer: EventPointer) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
34
- /**
35
- * A method that will be called when a replaceable event isn't found in the store
36
- * @experimental
37
- */
38
- replaceableLoader?: (pointer: AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
39
- /**
40
- * A method that will be called when an addressable event isn't found in the store
41
- * @experimental
42
- */
43
- addressableLoader?: (pointer: AddressPointer) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
32
+ eventLoader?: (pointer: EventPointer | AddressPointer | AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
44
33
  constructor(database: IAsyncEventDatabase);
45
34
  /** A method to add all events to memory to ensure there is only ever a single instance of an event */
46
35
  private mapToMemory;
@@ -38,19 +38,8 @@ export class AsyncEventStore extends EventModels {
38
38
  remove$ = new Subject();
39
39
  /**
40
40
  * A method that will be called when an event isn't found in the store
41
- * @experimental
42
41
  */
43
42
  eventLoader;
44
- /**
45
- * A method that will be called when a replaceable event isn't found in the store
46
- * @experimental
47
- */
48
- replaceableLoader;
49
- /**
50
- * A method that will be called when an addressable event isn't found in the store
51
- * @experimental
52
- */
53
- addressableLoader;
54
43
  constructor(database) {
55
44
  super();
56
45
  this.database = database;
@@ -26,21 +26,8 @@ export declare class EventStore extends EventModels implements IEventStore {
26
26
  update$: Subject<import("nostr-tools/core").Event>;
27
27
  /** A stream of events that have been removed */
28
28
  remove$: Subject<import("nostr-tools/core").Event>;
29
- /**
30
- * A method that will be called when an event isn't found in the store
31
- * @experimental
32
- */
33
- eventLoader?: (pointer: EventPointer) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
34
- /**
35
- * A method that will be called when a replaceable event isn't found in the store
36
- * @experimental
37
- */
38
- replaceableLoader?: (pointer: AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
39
- /**
40
- * A method that will be called when an addressable event isn't found in the store
41
- * @experimental
42
- */
43
- addressableLoader?: (pointer: AddressPointer) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
29
+ /** A method that will be called when an event isn't found in the store */
30
+ eventLoader?: (pointer: EventPointer | AddressPointer | AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
44
31
  constructor(database?: IEventDatabase);
45
32
  /** A method to add all events to memory to ensure there is only ever a single instance of an event */
46
33
  private mapToMemory;
@@ -38,21 +38,8 @@ export class EventStore extends EventModels {
38
38
  update$ = new Subject();
39
39
  /** A stream of events that have been removed */
40
40
  remove$ = new Subject();
41
- /**
42
- * A method that will be called when an event isn't found in the store
43
- * @experimental
44
- */
41
+ /** A method that will be called when an event isn't found in the store */
45
42
  eventLoader;
46
- /**
47
- * A method that will be called when a replaceable event isn't found in the store
48
- * @experimental
49
- */
50
- replaceableLoader;
51
- /**
52
- * A method that will be called when an addressable event isn't found in the store
53
- * @experimental
54
- */
55
- addressableLoader;
56
43
  constructor(database = new EventMemory()) {
57
44
  super();
58
45
  if (database) {
@@ -99,7 +99,7 @@ export interface IEventModelMixin<TStore extends IEventStore | IAsyncEventStore>
99
99
  model<T extends unknown, Args extends Array<any>>(constructor: ModelConstructor<T, Args, TStore>, ...args: Args): Observable<T>;
100
100
  }
101
101
  /** The interface that is passed to the model for creating subscriptions */
102
- export type ModelEventStore<TStore extends IEventStore | IAsyncEventStore> = IEventStoreStreams & IEventSubscriptions & IEventModelMixin<TStore> & IEventFallbackLoaders & TStore;
102
+ export type ModelEventStore<TStore extends IEventStore | IAsyncEventStore> = IEventStoreStreams & IEventSubscriptions & IEventModelMixin<TStore> & IMissingEventLoader & TStore;
103
103
  /** A computed view of an event set or event store */
104
104
  export type Model<T extends unknown, TStore extends IEventStore | IAsyncEventStore = IEventStore | IAsyncEventStore> = (events: ModelEventStore<TStore>) => Observable<T>;
105
105
  /** A constructor for a {@link Model} */
@@ -136,17 +136,13 @@ export interface IEventMemory extends IEventStoreRead, IEventClaims {
136
136
  remove(event: string | NostrEvent): boolean;
137
137
  }
138
138
  /** A set of methods that an event store will use to load single events it does not have */
139
- export interface IEventFallbackLoaders {
139
+ export interface IMissingEventLoader {
140
140
  /** A method that will be called when an event isn't found in the store */
141
- eventLoader?: (pointer: EventPointer) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
142
- /** A method that will be called when a replaceable event isn't found in the store */
143
- replaceableLoader?: (pointer: AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
144
- /** A method that will be called when an addressable event isn't found in the store */
145
- addressableLoader?: (pointer: AddressPointer) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
141
+ eventLoader?: (pointer: EventPointer | AddressPointer | AddressPointerWithoutD) => Observable<NostrEvent> | Promise<NostrEvent | undefined>;
146
142
  }
147
143
  /** Generic async event store interface */
148
- export interface IAsyncEventStore extends IAsyncEventStoreRead, IEventStoreStreams, IEventSubscriptions, IAsyncEventStoreActions, IEventModelMixin<IAsyncEventStore>, IEventClaims, IEventFallbackLoaders, IEventStoreModels {
144
+ export interface IAsyncEventStore extends IAsyncEventStoreRead, IEventStoreStreams, IEventSubscriptions, IAsyncEventStoreActions, IEventModelMixin<IAsyncEventStore>, IEventClaims, IMissingEventLoader, IEventStoreModels {
149
145
  }
150
146
  /** Generic sync event store interface */
151
- export interface IEventStore extends IEventStoreRead, IEventStoreStreams, IEventSubscriptions, IEventStoreActions, IEventModelMixin<IEventStore>, IEventClaims, IEventFallbackLoaders, IEventStoreModels {
147
+ export interface IEventStore extends IEventStoreRead, IEventStoreStreams, IEventSubscriptions, IEventStoreActions, IEventModelMixin<IEventStore>, IEventClaims, IMissingEventLoader, IEventStoreModels {
152
148
  }
@@ -38,24 +38,7 @@ function loadEventUsingFallback(store, pointer) {
38
38
  // If event was not found, attempt to load
39
39
  if (!store.eventLoader)
40
40
  return EMPTY;
41
- return from(store.eventLoader(pointer));
42
- });
43
- }
44
- /** If replaceable event is undefined, attempt to load using the fallback loader */
45
- function loadReplaceableUsingFallback(store, pointer) {
46
- return switchMap((event) => {
47
- if (event)
48
- return of(event);
49
- else if (pointer.identifier !== undefined) {
50
- if (!store.addressableLoader)
51
- return EMPTY;
52
- return from(store.addressableLoader(pointer)).pipe(filter((e) => !!e));
53
- }
54
- else {
55
- if (!store.replaceableLoader)
56
- return EMPTY;
57
- return from(store.replaceableLoader(pointer)).pipe(filter((e) => !!e));
58
- }
41
+ return from(store.eventLoader(pointer)).pipe(filter((e) => !!e));
59
42
  });
60
43
  }
61
44
  /** A model that returns a single event or undefined when its removed */
@@ -88,7 +71,7 @@ export function ReplaceableModel(pointer) {
88
71
  // lazily get current event
89
72
  defer(() => getReplaceableFromStores(store, pointer)).pipe(
90
73
  // If the event isn't found, attempt to load using the fallback loader
91
- loadReplaceableUsingFallback(store, pointer),
74
+ loadEventUsingFallback(store, pointer),
92
75
  // Only emit found events
93
76
  defined()),
94
77
  // Subscribe to new events that match the pointer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20251203172109",
3
+ "version": "0.0.0-next-20251205152544",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",