type-safe-builder-pattern 0.0.4 → 0.1.5

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.
@@ -0,0 +1,12 @@
1
+ import type { BuilderAddProperty } from "./types";
2
+ type SchemaConstraint = Record<string, unknown>;
3
+ type ObjectBuilderSetFunctionReturnType<Current extends SchemaConstraint, Schema extends SchemaConstraint> = Current extends Schema ? ObjectBuilderHelperWithBuildMethodType<Current, Schema> : ObjectBuilderHelperType<Current, Schema>;
4
+ interface ObjectBuilderHelperType<Current extends SchemaConstraint, Schema extends SchemaConstraint> {
5
+ set: <const Key extends Exclude<keyof Schema, keyof Current> & string, const Value extends Schema[Key], const Next extends object & BuilderAddProperty<Key, Value, Current> = BuilderAddProperty<Key, Value, Current>>(key: Key, value: Value) => ObjectBuilderSetFunctionReturnType<Next, Schema>;
6
+ }
7
+ interface ObjectBuilderHelperWithBuildMethodType<Current extends SchemaConstraint, Schema extends SchemaConstraint> extends ObjectBuilderHelperType<Current, Schema> {
8
+ build: () => Current;
9
+ }
10
+ export declare function objectBuilder<const Schema extends SchemaConstraint>(): ObjectBuilderSetFunctionReturnType<{}, Schema>;
11
+ export {};
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAyB,MAAM,SAAS,CAAC;AAEzE,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD,KAAK,kCAAkC,CACnC,OAAO,SAAS,gBAAgB,EAChC,MAAM,SAAS,gBAAgB,IAC/B,OAAO,SAAS,MAAM,GACpB,sCAAsC,CAAC,OAAO,EAAE,MAAM,CAAC,GACvD,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAE/C,UAAU,uBAAuB,CAC7B,OAAO,SAAS,gBAAgB,EAChC,MAAM,SAAS,gBAAgB;IAE/B,GAAG,EAAE,CACD,KAAK,CAAC,GAAG,SAAS,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,MAAM,EAC/D,KAAK,CAAC,KAAK,SAAS,MAAM,CAAC,GAAG,CAAC,EAC/B,KAAK,CAAC,IAAI,SAAS,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,GAC/D,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,EAE3C,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,KACX,kCAAkC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;CACzD;AAED,UAAU,sCAAsC,CAC5C,OAAO,SAAS,gBAAgB,EAChC,MAAM,SAAS,gBAAgB,CACjC,SAAQ,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC;IAC9C,KAAK,EAAE,MAAM,OAAO,CAAC;CACxB;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,MAAM,SAAS,gBAAgB,oDAElE"}
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ export function objectBuilder() {
4
4
  function objectBuilderHelper(object) {
5
5
  function set(key, value) {
6
6
  return objectBuilderHelper({
7
- ...object,
8
7
  [key]: value,
8
+ ...object,
9
9
  });
10
10
  }
11
11
  function build() {
@@ -0,0 +1,10 @@
1
+ type BuilderDoAddUniqueProperty<KeyLiteral extends string, Value, BuilderObject extends Record<string, unknown> = {}> = {
2
+ [K in keyof BuilderObject]: BuilderObject[K];
3
+ } & Record<KeyLiteral, Value>;
4
+ type BuilderDoAddProperty<KeyLiteral extends string, Value, BuilderObject extends Record<string, unknown> = {}> = BuilderDoAddUniqueProperty<KeyLiteral, Value, KeyLiteral extends keyof BuilderObject ? Omit<BuilderObject, KeyLiteral> : BuilderObject>;
5
+ export type BuilderAddProperty<Key extends string, Value, BuilderObject extends Record<string, unknown> = {}> = string extends Key ? never : PrettifyBuilderObject<BuilderDoAddProperty<Key, Value, BuilderObject>>;
6
+ export type PrettifyBuilderObject<T extends Record<string, unknown>> = {
7
+ [K in keyof T]: T[K];
8
+ } & {};
9
+ export {};
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,0BAA0B,CAC3B,UAAU,SAAS,MAAM,EACzB,KAAK,EACL,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,IAClD;KACC,CAAC,IAAI,MAAM,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC;CAC/C,GAAG,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAE9B,KAAK,oBAAoB,CACrB,UAAU,SAAS,MAAM,EACzB,KAAK,EACL,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,IAClD,0BAA0B,CAC1B,UAAU,EACV,KAAK,EACL,UAAU,SAAS,MAAM,aAAa,GAChC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,GAC/B,aAAa,CACtB,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAC1B,GAAG,SAAS,MAAM,EAClB,KAAK,EACL,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,IAClD,MAAM,SAAS,GAAG,GAChB,KAAK,GACL,qBAAqB,CAAC,oBAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;AAE7E,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAClE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACvB,GAAG,EAAE,CAAC"}
package/dist/types.js CHANGED
@@ -1,2 +1 @@
1
- // declare const BUILDER: unique symbol;
2
1
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "type-safe-builder-pattern",
3
3
  "description": "Implementation of the 'Builder' design pattern in typescript",
4
- "version": "0.0.4",
4
+ "version": "0.1.5",
5
5
  "author": "Romeo Sarkar",
6
6
  "repository": {
7
7
  "type": "git",
@@ -30,7 +30,12 @@
30
30
  "builder",
31
31
  "builder-pattern",
32
32
  "type-safe-builder-pattern",
33
- "type-safe"
33
+ "type-safe",
34
+ "design-patterns",
35
+ "builder-design-pattern",
36
+ "typescript-design-patterns",
37
+ "typescript-wizard",
38
+ "wizard"
34
39
  ],
35
40
  "scripts": {
36
41
  "build": "tsc -p tsconfig.src.json",