@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.
- package/README.md +20 -5
- package/bin/index.cjs +1 -4948
- package/bin/index.js +1 -4923
- package/dist/browser/index.cjs +1 -1424
- package/dist/browser/index.d.cts +73 -14
- package/dist/browser/index.d.ts +73 -14
- package/dist/browser/index.js +1 -1359
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +1449 -0
- package/dist/index.d.ts +72 -12
- package/dist/index.js +1 -4723
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -900,7 +900,9 @@ declare class arquebus<M extends Model$2 = Model$2> {
|
|
|
900
900
|
createModel(name: string, options?: ModelOptions): typeof Model$2;
|
|
901
901
|
}
|
|
902
902
|
|
|
903
|
-
declare const BaseModel$1: new (...args: any[]) => any
|
|
903
|
+
declare const BaseModel$1: (new (...args: any[]) => any) & {
|
|
904
|
+
[x: string]: any;
|
|
905
|
+
};
|
|
904
906
|
declare class Model$2 extends BaseModel$1 {
|
|
905
907
|
protected primaryKey: string;
|
|
906
908
|
protected builder: IBuilder<any, any> | null;
|
|
@@ -1049,7 +1051,9 @@ declare class Collection<I extends Model$1> extends Collection$2<I> {
|
|
|
1049
1051
|
[Symbol.iterator]: () => Iterator<I>;
|
|
1050
1052
|
}
|
|
1051
1053
|
|
|
1052
|
-
declare const BaseModel: new (...args: any[]) => any
|
|
1054
|
+
declare const BaseModel: (new (...args: any[]) => any) & {
|
|
1055
|
+
[x: string]: any;
|
|
1056
|
+
};
|
|
1053
1057
|
declare class Model$1 extends BaseModel {
|
|
1054
1058
|
protected primaryKey: string;
|
|
1055
1059
|
protected perPage: number;
|
|
@@ -1348,6 +1352,71 @@ declare class RelationNotFoundError extends BaseError {
|
|
|
1348
1352
|
declare class InvalidArgumentError extends BaseError {
|
|
1349
1353
|
}
|
|
1350
1354
|
|
|
1355
|
+
/**
|
|
1356
|
+
* Helper type to extract instance type from constructor or mixin function
|
|
1357
|
+
*/
|
|
1358
|
+
type Constructor<T = TGeneric> = MixinConstructor<T>;
|
|
1359
|
+
type Mixin<TBase extends Constructor> = (Base: TBase) => Constructor;
|
|
1360
|
+
/**
|
|
1361
|
+
* Helper type to convert union to intersection
|
|
1362
|
+
*/
|
|
1363
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
1364
|
+
/**
|
|
1365
|
+
* Helper type to get static side of a constructor
|
|
1366
|
+
*/
|
|
1367
|
+
type Static<T> = {
|
|
1368
|
+
[K in keyof T]: T[K];
|
|
1369
|
+
};
|
|
1370
|
+
/**
|
|
1371
|
+
* Compose function that merges multiple classes and mixins
|
|
1372
|
+
*
|
|
1373
|
+
* @example
|
|
1374
|
+
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1375
|
+
* return class extends Base {
|
|
1376
|
+
* pluginAttribtue = 'plugin'
|
|
1377
|
+
* pluginMethod () {
|
|
1378
|
+
* return this.pluginAttribtue
|
|
1379
|
+
* }
|
|
1380
|
+
* }
|
|
1381
|
+
* }
|
|
1382
|
+
*
|
|
1383
|
+
* // Base class
|
|
1384
|
+
* class Model {
|
|
1385
|
+
* make () {
|
|
1386
|
+
* console.log('make')
|
|
1387
|
+
* }
|
|
1388
|
+
* pluginMethod (id: string) {
|
|
1389
|
+
* }
|
|
1390
|
+
* }
|
|
1391
|
+
*
|
|
1392
|
+
* class User extends compose(
|
|
1393
|
+
* Model,
|
|
1394
|
+
* SomePlugin,
|
|
1395
|
+
* ) {
|
|
1396
|
+
* relationPosts () {
|
|
1397
|
+
* return 'hasMany Posts'
|
|
1398
|
+
* }
|
|
1399
|
+
* }
|
|
1400
|
+
*
|
|
1401
|
+
* const user = new User()
|
|
1402
|
+
* user.make() // from Model
|
|
1403
|
+
* user.pluginMethod() // from SomePlugin
|
|
1404
|
+
* user.relationPosts() // from User
|
|
1405
|
+
*
|
|
1406
|
+
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1407
|
+
* console.log(user.pluginMethod()) // "plugin"
|
|
1408
|
+
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1409
|
+
*
|
|
1410
|
+
* @param Base
|
|
1411
|
+
* @param mixins
|
|
1412
|
+
* @returns
|
|
1413
|
+
*/
|
|
1414
|
+
declare function compose$1<TBase extends Constructor, TMixins extends Array<Mixin<any> | Constructor>>(Base: TBase, ...mixins: TMixins): Constructor<InstanceType<TBase> & UnionToIntersection<{
|
|
1415
|
+
[K in keyof TMixins]: TMixins[K] extends Mixin<any> ? InstanceType<ReturnType<TMixins[K]>> : TMixins[K] extends Constructor ? InstanceType<TMixins[K]> : never;
|
|
1416
|
+
}[number]>> & UnionToIntersection<{
|
|
1417
|
+
[K in keyof TMixins]: TMixins[K] extends Mixin<any> ? Static<ReturnType<TMixins[K]>> : TMixins[K] extends Constructor ? Static<TMixins[K]> : never;
|
|
1418
|
+
}[number]> & Static<TBase>;
|
|
1419
|
+
|
|
1351
1420
|
declare const now: (format?: string) => string;
|
|
1352
1421
|
declare const getRelationName: (relationMethod: string) => string;
|
|
1353
1422
|
declare const getScopeName: (scopeMethod: string) => string;
|
|
@@ -1365,16 +1434,7 @@ declare const getAttrName: (attrMethod: string) => string;
|
|
|
1365
1434
|
* @returns
|
|
1366
1435
|
*/
|
|
1367
1436
|
declare const tap: <I>(instance: I, callback: (ins: I) => Promise<I> | I) => Promise<I> | I;
|
|
1368
|
-
|
|
1369
|
-
type Mixin<TBase extends MixinConstructor, TReturn extends MixinConstructor> = (base: TBase) => TReturn;
|
|
1370
|
-
/**
|
|
1371
|
-
* Compose functional mixins
|
|
1372
|
-
*
|
|
1373
|
-
* @param Base
|
|
1374
|
-
* @param mixins
|
|
1375
|
-
* @returns
|
|
1376
|
-
*/
|
|
1377
|
-
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]>>>;
|
|
1437
|
+
declare const compose: typeof compose$1;
|
|
1378
1438
|
declare const flattenDeep: (arr: any) => any;
|
|
1379
1439
|
declare const kebabCase: (str: string) => string;
|
|
1380
1440
|
declare const snakeCase: (str: string) => string;
|