jax-hono 1.0.8 → 1.0.10

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.
@@ -105,7 +105,7 @@ export abstract class ApiController extends Controller {
105
105
  return c.fail("数据获取失败");
106
106
  }
107
107
 
108
- return c.ok(await this.formatItem(doc));
108
+ return c.ok(await this._formatItem(doc));
109
109
  }
110
110
 
111
111
  async create(c: Context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jax-hono",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Lightweight framework layer on top of Hono, built for Bun",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
@@ -62,6 +62,7 @@ export function createSchemaModel<TSchema extends Schema>(
62
62
 
63
63
  applyDefaultSchemaOptions(schema);
64
64
  installCommonFields(schema);
65
+ installRankHooksIfNeeded(schema);
65
66
  installModelStatics(schema);
66
67
 
67
68
  return (mongoose.models[name] ??
@@ -74,6 +75,8 @@ export function createSchemaModel<TSchema extends Schema>(
74
75
 
75
76
  export const createModel = createSchemaModel;
76
77
 
78
+ const rankHooksInstalled = Symbol.for("jax-hono.mongoose.rankHooksInstalled");
79
+
77
80
  export function getModelName(filePathOrName: string) {
78
81
  const baseName =
79
82
  filePathOrName.includes("/") || filePathOrName.includes("\\")
@@ -151,6 +154,12 @@ export function applyDefaultSchemaOptions(schema: Schema) {
151
154
  }
152
155
 
153
156
  export function installRankHooks(schema: Schema) {
157
+ if ((schema as any)[rankHooksInstalled]) {
158
+ return;
159
+ }
160
+
161
+ (schema as any)[rankHooksInstalled] = true;
162
+
154
163
  schema.pre(["updateOne", "findOneAndUpdate", "updateMany"], function () {
155
164
  normalizeRank(this.getUpdate());
156
165
  });
@@ -160,6 +169,12 @@ export function installRankHooks(schema: Schema) {
160
169
  });
161
170
  }
162
171
 
172
+ function installRankHooksIfNeeded(schema: Schema) {
173
+ if (schema.path("rank") && schema.path("isTop")) {
174
+ installRankHooks(schema);
175
+ }
176
+ }
177
+
163
178
  export function installAutoNo(schema: Schema, field: string, start = 0) {
164
179
  schema.pre("save", async function () {
165
180
  if (!this.isNew || this.get(field)) {