kizlo 0.15.2 → 0.17.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.
Files changed (98) hide show
  1. package/dist/adapters/logger.d.ts +2 -5
  2. package/dist/adapters/logger.js +1 -1
  3. package/dist/adapters/types.d.ts +19 -0
  4. package/dist/adapters/types.js +17 -0
  5. package/dist/astro/server.d.ts +2 -2
  6. package/dist/astro/server.js +2 -2
  7. package/dist/category/index.js +2 -2
  8. package/dist/category/schema.js +2 -1
  9. package/dist/category/utils.js +1 -0
  10. package/dist/cli/commands/_setup.js +10 -10
  11. package/dist/cli/commands/dev.js +7 -7
  12. package/dist/cli/daemon/generate.js +19 -9
  13. package/dist/cli/daemon/jiti.js +4 -5
  14. package/dist/cli/daemon/watch.js +3 -2
  15. package/dist/cli/presets/template.js +1 -1
  16. package/dist/cli/utils.js +6 -6
  17. package/dist/cli/wp/bootstrap.js +15 -11
  18. package/dist/cli/wp/constants.js +1 -1
  19. package/dist/cli/wp/dev.js +6 -23
  20. package/dist/cli/wp/types.d.ts +2 -2
  21. package/dist/cli/wp/utils.d.ts +1 -1
  22. package/dist/cli/wp/utils.js +1 -1
  23. package/dist/client.d.ts +7 -7
  24. package/dist/client.js +1 -1
  25. package/dist/comment/index.js +2 -2
  26. package/dist/comment/schema.js +3 -3
  27. package/dist/comment/utils.js +4 -14
  28. package/dist/config.d.ts +8 -8
  29. package/dist/context.d.ts +5 -5
  30. package/dist/context.js +5 -5
  31. package/dist/index.d.ts +8 -7
  32. package/dist/index.js +6 -5
  33. package/dist/integrations/astro/integration.d.ts +12 -0
  34. package/dist/integrations/astro/integration.js +14 -0
  35. package/dist/integrations/astro/kizlo.client.d.ts +4 -4
  36. package/dist/integrations/astro/utils.d.ts +4 -5
  37. package/dist/integrations/astro/utils.js +5 -6
  38. package/dist/integrations/nextjs/integration.d.ts +15 -0
  39. package/dist/integrations/nextjs/integration.js +18 -0
  40. package/dist/integrations/nextjs/kizlo.client.d.ts +2 -2
  41. package/dist/integrations/nextjs/revalidate.d.ts +2 -3
  42. package/dist/integrations/nextjs/revalidate.js +4 -4
  43. package/dist/integrations/nextjs/utils.js +2 -2
  44. package/dist/integrations/node/integration.d.ts +12 -0
  45. package/dist/integrations/node/integration.js +14 -0
  46. package/dist/integrations/runtime-env.js +25 -0
  47. package/dist/integrations/tanstack-start/api.d.ts +1 -1
  48. package/dist/integrations/tanstack-start/integration.d.ts +12 -0
  49. package/dist/integrations/tanstack-start/integration.js +14 -0
  50. package/dist/integrations/tanstack-start/kizlo.client.d.ts +4 -4
  51. package/dist/integrations/tanstack-start/utils.d.ts +1 -1
  52. package/dist/integrations/tanstack-start/utils.js +3 -3
  53. package/dist/kizlo.d.ts +33 -70
  54. package/dist/kizlo.js +91 -75
  55. package/dist/menu/index.js +2 -2
  56. package/dist/nextjs/server.d.ts +2 -2
  57. package/dist/nextjs/server.js +2 -2
  58. package/dist/node.d.ts +2 -0
  59. package/dist/node.js +3 -0
  60. package/dist/package.js +1 -1
  61. package/dist/page/index.js +2 -2
  62. package/dist/page/schema.js +5 -4
  63. package/dist/page/utils.js +5 -9
  64. package/dist/post/index.js +2 -2
  65. package/dist/post/schema.js +5 -4
  66. package/dist/post/utils.js +5 -9
  67. package/dist/{router.d.ts → procedures.d.ts} +42 -125
  68. package/dist/procedures.js +23 -0
  69. package/dist/seo/index.js +2 -2
  70. package/dist/seo/schema.d.ts +5 -5
  71. package/dist/settings/index.js +2 -2
  72. package/dist/shared/constants.js +1 -9
  73. package/dist/shared/contract-generation.js +14 -0
  74. package/dist/shared/contract.d.ts +2 -2
  75. package/dist/shared/contract.js +2 -2
  76. package/dist/shared/integration.d.ts +91 -0
  77. package/dist/shared/integration.js +59 -0
  78. package/dist/shared/procedure.d.ts +8 -8
  79. package/dist/shared/result.d.ts +2 -2
  80. package/dist/shared/router.d.ts +2 -2
  81. package/dist/shared/router.js +2 -2
  82. package/dist/shared/schema.d.ts +3 -1
  83. package/dist/shared/schema.js +3 -1
  84. package/dist/tag/index.js +2 -2
  85. package/dist/tag/schema.js +2 -1
  86. package/dist/tag/utils.js +1 -0
  87. package/dist/tanstack-start/server.d.ts +2 -2
  88. package/dist/tanstack-start/server.js +2 -2
  89. package/package.json +8 -2
  90. package/dist/integrations/astro/kizlo.server.d.ts +0 -10
  91. package/dist/integrations/astro/kizlo.server.js +0 -12
  92. package/dist/integrations/nextjs/kizlo.server.d.ts +0 -11
  93. package/dist/integrations/nextjs/kizlo.server.js +0 -15
  94. package/dist/integrations/tanstack-start/kizlo.server.d.ts +0 -14
  95. package/dist/integrations/tanstack-start/kizlo.server.js +0 -15
  96. package/dist/router.js +0 -23
  97. package/dist/shared/extension.d.ts +0 -58
  98. package/dist/shared/extension.js +0 -37
@@ -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 AnyProcedureRouter = {
12
- [K: string]: AnyProcedure | AnyProcedureRouter;
11
+ type AnyProcedureTree = {
12
+ [K: string]: AnyProcedure | AnyProcedureTree;
13
13
  };
14
- type RouterDepthTuple = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
15
- type ExtractProcedureByScope<TRouter extends AnyProcedureRouter, TScope extends InvocationScope, TDepth extends number = 10> = TDepth extends 0 ? TRouter : { [K in keyof TRouter as TRouter[K] extends Procedure<infer Scope, infer _Input, infer _Output, infer _Errors> ? Scope extends TScope ? K : never : TRouter[K] extends AnyProcedureRouter ? keyof ExtractProcedureByScope<TRouter[K], TScope, RouterDepthTuple[TDepth]> extends never ? never : K : never]: TRouter[K] extends AnyProcedure ? TRouter[K] : TRouter[K] extends AnyProcedureRouter ? ExtractProcedureByScope<TRouter[K], TScope, RouterDepthTuple[TDepth]> : never };
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 — the WordPress client, logger, cookies, auth, and more — plus anything middleware adds. */
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 — throw `errors.SOME_CODE()` for a known failure. */
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 — and, when `outputValidation` is on, validates — the handler's return value. */
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, AnyProcedureRouter, BaseHandlerOptions, ExtractParams, ExtractProcedureByScope, InvocationScope, OpenapiPart, Procedure, ProcedureErrors, ProcedureHandler, ProcedureOptions, ResolveParamsPart, ResolvedSchemaInput, ResolvedSchemaOutput, RouterDepthTuple, SchemaIO, buildProcedure, combineDetailed, createProcedure, handleUnexpectedError, schemaType };
119
+ export { AnyProcedure, AnyProcedureTree, BaseHandlerOptions, ExtractParams, ExtractProcedureByScope, InvocationScope, OpenapiPart, Procedure, ProcedureErrors, ProcedureHandler, ProcedureOptions, ProcedureTreeDepthTuple, ResolveParamsPart, ResolvedSchemaInput, ResolvedSchemaOutput, SchemaIO, buildProcedure, combineDetailed, createProcedure, handleUnexpectedError, schemaType };
@@ -1,5 +1,5 @@
1
1
  import { DefinedErrorMapLike, KizloError, WithCommonErrorMap } from "./error.js";
2
- import { AnyProcedureRouter, Procedure } from "./procedure.js";
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 AnyProcedureRouter> = { [K in keyof T]: T[K] extends Procedure<infer _Scope, infer Input, infer Output, infer Errors> ? ProcedureMethod<Input, Output, Errors> : T[K] extends AnyProcedureRouter ? ResultClient<T[K]> : never };
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 };
@@ -1,7 +1,7 @@
1
- import { AnyProcedureRouter } from "./procedure.js";
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(router: AnyProcedureRouter): AnyRouter;
5
+ declare function createOrpcRouter(procedures: AnyProcedureTree): AnyRouter;
6
6
  //#endregion
7
7
  export { createOrpcRouter };
@@ -1,9 +1,9 @@
1
1
  import { buildProcedure } from "./procedure.js";
2
2
 
3
3
  //#region src/shared/router.ts
4
- function createOrpcRouter(router) {
4
+ function createOrpcRouter(procedures) {
5
5
  const cache = /* @__PURE__ */ new Map();
6
- return new Proxy(router, { get: (target, p) => {
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];
@@ -29,6 +29,8 @@ declare const CurrencyFormat: z.ZodObject<{
29
29
  type CurrencyFormat = z.infer<typeof CurrencyFormat>;
30
30
  declare const IdentifierInput: z.ZodUnion<readonly [z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>, z.ZodString]>;
31
31
  type IdentifierInput = z.output<typeof IdentifierInput>;
32
+ /** Preserve a project's generated custom-field shape while checking the runtime value is an object. */
33
+ declare const customFieldsSchema: <TCustom extends object>() => z.ZodCustom<TCustom, TCustom>;
32
34
  declare const PreviewTokenPayload: z.ZodObject<{
33
35
  id: z.ZodNumber;
34
36
  parent: z.ZodNumber;
@@ -45,4 +47,4 @@ declare const PreviewTokenData: z.ZodObject<{
45
47
  }, z.core.$strip>;
46
48
  type PreviewTokenData = z.infer<typeof PreviewTokenData>;
47
49
  //#endregion
48
- export { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, PreviewTokenData, PreviewTokenPayload };
50
+ export { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, PreviewTokenData, PreviewTokenPayload, customFieldsSchema };
@@ -23,6 +23,8 @@ const CurrencyFormat = z.object({
23
23
  currencyThousandSeparator: z.string()
24
24
  });
25
25
  const IdentifierInput = z.union([NumberLike, z.string()]);
26
+ /** Preserve a project's generated custom-field shape while checking the runtime value is an object. */
27
+ const customFieldsSchema = () => z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value), "Expected custom fields to be an object");
26
28
  const PreviewTokenPayload = z.object({
27
29
  id: z.number(),
28
30
  parent: z.number(),
@@ -34,4 +36,4 @@ const PreviewTokenData = z.object({
34
36
  });
35
37
 
36
38
  //#endregion
37
- export { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, PreviewTokenData, PreviewTokenPayload };
39
+ export { CurrencyFormat, IdentifierInput, LIST_ORDER, ListMetadata, ListOrder, PreviewTokenData, PreviewTokenPayload, customFieldsSchema };
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 TAG_ROUTER_MAP = {
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 { TAG_ROUTER_MAP };
76
+ export { TAG_PROCEDURES };
@@ -1,4 +1,4 @@
1
- import { IdentifierInput, ListMetadata, ListOrder } from "../shared/schema.js";
1
+ import { IdentifierInput, ListMetadata, ListOrder, customFieldsSchema } from "../shared/schema.js";
2
2
  import { Seo } from "../seo/schema.js";
3
3
  import { BooleanLike, Metadata, NumberLike, arrayable, lenient } from "@kizlo/shared";
4
4
  import z from "zod/v4";
@@ -22,6 +22,7 @@ const Tag = z.object({
22
22
  description: z.string().nullable(),
23
23
  postCount: z.number(),
24
24
  seo: Seo.nullable(),
25
+ custom: customFieldsSchema(),
25
26
  meta: Metadata
26
27
  });
27
28
  const RetrieveTagInput = z.object({ identifier: IdentifierInput });
package/dist/tag/utils.js CHANGED
@@ -11,6 +11,7 @@ function deserializeTag(data) {
11
11
  description: data.description.length > 0 ? data.description : null,
12
12
  postCount: data.count,
13
13
  seo: "seo" in data.kizlo ? deserializeSeo(data.kizlo.seo) : null,
14
+ custom: data.kizlo.custom,
14
15
  meta: stringifiedMetaRecord(data.meta)
15
16
  };
16
17
  }
@@ -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 { KizloServerOptions, createKizlo } from "../integrations/tanstack-start/kizlo.server.js";
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, KizloServerOptions, LinkDescriptor, MetaDescriptor, RouteHead, ScriptDescriptor, ServerRoute, ServerRouteContext, WEB_MANIFEST_ROUTE, createApiHandlers, createKizlo, createManifestRoute, createRobotsRoute, createSitemapRedirectRoute, createSitemapRoute, getServerBaseUrl, renderJsonLd, resolvePageHead, resolveRootHead };
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 { createKizlo } from "../integrations/tanstack-start/kizlo.server.js";
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, createKizlo, createManifestRoute, createRobotsRoute, createSitemapRedirectRoute, createSitemapRoute, getServerBaseUrl, renderJsonLd, resolvePageHead, resolveRootHead };
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.15.2",
3
+ "version": "0.17.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.7.0",
109
+ "@kizlo/shared": "0.9.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 };
@@ -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 };