@voxgig/sdkgen 1.3.4 → 1.3.5

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 (87) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ReadmeErrors.js +15 -15
  3. package/dist/cmp/ReadmeErrors.js.map +1 -1
  4. package/dist/cmp/ReadmeExplanation.js +37 -35
  5. package/dist/cmp/ReadmeExplanation.js.map +1 -1
  6. package/dist/helpers/naming.js +29 -2
  7. package/dist/helpers/naming.js.map +1 -1
  8. package/dist/helpers/opShape.d.ts +6 -1
  9. package/dist/helpers/opShape.js +78 -0
  10. package/dist/helpers/opShape.js.map +1 -1
  11. package/dist/sdkgen.d.ts +2 -2
  12. package/dist/sdkgen.js +3 -1
  13. package/dist/sdkgen.js.map +1 -1
  14. package/package.json +1 -1
  15. package/project/.sdk/src/cmp/go/EntityOperation_go.ts +8 -1
  16. package/project/.sdk/src/cmp/go/Entity_go.ts +20 -3
  17. package/project/.sdk/src/cmp/go/Main_go.ts +2 -1
  18. package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +5 -5
  19. package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +23 -12
  20. package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +27 -17
  21. package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +5 -5
  22. package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +5 -6
  23. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +11 -11
  24. package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +2 -2
  25. package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +2 -2
  26. package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +2 -2
  27. package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +2 -2
  28. package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +2 -2
  29. package/project/.sdk/src/cmp/js/Entity_js.ts +18 -2
  30. package/project/.sdk/src/cmp/js/MainEntity_js.ts +12 -2
  31. package/project/.sdk/src/cmp/js/Main_js.ts +5 -2
  32. package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +5 -5
  33. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +37 -26
  34. package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +5 -5
  35. package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +5 -6
  36. package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +3 -3
  37. package/project/.sdk/src/cmp/lua/EntityOperation_lua.ts +6 -1
  38. package/project/.sdk/src/cmp/lua/Entity_lua.ts +20 -2
  39. package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +8 -5
  40. package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +14 -7
  41. package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +9 -6
  42. package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +5 -2
  43. package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +8 -5
  44. package/project/.sdk/src/cmp/lua/ReadmeTopTest_lua.ts +5 -6
  45. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +13 -13
  46. package/project/.sdk/src/cmp/lua/fragment/EntityCreateOp.fragment.lua +1 -1
  47. package/project/.sdk/src/cmp/lua/fragment/EntityListOp.fragment.lua +1 -1
  48. package/project/.sdk/src/cmp/lua/fragment/EntityLoadOp.fragment.lua +1 -1
  49. package/project/.sdk/src/cmp/lua/fragment/EntityRemoveOp.fragment.lua +1 -1
  50. package/project/.sdk/src/cmp/lua/fragment/EntityUpdateOp.fragment.lua +1 -1
  51. package/project/.sdk/src/cmp/php/Entity_php.ts +17 -1
  52. package/project/.sdk/src/cmp/php/MainEntity_php.ts +12 -3
  53. package/project/.sdk/src/cmp/php/ReadmeHowto_php.ts +15 -8
  54. package/project/.sdk/src/cmp/php/ReadmeTopTest_php.ts +5 -6
  55. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +2 -2
  56. package/project/.sdk/src/cmp/py/Entity_py.ts +18 -1
  57. package/project/.sdk/src/cmp/py/MainEntity_py.ts +14 -4
  58. package/project/.sdk/src/cmp/py/Main_py.ts +2 -1
  59. package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +8 -5
  60. package/project/.sdk/src/cmp/py/ReadmeHowto_py.ts +18 -8
  61. package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +10 -7
  62. package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +7 -4
  63. package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +9 -6
  64. package/project/.sdk/src/cmp/py/ReadmeTopTest_py.ts +6 -7
  65. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +2 -2
  66. package/project/.sdk/src/cmp/rb/Entity_rb.ts +17 -1
  67. package/project/.sdk/src/cmp/rb/MainEntity_rb.ts +11 -2
  68. package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +8 -5
  69. package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +20 -8
  70. package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +9 -6
  71. package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +5 -2
  72. package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +8 -5
  73. package/project/.sdk/src/cmp/rb/ReadmeTopTest_rb.ts +10 -8
  74. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +2 -2
  75. package/project/.sdk/src/cmp/ts/Entity_ts.ts +18 -2
  76. package/project/.sdk/src/cmp/ts/MainEntity_ts.ts +12 -2
  77. package/project/.sdk/src/cmp/ts/Main_ts.ts +5 -2
  78. package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +5 -5
  79. package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +36 -26
  80. package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +4 -5
  81. package/project/.sdk/src/cmp/ts/ReadmeTopTest_ts.ts +5 -6
  82. package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +4 -4
  83. package/src/cmp/ReadmeErrors.ts +16 -17
  84. package/src/cmp/ReadmeExplanation.ts +37 -35
  85. package/src/helpers/naming.ts +32 -2
  86. package/src/helpers/opShape.ts +89 -0
  87. package/src/sdkgen.ts +3 -1
@@ -238,6 +238,93 @@ function entityPrimaryOp(ent: any): string | null {
238
238
  }
239
239
 
240
240
 
241
+ // Collision-free target-language CLASS name for an entity. The natural
242
+ // class name is `<Name>Entity`, but that can equal another entity's
243
+ // canonical DATA-type name `<Name'>` when Name' === Name + 'Entity' (e.g.
244
+ // GitLab's `project` -> class `ProjectEntity` collides with `project_entity`
245
+ // -> data type `ProjectEntity`), which redeclares a type in Go and merges/
246
+ // shadows it in ts/py/rb. This assigns each entity a class name that is
247
+ // unique across ALL emitted top-level type names (every entity's data type
248
+ // and per-op Match/Data types, plus already-assigned class names): the
249
+ // natural `<Name>Entity` when free, else `<Name>EntityClient`, `...Client2`,
250
+ // … The DATA type keeps its canonical `<Name>` — only the suffixed class
251
+ // yields. Deterministic (sorted-key iteration) and stable across runs.
252
+ //
253
+ // Memoised per entity-collection object so the O(n) assignment runs once.
254
+ const _classNameCache = new WeakMap<object, Record<string, string>>()
255
+
256
+ function entityClassNames(entityColl: any): Record<string, string> {
257
+ const cached = _classNameCache.get(entityColl)
258
+ if (null != cached) {
259
+ return cached
260
+ }
261
+
262
+ const ents = each(entityColl).filter((e: any) => e && e.active !== false)
263
+
264
+ // 1. Every top-level DATA-type name the target emits.
265
+ const taken: Record<string, boolean> = {}
266
+ ents.forEach((e: any) => {
267
+ taken[e.Name] = true
268
+ for (const op of ['load', 'list', 'create', 'update', 'remove']) {
269
+ if (e.op && e.op[op]) {
270
+ taken[opTypeName(e.Name, op)] = true
271
+ }
272
+ }
273
+ })
274
+
275
+ // 2. Assign each class name, avoiding all data types and prior classes.
276
+ const out: Record<string, string> = {}
277
+ ents.forEach((e: any) => {
278
+ let name = e.Name + 'Entity'
279
+ if (taken[name]) {
280
+ const base = name + 'Client'
281
+ name = base
282
+ let n = 1
283
+ while (taken[name]) {
284
+ n++
285
+ name = base + n
286
+ }
287
+ }
288
+ taken[name] = true
289
+ out[e.name] = name
290
+ })
291
+
292
+ _classNameCache.set(entityColl, out)
293
+ return out
294
+ }
295
+
296
+
297
+ // The collision-free class name for one entity (see entityClassNames).
298
+ // `entityColl` is main.<KIT>.entity (the collection the entity belongs to).
299
+ function entityClassName(ent: any, entityColl: any): string {
300
+ if (null == ent) {
301
+ return ''
302
+ }
303
+ const map = entityClassNames(entityColl)
304
+ return map[ent.name] || (ent.Name + 'Entity')
305
+ }
306
+
307
+
308
+ // Pick a representative entity for a single illustrative snippet (e.g. the
309
+ // README's test-mode example): the first ACTIVE entity that exposes a read
310
+ // op (list/load) so the snippet is meaningful, else the first with ANY
311
+ // active op, else the first active entity. Returns { entity, primaryOp }
312
+ // where primaryOp is null only when NO entity has an op — so callers never
313
+ // fabricate an op the entity lacks (the cause of `.load()` on an op-less
314
+ // entity like Cloudsmith's `Abort`). Entities iterate in sorted-key order
315
+ // for deterministic output.
316
+ function pickExampleEntity(entity: any): { entity: any, primaryOp: string | null } {
317
+ const actives = each(entity).filter((e: any) => e && e.active !== false)
318
+ const readable = actives.find((e: any) => {
319
+ const op = entityPrimaryOp(e)
320
+ return 'list' === op || 'load' === op
321
+ })
322
+ const withOp = actives.find((e: any) => null != entityPrimaryOp(e))
323
+ const chosen = readable || withOp || actives[0] || null
324
+ return { entity: chosen, primaryOp: null == chosen ? null : entityPrimaryOp(chosen) }
325
+ }
326
+
327
+
241
328
  // The id field on the entity's DATA type (its fields[]), or null. DISTINCT from
242
329
  // entityIdField (the load-MATCH key): an API can model a load match that carries
243
330
  // an `id` param while the response entity itself has no `id` field, so `.id`
@@ -267,6 +354,8 @@ export {
267
354
  entityDataIdField,
268
355
  entityOps,
269
356
  entityPrimaryOp,
357
+ pickExampleEntity,
358
+ entityClassName,
270
359
  }
271
360
 
272
361
  export type {
package/src/sdkgen.ts CHANGED
@@ -48,7 +48,7 @@ import { getMatchEntries } from './helpers/getMatchEntries'
48
48
  import { collectDeps } from './helpers/collectDeps'
49
49
  import type { DepEntry } from './helpers/collectDeps'
50
50
  import { canonToType, canonKey } from './helpers/canonType'
51
- import { OP_SUFFIX, opTypeName, opParams, opRequestShape, entityIdField, entityDataIdField, entityOps, entityPrimaryOp } from './helpers/opShape'
51
+ import { OP_SUFFIX, opTypeName, opParams, opRequestShape, entityIdField, entityDataIdField, entityOps, entityPrimaryOp, pickExampleEntity, entityClassName } from './helpers/opShape'
52
52
  import { isReservedName, safeVarName } from './helpers/naming'
53
53
  import {
54
54
  packageName,
@@ -448,6 +448,8 @@ export {
448
448
  entityDataIdField,
449
449
  entityOps,
450
450
  entityPrimaryOp,
451
+ pickExampleEntity,
452
+ entityClassName,
451
453
  isReservedName,
452
454
  safeVarName,
453
455