MCPcopy Create free account
hub / github.com/arktypeio/arktype / jsCopyOnce

Method jsCopyOnce

ark/schema/structure/structure.ts:1273–1285  ·  view source on GitHub ↗

writes the copy of a plain object missing every default, its only changes, once

(js: NodeCompiler)

Source from the content-addressed store, hash-verified

1271
1272 /** writes the copy of a plain object missing every default, its only changes, once */
1273 private jsCopyOnce(js: NodeCompiler): NodeCompiler {
1274 if (this.hasMorph || this.undeclared === "delete" || js.inPlace) return js
1275 const keys = this.defaultable.map(prop => prop.key)
1276 return js.if(
1277 `${keys.map(k => `!(${js.serialize(k)} in data) && `).join("")}${this.jsShapeCheck(js)}Object.getPrototypeOf(data) === Object.prototype`,
1278 () => {
1279 js.const("out", "{ ...data }")
1280 for (const prop of this.defaultable)
1281 compileDefault(js, prop, "out", true)
1282 return this.jsDeclaredCopy(js, keys).return("out")
1283 }
1284 )
1285 }
1286
1287 /** writes the defaults of its missing keys */
1288 private jsDefaults(js: NodeCompiler, options?: CopyOptions): NodeCompiler {

Callers 1

jsTfMethod · 0.95

Calls 7

jsShapeCheckMethod · 0.95
jsDeclaredCopyMethod · 0.95
compileDefaultFunction · 0.85
ifMethod · 0.80
constMethod · 0.80
returnMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected