parse-stack-next 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +2 -0
  3. data/.env.sample +112 -0
  4. data/.env.test +10 -0
  5. data/.github/workflows/ruby.yml +36 -0
  6. data/.gitignore +49 -0
  7. data/.ruby-version +1 -0
  8. data/.solargraph.yml +22 -0
  9. data/CHANGELOG.md +5816 -0
  10. data/Gemfile +30 -0
  11. data/Gemfile.lock +175 -0
  12. data/LICENSE.txt +23 -0
  13. data/Makefile +63 -0
  14. data/README.md +5655 -0
  15. data/Rakefile +573 -0
  16. data/bin/console +38 -0
  17. data/bin/parse-console +136 -0
  18. data/bin/server +17 -0
  19. data/bin/setup +7 -0
  20. data/config/parse-config.json +12 -0
  21. data/docs/TEST_SERVER.md +271 -0
  22. data/docs/_config.yml +1 -0
  23. data/docs/mcp_guide.md +3484 -0
  24. data/docs/mongodb_direct_guide.md +1348 -0
  25. data/docs/mongodb_index_optimization_guide.md +631 -0
  26. data/examples/transaction_example.rb +219 -0
  27. data/lib/parse/acl_scope.rb +728 -0
  28. data/lib/parse/agent/cancellation_token.rb +80 -0
  29. data/lib/parse/agent/constraint_translator.rb +480 -0
  30. data/lib/parse/agent/describe.rb +420 -0
  31. data/lib/parse/agent/errors.rb +133 -0
  32. data/lib/parse/agent/mcp_client.rb +557 -0
  33. data/lib/parse/agent/mcp_dispatcher.rb +1023 -0
  34. data/lib/parse/agent/mcp_rack_app.rb +1143 -0
  35. data/lib/parse/agent/mcp_server.rb +376 -0
  36. data/lib/parse/agent/metadata_audit.rb +259 -0
  37. data/lib/parse/agent/metadata_dsl.rb +733 -0
  38. data/lib/parse/agent/metadata_registry.rb +794 -0
  39. data/lib/parse/agent/pipeline_validator.rb +82 -0
  40. data/lib/parse/agent/prompts.rb +351 -0
  41. data/lib/parse/agent/rate_limiter.rb +158 -0
  42. data/lib/parse/agent/relation_graph.rb +162 -0
  43. data/lib/parse/agent/result_formatter.rb +453 -0
  44. data/lib/parse/agent/tools.rb +5489 -0
  45. data/lib/parse/agent.rb +3249 -0
  46. data/lib/parse/api/aggregate.rb +79 -0
  47. data/lib/parse/api/all.rb +26 -0
  48. data/lib/parse/api/analytics.rb +18 -0
  49. data/lib/parse/api/batch.rb +33 -0
  50. data/lib/parse/api/cloud_functions.rb +58 -0
  51. data/lib/parse/api/config.rb +125 -0
  52. data/lib/parse/api/files.rb +29 -0
  53. data/lib/parse/api/hooks.rb +117 -0
  54. data/lib/parse/api/objects.rb +146 -0
  55. data/lib/parse/api/path_segment.rb +75 -0
  56. data/lib/parse/api/push.rb +20 -0
  57. data/lib/parse/api/schema.rb +49 -0
  58. data/lib/parse/api/server.rb +50 -0
  59. data/lib/parse/api/sessions.rb +24 -0
  60. data/lib/parse/api/users.rb +250 -0
  61. data/lib/parse/atlas_search/index_manager.rb +353 -0
  62. data/lib/parse/atlas_search/result.rb +204 -0
  63. data/lib/parse/atlas_search/search_builder.rb +604 -0
  64. data/lib/parse/atlas_search/session.rb +253 -0
  65. data/lib/parse/atlas_search.rb +995 -0
  66. data/lib/parse/client/authentication.rb +97 -0
  67. data/lib/parse/client/batch.rb +234 -0
  68. data/lib/parse/client/body_builder.rb +240 -0
  69. data/lib/parse/client/caching.rb +203 -0
  70. data/lib/parse/client/logging.rb +293 -0
  71. data/lib/parse/client/profiling.rb +181 -0
  72. data/lib/parse/client/protocol.rb +91 -0
  73. data/lib/parse/client/request.rb +233 -0
  74. data/lib/parse/client/response.rb +208 -0
  75. data/lib/parse/client.rb +1104 -0
  76. data/lib/parse/clp_scope.rb +361 -0
  77. data/lib/parse/live_query/circuit_breaker.rb +256 -0
  78. data/lib/parse/live_query/client.rb +1001 -0
  79. data/lib/parse/live_query/configuration.rb +224 -0
  80. data/lib/parse/live_query/event.rb +115 -0
  81. data/lib/parse/live_query/event_queue.rb +272 -0
  82. data/lib/parse/live_query/health_monitor.rb +214 -0
  83. data/lib/parse/live_query/logging.rb +149 -0
  84. data/lib/parse/live_query/subscription.rb +294 -0
  85. data/lib/parse/live_query.rb +163 -0
  86. data/lib/parse/lookup_rewriter.rb +445 -0
  87. data/lib/parse/model/acl.rb +968 -0
  88. data/lib/parse/model/associations/belongs_to.rb +275 -0
  89. data/lib/parse/model/associations/collection_proxy.rb +435 -0
  90. data/lib/parse/model/associations/has_many.rb +597 -0
  91. data/lib/parse/model/associations/has_one.rb +158 -0
  92. data/lib/parse/model/associations/pointer_collection_proxy.rb +134 -0
  93. data/lib/parse/model/associations/relation_collection_proxy.rb +177 -0
  94. data/lib/parse/model/bytes.rb +62 -0
  95. data/lib/parse/model/classes/audience.rb +262 -0
  96. data/lib/parse/model/classes/installation.rb +363 -0
  97. data/lib/parse/model/classes/job_schedule.rb +153 -0
  98. data/lib/parse/model/classes/job_status.rb +264 -0
  99. data/lib/parse/model/classes/product.rb +75 -0
  100. data/lib/parse/model/classes/push_status.rb +263 -0
  101. data/lib/parse/model/classes/role.rb +751 -0
  102. data/lib/parse/model/classes/session.rb +201 -0
  103. data/lib/parse/model/classes/user.rb +943 -0
  104. data/lib/parse/model/clp.rb +544 -0
  105. data/lib/parse/model/core/actions.rb +1268 -0
  106. data/lib/parse/model/core/builder.rb +139 -0
  107. data/lib/parse/model/core/create_lock.rb +386 -0
  108. data/lib/parse/model/core/describe.rb +382 -0
  109. data/lib/parse/model/core/enhanced_change_tracking.rb +159 -0
  110. data/lib/parse/model/core/errors.rb +38 -0
  111. data/lib/parse/model/core/fetching.rb +566 -0
  112. data/lib/parse/model/core/field_guards.rb +220 -0
  113. data/lib/parse/model/core/indexing.rb +382 -0
  114. data/lib/parse/model/core/parse_reference.rb +407 -0
  115. data/lib/parse/model/core/properties.rb +809 -0
  116. data/lib/parse/model/core/querying.rb +491 -0
  117. data/lib/parse/model/core/schema.rb +202 -0
  118. data/lib/parse/model/core/search_indexing.rb +174 -0
  119. data/lib/parse/model/date.rb +88 -0
  120. data/lib/parse/model/email.rb +213 -0
  121. data/lib/parse/model/file.rb +527 -0
  122. data/lib/parse/model/geojson.rb +271 -0
  123. data/lib/parse/model/geopoint.rb +261 -0
  124. data/lib/parse/model/model.rb +260 -0
  125. data/lib/parse/model/object.rb +2068 -0
  126. data/lib/parse/model/phone.rb +520 -0
  127. data/lib/parse/model/pointer.rb +443 -0
  128. data/lib/parse/model/polygon.rb +406 -0
  129. data/lib/parse/model/push.rb +975 -0
  130. data/lib/parse/model/shortnames.rb +8 -0
  131. data/lib/parse/model/time_zone.rb +141 -0
  132. data/lib/parse/model/validations/uniqueness_validator.rb +97 -0
  133. data/lib/parse/model/validations.rb +96 -0
  134. data/lib/parse/mongodb.rb +2300 -0
  135. data/lib/parse/pipeline_security.rb +554 -0
  136. data/lib/parse/query/constraint.rb +198 -0
  137. data/lib/parse/query/constraints.rb +3279 -0
  138. data/lib/parse/query/cursor.rb +434 -0
  139. data/lib/parse/query/n_plus_one_detector.rb +445 -0
  140. data/lib/parse/query/operation.rb +104 -0
  141. data/lib/parse/query/ordering.rb +66 -0
  142. data/lib/parse/query.rb +7028 -0
  143. data/lib/parse/schema/index_migrator.rb +291 -0
  144. data/lib/parse/schema/search_index_migrator.rb +289 -0
  145. data/lib/parse/schema.rb +494 -0
  146. data/lib/parse/stack/generators/rails.rb +40 -0
  147. data/lib/parse/stack/generators/templates/model.erb +51 -0
  148. data/lib/parse/stack/generators/templates/model_installation.rb +4 -0
  149. data/lib/parse/stack/generators/templates/model_role.rb +4 -0
  150. data/lib/parse/stack/generators/templates/model_session.rb +4 -0
  151. data/lib/parse/stack/generators/templates/model_user.rb +11 -0
  152. data/lib/parse/stack/generators/templates/parse.rb +12 -0
  153. data/lib/parse/stack/generators/templates/webhooks.rb +10 -0
  154. data/lib/parse/stack/railtie.rb +18 -0
  155. data/lib/parse/stack/tasks.rb +563 -0
  156. data/lib/parse/stack/version.rb +11 -0
  157. data/lib/parse/stack.rb +455 -0
  158. data/lib/parse/two_factor_auth/user_extension.rb +449 -0
  159. data/lib/parse/two_factor_auth.rb +310 -0
  160. data/lib/parse/webhooks/payload.rb +360 -0
  161. data/lib/parse/webhooks/registration.rb +199 -0
  162. data/lib/parse/webhooks/replay_protection.rb +189 -0
  163. data/lib/parse/webhooks.rb +510 -0
  164. data/lib/parse-stack-next.rb +5 -0
  165. data/lib/parse-stack.rb +5 -0
  166. data/parse-stack-next.gemspec +82 -0
  167. data/parse-stack.png +0 -0
  168. data/scripts/debug-ips.js +35 -0
  169. data/scripts/docker/Dockerfile.parse +13 -0
  170. data/scripts/docker/atlas-init.js +284 -0
  171. data/scripts/docker/docker-compose.atlas.yml +76 -0
  172. data/scripts/docker/docker-compose.test.yml +106 -0
  173. data/scripts/docker/mongo-init.js +21 -0
  174. data/scripts/eval_mcp_with_lm_studio.rb +274 -0
  175. data/scripts/start-parse.sh +90 -0
  176. data/scripts/start_mcp_server.rb +78 -0
  177. data/scripts/test_server_connection.rb +82 -0
  178. metadata +377 -0
@@ -0,0 +1,198 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "operation"
5
+ require "time"
6
+ require "date"
7
+
8
+ module Parse
9
+ # Constraints are the heart of the Parse::Query system.
10
+ # Each constraint is made up of an Operation and a value (the right side
11
+ # of an operator). Constraints are responsible for making their specific
12
+ # Parse hash format required when sending Queries to Parse. All constraints can
13
+ # be combined by merging different constraints (since they are multiple hashes)
14
+ # and some constraints may have higher precedence than others (ex. equality is higher
15
+ # precedence than an "in" query).
16
+ #
17
+ # All constraints should inherit from Parse::Constraint and should
18
+ # register their specific Operation method (ex. :eq or :lte)
19
+ # For more information about the query design pattern from DataMapper
20
+ # that inspired this, see http://datamapper.org/docs/find.html
21
+ class Constraint
22
+
23
+ # @!attribute operation
24
+ # The operation tied to this constraint.
25
+ # @return [Parse::Operation]
26
+
27
+ # @!attribute value
28
+ # The value to be applied to this constraint.
29
+ # @return [Parse::Operation]
30
+
31
+ attr_accessor :operation, :value
32
+
33
+ # Create a new constraint.
34
+ # @param operation [Parse::Operation] the operation for this constraint.
35
+ # @param value [Object] the value to attach to this constraint.
36
+ # @yield You may also pass a block to modify the operation or value.
37
+ def initialize(operation, value)
38
+ # if the first parameter is not an Operation, but it is a symbol
39
+ # it most likely is just the field name, so let's assume they want
40
+ # the default equality operation.
41
+ if operation.is_a?(Operation) == false && operation.respond_to?(:to_sym)
42
+ operation = Operation.new(operation.to_sym, self.class.operand)
43
+ end
44
+ @operation = operation
45
+ @value = value
46
+ yield(self) if block_given?
47
+ end
48
+
49
+ class << self
50
+ # @!attribute key
51
+ # The class attributes keep track of the Parse key (special Parse
52
+ # text symbol representing this operation. Ex. local method could be called
53
+ # .ex, where the Parse Query operation that should be sent out is "$exists")
54
+ # in this case, key should be set to "$exists"
55
+ # @return [Symbol]
56
+ attr_accessor :key
57
+
58
+ # @!attribute precedence
59
+ # Precedence defines the priority of this operation when merging.
60
+ # The higher the more priority it will receive.
61
+ # @return [Integer]
62
+ attr_writer :precedence
63
+
64
+ # @!attribute operand
65
+ # @return [Symbol] the operand for this constraint.
66
+ attr_accessor :operand
67
+
68
+ # Creates a new constraint given an operation and value.
69
+ def create(operation, value)
70
+ #default to a generic equality constraint if not passed an operation
71
+ unless operation.is_a?(Parse::Operation) && operation.valid?
72
+ return self.new(operation, value)
73
+ end
74
+ operation.constraint(value)
75
+ end
76
+
77
+ # Set the keyword for this Constraint. Subclasses should use this method.
78
+ # @param keyword [Symbol]
79
+ # @return (see key)
80
+ def constraint_keyword(keyword)
81
+ @key = keyword
82
+ end
83
+
84
+ # Set the default precedence for this constraint.
85
+ # @param priority [Integer] a higher priority has higher precedence
86
+ # @return [Integer]
87
+ def precedence(priority = nil)
88
+ @precedence = 0 if @precedence.nil?
89
+ @precedence = priority unless priority.nil?
90
+ @precedence
91
+ end
92
+
93
+ # Register the given operand for this Parse::Constraint subclass.
94
+ # @note All subclasses should register their operation and themselves.
95
+ # @param op [Symbol] the operand
96
+ # @param klass [Parse::Constraint] a subclass of Parse::Constraint
97
+ # @return (see Parse::Operation.register)
98
+ def register(op, klass = self)
99
+ self.operand ||= op
100
+ Operation.register op, klass
101
+ end
102
+
103
+ # @return [Object] a formatted value based on the data type.
104
+ def formatted_value(value)
105
+ d = value
106
+
107
+ # Handle arrays by recursively processing each element
108
+ if d.is_a?(Array)
109
+ return d.map { |item| formatted_value(item) }
110
+ end
111
+
112
+ d = { __type: Parse::Model::TYPE_DATE, iso: d.utc.iso8601(3) } if d.respond_to?(:utc)
113
+ # if it responds to parse_date (most likely a time/date object), then call the conversion
114
+ d = d.parse_date if d.respond_to?(:parse_date)
115
+ # if it's not a Parse::Date, but still responds to iso8601, then do it manually
116
+ if d.is_a?(Parse::Date) == false && d.respond_to?(:iso8601)
117
+ d = { __type: Parse::Model::TYPE_DATE, iso: d.iso8601(3) }
118
+ end
119
+ d = d.pointer if d.respond_to?(:pointer) #simplified query object
120
+ d = d.to_s if d.is_a?(Regexp)
121
+ # d = d.pointer if d.is_a?(Parse::Object) #simplified query object
122
+ # d = d.compile
123
+ if d.is_a?(Parse::Query)
124
+ compiled = d.compile(encode: false, includeClassName: true)
125
+ # compiled["className"] = d.table
126
+ d = compiled
127
+ end
128
+ d
129
+ end
130
+ end
131
+
132
+ # @return [Integer] the precedence of this constraint
133
+ def precedence
134
+ self.class.precedence
135
+ end
136
+
137
+ # @return [Symbol] the Parse keyword for this constraint.
138
+ def key
139
+ self.class.key
140
+ end
141
+
142
+ # @!attribute operand
143
+ # @return [Symbol] the operand for the operation.
144
+ def operand
145
+ @operation.operand unless @operation.nil?
146
+ end
147
+
148
+ def operand=(o)
149
+ @operation.operand = o unless @operation.nil?
150
+ end
151
+
152
+ # @!attribute operator
153
+ # @return [Symbol] the operator for the operation.
154
+ def operator
155
+ @operation.operator unless @operation.nil?
156
+ end
157
+
158
+ def operator=(o)
159
+ @operation.operator = o unless @operation.nil?
160
+ end
161
+
162
+ # @!visibility private
163
+ def inspect
164
+ "<#{self.class} #{operator.to_s}(#{operand.inspect}, `#{value}`)>"
165
+ end
166
+
167
+ # Calls build internally
168
+ # @return [Hash]
169
+ def as_json(*args)
170
+ build
171
+ end
172
+
173
+ # Builds the JSON hash representation of this constraint for a Parse query.
174
+ # This method should be overriden by subclasses. The default implementation
175
+ # implements buildling the equality constraint.
176
+ # @raise ArgumentError if the constraint could be be build due to a bad parameter.
177
+ # This will be different depending on the constraint subclass.
178
+ # @return [Hash]
179
+ def build
180
+ return { @operation.operand => formatted_value } if @operation.operator == :eq || key.nil?
181
+ { @operation.operand => { key => formatted_value } }
182
+ end
183
+
184
+ # @return [String] string representation of this constraint.
185
+ def to_s
186
+ inspect
187
+ end
188
+
189
+ # @return [Object] formatted value based on the specific data type.
190
+ def formatted_value
191
+ self.class.formatted_value(@value)
192
+ end
193
+
194
+ # Registers the default constraint of equality
195
+ register :eq, Constraint
196
+ precedence 100
197
+ end
198
+ end