references inside and into nested struct-templates ("graph-templates") #1725
-
EDIT: I understood CUE some more and rephrased the question in the answer below. I have nested structs where nodes may reference any other node in that struct (the level of nesting is arbitrary and unknown)
Here for example
Now the IDs are obviously not unique anymore. also I want to grab into
CUE is amazing! Thank you for it! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
I think we're struggling with a similar problem #1723 |
Beta Was this translation helpful? Give feedback.
-
I found this discussion about uuidgen() here: #192 But the generated ID here is only needed to model the reference (in JSON). If you look at it in a more abstract way, the references itself do not break the hermetic sealing. So my question should be: is there a way to model such "graph-templates"?
As seen in the OP you can already model that in CUE, but the reference information is lost, because the target of the ref is just copied. The config files I am using (Building models / BIM / ICF) heavily use such internal references and are also very repetitive. I think I could reduce the size and complexity by magnitudes with CUE. This could be really a game changer. I'd even accept a non hermetic solution. |
Beta Was this translation helpful? Give feedback.
-
Can you not leverage the uniqueness you already have in your structure? i.e. your https://cuelang.org/play/?id=v24ulXI8rrE#cue@export@cue As you say, this "uniqueness" only needs to exist within the model itself, hence you don't need true UUIDs. If you wanted to define the references to actual https://cuelang.org/play/?id=2TE1qNGGsST#cue@export@cue Note that whilst this syntax looks a bit clunky today, it is the basis of a proposal for a "function" syntax. See the first heading "Functions" in #943. |
Beta Was this translation helpful? Give feedback.
Can you not leverage the uniqueness you already have in your structure?
i.e. your
foos
struct defines fields for each#foo
instance, and within each#foo
, theitems
each have a unique key. So then identify each#item
by that unique path:https://cuelang.org/play/?id=v24ulXI8rrE#cue@export@cue
As you say, this "uniqueness" only needs to exist within the model itself, hence you don't need true UUIDs.
If you wanted to define the references to actual
#item
values and have the export (i.e. manifestation) of the configuration reduce that to theid
then you could do something like:https://cuelang.org/play/?id=2TE1qNGGsST#cue@export@cue
Note that whilst this syntax looks a bit clunky today, it i…