@h3ravel/arquebus 0.2.0 → 0.2.2

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.
@@ -843,6 +843,71 @@ declare class RelationNotFoundError extends BaseError {
843
843
  declare class InvalidArgumentError extends BaseError {
844
844
  }
845
845
 
846
+ /**
847
+ * Helper type to extract instance type from constructor or mixin function
848
+ */
849
+ type Constructor<T = TGeneric> = MixinConstructor<T>;
850
+ type Mixin<TBase extends Constructor> = (Base: TBase) => Constructor;
851
+ /**
852
+ * Helper type to convert union to intersection
853
+ */
854
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
855
+ /**
856
+ * Helper type to get static side of a constructor
857
+ */
858
+ type Static<T> = {
859
+ [K in keyof T]: T[K];
860
+ };
861
+ /**
862
+ * Compose function that merges multiple classes and mixins
863
+ *
864
+ * @example
865
+ * const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
866
+ * return class extends Base {
867
+ * pluginAttribtue = 'plugin'
868
+ * pluginMethod () {
869
+ * return this.pluginAttribtue
870
+ * }
871
+ * }
872
+ * }
873
+ *
874
+ * // Base class
875
+ * class Model {
876
+ * make () {
877
+ * console.log('make')
878
+ * }
879
+ * pluginMethod (id: string) {
880
+ * }
881
+ * }
882
+ *
883
+ * class User extends compose(
884
+ * Model,
885
+ * SomePlugin,
886
+ * ) {
887
+ * relationPosts () {
888
+ * return 'hasMany Posts'
889
+ * }
890
+ * }
891
+ *
892
+ * const user = new User()
893
+ * user.make() // from Model
894
+ * user.pluginMethod() // from SomePlugin
895
+ * user.relationPosts() // from User
896
+ *
897
+ * console.log(user.pluginMethod('w')) // "plugin"
898
+ * console.log(user.pluginMethod()) // "plugin"
899
+ * console.log(user.relationPosts()) // "hasMany Posts"
900
+ *
901
+ * @param Base
902
+ * @param mixins
903
+ * @returns
904
+ */
905
+ declare function compose$1<TBase extends Constructor, TMixins extends Array<Mixin<any> | Constructor>>(Base: TBase, ...mixins: TMixins): Constructor<InstanceType<TBase> & UnionToIntersection<{
906
+ [K in keyof TMixins]: TMixins[K] extends Mixin<any> ? InstanceType<ReturnType<TMixins[K]>> : TMixins[K] extends Constructor ? InstanceType<TMixins[K]> : never;
907
+ }[number]>> & UnionToIntersection<{
908
+ [K in keyof TMixins]: TMixins[K] extends Mixin<any> ? Static<ReturnType<TMixins[K]>> : TMixins[K] extends Constructor ? Static<TMixins[K]> : never;
909
+ }[number]> & Static<TBase>;
910
+
846
911
  declare const now: (format?: string) => string;
847
912
  declare const getRelationName: (relationMethod: string) => string;
848
913
  declare const getScopeName: (scopeMethod: string) => string;
@@ -860,16 +925,7 @@ declare const getAttrName: (attrMethod: string) => string;
860
925
  * @returns
861
926
  */
862
927
  declare const tap: <I>(instance: I, callback: (ins: I) => Promise<I> | I) => Promise<I> | I;
863
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
864
- type Mixin<TBase extends MixinConstructor, TReturn extends MixinConstructor> = (base: TBase) => TReturn;
865
- /**
866
- * Compose functional mixins
867
- *
868
- * @param Base
869
- * @param mixins
870
- * @returns
871
- */
872
- declare function compose<MC extends MixinConstructor, P extends Mixin<MC, MixinConstructor>[]>(Base: MC, ...mixins: P): new (...args: any[]) => InstanceType<MC> & UnionToIntersection<InstanceType<ReturnType<P[number]>>>;
928
+ declare const compose: typeof compose$1;
873
929
  declare const flattenDeep: (arr: any) => any;
874
930
  declare const kebabCase: (str: string) => string;
875
931
  declare const snakeCase: (str: string) => string;
@@ -948,7 +1004,9 @@ interface TField {
948
1004
  geometry: TFunction;
949
1005
  }
950
1006
 
951
- declare const BaseModel$1: new (...args: any[]) => any;
1007
+ declare const BaseModel$1: (new (...args: any[]) => any) & {
1008
+ [x: string]: any;
1009
+ };
952
1010
  declare class Model$1 extends BaseModel$1 {
953
1011
  protected primaryKey: string;
954
1012
  protected perPage: number;
@@ -1083,7 +1141,9 @@ interface IPaginator<T extends Model | Model$1, K extends IPaginatorParams = IPa
1083
1141
  };
1084
1142
  }
1085
1143
 
1086
- declare const BaseModel: new (...args: any[]) => any;
1144
+ declare const BaseModel: (new (...args: any[]) => any) & {
1145
+ [x: string]: any;
1146
+ };
1087
1147
  declare class Model extends BaseModel {
1088
1148
  protected primaryKey: string;
1089
1149
  protected builder: IBuilder<any, any> | null;
@@ -1237,7 +1297,6 @@ declare const make: (model: Model$1, data: TGeneric, options?: {
1237
1297
  paginated: IPaginatorParams;
1238
1298
  }) => any;
1239
1299
  declare const makeCollection: (model: Model$1, data: TGeneric) => Collection$1<Model$1>;
1240
- declare const makePaginator: (model: Model$1, data: TGeneric) => Paginator<Model$1, IPaginatorParams>;
1241
1300
  declare const isBrowser = true;
1242
1301
 
1243
1302
  declare const _default: {
@@ -1264,4 +1323,4 @@ declare const _default: {
1264
1323
  makePaginator: (model: Model$1, data: TGeneric) => Paginator<Model$1, IPaginatorParams>;
1265
1324
  };
1266
1325
 
1267
- export { Attribute, CastsAttributes, Collection$1 as Collection, HasUniqueIds, InvalidArgumentError, Model$1 as Model, ModelNotFoundError, Paginator, Pivot$1 as Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
1326
+ export { Attribute, CastsAttributes, Collection$1 as Collection, HasUniqueIds, InvalidArgumentError, Model$1 as Model, ModelNotFoundError, Paginator, Pivot$1 as Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
@@ -843,6 +843,71 @@ declare class RelationNotFoundError extends BaseError {
843
843
  declare class InvalidArgumentError extends BaseError {
844
844
  }
845
845
 
846
+ /**
847
+ * Helper type to extract instance type from constructor or mixin function
848
+ */
849
+ type Constructor<T = TGeneric> = MixinConstructor<T>;
850
+ type Mixin<TBase extends Constructor> = (Base: TBase) => Constructor;
851
+ /**
852
+ * Helper type to convert union to intersection
853
+ */
854
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
855
+ /**
856
+ * Helper type to get static side of a constructor
857
+ */
858
+ type Static<T> = {
859
+ [K in keyof T]: T[K];
860
+ };
861
+ /**
862
+ * Compose function that merges multiple classes and mixins
863
+ *
864
+ * @example
865
+ * const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
866
+ * return class extends Base {
867
+ * pluginAttribtue = 'plugin'
868
+ * pluginMethod () {
869
+ * return this.pluginAttribtue
870
+ * }
871
+ * }
872
+ * }
873
+ *
874
+ * // Base class
875
+ * class Model {
876
+ * make () {
877
+ * console.log('make')
878
+ * }
879
+ * pluginMethod (id: string) {
880
+ * }
881
+ * }
882
+ *
883
+ * class User extends compose(
884
+ * Model,
885
+ * SomePlugin,
886
+ * ) {
887
+ * relationPosts () {
888
+ * return 'hasMany Posts'
889
+ * }
890
+ * }
891
+ *
892
+ * const user = new User()
893
+ * user.make() // from Model
894
+ * user.pluginMethod() // from SomePlugin
895
+ * user.relationPosts() // from User
896
+ *
897
+ * console.log(user.pluginMethod('w')) // "plugin"
898
+ * console.log(user.pluginMethod()) // "plugin"
899
+ * console.log(user.relationPosts()) // "hasMany Posts"
900
+ *
901
+ * @param Base
902
+ * @param mixins
903
+ * @returns
904
+ */
905
+ declare function compose$1<TBase extends Constructor, TMixins extends Array<Mixin<any> | Constructor>>(Base: TBase, ...mixins: TMixins): Constructor<InstanceType<TBase> & UnionToIntersection<{
906
+ [K in keyof TMixins]: TMixins[K] extends Mixin<any> ? InstanceType<ReturnType<TMixins[K]>> : TMixins[K] extends Constructor ? InstanceType<TMixins[K]> : never;
907
+ }[number]>> & UnionToIntersection<{
908
+ [K in keyof TMixins]: TMixins[K] extends Mixin<any> ? Static<ReturnType<TMixins[K]>> : TMixins[K] extends Constructor ? Static<TMixins[K]> : never;
909
+ }[number]> & Static<TBase>;
910
+
846
911
  declare const now: (format?: string) => string;
847
912
  declare const getRelationName: (relationMethod: string) => string;
848
913
  declare const getScopeName: (scopeMethod: string) => string;
@@ -860,16 +925,7 @@ declare const getAttrName: (attrMethod: string) => string;
860
925
  * @returns
861
926
  */
862
927
  declare const tap: <I>(instance: I, callback: (ins: I) => Promise<I> | I) => Promise<I> | I;
863
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
864
- type Mixin<TBase extends MixinConstructor, TReturn extends MixinConstructor> = (base: TBase) => TReturn;
865
- /**
866
- * Compose functional mixins
867
- *
868
- * @param Base
869
- * @param mixins
870
- * @returns
871
- */
872
- declare function compose<MC extends MixinConstructor, P extends Mixin<MC, MixinConstructor>[]>(Base: MC, ...mixins: P): new (...args: any[]) => InstanceType<MC> & UnionToIntersection<InstanceType<ReturnType<P[number]>>>;
928
+ declare const compose: typeof compose$1;
873
929
  declare const flattenDeep: (arr: any) => any;
874
930
  declare const kebabCase: (str: string) => string;
875
931
  declare const snakeCase: (str: string) => string;
@@ -948,7 +1004,9 @@ interface TField {
948
1004
  geometry: TFunction;
949
1005
  }
950
1006
 
951
- declare const BaseModel$1: new (...args: any[]) => any;
1007
+ declare const BaseModel$1: (new (...args: any[]) => any) & {
1008
+ [x: string]: any;
1009
+ };
952
1010
  declare class Model$1 extends BaseModel$1 {
953
1011
  protected primaryKey: string;
954
1012
  protected perPage: number;
@@ -1083,7 +1141,9 @@ interface IPaginator<T extends Model | Model$1, K extends IPaginatorParams = IPa
1083
1141
  };
1084
1142
  }
1085
1143
 
1086
- declare const BaseModel: new (...args: any[]) => any;
1144
+ declare const BaseModel: (new (...args: any[]) => any) & {
1145
+ [x: string]: any;
1146
+ };
1087
1147
  declare class Model extends BaseModel {
1088
1148
  protected primaryKey: string;
1089
1149
  protected builder: IBuilder<any, any> | null;
@@ -1237,7 +1297,6 @@ declare const make: (model: Model$1, data: TGeneric, options?: {
1237
1297
  paginated: IPaginatorParams;
1238
1298
  }) => any;
1239
1299
  declare const makeCollection: (model: Model$1, data: TGeneric) => Collection$1<Model$1>;
1240
- declare const makePaginator: (model: Model$1, data: TGeneric) => Paginator<Model$1, IPaginatorParams>;
1241
1300
  declare const isBrowser = true;
1242
1301
 
1243
1302
  declare const _default: {
@@ -1264,4 +1323,4 @@ declare const _default: {
1264
1323
  makePaginator: (model: Model$1, data: TGeneric) => Paginator<Model$1, IPaginatorParams>;
1265
1324
  };
1266
1325
 
1267
- export { Attribute, CastsAttributes, Collection$1 as Collection, HasUniqueIds, InvalidArgumentError, Model$1 as Model, ModelNotFoundError, Paginator, Pivot$1 as Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
1326
+ export { Attribute, CastsAttributes, Collection$1 as Collection, HasUniqueIds, InvalidArgumentError, Model$1 as Model, ModelNotFoundError, Paginator, Pivot$1 as Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };