Class: Hecks::Runtime::QueryInterpreter
- Inherits:
-
Object
- Object
- Hecks::Runtime::QueryInterpreter
- Defined in:
- lib/hecks/runtime/query_interpreter.rb
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #call(domain, aggregate, query_name, args) ⇒ Object
-
#initialize(registry) ⇒ QueryInterpreter
constructor
A new instance of QueryInterpreter.
-
#reference_call(domain, aggregate, query_name, args) ⇒ Object
The REFERENCE answer — this interpreter's own evaluation, never an adapter's native hook.
Constructor Details
#initialize(registry) ⇒ QueryInterpreter
Returns a new instance of QueryInterpreter.
17 18 19 |
# File 'lib/hecks/runtime/query_interpreter.rb', line 17 def initialize(registry) @registry = registry end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
15 16 17 |
# File 'lib/hecks/runtime/query_interpreter.rb', line 15 def registry @registry end |
Instance Method Details
#call(domain, aggregate, query_name, args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hecks/runtime/query_interpreter.rb', line 21 def call(domain, aggregate, query_name, args) return entity_rows(domain, aggregate, query_name, args) if query_name.include?(".") declared = declared_query(aggregate, query_name) args = normalize_args(aggregate, declared, args) declared = TenantScope.apply(declared, args) # AFTER TenantScope, so its synthetic clause is already present # in `.wheres` and rides through as an ordinary LOCAL clause on # the OUTER query. It does not reach the hop's own inner # sub-query against the TARGET aggregate — a hop's target may # not even declare the same tenant boundary, and propagating one # aggregate's tenant scope onto an unrelated aggregate's own # query is a real design question of its own, not answered here. declared = ReferenceHop.apply(declared, args, registry: @registry, domain: domain, aggregate: aggregate) repository = @registry.repository(domain, aggregate) # `registry:` is threaded through so a `none_in_state` where-clause # can look its target aggregate up — see # QuerySpecification::Common::Comparison#none_in_state? for the # comparator itself, and for why an ordinary aggregate-level # Memory query needs the registry passed explicitly rather than # closing over an instance variable. if (native = Ports::Query.execute(repository, declared, args, context: { domain: domain, aggregate: aggregate, registry: @registry })) records = native # `record.state.merge(id: record.id)` — id LAST, not first. See # Instance#to_h's own comment: an aggregate free to declare its # own attribute literally named `id` has that attribute's own # wrapped value sitting in `record.state[:id]` already; merging # it OVER a `{id:}.merge(state)` used to let it silently # clobber the correct bare identity this row is supposed to # carry. # A QUERY ROW IS AN ANSWER, NOT A HANDLE. Mutating one edits # nobody's state and silently disagrees with the store. return Freezer.deep(records.map { |record| record.state.merge(id: record.id) }) end Freezer.deep(interpret(repository.all, declared, args, domain: domain)) end |
#reference_call(domain, aggregate, query_name, args) ⇒ Object
The REFERENCE answer — this interpreter's own evaluation, never an adapter's native hook. The fuzzer's query oracle replays every generated ask through both paths and treats a difference as a finding: the differential gate the retired cross-runtime harness should always have been, aimed where the divergence actually lives — between the engines inside this one runtime.
A hop clause is answered here by its OWN, deliberately naive walk (reference_where_holds?) — never Runtime::ReferenceHop's partition/fold/IN-clause. Sharing that algorithm would have made this oracle blind to exactly the code the hop feature adds: every PHASE of a shared fold would still get diffed against the native adapters, but the fold itself — the empty candidate set, a duplicate id, a dangling reference, a chain's inside-out resolution order — would only ever be compared against itself.
76 77 78 79 80 81 82 83 84 |
# File 'lib/hecks/runtime/query_interpreter.rb', line 76 def reference_call(domain, aggregate, query_name, args) return entity_rows(domain, aggregate, query_name, args) if query_name.include?(".") declared = declared_query(aggregate, query_name) args = normalize_args(aggregate, declared, args) declared = TenantScope.apply(declared, args) reference_interpret(@registry.repository(domain, aggregate).all, declared, args, domain: domain, shape: aggregate) end |