From 00696267bcb42e1f3d1b5d01650b76014a64c05a Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 30 Aug 2023 14:23:17 -0400 Subject: [PATCH] ServiceNow: when looking up a table's schema, include the name of the display column --- examples/serviceNowDemo.ur | 6 +++++- src/ur/serviceNow.ur | 28 +++++++++++++++++++++++----- src/ur/serviceNow.urs | 7 ++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/examples/serviceNowDemo.ur b/examples/serviceNowDemo.ur index 2aa29bd..8cdcb8c 100644 --- a/examples/serviceNowDemo.ur +++ b/examples/serviceNowDemo.ur @@ -10,10 +10,14 @@ structure A = ServiceNow.ThreeLegged(struct structure S = ServiceNow.Make(A) fun table_ name = - cs <- S.Tables.columns name; + {Columns = cs, DisplayColumn = disp} <- S.Tables.columns name; return

Columns

+ {case disp of + None => + | Some disp =>

Display column is: {[disp]}.

} + {List.mapX (fn c => diff --git a/src/ur/serviceNow.ur b/src/ur/serviceNow.ur index 5e3a38e..f05bfe0 100644 --- a/src/ur/serviceNow.ur +++ b/src/ur/serviceNow.ur @@ -55,10 +55,17 @@ type column = { type column' = { Nam : option string, - Typ : option reference + Typ : option reference, + Display : option bool } val _ : json column' = json_record_withOptional {} {Nam = "element", - Typ = "internal_type"} + Typ = "internal_type", + Display = "display"} + +type full_table = { + Columns : list column, + DisplayColumn : option string +} functor Make(M : AUTH) = struct open M @@ -120,9 +127,9 @@ functor Make(M : AUTH) = struct if name = "" then None else - return {Nam = name, Typ = typ.Value}) raw) + return {Nam = name, Typ = typ.Value, Display = r.Display}) raw) - fun columns tabl = + fun columnsRaw tabl = cs <- columnsWithoutInheritance tabl; t <- get tabl; case t of @@ -135,8 +142,19 @@ functor Make(M : AUTH) = struct case p of None => return cs | Some p => - cs' <- columns p.Nam; + cs' <- columnsRaw p.Nam; return (List.append cs cs') + + fun columns tabl = + cs <- columnsRaw tabl; + disp <- return (case List.find (fn c => c.Display = Some True) cs of + Some c => Some c.Nam + | None => + case List.find (fn c => c.Nam = "number" || c.Nam = "name" || c.Nam = "u_number" || c.Nam = "u_name") cs of + Some c => Some c.Nam + | None => None); + return {Columns = List.mp (fn c => c -- #Display) cs, + DisplayColumn = disp} end structure Table = struct diff --git a/src/ur/serviceNow.urs b/src/ur/serviceNow.urs index 62f20ae..3f7e079 100644 --- a/src/ur/serviceNow.urs +++ b/src/ur/serviceNow.urs @@ -60,6 +60,11 @@ type column = { Typ : string } +type full_table = { + Columns : list column, + DisplayColumn : option string (* name of column to use in summarizing a row of this table, e.g. in a list of several rows somewhere *) +} + functor Make(M : AUTH) : sig structure Incidents : sig val list : transaction (list incident) @@ -67,7 +72,7 @@ functor Make(M : AUTH) : sig structure Tables : sig val list : transaction (list tabl) - val columns : string -> transaction (list column) + val columns : string -> transaction full_table end structure Table : sig
Name Type