DOCS: Add addSharedPublication to meteor-rpc docs

This commit is contained in:
Gabriel Grubba
2025-07-24 17:11:31 -03:00
parent e7d0884324
commit c16cb55685

View File

@@ -175,6 +175,37 @@ Meteor.publish("chatRooms", function () {
:::
### module.addSharedPublication
`addSharedPublication(name: string, schema: ZodSchema, handler: (args: ZodTypeInput<ZodSchema>) => Array<Mongo.Cursor<any>> | Promise<Array<Mongo.Cursor<any>>> )`
This is similar to `addPublication`, but it allows you to create an array of cursors, which can be useful for shared queries that need to return multiple collections or different queries.
```typescript [server/chat.ts]
// server/main.ts
import { createModule } from "meteor-rpc";
import { ChatCollection } from "/imports/api/chat";
import { UserCollection } from "/imports/api/user";
import { z } from "zod";
const server = createModule();
server.addSharedPublication("chatRooms", z.string(), (userId) => {
return [ChatCollection.find({ userId }), UserCollection.find({ userId })];
});
server.build();
// is the same as
import { Meteor } from "meteor/meteor";
import { ChatCollection } from "/imports/api/chat";
import { UserCollection } from "/imports/api/user";
import { check } from "meteor/check";
Meteor.publish("chatRooms", function (userId) {
check(userId, String);
return [ChatCollection.find({ userId }), UserCollection.find({ userId })];
});
```
### `module.addSubmodule`
This is used to add a submodule to the main module, adding namespaces for your methods and publications and making it easier to organize your code.