@wxn0brp/db-core 0.11.5-alpha.1 → 0.11.5

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.
@@ -75,25 +75,19 @@ export class ValtheraClass {
75
75
  await this.init();
76
76
  const plugins = this._plugins;
77
77
  const self = this;
78
- const exe = () => self.executor.addOp(self.adapter[name].bind(self.adapter), query, typeof query === "string" ? query : query.collection);
79
- if (plugins.length === 0) {
80
- const result = await exe();
81
- this.emitter.emit(name, query, result);
82
- return result;
83
- }
84
- let q = query;
85
78
  let idx = 0;
86
- const op = name;
87
- const next = async (modifiedQuery) => {
88
- if (modifiedQuery !== undefined)
89
- q = modifiedQuery;
90
- if (idx < plugins.length)
91
- return plugins[idx++].execute(op, q, next);
92
- return exe();
79
+ const ctx = {
80
+ op: name,
81
+ query,
82
+ next: async () => {
83
+ if (idx < plugins.length)
84
+ return plugins[idx++].execute(ctx);
85
+ return self.executor.addOp(self.adapter[ctx.op].bind(self.adapter), ctx.query, typeof ctx.query === "string" ? ctx.query : ctx.query.collection);
86
+ }
93
87
  };
94
- const r = await next();
95
- this.emitter.emit(name, q, r);
96
- return r;
88
+ const result = await ctx.next();
89
+ this.emitter.emit(ctx.op, ctx.query, result);
90
+ return result;
97
91
  }
98
92
  /**
99
93
  * Create a new instance of a Collection class.
package/dist/index.d.ts CHANGED
@@ -7,6 +7,5 @@ export { Relation } from "./helpers/relation.js";
7
7
  export { convertIdToUnix, sortByIds } from "./utils/id.js";
8
8
  export type { ValtheraTypes } from "./types/export.js";
9
9
  export type { Id } from "./types/Id.js";
10
- export type { ValtheraPlugin } from "./types/plugin.js";
11
10
  export type { RelationTypes } from "./types/relation.js";
12
11
  export type { ValtheraCompatible } from "./types/valthera.js";
@@ -1,6 +1,11 @@
1
1
  import type { ValtheraClass } from "../db/valthera.js";
2
+ export interface PluginContext {
3
+ op: string;
4
+ query: any;
5
+ next: () => Promise<any>;
6
+ }
2
7
  export interface ValtheraPlugin {
3
8
  name: string;
4
- execute(op: string, query: any, next: (q?: any) => Promise<any>): Promise<any>;
9
+ execute(ctx: PluginContext): Promise<any>;
5
10
  init?: (db: ValtheraClass) => void;
6
11
  }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.11.5-alpha.1";
1
+ export const version = "0.11.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.11.5-alpha.1",
3
+ "version": "0.11.5",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",