meteor/agent-skills

meteor-methods

Use when authoring or debugging Meteor methods (Meteor.methods, Meteor.call, Meteor.callAsync).

소스 보기
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

Meteor methods

Methods are Meteor's primitive for server-side mutation called from the client. In Meteor 3 they are async on the server. Latency compensation still works via client-side stubs.

Decision flow

  1. Is this code mutating server data? Use a method.
  2. Does the client need to read the result before the server replies? Write

a client stub with the same name; it mutates the local Minimongo collection and the change is reverted if the server disagrees.

  1. Does the method accept untrusted input? Validate every argument with

check(). Otherwise the agent should refuse to write the method.

  1. Is the method rate-sensitive? Add a DDPRateLimiter.addRule.

Scaffold

javascript
import { Meteor } from "meteor/meteor";
import { check, Match } from "meteor/check";

Meteor.methods({
  async addItem(payload) {
    check(payload, {
      title: String,
      qty: Match.Integer,
    });
    if (!this.userId) {
      throw new Meteor.Error("not-authorized");
    }
    const _id = await Items.insertAsync({
      ...payload,
      ownerId: this.userId,
      createdAt: new Date(),
    });
    return _id;
  },
});

Calling from the client

javascript
try {
  const id = await Meteor.callAsync("addItem", { title: "Hi", qty: 1 });
  setLocalId(id);
} catch (err) {
  if (err && typeof err === "object" && "error" in err) {
    console.error(err.error, err.reason, err.details);
  } else {
    console.error("local or transport failure", err);
  }
}

Optimistic UI

Define the same method on the client. The client stub runs immediately against the local Minimongo; the server's authoritative result reverts any divergence.

javascript
// client/methods.js
import { Meteor } from "meteor/meteor";
import { Random } from "meteor/random";
Meteor.methods({
  addItem(payload) {
    Items.insert({
      ...payload,
      _id: Random.id(),
      ownerId: Meteor.userId(),
      createdAt: new Date(),
    });
  },
});

Synchronous stubs are simplest when they only need synchronous Minimongo. Async stubs are also supported by callAsync and are useful when the same method definition runs on client and server with *Async collection calls. An async stub may await microtask-based local work, but it must not wait on fetch, timers, IndexedDB, workers, or other browser macrotask APIs. Run external I/O outside the stub.

Rate limiting

javascript
import { DDPRateLimiter } from "meteor/ddp-rate-limiter";

DDPRateLimiter.addRule(
  {
    type: "method",
    name: "addItem",
    userId: (userId) => Boolean(userId),
  },
  5,        // operations
  10000,    // per 10s
);

Meteor 3.5+ permits async matcher functions for database-backed decisions. On Meteor 3.0 through 3.4, matchers must stay synchronous; use a fixed rule, precomputed synchronous state, or upgrade instead of awaiting Mongo in a matcher.

Meteor awaits async matchers sequentially on the incoming connection's message queue. Project only required fields and keep the lookup fast. A rejected matcher Promise errors the invocation; test that path explicitly.

See references/rate-limiting.md for the rule-object schema and per-connection vs per-user keys.

Error handling

Throw Meteor.Error(code, reason, details?) for an intentional client-visible failure. A plain Error is logged on the server and sanitized for the client as Meteor.Error(500, "Internal server error"); its original message and stack are not exposed. Meteor.Error carries its code, reason, and details. Do not assume every callAsync rejection has that shape: callback misuse, transport failures, and local stub exceptions can produce native or arbitrary errors. Narrow the caught value before reading Meteor-specific fields.

Anti-patterns

  • Methods without check() on every argument. Reject the method in code

review.

  • Reusing a method for both authenticated and unauthenticated calls. Split

into two methods.

  • Awaiting browser macrotask APIs such as fetch or timers inside a client

stub. Async stubs are valid, but those APIs let unrelated code run before the optimistic simulation finishes.

  • Calling Meteor.user() inside an async method body. Use this.userId.

See also

  • references/check-and-validate.md
  • references/rate-limiting.md
  • references/eval-cases.md
같은 저장소의 Skills

더 많은 Skills

모든 Skills
meteor
커뮤니티

meteor-community-packages

Use when choosing, evaluating, adopting, configuring, or debugging a package from Meteor's documented community catalog, or moving from a community package to a promoted core package such as roles. Triggers on community package recommendations, Atmosphere vs npm selection, Packosphere maintenance checks, jam: helpers, Meteor.publish.once, Meteor.publish.stream, meteor-rpc, Wormhole, cluster, mail-preview, meteor add --search, or adopting a Git-hosted Atmosphere package. Use this skill when the user asks which maintained package fits or how its documented integration works. Route Meteor 2-to-3 package failures to migrate-to-meteor-3 and underlying core API design to its owning skill.

설치 수
1
GitHub Stars
9
업데이트
9월 11일
meteor
커뮤니티

meteor-debugging

Use when diagnosing an unexplained failure in a Meteor 3 application before the failing layer or fix is known. Triggers on server crashes, client-only errors, stuck subscriptions, DDP or WebSocket disconnects, Minimongo/server data mismatches, hanging or flaky tests, slow builds, --inspect, console.log, .only, Playwright traces, or requests to debug a Meteor app. Use this skill when evidence must distinguish Meteor tool, server, client, data, test, browser, mobile, or production boundaries. For test setup and authoring use meteor-testing; after confirming a domain cause, hand the repair to the owning skill.

설치 수
1
GitHub Stars
9
업데이트
9월 11일
meteor
커뮤니티

meteor-deployment

Use when deploying a Meteor 3 application. Triggers on meteor build, meteor deploy, Galaxy Push to Deploy, Galaxy Mode, Repository Mode, DEPLOYHOSTNAME, Docker, Kubernetes, settings.json, METEORSETTINGS, MONGOURL, MONGOOPLOGURL, ROOTURL, PORT, HTTPFORWARDEDCOUNT, NODEOPTIONS, health checks, pre-deploy commands, hot code push, --architecture os.linux.x8664, --server-only, or a deployed Node.js version mismatch. Use this skill when the user asks about shipping the app, asks about production config, or asks about containerizing. For Cordova Android/iOS artifacts, signing, and native HCP compatibility use meteor-native; this skill owns the backend deployment.

설치 수
1
GitHub Stars
9
업데이트
9월 11일
meteor
커뮤니티

meteor-modern-build-stack

Use when configuring or tuning the Meteor 3 modern build stack: SWC transpiler, SWC-based minifier, modern @parcel/watcher, web-arch skipping in development, .meteorignore, and the Rspack bundler integration via the rspack Atmosphere package. Triggers on package.json "meteor": { "modern": true }, .swcrc, swc.config.js, [Transpiler] Used Babel Fallback logs, rspack.config.js, rspack.config.ts, defineConfig from @meteorjs/rspack, Meteor.compileWith helpers, Meteor.extendConfig, Meteor.extendSwcConfig vs Meteor.replaceSwcConfig, Meteor.splitVendorChunk, Meteor.persistDevFiles, Meteor.disablePlugins, Meteor.enablePortableBuild, HtmlRspackPlugin customization, RSPACKDEVSERVERPORT, TOOLNODEFLAGS, pnpm workspaces, Rspack 2, skeleton selection, PWA, Workbox and service-worker build setup. Use this skill when the user asks about SWC vs Babel or Rspack configuration. Route existing-app bundler migration to migrate-to-rspack, Blaze PWA scaffolding to meteor-blaze, and jam:offline data to meteor-community-packages.

설치 수
1
GitHub Stars
9
업데이트
9월 11일