@voxgig/sdkgen 3.5.1 → 3.6.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 (171) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ExternalTarget.js +1 -1
  3. package/dist/cmp/ExternalTarget.js.map +1 -1
  4. package/dist/helpers/naming.d.ts +4 -1
  5. package/dist/helpers/naming.js +119 -5
  6. package/dist/helpers/naming.js.map +1 -1
  7. package/dist/helpers/opShape.js +72 -0
  8. package/dist/helpers/opShape.js.map +1 -1
  9. package/dist/helpers/packageMeta.d.ts +2 -1
  10. package/dist/helpers/packageMeta.js +57 -20
  11. package/dist/helpers/packageMeta.js.map +1 -1
  12. package/dist/sdkgen.d.ts +3 -3
  13. package/dist/sdkgen.js +61 -18
  14. package/dist/sdkgen.js.map +1 -1
  15. package/dist/testkit.d.ts +39 -0
  16. package/dist/testkit.js +663 -0
  17. package/dist/testkit.js.map +1 -0
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/package.json +32 -8
  20. package/project/.sdk/src/cmp/c/Test_c.ts +5 -7
  21. package/project/.sdk/src/cmp/clojure/Test_clojure.ts +3 -7
  22. package/project/.sdk/src/cmp/cpp/Test_cpp.ts +4 -7
  23. package/project/.sdk/src/cmp/csharp/Package_csharp.ts +1 -1
  24. package/project/.sdk/src/cmp/csharp/Test_csharp.ts +5 -7
  25. package/project/.sdk/src/cmp/dart/Test_dart.ts +3 -4
  26. package/project/.sdk/src/cmp/elixir/Package_elixir.ts +1 -1
  27. package/project/.sdk/src/cmp/elixir/Test_elixir.ts +5 -6
  28. package/project/.sdk/src/cmp/go/EntityTypes_go.ts +1 -1
  29. package/project/.sdk/src/cmp/go/Entity_go.ts +1 -1
  30. package/project/.sdk/src/cmp/go/Gitignore_go.ts +6 -0
  31. package/project/.sdk/src/cmp/go/Main_go.ts +2 -2
  32. package/project/.sdk/src/cmp/go/Package_go.ts +1 -1
  33. package/project/.sdk/src/cmp/go/ReadmeExamplesTest_go.ts +59 -6
  34. package/project/.sdk/src/cmp/go/ReadmeExplanation_go.ts +1 -1
  35. package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +1 -1
  36. package/project/.sdk/src/cmp/go/ReadmeInstall_go.ts +1 -1
  37. package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +1 -1
  38. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
  39. package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +1 -1
  40. package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +1 -1
  41. package/project/.sdk/src/cmp/go/Test_go.ts +6 -8
  42. package/project/.sdk/src/cmp/go-cli/Main_go-cli.ts +6 -2
  43. package/project/.sdk/src/cmp/go-mcp/Main_go-mcp.ts +6 -2
  44. package/project/.sdk/src/cmp/java/Test_java.ts +4 -7
  45. package/project/.sdk/src/cmp/js/Package_js.ts +1 -1
  46. package/project/.sdk/src/cmp/js/Test_js.ts +4 -7
  47. package/project/.sdk/src/cmp/kotlin/Test_kotlin.ts +4 -7
  48. package/project/.sdk/src/cmp/lean/Test_lean.ts +3 -3
  49. package/project/.sdk/src/cmp/lua/Package_lua.ts +2 -2
  50. package/project/.sdk/src/cmp/lua/Test_lua.ts +5 -7
  51. package/project/.sdk/src/cmp/ocaml/Test_ocaml.ts +3 -7
  52. package/project/.sdk/src/cmp/perl/Package_perl.ts +1 -1
  53. package/project/.sdk/src/cmp/perl/Test_perl.ts +5 -7
  54. package/project/.sdk/src/cmp/php/EntityTypes_php.ts +13 -2
  55. package/project/.sdk/src/cmp/php/Package_php.ts +2 -2
  56. package/project/.sdk/src/cmp/php/Test_php.ts +5 -7
  57. package/project/.sdk/src/cmp/py/Package_py.ts +2 -2
  58. package/project/.sdk/src/cmp/py/Test_py.ts +5 -7
  59. package/project/.sdk/src/cmp/py-data/Main_py-data.ts +14 -19
  60. package/project/.sdk/src/cmp/rb/Package_rb.ts +3 -3
  61. package/project/.sdk/src/cmp/rb/ReadmeInstall_rb.ts +1 -1
  62. package/project/.sdk/src/cmp/rb/Test_rb.ts +5 -7
  63. package/project/.sdk/src/cmp/rust/Test_rust.ts +5 -7
  64. package/project/.sdk/src/cmp/scala/Test_scala.ts +5 -2
  65. package/project/.sdk/src/cmp/seneca-provider/Gitignore_seneca-provider.ts +161 -0
  66. package/project/.sdk/src/cmp/seneca-provider/Main_seneca-provider.ts +20 -11
  67. package/project/.sdk/src/cmp/swift/Test_swift.ts +5 -7
  68. package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
  69. package/project/.sdk/src/cmp/ts/Test_ts.ts +8 -7
  70. package/project/.sdk/src/cmp/zig/Test_zig.ts +3 -7
  71. package/project/.sdk/tm/c/utility/make_point.c +64 -3
  72. package/project/.sdk/tm/clojure/src/sdk/core.clj +49 -14
  73. package/project/.sdk/tm/cpp/utility/pipeline.hpp +55 -3
  74. package/project/.sdk/tm/csharp/feature/TestFeature.cs +36 -2
  75. package/project/.sdk/tm/csharp/utility/MakePoint.cs +65 -2
  76. package/project/.sdk/tm/dart/lib/feature/test/TestFeature.dart +34 -4
  77. package/project/.sdk/tm/dart/lib/utility/MakePointUtility.dart +48 -2
  78. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +70 -10
  79. package/project/.sdk/tm/go/feature/test_feature.go +34 -2
  80. package/project/.sdk/tm/go/utility/make_point.go +66 -2
  81. package/project/.sdk/tm/java/feature/TestFeature.java +42 -2
  82. package/project/.sdk/tm/java/utility/MakePoint.java +61 -2
  83. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +22 -3
  84. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +72 -2
  85. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +31 -2
  86. package/project/.sdk/tm/kotlin/utility/MakePoint.kt +58 -2
  87. package/project/.sdk/tm/lean/src/SdkUtility.lean +28 -0
  88. package/project/.sdk/tm/lua/utility/make_point.lua +65 -2
  89. package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -2
  90. package/project/.sdk/tm/perl/utility/make_point.pm +55 -2
  91. package/project/.sdk/tm/php/feature/TestFeature.php +30 -1
  92. package/project/.sdk/tm/php/utility/MakePoint.php +49 -1
  93. package/project/.sdk/tm/py/pkg/utility/make_point.py +56 -2
  94. package/project/.sdk/tm/rb/utility/make_point.rb +42 -2
  95. package/project/.sdk/tm/rust/utility/make_point.rs +69 -2
  96. package/project/.sdk/tm/scala/feature/TestFeature.scala +36 -1
  97. package/project/.sdk/tm/scala/utility/Make.scala +57 -3
  98. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +29 -1
  99. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +51 -2
  100. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +22 -3
  101. package/project/.sdk/tm/ts/src/utility/MakePointUtility.ts +72 -2
  102. package/project/.sdk/tm/zig/core/utility.zig +66 -3
  103. package/project/sdkgen-package.json +1 -2
  104. package/src/cmp/ExternalTarget.ts +1 -1
  105. package/src/helpers/naming.ts +129 -5
  106. package/src/helpers/opShape.ts +85 -0
  107. package/src/helpers/packageMeta.ts +59 -20
  108. package/src/sdkgen.ts +68 -20
  109. package/src/testkit.ts +863 -0
  110. package/testkit.d.ts +3 -0
  111. package/testkit.js +12 -0
  112. package/project/.sdk/model/target/haskell.aontu +0 -72
  113. package/project/.sdk/src/cmp/haskell/Config_haskell.ts +0 -98
  114. package/project/.sdk/src/cmp/haskell/Entity_haskell.ts +0 -13
  115. package/project/.sdk/src/cmp/haskell/Gitignore_haskell.ts +0 -27
  116. package/project/.sdk/src/cmp/haskell/Main_haskell.ts +0 -123
  117. package/project/.sdk/src/cmp/haskell/Package_haskell.ts +0 -60
  118. package/project/.sdk/src/cmp/haskell/ReadmeEntity_haskell.ts +0 -186
  119. package/project/.sdk/src/cmp/haskell/ReadmeExamplesTest_haskell.ts +0 -135
  120. package/project/.sdk/src/cmp/haskell/ReadmeExplanation_haskell.ts +0 -48
  121. package/project/.sdk/src/cmp/haskell/ReadmeHowto_haskell.ts +0 -168
  122. package/project/.sdk/src/cmp/haskell/ReadmeInstall_haskell.ts +0 -51
  123. package/project/.sdk/src/cmp/haskell/ReadmeIntro_haskell.ts +0 -67
  124. package/project/.sdk/src/cmp/haskell/ReadmeModel_haskell.ts +0 -162
  125. package/project/.sdk/src/cmp/haskell/ReadmeOptions_haskell.ts +0 -74
  126. package/project/.sdk/src/cmp/haskell/ReadmeQuick_haskell.ts +0 -241
  127. package/project/.sdk/src/cmp/haskell/ReadmeRef_haskell.ts +0 -408
  128. package/project/.sdk/src/cmp/haskell/ReadmeTopHowto_haskell.ts +0 -31
  129. package/project/.sdk/src/cmp/haskell/ReadmeTopQuick_haskell.ts +0 -104
  130. package/project/.sdk/src/cmp/haskell/ReadmeTopTest_haskell.ts +0 -80
  131. package/project/.sdk/src/cmp/haskell/Test_haskell.ts +0 -300
  132. package/project/.sdk/src/cmp/haskell/tsconfig.json +0 -15
  133. package/project/.sdk/src/cmp/haskell/utility_haskell.ts +0 -166
  134. package/project/.sdk/tm/haskell/LICENSE +0 -21
  135. package/project/.sdk/tm/haskell/Makefile +0 -22
  136. package/project/.sdk/tm/haskell/VERSION +0 -1
  137. package/project/.sdk/tm/haskell/src/SdkFeatures.hs +0 -1440
  138. package/project/.sdk/tm/haskell/src/SdkHelpers.hs +0 -337
  139. package/project/.sdk/tm/haskell/src/SdkJson.hs +0 -111
  140. package/project/.sdk/tm/haskell/src/SdkRuntime.hs +0 -1219
  141. package/project/.sdk/tm/haskell/src/SdkTypes.hs +0 -195
  142. package/project/.sdk/tm/haskell/src/VoxgigStruct.hs +0 -2299
  143. package/project/.sdk/tm/haskell/src/Vregex.hs +0 -237
  144. package/project/.sdk/tm/haskell/src/feature/README.md +0 -5
  145. package/project/.sdk/tm/haskell/src/feature/audit/.gitkeep +0 -0
  146. package/project/.sdk/tm/haskell/src/feature/base/.gitkeep +0 -0
  147. package/project/.sdk/tm/haskell/src/feature/cache/.gitkeep +0 -0
  148. package/project/.sdk/tm/haskell/src/feature/clienttrack/.gitkeep +0 -0
  149. package/project/.sdk/tm/haskell/src/feature/debug/.gitkeep +0 -0
  150. package/project/.sdk/tm/haskell/src/feature/idempotency/.gitkeep +0 -0
  151. package/project/.sdk/tm/haskell/src/feature/log/.gitkeep +0 -0
  152. package/project/.sdk/tm/haskell/src/feature/metrics/.gitkeep +0 -0
  153. package/project/.sdk/tm/haskell/src/feature/netsim/.gitkeep +0 -0
  154. package/project/.sdk/tm/haskell/src/feature/paging/.gitkeep +0 -0
  155. package/project/.sdk/tm/haskell/src/feature/proxy/.gitkeep +0 -0
  156. package/project/.sdk/tm/haskell/src/feature/ratelimit/.gitkeep +0 -0
  157. package/project/.sdk/tm/haskell/src/feature/rbac/.gitkeep +0 -0
  158. package/project/.sdk/tm/haskell/src/feature/retry/.gitkeep +0 -0
  159. package/project/.sdk/tm/haskell/src/feature/streaming/.gitkeep +0 -0
  160. package/project/.sdk/tm/haskell/src/feature/telemetry/.gitkeep +0 -0
  161. package/project/.sdk/tm/haskell/src/feature/test/.gitkeep +0 -0
  162. package/project/.sdk/tm/haskell/src/feature/timeout/.gitkeep +0 -0
  163. package/project/.sdk/tm/haskell/test/Harness.hs +0 -281
  164. package/project/.sdk/tm/haskell/test/Runner.hs +0 -47
  165. package/project/.sdk/tm/haskell/test/StructCorpus.hs +0 -449
  166. package/project/.sdk/tm/haskell/test/TCustomUtility.hs +0 -38
  167. package/project/.sdk/tm/haskell/test/TFeature.hs +0 -794
  168. package/project/.sdk/tm/haskell/test/TNetsim.hs +0 -50
  169. package/project/.sdk/tm/haskell/test/TPipeline.hs +0 -334
  170. package/project/.sdk/tm/haskell/test/TPrimaryUtility.hs +0 -386
  171. package/project/.sdk/tm/haskell/test/Testutil.hs +0 -59
@@ -1,408 +0,0 @@
1
-
2
- import { cmp, each, Content, canonKey, File, isAuthActive, entityIdField, opRequestShape } from '@voxgig/sdkgen'
3
-
4
- import {
5
- KIT,
6
- getModelPath,
7
- } from '@voxgig/apidef'
8
-
9
- import { hsVarName } from './utility_haskell'
10
-
11
-
12
- // A type-correct Haskell `Value` literal for a field's canonical type.
13
- function hsLit(type: any, placeholder: string = 'example'): string {
14
- const k = canonKey(type)
15
- if ('INTEGER' === k || 'NUMBER' === k) return 'VNum 1'
16
- if ('BOOLEAN' === k) return 'VBool True'
17
- if ('ARRAY' === k || 'OBJECT' === k) return 'VNoval'
18
- return `VStr "${placeholder}"`
19
- }
20
-
21
-
22
- // A readable Haskell type name for a field's canonical type.
23
- function hsType(type: any): string {
24
- const k = canonKey(type)
25
- if ('STRING' === k) return 'String'
26
- if ('INTEGER' === k) return 'Int'
27
- if ('NUMBER' === k) return 'Double'
28
- if ('BOOLEAN' === k) return 'Bool'
29
- if ('ARRAY' === k) return '[Value]'
30
- return 'Value'
31
- }
32
-
33
-
34
- const OP_SIGNATURES: Record<string, { sig: string, returns: string, desc: string }> = {
35
- load: {
36
- sig: 'eLoad ent match ctrl :: IO Entity',
37
- returns: 'the entity',
38
- desc: 'Load a single entity matching the given criteria. Resolves to the ENTITY (read the record with `eDataGet`) and raises on error.',
39
- },
40
- list: {
41
- sig: 'eList ent match ctrl :: IO [Entity]',
42
- returns: 'one entity per record',
43
- desc: 'List entities matching the given criteria. The match is optional \u2014 pass an empty map to list all records. Resolves to one ENTITY per record and raises on error.',
44
- },
45
- create: {
46
- sig: 'eCreate ent data ctrl :: IO Entity',
47
- returns: 'the created entity',
48
- desc: 'Create a new entity with the given data. Resolves to the ENTITY (read the record with `eDataGet`) and raises on error.',
49
- },
50
- update: {
51
- sig: 'eUpdate ent data ctrl :: IO Entity',
52
- returns: 'the updated entity',
53
- desc: 'Update an existing entity. The data must include the entity `id`. Resolves to the ENTITY (read the record with `eDataGet`) and raises on error.',
54
- },
55
- remove: {
56
- sig: 'eRemove ent match ctrl :: IO Entity',
57
- returns: 'the removed entity',
58
- desc: 'Remove the entity matching the given criteria. Resolves to the ENTITY, marked deleted (`eDeleted`); it keeps the data it held. Raises on error.',
59
- },
60
- }
61
-
62
-
63
- const ReadmeRef = cmp(function ReadmeRef(props: any) {
64
- const { target } = props
65
- const { model } = props.ctx$
66
-
67
- const entity = getModelPath(model, `main.${KIT}.entity`)
68
- const feature = getModelPath(model, `main.${KIT}.feature`)
69
-
70
- const publishedEntities = each(entity).filter((e: any) => e.active !== false)
71
-
72
-
73
- File({ name: 'REFERENCE.md' }, () => {
74
-
75
- Content(`# ${model.Name} ${target.title} SDK Reference
76
-
77
- Complete API reference for the ${model.Name} ${target.title} SDK.
78
-
79
-
80
- ## Client
81
-
82
- ### Constructors
83
-
84
- \`\`\`haskell
85
- import qualified SdkClient as Sdk
86
- import VoxgigStruct (Value (..))
87
- import SdkHelpers (jo)
88
-
89
- makeClient :: IO Sdk.Client
90
- makeClient = do
91
- opts <- jo [("base", VStr "https://api.example.com")]
92
- Sdk.newSdk opts
93
- \`\`\`
94
-
95
- Construct a live SDK client.
96
-
97
- **Functions:**
98
-
99
- | Function | Signature | Description |
100
- | --- | --- | --- |
101
- | \`newSdk\` | \`Value -> IO Client\` | Construct a client from an options map. |
102
- | \`newSdk0\` | \`IO Client\` | Construct a client with defaults. |
103
-
104
- **Options (map keys):**
105
-
106
- | Key | Type | Description |
107
- | --- | --- | --- |
108
- ${isAuthActive(model) ? '| `apikey` | `String` | API key for authentication. |\n' : ''}| \`base\` | \`String\` | Base URL for API requests. |
109
- | \`prefix\` | \`String\` | URL prefix appended after base. |
110
- | \`suffix\` | \`String\` | URL suffix appended after path. |
111
- | \`headers\` | \`Value\` | Custom headers for all requests. |
112
- | \`feature\` | \`Value\` | Feature configuration. |
113
- | \`system\` | \`Value\` | System overrides (e.g. custom fetch). |
114
-
115
-
116
- ### Test constructors
117
-
118
- \`\`\`haskell
119
- client <- Sdk.testSdk0
120
- \`\`\`
121
-
122
- \`testSdk :: Value -> Value -> IO Client\` constructs a test client with mock
123
- features active (\`testSdk0 :: IO Client\` for the no-argument form). Pass
124
- \`VNoval\` for defaults.
125
-
126
-
127
- ### Entity accessors
128
-
129
- `)
130
-
131
-
132
- // Entity factory functions
133
- publishedEntities.map((ent: any) => {
134
- const eFn = hsVarName(ent.name)
135
- Content(`#### \`${eFn} :: Client -> Value -> IO Entity\`
136
-
137
- Construct a \`${ent.Name}\` entity bound to the client. Pass \`VNoval\` for no initial options.
138
-
139
- `)
140
- })
141
-
142
-
143
- Content(`### HTTP escape hatches
144
-
145
- #### \`direct :: Client -> Value -> IO Value\` (module \`SdkFeatures\`)
146
-
147
- Make a direct HTTP request to any API endpoint. Returns a result \`Value\` with
148
- \`ok\`, \`status\`, \`headers\`, and \`data\` (or \`err\` on failure). This escape
149
- hatch never raises — branch on \`getp result "ok"\`.
150
-
151
- **Argument (map keys):**
152
-
153
- | Key | Type | Description |
154
- | --- | --- | --- |
155
- | \`path\` | \`String\` | URL path with optional \`{param}\` placeholders. |
156
- | \`method\` | \`String\` | HTTP method (default: \`"GET"\`). |
157
- | \`params\` | \`Value\` | Path parameter values. |
158
- | \`query\` | \`Value\` | Query string parameters. |
159
- | \`headers\` | \`Value\` | Request headers (merged with defaults). |
160
- | \`body\` | \`Value\` | Request body (maps are JSON-serialized). |
161
-
162
- #### \`prepare :: Client -> Value -> IO Value\` (module \`SdkFeatures\`)
163
-
164
- Prepare a fetch definition without sending. Returns the \`fetchdef\` and raises on error.
165
-
166
- `)
167
-
168
-
169
- // Entity reference sections
170
- publishedEntities.map((ent: any) => {
171
- const opnames = Object.keys(ent.op || {})
172
- const fields = ent.fields || []
173
- const idF = entityIdField(ent)
174
- const eFn = hsVarName(ent.name)
175
-
176
- Content(`
177
- ---
178
-
179
- ## ${ent.Name}
180
-
181
- `)
182
-
183
- if (ent.short) {
184
- Content(`${ent.short}
185
-
186
- `)
187
- }
188
-
189
- Content(`\`\`\`haskell
190
- ent <- Sdk.${eFn} sdk VNoval
191
- \`\`\`
192
-
193
- `)
194
-
195
-
196
- // Field schema
197
- if (fields.length > 0) {
198
- Content(`### Fields
199
-
200
- | Field | Type | Required | Description |
201
- | --- | --- | --- | --- |
202
- `)
203
- each(fields, (field: any) => {
204
- const req = field.req ? 'Yes' : 'No'
205
- const desc = field.short || ''
206
- Content(`| \`${field.name}\` | \`${hsType(field.type)}\` | ${req} | ${desc} |
207
- `)
208
- })
209
-
210
- Content(`
211
- `)
212
-
213
- // Field operations breakdown
214
- const hasFieldOps = fields.some((f: any) => f.op && Object.keys(f.op).length > 0)
215
- if (hasFieldOps) {
216
- const opcols = ['load', 'list', 'create', 'update', 'remove']
217
- .filter((op: string) => opnames.includes(op) && ent.op[op]?.active !== false)
218
- Content(`### Field Usage by Operation
219
-
220
- | Field | ${opcols.join(' | ')} |
221
- | --- | ${opcols.map(() => '---').join(' | ')} |
222
- `)
223
- each(fields, (field: any) => {
224
- const fops = field.op || {}
225
- const cols = opcols.map((op: string) => {
226
- const fop = fops[op]
227
- if (null == fop) return '-'
228
- if (fop.active === false) return '-'
229
- return 'Yes'
230
- })
231
- Content(`| \`${field.name}\` | ${cols.join(' | ')} |
232
- `)
233
- })
234
-
235
- Content(`
236
- `)
237
- }
238
- }
239
-
240
-
241
- // Operation details
242
- if (opnames.length > 0) {
243
- Content(`### Operations
244
-
245
- `)
246
-
247
- opnames.map((opname: string) => {
248
- const info = OP_SIGNATURES[opname]
249
- if (!info) return
250
-
251
- Content(`#### \`${info.sig}\`
252
-
253
- ${info.desc}
254
-
255
- `)
256
-
257
- if ('load' === opname || 'remove' === opname) {
258
- const matchItems = opRequestShape(ent, opname).items
259
- .filter((it: any) => !it.optional || it.name === idF)
260
- .sort((a: any, b: any) =>
261
- (a.name === idF ? 0 : 1) - (b.name === idF ? 0 : 1))
262
- const arg = 0 < matchItems.length
263
- ? `[${matchItems.map((it: any) =>
264
- `("${it.name}", ${hsLit(it.type,
265
- it.name === idF ? ent.name + '_id' : it.name)})`).join(', ')}]`
266
- : '[]'
267
- Content(`\`\`\`haskell
268
- ent <- Sdk.${eFn} sdk VNoval
269
- match <- jo ${arg}
270
- ctrl <- emptyMap
271
- result <- Sdk.e${opname.charAt(0).toUpperCase() + opname.slice(1)} ent match ctrl
272
- \`\`\`
273
-
274
- `)
275
- }
276
- else if ('list' === opname) {
277
- Content(`\`\`\`haskell
278
- ent <- Sdk.${eFn} sdk VNoval
279
- match <- emptyMap
280
- ctrl <- emptyMap
281
- results <- Sdk.eList ent match ctrl -- one ENTITY per record
282
- datas <- mapM Sdk.eDataGet results
283
- \`\`\`
284
-
285
- `)
286
- }
287
- else if ('create' === opname) {
288
- const createItems = opRequestShape(ent, 'create').items
289
- .filter((it: any) => !it.optional)
290
- Content(`\`\`\`haskell
291
- ent <- Sdk.${eFn} sdk VNoval
292
- d <- jo
293
- [`)
294
- createItems.map((it: any, i: number) => {
295
- const bracket = 0 === i ? ' ' : ', '
296
- Content(`${bracket}("${it.name}", ${hsLit(it.type, 'example_' + it.name)}) -- ${hsType(it.type)}
297
- `)
298
- })
299
- Content(`]
300
- ctrl <- emptyMap
301
- result <- Sdk.eCreate ent d ctrl -- the ENTITY
302
- d2 <- Sdk.eDataGet result
303
- \`\`\`
304
-
305
- `)
306
- }
307
- else if ('update' === opname) {
308
- const updateItems = opRequestShape(ent, 'update').items
309
- .filter((it: any) => !it.optional || it.name === idF)
310
- .sort((a: any, b: any) =>
311
- (a.name === idF ? 0 : 1) - (b.name === idF ? 0 : 1))
312
- const updateLines = updateItems.map((it: any, i: number) => {
313
- const bracket = 0 === i ? ' ' : ', '
314
- return `${bracket}("${it.name}", ${hsLit(it.type,
315
- it.name === idF ? ent.name + '_id' : it.name)})`
316
- }).join('\n ')
317
- Content(`\`\`\`haskell
318
- ent <- Sdk.${eFn} sdk VNoval
319
- d <- jo
320
- [${updateLines}
321
- ] -- fields to update
322
- ctrl <- emptyMap
323
- result <- Sdk.eUpdate ent d ctrl -- the ENTITY
324
- d2 <- Sdk.eDataGet result
325
- \`\`\`
326
-
327
- `)
328
- }
329
- })
330
- }
331
-
332
-
333
- // Common methods
334
- Content(`### Common Fields
335
-
336
- #### \`eDataGet :: IO Value\`
337
-
338
- Get the entity data.
339
-
340
- #### \`eDataSet :: Value -> IO ()\`
341
-
342
- Set the entity data.
343
-
344
- #### \`eStream :: String -> Value -> Value -> IO [Value]\`
345
-
346
- Run an operation as a lazy stream of result items.
347
-
348
- #### \`eMake :: IO Entity\`
349
-
350
- Create a new \`${ent.Name}\` entity with the same options.
351
-
352
- #### \`eName :: String\`
353
-
354
- The entity name.
355
-
356
- `)
357
- })
358
-
359
-
360
- // Features section
361
- const activeFeatures = each(feature).filter((f: any) => f.active)
362
- if (activeFeatures.length > 0) {
363
- Content(`
364
- ---
365
-
366
- ## Features
367
-
368
- | Feature | Version | Description |
369
- | --- | --- | --- |
370
- `)
371
-
372
- activeFeatures.map((f: any) => {
373
- Content(`| \`${f.name}\` | ${f.version || '0.0.1'} | ${f.title || ''} |
374
- `)
375
- })
376
-
377
- Content(`
378
-
379
- Features are activated via the \`feature\` option:
380
-
381
- `)
382
-
383
- Content(`\`\`\`haskell
384
- active <- jo [("active", VBool True)]
385
- featureCfg <- jo
386
- [`)
387
- activeFeatures.map((f: any, i: number) => {
388
- const bracket = 0 === i ? ' ' : ', '
389
- Content(`${bracket}("${f.name}", active)
390
- `)
391
- })
392
- Content(`]
393
- opts <- jo [("feature", featureCfg)]
394
- client <- Sdk.newSdk opts
395
- \`\`\`
396
-
397
- `)
398
- }
399
-
400
- })
401
- })
402
-
403
-
404
-
405
-
406
- export {
407
- ReadmeRef
408
- }
@@ -1,31 +0,0 @@
1
-
2
- import { cmp, Content } from '@voxgig/sdkgen'
3
-
4
-
5
- const ReadmeTopHowto = cmp(function ReadmeTopHowto(props: any) {
6
- const { target } = props
7
-
8
- Content(`**Haskell:**
9
- \`\`\`haskell
10
- import qualified SdkClient as Sdk
11
- import qualified SdkFeatures as F
12
- import VoxgigStruct (Value (..))
13
- import SdkHelpers (jo)
14
-
15
- main :: IO ()
16
- main = do
17
- sdk <- Sdk.newSdk0
18
- params <- jo [("id", VStr "example")]
19
- args <- jo [("path", VStr "/api/resource/{id}"), ("method", VStr "GET"), ("params", params)]
20
- result <- F.direct sdk args
21
- print result
22
- \`\`\`
23
-
24
- `)
25
-
26
- })
27
-
28
-
29
- export {
30
- ReadmeTopHowto
31
- }
@@ -1,104 +0,0 @@
1
-
2
- import { cmp, Content, isAuthActive, envName, canonKey, entityIdField, opRequestShape } from '@voxgig/sdkgen'
3
-
4
- import {
5
- KIT,
6
- getModelPath,
7
- nom,
8
- } from '@voxgig/apidef'
9
-
10
- import { hsVarName } from './utility_haskell'
11
-
12
-
13
- // A type-correct Haskell `Value` literal for a param.
14
- function hsLit(type: any, placeholder: string = 'example'): string {
15
- const k = canonKey(type)
16
- if ('INTEGER' === k || 'NUMBER' === k) return 'VNum 1'
17
- if ('BOOLEAN' === k) return 'VBool True'
18
- if ('ARRAY' === k || 'OBJECT' === k) return 'VNoval'
19
- return `VStr "${placeholder}"`
20
- }
21
-
22
-
23
- const ReadmeTopQuick = cmp(function ReadmeTopQuick(props: any) {
24
- const { target, ctx$: { model } } = props
25
-
26
- const entity = getModelPath(model, `main.${KIT}.entity`)
27
-
28
- const exampleEntity = Object.values(entity).find((e: any) => e.active !== false) as any
29
-
30
- const authActive = isAuthActive(model)
31
-
32
- Content(`\`\`\`haskell
33
- `)
34
- if (authActive) {
35
- Content(`import System.Environment (lookupEnv)
36
- import qualified SdkClient as Sdk
37
- import VoxgigStruct (Value (..), emptyMap)
38
- import SdkHelpers (jo)
39
-
40
- main :: IO ()
41
- main = do
42
- mkey <- lookupEnv "${envName(model)}_APIKEY"
43
- opts <- jo [("apikey", maybe VNoval VStr mkey)]
44
- sdk <- Sdk.newSdk opts
45
- `)
46
- }
47
- else {
48
- Content(`import qualified SdkClient as Sdk
49
- import VoxgigStruct (Value (..), emptyMap)
50
- import SdkHelpers (jo)
51
-
52
- main :: IO ()
53
- main = do
54
- sdk <- Sdk.newSdk0
55
- `)
56
- }
57
-
58
- if (exampleEntity) {
59
- const eName = nom(exampleEntity, 'Name')
60
- const eFn = hsVarName(exampleEntity.name)
61
- const opnames = Object.keys(exampleEntity.op || {})
62
- const idF = entityIdField(exampleEntity)
63
-
64
- if (opnames.includes('list')) {
65
- Content(`
66
- -- List all ${eName.toLowerCase()}s (one ENTITY per record, raises on error)
67
- ent <- Sdk.${eFn} sdk VNoval
68
- match <- emptyMap
69
- ctrl <- emptyMap
70
- ${eFn}s <- Sdk.eList ent match ctrl
71
- mapM_ (\\en -> print =<< Sdk.eDataGet en) ${eFn}s
72
- `)
73
- }
74
-
75
- if (opnames.includes('load')) {
76
- const loadItems = opRequestShape(exampleEntity, 'load').items
77
- .filter((it: any) => !it.optional || it.name === idF)
78
- .sort((a: any, b: any) =>
79
- (a.name === idF ? 0 : 1) - (b.name === idF ? 0 : 1))
80
- const loadArg = 0 < loadItems.length
81
- ? `[${loadItems.map((it: any) =>
82
- `("${it.name}", ${hsLit(it.type,
83
- it.name === idF ? 'example_id' : 'example_' + it.name)})`).join(', ')}]`
84
- : '[]'
85
- Content(`
86
- -- Load a specific ${eName.toLowerCase()} (returns the ENTITY, raises on error)
87
- ent2 <- Sdk.${eFn} sdk VNoval
88
- m <- jo ${loadArg}
89
- ctrl2 <- emptyMap
90
- ${eFn} <- Sdk.eLoad ent2 m ctrl2
91
- print =<< Sdk.eDataGet ${eFn}
92
- `)
93
- }
94
- }
95
-
96
- Content(`\`\`\`
97
- `)
98
-
99
- })
100
-
101
-
102
- export {
103
- ReadmeTopQuick
104
- }
@@ -1,80 +0,0 @@
1
-
2
- import { cmp, Content, canonKey, entityIdField, pickExampleEntity, opRequestShape } from '@voxgig/sdkgen'
3
-
4
- import {
5
- KIT,
6
- getModelPath,
7
- nom,
8
- } from '@voxgig/apidef'
9
-
10
- import { hsVarName } from './utility_haskell'
11
-
12
-
13
- // A type-correct Haskell `Value` literal for a field's canonical type.
14
- function hsLit(type: any): string {
15
- const k = canonKey(type)
16
- if ('INTEGER' === k || 'NUMBER' === k) return 'VNum 1'
17
- if ('BOOLEAN' === k) return 'VBool True'
18
- if ('ARRAY' === k || 'OBJECT' === k) return 'VNoval'
19
- return 'VStr "example"'
20
- }
21
-
22
-
23
- const ReadmeTopTest = cmp(function ReadmeTopTest(props: any) {
24
- const { target, ctx$: { model } } = props
25
-
26
- const entity = getModelPath(model, `main.${KIT}.entity`)
27
-
28
- const { entity: exampleEntity, primaryOp } = pickExampleEntity(entity)
29
-
30
- Content(`\`\`\`haskell
31
- import qualified SdkClient as Sdk
32
- import VoxgigStruct (Value (..), emptyMap)
33
- import SdkHelpers (jo)
34
-
35
- main :: IO ()
36
- main = do
37
- sdk <- Sdk.testSdk0
38
- `)
39
-
40
- if (exampleEntity && primaryOp) {
41
- const eName = nom(exampleEntity, 'Name')
42
- const eFn = hsVarName(exampleEntity.name)
43
- const idF = entityIdField(exampleEntity)
44
- const isMatchOp = 'load' === primaryOp || 'remove' === primaryOp
45
- let argExpr = 'emptyMap'
46
- if (isMatchOp) {
47
- const items = opRequestShape(exampleEntity, primaryOp).items
48
- .filter((it: any) => !it.optional || it.name === idF)
49
- .sort((a: any, b: any) =>
50
- (a.name === idF ? 0 : 1) - (b.name === idF ? 0 : 1))
51
- argExpr = 0 < items.length
52
- ? `jo [${items.map((it: any) =>
53
- `("${it.name}", ${it.name === idF ? 'VStr "test01"' : hsLit(it.type)})`).join(', ')}]`
54
- : 'emptyMap'
55
- } else if ('create' === primaryOp || 'update' === primaryOp) {
56
- const items = opRequestShape(exampleEntity, primaryOp).items
57
- .filter((it: any) => it.name !== idF && it.name !== 'id')
58
- const required = items.filter((it: any) => !it.optional)
59
- const chosen = required.length ? required : items.slice(0, 3)
60
- argExpr = `jo [${chosen.map((it: any) => `("${it.name}", ${hsLit(it.type)})`).join(', ')}]`
61
- }
62
- const opCap = 'e' + primaryOp.charAt(0).toUpperCase() + primaryOp.slice(1)
63
- const resVar = hsVarName(exampleEntity.name) + ('list' === primaryOp ? 's' : '')
64
- Content(` ent <- Sdk.${eFn} sdk VNoval
65
- arg <- ${argExpr}
66
- ctrl <- emptyMap
67
- ${resVar} <- Sdk.${opCap} ent arg ctrl
68
- print ${resVar}
69
- `)
70
- }
71
-
72
- Content(`\`\`\`
73
- `)
74
-
75
- })
76
-
77
-
78
- export {
79
- ReadmeTopTest
80
- }