@strapi/database 5.0.0-rc.2 → 5.0.0-rc.21
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/dist/entity-manager/index.d.ts.map +1 -1
- package/dist/fields/json.d.ts +1 -1
- package/dist/fields/json.d.ts.map +1 -1
- package/dist/index.js +37 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -13
- package/dist/index.mjs.map +1 -1
- package/dist/metadata/relations.d.ts.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.d.ts.map +1 -1
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity-manager/index.ts"],"names":[],"mappings":"AA0CA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAGnC,OAAO,EAAE,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE5D,cAAc,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entity-manager/index.ts"],"names":[],"mappings":"AA0CA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAGnC,OAAO,EAAE,aAAa,EAAsB,MAAM,SAAS,CAAC;AAE5D,cAAc,SAAS,CAAC;AAyLxB,eAAO,MAAM,mBAAmB,OAAQ,QAAQ,KAAG,aA2kClD,CAAC"}
|
package/dist/fields/json.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/fields/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK;IAC1C,IAAI,CAAC,KAAK,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/fields/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK;IAC1C,IAAI,CAAC,KAAK,EAAE,OAAO;IAYnB,MAAM,CAAC,KAAK,EAAE,OAAO;CAsBtB"}
|
package/dist/index.js
CHANGED
|
@@ -2347,7 +2347,7 @@ const createMorphToOne = (attributeName, attribute) => {
|
|
|
2347
2347
|
});
|
|
2348
2348
|
};
|
|
2349
2349
|
const createMorphToMany = (attributeName, attribute, meta, metadata) => {
|
|
2350
|
-
if ("joinTable" in attribute && attribute.joinTable) {
|
|
2350
|
+
if ("joinTable" in attribute && attribute.joinTable && !attribute.joinTable.__internal__) {
|
|
2351
2351
|
return;
|
|
2352
2352
|
}
|
|
2353
2353
|
const joinTableName = identifiers.getMorphTableName(meta.tableName, attributeName);
|
|
@@ -2417,6 +2417,7 @@ const createMorphToMany = (attributeName, attribute, meta, metadata) => {
|
|
|
2417
2417
|
columnToAttribute: {}
|
|
2418
2418
|
});
|
|
2419
2419
|
const joinTable = {
|
|
2420
|
+
__internal__: true,
|
|
2420
2421
|
name: joinTableName,
|
|
2421
2422
|
joinColumn: {
|
|
2422
2423
|
name: joinColumnName,
|
|
@@ -2486,7 +2487,7 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
|
2486
2487
|
if (!targetMeta) {
|
|
2487
2488
|
throw new Error(`Unknown target ${attribute.target}`);
|
|
2488
2489
|
}
|
|
2489
|
-
if ("joinTable" in attribute && attribute.joinTable) {
|
|
2490
|
+
if ("joinTable" in attribute && attribute.joinTable && !attribute.joinTable.__internal__) {
|
|
2490
2491
|
return;
|
|
2491
2492
|
}
|
|
2492
2493
|
const joinTableName = identifiers.getJoinTableName(
|
|
@@ -2570,6 +2571,7 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
|
2570
2571
|
columnToAttribute: {}
|
|
2571
2572
|
};
|
|
2572
2573
|
const joinTable = {
|
|
2574
|
+
__internal__: true,
|
|
2573
2575
|
name: joinTableName,
|
|
2574
2576
|
joinColumn: {
|
|
2575
2577
|
name: joinColumnName,
|
|
@@ -2589,7 +2591,8 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
|
2589
2591
|
column: {
|
|
2590
2592
|
unsigned: true,
|
|
2591
2593
|
defaultTo: null
|
|
2592
|
-
}
|
|
2594
|
+
},
|
|
2595
|
+
columnName: orderColumnName
|
|
2593
2596
|
};
|
|
2594
2597
|
metadataSchema.indexes.push({
|
|
2595
2598
|
name: identifiers.getOrderFkIndexName(joinTableName),
|
|
@@ -2604,7 +2607,8 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
|
2604
2607
|
column: {
|
|
2605
2608
|
unsigned: true,
|
|
2606
2609
|
defaultTo: null
|
|
2607
|
-
}
|
|
2610
|
+
},
|
|
2611
|
+
columnName: inverseOrderColumnName
|
|
2608
2612
|
};
|
|
2609
2613
|
metadataSchema.indexes.push({
|
|
2610
2614
|
name: identifiers.getOrderInverseFkIndexName(joinTableName),
|
|
@@ -2627,6 +2631,7 @@ const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
|
2627
2631
|
);
|
|
2628
2632
|
}
|
|
2629
2633
|
inverseAttribute.joinTable = {
|
|
2634
|
+
__internal__: true,
|
|
2630
2635
|
name: joinTableName,
|
|
2631
2636
|
joinColumn: joinTable.inverseJoinColumn,
|
|
2632
2637
|
inverseJoinColumn: joinTable.joinColumn,
|
|
@@ -2775,12 +2780,22 @@ class StringField extends Field {
|
|
|
2775
2780
|
}
|
|
2776
2781
|
class JSONField extends Field {
|
|
2777
2782
|
toDB(value) {
|
|
2778
|
-
|
|
2783
|
+
if (value == null) {
|
|
2784
|
+
return null;
|
|
2785
|
+
}
|
|
2786
|
+
if (typeof value === "object") {
|
|
2787
|
+
return JSON.stringify(value);
|
|
2788
|
+
}
|
|
2789
|
+
return value;
|
|
2779
2790
|
}
|
|
2780
2791
|
fromDB(value) {
|
|
2781
2792
|
try {
|
|
2782
2793
|
if (typeof value === "string") {
|
|
2783
|
-
|
|
2794
|
+
const parsedValue = JSON.parse(value);
|
|
2795
|
+
if (typeof parsedValue === "string") {
|
|
2796
|
+
return JSON.parse(parsedValue);
|
|
2797
|
+
}
|
|
2798
|
+
return parsedValue;
|
|
2784
2799
|
}
|
|
2785
2800
|
} catch (error) {
|
|
2786
2801
|
return value;
|
|
@@ -3458,7 +3473,11 @@ const oneToMany = async (input, ctx) => {
|
|
|
3458
3473
|
const { db, qb } = ctx;
|
|
3459
3474
|
const fromTargetRow = (rowOrRows) => fromRow(targetMeta, rowOrRows);
|
|
3460
3475
|
if ("joinColumn" in attribute && attribute.joinColumn) {
|
|
3461
|
-
const {
|
|
3476
|
+
const {
|
|
3477
|
+
name: joinColumnName,
|
|
3478
|
+
referencedColumn: referencedColumnName,
|
|
3479
|
+
on
|
|
3480
|
+
} = attribute.joinColumn;
|
|
3462
3481
|
const referencedValues = ___default.default.uniq(
|
|
3463
3482
|
results.map((r) => r[joinColumnName]).filter((value) => !___default.default.isNil(value))
|
|
3464
3483
|
);
|
|
@@ -3468,7 +3487,10 @@ const oneToMany = async (input, ctx) => {
|
|
|
3468
3487
|
});
|
|
3469
3488
|
return;
|
|
3470
3489
|
}
|
|
3471
|
-
const rows = await db.entityManager.createQueryBuilder(targetMeta.uid).init(populateValue).addSelect(`${qb.alias}.${referencedColumnName}`).where({
|
|
3490
|
+
const rows = await db.entityManager.createQueryBuilder(targetMeta.uid).init(populateValue).addSelect(`${qb.alias}.${referencedColumnName}`).where({
|
|
3491
|
+
[referencedColumnName]: referencedValues,
|
|
3492
|
+
...on && typeof on === "function" ? on({ populateValue, results }) : {}
|
|
3493
|
+
}).execute({ mapResults: false });
|
|
3472
3494
|
const map = ___default.default.groupBy(referencedColumnName)(rows);
|
|
3473
3495
|
results.forEach((result) => {
|
|
3474
3496
|
result[attributeName] = fromTargetRow(map[result[joinColumnName]] || []);
|
|
@@ -5275,8 +5297,10 @@ const processData = (metadata, data = {}, { withDefaults = false } = {}) => {
|
|
|
5275
5297
|
if ("joinColumn" in attribute && attribute.joinColumn && attribute.owner) {
|
|
5276
5298
|
const joinColumnName = attribute.joinColumn.name;
|
|
5277
5299
|
const attrValue = !_.isUndefined(data[attributeName]) ? data[attributeName] : data[joinColumnName];
|
|
5278
|
-
if (
|
|
5300
|
+
if (_.isNull(attrValue)) {
|
|
5279
5301
|
obj[joinColumnName] = attrValue;
|
|
5302
|
+
} else if (!_.isUndefined(attrValue)) {
|
|
5303
|
+
obj[joinColumnName] = toId(attrValue);
|
|
5280
5304
|
}
|
|
5281
5305
|
continue;
|
|
5282
5306
|
}
|
|
@@ -6164,15 +6188,15 @@ const getNextIdsToCreateDocumentId = async (db, knex2, {
|
|
|
6164
6188
|
};
|
|
6165
6189
|
const migrateDocumentIdsWithLocalizations = async (db, knex2, meta) => {
|
|
6166
6190
|
const singularName = meta.singularName.toLowerCase();
|
|
6167
|
-
const joinColumn =
|
|
6168
|
-
const inverseJoinColumn =
|
|
6191
|
+
const joinColumn = _.snakeCase(`${singularName}_id`);
|
|
6192
|
+
const inverseJoinColumn = _.snakeCase(`inv_${singularName}_id`);
|
|
6169
6193
|
let ids;
|
|
6170
6194
|
do {
|
|
6171
6195
|
ids = await getNextIdsToCreateDocumentId(db, knex2, {
|
|
6172
6196
|
joinColumn,
|
|
6173
6197
|
inverseJoinColumn,
|
|
6174
6198
|
tableName: meta.tableName,
|
|
6175
|
-
joinTableName:
|
|
6199
|
+
joinTableName: _.snakeCase(`${meta.tableName}_localizations_links`)
|
|
6176
6200
|
});
|
|
6177
6201
|
if (ids.length > 0) {
|
|
6178
6202
|
await knex2(meta.tableName).update({ document_id: cuid2.createId() }).whereIn("id", ids);
|
|
@@ -6194,7 +6218,7 @@ const createDocumentIdColumn = async (knex2, tableName) => {
|
|
|
6194
6218
|
});
|
|
6195
6219
|
};
|
|
6196
6220
|
const hasLocalizationsJoinTable = async (knex2, tableName) => {
|
|
6197
|
-
const joinTableName =
|
|
6221
|
+
const joinTableName = _.snakeCase(`${tableName}_localizations_links`);
|
|
6198
6222
|
return knex2.schema.hasTable(joinTableName);
|
|
6199
6223
|
};
|
|
6200
6224
|
const createdDocumentId = {
|