@wyrly/next 1.0.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 (69) hide show
  1. package/LICENSE +202 -0
  2. package/esm/_dnt.shims.d.ts +6 -0
  3. package/esm/_dnt.shims.d.ts.map +1 -0
  4. package/esm/_dnt.shims.js +61 -0
  5. package/esm/core/container.d.ts +54 -0
  6. package/esm/core/container.d.ts.map +1 -0
  7. package/esm/core/container.js +282 -0
  8. package/esm/core/decorators.d.ts +8 -0
  9. package/esm/core/decorators.d.ts.map +1 -0
  10. package/esm/core/decorators.js +9 -0
  11. package/esm/core/errors.d.ts +33 -0
  12. package/esm/core/errors.d.ts.map +1 -0
  13. package/esm/core/errors.js +109 -0
  14. package/esm/core/graph.d.ts +26 -0
  15. package/esm/core/graph.d.ts.map +1 -0
  16. package/esm/core/graph.js +75 -0
  17. package/esm/core/graph_format.d.ts +17 -0
  18. package/esm/core/graph_format.d.ts.map +1 -0
  19. package/esm/core/graph_format.js +49 -0
  20. package/esm/core/i18n.d.ts +15 -0
  21. package/esm/core/i18n.d.ts.map +1 -0
  22. package/esm/core/i18n.js +122 -0
  23. package/esm/core/internal_keys.d.ts +6 -0
  24. package/esm/core/internal_keys.d.ts.map +1 -0
  25. package/esm/core/internal_keys.js +18 -0
  26. package/esm/core/lifetime.d.ts +2 -0
  27. package/esm/core/lifetime.d.ts.map +1 -0
  28. package/esm/core/lifetime.js +1 -0
  29. package/esm/core/metadata.d.ts +10 -0
  30. package/esm/core/metadata.d.ts.map +1 -0
  31. package/esm/core/metadata.js +7 -0
  32. package/esm/core/mod.d.ts +14 -0
  33. package/esm/core/mod.d.ts.map +1 -0
  34. package/esm/core/mod.js +7 -0
  35. package/esm/core/provider.d.ts +42 -0
  36. package/esm/core/provider.d.ts.map +1 -0
  37. package/esm/core/provider.js +69 -0
  38. package/esm/core/scope.d.ts +10 -0
  39. package/esm/core/scope.d.ts.map +1 -0
  40. package/esm/core/scope.js +1 -0
  41. package/esm/core/token.d.ts +12 -0
  42. package/esm/core/token.d.ts.map +1 -0
  43. package/esm/core/token.js +7 -0
  44. package/esm/core/types_decorator.d.ts +11 -0
  45. package/esm/core/types_decorator.d.ts.map +1 -0
  46. package/esm/core/types_decorator.js +1 -0
  47. package/esm/core/validate.d.ts +19 -0
  48. package/esm/core/validate.d.ts.map +1 -0
  49. package/esm/core/validate.js +127 -0
  50. package/esm/next/mod.d.ts +6 -0
  51. package/esm/next/mod.d.ts.map +1 -0
  52. package/esm/next/mod.js +4 -0
  53. package/esm/next/server_di.d.ts +14 -0
  54. package/esm/next/server_di.d.ts.map +1 -0
  55. package/esm/next/server_di.js +20 -0
  56. package/esm/next/tokens.d.ts +4 -0
  57. package/esm/next/tokens.d.ts.map +1 -0
  58. package/esm/next/tokens.js +3 -0
  59. package/esm/next/types.d.ts +19 -0
  60. package/esm/next/types.d.ts.map +1 -0
  61. package/esm/next/types.js +1 -0
  62. package/esm/next/with_action_di.d.ts +11 -0
  63. package/esm/next/with_action_di.d.ts.map +1 -0
  64. package/esm/next/with_action_di.js +19 -0
  65. package/esm/next/with_di.d.ts +14 -0
  66. package/esm/next/with_di.d.ts.map +1 -0
  67. package/esm/next/with_di.js +24 -0
  68. package/esm/package.json +3 -0
  69. package/package.json +33 -0
@@ -0,0 +1,33 @@
1
+ import type { InjectionToken } from "./token.js";
2
+ import { type ErrorMessageKind, type Locale } from "./i18n.js";
3
+ /** Dependency chain while resolving (for debugging and error display). */
4
+ export type ResolutionPath = readonly string[];
5
+ export interface ErrorLocaleOptions {
6
+ locale?: Locale;
7
+ }
8
+ export declare class ProviderNotFoundError extends Error {
9
+ readonly token: InjectionToken<unknown>;
10
+ readonly path: ResolutionPath;
11
+ constructor(token: InjectionToken<unknown>, path: ResolutionPath, options?: ErrorLocaleOptions);
12
+ }
13
+ export declare class CircularDependencyError extends Error {
14
+ readonly path: ResolutionPath;
15
+ constructor(path: ResolutionPath, options?: ErrorLocaleOptions);
16
+ }
17
+ export declare class InvalidProviderError extends Error {
18
+ constructor(messageOrKind: string | Extract<ErrorMessageKind, "InvalidProvider_class_token_only" | "InvalidProvider_scoped_from_root" | "InvalidProvider_unsupported_provider_type">, params?: Record<string, string> & ErrorLocaleOptions);
19
+ }
20
+ export declare class ScopeDisposedError extends Error {
21
+ constructor(options?: ErrorLocaleOptions);
22
+ }
23
+ export declare class LifetimeViolationError extends Error {
24
+ readonly fromLifetime: string;
25
+ readonly toLifetime: string;
26
+ readonly path: ResolutionPath;
27
+ constructor(fromLifetime: string, toLifetime: string, path: ResolutionPath, options?: ErrorLocaleOptions);
28
+ }
29
+ export declare class DuplicateProviderError extends Error {
30
+ readonly token: InjectionToken<unknown>;
31
+ constructor(token: InjectionToken<unknown>, options?: ErrorLocaleOptions);
32
+ }
33
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAEL,KAAK,gBAAgB,EAErB,KAAK,MAAM,EAGZ,MAAM,WAAW,CAAC;AAEnB,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GAAG,SAAS,MAAM,EAAE,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;gBAG5B,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,EAC9B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,kBAAkB;CAe/B;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;gBAElB,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,kBAAkB;CAU/D;AAED,qBAAa,oBAAqB,SAAQ,KAAK;gBAE3C,aAAa,EACT,MAAM,GACN,OAAO,CACP,gBAAgB,EACd,kCAAkC,GAClC,kCAAkC,GAClC,2CAA2C,CAC9C,EACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,kBAAkB;CASvD;AAED,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,CAAC,EAAE,kBAAkB;CAKzC;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;gBAG5B,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,kBAAkB;CAgB/B;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;gBAE5B,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB;CAOzE"}
@@ -0,0 +1,109 @@
1
+ import { tokenLabel } from "./internal_keys.js";
2
+ import { errorMessage, lifetimeViolationHint, providerNotFoundHint, resolveLocale, } from "./i18n.js";
3
+ export class ProviderNotFoundError extends Error {
4
+ constructor(token, path, options) {
5
+ const locale = resolveLocale(options);
6
+ const label = tokenLabel(token);
7
+ super(errorMessage("ProviderNotFound", {
8
+ label,
9
+ path: path.join(" -> "),
10
+ hint: providerNotFoundHint(locale),
11
+ }, locale));
12
+ Object.defineProperty(this, "token", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "path", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ this.name = "ProviderNotFoundError";
25
+ this.token = token;
26
+ this.path = path;
27
+ }
28
+ }
29
+ export class CircularDependencyError extends Error {
30
+ constructor(path, options) {
31
+ const locale = resolveLocale(options);
32
+ super(errorMessage("CircularDependency", {
33
+ path: path.join(" -> "),
34
+ }, locale));
35
+ Object.defineProperty(this, "path", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ this.name = "CircularDependencyError";
42
+ this.path = path;
43
+ }
44
+ }
45
+ export class InvalidProviderError extends Error {
46
+ constructor(messageOrKind, params) {
47
+ const locale = resolveLocale(params);
48
+ const text = typeof messageOrKind === "string"
49
+ ? errorMessage("InvalidProvider_custom", { detail: messageOrKind }, locale)
50
+ : errorMessage(messageOrKind, params ?? {}, locale);
51
+ super(text);
52
+ this.name = "InvalidProviderError";
53
+ }
54
+ }
55
+ export class ScopeDisposedError extends Error {
56
+ constructor(options) {
57
+ const locale = resolveLocale(options);
58
+ super(errorMessage("ScopeDisposed", {}, locale));
59
+ this.name = "ScopeDisposedError";
60
+ }
61
+ }
62
+ export class LifetimeViolationError extends Error {
63
+ constructor(fromLifetime, toLifetime, path, options) {
64
+ const locale = resolveLocale(options);
65
+ super(errorMessage("LifetimeViolation", {
66
+ fromLifetime,
67
+ toLifetime,
68
+ path: path.join(" -> "),
69
+ hint: lifetimeViolationHint(locale),
70
+ }, locale));
71
+ Object.defineProperty(this, "fromLifetime", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: void 0
76
+ });
77
+ Object.defineProperty(this, "toLifetime", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: void 0
82
+ });
83
+ Object.defineProperty(this, "path", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: void 0
88
+ });
89
+ this.name = "LifetimeViolationError";
90
+ this.fromLifetime = fromLifetime;
91
+ this.toLifetime = toLifetime;
92
+ this.path = path;
93
+ }
94
+ }
95
+ export class DuplicateProviderError extends Error {
96
+ constructor(token, options) {
97
+ const locale = resolveLocale(options);
98
+ const label = tokenLabel(token);
99
+ super(errorMessage("DuplicateProvider", { label }, locale));
100
+ Object.defineProperty(this, "token", {
101
+ enumerable: true,
102
+ configurable: true,
103
+ writable: true,
104
+ value: void 0
105
+ });
106
+ this.name = "DuplicateProviderError";
107
+ this.token = token;
108
+ }
109
+ }
@@ -0,0 +1,26 @@
1
+ import type { Lifetime } from "./lifetime.js";
2
+ import type { NormalizedProvider, ProviderType } from "./provider.js";
3
+ import type { InjectionToken } from "./token.js";
4
+ export interface DependencyNode {
5
+ id: string;
6
+ name: string;
7
+ lifetime: Lifetime;
8
+ provider: ProviderType;
9
+ }
10
+ export interface DependencyEdge {
11
+ from: string;
12
+ to: string;
13
+ }
14
+ export interface DependencyGraph {
15
+ nodes: DependencyNode[];
16
+ edges: DependencyEdge[];
17
+ }
18
+ export declare function inferLifetimeForToken(dep: InjectionToken<unknown>): Lifetime;
19
+ export declare function buildGraph(providers: Iterable<NormalizedProvider<unknown>>): DependencyGraph;
20
+ /** Collapses duplicate edges with the same from/to into one */
21
+ export declare function dedupeEdges(edges: DependencyEdge[]): DependencyEdge[];
22
+ import type { RegistryKey } from "./internal_keys.js";
23
+ export declare function collectRegisteredProviders(registry: Map<RegistryKey, NormalizedProvider<unknown>>): NormalizedProvider<unknown>[];
24
+ /** For inspect: include @Injectable-only classes not registered as tokens */
25
+ export declare function augmentGraphWithInjectableClasses(graph: DependencyGraph, extraClasses: Iterable<InjectionToken<unknown>>): DependencyGraph;
26
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/core/graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,QAAQ,CAM5E;AAED,wBAAgB,UAAU,CACxB,SAAS,EAAE,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC/C,eAAe,CAgCjB;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAUrE;AAED,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,GACtD,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAE/B;AAED,6EAA6E;AAC7E,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,GAC9C,eAAe,CAiBjB"}
@@ -0,0 +1,75 @@
1
+ import { graphNodeId, tokenLabel } from "./internal_keys.js";
2
+ import { getInjectableMetadata } from "./metadata.js";
3
+ export function inferLifetimeForToken(dep) {
4
+ if (typeof dep === "function") {
5
+ const meta = getInjectableMetadata(dep);
6
+ if (meta?.lifetime)
7
+ return meta.lifetime;
8
+ }
9
+ return "singleton";
10
+ }
11
+ export function buildGraph(providers) {
12
+ const nodes = new Map();
13
+ const edges = [];
14
+ const list = [...providers];
15
+ for (const p of list) {
16
+ const id = graphNodeId(p.token);
17
+ nodes.set(id, {
18
+ id,
19
+ name: tokenLabel(p.token),
20
+ lifetime: p.lifetime,
21
+ provider: p.providerType,
22
+ });
23
+ }
24
+ for (const p of list) {
25
+ const id = graphNodeId(p.token);
26
+ for (const dep of p.deps) {
27
+ const toId = graphNodeId(dep);
28
+ if (!nodes.has(toId)) {
29
+ nodes.set(toId, {
30
+ id: toId,
31
+ name: tokenLabel(dep),
32
+ lifetime: inferLifetimeForToken(dep),
33
+ provider: "class",
34
+ });
35
+ }
36
+ edges.push({ from: id, to: toId });
37
+ }
38
+ }
39
+ return { nodes: [...nodes.values()], edges: dedupeEdges(edges) };
40
+ }
41
+ /** Collapses duplicate edges with the same from/to into one */
42
+ export function dedupeEdges(edges) {
43
+ const seen = new Set();
44
+ const out = [];
45
+ for (const e of edges) {
46
+ const key = `${e.from}\0${e.to}`;
47
+ if (seen.has(key))
48
+ continue;
49
+ seen.add(key);
50
+ out.push(e);
51
+ }
52
+ return out;
53
+ }
54
+ export function collectRegisteredProviders(registry) {
55
+ return [...registry.values()];
56
+ }
57
+ /** For inspect: include @Injectable-only classes not registered as tokens */
58
+ export function augmentGraphWithInjectableClasses(graph, extraClasses) {
59
+ const nodes = new Map(graph.nodes.map((n) => [n.id, n]));
60
+ const edges = [...graph.edges];
61
+ for (const t of extraClasses) {
62
+ if (typeof t !== "function")
63
+ continue;
64
+ const id = graphNodeId(t);
65
+ if (nodes.has(id))
66
+ continue;
67
+ nodes.set(id, {
68
+ id,
69
+ name: tokenLabel(t),
70
+ lifetime: inferLifetimeForToken(t),
71
+ provider: "class",
72
+ });
73
+ }
74
+ return { nodes: [...nodes.values()], edges: dedupeEdges(edges) };
75
+ }
@@ -0,0 +1,17 @@
1
+ import type { DependencyGraph } from "./graph.js";
2
+ export interface GraphToJsonOptions {
3
+ indent?: number;
4
+ }
5
+ /**
6
+ * Serializes the dependency graph to a JSON string.
7
+ */
8
+ export declare function graphToJson(graph: DependencyGraph, options?: GraphToJsonOptions): string;
9
+ /**
10
+ * Converts the dependency graph to Graphviz DOT format.
11
+ */
12
+ export declare function graphToDot(graph: DependencyGraph): string;
13
+ /**
14
+ * Converts the dependency graph to Mermaid flowchart format.
15
+ */
16
+ export declare function graphToMermaid(graph: DependencyGraph): string;
17
+ //# sourceMappingURL=graph_format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph_format.d.ts","sourceRoot":"","sources":["../../src/core/graph_format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAkB,MAAM,YAAY,CAAC;AAElE,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAcD;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAYzD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAa7D"}
@@ -0,0 +1,49 @@
1
+ function escapeDotId(id) {
2
+ return JSON.stringify(id);
3
+ }
4
+ function escapeMermaidId(id) {
5
+ return id.replace(/[^a-zA-Z0-9_]/g, "_");
6
+ }
7
+ function nodeLabel(node) {
8
+ return `${node.name} (${node.lifetime})`;
9
+ }
10
+ /**
11
+ * Serializes the dependency graph to a JSON string.
12
+ */
13
+ export function graphToJson(graph, options = {}) {
14
+ const indent = options.indent ?? 2;
15
+ return JSON.stringify(graph, null, indent);
16
+ }
17
+ /**
18
+ * Converts the dependency graph to Graphviz DOT format.
19
+ */
20
+ export function graphToDot(graph) {
21
+ const lines = ["digraph DependencyGraph {", ' rankdir="LR";'];
22
+ for (const node of graph.nodes) {
23
+ const id = escapeDotId(node.id);
24
+ const label = JSON.stringify(nodeLabel(node));
25
+ lines.push(` ${id} [label=${label}];`);
26
+ }
27
+ for (const edge of graph.edges) {
28
+ lines.push(` ${escapeDotId(edge.from)} -> ${escapeDotId(edge.to)};`);
29
+ }
30
+ lines.push("}");
31
+ return lines.join("\n");
32
+ }
33
+ /**
34
+ * Converts the dependency graph to Mermaid flowchart format.
35
+ */
36
+ export function graphToMermaid(graph) {
37
+ const lines = ["flowchart TD"];
38
+ for (const node of graph.nodes) {
39
+ const id = escapeMermaidId(node.id);
40
+ const label = nodeLabel(node).replace(/"/g, "'");
41
+ lines.push(` ${id}["${label}"]`);
42
+ }
43
+ for (const edge of graph.edges) {
44
+ const from = escapeMermaidId(edge.from);
45
+ const to = escapeMermaidId(edge.to);
46
+ lines.push(` ${from} --> ${to}`);
47
+ }
48
+ return lines.join("\n");
49
+ }
@@ -0,0 +1,15 @@
1
+ export type Locale = "en" | "ja";
2
+ export declare const DEFAULT_LOCALE: Locale;
3
+ export type ValidationMessageCode = "unresolved_dependency" | "singleton_depends_on_scoped" | "transient_depends_on_scoped" | "circular_dependency" | "unused_provider";
4
+ export type ErrorMessageKind = "ProviderNotFound" | "CircularDependency" | "ScopeDisposed" | "LifetimeViolation" | "DuplicateProvider" | "InvalidProvider_class_token_only" | "InvalidProvider_scoped_from_root" | "InvalidProvider_unsupported_provider_type" | "InvalidProvider_custom";
5
+ /** Normalize BCP 47 / POSIX locale tags to supported `en` | `ja`. */
6
+ export declare function normalizeLocaleTag(tag: string): Locale;
7
+ /** Resolve locale from options, env, Intl, or fall back to `en`. */
8
+ export declare function resolveLocale(options?: {
9
+ locale?: Locale;
10
+ }): Locale;
11
+ export declare function validationMessage(code: ValidationMessageCode, params: Record<string, string>, locale: Locale): string;
12
+ export declare function errorMessage(kind: ErrorMessageKind, params: Record<string, string>, locale: Locale): string;
13
+ export declare function providerNotFoundHint(locale: Locale): string;
14
+ export declare function lifetimeViolationHint(locale: Locale): string;
15
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/core/i18n.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;AAEjC,eAAO,MAAM,cAAc,EAAE,MAAa,CAAC;AAE3C,MAAM,MAAM,qBAAqB,GAC7B,uBAAuB,GACvB,6BAA6B,GAC7B,6BAA6B,GAC7B,qBAAqB,GACrB,iBAAiB,CAAC;AAEtB,MAAM,MAAM,gBAAgB,GACxB,kBAAkB,GAClB,oBAAoB,GACpB,eAAe,GACf,mBAAmB,GACnB,mBAAmB,GACnB,kCAAkC,GAClC,kCAAkC,GAClC,2CAA2C,GAC3C,wBAAwB,CAAC;AAE7B,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAItD;AAUD,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA0BnE;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,qBAAqB,EAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,MAAM,EAAE,MAAM,GACb,MAAM,CAsBR;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,gBAAgB,EACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,MAAM,EAAE,MAAM,GACb,MAAM,CA6CR;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI5D"}
@@ -0,0 +1,122 @@
1
+ import * as dntShim from "../_dnt.shims.js";
2
+ export const DEFAULT_LOCALE = "en";
3
+ /** Normalize BCP 47 / POSIX locale tags to supported `en` | `ja`. */
4
+ export function normalizeLocaleTag(tag) {
5
+ const primary = tag.trim().split(/[-_]/)[0]?.toLowerCase();
6
+ if (primary === "ja")
7
+ return "ja";
8
+ return "en";
9
+ }
10
+ function envGet(key) {
11
+ try {
12
+ return dntShim.Deno.env.get(key);
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ }
18
+ /** Resolve locale from options, env, Intl, or fall back to `en`. */
19
+ export function resolveLocale(options) {
20
+ if (options?.locale)
21
+ return options.locale;
22
+ const explicit = envGet("WYRLY_LOCALE");
23
+ if (explicit)
24
+ return normalizeLocaleTag(explicit);
25
+ for (const key of ["LC_ALL", "LC_MESSAGES", "LANG"]) {
26
+ const v = envGet(key);
27
+ if (v) {
28
+ const part = v.split(".")[0] ?? v;
29
+ return normalizeLocaleTag(part.replace("_", "-"));
30
+ }
31
+ }
32
+ try {
33
+ const intl = Intl.DateTimeFormat().resolvedOptions().locale;
34
+ if (intl)
35
+ return normalizeLocaleTag(intl);
36
+ }
37
+ catch {
38
+ // ignore
39
+ }
40
+ if (typeof navigator !== "undefined" && navigator.language) {
41
+ return normalizeLocaleTag(navigator.language);
42
+ }
43
+ return DEFAULT_LOCALE;
44
+ }
45
+ export function validationMessage(code, params, locale) {
46
+ const { fromId, depId, cycle } = params;
47
+ switch (code) {
48
+ case "unresolved_dependency":
49
+ return locale === "ja"
50
+ ? `${fromId} が未登録の依存 ${depId} を参照しています。`
51
+ : `${fromId} references unregistered dependency ${depId}.`;
52
+ case "singleton_depends_on_scoped":
53
+ return locale === "ja"
54
+ ? `${fromId} (singleton) が scoped の依存 ${depId} に依存しています。`
55
+ : `${fromId} (singleton) depends on scoped dependency ${depId}.`;
56
+ case "transient_depends_on_scoped":
57
+ return locale === "ja"
58
+ ? `${fromId} (transient) が scoped の依存 ${depId} に依存しています。実行コンテキストに注意してください。`
59
+ : `${fromId} (transient) depends on scoped dependency ${depId}. Mind the execution context.`;
60
+ case "circular_dependency":
61
+ return locale === "ja" ? `循環依存: ${cycle ?? ""}` : `Circular dependency: ${cycle ?? ""}`;
62
+ case "unused_provider":
63
+ return locale === "ja"
64
+ ? `${fromId} は他の provider から依存されていません(未使用の可能性があります)。`
65
+ : `${fromId} is not depended on by any other provider (may be unused).`;
66
+ }
67
+ }
68
+ export function errorMessage(kind, params, locale) {
69
+ const label = params.label ?? "";
70
+ const path = params.path ?? "";
71
+ const hint = params.hint ?? "";
72
+ const detail = params.detail ?? "";
73
+ const fromLifetime = params.fromLifetime ?? "";
74
+ const toLifetime = params.toLifetime ?? "";
75
+ const providerType = params.providerType ?? "";
76
+ switch (kind) {
77
+ case "ProviderNotFound":
78
+ return locale === "ja"
79
+ ? `ProviderNotFoundError: ${label} を解決できません。依存パス: [${path}]。${hint}`
80
+ : `ProviderNotFoundError: Cannot resolve ${label}. Dependency path: [${path}]. ${hint}`;
81
+ case "CircularDependency":
82
+ return locale === "ja"
83
+ ? `CircularDependencyError: 循環依存を検出しました: ${path}。依存関係を見直してください。`
84
+ : `CircularDependencyError: Circular dependency detected: ${path}. Review your dependency graph.`;
85
+ case "ScopeDisposed":
86
+ return locale === "ja"
87
+ ? "ScopeDisposedError: すでに dispose 済みのスコープで resolve しようとしました。リクエスト終了後に resolve していないか確認してください。"
88
+ : "ScopeDisposedError: Attempted to resolve on an already disposed scope. Check for resolve after request end.";
89
+ case "LifetimeViolation":
90
+ return locale === "ja"
91
+ ? `LifetimeViolationError: lifetime ${fromLifetime} が ${toLifetime} に依存しようとしています。パス: [${path}]。${hint}`
92
+ : `LifetimeViolationError: lifetime ${fromLifetime} cannot depend on ${toLifetime}. Path: [${path}]. ${hint}`;
93
+ case "DuplicateProvider":
94
+ return locale === "ja"
95
+ ? `DuplicateProviderError: ${label} はすでに登録されています。上書きする場合は override() を使ってください。`
96
+ : `DuplicateProviderError: ${label} is already registered. Use override() to replace it.`;
97
+ case "InvalidProvider_class_token_only":
98
+ return locale === "ja"
99
+ ? "InvalidProviderError: provider を省略できるのはクラストークンのみです。"
100
+ : "InvalidProviderError: Omitting provider is only allowed for class tokens.";
101
+ case "InvalidProvider_scoped_from_root":
102
+ return locale === "ja"
103
+ ? "InvalidProviderError: scoped のプロバイダは createScope() で得た Scope から resolve() してください。"
104
+ : "InvalidProviderError: Resolve scoped providers from a Scope created via createScope().";
105
+ case "InvalidProvider_unsupported_provider_type":
106
+ return locale === "ja"
107
+ ? `InvalidProviderError: 未対応の providerType: ${providerType}`
108
+ : `InvalidProviderError: Unsupported providerType: ${providerType}`;
109
+ case "InvalidProvider_custom":
110
+ return `InvalidProviderError: ${detail}`;
111
+ }
112
+ }
113
+ export function providerNotFoundHint(locale) {
114
+ return locale === "ja"
115
+ ? "composition root で register() するか、@Injectable() の deps を確認してください。"
116
+ : "Register it in the composition root or check @Injectable() deps.";
117
+ }
118
+ export function lifetimeViolationHint(locale) {
119
+ return locale === "ja"
120
+ ? "singleton は scoped インスタンスに依存できません。scoped にするか、依存を singleton/transient に変更してください。"
121
+ : "singleton cannot depend on scoped instances. Use scoped lifetime or change dependencies to singleton/transient.";
122
+ }
@@ -0,0 +1,6 @@
1
+ import type { ClassToken, InjectionToken } from "./token.js";
2
+ export type RegistryKey = symbol | ClassToken<unknown>;
3
+ export declare function registryKey(t: InjectionToken<unknown>): RegistryKey;
4
+ export declare function tokenLabel(t: InjectionToken<unknown>): string;
5
+ export declare function graphNodeId(t: InjectionToken<unknown>): string;
6
+ //# sourceMappingURL=internal_keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal_keys.d.ts","sourceRoot":"","sources":["../../src/core/internal_keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAS,MAAM,YAAY,CAAC;AAEpE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AAEvD,wBAAgB,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,WAAW,CAGnE;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,MAAM,CAK7D;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,MAAM,CAM9D"}
@@ -0,0 +1,18 @@
1
+ export function registryKey(t) {
2
+ if (typeof t === "function")
3
+ return t;
4
+ return t.id;
5
+ }
6
+ export function tokenLabel(t) {
7
+ if (typeof t === "function") {
8
+ return `class:${t.name || "(anonymous)"}`;
9
+ }
10
+ return `token:${t.name}`;
11
+ }
12
+ export function graphNodeId(t) {
13
+ if (typeof t === "function") {
14
+ return `class:${t.name || "(anonymous)"}`;
15
+ }
16
+ const tok = t;
17
+ return `token:${tok.name}@${String(tok.id)}`;
18
+ }
@@ -0,0 +1,2 @@
1
+ export type Lifetime = "singleton" | "scoped" | "transient";
2
+ //# sourceMappingURL=lifetime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifetime.d.ts","sourceRoot":"","sources":["../../src/core/lifetime.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { ClassToken } from "./token.js";
2
+ import type { Lifetime } from "./lifetime.js";
3
+ import type { InjectionToken } from "./token.js";
4
+ export interface InjectableMetadata {
5
+ deps?: InjectionToken<unknown>[];
6
+ lifetime?: Lifetime;
7
+ }
8
+ export declare function setInjectableMetadata(ctor: ClassToken<unknown>, meta: InjectableMetadata): void;
9
+ export declare function getInjectableMetadata(ctor: ClassToken<unknown>): InjectableMetadata | undefined;
10
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAOD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EACzB,IAAI,EAAE,kBAAkB,GACvB,IAAI,CAEN;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GACxB,kBAAkB,GAAG,SAAS,CAEhC"}
@@ -0,0 +1,7 @@
1
+ const injectableMetadata = new WeakMap();
2
+ export function setInjectableMetadata(ctor, meta) {
3
+ injectableMetadata.set(ctor, meta);
4
+ }
5
+ export function getInjectableMetadata(ctor) {
6
+ return injectableMetadata.get(ctor);
7
+ }
@@ -0,0 +1,14 @@
1
+ export { type ClassToken, type InjectionToken, type Token, token } from "./token.js";
2
+ export type { Lifetime } from "./lifetime.js";
3
+ export { Injectable } from "./decorators.js";
4
+ export { type Container, createContainer } from "./container.js";
5
+ export type { Scope } from "./scope.js";
6
+ export type { ClassProvider, ExistingProvider, FactoryProvider, Provider, ValueProvider, } from "./provider.js";
7
+ export type { DependencyEdge, DependencyGraph, DependencyNode } from "./graph.js";
8
+ export { graphToDot, graphToJson, graphToMermaid } from "./graph_format.js";
9
+ export type { GraphToJsonOptions } from "./graph_format.js";
10
+ export type { ValidateOptions, ValidationIssue, ValidationResult } from "./validate.js";
11
+ export { validateNormalizedProviders } from "./validate.js";
12
+ export { DEFAULT_LOCALE, errorMessage, type ErrorMessageKind, lifetimeViolationHint, type Locale, normalizeLocaleTag, providerNotFoundHint, resolveLocale, validationMessage, type ValidationMessageCode, } from "./i18n.js";
13
+ export { CircularDependencyError, DuplicateProviderError, InvalidProviderError, LifetimeViolationError, ProviderNotFoundError, ScopeDisposedError, } from "./errors.js";
14
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/core/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrF,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjE,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC5E,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,cAAc,EACd,YAAY,EACZ,KAAK,gBAAgB,EACrB,qBAAqB,EACrB,KAAK,MAAM,EACX,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,KAAK,qBAAqB,GAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { token } from "./token.js";
2
+ export { Injectable } from "./decorators.js";
3
+ export { createContainer } from "./container.js";
4
+ export { graphToDot, graphToJson, graphToMermaid } from "./graph_format.js";
5
+ export { validateNormalizedProviders } from "./validate.js";
6
+ export { DEFAULT_LOCALE, errorMessage, lifetimeViolationHint, normalizeLocaleTag, providerNotFoundHint, resolveLocale, validationMessage, } from "./i18n.js";
7
+ export { CircularDependencyError, DuplicateProviderError, InvalidProviderError, LifetimeViolationError, ProviderNotFoundError, ScopeDisposedError, } from "./errors.js";
@@ -0,0 +1,42 @@
1
+ import type { Scope } from "./scope.js";
2
+ import type { ClassToken } from "./token.js";
3
+ import type { InjectionToken } from "./token.js";
4
+ import type { Lifetime } from "./lifetime.js";
5
+ export type Provider<T> = ClassProvider<T> | ValueProvider<T> | FactoryProvider<T> | ExistingProvider<T>;
6
+ export interface ClassProvider<T> {
7
+ useClass: ClassToken<T>;
8
+ deps?: InjectionToken<unknown>[];
9
+ lifetime?: Lifetime;
10
+ }
11
+ export interface ValueProvider<T> {
12
+ useValue: T;
13
+ lifetime?: "singleton";
14
+ }
15
+ /**
16
+ * MVP supports synchronous factories only. `Promise<T>` is planned for a future `resolveAsync`.
17
+ */
18
+ export interface FactoryProvider<T> {
19
+ useFactory: (scope: Scope) => T;
20
+ deps?: InjectionToken<unknown>[];
21
+ lifetime?: Lifetime;
22
+ }
23
+ export interface ExistingProvider<T> {
24
+ useExisting: InjectionToken<T>;
25
+ lifetime?: Lifetime;
26
+ }
27
+ export type ProviderType = "class" | "value" | "factory" | "existing";
28
+ /** Container-internal representation (normalized after registration) */
29
+ export interface NormalizedProvider<T = unknown> {
30
+ readonly token: InjectionToken<T>;
31
+ readonly providerType: ProviderType;
32
+ readonly deps: readonly InjectionToken<unknown>[];
33
+ readonly lifetime: Lifetime;
34
+ readonly displayName: string;
35
+ readonly useClass?: ClassToken<T>;
36
+ readonly useValue?: T;
37
+ readonly useFactory?: (scope: Scope) => T;
38
+ readonly useExisting?: InjectionToken<T>;
39
+ }
40
+ export declare function normalizeProvider<T>(token: InjectionToken<T>, provider: Provider<T>): NormalizedProvider<T>;
41
+ export declare function syntheticClassProvider<T>(token: ClassToken<T>): NormalizedProvider<T>;
42
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/core/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9C,MAAM,MAAM,QAAQ,CAAC,CAAC,IAClB,aAAa,CAAC,CAAC,CAAC,GAChB,aAAa,CAAC,CAAC,CAAC,GAChB,eAAe,CAAC,CAAC,CAAC,GAClB,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAExB,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC;IACZ,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AAEtE,wEAAwE;AACxE,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,SAAS,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IAClD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CAC1C;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EACxB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GACpB,kBAAkB,CAAC,CAAC,CAAC,CAwDvB;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GACnB,kBAAkB,CAAC,CAAC,CAAC,CAYvB"}