mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
DOCS: Add addSharedPublication to meteor-rpc docs
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user