sanity 3.77.3-server-side-schemas.36 → 3.77.3-server-side-schemas.37
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/lib/_chunks-cjs/_internal.js +1 -1
- package/lib/_chunks-cjs/_internal.js.map +1 -1
- package/lib/_chunks-cjs/deleteSchemaAction.js +21 -25
- package/lib/_chunks-cjs/deleteSchemaAction.js.map +1 -1
- package/lib/_chunks-cjs/listSchemasAction.js +3 -5
- package/lib/_chunks-cjs/listSchemasAction.js.map +1 -1
- package/lib/_chunks-cjs/schemaApiClient.js +0 -20
- package/lib/_chunks-cjs/schemaApiClient.js.map +1 -1
- package/lib/_chunks-cjs/storeSchemaOutStrings.js +14 -0
- package/lib/_chunks-cjs/storeSchemaOutStrings.js.map +1 -0
- package/lib/_chunks-cjs/version.js +1 -1
- package/lib/_chunks-es/version.mjs +1 -1
- package/lib/_legacy/version.esm.js +1 -1
- package/package.json +10 -10
- package/src/_internal/cli/actions/schema/deleteSchemaAction.ts +43 -48
- package/src/_internal/cli/actions/schema/listSchemasAction.ts +0 -3
- package/src/_internal/cli/actions/schema/utils/schemaStoreValidation.ts +2 -2
- package/src/_internal/cli/actions/schema/utils/storeSchemaOutStrings.ts +4 -0
- package/src/_internal/cli/commands/schema/deleteSchemaCommand.ts +1 -1
@@ -3,18 +3,16 @@ import chalk from 'chalk'
|
|
3
3
|
import uniq from 'lodash/uniq'
|
4
4
|
|
5
5
|
import {isDefined} from '../../../manifest/manifestTypeHelpers'
|
6
|
-
import {type ManifestWorkspaceFile} from '../../../manifest/manifestTypes'
|
7
6
|
import {type SchemaStoreContext} from './schemaStoreTypes'
|
8
7
|
import {createManifestExtractor, isManifestExtractSatisfied} from './utils/mainfestExtractor'
|
9
8
|
import {createManifestReader} from './utils/manifestReader'
|
10
9
|
import {createSchemaApiClient} from './utils/schemaApiClient'
|
11
10
|
import {
|
12
|
-
assetIdsMatchesWorkspaces,
|
13
11
|
filterLogReadProjectIdMismatch,
|
14
12
|
parseDeleteSchemasConfig,
|
15
13
|
type StoreSchemaCommonFlags,
|
16
14
|
} from './utils/schemaStoreValidation'
|
17
|
-
import {getDatasetsOutString,
|
15
|
+
import {getDatasetsOutString, getStringList} from './utils/storeSchemaOutStrings'
|
18
16
|
|
19
17
|
export interface DeleteSchemaFlags extends StoreSchemaCommonFlags {
|
20
18
|
ids?: string
|
@@ -22,19 +20,19 @@ export interface DeleteSchemaFlags extends StoreSchemaCommonFlags {
|
|
22
20
|
}
|
23
21
|
|
24
22
|
interface DeleteResult {
|
25
|
-
|
23
|
+
dataset: string
|
26
24
|
schemaId: string
|
27
25
|
deleted: boolean
|
28
26
|
}
|
29
27
|
|
30
28
|
class DeleteIdError extends Error {
|
31
29
|
public id: string
|
32
|
-
public
|
33
|
-
constructor(id: string,
|
30
|
+
public dataset: string
|
31
|
+
constructor(id: string, dataset: string, options?: ErrorOptions) {
|
34
32
|
super((options?.cause as {message?: string})?.message, options)
|
35
33
|
this.name = 'DeleteIdError'
|
36
34
|
this.id = id
|
37
|
-
this.
|
35
|
+
this.dataset = dataset
|
38
36
|
}
|
39
37
|
}
|
40
38
|
|
@@ -76,76 +74,73 @@ export async function deleteSchemaAction(
|
|
76
74
|
.filter((workspace) => !dataset || workspace.dataset === dataset)
|
77
75
|
.filter((workspace) => filterLogReadProjectIdMismatch(workspace, projectId, output))
|
78
76
|
|
79
|
-
|
80
|
-
ids.map((id) => id.schemaId),
|
81
|
-
workspaces,
|
82
|
-
)
|
77
|
+
const datasets = uniq(workspaces.map((w) => w.dataset))
|
83
78
|
|
84
79
|
const results = await Promise.allSettled(
|
85
|
-
|
86
|
-
return ids
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
} catch (err) {
|
95
|
-
throw new DeleteIdError(schemaId, workspace, {cause: err})
|
96
|
-
}
|
97
|
-
})
|
80
|
+
datasets.flatMap((targetDataset: string) => {
|
81
|
+
return ids.map(async ({schemaId}): Promise<DeleteResult> => {
|
82
|
+
try {
|
83
|
+
const deletedSchema = await client.withConfig({dataset: targetDataset}).delete(schemaId)
|
84
|
+
return {dataset: targetDataset, schemaId, deleted: deletedSchema.results.length}
|
85
|
+
} catch (err) {
|
86
|
+
throw new DeleteIdError(schemaId, targetDataset, {cause: err})
|
87
|
+
}
|
88
|
+
})
|
98
89
|
}),
|
99
90
|
)
|
100
91
|
|
101
92
|
const deletedIds = results
|
102
93
|
.filter((r): r is PromiseFulfilledResult<DeleteResult> => r.status === 'fulfilled')
|
103
94
|
.filter((r) => r.value.deleted)
|
104
|
-
.map((r) => r.value
|
95
|
+
.map((r) => r.value)
|
105
96
|
|
106
97
|
const notFound = uniq(
|
107
98
|
results
|
108
99
|
.filter((r): r is PromiseFulfilledResult<DeleteResult> => r.status === 'fulfilled')
|
109
100
|
.filter((r) => !r.value.deleted)
|
101
|
+
.filter((r) => !deletedIds.map(({schemaId}) => schemaId).includes(r.value.schemaId))
|
110
102
|
.map((r) => r.value.schemaId),
|
111
103
|
)
|
112
104
|
|
113
|
-
const deleteFailureIds =
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
105
|
+
const deleteFailureIds = uniq(
|
106
|
+
results
|
107
|
+
.filter((r) => r.status === 'rejected')
|
108
|
+
.map((result) => {
|
109
|
+
const error = result.reason
|
110
|
+
if (error instanceof DeleteIdError) {
|
111
|
+
output.error(
|
112
|
+
chalk.red(
|
113
|
+
`Failed to delete schema "${error.id}" in dataset "${error.dataset}":\n${error.message}`,
|
114
|
+
),
|
115
|
+
)
|
116
|
+
if (verbose) output.error(error)
|
117
|
+
return error.id
|
118
|
+
}
|
119
|
+
//hubris inc: given the try-catch wrapping the full promise "this should never happen"
|
120
|
+
throw error
|
121
|
+
}),
|
122
|
+
)
|
129
123
|
|
130
124
|
const success = deletedIds.length === ids.length
|
131
125
|
if (success) {
|
132
126
|
output.success(`Successfully deleted ${deletedIds.length}/${ids.length} schemas`)
|
133
127
|
} else {
|
134
|
-
const datasets = uniq(workspaces.map((w) => w.dataset))
|
135
128
|
output.error(
|
136
129
|
[
|
137
130
|
`Deleted ${deletedIds.length}/${ids.length} schemas.`,
|
138
131
|
deletedIds.length
|
139
|
-
? `Successfully deleted ids:\n
|
132
|
+
? `Successfully deleted ids:\n${deletedIds
|
133
|
+
.map(
|
134
|
+
({schemaId, dataset: targetDataset}) =>
|
135
|
+
`- "${schemaId}" (in ${getDatasetsOutString([targetDataset])})`,
|
136
|
+
)
|
137
|
+
.join('\n')}`
|
140
138
|
: undefined,
|
141
139
|
notFound.length
|
142
|
-
? `Ids not found in ${getDatasetsOutString(datasets)}:\n
|
140
|
+
? `Ids not found in ${getDatasetsOutString(datasets)}:\n${getStringList(notFound)}`
|
143
141
|
: undefined,
|
144
142
|
...(deleteFailureIds.length
|
145
|
-
? [
|
146
|
-
`Failed to delete ids:\n ${getStringArrayOutString(deleteFailureIds)}`,
|
147
|
-
'Check logs for errors.',
|
148
|
-
]
|
143
|
+
? [`Failed to delete ids:\n${getStringList(deleteFailureIds)}`, 'Check logs for errors.']
|
149
144
|
: []),
|
150
145
|
]
|
151
146
|
.filter(isDefined)
|
@@ -13,7 +13,6 @@ import {createManifestExtractor, isManifestExtractSatisfied} from './utils/mainf
|
|
13
13
|
import {createManifestReader} from './utils/manifestReader'
|
14
14
|
import {createSchemaApiClient} from './utils/schemaApiClient'
|
15
15
|
import {
|
16
|
-
assetIdsMatchesWorkspaces,
|
17
16
|
filterLogReadProjectIdMismatch,
|
18
17
|
parseListSchemasConfig,
|
19
18
|
type StoreSchemaCommonFlags,
|
@@ -68,8 +67,6 @@ export async function listSchemasAction(
|
|
68
67
|
filterLogReadProjectIdMismatch(workspace, projectId, output),
|
69
68
|
)
|
70
69
|
|
71
|
-
if (id) assetIdsMatchesWorkspaces([id], workspaces)
|
72
|
-
|
73
70
|
const datasets = uniq(workspaces.map((w) => w.dataset))
|
74
71
|
|
75
72
|
const schemaResults = await Promise.allSettled(
|
@@ -94,13 +94,13 @@ function assertNoErrors(errors: string[]) {
|
|
94
94
|
}
|
95
95
|
}
|
96
96
|
|
97
|
-
export function
|
97
|
+
export function assertIdsMatchesWorkspaces(ids: string[], workspaces: {name: string}[]) {
|
98
98
|
const invalidIds = ids
|
99
99
|
.map((id) => ({
|
100
100
|
id,
|
101
101
|
parsedId: parseWorkspaceSchemaId(id, []),
|
102
102
|
}))
|
103
|
-
.filter(({
|
103
|
+
.filter(({parsedId}) => !parsedId || !workspaces.some((w) => w.name === parsedId.workspace))
|
104
104
|
|
105
105
|
if (invalidIds.length)
|
106
106
|
throw new FlagValidationError(
|
@@ -7,3 +7,7 @@ export function getDatasetsOutString(datasets: string[]) {
|
|
7
7
|
export function getStringArrayOutString(array: string[]) {
|
8
8
|
return `[${array.map((d) => `"${d}"`).join(',')}]`
|
9
9
|
}
|
10
|
+
|
11
|
+
export function getStringList(array: string[]) {
|
12
|
+
return array.map((s) => `- "${s}"`).join('\n')
|
13
|
+
}
|