capable-kit 0.0.1-alpha.6 → 0.0.1-alpha.7

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.
@@ -0,0 +1,14 @@
1
+ //#region packages/next/src/index.d.ts
2
+ type NextRouteHandler = (request: Request) => Promise<Response> | Response;
3
+ declare function createNextRouteHandlers(fetch: NextRouteHandler): {
4
+ GET: NextRouteHandler;
5
+ POST: NextRouteHandler;
6
+ PUT: NextRouteHandler;
7
+ PATCH: NextRouteHandler;
8
+ DELETE: NextRouteHandler;
9
+ HEAD: NextRouteHandler;
10
+ OPTIONS: NextRouteHandler;
11
+ };
12
+ //#endregion
13
+ export { NextRouteHandler, createNextRouteHandlers };
14
+ //# sourceMappingURL=next.d.mts.map
package/dist/next.mjs ADDED
@@ -0,0 +1,16 @@
1
+ //#region packages/next/src/index.ts
2
+ function createNextRouteHandlers(fetch) {
3
+ return {
4
+ GET: fetch,
5
+ POST: fetch,
6
+ PUT: fetch,
7
+ PATCH: fetch,
8
+ DELETE: fetch,
9
+ HEAD: fetch,
10
+ OPTIONS: fetch
11
+ };
12
+ }
13
+ //#endregion
14
+ export { createNextRouteHandlers };
15
+
16
+ //# sourceMappingURL=next.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.mjs","names":[],"sources":["../../next/src/index.ts"],"sourcesContent":["export type NextRouteHandler = (request: Request) => Promise<Response> | Response;\n\nexport function createNextRouteHandlers(fetch: NextRouteHandler): {\n GET: NextRouteHandler;\n POST: NextRouteHandler;\n PUT: NextRouteHandler;\n PATCH: NextRouteHandler;\n DELETE: NextRouteHandler;\n HEAD: NextRouteHandler;\n OPTIONS: NextRouteHandler;\n} {\n return {\n GET: fetch,\n POST: fetch,\n PUT: fetch,\n PATCH: fetch,\n DELETE: fetch,\n HEAD: fetch,\n OPTIONS: fetch,\n };\n}\n"],"mappings":";AAEA,SAAgB,wBAAwB,OAQtC;CACA,OAAO;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACN,SAAS;CACX;AACF"}
@@ -0,0 +1,34 @@
1
+ import { u as AppCapabilityIsSubscribable } from "./index-Dbc4g9WM.mjs";
2
+ import { QueryFunction, QueryKey, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
3
+ //#region packages/react-query/src/index.d.ts
4
+ type CapabilityCall = (...args: any[]) => Promise<any>;
5
+ type CapabilityInput<TCall extends CapabilityCall> = Exclude<Parameters<TCall>[0], undefined>;
6
+ type CapabilityVariables<TCall extends CapabilityCall> = undefined extends Parameters<TCall>[0] ? void : Parameters<TCall>[0];
7
+ type CapabilityOutput<TCall extends CapabilityCall> = Awaited<ReturnType<TCall>>;
8
+ type CapabilityQueryOptions<TCall extends CapabilityCall, TData = CapabilityOutput<TCall>> = Omit<UseQueryOptions<CapabilityOutput<TCall>, Error, TData, QueryKey>, "queryKey" | "queryFn">;
9
+ type CapabilityMutationOptions<TCall extends CapabilityCall, TOnMutateResult = unknown> = Omit<UseMutationOptions<CapabilityOutput<TCall>, Error, CapabilityVariables<TCall>, TOnMutateResult>, "mutationKey" | "mutationFn">;
10
+ type ReactQueryCapability<TCall extends CapabilityCall> = {
11
+ queryKey(input?: CapabilityInput<TCall>): QueryKey;
12
+ queryOptions<TData = CapabilityOutput<TCall>>(input: CapabilityInput<TCall>, options?: CapabilityQueryOptions<TCall, TData>): UseQueryOptions<CapabilityOutput<TCall>, Error, TData, QueryKey> & {
13
+ readonly queryKey: QueryKey;
14
+ readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;
15
+ };
16
+ mutationOptions<TOnMutateResult = unknown>(options?: CapabilityMutationOptions<TCall, TOnMutateResult>): UseMutationOptions<CapabilityOutput<TCall>, Error, CapabilityVariables<TCall>, TOnMutateResult> & {
17
+ readonly mutationKey: QueryKey;
18
+ readonly mutationFn: (variables: CapabilityVariables<TCall>) => Promise<CapabilityOutput<TCall>>;
19
+ };
20
+ };
21
+ type ReactQueryLiveCapability<TCall extends CapabilityCall> = ReactQueryCapability<TCall> & {
22
+ liveQueryOptions<TData = CapabilityOutput<TCall>>(input: CapabilityInput<TCall>, options?: CapabilityQueryOptions<TCall, TData>): UseQueryOptions<CapabilityOutput<TCall>, Error, TData, QueryKey> & {
23
+ readonly queryKey: QueryKey;
24
+ readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;
25
+ };
26
+ };
27
+ type ReactQueryNode<TValue> = TValue extends CapabilityCall ? AppCapabilityIsSubscribable<TValue> extends true ? ReactQueryLiveCapability<TValue> : ReactQueryCapability<TValue> : TValue extends object ? { readonly [TKey in Extract<keyof TValue, string>]: ReactQueryNode<TValue[TKey]>; } : never;
28
+ type ReactQueryApp<TApp extends object> = ReactQueryNode<TApp>;
29
+ declare function createReactQuery<const TApp extends object>(app: TApp, options?: {
30
+ readonly keyPrefix?: QueryKey;
31
+ }): ReactQueryApp<TApp>;
32
+ //#endregion
33
+ export { CapabilityMutationOptions, CapabilityQueryOptions, ReactQueryApp, ReactQueryCapability, ReactQueryLiveCapability, createReactQuery };
34
+ //# sourceMappingURL=react-query.d.mts.map
@@ -0,0 +1,47 @@
1
+ import { u as subscribe } from "./src-C2MGIlT0.mjs";
2
+ import { experimental_streamedQuery } from "@tanstack/react-query";
3
+ //#region packages/react-query/src/index.ts
4
+ const subscribeCall = subscribe;
5
+ function createReactQuery(app, options = {}) {
6
+ const keyPrefix = Object.freeze([...options.keyPrefix ?? ["capable"]]);
7
+ const callableAt = (path) => {
8
+ let current = app;
9
+ for (const segment of path) current = current[segment];
10
+ return current;
11
+ };
12
+ const capabilityKey = (path, input) => Object.freeze([
13
+ ...keyPrefix,
14
+ ...path,
15
+ ...input === void 0 ? [] : [input]
16
+ ]);
17
+ const proxy = (path) => new Proxy({}, { get(_target, key) {
18
+ if (key === "then") return void 0;
19
+ if (key === "queryKey") return (input) => capabilityKey(path, input);
20
+ if (key === "queryOptions") return (input, queryOptions = {}) => ({
21
+ ...queryOptions,
22
+ queryKey: capabilityKey(path, input),
23
+ queryFn: ({ signal }) => callableAt(path)(input, { signal })
24
+ });
25
+ if (key === "liveQueryOptions") return (input, queryOptions = {}) => ({
26
+ ...queryOptions,
27
+ queryKey: capabilityKey(path, input),
28
+ queryFn: experimental_streamedQuery({
29
+ streamFn: ({ signal }) => subscribeCall(callableAt(path), input, { signal }),
30
+ reducer: (_current, output) => output,
31
+ initialValue: void 0
32
+ })
33
+ });
34
+ if (key === "mutationOptions") return (mutationOptions = {}) => ({
35
+ ...mutationOptions,
36
+ mutationKey: capabilityKey(path),
37
+ mutationFn: (input) => callableAt(path)(input ?? {})
38
+ });
39
+ if (typeof key !== "string") return void 0;
40
+ return proxy([...path, key]);
41
+ } });
42
+ return proxy([]);
43
+ }
44
+ //#endregion
45
+ export { createReactQuery };
46
+
47
+ //# sourceMappingURL=react-query.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-query.mjs","names":[],"sources":["../../react-query/src/index.ts"],"sourcesContent":["import {\n subscribe,\n type AppCapabilityIsSubscribable,\n} from \"@capable/app\";\nimport {\n experimental_streamedQuery,\n type QueryFunction,\n type QueryKey,\n type UseMutationOptions,\n type UseQueryOptions,\n} from \"@tanstack/react-query\";\n\ntype CapabilityCall = (...args: any[]) => Promise<any>;\n\nconst subscribeCall = subscribe as unknown as (\n capabilityCall: CapabilityCall,\n input: unknown,\n options: { readonly signal: AbortSignal },\n) => AsyncIterableIterator<unknown>;\n\ntype CapabilityInput<TCall extends CapabilityCall> =\n Exclude<Parameters<TCall>[0], undefined>;\n\ntype CapabilityVariables<TCall extends CapabilityCall> =\n undefined extends Parameters<TCall>[0]\n ? void\n : Parameters<TCall>[0];\n\ntype CapabilityOutput<TCall extends CapabilityCall> =\n Awaited<ReturnType<TCall>>;\n\nexport type CapabilityQueryOptions<\n TCall extends CapabilityCall,\n TData = CapabilityOutput<TCall>,\n> = Omit<\n UseQueryOptions<\n CapabilityOutput<TCall>,\n Error,\n TData,\n QueryKey\n >,\n \"queryKey\" | \"queryFn\"\n>;\n\nexport type CapabilityMutationOptions<\n TCall extends CapabilityCall,\n TOnMutateResult = unknown,\n> = Omit<\n UseMutationOptions<\n CapabilityOutput<TCall>,\n Error,\n CapabilityVariables<TCall>,\n TOnMutateResult\n >,\n \"mutationKey\" | \"mutationFn\"\n>;\n\nexport type ReactQueryCapability<TCall extends CapabilityCall> = {\n queryKey(input?: CapabilityInput<TCall>): QueryKey;\n queryOptions<TData = CapabilityOutput<TCall>>(\n input: CapabilityInput<TCall>,\n options?: CapabilityQueryOptions<TCall, TData>,\n ): UseQueryOptions<\n CapabilityOutput<TCall>,\n Error,\n TData,\n QueryKey\n > & {\n readonly queryKey: QueryKey;\n readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;\n };\n mutationOptions<TOnMutateResult = unknown>(\n options?: CapabilityMutationOptions<TCall, TOnMutateResult>,\n ): UseMutationOptions<\n CapabilityOutput<TCall>,\n Error,\n CapabilityVariables<TCall>,\n TOnMutateResult\n > & {\n readonly mutationKey: QueryKey;\n readonly mutationFn: (\n variables: CapabilityVariables<TCall>,\n ) => Promise<CapabilityOutput<TCall>>;\n };\n};\n\nexport type ReactQueryLiveCapability<TCall extends CapabilityCall> =\n ReactQueryCapability<TCall> & {\n liveQueryOptions<TData = CapabilityOutput<TCall>>(\n input: CapabilityInput<TCall>,\n options?: CapabilityQueryOptions<TCall, TData>,\n ): UseQueryOptions<\n CapabilityOutput<TCall>,\n Error,\n TData,\n QueryKey\n > & {\n readonly queryKey: QueryKey;\n readonly queryFn: QueryFunction<CapabilityOutput<TCall>, QueryKey>;\n };\n };\n\ntype ReactQueryNode<TValue> =\n TValue extends CapabilityCall\n ? AppCapabilityIsSubscribable<TValue> extends true\n ? ReactQueryLiveCapability<TValue>\n : ReactQueryCapability<TValue>\n : TValue extends object\n ? {\n readonly [TKey in Extract<keyof TValue, string>]:\n ReactQueryNode<TValue[TKey]>;\n }\n : never;\n\nexport type ReactQueryApp<TApp extends object> = ReactQueryNode<TApp>;\n\nexport function createReactQuery<const TApp extends object>(\n app: TApp,\n options: {\n readonly keyPrefix?: QueryKey;\n } = {},\n): ReactQueryApp<TApp> {\n const keyPrefix = Object.freeze([...(options.keyPrefix ?? [\"capable\"])]);\n\n const callableAt = (path: readonly string[]): CapabilityCall => {\n let current: unknown = app;\n for (const segment of path) {\n current = (current as Record<string, unknown>)[segment];\n }\n return current as CapabilityCall;\n };\n\n const capabilityKey = (\n path: readonly string[],\n input?: unknown,\n ): QueryKey => Object.freeze([\n ...keyPrefix,\n ...path,\n ...(input === undefined ? [] : [input]),\n ]);\n\n const proxy = (path: readonly string[]): unknown =>\n new Proxy({}, {\n get(_target, key) {\n if (key === \"then\") return undefined;\n if (key === \"queryKey\") {\n return (input?: unknown) => capabilityKey(path, input);\n }\n if (key === \"queryOptions\") {\n return (\n input: unknown,\n queryOptions: Record<string, unknown> = {},\n ) => ({\n ...queryOptions,\n queryKey: capabilityKey(path, input),\n queryFn: ({ signal }: { readonly signal: AbortSignal }) =>\n callableAt(path)(input, { signal }),\n });\n }\n if (key === \"liveQueryOptions\") {\n return (\n input: unknown,\n queryOptions: Record<string, unknown> = {},\n ) => ({\n ...queryOptions,\n queryKey: capabilityKey(path, input),\n queryFn: experimental_streamedQuery<unknown, unknown>({\n streamFn: ({ signal }) =>\n subscribeCall(callableAt(path), input, { signal }),\n reducer: (_current, output) => output,\n initialValue: undefined,\n }) as QueryFunction<unknown, QueryKey>,\n });\n }\n if (key === \"mutationOptions\") {\n return (\n mutationOptions: Record<string, unknown> = {},\n ) => ({\n ...mutationOptions,\n mutationKey: capabilityKey(path),\n mutationFn: (input?: unknown) =>\n callableAt(path)(input ?? {}),\n });\n }\n if (typeof key !== \"string\") return undefined;\n return proxy([...path, key]);\n },\n });\n\n return proxy([]) as ReactQueryApp<TApp>;\n}\n"],"mappings":";;;AAcA,MAAM,gBAAgB;AAsGtB,SAAgB,iBACd,KACA,UAEI,CAAC,GACgB;CACrB,MA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@
1
+ import { u as AppCapabilityIsSubscribable } from "./index-Dbc4g9WM.mjs";
2
+ import { Fetcher, SWRConfiguration } from "swr";
3
+ import { MutationFetcher, SWRMutationConfiguration } from "swr/mutation";
4
+ import { SWRSubscription } from "swr/subscription";
5
+ //#region packages/swr/src/index.d.ts
6
+ type CapabilityCall = (...args: any[]) => Promise<any>;
7
+ type CapabilityInput<TCall extends CapabilityCall> = Exclude<Parameters<TCall>[0], undefined>;
8
+ type CapabilityVariables<TCall extends CapabilityCall> = undefined extends Parameters<TCall>[0] ? Exclude<Parameters<TCall>[0], undefined> | void : Parameters<TCall>[0];
9
+ type CapabilityOutput<TCall extends CapabilityCall> = Awaited<ReturnType<TCall>>;
10
+ type CapabilitySWRKey = readonly [unknown, ...unknown[]];
11
+ type CapabilityFetcher<TCall extends CapabilityCall> = Fetcher<CapabilityOutput<TCall>, CapabilitySWRKey>;
12
+ type CapabilityMutationFetcher<TCall extends CapabilityCall> = MutationFetcher<CapabilityOutput<TCall>, CapabilitySWRKey, CapabilityVariables<TCall>>;
13
+ type CapabilitySWRConfiguration<TCall extends CapabilityCall> = Omit<SWRConfiguration<CapabilityOutput<TCall>, Error, CapabilityFetcher<TCall>>, "fetcher">;
14
+ type CapabilitySWRMutationConfiguration<TCall extends CapabilityCall, TSWRData = CapabilityOutput<TCall>> = SWRMutationConfiguration<CapabilityOutput<TCall>, Error, CapabilitySWRKey, CapabilityVariables<TCall>, TSWRData> & {
15
+ readonly throwOnError?: boolean;
16
+ };
17
+ type CapabilitySWRSubscriptionConfiguration<TCall extends CapabilityCall> = SWRConfiguration<CapabilityOutput<TCall>, Error>;
18
+ type SWRCapability<TCall extends CapabilityCall> = {
19
+ key(input?: CapabilityInput<TCall>): CapabilitySWRKey;
20
+ swr(input: CapabilityInput<TCall>): readonly [key: CapabilitySWRKey, fetcher: CapabilityFetcher<TCall>];
21
+ swr<const TOptions extends CapabilitySWRConfiguration<TCall>>(input: CapabilityInput<TCall>, options: TOptions): readonly [key: CapabilitySWRKey, fetcher: CapabilityFetcher<TCall>, options: TOptions];
22
+ mutation(): readonly [key: CapabilitySWRKey, fetcher: CapabilityMutationFetcher<TCall>];
23
+ mutation<TSWRData = CapabilityOutput<TCall>>(options: CapabilitySWRMutationConfiguration<TCall, TSWRData>): readonly [key: CapabilitySWRKey, fetcher: CapabilityMutationFetcher<TCall>, options: CapabilitySWRMutationConfiguration<TCall, TSWRData>];
24
+ };
25
+ type SWRLiveCapability<TCall extends CapabilityCall> = SWRCapability<TCall> & {
26
+ subscription(input: CapabilityInput<TCall>): readonly [key: CapabilitySWRKey, subscriber: SWRSubscription<CapabilitySWRKey, CapabilityOutput<TCall>, Error>];
27
+ subscription<const TOptions extends CapabilitySWRSubscriptionConfiguration<TCall>>(input: CapabilityInput<TCall>, options: TOptions): readonly [key: CapabilitySWRKey, subscriber: SWRSubscription<CapabilitySWRKey, CapabilityOutput<TCall>, Error>, options: TOptions];
28
+ };
29
+ type SWRNode<TValue> = TValue extends CapabilityCall ? AppCapabilityIsSubscribable<TValue> extends true ? SWRLiveCapability<TValue> : SWRCapability<TValue> : TValue extends object ? { readonly [TKey in Extract<keyof TValue, string>]: SWRNode<TValue[TKey]>; } : never;
30
+ type SWRApp<TApp extends object> = SWRNode<TApp>;
31
+ declare function createSWR<const TApp extends object>(app: TApp, options?: {
32
+ readonly keyPrefix?: readonly unknown[];
33
+ }): SWRApp<TApp>;
34
+ //#endregion
35
+ export { CapabilitySWRConfiguration, CapabilitySWRKey, CapabilitySWRMutationConfiguration, CapabilitySWRSubscriptionConfiguration, SWRApp, SWRCapability, SWRLiveCapability, createSWR };
36
+ //# sourceMappingURL=swr.d.mts.map
package/dist/swr.mjs ADDED
@@ -0,0 +1,48 @@
1
+ import { u as subscribe } from "./src-C2MGIlT0.mjs";
2
+ //#region packages/swr/src/index.ts
3
+ const subscribeCall = subscribe;
4
+ function createSWR(app, options = {}) {
5
+ const keyPrefix = Object.freeze([...options.keyPrefix ?? ["capable"]]);
6
+ const callableAt = (path) => {
7
+ let current = app;
8
+ for (const segment of path) current = current[segment];
9
+ return current;
10
+ };
11
+ const capabilityKey = (path, input) => Object.freeze([
12
+ ...keyPrefix,
13
+ ...path,
14
+ ...input === void 0 ? [] : [input]
15
+ ]);
16
+ const withOptions = (key, operation, hookOptions) => hookOptions === void 0 ? [key, operation] : [
17
+ key,
18
+ operation,
19
+ hookOptions
20
+ ];
21
+ const proxy = (path) => new Proxy({}, { get(_target, key) {
22
+ if (key === "then") return void 0;
23
+ if (key === "key") return (input) => capabilityKey(path, input);
24
+ if (key === "swr") return (input, swrOptions) => withOptions(capabilityKey(path, input), () => callableAt(path)(input), swrOptions);
25
+ if (key === "mutation") return (mutationOptions) => withOptions(capabilityKey(path), (_key, { arg }) => callableAt(path)(arg), mutationOptions);
26
+ if (key === "subscription") return (input, subscriptionOptions) => withOptions(capabilityKey(path, input), (_key, { next }) => {
27
+ const controller = new AbortController();
28
+ (async () => {
29
+ try {
30
+ for await (const output of subscribeCall(callableAt(path), input, { signal: controller.signal })) next(null, output);
31
+ } catch (error) {
32
+ if (!controller.signal.aborted) next(toError(error));
33
+ }
34
+ })();
35
+ return () => controller.abort();
36
+ }, subscriptionOptions);
37
+ if (typeof key !== "string") return void 0;
38
+ return proxy([...path, key]);
39
+ } });
40
+ return proxy([]);
41
+ }
42
+ function toError(error) {
43
+ return error instanceof Error ? error : new Error(String(error));
44
+ }
45
+ //#endregion
46
+ export { createSWR };
47
+
48
+ //# sourceMappingURL=swr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swr.mjs","names":[],"sources":["../../swr/src/index.ts"],"sourcesContent":["import {\n subscribe,\n type AppCapabilityIsSubscribable,\n} from \"@capable/app\";\nimport type {\n Fetcher,\n SWRConfiguration,\n} from \"swr\";\nimport type {\n MutationFetcher,\n SWRMutationConfiguration,\n} from \"swr/mutation\";\nimport type { SWRSubscription } from \"swr/subscription\";\n\ntype CapabilityCall = (...args: any[]) => Promise<any>;\n\nconst subscribeCall = subscribe as unknown as (\n capabilityCall: CapabilityCall,\n input: unknown,\n options: { readonly signal: AbortSignal },\n) => AsyncIterableIterator<unknown>;\n\ntype CapabilityInput<TCall extends CapabilityCall> =\n Exclude<Parameters<TCall>[0], undefined>;\n\ntype CapabilityVariables<TCall extends CapabilityCall> =\n undefined extends Parameters<TCall>[0]\n ? Exclude<Parameters<TCall>[0], undefined> | void\n : Parameters<TCall>[0];\n\ntype CapabilityOutput<TCall extends CapabilityCall> =\n Awaited<ReturnType<TCall>>;\n\nexport type CapabilitySWRKey = readonly [unknown, ...unknown[]];\n\ntype CapabilityFetcher<TCall extends CapabilityCall> = Fetcher<\n CapabilityOutput<TCall>,\n CapabilitySWRKey\n>;\n\ntype CapabilityMutationFetcher<TCall extends CapabilityCall> = MutationFetcher<\n CapabilityOutput<TCall>,\n CapabilitySWRKey,\n CapabilityVariables<TCall>\n>;\n\nexport type CapabilitySWRConfiguration<\n TCall extends CapabilityCall,\n> = Omit<\n SWRConfiguration<\n CapabilityOutput<TCall>,\n Error,\n CapabilityFetcher<TCall>\n >,\n \"fetcher\"\n>;\n\nexport type CapabilitySWRMutationConfiguration<\n TCall extends CapabilityCall,\n TSWRData = CapabilityOutput<TCall>,\n> = SWRMutationConfiguration<\n CapabilityOutput<TCall>,\n Error,\n CapabilitySWRKey,\n CapabilityVariables<TCall>,\n TSWRData\n> & {\n readonly throwOnError?: boolean;\n};\n\nexport type CapabilitySWRSubscriptionConfiguration<\n TCall extends CapabilityCall,\n> = SWRConfiguration<CapabilityOutput<TCall>, Error>;\n\nexport type SWRCapability<TCall extends CapabilityCall> = {\n key(input?: CapabilityInput<TCall>): CapabilitySWRKey;\n swr(input: CapabilityInput<TCall>): readonly [\n key: CapabilitySWRKey,\n fetcher: CapabilityFetcher<TCall>,\n ];\n swr<const TOptions extends CapabilitySWRConfiguration<TCall>>(\n input: CapabilityInput<TCall>,\n options: TOptions,\n ): readonly [\n key: CapabilitySWRKey,\n fetcher: CapabilityFetcher<TCall>,\n options: TOptions,\n ];\n mutation(): readonly [\n key: CapabilitySWRKey,\n fetcher: CapabilityMutationFetcher<TCall>,\n ];\n mutation<TSWRData = CapabilityOutput<TCall>>(\n options: CapabilitySWRMutationConfiguration<TCall, TSWRData>,\n ): readonly [\n key: CapabilitySWRKey,\n fetcher: CapabilityMutationFetcher<TCall>,\n options: CapabilitySWRMutationConfiguration<TCall, TSWRData>,\n ];\n};\n\nexport type SWRLiveCapability<TCall extends CapabilityCall> =\n SWRCapability<TCall> & {\n subscription(input: CapabilityInput<TCall>): readonly [\n key: CapabilitySWRKey,\n subscriber: SWRSubscription<\n CapabilitySWRKey,\n CapabilityOutput<TCall>,\n Error\n >,\n ];\n subscription<\n const TOptions extends CapabilitySWRSubscriptionConfiguration<TCall>,\n >(\n input: CapabilityInput<TCall>,\n options: TOptions,\n ): readonly [\n key: CapabilitySWRKey,\n subscriber: SWRSubscription<\n CapabilitySWRKey,\n CapabilityOutput<TCall>,\n Error\n >,\n options: TOptions,\n ];\n };\n\ntype SWRNode<TValue> =\n TValue extends CapabilityCall\n ? AppCapabilityIsSubscribable<TValue> extends true\n ? SWRLiveCapability<TValue>\n : SWRCapability<TValue>\n : TValue extends object\n ? {\n readonly [TKey in Extract<keyof TValue, string>]:\n SWRNode<TValue[TKey]>;\n }\n : never;\n\nexport type SWRApp<TApp extends object> = SWRNode<TApp>;\n\nexport function createSWR<const TApp extends object>(\n app: TApp,\n options: {\n readonly keyPrefix?: readonly unknown[];\n } = {},\n): SWRApp<TApp> {\n const keyPrefix = Object.freeze([...(options.keyPrefix ?? [\"capable\"])]);\n\n const callableAt = (path: readonly string[]): CapabilityCall => {\n let current: unknown = app;\n for (const segment of path) {\n current = (current as Record<string, unknown>)[segment];\n }\n return current as CapabilityCall;\n };\n\n const capabilityKey = (\n path: readonly string[],\n input?: unknown,\n ): CapabilitySWRKey => Object.freeze([\n ...keyPrefix,\n ...path,\n ...(input === undefined ? [] : [input]),\n ]) as CapabilitySWRKey;\n\n const withOptions = (\n key: CapabilitySWRKey,\n operation: (...args: any[]) => unknown,\n hookOptions: unknown,\n ): readonly unknown[] => hookOptions === undefined\n ? [key, operation]\n : [key, operation, hookOptions];\n\n const proxy = (path: readonly string[]): unknown =>\n new Proxy({}, {\n get(_target, key) {\n if (key === \"then\") return undefined;\n if (key === \"key\") {\n return (input?: unknown) => capabilityKey(path, input);\n }\n if (key === \"swr\") {\n return (input: unknown, swrOptions?: unknown) => withOptions(\n capabilityKey(path, input),\n () => callableAt(path)(input),\n swrOptions,\n );\n }\n if (key === \"mutation\") {\n return (mutationOptions?: unknown) => withOptions(\n capabilityKey(path),\n (_key: CapabilitySWRKey, { arg }: { readonly arg?: unknown }) =>\n callableAt(path)(arg),\n mutationOptions,\n );\n }\n if (key === \"subscription\") {\n return (input: unknown, subscriptionOptions?: unknown) => withOptions(\n capabilityKey(path, input),\n (\n _key: CapabilitySWRKey,\n { next }: {\n readonly next: (error?: Error | null, data?: unknown) => void;\n },\n ) => {\n const controller = new AbortController();\n\n void (async () => {\n try {\n for await (const output of subscribeCall(\n callableAt(path),\n input,\n { signal: controller.signal },\n )) {\n next(null, output);\n }\n } catch (error) {\n if (!controller.signal.aborted) {\n next(toError(error));\n }\n }\n })();\n\n return () => controller.abort();\n },\n subscriptionOptions,\n );\n }\n if (typeof key !== \"string\") return undefined;\n return proxy([...path, key]);\n },\n });\n\n return proxy([]) as SWRApp<TApp>;\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n"],"mappings":";;AAgBA,MAAM,gBAAgB;AA6HtB,SAAgB,UACd,KACA,UAEI,CAAC,GACS;CACd,MAAM,YAAY,OAAO,OAAO,CAAC,GAAI,QAAQ,aAAa,CAAC,SAAS,CAAE,CAAC;CAEvE,MAAM,cAAc,SAA4C;EAC9D,IAAI,UAAmB;EACvB,KAAK,MAAM,WAAW,MACpB,UAAW,QAAoC;EAEjD,OAAO;CACT;CAEA,MAAM,iBACJ,MACA,UACqB,OAAO,OA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OAAO,KAAK,CAAC;AACjE"}
@@ -413,6 +413,21 @@ duplicated, or leaky implementation work as it appears.
413
413
  The projection's `key`, `swr`, `mutation`, and `subscription` member names are
414
414
  reserved until App leaves have synchronous metadata.
415
415
 
416
+ ## 2026-08-05 — npm pack silently accepted missing export targets
417
+
418
+ - **Observed:** `capable-kit@0.0.1-alpha.6` advertised the new `next`,
419
+ `react-query`, and `swr` subpaths, but the publishing worktree's ignored
420
+ `dist/` directory did not contain their built files. npm included the export
421
+ map without warning and published a tarball with phantom entry points.
422
+ - **Why it matters:** Type-aware tooling could see the intended API while every
423
+ runtime import failed. A successful source build in another worktree did not
424
+ prove the contents of the worktree used for publishing.
425
+ - **Current choice:** `prepack` builds from source, verifies every export and bin
426
+ target, and only then assembles documentation. The package test independently
427
+ checks that every manifest target appears in the produced tarball.
428
+ - **Follow-up:** Keep release validation tarball-based; do not treat an ignored
429
+ local `dist/` directory or a source-level test as publication evidence.
430
+
416
431
  ## 2026-07-28 — A fresh Next.js build can race SQLite initialization
417
432
 
418
433
  - **Observed:** Next.js page-data collection imports the authenticated Todo
@@ -0,0 +1,137 @@
1
+ import { existsSync } from "node:fs";
2
+ import {
3
+ cp,
4
+ mkdir,
5
+ readdir,
6
+ readFile,
7
+ rm,
8
+ writeFile,
9
+ } from "node:fs/promises";
10
+ import { dirname, join, relative } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ const repositoryDirectory = new URL("../../", import.meta.url);
14
+ const outputDirectory = new URL("./docs/", import.meta.url);
15
+ const canonicalSiteDirectory = new URL("./website/app/", repositoryDirectory);
16
+ const packagedSiteDirectory = new URL("./site/", outputDirectory);
17
+ const canonicalDocumentationAvailable = [
18
+ new URL("./CONTEXT.md", repositoryDirectory),
19
+ new URL("./docs/", repositoryDirectory),
20
+ canonicalSiteDirectory,
21
+ ].every(existsSync);
22
+
23
+ async function findPages(directory) {
24
+ const entries = await readdir(directory, { withFileTypes: true });
25
+ const nested = await Promise.all(
26
+ entries.map((entry) => {
27
+ const path = join(directory, entry.name);
28
+ if (entry.isDirectory()) return findPages(path);
29
+ return entry.name === "page.mdx" ? [path] : [];
30
+ }),
31
+ );
32
+ return nested.flat();
33
+ }
34
+
35
+ function titleSlug(source, file) {
36
+ const title = source.match(/^title:\s*"([^"]+)"$/m)?.[1];
37
+ if (!title) throw new Error(`Missing title frontmatter in ${file}`);
38
+
39
+ return title
40
+ .normalize("NFKD")
41
+ .replace(/[\u0300-\u036f]/g, "")
42
+ .replace(/[^a-zA-Z0-9]+/g, "-")
43
+ .replace(/^-|-$/g, "")
44
+ .toLowerCase();
45
+ }
46
+
47
+ async function copyPublicGuides() {
48
+ const sourceRoot = fileURLToPath(canonicalSiteDirectory);
49
+ const outputRoot = fileURLToPath(packagedSiteDirectory);
50
+
51
+ for (const page of await findPages(sourceRoot)) {
52
+ const source = await readFile(page, "utf8");
53
+ const routeDirectory = relative(sourceRoot, dirname(page));
54
+ const section =
55
+ routeDirectory === "" ? "" : dirname(routeDirectory);
56
+ const destinationDirectory = join(
57
+ outputRoot,
58
+ section === "." ? "" : section,
59
+ );
60
+
61
+ await mkdir(destinationDirectory, { recursive: true });
62
+ await writeFile(
63
+ join(destinationDirectory, `${titleSlug(source, page)}.mdx`),
64
+ source,
65
+ );
66
+ }
67
+ }
68
+
69
+ async function copyDocumentation() {
70
+ // A tarball can be packed again after installation. In that case the
71
+ // canonical repository sources are absent and the included docs are already
72
+ // the correct input.
73
+ if (!canonicalDocumentationAvailable) {
74
+ if (existsSync(outputDirectory)) return;
75
+ throw new Error("Could not find Capable's canonical documentation sources.");
76
+ }
77
+
78
+ await rm(outputDirectory, { force: true, recursive: true });
79
+ await mkdir(outputDirectory, { recursive: true });
80
+
81
+ await Promise.all([
82
+ cp(
83
+ new URL("./docs/", repositoryDirectory),
84
+ new URL("./internal/", outputDirectory),
85
+ { recursive: true },
86
+ ),
87
+ cp(
88
+ new URL("./CONTEXT.md", repositoryDirectory),
89
+ new URL("./CONTEXT.md", outputDirectory),
90
+ ),
91
+ copyPublicGuides(),
92
+ ]);
93
+
94
+ await writeFile(
95
+ new URL("./README.md", outputDirectory),
96
+ `# Capable documentation
97
+
98
+ This directory is assembled from Capable's canonical documentation sources when
99
+ the npm package is packed. It matches the installed package version.
100
+
101
+ ## For coding agents
102
+
103
+ Do not rely on remembered Capable APIs. Read the relevant bundled guide and
104
+ inspect \`../src/\` when you need a detail the guides do not cover.
105
+
106
+ Start here:
107
+
108
+ 1. [Introduction](./site/introduction.mdx)
109
+ 2. [Quickstart](./site/quickstart.mdx)
110
+ 3. [Capabilities](./site/concepts/capabilities.mdx)
111
+ 4. [Apps](./site/concepts/apps.mdx)
112
+ 5. [Surfaces](./site/surfaces.mdx)
113
+ 6. [Packages and entry points](./site/reference/packages-and-entry-points.mdx)
114
+
115
+ Public guides are grouped by section and named from their frontmatter titles.
116
+ To find a topic, search the files under \`site/\` or list its \`.mdx\` files.
117
+
118
+ - \`site/\` contains the canonical, human- and agent-readable MDX guides.
119
+ - \`internal/\` contains design notes for contributors.
120
+ - \`CONTEXT.md\` defines the framework's domain language and invariants.
121
+
122
+ The canonical sources live in \`website/\`, \`docs/\`, and \`CONTEXT.md\` in the
123
+ Capable repository. Edit those sources rather than the generated package copy.
124
+ `,
125
+ );
126
+ }
127
+
128
+ async function cleanDocumentation() {
129
+ if (!canonicalDocumentationAvailable) return;
130
+ await rm(outputDirectory, { force: true, recursive: true });
131
+ }
132
+
133
+ if (process.argv.includes("--clean")) {
134
+ await cleanDocumentation();
135
+ } else {
136
+ await copyDocumentation();
137
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capable-kit",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.0.1-alpha.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "cap": "dist/bin.mjs",
@@ -61,14 +61,17 @@
61
61
  "dist/*.mjs",
62
62
  "dist/*.mjs.map",
63
63
  "docs",
64
+ "package-docs.mjs",
65
+ "prepare-package.mjs",
64
66
  "src",
67
+ "verify-package-exports.mjs",
65
68
  "README.md"
66
69
  ],
67
70
  "directories": {
68
71
  "doc": "./docs"
69
72
  },
70
73
  "scripts": {
71
- "prepack": "node package-docs.mjs",
74
+ "prepack": "node prepare-package.mjs",
72
75
  "postpack": "node package-docs.mjs --clean"
73
76
  },
74
77
  "engines": {
@@ -0,0 +1,21 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const repositorySource = new URL("../../packages/capable/src/index.ts", import.meta.url);
6
+ if (existsSync(repositorySource)) {
7
+ const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
8
+ const build = spawnSync(pnpm, ["--dir", "../..", "build"], {
9
+ cwd: fileURLToPath(new URL("./", import.meta.url)),
10
+ encoding: "utf8",
11
+ });
12
+
13
+ if (build.status !== 0) {
14
+ process.stderr.write(build.stdout ?? "");
15
+ process.stderr.write(build.stderr ?? "");
16
+ process.exit(build.status ?? 1);
17
+ }
18
+ }
19
+
20
+ await import("./verify-package-exports.mjs");
21
+ await import("./package-docs.mjs");
@@ -28,24 +28,29 @@ describe("published package", () => {
28
28
 
29
29
  try {
30
30
  const output = execFileSync(
31
- "pnpm",
31
+ "npm",
32
32
  ["pack", "--json", "--pack-destination", destination],
33
33
  {
34
34
  cwd: packageDirectory,
35
35
  encoding: "utf8",
36
36
  },
37
37
  );
38
- const result = JSON.parse(output) as PackResult;
38
+ const result = findPackResult(JSON.parse(output));
39
39
  const paths = new Set(result.files.map((file) => file.path));
40
+ const archive = join(destination, result.filename);
40
41
  const manifest = JSON.parse(
41
42
  execFileSync(
42
43
  "tar",
43
- ["-xOzf", result.filename, "package/package.json"],
44
+ ["-xOzf", archive, "package/package.json"],
44
45
  { encoding: "utf8" },
45
46
  ),
46
47
  ) as {
48
+ readonly bin?: Readonly<Record<string, string>>;
47
49
  readonly directories?: { readonly doc?: string };
48
- readonly exports?: Readonly<Record<string, unknown>>;
50
+ readonly exports?: Readonly<Record<
51
+ string,
52
+ string | Readonly<Record<string, string>>
53
+ >>;
49
54
  readonly peerDependenciesMeta?: Readonly<Record<
50
55
  string,
51
56
  { readonly optional?: boolean }
@@ -56,7 +61,7 @@ describe("published package", () => {
56
61
  "tar",
57
62
  [
58
63
  "-xOzf",
59
- result.filename,
64
+ archive,
60
65
  "package/docs/site/quickstart.mdx",
61
66
  ],
62
67
  { encoding: "utf8" },
@@ -94,10 +99,14 @@ describe("published package", () => {
94
99
  (path) => path.startsWith("dist/package/") || path.endsWith(".tgz"),
95
100
  ),
96
101
  ).toBe(false);
97
- expect(paths).not.toContain("package-docs.mjs");
102
+ expect(paths).toContain("package-docs.mjs");
103
+ expect(paths).toContain("prepare-package.mjs");
104
+ expect(paths).toContain("verify-package-exports.mjs");
98
105
  expect(manifest.directories?.doc).toBe("./docs");
99
- expect(manifest.scripts?.prepack).toBeUndefined();
100
- expect(manifest.scripts?.postpack).toBeUndefined();
106
+ expect(manifest.scripts).toMatchObject({
107
+ prepack: "node prepare-package.mjs",
108
+ postpack: "node package-docs.mjs --clean",
109
+ });
101
110
  expect(Object.keys(manifest.exports ?? {})).toEqual([
102
111
  ".",
103
112
  "./ai-sdk",
@@ -116,6 +125,21 @@ describe("published package", () => {
116
125
  "@tanstack/react-query": { optional: true },
117
126
  swr: { optional: true },
118
127
  });
128
+ for (const [entryPoint, conditions] of Object.entries(
129
+ manifest.exports ?? {},
130
+ )) {
131
+ const targets = typeof conditions === "string"
132
+ ? [conditions]
133
+ : Object.values(conditions);
134
+ for (const target of targets) {
135
+ expect(paths, `${entryPoint} -> ${target}`).toContain(
136
+ target.replace(/^\.\//, ""),
137
+ );
138
+ }
139
+ }
140
+ for (const [command, target] of Object.entries(manifest.bin ?? {})) {
141
+ expect(paths, `bin:${command} -> ${target}`).toContain(target);
142
+ }
119
143
  expect(quickstart).toMatch(
120
144
  /^---\ntitle: "Quickstart"\ndescription: ".+"\n---/,
121
145
  );
@@ -155,3 +179,15 @@ describe("published package", () => {
155
179
  }
156
180
  });
157
181
  });
182
+
183
+ function findPackResult(value: unknown): PackResult {
184
+ if (Array.isArray(value)) return findPackResult(value[0]);
185
+ if (typeof value !== "object" || value === null) {
186
+ throw new Error("npm pack did not return a package");
187
+ }
188
+ if ("filename" in value && "files" in value) return value as PackResult;
189
+
190
+ const nested = Object.values(value);
191
+ if (nested.length === 1) return findPackResult(nested[0]);
192
+ throw new Error("npm pack returned an unknown result shape");
193
+ }
@@ -0,0 +1,37 @@
1
+ import { access, readFile } from "node:fs/promises";
2
+
3
+ const packageDirectory = new URL("./", import.meta.url);
4
+ const manifest = JSON.parse(
5
+ await readFile(new URL("./package.json", packageDirectory), "utf8"),
6
+ );
7
+
8
+ const targets = [
9
+ ...Object.entries(manifest.exports ?? {}).flatMap(([entryPoint, conditions]) =>
10
+ typeof conditions === "string"
11
+ ? [[entryPoint, conditions]]
12
+ : Object.entries(conditions).map(([condition, target]) => [
13
+ `${entryPoint} (${condition})`,
14
+ target,
15
+ ]),
16
+ ),
17
+ ...Object.entries(manifest.bin ?? {}).map(([command, target]) => [
18
+ `bin:${command}`,
19
+ target,
20
+ ]),
21
+ ];
22
+
23
+ const missing = [];
24
+ for (const [label, target] of targets) {
25
+ if (typeof target !== "string") continue;
26
+ try {
27
+ await access(new URL(target, packageDirectory));
28
+ } catch {
29
+ missing.push(`${label} -> ${target}`);
30
+ }
31
+ }
32
+
33
+ if (missing.length > 0) {
34
+ throw new Error(
35
+ `Package manifest points to missing files:\n${missing.join("\n")}`,
36
+ );
37
+ }