@haus-tech/product-import-export-plugin 3.6.3 → 3.6.5
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/CHANGELOG.md +26 -54
- package/{README.mdx → README.md} +64 -35
- package/package.json +10 -10
- package/src/dashboard/bulk-export.tsx +1 -0
- package/src/dashboard/export-configuration-panel.tsx +448 -0
- package/src/dashboard/export-dialog.tsx +22 -285
- package/src/dashboard/export.tsx +52 -17
- package/src/dashboard/exported-list.tsx +176 -96
- package/src/dashboard/import.tsx +286 -149
- package/src/dashboard/index.tsx +27 -28
- package/src/dashboard/use-active-channel-key.ts +7 -0
- package/src/product-import-export.plugin.d.ts +6 -0
- package/src/product-import-export.plugin.js +29 -1
- package/src/product-import-export.plugin.js.map +1 -1
- package/src/providers/import-providers/asset-importer.js +27 -8
- package/src/providers/import-providers/asset-importer.js.map +1 -1
- package/src/providers/import-providers/import-parser.d.ts +1 -0
- package/src/providers/import-providers/import-parser.js +42 -4
- package/src/providers/import-providers/import-parser.js.map +1 -1
- package/src/providers/import-providers/product-importer.d.ts +10 -0
- package/src/providers/import-providers/product-importer.js +111 -20
- package/src/providers/import-providers/product-importer.js.map +1 -1
- package/src/services/export-storage/export-storage-strategy.d.ts +8 -0
- package/src/services/extended-fast-importer.service.js +20 -12
- package/src/services/extended-fast-importer.service.js.map +1 -1
- package/src/services/import-storage/import-job-storage-strategy.d.ts +9 -0
- package/src/services/product-export.service.d.ts +20 -6
- package/src/services/product-export.service.js +174 -45
- package/src/services/product-export.service.js.map +1 -1
- package/src/services/self-relation-custom-fields.d.ts +26 -0
- package/src/services/self-relation-custom-fields.js +67 -0
- package/src/services/self-relation-custom-fields.js.map +1 -0
- package/src/types.d.ts +7 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitSelfRelationCustomFields = splitSelfRelationCustomFields;
|
|
4
|
+
exports.loadSelfRelationCustomFieldIds = loadSelfRelationCustomFieldIds;
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
/** Owner ids per query, far below Postgres' 65 535 bind parameter limit. */
|
|
7
|
+
const ID_CHUNK_SIZE = 1000;
|
|
8
|
+
/**
|
|
9
|
+
* Splits an entity's relation custom fields into paths that can be loaded through
|
|
10
|
+
* `ProductService.findAll` / repository `relations`, and self-referencing fields (a Product field
|
|
11
|
+
* relating to Product, a ProductVariant field relating to ProductVariant). TypeORM joins a
|
|
12
|
+
* self-referencing relation under the owner table's own alias a second time, which Postgres rejects
|
|
13
|
+
* ("table name specified more than once"), so those must be loaded with
|
|
14
|
+
* {@link loadSelfRelationCustomFieldIds} instead.
|
|
15
|
+
*/
|
|
16
|
+
function splitSelfRelationCustomFields(fields, owner, prefix) {
|
|
17
|
+
const relationFields = fields.filter((field) => field.type === 'relation');
|
|
18
|
+
return {
|
|
19
|
+
relations: relationFields
|
|
20
|
+
.filter((field) => field.entity !== owner)
|
|
21
|
+
.map((field) => `${prefix}${field.name}`),
|
|
22
|
+
selfRelationNames: relationFields
|
|
23
|
+
.filter((field) => field.entity === owner)
|
|
24
|
+
.map((field) => field.name),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Loads the related ids of self-referencing relation custom fields with an explicit join alias,
|
|
29
|
+
* one query per field. Returns a map keyed by the stringified owner id; each entry holds every
|
|
30
|
+
* requested field: `ID | null` for a single relation, `ID[]` (possibly empty) for a list.
|
|
31
|
+
*/
|
|
32
|
+
async function loadSelfRelationCustomFieldIds(repository, alias, ids, fields) {
|
|
33
|
+
const byOwnerId = new Map();
|
|
34
|
+
if (ids.length === 0 || fields.length === 0) {
|
|
35
|
+
return byOwnerId;
|
|
36
|
+
}
|
|
37
|
+
for (const id of ids) {
|
|
38
|
+
byOwnerId.set(String(id), Object.fromEntries(fields.map((field) => [field.name, field.list ? [] : null])));
|
|
39
|
+
}
|
|
40
|
+
for (const [field, idChunk] of fields.flatMap((field) => (0, lodash_1.chunk)(ids, ID_CHUNK_SIZE).map((idChunk) => [field, idChunk]))) {
|
|
41
|
+
const rows = await repository
|
|
42
|
+
.createQueryBuilder(alias)
|
|
43
|
+
.select(`${alias}.id`, 'ownerId')
|
|
44
|
+
.addSelect('related.id', 'relatedId')
|
|
45
|
+
.innerJoin(`${alias}.customFields.${field.name}`, 'related')
|
|
46
|
+
.where(`${alias}.id IN (:...ids)`, { ids: idChunk })
|
|
47
|
+
// A stable order for list fields; the join table stores no position.
|
|
48
|
+
.orderBy('related.id', 'ASC')
|
|
49
|
+
.getRawMany();
|
|
50
|
+
for (const row of rows) {
|
|
51
|
+
const entry = byOwnerId.get(String(row.ownerId));
|
|
52
|
+
if (!entry) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const current = entry[field.name];
|
|
56
|
+
if (Array.isArray(current)) {
|
|
57
|
+
// The array was created above for this call only, so appending in place is safe.
|
|
58
|
+
current.push(row.relatedId);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
entry[field.name] = row.relatedId;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return byOwnerId;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=self-relation-custom-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-relation-custom-fields.js","sourceRoot":"","sources":["../../../../../packages/product-import-export-plugin/src/services/self-relation-custom-fields.ts"],"names":[],"mappings":";;AAsBA,sEAcC;AAOD,wEA2CC;AArFD,mCAA8B;AAG9B,4EAA4E;AAC5E,MAAM,aAAa,GAAG,IAAI,CAAA;AAS1B;;;;;;;GAOG;AACH,SAAgB,6BAA6B,CAC3C,MAA2B,EAC3B,KAA6C,EAC7C,MAAc;IAEd,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK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AC,KAAK,EAAE,OAAO,CAAU,CAAC,CACtE,EAAE,CAAC;QACF,MAAM,IAAI,GAAG,MAAO,UAAmD;aACpE,kBAAkB,CAAC,KAAK,CAAC;aACzB,MAAM,CAAC,GAAG,KAAK,KAAK,EAAE,SAAS,CAAC;aAChC,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC;aACpC,SAAS,CAAC,GAAG,KAAK,iBAAiB,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC;aAC3D,KAAK,CAAC,GAAG,KAAK,kBAAkB,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;YACpD,qEAAqE;aACpE,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC;aAC5B,UAAU,EAAkC,CAAA;QAC/C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;YAChD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,SAAQ;YACV,CAAC;YACD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACjC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC3B,iFAAiF;gBACjF,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7B,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,SAAS,CAAA;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
package/src/types.d.ts
CHANGED
|
@@ -36,6 +36,13 @@ type ImportOptions = {
|
|
|
36
36
|
*/
|
|
37
37
|
importJobStorage?: 'local' | 's3';
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* @description
|
|
41
|
+
* Options passed to {@link ProductImportExportPlugin}.init to configure import and
|
|
42
|
+
* export behaviour, including which storage strategy backs each operation.
|
|
43
|
+
*
|
|
44
|
+
* @category Options
|
|
45
|
+
*/
|
|
39
46
|
export interface PluginInitOptions {
|
|
40
47
|
importOptions: {
|
|
41
48
|
visibleOptions?: Array<keyof ImportOptions>;
|