@nocobase/database 2.0.0-alpha.9 → 2.0.0-beta.1

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.
Files changed (44) hide show
  1. package/lib/belongs-to-array/belongs-to-array-repository.d.ts +0 -2
  2. package/lib/belongs-to-array/belongs-to-array-repository.js +0 -13
  3. package/lib/collection.d.ts +1 -3
  4. package/lib/collection.js +31 -30
  5. package/lib/database.d.ts +1 -0
  6. package/lib/database.js +19 -10
  7. package/lib/dialects/mariadb-dialect.js +6 -1
  8. package/lib/dialects/postgres-dialect.js +0 -3
  9. package/lib/eager-loading/eager-loading-tree.js +3 -2
  10. package/lib/fields/field.js +4 -0
  11. package/lib/fields/index.d.ts +1 -3
  12. package/lib/fields/index.js +0 -2
  13. package/lib/fields/snowflake-id-field.js +10 -2
  14. package/lib/index.d.ts +3 -1
  15. package/lib/index.js +8 -0
  16. package/lib/interfaces/time-interface.js +1 -1
  17. package/lib/operators/date.js +0 -3
  18. package/lib/{fields/encryption-field/index.d.ts → operators/in.d.ts} +2 -3
  19. package/lib/{fields/encryption-field/errors/EncryptionError.js → operators/in.js} +11 -15
  20. package/lib/operators/index.js +2 -0
  21. package/lib/options-parser.d.ts +3 -1
  22. package/lib/options-parser.js +14 -7
  23. package/lib/relation-repository/belongs-to-many-repository.js +1 -2
  24. package/lib/relation-repository/multiple-relation-repository.d.ts +1 -0
  25. package/lib/relation-repository/multiple-relation-repository.js +13 -0
  26. package/lib/relation-repository/relation-repository.js +1 -1
  27. package/lib/relation-repository/single-relation-repository.js +1 -2
  28. package/lib/repository.d.ts +2 -2
  29. package/lib/repository.js +3 -3
  30. package/lib/sync-runner.js +3 -0
  31. package/lib/update-associations.d.ts +2 -4
  32. package/lib/update-associations.js +6 -14
  33. package/lib/utils/field-validation.d.ts +0 -45
  34. package/lib/utils/field-validation.js +2 -60
  35. package/lib/utils.d.ts +1 -0
  36. package/lib/utils.js +10 -0
  37. package/lib/view/field-type-map.js +3 -3
  38. package/package.json +4 -4
  39. package/lib/fields/encryption-field/encryption-field.d.ts +0 -20
  40. package/lib/fields/encryption-field/encryption-field.js +0 -110
  41. package/lib/fields/encryption-field/errors/EncryptionError.d.ts +0 -11
  42. package/lib/fields/encryption-field/index.js +0 -34
  43. package/lib/fields/encryption-field/utils.d.ts +0 -6
  44. package/lib/fields/encryption-field/utils.js +0 -152
@@ -1,152 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key2 of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key2) && key2 !== except)
25
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var utils_exports = {};
39
- __export(utils_exports, {
40
- aesCheckKey: () => aesCheckKey,
41
- aesDecrypt: () => aesDecrypt,
42
- aesEncrypt: () => aesEncrypt,
43
- aesEncryptSync: () => aesEncryptSync,
44
- aseDecryptSync: () => aseDecryptSync,
45
- checkValueAndIv: () => checkValueAndIv
46
- });
47
- module.exports = __toCommonJS(utils_exports);
48
- var import_crypto = __toESM(require("crypto"));
49
- var import_EncryptionError = require("./errors/EncryptionError");
50
- const algorithm = "aes-256-cbc";
51
- const keyString = process.env.ENCRYPTION_FIELD_KEY || "";
52
- const defaultIvString = process.env.ENCRYPTION_FIELD_IV || "Vc53-4G(rTi0vg@a";
53
- const key = Buffer.from(keyString, "utf8");
54
- function aesEncrypt(text, ivString = defaultIvString) {
55
- checkValueAndIv("Encrypt", text, ivString);
56
- return new Promise((resolve, reject) => {
57
- const iv = Buffer.from(ivString, "utf8");
58
- const cipher = import_crypto.default.createCipheriv(algorithm, key, iv);
59
- let encrypted = "";
60
- cipher.setEncoding("hex");
61
- cipher.on("data", (chunk) => {
62
- encrypted += chunk;
63
- });
64
- cipher.on("end", () => {
65
- resolve(encrypted);
66
- });
67
- cipher.on("error", (err) => {
68
- reject(err);
69
- });
70
- cipher.write(text);
71
- cipher.end();
72
- });
73
- }
74
- __name(aesEncrypt, "aesEncrypt");
75
- function aesDecrypt(encrypted, ivString = defaultIvString) {
76
- checkValueAndIv("Decrypt", encrypted, ivString);
77
- return new Promise((resolve, reject) => {
78
- const iv = Buffer.from(ivString, "utf8");
79
- const decipher = import_crypto.default.createDecipheriv(algorithm, key, iv);
80
- let decrypted = "";
81
- decipher.setEncoding("utf8");
82
- decipher.on("data", (chunk) => {
83
- decrypted += chunk;
84
- });
85
- decipher.on("end", () => {
86
- resolve(decrypted);
87
- });
88
- decipher.on("error", (err) => {
89
- reject(err);
90
- });
91
- decipher.write(encrypted, "hex");
92
- decipher.end();
93
- });
94
- }
95
- __name(aesDecrypt, "aesDecrypt");
96
- function aesEncryptSync(text, ivString = defaultIvString) {
97
- checkValueAndIv("Encrypt", text, ivString);
98
- const iv = Buffer.from(ivString, "utf8");
99
- const cipher = import_crypto.default.createCipheriv(algorithm, key, iv);
100
- let encrypted = cipher.update(text, "utf8", "hex");
101
- encrypted += cipher.final("hex");
102
- return encrypted;
103
- }
104
- __name(aesEncryptSync, "aesEncryptSync");
105
- function aseDecryptSync(encrypted, ivString = defaultIvString) {
106
- checkValueAndIv("Decrypt", encrypted, ivString);
107
- const iv = Buffer.from(ivString, "utf8");
108
- const decipher = import_crypto.default.createDecipheriv(algorithm, key, iv);
109
- let decrypted = decipher.update(encrypted, "hex", "utf8");
110
- decrypted += decipher.final("utf8");
111
- return decrypted;
112
- }
113
- __name(aseDecryptSync, "aseDecryptSync");
114
- function aesCheckKey() {
115
- if (!keyString) {
116
- throw new import_EncryptionError.EncryptionError("The environment variable `ENCRYPTION_FIELD_KEY` is required, please set it");
117
- }
118
- if (typeof keyString !== "string") {
119
- throw new import_EncryptionError.EncryptionError("The environment variable `ENCRYPTION_FIELD_KEY` must be a string");
120
- }
121
- if (keyString.length !== 32) {
122
- throw new import_EncryptionError.EncryptionError("The environment variable `ENCRYPTION_FIELD_KEY` must be a 32-character string");
123
- }
124
- }
125
- __name(aesCheckKey, "aesCheckKey");
126
- function checkValueAndIv(type, value, iv) {
127
- const msg = `${type} Failed: `;
128
- if (typeof value !== "string") {
129
- throw new import_EncryptionError.EncryptionError(msg + "The value must be a string, but got " + typeof value);
130
- }
131
- if (type === "Decrypt") {
132
- if (value.length % 2 !== 0) {
133
- throw new import_EncryptionError.EncryptionError(msg + `The encrypted value is invalid, not a hex string. The value is "${value}"`);
134
- }
135
- }
136
- if (typeof iv !== "string") {
137
- throw new import_EncryptionError.EncryptionError(msg + "The `iv` must be a string, but got " + typeof iv);
138
- }
139
- if (iv.length !== 16) {
140
- throw new import_EncryptionError.EncryptionError(msg + "The `iv` must be a 16-character string");
141
- }
142
- }
143
- __name(checkValueAndIv, "checkValueAndIv");
144
- // Annotate the CommonJS export names for ESM import in node:
145
- 0 && (module.exports = {
146
- aesCheckKey,
147
- aesDecrypt,
148
- aesEncrypt,
149
- aesEncryptSync,
150
- aseDecryptSync,
151
- checkValueAndIv
152
- });