@spoosh/angular 0.1.4 → 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 CHANGED
@@ -48,7 +48,7 @@ Fetch data with automatic caching and refetching using Angular signals.
48
48
  `,
49
49
  })
50
50
  export class UserListComponent {
51
- users = injectRead((api) => api.users.$get());
51
+ users = injectRead((api) => api("users").GET());
52
52
  }
53
53
 
54
54
  // With options
@@ -58,15 +58,19 @@ export class UserListComponent {
58
58
 
59
59
  // Recommended: Pass signal directly (shorter syntax)
60
60
  users = injectRead(
61
- (api) => api.users.$get({ query: { page: 1 } }),
61
+ (api) => api("users").GET({ query: { page: 1 } }),
62
62
  {
63
63
  staleTime: 10000,
64
64
  enabled: this.isReady,
65
65
  }
66
66
  );
67
67
 
68
- // Also works: Arrow function wrapper
69
- // enabled: () => this.isReady(),
68
+ // With path parameters
69
+ userId = signal(123);
70
+ user = injectRead(
71
+ (api) => api("users/:id").GET({ params: { id: this.userId() } }),
72
+ { enabled: () => this.userId() !== null }
73
+ );
70
74
  }
71
75
  ```
72
76
 
@@ -88,7 +92,7 @@ Trigger mutations with loading and error states.
88
92
  export class CreateUserComponent {
89
93
  title = signal("");
90
94
 
91
- createUser = injectWrite((api) => api.users.$post);
95
+ createUser = injectWrite((api) => api("users").POST);
92
96
 
93
97
  async handleSubmit() {
94
98
  const result = await this.createUser.trigger({
@@ -100,6 +104,16 @@ export class CreateUserComponent {
100
104
  }
101
105
  }
102
106
  }
107
+
108
+ // With path parameters
109
+ updateUser = injectWrite((api) => api("users/:id").PUT);
110
+
111
+ async updateUserName(userId: number, name: string) {
112
+ await this.updateUser.trigger({
113
+ params: { id: userId },
114
+ body: { name },
115
+ });
116
+ }
103
117
  ```
104
118
 
105
119
  ### injectInfiniteRead
@@ -127,26 +141,29 @@ Bidirectional paginated data fetching with infinite scroll support.
127
141
  `,
128
142
  })
129
143
  export class PostListComponent {
130
- posts = injectInfiniteRead((api) => api.posts.$get({ query: { page: 1 } }), {
131
- // Required: Check if next page exists
132
- canFetchNext: ({ response }) => response?.meta.hasMore ?? false,
144
+ posts = injectInfiniteRead(
145
+ (api) => api("posts").GET({ query: { page: 1 } }),
146
+ {
147
+ // Required: Check if next page exists
148
+ canFetchNext: ({ response }) => response?.meta.hasMore ?? false,
133
149
 
134
- // Required: Build request for next page
135
- nextPageRequest: ({ response, request }) => ({
136
- query: { ...request.query, page: (response?.meta.page ?? 0) + 1 },
137
- }),
150
+ // Required: Build request for next page
151
+ nextPageRequest: ({ response, request }) => ({
152
+ query: { ...request.query, page: (response?.meta.page ?? 0) + 1 },
153
+ }),
138
154
 
139
- // Required: Merge all responses into items
140
- merger: (allResponses) => allResponses.flatMap((r) => r.items),
155
+ // Required: Merge all responses into items
156
+ merger: (allResponses) => allResponses.flatMap((r) => r.items),
141
157
 
142
- // Optional: Check if previous page exists
143
- canFetchPrev: ({ response }) => (response?.meta.page ?? 1) > 1,
158
+ // Optional: Check if previous page exists
159
+ canFetchPrev: ({ response }) => (response?.meta.page ?? 1) > 1,
144
160
 
145
- // Optional: Build request for previous page
146
- prevPageRequest: ({ response, request }) => ({
147
- query: { ...request.query, page: (response?.meta.page ?? 2) - 1 },
148
- }),
149
- });
161
+ // Optional: Build request for previous page
162
+ prevPageRequest: ({ response, request }) => ({
163
+ query: { ...request.query, page: (response?.meta.page ?? 2) - 1 },
164
+ }),
165
+ }
166
+ );
150
167
  }
151
168
  ```
152
169
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _spoosh_core from '@spoosh/core';
2
- import { PluginArray, StateManager, EventEmitter, PluginExecutor, QueryOnlyClient, MethodOptionsMap, CoreRequestOptionsBase, SpooshResponse, MutationOnlyClient, SpooshPlugin, PluginTypeConfig, InfiniteRequestOptions, ResolveTypes, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
2
+ import { PluginArray, StateManager, EventEmitter, PluginExecutor, ReadClient, SpooshResponse, WriteClient, MethodOptionsMap, CoreRequestOptionsBase, SpooshPlugin, PluginTypeConfig, InfiniteRequestOptions, ResolveTypes, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
3
3
  import { Signal } from '@angular/core';
4
4
 
5
5
  interface SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins extends PluginArray> {
@@ -68,8 +68,8 @@ interface BaseInfiniteReadResult<TData, TError, TItem, TPluginResult = Record<st
68
68
  type QueryRequestOptions = CoreRequestOptionsBase;
69
69
  type MutationRequestOptions = CoreRequestOptionsBase;
70
70
  type AngularOptionsMap = MethodOptionsMap<QueryRequestOptions, MutationRequestOptions>;
71
- type ReadApiClient<TSchema, TDefaultError> = QueryOnlyClient<TSchema, TDefaultError, AngularOptionsMap>;
72
- type WriteApiClient<TSchema, TDefaultError> = MutationOnlyClient<TSchema, TDefaultError, AngularOptionsMap>;
71
+ type ReadApiClient<TSchema, TDefaultError> = ReadClient<TSchema, TDefaultError>;
72
+ type WriteApiClient<TSchema, TDefaultError> = WriteClient<TSchema, TDefaultError>;
73
73
  type QueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
74
74
  query?: Exclude<TQuery, undefined>;
75
75
  } : {
@@ -80,17 +80,16 @@ type BodyField<TBody> = [TBody] extends [never] ? object : undefined extends TBo
80
80
  } : {
81
81
  body: TBody;
82
82
  };
83
- type FormDataField<TFormData> = [TFormData] extends [never] ? object : undefined extends TFormData ? {
84
- formData?: Exclude<TFormData, undefined>;
85
- } : {
86
- formData: TFormData;
87
- };
88
83
  type ParamsField<TParamNames extends string> = [TParamNames] extends [never] ? object : {
89
84
  params: Record<TParamNames, string | number>;
90
85
  };
91
- type ReadInputFields<TQuery, TBody, TFormData, TParamNames extends string> = QueryField<TQuery> & BodyField<TBody> & FormDataField<TFormData> & ParamsField<TParamNames>;
92
- type ResponseInputFields<TQuery, TBody, TFormData, TParamNames extends string> = [TQuery, TBody, TFormData, TParamNames] extends [never, never, never, never] ? object : {
93
- input: ReadInputFields<TQuery, TBody, TFormData, TParamNames>;
86
+ type ReadInputFields<TQuery, TBody, TParamNames extends string> = QueryField<TQuery> & BodyField<TBody> & ParamsField<TParamNames>;
87
+ type ResponseInputFields<TQuery, TBody, TParamNames extends string> = [
88
+ TQuery,
89
+ TBody,
90
+ TParamNames
91
+ ] extends [never, never, never] ? object : {
92
+ input: ReadInputFields<TQuery, TBody, TParamNames>;
94
93
  };
95
94
  type OptionalQueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
96
95
  query?: Exclude<TQuery, undefined>;
@@ -102,19 +101,14 @@ type OptionalBodyField<TBody> = [TBody] extends [never] ? object : undefined ext
102
101
  } : {
103
102
  body: TBody;
104
103
  };
105
- type OptionalFormDataField<TFormData> = [TFormData] extends [never] ? object : undefined extends TFormData ? {
106
- formData?: Exclude<TFormData, undefined>;
107
- } : {
108
- formData: TFormData;
109
- };
110
104
  type OptionalParamsField<TParamNames extends string> = [TParamNames] extends [
111
105
  never
112
106
  ] ? object : {
113
107
  params: Record<TParamNames, string | number>;
114
108
  };
115
- type InputFields<TQuery, TBody, TFormData, TParamNames extends string> = OptionalQueryField<TQuery> & OptionalBodyField<TBody> & OptionalFormDataField<TFormData> & OptionalParamsField<TParamNames>;
116
- type WriteResponseInputFields<TQuery, TBody, TFormData, TParamNames extends string> = [TQuery, TBody, TFormData, TParamNames] extends [never, never, never, never] ? object : {
117
- input: Signal<InputFields<TQuery, TBody, TFormData, TParamNames> | undefined>;
109
+ type InputFields<TQuery, TBody, TParamNames extends string> = OptionalQueryField<TQuery> & OptionalBodyField<TBody> & OptionalParamsField<TParamNames>;
110
+ type WriteResponseInputFields<TQuery, TBody, TParamNames extends string> = [TQuery, TBody, TParamNames] extends [never, never, never] ? object : {
111
+ input: Signal<InputFields<TQuery, TBody, TParamNames> | undefined>;
118
112
  };
119
113
  type SuccessResponse<T> = Extract<T, {
120
114
  data: unknown;
@@ -143,11 +137,6 @@ type ExtractResponseBody<T> = SuccessReturnType<T> extends {
143
137
  body: infer B;
144
138
  };
145
139
  } ? B : never;
146
- type ExtractResponseFormData<T> = SuccessReturnType<T> extends {
147
- input: {
148
- formData: infer F;
149
- };
150
- } ? F : never;
151
140
  type ExtractResponseParamNames<T> = SuccessReturnType<T> extends {
152
141
  input: {
153
142
  params: Record<infer K, unknown>;
@@ -159,12 +148,6 @@ type ExtractMethodQuery<T> = ExtractMethodOptions<T> extends {
159
148
  type ExtractMethodBody<T> = ExtractMethodOptions<T> extends {
160
149
  body: infer B;
161
150
  } ? B : never;
162
- type ExtractMethodFormData<T> = ExtractMethodOptions<T> extends {
163
- formData: infer F;
164
- } ? F : never;
165
- type ExtractMethodUrlEncoded<T> = ExtractMethodOptions<T> extends {
166
- urlEncoded: infer U;
167
- } ? U : never;
168
151
 
169
152
  type AnyInfiniteRequestOptions = InfiniteRequestOptions;
170
153
  declare function createInjectInfiniteRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<SpooshResponse<unknown, unknown>>, TRequest extends AnyInfiniteRequestOptions = AnyInfiniteRequestOptions, TItem = unknown>(readFn: TReadFn, readOptions: BaseInfiniteReadOptions<TReadFn extends (...args: never[]) => infer R ? Extract<Awaited<R>, {
@@ -231,7 +214,7 @@ declare function createInjectWrite<TSchema, TDefaultError, TPlugins extends read
231
214
  data?: undefined;
232
215
  }> extends {
233
216
  error: infer E;
234
- } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>, ExtractMethodFormData<TMethod>, never>> = (TMethod extends (...args: infer A) => unknown ? A[0] : never) & _spoosh_core.ResolveTypes<((TPlugins[number] extends infer T_6 ? T_6 extends TPlugins[number] ? T_6 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
217
+ } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>> = (TMethod extends (...args: infer A) => unknown ? A[0] : never) & _spoosh_core.ResolveTypes<((TPlugins[number] extends infer T_6 ? T_6 extends TPlugins[number] ? T_6 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
235
218
  writeOptions: infer W_1;
236
219
  } ? W_1 : object : object : never : never) extends infer T_7 ? T_7 extends (TPlugins[number] extends infer T_8 ? T_8 extends TPlugins[number] ? T_8 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
237
220
  writeOptions: infer W_1;
@@ -250,7 +233,7 @@ declare function createInjectWrite<TSchema, TDefaultError, TPlugins extends read
250
233
  data?: undefined;
251
234
  }> extends {
252
235
  error: infer E;
253
- } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>, ExtractMethodFormData<TMethod>, never>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod) => BaseWriteResult<TMethod extends (...args: never[]) => infer R ? Extract<Awaited<R>, {
236
+ } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod) => BaseWriteResult<TMethod extends (...args: never[]) => infer R ? Extract<Awaited<R>, {
254
237
  data: unknown;
255
238
  error?: undefined;
256
239
  }> extends {
@@ -269,7 +252,7 @@ declare function createInjectWrite<TSchema, TDefaultError, TPlugins extends read
269
252
  writeResult: infer W;
270
253
  } ? W : object : object : never : never) extends infer T_1 ? T_1 extends (TPlugins[number] extends infer T_2 ? T_2 extends TPlugins[number] ? T_2 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
271
254
  writeResult: infer W;
272
- } ? W : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TWriteOpts>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseFormData<TMethod>, ExtractResponseParamNames<TMethod>>;
255
+ } ? W : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TWriteOpts>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseParamNames<TMethod>>;
273
256
 
274
257
  declare function createInjectRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<{
275
258
  data?: unknown;
@@ -331,7 +314,7 @@ declare function createInjectRead<TSchema, TDefaultError, TPlugins extends reado
331
314
  readResult: infer R_2;
332
315
  } ? R_2 : object : object : never : never) extends infer T_1 ? T_1 extends (TPlugins[number] extends infer T_2 ? T_2 extends TPlugins[number] ? T_2 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
333
316
  readResult: infer R_2;
334
- } ? R_2 : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TReadOpts>> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseFormData<TReadFn>, ExtractResponseParamNames<TReadFn>>;
317
+ } ? R_2 : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TReadOpts>> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn>>;
335
318
 
336
319
  type SpooshAngularFunctions<TDefaultError, TSchema, TPlugins extends PluginArray> = {
337
320
  injectRead: ReturnType<typeof createInjectRead<TSchema, TDefaultError, TPlugins>>;
@@ -341,4 +324,4 @@ type SpooshAngularFunctions<TDefaultError, TSchema, TPlugins extends PluginArray
341
324
 
342
325
  declare function createAngularSpoosh<TSchema, TDefaultError, TPlugins extends PluginArray, TApi>(instance: SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins>): SpooshAngularFunctions<TDefaultError, TSchema, TPlugins>;
343
326
 
344
- export { type AngularOptionsMap, type BaseInfiniteReadOptions, type BaseInfiniteReadResult, type BaseReadOptions, type BaseReadResult, type BaseWriteResult, type EnabledOption, type ExtractMethodBody, type ExtractMethodData, type ExtractMethodError, type ExtractMethodFormData, type ExtractMethodOptions, type ExtractMethodQuery, type ExtractMethodUrlEncoded, type ExtractResponseBody, type ExtractResponseFormData, type ExtractResponseParamNames, type ExtractResponseQuery, type PageContext, type ReadApiClient, type ResponseInputFields, type SpooshInstanceShape, type WriteApiClient, type WriteResponseInputFields, createAngularSpoosh };
327
+ export { type AngularOptionsMap, type BaseInfiniteReadOptions, type BaseInfiniteReadResult, type BaseReadOptions, type BaseReadResult, type BaseWriteResult, type EnabledOption, type ExtractMethodBody, type ExtractMethodData, type ExtractMethodError, type ExtractMethodOptions, type ExtractMethodQuery, type ExtractResponseBody, type ExtractResponseParamNames, type ExtractResponseQuery, type PageContext, type ReadApiClient, type ResponseInputFields, type SpooshInstanceShape, type WriteApiClient, type WriteResponseInputFields, createAngularSpoosh };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _spoosh_core from '@spoosh/core';
2
- import { PluginArray, StateManager, EventEmitter, PluginExecutor, QueryOnlyClient, MethodOptionsMap, CoreRequestOptionsBase, SpooshResponse, MutationOnlyClient, SpooshPlugin, PluginTypeConfig, InfiniteRequestOptions, ResolveTypes, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
2
+ import { PluginArray, StateManager, EventEmitter, PluginExecutor, ReadClient, SpooshResponse, WriteClient, MethodOptionsMap, CoreRequestOptionsBase, SpooshPlugin, PluginTypeConfig, InfiniteRequestOptions, ResolveTypes, ResolverContext, ResolveResultTypes, MergePluginInstanceApi } from '@spoosh/core';
3
3
  import { Signal } from '@angular/core';
4
4
 
5
5
  interface SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins extends PluginArray> {
@@ -68,8 +68,8 @@ interface BaseInfiniteReadResult<TData, TError, TItem, TPluginResult = Record<st
68
68
  type QueryRequestOptions = CoreRequestOptionsBase;
69
69
  type MutationRequestOptions = CoreRequestOptionsBase;
70
70
  type AngularOptionsMap = MethodOptionsMap<QueryRequestOptions, MutationRequestOptions>;
71
- type ReadApiClient<TSchema, TDefaultError> = QueryOnlyClient<TSchema, TDefaultError, AngularOptionsMap>;
72
- type WriteApiClient<TSchema, TDefaultError> = MutationOnlyClient<TSchema, TDefaultError, AngularOptionsMap>;
71
+ type ReadApiClient<TSchema, TDefaultError> = ReadClient<TSchema, TDefaultError>;
72
+ type WriteApiClient<TSchema, TDefaultError> = WriteClient<TSchema, TDefaultError>;
73
73
  type QueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
74
74
  query?: Exclude<TQuery, undefined>;
75
75
  } : {
@@ -80,17 +80,16 @@ type BodyField<TBody> = [TBody] extends [never] ? object : undefined extends TBo
80
80
  } : {
81
81
  body: TBody;
82
82
  };
83
- type FormDataField<TFormData> = [TFormData] extends [never] ? object : undefined extends TFormData ? {
84
- formData?: Exclude<TFormData, undefined>;
85
- } : {
86
- formData: TFormData;
87
- };
88
83
  type ParamsField<TParamNames extends string> = [TParamNames] extends [never] ? object : {
89
84
  params: Record<TParamNames, string | number>;
90
85
  };
91
- type ReadInputFields<TQuery, TBody, TFormData, TParamNames extends string> = QueryField<TQuery> & BodyField<TBody> & FormDataField<TFormData> & ParamsField<TParamNames>;
92
- type ResponseInputFields<TQuery, TBody, TFormData, TParamNames extends string> = [TQuery, TBody, TFormData, TParamNames] extends [never, never, never, never] ? object : {
93
- input: ReadInputFields<TQuery, TBody, TFormData, TParamNames>;
86
+ type ReadInputFields<TQuery, TBody, TParamNames extends string> = QueryField<TQuery> & BodyField<TBody> & ParamsField<TParamNames>;
87
+ type ResponseInputFields<TQuery, TBody, TParamNames extends string> = [
88
+ TQuery,
89
+ TBody,
90
+ TParamNames
91
+ ] extends [never, never, never] ? object : {
92
+ input: ReadInputFields<TQuery, TBody, TParamNames>;
94
93
  };
95
94
  type OptionalQueryField<TQuery> = [TQuery] extends [never] ? object : undefined extends TQuery ? {
96
95
  query?: Exclude<TQuery, undefined>;
@@ -102,19 +101,14 @@ type OptionalBodyField<TBody> = [TBody] extends [never] ? object : undefined ext
102
101
  } : {
103
102
  body: TBody;
104
103
  };
105
- type OptionalFormDataField<TFormData> = [TFormData] extends [never] ? object : undefined extends TFormData ? {
106
- formData?: Exclude<TFormData, undefined>;
107
- } : {
108
- formData: TFormData;
109
- };
110
104
  type OptionalParamsField<TParamNames extends string> = [TParamNames] extends [
111
105
  never
112
106
  ] ? object : {
113
107
  params: Record<TParamNames, string | number>;
114
108
  };
115
- type InputFields<TQuery, TBody, TFormData, TParamNames extends string> = OptionalQueryField<TQuery> & OptionalBodyField<TBody> & OptionalFormDataField<TFormData> & OptionalParamsField<TParamNames>;
116
- type WriteResponseInputFields<TQuery, TBody, TFormData, TParamNames extends string> = [TQuery, TBody, TFormData, TParamNames] extends [never, never, never, never] ? object : {
117
- input: Signal<InputFields<TQuery, TBody, TFormData, TParamNames> | undefined>;
109
+ type InputFields<TQuery, TBody, TParamNames extends string> = OptionalQueryField<TQuery> & OptionalBodyField<TBody> & OptionalParamsField<TParamNames>;
110
+ type WriteResponseInputFields<TQuery, TBody, TParamNames extends string> = [TQuery, TBody, TParamNames] extends [never, never, never] ? object : {
111
+ input: Signal<InputFields<TQuery, TBody, TParamNames> | undefined>;
118
112
  };
119
113
  type SuccessResponse<T> = Extract<T, {
120
114
  data: unknown;
@@ -143,11 +137,6 @@ type ExtractResponseBody<T> = SuccessReturnType<T> extends {
143
137
  body: infer B;
144
138
  };
145
139
  } ? B : never;
146
- type ExtractResponseFormData<T> = SuccessReturnType<T> extends {
147
- input: {
148
- formData: infer F;
149
- };
150
- } ? F : never;
151
140
  type ExtractResponseParamNames<T> = SuccessReturnType<T> extends {
152
141
  input: {
153
142
  params: Record<infer K, unknown>;
@@ -159,12 +148,6 @@ type ExtractMethodQuery<T> = ExtractMethodOptions<T> extends {
159
148
  type ExtractMethodBody<T> = ExtractMethodOptions<T> extends {
160
149
  body: infer B;
161
150
  } ? B : never;
162
- type ExtractMethodFormData<T> = ExtractMethodOptions<T> extends {
163
- formData: infer F;
164
- } ? F : never;
165
- type ExtractMethodUrlEncoded<T> = ExtractMethodOptions<T> extends {
166
- urlEncoded: infer U;
167
- } ? U : never;
168
151
 
169
152
  type AnyInfiniteRequestOptions = InfiniteRequestOptions;
170
153
  declare function createInjectInfiniteRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<SpooshResponse<unknown, unknown>>, TRequest extends AnyInfiniteRequestOptions = AnyInfiniteRequestOptions, TItem = unknown>(readFn: TReadFn, readOptions: BaseInfiniteReadOptions<TReadFn extends (...args: never[]) => infer R ? Extract<Awaited<R>, {
@@ -231,7 +214,7 @@ declare function createInjectWrite<TSchema, TDefaultError, TPlugins extends read
231
214
  data?: undefined;
232
215
  }> extends {
233
216
  error: infer E;
234
- } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>, ExtractMethodFormData<TMethod>, never>> = (TMethod extends (...args: infer A) => unknown ? A[0] : never) & _spoosh_core.ResolveTypes<((TPlugins[number] extends infer T_6 ? T_6 extends TPlugins[number] ? T_6 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
217
+ } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>> = (TMethod extends (...args: infer A) => unknown ? A[0] : never) & _spoosh_core.ResolveTypes<((TPlugins[number] extends infer T_6 ? T_6 extends TPlugins[number] ? T_6 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
235
218
  writeOptions: infer W_1;
236
219
  } ? W_1 : object : object : never : never) extends infer T_7 ? T_7 extends (TPlugins[number] extends infer T_8 ? T_8 extends TPlugins[number] ? T_8 extends SpooshPlugin<infer Types_1 extends PluginTypeConfig> ? Types_1 extends {
237
220
  writeOptions: infer W_1;
@@ -250,7 +233,7 @@ declare function createInjectWrite<TSchema, TDefaultError, TPlugins extends read
250
233
  data?: undefined;
251
234
  }> extends {
252
235
  error: infer E;
253
- } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>, ExtractMethodFormData<TMethod>, never>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod) => BaseWriteResult<TMethod extends (...args: never[]) => infer R ? Extract<Awaited<R>, {
236
+ } ? E : unknown : unknown, ExtractMethodQuery<TMethod>, ExtractMethodBody<TMethod>, ExtractResponseParamNames<TMethod> extends never ? never : Record<ExtractResponseParamNames<TMethod>, string | number>>>>(writeFn: (api: WriteApiClient<TSchema, TDefaultError>) => TMethod) => BaseWriteResult<TMethod extends (...args: never[]) => infer R ? Extract<Awaited<R>, {
254
237
  data: unknown;
255
238
  error?: undefined;
256
239
  }> extends {
@@ -269,7 +252,7 @@ declare function createInjectWrite<TSchema, TDefaultError, TPlugins extends read
269
252
  writeResult: infer W;
270
253
  } ? W : object : object : never : never) extends infer T_1 ? T_1 extends (TPlugins[number] extends infer T_2 ? T_2 extends TPlugins[number] ? T_2 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
271
254
  writeResult: infer W;
272
- } ? W : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TWriteOpts>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseFormData<TMethod>, ExtractResponseParamNames<TMethod>>;
255
+ } ? W : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TWriteOpts>> & WriteResponseInputFields<ExtractResponseQuery<TMethod>, ExtractResponseBody<TMethod>, ExtractResponseParamNames<TMethod>>;
273
256
 
274
257
  declare function createInjectRead<TSchema, TDefaultError, TPlugins extends readonly SpooshPlugin<PluginTypeConfig>[]>(options: Omit<SpooshInstanceShape<unknown, TSchema, TDefaultError, TPlugins>, "_types">): <TReadFn extends (api: ReadApiClient<TSchema, TDefaultError>) => Promise<{
275
258
  data?: unknown;
@@ -331,7 +314,7 @@ declare function createInjectRead<TSchema, TDefaultError, TPlugins extends reado
331
314
  readResult: infer R_2;
332
315
  } ? R_2 : object : object : never : never) extends infer T_1 ? T_1 extends (TPlugins[number] extends infer T_2 ? T_2 extends TPlugins[number] ? T_2 extends SpooshPlugin<infer Types extends PluginTypeConfig> ? Types extends {
333
316
  readResult: infer R_2;
334
- } ? R_2 : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TReadOpts>> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseFormData<TReadFn>, ExtractResponseParamNames<TReadFn>>;
317
+ } ? R_2 : object : object : never : never) ? T_1 extends unknown ? (x: T_1) => void : never : never : never) extends (x: infer I) => void ? I : never, TReadOpts>> & ResponseInputFields<ExtractResponseQuery<TReadFn>, ExtractResponseBody<TReadFn>, ExtractResponseParamNames<TReadFn>>;
335
318
 
336
319
  type SpooshAngularFunctions<TDefaultError, TSchema, TPlugins extends PluginArray> = {
337
320
  injectRead: ReturnType<typeof createInjectRead<TSchema, TDefaultError, TPlugins>>;
@@ -341,4 +324,4 @@ type SpooshAngularFunctions<TDefaultError, TSchema, TPlugins extends PluginArray
341
324
 
342
325
  declare function createAngularSpoosh<TSchema, TDefaultError, TPlugins extends PluginArray, TApi>(instance: SpooshInstanceShape<TApi, TSchema, TDefaultError, TPlugins>): SpooshAngularFunctions<TDefaultError, TSchema, TPlugins>;
343
326
 
344
- export { type AngularOptionsMap, type BaseInfiniteReadOptions, type BaseInfiniteReadResult, type BaseReadOptions, type BaseReadResult, type BaseWriteResult, type EnabledOption, type ExtractMethodBody, type ExtractMethodData, type ExtractMethodError, type ExtractMethodFormData, type ExtractMethodOptions, type ExtractMethodQuery, type ExtractMethodUrlEncoded, type ExtractResponseBody, type ExtractResponseFormData, type ExtractResponseParamNames, type ExtractResponseQuery, type PageContext, type ReadApiClient, type ResponseInputFields, type SpooshInstanceShape, type WriteApiClient, type WriteResponseInputFields, createAngularSpoosh };
327
+ export { type AngularOptionsMap, type BaseInfiniteReadOptions, type BaseInfiniteReadResult, type BaseReadOptions, type BaseReadResult, type BaseWriteResult, type EnabledOption, type ExtractMethodBody, type ExtractMethodData, type ExtractMethodError, type ExtractMethodOptions, type ExtractMethodQuery, type ExtractResponseBody, type ExtractResponseParamNames, type ExtractResponseQuery, type PageContext, type ReadApiClient, type ResponseInputFields, type SpooshInstanceShape, type WriteApiClient, type WriteResponseInputFields, createAngularSpoosh };
package/dist/index.js CHANGED
@@ -65,13 +65,14 @@ function createInjectRead(options) {
65
65
  readFn(selectorProxy);
66
66
  return selectorResult;
67
67
  };
68
- const createController = (capturedCall, resolvedPath, resolvedTags, queryKey) => {
68
+ const createController = (capturedCall, resolvedTags, queryKey) => {
69
69
  if (currentSubscription) {
70
70
  currentSubscription();
71
71
  }
72
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
72
73
  const controller = (0, import_core2.createOperationController)({
73
74
  operationType: "read",
74
- path: capturedCall.path,
75
+ path: pathSegments,
75
76
  method: capturedCall.method,
76
77
  tags: resolvedTags,
77
78
  requestOptions: capturedCall.options,
@@ -80,11 +81,8 @@ function createInjectRead(options) {
80
81
  pluginExecutor,
81
82
  hookId,
82
83
  fetchFn: async (fetchOpts) => {
83
- let current = api;
84
- for (const segment of resolvedPath) {
85
- current = current[segment];
86
- }
87
- const method = current[capturedCall.method];
84
+ const pathMethods = api(capturedCall.path);
85
+ const method = pathMethods[capturedCall.method];
88
86
  return method(fetchOpts);
89
87
  }
90
88
  });
@@ -94,7 +92,7 @@ function createInjectRead(options) {
94
92
  dataSignal.set(state.data);
95
93
  errorSignal.set(state.error);
96
94
  const entry = stateManager.getCache(queryKey);
97
- const newMeta = entry?.pluginResult ? Object.fromEntries(entry.pluginResult) : {};
95
+ const newMeta = entry?.meta ? Object.fromEntries(entry.meta) : {};
98
96
  metaSignal.set(newMeta);
99
97
  });
100
98
  currentController = controller;
@@ -129,12 +127,13 @@ function createInjectRead(options) {
129
127
  const initialCapturedCall = initialSelectorResult.call;
130
128
  if (!initialCapturedCall) {
131
129
  throw new Error(
132
- "injectRead requires calling an HTTP method ($get). Example: injectRead((api) => api.posts.$get())"
130
+ 'injectRead requires calling an HTTP method (GET). Example: injectRead((api) => api("posts").GET())'
133
131
  );
134
132
  }
135
133
  const initialRequestOptions = initialCapturedCall.options;
134
+ const initialPathSegments = initialCapturedCall.path.split("/").filter(Boolean);
136
135
  const initialResolvedPath = (0, import_core2.resolvePath)(
137
- initialCapturedCall.path,
136
+ initialPathSegments,
138
137
  initialRequestOptions?.params
139
138
  );
140
139
  const initialResolvedTags = (0, import_core2.resolveTags)(
@@ -142,16 +141,11 @@ function createInjectRead(options) {
142
141
  initialResolvedPath
143
142
  );
144
143
  const initialQueryKey = stateManager.createQueryKey({
145
- path: initialCapturedCall.path,
144
+ path: initialPathSegments,
146
145
  method: initialCapturedCall.method,
147
146
  options: initialCapturedCall.options
148
147
  });
149
- createController(
150
- initialCapturedCall,
151
- initialResolvedPath,
152
- initialResolvedTags,
153
- initialQueryKey
154
- );
148
+ createController(initialCapturedCall, initialResolvedTags, initialQueryKey);
155
149
  loadingSignal.set(false);
156
150
  let wasEnabled = false;
157
151
  (0, import_core.effect)(
@@ -161,20 +155,18 @@ function createInjectRead(options) {
161
155
  const capturedCall = selectorResult.call;
162
156
  if (!capturedCall) {
163
157
  throw new Error(
164
- "injectRead requires calling an HTTP method ($get). Example: injectRead((api) => api.posts.$get())"
158
+ 'injectRead requires calling an HTTP method (GET). Example: injectRead((api) => api("posts").GET())'
165
159
  );
166
160
  }
167
161
  const requestOptions = capturedCall.options;
168
- const resolvedPath = (0, import_core2.resolvePath)(
169
- capturedCall.path,
170
- requestOptions?.params
171
- );
162
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
163
+ const resolvedPath = (0, import_core2.resolvePath)(pathSegments, requestOptions?.params);
172
164
  const resolvedTags = (0, import_core2.resolveTags)(
173
165
  { tags, additionalTags },
174
166
  resolvedPath
175
167
  );
176
168
  const queryKey = stateManager.createQueryKey({
177
- path: capturedCall.path,
169
+ path: pathSegments,
178
170
  method: capturedCall.method,
179
171
  options: capturedCall.options
180
172
  });
@@ -186,9 +178,6 @@ function createInjectRead(options) {
186
178
  if (opts?.body !== void 0) {
187
179
  inputInner.body = opts.body;
188
180
  }
189
- if (opts?.formData !== void 0) {
190
- inputInner.formData = opts.formData;
191
- }
192
181
  if (opts?.params !== void 0) {
193
182
  inputInner.params = opts.params;
194
183
  }
@@ -206,7 +195,6 @@ function createInjectRead(options) {
206
195
  }
207
196
  const controller = createController(
208
197
  capturedCall,
209
- resolvedPath,
210
198
  resolvedTags,
211
199
  queryKey
212
200
  );
@@ -327,7 +315,7 @@ function createInjectWrite(options) {
327
315
  writeFn(selectorProxy);
328
316
  if (!selectorResult.selector) {
329
317
  throw new Error(
330
- "injectWrite requires selecting an HTTP method ($post, $put, $patch, $delete). Example: injectWrite((api) => api.posts.$post)"
318
+ 'injectWrite requires selecting an HTTP method (POST, PUT, PATCH, DELETE). Example: injectWrite((api) => api("posts").POST)'
331
319
  );
332
320
  }
333
321
  return selectorResult.selector;
@@ -360,10 +348,11 @@ function createInjectWrite(options) {
360
348
  const trigger = async (triggerOptions) => {
361
349
  const selectedEndpoint = captureSelector();
362
350
  const params = triggerOptions?.params;
363
- const resolvedPath = (0, import_core4.resolvePath)(selectedEndpoint.path, params);
351
+ const pathSegments = selectedEndpoint.path.split("/").filter(Boolean);
352
+ const resolvedPath = (0, import_core4.resolvePath)(pathSegments, params);
364
353
  const tags = (0, import_core4.resolveTags)(triggerOptions, resolvedPath);
365
354
  const queryKey = stateManager.createQueryKey({
366
- path: selectedEndpoint.path,
355
+ path: pathSegments,
367
356
  method: selectedEndpoint.method,
368
357
  options: triggerOptions
369
358
  });
@@ -374,7 +363,7 @@ function createInjectWrite(options) {
374
363
  }
375
364
  const controller = (0, import_core4.createOperationController)({
376
365
  operationType: "write",
377
- path: selectedEndpoint.path,
366
+ path: pathSegments,
378
367
  method: selectedEndpoint.method,
379
368
  tags,
380
369
  stateManager,
@@ -382,16 +371,8 @@ function createInjectWrite(options) {
382
371
  pluginExecutor,
383
372
  hookId,
384
373
  fetchFn: async (fetchOpts) => {
385
- const fetchParams = fetchOpts?.params;
386
- const fetchResolvedPath = (0, import_core4.resolvePath)(
387
- selectedEndpoint.path,
388
- fetchParams
389
- );
390
- let current = api;
391
- for (const segment of fetchResolvedPath) {
392
- current = current[segment];
393
- }
394
- const method = current[selectedEndpoint.method];
374
+ const pathMethods = api(selectedEndpoint.path);
375
+ const method = pathMethods[selectedEndpoint.method];
395
376
  return method(fetchOpts);
396
377
  }
397
378
  });
@@ -400,7 +381,7 @@ function createInjectWrite(options) {
400
381
  dataSignal.set(state.data);
401
382
  errorSignal.set(state.error);
402
383
  const entry = stateManager.getCache(queryKey);
403
- const newMeta = entry?.pluginResult ? Object.fromEntries(entry.pluginResult) : {};
384
+ const newMeta = entry?.meta ? Object.fromEntries(entry.meta) : {};
404
385
  metaSignal.set(newMeta);
405
386
  });
406
387
  currentController = controller;
@@ -437,9 +418,6 @@ function createInjectWrite(options) {
437
418
  if (opts?.body !== void 0) {
438
419
  inputInner.body = opts.body;
439
420
  }
440
- if (opts?.formData !== void 0) {
441
- inputInner.formData = opts.formData;
442
- }
443
421
  if (opts?.params !== void 0) {
444
422
  inputInner.params = opts.params;
445
423
  }
@@ -501,7 +479,7 @@ function createInjectInfiniteRead(options) {
501
479
  readFn(selectorProxy);
502
480
  if (!selectorResult.call) {
503
481
  throw new Error(
504
- "injectInfiniteRead requires calling an HTTP method ($get). Example: injectInfiniteRead((api) => api.posts.$get())"
482
+ 'injectInfiniteRead requires calling an HTTP method (GET). Example: injectInfiniteRead((api) => api("posts").GET())'
505
483
  );
506
484
  }
507
485
  return selectorResult.call;
@@ -558,6 +536,7 @@ function createInjectInfiniteRead(options) {
558
536
  unsubInvalidate();
559
537
  }
560
538
  const requestOptions = capturedCall.options;
539
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
561
540
  const baseOptionsForKey = {
562
541
  ...capturedCall.options,
563
542
  query: void 0,
@@ -570,7 +549,7 @@ function createInjectInfiniteRead(options) {
570
549
  body: requestOptions?.body
571
550
  };
572
551
  const controller = (0, import_core6.createInfiniteReadController)({
573
- path: capturedCall.path,
552
+ path: pathSegments,
574
553
  method: capturedCall.method,
575
554
  tags: resolvedTags,
576
555
  initialRequest,
@@ -585,12 +564,8 @@ function createInjectInfiniteRead(options) {
585
564
  pluginExecutor,
586
565
  hookId,
587
566
  fetchFn: async (opts, abortSignal) => {
588
- const fetchPath = (0, import_core6.resolvePath)(capturedCall.path, opts.params);
589
- let current = api;
590
- for (const segment of fetchPath) {
591
- current = current[segment];
592
- }
593
- const method = current[capturedCall.method];
567
+ const pathMethods = api(capturedCall.path);
568
+ const method = pathMethods[capturedCall.method];
594
569
  const fetchOptions = {
595
570
  ...capturedCall.options,
596
571
  query: opts.query,
@@ -610,7 +585,7 @@ function createInjectInfiniteRead(options) {
610
585
  canFetchNextSignal.set(state.canFetchNext);
611
586
  canFetchPrevSignal.set(state.canFetchPrev);
612
587
  const entry = stateManager.getCache(queryKey);
613
- const newMeta = entry?.pluginResult ? Object.fromEntries(entry.pluginResult) : {};
588
+ const newMeta = entry?.meta ? Object.fromEntries(entry.meta) : {};
614
589
  metaSignal.set(newMeta);
615
590
  });
616
591
  currentController = controller;
@@ -636,8 +611,9 @@ function createInjectInfiniteRead(options) {
636
611
  };
637
612
  const initialCapturedCall = captureSelector();
638
613
  const initialRequestOptions = initialCapturedCall.options;
614
+ const initialPathSegments = initialCapturedCall.path.split("/").filter(Boolean);
639
615
  const initialResolvedPath = (0, import_core6.resolvePath)(
640
- initialCapturedCall.path,
616
+ initialPathSegments,
641
617
  initialRequestOptions?.params
642
618
  );
643
619
  const initialResolvedTags = (0, import_core6.resolveTags)(
@@ -651,7 +627,7 @@ function createInjectInfiniteRead(options) {
651
627
  body: void 0
652
628
  };
653
629
  const initialQueryKey = stateManager.createQueryKey({
654
- path: initialCapturedCall.path,
630
+ path: initialPathSegments,
655
631
  method: initialCapturedCall.method,
656
632
  options: initialBaseOptionsForKey
657
633
  });
@@ -661,10 +637,8 @@ function createInjectInfiniteRead(options) {
661
637
  const isEnabled = getEnabled();
662
638
  const capturedCall = captureSelector();
663
639
  const requestOptions = capturedCall.options;
664
- const resolvedPath = (0, import_core6.resolvePath)(
665
- capturedCall.path,
666
- requestOptions?.params
667
- );
640
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
641
+ const resolvedPath = (0, import_core6.resolvePath)(pathSegments, requestOptions?.params);
668
642
  const resolvedTags = (0, import_core6.resolveTags)(
669
643
  { tags, additionalTags },
670
644
  resolvedPath
@@ -676,7 +650,7 @@ function createInjectInfiniteRead(options) {
676
650
  body: void 0
677
651
  };
678
652
  const queryKey = stateManager.createQueryKey({
679
- path: capturedCall.path,
653
+ path: pathSegments,
680
654
  method: capturedCall.method,
681
655
  options: baseOptionsForKey
682
656
  });
package/dist/index.mjs CHANGED
@@ -50,13 +50,14 @@ function createInjectRead(options) {
50
50
  readFn(selectorProxy);
51
51
  return selectorResult;
52
52
  };
53
- const createController = (capturedCall, resolvedPath, resolvedTags, queryKey) => {
53
+ const createController = (capturedCall, resolvedTags, queryKey) => {
54
54
  if (currentSubscription) {
55
55
  currentSubscription();
56
56
  }
57
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
57
58
  const controller = createOperationController({
58
59
  operationType: "read",
59
- path: capturedCall.path,
60
+ path: pathSegments,
60
61
  method: capturedCall.method,
61
62
  tags: resolvedTags,
62
63
  requestOptions: capturedCall.options,
@@ -65,11 +66,8 @@ function createInjectRead(options) {
65
66
  pluginExecutor,
66
67
  hookId,
67
68
  fetchFn: async (fetchOpts) => {
68
- let current = api;
69
- for (const segment of resolvedPath) {
70
- current = current[segment];
71
- }
72
- const method = current[capturedCall.method];
69
+ const pathMethods = api(capturedCall.path);
70
+ const method = pathMethods[capturedCall.method];
73
71
  return method(fetchOpts);
74
72
  }
75
73
  });
@@ -79,7 +77,7 @@ function createInjectRead(options) {
79
77
  dataSignal.set(state.data);
80
78
  errorSignal.set(state.error);
81
79
  const entry = stateManager.getCache(queryKey);
82
- const newMeta = entry?.pluginResult ? Object.fromEntries(entry.pluginResult) : {};
80
+ const newMeta = entry?.meta ? Object.fromEntries(entry.meta) : {};
83
81
  metaSignal.set(newMeta);
84
82
  });
85
83
  currentController = controller;
@@ -114,12 +112,13 @@ function createInjectRead(options) {
114
112
  const initialCapturedCall = initialSelectorResult.call;
115
113
  if (!initialCapturedCall) {
116
114
  throw new Error(
117
- "injectRead requires calling an HTTP method ($get). Example: injectRead((api) => api.posts.$get())"
115
+ 'injectRead requires calling an HTTP method (GET). Example: injectRead((api) => api("posts").GET())'
118
116
  );
119
117
  }
120
118
  const initialRequestOptions = initialCapturedCall.options;
119
+ const initialPathSegments = initialCapturedCall.path.split("/").filter(Boolean);
121
120
  const initialResolvedPath = resolvePath(
122
- initialCapturedCall.path,
121
+ initialPathSegments,
123
122
  initialRequestOptions?.params
124
123
  );
125
124
  const initialResolvedTags = resolveTags(
@@ -127,16 +126,11 @@ function createInjectRead(options) {
127
126
  initialResolvedPath
128
127
  );
129
128
  const initialQueryKey = stateManager.createQueryKey({
130
- path: initialCapturedCall.path,
129
+ path: initialPathSegments,
131
130
  method: initialCapturedCall.method,
132
131
  options: initialCapturedCall.options
133
132
  });
134
- createController(
135
- initialCapturedCall,
136
- initialResolvedPath,
137
- initialResolvedTags,
138
- initialQueryKey
139
- );
133
+ createController(initialCapturedCall, initialResolvedTags, initialQueryKey);
140
134
  loadingSignal.set(false);
141
135
  let wasEnabled = false;
142
136
  effect(
@@ -146,20 +140,18 @@ function createInjectRead(options) {
146
140
  const capturedCall = selectorResult.call;
147
141
  if (!capturedCall) {
148
142
  throw new Error(
149
- "injectRead requires calling an HTTP method ($get). Example: injectRead((api) => api.posts.$get())"
143
+ 'injectRead requires calling an HTTP method (GET). Example: injectRead((api) => api("posts").GET())'
150
144
  );
151
145
  }
152
146
  const requestOptions = capturedCall.options;
153
- const resolvedPath = resolvePath(
154
- capturedCall.path,
155
- requestOptions?.params
156
- );
147
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
148
+ const resolvedPath = resolvePath(pathSegments, requestOptions?.params);
157
149
  const resolvedTags = resolveTags(
158
150
  { tags, additionalTags },
159
151
  resolvedPath
160
152
  );
161
153
  const queryKey = stateManager.createQueryKey({
162
- path: capturedCall.path,
154
+ path: pathSegments,
163
155
  method: capturedCall.method,
164
156
  options: capturedCall.options
165
157
  });
@@ -171,9 +163,6 @@ function createInjectRead(options) {
171
163
  if (opts?.body !== void 0) {
172
164
  inputInner.body = opts.body;
173
165
  }
174
- if (opts?.formData !== void 0) {
175
- inputInner.formData = opts.formData;
176
- }
177
166
  if (opts?.params !== void 0) {
178
167
  inputInner.params = opts.params;
179
168
  }
@@ -191,7 +180,6 @@ function createInjectRead(options) {
191
180
  }
192
181
  const controller = createController(
193
182
  capturedCall,
194
- resolvedPath,
195
183
  resolvedTags,
196
184
  queryKey
197
185
  );
@@ -317,7 +305,7 @@ function createInjectWrite(options) {
317
305
  writeFn(selectorProxy);
318
306
  if (!selectorResult.selector) {
319
307
  throw new Error(
320
- "injectWrite requires selecting an HTTP method ($post, $put, $patch, $delete). Example: injectWrite((api) => api.posts.$post)"
308
+ 'injectWrite requires selecting an HTTP method (POST, PUT, PATCH, DELETE). Example: injectWrite((api) => api("posts").POST)'
321
309
  );
322
310
  }
323
311
  return selectorResult.selector;
@@ -350,10 +338,11 @@ function createInjectWrite(options) {
350
338
  const trigger = async (triggerOptions) => {
351
339
  const selectedEndpoint = captureSelector();
352
340
  const params = triggerOptions?.params;
353
- const resolvedPath = resolvePath2(selectedEndpoint.path, params);
341
+ const pathSegments = selectedEndpoint.path.split("/").filter(Boolean);
342
+ const resolvedPath = resolvePath2(pathSegments, params);
354
343
  const tags = resolveTags2(triggerOptions, resolvedPath);
355
344
  const queryKey = stateManager.createQueryKey({
356
- path: selectedEndpoint.path,
345
+ path: pathSegments,
357
346
  method: selectedEndpoint.method,
358
347
  options: triggerOptions
359
348
  });
@@ -364,7 +353,7 @@ function createInjectWrite(options) {
364
353
  }
365
354
  const controller = createOperationController2({
366
355
  operationType: "write",
367
- path: selectedEndpoint.path,
356
+ path: pathSegments,
368
357
  method: selectedEndpoint.method,
369
358
  tags,
370
359
  stateManager,
@@ -372,16 +361,8 @@ function createInjectWrite(options) {
372
361
  pluginExecutor,
373
362
  hookId,
374
363
  fetchFn: async (fetchOpts) => {
375
- const fetchParams = fetchOpts?.params;
376
- const fetchResolvedPath = resolvePath2(
377
- selectedEndpoint.path,
378
- fetchParams
379
- );
380
- let current = api;
381
- for (const segment of fetchResolvedPath) {
382
- current = current[segment];
383
- }
384
- const method = current[selectedEndpoint.method];
364
+ const pathMethods = api(selectedEndpoint.path);
365
+ const method = pathMethods[selectedEndpoint.method];
385
366
  return method(fetchOpts);
386
367
  }
387
368
  });
@@ -390,7 +371,7 @@ function createInjectWrite(options) {
390
371
  dataSignal.set(state.data);
391
372
  errorSignal.set(state.error);
392
373
  const entry = stateManager.getCache(queryKey);
393
- const newMeta = entry?.pluginResult ? Object.fromEntries(entry.pluginResult) : {};
374
+ const newMeta = entry?.meta ? Object.fromEntries(entry.meta) : {};
394
375
  metaSignal.set(newMeta);
395
376
  });
396
377
  currentController = controller;
@@ -427,9 +408,6 @@ function createInjectWrite(options) {
427
408
  if (opts?.body !== void 0) {
428
409
  inputInner.body = opts.body;
429
410
  }
430
- if (opts?.formData !== void 0) {
431
- inputInner.formData = opts.formData;
432
- }
433
411
  if (opts?.params !== void 0) {
434
412
  inputInner.params = opts.params;
435
413
  }
@@ -503,7 +481,7 @@ function createInjectInfiniteRead(options) {
503
481
  readFn(selectorProxy);
504
482
  if (!selectorResult.call) {
505
483
  throw new Error(
506
- "injectInfiniteRead requires calling an HTTP method ($get). Example: injectInfiniteRead((api) => api.posts.$get())"
484
+ 'injectInfiniteRead requires calling an HTTP method (GET). Example: injectInfiniteRead((api) => api("posts").GET())'
507
485
  );
508
486
  }
509
487
  return selectorResult.call;
@@ -560,6 +538,7 @@ function createInjectInfiniteRead(options) {
560
538
  unsubInvalidate();
561
539
  }
562
540
  const requestOptions = capturedCall.options;
541
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
563
542
  const baseOptionsForKey = {
564
543
  ...capturedCall.options,
565
544
  query: void 0,
@@ -572,7 +551,7 @@ function createInjectInfiniteRead(options) {
572
551
  body: requestOptions?.body
573
552
  };
574
553
  const controller = createInfiniteReadController({
575
- path: capturedCall.path,
554
+ path: pathSegments,
576
555
  method: capturedCall.method,
577
556
  tags: resolvedTags,
578
557
  initialRequest,
@@ -587,12 +566,8 @@ function createInjectInfiniteRead(options) {
587
566
  pluginExecutor,
588
567
  hookId,
589
568
  fetchFn: async (opts, abortSignal) => {
590
- const fetchPath = resolvePath3(capturedCall.path, opts.params);
591
- let current = api;
592
- for (const segment of fetchPath) {
593
- current = current[segment];
594
- }
595
- const method = current[capturedCall.method];
569
+ const pathMethods = api(capturedCall.path);
570
+ const method = pathMethods[capturedCall.method];
596
571
  const fetchOptions = {
597
572
  ...capturedCall.options,
598
573
  query: opts.query,
@@ -612,7 +587,7 @@ function createInjectInfiniteRead(options) {
612
587
  canFetchNextSignal.set(state.canFetchNext);
613
588
  canFetchPrevSignal.set(state.canFetchPrev);
614
589
  const entry = stateManager.getCache(queryKey);
615
- const newMeta = entry?.pluginResult ? Object.fromEntries(entry.pluginResult) : {};
590
+ const newMeta = entry?.meta ? Object.fromEntries(entry.meta) : {};
616
591
  metaSignal.set(newMeta);
617
592
  });
618
593
  currentController = controller;
@@ -638,8 +613,9 @@ function createInjectInfiniteRead(options) {
638
613
  };
639
614
  const initialCapturedCall = captureSelector();
640
615
  const initialRequestOptions = initialCapturedCall.options;
616
+ const initialPathSegments = initialCapturedCall.path.split("/").filter(Boolean);
641
617
  const initialResolvedPath = resolvePath3(
642
- initialCapturedCall.path,
618
+ initialPathSegments,
643
619
  initialRequestOptions?.params
644
620
  );
645
621
  const initialResolvedTags = resolveTags3(
@@ -653,7 +629,7 @@ function createInjectInfiniteRead(options) {
653
629
  body: void 0
654
630
  };
655
631
  const initialQueryKey = stateManager.createQueryKey({
656
- path: initialCapturedCall.path,
632
+ path: initialPathSegments,
657
633
  method: initialCapturedCall.method,
658
634
  options: initialBaseOptionsForKey
659
635
  });
@@ -663,10 +639,8 @@ function createInjectInfiniteRead(options) {
663
639
  const isEnabled = getEnabled();
664
640
  const capturedCall = captureSelector();
665
641
  const requestOptions = capturedCall.options;
666
- const resolvedPath = resolvePath3(
667
- capturedCall.path,
668
- requestOptions?.params
669
- );
642
+ const pathSegments = capturedCall.path.split("/").filter(Boolean);
643
+ const resolvedPath = resolvePath3(pathSegments, requestOptions?.params);
670
644
  const resolvedTags = resolveTags3(
671
645
  { tags, additionalTags },
672
646
  resolvedPath
@@ -678,7 +652,7 @@ function createInjectInfiniteRead(options) {
678
652
  body: void 0
679
653
  };
680
654
  const queryKey = stateManager.createQueryKey({
681
- path: capturedCall.path,
655
+ path: pathSegments,
682
656
  method: capturedCall.method,
683
657
  options: baseOptionsForKey
684
658
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/angular",
3
- "version": "0.1.4",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "description": "Angular signals integration for Spoosh API client",
6
6
  "keywords": [
@@ -34,11 +34,11 @@
34
34
  }
35
35
  },
36
36
  "peerDependencies": {
37
- "@spoosh/core": ">=0.4.0",
37
+ "@spoosh/core": ">=0.6.0",
38
38
  "@angular/core": ">=16.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@spoosh/core": "0.4.3"
41
+ "@spoosh/core": "0.6.0"
42
42
  },
43
43
  "scripts": {
44
44
  "dev": "tsup --watch",