({
id,
alias,
kind,
inner,
meta,
$,
ignoreCache,
shell,
unchecked
}: CreateNodeInput)
| 294 | export let lastCreated: string | undefined |
| 295 | |
| 296 | export const createNode = ({ |
| 297 | id, |
| 298 | alias, |
| 299 | kind, |
| 300 | inner, |
| 301 | meta, |
| 302 | $, |
| 303 | ignoreCache, |
| 304 | shell, |
| 305 | unchecked |
| 306 | }: CreateNodeInput): BaseNode => { |
| 307 | // serialized as the node is created, so meta that can't be throws here |
| 308 | const metaJson = isEmptyObject(meta) ? undefined : metaJsonOf(meta) |
| 309 | const impl = nodeImplementationsByKind[kind] |
| 310 | |
| 311 | // nodes are only cached with a set engine, which reduces them first |
| 312 | const key = |
| 313 | ignoreCache || hasSymbolMeta(meta) || !$ark.sets ? |
| 314 | undefined |
| 315 | : nodeKeyOf(kind, impl, inner, metaJson, $) |
| 316 | |
| 317 | if (key) { |
| 318 | const cached = $.nodesByKey.get(key) |
| 319 | // one whose check was thrown, or discarded with its definition, before it |
| 320 | // passed is created again, which makes the check again |
| 321 | if (cached && !cached.c.unchecked) { |
| 322 | $ark.reached?.node(cached) |
| 323 | return cached |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | let children: BaseNode[] = noChildren |
| 328 | for (const k in inner) { |
| 329 | const keyImpl = impl.keys[k] |
| 330 | if (!keyImpl.child) continue |
| 331 | const value = inner[k] as listable<BaseNode> |
| 332 | const held = |
| 333 | keyImpl.child === true ? |
| 334 | isArray(value) ? value |
| 335 | : [value] |
| 336 | : keyImpl.child(value as never) |
| 337 | // held by a union or a list alone, it's that list |
| 338 | children = |
| 339 | children === noChildren ? (held as BaseNode[]) : children.concat(held) |
| 340 | } |
| 341 | |
| 342 | const attachments: UnknownAttachmentsInput = { |
| 343 | id: id ?? registerNodeId(alias ?? kind), |
| 344 | kind, |
| 345 | impl, |
| 346 | inner, |
| 347 | meta, |
| 348 | metaJson, |
| 349 | children, |
| 350 | shell |
| 351 | } |
| 352 | |
| 353 | const node = composing(() => |
no test coverage detected