@voxgig/sdkgen 4.48.0 → 4.48.1

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 (59) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/dist/utility.js +9 -1
  4. package/dist/utility.js.map +1 -1
  5. package/package.json +1 -1
  6. package/project/.sdk/tm/c/utility/make_spec.c +1 -1
  7. package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
  8. package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
  9. package/project/.sdk/tm/clojure/src/sdk/core.clj +40 -9
  10. package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
  11. package/project/.sdk/tm/csharp/core/Point.cs +6 -0
  12. package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
  13. package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
  14. package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
  15. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
  16. package/project/.sdk/tm/go/core/target.go +8 -0
  17. package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
  18. package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
  19. package/project/.sdk/tm/java/core/Point.java +7 -0
  20. package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
  21. package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
  22. package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
  23. package/project/.sdk/tm/js/src/Point.js +2 -0
  24. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
  25. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
  26. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
  27. package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
  28. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
  29. package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
  30. package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
  31. package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
  32. package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
  33. package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
  34. package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
  35. package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
  36. package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
  37. package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
  38. package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
  39. package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
  40. package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
  41. package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
  42. package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
  43. package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
  44. package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
  45. package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
  46. package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
  47. package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
  48. package/project/.sdk/tm/scala/core/Point.scala +3 -0
  49. package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
  50. package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
  51. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
  52. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
  53. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
  54. package/project/.sdk/tm/ts/src/Point.ts +3 -0
  55. package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
  56. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
  57. package/project/.sdk/tm/zig/core/utility.zig +47 -4
  58. package/project/sdkgen-package.json +1 -1
  59. package/src/utility.ts +12 -1
@@ -1197,7 +1197,7 @@ pub fn make_spec_util(ctx: *Context) E!*Spec {
1197
1197
  if (std.mem.eql(u8, kind, "graphql")) {
1198
1198
  // GraphQL addresses one endpoint: no path parts, no query string,
1199
1199
  // and the body carries the operation. prepare_body is skipped
1200
- // deliberately — it only emits a body for data-input ops, whereas
1200
+ // deliberately — it builds only a REST body, whereas
1201
1201
  // every GraphQL op posts one, including load/list/remove.
1202
1202
  spec.body = graphql_body_util(ctx);
1203
1203
  spec.path = "";
@@ -1779,9 +1779,38 @@ pub fn prepare_body_util(ctx: *Context) Value {
1779
1779
  if (is_raw_request(ctx.point)) return raw_body(ctx.reqdata);
1780
1780
  return transform_request_util(ctx);
1781
1781
  }
1782
+ const fields = h.getp(ctx.point, "fields");
1783
+ if (fields == .array and fields.array.data.items.len != 0) return match_body(ctx, fields);
1782
1784
  return h.vnull();
1783
1785
  }
1784
1786
 
1787
+ // A list, load or remove routed to a method with a body sends the match
1788
+ // fields that body declares, never a path parameter, and never a header,
1789
+ // cookie or query argument the body does not also declare as a field.
1790
+ fn match_body(ctx: *Context, fields: Value) Value {
1791
+ const body = h.omap();
1792
+ for (fields.array.data.items) |f| {
1793
+ if (f != .string or std.mem.eql(u8, f.string, "$action") or body_routed(ctx.point, f.string)) continue;
1794
+ const val = h.getp(ctx.reqmatch, f.string);
1795
+ if (!h.is_noval(val)) h.setp(body, f.string, val);
1796
+ }
1797
+ return body;
1798
+ }
1799
+
1800
+ fn body_routed(point: Value, key: []const u8) bool {
1801
+ if (listed(h.getp(point, "params"), key) or names_key(h.getpath(&.{ "args", "params" }, point), key)) return true;
1802
+ for ([_][]const u8{ "header", "cookie", "query" }) |kind| {
1803
+ const defs: Value = h.getpath(&.{ "args", kind }, point);
1804
+ if (defs != .array) continue;
1805
+ for (defs.array.data.items) |ad| {
1806
+ const n = h.getp(ad, "name");
1807
+ const f = h.getp(ad, "field");
1808
+ if (n == .string and std.mem.eql(u8, n.string, key) and !(f == .bool and f.bool)) return true;
1809
+ }
1810
+ }
1811
+ return false;
1812
+ }
1813
+
1785
1814
  pub fn prepare_params_util(ctx: *Context) Value {
1786
1815
  const point = ctx.point;
1787
1816
  const args = h.to_map(h.getp(point, "args"));
@@ -1828,6 +1857,15 @@ fn names_key(defs: Value, key: []const u8) bool {
1828
1857
  return false;
1829
1858
  }
1830
1859
 
1860
+ // Whether a list of names holds this key.
1861
+ fn listed(names: Value, key: []const u8) bool {
1862
+ if (names != .array) return false;
1863
+ for (names.array.data.items) |v| {
1864
+ if (v == .string and std.mem.eql(u8, v.string, key)) return true;
1865
+ }
1866
+ return false;
1867
+ }
1868
+
1831
1869
  pub fn prepare_query_util(ctx: *Context) Value {
1832
1870
  const point = ctx.point;
1833
1871
  const reqmatch: Value = switch (ctx.reqmatch) {
@@ -1842,9 +1880,12 @@ pub fn prepare_query_util(ctx: *Context) Value {
1842
1880
  // as args.params, which prepare_params reads; params is the older list.
1843
1881
  const aparams: Value = h.getpath(&.{ "args", "params" }, point);
1844
1882
  // A header or cookie parameter travels in the headers, which prepare_headers
1845
- // fills, unless a query parameter shares its name: then both are sent.
1883
+ // fills, and a field the point's body declares travels in the body, which
1884
+ // prepare_body fills, unless a query parameter shares its name: then both
1885
+ // are sent.
1846
1886
  const aheader: Value = h.getpath(&.{ "args", "header" }, point);
1847
1887
  const acookie: Value = h.getpath(&.{ "args", "cookie" }, point);
1888
+ const fields: Value = h.getp(point, "fields");
1848
1889
  // A query parameter travels under the name the definition gives it, its
1849
1890
  // orig, which the model may have renamed for the caller.
1850
1891
  const aquery: Value = h.getpath(&.{ "args", "query" }, point);
@@ -1865,7 +1906,8 @@ pub fn prepare_query_util(ctx: *Context) Value {
1865
1906
  }
1866
1907
  }
1867
1908
  if (!contained) contained = names_key(aparams, key) or
1868
- ((names_key(aheader, key) or names_key(acookie, key)) and !names_key(aquery, key));
1909
+ ((names_key(aheader, key) or names_key(acookie, key) or listed(fields, key)) and
1910
+ !names_key(aquery, key));
1869
1911
  var wire: []const u8 = key;
1870
1912
  if (aquery == .array) {
1871
1913
  for (aquery.array.data.items) |qd| {
@@ -1886,7 +1928,8 @@ pub fn prepare_query_util(ctx: *Context) Value {
1886
1928
  // A create or update passes its query arguments in its data.
1887
1929
  for (call_args(ctx, "query")) |arg| {
1888
1930
  var contained = h.is_noval(arg.val) or names_key(aparams, arg.name) or
1889
- ((names_key(aheader, arg.name) or names_key(acookie, arg.name)) and !names_key(aquery, arg.name));
1931
+ ((names_key(aheader, arg.name) or names_key(acookie, arg.name) or listed(fields, arg.name)) and
1932
+ !names_key(aquery, arg.name));
1890
1933
  if (params == .array) {
1891
1934
  for (params.array.data.items) |v| {
1892
1935
  if (v == .string and std.mem.eql(u8, v.string, arg.name)) contained = true;
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen",
6
- "version": "4.48.0",
6
+ "version": "4.48.1",
7
7
  "provides": {
8
8
  "target": [
9
9
  "c",
package/src/utility.ts CHANGED
@@ -286,6 +286,17 @@ const SPEC_FACTS: Record<string, (model: any) => any> = {
286
286
  const ROUTED_KINDS = ['header', 'cookie', 'query']
287
287
 
288
288
 
289
+ // A list, load or remove takes a match, not data. Routed to a method that
290
+ // carries a body, it sends the fields that body declares there.
291
+ const MATCH_OPS = ['list', 'load', 'remove']
292
+ const BODY_METHODS = ['POST', 'PUT', 'PATCH']
293
+
294
+ function matchBodyFields(opname: string, pt: any): string[] | undefined {
295
+ return MATCH_OPS.includes(opname) && BODY_METHODS.includes(String(pt.m).toUpperCase()) &&
296
+ Array.isArray(pt.bf) && 0 < pt.bf.length ? [...pt.bf] : undefined
297
+ }
298
+
299
+
289
300
  // `alias` names the record field an entity keeps its identity in, where that is
290
301
  // not the parameter's own name, so an entity a list returned can address itself.
291
302
  function withPointParts(
@@ -315,7 +326,7 @@ function withPointParts(
315
326
  active: pt.a, kind: pt.k, method: pt.m, orig: pt.o,
316
327
  segments: pt.s, parts: pointParts(pt), rename: pt.r,
317
328
  transform: pt.t, args, select: pt.q, live: pt.li, graphql: pointGraphql(pt),
318
- body: pt.rb, response: pt.rs, alias,
329
+ body: pt.rb, response: pt.rs, alias, fields: matchBodyFields(opname, pt),
319
330
  }
320
331
  }),
321
332
  }