From c16cb55685ea858f9f2d191630072fd6b4eef513 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Thu, 24 Jul 2025 17:11:31 -0300 Subject: [PATCH] DOCS: Add addSharedPublication to meteor-rpc docs --- v3-docs/docs/community-packages/meteor-rpc.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/v3-docs/docs/community-packages/meteor-rpc.md b/v3-docs/docs/community-packages/meteor-rpc.md index 683a98be16..3c3e5b5554 100644 --- a/v3-docs/docs/community-packages/meteor-rpc.md +++ b/v3-docs/docs/community-packages/meteor-rpc.md @@ -175,6 +175,37 @@ Meteor.publish("chatRooms", function () { ::: +### module.addSharedPublication + +`addSharedPublication(name: string, schema: ZodSchema, handler: (args: ZodTypeInput) => Array> | Promise>> )` + +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.