@rpcbase/db 0.14.0 → 0.15.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.js CHANGED
@@ -752,14 +752,26 @@ function parseMixed(required = true, def) {
752
752
  };
753
753
  }
754
754
  let cachedModels = null;
755
- const buildAppModels = (modules) => Object.entries(modules).filter(([key, schema]) => key.endsWith("Schema") && schema instanceof mongoose.Schema).map(([key, schema]) => {
755
+ const assertSchema = (exportName, value) => {
756
+ if (value instanceof mongoose.Schema) return value;
757
+ throw new Error(
758
+ [
759
+ `Expected ${exportName} to be an instance of mongoose.Schema, but it was not.`,
760
+ "rpcbase supports mongoose 9+ only.",
761
+ "Fix: ensure the project is using mongoose 9.x and that all packages resolve the same mongoose instance (try `npm ls mongoose`)."
762
+ ].join(" ")
763
+ );
764
+ };
765
+ const buildAppModels = (modules) => Object.entries(modules).filter(([key]) => key.endsWith("Schema")).map(([key, schemaValue]) => {
766
+ const schema = assertSchema(key, schemaValue);
756
767
  const name = key.replace(/Schema$/, "");
757
768
  return {
758
769
  name,
759
770
  model: mongoose.models[name] ?? mongoose.model(name, schema)
760
771
  };
761
772
  });
762
- const buildFrameworkModels = () => Object.entries(frameworkSchemas).filter(([_, schema]) => schema instanceof mongoose.Schema).map(([key, schema]) => {
773
+ const buildFrameworkModels = () => Object.entries(frameworkSchemas).filter(([key]) => key.endsWith("Schema")).map(([key, schemaValue]) => {
774
+ const schema = assertSchema(key, schemaValue);
763
775
  const name = key.replace(/Schema$/, "");
764
776
  return {
765
777
  name,
@@ -8,6 +8,6 @@ type LoadModelCtx = {
8
8
  } | null;
9
9
  };
10
10
  };
11
- export declare const loadModel: (modelName: string, ctx: LoadModelCtx) => Promise<mongoose.Model<any, {}, {}, {}, any, any>>;
11
+ export declare const loadModel: (modelName: string, ctx: LoadModelCtx) => Promise<mongoose.Model<any, {}, {}, {}, any, any, any>>;
12
12
  export type { LoadModelCtx };
13
13
  //# sourceMappingURL=loadModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadModel.d.ts","sourceRoot":"","sources":["../src/loadModel.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAK/B,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE;QACH,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,EAAE;gBACL,iBAAiB,CAAC,EAAE,MAAM,CAAC;aAC5B,CAAA;SACF,GAAG,IAAI,CAAC;KACV,CAAC;CACH,CAAC;AAKF,eAAO,MAAM,SAAS,GAAU,WAAW,MAAM,EAAE,KAAK,YAAY,uDA4CnE,CAAA;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"loadModel.d.ts","sourceRoot":"","sources":["../src/loadModel.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAK/B,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE;QACH,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,EAAE;gBACL,iBAAiB,CAAC,EAAE,MAAM,CAAC;aAC5B,CAAA;SACF,GAAG,IAAI,CAAC;KACV,CAAC;CACH,CAAC;AAKF,eAAO,MAAM,SAAS,GAAU,WAAW,MAAM,EAAE,KAAK,YAAY,4DA4CnE,CAAA;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { default as mongoose } from '../../vite/node_modules/mongoose';
2
2
  type ModelModules = Record<string, unknown>;
3
3
  export declare const registerModels: (modules: ModelModules) => void;
4
- export declare const getRegisteredModels: () => Record<string, mongoose.Model<any, {}, {}, {}, any, any>>;
4
+ export declare const getRegisteredModels: () => Record<string, mongoose.Model<any, {}, {}, {}, any, any, any>>;
5
5
  export type { ModelModules };
6
6
  //# sourceMappingURL=registerModels.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registerModels.d.ts","sourceRoot":"","sources":["../src/registerModels.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAK/B,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAoC3C,eAAO,MAAM,cAAc,GAAI,SAAS,YAAY,SAEnD,CAAA;AAED,eAAO,MAAM,mBAAmB,iEAK/B,CAAA;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"registerModels.d.ts","sourceRoot":"","sources":["../src/registerModels.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAK/B,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAkD3C,eAAO,MAAM,cAAc,GAAI,SAAS,YAAY,SAEnD,CAAA;AAED,eAAO,MAAM,mBAAmB,sEAK/B,CAAA;AAED,YAAY,EAAE,YAAY,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/db",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -50,13 +50,12 @@
50
50
  }
51
51
  },
52
52
  "peerDependencies": {
53
- "mongoose": "^8 || ^9",
53
+ "mongoose": "^9",
54
54
  "zod": "^4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "24.10.1",
58
58
  "@vitest/coverage-v8": "4.0.9",
59
- "mongoose": "8.19.4",
60
59
  "vitest": "4.0.9"
61
60
  }
62
61
  }