leoric 2.8.1 → 2.8.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/History.md CHANGED
@@ -1,3 +1,13 @@
1
+ 2.8.2 / 2022-09-13
2
+ ==================
3
+
4
+ ## What's Changed
5
+ * fix: AssociateOptions in HasMany, BelongdsTo decorators by @cyjake in https://github.com/cyjake/leoric/pull/341
6
+ * fix: invokable dataType in decorators should work and dts fix by @JimmyDaddy in https://github.com/cyjake/leoric/pull/342
7
+
8
+
9
+ **Full Changelog**: https://github.com/cyjake/leoric/compare/v2.8.1...v2.8.2
10
+
1
11
  2.8.1 / 2022-08-31
2
12
  ==================
3
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leoric",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "description": "JavaScript Object-relational mapping alchemy",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -25,6 +25,10 @@ interface BaseSequelizeConditions<T extends typeof SequelizeBone> extends QueryO
25
25
  offset?: number;
26
26
  }
27
27
 
28
+ type SequelizeUpdateOptions<T extends typeof SequelizeBone> = BaseSequelizeConditions<T> & {
29
+ fields?: string[];
30
+ }
31
+
28
32
  interface SequelizeConditions<T extends typeof SequelizeBone> extends BaseSequelizeConditions<T> {
29
33
  group?: string | string[] | Raw;
30
34
  having?: WhereConditions<T> | string | { [key:string]: Literal | Literal[] } | Raw;
@@ -165,8 +169,8 @@ export class SequelizeBone extends AbstractBone {
165
169
 
166
170
  static restore<T extends typeof SequelizeBone>(this: T, options: BaseSequelizeConditions<T>): Spell<T, number>;
167
171
 
168
- static update<T extends typeof SequelizeBone>(this: T, values: SetOptions<T>, options: BaseSequelizeConditions<T>): Promise<number>;
169
- static bulkUpdate<T extends typeof SequelizeBone>(this: T, values: SetOptions<T>, options: BaseSequelizeConditions<T>): Spell<T, number>;
172
+ static update<T extends typeof SequelizeBone>(this: T, values: SetOptions<T>, options: SequelizeUpdateOptions<T>): Promise<number>;
173
+ static bulkUpdate<T extends typeof SequelizeBone>(this: T, values: SetOptions<T>, options: SequelizeUpdateOptions<T>): Spell<T, number>;
170
174
 
171
175
  /**
172
176
  * An alias of instance constructor. Some legacy code access model name from instance with `this.Model.name`.
package/src/decorators.js CHANGED
@@ -50,7 +50,7 @@ function Column(options) {
50
50
  options = {};
51
51
  }
52
52
  // target refers to model prototype, an internal instance of `Bone {}`
53
- if (options['prototype'] instanceof data_types_1.DataType)
53
+ if (options['prototype'] instanceof data_types_1.DataType || options instanceof data_types_1.DataType)
54
54
  options = { type: options };
55
55
  if (!('type' in options)) {
56
56
  const tsType = Reflect.getMetadata('design:type', target, propertyKey);
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA0B;AAG1B,2DAA8D;AAC9D,2CAAqD;AAWrD,SAAS,QAAQ,CAAC,MAAM;IACtB,MAAM,EACJ,MAAM,EAAE,OAAO,EACf,IAAI,EACJ,MAAM,EACN,OAAO,GACR,GAAG,oBAAS,CAAC;IAEd,QAAQ,MAAM,EAAE;QACd,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,OAAO,CAAC;QACjB,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;KACxD;AACH,CAAC;AAED,SAAgB,MAAM,CAAC,OAAuD;IAC5E,OAAO,UAAS,MAAY,EAAE,WAAmB;QAC/C,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,OAAO,GAAG,EAAE,CAAC;SACd;QACD,sEAAsE;QACtE,IAAI,OAAO,CAAC,WAAW,CAAC,YAA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AK,CAAC;YACtC,CAAC,WAAW,CAAC,EAAE,OAAO;SACvB,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAA;AACH,CAAC;AARD,0BAQC;AAED,SAAgB,MAAM,CAAC,OAA0B;IAC/C,OAAO,UAAS,MAAY,EAAE,WAAmB;QAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC;QACjC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE;YAC7B,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC;YACrC,CAAC,WAAW,CAAC,EAAE,OAAO;SACvB,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAA;AACH,CAAC;AARD,wBAQC;AAED,SAAgB,SAAS,CAAC,OAA0B;IAClD,OAAO,UAAS,MAAY,EAAE,WAAmB;QAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC;QACjC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE;YAChC,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC;YACxC,CAAC,WAAW,CAAC,EAAE,OAAO;SACvB,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAA;AACH,CAAC;AARD,8BAQC"}
package/src/decorators.ts CHANGED
@@ -42,8 +42,9 @@ export function Column(options?: ColumnOption | DATA_TYPE<DataType> | DataType)
42
42
  if (options == null) {
43
43
  options = {};
44
44
  }
45
+
45
46
  // target refers to model prototype, an internal instance of `Bone {}`
46
- if (options['prototype'] instanceof DataType) options = { type: options as DATA_TYPE<DataType> };
47
+ if (options['prototype'] instanceof DataType || options instanceof DataType) options = { type: options as DATA_TYPE<DataType> };
47
48
 
48
49
  if (!('type' in options)) {
49
50
  const tsType = Reflect.getMetadata('design:type', target, propertyKey);
@@ -2,7 +2,7 @@ import DataTypes, { AbstractDataType, DataType } from "../data_types";
2
2
  import {
3
3
  Pool, Literal, WhereConditions,
4
4
  Collection, ResultSet, InstanceValues, OrderOptions,
5
- QueryOptions, AttributeMeta, AssociateOptions, Values, Connection,
5
+ QueryOptions, AttributeMeta, AssociateOptions, Values, Connection, BulkCreateOptions,
6
6
  } from './common';
7
7
  import { AbstractDriver } from '../drivers';
8
8
  import { Spell } from '../spell';
@@ -119,7 +119,7 @@ export class AbstractBone {
119
119
  /**
120
120
  * Batch INSERT
121
121
  */
122
- static bulkCreate<T extends typeof AbstractBone>(this: T, records: Array<Record<string, Literal>>, options?: QueryOptions): Promise<Array<InstanceType<T>>>;
122
+ static bulkCreate<T extends typeof AbstractBone>(this: T, records: Array<Record<string, Literal>>, options?: BulkCreateOptions): Promise<Array<InstanceType<T>>>;
123
123
 
124
124
  /**
125
125
  * SELECT all rows. In production, when the table is at large, it is not recommended to access records in this way. To iterate over all records, {@link Bone.batch} shall be considered as the better alternative. For tables with soft delete enabled, which means they've got `deletedAt` attribute, use {@link Bone.unscoped} to discard the default scope.
@@ -5,7 +5,7 @@ import { AbstractBone } from './abstract_bone';
5
5
 
6
6
  export type Literal = null | undefined | boolean | number | bigint | string | Date | object | ArrayBuffer;
7
7
 
8
- type BaseValidateArgs = boolean | RegExp | Function | Array<Array<Literal>> | string;
8
+ type BaseValidateArgs = boolean | RegExp | Function | Array<Array<Literal>> | string | Array<Literal>;
9
9
 
10
10
  export type Validator = BaseValidateArgs | {
11
11
  args?: BaseValidateArgs,
@@ -53,12 +53,21 @@ export interface QueryOptions {
53
53
  connection?: Connection;
54
54
  hints?: Array<CommonHintsArgs>;
55
55
  hint?: CommonHintsArgs;
56
- transaction?: Connection;
56
+ transaction?: Connection | {
57
+ connection: Connection
58
+ };
59
+ }
60
+
61
+ export type BulkCreateOptions = QueryOptions & {
62
+ updateOnDuplicate?: string[];
63
+ fields?: string[];
57
64
  }
58
65
 
59
66
  export interface AssociateOptions {
60
67
  className?: string;
61
68
  foreignKey?: string;
69
+ through?: string;
70
+ where?: Record<string, Literal>;
62
71
  }
63
72
 
64
73
  export type command = 'select' | 'insert' | 'bulkInsert' | 'update' | 'delete' | 'upsert';