@strapi/core 5.0.0-beta.1 → 5.0.0-beta.2
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/Strapi.d.ts +4 -11
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +9 -16
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +9 -17
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/config-loader.d.ts.map +1 -1
- package/dist/configuration/config-loader.js +8 -5
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/config-loader.mjs +8 -5
- package/dist/configuration/config-loader.mjs.map +1 -1
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -3
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +2 -1
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +1 -1
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-api/permissions/index.js +1 -1
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/content-api/permissions/index.mjs +1 -1
- package/dist/services/content-api/permissions/index.mjs.map +1 -1
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js +4 -0
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +4 -0
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +11 -1
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +11 -1
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js +4 -2
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs +4 -2
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +8 -7
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +42 -78
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs +42 -78
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts +7 -3
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +57 -125
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +58 -126
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts +9 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.js +32 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.js.map +1 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs +32 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/i18n.d.ts +2 -2
- package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/utils/i18n.js +3 -9
- package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/i18n.mjs +3 -9
- package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.d.ts +6 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.js +87 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs +87 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts +6 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
- package/dist/services/entity-service/components.d.ts.map +1 -1
- package/dist/services/entity-service/components.js +1 -4
- package/dist/services/entity-service/components.js.map +1 -1
- package/dist/services/entity-service/components.mjs +1 -4
- package/dist/services/entity-service/components.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +93 -87
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +93 -87
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/metrics/rate-limiter.d.ts.map +1 -1
- package/dist/services/metrics/rate-limiter.js.map +1 -1
- package/dist/services/metrics/rate-limiter.mjs.map +1 -1
- package/dist/services/server/register-routes.js +2 -2
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +2 -2
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +21 -16
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +95 -57
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +95 -57
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +15 -15
- package/dist/services/document-service/transform/relations/transform/output-ids.d.ts +0 -2
- package/dist/services/document-service/transform/relations/transform/output-ids.d.ts.map +0 -1
- package/dist/services/document-service/transform/relations/utils/data.js +0 -12
- package/dist/services/document-service/transform/relations/utils/data.js.map +0 -1
- package/dist/services/document-service/transform/relations/utils/data.mjs +0 -12
- package/dist/services/document-service/transform/relations/utils/data.mjs.map +0 -1
@@ -1,17 +1,41 @@
|
|
1
|
-
import { utils } from "@strapi/database";
|
2
1
|
import { createId } from "@paralleldrive/cuid2";
|
3
2
|
import assert from "node:assert";
|
4
3
|
import _ from "lodash/fp";
|
5
|
-
const
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
const getComponentJoinTableName = (collectionName, identifiers) => {
|
5
|
+
return identifiers.getNameFromTokens([
|
6
|
+
{ name: collectionName, compressible: true },
|
7
|
+
{ name: "components", shortName: "cmps", compressible: false }
|
8
|
+
]);
|
9
|
+
};
|
10
|
+
const getDzJoinTableName = (collectionName, identifiers) => {
|
11
|
+
return identifiers.getNameFromTokens([
|
12
|
+
{ name: collectionName, compressible: true },
|
13
|
+
{ name: "components", shortName: "cmps", compressible: false }
|
14
|
+
]);
|
15
|
+
};
|
16
|
+
const getComponentJoinColumnEntityName = (identifiers) => {
|
17
|
+
return identifiers.getNameFromTokens([
|
18
|
+
{ name: "entity", compressible: false },
|
19
|
+
{ name: "id", compressible: false }
|
20
|
+
]);
|
21
|
+
};
|
22
|
+
const getComponentJoinColumnInverseName = (identifiers) => {
|
23
|
+
return identifiers.getNameFromTokens([
|
24
|
+
{ name: "component", shortName: "cmp", compressible: false },
|
25
|
+
{ name: "id", compressible: false }
|
26
|
+
]);
|
27
|
+
};
|
28
|
+
const getComponentTypeColumn = (identifiers) => {
|
29
|
+
return identifiers.getNameFromTokens([{ name: "component_type", compressible: false }]);
|
30
|
+
};
|
31
|
+
const getComponentFkIndexName = (contentType, identifiers) => {
|
32
|
+
return identifiers.getNameFromTokens([
|
33
|
+
{ name: contentType, compressible: true },
|
34
|
+
{ name: "entity", compressible: false },
|
35
|
+
{ name: "fk", compressible: false }
|
36
|
+
]);
|
37
|
+
};
|
38
|
+
const transformAttribute = (name, attribute, contentType, identifiers) => {
|
15
39
|
switch (attribute.type) {
|
16
40
|
case "media": {
|
17
41
|
return {
|
@@ -22,11 +46,10 @@ const transformAttribute = (name, attribute, contentType) => {
|
|
22
46
|
};
|
23
47
|
}
|
24
48
|
case "component": {
|
25
|
-
const joinTableName = getComponentJoinTableName(contentType.collectionName);
|
26
|
-
const joinColumnEntityName = identifiers
|
27
|
-
const joinColumnInverseName = identifiers
|
28
|
-
|
29
|
-
);
|
49
|
+
const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);
|
50
|
+
const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
|
51
|
+
const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
|
52
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
30
53
|
return {
|
31
54
|
type: "relation",
|
32
55
|
relation: attribute.repeatable === true ? "oneToMany" : "oneToOne",
|
@@ -37,29 +60,33 @@ const transformAttribute = (name, attribute, contentType) => {
|
|
37
60
|
name: joinTableName,
|
38
61
|
joinColumn: {
|
39
62
|
name: joinColumnEntityName,
|
40
|
-
referencedColumn:
|
63
|
+
referencedColumn: identifiers.ID_COLUMN
|
41
64
|
},
|
42
65
|
inverseJoinColumn: {
|
43
66
|
name: joinColumnInverseName,
|
44
|
-
referencedColumn:
|
67
|
+
referencedColumn: identifiers.ID_COLUMN
|
45
68
|
},
|
46
69
|
on: {
|
47
70
|
field: name
|
48
71
|
},
|
49
|
-
orderColumnName:
|
72
|
+
orderColumnName: identifiers.ORDER_COLUMN,
|
50
73
|
orderBy: {
|
51
74
|
order: "asc"
|
52
75
|
},
|
53
|
-
pivotColumns: [
|
76
|
+
pivotColumns: [
|
77
|
+
joinColumnEntityName,
|
78
|
+
joinColumnInverseName,
|
79
|
+
identifiers.FIELD_COLUMN,
|
80
|
+
compTypeColumn
|
81
|
+
]
|
54
82
|
}
|
55
83
|
};
|
56
84
|
}
|
57
85
|
case "dynamiczone": {
|
58
|
-
const joinTableName = getDzJoinTableName(contentType.collectionName);
|
59
|
-
const joinColumnEntityName = identifiers
|
60
|
-
const joinColumnInverseName = identifiers
|
61
|
-
|
62
|
-
);
|
86
|
+
const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);
|
87
|
+
const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
|
88
|
+
const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
|
89
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
63
90
|
return {
|
64
91
|
type: "relation",
|
65
92
|
relation: "morphToMany",
|
@@ -69,15 +96,15 @@ const transformAttribute = (name, attribute, contentType) => {
|
|
69
96
|
name: joinTableName,
|
70
97
|
joinColumn: {
|
71
98
|
name: joinColumnEntityName,
|
72
|
-
referencedColumn:
|
99
|
+
referencedColumn: identifiers.ID_COLUMN
|
73
100
|
},
|
74
101
|
morphColumn: {
|
75
102
|
idColumn: {
|
76
103
|
name: joinColumnInverseName,
|
77
|
-
referencedColumn:
|
104
|
+
referencedColumn: identifiers.ID_COLUMN
|
78
105
|
},
|
79
106
|
typeColumn: {
|
80
|
-
name:
|
107
|
+
name: compTypeColumn
|
81
108
|
},
|
82
109
|
typeField: "__component"
|
83
110
|
},
|
@@ -87,7 +114,12 @@ const transformAttribute = (name, attribute, contentType) => {
|
|
87
114
|
orderBy: {
|
88
115
|
order: "asc"
|
89
116
|
},
|
90
|
-
pivotColumns: [
|
117
|
+
pivotColumns: [
|
118
|
+
joinColumnEntityName,
|
119
|
+
joinColumnInverseName,
|
120
|
+
identifiers.FIELD_COLUMN,
|
121
|
+
compTypeColumn
|
122
|
+
]
|
91
123
|
}
|
92
124
|
};
|
93
125
|
}
|
@@ -96,11 +128,16 @@ const transformAttribute = (name, attribute, contentType) => {
|
|
96
128
|
}
|
97
129
|
}
|
98
130
|
};
|
99
|
-
const transformAttributes = (contentType) => {
|
131
|
+
const transformAttributes = (contentType, identifiers) => {
|
100
132
|
return Object.keys(contentType.attributes || {}).reduce((attrs, attrName) => {
|
101
133
|
return {
|
102
134
|
...attrs,
|
103
|
-
[attrName]: transformAttribute(
|
135
|
+
[attrName]: transformAttribute(
|
136
|
+
attrName,
|
137
|
+
contentType.attributes[attrName],
|
138
|
+
contentType,
|
139
|
+
identifiers
|
140
|
+
)
|
104
141
|
};
|
105
142
|
}, {});
|
106
143
|
};
|
@@ -110,18 +147,19 @@ const hasComponentsOrDz = (contentType) => {
|
|
110
147
|
);
|
111
148
|
};
|
112
149
|
const createDocumentId = createId;
|
113
|
-
const createCompoLinkModel = (contentType) => {
|
114
|
-
const name = getComponentJoinTableName(contentType.collectionName);
|
115
|
-
const entityId = identifiers
|
116
|
-
const componentId = identifiers
|
117
|
-
const
|
150
|
+
const createCompoLinkModel = (contentType, identifiers) => {
|
151
|
+
const name = getComponentJoinTableName(contentType.collectionName, identifiers);
|
152
|
+
const entityId = getComponentJoinColumnEntityName(identifiers);
|
153
|
+
const componentId = getComponentJoinColumnInverseName(identifiers);
|
154
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
155
|
+
const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);
|
118
156
|
return {
|
119
157
|
// TODO: make sure there can't be any conflicts with a prefix
|
120
158
|
singularName: name,
|
121
159
|
uid: name,
|
122
160
|
tableName: name,
|
123
161
|
attributes: {
|
124
|
-
[
|
162
|
+
[identifiers.ID_COLUMN]: {
|
125
163
|
type: "increments"
|
126
164
|
},
|
127
165
|
[entityId]: {
|
@@ -136,13 +174,13 @@ const createCompoLinkModel = (contentType) => {
|
|
136
174
|
unsigned: true
|
137
175
|
}
|
138
176
|
},
|
139
|
-
[
|
177
|
+
[compTypeColumn]: {
|
140
178
|
type: "string"
|
141
179
|
},
|
142
|
-
[
|
180
|
+
[identifiers.FIELD_COLUMN]: {
|
143
181
|
type: "string"
|
144
182
|
},
|
145
|
-
[
|
183
|
+
[identifiers.ORDER_COLUMN]: {
|
146
184
|
type: "float",
|
147
185
|
column: {
|
148
186
|
unsigned: true,
|
@@ -152,12 +190,12 @@ const createCompoLinkModel = (contentType) => {
|
|
152
190
|
},
|
153
191
|
indexes: [
|
154
192
|
{
|
155
|
-
name: identifiers.getIndexName([contentType.collectionName,
|
156
|
-
columns: [
|
193
|
+
name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),
|
194
|
+
columns: [identifiers.FIELD_COLUMN]
|
157
195
|
},
|
158
196
|
{
|
159
|
-
name: identifiers.getIndexName([contentType.collectionName,
|
160
|
-
columns: [
|
197
|
+
name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),
|
198
|
+
columns: [compTypeColumn]
|
161
199
|
},
|
162
200
|
{
|
163
201
|
name: fkIndex,
|
@@ -166,7 +204,7 @@ const createCompoLinkModel = (contentType) => {
|
|
166
204
|
{
|
167
205
|
// NOTE: since we don't include attribute names, we need to be careful not to create another unique index
|
168
206
|
name: identifiers.getUniqueIndexName([contentType.collectionName]),
|
169
|
-
columns: [entityId, componentId,
|
207
|
+
columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],
|
170
208
|
type: "unique"
|
171
209
|
}
|
172
210
|
],
|
@@ -174,21 +212,21 @@ const createCompoLinkModel = (contentType) => {
|
|
174
212
|
{
|
175
213
|
name: fkIndex,
|
176
214
|
columns: [entityId],
|
177
|
-
referencedColumns: [
|
215
|
+
referencedColumns: [identifiers.ID_COLUMN],
|
178
216
|
referencedTable: identifiers.getTableName(contentType.collectionName),
|
179
217
|
onDelete: "CASCADE"
|
180
218
|
}
|
181
219
|
]
|
182
220
|
};
|
183
221
|
};
|
184
|
-
const transformContentTypesToModels = (contentTypes) => {
|
222
|
+
const transformContentTypesToModels = (contentTypes, identifiers) => {
|
185
223
|
const models = [];
|
186
224
|
contentTypes.forEach((contentType) => {
|
187
225
|
assert(contentType.collectionName, 'Content type "collectionName" is required');
|
188
226
|
assert(contentType.modelName, 'Content type "modelName" is required');
|
189
227
|
assert(contentType.uid, 'Content type "uid" is required');
|
190
228
|
const documentIdAttribute = contentType.modelType === "contentType" ? { documentId: { type: "string", default: createDocumentId } } : {};
|
191
|
-
const reservedAttributeNames = ["document_id",
|
229
|
+
const reservedAttributeNames = ["document_id", identifiers.ID_COLUMN];
|
192
230
|
Object.keys(contentType.attributes || {}).forEach((attributeName) => {
|
193
231
|
const snakeCasedAttributeName = _.snakeCase(attributeName);
|
194
232
|
if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
|
@@ -198,19 +236,20 @@ const transformContentTypesToModels = (contentTypes) => {
|
|
198
236
|
}
|
199
237
|
});
|
200
238
|
if (hasComponentsOrDz(contentType)) {
|
201
|
-
const compoLinkModel = createCompoLinkModel(contentType);
|
239
|
+
const compoLinkModel = createCompoLinkModel(contentType, identifiers);
|
202
240
|
models.push(compoLinkModel);
|
203
241
|
}
|
204
242
|
const model = {
|
205
243
|
uid: contentType.uid,
|
206
244
|
singularName: contentType.modelName,
|
207
|
-
tableName:
|
245
|
+
tableName: contentType.collectionName,
|
246
|
+
// This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice
|
208
247
|
attributes: {
|
209
|
-
[
|
248
|
+
[identifiers.ID_COLUMN]: {
|
210
249
|
type: "increments"
|
211
250
|
},
|
212
251
|
...documentIdAttribute,
|
213
|
-
...transformAttributes(contentType)
|
252
|
+
...transformAttributes(contentType, identifiers)
|
214
253
|
}
|
215
254
|
};
|
216
255
|
models.push(model);
|
@@ -218,13 +257,12 @@ const transformContentTypesToModels = (contentTypes) => {
|
|
218
257
|
return models;
|
219
258
|
};
|
220
259
|
export {
|
221
|
-
COMPONENT_INVERSE_COLUMN_NAME,
|
222
|
-
COMPONENT_JOIN_TABLE_SUFFIX,
|
223
|
-
COMPONENT_TYPE_COLUMN,
|
224
|
-
DZ_JOIN_TABLE_SUFFIX,
|
225
|
-
ENTITY,
|
226
260
|
createDocumentId,
|
261
|
+
getComponentFkIndexName,
|
262
|
+
getComponentJoinColumnEntityName,
|
263
|
+
getComponentJoinColumnInverseName,
|
227
264
|
getComponentJoinTableName,
|
265
|
+
getComponentTypeColumn,
|
228
266
|
getDzJoinTableName,
|
229
267
|
hasComponentsOrDz,
|
230
268
|
transformAttribute,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, utils } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\nconst { identifiers } = utils;\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n */\n\nexport const COMPONENT_JOIN_TABLE_SUFFIX = 'components';\nexport const DZ_JOIN_TABLE_SUFFIX = 'components';\nexport const COMPONENT_INVERSE_COLUMN_NAME = 'component';\nexport const COMPONENT_TYPE_COLUMN = 'component_type';\nexport const ENTITY = 'entity';\n\nexport const getComponentJoinTableName = (collectionName: string) =>\n identifiers.getTableName(collectionName, { suffix: COMPONENT_JOIN_TABLE_SUFFIX });\n\nexport const getDzJoinTableName = (collectionName: string) =>\n identifiers.getTableName(collectionName, { suffix: DZ_JOIN_TABLE_SUFFIX });\n\nconst { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName);\n const joinColumnEntityName = identifiers.getJoinColumnAttributeIdName(ENTITY);\n const joinColumnInverseName = identifiers.getJoinColumnAttributeIdName(\n COMPONENT_INVERSE_COLUMN_NAME\n );\n\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n on: {\n field: name,\n },\n orderColumnName: order,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, COMPONENT_TYPE_COLUMN],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName);\n const joinColumnEntityName = identifiers.getJoinColumnAttributeIdName(ENTITY);\n const joinColumnInverseName = identifiers.getJoinColumnAttributeIdName(\n COMPONENT_INVERSE_COLUMN_NAME\n );\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: id,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: id,\n },\n typeColumn: {\n name: COMPONENT_TYPE_COLUMN,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [joinColumnEntityName, joinColumnInverseName, field, COMPONENT_TYPE_COLUMN],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (contentType: LoadedContentTypeModel) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(attrName, contentType.attributes[attrName]!, contentType),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n ({ type }) => type === 'dynamiczone' || type === 'component'\n );\n};\n\nexport const createDocumentId = createId;\n\n// Creates the\nconst createCompoLinkModel = (contentType: LoadedContentTypeModel): Model => {\n const name = getComponentJoinTableName(contentType.collectionName);\n\n const entityId = identifiers.getJoinColumnAttributeIdName(ENTITY);\n const componentId = identifiers.getJoinColumnAttributeIdName(COMPONENT_INVERSE_COLUMN_NAME);\n const fkIndex = identifiers.getFkIndexName([contentType.collectionName, ENTITY]);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [id]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [COMPONENT_TYPE_COLUMN]: {\n type: 'string',\n },\n [field]: {\n type: 'string',\n },\n [order]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, field]),\n columns: [field],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, COMPONENT_TYPE_COLUMN]),\n columns: [COMPONENT_TYPE_COLUMN],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, field, COMPONENT_TYPE_COLUMN],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [id],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (contentTypes: LoadedContentTypeModel[]): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', id];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: identifiers.getTableName(contentType.collectionName),\n attributes: {\n [id]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":[],"mappings":";;;;AAMA,MAAM,EAAE,YAAgB,IAAA;AASjB,MAAM,8BAA8B;AACpC,MAAM,uBAAuB;AAC7B,MAAM,gCAAgC;AACtC,MAAM,wBAAwB;AAC9B,MAAM,SAAS;AAET,MAAA,4BAA4B,CAAC,mBACxC,YAAY,aAAa,gBAAgB,EAAE,QAAQ,6BAA6B;AAErE,MAAA,qBAAqB,CAAC,mBACjC,YAAY,aAAa,gBAAgB,EAAE,QAAQ,sBAAsB;AAE3E,MAAM,EAAE,WAAW,IAAI,cAAc,OAAO,cAAc,MAAU,IAAA;AAM7D,MAAM,qBAAqB,CAChC,MACA,WACA,gBACG;AACH,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK,SAAS;AACL,aAAA;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BAAiB,EAAA,IAC1D,CAAA;AAIA,UAAA,yBAAyB,CAAC,eAAe,EAAE;AAC1C,WAAA,KAAK,YAAY,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,kBAAkB;AAC7D,YAAA,0BAA0B,EAAE,UAAU,aAAa;AACrD,UAAA,uBAAuB,SAAS,uBAAuB,GAAG;AAC5D,cAAM,IAAI;AAAA,UACR,kBAAkB,aAAa,+DAA+D,YAAY,SAAS,gBAAgB,aAAa;AAAA,QAAA;AAAA,MAEpJ;AAAA,IAAA,CACD;AAEG,QAAA,kBAAkB,WAAW,GAAG;AAC5B,YAAA,iBAAiB,qBAAqB,WAAW;AACvD,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,UAAM,QAAe;AAAA,MACnB,KAAK,YAAY;AAAA,MACjB,cAAc,YAAY;AAAA,MAC1B,WAAW,YAAY,aAAa,YAAY,cAAc;AAAA,MAC9D,YAAY;AAAA,QACV,CAAC,EAAE,GAAG;AAAA,UACJ,MAAM;AAAA,QACR;AAAA,QACA,GAAG;AAAA,QACH,GAAG,oBAAoB,WAAW;AAAA,MACpC;AAAA,IAAA;AAGF,WAAO,KAAK,KAAK;AAAA,EAAA,CAClB;AAEM,SAAA;AACT;"}
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.mjs","sources":["../../src/utils/transform-content-types-to-models.ts"],"sourcesContent":["import { type Model, type Identifiers } from '@strapi/database';\nimport type { Struct, Schema } from '@strapi/types';\nimport { createId } from '@paralleldrive/cuid2';\nimport assert from 'node:assert';\nimport _ from 'lodash/fp';\n\n/**\n * Because strapi/database models don't know about things like components or dynamic zones, we use this file to convert them\n * to a relations format that it recognizes\n *\n * Therefore we have to keep an additional set of helpers/extensions to the database naming methods\n *\n * IMPORTANT!\n * If we use short versions of anything, we MUST call getNameFromTokens directly; attempting to shorten them ourselves\n * prevents the unshortened name map from being filled properly, so for example it will think that the short name\n * 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'\n * Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening\n */\n\nexport const getComponentJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getDzJoinTableName = (collectionName: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: collectionName, compressible: true },\n { name: 'components', shortName: 'cmps', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnEntityName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'entity', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentJoinColumnInverseName = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: 'component', shortName: 'cmp', compressible: false },\n { name: 'id', compressible: false },\n ]);\n};\n\nexport const getComponentTypeColumn = (identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([{ name: 'component_type', compressible: false }]);\n};\n\nexport const getComponentFkIndexName = (contentType: string, identifiers: Identifiers) => {\n return identifiers.getNameFromTokens([\n { name: contentType, compressible: true },\n { name: 'entity', compressible: false },\n { name: 'fk', compressible: false },\n ]);\n};\n\n// const { ID_COLUMN: id, FIELD_COLUMN: field, ORDER_COLUMN: order } = identifiers;\n\nexport type LoadedContentTypeModel = Struct.ContentTypeSchema &\n Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;\n\n// Transforms an attribute (particularly for relation types) into the format that strapi/database accepts\nexport const transformAttribute = (\n name: string,\n attribute: Schema.Attribute.AnyAttribute,\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n switch (attribute.type) {\n case 'media': {\n return {\n type: 'relation',\n relation: attribute.multiple === true ? 'morphMany' : 'morphOne',\n target: 'plugin::upload.file',\n morphBy: 'related',\n };\n }\n case 'component': {\n const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n return {\n type: 'relation',\n relation: attribute.repeatable === true ? 'oneToMany' : 'oneToOne',\n target: attribute.component,\n\n // We need the join table name to be deterministic,\n // We need to allow passing the join table name as an option\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n inverseJoinColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n on: {\n field: name,\n },\n orderColumnName: identifiers.ORDER_COLUMN,\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n case 'dynamiczone': {\n const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);\n const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);\n const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n\n return {\n type: 'relation',\n relation: 'morphToMany',\n // TODO: handle restrictions at some point\n // target: attribute.components,\n joinTable: {\n name: joinTableName,\n joinColumn: {\n name: joinColumnEntityName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n morphColumn: {\n idColumn: {\n name: joinColumnInverseName,\n referencedColumn: identifiers.ID_COLUMN,\n },\n typeColumn: {\n name: compTypeColumn,\n },\n typeField: '__component',\n },\n on: {\n field: name,\n },\n orderBy: {\n order: 'asc',\n },\n pivotColumns: [\n joinColumnEntityName,\n joinColumnInverseName,\n identifiers.FIELD_COLUMN,\n compTypeColumn,\n ],\n },\n };\n }\n default: {\n return attribute;\n }\n }\n};\n\nexport const transformAttributes = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n) => {\n return Object.keys(contentType.attributes! || {}).reduce((attrs, attrName) => {\n return {\n ...attrs,\n [attrName]: transformAttribute(\n attrName,\n contentType.attributes[attrName]!,\n contentType,\n identifiers\n ),\n };\n }, {});\n};\n\nexport const hasComponentsOrDz = (\n contentType: LoadedContentTypeModel\n): contentType is LoadedContentTypeModel & { type: 'dynamiczone' | 'component' } => {\n return Object.values(contentType.attributes || {}).some(\n (({ type }: { type: string }) => type === 'dynamiczone' || type === 'component') as any\n );\n};\n\nexport const createDocumentId = createId;\n\nconst createCompoLinkModel = (\n contentType: LoadedContentTypeModel,\n identifiers: Identifiers\n): Model => {\n const name = getComponentJoinTableName(contentType.collectionName, identifiers);\n\n const entityId = getComponentJoinColumnEntityName(identifiers);\n const componentId = getComponentJoinColumnInverseName(identifiers);\n const compTypeColumn = getComponentTypeColumn(identifiers);\n const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);\n\n return {\n // TODO: make sure there can't be any conflicts with a prefix\n singularName: name,\n uid: name,\n tableName: name,\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n [entityId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [componentId]: {\n type: 'integer',\n column: {\n unsigned: true,\n },\n },\n [compTypeColumn]: {\n type: 'string',\n },\n [identifiers.FIELD_COLUMN]: {\n type: 'string',\n },\n [identifiers.ORDER_COLUMN]: {\n type: 'float',\n column: {\n unsigned: true,\n defaultTo: null,\n },\n },\n },\n indexes: [\n {\n name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),\n columns: [identifiers.FIELD_COLUMN],\n },\n {\n name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),\n columns: [compTypeColumn],\n },\n {\n name: fkIndex,\n columns: [entityId],\n },\n {\n // NOTE: since we don't include attribute names, we need to be careful not to create another unique index\n name: identifiers.getUniqueIndexName([contentType.collectionName]),\n columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],\n type: 'unique',\n },\n ],\n foreignKeys: [\n {\n name: fkIndex,\n columns: [entityId],\n referencedColumns: [identifiers.ID_COLUMN],\n referencedTable: identifiers.getTableName(contentType.collectionName),\n onDelete: 'CASCADE',\n },\n ],\n };\n};\n\nexport const transformContentTypesToModels = (\n contentTypes: LoadedContentTypeModel[],\n identifiers: Identifiers\n): Model[] => {\n const models: Model[] = [];\n\n contentTypes.forEach((contentType) => {\n assert(contentType.collectionName, 'Content type \"collectionName\" is required');\n assert(contentType.modelName, 'Content type \"modelName\" is required');\n assert(contentType.uid, 'Content type \"uid\" is required');\n\n // Add document id to content types\n // as it is not documented\n const documentIdAttribute: Record<string, Schema.Attribute.AnyAttribute> =\n contentType.modelType === 'contentType'\n ? { documentId: { type: 'string', default: createDocumentId } }\n : {};\n\n // TODO: this needs to be combined with getReservedNames, we should not be maintaining two lists\n // Prevent user from creating a documentId attribute\n const reservedAttributeNames = ['document_id', identifiers.ID_COLUMN];\n Object.keys(contentType.attributes || {}).forEach((attributeName) => {\n const snakeCasedAttributeName = _.snakeCase(attributeName);\n if (reservedAttributeNames.includes(snakeCasedAttributeName)) {\n throw new Error(\n `The attribute \"${attributeName}\" is reserved and cannot be used in a model. Please rename \"${contentType.modelName}\" attribute \"${attributeName}\" to something else.`\n );\n }\n });\n\n if (hasComponentsOrDz(contentType)) {\n const compoLinkModel = createCompoLinkModel(contentType, identifiers);\n models.push(compoLinkModel);\n }\n\n const model: Model = {\n uid: contentType.uid,\n singularName: contentType.modelName,\n tableName: contentType.collectionName, // This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice\n attributes: {\n [identifiers.ID_COLUMN]: {\n type: 'increments',\n },\n ...documentIdAttribute,\n ...transformAttributes(contentType, identifiers),\n },\n };\n\n models.push(model);\n });\n\n return models;\n};\n"],"names":[],"mappings":";;;AAmBa,MAAA,4BAA4B,CAAC,gBAAwB,gBAA6B;AAC7F,SAAO,YAAY,kBAAkB;AAAA,IACnC,EAAE,MAAM,gBAAgB,cAAc,KAAK;AAAA,IAC3C,EAAE,MAAM,cAAc,WAAW,QAAQ,cAAc,MAAM;AAAA,EAAA,CAC9D;AACH;AAEa,MAAA,qBAAqB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AAe,YAAY,SAAS;AAC7D,WAAA,KAAK,YAAY,cAAc,CAAA,CAAE,EAAE,QAAQ,CAAC,kBAAkB;AAC7D,YAAA,0BAA0B,EAAE,UAAU,aAAa;AACrD,UAAA,uBAAuB,SAAS,uBAAuB,GAAG;AAC5D,cAAM,IAAI;AAAA,UACR,kBAAkB,aAAa,+DAA+D,YAAY,SAAS,gBAAgB,aAAa;AAAA,QAAA;AAAA,MAEpJ;AAAA,IAAA,CACD;AAEG,QAAA,kBAAkB,WAAW,GAAG;AAC5B,YAAA,iBAAiB,qBAAqB,aAAa,WAAW;AACpE,aAAO,KAAK,cAAc;AAAA,IAC5B;AAEA,UAAM,QAAe;AAAA,MACnB,KAAK,YAAY;AAAA,MACjB,cAAc,YAAY;AAAA,MAC1B,WAAW,YAAY;AAAA;AAAA,MACvB,YAAY;AAAA,QACV,CAAC,YAAY,SAAS,GAAG;AAAA,UACvB,MAAM;AAAA,QACR;AAAA,QACA,GAAG;AAAA,QACH,GAAG,oBAAoB,aAAa,WAAW;AAAA,MACjD;AAAA,IAAA;AAGF,WAAO,KAAK,KAAK;AAAA,EAAA,CAClB;AAEM,SAAA;AACT;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@strapi/core",
|
3
|
-
"version": "5.0.0-beta.
|
3
|
+
"version": "5.0.0-beta.2",
|
4
4
|
"description": "Core of Strapi",
|
5
5
|
"homepage": "https://strapi.io",
|
6
6
|
"bugs": {
|
@@ -42,7 +42,7 @@
|
|
42
42
|
"resources/"
|
43
43
|
],
|
44
44
|
"scripts": {
|
45
|
-
"build": "
|
45
|
+
"build": "pack-up build && run copy-files",
|
46
46
|
"clean": "run -T rimraf ./dist",
|
47
47
|
"copy-files": "copyfiles -u 1 -a 'src/**/*.html' 'src/**/*.png' dist",
|
48
48
|
"lint": "run -T eslint .",
|
@@ -55,16 +55,16 @@
|
|
55
55
|
"@koa/cors": "3.4.3",
|
56
56
|
"@koa/router": "10.1.1",
|
57
57
|
"@paralleldrive/cuid2": "2.2.2",
|
58
|
-
"@strapi/admin": "5.0.0-beta.
|
59
|
-
"@strapi/database": "5.0.0-beta.
|
60
|
-
"@strapi/generate-new": "5.0.0-beta.
|
61
|
-
"@strapi/generators": "5.0.0-beta.
|
62
|
-
"@strapi/logger": "5.0.0-beta.
|
63
|
-
"@strapi/pack-up": "5.0.0-beta.
|
64
|
-
"@strapi/permissions": "5.0.0-beta.
|
65
|
-
"@strapi/types": "5.0.0-beta.
|
66
|
-
"@strapi/typescript-utils": "5.0.0-beta.
|
67
|
-
"@strapi/utils": "5.0.0-beta.
|
58
|
+
"@strapi/admin": "5.0.0-beta.2",
|
59
|
+
"@strapi/database": "5.0.0-beta.2",
|
60
|
+
"@strapi/generate-new": "5.0.0-beta.2",
|
61
|
+
"@strapi/generators": "5.0.0-beta.2",
|
62
|
+
"@strapi/logger": "5.0.0-beta.2",
|
63
|
+
"@strapi/pack-up": "5.0.0-beta.2",
|
64
|
+
"@strapi/permissions": "5.0.0-beta.2",
|
65
|
+
"@strapi/types": "5.0.0-beta.2",
|
66
|
+
"@strapi/typescript-utils": "5.0.0-beta.2",
|
67
|
+
"@strapi/utils": "5.0.0-beta.2",
|
68
68
|
"bcryptjs": "2.4.3",
|
69
69
|
"boxen": "5.1.2",
|
70
70
|
"chalk": "4.1.2",
|
@@ -122,13 +122,13 @@
|
|
122
122
|
"@types/node": "18.19.24",
|
123
123
|
"@types/node-schedule": "2.1.0",
|
124
124
|
"@types/statuses": "2.0.1",
|
125
|
-
"eslint-config-custom": "5.0.0-beta.
|
125
|
+
"eslint-config-custom": "5.0.0-beta.2",
|
126
126
|
"supertest": "6.3.3",
|
127
|
-
"tsconfig": "5.0.0-beta.
|
127
|
+
"tsconfig": "5.0.0-beta.2"
|
128
128
|
},
|
129
129
|
"engines": {
|
130
130
|
"node": ">=18.0.0 <=20.x.x",
|
131
131
|
"npm": ">=6.0.0"
|
132
132
|
},
|
133
|
-
"gitHead": "
|
133
|
+
"gitHead": "e39426bd12ead73ca35d3d9bbf6dc71b5e8ac354"
|
134
134
|
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"output-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/output-ids.ts"],"names":[],"mappings":""}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const _ = require("lodash/fp");
|
4
|
-
const isShortHand = (relation) => {
|
5
|
-
return typeof relation === "string" || typeof relation === "number";
|
6
|
-
};
|
7
|
-
const isLongHand = (relation) => {
|
8
|
-
return _.isObject(relation) && ("id" in relation || "documentId" in relation);
|
9
|
-
};
|
10
|
-
exports.isLongHand = isLongHand;
|
11
|
-
exports.isShortHand = isShortHand;
|
12
|
-
//# sourceMappingURL=data.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"data.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { ID, LongHand } from './types';\n\nexport const isShortHand = (relation: any): relation is ID => {\n return typeof relation === 'string' || typeof relation === 'number';\n};\n\nexport const isLongHand = (relation: any): relation is LongHand => {\n return isObject(relation) && ('id' in relation || 'documentId' in relation);\n};\n"],"names":["isObject"],"mappings":";;;AAGa,MAAA,cAAc,CAAC,aAAkC;AAC5D,SAAO,OAAO,aAAa,YAAY,OAAO,aAAa;AAC7D;AAEa,MAAA,aAAa,CAAC,aAAwC;AACjE,SAAOA,EAAAA,SAAS,QAAQ,MAAM,QAAQ,YAAY,gBAAgB;AACpE;;;"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { isObject } from "lodash/fp";
|
2
|
-
const isShortHand = (relation) => {
|
3
|
-
return typeof relation === "string" || typeof relation === "number";
|
4
|
-
};
|
5
|
-
const isLongHand = (relation) => {
|
6
|
-
return isObject(relation) && ("id" in relation || "documentId" in relation);
|
7
|
-
};
|
8
|
-
export {
|
9
|
-
isLongHand,
|
10
|
-
isShortHand
|
11
|
-
};
|
12
|
-
//# sourceMappingURL=data.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"data.mjs","sources":["../../../../../../src/services/document-service/transform/relations/utils/data.ts"],"sourcesContent":["import { isObject } from 'lodash/fp';\nimport { ID, LongHand } from './types';\n\nexport const isShortHand = (relation: any): relation is ID => {\n return typeof relation === 'string' || typeof relation === 'number';\n};\n\nexport const isLongHand = (relation: any): relation is LongHand => {\n return isObject(relation) && ('id' in relation || 'documentId' in relation);\n};\n"],"names":[],"mappings":";AAGa,MAAA,cAAc,CAAC,aAAkC;AAC5D,SAAO,OAAO,aAAa,YAAY,OAAO,aAAa;AAC7D;AAEa,MAAA,aAAa,CAAC,aAAwC;AACjE,SAAO,SAAS,QAAQ,MAAM,QAAQ,YAAY,gBAAgB;AACpE;"}
|