@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,64 @@
|
|
|
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_value_parser_exports = {};
|
|
20
|
+
__export(string_value_parser_exports, {
|
|
21
|
+
StringValueParser: () => StringValueParser
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(string_value_parser_exports);
|
|
24
|
+
var import_base_value_parser = require("./base-value-parser");
|
|
25
|
+
const _StringValueParser = class _StringValueParser extends import_base_value_parser.BaseValueParser {
|
|
26
|
+
async setValue(value) {
|
|
27
|
+
const { map, set } = this.getOptions();
|
|
28
|
+
if (set.size > 0) {
|
|
29
|
+
if (map.has(value)) {
|
|
30
|
+
value = map.get(value);
|
|
31
|
+
}
|
|
32
|
+
if (set.has(value)) {
|
|
33
|
+
this.value = value;
|
|
34
|
+
} else {
|
|
35
|
+
this.errors.push(`No matching option found - ${JSON.stringify(value)}`);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
this.value = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getOptions() {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const options = ((_b = (_a = this.field.options) == null ? void 0 : _a["uiSchema"]) == null ? void 0 : _b.enum) || [];
|
|
44
|
+
const map = /* @__PURE__ */ new Map();
|
|
45
|
+
const set = /* @__PURE__ */ new Set();
|
|
46
|
+
for (const option of options) {
|
|
47
|
+
if (typeof option === "string") {
|
|
48
|
+
set.add(option);
|
|
49
|
+
map.set(option, option);
|
|
50
|
+
} else {
|
|
51
|
+
set.add(option.value);
|
|
52
|
+
set.add(option.label);
|
|
53
|
+
map.set(option.label, option.value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { map, set };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(_StringValueParser, "StringValueParser");
|
|
60
|
+
let StringValueParser = _StringValueParser;
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
StringValueParser
|
|
64
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseValueParser } from './base-value-parser';
|
|
2
|
+
export declare class ToManyValueParser extends BaseValueParser {
|
|
3
|
+
setAccessors: {
|
|
4
|
+
attachment: string;
|
|
5
|
+
chinaRegion: string;
|
|
6
|
+
};
|
|
7
|
+
setAttachments(value: any): Promise<void>;
|
|
8
|
+
setChinaRegion(value: any): Promise<void>;
|
|
9
|
+
setAssociations(value: any): Promise<void>;
|
|
10
|
+
setValue(value: any): Promise<void>;
|
|
11
|
+
getInterface(): string;
|
|
12
|
+
isInterface(name: string): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 to_many_value_parser_exports = {};
|
|
20
|
+
__export(to_many_value_parser_exports, {
|
|
21
|
+
ToManyValueParser: () => ToManyValueParser
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(to_many_value_parser_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
var import_base_value_parser = require("./base-value-parser");
|
|
26
|
+
const _ToManyValueParser = class _ToManyValueParser extends import_base_value_parser.BaseValueParser {
|
|
27
|
+
setAccessors = {
|
|
28
|
+
attachment: "setAttachments",
|
|
29
|
+
chinaRegion: "setChinaRegion"
|
|
30
|
+
};
|
|
31
|
+
async setAttachments(value) {
|
|
32
|
+
this.value = this.toArr(value).map((url) => {
|
|
33
|
+
return {
|
|
34
|
+
title: (0, import_path.basename)(url),
|
|
35
|
+
extname: (0, import_path.extname)(url),
|
|
36
|
+
filename: (0, import_path.basename)(url),
|
|
37
|
+
url
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async setChinaRegion(value) {
|
|
42
|
+
const repository = this.field.database.getRepository(this.field.target);
|
|
43
|
+
try {
|
|
44
|
+
const values = [];
|
|
45
|
+
const names = this.toArr(value, "/");
|
|
46
|
+
let parentCode = null;
|
|
47
|
+
for (const name of names) {
|
|
48
|
+
const instance = await repository.findOne({
|
|
49
|
+
filter: {
|
|
50
|
+
name: name.trim(),
|
|
51
|
+
parentCode
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (!instance) {
|
|
55
|
+
throw new Error(`"${value}" does not exist`);
|
|
56
|
+
}
|
|
57
|
+
parentCode = instance.get("code");
|
|
58
|
+
values.push(parentCode);
|
|
59
|
+
}
|
|
60
|
+
if (values.length !== names.length) {
|
|
61
|
+
throw new Error(`"${value}" does not exist`);
|
|
62
|
+
}
|
|
63
|
+
this.value = values;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.errors.push(error.message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async setAssociations(value) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const dataIndex = ((_b = (_a = this.ctx) == null ? void 0 : _a.column) == null ? void 0 : _b.dataIndex) || [];
|
|
71
|
+
if (Array.isArray(dataIndex) && dataIndex.length < 2) {
|
|
72
|
+
this.errors.push(`data index invalid`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const key = this.ctx.column.dataIndex[1];
|
|
76
|
+
const repository = this.field.database.getRepository(this.field.target);
|
|
77
|
+
try {
|
|
78
|
+
this.value = await Promise.all(
|
|
79
|
+
this.toArr(value).map(async (v) => {
|
|
80
|
+
const instance = await repository.findOne({ filter: { [key]: v } });
|
|
81
|
+
if (!instance) {
|
|
82
|
+
throw new Error(`"${v}" does not exist`);
|
|
83
|
+
}
|
|
84
|
+
return instance.get(this.field.targetKey || "id");
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
this.errors.push(error.message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async setValue(value) {
|
|
92
|
+
const setAccessor = this.setAccessors[this.getInterface()] || "setAssociations";
|
|
93
|
+
await this[setAccessor](value);
|
|
94
|
+
}
|
|
95
|
+
getInterface() {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
return (_b = (_a = this.field) == null ? void 0 : _a.options) == null ? void 0 : _b.interface;
|
|
98
|
+
}
|
|
99
|
+
isInterface(name) {
|
|
100
|
+
return this.getInterface() === name;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
__name(_ToManyValueParser, "ToManyValueParser");
|
|
104
|
+
let ToManyValueParser = _ToManyValueParser;
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
ToManyValueParser
|
|
108
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
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 to_one_value_parser_exports = {};
|
|
20
|
+
__export(to_one_value_parser_exports, {
|
|
21
|
+
ToOneValueParser: () => ToOneValueParser
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(to_one_value_parser_exports);
|
|
24
|
+
var import_base_value_parser = require("./base-value-parser");
|
|
25
|
+
const _ToOneValueParser = class _ToOneValueParser extends import_base_value_parser.BaseValueParser {
|
|
26
|
+
async setValue(value) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const dataIndex = ((_b = (_a = this.ctx) == null ? void 0 : _a.column) == null ? void 0 : _b.dataIndex) || [];
|
|
29
|
+
if (Array.isArray(dataIndex) && dataIndex.length < 2) {
|
|
30
|
+
this.errors.push(`data index invalid`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const key = this.ctx.column.dataIndex[1];
|
|
34
|
+
const repository = this.field.database.getRepository(this.field.target);
|
|
35
|
+
const instance = await repository.findOne({ filter: { [key]: this.trim(value) } });
|
|
36
|
+
if (instance) {
|
|
37
|
+
this.value = instance.get(this.field.targetKey || "id");
|
|
38
|
+
} else {
|
|
39
|
+
this.errors.push(`"${value}" does not exist`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__name(_ToOneValueParser, "ToOneValueParser");
|
|
44
|
+
let ToOneValueParser = _ToOneValueParser;
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
ToOneValueParser
|
|
48
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
postgres: {
|
|
3
|
+
'character varying': string[];
|
|
4
|
+
varchar: string[];
|
|
5
|
+
char: string[];
|
|
6
|
+
character: string;
|
|
7
|
+
text: string;
|
|
8
|
+
oid: string;
|
|
9
|
+
name: string;
|
|
10
|
+
smallint: string[];
|
|
11
|
+
integer: string[];
|
|
12
|
+
bigint: string[];
|
|
13
|
+
decimal: string;
|
|
14
|
+
numeric: string;
|
|
15
|
+
real: string;
|
|
16
|
+
'double precision': string;
|
|
17
|
+
'timestamp without time zone': string;
|
|
18
|
+
'timestamp with time zone': string;
|
|
19
|
+
'time without time zone': string;
|
|
20
|
+
date: string;
|
|
21
|
+
boolean: string;
|
|
22
|
+
json: string[];
|
|
23
|
+
jsonb: string[];
|
|
24
|
+
point: string;
|
|
25
|
+
path: string;
|
|
26
|
+
polygon: string;
|
|
27
|
+
circle: string;
|
|
28
|
+
uuid: string;
|
|
29
|
+
};
|
|
30
|
+
mysql: {
|
|
31
|
+
smallint: string[];
|
|
32
|
+
tinyint: string[];
|
|
33
|
+
mediumint: string[];
|
|
34
|
+
'smallint unsigned': string[];
|
|
35
|
+
'tinyint unsigned': string[];
|
|
36
|
+
'mediumint unsigned': string[];
|
|
37
|
+
char: string[];
|
|
38
|
+
varchar: string[];
|
|
39
|
+
date: string;
|
|
40
|
+
time: string;
|
|
41
|
+
text: string;
|
|
42
|
+
longtext: string;
|
|
43
|
+
int: string[];
|
|
44
|
+
'int unsigned': string[];
|
|
45
|
+
integer: string[];
|
|
46
|
+
bigint: string[];
|
|
47
|
+
'bigint unsigned': string[];
|
|
48
|
+
float: string;
|
|
49
|
+
double: string;
|
|
50
|
+
boolean: string;
|
|
51
|
+
decimal: string;
|
|
52
|
+
datetime: string;
|
|
53
|
+
timestamp: string;
|
|
54
|
+
json: string[];
|
|
55
|
+
enum: string;
|
|
56
|
+
};
|
|
57
|
+
sqlite: {
|
|
58
|
+
text: string;
|
|
59
|
+
varchar: string[];
|
|
60
|
+
integer: string;
|
|
61
|
+
real: string;
|
|
62
|
+
datetime: string;
|
|
63
|
+
date: string;
|
|
64
|
+
time: string;
|
|
65
|
+
boolean: string;
|
|
66
|
+
numeric: string;
|
|
67
|
+
json: string[];
|
|
68
|
+
};
|
|
69
|
+
mariadb: {
|
|
70
|
+
smallint: string[];
|
|
71
|
+
tinyint: string[];
|
|
72
|
+
mediumint: string[];
|
|
73
|
+
'smallint unsigned': string[];
|
|
74
|
+
'tinyint unsigned': string[];
|
|
75
|
+
'mediumint unsigned': string[];
|
|
76
|
+
char: string[];
|
|
77
|
+
varchar: string[];
|
|
78
|
+
date: string;
|
|
79
|
+
time: string;
|
|
80
|
+
text: string;
|
|
81
|
+
longtext: string;
|
|
82
|
+
int: string[];
|
|
83
|
+
'int unsigned': string[];
|
|
84
|
+
integer: string[];
|
|
85
|
+
bigint: string[];
|
|
86
|
+
'bigint unsigned': string[];
|
|
87
|
+
float: string;
|
|
88
|
+
double: string;
|
|
89
|
+
boolean: string;
|
|
90
|
+
decimal: string;
|
|
91
|
+
datetime: string;
|
|
92
|
+
timestamp: string;
|
|
93
|
+
json: string[];
|
|
94
|
+
enum: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export default _default;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var field_type_map_exports = {};
|
|
19
|
+
__export(field_type_map_exports, {
|
|
20
|
+
default: () => field_type_map_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(field_type_map_exports);
|
|
23
|
+
const postgres = {
|
|
24
|
+
"character varying": ["string", "uuid", "nanoid"],
|
|
25
|
+
varchar: ["string", "uuid", "nanoid"],
|
|
26
|
+
char: ["string", "uuid", "nanoid"],
|
|
27
|
+
character: "string",
|
|
28
|
+
text: "text",
|
|
29
|
+
oid: "string",
|
|
30
|
+
name: "string",
|
|
31
|
+
smallint: ["integer", "sort"],
|
|
32
|
+
integer: ["integer", "sort"],
|
|
33
|
+
bigint: ["bigInt", "sort"],
|
|
34
|
+
decimal: "decimal",
|
|
35
|
+
numeric: "float",
|
|
36
|
+
real: "float",
|
|
37
|
+
"double precision": "float",
|
|
38
|
+
"timestamp without time zone": "date",
|
|
39
|
+
"timestamp with time zone": "date",
|
|
40
|
+
"time without time zone": "time",
|
|
41
|
+
date: "date",
|
|
42
|
+
boolean: "boolean",
|
|
43
|
+
json: ["json", "array"],
|
|
44
|
+
jsonb: ["json", "array", "jsonb"],
|
|
45
|
+
point: "json",
|
|
46
|
+
path: "json",
|
|
47
|
+
polygon: "json",
|
|
48
|
+
circle: "json",
|
|
49
|
+
uuid: "uuid"
|
|
50
|
+
};
|
|
51
|
+
const mysql = {
|
|
52
|
+
smallint: ["integer", "boolean", "sort"],
|
|
53
|
+
tinyint: ["integer", "boolean", "sort"],
|
|
54
|
+
mediumint: ["integer", "boolean", "sort"],
|
|
55
|
+
"smallint unsigned": ["integer", "boolean", "sort"],
|
|
56
|
+
"tinyint unsigned": ["integer", "boolean", "sort"],
|
|
57
|
+
"mediumint unsigned": ["integer", "boolean", "sort"],
|
|
58
|
+
char: ["string", "uuid", "nanoid"],
|
|
59
|
+
varchar: ["string", "uuid", "nanoid"],
|
|
60
|
+
date: "date",
|
|
61
|
+
time: "time",
|
|
62
|
+
text: "text",
|
|
63
|
+
longtext: "text",
|
|
64
|
+
int: ["integer", "sort"],
|
|
65
|
+
"int unsigned": ["integer", "sort"],
|
|
66
|
+
integer: ["integer", "sort"],
|
|
67
|
+
bigint: ["bigInt", "sort"],
|
|
68
|
+
"bigint unsigned": ["bigInt", "sort"],
|
|
69
|
+
float: "float",
|
|
70
|
+
double: "float",
|
|
71
|
+
boolean: "boolean",
|
|
72
|
+
decimal: "decimal",
|
|
73
|
+
datetime: "date",
|
|
74
|
+
timestamp: "date",
|
|
75
|
+
json: ["json", "array"],
|
|
76
|
+
enum: "string"
|
|
77
|
+
};
|
|
78
|
+
const sqlite = {
|
|
79
|
+
text: "text",
|
|
80
|
+
varchar: ["string", "uuid", "nanoid"],
|
|
81
|
+
integer: "integer",
|
|
82
|
+
real: "real",
|
|
83
|
+
datetime: "date",
|
|
84
|
+
date: "date",
|
|
85
|
+
time: "time",
|
|
86
|
+
boolean: "boolean",
|
|
87
|
+
numeric: "decimal",
|
|
88
|
+
json: ["json", "array"]
|
|
89
|
+
};
|
|
90
|
+
var field_type_map_default = { postgres, mysql, sqlite, mariadb: mysql };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Database from '../database';
|
|
2
|
+
type InferredField = {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
source?: string;
|
|
6
|
+
};
|
|
7
|
+
type InferredFieldResult = {
|
|
8
|
+
[key: string]: InferredField;
|
|
9
|
+
};
|
|
10
|
+
export declare class ViewFieldInference {
|
|
11
|
+
static extractTypeFromDefinition(typeDefinition: any): any;
|
|
12
|
+
static inferFields(options: {
|
|
13
|
+
db: Database;
|
|
14
|
+
viewName: string;
|
|
15
|
+
viewSchema?: string;
|
|
16
|
+
}): Promise<InferredFieldResult>;
|
|
17
|
+
static inferToFieldType(options: {
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
dialect: string;
|
|
21
|
+
}): {
|
|
22
|
+
possibleTypes: string[];
|
|
23
|
+
type?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
type: any;
|
|
26
|
+
possibleTypes: any[];
|
|
27
|
+
} | {
|
|
28
|
+
type: any;
|
|
29
|
+
possibleTypes?: undefined;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var view_inference_exports = {};
|
|
30
|
+
__export(view_inference_exports, {
|
|
31
|
+
ViewFieldInference: () => ViewFieldInference
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(view_inference_exports);
|
|
34
|
+
var import_mathjs = require("mathjs");
|
|
35
|
+
var import_field_type_map = __toESM(require("./field-type-map"));
|
|
36
|
+
const _ViewFieldInference = class _ViewFieldInference {
|
|
37
|
+
static extractTypeFromDefinition(typeDefinition) {
|
|
38
|
+
const leftParenIndex = typeDefinition.indexOf("(");
|
|
39
|
+
if (leftParenIndex === -1) {
|
|
40
|
+
return typeDefinition.toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
return typeDefinition.substring(0, leftParenIndex).toLowerCase().trim();
|
|
43
|
+
}
|
|
44
|
+
static async inferFields(options) {
|
|
45
|
+
const { db } = options;
|
|
46
|
+
if (!db.inDialect("postgres")) {
|
|
47
|
+
options.viewSchema = void 0;
|
|
48
|
+
}
|
|
49
|
+
const columns = await db.sequelize.getQueryInterface().describeTable(options.viewName, options.viewSchema);
|
|
50
|
+
const columnUsage = await db.queryInterface.viewColumnUsage({
|
|
51
|
+
viewName: options.viewName,
|
|
52
|
+
schema: options.viewSchema
|
|
53
|
+
});
|
|
54
|
+
const rawFields = [];
|
|
55
|
+
for (const [name, column] of Object.entries(columns)) {
|
|
56
|
+
const inferResult = { name };
|
|
57
|
+
const usage = columnUsage[name];
|
|
58
|
+
if (usage) {
|
|
59
|
+
const collection = db.tableNameCollectionMap.get(
|
|
60
|
+
`${usage.table_schema ? `${usage.table_schema}.` : ""}${usage.table_name}`
|
|
61
|
+
);
|
|
62
|
+
const collectionField = (() => {
|
|
63
|
+
if (!collection) return false;
|
|
64
|
+
const fieldAttribute = Object.values(collection.model.rawAttributes).find(
|
|
65
|
+
(field) => field.field === usage.column_name
|
|
66
|
+
);
|
|
67
|
+
if (!fieldAttribute) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const fieldName = fieldAttribute.fieldName;
|
|
71
|
+
return collection.getField(fieldName);
|
|
72
|
+
})();
|
|
73
|
+
const belongsToAssociationField = (() => {
|
|
74
|
+
if (!collection) return false;
|
|
75
|
+
const field = Object.values(collection.model.rawAttributes).find(
|
|
76
|
+
(field2) => field2.field === usage.column_name
|
|
77
|
+
);
|
|
78
|
+
if (!field) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const association = Object.values(collection.model.associations).find(
|
|
82
|
+
(association2) => association2.associationType === "BelongsTo" && association2.foreignKey === field.fieldName
|
|
83
|
+
);
|
|
84
|
+
if (!association) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return collection.getField(association.as);
|
|
88
|
+
})();
|
|
89
|
+
if (belongsToAssociationField) {
|
|
90
|
+
rawFields.push([
|
|
91
|
+
belongsToAssociationField.name,
|
|
92
|
+
{
|
|
93
|
+
name: belongsToAssociationField.name,
|
|
94
|
+
type: belongsToAssociationField.type,
|
|
95
|
+
source: `${belongsToAssociationField.collection.name}.${belongsToAssociationField.name}`
|
|
96
|
+
}
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
if (collectionField) {
|
|
100
|
+
if (collectionField.options.interface) {
|
|
101
|
+
inferResult.type = collectionField.type;
|
|
102
|
+
inferResult.source = `${collectionField.collection.name}.${collectionField.name}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!inferResult.type) {
|
|
107
|
+
Object.assign(
|
|
108
|
+
inferResult,
|
|
109
|
+
this.inferToFieldType({
|
|
110
|
+
dialect: db.sequelize.getDialect(),
|
|
111
|
+
name,
|
|
112
|
+
type: column.type
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
rawFields.push([name, inferResult]);
|
|
117
|
+
}
|
|
118
|
+
return Object.fromEntries(rawFields);
|
|
119
|
+
}
|
|
120
|
+
static inferToFieldType(options) {
|
|
121
|
+
const { dialect } = options;
|
|
122
|
+
const fieldTypeMap = import_field_type_map.default[dialect];
|
|
123
|
+
if (!options.type) {
|
|
124
|
+
return {
|
|
125
|
+
possibleTypes: Object.keys(fieldTypeMap)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const queryType = this.extractTypeFromDefinition(options.type);
|
|
129
|
+
const mappedType = fieldTypeMap[queryType];
|
|
130
|
+
if ((0, import_mathjs.isArray)(mappedType)) {
|
|
131
|
+
return {
|
|
132
|
+
type: mappedType[0],
|
|
133
|
+
possibleTypes: mappedType
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
type: mappedType
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
__name(_ViewFieldInference, "ViewFieldInference");
|
|
142
|
+
let ViewFieldInference = _ViewFieldInference;
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
ViewFieldInference
|
|
146
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Collection, CollectionContext, CollectionOptions } from './collection';
|
|
2
|
+
export declare class ViewCollection extends Collection {
|
|
3
|
+
constructor(options: CollectionOptions, context: CollectionContext);
|
|
4
|
+
isView(): boolean;
|
|
5
|
+
protected sequelizeModelOptions(): any;
|
|
6
|
+
}
|
|
@@ -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 view_collection_exports = {};
|
|
20
|
+
__export(view_collection_exports, {
|
|
21
|
+
ViewCollection: () => ViewCollection
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(view_collection_exports);
|
|
24
|
+
var import_collection = require("./collection");
|
|
25
|
+
const _ViewCollection = class _ViewCollection extends import_collection.Collection {
|
|
26
|
+
constructor(options, context) {
|
|
27
|
+
options.autoGenId = false;
|
|
28
|
+
options.timestamps = false;
|
|
29
|
+
super(options, context);
|
|
30
|
+
}
|
|
31
|
+
isView() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
sequelizeModelOptions() {
|
|
35
|
+
const modelOptions = super.sequelizeModelOptions();
|
|
36
|
+
modelOptions.tableName = this.options.viewName || this.options.name;
|
|
37
|
+
return modelOptions;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
__name(_ViewCollection, "ViewCollection");
|
|
41
|
+
let ViewCollection = _ViewCollection;
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
ViewCollection
|
|
45
|
+
});
|