@voxgig/sdkgen 4.2.2 → 4.2.3

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.2.2'
11
+ const VERSION = '4.2.3'
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.2.2",
3
+ "version": "4.2.3",
4
4
  "main": "dist/sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -7,7 +7,7 @@ import {
7
7
  getModelPath
8
8
  } from '@voxgig/apidef'
9
9
 
10
- import { rustVarName } from './utility_rust'
10
+ import { rustVarName, rustMethodName } from './utility_rust'
11
11
 
12
12
 
13
13
  // Entity accessor method on the SDK client, injected at the Main fragment
@@ -19,7 +19,7 @@ const MainEntity = cmp(async function MainEntity(props: any) {
19
19
 
20
20
  const entityColl = entityCollection(model)
21
21
  const cls = entityClassName(entity, entityColl)
22
- const method = rustVarName(entity.name)
22
+ const method = rustMethodName(entity.name)
23
23
  const mod = rustVarName(entity.name)
24
24
 
25
25
  Content(`
@@ -18,6 +18,32 @@ const RUST_RESERVED = new Set<string>([
18
18
  ])
19
19
 
20
20
 
21
+ // Method names on a generated struct that must never be an entity accessor.
22
+ //
23
+ // An entity called `clone` generated `pub fn clone(&self, Value)` on the SDK
24
+ // struct, which SHADOWS Clone::clone — so every `sdk.clone()` the generated
25
+ // code makes elsewhere resolved to the entity accessor and the crate failed
26
+ // with "this method takes 1 argument but 0 arguments were supplied", 16 times
27
+ // over, pointing at the call sites and never at the entity that caused it.
28
+ // `new` would collide with the struct's own constructor the same way.
29
+ //
30
+ // These are not Rust keywords, so RUST_RESERVED does not catch them; they are
31
+ // inherent or std-trait methods the generated code actually calls.
32
+ const RUST_METHOD_RESERVED = new Set<string>([
33
+ 'clone', 'new', 'default', 'drop', 'from', 'into', 'to_string',
34
+ 'as_ref', 'as_mut', 'borrow', 'borrow_mut', 'deref', 'deref_mut',
35
+ 'eq', 'ne', 'cmp', 'partial_cmp', 'hash', 'fmt', 'next', 'iter',
36
+ ])
37
+
38
+
39
+ // A snake_case rust METHOD name for a model name — rustVarName, plus a guard
40
+ // against shadowing a method the generated code calls on the same struct.
41
+ function rustMethodName(name: string): string {
42
+ const ident = rustVarName(name)
43
+ return RUST_METHOD_RESERVED.has(ident) ? ident + '_' : ident
44
+ }
45
+
46
+
21
47
  // A collision-free snake_case rust identifier for a model name.
22
48
  function rustVarName(name: string): string {
23
49
  let snake = name.replace(/[^a-zA-Z0-9_]/g, '_').toLowerCase()
@@ -170,6 +196,7 @@ function rustRawString(s: string): string {
170
196
  }
171
197
 
172
198
  export {
199
+ rustMethodName,
173
200
  rustRawString,
174
201
  clean,
175
202
  crateIdent,
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen",
6
- "version": "4.2.2",
6
+ "version": "4.2.3",
7
7
  "provides": {
8
8
  "target": [
9
9
  "c",