@voxgig/sdkgen 0.44.0 → 1.0.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 (160) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ReadmeEntity.js +9 -153
  3. package/dist/cmp/ReadmeEntity.js.map +1 -1
  4. package/dist/cmp/ReadmeIntro.js +9 -14
  5. package/dist/cmp/ReadmeIntro.js.map +1 -1
  6. package/dist/cmp/ReadmeModel.js +6 -4
  7. package/dist/cmp/ReadmeModel.js.map +1 -1
  8. package/dist/cmp/ReadmeOptions.js +9 -61
  9. package/dist/cmp/ReadmeOptions.js.map +1 -1
  10. package/dist/cmp/ReadmeRef.js +10 -1328
  11. package/dist/cmp/ReadmeRef.js.map +1 -1
  12. package/dist/sdkgen.d.ts +2 -2
  13. package/dist/sdkgen.js +2 -1
  14. package/dist/sdkgen.js.map +1 -1
  15. package/dist/utility.d.ts +2 -1
  16. package/dist/utility.js +9 -0
  17. package/dist/utility.js.map +1 -1
  18. package/package.json +3 -3
  19. package/project/.sdk/src/cmp/go/Config_go.ts +9 -4
  20. package/project/.sdk/src/cmp/go/Entity_go.ts +2 -2
  21. package/project/.sdk/src/cmp/go/Main_go.ts +8 -4
  22. package/project/.sdk/src/cmp/go/Package_go.ts +2 -2
  23. package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +138 -0
  24. package/project/.sdk/src/cmp/go/ReadmeExplanation_go.ts +2 -2
  25. package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +8 -5
  26. package/project/.sdk/src/cmp/go/ReadmeInstall_go.ts +2 -2
  27. package/project/.sdk/src/cmp/go/ReadmeIntro_go.ts +18 -0
  28. package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +8 -5
  29. package/project/.sdk/src/cmp/go/ReadmeOptions_go.ts +58 -0
  30. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +13 -9
  31. package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +354 -0
  32. package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +8 -6
  33. package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +2 -2
  34. package/project/.sdk/src/cmp/go/TestDirect_go.ts +222 -41
  35. package/project/.sdk/src/cmp/go/TestEntity_go.ts +142 -60
  36. package/project/.sdk/src/cmp/go/Test_go.ts +2 -2
  37. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +21 -4
  38. package/project/.sdk/src/cmp/js/Config_js.ts +18 -0
  39. package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +138 -0
  40. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +11 -6
  41. package/project/.sdk/src/cmp/js/ReadmeIntro_js.ts +18 -0
  42. package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +6 -3
  43. package/project/.sdk/src/cmp/js/ReadmeOptions_js.ts +58 -0
  44. package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +6 -4
  45. package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +384 -0
  46. package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +6 -4
  47. package/project/.sdk/src/cmp/js/TestDirect_js.ts +23 -12
  48. package/project/.sdk/src/cmp/js/TestEntity_js.ts +107 -74
  49. package/project/.sdk/src/cmp/js/fragment/Config.fragment.js +1 -5
  50. package/project/.sdk/src/cmp/lua/Config_lua.ts +9 -4
  51. package/project/.sdk/src/cmp/lua/Package_lua.ts +9 -2
  52. package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +138 -0
  53. package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +6 -3
  54. package/project/.sdk/src/cmp/lua/ReadmeIntro_lua.ts +18 -0
  55. package/project/.sdk/src/cmp/lua/ReadmeModel_lua.ts +6 -3
  56. package/project/.sdk/src/cmp/lua/ReadmeOptions_lua.ts +58 -0
  57. package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +6 -4
  58. package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +360 -0
  59. package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +6 -4
  60. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +172 -29
  61. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +120 -52
  62. package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +20 -4
  63. package/project/.sdk/src/cmp/php/Config_php.ts +10 -8
  64. package/project/.sdk/src/cmp/php/Package_php.ts +7 -1
  65. package/project/.sdk/src/cmp/php/ReadmeEntity_php.ts +138 -0
  66. package/project/.sdk/src/cmp/php/ReadmeHowto_php.ts +6 -3
  67. package/project/.sdk/src/cmp/php/ReadmeIntro_php.ts +18 -0
  68. package/project/.sdk/src/cmp/php/ReadmeModel_php.ts +6 -3
  69. package/project/.sdk/src/cmp/php/ReadmeOptions_php.ts +58 -0
  70. package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +6 -4
  71. package/project/.sdk/src/cmp/php/ReadmeRef_php.ts +358 -0
  72. package/project/.sdk/src/cmp/php/ReadmeTopQuick_php.ts +6 -4
  73. package/project/.sdk/src/cmp/php/TestDirect_php.ts +171 -28
  74. package/project/.sdk/src/cmp/php/TestEntity_php.ts +126 -55
  75. package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +17 -3
  76. package/project/.sdk/src/cmp/py/Config_py.ts +9 -4
  77. package/project/.sdk/src/cmp/py/Package_py.ts +8 -1
  78. package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +138 -0
  79. package/project/.sdk/src/cmp/py/ReadmeHowto_py.ts +6 -3
  80. package/project/.sdk/src/cmp/py/ReadmeIntro_py.ts +18 -0
  81. package/project/.sdk/src/cmp/py/ReadmeModel_py.ts +6 -3
  82. package/project/.sdk/src/cmp/py/ReadmeOptions_py.ts +58 -0
  83. package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +9 -6
  84. package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +356 -0
  85. package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +9 -6
  86. package/project/.sdk/src/cmp/py/TestDirect_py.ts +164 -27
  87. package/project/.sdk/src/cmp/py/TestEntity_py.ts +125 -51
  88. package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +19 -4
  89. package/project/.sdk/src/cmp/rb/Config_rb.ts +9 -4
  90. package/project/.sdk/src/cmp/rb/Package_rb.ts +9 -2
  91. package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +138 -0
  92. package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +6 -3
  93. package/project/.sdk/src/cmp/rb/ReadmeIntro_rb.ts +18 -0
  94. package/project/.sdk/src/cmp/rb/ReadmeModel_rb.ts +6 -3
  95. package/project/.sdk/src/cmp/rb/ReadmeOptions_rb.ts +58 -0
  96. package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +6 -4
  97. package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +361 -0
  98. package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +6 -4
  99. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +172 -29
  100. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +120 -52
  101. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +19 -3
  102. package/project/.sdk/src/cmp/ts/Config_ts.ts +18 -0
  103. package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
  104. package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +138 -0
  105. package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +11 -6
  106. package/project/.sdk/src/cmp/ts/ReadmeIntro_ts.ts +18 -0
  107. package/project/.sdk/src/cmp/ts/ReadmeModel_ts.ts +9 -5
  108. package/project/.sdk/src/cmp/ts/ReadmeOptions_ts.ts +58 -0
  109. package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +6 -4
  110. package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +384 -0
  111. package/project/.sdk/src/cmp/ts/ReadmeTopQuick_ts.ts +6 -4
  112. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +213 -42
  113. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +168 -75
  114. package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +1 -5
  115. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +8 -1
  116. package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +8 -2
  117. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +21 -1
  118. package/project/.sdk/tm/go/feature/test_feature.go +51 -3
  119. package/project/.sdk/tm/go/test/runner_test.go +106 -6
  120. package/project/.sdk/tm/go/test/sdk-test-control.json +19 -0
  121. package/project/.sdk/tm/go/utility/fetcher.go +10 -0
  122. package/project/.sdk/tm/go/utility/make_url.go +12 -0
  123. package/project/.sdk/tm/go/utility/prepare_auth.go +15 -1
  124. package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +7 -1
  125. package/project/.sdk/tm/lua/feature/test_feature.lua +41 -3
  126. package/project/.sdk/tm/lua/test/runner.lua +74 -0
  127. package/project/.sdk/tm/lua/test/sdk-test-control.json +19 -0
  128. package/project/.sdk/tm/lua/utility/fetcher.lua +13 -0
  129. package/project/.sdk/tm/lua/utility/make_url.lua +16 -0
  130. package/project/.sdk/tm/lua/utility/prepare_auth.lua +9 -1
  131. package/project/.sdk/tm/php/feature/TestFeature.php +185 -43
  132. package/project/.sdk/tm/php/test/Runner.php +62 -0
  133. package/project/.sdk/tm/php/test/sdk-test-control.json +19 -0
  134. package/project/.sdk/tm/php/utility/Fetcher.php +132 -9
  135. package/project/.sdk/tm/php/utility/MakeUrl.php +16 -0
  136. package/project/.sdk/tm/php/utility/PrepareAuth.php +11 -1
  137. package/project/.sdk/tm/py/feature/test_feature.py +35 -3
  138. package/project/.sdk/tm/py/test/runner.py +60 -0
  139. package/project/.sdk/tm/py/test/sdk-test-control.json +19 -0
  140. package/project/.sdk/tm/py/utility/fetcher.py +13 -0
  141. package/project/.sdk/tm/py/utility/make_url.py +13 -0
  142. package/project/.sdk/tm/py/utility/prepare_auth.py +10 -1
  143. package/project/.sdk/tm/rb/feature/test_feature.rb +36 -3
  144. package/project/.sdk/tm/rb/test/runner.rb +46 -0
  145. package/project/.sdk/tm/rb/test/sdk-test-control.json +19 -0
  146. package/project/.sdk/tm/rb/utility/fetcher.rb +49 -28
  147. package/project/.sdk/tm/rb/utility/make_url.rb +16 -0
  148. package/project/.sdk/tm/rb/utility/prepare_auth.rb +8 -1
  149. package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +7 -8
  150. package/project/.sdk/tm/ts/src/utility/PrepareAuthUtility.ts +7 -1
  151. package/project/.sdk/tm/ts/test/sdk-test-control.json +19 -0
  152. package/project/.sdk/tm/ts/test/utility.ts +120 -2
  153. package/src/cmp/ReadmeEntity.ts +11 -178
  154. package/src/cmp/ReadmeIntro.ts +11 -25
  155. package/src/cmp/ReadmeModel.ts +7 -5
  156. package/src/cmp/ReadmeOptions.ts +12 -74
  157. package/src/cmp/ReadmeRef.ts +11 -1372
  158. package/src/sdkgen.ts +2 -1
  159. package/src/utility.ts +12 -0
  160. /package/project/.sdk/tm/go/utility/{make_target.go → make_point.go} +0 -0
@@ -1,5 +1,5 @@
1
1
 
2
- import { cmp, each, Content } from '@voxgig/sdkgen'
2
+ import { cmp, each, Content, isAuthActive } from '@voxgig/sdkgen'
3
3
 
4
4
  import {
5
5
  KIT,
@@ -13,13 +13,18 @@ const ReadmeModel = cmp(function ReadmeModel(props: any) {
13
13
  const entity = getModelPath(model, `main.${KIT}.entity`)
14
14
  const entityList = each(entity).filter((e: any) => e.active !== false)
15
15
 
16
+ const authActive = isAuthActive(model)
17
+ const apikeyOptionType = authActive ? `\n apikey?: string` : ''
18
+ const apikeyOptionRow = authActive
19
+ ? '| `apikey` | `string` | API key for authentication. |\n'
20
+ : ''
21
+
16
22
  Content(`### ${model.const.Name}SDK
17
23
 
18
24
  #### Constructor
19
25
 
20
26
  \`\`\`ts
21
- new ${model.const.Name}SDK(options?: {
22
- apikey?: string
27
+ new ${model.const.Name}SDK(options?: {${apikeyOptionType}
23
28
  base?: string
24
29
  prefix?: string
25
30
  suffix?: string
@@ -30,8 +35,7 @@ new ${model.const.Name}SDK(options?: {
30
35
 
31
36
  | Option | Type | Description |
32
37
  | --- | --- | --- |
33
- | \`apikey\` | \`string\` | API key for authentication. |
34
- | \`base\` | \`string\` | Base URL of the API server. |
38
+ ${apikeyOptionRow}| \`base\` | \`string\` | Base URL of the API server. |
35
39
  | \`prefix\` | \`string\` | URL path prefix prepended to all requests. |
36
40
  | \`suffix\` | \`string\` | URL path suffix appended to all requests. |
37
41
  | \`feature\` | \`object\` | Feature activation flags (e.g. \`{ test: { active: true } }\`). |
@@ -0,0 +1,58 @@
1
+
2
+ import { cmp, each, Content } 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) => option.publish)
10
+ if (0 === publishedOptions.length) {
11
+ return
12
+ }
13
+
14
+ Content(`
15
+
16
+ ## Options
17
+
18
+ Pass options when creating a client instance:
19
+
20
+ `)
21
+
22
+ Content(`\`\`\`ts
23
+ const client = new ${model.Name}SDK({
24
+ `)
25
+
26
+ publishedOptions.map((option: any) => {
27
+ if ('apikey' === option.name) {
28
+ Content(` ${option.name}: process.env.${model.NAME}_APIKEY,
29
+ `)
30
+ }
31
+ else {
32
+ Content(` // ${option.name}: ${option.kind === 'string' ? "'...'" : '...'},
33
+ `)
34
+ }
35
+ })
36
+
37
+ Content(`})
38
+ \`\`\`
39
+
40
+ `)
41
+
42
+ Content(`| Option | Type | Description |
43
+ | --- | --- | --- |
44
+ `)
45
+
46
+ publishedOptions.map((option: any) => {
47
+ Content(`| \`${option.name}\` | \`${option.kind}\` | ${option.short} |
48
+ `)
49
+ })
50
+
51
+ Content(`
52
+ `)
53
+ })
54
+
55
+
56
+ export {
57
+ ReadmeOptions
58
+ }
@@ -1,5 +1,5 @@
1
1
 
2
- import { cmp, each, Content } from '@voxgig/sdkgen'
2
+ import { cmp, each, Content, isAuthActive } from '@voxgig/sdkgen'
3
3
 
4
4
  import {
5
5
  KIT,
@@ -21,14 +21,16 @@ const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
21
21
  e.active !== false && e.ancestors && e.ancestors.length > 0
22
22
  ) as any
23
23
 
24
+ const apikeyArg = isAuthActive(model)
25
+ ? `\n apikey: process.env.${model.NAME}_APIKEY,\n`
26
+ : ''
27
+
24
28
  Content(`### 1. Create a client
25
29
 
26
30
  \`\`\`ts
27
31
  import { ${model.const.Name}SDK } from '${target.module.name}'
28
32
 
29
- const client = new ${model.const.Name}SDK({
30
- apikey: process.env.${model.NAME}_APIKEY,
31
- })
33
+ const client = new ${model.const.Name}SDK({${apikeyArg}})
32
34
  \`\`\`
33
35
 
34
36
  `)
@@ -0,0 +1,384 @@
1
+
2
+ import { cmp, each, Content, File, isAuthActive } from '@voxgig/sdkgen'
3
+
4
+ import {
5
+ KIT,
6
+ getModelPath,
7
+ } from '@voxgig/apidef'
8
+
9
+
10
+ const OP_SIGNATURES: Record<string, { sig: string, returns: string, desc: string }> = {
11
+ load: {
12
+ sig: 'load(match: object, ctrl?: object)',
13
+ returns: 'Promise<object>',
14
+ desc: 'Load a single entity matching the given criteria.',
15
+ },
16
+ list: {
17
+ sig: 'list(match: object, ctrl?: object)',
18
+ returns: 'Promise<object[]>',
19
+ desc: 'List entities matching the given criteria. Returns an array.',
20
+ },
21
+ create: {
22
+ sig: 'create(data: object, ctrl?: object)',
23
+ returns: 'Promise<object>',
24
+ desc: 'Create a new entity with the given data.',
25
+ },
26
+ update: {
27
+ sig: 'update(data: object, ctrl?: object)',
28
+ returns: 'Promise<object>',
29
+ desc: 'Update an existing entity. The data must include the entity `id`.',
30
+ },
31
+ remove: {
32
+ sig: 'remove(match: object, ctrl?: object)',
33
+ returns: 'Promise<void>',
34
+ desc: 'Remove the entity matching the given criteria.',
35
+ },
36
+ }
37
+
38
+
39
+ const ReadmeRef = cmp(function ReadmeRef(props: any) {
40
+ const { target } = props
41
+ const { model } = props.ctx$
42
+
43
+ const entity = getModelPath(model, `main.${KIT}.entity`)
44
+ const feature = getModelPath(model, `main.${KIT}.feature`)
45
+
46
+ const publishedEntities = each(entity).filter((e: any) => e.active !== false)
47
+
48
+
49
+ File({ name: 'REFERENCE.md' }, () => {
50
+
51
+ Content(`# ${model.Name} ${target.title} SDK Reference
52
+
53
+ Complete API reference for the ${model.Name} ${target.title} SDK.
54
+
55
+
56
+ ## ${model.Name}SDK
57
+
58
+ ### Constructor
59
+
60
+ `)
61
+
62
+ Content(`\`\`\`ts
63
+ new ${model.Name}SDK(options?: object)
64
+ \`\`\`
65
+
66
+ Create a new SDK client instance.
67
+
68
+ **Parameters:**
69
+
70
+ | Name | Type | Description |
71
+ | --- | --- | --- |
72
+ | \`options\` | \`object\` | SDK configuration options. |
73
+ | \`options.apikey\` | \`string\` | API key for authentication. |
74
+ | \`options.base\` | \`string\` | Base URL for API requests. |
75
+ | \`options.prefix\` | \`string\` | URL prefix appended after base. |
76
+ | \`options.suffix\` | \`string\` | URL suffix appended after path. |
77
+ | \`options.headers\` | \`object\` | Custom headers for all requests. |
78
+ | \`options.feature\` | \`object\` | Feature configuration. |
79
+ | \`options.system\` | \`object\` | System overrides (e.g. custom fetch). |
80
+
81
+ `)
82
+
83
+
84
+ Content(`
85
+ ### Static Methods
86
+
87
+ `)
88
+
89
+ Content(`#### \`${model.Name}SDK.test(testopts?, sdkopts?)\`
90
+
91
+ Create a test client with mock features active.
92
+
93
+ \`\`\`ts
94
+ const client = ${model.Name}SDK.test()
95
+ \`\`\`
96
+
97
+ **Parameters:**
98
+
99
+ | Name | Type | Description |
100
+ | --- | --- | --- |
101
+ | \`testopts\` | \`object\` | Test feature options. |
102
+ | \`sdkopts\` | \`object\` | Additional SDK options merged with test defaults. |
103
+
104
+ **Returns:** \`${model.Name}SDK\` instance in test mode.
105
+
106
+ `)
107
+
108
+
109
+ Content(`
110
+ ### Instance Methods
111
+
112
+ `)
113
+
114
+
115
+ // Entity factory methods
116
+ publishedEntities.map((ent: any) => {
117
+ Content(`#### \`${ent.Name}(data?: object)\`
118
+
119
+ Create a new \`${ent.Name}\` entity instance.
120
+
121
+ **Parameters:**
122
+
123
+ | Name | Type | Description |
124
+ | --- | --- | --- |
125
+ | \`data\` | \`object\` | Initial entity data. |
126
+
127
+ **Returns:** \`${ent.Name}Entity\` instance.
128
+
129
+ `)
130
+ })
131
+
132
+
133
+ Content(`#### \`options()\`
134
+
135
+ Return a deep copy of the current SDK options.
136
+
137
+ **Returns:** \`object\`
138
+
139
+ #### \`utility()\`
140
+
141
+ Return a copy of the SDK utility object.
142
+
143
+ **Returns:** \`object\`
144
+
145
+ #### \`direct(fetchargs?: object)\`
146
+
147
+ Make a direct HTTP request to any API endpoint.
148
+
149
+ **Parameters:**
150
+
151
+ | Name | Type | Description |
152
+ | --- | --- | --- |
153
+ | \`fetchargs.path\` | \`string\` | URL path with optional \`{param}\` placeholders. |
154
+ | \`fetchargs.method\` | \`string\` | HTTP method (default: \`GET\`). |
155
+ | \`fetchargs.params\` | \`object\` | Path parameter values for \`{param}\` substitution. |
156
+ | \`fetchargs.query\` | \`object\` | Query string parameters. |
157
+ | \`fetchargs.headers\` | \`object\` | Request headers (merged with defaults). |
158
+ | \`fetchargs.body\` | \`any\` | Request body (objects are JSON-serialized). |
159
+ | \`fetchargs.ctrl\` | \`object\` | Control options (e.g. \`{ explain: true }\`). |
160
+
161
+ **Returns:** \`Promise<{ ok, status, headers, data } | Error>\`
162
+
163
+ #### \`prepare(fetchargs?: object)\`
164
+
165
+ Prepare a fetch definition without sending the request. Accepts the
166
+ same parameters as \`direct()\`.
167
+
168
+ **Returns:** \`Promise<{ url, method, headers, body } | Error>\`
169
+
170
+ #### \`tester(testopts?, sdkopts?)\`
171
+
172
+ Alias for \`${model.Name}SDK.test()\`.
173
+
174
+ **Returns:** \`${model.Name}SDK\` instance in test mode.
175
+
176
+ `)
177
+
178
+
179
+ // Entity reference sections
180
+ publishedEntities.map((ent: any) => {
181
+ const opnames = Object.keys(ent.op || {})
182
+ const fields = ent.fields || []
183
+
184
+ Content(`
185
+ ---
186
+
187
+ ## ${ent.Name}Entity
188
+
189
+ `)
190
+
191
+ if (ent.short) {
192
+ Content(`${ent.short}
193
+
194
+ `)
195
+ }
196
+
197
+ Content(`\`\`\`ts
198
+ const ${ent.name} = client.${ent.Name}()
199
+ \`\`\`
200
+
201
+ `)
202
+
203
+
204
+ // Field schema
205
+ if (fields.length > 0) {
206
+ Content(`### Fields
207
+
208
+ | Field | Type | Required | Description |
209
+ | --- | --- | --- | --- |
210
+ `)
211
+ each(fields, (field: any) => {
212
+ const req = field.req ? 'Yes' : 'No'
213
+ const desc = field.short || ''
214
+ Content(`| \`${field.name}\` | \`${field.type || 'any'}\` | ${req} | ${desc} |
215
+ `)
216
+ })
217
+
218
+ Content(`
219
+ `)
220
+
221
+ // Field operations breakdown
222
+ const hasFieldOps = fields.some((f: any) => f.op && Object.keys(f.op).length > 0)
223
+ if (hasFieldOps) {
224
+ Content(`### Field Usage by Operation
225
+
226
+ | Field | load | list | create | update | remove |
227
+ | --- | --- | --- | --- | --- | --- |
228
+ `)
229
+ each(fields, (field: any) => {
230
+ const fops = field.op || {}
231
+ const cols = ['load', 'list', 'create', 'update', 'remove'].map((op: string) => {
232
+ if (!opnames.includes(op)) return '-'
233
+ const fop = fops[op]
234
+ if (null == fop) return '-'
235
+ if (fop.active === false) return '-'
236
+ return 'Yes'
237
+ })
238
+ Content(`| \`${field.name}\` | ${cols.join(' | ')} |
239
+ `)
240
+ })
241
+
242
+ Content(`
243
+ `)
244
+ }
245
+ }
246
+
247
+
248
+ // Operation details
249
+ if (opnames.length > 0) {
250
+ Content(`### Operations
251
+
252
+ `)
253
+
254
+ opnames.map((opname: string) => {
255
+ const info = OP_SIGNATURES[opname]
256
+ if (!info) return
257
+
258
+ Content(`#### \`${info.sig}\`
259
+
260
+ ${info.desc}
261
+
262
+ `)
263
+
264
+ // Show example
265
+ if ('load' === opname || 'remove' === opname) {
266
+ Content(`\`\`\`ts
267
+ const result = await client.${ent.Name}().${opname}({ id: '${ent.name}_id' })
268
+ \`\`\`
269
+
270
+ `)
271
+ }
272
+ else if ('list' === opname) {
273
+ Content(`\`\`\`ts
274
+ const results = await client.${ent.Name}().${opname}()
275
+ \`\`\`
276
+
277
+ `)
278
+ }
279
+ else if ('create' === opname) {
280
+ Content(`\`\`\`ts
281
+ const result = await client.${ent.Name}().create({
282
+ `)
283
+ each(fields, (field: any) => {
284
+ if ('id' !== field.name && field.req) {
285
+ Content(` ${field.name}: /* ${field.type || 'value'} */,
286
+ `)
287
+ }
288
+ })
289
+ Content(`})
290
+ \`\`\`
291
+
292
+ `)
293
+ }
294
+ else if ('update' === opname) {
295
+ Content(`\`\`\`ts
296
+ const result = await client.${ent.Name}().update({
297
+ id: '${ent.name}_id',
298
+ // Fields to update
299
+ })
300
+ \`\`\`
301
+
302
+ `)
303
+ }
304
+ })
305
+ }
306
+
307
+
308
+ // Common methods
309
+ Content(`### Common Methods
310
+
311
+ #### \`data(data?: object)\`
312
+
313
+ Get or set the entity data. When called with data, sets the entity's
314
+ internal data and returns the current data. When called without
315
+ arguments, returns a copy of the current data.
316
+
317
+ #### \`match(match?: object)\`
318
+
319
+ Get or set the entity match criteria. Works the same as \`data()\`.
320
+
321
+ #### \`make()\`
322
+
323
+ Create a new \`${ent.Name}Entity\` instance with the same client and
324
+ options.
325
+
326
+ #### \`client()\`
327
+
328
+ Return the parent \`${model.Name}SDK\` instance.
329
+
330
+ #### \`entopts()\`
331
+
332
+ Return a copy of the entity options.
333
+
334
+ `)
335
+ })
336
+
337
+
338
+ // Features section
339
+ const activeFeatures = each(feature).filter((f: any) => f.active)
340
+ if (activeFeatures.length > 0) {
341
+ Content(`
342
+ ---
343
+
344
+ ## Features
345
+
346
+ | Feature | Version | Description |
347
+ | --- | --- | --- |
348
+ `)
349
+
350
+ activeFeatures.map((f: any) => {
351
+ Content(`| \`${f.name}\` | ${f.version || '0.0.1'} | ${f.title || ''} |
352
+ `)
353
+ })
354
+
355
+ Content(`
356
+
357
+ Features are activated via the \`feature\` option:
358
+
359
+ `)
360
+
361
+ Content(`\`\`\`ts
362
+ const client = new ${model.Name}SDK({
363
+ feature: {
364
+ `)
365
+ activeFeatures.map((f: any) => {
366
+ Content(` ${f.name}: { active: true },
367
+ `)
368
+ })
369
+ Content(` }
370
+ })
371
+ \`\`\`
372
+
373
+ `)
374
+ }
375
+
376
+ })
377
+ })
378
+
379
+
380
+
381
+
382
+ export {
383
+ ReadmeRef
384
+ }
@@ -1,5 +1,5 @@
1
1
 
2
- import { cmp, Content } from '@voxgig/sdkgen'
2
+ import { cmp, Content, isAuthActive } from '@voxgig/sdkgen'
3
3
 
4
4
  import {
5
5
  KIT,
@@ -14,12 +14,14 @@ const ReadmeTopQuick = cmp(function ReadmeTopQuick(props: any) {
14
14
  const entity = getModelPath(model, `main.${KIT}.entity`)
15
15
  const exampleEntity = Object.values(entity).find((e: any) => e.active !== false) as any
16
16
 
17
+ const apikeyArg = isAuthActive(model)
18
+ ? `\n apikey: process.env.${model.NAME}_APIKEY,\n`
19
+ : ''
20
+
17
21
  Content(`\`\`\`ts
18
22
  import { ${model.const.Name}SDK } from '${target.module.name}'
19
23
 
20
- const client = new ${model.const.Name}SDK({
21
- apikey: process.env.${model.NAME}_APIKEY,
22
- })
24
+ const client = new ${model.const.Name}SDK({${apikeyArg}})
23
25
 
24
26
  `)
25
27