leoric 2.8.6 → 2.8.8
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 +22 -0
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/bone.js +2 -2
- package/src/data_types.ts +2 -2
- package/src/decorators.js +9 -2
- package/src/decorators.js.map +1 -1
- package/src/decorators.ts +9 -2
- package/src/drivers/abstract/spellbook.js +1 -0
- package/src/drivers/postgres/index.js +7 -6
- package/src/spell.js +5 -2
- package/src/types/abstract_bone.d.ts +1 -1
- package/src/types/common.d.ts +3 -1
package/History.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
2.8.8 / 2022-10-25
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: join query with select columns should include order columns by @cyjake in https://github.com/cyjake/leoric/pull/360
|
|
6
|
+
* docs: support switchable dark theme, at web app level by @cyjake in https://github.com/cyjake/leoric/pull/359
|
|
7
|
+
* fix: @Column() should not tamper parent attributes directly by @cyjake in https://github.com/cyjake/leoric/pull/362
|
|
8
|
+
* fix: bone.update({ deletedAt: null }) and likewise methods should work by @cyjake in https://github.com/cyjake/leoric/pull/363
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.8.7...v2.8.8
|
|
12
|
+
|
|
13
|
+
2.8.7 / 2022-10-11
|
|
14
|
+
==================
|
|
15
|
+
|
|
16
|
+
## What's Changed
|
|
17
|
+
* fix: enable strictNullChecks by @cyjake in https://github.com/cyjake/leoric/pull/357
|
|
18
|
+
* fix: declaration types of realm.query() and static update values by @cyjake in https://github.com/cyjake/leoric/pull/358
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.8.6...v2.8.7
|
|
22
|
+
|
|
1
23
|
2.8.6 / 2022-10-11
|
|
2
24
|
==================
|
|
3
25
|
|
package/index.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export default class Realm {
|
|
|
74
74
|
|
|
75
75
|
escape(value: Literal): string;
|
|
76
76
|
|
|
77
|
-
query<T
|
|
77
|
+
query<T>(sql: string, values?: Array<Literal>, options?: RawQueryOptions & { model?: T }): Promise<{ rows: T extends typeof Bone ? InstanceType<T>[] : Record<string, Literal>[], fields?: Record<string, ColumnMeta>[], affectedRows?: number }>;
|
|
78
78
|
|
|
79
79
|
transaction<T extends (options: { connection: Connection }) => Generator>(callback: T): Promise<GeneratorReturnType<ReturnType<T>>>;
|
|
80
80
|
transaction<T extends (options: { connection: Connection }) => Promise<any>>(callback: T): Promise<ReturnType<T>>;
|
package/package.json
CHANGED
package/src/bone.js
CHANGED
|
@@ -668,7 +668,7 @@ class Bone {
|
|
|
668
668
|
* @public
|
|
669
669
|
* @param {Object} values
|
|
670
670
|
* @param {Object?} options
|
|
671
|
-
* @returns {number} affected rows
|
|
671
|
+
* @returns {Promise<number>} affected rows
|
|
672
672
|
* @memberof Bone
|
|
673
673
|
*/
|
|
674
674
|
async update(values, options = {}) {
|
|
@@ -697,7 +697,7 @@ class Bone {
|
|
|
697
697
|
/**
|
|
698
698
|
* Persist changes on current instance back to database with `UPDATE`.
|
|
699
699
|
* @private
|
|
700
|
-
* @return {number}
|
|
700
|
+
* @return {Promise<number>}
|
|
701
701
|
*/
|
|
702
702
|
async _update(values, options = {}) {
|
|
703
703
|
const Model = this.constructor;
|
package/src/data_types.ts
CHANGED
|
@@ -65,7 +65,7 @@ class STRING extends DataType {
|
|
|
65
65
|
return chunks.join(' ');
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
uncast(value: string | Raw | null): string | Raw {
|
|
68
|
+
uncast(value: string | Raw | null): string | Raw | null {
|
|
69
69
|
if (value == null || value instanceof Raw) return value;
|
|
70
70
|
return '' + value;
|
|
71
71
|
}
|
|
@@ -304,7 +304,7 @@ class DATE extends DataType {
|
|
|
304
304
|
return this._round(value);
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
uncast(value: null | Raw | string | Date | { toDate: () => Date }, _strict?: boolean): string | Date | Raw {
|
|
307
|
+
uncast(value: null | Raw | string | Date | { toDate: () => Date }, _strict?: boolean): string | Date | Raw | null | undefined {
|
|
308
308
|
const originValue = value;
|
|
309
309
|
|
|
310
310
|
// type narrowing doesn't handle `return value` correctly
|
package/src/decorators.js
CHANGED
|
@@ -59,9 +59,16 @@ function Column(options = {}) {
|
|
|
59
59
|
throw new Error(`unknown column options ${options}`);
|
|
60
60
|
// target refers to model prototype, an internal instance of `Bone {}`
|
|
61
61
|
const model = target.constructor;
|
|
62
|
-
|
|
62
|
+
if (!Object.hasOwnProperty('attributes') || !model.attributes) {
|
|
63
|
+
Object.defineProperty(model, 'attributes', {
|
|
64
|
+
value: { ...model.attributes },
|
|
65
|
+
writable: false,
|
|
66
|
+
enumerable: false,
|
|
67
|
+
configurable: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
63
70
|
const { name: columnName, ...restOptions } = options;
|
|
64
|
-
attributes[propertyKey] = { ...restOptions, columnName };
|
|
71
|
+
model.attributes[propertyKey] = { ...restOptions, columnName };
|
|
65
72
|
};
|
|
66
73
|
}
|
|
67
74
|
exports.Column = Column;
|
package/src/decorators.js.map
CHANGED
|
@@ -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;Q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CAAC;QACjC,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,EAAE;YAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;YACvE,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU;gBAAE,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;SACjE;QACD,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;AAZD,8BAYC"}
|
package/src/decorators.ts
CHANGED
|
@@ -54,9 +54,16 @@ export function Column(options: ColumnOption | DATA_TYPE<DataType> | DataType =
|
|
|
54
54
|
|
|
55
55
|
// target refers to model prototype, an internal instance of `Bone {}`
|
|
56
56
|
const model = target.constructor as any;
|
|
57
|
-
|
|
57
|
+
if (!Object.hasOwnProperty('attributes') || !model.attributes) {
|
|
58
|
+
Object.defineProperty(model, 'attributes', {
|
|
59
|
+
value: { ...model.attributes },
|
|
60
|
+
writable: false,
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
58
65
|
const { name: columnName, ...restOptions } = options;
|
|
59
|
-
attributes[propertyKey] = { ...restOptions, columnName };
|
|
66
|
+
model.attributes[propertyKey] = { ...restOptions, columnName };
|
|
60
67
|
};
|
|
61
68
|
}
|
|
62
69
|
|
|
@@ -54,6 +54,7 @@ function createSubspell(spell) {
|
|
|
54
54
|
const { type, qualifiers = [], value } = token;
|
|
55
55
|
if (type == 'id' && qualifiers[0] == baseName) {
|
|
56
56
|
subspell.orders.push([{ type, value }, direction]);
|
|
57
|
+
if (subspell.columns.length > 0) subspell.columns.push({ type, value });
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -109,15 +109,16 @@ class PostgresDriver extends AbstractDriver {
|
|
|
109
109
|
tables = [].concat(tables);
|
|
110
110
|
const text = heresql(`
|
|
111
111
|
SELECT columns.*,
|
|
112
|
-
|
|
112
|
+
constraints.constraint_type
|
|
113
113
|
FROM information_schema.columns AS columns
|
|
114
|
-
|
|
114
|
+
LEFT JOIN information_schema.key_column_usage AS usage
|
|
115
115
|
ON columns.table_catalog = usage.table_catalog
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
AND columns.table_name = usage.table_name
|
|
117
|
+
AND columns.column_name = usage.column_name
|
|
118
|
+
LEFT JOIN information_schema.table_constraints AS constraints
|
|
119
119
|
ON usage.constraint_name = constraints.constraint_name
|
|
120
|
-
|
|
120
|
+
WHERE columns.table_catalog = $1 AND columns.table_name = ANY($2)
|
|
121
|
+
ORDER BY columns.ordinal_position ASC
|
|
121
122
|
`);
|
|
122
123
|
|
|
123
124
|
const { pool } = this;
|
package/src/spell.js
CHANGED
|
@@ -263,13 +263,16 @@ function joinAssociation(spell, BaseModel, baseName, refName, opts = {}) {
|
|
|
263
263
|
* If Model supports soft delete, and deletedAt isn't specified in whereConditions yet, and the table isn't a subquery, append a default where({ deletedAt: null }).
|
|
264
264
|
*/
|
|
265
265
|
function scopeDeletedAt(spell) {
|
|
266
|
-
const { table, whereConditions, Model } = spell;
|
|
266
|
+
const { table, sets, whereConditions, Model } = spell;
|
|
267
267
|
|
|
268
268
|
const { deletedAt } = Model.timestamps;
|
|
269
269
|
|
|
270
270
|
// from subquery
|
|
271
271
|
if (table.type !== 'id') return;
|
|
272
272
|
|
|
273
|
+
// UPDATE users SET deleted_at = NULL WHERE id = 42;
|
|
274
|
+
if (sets && sets[deletedAt] === null) return;
|
|
275
|
+
|
|
273
276
|
// deletedAt already specified
|
|
274
277
|
for (const condition of whereConditions) {
|
|
275
278
|
let found = false;
|
|
@@ -963,7 +966,7 @@ for (const aggregator in AGGREGATOR_MAP) {
|
|
|
963
966
|
value: function Spell_aggregator(name = '*') {
|
|
964
967
|
if (name instanceof Raw) {
|
|
965
968
|
this.$select(Raw.build(`${func.toUpperCase()}(${name}) AS ${aggregator}`));
|
|
966
|
-
return this
|
|
969
|
+
return this;
|
|
967
970
|
}
|
|
968
971
|
if (name !== '*' && parseExpr(name).type !== 'id') {
|
|
969
972
|
throw new Error(`unexpected operand ${name} for ${func.toUpperCase()}()`);
|
|
@@ -32,7 +32,7 @@ export class AbstractBone {
|
|
|
32
32
|
/**
|
|
33
33
|
* The driver that powers the model
|
|
34
34
|
*/
|
|
35
|
-
static driver: AbstractDriver;
|
|
35
|
+
static driver: AbstractDriver | null;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* The connected models structured as `{ [model.name]: model }`, e.g. `Bone.model.Post => Post`
|
package/src/types/common.d.ts
CHANGED
|
@@ -177,7 +177,9 @@ export type WhereConditions<T extends typeof AbstractBone> = {
|
|
|
177
177
|
// https://stackoverflow.com/a/68077021/179691
|
|
178
178
|
export type PickTypeKeys<Obj, Type, T extends keyof Obj = keyof Obj> = ({ [P in keyof Obj]: Obj[P] extends Type ? P : never })[T];
|
|
179
179
|
|
|
180
|
-
export type
|
|
180
|
+
export type NullablePartial<T> = { [P in keyof T]?: T[P] | null };
|
|
181
|
+
|
|
182
|
+
export type Values<T> = NullablePartial<Omit<T, PickTypeKeys<T, Function> | 'isNewRecord' | 'Model' | 'dataValues'>>;
|
|
181
183
|
|
|
182
184
|
export type BoneColumns<T extends typeof AbstractBone, Key extends keyof InstanceType<T> = keyof Values<InstanceType<T>>> = Key;
|
|
183
185
|
|