Repository navigation
[DRAFT] In house JsonSchema to TS generator - #1382
JuanGalilea wants to merge 21 commits into
Conversation
9c2467e to
1406406
Compare
024469a to
fd4d2f0
Compare
apify-factory
left a comment
There was a problem hiding this comment.
Good work, one thing to fix before merge.
🏭 Factory review — ℹ️ not auto-approved
This change was reviewed but cannot be auto-approved: a gate failed, so the review cannot end in an approval.
| check | result |
|---|---|
| Static gates | ❌ 8/16 — author-allowed, max-files, max-lines, file-extensions, deny-globs, patch-present, no-risky-content, pr-title |
| Review findings | ❌ not clean |
| Reviewer escalation | ❌ Replaces a dependency with a new in-house compiler and breaks the public CLI and generated-file contract (removes --strict/--all-optional, renames exported types from Input interfaces to lowercase input types, changes the KVS output shape). |
Juror 1 — claude-sonnet-5-5, adversarial |
⏭️ skipped — a gate failed |
Why it was not auto-approved
Failed gates:
author-allowed: JuanGalilea: not a member of apify/product-engineeringmax-files: 54 changed files, limit 10max-lines: 22661 changed lines (+21733/-928), limit 200file-extensions: disallowed extension: .vscode/settings.json, package.json, pnpm-lock.yaml, test/setup/output-schemas/valid.json, test/local/fixtures/lib/schema-to-ts/dataset/comment-scraper.json, test/local/fixtures/lib/schema-to-ts/dataset/google-places.json, test/local/fixtures/lib/schema-to-ts/dataset/tiktok-followers-scraper.json, test/local/fixtures/lib/schema-to-ts/input/api-scraper.json, test/local/fixtures/lib/schema-to-ts/input/comment-scraper.json, test/local/fixtures/lib/schema-to-ts/input/free-amazon-product-scraper.json, test/local/fixtures/lib/schema-to-ts/input/google-places.json, test/local/fixtures/lib/schema-to-ts/kitchen-sink.json, test/local/fixtures/lib/schema-to-ts/kvstore/maps-to-polygon.json, test/tsconfig.jsondeny-globs: package.json matches **/package.json; pnpm-lock.yaml matches **/pnpm-lock.yamlpatch-present: no text diff for test/local/fixtures/lib/schema-to-ts/expected/input/google-places.ts, test/local/fixtures/lib/schema-to-ts/input/google-places.jsonno-risky-content: test/local/lib/schema-to-ts/hash.test.ts: credential-like assignment (credential-assignment); test/local/lib/schema-to-ts/parser.test.ts: credential-like assignment (credential-assignment); test/local/lib/schema-to-ts/preprocess/input.test.ts: credential-like assignment (credential-assignment)pr-title: title "[DRAFT] In house JsonSchema to TS generator" must match type(scope): message
The comments above are the review itself; this section only explains the approval decision. Push a change and request @apify-factory again to re-run it, or ask a human to review.
Reviewed 99faebbca · workflow run
| label: 'output', | ||
| outputDir, | ||
| fileName: 'output.ts', | ||
| schema: outputSchema, |
There was a problem hiding this comment.
Important: the output schema now goes to compile raw, and the parser treats a missing type as an error that becomes unknown, so an output schema without a root "type": "object" (like the valid.json fixture before this PR had to add it) now generates export type output = unknown; and still exits 0. The deleted prepareOutputSchemaForCompilation (and the dataset/KVS preparers) defaulted type to 'object', so this is a regression for Actors that worked before; the same thing happens to dataset fields and KVS jsonSchema that leave out type.
There was a problem hiding this comment.
tru that and its not required on JSONSchemas.
Added a defaulting step to normalization preprocessors of relevant schemas
c67060e to
de83ec1
Compare
apify-factory
left a comment
There was a problem hiding this comment.
Looks good, just a few notes.
🏭 Factory review — ℹ️ not auto-approved
This change was reviewed but cannot be auto-approved: a gate failed, so the review cannot end in an approval.
| check | result |
|---|---|
| Static gates | ❌ 7/16 — author-allowed, actor-allowed, max-files, max-lines, file-extensions, deny-globs, patch-present, no-risky-content, pr-title |
| Review findings | ❌ not clean |
| Reviewer escalation | ❌ This replaces a dependency, removes the public --strict/--all-optional flags, and renames the exported generated types (Input -> input), all of which break existing users' scripts and imports. |
Juror 1 — claude-sonnet-5-5, adversarial |
⏭️ skipped — a gate failed |
Why it was not auto-approved
Failed gates:
author-allowed: JuanGalilea: not a member of apify/product-engineeringactor-allowed: JuanGalilea: not a member of apify/product-engineeringmax-files: 56 changed files, limit 10max-lines: 24084 changed lines (+22445/-1639), limit 200file-extensions: disallowed extension: .vscode/settings.json, package.json, pnpm-lock.yaml, test/local/fixtures/lib/schema-to-ts/dataset/comment-scraper.json, test/local/fixtures/lib/schema-to-ts/dataset/google-places.json, test/local/fixtures/lib/schema-to-ts/dataset/tiktok-followers-scraper.json, test/local/fixtures/lib/schema-to-ts/input/api-scraper.json, test/local/fixtures/lib/schema-to-ts/input/comment-scraper.json, test/local/fixtures/lib/schema-to-ts/input/free-amazon-product-scraper.json, test/local/fixtures/lib/schema-to-ts/input/google-places.json, test/local/fixtures/lib/schema-to-ts/kitchen-sink.json, test/local/fixtures/lib/schema-to-ts/kvstore/maps-to-polygon.json, test/tsconfig.jsondeny-globs: package.json matches **/package.json; pnpm-lock.yaml matches **/pnpm-lock.yamlpatch-present: no text diff for pnpm-lock.yaml, test/local/fixtures/lib/schema-to-ts/expected/input/google-places.ts, test/local/fixtures/lib/schema-to-ts/input/google-places.jsonno-risky-content: test/local/lib/schema-to-ts/hash.test.ts: credential-like assignment (credential-assignment); test/local/lib/schema-to-ts/parser.test.ts: credential-like assignment (credential-assignment); test/local/lib/schema-to-ts/preprocess/input.test.ts: credential-like assignment (credential-assignment)pr-title: title "[DRAFT] In house JsonSchema to TS generator" must match type(scope): message
The comments above are the review itself; this section only explains the approval decision. Push a change and request @apify-factory again to re-run it, or ask a human to review.
Reviewed de83ec17e · workflow run
| // Parenthesized unconditionally: `&` binds tighter than `|` so it is already correct inside | ||
| // a union, but `{...} & Record<...> | null` is a horrible thing to read. Keeping it | ||
| // unconditional means the object never has to know what context it sits in. | ||
| if (values !== null) return `(${literal} & Record<string, ${values}>)`; |
There was a problem hiding this comment.
Note: {...} & Record<string, V> forces every declared prop to also satisfy V, so when a declared prop's type differs from additionalProperties, no object literal type-checks. For example, the kitchen-sink fixture's { known: string } & Record<string, number> rejects { known: 'x' }, which makes the supplied variant impossible to write without a cast.
|
|
||
| const inner = indent + INDENT; | ||
| const members = node.props.map((prop) => { | ||
| const optional = variant === 'supplied' ? !prop.required : !prop.required && !prop.hasDefault; |
There was a problem hiding this comment.
Note: received makes any prop with a default required, but only the input gets defaults filled in by the platform. Under --perspective user, the dataset, output, and key-value store types (outOfActor: 'received') mark defaulted fields as always present even when the Actor never wrote them.
Resolved: a newer review found nothing blocking.
base generator and tons of testing added.
actor generate-schema-typesInstall size change (
node scripts/report-install-size.mjs)AI
/show-mebelowReplaces the
json-schema-to-typescriptdependency with an in-house schema→TypeScript compiler (src/lib/schema-to-ts/, zero runtime deps — onlynode:crypto), and reframes the CLI flag surface around a single--perspective.The pipeline
Two orthogonal signals come out: diagnostics = fidelity lost (something became
unknown), notices = schema lint with no type impact. Neither feeds the hash.The
supplied/receivedsplit is the conceptual core — same IR, two renderings:Drift detection
canonical.tssorts props/enum members whileemit.tsreproduces authored order — so reordering keys in a schema never reports drift. Header is matched anywhere in the file (gm), so a user's prepended banner is free; two headers →duplicate-headererror.CLI surface change
Behavior changes worth a reviewer's attention
export interface Inputexport type input— lowercase, fromconst name = 'input'biome-ignore-all,eslint-disable,prettier-ignore-startfields→ skip with warningexport type dataset = Record<string, unknown>;prettierformatting via the libraryArray<T>, parenthesized intersections)