@tachybase/database 0.23.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/.turbo/turbo-build.log +10 -0
- package/LICENSE +201 -0
- package/lib/collection-factory.d.ts +17 -0
- package/lib/collection-factory.js +52 -0
- package/lib/collection-group-manager.d.ts +26 -0
- package/lib/collection-group-manager.js +57 -0
- package/lib/collection-importer.d.ts +7 -0
- package/lib/collection-importer.js +74 -0
- package/lib/collection.d.ts +138 -0
- package/lib/collection.js +686 -0
- package/lib/database-utils/index.d.ts +9 -0
- package/lib/database-utils/index.js +71 -0
- package/lib/database-utils/traverseJSON.d.ts +10 -0
- package/lib/database-utils/traverseJSON.js +126 -0
- package/lib/database.d.ts +201 -0
- package/lib/database.js +765 -0
- package/lib/decorators/must-have-filter-decorator.d.ts +2 -0
- package/lib/decorators/must-have-filter-decorator.js +38 -0
- package/lib/decorators/target-collection-decorator.d.ts +2 -0
- package/lib/decorators/target-collection-decorator.js +47 -0
- package/lib/decorators/transaction-decorator.d.ts +1 -0
- package/lib/decorators/transaction-decorator.js +88 -0
- package/lib/eager-loading/eager-loading-tree.d.ts +31 -0
- package/lib/eager-loading/eager-loading-tree.js +439 -0
- package/lib/errors/identifier-error.d.ts +3 -0
- package/lib/errors/identifier-error.js +35 -0
- package/lib/errors/zero-column-table-error.d.ts +2 -0
- package/lib/errors/zero-column-table-error.js +31 -0
- package/lib/features/references-map.d.ts +18 -0
- package/lib/features/references-map.js +109 -0
- package/lib/features/referential-integrity-check.d.ts +8 -0
- package/lib/features/referential-integrity-check.js +83 -0
- package/lib/field-repository/array-field-repository.d.ts +28 -0
- package/lib/field-repository/array-field-repository.js +197 -0
- package/lib/fields/array-field.d.ts +11 -0
- package/lib/fields/array-field.js +57 -0
- package/lib/fields/belongs-to-field.d.ts +17 -0
- package/lib/fields/belongs-to-field.js +154 -0
- package/lib/fields/belongs-to-many-field.d.ts +20 -0
- package/lib/fields/belongs-to-many-field.js +187 -0
- package/lib/fields/boolean-field.d.ts +8 -0
- package/lib/fields/boolean-field.js +36 -0
- package/lib/fields/context-field.d.ts +14 -0
- package/lib/fields/context-field.js +70 -0
- package/lib/fields/date-field.d.ts +13 -0
- package/lib/fields/date-field.js +64 -0
- package/lib/fields/field.d.ts +43 -0
- package/lib/fields/field.js +156 -0
- package/lib/fields/has-inverse-field.d.ts +4 -0
- package/lib/fields/has-inverse-field.js +15 -0
- package/lib/fields/has-many-field.d.ts +68 -0
- package/lib/fields/has-many-field.js +156 -0
- package/lib/fields/has-one-field.d.ts +68 -0
- package/lib/fields/has-one-field.js +150 -0
- package/lib/fields/index.d.ts +46 -0
- package/lib/fields/index.js +65 -0
- package/lib/fields/json-field.d.ts +14 -0
- package/lib/fields/json-field.js +54 -0
- package/lib/fields/nanoid-field.d.ts +13 -0
- package/lib/fields/nanoid-field.js +58 -0
- package/lib/fields/number-field.d.ts +41 -0
- package/lib/fields/number-field.js +85 -0
- package/lib/fields/password-field.d.ts +21 -0
- package/lib/fields/password-field.js +95 -0
- package/lib/fields/radio-field.d.ts +16 -0
- package/lib/fields/radio-field.js +66 -0
- package/lib/fields/relation-field.d.ts +21 -0
- package/lib/fields/relation-field.js +79 -0
- package/lib/fields/set-field.d.ts +10 -0
- package/lib/fields/set-field.js +46 -0
- package/lib/fields/sort-field.d.ts +16 -0
- package/lib/fields/sort-field.js +187 -0
- package/lib/fields/string-field.d.ts +8 -0
- package/lib/fields/string-field.js +36 -0
- package/lib/fields/text-field.d.ts +8 -0
- package/lib/fields/text-field.js +36 -0
- package/lib/fields/time-field.d.ts +8 -0
- package/lib/fields/time-field.js +36 -0
- package/lib/fields/uid-field.d.ts +13 -0
- package/lib/fields/uid-field.js +63 -0
- package/lib/fields/uuid-field.d.ts +9 -0
- package/lib/fields/uuid-field.js +45 -0
- package/lib/fields/virtual-field.d.ts +8 -0
- package/lib/fields/virtual-field.js +36 -0
- package/lib/filter-match.d.ts +1 -0
- package/lib/filter-match.js +66 -0
- package/lib/filter-parser.d.ts +21 -0
- package/lib/filter-parser.js +230 -0
- package/lib/helpers.d.ts +3 -0
- package/lib/helpers.js +167 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +114 -0
- package/lib/inherited-collection.d.ts +14 -0
- package/lib/inherited-collection.js +138 -0
- package/lib/inherited-map.d.ts +21 -0
- package/lib/inherited-map.js +113 -0
- package/lib/inherited-sync-runner.d.ts +4 -0
- package/lib/inherited-sync-runner.js +175 -0
- package/lib/listeners/adjacency-list.d.ts +2 -0
- package/lib/listeners/adjacency-list.js +42 -0
- package/lib/listeners/append-child-collection-name-after-repository-find.d.ts +6 -0
- package/lib/listeners/append-child-collection-name-after-repository-find.js +66 -0
- package/lib/listeners/index.d.ts +2 -0
- package/lib/listeners/index.js +33 -0
- package/lib/magic-attribute-model.d.ts +8 -0
- package/lib/magic-attribute-model.js +203 -0
- package/lib/migration.d.ts +35 -0
- package/lib/migration.js +103 -0
- package/lib/mock-database.d.ts +25 -0
- package/lib/mock-database.js +126 -0
- package/lib/model-hook.d.ts +12 -0
- package/lib/model-hook.js +92 -0
- package/lib/model.d.ts +23 -0
- package/lib/model.js +152 -0
- package/lib/operators/array.d.ts +2 -0
- package/lib/operators/array.js +158 -0
- package/lib/operators/association.d.ts +2 -0
- package/lib/operators/association.js +35 -0
- package/lib/operators/boolean.d.ts +2 -0
- package/lib/operators/boolean.js +38 -0
- package/lib/operators/child-collection.d.ts +2 -0
- package/lib/operators/child-collection.js +67 -0
- package/lib/operators/date.d.ts +2 -0
- package/lib/operators/date.js +140 -0
- package/lib/operators/empty.d.ts +5 -0
- package/lib/operators/empty.js +89 -0
- package/lib/operators/eq.d.ts +2 -0
- package/lib/operators/eq.js +35 -0
- package/lib/operators/index.d.ts +5 -0
- package/lib/operators/index.js +56 -0
- package/lib/operators/jsonb.d.ts +2 -0
- package/lib/operators/jsonb.js +50 -0
- package/lib/operators/ne.d.ts +2 -0
- package/lib/operators/ne.js +40 -0
- package/lib/operators/notIn.d.ts +2 -0
- package/lib/operators/notIn.js +33 -0
- package/lib/operators/string.d.ts +2 -0
- package/lib/operators/string.js +109 -0
- package/lib/operators/utils.d.ts +4 -0
- package/lib/operators/utils.js +40 -0
- package/lib/options-parser.d.ts +37 -0
- package/lib/options-parser.js +332 -0
- package/lib/playground.d.ts +1 -0
- package/lib/playground.js +43 -0
- package/lib/query-interface/mysql-query-interface.d.ts +35 -0
- package/lib/query-interface/mysql-query-interface.js +122 -0
- package/lib/query-interface/postgres-query-interface.d.ts +32 -0
- package/lib/query-interface/postgres-query-interface.js +189 -0
- package/lib/query-interface/query-interface-builder.d.ts +2 -0
- package/lib/query-interface/query-interface-builder.js +46 -0
- package/lib/query-interface/query-interface.d.ts +42 -0
- package/lib/query-interface/query-interface.js +46 -0
- package/lib/query-interface/sqlite-query-interface.d.ts +35 -0
- package/lib/query-interface/sqlite-query-interface.js +131 -0
- package/lib/relation-repository/belongs-to-many-repository.d.ts +21 -0
- package/lib/relation-repository/belongs-to-many-repository.js +280 -0
- package/lib/relation-repository/belongs-to-repository.d.ts +6 -0
- package/lib/relation-repository/belongs-to-repository.js +39 -0
- package/lib/relation-repository/hasmany-repository.d.ts +10 -0
- package/lib/relation-repository/hasmany-repository.js +182 -0
- package/lib/relation-repository/hasone-repository.d.ts +6 -0
- package/lib/relation-repository/hasone-repository.js +39 -0
- package/lib/relation-repository/multiple-relation-repository.d.ts +20 -0
- package/lib/relation-repository/multiple-relation-repository.js +229 -0
- package/lib/relation-repository/relation-repository.d.ts +29 -0
- package/lib/relation-repository/relation-repository.js +202 -0
- package/lib/relation-repository/single-relation-repository.d.ts +25 -0
- package/lib/relation-repository/single-relation-repository.js +162 -0
- package/lib/relation-repository/types.d.ts +7 -0
- package/lib/relation-repository/types.js +15 -0
- package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +18 -0
- package/lib/repositories/tree-repository/adjacency-list-repository.js +183 -0
- package/lib/repositories/view-repository.d.ts +3 -0
- package/lib/repositories/view-repository.js +32 -0
- package/lib/repository.d.ts +206 -0
- package/lib/repository.js +597 -0
- package/lib/sql-collection/index.d.ts +2 -0
- package/lib/sql-collection/index.js +23 -0
- package/lib/sql-collection/query-generator.d.ts +10 -0
- package/lib/sql-collection/query-generator.js +70 -0
- package/lib/sql-collection/sql-collection.d.ts +7 -0
- package/lib/sql-collection/sql-collection.js +69 -0
- package/lib/sql-collection/sql-model.d.ts +16 -0
- package/lib/sql-collection/sql-model.js +168 -0
- package/lib/sql-parser/index.d.ts +10 -0
- package/lib/sql-parser/index.js +10699 -0
- package/lib/sql-parser/postgres.d.ts +10 -0
- package/lib/sql-parser/postgres.js +31506 -0
- package/lib/sql-parser/sql.pegjs +1297 -0
- package/lib/sync-runner.d.ts +30 -0
- package/lib/sync-runner.js +277 -0
- package/lib/types.d.ts +49 -0
- package/lib/types.js +15 -0
- package/lib/update-associations.d.ts +60 -0
- package/lib/update-associations.js +405 -0
- package/lib/update-guard.d.ts +28 -0
- package/lib/update-guard.js +202 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +127 -0
- package/lib/value-parsers/array-value-parser.d.ts +8 -0
- package/lib/value-parsers/array-value-parser.js +58 -0
- package/lib/value-parsers/base-value-parser.d.ts +12 -0
- package/lib/value-parsers/base-value-parser.js +63 -0
- package/lib/value-parsers/boolean-value-parser.d.ts +4 -0
- package/lib/value-parsers/boolean-value-parser.js +52 -0
- package/lib/value-parsers/date-value-parser.d.ts +5 -0
- package/lib/value-parsers/date-value-parser.js +88 -0
- package/lib/value-parsers/index.d.ts +12 -0
- package/lib/value-parsers/index.js +78 -0
- package/lib/value-parsers/json-value-parser.d.ts +4 -0
- package/lib/value-parsers/json-value-parser.js +47 -0
- package/lib/value-parsers/number-value-parser.d.ts +4 -0
- package/lib/value-parsers/number-value-parser.js +58 -0
- package/lib/value-parsers/string-value-parser.d.ts +8 -0
- package/lib/value-parsers/string-value-parser.js +64 -0
- package/lib/value-parsers/to-many-value-parser.d.ts +13 -0
- package/lib/value-parsers/to-many-value-parser.js +108 -0
- package/lib/value-parsers/to-one-value-parser.d.ts +4 -0
- package/lib/value-parsers/to-one-value-parser.js +48 -0
- package/lib/view/field-type-map.d.ts +97 -0
- package/lib/view/field-type-map.js +90 -0
- package/lib/view/view-inference.d.ts +32 -0
- package/lib/view/view-inference.js +146 -0
- package/lib/view-collection.d.ts +6 -0
- package/lib/view-collection.js +45 -0
- package/package.json +38 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var set_field_exports = {};
|
|
20
|
+
__export(set_field_exports, {
|
|
21
|
+
SetField: () => SetField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(set_field_exports);
|
|
24
|
+
var import_array_field = require("./array-field");
|
|
25
|
+
const _SetField = class _SetField extends import_array_field.ArrayField {
|
|
26
|
+
beforeSave = /* @__PURE__ */ __name((model) => {
|
|
27
|
+
const oldValue = model.get(this.options.name);
|
|
28
|
+
if (oldValue) {
|
|
29
|
+
model.set(this.options.name, [...new Set(oldValue)]);
|
|
30
|
+
}
|
|
31
|
+
}, "beforeSave");
|
|
32
|
+
bind() {
|
|
33
|
+
super.bind();
|
|
34
|
+
this.on("beforeSave", this.beforeSave);
|
|
35
|
+
}
|
|
36
|
+
unbind() {
|
|
37
|
+
super.unbind();
|
|
38
|
+
this.off("beforeSave", this.beforeSave);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
__name(_SetField, "SetField");
|
|
42
|
+
let SetField = _SetField;
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
SetField
|
|
46
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field } from './field';
|
|
3
|
+
export declare class SortField extends Field {
|
|
4
|
+
get dataType(): DataTypes.BigIntDataTypeConstructor;
|
|
5
|
+
setSortValue: (instance: any, options: any) => Promise<void>;
|
|
6
|
+
onScopeChange: (instance: any, options: any) => Promise<void>;
|
|
7
|
+
initRecordsSortValue: ({ transaction }: {
|
|
8
|
+
transaction: any;
|
|
9
|
+
}) => Promise<void>;
|
|
10
|
+
bind(): void;
|
|
11
|
+
unbind(): void;
|
|
12
|
+
}
|
|
13
|
+
export interface SortFieldOptions extends BaseColumnFieldOptions {
|
|
14
|
+
type: 'sort';
|
|
15
|
+
scopeKey?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sort_field_exports = {};
|
|
20
|
+
__export(sort_field_exports, {
|
|
21
|
+
SortField: () => SortField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sort_field_exports);
|
|
24
|
+
var import_async_mutex = require("async-mutex");
|
|
25
|
+
var import_lodash = require("lodash");
|
|
26
|
+
var import_sequelize = require("sequelize");
|
|
27
|
+
var import_field = require("./field");
|
|
28
|
+
const sortFieldMutex = new import_async_mutex.Mutex();
|
|
29
|
+
const _SortField = class _SortField extends import_field.Field {
|
|
30
|
+
get dataType() {
|
|
31
|
+
return import_sequelize.DataTypes.BIGINT;
|
|
32
|
+
}
|
|
33
|
+
setSortValue = /* @__PURE__ */ __name(async (instance, options) => {
|
|
34
|
+
const { name, scopeKey } = this.options;
|
|
35
|
+
const { model } = this.context.collection;
|
|
36
|
+
if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const where = {};
|
|
40
|
+
if (scopeKey) {
|
|
41
|
+
const value = instance.get(scopeKey);
|
|
42
|
+
if (value !== void 0 && value !== null) {
|
|
43
|
+
where[scopeKey] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await sortFieldMutex.runExclusive(async () => {
|
|
47
|
+
const max = await model.max(name, { ...options, where });
|
|
48
|
+
const newValue = (max || 0) + 1;
|
|
49
|
+
instance.set(name, newValue);
|
|
50
|
+
});
|
|
51
|
+
}, "setSortValue");
|
|
52
|
+
onScopeChange = /* @__PURE__ */ __name(async (instance, options) => {
|
|
53
|
+
const { scopeKey } = this.options;
|
|
54
|
+
if (scopeKey && !instance.isNewRecord && instance._previousDataValues[scopeKey] != instance[scopeKey]) {
|
|
55
|
+
await this.setSortValue(instance, options);
|
|
56
|
+
}
|
|
57
|
+
}, "onScopeChange");
|
|
58
|
+
initRecordsSortValue = /* @__PURE__ */ __name(async ({ transaction }) => {
|
|
59
|
+
const orderField = (() => {
|
|
60
|
+
const model = this.collection.model;
|
|
61
|
+
if (model.primaryKeyAttribute) {
|
|
62
|
+
return model.primaryKeyAttribute;
|
|
63
|
+
}
|
|
64
|
+
if (model.rawAttributes["createdAt"]) {
|
|
65
|
+
return model.rawAttributes["createdAt"].field;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`can not find order key for collection ${this.collection.name}`);
|
|
68
|
+
})();
|
|
69
|
+
const needInit = /* @__PURE__ */ __name(async (scopeKey2 = null, scopeValue = null) => {
|
|
70
|
+
const filter = {};
|
|
71
|
+
if (scopeKey2 && scopeValue) {
|
|
72
|
+
filter[scopeKey2] = scopeValue;
|
|
73
|
+
}
|
|
74
|
+
const totalCount = await this.collection.repository.count({
|
|
75
|
+
filter,
|
|
76
|
+
transaction
|
|
77
|
+
});
|
|
78
|
+
const emptyCount = await this.collection.repository.count({
|
|
79
|
+
filter: {
|
|
80
|
+
[this.name]: null,
|
|
81
|
+
...filter
|
|
82
|
+
},
|
|
83
|
+
transaction
|
|
84
|
+
});
|
|
85
|
+
return emptyCount === totalCount && emptyCount > 0;
|
|
86
|
+
}, "needInit");
|
|
87
|
+
const doInit = /* @__PURE__ */ __name(async (scopeKey2 = null, scopeValue = null) => {
|
|
88
|
+
const queryInterface = this.collection.db.sequelize.getQueryInterface();
|
|
89
|
+
if (scopeKey2) {
|
|
90
|
+
const scopeAttribute = this.collection.model.rawAttributes[scopeKey2];
|
|
91
|
+
if (!scopeAttribute) {
|
|
92
|
+
throw new Error(`can not find scope field ${scopeKey2} for collection ${this.collection.name}`);
|
|
93
|
+
}
|
|
94
|
+
scopeKey2 = scopeAttribute.field;
|
|
95
|
+
}
|
|
96
|
+
const quotedOrderField = queryInterface.quoteIdentifier(orderField);
|
|
97
|
+
const sortColumnName = queryInterface.quoteIdentifier(this.collection.model.rawAttributes[this.name].field);
|
|
98
|
+
let sql;
|
|
99
|
+
const whereClause = scopeKey2 && scopeValue ? (() => {
|
|
100
|
+
const filteredScopeValue = scopeValue.filter((v) => v !== null);
|
|
101
|
+
if (filteredScopeValue.length === 0) {
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
const initialClause = `
|
|
105
|
+
WHERE ${queryInterface.quoteIdentifier(scopeKey2)} IN (${filteredScopeValue.map((v) => `'${v}'`).join(", ")})`;
|
|
106
|
+
const nullCheck = scopeValue.includes(null) ? ` OR ${queryInterface.quoteIdentifier(scopeKey2)} IS NULL` : "";
|
|
107
|
+
return initialClause + nullCheck;
|
|
108
|
+
})() : "";
|
|
109
|
+
if (this.collection.db.inDialect("postgres")) {
|
|
110
|
+
sql = `
|
|
111
|
+
UPDATE ${this.collection.quotedTableName()}
|
|
112
|
+
SET ${sortColumnName} = ordered_table.new_sequence_number
|
|
113
|
+
FROM (
|
|
114
|
+
SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
|
|
115
|
+
FROM ${this.collection.quotedTableName()}
|
|
116
|
+
${whereClause}
|
|
117
|
+
) AS ordered_table
|
|
118
|
+
WHERE ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField};
|
|
119
|
+
`;
|
|
120
|
+
} else if (this.collection.db.inDialect("sqlite")) {
|
|
121
|
+
sql = `
|
|
122
|
+
UPDATE ${this.collection.quotedTableName()}
|
|
123
|
+
SET ${sortColumnName} = (
|
|
124
|
+
SELECT new_sequence_number
|
|
125
|
+
FROM (
|
|
126
|
+
SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
|
|
127
|
+
FROM ${this.collection.quotedTableName()}
|
|
128
|
+
${whereClause}
|
|
129
|
+
) AS ordered_table
|
|
130
|
+
WHERE ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField}
|
|
131
|
+
);
|
|
132
|
+
`;
|
|
133
|
+
} else if (this.collection.db.inDialect("mysql") || this.collection.db.inDialect("mariadb")) {
|
|
134
|
+
sql = `
|
|
135
|
+
UPDATE ${this.collection.quotedTableName()}
|
|
136
|
+
JOIN (
|
|
137
|
+
SELECT *, ROW_NUMBER() OVER (${scopeKey2 ? `PARTITION BY ${queryInterface.quoteIdentifier(scopeKey2)}` : ""} ORDER BY ${quotedOrderField}) AS new_sequence_number
|
|
138
|
+
FROM ${this.collection.quotedTableName()}
|
|
139
|
+
${whereClause}
|
|
140
|
+
) AS ordered_table ON ${this.collection.quotedTableName()}.${quotedOrderField} = ordered_table.${quotedOrderField}
|
|
141
|
+
SET ${this.collection.quotedTableName()}.${sortColumnName} = ordered_table.new_sequence_number;
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
await this.collection.db.sequelize.query(sql, {
|
|
145
|
+
transaction
|
|
146
|
+
});
|
|
147
|
+
}, "doInit");
|
|
148
|
+
const scopeKey = this.options.scopeKey;
|
|
149
|
+
if (scopeKey) {
|
|
150
|
+
const groups = await this.collection.repository.find({
|
|
151
|
+
attributes: [scopeKey],
|
|
152
|
+
group: [scopeKey],
|
|
153
|
+
raw: true,
|
|
154
|
+
transaction
|
|
155
|
+
});
|
|
156
|
+
const needInitGroups = [];
|
|
157
|
+
for (const group of groups) {
|
|
158
|
+
if (await needInit(scopeKey, group[scopeKey])) {
|
|
159
|
+
needInitGroups.push(group[scopeKey]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (needInitGroups.length > 0) {
|
|
163
|
+
await doInit(scopeKey, needInitGroups);
|
|
164
|
+
}
|
|
165
|
+
} else if (await needInit()) {
|
|
166
|
+
await doInit();
|
|
167
|
+
}
|
|
168
|
+
}, "initRecordsSortValue");
|
|
169
|
+
bind() {
|
|
170
|
+
super.bind();
|
|
171
|
+
this.on("afterSync", this.initRecordsSortValue);
|
|
172
|
+
this.on("beforeUpdate", this.onScopeChange);
|
|
173
|
+
this.on("beforeCreate", this.setSortValue);
|
|
174
|
+
}
|
|
175
|
+
unbind() {
|
|
176
|
+
super.unbind();
|
|
177
|
+
this.off("beforeUpdate", this.onScopeChange);
|
|
178
|
+
this.off("beforeCreate", this.setSortValue);
|
|
179
|
+
this.off("afterSync", this.initRecordsSortValue);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
__name(_SortField, "SortField");
|
|
183
|
+
let SortField = _SortField;
|
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
185
|
+
0 && (module.exports = {
|
|
186
|
+
SortField
|
|
187
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field } from './field';
|
|
3
|
+
export declare class StringField extends Field {
|
|
4
|
+
get dataType(): DataTypes.StringDataTypeConstructor;
|
|
5
|
+
}
|
|
6
|
+
export interface StringFieldOptions extends BaseColumnFieldOptions {
|
|
7
|
+
type: 'string';
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var string_field_exports = {};
|
|
20
|
+
__export(string_field_exports, {
|
|
21
|
+
StringField: () => StringField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(string_field_exports);
|
|
24
|
+
var import_sequelize = require("sequelize");
|
|
25
|
+
var import_field = require("./field");
|
|
26
|
+
const _StringField = class _StringField extends import_field.Field {
|
|
27
|
+
get dataType() {
|
|
28
|
+
return import_sequelize.DataTypes.STRING;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
__name(_StringField, "StringField");
|
|
32
|
+
let StringField = _StringField;
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
StringField
|
|
36
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field } from './field';
|
|
3
|
+
export declare class TextField extends Field {
|
|
4
|
+
get dataType(): DataTypes.TextDataTypeConstructor;
|
|
5
|
+
}
|
|
6
|
+
export interface TextFieldOptions extends BaseColumnFieldOptions {
|
|
7
|
+
type: 'text';
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var text_field_exports = {};
|
|
20
|
+
__export(text_field_exports, {
|
|
21
|
+
TextField: () => TextField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(text_field_exports);
|
|
24
|
+
var import_sequelize = require("sequelize");
|
|
25
|
+
var import_field = require("./field");
|
|
26
|
+
const _TextField = class _TextField extends import_field.Field {
|
|
27
|
+
get dataType() {
|
|
28
|
+
return import_sequelize.DataTypes.TEXT;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
__name(_TextField, "TextField");
|
|
32
|
+
let TextField = _TextField;
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
TextField
|
|
36
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field } from './field';
|
|
3
|
+
export declare class TimeField extends Field {
|
|
4
|
+
get dataType(): DataTypes.AbstractDataTypeConstructor;
|
|
5
|
+
}
|
|
6
|
+
export interface TimeFieldOptions extends BaseColumnFieldOptions {
|
|
7
|
+
type: 'time';
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var time_field_exports = {};
|
|
20
|
+
__export(time_field_exports, {
|
|
21
|
+
TimeField: () => TimeField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(time_field_exports);
|
|
24
|
+
var import_sequelize = require("sequelize");
|
|
25
|
+
var import_field = require("./field");
|
|
26
|
+
const _TimeField = class _TimeField extends import_field.Field {
|
|
27
|
+
get dataType() {
|
|
28
|
+
return import_sequelize.DataTypes.TIME;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
__name(_TimeField, "TimeField");
|
|
32
|
+
let TimeField = _TimeField;
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
TimeField
|
|
36
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field } from './field';
|
|
3
|
+
export declare class UidField extends Field {
|
|
4
|
+
get dataType(): DataTypes.StringDataTypeConstructor;
|
|
5
|
+
init(): void;
|
|
6
|
+
bind(): void;
|
|
7
|
+
unbind(): void;
|
|
8
|
+
}
|
|
9
|
+
export interface UidFieldOptions extends BaseColumnFieldOptions {
|
|
10
|
+
type: 'uid';
|
|
11
|
+
prefix?: string;
|
|
12
|
+
pattern?: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var uid_field_exports = {};
|
|
20
|
+
__export(uid_field_exports, {
|
|
21
|
+
UidField: () => UidField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(uid_field_exports);
|
|
24
|
+
var import_utils = require("@tachybase/utils");
|
|
25
|
+
var import_sequelize = require("sequelize");
|
|
26
|
+
var import_field = require("./field");
|
|
27
|
+
const _UidField = class _UidField extends import_field.Field {
|
|
28
|
+
get dataType() {
|
|
29
|
+
return import_sequelize.DataTypes.STRING;
|
|
30
|
+
}
|
|
31
|
+
init() {
|
|
32
|
+
const { name, prefix = "", pattern } = this.options;
|
|
33
|
+
const re = new RegExp(pattern || "^[A-Za-z0-9_][A-Za-z0-9_-]*$");
|
|
34
|
+
this.listener = async (instance) => {
|
|
35
|
+
const value = instance.get(name);
|
|
36
|
+
if (!value) {
|
|
37
|
+
instance.set(name, `${prefix}${(0, import_utils.uid)()}`);
|
|
38
|
+
} else if (re.test(value)) {
|
|
39
|
+
instance.set(name, value);
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`${this.collection.name}.${this.options.name} can only include A-Z, a-z, 0-9, _-*$, '${value}' is invalid`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
bind() {
|
|
48
|
+
super.bind();
|
|
49
|
+
this.on("beforeCreate", this.listener);
|
|
50
|
+
this.on("beforeUpdate", this.listener);
|
|
51
|
+
}
|
|
52
|
+
unbind() {
|
|
53
|
+
super.unbind();
|
|
54
|
+
this.off("beforeCreate", this.listener);
|
|
55
|
+
this.off("beforeUpdate", this.listener);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
__name(_UidField, "UidField");
|
|
59
|
+
let UidField = _UidField;
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
UidField
|
|
63
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field, FieldContext } from './field';
|
|
3
|
+
export declare class UuidField extends Field {
|
|
4
|
+
constructor(options?: any, context?: FieldContext);
|
|
5
|
+
get dataType(): DataTypes.AbstractDataTypeConstructor;
|
|
6
|
+
}
|
|
7
|
+
export interface UUIDFieldOptions extends BaseColumnFieldOptions {
|
|
8
|
+
type: 'uuid';
|
|
9
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var uuid_field_exports = {};
|
|
20
|
+
__export(uuid_field_exports, {
|
|
21
|
+
UuidField: () => UuidField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(uuid_field_exports);
|
|
24
|
+
var import_sequelize = require("sequelize");
|
|
25
|
+
var import_field = require("./field");
|
|
26
|
+
const _UuidField = class _UuidField extends import_field.Field {
|
|
27
|
+
constructor(options, context) {
|
|
28
|
+
super(
|
|
29
|
+
{
|
|
30
|
+
defaultValue: new import_sequelize.DataTypes.UUIDV4(),
|
|
31
|
+
...options
|
|
32
|
+
},
|
|
33
|
+
context
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
get dataType() {
|
|
37
|
+
return import_sequelize.DataTypes.UUID;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
__name(_UuidField, "UuidField");
|
|
41
|
+
let UuidField = _UuidField;
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
UuidField
|
|
45
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataTypes } from 'sequelize';
|
|
2
|
+
import { BaseColumnFieldOptions, Field } from './field';
|
|
3
|
+
export declare class VirtualField extends Field {
|
|
4
|
+
get dataType(): DataTypes.VirtualDataTypeConstructor;
|
|
5
|
+
}
|
|
6
|
+
export interface VirtualFieldOptions extends BaseColumnFieldOptions {
|
|
7
|
+
type: 'virtual';
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var virtual_field_exports = {};
|
|
20
|
+
__export(virtual_field_exports, {
|
|
21
|
+
VirtualField: () => VirtualField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(virtual_field_exports);
|
|
24
|
+
var import_sequelize = require("sequelize");
|
|
25
|
+
var import_field = require("./field");
|
|
26
|
+
const _VirtualField = class _VirtualField extends import_field.Field {
|
|
27
|
+
get dataType() {
|
|
28
|
+
return import_sequelize.DataTypes.VIRTUAL;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
__name(_VirtualField, "VirtualField");
|
|
32
|
+
let VirtualField = _VirtualField;
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
VirtualField
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filterMatch(model: any, where: any): boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var filter_match_exports = {};
|
|
20
|
+
__export(filter_match_exports, {
|
|
21
|
+
filterMatch: () => filterMatch
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(filter_match_exports);
|
|
24
|
+
var import_mathjs = require("mathjs");
|
|
25
|
+
function filterMatch(model, where) {
|
|
26
|
+
if (where.filter !== void 0) {
|
|
27
|
+
where = import_mathjs.filter;
|
|
28
|
+
}
|
|
29
|
+
const operatorFunctions = {
|
|
30
|
+
$eq: /* @__PURE__ */ __name((value, condition) => value === condition, "$eq"),
|
|
31
|
+
$not: /* @__PURE__ */ __name((value, condition) => !filterMatch(model, condition), "$not"),
|
|
32
|
+
$gt: /* @__PURE__ */ __name((value, condition) => value > condition, "$gt"),
|
|
33
|
+
$gte: /* @__PURE__ */ __name((value, condition) => value >= condition, "$gte"),
|
|
34
|
+
$lt: /* @__PURE__ */ __name((value, condition) => value < condition, "$lt"),
|
|
35
|
+
$lte: /* @__PURE__ */ __name((value, condition) => value <= condition, "$lte"),
|
|
36
|
+
$ne: /* @__PURE__ */ __name((value, condition) => value !== condition, "$ne"),
|
|
37
|
+
$in: /* @__PURE__ */ __name((value, condition) => condition.includes(value), "$in"),
|
|
38
|
+
$or: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).some((condition) => filterMatch(model2, condition)), "$or"),
|
|
39
|
+
$and: /* @__PURE__ */ __name((model2, conditions) => Object.values(conditions).every((condition) => filterMatch(model2, condition)), "$and")
|
|
40
|
+
};
|
|
41
|
+
for (const [key, value] of Object.entries(where)) {
|
|
42
|
+
if (operatorFunctions[key] !== void 0) {
|
|
43
|
+
if (!operatorFunctions[key](model, value)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
if (typeof value === "object") {
|
|
48
|
+
for (const [operator, condition] of Object.entries(value)) {
|
|
49
|
+
if (!operatorFunctions[operator](model[key], condition)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
if (!operatorFunctions["$eq"](model[key], value)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
__name(filterMatch, "filterMatch");
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
filterMatch
|
|
66
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ModelStatic } from 'sequelize';
|
|
2
|
+
import { Collection } from './collection';
|
|
3
|
+
import { Database } from './database';
|
|
4
|
+
import { Model } from './model';
|
|
5
|
+
type FilterType = any;
|
|
6
|
+
interface FilterParserContext {
|
|
7
|
+
collection: Collection;
|
|
8
|
+
app?: any;
|
|
9
|
+
}
|
|
10
|
+
export default class FilterParser {
|
|
11
|
+
collection: Collection;
|
|
12
|
+
database: Database;
|
|
13
|
+
model: ModelStatic<Model>;
|
|
14
|
+
filter: FilterType;
|
|
15
|
+
context: FilterParserContext;
|
|
16
|
+
constructor(filter: FilterType, context: FilterParserContext);
|
|
17
|
+
prepareFilter(filter: FilterType): any;
|
|
18
|
+
toSequelizeParams(): any;
|
|
19
|
+
private getFieldNameFromQueryPath;
|
|
20
|
+
}
|
|
21
|
+
export {};
|