autobuilder-ts 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark Manley
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,33 @@
1
+ # autobuilder-ts
2
+
3
+ A "mad science", strongly-typed AutoBuilder for TypeScript. It automatically
4
+ collapses into your final object as soon as your planned keys are fulfilled,
5
+ eliminating the need for a trailing `.build()` method.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install autobuilder-ts
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { autoBuilder } from "autobuilder-ts";
17
+
18
+ interface User {
19
+ id: number;
20
+ username: string;
21
+ age?: number;
22
+ }
23
+
24
+ // 1. Define your target schema and plan your required/optional keys
25
+ const builder = autoBuilder.returns<User>().plan("id", "username");
26
+
27
+ // 2. Start chaining!
28
+ // The moment the final planned key is provided, the builder returns
29
+ // the finalized object.
30
+ const user = builder.with("id", 1).with("username", "admin");
31
+
32
+ console.log(user.username); // "admin"
33
+ ```
@@ -0,0 +1,21 @@
1
+ type RequiredKeys<T> = {
2
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
3
+ }[keyof T];
4
+ type MissingKeysError<Missing> = {
5
+ "ERROR: Missing required keys in plan": Missing;
6
+ };
7
+ type Remaining<ExpectedKeys extends PropertyKey, Current extends object> = Exclude<ExpectedKeys, keyof Current>;
8
+ type Compute<T> = {
9
+ [K in keyof T]: T[K];
10
+ } & {};
11
+ type StepResult<Target extends object, ExpectedKeys extends keyof Target, NextState extends object> = Remaining<ExpectedKeys, NextState> extends never ? Compute<NextState> : AutoBuilderType<Target, ExpectedKeys, NextState>;
12
+ export interface AutoBuilderType<Target extends object, ExpectedKeys extends keyof Target, Current extends object> {
13
+ with<K extends Remaining<ExpectedKeys, Current>>(key: K, value: Target[K]): StepResult<Target, ExpectedKeys, Compute<Current & Record<K, Target[K]>>>;
14
+ }
15
+ export declare const autoBuilder: {
16
+ returns: <Target extends object>() => {
17
+ plan: <K extends keyof Target>(...keys: K[]) => [RequiredKeys<Target>] extends [K] ? AutoBuilderType<Target, K, {}> : MissingKeysError<Exclude<RequiredKeys<Target>, K>>;
18
+ };
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,KAAK,YAAY,CAAC,CAAC,IAAI;KACpB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;CACpD,CAAC,MAAM,CAAC,CAAC,CAAC;AAGX,KAAK,gBAAgB,CAAC,OAAO,IAAI;IAC/B,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DED
@@ -0,0 +1,30 @@
1
+ // --- Advanced Utility Types ---
2
+ class AutoBuilderImpl {
3
+ targetKeys;
4
+ state;
5
+ constructor(targetKeys, state) {
6
+ this.targetKeys = targetKeys;
7
+ this.state = state;
8
+ }
9
+ with(key, value) {
10
+ const newState = { ...this.state, [key]: value };
11
+ // Check if every key in our plan has been provided
12
+ const hasAllKeys = this.targetKeys.every((k) => k in newState);
13
+ if (hasAllKeys) {
14
+ return newState; // Auto-build triggers!
15
+ }
16
+ return new AutoBuilderImpl(this.targetKeys, newState);
17
+ }
18
+ }
19
+ // --- Entry Point ---
20
+ export const autoBuilder = {
21
+ // Step 1: Explicitly define the target interface (Schema)
22
+ returns: () => ({
23
+ // Step 2: Dynamically infer the chosen keys (The Plan)
24
+ plan: (...keys) => {
25
+ // ^ If required keys are missing, we return a custom Error Interface
26
+ return new AutoBuilderImpl(keys, {});
27
+ },
28
+ }),
29
+ };
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iCAAiC;AA+CjC,MAAM,eAAe;IAMT;IACA;IAFV,YACU,UAA0B,EAC1B,KAAc;QADd,eAAU,GAAV,UAAU,CAAgB;QAC1B,UAAK,GAAL,KAAK,CAAS;IACrB,CAAC;IAEJ,IAAI,CACF,GAAM,EACN,KAAgB;QAEhB,MAAM,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAS,CAAC;QAExD,mDAAmD;QACnD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC;QAE/D,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,QAAQ,CAAC,CAAC,uBAAuB;QAC1C,CAAC;QAED,OAAO,IAAI,eAAe,CAA4B,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAQ,CAAC;IAC1F,CAAC;CACF;AAED,sBAAsB;AAEtB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,0DAA0D;IAC1D,OAAO,EAAE,GAA0B,EAAE,CAAC,CAAC;QACrC,uDAAuD;QACvD,IAAI,EAAE,CACJ,GAAG,IAAS,EAGyC,EAAE;YACvD,qEAAqE;YACrE,OAAO,IAAI,eAAe,CAAgB,IAAI,EAAE,EAAS,CAAQ,CAAC;QACpE,CAAC;KACF,CAAC;CACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "autobuilder-ts",
3
+ "version": "1.0.0",
4
+ "description": "A strongly-typed, auto-building Builder Pattern for TypeScript",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "keywords": [
18
+ "typescript",
19
+ "builder",
20
+ "builder-pattern",
21
+ "fluent-api",
22
+ "type-safe",
23
+ "auto",
24
+ "design",
25
+ "pattern",
26
+ "autobuilder",
27
+ "autobuilder-ts"
28
+ ],
29
+ "homepage": "https://github.com/Xs-and-10s/autobuilder-ts#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/Xs-and-10s/autobuilder-ts/issues"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/Xs-and-10s/autobuilder-ts.git"
36
+ },
37
+ "license": "MIT",
38
+ "author": "Mark Manley",
39
+ "scripts": {
40
+ "build": "tsc",
41
+ "format": "oxfmt --write src tests",
42
+ "lint": "oxlint",
43
+ "lint:fix": "oxlint --fix",
44
+ "lint:watch": "oxlint --watch",
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "prepublishOnly": "npm run format && npm run lint && npm run test && npm run build"
48
+ },
49
+ "devDependencies": {
50
+ "oxfmt": "^0.34.0",
51
+ "oxlint": "^1.49.0",
52
+ "typescript": "^5.9.3",
53
+ "vitest": "^4.0.18"
54
+ }
55
+ }