apify-schema-tools 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/apify-schema-tools.js +8 -2
- package/dist/apify-schema-tools.js.map +1 -1
- package/dist/apify.d.ts +1 -0
- package/dist/apify.d.ts.map +1 -1
- package/dist/apify.js +13 -10
- package/dist/apify.js.map +1 -1
- package/package.json +1 -1
- package/samples/all-defaults/src/generated/input-utils.ts +21 -13
- package/samples/deep-merged-schemas/src/generated/input-utils.ts +22 -14
- package/samples/merged-schemas/src/generated/input-utils.ts +21 -13
- package/samples/package-json-config/src/custom-generated/input-utils.ts +21 -13
- package/src/apify-schema-tools.ts +9 -2
- package/src/apify.ts +18 -14
- package/test/apify-schema-tools.test.ts +1 -1
- package/test/apify.test.ts +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { ArgumentDefaultsHelpFormatter, ArgumentParser } from "argparse";
|
|
5
|
-
import { ACTOR_CONFIG_PATH, DATASET_SCHEMA_FIELD, filterValidInputSchemaProperties, generateInputDefaultsTSFileContent, } from "./apify.js";
|
|
5
|
+
import { ACTOR_CONFIG_PATH, DATASET_SCHEMA_FIELD, filterValidInputSchemaProperties, generateInputDefaultsTSFileContent, getPathRelativeToActorConfig, } from "./apify.js";
|
|
6
6
|
import { addCommonCLIArgs, parseConfigurationFromFileOrDefault, writeConfigurationToPackageJson, } from "./configuration.js";
|
|
7
7
|
import { readFile, writeFile } from "./filesystem.js";
|
|
8
8
|
import { compareSchemas, mergeObjectSchemas, readJsonSchema, readJsonSchemaField, writeJsonSchema, writeSchemaToField, } from "./json-schemas.js";
|
|
@@ -66,7 +66,13 @@ function init(args) {
|
|
|
66
66
|
}
|
|
67
67
|
const actorConfig = JSON.parse(readFile(ACTOR_CONFIG_PATH));
|
|
68
68
|
if (actorConfig.storages?.dataset !== args.dataset_schema) {
|
|
69
|
-
writeFile(ACTOR_CONFIG_PATH, JSON.stringify({
|
|
69
|
+
writeFile(ACTOR_CONFIG_PATH, JSON.stringify({
|
|
70
|
+
...actorConfig,
|
|
71
|
+
storages: {
|
|
72
|
+
...actorConfig.storages,
|
|
73
|
+
dataset: getPathRelativeToActorConfig(args.dataset_schema),
|
|
74
|
+
},
|
|
75
|
+
}, null, 4));
|
|
70
76
|
console.log(`Updated ${ACTOR_CONFIG_PATH} to use the dataset schema at ${args.dataset_schema}`);
|
|
71
77
|
}
|
|
72
78
|
if (!existsSync(args.dataset_schema)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apify-schema-tools.js","sourceRoot":"","sources":["../src/apify-schema-tools.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"apify-schema-tools.js","sourceRoot":"","sources":["../src/apify-schema-tools.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,6BAA6B,EAAwB,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,EACN,iBAAiB,EACjB,oBAAoB,EACpB,gCAAgC,EAChC,kCAAkC,EAClC,4BAA4B,GAC5B,MAAM,YAAY,CAAC;AACpB,OAAO,EAEN,gBAAgB,EAChB,mCAAmC,EACnC,+BAA+B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,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AG,2BAA2B,CACtD,wBAAwB,EACxB,kBAAkB,EAClB,IAAI,CAAC,mBAAmB,CACxB,CAAC;YACF,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBAC1B,OAAO,CAAC,KAAK,CACZ,4GAA4G,CAC5G,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACjB,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC;AACD,WAAW,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAE1C,oBAAoB;AAEpB,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC;AAC3C,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/apify.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ObjectSchema } from "./json-schemas.js";
|
|
2
2
|
export declare const ACTOR_CONFIG_PATH = ".actor/actor.json";
|
|
3
|
+
export declare function getPathRelativeToActorConfig(path: string): string;
|
|
3
4
|
export declare function filterValidInputSchemaProperties(schema: ObjectSchema): ObjectSchema;
|
|
4
5
|
/**
|
|
5
6
|
* Generates the content of a TypeScript file that exports a function to fill
|
package/dist/apify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apify.d.ts","sourceRoot":"","sources":["../src/apify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apify.d.ts","sourceRoot":"","sources":["../src/apify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAA+B,MAAM,mBAAmB,CAAC;AAGnF,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjE;AA+CD,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAQnF;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,WAAW,EAAE,YAAY,UAyE3E;AAED,eAAO,MAAM,oBAAoB,WAAW,CAAC"}
|
package/dist/apify.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { dirname, relative } from "node:path";
|
|
1
2
|
import { filterValidSchemaProperties } from "./json-schemas.js";
|
|
2
3
|
import { jsonSchemaToTypeScriptInterface, serializeTypeScriptSchema } from "./typescript.js";
|
|
3
4
|
export const ACTOR_CONFIG_PATH = ".actor/actor.json";
|
|
5
|
+
export function getPathRelativeToActorConfig(path) {
|
|
6
|
+
return `./${relative(dirname(ACTOR_CONFIG_PATH), path)}`;
|
|
7
|
+
}
|
|
4
8
|
const VALID_INPUT_ROOT_KEYS = ["title", "description", "type", "schemaVersion", "properties", "required"];
|
|
5
9
|
const VALID_INPUT_PROPERTY_KEYS = [
|
|
6
10
|
"type",
|
|
@@ -57,16 +61,16 @@ export function generateInputDefaultsTSFileContent(inputSchema) {
|
|
|
57
61
|
defaultValues[property] = definition.default;
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
|
-
const
|
|
61
|
-
const
|
|
64
|
+
const tsInterface = jsonSchemaToTypeScriptInterface(inputSchema);
|
|
65
|
+
const defaultInterface = {
|
|
62
66
|
isArray: false,
|
|
63
67
|
isRequired: true,
|
|
64
68
|
properties: {},
|
|
65
69
|
};
|
|
66
70
|
const requiredParamsWithoutDefaults = [];
|
|
67
|
-
for (const [key, schema] of Object.entries(
|
|
68
|
-
if (
|
|
69
|
-
|
|
71
|
+
for (const [key, schema] of Object.entries(tsInterface.properties)) {
|
|
72
|
+
if (key in defaultValues) {
|
|
73
|
+
defaultInterface.properties[key] = {
|
|
70
74
|
...schema,
|
|
71
75
|
isRequired: true,
|
|
72
76
|
};
|
|
@@ -75,14 +79,14 @@ export function generateInputDefaultsTSFileContent(inputSchema) {
|
|
|
75
79
|
requiredParamsWithoutDefaults.push(key);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
|
-
const areThereDefaults = Object.keys(
|
|
82
|
+
const areThereDefaults = Object.keys(defaultInterface.properties).length > 0;
|
|
79
83
|
return `\
|
|
80
84
|
import { Actor } from "apify";
|
|
81
85
|
import type { Input } from "./input.js";
|
|
82
86
|
|
|
83
87
|
${areThereDefaults
|
|
84
88
|
? `\
|
|
85
|
-
interface DefaultInputs ${serializeTypeScriptSchema(
|
|
89
|
+
interface DefaultInputs ${serializeTypeScriptSchema(defaultInterface)};
|
|
86
90
|
|
|
87
91
|
export type InputWithDefaults = Input & DefaultInputs;
|
|
88
92
|
|
|
@@ -98,9 +102,8 @@ export function getInputWithDefaultValues(input?: Input | null): InputWithDefaul
|
|
|
98
102
|
if (Actor.isAtHome()) {
|
|
99
103
|
// The platform is supposed to fill in the default values
|
|
100
104
|
return input as InputWithDefaults;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
? `\
|
|
105
|
+
}${requiredParamsWithoutDefaults.length > 0
|
|
106
|
+
? `
|
|
104
107
|
if (!input) {
|
|
105
108
|
throw new Error(\`Input is required, because the following fields are required: $\{REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT.join(", ")\}\`);
|
|
106
109
|
}`
|
package/dist/apify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apify.js","sourceRoot":"","sources":["../src/apify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAA4B,+BAA+B,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEvH,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAErD,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AAE1G,MAAM,yBAAyB,GAAG;IACjC,MAAM;IACN,OAAO;IACP,aAAa;IACb,SAAS;IACT,SAAS;IAC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AC,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG;QAC/F,CAAC,CAAC;;;iEAIJ;;uDAEuD,IAAI,CAAC,SAAS,CAAC,6BAA6B,EAAE,IAAI,EAAE,IAAI,CAAC;;;;;;IAO9G,6BAA6B,CAAC,MAAM,GAAG,CAAC;QACvC,CAAC,CAAC;;;GAGF;QACA,CAAC,CAAC,EACJ;EAEA,gBAAgB;QACf,CAAC,CAAC;;;;IAIA;QACF,CAAC,CAAC;8BAEJ;;CAEC,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -7,19 +7,13 @@
|
|
|
7
7
|
import { Actor } from "apify";
|
|
8
8
|
import type { Input } from "./input.js";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
debugMode: false,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
21
|
-
|
|
22
|
-
export type InputWithDefaults = Input & {
|
|
10
|
+
interface DefaultInputs {
|
|
11
|
+
/**
|
|
12
|
+
* List of URLs to scrape
|
|
13
|
+
*/
|
|
14
|
+
startUrls: {
|
|
15
|
+
url?: string;
|
|
16
|
+
}[];
|
|
23
17
|
/**
|
|
24
18
|
* List of categories to filter results
|
|
25
19
|
*/
|
|
@@ -41,8 +35,22 @@ export type InputWithDefaults = Input & {
|
|
|
41
35
|
* Enable debug logging
|
|
42
36
|
*/
|
|
43
37
|
debugMode: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type InputWithDefaults = Input & DefaultInputs;
|
|
41
|
+
|
|
42
|
+
export const DEFAULT_INPUT_VALUES: DefaultInputs = {
|
|
43
|
+
startUrls: [],
|
|
44
|
+
categories: [],
|
|
45
|
+
maxPages: 10,
|
|
46
|
+
proxy: {
|
|
47
|
+
useApifyProxy: true,
|
|
48
|
+
},
|
|
49
|
+
debugMode: false,
|
|
44
50
|
};
|
|
45
51
|
|
|
52
|
+
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
53
|
+
|
|
46
54
|
export function getInputWithDefaultValues(input?: Input | null): InputWithDefaults {
|
|
47
55
|
if (Actor.isAtHome()) {
|
|
48
56
|
// The platform is supposed to fill in the default values
|
|
@@ -7,20 +7,13 @@
|
|
|
7
7
|
import { Actor } from "apify";
|
|
8
8
|
import type { Input } from "./input.js";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
maxRetries: 3,
|
|
18
|
-
debugMode: false,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
22
|
-
|
|
23
|
-
export type InputWithDefaults = Input & {
|
|
10
|
+
interface DefaultInputs {
|
|
11
|
+
/**
|
|
12
|
+
* List of URLs to scrape
|
|
13
|
+
*/
|
|
14
|
+
startUrls: {
|
|
15
|
+
url?: string;
|
|
16
|
+
}[];
|
|
24
17
|
/**
|
|
25
18
|
* List of categories to filter results
|
|
26
19
|
*/
|
|
@@ -47,8 +40,23 @@ export type InputWithDefaults = Input & {
|
|
|
47
40
|
* Enable debug logging
|
|
48
41
|
*/
|
|
49
42
|
debugMode: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type InputWithDefaults = Input & DefaultInputs;
|
|
46
|
+
|
|
47
|
+
export const DEFAULT_INPUT_VALUES: DefaultInputs = {
|
|
48
|
+
startUrls: [],
|
|
49
|
+
categories: [],
|
|
50
|
+
maxPages: 10,
|
|
51
|
+
proxy: {
|
|
52
|
+
useApifyProxy: true,
|
|
53
|
+
},
|
|
54
|
+
maxRetries: 3,
|
|
55
|
+
debugMode: false,
|
|
50
56
|
};
|
|
51
57
|
|
|
58
|
+
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
59
|
+
|
|
52
60
|
export function getInputWithDefaultValues(input?: Input | null): InputWithDefaults {
|
|
53
61
|
if (Actor.isAtHome()) {
|
|
54
62
|
// The platform is supposed to fill in the default values
|
|
@@ -7,19 +7,13 @@
|
|
|
7
7
|
import { Actor } from "apify";
|
|
8
8
|
import type { Input } from "./input.js";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
debugMode: false,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
21
|
-
|
|
22
|
-
export type InputWithDefaults = Input & {
|
|
10
|
+
interface DefaultInputs {
|
|
11
|
+
/**
|
|
12
|
+
* List of URLs to scrape
|
|
13
|
+
*/
|
|
14
|
+
startUrls: {
|
|
15
|
+
url?: string;
|
|
16
|
+
}[];
|
|
23
17
|
/**
|
|
24
18
|
* Maximum number of pages to scrape
|
|
25
19
|
*/
|
|
@@ -38,8 +32,22 @@ export type InputWithDefaults = Input & {
|
|
|
38
32
|
* Enable debug logging
|
|
39
33
|
*/
|
|
40
34
|
debugMode: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type InputWithDefaults = Input & DefaultInputs;
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_INPUT_VALUES: DefaultInputs = {
|
|
40
|
+
startUrls: [],
|
|
41
|
+
maxPages: 10,
|
|
42
|
+
proxy: {
|
|
43
|
+
useApifyProxy: true,
|
|
44
|
+
},
|
|
45
|
+
maxRetries: 3,
|
|
46
|
+
debugMode: false,
|
|
41
47
|
};
|
|
42
48
|
|
|
49
|
+
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
50
|
+
|
|
43
51
|
export function getInputWithDefaultValues(input?: Input | null): InputWithDefaults {
|
|
44
52
|
if (Actor.isAtHome()) {
|
|
45
53
|
// The platform is supposed to fill in the default values
|
|
@@ -7,19 +7,13 @@
|
|
|
7
7
|
import { Actor } from "apify";
|
|
8
8
|
import type { Input } from "./input.js";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
debugMode: false,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
21
|
-
|
|
22
|
-
export type InputWithDefaults = Input & {
|
|
10
|
+
interface DefaultInputs {
|
|
11
|
+
/**
|
|
12
|
+
* List of URLs to scrape
|
|
13
|
+
*/
|
|
14
|
+
startUrls: {
|
|
15
|
+
url?: string;
|
|
16
|
+
}[];
|
|
23
17
|
/**
|
|
24
18
|
* List of categories to filter results
|
|
25
19
|
*/
|
|
@@ -41,8 +35,22 @@ export type InputWithDefaults = Input & {
|
|
|
41
35
|
* Enable debug logging
|
|
42
36
|
*/
|
|
43
37
|
debugMode: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type InputWithDefaults = Input & DefaultInputs;
|
|
41
|
+
|
|
42
|
+
export const DEFAULT_INPUT_VALUES: DefaultInputs = {
|
|
43
|
+
startUrls: [],
|
|
44
|
+
categories: [],
|
|
45
|
+
maxPages: 10,
|
|
46
|
+
proxy: {
|
|
47
|
+
useApifyProxy: true,
|
|
48
|
+
},
|
|
49
|
+
debugMode: false,
|
|
44
50
|
};
|
|
45
51
|
|
|
52
|
+
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ["searchTerm"];
|
|
53
|
+
|
|
46
54
|
export function getInputWithDefaultValues(input?: Input | null): InputWithDefaults {
|
|
47
55
|
if (Actor.isAtHome()) {
|
|
48
56
|
// The platform is supposed to fill in the default values
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { existsSync
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { ArgumentDefaultsHelpFormatter, type ArgumentOptions, ArgumentParser } from "argparse";
|
|
6
6
|
import {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
DATASET_SCHEMA_FIELD,
|
|
9
9
|
filterValidInputSchemaProperties,
|
|
10
10
|
generateInputDefaultsTSFileContent,
|
|
11
|
+
getPathRelativeToActorConfig,
|
|
11
12
|
} from "./apify.js";
|
|
12
13
|
import {
|
|
13
14
|
type CommonCLIArgs,
|
|
@@ -113,7 +114,13 @@ function init(args: InitArgs) {
|
|
|
113
114
|
writeFile(
|
|
114
115
|
ACTOR_CONFIG_PATH,
|
|
115
116
|
JSON.stringify(
|
|
116
|
-
{
|
|
117
|
+
{
|
|
118
|
+
...actorConfig,
|
|
119
|
+
storages: {
|
|
120
|
+
...actorConfig.storages,
|
|
121
|
+
dataset: getPathRelativeToActorConfig(args.dataset_schema),
|
|
122
|
+
},
|
|
123
|
+
},
|
|
117
124
|
null,
|
|
118
125
|
4,
|
|
119
126
|
),
|
package/src/apify.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { dirname, relative } from "node:path";
|
|
1
2
|
import { type ObjectSchema, filterValidSchemaProperties } from "./json-schemas.js";
|
|
2
3
|
import { type TypeScriptInterface, jsonSchemaToTypeScriptInterface, serializeTypeScriptSchema } from "./typescript.js";
|
|
3
4
|
|
|
4
5
|
export const ACTOR_CONFIG_PATH = ".actor/actor.json";
|
|
5
6
|
|
|
7
|
+
export function getPathRelativeToActorConfig(path: string): string {
|
|
8
|
+
return `./${relative(dirname(ACTOR_CONFIG_PATH), path)}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
const VALID_INPUT_ROOT_KEYS = ["title", "description", "type", "schemaVersion", "properties", "required"];
|
|
7
12
|
|
|
8
13
|
const VALID_INPUT_PROPERTY_KEYS = [
|
|
@@ -65,23 +70,23 @@ export function filterValidInputSchemaProperties(schema: ObjectSchema): ObjectSc
|
|
|
65
70
|
*/
|
|
66
71
|
export function generateInputDefaultsTSFileContent(inputSchema: ObjectSchema) {
|
|
67
72
|
const defaultValues: Record<string, unknown> = {};
|
|
68
|
-
|
|
69
73
|
for (const [property, definition] of Object.entries(inputSchema.properties ?? {})) {
|
|
70
74
|
if ("default" in definition) {
|
|
71
75
|
defaultValues[property] = definition.default;
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
|
-
const tsInterfaceSchema = jsonSchemaToTypeScriptInterface(inputSchema);
|
|
75
78
|
|
|
76
|
-
const
|
|
79
|
+
const tsInterface = jsonSchemaToTypeScriptInterface(inputSchema);
|
|
80
|
+
|
|
81
|
+
const defaultInterface: TypeScriptInterface = {
|
|
77
82
|
isArray: false,
|
|
78
83
|
isRequired: true,
|
|
79
84
|
properties: {},
|
|
80
85
|
};
|
|
81
86
|
const requiredParamsWithoutDefaults: string[] = [];
|
|
82
|
-
for (const [key, schema] of Object.entries(
|
|
83
|
-
if (
|
|
84
|
-
|
|
87
|
+
for (const [key, schema] of Object.entries(tsInterface.properties)) {
|
|
88
|
+
if (key in defaultValues) {
|
|
89
|
+
defaultInterface.properties[key] = {
|
|
85
90
|
...schema,
|
|
86
91
|
isRequired: true,
|
|
87
92
|
};
|
|
@@ -90,7 +95,7 @@ export function generateInputDefaultsTSFileContent(inputSchema: ObjectSchema) {
|
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
const areThereDefaults = Object.keys(
|
|
98
|
+
const areThereDefaults = Object.keys(defaultInterface.properties).length > 0;
|
|
94
99
|
|
|
95
100
|
return `\
|
|
96
101
|
import { Actor } from "apify";
|
|
@@ -99,7 +104,7 @@ import type { Input } from "./input.js";
|
|
|
99
104
|
${
|
|
100
105
|
areThereDefaults
|
|
101
106
|
? `\
|
|
102
|
-
interface DefaultInputs ${serializeTypeScriptSchema(
|
|
107
|
+
interface DefaultInputs ${serializeTypeScriptSchema(defaultInterface)};
|
|
103
108
|
|
|
104
109
|
export type InputWithDefaults = Input & DefaultInputs;
|
|
105
110
|
|
|
@@ -116,15 +121,14 @@ export function getInputWithDefaultValues(input?: Input | null): InputWithDefaul
|
|
|
116
121
|
if (Actor.isAtHome()) {
|
|
117
122
|
// The platform is supposed to fill in the default values
|
|
118
123
|
return input as InputWithDefaults;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
? `\
|
|
124
|
+
}${
|
|
125
|
+
requiredParamsWithoutDefaults.length > 0
|
|
126
|
+
? `
|
|
123
127
|
if (!input) {
|
|
124
128
|
throw new Error(\`Input is required, because the following fields are required: $\{REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT.join(", ")\}\`);
|
|
125
129
|
}`
|
|
126
|
-
|
|
127
|
-
}
|
|
130
|
+
: ""
|
|
131
|
+
}
|
|
128
132
|
${
|
|
129
133
|
areThereDefaults
|
|
130
134
|
? `\
|
|
@@ -131,7 +131,7 @@ describe("The apify-schema-tools cli", () => {
|
|
|
131
131
|
|
|
132
132
|
// Check that actor config was updated
|
|
133
133
|
const updatedActorConfig = JSON.parse(readFileSync(actorConfigPath, "utf8"));
|
|
134
|
-
expect(updatedActorConfig.storages?.dataset).toBe("
|
|
134
|
+
expect(updatedActorConfig.storages?.dataset).toBe("./dataset_schema.json");
|
|
135
135
|
|
|
136
136
|
// Check that dataset schema file was created
|
|
137
137
|
expect(existsSync(DATASET_SCHEMA_PATH)).toBe(true);
|
package/test/apify.test.ts
CHANGED
|
@@ -23,6 +23,7 @@ describe("Apify utilities", () => {
|
|
|
23
23
|
import type { Input } from "./input.js";
|
|
24
24
|
|
|
25
25
|
interface DefaultInputs {
|
|
26
|
+
name: string;
|
|
26
27
|
age: number;
|
|
27
28
|
};
|
|
28
29
|
|
|
@@ -40,7 +41,6 @@ export function getInputWithDefaultValues(input?: Input | null): InputWithDefaul
|
|
|
40
41
|
// The platform is supposed to fill in the default values
|
|
41
42
|
return input as InputWithDefaults;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
44
|
return {
|
|
45
45
|
...DEFAULT_INPUT_VALUES,
|
|
46
46
|
...(input ?? {} as Input),
|
|
@@ -54,7 +54,7 @@ export function getInputWithDefaultValues(input?: Input | null): InputWithDefaul
|
|
|
54
54
|
const inputSchema: ObjectSchema = {
|
|
55
55
|
type: "object",
|
|
56
56
|
properties: {
|
|
57
|
-
name: { type: "string"
|
|
57
|
+
name: { type: "string" },
|
|
58
58
|
age: { type: "number" },
|
|
59
59
|
email: { type: "string" },
|
|
60
60
|
},
|
|
@@ -71,14 +71,18 @@ export type InputWithDefaults = Input;
|
|
|
71
71
|
|
|
72
72
|
export const DEFAULT_INPUT_VALUES: Record<string, unknown> = {};
|
|
73
73
|
|
|
74
|
-
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = [
|
|
74
|
+
export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = [
|
|
75
|
+
"name"
|
|
76
|
+
];
|
|
75
77
|
|
|
76
78
|
export function getInputWithDefaultValues(input?: Input | null): InputWithDefaults {
|
|
77
79
|
if (Actor.isAtHome()) {
|
|
78
80
|
// The platform is supposed to fill in the default values
|
|
79
81
|
return input as InputWithDefaults;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
if (!input) {
|
|
84
|
+
throw new Error(\`Input is required, because the following fields are required: $\{REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT.join(", ")\}\`);
|
|
85
|
+
}
|
|
82
86
|
return input ?? {} as Input;
|
|
83
87
|
}
|
|
84
88
|
`,
|