@tstdl/base 0.90.60 → 0.90.62
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/core.d.ts +2 -3
- package/function/log.d.ts +2 -1
- package/function/log.js +10 -5
- package/http/http-query.d.ts +1 -2
- package/http/server/node/node-http-server.d.ts +2 -4
- package/injector/inject.d.ts +1 -2
- package/injector/injector.d.ts +9 -4
- package/injector/injector.js +45 -35
- package/injector/types.d.ts +6 -4
- package/package.json +7 -7
- package/polyfills.d.ts +2 -159
- package/polyfills.js +2 -1
- package/reflection/decorators.d.ts +1 -1
- package/signals/defer.d.ts +1 -1
- package/signals/implementation/effect.d.ts +3 -8
- package/signals/implementation/effect.js +7 -4
- package/signals/implementation/signal.d.ts +1 -1
package/core.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { CancellationSignal } from './cancellation/token.js';
|
|
2
2
|
import { Injector } from './injector/injector.js';
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
5
|
-
import { LogLevel, Logger } from './logger/index.js';
|
|
3
|
+
import { type InjectionToken } from './injector/token.js';
|
|
4
|
+
import { LogLevel, Logger, type LoggerArgument } from './logger/index.js';
|
|
6
5
|
declare global {
|
|
7
6
|
var tstdlLoaded: boolean | undefined;
|
|
8
7
|
}
|
package/function/log.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Logger } from '../logger/logger.js';
|
|
2
2
|
export type WrapLogOptions = {
|
|
3
3
|
fnName?: string;
|
|
4
|
+
logResult?: boolean;
|
|
4
5
|
logger?: Logger;
|
|
5
6
|
trace?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare function wrapLog(fn: Function, { fnName, logger, trace }?: WrapLogOptions): Function;
|
|
8
|
+
export declare function wrapLog(fn: Function, { fnName, logResult, logger, trace }?: WrapLogOptions): Function;
|
package/function/log.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
2
|
import { isArray, isPrimitive, isString } from '../utils/type-guards.js';
|
|
3
3
|
import { typeOf } from '../utils/type-of.js';
|
|
4
|
-
export function wrapLog(fn, { fnName = fn.name, logger, trace = false } = {}) {
|
|
4
|
+
export function wrapLog(fn, { fnName = fn.name, logResult = true, logger, trace = false } = {}) {
|
|
5
5
|
const log = logger?.trace.bind(logger) ?? console.log.bind(console); // eslint-disable-line no-console
|
|
6
6
|
const wrapped = {
|
|
7
7
|
[fnName](...args) {
|
|
8
|
-
const argString = args.map((arg) =>
|
|
8
|
+
const argString = args.map((arg) => stringifyValue(arg)).join(', ');
|
|
9
9
|
log(`[call: ${fnName}(${argString})]`);
|
|
10
10
|
if (trace) {
|
|
11
11
|
console.trace();
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const result = Reflect.apply(fn, this, args);
|
|
14
|
+
if (logResult) {
|
|
15
|
+
const resultString = stringifyValue(result);
|
|
16
|
+
log(`[return: ${fnName} => ${resultString}]`);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
14
19
|
}
|
|
15
20
|
};
|
|
16
21
|
return wrapped[fnName];
|
|
17
22
|
}
|
|
18
|
-
function
|
|
23
|
+
function stringifyValue(arg, depth = 1) {
|
|
19
24
|
if (isArray(arg) && (depth > 0)) {
|
|
20
|
-
const argString = arg.map((innerArg) =>
|
|
25
|
+
const argString = arg.map((innerArg) => stringifyValue(innerArg, depth - 1)).join(', ');
|
|
21
26
|
return `[${argString}]`;
|
|
22
27
|
}
|
|
23
28
|
return isPrimitive(arg) ? isString(arg) ? `"${arg}"` : String(arg) : typeOf(arg);
|
package/http/http-query.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { HttpValueMap } from './http-value-map.js';
|
|
1
|
+
import { HttpValueMap, type HttpValueMapInput } from './http-value-map.js';
|
|
3
2
|
import type { HttpValueObject, NormalizedHttpValueObject } from './types.js';
|
|
4
3
|
export type HttpQueryObject = HttpValueObject;
|
|
5
4
|
export type NormalizedHttpQueryObject = NormalizedHttpValueObject;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import * as Http from 'node:http';
|
|
3
|
-
import type
|
|
4
|
-
import { disposeAsync } from '../../../disposable/index.js';
|
|
3
|
+
import { disposeAsync, type AsyncDisposable } from '../../../disposable/index.js';
|
|
5
4
|
import { Logger } from '../../../logger/index.js';
|
|
6
|
-
import type
|
|
7
|
-
import { HttpServer } from '../http-server.js';
|
|
5
|
+
import { HttpServer, type HttpServerRequestContext } from '../http-server.js';
|
|
8
6
|
export type NodeHttpServerContext = {
|
|
9
7
|
nodeRequest: Http.IncomingMessage;
|
|
10
8
|
nodeResponse: Http.ServerResponse;
|
package/injector/inject.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { Injector } from './injector.js';
|
|
1
|
+
import { Injector, type ResolveManyItem, type ResolveManyReturnType } from './injector.js';
|
|
3
2
|
import type { Resolvable, ResolveArgument } from './interfaces.js';
|
|
4
3
|
import type { InjectionToken } from './token.js';
|
|
5
4
|
import type { ResolveOptions } from './types.js';
|
package/injector/injector.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AsyncDisposable } from '../disposable/disposable.js';
|
|
2
2
|
import type { OneOrMany, Record, TypedOmit } from '../types.js';
|
|
3
|
-
import type
|
|
4
|
-
import type
|
|
3
|
+
import { type InjectOptions } from './inject.js';
|
|
4
|
+
import { type ResolveArgument } from './interfaces.js';
|
|
5
5
|
import { type Provider } from './provider.js';
|
|
6
6
|
import { type InjectionToken } from './token.js';
|
|
7
7
|
import type { RegistrationOptions, ResolveOptions } from './types.js';
|
|
8
|
+
export type ProvidersItem<T = any, A = any, D extends Record = Record> = Provider<T, A, D> & {
|
|
9
|
+
provide: InjectionToken<T, A>;
|
|
10
|
+
multi?: boolean;
|
|
11
|
+
};
|
|
8
12
|
export type GlobalRegistration<T = any, A = any> = {
|
|
9
13
|
token: InjectionToken<T, A>;
|
|
10
14
|
provider: Provider<T, A>;
|
|
15
|
+
providers: ProvidersItem[];
|
|
11
16
|
options: RegistrationOptions<T, A>;
|
|
12
17
|
};
|
|
13
18
|
export type Registration<T = any, A = any> = GlobalRegistration<T, A> & {
|
|
@@ -37,7 +42,7 @@ export declare class Injector implements AsyncDisposable {
|
|
|
37
42
|
* @param provider provider used to resolve the token
|
|
38
43
|
* @param options registration options
|
|
39
44
|
*/
|
|
40
|
-
static register<T, A = any,
|
|
45
|
+
static register<T, A = any, D extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, D>>, options?: RegistrationOptions<T, A, D>): void;
|
|
41
46
|
/**
|
|
42
47
|
* Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
|
|
43
48
|
* @param token token to register
|
package/injector/injector.js
CHANGED
|
@@ -54,11 +54,13 @@ export class Injector {
|
|
|
54
54
|
* @param options registration options
|
|
55
55
|
*/
|
|
56
56
|
static register(token, providers, options = {}) {
|
|
57
|
+
const multi = isArray(providers);
|
|
57
58
|
for (const provider of toArray(providers)) {
|
|
58
59
|
const registration = {
|
|
59
60
|
token,
|
|
60
61
|
provider,
|
|
61
|
-
|
|
62
|
+
providers: options.providers ?? [],
|
|
63
|
+
options: { multi, ...options }
|
|
62
64
|
};
|
|
63
65
|
addRegistration(Injector.#globalRegistrations, registration);
|
|
64
66
|
}
|
|
@@ -93,11 +95,13 @@ export class Injector {
|
|
|
93
95
|
*/
|
|
94
96
|
register(token, providers, options = {}) {
|
|
95
97
|
this.assertNotDisposed();
|
|
98
|
+
const multi = isArray(providers);
|
|
96
99
|
for (const provider of toArray(providers)) {
|
|
97
100
|
const registration = {
|
|
98
101
|
token,
|
|
99
102
|
provider,
|
|
100
|
-
|
|
103
|
+
providers: options.providers ?? [],
|
|
104
|
+
options: { multi, ...options },
|
|
101
105
|
resolutions: new Map()
|
|
102
106
|
};
|
|
103
107
|
addRegistration(this.#registrations, registration);
|
|
@@ -125,20 +129,22 @@ export class Injector {
|
|
|
125
129
|
* @param token token to get registration for
|
|
126
130
|
*/
|
|
127
131
|
tryGetRegistration(token, options) {
|
|
128
|
-
if (isNull(this.#parent) && !this.#registrations.has(token)
|
|
129
|
-
const globalRegistrations = toArray(Injector.#globalRegistrations.get(token));
|
|
132
|
+
if (isNull(this.#parent) && !this.#registrations.has(token)) {
|
|
133
|
+
const globalRegistrations = toArray(Injector.#globalRegistrations.get(token) ?? []);
|
|
130
134
|
for (const globalRegistration of globalRegistrations) {
|
|
131
135
|
this.register(globalRegistration.token, globalRegistration.provider, globalRegistration.options);
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
if (options?.skipSelf != true) {
|
|
139
|
+
const ownRegistration = this.#registrations.get(token);
|
|
140
|
+
if (isDefined(ownRegistration)) {
|
|
141
|
+
return ownRegistration;
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
|
-
if (options?.onlySelf
|
|
139
|
-
return
|
|
144
|
+
if (options?.onlySelf != true) {
|
|
145
|
+
return this.#parent?.tryGetRegistration(token);
|
|
140
146
|
}
|
|
141
|
-
return
|
|
147
|
+
return undefined;
|
|
142
148
|
}
|
|
143
149
|
/**
|
|
144
150
|
* Get registration
|
|
@@ -212,17 +218,17 @@ export class Injector {
|
|
|
212
218
|
throw new ResolveError('Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.', chain);
|
|
213
219
|
}
|
|
214
220
|
const registration = (options.skipSelf == true) ? undefined : this.tryGetRegistration(token);
|
|
215
|
-
if (
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
if (isDefined(registration)) {
|
|
222
|
+
const singleRegistration = isArray(registration) ? registration[0] : registration;
|
|
223
|
+
return this._resolveRegistration(singleRegistration, argument, options, context, chain);
|
|
224
|
+
}
|
|
225
|
+
if (isNotNull(this.#parent) && (options.onlySelf != true)) {
|
|
226
|
+
return this.#parent._resolve(token, argument, { ...options, skipSelf: false }, context, chain);
|
|
227
|
+
}
|
|
228
|
+
if (options.optional == true) {
|
|
229
|
+
return undefined;
|
|
223
230
|
}
|
|
224
|
-
|
|
225
|
-
return this._resolveRegistration(singleRegistration, argument, options, context, chain);
|
|
231
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
226
232
|
}
|
|
227
233
|
_resolveAll(token, argument, options, context, chain) {
|
|
228
234
|
this.assertNotDisposed();
|
|
@@ -237,29 +243,33 @@ export class Injector {
|
|
|
237
243
|
throw new ResolveError('Token is undefined - this might be because of circular dependencies, use alias or forwardRef in this case.', chain);
|
|
238
244
|
}
|
|
239
245
|
const registration = (options.skipSelf == true) ? undefined : this.tryGetRegistration(token);
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
if (options.optional == true) {
|
|
245
|
-
return [];
|
|
246
|
-
}
|
|
247
|
-
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
246
|
+
if (isDefined(registration)) {
|
|
247
|
+
const registrations = isArray(registration) ? registration : [registration];
|
|
248
|
+
return registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
|
|
248
249
|
}
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
if (isNotNull(this.#parent) && (options.onlySelf != true)) {
|
|
251
|
+
return this.#parent._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain);
|
|
252
|
+
}
|
|
253
|
+
if (options.optional == true) {
|
|
254
|
+
return [];
|
|
255
|
+
}
|
|
256
|
+
throw new ResolveError(`No provider for ${getTokenName(token)} registered.`, chain);
|
|
251
257
|
}
|
|
252
258
|
_resolveRegistration(registration, argument, options, context, chain) {
|
|
253
259
|
checkOverflow(chain, context);
|
|
254
|
-
const
|
|
260
|
+
const { token, providers } = registration;
|
|
261
|
+
const injector = (providers.length > 0) ? this.fork('LocalProvidersInjector') : this;
|
|
262
|
+
for (const nestedProvider of providers) {
|
|
263
|
+
injector.register(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
|
|
264
|
+
}
|
|
265
|
+
const injectionContext = injector.getInjectionContext(context, argument, chain);
|
|
255
266
|
const previousInjectionContext = setCurrentInjectionContext(injectionContext);
|
|
256
267
|
const resolutionTag = Symbol(); // eslint-disable-line symbol-description
|
|
257
268
|
try {
|
|
258
|
-
const { token } = registration;
|
|
259
269
|
const resolutionScoped = registration.options.lifecycle == 'resolution';
|
|
260
270
|
const injectorScoped = registration.options.lifecycle == 'injector';
|
|
261
271
|
const singletonScoped = registration.options.lifecycle == 'singleton';
|
|
262
|
-
const resolveArgument = argument ?? registration.options.defaultArgument ?? (registration.options.defaultArgumentProvider?.(
|
|
272
|
+
const resolveArgument = argument ?? registration.options.defaultArgument ?? (registration.options.defaultArgumentProvider?.(injector.getResolveContext(resolutionTag, context, chain)));
|
|
263
273
|
const argumentIdentity = resolveArgumentIdentity(registration, resolveArgument);
|
|
264
274
|
if (resolutionScoped && context.resolutionScopedResolutions.hasFlat(token, argumentIdentity)) {
|
|
265
275
|
return context.resolutionScopedResolutions.getFlat(token, argumentIdentity).value;
|
|
@@ -270,13 +280,13 @@ export class Injector {
|
|
|
270
280
|
else if (singletonScoped && registration.resolutions.has(argumentIdentity)) {
|
|
271
281
|
return registration.resolutions.get(argumentIdentity);
|
|
272
282
|
}
|
|
273
|
-
const value =
|
|
283
|
+
const value = injector._resolveProvider(resolutionTag, registration, resolveArgument, options, context, injectionContext, chain);
|
|
274
284
|
const resolution = {
|
|
275
285
|
tag: resolutionTag,
|
|
276
286
|
registration,
|
|
277
287
|
value,
|
|
278
288
|
argument: injectionContext.argument,
|
|
279
|
-
afterResolveContext:
|
|
289
|
+
afterResolveContext: injector.getAfterResolveContext(resolutionTag, context),
|
|
280
290
|
chain
|
|
281
291
|
};
|
|
282
292
|
context.resolutions.push(resolution);
|
package/injector/types.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import type { CancellationSignal } from '../cancellation/index.js';
|
|
|
2
2
|
import type { AsyncDisposeHandler } from '../disposable/async-disposer.js';
|
|
3
3
|
import type { Record } from '../types.js';
|
|
4
4
|
import type { ForwardRefTypeHint } from '../utils/object/forward-ref.js';
|
|
5
|
-
import type { Injector } from './injector.js';
|
|
5
|
+
import type { Injector, ProvidersItem } from './injector.js';
|
|
6
6
|
import type { ResolveArgument } from './interfaces.js';
|
|
7
7
|
import type { InjectionToken } from './token.js';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Transient: new resolution for every resolve
|
|
10
10
|
* resolution: one resolution per resolve tree
|
|
11
11
|
* injector: one resolution per injector
|
|
12
12
|
* singleton: one resolution at injector where token is registered
|
|
@@ -34,11 +34,13 @@ export type ResolveOptions<T, A> = {
|
|
|
34
34
|
forwardRefTypeHint?: ForwardRefTypeHint;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Data to store between different stages like resolve and afterResolve
|
|
38
38
|
*/
|
|
39
39
|
export type ResolveContextData<T extends Record> = T;
|
|
40
40
|
export type RegistrationOptions<T, A = unknown, D extends Record = Record> = {
|
|
41
41
|
lifecycle?: Lifecycle;
|
|
42
|
+
/** Local providers for inner resolutions */
|
|
43
|
+
providers?: ProvidersItem[];
|
|
42
44
|
/** Default resolve argument used when neither token nor explicit resolve argument is provided */
|
|
43
45
|
defaultArgument?: ResolveArgument<T, A>;
|
|
44
46
|
/** Default resolve argument used when neither token nor explicit resolve argument is provided */
|
|
@@ -57,6 +59,6 @@ export type RegistrationOptions<T, A = unknown, D extends Record = Record> = {
|
|
|
57
59
|
afterResolve?: (instance: T, argument: ResolveArgument<T, A>, context: AfterResolveContext<D>) => any;
|
|
58
60
|
/** Whether multiple values can be resolved or not (used with {@link Injector.resolveAll}). If false, previous registrations are removed */
|
|
59
61
|
multi?: boolean;
|
|
60
|
-
/**
|
|
62
|
+
/** Custom metadata */
|
|
61
63
|
metadata?: Record;
|
|
62
64
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.90.
|
|
3
|
+
"version": "0.90.62",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -105,11 +105,11 @@
|
|
|
105
105
|
"./utils/string": "./utils/object/index.js"
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"
|
|
108
|
+
"core-js": "3.36",
|
|
109
109
|
"luxon": "^3.4",
|
|
110
110
|
"reflect-metadata": "^0.2",
|
|
111
111
|
"rxjs": "^7.8",
|
|
112
|
-
"type-fest": "4.
|
|
112
|
+
"type-fest": "4.15"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@mxssfd/typedoc-theme": "1.1",
|
|
@@ -130,10 +130,10 @@
|
|
|
130
130
|
"typedoc": "0.25",
|
|
131
131
|
"typedoc-plugin-missing-exports": "2.2",
|
|
132
132
|
"typescript": "5.4",
|
|
133
|
-
"typescript-eslint": "7.
|
|
133
|
+
"typescript-eslint": "7.5"
|
|
134
134
|
},
|
|
135
135
|
"peerDependencies": {
|
|
136
|
-
"@elastic/elasticsearch": "^8.
|
|
136
|
+
"@elastic/elasticsearch": "^8.13",
|
|
137
137
|
"@koa/router": "^12.0",
|
|
138
138
|
"@tstdl/angular": "^0.90",
|
|
139
139
|
"@zxcvbn-ts/core": "^3.0",
|
|
@@ -148,9 +148,9 @@
|
|
|
148
148
|
"mongodb": "^6.5",
|
|
149
149
|
"nodemailer": "^6.9",
|
|
150
150
|
"playwright": "^1.42",
|
|
151
|
-
"preact": "^10.
|
|
151
|
+
"preact": "^10.20",
|
|
152
152
|
"preact-render-to-string": "^6.4",
|
|
153
|
-
"undici": "^6.
|
|
153
|
+
"undici": "^6.11",
|
|
154
154
|
"urlpattern-polyfill": "^10.0"
|
|
155
155
|
},
|
|
156
156
|
"peerDependenciesMeta": {
|
package/polyfills.d.ts
CHANGED
|
@@ -1,159 +1,2 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
interface SymbolConstructor {
|
|
4
|
-
/**
|
|
5
|
-
* A method that is used to release resources held by an object. Called by the semantics of the `using` statement.
|
|
6
|
-
*/
|
|
7
|
-
readonly dispose: unique symbol;
|
|
8
|
-
/**
|
|
9
|
-
* A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.
|
|
10
|
-
*/
|
|
11
|
-
readonly asyncDispose: unique symbol;
|
|
12
|
-
}
|
|
13
|
-
interface Disposable {
|
|
14
|
-
[Symbol.dispose](): void;
|
|
15
|
-
}
|
|
16
|
-
interface AsyncDisposable {
|
|
17
|
-
[Symbol.asyncDispose](): PromiseLike<void>;
|
|
18
|
-
}
|
|
19
|
-
interface SuppressedError extends Error {
|
|
20
|
-
error: any;
|
|
21
|
-
suppressed: any;
|
|
22
|
-
}
|
|
23
|
-
interface SuppressedErrorConstructor extends ErrorConstructor {
|
|
24
|
-
new (error: any, suppressed: any, message?: string): SuppressedError;
|
|
25
|
-
(error: any, suppressed: any, message?: string): SuppressedError;
|
|
26
|
-
readonly prototype: SuppressedError;
|
|
27
|
-
}
|
|
28
|
-
var SuppressedError: SuppressedErrorConstructor;
|
|
29
|
-
interface DisposableStack {
|
|
30
|
-
/**
|
|
31
|
-
* Returns a value indicating whether this stack has been disposed.
|
|
32
|
-
*/
|
|
33
|
-
readonly disposed: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Disposes each resource in the stack in the reverse order that they were added.
|
|
36
|
-
*/
|
|
37
|
-
dispose(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Adds a disposable resource to the stack, returning the resource.
|
|
40
|
-
* @param value The resource to add. `null` and `undefined` will not be added, but will be returned.
|
|
41
|
-
* @returns The provided {@link value}.
|
|
42
|
-
*/
|
|
43
|
-
use<T extends Disposable | null | undefined>(value: T): T;
|
|
44
|
-
/**
|
|
45
|
-
* Adds a value and associated disposal callback as a resource to the stack.
|
|
46
|
-
* @param value The value to add.
|
|
47
|
-
* @param onDispose The callback to use in place of a `[Symbol.dispose]()` method. Will be invoked with `value`
|
|
48
|
-
* as the first parameter.
|
|
49
|
-
* @returns The provided {@link value}.
|
|
50
|
-
*/
|
|
51
|
-
adopt<T>(value: T, onDispose: (value: T) => void): T;
|
|
52
|
-
/**
|
|
53
|
-
* Adds a callback to be invoked when the stack is disposed.
|
|
54
|
-
*/
|
|
55
|
-
defer(onDispose: () => void): void;
|
|
56
|
-
/**
|
|
57
|
-
* Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* class C {
|
|
61
|
-
* #res1: Disposable;
|
|
62
|
-
* #res2: Disposable;
|
|
63
|
-
* #disposables: DisposableStack;
|
|
64
|
-
* constructor() {
|
|
65
|
-
* // stack will be disposed when exiting constructor for any reason
|
|
66
|
-
* using stack = new DisposableStack();
|
|
67
|
-
*
|
|
68
|
-
* // get first resource
|
|
69
|
-
* this.#res1 = stack.use(getResource1());
|
|
70
|
-
*
|
|
71
|
-
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
|
|
72
|
-
* this.#res2 = stack.use(getResource2());
|
|
73
|
-
*
|
|
74
|
-
* // all operations succeeded, move resources out of `stack` so that they aren't disposed
|
|
75
|
-
* // when constructor exits
|
|
76
|
-
* this.#disposables = stack.move();
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* [Symbol.dispose]() {
|
|
80
|
-
* this.#disposables.dispose();
|
|
81
|
-
* }
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
move(): DisposableStack;
|
|
86
|
-
[Symbol.dispose](): void;
|
|
87
|
-
readonly [Symbol.toStringTag]: string;
|
|
88
|
-
}
|
|
89
|
-
interface DisposableStackConstructor {
|
|
90
|
-
new (): DisposableStack;
|
|
91
|
-
readonly prototype: DisposableStack;
|
|
92
|
-
}
|
|
93
|
-
var DisposableStack: DisposableStackConstructor;
|
|
94
|
-
interface AsyncDisposableStack {
|
|
95
|
-
/**
|
|
96
|
-
* Returns a value indicating whether this stack has been disposed.
|
|
97
|
-
*/
|
|
98
|
-
readonly disposed: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Disposes each resource in the stack in the reverse order that they were added.
|
|
101
|
-
*/
|
|
102
|
-
disposeAsync(): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Adds a disposable resource to the stack, returning the resource.
|
|
105
|
-
* @param value The resource to add. `null` and `undefined` will not be added, but will be returned.
|
|
106
|
-
* @returns The provided {@link value}.
|
|
107
|
-
*/
|
|
108
|
-
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
|
|
109
|
-
/**
|
|
110
|
-
* Adds a value and associated disposal callback as a resource to the stack.
|
|
111
|
-
* @param value The value to add.
|
|
112
|
-
* @param onDisposeAsync The callback to use in place of a `[Symbol.asyncDispose]()` method. Will be invoked with `value`
|
|
113
|
-
* as the first parameter.
|
|
114
|
-
* @returns The provided {@link value}.
|
|
115
|
-
*/
|
|
116
|
-
adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T;
|
|
117
|
-
/**
|
|
118
|
-
* Adds a callback to be invoked when the stack is disposed.
|
|
119
|
-
*/
|
|
120
|
-
defer(onDisposeAsync: () => PromiseLike<void> | void): void;
|
|
121
|
-
/**
|
|
122
|
-
* Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* class C {
|
|
126
|
-
* #res1: Disposable;
|
|
127
|
-
* #res2: Disposable;
|
|
128
|
-
* #disposables: DisposableStack;
|
|
129
|
-
* constructor() {
|
|
130
|
-
* // stack will be disposed when exiting constructor for any reason
|
|
131
|
-
* using stack = new DisposableStack();
|
|
132
|
-
*
|
|
133
|
-
* // get first resource
|
|
134
|
-
* this.#res1 = stack.use(getResource1());
|
|
135
|
-
*
|
|
136
|
-
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
|
|
137
|
-
* this.#res2 = stack.use(getResource2());
|
|
138
|
-
*
|
|
139
|
-
* // all operations succeeded, move resources out of `stack` so that they aren't disposed
|
|
140
|
-
* // when constructor exits
|
|
141
|
-
* this.#disposables = stack.move();
|
|
142
|
-
* }
|
|
143
|
-
*
|
|
144
|
-
* [Symbol.dispose]() {
|
|
145
|
-
* this.#disposables.dispose();
|
|
146
|
-
* }
|
|
147
|
-
* }
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
move(): AsyncDisposableStack;
|
|
151
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
152
|
-
readonly [Symbol.toStringTag]: string;
|
|
153
|
-
}
|
|
154
|
-
interface AsyncDisposableStackConstructor {
|
|
155
|
-
new (): AsyncDisposableStack;
|
|
156
|
-
readonly prototype: AsyncDisposableStack;
|
|
157
|
-
}
|
|
158
|
-
var AsyncDisposableStack: AsyncDisposableStackConstructor;
|
|
159
|
-
}
|
|
1
|
+
import 'core-js/actual/async-disposable-stack/index.js';
|
|
2
|
+
import 'core-js/actual/disposable-stack/index.js';
|
package/polyfills.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import 'core-js/actual/async-disposable-stack/index.js';
|
|
2
|
+
import 'core-js/actual/disposable-stack/index.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata/lite';
|
|
2
2
|
import type { ConstructorParameterDecorator } from '../types.js';
|
|
3
3
|
import type { Decorator, DecoratorHandler } from './types.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type CreateDecoratorOptions, type SpecificCreateDecoratorOptions } from './utils.js';
|
|
5
5
|
export declare function Decorate({ handler, ...options }?: CreateDecoratorOptions & {
|
|
6
6
|
handler?: DecoratorHandler;
|
|
7
7
|
}): Decorator;
|
package/signals/defer.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Signal } from './api.js';
|
|
2
2
|
export declare function defer<T>(signalFactory: () => Signal<T>): Signal<T>;
|
|
@@ -21,19 +21,14 @@ export declare abstract class EffectScheduler {
|
|
|
21
21
|
* It is an error to attempt to execute any effects synchronously during a scheduling operation.
|
|
22
22
|
*/
|
|
23
23
|
abstract scheduleEffect(e: SchedulableEffect): void;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Interface to an `EffectScheduler` capable of running scheduled effects synchronously.
|
|
27
|
-
*/
|
|
28
|
-
export interface FlushableEffectRunner {
|
|
29
24
|
/**
|
|
30
25
|
* Run any scheduled effects.
|
|
31
26
|
*/
|
|
32
|
-
flush(): void;
|
|
27
|
+
abstract flush(): void;
|
|
33
28
|
}
|
|
34
|
-
export declare class TstdlEffectScheduler implements EffectScheduler
|
|
29
|
+
export declare class TstdlEffectScheduler implements EffectScheduler {
|
|
35
30
|
private readonly queue;
|
|
36
|
-
private
|
|
31
|
+
private hasPendingFlush;
|
|
37
32
|
scheduleEffect(effect: SchedulableEffect): void;
|
|
38
33
|
flush(): void;
|
|
39
34
|
}
|
|
@@ -15,13 +15,16 @@ export class EffectScheduler {
|
|
|
15
15
|
}
|
|
16
16
|
export class TstdlEffectScheduler {
|
|
17
17
|
queue = new Set();
|
|
18
|
-
|
|
18
|
+
hasPendingFlush = false;
|
|
19
19
|
scheduleEffect(effect) {
|
|
20
|
+
if (this.queue.has(effect)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
20
23
|
this.queue.add(effect);
|
|
21
|
-
if (!this.
|
|
22
|
-
this.
|
|
24
|
+
if (!this.hasPendingFlush) {
|
|
25
|
+
this.hasPendingFlush = true;
|
|
23
26
|
queueMicrotask(() => {
|
|
24
|
-
this.
|
|
27
|
+
this.hasPendingFlush = false;
|
|
25
28
|
this.flush();
|
|
26
29
|
});
|
|
27
30
|
}
|
|
@@ -44,7 +44,7 @@ export interface WritableSignal<T> extends Signal<T> {
|
|
|
44
44
|
update(updateFn: (value: T) => T): void;
|
|
45
45
|
/**
|
|
46
46
|
* Returns a readonly version of this signal. Readonly signals can be accessed to read their value
|
|
47
|
-
* but can't be changed using set
|
|
47
|
+
* but can't be changed using set or update methods. The readonly signals do _not_ have
|
|
48
48
|
* any built-in mechanism that would prevent deep-mutation of their value.
|
|
49
49
|
*/
|
|
50
50
|
asReadonly(): Signal<T>;
|