Skip to content

Commit 6b06b9c

Browse files
authored
feat: @apify/json_schemas package (#538)
### `@apify/json_schemas` package This introduce new `@apify/json_schemas` package that would hold all our actor schemas definitions, it moves there: - `input.json` from `@apify/input_schema` - `actor.json` from worker - `dataset.json` from worker - `key_value_store.json` from worker - `output.json` from worker This allows us: - to use the schemas in other places too (e.g. API), not just in worker - publish them since this repository is public, which will allow validation and other features in IDEs How to use this package can be seen in this draft PR in worker, which removes the schemas from there and uses this new package: apify/apify-worker#1508 Schema can be imported right away as object: ``` import { actorSchema, inputSchema } from '@apify/json_schemas'; ``` Or the `ajv` validator builder function: ``` import { getActorSchemaValidator } from '@apify/json_schemas'; const validator = getActorSchemaValidator(); ``` All the schemas are `.json` files except the `actor.ts` and `actor.json`. In this case the `.json` file is generated from the `actor.ts` during the build step. We had it like this already in worker, where `ACTOR_LIMITS` are imported to the schema from `@apify/consts`. But we need public `.json` file too. But I'm not sure how to prevent devs modifying the `.json` file directly 🤔
1 parent 9e58031 commit 6b06b9c

23 files changed

+1553
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package | version
1111
`@apify/input_schema` | [![NPM version](https://img.shields.io/npm/v/@apify/input_schema.svg)](https://www.npmjs.com/package/@apify/input_schema)
1212
`@apify/input_secrets` | [![NPM version](https://img.shields.io/npm/v/@apify/input_secrets.svg)](https://www.npmjs.com/package/@apify/input_secrets)
1313
`@apify/image_proxy_client` | [![NPM version](https://img.shields.io/npm/v/@apify/image_proxy_client.svg)](https://www.npmjs.com/package/@apify/image_proxy_client)
14+
`@apify/json_schemas` | [![NPM version](https://img.shields.io/npm/v/@apify/json_schemas.svg)](https://www.npmjs.com/package/@apify/json_schemas)
1415
`@apify/log` | [![NPM version](https://img.shields.io/npm/v/@apify/log.svg)](https://www.npmjs.com/package/@apify/log)
1516
`@apify/markdown` | [![NPM version](https://img.shields.io/npm/v/@apify/markdown.svg)](https://www.npmjs.com/package/@apify/markdown)
1617
`@apify/payment_qr_codes` | [![NPM version](https://img.shields.io/npm/v/@apify/payment_qr_codes.svg)](https://www.npmjs.com/package/@apify/payment_qr_codes)

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/input_schema/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"dependencies": {
5151
"@apify/consts": "^2.44.1",
5252
"@apify/input_secrets": "^1.2.6",
53+
"@apify/json_schemas": "^0.1.0",
5354
"acorn-loose": "^8.4.0",
5455
"countries-list": "^3.0.0"
5556
},

packages/input_schema/src/input_schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { ErrorObject, Schema } from 'ajv';
22
import type Ajv from 'ajv';
33

4+
import { inputSchema as schema } from '@apify/json_schemas';
5+
46
import { m } from './intl';
5-
import schema from './schema.json';
67
import type {
78
CommonResourceFieldDefinition,
89
FieldDefinition,

packages/json_schemas/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

packages/json_schemas/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@apify/json_schemas",
3+
"version": "0.1.0",
4+
"description": "Publicly available JSON schemas for Apify platform",
5+
"main": "./dist/cjs/index.cjs",
6+
"module": "./dist/esm/index.mjs",
7+
"typings": "./dist/cjs/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": {
11+
"types": "./dist/esm/index.d.mts",
12+
"default": "./dist/esm/index.mjs"
13+
},
14+
"require": {
15+
"types": "./dist/cjs/index.d.ts",
16+
"default": "./dist/cjs/index.cjs"
17+
}
18+
}
19+
},
20+
"keywords": [
21+
"apify",
22+
"json-schema"
23+
],
24+
"author": {
25+
"name": "Apify",
26+
"email": "[email protected]",
27+
"url": "https://apify.com"
28+
},
29+
"license": "Apache-2.0",
30+
"repository": {
31+
"type": "git",
32+
"url": "git+https://github.com/apify/apify-shared-js"
33+
},
34+
"bugs": {
35+
"url": "https://github.com/apify/apify-shared-js/issues"
36+
},
37+
"homepage": "https://apify.com",
38+
"scripts": {
39+
"build": "npm run clean && npm run build-schemas && npm run compile && npm run copy",
40+
"clean": "rimraf ./dist",
41+
"compile": "tsup",
42+
"build-schemas": "ts-node scripts/build-schemas.ts",
43+
"copy": "ts-node -T ../../scripts/copy.ts"
44+
},
45+
"publishConfig": {
46+
"access": "public"
47+
},
48+
"dependencies": {
49+
"@apify/consts": "^2.44.1",
50+
"ajv": "^8.17.1"
51+
}
52+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"$id": "actor.json",
3+
"title": "JSON schema of Apify Actor actor.json file",
4+
"type": "object",
5+
"properties": {
6+
"actorSpecification": {
7+
"type": "integer",
8+
"minimum": 1,
9+
"maximum": 1
10+
},
11+
"name": {
12+
"type": "string"
13+
},
14+
"title": {
15+
"type": "string"
16+
},
17+
"description": {
18+
"type": "string"
19+
},
20+
"version": {
21+
"type": "string",
22+
"pattern": "^([0-9]+)\\.([0-9]+)(\\.[0-9]+){0,1}$"
23+
},
24+
"buildTag": {
25+
"type": "string",
26+
"default": "latest"
27+
},
28+
"environmentVariables": {
29+
"type": "object",
30+
"patternProperties": {
31+
"^": {
32+
"type": "string"
33+
}
34+
}
35+
},
36+
"dockerfile": {
37+
"type": "string",
38+
"default": "../Dockerfile"
39+
},
40+
"readme": {
41+
"type": "string",
42+
"default": "../README.md"
43+
},
44+
"minMemoryMbytes": {
45+
"type": "integer",
46+
"minimum": 128,
47+
"maximum": 32768
48+
},
49+
"maxMemoryMbytes": {
50+
"type": "integer",
51+
"minimum": 128,
52+
"maximum": 32768
53+
},
54+
"input": {
55+
"oneOf": [
56+
{
57+
"type": "string"
58+
},
59+
{
60+
"type": "object"
61+
}
62+
]
63+
},
64+
"inputSchema": {
65+
"oneOf": [
66+
{
67+
"type": "string"
68+
},
69+
{
70+
"type": "object"
71+
}
72+
]
73+
},
74+
"output": {
75+
"oneOf": [
76+
{
77+
"type": "string"
78+
},
79+
{
80+
"$ref": "output.json"
81+
}
82+
]
83+
},
84+
"outputSchema": {
85+
"oneOf": [
86+
{
87+
"type": "string"
88+
},
89+
{
90+
"$ref": "output.json"
91+
}
92+
]
93+
},
94+
"storages": {
95+
"type": "object",
96+
"properties": {
97+
"keyValueStore": {
98+
"oneOf": [
99+
{
100+
"type": "string"
101+
},
102+
{
103+
"$ref": "key_value_store.json"
104+
}
105+
]
106+
},
107+
"dataset": {
108+
"oneOf": [
109+
{
110+
"type": "string"
111+
},
112+
{
113+
"$ref": "dataset.json"
114+
}
115+
]
116+
},
117+
"requestQueue": {
118+
"type": "string"
119+
}
120+
}
121+
},
122+
"usesStandbyMode": {
123+
"type": "boolean"
124+
},
125+
"webServerSchema": {
126+
"oneOf": [
127+
{
128+
"type": "string"
129+
},
130+
{
131+
"type": "object"
132+
}
133+
]
134+
},
135+
"webServerMcpPath": {
136+
"type": "string"
137+
}
138+
},
139+
"required": [
140+
"actorSpecification",
141+
"version",
142+
"name"
143+
]
144+
}

0 commit comments

Comments
 (0)