@occultist/occultist 0.0.8 → 0.0.9
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/mod.d.ts +1 -0
- package/dist/mod.js +1 -0
- package/dist/registry.d.ts +13 -0
- package/dist/registry.js +27 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +1 -0
- package/lib/mod.ts +1 -0
- package/lib/registry.ts +32 -0
- package/lib/types.ts +11 -0
- package/package.json +1 -1
package/dist/mod.d.ts
CHANGED
package/dist/mod.js
CHANGED
package/dist/registry.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { IncomingMessage, type ServerResponse } from "node:http";
|
|
|
7
7
|
import type { Merge } from "./actions/spec.ts";
|
|
8
8
|
import type { ContextState, Middleware } from "./actions/spec.ts";
|
|
9
9
|
import { type CacheOperationResult } from "./mod.ts";
|
|
10
|
+
import type { Extension } from "./types.ts";
|
|
10
11
|
export interface Callable<State extends ContextState = ContextState> {
|
|
11
12
|
method(method: string, name: string, path: string): ActionAuth<State>;
|
|
12
13
|
}
|
|
@@ -248,6 +249,18 @@ export declare class Registry<State extends ContextState = ContextState> impleme
|
|
|
248
249
|
* @returns A NodeJS server response instance.
|
|
249
250
|
*/
|
|
250
251
|
handleRequest(req: IncomingMessage, res: ServerResponse): Promise<ServerResponse>;
|
|
252
|
+
/**
|
|
253
|
+
* Registers an Occultist extension. This is usually done
|
|
254
|
+
* by extensions when they are created.
|
|
255
|
+
*
|
|
256
|
+
* @param The Occultist extension to register.
|
|
257
|
+
*/
|
|
258
|
+
registerExtension(extension: Extension): void;
|
|
259
|
+
/**
|
|
260
|
+
* Must be called after all Occultist extensions have been registered.
|
|
261
|
+
* When some of the extensions have async setup tasks.
|
|
262
|
+
*/
|
|
263
|
+
setupExtensions(): Promise<void>;
|
|
251
264
|
addEventListener(type: RegistryEvents, callback: EventListener): void;
|
|
252
265
|
removeEventListener(type: RegistryEvents, callback: EventListener): void;
|
|
253
266
|
}
|
package/dist/registry.js
CHANGED
|
@@ -122,6 +122,7 @@ export class Registry {
|
|
|
122
122
|
#middleware = [];
|
|
123
123
|
#actions = null;
|
|
124
124
|
#handlers = null;
|
|
125
|
+
#extensions = [];
|
|
125
126
|
constructor(args) {
|
|
126
127
|
const url = new URL(args.rootIRI);
|
|
127
128
|
this.#rootIRI = args.rootIRI;
|
|
@@ -499,6 +500,32 @@ export class Registry {
|
|
|
499
500
|
return res;
|
|
500
501
|
}
|
|
501
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* Registers an Occultist extension. This is usually done
|
|
505
|
+
* by extensions when they are created.
|
|
506
|
+
*
|
|
507
|
+
* @param The Occultist extension to register.
|
|
508
|
+
*/
|
|
509
|
+
registerExtension(extension) {
|
|
510
|
+
this.#extensions.push(extension);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Must be called after all Occultist extensions have been registered.
|
|
514
|
+
* When some of the extensions have async setup tasks.
|
|
515
|
+
*/
|
|
516
|
+
async setupExtensions() {
|
|
517
|
+
const setupStreams = [];
|
|
518
|
+
for (let i = 0; i < this.#extensions.length; i++) {
|
|
519
|
+
if (typeof this.#extensions[i].setup === 'function') {
|
|
520
|
+
setupStreams.push(this.#extensions[i].setup());
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
for (let i = 0; i < setupStreams.length; i++) {
|
|
524
|
+
for await (const message of setupStreams[i]) {
|
|
525
|
+
console.log(message);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
502
529
|
addEventListener(type, callback) {
|
|
503
530
|
this.#eventTarget.addEventListener(type, callback);
|
|
504
531
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export interface StaticContext {
|
|
2
|
+
link(alias: string, as: string): string;
|
|
3
|
+
}
|
|
4
|
+
export interface Extension {
|
|
5
|
+
name: string;
|
|
6
|
+
setup?(): ReadableStream;
|
|
7
|
+
createStaticContext?(): StaticContext;
|
|
8
|
+
}
|
|
1
9
|
export type ProblemDetailsParam = {
|
|
2
10
|
name: string;
|
|
3
11
|
reason: string;
|
package/dist/types.js
CHANGED
package/lib/mod.ts
CHANGED
package/lib/registry.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { ContextState, Middleware } from "./actions/spec.ts";
|
|
|
11
11
|
import {ProblemDetailsError} from "./errors.ts"
|
|
12
12
|
import {WrappedRequest} from "./request.ts";
|
|
13
13
|
import {type CacheOperationResult} from "./mod.ts";
|
|
14
|
+
import type {Extension} from "./types.ts";
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
export interface Callable<
|
|
@@ -187,6 +188,7 @@ export class Registry<
|
|
|
187
188
|
#middleware: Middleware[] = [];
|
|
188
189
|
#actions: ImplementedAction[] | null = null;
|
|
189
190
|
#handlers: HandlerDefinition[] | null = null;
|
|
191
|
+
#extensions: Extension[] = [];
|
|
190
192
|
|
|
191
193
|
constructor(args: RegistryArgs) {
|
|
192
194
|
const url = new URL(args.rootIRI);
|
|
@@ -731,6 +733,36 @@ export class Registry<
|
|
|
731
733
|
}
|
|
732
734
|
}
|
|
733
735
|
|
|
736
|
+
/**
|
|
737
|
+
* Registers an Occultist extension. This is usually done
|
|
738
|
+
* by extensions when they are created.
|
|
739
|
+
*
|
|
740
|
+
* @param The Occultist extension to register.
|
|
741
|
+
*/
|
|
742
|
+
registerExtension(extension: Extension): void {
|
|
743
|
+
this.#extensions.push(extension);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Must be called after all Occultist extensions have been registered.
|
|
748
|
+
* When some of the extensions have async setup tasks.
|
|
749
|
+
*/
|
|
750
|
+
async setupExtensions(): Promise<void> {
|
|
751
|
+
const setupStreams: ReadableStream[] = [];
|
|
752
|
+
|
|
753
|
+
for (let i = 0; i < this.#extensions.length; i++) {
|
|
754
|
+
if (typeof this.#extensions[i].setup === 'function') {
|
|
755
|
+
setupStreams.push(this.#extensions[i].setup());
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
for (let i = 0; i < setupStreams.length; i++) {
|
|
760
|
+
for await (const message of setupStreams[i]) {
|
|
761
|
+
console.log(message);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
734
766
|
addEventListener(type: RegistryEvents, callback: EventListener) {
|
|
735
767
|
this.#eventTarget.addEventListener(type, callback);
|
|
736
768
|
};
|
package/lib/types.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
export interface StaticContext {
|
|
3
|
+
link(alias: string, as: string): string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface Extension {
|
|
7
|
+
name: string;
|
|
8
|
+
setup?(): ReadableStream;
|
|
9
|
+
createStaticContext?(): StaticContext;
|
|
10
|
+
};
|
|
11
|
+
|
|
1
12
|
export type ProblemDetailsParam = {
|
|
2
13
|
name: string;
|
|
3
14
|
reason: string;
|