@tstdl/base 0.85.16 → 0.85.18

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.
@@ -1,5 +1,5 @@
1
- import { Collection } from './collection.js';
2
- export declare class SetCollection<T> extends Collection<T, SetCollection<T>> implements globalThis.Set<T> {
1
+ import { DistinctCollection } from './distinct-collection.js';
2
+ export declare class SetCollection<T> extends DistinctCollection<T, SetCollection<T>> implements globalThis.Set<T> {
3
3
  private readonly backingSet;
4
4
  readonly [Symbol.toStringTag]: string;
5
5
  constructor(items?: Iterable<T>);
@@ -21,8 +21,8 @@ __export(set_collection_exports, {
21
21
  SetCollection: () => SetCollection
22
22
  });
23
23
  module.exports = __toCommonJS(set_collection_exports);
24
- var import_collection = require("./collection.js");
25
- class SetCollection extends import_collection.Collection {
24
+ var import_distinct_collection = require("./distinct-collection.js");
25
+ class SetCollection extends import_distinct_collection.DistinctCollection {
26
26
  backingSet;
27
27
  [Symbol.toStringTag] = "Set";
28
28
  constructor(items) {
@@ -1,10 +1,15 @@
1
1
  import type { Decorator } from '../reflection/index.js';
2
- import type { Constructor, Simplify, TypedOmit } from '../types.js';
2
+ import type { Constructor, OneOrMany, Simplify, TypedOmit } from '../types.js';
3
+ import type { Provider } from './provider.js';
3
4
  import type { InjectionToken } from './token.js';
4
- import type { InjectableMetadata } from './type-info.js';
5
- import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
6
- type InjectDecorator = Decorator<'property' | 'accessor' | 'constructorParameter'>;
7
- export type InjectableOptions<T, A> = InjectableMetadata<T, A>;
5
+ import type { ArgumentProvider, ForwardRefInjectionToken, Mapper, RegistrationOptions } from './types.js';
6
+ type InjectDecorator = Decorator<'accessor' | 'constructorParameter'>;
7
+ export type InjectableOptions<T, A> = RegistrationOptions<T, A> & {
8
+ /** aliases (tokens) for the class. Useful for example for circular dependencies when you can't use the class itself as a token */
9
+ alias?: OneOrMany<InjectionToken>;
10
+ /** custom provider. Useful for example if initialization is required */
11
+ provider?: Provider<T, A>;
12
+ };
8
13
  export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<InjectableOptions<T, A>, 'lifecycle'>>;
9
14
  /**
10
15
  * Helper decorator to replace a class definition with an other
@@ -13,7 +18,7 @@ export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<Injecta
13
18
  */
14
19
  export declare function ReplaceClass<T>(constructor: Constructor<T>): ClassDecorator;
15
20
  /**
16
- * registers the class in the global container. Decorated class is not modified in any way
21
+ * Globally registers the class for injection
17
22
  * @param options registration options
18
23
  */
19
24
  export declare function Injectable<T = any, A = any>(options?: InjectableOptions<T, A>): ClassDecorator;
@@ -41,16 +41,16 @@ function ReplaceClass(constructor) {
41
41
  }
42
42
  function Injectable(options = {}) {
43
43
  return (0, import_reflection.createClassDecorator)({
44
- data: { [import_symbols.injectableMetadataSymbol]: options },
44
+ data: { [import_symbols.injectableMetadataSymbol]: {} },
45
45
  mergeData: true,
46
46
  handler: (data) => {
47
47
  const { alias: aliases, provider, ...registrationOptions } = options;
48
48
  const token = data.constructor;
49
49
  const targetProvider = provider ?? { useClass: token };
50
- import_injector.Injector.registerGlobal(token, targetProvider, registrationOptions);
50
+ import_injector.Injector.register(token, targetProvider, registrationOptions);
51
51
  if ((0, import_type_guards.isDefined)(aliases)) {
52
52
  for (const alias of (0, import_array.toArray)(aliases)) {
53
- import_injector.Injector.registerGlobal(alias, { useToken: token }, registrationOptions);
53
+ import_injector.Injector.register(alias, { useToken: token }, registrationOptions);
54
54
  }
55
55
  }
56
56
  }
@@ -43,19 +43,19 @@ export declare class Injector {
43
43
  readonly name: string;
44
44
  constructor(name: string, parent?: Injector | null);
45
45
  /**
46
- * Register a provider for a token
46
+ * Globally register a provider for a token
47
47
  * @param token token to register
48
48
  * @param provider provider used to resolve the token
49
49
  * @param options registration options
50
50
  */
51
- static registerGlobal<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
51
+ static register<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
52
52
  /**
53
- * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
53
+ * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
54
54
  * @param token token to register
55
55
  * @param provider provider used to resolve the token
56
56
  * @param options registration options
57
57
  */
58
- static registerGlobalSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
58
+ static registerSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
59
59
  fork(name: string): Injector;
60
60
  /**
61
61
  * Register a provider for a token
@@ -48,12 +48,12 @@ class Injector {
48
48
  this.register(Injector, { useValue: this });
49
49
  }
50
50
  /**
51
- * Register a provider for a token
51
+ * Globally register a provider for a token
52
52
  * @param token token to register
53
53
  * @param provider provider used to resolve the token
54
54
  * @param options registration options
55
55
  */
56
- static registerGlobal(token, provider, options = {}) {
56
+ static register(token, provider, options = {}) {
57
57
  const registration = {
58
58
  token,
59
59
  provider,
@@ -62,13 +62,13 @@ class Injector {
62
62
  addRegistration(Injector.#globalRegistrations, registration);
63
63
  }
64
64
  /**
65
- * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
65
+ * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
66
66
  * @param token token to register
67
67
  * @param provider provider used to resolve the token
68
68
  * @param options registration options
69
69
  */
70
- static registerGlobalSingleton(token, provider, options) {
71
- Injector.registerGlobal(token, provider, { ...options, lifecycle: "singleton" });
70
+ static registerSingleton(token, provider, options) {
71
+ Injector.register(token, provider, { ...options, lifecycle: "singleton" });
72
72
  }
73
73
  fork(name) {
74
74
  return new Injector(name, this);
@@ -1,13 +1,5 @@
1
- import type { OneOrMany } from '../types.js';
2
- import type { Provider } from './provider.js';
3
1
  import type { InjectionToken } from './token.js';
4
- import type { ArgumentProvider, ForwardRefInjectionToken, Mapper, RegistrationOptions } from './types.js';
5
- export type InjectableMetadata<T, A> = RegistrationOptions<T, A> & {
6
- /** aliases (tokens) for the class. Useful for example for circular dependencies when you can't use the class itself as a token */
7
- alias?: OneOrMany<InjectionToken>;
8
- /** custom provider. Useful for example if initialization is required */
9
- provider?: Provider<T, A>;
10
- };
2
+ import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
11
3
  export type InjectMetadata = {
12
4
  /** token overwrite by inject decorator */
13
5
  injectToken?: InjectionToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.85.16",
3
+ "version": "0.85.18",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/rxjs/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './performance-observer.js';
7
7
  export * from './resize-observer.js';
8
8
  export * from './retry-backoff.js';
9
9
  export * from './slow-array.js';
10
+ export * from './start-with-provider.js';
10
11
  export * from './teardown.js';
11
12
  export * from './timing.js';
12
13
  export * from './touch.js';
package/rxjs/index.js CHANGED
@@ -24,6 +24,7 @@ __reExport(rxjs_exports, require("./performance-observer.js"), module.exports);
24
24
  __reExport(rxjs_exports, require("./resize-observer.js"), module.exports);
25
25
  __reExport(rxjs_exports, require("./retry-backoff.js"), module.exports);
26
26
  __reExport(rxjs_exports, require("./slow-array.js"), module.exports);
27
+ __reExport(rxjs_exports, require("./start-with-provider.js"), module.exports);
27
28
  __reExport(rxjs_exports, require("./teardown.js"), module.exports);
28
29
  __reExport(rxjs_exports, require("./timing.js"), module.exports);
29
30
  __reExport(rxjs_exports, require("./touch.js"), module.exports);
@@ -0,0 +1,2 @@
1
+ import type { OperatorFunction } from 'rxjs';
2
+ export declare function startWithProvider<T, D>(valueProvider: () => D): OperatorFunction<T, T | D>;
@@ -0,0 +1,29 @@
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
+ var start_with_provider_exports = {};
20
+ __export(start_with_provider_exports, {
21
+ startWithProvider: () => startWithProvider
22
+ });
23
+ module.exports = __toCommonJS(start_with_provider_exports);
24
+ var import_rxjs = require("rxjs");
25
+ function startWithProvider(valueProvider) {
26
+ return function startWithProvider2(source) {
27
+ return (0, import_rxjs.concat)((0, import_rxjs.defer)(() => (0, import_rxjs.of)(valueProvider())), source);
28
+ };
29
+ }
package/signals/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type * as Types from './implementation/index.js';
2
- export type { CreateComputedOptions, CreateEffectOptions, CreateSignalOptions, EffectCleanupRegisterFn, EffectRef, Signal, WritableSignal } from './implementation/index.js';
2
+ export type { CreateComputedOptions, CreateEffectOptions, CreateSignalOptions, EffectCleanupRegisterFn, EffectRef, Signal, ToSignalOptions, WritableSignal } from './implementation/index.js';
3
3
  export type SignalsConfiguration = {
4
4
  signal: typeof Types.signal;
5
5
  computed: typeof Types.computed;
package/signals/api.js CHANGED
@@ -28,13 +28,13 @@ __export(api_exports, {
28
28
  untracked: () => untracked
29
29
  });
30
30
  module.exports = __toCommonJS(api_exports);
31
- let signal;
32
- let computed;
33
- let effect;
34
- let untracked;
35
- let isSignal;
36
- let toSignal;
37
- let toObservable;
31
+ let signal = throwSignalsNotConfigured;
32
+ let computed = throwSignalsNotConfigured;
33
+ let effect = throwSignalsNotConfigured;
34
+ let untracked = throwSignalsNotConfigured;
35
+ let isSignal = throwSignalsNotConfigured;
36
+ let toSignal = throwSignalsNotConfigured;
37
+ let toObservable = throwSignalsNotConfigured;
38
38
  function configureSignals(configuration) {
39
39
  signal = configuration.signal;
40
40
  computed = configuration.computed;
@@ -44,3 +44,6 @@ function configureSignals(configuration) {
44
44
  toSignal = configuration.toSignal;
45
45
  toObservable = configuration.toObservable;
46
46
  }
47
+ function throwSignalsNotConfigured() {
48
+ throw new Error("Signals are not configured. Use configureDefaultSignalsImplementation() for default implementation or configureSignals() for custom implementation.");
49
+ }
@@ -71,7 +71,7 @@ class ReactiveNode {
71
71
  consumerPollProducersForChange() {
72
72
  for (const [producerId, edge] of this.producers) {
73
73
  const producer = edge.producerNode.deref();
74
- if (producer === void 0 || edge.atTrackingVersion !== this.trackingVersion) {
74
+ if (producer == null || edge.atTrackingVersion !== this.trackingVersion) {
75
75
  this.producers.delete(producerId);
76
76
  producer?.consumers.delete(this.id);
77
77
  continue;
@@ -91,7 +91,7 @@ class ReactiveNode {
91
91
  try {
92
92
  for (const [consumerId, edge] of this.consumers) {
93
93
  const consumer = edge.consumerNode.deref();
94
- if (consumer === void 0 || consumer.trackingVersion !== edge.atTrackingVersion) {
94
+ if (consumer == null || consumer.trackingVersion !== edge.atTrackingVersion) {
95
95
  this.consumers.delete(consumerId);
96
96
  consumer?.producers.delete(this.id);
97
97
  continue;
@@ -3,5 +3,6 @@ export * from './computed-with-dependencies.js';
3
3
  export * from './effect-with-dependencies.js';
4
4
  export * from './pipe.js';
5
5
  export * from './switch-map.js';
6
+ export * from './to-signal-2.js';
6
7
  export * from './types.js';
7
8
  export * from './untracked-operator.js';
package/signals/index.js CHANGED
@@ -20,5 +20,6 @@ __reExport(signals_exports, require("./computed-with-dependencies.js"), module.e
20
20
  __reExport(signals_exports, require("./effect-with-dependencies.js"), module.exports);
21
21
  __reExport(signals_exports, require("./pipe.js"), module.exports);
22
22
  __reExport(signals_exports, require("./switch-map.js"), module.exports);
23
+ __reExport(signals_exports, require("./to-signal-2.js"), module.exports);
23
24
  __reExport(signals_exports, require("./types.js"), module.exports);
24
25
  __reExport(signals_exports, require("./untracked-operator.js"), module.exports);
package/signals/pipe.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare function pipe<T, A, B, C, D, E, F, G, H>(source: Signal<T>, op1:
16
16
  export declare function pipe<T, A, B, C, D, E, F, G, H, I>(source: Signal<T>, op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Signal<I>;
17
17
  export declare function pipe(source: Signal<unknown>, ...operators: OperatorFunction<unknown, unknown>[]): Signal<unknown>;
18
18
  /**
19
- * As we need an synchronous value for the resulting signal and effect scheduling is async, you have to provide an immediate value on subscription, for example via the {@link startWith} operator, otherwise an error is thrown.
19
+ * As we need an synchronous value for the resulting signal and effect scheduling is async, you have to provide an immediate value on subscription, for example via the `startWith` operator, otherwise an error is thrown.
20
20
  */
21
21
  export declare function rawPipe<T, A>(source: Signal<T>, op1: OperatorFunction<T, A>): Signal<A>;
22
22
  export declare function rawPipe<T, A, B>(source: Signal<T>, op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Signal<B>;
package/signals/pipe.js CHANGED
@@ -23,11 +23,13 @@ __export(pipe_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(pipe_exports);
25
25
  var import_rxjs = require("rxjs");
26
+ var import_start_with_provider = require("../rxjs/start-with-provider.js");
26
27
  var import_api = require("./api.js");
28
+ var import_to_signal_2 = require("./to-signal-2.js");
27
29
  function pipe(source, ...operators) {
28
- return rawPipe(source, (0, import_rxjs.startWith)(source()), (0, import_rxjs.distinctUntilChanged)(), ...operators);
30
+ return rawPipe(source, (0, import_start_with_provider.startWithProvider)(source), (0, import_rxjs.distinctUntilChanged)(), ...operators);
29
31
  }
30
32
  function rawPipe(source, ...operators) {
31
33
  const piped = (0, import_api.toObservable)(source).pipe(...operators);
32
- return (0, import_api.toSignal)(piped, { requireSync: true });
34
+ return (0, import_to_signal_2.toSignal2)(piped, { requireSync: true });
33
35
  }
@@ -0,0 +1,14 @@
1
+ import type { Subscribable } from 'rxjs';
2
+ import type { Signal, ToSignalOptions } from './api.js';
3
+ export type ToSignal2Options<T> = ToSignalOptions<T> & {
4
+ /** defer subscription until signal is used */
5
+ lazy?: boolean;
6
+ };
7
+ /** like `toSignal`, except that it uses untracked internal operations (required for some scenarios, but might be less safe in terms of bugs catching) and has the ability to subscribe lazily */
8
+ export declare function toSignal2<T>(source: Subscribable<T>): Signal<T | undefined>;
9
+ export declare function toSignal2<T>(source: Subscribable<T>, options: ToSignal2Options<undefined> & {
10
+ requireSync: true;
11
+ }): Signal<T>;
12
+ export declare function toSignal2<T, const I = undefined>(source: Subscribable<T>, options: ToSignal2Options<I> & {
13
+ requireSync?: false;
14
+ }): Signal<T | I>;
@@ -0,0 +1,67 @@
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
+ var to_signal_2_exports = {};
20
+ __export(to_signal_2_exports, {
21
+ toSignal2: () => toSignal2
22
+ });
23
+ module.exports = __toCommonJS(to_signal_2_exports);
24
+ var import_core = require("../core.js");
25
+ var import_finalization = require("../memory/finalization.js");
26
+ var import_type_guards = require("../utils/type-guards.js");
27
+ var import_api = require("./api.js");
28
+ var StateKind;
29
+ (function(StateKind2) {
30
+ StateKind2[StateKind2["NoValue"] = 0] = "NoValue";
31
+ StateKind2[StateKind2["Value"] = 1] = "Value";
32
+ StateKind2[StateKind2["Error"] = 2] = "Error";
33
+ })(StateKind || (StateKind = {}));
34
+ function toSignal2(source, options) {
35
+ const initialState = options?.requireSync == true ? { kind: StateKind.NoValue } : { kind: StateKind.Value, value: options?.initialValue };
36
+ const state = (0, import_api.signal)(initialState);
37
+ let subscription;
38
+ if (options?.lazy != true) {
39
+ subscription = subscribe(source, state, options);
40
+ }
41
+ const result = (0, import_api.computed)(() => {
42
+ if ((0, import_type_guards.isUndefined)(subscription)) {
43
+ subscription = subscribe(source, state, options);
44
+ }
45
+ const current = state();
46
+ switch (current.kind) {
47
+ case StateKind.Value:
48
+ return current.value;
49
+ case StateKind.Error:
50
+ throw current.error;
51
+ case StateKind.NoValue:
52
+ throw new Error("`toSignalLazy()` called with `requireSync` but `Observable` did not emit synchronously.");
53
+ }
54
+ });
55
+ (0, import_finalization.registerFinalization)(result, () => subscription?.unsubscribe());
56
+ return result;
57
+ }
58
+ function subscribe(source, state, options) {
59
+ const subscription = source.subscribe({
60
+ next: (value) => (0, import_api.untracked)(() => state.set({ kind: StateKind.Value, value })),
61
+ error: (error) => (0, import_api.untracked)(() => state.set({ kind: StateKind.Error, error }))
62
+ });
63
+ if ((0, import_core.isDevMode)() && options?.requireSync == true && (0, import_api.untracked)(state).kind == StateKind.NoValue) {
64
+ throw new Error("`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.");
65
+ }
66
+ return subscription;
67
+ }