experimental: npm link test
This commit is contained in:
10
api/test-role.js
Normal file
10
api/test-role.js
Normal file
@@ -0,0 +1,10 @@
|
||||
require('dotenv').config({ path: '../.env' });
|
||||
const connect = require('../config/connect');
|
||||
const { Role } = require('@librechat/data-schemas');
|
||||
|
||||
(async () => {
|
||||
await connect();
|
||||
console.log('Connected to database');
|
||||
const role = await Role.findOne({ name: 'ADMIN' });
|
||||
console.log(role);
|
||||
})();
|
||||
9
package-lock.json
generated
9
package-lock.json
generated
@@ -36363,6 +36363,7 @@
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz",
|
||||
"integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/whatwg-url": "^11.0.2",
|
||||
"whatwg-url": "^14.1.0 || ^13.0.0"
|
||||
@@ -36372,6 +36373,7 @@
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz",
|
||||
"integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"punycode": "^2.3.1"
|
||||
},
|
||||
@@ -36383,6 +36385,7 @@
|
||||
"version": "14.2.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz",
|
||||
"integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"tr46": "^5.1.0",
|
||||
"webidl-conversions": "^7.0.0"
|
||||
@@ -45610,7 +45613,6 @@
|
||||
"klona": "^2.0.6",
|
||||
"lodash": "^4.17.21",
|
||||
"meilisearch": "^0.38.0",
|
||||
"mongoose": "^8.12.1",
|
||||
"traverse": "^0.6.11",
|
||||
"winston": "^3.17.0",
|
||||
"winston-daily-rotate-file": "^5.0.0"
|
||||
@@ -45639,7 +45641,8 @@
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"keyv": "^5.3.2"
|
||||
"keyv": "^5.3.2",
|
||||
"mongoose": "^8.12.1"
|
||||
}
|
||||
},
|
||||
"packages/data-schemas/node_modules/brace-expansion": {
|
||||
@@ -45725,6 +45728,7 @@
|
||||
"version": "6.14.2",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.14.2.tgz",
|
||||
"integrity": "sha512-kMEHNo0F3P6QKDq17zcDuPeaywK/YaJVCEQRzPF3TOM/Bl9MFg64YE5Tu7ifj37qZJMhwU1tl2Ioivws5gRG5Q==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@mongodb-js/saslprep": "^1.1.9",
|
||||
"bson": "^6.10.3",
|
||||
@@ -45770,6 +45774,7 @@
|
||||
"version": "8.12.1",
|
||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.12.1.tgz",
|
||||
"integrity": "sha512-UW22y8QFVYmrb36hm8cGncfn4ARc/XsYWQwRTaj0gxtQk1rDuhzDO1eBantS+hTTatfAIS96LlRCJrcNHvW5+Q==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"bson": "^6.10.3",
|
||||
"kareem": "2.6.3",
|
||||
|
||||
@@ -64,13 +64,13 @@
|
||||
"klona": "^2.0.6",
|
||||
"lodash": "^4.17.21",
|
||||
"meilisearch": "^0.38.0",
|
||||
"mongoose": "^8.12.1",
|
||||
"traverse": "^0.6.11",
|
||||
"winston": "^3.17.0",
|
||||
"winston-daily-rotate-file": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"keyv": "^5.3.2"
|
||||
"keyv": "^5.3.2",
|
||||
"mongoose": "^8.12.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
|
||||
@@ -1,65 +1,66 @@
|
||||
export { default as logger } from './config/winston';
|
||||
export { default as meiliLogger } from './config/meiliLogger';
|
||||
export * from './types';
|
||||
export * from './models';
|
||||
export * from './methods';
|
||||
export { Role } from './models/role';
|
||||
// export { default as logger } from './config/winston';
|
||||
// export { default as meiliLogger } from './config/meiliLogger';
|
||||
// export * from './types';
|
||||
// export * from './models';
|
||||
// export * from './methods';
|
||||
|
||||
// Export schemas (if needed for direct access)
|
||||
export { default as userSchema } from './schema/user';
|
||||
export { default as sessionSchema } from './schema/session';
|
||||
export { default as tokenSchema } from './schema/token';
|
||||
// // Export schemas (if needed for direct access)
|
||||
// export { default as userSchema } from './schema/user';
|
||||
// export { default as sessionSchema } from './schema/session';
|
||||
// export { default as tokenSchema } from './schema/token';
|
||||
|
||||
// Export utility functions from schemas
|
||||
export { signPayload, hashToken } from './schema/session';
|
||||
// // Export utility functions from schemas
|
||||
// export { signPayload, hashToken } from './schema/session';
|
||||
|
||||
export { default as actionSchema } from './schema/action';
|
||||
// export { default as actionSchema } from './schema/action';
|
||||
|
||||
export { default as agentSchema } from './schema/agent';
|
||||
// export { default as agentSchema } from './schema/agent';
|
||||
|
||||
export { default as assistantSchema } from './schema/assistant';
|
||||
// export { default as assistantSchema } from './schema/assistant';
|
||||
|
||||
export { default as balanceSchema } from './schema/balance';
|
||||
// export { default as balanceSchema } from './schema/balance';
|
||||
|
||||
export { default as bannerSchema } from './schema/banner';
|
||||
export type { IBanner } from './schema/banner';
|
||||
// export { default as bannerSchema } from './schema/banner';
|
||||
// export type { IBanner } from './schema/banner';
|
||||
|
||||
export { default as categoriesSchema } from './schema/categories';
|
||||
export type { ICategory } from './schema/categories';
|
||||
// export { default as categoriesSchema } from './schema/categories';
|
||||
// export type { ICategory } from './schema/categories';
|
||||
|
||||
export { default as conversationTagSchema } from './schema/conversationTag';
|
||||
export type { IConversationTag } from './schema/conversationTag';
|
||||
// export { default as conversationTagSchema } from './schema/conversationTag';
|
||||
// export type { IConversationTag } from './schema/conversationTag';
|
||||
|
||||
export { default as convoSchema } from './schema/convo';
|
||||
// export { default as convoSchema } from './schema/convo';
|
||||
|
||||
export { default as fileSchema } from './schema/file';
|
||||
// export { default as fileSchema } from './schema/file';
|
||||
|
||||
export { default as keySchema } from './schema/key';
|
||||
// export { default as keySchema } from './schema/key';
|
||||
|
||||
export { default as messageSchema } from './schema/message';
|
||||
export type { IMessage } from './schema/message';
|
||||
// export { default as messageSchema } from './schema/message';
|
||||
// export type { IMessage } from './schema/message';
|
||||
|
||||
export { default as pluginAuthSchema } from './schema/pluginAuth';
|
||||
export type { IPluginAuth } from './schema/pluginAuth';
|
||||
// export { default as pluginAuthSchema } from './schema/pluginAuth';
|
||||
// export type { IPluginAuth } from './schema/pluginAuth';
|
||||
|
||||
export { default as presetSchema } from './schema/preset';
|
||||
export type { IPreset } from './schema/preset';
|
||||
// export { default as presetSchema } from './schema/preset';
|
||||
// export type { IPreset } from './schema/preset';
|
||||
|
||||
export { default as projectSchema } from './schema/project';
|
||||
export type { IMongoProject } from './schema/project';
|
||||
// export { default as projectSchema } from './schema/project';
|
||||
// export type { IMongoProject } from './schema/project';
|
||||
|
||||
export { default as promptSchema } from './schema/prompt';
|
||||
export type { IPrompt } from './schema/prompt';
|
||||
// export { default as promptSchema } from './schema/prompt';
|
||||
// export type { IPrompt } from './schema/prompt';
|
||||
|
||||
export { default as promptGroupSchema } from './schema/promptGroup';
|
||||
export type { IPromptGroup, IPromptGroupDocument } from './schema/promptGroup';
|
||||
// export { default as promptGroupSchema } from './schema/promptGroup';
|
||||
// export type { IPromptGroup, IPromptGroupDocument } from './schema/promptGroup';
|
||||
|
||||
export { default as roleSchema } from './schema/role';
|
||||
// export { default as roleSchema } from './schema/role';
|
||||
|
||||
export { default as shareSchema } from './schema/share';
|
||||
export type { ISharedLink } from './schema/share';
|
||||
// export { default as shareSchema } from './schema/share';
|
||||
// export type { ISharedLink } from './schema/share';
|
||||
|
||||
export { default as toolCallSchema } from './schema/toolCall';
|
||||
export type { IToolCallData } from './schema/toolCall';
|
||||
// export { default as toolCallSchema } from './schema/toolCall';
|
||||
// export type { IToolCallData } from './schema/toolCall';
|
||||
|
||||
export { default as transactionSchema } from './schema/transaction';
|
||||
export type { ITransaction } from './schema/transaction';
|
||||
// export { default as transactionSchema } from './schema/transaction';
|
||||
// export type { ITransaction } from './schema/transaction';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import mongoose from 'mongoose';
|
||||
import mongoose from '~/mongoose';
|
||||
import roleSchema from '~/schema/role';
|
||||
import type { IRole } from '~/types';
|
||||
|
||||
export const Role = mongoose.models.Role || mongoose.model<IRole>('Role', roleSchema);
|
||||
export const Role = mongoose.models.Role || mongoose.model('Role', roleSchema) as any;
|
||||
|
||||
58
packages/data-schemas/src/mongoose.ts
Normal file
58
packages/data-schemas/src/mongoose.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Mongoose peer dependency loader
|
||||
* This handles loading mongoose from the parent project for proper peer dependency resolution
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let mongoose: any;
|
||||
|
||||
try {
|
||||
// First try to require mongoose normally (this works in production)
|
||||
mongoose = require('mongoose');
|
||||
} catch (error) {
|
||||
try {
|
||||
// If that fails, try to require from parent context (for npm link scenarios)
|
||||
// This is the TypeScript equivalent of the parent-require solution
|
||||
const Module = require('module');
|
||||
const originalRequire = Module.prototype.require;
|
||||
|
||||
// Try to find mongoose in parent module paths
|
||||
const parentPaths = require.main?.paths || [];
|
||||
for (const parentPath of parentPaths) {
|
||||
try {
|
||||
const parentRequire = Module.createRequire(parentPath + '/package.json');
|
||||
mongoose = parentRequire('mongoose');
|
||||
break;
|
||||
} catch {
|
||||
// Continue to next path
|
||||
}
|
||||
}
|
||||
|
||||
if (!mongoose) {
|
||||
// Last resort: use eval to get parent require
|
||||
const parentRequire = eval('require');
|
||||
mongoose = parentRequire('mongoose');
|
||||
}
|
||||
} catch (parentError) {
|
||||
throw new Error(
|
||||
'Could not load mongoose. Make sure mongoose is installed in the parent project or available as a peer dependency.\n' +
|
||||
`Local require error: ${error}\n` +
|
||||
`Parent require error: ${parentError}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default mongoose;
|
||||
|
||||
// Also export common mongoose items for convenience
|
||||
export const {
|
||||
Schema,
|
||||
model,
|
||||
models,
|
||||
connect,
|
||||
connection,
|
||||
Document,
|
||||
Types,
|
||||
Query,
|
||||
Model,
|
||||
} = mongoose;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Schema } from 'mongoose';
|
||||
import { Schema } from '~/mongoose';
|
||||
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
import type { IRole } from '~/types';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user