Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"configparser": "~0.3.10",
"cors": "~2.8.5",
"detect-indent": "~7.0.1",
"es-toolkit": "^1.45.1",
"escape-string-regexp": "~5.0.0",
"execa": "^9.5.2",
"express": "~5.2.0",
Expand Down
4 changes: 3 additions & 1 deletion src/lib/input_schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { existsSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

import { cloneDeep } from 'es-toolkit';

import { KEY_VALUE_STORE_KEYS } from '@apify/consts';
import { validateInputSchema } from '@apify/input_schema';

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

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

for (const [inputSchemaFieldKey, inputSchemaField] of Object.entries<any>(inputSchema.properties)) {
Expand Down
14 changes: 8 additions & 6 deletions src/lib/schema-transforms.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { cloneDeep } from 'es-toolkit';

/**
* Transforms a JSON schema so that all properties without a `default` value are marked as required.
* Properties that have a `default` are left optional, since Apify fills them in at runtime.
* Recurses into nested object properties.
*/
export function makePropertiesRequired(schema: Record<string, unknown>): Record<string, unknown> {
const clone = structuredClone(schema);
const clone = cloneDeep(schema);

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

delete clone.required;

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

delete clone.title;

Expand Down Expand Up @@ -137,7 +139,7 @@ export function prepareFieldsSchemaForCompilation(schema: Record<string, unknown
return null;
}

const clone = structuredClone(fields);
const clone = cloneDeep(fields);

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

const clonedProperties = structuredClone(properties);
const clonedProperties = cloneDeep(properties);

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

const clone = structuredClone(jsonSchema);
const clone = cloneDeep(jsonSchema);

if (!clone.type) {
clone.type = 'object';
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2441,6 +2441,7 @@ __metadata:
cors: "npm:~2.8.5"
cross-env: "npm:^10.0.0"
detect-indent: "npm:~7.0.1"
es-toolkit: "npm:^1.45.1"
escape-string-regexp: "npm:~5.0.0"
eslint: "npm:^9.25.1"
eslint-config-prettier: "npm:^10.1.2"
Expand Down Expand Up @@ -4076,7 +4077,7 @@ __metadata:
languageName: node
linkType: hard

"es-toolkit@npm:^1.39.7":
"es-toolkit@npm:^1.39.7, es-toolkit@npm:^1.45.1":
version: 1.45.1
resolution: "es-toolkit@npm:1.45.1"
dependenciesMeta:
Expand Down