apify-schema-tools 3.0.0 → 3.2.0

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 (148) hide show
  1. package/.cspell/custom-dictionary.txt +1 -0
  2. package/.node-version +1 -1
  3. package/CHANGELOG.md +13 -1
  4. package/biome.json +24 -18
  5. package/check-samples.sh +4 -0
  6. package/dist/apify-schema-tools.js +16 -21
  7. package/dist/apify-schema-tools.js.map +1 -1
  8. package/dist/apify.d.ts +1 -1
  9. package/dist/apify.d.ts.map +1 -1
  10. package/dist/apify.js +22 -8
  11. package/dist/apify.js.map +1 -1
  12. package/dist/cli/check.d.ts +5 -0
  13. package/dist/cli/check.d.ts.map +1 -0
  14. package/dist/cli/check.js +86 -0
  15. package/dist/cli/check.js.map +1 -0
  16. package/dist/cli/init.d.ts +5 -0
  17. package/dist/cli/init.d.ts.map +1 -0
  18. package/dist/cli/init.js +92 -0
  19. package/dist/cli/init.js.map +1 -0
  20. package/dist/cli/sync.d.ts +5 -0
  21. package/dist/cli/sync.d.ts.map +1 -0
  22. package/dist/cli/sync.js +112 -0
  23. package/dist/cli/sync.js.map +1 -0
  24. package/dist/configuration.d.ts +16 -5
  25. package/dist/configuration.d.ts.map +1 -1
  26. package/dist/configuration.js +19 -7
  27. package/dist/configuration.js.map +1 -1
  28. package/dist/json-schema-conflicts.js +3 -3
  29. package/dist/json-schema-conflicts.js.map +1 -1
  30. package/dist/json-schemas.d.ts +1 -1
  31. package/dist/json-schemas.d.ts.map +1 -1
  32. package/dist/json-schemas.js +1 -1
  33. package/dist/json-schemas.js.map +1 -1
  34. package/dist/main.d.ts +4 -0
  35. package/dist/main.d.ts.map +1 -0
  36. package/dist/main.js +19 -0
  37. package/dist/main.js.map +1 -0
  38. package/dist/middle-schema/compare-schemas.d.ts +3 -0
  39. package/dist/middle-schema/compare-schemas.d.ts.map +1 -0
  40. package/dist/middle-schema/compare-schemas.js +90 -0
  41. package/dist/middle-schema/compare-schemas.js.map +1 -0
  42. package/dist/middle-schema/generate-typescript.d.ts +7 -0
  43. package/dist/middle-schema/generate-typescript.d.ts.map +1 -0
  44. package/dist/middle-schema/generate-typescript.js +70 -0
  45. package/dist/middle-schema/generate-typescript.js.map +1 -0
  46. package/dist/middle-schema/parse-json-schema.d.ts +4 -0
  47. package/dist/middle-schema/parse-json-schema.d.ts.map +1 -0
  48. package/dist/middle-schema/parse-json-schema.js +65 -0
  49. package/dist/middle-schema/parse-json-schema.js.map +1 -0
  50. package/dist/middle-schema/parse-typescript.d.ts +4 -0
  51. package/dist/middle-schema/parse-typescript.d.ts.map +1 -0
  52. package/dist/middle-schema/parse-typescript.js +199 -0
  53. package/dist/middle-schema/parse-typescript.js.map +1 -0
  54. package/dist/middle-schema/schema-types.d.ts +24 -0
  55. package/dist/middle-schema/schema-types.d.ts.map +1 -0
  56. package/dist/middle-schema/schema-types.js +14 -0
  57. package/dist/middle-schema/schema-types.js.map +1 -0
  58. package/dist/middle-schema/schema.d.ts +24 -0
  59. package/dist/middle-schema/schema.d.ts.map +1 -0
  60. package/dist/middle-schema/schema.js +14 -0
  61. package/dist/middle-schema/schema.js.map +1 -0
  62. package/dist/schema/entities/abstract-entity.d.ts +5 -0
  63. package/dist/schema/entities/abstract-entity.d.ts.map +1 -0
  64. package/dist/schema/entities/abstract-entity.js +3 -0
  65. package/dist/schema/entities/abstract-entity.js.map +1 -0
  66. package/dist/schema/entities/primitive-union.d.ts +12 -0
  67. package/dist/schema/entities/primitive-union.d.ts.map +1 -0
  68. package/dist/schema/entities/primitive-union.js +74 -0
  69. package/dist/schema/entities/primitive-union.js.map +1 -0
  70. package/dist/schema/entities/primitive.d.ts +15 -0
  71. package/dist/schema/entities/primitive.d.ts.map +1 -0
  72. package/dist/schema/entities/primitive.js +54 -0
  73. package/dist/schema/entities/primitive.js.map +1 -0
  74. package/dist/schema/parsers/json-schema.d.ts +4 -0
  75. package/dist/schema/parsers/json-schema.d.ts.map +1 -0
  76. package/dist/schema/parsers/json-schema.js +12 -0
  77. package/dist/schema/parsers/json-schema.js.map +1 -0
  78. package/dist/schema/parsers/typescript.d.ts +3 -0
  79. package/dist/schema/parsers/typescript.d.ts.map +1 -0
  80. package/dist/schema/parsers/typescript.js +24 -0
  81. package/dist/schema/parsers/typescript.js.map +1 -0
  82. package/dist/schemas/input.d.ts +840 -0
  83. package/dist/schemas/input.d.ts.map +1 -0
  84. package/dist/schemas/input.js +349 -0
  85. package/dist/schemas/input.js.map +1 -0
  86. package/dist/utils/filesystem.d.ts +8 -0
  87. package/dist/utils/filesystem.d.ts.map +1 -0
  88. package/dist/utils/filesystem.js +16 -0
  89. package/dist/utils/filesystem.js.map +1 -0
  90. package/dist/utils/json-schemas-interactive-conflict.d.ts +16 -0
  91. package/dist/utils/json-schemas-interactive-conflict.d.ts.map +1 -0
  92. package/dist/utils/json-schemas-interactive-conflict.js +165 -0
  93. package/dist/utils/json-schemas-interactive-conflict.js.map +1 -0
  94. package/dist/utils/json-schemas.d.ts +42 -0
  95. package/dist/utils/json-schemas.d.ts.map +1 -0
  96. package/dist/utils/json-schemas.js +162 -0
  97. package/dist/utils/json-schemas.js.map +1 -0
  98. package/dist/zod/schemas/input.d.ts +840 -0
  99. package/dist/zod/schemas/input.d.ts.map +1 -0
  100. package/dist/zod/schemas/input.js +393 -0
  101. package/dist/zod/schemas/input.js.map +1 -0
  102. package/package.json +12 -12
  103. package/samples/all-defaults/.actor/input_schema.json +32 -3
  104. package/samples/all-defaults/src-schemas/input.json +2 -1
  105. package/samples/deep-merged-schemas/.actor/input_schema.json +36 -3
  106. package/samples/merged-schemas/.actor/input_schema.json +27 -3
  107. package/samples/package-json-config/.actor/input_schema.json +32 -3
  108. package/samples/package-json-config-merged/.actor/actor.json +15 -0
  109. package/samples/package-json-config-merged/.actor/dataset_schema.json +32 -0
  110. package/samples/package-json-config-merged/.actor/input_schema.json +91 -0
  111. package/samples/package-json-config-merged/custom-add-schemas/add-input.json +21 -0
  112. package/samples/package-json-config-merged/custom-src-schemas/dataset-item.json +28 -0
  113. package/samples/package-json-config-merged/custom-src-schemas/input.json +89 -0
  114. package/samples/package-json-config-merged/package.json +19 -0
  115. package/samples/package-json-config-merged/src/custom-generated/dataset.ts +25 -0
  116. package/samples/package-json-config-merged/src/custom-generated/input-utils.ts +73 -0
  117. package/samples/package-json-config-merged/src/custom-generated/input.ts +49 -0
  118. package/src/apify.ts +24 -9
  119. package/src/cli/check.ts +114 -0
  120. package/src/cli/init.ts +125 -0
  121. package/src/cli/sync.ts +164 -0
  122. package/src/configuration.ts +27 -8
  123. package/src/main.ts +25 -0
  124. package/src/middle-schema/compare-schemas.ts +113 -0
  125. package/src/middle-schema/generate-typescript.ts +88 -0
  126. package/src/middle-schema/parse-json-schema.ts +104 -0
  127. package/src/middle-schema/parse-typescript.ts +239 -0
  128. package/src/middle-schema/schema-types.ts +40 -0
  129. package/src/{json-schema-conflicts.ts → utils/json-schemas-interactive-conflict.ts} +3 -3
  130. package/src/{json-schemas.ts → utils/json-schemas.ts} +1 -1
  131. package/test/apify.test.ts +413 -5
  132. package/test/cli/check.test.ts +1571 -0
  133. package/test/cli/init.test.ts +459 -0
  134. package/test/cli/sync.test.ts +341 -0
  135. package/test/common.ts +68 -0
  136. package/test/configuration.test.ts +59 -26
  137. package/test/middle-schema/compare-schemas.test.ts +585 -0
  138. package/test/middle-schema/generate-typescript.test.ts +191 -0
  139. package/test/middle-schema/parse-json-schema.test.ts +178 -0
  140. package/test/middle-schema/parse-typescript.test.ts +143 -0
  141. package/test/{json-schema-conflicts.test.ts → utils/json-schemas-interactive-conflict.test.ts} +3 -3
  142. package/test/{json-schemas.test.ts → utils/json-schemas.test.ts} +4 -4
  143. package/update-samples.sh +4 -0
  144. package/src/apify-schema-tools.ts +0 -431
  145. package/src/typescript.ts +0 -563
  146. package/test/apify-schema-tools.test.ts +0 -2216
  147. package/test/typescript.test.ts +0 -1079
  148. /package/src/{filesystem.ts → utils/filesystem.ts} +0 -0
@@ -0,0 +1,459 @@
1
+ import { execSync } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { afterEach, beforeAll, describe, expect, it } from "vitest";
5
+ import { ACTOR_CONFIG_PATH } from "../../src/apify.js";
6
+ import { writeFile } from "../../src/utils/filesystem.js";
7
+ import { type ObjectSchema, readJsonSchema, writeJsonSchema } from "../../src/utils/json-schemas.js";
8
+ import {
9
+ cleanupTestDirectory,
10
+ getDatasetSchemaPath,
11
+ getInputSchemaPath,
12
+ getTestDir,
13
+ setupTestDirectory,
14
+ } from "../common.js";
15
+
16
+ const EXEC_CMD = `node ${import.meta.dirname}/../../dist/apify-schema-tools.js`;
17
+
18
+ const TEST_DIR = getTestDir("init-command");
19
+ const INPUT_SCHEMA_PATH = getInputSchemaPath(TEST_DIR);
20
+ const DATASET_SCHEMA_PATH = getDatasetSchemaPath(TEST_DIR);
21
+
22
+ describe("init command", () => {
23
+ beforeAll(() => {
24
+ execSync("npm run build", { stdio: "inherit" });
25
+ });
26
+ afterEach(() => {
27
+ cleanupTestDirectory(TEST_DIR);
28
+ });
29
+
30
+ it("should initialize configuration and schemas with default values", () => {
31
+ setupTestDirectory(TEST_DIR);
32
+
33
+ // Create package.json for config writing
34
+ const packageJsonPath = join(TEST_DIR, "package.json");
35
+ writeFile(
36
+ packageJsonPath,
37
+ JSON.stringify(
38
+ {
39
+ name: "test-project",
40
+ version: "1.0.0",
41
+ },
42
+ null,
43
+ 2,
44
+ ),
45
+ );
46
+
47
+ // Create existing input schema that will be copied
48
+ const existingInputSchema: ObjectSchema = {
49
+ title: "Existing Input Schema",
50
+ type: "object",
51
+ properties: {
52
+ name: { type: "string" },
53
+ age: { type: "integer" },
54
+ },
55
+ required: ["name"],
56
+ };
57
+ writeJsonSchema(INPUT_SCHEMA_PATH, existingInputSchema);
58
+
59
+ // Create existing actor config for dataset initialization
60
+ const actorConfigPath = join(TEST_DIR, ACTOR_CONFIG_PATH);
61
+ const existingActorConfig = {
62
+ actorSpecification: 1,
63
+ name: "test-actor",
64
+ version: "1.0.0",
65
+ };
66
+ writeFile(actorConfigPath, JSON.stringify(existingActorConfig, null, 4));
67
+
68
+ // Create the src-schemas directory that the init command will use
69
+
70
+ execSync(`${EXEC_CMD} init`, {
71
+ cwd: TEST_DIR,
72
+ stdio: "inherit",
73
+ });
74
+
75
+ // Check that configuration was written to package.json
76
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
77
+ expect(packageJson["apify-schema-tools"]).toBeDefined();
78
+ expect(packageJson["apify-schema-tools"].input).toEqual(["input", "dataset"]);
79
+ expect(packageJson["apify-schema-tools"].output).toEqual(["json-schemas", "ts-types"]);
80
+
81
+ // Check that input schema was initialized
82
+ const srcInputPath = join(TEST_DIR, "src-schemas", "input.json");
83
+ expect(existsSync(srcInputPath)).toBe(true);
84
+ const initializedInputSchema = readJsonSchema(srcInputPath);
85
+ expect(initializedInputSchema).toEqual(existingInputSchema);
86
+
87
+ // Check that dataset schema was initialized
88
+ const srcDatasetPath = join(TEST_DIR, "src-schemas", "dataset-item.json");
89
+ expect(existsSync(srcDatasetPath)).toBe(true);
90
+ const initializedDatasetSchema = readJsonSchema(srcDatasetPath);
91
+ expect(initializedDatasetSchema).toEqual({ type: "object", properties: {} });
92
+
93
+ // Check that actor config was updated
94
+ const updatedActorConfig = JSON.parse(readFileSync(actorConfigPath, "utf8"));
95
+ expect(updatedActorConfig.storages?.dataset).toBe("./dataset_schema.json");
96
+
97
+ // Check that dataset schema file was created
98
+ expect(existsSync(DATASET_SCHEMA_PATH)).toBe(true);
99
+ const datasetSchemaFile = JSON.parse(readFileSync(DATASET_SCHEMA_PATH, "utf8"));
100
+ expect(datasetSchemaFile).toEqual({
101
+ actorSpecification: 1,
102
+ fields: { type: "object", properties: {} },
103
+ });
104
+ });
105
+
106
+ it("should initialize with custom options", () => {
107
+ setupTestDirectory(TEST_DIR);
108
+
109
+ const packageJsonPath = join(TEST_DIR, "package.json");
110
+ writeFile(
111
+ packageJsonPath,
112
+ JSON.stringify(
113
+ {
114
+ name: "test-project",
115
+ version: "1.0.0",
116
+ },
117
+ null,
118
+ 2,
119
+ ),
120
+ );
121
+
122
+ // Create existing input schema
123
+ const existingInputSchema: ObjectSchema = {
124
+ title: "Custom Input Schema",
125
+ type: "object",
126
+ properties: {
127
+ customField: { type: "string" },
128
+ },
129
+ required: ["customField"],
130
+ };
131
+ writeJsonSchema(INPUT_SCHEMA_PATH, existingInputSchema);
132
+
133
+ // Create existing actor config
134
+ const actorConfigPath = join(TEST_DIR, ACTOR_CONFIG_PATH);
135
+ const existingActorConfig = {
136
+ actorSpecification: 1,
137
+ name: "custom-actor",
138
+ version: "2.0.0",
139
+ };
140
+ writeFile(actorConfigPath, JSON.stringify(existingActorConfig, null, 4));
141
+
142
+ // Create the necessary directories that the init command will use
143
+
144
+ execSync(
145
+ [
146
+ `${EXEC_CMD} init`,
147
+ "-i input dataset",
148
+ "-o json-schemas ts-types",
149
+ "--src-input custom-src/custom-input.json",
150
+ "--src-dataset custom-src/custom-dataset.json",
151
+ "--output-ts-dir custom-output",
152
+ "--add-input custom-add/add-input.json",
153
+ "--add-dataset custom-add/add-dataset.json",
154
+ ].join(" "),
155
+ {
156
+ cwd: TEST_DIR,
157
+ stdio: "inherit",
158
+ },
159
+ );
160
+
161
+ // Check that configuration was written with custom values
162
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
163
+ expect(packageJson["apify-schema-tools"]).toBeDefined();
164
+ expect(packageJson["apify-schema-tools"].input).toEqual(["input", "dataset"]);
165
+ expect(packageJson["apify-schema-tools"].output).toEqual(["json-schemas", "ts-types"]);
166
+ expect(packageJson["apify-schema-tools"].srcInput).toBe("custom-src/custom-input.json");
167
+ expect(packageJson["apify-schema-tools"].srcDataset).toBe("custom-src/custom-dataset.json");
168
+ expect(packageJson["apify-schema-tools"].outputTSDir).toBe("custom-output");
169
+ expect(packageJson["apify-schema-tools"].addInput).toBe("custom-add/add-input.json");
170
+ expect(packageJson["apify-schema-tools"].addDataset).toBe("custom-add/add-dataset.json");
171
+
172
+ // Check that input schema was initialized at custom location
173
+ const customSrcInputPath = join(TEST_DIR, "custom-src", "custom-input.json");
174
+ expect(existsSync(customSrcInputPath)).toBe(true);
175
+ const initializedInputSchema = readJsonSchema(customSrcInputPath);
176
+ expect(initializedInputSchema).toEqual(existingInputSchema);
177
+
178
+ // Check that additional input schema was initialized
179
+ const customAddInputPath = join(TEST_DIR, "custom-add", "add-input.json");
180
+ expect(existsSync(customAddInputPath)).toBe(true);
181
+ const initializedAddInputSchema = readJsonSchema(customAddInputPath);
182
+ expect(initializedAddInputSchema).toEqual({ type: "object", properties: {} });
183
+ });
184
+
185
+ it("should only create config file when --only-config-file is specified", () => {
186
+ setupTestDirectory(TEST_DIR);
187
+
188
+ const packageJsonPath = join(TEST_DIR, "package.json");
189
+ writeFile(
190
+ packageJsonPath,
191
+ JSON.stringify(
192
+ {
193
+ name: "test-project",
194
+ version: "1.0.0",
195
+ },
196
+ null,
197
+ 2,
198
+ ),
199
+ );
200
+
201
+ execSync(`${EXEC_CMD} init --only-config-file`, {
202
+ cwd: TEST_DIR,
203
+ stdio: "inherit",
204
+ });
205
+
206
+ // Check that configuration was written to package.json
207
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
208
+ expect(packageJson["apify-schema-tools"]).toBeDefined();
209
+
210
+ // Check that schemas were NOT initialized
211
+ const srcInputPath = join(TEST_DIR, "src-schemas", "input.json");
212
+ const srcDatasetPath = join(TEST_DIR, "src-schemas", "dataset-item.json");
213
+ expect(existsSync(srcInputPath)).toBe(false);
214
+ expect(existsSync(srcDatasetPath)).toBe(false);
215
+ });
216
+
217
+ it("should not create config file when --no-config-file is specified", () => {
218
+ setupTestDirectory(TEST_DIR);
219
+
220
+ const packageJsonPath = join(TEST_DIR, "package.json");
221
+ writeFile(
222
+ packageJsonPath,
223
+ JSON.stringify(
224
+ {
225
+ name: "test-project",
226
+ version: "1.0.0",
227
+ },
228
+ null,
229
+ 2,
230
+ ),
231
+ );
232
+
233
+ // Create existing input schema
234
+ const existingInputSchema: ObjectSchema = {
235
+ title: "Test Input Schema",
236
+ type: "object",
237
+ properties: {
238
+ testField: { type: "string" },
239
+ },
240
+ required: ["testField"],
241
+ };
242
+ writeJsonSchema(INPUT_SCHEMA_PATH, existingInputSchema);
243
+
244
+ // Create existing actor config
245
+ const actorConfigPath = join(TEST_DIR, ACTOR_CONFIG_PATH);
246
+ const existingActorConfig = {
247
+ actorSpecification: 1,
248
+ name: "test-actor",
249
+ version: "1.0.0",
250
+ };
251
+ writeFile(actorConfigPath, JSON.stringify(existingActorConfig, null, 4));
252
+
253
+ // Create the src-schemas directory that the init command will use
254
+
255
+ execSync(`${EXEC_CMD} init --no-config-file`, {
256
+ cwd: TEST_DIR,
257
+ stdio: "inherit",
258
+ });
259
+
260
+ // Check that configuration was NOT written to package.json
261
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
262
+ expect(packageJson["apify-schema-tools"]).toBeUndefined();
263
+
264
+ // Check that schemas were initialized
265
+ const srcInputPath = join(TEST_DIR, "src-schemas", "input.json");
266
+ expect(existsSync(srcInputPath)).toBe(true);
267
+ const initializedInputSchema = readJsonSchema(srcInputPath);
268
+ expect(initializedInputSchema).toEqual(existingInputSchema);
269
+ });
270
+
271
+ it("should throw error when both --only-config-file and --no-config-file are specified", () => {
272
+ setupTestDirectory(TEST_DIR);
273
+
274
+ const packageJsonPath = join(TEST_DIR, "package.json");
275
+ writeFile(
276
+ packageJsonPath,
277
+ JSON.stringify(
278
+ {
279
+ name: "test-project",
280
+ version: "1.0.0",
281
+ },
282
+ null,
283
+ 2,
284
+ ),
285
+ );
286
+
287
+ expect(() => {
288
+ execSync(`${EXEC_CMD} init --only-config-file --no-config-file`, {
289
+ cwd: TEST_DIR,
290
+ stdio: "inherit",
291
+ });
292
+ }).toThrow();
293
+ });
294
+
295
+ it("should handle partial initialization when some files already exist", () => {
296
+ setupTestDirectory(TEST_DIR);
297
+
298
+ const packageJsonPath = join(TEST_DIR, "package.json");
299
+ writeFile(
300
+ packageJsonPath,
301
+ JSON.stringify(
302
+ {
303
+ name: "test-project",
304
+ version: "1.0.0",
305
+ },
306
+ null,
307
+ 2,
308
+ ),
309
+ );
310
+
311
+ // Create existing input schema
312
+ const existingInputSchema: ObjectSchema = {
313
+ title: "Existing Input Schema",
314
+ type: "object",
315
+ properties: {
316
+ existingField: { type: "string" },
317
+ },
318
+ required: ["existingField"],
319
+ };
320
+ writeJsonSchema(INPUT_SCHEMA_PATH, existingInputSchema);
321
+
322
+ // Create existing actor config
323
+ const actorConfigPath = join(TEST_DIR, ACTOR_CONFIG_PATH);
324
+ const existingActorConfig = {
325
+ actorSpecification: 1,
326
+ name: "existing-actor",
327
+ version: "1.0.0",
328
+ };
329
+ writeFile(actorConfigPath, JSON.stringify(existingActorConfig, null, 4));
330
+
331
+ // Pre-create one of the source schema files
332
+ const srcInputPath = join(TEST_DIR, "src-schemas", "input.json");
333
+ const preExistingSchema: ObjectSchema = {
334
+ title: "Pre-existing Schema",
335
+ type: "object",
336
+ properties: {
337
+ preExistingField: { type: "boolean" },
338
+ },
339
+ required: ["preExistingField"],
340
+ };
341
+ writeJsonSchema(srcInputPath, preExistingSchema);
342
+
343
+ execSync(`${EXEC_CMD} init`, {
344
+ cwd: TEST_DIR,
345
+ stdio: "inherit",
346
+ });
347
+
348
+ // Check that the pre-existing schema was preserved (not overwritten)
349
+ const preservedSchema = readJsonSchema(srcInputPath);
350
+ expect(preservedSchema).toEqual(preExistingSchema);
351
+
352
+ // Check that the dataset schema was still initialized
353
+ const srcDatasetPath = join(TEST_DIR, "src-schemas", "dataset-item.json");
354
+ expect(existsSync(srcDatasetPath)).toBe(true);
355
+ const initializedDatasetSchema = readJsonSchema(srcDatasetPath);
356
+ expect(initializedDatasetSchema).toEqual({ type: "object", properties: {} });
357
+ });
358
+
359
+ it("should throw error when input schema doesn't exist", () => {
360
+ setupTestDirectory(TEST_DIR);
361
+
362
+ const packageJsonPath = join(TEST_DIR, "package.json");
363
+ writeFile(
364
+ packageJsonPath,
365
+ JSON.stringify(
366
+ {
367
+ name: "test-project",
368
+ version: "1.0.0",
369
+ },
370
+ null,
371
+ 2,
372
+ ),
373
+ );
374
+
375
+ // Don't create the input schema file
376
+
377
+ expect(() => {
378
+ execSync(`${EXEC_CMD} init`, {
379
+ cwd: TEST_DIR,
380
+ stdio: "inherit",
381
+ });
382
+ }).toThrow();
383
+ });
384
+
385
+ it("should throw error when actor config doesn't exist", () => {
386
+ setupTestDirectory(TEST_DIR);
387
+
388
+ const packageJsonPath = join(TEST_DIR, "package.json");
389
+ writeFile(
390
+ packageJsonPath,
391
+ JSON.stringify(
392
+ {
393
+ name: "test-project",
394
+ version: "1.0.0",
395
+ },
396
+ null,
397
+ 2,
398
+ ),
399
+ );
400
+
401
+ // Create existing input schema
402
+ const existingInputSchema: ObjectSchema = {
403
+ title: "Test Input Schema",
404
+ type: "object",
405
+ properties: {
406
+ testField: { type: "string" },
407
+ },
408
+ required: ["testField"],
409
+ };
410
+ writeJsonSchema(INPUT_SCHEMA_PATH, existingInputSchema);
411
+
412
+ // Don't create the actor config file
413
+
414
+ expect(() => {
415
+ execSync(`${EXEC_CMD} init`, {
416
+ cwd: TEST_DIR,
417
+ stdio: "inherit",
418
+ });
419
+ }).toThrow();
420
+ });
421
+
422
+ it("should fix the dataset path in actor.json", () => {
423
+ setupTestDirectory(TEST_DIR);
424
+
425
+ const packageJsonPath = join(TEST_DIR, "package.json");
426
+ writeFile(
427
+ packageJsonPath,
428
+ JSON.stringify(
429
+ {
430
+ name: "test-project",
431
+ version: "1.0.0",
432
+ },
433
+ null,
434
+ 2,
435
+ ),
436
+ );
437
+
438
+ // Create existing actor config with incorrect dataset path
439
+ const actorConfigPath = join(TEST_DIR, ACTOR_CONFIG_PATH);
440
+ const existingActorConfig = {
441
+ actorSpecification: 1,
442
+ name: "test-actor",
443
+ version: "1.0.0",
444
+ storages: {
445
+ dataset: "wrong/dataset/path.json",
446
+ },
447
+ };
448
+ writeFile(actorConfigPath, JSON.stringify(existingActorConfig, null, 4));
449
+
450
+ execSync(`${EXEC_CMD} init --input dataset`, {
451
+ cwd: TEST_DIR,
452
+ stdio: "inherit",
453
+ });
454
+
455
+ // Check that actor config was updated with the correct dataset path
456
+ const updatedActorConfig = JSON.parse(readFileSync(actorConfigPath, "utf8"));
457
+ expect(updatedActorConfig.storages?.dataset).toBe("./dataset_schema.json");
458
+ });
459
+ });