suma 0.5.30 → 0.5.32

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c4133e715420dbc264798602c9bb0dbebf8a537f5b2f8bdaccb84258fcc37d7
4
- data.tar.gz: e994b0e3f502603fcd1b7f7eb45a93cf724bb1b844dce598775e0e6f7fc200b2
3
+ metadata.gz: e58de844e84a98a6114627866bee6a97f6e9b77b17e4b14f8086a9f38085436c
4
+ data.tar.gz: 907a991943cd782e14da96bd6579937ab382c75e0b332cf3ec55ec3ee7d649aa
5
5
  SHA512:
6
- metadata.gz: 6316644ee7b6ed8d3bd6cf3b5520a132ee81f457b7ad797a50a4fdecb0a44570e1e28835c542e2a11ab582303da3e7670b955e372ffcc98e3a7f9c5178b77a61
7
- data.tar.gz: ab7268c9cb367028d620cca8de69719f3e44e606f8ee60d7925d45b57d836b86b1b3562d4cb186d9688b30a30b7d7c9a394bb7cdb75b0dee080e013b12033658
6
+ metadata.gz: df779c2bda89b8e69bc56fac088acb60d734072522a239e9cc1879389707b53d21bf115897d2550708e9b1b2a53586b05fa533d12f52f5abc2d50efda02b0f1b
7
+ data.tar.gz: f99cf892fd49bf72f1f02bc3821202fabdc16ef82486fd6cdd7af9ca7e294de2343e36e41b0c3616f598989d67e679d5b03bfb3d80bccd013276954a5dc85d13
@@ -288,7 +288,8 @@ module Suma
288
288
  "#{entity_name_to_text(entity.id)} #{entity_ref}"
289
289
  else
290
290
  entity_subtypes = subtypes.map do |e|
291
- urn_mention(express_entity_urn("#{schema.id}.#{e.id}"), e.id)
291
+ owner = declaring_schema_id(schema, e.id) || schema.id
292
+ urn_mention(express_entity_urn("#{owner}.#{e.id}"), e.id)
292
293
  end
293
294
 
294
295
  "#{entity_type} that is a type of " \
@@ -297,5 +298,106 @@ module Suma
297
298
  "#{entity_name_to_text(entity.id)} #{entity_ref}"
298
299
  end
299
300
  end
301
+
302
+ # The schema an imported declaration is declared in, resolved through
303
+ # +schema+'s USE-FROM closure — the same resolution the source remark
304
+ # xrefs carry: a local declaration wins; otherwise the USE FROM edges
305
+ # (item-naming ones first, then bare ones) are walked transitively,
306
+ # and a single distinct declaring schema wins. nil leaves the citation
307
+ # qualified with the citing schema, since inventing an owner would be
308
+ # wrong (iso-10303#835: the declarer can sit more than one USE FROM
309
+ # away, and sibling branches must all be searched before settling).
310
+ def declaring_schema_id(schema, entity_id)
311
+ declarers = declaring_schemas(schema, entity_id, [])
312
+ declarers.uniq.one? ? declarers.first : nil
313
+ end
314
+
315
+ # Distinct schema ids within +schema+'s USE-FROM closure declaring
316
+ # +entity_id+. An interface whose item list names the declaration
317
+ # claims it outright (that is what the item list means in EXPRESS) —
318
+ # those sources are terminal candidates. Bare USE FROMs carry no
319
+ # claim, so they are walked; a bare source outside the manifest
320
+ # cannot be verified and stands as its own candidate. Each branch
321
+ # tracks its own visited list so sibling imports are searched
322
+ # independently; re-entering a schema on the same branch ends it.
323
+ def declaring_schemas(schema, entity_id, visited)
324
+ return [] if visited.include?(schema.id)
325
+
326
+ visited << schema.id
327
+ return [schema.id] if schema.entities.any? { |e| e.id == entity_id }
328
+
329
+ item_matches, bare_sources = use_from_sources(schema, entity_id)
330
+ return item_matches.uniq if item_matches.any?
331
+
332
+ walk_bare_sources(bare_sources, entity_id, visited)
333
+ end
334
+
335
+ def walk_bare_sources(bare_sources, entity_id, visited)
336
+ bare_sources.uniq.flat_map do |source|
337
+ loaded = loaded_schema(source)
338
+ if loaded
339
+ declaring_schemas(loaded, entity_id, visited.dup)
340
+ else
341
+ [source]
342
+ end
343
+ end
344
+ end
345
+
346
+ # The USE FROM interfaces of +schema+ relevant to +entity_id+: the
347
+ # sources whose item list names it, and the bare USE FROM sources.
348
+ def use_from_sources(schema, entity_id)
349
+ item_matches = []
350
+ bare_sources = []
351
+ schema.interfaces.each do |interface|
352
+ case interface_claim(interface, entity_id)
353
+ when :item then item_matches << interface.schema.id
354
+ when :bare then bare_sources << interface.schema.id
355
+ end
356
+ end
357
+
358
+ [item_matches, bare_sources]
359
+ end
360
+
361
+ # :item when the interface's item list names the declaration, :bare
362
+ # for a bare USE FROM, nil when the interface is irrelevant to it.
363
+ def interface_claim(interface, entity_id)
364
+ source = interface.schema&.id
365
+ return nil unless source && interface.kind == "USE"
366
+
367
+ items = Array(interface.items)
368
+ return :bare if items.empty?
369
+ return :item if item_names?(items, entity_id)
370
+
371
+ nil
372
+ end
373
+
374
+ def item_names?(items, entity_id)
375
+ items.any? { |item| import_item_id(item) == entity_id }
376
+ end
377
+
378
+ # Sibling schema by EXPRESS id, parsed on demand from the schema
379
+ # manifest and memoized — the walk only touches schemas a citation
380
+ # chain actually names.
381
+ def loaded_schema(id)
382
+ @loaded_schemas ||= {}
383
+ return @loaded_schemas[id] if @loaded_schemas.key?(id)
384
+
385
+ path = schema_manifest_paths[id]
386
+ @loaded_schemas[id] =
387
+ path && Expressir::Express::Parser.from_file(path)&.schemas&.first
388
+ end
389
+
390
+ def schema_manifest_paths
391
+ @schema_manifest_paths ||=
392
+ Expressir::SchemaManifest.from_file(@schema_manifest_file).schemas
393
+ .to_h { |entry| [entry.id, entry.path] }
394
+ end
395
+
396
+ # The imported declaration's name as written in the USE FROM list:
397
+ # InterfaceItem carries it on #ref (the reference node), with #id
398
+ # holding the local rename when present.
399
+ def import_item_id(item)
400
+ item.ref&.id || item.id
401
+ end
300
402
  end
301
403
  end
data/lib/suma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Suma
4
- VERSION = "0.5.30"
4
+ VERSION = "0.5.32"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.30
4
+ version: 0.5.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-10 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64