@spoosh/core 0.2.2 → 0.3.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/README.md +12 -15
- package/dist/index.d.mts +12 -65
- package/dist/index.d.ts +12 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,25 +65,22 @@ const { data: newUser } = await api.users.$post({
|
|
|
65
65
|
body: { name: "John", email: "john@example.com" },
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
// GET /api/users/123 (
|
|
69
|
-
const { data: user } = await api.users
|
|
68
|
+
// GET /api/users/123 (direct usage - simplest)
|
|
69
|
+
const { data: user } = await api.users(123).$get();
|
|
70
70
|
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
// Alternative bracket syntaxes (less recommended):
|
|
77
|
-
// api.users[":userId"].$get() - works but no type inference for params
|
|
78
|
-
// api.users[userId].$get() - works with variable, no type inference
|
|
79
|
-
|
|
80
|
-
// PUT /api/users/123
|
|
81
|
-
const { data: updated } = await api.users[123].$put({
|
|
71
|
+
// PUT /api/users/123 (with variable)
|
|
72
|
+
const userId = 123;
|
|
73
|
+
const { data: updated } = await api.users(userId).$put({
|
|
82
74
|
body: { name: "John Updated" },
|
|
83
75
|
});
|
|
84
76
|
|
|
85
77
|
// DELETE /api/users/123
|
|
86
|
-
await api.users
|
|
78
|
+
await api.users(123).$delete();
|
|
79
|
+
|
|
80
|
+
// Typed params (advanced - when you need explicit param names)
|
|
81
|
+
const { data } = await api.users(":userId").$get({
|
|
82
|
+
params: { userId: 123 },
|
|
83
|
+
});
|
|
87
84
|
|
|
88
85
|
// POST with FormData
|
|
89
86
|
const { data: uploaded } = await api.upload.$post({
|
|
@@ -124,7 +121,7 @@ const api = createClient<ApiSchema>({ baseUrl: process.env.API_URL! });
|
|
|
124
121
|
const { data: posts } = await api.posts.$get();
|
|
125
122
|
|
|
126
123
|
// Auto-generates next: { tags: ['users', 'users/123', 'users/123/posts'] }
|
|
127
|
-
const { data: userPosts } = await api.users
|
|
124
|
+
const { data: userPosts } = await api.users(123).posts.$get();
|
|
128
125
|
```
|
|
129
126
|
|
|
130
127
|
This enables automatic cache invalidation with `revalidateTag()` in Next.js.
|
package/dist/index.d.mts
CHANGED
|
@@ -787,7 +787,7 @@ type HasMethod<TSchema, TMethod extends SchemaMethod> = TSchema extends {
|
|
|
787
787
|
} ? true : false;
|
|
788
788
|
type HasRequiredOptions<TSchema, TMethod extends SchemaMethod, TDefaultError = unknown> = [ExtractBody<TSchema, TMethod, TDefaultError>] extends [never] ? [ExtractFormData<TSchema, TMethod, TDefaultError>] extends [never] ? [ExtractUrlEncoded<TSchema, TMethod, TDefaultError>] extends [never] ? false : true : true : true;
|
|
789
789
|
|
|
790
|
-
type ExtractParamName$1<S
|
|
790
|
+
type ExtractParamName$1<S> = S extends `:${infer P}` ? P : never;
|
|
791
791
|
type MethodRequestOptions<TSchema, TMethod extends SchemaMethod, TDefaultError, TOptionsMap, TParamNames extends string, TRequired extends boolean> = TRequired extends true ? RequestOptions<ExtractBody<TSchema, TMethod, TDefaultError>, ExtractQuery<TSchema, TMethod, TDefaultError>, ExtractFormData<TSchema, TMethod, TDefaultError>, ExtractUrlEncoded<TSchema, TMethod, TDefaultError>> & ComputeRequestOptions<ExtractMethodOptions<TOptionsMap, TMethod>, TParamNames> : RequestOptions<never, ExtractQuery<TSchema, TMethod, TDefaultError>, never, never> & ComputeRequestOptions<ExtractMethodOptions<TOptionsMap, TMethod>, TParamNames>;
|
|
792
792
|
type MethodFn<TSchema, TMethod extends SchemaMethod, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = HasMethod<TSchema, TMethod> extends true ? HasRequiredOptions<TSchema, TMethod, TDefaultError> extends true ? (options: MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, true>) => Promise<SpooshResponse<ExtractData<TSchema, TMethod, TDefaultError>, ExtractError<TSchema, TMethod, TDefaultError>, MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, true>, ExtractQuery<TSchema, TMethod, TDefaultError>, ExtractBody<TSchema, TMethod, TDefaultError>, ExtractFormData<TSchema, TMethod, TDefaultError>, ExtractUrlEncoded<TSchema, TMethod, TDefaultError>, TParamNames>> : (options?: MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, false>) => Promise<SpooshResponse<ExtractData<TSchema, TMethod, TDefaultError>, ExtractError<TSchema, TMethod, TDefaultError>, MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, false>, ExtractQuery<TSchema, TMethod, TDefaultError>, ExtractBody<TSchema, TMethod, TDefaultError>, ExtractFormData<TSchema, TMethod, TDefaultError>, ExtractUrlEncoded<TSchema, TMethod, TDefaultError>, TParamNames>> : never;
|
|
793
793
|
type IsSpecialKey<K> = K extends SchemaMethod | "_" ? true : false;
|
|
@@ -801,7 +801,6 @@ type HttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamN
|
|
|
801
801
|
[K in SchemaMethod as K extends keyof TSchema ? K : never]: MethodFn<TSchema, K, TDefaultError, TOptionsMap, TParamNames>;
|
|
802
802
|
};
|
|
803
803
|
type DynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = ExtractDynamicSchema<TSchema> extends never ? object : {
|
|
804
|
-
[key: string]: SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
805
804
|
[key: number]: SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
806
805
|
/**
|
|
807
806
|
* Dynamic path segment with typed param name.
|
|
@@ -809,27 +808,16 @@ type DynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TPara
|
|
|
809
808
|
*
|
|
810
809
|
* @example
|
|
811
810
|
* ```ts
|
|
812
|
-
* //
|
|
811
|
+
* // With number
|
|
812
|
+
* await api.users(123).$get()
|
|
813
|
+
*
|
|
814
|
+
* // With typed params
|
|
813
815
|
* const { data, params } = await api.users(':userId').$get({ params: { userId: 123 } })
|
|
814
816
|
* ```
|
|
815
817
|
*/
|
|
816
|
-
<TKey extends string>(key: TKey): SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | ExtractParamName$1<TKey>, TRootSchema>;
|
|
818
|
+
<TKey extends string | number>(key: TKey): SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | ExtractParamName$1<TKey>, TRootSchema>;
|
|
817
819
|
};
|
|
818
|
-
type
|
|
819
|
-
_: infer D;
|
|
820
|
-
} ? {
|
|
821
|
-
/**
|
|
822
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
823
|
-
*
|
|
824
|
-
* @example
|
|
825
|
-
* ```ts
|
|
826
|
-
* // Direct client usage
|
|
827
|
-
* const { data } = await api.posts._.$get({ params: { id: 123 } })
|
|
828
|
-
* ```
|
|
829
|
-
*/
|
|
830
|
-
_: SpooshClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
831
|
-
} : object;
|
|
832
|
-
type SpooshClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = HttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & DynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & DynamicKey<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
820
|
+
type SpooshClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = HttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & DynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
833
821
|
[K in keyof StaticPathKeys<TSchema> as K extends SchemaMethod ? never : K]: SpooshClient<TSchema[K], TDefaultError, TOptionsMap, TParamNames, TRootSchema>;
|
|
834
822
|
};
|
|
835
823
|
|
|
@@ -852,29 +840,14 @@ type HasMutationMethods<TSchema> = TSchema extends object ? MutationMethod exten
|
|
|
852
840
|
type QueryHttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = {
|
|
853
841
|
[K in QueryMethod as K extends keyof TSchema ? K : never]: MethodFn<TSchema, K, TDefaultError, TOptionsMap, TParamNames>;
|
|
854
842
|
};
|
|
855
|
-
type ExtractParamName<S
|
|
843
|
+
type ExtractParamName<S> = S extends `:${infer P}` ? P : never;
|
|
856
844
|
type QueryDynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = TSchema extends {
|
|
857
845
|
_: infer D;
|
|
858
846
|
} ? HasQueryMethods<D> extends true ? {
|
|
859
|
-
[key: string]: QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
860
847
|
[key: number]: QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
861
|
-
<TKey extends string>(key: TKey): QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>, TRootSchema>;
|
|
848
|
+
<TKey extends string | number>(key: TKey): QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>, TRootSchema>;
|
|
862
849
|
} : object : object;
|
|
863
|
-
type
|
|
864
|
-
_: infer D;
|
|
865
|
-
} ? HasQueryMethods<D> extends true ? {
|
|
866
|
-
/**
|
|
867
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
868
|
-
*
|
|
869
|
-
* @example
|
|
870
|
-
* ```ts
|
|
871
|
-
* useRead((api) => api.posts[123].$get())
|
|
872
|
-
* useRead((api) => api.posts(':id').$get({ params: { id: 123 } }))
|
|
873
|
-
* ```
|
|
874
|
-
*/
|
|
875
|
-
_: QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
876
|
-
} : object : object;
|
|
877
|
-
type QueryOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = QueryHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & QueryDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & QueryDynamicKey<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
850
|
+
type QueryOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = QueryHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & QueryDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
878
851
|
[K in keyof StaticPathKeys<TSchema> as K extends SchemaMethod ? never : HasQueryMethods<TSchema[K]> extends true ? K : never]: QueryOnlyClient<TSchema[K], TDefaultError, TOptionsMap, TParamNames, TRootSchema>;
|
|
879
852
|
};
|
|
880
853
|
type MutationHttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = {
|
|
@@ -883,25 +856,10 @@ type MutationHttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object,
|
|
|
883
856
|
type MutationDynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = TSchema extends {
|
|
884
857
|
_: infer D;
|
|
885
858
|
} ? HasMutationMethods<D> extends true ? {
|
|
886
|
-
[key: string]: MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string>;
|
|
887
859
|
[key: number]: MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string>;
|
|
888
|
-
<TKey extends string>(key: TKey): MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>>;
|
|
889
|
-
} : object : object;
|
|
890
|
-
type MutationDynamicKey<TSchema, TDefaultError, TOptionsMap, TParamNames extends string = never> = TSchema extends {
|
|
891
|
-
_: infer D;
|
|
892
|
-
} ? HasMutationMethods<D> extends true ? {
|
|
893
|
-
/**
|
|
894
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
895
|
-
*
|
|
896
|
-
* @example
|
|
897
|
-
* ```ts
|
|
898
|
-
* const { trigger } = useWrite((api) => api.posts(':id').$delete)
|
|
899
|
-
* trigger({ params: { id: 123 } })
|
|
900
|
-
* ```
|
|
901
|
-
*/
|
|
902
|
-
_: MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string>;
|
|
860
|
+
<TKey extends string | number>(key: TKey): MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>>;
|
|
903
861
|
} : object : object;
|
|
904
|
-
type MutationOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = MutationHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & MutationDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames> &
|
|
862
|
+
type MutationOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = MutationHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & MutationDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames> & {
|
|
905
863
|
[K in keyof StaticPathKeys<TSchema> as K extends SchemaMethod ? never : HasMutationMethods<TSchema[K]> extends true ? K : never]: MutationOnlyClient<TSchema[K], TDefaultError, TOptionsMap, TParamNames>;
|
|
906
864
|
};
|
|
907
865
|
|
|
@@ -961,17 +919,6 @@ type QuerySchemaHelper<TSchema> = {
|
|
|
961
919
|
} & (TSchema extends {
|
|
962
920
|
_: infer D;
|
|
963
921
|
} ? HasQueryMethods<D> extends true ? {
|
|
964
|
-
/**
|
|
965
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
966
|
-
*
|
|
967
|
-
* @example
|
|
968
|
-
* ```ts
|
|
969
|
-
* // In plugin callback - reference the endpoint
|
|
970
|
-
* myCallback: (api) => api.posts._.$get
|
|
971
|
-
* ```
|
|
972
|
-
*/
|
|
973
|
-
_: QuerySchemaHelper<D>;
|
|
974
|
-
[key: string]: QuerySchemaHelper<D>;
|
|
975
922
|
[key: number]: QuerySchemaHelper<D>;
|
|
976
923
|
} : object : object);
|
|
977
924
|
|
package/dist/index.d.ts
CHANGED
|
@@ -787,7 +787,7 @@ type HasMethod<TSchema, TMethod extends SchemaMethod> = TSchema extends {
|
|
|
787
787
|
} ? true : false;
|
|
788
788
|
type HasRequiredOptions<TSchema, TMethod extends SchemaMethod, TDefaultError = unknown> = [ExtractBody<TSchema, TMethod, TDefaultError>] extends [never] ? [ExtractFormData<TSchema, TMethod, TDefaultError>] extends [never] ? [ExtractUrlEncoded<TSchema, TMethod, TDefaultError>] extends [never] ? false : true : true : true;
|
|
789
789
|
|
|
790
|
-
type ExtractParamName$1<S
|
|
790
|
+
type ExtractParamName$1<S> = S extends `:${infer P}` ? P : never;
|
|
791
791
|
type MethodRequestOptions<TSchema, TMethod extends SchemaMethod, TDefaultError, TOptionsMap, TParamNames extends string, TRequired extends boolean> = TRequired extends true ? RequestOptions<ExtractBody<TSchema, TMethod, TDefaultError>, ExtractQuery<TSchema, TMethod, TDefaultError>, ExtractFormData<TSchema, TMethod, TDefaultError>, ExtractUrlEncoded<TSchema, TMethod, TDefaultError>> & ComputeRequestOptions<ExtractMethodOptions<TOptionsMap, TMethod>, TParamNames> : RequestOptions<never, ExtractQuery<TSchema, TMethod, TDefaultError>, never, never> & ComputeRequestOptions<ExtractMethodOptions<TOptionsMap, TMethod>, TParamNames>;
|
|
792
792
|
type MethodFn<TSchema, TMethod extends SchemaMethod, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = HasMethod<TSchema, TMethod> extends true ? HasRequiredOptions<TSchema, TMethod, TDefaultError> extends true ? (options: MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, true>) => Promise<SpooshResponse<ExtractData<TSchema, TMethod, TDefaultError>, ExtractError<TSchema, TMethod, TDefaultError>, MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, true>, ExtractQuery<TSchema, TMethod, TDefaultError>, ExtractBody<TSchema, TMethod, TDefaultError>, ExtractFormData<TSchema, TMethod, TDefaultError>, ExtractUrlEncoded<TSchema, TMethod, TDefaultError>, TParamNames>> : (options?: MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, false>) => Promise<SpooshResponse<ExtractData<TSchema, TMethod, TDefaultError>, ExtractError<TSchema, TMethod, TDefaultError>, MethodRequestOptions<TSchema, TMethod, TDefaultError, TOptionsMap, TParamNames, false>, ExtractQuery<TSchema, TMethod, TDefaultError>, ExtractBody<TSchema, TMethod, TDefaultError>, ExtractFormData<TSchema, TMethod, TDefaultError>, ExtractUrlEncoded<TSchema, TMethod, TDefaultError>, TParamNames>> : never;
|
|
793
793
|
type IsSpecialKey<K> = K extends SchemaMethod | "_" ? true : false;
|
|
@@ -801,7 +801,6 @@ type HttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamN
|
|
|
801
801
|
[K in SchemaMethod as K extends keyof TSchema ? K : never]: MethodFn<TSchema, K, TDefaultError, TOptionsMap, TParamNames>;
|
|
802
802
|
};
|
|
803
803
|
type DynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = ExtractDynamicSchema<TSchema> extends never ? object : {
|
|
804
|
-
[key: string]: SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
805
804
|
[key: number]: SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
806
805
|
/**
|
|
807
806
|
* Dynamic path segment with typed param name.
|
|
@@ -809,27 +808,16 @@ type DynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TPara
|
|
|
809
808
|
*
|
|
810
809
|
* @example
|
|
811
810
|
* ```ts
|
|
812
|
-
* //
|
|
811
|
+
* // With number
|
|
812
|
+
* await api.users(123).$get()
|
|
813
|
+
*
|
|
814
|
+
* // With typed params
|
|
813
815
|
* const { data, params } = await api.users(':userId').$get({ params: { userId: 123 } })
|
|
814
816
|
* ```
|
|
815
817
|
*/
|
|
816
|
-
<TKey extends string>(key: TKey): SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | ExtractParamName$1<TKey>, TRootSchema>;
|
|
818
|
+
<TKey extends string | number>(key: TKey): SpooshClient<ExtractDynamicSchema<TSchema>, TDefaultError, TOptionsMap, TParamNames | ExtractParamName$1<TKey>, TRootSchema>;
|
|
817
819
|
};
|
|
818
|
-
type
|
|
819
|
-
_: infer D;
|
|
820
|
-
} ? {
|
|
821
|
-
/**
|
|
822
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
823
|
-
*
|
|
824
|
-
* @example
|
|
825
|
-
* ```ts
|
|
826
|
-
* // Direct client usage
|
|
827
|
-
* const { data } = await api.posts._.$get({ params: { id: 123 } })
|
|
828
|
-
* ```
|
|
829
|
-
*/
|
|
830
|
-
_: SpooshClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
831
|
-
} : object;
|
|
832
|
-
type SpooshClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = HttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & DynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & DynamicKey<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
820
|
+
type SpooshClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = HttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & DynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
833
821
|
[K in keyof StaticPathKeys<TSchema> as K extends SchemaMethod ? never : K]: SpooshClient<TSchema[K], TDefaultError, TOptionsMap, TParamNames, TRootSchema>;
|
|
834
822
|
};
|
|
835
823
|
|
|
@@ -852,29 +840,14 @@ type HasMutationMethods<TSchema> = TSchema extends object ? MutationMethod exten
|
|
|
852
840
|
type QueryHttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = {
|
|
853
841
|
[K in QueryMethod as K extends keyof TSchema ? K : never]: MethodFn<TSchema, K, TDefaultError, TOptionsMap, TParamNames>;
|
|
854
842
|
};
|
|
855
|
-
type ExtractParamName<S
|
|
843
|
+
type ExtractParamName<S> = S extends `:${infer P}` ? P : never;
|
|
856
844
|
type QueryDynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = TSchema extends {
|
|
857
845
|
_: infer D;
|
|
858
846
|
} ? HasQueryMethods<D> extends true ? {
|
|
859
|
-
[key: string]: QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
860
847
|
[key: number]: QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
861
|
-
<TKey extends string>(key: TKey): QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>, TRootSchema>;
|
|
848
|
+
<TKey extends string | number>(key: TKey): QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>, TRootSchema>;
|
|
862
849
|
} : object : object;
|
|
863
|
-
type
|
|
864
|
-
_: infer D;
|
|
865
|
-
} ? HasQueryMethods<D> extends true ? {
|
|
866
|
-
/**
|
|
867
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
868
|
-
*
|
|
869
|
-
* @example
|
|
870
|
-
* ```ts
|
|
871
|
-
* useRead((api) => api.posts[123].$get())
|
|
872
|
-
* useRead((api) => api.posts(':id').$get({ params: { id: 123 } }))
|
|
873
|
-
* ```
|
|
874
|
-
*/
|
|
875
|
-
_: QueryOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string, TRootSchema>;
|
|
876
|
-
} : object : object;
|
|
877
|
-
type QueryOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = QueryHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & QueryDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & QueryDynamicKey<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
850
|
+
type QueryOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never, TRootSchema = TSchema> = QueryHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & QueryDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames, TRootSchema> & {
|
|
878
851
|
[K in keyof StaticPathKeys<TSchema> as K extends SchemaMethod ? never : HasQueryMethods<TSchema[K]> extends true ? K : never]: QueryOnlyClient<TSchema[K], TDefaultError, TOptionsMap, TParamNames, TRootSchema>;
|
|
879
852
|
};
|
|
880
853
|
type MutationHttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = {
|
|
@@ -883,25 +856,10 @@ type MutationHttpMethods<TSchema, TDefaultError = unknown, TOptionsMap = object,
|
|
|
883
856
|
type MutationDynamicAccess<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = TSchema extends {
|
|
884
857
|
_: infer D;
|
|
885
858
|
} ? HasMutationMethods<D> extends true ? {
|
|
886
|
-
[key: string]: MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string>;
|
|
887
859
|
[key: number]: MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string>;
|
|
888
|
-
<TKey extends string>(key: TKey): MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>>;
|
|
889
|
-
} : object : object;
|
|
890
|
-
type MutationDynamicKey<TSchema, TDefaultError, TOptionsMap, TParamNames extends string = never> = TSchema extends {
|
|
891
|
-
_: infer D;
|
|
892
|
-
} ? HasMutationMethods<D> extends true ? {
|
|
893
|
-
/**
|
|
894
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
895
|
-
*
|
|
896
|
-
* @example
|
|
897
|
-
* ```ts
|
|
898
|
-
* const { trigger } = useWrite((api) => api.posts(':id').$delete)
|
|
899
|
-
* trigger({ params: { id: 123 } })
|
|
900
|
-
* ```
|
|
901
|
-
*/
|
|
902
|
-
_: MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | string>;
|
|
860
|
+
<TKey extends string | number>(key: TKey): MutationOnlyClient<D, TDefaultError, TOptionsMap, TParamNames | ExtractParamName<TKey>>;
|
|
903
861
|
} : object : object;
|
|
904
|
-
type MutationOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = MutationHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & MutationDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames> &
|
|
862
|
+
type MutationOnlyClient<TSchema, TDefaultError = unknown, TOptionsMap = object, TParamNames extends string = never> = MutationHttpMethods<TSchema, TDefaultError, TOptionsMap, TParamNames> & MutationDynamicAccess<TSchema, TDefaultError, TOptionsMap, TParamNames> & {
|
|
905
863
|
[K in keyof StaticPathKeys<TSchema> as K extends SchemaMethod ? never : HasMutationMethods<TSchema[K]> extends true ? K : never]: MutationOnlyClient<TSchema[K], TDefaultError, TOptionsMap, TParamNames>;
|
|
906
864
|
};
|
|
907
865
|
|
|
@@ -961,17 +919,6 @@ type QuerySchemaHelper<TSchema> = {
|
|
|
961
919
|
} & (TSchema extends {
|
|
962
920
|
_: infer D;
|
|
963
921
|
} ? HasQueryMethods<D> extends true ? {
|
|
964
|
-
/**
|
|
965
|
-
* Dynamic path segment placeholder for routes like `/posts/:id`.
|
|
966
|
-
*
|
|
967
|
-
* @example
|
|
968
|
-
* ```ts
|
|
969
|
-
* // In plugin callback - reference the endpoint
|
|
970
|
-
* myCallback: (api) => api.posts._.$get
|
|
971
|
-
* ```
|
|
972
|
-
*/
|
|
973
|
-
_: QuerySchemaHelper<D>;
|
|
974
|
-
[key: string]: QuerySchemaHelper<D>;
|
|
975
922
|
[key: number]: QuerySchemaHelper<D>;
|
|
976
923
|
} : object : object);
|
|
977
924
|
|