kizlo 0.17.0 → 0.19.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.
- package/dist/adapters/auth.d.ts +17 -16
- package/dist/adapters/auth.js +4 -5
- package/dist/category/index.js +4 -4
- package/dist/category/schema.d.ts +153 -0
- package/dist/category/schema.js +4 -3
- package/dist/cli/commands/_wiring.js +9 -8
- package/dist/cli/commands/check.js +11 -15
- package/dist/cli/commands/dev.js +3 -3
- package/dist/cli/commands/generate.js +15 -17
- package/dist/cli/commands/test.js +3 -3
- package/dist/cli/daemon/config.js +148 -82
- package/dist/cli/daemon/generate.js +54 -54
- package/dist/cli/daemon/watch.js +41 -54
- package/dist/cli/wp/constants.d.ts +2 -4
- package/dist/cli/wp/constants.js +2 -4
- package/dist/cli/wp/types.d.ts +6 -3
- package/dist/cli/wp/utils.d.ts +3 -3
- package/dist/cli/wp/utils.js +9 -3
- package/dist/comment/errors.js +0 -1
- package/dist/comment/index.js +6 -6
- package/dist/config.d.ts +61 -47
- package/dist/context.d.ts +7 -7
- package/dist/context.js +4 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +8 -3
- package/dist/package.js +1 -1
- package/dist/page/index.js +3 -3
- package/dist/page/schema.d.ts +226 -0
- package/dist/page/schema.js +4 -3
- package/dist/post/index.js +3 -3
- package/dist/post/schema.d.ts +268 -0
- package/dist/post/schema.js +4 -3
- package/dist/procedures.d.ts +35 -902
- package/dist/seo/index.js +1 -1
- package/dist/seo/schema.d.ts +5 -5
- package/dist/shared/contract.d.ts +1 -1
- package/dist/shared/procedure.d.ts +12 -3
- package/dist/shared/procedure.js +4 -0
- package/dist/shared/result.d.ts +16 -7
- package/dist/shared/types.d.ts +1 -1
- package/dist/tag/index.js +3 -3
- package/dist/tag/schema.d.ts +151 -0
- package/dist/tag/schema.js +4 -3
- package/dist/test/auth.js +2 -3
- package/dist/test/users.d.ts +2 -4
- package/dist/test/users.js +4 -9
- package/dist/test.d.ts +2 -2
- package/dist/test.js +2 -2
- package/dist/wordpress/endpoint.js +2 -1
- package/dist/wordpress/error.d.ts +1 -0
- package/dist/wordpress/error.js +2 -0
- package/dist/wordpress/fetch-introspection.js +1 -1
- package/dist/wordpress/generate.js +51 -7
- package/dist/wordpress/index.d.ts +1 -1
- package/dist/wordpress/transport.js +5 -3
- package/dist/wordpress/types.d.ts +38 -12
- package/dist/wordpress/utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/seo/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createProcedure } from "../shared/procedure.js";
|
|
2
1
|
import { ListSitemapUrlInput, Robots, Seo, SitemapIndex, SitemapList, SitemapUrlList } from "./schema.js";
|
|
2
|
+
import { createProcedure } from "../shared/procedure.js";
|
|
3
3
|
import { deserializeSeo } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
//#region src/seo/index.ts
|
package/dist/seo/schema.d.ts
CHANGED
|
@@ -108,17 +108,17 @@ declare const Seo: z.ZodObject<{
|
|
|
108
108
|
type Seo = z.infer<typeof Seo>;
|
|
109
109
|
declare const CONTENT_TYPES: readonly ["post_type", "taxonomy", "author"];
|
|
110
110
|
declare const ContentType: z.ZodEnum<{
|
|
111
|
-
author: "author";
|
|
112
111
|
post_type: "post_type";
|
|
113
112
|
taxonomy: "taxonomy";
|
|
113
|
+
author: "author";
|
|
114
114
|
}>;
|
|
115
115
|
type ContentType = z.infer<typeof ContentType>;
|
|
116
116
|
declare const Sitemap: z.ZodObject<{
|
|
117
117
|
key: z.ZodString;
|
|
118
118
|
type: z.ZodEnum<{
|
|
119
|
-
author: "author";
|
|
120
119
|
post_type: "post_type";
|
|
121
120
|
taxonomy: "taxonomy";
|
|
121
|
+
author: "author";
|
|
122
122
|
}>;
|
|
123
123
|
pages: z.ZodNumber;
|
|
124
124
|
lastmod: z.ZodString;
|
|
@@ -127,9 +127,9 @@ type Sitemap = z.infer<typeof Sitemap>;
|
|
|
127
127
|
declare const SitemapList: z.ZodArray<z.ZodObject<{
|
|
128
128
|
key: z.ZodString;
|
|
129
129
|
type: z.ZodEnum<{
|
|
130
|
-
author: "author";
|
|
131
130
|
post_type: "post_type";
|
|
132
131
|
taxonomy: "taxonomy";
|
|
132
|
+
author: "author";
|
|
133
133
|
}>;
|
|
134
134
|
pages: z.ZodNumber;
|
|
135
135
|
lastmod: z.ZodString;
|
|
@@ -140,9 +140,9 @@ declare const SitemapIndex: z.ZodObject<{
|
|
|
140
140
|
sitemaps: z.ZodArray<z.ZodObject<{
|
|
141
141
|
key: z.ZodString;
|
|
142
142
|
type: z.ZodEnum<{
|
|
143
|
-
author: "author";
|
|
144
143
|
post_type: "post_type";
|
|
145
144
|
taxonomy: "taxonomy";
|
|
145
|
+
author: "author";
|
|
146
146
|
}>;
|
|
147
147
|
pages: z.ZodNumber;
|
|
148
148
|
lastmod: z.ZodString;
|
|
@@ -174,9 +174,9 @@ declare const SitemapUrlList: z.ZodArray<z.ZodObject<{
|
|
|
174
174
|
type SitemapUrlList = z.infer<typeof SitemapUrlList>;
|
|
175
175
|
declare const ListSitemapUrlInputBase: z.ZodObject<{
|
|
176
176
|
type: z.ZodEnum<{
|
|
177
|
-
author: "author";
|
|
178
177
|
post_type: "post_type";
|
|
179
178
|
taxonomy: "taxonomy";
|
|
179
|
+
author: "author";
|
|
180
180
|
}>;
|
|
181
181
|
page: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>>;
|
|
182
182
|
}, z.core.$strip>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HTTPMethod } from "./types.js";
|
|
2
2
|
import { AnyProcedureTree, InvocationScope } from "./procedure.js";
|
|
3
|
-
import { AnyContractRouter } from "@orpc/contract";
|
|
4
3
|
import { Pathname } from "@kizlo/shared";
|
|
4
|
+
import { AnyContractRouter } from "@orpc/contract";
|
|
5
5
|
|
|
6
6
|
//#region src/shared/contract.d.ts
|
|
7
7
|
type Contract = {
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { ProcedureContext } from "../context.js";
|
|
2
2
|
import { DefinedErrorMapLike, ThrowableErrorMap, WithCommonErrorMap } from "./error.js";
|
|
3
3
|
import { AnyMiddleware, InferMiddlewares, Middleware } from "./middleware.js";
|
|
4
|
-
import * as _orpc_contract0 from "@orpc/contract";
|
|
5
4
|
import { DeepMerge, Pathname, Prettify, Promisify, Schema, SchemaInput, SchemaOutput } from "@kizlo/shared";
|
|
5
|
+
import * as _orpc_contract0 from "@orpc/contract";
|
|
6
6
|
import * as _orpc_server0 from "@orpc/server";
|
|
7
7
|
import { HTTPMethod } from "@orpc/server";
|
|
8
8
|
import { JsonifiedValue } from "@orpc/openapi-client";
|
|
9
9
|
|
|
10
10
|
//#region src/shared/procedure.d.ts
|
|
11
|
+
declare const schemaTypeOutput: unique symbol;
|
|
12
|
+
type TypedSchema<TInput, TOutput = TInput> = Schema<TInput, TOutput> & {
|
|
13
|
+
readonly [schemaTypeOutput]: TOutput;
|
|
14
|
+
};
|
|
15
|
+
type ProcedureOutput<TScope, TOutput extends Schema> = TScope extends "api" ? TOutput extends TypedSchema<any, infer TPreservedOutput> ? TPreservedOutput : JsonifiedValue<SchemaOutput<TOutput>> : SchemaOutput<TOutput>;
|
|
11
16
|
type AnyProcedureTree = {
|
|
12
17
|
[K: string]: AnyProcedure | AnyProcedureTree;
|
|
13
18
|
};
|
|
@@ -110,8 +115,12 @@ type ProcedureOptions<TScope extends InvocationScope, TPathname extends Pathname
|
|
|
110
115
|
/** Schema for the call's single input argument. */
|
|
111
116
|
input?: TInput;
|
|
112
117
|
});
|
|
113
|
-
declare function createProcedure<TScope extends InvocationScope, TPathname extends Pathname, TInput extends Schema | undefined = undefined, TBody extends Schema | undefined = undefined, TParams extends Schema | undefined = undefined, TQuery extends Schema | undefined = undefined, THeaders extends Schema | undefined = undefined, TOutput extends Schema = Schema, TError extends DefinedErrorMapLike = DefinedErrorMapLike, TMiddlewares extends Middleware<ResolvedSchemaOutput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, SchemaOutput<TOutput>, TError>[] = Middleware<ResolvedSchemaOutput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, SchemaOutput<TOutput>, TError>[], TContext extends ProcedureContext & InferMiddlewares<TMiddlewares> = ProcedureContext & InferMiddlewares<TMiddlewares>>(options: ProcedureOptions<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders, TOutput, TError, TMiddlewares>, handler: ProcedureHandler<ResolvedSchemaOutput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, SchemaOutput<TOutput>, TError, TContext>): Procedure<TScope, ResolvedSchemaInput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, TScope
|
|
114
|
-
|
|
118
|
+
declare function createProcedure<TScope extends InvocationScope, TPathname extends Pathname, TInput extends Schema | undefined = undefined, TBody extends Schema | undefined = undefined, TParams extends Schema | undefined = undefined, TQuery extends Schema | undefined = undefined, THeaders extends Schema | undefined = undefined, TOutput extends Schema = Schema, TError extends DefinedErrorMapLike = DefinedErrorMapLike, TMiddlewares extends Middleware<ResolvedSchemaOutput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, SchemaOutput<TOutput>, TError>[] = Middleware<ResolvedSchemaOutput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, SchemaOutput<TOutput>, TError>[], TContext extends ProcedureContext & InferMiddlewares<TMiddlewares> = ProcedureContext & InferMiddlewares<TMiddlewares>>(options: ProcedureOptions<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders, TOutput, TError, TMiddlewares>, handler: ProcedureHandler<ResolvedSchemaOutput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, SchemaOutput<TOutput>, TError, TContext>): Procedure<TScope, ResolvedSchemaInput<TScope, TPathname, TInput, TBody, TParams, TQuery, THeaders>, ProcedureOutput<TScope, TOutput>, TError>;
|
|
119
|
+
/**
|
|
120
|
+
* Give a schema an explicit input and output type. For API procedure outputs, the declared output
|
|
121
|
+
* is already the client-visible wire type and is preserved without structural JSON remapping.
|
|
122
|
+
*/
|
|
123
|
+
declare function schemaType<TInput, TOutput = TInput>(schema?: Schema): TypedSchema<TInput, TOutput>;
|
|
115
124
|
declare function buildProcedure(procedure: AnyProcedure): _orpc_server0.DecoratedProcedure<_orpc_server0.Context & Record<never, never>, _orpc_server0.Context, _orpc_contract0.Schema<unknown, unknown>, _orpc_contract0.Schema<any, any>, Record<never, never>, Record<never, never>>;
|
|
116
125
|
declare function handleUnexpectedError(error: unknown, errors?: DefinedErrorMapLike): never;
|
|
117
126
|
declare function combineDetailed(parts: Record<string, Schema>): Schema;
|
package/dist/shared/procedure.js
CHANGED
|
@@ -9,6 +9,10 @@ function createProcedure(options, handler) {
|
|
|
9
9
|
handler: (ctx) => handler(ctx)
|
|
10
10
|
} };
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Give a schema an explicit input and output type. For API procedure outputs, the declared output
|
|
14
|
+
* is already the client-visible wire type and is preserved without structural JSON remapping.
|
|
15
|
+
*/
|
|
12
16
|
function schemaType(schema) {
|
|
13
17
|
return schema ?? { "~standard": {
|
|
14
18
|
vendor: "custom",
|
package/dist/shared/result.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefinedErrorMapLike, KizloError, WithCommonErrorMap } from "./error.js";
|
|
2
|
-
import { AnyProcedureTree, Procedure } from "./procedure.js";
|
|
3
|
-
import { NestedClient } from "@orpc/client";
|
|
2
|
+
import { AnyProcedure, AnyProcedureTree, Procedure } from "./procedure.js";
|
|
4
3
|
import { SchemaOutput } from "@kizlo/shared";
|
|
4
|
+
import { NestedClient } from "@orpc/client";
|
|
5
5
|
|
|
6
6
|
//#region src/shared/result.d.ts
|
|
7
7
|
type MaybeCallerOptions<UInput> = unknown extends UInput ? [] : [UInput] extends [undefined] ? [] : object extends UInput ? [input?: UInput] : [input: UInput];
|
|
@@ -9,16 +9,25 @@ type ProcedureMethod<UInput, UOutput, TError extends DefinedErrorMapLike> = {
|
|
|
9
9
|
(...rest: MaybeCallerOptions<UInput>): Promise<KizloResult<UOutput, TError>>;
|
|
10
10
|
call: (...rest: MaybeCallerOptions<UInput>) => Promise<UOutput>;
|
|
11
11
|
};
|
|
12
|
-
type KizloErrorUnion<TErrors extends DefinedErrorMapLike> = { [K in Extract<keyof TErrors, string>]: KizloError<K, SchemaOutput<TErrors[K]["data"]>> }[Extract<keyof TErrors, string>];
|
|
13
|
-
type KizloResult<TOutput, TErrors extends DefinedErrorMapLike = DefinedErrorMapLike> = {
|
|
14
|
-
data: TOutput;
|
|
12
|
+
type KizloErrorUnion<TErrors$1 extends DefinedErrorMapLike> = { [K in Extract<keyof TErrors$1, string>]: KizloError<K, SchemaOutput<TErrors$1[K]["data"]>> }[Extract<keyof TErrors$1, string>];
|
|
13
|
+
type KizloResult<TOutput$1, TErrors$1 extends DefinedErrorMapLike = DefinedErrorMapLike> = {
|
|
14
|
+
data: TOutput$1;
|
|
15
15
|
error: null;
|
|
16
16
|
success: true;
|
|
17
17
|
} | {
|
|
18
18
|
data: undefined;
|
|
19
|
-
error: KizloErrorUnion<WithCommonErrorMap<TErrors>>;
|
|
19
|
+
error: KizloErrorUnion<WithCommonErrorMap<TErrors$1>>;
|
|
20
20
|
success: false;
|
|
21
21
|
};
|
|
22
|
+
/** The input accepted by one public Kizlo procedure object. */
|
|
23
|
+
type InferProcedureInput<TProcedure extends AnyProcedure> = TProcedure extends Procedure<any, infer TInput, any, any> ? TInput : never;
|
|
24
|
+
/** The successful data returned by one public Kizlo procedure object. */
|
|
25
|
+
type InferProcedureData<TProcedure extends AnyProcedure> = TProcedure extends Procedure<any, any, infer TOutput, any> ? TOutput : never;
|
|
26
|
+
/** The declared and common client-visible errors returned by one public Kizlo procedure object. */
|
|
27
|
+
type InferProcedureError<TProcedure extends AnyProcedure> = TProcedure extends Procedure<any, any, any, infer TErrors> ? KizloErrorUnion<WithCommonErrorMap<TErrors>> : never;
|
|
28
|
+
/** The complete wrapped result returned by a normal call to one public Kizlo procedure object. */
|
|
29
|
+
type InferProcedureResult<TProcedure extends AnyProcedure> = TProcedure extends Procedure<any, any, infer TOutput, infer TErrors> ? KizloResult<TOutput, TErrors> : never;
|
|
22
30
|
type ResultClient<T extends AnyProcedureTree> = { [K in keyof T]: T[K] extends Procedure<infer _Scope, infer Input, infer Output, infer Errors> ? ProcedureMethod<Input, Output, Errors> : T[K] extends AnyProcedureTree ? ResultClient<T[K]> : never };
|
|
31
|
+
declare function createResultClient<T extends AnyProcedureTree>(client: NestedClient<any>): ResultClient<T>;
|
|
23
32
|
//#endregion
|
|
24
|
-
export { ResultClient };
|
|
33
|
+
export { InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, KizloErrorUnion, KizloResult, MaybeCallerOptions, ProcedureMethod, ResultClient, createResultClient };
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ListMetadata } from "./schema.js";
|
|
2
|
-
import { NestedClient } from "@orpc/client";
|
|
3
2
|
import { CookieOptions, CookieWithOptions } from "@kizlo/shared";
|
|
3
|
+
import { NestedClient } from "@orpc/client";
|
|
4
4
|
|
|
5
5
|
//#region src/shared/types.d.ts
|
|
6
6
|
type AnyContext = Record<PropertyKey, any>;
|
package/dist/tag/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createProcedure } from "../shared/procedure.js";
|
|
1
|
+
import { createProcedure, schemaType } from "../shared/procedure.js";
|
|
2
2
|
import { parseIdentifier } from "../shared/identifier.js";
|
|
3
3
|
import { deserializeListMetadata } from "../shared/serialize.js";
|
|
4
4
|
import { GET_TAG_ERROR_MAP, LIST_TAG_ERROR_MAP } from "./error.js";
|
|
@@ -13,7 +13,7 @@ const TAG_PROCEDURES = {
|
|
|
13
13
|
method: "GET",
|
|
14
14
|
path: "/tags/{identifier}",
|
|
15
15
|
params: RetrieveTagInput.pick({ identifier: true }),
|
|
16
|
-
output: Tag,
|
|
16
|
+
output: schemaType(Tag),
|
|
17
17
|
errors: GET_TAG_ERROR_MAP
|
|
18
18
|
}, async ({ input, context, errors }) => {
|
|
19
19
|
const identifier = parseIdentifier(input.params.identifier);
|
|
@@ -38,7 +38,7 @@ const TAG_PROCEDURES = {
|
|
|
38
38
|
method: "GET",
|
|
39
39
|
path: "/tags",
|
|
40
40
|
query: ListTagInput.optional(),
|
|
41
|
-
output: TagList,
|
|
41
|
+
output: schemaType(TagList),
|
|
42
42
|
errors: LIST_TAG_ERROR_MAP
|
|
43
43
|
}, async ({ input, context, errors }) => {
|
|
44
44
|
const response = await context.wordpress.taxonomies.postTag.list({
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { WP_CustomFields } from "../wordpress/types.js";
|
|
2
|
+
import "../wordpress/index.js";
|
|
3
|
+
import * as _kizlo_shared24 from "@kizlo/shared";
|
|
4
|
+
import z from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/tag/schema.d.ts
|
|
7
|
+
type TagCustomFields = WP_CustomFields<"taxonomies.postTag">;
|
|
8
|
+
declare const TagCustomFieldsSchema: z.ZodType<TagCustomFields, TagCustomFields>;
|
|
9
|
+
declare const Tag: z.ZodObject<{
|
|
10
|
+
id: z.ZodNumber;
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
slug: z.ZodString;
|
|
13
|
+
url: z.ZodNullable<z.ZodString>;
|
|
14
|
+
description: z.ZodNullable<z.ZodString>;
|
|
15
|
+
postCount: z.ZodNumber;
|
|
16
|
+
seo: z.ZodNullable<z.ZodObject<{
|
|
17
|
+
head: z.ZodObject<{
|
|
18
|
+
title: z.ZodString;
|
|
19
|
+
canonical: z.ZodString;
|
|
20
|
+
robots: z.ZodObject<{
|
|
21
|
+
index: z.ZodString;
|
|
22
|
+
follow: z.ZodString;
|
|
23
|
+
maxSnippet: z.ZodString;
|
|
24
|
+
maxImagePreview: z.ZodString;
|
|
25
|
+
maxVideoPreview: z.ZodString;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
og: z.ZodObject<{
|
|
28
|
+
locale: z.ZodString;
|
|
29
|
+
type: z.ZodString;
|
|
30
|
+
title: z.ZodString;
|
|
31
|
+
url: z.ZodString;
|
|
32
|
+
siteName: z.ZodString;
|
|
33
|
+
description: z.ZodString;
|
|
34
|
+
image: z.ZodNullable<z.ZodObject<{
|
|
35
|
+
url: z.ZodString;
|
|
36
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
37
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
38
|
+
type: z.ZodNullable<z.ZodString>;
|
|
39
|
+
alt: z.ZodNullable<z.ZodString>;
|
|
40
|
+
}, z.core.$strip>>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
twitter: z.ZodObject<{
|
|
43
|
+
card: z.ZodEnum<{
|
|
44
|
+
summary: "summary";
|
|
45
|
+
summary_large_image: "summary_large_image";
|
|
46
|
+
}>;
|
|
47
|
+
title: z.ZodString;
|
|
48
|
+
site: z.ZodNullable<z.ZodString>;
|
|
49
|
+
creator: z.ZodNullable<z.ZodString>;
|
|
50
|
+
description: z.ZodString;
|
|
51
|
+
image: z.ZodNullable<z.ZodString>;
|
|
52
|
+
imageAlt: z.ZodNullable<z.ZodString>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
article: z.ZodNullable<z.ZodObject<{
|
|
55
|
+
publishedTime: z.ZodString;
|
|
56
|
+
modifiedTime: z.ZodString;
|
|
57
|
+
author: z.ZodString;
|
|
58
|
+
authorUrl: z.ZodString;
|
|
59
|
+
section: z.ZodString;
|
|
60
|
+
tags: z.ZodArray<z.ZodString>;
|
|
61
|
+
}, z.core.$strip>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
schema: z.ZodObject<{
|
|
64
|
+
"@context": z.ZodLiteral<"https://schema.org">;
|
|
65
|
+
"@graph": z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
}, z.core.$strip>>;
|
|
68
|
+
custom: z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>;
|
|
69
|
+
meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared24.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared24.JSONValue, unknown>>>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
type Tag = Omit<z.output<typeof Tag>, "custom"> & {
|
|
72
|
+
custom: TagCustomFields;
|
|
73
|
+
};
|
|
74
|
+
declare const TagList: z.ZodObject<{
|
|
75
|
+
items: z.ZodArray<z.ZodObject<{
|
|
76
|
+
id: z.ZodNumber;
|
|
77
|
+
name: z.ZodString;
|
|
78
|
+
slug: z.ZodString;
|
|
79
|
+
url: z.ZodNullable<z.ZodString>;
|
|
80
|
+
description: z.ZodNullable<z.ZodString>;
|
|
81
|
+
postCount: z.ZodNumber;
|
|
82
|
+
seo: z.ZodNullable<z.ZodObject<{
|
|
83
|
+
head: z.ZodObject<{
|
|
84
|
+
title: z.ZodString;
|
|
85
|
+
canonical: z.ZodString;
|
|
86
|
+
robots: z.ZodObject<{
|
|
87
|
+
index: z.ZodString;
|
|
88
|
+
follow: z.ZodString;
|
|
89
|
+
maxSnippet: z.ZodString;
|
|
90
|
+
maxImagePreview: z.ZodString;
|
|
91
|
+
maxVideoPreview: z.ZodString;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
og: z.ZodObject<{
|
|
94
|
+
locale: z.ZodString;
|
|
95
|
+
type: z.ZodString;
|
|
96
|
+
title: z.ZodString;
|
|
97
|
+
url: z.ZodString;
|
|
98
|
+
siteName: z.ZodString;
|
|
99
|
+
description: z.ZodString;
|
|
100
|
+
image: z.ZodNullable<z.ZodObject<{
|
|
101
|
+
url: z.ZodString;
|
|
102
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
103
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
104
|
+
type: z.ZodNullable<z.ZodString>;
|
|
105
|
+
alt: z.ZodNullable<z.ZodString>;
|
|
106
|
+
}, z.core.$strip>>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
twitter: z.ZodObject<{
|
|
109
|
+
card: z.ZodEnum<{
|
|
110
|
+
summary: "summary";
|
|
111
|
+
summary_large_image: "summary_large_image";
|
|
112
|
+
}>;
|
|
113
|
+
title: z.ZodString;
|
|
114
|
+
site: z.ZodNullable<z.ZodString>;
|
|
115
|
+
creator: z.ZodNullable<z.ZodString>;
|
|
116
|
+
description: z.ZodString;
|
|
117
|
+
image: z.ZodNullable<z.ZodString>;
|
|
118
|
+
imageAlt: z.ZodNullable<z.ZodString>;
|
|
119
|
+
}, z.core.$strip>;
|
|
120
|
+
article: z.ZodNullable<z.ZodObject<{
|
|
121
|
+
publishedTime: z.ZodString;
|
|
122
|
+
modifiedTime: z.ZodString;
|
|
123
|
+
author: z.ZodString;
|
|
124
|
+
authorUrl: z.ZodString;
|
|
125
|
+
section: z.ZodString;
|
|
126
|
+
tags: z.ZodArray<z.ZodString>;
|
|
127
|
+
}, z.core.$strip>>;
|
|
128
|
+
}, z.core.$strip>;
|
|
129
|
+
schema: z.ZodObject<{
|
|
130
|
+
"@context": z.ZodLiteral<"https://schema.org">;
|
|
131
|
+
"@graph": z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
}, z.core.$strip>>;
|
|
134
|
+
custom: z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>;
|
|
135
|
+
meta: z.ZodRecord<z.ZodString, z.ZodType<_kizlo_shared24.JSONValue, unknown, z.core.$ZodTypeInternals<_kizlo_shared24.JSONValue, unknown>>>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
meta: z.ZodObject<{
|
|
138
|
+
page: z.ZodNumber;
|
|
139
|
+
totalItems: z.ZodNumber;
|
|
140
|
+
totalPages: z.ZodNumber;
|
|
141
|
+
nextPage: z.ZodNullable<z.ZodNumber>;
|
|
142
|
+
prevPage: z.ZodNullable<z.ZodNumber>;
|
|
143
|
+
hasNextPage: z.ZodBoolean;
|
|
144
|
+
hasPrevPage: z.ZodBoolean;
|
|
145
|
+
}, z.core.$strip>;
|
|
146
|
+
}, z.core.$strip>;
|
|
147
|
+
type TagList = Omit<z.output<typeof TagList>, "items"> & {
|
|
148
|
+
items: Tag[];
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { Tag, TagCustomFields, TagCustomFieldsSchema, TagList };
|
package/dist/tag/schema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IdentifierInput, ListMetadata, ListOrder, customFieldsSchema } from "../shared/schema.js";
|
|
2
1
|
import { Seo } from "../seo/schema.js";
|
|
2
|
+
import { IdentifierInput, ListMetadata, ListOrder, customFieldsSchema } from "../shared/schema.js";
|
|
3
3
|
import { BooleanLike, Metadata, NumberLike, arrayable, lenient } from "@kizlo/shared";
|
|
4
4
|
import z from "zod/v4";
|
|
5
5
|
|
|
@@ -14,6 +14,7 @@ const WP_TAG_ORDER_BYS = [
|
|
|
14
14
|
"description",
|
|
15
15
|
"count"
|
|
16
16
|
];
|
|
17
|
+
const TagCustomFieldsSchema = customFieldsSchema();
|
|
17
18
|
const Tag = z.object({
|
|
18
19
|
id: z.number(),
|
|
19
20
|
name: z.string(),
|
|
@@ -22,7 +23,7 @@ const Tag = z.object({
|
|
|
22
23
|
description: z.string().nullable(),
|
|
23
24
|
postCount: z.number(),
|
|
24
25
|
seo: Seo.nullable(),
|
|
25
|
-
custom:
|
|
26
|
+
custom: TagCustomFieldsSchema,
|
|
26
27
|
meta: Metadata
|
|
27
28
|
});
|
|
28
29
|
const RetrieveTagInput = z.object({ identifier: IdentifierInput });
|
|
@@ -45,4 +46,4 @@ const ListTagInput = z.object({
|
|
|
45
46
|
});
|
|
46
47
|
|
|
47
48
|
//#endregion
|
|
48
|
-
export { ListTagInput, RetrieveTagInput, Tag, TagList };
|
|
49
|
+
export { ListTagInput, RetrieveTagInput, Tag, TagCustomFieldsSchema, TagList };
|
package/dist/test/auth.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
//#region src/test/auth.ts
|
|
2
2
|
function testAuthAdapter(user) {
|
|
3
|
-
return {
|
|
3
|
+
return { getSession() {
|
|
4
4
|
return {
|
|
5
|
-
id: user.
|
|
5
|
+
id: user.id,
|
|
6
6
|
email: user.email,
|
|
7
|
-
phone: user.phone,
|
|
8
7
|
firstName: user.firstName,
|
|
9
8
|
lastName: user.lastName
|
|
10
9
|
};
|
package/dist/test/users.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import { TestCredentials } from "../cli/wp/types.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/test/users.d.ts
|
|
4
4
|
interface TestAuthAdapterUser {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
id: string;
|
|
6
|
+
email: string;
|
|
7
7
|
firstName: string;
|
|
8
8
|
lastName: string;
|
|
9
|
-
email: string;
|
|
10
|
-
phone: string;
|
|
11
9
|
}
|
|
12
10
|
declare function toTestUser(user: TestCredentials["users"]["user"]): TestAuthAdapterUser;
|
|
13
11
|
//#endregion
|
package/dist/test/users.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
//#region src/test/users.ts
|
|
2
|
-
const STATIC_FIELDS = {
|
|
3
|
-
firstName: "Test",
|
|
4
|
-
lastName: "Customer",
|
|
5
|
-
email: "customer@example.com",
|
|
6
|
-
phone: "+10000000002"
|
|
7
|
-
};
|
|
8
2
|
function toTestUser(user) {
|
|
9
3
|
return {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
id: String(user.id),
|
|
5
|
+
email: user.email,
|
|
6
|
+
firstName: "Test",
|
|
7
|
+
lastName: "Customer"
|
|
13
8
|
};
|
|
14
9
|
}
|
|
15
10
|
|
package/dist/test.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevPluginSource, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, JsonValue, LocalPlugin, PluginSource, SeedContext, SettleContext, TestAdminUser, TestCredentials, TestUser, defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
2
|
-
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER,
|
|
2
|
+
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, INTROSPECTION_META_REL, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER, githubRelease, kizloRelease } from "./cli/wp/constants.js";
|
|
3
3
|
import { DockerStack, DockerStatus, RunResult, Stack, StackStatus, compose, composeDown, composePull, composeStop, composeUp, createStack, dockerAvailable, dockerHint, dockerStatus, runningProjectContainers, stackStatus, stopProjectContainers, wpCli, wpEval } from "./cli/wp/docker.js";
|
|
4
4
|
import { activateLocalPlugin, credentialsPath, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, isSeeded, recordedPort, resolvePluginSource, settleFixtures } from "./cli/wp/utils.js";
|
|
5
5
|
import { TestAuthAdapterUser, toTestUser } from "./test/users.js";
|
|
@@ -8,4 +8,4 @@ import { CAPTCHA_TEST_TOKEN_PASS, captchaMock } from "./test/captcha.js";
|
|
|
8
8
|
import { menuFixture } from "./menu/fixture.js";
|
|
9
9
|
import { postFixture } from "./post/fixture.js";
|
|
10
10
|
import { coreFixtures } from "./test/fixtures.js";
|
|
11
|
-
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, DevPluginSource, DockerStack, DockerStatus, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, JsonValue, LOCAL_DIR_REL, LocalPlugin, OPCACHE_INI, PluginSource, REMAP_ENTRYPOINT, RunResult, SEED_MARKER_OPTION, SEED_VERSION, SeedContext, SettleContext, Stack, StackStatus, TEST_ADMIN, TEST_USER, TestAdminUser, TestAuthAdapterUser, TestCredentials, TestUser,
|
|
11
|
+
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, DevPluginSource, DockerStack, DockerStatus, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, INTROSPECTION_META_REL, JsonValue, LOCAL_DIR_REL, LocalPlugin, OPCACHE_INI, PluginSource, REMAP_ENTRYPOINT, RunResult, SEED_MARKER_OPTION, SEED_VERSION, SeedContext, SettleContext, Stack, StackStatus, TEST_ADMIN, TEST_USER, TestAdminUser, TestAuthAdapterUser, TestCredentials, TestUser, activateLocalPlugin, captchaMock, compose, composeDown, composePull, composeStop, composeUp, coreFixtures, createStack, credentialsPath, defineFixture, dockerAvailable, dockerHint, dockerStatus, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, githubRelease, isLocalPlugin, isSeeded, kizloRelease, menuFixture, postFixture, recordedPort, resolvePluginSource, runningProjectContainers, settleFixtures, stackStatus, stopProjectContainers, testAuthAdapter, toTestUser, wpCli, wpEval };
|
package/dist/test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineFixture, isLocalPlugin } from "./cli/wp/types.js";
|
|
2
|
-
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER,
|
|
2
|
+
import { COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, INTROSPECTION_META_REL, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER, githubRelease, kizloRelease } from "./cli/wp/constants.js";
|
|
3
3
|
import { compose, composeDown, composePull, composeStop, composeUp, createStack, dockerAvailable, dockerHint, dockerStatus, runningProjectContainers, stackStatus, stopProjectContainers, wpCli, wpEval } from "./cli/wp/docker.js";
|
|
4
4
|
import { activateLocalPlugin, credentialsPath, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, isSeeded, recordedPort, resolvePluginSource, settleFixtures } from "./cli/wp/utils.js";
|
|
5
5
|
import { testAuthAdapter } from "./test/auth.js";
|
|
@@ -9,4 +9,4 @@ import { postFixture } from "./post/fixture.js";
|
|
|
9
9
|
import { coreFixtures } from "./test/fixtures.js";
|
|
10
10
|
import { toTestUser } from "./test/users.js";
|
|
11
11
|
|
|
12
|
-
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER,
|
|
12
|
+
export { CAPTCHA_TEST_TOKEN_PASS, COMPOSE_FILE, CONFIG_FILES, CREDENTIALS_REL, DEFAULT_PLUGINS, DEFAULT_PORT, DEFAULT_WORDPRESS_TAG, INTROSPECTION_META_REL, LOCAL_DIR_REL, OPCACHE_INI, REMAP_ENTRYPOINT, SEED_MARKER_OPTION, SEED_VERSION, TEST_ADMIN, TEST_USER, activateLocalPlugin, captchaMock, compose, composeDown, composePull, composeStop, composeUp, coreFixtures, createStack, credentialsPath, defineFixture, dockerAvailable, dockerHint, dockerStatus, ensurePlugin, ensurePlugins, findConfigDir, getTestCredentials, githubRelease, isLocalPlugin, isSeeded, kizloRelease, menuFixture, postFixture, recordedPort, resolvePluginSource, runningProjectContainers, settleFixtures, stackStatus, stopProjectContainers, testAuthAdapter, toTestUser, wpCli, wpEval };
|
|
@@ -66,7 +66,8 @@ function buildWordPressRequest(definition, input) {
|
|
|
66
66
|
body: rest,
|
|
67
67
|
requestContentType: definition.requestContentType
|
|
68
68
|
} : { searchParams: rest },
|
|
69
|
-
responseContentTypes: definition.responseContentTypes
|
|
69
|
+
responseContentTypes: definition.responseContentTypes,
|
|
70
|
+
dataResponseStatuses: definition.dataResponseStatuses
|
|
70
71
|
},
|
|
71
72
|
error: null
|
|
72
73
|
};
|
|
@@ -3,6 +3,7 @@ import { WP_CommonErrorCode, WP_ErrorData } from "./types.js";
|
|
|
3
3
|
//#region src/wordpress/error.d.ts
|
|
4
4
|
declare class WP_Error<TCode extends string = string> extends Error {
|
|
5
5
|
code: TCode | WP_CommonErrorCode;
|
|
6
|
+
readonly data: unknown;
|
|
6
7
|
constructor(error: WP_ErrorData<TCode>);
|
|
7
8
|
}
|
|
8
9
|
//#endregion
|
package/dist/wordpress/error.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
//#region src/wordpress/error.ts
|
|
2
2
|
var WP_Error = class extends Error {
|
|
3
3
|
code;
|
|
4
|
+
data;
|
|
4
5
|
constructor(error) {
|
|
5
6
|
super(error.message ?? "Internal server error, please try again.");
|
|
6
7
|
this.name = "WordPress Error";
|
|
7
8
|
this.code = error.code;
|
|
9
|
+
this.data = error.data ?? null;
|
|
8
10
|
}
|
|
9
11
|
};
|
|
10
12
|
|
|
@@ -6,7 +6,7 @@ import { PLUGIN_VERSION_HEADER } from "@kizlo/shared";
|
|
|
6
6
|
* WordPress could not be asked, or did not answer with a contract: a transport failure, a non-2xx
|
|
7
7
|
* status, a body that is not JSON. A document that parsed is never one of these, however much of it
|
|
8
8
|
* WordPress had to exclude, because what to do about an exclusion is the generator's policy and not
|
|
9
|
-
* this function's. It reports; {@link
|
|
9
|
+
* this function's. It reports; {@link generateIntrospectionOnce} decides.
|
|
10
10
|
*/
|
|
11
11
|
var IntrospectionFetchError = class extends Error {
|
|
12
12
|
/**
|
|
@@ -182,6 +182,9 @@ function responseStatus(status) {
|
|
|
182
182
|
function isSuccessStatus(status) {
|
|
183
183
|
return /^2\d\d$/.test(status);
|
|
184
184
|
}
|
|
185
|
+
function isWordPressErrorResponse(response) {
|
|
186
|
+
return response.body?.$ref === "kizlo.error";
|
|
187
|
+
}
|
|
185
188
|
/**
|
|
186
189
|
* Every failing status of an endpoint carries the same error union, so spelling one member per
|
|
187
190
|
* status would repeat it four or five times for no discrimination anyone can act on. They collapse
|
|
@@ -193,10 +196,10 @@ function renderResult(apiId, operationId, operation, context) {
|
|
|
193
196
|
const name = endpointName(apiId, operationId, "EndpointResult");
|
|
194
197
|
const errors = operation.errors.map(literal).join(" | ") || "never";
|
|
195
198
|
const responses = sortedEntries(operation.responses);
|
|
196
|
-
const failures = responses.filter(([
|
|
199
|
+
const failures = responses.filter(([, response]) => isWordPressErrorResponse(response));
|
|
197
200
|
const headerNames = [...new Set(responses.flatMap(([, response]) => responseHeaderNames(response, context)))].sort((left, right) => left.localeCompare(right)).map(literal).join(" | ");
|
|
198
201
|
const sharedHeaderNames = headerNames ? `, ${headerNames}` : "";
|
|
199
|
-
const variants = responses.filter(([
|
|
202
|
+
const variants = responses.filter(([, response]) => !isWordPressErrorResponse(response)).map(([status, response]) => `WP_Success<${responseBody(response, context)}, ${status}, ${responseHeaders(response, context)}${sharedHeaderNames}>`);
|
|
200
203
|
if (new Set([NO_HEADERS, ...failures.map(([, response]) => responseHeaders(response, context))]).size === 1) variants.push(`WP_Failure<${errors}, number, ${NO_HEADERS}${sharedHeaderNames}>`);
|
|
201
204
|
else {
|
|
202
205
|
for (const [status, response] of failures) variants.push(`WP_Failure<${errors}, ${responseStatus(status)}, ${responseHeaders(response, context)}${sharedHeaderNames}>`);
|
|
@@ -257,13 +260,15 @@ function sortedEndpoints(node) {
|
|
|
257
260
|
function endpointDefinition(entry) {
|
|
258
261
|
const pathParameters = sortedEntries(entry.operation.input.properties ?? {}).filter(([, schema]) => schema.in === "path").map(([name]) => name);
|
|
259
262
|
const responseContentTypes = Object.fromEntries(sortedEntries(entry.operation.responses).map(([status, response]) => [status, response.content_type]));
|
|
263
|
+
const dataResponseStatuses = sortedEntries(entry.operation.responses).filter(([status, response]) => !isSuccessStatus(status) && !isWordPressErrorResponse(response)).map(([status]) => status);
|
|
260
264
|
return {
|
|
261
265
|
namespace: entry.namespace,
|
|
262
266
|
path: entry.path,
|
|
263
267
|
method: entry.operation.method,
|
|
264
268
|
pathParameters,
|
|
265
269
|
...entry.operation.input.content_type ? { requestContentType: entry.operation.input.content_type } : {},
|
|
266
|
-
responseContentTypes
|
|
270
|
+
responseContentTypes,
|
|
271
|
+
...dataResponseStatuses.length > 0 ? { dataResponseStatuses } : {}
|
|
267
272
|
};
|
|
268
273
|
}
|
|
269
274
|
function renderRecord(value) {
|
|
@@ -279,7 +284,8 @@ function renderDefinition(definition) {
|
|
|
279
284
|
`method: ${literal(definition.method)}`,
|
|
280
285
|
`pathParameters: [${definition.pathParameters.map(literal).join(", ")}]`,
|
|
281
286
|
...definition.requestContentType ? [`requestContentType: ${literal(definition.requestContentType)}`] : [],
|
|
282
|
-
`responseContentTypes: ${renderRecord(definition.responseContentTypes)}
|
|
287
|
+
`responseContentTypes: ${renderRecord(definition.responseContentTypes)}`,
|
|
288
|
+
...definition.dataResponseStatuses?.length ? [`dataResponseStatuses: [${definition.dataResponseStatuses.map(literal).join(", ")}]`] : []
|
|
283
289
|
].join(", ")} }`;
|
|
284
290
|
}
|
|
285
291
|
/**
|
|
@@ -300,6 +306,28 @@ function renderEndpointNode(node, indent) {
|
|
|
300
306
|
if (entries.length === 0) return "{}";
|
|
301
307
|
return `{\n${entries.join("\n")}\n${indent.slice(0, -1)}}`;
|
|
302
308
|
}
|
|
309
|
+
function renderEndpointRegistry(node, path = []) {
|
|
310
|
+
const entries = [];
|
|
311
|
+
for (const [key, child] of sortedChildren(node)) entries.push(...renderEndpointRegistry(child, [...path, key]));
|
|
312
|
+
for (const entry of sortedEndpoints(node)) {
|
|
313
|
+
const input = endpointName(entry.apiId, entry.operationId, "EndpointInput");
|
|
314
|
+
const result = endpointName(entry.apiId, entry.operationId, "EndpointResult");
|
|
315
|
+
entries.push(`\t\t${JSON.stringify([...path, entry.member].join("."))}: WP_Endpoint<${input}, ${result}>`);
|
|
316
|
+
}
|
|
317
|
+
return entries;
|
|
318
|
+
}
|
|
319
|
+
function renderCustomFieldsRegistry(document) {
|
|
320
|
+
const entries = [];
|
|
321
|
+
for (const id of Object.keys(document.schemas).sort((left, right) => left.localeCompare(right))) {
|
|
322
|
+
const match = /^(post-types|taxonomies)\.([^.]+)\.item$/.exec(id);
|
|
323
|
+
if (!match) continue;
|
|
324
|
+
const namespace = match[1] === "post-types" ? "postTypes" : "taxonomies";
|
|
325
|
+
const slug = match[2];
|
|
326
|
+
if (!slug) continue;
|
|
327
|
+
entries.push(`\t\t${JSON.stringify(`${namespace}.${camel(slug)}`)}: ${schemaName(id)}["kizlo"]["custom"]`);
|
|
328
|
+
}
|
|
329
|
+
return entries;
|
|
330
|
+
}
|
|
303
331
|
function operationEntries(apiId, api) {
|
|
304
332
|
const entries = [];
|
|
305
333
|
for (const [, operations] of sortedEntries(api.paths)) for (const [operationId, operation] of sortedEntries(operations)) entries.push([operationId, operation]);
|
|
@@ -349,13 +377,29 @@ const RUNTIME_TYPES = [
|
|
|
349
377
|
"WP_Success",
|
|
350
378
|
"WP_TransportFailure"
|
|
351
379
|
];
|
|
352
|
-
|
|
380
|
+
function renderRegistries(tree, document) {
|
|
381
|
+
const endpoints = renderEndpointRegistry(tree);
|
|
382
|
+
const customFields = renderCustomFieldsRegistry(document);
|
|
383
|
+
return [
|
|
384
|
+
`declare module "kizlo" {`,
|
|
385
|
+
`\tinterface WordPressClientRegistry {`,
|
|
386
|
+
`\t\tendpoints: typeof endpoints`,
|
|
387
|
+
`\t}`,
|
|
388
|
+
`\tinterface WordPressEndpointRegistry {`,
|
|
389
|
+
...endpoints,
|
|
390
|
+
`\t}`,
|
|
391
|
+
`\tinterface WordPressCustomFieldsRegistry {`,
|
|
392
|
+
...customFields,
|
|
393
|
+
`\t}`,
|
|
394
|
+
`}`
|
|
395
|
+
].join("\n");
|
|
396
|
+
}
|
|
353
397
|
/**
|
|
354
398
|
* The `kizlo` names a generated module uses. `wpEndpoint` is the only value among them, so the rest
|
|
355
399
|
* erase at build.
|
|
356
400
|
*/
|
|
357
401
|
function kizloImports(body, hasEndpoints) {
|
|
358
|
-
const types = new Set(["WP_Client", ...RUNTIME_TYPES.filter((name) => (/* @__PURE__ */ new RegExp(`\\b${name}\\b`)).test(body))]);
|
|
402
|
+
const types = new Set(["WP_Client", ...["WP_Endpoint", ...RUNTIME_TYPES].filter((name) => (/* @__PURE__ */ new RegExp(`\\b${name}\\b`)).test(body))]);
|
|
359
403
|
const values = hasEndpoints ? ["wpEndpoint"] : [];
|
|
360
404
|
return [...types, ...values].sort().map((name) => types.has(name) ? `type ${name}` : name).join(", ");
|
|
361
405
|
}
|
|
@@ -389,7 +433,7 @@ function generateWordPressModule(document) {
|
|
|
389
433
|
body,
|
|
390
434
|
`export const endpoints = ${endpointBody}`,
|
|
391
435
|
`export type WordPressClient = WP_Client<typeof endpoints>`,
|
|
392
|
-
|
|
436
|
+
renderRegistries(tree, document)
|
|
393
437
|
].join(DECLARATION_SEPARATOR);
|
|
394
438
|
const imports = `import { ${kizloImports(moduleBody, endpointBody !== "{}")} } from "kizlo"`;
|
|
395
439
|
const preamble = `${GENERATED_HEADER}// Introspection ${document.hash}\n\n${imports}\n\n`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WP_Error } from "./error.js";
|
|
2
|
-
import { ActiveWordPressClient, WP_CallOptions, WP_Client, WP_CommonErrorCode, WP_CurrencyFormat, WP_Endpoint, WP_EndpointData, WP_EndpointDefinition, WP_EndpointInput, WP_EndpointResult, WP_ErrorData, WP_Failure, WP_List, WP_ListMetadata, WP_RequestBuild, WP_RequestContentType, WP_RequestInput, WP_RequestMethod, WP_ResponseContentType, WP_Result, WP_Success, WP_TransportFailure, WP_TypedHeaders, WordPressClientRegistry, WordPressCredentials } from "./types.js";
|
|
2
|
+
import { ActiveWordPressClient, WP_CallOptions, WP_Client, WP_CommonErrorCode, WP_CurrencyFormat, WP_CustomFields, WP_CustomFieldsPath, WP_Endpoint, WP_EndpointData, WP_EndpointDefinition, WP_EndpointError, WP_EndpointInput, WP_EndpointPath, WP_EndpointResult, WP_ErrorData, WP_Failure, WP_List, WP_ListMetadata, WP_RequestBuild, WP_RequestContentType, WP_RequestInput, WP_RequestMethod, WP_ResponseContentType, WP_Result, WP_Success, WP_TransportFailure, WP_TypedHeaders, WordPressClientRegistry, WordPressCredentials, WordPressCustomFieldsRegistry, WordPressEndpointRegistry } from "./types.js";
|
|
3
3
|
import { WordPressTransport, WordPressTransportOptions, WordPressTransportResult } from "./transport.js";
|
|
4
4
|
import { buildWordPressRequest, createWordPressClient, wpEndpoint } from "./endpoint.js";
|
|
5
5
|
import { isWordPressResourceError } from "./utils.js";
|