From 4ee0fdd206fddd9874bb8ca6c2784f2c751ce40b Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Fri, 28 Nov 2025 10:57:22 -0300 Subject: [PATCH] FEATURE: Add deferrable functions to meteor.d.ts --- packages/meteor/meteor.d.ts | 57 ++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/packages/meteor/meteor.d.ts b/packages/meteor/meteor.d.ts index d14ec0d1ef..9edb9cff6d 100644 --- a/packages/meteor/meteor.d.ts +++ b/packages/meteor/meteor.d.ts @@ -1,6 +1,6 @@ -import { Mongo } from 'meteor/mongo'; -import { EJSONable, EJSONableProperty } from 'meteor/ejson'; -import { DDP } from 'meteor/ddp'; +import { Mongo } from "meteor/mongo"; +import { EJSONable, EJSONableProperty } from "meteor/ejson"; +import { DDP } from "meteor/ddp"; export type global_Error = Error; @@ -21,7 +21,7 @@ export namespace Meteor { var release: string; var meteorRelease: string; - + interface ErrorConstructor { new (...args: any[]): Error; errorType: string; @@ -181,7 +181,13 @@ export namespace Meteor { | EJSONable[] | EJSONableProperty | EJSONableProperty[] - >(name: string, ...args: any[]): Promise & { stubPromise: Promise, serverPromise: Promise }; + >( + name: string, + ...args: any[] + ): Promise & { + stubPromise: Promise; + serverPromise: Promise; + }; interface MethodApplyOptions< Result extends @@ -261,7 +267,10 @@ export namespace Meteor { error: global_Error | Meteor.Error | undefined, result?: Result ) => void - ): Promise & { stubPromise: Promise, serverPromise: Promise }; + ): Promise & { + stubPromise: Promise; + serverPromise: Promise; + }; /** Method **/ /** Url **/ @@ -317,6 +326,28 @@ export namespace Meteor { * @param func The function to run */ function defer(func: Function): void; + + /** + * Wrap a function so that it only runs in the specified environments. + * @param func The function to wrap + * @param options An object with an `on` property that is an array of environment names: `"development"`, `"production"`, and/or `"test"`. + */ + function deferrable( + func: T, + options: { on: Array<"development" | "production" | "test"> } + ): T | void; + + /** + * Wrap a function so that it only runs in development environment. + * @param func The function to wrap + */ + function deferDev(func: T): T | void; + + /** + * Wrap a function so that it only runs in production environment. + * @param func The function to wrap + */ + function deferProd(func: T): T | void; /** Timeout **/ /** utils **/ @@ -336,7 +367,10 @@ export namespace Meteor { * @param func A function that takes a callback as its final parameter * @param context Optional `this` object against which the original function will be invoked */ - function wrapAsync(func: T, context?: ThisParameterType): Function; + function wrapAsync( + func: T, + context?: ThisParameterType + ): Function; function bindEnvironment(func: TFunc): TFunc; @@ -396,7 +430,7 @@ export namespace Meteor { * others can be set using Meteor's standard OAuth login parameters */ loginUrlParameters?: { include_granted_scopes: boolean; - }, + }; }, callback?: (error?: global_Error | Meteor.Error | Meteor.TypedError) => void ): void; @@ -440,7 +474,6 @@ export namespace Meteor { ): void; /** Login **/ - /** Connection **/ function reconnect(): void; @@ -518,7 +551,11 @@ export interface Subscription { * @param fields The fields in the document that have changed, together with their new values. If a field is not present in `fields` it was left unchanged; if it is present in `fields` and * has a value of `undefined` it was removed from the document. If `_id` is present it is ignored. */ - changed(collection: string, id: string, fields: Record): void; + changed( + collection: string, + id: string, + fields: Record + ): void; /** Access inside the publish function. The incoming connection for this subscription. */ connection: Meteor.Connection; /**