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

Method jsCopy

ark/schema/structure/structure.ts:1308–1322  ·  view source on GitHub ↗

writes `out`, which a transform writes into: data at the first site and where it writes in place

(js: NodeCompiler, options?: CopyOptions)

Source from the content-addressed store, hash-verified

1306
1307 /** writes `out`, which a transform writes into: data at the first site and where it writes in place */
1308 private jsCopy(js: NodeCompiler, options?: CopyOptions): NodeCompiler {
1309 if (this.writesInto(js)) return js
1310 const copy = () =>
1311 this.sequence ?
1312 this.jsCopyProps(
1313 js.set("out", `${js.ref(copyOf)}(data)`),
1314 "data",
1315 "out"
1316 )
1317 : js.set(
1318 "out",
1319 `${this.jsShapeCheck(js)}Object.getPrototypeOf(data) === Object.prototype ? { ...data } : ${js.ref(copyOf)}(data)`
1320 )
1321 return options?.first ? copy() : js.if("out === data", copy)
1322 }
1323
1324 /** writes the check of data's shape, reading a required key first; copyOf handles data without it */
1325 jsShapeCheck(js: NodeCompiler): string {

Callers 6

onChangeMethod · 0.95
tfKeyMethod · 0.95
jsDefaultsMethod · 0.95
jsSequenceDefaultsMethod · 0.95
jsDeleteFromCopyMethod · 0.95
deletesMethod · 0.95

Calls 3

writesIntoMethod · 0.95
ifMethod · 0.80
copyFunction · 0.50

Tested by

no test coverage detected