@byearlybird/starling 0.2.2 → 0.3.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/index.d.ts CHANGED
@@ -74,7 +74,7 @@ declare const create$1: (iterable?: Iterable<readonly [string, EncodedDocument]>
74
74
  };
75
75
  };
76
76
  declare namespace store_d_exports {
77
- export { Plugin, PluginHandle, Store as StarlingStore, StoreHooks, StoreOnBeforeDelete, StoreOnBeforePatch, StoreOnBeforePut, StoreOnDelete, StoreOnPatch, StoreOnPut, StoreTransaction, create };
77
+ export { Plugin, PluginHandle, PluginMethods, Store as StarlingStore, StoreHooks, StoreOnBeforeDelete, StoreOnBeforePatch, StoreOnBeforePut, StoreOnDelete, StoreOnPatch, StoreOnPut, StoreTransaction, create };
78
78
  }
79
79
  type DeepPartial<T$1> = T$1 extends object ? { [P in keyof T$1]?: DeepPartial<T$1[P]> } : T$1;
80
80
  /**
@@ -131,13 +131,15 @@ type StoreTransaction<T$1 extends Record<string, unknown>> = {
131
131
  }) => void;
132
132
  rollback: () => void;
133
133
  };
134
- type PluginHandle<T$1 extends Record<string, unknown>> = {
134
+ type PluginMethods = Record<string, (...args: any[]) => any>;
135
+ type PluginHandle<T$1 extends Record<string, unknown>, M$1 extends PluginMethods = {}> = {
135
136
  init: () => Promise<void> | void;
136
137
  dispose: () => Promise<void> | void;
137
138
  hooks?: StoreHooks<T$1>;
139
+ methods?: M$1;
138
140
  };
139
- type Plugin<T$1 extends Record<string, unknown>> = (store: Store<T$1>) => PluginHandle<T$1>;
140
- type Store<T$1 extends Record<string, unknown>> = {
141
+ type Plugin<T$1 extends Record<string, unknown>, M$1 extends PluginMethods = {}> = (store: Store<T$1, any>) => PluginHandle<T$1, M$1>;
142
+ type Store<T$1 extends Record<string, unknown>, Extended = {}> = {
141
143
  get: (key: string) => T$1 | null;
142
144
  has: (key: string) => boolean;
143
145
  readonly size: number;
@@ -148,10 +150,10 @@ type Store<T$1 extends Record<string, unknown>> = {
148
150
  patch: (key: string, value: DeepPartial<T$1>) => void;
149
151
  del: (key: string) => void;
150
152
  begin: () => StoreTransaction<T$1>;
151
- use: (plugin: Plugin<T$1>) => Store<T$1>;
152
- init: () => Promise<Store<T$1>>;
153
+ use: <M extends PluginMethods>(plugin: Plugin<T$1, M>) => Store<T$1, Extended & M>;
154
+ init: () => Promise<Store<T$1, Extended>>;
153
155
  dispose: () => Promise<void>;
154
- };
155
- declare const create: <T extends Record<string, unknown>>() => Store<T>;
156
+ } & Extended;
157
+ declare const create: <T extends Record<string, unknown>>() => Store<T, {}>;
156
158
  //#endregion
157
159
  export { type clock_d_exports as Clock, document_d_exports as Document, eventstamp_d_exports as Eventstamp, kv_d_exports as KV, record_d_exports as Record, store_d_exports as Store, value_d_exports as Value };
package/dist/index.js CHANGED
@@ -332,7 +332,7 @@ const create$1 = () => {
332
332
  };
333
333
  },
334
334
  use(plugin) {
335
- const { hooks: pluginHooks, init, dispose } = plugin(this);
335
+ const { hooks: pluginHooks, init, dispose, methods } = plugin(this);
336
336
  if (pluginHooks) {
337
337
  if (pluginHooks.onBeforePut) {
338
338
  const callback = pluginHooks.onBeforePut;
@@ -377,6 +377,7 @@ const create$1 = () => {
377
377
  });
378
378
  }
379
379
  }
380
+ if (methods) Object.assign(this, methods);
380
381
  initializers.add(init);
381
382
  disposers.add(dispose);
382
383
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byearlybird/starling",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",