@spoosh/angular 0.10.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,48 +1,33 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- create: () => create
24
- });
25
- module.exports = __toCommonJS(src_exports);
26
-
27
1
  // src/injectRead/index.ts
28
- var import_core = require("@angular/core");
29
- var import_core2 = require("@spoosh/core");
2
+ import {
3
+ signal,
4
+ effect,
5
+ DestroyRef,
6
+ inject,
7
+ untracked
8
+ } from "@angular/core";
9
+ import {
10
+ createOperationController,
11
+ createSelectorProxy,
12
+ resolvePath,
13
+ resolveTags
14
+ } from "@spoosh/core";
30
15
  function createInjectRead(options) {
31
16
  const { api, stateManager, eventEmitter, pluginExecutor } = options;
32
17
  return function injectRead(readFn, readOptions) {
33
- const destroyRef = (0, import_core.inject)(import_core.DestroyRef);
18
+ const destroyRef = inject(DestroyRef);
34
19
  const {
35
20
  enabled: enabledOption = true,
36
21
  tags,
37
22
  ...pluginOpts
38
23
  } = readOptions ?? {};
39
24
  const getEnabled = () => typeof enabledOption === "function" ? enabledOption() : enabledOption;
40
- const dataSignal = (0, import_core.signal)(void 0);
41
- const errorSignal = (0, import_core.signal)(void 0);
42
- const loadingSignal = (0, import_core.signal)(true);
43
- const fetchingSignal = (0, import_core.signal)(false);
44
- const inputSignal = (0, import_core.signal)({});
45
- const metaSignal = (0, import_core.signal)({});
25
+ const dataSignal = signal(void 0);
26
+ const errorSignal = signal(void 0);
27
+ const loadingSignal = signal(true);
28
+ const fetchingSignal = signal(false);
29
+ const inputSignal = signal({});
30
+ const metaSignal = signal({});
46
31
  let currentController = null;
47
32
  let currentQueryKey = null;
48
33
  let baseQueryKey = null;
@@ -56,7 +41,7 @@ function createInjectRead(options) {
56
41
  call: null,
57
42
  selector: null
58
43
  };
59
- const selectorProxy = (0, import_core2.createSelectorProxy)(
44
+ const selectorProxy = createSelectorProxy(
60
45
  (result2) => {
61
46
  selectorResult.call = result2.call;
62
47
  selectorResult.selector = result2.selector;
@@ -69,7 +54,7 @@ function createInjectRead(options) {
69
54
  if (currentSubscription) {
70
55
  currentSubscription();
71
56
  }
72
- const controller = (0, import_core2.createOperationController)({
57
+ const controller = createOperationController({
73
58
  operationType: "read",
74
59
  path: capturedCall.path,
75
60
  method: capturedCall.method,
@@ -136,11 +121,11 @@ function createInjectRead(options) {
136
121
  }
137
122
  const initialRequestOptions = initialCapturedCall.options;
138
123
  const initialPathSegments = initialCapturedCall.path.split("/").filter(Boolean);
139
- const initialResolvedPath = (0, import_core2.resolvePath)(
124
+ const initialResolvedPath = resolvePath(
140
125
  initialPathSegments,
141
126
  initialRequestOptions?.params
142
127
  );
143
- const initialResolvedTags = (0, import_core2.resolveTags)(
128
+ const initialResolvedTags = resolveTags(
144
129
  tags !== void 0 ? { tags } : void 0,
145
130
  initialResolvedPath
146
131
  );
@@ -153,7 +138,7 @@ function createInjectRead(options) {
153
138
  baseQueryKey = initialQueryKey;
154
139
  loadingSignal.set(false);
155
140
  let wasEnabled = false;
156
- (0, import_core.effect)(
141
+ effect(
157
142
  () => {
158
143
  const isEnabled = getEnabled();
159
144
  const selectorResult = captureSelector();
@@ -165,8 +150,8 @@ function createInjectRead(options) {
165
150
  }
166
151
  const requestOptions = capturedCall.options;
167
152
  const pathSegments = capturedCall.path.split("/").filter(Boolean);
168
- const resolvedPath = (0, import_core2.resolvePath)(pathSegments, requestOptions?.params);
169
- const resolvedTags = (0, import_core2.resolveTags)(
153
+ const resolvedPath = resolvePath(pathSegments, requestOptions?.params);
154
+ const resolvedTags = resolveTags(
170
155
  tags !== void 0 ? { tags } : void 0,
171
156
  resolvedPath
172
157
  );
@@ -211,7 +196,7 @@ function createInjectRead(options) {
211
196
  if (isEnabled) {
212
197
  controller.mount();
213
198
  isMounted = true;
214
- (0, import_core.untracked)(() => {
199
+ untracked(() => {
215
200
  executeWithTracking(controller, false);
216
201
  });
217
202
  } else {
@@ -221,7 +206,7 @@ function createInjectRead(options) {
221
206
  if (isEnabled && !isMounted) {
222
207
  currentController.mount();
223
208
  isMounted = true;
224
- (0, import_core.untracked)(() => {
209
+ untracked(() => {
225
210
  executeWithTracking(currentController, false);
226
211
  });
227
212
  } else if (!isEnabled && isMounted) {
@@ -237,7 +222,7 @@ function createInjectRead(options) {
237
222
  "refetch",
238
223
  (event) => {
239
224
  if (event.queryKey === currentQueryKey && currentController) {
240
- (0, import_core.untracked)(() => {
225
+ untracked(() => {
241
226
  executeWithTracking(currentController, true);
242
227
  });
243
228
  }
@@ -250,7 +235,7 @@ function createInjectRead(options) {
250
235
  (tag) => currentResolvedTags.includes(tag)
251
236
  );
252
237
  if (hasMatch && currentController) {
253
- (0, import_core.untracked)(() => {
238
+ untracked(() => {
254
239
  executeWithTracking(currentController, true);
255
240
  });
256
241
  }
@@ -258,7 +243,7 @@ function createInjectRead(options) {
258
243
  );
259
244
  const unsubRefetchAll = eventEmitter.on("refetchAll", () => {
260
245
  if (currentController) {
261
- (0, import_core.untracked)(() => {
246
+ untracked(() => {
262
247
  executeWithTracking(currentController, true);
263
248
  });
264
249
  }
@@ -310,8 +295,8 @@ function createInjectRead(options) {
310
295
  return executeWithTracking(currentController, force, overrideOptions);
311
296
  }
312
297
  const params = mergedOptions?.params;
313
- const newResolvedPath = (0, import_core2.resolvePath)(pathSegments, params);
314
- const newResolvedTags = (0, import_core2.resolveTags)(
298
+ const newResolvedPath = resolvePath(pathSegments, params);
299
+ const newResolvedTags = resolveTags(
315
300
  tags !== void 0 ? { tags } : void 0,
316
301
  newResolvedPath
317
302
  );
@@ -341,18 +326,23 @@ function createInjectRead(options) {
341
326
  }
342
327
 
343
328
  // src/injectWrite/index.ts
344
- var import_core3 = require("@angular/core");
345
- var import_core4 = require("@spoosh/core");
329
+ import { signal as signal2, effect as effect2, DestroyRef as DestroyRef2, inject as inject2 } from "@angular/core";
330
+ import {
331
+ createOperationController as createOperationController2,
332
+ createSelectorProxy as createSelectorProxy2,
333
+ resolvePath as resolvePath2,
334
+ resolveTags as resolveTags2
335
+ } from "@spoosh/core";
346
336
  function createInjectWrite(options) {
347
337
  const { api, stateManager, pluginExecutor, eventEmitter } = options;
348
338
  function injectWrite(writeFn, writeOptions) {
349
- const destroyRef = (0, import_core3.inject)(import_core3.DestroyRef);
339
+ const destroyRef = inject2(DestroyRef2);
350
340
  const captureSelector = () => {
351
341
  const selectorResult = {
352
342
  call: null,
353
343
  selector: null
354
344
  };
355
- const selectorProxy = (0, import_core4.createSelectorProxy)(
345
+ const selectorProxy = createSelectorProxy2(
356
346
  (result2) => {
357
347
  selectorResult.call = result2.call;
358
348
  selectorResult.selector = result2.selector;
@@ -370,11 +360,11 @@ function createInjectWrite(options) {
370
360
  let currentQueryKey = null;
371
361
  let currentController = null;
372
362
  let currentSubscription = null;
373
- const dataSignal = (0, import_core3.signal)(void 0);
374
- const errorSignal = (0, import_core3.signal)(void 0);
375
- const loadingSignal = (0, import_core3.signal)(false);
376
- const lastTriggerOptionsSignal = (0, import_core3.signal)(void 0);
377
- const metaSignal = (0, import_core3.signal)({});
363
+ const dataSignal = signal2(void 0);
364
+ const errorSignal = signal2(void 0);
365
+ const loadingSignal = signal2(false);
366
+ const lastTriggerOptionsSignal = signal2(void 0);
367
+ const metaSignal = signal2({});
378
368
  destroyRef.onDestroy(() => {
379
369
  if (currentSubscription) {
380
370
  currentSubscription();
@@ -387,8 +377,8 @@ function createInjectWrite(options) {
387
377
  const selectedEndpoint = captureSelector();
388
378
  const params = triggerOptions?.params;
389
379
  const pathSegments = selectedEndpoint.path.split("/").filter(Boolean);
390
- const resolvedPath = (0, import_core4.resolvePath)(pathSegments, params);
391
- const tags = (0, import_core4.resolveTags)(triggerOptions, resolvedPath);
380
+ const resolvedPath = resolvePath2(pathSegments, params);
381
+ const tags = resolveTags2(triggerOptions, resolvedPath);
392
382
  const queryKey = stateManager.createQueryKey({
393
383
  path: selectedEndpoint.path,
394
384
  method: selectedEndpoint.method,
@@ -399,7 +389,7 @@ function createInjectWrite(options) {
399
389
  if (currentSubscription) {
400
390
  currentSubscription();
401
391
  }
402
- const controller = (0, import_core4.createOperationController)({
392
+ const controller = createOperationController2({
403
393
  operationType: "write",
404
394
  path: selectedEndpoint.path,
405
395
  method: selectedEndpoint.method,
@@ -447,8 +437,8 @@ function createInjectWrite(options) {
447
437
  loadingSignal.set(false);
448
438
  }
449
439
  };
450
- const inputSignal = (0, import_core3.signal)({});
451
- (0, import_core3.effect)(
440
+ const inputSignal = signal2({});
441
+ effect2(
452
442
  () => {
453
443
  const opts = lastTriggerOptionsSignal();
454
444
  const inputInner = {};
@@ -480,12 +470,24 @@ function createInjectWrite(options) {
480
470
  }
481
471
 
482
472
  // src/injectPages/index.ts
483
- var import_core5 = require("@angular/core");
484
- var import_core6 = require("@spoosh/core");
473
+ import {
474
+ signal as signal3,
475
+ computed,
476
+ effect as effect3,
477
+ DestroyRef as DestroyRef3,
478
+ inject as inject3,
479
+ untracked as untracked2
480
+ } from "@angular/core";
481
+ import {
482
+ createInfiniteReadController,
483
+ createSelectorProxy as createSelectorProxy3,
484
+ resolvePath as resolvePath3,
485
+ resolveTags as resolveTags3
486
+ } from "@spoosh/core";
485
487
  function createInjectPages(options) {
486
488
  const { api, stateManager, eventEmitter, pluginExecutor } = options;
487
489
  return function injectPages(readFn, readOptions) {
488
- const destroyRef = (0, import_core5.inject)(import_core5.DestroyRef);
490
+ const destroyRef = inject3(DestroyRef3);
489
491
  const {
490
492
  enabled: enabledOption = true,
491
493
  tags,
@@ -509,7 +511,7 @@ function createInjectPages(options) {
509
511
  call: null,
510
512
  selector: null
511
513
  };
512
- const selectorProxy = (0, import_core6.createSelectorProxy)(
514
+ const selectorProxy = createSelectorProxy3(
513
515
  (result2) => {
514
516
  selectorResult.call = result2.call;
515
517
  selectorResult.selector = result2.selector;
@@ -524,14 +526,14 @@ function createInjectPages(options) {
524
526
  return selectorResult.call;
525
527
  };
526
528
  const instanceId = `angular-${Math.random().toString(36).slice(2)}`;
527
- const dataSignal = (0, import_core5.signal)(void 0);
528
- const pagesSignal = (0, import_core5.signal)([]);
529
- const errorSignal = (0, import_core5.signal)(void 0);
530
- const loadingSignal = (0, import_core5.signal)(false);
531
- const canFetchNextSignal = (0, import_core5.signal)(false);
532
- const canFetchPrevSignal = (0, import_core5.signal)(false);
533
- const fetchingNextSignal = (0, import_core5.signal)(false);
534
- const fetchingPrevSignal = (0, import_core5.signal)(false);
529
+ const dataSignal = signal3(void 0);
530
+ const pagesSignal = signal3([]);
531
+ const errorSignal = signal3(void 0);
532
+ const loadingSignal = signal3(false);
533
+ const canFetchNextSignal = signal3(false);
534
+ const canFetchPrevSignal = signal3(false);
535
+ const fetchingNextSignal = signal3(false);
536
+ const fetchingPrevSignal = signal3(false);
535
537
  let currentController = null;
536
538
  let currentQueryKey = null;
537
539
  let currentSubscription = null;
@@ -554,7 +556,7 @@ function createInjectPages(options) {
554
556
  const triggerFetch = () => {
555
557
  if (!currentController) return;
556
558
  const currentState = currentController.getState();
557
- const isFetching = (0, import_core5.untracked)(
559
+ const isFetching = untracked2(
558
560
  () => fetchingNextSignal() || fetchingPrevSignal()
559
561
  );
560
562
  if (currentState.data === void 0 && !isFetching) {
@@ -586,7 +588,7 @@ function createInjectPages(options) {
586
588
  params: requestOptions?.params,
587
589
  body: requestOptions?.body
588
590
  };
589
- const controller = (0, import_core6.createInfiniteReadController)({
591
+ const controller = createInfiniteReadController({
590
592
  path: capturedCall.path,
591
593
  method: capturedCall.method,
592
594
  tags: resolvedTags,
@@ -654,11 +656,11 @@ function createInjectPages(options) {
654
656
  const initialCapturedCall = captureSelector();
655
657
  const initialRequestOptions = initialCapturedCall.options;
656
658
  const initialPathSegments = initialCapturedCall.path.split("/").filter(Boolean);
657
- const initialResolvedPath = (0, import_core6.resolvePath)(
659
+ const initialResolvedPath = resolvePath3(
658
660
  initialPathSegments,
659
661
  initialRequestOptions?.params
660
662
  );
661
- const initialResolvedTags = (0, import_core6.resolveTags)(
663
+ const initialResolvedTags = resolveTags3(
662
664
  tags !== void 0 ? { tags } : void 0,
663
665
  initialResolvedPath
664
666
  );
@@ -668,14 +670,14 @@ function createInjectPages(options) {
668
670
  options: initialCapturedCall.options
669
671
  });
670
672
  createController(initialCapturedCall, initialResolvedTags, initialQueryKey);
671
- (0, import_core5.effect)(
673
+ effect3(
672
674
  () => {
673
675
  const isEnabled = getEnabled();
674
676
  const capturedCall = captureSelector();
675
677
  const requestOptions = capturedCall.options;
676
678
  const pathSegments = capturedCall.path.split("/").filter(Boolean);
677
- const resolvedPath = (0, import_core6.resolvePath)(pathSegments, requestOptions?.params);
678
- const resolvedTags = (0, import_core6.resolveTags)(
679
+ const resolvedPath = resolvePath3(pathSegments, requestOptions?.params);
680
+ const resolvedTags = resolveTags3(
679
681
  tags !== void 0 ? { tags } : void 0,
680
682
  resolvedPath
681
683
  );
@@ -710,7 +712,7 @@ function createInjectPages(options) {
710
712
  }
711
713
  controller.mount();
712
714
  isMounted = true;
713
- (0, import_core5.untracked)(() => {
715
+ untracked2(() => {
714
716
  loadingSignal.set(true);
715
717
  fetchingNextSignal.set(true);
716
718
  errorSignal.set(void 0);
@@ -723,7 +725,7 @@ function createInjectPages(options) {
723
725
  } else if (!isMounted && currentController) {
724
726
  currentController.mount();
725
727
  isMounted = true;
726
- (0, import_core5.untracked)(() => {
728
+ untracked2(() => {
727
729
  triggerFetch();
728
730
  });
729
731
  }
@@ -789,7 +791,7 @@ function createInjectPages(options) {
789
791
  const abort = () => {
790
792
  currentController?.abort();
791
793
  };
792
- const fetchingSignal = (0, import_core5.computed)(
794
+ const fetchingSignal = computed(
793
795
  () => fetchingNextSignal() || fetchingPrevSignal()
794
796
  );
795
797
  const result = {
@@ -812,18 +814,21 @@ function createInjectPages(options) {
812
814
  }
813
815
 
814
816
  // src/injectQueue/index.ts
815
- var import_core7 = require("@angular/core");
816
- var import_core8 = require("@spoosh/core");
817
+ import { signal as signal4, DestroyRef as DestroyRef4, inject as inject4 } from "@angular/core";
818
+ import {
819
+ createSelectorProxy as createSelectorProxy4,
820
+ createQueueController
821
+ } from "@spoosh/core";
817
822
  function createInjectQueue(options) {
818
823
  const { api, stateManager, pluginExecutor, eventEmitter } = options;
819
824
  function injectQueue(queueFn, queueOptions) {
820
- const destroyRef = (0, import_core7.inject)(import_core7.DestroyRef);
825
+ const destroyRef = inject4(DestroyRef4);
821
826
  const captureSelector = () => {
822
827
  const selectorResult = {
823
828
  call: null,
824
829
  selector: null
825
830
  };
826
- const selectorProxy = (0, import_core8.createSelectorProxy)(
831
+ const selectorProxy = createSelectorProxy4(
827
832
  (result) => {
828
833
  selectorResult.call = result.call;
829
834
  selectorResult.selector = result.selector;
@@ -847,14 +852,14 @@ function createInjectQueue(options) {
847
852
  operationType: "queue",
848
853
  hookOptions
849
854
  };
850
- const controller = (0, import_core8.createQueueController)(config, {
855
+ const controller = createQueueController(config, {
851
856
  api,
852
857
  stateManager,
853
858
  eventEmitter,
854
859
  pluginExecutor
855
860
  });
856
- const tasksSignal = (0, import_core7.signal)(controller.getQueue());
857
- const statsSignal = (0, import_core7.signal)(controller.getStats());
861
+ const tasksSignal = signal4(controller.getQueue());
862
+ const statsSignal = signal4(controller.getStats());
858
863
  const unsubscribe = controller.subscribe(() => {
859
864
  tasksSignal.set(controller.getQueue());
860
865
  statsSignal.set(controller.getStats());
@@ -917,16 +922,16 @@ function create(instance) {
917
922
  for (const plugin of plugins) {
918
923
  plugin.setup?.(setupContext);
919
924
  }
920
- const instanceApiContext = {
921
- api,
925
+ const apiContext = {
926
+ spoosh: api,
922
927
  stateManager,
923
928
  eventEmitter,
924
929
  pluginExecutor
925
930
  };
926
- const instanceApis = plugins.reduce(
931
+ const pluginApis = plugins.reduce(
927
932
  (acc, plugin) => {
928
- if (plugin.instanceApi) {
929
- return { ...acc, ...plugin.instanceApi(instanceApiContext) };
933
+ if (plugin.api) {
934
+ return { ...acc, ...plugin.api(apiContext) };
930
935
  }
931
936
  return acc;
932
937
  },
@@ -937,6 +942,9 @@ function create(instance) {
937
942
  injectWrite,
938
943
  injectPages,
939
944
  injectQueue,
940
- ...instanceApis
945
+ ...pluginApis
941
946
  };
942
947
  }
948
+ export {
949
+ create
950
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/angular",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "license": "MIT",
5
5
  "description": "Angular signals integration for Spoosh API toolkit",
6
6
  "keywords": [
@@ -23,24 +23,24 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
+ "type": "module",
26
27
  "files": [
27
28
  "dist"
28
29
  ],
29
30
  "exports": {
30
31
  ".": {
31
32
  "types": "./dist/index.d.ts",
32
- "import": "./dist/index.mjs",
33
- "require": "./dist/index.js"
33
+ "import": "./dist/index.js"
34
34
  }
35
35
  },
36
36
  "peerDependencies": {
37
- "@spoosh/core": ">=0.15.0",
37
+ "@spoosh/core": ">=0.17.0",
38
38
  "@angular/core": ">=16.0.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@angular/core": "^21.1.0",
42
- "@spoosh/core": "0.16.0",
43
- "@spoosh/test-utils": "0.3.0"
42
+ "@spoosh/test-utils": "0.3.0",
43
+ "@spoosh/core": "0.17.0"
44
44
  },
45
45
  "scripts": {
46
46
  "dev": "tsup --watch",