@voxgig/sdkgen 3.5.0 → 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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/ExternalTarget.js +1 -1
- package/dist/cmp/ExternalTarget.js.map +1 -1
- package/dist/helpers/naming.d.ts +4 -1
- package/dist/helpers/naming.js +119 -5
- package/dist/helpers/naming.js.map +1 -1
- package/dist/helpers/opShape.js +72 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/packageMeta.d.ts +2 -1
- package/dist/helpers/packageMeta.js +57 -20
- package/dist/helpers/packageMeta.js.map +1 -1
- package/dist/sdkgen.d.ts +3 -3
- package/dist/sdkgen.js +61 -18
- package/dist/sdkgen.js.map +1 -1
- package/dist/testkit.d.ts +39 -0
- package/dist/testkit.js +663 -0
- package/dist/testkit.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -8
- package/project/.sdk/src/cmp/c/Test_c.ts +5 -7
- package/project/.sdk/src/cmp/clojure/Test_clojure.ts +3 -7
- package/project/.sdk/src/cmp/cpp/Test_cpp.ts +4 -7
- package/project/.sdk/src/cmp/csharp/Package_csharp.ts +1 -1
- package/project/.sdk/src/cmp/csharp/Test_csharp.ts +5 -7
- package/project/.sdk/src/cmp/dart/Test_dart.ts +3 -4
- package/project/.sdk/src/cmp/elixir/Package_elixir.ts +1 -1
- package/project/.sdk/src/cmp/elixir/Test_elixir.ts +5 -6
- package/project/.sdk/src/cmp/go/EntityTypes_go.ts +1 -1
- package/project/.sdk/src/cmp/go/Entity_go.ts +1 -1
- package/project/.sdk/src/cmp/go/Gitignore_go.ts +6 -0
- package/project/.sdk/src/cmp/go/Main_go.ts +2 -2
- package/project/.sdk/src/cmp/go/Package_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeExamplesTest_go.ts +59 -6
- package/project/.sdk/src/cmp/go/ReadmeExplanation_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeInstall_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +1 -1
- package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +1 -1
- package/project/.sdk/src/cmp/go/Test_go.ts +6 -8
- package/project/.sdk/src/cmp/go-cli/Main_go-cli.ts +6 -2
- package/project/.sdk/src/cmp/go-mcp/Main_go-mcp.ts +6 -2
- package/project/.sdk/src/cmp/java/Test_java.ts +4 -7
- package/project/.sdk/src/cmp/js/Package_js.ts +1 -1
- package/project/.sdk/src/cmp/js/Test_js.ts +4 -7
- package/project/.sdk/src/cmp/kotlin/Test_kotlin.ts +4 -7
- package/project/.sdk/src/cmp/lean/Test_lean.ts +3 -3
- package/project/.sdk/src/cmp/lua/Package_lua.ts +2 -2
- package/project/.sdk/src/cmp/lua/Test_lua.ts +5 -7
- package/project/.sdk/src/cmp/ocaml/Test_ocaml.ts +3 -7
- package/project/.sdk/src/cmp/perl/Package_perl.ts +1 -1
- package/project/.sdk/src/cmp/perl/Test_perl.ts +5 -7
- package/project/.sdk/src/cmp/php/EntityTypes_php.ts +13 -2
- package/project/.sdk/src/cmp/php/Package_php.ts +2 -2
- package/project/.sdk/src/cmp/php/Test_php.ts +5 -7
- package/project/.sdk/src/cmp/py/Package_py.ts +2 -2
- package/project/.sdk/src/cmp/py/Test_py.ts +5 -7
- package/project/.sdk/src/cmp/py-data/Main_py-data.ts +14 -19
- package/project/.sdk/src/cmp/rb/Package_rb.ts +3 -3
- package/project/.sdk/src/cmp/rb/ReadmeInstall_rb.ts +1 -1
- package/project/.sdk/src/cmp/rb/Test_rb.ts +5 -7
- package/project/.sdk/src/cmp/rust/Test_rust.ts +5 -7
- package/project/.sdk/src/cmp/scala/Test_scala.ts +5 -2
- package/project/.sdk/src/cmp/seneca-provider/Gitignore_seneca-provider.ts +161 -0
- package/project/.sdk/src/cmp/seneca-provider/Main_seneca-provider.ts +20 -11
- package/project/.sdk/src/cmp/swift/Test_swift.ts +5 -7
- package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/Test_ts.ts +8 -7
- package/project/.sdk/src/cmp/zig/Test_zig.ts +3 -7
- package/project/.sdk/tm/c/utility/make_point.c +64 -3
- package/project/.sdk/tm/clojure/src/sdk/core.clj +49 -14
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +55 -3
- package/project/.sdk/tm/csharp/feature/TestFeature.cs +36 -2
- package/project/.sdk/tm/csharp/utility/MakePoint.cs +65 -2
- package/project/.sdk/tm/dart/lib/feature/test/TestFeature.dart +34 -4
- package/project/.sdk/tm/dart/lib/utility/MakePointUtility.dart +48 -2
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +70 -10
- package/project/.sdk/tm/go/feature/test_feature.go +34 -2
- package/project/.sdk/tm/go/utility/make_point.go +66 -2
- package/project/.sdk/tm/java/feature/TestFeature.java +42 -2
- package/project/.sdk/tm/java/utility/MakePoint.java +61 -2
- package/project/.sdk/tm/js/src/feature/test/TestFeature.js +22 -3
- package/project/.sdk/tm/js/src/utility/MakePointUtility.js +72 -2
- package/project/.sdk/tm/kotlin/feature/TestFeature.kt +31 -2
- package/project/.sdk/tm/kotlin/utility/MakePoint.kt +58 -2
- package/project/.sdk/tm/lean/src/SdkUtility.lean +28 -0
- package/project/.sdk/tm/lua/utility/make_point.lua +65 -2
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -2
- package/project/.sdk/tm/perl/utility/make_point.pm +55 -2
- package/project/.sdk/tm/php/feature/TestFeature.php +30 -1
- package/project/.sdk/tm/php/utility/MakePoint.php +49 -1
- package/project/.sdk/tm/py/pkg/utility/make_point.py +56 -2
- package/project/.sdk/tm/rb/utility/make_point.rb +42 -2
- package/project/.sdk/tm/rust/utility/make_point.rs +69 -2
- package/project/.sdk/tm/scala/feature/TestFeature.scala +36 -1
- package/project/.sdk/tm/scala/utility/Make.scala +57 -3
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +29 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +51 -2
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +22 -3
- package/project/.sdk/tm/ts/src/utility/MakePointUtility.ts +72 -2
- package/project/.sdk/tm/zig/core/utility.zig +66 -3
- package/project/sdkgen-package.json +1 -2
- package/src/cmp/ExternalTarget.ts +1 -1
- package/src/helpers/naming.ts +129 -5
- package/src/helpers/opShape.ts +85 -0
- package/src/helpers/packageMeta.ts +59 -20
- package/src/sdkgen.ts +68 -20
- package/src/testkit.ts +863 -0
- package/testkit.d.ts +3 -0
- package/testkit.js +12 -0
- package/project/.sdk/model/target/haskell.aontu +0 -72
- package/project/.sdk/src/cmp/haskell/Config_haskell.ts +0 -98
- package/project/.sdk/src/cmp/haskell/Entity_haskell.ts +0 -13
- package/project/.sdk/src/cmp/haskell/Gitignore_haskell.ts +0 -27
- package/project/.sdk/src/cmp/haskell/Main_haskell.ts +0 -123
- package/project/.sdk/src/cmp/haskell/Package_haskell.ts +0 -60
- package/project/.sdk/src/cmp/haskell/ReadmeEntity_haskell.ts +0 -186
- package/project/.sdk/src/cmp/haskell/ReadmeExamplesTest_haskell.ts +0 -135
- package/project/.sdk/src/cmp/haskell/ReadmeExplanation_haskell.ts +0 -48
- package/project/.sdk/src/cmp/haskell/ReadmeHowto_haskell.ts +0 -168
- package/project/.sdk/src/cmp/haskell/ReadmeInstall_haskell.ts +0 -51
- package/project/.sdk/src/cmp/haskell/ReadmeIntro_haskell.ts +0 -67
- package/project/.sdk/src/cmp/haskell/ReadmeModel_haskell.ts +0 -162
- package/project/.sdk/src/cmp/haskell/ReadmeOptions_haskell.ts +0 -74
- package/project/.sdk/src/cmp/haskell/ReadmeQuick_haskell.ts +0 -241
- package/project/.sdk/src/cmp/haskell/ReadmeRef_haskell.ts +0 -408
- package/project/.sdk/src/cmp/haskell/ReadmeTopHowto_haskell.ts +0 -31
- package/project/.sdk/src/cmp/haskell/ReadmeTopQuick_haskell.ts +0 -104
- package/project/.sdk/src/cmp/haskell/ReadmeTopTest_haskell.ts +0 -80
- package/project/.sdk/src/cmp/haskell/Test_haskell.ts +0 -300
- package/project/.sdk/src/cmp/haskell/tsconfig.json +0 -15
- package/project/.sdk/src/cmp/haskell/utility_haskell.ts +0 -166
- package/project/.sdk/tm/haskell/LICENSE +0 -21
- package/project/.sdk/tm/haskell/Makefile +0 -22
- package/project/.sdk/tm/haskell/VERSION +0 -1
- package/project/.sdk/tm/haskell/src/SdkFeatures.hs +0 -1440
- package/project/.sdk/tm/haskell/src/SdkHelpers.hs +0 -337
- package/project/.sdk/tm/haskell/src/SdkJson.hs +0 -111
- package/project/.sdk/tm/haskell/src/SdkRuntime.hs +0 -1219
- package/project/.sdk/tm/haskell/src/SdkTypes.hs +0 -195
- package/project/.sdk/tm/haskell/src/VoxgigStruct.hs +0 -2299
- package/project/.sdk/tm/haskell/src/Vregex.hs +0 -237
- package/project/.sdk/tm/haskell/src/feature/README.md +0 -5
- package/project/.sdk/tm/haskell/src/feature/audit/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/base/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/cache/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/clienttrack/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/debug/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/idempotency/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/log/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/metrics/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/netsim/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/paging/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/proxy/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/ratelimit/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/rbac/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/retry/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/streaming/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/telemetry/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/test/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/src/feature/timeout/.gitkeep +0 -0
- package/project/.sdk/tm/haskell/test/Harness.hs +0 -281
- package/project/.sdk/tm/haskell/test/Runner.hs +0 -47
- package/project/.sdk/tm/haskell/test/StructCorpus.hs +0 -449
- package/project/.sdk/tm/haskell/test/TCustomUtility.hs +0 -38
- package/project/.sdk/tm/haskell/test/TFeature.hs +0 -794
- package/project/.sdk/tm/haskell/test/TNetsim.hs +0 -50
- package/project/.sdk/tm/haskell/test/TPipeline.hs +0 -334
- package/project/.sdk/tm/haskell/test/TPrimaryUtility.hs +0 -386
- package/project/.sdk/tm/haskell/test/Testutil.hs +0 -59
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, each, Content, envName, isAuthActive } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const ReadmeOptions = cmp(function ReadmeOptions(props: any) {
|
|
6
|
-
const { target } = props
|
|
7
|
-
const { model } = props.ctx$
|
|
8
|
-
|
|
9
|
-
const publishedOptions = each(target.options).filter((option: any) =>
|
|
10
|
-
option.publish && ('apikey' !== option.name || isAuthActive(model)))
|
|
11
|
-
if (0 === publishedOptions.length) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const authActive = isAuthActive(model)
|
|
16
|
-
|
|
17
|
-
Content(`
|
|
18
|
-
|
|
19
|
-
## Options
|
|
20
|
-
|
|
21
|
-
Pass an options \`Value\` (built with \`jo\`) when constructing a client. Any
|
|
22
|
-
option may be omitted; the entries below are illustrative.
|
|
23
|
-
|
|
24
|
-
`)
|
|
25
|
-
|
|
26
|
-
if (authActive) {
|
|
27
|
-
Content(`\`\`\`haskell
|
|
28
|
-
import qualified SdkClient as Sdk
|
|
29
|
-
import VoxgigStruct (Value (..))
|
|
30
|
-
import SdkHelpers (jo)
|
|
31
|
-
|
|
32
|
-
makeClient :: IO Sdk.Client
|
|
33
|
-
makeClient = do
|
|
34
|
-
-- Read the API key from the ${envName(model)}_APIKEY environment variable.
|
|
35
|
-
opts <- jo [("apikey", VStr "your-api-key")]
|
|
36
|
-
Sdk.newSdk opts
|
|
37
|
-
\`\`\`
|
|
38
|
-
|
|
39
|
-
`)
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
Content(`\`\`\`haskell
|
|
43
|
-
import qualified SdkClient as Sdk
|
|
44
|
-
import VoxgigStruct (Value (..))
|
|
45
|
-
import SdkHelpers (jo)
|
|
46
|
-
|
|
47
|
-
makeClient :: IO Sdk.Client
|
|
48
|
-
makeClient = do
|
|
49
|
-
opts <- jo [("base", VStr "https://api.example.com")]
|
|
50
|
-
Sdk.newSdk opts
|
|
51
|
-
\`\`\`
|
|
52
|
-
|
|
53
|
-
`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Content(`Every published option:
|
|
57
|
-
|
|
58
|
-
| Option | Type | Description |
|
|
59
|
-
| --- | --- | --- |
|
|
60
|
-
`)
|
|
61
|
-
|
|
62
|
-
publishedOptions.map((option: any) => {
|
|
63
|
-
Content(`| \`${option.name}\` | \`${option.kind}\` | ${option.short} |
|
|
64
|
-
`)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
Content(`
|
|
68
|
-
`)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
export {
|
|
73
|
-
ReadmeOptions
|
|
74
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, Content, isAuthActive, envName, canonKey, opRequestShape, entityIdField, entityOps } 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. List/object params fall
|
|
14
|
-
// back to VNoval (they cannot be built as a pure literal inside `jo`); scalars
|
|
15
|
-
// use the matching constructor.
|
|
16
|
-
function hsLit(type: any, placeholder: string = 'example'): string {
|
|
17
|
-
const k = canonKey(type)
|
|
18
|
-
if ('INTEGER' === k || 'NUMBER' === k) return 'VNum 1'
|
|
19
|
-
if ('BOOLEAN' === k) return 'VBool True'
|
|
20
|
-
if ('ARRAY' === k || 'OBJECT' === k) return 'VNoval'
|
|
21
|
-
return `VStr "${placeholder}"`
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
26
|
-
const { target, ctx$: { model } } = props
|
|
27
|
-
|
|
28
|
-
const entity = getModelPath(model, `main.${KIT}.entity`)
|
|
29
|
-
|
|
30
|
-
const exampleEntity = Object.values(entity).find((e: any) => e.active !== false) as any
|
|
31
|
-
|
|
32
|
-
// Find a nested entity if available: one with a parent chain
|
|
33
|
-
// (relations.ancestors), an active load op, and a required non-id load
|
|
34
|
-
// param to demonstrate (the parent key, e.g. page_id).
|
|
35
|
-
const nestedEntity = Object.values(entity).find((e: any) =>
|
|
36
|
-
e.active !== false &&
|
|
37
|
-
e.relations && e.relations.ancestors && 0 < e.relations.ancestors.length &&
|
|
38
|
-
entityOps(e).includes('load') &&
|
|
39
|
-
opRequestShape(e, 'load').items.some((it: any) =>
|
|
40
|
-
!it.optional && it.name !== entityIdField(e))
|
|
41
|
-
) as any
|
|
42
|
-
|
|
43
|
-
const authActive = isAuthActive(model)
|
|
44
|
-
|
|
45
|
-
Content(`### 1. Create a client
|
|
46
|
-
|
|
47
|
-
\`\`\`haskell
|
|
48
|
-
`)
|
|
49
|
-
if (authActive) {
|
|
50
|
-
Content(`import System.Environment (lookupEnv)
|
|
51
|
-
import qualified SdkClient as Sdk
|
|
52
|
-
import VoxgigStruct (Value (..), emptyMap)
|
|
53
|
-
import SdkHelpers (jo)
|
|
54
|
-
|
|
55
|
-
main :: IO ()
|
|
56
|
-
main = do
|
|
57
|
-
mkey <- lookupEnv "${envName(model)}_APIKEY"
|
|
58
|
-
opts <- jo [("apikey", maybe VNoval VStr mkey)]
|
|
59
|
-
sdk <- Sdk.newSdk opts
|
|
60
|
-
`)
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
Content(`import qualified SdkClient as Sdk
|
|
64
|
-
import VoxgigStruct (Value (..), emptyMap)
|
|
65
|
-
import SdkHelpers (jo)
|
|
66
|
-
|
|
67
|
-
main :: IO ()
|
|
68
|
-
main = do
|
|
69
|
-
sdk <- Sdk.newSdk0
|
|
70
|
-
`)
|
|
71
|
-
}
|
|
72
|
-
Content(`\`\`\`
|
|
73
|
-
|
|
74
|
-
Entity operations raise on error (via \`Control.Exception.throwIO\`) and
|
|
75
|
-
return the bare result \`Value\`. Wrap a call in \`Control.Exception.try\`
|
|
76
|
-
to recover from failures.
|
|
77
|
-
|
|
78
|
-
`)
|
|
79
|
-
|
|
80
|
-
if (exampleEntity) {
|
|
81
|
-
const eName = nom(exampleEntity, 'Name')
|
|
82
|
-
const article = /^[aeiou]/i.test(eName) ? 'an' : 'a'
|
|
83
|
-
const eFn = hsVarName(exampleEntity.name)
|
|
84
|
-
const opnames = entityOps(exampleEntity)
|
|
85
|
-
// Model-driven id key: `idF` is the entity's id-like MATCH field name, or
|
|
86
|
-
// null when it has none. `dataIdF` is the id on the RETURNED record's data
|
|
87
|
-
// type.
|
|
88
|
-
const idF = entityIdField(exampleEntity)
|
|
89
|
-
|
|
90
|
-
if (opnames.includes('list')) {
|
|
91
|
-
Content(`### 2. List ${eName.toLowerCase()} records
|
|
92
|
-
|
|
93
|
-
\`eList ent match ctrl\` resolves to one ENTITY per record and raises on
|
|
94
|
-
error. Read a record with \`eDataGet\`.
|
|
95
|
-
|
|
96
|
-
\`\`\`haskell
|
|
97
|
-
ent <- Sdk.${eFn} sdk VNoval
|
|
98
|
-
match <- emptyMap
|
|
99
|
-
ctrl <- emptyMap
|
|
100
|
-
${eFn}s <- Sdk.eList ent match ctrl
|
|
101
|
-
mapM_ (\\en -> print =<< Sdk.eDataGet en) ${eFn}s
|
|
102
|
-
\`\`\`
|
|
103
|
-
|
|
104
|
-
`)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (nestedEntity) {
|
|
108
|
-
const neName = nom(nestedEntity, 'Name')
|
|
109
|
-
const neArticle = /^[aeiou]/i.test(neName) ? 'an' : 'a'
|
|
110
|
-
const neFn = hsVarName(nestedEntity.name)
|
|
111
|
-
|
|
112
|
-
const neIdF = entityIdField(nestedEntity)
|
|
113
|
-
const neRequired = opRequestShape(nestedEntity, 'load').items
|
|
114
|
-
.filter((it: any) => !it.optional)
|
|
115
|
-
.sort((a: any, b: any) =>
|
|
116
|
-
(a.name === neIdF ? 1 : 0) - (b.name === neIdF ? 1 : 0))
|
|
117
|
-
const parentItem = neRequired.find((it: any) => it.name !== neIdF) as any
|
|
118
|
-
const parentParam = parentItem && parentItem.name
|
|
119
|
-
const parentName = parentParam ? parentParam.replace(/_id$/, '') : 'its parent'
|
|
120
|
-
const neMatch = neRequired.map((it: any) =>
|
|
121
|
-
`("${it.name}", ${hsLit(it.type,
|
|
122
|
-
it.name === neIdF ? 'example_id' : 'example_' + it.name)})`)
|
|
123
|
-
|
|
124
|
-
Content(`### 3. Load ${neArticle} ${neName.toLowerCase()}
|
|
125
|
-
|
|
126
|
-
${neName} is nested under ${parentName}, so provide the \`${parentParam}\`.
|
|
127
|
-
\`eLoad\` resolves to the ENTITY and raises on error; \`eDataGet\` gives the
|
|
128
|
-
record.
|
|
129
|
-
|
|
130
|
-
\`\`\`haskell
|
|
131
|
-
${neFn}Ent <- Sdk.${neFn} sdk VNoval
|
|
132
|
-
m <- jo [${neMatch.join(', ')}]
|
|
133
|
-
ctrl2 <- emptyMap
|
|
134
|
-
${neFn} <- Sdk.eLoad ${neFn}Ent m ctrl2
|
|
135
|
-
print =<< Sdk.eDataGet ${neFn}
|
|
136
|
-
\`\`\`
|
|
137
|
-
|
|
138
|
-
`)
|
|
139
|
-
}
|
|
140
|
-
else if (opnames.includes('load')) {
|
|
141
|
-
const loadRequired = opRequestShape(exampleEntity, 'load').items
|
|
142
|
-
.filter((it: any) => !it.optional || it.name === idF)
|
|
143
|
-
.sort((a: any, b: any) =>
|
|
144
|
-
(a.name === idF ? 0 : 1) - (b.name === idF ? 0 : 1))
|
|
145
|
-
const loadArg = 0 < loadRequired.length
|
|
146
|
-
? `[${loadRequired.map((it: any) =>
|
|
147
|
-
`("${it.name}", ${hsLit(it.type,
|
|
148
|
-
it.name === idF ? 'example_id' : 'example_' + it.name)})`).join(', ')}]`
|
|
149
|
-
: '[]'
|
|
150
|
-
|
|
151
|
-
Content(`### 3. Load ${article} ${eName.toLowerCase()}
|
|
152
|
-
|
|
153
|
-
\`eLoad ent match ctrl\` resolves to the ENTITY and raises on error;
|
|
154
|
-
\`eDataGet\` gives the record.
|
|
155
|
-
|
|
156
|
-
\`\`\`haskell
|
|
157
|
-
ent2 <- Sdk.${eFn} sdk VNoval
|
|
158
|
-
m <- jo ${loadArg}
|
|
159
|
-
ctrl2 <- emptyMap
|
|
160
|
-
${eFn} <- Sdk.eLoad ent2 m ctrl2
|
|
161
|
-
print =<< Sdk.eDataGet ${eFn}
|
|
162
|
-
\`\`\`
|
|
163
|
-
|
|
164
|
-
`)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Model-driven example fields: derive the create/update body from the op
|
|
168
|
-
// shape so the docs reference REAL writable fields.
|
|
169
|
-
const examplePairs = (opname: string): string[] => {
|
|
170
|
-
const items = opRequestShape(exampleEntity, opname).items
|
|
171
|
-
.filter((it: any) => (it.name !== idF && it.name !== 'id') ||
|
|
172
|
-
('create' === opname && !it.optional))
|
|
173
|
-
const required = items.filter((it: any) => !it.optional)
|
|
174
|
-
const optional = items.filter((it: any) => it.optional)
|
|
175
|
-
const chosen = 'create' === opname
|
|
176
|
-
? (required.length ? required : items.slice(0, 2))
|
|
177
|
-
: required.concat(optional).slice(0, Math.max(2, required.length))
|
|
178
|
-
return chosen.map((it: any) => `("${it.name}", ${hsLit(it.type, 'example_' + it.name)})`)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const idParamType = (opname: string): any => {
|
|
182
|
-
const it = opRequestShape(exampleEntity, opname).items.find((x: any) => x.name === idF)
|
|
183
|
-
return it && it.type
|
|
184
|
-
}
|
|
185
|
-
const idValueFor = (opname: string): string =>
|
|
186
|
-
hsLit(idParamType(opname), 'example_id')
|
|
187
|
-
|
|
188
|
-
if (opnames.includes('create') || opnames.includes('update') || opnames.includes('remove')) {
|
|
189
|
-
Content(`### 4. Create, update, and remove
|
|
190
|
-
|
|
191
|
-
`)
|
|
192
|
-
if (opnames.includes('create')) {
|
|
193
|
-
Content(`\`\`\`haskell
|
|
194
|
-
createEnt <- Sdk.${eFn} sdk VNoval
|
|
195
|
-
d <- jo [${examplePairs('create').join(', ')}]
|
|
196
|
-
cctrl <- emptyMap
|
|
197
|
-
created <- Sdk.eCreate createEnt d cctrl
|
|
198
|
-
print =<< Sdk.eDataGet created
|
|
199
|
-
\`\`\`
|
|
200
|
-
|
|
201
|
-
`)
|
|
202
|
-
}
|
|
203
|
-
if (opnames.includes('update')) {
|
|
204
|
-
const updatePairs = (idF ? [`("${idF}", ${idValueFor('update')})`] : []).concat(examplePairs('update'))
|
|
205
|
-
Content(`\`\`\`haskell
|
|
206
|
-
updateEnt <- Sdk.${eFn} sdk VNoval
|
|
207
|
-
upd <- jo [${updatePairs.join(', ')}]
|
|
208
|
-
uctrl <- emptyMap
|
|
209
|
-
updated <- Sdk.eUpdate updateEnt upd uctrl
|
|
210
|
-
print =<< Sdk.eDataGet updated
|
|
211
|
-
\`\`\`
|
|
212
|
-
|
|
213
|
-
`)
|
|
214
|
-
}
|
|
215
|
-
if (opnames.includes('remove')) {
|
|
216
|
-
const removePairs = opRequestShape(exampleEntity, 'remove').items
|
|
217
|
-
.filter((it: any) => !it.optional || it.name === idF)
|
|
218
|
-
.sort((a: any, b: any) =>
|
|
219
|
-
(a.name === idF ? 0 : 1) - (b.name === idF ? 0 : 1))
|
|
220
|
-
.map((it: any) => it.name === idF
|
|
221
|
-
? `("${it.name}", ${idValueFor('remove')})`
|
|
222
|
-
: `("${it.name}", ${hsLit(it.type, 'example_' + it.name)})`)
|
|
223
|
-
Content(`\`\`\`haskell
|
|
224
|
-
removeEnt <- Sdk.${eFn} sdk VNoval
|
|
225
|
-
rm <- jo [${removePairs.length ? removePairs.join(', ') : ''}]
|
|
226
|
-
rctrl <- emptyMap
|
|
227
|
-
-- Resolves to the entity, marked deleted; it keeps the data it held.
|
|
228
|
-
removed <- Sdk.eRemove removeEnt rm rctrl
|
|
229
|
-
print =<< readIORef (Sdk.eDeleted removed)
|
|
230
|
-
\`\`\`
|
|
231
|
-
|
|
232
|
-
`)
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
export {
|
|
240
|
-
ReadmeQuick
|
|
241
|
-
}
|