apify-schema-tools 2.0.1

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.
Files changed (83) hide show
  1. package/.cspell/custom-dictionary.txt +4 -0
  2. package/.husky/pre-commit +33 -0
  3. package/.node-version +1 -0
  4. package/CHANGELOG.md +88 -0
  5. package/LICENSE +201 -0
  6. package/README.md +312 -0
  7. package/biome.json +31 -0
  8. package/dist/apify-schema-tools.d.ts +3 -0
  9. package/dist/apify-schema-tools.d.ts.map +1 -0
  10. package/dist/apify-schema-tools.js +197 -0
  11. package/dist/apify-schema-tools.js.map +1 -0
  12. package/dist/apify.d.ts +11 -0
  13. package/dist/apify.d.ts.map +1 -0
  14. package/dist/apify.js +107 -0
  15. package/dist/apify.js.map +1 -0
  16. package/dist/configuration.d.ts +43 -0
  17. package/dist/configuration.d.ts.map +1 -0
  18. package/dist/configuration.js +87 -0
  19. package/dist/configuration.js.map +1 -0
  20. package/dist/filesystem.d.ts +8 -0
  21. package/dist/filesystem.d.ts.map +1 -0
  22. package/dist/filesystem.js +16 -0
  23. package/dist/filesystem.js.map +1 -0
  24. package/dist/json-schemas.d.ts +34 -0
  25. package/dist/json-schemas.d.ts.map +1 -0
  26. package/dist/json-schemas.js +185 -0
  27. package/dist/json-schemas.js.map +1 -0
  28. package/dist/typescript.d.ts +26 -0
  29. package/dist/typescript.d.ts.map +1 -0
  30. package/dist/typescript.js +316 -0
  31. package/dist/typescript.js.map +1 -0
  32. package/package.json +60 -0
  33. package/samples/all-defaults/.actor/actor.json +15 -0
  34. package/samples/all-defaults/.actor/dataset_schema.json +32 -0
  35. package/samples/all-defaults/.actor/input_schema.json +53 -0
  36. package/samples/all-defaults/src/generated/dataset.ts +24 -0
  37. package/samples/all-defaults/src/generated/input-utils.ts +60 -0
  38. package/samples/all-defaults/src/generated/input.ts +42 -0
  39. package/samples/all-defaults/src-schemas/dataset-item.json +28 -0
  40. package/samples/all-defaults/src-schemas/input.json +73 -0
  41. package/samples/deep-merged-schemas/.actor/actor.json +15 -0
  42. package/samples/deep-merged-schemas/.actor/dataset_schema.json +37 -0
  43. package/samples/deep-merged-schemas/.actor/input_schema.json +61 -0
  44. package/samples/deep-merged-schemas/add-schemas/dataset-item.json +10 -0
  45. package/samples/deep-merged-schemas/add-schemas/input.json +33 -0
  46. package/samples/deep-merged-schemas/src/generated/dataset.ts +28 -0
  47. package/samples/deep-merged-schemas/src/generated/input-utils.ts +66 -0
  48. package/samples/deep-merged-schemas/src/generated/input.ts +47 -0
  49. package/samples/deep-merged-schemas/src-schemas/dataset-item.json +28 -0
  50. package/samples/deep-merged-schemas/src-schemas/input.json +73 -0
  51. package/samples/merged-schemas/.actor/actor.json +15 -0
  52. package/samples/merged-schemas/.actor/dataset_schema.json +37 -0
  53. package/samples/merged-schemas/.actor/input_schema.json +58 -0
  54. package/samples/merged-schemas/add-schemas/dataset-item.json +10 -0
  55. package/samples/merged-schemas/add-schemas/input.json +33 -0
  56. package/samples/merged-schemas/src/generated/dataset.ts +28 -0
  57. package/samples/merged-schemas/src/generated/input-utils.ts +57 -0
  58. package/samples/merged-schemas/src/generated/input.ts +42 -0
  59. package/samples/merged-schemas/src-schemas/dataset-item.json +28 -0
  60. package/samples/merged-schemas/src-schemas/input.json +73 -0
  61. package/samples/package-json-config/.actor/actor.json +15 -0
  62. package/samples/package-json-config/.actor/dataset_schema.json +32 -0
  63. package/samples/package-json-config/.actor/input_schema.json +53 -0
  64. package/samples/package-json-config/custom-src-schemas/dataset-item.json +28 -0
  65. package/samples/package-json-config/custom-src-schemas/input.json +73 -0
  66. package/samples/package-json-config/package.json +11 -0
  67. package/samples/package-json-config/src/custom-generated/dataset.ts +24 -0
  68. package/samples/package-json-config/src/custom-generated/input-utils.ts +60 -0
  69. package/samples/package-json-config/src/custom-generated/input.ts +42 -0
  70. package/src/apify-schema-tools.ts +302 -0
  71. package/src/apify.ts +124 -0
  72. package/src/configuration.ts +110 -0
  73. package/src/filesystem.ts +18 -0
  74. package/src/json-schemas.ts +252 -0
  75. package/src/typescript.ts +381 -0
  76. package/test/apify-schema-tools.test.ts +2064 -0
  77. package/test/apify.test.ts +28 -0
  78. package/test/common.ts +19 -0
  79. package/test/configuration.test.ts +642 -0
  80. package/test/json-schemas.test.ts +587 -0
  81. package/test/typescript.test.ts +817 -0
  82. package/tsconfig.json +18 -0
  83. package/update-samples.sh +27 -0
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { ArgumentDefaultsHelpFormatter, ArgumentParser } from "argparse";
5
+ import { ACTOR_CONFIG_PATH, DATASET_SCHEMA_FIELD, filterValidInputSchemaProperties, generateInputDefaultsTSFileContent, } from "./apify.js";
6
+ import { addCommonCLIArgs, parseConfigurationFromFileOrDefault, writeConfigurationToPackageJson, } from "./configuration.js";
7
+ import { readFile, writeFile } from "./filesystem.js";
8
+ import { compareSchemas, mergeObjectSchemas, readJsonSchema, readJsonSchemaField, writeJsonSchema, writeSchemaToField, } from "./json-schemas.js";
9
+ import { compareTypescriptInterfaces, jsonSchemaToTypeScriptInterface, parseTypeScriptInterface, removeTypeScriptHeader, serializeTypeScriptInterface, writeTypeScriptFile, } from "./typescript.js";
10
+ const configuration = parseConfigurationFromFileOrDefault();
11
+ const rootParser = new ArgumentParser({
12
+ description: "Apify Schema Tools - Generate JSON schemas and TypeScript files for Actor input and output dataset.",
13
+ formatter_class: ArgumentDefaultsHelpFormatter,
14
+ });
15
+ // Create subparsers for commands, and define arguments shared by multiple commands
16
+ const subparsers = rootParser.add_subparsers();
17
+ const DEEP_MERGE_PARAM = "--deep-merge";
18
+ const DEEP_MERGE_OPTIONS = {
19
+ help: "whether to deep merge additional schemas into the main schema",
20
+ action: "store_true",
21
+ default: false,
22
+ };
23
+ const initParser = subparsers.add_parser("init", {
24
+ help: "Initialize the Apify Schema Tools project with default settings.",
25
+ formatter_class: ArgumentDefaultsHelpFormatter,
26
+ });
27
+ addCommonCLIArgs(initParser, configuration);
28
+ initParser.add_argument("--no-config-file", {
29
+ help: "do not create a configuration file in package.json",
30
+ action: "store_true",
31
+ default: false,
32
+ });
33
+ initParser.add_argument("--only-config-file", {
34
+ help: "create only the configuration file in package.json, without initializing schemas",
35
+ action: "store_true",
36
+ default: false,
37
+ });
38
+ function init(args) {
39
+ if (args.only_config_file && args.no_config_file) {
40
+ throw new Error("The options --only-config-file and --no-config-file were defined together: doing nothing.");
41
+ }
42
+ console.log("Initializing Apify Schema Tools in the current project...");
43
+ if (!args.no_config_file) {
44
+ writeConfigurationToPackageJson(args);
45
+ console.log("Configuration written to package.json");
46
+ }
47
+ if (args.only_config_file) {
48
+ console.log("Only configuration file created, skipping schema initialization.");
49
+ return;
50
+ }
51
+ if (args.input.includes("input")) {
52
+ if (!existsSync(args.input_schema)) {
53
+ throw new Error("The current Actor does not have an input schema.");
54
+ }
55
+ const inputSchema = readJsonSchema(args.input_schema);
56
+ writeJsonSchema(args.src_input, inputSchema);
57
+ console.log(`Input schema initialized at ${args.src_input}`);
58
+ if (args.add_input) {
59
+ writeJsonSchema(args.add_input, { type: "object", properties: {} });
60
+ console.log(`Additional input schema initialized at ${args.add_input}`);
61
+ }
62
+ }
63
+ if (args.input.includes("dataset")) {
64
+ if (!existsSync(ACTOR_CONFIG_PATH)) {
65
+ throw new Error(`The current Actor does not have an ${ACTOR_CONFIG_PATH} configuration file.`);
66
+ }
67
+ const actorConfig = JSON.parse(readFile(ACTOR_CONFIG_PATH));
68
+ if (actorConfig.storages?.dataset !== args.dataset_schema) {
69
+ writeFile(ACTOR_CONFIG_PATH, JSON.stringify({ ...actorConfig, storages: { ...actorConfig.storages, dataset: args.dataset_schema } }, null, 4));
70
+ console.log(`Updated ${ACTOR_CONFIG_PATH} to use the dataset schema at ${args.dataset_schema}`);
71
+ }
72
+ if (!existsSync(args.dataset_schema)) {
73
+ writeFile(args.dataset_schema, JSON.stringify({
74
+ actorSpecification: 1,
75
+ [DATASET_SCHEMA_FIELD]: { type: "object", properties: {} },
76
+ }, null, 4));
77
+ console.log(`Dataset schema initialized at ${args.dataset_schema}`);
78
+ }
79
+ const datasetItemSchema = readJsonSchemaField(args.dataset_schema, DATASET_SCHEMA_FIELD);
80
+ writeJsonSchema(args.src_dataset, datasetItemSchema);
81
+ }
82
+ }
83
+ initParser.set_defaults({ func: init });
84
+ const syncParser = subparsers.add_parser("sync", {
85
+ help: "Generate JSON schemas and TypeScript files from the source schemas.",
86
+ formatter_class: ArgumentDefaultsHelpFormatter,
87
+ });
88
+ addCommonCLIArgs(syncParser, configuration);
89
+ syncParser.add_argument(DEEP_MERGE_PARAM, DEEP_MERGE_OPTIONS);
90
+ syncParser.add_argument("--include-input-utils", {
91
+ help: "include input utilities in the generated TypeScript files:" + " 'input' input and 'ts-types' output are required",
92
+ choices: ["true", "false"],
93
+ default: "true",
94
+ });
95
+ function sync(args) {
96
+ console.log("Syncing schemas...");
97
+ if (args.input.includes("input")) {
98
+ let inputSchema = readJsonSchema(args.src_input);
99
+ if (args.add_input) {
100
+ inputSchema = mergeObjectSchemas(inputSchema, readJsonSchema(args.add_input), args.deep_merge);
101
+ }
102
+ if (args.output.includes("json-schemas")) {
103
+ writeJsonSchema(args.input_schema, filterValidInputSchemaProperties(inputSchema));
104
+ }
105
+ if (args.output.includes("ts-types")) {
106
+ writeTypeScriptFile(join(args.output_ts_dir, "input.ts"), serializeTypeScriptInterface("Input", jsonSchemaToTypeScriptInterface(inputSchema)));
107
+ if (args.include_input_utils === "true") {
108
+ writeTypeScriptFile(join(args.output_ts_dir, "input-utils.ts"), generateInputDefaultsTSFileContent(inputSchema));
109
+ }
110
+ }
111
+ }
112
+ if (args.input.includes("dataset")) {
113
+ let datasetSchema = readJsonSchema(args.src_dataset);
114
+ if (args.add_dataset) {
115
+ datasetSchema = mergeObjectSchemas(datasetSchema, readJsonSchema(args.add_dataset), args.deep_merge);
116
+ }
117
+ if (args.output.includes("json-schemas")) {
118
+ writeSchemaToField(args.dataset_schema, datasetSchema, DATASET_SCHEMA_FIELD);
119
+ }
120
+ if (args.output.includes("ts-types")) {
121
+ writeTypeScriptFile(join(args.output_ts_dir, "dataset.ts"), serializeTypeScriptInterface("DatasetItem", jsonSchemaToTypeScriptInterface(datasetSchema)));
122
+ }
123
+ }
124
+ }
125
+ syncParser.set_defaults({ func: sync });
126
+ const checkParser = subparsers.add_parser("check", {
127
+ help: "Check the schemas for consistency and correctness. (WARNING: input utils will not be checked!)",
128
+ formatter_class: ArgumentDefaultsHelpFormatter,
129
+ });
130
+ addCommonCLIArgs(checkParser, configuration);
131
+ checkParser.add_argument(DEEP_MERGE_PARAM, DEEP_MERGE_OPTIONS);
132
+ checkParser.add_argument("--ignore-descriptions", {
133
+ help: "ignore the 'title' and 'description' fields during the comparison",
134
+ action: "store_true",
135
+ default: false,
136
+ });
137
+ function check(args) {
138
+ if (args.input.includes("input")) {
139
+ let sourceInputSchema = readJsonSchema(args.src_input);
140
+ if (args.add_input) {
141
+ sourceInputSchema = mergeObjectSchemas(sourceInputSchema, readJsonSchema(args.add_input), args.deep_merge);
142
+ }
143
+ const generatedInputSchema = filterValidInputSchemaProperties(sourceInputSchema);
144
+ if (args.output.includes("json-schemas")) {
145
+ const outputInputSchema = readJsonSchema(args.input_schema);
146
+ const isInputSchemaCoherent = compareSchemas(generatedInputSchema, outputInputSchema, args.ignore_descriptions);
147
+ if (!isInputSchemaCoherent) {
148
+ console.error("Input schema validation failed: the input schema does not match the source schema.");
149
+ process.exit(1);
150
+ }
151
+ }
152
+ if (args.output.includes("ts-types")) {
153
+ const inputTSContent = readFile(join(args.output_ts_dir, "input.ts"));
154
+ const inputTSInterface = parseTypeScriptInterface(removeTypeScriptHeader(inputTSContent));
155
+ const sourceInputTSInterface = jsonSchemaToTypeScriptInterface(sourceInputSchema);
156
+ const isTSInputCoherent = compareTypescriptInterfaces(sourceInputTSInterface, inputTSInterface, args.ignore_descriptions);
157
+ if (!isTSInputCoherent) {
158
+ console.error("Input TypeScript interface validation failed: the TypeScript interface does not match the source schema.");
159
+ process.exit(1);
160
+ }
161
+ }
162
+ }
163
+ if (args.input.includes("dataset")) {
164
+ let sourceDatasetSchema = readJsonSchema(args.src_dataset);
165
+ if (args.add_dataset) {
166
+ sourceDatasetSchema = mergeObjectSchemas(sourceDatasetSchema, readJsonSchema(args.add_dataset), args.deep_merge);
167
+ }
168
+ if (args.output.includes("json-schemas")) {
169
+ const outputDatasetSchema = readJsonSchemaField(args.dataset_schema, DATASET_SCHEMA_FIELD);
170
+ if (!outputDatasetSchema) {
171
+ console.error(`Dataset schema field "${DATASET_SCHEMA_FIELD}" not found in ${args.dataset_schema}.`);
172
+ process.exit(1);
173
+ }
174
+ const isDatasetSchemaCoherent = compareSchemas(sourceDatasetSchema, outputDatasetSchema, args.ignore_descriptions);
175
+ if (!isDatasetSchemaCoherent) {
176
+ console.error("Dataset schema validation failed: the dataset schema does not match the source schema.");
177
+ process.exit(1);
178
+ }
179
+ }
180
+ if (args.output.includes("ts-types")) {
181
+ const datasetTSContent = readFile(join(args.output_ts_dir, "dataset.ts"));
182
+ const datasetTSInterface = parseTypeScriptInterface(removeTypeScriptHeader(datasetTSContent));
183
+ const sourceDatasetTSInterface = jsonSchemaToTypeScriptInterface(sourceDatasetSchema);
184
+ const isTSDatasetCoherent = compareTypescriptInterfaces(sourceDatasetTSInterface, datasetTSInterface, args.ignore_descriptions);
185
+ if (!isTSDatasetCoherent) {
186
+ console.error("Dataset TypeScript interface validation failed: the TypeScript interface does not match the source schema.");
187
+ process.exit(1);
188
+ }
189
+ }
190
+ }
191
+ console.log("Check passed.");
192
+ }
193
+ checkParser.set_defaults({ func: check });
194
+ // Parse and execute
195
+ const parsedArgs = rootParser.parse_args();
196
+ parsedArgs.func(parsedArgs);
197
+ //# sourceMappingURL=apify-schema-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apify-schema-tools.js","sourceRoot":"","sources":["../src/apify-schema-tools.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE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,mBAAmB,EACnB,IAAI,CAAC,mBAAmB,CACxB,CAAC;YACF,IAAI,CAAC,uBAAuB,EAAE,CAAC;gBAC9B,OAAO,CAAC,KAAK,CAAC,wFAAwF,CAAC,CAAC;gBACxG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACjB,CAAC;QACF,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACtC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC;YAC1E,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAC9F,MAAM,wBAAwB,GAAG,+BAA+B,CAAC,mBAAmB,CAAC,CAAC;YACtF,MAAM,mBAAmB,GAAG,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"}
@@ -0,0 +1,11 @@
1
+ import { type ObjectSchema } from "./json-schemas.js";
2
+ export declare const ACTOR_CONFIG_PATH = ".actor/actor.json";
3
+ export declare function filterValidInputSchemaProperties(schema: ObjectSchema): ObjectSchema;
4
+ /**
5
+ * Generates the content of a TypeScript file that exports a function to fill
6
+ * the default values for the input schema, and the interface for the input
7
+ * with the default values filled in.
8
+ */
9
+ export declare function generateInputDefaultsTSFileContent(inputSchema: ObjectSchema): string;
10
+ export declare const DATASET_SCHEMA_FIELD = "fields";
11
+ //# sourceMappingURL=apify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apify.d.ts","sourceRoot":"","sources":["../src/apify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAA+B,MAAM,mBAAmB,CAAC;AAGnF,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AA+CrD,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAQnF;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,WAAW,EAAE,YAAY,UAwD3E;AAED,eAAO,MAAM,oBAAoB,WAAW,CAAC"}
package/dist/apify.js ADDED
@@ -0,0 +1,107 @@
1
+ import { filterValidSchemaProperties } from "./json-schemas.js";
2
+ import { jsonSchemaToTypeScriptInterface, serializeTypeScriptSchema } from "./typescript.js";
3
+ export const ACTOR_CONFIG_PATH = ".actor/actor.json";
4
+ const VALID_INPUT_ROOT_KEYS = ["title", "description", "type", "schemaVersion", "properties", "required"];
5
+ const VALID_INPUT_PROPERTY_KEYS = [
6
+ "type",
7
+ "title",
8
+ "description",
9
+ "default",
10
+ "prefill",
11
+ "example",
12
+ "sectionCaption",
13
+ "sectionDescription",
14
+ ];
15
+ const VALID_INPUT_PROPERTY_TYPES = ["string", "boolean", "integer", "object", "array"];
16
+ const VALID_INPUT_PROPERTY_KEYS_BY_TYPE = {
17
+ string: [
18
+ "editor",
19
+ "pattern",
20
+ "minLength",
21
+ "maxLength",
22
+ "enum",
23
+ "enumTitles",
24
+ "nullable",
25
+ "isSecret",
26
+ "dateType",
27
+ "resourceType",
28
+ ],
29
+ boolean: ["editor", "groupCaption", "groupDescription", "nullable"],
30
+ integer: ["editor", "maximum", "minimum", "unit", "nullable"],
31
+ object: ["editor", "patternKey", "patternValue", "maxProperties", "minProperties", "nullable"],
32
+ array: [
33
+ "editor",
34
+ "placeholderKey",
35
+ "placeholderValue",
36
+ "patternKey",
37
+ "patternValue",
38
+ "maxItems",
39
+ "minItems",
40
+ "uniqueItems",
41
+ "nullable",
42
+ "resourceType",
43
+ ],
44
+ };
45
+ export function filterValidInputSchemaProperties(schema) {
46
+ return filterValidSchemaProperties(schema, VALID_INPUT_ROOT_KEYS, VALID_INPUT_PROPERTY_KEYS, VALID_INPUT_PROPERTY_TYPES, VALID_INPUT_PROPERTY_KEYS_BY_TYPE);
47
+ }
48
+ /**
49
+ * Generates the content of a TypeScript file that exports a function to fill
50
+ * the default values for the input schema, and the interface for the input
51
+ * with the default values filled in.
52
+ */
53
+ export function generateInputDefaultsTSFileContent(inputSchema) {
54
+ const defaultValues = {};
55
+ for (const [property, definition] of Object.entries(inputSchema.properties ?? {})) {
56
+ if ("default" in definition) {
57
+ defaultValues[property] = definition.default;
58
+ }
59
+ }
60
+ const tsInterfaceSchema = jsonSchemaToTypeScriptInterface(inputSchema);
61
+ const optionalParamsWithDefaults = {
62
+ isArray: false,
63
+ isRequired: true,
64
+ properties: {},
65
+ };
66
+ const requiredParamsWithoutDefaults = [];
67
+ for (const [key, schema] of Object.entries(tsInterfaceSchema.properties)) {
68
+ if (!schema.isRequired && key in defaultValues) {
69
+ optionalParamsWithDefaults.properties[key] = {
70
+ ...schema,
71
+ isRequired: true,
72
+ };
73
+ }
74
+ else if (schema.isRequired && !(key in defaultValues)) {
75
+ requiredParamsWithoutDefaults.push(key);
76
+ }
77
+ }
78
+ return `\
79
+ import { Actor } from "apify";
80
+ import type { Input } from "./input.js";
81
+
82
+ export const DEFAULT_INPUT_VALUES = ${JSON.stringify(defaultValues, null, "\t")};
83
+
84
+ export const REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT = ${JSON.stringify(requiredParamsWithoutDefaults, null, "\t")};
85
+
86
+ export type InputWithDefaults = Input & ${serializeTypeScriptSchema(optionalParamsWithDefaults)}
87
+
88
+ export function getInputWithDefaultValues(input?: Input | null): InputWithDefaults {
89
+ if (Actor.isAtHome()) {
90
+ // The platform is supposed to fill in the default values
91
+ return input as InputWithDefaults;
92
+ }
93
+ ${requiredParamsWithoutDefaults.length > 0
94
+ ? `\
95
+ if (!input) {
96
+ throw new Error(\`Input is required, because the following fields are required: $\{REQUIRED_INPUT_FIELDS_WITHOUT_DEFAULT.join(", ")\}\`);
97
+ }`
98
+ : ""}
99
+ return {
100
+ ...DEFAULT_INPUT_VALUES,
101
+ ...(input ?? {} as Input),
102
+ };
103
+ }
104
+ `;
105
+ }
106
+ export const DATASET_SCHEMA_FIELD = "fields";
107
+ //# sourceMappingURL=apify.js.map
@@ -0,0 +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;IACT,SAAS;IACT,gBAAgB;IAChB,oBAAoB;CACpB,CAAC;AAEF,MAAM,0BAA0B,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAEvF,MAAM,iCAAiC,GAA6B;IACnE,MAAM,EAAE;QACP,QAAQ;QACR,SAAS;QACT,WAAW;QACX,WAAW;QACX,MAAM;QACN,YAAY;QACZ,UAAU;QACV,UAAU;QACV,UAAU;QACV,cAAc;KACd;IACD,OAAO,EAA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,CAAC,MAAM,CAAC,UAAU,IAAI,GAAG,IAAI,aAAa,EAAE,CAAC;YAChD,0BAA0B,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG;gBAC5C,GAAG,MAAM;gBACT,UAAU,EAAE,IAAI;aAChB,CAAC;QACH,CAAC;aAAM,IAAI,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC;YACzD,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC;IACF,CAAC;IAED,OAAO;;;;sCAI8B,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC;;uDAExB,IAAI,CAAC,SAAS,CAAC,6BAA6B,EAAE,IAAI,EAAE,IAAI,CAAC;;0CAEtE,yBAAyB,CAAC,0BAA0B,CAAC;;;;;;;EAQ9F,6BAA6B,CAAC,MAAM,GAAG,CAAC;QACvC,CAAC,CAAC;;;GAGD;QACD,CAAC,CAAC,EACJ;;;;;;CAMC,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { ArgumentParser } from "argparse";
2
+ import * as zod from "zod/v4";
3
+ declare const INPUTS: readonly ["input", "dataset"];
4
+ declare const OUTPUTS: readonly ["json-schemas", "ts-types"];
5
+ type Input = (typeof INPUTS)[number];
6
+ type Output = (typeof OUTPUTS)[number];
7
+ export interface CommonCLIArgs {
8
+ input: Input[];
9
+ output: Output[];
10
+ src_input: string;
11
+ src_dataset: string;
12
+ add_input?: string;
13
+ add_dataset?: string;
14
+ input_schema: string;
15
+ dataset_schema: string;
16
+ output_ts_dir: string;
17
+ }
18
+ export declare const Configuration: zod.ZodObject<{
19
+ input: zod.ZodDefault<zod.ZodArray<zod.ZodEnum<{
20
+ input: "input";
21
+ dataset: "dataset";
22
+ }>>>;
23
+ output: zod.ZodDefault<zod.ZodArray<zod.ZodEnum<{
24
+ "json-schemas": "json-schemas";
25
+ "ts-types": "ts-types";
26
+ }>>>;
27
+ srcInput: zod.ZodDefault<zod.ZodString>;
28
+ srcDataset: zod.ZodDefault<zod.ZodString>;
29
+ addInput: zod.ZodOptional<zod.ZodString>;
30
+ addDataset: zod.ZodOptional<zod.ZodString>;
31
+ inputSchema: zod.ZodDefault<zod.ZodString>;
32
+ datasetSchema: zod.ZodDefault<zod.ZodString>;
33
+ outputTSDir: zod.ZodDefault<zod.ZodString>;
34
+ }, zod.z.core.$strip>;
35
+ export declare function parseConfigurationFromFileOrDefault(): zod.infer<typeof Configuration>;
36
+ export declare function writeConfigurationToPackageJson(args: CommonCLIArgs): void;
37
+ /**
38
+ * This function will set as default values the configuration from package.json, or the default one.
39
+ * In this way, the CLI arguments can override the configuration.
40
+ */
41
+ export declare function addCommonCLIArgs(parser: ArgumentParser, configuration: zod.infer<typeof Configuration>): void;
42
+ export {};
43
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,GAAG,MAAM,QAAQ,CAAC;AAG9B,QAAA,MAAM,MAAM,+BAAgC,CAAC;AAC7C,QAAA,MAAM,OAAO,uCAAwC,CAAC;AAEtD,KAAK,KAAK,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AACrC,KAAK,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvC,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;qBAUxB,CAAC;AAEH,wBAAgB,mCAAmC,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAIrF;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAkBzE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAAG,IAAI,CA4C7G"}
@@ -0,0 +1,87 @@
1
+ import { existsSync } from "node:fs";
2
+ import * as zod from "zod/v4";
3
+ import { readFile, writeFile } from "./filesystem.js";
4
+ const INPUTS = ["input", "dataset"];
5
+ const OUTPUTS = ["json-schemas", "ts-types"];
6
+ export const Configuration = zod.object({
7
+ input: zod.array(zod.enum(INPUTS)).default([...INPUTS]),
8
+ output: zod.array(zod.enum(OUTPUTS)).default([...OUTPUTS]),
9
+ srcInput: zod.string().default("src-schemas/input.json"),
10
+ srcDataset: zod.string().default("src-schemas/dataset-item.json"),
11
+ addInput: zod.string().optional(),
12
+ addDataset: zod.string().optional(),
13
+ inputSchema: zod.string().default(".actor/input_schema.json"),
14
+ datasetSchema: zod.string().default(".actor/dataset_schema.json"),
15
+ outputTSDir: zod.string().default("src/generated"),
16
+ });
17
+ export function parseConfigurationFromFileOrDefault() {
18
+ const packageJsonContent = existsSync("package.json") ? readFile("package.json") : undefined;
19
+ const rawConfig = packageJsonContent ? (JSON.parse(packageJsonContent)["apify-schema-tools"] ?? {}) : {};
20
+ return Configuration.parse(rawConfig);
21
+ }
22
+ export function writeConfigurationToPackageJson(args) {
23
+ if (!existsSync("package.json")) {
24
+ throw new Error("package.json does not exist. Please run this command in the root of your project.");
25
+ }
26
+ const packageJsonContent = readFile("package.json");
27
+ const packageJson = JSON.parse(packageJsonContent);
28
+ packageJson["apify-schema-tools"] = {
29
+ input: args.input,
30
+ output: args.output,
31
+ srcInput: args.src_input,
32
+ srcDataset: args.src_dataset,
33
+ addInput: args.add_input,
34
+ addDataset: args.add_dataset,
35
+ inputSchema: args.input_schema,
36
+ datasetSchema: args.dataset_schema,
37
+ outputTSDir: args.output_ts_dir,
38
+ };
39
+ writeFile("package.json", JSON.stringify(packageJson, null, 2));
40
+ }
41
+ /**
42
+ * This function will set as default values the configuration from package.json, or the default one.
43
+ * In this way, the CLI arguments can override the configuration.
44
+ */
45
+ export function addCommonCLIArgs(parser, configuration) {
46
+ parser.add_argument("-i", "--input", {
47
+ help: "specify which sources to use for generation",
48
+ choices: [...INPUTS],
49
+ default: configuration.input,
50
+ nargs: "*",
51
+ });
52
+ parser.add_argument("-o", "--output", {
53
+ help: "specify what to generate",
54
+ choices: [...OUTPUTS],
55
+ default: configuration.output,
56
+ nargs: "*",
57
+ });
58
+ parser.add_argument("--src-input", {
59
+ help: "path to the input schema source file",
60
+ default: configuration.srcInput,
61
+ });
62
+ parser.add_argument("--src-dataset", {
63
+ help: "path to the dataset schema source file",
64
+ default: configuration.srcDataset,
65
+ });
66
+ parser.add_argument("--add-input", {
67
+ help: "path to an additional schema to merge into the input schema",
68
+ default: configuration.addInput,
69
+ });
70
+ parser.add_argument("--add-dataset", {
71
+ help: "path to an additional schema to merge into the dataset schema",
72
+ default: configuration.addDataset,
73
+ });
74
+ parser.add_argument("--input-schema", {
75
+ help: "the path of the destination input schema file",
76
+ default: configuration.inputSchema,
77
+ });
78
+ parser.add_argument("--dataset-schema", {
79
+ help: "the path of the destination dataset schema file",
80
+ default: configuration.datasetSchema,
81
+ });
82
+ parser.add_argument("--output-ts-dir", {
83
+ help: "path where to save generated TypeScript files",
84
+ default: configuration.outputTSDir,
85
+ });
86
+ }
87
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration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+ export declare function readFile(filePath: string): string;
2
+ /**
3
+ * Writes content to a file, creating the directory structure if it doesn't exist.
4
+ * @param filePath - The path to the file to write.
5
+ * @param content - The content to write to the file.
6
+ */
7
+ export declare function writeFile(filePath: string, content: string): void;
8
+ //# sourceMappingURL=filesystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../src/filesystem.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAGjE"}
@@ -0,0 +1,16 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ const DEFAULT_ENCODING = "utf-8";
4
+ export function readFile(filePath) {
5
+ return readFileSync(filePath, DEFAULT_ENCODING);
6
+ }
7
+ /**
8
+ * Writes content to a file, creating the directory structure if it doesn't exist.
9
+ * @param filePath - The path to the file to write.
10
+ * @param content - The content to write to the file.
11
+ */
12
+ export function writeFile(filePath, content) {
13
+ mkdirSync(dirname(filePath), { recursive: true });
14
+ writeFileSync(filePath, content, DEFAULT_ENCODING);
15
+ }
16
+ //# sourceMappingURL=filesystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.js","sourceRoot":"","sources":["../src/filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,gBAAgB,GAAmB,OAAO,CAAC;AAEjD,MAAM,UAAU,QAAQ,CAAC,QAAgB;IACxC,OAAO,YAAY,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,OAAe;IAC1D,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { JSONSchema4 } from "json-schema";
2
+ type SchemaProperty = JSONSchema4 & {
3
+ position?: number;
4
+ };
5
+ export interface ArraySchema extends JSONSchema4 {
6
+ type: "array";
7
+ }
8
+ export declare function isArraySchema(schema: JSONSchema4): schema is ArraySchema;
9
+ export interface ObjectSchema extends JSONSchema4 {
10
+ type: "object";
11
+ properties?: Record<string, SchemaProperty>;
12
+ required?: string[];
13
+ }
14
+ export declare function isObjectSchema(schema: JSONSchema4): schema is ObjectSchema;
15
+ /**
16
+ * Schemas are expected to be of type object at the root level.
17
+ */
18
+ export declare function readJsonSchema(filePath: string): ObjectSchema;
19
+ /**
20
+ * Schemas are expected to be of type object at the root level.
21
+ */
22
+ export declare function writeJsonSchema(filePath: string, schema: ObjectSchema): void;
23
+ export declare function readJsonSchemaField(filePath: string, fieldName: string): ObjectSchema;
24
+ export declare function writeSchemaToField(filePath: string, schema: ObjectSchema, fieldName: string): void;
25
+ export declare function filterValidSchemaProperties(schema: ObjectSchema, validRootKeys: string[], validPropertyKeys: string[], validPropertyTypes: string[], validPropertyKeysByType: Record<string, string[]>): ObjectSchema;
26
+ export declare function mergeObjectSchemas(baseSchema: ObjectSchema, additionalSchema: ObjectSchema, deep?: boolean): ObjectSchema;
27
+ export declare function compareSchemas(a: ObjectSchema, b: ObjectSchema, ignoreDescriptions?: boolean): boolean;
28
+ /**
29
+ * Compare descriptions of source and output schemas.
30
+ * Ignore properties that were removed from the source schema, or that were added to the source schema.
31
+ */
32
+ export declare function compareDescriptions(sourceSchema: JSONSchema4, outputSchema: JSONSchema4): boolean;
33
+ export {};
34
+ //# sourceMappingURL=json-schemas.d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