@h3ravel/arquebus 0.3.6 → 0.4.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.
@@ -205,6 +205,7 @@ const tap = (instance, callback) => {
205
205
  return result instanceof Promise ? result.then(() => instance) : instance;
206
206
  };
207
207
  const { compose } = mixin_exports;
208
+ const flatten = (arr) => arr.flat();
208
209
  const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
209
210
  const kebabCase = (str) => (0, radashi.trim)((0, radashi.dash)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
210
211
  const snakeCase = (str) => (0, radashi.trim)((0, radashi.snake)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
@@ -1251,6 +1252,7 @@ exports.RelationNotFoundError = RelationNotFoundError;
1251
1252
  exports.compose = compose;
1252
1253
  exports.default = browser_default;
1253
1254
  exports.defineConfig = defineConfig;
1255
+ exports.flatten = flatten;
1254
1256
  exports.flattenDeep = flattenDeep;
1255
1257
  exports.getAttrMethod = getAttrMethod;
1256
1258
  exports.getAttrName = getAttrName;
@@ -213,9 +213,92 @@ declare class Builder<M extends Model$1 = Model$1, R = IModel | ICollection<M>>
213
213
  hydrate(items: any[]): Collection$2<any>;
214
214
  }
215
215
  //#endregion
216
+ //#region src/inspector/types/column.d.ts
217
+ interface Column {
218
+ name: string;
219
+ table: string;
220
+ data_type: string;
221
+ default_value: string | null;
222
+ max_length: number | null;
223
+ numeric_precision: number | null;
224
+ numeric_scale: number | null;
225
+ is_nullable: boolean;
226
+ is_unique: boolean;
227
+ is_primary_key: boolean;
228
+ is_generated: boolean;
229
+ generation_expression?: string | null;
230
+ has_auto_increment: boolean;
231
+ foreign_key_table: string | null;
232
+ foreign_key_column: string | null;
233
+ comment?: string | null;
234
+ schema?: string;
235
+ foreign_key_schema?: string | null;
236
+ collation?: string | null;
237
+ }
238
+ //#endregion
239
+ //#region src/inspector/types/foreign-key.d.ts
240
+ type ForeignKey = {
241
+ table: string;
242
+ column: string;
243
+ foreign_key_table: string;
244
+ foreign_key_column: string;
245
+ foreign_key_schema?: string;
246
+ constraint_name: null | string;
247
+ on_update: null | 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
248
+ on_delete: null | 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
249
+ };
250
+ //#endregion
251
+ //#region src/inspector/types/table.d.ts
252
+ interface Table {
253
+ name: string;
254
+ comment?: string | null;
255
+ schema?: string;
256
+ collation?: string;
257
+ engine?: string;
258
+ owner?: string;
259
+ sql?: string;
260
+ catalog?: string;
261
+ }
262
+ //#endregion
216
263
  //#region types/query-builder.d.ts
217
264
  interface SchemaBuilder extends Knex.SchemaBuilder {
218
265
  [k: string]: any;
266
+ /**
267
+ * Retrieve all tables in the current database.
268
+ */
269
+ tables(): Promise<string[]>;
270
+ /**
271
+ * Retrieve the table info for the given table, or all tables if no table is specified.
272
+ *
273
+ * @param table
274
+ */
275
+ tableInfo(table?: string): Promise<Table | Table[]>;
276
+ /**
277
+ * Retrieve all columns in a given table, or all columns if no table is specified.
278
+ *
279
+ * @param table
280
+ */
281
+ columns(table?: string): Promise<{
282
+ table: string;
283
+ column: string;
284
+ }[]>;
285
+ /**
286
+ * Retrieve all columns from a given table. Returns all columns if table parameter is undefined.
287
+ *
288
+ * @param table
289
+ * @param column
290
+ */
291
+ columnInfo(table?: string, column?: string): Promise<Column[] | Column>;
292
+ /**
293
+ * Retrieve the primary key column for a given table.
294
+ *
295
+ * @param table
296
+ */
297
+ primary(table: string): Promise<string>;
298
+ /**
299
+ * Retrieve all configured foreign key constraints
300
+ */
301
+ foreignKeys(): Promise<ForeignKey>;
219
302
  }
220
303
  interface AsMethod<QB extends AnyQueryBuilder> {
221
304
  (alias: string): QB;
@@ -346,7 +429,7 @@ interface IQueryBuilder<M extends Model$1 | Model = Model$1, R = M[] | M> {
346
429
  take(count: number): this;
347
430
  limit(count: number): this;
348
431
  offset(count: number): this;
349
- pluck<X extends Model$1 = any>(column: string): Promise<ICollection<X>>;
432
+ pluck<X extends Model$1 = any>(column: string): Promise<Array<X>>;
350
433
  chunk(count: number, callback: (rows: M[]) => any): Promise<boolean>;
351
434
  forPage(page: number, perPage?: number): this;
352
435
  paginate<F extends IPaginatorParams>(page?: number, perPage?: number): Promise<IPaginator<M, F>>;
@@ -359,10 +442,13 @@ declare const Inference: {
359
442
  declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inference<M, R> {
360
443
  model: M;
361
444
  schema: SchemaBuilder;
362
- private connector;
445
+ connector: IQueryBuilder<M, R> & Knex.QueryBuilder & {
446
+ _statements: any[];
447
+ _single: any;
448
+ } & Knex;
363
449
  constructor(config: TConfig | null, connector: TFunction);
364
450
  asProxy(): any;
365
- beginTransaction(): Promise<Knex.Transaction<any, any[]> | undefined>;
451
+ beginTransaction(): Promise<Knex.Transaction<any, any[]>>;
366
452
  table<X extends M>(table: string): IQueryBuilder<X, R>;
367
453
  transaction(callback?: TFunction): Promise<Knex.Transaction> | undefined;
368
454
  find(id: string | number, columns?: string[]): Promise<any>;
@@ -386,7 +472,7 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
386
472
  destroy(...args: Parameters<typeof (void 0).connector.destroy>): Promise<number>;
387
473
  get _statements(): IStatement[] & any[];
388
474
  get _single(): any;
389
- get from(): Knex.Table<any, any>;
475
+ get from(): Knex.Table<any, any> & Knex.Table<any, any[]>;
390
476
  }
391
477
  //#endregion
392
478
  //#region src/relations/relation.d.ts
@@ -496,7 +582,7 @@ declare class arquebus<M extends Model$1 = Model$1> {
496
582
  static setConnectorFactory(connectorFactory: typeof Knex$1): void;
497
583
  static getConnectorFactory(): typeof Knex$1;
498
584
  static addConnection(config: TConfig | TBaseConfig, name?: string): void;
499
- static beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]> | undefined>;
585
+ static beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>>;
500
586
  static transaction(callback: TFunction, connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>> | undefined;
501
587
  static table(name: string, connection?: null): IQueryBuilder<Model$1, Model$1 | Model$1[]>;
502
588
  static schema(connection?: null): SchemaBuilder;
@@ -516,7 +602,7 @@ declare class arquebus<M extends Model$1 = Model$1> {
516
602
  * @returns
517
603
  */
518
604
  static autoLoad(addConnection?: boolean): Promise<TBaseConfig>;
519
- beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]> | undefined>;
605
+ beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>>;
520
606
  transaction(callback: TFunction, connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>> | undefined;
521
607
  table(name: string, connection?: null): IQueryBuilder<M, M | M[]>;
522
608
  schema(connection?: null): SchemaBuilder;
@@ -618,6 +704,7 @@ declare const getAttrName: (attrMethod: string) => string;
618
704
  */
619
705
  declare const tap: <I>(instance: I, callback: (ins: I) => Promise<I> | I) => Promise<I> | I;
620
706
  declare const compose: typeof compose$1;
707
+ declare const flatten: <A = any>(arr: A[]) => (A extends readonly (infer InnerArr)[] ? InnerArr : A)[];
621
708
  declare const flattenDeep: (arr: any) => any;
622
709
  declare const kebabCase: (str: string) => string;
623
710
  declare const snakeCase: (str: string) => string;
@@ -1370,4 +1457,4 @@ declare const _default: {
1370
1457
  makePaginator: (model: Model, data: TGeneric) => Paginator<Model, IPaginatorParams>;
1371
1458
  };
1372
1459
  //#endregion
1373
- export { Attribute, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Model, ModelNotFoundError, Paginator, Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
1460
+ export { Attribute, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Model, ModelNotFoundError, Paginator, Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
@@ -213,9 +213,92 @@ declare class Builder<M extends Model$1 = Model$1, R = IModel | ICollection<M>>
213
213
  hydrate(items: any[]): Collection$2<any>;
214
214
  }
215
215
  //#endregion
216
+ //#region src/inspector/types/column.d.ts
217
+ interface Column {
218
+ name: string;
219
+ table: string;
220
+ data_type: string;
221
+ default_value: string | null;
222
+ max_length: number | null;
223
+ numeric_precision: number | null;
224
+ numeric_scale: number | null;
225
+ is_nullable: boolean;
226
+ is_unique: boolean;
227
+ is_primary_key: boolean;
228
+ is_generated: boolean;
229
+ generation_expression?: string | null;
230
+ has_auto_increment: boolean;
231
+ foreign_key_table: string | null;
232
+ foreign_key_column: string | null;
233
+ comment?: string | null;
234
+ schema?: string;
235
+ foreign_key_schema?: string | null;
236
+ collation?: string | null;
237
+ }
238
+ //#endregion
239
+ //#region src/inspector/types/foreign-key.d.ts
240
+ type ForeignKey = {
241
+ table: string;
242
+ column: string;
243
+ foreign_key_table: string;
244
+ foreign_key_column: string;
245
+ foreign_key_schema?: string;
246
+ constraint_name: null | string;
247
+ on_update: null | 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
248
+ on_delete: null | 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
249
+ };
250
+ //#endregion
251
+ //#region src/inspector/types/table.d.ts
252
+ interface Table {
253
+ name: string;
254
+ comment?: string | null;
255
+ schema?: string;
256
+ collation?: string;
257
+ engine?: string;
258
+ owner?: string;
259
+ sql?: string;
260
+ catalog?: string;
261
+ }
262
+ //#endregion
216
263
  //#region types/query-builder.d.ts
217
264
  interface SchemaBuilder extends Knex.SchemaBuilder {
218
265
  [k: string]: any;
266
+ /**
267
+ * Retrieve all tables in the current database.
268
+ */
269
+ tables(): Promise<string[]>;
270
+ /**
271
+ * Retrieve the table info for the given table, or all tables if no table is specified.
272
+ *
273
+ * @param table
274
+ */
275
+ tableInfo(table?: string): Promise<Table | Table[]>;
276
+ /**
277
+ * Retrieve all columns in a given table, or all columns if no table is specified.
278
+ *
279
+ * @param table
280
+ */
281
+ columns(table?: string): Promise<{
282
+ table: string;
283
+ column: string;
284
+ }[]>;
285
+ /**
286
+ * Retrieve all columns from a given table. Returns all columns if table parameter is undefined.
287
+ *
288
+ * @param table
289
+ * @param column
290
+ */
291
+ columnInfo(table?: string, column?: string): Promise<Column[] | Column>;
292
+ /**
293
+ * Retrieve the primary key column for a given table.
294
+ *
295
+ * @param table
296
+ */
297
+ primary(table: string): Promise<string>;
298
+ /**
299
+ * Retrieve all configured foreign key constraints
300
+ */
301
+ foreignKeys(): Promise<ForeignKey>;
219
302
  }
220
303
  interface AsMethod<QB extends AnyQueryBuilder> {
221
304
  (alias: string): QB;
@@ -346,7 +429,7 @@ interface IQueryBuilder<M extends Model$1 | Model = Model$1, R = M[] | M> {
346
429
  take(count: number): this;
347
430
  limit(count: number): this;
348
431
  offset(count: number): this;
349
- pluck<X extends Model$1 = any>(column: string): Promise<ICollection<X>>;
432
+ pluck<X extends Model$1 = any>(column: string): Promise<Array<X>>;
350
433
  chunk(count: number, callback: (rows: M[]) => any): Promise<boolean>;
351
434
  forPage(page: number, perPage?: number): this;
352
435
  paginate<F extends IPaginatorParams>(page?: number, perPage?: number): Promise<IPaginator<M, F>>;
@@ -359,10 +442,13 @@ declare const Inference: {
359
442
  declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inference<M, R> {
360
443
  model: M;
361
444
  schema: SchemaBuilder;
362
- private connector;
445
+ connector: IQueryBuilder<M, R> & Knex.QueryBuilder & {
446
+ _statements: any[];
447
+ _single: any;
448
+ } & Knex;
363
449
  constructor(config: TConfig | null, connector: TFunction);
364
450
  asProxy(): any;
365
- beginTransaction(): Promise<Knex.Transaction<any, any[]> | undefined>;
451
+ beginTransaction(): Promise<Knex.Transaction<any, any[]>>;
366
452
  table<X extends M>(table: string): IQueryBuilder<X, R>;
367
453
  transaction(callback?: TFunction): Promise<Knex.Transaction> | undefined;
368
454
  find(id: string | number, columns?: string[]): Promise<any>;
@@ -386,7 +472,7 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
386
472
  destroy(...args: Parameters<typeof (void 0).connector.destroy>): Promise<number>;
387
473
  get _statements(): IStatement[] & any[];
388
474
  get _single(): any;
389
- get from(): Knex.Table<any, any>;
475
+ get from(): Knex.Table<any, any> & Knex.Table<any, any[]>;
390
476
  }
391
477
  //#endregion
392
478
  //#region src/relations/relation.d.ts
@@ -496,7 +582,7 @@ declare class arquebus<M extends Model$1 = Model$1> {
496
582
  static setConnectorFactory(connectorFactory: typeof Knex$1): void;
497
583
  static getConnectorFactory(): typeof Knex$1;
498
584
  static addConnection(config: TConfig | TBaseConfig, name?: string): void;
499
- static beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]> | undefined>;
585
+ static beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>>;
500
586
  static transaction(callback: TFunction, connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>> | undefined;
501
587
  static table(name: string, connection?: null): IQueryBuilder<Model$1, Model$1 | Model$1[]>;
502
588
  static schema(connection?: null): SchemaBuilder;
@@ -516,7 +602,7 @@ declare class arquebus<M extends Model$1 = Model$1> {
516
602
  * @returns
517
603
  */
518
604
  static autoLoad(addConnection?: boolean): Promise<TBaseConfig>;
519
- beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]> | undefined>;
605
+ beginTransaction(connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>>;
520
606
  transaction(callback: TFunction, connection?: null): Promise<Knex$1.Knex.Transaction<any, any[]>> | undefined;
521
607
  table(name: string, connection?: null): IQueryBuilder<M, M | M[]>;
522
608
  schema(connection?: null): SchemaBuilder;
@@ -618,6 +704,7 @@ declare const getAttrName: (attrMethod: string) => string;
618
704
  */
619
705
  declare const tap: <I>(instance: I, callback: (ins: I) => Promise<I> | I) => Promise<I> | I;
620
706
  declare const compose: typeof compose$1;
707
+ declare const flatten: <A = any>(arr: A[]) => (A extends readonly (infer InnerArr)[] ? InnerArr : A)[];
621
708
  declare const flattenDeep: (arr: any) => any;
622
709
  declare const kebabCase: (str: string) => string;
623
710
  declare const snakeCase: (str: string) => string;
@@ -1370,4 +1457,4 @@ declare const _default: {
1370
1457
  makePaginator: (model: Model, data: TGeneric) => Paginator<Model, IPaginatorParams>;
1371
1458
  };
1372
1459
  //#endregion
1373
- export { Attribute, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Model, ModelNotFoundError, Paginator, Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
1460
+ export { Attribute, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Model, ModelNotFoundError, Paginator, Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
@@ -181,6 +181,7 @@ const tap = (instance, callback) => {
181
181
  return result instanceof Promise ? result.then(() => instance) : instance;
182
182
  };
183
183
  const { compose } = mixin_exports;
184
+ const flatten = (arr) => arr.flat();
184
185
  const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
185
186
  const kebabCase = (str) => trim(dash(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
186
187
  const snakeCase = (str) => trim(snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
@@ -1214,4 +1215,4 @@ var browser_default = {
1214
1215
  };
1215
1216
 
1216
1217
  //#endregion
1217
- export { attribute_default as Attribute, casts_attributes_default as CastsAttributes, collection_default as Collection, has_unique_ids_default as HasUniqueIds, InvalidArgumentError, model_default as Model, ModelNotFoundError, paginator_default as Paginator, pivot_default as Pivot, RelationNotFoundError, compose, browser_default as default, defineConfig, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
1218
+ export { attribute_default as Attribute, casts_attributes_default as CastsAttributes, collection_default as Collection, has_unique_ids_default as HasUniqueIds, InvalidArgumentError, model_default as Model, ModelNotFoundError, paginator_default as Paginator, pivot_default as Pivot, RelationNotFoundError, compose, browser_default as default, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };