@voxgig/sdkgen 4.44.2 → 4.45.0

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 (43) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/AgentGuideFeature.js +2 -1
  3. package/dist/cmp/AgentGuideFeature.js.map +1 -1
  4. package/dist/helpers/facts.d.ts +3 -0
  5. package/dist/helpers/facts.js +57 -0
  6. package/dist/helpers/facts.js.map +1 -0
  7. package/dist/helpers/opShape.js +3 -6
  8. package/dist/helpers/opShape.js.map +1 -1
  9. package/dist/helpers/shipped.d.ts +2 -1
  10. package/dist/helpers/shipped.js +4 -0
  11. package/dist/helpers/shipped.js.map +1 -1
  12. package/dist/sdkgen.d.ts +2 -1
  13. package/dist/sdkgen.js +8 -4
  14. package/dist/sdkgen.js.map +1 -1
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/model/fact.aontu +15 -0
  17. package/package.json +1 -1
  18. package/project/.sdk/tm/c/utility/make_point.c +9 -5
  19. package/project/.sdk/tm/clojure/src/sdk/core.clj +7 -1
  20. package/project/.sdk/tm/cpp/utility/pipeline.hpp +15 -11
  21. package/project/.sdk/tm/csharp/utility/MakePoint.cs +19 -15
  22. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +13 -1
  23. package/project/.sdk/tm/go/utility/make_point.go +16 -12
  24. package/project/.sdk/tm/java/utility/MakePoint.java +18 -13
  25. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +13 -6
  26. package/project/.sdk/tm/kotlin/utility/MakePoint.kt +17 -12
  27. package/project/.sdk/tm/lua/utility/make_point.lua +14 -10
  28. package/project/.sdk/tm/ocaml/sdk_runtime.ml +8 -4
  29. package/project/.sdk/tm/perl/utility/make_point.pm +8 -4
  30. package/project/.sdk/tm/php/utility/MakePoint.php +9 -4
  31. package/project/.sdk/tm/py/pkg/utility/make_point.py +12 -8
  32. package/project/.sdk/tm/rb/utility/make_point.rb +8 -4
  33. package/project/.sdk/tm/rust/utility/make_point.rs +12 -8
  34. package/project/.sdk/tm/scala/utility/Make.scala +8 -4
  35. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +14 -11
  36. package/project/.sdk/tm/ts/src/utility/MakePointUtility.ts +13 -6
  37. package/project/.sdk/tm/zig/core/utility.zig +8 -5
  38. package/project/sdkgen-package.json +1 -1
  39. package/src/cmp/AgentGuideFeature.ts +2 -1
  40. package/src/helpers/facts.ts +74 -0
  41. package/src/helpers/opShape.ts +3 -7
  42. package/src/helpers/shipped.ts +5 -0
  43. package/src/sdkgen.ts +5 -0
@@ -0,0 +1,74 @@
1
+ import { readFileSync } from 'node:fs'
2
+
3
+ import { Aontu } from 'aontu'
4
+ import { KIT } from '@voxgig/apidef'
5
+
6
+ import { factRulesFile } from './shipped'
7
+
8
+
9
+ // No fact rule reads these, and they are most of a large model.
10
+ const UNREAD = ['entity', 'flow']
11
+
12
+
13
+ function isMap(v: any): boolean {
14
+ return null != v && 'object' === typeof v && !Array.isArray(v)
15
+ }
16
+
17
+
18
+ function copyFacts(from: any, to: any): void {
19
+ for (const [key, val] of Object.entries(from)) {
20
+ if ('fact' === key) {
21
+ to.fact = val
22
+ }
23
+ else if (isMap(val) && isMap(to[key])) {
24
+ copyFacts(val, to[key])
25
+ }
26
+ }
27
+ }
28
+
29
+
30
+ // Computes every fact once and writes it into the model beside what it
31
+ // describes, as `fact`. Templates read facts with `fact`; none computes one.
32
+ function applyFacts(model: any): any {
33
+ const kit = model?.main?.[KIT]
34
+ if (!isMap(kit)) {
35
+ return model
36
+ }
37
+
38
+ const input: any = {}
39
+ for (const [key, val] of Object.entries(kit)) {
40
+ if (!UNREAD.includes(key)) {
41
+ input[key] = val
42
+ }
43
+ }
44
+
45
+ const path = factRulesFile()
46
+ const src = JSON.stringify({ main: { [KIT]: input } }).slice(1, -1) +
47
+ '\n' + readFileSync(path, 'utf8')
48
+
49
+ const errs: any[] = []
50
+ const out = new Aontu().generate(src, { path, errs })
51
+ if (0 < errs.length || null == out?.main?.[KIT]) {
52
+ throw new Error('sdkgen facts: the fact rules did not evaluate: ' +
53
+ errs.map((e: any) => `[${e.why}] ${e.msg}`).join(' | '))
54
+ }
55
+
56
+ copyFacts(out.main[KIT], kit)
57
+ return model
58
+ }
59
+
60
+
61
+ function fact(node: any, name: string): any {
62
+ const facts = node?.fact
63
+ if (!isMap(facts) || !(name in facts)) {
64
+ throw new Error(`sdkgen facts: '${node?.name ?? '?'}' has no fact '${name}': ` +
65
+ 'the model did not pass through applyFacts, or lacks what the fact reads')
66
+ }
67
+ return facts[name]
68
+ }
69
+
70
+
71
+ export {
72
+ applyFacts,
73
+ fact,
74
+ }
@@ -140,24 +140,20 @@ function samePath(points: any[]): boolean {
140
140
  }
141
141
 
142
142
 
143
- // The rule makePoint applies: a lone point is taken as it is, otherwise only
144
- // a point without an action, and one the call fills.
143
+ // The rule makePoint applies to a call without an action: only a point
144
+ // without one, and one the call fills.
145
145
  function opReachable(op: any, given: string[]): boolean {
146
146
  const points: any[] = op && op.points ? each(op.points) : []
147
147
  const have = new Set(given)
148
148
  const fills = (pt: any) => pointPlaceholders(pt).every((name) => have.has(name))
149
149
 
150
- if (1 === points.length) {
151
- return fills(points[0])
152
- }
153
-
154
150
  return points.some((pt: any) => null == (pt && pt.q && pt.q['$action']) && fills(pt))
155
151
  }
156
152
 
157
153
 
158
154
  function opNeedsAction(op: any): boolean {
159
155
  const points: any[] = op && op.points ? each(op.points) : []
160
- return 1 < points.length &&
156
+ return 0 < points.length &&
161
157
  points.every((pt: any) => null != (pt && pt.q && pt.q['$action']))
162
158
  }
163
159
 
@@ -19,8 +19,13 @@ function scaffoldFolder(): string {
19
19
  }
20
20
 
21
21
 
22
+ function factRulesFile(): string {
23
+ return Path.join(packageRoot(), 'model', 'fact.aontu')
24
+ }
25
+
22
26
  export {
23
27
  packageRoot,
24
28
  schemaFile,
25
29
  scaffoldFolder,
30
+ factRulesFile,
26
31
  }
package/src/sdkgen.ts CHANGED
@@ -65,6 +65,7 @@ import { getMatchEntries } from './helpers/getMatchEntries'
65
65
  import { collectDeps } from './helpers/collectDeps'
66
66
  import { guardModelNames } from './helpers/modelNames'
67
67
  import { guardFlowSteps } from './helpers/flowGuard'
68
+ import { applyFacts, fact } from './helpers/facts'
68
69
  import { claimedFiles, pruneGenerated } from './helpers/generated'
69
70
  import { cmp as labelledCmp } from './helpers/component'
70
71
  import type { DepEntry } from './helpers/collectDeps'
@@ -332,6 +333,8 @@ function SdkGen(opts: SdkGenOptions) {
332
333
  // generated test makes it; see helpers/flowGuard.
333
334
  guardFlowSteps(model, log)
334
335
 
336
+ applyFacts(model)
337
+
335
338
  let Root = spec.root
336
339
 
337
340
  if (null == Root && null != config?.root) {
@@ -1190,6 +1193,8 @@ export {
1190
1193
  entityCollection,
1191
1194
  guardModelNames,
1192
1195
  guardFlowSteps,
1196
+ applyFacts,
1197
+ fact,
1193
1198
  projectConst,
1194
1199
  isReservedName,
1195
1200
  safeVarName,