@fougere/container 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fougere contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @fougere/container
2
+ > The DI container interface
3
+ The interface alone, with no implementation and no dependency — enough to write code
4
+ that resolves its dependencies without marrying one particular container.
5
+
6
+ ## Installation
7
+ ```bash
8
+ pnpm add @fougere/container
9
+ ```
10
+
11
+ ---
12
+
13
+ Part of [Fougere](https://github.com/chok/fougere) — one schema, a gradient from
14
+ monolith to distributed, the same user code.
15
+ Reference documentation: [the site](https://chok.github.io/fougere/) (en/fr).
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Resolver function — receives the container to resolve dependencies.
3
+ */
4
+ export type ResolverFn<T = unknown> = (container: Container) => T;
5
+ /**
6
+ * Registration options.
7
+ */
8
+ export interface RegisterOptions {
9
+ /** Lifetime of the resolved value. Default: 'transient'. */
10
+ lifetime?: 'singleton' | 'scoped' | 'transient';
11
+ /** Dependency type names for type-based resolution (from AST scan). */
12
+ deps?: string[];
13
+ }
14
+ /**
15
+ * A class constructor with any arguments.
16
+ */
17
+ export type Constructor<T = unknown> = new (...args: any[]) => T;
18
+ /**
19
+ * What can be registered: a class or a resolver function.
20
+ */
21
+ export type Registration<T = unknown> = Constructor<T> | ResolverFn<T>;
22
+ /**
23
+ * DI container interface — the only thing application code sees.
24
+ */
25
+ export interface Container {
26
+ /** Register a value by name. */
27
+ register<T>(name: string, registration: Registration<T>, options?: RegisterOptions): void;
28
+ /** Register a pre-built value by name. */
29
+ registerValue<T>(name: string, value: T): void;
30
+ /** Resolve a dependency by name. */
31
+ resolve<T>(name: string): T;
32
+ /** Check if a name is registered (including parent scopes). */
33
+ has(name: string): boolean;
34
+ /**
35
+ * A resolver of last resort, consulted when no scope holds the name.
36
+ *
37
+ * It exists for one reason: a frond declared in `remotes` registers nothing locally,
38
+ * so its façade cannot be *found* — it has to be fabricated. Set on the root, inherited
39
+ * by every scope. Returning `undefined` means "I don't know either", and the miss
40
+ * throws as before.
41
+ *
42
+ * Optional: a container without one behaves exactly as it did.
43
+ */
44
+ setFallback?(resolve: (name: string) => unknown): void;
45
+ /** Create a child scope. Inherits parent registrations. */
46
+ createScope(): Container;
47
+ /** Dispose the container and its scoped singletons. */
48
+ dispose(): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAChD,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AAEH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,gCAAgC;IAChC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAE1F,0CAA0C;IAC1C,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAE/C,oCAAoC;IACpC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IAE5B,+DAA+D;IAC/D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3B;;;;;;;;;OASG;IACH,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;IAEvD,2DAA2D;IAC3D,WAAW,IAAI,SAAS,CAAC;IAEzB,uDAAuD;IACvD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { type Container, type Registration, type RegisterOptions, type ResolverFn, type Constructor, } from './container.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@fougere/container",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Fougere's DI container interface. Zero dependencies.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/chok/fougere.git",
9
+ "directory": "packages/container"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "rm -rf dist && tsc",
29
+ "typecheck": "tsc --noEmit"
30
+ }
31
+ }