Skip to content

Commit a7f2419

Browse files
l2yshoclaude
andauthored
chore: replace structuredClone with es-toolkit cloneDeep in schema paths (#1041)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cb77da8 commit a7f2419

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"configparser": "~0.3.10",
9191
"cors": "~2.8.5",
9292
"detect-indent": "~7.0.1",
93+
"es-toolkit": "^1.45.1",
9394
"escape-string-regexp": "~5.0.0",
9495
"execa": "^9.5.2",
9596
"express": "~5.2.0",

src/lib/input_schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { existsSync, writeFileSync } from 'node:fs';
22
import { join } from 'node:path';
33

4+
import { cloneDeep } from 'es-toolkit';
5+
46
import { KEY_VALUE_STORE_KEYS } from '@apify/consts';
57
import { validateInputSchema } from '@apify/input_schema';
68

@@ -255,7 +257,7 @@ export const getDefaultsFromInputSchema = (inputSchema: any) => {
255257

256258
// Lots of code copied from @apify-packages/actor, this really should be moved to the shared input_schema package
257259
export const getAjvValidator = (inputSchema: any, ajvInstance: import('ajv').Ajv) => {
258-
const copyOfSchema = structuredClone(inputSchema);
260+
const copyOfSchema = cloneDeep(inputSchema);
259261
copyOfSchema.required = [];
260262

261263
for (const [inputSchemaFieldKey, inputSchemaField] of Object.entries<any>(inputSchema.properties)) {

src/lib/schema-transforms.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { cloneDeep } from 'es-toolkit';
2+
13
/**
24
* Transforms a JSON schema so that all properties without a `default` value are marked as required.
35
* Properties that have a `default` are left optional, since Apify fills them in at runtime.
46
* Recurses into nested object properties.
57
*/
68
export function makePropertiesRequired(schema: Record<string, unknown>): Record<string, unknown> {
7-
const clone = structuredClone(schema);
9+
const clone = cloneDeep(schema);
810

911
if (!clone.properties || typeof clone.properties !== 'object') {
1012
return clone;
@@ -35,7 +37,7 @@ export function makePropertiesRequired(schema: Record<string, unknown>): Record<
3537
* making every property optional at all nesting levels.
3638
*/
3739
export function clearAllRequired(schema: Record<string, unknown>): Record<string, unknown> {
38-
const clone = structuredClone(schema);
40+
const clone = cloneDeep(schema);
3941

4042
delete clone.required;
4143

@@ -59,7 +61,7 @@ export function clearAllRequired(schema: Record<string, unknown>): Record<string
5961
* to be inlined, ensuring only one exported interface per schema.
6062
*/
6163
export function stripTitles(schema: Record<string, unknown>): Record<string, unknown> {
62-
const clone = structuredClone(schema);
64+
const clone = cloneDeep(schema);
6365

6466
delete clone.title;
6567

@@ -137,7 +139,7 @@ export function prepareFieldsSchemaForCompilation(schema: Record<string, unknown
137139
return null;
138140
}
139141

140-
const clone = structuredClone(fields);
142+
const clone = cloneDeep(fields);
141143

142144
if (!clone.type) {
143145
clone.type = 'object';
@@ -162,7 +164,7 @@ export function prepareOutputSchemaForCompilation(schema: Record<string, unknown
162164
return null;
163165
}
164166

165-
const clonedProperties = structuredClone(properties);
167+
const clonedProperties = cloneDeep(properties);
166168

167169
// Strip non-JSON-Schema keys (like `template`) from each property
168170
for (const prop of Object.values(clonedProperties)) {
@@ -214,7 +216,7 @@ export function prepareKvsCollectionsForCompilation(
214216
continue;
215217
}
216218

217-
const clone = structuredClone(jsonSchema);
219+
const clone = cloneDeep(jsonSchema);
218220

219221
if (!clone.type) {
220222
clone.type = 'object';

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,7 @@ __metadata:
24412441
cors: "npm:~2.8.5"
24422442
cross-env: "npm:^10.0.0"
24432443
detect-indent: "npm:~7.0.1"
2444+
es-toolkit: "npm:^1.45.1"
24442445
escape-string-regexp: "npm:~5.0.0"
24452446
eslint: "npm:^9.25.1"
24462447
eslint-config-prettier: "npm:^10.1.2"
@@ -4076,7 +4077,7 @@ __metadata:
40764077
languageName: node
40774078
linkType: hard
40784079

4079-
"es-toolkit@npm:^1.39.7":
4080+
"es-toolkit@npm:^1.39.7, es-toolkit@npm:^1.45.1":
40804081
version: 1.45.1
40814082
resolution: "es-toolkit@npm:1.45.1"
40824083
dependenciesMeta:

0 commit comments

Comments
 (0)