@spoosh/core 0.13.0 → 0.13.1

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.mts CHANGED
@@ -592,6 +592,7 @@ type PluginTypeConfig = {
592
592
  readOptions?: object;
593
593
  writeOptions?: object;
594
594
  infiniteReadOptions?: object;
595
+ writeTriggerOptions?: object;
595
596
  readResult?: object;
596
597
  writeResult?: object;
597
598
  instanceApi?: object;
@@ -1019,6 +1020,9 @@ type ExtractWriteOptions<T> = T extends SpooshPlugin<infer Types> ? Types extend
1019
1020
  type ExtractInfiniteReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1020
1021
  infiniteReadOptions: infer I;
1021
1022
  } ? I : object : object;
1023
+ type ExtractWriteTriggerOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1024
+ writeTriggerOptions: infer W;
1025
+ } ? W : object : object;
1022
1026
  type ExtractReadResult<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1023
1027
  readResult: infer R;
1024
1028
  } ? R : object : object;
@@ -1033,6 +1037,7 @@ type MergePluginOptions<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>
1033
1037
  read: UnionToIntersection<ExtractReadOptions<TPlugins[number]>>;
1034
1038
  write: UnionToIntersection<ExtractWriteOptions<TPlugins[number]>>;
1035
1039
  infiniteRead: UnionToIntersection<ExtractInfiniteReadOptions<TPlugins[number]>>;
1040
+ writeTrigger: UnionToIntersection<ExtractWriteTriggerOptions<TPlugins[number]>>;
1036
1041
  };
1037
1042
  type MergePluginResults<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
1038
1043
  read: UnionToIntersection<ExtractReadResult<TPlugins[number]>>;
@@ -1408,6 +1413,22 @@ type WritePathMethods<TSchema, TPath extends string, TDefaultError> = FindMatchi
1408
1413
  * Used by useWrite and injectWrite hooks.
1409
1414
  */
1410
1415
  type WriteClient<TSchema, TDefaultError = unknown> = <TPath extends WritePaths<TSchema> | (string & {})>(path: TPath) => HasWriteMethod<TSchema, TPath> extends true ? WritePathMethods<TSchema, TPath, TDefaultError> : never;
1416
+ /**
1417
+ * Method function type for write selectors - accepts no arguments.
1418
+ * All input (body, query, params) is passed to trigger() instead.
1419
+ */
1420
+ type WriteSelectorMethodFn<TMethodConfig, TDefaultError, TUserPath extends string> = () => Promise<MethodResponse<TMethodConfig, TDefaultError, TUserPath>>;
1421
+ /**
1422
+ * Write selector path methods - methods accept no arguments.
1423
+ */
1424
+ type WriteSelectorPathMethods<TSchema, TPath extends string, TDefaultError> = FindMatchingKey<TSchema, TPath> extends infer TKey ? TKey extends keyof TSchema ? Simplify<{
1425
+ [M in WriteMethod as M extends keyof TSchema[TKey] ? M : never]: M extends keyof TSchema[TKey] ? WriteSelectorMethodFn<TSchema[TKey][M], TDefaultError, TPath> : never;
1426
+ }> : never : never;
1427
+ /**
1428
+ * Write selector client - methods accept no arguments.
1429
+ * Used by useWrite for selecting endpoints. All input goes to trigger().
1430
+ */
1431
+ type WriteSelectorClient<TSchema, TDefaultError = unknown> = <TPath extends WritePaths<TSchema> | (string & {})>(path: TPath) => HasWriteMethod<TSchema, TPath> extends true ? WriteSelectorPathMethods<TSchema, TPath, TDefaultError> : never;
1411
1432
 
1412
1433
  type PluginArray = readonly SpooshPlugin<PluginTypeConfig>[];
1413
1434
  interface SpooshConfig<TPlugins extends PluginArray = PluginArray> {
@@ -1465,7 +1486,7 @@ type SpooshInstance<TSchema = unknown, TDefaultError = unknown, TPlugins extends
1465
1486
  *
1466
1487
  * // In component
1467
1488
  * const { data } = useRead((api) => api("posts").GET());
1468
- * const { trigger } = useWrite((api) => api("posts").POST);
1489
+ * const { trigger } = useWrite((api) => api("posts").POST());
1469
1490
  * ```
1470
1491
  *
1471
1492
  * @since 0.1.0
@@ -1872,7 +1893,7 @@ declare function extractPathFromSelector(fn: unknown): string;
1872
1893
  * @example
1873
1894
  * ```ts
1874
1895
  * const proxy = createSelectorProxy<ApiSchema>();
1875
- * const method = extractMethodFromSelector(proxy("posts").POST);
1896
+ * const method = extractMethodFromSelector(proxy("posts").POST());
1876
1897
  * // method = 'POST'
1877
1898
  * ```
1878
1899
  */
@@ -1981,4 +2002,4 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
1981
2002
  };
1982
2003
  declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
1983
2004
 
1984
- export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
2005
+ export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
package/dist/index.d.ts CHANGED
@@ -592,6 +592,7 @@ type PluginTypeConfig = {
592
592
  readOptions?: object;
593
593
  writeOptions?: object;
594
594
  infiniteReadOptions?: object;
595
+ writeTriggerOptions?: object;
595
596
  readResult?: object;
596
597
  writeResult?: object;
597
598
  instanceApi?: object;
@@ -1019,6 +1020,9 @@ type ExtractWriteOptions<T> = T extends SpooshPlugin<infer Types> ? Types extend
1019
1020
  type ExtractInfiniteReadOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1020
1021
  infiniteReadOptions: infer I;
1021
1022
  } ? I : object : object;
1023
+ type ExtractWriteTriggerOptions<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1024
+ writeTriggerOptions: infer W;
1025
+ } ? W : object : object;
1022
1026
  type ExtractReadResult<T> = T extends SpooshPlugin<infer Types> ? Types extends {
1023
1027
  readResult: infer R;
1024
1028
  } ? R : object : object;
@@ -1033,6 +1037,7 @@ type MergePluginOptions<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>
1033
1037
  read: UnionToIntersection<ExtractReadOptions<TPlugins[number]>>;
1034
1038
  write: UnionToIntersection<ExtractWriteOptions<TPlugins[number]>>;
1035
1039
  infiniteRead: UnionToIntersection<ExtractInfiniteReadOptions<TPlugins[number]>>;
1040
+ writeTrigger: UnionToIntersection<ExtractWriteTriggerOptions<TPlugins[number]>>;
1036
1041
  };
1037
1042
  type MergePluginResults<TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]> = {
1038
1043
  read: UnionToIntersection<ExtractReadResult<TPlugins[number]>>;
@@ -1408,6 +1413,22 @@ type WritePathMethods<TSchema, TPath extends string, TDefaultError> = FindMatchi
1408
1413
  * Used by useWrite and injectWrite hooks.
1409
1414
  */
1410
1415
  type WriteClient<TSchema, TDefaultError = unknown> = <TPath extends WritePaths<TSchema> | (string & {})>(path: TPath) => HasWriteMethod<TSchema, TPath> extends true ? WritePathMethods<TSchema, TPath, TDefaultError> : never;
1416
+ /**
1417
+ * Method function type for write selectors - accepts no arguments.
1418
+ * All input (body, query, params) is passed to trigger() instead.
1419
+ */
1420
+ type WriteSelectorMethodFn<TMethodConfig, TDefaultError, TUserPath extends string> = () => Promise<MethodResponse<TMethodConfig, TDefaultError, TUserPath>>;
1421
+ /**
1422
+ * Write selector path methods - methods accept no arguments.
1423
+ */
1424
+ type WriteSelectorPathMethods<TSchema, TPath extends string, TDefaultError> = FindMatchingKey<TSchema, TPath> extends infer TKey ? TKey extends keyof TSchema ? Simplify<{
1425
+ [M in WriteMethod as M extends keyof TSchema[TKey] ? M : never]: M extends keyof TSchema[TKey] ? WriteSelectorMethodFn<TSchema[TKey][M], TDefaultError, TPath> : never;
1426
+ }> : never : never;
1427
+ /**
1428
+ * Write selector client - methods accept no arguments.
1429
+ * Used by useWrite for selecting endpoints. All input goes to trigger().
1430
+ */
1431
+ type WriteSelectorClient<TSchema, TDefaultError = unknown> = <TPath extends WritePaths<TSchema> | (string & {})>(path: TPath) => HasWriteMethod<TSchema, TPath> extends true ? WriteSelectorPathMethods<TSchema, TPath, TDefaultError> : never;
1411
1432
 
1412
1433
  type PluginArray = readonly SpooshPlugin<PluginTypeConfig>[];
1413
1434
  interface SpooshConfig<TPlugins extends PluginArray = PluginArray> {
@@ -1465,7 +1486,7 @@ type SpooshInstance<TSchema = unknown, TDefaultError = unknown, TPlugins extends
1465
1486
  *
1466
1487
  * // In component
1467
1488
  * const { data } = useRead((api) => api("posts").GET());
1468
- * const { trigger } = useWrite((api) => api("posts").POST);
1489
+ * const { trigger } = useWrite((api) => api("posts").POST());
1469
1490
  * ```
1470
1491
  *
1471
1492
  * @since 0.1.0
@@ -1872,7 +1893,7 @@ declare function extractPathFromSelector(fn: unknown): string;
1872
1893
  * @example
1873
1894
  * ```ts
1874
1895
  * const proxy = createSelectorProxy<ApiSchema>();
1875
- * const method = extractMethodFromSelector(proxy("posts").POST);
1896
+ * const method = extractMethodFromSelector(proxy("posts").POST());
1876
1897
  * // method = 'POST'
1877
1898
  * ```
1878
1899
  */
@@ -1981,4 +2002,4 @@ type CreateInfiniteReadOptions<TData, TItem, TError, TRequest> = {
1981
2002
  };
1982
2003
  declare function createInfiniteReadController<TData, TItem, TError, TRequest extends InfiniteRequestOptions = InfiniteRequestOptions>(options: CreateInfiniteReadOptions<TData, TItem, TError, TRequest>): InfiniteReadController<TData, TItem, TError>;
1983
2004
 
1984
- export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
2005
+ export { type AnyRequestOptions, type ApiSchema, type BuiltInEvents, type CacheEntry, type CacheEntryWithKey, type CapturedCall, type ComputeRequestOptions, type CoreRequestOptionsBase, type CreateInfiniteReadOptions, type CreateOperationOptions, type DataAwareCallback, type DataAwareTransform, type DevtoolEvents, type EventEmitter, type EventListener, type EventOptions, type EventTracer, type ExtractBody$1 as ExtractBody, type ExtractData, type ExtractError, type ExtractMethodOptions, type ExtractParamNames, type ExtractQuery$1 as ExtractQuery, type FetchDirection, type FetchExecutor, type FindMatchingKey, HTTP_METHODS, type HasParams, type HasReadMethod, type HasWriteMethod, type HeadersInitOrGetter, type HttpMethod, type HttpMethodKey, type InfiniteReadController, type InfiniteReadState, type InfiniteRequestOptions, type InstanceApiContext, type InstanceApiResolvers, type InstancePluginExecutor, type LifecyclePhase, type MergePluginInstanceApi, type MergePluginOptions, type MergePluginResults, type MethodOptionsMap, type OperationController, type OperationState, type OperationType, type PageContext, type PluginAccessor, type PluginArray, type PluginContext, type PluginContextBase, type PluginContextExtensions, type PluginContextInput, type PluginExecutor, type PluginExportsRegistry, type PluginFactory, type PluginHandler, type PluginLifecycle, type PluginMiddleware, type PluginRegistry, type PluginRequestOptions, type PluginResolvers, type PluginResponseHandler, type PluginResultResolvers, type PluginTypeConfig, type PluginUpdateHandler, type ReadClient, type ReadPaths, type ReadSchemaHelper, type RefetchEvent, type RequestCompleteEvent, type RequestOptions$1 as RequestOptions, type RequestTracer, type ResolveInstanceApi, type ResolveResultTypes, type ResolveSchemaTypes, type ResolveTypes, type ResolverContext, type SchemaPaths, type SelectedEndpoint, type SelectorFunction, type SelectorResult, type SetupContext, type Simplify, Spoosh, type SpooshBody, type SpooshClient, type SpooshConfig, type SpooshInstance, type SpooshOptions, type SpooshOptionsInput, type SpooshPlugin, type SpooshResponse, type SpooshSchema, type StandaloneEvent, type StateManager, type StripPrefix, type TagMode, type TagOptions, type Trace, type TraceColor, type TraceEvent, type TraceInfo, type TraceListener, type TraceOptions, type TraceStage, type Transport, type TransportOption, type TransportOptionsMap, type TransportResponse, type WriteClient, type WriteMethod, type WritePaths, type WriteSchemaHelper, type WriteSelectorClient, __DEV__, buildUrl, clone, containsFile, createClient, createEventEmitter, createInfiniteReadController, createInitialState, createOperationController, createPluginExecutor, createPluginRegistry, createProxyHandler, createSelectorProxy, createStateManager, createTracer, executeFetch, extractMethodFromSelector, extractPathFromSelector, fetchTransport, form, generateTags, getContentType, isAbortError, isJsonBody, isNetworkError, isSpooshBody, json, mergeHeaders, objectToFormData, objectToUrlEncoded, resolveHeadersToRecord, resolvePath, resolveRequestBody, resolveTags, setHeaders, sortObjectKeys, urlencoded, xhrTransport };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/core",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "license": "MIT",
5
5
  "description": "Type-safe API toolkit with plugin middleware system",
6
6
  "keywords": [