type-safe-builder-pattern 0.0.4 → 0.0.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.
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BuilderAddProperty } from "./types";
|
|
2
|
+
type SchemaConstraint = Record<string, unknown>;
|
|
3
|
+
type ObjectBuilderSetFunctionReturnType<T extends SchemaConstraint, Schema extends SchemaConstraint> = T extends Schema ? ObjectBuilderHelperWithBuildMethodType<T, Schema> : ObjectBuilderHelperType<T, Schema>;
|
|
4
|
+
interface ObjectBuilderHelperType<T extends SchemaConstraint, Schema extends SchemaConstraint> {
|
|
5
|
+
set: <const Key extends keyof Schema & string, const Value extends Schema[Key], const U extends object & BuilderAddProperty<Key, Value, T> = BuilderAddProperty<Key, Value, T>>(key: Key, value: Value) => ObjectBuilderSetFunctionReturnType<U, Schema>;
|
|
6
|
+
}
|
|
7
|
+
interface ObjectBuilderHelperWithBuildMethodType<T extends SchemaConstraint, Schema extends SchemaConstraint> extends ObjectBuilderHelperType<T, Schema> {
|
|
8
|
+
build: () => T;
|
|
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,CAAC,SAAS,gBAAgB,EAC1B,MAAM,SAAS,gBAAgB,IAC/B,CAAC,SAAS,MAAM,GACd,sCAAsC,CAAC,CAAC,EAAE,MAAM,CAAC,GACjD,uBAAuB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEzC,UAAU,uBAAuB,CAC7B,CAAC,SAAS,gBAAgB,EAC1B,MAAM,SAAS,gBAAgB;IAE/B,GAAG,EAAE,CACD,KAAK,CAAC,GAAG,SAAS,MAAM,MAAM,GAAG,MAAM,EACvC,KAAK,CAAC,KAAK,SAAS,MAAM,CAAC,GAAG,CAAC,EAC/B,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,GACtD,kBAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAErC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,KACX,kCAAkC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;CACtD;AAED,UAAU,sCAAsC,CAC5C,CAAC,SAAS,gBAAgB,EAC1B,MAAM,SAAS,gBAAgB,CACjC,SAAQ,uBAAuB,CAAC,CAAC,EAAE,MAAM,CAAC;IACxC,KAAK,EAAE,MAAM,CAAC,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,MAAM,SAAS,gBAAgB,oDAElE"}
|
package/dist/types.d.ts
ADDED
|
@@ -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":"AAkBA,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"}
|