@opalesce/core 0.0.1 → 0.1.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.
Files changed (39) hide show
  1. package/README.md +103 -157
  2. package/dist/index.d.ts +7 -5
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -2
  5. package/dist/interaction/build.d.ts +5 -0
  6. package/dist/interaction/build.d.ts.map +1 -0
  7. package/dist/interaction/build.js +315 -0
  8. package/dist/interaction/errors.d.ts +12 -0
  9. package/dist/interaction/errors.d.ts.map +1 -0
  10. package/dist/interaction/errors.js +12 -0
  11. package/dist/interaction/schema.d.ts +9 -0
  12. package/dist/interaction/schema.d.ts.map +1 -0
  13. package/dist/interaction/schema.js +178 -0
  14. package/dist/interaction/types.d.ts +69 -0
  15. package/dist/interaction/types.d.ts.map +1 -0
  16. package/dist/interaction/types.js +1 -0
  17. package/dist/orchestrator/artifacts.d.ts +1 -1
  18. package/dist/orchestrator/artifacts.d.ts.map +1 -1
  19. package/dist/orchestrator/artifacts.js +1 -1
  20. package/dist/orchestrator/errors.d.ts +1 -17
  21. package/dist/orchestrator/errors.d.ts.map +1 -1
  22. package/dist/orchestrator/errors.js +3 -27
  23. package/dist/orchestrator/run.d.ts.map +1 -1
  24. package/dist/orchestrator/run.js +35 -33
  25. package/dist/orchestrator/types.d.ts +6 -13
  26. package/dist/orchestrator/types.d.ts.map +1 -1
  27. package/dist/parseAsyncAPI.d.ts +2 -0
  28. package/dist/parseAsyncAPI.d.ts.map +1 -1
  29. package/dist/parseAsyncAPI.js +6 -0
  30. package/dist/source.d.ts +12 -0
  31. package/dist/source.d.ts.map +1 -0
  32. package/dist/source.js +39 -0
  33. package/package.json +18 -2
  34. package/dist/orchestrator/orderPlugins.d.ts +0 -3
  35. package/dist/orchestrator/orderPlugins.d.ts.map +0 -1
  36. package/dist/orchestrator/orderPlugins.js +0 -41
  37. package/dist/orchestrator/services.d.ts +0 -26
  38. package/dist/orchestrator/services.d.ts.map +0 -1
  39. package/dist/orchestrator/services.js +0 -42
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/orchestrator/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,MAAM,4BAA4B,GACpC,YAAY,GACZ,gBAAgB,GAChB,oBAAoB,GACpB,kBAAkB,CAAC;AAEvB,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,SAAkB,IAAI,8BAA8B;IACpD,QAAQ,CAAC,IAAI,EAAE,4BAA4B,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;gBAGtC,IAAI,EAAE,4BAA4B,EAClC,OAAO,EAAE,MAAM,EACf,WAAW,GAAE,SAAS,MAAM,EAAO;CAMtC;AAED,MAAM,MAAM,wBAAwB,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAE/E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,SAAkB,IAAI,0BAA0B;IAChD,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM;CAShE;AAED,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAElE,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,IAAI,mBAAmB;IACzC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM;CASlD;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,SAAkB,IAAI,0BAA0B;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;gBAEzB,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,OAAO;CAK5E"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/orchestrator/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,gBAAgB,CAAC;AAElE,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,IAAI,mBAAmB;IACzC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM;CASlD;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,SAAkB,IAAI,0BAA0B;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAI/C"}
@@ -1,25 +1,3 @@
1
- export class PluginConfigurationError extends Error {
2
- name = "PluginConfigurationError";
3
- code;
4
- pluginNames;
5
- constructor(code, message, pluginNames = []) {
6
- super(message);
7
- this.code = code;
8
- this.pluginNames = Object.freeze([...pluginNames]);
9
- }
10
- }
11
- export class ServiceRegistryError extends Error {
12
- name = "ServiceRegistryError";
13
- code;
14
- serviceName;
15
- constructor(code, serviceName) {
16
- super(code === "duplicate-service"
17
- ? `Service "${serviceName}" has already been provided.`
18
- : `Service "${serviceName}" has not been provided.`);
19
- this.code = code;
20
- this.serviceName = serviceName;
21
- }
22
- }
23
1
  export class ArtifactError extends Error {
24
2
  name = "ArtifactError";
25
3
  code;
@@ -27,7 +5,7 @@ export class ArtifactError extends Error {
27
5
  constructor(code, path) {
28
6
  super(code === "invalid-path"
29
7
  ? `Artifact path "${path}" must be a canonical relative path using forward slashes.`
30
- : `Artifact path "${path}" has already been emitted.`);
8
+ : `Artifact path "${path}" has already been generated.`);
31
9
  this.code = code;
32
10
  this.path = path;
33
11
  }
@@ -35,10 +13,8 @@ export class ArtifactError extends Error {
35
13
  export class PluginExecutionError extends Error {
36
14
  name = "PluginExecutionError";
37
15
  pluginName;
38
- phase;
39
- constructor(pluginName, phase, cause) {
40
- super(`Plugin "${pluginName}" failed during ${phase}.`, { cause });
16
+ constructor(pluginName, cause) {
17
+ super(`Plugin "${pluginName}" failed.`, { cause });
41
18
  this.pluginName = pluginName;
42
- this.phase = phase;
43
19
  }
44
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/orchestrator/run.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,cAAc,EACd,cAAc,EAIf,MAAM,YAAY,CAAC;AAcpB,wBAAsB,GAAG,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAiDzE"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/orchestrator/run.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAC;AAUhF,wBAAsB,GAAG,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAiDzE"}
@@ -1,56 +1,58 @@
1
1
  import { parseAsyncAPI } from "../parseAsyncAPI.js";
2
+ import { buildInteractionContract } from "../interaction/build.js";
2
3
  import { ArtifactStore } from "./artifacts.js";
3
4
  import { PluginExecutionError } from "./errors.js";
4
- import { orderPlugins } from "./orderPlugins.js";
5
- import { ServiceRegistry } from "./services.js";
6
- async function runHook(pluginName, phase, hook) {
5
+ async function runPlugin(pluginName, generate) {
7
6
  try {
8
- await hook();
7
+ await generate();
9
8
  }
10
9
  catch (cause) {
11
- throw new PluginExecutionError(pluginName, phase, cause);
10
+ throw new PluginExecutionError(pluginName, cause);
12
11
  }
13
12
  }
14
13
  export async function run(config) {
15
- const plugins = orderPlugins(config.plugins ?? []);
14
+ const plugins = Object.freeze([...(config.plugins ?? [])]);
16
15
  const parsed = await parseAsyncAPI(config.input, config.parser);
17
- const services = new ServiceRegistry();
18
16
  const artifacts = new ArtifactStore();
19
- function get(token) {
20
- return services.get(token);
21
- }
22
- const setupContext = Object.freeze({
17
+ let interaction;
18
+ let interactionError;
19
+ let interactionFailed = false;
20
+ const getInteraction = () => {
21
+ if (interaction !== undefined) {
22
+ return interaction;
23
+ }
24
+ if (interactionFailed) {
25
+ throw interactionError;
26
+ }
27
+ try {
28
+ interaction = buildInteractionContract(parsed.document, parsed.source);
29
+ return interaction;
30
+ }
31
+ catch (error) {
32
+ interactionError = error;
33
+ interactionFailed = true;
34
+ throw error;
35
+ }
36
+ };
37
+ const context = Object.freeze({
23
38
  document: parsed.document,
24
- diagnostics: parsed.diagnostics,
25
- get,
26
- provide(token, value) {
27
- services.provide(token, value);
39
+ get interaction() {
40
+ return getInteraction();
28
41
  },
29
- });
30
- const buildContext = Object.freeze({
31
- document: parsed.document,
32
42
  diagnostics: parsed.diagnostics,
33
- get,
34
- get artifacts() {
35
- return artifacts.snapshot();
36
- },
37
- emit(artifact) {
38
- artifacts.emit(artifact);
39
- },
43
+ ...(parsed.source === undefined ? {} : { source: parsed.source }),
40
44
  });
41
45
  for (const plugin of plugins) {
42
- if (plugin.setup !== undefined) {
43
- await runHook(plugin.name, "setup", () => plugin.setup?.(setupContext));
44
- }
45
- }
46
- for (const plugin of plugins) {
47
- if (plugin.build !== undefined) {
48
- await runHook(plugin.name, "build", () => plugin.build?.(buildContext));
49
- }
46
+ await runPlugin(plugin.name, async () => {
47
+ for (const artifact of await plugin.generate(context)) {
48
+ artifacts.add(artifact);
49
+ }
50
+ });
50
51
  }
51
52
  return Object.freeze({
52
53
  document: parsed.document,
53
54
  diagnostics: parsed.diagnostics,
55
+ ...(parsed.source === undefined ? {} : { source: parsed.source }),
54
56
  artifacts: artifacts.snapshot(),
55
57
  pluginNames: Object.freeze(plugins.map((plugin) => plugin.name)),
56
58
  });
@@ -1,26 +1,19 @@
1
1
  import type { AsyncAPIDocumentInterface, Diagnostic, Input, ParseAsyncAPIOptions } from "../parseAsyncAPI.js";
2
- import type { ServiceToken } from "./services.js";
2
+ import type { AsyncAPISource } from "../source.js";
3
+ import type { InteractionContract } from "../interaction/types.js";
3
4
  export interface GeneratedArtifact {
4
5
  readonly path: string;
5
6
  readonly contents: string;
6
7
  }
7
8
  export interface PluginContext {
8
9
  readonly document: AsyncAPIDocumentInterface;
10
+ readonly interaction: InteractionContract;
9
11
  readonly diagnostics: readonly Diagnostic[];
10
- get<T>(token: ServiceToken<T>): T;
11
- }
12
- export interface PluginSetupContext extends PluginContext {
13
- provide<T>(token: ServiceToken<T>, value: T): void;
14
- }
15
- export interface PluginBuildContext extends PluginContext {
16
- readonly artifacts: readonly GeneratedArtifact[];
17
- emit(artifact: GeneratedArtifact): void;
12
+ readonly source?: AsyncAPISource;
18
13
  }
19
14
  export interface OrchestrationPlugin<TName extends string = string> {
20
15
  readonly name: TName;
21
- readonly dependsOn?: readonly string[];
22
- setup?(context: PluginSetupContext): void | Promise<void>;
23
- build?(context: PluginBuildContext): void | Promise<void>;
16
+ generate(context: PluginContext): readonly GeneratedArtifact[] | Promise<readonly GeneratedArtifact[]>;
24
17
  }
25
18
  export interface PipelineConfig {
26
19
  readonly input: Input;
@@ -30,8 +23,8 @@ export interface PipelineConfig {
30
23
  export interface PipelineResult {
31
24
  readonly document: AsyncAPIDocumentInterface;
32
25
  readonly diagnostics: readonly Diagnostic[];
26
+ readonly source?: AsyncAPISource;
33
27
  readonly artifacts: readonly GeneratedArtifact[];
34
28
  readonly pluginNames: readonly string[];
35
29
  }
36
- export type PluginExecutionPhase = "setup" | "build";
37
30
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/orchestrator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,UAAU,EACV,KAAK,EACL,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;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KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACnD;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,CAAC;IAC7C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACjD,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC"}
@@ -1,8 +1,10 @@
1
1
  import { Parser, type AsyncAPIDocumentInterface, type Diagnostic, type Input, type ParseOptions } from "@asyncapi/parser";
2
+ import { type AsyncAPISource } from "./source.js";
2
3
  export type { AsyncAPIDocumentInterface, Diagnostic, Input, ParseOptions } from "@asyncapi/parser";
3
4
  export interface ParsedAsyncAPI {
4
5
  readonly document: AsyncAPIDocumentInterface;
5
6
  readonly diagnostics: readonly Diagnostic[];
7
+ readonly source?: AsyncAPISource;
6
8
  }
7
9
  export type AsyncAPIParserOptions = NonNullable<ConstructorParameters<typeof Parser>[0]>;
8
10
  export interface ParseAsyncAPIOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"parseAsyncAPI.d.ts","sourceRoot":"","sources":["../src/parseAsyncAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EACN,KAAK,yBAAyB,EAC9B,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,yBAAyB,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnG,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,CAAC;IAC7C,QAAQ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AAC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;CAC/B;AAMD,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;gBAEhC,WAAW,EAAE,SAAS,UAAU,EAAE;CAK/C;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,cAAc,CAAC,CAoBzB"}
@@ -1,4 +1,5 @@
1
1
  import { DiagnosticSeverity, Parser, } from "@asyncapi/parser";
2
+ import { createAsyncAPISource } from "./source.js";
2
3
  function freezeDiagnostics(diagnostics) {
3
4
  return Object.freeze([...diagnostics]);
4
5
  }
@@ -20,5 +21,10 @@ export async function parseAsyncAPI(input, options) {
20
21
  return {
21
22
  document: output.document,
22
23
  diagnostics: freezeDiagnostics(output.diagnostics),
24
+ ...(output.extras === undefined
25
+ ? {}
26
+ : {
27
+ source: createAsyncAPISource(output.extras.document.data, output.extras.document.source),
28
+ }),
23
29
  };
24
30
  }
@@ -0,0 +1,12 @@
1
+ export type JsonPrimitive = boolean | null | number | string;
2
+ export type JsonArray = readonly JsonValue[];
3
+ export interface JsonObject {
4
+ readonly [key: string]: JsonValue;
5
+ }
6
+ export type JsonValue = JsonArray | JsonObject | JsonPrimitive;
7
+ export interface AsyncAPISource {
8
+ readonly data: JsonValue;
9
+ readonly uri?: string;
10
+ }
11
+ export declare function createAsyncAPISource(data: unknown, uri: string | null): AsyncAPISource;
12
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,SAAS,SAAS,EAAE,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC;AAE/D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AA+CD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc,CAOtF"}
package/dist/source.js ADDED
@@ -0,0 +1,39 @@
1
+ function sourceValueError(pointer) {
2
+ return new TypeError(`AsyncAPI parser source at "${pointer || "/"}" is not JSON-compatible.`);
3
+ }
4
+ function copyJsonValue(value, pointer, ancestors) {
5
+ if (value === null ||
6
+ typeof value === "boolean" ||
7
+ typeof value === "string" ||
8
+ (typeof value === "number" && Number.isFinite(value))) {
9
+ return value;
10
+ }
11
+ if (typeof value !== "object") {
12
+ throw sourceValueError(pointer);
13
+ }
14
+ if (ancestors.has(value)) {
15
+ throw sourceValueError(pointer);
16
+ }
17
+ const nextAncestors = new Set(ancestors).add(value);
18
+ if (Array.isArray(value)) {
19
+ const copy = value.map((item, index) => copyJsonValue(item, `${pointer}/${index}`, nextAncestors));
20
+ return Object.freeze(copy);
21
+ }
22
+ const prototype = Object.getPrototypeOf(value);
23
+ if (prototype !== Object.prototype && prototype !== null) {
24
+ throw sourceValueError(pointer);
25
+ }
26
+ const entries = [];
27
+ for (const [key, child] of Object.entries(value)) {
28
+ const escapedKey = key.replaceAll("~", "~0").replaceAll("/", "~1");
29
+ entries.push([key, copyJsonValue(child, `${pointer}/${escapedKey}`, nextAncestors)]);
30
+ }
31
+ return Object.freeze(Object.fromEntries(entries));
32
+ }
33
+ export function createAsyncAPISource(data, uri) {
34
+ const source = {
35
+ data: copyJsonValue(data, "", new Set()),
36
+ ...(uri === null ? {} : { uri }),
37
+ };
38
+ return Object.freeze(source);
39
+ }
package/package.json CHANGED
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "@opalesce/core",
3
- "version": "0.0.1",
4
- "description": "AsyncAPI parsing and plugin orchestration engine for Opalesce",
3
+ "version": "0.1.0",
4
+ "description": "Transform AsyncAPI specifications into artifacts with Opalesce's plugin-based generation engine.",
5
+ "keywords": [
6
+ "artifact-generator",
7
+ "asyncapi",
8
+ "asyncapi-generator",
9
+ "code-generator",
10
+ "codegen",
11
+ "core-library",
12
+ "event-driven-api",
13
+ "event-driven-architecture",
14
+ "opalesce",
15
+ "plugin-framework",
16
+ "plugin-system",
17
+ "plugins",
18
+ "schema-parser",
19
+ "typescript"
20
+ ],
5
21
  "license": "MIT",
6
22
  "repository": {
7
23
  "type": "git",
@@ -1,3 +0,0 @@
1
- import type { OrchestrationPlugin } from "./types.js";
2
- export declare function orderPlugins(configuredPlugins: readonly OrchestrationPlugin[]): readonly OrchestrationPlugin[];
3
- //# sourceMappingURL=orderPlugins.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orderPlugins.d.ts","sourceRoot":"","sources":["../../src/orchestrator/orderPlugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAOtD,wBAAgB,YAAY,CAC1B,iBAAiB,EAAE,SAAS,mBAAmB,EAAE,GAChD,SAAS,mBAAmB,EAAE,CAwEhC"}
@@ -1,41 +0,0 @@
1
- import { PluginConfigurationError } from "./errors.js";
2
- export function orderPlugins(configuredPlugins) {
3
- const records = [];
4
- const pluginsByName = new Map();
5
- for (const plugin of configuredPlugins) {
6
- if (typeof plugin.name !== "string" || plugin.name.trim().length === 0) {
7
- throw new PluginConfigurationError("empty-name", "Plugin names must contain at least one non-whitespace character.");
8
- }
9
- if (pluginsByName.has(plugin.name)) {
10
- throw new PluginConfigurationError("duplicate-name", `Plugin name "${plugin.name}" is configured more than once.`, [plugin.name]);
11
- }
12
- pluginsByName.set(plugin.name, plugin);
13
- records.push({
14
- plugin,
15
- dependencies: Object.freeze([...new Set(plugin.dependsOn ?? [])]),
16
- });
17
- }
18
- for (const record of records) {
19
- if (record.dependencies.includes(record.plugin.name)) {
20
- throw new PluginConfigurationError("dependency-cycle", `Plugin "${record.plugin.name}" cannot depend on itself.`, [record.plugin.name]);
21
- }
22
- const missing = record.dependencies.filter((name) => !pluginsByName.has(name));
23
- if (missing.length > 0) {
24
- throw new PluginConfigurationError("missing-dependency", `Plugin "${record.plugin.name}" requires missing dependencies: ${missing.join(", ")}.`, [record.plugin.name, ...missing]);
25
- }
26
- }
27
- const pending = [...records];
28
- const resolvedNames = new Set();
29
- const ordered = [];
30
- while (pending.length > 0) {
31
- const ready = pending.find((record) => record.dependencies.every((name) => resolvedNames.has(name)));
32
- if (ready === undefined) {
33
- const cyclicNames = pending.map((record) => record.plugin.name);
34
- throw new PluginConfigurationError("dependency-cycle", `Plugin dependency cycle detected: ${cyclicNames.join(", ")}.`, cyclicNames);
35
- }
36
- pending.splice(pending.indexOf(ready), 1);
37
- ordered.push(ready.plugin);
38
- resolvedNames.add(ready.plugin.name);
39
- }
40
- return Object.freeze(ordered);
41
- }
@@ -1,26 +0,0 @@
1
- declare const serviceAccess: unique symbol;
2
- interface MissingService {
3
- readonly found: false;
4
- }
5
- interface AvailableService<T> {
6
- readonly found: true;
7
- readonly value: T;
8
- }
9
- type ServiceLookup<T> = MissingService | AvailableService<T>;
10
- interface ServiceAccess<T> {
11
- read(scope: object): ServiceLookup<T>;
12
- write(scope: object, value: T): boolean;
13
- }
14
- export interface ServiceToken<T> {
15
- readonly name: string;
16
- readonly key: symbol;
17
- readonly [serviceAccess]: ServiceAccess<T>;
18
- }
19
- export declare function createServiceToken<T>(name: string): ServiceToken<T>;
20
- export declare class ServiceRegistry {
21
- private readonly scope;
22
- provide<T>(token: ServiceToken<T>, value: T): void;
23
- get<T>(token: ServiceToken<T>): T;
24
- }
25
- export {};
26
- //# sourceMappingURL=services.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/orchestrator/services.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa,eAAoC,CAAC;AAExD,UAAU,cAAc;IACtB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED,UAAU,gBAAgB,CAAC,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AAED,KAAK,aAAa,CAAC,CAAC,IAAI,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAE7D,UAAU,aAAa,CAAC,CAAC;IACvB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IACtC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC;CACzC;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;CAC5C;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CA2BnE;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAM;IAE5B,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAMlD,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC;CASlC"}
@@ -1,42 +0,0 @@
1
- import { ServiceRegistryError } from "./errors.js";
2
- const serviceAccess = Symbol("opalesce.service-access");
3
- export function createServiceToken(name) {
4
- const values = new WeakMap();
5
- return Object.freeze({
6
- name,
7
- key: Symbol(name),
8
- [serviceAccess]: {
9
- read(scope) {
10
- const entry = values.get(scope);
11
- return entry === undefined
12
- ? { found: false }
13
- : {
14
- found: true,
15
- value: entry.value,
16
- };
17
- },
18
- write(scope, value) {
19
- if (values.has(scope)) {
20
- return false;
21
- }
22
- values.set(scope, { value });
23
- return true;
24
- },
25
- },
26
- });
27
- }
28
- export class ServiceRegistry {
29
- scope = {};
30
- provide(token, value) {
31
- if (!token[serviceAccess].write(this.scope, value)) {
32
- throw new ServiceRegistryError("duplicate-service", token.name);
33
- }
34
- }
35
- get(token) {
36
- const lookup = token[serviceAccess].read(this.scope);
37
- if (!lookup.found) {
38
- throw new ServiceRegistryError("missing-service", token.name);
39
- }
40
- return lookup.value;
41
- }
42
- }