Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement partial schemas and switch to 2019-09 #74

Merged
merged 9 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@php -r \"file_exists( 'tests/wordpress/wp-content/db.php' ) || copy( 'tests/wordpress/wp-content/plugins/sqlite-database-integration/db.copy', 'tests/wordpress/wp-content/db.php' );\"",

"npm run validate",
"npm run build-wp-types",
"./tests/bin/build-wp-types.sh",
"npm run test-wp-types",

"rm -f tests/wordpress/wp-content/database/.ht.sqlite",
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
"license": "MIT",
"devDependencies": {
"ajv-cli": "^5.0",
"ajv-formats": "^2.0",
"json-schema-to-typescript": "^12.0",
"node-jq": "^2.3.5",
"typescript": ">=3"
"ajv-formats": "^3.0",
"json-schema-to-typescript": "^15.0",
"node-jq": "^6.0",
"typescript": ">=5"
},
"scripts": {
"version": "cd packages/wp-types && npm version $(node -p -e \"require('../../package.json').version\") && git add .",
"build-wp-types": "json2ts -i schema.json -o packages/wp-types/index.ts --style.trailingComma=all --style.useTabs && cat packages/wp-types/append.ts >> packages/wp-types/index.ts",
"test-wp-types": "tsc packages/wp-types/tests/test.ts --noEmit --strict",
"validate": "ajv compile --strict --strict-schema=false -c ajv-formats -m tests/external-schemas/hyper-schema.json -s schema.json -r \"schemas/**/*.json\""
"test-wp-types": "tsc packages/wp-types/tests/test.ts --noEmit --strict --target es2015",
"validate": "ajv compile --spec=draft2019 --strict --strict-schema=false -c ajv-formats -m tests/external-schemas/hyper-schema.json -s schema.json -r \"schemas/**/*.json\""
}
}
187 changes: 124 additions & 63 deletions packages/wp-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,82 @@ export type WP_REST_API_Font_Families = WP_REST_API_Font_Family[];
* A collection of font face objects in a REST API context.
*/
export type WP_REST_API_Font_Faces = WP_REST_API_Font_Face[];
/**
* A post object in a REST API context.
*/
export type WP_REST_API_Post = WP_REST_API_Partial_Post_Common &
WP_REST_API_Partial_Post_Author &
WP_REST_API_Partial_Post_Public &
WP_REST_API_Partial_Post_Comments &
WP_REST_API_Partial_Post_Excerpt & {
/**
* The embedded representation of relations. Only present when the '_embed' query parameter is set.
*/
_embedded?: {
/**
* The author of the post.
*/
author: unknown[];
/**
* The replies to the post (comments, pingbacks, trackbacks).
*/
replies?: unknown[];
/**
* The taxonomy terms for the post.
*/
"wp:term"?: unknown[];
/**
* The featured image post.
*/
"wp:featuredmedia"?: unknown[];
/**
* The parent post.
*/
up?: unknown[];
[k: string]: unknown;
};
[k: string]: unknown;
};
/**
* A collection of post objects in a REST API context.
*/
export type WP_REST_API_Posts = WP_REST_API_Post[];
/**
* A page object in a REST API context.
*/
export type WP_REST_API_Page = WP_REST_API_Post;
export type WP_REST_API_Page = WP_REST_API_Partial_Post_Common &
WP_REST_API_Partial_Post_Author &
WP_REST_API_Partial_Post_Public &
WP_REST_API_Partial_Post_Comments &
WP_REST_API_Partial_Post_Excerpt & {
/**
* The embedded representation of relations. Only present when the '_embed' query parameter is set.
*/
_embedded?: {
/**
* The author of the page.
*/
author: unknown[];
/**
* The replies to the page (comments, pingbacks, trackbacks).
*/
replies?: unknown[];
/**
* The taxonomy terms for the page.
*/
"wp:term"?: unknown[];
/**
* The featured image page.
*/
"wp:featuredmedia"?: unknown[];
/**
* The parent page.
*/
up?: unknown[];
[k: string]: unknown;
};
[k: string]: unknown;
};
/**
* A collection of page objects in a REST API context.
*/
Expand Down Expand Up @@ -2106,9 +2174,9 @@ export interface WP_REST_API_Font_Face {
[k: string]: unknown;
}
/**
* A post object in a REST API context.
* Common post properties
*/
export interface WP_REST_API_Post {
interface WP_REST_API_Partial_Post_Common {
/**
* The date the post was published, in the site's timezone.
*/
Expand Down Expand Up @@ -2162,14 +2230,6 @@ export interface WP_REST_API_Post {
* A password to protect access to the content and excerpt. Only present when using the 'edit' context.
*/
password?: string;
/**
* Permalink template for the post. Only present when using the 'edit' context and the post type is public.
*/
permalink_template?: string;
/**
* Slug automatically generated from the post title. Only present when using the 'edit' context and the post type is public.
*/
generated_slug?: string;
/**
* The ID for the parent of the post. Only present for hierarchical post types.
*/
Expand All @@ -2178,10 +2238,6 @@ export interface WP_REST_API_Post {
* A field used for ordering posts.
*/
menu_order?: number;
/**
* An array of the class names for the post container element.
*/
class_list: string[];
/**
* The title for the post.
*/
Expand Down Expand Up @@ -2216,47 +2272,18 @@ export interface WP_REST_API_Post {
*/
protected: boolean;
};
/**
* The ID for the author of the post.
*/
author: number;
/**
* The excerpt for the post.
*/
excerpt: {
/**
* Excerpt for the post, as it exists in the database. Only present when using the 'edit' context.
*/
raw?: string;
/**
* HTML excerpt for the post, transformed for display.
*/
rendered: string;
/**
* Whether the excerpt is protected with a password.
*/
protected: boolean;
};
/**
* The ID of the featured media for the post.
*/
featured_media?: number;
/**
* Whether or not comments are open on the post.
*/
comment_status: WP_Post_Comment_Status_Name;
/**
* Whether or not the post can be pinged.
*/
ping_status: WP_Post_Comment_Status_Name;
/**
* The format for the post.
*/
format?: WP_Post_Format_Name;
/**
* Meta fields.
*/
meta:
meta?:
| EmptyArray
| {
[k: string]: unknown;
Expand All @@ -2278,33 +2305,67 @@ export interface WP_REST_API_Post {
*/
tags?: number[];
_links: WP_REST_API_Object_Links;
}
/**
* Hello.
*/
interface WP_REST_API_Partial_Post_Author {
/**
* The embedded representation of relations. Only present when the '_embed' query parameter is set.
* The ID for the author of the post.
*/
_embedded?: {
/**
* The author of the post.
*/
author: unknown[];
/**
* The replies to the post (comments, pingbacks, trackbacks).
*/
replies?: unknown[];
author: number;
}
/**
* Properties for public post types
*/
interface WP_REST_API_Partial_Post_Public {
/**
* Permalink template for the post. Only present when using the 'edit' context and the post type is public.
*/
permalink_template?: string;
/**
* Slug automatically generated from the post title. Only present when using the 'edit' context and the post type is public.
*/
generated_slug?: string;
/**
* An array of the class names for the post container element.
*/
class_list: string[];
}
/**
* Properties for post types that support comments
*/
interface WP_REST_API_Partial_Post_Comments {
/**
* Whether or not comments are open on the post.
*/
comment_status: WP_Post_Comment_Status_Name;
/**
* Whether or not the post can be pinged.
*/
ping_status: WP_Post_Comment_Status_Name;
}
/**
* Properties for post types that support an excerpt
*/
interface WP_REST_API_Partial_Post_Excerpt {
/**
* The excerpt for the post.
*/
excerpt: {
/**
* The taxonomy terms for the post.
* Excerpt for the post, as it exists in the database. Only present when using the 'edit' context.
*/
"wp:term"?: unknown[];
raw?: string;
/**
* The featured image post.
* HTML excerpt for the post, transformed for display.
*/
"wp:featuredmedia"?: unknown[];
rendered: string;
/**
* The parent post.
* Whether the excerpt is protected with a password.
*/
up?: unknown[];
[k: string]: unknown;
protected: boolean;
};
[k: string]: unknown;
}
/**
* A media attachment object in a REST API context.
Expand Down
2 changes: 1 addition & 1 deletion packages/wp-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"author": "John Blackbourn",
"license": "MIT",
"dependencies": {
"typescript": ">=3"
"typescript": ">=5"
}
}
8 changes: 0 additions & 8 deletions packages/wp-types/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/hyper-schema#",
"$schema": "https://json-schema.org/draft/2019-09/hyper-schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schema.json",
"title": "WP",
"description": "WordPress is open source software you can use to create a beautiful website, blog, or app.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/block-template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/block-template.json",
"title": "WP_Block_Template",
"description": "Core class representing a block template.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/block-type.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/block-type.json",
"title": "WP_Block_Type",
"description": "Core class representing a block type.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/block.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/block.json",
"title": "WP_Block",
"description": "Class representing a parsed instance of a block.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/comment.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/comment.json",
"title": "WP_Comment",
"description": "Core class used to organize comments as instantiated objects with defined members.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/error-with-error.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/error-with-error.json",
"title": "WP_Error_With_Error",
"description": "WordPress Error class.\n\nRepresents a WP_Error object that contains at least one error.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/error-without-error.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/error-without-error.json",
"title": "WP_Error_Without_Error",
"description": "Empty WordPress Error class.\n\nRepresents a WP_Error object that contains no errors.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/error.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/error.json",
"title": "WP_Error",
"description": "WordPress Error class.\n\nContainer for checking for WordPress errors and error messages. Many core WordPress functions pass this class in the event of an error.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/locale.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/locale.json",
"title": "WP_Locale",
"description": "Core class used to store translated data for a locale.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/network.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/network.json",
"title": "WP_Network",
"description": "Core class used for interacting with a multisite network.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/post-type.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/post-type.json",
"title": "WP_Post_Type",
"description": "Core class used for interacting with post types.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/post.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/post.json",
"title": "WP_Post",
"description": "Core class used to implement the WP_Post object.",
Expand Down
2 changes: 1 addition & 1 deletion schemas/properties/block-parsed.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://raw.githubusercontent.com/johnbillion/wp-json-schemas/trunk/schemas/properties/block-parsed.json",
"title": "WP_Block_Parsed",
"description": "Original parsed array representation of block.",
Expand Down
Loading