@antelopejs/interface-database-decorators 0.1.10 → 0.1.12
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/README.md +9 -7
- package/dist/common.js.map +1 -1
- package/dist/database.js +18 -2
- package/dist/database.js.map +1 -1
- package/dist/model.js +48 -29
- package/dist/model.js.map +1 -1
- package/dist/modifiers/common.d.ts +24 -4
- package/dist/modifiers/common.js +104 -130
- package/dist/modifiers/common.js.map +1 -1
- package/dist/modifiers/encryption.js +14 -9
- package/dist/modifiers/encryption.js.map +1 -1
- package/dist/modifiers/hash.d.ts +46 -4
- package/dist/modifiers/hash.js +172 -14
- package/dist/modifiers/hash.js.map +1 -1
- package/dist/modifiers/internal/kinds.d.ts +13 -0
- package/dist/modifiers/internal/kinds.js +33 -0
- package/dist/modifiers/internal/kinds.js.map +1 -0
- package/dist/modifiers/internal/records.d.ts +31 -0
- package/dist/modifiers/internal/records.js +56 -0
- package/dist/modifiers/internal/records.js.map +1 -0
- package/dist/modifiers/localization.js +4 -2
- package/dist/modifiers/localization.js.map +1 -1
- package/dist/schema.js +1 -2
- package/dist/schema.js.map +1 -1
- package/dist/table.js +21 -6
- package/dist/table.js.map +1 -1
- package/dist/tests/codec_helpers.d.ts +6 -2
- package/dist/tests/codec_helpers.js +18 -14
- package/dist/tests/codec_helpers.js.map +1 -1
- package/dist/tests/common.test.js +38 -46
- package/dist/tests/common.test.js.map +1 -1
- package/dist/tests/cross_instance.test.js +27 -2
- package/dist/tests/cross_instance.test.js.map +1 -1
- package/dist/tests/database.test.js +278 -256
- package/dist/tests/database.test.js.map +1 -1
- package/dist/tests/hash_upgrade.test.d.ts +1 -0
- package/dist/tests/hash_upgrade.test.js +132 -0
- package/dist/tests/hash_upgrade.test.js.map +1 -0
- package/dist/tests/helpers/hash-rows.d.ts +40 -0
- package/dist/tests/helpers/hash-rows.js +41 -0
- package/dist/tests/helpers/hash-rows.js.map +1 -0
- package/dist/tests/helpers/other-instance.d.ts +1 -1
- package/dist/tests/helpers/other-instance.js +41 -9
- package/dist/tests/helpers/other-instance.js.map +1 -1
- package/dist/tests/integration.test.js +485 -485
- package/dist/tests/integration.test.js.map +1 -1
- package/dist/tests/model.test.js +293 -308
- package/dist/tests/model.test.js.map +1 -1
- package/dist/tests/modifiers/autodate.test.js +80 -86
- package/dist/tests/modifiers/autodate.test.js.map +1 -1
- package/dist/tests/modifiers/common.test.js +181 -195
- package/dist/tests/modifiers/common.test.js.map +1 -1
- package/dist/tests/modifiers/encryption.test.js +149 -155
- package/dist/tests/modifiers/encryption.test.js.map +1 -1
- package/dist/tests/modifiers/hash.test.js +386 -99
- package/dist/tests/modifiers/hash.test.js.map +1 -1
- package/dist/tests/modifiers/localization.test.js +186 -196
- package/dist/tests/modifiers/localization.test.js.map +1 -1
- package/dist/tests/partial_update.test.d.ts +1 -0
- package/dist/tests/partial_update.test.js +55 -0
- package/dist/tests/partial_update.test.js.map +1 -0
- package/dist/tests/relation.test.js +92 -97
- package/dist/tests/relation.test.js.map +1 -1
- package/dist/tests/schema.test.js +101 -106
- package/dist/tests/schema.test.js.map +1 -1
- package/dist/tests/table.test.js +124 -132
- package/dist/tests/table.test.js.map +1 -1
- package/docs/3.table-modifiers.md +36 -15
- package/package.json +14 -3
- package/skills/database-decorators-interface/SKILL.md +4 -2
- package/skills/database-decorators-interface/cases.json +71 -0
|
@@ -11,14 +11,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const chai_1 = require("chai");
|
|
13
13
|
const interface_database_1 = require("@antelopejs/interface-database");
|
|
14
|
-
const schema_1 = require("
|
|
15
|
-
const database_1 = require("
|
|
16
|
-
const model_1 = require("
|
|
17
|
-
const hash_1 = require("
|
|
18
|
-
const table_1 = require("
|
|
19
|
-
const encryption_1 = require("
|
|
20
|
-
const localization_1 = require("
|
|
21
|
-
const common_1 = require("
|
|
14
|
+
const schema_1 = require("../schema");
|
|
15
|
+
const database_1 = require("../database");
|
|
16
|
+
const model_1 = require("../model");
|
|
17
|
+
const hash_1 = require("../modifiers/hash");
|
|
18
|
+
const table_1 = require("../table");
|
|
19
|
+
const encryption_1 = require("../modifiers/encryption");
|
|
20
|
+
const localization_1 = require("../modifiers/localization");
|
|
21
|
+
const common_1 = require("../modifiers/common");
|
|
22
22
|
const codec_helpers_1 = require("./codec_helpers");
|
|
23
23
|
function getDatabase(schemaId) {
|
|
24
24
|
const instance = interface_database_1.Schema.get(schemaId)?.instance();
|
|
@@ -27,486 +27,486 @@ function getDatabase(schemaId) {
|
|
|
27
27
|
return instance;
|
|
28
28
|
}
|
|
29
29
|
describe("Integration - real database operations", () => {
|
|
30
|
-
it("creates and queries user with modifiers", async () =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
it("creates and queries user with modifiers", async () => {
|
|
31
|
+
let User = class User extends table_1.Table.with(hash_1.HashModifier, encryption_1.EncryptionModifier) {
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, table_1.Index)(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], User.prototype, "email", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, hash_1.Hashed)({ algorithm: "sha256" }),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], User.prototype, "password", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, encryption_1.Encrypted)({ secretKey: "12345678901234567890123456789012" }),
|
|
43
|
+
__metadata("design:type", Object)
|
|
44
|
+
], User.prototype, "secretData", void 0);
|
|
45
|
+
User = __decorate([
|
|
46
|
+
(0, schema_1.RegisterTable)("users", "integration-modifiers-schema")
|
|
47
|
+
], User);
|
|
48
|
+
const UserModel = (0, model_1.BasicDataModel)(User, "users");
|
|
49
|
+
await (0, database_1.RegisterSchema)("integration-modifiers-schema");
|
|
50
|
+
const schemaInstance = getDatabase("integration-modifiers-schema");
|
|
51
|
+
const userModel = new UserModel(schemaInstance);
|
|
52
|
+
const userData = {
|
|
53
|
+
email: "test@example.com",
|
|
54
|
+
password: "securePassword123",
|
|
55
|
+
secretData: { token: "secret-token-123" },
|
|
56
|
+
name: "John Doe",
|
|
57
|
+
age: 30,
|
|
58
|
+
};
|
|
59
|
+
const insertResult = await userModel.insert(userData);
|
|
60
|
+
(0, chai_1.expect)(insertResult).to.have.length(1);
|
|
61
|
+
const userId = insertResult[0];
|
|
62
|
+
const retrievedUserFromModel = await userModel.get(userId);
|
|
63
|
+
const retrievedUserFromDatabase = await schemaInstance
|
|
64
|
+
.table("users")
|
|
65
|
+
.get(userId)
|
|
66
|
+
.run();
|
|
67
|
+
(0, chai_1.expect)(retrievedUserFromModel)
|
|
68
|
+
.to.have.property("email")
|
|
69
|
+
.that.equals("test@example.com");
|
|
70
|
+
(0, chai_1.expect)(retrievedUserFromModel)
|
|
71
|
+
.to.have.property("name")
|
|
72
|
+
.that.equals("John Doe");
|
|
73
|
+
(0, chai_1.expect)(retrievedUserFromModel).to.have.property("age").that.equals(30);
|
|
74
|
+
(0, chai_1.expect)(retrievedUserFromModel?.password).to.not.equal("securePassword123");
|
|
75
|
+
(0, chai_1.expect)(retrievedUserFromModel?.secretData).to.deep.equal({
|
|
76
|
+
token: "secret-token-123",
|
|
77
|
+
});
|
|
78
|
+
(0, chai_1.expect)(retrievedUserFromDatabase?.secretData).to.not.deep.equal({
|
|
79
|
+
token: "secret-token-123",
|
|
80
|
+
});
|
|
81
|
+
if (retrievedUserFromModel?.testHash) {
|
|
82
|
+
const isPasswordValid = retrievedUserFromModel.testHash("password", "securePassword123");
|
|
83
|
+
(0, chai_1.expect)(isPasswordValid).to.equal(true);
|
|
84
|
+
}
|
|
85
|
+
const dbUser = await schemaInstance.table("users").get(userId).run();
|
|
86
|
+
(0, chai_1.expect)(dbUser).to.have.property("email").that.equals("test@example.com");
|
|
87
|
+
(0, chai_1.expect)(dbUser).to.have.property("name").that.equals("John Doe");
|
|
88
|
+
});
|
|
89
|
+
it("performs CRUD operations on products", async () => {
|
|
90
|
+
let Product = class Product extends table_1.Table {
|
|
91
|
+
};
|
|
92
|
+
__decorate([
|
|
93
|
+
(0, table_1.Index)(),
|
|
94
|
+
__metadata("design:type", String)
|
|
95
|
+
], Product.prototype, "name", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, table_1.Index)(),
|
|
98
|
+
__metadata("design:type", String)
|
|
99
|
+
], Product.prototype, "category", void 0);
|
|
100
|
+
Product = __decorate([
|
|
101
|
+
(0, schema_1.RegisterTable)("products", "integration-crud-schema")
|
|
102
|
+
], Product);
|
|
103
|
+
const ProductModel = (0, model_1.BasicDataModel)(Product, "products");
|
|
104
|
+
await (0, database_1.RegisterSchema)("integration-crud-schema");
|
|
105
|
+
const schemaInstance = getDatabase("integration-crud-schema");
|
|
106
|
+
const productModel = new ProductModel(schemaInstance);
|
|
107
|
+
const productData = {
|
|
108
|
+
name: "Test Product",
|
|
109
|
+
category: "Electronics",
|
|
110
|
+
price: 99.99,
|
|
111
|
+
stockQuantity: 50,
|
|
112
|
+
isActive: true,
|
|
113
|
+
};
|
|
114
|
+
const insertResult = await productModel.insert(productData);
|
|
115
|
+
const productId = insertResult[0];
|
|
116
|
+
const retrievedProduct = await productModel.get(productId);
|
|
117
|
+
(0, chai_1.expect)(retrievedProduct)
|
|
118
|
+
.to.have.property("name")
|
|
119
|
+
.that.equals("Test Product");
|
|
120
|
+
(0, chai_1.expect)(retrievedProduct).to.have.property("price").that.equals(99.99);
|
|
121
|
+
const updateData = { price: 89.99, stockQuantity: 45 };
|
|
122
|
+
await productModel.update(productId, updateData);
|
|
123
|
+
const updatedProduct = await productModel.get(productId);
|
|
124
|
+
(0, chai_1.expect)(updatedProduct).to.have.property("price").that.equals(89.99);
|
|
125
|
+
(0, chai_1.expect)(updatedProduct).to.have.property("stockQuantity").that.equals(45);
|
|
126
|
+
await productModel.delete(productId);
|
|
127
|
+
const deletedProduct = await productModel.get(productId);
|
|
128
|
+
(0, chai_1.expect)(deletedProduct).to.equal(undefined);
|
|
129
|
+
});
|
|
39
130
|
});
|
|
40
|
-
describe("
|
|
41
|
-
it("
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
131
|
+
describe("Integration - real database operations", () => {
|
|
132
|
+
it("handles localized content", async () => {
|
|
133
|
+
let LocalizedContent = class LocalizedContent extends table_1.Table.with(localization_1.LocalizationModifier) {
|
|
134
|
+
};
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, localization_1.Localized)({ fallbackLocale: "en" }),
|
|
137
|
+
__metadata("design:type", String)
|
|
138
|
+
], LocalizedContent.prototype, "title", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
(0, localization_1.Localized)({ fallbackLocale: "en" }),
|
|
141
|
+
__metadata("design:type", String)
|
|
142
|
+
], LocalizedContent.prototype, "description", void 0);
|
|
143
|
+
LocalizedContent = __decorate([
|
|
144
|
+
(0, schema_1.RegisterTable)("localized_content", "integration-l10n-schema")
|
|
145
|
+
], LocalizedContent);
|
|
146
|
+
const ContentModel = (0, model_1.BasicDataModel)(LocalizedContent, "localized_content");
|
|
147
|
+
await (0, database_1.RegisterSchema)("integration-l10n-schema");
|
|
148
|
+
const schemaInstance = getDatabase("integration-l10n-schema");
|
|
149
|
+
const contentModel = new ContentModel(schemaInstance);
|
|
150
|
+
const content = new LocalizedContent();
|
|
151
|
+
content._id = "content-123";
|
|
152
|
+
content.category = "News";
|
|
153
|
+
content.localize("en").title = "English Title";
|
|
154
|
+
content.localize("fr").title = "French Title";
|
|
155
|
+
content.localize("en").description = "English Description";
|
|
156
|
+
content.localize("fr").description = "French Description";
|
|
157
|
+
const insertResult = await contentModel.insert(content);
|
|
158
|
+
const contentId = insertResult[0];
|
|
159
|
+
const retrievedContent = await contentModel.get(contentId);
|
|
160
|
+
(0, chai_1.expect)(retrievedContent).to.have.property("title");
|
|
161
|
+
(0, chai_1.expect)(retrievedContent).to.have.property("description");
|
|
162
|
+
(0, chai_1.expect)(retrievedContent).to.have.property("category").that.equals("News");
|
|
163
|
+
if (retrievedContent?.localize) {
|
|
164
|
+
const frenchContent = retrievedContent.localize("fr");
|
|
165
|
+
(0, chai_1.expect)(frenchContent.title).to.equal("French Title");
|
|
166
|
+
(0, chai_1.expect)(frenchContent.description).to.equal("French Description");
|
|
167
|
+
const englishContent = retrievedContent.localize("en");
|
|
168
|
+
(0, chai_1.expect)(englishContent.title).to.equal("English Title");
|
|
169
|
+
(0, chai_1.expect)(englishContent.description).to.equal("English Description");
|
|
170
|
+
const germanContent = retrievedContent.localize("de");
|
|
171
|
+
(0, chai_1.expect)(germanContent.title).to.equal("English Title");
|
|
172
|
+
(0, chai_1.expect)(germanContent.description).to.equal("English Description");
|
|
173
|
+
}
|
|
174
|
+
const untranslated = new LocalizedContent();
|
|
175
|
+
untranslated._id = "content-untranslated";
|
|
176
|
+
untranslated.category = "News";
|
|
177
|
+
untranslated.localize("en").title = "Only English";
|
|
178
|
+
untranslated.localize("fr").title = "";
|
|
179
|
+
await contentModel.insert(untranslated);
|
|
180
|
+
const stored = await contentModel.get("content-untranslated");
|
|
181
|
+
(0, chai_1.expect)(stored?.localize("fr").title).to.equal("Only English");
|
|
182
|
+
const frenchTitles = await LocalizedContent.table(schemaInstance)
|
|
183
|
+
.filter((row) => row.key("_id").eq("content-untranslated"))
|
|
184
|
+
.map((row) => (0, common_1.unlockrequest)(LocalizedContent, row, "title", [
|
|
185
|
+
{ modifier: localization_1.LocalizationModifier, args: ["fr"] },
|
|
186
|
+
]))
|
|
187
|
+
.run();
|
|
188
|
+
(0, chai_1.expect)(frenchTitles).to.deep.equal(["Only English"]);
|
|
189
|
+
});
|
|
190
|
+
it("manages encrypted sensitive data", async () => {
|
|
191
|
+
let SensitiveData = class SensitiveData extends table_1.Table.with(encryption_1.EncryptionModifier) {
|
|
192
|
+
};
|
|
193
|
+
__decorate([
|
|
194
|
+
(0, encryption_1.Encrypted)({ secretKey: "12345678901234567890123456789012" }),
|
|
195
|
+
__metadata("design:type", String)
|
|
196
|
+
], SensitiveData.prototype, "creditCard", void 0);
|
|
197
|
+
__decorate([
|
|
198
|
+
(0, encryption_1.Encrypted)({ secretKey: "12345678901234567890123456789012" }),
|
|
199
|
+
__metadata("design:type", String)
|
|
200
|
+
], SensitiveData.prototype, "ssn", void 0);
|
|
201
|
+
SensitiveData = __decorate([
|
|
202
|
+
(0, schema_1.RegisterTable)("sensitive_data", "integration-encrypt-schema")
|
|
203
|
+
], SensitiveData);
|
|
204
|
+
const SensitiveDataModel = (0, model_1.BasicDataModel)(SensitiveData, "sensitive_data");
|
|
205
|
+
await (0, database_1.RegisterSchema)("integration-encrypt-schema");
|
|
206
|
+
const schemaInstance = getDatabase("integration-encrypt-schema");
|
|
207
|
+
const sensitiveDataModel = new SensitiveDataModel(schemaInstance);
|
|
208
|
+
const sensitiveData = {
|
|
209
|
+
creditCard: "4111-1111-1111-1111",
|
|
210
|
+
ssn: "123-45-6789",
|
|
211
|
+
userId: "user123",
|
|
212
|
+
};
|
|
213
|
+
const insertResult = await sensitiveDataModel.insert(sensitiveData);
|
|
214
|
+
const dataId = insertResult[0];
|
|
215
|
+
const retrievedData = await sensitiveDataModel.get(dataId);
|
|
216
|
+
(0, chai_1.expect)(retrievedData).to.have.property("userId").that.equals("user123");
|
|
217
|
+
(0, chai_1.expect)(retrievedData?.creditCard).to.equal("4111-1111-1111-1111");
|
|
218
|
+
(0, chai_1.expect)(retrievedData?.ssn).to.equal("123-45-6789");
|
|
219
|
+
const dbData = await schemaInstance
|
|
220
|
+
.table("sensitive_data")
|
|
221
|
+
.get(dataId)
|
|
222
|
+
.run();
|
|
223
|
+
(0, chai_1.expect)(dbData).to.have.property("userId").that.equals("user123");
|
|
224
|
+
(0, chai_1.expect)(dbData?.creditCard).to.not.equal("4111-1111-1111-1111");
|
|
225
|
+
(0, chai_1.expect)(dbData?.ssn).to.not.equal("123-45-6789");
|
|
226
|
+
});
|
|
45
227
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const model = (0, model_1.GetModel)(TM);
|
|
84
|
-
const ids = await model.insert({ age: 30 }, { validate: true });
|
|
85
|
-
(0, chai_1.expect)(ids).to.not.equal(undefined);
|
|
86
|
-
}
|
|
87
|
-
async function ValidateOnUpdateRejectsTest() {
|
|
88
|
-
let _T = class _T extends table_1.Table {
|
|
89
|
-
};
|
|
90
|
-
__decorate([
|
|
91
|
-
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
92
|
-
__metadata("design:type", Number)
|
|
93
|
-
], _T.prototype, "age", void 0);
|
|
94
|
-
_T = __decorate([
|
|
95
|
-
(0, schema_1.RegisterTable)("v_update_bad", "model-vow-schema-3")
|
|
96
|
-
], _T);
|
|
97
|
-
const TM = (0, model_1.BasicDataModel)(_T, "v_update_bad");
|
|
98
|
-
await (0, database_1.RegisterSchema)("model-vow-schema-3");
|
|
99
|
-
const model = (0, model_1.GetModel)(TM);
|
|
100
|
-
const inserted = await model.insert({ age: 30 });
|
|
101
|
-
const id = Array.isArray(inserted) ? inserted[0] : inserted;
|
|
102
|
-
let threw = false;
|
|
103
|
-
try {
|
|
104
|
-
await model.update(id, { age: "old" }, { validate: true });
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
threw = true;
|
|
108
|
-
(0, chai_1.expect)(e.message).to.contain("validation failed");
|
|
109
|
-
}
|
|
110
|
-
(0, chai_1.expect)(threw).to.equal(true);
|
|
111
|
-
}
|
|
112
|
-
async function ValidateOnUpdateAcceptsPartialTest() {
|
|
113
|
-
let _T = class _T extends table_1.Table {
|
|
114
|
-
};
|
|
115
|
-
__decorate([
|
|
116
|
-
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
117
|
-
__metadata("design:type", Number)
|
|
118
|
-
], _T.prototype, "age", void 0);
|
|
119
|
-
__decorate([
|
|
120
|
-
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
121
|
-
__metadata("design:type", Number)
|
|
122
|
-
], _T.prototype, "score", void 0);
|
|
123
|
-
_T = __decorate([
|
|
124
|
-
(0, schema_1.RegisterTable)("v_update_partial", "model-vow-schema-4")
|
|
125
|
-
], _T);
|
|
126
|
-
const TM = (0, model_1.BasicDataModel)(_T, "v_update_partial");
|
|
127
|
-
await (0, database_1.RegisterSchema)("model-vow-schema-4");
|
|
128
|
-
const model = (0, model_1.GetModel)(TM);
|
|
129
|
-
const inserted = await model.insert({ age: 30, score: 100 });
|
|
130
|
-
const id = Array.isArray(inserted) ? inserted[0] : inserted;
|
|
131
|
-
const updated = await model.update(id, { age: 31 }, {
|
|
132
|
-
validate: true,
|
|
228
|
+
describe("Integration - real database operations", () => {
|
|
229
|
+
it("validates hashed passwords", async () => {
|
|
230
|
+
let UserAccount = class UserAccount extends table_1.Table.with(hash_1.HashModifier) {
|
|
231
|
+
};
|
|
232
|
+
__decorate([
|
|
233
|
+
(0, table_1.Index)(),
|
|
234
|
+
__metadata("design:type", String)
|
|
235
|
+
], UserAccount.prototype, "username", void 0);
|
|
236
|
+
__decorate([
|
|
237
|
+
(0, hash_1.Hashed)({ algorithm: "sha256" }),
|
|
238
|
+
__metadata("design:type", String)
|
|
239
|
+
], UserAccount.prototype, "password", void 0);
|
|
240
|
+
UserAccount = __decorate([
|
|
241
|
+
(0, schema_1.RegisterTable)("user_accounts", "integration-hash-schema")
|
|
242
|
+
], UserAccount);
|
|
243
|
+
const UserAccountModel = (0, model_1.BasicDataModel)(UserAccount, "user_accounts");
|
|
244
|
+
await (0, database_1.RegisterSchema)("integration-hash-schema");
|
|
245
|
+
const schemaInstance = getDatabase("integration-hash-schema");
|
|
246
|
+
const userAccountModel = new UserAccountModel(schemaInstance);
|
|
247
|
+
const accountData = {
|
|
248
|
+
username: "testuser",
|
|
249
|
+
password: "mySecurePassword123",
|
|
250
|
+
email: "test@example.com",
|
|
251
|
+
};
|
|
252
|
+
const insertResult = await userAccountModel.insert(accountData);
|
|
253
|
+
const accountId = insertResult[0];
|
|
254
|
+
const retrievedAccount = await userAccountModel.get(accountId);
|
|
255
|
+
(0, chai_1.expect)(retrievedAccount)
|
|
256
|
+
.to.have.property("username")
|
|
257
|
+
.that.equals("testuser");
|
|
258
|
+
(0, chai_1.expect)(retrievedAccount?.password).to.not.equal("mySecurePassword123");
|
|
259
|
+
if (retrievedAccount?.testHash) {
|
|
260
|
+
const isPasswordValid = retrievedAccount.testHash("password", "mySecurePassword123");
|
|
261
|
+
const isPasswordInvalid = retrievedAccount.testHash("password", "wrongPassword");
|
|
262
|
+
(0, chai_1.expect)(isPasswordValid).to.equal(true);
|
|
263
|
+
(0, chai_1.expect)(isPasswordInvalid).to.equal(false);
|
|
264
|
+
}
|
|
133
265
|
});
|
|
134
|
-
(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
email: "
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
(0, chai_1.expect)(retrievedUserFromModel)
|
|
174
|
-
.to.have.property("email")
|
|
175
|
-
.that.equals("test@example.com");
|
|
176
|
-
(0, chai_1.expect)(retrievedUserFromModel)
|
|
177
|
-
.to.have.property("name")
|
|
178
|
-
.that.equals("John Doe");
|
|
179
|
-
(0, chai_1.expect)(retrievedUserFromModel).to.have.property("age").that.equals(30);
|
|
180
|
-
(0, chai_1.expect)(retrievedUserFromModel?.password).to.not.equal("securePassword123");
|
|
181
|
-
(0, chai_1.expect)(retrievedUserFromModel?.secretData).to.deep.equal({
|
|
182
|
-
token: "secret-token-123",
|
|
266
|
+
it("works with schema registration", async () => {
|
|
267
|
+
let SchemaUser = class SchemaUser extends table_1.Table {
|
|
268
|
+
};
|
|
269
|
+
__decorate([
|
|
270
|
+
(0, table_1.Index)(),
|
|
271
|
+
__metadata("design:type", String)
|
|
272
|
+
], SchemaUser.prototype, "email", void 0);
|
|
273
|
+
SchemaUser = __decorate([
|
|
274
|
+
(0, schema_1.RegisterTable)("schema_users", "integration-schema-reg")
|
|
275
|
+
], SchemaUser);
|
|
276
|
+
let SchemaProduct = class SchemaProduct extends table_1.Table {
|
|
277
|
+
};
|
|
278
|
+
__decorate([
|
|
279
|
+
(0, table_1.Index)(),
|
|
280
|
+
__metadata("design:type", String)
|
|
281
|
+
], SchemaProduct.prototype, "name", void 0);
|
|
282
|
+
SchemaProduct = __decorate([
|
|
283
|
+
(0, schema_1.RegisterTable)("schema_products", "integration-schema-reg")
|
|
284
|
+
], SchemaProduct);
|
|
285
|
+
await (0, database_1.RegisterSchema)("integration-schema-reg");
|
|
286
|
+
const schemaInstance = getDatabase("integration-schema-reg");
|
|
287
|
+
const UserModel = (0, model_1.BasicDataModel)(SchemaUser, "schema_users");
|
|
288
|
+
const ProductModel = (0, model_1.BasicDataModel)(SchemaProduct, "schema_products");
|
|
289
|
+
const userModel = new UserModel(schemaInstance);
|
|
290
|
+
const productModel = new ProductModel(schemaInstance);
|
|
291
|
+
const userData = { email: "user@example.com", name: "Test User" };
|
|
292
|
+
const productData = { name: "Test Product", price: 29.99 };
|
|
293
|
+
const userResult = await userModel.insert(userData);
|
|
294
|
+
const productResult = await productModel.insert(productData);
|
|
295
|
+
(0, chai_1.expect)(userResult).to.have.length(1);
|
|
296
|
+
(0, chai_1.expect)(productResult).to.have.length(1);
|
|
297
|
+
const retrievedUser = await userModel.get(userResult[0]);
|
|
298
|
+
const retrievedProduct = await productModel.get(productResult[0]);
|
|
299
|
+
(0, chai_1.expect)(retrievedUser)
|
|
300
|
+
.to.have.property("email")
|
|
301
|
+
.that.equals("user@example.com");
|
|
302
|
+
(0, chai_1.expect)(retrievedProduct)
|
|
303
|
+
.to.have.property("name")
|
|
304
|
+
.that.equals("Test Product");
|
|
183
305
|
});
|
|
184
|
-
|
|
185
|
-
|
|
306
|
+
});
|
|
307
|
+
describe("Integration - real database operations", () => {
|
|
308
|
+
it("handles complex relationships", async () => {
|
|
309
|
+
let Order = class Order extends table_1.Table {
|
|
310
|
+
};
|
|
311
|
+
__decorate([
|
|
312
|
+
(0, table_1.Index)(),
|
|
313
|
+
__metadata("design:type", String)
|
|
314
|
+
], Order.prototype, "customerId", void 0);
|
|
315
|
+
__decorate([
|
|
316
|
+
(0, table_1.Index)(),
|
|
317
|
+
__metadata("design:type", Date)
|
|
318
|
+
], Order.prototype, "orderDate", void 0);
|
|
319
|
+
Order = __decorate([
|
|
320
|
+
(0, schema_1.RegisterTable)("orders", "integration-rel-schema")
|
|
321
|
+
], Order);
|
|
322
|
+
let OrderItem = class OrderItem extends table_1.Table {
|
|
323
|
+
};
|
|
324
|
+
__decorate([
|
|
325
|
+
(0, table_1.Index)(),
|
|
326
|
+
__metadata("design:type", String)
|
|
327
|
+
], OrderItem.prototype, "orderId", void 0);
|
|
328
|
+
__decorate([
|
|
329
|
+
(0, table_1.Index)(),
|
|
330
|
+
__metadata("design:type", String)
|
|
331
|
+
], OrderItem.prototype, "productId", void 0);
|
|
332
|
+
OrderItem = __decorate([
|
|
333
|
+
(0, schema_1.RegisterTable)("order_items", "integration-rel-schema")
|
|
334
|
+
], OrderItem);
|
|
335
|
+
const OrderModel = (0, model_1.BasicDataModel)(Order, "orders");
|
|
336
|
+
const OrderItemModel = (0, model_1.BasicDataModel)(OrderItem, "order_items");
|
|
337
|
+
await (0, database_1.RegisterSchema)("integration-rel-schema");
|
|
338
|
+
const schemaInstance = getDatabase("integration-rel-schema");
|
|
339
|
+
const orderModel = new OrderModel(schemaInstance);
|
|
340
|
+
const orderItemModel = new OrderItemModel(schemaInstance);
|
|
341
|
+
const orderData = {
|
|
342
|
+
customerId: "customer123",
|
|
343
|
+
orderDate: new Date(),
|
|
344
|
+
totalAmount: 299.97,
|
|
345
|
+
status: "pending",
|
|
346
|
+
};
|
|
347
|
+
const orderResult = await orderModel.insert(orderData);
|
|
348
|
+
const orderId = orderResult[0];
|
|
349
|
+
const orderItemsData = [
|
|
350
|
+
{ orderId, productId: "product1", quantity: 2, unitPrice: 99.99 },
|
|
351
|
+
{ orderId, productId: "product2", quantity: 1, unitPrice: 99.99 },
|
|
352
|
+
];
|
|
353
|
+
const orderItemsResult = await orderItemModel.insert(orderItemsData);
|
|
354
|
+
(0, chai_1.expect)(orderItemsResult).to.have.length(2);
|
|
355
|
+
const retrievedOrder = await orderModel.get(orderId);
|
|
356
|
+
(0, chai_1.expect)(retrievedOrder)
|
|
357
|
+
.to.have.property("customerId")
|
|
358
|
+
.that.equals("customer123");
|
|
359
|
+
(0, chai_1.expect)(retrievedOrder).to.have.property("totalAmount").that.equals(299.97);
|
|
360
|
+
const orderItems = await orderItemModel.getBy("orderId", orderId);
|
|
361
|
+
(0, chai_1.expect)(orderItems).to.be.an("array");
|
|
362
|
+
(0, chai_1.expect)(orderItems).to.have.length(2);
|
|
186
363
|
});
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
], UserAccount.prototype, "username", void 0);
|
|
336
|
-
__decorate([
|
|
337
|
-
(0, hash_1.Hashed)({ algorithm: "sha256" }),
|
|
338
|
-
__metadata("design:type", String)
|
|
339
|
-
], UserAccount.prototype, "password", void 0);
|
|
340
|
-
UserAccount = __decorate([
|
|
341
|
-
(0, schema_1.RegisterTable)("user_accounts", "integration-hash-schema")
|
|
342
|
-
], UserAccount);
|
|
343
|
-
const UserAccountModel = (0, model_1.BasicDataModel)(UserAccount, "user_accounts");
|
|
344
|
-
await (0, database_1.RegisterSchema)("integration-hash-schema");
|
|
345
|
-
const schemaInstance = getDatabase("integration-hash-schema");
|
|
346
|
-
const userAccountModel = new UserAccountModel(schemaInstance);
|
|
347
|
-
const accountData = {
|
|
348
|
-
username: "testuser",
|
|
349
|
-
password: "mySecurePassword123",
|
|
350
|
-
email: "test@example.com",
|
|
351
|
-
};
|
|
352
|
-
const insertResult = await userAccountModel.insert(accountData);
|
|
353
|
-
const accountId = insertResult[0];
|
|
354
|
-
const retrievedAccount = await userAccountModel.get(accountId);
|
|
355
|
-
(0, chai_1.expect)(retrievedAccount).to.have.property("username").that.equals("testuser");
|
|
356
|
-
(0, chai_1.expect)(retrievedAccount?.password).to.not.equal("mySecurePassword123");
|
|
357
|
-
if (retrievedAccount?.testHash) {
|
|
358
|
-
const isPasswordValid = retrievedAccount.testHash("password", "mySecurePassword123");
|
|
359
|
-
const isPasswordInvalid = retrievedAccount.testHash("password", "wrongPassword");
|
|
360
|
-
(0, chai_1.expect)(isPasswordValid).to.equal(true);
|
|
361
|
-
(0, chai_1.expect)(isPasswordInvalid).to.equal(false);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
async function WorkWithSchemaRegistrationTest() {
|
|
365
|
-
let SchemaUser = class SchemaUser extends table_1.Table {
|
|
366
|
-
};
|
|
367
|
-
__decorate([
|
|
368
|
-
(0, table_1.Index)(),
|
|
369
|
-
__metadata("design:type", String)
|
|
370
|
-
], SchemaUser.prototype, "email", void 0);
|
|
371
|
-
SchemaUser = __decorate([
|
|
372
|
-
(0, schema_1.RegisterTable)("schema_users", "integration-schema-reg")
|
|
373
|
-
], SchemaUser);
|
|
374
|
-
let SchemaProduct = class SchemaProduct extends table_1.Table {
|
|
375
|
-
};
|
|
376
|
-
__decorate([
|
|
377
|
-
(0, table_1.Index)(),
|
|
378
|
-
__metadata("design:type", String)
|
|
379
|
-
], SchemaProduct.prototype, "name", void 0);
|
|
380
|
-
SchemaProduct = __decorate([
|
|
381
|
-
(0, schema_1.RegisterTable)("schema_products", "integration-schema-reg")
|
|
382
|
-
], SchemaProduct);
|
|
383
|
-
await (0, database_1.RegisterSchema)("integration-schema-reg");
|
|
384
|
-
const schemaInstance = getDatabase("integration-schema-reg");
|
|
385
|
-
const UserModel = (0, model_1.BasicDataModel)(SchemaUser, "schema_users");
|
|
386
|
-
const ProductModel = (0, model_1.BasicDataModel)(SchemaProduct, "schema_products");
|
|
387
|
-
const userModel = new UserModel(schemaInstance);
|
|
388
|
-
const productModel = new ProductModel(schemaInstance);
|
|
389
|
-
const userData = { email: "user@example.com", name: "Test User" };
|
|
390
|
-
const productData = { name: "Test Product", price: 29.99 };
|
|
391
|
-
const userResult = await userModel.insert(userData);
|
|
392
|
-
const productResult = await productModel.insert(productData);
|
|
393
|
-
(0, chai_1.expect)(userResult).to.have.length(1);
|
|
394
|
-
(0, chai_1.expect)(productResult).to.have.length(1);
|
|
395
|
-
const retrievedUser = await userModel.get(userResult[0]);
|
|
396
|
-
const retrievedProduct = await productModel.get(productResult[0]);
|
|
397
|
-
(0, chai_1.expect)(retrievedUser)
|
|
398
|
-
.to.have.property("email")
|
|
399
|
-
.that.equals("user@example.com");
|
|
400
|
-
(0, chai_1.expect)(retrievedProduct).to.have.property("name").that.equals("Test Product");
|
|
401
|
-
}
|
|
402
|
-
async function HandleComplexRelationshipsTest() {
|
|
403
|
-
let Order = class Order extends table_1.Table {
|
|
404
|
-
};
|
|
405
|
-
__decorate([
|
|
406
|
-
(0, table_1.Index)(),
|
|
407
|
-
__metadata("design:type", String)
|
|
408
|
-
], Order.prototype, "customerId", void 0);
|
|
409
|
-
__decorate([
|
|
410
|
-
(0, table_1.Index)(),
|
|
411
|
-
__metadata("design:type", Date)
|
|
412
|
-
], Order.prototype, "orderDate", void 0);
|
|
413
|
-
Order = __decorate([
|
|
414
|
-
(0, schema_1.RegisterTable)("orders", "integration-rel-schema")
|
|
415
|
-
], Order);
|
|
416
|
-
let OrderItem = class OrderItem extends table_1.Table {
|
|
417
|
-
};
|
|
418
|
-
__decorate([
|
|
419
|
-
(0, table_1.Index)(),
|
|
420
|
-
__metadata("design:type", String)
|
|
421
|
-
], OrderItem.prototype, "orderId", void 0);
|
|
422
|
-
__decorate([
|
|
423
|
-
(0, table_1.Index)(),
|
|
424
|
-
__metadata("design:type", String)
|
|
425
|
-
], OrderItem.prototype, "productId", void 0);
|
|
426
|
-
OrderItem = __decorate([
|
|
427
|
-
(0, schema_1.RegisterTable)("order_items", "integration-rel-schema")
|
|
428
|
-
], OrderItem);
|
|
429
|
-
const OrderModel = (0, model_1.BasicDataModel)(Order, "orders");
|
|
430
|
-
const OrderItemModel = (0, model_1.BasicDataModel)(OrderItem, "order_items");
|
|
431
|
-
await (0, database_1.RegisterSchema)("integration-rel-schema");
|
|
432
|
-
const schemaInstance = getDatabase("integration-rel-schema");
|
|
433
|
-
const orderModel = new OrderModel(schemaInstance);
|
|
434
|
-
const orderItemModel = new OrderItemModel(schemaInstance);
|
|
435
|
-
const orderData = {
|
|
436
|
-
customerId: "customer123",
|
|
437
|
-
orderDate: new Date(),
|
|
438
|
-
totalAmount: 299.97,
|
|
439
|
-
status: "pending",
|
|
440
|
-
};
|
|
441
|
-
const orderResult = await orderModel.insert(orderData);
|
|
442
|
-
const orderId = orderResult[0];
|
|
443
|
-
const orderItemsData = [
|
|
444
|
-
{ orderId, productId: "product1", quantity: 2, unitPrice: 99.99 },
|
|
445
|
-
{ orderId, productId: "product2", quantity: 1, unitPrice: 99.99 },
|
|
446
|
-
];
|
|
447
|
-
const orderItemsResult = await orderItemModel.insert(orderItemsData);
|
|
448
|
-
(0, chai_1.expect)(orderItemsResult).to.have.length(2);
|
|
449
|
-
const retrievedOrder = await orderModel.get(orderId);
|
|
450
|
-
(0, chai_1.expect)(retrievedOrder)
|
|
451
|
-
.to.have.property("customerId")
|
|
452
|
-
.that.equals("customer123");
|
|
453
|
-
(0, chai_1.expect)(retrievedOrder).to.have.property("totalAmount").that.equals(299.97);
|
|
454
|
-
const orderItems = await orderItemModel.getBy("orderId", orderId);
|
|
455
|
-
(0, chai_1.expect)(orderItems).to.be.an("array");
|
|
456
|
-
(0, chai_1.expect)(orderItems).to.have.length(2);
|
|
457
|
-
}
|
|
458
|
-
async function PerformBulkOperationsTest() {
|
|
459
|
-
let BulkProduct = class BulkProduct extends table_1.Table {
|
|
460
|
-
};
|
|
461
|
-
__decorate([
|
|
462
|
-
(0, table_1.Index)(),
|
|
463
|
-
__metadata("design:type", String)
|
|
464
|
-
], BulkProduct.prototype, "category", void 0);
|
|
465
|
-
BulkProduct = __decorate([
|
|
466
|
-
(0, schema_1.RegisterTable)("bulk_products", "integration-bulk-schema")
|
|
467
|
-
], BulkProduct);
|
|
468
|
-
const BulkProductModel = (0, model_1.BasicDataModel)(BulkProduct, "bulk_products");
|
|
469
|
-
await (0, database_1.RegisterSchema)("integration-bulk-schema");
|
|
470
|
-
const schemaInstance = getDatabase("integration-bulk-schema");
|
|
471
|
-
const bulkProductModel = new BulkProductModel(schemaInstance);
|
|
472
|
-
const bulkData = [
|
|
473
|
-
{ name: "Product 1", category: "Electronics", price: 99.99 },
|
|
474
|
-
{ name: "Product 2", category: "Electronics", price: 149.99 },
|
|
475
|
-
{ name: "Product 3", category: "Books", price: 19.99 },
|
|
476
|
-
{ name: "Product 4", category: "Books", price: 29.99 },
|
|
477
|
-
{ name: "Product 5", category: "Clothing", price: 49.99 },
|
|
478
|
-
];
|
|
479
|
-
const insertResult = await bulkProductModel.insert(bulkData);
|
|
480
|
-
(0, chai_1.expect)(insertResult).to.have.length(5);
|
|
481
|
-
const allProducts = await bulkProductModel.getAll();
|
|
482
|
-
(0, chai_1.expect)(allProducts).to.be.an("array");
|
|
483
|
-
(0, chai_1.expect)(allProducts).to.have.length(5);
|
|
484
|
-
const electronicsProducts = await bulkProductModel.getBy("category", "Electronics");
|
|
485
|
-
(0, chai_1.expect)(electronicsProducts).to.be.an("array");
|
|
486
|
-
(0, chai_1.expect)(electronicsProducts).to.have.length(2);
|
|
487
|
-
const booksProducts = await bulkProductModel.getBy("category", "Books");
|
|
488
|
-
(0, chai_1.expect)(booksProducts).to.be.an("array");
|
|
489
|
-
(0, chai_1.expect)(booksProducts).to.have.length(2);
|
|
490
|
-
}
|
|
491
|
-
async function ManageDatabaseInitializationTest() {
|
|
492
|
-
let FixtureUser = class FixtureUser extends table_1.Table {
|
|
493
|
-
};
|
|
494
|
-
__decorate([
|
|
495
|
-
(0, table_1.Index)(),
|
|
496
|
-
__metadata("design:type", String)
|
|
497
|
-
], FixtureUser.prototype, "email", void 0);
|
|
498
|
-
FixtureUser = __decorate([
|
|
499
|
-
(0, table_1.Fixture)(() => [
|
|
500
|
-
{ id: "1", name: "Fixture User 1", email: "fixture1@example.com" },
|
|
501
|
-
{ id: "2", name: "Fixture User 2", email: "fixture2@example.com" },
|
|
502
|
-
]),
|
|
503
|
-
(0, schema_1.RegisterTable)("fixture_users", "integration-fixture-schema")
|
|
504
|
-
], FixtureUser);
|
|
505
|
-
await (0, database_1.RegisterSchema)("integration-fixture-schema");
|
|
506
|
-
const schemaInstance = getDatabase("integration-fixture-schema");
|
|
507
|
-
const FixtureUserModel = (0, model_1.BasicDataModel)(FixtureUser, "fixture_users");
|
|
508
|
-
const fixtureUserModel = new FixtureUserModel(schemaInstance);
|
|
509
|
-
const allUsers = await fixtureUserModel.getAll();
|
|
510
|
-
(0, chai_1.expect)(allUsers.length).to.be.greaterThan(0);
|
|
511
|
-
}
|
|
364
|
+
it("performs bulk operations", async () => {
|
|
365
|
+
let BulkProduct = class BulkProduct extends table_1.Table {
|
|
366
|
+
};
|
|
367
|
+
__decorate([
|
|
368
|
+
(0, table_1.Index)(),
|
|
369
|
+
__metadata("design:type", String)
|
|
370
|
+
], BulkProduct.prototype, "category", void 0);
|
|
371
|
+
BulkProduct = __decorate([
|
|
372
|
+
(0, schema_1.RegisterTable)("bulk_products", "integration-bulk-schema")
|
|
373
|
+
], BulkProduct);
|
|
374
|
+
const BulkProductModel = (0, model_1.BasicDataModel)(BulkProduct, "bulk_products");
|
|
375
|
+
await (0, database_1.RegisterSchema)("integration-bulk-schema");
|
|
376
|
+
const schemaInstance = getDatabase("integration-bulk-schema");
|
|
377
|
+
const bulkProductModel = new BulkProductModel(schemaInstance);
|
|
378
|
+
const bulkData = [
|
|
379
|
+
{ name: "Product 1", category: "Electronics", price: 99.99 },
|
|
380
|
+
{ name: "Product 2", category: "Electronics", price: 149.99 },
|
|
381
|
+
{ name: "Product 3", category: "Books", price: 19.99 },
|
|
382
|
+
{ name: "Product 4", category: "Books", price: 29.99 },
|
|
383
|
+
{ name: "Product 5", category: "Clothing", price: 49.99 },
|
|
384
|
+
];
|
|
385
|
+
const insertResult = await bulkProductModel.insert(bulkData);
|
|
386
|
+
(0, chai_1.expect)(insertResult).to.have.length(5);
|
|
387
|
+
const allProducts = await bulkProductModel.getAll();
|
|
388
|
+
(0, chai_1.expect)(allProducts).to.be.an("array");
|
|
389
|
+
(0, chai_1.expect)(allProducts).to.have.length(5);
|
|
390
|
+
const electronicsProducts = await bulkProductModel.getBy("category", "Electronics");
|
|
391
|
+
(0, chai_1.expect)(electronicsProducts).to.be.an("array");
|
|
392
|
+
(0, chai_1.expect)(electronicsProducts).to.have.length(2);
|
|
393
|
+
const booksProducts = await bulkProductModel.getBy("category", "Books");
|
|
394
|
+
(0, chai_1.expect)(booksProducts).to.be.an("array");
|
|
395
|
+
(0, chai_1.expect)(booksProducts).to.have.length(2);
|
|
396
|
+
});
|
|
397
|
+
it("manages database initialization", async () => {
|
|
398
|
+
let FixtureUser = class FixtureUser extends table_1.Table {
|
|
399
|
+
};
|
|
400
|
+
__decorate([
|
|
401
|
+
(0, table_1.Index)(),
|
|
402
|
+
__metadata("design:type", String)
|
|
403
|
+
], FixtureUser.prototype, "email", void 0);
|
|
404
|
+
FixtureUser = __decorate([
|
|
405
|
+
(0, table_1.Fixture)(() => [
|
|
406
|
+
{ id: "1", name: "Fixture User 1", email: "fixture1@example.com" },
|
|
407
|
+
{ id: "2", name: "Fixture User 2", email: "fixture2@example.com" },
|
|
408
|
+
]),
|
|
409
|
+
(0, schema_1.RegisterTable)("fixture_users", "integration-fixture-schema")
|
|
410
|
+
], FixtureUser);
|
|
411
|
+
await (0, database_1.RegisterSchema)("integration-fixture-schema");
|
|
412
|
+
const schemaInstance = getDatabase("integration-fixture-schema");
|
|
413
|
+
const FixtureUserModel = (0, model_1.BasicDataModel)(FixtureUser, "fixture_users");
|
|
414
|
+
const fixtureUserModel = new FixtureUserModel(schemaInstance);
|
|
415
|
+
const allUsers = await fixtureUserModel.getAll();
|
|
416
|
+
(0, chai_1.expect)(allUsers.length).to.be.greaterThan(0);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
describe("Model - validate-on-write", () => {
|
|
420
|
+
it("rejects insert with validate:true on bad input", async () => {
|
|
421
|
+
let _T = class _T extends table_1.Table {
|
|
422
|
+
};
|
|
423
|
+
__decorate([
|
|
424
|
+
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
425
|
+
__metadata("design:type", Object)
|
|
426
|
+
], _T.prototype, "age", void 0);
|
|
427
|
+
_T = __decorate([
|
|
428
|
+
(0, schema_1.RegisterTable)("v_insert_bad", "model-vow-schema-1")
|
|
429
|
+
], _T);
|
|
430
|
+
const TM = (0, model_1.BasicDataModel)(_T, "v_insert_bad");
|
|
431
|
+
await (0, database_1.RegisterSchema)("model-vow-schema-1");
|
|
432
|
+
const model = (0, model_1.GetModel)(TM);
|
|
433
|
+
let threw = false;
|
|
434
|
+
try {
|
|
435
|
+
await model.insert({ age: "old" }, { validate: true });
|
|
436
|
+
}
|
|
437
|
+
catch (e) {
|
|
438
|
+
threw = true;
|
|
439
|
+
(0, chai_1.expect)(e).to.have.property("errors").that.is.an("array");
|
|
440
|
+
(0, chai_1.expect)(e).to.have.nested.property("errors[0].field", "age");
|
|
441
|
+
}
|
|
442
|
+
(0, chai_1.expect)(threw).to.equal(true);
|
|
443
|
+
});
|
|
444
|
+
it("accepts insert with validate:true on good input", async () => {
|
|
445
|
+
let _T = class _T extends table_1.Table {
|
|
446
|
+
};
|
|
447
|
+
__decorate([
|
|
448
|
+
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
449
|
+
__metadata("design:type", Number)
|
|
450
|
+
], _T.prototype, "age", void 0);
|
|
451
|
+
_T = __decorate([
|
|
452
|
+
(0, schema_1.RegisterTable)("v_insert_ok", "model-vow-schema-2")
|
|
453
|
+
], _T);
|
|
454
|
+
const TM = (0, model_1.BasicDataModel)(_T, "v_insert_ok");
|
|
455
|
+
await (0, database_1.RegisterSchema)("model-vow-schema-2");
|
|
456
|
+
const model = (0, model_1.GetModel)(TM);
|
|
457
|
+
const ids = await model.insert({ age: 30 }, { validate: true });
|
|
458
|
+
(0, chai_1.expect)(ids).to.not.equal(undefined);
|
|
459
|
+
});
|
|
460
|
+
it("rejects update with validate:true on bad input", async () => {
|
|
461
|
+
let _T = class _T extends table_1.Table {
|
|
462
|
+
};
|
|
463
|
+
__decorate([
|
|
464
|
+
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
465
|
+
__metadata("design:type", Object)
|
|
466
|
+
], _T.prototype, "age", void 0);
|
|
467
|
+
_T = __decorate([
|
|
468
|
+
(0, schema_1.RegisterTable)("v_update_bad", "model-vow-schema-3")
|
|
469
|
+
], _T);
|
|
470
|
+
const TM = (0, model_1.BasicDataModel)(_T, "v_update_bad");
|
|
471
|
+
await (0, database_1.RegisterSchema)("model-vow-schema-3");
|
|
472
|
+
const model = (0, model_1.GetModel)(TM);
|
|
473
|
+
const inserted = await model.insert({ age: 30 });
|
|
474
|
+
const id = Array.isArray(inserted) ? inserted[0] : inserted;
|
|
475
|
+
let threw = false;
|
|
476
|
+
try {
|
|
477
|
+
await model.update(id, { age: "old" }, {
|
|
478
|
+
validate: true,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
catch (e) {
|
|
482
|
+
threw = true;
|
|
483
|
+
(0, chai_1.expect)(e).to.have.property("message").that.contains("validation failed");
|
|
484
|
+
}
|
|
485
|
+
(0, chai_1.expect)(threw).to.equal(true);
|
|
486
|
+
});
|
|
487
|
+
it("accepts partial update with validate:true when omitted fields are absent", async () => {
|
|
488
|
+
let _T = class _T extends table_1.Table {
|
|
489
|
+
};
|
|
490
|
+
__decorate([
|
|
491
|
+
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
492
|
+
__metadata("design:type", Number)
|
|
493
|
+
], _T.prototype, "age", void 0);
|
|
494
|
+
__decorate([
|
|
495
|
+
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
496
|
+
__metadata("design:type", Number)
|
|
497
|
+
], _T.prototype, "score", void 0);
|
|
498
|
+
_T = __decorate([
|
|
499
|
+
(0, schema_1.RegisterTable)("v_update_partial", "model-vow-schema-4")
|
|
500
|
+
], _T);
|
|
501
|
+
const TM = (0, model_1.BasicDataModel)(_T, "v_update_partial");
|
|
502
|
+
await (0, database_1.RegisterSchema)("model-vow-schema-4");
|
|
503
|
+
const model = (0, model_1.GetModel)(TM);
|
|
504
|
+
const inserted = await model.insert({ age: 30, score: 100 });
|
|
505
|
+
const id = Array.isArray(inserted) ? inserted[0] : inserted;
|
|
506
|
+
const updated = await model.update(id, { age: 31 }, {
|
|
507
|
+
validate: true,
|
|
508
|
+
});
|
|
509
|
+
(0, chai_1.expect)(updated).to.not.equal(undefined);
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
512
|
//# sourceMappingURL=integration.test.js.map
|