kizlo 0.23.0 → 0.25.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/index.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/procedures.d.ts +7 -7
- package/dist/react.d.ts +56 -0
- package/dist/react.js +54 -0
- package/dist/shared/result.d.ts +32 -1
- package/package.json +7 -1
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { COMMON_ERRORS, CommonErrorCode, CommonErrorLiteral, CommonErrorMap, Def
|
|
|
29
29
|
import { AnyMiddleware, ExtractMiddlewareContextOutput, InferMiddlewares, Middleware, MiddlewareHandler, MiddlewareNextFn, MiddlewareOptions, MiddlewareResult, createMiddleware } from "./shared/middleware.js";
|
|
30
30
|
import { AnyProcedure, AnyProcedureTree, BaseHandlerOptions, ExtractParams, ExtractProcedureByScope, InvocationScope, OpenapiPart, Procedure, ProcedureErrors, ProcedureHandler, ProcedureOptions, ProcedureTreeDepthTuple, ResolveParamsPart, ResolvedSchemaInput, ResolvedSchemaOutput, SchemaIO, buildProcedure, combineDetailed, createProcedure, handleUnexpectedError, schemaType } from "./shared/procedure.js";
|
|
31
31
|
import { AnyIntegration, EnvReader, EnvRecord, EnvSource, ExtractIntegrationProcedures, InferIntegrationProcedures, Integration, IntegrationRequirements, KizloEnv, WordPressEnv, assertIntegrationEndpoints, assertIntegrationEnv, createIntegration, missingEndpoints, missingEnv, readEnv, sortIntegrations } from "./shared/integration.js";
|
|
32
|
-
import { InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, KizloErrorUnion, KizloResult, MaybeCallerOptions, ProcedureMethod, ResultClient, createResultClient } from "./shared/result.js";
|
|
32
|
+
import { InferClientData, InferClientError, InferClientInput, InferClientResult, InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, KizloErrorUnion, KizloResult, MaybeCallerOptions, ProcedureMethod, ResultClient, createResultClient } from "./shared/result.js";
|
|
33
33
|
import { AnyKizloConfig, CreateKizloOptions, Kizlo, KizloConfig, RootProcedures, S2SClient, createKizlo, integrationEnv, resolveKizloConfig, resolveWordPressConnection, wordPressConnectionComplete } from "./kizlo.js";
|
|
34
34
|
import { WEB_MANIFEST_ROUTE, WebManifest, buildWebManifest, createManifestRoute } from "./brand/manifest.js";
|
|
35
35
|
import "./brand/index.js";
|
|
@@ -43,4 +43,4 @@ import { ShaAlgorithm, compare, hash, hmac } from "./shared/crypto.js";
|
|
|
43
43
|
import { Identifier, parseIdentifier } from "./shared/identifier.js";
|
|
44
44
|
import { createOrpcRouter } from "./shared/router.js";
|
|
45
45
|
import { deserializeCurrencyFormat, deserializeListMetadata, emptyList, serializeCurrencyFormat } from "./shared/serialize.js";
|
|
46
|
-
export { ActiveKizloClient, ActiveWordPressClient, AnyContext, AnyEventSchema, AnyEvents, AnyIntegration, AnyKizloConfig, AnyMiddleware, AnyNestedClient, AnyProcedure, AnyProcedureTree, AuthAdapter, AuthGetSession, AuthUser, AuthorsSettings, AuthorsSettingsInput, BaseHandlerOptions, BrandSettings, BrandSettingsInput, COMMON_ERRORS, CONTENT_TYPES, CORE_PROCEDURES, CaptchaAdapter, type Category, type CategoryCustomFields, CategoryCustomFieldsSchema, CommonErrorCode, CommonErrorLiteral, CommonErrorMap, ConnInfo, ConnInfoFn, ConsoleLogAdapterOptions, ContentType, Context, ContextConfig, Contract, ContractProcedure, CookiesAdapter, CookiesDeleteAll, CookiesGetAll, CookiesSetAll, CookiesStorage, CoreProcedures, CrawlingSettings, CrawlingSettingsInput, CreateKizloOptions, CreateSitemapRouteOptions, CurrencyFormat, DefinedErrorMapLike, DevPluginSource, EnvReader, EnvRecord, EnvSource, ErrorDefinition, EventHandler, EventHandlerFn, ExtractIntegrationProcedures, ExtractMiddlewareContextOutput, ExtractParams, ExtractProcedureByScope, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, GeoAdapter, GeoGetConnInfo, HTTPMethod, HeadlessSettings, HeadlessSettingsInput, IconDescriptor, Identifier, IdentifierInput, IdentitySettings, IdentitySettingsInput, InferEventUnion, InferIntegrationProcedures, InferMiddlewares, InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, Integration, IntegrationRequirements, InvocationScope, JsonValue, Kizlo, KizloBrowserClient, KizloClient, KizloClientConfig, KizloConfig, KizloEnv, KizloError, KizloErrorOptions, KizloErrorUnion, KizloProcedureRegistry, KizloResult, LIST_ORDER, List, ListMetadata, ListOrder, ListSitemapUrlInput, ListSitemapUrlInputBase, LocalPlugin, LogLevel, LogPayload, Logger, LoggerAdapter, ManifestIcon, MaybeCallerOptions, MaybeOptionalOptions, Middleware, MiddlewareHandler, MiddlewareNextFn, MiddlewareOptions, MiddlewareResult, OpenapiPart, OrganizationFounder, OrganizationSettings, OrganizationSettingsInput, type Page, type PageCustomFields, PageCustomFieldsSchema, PersonSettings, PersonSettingsInput, PluginSource, type Post, type PostCustomFields, PostCustomFieldsSchema, PostStatusDefinition, PostTypeSettings, PostTypeSettingsInput, PreviewTokenData, PreviewTokenPayload, Procedure, ProcedureContext, ProcedureErrors, ProcedureHandler, ProcedureMethod, ProcedureOptions, ProcedureTreeDepthTuple, RedirectInput, RedirectStatus, ResolveParamsPart, ResolvedIcons, ResolvedSchemaInput, ResolvedSchemaOutput, ResultClient, Robots, RobotsRule, RootProcedures, S2SClient, SITEMAP_BASE, SITEMAP_INDEX_SLUG, SchemaIO, SeedContext, Seo, SeoHead, SeoSchema, ServiceAdapters, SessionFn, Settings, SettingsService, SettleContext, ShaAlgorithm, SiteSettings, SiteSettingsInput, Sitemap, SitemapIndex, SitemapIndexEntry, SitemapList, SitemapRouteExtra, SitemapUrl, SitemapUrlImage, SitemapUrlList, SocialProfile, type Tag, type TagCustomFields, TagCustomFieldsSchema, TaxonomySettings, TaxonomySettingsInput, TestAdminUser, TestCredentials, TestUser, ThrowableErrorFn, ThrowableErrorMap, UploadsSettings, UploadsSettingsInput, VerifyCaptchaFn, VerifyPreviewTokenFn, WEB_MANIFEST_ROUTE, WPK_RobotRule, WPK_Robots, WPK_Seo, WPK_Sitemap, WPK_SitemapUrl, WPK_SitemapUrlImage, 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_Error, WP_ErrorData, WP_Failure, WP_List, WP_ListMetadata, WP_RequestBuild, WP_RequestContentType, WP_RequestInput, WP_RequestMethod, WP_RequestParts, WP_ResponseContentType, WP_Result, WP_Success, WP_TransportFailure, WP_TypedHeaders, WebManifest, WebhookOptions, WebhookSettings, WebhookSettingsInput, WithCommonErrorMap, WordPressClientRegistry, WordPressCredentials, WordPressCustomFieldsRegistry, WordPressEndpointRegistry, WordPressEnv, WordPressTransport, WordPressTransportOptions, WordPressTransportResult, altcha, arkose, assertIntegrationEndpoints, assertIntegrationEnv, authMock, buildProcedure, buildWebManifest, buildWordPressRequest, combineDetailed, compare, consoleLog, createAuthAdapter, createCaptchaAdapter, createCookiesAdapter, createEventHandler, createGeoAdapter, createIntegration, createKizlo, createKizloClient, createLoggerAdapter, createManifestRoute, createMiddleware, createOrpcRouter, createProcedure, createResultClient, createSitemapRedirectRoute, createSitemapRoute, createThrowableErrorMap, createWebhookRouter, createWordPressClient, customFieldsSchema, defineErrorMap, defineFixture, deserializeCurrencyFormat, deserializeListMetadata, deserializeSeo, emptyList, friendlyCaptcha, generateContract, geoMock, geoVercelNext, handleUnexpectedError, hash, hcaptcha, hmac, integrationEnv, isContractProcedure, isKizloError, isLocalPlugin, isWordPressResourceError, mergeServiceAdapters, missingEndpoints, missingEnv, noopAdapter, parseIdentifier, parseSitemapSlug, readEnv, recaptcha, renderJsonLd, renderSitemapIndex, renderUrlSet, resolveIcons, resolveKizloConfig, resolveWordPressConnection, restoreContract, schemaType, serializeCurrencyFormat, sitemapEntryPath, sortIntegrations, toKizloError, turnstile, wordPressConnectionComplete, wpEndpoint, xmlResponse };
|
|
46
|
+
export { ActiveKizloClient, ActiveWordPressClient, AnyContext, AnyEventSchema, AnyEvents, AnyIntegration, AnyKizloConfig, AnyMiddleware, AnyNestedClient, AnyProcedure, AnyProcedureTree, AuthAdapter, AuthGetSession, AuthUser, AuthorsSettings, AuthorsSettingsInput, BaseHandlerOptions, BrandSettings, BrandSettingsInput, COMMON_ERRORS, CONTENT_TYPES, CORE_PROCEDURES, CaptchaAdapter, type Category, type CategoryCustomFields, CategoryCustomFieldsSchema, CommonErrorCode, CommonErrorLiteral, CommonErrorMap, ConnInfo, ConnInfoFn, ConsoleLogAdapterOptions, ContentType, Context, ContextConfig, Contract, ContractProcedure, CookiesAdapter, CookiesDeleteAll, CookiesGetAll, CookiesSetAll, CookiesStorage, CoreProcedures, CrawlingSettings, CrawlingSettingsInput, CreateKizloOptions, CreateSitemapRouteOptions, CurrencyFormat, DefinedErrorMapLike, DevPluginSource, EnvReader, EnvRecord, EnvSource, ErrorDefinition, EventHandler, EventHandlerFn, ExtractIntegrationProcedures, ExtractMiddlewareContextOutput, ExtractParams, ExtractProcedureByScope, Fixture, FixtureCleanupFn, FixtureSeedFn, FixtureSettleFn, GeoAdapter, GeoGetConnInfo, HTTPMethod, HeadlessSettings, HeadlessSettingsInput, IconDescriptor, Identifier, IdentifierInput, IdentitySettings, IdentitySettingsInput, InferClientData, InferClientError, InferClientInput, InferClientResult, InferEventUnion, InferIntegrationProcedures, InferMiddlewares, InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, Integration, IntegrationRequirements, InvocationScope, JsonValue, Kizlo, KizloBrowserClient, KizloClient, KizloClientConfig, KizloConfig, KizloEnv, KizloError, KizloErrorOptions, KizloErrorUnion, KizloProcedureRegistry, KizloResult, LIST_ORDER, List, ListMetadata, ListOrder, ListSitemapUrlInput, ListSitemapUrlInputBase, LocalPlugin, LogLevel, LogPayload, Logger, LoggerAdapter, ManifestIcon, MaybeCallerOptions, MaybeOptionalOptions, Middleware, MiddlewareHandler, MiddlewareNextFn, MiddlewareOptions, MiddlewareResult, OpenapiPart, OrganizationFounder, OrganizationSettings, OrganizationSettingsInput, type Page, type PageCustomFields, PageCustomFieldsSchema, PersonSettings, PersonSettingsInput, PluginSource, type Post, type PostCustomFields, PostCustomFieldsSchema, PostStatusDefinition, PostTypeSettings, PostTypeSettingsInput, PreviewTokenData, PreviewTokenPayload, Procedure, ProcedureContext, ProcedureErrors, ProcedureHandler, ProcedureMethod, ProcedureOptions, ProcedureTreeDepthTuple, RedirectInput, RedirectStatus, ResolveParamsPart, ResolvedIcons, ResolvedSchemaInput, ResolvedSchemaOutput, ResultClient, Robots, RobotsRule, RootProcedures, S2SClient, SITEMAP_BASE, SITEMAP_INDEX_SLUG, SchemaIO, SeedContext, Seo, SeoHead, SeoSchema, ServiceAdapters, SessionFn, Settings, SettingsService, SettleContext, ShaAlgorithm, SiteSettings, SiteSettingsInput, Sitemap, SitemapIndex, SitemapIndexEntry, SitemapList, SitemapRouteExtra, SitemapUrl, SitemapUrlImage, SitemapUrlList, SocialProfile, type Tag, type TagCustomFields, TagCustomFieldsSchema, TaxonomySettings, TaxonomySettingsInput, TestAdminUser, TestCredentials, TestUser, ThrowableErrorFn, ThrowableErrorMap, UploadsSettings, UploadsSettingsInput, VerifyCaptchaFn, VerifyPreviewTokenFn, WEB_MANIFEST_ROUTE, WPK_RobotRule, WPK_Robots, WPK_Seo, WPK_Sitemap, WPK_SitemapUrl, WPK_SitemapUrlImage, 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_Error, WP_ErrorData, WP_Failure, WP_List, WP_ListMetadata, WP_RequestBuild, WP_RequestContentType, WP_RequestInput, WP_RequestMethod, WP_RequestParts, WP_ResponseContentType, WP_Result, WP_Success, WP_TransportFailure, WP_TypedHeaders, WebManifest, WebhookOptions, WebhookSettings, WebhookSettingsInput, WithCommonErrorMap, WordPressClientRegistry, WordPressCredentials, WordPressCustomFieldsRegistry, WordPressEndpointRegistry, WordPressEnv, WordPressTransport, WordPressTransportOptions, WordPressTransportResult, altcha, arkose, assertIntegrationEndpoints, assertIntegrationEnv, authMock, buildProcedure, buildWebManifest, buildWordPressRequest, combineDetailed, compare, consoleLog, createAuthAdapter, createCaptchaAdapter, createCookiesAdapter, createEventHandler, createGeoAdapter, createIntegration, createKizlo, createKizloClient, createLoggerAdapter, createManifestRoute, createMiddleware, createOrpcRouter, createProcedure, createResultClient, createSitemapRedirectRoute, createSitemapRoute, createThrowableErrorMap, createWebhookRouter, createWordPressClient, customFieldsSchema, defineErrorMap, defineFixture, deserializeCurrencyFormat, deserializeListMetadata, deserializeSeo, emptyList, friendlyCaptcha, generateContract, geoMock, geoVercelNext, handleUnexpectedError, hash, hcaptcha, hmac, integrationEnv, isContractProcedure, isKizloError, isLocalPlugin, isWordPressResourceError, mergeServiceAdapters, missingEndpoints, missingEnv, noopAdapter, parseIdentifier, parseSitemapSlug, readEnv, recaptcha, renderJsonLd, renderSitemapIndex, renderUrlSet, resolveIcons, resolveKizloConfig, resolveWordPressConnection, restoreContract, schemaType, serializeCurrencyFormat, sitemapEntryPath, sortIntegrations, toKizloError, turnstile, wordPressConnectionComplete, wpEndpoint, xmlResponse };
|
package/dist/package.js
CHANGED
package/dist/procedures.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ declare const CORE_PROCEDURES: {
|
|
|
44
44
|
include?: string | number | (string | number)[] | undefined;
|
|
45
45
|
offset?: string | number | undefined;
|
|
46
46
|
order?: "asc" | "desc" | undefined;
|
|
47
|
-
orderby?: "
|
|
47
|
+
orderby?: "id" | "date" | "slug" | "parent" | "title" | "author" | "include" | "modified" | "relevance" | "include_slugs" | undefined;
|
|
48
48
|
searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
|
|
49
49
|
slug?: string | string[] | undefined;
|
|
50
50
|
taxRelation?: "AND" | "OR" | undefined;
|
|
@@ -99,7 +99,7 @@ declare const CORE_PROCEDURES: {
|
|
|
99
99
|
include?: string | number | (string | number)[] | undefined;
|
|
100
100
|
offset?: string | number | undefined;
|
|
101
101
|
order?: "asc" | "desc" | undefined;
|
|
102
|
-
orderby?: "
|
|
102
|
+
orderby?: "id" | "date" | "slug" | "parent" | "title" | "author" | "include" | "modified" | "relevance" | "include_slugs" | "menu_order" | undefined;
|
|
103
103
|
searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
|
|
104
104
|
slug?: string | string[] | undefined;
|
|
105
105
|
parent?: string | number | (string | number)[] | undefined;
|
|
@@ -136,7 +136,7 @@ declare const CORE_PROCEDURES: {
|
|
|
136
136
|
exclude?: string | number | (string | number)[] | undefined;
|
|
137
137
|
include?: string | number | (string | number)[] | undefined;
|
|
138
138
|
order?: "asc" | "desc" | undefined;
|
|
139
|
-
orderBy?: "
|
|
139
|
+
orderBy?: "id" | "count" | "slug" | "name" | "description" | "include" | "include_slugs" | "term_group" | undefined;
|
|
140
140
|
hideEmpty?: string | boolean | undefined;
|
|
141
141
|
parent?: string | number | undefined;
|
|
142
142
|
post?: string | number | undefined;
|
|
@@ -172,7 +172,7 @@ declare const CORE_PROCEDURES: {
|
|
|
172
172
|
exclude?: string | number | (string | number)[] | undefined;
|
|
173
173
|
include?: string | number | (string | number)[] | undefined;
|
|
174
174
|
order?: "asc" | "desc" | undefined;
|
|
175
|
-
orderBy?: "
|
|
175
|
+
orderBy?: "id" | "count" | "slug" | "name" | "description" | "include" | "include_slugs" | "term_group" | undefined;
|
|
176
176
|
hideEmpty?: string | boolean | undefined;
|
|
177
177
|
post?: string | number | undefined;
|
|
178
178
|
slug?: string | string[] | undefined;
|
|
@@ -292,7 +292,7 @@ declare const CORE_PROCEDURES: {
|
|
|
292
292
|
include?: string | number | (string | number)[] | undefined;
|
|
293
293
|
offset?: string | number | undefined;
|
|
294
294
|
order?: "asc" | "desc" | undefined;
|
|
295
|
-
orderby?: "
|
|
295
|
+
orderby?: "id" | "date" | "slug" | "parent" | "title" | "author" | "include" | "relevance" | "include_slugs" | "menu_order" | undefined;
|
|
296
296
|
searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
|
|
297
297
|
slug?: string | string[] | undefined;
|
|
298
298
|
taxRelation?: "AND" | "OR" | undefined;
|
|
@@ -371,7 +371,7 @@ declare const CORE_PROCEDURES: {
|
|
|
371
371
|
include?: string | number | (string | number)[] | undefined;
|
|
372
372
|
offset?: string | number | undefined;
|
|
373
373
|
order?: "asc" | "desc" | undefined;
|
|
374
|
-
orderby?: "
|
|
374
|
+
orderby?: "id" | "date" | "slug" | "parent" | "title" | "author" | "include" | "relevance" | "include_slugs" | "menu_order" | undefined;
|
|
375
375
|
searchColumns?: ("post_title" | "post_content" | "post_excerpt")[] | undefined;
|
|
376
376
|
slug?: string | string[] | undefined;
|
|
377
377
|
taxRelation?: "AND" | "OR" | undefined;
|
|
@@ -507,7 +507,7 @@ declare const CORE_PROCEDURES: {
|
|
|
507
507
|
include?: string | number | (string | number)[] | undefined;
|
|
508
508
|
offset?: string | number | undefined;
|
|
509
509
|
order?: "asc" | "desc" | undefined;
|
|
510
|
-
orderby?: "
|
|
510
|
+
orderby?: "id" | "date" | "parent" | "include" | "post" | undefined;
|
|
511
511
|
parent?: string | number | (string | number)[] | undefined;
|
|
512
512
|
parentExclude?: string | number | (string | number)[] | undefined;
|
|
513
513
|
post?: string | number | (string | number)[] | undefined;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ActiveKizloClient } from "./client.js";
|
|
2
|
+
import * as react0 from "react";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/react.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What the context carries. One key today, which is why the hook hands back the object rather than the client itself: a
|
|
9
|
+
* locale, a session or app-wide configuration can join it without changing a signature.
|
|
10
|
+
*/
|
|
11
|
+
type KizloContextValue = {
|
|
12
|
+
/** The app's browser Kizlo client, typed from the procedures that app registered. */
|
|
13
|
+
client: ActiveKizloClient;
|
|
14
|
+
};
|
|
15
|
+
type KizloProviderProps = {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
/** The app's browser Kizlo client, the callable procedure tree. */
|
|
18
|
+
client: ActiveKizloClient;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Holds the app's browser Kizlo client for the client components below it. Mount it once, above anything that reads it.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // app/providers.tsx
|
|
26
|
+
* "use client"
|
|
27
|
+
* import { KizloProvider } from "kizlo/react"
|
|
28
|
+
* import { client } from "@/lib/kizlo/client"
|
|
29
|
+
*
|
|
30
|
+
* export function Providers({ children }: { children: React.ReactNode }) {
|
|
31
|
+
* return <KizloProvider client={client}>{children}</KizloProvider>
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function KizloProvider({
|
|
36
|
+
children,
|
|
37
|
+
client
|
|
38
|
+
}: KizloProviderProps): react0.JSX.Element;
|
|
39
|
+
/**
|
|
40
|
+
* Reads the context, whose `client` is typed from the procedures the app registered, so a call the contract does not
|
|
41
|
+
* carry is a compile error rather than a runtime surprise.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* "use client"
|
|
46
|
+
* import { useKizloContext } from "kizlo/react"
|
|
47
|
+
*
|
|
48
|
+
* function LatestPosts() {
|
|
49
|
+
* const { client } = useKizloContext()
|
|
50
|
+
* // ...
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare function useKizloContext(): KizloContextValue;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { KizloContextValue, KizloProvider, KizloProviderProps, useKizloContext };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { createContext, useContext, useMemo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/react.tsx
|
|
8
|
+
const KizloContext = createContext(null);
|
|
9
|
+
/**
|
|
10
|
+
* Holds the app's browser Kizlo client for the client components below it. Mount it once, above anything that reads it.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // app/providers.tsx
|
|
15
|
+
* "use client"
|
|
16
|
+
* import { KizloProvider } from "kizlo/react"
|
|
17
|
+
* import { client } from "@/lib/kizlo/client"
|
|
18
|
+
*
|
|
19
|
+
* export function Providers({ children }: { children: React.ReactNode }) {
|
|
20
|
+
* return <KizloProvider client={client}>{children}</KizloProvider>
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function KizloProvider({ children, client }) {
|
|
25
|
+
if (!client) throw new Error("<KizloProvider client={client}> needs the browser client `createKizloClient` returned.");
|
|
26
|
+
const value = useMemo(() => ({ client }), [client]);
|
|
27
|
+
return /* @__PURE__ */ jsx(KizloContext.Provider, {
|
|
28
|
+
value,
|
|
29
|
+
children
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reads the context, whose `client` is typed from the procedures the app registered, so a call the contract does not
|
|
34
|
+
* carry is a compile error rather than a runtime surprise.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* "use client"
|
|
39
|
+
* import { useKizloContext } from "kizlo/react"
|
|
40
|
+
*
|
|
41
|
+
* function LatestPosts() {
|
|
42
|
+
* const { client } = useKizloContext()
|
|
43
|
+
* // ...
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
function useKizloContext() {
|
|
48
|
+
const value = useContext(KizloContext);
|
|
49
|
+
if (!value) throw new Error("mount <KizloProvider client={client}> from kizlo/react above this component.");
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { KizloProvider, useKizloContext };
|
package/dist/shared/result.d.ts
CHANGED
|
@@ -27,7 +27,38 @@ type InferProcedureData<TProcedure extends AnyProcedure> = TProcedure extends Pr
|
|
|
27
27
|
type InferProcedureError<TProcedure extends AnyProcedure> = TProcedure extends Procedure<any, any, any, infer TErrors> ? KizloErrorUnion<WithCommonErrorMap<TErrors>> : never;
|
|
28
28
|
/** The complete wrapped result returned by a normal call to one public Kizlo procedure object. */
|
|
29
29
|
type InferProcedureResult<TProcedure extends AnyProcedure> = TProcedure extends Procedure<any, any, infer TOutput, infer TErrors> ? KizloResult<TOutput, TErrors> : never;
|
|
30
|
+
/**
|
|
31
|
+
* Matches `any` alone. A conditional type resolves `any` to both branches and infers `unknown` from
|
|
32
|
+
* it, so the client-level helpers guard on this to pass the unregistered-client fallback through
|
|
33
|
+
* intact instead of narrowing it to something a consumer can no longer index.
|
|
34
|
+
*/
|
|
35
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
36
|
+
/**
|
|
37
|
+
* The complete wrapped result returned by a normal call to one Kizlo client method.
|
|
38
|
+
*
|
|
39
|
+
* The client-level helpers read {@link ProcedureMethod}'s own call signature rather than re-deriving
|
|
40
|
+
* from `Procedure`, which is what lets them work on a client method alone, including the `any`
|
|
41
|
+
* short-circuit `ActiveKizloClient` falls back to while `KizloProcedureRegistry` is unaugmented.
|
|
42
|
+
*/
|
|
43
|
+
type InferClientResult<TMethod> = IsAny<TMethod> extends true ? any : TMethod extends ((...args: never) => Promise<infer TResult>) ? TResult : never;
|
|
44
|
+
/**
|
|
45
|
+
* Reads one key off a `KizloResult` branch. `never` is short-circuited rather than let through:
|
|
46
|
+
* every type is assignable to it, so a node that is not a client method leaves nothing for
|
|
47
|
+
* `Extract` to find and would otherwise infer `unknown`, turning a missing procedure into a loose
|
|
48
|
+
* type instead of a missing one.
|
|
49
|
+
*/
|
|
50
|
+
type BranchValue<TBranch, TKey extends "data" | "error"> = [TBranch] extends [never] ? never : TBranch extends Record<TKey, infer TValue> ? TValue : never;
|
|
51
|
+
/** The successful data returned by one Kizlo client method. */
|
|
52
|
+
type InferClientData<TMethod> = IsAny<TMethod> extends true ? any : BranchValue<Extract<InferClientResult<TMethod>, {
|
|
53
|
+
success: true;
|
|
54
|
+
}>, "data">;
|
|
55
|
+
/** The declared and common client-visible errors returned by one Kizlo client method. */
|
|
56
|
+
type InferClientError<TMethod> = IsAny<TMethod> extends true ? any : BranchValue<Extract<InferClientResult<TMethod>, {
|
|
57
|
+
success: false;
|
|
58
|
+
}>, "error">;
|
|
59
|
+
/** The input accepted by one Kizlo client method. */
|
|
60
|
+
type InferClientInput<TMethod> = IsAny<TMethod> extends true ? any : TMethod extends ((...args: infer TArgs) => unknown) ? TArgs[0] : never;
|
|
30
61
|
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
62
|
declare function createResultClient<T extends AnyProcedureTree>(client: NestedClient<any>): ResultClient<T>;
|
|
32
63
|
//#endregion
|
|
33
|
-
export { InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, KizloErrorUnion, KizloResult, MaybeCallerOptions, ProcedureMethod, ResultClient, createResultClient };
|
|
64
|
+
export { InferClientData, InferClientError, InferClientInput, InferClientResult, InferProcedureData, InferProcedureError, InferProcedureInput, InferProcedureResult, KizloErrorUnion, KizloResult, MaybeCallerOptions, ProcedureMethod, ResultClient, createResultClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kizlo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A headless WordPress framework for TypeScript.",
|
|
6
6
|
"keywords": [
|
|
@@ -40,6 +40,12 @@
|
|
|
40
40
|
"default": "./dist/index.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"./react": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/react.d.ts",
|
|
46
|
+
"default": "./dist/react.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
43
49
|
"./config": {
|
|
44
50
|
"import": {
|
|
45
51
|
"types": "./dist/config.d.ts",
|