@mailwoman/core 7.2.1 → 7.4.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/api/APIClient.ts +2 -2
- package/out/api/APIClient.d.ts.map +1 -1
- package/out/api/APIClient.js +2 -2
- package/out/api/APIClient.js.map +1 -1
- package/out/pipeline/types.d.ts +13 -0
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js.map +1 -1
- package/out/scripting/utils/index.d.ts.map +1 -1
- package/out/scripting/utils/index.js +3 -5
- package/out/scripting/utils/index.js.map +1 -1
- package/package.json +3 -11
- package/pipeline/types.ts +9 -0
- package/scripting/utils/index.ts +4 -7
- package/lifecycle/ServiceSymbol.ts +0 -95
- package/lifecycle/index.ts +0 -11
- package/lifecycle/lru-cache.ts +0 -44
- package/lifecycle/services.ts +0 -322
- package/out/lifecycle/ServiceSymbol.d.ts +0 -57
- package/out/lifecycle/ServiceSymbol.d.ts.map +0 -1
- package/out/lifecycle/ServiceSymbol.js +0 -60
- package/out/lifecycle/ServiceSymbol.js.map +0 -1
- package/out/lifecycle/index.d.ts +0 -11
- package/out/lifecycle/index.d.ts.map +0 -1
- package/out/lifecycle/index.js +0 -11
- package/out/lifecycle/index.js.map +0 -1
- package/out/lifecycle/lru-cache.d.ts +0 -22
- package/out/lifecycle/lru-cache.d.ts.map +0 -1
- package/out/lifecycle/lru-cache.js +0 -31
- package/out/lifecycle/lru-cache.js.map +0 -1
- package/out/lifecycle/services.d.ts +0 -144
- package/out/lifecycle/services.d.ts.map +0 -1
- package/out/lifecycle/services.js +0 -191
- package/out/lifecycle/services.js.map +0 -1
package/lifecycle/services.ts
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Utilities for creating branded nominal types.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ResourceError } from "../errors/schema.ts"
|
|
10
|
-
import { ConsoleLogger } from "../logging/index.ts"
|
|
11
|
-
import { ServiceSymbol } from "./ServiceSymbol.ts"
|
|
12
|
-
|
|
13
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
-
|
|
15
|
-
//#region Asynchronous
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Type definition for a class which implements the AsyncDisposable interface.
|
|
19
|
-
*
|
|
20
|
-
* @category Utilities
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export type ServiceConstructor<T> = new (...args: any[]) => T & AsyncDisposable
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Type-predicate to determine if a given input is a ServiceConstructor, i.e. a function which is a constructor for a
|
|
27
|
-
* class which implements the AsyncDisposable interface.
|
|
28
|
-
*/
|
|
29
|
-
export function isServiceConstructor<T>(input: unknown): input is ServiceConstructor<T> {
|
|
30
|
-
if (typeof input !== "function") return false
|
|
31
|
-
|
|
32
|
-
if (!input.prototype || typeof input.prototype !== "object") return false
|
|
33
|
-
|
|
34
|
-
return Object.hasOwn(input.prototype, Symbol.asyncDispose) || Object.hasOwn(input.prototype, ServiceSymbol.asyncInit)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
|
|
39
|
-
//#region Service Registry
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Stateful context for a service registry.
|
|
43
|
-
*
|
|
44
|
-
* This is used to provide a context for services during resolution.
|
|
45
|
-
*/
|
|
46
|
-
export interface ServiceRegistryContext {
|
|
47
|
-
abortController: AbortController
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Type definition for a function which returns an instance which implements the AsyncDisposable interface.
|
|
52
|
-
*
|
|
53
|
-
* @category Utilities
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
export type ServiceCallback<T extends AsyncDisposable> = {
|
|
57
|
-
(context: ServiceRegistryContext): Promise<T> | T
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type ServiceResolver<T extends AsyncDisposable = AsyncDisposable> =
|
|
61
|
-
| T
|
|
62
|
-
| ServiceCallback<T>
|
|
63
|
-
| ServiceConstructor<T>
|
|
64
|
-
|
|
65
|
-
const kInstance = Symbol.for("ServiceInstance")
|
|
66
|
-
const kResolver = Symbol.for("ServiceResolver")
|
|
67
|
-
const kRegistryMap = Symbol.for("ServiceRepositoryMap")
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Given a service which may not yet be resolved, intercept any method calls and resolve the service before invoking the
|
|
71
|
-
* method.
|
|
72
|
-
*
|
|
73
|
-
* @category Services
|
|
74
|
-
*/
|
|
75
|
-
export type ServiceMethodResolver<T> = {
|
|
76
|
-
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : T[K]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Promise-like wrapper for asynchronous services.
|
|
81
|
-
*
|
|
82
|
-
* @see {@linkcode ServiceRepository} for usage.
|
|
83
|
-
*/
|
|
84
|
-
export class Service<T extends AsyncDisposable = AsyncDisposable> implements PromiseLike<T>, AsyncDisposable {
|
|
85
|
-
/**
|
|
86
|
-
* Instance of the service.
|
|
87
|
-
*
|
|
88
|
-
* @internal
|
|
89
|
-
*/
|
|
90
|
-
public [kInstance]: T | null = null
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Resolver for the service.
|
|
94
|
-
*
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
public [kResolver]?: ServiceResolver<T>
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Context for the parent service registry.
|
|
101
|
-
*/
|
|
102
|
-
public readonly context: ServiceRegistryContext
|
|
103
|
-
|
|
104
|
-
protected constructor(resolver: ServiceResolver<T>) {
|
|
105
|
-
this[kResolver] = resolver
|
|
106
|
-
|
|
107
|
-
this.context = {
|
|
108
|
-
abortController: ServiceRepository.abortController,
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Given an instance of a service, attach it to the resolver.
|
|
114
|
-
*
|
|
115
|
-
* This can be used to attach a service that was created outside of the resolver, such as when a resolver is defined
|
|
116
|
-
* from a TypeScript interface.
|
|
117
|
-
*
|
|
118
|
-
* @internal
|
|
119
|
-
*/
|
|
120
|
-
public attach(service: T): void {
|
|
121
|
-
this[kInstance] = service
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Resolve the service instance.
|
|
126
|
-
*
|
|
127
|
-
* This method is called implicitly when the service is awaited.
|
|
128
|
-
*/
|
|
129
|
-
protected async resolve(): Promise<T> {
|
|
130
|
-
if (this[kInstance]) return this[kInstance]
|
|
131
|
-
|
|
132
|
-
if (!this[kResolver])
|
|
133
|
-
throw ResourceError.from(
|
|
134
|
-
500,
|
|
135
|
-
"Cannot resolve service without a resolver. Did you mean to call `attach` before calling `resolve`?"
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
if (typeof this[kResolver] === "function") {
|
|
139
|
-
if (isServiceConstructor(this[kResolver])) {
|
|
140
|
-
this[kInstance] = new this[kResolver]()
|
|
141
|
-
|
|
142
|
-
return this[kInstance]
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const nextInstance = await this[kResolver](this.context)
|
|
146
|
-
|
|
147
|
-
if (ServiceSymbol.isAsyncInitializable(nextInstance)) {
|
|
148
|
-
await nextInstance[ServiceSymbol.asyncInit]()
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
this[kInstance] = nextInstance
|
|
152
|
-
|
|
153
|
-
return this[kInstance]
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (typeof this[kResolver] === "object") {
|
|
157
|
-
const nextInstance = this[kResolver]
|
|
158
|
-
|
|
159
|
-
if (ServiceSymbol.isAsyncInitializable(nextInstance)) {
|
|
160
|
-
await nextInstance[ServiceSymbol.asyncInit]()
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
this[kInstance] = nextInstance
|
|
164
|
-
|
|
165
|
-
return this[kInstance]
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
throw ResourceError.from(500, `Invalid resolver type. ${this[kResolver]}`)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Resolve the service instance. Called implicitly when the service is awaited.
|
|
173
|
-
*/
|
|
174
|
-
// oxlint-disable-next-line unicorn/no-thenable -- intentional: a Service is awaitable by design (the await resolves the instance)
|
|
175
|
-
public then<TResult1 = T, TResult2 = never>(
|
|
176
|
-
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,
|
|
177
|
-
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined
|
|
178
|
-
): Promise<TResult1 | TResult2> {
|
|
179
|
-
return this.resolve()
|
|
180
|
-
.then((instance) => {
|
|
181
|
-
if (!this[kResolver]) {
|
|
182
|
-
throw ResourceError.from(500, "Service resolver was disposed before service was resolved.")
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
ServiceRepository[kRegistryMap].set(this[kResolver], this)
|
|
186
|
-
|
|
187
|
-
return instance
|
|
188
|
-
})
|
|
189
|
-
.then(onfulfilled, onrejected)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
public async [Symbol.asyncDispose](): Promise<void> {
|
|
193
|
-
if (!this[kInstance]) {
|
|
194
|
-
ConsoleLogger.warn("Attempted to dispose a service resolver without a service!")
|
|
195
|
-
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (typeof this[kInstance][Symbol.asyncDispose] !== "function") {
|
|
200
|
-
ConsoleLogger.warn("Attempted to dispose a service resolver without a disposable service!")
|
|
201
|
-
|
|
202
|
-
return
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
await this[kInstance][Symbol.asyncDispose]()
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Service repository for managing asynchronous services.
|
|
211
|
-
*
|
|
212
|
-
* @singleton
|
|
213
|
-
*/
|
|
214
|
-
export class ServiceRepository extends Service<AsyncDisposable> {
|
|
215
|
-
static readonly [kRegistryMap] = new Map<ServiceResolver<any>, Service<any>>()
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Abort controller for the service repository.
|
|
219
|
-
*/
|
|
220
|
-
static readonly abortController = new AbortController()
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Inspect the current state of the service registry.
|
|
224
|
-
*/
|
|
225
|
-
static inspect(): Service<any>[] {
|
|
226
|
-
const services = [...this[kRegistryMap].values()].reverse()
|
|
227
|
-
|
|
228
|
-
return services
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Dispose of all services in the registry.
|
|
233
|
-
*/
|
|
234
|
-
static async [Symbol.asyncDispose](): Promise<void> {
|
|
235
|
-
const services = ServiceRepository.inspect()
|
|
236
|
-
|
|
237
|
-
ConsoleLogger.debug(`🚮 Disposing ${services.length} services...`)
|
|
238
|
-
|
|
239
|
-
for (const service of services) {
|
|
240
|
-
const label = String(service[kInstance])
|
|
241
|
-
ConsoleLogger.debug(`[${label}] Disposing...`)
|
|
242
|
-
|
|
243
|
-
const marked = ServiceSymbol.markAsDisposed(service[kInstance])
|
|
244
|
-
|
|
245
|
-
if (!marked) continue
|
|
246
|
-
|
|
247
|
-
await service[Symbol.asyncDispose]()
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
this[kRegistryMap].clear()
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Dispose of all services in the registry.
|
|
255
|
-
*/
|
|
256
|
-
static dispose(): Promise<void> {
|
|
257
|
-
return this[Symbol.asyncDispose]()
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Register a pre-initialized service with the service repository.
|
|
262
|
-
*
|
|
263
|
-
* @param service - An instance of a service.
|
|
264
|
-
*/
|
|
265
|
-
static register<T extends AsyncDisposable>(service: T): Service<T> & ServiceMethodResolver<T>
|
|
266
|
-
/**
|
|
267
|
-
* Register a service resolver with the service repository.
|
|
268
|
-
*
|
|
269
|
-
* @param serviceCallback - A callback which returns a service instance.
|
|
270
|
-
*/
|
|
271
|
-
static register<T extends AsyncDisposable>(serviceCallback: ServiceCallback<T>): Service<T> & ServiceMethodResolver<T>
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Register a service constructor with the service repository.
|
|
275
|
-
*
|
|
276
|
-
* @param ServiceConstructor - A constructor which returns a service instance.
|
|
277
|
-
*/
|
|
278
|
-
static register<T extends AsyncDisposable>(
|
|
279
|
-
ServiceConstructor: ServiceConstructor<T>
|
|
280
|
-
): Service<T> & ServiceMethodResolver<T>
|
|
281
|
-
/**
|
|
282
|
-
* Register a service with the service repository.
|
|
283
|
-
*
|
|
284
|
-
* @param resolver - A service resolver, instance, or constructor.
|
|
285
|
-
*/
|
|
286
|
-
static register<T extends AsyncDisposable>(resolver: ServiceResolver<T>): Service<T> & ServiceMethodResolver<T>
|
|
287
|
-
static register<T extends AsyncDisposable>(resolver: ServiceResolver<T>): Service<T> & ServiceMethodResolver<T> {
|
|
288
|
-
const service = new Service<T>(resolver)
|
|
289
|
-
|
|
290
|
-
const serviceMethodResolver = new Proxy(service as Service<T> & T, {
|
|
291
|
-
get(target, prop) {
|
|
292
|
-
if (prop in target) {
|
|
293
|
-
return (target as any)[prop]
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return async (...args: any[]) => {
|
|
297
|
-
const instance = (await target) as T
|
|
298
|
-
|
|
299
|
-
if (typeof (instance as any)[prop] === "function") {
|
|
300
|
-
return (instance as any)[prop](...args)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return (instance as any)[prop]
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
|
|
307
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
308
|
-
return "ServiceMethodResolver"
|
|
309
|
-
},
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
return serviceMethodResolver as Service<T> & ServiceMethodResolver<T>
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
constructor() {
|
|
316
|
-
if (new.target === ServiceRepository) {
|
|
317
|
-
throw new TypeError("Cannot instantiate static class `ServiceRepository`.")
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
super(null as never)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Supplemental interface for objects which can be further initialized asynchronously.
|
|
8
|
-
*/
|
|
9
|
-
export interface AsyncInitializable extends AsyncDisposable {
|
|
10
|
-
/**
|
|
11
|
-
* A method which can be called to asynchronously construct the object.
|
|
12
|
-
*/
|
|
13
|
-
[ServiceSymbol.asyncInit](...args: any[]): Promise<this>;
|
|
14
|
-
/**
|
|
15
|
-
* Alias for the `AsyncInitSymbol` method.
|
|
16
|
-
*/
|
|
17
|
-
ready?(...args: any[]): Promise<this>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Type definition for a class which implements the AsyncInitializable interface.
|
|
21
|
-
*/
|
|
22
|
-
export type AsyncInitializableConstructor<T> = T extends new (...args: any[]) => AsyncInitializable ? new (...args: ConstructorParameters<T>) => T : never;
|
|
23
|
-
/**
|
|
24
|
-
* Symbol extensions associated with a service lifecycle.
|
|
25
|
-
*
|
|
26
|
-
* @singleton
|
|
27
|
-
* @static
|
|
28
|
-
*/
|
|
29
|
-
export declare class ServiceSymbol {
|
|
30
|
-
private constructor();
|
|
31
|
-
/**
|
|
32
|
-
* Global symbol for the AsyncConstructable interface.
|
|
33
|
-
*/
|
|
34
|
-
static readonly asyncInit: unique symbol;
|
|
35
|
-
/**
|
|
36
|
-
* Global symbol to mark an object as disposed.
|
|
37
|
-
*/
|
|
38
|
-
static readonly asyncDisposed: unique symbol;
|
|
39
|
-
/**
|
|
40
|
-
* Mark an object as disposed.
|
|
41
|
-
*/
|
|
42
|
-
static markAsDisposed(disposable: AsyncDisposable): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Type-predicate to determine if an object has been disposed.
|
|
45
|
-
*/
|
|
46
|
-
static isDisposed(disposable: AsyncDisposable): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Type-predicate to determine if a given input is an object which implements the `AsyncInitializable` interface.
|
|
49
|
-
*/
|
|
50
|
-
static isAsyncInitializable(input: AsyncDisposable): input is AsyncInitializable;
|
|
51
|
-
/**
|
|
52
|
-
* Type-predicate to determine if a given input is an object which implements the `AsyncDisposable` interface.
|
|
53
|
-
*/
|
|
54
|
-
static isAsyncDisposable<T>(input: T): input is T & AsyncDisposable;
|
|
55
|
-
static toString(): string;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=ServiceSymbol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceSymbol.d.ts","sourceRoot":"","sources":["../../lifecycle/ServiceSymbol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IAC1D;;OAEG;IACH,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAExD;;OAEG;IACH,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,6BAA6B,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,kBAAkB,GAChG,KAAK,GAAG,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,GAC5C,KAAK,CAAA;AAER;;;;;GAKG;AACH,qBAAa,aAAa;IACzB,OAAO;IAIP;;OAEG;IACH,gBAAuB,SAAS,EAAE,OAAO,MAAM,CAA0B;IAEzE;;OAEG;IACH,gBAAuB,aAAa,EAAE,OAAO,MAAM,CAA8B;IAEjF;;OAEG;WACW,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO;IAYlE;;OAEG;WACW,UAAU,CAAC,UAAU,EAAE,eAAe,GAAG,OAAO;IAI9D;;OAEG;WACW,oBAAoB,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,IAAI,kBAAkB;IAIvF;;OAEG;WACW,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,eAAe;WAM5D,QAAQ;CAGtB"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { ConsoleLogger } from "../logging/index.js";
|
|
7
|
-
/**
|
|
8
|
-
* Symbol extensions associated with a service lifecycle.
|
|
9
|
-
*
|
|
10
|
-
* @singleton
|
|
11
|
-
* @static
|
|
12
|
-
*/
|
|
13
|
-
export class ServiceSymbol {
|
|
14
|
-
constructor() {
|
|
15
|
-
throw new TypeError("Cannot instantiate static class `ServiceSymbol`.");
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Global symbol for the AsyncConstructable interface.
|
|
19
|
-
*/
|
|
20
|
-
static asyncInit = Symbol.for("asyncInit");
|
|
21
|
-
/**
|
|
22
|
-
* Global symbol to mark an object as disposed.
|
|
23
|
-
*/
|
|
24
|
-
static asyncDisposed = Symbol.for("asyncDisposed");
|
|
25
|
-
/**
|
|
26
|
-
* Mark an object as disposed.
|
|
27
|
-
*/
|
|
28
|
-
static markAsDisposed(disposable) {
|
|
29
|
-
if (ServiceSymbol.asyncDisposed in disposable) {
|
|
30
|
-
ConsoleLogger.warn(`[${disposable}] Already disposed!`);
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
Object.assign(disposable, { AsyncDisposedSymbol: true });
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Type-predicate to determine if an object has been disposed.
|
|
38
|
-
*/
|
|
39
|
-
static isDisposed(disposable) {
|
|
40
|
-
return ServiceSymbol.asyncDisposed in disposable;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Type-predicate to determine if a given input is an object which implements the `AsyncInitializable` interface.
|
|
44
|
-
*/
|
|
45
|
-
static isAsyncInitializable(input) {
|
|
46
|
-
return ServiceSymbol.asyncInit in input && typeof input[ServiceSymbol.asyncInit] === "function";
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Type-predicate to determine if a given input is an object which implements the `AsyncDisposable` interface.
|
|
50
|
-
*/
|
|
51
|
-
static isAsyncDisposable(input) {
|
|
52
|
-
if (!input || typeof input !== "object")
|
|
53
|
-
return false;
|
|
54
|
-
return Object.hasOwn(input, Symbol.asyncDispose);
|
|
55
|
-
}
|
|
56
|
-
static toString() {
|
|
57
|
-
return "ServiceSymbol";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=ServiceSymbol.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceSymbol.js","sourceRoot":"","sources":["../../lifecycle/ServiceSymbol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AA0BnD;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACzB;QACC,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAA;IACxE,CAAC;IAED;;OAEG;IACI,MAAM,CAAU,SAAS,GAAkB,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IAEzE;;OAEG;IACI,MAAM,CAAU,aAAa,GAAkB,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IAEjF;;OAEG;IACI,MAAM,CAAC,cAAc,CAAC,UAA2B;QACvD,IAAI,aAAa,CAAC,aAAa,IAAI,UAAU,EAAE,CAAC;YAC/C,aAAa,CAAC,IAAI,CAAC,IAAI,UAAU,qBAAqB,CAAC,CAAA;YAEvD,OAAO,KAAK,CAAA;QACb,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAA;QAExD,OAAO,IAAI,CAAA;IACZ,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,UAAU,CAAC,UAA2B;QACnD,OAAO,aAAa,CAAC,aAAa,IAAI,UAAU,CAAA;IACjD,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,oBAAoB,CAAC,KAAsB;QACxD,OAAO,aAAa,CAAC,SAAS,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,UAAU,CAAA;IAChG,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,iBAAiB,CAAI,KAAQ;QAC1C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAA;QAErD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAA;IACjD,CAAC;IAEM,MAAM,CAAC,QAAQ;QACrB,OAAO,eAAe,CAAA;IACvB,CAAC"}
|
package/out/lifecycle/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Lifecycle utilities.
|
|
7
|
-
*/
|
|
8
|
-
export * from "./lru-cache.ts";
|
|
9
|
-
export * from "./services.ts";
|
|
10
|
-
export * from "./ServiceSymbol.ts";
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lifecycle/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA"}
|
package/out/lifecycle/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Lifecycle utilities.
|
|
7
|
-
*/
|
|
8
|
-
export * from "./lru-cache.js";
|
|
9
|
-
export * from "./services.js";
|
|
10
|
-
export * from "./ServiceSymbol.js";
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lifecycle/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* LRU cache utilities.
|
|
7
|
-
*/
|
|
8
|
-
import { LRUCache } from "lru-cache";
|
|
9
|
-
export interface AsyncDisposableLRUCacheOptions {
|
|
10
|
-
max: number;
|
|
11
|
-
displayName?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* An LRU cache that automatically disposes of its values when they are evicted.
|
|
15
|
-
*/
|
|
16
|
-
export declare class AsyncDisposableLRUCache<K extends object, V extends AsyncDisposable> extends LRUCache<K, V> implements AsyncDisposable {
|
|
17
|
-
readonly displayName: string;
|
|
18
|
-
constructor({ max, displayName }: AsyncDisposableLRUCacheOptions);
|
|
19
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
20
|
-
toString(): string;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=lru-cache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.d.ts","sourceRoot":"","sources":["../../lifecycle/lru-cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,WAAW,8BAA8B;IAC9C,GAAG,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,qBAAa,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,eAAe,CAC/E,SAAQ,QAAQ,CAAC,CAAC,EAAE,CAAC,CACrB,YAAW,eAAe;IAE1B,SAAgB,WAAW,EAAE,MAAM,CAAA;gBAEvB,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,8BAA8B;IASnD,CAAC,MAAM,CAAC,YAAY,CAAC;IAOlB,QAAQ;CAGxB"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* LRU cache utilities.
|
|
7
|
-
*/
|
|
8
|
-
import { LRUCache } from "lru-cache";
|
|
9
|
-
/**
|
|
10
|
-
* An LRU cache that automatically disposes of its values when they are evicted.
|
|
11
|
-
*/
|
|
12
|
-
export class AsyncDisposableLRUCache extends LRUCache {
|
|
13
|
-
displayName;
|
|
14
|
-
constructor({ max, displayName }) {
|
|
15
|
-
super({
|
|
16
|
-
max,
|
|
17
|
-
dispose: (value) => value[Symbol.asyncDispose](),
|
|
18
|
-
});
|
|
19
|
-
this.displayName = displayName ?? "cache";
|
|
20
|
-
}
|
|
21
|
-
async [Symbol.asyncDispose]() {
|
|
22
|
-
for (const [key, value] of this.entries()) {
|
|
23
|
-
await value[Symbol.asyncDispose]();
|
|
24
|
-
this.delete(key);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
toString() {
|
|
28
|
-
return `Async LRU ${this.displayName}`;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=lru-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../lifecycle/lru-cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAOpC;;GAEG;AACH,MAAM,OAAO,uBACZ,SAAQ,QAAc;IAGN,WAAW,CAAQ;IAEnC,YAAY,EAAE,GAAG,EAAE,WAAW,EAAkC;QAC/D,KAAK,CAAC;YACL,GAAG;YACH,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;SAChD,CAAC,CAAA;QAEF,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,OAAO,CAAA;IAC1C,CAAC;IAEM,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACjC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAC3C,MAAM,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAA;YAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACjB,CAAC;IACF,CAAC;IAEe,QAAQ;QACvB,OAAO,aAAa,IAAI,CAAC,WAAW,EAAE,CAAA;IACvC,CAAC;CACD"}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*
|
|
6
|
-
* Utilities for creating branded nominal types.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Type definition for a class which implements the AsyncDisposable interface.
|
|
10
|
-
*
|
|
11
|
-
* @category Utilities
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export type ServiceConstructor<T> = new (...args: any[]) => T & AsyncDisposable;
|
|
15
|
-
/**
|
|
16
|
-
* Type-predicate to determine if a given input is a ServiceConstructor, i.e. a function which is a constructor for a
|
|
17
|
-
* class which implements the AsyncDisposable interface.
|
|
18
|
-
*/
|
|
19
|
-
export declare function isServiceConstructor<T>(input: unknown): input is ServiceConstructor<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Stateful context for a service registry.
|
|
22
|
-
*
|
|
23
|
-
* This is used to provide a context for services during resolution.
|
|
24
|
-
*/
|
|
25
|
-
export interface ServiceRegistryContext {
|
|
26
|
-
abortController: AbortController;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Type definition for a function which returns an instance which implements the AsyncDisposable interface.
|
|
30
|
-
*
|
|
31
|
-
* @category Utilities
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
|
-
export type ServiceCallback<T extends AsyncDisposable> = {
|
|
35
|
-
(context: ServiceRegistryContext): Promise<T> | T;
|
|
36
|
-
};
|
|
37
|
-
export type ServiceResolver<T extends AsyncDisposable = AsyncDisposable> = T | ServiceCallback<T> | ServiceConstructor<T>;
|
|
38
|
-
declare const kInstance: unique symbol;
|
|
39
|
-
declare const kResolver: unique symbol;
|
|
40
|
-
declare const kRegistryMap: unique symbol;
|
|
41
|
-
/**
|
|
42
|
-
* Given a service which may not yet be resolved, intercept any method calls and resolve the service before invoking the
|
|
43
|
-
* method.
|
|
44
|
-
*
|
|
45
|
-
* @category Services
|
|
46
|
-
*/
|
|
47
|
-
export type ServiceMethodResolver<T> = {
|
|
48
|
-
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : T[K];
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Promise-like wrapper for asynchronous services.
|
|
52
|
-
*
|
|
53
|
-
* @see {@linkcode ServiceRepository} for usage.
|
|
54
|
-
*/
|
|
55
|
-
export declare class Service<T extends AsyncDisposable = AsyncDisposable> implements PromiseLike<T>, AsyncDisposable {
|
|
56
|
-
/**
|
|
57
|
-
* Instance of the service.
|
|
58
|
-
*
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
[kInstance]: T | null;
|
|
62
|
-
/**
|
|
63
|
-
* Resolver for the service.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
[kResolver]?: ServiceResolver<T>;
|
|
68
|
-
/**
|
|
69
|
-
* Context for the parent service registry.
|
|
70
|
-
*/
|
|
71
|
-
readonly context: ServiceRegistryContext;
|
|
72
|
-
protected constructor(resolver: ServiceResolver<T>);
|
|
73
|
-
/**
|
|
74
|
-
* Given an instance of a service, attach it to the resolver.
|
|
75
|
-
*
|
|
76
|
-
* This can be used to attach a service that was created outside of the resolver, such as when a resolver is defined
|
|
77
|
-
* from a TypeScript interface.
|
|
78
|
-
*
|
|
79
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
attach(service: T): void;
|
|
82
|
-
/**
|
|
83
|
-
* Resolve the service instance.
|
|
84
|
-
*
|
|
85
|
-
* This method is called implicitly when the service is awaited.
|
|
86
|
-
*/
|
|
87
|
-
protected resolve(): Promise<T>;
|
|
88
|
-
/**
|
|
89
|
-
* Resolve the service instance. Called implicitly when the service is awaited.
|
|
90
|
-
*/
|
|
91
|
-
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
|
92
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Service repository for managing asynchronous services.
|
|
96
|
-
*
|
|
97
|
-
* @singleton
|
|
98
|
-
*/
|
|
99
|
-
export declare class ServiceRepository extends Service<AsyncDisposable> {
|
|
100
|
-
static readonly [kRegistryMap]: Map<any, Service<any>>;
|
|
101
|
-
/**
|
|
102
|
-
* Abort controller for the service repository.
|
|
103
|
-
*/
|
|
104
|
-
static readonly abortController: AbortController;
|
|
105
|
-
/**
|
|
106
|
-
* Inspect the current state of the service registry.
|
|
107
|
-
*/
|
|
108
|
-
static inspect(): Service<any>[];
|
|
109
|
-
/**
|
|
110
|
-
* Dispose of all services in the registry.
|
|
111
|
-
*/
|
|
112
|
-
static [Symbol.asyncDispose](): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Dispose of all services in the registry.
|
|
115
|
-
*/
|
|
116
|
-
static dispose(): Promise<void>;
|
|
117
|
-
/**
|
|
118
|
-
* Register a pre-initialized service with the service repository.
|
|
119
|
-
*
|
|
120
|
-
* @param service - An instance of a service.
|
|
121
|
-
*/
|
|
122
|
-
static register<T extends AsyncDisposable>(service: T): Service<T> & ServiceMethodResolver<T>;
|
|
123
|
-
/**
|
|
124
|
-
* Register a service resolver with the service repository.
|
|
125
|
-
*
|
|
126
|
-
* @param serviceCallback - A callback which returns a service instance.
|
|
127
|
-
*/
|
|
128
|
-
static register<T extends AsyncDisposable>(serviceCallback: ServiceCallback<T>): Service<T> & ServiceMethodResolver<T>;
|
|
129
|
-
/**
|
|
130
|
-
* Register a service constructor with the service repository.
|
|
131
|
-
*
|
|
132
|
-
* @param ServiceConstructor - A constructor which returns a service instance.
|
|
133
|
-
*/
|
|
134
|
-
static register<T extends AsyncDisposable>(ServiceConstructor: ServiceConstructor<T>): Service<T> & ServiceMethodResolver<T>;
|
|
135
|
-
/**
|
|
136
|
-
* Register a service with the service repository.
|
|
137
|
-
*
|
|
138
|
-
* @param resolver - A service resolver, instance, or constructor.
|
|
139
|
-
*/
|
|
140
|
-
static register<T extends AsyncDisposable>(resolver: ServiceResolver<T>): Service<T> & ServiceMethodResolver<T>;
|
|
141
|
-
constructor();
|
|
142
|
-
}
|
|
143
|
-
export {};
|
|
144
|
-
//# sourceMappingURL=services.d.ts.map
|