@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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/ReadmeErrors.js +15 -15
- package/dist/cmp/ReadmeErrors.js.map +1 -1
- package/dist/cmp/ReadmeExplanation.js +37 -35
- package/dist/cmp/ReadmeExplanation.js.map +1 -1
- package/dist/helpers/naming.js +29 -2
- package/dist/helpers/naming.js.map +1 -1
- package/dist/helpers/opShape.d.ts +6 -1
- package/dist/helpers/opShape.js +78 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +3 -1
- package/dist/sdkgen.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/go/EntityOperation_go.ts +8 -1
- package/project/.sdk/src/cmp/go/Entity_go.ts +20 -3
- package/project/.sdk/src/cmp/go/Main_go.ts +2 -1
- package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +5 -5
- package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +23 -12
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +27 -17
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +5 -5
- package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +5 -6
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +11 -11
- package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +2 -2
- package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +2 -2
- package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +2 -2
- package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +2 -2
- package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +2 -2
- package/project/.sdk/src/cmp/js/Entity_js.ts +18 -2
- package/project/.sdk/src/cmp/js/MainEntity_js.ts +12 -2
- package/project/.sdk/src/cmp/js/Main_js.ts +5 -2
- package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +5 -5
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +37 -26
- package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +5 -5
- package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +5 -6
- package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +3 -3
- package/project/.sdk/src/cmp/lua/EntityOperation_lua.ts +6 -1
- package/project/.sdk/src/cmp/lua/Entity_lua.ts +20 -2
- package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +8 -5
- package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +14 -7
- package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +9 -6
- package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +5 -2
- package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +8 -5
- package/project/.sdk/src/cmp/lua/ReadmeTopTest_lua.ts +5 -6
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +13 -13
- package/project/.sdk/src/cmp/lua/fragment/EntityCreateOp.fragment.lua +1 -1
- package/project/.sdk/src/cmp/lua/fragment/EntityListOp.fragment.lua +1 -1
- package/project/.sdk/src/cmp/lua/fragment/EntityLoadOp.fragment.lua +1 -1
- package/project/.sdk/src/cmp/lua/fragment/EntityRemoveOp.fragment.lua +1 -1
- package/project/.sdk/src/cmp/lua/fragment/EntityUpdateOp.fragment.lua +1 -1
- package/project/.sdk/src/cmp/php/Entity_php.ts +17 -1
- package/project/.sdk/src/cmp/php/MainEntity_php.ts +12 -3
- package/project/.sdk/src/cmp/php/ReadmeHowto_php.ts +15 -8
- package/project/.sdk/src/cmp/php/ReadmeTopTest_php.ts +5 -6
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +2 -2
- package/project/.sdk/src/cmp/py/Entity_py.ts +18 -1
- package/project/.sdk/src/cmp/py/MainEntity_py.ts +14 -4
- package/project/.sdk/src/cmp/py/Main_py.ts +2 -1
- package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +8 -5
- package/project/.sdk/src/cmp/py/ReadmeHowto_py.ts +18 -8
- package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +10 -7
- package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +7 -4
- package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +9 -6
- package/project/.sdk/src/cmp/py/ReadmeTopTest_py.ts +6 -7
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +2 -2
- package/project/.sdk/src/cmp/rb/Entity_rb.ts +17 -1
- package/project/.sdk/src/cmp/rb/MainEntity_rb.ts +11 -2
- package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +8 -5
- package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +20 -8
- package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +9 -6
- package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +5 -2
- package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +8 -5
- package/project/.sdk/src/cmp/rb/ReadmeTopTest_rb.ts +10 -8
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +2 -2
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +18 -2
- package/project/.sdk/src/cmp/ts/MainEntity_ts.ts +12 -2
- package/project/.sdk/src/cmp/ts/Main_ts.ts +5 -2
- package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +5 -5
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +36 -26
- package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +4 -5
- package/project/.sdk/src/cmp/ts/ReadmeTopTest_ts.ts +5 -6
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +4 -4
- package/src/cmp/ReadmeErrors.ts +16 -17
- package/src/cmp/ReadmeExplanation.ts +37 -35
- package/src/helpers/naming.ts +32 -2
- package/src/helpers/opShape.ts +89 -0
- package/src/sdkgen.ts +3 -1
package/src/helpers/opShape.ts
CHANGED
|
@@ -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
|
|