MCPcopy Create free account
hub / github.com/instantdb/instant / entityDefToCodeStr

Function entityDefToCodeStr

client/packages/platform/src/schema.ts:273–289  ·  view source on GitHub ↗
(
  name: string,
  edef: EntityDef<
    AttrsDefs,
    Record<string, LinkAttrDef<CardinalityKind, string>>,
    any
  >,
)

Source from the content-addressed store, hash-verified

271}
272
273function entityDefToCodeStr(
274 name: string,
275 edef: EntityDef<
276 AttrsDefs,
277 Record<string, LinkAttrDef<CardinalityKind, string>>,
278 any
279 >,
280) {
281 const attrBlock = joinWithTrailingSep(
282 sortedEntries(edef.attrs).map(attrDefToCodeString),
283 ',\n',
284 ',',
285 );
286
287 // a block of code for each entity
288 return `${formatKey(name)}: i.entity({${attrBlock.length ? '\n' : ''}${indentLines(attrBlock, 2)}${attrBlock.length ? '\n' : ''}})`;
289}
290
291export function identEtype(ident: InstantDBIdent) {
292 return ident[1];

Callers 2

roomDefToCodeStrFunction · 0.85

Calls 4

joinWithTrailingSepFunction · 0.90
sortedEntriesFunction · 0.90
formatKeyFunction · 0.90
indentLinesFunction · 0.90

Tested by

no test coverage detected