@sanity/cross-dataset-duplicator 1.4.0-beta.2 → 1.4.1
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/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/index.d.ts +4 -8
- package/dist/index.esm.js +58 -49
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +57 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Duplicator.tsx +4 -2
- package/src/components/DuplicatorQuery.tsx +33 -11
- package/src/components/StatusBadge.tsx +5 -1
- package/src/helpers/constants.ts +1 -0
- package/src/helpers/getDocumentsInArray.ts +10 -57
- package/src/types/index.ts +4 -9
|
@@ -10,21 +10,10 @@ type OptionsBag = {
|
|
|
10
10
|
projection?: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const isAsset = (doc: SanityDocument) =>
|
|
14
|
-
doc._type === 'sanity.imageAsset' || doc._type === 'sanity.fileAsset'
|
|
15
|
-
|
|
16
|
-
const returnOnlyAssets = (references: SanityDocument[]) =>
|
|
17
|
-
references.filter((item) => isAsset(item))
|
|
18
|
-
|
|
19
13
|
// Recursively fetch Documents from an array of _id's and their references
|
|
20
14
|
// Heavy use of Set is to avoid recursively querying for id's already in the payload
|
|
21
|
-
|
|
22
|
-
export async function getDocumentsInArray(
|
|
23
|
-
options: OptionsBag,
|
|
24
|
-
recurrsionDepth: number = 0
|
|
25
|
-
): Promise<SanityDocument[]> {
|
|
15
|
+
export async function getDocumentsInArray(options: OptionsBag): Promise<SanityDocument[]> {
|
|
26
16
|
const {fetchIds, client, pluginConfig, currentIds, projection} = options
|
|
27
|
-
const {reference} = pluginConfig
|
|
28
17
|
const collection: SanityDocument[] = []
|
|
29
18
|
|
|
30
19
|
// Find initial docs
|
|
@@ -67,51 +56,15 @@ export async function getDocumentsInArray(
|
|
|
67
56
|
|
|
68
57
|
if (newReferenceIds.size) {
|
|
69
58
|
// Recursive query for new documents
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
client,
|
|
80
|
-
pluginConfig,
|
|
81
|
-
},
|
|
82
|
-
recurrsionDepth
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
// I know this is a bit messy... but I hit the max nesting eslint limit
|
|
86
|
-
if (
|
|
87
|
-
// // If we are at the max depth and reference?.assetsOnly is falsy
|
|
88
|
-
referenceDocs?.length &&
|
|
89
|
-
recurrsionDepth === reference.maxDepth + 1 &&
|
|
90
|
-
!reference?.assetsOnly
|
|
91
|
-
) {
|
|
92
|
-
collection.push(...referenceDocs)
|
|
93
|
-
} else if (
|
|
94
|
-
// // If we are at the max depth and reference?.assetsOnly is truthy
|
|
95
|
-
referenceDocs?.length &&
|
|
96
|
-
recurrsionDepth === reference.maxDepth + 1 &&
|
|
97
|
-
reference?.assetsOnly
|
|
98
|
-
) {
|
|
99
|
-
collection.push(...returnOnlyAssets(referenceDocs))
|
|
100
|
-
} else if (referenceDocs?.length && recurrsionDepth < reference.maxDepth + 1) {
|
|
101
|
-
// // If we are not at the max depth
|
|
102
|
-
collection.push(...referenceDocs)
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
const referenceDocs = await getDocumentsInArray({
|
|
106
|
-
fetchIds: Array.from(newReferenceIds),
|
|
107
|
-
currentIds: localCurrentIds,
|
|
108
|
-
client,
|
|
109
|
-
pluginConfig,
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
if (referenceDocs?.length) {
|
|
113
|
-
collection.push(...referenceDocs)
|
|
114
|
-
}
|
|
59
|
+
const referenceDocs = await getDocumentsInArray({
|
|
60
|
+
fetchIds: Array.from(newReferenceIds),
|
|
61
|
+
currentIds: localCurrentIds,
|
|
62
|
+
client,
|
|
63
|
+
pluginConfig,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
if (referenceDocs?.length) {
|
|
67
|
+
collection.push(...referenceDocs)
|
|
115
68
|
}
|
|
116
69
|
}
|
|
117
70
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import {SanityDocument} from 'sanity'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export type reference = {
|
|
8
|
-
maxDepth: number // Number of documents deep to follow
|
|
9
|
-
assetsOnly?: boolean // If true, only gather image and file assets
|
|
3
|
+
type PreDefinedQuery = {
|
|
4
|
+
label: string
|
|
5
|
+
query: string
|
|
10
6
|
}
|
|
11
|
-
|
|
12
7
|
/**
|
|
13
8
|
* Plugin configuration
|
|
14
9
|
* @public
|
|
@@ -18,7 +13,7 @@ export interface PluginConfig {
|
|
|
18
13
|
types?: string[]
|
|
19
14
|
filter?: string
|
|
20
15
|
follow?: ('inbound' | 'outbound')[]
|
|
21
|
-
|
|
16
|
+
queries?: PreDefinedQuery[]
|
|
22
17
|
}
|
|
23
18
|
|
|
24
19
|
/**
|