@antelopejs/interface-database-decorators 0.1.9 → 0.1.11
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 +1 -1
- package/dist/antelope.test.js +1 -1
- package/dist/common.d.ts +2 -1
- package/dist/common.js +5 -1
- package/dist/common.js.map +1 -1
- package/dist/database.js +1 -0
- package/dist/database.js.map +1 -1
- package/dist/model.js +29 -26
- package/dist/model.js.map +1 -1
- package/dist/modifiers/common.d.ts +24 -4
- package/dist/modifiers/common.js +92 -114
- 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/internal/kinds.d.ts +12 -0
- package/dist/modifiers/internal/kinds.js +29 -0
- package/dist/modifiers/internal/kinds.js.map +1 -0
- package/dist/modifiers/internal/records.d.ts +29 -0
- package/dist/modifiers/internal/records.js +42 -0
- package/dist/modifiers/internal/records.js.map +1 -0
- package/dist/modifiers/localization.d.ts +19 -1
- package/dist/modifiers/localization.js +41 -6
- package/dist/modifiers/localization.js.map +1 -1
- package/dist/schema.js +1 -2
- package/dist/schema.js.map +1 -1
- package/dist/table.d.ts +8 -0
- 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 +247 -226
- package/dist/tests/database.test.js.map +1 -1
- 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 -469
- 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 +91 -99
- package/dist/tests/modifiers/hash.test.js.map +1 -1
- package/dist/tests/modifiers/localization.test.js +186 -159
- package/dist/tests/modifiers/localization.test.js.map +1 -1
- 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/1.introduction.md +56 -2
- package/docs/2.table-definitions.md +15 -0
- package/docs/3.table-modifiers.md +10 -4
- package/docs/4.data-models.md +12 -0
- package/docs/5.parameter-decoration.md +4 -0
- package/docs/assets/model-conversion.svg +21 -0
- package/package.json +16 -5
- package/skills/database-decorators-interface/SKILL.md +4 -0
- package/skills/database-decorators-interface/cases.json +71 -0
|
@@ -11,242 +11,263 @@ 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 table_1 = require("
|
|
14
|
+
const schema_1 = require("../schema");
|
|
15
|
+
const database_1 = require("../database");
|
|
16
|
+
const model_1 = require("../model");
|
|
17
|
+
const table_1 = require("../table");
|
|
18
18
|
const codec_helpers_1 = require("./codec_helpers");
|
|
19
19
|
describe("Database - initialization", () => {
|
|
20
|
-
it("creates a schema", async () =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
it("
|
|
20
|
+
it("creates a schema", async () => {
|
|
21
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
22
|
+
};
|
|
23
|
+
_TestTable = __decorate([
|
|
24
|
+
(0, schema_1.RegisterTable)("test_table", "test-new-schema")
|
|
25
|
+
], _TestTable);
|
|
26
|
+
await (0, database_1.RegisterSchema)("test-new-schema");
|
|
27
|
+
const schema = interface_database_1.Schema.get("test-new-schema");
|
|
28
|
+
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
29
|
+
});
|
|
30
|
+
it("creates tables with default primary key", async () => {
|
|
31
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
32
|
+
};
|
|
33
|
+
_TestTable = __decorate([
|
|
34
|
+
(0, schema_1.RegisterTable)("pk_table", "test-pk-schema")
|
|
35
|
+
], _TestTable);
|
|
36
|
+
await (0, database_1.RegisterSchema)("test-pk-schema");
|
|
37
|
+
const schema = interface_database_1.Schema.get("test-pk-schema");
|
|
38
|
+
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
39
|
+
});
|
|
40
|
+
it("creates tables with indexes", async () => {
|
|
41
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, table_1.Index)(),
|
|
45
|
+
__metadata("design:type", String)
|
|
46
|
+
], _TestTable.prototype, "name", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, table_1.Index)(),
|
|
49
|
+
__metadata("design:type", String)
|
|
50
|
+
], _TestTable.prototype, "email", void 0);
|
|
51
|
+
_TestTable = __decorate([
|
|
52
|
+
(0, schema_1.RegisterTable)("idx_table", "test-idx-schema")
|
|
53
|
+
], _TestTable);
|
|
54
|
+
await (0, database_1.RegisterSchema)("test-idx-schema");
|
|
55
|
+
const schema = interface_database_1.Schema.get("test-idx-schema");
|
|
56
|
+
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
57
|
+
});
|
|
58
|
+
it("creates tables with grouped indexes", async () => {
|
|
59
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
60
|
+
};
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, table_1.Index)({ group: "user_search" }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], _TestTable.prototype, "name", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, table_1.Index)({ group: "user_search" }),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], _TestTable.prototype, "email", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, table_1.Index)({ group: "age_range" }),
|
|
71
|
+
__metadata("design:type", Number)
|
|
72
|
+
], _TestTable.prototype, "age", void 0);
|
|
73
|
+
_TestTable = __decorate([
|
|
74
|
+
(0, schema_1.RegisterTable)("grp_table", "test-grp-schema")
|
|
75
|
+
], _TestTable);
|
|
76
|
+
await (0, database_1.RegisterSchema)("test-grp-schema");
|
|
77
|
+
const schema = interface_database_1.Schema.get("test-grp-schema");
|
|
78
|
+
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
79
|
+
});
|
|
80
|
+
it("marks a single-field index as cross-instance", async () => {
|
|
81
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
82
|
+
};
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, table_1.Index)({ crossInstance: true }),
|
|
85
|
+
__metadata("design:type", String)
|
|
86
|
+
], _TestTable.prototype, "email", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, table_1.Index)(),
|
|
89
|
+
__metadata("design:type", String)
|
|
90
|
+
], _TestTable.prototype, "name", void 0);
|
|
91
|
+
_TestTable = __decorate([
|
|
92
|
+
(0, schema_1.RegisterTable)("cross_single", "test-cross-single-schema")
|
|
93
|
+
], _TestTable);
|
|
94
|
+
await (0, database_1.RegisterSchema)("test-cross-single-schema");
|
|
95
|
+
const indexes = getIndexDefinitions("test-cross-single-schema", "cross_single");
|
|
96
|
+
(0, chai_1.expect)(indexes).to.deep.equal({
|
|
97
|
+
email: { fields: undefined, crossInstance: true },
|
|
98
|
+
name: { fields: undefined },
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it("marks a group index as cross-instance when one member sets it", async () => {
|
|
102
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
103
|
+
};
|
|
104
|
+
__decorate([
|
|
105
|
+
(0, table_1.Index)({ group: "user_search" }),
|
|
106
|
+
__metadata("design:type", String)
|
|
107
|
+
], _TestTable.prototype, "name", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
(0, table_1.Index)({ group: "user_search", crossInstance: true }),
|
|
110
|
+
__metadata("design:type", String)
|
|
111
|
+
], _TestTable.prototype, "email", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, table_1.Index)({ group: "age_range" }),
|
|
114
|
+
__metadata("design:type", Number)
|
|
115
|
+
], _TestTable.prototype, "age", void 0);
|
|
116
|
+
_TestTable = __decorate([
|
|
117
|
+
(0, schema_1.RegisterTable)("cross_group", "test-cross-group-schema")
|
|
118
|
+
], _TestTable);
|
|
119
|
+
await (0, database_1.RegisterSchema)("test-cross-group-schema");
|
|
120
|
+
const indexes = getIndexDefinitions("test-cross-group-schema", "cross_group");
|
|
121
|
+
(0, chai_1.expect)(indexes).to.deep.equal({
|
|
122
|
+
user_search: { fields: ["name", "email"], crossInstance: true },
|
|
123
|
+
age_range: { fields: ["age"] },
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
it("marks a group index as unique when one member sets it", async () => {
|
|
127
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
128
|
+
};
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, table_1.Index)({ unique: true }),
|
|
131
|
+
__metadata("design:type", String)
|
|
132
|
+
], _TestTable.prototype, "slug", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, table_1.Index)({ group: "full_name" }),
|
|
135
|
+
__metadata("design:type", String)
|
|
136
|
+
], _TestTable.prototype, "lastName", void 0);
|
|
137
|
+
__decorate([
|
|
138
|
+
(0, table_1.Index)({ group: "full_name", unique: true }),
|
|
139
|
+
__metadata("design:type", String)
|
|
140
|
+
], _TestTable.prototype, "firstName", void 0);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, table_1.Index)(),
|
|
143
|
+
__metadata("design:type", Number)
|
|
144
|
+
], _TestTable.prototype, "age", void 0);
|
|
145
|
+
_TestTable = __decorate([
|
|
146
|
+
(0, schema_1.RegisterTable)("unique_group", "test-unique-group-schema")
|
|
147
|
+
], _TestTable);
|
|
148
|
+
await (0, database_1.RegisterSchema)("test-unique-group-schema");
|
|
149
|
+
const indexes = getIndexDefinitions("test-unique-group-schema", "unique_group");
|
|
150
|
+
(0, chai_1.expect)(indexes).to.deep.equal({
|
|
151
|
+
slug: { fields: undefined, unique: true },
|
|
152
|
+
full_name: { fields: ["lastName", "firstName"], unique: true },
|
|
153
|
+
age: { fields: undefined },
|
|
154
|
+
});
|
|
155
|
+
});
|
|
31
156
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
__decorate([
|
|
56
|
-
(0, table_1.Index)(),
|
|
57
|
-
__metadata("design:type", String)
|
|
58
|
-
], _TestTable.prototype, "name", void 0);
|
|
59
|
-
__decorate([
|
|
60
|
-
(0, table_1.Index)(),
|
|
61
|
-
__metadata("design:type", String)
|
|
62
|
-
], _TestTable.prototype, "email", void 0);
|
|
63
|
-
_TestTable = __decorate([
|
|
64
|
-
(0, schema_1.RegisterTable)("idx_table", "test-idx-schema")
|
|
65
|
-
], _TestTable);
|
|
66
|
-
await (0, database_1.RegisterSchema)("test-idx-schema");
|
|
67
|
-
const schema = interface_database_1.Schema.get("test-idx-schema");
|
|
68
|
-
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
69
|
-
}
|
|
70
|
-
async function CreateTablesWithGroupedIndexesTest() {
|
|
71
|
-
let _TestTable = class _TestTable extends table_1.Table {
|
|
72
|
-
};
|
|
73
|
-
__decorate([
|
|
74
|
-
(0, table_1.Index)({ group: "user_search" }),
|
|
75
|
-
__metadata("design:type", String)
|
|
76
|
-
], _TestTable.prototype, "name", void 0);
|
|
77
|
-
__decorate([
|
|
78
|
-
(0, table_1.Index)({ group: "user_search" }),
|
|
79
|
-
__metadata("design:type", String)
|
|
80
|
-
], _TestTable.prototype, "email", void 0);
|
|
81
|
-
__decorate([
|
|
82
|
-
(0, table_1.Index)({ group: "age_range" }),
|
|
83
|
-
__metadata("design:type", Number)
|
|
84
|
-
], _TestTable.prototype, "age", void 0);
|
|
85
|
-
_TestTable = __decorate([
|
|
86
|
-
(0, schema_1.RegisterTable)("grp_table", "test-grp-schema")
|
|
87
|
-
], _TestTable);
|
|
88
|
-
await (0, database_1.RegisterSchema)("test-grp-schema");
|
|
89
|
-
const schema = interface_database_1.Schema.get("test-grp-schema");
|
|
90
|
-
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
91
|
-
}
|
|
92
|
-
async function MarksSingleFieldIndexCrossInstanceTest() {
|
|
93
|
-
let _TestTable = class _TestTable extends table_1.Table {
|
|
94
|
-
};
|
|
95
|
-
__decorate([
|
|
96
|
-
(0, table_1.Index)({ crossInstance: true }),
|
|
97
|
-
__metadata("design:type", String)
|
|
98
|
-
], _TestTable.prototype, "email", void 0);
|
|
99
|
-
__decorate([
|
|
100
|
-
(0, table_1.Index)(),
|
|
101
|
-
__metadata("design:type", String)
|
|
102
|
-
], _TestTable.prototype, "name", void 0);
|
|
103
|
-
_TestTable = __decorate([
|
|
104
|
-
(0, schema_1.RegisterTable)("cross_single", "test-cross-single-schema")
|
|
105
|
-
], _TestTable);
|
|
106
|
-
await (0, database_1.RegisterSchema)("test-cross-single-schema");
|
|
107
|
-
const indexes = getIndexDefinitions("test-cross-single-schema", "cross_single");
|
|
108
|
-
(0, chai_1.expect)(indexes).to.deep.equal({
|
|
109
|
-
email: { fields: undefined, crossInstance: true },
|
|
110
|
-
name: { fields: undefined },
|
|
157
|
+
describe("Database - initialization", () => {
|
|
158
|
+
it("leaves index definitions unchanged without crossInstance", async () => {
|
|
159
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
160
|
+
};
|
|
161
|
+
__decorate([
|
|
162
|
+
(0, table_1.Index)(),
|
|
163
|
+
__metadata("design:type", String)
|
|
164
|
+
], _TestTable.prototype, "name", void 0);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, table_1.Index)({ group: "user_search" }),
|
|
167
|
+
__metadata("design:type", String)
|
|
168
|
+
], _TestTable.prototype, "email", void 0);
|
|
169
|
+
_TestTable = __decorate([
|
|
170
|
+
(0, schema_1.RegisterTable)("cross_none", "test-cross-none-schema")
|
|
171
|
+
], _TestTable);
|
|
172
|
+
await (0, database_1.RegisterSchema)("test-cross-none-schema");
|
|
173
|
+
const indexes = getIndexDefinitions("test-cross-none-schema", "cross_none");
|
|
174
|
+
(0, chai_1.expect)(indexes).to.deep.equal({
|
|
175
|
+
name: { fields: undefined },
|
|
176
|
+
user_search: { fields: ["email"] },
|
|
177
|
+
});
|
|
178
|
+
const hasCrossInstanceKey = Object.values(indexes).some((index) => "crossInstance" in index);
|
|
179
|
+
(0, chai_1.expect)(hasCrossInstanceKey).to.equal(false);
|
|
111
180
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
user_search: { fields: ["name", "email"], crossInstance: true },
|
|
135
|
-
age_range: { fields: ["age"] },
|
|
181
|
+
it("creates tables with fixture data", async () => {
|
|
182
|
+
const testData = [
|
|
183
|
+
{ id: "1", name: "Test User 1" },
|
|
184
|
+
{ id: "2", name: "Test User 2" },
|
|
185
|
+
];
|
|
186
|
+
let _TestTable = class _TestTable extends table_1.Table {
|
|
187
|
+
};
|
|
188
|
+
_TestTable = __decorate([
|
|
189
|
+
(0, table_1.Fixture)(() => testData),
|
|
190
|
+
(0, schema_1.RegisterTable)("fixture_table", "test-fixture-schema")
|
|
191
|
+
], _TestTable);
|
|
192
|
+
await (0, database_1.RegisterSchema)("test-fixture-schema");
|
|
193
|
+
const schema = interface_database_1.Schema.get("test-fixture-schema");
|
|
194
|
+
if (!schema)
|
|
195
|
+
throw new Error("Schema not found");
|
|
196
|
+
const result = await schema.instance().table("fixture_table");
|
|
197
|
+
for (const val of result) {
|
|
198
|
+
delete val._id;
|
|
199
|
+
delete val._instance;
|
|
200
|
+
}
|
|
201
|
+
const sortById = (a, b) => a.id.localeCompare(b.id);
|
|
202
|
+
(0, chai_1.expect)(result.sort(sortById)).to.deep.equal(testData.sort(sortById));
|
|
136
203
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
204
|
+
it("handles multiple tables", async () => {
|
|
205
|
+
let _UserTable = class _UserTable extends table_1.Table {
|
|
206
|
+
};
|
|
207
|
+
__decorate([
|
|
208
|
+
(0, table_1.Index)(),
|
|
209
|
+
__metadata("design:type", String)
|
|
210
|
+
], _UserTable.prototype, "email", void 0);
|
|
211
|
+
_UserTable = __decorate([
|
|
212
|
+
(0, schema_1.RegisterTable)("users", "test-multi-table-schema")
|
|
213
|
+
], _UserTable);
|
|
214
|
+
let _ProductTable = class _ProductTable extends table_1.Table {
|
|
215
|
+
};
|
|
216
|
+
__decorate([
|
|
217
|
+
(0, table_1.Index)(),
|
|
218
|
+
__metadata("design:type", String)
|
|
219
|
+
], _ProductTable.prototype, "name", void 0);
|
|
220
|
+
_ProductTable = __decorate([
|
|
221
|
+
(0, schema_1.RegisterTable)("products", "test-multi-table-schema")
|
|
222
|
+
], _ProductTable);
|
|
223
|
+
await (0, database_1.RegisterSchema)("test-multi-table-schema");
|
|
224
|
+
const schema = interface_database_1.Schema.get("test-multi-table-schema");
|
|
225
|
+
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
157
226
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
227
|
+
it("binds a table class registered after RegisterSchema ran to that schema (module hot reload)", async () => {
|
|
228
|
+
let _Declared = class _Declared extends table_1.Table {
|
|
229
|
+
};
|
|
230
|
+
_Declared = __decorate([
|
|
231
|
+
(0, schema_1.RegisterTable)("late_items", "test-late-schema")
|
|
232
|
+
], _Declared);
|
|
233
|
+
await (0, database_1.RegisterSchema)("test-late-schema");
|
|
234
|
+
let Reloaded = class Reloaded extends table_1.Table {
|
|
235
|
+
};
|
|
236
|
+
Reloaded = __decorate([
|
|
237
|
+
(0, schema_1.RegisterTable)("late_items", "test-late-schema")
|
|
238
|
+
], Reloaded);
|
|
239
|
+
const model = (0, model_1.GetModel)((0, model_1.BasicDataModel)(Reloaded), "late-instance");
|
|
240
|
+
(0, chai_1.expect)(model.database.build()[0].options.id).to.equal("test-late-schema");
|
|
241
|
+
(0, chai_1.expect)(Reloaded.table().build()[0].options.id).to.equal("test-late-schema");
|
|
242
|
+
});
|
|
243
|
+
it("populates TableDefinition.fields from @Field declarations", async () => {
|
|
244
|
+
let _Order = class _Order extends table_1.Table {
|
|
245
|
+
};
|
|
246
|
+
__decorate([
|
|
247
|
+
(0, table_1.Field)("string"),
|
|
248
|
+
__metadata("design:type", String)
|
|
249
|
+
], _Order.prototype, "status", void 0);
|
|
250
|
+
__decorate([
|
|
251
|
+
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
252
|
+
__metadata("design:type", Number)
|
|
253
|
+
], _Order.prototype, "total", void 0);
|
|
254
|
+
_Order = __decorate([
|
|
255
|
+
(0, schema_1.RegisterTable)("orders", "test-fields-schema")
|
|
256
|
+
], _Order);
|
|
257
|
+
await (0, database_1.RegisterSchema)("test-fields-schema");
|
|
258
|
+
const schema = interface_database_1.Schema.get("test-fields-schema");
|
|
259
|
+
if (!schema)
|
|
260
|
+
throw new Error("Schema not found");
|
|
261
|
+
const fields = schema.definition.orders.fields;
|
|
262
|
+
(0, chai_1.expect)(fields.status).to.equal("string");
|
|
263
|
+
(0, chai_1.expect)(fields.total).to.equal(codec_helpers_1.numberCodec);
|
|
264
|
+
(0, chai_1.expect)("untyped" in fields).to.equal(false);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
161
267
|
function getIndexDefinitions(schemaId, tableName) {
|
|
162
268
|
const schema = interface_database_1.Schema.get(schemaId);
|
|
163
269
|
if (!schema)
|
|
164
270
|
throw new Error("Schema not found");
|
|
165
271
|
return schema.definition[tableName].indexes;
|
|
166
272
|
}
|
|
167
|
-
async function CreateTablesWithFixtureDataTest() {
|
|
168
|
-
const testData = [
|
|
169
|
-
{ id: "1", name: "Test User 1" },
|
|
170
|
-
{ id: "2", name: "Test User 2" },
|
|
171
|
-
];
|
|
172
|
-
let _TestTable = class _TestTable extends table_1.Table {
|
|
173
|
-
};
|
|
174
|
-
_TestTable = __decorate([
|
|
175
|
-
(0, table_1.Fixture)(() => testData),
|
|
176
|
-
(0, schema_1.RegisterTable)("fixture_table", "test-fixture-schema")
|
|
177
|
-
], _TestTable);
|
|
178
|
-
await (0, database_1.RegisterSchema)("test-fixture-schema");
|
|
179
|
-
const schema = interface_database_1.Schema.get("test-fixture-schema");
|
|
180
|
-
if (!schema)
|
|
181
|
-
throw new Error("Schema not found");
|
|
182
|
-
const result = await schema.instance().table("fixture_table");
|
|
183
|
-
for (const val of result) {
|
|
184
|
-
delete val._id;
|
|
185
|
-
delete val._instance;
|
|
186
|
-
}
|
|
187
|
-
const sortById = (a, b) => a.id.localeCompare(b.id);
|
|
188
|
-
(0, chai_1.expect)(result.sort(sortById)).to.deep.equal(testData.sort(sortById));
|
|
189
|
-
}
|
|
190
|
-
async function PopulatesTableDefinitionFieldsTest() {
|
|
191
|
-
let _Order = class _Order extends table_1.Table {
|
|
192
|
-
};
|
|
193
|
-
__decorate([
|
|
194
|
-
(0, table_1.Field)("string"),
|
|
195
|
-
__metadata("design:type", String)
|
|
196
|
-
], _Order.prototype, "status", void 0);
|
|
197
|
-
__decorate([
|
|
198
|
-
(0, table_1.Field)((0, codec_helpers_1.asFieldType)(codec_helpers_1.numberCodec)),
|
|
199
|
-
__metadata("design:type", Number)
|
|
200
|
-
], _Order.prototype, "total", void 0);
|
|
201
|
-
_Order = __decorate([
|
|
202
|
-
(0, schema_1.RegisterTable)("orders", "test-fields-schema")
|
|
203
|
-
], _Order);
|
|
204
|
-
await (0, database_1.RegisterSchema)("test-fields-schema");
|
|
205
|
-
const schema = interface_database_1.Schema.get("test-fields-schema");
|
|
206
|
-
if (!schema)
|
|
207
|
-
throw new Error("Schema not found");
|
|
208
|
-
const fields = schema.definition.orders.fields;
|
|
209
|
-
(0, chai_1.expect)(fields.status).to.equal("string");
|
|
210
|
-
(0, chai_1.expect)(fields.total).to.equal(codec_helpers_1.numberCodec);
|
|
211
|
-
(0, chai_1.expect)("untyped" in fields).to.equal(false);
|
|
212
|
-
}
|
|
213
|
-
async function HandleMultipleTablesTest() {
|
|
214
|
-
let _UserTable = class _UserTable extends table_1.Table {
|
|
215
|
-
};
|
|
216
|
-
__decorate([
|
|
217
|
-
(0, table_1.Index)(),
|
|
218
|
-
__metadata("design:type", String)
|
|
219
|
-
], _UserTable.prototype, "email", void 0);
|
|
220
|
-
_UserTable = __decorate([
|
|
221
|
-
(0, schema_1.RegisterTable)("users", "test-multi-table-schema")
|
|
222
|
-
], _UserTable);
|
|
223
|
-
let _ProductTable = class _ProductTable extends table_1.Table {
|
|
224
|
-
};
|
|
225
|
-
__decorate([
|
|
226
|
-
(0, table_1.Index)(),
|
|
227
|
-
__metadata("design:type", String)
|
|
228
|
-
], _ProductTable.prototype, "name", void 0);
|
|
229
|
-
_ProductTable = __decorate([
|
|
230
|
-
(0, schema_1.RegisterTable)("products", "test-multi-table-schema")
|
|
231
|
-
], _ProductTable);
|
|
232
|
-
await (0, database_1.RegisterSchema)("test-multi-table-schema");
|
|
233
|
-
const schema = interface_database_1.Schema.get("test-multi-table-schema");
|
|
234
|
-
(0, chai_1.expect)(schema).to.not.equal(undefined);
|
|
235
|
-
}
|
|
236
|
-
async function BindsLateRegisteredTableTest() {
|
|
237
|
-
let _Declared = class _Declared extends table_1.Table {
|
|
238
|
-
};
|
|
239
|
-
_Declared = __decorate([
|
|
240
|
-
(0, schema_1.RegisterTable)("late_items", "test-late-schema")
|
|
241
|
-
], _Declared);
|
|
242
|
-
await (0, database_1.RegisterSchema)("test-late-schema");
|
|
243
|
-
let Reloaded = class Reloaded extends table_1.Table {
|
|
244
|
-
};
|
|
245
|
-
Reloaded = __decorate([
|
|
246
|
-
(0, schema_1.RegisterTable)("late_items", "test-late-schema")
|
|
247
|
-
], Reloaded);
|
|
248
|
-
const model = (0, model_1.GetModel)((0, model_1.BasicDataModel)(Reloaded), "late-instance");
|
|
249
|
-
(0, chai_1.expect)(model.database.build()[0].options.id).to.equal("test-late-schema");
|
|
250
|
-
(0, chai_1.expect)(Reloaded.table().build()[0].options.id).to.equal("test-late-schema");
|
|
251
|
-
}
|
|
252
273
|
//# sourceMappingURL=database.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.test.js","sourceRoot":"","sources":["../../src/tests/database.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+BAA8B;AAC9B,uEAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"database.test.js","sourceRoot":"","sources":["../../src/tests/database.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+BAA8B;AAC9B,uEAAwD;AACxD,sCAA0C;AAC1C,0CAA6C;AAC7C,oCAAoD;AACpD,oCAAwD;AAExD,mDAA2D;AAE3D,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;QAEhC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,aAAK;SAE7B,CAAA;QAFK,UAAU;YADf,IAAA,sBAAa,EAAC,YAAY,EAAE,iBAAiB,CAAC;WACzC,UAAU,CAEf;QAED,MAAM,IAAA,yBAAc,EAAC,iBAAiB,CAAC,CAAC;QAExC,MAAM,MAAM,GAAG,2BAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC7C,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QAEvD,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,aAAK;SAE7B,CAAA;QAFK,UAAU;YADf,IAAA,sBAAa,EAAC,UAAU,EAAE,gBAAgB,CAAC;WACtC,UAAU,CAEf;QAED,MAAM,IAAA,yBAAc,EAAC,gBAAgB,CAAC,CAAC;QAEvC,MAAM,MAAM,GAAG,2BAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC5C,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACzC,CA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,IAAA,aAAK,EAAC,IAAA,2BAAW,EAAC,2BAAW,CAAC,CAAC;;6CACV;QALlB,MAAM;YADX,IAAA,sBAAa,EAAC,QAAQ,EAAE,oBAAoB,CAAC;WACxC,MAAM,CAQX;QACD,MAAM,IAAA,yBAAc,EAAC,oBAAoB,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,2BAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;QAC/C,IAAA,aAAM,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAA,aAAM,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,2BAAW,CAAC,CAAC;QAC3C,IAAA,aAAM,EAAC,SAAS,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAS,mBAAmB,CAAC,QAAgB,EAAE,SAAiB;IAC9D,MAAM,MAAM,GAAG,2BAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjD,OAAO,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC;AAC9C,CAAC"}
|
|
@@ -7,7 +7,31 @@ exports.CreateOtherInstance = CreateOtherInstance;
|
|
|
7
7
|
const node_module_1 = __importDefault(require("node:module"));
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
|
|
10
|
+
function hasInternals(candidate) {
|
|
11
|
+
return ("_resolveFilename" in candidate &&
|
|
12
|
+
typeof candidate._resolveFilename === "function" &&
|
|
13
|
+
"_nodeModulePaths" in candidate &&
|
|
14
|
+
typeof candidate._nodeModulePaths === "function");
|
|
15
|
+
}
|
|
16
|
+
function isLoadable(candidate) {
|
|
17
|
+
return "load" in candidate && typeof candidate.load === "function";
|
|
18
|
+
}
|
|
19
|
+
function isModuleExports(value) {
|
|
20
|
+
return ((typeof value === "object" || typeof value === "function") && value !== null);
|
|
21
|
+
}
|
|
22
|
+
function exportsOf(loaded) {
|
|
23
|
+
const exported = loaded.exports;
|
|
24
|
+
if (!isModuleExports(exported)) {
|
|
25
|
+
throw new Error(`${loaded.filename} does not export an object or a function`);
|
|
26
|
+
}
|
|
27
|
+
return exported;
|
|
28
|
+
}
|
|
29
|
+
function resolveInternals() {
|
|
30
|
+
if (!hasInternals(node_module_1.default)) {
|
|
31
|
+
throw new Error("node:module does not expose its resolution internals");
|
|
32
|
+
}
|
|
33
|
+
return node_module_1.default;
|
|
34
|
+
}
|
|
11
35
|
/**
|
|
12
36
|
* Evaluates built packages a second time, the way the core gives each
|
|
13
37
|
* provider binding its own copy of an interface: every file under `folders`
|
|
@@ -24,22 +48,30 @@ function CreateOtherInstance(folders) {
|
|
|
24
48
|
const load = (filename, parent) => {
|
|
25
49
|
const cached = modules.get(filename);
|
|
26
50
|
if (cached) {
|
|
27
|
-
return cached
|
|
51
|
+
return exportsOf(cached);
|
|
28
52
|
}
|
|
29
53
|
const loaded = new node_module_1.default(filename, parent);
|
|
30
54
|
loaded.filename = filename;
|
|
31
|
-
loaded.paths =
|
|
32
|
-
loaded.require = (
|
|
55
|
+
loaded.paths = resolveInternals()._nodeModulePaths(node_path_1.default.dirname(filename));
|
|
56
|
+
loaded.require = (request) => requireFrom(loaded, request);
|
|
33
57
|
modules.set(filename, loaded);
|
|
58
|
+
if (!isLoadable(loaded)) {
|
|
59
|
+
throw new Error("node:module instances cannot load a file directly");
|
|
60
|
+
}
|
|
34
61
|
loaded.load(filename);
|
|
35
|
-
return loaded
|
|
62
|
+
return exportsOf(loaded);
|
|
36
63
|
};
|
|
37
64
|
const requireFrom = (parent, request) => {
|
|
38
|
-
const filename =
|
|
65
|
+
const filename = resolveInternals()._resolveFilename(request, parent);
|
|
39
66
|
const isOwned = owned.some((root) => filename.startsWith(root));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
67
|
+
if (isOwned) {
|
|
68
|
+
return load(filename, parent);
|
|
69
|
+
}
|
|
70
|
+
const required = node_module_1.default.prototype.require.call(parent, request);
|
|
71
|
+
if (!isModuleExports(required)) {
|
|
72
|
+
throw new Error(`${request} does not export an object or a function`);
|
|
73
|
+
}
|
|
74
|
+
return required;
|
|
43
75
|
};
|
|
44
76
|
return (request) => requireFrom(module, request);
|
|
45
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"other-instance.js","sourceRoot":"","sources":["../../../src/tests/helpers/other-instance.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"other-instance.js","sourceRoot":"","sources":["../../../src/tests/helpers/other-instance.ts"],"names":[],"mappings":";;;;;AA+DA,kDAmCC;AAlGD,8DAAiC;AACjC,qCAAuC;AACvC,0DAA6B;AAa7B,SAAS,YAAY,CACnB,SAAwB;IAExB,OAAO,CACL,kBAAkB,IAAI,SAAS;QAC/B,OAAO,SAAS,CAAC,gBAAgB,KAAK,UAAU;QAChD,kBAAkB,IAAI,SAAS;QAC/B,OAAO,SAAS,CAAC,gBAAgB,KAAK,UAAU,CACjD,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB;IACnC,OAAO,MAAM,IAAI,SAAS,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,CAAC;AACrE,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CACL,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,IAA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