kizlo 0.15.2 → 0.16.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/logger.d.ts +2 -5
- package/dist/adapters/logger.js +1 -1
- package/dist/adapters/types.d.ts +19 -0
- package/dist/adapters/types.js +17 -0
- package/dist/astro/server.d.ts +2 -2
- package/dist/astro/server.js +2 -2
- package/dist/category/index.js +2 -2
- package/dist/cli/commands/_setup.js +10 -10
- package/dist/cli/commands/dev.js +7 -7
- package/dist/cli/daemon/generate.js +19 -9
- package/dist/cli/daemon/jiti.js +4 -5
- package/dist/cli/daemon/watch.js +3 -2
- package/dist/cli/presets/template.js +1 -1
- package/dist/cli/utils.js +6 -6
- package/dist/cli/wp/bootstrap.js +15 -11
- package/dist/cli/wp/constants.js +1 -1
- package/dist/cli/wp/dev.js +6 -23
- package/dist/cli/wp/types.d.ts +2 -2
- package/dist/cli/wp/utils.d.ts +1 -1
- package/dist/cli/wp/utils.js +1 -1
- package/dist/client.d.ts +7 -7
- package/dist/client.js +1 -1
- package/dist/comment/index.js +2 -2
- package/dist/config.d.ts +8 -8
- package/dist/context.d.ts +5 -5
- package/dist/context.js +5 -5
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- package/dist/integrations/astro/integration.d.ts +12 -0
- package/dist/integrations/astro/integration.js +14 -0
- package/dist/integrations/astro/kizlo.client.d.ts +4 -4
- package/dist/integrations/astro/utils.d.ts +4 -5
- package/dist/integrations/astro/utils.js +5 -6
- package/dist/integrations/nextjs/integration.d.ts +15 -0
- package/dist/integrations/nextjs/integration.js +18 -0
- package/dist/integrations/nextjs/kizlo.client.d.ts +2 -2
- package/dist/integrations/nextjs/revalidate.d.ts +2 -3
- package/dist/integrations/nextjs/revalidate.js +4 -4
- package/dist/integrations/nextjs/utils.js +2 -2
- package/dist/integrations/node/integration.d.ts +12 -0
- package/dist/integrations/node/integration.js +14 -0
- package/dist/integrations/runtime-env.js +25 -0
- package/dist/integrations/tanstack-start/api.d.ts +1 -1
- package/dist/integrations/tanstack-start/integration.d.ts +12 -0
- package/dist/integrations/tanstack-start/integration.js +14 -0
- package/dist/integrations/tanstack-start/kizlo.client.d.ts +4 -4
- package/dist/integrations/tanstack-start/utils.d.ts +1 -1
- package/dist/integrations/tanstack-start/utils.js +3 -3
- package/dist/kizlo.d.ts +33 -70
- package/dist/kizlo.js +91 -75
- package/dist/menu/index.js +2 -2
- package/dist/nextjs/server.d.ts +2 -2
- package/dist/nextjs/server.js +2 -2
- package/dist/node.d.ts +2 -0
- package/dist/node.js +3 -0
- package/dist/package.js +1 -1
- package/dist/page/index.js +2 -2
- package/dist/post/index.js +2 -2
- package/dist/{router.d.ts → procedures.d.ts} +11 -11
- package/dist/procedures.js +23 -0
- package/dist/seo/index.js +2 -2
- package/dist/settings/index.js +2 -2
- package/dist/shared/constants.js +1 -9
- package/dist/shared/contract-generation.js +14 -0
- package/dist/shared/contract.d.ts +2 -2
- package/dist/shared/contract.js +2 -2
- package/dist/shared/integration.d.ts +91 -0
- package/dist/shared/integration.js +59 -0
- package/dist/shared/procedure.d.ts +8 -8
- package/dist/shared/result.d.ts +2 -2
- package/dist/shared/router.d.ts +2 -2
- package/dist/shared/router.js +2 -2
- package/dist/tag/index.js +2 -2
- package/dist/tanstack-start/server.d.ts +2 -2
- package/dist/tanstack-start/server.js +2 -2
- package/package.json +8 -2
- package/dist/integrations/astro/kizlo.server.d.ts +0 -10
- package/dist/integrations/astro/kizlo.server.js +0 -12
- package/dist/integrations/nextjs/kizlo.server.d.ts +0 -11
- package/dist/integrations/nextjs/kizlo.server.js +0 -15
- package/dist/integrations/tanstack-start/kizlo.server.d.ts +0 -14
- package/dist/integrations/tanstack-start/kizlo.server.js +0 -15
- package/dist/router.js +0 -23
- package/dist/shared/extension.d.ts +0 -58
- package/dist/shared/extension.js +0 -37
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPMethod } from "./types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyProcedureTree, InvocationScope } from "./procedure.js";
|
|
3
3
|
import { AnyContractRouter } from "@orpc/contract";
|
|
4
4
|
import { Pathname } from "@kizlo/shared";
|
|
5
5
|
|
|
@@ -15,7 +15,7 @@ type ContractProcedure = {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
declare function isContractProcedure$1(node: unknown): node is ContractProcedure;
|
|
18
|
-
declare function generateContract<
|
|
18
|
+
declare function generateContract<TProcedures extends AnyProcedureTree>(procedures: TProcedures): Promise<Contract>;
|
|
19
19
|
declare function restoreContract(contract: Contract): AnyContractRouter;
|
|
20
20
|
//#endregion
|
|
21
21
|
export { Contract, ContractProcedure, generateContract, isContractProcedure$1 as isContractProcedure, restoreContract };
|
package/dist/shared/contract.js
CHANGED
|
@@ -6,8 +6,8 @@ function isContractProcedure$1(node) {
|
|
|
6
6
|
if (!node || typeof node !== "object") return false;
|
|
7
7
|
return "route" in node || "meta" in node;
|
|
8
8
|
}
|
|
9
|
-
async function generateContract(
|
|
10
|
-
const contract = minifyContractRouter(createOrpcRouter(
|
|
9
|
+
async function generateContract(procedures) {
|
|
10
|
+
const contract = minifyContractRouter(createOrpcRouter(procedures));
|
|
11
11
|
const walk = (node) => {
|
|
12
12
|
const out = {};
|
|
13
13
|
for (const [key, value] of Object.entries(node)) if (isContractProcedure(value)) {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ServiceAdapters } from "../adapters/types.js";
|
|
2
|
+
import { EventHandler } from "../webhook/index.js";
|
|
3
|
+
import { AnyProcedureTree } from "./procedure.js";
|
|
4
|
+
import { IntegrationPluginRequirement, UnionToIntersection } from "@kizlo/shared";
|
|
5
|
+
|
|
6
|
+
//#region src/shared/integration.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What an integration needs to work at all.
|
|
10
|
+
*
|
|
11
|
+
* An integration can ship in two halves that update separately: this package, and the WordPress plugin
|
|
12
|
+
* that serves the endpoints it calls. Environment values and endpoints are checked when the server starts.
|
|
13
|
+
* Plugin versions are checked from the headers WordPress returns.
|
|
14
|
+
*/
|
|
15
|
+
interface IntegrationRequirements {
|
|
16
|
+
/** WordPress plugins serving this integration's endpoints, checked against what the site reports. */
|
|
17
|
+
plugins?: IntegrationPluginRequirement[];
|
|
18
|
+
/** Resolved environment values this integration needs, checked after every integration's `env` contribution is composed. */
|
|
19
|
+
env?: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Endpoint subtrees this integration calls, dotted from the root of the generated tree, e.g.
|
|
22
|
+
* `"woocommerce.store.cart"`. Naming the subtree rather than every leaf keeps this a statement about
|
|
23
|
+
* which contract has to be present, not a second copy of the call sites.
|
|
24
|
+
*/
|
|
25
|
+
endpoints?: string[];
|
|
26
|
+
}
|
|
27
|
+
/** Reads a scalar environment value by name. */
|
|
28
|
+
type EnvReader = (name: string) => string | undefined;
|
|
29
|
+
/** A nested environment record. Leaf values are strings supplied by the owning runtime. */
|
|
30
|
+
interface EnvRecord {
|
|
31
|
+
readonly [name: string]: string | EnvRecord | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** One WordPress connection profile contributed by a runtime integration. */
|
|
34
|
+
interface WordPressEnv extends EnvRecord {
|
|
35
|
+
readonly siteSecret?: string;
|
|
36
|
+
readonly wordpressUrl?: string;
|
|
37
|
+
readonly wordpressUsername?: string;
|
|
38
|
+
readonly wordpressPassword?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Runtime-neutral values Kizlo consumes. Runtime integrations map their environment system onto
|
|
42
|
+
* these camel-case keys. The open string index also lets integrations contribute provider values.
|
|
43
|
+
*/
|
|
44
|
+
interface KizloEnv extends EnvRecord {
|
|
45
|
+
/** Public URL of the mounted Kizlo handler. */
|
|
46
|
+
readonly baseUrl?: string;
|
|
47
|
+
/** WordPress profile to use. Defaults to `remote`. */
|
|
48
|
+
readonly mode?: string;
|
|
49
|
+
/** Values used when `mode` is absent or `remote`. */
|
|
50
|
+
readonly remote?: WordPressEnv;
|
|
51
|
+
/** Values used when `mode` is `local`. */
|
|
52
|
+
readonly local?: WordPressEnv;
|
|
53
|
+
}
|
|
54
|
+
/** Environment values an integration contributes, either as a typed record or a lazy reader. */
|
|
55
|
+
type EnvSource = KizloEnv | EnvReader;
|
|
56
|
+
/** Read one scalar value by dotted path from an environment record or reader. */
|
|
57
|
+
declare function readEnv(source: EnvSource, name: string): string | undefined;
|
|
58
|
+
/** Required environment values the composed source does not provide. */
|
|
59
|
+
declare function missingEnv(source: EnvSource, required: readonly string[]): string[];
|
|
60
|
+
interface Integration<TId extends string, TProcedures extends AnyProcedureTree = Record<never, never>> {
|
|
61
|
+
id: TId;
|
|
62
|
+
/** Procedures the integration exposes. Each entry or nested group becomes a client method under its `id`. */
|
|
63
|
+
procedures?: TProcedures;
|
|
64
|
+
/** Webhook event handlers, built with `createEventHandler`, run when WordPress emits a matching event. */
|
|
65
|
+
events?: EventHandler[];
|
|
66
|
+
/** Auth, captcha, geo, logger, or cookies adapters the integration supplies. */
|
|
67
|
+
adapters?: ServiceAdapters;
|
|
68
|
+
/** Runtime-neutral environment values the integration contributes. Later concrete values replace earlier ones. */
|
|
69
|
+
env?: EnvSource;
|
|
70
|
+
/** Environment, endpoint, and WordPress plugin requirements checked at their documented lifecycle points. */
|
|
71
|
+
requires?: IntegrationRequirements;
|
|
72
|
+
}
|
|
73
|
+
type AnyIntegration = Integration<any, AnyProcedureTree>;
|
|
74
|
+
type ExtractIntegrationProcedures<TIntegration extends AnyIntegration> = TIntegration extends Integration<infer Name, infer Procedures> ? [keyof Procedures] extends [never] ? never : string extends keyof Procedures ? never : Record<Name, Procedures> : never;
|
|
75
|
+
type InferIntegrationProcedures<TIntegrations extends readonly AnyIntegration[]> = TIntegrations extends readonly [] ? Record<never, never> : ExtractIntegrationProcedures<TIntegrations[number]> extends infer R ? [R] extends [never] ? Record<never, never> : UnionToIntersection<R> : never;
|
|
76
|
+
declare function createIntegration<TId extends string, TProcedures extends AnyProcedureTree = Record<never, never>>(integration: Integration<TId, TProcedures>): Integration<TId, TProcedures>;
|
|
77
|
+
/** The declared subtrees the generated tree does not have. */
|
|
78
|
+
declare function missingEndpoints(endpoints: object, required: readonly string[]): string[];
|
|
79
|
+
/**
|
|
80
|
+
* Fail at startup when an integration's endpoints are not in the generated tree, naming the plugins that
|
|
81
|
+
* would have put them there.
|
|
82
|
+
*
|
|
83
|
+
* Absent endpoints mean the WordPress half is missing, too old to describe its routes, or the tree was
|
|
84
|
+
* generated against a different WordPress. Left alone it surfaces as a property access on `undefined`
|
|
85
|
+
* inside whichever procedure ran first, which says nothing about any of that.
|
|
86
|
+
*/
|
|
87
|
+
declare function assertIntegrationEndpoints(integration: AnyIntegration, endpoints: object): void;
|
|
88
|
+
/** Fail at startup when an integration's required environment values are absent. */
|
|
89
|
+
declare function assertIntegrationEnv(integration: AnyIntegration, env: EnvSource): void;
|
|
90
|
+
//#endregion
|
|
91
|
+
export { AnyIntegration, EnvReader, EnvRecord, EnvSource, ExtractIntegrationProcedures, InferIntegrationProcedures, Integration, IntegrationRequirements, KizloEnv, WordPressEnv, assertIntegrationEndpoints, assertIntegrationEnv, createIntegration, missingEndpoints, missingEnv, readEnv };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { KizloError } from "./error.js";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/integration.ts
|
|
4
|
+
/** Read one scalar value by dotted path from an environment record or reader. */
|
|
5
|
+
function readEnv(source, name) {
|
|
6
|
+
if (typeof source === "function") return source(name);
|
|
7
|
+
let value = source;
|
|
8
|
+
for (const segment of name.split(".")) {
|
|
9
|
+
if (!value || typeof value === "string") return void 0;
|
|
10
|
+
value = value[segment];
|
|
11
|
+
}
|
|
12
|
+
return typeof value === "string" ? value : void 0;
|
|
13
|
+
}
|
|
14
|
+
/** Required environment values the composed source does not provide. */
|
|
15
|
+
function missingEnv(source, required) {
|
|
16
|
+
return required.filter((name) => !readEnv(source, name)?.trim());
|
|
17
|
+
}
|
|
18
|
+
function createIntegration(integration) {
|
|
19
|
+
return integration;
|
|
20
|
+
}
|
|
21
|
+
/** The declared subtrees the generated tree does not have. */
|
|
22
|
+
function missingEndpoints(endpoints, required) {
|
|
23
|
+
return required.filter((path) => {
|
|
24
|
+
let node = endpoints;
|
|
25
|
+
for (const key of path.split(".")) {
|
|
26
|
+
if (node === null || typeof node !== "object" || !(key in node)) return true;
|
|
27
|
+
node = node[key];
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fail at startup when an integration's endpoints are not in the generated tree, naming the plugins that
|
|
34
|
+
* would have put them there.
|
|
35
|
+
*
|
|
36
|
+
* Absent endpoints mean the WordPress half is missing, too old to describe its routes, or the tree was
|
|
37
|
+
* generated against a different WordPress. Left alone it surfaces as a property access on `undefined`
|
|
38
|
+
* inside whichever procedure ran first, which says nothing about any of that.
|
|
39
|
+
*/
|
|
40
|
+
function assertIntegrationEndpoints(integration, endpoints) {
|
|
41
|
+
const required = integration.requires?.endpoints;
|
|
42
|
+
if (!required?.length) return;
|
|
43
|
+
const missing = missingEndpoints(endpoints, required);
|
|
44
|
+
if (missing.length === 0) return;
|
|
45
|
+
const plugins = integration.requires?.plugins;
|
|
46
|
+
const remedy = plugins?.length ? `Install or update the required WordPress plugins (${plugins.map((plugin) => `${plugin.name} ${plugin.version}+`).join(", ")}), then run \`kizlo generate\`.` : "Run `kizlo generate` against a WordPress that serves them.";
|
|
47
|
+
throw new KizloError("MISSING_WORDPRESS_ENDPOINTS", { message: `The "${integration.id}" integration needs WordPress endpoints your generated client does not have: ${missing.join(", ")}. ${remedy}` });
|
|
48
|
+
}
|
|
49
|
+
/** Fail at startup when an integration's required environment values are absent. */
|
|
50
|
+
function assertIntegrationEnv(integration, env) {
|
|
51
|
+
const required = integration.requires?.env;
|
|
52
|
+
if (!required?.length) return;
|
|
53
|
+
const missing = missingEnv(env, required);
|
|
54
|
+
if (missing.length === 0) return;
|
|
55
|
+
throw new KizloError("MISSING_ENV_VALUE", { message: `The "${integration.id}" integration requires environment values that are missing: ${missing.join(", ")}.` });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { assertIntegrationEndpoints, assertIntegrationEnv, createIntegration, missingEndpoints, missingEnv, readEnv };
|
|
@@ -8,18 +8,18 @@ import { HTTPMethod } from "@orpc/server";
|
|
|
8
8
|
import { JsonifiedValue } from "@orpc/openapi-client";
|
|
9
9
|
|
|
10
10
|
//#region src/shared/procedure.d.ts
|
|
11
|
-
type
|
|
12
|
-
[K: string]: AnyProcedure |
|
|
11
|
+
type AnyProcedureTree = {
|
|
12
|
+
[K: string]: AnyProcedure | AnyProcedureTree;
|
|
13
13
|
};
|
|
14
|
-
type
|
|
15
|
-
type ExtractProcedureByScope<
|
|
14
|
+
type ProcedureTreeDepthTuple = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
15
|
+
type ExtractProcedureByScope<TProcedures extends AnyProcedureTree, TScope extends InvocationScope, TDepth extends number = 10> = TDepth extends 0 ? TProcedures : { [K in keyof TProcedures as TProcedures[K] extends Procedure<infer Scope, infer _Input, infer _Output, infer _Errors> ? Scope extends TScope ? K : never : TProcedures[K] extends AnyProcedureTree ? keyof ExtractProcedureByScope<TProcedures[K], TScope, ProcedureTreeDepthTuple[TDepth]> extends never ? never : K : never]: TProcedures[K] extends AnyProcedure ? TProcedures[K] : TProcedures[K] extends AnyProcedureTree ? ExtractProcedureByScope<TProcedures[K], TScope, ProcedureTreeDepthTuple[TDepth]> : never };
|
|
16
16
|
/** The base options passed to every procedure handler and middleware. */
|
|
17
17
|
interface BaseHandlerOptions<TInput, TContext, TError extends DefinedErrorMapLike> {
|
|
18
18
|
/** The validated, typed request. For `api`, the merged `{ params, query, body, headers }`; for `remote`/`internal`, the `input` schema's type. */
|
|
19
19
|
input: TInput;
|
|
20
|
-
/** Server-side services and adapters
|
|
20
|
+
/** Server-side services and adapters, including the WordPress client, logger, cookies, and auth, plus anything middleware adds. */
|
|
21
21
|
context: TContext;
|
|
22
|
-
/** Typed error map
|
|
22
|
+
/** Typed error map. Throw `errors.SOME_CODE()` for a known failure. */
|
|
23
23
|
errors: ProcedureErrors<TError>;
|
|
24
24
|
}
|
|
25
25
|
type InvocationScope = "internal" | "remote" | "api";
|
|
@@ -74,7 +74,7 @@ type ProcedureOptions<TScope extends InvocationScope, TPathname extends Pathname
|
|
|
74
74
|
scope: TScope;
|
|
75
75
|
/** Error codes this procedure can throw, on top of the built-in common HTTP errors. An inline object or a `defineErrorMap`. */
|
|
76
76
|
errors?: TError;
|
|
77
|
-
/** Schema that types
|
|
77
|
+
/** Schema that types the handler's return value and validates it when `outputValidation` is on. */
|
|
78
78
|
output: TOutput;
|
|
79
79
|
/** Middleware to run before the handler, in declaration order. */
|
|
80
80
|
middlewares?: TMiddlewares;
|
|
@@ -116,4 +116,4 @@ declare function buildProcedure(procedure: AnyProcedure): _orpc_server0.Decorate
|
|
|
116
116
|
declare function handleUnexpectedError(error: unknown, errors?: DefinedErrorMapLike): never;
|
|
117
117
|
declare function combineDetailed(parts: Record<string, Schema>): Schema;
|
|
118
118
|
//#endregion
|
|
119
|
-
export { AnyProcedure,
|
|
119
|
+
export { AnyProcedure, AnyProcedureTree, BaseHandlerOptions, ExtractParams, ExtractProcedureByScope, InvocationScope, OpenapiPart, Procedure, ProcedureErrors, ProcedureHandler, ProcedureOptions, ProcedureTreeDepthTuple, ResolveParamsPart, ResolvedSchemaInput, ResolvedSchemaOutput, SchemaIO, buildProcedure, combineDetailed, createProcedure, handleUnexpectedError, schemaType };
|
package/dist/shared/result.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DefinedErrorMapLike, KizloError, WithCommonErrorMap } from "./error.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyProcedureTree, Procedure } from "./procedure.js";
|
|
3
3
|
import { NestedClient } from "@orpc/client";
|
|
4
4
|
import { SchemaOutput } from "@kizlo/shared";
|
|
5
5
|
|
|
@@ -19,6 +19,6 @@ type KizloResult<TOutput, TErrors extends DefinedErrorMapLike = DefinedErrorMapL
|
|
|
19
19
|
error: KizloErrorUnion<WithCommonErrorMap<TErrors>>;
|
|
20
20
|
success: false;
|
|
21
21
|
};
|
|
22
|
-
type ResultClient<T extends
|
|
22
|
+
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 };
|
|
23
23
|
//#endregion
|
|
24
24
|
export { ResultClient };
|
package/dist/shared/router.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyProcedureTree } from "./procedure.js";
|
|
2
2
|
import { AnyRouter } from "@orpc/server";
|
|
3
3
|
|
|
4
4
|
//#region src/shared/router.d.ts
|
|
5
|
-
declare function createOrpcRouter(
|
|
5
|
+
declare function createOrpcRouter(procedures: AnyProcedureTree): AnyRouter;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { createOrpcRouter };
|
package/dist/shared/router.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { buildProcedure } from "./procedure.js";
|
|
2
2
|
|
|
3
3
|
//#region src/shared/router.ts
|
|
4
|
-
function createOrpcRouter(
|
|
4
|
+
function createOrpcRouter(procedures) {
|
|
5
5
|
const cache = /* @__PURE__ */ new Map();
|
|
6
|
-
return new Proxy(
|
|
6
|
+
return new Proxy(procedures, { get: (target, p) => {
|
|
7
7
|
if (typeof p === "symbol") return target[p];
|
|
8
8
|
if (cache.has(p)) return cache.get(p);
|
|
9
9
|
const value = target[p];
|
package/dist/tag/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { deserializeTag } from "./utils.js";
|
|
|
7
7
|
import { normalizeArrayableValue } from "@kizlo/shared";
|
|
8
8
|
|
|
9
9
|
//#region src/tag/index.ts
|
|
10
|
-
const
|
|
10
|
+
const TAG_PROCEDURES = {
|
|
11
11
|
get: createProcedure({
|
|
12
12
|
scope: "api",
|
|
13
13
|
method: "GET",
|
|
@@ -73,4 +73,4 @@ const TAG_ROUTER_MAP = {
|
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
//#endregion
|
|
76
|
-
export {
|
|
76
|
+
export { TAG_PROCEDURES };
|
|
@@ -3,9 +3,9 @@ import { renderJsonLd } from "../seo/utils.js";
|
|
|
3
3
|
import { LinkDescriptor, MetaDescriptor, RouteHead, ScriptDescriptor, resolvePageHead } from "../integrations/tanstack-start/metadata.js";
|
|
4
4
|
import { ServerRoute, ServerRouteContext, getServerBaseUrl } from "../integrations/tanstack-start/utils.js";
|
|
5
5
|
import { ApiHandlers, KizloHandler, createApiHandlers } from "../integrations/tanstack-start/api.js";
|
|
6
|
-
import {
|
|
6
|
+
import { TanstackStartOptions, tanstackStart } from "../integrations/tanstack-start/integration.js";
|
|
7
7
|
import { createManifestRoute } from "../integrations/tanstack-start/manifest.js";
|
|
8
8
|
import { createRobotsRoute } from "../integrations/tanstack-start/robots.js";
|
|
9
9
|
import { resolveRootHead } from "../integrations/tanstack-start/root-head.js";
|
|
10
10
|
import { createSitemapRedirectRoute, createSitemapRoute } from "../integrations/tanstack-start/sitemap.js";
|
|
11
|
-
export { ApiHandlers, KizloHandler,
|
|
11
|
+
export { ApiHandlers, KizloHandler, LinkDescriptor, MetaDescriptor, RouteHead, ScriptDescriptor, ServerRoute, ServerRouteContext, TanstackStartOptions, WEB_MANIFEST_ROUTE, createApiHandlers, createManifestRoute, createRobotsRoute, createSitemapRedirectRoute, createSitemapRoute, getServerBaseUrl, renderJsonLd, resolvePageHead, resolveRootHead, tanstackStart };
|
|
@@ -3,10 +3,10 @@ import { renderJsonLd } from "../seo/utils.js";
|
|
|
3
3
|
import { getServerBaseUrl } from "../integrations/tanstack-start/utils.js";
|
|
4
4
|
import { resolvePageHead } from "../integrations/tanstack-start/metadata.js";
|
|
5
5
|
import { createApiHandlers } from "../integrations/tanstack-start/api.js";
|
|
6
|
-
import {
|
|
6
|
+
import { tanstackStart } from "../integrations/tanstack-start/integration.js";
|
|
7
7
|
import { createManifestRoute } from "../integrations/tanstack-start/manifest.js";
|
|
8
8
|
import { createRobotsRoute } from "../integrations/tanstack-start/robots.js";
|
|
9
9
|
import { resolveRootHead } from "../integrations/tanstack-start/root-head.js";
|
|
10
10
|
import { createSitemapRedirectRoute, createSitemapRoute } from "../integrations/tanstack-start/sitemap.js";
|
|
11
11
|
|
|
12
|
-
export { WEB_MANIFEST_ROUTE, createApiHandlers,
|
|
12
|
+
export { WEB_MANIFEST_ROUTE, createApiHandlers, createManifestRoute, createRobotsRoute, createSitemapRedirectRoute, createSitemapRoute, getServerBaseUrl, renderJsonLd, resolvePageHead, resolveRootHead, tanstackStart };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kizlo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A headless WordPress framework for TypeScript.",
|
|
6
6
|
"keywords": [
|
|
@@ -52,6 +52,12 @@
|
|
|
52
52
|
"default": "./dist/test.js"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
+
"./node": {
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./dist/node.d.ts",
|
|
58
|
+
"default": "./dist/node.js"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
55
61
|
"./nextjs": {
|
|
56
62
|
"import": {
|
|
57
63
|
"types": "./dist/nextjs.d.ts",
|
|
@@ -100,7 +106,7 @@
|
|
|
100
106
|
},
|
|
101
107
|
"dependencies": {
|
|
102
108
|
"@clack/prompts": "^1.5.1",
|
|
103
|
-
"@kizlo/shared": "0.
|
|
109
|
+
"@kizlo/shared": "0.8.0",
|
|
104
110
|
"@orpc/client": "^1.14.3",
|
|
105
111
|
"@orpc/contract": "^1.14.3",
|
|
106
112
|
"@orpc/openapi": "^1.14.3",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AnyExtension } from "../../shared/extension.js";
|
|
2
|
-
import { CreateKizloOptions, EnvReader, Kizlo } from "../../kizlo.js";
|
|
3
|
-
|
|
4
|
-
//#region src/integrations/astro/kizlo.server.d.ts
|
|
5
|
-
type KizloServerOptions<TExts extends readonly AnyExtension[] = []> = CreateKizloOptions<TExts> & {
|
|
6
|
-
getSecret: EnvReader;
|
|
7
|
-
};
|
|
8
|
-
declare function createKizlo<TExts extends readonly AnyExtension[] = []>(options: KizloServerOptions<TExts>): Kizlo<TExts>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { KizloServerOptions, createKizlo };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Kizlo, resolveKizloConfig } from "../../kizlo.js";
|
|
2
|
-
|
|
3
|
-
//#region src/integrations/astro/kizlo.server.ts
|
|
4
|
-
function createKizlo(options) {
|
|
5
|
-
return new Kizlo(resolveKizloConfig(options, {
|
|
6
|
-
baseUrlEnvKey: "PUBLIC_KIZLO_API_URL",
|
|
7
|
-
env: options?.getSecret
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { createKizlo };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AnyExtension } from "../../shared/extension.js";
|
|
2
|
-
import { CreateKizloOptions, Kizlo } from "../../kizlo.js";
|
|
3
|
-
import { NextRevalidateOptions } from "./revalidate.js";
|
|
4
|
-
|
|
5
|
-
//#region src/integrations/nextjs/kizlo.server.d.ts
|
|
6
|
-
type KizloServerOptions<TExts extends readonly AnyExtension[] = []> = CreateKizloOptions<TExts> & {
|
|
7
|
-
revalidate?: boolean | NextRevalidateOptions;
|
|
8
|
-
};
|
|
9
|
-
declare function createKizlo<TExts extends readonly AnyExtension[] = []>(options?: KizloServerOptions<TExts>): Kizlo<TExts>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { KizloServerOptions, createKizlo };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Kizlo, resolveKizloConfig } from "../../kizlo.js";
|
|
2
|
-
import { nextRevalidation } from "./revalidate.js";
|
|
3
|
-
|
|
4
|
-
//#region src/integrations/nextjs/kizlo.server.ts
|
|
5
|
-
function createKizlo(options) {
|
|
6
|
-
const revalidate = options?.revalidate;
|
|
7
|
-
const extensions = [...revalidate === false ? [] : [nextRevalidation(typeof revalidate === "object" ? revalidate : void 0)], ...options?.extensions ?? []];
|
|
8
|
-
return new Kizlo(resolveKizloConfig({
|
|
9
|
-
...options,
|
|
10
|
-
extensions
|
|
11
|
-
}, { baseUrlEnvKey: "NEXT_PUBLIC_KIZLO_API_URL" }));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { createKizlo };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AnyExtension } from "../../shared/extension.js";
|
|
2
|
-
import { CreateKizloOptions, Kizlo } from "../../kizlo.js";
|
|
3
|
-
|
|
4
|
-
//#region src/integrations/tanstack-start/kizlo.server.d.ts
|
|
5
|
-
type KizloServerOptions<TExts extends readonly AnyExtension[] = []> = CreateKizloOptions<TExts>;
|
|
6
|
-
/**
|
|
7
|
-
* The server-to-server Kizlo instance for a TanStack Start app. Reads env through `process.env` (the
|
|
8
|
-
* Nitro/Node server runtime TanStack Start builds on), resolving the public API base URL from
|
|
9
|
-
* `VITE_KIZLO_API_URL`. Used only server-side — server routes and server functions — so it never
|
|
10
|
-
* reaches the browser bundle.
|
|
11
|
-
*/
|
|
12
|
-
declare function createKizlo<TExts extends readonly AnyExtension[] = []>(options?: KizloServerOptions<TExts>): Kizlo<TExts>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { KizloServerOptions, createKizlo };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Kizlo, resolveKizloConfig } from "../../kizlo.js";
|
|
2
|
-
|
|
3
|
-
//#region src/integrations/tanstack-start/kizlo.server.ts
|
|
4
|
-
/**
|
|
5
|
-
* The server-to-server Kizlo instance for a TanStack Start app. Reads env through `process.env` (the
|
|
6
|
-
* Nitro/Node server runtime TanStack Start builds on), resolving the public API base URL from
|
|
7
|
-
* `VITE_KIZLO_API_URL`. Used only server-side — server routes and server functions — so it never
|
|
8
|
-
* reaches the browser bundle.
|
|
9
|
-
*/
|
|
10
|
-
function createKizlo(options) {
|
|
11
|
-
return new Kizlo(resolveKizloConfig(options, { baseUrlEnvKey: "VITE_KIZLO_API_URL" }));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { createKizlo };
|
package/dist/router.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { CATEGORY_ROUTER_MAP } from "./category/index.js";
|
|
2
|
-
import { COMMENT_ROUTER_MAP } from "./comment/index.js";
|
|
3
|
-
import { MENU_ROUTER_MAP } from "./menu/index.js";
|
|
4
|
-
import { PAGE_ROUTER_MAP } from "./page/index.js";
|
|
5
|
-
import { POST_ROUTER_MAP } from "./post/index.js";
|
|
6
|
-
import { SEO_ROUTER_MAP } from "./seo/index.js";
|
|
7
|
-
import { SETTINGS_ROUTER_MAP } from "./settings/index.js";
|
|
8
|
-
import { TAG_ROUTER_MAP } from "./tag/index.js";
|
|
9
|
-
|
|
10
|
-
//#region src/router.ts
|
|
11
|
-
const ROUTER_MAP = {
|
|
12
|
-
posts: POST_ROUTER_MAP,
|
|
13
|
-
pages: PAGE_ROUTER_MAP,
|
|
14
|
-
categories: CATEGORY_ROUTER_MAP,
|
|
15
|
-
tags: TAG_ROUTER_MAP,
|
|
16
|
-
seo: SEO_ROUTER_MAP,
|
|
17
|
-
menus: MENU_ROUTER_MAP,
|
|
18
|
-
comments: COMMENT_ROUTER_MAP,
|
|
19
|
-
settings: SETTINGS_ROUTER_MAP
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
export { ROUTER_MAP };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { EventHandler } from "../webhook/index.js";
|
|
2
|
-
import { AnyProcedureRouter } from "./procedure.js";
|
|
3
|
-
import { ExtensionPluginRequirement, UnionToIntersection } from "@kizlo/shared";
|
|
4
|
-
|
|
5
|
-
//#region src/shared/extension.d.ts
|
|
6
|
-
interface ExtensionInitOptions {
|
|
7
|
-
context: {
|
|
8
|
-
something: string;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* What an extension needs from WordPress to work at all.
|
|
13
|
-
*
|
|
14
|
-
* An extension ships in two halves that update separately: this package, and the WordPress plugin that
|
|
15
|
-
* serves the endpoints it calls. Neither half can see the other's version through npm, so an extension
|
|
16
|
-
* says here what it is calling, and Kizlo checks it once at startup rather than letting the first
|
|
17
|
-
* request fail somewhere inside a procedure.
|
|
18
|
-
*/
|
|
19
|
-
interface ExtensionRequirements {
|
|
20
|
-
/** The WordPress plugin serving this extension's endpoints, checked against what the site reports. */
|
|
21
|
-
plugin?: ExtensionPluginRequirement;
|
|
22
|
-
/**
|
|
23
|
-
* Endpoint subtrees this extension calls, dotted from the root of the generated tree, e.g.
|
|
24
|
-
* `"woocommerce.store.cart"`. Naming the subtree rather than every leaf keeps this a statement about
|
|
25
|
-
* which contract has to be present, not a second copy of the call sites.
|
|
26
|
-
*/
|
|
27
|
-
endpoints?: string[];
|
|
28
|
-
}
|
|
29
|
-
interface ExtensionInitResult<TRouter extends AnyProcedureRouter> {
|
|
30
|
-
/** Procedures the extension exposes, grouped by name. Each entry (or nested group) becomes a client method under the extension's `id`. */
|
|
31
|
-
router?: TRouter;
|
|
32
|
-
/** Webhook event handlers, built with `createEventHandler`, run when WordPress emits a matching event. */
|
|
33
|
-
events?: EventHandler[];
|
|
34
|
-
}
|
|
35
|
-
interface Extension<TId extends string, TRouter extends AnyProcedureRouter> {
|
|
36
|
-
id: TId;
|
|
37
|
-
init: ExtensionInitFn<TRouter>;
|
|
38
|
-
/** What this extension needs from WordPress. Checked when the server is created. */
|
|
39
|
-
requires?: ExtensionRequirements;
|
|
40
|
-
}
|
|
41
|
-
type AnyExtension = Extension<any, AnyProcedureRouter>;
|
|
42
|
-
type ExtensionInitFn<TRouter extends AnyProcedureRouter> = (context: ExtensionInitOptions) => ExtensionInitResult<TRouter>;
|
|
43
|
-
type ExtractExtensionRouter<TExt extends AnyExtension> = TExt extends Extension<infer Name, infer Router> ? [keyof Router] extends [never] ? never : string extends keyof Router ? never : Record<Name, Router> : never;
|
|
44
|
-
type InferExtensionRouter<TExt extends readonly AnyExtension[]> = TExt extends readonly [] ? Record<never, never> : ExtractExtensionRouter<TExt[number]> extends infer R ? [R] extends [never] ? Record<never, never> : UnionToIntersection<R> : never;
|
|
45
|
-
declare function createExtension<TId extends string, TRouter extends AnyProcedureRouter = AnyProcedureRouter>(extension: Extension<TId, TRouter>): Extension<TId, TRouter>;
|
|
46
|
-
/** The declared subtrees the generated tree does not have. */
|
|
47
|
-
declare function missingEndpoints(endpoints: object, required: readonly string[]): string[];
|
|
48
|
-
/**
|
|
49
|
-
* Fail at startup when an extension's endpoints are not in the generated tree, naming the plugin that
|
|
50
|
-
* would have put them there.
|
|
51
|
-
*
|
|
52
|
-
* Absent endpoints mean the WordPress half is missing, too old to describe its routes, or the tree was
|
|
53
|
-
* generated against a different WordPress. Left alone it surfaces as a property access on `undefined`
|
|
54
|
-
* inside whichever procedure ran first, which says nothing about any of that.
|
|
55
|
-
*/
|
|
56
|
-
declare function assertExtensionEndpoints(extension: AnyExtension, endpoints: object): void;
|
|
57
|
-
//#endregion
|
|
58
|
-
export { AnyExtension, Extension, ExtensionInitFn, ExtensionInitOptions, ExtensionInitResult, ExtensionRequirements, ExtractExtensionRouter, InferExtensionRouter, assertExtensionEndpoints, createExtension, missingEndpoints };
|
package/dist/shared/extension.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { KizloError } from "./error.js";
|
|
2
|
-
|
|
3
|
-
//#region src/shared/extension.ts
|
|
4
|
-
function createExtension(extension) {
|
|
5
|
-
return extension;
|
|
6
|
-
}
|
|
7
|
-
/** The declared subtrees the generated tree does not have. */
|
|
8
|
-
function missingEndpoints(endpoints, required) {
|
|
9
|
-
return required.filter((path) => {
|
|
10
|
-
let node = endpoints;
|
|
11
|
-
for (const key of path.split(".")) {
|
|
12
|
-
if (node === null || typeof node !== "object" || !(key in node)) return true;
|
|
13
|
-
node = node[key];
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Fail at startup when an extension's endpoints are not in the generated tree, naming the plugin that
|
|
20
|
-
* would have put them there.
|
|
21
|
-
*
|
|
22
|
-
* Absent endpoints mean the WordPress half is missing, too old to describe its routes, or the tree was
|
|
23
|
-
* generated against a different WordPress. Left alone it surfaces as a property access on `undefined`
|
|
24
|
-
* inside whichever procedure ran first, which says nothing about any of that.
|
|
25
|
-
*/
|
|
26
|
-
function assertExtensionEndpoints(extension, endpoints) {
|
|
27
|
-
const required = extension.requires?.endpoints;
|
|
28
|
-
if (!required?.length) return;
|
|
29
|
-
const missing = missingEndpoints(endpoints, required);
|
|
30
|
-
if (missing.length === 0) return;
|
|
31
|
-
const plugin = extension.requires?.plugin;
|
|
32
|
-
const remedy = plugin ? `Install or update the ${plugin.name} WordPress plugin (${plugin.version}+), then run \`kizlo generate\`.` : "Run `kizlo generate` against a WordPress that serves them.";
|
|
33
|
-
throw new KizloError("MISSING_WORDPRESS_ENDPOINTS", { message: `The "${extension.id}" extension needs WordPress endpoints your generated client does not have: ${missing.join(", ")}. ${remedy}` });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
export { assertExtensionEndpoints, createExtension, missingEndpoints };
|