{"_id":"@bcibibi/y-sync-middleware-mongoose","_rev":"5-dc62d0362d3f23667a8118bae2779bfb","name":"@bcibibi/y-sync-middleware-mongoose","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@bcibibi/y-sync-middleware-mongoose","version":"1.0.0","keywords":["yjs","mongoose","sync","collaboration"],"author":{"name":"bcibibi"},"license":"MIT","_id":"@bcibibi/y-sync-middleware-mongoose@1.0.0","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"homepage":"https://github.com/bcibibi/y-sync/tree/main/middleware/mongoose#readme","bugs":{"url":"https://github.com/bcibibi/y-sync/issues"},"dist":{"shasum":"7a73e0f2e826d92fef000744730a1be5a956fa01","tarball":"https://registry.npmjs.org/@bcibibi/y-sync-middleware-mongoose/-/y-sync-middleware-mongoose-1.0.0.tgz","fileCount":22,"integrity":"sha512-FwYezOfkCPmUHwXcJCGo8ue0Zbppt8DzR8NT2AkN5A+hVskCyyGrvvcWhRKJbMyi8DbcpzUQPTRsscMxa1fT0Q==","signatures":[{"sig":"MEUCIQCMH49gO1IWUvplMq1GAEjhG2TvaTOGsr9EBZaVve3zbQIgOKVyNNj0ej1iNQaP512TUe592uTIbUXwGxrlxEv8kRo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18160},"main":"./dist/cjs/index.js","type":"module","types":"./dist/esm/index.d.ts","module":"./dist/esm/index.js","exports":{"./client":{"types":"./dist/esm/client.d.ts","import":"./dist/esm/client.js","default":"./dist/esm/client.js","require":"./dist/cjs/client.js"},"./middleware":{"types":"./dist/esm/middleware.d.ts","import":"./dist/esm/middleware.js","default":"./dist/esm/middleware.js","require":"./dist/cjs/middleware.js"},"./package.json":"./package.json"},"gitHead":"fcfd6c84d1c586ddaca8ac78591dea3f4d5d4ae3","scripts":{"build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:cjs":"tsc -p tsconfig.cjs.json","build:esm":"tsc -p tsconfig.esm.json","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\""},"_npmUser":{"name":"bcibi","email":"benoit.cibillon@gmail.com"},"repository":{"url":"git+https://github.com/bcibibi/y-sync.git","type":"git"},"_npmVersion":"11.16.0","description":"Y server and client for syncing Yjs documents over Mongoose","directories":{},"_nodeVersion":"24.18.0","dependencies":{"debug":"^4.4.3","p-debounce":"^5.1.0","@bcibibi/y-utils":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.4.2","ts-jest":"^29.4.11","typescript":"^6.0.3","@types/jest":"^30.0.0","@types/node":"^25.9.1","@types/debug":"^4.1.13","@types/crypto-js":"^4.2.2"},"peerDependencies":{"yjs":"^13.6.31","mongoose":"^9.7.4","@bcibibi/y-sync-client":"^1.0.0","@bcibibi/y-sync-server":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/y-sync-middleware-mongoose_1.0.0_1785057665728_0.49888599053870664","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@bcibibi/y-sync-middleware-mongoose","version":"1.0.1","keywords":["yjs","mongoose","sync","collaboration"],"author":{"name":"bcibibi"},"license":"MIT","_id":"@bcibibi/y-sync-middleware-mongoose@1.0.1","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"homepage":"https://github.com/bcibibi/y-sync/tree/main/middleware/mongoose#readme","bugs":{"url":"https://github.com/bcibibi/y-sync/issues"},"dist":{"shasum":"ec7a5ab7383b2fc86553a106eb76fe169d8f68b2","tarball":"https://registry.npmjs.org/@bcibibi/y-sync-middleware-mongoose/-/y-sync-middleware-mongoose-1.0.1.tgz","fileCount":22,"integrity":"sha512-SbupbnHR4cAuOmQR0zCvLEraDdZwrRriz5mNyU9TigNwAB4LqE6G7In9z40sT27HxgPQulpPN2mzrY09UuWr8g==","signatures":[{"sig":"MEUCIQDBsguE8aqJQCc9zIbSG1S2Li7TQcIG2e8j7Yqlzit0nwIgf1oicd3P67ijq1oAWnzh/6XzpczmF1HfzKCrKC8tlWg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@bcibibi%2fy-sync-middleware-mongoose@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":18160},"main":"./dist/cjs/index.js","type":"module","types":"./dist/esm/index.d.ts","module":"./dist/esm/index.js","exports":{"./client":{"types":"./dist/esm/client.d.ts","import":"./dist/esm/client.js","default":"./dist/esm/client.js","require":"./dist/cjs/client.js"},"./middleware":{"types":"./dist/esm/middleware.d.ts","import":"./dist/esm/middleware.js","default":"./dist/esm/middleware.js","require":"./dist/cjs/middleware.js"},"./package.json":"./package.json"},"gitHead":"9142e7dcd5e13ee881632b845b1ca603694ccbd2","scripts":{"build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:cjs":"tsc -p tsconfig.cjs.json","build:esm":"tsc -p tsconfig.esm.json","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f0e439ad-ec40-4ed3-929c-7d2b0504d85f"}},"repository":{"url":"git+https://github.com/bcibibi/y-sync.git","type":"git"},"_npmVersion":"11.17.0","description":"Y server and client for syncing Yjs documents over Mongoose","directories":{},"_nodeVersion":"24.19.0","dependencies":{"debug":"^4.4.3","p-debounce":"^5.1.0","@bcibibi/y-utils":"^1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.4.2","ts-jest":"^29.4.11","typescript":"^6.0.3","@types/jest":"^30.0.0","@types/node":"^26.2.0","@types/debug":"^4.1.13","@types/crypto-js":"^4.2.2"},"peerDependencies":{"yjs":"^13.6.31","mongoose":"^9.7.4","@bcibibi/y-sync-client":"^1.0.1","@bcibibi/y-sync-server":"^1.0.1"},"_npmOperationalInternal":{"tmp":"tmp/y-sync-middleware-mongoose_1.0.1_1787727199520_0.9735259208757454","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@bcibibi/y-sync-middleware-mongoose","version":"1.0.2","keywords":["yjs","mongoose","sync","collaboration"],"author":{"name":"bcibibi"},"license":"MIT","_id":"@bcibibi/y-sync-middleware-mongoose@1.0.2","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"homepage":"https://github.com/bcibibi/y-sync/tree/main/middleware/mongoose#readme","bugs":{"url":"https://github.com/bcibibi/y-sync/issues"},"dist":{"shasum":"bada62e81be100a233885df57a66c75d7443dc08","tarball":"https://registry.npmjs.org/@bcibibi/y-sync-middleware-mongoose/-/y-sync-middleware-mongoose-1.0.2.tgz","fileCount":22,"integrity":"sha512-irPBdU/oMKc3u50aOE8QI1omW48yZM+rJ+GsegA6Ah9PBjILsc1AFxIWiJunmlS+V2fCYosSKHjiioDaoXccUw==","signatures":[{"sig":"MEQCIAjqabiF4apsXIV3v8kH/CrIIzx8Kd9PmoFERlUk6Oj1AiAydnOfAP3iijjjIAsWuM9jSzmLY0SxPAzJKKW/kcF5SQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@bcibibi%2fy-sync-middleware-mongoose@1.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":18160},"main":"./dist/cjs/index.js","type":"module","types":"./dist/esm/index.d.ts","module":"./dist/esm/index.js","exports":{"./client":{"types":"./dist/esm/client.d.ts","import":"./dist/esm/client.js","default":"./dist/esm/client.js","require":"./dist/cjs/client.js"},"./middleware":{"types":"./dist/esm/middleware.d.ts","import":"./dist/esm/middleware.js","default":"./dist/esm/middleware.js","require":"./dist/cjs/middleware.js"},"./package.json":"./package.json"},"gitHead":"01b7a10ff2762f1ab6d02c2d7de1046693ba8aa9","scripts":{"build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:cjs":"tsc -p tsconfig.cjs.json","build:esm":"tsc -p tsconfig.esm.json","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f0e439ad-ec40-4ed3-929c-7d2b0504d85f"}},"repository":{"url":"git+https://github.com/bcibibi/y-sync.git","type":"git"},"_npmVersion":"11.17.0","description":"Y server and client for syncing Yjs documents over Mongoose","directories":{},"_nodeVersion":"24.19.0","dependencies":{"debug":"^4.4.3","p-debounce":"^5.1.0","@bcibibi/y-utils":"^1.0.2"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.4.2","ts-jest":"^29.4.11","typescript":"^6.0.3","@types/jest":"^30.0.0","@types/node":"^26.2.0","@types/debug":"^4.1.13","@types/crypto-js":"^4.2.2"},"peerDependencies":{"yjs":"^13.6.31","mongoose":"^9.7.4","@bcibibi/y-sync-client":"^1.0.2","@bcibibi/y-sync-server":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/y-sync-middleware-mongoose_1.0.2_1787984109837_0.9027936343004781","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@bcibibi/y-sync-middleware-mongoose","version":"1.0.3","keywords":["yjs","mongoose","sync","collaboration"],"author":{"name":"bcibibi"},"license":"MIT","_id":"@bcibibi/y-sync-middleware-mongoose@1.0.3","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"homepage":"https://github.com/bcibibi/y-sync/tree/main/middleware/mongoose#readme","bugs":{"url":"https://github.com/bcibibi/y-sync/issues"},"dist":{"shasum":"5b1000f0e2a1d6e5057302e5a3b09bdf7c34cf7d","tarball":"https://registry.npmjs.org/@bcibibi/y-sync-middleware-mongoose/-/y-sync-middleware-mongoose-1.0.3.tgz","fileCount":22,"integrity":"sha512-MYbKR2UjVmBSQgFzGWxq3UKIE8sPXLZN25B4+BxxPLFyWt+oaIeaD/0RtugXK9aI1HQW9gZcwAl4yags4oxTng==","signatures":[{"sig":"MEUCIF2FPcx/Fg36ctu/6H8bZ2XFlqmrsVw56Axox1xnyU6QAiEA660vBh/thQfwMvTSJKHMgcYHyXgCkRaUYaSE43mkJ/I=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@bcibibi%2fy-sync-middleware-mongoose@1.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":23553},"main":"./dist/cjs/index.js","type":"module","types":"./dist/esm/index.d.ts","module":"./dist/esm/index.js","exports":{"./client":{"types":"./dist/esm/client.d.ts","import":"./dist/esm/client.js","default":"./dist/esm/client.js","require":"./dist/cjs/client.js"},"./middleware":{"types":"./dist/esm/middleware.d.ts","import":"./dist/esm/middleware.js","default":"./dist/esm/middleware.js","require":"./dist/cjs/middleware.js"},"./package.json":"./package.json"},"gitHead":"0c1b3ec7784809bee924d6011dbe17ce4757edb9","scripts":{"build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:cjs":"tsc -p tsconfig.cjs.json","build:esm":"tsc -p tsconfig.esm.json","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f0e439ad-ec40-4ed3-929c-7d2b0504d85f"}},"repository":{"url":"git+https://github.com/bcibibi/y-sync.git","type":"git"},"_npmVersion":"11.17.0","description":"Y server and client for syncing Yjs documents over Mongoose","directories":{},"_nodeVersion":"24.19.0","dependencies":{"debug":"^4.4.3","p-debounce":"^5.1.0","@bcibibi/y-utils":"^1.0.3"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.4.2","ts-jest":"^29.4.11","typescript":"^6.0.3","@types/jest":"^30.0.0","@types/node":"^26.2.0","@types/debug":"^4.1.13","@types/crypto-js":"^4.2.2"},"peerDependencies":{"yjs":"^13.6.31","mongoose":"^9.7.4","@bcibibi/y-sync-client":"^1.0.3","@bcibibi/y-sync-server":"^1.0.3"},"_npmOperationalInternal":{"tmp":"tmp/y-sync-middleware-mongoose_1.0.3_1788028538157_0.6054806146957628","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@bcibibi/y-sync-middleware-mongoose","version":"1.0.4","description":"Y server and client for syncing Yjs documents over Mongoose","keywords":["yjs","mongoose","sync","collaboration"],"homepage":"https://github.com/bcibibi/y-sync/tree/main/middleware/mongoose#readme","bugs":{"url":"https://github.com/bcibibi/y-sync/issues"},"repository":{"type":"git","url":"git+https://github.com/bcibibi/y-sync.git"},"license":"MIT","author":{"name":"bcibibi"},"type":"module","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","exports":{"./client":{"types":"./dist/esm/client.d.ts","import":"./dist/esm/client.js","require":"./dist/cjs/client.js","default":"./dist/esm/client.js"},"./middleware":{"types":"./dist/esm/middleware.d.ts","import":"./dist/esm/middleware.js","require":"./dist/cjs/middleware.js","default":"./dist/esm/middleware.js"},"./package.json":"./package.json"},"scripts":{"clean":"node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"","build:esm":"tsc -p tsconfig.esm.json","build:cjs":"tsc -p tsconfig.cjs.json","build:dist-types":"node -e \"const fs=require('node:fs'); fs.mkdirSync('dist/cjs',{recursive:true}); fs.writeFileSync('dist/cjs/package.json', '{\\n  \\\"type\\\": \\\"commonjs\\\"\\n}\\n'); fs.mkdirSync('dist/esm',{recursive:true}); fs.writeFileSync('dist/esm/package.json', '{\\n  \\\"type\\\": \\\"module\\\"\\n}\\n');\"","build":"npm run clean && npm run build:esm && npm run build:cjs && npm run build:dist-types","verify:esm":"node --input-type=module -e \"import('./dist/esm/index.js').then(() => { console.log('esm:ok'); })\"","verify:cjs":"node -e \"require('./dist/cjs/index.js'); console.log('cjs:ok');\"","verify:modules":"npm run build && npm run verify:esm && npm run verify:cjs"},"devDependencies":{"@types/crypto-js":"^4.2.2","@types/debug":"^4.1.13","@types/jest":"^30.0.0","@types/node":"^26.2.0","jest":"^30.4.2","ts-jest":"^29.4.11","typescript":"^6.0.3"},"peerDependencies":{"mongoose":"^9.7.4","@bcibibi/y-sync-server":"^1.0.4","@bcibibi/y-sync-client":"^1.0.4","yjs":"^13.6.31"},"dependencies":{"p-debounce":"^5.1.0","debug":"^4.4.3","@bcibibi/y-utils":"^1.0.4"},"gitHead":"02272b05485da17e032c94668a58d357180f84e6","_id":"@bcibibi/y-sync-middleware-mongoose@1.0.4","_nodeVersion":"24.20.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-ramfHWRusxKVD6wuNmULR7iBxKBAlroF08VJXN4R4jT/VTXt3kQLO+hlrKj8Ku5/Z5qfFuyCwNsGF4cmHaSx7Q==","shasum":"53ff1bdb7fec65aa4316227b748111cdf8d13a67","tarball":"https://registry.npmjs.org/@bcibibi/y-sync-middleware-mongoose/-/y-sync-middleware-mongoose-1.0.4.tgz","fileCount":22,"unpackedSize":23553,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@bcibibi%2fy-sync-middleware-mongoose@1.0.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBUPGjgQQbdLad5kdb38JPJFBBVa1HKzox0PLIqp/N2jAiEA6r2drB2wsoU9S+vF3+lW61u6Iz751EdwR1+wEuuFfdM="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:f0e439ad-ec40-4ed3-929c-7d2b0504d85f"}},"directories":{},"maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/y-sync-middleware-mongoose_1.0.4_1788619230235_0.7325542003790866"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-26T09:21:05.577Z","modified":"2026-09-05T14:40:30.748Z","1.0.0":"2026-07-26T09:21:05.867Z","1.0.1":"2026-08-26T06:53:19.669Z","1.0.2":"2026-08-29T06:15:10.001Z","1.0.3":"2026-08-29T18:35:38.280Z","1.0.4":"2026-09-05T14:40:30.393Z"},"bugs":{"url":"https://github.com/bcibibi/y-sync/issues"},"author":{"name":"bcibibi"},"license":"MIT","homepage":"https://github.com/bcibibi/y-sync/tree/main/middleware/mongoose#readme","keywords":["yjs","mongoose","sync","collaboration"],"repository":{"type":"git","url":"git+https://github.com/bcibibi/y-sync.git"},"description":"Y server and client for syncing Yjs documents over Mongoose","maintainers":[{"name":"bcibi","email":"benoit.cibillon@gmail.com"}],"readme":"# @bcibibi/y-sync-middleware-mongoose\n\n> Beta: this package is currently in beta and APIs/behavior may evolve.\n\nMongoose middleware to plug persistence for collaborative Yjs documents.\n\n## Installation\n\n```bash\nnpm install @bcibibi/y-sync-middleware-mongoose mongoose yjs\n```\n\n## Available Exports\n\n- `@bcibibi/y-sync-middleware-mongoose/client`\n- `@bcibibi/y-sync-middleware-mongoose/middleware`\n\n## Server Middleware Usage\n\nRegister your Mongoose models before creating the y-sync server. The middleware reads the model name and document id from the Yjs document metadata, loads the MongoDB document when it is created, and saves later updates back to MongoDB.\n\n```ts\nimport { createServer } from 'node:http'\nimport mongoose from 'mongoose'\nimport { YSyncServer } from '@bcibibi/y-sync-server'\nimport { ySyncMongooseMiddleware } from '@bcibibi/y-sync-middleware-mongoose/middleware'\n\nawait mongoose.connect(process.env.MONGODB_URI!)\n\nmongoose.model('Article', new mongoose.Schema({\n\ttitle: String,\n\tcontent: String\n}))\n\nconst httpServer = createServer()\nconst syncServer = new YSyncServer(httpServer)\n\nsyncServer.use(ySyncMongooseMiddleware({\n\twait: 1_000\n}))\n\nhttpServer.listen(1234)\n```\n\nUse the matching client to create a document with the required `model` and `id` metadata:\n\n```ts\nimport { YSyncMongoose } from '@bcibibi/y-sync-middleware-mongoose/client'\n\nconst client = new YSyncMongoose('ws://localhost:1234/ysync')\nconst article = await client.getMongooseDocument('Article', 'YOUR_MONGODB_DOCUMENT_ID')\n\narticle.set('title', 'Updated title')\n```\n\nThe document must exist in MongoDB before the first client connection. On `create`, the middleware retrieves it and populates the Yjs map. On `update`, it writes the map's JSON representation with `model.updateOne({ _id: id }, data)` after the configured delay.\n\n## Middleware Options\n\nPass options to `ySyncMongooseMiddleware(options)`:\n\n- `wait?: number`: debounce delay in milliseconds before persisting an update. Defaults to `3000`.\n- `object?: ToObjectOptions`: options passed to Mongoose's `document.toObject()`. Defaults flatten `ObjectId`, UUID, and map values, and remove the version key.\n- `create?: (model, doc, transaction) => void | Promise<void>`: callback after a Mongoose document has been loaded into the Yjs map.\n- `update?: (model, doc, transaction) => void | Promise<void>`: callback before an updated Yjs map is persisted.\n\nUse the provided `transaction` callback for every Yjs mutation performed in `create` or `update` callbacks:\n\n```ts\nconst middleware = ySyncMongooseMiddleware({\n\twait: 1_000,\n\tcreate: (_model, doc, transaction) => {\n\t\ttransaction(() => {\n\t\t\tdoc.set('loadedAt', new Date().toISOString())\n\t\t})\n\t},\n\tupdate: async (model, doc) => {\n\t\tconsole.log(`Saving ${model.modelName}:`, doc.toJSON())\n\t}\n})\n\nsyncServer.use(middleware)\n```\n\n## Yjs Override Details\n\nThis module relies on Yjs runtime overrides from `@bcibibi/y-utils/override`.\n\nWhy it matters:\n\n- the middleware uses `Y.Map#setObject(...)` to map Mongoose objects into Yjs,\n- typed conversions (`string`, `number`, `boolean`, `Date`, arrays, nested objects) depend on those overrides,\n- `toJSON()` returns normalized plain values expected for MongoDB updates.\n\nGood news: both entrypoints import overrides automatically:\n\n- `@bcibibi/y-sync-middleware-mongoose/client`\n- `@bcibibi/y-sync-middleware-mongoose/middleware`\n\nYou only need a manual import if you use Yjs helpers directly outside these entrypoints:\n\n```ts\nimport '@bcibibi/y-utils/override'\n```\n","readmeFilename":"README.md"}