@voxgig/sdkgen 4.35.1 → 4.35.2

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 CHANGED
@@ -8,7 +8,7 @@ const { Shape, One, Skip } = require('shape')
8
8
 
9
9
  const { SdkGen } = require('../dist/sdkgen.js')
10
10
 
11
- const VERSION = '4.35.1'
11
+ const VERSION = '4.35.2'
12
12
  const KONSOLE = console
13
13
 
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/sdkgen",
3
- "version": "4.35.1",
3
+ "version": "4.35.2",
4
4
  "main": "dist/sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -17,7 +17,7 @@ import {
17
17
  const LANG = 'py'
18
18
 
19
19
 
20
- // Python keywords that cannot be used as class-syntax TypedDict field names.
20
+ // Python keywords, which cannot be class-syntax TypedDict field names.
21
21
  const PY_KEYWORDS = new Set([
22
22
  'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break',
23
23
  'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally',
@@ -32,32 +32,49 @@ function pyIdent(name: string): boolean {
32
32
 
33
33
 
34
34
  function emitTypedDict(typeName: string, items: any[], log?: any): void {
35
- const usable = items.filter((it: any) => it && null != it.name && pyIdent(it.name))
36
-
37
- items.forEach((it: any) => {
38
- if (it && null != it.name && !pyIdent(it.name) && log && log.warn) {
39
- log.warn({
40
- point: 'entity-types-skip-field', typeName, field: it.name,
41
- note: `py: field "${it.name}" of ${typeName} has no legal class-syntax ` +
42
- `TypedDict key form; omitted from the typed model (still reachable ` +
43
- `via the runtime dict)`,
44
- })
45
- }
46
- })
35
+ const named = items.filter((it: any) => it && null != it.name)
47
36
 
48
- const required = usable.filter((it: any) => !it.optional)
49
- const optional = usable.filter((it: any) => it.optional)
37
+ const required = named.filter((it: any) => !it.optional)
38
+ const optional = named.filter((it: any) => it.optional)
50
39
 
51
40
  const field = (it: any) => ` ${it.name}: ${canonToType(it.type, LANG)}
52
41
  `
53
42
 
54
- if (0 === usable.length) {
43
+ if (0 === named.length) {
55
44
  Content(`class ${typeName}(TypedDict):
56
45
  pass
57
46
  `)
58
47
  return
59
48
  }
60
49
 
50
+ // A keyword, or a name that is not an identifier, has no class-syntax
51
+ // form. The functional form takes any string as a key, so the whole type
52
+ // takes that form; a mixed one inherits a required and an optional half.
53
+ if (named.some((it: any) => !pyIdent(it.name))) {
54
+ const entry = (it: any) => ` ${JSON.stringify(it.name)}: ${canonToType(it.type, LANG)},
55
+ `
56
+ const dict = (name: string, its: any[], total: boolean) =>
57
+ `${name} = TypedDict('${name}', {
58
+ ` + its.map(entry).join('') + `}${total ? '' : ', total=False'})
59
+ `
60
+
61
+ if (0 === required.length || 0 === optional.length) {
62
+ Content(dict(typeName, named, 0 === optional.length))
63
+ return
64
+ }
65
+
66
+ Content(dict(typeName + 'Required', required, true))
67
+ Content(`
68
+ `)
69
+ Content(dict(typeName + 'Optional', optional, false))
70
+ Content(`
71
+
72
+ class ${typeName}(${typeName}Required, ${typeName}Optional):
73
+ pass
74
+ `)
75
+ return
76
+ }
77
+
61
78
  if (0 === required.length) {
62
79
  Content(`class ${typeName}(TypedDict, total=False):
63
80
  `)
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen",
6
- "version": "4.35.1",
6
+ "version": "4.35.2",
7
7
  "provides": {
8
8
  "target": [
9
9
  "c",