Module: Parse

Defined in:
lib/parse/agent.rb,
lib/parse/query.rb,
lib/parse/stack.rb,
lib/parse/client.rb,
lib/parse/schema.rb,
lib/parse/api/all.rb,
lib/parse/mongodb.rb,
lib/parse/api/push.rb,
lib/parse/webhooks.rb,
lib/parse/acl_scope.rb,
lib/parse/api/batch.rb,
lib/parse/api/files.rb,
lib/parse/api/hooks.rb,
lib/parse/api/users.rb,
lib/parse/clp_scope.rb,
lib/parse/model/acl.rb,
lib/parse/model/clp.rb,
lib/parse/api/config.rb,
lib/parse/api/schema.rb,
lib/parse/api/server.rb,
lib/parse/live_query.rb,
lib/parse/live_query.rb,
lib/parse/model/date.rb,
lib/parse/model/file.rb,
lib/parse/model/push.rb,
lib/parse/agent/tools.rb,
lib/parse/api/objects.rb,
lib/parse/model/bytes.rb,
lib/parse/model/email.rb,
lib/parse/model/model.rb,
lib/parse/model/phone.rb,
lib/parse/stack/tasks.rb,
lib/parse/agent/errors.rb,
lib/parse/api/sessions.rb,
lib/parse/atlas_search.rb,
lib/parse/client/batch.rb,
lib/parse/model/object.rb,
lib/parse/query/cursor.rb,
lib/parse/agent/prompts.rb,
lib/parse/api/aggregate.rb,
lib/parse/api/analytics.rb,
lib/parse/model/geojson.rb,
lib/parse/model/pointer.rb,
lib/parse/model/polygon.rb,
lib/parse/stack/railtie.rb,
lib/parse/stack/version.rb,
lib/parse/agent/describe.rb,
lib/parse/client/caching.rb,
lib/parse/client/logging.rb,
lib/parse/client/request.rb,
lib/parse/model/geopoint.rb,
lib/parse/query/ordering.rb,
lib/parse/client/protocol.rb,
lib/parse/client/response.rb,
lib/parse/lookup_rewriter.rb,
lib/parse/model/time_zone.rb,
lib/parse/query/operation.rb,
lib/parse/two_factor_auth.rb,
lib/parse/agent/mcp_client.rb,
lib/parse/agent/mcp_server.rb,
lib/parse/api/path_segment.rb,
lib/parse/client/profiling.rb,
lib/parse/live_query/event.rb,
lib/parse/query/constraint.rb,
lib/parse/webhooks/payload.rb,
lib/parse/live_query/client.rb,
lib/parse/model/core/errors.rb,
lib/parse/model/core/schema.rb,
lib/parse/model/validations.rb,
lib/parse/pipeline_security.rb,
lib/parse/query/constraints.rb,
lib/parse/agent/mcp_rack_app.rb,
lib/parse/agent/metadata_dsl.rb,
lib/parse/agent/rate_limiter.rb,
lib/parse/live_query/logging.rb,
lib/parse/model/classes/role.rb,
lib/parse/model/classes/user.rb,
lib/parse/model/core/actions.rb,
lib/parse/model/core/actions.rb,
lib/parse/model/core/builder.rb,
lib/parse/api/cloud_functions.rb,
lib/parse/atlas_search/result.rb,
lib/parse/client/body_builder.rb,
lib/parse/model/core/describe.rb,
lib/parse/model/core/fetching.rb,
lib/parse/model/core/indexing.rb,
lib/parse/model/core/querying.rb,
lib/parse/agent/mcp_dispatcher.rb,
lib/parse/agent/metadata_audit.rb,
lib/parse/agent/relation_graph.rb,
lib/parse/atlas_search/session.rb,
lib/parse/client/authentication.rb,
lib/parse/model/classes/product.rb,
lib/parse/model/classes/session.rb,
lib/parse/model/core/properties.rb,
lib/parse/schema/index_migrator.rb,
lib/parse/webhooks/registration.rb,
lib/parse/agent/result_formatter.rb,
lib/parse/live_query/event_queue.rb,
lib/parse/model/classes/audience.rb,
lib/parse/model/core/create_lock.rb,
lib/parse/agent/metadata_registry.rb,
lib/parse/live_query/subscription.rb,
lib/parse/model/core/field_guards.rb,
lib/parse/agent/cancellation_token.rb,
lib/parse/agent/pipeline_validator.rb,
lib/parse/live_query/configuration.rb,
lib/parse/model/classes/job_status.rb,
lib/parse/live_query/health_monitor.rb,
lib/parse/model/classes/push_status.rb,
lib/parse/query/n_plus_one_detector.rb,
lib/parse/atlas_search/index_manager.rb,
lib/parse/live_query/circuit_breaker.rb,
lib/parse/model/associations/has_one.rb,
lib/parse/model/classes/installation.rb,
lib/parse/model/classes/job_schedule.rb,
lib/parse/model/core/parse_reference.rb,
lib/parse/model/core/search_indexing.rb,
lib/parse/webhooks/replay_protection.rb,
lib/parse/agent/constraint_translator.rb,
lib/parse/atlas_search/search_builder.rb,
lib/parse/model/associations/has_many.rb,
lib/parse/schema/search_index_migrator.rb,
lib/parse/model/associations/belongs_to.rb,
lib/parse/two_factor_auth/user_extension.rb,
lib/parse/model/associations/collection_proxy.rb,
lib/parse/model/core/enhanced_change_tracking.rb,
lib/parse/model/validations/uniqueness_validator.rb,
lib/parse/model/associations/pointer_collection_proxy.rb,
lib/parse/model/associations/relation_collection_proxy.rb

Overview

Note: Do not require “../object” here - this file is loaded from object.rb and adding that require would create a circular dependency.

Defined Under Namespace

Modules: ACLScope, API, Associations, AtlasSearch, CLPScope, Core, CreateLock, Generated, GeoJSON, LiveQuery, LookupRewriter, MFA, Middleware, MongoDB, PipelineSecurity, Properties, Protocol, RegexSecurity, Schema, Stack, Validations Classes: ACL, Agent, Aggregation, AggregationResult, Audience, AutofetchTriggeredError, BatchOperation, Bytes, CLP, Client, CollectionProxy, Constraint, CreateLockInvalidKey, CreateLockTimeoutError, CreateLockUnavailableError, Cursor, DataType, Date, Email, Error, File, GeoPoint, GroupBy, GroupByDate, GroupedResult, Hyperdrive, Installation, JobSchedule, JobStatus, Model, NPlusOneDetector, NPlusOneQueryError, Object, Operation, Order, Phone, Pointer, PointerCollectionProxy, Polygon, Product, Push, PushStatus, Query, RecordNotSaved, RelationAction, RelationCollectionProxy, Request, Response, Role, Session, SortableGroupBy, SortableGroupByDate, TimeZone, UnfetchedFieldAccessError, User, Webhooks

Constant Summary collapse

MASTER_KEY_STATE_KEY =

Fiber-local key consulted by the authentication middleware. A truthy entry suppresses the master-key header for the duration of the block set by without_master_key; a :enabled entry forces the master-key header back on inside a nested with_master_key block.

:__parse_master_key_state__

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.autofetch_raise_on_missing_keysObject

Returns the value of attribute autofetch_raise_on_missing_keys.



285
286
287
# File 'lib/parse/stack.rb', line 285

def autofetch_raise_on_missing_keys
  @autofetch_raise_on_missing_keys
end

.cache_write_on_fetchObject

Returns the value of attribute cache_write_on_fetch.



285
286
287
# File 'lib/parse/stack.rb', line 285

def cache_write_on_fetch
  @cache_write_on_fetch
end

.default_query_cacheObject

Returns the value of attribute default_query_cache.



285
286
287
# File 'lib/parse/stack.rb', line 285

def default_query_cache
  @default_query_cache
end

.live_query_enabledObject

Returns the value of attribute live_query_enabled.



285
286
287
# File 'lib/parse/stack.rb', line 285

def live_query_enabled
  @live_query_enabled
end

.loggingBoolean

Sets Parse::Middleware::BodyBuilder logging. You may specify ‘:debug` for additional verbosity.

Returns:

  • (Boolean)


19
20
21
# File 'lib/parse/client/body_builder.rb', line 19

def self.logging
  Parse::Middleware::BodyBuilder.logging
end

.mcp_remote_apiObject

Returns the value of attribute mcp_remote_api.



285
286
287
# File 'lib/parse/stack.rb', line 285

def mcp_remote_api
  @mcp_remote_api
end

.mcp_server_enabledObject

Returns the value of attribute mcp_server_enabled.



285
286
287
# File 'lib/parse/stack.rb', line 285

def mcp_server_enabled
  @mcp_server_enabled
end

.mcp_server_portObject

Returns the value of attribute mcp_server_port.



285
286
287
# File 'lib/parse/stack.rb', line 285

def mcp_server_port
  @mcp_server_port
end

.rewrite_lookupsObject

Returns the value of attribute rewrite_lookups.



285
286
287
# File 'lib/parse/stack.rb', line 285

def rewrite_lookups
  @rewrite_lookups
end

.serialize_only_fetched_fieldsObject

Returns the value of attribute serialize_only_fetched_fields.



285
286
287
# File 'lib/parse/stack.rb', line 285

def serialize_only_fetched_fields
  @serialize_only_fetched_fields
end

.strict_pointer_shapesObject

Returns the value of attribute strict_pointer_shapes.



285
286
287
# File 'lib/parse/stack.rb', line 285

def strict_pointer_shapes
  @strict_pointer_shapes
end

.strict_property_redefinitionObject

Returns the value of attribute strict_property_redefinition.



285
286
287
# File 'lib/parse/stack.rb', line 285

def strict_property_redefinition
  @strict_property_redefinition
end

.synchronize_classesObject

Returns the value of attribute synchronize_classes.



285
286
287
# File 'lib/parse/stack.rb', line 285

def synchronize_classes
  @synchronize_classes
end

.synchronize_create_defaultObject

Returns the value of attribute synchronize_create_default.



285
286
287
# File 'lib/parse/stack.rb', line 285

def synchronize_create_default
  @synchronize_create_default
end

.synchronize_create_optionsObject

Returns the value of attribute synchronize_create_options.



285
286
287
# File 'lib/parse/stack.rb', line 285

def synchronize_create_options
  @synchronize_create_options
end

.synchronize_create_secretObject

Returns the value of attribute synchronize_create_secret.



285
286
287
# File 'lib/parse/stack.rb', line 285

def synchronize_create_secret
  @synchronize_create_secret
end

.synchronize_create_storeObject

Returns the value of attribute synchronize_create_store.



285
286
287
# File 'lib/parse/stack.rb', line 285

def synchronize_create_store
  @synchronize_create_store
end

.validate_query_keysObject

Returns the value of attribute validate_query_keys.



285
286
287
# File 'lib/parse/stack.rb', line 285

def validate_query_keys
  @validate_query_keys
end

.warn_on_query_issuesObject

Returns the value of attribute warn_on_query_issues.



285
286
287
# File 'lib/parse/stack.rb', line 285

def warn_on_query_issues
  @warn_on_query_issues
end

Class Method Details

.auto_generate_models!Array

Create all Parse::Object subclasses, including their properties and inferred associations by importing the schema for the remote collections in a Parse application. Uses the default configured client.

Returns:

  • (Array)

    an array of created Parse::Object subclasses.

See Also:



16
17
18
19
20
# File 'lib/parse/model/core/builder.rb', line 16

def self.auto_generate_models!
  Parse.schemas.map do |schema|
    Parse::Model::Builder.build!(schema)
  end
end

.auto_upgrade!Object

Perform a non-destructive upgrade of all your Parse schemas in the backend based on the property definitions of your local Object subclasses.



69
70
71
72
73
74
75
# File 'lib/parse/model/object.rb', line 69

def self.auto_upgrade!
  klassModels = Parse::Object.descendants
  klassModels.sort_by(&:parse_class).each do |klass|
    yield(klass) if block_given?
    klass.auto_upgrade!
  end
end

.batch(reqs = nil) ⇒ BatchOperation

Create a new batch operation.

Parameters:

Returns:



11
12
13
# File 'lib/parse/client/batch.rb', line 11

def self.batch(reqs = nil)
  BatchOperation.new(reqs)
end

.cacheMoneta::Transformer, Moneta::Expires

The shared cache for the default client connection. This is useful if you want to also utilize the same cache store for other purposes in your application. This should normally be a Moneta unified cache interface.

Returns:

  • (Moneta::Transformer, Moneta::Expires)

    the cache instance

See Also:



173
174
175
# File 'lib/parse/client.rb', line 173

def self.cache
  @shared_cache ||= Parse::Client.client(:default).cache
end

.call_function(name, body = {}, **opts) ⇒ Object

Helper method to call cloud functions and get results.

Parameters:

  • name (String)

    the name of the cloud code function to call.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the function.

  • opts (Hash)

    additional options.

Options Hash (**opts):

  • :session_token (String)

    The session token for authenticated requests.

  • :session (Symbol)

    The client connection to use (alternative to :client).

  • :client (Symbol)

    The client connection to use.

  • :raw (Boolean)

    Whether to return the raw response object.

  • :master_key (Boolean)

    Whether to use the master key for this request.

Returns:

  • (Object)

    the result data of the response. nil if there was an error.



1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/parse/client.rb', line 1047

def self.call_function(name, body = {}, **opts)
  conn = opts[:session] || opts[:client] || :default

  # Extract request options for the API call
  request_opts = {}
  request_opts[:session_token] = opts[:session_token] if opts[:session_token]
  request_opts[:master_key] = opts[:master_key] if opts[:master_key]

  response = Parse::Client.client(conn).call_function(name, body, opts: request_opts)
  return response if opts[:raw].present?
  if response.error?
    Parse::Client._safe_warn("CloudCodeError", response, name: name)
    return nil
  end
  _extract_cloud_result(response)
end

.call_function!(name, body = {}, **opts) ⇒ Object

Same as call_function but raises Parse::Error::CloudCodeError when the cloud function returns an error instead of silently returning nil. HTTP-level errors (auth, timeouts, throttling, etc.) still raise their specific Error subclasses as the underlying client does.

Parameters:

  • opts (see Parse.call_function)

    — :raw is ignored.

  • name (String)

    the name of the cloud code function to call.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the function.

Returns:

  • (Object)

    the result data of the response.

Raises:



1073
1074
1075
1076
1077
# File 'lib/parse/client.rb', line 1073

def self.call_function!(name, body = {}, **opts)
  response = call_function(name, body, **opts.merge(raw: true))
  raise Parse::Error::CloudCodeError.new(name, response) if response.error?
  _extract_cloud_result(response)
end

.call_function_with_session(name, body = {}, session_token, **opts) ⇒ Object

Helper method to call cloud functions with a session token. This is a convenience method that ensures proper session token handling.

Parameters:

  • name (String)

    the name of the cloud code function to call.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the function.

  • session_token (String)

    the session token for authenticated requests.

  • opts (Hash)

    additional options (same as call_function).

Returns:

  • (Object)

    the result data of the response. nil if there was an error.



1086
1087
1088
1089
# File 'lib/parse/client.rb', line 1086

def self.call_function_with_session(name, body = {}, session_token, **opts)
  opts[:session_token] = session_token
  call_function(name, body, **opts)
end

.call_function_with_session!(name, body = {}, session_token, **opts) ⇒ Object

Same as call_function_with_session but raises Parse::Error::CloudCodeError when the cloud function returns an error instead of silently returning nil.

Parameters:

  • name (String)

    the name of the cloud code function to call.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the function.

  • session_token (String)

    the session token for authenticated requests.

  • opts (Hash)

    additional options (same as call_function).

Returns:

  • (Object)

    the result data of the response.

Raises:



1100
1101
1102
1103
# File 'lib/parse/client.rb', line 1100

def self.call_function_with_session!(name, body = {}, session_token, **opts)
  opts[:session_token] = session_token
  call_function!(name, body, **opts)
end

.classify(className) ⇒ Class

Find a corresponding Parse::Object subclass for this string or symbol

Parameters:

  • className (String)

    The name of the Parse class as string (ex. “_User”)

Returns:

  • (Class)

    The proper subclass matching the className.



15
16
17
# File 'lib/parse/model/model.rb', line 15

def self.classify(className)
  Parse::Model.find_class className.to_parse_class
end

.clear_n_plus_one_callbacks!Object

Clear N+1 detection callbacks



392
393
394
# File 'lib/parse/query/n_plus_one_detector.rb', line 392

def clear_n_plus_one_callbacks!
  NPlusOneDetector.clear_callbacks!
end

.clear_profiles!Object

Clear all stored profiles



160
161
162
# File 'lib/parse/client/profiling.rb', line 160

def clear_profiles!
  Middleware::Profiling.clear_profiles!
end

.clear_profiling_callbacks!Object

Clear all profiling callbacks



177
178
179
# File 'lib/parse/client/profiling.rb', line 177

def clear_profiling_callbacks!
  Middleware::Profiling.clear_callbacks!
end

.client(conn = :default) ⇒ Parse::Client

Helper method to get the default Parse client.

Parameters:

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use. Defaults to :default

Returns:



163
164
165
# File 'lib/parse/client.rb', line 163

def self.client(conn = :default)
  Parse::Client.client(conn)
end

.config(conn = :default) ⇒ Hash

Retrieve the App specific Parse configuration parameters. The configuration for a connection is cached after the first request. Use the bang version to force update from the Parse backend.

Examples:

val = Parse.config["myKey"]
val = Parse.config["myKey"] # cached

Parameters:

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use.

Returns:

  • (Hash)

    the Parse config hash for the session.

See Also:



91
92
93
# File 'lib/parse/client.rb', line 91

def self.config(conn = :default)
  Parse::Client.client(conn).config
end

.config!(conn = :default) ⇒ Hash

Force fetch updated Parse configuration

Parameters:

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use.

Returns:

  • (Hash)

    the Parse configuration



132
133
134
# File 'lib/parse/client.rb', line 132

def self.config!(conn = :default)
  Parse::Client.client(conn).config!
end

.config_entries(conn = :default, master: false) ⇒ Hash{String=>Hash}

Return every config entry zipped with its masterKeyOnly trait.

Examples:

Parse.config_entries
# => { "fieldA" => { value: "x", master_key_only: false } }
Parse.config_entries(master: true)
# => { "fieldA" => { value: "x", master_key_only: false },
#      "fieldB" => { value: 42,  master_key_only: true  } }

Parameters:

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use.

  • master (Boolean) (defaults to: false)

    when true, include master-key-only entries.

Returns:



146
147
148
# File 'lib/parse/client.rb', line 146

def self.config_entries(conn = :default, master: false)
  Parse::Client.client(conn).config_entries(master: master)
end

.configure_logging {|Middleware::Logging| ... } ⇒ Object

Configure Parse logging with a block

Examples:

Parse.configure_logging do |config|
  config.enabled = true
  config.log_level = :debug
  config.logger = Rails.logger
end

Yields:



289
290
291
# File 'lib/parse/client/logging.rb', line 289

def configure_logging
  yield Middleware::Logging if block_given?
end

.configure_mcp_remote_api(provider:, api_key:, model: nil, base_url: nil) ⇒ Hash

Configure MCP remote API connection

Parameters:

  • provider (Symbol)

    the API provider (:openai, :claude, :custom)

  • api_key (String)

    the API key

  • model (String) (defaults to: nil)

    the model to use (e.g., ‘gpt-4’, ‘claude-3-opus’)

  • base_url (String, nil) (defaults to: nil)

    optional custom base URL

Returns:

  • (Hash)

    the configuration hash



322
323
324
325
326
327
328
329
# File 'lib/parse/stack.rb', line 322

def configure_mcp_remote_api(provider:, api_key:, model: nil, base_url: nil)
  @mcp_remote_api = {
    provider: provider.to_sym,
    api_key: api_key,
    model: model,
    base_url: base_url,
  }
end

.configure_n_plus_one {|NPlusOneDetector| ... } ⇒ Object

Configure N+1 detection thresholds.

Examples:

Configure thresholds

Parse.configure_n_plus_one do |config|
  config.detection_window = 5.0   # 5 seconds
  config.fetch_threshold = 5      # 5 fetches to trigger
  config.cleanup_interval = 120.0 # cleanup every 2 minutes
end

Yields:



417
418
419
# File 'lib/parse/query/n_plus_one_detector.rb', line 417

def configure_n_plus_one
  yield NPlusOneDetector if block_given?
end

.live_query_enabled?Boolean

Check if LiveQuery feature is enabled

Returns:

  • (Boolean)


294
295
296
# File 'lib/parse/stack.rb', line 294

def live_query_enabled?
  @live_query_enabled == true
end

.log_levelSymbol

Returns the current log level.

Returns:

  • (Symbol)

    the current log level



254
255
256
# File 'lib/parse/client/logging.rb', line 254

def log_level
  Middleware::Logging.current_log_level
end

.log_level=(value) ⇒ Object

Set the log level for Parse requests

Examples:

Set debug level

Parse.log_level = :debug

Parameters:

  • value (Symbol)

    one of :info, :debug, :warn



246
247
248
249
250
251
# File 'lib/parse/client/logging.rb', line 246

def log_level=(value)
  unless [:info, :debug, :warn].include?(value)
    raise ArgumentError, "Invalid log level: #{value}. Use :info, :debug, or :warn"
  end
  Middleware::Logging.log_level = value
end

.log_max_body_lengthInteger

Returns the maximum body length.

Returns:

  • (Integer)

    the maximum body length



278
279
280
# File 'lib/parse/client/logging.rb', line 278

def log_max_body_length
  Middleware::Logging.current_max_body_length
end

.log_max_body_length=(value) ⇒ Object

Set the maximum body length to log before truncation

Parameters:

  • value (Integer)


273
274
275
# File 'lib/parse/client/logging.rb', line 273

def log_max_body_length=(value)
  Middleware::Logging.max_body_length = value.to_i
end

.loggerLogger

Returns the current logger.

Returns:

  • (Logger)

    the current logger



267
268
269
# File 'lib/parse/client/logging.rb', line 267

def logger
  Middleware::Logging.current_logger
end

.logger=(value) ⇒ Object

Set a custom logger for Parse requests

Examples:

Use Rails logger

Parse.logger = Rails.logger

Parameters:

  • value (Logger)


262
263
264
# File 'lib/parse/client/logging.rb', line 262

def logger=(value)
  Middleware::Logging.logger = value
end

.logging_enabledBoolean

Returns whether logging is enabled.

Returns:

  • (Boolean)

    whether logging is enabled



238
239
240
# File 'lib/parse/client/logging.rb', line 238

def logging_enabled
  Middleware::Logging.enabled
end

.logging_enabled=(value) ⇒ Object

Enable or disable request/response logging

Examples:

Enable logging

Parse.logging_enabled = true

Parameters:

  • value (Boolean)


233
234
235
# File 'lib/parse/client/logging.rb', line 233

def logging_enabled=(value)
  Middleware::Logging.enabled = value
end

.master_key_disabled?Boolean

Returns true if the current fiber is inside a without_master_key block. Consulted by the authentication middleware in addition to the per-request disable header.

Returns:

  • (Boolean)

    true if the current fiber is inside a without_master_key block. Consulted by the authentication middleware in addition to the per-request disable header.



79
80
81
# File 'lib/parse/stack.rb', line 79

def self.master_key_disabled?
  Fiber[MASTER_KEY_STATE_KEY] == :disabled
end

.master_key_only(conn = :default) ⇒ Hash{String=>Boolean}

Retrieve the masterKeyOnly flag map for the application configuration.

Examples:

Parse.master_key_only["secretKey"] # => true

Parameters:

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use.

Returns:

  • (Hash{String=>Boolean})

    map of config keys to masterKeyOnly flags, or an empty hash if the server did not return one.



156
157
158
# File 'lib/parse/client.rb', line 156

def self.master_key_only(conn = :default)
  Parse::Client.client(conn).master_key_only
end

.mcp_remote_api_configured?Boolean

Check if MCP remote API is configured

Returns:

  • (Boolean)


333
334
335
# File 'lib/parse/stack.rb', line 333

def mcp_remote_api_configured?
  @mcp_remote_api.is_a?(Hash) && @mcp_remote_api[:api_key].present?
end

.mcp_server_enabled?Boolean

Check if MCP server feature is enabled Requires PARSE_MCP_ENABLED=true in environment AND Parse.mcp_server_enabled = true

Returns:

  • (Boolean)


311
312
313
314
# File 'lib/parse/stack.rb', line 311

def mcp_server_enabled?
  return false unless ENV["PARSE_MCP_ENABLED"] == "true"
  @mcp_server_enabled == true
end

.n_plus_one_detection_windowFloat

Get the N+1 detection window

Returns:

  • (Float)


429
430
431
# File 'lib/parse/query/n_plus_one_detector.rb', line 429

def n_plus_one_detection_window
  NPlusOneDetector.detection_window
end

.n_plus_one_detection_window=(value) ⇒ Object

Set the N+1 detection window (time in seconds to track related fetches)

Parameters:

  • value (Float)


423
424
425
# File 'lib/parse/query/n_plus_one_detector.rb', line 423

def n_plus_one_detection_window=(value)
  NPlusOneDetector.detection_window = value
end

.n_plus_one_fetch_thresholdInteger

Get the N+1 fetch threshold

Returns:

  • (Integer)


441
442
443
# File 'lib/parse/query/n_plus_one_detector.rb', line 441

def n_plus_one_fetch_threshold
  NPlusOneDetector.fetch_threshold
end

.n_plus_one_fetch_threshold=(value) ⇒ Object

Set the N+1 fetch threshold (minimum fetches to trigger warning)

Parameters:

  • value (Integer)


435
436
437
# File 'lib/parse/query/n_plus_one_detector.rb', line 435

def n_plus_one_fetch_threshold=(value)
  NPlusOneDetector.fetch_threshold = value
end

.n_plus_one_modeSymbol

Get the current N+1 detection mode.

Returns:

  • (Symbol)

    :warn, :raise, or :ignore



352
353
354
# File 'lib/parse/query/n_plus_one_detector.rb', line 352

def n_plus_one_mode
  NPlusOneDetector.mode
end

.n_plus_one_mode=(value) ⇒ Object

Set the N+1 detection mode.

Examples:

Different modes

Parse.n_plus_one_mode = :warn   # Log warnings (default when enabled)
Parse.n_plus_one_mode = :raise  # Raise NPlusOneQueryError (for CI/tests)
Parse.n_plus_one_mode = :ignore # Disable detection

Parameters:

  • value (Symbol)

    :warn, :raise, or :ignore



346
347
348
# File 'lib/parse/query/n_plus_one_detector.rb', line 346

def n_plus_one_mode=(value)
  NPlusOneDetector.mode = value
end

.n_plus_one_summaryHash

Get N+1 detection summary

Returns:



403
404
405
# File 'lib/parse/query/n_plus_one_detector.rb', line 403

def n_plus_one_summary
  NPlusOneDetector.summary
end

.on_n_plus_one {|source_class, association, target_class, count, location| ... } ⇒ Object

Register a callback for N+1 detection events. Useful for custom logging or metrics collection. Callbacks are called regardless of mode (even in :ignore mode).

Examples:

Track N+1 patterns

Parse.on_n_plus_one do |source, assoc, target, count, location|
  MyMetrics.increment("n_plus_one.#{source}.#{assoc}")
end

Yields:

  • (source_class, association, target_class, count, location)


387
388
389
# File 'lib/parse/query/n_plus_one_detector.rb', line 387

def on_n_plus_one(&block)
  NPlusOneDetector.on_n_plus_one(&block)
end

.on_request_complete {|Hash| ... } ⇒ Object

Register a callback for request completion

Yields:

  • (Hash)

    profile data



172
173
174
# File 'lib/parse/client/profiling.rb', line 172

def on_request_complete(&block)
  Middleware::Profiling.on_request_complete(&block)
end

.profiling_enabledBoolean

Returns whether profiling is enabled.

Returns:

  • (Boolean)

    whether profiling is enabled



149
150
151
# File 'lib/parse/client/profiling.rb', line 149

def profiling_enabled
  Middleware::Profiling.enabled
end

.profiling_enabled=(value) ⇒ Object

Enable or disable request profiling

Parameters:

  • value (Boolean)


144
145
146
# File 'lib/parse/client/profiling.rb', line 144

def profiling_enabled=(value)
  Middleware::Profiling.enabled = value
end

.profiling_statisticsHash

Get profiling statistics

Returns:



166
167
168
# File 'lib/parse/client/profiling.rb', line 166

def profiling_statistics
  Middleware::Profiling.statistics
end

.recent_profilesArray<Hash>

Get recent profile data

Returns:



155
156
157
# File 'lib/parse/client/profiling.rb', line 155

def recent_profiles
  Middleware::Profiling.profiles
end

.registered_classesArray

Returns an array of registered Parse::Object subclasses.

Returns:

  • (Array)

    an array of registered Parse::Object subclasses.



50
51
52
# File 'lib/parse/model/object.rb', line 50

def self.registered_classes
  Parse::Object.descendants.map(&:parse_class).uniq
end

.reset_n_plus_one_tracking!Object

Reset N+1 detection tracking



397
398
399
# File 'lib/parse/query/n_plus_one_detector.rb', line 397

def reset_n_plus_one_tracking!
  NPlusOneDetector.reset!
end

.schema(className) ⇒ Hash

Fetch the schema for a specific collection name.

Parameters:

  • className (String)

    the name collection

Returns:

  • (Hash)

    the schema document of this collection.

See Also:

  • Parse::Core::ClassBuilder.build!


63
64
65
# File 'lib/parse/model/object.rb', line 63

def self.schema(className)
  client.schema(className).result
end

.schemasArray<Hash>

Returns the list of all schemas for this application.

Returns:

  • (Array<Hash>)

    the list of all schemas for this application.



55
56
57
# File 'lib/parse/model/object.rb', line 55

def self.schemas
  client.schemas.results
end

.set_config(field, value, conn = :default, master_key_only: nil) ⇒ Hash

Set a parameter in the Parse configuration for an application.

Examples:

# update a config with Parse
Parse.set_config "myKey", "someValue"
# mark a single key as master-key-only
Parse.set_config "myKey", "someValue", master_key_only: true

Parameters:

  • field (String)

    the name configuration variable.

  • value (Object)

    the value configuration variable. Only Parse types are supported.

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use.

  • master_key_only (Boolean, nil) (defaults to: nil)

    when not nil, sets the masterKeyOnly flag for ‘field` to the given boolean value in the same request.

Returns:

  • (Hash)

    the Parse config hash for the session.



107
108
109
110
# File 'lib/parse/client.rb', line 107

def self.set_config(field, value, conn = :default, master_key_only: nil)
  opts = master_key_only.nil? ? {} : { master_key_only: { field.to_s => !!master_key_only } }
  Parse::Client.client(conn).update_config({ field => value }, **opts)
end

.setup(opts = {}) { ... } ⇒ Client

Helper method that users should call to setup the client stack. A block can be passed in order to do additional client configuration. To connect to a Parse server, you will need a minimum of an application_id, an api_key and a server_url. To connect to the server endpoint, you use the setup method below.

Examples:

Parse.setup app_id: "YOUR_APP_ID",
            api_key: "YOUR_REST_API_KEY",
            master_key: "YOUR_MASTER_KEY", # optional
            server_url: 'https://localhost:1337/parse' #default

Parameters:

  • opts (Hash) (defaults to: {})

    a set of connection options to configure the client.

Options Hash (opts):

  • :server_url (String)

    The server url of your Parse Server if you are not using the hosted Parse service. By default it will use ENV if available, otherwise fallback to Parse::Protocol::SERVER_URL.

  • :app_id (String)

    The Parse application id. Defaults to ENV.

  • :api_key (String)

    Your Parse REST API Key. Defaults to ENV.

  • :master_key (String)

    The Parse application master key (optional). If this key is set, it will be sent on every request sent by the client and your models. Defaults to ENV.

  • :logging (Boolean, Symbol)

    Controls request/response logging.

    • ‘true` - Enable logging at :info level

    • ‘:debug` - Enable verbose logging with headers and body content

    • ‘:warn` - Only log errors and warnings

    • ‘false` or `nil` - Disable logging (default)

    This configures both the new Parse::Middleware::Logging middleware and the legacy Parse::Middleware::BodyBuilder logging.

  • :logger (Logger)

    A custom logger instance for request/response logging. Defaults to Logger.new(STDOUT) if not specified.

  • :adapter (Object)

    The connection adapter. By default it uses ‘:net_http_persistent` for connection pooling. Set `connection_pooling: false` to use the standard `Faraday.default_adapter` (Net/HTTP) instead.

  • :connection_pooling (Boolean, Hash)

    Controls HTTP connection pooling. Defaults to ‘true`, using the `:net_http_persistent` adapter for improved performance through connection reuse. Set to `false` to disable pooling and create a new connection for each request. This option is ignored if `:adapter` is explicitly specified. Pass a Hash to enable pooling with custom configuration:

    • ‘:pool_size` [Integer] - Number of connections per thread (default: 1)

    • ‘:idle_timeout` [Integer] - Seconds before closing idle connections (default: 5)

    • ‘:keep_alive` [Integer] - HTTP Keep-Alive timeout in seconds

    @example Custom connection pooling

    Parse.setup(
      connection_pooling: { pool_size: 5, idle_timeout: 60, keep_alive: 60 }
    )
    
  • :cache (Moneta::Transformer, Moneta::Expires)

    A caching adapter of type Moneta::Transformer or Moneta::Expires that will be used by the caching middleware Parse::Middleware::Caching. Caching queries and object fetches can help improve the performance of your application, even if it is for a few seconds. Only successful GET object fetches and non-empty result queries will be cached by default. You may set the default expiration time with the expires option. At any point in time you may clear the cache by calling the Parse::Client#clear_cache! method on the client connection. See Moneta.

  • :expires (Integer)

    Sets the default cache expiration time (in seconds) for successful non-empty GET requests when using the caching middleware. The default value is 3 seconds. If :expires is set to 0, caching will be disabled. You can always clear the current state of the cache using the clear_cache! method on your Parse::Client instance.

  • :faraday (Hash)

    You may pass a hash of options that will be passed to the Faraday constructor.

  • :live_query_url (String)

    The WebSocket URL for Parse LiveQuery server (e.g., “wss://your-parse-server.com”). If not specified, falls back to ENV. LiveQuery enables real-time subscriptions to changes in Parse objects. @example Enable LiveQuery

    Parse.setup(
      server_url: "https://your-server.com/parse",
      application_id: "YOUR_APP_ID",
      api_key: "YOUR_API_KEY",
      live_query_url: "wss://your-server.com"
    )
    
  • :live_query (Hash)

    Advanced LiveQuery configuration options. Pass a hash with custom settings for the LiveQuery client.

    • :url [String] - WebSocket URL (alternative to :live_query_url)

    • :auto_reconnect [Boolean] - Auto-reconnect on disconnect (default: true)

Yields:

  • the block for additional configuration with Faraday middleware.

Returns:

  • (Client)

    a new instance of Client

See Also:



957
958
959
960
961
962
963
# File 'lib/parse/client.rb', line 957

def self.setup(opts = {}, &block)
  if block_given?
    Parse::Client.new(opts, &block)
  else
    Parse::Client.new(opts)
  end
end

.strict_pointer_shapes?Boolean

Check if strict pointer-shape validation is enabled. When true, impossible shapes (e.g. bare string ‘$in` element against a pointer column whose target class is unknown) raise Parse::Query::PointerShapeError instead of silently returning zero rows. See strict_pointer_shapes=.

Returns:

  • (Boolean)


304
305
306
# File 'lib/parse/stack.rb', line 304

def strict_pointer_shapes?
  @strict_pointer_shapes == true
end

.trigger_job(name, body = {}, **opts) ⇒ Object

Helper method to trigger cloud jobs and get results.

Parameters:

  • name (String)

    the name of the cloud code job to trigger.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the job.

  • opts (Hash)

    additional options.

Returns:

  • (Object)

    the result data of the response. nil if there was an error.



979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
# File 'lib/parse/client.rb', line 979

def self.trigger_job(name, body = {}, **opts)
  conn = opts[:session] || opts[:client] || :default

  # Extract request options for the API call
  request_opts = {}
  request_opts[:session_token] = opts[:session_token] if opts[:session_token]
  request_opts[:master_key] = opts[:master_key] if opts[:master_key]

  response = Parse::Client.client(conn).trigger_job(name, body, opts: request_opts)
  return response if opts[:raw].present?
  if response.error?
    Parse::Client._safe_warn("CloudCodeError", response, name: name)
    return nil
  end
  _extract_cloud_result(response)
end

.trigger_job!(name, body = {}, **opts) ⇒ Object

Same as trigger_job but raises Parse::Error::CloudCodeError when the job returns an error instead of silently returning nil. HTTP-level errors (auth, timeouts, throttling, etc.) still raise their specific Error subclasses as the underlying client does.

Parameters:

  • opts (see Parse.trigger_job)

    — :raw is ignored.

  • name (String)

    the name of the cloud code job to trigger.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the job.

Returns:

  • (Object)

    the result data of the response.

Raises:



1005
1006
1007
1008
1009
# File 'lib/parse/client.rb', line 1005

def self.trigger_job!(name, body = {}, **opts)
  response = trigger_job(name, body, **opts.merge(raw: true))
  raise Parse::Error::CloudCodeError.new(name, response) if response.error?
  _extract_cloud_result(response)
end

.trigger_job_with_session(name, body = {}, session_token, **opts) ⇒ Object

Helper method to trigger cloud jobs with a session token. This is a convenience method that ensures proper session token handling.

Parameters:

  • name (String)

    the name of the cloud code job to trigger.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the job.

  • session_token (String)

    the session token for authenticated requests.

  • opts (Hash)

    additional options (same as trigger_job).

Returns:

  • (Object)

    the result data of the response. nil if there was an error.



1018
1019
1020
1021
# File 'lib/parse/client.rb', line 1018

def self.trigger_job_with_session(name, body = {}, session_token, **opts)
  opts[:session_token] = session_token
  trigger_job(name, body, **opts)
end

.trigger_job_with_session!(name, body = {}, session_token, **opts) ⇒ Object

Same as trigger_job_with_session but raises Parse::Error::CloudCodeError when the job returns an error instead of silently returning nil.

Parameters:

  • name (String)

    the name of the cloud code job to trigger.

  • body (Hash) (defaults to: {})

    the set of parameters to pass to the job.

  • session_token (String)

    the session token for authenticated requests.

  • opts (Hash)

    additional options (same as trigger_job).

Returns:

  • (Object)

    the result data of the response.

Raises:



1032
1033
1034
1035
# File 'lib/parse/client.rb', line 1032

def self.trigger_job_with_session!(name, body = {}, session_token, **opts)
  opts[:session_token] = session_token
  trigger_job!(name, body, **opts)
end

.update_config(params, conn = :default, master_key_only: nil) ⇒ Hash

Set a key value pairs in the Parse configuration for an application.

Examples:

# batch update several
Parse.update_config({fieldEnabled: true, searchMiles: 50})
# also mark some keys as master-key-only
Parse.update_config({fieldEnabled: true}, master_key_only: { fieldEnabled: true })

Parameters:

  • params (Hash)

    a set of key value pairs to set in the Parse configuration.

  • conn (Symbol) (defaults to: :default)

    the name of the client connection to use.

  • master_key_only (Hash{String=>Boolean}, nil) (defaults to: nil)

    optional map of config keys to boolean masterKeyOnly flags. Parse Server merges this with any existing masterKeyOnly settings; unspecified keys keep their current flag.

Returns:

  • (Hash)

    the Parse config hash for the session.



124
125
126
127
# File 'lib/parse/client.rb', line 124

def self.update_config(params, conn = :default, master_key_only: nil)
  opts = master_key_only.nil? ? {} : { master_key_only: master_key_only }
  Parse::Client.client(conn).update_config(params, **opts)
end

.use_shortnames!Object

Alias shorter names of core Parse class names. Ex, alias Parse::User to User, Parse::Installation to Installation, etc.



79
80
81
# File 'lib/parse/model/object.rb', line 79

def self.use_shortnames!
  require_relative "shortnames"
end

.warn_on_n_plus_oneBoolean Also known as: warn_on_n_plus_one?

Check if N+1 detection is enabled.

Returns:

  • (Boolean)


370
371
372
# File 'lib/parse/query/n_plus_one_detector.rb', line 370

def warn_on_n_plus_one
  NPlusOneDetector.enabled?
end

.warn_on_n_plus_one=(value) ⇒ Object

Enable or disable N+1 query detection. When enabled, warnings are emitted when N+1 patterns are detected. For more control, use #n_plus_one_mode= instead.

Examples:

Enable N+1 detection

Parse.warn_on_n_plus_one = true

Parameters:

  • value (Boolean)

    true enables :warn mode, false sets :ignore mode



364
365
366
# File 'lib/parse/query/n_plus_one_detector.rb', line 364

def warn_on_n_plus_one=(value)
  NPlusOneDetector.enabled = value
end

.with_master_key { ... } ⇒ Object

Inverse of without_master_key: forces the master key back on for the duration of the block, even if a containing without_master_key had suppressed it. Useful for re-entering an admin-only operation inside a session-scoped block. If no master key is configured on the client, this is a no-op — the helper does not synthesise one.

Yields:

  • runs the block with master-key enabled (if configured)

Returns:

  • (Object)

    the block’s return value



68
69
70
71
72
73
74
# File 'lib/parse/stack.rb', line 68

def self.with_master_key
  previous = Fiber[MASTER_KEY_STATE_KEY]
  Fiber[MASTER_KEY_STATE_KEY] = :enabled
  yield
ensure
  Fiber[MASTER_KEY_STATE_KEY] = previous
end

.without_master_key { ... } ⇒ Object

Run block with the master key suppressed for every Parse request originating in the current fiber. Equivalent to setting the X-Disable-Parse-Master-Key header on each request, but block-scoped so callers can wrap a unit of work — e.g. running an action “as if the configured master key were not available” — without threading the header through every intermediate call.

Survives Faraday retries (the per-request header would be stripped on the first attempt and gone by the retry; the fiber-local state lives for the lifetime of the block).

Examples:

Parse.without_master_key do
  song = Song.find(id)         # session-token / API-key auth only
  song.title = "Renamed"
  song.save                    # subject to ACL/CLP
end

Yields:

  • runs the block with master-key disabled

Returns:

  • (Object)

    the block’s return value



52
53
54
55
56
57
58
# File 'lib/parse/stack.rb', line 52

def self.without_master_key
  previous = Fiber[MASTER_KEY_STATE_KEY]
  Fiber[MASTER_KEY_STATE_KEY] = :disabled
  yield
ensure
  Fiber[MASTER_KEY_STATE_KEY] = previous
end